* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
-#include "curl_printf.h"
+#define _MPRINTF_REPLACE
+#include <curl/mprintf.h>
+
#include "urldata.h"
#include "cookie.h"
#include "strequal.h"
#include "strtok.h"
#include "sendf.h"
#include "slist.h"
+#include "curl_memory.h"
#include "share.h"
#include "strtoofft.h"
#include "rawstr.h"
#include "curl_memrchr.h"
#include "inet_pton.h"
-/* The last #include files should be: */
-#include "curl_memory.h"
+/* The last #include file should be: */
#include "memdebug.h"
static void freecookie(struct Cookie *co)
{
- free(co->expirestr);
- free(co->domain);
- free(co->path);
- free(co->spath);
- free(co->name);
- free(co->value);
- free(co->maxage);
- free(co->version);
+ if(co->expirestr)
+ free(co->expirestr);
+ if(co->domain)
+ free(co->domain);
+ if(co->path)
+ free(co->path);
+ if(co->spath)
+ free(co->spath);
+ if(co->name)
+ free(co->name);
+ if(co->value)
+ free(co->value);
+ if(co->maxage)
+ free(co->maxage);
+ if(co->version)
+ free(co->version);
+
free(co);
}
*/
static void strstore(char **str, const char *newstr)
{
- free(*str);
+ if(*str)
+ free(*str);
*str = strdup(newstr);
}
do {
/* we have a <what>=<this> pair or a stand-alone word here */
name[0]=what[0]=0; /* init the buffers */
- if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^;\r\n =] =%"
+ if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^;\r\n =]=%"
MAX_COOKIE_LINE_TXT "[^;\r\n]",
name, what)) {
/* Use strstore() below to properly deal with received cookie
/* then free all the old pointers */
free(clist->name);
- free(clist->value);
- free(clist->domain);
- free(clist->path);
- free(clist->spath);
- free(clist->expirestr);
- free(clist->version);
- free(clist->maxage);
+ if(clist->value)
+ free(clist->value);
+ if(clist->domain)
+ free(clist->domain);
+ if(clist->path)
+ free(clist->path);
+ if(clist->spath)
+ free(clist->spath);
+ if(clist->expirestr)
+ free(clist->expirestr);
+
+ if(clist->version)
+ free(clist->version);
+ if(clist->maxage)
+ free(clist->maxage);
*clist = *co; /* then store all the new data */
fp = NULL;
}
else
- fp = file?fopen(file, FOPEN_READTEXT):NULL;
+ fp = file?fopen(file, "r"):NULL;
c->newsession = newsession; /* new session? */
return c;
fail:
- free(line);
+ Curl_safefree(line);
if(!inc)
/* Only clean up if we allocated it here, as the original could still be in
* use by a share handle */
void Curl_cookie_cleanup(struct CookieInfo *c)
{
if(c) {
- free(c->filename);
+ if(c->filename)
+ free(c->filename);
Curl_cookie_freelist(c->cookies, TRUE);
free(c); /* free the base struct as well */
}
use_stdout=TRUE;
}
else {
- out = fopen(dumphere, FOPEN_WRITETEXT);
+ out = fopen(dumphere, "w");
if(!out)
return 1; /* failure */
}
"# http://curl.haxx.se/docs/http-cookies.html\n"
"# This file was generated by libcurl! Edit at your own risk.\n\n",
out);
+ co = c->cookies;
- for(co = c->cookies; co; co = co->next) {
- if(!co->domain)
- continue;
+ while(co) {
format_ptr = get_netscape_format(co);
if(format_ptr == NULL) {
fprintf(out, "#\n# Fatal libcurl error\n");
}
fprintf(out, "%s\n", format_ptr);
free(format_ptr);
+ co=co->next;
}
}
(data->cookies->numcookies == 0))
return NULL;
- for(c = data->cookies->cookies; c; c = c->next) {
- if(!c->domain)
- continue;
+ c = data->cookies->cookies;
+
+ while(c) {
+ /* fill the list with _all_ the cookies we know */
line = get_netscape_format(c);
if(!line) {
curl_slist_free_all(list);
return NULL;
}
list = beg;
+ c = c->next;
}
return list;