]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Checkpoint. Broken.
authorBenno Rice <benno@squid-cache.org>
Tue, 2 Sep 2008 11:27:02 +0000 (21:27 +1000)
committerBenno Rice <benno@squid-cache.org>
Tue, 2 Sep 2008 11:27:02 +0000 (21:27 +1000)
src/Server.cc
src/protos.h
src/url.cc

index 2ec77c2efdf4af5c3d6705e45f67e087d562118c..3c5f0ba3e132a3d65fe530ba8982b6ed35a9fe64 100644 (file)
@@ -404,17 +404,17 @@ sameUrlHosts(const char *url1, const char *url2)
 static void
 purgeEntriesByHeader(const HttpRequest *req, const char *reqUrl, HttpMsg *rep, http_hdr_type hdr)
 {
-    const char *url, *absUrl;
+    const char *hdrUrl, *absUrl;
     
-    if ((url = rep->header.getStr(hdr)) != NULL) {
-           absUrl = urlAbsolute(req, url);
+    if ((hdrUrl = rep->header.getStr(hdr)) != NULL) {
+           absUrl = urlMakeAbsolute(req, hdrUrl);
            if (absUrl != NULL) {
-               url = absUrl;
+               hdrUrl = absUrl;
            }
            if (absUrl != NULL) { // if the URL was relative, it is by nature the same host
-            purgeEntriesByUrl(url);
-           } else if (sameUrlHosts(reqUrl, url)) { // prevent purging DoS, per RFC 2616 13.10, second last paragraph
-            purgeEntriesByUrl(url);
+                purgeEntriesByUrl(hdrUrl);
+           } else if (sameUrlHosts(reqUrl, hdrUrl)) { // prevent purging DoS, per RFC 2616 13.10, second last paragraph
+                purgeEntriesByUrl(hdrUrl);
         }
         if (absUrl != NULL) {
             safe_free(absUrl);
index 71f9fadee129be587420613397d34aa54776cb61..48f16947043791ab2277ee74ac2f8a413080ae3d 100644 (file)
@@ -638,7 +638,8 @@ SQUIDCEXTERN protocol_t urlParseProtocol(const char *, const char *e = NULL);
 SQUIDCEXTERN void urlInitialize(void);
 SQUIDCEXTERN HttpRequest *urlParse(const HttpRequestMethod&, char *, HttpRequest *request = NULL);
 SQUIDCEXTERN const char *urlCanonical(HttpRequest *);
-SQUIDCEXTERN const char *urlAbsolute(const HttpRequest *, const char *);
+SQUIDCEXTERN int urlIsRelative(const char *);
+SQUIDCEXTERN const char *urlMakeAbsolute(const HttpRequest *, const char *);
 SQUIDCEXTERN char *urlRInternal(const char *host, u_short port, const char *dir, const char *name);
 SQUIDCEXTERN char *urlInternal(const char *dir, const char *name);
 SQUIDCEXTERN int matchDomainName(const char *host, const char *domain);
index 9fb514047a305f97f9c6a48bc6d87a02ef654120..d6475977cae22dd3f26baa2399e909a588aa594a 100644 (file)
@@ -532,20 +532,48 @@ urlCanonicalClean(const HttpRequest * request)
     return buf;
 }
 
+/*
+ * Test if a URL is relative.
+ *
+ * RFC 1808 says that colons can show up in 'fragments' or 'queries'.
+ * Fragments come after a '#' and queries come after '?'.
+ */
+int
+urlIsRelative(const char *url)
+{
+    const char *p;
+
+    if (url == NULL) {
+        return (0);
+    }
+    if (*url == '\0') {
+        return (0);
+    }
+
+    for (p = url; *p != '\0' && *p != ':' && *p != '#' && *p != '?'; p++);
+
+    if (*p == ':') {
+        return (1);
+    }
+    return (0);
+}
+
+/*
+ * Take a potentially relative URL.  If the URL is _not_ relative, return NULL.
+ * If the URL is relative, generate an absolute URL based on the provided
+ * request.
+ */
 const char *
-urlAbsolute(const HttpRequest * req, const char *relUrl)
+urlMakeAbsolute(const HttpRequest * req, const char *relUrl)
 {
     char *urlbuf;
     const char *path, *last_slash;
     size_t urllen, pathlen;
 
-    if (relUrl == NULL) {
-        return (NULL);
-    }
     if (req->method.id() == METHOD_CONNECT) {
         return (NULL);
     }
-    if (strchr(relUrl, ':') != NULL) {
+    if (!urlIsRelative(relUrl)) {
         return (NULL);
     }
     urlbuf = (char *)xmalloc(MAX_URL * sizeof(char));