|
bagder: curl/lib cookie.c, 1.69, 1.70 cookie.h, 1.17, 1.18 getinfo.c, 1.45,: msg#00032web.curl.cvs
Update of /cvsroot/curl/curl/lib In directory labb:/tmp/cvs-serv14776/lib Modified Files: cookie.c cookie.h getinfo.c url.c Log Message: Peteris Krumins added CURLOPT_COOKIELIST and CURLINFO_COOKIELIST, which is a simple interface to extracting and setting cookies in libcurl's internal "cookie jar". See the new cookie_interface.c example code. Index: getinfo.c =================================================================== RCS file: /cvsroot/curl/curl/lib/getinfo.c,v retrieving revision 1.45 retrieving revision 1.46 diff -u -d -r1.45 -r1.46 --- getinfo.c 22 Apr 2005 20:48:07 -0000 1.45 +++ getinfo.c 27 Jul 2005 22:17:15 -0000 1.46 @@ -184,6 +184,9 @@ case CURLINFO_SSL_ENGINES: *param_slistp = Curl_ssl_engines_list(data); break; + case CURLINFO_COOKIELIST: + *param_slistp = Curl_cookie_list(data); + break; default: return CURLE_BAD_FUNCTION_ARGUMENT; } Index: cookie.h =================================================================== RCS file: /cvsroot/curl/curl/lib/cookie.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- cookie.h 6 Oct 2004 07:50:18 -0000 1.17 +++ cookie.h 27 Jul 2005 22:17:15 -0000 1.18 @@ -92,4 +92,10 @@ void Curl_cookie_cleanup(struct CookieInfo *); int Curl_cookie_output(struct CookieInfo *, char *); +#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES) +#define Curl_cookie_list(x) NULL +#else +struct curl_slist *Curl_cookie_list(struct SessionHandle *data); +#endif + #endif Index: url.c =================================================================== RCS file: /cvsroot/curl/curl/lib/url.c,v retrieving revision 1.467 retrieving revision 1.468 diff -u -d -r1.467 -r1.468 --- url.c 17 Jul 2005 12:44:11 -0000 1.467 +++ url.c 27 Jul 2005 22:17:15 -0000 1.468 @@ -773,6 +773,37 @@ */ data->set.cookiesession = (bool)va_arg(param, long); break; + + case CURLOPT_COOKIELIST: + argptr = va_arg(param, char *); + + if (argptr == NULL) + break; + + if (strequal(argptr, "ALL")) { + if (data->cookies == NULL) { + break; + } + else { + /* clear all cookies */ + Curl_cookie_freelist(data->cookies->cookies); + data->cookies->cookies = NULL; + break; + } + } + + if (!data->cookies) + /* if cookie engine was not running, activate it */ + data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE); + + if (checkprefix("Set-Cookie:", argptr)) + /* HTTP Header format line */ + Curl_cookie_add(data, data->cookies, TRUE, argptr + 11, NULL, NULL); + + else + /* Netscape format line */ + Curl_cookie_add(data, data->cookies, FALSE, argptr, NULL, NULL); + break; #endif /* CURL_DISABLE_COOKIES */ case CURLOPT_HTTPGET: Index: cookie.c =================================================================== RCS file: /cvsroot/curl/curl/lib/cookie.c,v retrieving revision 1.69 retrieving revision 1.70 diff -u -d -r1.69 -r1.70 --- cookie.c 26 Apr 2005 13:08:49 -0000 1.69 +++ cookie.c 27 Jul 2005 22:17:15 -0000 1.70 @@ -85,6 +85,9 @@ #include <stdlib.h> #include <string.h> +#define _MPRINTF_REPLACE /* without this on windows OS we get undefined reference to snprintf */ +#include <curl/mprintf.h> + #include "urldata.h" #include "cookie.h" #include "strequal.h" @@ -816,6 +819,34 @@ } } +/* get_netscape_format() + * + * Formats a string for Netscape output file, w/o a newline at the end. + * + * Function returns a char * to a formatted line. Has to be free()d +*/ +static char *get_netscape_format(const struct Cookie *co) +{ + return aprintf( + "%s%s\t" /* domain */ + "%s\t" /* tailmatch */ + "%s\t" /* path */ + "%s\t" /* secure */ + "%u\t" /* expires */ + "%s\t" /* name */ + "%s", /* value */ + /* Make sure all domains are prefixed with a dot if they allow + tailmatching. This is Mozilla-style. */ + (co->tailmatch && co->domain && co->domain[0] != '.')? ".":"", + co->domain?co->domain:"unknown", + co->tailmatch?"TRUE":"FALSE", + co->path?co->path:"/", + co->secure?"TRUE":"FALSE", + (unsigned int)co->expires, + co->name, + co->value?co->value:""); +} + /* * Curl_cookie_output() * @@ -847,6 +878,8 @@ } if(c) { + char *format_ptr; + fputs("# Netscape HTTP Cookie File\n" "# http://www.netscape.com/newsref/std/cookie_spec.html\n" "# This file was generated by libcurl! Edit at your own risk.\n\n", @@ -854,26 +887,13 @@ co = c->cookies; while(co) { - fprintf(out, - "%s%s\t" /* domain */ - "%s\t" /* tailmatch */ - "%s\t" /* path */ - "%s\t" /* secure */ - "%u\t" /* expires */ - "%s\t" /* name */ - "%s\n", /* value */ - - /* Make sure all domains are prefixed with a dot if they allow - tailmatching. This is Mozilla-style. */ - (co->tailmatch && co->domain && co->domain[0] != '.')? ".":"", - co->domain?co->domain:"unknown", - co->tailmatch?"TRUE":"FALSE", - co->path?co->path:"/", - co->secure?"TRUE":"FALSE", - (unsigned int)co->expires, - co->name, - co->value?co->value:""); - + format_ptr = get_netscape_format(co); + if (format_ptr == NULL) { + fprintf(out, "#\n# Fatal libcurl error\n"); + return 1; + } + fprintf(out, "%s\n", format_ptr); + free(format_ptr); co=co->next; } } @@ -884,4 +904,34 @@ return 0; } +struct curl_slist *Curl_cookie_list(struct SessionHandle *data) +{ + struct curl_slist *list = NULL; + struct curl_slist *beg; + struct Cookie *c; + char *line; + + if (data->cookies == NULL) return NULL; + if (data->cookies->numcookies == 0) return NULL; + + c = data->cookies->cookies; + + beg = list; + while (c) { + /* fill the list with _all_ the cookies we know */ + line = get_netscape_format(c); + if (line == NULL) { + /* get_netscape_format returns null only if we run out of memory */ + + curl_slist_free_all(beg); /* free some memory */ + return NULL; + } + list = curl_slist_append(list, line); + free(line); + c = c->next; + } + + return list; +} + #endif /* CURL_DISABLE_HTTP || CURL_DISABLE_COOKIES */ _______________________________________________ http://cool.haxx.se/mailman/listinfo/curl-commits |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | bagder: curl CHANGES,1.730,1.731 RELEASE-NOTES,1.268,1.269: 00032, cvs |
|---|---|
| Next by Date: | bagder: curl/lib url.c,1.468,1.469: 00032, cvs |
| Previous by Thread: | bagder: curl CHANGES,1.730,1.731 RELEASE-NOTES,1.268,1.269i: 00032, cvs |
| Next by Thread: | bagder: curl/lib url.c,1.468,1.469: 00032, cvs |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |