- Igor Novoseltsev added CURLOPT_PROXYUSER and CURLOPT_PROXYPASSWORD that then
authorDaniel Stenberg <daniel@haxx.se>
Thu, 16 Oct 2008 20:21:22 +0000 (20:21 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 16 Oct 2008 20:21:22 +0000 (20:21 +0000)
  make CURLOPT_PROXYUSERPWD sort of deprecated. The primary motive for adding
  these new options is that they have no problems with the colon separator
  that the CURLOPT_PROXYUSERPWD option does.

CHANGES
RELEASE-NOTES
docs/KNOWN_BUGS
docs/libcurl/curl_easy_setopt.3
include/curl/curl.h
include/curl/typecheck-gcc.h
lib/url.c
lib/urldata.h

diff --git a/CHANGES b/CHANGES
index d16b3ed..ff90a0c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,12 @@
 
                                   Changelog
 
+Daniel Stenberg (16 Oct 2008)
+- Igor Novoseltsev added CURLOPT_PROXYUSER and CURLOPT_PROXYPASSWORD that then
+  make CURLOPT_PROXYUSERPWD sort of deprecated. The primary motive for adding
+  these new options is that they have no problems with the colon separator
+  that the CURLOPT_PROXYUSERPWD option does.
+
 Daniel Stenberg (15 Oct 2008)
 - Pascal Terjan filed bug #2154627
   (http://curl.haxx.se/bug/view.cgi?id=2154627) which pointed out that libcurl
index cba3eed..bf78c15 100644 (file)
@@ -2,7 +2,7 @@ Curl and libcurl 7.19.1
 
  Public curl releases:         107
  Command line options:         128
- curl_easy_setopt() options:   156
+ curl_easy_setopt() options:   158
  Public functions in libcurl:  58
  Known libcurl bindings:       37
  Contributors:                 672
@@ -16,6 +16,7 @@ This release includes the following changes:
  o configure --disable-proxy disables proxy
  o Added CURLOPT_USERNAME and CURLOPT_PASSWORD
  o --interface now works with IPv6 connections on glibc systems
+ o Added CURLOPT_PROXYUSER and CURLOPT_PROXYPASSWORD
 
 This release includes the following bugfixes:
 
index dcc693c..e9ecd51 100644 (file)
@@ -160,11 +160,6 @@ may have been fixed since this was written!
   doesn't do a HEAD first to get the initial size. This needs to be done
   manually for HTTP PUT resume to work, and then '-C [index]'.
 
-7. CURLOPT_PROXYUSERPWD has no way of providing user names that contain a
-  colon. This can't be fixed easily in a backwards compatible way without
-  adding new options. CURLOPT_USERPWD was split into CURLOPT_USERNAME and
-  CURLOPT_PASSWORD for this reason.
-
 6. libcurl ignores empty path parts in FTP URLs, whereas RFC1738 states that
   such parts should be sent to the server as 'CWD ' (without an argument).
   The only exception to this rule, is that we knowingly break this if the
index cface44..9759e8f 100644 (file)
@@ -620,6 +620,26 @@ password to use for the transfer.
 
 The CURLOPT_PASSWORD option should be used in conjunction with
 as the \fICURLOPT_USERNAME\fP option. (Added in 7.19.1)
+.IP CURLOPT_PROXYUSERNAME\r
+Pass a char * as parameter, which should be pointing to the zero terminated\r
+user name to use for the transfer while connecting to Proxy.\r
+\r
+The CURLOPT_PROXYUSERNAME option should be used in same way as the\r
+\fICURLOPT_PROXYUSERPWD\fP is used.  In comparison to \fICURLOPT_PROXYUSERPWD\fP\r
+the CURLOPT_PROXYUSERNAME allows the username to contain colon,\r
+like in following example: "sip:user@example.com".\r
+Note the CURLOPT_PROXYUSERNAME option is an alternative way to set the user name\r
+while connecting to Proxy.  There is no meaning to use it together\r
+with the \fICURLOPT_PROXYUSERPWD\fP option.\r
+\r
+In order to specify the password to be used in conjunction with the user name\r
+use the \fICURLOPT_PROXYPASSWORD\fP option.  (Added in 7.19.1)\r
+.IP CURLOPT_PROXYPASSWORD\r
+Pass a char * as parameter, which should be pointing to the zero terminated\r
+password to use for the transfer while connecting to Proxy.\r
+\r
+The CURLOPT_PROXYPASSWORD option should be used in conjunction with\r
+as the \fICURLOPT_PROXYUSERNAME\fP option. (Added in 7.19.1)\r
 .IP CURLOPT_HTTPAUTH
 Pass a long as parameter, which is set to a bitmask, to tell libcurl what
 authentication method(s) you want it to use. The available bits are listed
index 7a0960f..0d4fdbb 100644 (file)
@@ -1144,6 +1144,10 @@ typedef enum {
   /* "name" and "pwd" to use when fetching. */
   CINIT(USERNAME, OBJECTPOINT, 173),
   CINIT(PASSWORD, OBJECTPOINT, 174),
+\r
+    /* "name" and "pwd" to use with Proxy when fetching. */\r
+  CINIT(PROXYUSERNAME, OBJECTPOINT, 175),\r
+  CINIT(PROXYPASSWORD, OBJECTPOINT, 176),\r
 
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
index 33e2647..6f5313f 100644 (file)
@@ -198,7 +198,9 @@ _CURL_WARNING(_curl_easy_getinfo_err_curl_slist,
    (option) == CURLOPT_USERPWD ||                                             \
    (option) == CURLOPT_USERNAME ||                                            \
    (option) == CURLOPT_PASSWORD ||                                            \
-   (option) == CURLOPT_PROXYUSERPWD ||                                        \
+   (option) == CURLOPT_PROXYUSERPWD ||                                        \\r
+   (option) == CURLOPT_PROXYUSERNAME ||                                       \\r
+   (option) == CURLOPT_PROXYPASSWORD ||                                       \\r
    (option) == CURLOPT_ENCODING ||                                            \
    (option) == CURLOPT_REFERER ||                                             \
    (option) == CURLOPT_USERAGENT ||                                           \
index 0f007fa..b385e2d 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -280,6 +280,39 @@ static CURLcode setstropt(char **charp, char * s)
   return CURLE_OK;
 }
 
+static CURLcode setstropt_userpwd(char *option, char **user_storage,
+                                  char **pwd_storage)
+{
+  char* separator;
+  CURLcode result = CURLE_OK;
+
+  separator = strchr(option, ':');
+  if (separator != NULL) {
+
+    /* 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;
+    }
+
+    /* store password part of option */
+    if (result == CURLE_OK) {
+      result = setstropt(pwd_storage, separator+1);
+    }
+  }
+  else {
+    result = setstropt(user_storage, option);
+  }
+  return result;
+}
+
 CURLcode Curl_dupset(struct SessionHandle * dst, struct SessionHandle * src)
 {
   CURLcode r = CURLE_OK;
@@ -1500,39 +1533,9 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
     /*
      * user:password to use in the operation
      */
-    {
-      char* userpwd;
-      char* separator;
-
-      userpwd = va_arg(param, char *);
-      if(userpwd == NULL)
-        break;
-
-      separator = strchr(userpwd, ':');
-      if (separator != NULL) {
-
-        /* store username part of option */
-        char * p;
-        size_t username_len = (size_t)(separator-userpwd);
-        p = malloc(username_len+1);
-        if(!p)
-          result = CURLE_OUT_OF_MEMORY;
-        else {
-            memcpy(p, userpwd, username_len);
-            p[username_len] = '\0';
-            Curl_safefree(data->set.str[STRING_USERNAME]);
-            data->set.str[STRING_USERNAME] = p;
-        }
-
-        /* store password part of option */
-        if (result == CURLE_OK) {
-          result = setstropt(&data->set.str[STRING_PASSWORD], separator+1);
-        }
-      }
-      else {
-        result = setstropt(&data->set.str[STRING_USERNAME], userpwd);
-      }
-    }
+    result = setstropt_userpwd(va_arg(param, char *),
+                               &data->set.str[STRING_USERNAME],
+                               &data->set.str[STRING_PASSWORD]);
     break;
   case CURLOPT_USERNAME:
     /*
@@ -1587,7 +1590,22 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
     /*
      * user:password needed to use the proxy
      */
-    result = setstropt(&data->set.str[STRING_PROXYUSERPWD],
+    result = setstropt_userpwd(va_arg(param, char *),
+                               &data->set.str[STRING_PROXYUSERNAME],
+                               &data->set.str[STRING_PROXYPASSWORD]);
+    break;
+  case CURLOPT_PROXYUSERNAME:
+    /*
+     * authentication user name to use in the operation
+     */
+    result = setstropt(&data->set.str[STRING_PROXYUSERNAME],
+                       va_arg(param, char *));
+    break;
+  case CURLOPT_PROXYPASSWORD:
+    /*
+     * authentication password to use in the operation
+     */
+    result = setstropt(&data->set.str[STRING_PROXYPASSWORD],
                        va_arg(param, char *));
     break;
   case CURLOPT_RANGE:
@@ -3545,10 +3563,15 @@ static CURLcode parse_proxy_auth(struct SessionHandle *data,
   char proxyuser[MAX_CURL_USER_LENGTH]="";
   char proxypasswd[MAX_CURL_PASSWORD_LENGTH]="";
 
-  sscanf(data->set.str[STRING_PROXYUSERPWD],
-         "%" MAX_CURL_USER_LENGTH_TXT "[^:]:"
-         "%" MAX_CURL_PASSWORD_LENGTH_TXT "[^\n]",
-         proxyuser, proxypasswd);
+  if(data->set.str[STRING_PROXYUSERNAME] != NULL) {
+    strncpy(proxyuser, data->set.str[STRING_PROXYUSERNAME], MAX_CURL_USER_LENGTH);
+    proxyuser[MAX_CURL_USER_LENGTH-1] = '\0';   /*To be on safe side*/
+  }
+  if(data->set.str[STRING_PROXYPASSWORD] != NULL) {
+    strncpy(proxypasswd, data->set.str[STRING_PROXYPASSWORD],
+            MAX_CURL_PASSWORD_LENGTH);
+    proxypasswd[MAX_CURL_PASSWORD_LENGTH-1] = '\0'; /*To be on safe side*/
+  }
 
   conn->proxyuser = curl_easy_unescape(data, proxyuser, 0, NULL);
   if(!conn->proxyuser)
@@ -4032,7 +4055,7 @@ static CURLcode create_conn(struct SessionHandle *data,
 
 
   conn->bits.user_passwd = (bool)(NULL != data->set.str[STRING_USERNAME]);
-  conn->bits.proxy_user_passwd = (bool)(NULL != data->set.str[STRING_PROXYUSERPWD]);
+  conn->bits.proxy_user_passwd = (bool)(NULL != data->set.str[STRING_PROXYUSERNAME]);
   conn->bits.tunnel_proxy = data->set.tunnel_thru_httpproxy;
   conn->bits.ftp_use_epsv = data->set.ftp_use_epsv;
   conn->bits.ftp_use_eprt = data->set.ftp_use_eprt;
index a1a95ef..079c771 100644 (file)
@@ -1322,7 +1322,6 @@ enum dupstring {
                              $HOME/.netrc */
   STRING_COPYPOSTFIELDS,  /* if POST, set the fields' values here */
   STRING_PROXY,           /* proxy to use */
-  STRING_PROXYUSERPWD,    /* Proxy <user:password>, if used */
   STRING_SET_RANGE,       /* range, if used */
   STRING_SET_REFERER,     /* custom string for the HTTP referer field */
   STRING_SET_URL,         /* what original URL to work on */
@@ -1339,6 +1338,8 @@ enum dupstring {
   STRING_SSL_ISSUERCERT,  /* issuer cert file to check certificate */
   STRING_USERNAME,        /* <username>, if used */
   STRING_PASSWORD,        /* <password>, if used */
+  STRING_PROXYUSERNAME,   /* Proxy <username>, if used */\r
+  STRING_PROXYPASSWORD,   /* Proxy <password>, if used */\r
 
   /* -- end of strings -- */
   STRING_LAST /* not used, just an end-of-list marker */