Add support for holding an index instead of fieldname

This commit is contained in:
David Adrian 2013-09-19 18:19:12 -04:00
parent 8db9f260f2
commit f7939bfbcb
5 changed files with 25 additions and 12 deletions

View File

@ -2,13 +2,20 @@
#include "../lib/xalloc.h"
node_t* alloc_node()
/* Static helper functions */
static node_t* alloc_node();
static int eval_single_node(node_t* node);
static node_t* alloc_node()
{
node_t *node = xmalloc(sizeof(node_t));
memset(node, 0, sizeof(node_t));
return node;
}
/* Exposed functions */
node_t* make_op_node(enum operation op)
{
node_t* node = alloc_node();
@ -21,7 +28,7 @@ node_t* make_field_node(char *fieldname)
{
node_t *node = alloc_node();
node->type = FIELD;
node->value.fieldname = fieldname;
node->value.field.fieldname = fieldname;
return node;
}
@ -56,7 +63,7 @@ void print_expression(node_t *root) {
printf(" %i ", root->value.op);
break;
case FIELD:
printf(" (%s", root->value.fieldname);
printf(" (%s", root->value.field.fieldname);
break;
case STRING:
printf("%s) ", root->value.string_literal);

View File

@ -13,11 +13,16 @@ enum node_type {
OP, FIELD, STRING, INT
};
union node_value {
enum operation op;
struct field_id {
int index;
char *fieldname;
};
union node_value {
struct field_id field;
char *string_literal;
int int_literal;
enum operation op;
};
typedef struct node {
@ -27,8 +32,6 @@ typedef struct node {
union node_value value;
} node_t;
node_t* alloc_node();
node_t* make_op_node(enum operation op);
node_t* make_field_node(char *fieldname);

View File

@ -8,18 +8,19 @@ extern int yyparse();
node_t *zfilter;
void parse_filter_string(char *filter)
int parse_filter_string(char *filter)
{
YY_BUFFER_STATE buffer_state = yy_scan_string(filter);
int status = yyparse();
yy_delete_buffer(buffer_state);
if (status) {
// Error
log_fatal("zmap", "Unable to parse filter");
log_error("zmap", "Unable to parse filter string: '%s'", filter);
return 0;
}
zconf.filter.expression = zfilter;
print_expression(zfilter);
printf("%s\n", "");
fflush(stdout);
return;
return 1;
}

View File

@ -7,6 +7,6 @@ struct output_filter {
node_t *expression;
};
void parse_filter_string(char *filter);
int parse_filter_string(char *filter);
#endif /* ZMAP_FILTER_H */

View File

@ -501,7 +501,9 @@ int main(int argc, char *argv[])
// Parse and validate the output filter, if any
if (args.output_filter_arg) {
parse_filter_string(args.output_filter_arg);
if (!parse_filter_string(args.output_filter_arg)) {
log_fatal("zmap", "Unable to parse filter expression");
}
}
SET_BOOL(zconf.dryrun, dryrun);