mirror of
https://github.com/curl/curl.git
synced 2026-08-26 09:33:33 +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
12
lib/url.c
12
lib/url.c
|
|
@ -1853,15 +1853,18 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
|
|||
}
|
||||
|
||||
/* returns the handler if the given scheme is built-in */
|
||||
const struct Curl_handler *Curl_builtin_scheme(const char *scheme)
|
||||
const struct Curl_handler *Curl_builtin_scheme(const char *scheme,
|
||||
size_t schemelen)
|
||||
{
|
||||
const struct Curl_handler * const *pp;
|
||||
const struct Curl_handler *p;
|
||||
/* Scan protocol handler table and match against 'scheme'. The handler may
|
||||
be changed later when the protocol specific setup function is called. */
|
||||
if(schemelen == CURL_ZERO_TERMINATED)
|
||||
schemelen = strlen(scheme);
|
||||
for(pp = protocols; (p = *pp) != NULL; pp++)
|
||||
if(strcasecompare(p->scheme, scheme))
|
||||
/* Protocol found in table. Check if allowed */
|
||||
if(strncasecompare(p->scheme, scheme, schemelen) && !p->scheme[schemelen])
|
||||
/* Protocol found in table. */
|
||||
return p;
|
||||
return NULL; /* not found */
|
||||
}
|
||||
|
|
@ -1871,7 +1874,8 @@ static CURLcode findprotocol(struct Curl_easy *data,
|
|||
struct connectdata *conn,
|
||||
const char *protostr)
|
||||
{
|
||||
const struct Curl_handler *p = Curl_builtin_scheme(protostr);
|
||||
const struct Curl_handler *p = Curl_builtin_scheme(protostr,
|
||||
CURL_ZERO_TERMINATED);
|
||||
|
||||
if(p && /* Protocol found in table. Check if allowed */
|
||||
(data->set.allowed_protocols & p->protocol)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue