Revision: 14437
Author: adrian.chadd
Date: Sun Feb 28 05:49:39 2010
Log: Migrate out clientPurgeRequest() into a new source file.


http://code.google.com/p/lusca-cache/source/detail?r=14437

Added:
 /branches/LUSCA_HEAD/src/client_side_purge.c
 /branches/LUSCA_HEAD/src/client_side_purge.h
Modified:
 /branches/LUSCA_HEAD/src/Makefile.am
 /branches/LUSCA_HEAD/src/client_side.c
 /branches/LUSCA_HEAD/src/client_side.h

=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/src/client_side_purge.c        Sun Feb 28 05:49:39 2010
@@ -0,0 +1,112 @@
+
+#include "squid.h"
+
+#include "client_side.h"
+#include "client_side_purge.h"
+
+
+void
+clientPurgeRequest(clientHttpRequest * http)
+{
+    StoreEntry *entry;
+    ErrorState *err = NULL;
+    HttpReply *r;
+    http_status status = HTTP_NOT_FOUND;
+    method_t *method_get = NULL, *method_head = NULL;
+ debug(33, 3) ("Config2.onoff.enable_purge = %d\n", Config2.onoff.enable_purge);
+    if (!Config2.onoff.enable_purge) {
+       http->log_type = LOG_TCP_DENIED;
+       err = errorCon(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, http->orig_request);
+ http->entry = clientCreateStoreEntry(http, http->request->method, null_request_flags);
+       errorAppendEntry(http->entry, err);
+       return;
+    }
+    /* Release both IP cache */
+    ipcacheInvalidate(http->request->host);
+
+    method_get = urlMethodGetKnownByCode(METHOD_GET);
+    method_head = urlMethodGetKnownByCode(METHOD_HEAD);
+
+    if (!http->flags.purging) {
+       /* Try to find a base entry */
+       http->flags.purging = 1;
+       entry = storeGetPublicByRequestMethod(http->request, method_get);
+       if (!entry) {
+           entry = storeGetPublicByRequestMethod(http->request, method_head);
+       }
+       if (entry) {
+           if (EBIT_TEST(entry->flags, ENTRY_SPECIAL)) {
+               http->log_type = LOG_TCP_DENIED;
+               err = errorCon(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, 
http->request);
+ http->entry = clientCreateStoreEntry(http, http->request->method, null_request_flags);
+               errorAppendEntry(http->entry, err);
+               return;
+           }
+           /* Swap in the metadata */
+           http->entry = entry;
+           storeLockObject(http->entry);
+           storeCreateMemObject(http->entry, http->uri);
+           http->entry->mem_obj->method = http->request->method;
+           http->sc = storeClientRegister(http->entry, http);
+           http->log_type = LOG_TCP_HIT;
+           storeClientCopyHeaders(http->sc, http->entry,
+               clientCacheHit,
+               http);
+           return;
+       }
+    }
+    http->log_type = LOG_TCP_MISS;
+    /* Release the cached URI */
+    entry = storeGetPublicByRequestMethod(http->request, method_get);
+    if (entry) {
+       debug(33, 4) ("clientPurgeRequest: GET '%s'\n",
+           storeUrl(entry));
+#if USE_HTCP
+ neighborsHtcpClear(entry, NULL, http->request, method_get, HTCP_CLR_PURGE);
+#endif
+       storeRelease(entry);
+       status = HTTP_OK;
+    }
+    entry = storeGetPublicByRequestMethod(http->request, method_head);
+    if (entry) {
+       debug(33, 4) ("clientPurgeRequest: HEAD '%s'\n",
+           storeUrl(entry));
+#if USE_HTCP
+ neighborsHtcpClear(entry, NULL, http->request, method_head, HTCP_CLR_PURGE);
+#endif
+       storeRelease(entry);
+       status = HTTP_OK;
+    }
+ /* And for Vary, release the base URI if none of the headers was included in the request */ + if (http->request->vary_headers && !strstr(http->request->vary_headers, "=")) {
+       entry = storeGetPublic(urlCanonical(http->request), method_get);
+       if (entry) {
+           debug(33, 4) ("clientPurgeRequest: Vary GET '%s'\n",
+               storeUrl(entry));
+#if USE_HTCP
+ neighborsHtcpClear(entry, NULL, http->request, method_get, HTCP_CLR_PURGE);
+#endif
+           storeRelease(entry);
+           status = HTTP_OK;
+       }
+       entry = storeGetPublic(urlCanonical(http->request), method_head);
+       if (entry) {
+           debug(33, 4) ("clientPurgeRequest: Vary HEAD '%s'\n",
+               storeUrl(entry));
+#if USE_HTCP
+ neighborsHtcpClear(entry, NULL, http->request, method_head, HTCP_CLR_PURGE);
+#endif
+           storeRelease(entry);
+           status = HTTP_OK;
+       }
+    }
+    /*
+     * Make a new entry to hold the reply to be written
+     * to the client.
+     */
+ http->entry = clientCreateStoreEntry(http, http->request->method, null_request_flags);
+    httpReplyReset(r = http->entry->mem_obj->reply);
+    httpReplySetHeaders(r, status, NULL, NULL, 0, -1, squid_curtime);
+    httpReplySwapOut(r, http->entry);
+    storeComplete(http->entry);
+}
=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/src/client_side_purge.h        Sun Feb 28 05:49:39 2010
@@ -0,0 +1,6 @@
+#ifndef        __CLIENT_SIDE_PURGE_H__
+#define        __CLIENT_SIDE_PURGE_H__
+
+extern void clientPurgeRequest(clientHttpRequest * http);
+
+#endif
=======================================
--- /branches/LUSCA_HEAD/src/Makefile.am        Thu Feb 18 23:57:27 2010
+++ /branches/LUSCA_HEAD/src/Makefile.am        Sun Feb 28 05:49:39 2010
@@ -117,6 +117,7 @@
        client_side_ranges.c \
        client_side_refresh.c \
        client_side_ims.c \
+       client_side_purge.c \
        client_side_async_refresh.c \
        client_side_storeurl_rewrite.c \
        client_side_location_rewrite.c \
=======================================
--- /branches/LUSCA_HEAD/src/client_side.c      Fri Feb 19 04:21:19 2010
+++ /branches/LUSCA_HEAD/src/client_side.c      Sun Feb 28 05:49:39 2010
@@ -43,6 +43,7 @@
 #include "client_side_refresh.h"
 #include "client_side_etag.h"
 #include "client_side_ims.h"
+#include "client_side_purge.h"

 #include "client_side.h"

@@ -76,7 +77,6 @@
 #endif

 static STNCB clientSendMoreData;
-static STHCB clientCacheHit;
 static void clientSetKeepaliveFlag(clientHttpRequest *);
 static int clientCachable(clientHttpRequest * http);
 static int clientHierarchical(clientHttpRequest * http);
@@ -155,112 +155,6 @@
     storeClientCopyHeaders(h->sc, e, clientSendHeaders, h);
     return e;
 }
-
-static void
-clientPurgeRequest(clientHttpRequest * http)
-{
-    StoreEntry *entry;
-    ErrorState *err = NULL;
-    HttpReply *r;
-    http_status status = HTTP_NOT_FOUND;
-    method_t *method_get = NULL, *method_head = NULL;
- debug(33, 3) ("Config2.onoff.enable_purge = %d\n", Config2.onoff.enable_purge);
-    if (!Config2.onoff.enable_purge) {
-       http->log_type = LOG_TCP_DENIED;
-       err = errorCon(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, http->orig_request);
- http->entry = clientCreateStoreEntry(http, http->request->method, null_request_flags);
-       errorAppendEntry(http->entry, err);
-       return;
-    }
-    /* Release both IP cache */
-    ipcacheInvalidate(http->request->host);
-
-    method_get = urlMethodGetKnownByCode(METHOD_GET);
-    method_head = urlMethodGetKnownByCode(METHOD_HEAD);
-
-    if (!http->flags.purging) {
-       /* Try to find a base entry */
-       http->flags.purging = 1;
-       entry = storeGetPublicByRequestMethod(http->request, method_get);
-       if (!entry) {
-           entry = storeGetPublicByRequestMethod(http->request, method_head);
-       }
-       if (entry) {
-           if (EBIT_TEST(entry->flags, ENTRY_SPECIAL)) {
-               http->log_type = LOG_TCP_DENIED;
-               err = errorCon(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, 
http->request);
- http->entry = clientCreateStoreEntry(http, http->request->method, null_request_flags);
-               errorAppendEntry(http->entry, err);
-               return;
-           }
-           /* Swap in the metadata */
-           http->entry = entry;
-           storeLockObject(http->entry);
-           storeCreateMemObject(http->entry, http->uri);
-           http->entry->mem_obj->method = http->request->method;
-           http->sc = storeClientRegister(http->entry, http);
-           http->log_type = LOG_TCP_HIT;
-           storeClientCopyHeaders(http->sc, http->entry,
-               clientCacheHit,
-               http);
-           return;
-       }
-    }
-    http->log_type = LOG_TCP_MISS;
-    /* Release the cached URI */
-    entry = storeGetPublicByRequestMethod(http->request, method_get);
-    if (entry) {
-       debug(33, 4) ("clientPurgeRequest: GET '%s'\n",
-           storeUrl(entry));
-#if USE_HTCP
- neighborsHtcpClear(entry, NULL, http->request, method_get, HTCP_CLR_PURGE);
-#endif
-       storeRelease(entry);
-       status = HTTP_OK;
-    }
-    entry = storeGetPublicByRequestMethod(http->request, method_head);
-    if (entry) {
-       debug(33, 4) ("clientPurgeRequest: HEAD '%s'\n",
-           storeUrl(entry));
-#if USE_HTCP
- neighborsHtcpClear(entry, NULL, http->request, method_head, HTCP_CLR_PURGE);
-#endif
-       storeRelease(entry);
-       status = HTTP_OK;
-    }
- /* And for Vary, release the base URI if none of the headers was included in the request */ - if (http->request->vary_headers && !strstr(http->request->vary_headers, "=")) {
-       entry = storeGetPublic(urlCanonical(http->request), method_get);
-       if (entry) {
-           debug(33, 4) ("clientPurgeRequest: Vary GET '%s'\n",
-               storeUrl(entry));
-#if USE_HTCP
- neighborsHtcpClear(entry, NULL, http->request, method_get, HTCP_CLR_PURGE);
-#endif
-           storeRelease(entry);
-           status = HTTP_OK;
-       }
-       entry = storeGetPublic(urlCanonical(http->request), method_head);
-       if (entry) {
-           debug(33, 4) ("clientPurgeRequest: Vary HEAD '%s'\n",
-               storeUrl(entry));
-#if USE_HTCP
- neighborsHtcpClear(entry, NULL, http->request, method_head, HTCP_CLR_PURGE);
-#endif
-           storeRelease(entry);
-           status = HTTP_OK;
-       }
-    }
-    /*
-     * Make a new entry to hold the reply to be written
-     * to the client.
-     */
- http->entry = clientCreateStoreEntry(http, http->request->method, null_request_flags);
-    httpReplyReset(r = http->entry->mem_obj->reply);
-    httpReplySetHeaders(r, status, NULL, NULL, 0, -1, squid_curtime);
-    httpReplySwapOut(r, http->entry);
-    storeComplete(http->entry);
-}

 int
 checkNegativeHit(StoreEntry * e)
@@ -1092,7 +986,7 @@
  * we hand off to clientSendMoreData, clientProcessExpired, or
  * clientProcessMiss.
  */
-static void
+void
 clientCacheHit(void *data, HttpReply * rep)
 {
     clientHttpRequest *http = data;
=======================================
--- /branches/LUSCA_HEAD/src/client_side.h      Thu Feb 18 23:57:27 2010
+++ /branches/LUSCA_HEAD/src/client_side.h      Sun Feb 28 05:49:39 2010
@@ -17,4 +17,10 @@
 extern STHCB clientSendHeaders;
 extern int clientOnlyIfCached(clientHttpRequest * http);

+/*
+ * XXX this is JUST for clientPurgeRequest() and JUST for now.
+ * XXX do NOT use this anywhere else!
+ */
+extern void clientCacheHit(void *data, HttpReply * rep);
+
 #endif

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to