summaryrefslogtreecommitdiffstats
path: root/functions20.h
diff options
context:
space:
mode:
authorGravatar Edward Rudd 2004-01-20 16:27:35 +0000
committerGravatar Edward Rudd 2004-01-20 16:27:35 +0000
commit40f0c8fe04858acd724d6221dbf8a357259e5d6b (patch)
treec3effb1a7fa38e47152417830ab1c7480bddf703 /functions20.h
parent417afc1671669fc9ba79410546c6ddfe242f2f4a (diff)
split out version specific code
code compiles under apache 1.3 and 2.0 updated apache m4 script to detect both verions (two minumums) defaulted install to not activate module in configuration file (use make activate)
Diffstat (limited to 'functions20.h')
-rw-r--r--functions20.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/functions20.h b/functions20.h
new file mode 100644
index 0000000..9ff3a63
--- /dev/null
+++ b/functions20.h
@@ -0,0 +1,92 @@
1/* functions */
2static const char *extract_request_time_custom(request_rec *r, char *a,
3 apr_time_exp_t *xt)
4{
5 apr_size_t retcode;
6 char tstr[MAX_STRING_LEN];
7 apr_strftime(tstr, &retcode, sizeof(tstr), a, xt);
8 return apr_pstrdup(r->pool, tstr);
9}
10
11#define DEFAULT_REQUEST_TIME_SIZE 32
12typedef struct {
13 unsigned t;
14 char timestr[DEFAULT_REQUEST_TIME_SIZE];
15 unsigned t_validate;
16} cached_request_time;
17
18#define TIME_CACHE_SIZE 4
19#define TIME_CACHE_MASK 3
20static cached_request_time request_time_cache[TIME_CACHE_SIZE];
21
22static const char *extract_request_time(request_rec *r, char *a)
23{
24 apr_time_exp_t xt;
25
26 /* Please read comments in mod_log_config.h for more info about
27 * the I_INSIST....COMPLIANCE define
28 */
29 if (a && *a) { /* Custom format */
30#ifdef I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE
31 ap_explode_recent_localtime(&xt, apr_time_now());
32#else
33 ap_explode_recent_localtime(&xt, r->request_time);
34#endif
35 return extract_request_time_custom(r, a, &xt);
36 } else { /* CLF format */
37 /* This code uses the same technique as ap_explode_recent_localtime():
38 * optimistic caching with logic to detect and correct race conditions.
39 * See the comments in server/util_time.c for more information.
40 */
41 cached_request_time* cached_time = apr_palloc(r->pool,
42 sizeof(*cached_time));
43#ifdef I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE
44 apr_time_t request_time = apr_time_now();
45#else
46 apr_time_t request_time = r->request_time;
47#endif
48 unsigned t_seconds = (unsigned)apr_time_sec(request_time);
49 unsigned i = t_seconds & TIME_CACHE_MASK;
50 memcpy(cached_time, &(request_time_cache[i]), sizeof(*cached_time));
51 if ((t_seconds != cached_time->t) ||
52 (t_seconds != cached_time->t_validate)) {
53
54 /* Invalid or old snapshot, so compute the proper time string
55 * and store it in the cache
56 */
57 char sign;
58 int timz;
59
60 ap_explode_recent_localtime(&xt, r->request_time);
61 timz = xt.tm_gmtoff;
62 if (timz < 0) {
63 timz = -timz;
64 sign = '-';
65 }
66 else {
67 sign = '+';
68 }
69 cached_time->t = t_seconds;
70 apr_snprintf(cached_time->timestr, DEFAULT_REQUEST_TIME_SIZE,
71 "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]",
72 xt.tm_mday, apr_month_snames[xt.tm_mon],
73 xt.tm_year+1900, xt.tm_hour, xt.tm_min, xt.tm_sec,
74 sign, timz / (60*60), timz % (60*60));
75 cached_time->t_validate = t_seconds;
76 memcpy(&(request_time_cache[i]), cached_time,
77 sizeof(*cached_time));
78 }
79 return cached_time->timestr;
80 }
81}
82
83static const char *extract_request_duration(request_rec *r, char *a)
84{
85 apr_time_t duration = apr_time_now() - r->request_time;
86 return apr_psprintf(r->pool, "%" APR_TIME_T_FMT, apr_time_sec(duration));
87}
88
89static const char *extract_request_timestamp(request_rec *r, char *a)
90{
91 return apr_psprintf(r->pool, "%"APR_TIME_T_FMT, apr_time_sec(apr_time_now()));
92}