]> sjero.net Git - wget/commitdiff
[svn] Consistently prepend / to path when entering cookie code.
authorhniksic <devnull@localhost>
Fri, 24 Jun 2005 12:15:03 +0000 (05:15 -0700)
committerhniksic <devnull@localhost>
Fri, 24 Jun 2005 12:15:03 +0000 (05:15 -0700)
src/ChangeLog
src/cookies.c
src/http.c

index 47264cfb8db13f9307b42ec466d6ea211f0a8639..ba28dea380267d460d51a622b7a1dbb685f974d7 100644 (file)
@@ -1,3 +1,10 @@
+2005-06-24  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * http.c (gethttp): Don't prepend / here.
+
+       * cookies.c (cookie_handle_set_cookie): Prepend / to PATH.
+       (cookie_header): Ditto.
+
 2005-06-24  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * init.c: opt.verbose must be declared as int.
index 95a46c14525d660ce0fcf62cbf63de0cad1263fc..ffc0cc158f27bf51199d71e12979b8e6891ffcc8 100644 (file)
@@ -822,6 +822,17 @@ check_path_match (const char *cookie_path, const char *path)
 {
   return path_matches (path, cookie_path) != 0;
 }
+
+/* Prepend '/' to string S.  S is copied to fresh stack-allocated
+   space and its value is modified to point to the new location.  */
+
+#define PREPEND_SLASH(s) do {                                  \
+  char *PS_newstr = (char *) alloca (1 + strlen (s) + 1);      \
+  *PS_newstr = '/';                                            \
+  strcpy (PS_newstr + 1, s);                                   \
+  s = PS_newstr;                                               \
+} while (0)
+
 \f
 /* Process the HTTP `Set-Cookie' header.  This results in storing the
    cookie or discarding a matching one, or ignoring it completely, all
@@ -835,6 +846,11 @@ cookie_handle_set_cookie (struct cookie_jar *jar,
   struct cookie *cookie;
   cookies_now = time (NULL);
 
+  /* Wget's paths don't begin with '/' (blame rfc1808), but cookie
+     usage assumes /-prefixed paths.  Until the rest of Wget is fixed,
+     simply prepend slash to PATH.  */
+  PREPEND_SLASH (path);
+
   cookie = parse_set_cookies (set_cookie, update_cookie_field, false);
   if (!cookie)
     goto out;
@@ -977,16 +993,7 @@ find_chains_of_host (struct cookie_jar *jar, const char *host,
 static int
 path_matches (const char *full_path, const char *prefix)
 {
-  int len;
-
-  if (*prefix != '/')
-    /* Wget's HTTP paths do not begin with '/' (the URL code treats it
-       as a mere separator, inspired by rfc1808), but the '/' is
-       assumed when matching against the cookie stuff.  */
-    return 0;
-
-  ++prefix;
-  len = strlen (prefix);
+  int len = strlen (prefix);
 
   if (0 != strncmp (full_path, prefix, len))
     /* FULL_PATH doesn't begin with PREFIX. */
@@ -1149,6 +1156,7 @@ cookie_header (struct cookie_jar *jar, const char *host,
   int count, i, ocnt;
   char *result;
   int result_size, pos;
+  PREPEND_SLASH (path);                /* see cookie_handle_set_cookie */
 
   /* First, find the cookie chains whose domains match HOST. */
 
index 5eb256ba06ac7500069814b53b7b727442739a13..30a1ca24ebe29e1407d3e7f523ec99c292f5a140 100644 (file)
@@ -1706,7 +1706,6 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
   /* Handle (possibly multiple instances of) the Set-Cookie header. */
   if (opt.cookies)
     {
-      char *pth = NULL;
       int scpos;
       const char *scbeg, *scend;
       /* The jar should have been created by now. */
@@ -1717,15 +1716,8 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
           ++scpos)
        {
          char *set_cookie; BOUNDED_TO_ALLOCA (scbeg, scend, set_cookie);
-         if (pth == NULL)
-           {
-             /* u->path doesn't begin with /, which cookies.c expects. */
-             pth = (char *) alloca (1 + strlen (u->path) + 1);
-             pth[0] = '/';
-             strcpy (pth + 1, u->path);
-           }
-         cookie_handle_set_cookie (wget_cookie_jar, u->host, u->port, pth,
-                                   set_cookie);
+         cookie_handle_set_cookie (wget_cookie_jar, u->host, u->port,
+                                   u->path, set_cookie);
        }
     }