mirror of
https://github.com/curl/curl.git
synced 2026-08-24 18:33:34 +03:00
setopt: use the handler table for protocol name to number conversions
This also returns error CURLE_UNSUPPORTED_PROTOCOL rather than CURLE_BAD_FUNCTION_ARGUMENT when a listed protocol name is not found. A new schemelen parameter is added to Curl_builtin_scheme() to support this extended use. Note that disabled protocols are not recognized anymore. Tests adapted accordingly. Closes #9472
This commit is contained in:
parent
1bbffa0833
commit
9d51329047
8 changed files with 90 additions and 98 deletions
|
|
@ -31,6 +31,11 @@ http
|
|||
<name>
|
||||
--libcurl for GET with various options
|
||||
</name>
|
||||
<features>
|
||||
http
|
||||
ftp
|
||||
file
|
||||
</features>
|
||||
<setenv>
|
||||
SSL_CERT_FILE=
|
||||
</setenv>
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
struct pair {
|
||||
const char *in;
|
||||
CURLcode exp;
|
||||
CURLcode *exp;
|
||||
};
|
||||
|
||||
int test(char *URL)
|
||||
|
|
@ -38,27 +38,34 @@ int test(char *URL)
|
|||
CURL *curl = NULL;
|
||||
int res = 0;
|
||||
CURLcode result = CURLE_OK;
|
||||
CURLcode ok = CURLE_OK;
|
||||
CURLcode bad = CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
CURLcode unsup = CURLE_UNSUPPORTED_PROTOCOL;
|
||||
CURLcode httpcode = CURLE_UNSUPPORTED_PROTOCOL;
|
||||
CURLcode httpscode = CURLE_UNSUPPORTED_PROTOCOL;
|
||||
curl_version_info_data *curlinfo;
|
||||
const char *const *proto;
|
||||
char protolist[1024];
|
||||
int n;
|
||||
int i;
|
||||
|
||||
struct pair prots[] = {
|
||||
{"goobar", CURLE_BAD_FUNCTION_ARGUMENT},
|
||||
{"http ", CURLE_BAD_FUNCTION_ARGUMENT},
|
||||
{" http", CURLE_BAD_FUNCTION_ARGUMENT},
|
||||
{"http", CURLE_OK},
|
||||
{"http,", CURLE_OK},
|
||||
{"https,", CURLE_OK},
|
||||
{"https,http", CURLE_OK},
|
||||
{"http,http", CURLE_OK},
|
||||
{"HTTP,HTTP", CURLE_OK},
|
||||
{",HTTP,HTTP", CURLE_OK},
|
||||
{"http,http,ft", CURLE_BAD_FUNCTION_ARGUMENT},
|
||||
{"", CURLE_BAD_FUNCTION_ARGUMENT},
|
||||
{",,", CURLE_BAD_FUNCTION_ARGUMENT},
|
||||
{"DICT,FILE,FTP,FTPS,GOPHER,GOPHERS,HTTP,HTTPS,IMAP,IMAPS,LDAP,LDAPS,"
|
||||
"POP3,POP3S,RTMP,RTMPE,RTMPS,RTMPT,RTMPTE,RTMPTS,RTSP,SCP,SFTP,SMB,"
|
||||
"SMBS,SMTP,SMTPS,TELNET,TFTP", CURLE_OK},
|
||||
{"all", CURLE_OK},
|
||||
{NULL, CURLE_OK},
|
||||
{"goobar", &unsup},
|
||||
{"http ", &unsup},
|
||||
{" http", &unsup},
|
||||
{"http", &httpcode},
|
||||
{"http,", &httpcode},
|
||||
{"https,", &httpscode},
|
||||
{"https,http", &httpscode},
|
||||
{"http,http", &httpcode},
|
||||
{"HTTP,HTTP", &httpcode},
|
||||
{",HTTP,HTTP", &httpcode},
|
||||
{"http,http,ft", &unsup},
|
||||
{"", &bad},
|
||||
{",,", &bad},
|
||||
{protolist, &ok},
|
||||
{"all", &ok},
|
||||
{NULL, NULL},
|
||||
};
|
||||
(void)URL;
|
||||
|
||||
|
|
@ -66,9 +73,32 @@ int test(char *URL)
|
|||
|
||||
easy_init(curl);
|
||||
|
||||
/* Get enabled protocols.*/
|
||||
curlinfo = curl_version_info(CURLVERSION_NOW);
|
||||
if(!curlinfo) {
|
||||
fputs("curl_version_info failed\n", stderr);
|
||||
res = (int) TEST_ERR_FAILURE;
|
||||
goto test_cleanup;
|
||||
}
|
||||
|
||||
n = 0;
|
||||
for(proto = curlinfo->protocols; *proto; proto++) {
|
||||
if((size_t) n >= sizeof(protolist)) {
|
||||
puts("protolist buffer too small\n");
|
||||
res = (int) TEST_ERR_FAILURE;
|
||||
goto test_cleanup;
|
||||
}
|
||||
n += msnprintf(protolist + n, sizeof(protolist) - n, ",%s", *proto);
|
||||
if(curl_strequal(*proto, "http"))
|
||||
httpcode = CURLE_OK;
|
||||
if(curl_strequal(*proto, "https"))
|
||||
httpscode = CURLE_OK;
|
||||
}
|
||||
|
||||
/* Run the tests. */
|
||||
for(i = 0; prots[i].in; i++) {
|
||||
result = curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, prots[i].in);
|
||||
if(result != prots[i].exp) {
|
||||
if(result != *prots[i].exp) {
|
||||
printf("unexpectedly '%s' returned %u\n",
|
||||
prots[i].in, result);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ int test(char *URL)
|
|||
case CURLE_BAD_FUNCTION_ARGUMENT: /* the most normal */
|
||||
case CURLE_UNKNOWN_OPTION: /* left out from the build */
|
||||
case CURLE_NOT_BUILT_IN: /* not supported */
|
||||
case CURLE_UNSUPPORTED_PROTOCOL: /* detected by protocol2num() */
|
||||
break;
|
||||
default:
|
||||
/* all other return codes are unexpected */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue