Search in sources :

Example 1 with PGNotification

use of org.postgresql.PGNotification in project binnavi by google.

the class PostgreSQLTypesNotificationParser method parse.

@Override
public Collection<TypesNotificationContainer> parse(final Collection<PGNotification> notifications, final SQLProvider provider) {
    Preconditions.checkNotNull(notifications, "Error: notifications argument can not be null");
    Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
    final Collection<TypesNotificationContainer> containers = Lists.newArrayList();
    for (final PGNotification notification : notifications) {
        if (notification.getParameter().startsWith(CTableNames.EXPRESSION_TYPES_TABLE)) {
            containers.add(parseExpressionTypesNotification(notification));
        } else if (notification.getParameter().startsWith(CTableNames.TYPE_MEMBERS_TABLE)) {
            containers.add(parseTypesNotification(notification));
        } else if (notification.getParameter().startsWith(CTableNames.BASE_TYPES_TABLE)) {
            containers.add(parseBaseTypesNotification(notification));
        } else {
            throw new IllegalStateException("Error: Table name supplied in notification " + notification.getParameter() + " does not match tables where type notifications are expected on.");
        }
    }
    return containers;
}
Also used : TypesNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypesNotificationContainer) PGNotification(org.postgresql.PGNotification)

Example 2 with PGNotification

use of org.postgresql.PGNotification in project binnavi by google.

the class PostgreSQLTypeInstancesNotificationParser method parse.

@Override
public Collection<TypeInstancesNotificationContainer> parse(final Collection<PGNotification> notifications, final SQLProvider provider) {
    Preconditions.checkNotNull(notifications, "Error: notifications argument can not be null");
    Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
    final Collection<TypeInstancesNotificationContainer> containers = Lists.newArrayList();
    for (final PGNotification notification : notifications) {
        if (notification.getParameter().startsWith(CTableNames.TYPE_INSTANCE_TABLE)) {
            containers.add(parseTypeInstanceNotification(notification));
        } else if (notification.getParameter().startsWith(CTableNames.EXPRESSION_TYPE_INSTANCES_TABLE)) {
            containers.add(parseExpressionTypeInstanceNotification(notification));
        } else {
            throw new IllegalStateException("Error: Table name supplied in notification " + notification.getParameter() + " does not match tables where type instance notifications are accepted on.");
        }
    }
    return containers;
}
Also used : TypeInstancesNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstancesNotificationContainer) PGNotification(org.postgresql.PGNotification)

Example 3 with PGNotification

use of org.postgresql.PGNotification 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 PGNotification

use of org.postgresql.PGNotification in project binnavi by google.

the class PostgreSQLCommentNotificationParser method parse.

@Override
public Collection<CommentNotification> parse(final Collection<PGNotification> commentNotifications, final SQLProvider provider) {
    Preconditions.checkNotNull(commentNotifications, "Error: commentNotifications argument can not be null");
    Preconditions.checkNotNull(provider, "IE02524: provider argument can not be null");
    for (final PGNotification notification : commentNotifications) {
        final String notificationParameter = notification.getParameter();
        final String tableName = notificationParameter.split("\\s")[0];
        try {
            switch(tableName) {
                case CTableNames.CODENODE_INSTRUCTIONS_TABLE:
                    informNotification(processNodeLocalInstructionCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.INSTRUCTIONS_TABLE:
                    informNotification(processInstructionGlobalCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.CODE_NODES_TABLE:
                    informNotification(processNodeLocalNodeCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.GLOBAL_NODE_COMMENTS_TABLE:
                    informNotification(processNodeGlobalCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.EDGES_TABLE:
                    informNotification(processEdgeLocalCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.GLOBAL_EDGE_COMMENTS_TABLE:
                    informNotification(processEdgeGlobalCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.FUNCTION_NODES_TABLE:
                    informNotification(processFunctionNodeCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.FUNCTIONS_TABLE:
                    informNotification(processFunctionCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.TEXT_NODES_TABLE:
                    informNotification(processTextNodeCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.GROUP_NODES_TABLE:
                    informNotification(processGroupNodeCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.TYPE_INSTANCE_TABLE:
                    informNotification(processTypeInstanceCommentNotification(notification, provider), provider);
                    break;
                case CTableNames.COMMENTS_TABLE:
                    informNotification(processCommentNotification(notification, provider), provider);
                    break;
                default:
                    NaviLogger.warning("Table name %s not known", tableName);
            }
        } catch (CouldntLoadDataException exception) {
            NaviLogger.severe("Error: Could not successfully parse the database comment notification: %s", notification.toString());
        }
    }
    // TODO(timkornau): change the interface to not return anything here.
    return new ArrayList<>();
}
Also used : CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) PGNotification(org.postgresql.PGNotification)

Example 5 with PGNotification

use of org.postgresql.PGNotification in project binnavi by google.

the class PostgreSQLNotificationParserTest method testTypeInstanceCommentParsingDeleteComment.

@Test
public void testTypeInstanceCommentParsingDeleteComment() throws CouldntSaveDataException, CouldntLoadDataException {
    final INaviModule module = new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    module.getContent().getSections().createSection("A", new CAddress(0), new CAddress(1234), SectionPermission.READ, null);
    final TypeInstance fakeInstance = module.getContent().getTypeInstanceContainer().createInstance("TYPE INSTANCE", null, module.getTypeManager().getTypes().get(0), module.getContent().getSections().getSection(0), 0);
    final PGNotification notification = new MockPGNotification("comment_changes", "bn_type_instances UPDATE 1 " + fakeInstance.getId() + " null");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processTypeInstanceCommentNotification(notification, provider);
    assertNotNull(result);
    final TypeInstanceCommentNotificationContainer container = (TypeInstanceCommentNotificationContainer) result;
    assertNotNull(container);
    final TypeInstance instance = container.getInstance();
    assertEquals(fakeInstance.getId(), instance.getId());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
}
Also used : TypeInstanceCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) PGNotification(org.postgresql.PGNotification) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

PGNotification (org.postgresql.PGNotification)7 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 FunctionNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNotificationContainer)1 TypeInstanceCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer)1 TypeInstancesNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstancesNotificationContainer)1 TypesNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypesNotificationContainer)1 ViewNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer)1 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)1 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)1 TypeInstance (com.google.security.zynamics.binnavi.disassembly.types.TypeInstance)1 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)1