| 187 | }; |
| 188 | |
| 189 | static int log_script(request_rec *r, cgi_server_conf * conf, int ret, |
| 190 | char *dbuf, const char *sbuf, apr_bucket_brigade *bb, |
| 191 | apr_file_t *script_err) |
| 192 | { |
| 193 | const apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in); |
| 194 | const apr_table_entry_t *hdrs = (const apr_table_entry_t *) hdrs_arr->elts; |
| 195 | char argsbuffer[HUGE_STRING_LEN]; |
| 196 | apr_file_t *f = NULL; |
| 197 | apr_bucket *e; |
| 198 | const char *buf; |
| 199 | apr_size_t len; |
| 200 | apr_status_t rv; |
| 201 | int first; |
| 202 | int i; |
| 203 | apr_finfo_t finfo; |
| 204 | char time_str[APR_CTIME_LEN]; |
| 205 | |
| 206 | /* XXX Very expensive mainline case! Open, then getfileinfo! */ |
| 207 | if (!conf->logname || |
| 208 | ((apr_stat(&finfo, conf->logname, |
| 209 | APR_FINFO_SIZE, r->pool) == APR_SUCCESS) && |
| 210 | (finfo.size > conf->logbytes)) || |
| 211 | (apr_file_open(&f, conf->logname, |
| 212 | APR_APPEND|APR_WRITE|APR_CREATE, APR_OS_DEFAULT, |
| 213 | r->pool) != APR_SUCCESS)) { |
| 214 | /* Soak up script output */ |
| 215 | discard_script_output(bb); |
| 216 | log_script_err(r, script_err); |
| 217 | return ret; |
| 218 | } |
| 219 | |
| 220 | /* "%% [Wed Jun 19 10:53:21 1996] GET /cgi-bin/printenv HTTP/1.0" */ |
| 221 | apr_ctime(time_str, apr_time_now()); |
| 222 | apr_file_printf(f, "%%%% [%s] %s %s%s%s %s\n", time_str, r->method, r->uri, |
| 223 | r->args ? "?" : "", r->args ? r->args : "", r->protocol); |
| 224 | /* "%% 500 /usr/local/apache/cgi-bin" */ |
| 225 | apr_file_printf(f, "%%%% %d %s\n", ret, r->filename); |
| 226 | |
| 227 | apr_file_puts("%request\n", f); |
| 228 | for (i = 0; i < hdrs_arr->nelts; ++i) { |
| 229 | if (!hdrs[i].key) |
| 230 | continue; |
| 231 | apr_file_printf(f, "%s: %s\n", hdrs[i].key, hdrs[i].val); |
| 232 | } |
| 233 | if ((r->method_number == M_POST || r->method_number == M_PUT) && |
| 234 | *dbuf) { |
| 235 | apr_file_printf(f, "\n%s\n", dbuf); |
| 236 | } |
| 237 | |
| 238 | apr_file_puts("%response\n", f); |
| 239 | hdrs_arr = apr_table_elts(r->err_headers_out); |
| 240 | hdrs = (const apr_table_entry_t *) hdrs_arr->elts; |
| 241 | |
| 242 | for (i = 0; i < hdrs_arr->nelts; ++i) { |
| 243 | if (!hdrs[i].key) |
| 244 | continue; |
| 245 | apr_file_printf(f, "%s: %s\n", hdrs[i].key, hdrs[i].val); |
| 246 | } |
no test coverage detected