| .. | .. |
|---|
| 11 | 11 | #include <sys/types.h> |
|---|
| 12 | 12 | |
|---|
| 13 | 13 | #include "event-parse.h" |
|---|
| 14 | +#include "event-parse-local.h" |
|---|
| 14 | 15 | #include "event-utils.h" |
|---|
| 15 | 16 | |
|---|
| 16 | 17 | #define COMM "COMM" |
|---|
| 17 | 18 | #define CPU "CPU" |
|---|
| 18 | 19 | |
|---|
| 19 | | -static struct format_field comm = { |
|---|
| 20 | +static struct tep_format_field comm = { |
|---|
| 20 | 21 | .name = "COMM", |
|---|
| 21 | 22 | }; |
|---|
| 22 | 23 | |
|---|
| 23 | | -static struct format_field cpu = { |
|---|
| 24 | +static struct tep_format_field cpu = { |
|---|
| 24 | 25 | .name = "CPU", |
|---|
| 25 | 26 | }; |
|---|
| 26 | 27 | |
|---|
| 27 | 28 | struct event_list { |
|---|
| 28 | 29 | struct event_list *next; |
|---|
| 29 | | - struct event_format *event; |
|---|
| 30 | + struct tep_event *event; |
|---|
| 30 | 31 | }; |
|---|
| 31 | 32 | |
|---|
| 32 | 33 | static void show_error(char *error_buf, const char *fmt, ...) |
|---|
| .. | .. |
|---|
| 37 | 38 | int len; |
|---|
| 38 | 39 | int i; |
|---|
| 39 | 40 | |
|---|
| 40 | | - input = tep_get_input_buf(); |
|---|
| 41 | | - index = tep_get_input_buf_ptr(); |
|---|
| 41 | + input = get_input_buf(); |
|---|
| 42 | + index = get_input_buf_ptr(); |
|---|
| 42 | 43 | len = input ? strlen(input) : 0; |
|---|
| 43 | 44 | |
|---|
| 44 | 45 | if (len) { |
|---|
| .. | .. |
|---|
| 56 | 57 | va_end(ap); |
|---|
| 57 | 58 | } |
|---|
| 58 | 59 | |
|---|
| 59 | | -static void free_token(char *token) |
|---|
| 60 | +static enum tep_event_type filter_read_token(char **tok) |
|---|
| 60 | 61 | { |
|---|
| 61 | | - tep_free_token(token); |
|---|
| 62 | | -} |
|---|
| 63 | | - |
|---|
| 64 | | -static enum event_type read_token(char **tok) |
|---|
| 65 | | -{ |
|---|
| 66 | | - enum event_type type; |
|---|
| 62 | + enum tep_event_type type; |
|---|
| 67 | 63 | char *token = NULL; |
|---|
| 68 | 64 | |
|---|
| 69 | 65 | do { |
|---|
| 70 | 66 | free_token(token); |
|---|
| 71 | | - type = tep_read_token(&token); |
|---|
| 72 | | - } while (type == EVENT_NEWLINE || type == EVENT_SPACE); |
|---|
| 67 | + type = read_token(&token); |
|---|
| 68 | + } while (type == TEP_EVENT_NEWLINE || type == TEP_EVENT_SPACE); |
|---|
| 73 | 69 | |
|---|
| 74 | 70 | /* If token is = or ! check to see if the next char is ~ */ |
|---|
| 75 | 71 | if (token && |
|---|
| 76 | 72 | (strcmp(token, "=") == 0 || strcmp(token, "!") == 0) && |
|---|
| 77 | | - tep_peek_char() == '~') { |
|---|
| 73 | + peek_char() == '~') { |
|---|
| 78 | 74 | /* append it */ |
|---|
| 79 | 75 | *tok = malloc(3); |
|---|
| 80 | 76 | if (*tok == NULL) { |
|---|
| 81 | 77 | free_token(token); |
|---|
| 82 | | - return EVENT_ERROR; |
|---|
| 78 | + return TEP_EVENT_ERROR; |
|---|
| 83 | 79 | } |
|---|
| 84 | 80 | sprintf(*tok, "%c%c", *token, '~'); |
|---|
| 85 | 81 | free_token(token); |
|---|
| 86 | 82 | /* Now remove the '~' from the buffer */ |
|---|
| 87 | | - tep_read_token(&token); |
|---|
| 83 | + read_token(&token); |
|---|
| 88 | 84 | free_token(token); |
|---|
| 89 | 85 | } else |
|---|
| 90 | 86 | *tok = token; |
|---|
| .. | .. |
|---|
| 94 | 90 | |
|---|
| 95 | 91 | static int filter_cmp(const void *a, const void *b) |
|---|
| 96 | 92 | { |
|---|
| 97 | | - const struct filter_type *ea = a; |
|---|
| 98 | | - const struct filter_type *eb = b; |
|---|
| 93 | + const struct tep_filter_type *ea = a; |
|---|
| 94 | + const struct tep_filter_type *eb = b; |
|---|
| 99 | 95 | |
|---|
| 100 | 96 | if (ea->event_id < eb->event_id) |
|---|
| 101 | 97 | return -1; |
|---|
| .. | .. |
|---|
| 106 | 102 | return 0; |
|---|
| 107 | 103 | } |
|---|
| 108 | 104 | |
|---|
| 109 | | -static struct filter_type * |
|---|
| 110 | | -find_filter_type(struct event_filter *filter, int id) |
|---|
| 105 | +static struct tep_filter_type * |
|---|
| 106 | +find_filter_type(struct tep_event_filter *filter, int id) |
|---|
| 111 | 107 | { |
|---|
| 112 | | - struct filter_type *filter_type; |
|---|
| 113 | | - struct filter_type key; |
|---|
| 108 | + struct tep_filter_type *filter_type; |
|---|
| 109 | + struct tep_filter_type key; |
|---|
| 114 | 110 | |
|---|
| 115 | 111 | key.event_id = id; |
|---|
| 116 | 112 | |
|---|
| .. | .. |
|---|
| 122 | 118 | return filter_type; |
|---|
| 123 | 119 | } |
|---|
| 124 | 120 | |
|---|
| 125 | | -static struct filter_type * |
|---|
| 126 | | -add_filter_type(struct event_filter *filter, int id) |
|---|
| 121 | +static struct tep_filter_type * |
|---|
| 122 | +add_filter_type(struct tep_event_filter *filter, int id) |
|---|
| 127 | 123 | { |
|---|
| 128 | | - struct filter_type *filter_type; |
|---|
| 124 | + struct tep_filter_type *filter_type; |
|---|
| 129 | 125 | int i; |
|---|
| 130 | 126 | |
|---|
| 131 | 127 | filter_type = find_filter_type(filter, id); |
|---|
| .. | .. |
|---|
| 153 | 149 | |
|---|
| 154 | 150 | filter_type = &filter->event_filters[i]; |
|---|
| 155 | 151 | filter_type->event_id = id; |
|---|
| 156 | | - filter_type->event = tep_find_event(filter->pevent, id); |
|---|
| 152 | + filter_type->event = tep_find_event(filter->tep, id); |
|---|
| 157 | 153 | filter_type->filter = NULL; |
|---|
| 158 | 154 | |
|---|
| 159 | 155 | filter->filters++; |
|---|
| .. | .. |
|---|
| 163 | 159 | |
|---|
| 164 | 160 | /** |
|---|
| 165 | 161 | * tep_filter_alloc - create a new event filter |
|---|
| 166 | | - * @pevent: The pevent that this filter is associated with |
|---|
| 162 | + * @tep: The tep that this filter is associated with |
|---|
| 167 | 163 | */ |
|---|
| 168 | | -struct event_filter *tep_filter_alloc(struct tep_handle *pevent) |
|---|
| 164 | +struct tep_event_filter *tep_filter_alloc(struct tep_handle *tep) |
|---|
| 169 | 165 | { |
|---|
| 170 | | - struct event_filter *filter; |
|---|
| 166 | + struct tep_event_filter *filter; |
|---|
| 171 | 167 | |
|---|
| 172 | 168 | filter = malloc(sizeof(*filter)); |
|---|
| 173 | 169 | if (filter == NULL) |
|---|
| 174 | 170 | return NULL; |
|---|
| 175 | 171 | |
|---|
| 176 | 172 | memset(filter, 0, sizeof(*filter)); |
|---|
| 177 | | - filter->pevent = pevent; |
|---|
| 178 | | - tep_ref(pevent); |
|---|
| 173 | + filter->tep = tep; |
|---|
| 174 | + tep_ref(tep); |
|---|
| 179 | 175 | |
|---|
| 180 | 176 | return filter; |
|---|
| 181 | 177 | } |
|---|
| 182 | 178 | |
|---|
| 183 | | -static struct filter_arg *allocate_arg(void) |
|---|
| 179 | +static struct tep_filter_arg *allocate_arg(void) |
|---|
| 184 | 180 | { |
|---|
| 185 | | - return calloc(1, sizeof(struct filter_arg)); |
|---|
| 181 | + return calloc(1, sizeof(struct tep_filter_arg)); |
|---|
| 186 | 182 | } |
|---|
| 187 | 183 | |
|---|
| 188 | | -static void free_arg(struct filter_arg *arg) |
|---|
| 184 | +static void free_arg(struct tep_filter_arg *arg) |
|---|
| 189 | 185 | { |
|---|
| 190 | 186 | if (!arg) |
|---|
| 191 | 187 | return; |
|---|
| 192 | 188 | |
|---|
| 193 | 189 | switch (arg->type) { |
|---|
| 194 | | - case FILTER_ARG_NONE: |
|---|
| 195 | | - case FILTER_ARG_BOOLEAN: |
|---|
| 190 | + case TEP_FILTER_ARG_NONE: |
|---|
| 191 | + case TEP_FILTER_ARG_BOOLEAN: |
|---|
| 196 | 192 | break; |
|---|
| 197 | 193 | |
|---|
| 198 | | - case FILTER_ARG_NUM: |
|---|
| 194 | + case TEP_FILTER_ARG_NUM: |
|---|
| 199 | 195 | free_arg(arg->num.left); |
|---|
| 200 | 196 | free_arg(arg->num.right); |
|---|
| 201 | 197 | break; |
|---|
| 202 | 198 | |
|---|
| 203 | | - case FILTER_ARG_EXP: |
|---|
| 199 | + case TEP_FILTER_ARG_EXP: |
|---|
| 204 | 200 | free_arg(arg->exp.left); |
|---|
| 205 | 201 | free_arg(arg->exp.right); |
|---|
| 206 | 202 | break; |
|---|
| 207 | 203 | |
|---|
| 208 | | - case FILTER_ARG_STR: |
|---|
| 204 | + case TEP_FILTER_ARG_STR: |
|---|
| 209 | 205 | free(arg->str.val); |
|---|
| 210 | 206 | regfree(&arg->str.reg); |
|---|
| 211 | 207 | free(arg->str.buffer); |
|---|
| 212 | 208 | break; |
|---|
| 213 | 209 | |
|---|
| 214 | | - case FILTER_ARG_VALUE: |
|---|
| 215 | | - if (arg->value.type == FILTER_STRING || |
|---|
| 216 | | - arg->value.type == FILTER_CHAR) |
|---|
| 210 | + case TEP_FILTER_ARG_VALUE: |
|---|
| 211 | + if (arg->value.type == TEP_FILTER_STRING || |
|---|
| 212 | + arg->value.type == TEP_FILTER_CHAR) |
|---|
| 217 | 213 | free(arg->value.str); |
|---|
| 218 | 214 | break; |
|---|
| 219 | 215 | |
|---|
| 220 | | - case FILTER_ARG_OP: |
|---|
| 216 | + case TEP_FILTER_ARG_OP: |
|---|
| 221 | 217 | free_arg(arg->op.left); |
|---|
| 222 | 218 | free_arg(arg->op.right); |
|---|
| 223 | 219 | default: |
|---|
| .. | .. |
|---|
| 228 | 224 | } |
|---|
| 229 | 225 | |
|---|
| 230 | 226 | static int add_event(struct event_list **events, |
|---|
| 231 | | - struct event_format *event) |
|---|
| 227 | + struct tep_event *event) |
|---|
| 232 | 228 | { |
|---|
| 233 | 229 | struct event_list *list; |
|---|
| 234 | 230 | |
|---|
| .. | .. |
|---|
| 242 | 238 | return 0; |
|---|
| 243 | 239 | } |
|---|
| 244 | 240 | |
|---|
| 245 | | -static int event_match(struct event_format *event, |
|---|
| 241 | +static int event_match(struct tep_event *event, |
|---|
| 246 | 242 | regex_t *sreg, regex_t *ereg) |
|---|
| 247 | 243 | { |
|---|
| 248 | 244 | if (sreg) { |
|---|
| .. | .. |
|---|
| 255 | 251 | } |
|---|
| 256 | 252 | |
|---|
| 257 | 253 | static enum tep_errno |
|---|
| 258 | | -find_event(struct tep_handle *pevent, struct event_list **events, |
|---|
| 254 | +find_event(struct tep_handle *tep, struct event_list **events, |
|---|
| 259 | 255 | char *sys_name, char *event_name) |
|---|
| 260 | 256 | { |
|---|
| 261 | | - struct event_format *event; |
|---|
| 257 | + struct tep_event *event; |
|---|
| 262 | 258 | regex_t ereg; |
|---|
| 263 | 259 | regex_t sreg; |
|---|
| 264 | 260 | int match = 0; |
|---|
| .. | .. |
|---|
| 298 | 294 | } |
|---|
| 299 | 295 | } |
|---|
| 300 | 296 | |
|---|
| 301 | | - for (i = 0; i < pevent->nr_events; i++) { |
|---|
| 302 | | - event = pevent->events[i]; |
|---|
| 297 | + for (i = 0; i < tep->nr_events; i++) { |
|---|
| 298 | + event = tep->events[i]; |
|---|
| 303 | 299 | if (event_match(event, sys_name ? &sreg : NULL, &ereg)) { |
|---|
| 304 | 300 | match = 1; |
|---|
| 305 | 301 | if (add_event(events, event) < 0) { |
|---|
| .. | .. |
|---|
| 333 | 329 | } |
|---|
| 334 | 330 | |
|---|
| 335 | 331 | static enum tep_errno |
|---|
| 336 | | -create_arg_item(struct event_format *event, const char *token, |
|---|
| 337 | | - enum event_type type, struct filter_arg **parg, char *error_str) |
|---|
| 332 | +create_arg_item(struct tep_event *event, const char *token, |
|---|
| 333 | + enum tep_event_type type, struct tep_filter_arg **parg, char *error_str) |
|---|
| 338 | 334 | { |
|---|
| 339 | | - struct format_field *field; |
|---|
| 340 | | - struct filter_arg *arg; |
|---|
| 335 | + struct tep_format_field *field; |
|---|
| 336 | + struct tep_filter_arg *arg; |
|---|
| 341 | 337 | |
|---|
| 342 | 338 | arg = allocate_arg(); |
|---|
| 343 | 339 | if (arg == NULL) { |
|---|
| .. | .. |
|---|
| 347 | 343 | |
|---|
| 348 | 344 | switch (type) { |
|---|
| 349 | 345 | |
|---|
| 350 | | - case EVENT_SQUOTE: |
|---|
| 351 | | - case EVENT_DQUOTE: |
|---|
| 352 | | - arg->type = FILTER_ARG_VALUE; |
|---|
| 346 | + case TEP_EVENT_SQUOTE: |
|---|
| 347 | + case TEP_EVENT_DQUOTE: |
|---|
| 348 | + arg->type = TEP_FILTER_ARG_VALUE; |
|---|
| 353 | 349 | arg->value.type = |
|---|
| 354 | | - type == EVENT_DQUOTE ? FILTER_STRING : FILTER_CHAR; |
|---|
| 350 | + type == TEP_EVENT_DQUOTE ? TEP_FILTER_STRING : TEP_FILTER_CHAR; |
|---|
| 355 | 351 | arg->value.str = strdup(token); |
|---|
| 356 | 352 | if (!arg->value.str) { |
|---|
| 357 | 353 | free_arg(arg); |
|---|
| .. | .. |
|---|
| 359 | 355 | return TEP_ERRNO__MEM_ALLOC_FAILED; |
|---|
| 360 | 356 | } |
|---|
| 361 | 357 | break; |
|---|
| 362 | | - case EVENT_ITEM: |
|---|
| 358 | + case TEP_EVENT_ITEM: |
|---|
| 363 | 359 | /* if it is a number, then convert it */ |
|---|
| 364 | 360 | if (isdigit(token[0])) { |
|---|
| 365 | | - arg->type = FILTER_ARG_VALUE; |
|---|
| 366 | | - arg->value.type = FILTER_NUMBER; |
|---|
| 361 | + arg->type = TEP_FILTER_ARG_VALUE; |
|---|
| 362 | + arg->value.type = TEP_FILTER_NUMBER; |
|---|
| 367 | 363 | arg->value.val = strtoull(token, NULL, 0); |
|---|
| 368 | 364 | break; |
|---|
| 369 | 365 | } |
|---|
| .. | .. |
|---|
| 377 | 373 | field = &cpu; |
|---|
| 378 | 374 | } else { |
|---|
| 379 | 375 | /* not a field, Make it false */ |
|---|
| 380 | | - arg->type = FILTER_ARG_BOOLEAN; |
|---|
| 381 | | - arg->boolean.value = FILTER_FALSE; |
|---|
| 376 | + arg->type = TEP_FILTER_ARG_BOOLEAN; |
|---|
| 377 | + arg->boolean.value = TEP_FILTER_FALSE; |
|---|
| 382 | 378 | break; |
|---|
| 383 | 379 | } |
|---|
| 384 | 380 | } |
|---|
| 385 | | - arg->type = FILTER_ARG_FIELD; |
|---|
| 381 | + arg->type = TEP_FILTER_ARG_FIELD; |
|---|
| 386 | 382 | arg->field.field = field; |
|---|
| 387 | 383 | break; |
|---|
| 388 | 384 | default: |
|---|
| .. | .. |
|---|
| 394 | 390 | return 0; |
|---|
| 395 | 391 | } |
|---|
| 396 | 392 | |
|---|
| 397 | | -static struct filter_arg * |
|---|
| 398 | | -create_arg_op(enum filter_op_type btype) |
|---|
| 393 | +static struct tep_filter_arg * |
|---|
| 394 | +create_arg_op(enum tep_filter_op_type btype) |
|---|
| 399 | 395 | { |
|---|
| 400 | | - struct filter_arg *arg; |
|---|
| 396 | + struct tep_filter_arg *arg; |
|---|
| 401 | 397 | |
|---|
| 402 | 398 | arg = allocate_arg(); |
|---|
| 403 | 399 | if (!arg) |
|---|
| 404 | 400 | return NULL; |
|---|
| 405 | 401 | |
|---|
| 406 | | - arg->type = FILTER_ARG_OP; |
|---|
| 402 | + arg->type = TEP_FILTER_ARG_OP; |
|---|
| 407 | 403 | arg->op.type = btype; |
|---|
| 408 | 404 | |
|---|
| 409 | 405 | return arg; |
|---|
| 410 | 406 | } |
|---|
| 411 | 407 | |
|---|
| 412 | | -static struct filter_arg * |
|---|
| 413 | | -create_arg_exp(enum filter_exp_type etype) |
|---|
| 408 | +static struct tep_filter_arg * |
|---|
| 409 | +create_arg_exp(enum tep_filter_exp_type etype) |
|---|
| 414 | 410 | { |
|---|
| 415 | | - struct filter_arg *arg; |
|---|
| 411 | + struct tep_filter_arg *arg; |
|---|
| 416 | 412 | |
|---|
| 417 | 413 | arg = allocate_arg(); |
|---|
| 418 | 414 | if (!arg) |
|---|
| 419 | 415 | return NULL; |
|---|
| 420 | 416 | |
|---|
| 421 | | - arg->type = FILTER_ARG_EXP; |
|---|
| 417 | + arg->type = TEP_FILTER_ARG_EXP; |
|---|
| 422 | 418 | arg->exp.type = etype; |
|---|
| 423 | 419 | |
|---|
| 424 | 420 | return arg; |
|---|
| 425 | 421 | } |
|---|
| 426 | 422 | |
|---|
| 427 | | -static struct filter_arg * |
|---|
| 428 | | -create_arg_cmp(enum filter_cmp_type ctype) |
|---|
| 423 | +static struct tep_filter_arg * |
|---|
| 424 | +create_arg_cmp(enum tep_filter_cmp_type ctype) |
|---|
| 429 | 425 | { |
|---|
| 430 | | - struct filter_arg *arg; |
|---|
| 426 | + struct tep_filter_arg *arg; |
|---|
| 431 | 427 | |
|---|
| 432 | 428 | arg = allocate_arg(); |
|---|
| 433 | 429 | if (!arg) |
|---|
| 434 | 430 | return NULL; |
|---|
| 435 | 431 | |
|---|
| 436 | 432 | /* Use NUM and change if necessary */ |
|---|
| 437 | | - arg->type = FILTER_ARG_NUM; |
|---|
| 433 | + arg->type = TEP_FILTER_ARG_NUM; |
|---|
| 438 | 434 | arg->num.type = ctype; |
|---|
| 439 | 435 | |
|---|
| 440 | 436 | return arg; |
|---|
| 441 | 437 | } |
|---|
| 442 | 438 | |
|---|
| 443 | 439 | static enum tep_errno |
|---|
| 444 | | -add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str) |
|---|
| 440 | +add_right(struct tep_filter_arg *op, struct tep_filter_arg *arg, char *error_str) |
|---|
| 445 | 441 | { |
|---|
| 446 | | - struct filter_arg *left; |
|---|
| 442 | + struct tep_filter_arg *left; |
|---|
| 447 | 443 | char *str; |
|---|
| 448 | 444 | int op_type; |
|---|
| 449 | 445 | int ret; |
|---|
| 450 | 446 | |
|---|
| 451 | 447 | switch (op->type) { |
|---|
| 452 | | - case FILTER_ARG_EXP: |
|---|
| 448 | + case TEP_FILTER_ARG_EXP: |
|---|
| 453 | 449 | if (op->exp.right) |
|---|
| 454 | 450 | goto out_fail; |
|---|
| 455 | 451 | op->exp.right = arg; |
|---|
| 456 | 452 | break; |
|---|
| 457 | 453 | |
|---|
| 458 | | - case FILTER_ARG_OP: |
|---|
| 454 | + case TEP_FILTER_ARG_OP: |
|---|
| 459 | 455 | if (op->op.right) |
|---|
| 460 | 456 | goto out_fail; |
|---|
| 461 | 457 | op->op.right = arg; |
|---|
| 462 | 458 | break; |
|---|
| 463 | 459 | |
|---|
| 464 | | - case FILTER_ARG_NUM: |
|---|
| 460 | + case TEP_FILTER_ARG_NUM: |
|---|
| 465 | 461 | if (op->op.right) |
|---|
| 466 | 462 | goto out_fail; |
|---|
| 467 | 463 | /* |
|---|
| 468 | 464 | * The arg must be num, str, or field |
|---|
| 469 | 465 | */ |
|---|
| 470 | 466 | switch (arg->type) { |
|---|
| 471 | | - case FILTER_ARG_VALUE: |
|---|
| 472 | | - case FILTER_ARG_FIELD: |
|---|
| 467 | + case TEP_FILTER_ARG_VALUE: |
|---|
| 468 | + case TEP_FILTER_ARG_FIELD: |
|---|
| 473 | 469 | break; |
|---|
| 474 | 470 | default: |
|---|
| 475 | 471 | show_error(error_str, "Illegal rvalue"); |
|---|
| .. | .. |
|---|
| 481 | 477 | * convert this to a string or regex. |
|---|
| 482 | 478 | */ |
|---|
| 483 | 479 | switch (arg->value.type) { |
|---|
| 484 | | - case FILTER_CHAR: |
|---|
| 480 | + case TEP_FILTER_CHAR: |
|---|
| 485 | 481 | /* |
|---|
| 486 | 482 | * A char should be converted to number if |
|---|
| 487 | 483 | * the string is 1 byte, and the compare |
|---|
| 488 | 484 | * is not a REGEX. |
|---|
| 489 | 485 | */ |
|---|
| 490 | 486 | if (strlen(arg->value.str) == 1 && |
|---|
| 491 | | - op->num.type != FILTER_CMP_REGEX && |
|---|
| 492 | | - op->num.type != FILTER_CMP_NOT_REGEX) { |
|---|
| 493 | | - arg->value.type = FILTER_NUMBER; |
|---|
| 487 | + op->num.type != TEP_FILTER_CMP_REGEX && |
|---|
| 488 | + op->num.type != TEP_FILTER_CMP_NOT_REGEX) { |
|---|
| 489 | + arg->value.type = TEP_FILTER_NUMBER; |
|---|
| 494 | 490 | goto do_int; |
|---|
| 495 | 491 | } |
|---|
| 496 | 492 | /* fall through */ |
|---|
| 497 | | - case FILTER_STRING: |
|---|
| 493 | + case TEP_FILTER_STRING: |
|---|
| 498 | 494 | |
|---|
| 499 | 495 | /* convert op to a string arg */ |
|---|
| 500 | 496 | op_type = op->num.type; |
|---|
| .. | .. |
|---|
| 508 | 504 | * If left arg was a field not found then |
|---|
| 509 | 505 | * NULL the entire op. |
|---|
| 510 | 506 | */ |
|---|
| 511 | | - if (left->type == FILTER_ARG_BOOLEAN) { |
|---|
| 507 | + if (left->type == TEP_FILTER_ARG_BOOLEAN) { |
|---|
| 512 | 508 | free_arg(left); |
|---|
| 513 | 509 | free_arg(arg); |
|---|
| 514 | | - op->type = FILTER_ARG_BOOLEAN; |
|---|
| 515 | | - op->boolean.value = FILTER_FALSE; |
|---|
| 510 | + op->type = TEP_FILTER_ARG_BOOLEAN; |
|---|
| 511 | + op->boolean.value = TEP_FILTER_FALSE; |
|---|
| 516 | 512 | break; |
|---|
| 517 | 513 | } |
|---|
| 518 | 514 | |
|---|
| 519 | 515 | /* Left arg must be a field */ |
|---|
| 520 | | - if (left->type != FILTER_ARG_FIELD) { |
|---|
| 516 | + if (left->type != TEP_FILTER_ARG_FIELD) { |
|---|
| 521 | 517 | show_error(error_str, |
|---|
| 522 | 518 | "Illegal lvalue for string comparison"); |
|---|
| 523 | 519 | return TEP_ERRNO__ILLEGAL_LVALUE; |
|---|
| .. | .. |
|---|
| 525 | 521 | |
|---|
| 526 | 522 | /* Make sure this is a valid string compare */ |
|---|
| 527 | 523 | switch (op_type) { |
|---|
| 528 | | - case FILTER_CMP_EQ: |
|---|
| 529 | | - op_type = FILTER_CMP_MATCH; |
|---|
| 524 | + case TEP_FILTER_CMP_EQ: |
|---|
| 525 | + op_type = TEP_FILTER_CMP_MATCH; |
|---|
| 530 | 526 | break; |
|---|
| 531 | | - case FILTER_CMP_NE: |
|---|
| 532 | | - op_type = FILTER_CMP_NOT_MATCH; |
|---|
| 527 | + case TEP_FILTER_CMP_NE: |
|---|
| 528 | + op_type = TEP_FILTER_CMP_NOT_MATCH; |
|---|
| 533 | 529 | break; |
|---|
| 534 | 530 | |
|---|
| 535 | | - case FILTER_CMP_REGEX: |
|---|
| 536 | | - case FILTER_CMP_NOT_REGEX: |
|---|
| 531 | + case TEP_FILTER_CMP_REGEX: |
|---|
| 532 | + case TEP_FILTER_CMP_NOT_REGEX: |
|---|
| 537 | 533 | ret = regcomp(&op->str.reg, str, REG_ICASE|REG_NOSUB); |
|---|
| 538 | 534 | if (ret) { |
|---|
| 539 | 535 | show_error(error_str, |
|---|
| .. | .. |
|---|
| 548 | 544 | return TEP_ERRNO__ILLEGAL_STRING_CMP; |
|---|
| 549 | 545 | } |
|---|
| 550 | 546 | |
|---|
| 551 | | - op->type = FILTER_ARG_STR; |
|---|
| 547 | + op->type = TEP_FILTER_ARG_STR; |
|---|
| 552 | 548 | op->str.type = op_type; |
|---|
| 553 | 549 | op->str.field = left->field.field; |
|---|
| 554 | 550 | op->str.val = strdup(str); |
|---|
| .. | .. |
|---|
| 573 | 569 | |
|---|
| 574 | 570 | break; |
|---|
| 575 | 571 | |
|---|
| 576 | | - case FILTER_NUMBER: |
|---|
| 572 | + case TEP_FILTER_NUMBER: |
|---|
| 577 | 573 | |
|---|
| 578 | 574 | do_int: |
|---|
| 579 | 575 | switch (op->num.type) { |
|---|
| 580 | | - case FILTER_CMP_REGEX: |
|---|
| 581 | | - case FILTER_CMP_NOT_REGEX: |
|---|
| 576 | + case TEP_FILTER_CMP_REGEX: |
|---|
| 577 | + case TEP_FILTER_CMP_NOT_REGEX: |
|---|
| 582 | 578 | show_error(error_str, |
|---|
| 583 | 579 | "Op not allowed with integers"); |
|---|
| 584 | 580 | return TEP_ERRNO__ILLEGAL_INTEGER_CMP; |
|---|
| .. | .. |
|---|
| 605 | 601 | return TEP_ERRNO__SYNTAX_ERROR; |
|---|
| 606 | 602 | } |
|---|
| 607 | 603 | |
|---|
| 608 | | -static struct filter_arg * |
|---|
| 609 | | -rotate_op_right(struct filter_arg *a, struct filter_arg *b) |
|---|
| 604 | +static struct tep_filter_arg * |
|---|
| 605 | +rotate_op_right(struct tep_filter_arg *a, struct tep_filter_arg *b) |
|---|
| 610 | 606 | { |
|---|
| 611 | | - struct filter_arg *arg; |
|---|
| 607 | + struct tep_filter_arg *arg; |
|---|
| 612 | 608 | |
|---|
| 613 | 609 | arg = a->op.right; |
|---|
| 614 | 610 | a->op.right = b; |
|---|
| 615 | 611 | return arg; |
|---|
| 616 | 612 | } |
|---|
| 617 | 613 | |
|---|
| 618 | | -static enum tep_errno add_left(struct filter_arg *op, struct filter_arg *arg) |
|---|
| 614 | +static enum tep_errno add_left(struct tep_filter_arg *op, struct tep_filter_arg *arg) |
|---|
| 619 | 615 | { |
|---|
| 620 | 616 | switch (op->type) { |
|---|
| 621 | | - case FILTER_ARG_EXP: |
|---|
| 622 | | - if (arg->type == FILTER_ARG_OP) |
|---|
| 617 | + case TEP_FILTER_ARG_EXP: |
|---|
| 618 | + if (arg->type == TEP_FILTER_ARG_OP) |
|---|
| 623 | 619 | arg = rotate_op_right(arg, op); |
|---|
| 624 | 620 | op->exp.left = arg; |
|---|
| 625 | 621 | break; |
|---|
| 626 | 622 | |
|---|
| 627 | | - case FILTER_ARG_OP: |
|---|
| 623 | + case TEP_FILTER_ARG_OP: |
|---|
| 628 | 624 | op->op.left = arg; |
|---|
| 629 | 625 | break; |
|---|
| 630 | | - case FILTER_ARG_NUM: |
|---|
| 631 | | - if (arg->type == FILTER_ARG_OP) |
|---|
| 626 | + case TEP_FILTER_ARG_NUM: |
|---|
| 627 | + if (arg->type == TEP_FILTER_ARG_OP) |
|---|
| 632 | 628 | arg = rotate_op_right(arg, op); |
|---|
| 633 | 629 | |
|---|
| 634 | 630 | /* left arg of compares must be a field */ |
|---|
| 635 | | - if (arg->type != FILTER_ARG_FIELD && |
|---|
| 636 | | - arg->type != FILTER_ARG_BOOLEAN) |
|---|
| 631 | + if (arg->type != TEP_FILTER_ARG_FIELD && |
|---|
| 632 | + arg->type != TEP_FILTER_ARG_BOOLEAN) |
|---|
| 637 | 633 | return TEP_ERRNO__INVALID_ARG_TYPE; |
|---|
| 638 | 634 | op->num.left = arg; |
|---|
| 639 | 635 | break; |
|---|
| .. | .. |
|---|
| 652 | 648 | }; |
|---|
| 653 | 649 | |
|---|
| 654 | 650 | static enum op_type process_op(const char *token, |
|---|
| 655 | | - enum filter_op_type *btype, |
|---|
| 656 | | - enum filter_cmp_type *ctype, |
|---|
| 657 | | - enum filter_exp_type *etype) |
|---|
| 651 | + enum tep_filter_op_type *btype, |
|---|
| 652 | + enum tep_filter_cmp_type *ctype, |
|---|
| 653 | + enum tep_filter_exp_type *etype) |
|---|
| 658 | 654 | { |
|---|
| 659 | | - *btype = FILTER_OP_NOT; |
|---|
| 660 | | - *etype = FILTER_EXP_NONE; |
|---|
| 661 | | - *ctype = FILTER_CMP_NONE; |
|---|
| 655 | + *btype = TEP_FILTER_OP_NOT; |
|---|
| 656 | + *etype = TEP_FILTER_EXP_NONE; |
|---|
| 657 | + *ctype = TEP_FILTER_CMP_NONE; |
|---|
| 662 | 658 | |
|---|
| 663 | 659 | if (strcmp(token, "&&") == 0) |
|---|
| 664 | | - *btype = FILTER_OP_AND; |
|---|
| 660 | + *btype = TEP_FILTER_OP_AND; |
|---|
| 665 | 661 | else if (strcmp(token, "||") == 0) |
|---|
| 666 | | - *btype = FILTER_OP_OR; |
|---|
| 662 | + *btype = TEP_FILTER_OP_OR; |
|---|
| 667 | 663 | else if (strcmp(token, "!") == 0) |
|---|
| 668 | 664 | return OP_NOT; |
|---|
| 669 | 665 | |
|---|
| 670 | | - if (*btype != FILTER_OP_NOT) |
|---|
| 666 | + if (*btype != TEP_FILTER_OP_NOT) |
|---|
| 671 | 667 | return OP_BOOL; |
|---|
| 672 | 668 | |
|---|
| 673 | 669 | /* Check for value expressions */ |
|---|
| 674 | 670 | if (strcmp(token, "+") == 0) { |
|---|
| 675 | | - *etype = FILTER_EXP_ADD; |
|---|
| 671 | + *etype = TEP_FILTER_EXP_ADD; |
|---|
| 676 | 672 | } else if (strcmp(token, "-") == 0) { |
|---|
| 677 | | - *etype = FILTER_EXP_SUB; |
|---|
| 673 | + *etype = TEP_FILTER_EXP_SUB; |
|---|
| 678 | 674 | } else if (strcmp(token, "*") == 0) { |
|---|
| 679 | | - *etype = FILTER_EXP_MUL; |
|---|
| 675 | + *etype = TEP_FILTER_EXP_MUL; |
|---|
| 680 | 676 | } else if (strcmp(token, "/") == 0) { |
|---|
| 681 | | - *etype = FILTER_EXP_DIV; |
|---|
| 677 | + *etype = TEP_FILTER_EXP_DIV; |
|---|
| 682 | 678 | } else if (strcmp(token, "%") == 0) { |
|---|
| 683 | | - *etype = FILTER_EXP_MOD; |
|---|
| 679 | + *etype = TEP_FILTER_EXP_MOD; |
|---|
| 684 | 680 | } else if (strcmp(token, ">>") == 0) { |
|---|
| 685 | | - *etype = FILTER_EXP_RSHIFT; |
|---|
| 681 | + *etype = TEP_FILTER_EXP_RSHIFT; |
|---|
| 686 | 682 | } else if (strcmp(token, "<<") == 0) { |
|---|
| 687 | | - *etype = FILTER_EXP_LSHIFT; |
|---|
| 683 | + *etype = TEP_FILTER_EXP_LSHIFT; |
|---|
| 688 | 684 | } else if (strcmp(token, "&") == 0) { |
|---|
| 689 | | - *etype = FILTER_EXP_AND; |
|---|
| 685 | + *etype = TEP_FILTER_EXP_AND; |
|---|
| 690 | 686 | } else if (strcmp(token, "|") == 0) { |
|---|
| 691 | | - *etype = FILTER_EXP_OR; |
|---|
| 687 | + *etype = TEP_FILTER_EXP_OR; |
|---|
| 692 | 688 | } else if (strcmp(token, "^") == 0) { |
|---|
| 693 | | - *etype = FILTER_EXP_XOR; |
|---|
| 689 | + *etype = TEP_FILTER_EXP_XOR; |
|---|
| 694 | 690 | } else if (strcmp(token, "~") == 0) |
|---|
| 695 | | - *etype = FILTER_EXP_NOT; |
|---|
| 691 | + *etype = TEP_FILTER_EXP_NOT; |
|---|
| 696 | 692 | |
|---|
| 697 | | - if (*etype != FILTER_EXP_NONE) |
|---|
| 693 | + if (*etype != TEP_FILTER_EXP_NONE) |
|---|
| 698 | 694 | return OP_EXP; |
|---|
| 699 | 695 | |
|---|
| 700 | 696 | /* Check for compares */ |
|---|
| 701 | 697 | if (strcmp(token, "==") == 0) |
|---|
| 702 | | - *ctype = FILTER_CMP_EQ; |
|---|
| 698 | + *ctype = TEP_FILTER_CMP_EQ; |
|---|
| 703 | 699 | else if (strcmp(token, "!=") == 0) |
|---|
| 704 | | - *ctype = FILTER_CMP_NE; |
|---|
| 700 | + *ctype = TEP_FILTER_CMP_NE; |
|---|
| 705 | 701 | else if (strcmp(token, "<") == 0) |
|---|
| 706 | | - *ctype = FILTER_CMP_LT; |
|---|
| 702 | + *ctype = TEP_FILTER_CMP_LT; |
|---|
| 707 | 703 | else if (strcmp(token, ">") == 0) |
|---|
| 708 | | - *ctype = FILTER_CMP_GT; |
|---|
| 704 | + *ctype = TEP_FILTER_CMP_GT; |
|---|
| 709 | 705 | else if (strcmp(token, "<=") == 0) |
|---|
| 710 | | - *ctype = FILTER_CMP_LE; |
|---|
| 706 | + *ctype = TEP_FILTER_CMP_LE; |
|---|
| 711 | 707 | else if (strcmp(token, ">=") == 0) |
|---|
| 712 | | - *ctype = FILTER_CMP_GE; |
|---|
| 708 | + *ctype = TEP_FILTER_CMP_GE; |
|---|
| 713 | 709 | else if (strcmp(token, "=~") == 0) |
|---|
| 714 | | - *ctype = FILTER_CMP_REGEX; |
|---|
| 710 | + *ctype = TEP_FILTER_CMP_REGEX; |
|---|
| 715 | 711 | else if (strcmp(token, "!~") == 0) |
|---|
| 716 | | - *ctype = FILTER_CMP_NOT_REGEX; |
|---|
| 712 | + *ctype = TEP_FILTER_CMP_NOT_REGEX; |
|---|
| 717 | 713 | else |
|---|
| 718 | 714 | return OP_NONE; |
|---|
| 719 | 715 | |
|---|
| 720 | 716 | return OP_CMP; |
|---|
| 721 | 717 | } |
|---|
| 722 | 718 | |
|---|
| 723 | | -static int check_op_done(struct filter_arg *arg) |
|---|
| 719 | +static int check_op_done(struct tep_filter_arg *arg) |
|---|
| 724 | 720 | { |
|---|
| 725 | 721 | switch (arg->type) { |
|---|
| 726 | | - case FILTER_ARG_EXP: |
|---|
| 722 | + case TEP_FILTER_ARG_EXP: |
|---|
| 727 | 723 | return arg->exp.right != NULL; |
|---|
| 728 | 724 | |
|---|
| 729 | | - case FILTER_ARG_OP: |
|---|
| 725 | + case TEP_FILTER_ARG_OP: |
|---|
| 730 | 726 | return arg->op.right != NULL; |
|---|
| 731 | 727 | |
|---|
| 732 | | - case FILTER_ARG_NUM: |
|---|
| 728 | + case TEP_FILTER_ARG_NUM: |
|---|
| 733 | 729 | return arg->num.right != NULL; |
|---|
| 734 | 730 | |
|---|
| 735 | | - case FILTER_ARG_STR: |
|---|
| 731 | + case TEP_FILTER_ARG_STR: |
|---|
| 736 | 732 | /* A string conversion is always done */ |
|---|
| 737 | 733 | return 1; |
|---|
| 738 | 734 | |
|---|
| 739 | | - case FILTER_ARG_BOOLEAN: |
|---|
| 735 | + case TEP_FILTER_ARG_BOOLEAN: |
|---|
| 740 | 736 | /* field not found, is ok */ |
|---|
| 741 | 737 | return 1; |
|---|
| 742 | 738 | |
|---|
| .. | .. |
|---|
| 752 | 748 | }; |
|---|
| 753 | 749 | |
|---|
| 754 | 750 | static enum tep_errno |
|---|
| 755 | | -reparent_op_arg(struct filter_arg *parent, struct filter_arg *old_child, |
|---|
| 756 | | - struct filter_arg *arg, char *error_str) |
|---|
| 751 | +reparent_op_arg(struct tep_filter_arg *parent, struct tep_filter_arg *old_child, |
|---|
| 752 | + struct tep_filter_arg *arg, char *error_str) |
|---|
| 757 | 753 | { |
|---|
| 758 | | - struct filter_arg *other_child; |
|---|
| 759 | | - struct filter_arg **ptr; |
|---|
| 754 | + struct tep_filter_arg *other_child; |
|---|
| 755 | + struct tep_filter_arg **ptr; |
|---|
| 760 | 756 | |
|---|
| 761 | | - if (parent->type != FILTER_ARG_OP && |
|---|
| 762 | | - arg->type != FILTER_ARG_OP) { |
|---|
| 757 | + if (parent->type != TEP_FILTER_ARG_OP && |
|---|
| 758 | + arg->type != TEP_FILTER_ARG_OP) { |
|---|
| 763 | 759 | show_error(error_str, "can not reparent other than OP"); |
|---|
| 764 | 760 | return TEP_ERRNO__REPARENT_NOT_OP; |
|---|
| 765 | 761 | } |
|---|
| .. | .. |
|---|
| 804 | 800 | } |
|---|
| 805 | 801 | |
|---|
| 806 | 802 | /* Returns either filter_vals (success) or tep_errno (failfure) */ |
|---|
| 807 | | -static int test_arg(struct filter_arg *parent, struct filter_arg *arg, |
|---|
| 803 | +static int test_arg(struct tep_filter_arg *parent, struct tep_filter_arg *arg, |
|---|
| 808 | 804 | char *error_str) |
|---|
| 809 | 805 | { |
|---|
| 810 | 806 | int lval, rval; |
|---|
| .. | .. |
|---|
| 812 | 808 | switch (arg->type) { |
|---|
| 813 | 809 | |
|---|
| 814 | 810 | /* bad case */ |
|---|
| 815 | | - case FILTER_ARG_BOOLEAN: |
|---|
| 811 | + case TEP_FILTER_ARG_BOOLEAN: |
|---|
| 816 | 812 | return FILTER_VAL_FALSE + arg->boolean.value; |
|---|
| 817 | 813 | |
|---|
| 818 | 814 | /* good cases: */ |
|---|
| 819 | | - case FILTER_ARG_STR: |
|---|
| 820 | | - case FILTER_ARG_VALUE: |
|---|
| 821 | | - case FILTER_ARG_FIELD: |
|---|
| 815 | + case TEP_FILTER_ARG_STR: |
|---|
| 816 | + case TEP_FILTER_ARG_VALUE: |
|---|
| 817 | + case TEP_FILTER_ARG_FIELD: |
|---|
| 822 | 818 | return FILTER_VAL_NORM; |
|---|
| 823 | 819 | |
|---|
| 824 | | - case FILTER_ARG_EXP: |
|---|
| 820 | + case TEP_FILTER_ARG_EXP: |
|---|
| 825 | 821 | lval = test_arg(arg, arg->exp.left, error_str); |
|---|
| 826 | 822 | if (lval != FILTER_VAL_NORM) |
|---|
| 827 | 823 | return lval; |
|---|
| .. | .. |
|---|
| 830 | 826 | return rval; |
|---|
| 831 | 827 | return FILTER_VAL_NORM; |
|---|
| 832 | 828 | |
|---|
| 833 | | - case FILTER_ARG_NUM: |
|---|
| 829 | + case TEP_FILTER_ARG_NUM: |
|---|
| 834 | 830 | lval = test_arg(arg, arg->num.left, error_str); |
|---|
| 835 | 831 | if (lval != FILTER_VAL_NORM) |
|---|
| 836 | 832 | return lval; |
|---|
| .. | .. |
|---|
| 839 | 835 | return rval; |
|---|
| 840 | 836 | return FILTER_VAL_NORM; |
|---|
| 841 | 837 | |
|---|
| 842 | | - case FILTER_ARG_OP: |
|---|
| 843 | | - if (arg->op.type != FILTER_OP_NOT) { |
|---|
| 838 | + case TEP_FILTER_ARG_OP: |
|---|
| 839 | + if (arg->op.type != TEP_FILTER_OP_NOT) { |
|---|
| 844 | 840 | lval = test_arg(arg, arg->op.left, error_str); |
|---|
| 845 | 841 | switch (lval) { |
|---|
| 846 | 842 | case FILTER_VAL_NORM: |
|---|
| 847 | 843 | break; |
|---|
| 848 | 844 | case FILTER_VAL_TRUE: |
|---|
| 849 | | - if (arg->op.type == FILTER_OP_OR) |
|---|
| 845 | + if (arg->op.type == TEP_FILTER_OP_OR) |
|---|
| 850 | 846 | return FILTER_VAL_TRUE; |
|---|
| 851 | 847 | rval = test_arg(arg, arg->op.right, error_str); |
|---|
| 852 | 848 | if (rval != FILTER_VAL_NORM) |
|---|
| .. | .. |
|---|
| 856 | 852 | error_str); |
|---|
| 857 | 853 | |
|---|
| 858 | 854 | case FILTER_VAL_FALSE: |
|---|
| 859 | | - if (arg->op.type == FILTER_OP_AND) |
|---|
| 855 | + if (arg->op.type == TEP_FILTER_OP_AND) |
|---|
| 860 | 856 | return FILTER_VAL_FALSE; |
|---|
| 861 | 857 | rval = test_arg(arg, arg->op.right, error_str); |
|---|
| 862 | 858 | if (rval != FILTER_VAL_NORM) |
|---|
| .. | .. |
|---|
| 877 | 873 | break; |
|---|
| 878 | 874 | |
|---|
| 879 | 875 | case FILTER_VAL_TRUE: |
|---|
| 880 | | - if (arg->op.type == FILTER_OP_OR) |
|---|
| 876 | + if (arg->op.type == TEP_FILTER_OP_OR) |
|---|
| 881 | 877 | return FILTER_VAL_TRUE; |
|---|
| 882 | | - if (arg->op.type == FILTER_OP_NOT) |
|---|
| 878 | + if (arg->op.type == TEP_FILTER_OP_NOT) |
|---|
| 883 | 879 | return FILTER_VAL_FALSE; |
|---|
| 884 | 880 | |
|---|
| 885 | 881 | return reparent_op_arg(parent, arg, arg->op.left, |
|---|
| 886 | 882 | error_str); |
|---|
| 887 | 883 | |
|---|
| 888 | 884 | case FILTER_VAL_FALSE: |
|---|
| 889 | | - if (arg->op.type == FILTER_OP_AND) |
|---|
| 885 | + if (arg->op.type == TEP_FILTER_OP_AND) |
|---|
| 890 | 886 | return FILTER_VAL_FALSE; |
|---|
| 891 | | - if (arg->op.type == FILTER_OP_NOT) |
|---|
| 887 | + if (arg->op.type == TEP_FILTER_OP_NOT) |
|---|
| 892 | 888 | return FILTER_VAL_TRUE; |
|---|
| 893 | 889 | |
|---|
| 894 | 890 | return reparent_op_arg(parent, arg, arg->op.left, |
|---|
| .. | .. |
|---|
| 904 | 900 | } |
|---|
| 905 | 901 | |
|---|
| 906 | 902 | /* Remove any unknown event fields */ |
|---|
| 907 | | -static int collapse_tree(struct filter_arg *arg, |
|---|
| 908 | | - struct filter_arg **arg_collapsed, char *error_str) |
|---|
| 903 | +static int collapse_tree(struct tep_filter_arg *arg, |
|---|
| 904 | + struct tep_filter_arg **arg_collapsed, char *error_str) |
|---|
| 909 | 905 | { |
|---|
| 910 | 906 | int ret; |
|---|
| 911 | 907 | |
|---|
| .. | .. |
|---|
| 919 | 915 | free_arg(arg); |
|---|
| 920 | 916 | arg = allocate_arg(); |
|---|
| 921 | 917 | if (arg) { |
|---|
| 922 | | - arg->type = FILTER_ARG_BOOLEAN; |
|---|
| 918 | + arg->type = TEP_FILTER_ARG_BOOLEAN; |
|---|
| 923 | 919 | arg->boolean.value = ret == FILTER_VAL_TRUE; |
|---|
| 924 | 920 | } else { |
|---|
| 925 | 921 | show_error(error_str, "Failed to allocate filter arg"); |
|---|
| .. | .. |
|---|
| 939 | 935 | } |
|---|
| 940 | 936 | |
|---|
| 941 | 937 | static enum tep_errno |
|---|
| 942 | | -process_filter(struct event_format *event, struct filter_arg **parg, |
|---|
| 938 | +process_filter(struct tep_event *event, struct tep_filter_arg **parg, |
|---|
| 943 | 939 | char *error_str, int not) |
|---|
| 944 | 940 | { |
|---|
| 945 | | - enum event_type type; |
|---|
| 941 | + enum tep_event_type type; |
|---|
| 946 | 942 | char *token = NULL; |
|---|
| 947 | | - struct filter_arg *current_op = NULL; |
|---|
| 948 | | - struct filter_arg *current_exp = NULL; |
|---|
| 949 | | - struct filter_arg *left_item = NULL; |
|---|
| 950 | | - struct filter_arg *arg = NULL; |
|---|
| 943 | + struct tep_filter_arg *current_op = NULL; |
|---|
| 944 | + struct tep_filter_arg *current_exp = NULL; |
|---|
| 945 | + struct tep_filter_arg *left_item = NULL; |
|---|
| 946 | + struct tep_filter_arg *arg = NULL; |
|---|
| 951 | 947 | enum op_type op_type; |
|---|
| 952 | | - enum filter_op_type btype; |
|---|
| 953 | | - enum filter_exp_type etype; |
|---|
| 954 | | - enum filter_cmp_type ctype; |
|---|
| 948 | + enum tep_filter_op_type btype; |
|---|
| 949 | + enum tep_filter_exp_type etype; |
|---|
| 950 | + enum tep_filter_cmp_type ctype; |
|---|
| 955 | 951 | enum tep_errno ret; |
|---|
| 956 | 952 | |
|---|
| 957 | 953 | *parg = NULL; |
|---|
| 958 | 954 | |
|---|
| 959 | 955 | do { |
|---|
| 960 | 956 | free(token); |
|---|
| 961 | | - type = read_token(&token); |
|---|
| 957 | + type = filter_read_token(&token); |
|---|
| 962 | 958 | switch (type) { |
|---|
| 963 | | - case EVENT_SQUOTE: |
|---|
| 964 | | - case EVENT_DQUOTE: |
|---|
| 965 | | - case EVENT_ITEM: |
|---|
| 959 | + case TEP_EVENT_SQUOTE: |
|---|
| 960 | + case TEP_EVENT_DQUOTE: |
|---|
| 961 | + case TEP_EVENT_ITEM: |
|---|
| 966 | 962 | ret = create_arg_item(event, token, type, &arg, error_str); |
|---|
| 967 | 963 | if (ret < 0) |
|---|
| 968 | 964 | goto fail; |
|---|
| .. | .. |
|---|
| 987 | 983 | arg = NULL; |
|---|
| 988 | 984 | break; |
|---|
| 989 | 985 | |
|---|
| 990 | | - case EVENT_DELIM: |
|---|
| 986 | + case TEP_EVENT_DELIM: |
|---|
| 991 | 987 | if (*token == ',') { |
|---|
| 992 | 988 | show_error(error_str, "Illegal token ','"); |
|---|
| 993 | 989 | ret = TEP_ERRNO__ILLEGAL_TOKEN; |
|---|
| .. | .. |
|---|
| 1054 | 1050 | } |
|---|
| 1055 | 1051 | break; |
|---|
| 1056 | 1052 | |
|---|
| 1057 | | - case EVENT_OP: |
|---|
| 1053 | + case TEP_EVENT_OP: |
|---|
| 1058 | 1054 | op_type = process_op(token, &btype, &ctype, &etype); |
|---|
| 1059 | 1055 | |
|---|
| 1060 | 1056 | /* All expect a left arg except for NOT */ |
|---|
| .. | .. |
|---|
| 1139 | 1135 | if (ret < 0) |
|---|
| 1140 | 1136 | goto fail_syntax; |
|---|
| 1141 | 1137 | break; |
|---|
| 1142 | | - case EVENT_NONE: |
|---|
| 1138 | + case TEP_EVENT_NONE: |
|---|
| 1143 | 1139 | break; |
|---|
| 1144 | | - case EVENT_ERROR: |
|---|
| 1140 | + case TEP_EVENT_ERROR: |
|---|
| 1145 | 1141 | goto fail_alloc; |
|---|
| 1146 | 1142 | default: |
|---|
| 1147 | 1143 | goto fail_syntax; |
|---|
| 1148 | 1144 | } |
|---|
| 1149 | | - } while (type != EVENT_NONE); |
|---|
| 1145 | + } while (type != TEP_EVENT_NONE); |
|---|
| 1150 | 1146 | |
|---|
| 1151 | 1147 | if (!current_op && !current_exp) |
|---|
| 1152 | 1148 | goto fail_syntax; |
|---|
| .. | .. |
|---|
| 1179 | 1175 | } |
|---|
| 1180 | 1176 | |
|---|
| 1181 | 1177 | static enum tep_errno |
|---|
| 1182 | | -process_event(struct event_format *event, const char *filter_str, |
|---|
| 1183 | | - struct filter_arg **parg, char *error_str) |
|---|
| 1178 | +process_event(struct tep_event *event, const char *filter_str, |
|---|
| 1179 | + struct tep_filter_arg **parg, char *error_str) |
|---|
| 1184 | 1180 | { |
|---|
| 1185 | 1181 | int ret; |
|---|
| 1186 | 1182 | |
|---|
| 1187 | | - tep_buffer_init(filter_str, strlen(filter_str)); |
|---|
| 1183 | + init_input_buf(filter_str, strlen(filter_str)); |
|---|
| 1188 | 1184 | |
|---|
| 1189 | 1185 | ret = process_filter(event, parg, error_str, 0); |
|---|
| 1190 | 1186 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 1196 | 1192 | if (*parg == NULL) |
|---|
| 1197 | 1193 | return TEP_ERRNO__MEM_ALLOC_FAILED; |
|---|
| 1198 | 1194 | |
|---|
| 1199 | | - (*parg)->type = FILTER_ARG_BOOLEAN; |
|---|
| 1200 | | - (*parg)->boolean.value = FILTER_FALSE; |
|---|
| 1195 | + (*parg)->type = TEP_FILTER_ARG_BOOLEAN; |
|---|
| 1196 | + (*parg)->boolean.value = TEP_FILTER_FALSE; |
|---|
| 1201 | 1197 | } |
|---|
| 1202 | 1198 | |
|---|
| 1203 | 1199 | return 0; |
|---|
| 1204 | 1200 | } |
|---|
| 1205 | 1201 | |
|---|
| 1206 | 1202 | static enum tep_errno |
|---|
| 1207 | | -filter_event(struct event_filter *filter, struct event_format *event, |
|---|
| 1203 | +filter_event(struct tep_event_filter *filter, struct tep_event *event, |
|---|
| 1208 | 1204 | const char *filter_str, char *error_str) |
|---|
| 1209 | 1205 | { |
|---|
| 1210 | | - struct filter_type *filter_type; |
|---|
| 1211 | | - struct filter_arg *arg; |
|---|
| 1206 | + struct tep_filter_type *filter_type; |
|---|
| 1207 | + struct tep_filter_arg *arg; |
|---|
| 1212 | 1208 | enum tep_errno ret; |
|---|
| 1213 | 1209 | |
|---|
| 1214 | 1210 | if (filter_str) { |
|---|
| .. | .. |
|---|
| 1222 | 1218 | if (arg == NULL) |
|---|
| 1223 | 1219 | return TEP_ERRNO__MEM_ALLOC_FAILED; |
|---|
| 1224 | 1220 | |
|---|
| 1225 | | - arg->type = FILTER_ARG_BOOLEAN; |
|---|
| 1226 | | - arg->boolean.value = FILTER_TRUE; |
|---|
| 1221 | + arg->type = TEP_FILTER_ARG_BOOLEAN; |
|---|
| 1222 | + arg->boolean.value = TEP_FILTER_TRUE; |
|---|
| 1227 | 1223 | } |
|---|
| 1228 | 1224 | |
|---|
| 1229 | 1225 | filter_type = add_filter_type(filter, event->id); |
|---|
| .. | .. |
|---|
| 1239 | 1235 | return 0; |
|---|
| 1240 | 1236 | } |
|---|
| 1241 | 1237 | |
|---|
| 1242 | | -static void filter_init_error_buf(struct event_filter *filter) |
|---|
| 1238 | +static void filter_init_error_buf(struct tep_event_filter *filter) |
|---|
| 1243 | 1239 | { |
|---|
| 1244 | 1240 | /* clear buffer to reset show error */ |
|---|
| 1245 | | - tep_buffer_init("", 0); |
|---|
| 1241 | + init_input_buf("", 0); |
|---|
| 1246 | 1242 | filter->error_buffer[0] = '\0'; |
|---|
| 1247 | 1243 | } |
|---|
| 1248 | 1244 | |
|---|
| .. | .. |
|---|
| 1255 | 1251 | * negative error code. Use tep_filter_strerror() to see |
|---|
| 1256 | 1252 | * actual error message in case of error. |
|---|
| 1257 | 1253 | */ |
|---|
| 1258 | | -enum tep_errno tep_filter_add_filter_str(struct event_filter *filter, |
|---|
| 1254 | +enum tep_errno tep_filter_add_filter_str(struct tep_event_filter *filter, |
|---|
| 1259 | 1255 | const char *filter_str) |
|---|
| 1260 | 1256 | { |
|---|
| 1261 | | - struct tep_handle *pevent = filter->pevent; |
|---|
| 1257 | + struct tep_handle *tep = filter->tep; |
|---|
| 1262 | 1258 | struct event_list *event; |
|---|
| 1263 | 1259 | struct event_list *events = NULL; |
|---|
| 1264 | 1260 | const char *filter_start; |
|---|
| .. | .. |
|---|
| 1314 | 1310 | } |
|---|
| 1315 | 1311 | |
|---|
| 1316 | 1312 | /* Find this event */ |
|---|
| 1317 | | - ret = find_event(pevent, &events, strim(sys_name), strim(event_name)); |
|---|
| 1313 | + ret = find_event(tep, &events, strim(sys_name), strim(event_name)); |
|---|
| 1318 | 1314 | if (ret < 0) { |
|---|
| 1319 | 1315 | free_events(events); |
|---|
| 1320 | 1316 | free(this_event); |
|---|
| .. | .. |
|---|
| 1335 | 1331 | if (ret < 0) |
|---|
| 1336 | 1332 | rtn = ret; |
|---|
| 1337 | 1333 | |
|---|
| 1338 | | - if (ret >= 0 && pevent->test_filters) { |
|---|
| 1334 | + if (ret >= 0 && tep->test_filters) { |
|---|
| 1339 | 1335 | char *test; |
|---|
| 1340 | 1336 | test = tep_filter_make_string(filter, event->event->id); |
|---|
| 1341 | 1337 | if (test) { |
|---|
| .. | .. |
|---|
| 1347 | 1343 | |
|---|
| 1348 | 1344 | free_events(events); |
|---|
| 1349 | 1345 | |
|---|
| 1350 | | - if (rtn >= 0 && pevent->test_filters) |
|---|
| 1351 | | - exit(0); |
|---|
| 1352 | | - |
|---|
| 1353 | 1346 | return rtn; |
|---|
| 1354 | 1347 | } |
|---|
| 1355 | 1348 | |
|---|
| 1356 | | -static void free_filter_type(struct filter_type *filter_type) |
|---|
| 1349 | +static void free_filter_type(struct tep_filter_type *filter_type) |
|---|
| 1357 | 1350 | { |
|---|
| 1358 | 1351 | free_arg(filter_type->filter); |
|---|
| 1359 | 1352 | } |
|---|
| .. | .. |
|---|
| 1367 | 1360 | * |
|---|
| 1368 | 1361 | * Returns 0 if message was filled successfully, -1 if error |
|---|
| 1369 | 1362 | */ |
|---|
| 1370 | | -int tep_filter_strerror(struct event_filter *filter, enum tep_errno err, |
|---|
| 1363 | +int tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err, |
|---|
| 1371 | 1364 | char *buf, size_t buflen) |
|---|
| 1372 | 1365 | { |
|---|
| 1373 | 1366 | if (err <= __TEP_ERRNO__START || err >= __TEP_ERRNO__END) |
|---|
| .. | .. |
|---|
| 1381 | 1374 | return 0; |
|---|
| 1382 | 1375 | } |
|---|
| 1383 | 1376 | |
|---|
| 1384 | | - return tep_strerror(filter->pevent, err, buf, buflen); |
|---|
| 1377 | + return tep_strerror(filter->tep, err, buf, buflen); |
|---|
| 1385 | 1378 | } |
|---|
| 1386 | 1379 | |
|---|
| 1387 | 1380 | /** |
|---|
| .. | .. |
|---|
| 1395 | 1388 | * Returns 1: if an event was removed |
|---|
| 1396 | 1389 | * 0: if the event was not found |
|---|
| 1397 | 1390 | */ |
|---|
| 1398 | | -int tep_filter_remove_event(struct event_filter *filter, |
|---|
| 1391 | +int tep_filter_remove_event(struct tep_event_filter *filter, |
|---|
| 1399 | 1392 | int event_id) |
|---|
| 1400 | 1393 | { |
|---|
| 1401 | | - struct filter_type *filter_type; |
|---|
| 1394 | + struct tep_filter_type *filter_type; |
|---|
| 1402 | 1395 | unsigned long len; |
|---|
| 1403 | 1396 | |
|---|
| 1404 | 1397 | if (!filter->filters) |
|---|
| .. | .. |
|---|
| 1430 | 1423 | * |
|---|
| 1431 | 1424 | * Removes all filters from a filter and resets it. |
|---|
| 1432 | 1425 | */ |
|---|
| 1433 | | -void tep_filter_reset(struct event_filter *filter) |
|---|
| 1426 | +void tep_filter_reset(struct tep_event_filter *filter) |
|---|
| 1434 | 1427 | { |
|---|
| 1435 | 1428 | int i; |
|---|
| 1436 | 1429 | |
|---|
| .. | .. |
|---|
| 1442 | 1435 | filter->event_filters = NULL; |
|---|
| 1443 | 1436 | } |
|---|
| 1444 | 1437 | |
|---|
| 1445 | | -void tep_filter_free(struct event_filter *filter) |
|---|
| 1438 | +void tep_filter_free(struct tep_event_filter *filter) |
|---|
| 1446 | 1439 | { |
|---|
| 1447 | | - tep_unref(filter->pevent); |
|---|
| 1440 | + tep_unref(filter->tep); |
|---|
| 1448 | 1441 | |
|---|
| 1449 | 1442 | tep_filter_reset(filter); |
|---|
| 1450 | 1443 | |
|---|
| 1451 | 1444 | free(filter); |
|---|
| 1452 | 1445 | } |
|---|
| 1453 | 1446 | |
|---|
| 1454 | | -static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg); |
|---|
| 1447 | +static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg); |
|---|
| 1455 | 1448 | |
|---|
| 1456 | | -static int copy_filter_type(struct event_filter *filter, |
|---|
| 1457 | | - struct event_filter *source, |
|---|
| 1458 | | - struct filter_type *filter_type) |
|---|
| 1449 | +static int copy_filter_type(struct tep_event_filter *filter, |
|---|
| 1450 | + struct tep_event_filter *source, |
|---|
| 1451 | + struct tep_filter_type *filter_type) |
|---|
| 1459 | 1452 | { |
|---|
| 1460 | | - struct filter_arg *arg; |
|---|
| 1461 | | - struct event_format *event; |
|---|
| 1453 | + struct tep_filter_arg *arg; |
|---|
| 1454 | + struct tep_event *event; |
|---|
| 1462 | 1455 | const char *sys; |
|---|
| 1463 | 1456 | const char *name; |
|---|
| 1464 | 1457 | char *str; |
|---|
| 1465 | 1458 | |
|---|
| 1466 | | - /* Can't assume that the pevent's are the same */ |
|---|
| 1459 | + /* Can't assume that the tep's are the same */ |
|---|
| 1467 | 1460 | sys = filter_type->event->system; |
|---|
| 1468 | 1461 | name = filter_type->event->name; |
|---|
| 1469 | | - event = tep_find_event_by_name(filter->pevent, sys, name); |
|---|
| 1462 | + event = tep_find_event_by_name(filter->tep, sys, name); |
|---|
| 1470 | 1463 | if (!event) |
|---|
| 1471 | 1464 | return -1; |
|---|
| 1472 | 1465 | |
|---|
| .. | .. |
|---|
| 1482 | 1475 | return -1; |
|---|
| 1483 | 1476 | } |
|---|
| 1484 | 1477 | |
|---|
| 1485 | | - arg->type = FILTER_ARG_BOOLEAN; |
|---|
| 1478 | + arg->type = TEP_FILTER_ARG_BOOLEAN; |
|---|
| 1486 | 1479 | if (strcmp(str, "TRUE") == 0) |
|---|
| 1487 | 1480 | arg->boolean.value = 1; |
|---|
| 1488 | 1481 | else |
|---|
| .. | .. |
|---|
| 1514 | 1507 | * |
|---|
| 1515 | 1508 | * Returns 0 on success and -1 if not all filters were copied |
|---|
| 1516 | 1509 | */ |
|---|
| 1517 | | -int tep_filter_copy(struct event_filter *dest, struct event_filter *source) |
|---|
| 1510 | +int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *source) |
|---|
| 1518 | 1511 | { |
|---|
| 1519 | 1512 | int ret = 0; |
|---|
| 1520 | 1513 | int i; |
|---|
| .. | .. |
|---|
| 1528 | 1521 | return ret; |
|---|
| 1529 | 1522 | } |
|---|
| 1530 | 1523 | |
|---|
| 1531 | | - |
|---|
| 1532 | | -/** |
|---|
| 1533 | | - * tep_update_trivial - update the trivial filters with the given filter |
|---|
| 1534 | | - * @dest - the filter to update |
|---|
| 1535 | | - * @source - the filter as the source of the update |
|---|
| 1536 | | - * @type - the type of trivial filter to update. |
|---|
| 1537 | | - * |
|---|
| 1538 | | - * Scan dest for trivial events matching @type to replace with the source. |
|---|
| 1539 | | - * |
|---|
| 1540 | | - * Returns 0 on success and -1 if there was a problem updating, but |
|---|
| 1541 | | - * events may have still been updated on error. |
|---|
| 1542 | | - */ |
|---|
| 1543 | | -int tep_update_trivial(struct event_filter *dest, struct event_filter *source, |
|---|
| 1544 | | - enum filter_trivial_type type) |
|---|
| 1545 | | -{ |
|---|
| 1546 | | - struct tep_handle *src_pevent; |
|---|
| 1547 | | - struct tep_handle *dest_pevent; |
|---|
| 1548 | | - struct event_format *event; |
|---|
| 1549 | | - struct filter_type *filter_type; |
|---|
| 1550 | | - struct filter_arg *arg; |
|---|
| 1551 | | - char *str; |
|---|
| 1552 | | - int i; |
|---|
| 1553 | | - |
|---|
| 1554 | | - src_pevent = source->pevent; |
|---|
| 1555 | | - dest_pevent = dest->pevent; |
|---|
| 1556 | | - |
|---|
| 1557 | | - /* Do nothing if either of the filters has nothing to filter */ |
|---|
| 1558 | | - if (!dest->filters || !source->filters) |
|---|
| 1559 | | - return 0; |
|---|
| 1560 | | - |
|---|
| 1561 | | - for (i = 0; i < dest->filters; i++) { |
|---|
| 1562 | | - filter_type = &dest->event_filters[i]; |
|---|
| 1563 | | - arg = filter_type->filter; |
|---|
| 1564 | | - if (arg->type != FILTER_ARG_BOOLEAN) |
|---|
| 1565 | | - continue; |
|---|
| 1566 | | - if ((arg->boolean.value && type == FILTER_TRIVIAL_FALSE) || |
|---|
| 1567 | | - (!arg->boolean.value && type == FILTER_TRIVIAL_TRUE)) |
|---|
| 1568 | | - continue; |
|---|
| 1569 | | - |
|---|
| 1570 | | - event = filter_type->event; |
|---|
| 1571 | | - |
|---|
| 1572 | | - if (src_pevent != dest_pevent) { |
|---|
| 1573 | | - /* do a look up */ |
|---|
| 1574 | | - event = tep_find_event_by_name(src_pevent, |
|---|
| 1575 | | - event->system, |
|---|
| 1576 | | - event->name); |
|---|
| 1577 | | - if (!event) |
|---|
| 1578 | | - return -1; |
|---|
| 1579 | | - } |
|---|
| 1580 | | - |
|---|
| 1581 | | - str = tep_filter_make_string(source, event->id); |
|---|
| 1582 | | - if (!str) |
|---|
| 1583 | | - continue; |
|---|
| 1584 | | - |
|---|
| 1585 | | - /* Don't bother if the filter is trivial too */ |
|---|
| 1586 | | - if (strcmp(str, "TRUE") != 0 && strcmp(str, "FALSE") != 0) |
|---|
| 1587 | | - filter_event(dest, event, str, NULL); |
|---|
| 1588 | | - free(str); |
|---|
| 1589 | | - } |
|---|
| 1590 | | - return 0; |
|---|
| 1591 | | -} |
|---|
| 1592 | | - |
|---|
| 1593 | | -/** |
|---|
| 1594 | | - * tep_filter_clear_trivial - clear TRUE and FALSE filters |
|---|
| 1595 | | - * @filter: the filter to remove trivial filters from |
|---|
| 1596 | | - * @type: remove only true, false, or both |
|---|
| 1597 | | - * |
|---|
| 1598 | | - * Removes filters that only contain a TRUE or FALES boolean arg. |
|---|
| 1599 | | - * |
|---|
| 1600 | | - * Returns 0 on success and -1 if there was a problem. |
|---|
| 1601 | | - */ |
|---|
| 1602 | | -int tep_filter_clear_trivial(struct event_filter *filter, |
|---|
| 1603 | | - enum filter_trivial_type type) |
|---|
| 1604 | | -{ |
|---|
| 1605 | | - struct filter_type *filter_type; |
|---|
| 1606 | | - int count = 0; |
|---|
| 1607 | | - int *ids = NULL; |
|---|
| 1608 | | - int i; |
|---|
| 1609 | | - |
|---|
| 1610 | | - if (!filter->filters) |
|---|
| 1611 | | - return 0; |
|---|
| 1612 | | - |
|---|
| 1613 | | - /* |
|---|
| 1614 | | - * Two steps, first get all ids with trivial filters. |
|---|
| 1615 | | - * then remove those ids. |
|---|
| 1616 | | - */ |
|---|
| 1617 | | - for (i = 0; i < filter->filters; i++) { |
|---|
| 1618 | | - int *new_ids; |
|---|
| 1619 | | - |
|---|
| 1620 | | - filter_type = &filter->event_filters[i]; |
|---|
| 1621 | | - if (filter_type->filter->type != FILTER_ARG_BOOLEAN) |
|---|
| 1622 | | - continue; |
|---|
| 1623 | | - switch (type) { |
|---|
| 1624 | | - case FILTER_TRIVIAL_FALSE: |
|---|
| 1625 | | - if (filter_type->filter->boolean.value) |
|---|
| 1626 | | - continue; |
|---|
| 1627 | | - break; |
|---|
| 1628 | | - case FILTER_TRIVIAL_TRUE: |
|---|
| 1629 | | - if (!filter_type->filter->boolean.value) |
|---|
| 1630 | | - continue; |
|---|
| 1631 | | - default: |
|---|
| 1632 | | - break; |
|---|
| 1633 | | - } |
|---|
| 1634 | | - |
|---|
| 1635 | | - new_ids = realloc(ids, sizeof(*ids) * (count + 1)); |
|---|
| 1636 | | - if (!new_ids) { |
|---|
| 1637 | | - free(ids); |
|---|
| 1638 | | - return -1; |
|---|
| 1639 | | - } |
|---|
| 1640 | | - |
|---|
| 1641 | | - ids = new_ids; |
|---|
| 1642 | | - ids[count++] = filter_type->event_id; |
|---|
| 1643 | | - } |
|---|
| 1644 | | - |
|---|
| 1645 | | - if (!count) |
|---|
| 1646 | | - return 0; |
|---|
| 1647 | | - |
|---|
| 1648 | | - for (i = 0; i < count; i++) |
|---|
| 1649 | | - tep_filter_remove_event(filter, ids[i]); |
|---|
| 1650 | | - |
|---|
| 1651 | | - free(ids); |
|---|
| 1652 | | - return 0; |
|---|
| 1653 | | -} |
|---|
| 1654 | | - |
|---|
| 1655 | | -/** |
|---|
| 1656 | | - * tep_filter_event_has_trivial - return true event contains trivial filter |
|---|
| 1657 | | - * @filter: the filter with the information |
|---|
| 1658 | | - * @event_id: the id of the event to test |
|---|
| 1659 | | - * @type: trivial type to test for (TRUE, FALSE, EITHER) |
|---|
| 1660 | | - * |
|---|
| 1661 | | - * Returns 1 if the event contains a matching trivial type |
|---|
| 1662 | | - * otherwise 0. |
|---|
| 1663 | | - */ |
|---|
| 1664 | | -int tep_filter_event_has_trivial(struct event_filter *filter, |
|---|
| 1665 | | - int event_id, |
|---|
| 1666 | | - enum filter_trivial_type type) |
|---|
| 1667 | | -{ |
|---|
| 1668 | | - struct filter_type *filter_type; |
|---|
| 1669 | | - |
|---|
| 1670 | | - if (!filter->filters) |
|---|
| 1671 | | - return 0; |
|---|
| 1672 | | - |
|---|
| 1673 | | - filter_type = find_filter_type(filter, event_id); |
|---|
| 1674 | | - |
|---|
| 1675 | | - if (!filter_type) |
|---|
| 1676 | | - return 0; |
|---|
| 1677 | | - |
|---|
| 1678 | | - if (filter_type->filter->type != FILTER_ARG_BOOLEAN) |
|---|
| 1679 | | - return 0; |
|---|
| 1680 | | - |
|---|
| 1681 | | - switch (type) { |
|---|
| 1682 | | - case FILTER_TRIVIAL_FALSE: |
|---|
| 1683 | | - return !filter_type->filter->boolean.value; |
|---|
| 1684 | | - |
|---|
| 1685 | | - case FILTER_TRIVIAL_TRUE: |
|---|
| 1686 | | - return filter_type->filter->boolean.value; |
|---|
| 1687 | | - default: |
|---|
| 1688 | | - return 1; |
|---|
| 1689 | | - } |
|---|
| 1690 | | -} |
|---|
| 1691 | | - |
|---|
| 1692 | | -static int test_filter(struct event_format *event, struct filter_arg *arg, |
|---|
| 1524 | +static int test_filter(struct tep_event *event, struct tep_filter_arg *arg, |
|---|
| 1693 | 1525 | struct tep_record *record, enum tep_errno *err); |
|---|
| 1694 | 1526 | |
|---|
| 1695 | 1527 | static const char * |
|---|
| 1696 | | -get_comm(struct event_format *event, struct tep_record *record) |
|---|
| 1528 | +get_comm(struct tep_event *event, struct tep_record *record) |
|---|
| 1697 | 1529 | { |
|---|
| 1698 | 1530 | const char *comm; |
|---|
| 1699 | 1531 | int pid; |
|---|
| 1700 | 1532 | |
|---|
| 1701 | | - pid = tep_data_pid(event->pevent, record); |
|---|
| 1702 | | - comm = tep_data_comm_from_pid(event->pevent, pid); |
|---|
| 1533 | + pid = tep_data_pid(event->tep, record); |
|---|
| 1534 | + comm = tep_data_comm_from_pid(event->tep, pid); |
|---|
| 1703 | 1535 | return comm; |
|---|
| 1704 | 1536 | } |
|---|
| 1705 | 1537 | |
|---|
| 1706 | 1538 | static unsigned long long |
|---|
| 1707 | | -get_value(struct event_format *event, |
|---|
| 1708 | | - struct format_field *field, struct tep_record *record) |
|---|
| 1539 | +get_value(struct tep_event *event, |
|---|
| 1540 | + struct tep_format_field *field, struct tep_record *record) |
|---|
| 1709 | 1541 | { |
|---|
| 1710 | 1542 | unsigned long long val; |
|---|
| 1711 | 1543 | |
|---|
| .. | .. |
|---|
| 1723 | 1555 | |
|---|
| 1724 | 1556 | tep_read_number_field(field, record->data, &val); |
|---|
| 1725 | 1557 | |
|---|
| 1726 | | - if (!(field->flags & FIELD_IS_SIGNED)) |
|---|
| 1558 | + if (!(field->flags & TEP_FIELD_IS_SIGNED)) |
|---|
| 1727 | 1559 | return val; |
|---|
| 1728 | 1560 | |
|---|
| 1729 | 1561 | switch (field->size) { |
|---|
| .. | .. |
|---|
| 1740 | 1572 | } |
|---|
| 1741 | 1573 | |
|---|
| 1742 | 1574 | static unsigned long long |
|---|
| 1743 | | -get_arg_value(struct event_format *event, struct filter_arg *arg, |
|---|
| 1575 | +get_arg_value(struct tep_event *event, struct tep_filter_arg *arg, |
|---|
| 1744 | 1576 | struct tep_record *record, enum tep_errno *err); |
|---|
| 1745 | 1577 | |
|---|
| 1746 | 1578 | static unsigned long long |
|---|
| 1747 | | -get_exp_value(struct event_format *event, struct filter_arg *arg, |
|---|
| 1579 | +get_exp_value(struct tep_event *event, struct tep_filter_arg *arg, |
|---|
| 1748 | 1580 | struct tep_record *record, enum tep_errno *err) |
|---|
| 1749 | 1581 | { |
|---|
| 1750 | 1582 | unsigned long long lval, rval; |
|---|
| .. | .. |
|---|
| 1760 | 1592 | } |
|---|
| 1761 | 1593 | |
|---|
| 1762 | 1594 | switch (arg->exp.type) { |
|---|
| 1763 | | - case FILTER_EXP_ADD: |
|---|
| 1595 | + case TEP_FILTER_EXP_ADD: |
|---|
| 1764 | 1596 | return lval + rval; |
|---|
| 1765 | 1597 | |
|---|
| 1766 | | - case FILTER_EXP_SUB: |
|---|
| 1598 | + case TEP_FILTER_EXP_SUB: |
|---|
| 1767 | 1599 | return lval - rval; |
|---|
| 1768 | 1600 | |
|---|
| 1769 | | - case FILTER_EXP_MUL: |
|---|
| 1601 | + case TEP_FILTER_EXP_MUL: |
|---|
| 1770 | 1602 | return lval * rval; |
|---|
| 1771 | 1603 | |
|---|
| 1772 | | - case FILTER_EXP_DIV: |
|---|
| 1604 | + case TEP_FILTER_EXP_DIV: |
|---|
| 1773 | 1605 | return lval / rval; |
|---|
| 1774 | 1606 | |
|---|
| 1775 | | - case FILTER_EXP_MOD: |
|---|
| 1607 | + case TEP_FILTER_EXP_MOD: |
|---|
| 1776 | 1608 | return lval % rval; |
|---|
| 1777 | 1609 | |
|---|
| 1778 | | - case FILTER_EXP_RSHIFT: |
|---|
| 1610 | + case TEP_FILTER_EXP_RSHIFT: |
|---|
| 1779 | 1611 | return lval >> rval; |
|---|
| 1780 | 1612 | |
|---|
| 1781 | | - case FILTER_EXP_LSHIFT: |
|---|
| 1613 | + case TEP_FILTER_EXP_LSHIFT: |
|---|
| 1782 | 1614 | return lval << rval; |
|---|
| 1783 | 1615 | |
|---|
| 1784 | | - case FILTER_EXP_AND: |
|---|
| 1616 | + case TEP_FILTER_EXP_AND: |
|---|
| 1785 | 1617 | return lval & rval; |
|---|
| 1786 | 1618 | |
|---|
| 1787 | | - case FILTER_EXP_OR: |
|---|
| 1619 | + case TEP_FILTER_EXP_OR: |
|---|
| 1788 | 1620 | return lval | rval; |
|---|
| 1789 | 1621 | |
|---|
| 1790 | | - case FILTER_EXP_XOR: |
|---|
| 1622 | + case TEP_FILTER_EXP_XOR: |
|---|
| 1791 | 1623 | return lval ^ rval; |
|---|
| 1792 | 1624 | |
|---|
| 1793 | | - case FILTER_EXP_NOT: |
|---|
| 1625 | + case TEP_FILTER_EXP_NOT: |
|---|
| 1794 | 1626 | default: |
|---|
| 1795 | 1627 | if (!*err) |
|---|
| 1796 | 1628 | *err = TEP_ERRNO__INVALID_EXP_TYPE; |
|---|
| .. | .. |
|---|
| 1799 | 1631 | } |
|---|
| 1800 | 1632 | |
|---|
| 1801 | 1633 | static unsigned long long |
|---|
| 1802 | | -get_arg_value(struct event_format *event, struct filter_arg *arg, |
|---|
| 1634 | +get_arg_value(struct tep_event *event, struct tep_filter_arg *arg, |
|---|
| 1803 | 1635 | struct tep_record *record, enum tep_errno *err) |
|---|
| 1804 | 1636 | { |
|---|
| 1805 | 1637 | switch (arg->type) { |
|---|
| 1806 | | - case FILTER_ARG_FIELD: |
|---|
| 1638 | + case TEP_FILTER_ARG_FIELD: |
|---|
| 1807 | 1639 | return get_value(event, arg->field.field, record); |
|---|
| 1808 | 1640 | |
|---|
| 1809 | | - case FILTER_ARG_VALUE: |
|---|
| 1810 | | - if (arg->value.type != FILTER_NUMBER) { |
|---|
| 1641 | + case TEP_FILTER_ARG_VALUE: |
|---|
| 1642 | + if (arg->value.type != TEP_FILTER_NUMBER) { |
|---|
| 1811 | 1643 | if (!*err) |
|---|
| 1812 | 1644 | *err = TEP_ERRNO__NOT_A_NUMBER; |
|---|
| 1813 | 1645 | } |
|---|
| 1814 | 1646 | return arg->value.val; |
|---|
| 1815 | 1647 | |
|---|
| 1816 | | - case FILTER_ARG_EXP: |
|---|
| 1648 | + case TEP_FILTER_ARG_EXP: |
|---|
| 1817 | 1649 | return get_exp_value(event, arg, record, err); |
|---|
| 1818 | 1650 | |
|---|
| 1819 | 1651 | default: |
|---|
| .. | .. |
|---|
| 1823 | 1655 | return 0; |
|---|
| 1824 | 1656 | } |
|---|
| 1825 | 1657 | |
|---|
| 1826 | | -static int test_num(struct event_format *event, struct filter_arg *arg, |
|---|
| 1658 | +static int test_num(struct tep_event *event, struct tep_filter_arg *arg, |
|---|
| 1827 | 1659 | struct tep_record *record, enum tep_errno *err) |
|---|
| 1828 | 1660 | { |
|---|
| 1829 | 1661 | unsigned long long lval, rval; |
|---|
| .. | .. |
|---|
| 1839 | 1671 | } |
|---|
| 1840 | 1672 | |
|---|
| 1841 | 1673 | switch (arg->num.type) { |
|---|
| 1842 | | - case FILTER_CMP_EQ: |
|---|
| 1674 | + case TEP_FILTER_CMP_EQ: |
|---|
| 1843 | 1675 | return lval == rval; |
|---|
| 1844 | 1676 | |
|---|
| 1845 | | - case FILTER_CMP_NE: |
|---|
| 1677 | + case TEP_FILTER_CMP_NE: |
|---|
| 1846 | 1678 | return lval != rval; |
|---|
| 1847 | 1679 | |
|---|
| 1848 | | - case FILTER_CMP_GT: |
|---|
| 1680 | + case TEP_FILTER_CMP_GT: |
|---|
| 1849 | 1681 | return lval > rval; |
|---|
| 1850 | 1682 | |
|---|
| 1851 | | - case FILTER_CMP_LT: |
|---|
| 1683 | + case TEP_FILTER_CMP_LT: |
|---|
| 1852 | 1684 | return lval < rval; |
|---|
| 1853 | 1685 | |
|---|
| 1854 | | - case FILTER_CMP_GE: |
|---|
| 1686 | + case TEP_FILTER_CMP_GE: |
|---|
| 1855 | 1687 | return lval >= rval; |
|---|
| 1856 | 1688 | |
|---|
| 1857 | | - case FILTER_CMP_LE: |
|---|
| 1689 | + case TEP_FILTER_CMP_LE: |
|---|
| 1858 | 1690 | return lval <= rval; |
|---|
| 1859 | 1691 | |
|---|
| 1860 | 1692 | default: |
|---|
| .. | .. |
|---|
| 1864 | 1696 | } |
|---|
| 1865 | 1697 | } |
|---|
| 1866 | 1698 | |
|---|
| 1867 | | -static const char *get_field_str(struct filter_arg *arg, struct tep_record *record) |
|---|
| 1699 | +static const char *get_field_str(struct tep_filter_arg *arg, struct tep_record *record) |
|---|
| 1868 | 1700 | { |
|---|
| 1869 | | - struct event_format *event; |
|---|
| 1870 | | - struct tep_handle *pevent; |
|---|
| 1701 | + struct tep_event *event; |
|---|
| 1702 | + struct tep_handle *tep; |
|---|
| 1871 | 1703 | unsigned long long addr; |
|---|
| 1872 | 1704 | const char *val = NULL; |
|---|
| 1873 | 1705 | unsigned int size; |
|---|
| 1874 | 1706 | char hex[64]; |
|---|
| 1875 | 1707 | |
|---|
| 1876 | 1708 | /* If the field is not a string convert it */ |
|---|
| 1877 | | - if (arg->str.field->flags & FIELD_IS_STRING) { |
|---|
| 1709 | + if (arg->str.field->flags & TEP_FIELD_IS_STRING) { |
|---|
| 1878 | 1710 | val = record->data + arg->str.field->offset; |
|---|
| 1879 | 1711 | size = arg->str.field->size; |
|---|
| 1880 | 1712 | |
|---|
| 1881 | | - if (arg->str.field->flags & FIELD_IS_DYNAMIC) { |
|---|
| 1713 | + if (arg->str.field->flags & TEP_FIELD_IS_DYNAMIC) { |
|---|
| 1882 | 1714 | addr = *(unsigned int *)val; |
|---|
| 1883 | 1715 | val = record->data + (addr & 0xffff); |
|---|
| 1884 | 1716 | size = addr >> 16; |
|---|
| .. | .. |
|---|
| 1897 | 1729 | |
|---|
| 1898 | 1730 | } else { |
|---|
| 1899 | 1731 | event = arg->str.field->event; |
|---|
| 1900 | | - pevent = event->pevent; |
|---|
| 1732 | + tep = event->tep; |
|---|
| 1901 | 1733 | addr = get_value(event, arg->str.field, record); |
|---|
| 1902 | 1734 | |
|---|
| 1903 | | - if (arg->str.field->flags & (FIELD_IS_POINTER | FIELD_IS_LONG)) |
|---|
| 1735 | + if (arg->str.field->flags & (TEP_FIELD_IS_POINTER | TEP_FIELD_IS_LONG)) |
|---|
| 1904 | 1736 | /* convert to a kernel symbol */ |
|---|
| 1905 | | - val = tep_find_function(pevent, addr); |
|---|
| 1737 | + val = tep_find_function(tep, addr); |
|---|
| 1906 | 1738 | |
|---|
| 1907 | 1739 | if (val == NULL) { |
|---|
| 1908 | 1740 | /* just use the hex of the string name */ |
|---|
| .. | .. |
|---|
| 1914 | 1746 | return val; |
|---|
| 1915 | 1747 | } |
|---|
| 1916 | 1748 | |
|---|
| 1917 | | -static int test_str(struct event_format *event, struct filter_arg *arg, |
|---|
| 1749 | +static int test_str(struct tep_event *event, struct tep_filter_arg *arg, |
|---|
| 1918 | 1750 | struct tep_record *record, enum tep_errno *err) |
|---|
| 1919 | 1751 | { |
|---|
| 1920 | 1752 | const char *val; |
|---|
| .. | .. |
|---|
| 1925 | 1757 | val = get_field_str(arg, record); |
|---|
| 1926 | 1758 | |
|---|
| 1927 | 1759 | switch (arg->str.type) { |
|---|
| 1928 | | - case FILTER_CMP_MATCH: |
|---|
| 1760 | + case TEP_FILTER_CMP_MATCH: |
|---|
| 1929 | 1761 | return strcmp(val, arg->str.val) == 0; |
|---|
| 1930 | 1762 | |
|---|
| 1931 | | - case FILTER_CMP_NOT_MATCH: |
|---|
| 1763 | + case TEP_FILTER_CMP_NOT_MATCH: |
|---|
| 1932 | 1764 | return strcmp(val, arg->str.val) != 0; |
|---|
| 1933 | 1765 | |
|---|
| 1934 | | - case FILTER_CMP_REGEX: |
|---|
| 1766 | + case TEP_FILTER_CMP_REGEX: |
|---|
| 1935 | 1767 | /* Returns zero on match */ |
|---|
| 1936 | 1768 | return !regexec(&arg->str.reg, val, 0, NULL, 0); |
|---|
| 1937 | 1769 | |
|---|
| 1938 | | - case FILTER_CMP_NOT_REGEX: |
|---|
| 1770 | + case TEP_FILTER_CMP_NOT_REGEX: |
|---|
| 1939 | 1771 | return regexec(&arg->str.reg, val, 0, NULL, 0); |
|---|
| 1940 | 1772 | |
|---|
| 1941 | 1773 | default: |
|---|
| .. | .. |
|---|
| 1945 | 1777 | } |
|---|
| 1946 | 1778 | } |
|---|
| 1947 | 1779 | |
|---|
| 1948 | | -static int test_op(struct event_format *event, struct filter_arg *arg, |
|---|
| 1780 | +static int test_op(struct tep_event *event, struct tep_filter_arg *arg, |
|---|
| 1949 | 1781 | struct tep_record *record, enum tep_errno *err) |
|---|
| 1950 | 1782 | { |
|---|
| 1951 | 1783 | switch (arg->op.type) { |
|---|
| 1952 | | - case FILTER_OP_AND: |
|---|
| 1784 | + case TEP_FILTER_OP_AND: |
|---|
| 1953 | 1785 | return test_filter(event, arg->op.left, record, err) && |
|---|
| 1954 | 1786 | test_filter(event, arg->op.right, record, err); |
|---|
| 1955 | 1787 | |
|---|
| 1956 | | - case FILTER_OP_OR: |
|---|
| 1788 | + case TEP_FILTER_OP_OR: |
|---|
| 1957 | 1789 | return test_filter(event, arg->op.left, record, err) || |
|---|
| 1958 | 1790 | test_filter(event, arg->op.right, record, err); |
|---|
| 1959 | 1791 | |
|---|
| 1960 | | - case FILTER_OP_NOT: |
|---|
| 1792 | + case TEP_FILTER_OP_NOT: |
|---|
| 1961 | 1793 | return !test_filter(event, arg->op.right, record, err); |
|---|
| 1962 | 1794 | |
|---|
| 1963 | 1795 | default: |
|---|
| .. | .. |
|---|
| 1967 | 1799 | } |
|---|
| 1968 | 1800 | } |
|---|
| 1969 | 1801 | |
|---|
| 1970 | | -static int test_filter(struct event_format *event, struct filter_arg *arg, |
|---|
| 1802 | +static int test_filter(struct tep_event *event, struct tep_filter_arg *arg, |
|---|
| 1971 | 1803 | struct tep_record *record, enum tep_errno *err) |
|---|
| 1972 | 1804 | { |
|---|
| 1973 | 1805 | if (*err) { |
|---|
| .. | .. |
|---|
| 1978 | 1810 | } |
|---|
| 1979 | 1811 | |
|---|
| 1980 | 1812 | switch (arg->type) { |
|---|
| 1981 | | - case FILTER_ARG_BOOLEAN: |
|---|
| 1813 | + case TEP_FILTER_ARG_BOOLEAN: |
|---|
| 1982 | 1814 | /* easy case */ |
|---|
| 1983 | 1815 | return arg->boolean.value; |
|---|
| 1984 | 1816 | |
|---|
| 1985 | | - case FILTER_ARG_OP: |
|---|
| 1817 | + case TEP_FILTER_ARG_OP: |
|---|
| 1986 | 1818 | return test_op(event, arg, record, err); |
|---|
| 1987 | 1819 | |
|---|
| 1988 | | - case FILTER_ARG_NUM: |
|---|
| 1820 | + case TEP_FILTER_ARG_NUM: |
|---|
| 1989 | 1821 | return test_num(event, arg, record, err); |
|---|
| 1990 | 1822 | |
|---|
| 1991 | | - case FILTER_ARG_STR: |
|---|
| 1823 | + case TEP_FILTER_ARG_STR: |
|---|
| 1992 | 1824 | return test_str(event, arg, record, err); |
|---|
| 1993 | 1825 | |
|---|
| 1994 | | - case FILTER_ARG_EXP: |
|---|
| 1995 | | - case FILTER_ARG_VALUE: |
|---|
| 1996 | | - case FILTER_ARG_FIELD: |
|---|
| 1826 | + case TEP_FILTER_ARG_EXP: |
|---|
| 1827 | + case TEP_FILTER_ARG_VALUE: |
|---|
| 1828 | + case TEP_FILTER_ARG_FIELD: |
|---|
| 1997 | 1829 | /* |
|---|
| 1998 | 1830 | * Expressions, fields and values evaluate |
|---|
| 1999 | 1831 | * to true if they return non zero |
|---|
| .. | .. |
|---|
| 2015 | 1847 | * Returns 1 if filter found for @event_id |
|---|
| 2016 | 1848 | * otherwise 0; |
|---|
| 2017 | 1849 | */ |
|---|
| 2018 | | -int tep_event_filtered(struct event_filter *filter, int event_id) |
|---|
| 1850 | +int tep_event_filtered(struct tep_event_filter *filter, int event_id) |
|---|
| 2019 | 1851 | { |
|---|
| 2020 | | - struct filter_type *filter_type; |
|---|
| 1852 | + struct tep_filter_type *filter_type; |
|---|
| 2021 | 1853 | |
|---|
| 2022 | 1854 | if (!filter->filters) |
|---|
| 2023 | 1855 | return 0; |
|---|
| .. | .. |
|---|
| 2039 | 1871 | * NO_FILTER - if no filters exist |
|---|
| 2040 | 1872 | * otherwise - error occurred during test |
|---|
| 2041 | 1873 | */ |
|---|
| 2042 | | -enum tep_errno tep_filter_match(struct event_filter *filter, |
|---|
| 1874 | +enum tep_errno tep_filter_match(struct tep_event_filter *filter, |
|---|
| 2043 | 1875 | struct tep_record *record) |
|---|
| 2044 | 1876 | { |
|---|
| 2045 | | - struct tep_handle *pevent = filter->pevent; |
|---|
| 2046 | | - struct filter_type *filter_type; |
|---|
| 1877 | + struct tep_handle *tep = filter->tep; |
|---|
| 1878 | + struct tep_filter_type *filter_type; |
|---|
| 2047 | 1879 | int event_id; |
|---|
| 2048 | 1880 | int ret; |
|---|
| 2049 | 1881 | enum tep_errno err = 0; |
|---|
| .. | .. |
|---|
| 2053 | 1885 | if (!filter->filters) |
|---|
| 2054 | 1886 | return TEP_ERRNO__NO_FILTER; |
|---|
| 2055 | 1887 | |
|---|
| 2056 | | - event_id = tep_data_type(pevent, record); |
|---|
| 1888 | + event_id = tep_data_type(tep, record); |
|---|
| 2057 | 1889 | |
|---|
| 2058 | 1890 | filter_type = find_filter_type(filter, event_id); |
|---|
| 2059 | 1891 | if (!filter_type) |
|---|
| .. | .. |
|---|
| 2066 | 1898 | return ret ? TEP_ERRNO__FILTER_MATCH : TEP_ERRNO__FILTER_MISS; |
|---|
| 2067 | 1899 | } |
|---|
| 2068 | 1900 | |
|---|
| 2069 | | -static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) |
|---|
| 1901 | +static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg) |
|---|
| 2070 | 1902 | { |
|---|
| 2071 | 1903 | char *str = NULL; |
|---|
| 2072 | 1904 | char *left = NULL; |
|---|
| .. | .. |
|---|
| 2077 | 1909 | int val; |
|---|
| 2078 | 1910 | |
|---|
| 2079 | 1911 | switch (arg->op.type) { |
|---|
| 2080 | | - case FILTER_OP_AND: |
|---|
| 1912 | + case TEP_FILTER_OP_AND: |
|---|
| 2081 | 1913 | op = "&&"; |
|---|
| 2082 | 1914 | /* fall through */ |
|---|
| 2083 | | - case FILTER_OP_OR: |
|---|
| 1915 | + case TEP_FILTER_OP_OR: |
|---|
| 2084 | 1916 | if (!op) |
|---|
| 2085 | 1917 | op = "||"; |
|---|
| 2086 | 1918 | |
|---|
| .. | .. |
|---|
| 2101 | 1933 | right_val = 0; |
|---|
| 2102 | 1934 | |
|---|
| 2103 | 1935 | if (left_val >= 0) { |
|---|
| 2104 | | - if ((arg->op.type == FILTER_OP_AND && !left_val) || |
|---|
| 2105 | | - (arg->op.type == FILTER_OP_OR && left_val)) { |
|---|
| 1936 | + if ((arg->op.type == TEP_FILTER_OP_AND && !left_val) || |
|---|
| 1937 | + (arg->op.type == TEP_FILTER_OP_OR && left_val)) { |
|---|
| 2106 | 1938 | /* Just return left value */ |
|---|
| 2107 | 1939 | str = left; |
|---|
| 2108 | 1940 | left = NULL; |
|---|
| .. | .. |
|---|
| 2112 | 1944 | /* just evaluate this. */ |
|---|
| 2113 | 1945 | val = 0; |
|---|
| 2114 | 1946 | switch (arg->op.type) { |
|---|
| 2115 | | - case FILTER_OP_AND: |
|---|
| 1947 | + case TEP_FILTER_OP_AND: |
|---|
| 2116 | 1948 | val = left_val && right_val; |
|---|
| 2117 | 1949 | break; |
|---|
| 2118 | | - case FILTER_OP_OR: |
|---|
| 1950 | + case TEP_FILTER_OP_OR: |
|---|
| 2119 | 1951 | val = left_val || right_val; |
|---|
| 2120 | 1952 | break; |
|---|
| 2121 | 1953 | default: |
|---|
| 2122 | 1954 | break; |
|---|
| 2123 | 1955 | } |
|---|
| 2124 | | - asprintf(&str, val ? "TRUE" : "FALSE"); |
|---|
| 1956 | + if (asprintf(&str, val ? "TRUE" : "FALSE") < 0) |
|---|
| 1957 | + str = NULL; |
|---|
| 2125 | 1958 | break; |
|---|
| 2126 | 1959 | } |
|---|
| 2127 | 1960 | } |
|---|
| 2128 | 1961 | if (right_val >= 0) { |
|---|
| 2129 | | - if ((arg->op.type == FILTER_OP_AND && !right_val) || |
|---|
| 2130 | | - (arg->op.type == FILTER_OP_OR && right_val)) { |
|---|
| 1962 | + if ((arg->op.type == TEP_FILTER_OP_AND && !right_val) || |
|---|
| 1963 | + (arg->op.type == TEP_FILTER_OP_OR && right_val)) { |
|---|
| 2131 | 1964 | /* Just return right value */ |
|---|
| 2132 | 1965 | str = right; |
|---|
| 2133 | 1966 | right = NULL; |
|---|
| .. | .. |
|---|
| 2139 | 1972 | break; |
|---|
| 2140 | 1973 | } |
|---|
| 2141 | 1974 | |
|---|
| 2142 | | - asprintf(&str, "(%s) %s (%s)", left, op, right); |
|---|
| 1975 | + if (asprintf(&str, "(%s) %s (%s)", left, op, right) < 0) |
|---|
| 1976 | + str = NULL; |
|---|
| 2143 | 1977 | break; |
|---|
| 2144 | 1978 | |
|---|
| 2145 | | - case FILTER_OP_NOT: |
|---|
| 1979 | + case TEP_FILTER_OP_NOT: |
|---|
| 2146 | 1980 | op = "!"; |
|---|
| 2147 | 1981 | right = arg_to_str(filter, arg->op.right); |
|---|
| 2148 | 1982 | if (!right) |
|---|
| .. | .. |
|---|
| 2155 | 1989 | right_val = 0; |
|---|
| 2156 | 1990 | if (right_val >= 0) { |
|---|
| 2157 | 1991 | /* just return the opposite */ |
|---|
| 2158 | | - asprintf(&str, right_val ? "FALSE" : "TRUE"); |
|---|
| 1992 | + if (asprintf(&str, right_val ? "FALSE" : "TRUE") < 0) |
|---|
| 1993 | + str = NULL; |
|---|
| 2159 | 1994 | break; |
|---|
| 2160 | 1995 | } |
|---|
| 2161 | | - asprintf(&str, "%s(%s)", op, right); |
|---|
| 1996 | + if (asprintf(&str, "%s(%s)", op, right) < 0) |
|---|
| 1997 | + str = NULL; |
|---|
| 2162 | 1998 | break; |
|---|
| 2163 | 1999 | |
|---|
| 2164 | 2000 | default: |
|---|
| .. | .. |
|---|
| 2170 | 2006 | return str; |
|---|
| 2171 | 2007 | } |
|---|
| 2172 | 2008 | |
|---|
| 2173 | | -static char *val_to_str(struct event_filter *filter, struct filter_arg *arg) |
|---|
| 2009 | +static char *val_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg) |
|---|
| 2174 | 2010 | { |
|---|
| 2175 | 2011 | char *str = NULL; |
|---|
| 2176 | 2012 | |
|---|
| 2177 | | - asprintf(&str, "%lld", arg->value.val); |
|---|
| 2013 | + if (asprintf(&str, "%lld", arg->value.val) < 0) |
|---|
| 2014 | + str = NULL; |
|---|
| 2178 | 2015 | |
|---|
| 2179 | 2016 | return str; |
|---|
| 2180 | 2017 | } |
|---|
| 2181 | 2018 | |
|---|
| 2182 | | -static char *field_to_str(struct event_filter *filter, struct filter_arg *arg) |
|---|
| 2019 | +static char *field_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg) |
|---|
| 2183 | 2020 | { |
|---|
| 2184 | 2021 | return strdup(arg->field.field->name); |
|---|
| 2185 | 2022 | } |
|---|
| 2186 | 2023 | |
|---|
| 2187 | | -static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg) |
|---|
| 2024 | +static char *exp_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg) |
|---|
| 2188 | 2025 | { |
|---|
| 2189 | 2026 | char *lstr; |
|---|
| 2190 | 2027 | char *rstr; |
|---|
| .. | .. |
|---|
| 2197 | 2034 | goto out; |
|---|
| 2198 | 2035 | |
|---|
| 2199 | 2036 | switch (arg->exp.type) { |
|---|
| 2200 | | - case FILTER_EXP_ADD: |
|---|
| 2037 | + case TEP_FILTER_EXP_ADD: |
|---|
| 2201 | 2038 | op = "+"; |
|---|
| 2202 | 2039 | break; |
|---|
| 2203 | | - case FILTER_EXP_SUB: |
|---|
| 2040 | + case TEP_FILTER_EXP_SUB: |
|---|
| 2204 | 2041 | op = "-"; |
|---|
| 2205 | 2042 | break; |
|---|
| 2206 | | - case FILTER_EXP_MUL: |
|---|
| 2043 | + case TEP_FILTER_EXP_MUL: |
|---|
| 2207 | 2044 | op = "*"; |
|---|
| 2208 | 2045 | break; |
|---|
| 2209 | | - case FILTER_EXP_DIV: |
|---|
| 2046 | + case TEP_FILTER_EXP_DIV: |
|---|
| 2210 | 2047 | op = "/"; |
|---|
| 2211 | 2048 | break; |
|---|
| 2212 | | - case FILTER_EXP_MOD: |
|---|
| 2049 | + case TEP_FILTER_EXP_MOD: |
|---|
| 2213 | 2050 | op = "%"; |
|---|
| 2214 | 2051 | break; |
|---|
| 2215 | | - case FILTER_EXP_RSHIFT: |
|---|
| 2052 | + case TEP_FILTER_EXP_RSHIFT: |
|---|
| 2216 | 2053 | op = ">>"; |
|---|
| 2217 | 2054 | break; |
|---|
| 2218 | | - case FILTER_EXP_LSHIFT: |
|---|
| 2055 | + case TEP_FILTER_EXP_LSHIFT: |
|---|
| 2219 | 2056 | op = "<<"; |
|---|
| 2220 | 2057 | break; |
|---|
| 2221 | | - case FILTER_EXP_AND: |
|---|
| 2058 | + case TEP_FILTER_EXP_AND: |
|---|
| 2222 | 2059 | op = "&"; |
|---|
| 2223 | 2060 | break; |
|---|
| 2224 | | - case FILTER_EXP_OR: |
|---|
| 2061 | + case TEP_FILTER_EXP_OR: |
|---|
| 2225 | 2062 | op = "|"; |
|---|
| 2226 | 2063 | break; |
|---|
| 2227 | | - case FILTER_EXP_XOR: |
|---|
| 2064 | + case TEP_FILTER_EXP_XOR: |
|---|
| 2228 | 2065 | op = "^"; |
|---|
| 2229 | 2066 | break; |
|---|
| 2230 | 2067 | default: |
|---|
| .. | .. |
|---|
| 2232 | 2069 | break; |
|---|
| 2233 | 2070 | } |
|---|
| 2234 | 2071 | |
|---|
| 2235 | | - asprintf(&str, "%s %s %s", lstr, op, rstr); |
|---|
| 2072 | + if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0) |
|---|
| 2073 | + str = NULL; |
|---|
| 2236 | 2074 | out: |
|---|
| 2237 | 2075 | free(lstr); |
|---|
| 2238 | 2076 | free(rstr); |
|---|
| .. | .. |
|---|
| 2240 | 2078 | return str; |
|---|
| 2241 | 2079 | } |
|---|
| 2242 | 2080 | |
|---|
| 2243 | | -static char *num_to_str(struct event_filter *filter, struct filter_arg *arg) |
|---|
| 2081 | +static char *num_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg) |
|---|
| 2244 | 2082 | { |
|---|
| 2245 | 2083 | char *lstr; |
|---|
| 2246 | 2084 | char *rstr; |
|---|
| .. | .. |
|---|
| 2253 | 2091 | goto out; |
|---|
| 2254 | 2092 | |
|---|
| 2255 | 2093 | switch (arg->num.type) { |
|---|
| 2256 | | - case FILTER_CMP_EQ: |
|---|
| 2094 | + case TEP_FILTER_CMP_EQ: |
|---|
| 2257 | 2095 | op = "=="; |
|---|
| 2258 | 2096 | /* fall through */ |
|---|
| 2259 | | - case FILTER_CMP_NE: |
|---|
| 2097 | + case TEP_FILTER_CMP_NE: |
|---|
| 2260 | 2098 | if (!op) |
|---|
| 2261 | 2099 | op = "!="; |
|---|
| 2262 | 2100 | /* fall through */ |
|---|
| 2263 | | - case FILTER_CMP_GT: |
|---|
| 2101 | + case TEP_FILTER_CMP_GT: |
|---|
| 2264 | 2102 | if (!op) |
|---|
| 2265 | 2103 | op = ">"; |
|---|
| 2266 | 2104 | /* fall through */ |
|---|
| 2267 | | - case FILTER_CMP_LT: |
|---|
| 2105 | + case TEP_FILTER_CMP_LT: |
|---|
| 2268 | 2106 | if (!op) |
|---|
| 2269 | 2107 | op = "<"; |
|---|
| 2270 | 2108 | /* fall through */ |
|---|
| 2271 | | - case FILTER_CMP_GE: |
|---|
| 2109 | + case TEP_FILTER_CMP_GE: |
|---|
| 2272 | 2110 | if (!op) |
|---|
| 2273 | 2111 | op = ">="; |
|---|
| 2274 | 2112 | /* fall through */ |
|---|
| 2275 | | - case FILTER_CMP_LE: |
|---|
| 2113 | + case TEP_FILTER_CMP_LE: |
|---|
| 2276 | 2114 | if (!op) |
|---|
| 2277 | 2115 | op = "<="; |
|---|
| 2278 | 2116 | |
|---|
| 2279 | | - asprintf(&str, "%s %s %s", lstr, op, rstr); |
|---|
| 2117 | + if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0) |
|---|
| 2118 | + str = NULL; |
|---|
| 2280 | 2119 | break; |
|---|
| 2281 | 2120 | |
|---|
| 2282 | 2121 | default: |
|---|
| .. | .. |
|---|
| 2290 | 2129 | return str; |
|---|
| 2291 | 2130 | } |
|---|
| 2292 | 2131 | |
|---|
| 2293 | | -static char *str_to_str(struct event_filter *filter, struct filter_arg *arg) |
|---|
| 2132 | +static char *str_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg) |
|---|
| 2294 | 2133 | { |
|---|
| 2295 | 2134 | char *str = NULL; |
|---|
| 2296 | 2135 | char *op = NULL; |
|---|
| 2297 | 2136 | |
|---|
| 2298 | 2137 | switch (arg->str.type) { |
|---|
| 2299 | | - case FILTER_CMP_MATCH: |
|---|
| 2138 | + case TEP_FILTER_CMP_MATCH: |
|---|
| 2300 | 2139 | op = "=="; |
|---|
| 2301 | 2140 | /* fall through */ |
|---|
| 2302 | | - case FILTER_CMP_NOT_MATCH: |
|---|
| 2141 | + case TEP_FILTER_CMP_NOT_MATCH: |
|---|
| 2303 | 2142 | if (!op) |
|---|
| 2304 | 2143 | op = "!="; |
|---|
| 2305 | 2144 | /* fall through */ |
|---|
| 2306 | | - case FILTER_CMP_REGEX: |
|---|
| 2145 | + case TEP_FILTER_CMP_REGEX: |
|---|
| 2307 | 2146 | if (!op) |
|---|
| 2308 | 2147 | op = "=~"; |
|---|
| 2309 | 2148 | /* fall through */ |
|---|
| 2310 | | - case FILTER_CMP_NOT_REGEX: |
|---|
| 2149 | + case TEP_FILTER_CMP_NOT_REGEX: |
|---|
| 2311 | 2150 | if (!op) |
|---|
| 2312 | 2151 | op = "!~"; |
|---|
| 2313 | 2152 | |
|---|
| 2314 | | - asprintf(&str, "%s %s \"%s\"", |
|---|
| 2315 | | - arg->str.field->name, op, arg->str.val); |
|---|
| 2153 | + if (asprintf(&str, "%s %s \"%s\"", |
|---|
| 2154 | + arg->str.field->name, op, arg->str.val) < 0) |
|---|
| 2155 | + str = NULL; |
|---|
| 2316 | 2156 | break; |
|---|
| 2317 | 2157 | |
|---|
| 2318 | 2158 | default: |
|---|
| .. | .. |
|---|
| 2322 | 2162 | return str; |
|---|
| 2323 | 2163 | } |
|---|
| 2324 | 2164 | |
|---|
| 2325 | | -static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg) |
|---|
| 2165 | +static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg) |
|---|
| 2326 | 2166 | { |
|---|
| 2327 | 2167 | char *str = NULL; |
|---|
| 2328 | 2168 | |
|---|
| 2329 | 2169 | switch (arg->type) { |
|---|
| 2330 | | - case FILTER_ARG_BOOLEAN: |
|---|
| 2331 | | - asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE"); |
|---|
| 2170 | + case TEP_FILTER_ARG_BOOLEAN: |
|---|
| 2171 | + if (asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE") < 0) |
|---|
| 2172 | + str = NULL; |
|---|
| 2332 | 2173 | return str; |
|---|
| 2333 | 2174 | |
|---|
| 2334 | | - case FILTER_ARG_OP: |
|---|
| 2175 | + case TEP_FILTER_ARG_OP: |
|---|
| 2335 | 2176 | return op_to_str(filter, arg); |
|---|
| 2336 | 2177 | |
|---|
| 2337 | | - case FILTER_ARG_NUM: |
|---|
| 2178 | + case TEP_FILTER_ARG_NUM: |
|---|
| 2338 | 2179 | return num_to_str(filter, arg); |
|---|
| 2339 | 2180 | |
|---|
| 2340 | | - case FILTER_ARG_STR: |
|---|
| 2181 | + case TEP_FILTER_ARG_STR: |
|---|
| 2341 | 2182 | return str_to_str(filter, arg); |
|---|
| 2342 | 2183 | |
|---|
| 2343 | | - case FILTER_ARG_VALUE: |
|---|
| 2184 | + case TEP_FILTER_ARG_VALUE: |
|---|
| 2344 | 2185 | return val_to_str(filter, arg); |
|---|
| 2345 | 2186 | |
|---|
| 2346 | | - case FILTER_ARG_FIELD: |
|---|
| 2187 | + case TEP_FILTER_ARG_FIELD: |
|---|
| 2347 | 2188 | return field_to_str(filter, arg); |
|---|
| 2348 | 2189 | |
|---|
| 2349 | | - case FILTER_ARG_EXP: |
|---|
| 2190 | + case TEP_FILTER_ARG_EXP: |
|---|
| 2350 | 2191 | return exp_to_str(filter, arg); |
|---|
| 2351 | 2192 | |
|---|
| 2352 | 2193 | default: |
|---|
| .. | .. |
|---|
| 2366 | 2207 | * NULL is returned if no filter is found or allocation failed. |
|---|
| 2367 | 2208 | */ |
|---|
| 2368 | 2209 | char * |
|---|
| 2369 | | -tep_filter_make_string(struct event_filter *filter, int event_id) |
|---|
| 2210 | +tep_filter_make_string(struct tep_event_filter *filter, int event_id) |
|---|
| 2370 | 2211 | { |
|---|
| 2371 | | - struct filter_type *filter_type; |
|---|
| 2212 | + struct tep_filter_type *filter_type; |
|---|
| 2372 | 2213 | |
|---|
| 2373 | 2214 | if (!filter->filters) |
|---|
| 2374 | 2215 | return NULL; |
|---|
| .. | .. |
|---|
| 2390 | 2231 | * 1 if the two filters hold the same content. |
|---|
| 2391 | 2232 | * 0 if they do not. |
|---|
| 2392 | 2233 | */ |
|---|
| 2393 | | -int tep_filter_compare(struct event_filter *filter1, struct event_filter *filter2) |
|---|
| 2234 | +int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2) |
|---|
| 2394 | 2235 | { |
|---|
| 2395 | | - struct filter_type *filter_type1; |
|---|
| 2396 | | - struct filter_type *filter_type2; |
|---|
| 2236 | + struct tep_filter_type *filter_type1; |
|---|
| 2237 | + struct tep_filter_type *filter_type2; |
|---|
| 2397 | 2238 | char *str1, *str2; |
|---|
| 2398 | 2239 | int result; |
|---|
| 2399 | 2240 | int i; |
|---|
| .. | .. |
|---|
| 2415 | 2256 | break; |
|---|
| 2416 | 2257 | if (filter_type1->filter->type != filter_type2->filter->type) |
|---|
| 2417 | 2258 | break; |
|---|
| 2418 | | - switch (filter_type1->filter->type) { |
|---|
| 2419 | | - case FILTER_TRIVIAL_FALSE: |
|---|
| 2420 | | - case FILTER_TRIVIAL_TRUE: |
|---|
| 2421 | | - /* trivial types just need the type compared */ |
|---|
| 2422 | | - continue; |
|---|
| 2423 | | - default: |
|---|
| 2424 | | - break; |
|---|
| 2425 | | - } |
|---|
| 2426 | 2259 | /* The best way to compare complex filters is with strings */ |
|---|
| 2427 | 2260 | str1 = arg_to_str(filter1, filter_type1->filter); |
|---|
| 2428 | 2261 | str2 = arg_to_str(filter2, filter_type2->filter); |
|---|