| 536 | } |
| 537 | |
| 538 | int fixup_named_flags(void** param, str *flag_names, str *kv_flag_names, |
| 539 | str *kv_flag_vals) |
| 540 | { |
| 541 | str *s = (str*)*param; |
| 542 | csv_record *list, *rec; |
| 543 | int i; |
| 544 | unsigned int flags = 0; |
| 545 | char *p; |
| 546 | str name; |
| 547 | |
| 548 | list = parse_csv_record(s); |
| 549 | if (!list) { |
| 550 | LM_ERR("Failed to parse list of flags\n"); |
| 551 | return -1; |
| 552 | } |
| 553 | |
| 554 | if (kv_flag_names) |
| 555 | for (i = 0; kv_flag_names[i].s ; i++) { |
| 556 | kv_flag_vals[i].s = NULL; |
| 557 | kv_flag_vals[i].len = 0; |
| 558 | } |
| 559 | |
| 560 | for (rec = list; rec; rec = rec->next) { |
| 561 | if (flag_names) { |
| 562 | for (i = 0; flag_names[i].s && !str_match(&rec->s, &flag_names[i]); |
| 563 | i++) ; |
| 564 | |
| 565 | if (!flag_names[i].s) { |
| 566 | if (!kv_flag_names) { |
| 567 | LM_ERR("Unknown flag: %.*s\n", rec->s.len, rec->s.s); |
| 568 | goto error; |
| 569 | } |
| 570 | } else { |
| 571 | flags |= (1<<i); |
| 572 | continue; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | /* the current flag must be a key-value flag at this point */ |
| 577 | if (kv_flag_names) { |
| 578 | p = q_memchr(rec->s.s, '=', rec->s.len); |
| 579 | |
| 580 | name.s = rec->s.s; |
| 581 | name.len = p ? (p - rec->s.s) : rec->s.len; |
| 582 | |
| 583 | for (i = 0; kv_flag_names[i].s && |
| 584 | !str_match(&name, &kv_flag_names[i]); i++) ; |
| 585 | |
| 586 | if (!kv_flag_names[i].s) { |
| 587 | LM_ERR("Unknown flag: %.*s\n", name.len, name.s); |
| 588 | goto error; |
| 589 | } |
| 590 | |
| 591 | if (!p || (rec->s.len - (p - rec->s.s) - 1) == 0) { |
| 592 | LM_ERR("Bad format for key-value flag: %.*s\n", |
| 593 | rec->s.len, rec->s.s); |
| 594 | goto error; |
| 595 | } |