| 543 | } |
| 544 | |
| 545 | void |
| 546 | parse_host_res_preference(const char *value, HostResPreferenceOrder &order) |
| 547 | { |
| 548 | Tokenizer tokens(";/|"); |
| 549 | // preference from the config string. |
| 550 | int np = 0; // index in to @a m_host_res_preference |
| 551 | bool found[N_HOST_RES_PREFERENCE]; // redundancy check array |
| 552 | int n; // # of tokens |
| 553 | int i; // index |
| 554 | |
| 555 | n = tokens.Initialize(value); |
| 556 | |
| 557 | for (i = 0; i < N_HOST_RES_PREFERENCE; ++i) { |
| 558 | found[i] = false; |
| 559 | } |
| 560 | |
| 561 | const int order_size = static_cast<int>(order.size()); |
| 562 | for (i = 0; i < n && np < order_size; ++i) { |
| 563 | const char *elt = tokens[i]; |
| 564 | // special case none/only because that terminates the sequence. |
| 565 | if (0 == strcasecmp(elt, HOST_RES_PREFERENCE_STRING[HOST_RES_PREFER_NONE])) { |
| 566 | found[HOST_RES_PREFER_NONE] = true; |
| 567 | order[np] = HOST_RES_PREFER_NONE; |
| 568 | break; |
| 569 | } else { |
| 570 | // scan the other types |
| 571 | HostResPreference ep = HOST_RES_PREFER_NONE; |
| 572 | for (int ip = HOST_RES_PREFER_NONE + 1; ip < N_HOST_RES_PREFERENCE; ++ip) { |
| 573 | if (0 == strcasecmp(elt, HOST_RES_PREFERENCE_STRING[ip])) { |
| 574 | ep = static_cast<HostResPreference>(ip); |
| 575 | break; |
| 576 | } |
| 577 | } |
| 578 | if (HOST_RES_PREFER_NONE != ep && !found[ep]) { // ignore duplicates |
| 579 | found[ep] = true; |
| 580 | order[np++] = ep; |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | if (!found[HOST_RES_PREFER_NONE]) { |
| 586 | // If 'only' wasn't explicit, fill in the rest by default. |
| 587 | if (!found[HOST_RES_PREFER_IPV4]) { |
| 588 | order[np++] = HOST_RES_PREFER_IPV4; |
| 589 | } |
| 590 | if (!found[HOST_RES_PREFER_IPV6]) { |
| 591 | order[np++] = HOST_RES_PREFER_IPV6; |
| 592 | } |
| 593 | if (np < order_size) { // was N_HOST_RES_PREFERENCE) |
| 594 | order[np] = HOST_RES_PREFER_NONE; |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | int |
| 600 | ts_host_res_order_to_string(HostResPreferenceOrder const &order, char *out, int size) |
no test coverage detected