]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Rename mime_get_header_field() as Http1Parser::getHeaderField()
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 31 Dec 2013 13:55:12 +0000 (05:55 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 31 Dec 2013 13:55:12 +0000 (05:55 -0800)
src/client_side.cc
src/http/Http1Parser.cc
src/http/Http1Parser.h
src/mime.cc
src/mime_header.cc
src/mime_header.h

index 1f67c91e5736d9a84d16c9eb3b867b81ade63c00..10fa4e961dd694a6df1562cc3bf902dcaef69ce9 100644 (file)
@@ -2080,7 +2080,7 @@ setLogUri(ClientHttpRequest * http, char const *uri, bool cleanUrl)
 }
 
 static void
-prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url, const char *req_hdr)
+prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url, const Http::Http1ParserPointer &hp)
 {
     int vhost = conn->port->vhost;
     int vport = conn->port->vport;
@@ -2121,7 +2121,7 @@ prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url,
 
     const bool switchedToHttps = conn->switchedToHttps();
     const bool tryHostHeader = vhost || switchedToHttps;
-    if (tryHostHeader && (host = mime_get_header_field(req_hdr, "Host")) != NULL) {
+    if (tryHostHeader && (host = hp->getHeaderField("Host")) != NULL) {
         debugs(33, 5, "ACCEL VHOST REWRITE: vhost=" << host << " + vport=" << vport);
         char thost[256];
         if (vport > 0) {
@@ -2170,7 +2170,7 @@ prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url,
 }
 
 static void
-prepareTransparentURL(ConnStateData * conn, ClientHttpRequest *http, char *url, const char *req_hdr)
+prepareTransparentURL(ConnStateData * conn, ClientHttpRequest *http, char *url, const Http::Http1ParserPointer &hp)
 {
     char *host;
     char ipbuf[MAX_IPSTRLEN];
@@ -2180,7 +2180,7 @@ prepareTransparentURL(ConnStateData * conn, ClientHttpRequest *http, char *url,
 
     /* BUG: Squid cannot deal with '*' URLs (RFC2616 5.1.2) */
 
-    if ((host = mime_get_header_field(req_hdr, "Host")) != NULL) {
+    if ((host = hp->getHeaderField("Host")) != NULL) {
         int url_sz = strlen(url) + 32 + Config.appendDomainLen +
                      strlen(host);
         http->uri = (char *)xcalloc(url_sz, 1);
@@ -2278,11 +2278,7 @@ parseHttpRequest(ConnStateData *csd, const Http::Http1ParserPointer &hp)
      * Process headers after request line
      * TODO: Use httpRequestParse here.
      */
-    /* XXX this code should be modified to take a const char * later! */
-    const char *req_hdr = hp->rawHeaderBuf();
-
-    debugs(33, 3, Raw("req_hdr", req_hdr, hp->headerBlockSize()));
-
+    debugs(33, 3, Raw("req_hdr", hp->rawHeaderBuf(), hp->headerBlockSize()));
     debugs(33, 3, "prefix_sz = " << hp->messageHeaderSize() <<
            ", request-line-size=" << hp->firstLineSize() <<
            ", mime-header-size=" << hp->headerBlockSize());
@@ -2336,7 +2332,7 @@ parseHttpRequest(ConnStateData *csd, const Http::Http1ParserPointer &hp)
      */
     if (csd->transparent()) {
         /* intercept or transparent mode, properly working with no failures */
-        prepareTransparentURL(csd, http, url, req_hdr);
+        prepareTransparentURL(csd, http, url, hp);
 
     } else if (internalCheck(url)) {
         /* internal URL mode */
@@ -2348,7 +2344,7 @@ parseHttpRequest(ConnStateData *csd, const Http::Http1ParserPointer &hp)
 
     } else if (csd->port->flags.accelSurrogate || csd->switchedToHttps()) {
         /* accelerator mode */
-        prepareAcceleratedURL(csd, http, url, req_hdr);
+        prepareAcceleratedURL(csd, http, url, hp);
     }
 
     if (!http->uri) {
index b7041fa0c9f3ee81b1c08d82d68ccccc92e57320..5e36d1f75297524268de25f2f2f01058c749b6ef 100644 (file)
@@ -370,3 +370,65 @@ Http::Http1Parser::parseRequest()
 
     return isDone();
 }
+
+// arbitrary maximum-length for headers which can be found by Http1Parser::getHeaderField()
+#define GET_HDR_SZ     1024
+
+char *
+Http::Http1Parser::getHeaderField(const char *name)
+{
+    LOCAL_ARRAY(char, header, GET_HDR_SZ);
+    const char *p = NULL;
+    char *q = NULL;
+    char got = 0;
+    const int namelen = name ? strlen(name) : 0;
+
+    if (!headerBlockSize() || !name)
+        return NULL;
+
+    debugs(25, 5, "looking for '" << name << "'");
+
+    for (p = rawHeaderBuf(); *p; p += strcspn(p, "\n\r")) {
+        if (strcmp(p, "\r\n\r\n") == 0 || strcmp(p, "\n\n") == 0)
+            return NULL;
+
+        while (xisspace(*p))
+            ++p;
+
+        if (strncasecmp(p, name, namelen))
+            continue;
+
+        if (!xisspace(p[namelen]) && p[namelen] != ':')
+            continue;
+
+        int l = strcspn(p, "\n\r") + 1;
+
+        if (l > GET_HDR_SZ)
+            l = GET_HDR_SZ;
+
+        xstrncpy(header, p, l);
+
+        debugs(25, 5, "checking '" << header << "'");
+
+        q = header;
+
+        q += namelen;
+
+        if (*q == ':') {
+            ++q;
+            got = 1;
+        }
+
+        while (xisspace(*q)) {
+            ++q;
+            got = 1;
+        }
+
+        if (got) {
+            debugs(25, 5, "returning '" << q << "'");
+            return q;
+        }
+    }
+
+    return NULL;
+}
index b217edfdc71215153522b0bf545eb46adf46b7ba..803b5b82e889002b7ee35df8eb3f88f04def7d68 100644 (file)
@@ -74,6 +74,11 @@ public:
      */
     bool parseRequest();
 
+    /**
+     * \return A pointer to a field-value of the first matching field-name, or NULL.
+     */
+    char *getHeaderField(const char *name);
+
 public:
     const char *buf;
     int bufsiz;
index e0c2983f544f7d8655a6de91378a5c63ea7f7b8e..d116b61a765c37ca5539b4a2b7f3b52f08573755 100644 (file)
@@ -51,8 +51,6 @@
 #include <sys/stat.h>
 #endif
 
-#define GET_HDR_SZ 1024
-
 /* forward declarations */
 static void mimeFreeMemory(void);
 static char const *mimeGetIcon(const char *fn);
index 2347481171e0133d1d37bc0f5543b224128f1c95..2a40576485e0d393d4abbc8b2d78fe1efc9da0a1 100644 (file)
  */
 
 #include "squid.h"
-
-#define GET_HDR_SZ 1024
 #include "Debug.h"
 #include "profiler/Profiler.h"
 
-/*
- * returns a pointer to a field-value of the first matching field-name where
- * field-value matches prefix if any
- */
-char *
-mime_get_header_field(const char *mime, const char *name)
-{
-    LOCAL_ARRAY(char, header, GET_HDR_SZ);
-    const char *p = NULL;
-    char *q = NULL;
-    char got = 0;
-    const int namelen = name ? strlen(name) : 0;
-    int l;
-
-    if (NULL == mime)
-        return NULL;
-
-    assert(NULL != name);
-
-    debugs(25, 5, "mime_get_header: looking for '" << name << "'");
-
-    for (p = mime; *p; p += strcspn(p, "\n\r")) {
-        if (strcmp(p, "\r\n\r\n") == 0 || strcmp(p, "\n\n") == 0)
-            return NULL;
-
-        while (xisspace(*p))
-            ++p;
-
-        if (strncasecmp(p, name, namelen))
-            continue;
-
-        if (!xisspace(p[namelen]) && p[namelen] != ':')
-            continue;
-
-        l = strcspn(p, "\n\r") + 1;
-
-        if (l > GET_HDR_SZ)
-            l = GET_HDR_SZ;
-
-        xstrncpy(header, p, l);
-
-        debugs(25, 5, "mime_get_header: checking '" << header << "'");
-
-        q = header;
-
-        q += namelen;
-
-        if (*q == ':') {
-            ++q;
-            got = 1;
-        }
-
-        while (xisspace(*q)) {
-            ++q;
-            got = 1;
-        }
-
-        if (got) {
-            debugs(25, 5, "mime_get_header: returning '" << q << "'");
-            return q;
-        }
-    }
-
-    return NULL;
-}
-
 size_t
 headersEnd(const char *mime, size_t l)
 {
index 3fd272bf18ac8be423a93829ea720bfe9b3ae705..1a9a5f6b3eb9fb5ed5639cd1002e0fa4a72e881b 100644 (file)
@@ -33,7 +33,6 @@
 #ifndef SQUID_MIME_HEADER_H_
 #define SQUID_MIME_HEADER_H_
 
-char *mime_get_header_field(const char *mime, const char *name);
 size_t headersEnd(const char *, size_t);
 
 #endif /* SQUID_MIME_HEADER_H_ */