--------------------- PatchSet 10242 Date: 2007/12/14 07:09:37 Author: adri Branch: s27_adri Tag: (none) Log: convert the accessLog.http.content_type to be a String; saving a couple of strBuf()'s This introduces a new strBuf() into access_log.c (which takes the count from 46 to 47) but that'll be eliminated when I do a pass over the whole function and pull them all out in one swift stroke. Members: libbuf/String.h:1.1.2.14->1.1.2.15 src/access_log.c:1.43.2.1->1.43.2.1.4.1 src/client_side.c:1.202.2.9.4.12->1.202.2.9.4.13 src/structs.h:1.158.2.5.4.4->1.158.2.5.4.5 Index: squid/libbuf/String.h =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/String.h,v retrieving revision 1.1.2.14 retrieving revision 1.1.2.15 diff -u -r1.1.2.14 -r1.1.2.15 --- squid/libbuf/String.h 14 Dec 2007 06:46:33 -0000 1.1.2.14 +++ squid/libbuf/String.h 14 Dec 2007 07:09:37 -0000 1.1.2.15 @@ -109,6 +109,7 @@ extern void stringInit(String * s, const char *str); extern void stringLimitInit(String * s, const char *str, int len); + extern String stringDup(const String * s); extern void stringClean(String * s); extern void stringReset(String * s, const char *str); @@ -149,6 +150,13 @@ return 0; } +/* XXX this will eventually bypass needing to copy the backend buf_t unless its modified */ +static inline void stringInitStatic(String * s, const char *str) +{ + stringClean(s); + stringInit(s, str); +} + #endif /* __LIBBUF_STRING__H_ */ Index: squid/src/access_log.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/access_log.c,v retrieving revision 1.43.2.1 retrieving revision 1.43.2.1.4.1 diff -u -r1.43.2.1 -r1.43.2.1.4.1 --- squid/src/access_log.c 27 Nov 2007 08:12:24 -0000 1.43.2.1 +++ squid/src/access_log.c 14 Dec 2007 07:09:37 -0000 1.43.2.1.4.1 @@ -1,6 +1,6 @@ /* - * $Id: access_log.c,v 1.43.2.1 2007/11/27 08:12:24 adri Exp $ + * $Id: access_log.c,v 1.43.2.1.4.1 2007/12/14 07:09:37 adri Exp $ * * DEBUG: section 46 Access Log * AUTHOR: Duane Wessels @@ -636,7 +636,7 @@ break; case LFT_MIME_TYPE: - out = al->http.content_type; + out = strBuf(al->http.content_type); break; case LFT_REQUEST_METHOD: @@ -1055,7 +1055,7 @@ if (user && !*user) safe_free(user); if (!Config.onoff.log_mime_hdrs) { - logfilePrintf(logfile, "%9ld.%03d %6d %s %s/%03d %" PRINTF_OFF_T " %s %s %s %s%s/%s %s\n", + logfilePrintf(logfile, "%9ld.%03d %6d %s %s/%03d %" PRINTF_OFF_T " %s %s %s %s%s/%s %.*s\n", (long int) current_time.tv_sec, (int) current_time.tv_usec / 1000, al->cache.msec, @@ -1069,11 +1069,12 @@ al->hier.ping.timedout ? "TIMEOUT_" : "", hier_strings[al->hier.code], al->hier.host, - al->http.content_type); + strLen2(al->http.content_type), + strBuf2(al->http.content_type)); } else { char *ereq = log_quote(al->headers.request); char *erep = log_quote(al->headers.reply); - logfilePrintf(logfile, "%9ld.%03d %6d %s %s/%03d %" PRINTF_OFF_T " %s %s %s %s%s/%s %s [%s] [%s]\n", + logfilePrintf(logfile, "%9ld.%03d %6d %s %s/%03d %" PRINTF_OFF_T " %s %s %s %s%s/%s %.*s [%s] [%s]\n", (long int) current_time.tv_sec, (int) current_time.tv_usec / 1000, al->cache.msec, @@ -1087,7 +1088,8 @@ al->hier.ping.timedout ? "TIMEOUT_" : "", hier_strings[al->hier.code], al->hier.host, - al->http.content_type, + strLen2(al->http.content_type), + strBuf2(al->http.content_type), ereq, erep); safe_free(ereq); @@ -1140,8 +1142,9 @@ return; if (al->url == NULL) al->url = dash_str; - if (!al->http.content_type || *al->http.content_type == '\0') - al->http.content_type = dash_str; + if (strIsNull(al->http.content_type) || strLen2(al->http.content_type) == 0) { + stringInitStatic(&al->http.content_type, "-"); + } if (al->icp.opcode) al->private.method_str = icp_opcode_str[al->icp.opcode]; else Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.202.2.9.4.12 retrieving revision 1.202.2.9.4.13 diff -u -r1.202.2.9.4.12 -r1.202.2.9.4.13 --- squid/src/client_side.c 14 Dec 2007 06:11:26 -0000 1.202.2.9.4.12 +++ squid/src/client_side.c 14 Dec 2007 07:09:37 -0000 1.202.2.9.4.13 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.202.2.9.4.12 2007/12/14 06:11:26 adri Exp $ + * $Id: client_side.c,v 1.202.2.9.4.13 2007/12/14 07:09:37 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1173,10 +1173,10 @@ http->al.cache.out_ip = request->out_ip; if (http->reply && http->log_type != LOG_TCP_DENIED) { http->al.http.code = http->reply->sline.status; - http->al.http.content_type = strBuf(http->reply->content_type); + http->al.http.content_type = stringDup(&http->reply->content_type); } else if (mem) { http->al.http.code = mem->reply->sline.status; - http->al.http.content_type = strBuf(mem->reply->content_type); + http->al.http.content_type = stringDup(&mem->reply->content_type); } http->al.cache.caddr = conn->log_addr; http->al.cache.size = http->out.size; @@ -1231,6 +1231,7 @@ safe_free(http->al.headers.request); safe_free(http->al.headers.reply); safe_free(http->al.cache.authuser); + stringClean(&http->al.http.content_type); http->al.request = NULL; safe_free(http->redirect.location); stringClean(&http->range_iter.boundary); @@ -2029,7 +2030,7 @@ al.url = mem->url; debug(33, 9) ("clientAsyncDone: url='%s'\n", al.url); al.http.code = mem->reply->sline.status; - al.http.content_type = strBuf(mem->reply->content_type); + al.http.content_type = stringDup(&mem->reply->content_type); al.cache.size = async->offset; if (async->old_entry->mem_obj) async->old_entry->mem_obj->refresh_timestamp = 0; @@ -2080,6 +2081,7 @@ safe_free(al.headers.request); safe_free(al.headers.reply); safe_free(al.cache.authuser); + stringClean(&al.http.content_type); cbdataFree(async); } Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.158.2.5.4.4 retrieving revision 1.158.2.5.4.5 diff -u -r1.158.2.5.4.4 -r1.158.2.5.4.5 --- squid/src/structs.h 14 Dec 2007 06:11:30 -0000 1.158.2.5.4.4 +++ squid/src/structs.h 14 Dec 2007 07:09:38 -0000 1.158.2.5.4.5 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.158.2.5.4.4 2007/12/14 06:11:30 adri Exp $ + * $Id: structs.h,v 1.158.2.5.4.5 2007/12/14 07:09:38 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1154,7 +1154,7 @@ struct { method_t method; int code; - const char *content_type; + String content_type; http_version_t version; } http; struct {