use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstancesNotificationContainer in project binnavi by google.
the class PostgreSQLTypeInstancesNotificationParser method parseTypeInstanceNotification.
/**
* Parses type instance notifications. This function parses messages for synchronization of
* changes in the {@link CTableNames bn_type_instances} table.
*
* @param notification The {@link PGNotification} which carries the information to be parsed.
* @return A {@link TypeInstancesNotificationContainer} with the parsed information.
*/
private TypeInstancesNotificationContainer parseTypeInstanceNotification(final PGNotification notification) {
final Matcher matcher = typeInstanceNotificationPattern.matcher(notification.getParameter());
if (!matcher.find()) {
throw new IllegalStateException("Error: compiled pattern: " + typeInstanceNotificationPattern.toString() + " did not match notification: " + notification.getParameter());
}
final String databaseOperation = matcher.group(2);
final Integer moduleId = Integer.parseInt(matcher.group(3));
final Integer typeInstanceId = Integer.parseInt(matcher.group(4));
return new TypeInstancesNotificationContainer(databaseOperation, moduleId, typeInstanceId, Optional.<BigInteger>absent(), Optional.<Integer>absent(), Optional.<Integer>absent());
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstancesNotificationContainer 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;
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstancesNotificationContainer in project binnavi by google.
the class PostgreSQLTypeInstancesNotificationParser method parseExpressionTypeInstanceNotification.
/**
* Parses expression type instances or simpler type substitutions on operands. This function
* parses messages for synchronization of changes in the {@link CTableNames
* bn_expression_type_instances} table.
*
* @param notification The {@link PGNotification} which carries the information to be parsed.
* @return A {@link TypeInstancesNotificationContainer} with the parsed information.
*/
private TypeInstancesNotificationContainer parseExpressionTypeInstanceNotification(final PGNotification notification) {
final Matcher matcher = expressionTypeInstanceNotificationPattern.matcher(notification.getParameter());
if (!matcher.find()) {
throw new IllegalStateException("Error: compiled pattern: " + expressionTypeInstanceNotificationPattern.toString() + " did not match notification: " + notification.getParameter());
}
final String databaseOperation = matcher.group(2);
final Integer moduleId = Integer.parseInt(matcher.group(3));
final BigInteger address = new BigInteger(matcher.group(4));
final Integer position = Integer.parseInt(matcher.group(5));
final Integer expressionId = Integer.parseInt(matcher.group(6));
final Integer typeInstanceId = Integer.parseInt(matcher.group(7));
return new TypeInstancesNotificationContainer(databaseOperation, moduleId, typeInstanceId, Optional.of(address), Optional.of(position), Optional.of(expressionId));
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstancesNotificationContainer in project binnavi by google.
the class PostgreSQLTypeInstancesNotificationParserTest method testParser.
private void testParser(final String table, final String databaseOperation, final String moduleId, final String address, final String position, final String expressionId, final String typeInstanceId) {
final StringBuilder builder = new StringBuilder();
builder.append(table);
builder.append(' ');
builder.append(databaseOperation);
builder.append(' ');
builder.append(moduleId);
builder.append(' ');
if (address != null) {
builder.append(address);
builder.append(' ');
}
if (position != null) {
builder.append(position);
builder.append(' ');
}
if (expressionId != null) {
builder.append(expressionId);
builder.append(' ');
}
builder.append(typeInstanceId);
final String notification = builder.toString();
notifications.add(new MockPGNotification("type_instances_changes", notification));
final PostgreSQLTypeInstancesNotificationParser parser = new PostgreSQLTypeInstancesNotificationParser();
final Collection<TypeInstancesNotificationContainer> result = parser.parse(notifications, provider);
assertNotNull(result);
assertTrue(!result.isEmpty());
assertTrue(result.size() == 1);
final TypeInstancesNotificationContainer container = Iterables.getFirst(result, null);
assertNotNull(container);
assertEquals(databaseOperation, container.getDatabaseOperation());
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstancesNotificationContainer in project binnavi by google.
the class PostgreSQLTypeInstancesNotificationParserTest method testTypeInstanceInform1.
@Test
public void testTypeInstanceInform1() throws CouldntLoadDataException {
final TypeInstancesNotificationContainer container = new TypeInstancesNotificationContainer("INSERT", module.getConfiguration().getId(), instance.getId(), Optional.<BigInteger>absent(), Optional.<Integer>absent(), Optional.<Integer>absent());
final PostgreSQLTypeInstancesNotificationParser parser = new PostgreSQLTypeInstancesNotificationParser();
parser.inform(Lists.newArrayList(container), provider);
}
Aggregations