trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject [trafficserver] 04/06: move code to utility function to reduce the interface size
Date Thu, 29 Aug 2019 06:39:41 GMT
This is an automated email from the ASF dual-hosted git repository.

zzz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 89bed7bcbc5b57652f9392b1905908d993483674
Author: xinli1 <xinli1@linkedin.com>
AuthorDate: Thu Aug 15 15:27:24 2019 -0700

    move code to utility function to reduce the interface size
---
 proxy/logging/LogFilter.h | 67 +++++++++++++++++++++++++----------------------
 1 file changed, 36 insertions(+), 31 deletions(-)

diff --git a/proxy/logging/LogFilter.h b/proxy/logging/LogFilter.h
index 6c05e53..4812be7 100644
--- a/proxy/logging/LogFilter.h
+++ b/proxy/logging/LogFilter.h
@@ -388,13 +388,13 @@ findPatternFromParamName(const char *lookup_query_param, const char
*pattern)
   const char *p1 = strstr(lookup_query_param, pattern);
   while (p1) {
     // wipe pattern in param name, need search again if find pattern in param value
-    const char *p10 = strstr(p1, "=");
+    const char *p10 = strchr(p1, '=');
     if (!p10) {
       // no "=" after p1, means p1 is not in the param name, and no more param after it
       p1 = nullptr;
       break;
     }
-    const char *p11 = strstr(p1, "&");
+    const char *p11 = strchr(p1, '&');
     if (p11 && p10 > p11) {
       //"=" is after "&" followd by p1, means p1 is not in the param name
       p1 = strstr(p11, pattern);
@@ -406,6 +406,37 @@ findPatternFromParamName(const char *lookup_query_param, const char *pattern)
   return p1;
 }
 
+static void
+updatePatternForFieldValue(char **field, const char *p1, int field_pos, char *buf_dest)
+{
+  char tmp_text[strlen(buf_dest) + 10];
+  char *temp_text = tmp_text;
+  memcpy(temp_text, buf_dest, (p1 - buf_dest));
+  temp_text += (p1 - buf_dest);
+  const char *p2 = strchr(p1, '=');
+  if (p2) {
+    p2++;
+    memcpy(temp_text, p1, (p2 - p1));
+    temp_text += (p2 - p1);
+    const char *p3 = strchr(p2, '&');
+    if (p3) {
+      for (int i = 0; i < (p3 - p2); i++)
+        temp_text[i] = 'X';
+      temp_text += (p3 - p2);
+      memcpy(temp_text, p3, ((buf_dest + strlen(buf_dest)) - p3));
+    } else {
+      for (int i = 0; i < ((buf_dest + strlen(buf_dest)) - p2); i++) {
+        temp_text[i] = 'X';
+      }
+    }
+  } else {
+    return;
+  }
+
+  tmp_text[strlen(buf_dest)] = '\0';
+  strcpy(*field, tmp_text);
+}
+
 /*---------------------------------------------------------------------------
   wipeField : Given a dest buffer, wipe the first occurrence of the value of the
   field in the buffer.
@@ -418,8 +449,8 @@ wipeField(char **field, char *pattern, const char *uppercase_field)
   const char *lookup_dest = uppercase_field ? uppercase_field : *field;
 
   if (buf_dest) {
-    char *query_param              = strstr(buf_dest, "?");
-    const char *lookup_query_param = strstr(lookup_dest, "?");
+    char *query_param              = strchr(buf_dest, '?');
+    const char *lookup_query_param = strchr(lookup_dest, '?');
     if (!query_param || !lookup_query_param) {
       return;
     }
@@ -428,33 +459,7 @@ wipeField(char **field, char *pattern, const char *uppercase_field)
     if (p1) {
       int field_pos = p1 - lookup_query_param;
       p1            = query_param + field_pos;
-
-      char tmp_text[strlen(buf_dest) + 10];
-      char *temp_text = tmp_text;
-      memcpy(temp_text, buf_dest, (p1 - buf_dest));
-      temp_text += (p1 - buf_dest);
-      const char *p2 = strstr(p1, "=");
-      if (p2) {
-        p2++;
-        memcpy(temp_text, p1, (p2 - p1));
-        temp_text += (p2 - p1);
-        const char *p3 = strstr(p2, "&");
-        if (p3) {
-          for (int i = 0; i < (p3 - p2); i++)
-            temp_text[i] = 'X';
-          temp_text += (p3 - p2);
-          memcpy(temp_text, p3, ((buf_dest + strlen(buf_dest)) - p3));
-        } else {
-          for (int i = 0; i < ((buf_dest + strlen(buf_dest)) - p2); i++) {
-            temp_text[i] = 'X';
-          }
-        }
-      } else {
-        return;
-      }
-
-      tmp_text[strlen(buf_dest)] = '\0';
-      strcpy(*field, tmp_text);
+      updatePatternForFieldValue(field, p1, field_pos, buf_dest);
     }
   }
 }


Mime
View raw message