mirror of
https://github.com/curl/curl.git
synced 2025-01-18 14:04:30 +08:00
misc: reduce strlen() calls with Curl_dyn_add()
Use STRCONST() to switch from Curl_dyn_add() to Curl_dyn_addn() for string literals. Closes #8398
This commit is contained in:
parent
2a1951519e
commit
b807219292
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2022, 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
|
||||
@ -142,7 +142,7 @@ static int hyper_each_header(void *userdata,
|
||||
return HYPER_ITER_BREAK;
|
||||
}
|
||||
else {
|
||||
if(Curl_dyn_add(&data->state.headerb, "\r\n"))
|
||||
if(Curl_dyn_addn(&data->state.headerb, STRCONST("\r\n")))
|
||||
return HYPER_ITER_BREAK;
|
||||
}
|
||||
len = Curl_dyn_len(&data->state.headerb);
|
||||
|
@ -530,7 +530,7 @@ static DOHcode store_cname(const unsigned char *doh,
|
||||
|
||||
if(length) {
|
||||
if(Curl_dyn_len(c)) {
|
||||
if(Curl_dyn_add(c, "."))
|
||||
if(Curl_dyn_addn(c, STRCONST(".")))
|
||||
return DOH_OUT_OF_MEM;
|
||||
}
|
||||
if((index + length) > dohlen)
|
||||
|
34
lib/http.c
34
lib/http.c
@ -1540,7 +1540,7 @@ static CURLcode add_haproxy_protocol_header(struct Curl_easy *data)
|
||||
#ifdef USE_UNIX_SOCKETS
|
||||
if(data->conn->unix_domain_socket)
|
||||
/* the buffer is large enough to hold this! */
|
||||
result = Curl_dyn_add(&req, "PROXY UNKNOWN\r\n");
|
||||
result = Curl_dyn_addn(&req, STRCONST("PROXY UNKNOWN\r\n"));
|
||||
else {
|
||||
#endif
|
||||
/* Emit the correct prefix for IPv6 */
|
||||
@ -1713,7 +1713,7 @@ static CURLcode expect100(struct Curl_easy *data,
|
||||
Curl_compareheader(ptr, STRCONST("Expect:"), STRCONST("100-continue"));
|
||||
}
|
||||
else {
|
||||
result = Curl_dyn_add(req, "Expect: 100-continue\r\n");
|
||||
result = Curl_dyn_addn(req, STRCONST("Expect: 100-continue\r\n"));
|
||||
if(!result)
|
||||
data->state.expect100header = TRUE;
|
||||
}
|
||||
@ -2404,7 +2404,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
|
||||
}
|
||||
|
||||
/* end of headers */
|
||||
result = Curl_dyn_add(r, "\r\n");
|
||||
result = Curl_dyn_addn(r, STRCONST("\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
@ -2429,7 +2429,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
|
||||
/* This is form posting using mime data. */
|
||||
if(conn->bits.authneg) {
|
||||
/* nothing to post! */
|
||||
result = Curl_dyn_add(r, "Content-Length: 0\r\n\r\n");
|
||||
result = Curl_dyn_addn(r, STRCONST("Content-Length: 0\r\n\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
@ -2490,7 +2490,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
|
||||
data->state.expect100header = FALSE;
|
||||
|
||||
/* make the request end in a true CRLF */
|
||||
result = Curl_dyn_add(r, "\r\n");
|
||||
result = Curl_dyn_addn(r, STRCONST("\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
@ -2539,8 +2539,8 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
|
||||
}
|
||||
|
||||
if(!Curl_checkheaders(data, "Content-Type")) {
|
||||
result = Curl_dyn_add(r, "Content-Type: application/"
|
||||
"x-www-form-urlencoded\r\n");
|
||||
result = Curl_dyn_addn(r, STRCONST("Content-Type: application/"
|
||||
"x-www-form-urlencoded\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
@ -2579,7 +2579,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
|
||||
get the data duplicated with malloc() and family. */
|
||||
|
||||
/* end of headers! */
|
||||
result = Curl_dyn_add(r, "\r\n");
|
||||
result = Curl_dyn_addn(r, STRCONST("\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
@ -2601,12 +2601,12 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
|
||||
result = Curl_dyn_addn(r, data->set.postfields,
|
||||
(size_t)http->postsize);
|
||||
if(!result)
|
||||
result = Curl_dyn_add(r, "\r\n");
|
||||
result = Curl_dyn_addn(r, STRCONST("\r\n"));
|
||||
included_body += 2;
|
||||
}
|
||||
}
|
||||
if(!result) {
|
||||
result = Curl_dyn_add(r, "\x30\x0d\x0a\x0d\x0a");
|
||||
result = Curl_dyn_addn(r, STRCONST("\x30\x0d\x0a\x0d\x0a"));
|
||||
/* 0 CR LF CR LF */
|
||||
included_body += 5;
|
||||
}
|
||||
@ -2629,7 +2629,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
|
||||
Curl_pgrsSetUploadSize(data, http->postsize);
|
||||
|
||||
/* end of headers! */
|
||||
result = Curl_dyn_add(r, "\r\n");
|
||||
result = Curl_dyn_addn(r, STRCONST("\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
@ -2638,14 +2638,14 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
|
||||
#endif
|
||||
{
|
||||
/* end of headers! */
|
||||
result = Curl_dyn_add(r, "\r\n");
|
||||
result = Curl_dyn_addn(r, STRCONST("\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
if(data->req.upload_chunky && conn->bits.authneg) {
|
||||
/* Chunky upload is selected and we're negotiating auth still, send
|
||||
end-of-data only */
|
||||
result = Curl_dyn_add(r, (char *)"\x30\x0d\x0a\x0d\x0a");
|
||||
result = Curl_dyn_addn(r, (char *)STRCONST("\x30\x0d\x0a\x0d\x0a"));
|
||||
/* 0 CR LF CR LF */
|
||||
if(result)
|
||||
return result;
|
||||
@ -2673,7 +2673,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
|
||||
break;
|
||||
|
||||
default:
|
||||
result = Curl_dyn_add(r, "\r\n");
|
||||
result = Curl_dyn_addn(r, STRCONST("\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
@ -2723,7 +2723,7 @@ CURLcode Curl_http_cookies(struct Curl_easy *data,
|
||||
while(co) {
|
||||
if(co->value) {
|
||||
if(0 == count) {
|
||||
result = Curl_dyn_add(r, "Cookie: ");
|
||||
result = Curl_dyn_addn(r, STRCONST("Cookie: "));
|
||||
if(result)
|
||||
break;
|
||||
}
|
||||
@ -2739,14 +2739,14 @@ CURLcode Curl_http_cookies(struct Curl_easy *data,
|
||||
}
|
||||
if(addcookies && !result) {
|
||||
if(!count)
|
||||
result = Curl_dyn_add(r, "Cookie: ");
|
||||
result = Curl_dyn_addn(r, STRCONST("Cookie: "));
|
||||
if(!result) {
|
||||
result = Curl_dyn_addf(r, "%s%s", count?"; ":"", addcookies);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if(count && !result)
|
||||
result = Curl_dyn_add(r, "\r\n");
|
||||
result = Curl_dyn_addn(r, STRCONST("\r\n"));
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
|
10
lib/http2.c
10
lib/http2.c
@ -758,7 +758,7 @@ static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame,
|
||||
stream->status_code = -1;
|
||||
}
|
||||
|
||||
result = Curl_dyn_add(&stream->header_recvbuf, "\r\n");
|
||||
result = Curl_dyn_addn(&stream->header_recvbuf, STRCONST("\r\n"));
|
||||
if(result)
|
||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||
|
||||
@ -1081,14 +1081,14 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
|
||||
stream->status_code = decode_status_code(value, valuelen);
|
||||
DEBUGASSERT(stream->status_code != -1);
|
||||
|
||||
result = Curl_dyn_add(&stream->header_recvbuf, "HTTP/2 ");
|
||||
result = Curl_dyn_addn(&stream->header_recvbuf, STRCONST("HTTP/2 "));
|
||||
if(result)
|
||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||
result = Curl_dyn_addn(&stream->header_recvbuf, value, valuelen);
|
||||
if(result)
|
||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||
/* the space character after the status code is mandatory */
|
||||
result = Curl_dyn_add(&stream->header_recvbuf, " \r\n");
|
||||
result = Curl_dyn_addn(&stream->header_recvbuf, STRCONST(" \r\n"));
|
||||
if(result)
|
||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||
/* if we receive data for another handle, wake that up */
|
||||
@ -1106,13 +1106,13 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
|
||||
result = Curl_dyn_addn(&stream->header_recvbuf, name, namelen);
|
||||
if(result)
|
||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||
result = Curl_dyn_add(&stream->header_recvbuf, ": ");
|
||||
result = Curl_dyn_addn(&stream->header_recvbuf, STRCONST(": "));
|
||||
if(result)
|
||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||
result = Curl_dyn_addn(&stream->header_recvbuf, value, valuelen);
|
||||
if(result)
|
||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||
result = Curl_dyn_add(&stream->header_recvbuf, "\r\n");
|
||||
result = Curl_dyn_addn(&stream->header_recvbuf, STRCONST("\r\n"));
|
||||
if(result)
|
||||
return NGHTTP2_ERR_CALLBACK_FAILURE;
|
||||
/* if we receive data for another handle, wake that up */
|
||||
|
@ -214,7 +214,7 @@ CHUNKcode Curl_httpchunk_read(struct Curl_easy *data,
|
||||
|
||||
if(tr) {
|
||||
size_t trlen;
|
||||
result = Curl_dyn_add(&conn->trailer, (char *)"\x0d\x0a");
|
||||
result = Curl_dyn_addn(&conn->trailer, (char *)STRCONST("\x0d\x0a"));
|
||||
if(result)
|
||||
return CHUNKE_OUT_OF_MEMORY;
|
||||
|
||||
|
@ -329,14 +329,15 @@ static CURLcode CONNECT(struct Curl_easy *data,
|
||||
data->set.str[STRING_USERAGENT]);
|
||||
|
||||
if(!result && !Curl_checkProxyheaders(data, conn, "Proxy-Connection"))
|
||||
result = Curl_dyn_add(req, "Proxy-Connection: Keep-Alive\r\n");
|
||||
result = Curl_dyn_addn(req,
|
||||
STRCONST("Proxy-Connection: Keep-Alive\r\n"));
|
||||
|
||||
if(!result)
|
||||
result = Curl_add_custom_headers(data, TRUE, req);
|
||||
|
||||
if(!result)
|
||||
/* CRLF terminate the request */
|
||||
result = Curl_dyn_add(req, "\r\n");
|
||||
result = Curl_dyn_addn(req, STRCONST("\r\n"));
|
||||
|
||||
if(!result) {
|
||||
/* Send the connect request to the proxy */
|
||||
|
14
lib/rtsp.c
14
lib/rtsp.c
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2022, 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
|
||||
@ -535,8 +535,9 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
|
||||
if(rtspreq == RTSPREQ_SET_PARAMETER ||
|
||||
rtspreq == RTSPREQ_GET_PARAMETER) {
|
||||
if(!Curl_checkheaders(data, "Content-Type")) {
|
||||
result = Curl_dyn_addf(&req_buffer,
|
||||
"Content-Type: text/parameters\r\n");
|
||||
result = Curl_dyn_addn(&req_buffer,
|
||||
STRCONST("Content-Type: "
|
||||
"text/parameters\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
@ -544,8 +545,9 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
|
||||
|
||||
if(rtspreq == RTSPREQ_ANNOUNCE) {
|
||||
if(!Curl_checkheaders(data, "Content-Type")) {
|
||||
result = Curl_dyn_addf(&req_buffer,
|
||||
"Content-Type: application/sdp\r\n");
|
||||
result = Curl_dyn_addn(&req_buffer,
|
||||
STRCONST("Content-Type: "
|
||||
"application/sdp\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
@ -563,7 +565,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
|
||||
/* RTSP never allows chunked transfer */
|
||||
data->req.forbidchunk = TRUE;
|
||||
/* Finish the request buffer */
|
||||
result = Curl_dyn_add(&req_buffer, "\r\n");
|
||||
result = Curl_dyn_addn(&req_buffer, STRCONST("\r\n"));
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user