mirror of
https://github.com/curl/curl.git
synced 2026-08-03 07:20:28 +03:00
setopt: add CURLOPT_PROTOCOLS_STR and CURLOPT_REDIR_PROTOCOLS_STR
... as replacements for deprecated CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS as these new ones do not risk running into the 32 bit limit the old ones are facing. CURLINFO_PROTCOOL is now deprecated. The curl tool is updated to use the new options. Added test 1597 to verify the libcurl protocol parser. Closes #8992
This commit is contained in:
parent
193215db3c
commit
e6f8445ede
24 changed files with 487 additions and 45 deletions
|
|
@ -203,6 +203,7 @@ struct curl_easyoption Curl_easyopts[] = {
|
|||
{"PROGRESSDATA", CURLOPT_XFERINFODATA, CURLOT_CBPTR, CURLOT_FLAG_ALIAS},
|
||||
{"PROGRESSFUNCTION", CURLOPT_PROGRESSFUNCTION, CURLOT_FUNCTION, 0},
|
||||
{"PROTOCOLS", CURLOPT_PROTOCOLS, CURLOT_LONG, 0},
|
||||
{"PROTOCOLS_STR", CURLOPT_PROTOCOLS_STR, CURLOT_STRING, 0},
|
||||
{"PROXY", CURLOPT_PROXY, CURLOT_STRING, 0},
|
||||
{"PROXYAUTH", CURLOPT_PROXYAUTH, CURLOT_VALUES, 0},
|
||||
{"PROXYHEADER", CURLOPT_PROXYHEADER, CURLOT_SLIST, 0},
|
||||
|
|
@ -245,6 +246,7 @@ struct curl_easyoption Curl_easyopts[] = {
|
|||
{"READDATA", CURLOPT_READDATA, CURLOT_CBPTR, 0},
|
||||
{"READFUNCTION", CURLOPT_READFUNCTION, CURLOT_FUNCTION, 0},
|
||||
{"REDIR_PROTOCOLS", CURLOPT_REDIR_PROTOCOLS, CURLOT_LONG, 0},
|
||||
{"REDIR_PROTOCOLS_STR", CURLOPT_REDIR_PROTOCOLS_STR, CURLOT_STRING, 0},
|
||||
{"REFERER", CURLOPT_REFERER, CURLOT_STRING, 0},
|
||||
{"REQUEST_TARGET", CURLOPT_REQUEST_TARGET, CURLOT_STRING, 0},
|
||||
{"RESOLVE", CURLOPT_RESOLVE, CURLOT_SLIST, 0},
|
||||
|
|
@ -275,14 +277,14 @@ struct curl_easyoption Curl_easyopts[] = {
|
|||
{"SOCKS5_GSSAPI_SERVICE", CURLOPT_SOCKS5_GSSAPI_SERVICE, CURLOT_STRING, 0},
|
||||
{"SSH_AUTH_TYPES", CURLOPT_SSH_AUTH_TYPES, CURLOT_VALUES, 0},
|
||||
{"SSH_COMPRESSION", CURLOPT_SSH_COMPRESSION, CURLOT_LONG, 0},
|
||||
{"SSH_HOSTKEYDATA", CURLOPT_SSH_HOSTKEYDATA, CURLOT_CBPTR, 0},
|
||||
{"SSH_HOSTKEYFUNCTION", CURLOPT_SSH_HOSTKEYFUNCTION, CURLOT_FUNCTION, 0},
|
||||
{"SSH_HOST_PUBLIC_KEY_MD5", CURLOPT_SSH_HOST_PUBLIC_KEY_MD5,
|
||||
CURLOT_STRING, 0},
|
||||
{"SSH_HOST_PUBLIC_KEY_SHA256", CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256,
|
||||
CURLOT_STRING, 0},
|
||||
{"SSH_KEYDATA", CURLOPT_SSH_KEYDATA, CURLOT_CBPTR, 0},
|
||||
{"SSH_KEYFUNCTION", CURLOPT_SSH_KEYFUNCTION, CURLOT_FUNCTION, 0},
|
||||
{"SSH_HOSTKEYDATA", CURLOPT_SSH_HOSTKEYDATA, CURLOT_CBPTR, 0},
|
||||
{"SSH_HOSTKEYFUNCTION", CURLOPT_SSH_HOSTKEYFUNCTION, CURLOT_FUNCTION, 0},
|
||||
{"SSH_KNOWNHOSTS", CURLOPT_SSH_KNOWNHOSTS, CURLOT_STRING, 0},
|
||||
{"SSH_PRIVATE_KEYFILE", CURLOPT_SSH_PRIVATE_KEYFILE, CURLOT_STRING, 0},
|
||||
{"SSH_PUBLIC_KEYFILE", CURLOPT_SSH_PUBLIC_KEYFILE, CURLOT_STRING, 0},
|
||||
|
|
@ -364,6 +366,6 @@ struct curl_easyoption Curl_easyopts[] = {
|
|||
*/
|
||||
int Curl_easyopts_check(void)
|
||||
{
|
||||
return ((CURLOPT_LASTENTRY%10000) != (317 + 1));
|
||||
return ((CURLOPT_LASTENTRY%10000) != (319 + 1));
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
99
lib/setopt.c
99
lib/setopt.c
|
|
@ -148,6 +148,85 @@ static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp)
|
|||
#define C_SSLVERSION_VALUE(x) (x & 0xffff)
|
||||
#define C_SSLVERSION_MAX_VALUE(x) (x & 0xffff0000)
|
||||
|
||||
static CURLcode protocol2num(char *str, curl_off_t *val)
|
||||
{
|
||||
bool found_comma = FALSE;
|
||||
static struct scheme {
|
||||
const char *name;
|
||||
long bit;
|
||||
} const protos[] = {
|
||||
{ "dict", CURLPROTO_DICT },
|
||||
{ "file", CURLPROTO_FILE },
|
||||
{ "ftp", CURLPROTO_FTP },
|
||||
{ "ftps", CURLPROTO_FTPS },
|
||||
{ "gopher", CURLPROTO_GOPHER },
|
||||
{ "gophers", CURLPROTO_GOPHERS },
|
||||
{ "http", CURLPROTO_HTTP },
|
||||
{ "https", CURLPROTO_HTTPS },
|
||||
{ "imap", CURLPROTO_IMAP },
|
||||
{ "imaps", CURLPROTO_IMAPS },
|
||||
{ "ldap", CURLPROTO_LDAP },
|
||||
{ "ldaps", CURLPROTO_LDAPS },
|
||||
{ "mqtt", CURLPROTO_MQTT },
|
||||
{ "pop3", CURLPROTO_POP3 },
|
||||
{ "pop3s", CURLPROTO_POP3S },
|
||||
{ "rtmp", CURLPROTO_RTMP },
|
||||
{ "rtmpe", CURLPROTO_RTMPE },
|
||||
{ "rtmps", CURLPROTO_RTMPS },
|
||||
{ "rtmpt", CURLPROTO_RTMPT },
|
||||
{ "rtmpte", CURLPROTO_RTMPTE },
|
||||
{ "rtmpts", CURLPROTO_RTMPTS },
|
||||
{ "rtsp", CURLPROTO_RTSP },
|
||||
{ "scp", CURLPROTO_SCP },
|
||||
{ "sftp", CURLPROTO_SFTP },
|
||||
{ "smb", CURLPROTO_SMB },
|
||||
{ "smbs", CURLPROTO_SMBS },
|
||||
{ "smtp", CURLPROTO_SMTP },
|
||||
{ "smtps", CURLPROTO_SMTPS },
|
||||
{ "telnet", CURLPROTO_TELNET },
|
||||
{ "tftp", CURLPROTO_TFTP },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
if(!str)
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
else if(curl_strequal(str, "all")) {
|
||||
*val = ~0;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
*val = 0;
|
||||
|
||||
do {
|
||||
size_t tlen;
|
||||
struct scheme const *pp;
|
||||
char *token;
|
||||
token = strchr(str, ',');
|
||||
found_comma = token ? TRUE : FALSE;
|
||||
if(!token)
|
||||
token = strchr(str, '\0');
|
||||
tlen = token - str;
|
||||
if(tlen) {
|
||||
for(pp = protos; pp->name; pp++) {
|
||||
if((strlen(pp->name) == tlen) &&
|
||||
curl_strnequal(str, pp->name, tlen)) {
|
||||
*val |= pp->bit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!(pp->name))
|
||||
/* protocol name didn't match */
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
}
|
||||
if(found_comma)
|
||||
str = token + 1;
|
||||
} while(found_comma);
|
||||
if(!*val)
|
||||
/* no matching protocol */
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do not make Curl_vsetopt() static: it is called from
|
||||
* packages/OS400/ccsidcurl.c.
|
||||
|
|
@ -2560,14 +2639,30 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
|
|||
transfer, which thus helps the app which takes URLs from users or other
|
||||
external inputs and want to restrict what protocol(s) to deal
|
||||
with. Defaults to CURLPROTO_ALL. */
|
||||
data->set.allowed_protocols = (unsigned int)va_arg(param, long);
|
||||
data->set.allowed_protocols = (curl_off_t)va_arg(param, long);
|
||||
break;
|
||||
|
||||
case CURLOPT_REDIR_PROTOCOLS:
|
||||
/* set the bitmask for the protocols that libcurl is allowed to follow to,
|
||||
as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs
|
||||
to be set in both bitmasks to be allowed to get redirected to. */
|
||||
data->set.redir_protocols = (unsigned int)va_arg(param, long);
|
||||
data->set.redir_protocols = (curl_off_t)va_arg(param, long);
|
||||
break;
|
||||
|
||||
case CURLOPT_PROTOCOLS_STR:
|
||||
argptr = va_arg(param, char *);
|
||||
result = protocol2num(argptr, &bigsize);
|
||||
if(result)
|
||||
return result;
|
||||
data->set.allowed_protocols = bigsize;
|
||||
break;
|
||||
|
||||
case CURLOPT_REDIR_PROTOCOLS_STR:
|
||||
argptr = va_arg(param, char *);
|
||||
result = protocol2num(argptr, &bigsize);
|
||||
if(result)
|
||||
return result;
|
||||
data->set.redir_protocols = bigsize;
|
||||
break;
|
||||
|
||||
case CURLOPT_DEFAULT_PROTOCOL:
|
||||
|
|
|
|||
|
|
@ -1782,8 +1782,8 @@ struct UserDefined {
|
|||
#ifdef ENABLE_IPV6
|
||||
unsigned int scope_id; /* Scope id for IPv6 */
|
||||
#endif
|
||||
unsigned int allowed_protocols;
|
||||
unsigned int redir_protocols;
|
||||
curl_off_t allowed_protocols;
|
||||
curl_off_t redir_protocols;
|
||||
unsigned int mime_options; /* Mime option flags. */
|
||||
|
||||
#ifndef CURL_DISABLE_RTSP
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue