Author: igalic
Date: Sun Sep 18 23:35:59 2011
New Revision: 1172393

URL: http://svn.apache.org/viewvc?rev=1172393&view=rev
Log:
TS-953: consolidate string copy/concat for proxy/logging.

Modified:
    trafficserver/traffic/trunk/proxy/logging/LogAccess.cc
    trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc
    trafficserver/traffic/trunk/proxy/logging/LogConfig.cc
    trafficserver/traffic/trunk/proxy/logging/LogFieldAliasMap.h
    trafficserver/traffic/trunk/proxy/logging/LogFormat.cc
    trafficserver/traffic/trunk/proxy/logging/LogObject.cc
    trafficserver/traffic/trunk/proxy/logging/LogSock.cc
    trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc
    trafficserver/traffic/trunk/proxy/logging/LogUtils.cc

Modified: trafficserver/traffic/trunk/proxy/logging/LogAccess.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogAccess.cc?rev=1172393&r1=1172392&r2=1172393&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogAccess.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogAccess.cc Sun Sep 18 23:35:59 
2011
@@ -1,6 +1,6 @@
 /** @file
 
-  A brief file description
+  This file implements the LogAccess class.
 
   @section license License
 
@@ -19,23 +19,19 @@
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
- */
-
-/***************************************************************************
- LogAccess.cc
-
- This file implements the LogAccess class.  However, LogAccess is an
- abstract base class, providing an interface that logging uses to get
- information from a module, such as HTTP or ICP.  Each module derives a
- specific implementation from this base class (such as LogAccessHttp), and
- implements the virtual accessor functions there.
-
- The LogAccess class also defines a set of static functions that are used
- to provide support for marshalling and unmarshalling support for the other
- LogAccess derived classes.
 
+  @section description
+  This file implements the LogAccess class.  However, LogAccess is an
+  abstract base class, providing an interface that logging uses to get
+  information from a module, such as HTTP or ICP.  Each module derives a
+  specific implementation from this base class (such as LogAccessHttp), and
+  implements the virtual accessor functions there.
+
+  The LogAccess class also defines a set of static functions that are used
+  to provide support for marshalling and unmarshalling support for the other
+  LogAccess derived classes.
+ */
 
- ***************************************************************************/
 #include "ink_unused.h"
 
 #include "libts.h"
@@ -751,7 +747,7 @@ LogAccess::marshal_str(char *dest, const
   if (source == NULL || source[0] == 0 || padded_len == 0) {
     source = DEFAULT_STR;
   }
-  ink_strncpy(dest, source, padded_len);
+  ink_strlcpy(dest, source, padded_len);
 
 #ifdef DEBUG
   //
@@ -813,7 +809,7 @@ LogAccess::unmarshal_with_map(int64_t co
       char invalidCodeMsg[bufSize];
       codeStrLen = snprintf(invalidCodeMsg, 64, "%s(%" PRId64 ")", msg, code);
       if (codeStrLen < bufSize && codeStrLen < len) {
-        ink_strncpy(dest, invalidCodeMsg, len);
+        ink_strlcpy(dest, invalidCodeMsg, len);
       } else {
         codeStrLen = -1;
       }

Modified: trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc?rev=1172393&r1=1172392&r2=1172393&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogBuffer.cc Sun Sep 18 23:35:59 
2011
@@ -1,6 +1,6 @@
 /** @file
 
-  A brief file description
+  This file implements the LogBuffer class, a thread-safe buffer for
 
   @section license License
 
@@ -19,17 +19,13 @@
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
- */
-
-/***************************************************************************
- LogBuffer.cc
-
- This file implements the LogBuffer class, which is a thread-safe buffer
- for recording log entries.  See the header file LogBuffer.h for more
- information on the structure of a LogBuffer.
 
+  @section description
+  This file implements the LogBuffer class, a thread-safe buffer for
+  recording log entries. See the header file LogBuffer.h for more
+  information on the structure of a LogBuffer.
+ */
 
- ***************************************************************************/
 
 #include "libts.h"
 #include "ink_unused.h"
@@ -358,8 +354,7 @@ LogBuffer::add_header_str(char *str, cha
 {
   unsigned len = 0;
   if (likely(str && (len = (unsigned) (strlen(str) + 1)) < buf_len)) {
-    ink_strncpy(buf_ptr, str, buf_len);
-    buf_ptr[len] = '\0';
+    ink_strlcpy(buf_ptr, str, buf_len);
   }
   return len;
 }

Modified: trafficserver/traffic/trunk/proxy/logging/LogConfig.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogConfig.cc?rev=1172393&r1=1172392&r2=1172393&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogConfig.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogConfig.cc Sun Sep 18 23:35:59 
2011
@@ -98,7 +98,7 @@ LogConfig::setup_default_values()
   const unsigned int bufSize = 512;
   char name[bufSize];
   if (!gethostname(name, bufSize)) {
-    ink_strncpy(name, "unknown_host_name", sizeof(name));
+    ink_strlcpy(name, "unknown_host_name", sizeof(name));
   }
   hostname = ats_strdup(name);
 

Modified: trafficserver/traffic/trunk/proxy/logging/LogFieldAliasMap.h
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogFieldAliasMap.h?rev=1172393&r1=1172392&r2=1172393&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogFieldAliasMap.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogFieldAliasMap.h Sun Sep 18 
23:35:59 2011
@@ -1,6 +1,6 @@
 /** @file
 
-  A brief file description
+  This file implements an abstract class to map between numbers of type IntType
 
   @section license License
 
@@ -19,13 +19,13 @@
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
- */
-
-/***************************************************************************
- LogFieldAliasMap.h
 
+  @section description
+  This file implements an abstract class to map between numbers of type IntType
+  and strings. The purpose is to obtain one representation from the other so 
that
+  easily remembered names can be used to refer to log fields of integer type.
+ */
 
- ***************************************************************************/
 
 #ifndef LOG_FIELD_ALIAS_MAP_H
 #define LOG_FIELD_ALIAS_MAP_H
@@ -167,7 +167,7 @@ public:
       register size_t l = m_table[i].length;
       if (l < bufLen)
       {
-        ink_strncpy(buf, m_table[key - m_min].name, bufLen);
+        ink_strlcpy(buf, m_table[key - m_min].name, bufLen);
         numChars = l;
         retVal = ALL_OK;
       } else

Modified: trafficserver/traffic/trunk/proxy/logging/LogFormat.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogFormat.cc?rev=1172393&r1=1172392&r2=1172393&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogFormat.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogFormat.cc Sun Sep 18 23:35:59 
2011
@@ -88,10 +88,10 @@ LogFormat::setup(const char *name, const
     const char *tag = " %<phn>";
     const size_t m_format_str_size = strlen(format_str) + (m_tagging_on ? 
strlen(tag) : 0) + 1;
     m_format_str = (char *)ats_malloc(m_format_str_size);
-    ink_strncpy(m_format_str, format_str, m_format_str_size);
+    ink_strlcpy(m_format_str, format_str, m_format_str_size);
     if (m_tagging_on) {
       Note("Log tagging enabled, adding %%<phn> field at the end of " "format 
%s", name);
-      strncat(m_format_str, tag, m_format_str_size - strlen(m_format_str) - 1);
+      ink_strlcat(m_format_str, tag, m_format_str_size);
     };
 
     char *printf_str = NULL;

Modified: trafficserver/traffic/trunk/proxy/logging/LogObject.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogObject.cc?rev=1172393&r1=1172392&r2=1172393&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogObject.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogObject.cc Sun Sep 18 23:35:59 
2011
@@ -602,7 +602,7 @@ LogObject::log(LogAccess * lad, char *te
     bytes_used = m_format->m_field_list.marshal(lad, &(*buffer)[offset]);
     ink_assert(bytes_needed >= bytes_used);
   } else if (text_entry) {
-    ink_strncpy(&(*buffer)[offset], text_entry, bytes_needed);
+    ink_strlcpy(&(*buffer)[offset], text_entry, bytes_needed);
   }
 
   LogBuffer::LB_ResultCode result_code = buffer->checkin_write(offset);

Modified: trafficserver/traffic/trunk/proxy/logging/LogSock.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogSock.cc?rev=1172393&r1=1172392&r2=1172393&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogSock.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogSock.cc Sun Sep 18 23:35:59 
2011
@@ -21,11 +21,6 @@
   limitations under the License.
  */
 
-/***************************************************************************
- LogSock.cc
-
-
- ***************************************************************************/
 #include "ink_unused.h"
 
 #include "P_EventSystem.h"
@@ -38,14 +33,13 @@ static const int LS_DOMAIN = AF_INET;
 static const int LS_SOCKTYPE = SOCK_STREAM;
 static const int LS_PROTOCOL = 0;
 
-/*-------------------------------------------------------------------------
+/**
   LogSock
 
   The constructor establishes the connection table (ct) and initializes the
   first entry of the table (index 0) to be the port on which new
   connections are accepted.
-  -------------------------------------------------------------------------*/
-
+*/ 
 LogSock::LogSock(int max_connects)
   :
 ct((ConnectTable *) NULL),
@@ -66,12 +60,11 @@ m_max_connections(max_connects + 1)
   Debug("log-sock", "LogSocket established");
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::~LogSock
 
   Shut down all connections and delete memory for the tables.
-  -------------------------------------------------------------------------*/
-
+*/ 
 LogSock::~LogSock()
 {
   Debug("log-sock", "shutting down LogSocket on [%s:%d]", ct[0].host, 
ct[0].port);
@@ -81,16 +74,15 @@ LogSock::~LogSock()
   delete[]ct;                   // delete the connection table
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::listen
 
   This routine sets up the LogSock to begin accepting connections on the
-  given accept port.  A maximum number of connections is also specified,
+  given @param accept port.  A maximum number of connections is also specified,
   which is used to establish the size of the listen queue.
 
-  Return zero if all goes well, -1 otherwise.
-  -------------------------------------------------------------------------*/
-
+  @Return zero if all goes well, -1 otherwise.
+*/
 int
 LogSock::listen(int accept_port)
 {
@@ -185,14 +177,14 @@ LogSock::listen(int accept_port)
   return 0;
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::accept
 
   Accept a new connection.  This is a blocking operation, so you may want
   to use one of the non-blocking pending_XXX calls to see if there is a
-  connection first.  This returns the table index for the new connection.
-  -------------------------------------------------------------------------*/
-
+  connection first.
+  @return This returns the table index for the new connection.
+*/
 int
 LogSock::accept()
 {
@@ -225,13 +217,12 @@ LogSock::accept()
   return cid;
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::connect
 
   Establish a new connection to another machine [host:port], and place this
   information into the connection and poll tables.
-  -------------------------------------------------------------------------*/
-
+*/  
 int
 LogSock::connect(char *host, int port)
 {
@@ -301,14 +292,14 @@ LogSock::connect(unsigned host_ip, int p
   return cid;
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::pending_data
 
   This private routine checks for incoming data on some of the socket
-  descriptors.  Returns true if there is something incoming, with *cid
+  descriptors.
+  @return Returns true if there is something incoming, with *cid
   set to the index corresponding to the incoming socket.
-  -------------------------------------------------------------------------*/
-
+*/ 
 bool LogSock::pending_data(int *cid, int timeout_msec, bool include_connects)
 {
   int
@@ -390,12 +381,11 @@ bool LogSock::pending_data(int *cid, int
   return false;
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::pending_any
 
   Check for incomming data on any of the INCOMING sockets.
-  -------------------------------------------------------------------------*/
-
+*/
 bool LogSock::pending_any(int *cid, int timeout_msec)
 {
   ink_assert(cid != NULL);
@@ -421,24 +411,22 @@ bool LogSock::pending_message_any(int *c
   return pending_data(cid, timeout_msec, false);
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::pending_message_on
 
   Check for incomming data on the specified socket.
-  -------------------------------------------------------------------------*/
-
+*/
 bool LogSock::pending_message_on(int cid, int timeout_msec)
 {
   return pending_data(&cid, timeout_msec, false);
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::pending_connect
 
   Check for an incoming connection request on the socket reserved for that
   (cid = 0).
-  -------------------------------------------------------------------------*/
-
+*/
 bool LogSock::pending_connect(int timeout_msec)
 {
   int
@@ -450,13 +438,12 @@ bool LogSock::pending_connect(int timeou
   }
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::close
 
   Close one (cid specified) or all (no argument) sockets, except for the
   incomming connection socket.
-  -------------------------------------------------------------------------*/
-
+*/
 void
 LogSock::close(int cid)
 {
@@ -479,13 +466,12 @@ LogSock::close()
   }
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::write
 
   Write data onto the socket corresponding to the given cid.  Return the
   number of bytes actually written.
-  -------------------------------------------------------------------------*/
-
+*/
 int
 LogSock::write(int cid, void *buf, int bytes)
 {
@@ -522,14 +508,13 @@ LogSock::write(int cid, void *buf, int b
   return::send(ct[cid].sd, (char *) buf, bytes, 0);
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::read
 
   Read data from the specified connection.  This is a blocking call, so you
   may want to use one of the pending_XXX calls to see if there is anything
   to read first.  Returns number of bytes read.
-  -------------------------------------------------------------------------*/
-
+*/
 int
 LogSock::read(int cid, void *buf, unsigned maxsize)
 {
@@ -553,15 +538,14 @@ LogSock::read(int cid, void *buf, unsign
   return read_body(ct[cid].sd, buf, size);
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::read_alloc
 
   This routine reads data from the specified connection, and returns a
   pointer to newly allocated space (allocated with new) containing the
   data.  The number of bytes read is set in the argument size, which is
   expected to be a pointer to an int.
-  -------------------------------------------------------------------------*/
-
+*/
 void *
 LogSock::read_alloc(int cid, int *size)
 {
@@ -591,9 +575,8 @@ LogSock::read_alloc(int cid, int *size)
   return data;
 }
 
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
+/**
+*/
 bool LogSock::is_connected(int cid, bool ping)
 {
   int
@@ -622,9 +605,8 @@ bool LogSock::is_connected(int cid, bool
   }
 }
 
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
+/**
+*/
 void
 LogSock::check_connections()
 {
@@ -638,12 +620,11 @@ LogSock::check_connections()
   }
 }
 
-/*-------------------------------------------------------------------------
+/**
   This routine will check to ensure that the client connecting is
   authorized to use the log collation port.  To authorize, the client is
   expected to send the logging secret string.
-  -------------------------------------------------------------------------*/
-
+*/
 bool LogSock::authorized_client(int cid, char *key)
 {
   //
@@ -669,8 +650,8 @@ bool LogSock::authorized_client(int cid,
   return false;
 }
 
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
+/**
+*/
 char *
 LogSock::connected_host(int cid)
 {
@@ -678,9 +659,8 @@ LogSock::connected_host(int cid)
   return ct[cid].host;
 }
 
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
+/**
+*/
 int
 LogSock::connected_port(int cid)
 {
@@ -692,10 +672,9 @@ LogSock::connected_port(int cid)
   LOCAL ROUTINES
   -------------------------------------------------------------------------*/
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::new_cid
-  -------------------------------------------------------------------------*/
-
+*/
 int
 LogSock::new_cid()
 {
@@ -711,10 +690,9 @@ LogSock::new_cid()
   return cid;
 }
 
-/*-------------------------------------------------------------------------
+/**
   LogSock::init_cid
-  -------------------------------------------------------------------------*/
-
+*/
 void
 LogSock::init_cid(int cid, char *host, int port, int sd, LogSock::State state)
 {
@@ -727,7 +705,7 @@ LogSock::init_cid(int cid, char *host, i
   if (host != NULL) {
     const size_t host_size = strlen(host) + 1;
     ct[cid].host = NEW(new char[host_size]);
-    ink_strncpy(ct[cid].host, host, sizeof(host_size));
+    ink_strlcpy(ct[cid].host, host, host_size);
   } else {
     ct[cid].host = NULL;
   }
@@ -737,9 +715,8 @@ LogSock::init_cid(int cid, char *host, i
   ct[cid].state = state;
 }
 
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
+/**
+*/
 int
 LogSock::read_header(int sd, LogSock::MsgHeader * header)
 {
@@ -755,9 +732,8 @@ LogSock::read_header(int sd, LogSock::Ms
   return bytes;
 }
 
-/*-------------------------------------------------------------------------
-  -------------------------------------------------------------------------*/
-
+/**
+*/
 int
 LogSock::read_body(int sd, void *buf, int bytes)
 {

Modified: trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc?rev=1172393&r1=1172392&r2=1172393&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc Sun Sep 18 
23:35:59 2011
@@ -103,7 +103,7 @@ initialize_process_manager()
   }
 
   if (management_directory[0] == '\0') {
-    ink_strncpy(management_directory, Layout::get()->sysconfdir, 
PATH_NAME_MAX);
+    ink_strlcpy(management_directory, Layout::get()->sysconfdir, 
sizeof(management_directory));
     if (access(management_directory, R_OK) == -1) {
       fprintf(stderr,"unable to access() management path '%s': %d, %s\n",
               management_directory, errno, strerror(errno));

Modified: trafficserver/traffic/trunk/proxy/logging/LogUtils.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogUtils.cc?rev=1172393&r1=1172392&r2=1172393&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogUtils.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogUtils.cc Sun Sep 18 23:35:59 
2011
@@ -1,6 +1,7 @@
 /** @file
 
-  A brief file description
+ This file contains a set of utility routines that are used throughout the
+ logging implementation.
 
   @section license License
 
@@ -21,14 +22,6 @@
   limitations under the License.
  */
 
-/***************************************************************************
- LogUtils.cc
-
- This file contains a set of utility routines that are used throughout the
- logging implementation.
-
-
- ***************************************************************************/
 
 #include "ink_config.h"
 #include "ink_unused.h"
@@ -156,7 +149,7 @@ LogUtils::timestamp_to_netscape_str(long
                             sign, offset / 60, offset % 60);
 
     strftime(timebuf, 64 - glen, "%d/%b/%Y:%H:%M:%S ", tms);
-    strncat(timebuf, gmtstr, sizeof(timebuf) - strlen(timebuf) - 1);
+    ink_strlcat(timebuf, gmtstr, sizeof(timebuf));
     last_timestamp = timestamp;
   }
   return timebuf;


Reply via email to