Repository: trafficserver
Updated Branches:
  refs/heads/master 558345f21 -> f914a62fc


TS-2610: Add "client_protocol_stack"(%<cps>) field into LogFormat

The output of %<cps> field would be the conjunction of protocol names
in client protocol stack spliced with '+', such as "TLS+SPDY".

Signed-off-by: Yunkai Zhang <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/f914a62f
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/f914a62f
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/f914a62f

Branch: refs/heads/master
Commit: f914a62fc3fc1f3d552b48dd7d6ca1283fb8c776
Parents: 25555f8
Author: Yunkai Zhang <[email protected]>
Authored: Mon Jan 6 16:59:19 2014 +0800
Committer: Yunkai Zhang <[email protected]>
Committed: Wed Mar 12 11:02:15 2014 +0800

----------------------------------------------------------------------
 doc/admin/event-logging-formats.en.rst |  4 +++
 proxy/logging/Log.cc                   | 20 ++++++++++++++
 proxy/logging/LogAccess.cc             | 41 +++++++++++++++++++++++++++++
 proxy/logging/LogAccess.h              |  2 ++
 proxy/logging/LogAccessHttp.cc         |  9 +++++++
 proxy/logging/LogAccessHttp.h          |  1 +
 6 files changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f914a62f/doc/admin/event-logging-formats.en.rst
----------------------------------------------------------------------
diff --git a/doc/admin/event-logging-formats.en.rst 
b/doc/admin/event-logging-formats.en.rst
index 67d484d..751ec35 100644
--- a/doc/admin/event-logging-formats.en.rst
+++ b/doc/admin/event-logging-formats.en.rst
@@ -75,6 +75,10 @@ The following list describes Traffic Server custom logging 
fields.
 ``chp``
     The port number of the client's host machine.
 
+``cps``
+    Client Protocol Stack, the output would be the conjunction of
+    protocol names in the stack spliced with '+', such as "TLS+SPDY".
+
 ``cqbl``
     The client request transfer length; the body length in the client
     request to Traffic Server (in bytes).

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f914a62f/proxy/logging/Log.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index 462d955..8a7d0d5 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -365,6 +365,26 @@ Log::init_fields()
   global_field_list.add (field, false);
   ink_hash_table_insert (field_symbol_hash, "caun", field);
 
+  Ptr<LogFieldAliasTable> proto_type_map = make_ptr(NEW(new 
LogFieldAliasTable));
+  proto_type_map->init(4,
+                       // Transport protocols
+                       TS_PROTO_UDP, "UDP",
+                       TS_PROTO_TCP, "TCP",
+                       TS_PROTO_TLS, "TLS",
+                       // Application protocols
+                       TS_PROTO_HTTP, "HTTP",
+                       TS_PROTO_SPDY, "SPDY",
+                       TS_PROTO_RTMP, "RTMP",
+                       TS_PROTO_WBSK, "WBSK");
+
+  field = NEW(new LogField("client_protocol_stack", "cps",
+                           LogField::sINT,
+                           &LogAccess::marshal_client_protocol_stack,
+                           &LogAccess::unmarshal_client_protocol_stack,
+                           (Ptr<LogFieldAliasMap>) proto_type_map));
+  global_field_list.add(field, false);
+  ink_hash_table_insert(field_symbol_hash, "cps", field);
+
   field = NEW(new LogField("client_req_timestamp_sec", "cqts",
                            LogField::sINT,
                            &LogAccess::marshal_client_req_timestamp_sec,

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f914a62f/proxy/logging/LogAccess.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogAccess.cc b/proxy/logging/LogAccess.cc
index 568c759..20121f7 100644
--- a/proxy/logging/LogAccess.cc
+++ b/proxy/logging/LogAccess.cc
@@ -75,6 +75,12 @@ LogAccess::init()
   -------------------------------------------------------------------------*/
 
 int
+LogAccess::marshal_client_protocol_stack(char *buf)
+{
+  DEFAULT_INT_FIELD;
+}
+
+int
 LogAccess::marshal_client_host_ip(char *buf)
 {
   DEFAULT_IP_FIELD;
@@ -1306,6 +1312,41 @@ LogAccess::unmarshal_cache_write_code(char **buf, char 
*dest, int len, Ptr<LogFi
 }
 
 int
+LogAccess::unmarshal_client_protocol_stack(char **buf, char *dest, int len, 
Ptr<LogFieldAliasMap> map)
+{
+  ink_assert(buf != NULL);
+  ink_assert(*buf != NULL);
+  ink_assert(dest != NULL);
+
+  char *p;
+  size_t nr_chars = 0;
+  int i, ret, nr_bits, left_len;
+  TSClientProtoStack proto_stack = (TSClientProtoStack)unmarshal_int(buf);
+
+  p = dest;
+  left_len = len;
+  nr_bits = 8 * sizeof(TSClientProtoStack);
+
+  for (i = 0; i < nr_bits && left_len; i++) {
+    if ((proto_stack >> i) & 0x1) {
+      if (p != dest) {
+        *p++ = '+';
+        left_len--;
+      }
+      ret = map->asString(i, p, left_len, &nr_chars);
+      if (ret == LogFieldAliasMap::ALL_OK) {
+        p += nr_chars;
+        left_len -= nr_chars;
+      } else if (ret == LogFieldAliasMap::BUFFER_TOO_SMALL) {
+        break;
+      }
+    }
+  }
+
+  return (len - left_len);
+}
+
+int
 LogAccess::unmarshal_record(char **buf, char *dest, int len)
 {
   ink_assert(buf != NULL);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f914a62f/proxy/logging/LogAccess.h
----------------------------------------------------------------------
diff --git a/proxy/logging/LogAccess.h b/proxy/logging/LogAccess.h
index a152de6..35291aa 100644
--- a/proxy/logging/LogAccess.h
+++ b/proxy/logging/LogAccess.h
@@ -172,6 +172,7 @@ public:
   inkcoreapi virtual int marshal_client_auth_user_name(char *); // STR
   int marshal_client_req_timestamp_sec(char *); // INT
 
+  inkcoreapi virtual int marshal_client_protocol_stack(char *); // INT
   inkcoreapi virtual int marshal_client_req_text(char *);       // STR
   inkcoreapi virtual int marshal_client_req_http_method(char *);        // STR
   inkcoreapi virtual int marshal_client_req_url(char *);        // STR
@@ -290,6 +291,7 @@ public:
   static int unmarshal_cache_code(char **buf, char *dest, int len, 
Ptr<LogFieldAliasMap> map);
   static int unmarshal_entry_type(char **buf, char *dest, int len, 
Ptr<LogFieldAliasMap> map);
   static int unmarshal_cache_write_code(char **buf, char *dest, int len, 
Ptr<LogFieldAliasMap> map);
+  static int unmarshal_client_protocol_stack(char **buf, char *dest, int len, 
Ptr<LogFieldAliasMap> map);
 
   static int unmarshal_with_map(int64_t code, char *dest, int len, 
Ptr<LogFieldAliasMap> map, const char *msg = 0);
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f914a62f/proxy/logging/LogAccessHttp.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogAccessHttp.cc b/proxy/logging/LogAccessHttp.cc
index 851458c..5ad308b 100644
--- a/proxy/logging/LogAccessHttp.cc
+++ b/proxy/logging/LogAccessHttp.cc
@@ -139,6 +139,15 @@ LogAccessHttp::init()
   -------------------------------------------------------------------------*/
 
 int
+LogAccessHttp::marshal_client_protocol_stack(char *buf)
+{
+  if (buf) {
+    marshal_int(buf, m_http_sm->proto_stack);
+  }
+  return INK_MIN_ALIGN;
+}
+
+int
 LogAccessHttp::marshal_client_host_ip(char *buf)
 {
   return marshal_ip(buf, &m_http_sm->t_state.client_info.addr.sa);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f914a62f/proxy/logging/LogAccessHttp.h
----------------------------------------------------------------------
diff --git a/proxy/logging/LogAccessHttp.h b/proxy/logging/LogAccessHttp.h
index 8ca3e8b..9235441 100644
--- a/proxy/logging/LogAccessHttp.h
+++ b/proxy/logging/LogAccessHttp.h
@@ -58,6 +58,7 @@ public:
   virtual int marshal_client_host_ip(char *);   // STR
   virtual int marshal_client_host_port(char *); // INT
   virtual int marshal_client_auth_user_name(char *);    // STR
+  virtual int marshal_client_protocol_stack(char *);    // INT
   virtual int marshal_client_req_text(char *);  // STR
   virtual int marshal_client_req_http_method(char *);   // INT
   virtual int marshal_client_req_url(char *);   // STR

Reply via email to