Commit 0d49e408 authored by Steve Holme's avatar Steve Holme
Browse files

url: Re-factored set_userpass() and parse_url_userpass()

Re-factored these functions to reflect their new behaviour following the
addition of login options.
parent 90c87f31
Loading
Loading
Loading
Loading
+23 −18
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ find_oldest_idle_connection_in_bundle(struct SessionHandle *data,
static void conn_free(struct connectdata *conn);
static void signalPipeClose(struct curl_llist *pipeline, bool pipe_broke);
static CURLcode do_init(struct connectdata *conn);
static CURLcode parse_url_userpass(struct SessionHandle *data,
static CURLcode parse_url_login(struct SessionHandle *data,
                                struct connectdata *conn,
                                char *user, char *passwd, char *options);
/*
@@ -3865,11 +3865,11 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
    data->change.url_alloc = TRUE; /* free this later */
  }

  /*************************************************************
   * Parse a user name and password in the URL and strip it out
   * of the host name
   *************************************************************/
  result = parse_url_userpass(data, conn, user, passwd, options);
  /*
   * Parse the login details from the URL and strip them out of
   * the host name
   */
  result = parse_url_login(data, conn, user, passwd, options);
  if(result != CURLE_OK)
    return result;

@@ -4327,7 +4327,8 @@ static CURLcode parse_proxy_auth(struct SessionHandle *data,

/*
 *
 * Parse a user name and password in the URL and strip it out of the host name
 * Parse the login details (user name, password and options) from the URL and
 * strip them out of the host name
 *
 * Inputs: data->set.use_netrc (CURLOPT_NETRC)
 *         conn->host.name
@@ -4335,10 +4336,11 @@ static CURLcode parse_proxy_auth(struct SessionHandle *data,
 * Outputs: (almost :- all currently undefined)
 *          conn->bits.user_passwd  - non-zero if non-default passwords exist
 *          user                    - non-zero length if defined
 *          passwd                  -   ditto
 *          passwd                  - non-zero length if defined
 *          options                 - non-zero length if defined
 *          conn->host.name         - remove user name and password
 */
static CURLcode parse_url_userpass(struct SessionHandle *data,
static CURLcode parse_url_login(struct SessionHandle *data,
                                struct connectdata *conn,
                                char *user, char *passwd, char *options)
{
@@ -4606,7 +4608,7 @@ static void override_userpass(struct SessionHandle *data,
/*
 * Set password so it's available in the connection.
 */
static CURLcode set_userpass(struct connectdata *conn,
static CURLcode set_login(struct connectdata *conn,
                          const char *user, const char *passwd,
                          const char *options)
{
@@ -4614,12 +4616,15 @@ static CURLcode set_userpass(struct connectdata *conn,

  /* If our protocol needs a password and we have none, use the defaults */
  if((conn->handler->flags & PROTOPT_NEEDSPWD) && !conn->bits.user_passwd) {

    /* Store the default user */
    conn->user = strdup(CURL_DEFAULT_USER);

    /* Store the default password */
    if(conn->user)
      conn->passwd = strdup(CURL_DEFAULT_PASSWORD);
    else
      conn->passwd = NULL;

    /* This is the default password, so DON'T set conn->bits.user_passwd */
  }
  else {
@@ -5084,7 +5089,7 @@ static CURLcode create_conn(struct SessionHandle *data,
   * for use
   *************************************************************/
  override_userpass(data, conn, user, passwd);
  result = set_userpass(conn, user, passwd, options);
  result = set_login(conn, user, passwd, options);
  if(result != CURLE_OK)
    return result;