mirror of
https://github.com/curl/curl.git
synced 2026-08-25 12:53:33 +03:00
curl_get_line: enhance the API
To make sure callers can properly differentiate between errors and know cleanly when EOF happens. Updated all users and unit test 3200. Triggered by a remark by ZeroPath Closes #19140
This commit is contained in:
parent
990a23bb97
commit
769ccb4d42
7 changed files with 112 additions and 110 deletions
30
lib/cookie.c
30
lib/cookie.c
|
|
@ -1205,19 +1205,27 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
|
|||
ci->running = FALSE; /* this is not running, this is init */
|
||||
if(fp) {
|
||||
struct dynbuf buf;
|
||||
bool eof = FALSE;
|
||||
CURLcode result;
|
||||
curlx_dyn_init(&buf, MAX_COOKIE_LINE);
|
||||
while(Curl_get_line(&buf, fp)) {
|
||||
const char *lineptr = curlx_dyn_ptr(&buf);
|
||||
bool headerline = FALSE;
|
||||
if(checkprefix("Set-Cookie:", lineptr)) {
|
||||
/* This is a cookie line, get it! */
|
||||
lineptr += 11;
|
||||
headerline = TRUE;
|
||||
curlx_str_passblanks(&lineptr);
|
||||
}
|
||||
do {
|
||||
result = Curl_get_line(&buf, fp, &eof);
|
||||
if(!result) {
|
||||
const char *lineptr = curlx_dyn_ptr(&buf);
|
||||
bool headerline = FALSE;
|
||||
if(checkprefix("Set-Cookie:", lineptr)) {
|
||||
/* This is a cookie line, get it! */
|
||||
lineptr += 11;
|
||||
headerline = TRUE;
|
||||
curlx_str_passblanks(&lineptr);
|
||||
}
|
||||
|
||||
Curl_cookie_add(data, ci, headerline, TRUE, lineptr, NULL, NULL, TRUE);
|
||||
}
|
||||
(void)Curl_cookie_add(data, ci, headerline, TRUE, lineptr, NULL,
|
||||
NULL, TRUE);
|
||||
/* File reading cookie failures are not propagated back to the
|
||||
caller because there is no way to do that */
|
||||
}
|
||||
} while(!result && !eof);
|
||||
curlx_dyn_free(&buf); /* free the line buffer */
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue