Search in sources :

Example 1 with TextNodeCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testTextNodeCommentParsingDeleteComment.

@Test
public void testTextNodeCommentParsingDeleteComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_text_nodes UPDATE 7777 null");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processTextNodeCommentNotification(notification, provider);
    assertNotNull(result);
    final TextNodeCommentNotificationContainer container = (TextNodeCommentNotificationContainer) result;
    final INaviTextNode textNode = container.getNode();
    assertEquals(7777, textNode.getId());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) TextNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TextNodeCommentNotificationContainer) Test(org.junit.Test)

Example 2 with TextNodeCommentNotificationContainer

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

the class PostgreSQLNotificationParserTest method testTextNodeCommentParsingAppendComment.

@Test
public void testTextNodeCommentParsingAppendComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_text_nodes UPDATE 7777 3333");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processTextNodeCommentNotification(notification, provider);
    assertNotNull(result);
    final TextNodeCommentNotificationContainer container = (TextNodeCommentNotificationContainer) result;
    final INaviTextNode textNode = container.getNode();
    assertEquals(7777, textNode.getId());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) TextNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TextNodeCommentNotificationContainer) Test(org.junit.Test)

Example 3 with TextNodeCommentNotificationContainer

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

the class PostgreSQLCommentNotificationParser method processTextNodeCommentNotification.

/**
   * Parses the {@link PGNotification} notifications from the PostgreSQL database back end for text
   * node comments by using a regular expression. If the regular expression matches the supplied
   * {@link PGNotification} notification, it is determined if the text node in the notification is
   * currently loaded, and if a {@link CommentNotificationContainer} with the gathered data from the
   * notification is returned.
   *
   * @param notification The {@link PGNotification} from the PostgreSQL database server.
   * @param provider The {@link SQLProvider} which is used to communicate with the database.
   */
static CommentNotification processTextNodeCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = TEXT_NODE_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer nodeId = Integer.parseInt(matcher.group(3));
    final Integer commentId = matcher.group(4).equals("null") ? null : Integer.parseInt(matcher.group(4));
    final INaviTextNode node = (INaviTextNode) NodeCache.get(provider).getNodeById(nodeId);
    if (node == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new TextNodeCommentNotificationContainer(node, operation, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) Matcher(java.util.regex.Matcher) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) TextNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TextNodeCommentNotificationContainer)

Aggregations

TextNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TextNodeCommentNotificationContainer)3 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)3 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)2 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)2 Test (org.junit.Test)2 CommentOperation (com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation)1 BigInteger (java.math.BigInteger)1 Matcher (java.util.regex.Matcher)1