use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer in project binnavi by google.
the class PostgreSQLNotificationParserTest method testFunctionNodeCommentParsingAppendComment.
@Test
public void testFunctionNodeCommentParsingAppendComment() {
new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
MockPGNotification notification = new MockPGNotification("comment_changes", "bn_function_nodes UPDATE 1 6666 4608 3333");
final CommentNotification result = PostgreSQLCommentNotificationParser.processFunctionNodeCommentNotification(notification, provider);
assertNotNull(result);
final FunctionNodeCommentNotificationContainer container = (FunctionNodeCommentNotificationContainer) result;
final INaviFunction function = container.getNode().getFunction();
assertEquals(new CAddress(4608), function.getAddress());
assertEquals(CommentOperation.APPEND, container.getOperation());
assertEquals(new Integer(3333), container.getCommentId());
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer in project binnavi by google.
the class PostgreSQLNotificationParserTest method testFunctionNodeCommentParsingDeleteComment.
@Test
public void testFunctionNodeCommentParsingDeleteComment() {
new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
MockPGNotification notification = new MockPGNotification("comment_changes", "bn_function_nodes UPDATE 1 6666 4608 null");
final CommentNotification result = PostgreSQLCommentNotificationParser.processFunctionNodeCommentNotification(notification, provider);
assertNotNull(result);
final FunctionNodeCommentNotificationContainer container = (FunctionNodeCommentNotificationContainer) result;
final INaviFunctionNode functionNode = container.getNode();
assertEquals(new CAddress(4608), functionNode.getAddress());
assertEquals(CommentOperation.DELETE, container.getOperation());
assertNull(container.getCommentId());
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionNodeCommentNotificationContainer in project binnavi by google.
the class PostgreSQLCommentNotificationParser method processFunctionNodeCommentNotification.
/**
* Parses the notifications from the database back end for function node comments by using a
* regular expression. If the regular expression matches the supplied {@link PGNotification}
* notification, it is determined if the function node in question is currently loaded, and if a
* {@link CommentNotificationContainer} with the gathered data 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 processFunctionNodeCommentNotification(final PGNotification notification, final SQLProvider provider) {
final Matcher matcher = FUNCTION_NODE_PATTERN.matcher(notification.getParameter());
if (!matcher.find()) {
return null;
}
final Integer moduleId = Integer.parseInt(matcher.group(3));
final Integer nodeId = Integer.parseInt(matcher.group(4));
final Integer commentId = matcher.group(6).equals("null") ? null : Integer.parseInt(matcher.group(6));
final INaviModule module = provider.findModule(moduleId);
if ((module == null) || !module.isLoaded()) {
return null;
}
final INaviFunctionNode functionNode = (INaviFunctionNode) NodeCache.get(provider).getNodeById(nodeId);
if (functionNode == null) {
return null;
}
final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
return new FunctionNodeCommentNotificationContainer(functionNode, operation, commentId);
}
Aggregations