httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject cvs commit: apache-1.3/src/modules/standard mod_usertrack.c
Date Wed, 18 Dec 2002 22:43:08 GMT
jim         2002/12/18 14:43:08

  Modified:    src      CHANGES
               src/modules/standard mod_usertrack.c
  Log:
  Clean up the compact/verbose cookie code to prevent a lot of
  overlap. Who knows, maybe a 3rd format might pop up one
  day. If this breaks, note who to blame for it
  
  Revision  Changes    Path
  1.1871    +1 -1      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1870
  retrieving revision 1.1871
  diff -u -r1.1870 -r1.1871
  --- CHANGES	18 Dec 2002 22:31:40 -0000	1.1870
  +++ CHANGES	18 Dec 2002 22:43:07 -0000	1.1871
  @@ -15,7 +15,7 @@
        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.
  
  
  
  1.54      +31 -83    apache-1.3/src/modules/standard/mod_usertrack.c
  
  Index: mod_usertrack.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_usertrack.c,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- mod_usertrack.c	16 Dec 2002 13:17:38 -0000	1.53
  +++ mod_usertrack.c	18 Dec 2002 22:43:08 -0000	1.54
  @@ -138,12 +138,12 @@
   #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 @@
       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 @@
      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 @@
   
       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;
  
  
  

Mime
View raw message