| 409 | -------------------------------------------------------------------------*/ |
| 410 | |
| 411 | int |
| 412 | LogFormat::parse_symbol_string(const char *symbol_string, LogFieldList *field_list, bool *contains_aggregates) |
| 413 | { |
| 414 | char *sym_str; |
| 415 | int field_count = 0; |
| 416 | LogField *f; |
| 417 | char *symbol, *name, *sym, *saveptr; |
| 418 | LogField::Container container; |
| 419 | LogField::Aggregate aggregate; |
| 420 | |
| 421 | if (symbol_string == nullptr) { |
| 422 | return 0; |
| 423 | } |
| 424 | ink_assert(field_list != nullptr); |
| 425 | ink_assert(contains_aggregates != nullptr); |
| 426 | |
| 427 | *contains_aggregates = false; // we'll change if it does |
| 428 | |
| 429 | // |
| 430 | // strtok_r will mangle the input string; we'll make a copy for that. |
| 431 | // |
| 432 | sym_str = ats_strdup(symbol_string); |
| 433 | symbol = strtok_r(sym_str, ",", &saveptr); |
| 434 | |
| 435 | while (symbol != nullptr) { |
| 436 | // |
| 437 | // See if there is an aggregate operator, which will contain "()" |
| 438 | // |
| 439 | char *begin_paren = strchr(symbol, '('); |
| 440 | if (begin_paren) { |
| 441 | char *end_paren = strchr(symbol, ')'); |
| 442 | if (end_paren) { |
| 443 | Dbg(dbg_ctl_log_agg, "Aggregate symbol: %s", symbol); |
| 444 | *begin_paren = '\0'; |
| 445 | *end_paren = '\0'; |
| 446 | name = begin_paren + 1; |
| 447 | sym = symbol; |
| 448 | Dbg(dbg_ctl_log_agg, "Aggregate = %s, field = %s", sym, name); |
| 449 | aggregate = LogField::valid_aggregate_name(sym); |
| 450 | if (aggregate == LogField::NO_AGGREGATE) { |
| 451 | Note("Invalid aggregate specification: %s", sym); |
| 452 | } else { |
| 453 | if (aggregate == LogField::eCOUNT && strcmp(name, "*") == 0) { |
| 454 | f = Log::global_field_list.find_by_symbol("psql"); |
| 455 | } else { |
| 456 | f = Log::global_field_list.find_by_symbol(name); |
| 457 | } |
| 458 | if (!f) { |
| 459 | Note("Invalid field symbol %s used in aggregate " |
| 460 | "operation", |
| 461 | name); |
| 462 | } else if (f->type() != LogField::sINT) { |
| 463 | Note("Only single integer field types may be aggregated"); |
| 464 | } else { |
| 465 | LogField *new_f = new LogField(*f); |
| 466 | new_f->set_aggregate_op(aggregate); |
| 467 | field_list->add(new_f, false); |
| 468 | field_count++; |
nothing calls this directly
no test coverage detected