--------------------- PatchSet 10225 Date: 2007/12/12 16:18:52 Author: adri Branch: s27_adri Tag: (none) Log: implement strIs(Not)Null(String) macros; use these in place of if (strBuf(String)) checks. (count is down to 69 now.) Members: ADRIAN_TODO:1.1.2.5->1.1.2.6 libbuf/String.h:1.1.2.10->1.1.2.11 src/HttpHdrCc.c:1.7.16.2->1.7.16.3 src/client_side.c:1.202.2.9.4.7->1.202.2.9.4.8 src/client_side_rewrite.c:1.2.4.2->1.2.4.2.4.1 src/http.c:1.63.2.3.4.4->1.63.2.3.4.5 src/store.c:1.49.4.3.4.2->1.49.4.3.4.3 src/store_key_md5.c:1.10.10.1.4.1->1.10.10.1.4.2 src/store_update.c:1.2.4.3.4.1->1.2.4.3.4.2 Index: squid/ADRIAN_TODO =================================================================== RCS file: /cvsroot/squid-sf//squid/Attic/ADRIAN_TODO,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- squid/ADRIAN_TODO 12 Dec 2007 14:51:57 -0000 1.1.2.5 +++ squid/ADRIAN_TODO 12 Dec 2007 16:18:52 -0000 1.1.2.6 @@ -43,3 +43,10 @@ * modify strListAdd() to eventually take a String and not a buf+len; see what passes it stuff other than a String atm and change it. + +* A lot of if strBuf()) and if (strBuf2()) calls are made to check whether + a header exists. These should be changed to use a new call, as they're + really checking if the strnig has been initialised. Perhaps a strIsNull() + call? and a strIsNotNull() call? And then go through the codebase again + and replace the calls? + Index: squid/libbuf/String.h =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/String.h,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -r1.1.2.10 -r1.1.2.11 --- squid/libbuf/String.h 12 Dec 2007 15:29:17 -0000 1.1.2.10 +++ squid/libbuf/String.h 12 Dec 2007 16:18:52 -0000 1.1.2.11 @@ -37,6 +37,9 @@ } +#define strIsNull(s) ((s).nb == NULL) +#define strIsNotNull(s) ((s).nb != NULL) + #define strCDup(s) strCDupOffset((s), 0) /* XXX None of these functions are non-NUL safe and they need to be later replaced */ Index: squid/src/HttpHdrCc.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpHdrCc.c,v retrieving revision 1.7.16.2 retrieving revision 1.7.16.3 diff -u -r1.7.16.2 -r1.7.16.3 --- squid/src/HttpHdrCc.c 12 Dec 2007 08:59:27 -0000 1.7.16.2 +++ squid/src/HttpHdrCc.c 12 Dec 2007 16:18:52 -0000 1.7.16.3 @@ -1,6 +1,6 @@ /* - * $Id: HttpHdrCc.c,v 1.7.16.2 2007/12/12 08:59:27 adri Exp $ + * $Id: HttpHdrCc.c,v 1.7.16.3 2007/12/12 16:18:52 adri Exp $ * * DEBUG: section 65 HTTP Cache Control Header * AUTHOR: Alex Rousskov @@ -171,7 +171,7 @@ httpHdrCcDestroy(HttpHdrCc * cc) { assert(cc); - if (strBuf(cc->other)) + if (strIsNotNull(cc->other)) stringClean(&cc->other); memFree(cc, MEM_HTTP_HDR_CC); } Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.202.2.9.4.7 retrieving revision 1.202.2.9.4.8 diff -u -r1.202.2.9.4.7 -r1.202.2.9.4.8 --- squid/src/client_side.c 12 Dec 2007 14:51:58 -0000 1.202.2.9.4.7 +++ squid/src/client_side.c 12 Dec 2007 16:18:52 -0000 1.202.2.9.4.8 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.202.2.9.4.7 2007/12/12 14:51:58 adri Exp $ + * $Id: client_side.c,v 1.202.2.9.4.8 2007/12/12 16:18:52 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -3474,7 +3474,7 @@ if (r->vary_headers) http->entry->mem_obj->vary_headers = xstrdup(r->vary_headers); safe_free(http->entry->mem_obj->vary_encoding); - if (strBuf(r->vary_encoding)) + if (strIsNotNull(r->vary_encoding)) http->entry->mem_obj->vary_encoding = strCDup(r->vary_encoding); http->entry->mem_obj->request = requestLink(r); EBIT_SET(http->entry->flags, KEY_EARLY_PUBLIC); Index: squid/src/client_side_rewrite.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side_rewrite.c,v retrieving revision 1.2.4.2 retrieving revision 1.2.4.2.4.1 diff -u -r1.2.4.2 -r1.2.4.2.4.1 --- squid/src/client_side_rewrite.c 27 Nov 2007 08:12:27 -0000 1.2.4.2 +++ squid/src/client_side_rewrite.c 12 Dec 2007 16:18:52 -0000 1.2.4.2.4.1 @@ -1,6 +1,6 @@ /* - * $Id: client_side_rewrite.c,v 1.2.4.2 2007/11/27 08:12:27 adri Exp $ + * $Id: client_side_rewrite.c,v 1.2.4.2.4.1 2007/12/12 16:18:52 adri Exp $ * * DEBUG: section 33 Client-side Routines - URL Rewriter * AUTHOR: Duane Wessels; Adrian Chadd @@ -130,7 +130,7 @@ old_request->body_reader_data = NULL; } new_request->content_length = old_request->content_length; - if (strBuf(old_request->extacl_log)) + if (strIsNotNull(old_request->extacl_log)) new_request->extacl_log = stringDup(&old_request->extacl_log); if (old_request->extacl_user) new_request->extacl_user = xstrdup(old_request->extacl_user); Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.63.2.3.4.4 retrieving revision 1.63.2.3.4.5 diff -u -r1.63.2.3.4.4 -r1.63.2.3.4.5 --- squid/src/http.c 12 Dec 2007 14:51:58 -0000 1.63.2.3.4.4 +++ squid/src/http.c 12 Dec 2007 16:18:52 -0000 1.63.2.3.4.5 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.63.2.3.4.4 2007/12/12 14:51:58 adri Exp $ + * $Id: http.c,v 1.63.2.3.4.5 2007/12/12 16:18:52 adri Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -356,12 +356,12 @@ stringClean(&vstr); hdr = httpHeaderGetList(&reply->header, HDR_VARY); - if (strBuf(hdr)) + if (strIsNotNull(hdr)) strListAdd(&vary, strBuf2(hdr), strLen2(hdr), ','); stringClean(&hdr); #if X_ACCELERATOR_VARY hdr = httpHeaderGetList(&reply->header, HDR_X_ACCELERATOR_VARY); - if (strBuf(hdr)) + if (strIsNotNull(hdr)) strListAdd(&vary, strBuf2(hdr), strLen2(hdr), ','); stringClean(&hdr); #endif @@ -401,7 +401,7 @@ } safe_free(request->vary_hdr); safe_free(request->vary_headers); - if (strBuf(vary) && strBuf(vstr)) { + if (strIsNotNull(vary) && strIsNotNull(vstr)) { request->vary_hdr = strCDup(vary); request->vary_headers = strCDup(vstr); } @@ -529,7 +529,7 @@ goto no_cache; /* XXX Would be better if this was used by the swicht statement below */ } entry->mem_obj->vary_headers = xstrdup(vary); - if (strBuf(httpState->orig_request->vary_encoding)) + if (strIsNotNull(httpState->orig_request->vary_encoding)) entry->mem_obj->vary_encoding = strCDup(httpState->orig_request->vary_encoding); } if (entry->mem_obj->old_entry) @@ -656,7 +656,7 @@ stringAppend(&httpState->chunkhdr, buf, size); buf += size; len -= size; - if (strLen(httpState->chunkhdr) > 256) { + if (strLen2(httpState->chunkhdr) > 256) { debug(11, 1) ("Oversized chunk header on port %d, url %s\n", comm_local_port(fd), entry->mem_obj->url); comm_close(fd); return; @@ -1059,7 +1059,7 @@ for (i = 0; i < request->etags->count; i++) strListAddUnique(&etags, request->etags->items[i], ','); } - if (strLen(etags)) + if (strIsNotNull(etags) && strLen2(etags) > 0) httpHeaderPutString(hdr_out, HDR_IF_NONE_MATCH, etags); stringClean(&etags); /* decide if we want to do Ranges ourselves @@ -1087,11 +1087,11 @@ strConnection = httpHeaderGetList(hdr_in, HDR_CONNECTION); while ((e = httpHeaderGetEntry(hdr_in, &pos))) { - debug(11, 5) ("httpBuildRequestHeader: %s: %s\n", - strBuf(e->name), strBuf(e->value)); + debug(11, 5) ("httpBuildRequestHeader: %.*s: %.*s\n", + strLen2(e->name), strBuf2(e->name), strLen2(e->value), strBuf2(e->value)); if (!httpRequestHdrAllowed(e, &strConnection)) { - debug(11, 2) ("'%s' header is a hop-by-hop connections header\n", - strBuf(e->name)); + debug(11, 2) ("'%.*s' header is a hop-by-hop connections header\n", + strLen2(e->name), strBuf2(e->name)); continue; } switch (e->id) { @@ -1326,7 +1326,7 @@ if (!EBIT_TEST(cc->mask, CC_MAX_AGE)) { const char *url = entry ? storeUrl(entry) : urlCanonical(orig_request); httpHdrCcSetMaxAge(cc, getMaxAge(url)); - if (strLen(request->urlpath)) + if (strIsNotNull(request->urlpath) && strLen2(request->urlpath) > 0) assert(strstr(url, strBuf(request->urlpath))); } /* Set no-cache if determined needed but not found */ Index: squid/src/store.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store.c,v retrieving revision 1.49.4.3.4.2 retrieving revision 1.49.4.3.4.3 diff -u -r1.49.4.3.4.2 -r1.49.4.3.4.3 --- squid/src/store.c 12 Dec 2007 14:51:59 -0000 1.49.4.3.4.2 +++ squid/src/store.c 12 Dec 2007 16:18:54 -0000 1.49.4.3.4.3 @@ -1,6 +1,6 @@ /* - * $Id: store.c,v 1.49.4.3.4.2 2007/12/12 14:51:59 adri Exp $ + * $Id: store.c,v 1.49.4.3.4.3 2007/12/12 16:18:54 adri Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -973,7 +973,7 @@ VaryData_pool = memPoolCreate("VaryData", sizeof(VaryData)); state = cbdataAlloc(LocateVaryState); state->vary_data = xstrdup(vary_data); - if (strBuf(accept_encoding)) + if (strIsNotNull(accept_encoding)) state->accept_encoding = strCDup(accept_encoding); state->data = memPoolAlloc(VaryData_pool); state->e = e; @@ -1060,13 +1060,13 @@ String vary = StringNull; String varyhdr; varyhdr = httpHeaderGetList(&mem->reply->header, HDR_VARY); - if (strBuf(varyhdr)) + if (strIsNotNull(varyhdr)) strListAdd(&vary, strBuf2(varyhdr), strLen2(varyhdr), ','); stringClean(&varyhdr); #if X_ACCELERATOR_VARY /* This needs to match the order in http.c:httpMakeVaryMark */ varyhdr = httpHeaderGetList(&mem->reply->header, HDR_X_ACCELERATOR_VARY); - if (strBuf(varyhdr)) + if (strIsNotNull(varyhdr)) strListAdd(&vary, strBuf2(varyhdr), strLen2(varyhdr), ','); stringClean(&varyhdr); #endif Index: squid/src/store_key_md5.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store_key_md5.c,v retrieving revision 1.10.10.1.4.1 retrieving revision 1.10.10.1.4.2 diff -u -r1.10.10.1.4.1 -r1.10.10.1.4.2 --- squid/src/store_key_md5.c 12 Dec 2007 10:02:26 -0000 1.10.10.1.4.1 +++ squid/src/store_key_md5.c 12 Dec 2007 16:18:54 -0000 1.10.10.1.4.2 @@ -1,6 +1,6 @@ /* - * $Id: store_key_md5.c,v 1.10.10.1.4.1 2007/12/12 10:02:26 adri Exp $ + * $Id: store_key_md5.c,v 1.10.10.1.4.2 2007/12/12 16:18:54 adri Exp $ * * DEBUG: section 20 Storage Manager MD5 Cache Keys * AUTHOR: Duane Wessels @@ -146,7 +146,7 @@ if (request->vary_headers) { MD5Update(&M, (unsigned char *) "\0V", 2); MD5Update(&M, (unsigned char *) request->vary_headers, strlen(request->vary_headers)); - if (strBuf2(request->vary_encoding)) { + if (strIsNotNull(request->vary_encoding)) { MD5Update(&M, (unsigned char *) "\0E", 2); MD5Update(&M, (unsigned char *) strBuf2(request->vary_encoding), strLen2(request->vary_encoding)); } Index: squid/src/store_update.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store_update.c,v retrieving revision 1.2.4.3.4.1 retrieving revision 1.2.4.3.4.2 diff -u -r1.2.4.3.4.1 -r1.2.4.3.4.2 --- squid/src/store_update.c 10 Dec 2007 08:56:54 -0000 1.2.4.3.4.1 +++ squid/src/store_update.c 12 Dec 2007 16:18:54 -0000 1.2.4.3.4.2 @@ -1,6 +1,6 @@ /* - * $Id: store_update.c,v 1.2.4.3.4.1 2007/12/10 08:56:54 adri Exp $ + * $Id: store_update.c,v 1.2.4.3.4.2 2007/12/12 16:18:54 adri Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Henrik Nordstrom @@ -168,7 +168,7 @@ vary = httpMakeVaryMark(request, state->newentry->mem_obj->reply); if (vary) { state->newentry->mem_obj->vary_headers = xstrdup(vary); - if (strBuf(request->vary_encoding)) + if (strIsNotNull(request->vary_encoding)) entry->mem_obj->vary_encoding = strCDup(request->vary_encoding); } } else {