#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;
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)
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,
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;