From 5d2ecfef56e49a8e4bfad25a582ff1597987f717 Mon Sep 17 00:00:00 2001 From: dartraiden Date: Wed, 6 Nov 2024 20:55:13 +0300 Subject: libcurl: update to 8.11.0 --- libs/libcurl/src/http.c | 172 ++++++++++++++++++++++++------------------------ 1 file changed, 85 insertions(+), 87 deletions(-) (limited to 'libs/libcurl/src/http.c') diff --git a/libs/libcurl/src/http.c b/libs/libcurl/src/http.c index 65189e9dee..6d61a9ec34 100644 --- a/libs/libcurl/src/http.c +++ b/libs/libcurl/src/http.c @@ -407,7 +407,7 @@ static CURLcode http_perhapsrewind(struct Curl_easy *data, { curl_off_t bytessent = data->req.writebytecount; curl_off_t expectsend = Curl_creader_total_length(data); - curl_off_t upload_remain = (expectsend >= 0)? (expectsend - bytessent) : -1; + curl_off_t upload_remain = (expectsend >= 0) ? (expectsend - bytessent) : -1; bool little_upload_remains = (upload_remain >= 0 && upload_remain < 2000); bool needs_rewind = Curl_creader_needs_rewind(data); /* By default, we would like to abort the transfer when little or unknown @@ -463,14 +463,14 @@ static CURLcode http_perhapsrewind(struct Curl_easy *data, if(abort_upload) { if(upload_remain >= 0) infof(data, "%s%sclose instead of sending %" FMT_OFF_T " more bytes", - ongoing_auth? ongoing_auth : "", - ongoing_auth? " send, " : "", + ongoing_auth ? ongoing_auth : "", + ongoing_auth ? " send, " : "", upload_remain); else infof(data, "%s%sclose instead of sending unknown amount " "of more bytes", - ongoing_auth? ongoing_auth : "", - ongoing_auth? " send, " : ""); + ongoing_auth ? ongoing_auth : "", + ongoing_auth ? " send, " : ""); /* We decided to abort the ongoing transfer */ streamclose(conn, "Mid-auth HTTP and much data left to send"); /* FIXME: questionable manipulation here, can we do this differently? */ @@ -502,7 +502,7 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data) return CURLE_OK; if(data->state.authproblem) - return data->set.http_fail_on_error?CURLE_HTTP_RETURNED_ERROR:CURLE_OK; + return data->set.http_fail_on_error ? CURLE_HTTP_RETURNED_ERROR : CURLE_OK; if((data->state.aptr.user || data->set.str[STRING_BEARER]) && ((data->req.httpcode == 401) || @@ -677,7 +677,7 @@ output_auth_headers(struct Curl_easy *data, auth, data->state.aptr.user ? data->state.aptr.user : ""); #endif - authstatus->multipass = (!authstatus->done) ? TRUE : FALSE; + authstatus->multipass = !authstatus->done; } else authstatus->multipass = FALSE; @@ -1261,8 +1261,8 @@ CURLcode Curl_dynhds_add_custom(struct Curl_easy *data, if(is_connect) proxy = HEADER_CONNECT; else - proxy = conn->bits.httpproxy && !conn->bits.tunnel_proxy? - HEADER_PROXY:HEADER_SERVER; + proxy = conn->bits.httpproxy && !conn->bits.tunnel_proxy ? + HEADER_PROXY : HEADER_SERVER; switch(proxy) { case HEADER_SERVER: @@ -1408,8 +1408,8 @@ CURLcode Curl_add_custom_headers(struct Curl_easy *data, if(is_connect) proxy = HEADER_CONNECT; else - proxy = conn->bits.httpproxy && !conn->bits.tunnel_proxy? - HEADER_PROXY:HEADER_SERVER; + proxy = conn->bits.httpproxy && !conn->bits.tunnel_proxy ? + HEADER_PROXY : HEADER_SERVER; switch(proxy) { case HEADER_SERVER: @@ -1602,7 +1602,7 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data, msnprintf(datestr, sizeof(datestr), "%s: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n", condp, - Curl_wkday[tm->tm_wday?tm->tm_wday-1:6], + Curl_wkday[tm->tm_wday ? tm->tm_wday-1 : 6], tm->tm_mday, Curl_month[tm->tm_mon], tm->tm_year + 1900, @@ -1755,11 +1755,12 @@ CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn) (conn->remote_port == PORT_HTTP)) ) /* if(HTTPS on port 443) OR (HTTP on port 80) then do not include the port number in the host string */ - aptr->host = aprintf("Host: %s%s%s\r\n", conn->bits.ipv6_ip?"[":"", - host, conn->bits.ipv6_ip?"]":""); + aptr->host = aprintf("Host: %s%s%s\r\n", conn->bits.ipv6_ip ? "[" : "", + host, conn->bits.ipv6_ip ? "]" : ""); else - aptr->host = aprintf("Host: %s%s%s:%d\r\n", conn->bits.ipv6_ip?"[":"", - host, conn->bits.ipv6_ip?"]":"", + aptr->host = aprintf("Host: %s%s%s:%d\r\n", + conn->bits.ipv6_ip ? "[" : "", + host, conn->bits.ipv6_ip ? "]" : "", conn->remote_port); if(!aptr->host) @@ -1836,8 +1837,8 @@ CURLcode Curl_http_target(struct Curl_easy *data, curl_url_cleanup(h); /* target or URL */ - result = Curl_dyn_add(r, data->set.str[STRING_TARGET]? - data->set.str[STRING_TARGET]:url); + result = Curl_dyn_add(r, data->set.str[STRING_TARGET] ? + data->set.str[STRING_TARGET] : url); free(url); if(result) return (result); @@ -1973,11 +1974,8 @@ static CURLcode set_reader(struct Curl_easy *data, Curl_HttpReq httpreq) switch(httpreq) { case HTTPREQ_PUT: /* Let's PUT the data to the server! */ - if(!postsize) - result = Curl_creader_set_null(data); - else - result = Curl_creader_set_fread(data, postsize); - return result; + return postsize ? Curl_creader_set_fread(data, postsize) : + Curl_creader_set_null(data); #if !defined(CURL_DISABLE_MIME) || !defined(CURL_DISABLE_FORM_API) case HTTPREQ_POST_FORM: @@ -2010,7 +2008,7 @@ static CURLcode set_reader(struct Curl_easy *data, Curl_HttpReq httpreq) chunked = Curl_compareheader(ptr, STRCONST("Transfer-Encoding:"), STRCONST("chunked")); } - result = Curl_creader_set_fread(data, chunked? -1 : postsize); + result = Curl_creader_set_fread(data, chunked ? -1 : postsize); } return result; @@ -2250,8 +2248,9 @@ CURLcode Curl_http_cookies(struct Curl_easy *data, addcookies = data->set.str[STRING_COOKIE]; if(data->cookies || addcookies) { - struct Cookie *co = NULL; /* no cookies from start */ + struct Curl_llist list; int count = 0; + int rc = 1; if(data->cookies && data->state.cookie_engine) { const char *host = data->state.aptr.cookiehost ? @@ -2260,17 +2259,19 @@ CURLcode Curl_http_cookies(struct Curl_easy *data, conn->handler->protocol&(CURLPROTO_HTTPS|CURLPROTO_WSS) || strcasecompare("localhost", host) || !strcmp(host, "127.0.0.1") || - !strcmp(host, "::1") ? TRUE : FALSE; + !strcmp(host, "::1"); Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); - co = Curl_cookie_getlist(data, data->cookies, host, data->state.up.path, - secure_context); + rc = Curl_cookie_getlist(data, data->cookies, host, data->state.up.path, + secure_context, &list); Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); } - if(co) { - struct Cookie *store = co; + if(!rc) { + struct Curl_llist_node *n; size_t clen = 8; /* hold the size of the generated Cookie: header */ - /* now loop through all cookies that matched */ - while(co) { + + /* loop through all cookies that matched */ + for(n = Curl_llist_head(&list); n; n = Curl_node_next(n)) { + struct Cookie *co = Curl_node_elem(n); if(co->value) { size_t add; if(!count) { @@ -2285,22 +2286,21 @@ CURLcode Curl_http_cookies(struct Curl_easy *data, linecap = TRUE; break; } - result = Curl_dyn_addf(r, "%s%s=%s", count?"; ":"", + result = Curl_dyn_addf(r, "%s%s=%s", count ? "; " : "", co->name, co->value); if(result) break; clen += add + (count ? 2 : 0); count++; } - co = co->next; /* next cookie please */ } - Curl_cookie_freelist(store); + Curl_llist_destroy(&list, NULL); } if(addcookies && !result && !linecap) { if(!count) result = Curl_dyn_addn(r, STRCONST("Cookie: ")); if(!result) { - result = Curl_dyn_addf(r, "%s%s", count?"; ":"", addcookies); + result = Curl_dyn_addf(r, "%s%s", count ? "; " : "", addcookies); count++; } } @@ -2350,7 +2350,7 @@ CURLcode Curl_http_range(struct Curl_easy *data, /* TODO: not sure if we want to send this header during authentication * negotiation, but test1084 checks for it. In which case we have a * "null" client reader installed that gives an unexpected length. */ - curl_off_t total_len = data->req.authneg? + curl_off_t total_len = data->req.authneg ? data->state.infilesize : (data->state.resume_from + req_clen); data->state.aptr.rangeline = @@ -2582,7 +2582,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done) goto fail; p_accept = Curl_checkheaders(data, - STRCONST("Accept"))?NULL:"Accept: */*\r\n"; + STRCONST("Accept")) ? NULL : "Accept: */*\r\n"; result = Curl_http_range(data, httpreq); if(result) @@ -2634,35 +2634,34 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done) "%s",/* Alt-Used */ httpstring, - (data->state.aptr.host?data->state.aptr.host:""), + (data->state.aptr.host ? data->state.aptr.host : ""), #ifndef CURL_DISABLE_PROXY - data->state.aptr.proxyuserpwd? - data->state.aptr.proxyuserpwd:"", + data->state.aptr.proxyuserpwd ? + data->state.aptr.proxyuserpwd : "", #else "", #endif - data->state.aptr.userpwd?data->state.aptr.userpwd:"", - (data->state.use_range && data->state.aptr.rangeline)? - data->state.aptr.rangeline:"", + data->state.aptr.userpwd ? data->state.aptr.userpwd : "", + (data->state.use_range && data->state.aptr.rangeline) ? + data->state.aptr.rangeline : "", (data->set.str[STRING_USERAGENT] && *data->set.str[STRING_USERAGENT] && - data->state.aptr.uagent)? - data->state.aptr.uagent:"", - p_accept?p_accept:"", - data->state.aptr.te?data->state.aptr.te:"", + data->state.aptr.uagent) ? + data->state.aptr.uagent : "", + p_accept ? p_accept : "", + data->state.aptr.te ? data->state.aptr.te : "", (data->set.str[STRING_ENCODING] && *data->set.str[STRING_ENCODING] && - data->state.aptr.accept_encoding)? - data->state.aptr.accept_encoding:"", - (data->state.referer && data->state.aptr.ref)? - data->state.aptr.ref:"" /* Referer: */, + data->state.aptr.accept_encoding) ? + data->state.aptr.accept_encoding : "", + (data->state.referer && data->state.aptr.ref) ? + data->state.aptr.ref : "" /* Referer: */, #ifndef CURL_DISABLE_PROXY (conn->bits.httpproxy && !conn->bits.tunnel_proxy && !Curl_checkheaders(data, STRCONST("Proxy-Connection")) && - !Curl_checkProxyheaders(data, - conn, - STRCONST("Proxy-Connection")))? + !Curl_checkProxyheaders(data, conn, + STRCONST("Proxy-Connection"))) ? "Proxy-Connection: Keep-Alive\r\n":"", #else "", @@ -2697,7 +2696,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done) } result = Curl_http_cookies(data, conn, &req); -#ifdef USE_WEBSOCKETS +#ifndef CURL_DISABLE_WEBSOCKETS if(!result && conn->handler->protocol&(CURLPROTO_WS|CURLPROTO_WSS)) result = Curl_ws_request(data, &req); #endif @@ -2754,7 +2753,7 @@ checkhttpprefix(struct Curl_easy *data, { struct curl_slist *head = data->set.http200aliases; statusline rc = STATUS_BAD; - statusline onmatch = len >= 5? STATUS_DONE : STATUS_UNKNOWN; + statusline onmatch = len >= 5 ? STATUS_DONE : STATUS_UNKNOWN; while(head) { if(checkprefixmax(head->data, s, len)) { @@ -2776,7 +2775,7 @@ checkrtspprefix(struct Curl_easy *data, const char *s, size_t len) { statusline result = STATUS_BAD; - statusline onmatch = len >= 5? STATUS_DONE : STATUS_UNKNOWN; + statusline onmatch = len >= 5 ? STATUS_DONE : STATUS_UNKNOWN; (void)data; /* unused */ if(checkprefixmax("RTSP/", s, len)) result = onmatch; @@ -2837,10 +2836,10 @@ CURLcode Curl_http_header(struct Curl_easy *data, #else 0 #endif - ))? HD_VAL(hd, hdlen, "Alt-Svc:") : NULL; + )) ? HD_VAL(hd, hdlen, "Alt-Svc:") : NULL; if(v) { /* the ALPN of the current request */ - enum alpnid id = (conn->httpversion == 30)? ALPN_h3 : + enum alpnid id = (conn->httpversion == 30) ? ALPN_h3 : (conn->httpversion == 20) ? ALPN_h2 : ALPN_h1; return Curl_altsvc_parse(data, data->asi, v, id, conn->host.name, curlx_uitous((unsigned int)conn->remote_port)); @@ -2850,8 +2849,8 @@ CURLcode Curl_http_header(struct Curl_easy *data, case 'c': case 'C': /* Check for Content-Length: header lines to get size */ - v = (!k->http_bodyless && !data->set.ignorecl)? - HD_VAL(hd, hdlen, "Content-Length:") : NULL; + v = (!k->http_bodyless && !data->set.ignorecl) ? + HD_VAL(hd, hdlen, "Content-Length:") : NULL; if(v) { curl_off_t contentlength; CURLofft offt = curlx_strtoofft(v, NULL, 10, &contentlength); @@ -2876,8 +2875,8 @@ CURLcode Curl_http_header(struct Curl_easy *data, } return CURLE_OK; } - v = (!k->http_bodyless && data->set.str[STRING_ENCODING])? - HD_VAL(hd, hdlen, "Content-Encoding:") : NULL; + v = (!k->http_bodyless && data->set.str[STRING_ENCODING]) ? + HD_VAL(hd, hdlen, "Content-Encoding:") : NULL; if(v) { /* * Process Content-Encoding. Look for the values: identity, @@ -2925,7 +2924,7 @@ CURLcode Curl_http_header(struct Curl_easy *data, infof(data, "HTTP/1.0 connection set to keep alive"); return CURLE_OK; } - v = !k->http_bodyless? HD_VAL(hd, hdlen, "Content-Range:") : NULL; + v = !k->http_bodyless ? HD_VAL(hd, hdlen, "Content-Range:") : NULL; if(v) { /* Content-Range: bytes [num]- Content-Range: bytes: [num]- @@ -2959,7 +2958,7 @@ CURLcode Curl_http_header(struct Curl_easy *data, case 'l': case 'L': v = (!k->http_bodyless && - (data->set.timecondition || data->set.get_filetime))? + (data->set.timecondition || data->set.get_filetime)) ? HD_VAL(hd, hdlen, "Last-Modified:") : NULL; if(v) { k->timeofdoc = Curl_getdate_capped(v); @@ -3042,8 +3041,7 @@ CURLcode Curl_http_header(struct Curl_easy *data, char *persistentauth = Curl_copy_header_value(hd); if(!persistentauth) return CURLE_OUT_OF_MEMORY; - negdata->noauthpersist = checkprefix("false", persistentauth)? - TRUE:FALSE; + negdata->noauthpersist = !!checkprefix("false", persistentauth); negdata->havenoauthpersist = TRUE; infof(data, "Negotiate: noauthpersist -> %d, header part: %s", negdata->noauthpersist, persistentauth); @@ -3073,18 +3071,18 @@ CURLcode Curl_http_header(struct Curl_easy *data, case 's': case 'S': #if !defined(CURL_DISABLE_COOKIES) - v = (data->cookies && data->state.cookie_engine)? + v = (data->cookies && data->state.cookie_engine) ? HD_VAL(hd, hdlen, "Set-Cookie:") : NULL; if(v) { /* If there is a custom-set Host: name, use it here, or else use * real peer hostname. */ - const char *host = data->state.aptr.cookiehost? - data->state.aptr.cookiehost:conn->host.name; + const char *host = data->state.aptr.cookiehost ? + data->state.aptr.cookiehost : conn->host.name; const bool secure_context = conn->handler->protocol&(CURLPROTO_HTTPS|CURLPROTO_WSS) || strcasecompare("localhost", host) || !strcmp(host, "127.0.0.1") || - !strcmp(host, "::1") ? TRUE : FALSE; + !strcmp(host, "::1"); Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); @@ -3105,7 +3103,7 @@ CURLcode Curl_http_header(struct Curl_easy *data, 0 #endif ) - )? HD_VAL(hd, hdlen, "Strict-Transport-Security:") : NULL; + ) ? HD_VAL(hd, hdlen, "Strict-Transport-Security:") : NULL; if(v) { CURLcode check = Curl_hsts_parse(data->hsts, conn->host.name, v); @@ -3133,8 +3131,8 @@ CURLcode Curl_http_header(struct Curl_easy *data, */ v = (!k->http_bodyless && (data->state.httpreq != HTTPREQ_HEAD) && - (k->httpcode != 304))? - HD_VAL(hd, hdlen, "Transfer-Encoding:") : NULL; + (k->httpcode != 304)) ? + HD_VAL(hd, hdlen, "Transfer-Encoding:") : NULL; if(v) { /* One or more encodings. We check for chunked and/or a compression algorithm. */ @@ -3372,8 +3370,8 @@ static CURLcode http_write_header(struct Curl_easy *data, return result; data->req.deductheadercount = (100 <= data->req.httpcode && - 199 >= data->req.httpcode)? - data->req.headerbytecount:0; + 199 >= data->req.httpcode) ? + data->req.headerbytecount : 0; return result; } @@ -3449,7 +3447,7 @@ static CURLcode http_on_response(struct Curl_easy *data, goto out; *pconsumed += blen; } -#ifdef USE_WEBSOCKETS +#ifndef CURL_DISABLE_WEBSOCKETS else if(k->upgr101 == UPGR101_WS) { /* verify the response. Any passed `buf` bytes are already in * WebSockets format and taken in by the protocol handler. */ @@ -3534,7 +3532,7 @@ static CURLcode http_on_response(struct Curl_easy *data, } #endif -#ifdef USE_WEBSOCKETS +#ifndef CURL_DISABLE_WEBSOCKETS /* All >=200 HTTP status codes are errors when wanting WebSockets */ if(data->req.upgr101 == UPGR101_WS) { failf(data, "Refused WebSockets upgrade: %d", k->httpcode); @@ -4052,7 +4050,7 @@ CURLcode Curl_http_decode_status(int *pstatus, const char *s, size_t len) } result = CURLE_OK; out: - *pstatus = result? -1 : status; + *pstatus = result ? -1 : status; return result; } @@ -4095,7 +4093,7 @@ CURLcode Curl_http_req_make(struct httpreq **preq, out: if(result && req) Curl_http_req_free(req); - *preq = result? NULL : req; + *preq = result ? NULL : req; return result; } @@ -4253,7 +4251,7 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, out: if(result && req) Curl_http_req_free(req); - *preq = result? NULL : req; + *preq = result ? NULL : req; return result; } @@ -4319,8 +4317,8 @@ CURLcode Curl_http_req_to_h2(struct dynhds *h2_headers, infof(data, "set pseudo header %s to %s", HTTP_PSEUDO_SCHEME, scheme); } else { - scheme = (data->conn && data->conn->handler->flags & PROTOPT_SSL)? - "https" : "http"; + scheme = (data->conn && data->conn->handler->flags & PROTOPT_SSL) ? + "https" : "http"; } } @@ -4384,7 +4382,7 @@ CURLcode Curl_http_resp_make(struct http_resp **presp, out: if(result && resp) Curl_http_resp_free(resp); - *presp = result? NULL : resp; + *presp = result ? NULL : resp; return result; } @@ -4479,7 +4477,7 @@ static void cr_exp100_done(struct Curl_easy *data, struct Curl_creader *reader, int premature) { struct cr_exp100_ctx *ctx = reader->ctx; - ctx->state = premature? EXP100_FAILED : EXP100_SEND_DATA; + ctx->state = premature ? EXP100_FAILED : EXP100_SEND_DATA; data->req.keepon &= ~KEEP_SEND_TIMED; Curl_expire_done(data, EXPIRE_100_TIMEOUT); } @@ -4545,7 +4543,7 @@ static void http_exp100_send_anyway(struct Curl_easy *data) bool Curl_http_exp100_is_selected(struct Curl_easy *data) { struct Curl_creader *r = Curl_creader_get_by_type(data, &cr_exp100); - return r? TRUE : FALSE; + return !!r; } #endif /* CURL_DISABLE_HTTP */ -- cgit v1.2.3