diff options
author | Edward Rudd <urkle@outoforder.cc> | 2008-10-25 16:44:17 (GMT) |
---|---|---|
committer | Edward Rudd <urkle@outoforder.cc> | 2008-10-25 16:44:17 (GMT) |
commit | 19e09e15d96fa891d18fd07bb0f751faa0a7fc7a (patch) | |
tree | 77da4c55a5c91713184a1344cca6270ae8fd0afe /utility/util.c | |
parent | caae8dcfed1462cb19c82f99087e6fe2ba3d407c (diff) |
implement query arg extracter
"merge in" ap_unescape_url from HTTPD
updated logging statements
add per-line func data and per-func data
Diffstat (limited to 'utility/util.c')
-rw-r--r-- | utility/util.c | 96 |
1 files changed, 93 insertions, 3 deletions
diff --git a/utility/util.c b/utility/util.c index 99bb046..7ecb902 100644 --- a/utility/util.c +++ b/utility/util.c | |||
@@ -31,6 +31,99 @@ void line_chomp(char *str) | |||
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | /* | ||
35 | * *** Ripped from HTTPD util.c (why are so many PORTABLE things not in APR UTIL?) | ||
36 | */ | ||
37 | static char x2c(const char *what) | ||
38 | { | ||
39 | register char digit; | ||
40 | |||
41 | digit = ((what[0] >= 'A') ? ((what[0] & 0xdf) - 'A') + 10 | ||
42 | : (what[0] - '0')); | ||
43 | digit *= 16; | ||
44 | digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A') + 10 | ||
45 | : (what[1] - '0')); | ||
46 | return (digit); | ||
47 | } | ||
48 | |||
49 | /* | ||
50 | * *** Ripped from HTTPD util.c (why are so many PORTABLE things not in APR UTIL?) | ||
51 | * | ||
52 | * Unescapes a URL, leaving reserved characters intact. | ||
53 | * Returns 0 on success, non-zero on error | ||
54 | * Failure is due to | ||
55 | * bad % escape returns HTTP_BAD_REQUEST | ||
56 | * | ||
57 | * decoding %00 or a forbidden character returns HTTP_NOT_FOUND | ||
58 | */ | ||
59 | static int unescape_url(char *url, const char *forbid, const char *reserved) | ||
60 | { | ||
61 | register int badesc, badpath; | ||
62 | char *x, *y; | ||
63 | |||
64 | badesc = 0; | ||
65 | badpath = 0; | ||
66 | /* Initial scan for first '%'. Don't bother writing values before | ||
67 | * seeing a '%' */ | ||
68 | y = strchr(url, '%'); | ||
69 | if (y == NULL) { | ||
70 | return APR_SUCCESS; | ||
71 | } | ||
72 | for (x = y; *y; ++x, ++y) { | ||
73 | if (*y != '%') { | ||
74 | *x = *y; | ||
75 | } | ||
76 | else { | ||
77 | if (!apr_isxdigit(*(y + 1)) || !apr_isxdigit(*(y + 2))) { | ||
78 | badesc = 1; | ||
79 | *x = '%'; | ||
80 | } | ||
81 | else { | ||
82 | char decoded; | ||
83 | decoded = x2c(y + 1); | ||
84 | if ((decoded == '\0') | ||
85 | || (forbid && strchr(forbid, decoded))) { | ||
86 | badpath = 1; | ||
87 | *x = decoded; | ||
88 | y += 2; | ||
89 | } | ||
90 | else if (reserved && strchr(reserved, decoded)) { | ||
91 | *x++ = *y++; | ||
92 | *x++ = *y++; | ||
93 | *x = *y; | ||
94 | } | ||
95 | else { | ||
96 | *x = decoded; | ||
97 | y += 2; | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | *x = '\0'; | ||
103 | if (badesc) { | ||
104 | return APR_EINVAL; | ||
105 | } | ||
106 | else if (badpath) { | ||
107 | return APR_EINVAL; | ||
108 | } | ||
109 | else { | ||
110 | return APR_SUCCESS; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | /* | ||
115 | * *** Ripped from HTTPD util.c (why are so many PORTABLE things not in APR UTIL?) | ||
116 | */ | ||
117 | int ap_unescape_url(char *url) | ||
118 | { | ||
119 | /* Traditional */ | ||
120 | #ifdef CASE_BLIND_FILESYSTEM | ||
121 | return unescape_url(url, "/\\", NULL); | ||
122 | #else | ||
123 | return unescape_url(url, "/", NULL); | ||
124 | #endif | ||
125 | } | ||
126 | |||
34 | void logging_init(config_t *cfg) | 127 | void logging_init(config_t *cfg) |
35 | { | 128 | { |
36 | apr_status_t rv; | 129 | apr_status_t rv; |
@@ -58,9 +151,6 @@ const char *logging_strerror(apr_status_t rv) | |||
58 | return apr_strerror(rv, buff, 256); | 151 | return apr_strerror(rv, buff, 256); |
59 | } | 152 | } |
60 | 153 | ||
61 | /** | ||
62 | * @todo implement logging | ||
63 | */ | ||
64 | void logging_log(config_t *cfg, loglevel_e level, const char *fmt, ...) | 154 | void logging_log(config_t *cfg, loglevel_e level, const char *fmt, ...) |
65 | { | 155 | { |
66 | va_list ap; | 156 | va_list ap; |