aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Holme <steve_holme@hotmail.com>2014-02-14 21:59:51 +0000
committerSteve Holme <steve_holme@hotmail.com>2014-02-15 16:31:32 +0000
commitf80ca7a05a2affce7b02f618592981aa02e61ce7 (patch)
treed1b2ec919870d044c51391826dfde3caa92ed7fe
parent89070d0e680402fd92468eb13073434ea5e5380e (diff)
tool_operate: Moved required argument getting into separate function
-rw-r--r--src/tool_operate.c24
-rw-r--r--src/tool_operhlp.c10
-rw-r--r--src/tool_operhlp.h2
-rw-r--r--src/tool_paramhlp.c42
-rw-r--r--src/tool_paramhlp.h2
5 files changed, 46 insertions, 34 deletions
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 0ecbcada9..fc54819ea 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -234,32 +234,18 @@ static int operate_do(struct Configurable *config)
** from outside of nested loops further down below.
*/
- if(config->userpwd && !config->xoauth2_bearer) {
- res = checkpasswd("host", &config->userpwd);
- if(res)
- goto quit_curl;
- }
-
- if(config->proxyuserpwd) {
- res = checkpasswd("proxy", &config->proxyuserpwd);
- if(res)
- goto quit_curl;
- }
+ /* Get the required aguments */
+ res = get_args(config);
+ if(res)
+ goto quit_curl;
+ /* Check we have a url */
if(!config->url_list || !config->url_list->url) {
helpf(config->errors, "no URL specified!\n");
res = CURLE_FAILED_INIT;
goto quit_curl;
}
- if(!config->useragent)
- config->useragent = my_useragent();
- if(!config->useragent) {
- helpf(config->errors, "out of memory\n");
- res = CURLE_OUT_OF_MEMORY;
- goto quit_curl;
- }
-
/* On WIN32 we can't set the path to curl-ca-bundle.crt
* at compile time. So we look here for the file in two ways:
* 1: look at the environment variable CURL_CA_BUNDLE for a path
diff --git a/src/tool_operhlp.c b/src/tool_operhlp.c
index a9dab9b80..a0da01c8d 100644
--- a/src/tool_operhlp.c
+++ b/src/tool_operhlp.c
@@ -30,20 +30,11 @@
#include "tool_cfgable.h"
#include "tool_convert.h"
#include "tool_operhlp.h"
-#include "tool_version.h"
#include "tool_metalink.h"
#include "memdebug.h" /* keep this as LAST include */
/*
- * my_useragent: returns allocated string with default user agent
- */
-char *my_useragent(void)
-{
- return strdup( CURL_NAME "/" CURL_VERSION );
-}
-
-/*
* Print list of OpenSSL supported engines
*/
void list_engines(const struct curl_slist *engines)
@@ -192,4 +183,3 @@ CURLcode get_url_file_name(char **filename, const char *url)
return CURLE_OK;
}
-
diff --git a/src/tool_operhlp.h b/src/tool_operhlp.h
index 7ca12362b..bfe298bf1 100644
--- a/src/tool_operhlp.h
+++ b/src/tool_operhlp.h
@@ -23,8 +23,6 @@
***************************************************************************/
#include "tool_setup.h"
-char *my_useragent(void);
-
void list_engines(const struct curl_slist *engines);
void clean_getout(struct Configurable *config);
diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c
index 46e926952..6dcee8d5f 100644
--- a/src/tool_paramhlp.c
+++ b/src/tool_paramhlp.c
@@ -33,6 +33,7 @@
#include "tool_homedir.h"
#include "tool_msgs.h"
#include "tool_paramhlp.h"
+#include "tool_version.h"
#include "memdebug.h" /* keep this as LAST include */
@@ -365,8 +366,8 @@ ParameterError str2offset(curl_off_t *val, const char *str)
return PARAM_BAD_NUMERIC;
}
-CURLcode checkpasswd(const char *kind, /* for what purpose */
- char **userpwd) /* pointer to allocated string */
+static CURLcode checkpasswd(const char *kind, /* for what purpose */
+ char **userpwd) /* pointer to allocated string */
{
char *psep;
char *osep;
@@ -464,3 +465,40 @@ long delegation(struct Configurable *config, char *str)
return CURLGSSAPI_DELEGATION_NONE;
}
+/*
+ * my_useragent: returns allocated string with default user agent
+ */
+static char *my_useragent(void)
+{
+ return strdup(CURL_NAME "/" CURL_VERSION);
+}
+
+CURLcode get_args(struct Configurable *config)
+{
+ CURLcode result = CURLE_OK;
+
+ /* Check we have a password for the given host user */
+ if(config->userpwd && !config->xoauth2_bearer) {
+ result = checkpasswd("host", &config->userpwd);
+ if(result)
+ return result;
+ }
+
+ /* Check we have a password for the given proxy user */
+ if(config->proxyuserpwd) {
+ result = checkpasswd("proxy", &config->proxyuserpwd);
+ if(result)
+ return result;
+ }
+
+ /* Check we have a user agent */
+ if(!config->useragent) {
+ config->useragent = my_useragent();
+ if(!config->useragent) {
+ helpf(config->errors, "out of memory\n");
+ result = CURLE_OUT_OF_MEMORY;
+ }
+ }
+
+ return result;
+}
diff --git a/src/tool_paramhlp.h b/src/tool_paramhlp.h
index 3722e9375..844137445 100644
--- a/src/tool_paramhlp.h
+++ b/src/tool_paramhlp.h
@@ -40,7 +40,7 @@ long proto2num(struct Configurable *config, long *val, const char *str);
ParameterError str2offset(curl_off_t *val, const char *str);
-CURLcode checkpasswd(const char *kind, char **userpwd);
+CURLcode get_args(struct Configurable *config);
ParameterError add2list(struct curl_slist **list, const char *ptr);