* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2013, 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
#include "curl.h"
#include "mprintf.h"
+#include "slist.h"
#include "urldata.h"
#include "url.h"
#include "getinfo.h"
ccsid &= 0xFFFF;
- if (ccsid == NOCONV_CCSID)
+ if(ccsid == NOCONV_CCSID)
ccsid = ASCII_CCSID;
memset(buf, 0, ICONV_ID_SIZE);
makeOS400IconvCode(tocode, ccsidout);
memset(tocode + 13, 0, sizeof tocode - 13); /* Dest. code id format. */
- if (cstr)
+ if(cstr)
fromcode[18] = '1'; /* Set null-terminator flag. */
return iconv_open(tocode, fromcode);
*** Return the converted destination byte count, or -1 if error.
**/
- if (sccsid == 65535)
+ if(sccsid == 65535)
sccsid = ASCII_CCSID;
- if (dccsid == 65535)
+ if(dccsid == 65535)
dccsid = ASCII_CCSID;
- if (sccsid == dccsid) {
+ if(sccsid == dccsid) {
lslen = slen >= 0? slen: strlen(s) + 1;
i = lslen < dlen? lslen: dlen;
- if (s != d && i > 0)
+ if(s != d && i > 0)
memcpy(d, s, i);
return i;
}
- if (slen < 0) {
+ if(slen < 0) {
lslen = 0;
cd = iconv_open_CCSID(dccsid, sccsid, 1);
}
cd = iconv_open_CCSID(dccsid, sccsid, 0);
}
- if (ICONV_OPEN_ERROR(cd))
+ if(ICONV_OPEN_ERROR(cd))
return -1;
i = dlen;
- if ((int) iconv(cd, (char * *) &s, &lslen, &d, &dlen) < 0)
+ if((int) iconv(cd, (char * *) &s, &lslen, &d, &dlen) < 0)
i = -1;
else
i -= dlen;
dlen *= MAX_CONV_EXPANSION; /* Allow some expansion. */
d = malloc(dlen);
- if (!d)
+ if(!d)
return (char *) NULL;
l = convert(d, dlen, dccsid, s, slen, sccsid);
- if (l < 0) {
+ if(l < 0) {
free(d);
return (char *) NULL;
}
- if (slen < 0) {
+ if(slen < 0) {
/* Need to null-terminate even when source length is given.
Since destination code size is unknown, use a conversion to generate
terminator. */
l2 = convert(d + l, dlen - l, dccsid, &nullbyte, -1, ASCII_CCSID);
- if (l2 < 0) {
+ if(l2 < 0) {
free(d);
return (char *) NULL;
}
l += l2;
}
- if ((size_t) l < dlen) {
+ if((size_t) l < dlen) {
cp = realloc(d, l); /* Shorten to minimum needed. */
- if (cp)
+ if(cp)
d = cp;
}
}
+static struct curl_slist *
+slist_convert(int dccsid, struct curl_slist * from, int sccsid)
+
+{
+ struct curl_slist * to = (struct curl_slist *) NULL;
+ char * cp;
+
+ for (; from; from = from->next) {
+ if(!(cp = dynconvert(dccsid, from->data, -1, sccsid))) {
+ curl_slist_free_all(to);
+ return (struct curl_slist *) NULL;
+ }
+ to = Curl_slist_append_nodup(to, cp);
+ }
+ return to;
+}
+
+
char *
curl_version_ccsid(unsigned int ccsid)
aversion = curl_version();
- if (!aversion)
+ if(!aversion)
return aversion;
i = strlen(aversion) + 1;
i *= MAX_CONV_EXPANSION;
- if (!(eversion = Curl_thread_buffer(LK_CURL_VERSION, i)))
+ if(!(eversion = Curl_thread_buffer(LK_CURL_VERSION, i)))
return (char *) NULL;
- if (convert(eversion, i, ccsid, aversion, -1, ASCII_CCSID) < 0)
+ if(convert(eversion, i, ccsid, aversion, -1, ASCII_CCSID) < 0)
return (char *) NULL;
return eversion;
char * s;
char * d;
- if (!string) {
+ if(!string) {
errno = EINVAL;
return (char *) NULL;
}
s = dynconvert(ASCII_CCSID, s, length? length: -1, sccsid);
- if (!s)
+ if(!s)
return (char *) NULL;
d = curl_easy_escape(handle, s, 0);
free(s);
- if (!d)
+ if(!d)
return (char *) NULL;
s = dynconvert(dccsid, d, -1, ASCII_CCSID);
char * s;
char * d;
- if (!string) {
+ if(!string) {
errno = EINVAL;
return (char *) NULL;
}
s = dynconvert(ASCII_CCSID, s, length? length: -1, sccsid);
- if (!s)
+ if(!s)
return (char *) NULL;
d = curl_easy_unescape(handle, s, 0, outlength);
free(s);
- if (!d)
+ if(!d)
return (char *) NULL;
s = dynconvert(dccsid, d, -1, ASCII_CCSID);
free(d);
- if (s && outlength)
+ if(s && outlength)
*outlength = strlen(s);
return s;
s = (char *) NULL;
- if (!data)
+ if(!data)
return curl_slist_append(list, data);
s = dynconvert(ASCII_CCSID, data, -1, ccsid);
- if (!s)
+ if(!s)
return (struct curl_slist *) NULL;
list = curl_slist_append(list, s);
char * s;
time_t t;
- if (!p)
+ if(!p)
return curl_getdate(p, unused);
s = dynconvert(ASCII_CCSID, p, -1, ccsid);
- if (!s)
+ if(!s)
return (time_t) -1;
t = curl_getdate(s, unused);
`*bufp' and `*left' are updated accordingly.
Return 0 if ok, else -1. */
- if (*stringp) {
+ if(*stringp) {
l = convert(*bufp, *left, ccsid, *stringp, -1, ASCII_CCSID);
- if (l <= 0)
+ if(l <= 0)
return -1;
*stringp = *bufp;
/* If caller has been compiled with a new version, error. */
- if (stamp > CURLVERSION_NOW)
+ if(stamp > CURLVERSION_NOW)
return (curl_version_info_data *) NULL;
p = curl_version_info(stamp);
- if (!p)
+ if(!p)
return p;
/* Measure thread space needed. */
n = 0;
nproto = 0;
- if (p->protocols) {
+ if(p->protocols) {
while (p->protocols[nproto])
n += strlen(p->protocols[nproto++]);
n += nproto++;
}
- if (p->version)
+ if(p->version)
n += strlen(p->version) + 1;
- if (p->host)
+ if(p->host)
n += strlen(p->host) + 1;
- if (p->ssl_version)
+ if(p->ssl_version)
n += strlen(p->ssl_version) + 1;
- if (p->libz_version)
+ if(p->libz_version)
n += strlen(p->libz_version) + 1;
- if (p->ares)
+ if(p->ares)
n += strlen(p->ares) + 1;
- if (p->libidn)
+ if(p->libidn)
n += strlen(p->libidn) + 1;
- if (p->libssh_version)
+ if(p->libssh_version)
n += strlen(p->libssh_version) + 1;
/* Allocate thread space. */
n *= MAX_CONV_EXPANSION;
- if (nproto)
+ if(nproto)
n += nproto * sizeof(const char *);
cp = Curl_thread_buffer(LK_VERSION_INFO_DATA, n);
id = (curl_version_info_data *) Curl_thread_buffer(LK_VERSION_INFO,
sizeof *id);
- if (!id || !cp)
+ if(!id || !cp)
return (curl_version_info_data *) NULL;
/* Copy data and convert strings. */
memcpy((char *) id, (char *) p, sizeof *p);
- if (id->protocols) {
+ if(id->protocols) {
id->protocols = (const char * const *) cp;
i = nproto * sizeof id->protocols[0];
memcpy(cp, (char *) p->protocols, i);
n -= i;
for (i = 0; id->protocols[i]; i++)
- if (convert_version_info_string(((const char * *) id->protocols) + i,
+ if(convert_version_info_string(((const char * *) id->protocols) + i,
&cp, &n, ccsid))
return (curl_version_info_data *) NULL;
}
- if (convert_version_info_string(&id->version, &cp, &n, ccsid))
+ if(convert_version_info_string(&id->version, &cp, &n, ccsid))
return (curl_version_info_data *) NULL;
- if (convert_version_info_string(&id->host, &cp, &n, ccsid))
+ if(convert_version_info_string(&id->host, &cp, &n, ccsid))
return (curl_version_info_data *) NULL;
- if (convert_version_info_string(&id->ssl_version, &cp, &n, ccsid))
+ if(convert_version_info_string(&id->ssl_version, &cp, &n, ccsid))
return (curl_version_info_data *) NULL;
- if (convert_version_info_string(&id->libz_version, &cp, &n, ccsid))
+ if(convert_version_info_string(&id->libz_version, &cp, &n, ccsid))
return (curl_version_info_data *) NULL;
- if (convert_version_info_string(&id->ares, &cp, &n, ccsid))
+ if(convert_version_info_string(&id->ares, &cp, &n, ccsid))
return (curl_version_info_data *) NULL;
- if (convert_version_info_string(&id->libidn, &cp, &n, ccsid))
+ if(convert_version_info_string(&id->libidn, &cp, &n, ccsid))
return (curl_version_info_data *) NULL;
- if (convert_version_info_string(&id->libssh_version, &cp, &n, ccsid))
+ if(convert_version_info_string(&id->libssh_version, &cp, &n, ccsid))
return (curl_version_info_data *) NULL;
return id;
s = curl_easy_strerror(error);
- if (!s)
+ if(!s)
return s;
i = MAX_CONV_EXPANSION * (strlen(s) + 1);
- if (!(buf = Curl_thread_buffer(LK_EASY_STRERROR, i)))
+ if(!(buf = Curl_thread_buffer(LK_EASY_STRERROR, i)))
return (const char *) NULL;
- if (convert(buf, i, ccsid, s, -1, ASCII_CCSID) < 0)
+ if(convert(buf, i, ccsid, s, -1, ASCII_CCSID) < 0)
return (const char *) NULL;
return (const char *) buf;
s = curl_share_strerror(error);
- if (!s)
+ if(!s)
return s;
i = MAX_CONV_EXPANSION * (strlen(s) + 1);
- if (!(buf = Curl_thread_buffer(LK_SHARE_STRERROR, i)))
+ if(!(buf = Curl_thread_buffer(LK_SHARE_STRERROR, i)))
return (const char *) NULL;
- if (convert(buf, i, ccsid, s, -1, ASCII_CCSID) < 0)
+ if(convert(buf, i, ccsid, s, -1, ASCII_CCSID) < 0)
return (const char *) NULL;
return (const char *) buf;
s = curl_multi_strerror(error);
- if (!s)
+ if(!s)
return s;
i = MAX_CONV_EXPANSION * (strlen(s) + 1);
- if (!(buf = Curl_thread_buffer(LK_MULTI_STRERROR, i)))
+ if(!(buf = Curl_thread_buffer(LK_MULTI_STRERROR, i)))
return (const char *) NULL;
- if (convert(buf, i, ccsid, s, -1, ASCII_CCSID) < 0)
+ if(convert(buf, i, ccsid, s, -1, ASCII_CCSID) < 0)
return (const char *) NULL;
return (const char *) buf;
}
+void
+curl_certinfo_free_all(struct curl_certinfo *info)
+
+{
+ int i;
+
+ /* Free all memory used by certificate info. */
+ if(info) {
+ if(info->certinfo) {
+ for (i = 0; i < info->num_of_certs; i++)
+ curl_slist_free_all(info->certinfo[i]);
+ free((char *) info->certinfo);
+ }
+ free((char *) info);
+ }
+}
+
+
CURLcode
curl_easy_getinfo_ccsid(CURL * curl, CURLINFO info, ...)
char * s;
char * d;
struct SessionHandle * data;
+ struct curl_slist * * slp;
+ struct curl_certinfo * cipf;
+ struct curl_certinfo * cipt;
+ int i;
/* WARNING: unlike curl_easy_get_info(), the strings returned by this
procedure have to be free'ed. */
paramp = va_arg(arg, void *);
ret = Curl_getinfo(data, info, paramp);
- if (ret != CURLE_OK || ((int) info & CURLINFO_TYPEMASK) != CURLINFO_STRING) {
- va_end(arg);
- return ret;
- }
+ if(ret == CURLE_OK)
+ switch ((int) info & CURLINFO_TYPEMASK) {
- ccsid = va_arg(arg, unsigned int);
- va_end(arg);
- cpp = (char * *) paramp;
- s = *cpp;
+ case CURLINFO_STRING:
+ ccsid = va_arg(arg, unsigned int);
+ cpp = (char * *) paramp;
+ s = *cpp;
+
+ if(s) {
+ d = dynconvert(ccsid, s, -1, ASCII_CCSID);
+ *cpp = d;
- if (!s)
- return ret;
+ if(!d)
+ ret = CURLE_OUT_OF_MEMORY;
+ }
- d = dynconvert(ccsid, s, -1, ASCII_CCSID);
- *cpp = d;
+ break;
- if (!d)
- return CURLE_OUT_OF_MEMORY;
+ case CURLINFO_SLIST:
+ ccsid = va_arg(arg, unsigned int);
+ if(info == CURLINFO_CERTINFO) {
+ cipf = *(struct curl_certinfo * *) paramp;
+ if(cipf) {
+ if(!(cipt = (struct curl_certinfo *) malloc(sizeof *cipt)))
+ ret = CURLE_OUT_OF_MEMORY;
+ else {
+ cipt->certinfo = (struct curl_slist * *) calloc(cipf->num_of_certs +
+ 1, sizeof(struct curl_slist *));
+ if(!cipt->certinfo)
+ ret = CURLE_OUT_OF_MEMORY;
+ else {
+ cipt->num_of_certs = cipf->num_of_certs;
+ for (i = 0; i < cipf->num_of_certs; i++)
+ if(cipf->certinfo[i])
+ if(!(cipt->certinfo[i] = slist_convert(ccsid,
+ cipf->certinfo[i],
+ ASCII_CCSID))) {
+ ret = CURLE_OUT_OF_MEMORY;
+ break;
+ }
+ }
+ }
+
+ if(ret != CURLE_OK) {
+ curl_certinfo_free_all(cipt);
+ cipt = (struct curl_certinfo *) NULL;
+ }
+
+ *(struct curl_certinfo * *) paramp = cipt;
+ }
+ }
+ else {
+ slp = (struct curl_slist * *) paramp;
+ if(*slp)
+ if(!(*slp = slist_convert(ccsid, *slp, ASCII_CCSID)))
+ ret = CURLE_OUT_OF_MEMORY;
+ }
+ }
+ va_end(arg);
return ret;
}
{
switch (option) {
- case CURLFORM_FILENAME:
- case CURLFORM_CONTENTTYPE:
- case CURLFORM_BUFFER:
- case CURLFORM_FILE:
- case CURLFORM_FILECONTENT:
- case CURLFORM_COPYCONTENTS:
- case CURLFORM_COPYNAME:
- return 1;
- }
+ case CURLFORM_FILENAME:
+ case CURLFORM_CONTENTTYPE:
+ case CURLFORM_BUFFER:
+ case CURLFORM_FILE:
+ case CURLFORM_FILECONTENT:
+ case CURLFORM_COPYCONTENTS:
+ case CURLFORM_COPYNAME:
+ return 1;
+ }
return 0;
}
{
while (nargs--)
- if (nargs != skip)
- if (Curl_is_formadd_string(forms[nargs].option))
- if (forms[nargs].value)
+ if(nargs != skip)
+ if(Curl_is_formadd_string(forms[nargs].option))
+ if(forms[nargs].value)
free((char *) forms[nargs].value);
free((char *) forms);
char * cp;
char * cp2;
- if (formx < 0 || !forms[formx].value)
+ if(formx < 0 || !forms[formx].value)
return 0;
- if (lengthx >= 0)
+ if(lengthx >= 0)
l = (int) forms[lengthx].value;
else
l = strlen(forms[formx].value) + 1;
cp = malloc(MAX_CONV_EXPANSION * l);
- if (!cp)
+ if(!cp)
return -1;
l = convert(cp, MAX_CONV_EXPANSION * l, ASCII_CCSID,
forms[formx].value, l, ccsid);
- if (l < 0) {
+ if(l < 0) {
free(cp);
return -1;
}
cp2 = realloc(cp, l); /* Shorten buffer to the string size. */
- if (cp2)
+ if(cp2)
cp = cp2;
forms[formx].value = cp;
- if (lengthx >= 0)
+ if(lengthx >= 0)
forms[lengthx].value = (char *) l; /* Update to length after conversion. */
return l;
lformlen = ALLOC_GRANULE;
lforms = malloc(lformlen * sizeof *lforms);
- if (!lforms)
+ if(!lforms)
return CURL_FORMADD_MEMORY;
/* Process the arguments, copying them into local array, latching conversion
for (;;) {
/* Make sure there is still room for an item in local array. */
- if (nargs >= lformlen) {
+ if(nargs >= lformlen) {
lformlen += ALLOC_GRANULE;
tforms = realloc(lforms, lformlen * sizeof *lforms);
- if (!tforms) {
+ if(!tforms) {
result = CURL_FORMADD_MEMORY;
break;
}
/* Get next option. */
- if (forms) {
+ if(forms) {
/* Get option from array. */
option = forms->option;
option = va_arg(arg, CURLformoption);
- if (option == CURLFORM_END)
+ if(option == CURLFORM_END)
break;
}
continue;
case CURLFORM_ARRAY:
- if (!forms) {
+ if(!forms) {
forms = va_arg(arg, struct curl_forms *);
continue;
}
option = CURLFORM_PTRNAME; /* Static for now. */
case CURLFORM_PTRNAME:
- if (namex >= 0)
+ if(namex >= 0)
result = CURL_FORMADD_OPTION_TWICE;
namex = nargs;
- if (!forms) {
+ if(!forms) {
value = va_arg(arg, char *);
nameccsid = (unsigned int) va_arg(arg, long);
}
break;
case CURLFORM_COPYCONTENTS:
- if (contentx >= 0)
+ if(contentx >= 0)
result = CURL_FORMADD_OPTION_TWICE;
contentx = nargs;
- if (!forms) {
+ if(!forms) {
value = va_arg(arg, char *);
contentccsid = (unsigned int) va_arg(arg, long);
}
case CURLFORM_PTRCONTENTS:
case CURLFORM_BUFFERPTR:
- if (!forms)
+ if(!forms)
value = va_arg(arg, char *); /* No conversion. */
break;
case CURLFORM_CONTENTSLENGTH:
lengthx = nargs;
- if (!forms)
+ if(!forms)
value = (char *) va_arg(arg, long);
break;
case CURLFORM_NAMELENGTH:
namelengthx = nargs;
- if (!forms)
+ if(!forms)
value = (char *) va_arg(arg, long);
break;
case CURLFORM_BUFFERLENGTH:
- if (!forms)
+ if(!forms)
value = (char *) va_arg(arg, long);
break;
case CURLFORM_CONTENTHEADER:
- if (!forms)
+ if(!forms)
value = (char *) va_arg(arg, struct curl_slist *);
break;
case CURLFORM_STREAM:
- if (!forms)
+ if(!forms)
value = (char *) va_arg(arg, void *);
break;
case CURLFORM_CONTENTTYPE:
/* If a previous content has been encountered, convert it now. */
- if (Curl_formadd_convert(lforms, contentx, lengthx, contentccsid) < 0) {
+ if(Curl_formadd_convert(lforms, contentx, lengthx, contentccsid) < 0) {
result = CURL_FORMADD_MEMORY;
break;
}
default:
/* Must be a convertible string. */
- if (!Curl_is_formadd_string(option)) {
+ if(!Curl_is_formadd_string(option)) {
result = CURL_FORMADD_UNKNOWN_OPTION;
break;
}
- if (!forms) {
+ if(!forms) {
value = va_arg(arg, char *);
ccsid = (unsigned int) va_arg(arg, long);
}
lforms[nargs].value = value;
- if (Curl_formadd_convert(lforms, nargs, -1, ccsid) < 0) {
+ if(Curl_formadd_convert(lforms, nargs, -1, ccsid) < 0) {
result = CURL_FORMADD_MEMORY;
break;
}
value = lforms[nargs].value;
}
- if (result != CURL_FORMADD_OK)
+ if(result != CURL_FORMADD_OK)
break;
lforms[nargs].value = value;
/* Convert the name and the last content, now that we know their lengths. */
- if (result == CURL_FORMADD_OK && namex >= 0) {
- if (Curl_formadd_convert(lforms, namex, namelengthx, nameccsid) < 0)
+ if(result == CURL_FORMADD_OK && namex >= 0) {
+ if(Curl_formadd_convert(lforms, namex, namelengthx, nameccsid) < 0)
result = CURL_FORMADD_MEMORY;
else
lforms[namex].option = CURLFORM_COPYNAME; /* Force copy. */
}
- if (result == CURL_FORMADD_OK) {
- if (Curl_formadd_convert(lforms, contentx, lengthx, contentccsid) < 0)
+ if(result == CURL_FORMADD_OK) {
+ if(Curl_formadd_convert(lforms, contentx, lengthx, contentccsid) < 0)
result = CURL_FORMADD_MEMORY;
else
contentx = -1;
/* Do the formadd with our converted parameters. */
- if (result == CURL_FORMADD_OK) {
+ if(result == CURL_FORMADD_OK) {
lforms[nargs].option = CURLFORM_END;
result = curl_formadd(httppost, last_post,
CURLFORM_ARRAY, lforms, CURLFORM_END);
p = (cfcdata *) arg;
- if ((long) len <= 0)
+ if((long) len <= 0)
return (*p->append)(p->arg, buf, len);
b = malloc(MAX_CONV_EXPANSION * len);
- if (!b)
+ if(!b)
return (size_t) -1;
l = convert(b, MAX_CONV_EXPANSION * len, p->ccsid, buf, len, ASCII_CCSID);
- if (l < 0) {
+ if(l < 0) {
free(b);
return (size_t) -1;
}
the same message; but since threadsafeness is not handled here,
this may occur (and we don't care!). */
- if (testwarn) {
+ if(testwarn) {
testwarn = 0;
#ifdef USE_TLS_SRP
- if ((int) STRING_LAST != (int) STRING_TLSAUTH_PASSWORD + 1)
+ if((int) STRING_LAST != (int) STRING_TLSAUTH_PASSWORD + 1)
#else
- if ((int) STRING_LAST != (int) STRING_MAIL_AUTH + 1)
+ if((int) STRING_LAST != (int) STRING_MAIL_AUTH + 1)
#endif
curl_mfprintf(stderr,
"*** WARNING: curl_easy_setopt_ccsid() should be reworked ***\n");
s = va_arg(arg, char *);
ccsid = va_arg(arg, unsigned int);
- if (s) {
+ if(s) {
s = dynconvert(ASCII_CCSID, s, -1, ccsid);
- if (!s) {
+ if(!s) {
result = CURLE_OUT_OF_MEMORY;
break;
}
result = curl_easy_setopt(curl, tag, s);
- if (s)
+ if(s)
free(s);
break;
pfsize = data->set.postfieldsize;
- if (!s || !pfsize || ccsid == NOCONV_CCSID || ccsid == ASCII_CCSID) {
+ if(!s || !pfsize || ccsid == NOCONV_CCSID || ccsid == ASCII_CCSID) {
result = curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, s);
break;
}
- if (pfsize == -1) {
+ if(pfsize == -1) {
/* Data is null-terminated. */
s = dynconvert(ASCII_CCSID, s, -1, ccsid);
- if (!s) {
+ if(!s) {
result = CURLE_OUT_OF_MEMORY;
break;
}
else {
/* Data length specified. */
- if (pfsize < 0 || pfsize > SIZE_MAX) {
+ if(pfsize < 0 || pfsize > SIZE_MAX) {
result = CURLE_OUT_OF_MEMORY;
break;
}
len = pfsize;
pfsize = len * MAX_CONV_EXPANSION;
- if (pfsize > SIZE_MAX)
+ if(pfsize > SIZE_MAX)
pfsize = SIZE_MAX;
cp = malloc(pfsize);
- if (!cp) {
+ if(!cp) {
result = CURLE_OUT_OF_MEMORY;
break;
}
pfsize = convert(cp, pfsize, ASCII_CCSID, s, len, ccsid);
- if (pfsize < 0) {
+ if(pfsize < 0) {
free(cp);
result = CURLE_OUT_OF_MEMORY;
break;