]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
reworking squid-internal namespace and functions
authorwessels <>
Tue, 5 May 1998 09:49:56 +0000 (09:49 +0000)
committerwessels <>
Tue, 5 May 1998 09:49:56 +0000 (09:49 +0000)
src/Makefile.in
src/client_side.cc
src/enums.h
src/internal.cc [new file with mode: 0644]
src/mime.cc
src/protos.h
src/store_digest.cc
src/url.cc

index 10a9549544c33d9586f7d8622c3edb2a7e40c2b9..1df50087445cfb1d5597c50abefd0934c3be4d0a 100644 (file)
@@ -1,7 +1,7 @@
 #
 #  Makefile for the Squid Object Cache server
 #
-#  $Id: Makefile.in,v 1.147 1998/04/23 22:30:19 wessels Exp $
+#  $Id: Makefile.in,v 1.148 1998/05/05 03:49:56 wessels Exp $
 #
 #  Uncomment and customize the following to suit your needs:
 #
@@ -115,6 +115,7 @@ OBJS                = \
                icp_v2.o \
                icp_v3.o \
                ident.o \
+               internal.o \
                ipc.o \
                ipcache.o \
                main.o \
index 3c9aced1731088fad2bd1bc352a4fb8823d0f678..b3c1abf144e901e319e229cacd4836c208b8f533 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.cc,v 1.297 1998/05/02 06:41:09 wessels Exp $
+ * $Id: client_side.cc,v 1.298 1998/05/05 03:49:57 wessels Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -221,7 +221,7 @@ clientRedirectDone(void *data, char *result)
        /* need to malloc because the URL returned by the redirector might
         * not be big enough to append the local domain
         * -- David Lamkin drl@net-tel.co.uk */
-       l = strlen(result) + Config.appendDomainLen + 5;
+       l = strlen(result) + Config.appendDomainLen + 64;
        http->uri = xcalloc(l, 1);
        xstrncpy(http->uri, result, l);
        new_request->http_ver = old_request->http_ver;
@@ -1644,9 +1644,7 @@ clientProcessMiss(clientHttpRequest * http)
     ch.src_addr = http->conn->peer.sin_addr;
     ch.request = r;
     answer = aclCheckFast(Config.accessList.miss, &ch);
-    if (answer == 0 || http->flags.internal) {
-       debug(33,1)("clientProcessMiss: Can't forward internal request '%s'\n",
-               r->urlpath);
+    if (answer == 0) {
        http->al.http.code = HTTP_FORBIDDEN;
        err = errorCon(ERR_FORWARDING_DENIED, HTTP_FORBIDDEN);
        err->request = requestLink(r);
@@ -1659,6 +1657,8 @@ clientProcessMiss(clientHttpRequest * http)
     http->entry = clientCreateStoreEntry(http, r->method, r->flags);
     http->entry->mem_obj->fd = http->conn->fd;
     http->entry->refcount++;
+    if (http->flags.internal)
+       r->protocol = PROTO_INTERNAL;
     protoDispatch(http->conn->fd, http->entry, r);
 }
 
@@ -1822,9 +1822,9 @@ parseHttpRequest(ConnStateData * conn, method_t * method_p, int *status,
        *t = '\0';
 
     /* handle internal objects */
-    if (0 == strncmp(url, "/squid-internal/", 16)) {
+    if (internalCheck(url)) {
        /* prepend our name & port */
-       http->uri = xstrdup(urlInternal(NULL, url + 16));
+       http->uri = xstrdup(internalLocalUri(NULL, url));
        http->flags.internal = 1;
     }
     /* see if we running in Config2.Accel.on, if so got to convert it to URL */
index 22646b6e0f57193d04ada01dbf618b6e208a8e1e..e6c42739f8c70f2f2fac69ebe6b13f6cb58a59fa 100644 (file)
@@ -353,6 +353,7 @@ typedef enum {
     PROTO_ICP,
     PROTO_URN,
     PROTO_WHOIS,
+    PROTO_INTERNAL,
     PROTO_MAX
 } protocol_t;
 
diff --git a/src/internal.cc b/src/internal.cc
new file mode 100644 (file)
index 0000000..435e2f2
--- /dev/null
@@ -0,0 +1,50 @@
+
+#include "squid.h"
+
+void
+internalStart(request_t * request, StoreEntry * entry)
+{
+    const char *upath = strBuf(request->urlpath);
+    debug(0, 1) ("internalStart: %s requesting '%s'\n",
+        inet_ntoa(request->client_addr), upath);
+    if (0 == strcmp(upath, "/squid-internal-dynamic/netdb"))
+       netdbBinaryExchange(entry);
+    else
+       debug(0,0)("internalStart: unknown request '%s'\n", upath);
+}
+
+int
+internalCheck(const char *urlpath)
+{
+       return (0 == strncmp(urlpath, "/squid-internal-", 16));
+}
+
+/*
+ * makes internal url with a given host and port (remote internal url)
+ */
+char *
+internalRemoteUri(const char *host, u_short port, const char *dir, const char *name)
+{
+    LOCAL_ARRAY(char, buf, MAX_URL);
+    int k = 0;
+    static char lc_host[SQUIDHOSTNAMELEN];
+    assert(host && port && name);
+    xstrncpy(lc_host, host, SQUIDHOSTNAMELEN);
+    Tolower(lc_host);
+    k += snprintf(buf + k, MAX_URL - k, "http://%s", lc_host);
+    if (port != urlDefaultPort(PROTO_HTTP))
+       k += snprintf(buf + k, MAX_URL - k, ":%d", port);
+    if (dir)
+       k += snprintf(buf + k, MAX_URL - k, "%s", dir);
+    k += snprintf(buf + k, MAX_URL - k, "%s", name);
+    return buf;
+}
+
+/*
+ * makes internal url with local host and port
+ */
+char *
+internalLocalUri(const char *dir, const char *name)
+{
+    return internalRemoteUri(getMyHostname(), Config.Port.http->i, dir, name);
+}
index d996a537c2a5df1d701e6674e41a65096128a806..871e96039e38253568d90207e44bcb9672a647e7 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: mime.cc,v 1.63 1998/04/24 07:09:38 wessels Exp $
+ * $Id: mime.cc,v 1.64 1998/05/05 03:49:59 wessels Exp $
  *
  * DEBUG: section 25    MIME Parsing
  * AUTHOR: Harvest Derived
@@ -334,7 +334,7 @@ mimeGetIconURL(const char *fn)
     char *icon = mimeGetIcon(fn);
     if (icon == NULL)
        return NULL;
-    return urlInternal("icons", icon);
+    return internalLocalUri("/squid-internal-static/icons/", icon);
 }
 
 char *
@@ -487,7 +487,8 @@ mimeLoadIconFile(const char *icon)
     const char *type = mimeGetContentType(icon);
     if (type == NULL)
        fatal("Unknown icon format while reading mime.conf\n");
-    xstrncpy(url, urlInternal("icons", icon), MAX_URL);
+    buf = internalLocalUri("/squid-internal-static/icons/", icon);
+    xstrncpy(url, buf, MAX_URL);
     key = storeKeyPublic(url, METHOD_GET);
     if (storeGet(key))
        return;
index 3312f3caf228a1c29525961d1b00aca49287c395..0046ed167d963c67b3dbd0142775627892644cfc 100644 (file)
@@ -511,6 +511,7 @@ extern int netdbHostPeerRtt(const char *host, peer * peer);
 extern void netdbUpdatePeer(request_t *, peer * e, int rtt, int hops);
 extern void netdbDeleteAddrNetwork(struct in_addr addr);
 extern int netdbHostPeerRtt(const char *host, peer * peer);
+extern void netdbBinaryExchange(StoreEntry *);
 
 extern void cachemgrStart(int fd, request_t * request, StoreEntry * entry);
 extern void cachemgrRegister(const char *, const char *, OBJH *, int);
@@ -838,8 +839,6 @@ extern method_t urlParseMethod(const char *);
 extern void urlInitialize(void);
 extern request_t *urlParse(method_t, char *);
 extern char *urlCanonical(const request_t *, char *);
-extern char *urlRInternal(const char *host, u_short port, const char *dir, const char *name);
-extern char *urlInternal(const char *dir, const char *name);
 extern request_t *requestLink(request_t *);
 extern void requestUnlink(request_t *);
 extern int matchDomainName(const char *d, const char *h);
@@ -927,6 +926,11 @@ extern void cacheDigestGuessStatsUpdate(cd_guess_stats * stats, int real_hit, in
 extern void cacheDigestGuessStatsReport(const cd_guess_stats * stats, StoreEntry * sentry, const char *label);
 extern void cacheDigestReport(CacheDigest * cd, const char *label, StoreEntry * e);
 
+extern void internalStart(request_t *, StoreEntry *);
+extern int internalCheck(const char *urlpath);
+extern char *internalLocalUri(const char *dir, const char *name);
+extern char *internalRemoteUri(const char *, u_short, const char *, const char *);
+
 /*
  * prototypes for system functions missing from system includes
  */
index e42bbc63dc09d7fe394d3e4fab87f1e5a2316a1d..fe57c92170c29365bc732b46e7ec3b101b8a5f3d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: store_digest.cc,v 1.11 1998/04/24 07:09:47 wessels Exp $
+ * $Id: store_digest.cc,v 1.12 1998/05/05 03:50:01 wessels Exp $
  *
  * DEBUG: section 71    Store Digest Manager
  * AUTHOR: Alex Rousskov
@@ -258,7 +258,7 @@ storeDigestRewriteStart(void *datanotused)
     }
     debug(71, 2) ("storeDigestRewrite: start rewrite #%d\n", sd_state.rewrite_count + 1);
     /* make new store entry */
-    url = urlInternal("", StoreDigestUrlPath);
+    url = internalLocalUri(NULL, StoreDigestUrlPath);
     flags = 0;
     EBIT_SET(flags, REQ_CACHABLE);
     sd_state.rewrite_lock = e = storeCreateEntry(url, url, flags, METHOD_GET);
index b816477516fd4badda968e26dcd1570a0b8ac144..5e63db9a9e35ac4528eb5bbab31213c9507f8fac 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: url.cc,v 1.88 1998/04/24 04:52:40 wessels Exp $
+ * $Id: url.cc,v 1.89 1998/05/05 03:50:02 wessels Exp $
  *
  * DEBUG: section 23    URL Parsing
  * AUTHOR: Duane Wessels
@@ -54,6 +54,7 @@ const char *ProtocolStr[] =
     "icp",
     "urn",
     "whois",
+    "internal",
     "TOTAL"
 };
 
@@ -175,6 +176,8 @@ urlParseProtocol(const char *s)
        return PROTO_URN;
     if (strncasecmp(s, "whois", 5) == 0)
        return PROTO_WHOIS;
+    if (strncasecmp(s, "internal", 8) == 0)
+       return PROTO_INTERNAL;
     return PROTO_NONE;
 }
 
@@ -192,6 +195,7 @@ urlDefaultPort(protocol_t p)
     case PROTO_WAIS:
        return 210;
     case PROTO_CACHEOBJ:
+    case PROTO_INTERNAL:
        return CACHE_HTTP_PORT;
     case PROTO_WHOIS:
        return 43;
@@ -369,33 +373,6 @@ urlCanonicalClean(const request_t * request)
     return buf;
 }
 
-/* makes internal url with a given host and port (remote internal url) */
-char *
-urlRInternal(const char *host, u_short port, const char *dir, const char *name)
-{
-    LOCAL_ARRAY(char, buf, MAX_URL);
-    int k = 0;
-    static char lc_host[SQUIDHOSTNAMELEN];
-    assert(host && port && name);
-    xstrncpy(lc_host, host, SQUIDHOSTNAMELEN);
-    Tolower(lc_host);
-    k += snprintf(buf + k, MAX_URL - k, "http://%s", lc_host);
-    if (port != urlDefaultPort(PROTO_HTTP))
-       k += snprintf(buf + k, MAX_URL - k, ":%d", port);
-    k += snprintf(buf + k, MAX_URL - k, "/%s", "squid-internal");
-    if (NULL != dir && '\0' != *dir)
-       k += snprintf(buf + k, MAX_URL - k, "/%s", dir);
-    k += snprintf(buf + k, MAX_URL - k, "/%s", name);
-    return buf;
-}
-
-/* makes internal url with local host and port */
-char *
-urlInternal(const char *dir, const char *name)
-{
-    return urlRInternal(getMyHostname(), Config.Port.http->i, dir, name);
-}
-
 request_t *
 requestLink(request_t * request)
 {