mirror of
https://github.com/curl/curl.git
synced 2026-08-24 19:13:39 +03:00
urlapi: add curl_url_strerror()
Add curl_url_strerror() to convert CURLUcode into readable string and facilitate easier troubleshooting in programs using URL API. Extend CURLUcode with CURLU_LAST for iteration in unit tests. Update man pages with a mention of new function. Update example code and tests with new functionality where it fits. Closes #7605
This commit is contained in:
parent
f0b8d1c5f6
commit
3363eeb262
25 changed files with 233 additions and 72 deletions
|
|
@ -152,6 +152,25 @@ s3: Invalid share handle
|
|||
s4: Out of memory
|
||||
s5: Feature not enabled in this library
|
||||
s6: CURLSHcode unknown
|
||||
u0: No error
|
||||
u1: An invalid CURLU pointer was passed as argument
|
||||
u2: An invalid 'part' argument was passed as argument
|
||||
u3: A malformed input was passed to a URL API function
|
||||
u4: The port number was not a decimal number between 0 and 65535
|
||||
u5: This libcurl build doesn't support the given URL scheme
|
||||
u6: URL decode error, most likely because of rubbish in the input
|
||||
u7: A memory function failed
|
||||
u8: Credentials was passed in the URL when prohibited
|
||||
u9: An unknown part ID was passed to a URL API function
|
||||
u10: There is no scheme part in the URL
|
||||
u11: There is no user part in the URL
|
||||
u12: There is no password part in the URL
|
||||
u13: There is no options part in the URL
|
||||
u14: There is no host part in the URL
|
||||
u15: There is no port part in the URL
|
||||
u16: There is no query part in the URL
|
||||
u17: There is no fragment part in the URL
|
||||
u18: CURLUcode unknown
|
||||
</stdout>
|
||||
</verify>
|
||||
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ Set excessive URL lengths
|
|||
<stdout>
|
||||
CURLOPT_URL 10000000 bytes URL == 43
|
||||
CURLOPT_POSTFIELDS 10000000 bytes data == 0
|
||||
CURLUPART_URL 10000000 bytes URL == 3
|
||||
CURLUPART_SCHEME 10000000 bytes scheme == 3
|
||||
CURLUPART_USER 10000000 bytes user == 3
|
||||
CURLUPART_URL 10000000 bytes URL == 3 (A malformed input was passed to a URL API function)
|
||||
CURLUPART_SCHEME 10000000 bytes scheme == 3 (A malformed input was passed to a URL API function)
|
||||
CURLUPART_USER 10000000 bytes user == 3 (A malformed input was passed to a URL API function)
|
||||
</stdout>
|
||||
</verify>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2021, 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
|
||||
|
|
@ -29,14 +29,17 @@ int test(char *URL)
|
|||
CURLcode easyret;
|
||||
CURLMcode multiret;
|
||||
CURLSHcode shareret;
|
||||
CURLUcode urlret;
|
||||
(void)URL;
|
||||
|
||||
curl_easy_strerror((CURLcode)INT_MAX);
|
||||
curl_multi_strerror((CURLMcode)INT_MAX);
|
||||
curl_share_strerror((CURLSHcode)INT_MAX);
|
||||
curl_url_strerror((CURLUcode)INT_MAX);
|
||||
curl_easy_strerror((CURLcode)-INT_MAX);
|
||||
curl_multi_strerror((CURLMcode)-INT_MAX);
|
||||
curl_share_strerror((CURLSHcode)-INT_MAX);
|
||||
curl_url_strerror((CURLUcode)-INT_MAX);
|
||||
for(easyret = CURLE_OK; easyret <= CURL_LAST; easyret++) {
|
||||
printf("e%d: %s\n", (int)easyret, curl_easy_strerror(easyret));
|
||||
}
|
||||
|
|
@ -47,6 +50,9 @@ int test(char *URL)
|
|||
for(shareret = CURLSHE_OK; shareret <= CURLSHE_LAST; shareret++) {
|
||||
printf("s%d: %s\n", (int)shareret, curl_share_strerror(shareret));
|
||||
}
|
||||
for(urlret = CURLUE_OK; urlret <= CURLUE_LAST; urlret++) {
|
||||
printf("u%d: %s\n", (int)urlret, curl_url_strerror(urlret));
|
||||
}
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2021, 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
|
||||
|
|
@ -54,14 +54,14 @@ int test(char *URL)
|
|||
u = curl_url();
|
||||
if(u) {
|
||||
CURLUcode uc = curl_url_set(u, CURLUPART_URL, longurl, 0);
|
||||
printf("CURLUPART_URL %d bytes URL == %d\n",
|
||||
EXCESSIVE, (int)uc);
|
||||
printf("CURLUPART_URL %d bytes URL == %d (%s)\n",
|
||||
EXCESSIVE, (int)uc, curl_url_strerror(uc));
|
||||
uc = curl_url_set(u, CURLUPART_SCHEME, longurl, CURLU_NON_SUPPORT_SCHEME);
|
||||
printf("CURLUPART_SCHEME %d bytes scheme == %d\n",
|
||||
EXCESSIVE, (int)uc);
|
||||
printf("CURLUPART_SCHEME %d bytes scheme == %d (%s)\n",
|
||||
EXCESSIVE, (int)uc, curl_url_strerror(uc));
|
||||
uc = curl_url_set(u, CURLUPART_USER, longurl, 0);
|
||||
printf("CURLUPART_USER %d bytes user == %d\n",
|
||||
EXCESSIVE, (int)uc);
|
||||
printf("CURLUPART_USER %d bytes user == %d (%s)\n",
|
||||
EXCESSIVE, (int)uc, curl_url_strerror(uc));
|
||||
curl_url_cleanup(u);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -785,17 +785,17 @@ static int set_url(void)
|
|||
rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].set,
|
||||
set_url_list[i].setflags);
|
||||
if(rc) {
|
||||
fprintf(stderr, "%s:%d Set URL %s returned %d\n",
|
||||
fprintf(stderr, "%s:%d Set URL %s returned %d (%s)\n",
|
||||
__FILE__, __LINE__, set_url_list[i].set,
|
||||
(int)rc);
|
||||
(int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
char *url = NULL;
|
||||
rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
|
||||
if(rc) {
|
||||
fprintf(stderr, "%s:%d Get URL returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
|
|
@ -847,8 +847,8 @@ static int set_parts(void)
|
|||
rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
|
||||
|
||||
if(rc) {
|
||||
fprintf(stderr, "%s:%d Get URL returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else if(checkurl(url, set_parts_list[i].out)) {
|
||||
|
|
@ -884,8 +884,8 @@ static int get_url(void)
|
|||
rc = curl_url_get(urlp, CURLUPART_URL, &url, get_url_list[i].getflags);
|
||||
|
||||
if(rc) {
|
||||
fprintf(stderr, "%s:%d returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
|
|
@ -987,8 +987,8 @@ static int append(void)
|
|||
char *url;
|
||||
rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
|
||||
if(rc) {
|
||||
fprintf(stderr, "%s:%d Get URL returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
|
|
@ -1013,15 +1013,15 @@ static int scopeid(void)
|
|||
rc = curl_url_set(u, CURLUPART_URL,
|
||||
"https://[fe80::20c:29ff:fe9c:409b%25eth0]/hello.html", 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_set returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_set returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
|
||||
rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
|
|
@ -1031,15 +1031,15 @@ static int scopeid(void)
|
|||
|
||||
rc = curl_url_set(u, CURLUPART_HOST, "[::1]", 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
|
||||
rc = curl_url_get(u, CURLUPART_URL, &url, 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
|
|
@ -1049,15 +1049,15 @@ static int scopeid(void)
|
|||
|
||||
rc = curl_url_set(u, CURLUPART_HOST, "example.com", 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
|
||||
rc = curl_url_get(u, CURLUPART_URL, &url, 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
|
|
@ -1068,15 +1068,15 @@ static int scopeid(void)
|
|||
rc = curl_url_set(u, CURLUPART_HOST,
|
||||
"[fe80::20c:29ff:fe9c:409b%25eth0]", 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
|
||||
rc = curl_url_get(u, CURLUPART_URL, &url, 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
|
|
@ -1086,8 +1086,8 @@ static int scopeid(void)
|
|||
|
||||
rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
|
|
@ -1097,8 +1097,8 @@ static int scopeid(void)
|
|||
|
||||
rc = curl_url_get(u, CURLUPART_ZONEID, &url, 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_ZONEID returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_ZONEID returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
|
|
@ -1108,15 +1108,15 @@ static int scopeid(void)
|
|||
|
||||
rc = curl_url_set(u, CURLUPART_ZONEID, "clown", 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_set CURLUPART_ZONEID returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_set CURLUPART_ZONEID returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
|
||||
rc = curl_url_get(u, CURLUPART_URL, &url, 0);
|
||||
if(rc != CURLUE_OK) {
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d\n",
|
||||
__FILE__, __LINE__, (int)rc);
|
||||
fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
|
||||
__FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
|
||||
error++;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2021, 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
|
||||
|
|
@ -48,7 +48,8 @@ int test(char *URL)
|
|||
|
||||
uc = curl_url_set(urlp, CURLUPART_URL, URL, 0);
|
||||
if(uc) {
|
||||
fprintf(stderr, "problem setting CURLUPART_URL.");
|
||||
fprintf(stderr, "problem setting CURLUPART_URL: %s.",
|
||||
curl_url_strerror(uc));
|
||||
goto test_cleanup;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2021, 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
|
||||
|
|
@ -49,7 +49,8 @@ int test(char *URL)
|
|||
|
||||
uc = curl_url_set(urlp, CURLUPART_URL, URL, 0);
|
||||
if(uc) {
|
||||
fprintf(stderr, "problem setting CURLUPART_URL.");
|
||||
fprintf(stderr, "problem setting CURLUPART_URL: %s.",
|
||||
curl_url_strerror(uc));
|
||||
goto test_cleanup;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue