summaryrefslogtreecommitdiffstats
path: root/Utilities/cmcurl/lib/mime.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-04-28 19:20:13 (GMT)
committerBrad King <brad.king@kitware.com>2022-04-28 19:21:23 (GMT)
commit30aba1ce8cedec012cec9099217d4d83d7080a1c (patch)
treee920c2c714b2f0662de839b140797da3bdc7ff64 /Utilities/cmcurl/lib/mime.c
parent5239672e64a85ad400ef1bdb4a9118aff2da0c3f (diff)
parent2a9bc9ebf09fbafa5378d143083434204e9f233e (diff)
downloadCMake-30aba1ce8cedec012cec9099217d4d83d7080a1c.zip
CMake-30aba1ce8cedec012cec9099217d4d83d7080a1c.tar.gz
CMake-30aba1ce8cedec012cec9099217d4d83d7080a1c.tar.bz2
Merge branch 'upstream-curl' into update-curl
* upstream-curl: curl 2022-04-27 (1669b17d)
Diffstat (limited to 'Utilities/cmcurl/lib/mime.c')
-rw-r--r--Utilities/cmcurl/lib/mime.c125
1 files changed, 34 insertions, 91 deletions
diff --git a/Utilities/cmcurl/lib/mime.c b/Utilities/cmcurl/lib/mime.c
index 7783b89..d6985d3 100644
--- a/Utilities/cmcurl/lib/mime.c
+++ b/Utilities/cmcurl/lib/mime.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
@@ -25,7 +25,6 @@
#include <curl/curl.h>
#include "mime.h"
-#include "non-ascii.h"
#include "warnless.h"
#include "urldata.h"
#include "sendf.h"
@@ -315,7 +314,7 @@ static char *escape_string(struct Curl_easy *data,
Curl_dyn_init(&db, CURL_MAX_INPUT_LENGTH);
- for(result = Curl_dyn_add(&db, ""); !result && *src; src++) {
+ for(result = Curl_dyn_addn(&db, STRCONST("")); !result && *src; src++) {
for(p = table; *p && **p != *src; p++)
;
@@ -340,9 +339,9 @@ static char *match_header(struct curl_slist *hdr, const char *lbl, size_t len)
}
/* Get a header from an slist. */
-static char *search_header(struct curl_slist *hdrlist, const char *hdr)
+static char *search_header(struct curl_slist *hdrlist,
+ const char *hdr, size_t len)
{
- size_t len = strlen(hdr);
char *value = NULL;
for(; !value && hdrlist; hdrlist = hdrlist->next)
@@ -506,15 +505,6 @@ static size_t encoder_base64_read(char *buffer, size_t size, bool ateof,
}
}
-#ifdef CURL_DOES_CONVERSIONS
- /* This is now textual data, Convert character codes. */
- if(part->easy && cursize) {
- CURLcode result = Curl_convert_to_network(part->easy, buffer, cursize);
- if(result)
- return READ_ERROR;
- }
-#endif
-
return cursize;
}
@@ -768,7 +758,7 @@ static void mime_file_free(void *ptr)
static size_t readback_bytes(struct mime_state *state,
char *buffer, size_t bufsize,
const char *bytes, size_t numbytes,
- const char *trail)
+ const char *trail, size_t traillen)
{
size_t sz;
size_t offset = curlx_sotouz(state->offset);
@@ -778,13 +768,11 @@ static size_t readback_bytes(struct mime_state *state,
bytes += offset;
}
else {
- size_t tsz = strlen(trail);
-
sz = offset - numbytes;
- if(sz >= tsz)
+ if(sz >= traillen)
return 0;
bytes = trail + sz;
- sz = tsz - sz;
+ sz = traillen - sz;
}
if(sz > bufsize)
@@ -925,9 +913,6 @@ static size_t readback_part(curl_mimepart *part,
char *buffer, size_t bufsize, bool *hasread)
{
size_t cursize = 0;
-#ifdef CURL_DOES_CONVERSIONS
- char *convbuf = buffer;
-#endif
/* Readback from part. */
@@ -956,26 +941,18 @@ static size_t readback_part(curl_mimepart *part,
mimesetstate(&part->state, MIMESTATE_USERHEADERS, part->userheaders);
else {
sz = readback_bytes(&part->state, buffer, bufsize,
- hdr->data, strlen(hdr->data), "\r\n");
+ hdr->data, strlen(hdr->data), STRCONST("\r\n"));
if(!sz)
mimesetstate(&part->state, part->state.state, hdr->next);
}
break;
case MIMESTATE_EOH:
- sz = readback_bytes(&part->state, buffer, bufsize, "\r\n", 2, "");
+ sz = readback_bytes(&part->state, buffer, bufsize, STRCONST("\r\n"),
+ STRCONST(""));
if(!sz)
mimesetstate(&part->state, MIMESTATE_BODY, NULL);
break;
case MIMESTATE_BODY:
-#ifdef CURL_DOES_CONVERSIONS
- if(part->easy && convbuf < buffer) {
- CURLcode result = Curl_convert_to_network(part->easy, convbuf,
- buffer - convbuf);
- if(result)
- return READ_ERROR;
- convbuf = buffer;
- }
-#endif
cleanup_encoder_state(&part->encstate);
mimesetstate(&part->state, MIMESTATE_CONTENT, NULL);
break;
@@ -1012,16 +989,6 @@ static size_t readback_part(curl_mimepart *part,
bufsize -= sz;
}
-#ifdef CURL_DOES_CONVERSIONS
- if(part->easy && convbuf < buffer &&
- part->state.state < MIMESTATE_BODY) {
- CURLcode result = Curl_convert_to_network(part->easy, convbuf,
- buffer - convbuf);
- if(result)
- return READ_ERROR;
- }
-#endif
-
return cursize;
}
@@ -1031,10 +998,6 @@ static size_t mime_subparts_read(char *buffer, size_t size, size_t nitems,
{
curl_mime *mime = (curl_mime *) instream;
size_t cursize = 0;
-#ifdef CURL_DOES_CONVERSIONS
- char *convbuf = buffer;
-#endif
-
(void) size; /* Always 1. */
while(nitems) {
@@ -1043,9 +1006,6 @@ static size_t mime_subparts_read(char *buffer, size_t size, size_t nitems,
switch(mime->state.state) {
case MIMESTATE_BEGIN:
case MIMESTATE_BODY:
-#ifdef CURL_DOES_CONVERSIONS
- convbuf = buffer;
-#endif
mimesetstate(&mime->state, MIMESTATE_BOUNDARY1, mime->firstpart);
/* The first boundary always follows the header termination empty line,
so is always preceded by a CRLF. We can then spare 2 characters
@@ -1053,23 +1013,19 @@ static size_t mime_subparts_read(char *buffer, size_t size, size_t nitems,
mime->state.offset += 2;
break;
case MIMESTATE_BOUNDARY1:
- sz = readback_bytes(&mime->state, buffer, nitems, "\r\n--", 4, "");
+ sz = readback_bytes(&mime->state, buffer, nitems, STRCONST("\r\n--"),
+ STRCONST(""));
if(!sz)
mimesetstate(&mime->state, MIMESTATE_BOUNDARY2, part);
break;
case MIMESTATE_BOUNDARY2:
- sz = readback_bytes(&mime->state, buffer, nitems, mime->boundary,
- strlen(mime->boundary), part? "\r\n": "--\r\n");
+ if(part)
+ sz = readback_bytes(&mime->state, buffer, nitems, mime->boundary,
+ MIME_BOUNDARY_LEN, STRCONST("\r\n"));
+ else
+ sz = readback_bytes(&mime->state, buffer, nitems, mime->boundary,
+ MIME_BOUNDARY_LEN, STRCONST("--\r\n"));
if(!sz) {
-#ifdef CURL_DOES_CONVERSIONS
- if(mime->easy && convbuf < buffer) {
- CURLcode result = Curl_convert_to_network(mime->easy, convbuf,
- buffer - convbuf);
- if(result)
- return READ_ERROR;
- convbuf = buffer;
- }
-#endif
mimesetstate(&mime->state, MIMESTATE_CONTENT, part);
}
break;
@@ -1086,9 +1042,6 @@ static size_t mime_subparts_read(char *buffer, size_t size, size_t nitems,
case STOP_FILLING:
return cursize? cursize: sz;
case 0:
-#ifdef CURL_DOES_CONVERSIONS
- convbuf = buffer;
-#endif
mimesetstate(&mime->state, MIMESTATE_BOUNDARY1, part->nextpart);
break;
}
@@ -1105,16 +1058,6 @@ static size_t mime_subparts_read(char *buffer, size_t size, size_t nitems,
nitems -= sz;
}
-#ifdef CURL_DOES_CONVERSIONS
- if(mime->easy && convbuf < buffer &&
- mime->state.state <= MIMESTATE_CONTENT) {
- CURLcode result = Curl_convert_to_network(mime->easy, convbuf,
- buffer - convbuf);
- if(result)
- return READ_ERROR;
- }
-#endif
-
return cursize;
}
@@ -1341,8 +1284,9 @@ curl_mime *curl_mime_init(struct Curl_easy *easy)
mime->firstpart = NULL;
mime->lastpart = NULL;
- memset(mime->boundary, '-', 24);
- if(Curl_rand_hex(easy, (unsigned char *) &mime->boundary[24],
+ memset(mime->boundary, '-', MIME_BOUNDARY_DASHES);
+ if(Curl_rand_hex(easy,
+ (unsigned char *) &mime->boundary[MIME_BOUNDARY_DASHES],
MIME_RAND_BOUNDARY_CHARS + 1)) {
/* failed to get random separator, bail out */
free(mime);
@@ -1619,7 +1563,7 @@ CURLcode Curl_mime_set_subparts(curl_mimepart *part,
root = root->parent->parent;
if(subparts == root) {
if(part->easy)
- failf(part->easy, "Can't add itself as a subpart!");
+ failf(part->easy, "Can't add itself as a subpart");
return CURLE_BAD_FUNCTION_ARGUMENT;
}
}
@@ -1675,10 +1619,9 @@ CURLcode Curl_mime_rewind(curl_mimepart *part)
/* Compute header list size. */
static size_t slist_size(struct curl_slist *s,
- size_t overhead, const char *skip)
+ size_t overhead, const char *skip, size_t skiplen)
{
size_t size = 0;
- size_t skiplen = skip? strlen(skip): 0;
for(; s; s = s->next)
if(!skip || !match_header(s, skip, skiplen))
@@ -1696,7 +1639,7 @@ static curl_off_t multipart_size(curl_mime *mime)
if(!mime)
return 0; /* Not present -> empty. */
- boundarysize = 4 + strlen(mime->boundary) + 2;
+ boundarysize = 4 + MIME_BOUNDARY_LEN + 2;
size = boundarysize; /* Final boundary - CRLF after headers. */
for(part = mime->firstpart; part; part = part->nextpart) {
@@ -1727,8 +1670,8 @@ curl_off_t Curl_mime_size(curl_mimepart *part)
if(size >= 0 && !(part->flags & MIME_BODY_ONLY)) {
/* Compute total part size. */
- size += slist_size(part->curlheaders, 2, NULL);
- size += slist_size(part->userheaders, 2, "Content-Type");
+ size += slist_size(part->curlheaders, 2, NULL, 0);
+ size += slist_size(part->userheaders, 2, STRCONST("Content-Type"));
size += 2; /* CRLF after headers. */
}
return size;
@@ -1804,10 +1747,9 @@ const char *Curl_mime_contenttype(const char *filename)
return NULL;
}
-static bool content_type_match(const char *contenttype, const char *target)
+static bool content_type_match(const char *contenttype,
+ const char *target, size_t len)
{
- size_t len = strlen(target);
-
if(contenttype && strncasecompare(contenttype, target, len))
switch(contenttype[len]) {
case '\0':
@@ -1843,7 +1785,7 @@ CURLcode Curl_mime_prepare_headers(curl_mimepart *part,
/* Check if content type is specified. */
customct = part->mimetype;
if(!customct)
- customct = search_header(part->userheaders, "Content-Type");
+ customct = search_header(part->userheaders, STRCONST("Content-Type"));
if(customct)
contenttype = customct;
@@ -1872,12 +1814,12 @@ CURLcode Curl_mime_prepare_headers(curl_mimepart *part,
boundary = mime->boundary;
}
else if(contenttype && !customct &&
- content_type_match(contenttype, "text/plain"))
+ content_type_match(contenttype, STRCONST("text/plain")))
if(strategy == MIMESTRATEGY_MAIL || !part->filename)
contenttype = NULL;
/* Issue content-disposition header only if not already set by caller. */
- if(!search_header(part->userheaders, "Content-Disposition")) {
+ if(!search_header(part->userheaders, STRCONST("Content-Disposition"))) {
if(!disposition)
if(part->filename || part->name ||
(contenttype && !strncasecompare(contenttype, "multipart/", 10)))
@@ -1924,7 +1866,8 @@ CURLcode Curl_mime_prepare_headers(curl_mimepart *part,
}
/* Content-Transfer-Encoding header. */
- if(!search_header(part->userheaders, "Content-Transfer-Encoding")) {
+ if(!search_header(part->userheaders,
+ STRCONST("Content-Transfer-Encoding"))) {
if(part->encoder)
cte = part->encoder->name;
else if(contenttype && strategy == MIMESTRATEGY_MAIL &&
@@ -1948,7 +1891,7 @@ CURLcode Curl_mime_prepare_headers(curl_mimepart *part,
curl_mimepart *subpart;
disposition = NULL;
- if(content_type_match(contenttype, "multipart/form-data"))
+ if(content_type_match(contenttype, STRCONST("multipart/form-data")))
disposition = "form-data";
for(subpart = mime->firstpart; subpart; subpart = subpart->nextpart) {
ret = Curl_mime_prepare_headers(subpart, NULL, disposition, strategy);