mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
mime: use size_t instead of ssize_t in public API interface.
To support telling a string is nul-terminated, symbol CURL_ZERO_TERMINATED has been introduced. Documentation updated accordingly. symbols in versions updated. Added form API symbols deprecation info.
This commit is contained in:
parent
1a3f4c1991
commit
efd9301426
@ -26,15 +26,16 @@ curl_mime_data - set a mime part's body data from memory
|
||||
.B #include <curl/curl.h>
|
||||
.sp
|
||||
.BI "CURLcode curl_mime_data(curl_mimepart * " part ", const char * " data
|
||||
.BI ", ssize_t " datasize ");"
|
||||
.BI ", size_t " datasize ");"
|
||||
.ad
|
||||
.SH DESCRIPTION
|
||||
curl_mime_data() sets a mime part's body content from memory data.
|
||||
|
||||
\fIdata\fP points to the data bytes: those are copied to the part and their
|
||||
storage may safely be reused after call.
|
||||
\fIdatasize\fP is the number of data bytes: it can be set to -1 to indicate
|
||||
\fIdata\fP is a nul-terminated character string.
|
||||
\fIdatasize\fP is the number of data bytes: it can be set to
|
||||
\fICURL_ZERO_TERMINATED\fP to indicate \fIdata\fP is a nul-terminated
|
||||
character string.
|
||||
\fIpart\fP is the part's to assign contents to.
|
||||
|
||||
Setting a part's contents twice is valid: only the value set by the last call
|
||||
|
@ -26,7 +26,7 @@ curl_mime_name - set a mime part's name
|
||||
.B #include <curl/curl.h>
|
||||
.sp
|
||||
.BI "CURLcode curl_mime_name(curl_mimepart * " part ", const char * " name
|
||||
.BI ", ssize_t " namesize ");"
|
||||
.BI ", size_t " namesize ");"
|
||||
.ad
|
||||
.SH DESCRIPTION
|
||||
curl_mime_name() sets a mime part's name. This is the way HTTP form fields are
|
||||
@ -34,8 +34,8 @@ named.
|
||||
|
||||
\fIname\fP points to the name byte string; the string may contain nul bytes
|
||||
unless \fInamesize\fP is -1.
|
||||
\fInamesize\fP is the name length: it can be set to -1 to indicate
|
||||
\fIname\fP is a nul-terminated string.
|
||||
\fInamesize\fP is the name length: it can be set to \fICURL_ZERO_TERMINATED\fP
|
||||
to indicate \fIname\fP is a nul-terminated string.
|
||||
\fIpart\fP is the part's handle to assign a name to.
|
||||
|
||||
The name string is copied into the part, thus the associated storage may safely
|
||||
|
@ -160,27 +160,27 @@ CURLFINFOFLAG_KNOWN_PERM 7.21.0
|
||||
CURLFINFOFLAG_KNOWN_SIZE 7.21.0
|
||||
CURLFINFOFLAG_KNOWN_TIME 7.21.0
|
||||
CURLFINFOFLAG_KNOWN_UID 7.21.0
|
||||
CURLFORM_ARRAY 7.9.1
|
||||
CURLFORM_ARRAY 7.9.1 7.56.0
|
||||
CURLFORM_ARRAY_END 7.9.1 7.9.5 7.9.6
|
||||
CURLFORM_ARRAY_START 7.9.1 7.9.5 7.9.6
|
||||
CURLFORM_BUFFER 7.9.8
|
||||
CURLFORM_BUFFERLENGTH 7.9.8
|
||||
CURLFORM_BUFFERPTR 7.9.8
|
||||
CURLFORM_CONTENTHEADER 7.9.3
|
||||
CURLFORM_CONTENTLEN 7.46.0
|
||||
CURLFORM_CONTENTSLENGTH 7.9
|
||||
CURLFORM_CONTENTTYPE 7.9
|
||||
CURLFORM_COPYCONTENTS 7.9
|
||||
CURLFORM_COPYNAME 7.9
|
||||
CURLFORM_END 7.9
|
||||
CURLFORM_FILE 7.9
|
||||
CURLFORM_FILECONTENT 7.9.1
|
||||
CURLFORM_FILENAME 7.9.6
|
||||
CURLFORM_NAMELENGTH 7.9
|
||||
CURLFORM_NOTHING 7.9
|
||||
CURLFORM_PTRCONTENTS 7.9
|
||||
CURLFORM_PTRNAME 7.9
|
||||
CURLFORM_STREAM 7.18.2
|
||||
CURLFORM_BUFFER 7.9.8 7.56.0
|
||||
CURLFORM_BUFFERLENGTH 7.9.8 7.56.0
|
||||
CURLFORM_BUFFERPTR 7.9.8 7.56.0
|
||||
CURLFORM_CONTENTHEADER 7.9.3 7.56.0
|
||||
CURLFORM_CONTENTLEN 7.46.0 7.56.0
|
||||
CURLFORM_CONTENTSLENGTH 7.9 7.56.0
|
||||
CURLFORM_CONTENTTYPE 7.9 7.56.0
|
||||
CURLFORM_COPYCONTENTS 7.9 7.56.0
|
||||
CURLFORM_COPYNAME 7.9 7.56.0
|
||||
CURLFORM_END 7.9 7.56.0
|
||||
CURLFORM_FILE 7.9 7.56.0
|
||||
CURLFORM_FILECONTENT 7.9.1 7.56.0
|
||||
CURLFORM_FILENAME 7.9.6 7.56.0
|
||||
CURLFORM_NAMELENGTH 7.9 7.56.0
|
||||
CURLFORM_NOTHING 7.9 7.56.0
|
||||
CURLFORM_PTRCONTENTS 7.9 7.56.0
|
||||
CURLFORM_PTRNAME 7.9 7.56.0
|
||||
CURLFORM_STREAM 7.18.2 7.56.0
|
||||
CURLFTPAUTH_DEFAULT 7.12.2
|
||||
CURLFTPAUTH_SSL 7.12.2
|
||||
CURLFTPAUTH_TLS 7.12.2
|
||||
@ -406,7 +406,7 @@ CURLOPT_HTTP200ALIASES 7.10.3
|
||||
CURLOPT_HTTPAUTH 7.10.6
|
||||
CURLOPT_HTTPGET 7.8.1
|
||||
CURLOPT_HTTPHEADER 7.1
|
||||
CURLOPT_HTTPPOST 7.1
|
||||
CURLOPT_HTTPPOST 7.1 7.56.0
|
||||
CURLOPT_HTTPPROXYTUNNEL 7.3
|
||||
CURLOPT_HTTPREQUEST 7.1 - 7.15.5
|
||||
CURLOPT_HTTP_CONTENT_DECODING 7.16.2
|
||||
@ -718,14 +718,14 @@ CURL_ERROR_SIZE 7.1
|
||||
CURL_FNMATCHFUNC_FAIL 7.21.0
|
||||
CURL_FNMATCHFUNC_MATCH 7.21.0
|
||||
CURL_FNMATCHFUNC_NOMATCH 7.21.0
|
||||
CURL_FORMADD_DISABLED 7.12.1
|
||||
CURL_FORMADD_ILLEGAL_ARRAY 7.9.8
|
||||
CURL_FORMADD_INCOMPLETE 7.9.8
|
||||
CURL_FORMADD_MEMORY 7.9.8
|
||||
CURL_FORMADD_NULL 7.9.8
|
||||
CURL_FORMADD_OK 7.9.8
|
||||
CURL_FORMADD_OPTION_TWICE 7.9.8
|
||||
CURL_FORMADD_UNKNOWN_OPTION 7.9.8
|
||||
CURL_FORMADD_DISABLED 7.12.1 7.56.0
|
||||
CURL_FORMADD_ILLEGAL_ARRAY 7.9.8 7.56.0
|
||||
CURL_FORMADD_INCOMPLETE 7.9.8 7.56.0
|
||||
CURL_FORMADD_MEMORY 7.9.8 7.56.0
|
||||
CURL_FORMADD_NULL 7.9.8 7.56.0
|
||||
CURL_FORMADD_OK 7.9.8 7.56.0
|
||||
CURL_FORMADD_OPTION_TWICE 7.9.8 7.56.0
|
||||
CURL_FORMADD_UNKNOWN_OPTION 7.9.8 7.56.0
|
||||
CURL_GLOBAL_ACK_EINTR 7.30.0
|
||||
CURL_GLOBAL_ALL 7.8
|
||||
CURL_GLOBAL_DEFAULT 7.8
|
||||
@ -854,3 +854,4 @@ CURL_WAIT_POLLIN 7.28.0
|
||||
CURL_WAIT_POLLOUT 7.28.0
|
||||
CURL_WAIT_POLLPRI 7.28.0
|
||||
CURL_WRITEFUNC_PAUSE 7.18.0
|
||||
CURL_ZERO_TERMINATED 7.56.0
|
||||
|
@ -1940,6 +1940,8 @@ typedef enum {
|
||||
CURL_TIMECOND_LAST
|
||||
} curl_TimeCond;
|
||||
|
||||
/* Special size_t value signaling a zero-terminated string. */
|
||||
#define CURL_ZERO_TERMINATED ((size_t) -1)
|
||||
|
||||
/* curl_strequal() and curl_strnequal() are subject for removal in a future
|
||||
libcurl, see lib/README.curlx for details
|
||||
@ -1990,7 +1992,7 @@ CURL_EXTERN curl_mimepart *curl_mime_addpart(curl_mime *mime);
|
||||
* Set mime/form part name.
|
||||
*/
|
||||
CURL_EXTERN CURLcode curl_mime_name(curl_mimepart *part,
|
||||
const char *name, ssize_t namesize);
|
||||
const char *name, size_t namesize);
|
||||
|
||||
/*
|
||||
* NAME curl_mime_filename()
|
||||
@ -2029,7 +2031,7 @@ CURL_EXTERN CURLcode curl_mime_encoder(struct Curl_mimepart *part,
|
||||
* Set mime part data source from memory data,
|
||||
*/
|
||||
CURL_EXTERN CURLcode curl_mime_data(curl_mimepart *part,
|
||||
const char *data, ssize_t datasize);
|
||||
const char *data, size_t datasize);
|
||||
|
||||
/*
|
||||
* NAME curl_mime_filedata()
|
||||
|
20
lib/mime.c
20
lib/mime.c
@ -209,13 +209,15 @@ static void mimesetstate(struct mime_state *state,
|
||||
|
||||
|
||||
/* Escape header string into allocated memory. */
|
||||
static char *escape_string(const char *src, ssize_t srclen)
|
||||
static char *escape_string(const char *src, size_t len)
|
||||
{
|
||||
size_t len = srclen >= 0? (size_t) srclen: strlen(src);
|
||||
size_t bytecount;
|
||||
size_t i;
|
||||
char *dst;
|
||||
|
||||
if(len == CURL_ZERO_TERMINATED)
|
||||
len = strlen(src);
|
||||
|
||||
bytecount = len;
|
||||
for(i = 0; i < len; i++)
|
||||
if(src[i] == '"' || src[i] == '\\' || !src[i])
|
||||
@ -801,7 +803,7 @@ struct Curl_mimepart *curl_mime_addpart(struct Curl_mime *mime)
|
||||
|
||||
/* Set mime part name. */
|
||||
CURLcode curl_mime_name(struct Curl_mimepart *part,
|
||||
const char *name, ssize_t namesize)
|
||||
const char *name, size_t namesize)
|
||||
{
|
||||
if(!part)
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
@ -811,7 +813,7 @@ CURLcode curl_mime_name(struct Curl_mimepart *part,
|
||||
part->namesize = 0;
|
||||
|
||||
if(name) {
|
||||
if(namesize < 0)
|
||||
if(namesize == CURL_ZERO_TERMINATED)
|
||||
namesize = strlen(name);
|
||||
part->name = malloc(namesize + 1);
|
||||
if(!part->name)
|
||||
@ -845,7 +847,7 @@ CURLcode curl_mime_filename(struct Curl_mimepart *part, const char *filename)
|
||||
|
||||
/* Set mime part content from memory data. */
|
||||
CURLcode curl_mime_data(struct Curl_mimepart *part,
|
||||
const char *data, ssize_t datasize)
|
||||
const char *data, size_t datasize)
|
||||
{
|
||||
if(!part)
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
@ -853,7 +855,7 @@ CURLcode curl_mime_data(struct Curl_mimepart *part,
|
||||
cleanup_part_content(part);
|
||||
|
||||
if(data) {
|
||||
if(datasize < 0)
|
||||
if(datasize == CURL_ZERO_TERMINATED)
|
||||
datasize = strlen(data);
|
||||
|
||||
part->data = malloc(datasize + 1);
|
||||
@ -1284,7 +1286,7 @@ CURLcode Curl_mime_prepare_headers(struct Curl_mimepart *part,
|
||||
ret = CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
if(!ret && part->filename) {
|
||||
filename = escape_string(part->filename, -1);
|
||||
filename = escape_string(part->filename, CURL_ZERO_TERMINATED);
|
||||
if(!filename)
|
||||
ret = CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
@ -1364,7 +1366,7 @@ curl_mimepart *curl_mime_addpart(curl_mime *mime)
|
||||
}
|
||||
|
||||
CURLcode curl_mime_name(curl_mimepart *part,
|
||||
const char *name, ssize_t namesize)
|
||||
const char *name, size_t namesize)
|
||||
{
|
||||
(void) part;
|
||||
(void) name;
|
||||
@ -1394,7 +1396,7 @@ CURLcode curl_mime_encoder(struct Curl_mimepart *part, const char *encoding)
|
||||
}
|
||||
|
||||
CURLcode curl_mime_data(curl_mimepart *part,
|
||||
const char *data, ssize_t datasize)
|
||||
const char *data, size_t datasize)
|
||||
{
|
||||
(void) part;
|
||||
(void) data;
|
||||
|
@ -210,12 +210,14 @@ static const NameValue setopt_nv_CURLNONZERODEFAULTS[] = {
|
||||
|
||||
/* Escape string to C string syntax. Return NULL if out of memory.
|
||||
* Is this correct for those wacky EBCDIC guys? */
|
||||
static char *c_escape(const char *str, ssize_t plen)
|
||||
static char *c_escape(const char *str, size_t len)
|
||||
{
|
||||
const char *s;
|
||||
unsigned char c;
|
||||
char *escaped, *e;
|
||||
size_t len = plen == -1? strlen(str): (size_t) plen;
|
||||
|
||||
if(len == CURL_ZERO_TERMINATED)
|
||||
len = strlen(str);
|
||||
|
||||
/* Check for possible overflow. */
|
||||
if(len > (~(size_t) 0) / 4)
|
||||
@ -392,7 +394,7 @@ static CURLcode libcurl_generate_slist(struct curl_slist *slist, int *slistno)
|
||||
CLEAN1("slist%d = NULL;", *slistno);
|
||||
for(; slist; slist = slist->next) {
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(slist->data, -1);
|
||||
escaped = c_escape(slist->data, CURL_ZERO_TERMINATED);
|
||||
if(!escaped)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
DATA3("slist%d = curl_slist_append(slist%d, \"%s\");",
|
||||
@ -432,7 +434,7 @@ static CURLcode libcurl_generate_mime(curl_mime *mime, int *mimeno)
|
||||
switch(part->kind) {
|
||||
case MIMEKIND_NAMEDFILE:
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(part->data, -1);
|
||||
escaped = c_escape(part->data, CURL_ZERO_TERMINATED);
|
||||
if(!escaped)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
CODE2("curl_mime_filedata(part%d, \"%s\");", *mimeno, escaped);
|
||||
@ -480,7 +482,7 @@ static CURLcode libcurl_generate_mime(curl_mime *mime, int *mimeno)
|
||||
;
|
||||
size = (cp == data + part->datasize)? (curl_off_t) -1: part->datasize;
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(data, (ssize_t) part->datasize);
|
||||
escaped = c_escape(data, (size_t) part->datasize);
|
||||
if(data != part->data)
|
||||
Curl_safefree(data);
|
||||
if(!escaped)
|
||||
@ -502,7 +504,7 @@ static CURLcode libcurl_generate_mime(curl_mime *mime, int *mimeno)
|
||||
|
||||
if(filename) {
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(filename, -1);
|
||||
escaped = c_escape(filename, CURL_ZERO_TERMINATED);
|
||||
if(!escaped)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
CODE2("curl_mime_filename(part%d, \"%s\");", *mimeno, escaped);
|
||||
@ -523,7 +525,7 @@ static CURLcode libcurl_generate_mime(curl_mime *mime, int *mimeno)
|
||||
|
||||
if(part->mimetype) {
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(part->mimetype, -1);
|
||||
escaped = c_escape(part->mimetype, CURL_ZERO_TERMINATED);
|
||||
if(!escaped)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
CODE2("curl_mime_type(part%d, \"%s\");", *mimeno, escaped);
|
||||
@ -674,7 +676,7 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *config,
|
||||
REM2("%s set to a %s", name, value);
|
||||
else {
|
||||
if(escape) {
|
||||
escaped = c_escape(value, -1);
|
||||
escaped = c_escape(value, CURL_ZERO_TERMINATED);
|
||||
if(!escaped) {
|
||||
ret = CURLE_OUT_OF_MEMORY;
|
||||
goto nomem;
|
||||
|
Loading…
Reference in New Issue
Block a user