) {
result = Curl_http2_switch(data, conn, FIRSTSOCKET);
if(result)
- return result;
+ goto fail;
}
else
#endif
DEBUGF(infof(data, "HTTP/2 over clean TCP"));
result = Curl_http2_switch(data, conn, FIRSTSOCKET);
if(result)
- return result;
+ goto fail;
}
break;
}
result = Curl_http_host(data, conn);
if(result)
- return result;
+ goto fail;
result = Curl_http_useragent(data);
if(result)
- return result;
+ goto fail;
Curl_http_method(data, conn, &request, &httpreq);
(pq ? pq : data->state.up.path), FALSE);
free(pq);
if(result)
- return result;
+ goto fail;
}
Curl_safefree(data->state.aptr.ref);
/* we only consider transfer-encoding magic if libz support is built-in */
result = Curl_transferencode(data);
if(result)
- return result;
+ goto fail;
#endif
result = Curl_http_body(data, conn, httpreq, &te);
if(result)
- return result;
+ goto fail;
p_accept = Curl_checkheaders(data,
STRCONST("Accept"))?NULL:"Accept: */*\r\n";
result = Curl_http_resume(data, conn, httpreq);
if(result)
- return result;
+ goto fail;
result = Curl_http_range(data, httpreq);
if(result)
- return result;
+ goto fail;
httpstring = get_http_string(data, conn);
result = Curl_http_target(data, conn, &req);
if(result) {
Curl_dyn_free(&req);
- return result;
+ goto fail;
}
#ifndef CURL_DISABLE_ALTSVC
if(result) {
Curl_dyn_free(&req);
- return result;
+ goto fail;
}
if(!(conn->handler->flags&PROTOPT_SSL) &&
}
if(result) {
Curl_dyn_free(&req);
- return result;
+ goto fail;
}
if((http->postsize > -1) &&
but is disabled here again to avoid that the chunked encoded version is
actually used when sending the request body over h2 */
data->req.upload_chunky = FALSE;
+fail:
+ if(CURLE_TOO_LARGE == result)
+ failf(data, "HTTP request too large");
return result;
}
return sep < query ? sep : query;
}
+/* convert CURLcode to CURLUcode */
+#define cc2cu(x) ((x) == CURLE_TOO_LARGE ? CURLUE_TOO_LARGE : \
+ CURLUE_OUT_OF_MEMORY)
/*
* Decide whether a character in a URL must be escaped.
*/
bool left = !query;
const unsigned char *iptr;
const unsigned char *host_sep = (const unsigned char *) url;
+ CURLcode result;
if(!relative)
host_sep = (const unsigned char *) find_host_sep(url);
len; iptr++, len--) {
if(iptr < host_sep) {
- if(Curl_dyn_addn(o, iptr, 1))
- return CURLUE_OUT_OF_MEMORY;
+ result = Curl_dyn_addn(o, iptr, 1);
+ if(result)
+ return cc2cu(result);
continue;
}
if(*iptr == ' ') {
- if(left) {
- if(Curl_dyn_addn(o, "%20", 3))
- return CURLUE_OUT_OF_MEMORY;
- }
- else {
- if(Curl_dyn_addn(o, "+", 1))
- return CURLUE_OUT_OF_MEMORY;
- }
+ if(left)
+ result = Curl_dyn_addn(o, "%20", 3);
+ else
+ result = Curl_dyn_addn(o, "+", 1);
+ if(result)
+ return cc2cu(result);
continue;
}
char out[3]={'%'};
out[1] = hexdigits[*iptr>>4];
out[2] = hexdigits[*iptr & 0xf];
- if(Curl_dyn_addn(o, out, 3))
- return CURLUE_OUT_OF_MEMORY;
- }
- else {
- if(Curl_dyn_addn(o, iptr, 1))
- return CURLUE_OUT_OF_MEMORY;
+ result = Curl_dyn_addn(o, out, 3);
}
+ else
+ result = Curl_dyn_addn(o, iptr, 1);
+ if(result)
+ return cc2cu(result);
}
return CURLUE_OK;
*
* Note that this function destroys the 'base' string.
*/
-static char *concat_url(char *base, const char *relurl)
+static CURLcode concat_url(char *base, const char *relurl, char **newurl)
{
/***
TRY to append this new path to the old URL
char *pathsep;
bool host_changed = FALSE;
const char *useurl = relurl;
+ CURLcode result = CURLE_OK;
+ CURLUcode uc;
+ *newurl = NULL;
/* protsep points to the start of the host name */
protsep = strstr(base, "//");
Curl_dyn_init(&newest, CURL_MAX_INPUT_LENGTH);
/* copy over the root url part */
- if(Curl_dyn_add(&newest, base))
- return NULL;
+ result = Curl_dyn_add(&newest, base);
+ if(result)
+ return result;
/* check if we need to append a slash */
if(('/' == useurl[0]) || (protsep && !*protsep) || ('?' == useurl[0]))
;
else {
- if(Curl_dyn_addn(&newest, "/", 1))
- return NULL;
+ result = Curl_dyn_addn(&newest, "/", 1);
+ if(result)
+ return result;
}
/* then append the new piece on the right side */
- urlencode_str(&newest, useurl, strlen(useurl), !host_changed, FALSE);
+ uc = urlencode_str(&newest, useurl, strlen(useurl), !host_changed,
+ FALSE);
+ if(uc)
+ return (uc == CURLUE_TOO_LARGE) ? CURLE_TOO_LARGE : CURLE_OUT_OF_MEMORY;
- return Curl_dyn_ptr(&newest);
+ *newurl = Curl_dyn_ptr(&newest);
+ return CURLE_OK;
}
/* scan for byte values <= 31, 127 and sometimes space */
result = Curl_dyn_addn(host, decoded, dlen);
free(decoded);
if(result)
- return CURLUE_OUT_OF_MEMORY;
+ return cc2cu(result);
}
return CURLUE_OK;
bool has_scheme)
{
size_t offset;
- CURLUcode result;
+ CURLUcode uc;
+ CURLcode result;
/*
* Parse the login details and strip them out of the host name.
*/
- result = parse_hostname_login(u, auth, authlen, flags, &offset);
- if(result)
+ uc = parse_hostname_login(u, auth, authlen, flags, &offset);
+ if(uc)
goto out;
- if(Curl_dyn_addn(host, auth + offset, authlen - offset)) {
- result = CURLUE_OUT_OF_MEMORY;
+ result = Curl_dyn_addn(host, auth + offset, authlen - offset);
+ if(result) {
+ uc = cc2cu(result);
goto out;
}
- result = Curl_parse_port(u, host, has_scheme);
- if(result)
+ uc = Curl_parse_port(u, host, has_scheme);
+ if(uc)
goto out;
if(!Curl_dyn_len(host))
case HOST_IPV4:
break;
case HOST_IPV6:
- result = ipv6_parse(u, Curl_dyn_ptr(host), Curl_dyn_len(host));
+ uc = ipv6_parse(u, Curl_dyn_ptr(host), Curl_dyn_len(host));
break;
case HOST_NAME:
- result = urldecode_host(host);
- if(!result)
- result = hostname_check(u, Curl_dyn_ptr(host), Curl_dyn_len(host));
+ uc = urldecode_host(host);
+ if(!uc)
+ uc = hostname_check(u, Curl_dyn_ptr(host), Curl_dyn_len(host));
break;
case HOST_ERROR:
- result = CURLUE_OUT_OF_MEMORY;
+ uc = CURLUE_OUT_OF_MEMORY;
break;
case HOST_BAD:
default:
- result = CURLUE_BAD_HOSTNAME; /* Bad IPv4 address even */
+ uc = CURLUE_BAD_HOSTNAME; /* Bad IPv4 address even */
break;
}
out:
- return result;
+ return uc;
}
CURLUcode Curl_url_set_authority(CURLU *u, const char *authority,
len = path - ptr;
if(len) {
- if(Curl_dyn_addn(&host, ptr, len)) {
- result = CURLUE_OUT_OF_MEMORY;
+ CURLcode code = Curl_dyn_addn(&host, ptr, len);
+ if(code) {
+ result = cc2cu(code);
goto fail;
}
uncpath = TRUE;
if(flags & CURLU_URLENCODE) {
struct dynbuf enc;
Curl_dyn_init(&enc, CURL_MAX_INPUT_LENGTH);
- if(urlencode_str(&enc, fragment + 1, fraglen - 1, TRUE, FALSE)) {
- result = CURLUE_OUT_OF_MEMORY;
+ result = urlencode_str(&enc, fragment + 1, fraglen - 1, TRUE, FALSE);
+ if(result)
goto fail;
- }
u->fragment = Curl_dyn_ptr(&enc);
}
else {
struct dynbuf enc;
Curl_dyn_init(&enc, CURL_MAX_INPUT_LENGTH);
/* skip the leading question mark */
- if(urlencode_str(&enc, query + 1, qlen - 1, TRUE, TRUE)) {
- result = CURLUE_OUT_OF_MEMORY;
+ result = urlencode_str(&enc, query + 1, qlen - 1, TRUE, TRUE);
+ if(result)
goto fail;
- }
u->query = Curl_dyn_ptr(&enc);
}
else {
if(pathlen && (flags & CURLU_URLENCODE)) {
struct dynbuf enc;
Curl_dyn_init(&enc, CURL_MAX_INPUT_LENGTH);
- if(urlencode_str(&enc, path, pathlen, TRUE, FALSE)) {
- result = CURLUE_OUT_OF_MEMORY;
+ result = urlencode_str(&enc, path, pathlen, TRUE, FALSE);
+ if(result)
goto fail;
- }
pathlen = Curl_dyn_len(&enc);
path = u->path = Curl_dyn_ptr(&enc);
}
}
if(urlencode) {
struct dynbuf enc;
+ CURLUcode uc;
Curl_dyn_init(&enc, CURL_MAX_INPUT_LENGTH);
- if(urlencode_str(&enc, *part, partlen, TRUE,
- what == CURLUPART_QUERY))
- return CURLUE_OUT_OF_MEMORY;
+ uc = urlencode_str(&enc, *part, partlen, TRUE, what == CURLUPART_QUERY);
+ if(uc)
+ return uc;
free(*part);
*part = Curl_dyn_ptr(&enc);
}
* If the existing contents is enough for a URL, allow a relative URL to
* replace it.
*/
- CURLUcode result;
+ CURLcode result;
+ CURLUcode uc;
char *oldurl;
char *redired_url;
/* apply the relative part to create a new URL
* and replace the existing one with it. */
- redired_url = concat_url(oldurl, part);
+ result = concat_url(oldurl, part, &redired_url);
free(oldurl);
- if(!redired_url)
- return CURLUE_OUT_OF_MEMORY;
+ if(result)
+ return cc2cu(result);
- result = parseurl_and_replace(redired_url, u, flags);
+ uc = parseurl_and_replace(redired_url, u, flags);
free(redired_url);
- return result;
+ return uc;
}
default:
return CURLUE_UNKNOWN_PART;
if(leadingslash && (part[0] != '/')) {
CURLcode result = Curl_dyn_addn(&enc, "/", 1);
if(result)
- return CURLUE_OUT_OF_MEMORY;
+ return cc2cu(result);
}
if(urlencode) {
const unsigned char *i;
equalsencode = FALSE;
result = Curl_dyn_addn(&enc, i, 1);
if(result)
- return CURLUE_OUT_OF_MEMORY;
+ return cc2cu(result);
}
else {
char out[3]={'%'};
out[2] = hexdigits[*i & 0xf];
result = Curl_dyn_addn(&enc, out, 3);
if(result)
- return CURLUE_OUT_OF_MEMORY;
+ return cc2cu(result);
}
}
}
char *p;
CURLcode result = Curl_dyn_add(&enc, part);
if(result)
- return CURLUE_OUT_OF_MEMORY;
+ return cc2cu(result);
p = Curl_dyn_ptr(&enc);
while(*p) {
/* make sure percent encoded are lower case */