The same patch reworked for Apache 2.0.
Justin, I had a look through filter examples but didn't feel confident
to undertake writing one. Maybe in the next version of the patch...
Bojan
--- mod_log_config.c.original Tue Aug 20 15:12:32 2002
+++ mod_log_config.c Tue Aug 20 15:39:09 2002
@@ -153,9 +153,11 @@
* 'X' = connection aborted before the response completed.
* '+' = connection may be kept alive after the response is sent.
* '-' = connection will be closed after the response is sent.
- (This directive was %...c in late versions of Apache 1.3, but
- this conflicted with the historical ssl %...{var}c syntax.)
-*
+ * (This directive was %...c in late versions of Apache 1.3, but
+ * this conflicted with the historical ssl %...{var}c syntax.)
+ * %...I: bytes received, including request and headers, cannot be zero
+ * %...O: bytes sent, including headers, cannot be zero
+ *
* The '...' can be nothing at all (e.g. "%h %u %r %s %b"), or it can
* indicate conditions for inclusion of the item (which will cause it
* to be replaced with '-' if the condition is not met). Note that
@@ -594,6 +596,67 @@
return "-";
}
+/*
+ * Header length function to work with apr_table_do()
+ *
+ * This and log_bytes_recv_all() and log_bytes_sent_all() is reworked from
+ * Simone Tellini's mod_accounting: http://sourceforge.net/projects/mod-acct/
+ *
+ */
+static int get_header_len(void *count, const char *key, const char *val) {
+
+ /* Header name, colon, space, header value, CRLF */
+ *((long *)count) += strlen(key) + strlen(val) + 4;
+
+ return 1;
+}
+
+static const char *log_bytes_recv_all(request_rec *r, char *a)
+{
+ /* Request length, CRLF and another CRLF after headers */
+ long recv = strlen(r->the_request) + 4; /* Never zero */
+ const char *clen = apr_table_get(r->headers_in, "Content-Length" );
+
+ /* Add length of headers */
+ apr_table_do(get_header_len, &recv, r->headers_in, NULL);
+
+ if (clen) /* We checked the value makes sense in http_protocol.c */
+ recv += atol(clen);
+
+ return apr_psprintf(r->pool, "%ld", recv);
+}
+
+static const char *log_bytes_sent_all(request_rec *r, char *a)
+{
+ long sent;
+ char *date = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
+
+ ap_recent_rfc822_date(date, r->request_time);
+
+ /* Headers that don't make it into headers tables
+ * "HTTP/x.x " + CRLF = 11 bytes
+ * "Server: " + CRLF = 10 bytes
+ * "Date: " + CRLF = 8 bytes
+ * CRLF after headers = 2 bytes --> Total = 31 bytes */
+ sent = strlen(r->status_line) + strlen(ap_get_server_version()) +
+ strlen(date) + 31;
+
+ /* Add regular and error headers */
+ apr_table_do(get_header_len, &sent, r->headers_out, NULL);
+ apr_table_do(get_header_len, &sent, r->err_headers_out, NULL);
+
+ /* Is the browser bug being avoided?
+ * If so, header "X-Pad: avoid browser bug" will be added and a CRLF
+ * 26 bytes in total */
+ if (sent >= 255 && sent <= 257)
+ sent += 26;
+
+ if (!r->header_only)
+ sent += r->bytes_sent;
+
+ return apr_psprintf(r->pool, "%ld", sent);
+}
+
/*****************************************************************
*
* Parsing the log format string
@@ -1272,6 +1335,8 @@
log_pfn_register(p, "T", log_request_duration, 1);
log_pfn_register(p, "U", log_request_uri, 1);
log_pfn_register(p, "s", log_status, 1);
+ log_pfn_register(p, "I", log_bytes_recv_all, 0);
+ log_pfn_register(p, "O", log_bytes_sent_all, 0);
}
return OK;
--- mod_log_config.html.en.original Tue Aug 20 15:21:05 2002
+++ mod_log_config.html.en Tue Aug 20 15:22:24 2002
@@ -135,6 +135,12 @@
this conflicted with the historical ssl %...{var}c
syntax.)</td></tr></table></blockquote>
</td></tr>
+<tr><td>%...I:</td>
+<td>Bytes received, including request and headers, cannot be zero.</td></tr>
+
+<tr><td>%...O:</td>
+<td>Bytes sent, including headers, cannot be zero.</td></tr>
+
</table>
<p>The "..." can be nothing at all (<em>e.g.</em>, <code>"%h %u
@@ -346,4 +352,4 @@
TransferLog logs/access_log
</code></td></tr></table></blockquote>
-<hr></blockquote><h3 align="center">Apache HTTP Server Version 2.0</h3><a
href="./"><img src="../images/index.gif" alt="Index"></a><a href="../"><img
src="../images/home.gif" alt="Home"></a></body></html>
\ No newline at end of file
+<hr></blockquote><h3 align="center">Apache HTTP Server Version 2.0</h3><a
+href="./"><img src="../images/index.gif" alt="Index"></a><a href="../"><img
+src="../images/home.gif" alt="Home"></a></body></html>