cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: data->set.str[STRING_PASSWORD] <=> conn->passwd

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 20 Nov 2008 07:58:12 +0100 (CET)

On Wed, 19 Nov 2008, Josef Wolf wrote:

> I am trying to understand the difference between
>
> conn->user <=> data->set.str[STRING_USERNAME]
> conn->passwd <=> data->set.str[STRING_PASSWORD]
> conn->proxyuser <=> data->set.str[STRING_PROXYUSERNAME]
> conn->passwd <=> data->set.str[STRING_PROXYPASSWORD]

> On a first glance, the main difference seems to be that the data->set.str[]
> entries are set by curl_easy_setopt() while the conn entries are parsed from
> the url/.netrc.

The difference is again down to 'conn' vs 'data'.

The 'data' pointer is the placeholder for general options for upcoming
connections. That may be one or many connections.

Each individual connection needs to have its own copy of this data, as the
'data' struct may very well change the credentials for the next transfer while
the previous conn remains alive (possibly to be re-used).

Let me try to explain a bit more with an imaginary use-case and pseudo code:

start of application:

  data->set.str[STRING_USERNAME] = "user"

start of first connection

  conn->user = data->set.str[STRING_USERNAME]

(the connection is kept alive after this use)

application now changes user name

  data->set.str[STRING_USERNAME] = "user2"

and makes a second connection

  conn2->user = data->set.str[STRING_USERNAME]

and then the application can go back to use the first name again:

  data->set.str[STRING_USERNAME] = "user"

and when doing a connection now, libcurl detects that this matches the
previous still existing connection 'conn' as the credentials match:

  re-use conn

-- 
  / daniel.haxx.se
Received on 2008-11-20