trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject svn commit: r1061115 - in /trafficserver/traffic/trunk: lib/ts/ink_hrtime.cc lib/ts/ink_hrtime.h proxy/logging/LogAccess.cc proxy/logging/LogBuffer.cc proxy/logging/LogObject.cc proxy/logging/LogUtils.cc proxy/logging/LogUtils.h proxy/signals.cc
Date Thu, 20 Jan 2011 04:20:22 GMT
Author: zwoop
Date: Thu Jan 20 04:20:22 2011
New Revision: 1061115

URL: http://svn.apache.org/viewvc?rev=1061115&view=rev
Log:
TS-649 Cleanup to have a chance to make it a shared lib

Modified:
    trafficserver/traffic/trunk/lib/ts/ink_hrtime.cc
    trafficserver/traffic/trunk/lib/ts/ink_hrtime.h
    trafficserver/traffic/trunk/proxy/logging/LogAccess.cc
    trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc
    trafficserver/traffic/trunk/proxy/logging/LogObject.cc
    trafficserver/traffic/trunk/proxy/logging/LogUtils.cc
    trafficserver/traffic/trunk/proxy/logging/LogUtils.h
    trafficserver/traffic/trunk/proxy/signals.cc

Modified: trafficserver/traffic/trunk/lib/ts/ink_hrtime.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_hrtime.cc?rev=1061115&r1=1061114&r2=1061115&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_hrtime.cc (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_hrtime.cc Thu Jan 20 04:20:22 2011
@@ -41,19 +41,18 @@
 #include "ink_unused.h"  /* MAGIC_EDITING_TAG */
 
 char *
-int64_to_str(char *buf, unsigned int buf_size, int64_t val,
-             unsigned int *total_chars, unsigned int req_width, char pad_char)
+int64_to_str(char *buf, unsigned int buf_size, int64_t val, unsigned int *total_chars, unsigned
int req_width, char pad_char)
 {
-  const int local_buf_size = 32;
+  const unsigned int local_buf_size = 32;
   char local_buf[local_buf_size];
-  int using_local_buffer = 0;
-  int negative = 0;
+  bool using_local_buffer = false;
+  bool negative = false;
   char *out_buf;
 
   if (buf_size < 22) {
     // int64_t may not fit in provided buffer, use the local one
     out_buf = &local_buf[local_buf_size - 1];
-    using_local_buffer = 1;
+    using_local_buffer = false;
   } else {
     out_buf = &buf[buf_size - 1];
   }
@@ -63,7 +62,7 @@ int64_to_str(char *buf, unsigned int buf
 
   if (val < 0) {
     val = -val;
-    negative = 1;
+    negative = false;
   }
 
   if (val < 10) {
@@ -138,10 +137,10 @@ int64_to_str(char *buf, unsigned int buf
 
 
 int
-squid_timestamp_to_buf(char *buf, uint32_t buf_size, uint64_t timestamp_sec, uint64_t timestamp_usec)
+squid_timestamp_to_buf(char *buf, unsigned int buf_size, long timestamp_sec, long timestamp_usec)
 {
   int res;
-  const int tmp_buf_size = 32;
+  const unsigned int tmp_buf_size = 32;
   char tmp_buf[tmp_buf_size];
 
   unsigned int num_chars_s;
@@ -153,8 +152,7 @@ squid_timestamp_to_buf(char *buf, uint32
   tmp_buf[tmp_buf_size - 5] = '.';
   int ms = timestamp_usec / 1000;
   unsigned int num_chars_ms;
-  char RELEASE_UNUSED *ts_ms = int64_to_str(&tmp_buf[tmp_buf_size - 4],
-                                            4, ms, &num_chars_ms, 4, '0');
+  char RELEASE_UNUSED *ts_ms = int64_to_str(&tmp_buf[tmp_buf_size - 4], 4, ms, &num_chars_ms,
4, '0');
   ink_debug_assert(ts_ms && num_chars_ms == 4);
 
   unsigned int chars_to_write = num_chars_s + 3;        // no eos

Modified: trafficserver/traffic/trunk/lib/ts/ink_hrtime.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_hrtime.h?rev=1061115&r1=1061114&r2=1061115&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_hrtime.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_hrtime.h Thu Jan 20 04:20:22 2011
@@ -35,9 +35,8 @@
 #include "ink_assert.h"
 #include "Compatability.h"
 
-int squid_timestamp_to_buf(char *buf, uint32_t buf_size, uint64_t timestamp_sec, uint64_t
timestamp_usec);
-char *int64_to_str(char *buf, int32_t buf_size, int64_t val,
-                   uint32_t *total_chars, uint32_t req_width, char pad_char);
+int squid_timestamp_to_buf(char *buf, unsigned int buf_size, long timestamp_sec, long timestamp_usec);
+char *int64_to_str(char *buf, unsigned int buf_size, int64_t val, unsigned int *total_chars,
unsigned int req_width=0, char pad_char='0');
 
 #ifdef NEED_HRTIME
 #include <time.h>

Modified: trafficserver/traffic/trunk/proxy/logging/LogAccess.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogAccess.cc?rev=1061115&r1=1061114&r2=1061115&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogAccess.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogAccess.cc Thu Jan 20 04:20:22 2011
@@ -870,7 +870,7 @@ LogAccess::marshal_record(char *record, 
 
       if (found) {
 
-        out_buf = LogUtils::int64_to_str(ascii_buf, max_chars, val, &num_chars);
+        out_buf = int64_to_str(ascii_buf, max_chars, val, &num_chars);
         ink_debug_assert(out_buf);
       } else {
         out_buf = (char *) record_not_found_msg;

Modified: trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc?rev=1061115&r1=1061114&r2=1061115&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc Thu Jan 20 04:20:22 2011
@@ -630,7 +630,6 @@ LogBuffer::resolve_custom_entry(LogField
   int *readfrom_map = NULL;
 
   if (alt_fieldlist && alt_printf_str) {
-
     LogField *f, *g;
     int n_alt_fields = alt_fieldlist->count();
     if (unlikely((readfrom_map = (int *) xmalloc(n_alt_fields * sizeof(int))) == NULL))
@@ -682,11 +681,9 @@ LogBuffer::resolve_custom_entry(LogField
         bool non_aggregate_timestamp = false;
 
         if (field->aggregate() == LogField::NO_AGGREGATE) {
-
           char *sym = field->symbol();
 
           if (strcmp(sym, "cqts") == 0) {
-
             // unmarshal_int_to_str expects data in
             // network order
             timestamp = htonl(timestamp);
@@ -700,7 +697,6 @@ LogBuffer::resolve_custom_entry(LogField
             non_aggregate_timestamp = true;
 
           } else if (strcmp(sym, "cqth") == 0) {
-
             // unmarshal_int_to_str_hex expects data in
             // network order
             timestamp = htonl(timestamp);
@@ -714,8 +710,8 @@ LogBuffer::resolve_custom_entry(LogField
             non_aggregate_timestamp = true;
 
           } else if (strcmp(sym, "cqtq") == 0) {
-
-            res = LogUtils::squid_timestamp_to_buf(to, write_to_len - bytes_written, timestamp,
timestamp_usec);
+            // From lib/ts
+            res = squid_timestamp_to_buf(to, write_to_len - bytes_written, timestamp, timestamp_usec);
             if (res < 0)
               res = -1;
 
@@ -727,7 +723,6 @@ LogBuffer::resolve_custom_entry(LogField
             non_aggregate_timestamp = true;
 
           } else if (strcmp(sym, "cqtn") == 0) {
-
             char *str = LogUtils::timestamp_to_netscape_str(timestamp);
             res = (int)::strlen(str);
             if (res < write_to_len - bytes_written) {
@@ -743,7 +738,6 @@ LogBuffer::resolve_custom_entry(LogField
             non_aggregate_timestamp = true;
 
           } else if (strcmp(sym, "cqtd") == 0) {
-
             char *str = LogUtils::timestamp_to_date_str(timestamp);
             res = (int)::strlen(str);
             if (res < write_to_len - bytes_written) {
@@ -759,7 +753,6 @@ LogBuffer::resolve_custom_entry(LogField
             non_aggregate_timestamp = true;
 
           } else if (strcmp(sym, "cqtt") == 0) {
-
             char *str = LogUtils::timestamp_to_time_str(timestamp);
             res = (int)::strlen(str);
             if (res < write_to_len - bytes_written) {

Modified: trafficserver/traffic/trunk/proxy/logging/LogObject.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogObject.cc?rev=1061115&r1=1061114&r2=1061115&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogObject.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogObject.cc Thu Jan 20 04:20:22 2011
@@ -650,8 +650,7 @@ LogObject::roll_files_if_needed(long tim
       // remaining until the next roll, but we calculate this figure
       // every time ...
       //
-      int secs_to_next = LogUtils::seconds_to_next_roll(time_now, m_rolling_offset_hr,
-                                                        m_rolling_interval_sec);
+      int secs_to_next = LogUtils::seconds_to_next_roll(time_now, m_rolling_offset_hr, m_rolling_interval_sec);
 
       // ... likewise, we make sure we compute the absolute value
       // of the seconds since the last roll (which would otherwise

Modified: trafficserver/traffic/trunk/proxy/logging/LogUtils.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogUtils.cc?rev=1061115&r1=1061114&r2=1061115&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogUtils.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogUtils.cc Thu Jan 20 04:20:22 2011
@@ -434,45 +434,6 @@ LogUtils::remove_content_type_attributes
   }
 }
 
-/*-------------------------------------------------------------------------
-  LogUtils::ip_to_hex_str
-
-  This routine simply writes the given IP integer [ip] in the equivalent
-  hexadecimal string format "xxxxxxxxxx" into the provided buffer [buf] of
-  size [bufLen].
-
-  It returns 1 if the provided buffer is not big enough to hold the
-  equivalent ip string (and its null terminator), and 0 otherwise.
-  If the buffer is not big enough, only the ip "segments" that completely
-  fit into it are written, and the buffer is null terminated.
-
-  If a non-null pointer to size_t [numCharsPtr] is given, then the
-  length of the ip string is written there (this is the same one would
-  get from calling strlen(buf) after a call to ip_to_str, so the null
-  string terminator is not counted).
-
-  -------------------------------------------------------------------------*/
-
-int
-LogUtils::ip_to_hex_str(unsigned ip, char *buf, size_t bufLen, size_t * numCharsPtr)
-{
-  static const char *table = "0123456789abcdef@";
-  int retVal = 1;
-  if (buf && bufLen > 0) {
-    if (bufLen > 8)
-      bufLen = 8;
-    for (retVal = 0; retVal < (int) bufLen;) {
-      buf[retVal++] = (char) table[(ip & 0xf)];
-      ip >>= 4;
-    }
-
-    if (numCharsPtr) {
-      *numCharsPtr = (size_t) retVal;
-    }
-    retVal = (retVal == 8) ? 0 : 1;
-  }
-  return retVal;
-}
 
 /*-------------------------------------------------------------------------
   LogUtils::timestamp_to_hex_str
@@ -694,165 +655,6 @@ LogUtils::seconds_to_next_roll(time_t ti
   return ((tr >= sidl ? (tr - sidl) % rolling_interval : (86400 - (sidl - tr)) % rolling_interval));
 }
 
-// Converts the int64_t val argument to a null terminated string, returning a
-// pointer to the beginning of the string.
-//
-// The string is stored in the provided buffer if the buffer is large
-// enough, otherwise the buffer is not touched, and the function returns NULL.
-//
-// The argument total_chars returns the number of characters that were
-// converted or that would have been converted if the buffer had been large
-// enough. total_chars includes the null terminator.
-//
-// The optional arguments req_width and pad_char allow users to
-// specify a requested width of the output string (including the null
-// terminator), and a padding character to use to reach that width. Padding
-// happens only if the resulting string is shorter than the requested width
-// and if there is room in the buffer to accomodate the padding.
-//
-char *
-LogUtils::int64_to_str(char *buf, unsigned int buf_size, int64_t val,
-                       unsigned int *total_chars, unsigned int req_width, char pad_char)
-{
-  const int local_buf_size = 32;
-  char local_buf[local_buf_size];
-  bool using_local_buffer = false;
-  bool negative = false;
-  char *out_buf;
-
-  if (buf_size < 22) {
-    // int64_t may not fit in provided buffer, use the local one
-    out_buf = &local_buf[local_buf_size - 1];
-    using_local_buffer = true;
-  } else {
-    out_buf = &buf[buf_size - 1];
-  }
-
-  unsigned int num_chars = 1;   // includes eos
-  *out_buf-- = 0;
-
-  if (val < 0) {
-    val = -val;
-    negative = true;
-  }
-
-  if (val < 10) {
-    *out_buf-- = '0' + (char) val;
-    ++num_chars;
-  } else {
-    do {
-      *out_buf-- = (char) (val % 10) + '0';
-      val /= 10;
-      ++num_chars;
-    } while (val);
-  }
-
-  // pad with pad_char if needed
-  //
-  if (req_width) {
-    // add minus sign if padding character is not 0
-    if (negative && pad_char != '0') {
-      *out_buf = '-';
-      ++num_chars;
-    } else {
-      out_buf++;
-    }
-    if (req_width > buf_size)
-      req_width = buf_size;
-    unsigned int num_padding = 0;
-    if (req_width > num_chars) {
-      num_padding = req_width - num_chars;
-      switch (num_padding) {
-      case 3:
-        *--out_buf = pad_char;
-      case 2:
-        *--out_buf = pad_char;
-      case 1:
-        *--out_buf = pad_char;
-        break;
-      default:
-        for (unsigned int i = 0; i < num_padding; ++i, *--out_buf = pad_char);
-      }
-      num_chars += num_padding;
-    }
-    // add minus sign if padding character is 0
-    if (negative && pad_char == '0') {
-      if (num_padding) {
-        *out_buf = '-';         // overwrite padding
-      } else {
-        *--out_buf = '-';
-        ++num_chars;
-      }
-    }
-  } else if (negative) {
-    *out_buf = '-';
-    ++num_chars;
-  } else {
-    out_buf++;
-  }
-
-  if (using_local_buffer) {
-    if (num_chars <= buf_size) {
-      memcpy(buf, out_buf, num_chars);
-      out_buf = buf;
-    } else {
-      // data does not fit return NULL
-      out_buf = NULL;
-    }
-  }
-
-  if (total_chars)
-    *total_chars = num_chars;
-  return out_buf;
-}
-
-// Formats the incoming timestamp_sec and timestamp_usec into a
-// non-null-terminated string of the format "%d.%03d" which is
-// 'almost' what squid specifies.  squid specifies "%9.%03d", but
-// timestamps of less than 9 digits for the seconds value correspond
-// to dates before March 1973, so it is not worth dealing with those.
-//
-// If the provided buffer buf of size buf_size is big enough to hold the
-// resulting string, then places the string in buf WITHOUT A
-// NULL-TERMINATING CHARACTER, and returns the number of characters written.
-//
-// If the provided buffer is too small, leaves it untouched and
-// returns -(required_buffer_size)
-//
-int
-LogUtils::squid_timestamp_to_buf(char *buf, unsigned int buf_size, long timestamp_sec, long
timestamp_usec)
-{
-  int res;
-  const int tmp_buf_size = 32;
-  char tmp_buf[tmp_buf_size];
-
-  // convert seconds
-  //
-  unsigned int num_chars_s;
-  char *ts_s = LogUtils::int64_to_str(tmp_buf, tmp_buf_size - 4,
-                                      timestamp_sec, &num_chars_s);
-  ink_debug_assert(ts_s);
-
-  // convert milliseconds
-  //
-  tmp_buf[tmp_buf_size - 5] = '.';
-  int ms = timestamp_usec / 1000;
-  unsigned int num_chars_ms;
-  char RELEASE_UNUSED *ts_ms = LogUtils::int64_to_str(&tmp_buf[tmp_buf_size - 4],
-                                                      4, ms, &num_chars_ms, 4, '0');
-  ink_debug_assert(ts_ms && num_chars_ms == 4);
-
-  unsigned int chars_to_write = num_chars_s + 3;        // no eos
-
-  if (buf_size >= chars_to_write) {
-    memcpy(buf, ts_s, chars_to_write);
-    res = chars_to_write;
-  } else {
-    res = -((int) chars_to_write);
-  }
-
-  return res;
-}
 
 // Checks if the file pointed to by full_filename either is a regular
 // file or a pipe and has write permission, or, if the file does not

Modified: trafficserver/traffic/trunk/proxy/logging/LogUtils.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogUtils.h?rev=1061115&r1=1061114&r2=1061115&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogUtils.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogUtils.h Thu Jan 20 04:20:22 2011
@@ -63,16 +63,13 @@ public:
   static void manager_alarm(AlarmType alarm_type, const char *msg, ...);
   static void strip_trailing_newline(char *buf);
   static char *escapify_url(Arena * arena, char *url, int len_in, int *len_out);
+  static char *int64_to_str(char *buf, unsigned int buf_size, int64_t val, unsigned int *total_chars,
unsigned int req_width=0, char pad_char='0');
   static void remove_content_type_attributes(char *type_str, int *type_len);
   static int timestamp_to_hex_str(unsigned timestamp, char *str, size_t len, size_t * n_chars
= 0);
-  static int ip_to_hex_str(unsigned ip, char *str, size_t len, size_t * n_chars = 0);
   static int ip_to_str(unsigned ip, char *str, size_t len, size_t * n_chars = 0);
   static unsigned str_to_ip(char *ipstr);
   static bool valid_ipstr_format(char *ipstr);
   static int seconds_to_next_roll(time_t time_now, int rolling_offset, int rolling_interval);
-  static char *int64_to_str(char *buf, unsigned int buf_size,
-                            int64_t val, unsigned int *total_chars, unsigned int req_width
= 0, char pad_char = '0');
-  static int squid_timestamp_to_buf(char *buf, unsigned int buf_size, long timestamp_sec,
long timestamp_usec);
   static int file_is_writeable(const char *full_filename,
                                off_t * size_bytes = 0,
                                bool * has_size_limit = 0, uint64_t * current_size_limit_bytes
= 0);
@@ -82,8 +79,10 @@ private:
   LogUtils & operator=(const LogUtils &);
 };
 
-enum LogDeleteProgram
-{ USE_DELETE, USE_XFREE };
+enum LogDeleteProgram {
+  USE_DELETE,
+  USE_XFREE
+};
 
 class LogMemoryDeleter
 {

Modified: trafficserver/traffic/trunk/proxy/signals.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/signals.cc?rev=1061115&r1=1061114&r2=1061115&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/signals.cc (original)
+++ trafficserver/traffic/trunk/proxy/signals.cc Thu Jan 20 04:20:22 2011
@@ -106,8 +106,8 @@ class TrackerContinuation:public Continu
 public:
   int baseline_taken;
   int use_baseline;
-    TrackerContinuation()
-  : Continuation(new_ProxyMutex())
+  TrackerContinuation()
+    : Continuation(new_ProxyMutex())
   {
     SET_HANDLER(&TrackerContinuation::periodic);
     use_baseline = 0;



Mime
View raw message