Search in sources :

Example 1 with TypesNotificationContainer

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

the class PostgreSQLTypesNotificationParser method inform.

@Override
public void inform(final Collection<TypesNotificationContainer> containers, final SQLProvider provider) throws CouldntLoadDataException {
    Preconditions.checkNotNull(containers, "Error: containers argument can not be null");
    Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
    for (final TypesNotificationContainer container : containers) {
        if (!provider.findModule(container.getModuleId()).isLoaded()) {
            // we do not need to look at notification for modules not loaded.
            continue;
        }
        if (container.getAddress().isPresent()) {
            informExpressionTypesNotification(container, provider);
        } else if (container.getTypeId().isPresent()) {
            informTypesNotification(container, provider);
        } else if (container.getBaseTypeId().isPresent()) {
            informBaseTypesNotification(container, provider);
        } else {
            throw new IllegalStateException("Error: the parsed notification does not contain a distinct element.");
        }
    }
}
Also used : TypesNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypesNotificationContainer)

Example 2 with TypesNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypesNotificationContainer 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 3 with TypesNotificationContainer

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

the class PostgreSQLTypesNotificationParser method parseExpressionTypesNotification.

/**
   * Parses expression type aka type substitution {@link PGNotification notifications} for
   * synchronizing the state of {@link TypeSubstitution type substitutions} between multiple
   * instances of BinNavi.
   * 
   * @param notification The {@link PGNotification} from the database.
   * @return A {@link TypesNotificationContainer container} with the parsed information.
   */
private TypesNotificationContainer parseExpressionTypesNotification(final PGNotification notification) {
    final Matcher matcher = EXPRESSION_TYPES_NOTIFICATION_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        throw new IllegalStateException("Error: compliled pattern " + EXPRESSION_TYPES_NOTIFICATION_PATTERN.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));
    return new TypesNotificationContainer(databaseOperation, moduleId, Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.of(address), Optional.of(position), Optional.of(expressionId));
}
Also used : BigInteger(java.math.BigInteger) Matcher(java.util.regex.Matcher) BigInteger(java.math.BigInteger) TypesNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypesNotificationContainer)

Example 4 with TypesNotificationContainer

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

the class PostgreSQLTypesNotificationParser method parseBaseTypesNotification.

/**
   * Parses base type {@link PGNotification notifications} for synchronizing the state of
   * {@link BaseType base types} between multiple instances of BinNavi.
   * 
   * @param notification THe {@link PGNotification} from the database.
   * @return A {@link TypesNotificationContainer container} with the parsed information.
   */
private TypesNotificationContainer parseBaseTypesNotification(final PGNotification notification) {
    final Matcher matcher = BASE_TYPES_NOTIFICATION_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        throw new IllegalStateException("Error: compiled pattern: " + BASE_TYPE_NOTIFICATION_REGEX + " did not match notification: " + notification.getParameter());
    }
    final String databaseOperation = matcher.group(2);
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final Integer baseTypeId = Integer.parseInt(matcher.group(4));
    return new TypesNotificationContainer(databaseOperation, moduleId, Optional.of(baseTypeId), Optional.<Integer>absent(), Optional.<BigInteger>absent(), Optional.<Integer>absent(), Optional.<Integer>absent());
}
Also used : BigInteger(java.math.BigInteger) Matcher(java.util.regex.Matcher) TypesNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypesNotificationContainer)

Example 5 with TypesNotificationContainer

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

the class PostgreSQLTypesNotificationParser method parseTypesNotification.

/**
   * Parses type {@link PGNotification notifications} for synchronizing the state of
   * {@link TypeMember type members} between multiple instances of BinNavi.
   * 
   * @param notification The {@link PGNotification} from the database.
   * @return A {@link TypesNotificationContainer container} with the parsed information.
   */
private TypesNotificationContainer parseTypesNotification(final PGNotification notification) {
    final Matcher matcher = TYPES_NOTIFICATION_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        throw new IllegalStateException("Error: compiled pattern: " + TYPES_NOTIFICATION_REGEX + " did not match notification: " + notification.getParameter());
    }
    final String databaseOperation = matcher.group(2);
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final Integer typeMemberId = Integer.parseInt(matcher.group(4));
    return new TypesNotificationContainer(databaseOperation, moduleId, Optional.<Integer>absent(), Optional.of(typeMemberId), Optional.<BigInteger>absent(), Optional.<Integer>absent(), Optional.<Integer>absent());
}
Also used : BigInteger(java.math.BigInteger) Matcher(java.util.regex.Matcher) TypesNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypesNotificationContainer)

Aggregations

TypesNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypesNotificationContainer)5 BigInteger (java.math.BigInteger)3 Matcher (java.util.regex.Matcher)3 PGNotification (org.postgresql.PGNotification)1