mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
Simplified the code within curl_easy_perform() that calls Curl_perform().
Pointed out by Bjorn Reese.
This commit is contained in:
parent
decae2dcda
commit
4922904991
36
lib/easy.c
36
lib/easy.c
@ -308,49 +308,19 @@ CURL *curl_easy_init(void)
|
|||||||
* curl_easy_setopt() is the external interface for setting options on an
|
* curl_easy_setopt() is the external interface for setting options on an
|
||||||
* easy handle.
|
* easy handle.
|
||||||
*/
|
*/
|
||||||
typedef int (*func_T)(void);
|
|
||||||
CURLcode curl_easy_setopt(CURL *curl, CURLoption tag, ...)
|
CURLcode curl_easy_setopt(CURL *curl, CURLoption tag, ...)
|
||||||
{
|
{
|
||||||
va_list arg;
|
va_list arg;
|
||||||
func_T param_func = (func_T)0;
|
|
||||||
long param_long = 0;
|
|
||||||
void *param_obj = NULL;
|
|
||||||
curl_off_t param_offset = 0;
|
|
||||||
struct SessionHandle *data = curl;
|
struct SessionHandle *data = curl;
|
||||||
CURLcode ret=CURLE_FAILED_INIT;
|
CURLcode ret;
|
||||||
|
|
||||||
if(!curl)
|
if(!curl)
|
||||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||||
|
|
||||||
va_start(arg, tag);
|
va_start(arg, tag);
|
||||||
|
|
||||||
/* PORTING NOTE:
|
ret = Curl_setopt(data, tag, arg);
|
||||||
Object pointers can't necessarily be casted to function pointers and
|
|
||||||
therefore we need to know what type it is and read the correct type
|
|
||||||
at once. This should also correct problems with different sizes of
|
|
||||||
the types.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(tag < CURLOPTTYPE_OBJECTPOINT) {
|
|
||||||
/* This is a LONG type */
|
|
||||||
param_long = va_arg(arg, long);
|
|
||||||
ret = Curl_setopt(data, tag, param_long);
|
|
||||||
}
|
|
||||||
else if(tag < CURLOPTTYPE_FUNCTIONPOINT) {
|
|
||||||
/* This is a object pointer type */
|
|
||||||
param_obj = va_arg(arg, void *);
|
|
||||||
ret = Curl_setopt(data, tag, param_obj);
|
|
||||||
}
|
|
||||||
else if(tag < CURLOPTTYPE_OFF_T) {
|
|
||||||
/* This is a function pointer type */
|
|
||||||
param_func = va_arg(arg, func_T );
|
|
||||||
ret = Curl_setopt(data, tag, param_func);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* This is a curl_off_t type */
|
|
||||||
param_offset = va_arg(arg, curl_off_t);
|
|
||||||
ret = Curl_setopt(data, tag, param_offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -372,14 +372,12 @@ CURLcode Curl_open(struct SessionHandle **curl)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...)
|
CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
||||||
|
va_list param)
|
||||||
{
|
{
|
||||||
va_list param;
|
|
||||||
char *argptr;
|
char *argptr;
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
|
|
||||||
va_start(param, option);
|
|
||||||
|
|
||||||
switch(option) {
|
switch(option) {
|
||||||
case CURLOPT_DNS_CACHE_TIMEOUT:
|
case CURLOPT_DNS_CACHE_TIMEOUT:
|
||||||
data->set.dns_cache_timeout = va_arg(param, int);
|
data->set.dns_cache_timeout = va_arg(param, int);
|
||||||
|
@ -23,12 +23,15 @@
|
|||||||
* $Id$
|
* $Id$
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <stdarg.h> /* to make sure we have ap_list */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prototypes for library-wide functions provided by url.c
|
* Prototypes for library-wide functions provided by url.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CURLcode Curl_open(struct SessionHandle **curl);
|
CURLcode Curl_open(struct SessionHandle **curl);
|
||||||
CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...);
|
CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
||||||
|
va_list arg);
|
||||||
CURLcode Curl_close(struct SessionHandle *data); /* opposite of curl_open() */
|
CURLcode Curl_close(struct SessionHandle *data); /* opposite of curl_open() */
|
||||||
CURLcode Curl_connect(struct SessionHandle *, struct connectdata **,
|
CURLcode Curl_connect(struct SessionHandle *, struct connectdata **,
|
||||||
bool *async, bool *protocol_connect);
|
bool *async, bool *protocol_connect);
|
||||||
|
Loading…
Reference in New Issue
Block a user