use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionCommentNotificationContainer in project binnavi by google.
the class PostgreSQLCommentNotificationParser method processFunctionCommentNotification.
/**
* Parses the notifications from the database back end for function comments by using a regular
* expression. If the regular expression matches the supplied {@link PGNotification} notification,
* a {@link CommentNotificationContainer} is build with the data from the notification.
*
* @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 processFunctionCommentNotification(final PGNotification notification, final SQLProvider provider) {
final Matcher matcher = FUNCTION_PATTERN.matcher(notification.getParameter());
if (!matcher.find()) {
return null;
}
final Integer notificationModuleId = Integer.parseInt(matcher.group(3));
final IAddress notificationFunctionAddress = new CAddress(new BigInteger(matcher.group(4)));
final Integer commentId = matcher.group(5).equals("null") ? null : Integer.parseInt(matcher.group(5));
final INaviModule module = provider.findModule(notificationModuleId);
if ((module == null) || !module.isLoaded()) {
return null;
}
final INaviFunction function = module.getContent().getFunctionContainer().getFunction(notificationFunctionAddress);
if (function == null) {
return null;
}
final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
return new FunctionCommentNotificationContainer(function, operation, commentId);
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionCommentNotificationContainer in project binnavi by google.
the class PostgreSQLNotificationParserTest method testFunctionCommentParsingAppendComment.
@Test
public void testFunctionCommentParsingAppendComment() {
new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
MockPGNotification notification = new MockPGNotification("comment_changes", "bn_functions UPDATE 1 4608 3333");
final CommentNotification result = PostgreSQLCommentNotificationParser.processFunctionCommentNotification(notification, provider);
assertNotNull(result);
final FunctionCommentNotificationContainer container = (FunctionCommentNotificationContainer) result;
final INaviFunction function = container.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.FunctionCommentNotificationContainer in project binnavi by google.
the class PostgreSQLNotificationParserTest method testFunctionCommentParsingDeleteComment.
@Test
public void testFunctionCommentParsingDeleteComment() {
new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
MockPGNotification notification = new MockPGNotification("comment_changes", "bn_functions UPDATE 1 4608 null");
final CommentNotification result = PostgreSQLCommentNotificationParser.processFunctionCommentNotification(notification, provider);
assertNotNull(result);
final FunctionCommentNotificationContainer container = (FunctionCommentNotificationContainer) result;
final INaviFunction function = container.getFunction();
assertEquals(new CAddress(4608), function.getAddress());
assertEquals(CommentOperation.DELETE, container.getOperation());
assertNull(container.getCommentId());
}
Aggregations