Add support for holding an index instead of fieldname
This commit is contained in:
parent
8db9f260f2
commit
f7939bfbcb
@ -2,13 +2,20 @@
|
|||||||
|
|
||||||
#include "../lib/xalloc.h"
|
#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));
|
node_t *node = xmalloc(sizeof(node_t));
|
||||||
memset(node, 0, sizeof(node_t));
|
memset(node, 0, sizeof(node_t));
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Exposed functions */
|
||||||
|
|
||||||
node_t* make_op_node(enum operation op)
|
node_t* make_op_node(enum operation op)
|
||||||
{
|
{
|
||||||
node_t* node = alloc_node();
|
node_t* node = alloc_node();
|
||||||
@ -21,7 +28,7 @@ node_t* make_field_node(char *fieldname)
|
|||||||
{
|
{
|
||||||
node_t *node = alloc_node();
|
node_t *node = alloc_node();
|
||||||
node->type = FIELD;
|
node->type = FIELD;
|
||||||
node->value.fieldname = fieldname;
|
node->value.field.fieldname = fieldname;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +63,7 @@ void print_expression(node_t *root) {
|
|||||||
printf(" %i ", root->value.op);
|
printf(" %i ", root->value.op);
|
||||||
break;
|
break;
|
||||||
case FIELD:
|
case FIELD:
|
||||||
printf(" (%s", root->value.fieldname);
|
printf(" (%s", root->value.field.fieldname);
|
||||||
break;
|
break;
|
||||||
case STRING:
|
case STRING:
|
||||||
printf("%s) ", root->value.string_literal);
|
printf("%s) ", root->value.string_literal);
|
||||||
|
@ -13,11 +13,16 @@ enum node_type {
|
|||||||
OP, FIELD, STRING, INT
|
OP, FIELD, STRING, INT
|
||||||
};
|
};
|
||||||
|
|
||||||
union node_value {
|
struct field_id {
|
||||||
enum operation op;
|
int index;
|
||||||
char *fieldname;
|
char *fieldname;
|
||||||
|
};
|
||||||
|
|
||||||
|
union node_value {
|
||||||
|
struct field_id field;
|
||||||
char *string_literal;
|
char *string_literal;
|
||||||
int int_literal;
|
int int_literal;
|
||||||
|
enum operation op;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct node {
|
typedef struct node {
|
||||||
@ -27,8 +32,6 @@ typedef struct node {
|
|||||||
union node_value value;
|
union node_value value;
|
||||||
} node_t;
|
} node_t;
|
||||||
|
|
||||||
node_t* alloc_node();
|
|
||||||
|
|
||||||
node_t* make_op_node(enum operation op);
|
node_t* make_op_node(enum operation op);
|
||||||
|
|
||||||
node_t* make_field_node(char *fieldname);
|
node_t* make_field_node(char *fieldname);
|
||||||
|
@ -8,18 +8,19 @@ extern int yyparse();
|
|||||||
|
|
||||||
node_t *zfilter;
|
node_t *zfilter;
|
||||||
|
|
||||||
void parse_filter_string(char *filter)
|
int parse_filter_string(char *filter)
|
||||||
{
|
{
|
||||||
YY_BUFFER_STATE buffer_state = yy_scan_string(filter);
|
YY_BUFFER_STATE buffer_state = yy_scan_string(filter);
|
||||||
int status = yyparse();
|
int status = yyparse();
|
||||||
yy_delete_buffer(buffer_state);
|
yy_delete_buffer(buffer_state);
|
||||||
if (status) {
|
if (status) {
|
||||||
// Error
|
// Error
|
||||||
log_fatal("zmap", "Unable to parse filter");
|
log_error("zmap", "Unable to parse filter string: '%s'", filter);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
zconf.filter.expression = zfilter;
|
zconf.filter.expression = zfilter;
|
||||||
print_expression(zfilter);
|
print_expression(zfilter);
|
||||||
printf("%s\n", "");
|
printf("%s\n", "");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
@ -7,6 +7,6 @@ struct output_filter {
|
|||||||
node_t *expression;
|
node_t *expression;
|
||||||
};
|
};
|
||||||
|
|
||||||
void parse_filter_string(char *filter);
|
int parse_filter_string(char *filter);
|
||||||
|
|
||||||
#endif /* ZMAP_FILTER_H */
|
#endif /* ZMAP_FILTER_H */
|
@ -501,7 +501,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Parse and validate the output filter, if any
|
// Parse and validate the output filter, if any
|
||||||
if (args.output_filter_arg) {
|
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);
|
SET_BOOL(zconf.dryrun, dryrun);
|
||||||
|
Loading…
Reference in New Issue
Block a user