summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/url.c2
-rw-r--r--src/tool_getparam.c72
-rw-r--r--src/tool_getparam.h2
-rw-r--r--src/tool_paramhlp.c18
-rw-r--r--src/tool_paramhlp.h6
-rw-r--r--tests/libtest/libauthretry.c36
6 files changed, 66 insertions, 70 deletions
diff --git a/lib/url.c b/lib/url.c
index 601d8d364..a781798e9 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2943,7 +2943,7 @@ ConnectionExists(struct SessionHandle *data,
struct connectdata *chosen = 0;
bool canPipeline = IsPipeliningPossible(data, needle);
bool wantNTLM = (data->state.authhost.want==CURLAUTH_NTLM) ||
- (data->state.authhost.want==CURLAUTH_NTLM_WB);
+ (data->state.authhost.want==CURLAUTH_NTLM_WB) ? TRUE : FALSE;
for(i=0; i< data->state.connc->num; i++) {
bool match = FALSE;
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index 685c224de..f3d72eeed 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -398,9 +398,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
GetStr(&config->egd_file, nextarg);
break;
case 'c': /* connect-timeout */
- rc=str2unum(&config->connecttimeout, nextarg);
- if(rc)
- return rc;
+ err = str2unum(&config->connecttimeout, nextarg);
+ if(err)
+ return err;
break;
case 'd': /* ciphers */
GetStr(&config->cipher_list, nextarg);
@@ -545,9 +545,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
case 's': /* --max-redirs */
/* specified max no of redirects (http(s)), this accepts -1 as a
special condition */
- rc = str2num(&config->maxredirs, nextarg);
- if(rc)
- return rc;
+ err = str2num(&config->maxredirs, nextarg);
+ if(err)
+ return err;
if(config->maxredirs < -1)
return PARAM_BAD_NUMERIC;
break;
@@ -592,9 +592,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
return PARAM_LIBCURL_DOESNT_SUPPORT;
break;
case 'y': /* --max-filesize */
- rc = str2offset(&config->max_filesize, nextarg);
- if(rc)
- return rc;
+ err = str2offset(&config->max_filesize, nextarg);
+ if(err)
+ return err;
break;
case 'z': /* --disable-eprt */
config->disable_eprt = toggle;
@@ -670,19 +670,19 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
config->proxybasic = toggle;
break;
case 'g': /* --retry */
- rc = str2unum(&config->req_retry, nextarg);
- if(rc)
- return rc;
+ err = str2unum(&config->req_retry, nextarg);
+ if(err)
+ return err;
break;
case 'h': /* --retry-delay */
- rc = str2unum(&config->retry_delay, nextarg);
- if(rc)
- return rc;
+ err = str2unum(&config->retry_delay, nextarg);
+ if(err)
+ return err;
break;
case 'i': /* --retry-max-time */
- rc = str2unum(&config->retry_maxtime, nextarg);
- if(rc)
- return rc;
+ err = str2unum(&config->retry_maxtime, nextarg);
+ if(err)
+ return err;
break;
case 'k': /* --proxy-negotiate */
@@ -769,9 +769,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
config->nokeepalive = (!toggle)?TRUE:FALSE;
break;
case '3': /* --keepalive-time */
- rc = str2unum(&config->alivetime, nextarg);
- if(rc)
- return rc;
+ err = str2unum(&config->alivetime, nextarg);
+ if(err)
+ return err;
break;
case '4': /* --post302 */
config->post302 = toggle;
@@ -797,9 +797,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
config->proxyver = CURLPROXY_HTTP_1_0;
break;
case '9': /* --tftp-blksize */
- rc = str2unum(&config->tftp_blksize, nextarg);
- if(rc)
- return rc;
+ err = str2unum(&config->tftp_blksize, nextarg);
+ if(err)
+ return err;
break;
case 'A': /* --mail-from */
GetStr(&config->mail_from, nextarg);
@@ -924,9 +924,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
case 'C':
/* This makes us continue an ftp transfer at given position */
if(!curlx_strequal(nextarg, "-")) {
- rc = str2offset(&config->resume_from, nextarg);
- if(rc)
- return rc;
+ err = str2offset(&config->resume_from, nextarg);
+ if(err)
+ return err;
config->resume_from_current = FALSE;
}
else {
@@ -1317,9 +1317,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
break;
case 'm':
/* specified max time */
- rc = str2unum(&config->timeout, nextarg);
- if(rc)
- return rc;
+ err = str2unum(&config->timeout, nextarg);
+ if(err)
+ return err;
break;
case 'M': /* M for manual, huge help */
if(toggle) { /* --no-manual shows no manual... */
@@ -1633,17 +1633,17 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
break;
case 'y':
/* low speed time */
- rc = str2unum(&config->low_speed_time, nextarg);
- if(rc)
- return rc;
+ err = str2unum(&config->low_speed_time, nextarg);
+ if(err)
+ return err;
if(!config->low_speed_limit)
config->low_speed_limit = 1;
break;
case 'Y':
/* low speed limit */
- rc = str2unum(&config->low_speed_limit, nextarg);
- if(rc)
- return rc;
+ err = str2unum(&config->low_speed_limit, nextarg);
+ if(err)
+ return err;
if(!config->low_speed_time)
config->low_speed_time = 30;
break;
diff --git a/src/tool_getparam.h b/src/tool_getparam.h
index 49cc684c9..38f0674f4 100644
--- a/src/tool_getparam.h
+++ b/src/tool_getparam.h
@@ -24,7 +24,7 @@
#include "tool_setup.h"
typedef enum {
- PARAM_OK,
+ PARAM_OK = 0,
PARAM_OPTION_AMBIGUOUS,
PARAM_OPTION_UNKNOWN,
PARAM_REQUIRES_PARAMETER,
diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c
index 85912a2ef..5d6f8bbc5 100644
--- a/src/tool_paramhlp.c
+++ b/src/tool_paramhlp.c
@@ -146,15 +146,15 @@ void cleanarg(char *str)
}
/*
- * Parse the string and write the long in the given address. Return non-zero
- * on failure, zero on success.
+ * Parse the string and write the long in the given address. Return PARAM_OK
+ * on success, otherwise a parameter specific error enum.
*
* Since this function gets called with the 'nextarg' pointer from within the
* getparameter a lot, we must check it for NULL before accessing the str
* data.
*/
-int str2num(long *val, const char *str)
+ParameterError str2num(long *val, const char *str)
{
if(str) {
char *endptr;
@@ -168,15 +168,15 @@ int str2num(long *val, const char *str)
}
/*
- * Parse the string and write the long in the given address. Return non-zero
- * on failure, zero on success. ONLY ACCEPTS POSITIVE NUMBERS!
+ * Parse the string and write the long in the given address. Return PARAM_OK
+ * on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS!
*
* Since this function gets called with the 'nextarg' pointer from within the
* getparameter a lot, we must check it for NULL before accessing the str
* data.
*/
-int str2unum(long *val, const char *str)
+ParameterError str2unum(long *val, const char *str)
{
if(str[0]=='-')
return PARAM_NEGATIVE_NUMERIC; /* badness */
@@ -295,9 +295,9 @@ long proto2num(struct Configurable *config, long *val, const char *str)
*
* @param val the offset to populate
* @param str the buffer containing the offset
- * @return zero if successful, non-zero if failure.
+ * @return PARAM_OK if successful, a parameter specific error enum if failure.
*/
-int str2offset(curl_off_t *val, const char *str)
+ParameterError str2offset(curl_off_t *val, const char *str)
{
char *endptr;
if(str[0] == '-')
@@ -314,7 +314,7 @@ int str2offset(curl_off_t *val, const char *str)
return PARAM_BAD_NUMERIC;
#endif
if((endptr != str) && (endptr == str + strlen(str)))
- return 0; /* Ok */
+ return PARAM_OK;
return PARAM_BAD_NUMERIC;
}
diff --git a/src/tool_paramhlp.h b/src/tool_paramhlp.h
index 50c693efd..de1604e90 100644
--- a/src/tool_paramhlp.h
+++ b/src/tool_paramhlp.h
@@ -31,12 +31,12 @@ ParameterError file2memory(char **bufp, size_t *size, FILE *file);
void cleanarg(char *str);
-int str2num(long *val, const char *str);
-int str2unum(long *val, const char *str); /* for unsigned input numbers */
+ParameterError str2num(long *val, const char *str);
+ParameterError str2unum(long *val, const char *str);
long proto2num(struct Configurable *config, long *val, const char *str);
-int str2offset(curl_off_t *val, const char *str);
+ParameterError str2offset(curl_off_t *val, const char *str);
ParameterError checkpasswd(const char *kind, char **userpwd);
diff --git a/tests/libtest/libauthretry.c b/tests/libtest/libauthretry.c
index 0b0816eab..95761325a 100644
--- a/tests/libtest/libauthretry.c
+++ b/tests/libtest/libauthretry.c
@@ -28,8 +28,8 @@
#include "strequal.h"
#include "memdebug.h"
-static int send_request(CURL *curl, const char *url, int seq,
- long auth_scheme, const char *userpwd)
+static CURLcode send_request(CURL *curl, const char *url, int seq,
+ long auth_scheme, const char *userpwd)
{
CURLcode res;
char* full_url = malloc(strlen(url) + 4 + 1);
@@ -56,14 +56,14 @@ test_cleanup:
return res;
}
-static int send_wrong_password(CURL *curl, const char *url, int seq,
- long auth_scheme)
+static CURLcode send_wrong_password(CURL *curl, const char *url, int seq,
+ long auth_scheme)
{
return send_request(curl, url, seq, auth_scheme, "testuser:wrongpass");
}
-static int send_right_password(CURL *curl, const char *url, int seq,
- long auth_scheme)
+static CURLcode send_right_password(CURL *curl, const char *url, int seq,
+ long auth_scheme)
{
return send_request(curl, url, seq, auth_scheme, "testuser:testpass");
}
@@ -85,7 +85,6 @@ int test(char *url)
{
CURLcode res;
CURL *curl = NULL;
- bool curl_is_init = FALSE;
long main_auth_scheme = parse_auth_name(libtest_arg2);
long fallback_auth_scheme = parse_auth_name(libtest_arg3);
@@ -93,29 +92,27 @@ int test(char *url)
if (main_auth_scheme == CURLAUTH_NONE ||
fallback_auth_scheme == CURLAUTH_NONE) {
fprintf(stderr, "auth schemes not found on commandline\n");
- res = TEST_ERR_MAJOR_BAD;
- goto test_cleanup;
+ return TEST_ERR_MAJOR_BAD;
}
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
fprintf(stderr, "curl_global_init() failed\n");
- res = TEST_ERR_MAJOR_BAD;
- goto test_cleanup;
+ return TEST_ERR_MAJOR_BAD;
}
- curl_is_init = TRUE;
/* Send wrong password, then right password */
if ((curl = curl_easy_init()) == NULL) {
fprintf(stderr, "curl_easy_init() failed\n");
- res = TEST_ERR_MAJOR_BAD;
- goto test_cleanup;
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
}
res = send_wrong_password(curl, url, 100, main_auth_scheme);
if (res != CURLE_OK)
goto test_cleanup;
curl_easy_reset(curl);
+
res = send_right_password(curl, url, 200, fallback_auth_scheme);
if (res != CURLE_OK)
goto test_cleanup;
@@ -127,8 +124,8 @@ int test(char *url)
if ((curl = curl_easy_init()) == NULL) {
fprintf(stderr, "curl_easy_init() failed\n");
- res = TEST_ERR_MAJOR_BAD;
- goto test_cleanup;
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
}
res = send_wrong_password(curl, url, 300, main_auth_scheme);
@@ -140,6 +137,7 @@ int test(char *url)
if (res != CURLE_OK)
goto test_cleanup;
curl_easy_reset(curl);
+
res = send_right_password(curl, url, 500, fallback_auth_scheme);
if (res != CURLE_OK)
goto test_cleanup;
@@ -147,10 +145,8 @@ int test(char *url)
test_cleanup:
- if (curl)
- curl_easy_cleanup(curl);
- if (curl_is_init)
- curl_global_cleanup();
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
return (int)res;
}