curl-library
Re: Simple cookie interface!
Date: Thu, 28 Jul 2005 09:05:13 +0300
Daniel Stenberg wrote:
> On Wed, 27 Jul 2005, Peteris Krumins [Newsgroups] wrote:
>
>> Okay. I have made the changes and added documentation for the
>> interface setopt/getinfo options in man pages.
>
>
> Great!
>
> I only modified it slightly to build fine even when HTTP or cookies
> are disabled. I've now committed this!
Excellent!
> The only downside with this interface that I can think of right now,
> is that it modifies the string given as input to CURLOPT_COOKIELIST,
> which I think is rather ugly.
> I have no easy work-around for this that doesn't involve simply
> strduping() the string on entry. But perhaps that's still better than
> requiring writable and disposable strings as input?
Agree. That is better. I attached a patch which changes this and
setopt(3) man page. Also numcookies was not set to 0 if cookies were
deleted.
P.Krumins
Index: docs/libcurl/curl_easy_setopt.3
===================================================================
--- docs/libcurl/curl_easy_setopt.3 (revision 48)
+++ docs/libcurl/curl_easy_setopt.3 (revision 49)
@@ -643,7 +643,6 @@
.IP CURLOPT_COOKIELIST
Pass a char * to a cookie string. Cookie can be either in Netscape / Mozilla
format or just regular HTTP-style header (Set-Cookie: ...) format.
-The passed string will get modified so make sure it's writable.
If cURL cookie engine was not enabled it will enable its cookie engine.
Passing a magic string "ALL" will erase all cookies known by cURL.
.IP CURLOPT_HTTPGET
Index: lib/url.c
===================================================================
--- lib/url.c (revision 48)
+++ lib/url.c (revision 49)
@@ -1398,6 +1398,7 @@
case CURLOPT_COOKIELIST:
{
+ char *ldup;
char *line = va_arg(param, char *);
if (line == NULL) {
@@ -1411,6 +1412,7 @@
/* clear all cookies */
Curl_cookie_freelist(data->cookies->cookies);
data->cookies->cookies = NULL;
+ data->cookies->numcookies = 0;
break;
}
}
@@ -1420,14 +1422,20 @@
data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE);
}
- if (checkprefix("Set-Cookie:", line)) {
+ ldup = strdup(line);
+ if (ldup == NULL) {
+ result = CURLE_OUT_OF_MEMORY;
+ break;
+ }
+ if (checkprefix("Set-Cookie:", ldup)) {
/* HTTP Header format line */
- Curl_cookie_add(data, data->cookies, TRUE, line + 11, NULL, NULL);
+ Curl_cookie_add(data, data->cookies, TRUE, ldup + 11, NULL, NULL);
}
else {
/* Netscape format line */
- Curl_cookie_add(data, data->cookies, FALSE, line, NULL, NULL);
+ Curl_cookie_add(data, data->cookies, FALSE, ldup, NULL, NULL);
}
+ free(ldup);
}
break;
Received on 2005-07-28