serrislew commented on code in PR #13018:
URL: https://github.com/apache/trafficserver/pull/13018#discussion_r3011326934


##########
src/proxy/logging/LogFormat.cc:
##########
@@ -55,6 +58,94 @@ DbgCtl dbg_ctl_log_format{"log-format"};
 DbgCtl dbg_ctl_log_agg{"log-agg"};
 DbgCtl dbg_ctl_log_slice{"log-slice"};
 
+char *
+trim_log_field_token(char *token)
+{
+  while (*token != '\0' && std::isspace(static_cast<unsigned char>(*token))) {
+    ++token;
+  }
+
+  size_t len = std::strlen(token);
+  while (len > 0 && std::isspace(static_cast<unsigned char>(token[len - 1]))) {
+    token[--len] = '\0';
+  }
+
+  return token;
+}
+
+bool
+parse_header_fallback_candidate(char *candidate, LogField::HeaderField &field, 
const std::string &original_symbol)
+{
+  candidate = trim_log_field_token(candidate);
+  if (*candidate == '\0') {
+    Note("Invalid header fallback field specification: empty candidate in %s", 
original_symbol.c_str());
+    return false;
+  }
+
+  if (*candidate != '{') {
+    Note("Invalid header fallback field specification: %s is not a header 
field candidate in %s", candidate,
+         original_symbol.c_str());
+    return false;
+  }
+
+  char *name_end = std::strchr(candidate, '}');
+  if (name_end == nullptr) {
+    Note("Invalid header fallback field specification: no trailing '}' in %s", 
original_symbol.c_str());
+    return false;
+  }
+
+  *name_end       = '\0';
+  char    *name   = candidate + 1;
+  char    *symbol = trim_log_field_token(name_end + 1);
+  LogSlice slice(symbol);
+
+  if (*name == '\0') {
+    Note("Invalid header fallback field specification: empty header name in 
%s", original_symbol.c_str());
+    return false;
+  }
+
+  auto container = LogField::valid_container_name(symbol);
+  if (!LogField::isHeaderContainer(container)) {
+    Note("Invalid header fallback field specification: %s is not a supported 
header container in %s", symbol,
+         original_symbol.c_str());
+    return false;
+  }
+
+  field.name      = name;
+  field.container = container;
+  field.slice     = slice;
+  return true;
+}
+
+LogField *
+parse_header_fallback_field(char *symbol)
+{
+  std::string                        original_symbol(symbol);
+  std::vector<LogField::HeaderField> header_fields;
+  char                              *candidate = symbol;
+
+  while (candidate != nullptr) {

Review Comment:
   Does this mean there can be multiple fallback candidates? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to