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:
Daniel Stenberg 2022-06-13 09:30:45 +02:00
parent 193215db3c
commit e6f8445ede
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
24 changed files with 487 additions and 45 deletions

View file

@ -275,8 +275,8 @@ ParameterError str2udouble(double *valp, const char *str, long max)
}
/*
* Parse the string and modify the long in the given address. Return
* non-zero on failure, zero on success.
* Parse the string and provide an allocated libcurl compatible protocol
* string output. Return non-zero on failure, zero on success.
*
* The string is a list of protocols
*
@ -285,17 +285,22 @@ ParameterError str2udouble(double *valp, const char *str, long max)
* data.
*/
long proto2num(struct OperationConfig *config, long *val, const char *str)
ParameterError proto2num(struct OperationConfig *config,
unsigned int val, char **ostr, const char *str)
{
char *buffer;
const char *sep = ",";
char *token;
char obuf[256];
size_t olen = sizeof(obuf);
char *optr;
struct sprotos const *pp;
static struct sprotos {
const char *name;
long bit;
unsigned int bit;
} const protos[] = {
{ "all", CURLPROTO_ALL },
{ "all", (unsigned int)CURLPROTO_ALL },
{ "http", CURLPROTO_HTTP },
{ "https", CURLPROTO_HTTPS },
{ "ftp", CURLPROTO_FTP },
@ -305,6 +310,7 @@ long proto2num(struct OperationConfig *config, long *val, const char *str)
{ "telnet", CURLPROTO_TELNET },
{ "ldap", CURLPROTO_LDAP },
{ "ldaps", CURLPROTO_LDAPS },
{ "mqtt", CURLPROTO_MQTT },
{ "dict", CURLPROTO_DICT },
{ "file", CURLPROTO_FILE },
{ "tftp", CURLPROTO_TFTP },
@ -316,6 +322,7 @@ long proto2num(struct OperationConfig *config, long *val, const char *str)
{ "smtps", CURLPROTO_SMTPS },
{ "rtsp", CURLPROTO_RTSP },
{ "gopher", CURLPROTO_GOPHER },
{ "gophers", CURLPROTO_GOPHERS },
{ "smb", CURLPROTO_SMB },
{ "smbs", CURLPROTO_SMBS },
{ NULL, 0 }
@ -335,8 +342,6 @@ long proto2num(struct OperationConfig *config, long *val, const char *str)
token = strtok(NULL, sep)) {
enum e_action { allow, deny, set } action = allow;
struct sprotos const *pp;
/* Process token modifiers */
while(!ISALNUM(*token)) { /* may be NULL if token is all modifiers */
switch (*token++) {
@ -359,13 +364,13 @@ long proto2num(struct OperationConfig *config, long *val, const char *str)
if(curl_strequal(token, pp->name)) {
switch(action) {
case deny:
*val &= ~(pp->bit);
val &= ~(pp->bit);
break;
case allow:
*val |= pp->bit;
val |= pp->bit;
break;
case set:
*val = pp->bit;
val = pp->bit;
break;
}
break;
@ -376,12 +381,25 @@ long proto2num(struct OperationConfig *config, long *val, const char *str)
/* If they have specified only this protocol, we say treat it as
if no protocols are allowed */
if(action == set)
*val = 0;
val = 0;
warnf(config->global, "unrecognized protocol '%s'\n", token);
}
}
Curl_safefree(buffer);
return 0;
optr = obuf;
for(pp = &protos[1]; pp->name; pp++) {
if(val & pp->bit) {
size_t n = msnprintf(optr, olen, "%s%s",
olen != sizeof(obuf) ? "," : "",
pp->name);
olen -= n;
optr += n;
}
}
*ostr = strdup(obuf);
return *ostr ? PARAM_OK : PARAM_NO_MEM;
}
/**