Search in sources :

Example 1 with ViewNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer in project binnavi by google.

the class PostgreSQLViewNotificationParser method inform.

/**
   * The inform function for parsed view notifications. The function takes the parsed
   * {@link ViewNotificationContainer} and dispatches to the appropriate inform functions.
   *
   * @param parsedViewNotifications The {@link Collection} of {@link ViewNotificationContainer}.
   * @param provider The {@link SQLProvider} to access the database.
   * @throws CouldntLoadDataException if the Information could not be stored to the database.
   */
@Override
public void inform(final Collection<ViewNotificationContainer> parsedViewNotifications, final SQLProvider provider) throws CouldntLoadDataException {
    Preconditions.checkNotNull(parsedViewNotifications, "Error: parsedViewNotifications argument can not be null");
    Preconditions.checkNotNull(provider, "IE02748: provider argument can not be null");
    for (final ViewNotificationContainer container : parsedViewNotifications) {
        if (container.getNotificationModule().isPresent()) {
            informModuleNotification(container, provider);
        } else if (container.getNotificationProject().isPresent()) {
            informProjectNotification(container, provider);
        } else if (!container.getNotificationObjectId().isPresent()) {
            // view case
            informViewNotification(container, provider);
        } else if (!container.getNotificationObjectId().isPresent() && !container.getNotificationModule().isPresent() && !container.getNotificationProject().isPresent()) {
            // and what else has to be synced that this situation can not really happen.
            throw new IllegalStateException("IE02749: Not enough information available.");
        }
    }
}
Also used : ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer)

Example 2 with ViewNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer in project binnavi by google.

the class PostgreSQLViewNotificationParser method parseModuleViewNotification.

/**
   * Parser for a bn_module_views notification. The function uses the moduleViewNotificationPattern
   * to parse the incoming {@link PGNotification} into a {@link ViewNotificationContainer}.
   *
   * @param notification The {@link PGNotification} to parse.
   * @param provider The {@link SQLProvider} to access the database.
   *
   * @return A {@link ViewNotificationContainer} with the parsed information.
   */
private ViewNotificationContainer parseModuleViewNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = moduleViewNotificationPattern.matcher(notification.getParameter());
    if (!matcher.find()) {
        throw new IllegalStateException("IE02743: compiled pattern: " + moduleViewNotificationPattern.toString() + " did not match notification: " + notification.getParameter());
    }
    final Integer viewId = Integer.parseInt(matcher.group(3));
    final Optional<INaviView> view = Optional.fromNullable(ViewManager.get(provider).getView(viewId));
    final Optional<Integer> moduleId = Optional.fromNullable(Integer.parseInt(matcher.group(4)));
    final Optional<INaviModule> module = Optional.fromNullable(provider.findModule(moduleId.get()));
    final String databaseOperation = matcher.group(2);
    return new ViewNotificationContainer(viewId, view, moduleId, module, Optional.<INaviProject>absent(), databaseOperation);
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer)

Example 3 with ViewNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer in project binnavi by google.

the class PostgreSQLViewNotificationParser method parse.

/**
   * The parser function for view notifications. The function checks for the database table the
   * notification originated from and dispatches the parsing appropriately to the right function.
   *
   * @param notifications The {@link Collection} of {@link PGNotification} to parse.
   * @param provider The {@link SQLProvider} to access the database with.
   * @return A {@link Collection} of {@link ViewNotificationContainer}.
   */
@Override
public Collection<ViewNotificationContainer> parse(final Collection<PGNotification> notifications, final SQLProvider provider) {
    Preconditions.checkNotNull(notifications, "IE02745: notifications argument can not be null");
    Preconditions.checkNotNull(provider, "IE02746: provider argument can not be null");
    final Collection<ViewNotificationContainer> containers = Lists.newArrayList();
    for (final PGNotification notification : notifications) {
        if (notification.getParameter().startsWith(CTableNames.VIEWS_TABLE)) {
            containers.add(parseViewNotification(notification, provider));
        } else if (notification.getParameter().startsWith(CTableNames.MODULE_VIEWS_TABLE)) {
            containers.add(parseModuleViewNotification(notification, provider));
        } else if (notification.getParameter().startsWith(CTableNames.PROJECT_VIEWS_TABLE)) {
            containers.add(parseProjectViewNotification(notification, provider));
        } else {
            throw new IllegalStateException("IE02747: Table name supplied in notification: " + notification.getParameter() + " does not match tables where view notifications are accepted on.");
        }
    }
    return containers;
}
Also used : ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer) PGNotification(org.postgresql.PGNotification)

Example 4 with ViewNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer in project binnavi by google.

the class PostgreSQLViewNotificationParser method parseViewNotification.

/**
   * Parser for a bn_views notification. The function uses the viewNotificationPattern to parse the
   * incoming {@link PGNotification} into a {@link ViewNotificationContainer}.
   *
   * @param notification The {@link PGNotification} to parse.
   * @param provider The {@link SQLProvider} to access the database.
   *
   * @return A {@link ViewNotificationContainer} with the parsed information.
   */
private ViewNotificationContainer parseViewNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = viewNotificationPattern.matcher(notification.getParameter());
    if (!matcher.find()) {
        throw new IllegalStateException("IE02742: compiled pattern: " + viewNotificationPattern.toString() + " did not match notification: " + notification.getParameter());
    }
    final Integer viewId = Integer.parseInt(matcher.group(3));
    final Optional<INaviView> view = Optional.fromNullable(ViewManager.get(provider).getView(viewId));
    final String databaseOperation = matcher.group(2);
    return new ViewNotificationContainer(viewId, view, Optional.<Integer>absent(), Optional.<INaviModule>absent(), Optional.<INaviProject>absent(), databaseOperation);
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) Matcher(java.util.regex.Matcher) ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer)

Example 5 with ViewNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer in project binnavi by google.

the class PostgreSQLViewNotificationParserTest method testModuleViewInform1.

@Test
public void testModuleViewInform1() throws CouldntLoadDataException {
    final INaviModule module = new MockModule(provider);
    final ViewNotificationContainer container = new ViewNotificationContainer(view.getConfiguration().getId(), Optional.fromNullable(view), Optional.of(module.getConfiguration().getId()), Optional.of(module), Optional.<INaviProject>absent(), "UPDATE");
    final PostgreSQLViewNotificationParser parser = new PostgreSQLViewNotificationParser();
    parser.inform(Lists.<ViewNotificationContainer>newArrayList(container), provider);
}
Also used : PostgreSQLViewNotificationParser(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.parsers.PostgreSQLViewNotificationParser) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer) Test(org.junit.Test)

Aggregations

ViewNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer)19 PostgreSQLViewNotificationParser (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.parsers.PostgreSQLViewNotificationParser)14 Test (org.junit.Test)13 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)5 INaviProject (com.google.security.zynamics.binnavi.disassembly.INaviProject)5 MockProject (com.google.security.zynamics.binnavi.disassembly.MockProject)4 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)4 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)3 Matcher (java.util.regex.Matcher)3 PGNotification (org.postgresql.PGNotification)1