]> granicus.if.org Git - curl/commitdiff
Now we're setting a default domain for received cookies so that we can
authorDaniel Stenberg <daniel@haxx.se>
Wed, 26 Sep 2001 07:08:29 +0000 (07:08 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 26 Sep 2001 07:08:29 +0000 (07:08 +0000)
properly match those cookies in subsequent requests

lib/cookie.c
lib/cookie.h
lib/transfer.c

index f859b0beed9e814df9166ad2221f08d8d0a9e661..2ae3b16243eaee5520fe6d337219eb75176e8162 100644 (file)
@@ -104,7 +104,8 @@ Example set of cookies:
 struct Cookie *
 Curl_cookie_add(struct CookieInfo *c,
                 bool httpheader, /* TRUE if HTTP header-style line */
-                char *lineptr) /* first non-space of the line */
+                char *lineptr,   /* first non-space of the line */
+                char *domain)    /* default domain */
 {
   struct Cookie *clist;
   char what[MAX_COOKIE_LINE];
@@ -194,6 +195,10 @@ Curl_cookie_add(struct CookieInfo *c,
         ptr++;
       semiptr=strchr(ptr, ';'); /* now, find the next semicolon */
     } while(semiptr);
+
+    if(NULL == co->domain)
+      /* no domain given in the header line, set the default now */
+      co->domain=strdup(domain);
   }
   else {
     /* This line is NOT a HTTP header style line, we do offer support for
@@ -441,7 +446,7 @@ struct CookieInfo *Curl_cookie_init(char *file, struct CookieInfo *inc)
       while(*lineptr && isspace((int)*lineptr))
         lineptr++;
 
-      Curl_cookie_add(c, headerline, lineptr);
+      Curl_cookie_add(c, headerline, lineptr, NULL);
     }
     if(fromfile)
       fclose(fp);
@@ -632,13 +637,13 @@ int Curl_cookie_output(struct CookieInfo *c, char *dumphere)
               "%u\t" /* expires */
               "%s\t" /* name */
               "%s\n", /* value */
-              co->domain,
+              co->domain?co->domain:"unknown",
               co->field1==2?"TRUE":"FALSE",
-              co->path,
+              co->path?co->path:"/",
               co->secure?"TRUE":"FALSE",
               (unsigned int)co->expires,
               co->name,
-              co->value);
+              co->value?co->value:"");
 
       co=co->next;
     }
index 34b6fd56a38677a8e004a31961ca97cbdeb0eab8..a00530bdad44cd0e97b715d845113b9c7cd43ebb 100644 (file)
@@ -68,7 +68,13 @@ struct CookieInfo {
 #define MAX_NAME 256
 #define MAX_NAME_TXT "255"
 
-struct Cookie *Curl_cookie_add(struct CookieInfo *, bool, char *);
+/*
+ * Add a cookie to the internal list of cookies. The domain argument is only
+ * used if the header boolean is TRUE.
+ */
+struct Cookie *Curl_cookie_add(struct CookieInfo *, bool header, char *line,
+                               char *domain);
+
 struct CookieInfo *Curl_cookie_init(char *, struct CookieInfo *);
 struct Cookie *Curl_cookie_getlist(struct CookieInfo *, char *, char *, bool);
 void Curl_cookie_freelist(struct Cookie *);
index 499454681073f4864fbd305f2dc9e8249dc54f21..c42970c5872fb7231da9749e47c8d1fde267b925 100644 (file)
@@ -620,7 +620,7 @@ Transfer(struct connectdata *c_conn)
               }
               else if(data->cookies &&
                       strnequal("Set-Cookie:", p, 11)) {
-                Curl_cookie_add(data->cookies, TRUE, &p[12]);
+                Curl_cookie_add(data->cookies, TRUE, &p[12], conn->name);
               }
               else if(strnequal("Last-Modified:", p,
                                 strlen("Last-Modified:")) &&