| 180 | } |
| 181 | |
| 182 | static int log_before(request_rec *r) |
| 183 | { |
| 184 | fcfg *cfg = ap_get_module_config(r->server->module_config, |
| 185 | &log_forensic_module); |
| 186 | const char *id; |
| 187 | hlog h; |
| 188 | apr_size_t n; |
| 189 | apr_status_t rv; |
| 190 | |
| 191 | if (!cfg->fd || r->prev) { |
| 192 | return DECLINED; |
| 193 | } |
| 194 | |
| 195 | if (!(id = apr_table_get(r->subprocess_env, "UNIQUE_ID"))) { |
| 196 | /* we make the assumption that we can't go through all the PIDs in |
| 197 | under 1 second */ |
| 198 | id = apr_psprintf(r->pool, "%" APR_PID_T_FMT ":%lx:%x", getpid(), |
| 199 | time(NULL), apr_atomic_inc32(&next_id)); |
| 200 | } |
| 201 | ap_set_module_config(r->request_config, &log_forensic_module, (char *)id); |
| 202 | |
| 203 | h.p = r->pool; |
| 204 | h.count = 0; |
| 205 | |
| 206 | apr_table_do(count_headers, &h, r->headers_in, NULL); |
| 207 | |
| 208 | h.count += 1+strlen(id)+1+count_string(r->the_request)+1+1; |
| 209 | h.log = apr_palloc(r->pool, h.count); |
| 210 | h.pos = h.log; |
| 211 | h.end = h.log+h.count; |
| 212 | |
| 213 | *h.pos++ = '+'; |
| 214 | strcpy(h.pos, id); |
| 215 | h.pos += strlen(h.pos); |
| 216 | *h.pos++ = '|'; |
| 217 | h.pos = log_escape(h.pos, h.end, r->the_request); |
| 218 | |
| 219 | apr_table_do(log_headers, &h, r->headers_in, NULL); |
| 220 | |
| 221 | ap_assert(h.pos < h.end); |
| 222 | *h.pos++ = '\n'; |
| 223 | |
| 224 | n = h.count-1; |
| 225 | rv = apr_file_write(cfg->fd, h.log, &n); |
| 226 | ap_assert(rv == APR_SUCCESS && n == h.count-1); |
| 227 | |
| 228 | apr_table_setn(r->notes, "forensic-id", id); |
| 229 | |
| 230 | return OK; |
| 231 | } |
| 232 | |
| 233 | static int log_after(request_rec *r) |
| 234 | { |
nothing calls this directly
no test coverage detected