--------------------- PatchSet 10182 Date: 2007/11/30 15:55:21 Author: adri Branch: store_copy Tag: (none) Log: Second half of the vary changes to use storeClientRef(). Members: src/http.c:1.63.2.1->1.63.2.2 src/peer_sourcehash.c:1.3->1.3.48.1 src/store.c:1.49.4.2->1.49.4.3 src/tools.c:1.62->1.62.2.1 Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.63.2.1 retrieving revision 1.63.2.2 diff -u -r1.63.2.1 -r1.63.2.2 --- squid/src/http.c 27 Nov 2007 08:12:28 -0000 1.63.2.1 +++ squid/src/http.c 30 Nov 2007 15:55:21 -0000 1.63.2.2 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.63.2.1 2007/11/27 08:12:28 adri Exp $ + * $Id: http.c,v 1.63.2.2 2007/11/30 15:55:21 adri Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -1220,7 +1220,7 @@ strFwd = httpHeaderGetList(hdr_in, HDR_X_FORWARDED_FOR); strListAdd(&strFwd, (((orig_request->client_addr.s_addr != no_addr.s_addr) && opt_forwarded_for) ? - inet_ntoa(orig_request->client_addr) : "unknown"), ','); + xinet_ntoa(orig_request->client_addr) : "unknown"), ','); httpHeaderPutStr(hdr_out, HDR_X_FORWARDED_FOR, strBuf(strFwd)); stringClean(&strFwd); } Index: squid/src/peer_sourcehash.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/peer_sourcehash.c,v retrieving revision 1.3 retrieving revision 1.3.48.1 diff -u -r1.3 -r1.3.48.1 --- squid/src/peer_sourcehash.c 16 May 2006 05:29:59 -0000 1.3 +++ squid/src/peer_sourcehash.c 30 Nov 2007 15:55:21 -0000 1.3.48.1 @@ -1,6 +1,6 @@ /* - * $Id: peer_sourcehash.c,v 1.3 2006/05/16 05:29:59 squidadm Exp $ + * $Id: peer_sourcehash.c,v 1.3.48.1 2007/11/30 15:55:21 adri Exp $ * * DEBUG: section 44 Peer user hash based selection * AUTHOR: Henrik Nordstrom @@ -134,9 +134,9 @@ unsigned int combined_hash; double score; double high_score = 0; - char *key = NULL; + const char *key = NULL; - key = inet_ntoa(request->client_addr); + key = xinet_ntoa(request->client_addr); /* calculate hash key */ debug(39, 2) ("peerSourceHashSelectParent: Calculating hash for %s\n", key); Index: squid/src/store.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store.c,v retrieving revision 1.49.4.2 retrieving revision 1.49.4.3 diff -u -r1.49.4.2 -r1.49.4.3 --- squid/src/store.c 30 Nov 2007 15:25:51 -0000 1.49.4.2 +++ squid/src/store.c 30 Nov 2007 15:55:21 -0000 1.49.4.3 @@ -1,6 +1,6 @@ /* - * $Id: store.c,v 1.49.4.2 2007/11/30 15:25:51 adri Exp $ + * $Id: store.c,v 1.49.4.3 2007/11/30 15:55:21 adri Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -554,22 +554,31 @@ } static void -storeAddVaryReadOld(void *data, char *buf, ssize_t size) +storeAddVaryReadOld(void *data, mem_node_ref nr, ssize_t size) { AddVaryState *state = data; size_t l = size + state->buf_offset; char *e; char *p = state->buf; + const char *buf = nr.node->data + nr.offset; + debug(11, 3) ("storeAddVaryReadOld: %p seen_offset=%" PRINTF_OFF_T " buf_offset=%d size=%d\n", data, state->seen_offset, (int) state->buf_offset, (int) size); if (size <= 0) { debug(11, 2) ("storeAddVaryReadOld: DONE\n"); cbdataFree(state); - return; + goto finish; } + + assert(size <= nr.node->len); + /* size should never exceed what we asked for; just make sure first */ + assert(size + state->buf_offset <= state->buf_size); + /* Copy in the data before we do anything else */ + memcpy(state->buf + state->buf_offset, nr.node->data + nr.offset, size); + if (EBIT_TEST(state->e->flags, ENTRY_ABORTED)) { debug(11, 1) ("storeAddVaryReadOld: New index aborted at %d (%d)\n", (int) state->seen_offset, (int) size); cbdataFree(state); - return; + goto finish; } storeBuffer(state->e); if (state->seen_offset != 0) { @@ -584,7 +593,7 @@ invalid_marker_obj: debug(11, 2) ("storeAddVaryReadOld: %p (%s) is not a Vary maker object, ignoring\n", data, storeUrl(state->oe)); cbdataFree(state); - return; + goto finish; } hdr_sz = state->oe->mem_obj->reply->hdr_sz; state->seen_offset = hdr_sz; @@ -690,18 +699,19 @@ /* This does not look good. Bail out. This should match the size <= 0 case above */ debug(11, 1) ("storeAddVaryReadOld: Buffer very large and still can't fit the data.. bailing out\n"); cbdataFree(state); - return; + goto finish; } } debug(11, 3) ("storeAddVaryReadOld: %p seen_offset=%" PRINTF_OFF_T " buf_offset=%d\n", data, state->seen_offset, (int) state->buf_offset); storeBufferFlush(state->e); - storeClientCopy(state->sc, state->oe, + storeClientRef(state->sc, state->oe, state->seen_offset, state->seen_offset, state->buf_size - state->buf_offset, - state->buf + state->buf_offset, storeAddVaryReadOld, state); +finish: + stmemNodeUnref(&nr); buf = NULL; } /* @@ -759,9 +769,8 @@ state->sc = storeClientRegister(state->oe, state); state->buf = memAllocBuf(4096, &state->buf_size); debug(11, 3) ("storeAddVary: %p\n", state); - storeClientCopy(state->sc, state->oe, 0, 0, + storeClientRef(state->sc, state->oe, 0, 0, state->buf_size, - state->buf, storeAddVaryReadOld, state); return; Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.62 retrieving revision 1.62.2.1 diff -u -r1.62 -r1.62.2.1 --- squid/src/tools.c 23 Sep 2007 14:51:45 -0000 1.62 +++ squid/src/tools.c 30 Nov 2007 15:55:21 -0000 1.62.2.1 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.62 2007/09/23 14:51:45 squidadm Exp $ + * $Id: tools.c,v 1.62.2.1 2007/11/30 15:55:21 adri Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -1403,7 +1403,41 @@ const char * xinet_ntoa(const struct in_addr addr) { - return inet_ntoa(addr); + static char buf[32]; + char *s = buf + 30; + unsigned char a; + unsigned int ad = ntohl(addr.s_addr); + s[31] = '\0'; + + a = (ad) & 0xff; + do { + *(s--) = (a % 10) + '0'; + a /= 10; + } while (a > 0); + *(s--) = '.'; + + a = (ad >> 8) & 0xff; + do { + *(s--) = (a % 10) + '0'; + a /= 10; + } while (a > 0); + *(s--) = '.'; + + a = (ad >> 16) & 0xff; + do { + *(s--) = (a % 10) + '0'; + a /= 10; + } while (a > 0); + *(s--) = '.'; + + a = (ad >> 24) & 0xff; + do { + *(s--) = (a % 10) + '0'; + a /= 10; + } while (a > 0); + + return s + 1; + } /**