MCPcopy Create free account
hub / github.com/apache/trafficserver / PreProcessParents

Method PreProcessParents

src/proxy/ParentSelection.cc:388–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386}
387
388void
389ParentRecord::PreProcessParents(const char *val, const int line_num, char *buf, size_t len)
390{
391 char *_val = ats_strndup(val, strlen(val));
392 char fqdn[TS_MAX_HOST_NAME_LEN] = {0}, *nm, *token, *savePtr;
393 std::string str;
394 Machine *machine = Machine::instance();
395 constexpr char PARENT_DELIMITERS[] = ";, ";
396 HostStatus &hs = HostStatus::instance();
397
398 token = strtok_r(_val, PARENT_DELIMITERS, &savePtr);
399 while (token != nullptr) {
400 if ((nm = strchr(token, ':')) != nullptr) {
401 size_t length = (nm - token);
402 ink_assert(length < sizeof(fqdn));
403 memset(fqdn, 0, sizeof(fqdn));
404 strncpy(fqdn, token, length);
405 if (self_detect && machine->is_self(std::string_view(fqdn))) {
406 if (self_detect == 1) {
407 Dbg(dbg_ctl_parent_select, "token: %s, matches this machine. Removing self from parent list at line %d", fqdn, line_num);
408 token = strtok_r(nullptr, PARENT_DELIMITERS, &savePtr);
409 continue;
410 } else {
411 Dbg(dbg_ctl_parent_select, "token: %s, matches this machine. Marking down self from parent list at line %d", fqdn,
412 line_num);
413 hs.setHostStatus(fqdn, TSHostStatus::TS_HOST_STATUS_DOWN, 0, Reason::SELF_DETECT);
414 }
415 }
416 } else {
417 if (self_detect && machine->is_self(std::string_view(token))) {
418 if (self_detect == 1) {
419 Dbg(dbg_ctl_parent_select, "token: %s, matches this machine. Removing self from parent list at line %d", token,
420 line_num);
421 token = strtok_r(nullptr, PARENT_DELIMITERS, &savePtr);
422 continue;
423 } else {
424 Dbg(dbg_ctl_parent_select, "token: %s, matches this machine. Marking down self from parent list at line %d", token,
425 line_num);
426 hs.setHostStatus(token, TSHostStatus::TS_HOST_STATUS_DOWN, 0, Reason::SELF_DETECT);
427 }
428 }
429 }
430
431 str += token;
432 str += ";";
433 token = strtok_r(nullptr, PARENT_DELIMITERS, &savePtr);
434 }
435 strncpy(buf, str.c_str(), len);
436 ats_free(_val);
437}
438
439// const char* ParentRecord::ProcessParents(char* val, bool isPrimary)
440//

Callers

nothing calls this directly

Calls 5

memsetFunction · 0.85
ats_freeFunction · 0.85
is_selfMethod · 0.80
setHostStatusMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected