]> granicus.if.org Git - curl/commitdiff
url: Added support for parsing login options from the CURLOPT_USERPWD
authorSteve Holme <steve_holme@hotmail.com>
Sat, 20 Apr 2013 07:47:59 +0000 (08:47 +0100)
committerSteve Holme <steve_holme@hotmail.com>
Sat, 20 Apr 2013 08:08:28 +0000 (09:08 +0100)
In addition to parsing the optional login options from the URL, added
support for parsing them from CURLOPT_USERPWD, to allow the following
supported command line:

--user username:password;options

lib/url.c
lib/urldata.h

index 3563f08535fe51bc0f0416bcb8f399544e95fd86..684d3fddfd2101a28cad5b08e8d74436fa3c13c5 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -298,43 +298,52 @@ static CURLcode setstropt(char **charp, char * s)
 }
 
 static CURLcode setstropt_userpwd(char *option, char **user_storage,
-                                  char **pwd_storage)
+                                  char **pwd_storage, char **options_storage)
 {
-  char* separator;
   CURLcode result = CURLE_OK;
+  char *userp = NULL;
+  char *passwdp = NULL;
+  char *optionsp = NULL;
 
   if(!option) {
     /* we treat a NULL passed in as a hint to clear existing info */
-    Curl_safefree(*user_storage);
-    *user_storage = (char *) NULL;
-    Curl_safefree(*pwd_storage);
-    *pwd_storage = (char *) NULL;
+    if(user_storage) {
+      Curl_safefree(*user_storage);
+      *user_storage = (char *) NULL;
+    }
+
+    if(pwd_storage) {
+      Curl_safefree(*pwd_storage);
+      *pwd_storage = (char *) NULL;
+    }
+
+    if(options_storage) {
+      Curl_safefree(*options_storage);
+      *options_storage = (char *) NULL;
+    }
+
     return CURLE_OK;
   }
 
-  separator = strchr(option, ':');
-  if(separator != NULL) {
-
+  /* Parse the login details */
+  result = parse_login_details(option, strlen(option),
+                               (user_storage ? &userp : NULL),
+                               (pwd_storage ? &passwdp : NULL),
+                               (options_storage ? &optionsp : NULL));
+  if(!result) {
     /* store username part of option */
-    char * p;
-    size_t username_len = (size_t)(separator-option);
-    p = malloc(username_len+1);
-    if(!p)
-      result = CURLE_OUT_OF_MEMORY;
-    else {
-      memcpy(p, option, username_len);
-      p[username_len] = '\0';
-      Curl_safefree(*user_storage);
-      *user_storage = p;
-    }
+    if(user_storage)
+      setstropt(user_storage, userp);
 
     /* store password part of option */
-    if(result == CURLE_OK)
-      result = setstropt(pwd_storage, separator+1);
-  }
-  else {
-    result = setstropt(user_storage, option);
+    if(pwd_storage)
+      setstropt(pwd_storage, passwdp);
+
+    /* store options part of option */
+    if(options_storage)
+      setstropt(options_storage, optionsp);
   }
+
   return result;
 }
 
@@ -1537,11 +1546,12 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
 
   case CURLOPT_USERPWD:
     /*
-     * user:password to use in the operation
+     * user:password;options to use in the operation
      */
     result = setstropt_userpwd(va_arg(param, char *),
                                &data->set.str[STRING_USERNAME],
-                               &data->set.str[STRING_PASSWORD]);
+                               &data->set.str[STRING_PASSWORD],
+                               &data->set.str[STRING_OPTIONS]);
     break;
   case CURLOPT_USERNAME:
     /*
@@ -1614,7 +1624,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
      */
     result = setstropt_userpwd(va_arg(param, char *),
                                &data->set.str[STRING_PROXYUSERNAME],
-                               &data->set.str[STRING_PROXYPASSWORD]);
+                               &data->set.str[STRING_PROXYPASSWORD], NULL);
     break;
   case CURLOPT_PROXYUSERNAME:
     /*
index 13a01d4b3c095dfb703e4c836d03f85607c997ff..39ef82367fac60d23639cb2045244a87adb81321 100644 (file)
@@ -1355,6 +1355,7 @@ enum dupstring {
   STRING_SSL_ISSUERCERT,  /* issuer cert file to check certificate */
   STRING_USERNAME,        /* <username>, if used */
   STRING_PASSWORD,        /* <password>, if used */
+  STRING_OPTIONS,         /* <options>, if used */
   STRING_PROXYUSERNAME,   /* Proxy <username>, if used */
   STRING_PROXYPASSWORD,   /* Proxy <password>, if used */
   STRING_NOPROXY,         /* List of hosts which should not use the proxy, if