]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Clean up the compact/verbose cookie code to prevent a lot of
authorJim Jagielski <jim@apache.org>
Wed, 18 Dec 2002 22:43:08 +0000 (22:43 +0000)
committerJim Jagielski <jim@apache.org>
Wed, 18 Dec 2002 22:43:08 +0000 (22:43 +0000)
overlap. Who knows, maybe a 3rd format might pop up one
day. If this breaks, note who to blame for it
PR:
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@98034 13f79535-47bb-0310-9956-ffa450edef68

src/CHANGES
src/modules/standard/mod_usertrack.c

index ea1dffd9af11c8366461dc8b5b8b1791cd03bf9b..0176c1ca1f6741c1db6737e01f0d0532db2a61ff 100644 (file)
@@ -15,7 +15,7 @@ Changes with Apache 1.3.28
      as well as "compact" version of the tracking cookie (the new
      'CookieFormat' directive), and the ability to prepend a string
      to the cookie via the 'CookiePrefix' directive.
-     [Pål Løberg <pallo@initio.no>]
+     [Pål Løberg <pallo@initio.no>, with cleanup by Jim Jagielski]
 
   *) Certain 3rd party modules would bypass the Apache API and not
      invoke ap_cleanup_for_exec() before creating sub-processes.
index 1368247ce517dfb004d936571494bd02aa0d87fd..eb7ec002dcf5f59655fc20b2ab665490b34aa4ee 100644 (file)
@@ -138,12 +138,12 @@ typedef struct {
 #define COOKIE_NAME "Apache"
 
 
-/* Make normal cookie: Try to make something unique based on 
+/* Make cookie id: Try to make something unique based on 
  * pid, time, and hostid, plus the user-configurable prefix.
  *
- * This function will make a "verbose" version of the cookie.
  */
-static char * make_normal_id(char * buffer, int bufsize, request_rec *r)
+static char * make_cookie_id(char * buffer, int bufsize, request_rec *r,
+                             cookie_format_e cformat)
 {
 #if defined(NO_GETTIMEOFDAY) && !defined(NO_TIMES)
     clock_t mpe_times;
@@ -156,70 +156,15 @@ static char * make_normal_id(char * buffer, int bufsize, request_rec *r)
     struct timezone tz = {0, 0};
 #endif /* defined(NETWARE) */
 #endif
-    const char *rname = ap_get_remote_host(r->connection, r->per_dir_config,
-                                          REMOTE_NAME);
-    cookie_dir_rec *dcfg;
-
-    dcfg = ap_get_module_config(r->per_dir_config, &usertrack_module);
-
-#if defined(NO_GETTIMEOFDAY) && !defined(NO_TIMES)
-/* We lack gettimeofday(), so we must use time() to obtain the epoch
-   seconds, and then times() to obtain CPU clock ticks (milliseconds).
-   Combine this together to obtain a hopefully unique cookie ID. */
-
-    mpe_times = times(&mpe_tms);
-
-    ap_snprintf(buffer, bufsize, "%s%s.%d%ld%ld", 
-               dcfg->prefix_string, rname, (int) getpid(),
-                (long) r->request_time, (long) mpe_tms.tms_utime);
-#elif defined(NETWARE)
-    ap_snprintf(buffer, bufsize, "%s%s.%d%ld%ld", 
-               dcfg->prefix_string, rname, (int) getpid(),
-               (long) r->request_time, (long) clock());
-#elif defined(WIN32)
-    /*
-     * We lack gettimeofday() and we lack times(). So we'll use a combination
-     * of time() and GetTickCount(), which returns milliseconds since Windows
-     * was started. It should be relatively unique.
-     */
-
-    ap_snprintf(buffer, bufsize, "%s%s.%d%ld%ld",
-               dcfg->prefix_string, rname, (int) getpid(),
-                (long) r->request_time, (long) GetTickCount());
 
-#else
-    gettimeofday(&tv, &tz);
-
-    ap_snprintf(buffer, bufsize, "%s%s.%d%ld%d", 
-               dcfg->prefix_string, rname, (int) getpid(),
-                (long) tv.tv_sec, (int) tv.tv_usec / 1000);
-#endif
-
-    return buffer;
-}
+    cookie_dir_rec *dcfg;
 
+    long reqtime = (long) r->request_time;
+    long clocktime;
 
-/* Make normal cookie: Try to make something unique based on 
- * pid, time, and hostid, plus the user-configurable prefix.
- *
- * This function will make a "compact" version of the cookie.
- */
-static char * make_compact_id(char * buffer, int bufsize, request_rec *r)
-{
-#if defined(NO_GETTIMEOFDAY) && !defined(NO_TIMES)
-    clock_t mpe_times;
-    struct tms mpe_tms;
-#elif !defined(WIN32)
-    struct timeval tv;
-#ifdef NETWARE
-    time_t tz = 0;
-#else
-    struct timezone tz = {0, 0};
-#endif /* defined(NETWARE) */
-#endif
     unsigned long ipaddr = ntohl(r->connection->remote_addr.sin_addr.s_addr);
-    cookie_dir_rec *dcfg;
-
+    const char *rname = ap_get_remote_host(r->connection, r->per_dir_config,
+                                          REMOTE_NAME);
     dcfg = ap_get_module_config(r->per_dir_config, &usertrack_module);
 
 #if defined(NO_GETTIMEOFDAY) && !defined(NO_TIMES)
@@ -228,37 +173,44 @@ static char * make_compact_id(char * buffer, int bufsize, request_rec *r)
    Combine this together to obtain a hopefully unique cookie ID. */
 
     mpe_times = times(&mpe_tms);
-
-    ap_snprintf(buffer, bufsize, "%s%lx%x%lx%lx", 
-               dcfg->prefix_string, ipaddr, (int) getpid(),
-                (long) r->request_time, (long) mpe_tms.tms_utime);
+    clocktime = (long) mpe_tms.tms_utime;
+    
 #elif defined(NETWARE)
-    ap_snprintf(buffer, bufsize, "%s%lx%x%lx%lx", 
-               dcfg->prefix_string, ipaddr, (int) getpid(),
-               (long) r->request_time, (long) clock());
+    clocktime = (long) clock();
+
 #elif defined(WIN32)
     /*
-     * We lack gettimeofday() and we lack times(). So we'll use a combination
-     * of time() and GetTickCount(), which returns milliseconds since Windows
+     * We lack gettimeofday() and we lack times(). So we'll use
+     * GetTickCount(), which returns milliseconds since Windows
      * was started. It should be relatively unique.
      */
 
-    ap_snprintf(buffer, bufsize, "%s%lx%x%lx%lx",
-               dcfg->prefix_string, ipaddr, (int) getpid(),
-                (long) r->request_time, (long) GetTickCount());
+    clocktime = (long) GetTickCount());
 
 #else
     gettimeofday(&tv, &tz);
 
-    ap_snprintf(buffer, bufsize, "%s%lx%x%lx%x", 
-               dcfg->prefix_string, ipaddr, (int) getpid(),
-                (long) tv.tv_sec, (int)(tv.tv_usec % 65535));
+    reqtime = (long) tv.tv_sec;
+    if (cformat == CF_COMPACT)
+       clocktime = (long) (tv.tv_usec % 65535);
+    else
+       clocktime = (long) (tv.tv_usec / 1000);
 #endif
 
+    if (cformat == CF_COMPACT)
+       ap_snprintf(buffer, bufsize, "%s%lx%x%lx%lx", 
+                   dcfg->prefix_string, ipaddr, (int) getpid(),
+                    reqtime, clocktime);
+    else
+       ap_snprintf(buffer, bufsize, "%s%s.%d%ld%ld", 
+                   dcfg->prefix_string, rname, (int) getpid(),
+                    reqtime, clocktime);
+
     return buffer;
 }
 
 
+
 static void make_cookie(request_rec *r)
 {
     cookie_log_state *cls = ap_get_module_config(r->server->module_config,
@@ -271,11 +223,7 @@ static void make_cookie(request_rec *r)
 
     dcfg = ap_get_module_config(r->per_dir_config, &usertrack_module);
 
-    if (dcfg->format == CF_COMPACT) {
-       make_compact_id(cookiebuf, sizeof(cookiebuf), r);
-    } else {
-       make_normal_id(cookiebuf, sizeof(cookiebuf), r);
-    }
+    make_cookie_id(cookiebuf, sizeof(cookiebuf), r, dcfg->format);
 
     if (cls->expires) {
         struct tm *tms;