in extra/curl/curl-8.12.1/lib/setopt.c [258:1415]
static CURLcode setopt_long(struct Curl_easy *data, CURLoption option,
long arg)
{
bool enabled = (0 != arg);
unsigned long uarg = (unsigned long)arg;
switch(option) {
case CURLOPT_DNS_CACHE_TIMEOUT:
if(arg < -1)
return CURLE_BAD_FUNCTION_ARGUMENT;
else if(arg > INT_MAX)
arg = INT_MAX;
data->set.dns_cache_timeout = (int)arg;
break;
case CURLOPT_CA_CACHE_TIMEOUT:
if(Curl_ssl_supports(data, SSLSUPP_CA_CACHE)) {
if(arg < -1)
return CURLE_BAD_FUNCTION_ARGUMENT;
else if(arg > INT_MAX)
arg = INT_MAX;
data->set.general_ssl.ca_cache_timeout = (int)arg;
}
else
return CURLE_NOT_BUILT_IN;
break;
case CURLOPT_MAXCONNECTS:
/*
* Set the absolute number of maximum simultaneous alive connection that
* libcurl is allowed to have.
*/
if(uarg > UINT_MAX)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.maxconnects = (unsigned int)uarg;
break;
case CURLOPT_FORBID_REUSE:
/*
* When this transfer is done, it must not be left to be reused by a
* subsequent transfer but shall be closed immediately.
*/
data->set.reuse_forbid = enabled;
break;
case CURLOPT_FRESH_CONNECT:
/*
* This transfer shall not use a previously cached connection but
* should be made with a fresh new connect!
*/
data->set.reuse_fresh = enabled;
break;
case CURLOPT_VERBOSE:
/*
* Verbose means infof() calls that give a lot of information about
* the connection and transfer procedures as well as internal choices.
*/
data->set.verbose = enabled;
break;
case CURLOPT_HEADER:
/*
* Set to include the header in the general data output stream.
*/
data->set.include_header = enabled;
break;
case CURLOPT_NOPROGRESS:
/*
* Shut off the internal supported progress meter
*/
data->set.hide_progress = enabled;
if(data->set.hide_progress)
data->progress.flags |= PGRS_HIDE;
else
data->progress.flags &= ~PGRS_HIDE;
break;
case CURLOPT_NOBODY:
/*
* Do not include the body part in the output data stream.
*/
data->set.opt_no_body = enabled;
#ifndef CURL_DISABLE_HTTP
if(data->set.opt_no_body)
/* in HTTP lingo, no body means using the HEAD request... */
data->set.method = HTTPREQ_HEAD;
else if(data->set.method == HTTPREQ_HEAD)
data->set.method = HTTPREQ_GET;
#endif
break;
case CURLOPT_FAILONERROR:
/*
* Do not output the >=400 error code HTML-page, but instead only
* return error.
*/
data->set.http_fail_on_error = enabled;
break;
case CURLOPT_KEEP_SENDING_ON_ERROR:
data->set.http_keep_sending_on_error = enabled;
break;
case CURLOPT_UPLOAD:
case CURLOPT_PUT:
/*
* We want to sent data to the remote host. If this is HTTP, that equals
* using the PUT request.
*/
if(arg) {
/* If this is HTTP, PUT is what's needed to "upload" */
data->set.method = HTTPREQ_PUT;
data->set.opt_no_body = FALSE; /* this is implied */
}
else
/* In HTTP, the opposite of upload is GET (unless NOBODY is true as
then this can be changed to HEAD later on) */
data->set.method = HTTPREQ_GET;
break;
case CURLOPT_FILETIME:
/*
* Try to get the file time of the remote document. The time will
* later (possibly) become available using curl_easy_getinfo().
*/
data->set.get_filetime = enabled;
break;
case CURLOPT_SERVER_RESPONSE_TIMEOUT:
/*
* Option that specifies how quickly a server response must be obtained
* before it is considered failure. For pingpong protocols.
*/
if((arg >= 0) && (arg <= (INT_MAX/1000)))
data->set.server_response_timeout = (unsigned int)arg * 1000;
else
return CURLE_BAD_FUNCTION_ARGUMENT;
break;
case CURLOPT_SERVER_RESPONSE_TIMEOUT_MS:
/*
* Option that specifies how quickly a server response must be obtained
* before it is considered failure. For pingpong protocols.
*/
if((arg >= 0) && (arg <= INT_MAX))
data->set.server_response_timeout = (unsigned int)arg;
else
return CURLE_BAD_FUNCTION_ARGUMENT;
break;
#ifndef CURL_DISABLE_TFTP
case CURLOPT_TFTP_NO_OPTIONS:
/*
* Option that prevents libcurl from sending TFTP option requests to the
* server.
*/
data->set.tftp_no_options = enabled;
break;
case CURLOPT_TFTP_BLKSIZE:
/*
* TFTP option that specifies the block size to use for data transmission.
*/
if(arg < TFTP_BLKSIZE_MIN)
arg = 512;
else if(arg > TFTP_BLKSIZE_MAX)
arg = TFTP_BLKSIZE_MAX;
data->set.tftp_blksize = arg;
break;
#endif
#ifndef CURL_DISABLE_NETRC
case CURLOPT_NETRC:
/*
* Parse the $HOME/.netrc file
*/
if((arg < CURL_NETRC_IGNORED) || (arg >= CURL_NETRC_LAST))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.use_netrc = (unsigned char)arg;
break;
#endif
case CURLOPT_TRANSFERTEXT:
/*
* This option was previously named 'FTPASCII'. Renamed to work with
* more protocols than merely FTP.
*
* Transfer using ASCII (instead of BINARY).
*/
data->set.prefer_ascii = enabled;
break;
case CURLOPT_TIMECONDITION:
/*
* Set HTTP time condition. This must be one of the defines in the
* curl/curl.h header file.
*/
if((arg < CURL_TIMECOND_NONE) || (arg >= CURL_TIMECOND_LAST))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.timecondition = (unsigned char)(curl_TimeCond)arg;
break;
case CURLOPT_TIMEVALUE:
/*
* This is the value to compare with the remote document with the
* method set with CURLOPT_TIMECONDITION
*/
data->set.timevalue = (time_t)arg;
break;
case CURLOPT_SSLVERSION:
#ifndef CURL_DISABLE_PROXY
case CURLOPT_PROXY_SSLVERSION:
#endif
/*
* Set explicit SSL version to try to connect with, as some SSL
* implementations are lame.
*/
#ifdef USE_SSL
{
long version, version_max;
struct ssl_primary_config *primary = &data->set.ssl.primary;
#ifndef CURL_DISABLE_PROXY
if(option != CURLOPT_SSLVERSION)
primary = &data->set.proxy_ssl.primary;
#endif
version = C_SSLVERSION_VALUE(arg);
version_max = (long)C_SSLVERSION_MAX_VALUE(arg);
if(version < CURL_SSLVERSION_DEFAULT ||
version == CURL_SSLVERSION_SSLv2 ||
version == CURL_SSLVERSION_SSLv3 ||
version >= CURL_SSLVERSION_LAST ||
version_max < CURL_SSLVERSION_MAX_NONE ||
version_max >= CURL_SSLVERSION_MAX_LAST)
return CURLE_BAD_FUNCTION_ARGUMENT;
primary->version = (unsigned char)version;
primary->version_max = (unsigned int)version_max;
}
#else
return CURLE_NOT_BUILT_IN;
#endif
break;
case CURLOPT_POSTFIELDSIZE:
/*
* The size of the POSTFIELD data to prevent libcurl to do strlen() to
* figure it out. Enables binary posts.
*/
if(arg < -1)
return CURLE_BAD_FUNCTION_ARGUMENT;
if(data->set.postfieldsize < arg &&
data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
/* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
Curl_safefree(data->set.str[STRING_COPYPOSTFIELDS]);
data->set.postfields = NULL;
}
data->set.postfieldsize = arg;
break;
#ifndef CURL_DISABLE_HTTP
#if !defined(CURL_DISABLE_COOKIES)
case CURLOPT_COOKIESESSION:
/*
* Set this option to TRUE to start a new "cookie session". It will
* prevent the forthcoming read-cookies-from-file actions to accept
* cookies that are marked as being session cookies, as they belong to a
* previous session.
*/
data->set.cookiesession = enabled;
break;
#endif
case CURLOPT_AUTOREFERER:
/*
* Switch on automatic referer that gets set if curl follows locations.
*/
data->set.http_auto_referer = enabled;
break;
case CURLOPT_TRANSFER_ENCODING:
data->set.http_transfer_encoding = enabled;
break;
case CURLOPT_FOLLOWLOCATION:
/*
* Follow Location: header hints on an HTTP-server.
*/
data->set.http_follow_location = enabled;
break;
case CURLOPT_UNRESTRICTED_AUTH:
/*
* Send authentication (user+password) when following locations, even when
* hostname changed.
*/
data->set.allow_auth_to_other_hosts = enabled;
break;
case CURLOPT_MAXREDIRS:
/*
* The maximum amount of hops you allow curl to follow Location:
* headers. This should mostly be used to detect never-ending loops.
*/
if(arg < -1)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.maxredirs = arg;
break;
case CURLOPT_POSTREDIR:
/*
* Set the behavior of POST when redirecting
* CURL_REDIR_GET_ALL - POST is changed to GET after 301 and 302
* CURL_REDIR_POST_301 - POST is kept as POST after 301
* CURL_REDIR_POST_302 - POST is kept as POST after 302
* CURL_REDIR_POST_303 - POST is kept as POST after 303
* CURL_REDIR_POST_ALL - POST is kept as POST after 301, 302 and 303
* other - POST is kept as POST after 301 and 302
*/
if(arg < CURL_REDIR_GET_ALL)
/* no return error on too high numbers since the bitmask could be
extended in a future */
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.keep_post = arg & CURL_REDIR_POST_ALL;
break;
case CURLOPT_POST:
/* Does this option serve a purpose anymore? Yes it does, when
CURLOPT_POSTFIELDS is not used and the POST data is read off the
callback! */
if(arg) {
data->set.method = HTTPREQ_POST;
data->set.opt_no_body = FALSE; /* this is implied */
}
else
data->set.method = HTTPREQ_GET;
break;
case CURLOPT_HEADEROPT:
/*
* Set header option.
*/
data->set.sep_headers = !!(arg & CURLHEADER_SEPARATE);
break;
case CURLOPT_HTTPAUTH:
return httpauth(data, FALSE, uarg);
case CURLOPT_HTTPGET:
/*
* Set to force us do HTTP GET
*/
if(enabled) {
data->set.method = HTTPREQ_GET;
data->set.opt_no_body = FALSE; /* this is implied */
}
break;
case CURLOPT_HTTP_VERSION:
/*
* This sets a requested HTTP version to be used. The value is one of
* the listed enums in curl/curl.h.
*/
switch(arg) {
case CURL_HTTP_VERSION_NONE:
#ifdef USE_HTTP2
/* This seems an undesirable quirk to force a behaviour on lower
* implementations that they should recognize independently? */
arg = CURL_HTTP_VERSION_2TLS;
#endif
/* accepted */
break;
case CURL_HTTP_VERSION_1_0:
case CURL_HTTP_VERSION_1_1:
/* accepted */
break;
#ifdef USE_HTTP2
case CURL_HTTP_VERSION_2_0:
case CURL_HTTP_VERSION_2TLS:
case CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE:
/* accepted */
break;
#endif
#ifdef USE_HTTP3
case CURL_HTTP_VERSION_3:
case CURL_HTTP_VERSION_3ONLY:
/* accepted */
break;
#endif
default:
/* not accepted */
if(arg < CURL_HTTP_VERSION_NONE)
return CURLE_BAD_FUNCTION_ARGUMENT;
return CURLE_UNSUPPORTED_PROTOCOL;
}
data->set.httpwant = (unsigned char)arg;
break;
case CURLOPT_EXPECT_100_TIMEOUT_MS:
/*
* Time to wait for a response to an HTTP request containing an
* Expect: 100-continue header before sending the data anyway.
*/
if(arg < 0)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.expect_100_timeout = arg;
break;
case CURLOPT_HTTP09_ALLOWED:
data->set.http09_allowed = enabled;
break;
#endif /* ! CURL_DISABLE_HTTP */
#ifndef CURL_DISABLE_MIME
case CURLOPT_MIME_OPTIONS:
data->set.mime_formescape = !!(arg & CURLMIMEOPT_FORMESCAPE);
break;
#endif
#ifndef CURL_DISABLE_PROXY
case CURLOPT_HTTPPROXYTUNNEL:
/*
* Tunnel operations through the proxy instead of normal proxy use
*/
data->set.tunnel_thru_httpproxy = enabled;
break;
case CURLOPT_PROXYPORT:
/*
* Explicitly set HTTP proxy port number.
*/
if((arg < 0) || (arg > 65535))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.proxyport = (unsigned short)arg;
break;
case CURLOPT_PROXYAUTH:
return httpauth(data, TRUE, uarg);
case CURLOPT_PROXYTYPE:
/*
* Set proxy type.
*/
if((arg < CURLPROXY_HTTP) || (arg > CURLPROXY_SOCKS5_HOSTNAME))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.proxytype = (unsigned char)(curl_proxytype)arg;
break;
case CURLOPT_PROXY_TRANSFER_MODE:
/*
* set transfer mode (;type=<a|i>) when doing FTP via an HTTP proxy
*/
if(uarg > 1)
/* reserve other values for future use */
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.proxy_transfer_mode = (bool)uarg;
break;
case CURLOPT_SOCKS5_AUTH:
if(data->set.socks5auth & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI))
return CURLE_NOT_BUILT_IN;
data->set.socks5auth = (unsigned char)uarg;
break;
case CURLOPT_HAPROXYPROTOCOL:
/*
* Set to send the HAProxy Proxy Protocol header
*/
data->set.haproxyprotocol = enabled;
break;
case CURLOPT_PROXY_SSL_VERIFYPEER:
/*
* Enable peer SSL verifying for proxy.
*/
data->set.proxy_ssl.primary.verifypeer = enabled;
/* Update the current connection proxy_ssl_config. */
Curl_ssl_conn_config_update(data, TRUE);
break;
case CURLOPT_PROXY_SSL_VERIFYHOST:
/*
* Enable verification of the hostname in the peer certificate for proxy
*/
data->set.proxy_ssl.primary.verifyhost = enabled;
/* Update the current connection proxy_ssl_config. */
Curl_ssl_conn_config_update(data, TRUE);
break;
#endif /* ! CURL_DISABLE_PROXY */
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
case CURLOPT_SOCKS5_GSSAPI_NEC:
/*
* Set flag for NEC SOCK5 support
*/
data->set.socks5_gssapi_nec = enabled;
break;
#endif
#ifdef CURL_LIST_ONLY_PROTOCOL
case CURLOPT_DIRLISTONLY:
/*
* An option that changes the command to one that asks for a list only, no
* file info details. Used for FTP, POP3 and SFTP.
*/
data->set.list_only = enabled;
break;
#endif
case CURLOPT_APPEND:
/*
* We want to upload and append to an existing file. Used for FTP and
* SFTP.
*/
data->set.remote_append = enabled;
break;
#ifndef CURL_DISABLE_FTP
case CURLOPT_FTP_FILEMETHOD:
/*
* How do access files over FTP.
*/
if((arg < CURLFTPMETHOD_DEFAULT) || (arg >= CURLFTPMETHOD_LAST))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.ftp_filemethod = (unsigned char)arg;
break;
case CURLOPT_FTP_USE_EPRT:
data->set.ftp_use_eprt = enabled;
break;
case CURLOPT_FTP_USE_EPSV:
data->set.ftp_use_epsv = enabled;
break;
case CURLOPT_FTP_USE_PRET:
data->set.ftp_use_pret = enabled;
break;
case CURLOPT_FTP_SSL_CCC:
if((arg < CURLFTPSSL_CCC_NONE) || (arg >= CURLFTPSSL_CCC_LAST))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.ftp_ccc = (unsigned char)arg;
break;
case CURLOPT_FTP_SKIP_PASV_IP:
/*
* Enable or disable FTP_SKIP_PASV_IP, which will disable/enable the
* bypass of the IP address in PASV responses.
*/
data->set.ftp_skip_ip = enabled;
break;
case CURLOPT_FTPSSLAUTH:
/*
* Set a specific auth for FTP-SSL transfers.
*/
if((arg < CURLFTPAUTH_DEFAULT) || (arg >= CURLFTPAUTH_LAST))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.ftpsslauth = (unsigned char)(curl_ftpauth)arg;
break;
case CURLOPT_ACCEPTTIMEOUT_MS:
/*
* The maximum time for curl to wait for FTP server connect
*/
if(uarg > UINT_MAX)
uarg = UINT_MAX;
data->set.accepttimeout = (unsigned int)uarg;
break;
case CURLOPT_WILDCARDMATCH:
data->set.wildcard_enabled = enabled;
break;
#endif /* ! CURL_DISABLE_FTP */
#if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
case CURLOPT_FTP_CREATE_MISSING_DIRS:
/*
* An FTP/SFTP option that modifies an upload to create missing
* directories on the server.
*/
/* reserve other values for future use */
if((arg < CURLFTP_CREATE_DIR_NONE) || (arg > CURLFTP_CREATE_DIR_RETRY))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.ftp_create_missing_dirs = (unsigned char)arg;
break;
#endif /* ! CURL_DISABLE_FTP || USE_SSH */
case CURLOPT_INFILESIZE:
/*
* If known, this should inform curl about the file size of the
* to-be-uploaded file.
*/
if(arg < -1)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.filesize = arg;
break;
case CURLOPT_LOW_SPEED_LIMIT:
/*
* The low speed limit that if transfers are below this for
* CURLOPT_LOW_SPEED_TIME, the transfer is aborted.
*/
if(arg < 0)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.low_speed_limit = arg;
break;
case CURLOPT_LOW_SPEED_TIME:
/*
* The low speed time that if transfers are below the set
* CURLOPT_LOW_SPEED_LIMIT during this time, the transfer is aborted.
*/
if(arg < 0)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.low_speed_time = arg;
break;
case CURLOPT_PORT:
/*
* The port number to use when getting the URL. 0 disables it.
*/
if((arg < 0) || (arg > 65535))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.use_port = (unsigned short)arg;
break;
case CURLOPT_TIMEOUT:
/*
* The maximum time you allow curl to use for a single transfer
* operation.
*/
if((arg >= 0) && (arg <= (INT_MAX/1000)))
data->set.timeout = (unsigned int)arg * 1000;
else
return CURLE_BAD_FUNCTION_ARGUMENT;
break;
case CURLOPT_TIMEOUT_MS:
if(uarg > UINT_MAX)
uarg = UINT_MAX;
data->set.timeout = (unsigned int)uarg;
break;
case CURLOPT_CONNECTTIMEOUT:
/*
* The maximum time you allow curl to use to connect.
*/
if((arg >= 0) && (arg <= (INT_MAX/1000)))
data->set.connecttimeout = (unsigned int)arg * 1000;
else
return CURLE_BAD_FUNCTION_ARGUMENT;
break;
case CURLOPT_CONNECTTIMEOUT_MS:
if(uarg > UINT_MAX)
uarg = UINT_MAX;
data->set.connecttimeout = (unsigned int)uarg;
break;
case CURLOPT_RESUME_FROM:
/*
* Resume transfer at the given file position
*/
if(arg < -1)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.set_resume_from = arg;
break;
case CURLOPT_CRLF:
/*
* Kludgy option to enable CRLF conversions. Subject for removal.
*/
data->set.crlf = enabled;
break;
#ifndef CURL_DISABLE_BINDLOCAL
case CURLOPT_LOCALPORT:
/*
* Set what local port to bind the socket to when performing an operation.
*/
if((arg < 0) || (arg > 65535))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.localport = curlx_sltous(arg);
break;
case CURLOPT_LOCALPORTRANGE:
/*
* Set number of local ports to try, starting with CURLOPT_LOCALPORT.
*/
if((arg < 0) || (arg > 65535))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.localportrange = curlx_sltous(arg);
break;
#endif
#ifdef HAVE_GSSAPI
case CURLOPT_GSSAPI_DELEGATION:
/*
* GSS-API credential delegation bitmask
*/
data->set.gssapi_delegation = (unsigned char)uarg&
(CURLGSSAPI_DELEGATION_POLICY_FLAG|CURLGSSAPI_DELEGATION_FLAG);
break;
#endif
case CURLOPT_SSL_VERIFYPEER:
/*
* Enable peer SSL verifying.
*/
data->set.ssl.primary.verifypeer = enabled;
/* Update the current connection ssl_config. */
Curl_ssl_conn_config_update(data, FALSE);
break;
#ifndef CURL_DISABLE_DOH
case CURLOPT_DOH_SSL_VERIFYPEER:
/*
* Enable peer SSL verifying for DoH.
*/
data->set.doh_verifypeer = enabled;
break;
case CURLOPT_DOH_SSL_VERIFYHOST:
/*
* Enable verification of the hostname in the peer certificate for DoH
*/
data->set.doh_verifyhost = enabled;
break;
case CURLOPT_DOH_SSL_VERIFYSTATUS:
/*
* Enable certificate status verifying for DoH.
*/
if(!Curl_ssl_cert_status_request())
return CURLE_NOT_BUILT_IN;
data->set.doh_verifystatus = enabled;
break;
#endif /* ! CURL_DISABLE_DOH */
case CURLOPT_SSL_VERIFYHOST:
/*
* Enable verification of the hostname in the peer certificate
*/
/* Obviously people are not reading documentation and too many thought
this argument took a boolean when it was not and misused it.
Treat 1 and 2 the same */
data->set.ssl.primary.verifyhost = enabled;
/* Update the current connection ssl_config. */
Curl_ssl_conn_config_update(data, FALSE);
break;
case CURLOPT_SSL_VERIFYSTATUS:
/*
* Enable certificate status verifying.
*/
if(!Curl_ssl_cert_status_request())
return CURLE_NOT_BUILT_IN;
data->set.ssl.primary.verifystatus = enabled;
/* Update the current connection ssl_config. */
Curl_ssl_conn_config_update(data, FALSE);
break;
case CURLOPT_SSL_FALSESTART:
/*
* Enable TLS false start.
*/
if(!Curl_ssl_false_start())
return CURLE_NOT_BUILT_IN;
data->set.ssl.falsestart = enabled;
break;
case CURLOPT_CERTINFO:
#ifdef USE_SSL
if(Curl_ssl_supports(data, SSLSUPP_CERTINFO))
data->set.ssl.certinfo = enabled;
else
#endif
return CURLE_NOT_BUILT_IN;
break;
case CURLOPT_BUFFERSIZE:
/*
* The application kindly asks for a differently sized receive buffer.
* If it seems reasonable, we will use it.
*/
if(arg > READBUFFER_MAX)
arg = READBUFFER_MAX;
else if(arg < 1)
arg = READBUFFER_SIZE;
else if(arg < READBUFFER_MIN)
arg = READBUFFER_MIN;
data->set.buffer_size = (unsigned int)arg;
break;
case CURLOPT_UPLOAD_BUFFERSIZE:
/*
* The application kindly asks for a differently sized upload buffer.
* Cap it to sensible.
*/
if(arg > UPLOADBUFFER_MAX)
arg = UPLOADBUFFER_MAX;
else if(arg < UPLOADBUFFER_MIN)
arg = UPLOADBUFFER_MIN;
data->set.upload_buffer_size = (unsigned int)arg;
break;
case CURLOPT_NOSIGNAL:
/*
* The application asks not to set any signal() or alarm() handlers,
* even when using a timeout.
*/
data->set.no_signal = enabled;
break;
case CURLOPT_MAXFILESIZE:
/*
* Set the maximum size of a file to download.
*/
if(arg < 0)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.max_filesize = arg;
break;
#ifdef USE_SSL
case CURLOPT_USE_SSL:
/*
* Make transfers attempt to use SSL/TLS.
*/
if((arg < CURLUSESSL_NONE) || (arg >= CURLUSESSL_LAST))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.use_ssl = (unsigned char)arg;
break;
case CURLOPT_SSL_OPTIONS:
data->set.ssl.primary.ssl_options = (unsigned char)(arg & 0xff);
data->set.ssl.enable_beast = !!(arg & CURLSSLOPT_ALLOW_BEAST);
data->set.ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
data->set.ssl.no_partialchain = !!(arg & CURLSSLOPT_NO_PARTIALCHAIN);
data->set.ssl.revoke_best_effort = !!(arg & CURLSSLOPT_REVOKE_BEST_EFFORT);
data->set.ssl.native_ca_store = !!(arg & CURLSSLOPT_NATIVE_CA);
data->set.ssl.auto_client_cert = !!(arg & CURLSSLOPT_AUTO_CLIENT_CERT);
data->set.ssl.earlydata = !!(arg & CURLSSLOPT_EARLYDATA);
/* If a setting is added here it should also be added in dohprobe()
which sets its own CURLOPT_SSL_OPTIONS based on these settings. */
break;
#ifndef CURL_DISABLE_PROXY
case CURLOPT_PROXY_SSL_OPTIONS:
data->set.proxy_ssl.primary.ssl_options = (unsigned char)(arg & 0xff);
data->set.proxy_ssl.enable_beast = !!(arg & CURLSSLOPT_ALLOW_BEAST);
data->set.proxy_ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
data->set.proxy_ssl.no_partialchain = !!(arg & CURLSSLOPT_NO_PARTIALCHAIN);
data->set.proxy_ssl.revoke_best_effort =
!!(arg & CURLSSLOPT_REVOKE_BEST_EFFORT);
data->set.proxy_ssl.native_ca_store = !!(arg & CURLSSLOPT_NATIVE_CA);
data->set.proxy_ssl.auto_client_cert =
!!(arg & CURLSSLOPT_AUTO_CLIENT_CERT);
break;
#endif
#endif /* USE_SSL */
case CURLOPT_IPRESOLVE:
if((arg < CURL_IPRESOLVE_WHATEVER) || (arg > CURL_IPRESOLVE_V6))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.ipver = (unsigned char) arg;
break;
case CURLOPT_TCP_NODELAY:
/*
* Enable or disable TCP_NODELAY, which will disable/enable the Nagle
* algorithm
*/
data->set.tcp_nodelay = enabled;
break;
case CURLOPT_IGNORE_CONTENT_LENGTH:
data->set.ignorecl = enabled;
break;
case CURLOPT_CONNECT_ONLY:
/*
* No data transfer.
* (1) - only do connection
* (2) - do first get request but get no content
*/
if(arg > 2)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.connect_only = !!arg;
data->set.connect_only_ws = (arg == 2);
break;
case CURLOPT_SSL_SESSIONID_CACHE:
data->set.ssl.primary.cache_session = enabled;
#ifndef CURL_DISABLE_PROXY
data->set.proxy_ssl.primary.cache_session =
data->set.ssl.primary.cache_session;
#endif
break;
#ifdef USE_SSH
/* we only include SSH options if explicitly built to support SSH */
case CURLOPT_SSH_AUTH_TYPES:
data->set.ssh_auth_types = (int)arg;
break;
case CURLOPT_SSH_COMPRESSION:
data->set.ssh_compression = enabled;
break;
#endif
case CURLOPT_HTTP_TRANSFER_DECODING:
/*
* disable libcurl transfer encoding is used
*/
#ifndef USE_HYPER
data->set.http_te_skip = !enabled; /* reversed */
break;
#else
return CURLE_NOT_BUILT_IN; /* hyper does not support */
#endif
case CURLOPT_HTTP_CONTENT_DECODING:
/*
* raw data passed to the application when content encoding is used
*/
data->set.http_ce_skip = !enabled; /* reversed */
break;
#if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
case CURLOPT_NEW_FILE_PERMS:
/*
* Uses these permissions instead of 0644
*/
if((arg < 0) || (arg > 0777))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.new_file_perms = (unsigned int)arg;
break;
#endif
#ifdef USE_SSH
case CURLOPT_NEW_DIRECTORY_PERMS:
/*
* Uses these permissions instead of 0755
*/
if((arg < 0) || (arg > 0777))
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.new_directory_perms = (unsigned int)arg;
break;
#endif
#ifdef USE_IPV6
case CURLOPT_ADDRESS_SCOPE:
/*
* Use this scope id when using IPv6
* We always get longs when passed plain numericals so we should check
* that the value fits into an unsigned 32-bit integer.
*/
#if SIZEOF_LONG > 4
if(uarg > UINT_MAX)
return CURLE_BAD_FUNCTION_ARGUMENT;
#endif
data->set.scope_id = (unsigned int)uarg;
break;
#endif
case CURLOPT_PROTOCOLS:
/* set the bitmask for the protocols that are allowed to be used for the
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 = (curl_prot_t)arg;
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 = (curl_prot_t)arg;
break;
#ifndef CURL_DISABLE_SMTP
case CURLOPT_MAIL_RCPT_ALLOWFAILS:
/* allow RCPT TO command to fail for some recipients */
data->set.mail_rcpt_allowfails = enabled;
break;
#endif /* !CURL_DISABLE_SMTP */
case CURLOPT_SASL_IR:
/* Enable/disable SASL initial response */
data->set.sasl_ir = enabled;
break;
#ifndef CURL_DISABLE_RTSP
case CURLOPT_RTSP_REQUEST:
{
/*
* Set the RTSP request method (OPTIONS, SETUP, PLAY, etc...)
* Would this be better if the RTSPREQ_* were just moved into here?
*/
Curl_RtspReq rtspreq = RTSPREQ_NONE;
switch(arg) {
case CURL_RTSPREQ_OPTIONS:
rtspreq = RTSPREQ_OPTIONS;
break;
case CURL_RTSPREQ_DESCRIBE:
rtspreq = RTSPREQ_DESCRIBE;
break;
case CURL_RTSPREQ_ANNOUNCE:
rtspreq = RTSPREQ_ANNOUNCE;
break;
case CURL_RTSPREQ_SETUP:
rtspreq = RTSPREQ_SETUP;
break;
case CURL_RTSPREQ_PLAY:
rtspreq = RTSPREQ_PLAY;
break;
case CURL_RTSPREQ_PAUSE:
rtspreq = RTSPREQ_PAUSE;
break;
case CURL_RTSPREQ_TEARDOWN:
rtspreq = RTSPREQ_TEARDOWN;
break;
case CURL_RTSPREQ_GET_PARAMETER:
rtspreq = RTSPREQ_GET_PARAMETER;
break;
case CURL_RTSPREQ_SET_PARAMETER:
rtspreq = RTSPREQ_SET_PARAMETER;
break;
case CURL_RTSPREQ_RECORD:
rtspreq = RTSPREQ_RECORD;
break;
case CURL_RTSPREQ_RECEIVE:
rtspreq = RTSPREQ_RECEIVE;
break;
default:
return CURLE_BAD_FUNCTION_ARGUMENT;
}
data->set.rtspreq = rtspreq;
break;
}
case CURLOPT_RTSP_CLIENT_CSEQ:
/*
* Set the CSEQ number to issue for the next RTSP request. Useful if the
* application is resuming a previously broken connection. The CSEQ
* will increment from this new number henceforth.
*/
data->state.rtsp_next_client_CSeq = arg;
break;
case CURLOPT_RTSP_SERVER_CSEQ:
/* Same as the above, but for server-initiated requests */
data->state.rtsp_next_server_CSeq = arg;
break;
#endif /* ! CURL_DISABLE_RTSP */
case CURLOPT_TCP_KEEPALIVE:
data->set.tcp_keepalive = enabled;
break;
case CURLOPT_TCP_KEEPIDLE:
if(arg < 0)
return CURLE_BAD_FUNCTION_ARGUMENT;
else if(arg > INT_MAX)
arg = INT_MAX;
data->set.tcp_keepidle = (int)arg;
break;
case CURLOPT_TCP_KEEPINTVL:
if(arg < 0)
return CURLE_BAD_FUNCTION_ARGUMENT;
else if(arg > INT_MAX)
arg = INT_MAX;
data->set.tcp_keepintvl = (int)arg;
break;
case CURLOPT_TCP_KEEPCNT:
if(arg < 0)
return CURLE_BAD_FUNCTION_ARGUMENT;
else if(arg > INT_MAX)
arg = INT_MAX;
data->set.tcp_keepcnt = (int)arg;
break;
case CURLOPT_TCP_FASTOPEN:
#if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN) || \
defined(TCP_FASTOPEN_CONNECT)
data->set.tcp_fastopen = enabled;
#else
return CURLE_NOT_BUILT_IN;
#endif
break;
case CURLOPT_SSL_ENABLE_NPN:
break;
case CURLOPT_SSL_ENABLE_ALPN:
data->set.ssl_enable_alpn = enabled;
break;
case CURLOPT_PATH_AS_IS:
data->set.path_as_is = enabled;
break;
case CURLOPT_PIPEWAIT:
data->set.pipewait = enabled;
break;
case CURLOPT_STREAM_WEIGHT:
#if defined(USE_HTTP2) || defined(USE_HTTP3)
if((arg >= 1) && (arg <= 256))
data->set.priority.weight = (int)arg;
break;
#else
return CURLE_NOT_BUILT_IN;
#endif
case CURLOPT_SUPPRESS_CONNECT_HEADERS:
data->set.suppress_connect_headers = enabled;
break;
case CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS:
if(uarg > UINT_MAX)
uarg = UINT_MAX;
data->set.happy_eyeballs_timeout = (unsigned int)uarg;
break;
#ifndef CURL_DISABLE_SHUFFLE_DNS
case CURLOPT_DNS_SHUFFLE_ADDRESSES:
data->set.dns_shuffle_addresses = enabled;
break;
#endif
case CURLOPT_DISALLOW_USERNAME_IN_URL:
data->set.disallow_username_in_url = enabled;
break;
case CURLOPT_UPKEEP_INTERVAL_MS:
if(arg < 0)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.upkeep_interval_ms = arg;
break;
case CURLOPT_MAXAGE_CONN:
if(arg < 0)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.maxage_conn = arg;
break;
case CURLOPT_MAXLIFETIME_CONN:
if(arg < 0)
return CURLE_BAD_FUNCTION_ARGUMENT;
data->set.maxlifetime_conn = arg;
break;
#ifndef CURL_DISABLE_HSTS
case CURLOPT_HSTS_CTRL:
if(arg & CURLHSTS_ENABLE) {
if(!data->hsts) {
data->hsts = Curl_hsts_init();
if(!data->hsts)
return CURLE_OUT_OF_MEMORY;
}
}
else
Curl_hsts_cleanup(&data->hsts);
break;
#endif /* ! CURL_DISABLE_HSTS */
#ifndef CURL_DISABLE_ALTSVC
case CURLOPT_ALTSVC_CTRL:
if(!arg) {
DEBUGF(infof(data, "bad CURLOPT_ALTSVC_CTRL input"));
return CURLE_BAD_FUNCTION_ARGUMENT;
}
if(!data->asi) {
data->asi = Curl_altsvc_init();
if(!data->asi)
return CURLE_OUT_OF_MEMORY;
}
return Curl_altsvc_ctrl(data->asi, arg);
#endif /* ! CURL_DISABLE_ALTSVC */
#ifndef CURL_DISABLE_WEBSOCKETS
case CURLOPT_WS_OPTIONS:
data->set.ws_raw_mode = (bool)(arg & CURLWS_RAW_MODE);
break;
#endif
case CURLOPT_QUICK_EXIT:
data->set.quick_exit = enabled;
break;
case CURLOPT_DNS_USE_GLOBAL_CACHE:
/* deprecated */
break;
case CURLOPT_SSLENGINE_DEFAULT:
/*
* flag to set engine as default.
*/
Curl_safefree(data->set.str[STRING_SSL_ENGINE]);
return Curl_ssl_set_engine_default(data);
default:
/* unknown option */
return CURLE_UNKNOWN_OPTION;
}
return CURLE_OK;
}