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:
Daniel Stenberg 2025-10-19 13:09:42 +02:00
parent 990a23bb97
commit 769ccb4d42
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
7 changed files with 112 additions and 110 deletions

View file

@ -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 */
/*