aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2000-02-10 23:14:53 +0000
committerDaniel Stenberg <daniel@haxx.se>2000-02-10 23:14:53 +0000
commit9280c208d3caf4b0188b66d32dffbce8f32f705f (patch)
treeba072e84209981b3873d62e8274d22bcc62a6896 /lib
parent1d75889360bb5ea892b7102f2c49f2991db9619c (diff)
* Made '-' as file name to read cookies from equal stdin.
* I hope I finally removed 'empty cookies' crash
Diffstat (limited to 'lib')
-rw-r--r--lib/cookie.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/cookie.c b/lib/cookie.c
index 613c52e7f..00497bc94 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -102,7 +102,7 @@ struct Cookie *cookie_add(struct CookieInfo *c,
/* we have a <what>=<this> pair or a 'secure' word here */
if(strchr(ptr, '=')) {
name[0]=what[0]=0; /* init the buffers */
- if(2 == sscanf(ptr, "%" MAX_NAME_TXT "[^=]=%"
+ if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^=]=%"
MAX_COOKIE_LINE_TXT "[^\r\n]",
name, what)) {
/* this is a legal <what>=<this> pair */
@@ -317,14 +317,21 @@ struct CookieInfo *cookie_init(char *file)
char line[MAX_COOKIE_LINE];
struct CookieInfo *c;
FILE *fp;
-
+ bool fromfile=TRUE;
+
c = (struct CookieInfo *)malloc(sizeof(struct CookieInfo));
if(!c)
return NULL; /* failed to get memory */
memset(c, 0, sizeof(struct CookieInfo));
c->filename = strdup(file?file:"none"); /* copy the name just in case */
- fp = file?fopen(file, "r"):NULL;
+ if(strequal(file, "-")) {
+ fp = stdin;
+ fromfile=FALSE;
+ }
+ else
+ fp = file?fopen(file, "r"):NULL;
+
if(fp) {
while(fgets(line, MAX_COOKIE_LINE, fp)) {
if(strnequal("Set-Cookie:", line, 11)) {
@@ -344,7 +351,8 @@ struct CookieInfo *cookie_init(char *file)
cookie_add(c, FALSE, lineptr);
}
}
- fclose(fp);
+ if(fromfile)
+ fclose(fp);
}
return c;