cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Asynch DNS (curl_split/curl_join)

From: codemastr <codemstr_at_ptd.net>
Date: Tue, 18 Mar 2003 13:24:16 -0500

> It's actually a little funny that this whole thread of asynch DNS came
> up today. Coincidentally, I was just tracking down some odd cases in how
> I was using curl. I do my own DNS lookups and rewrite the url as
explained
> by codemastr:

This made me think of another idea,
CURLcode curl_split(char *url, struct urldata *data);

struct urldata
{
    char *protocol;
    char *hostname;
    char *username;
    char *password;
    int port;
    char *file;
    char *query;
};

Basically it cuts up a URL:
curl_split("http://user@pass:www.blah.com/file.html?query=test", &data);
data.protocol = "http"
data.hostname = www.blah.com
data.username = "user"
data.password = "pass"
data.port = 80 (http protocol, therefore 80 by default)
data.file = "file.html"
data.query = "query=test"

The reason I suggest this is yes, in a string like
"http://www.blah.com/file.html" it is very easy to client side disect that.
But URLs have numerous odd cases. For example when getting the hostname,
many people will likely forget to check for [] (used when specifying an IPv6
IP), also they may forget to check for a port, or for a user_at_password, etc.
I guess some kind of curl_urldata_cleanup would be needed because you will
probably need to free the memory allocated to the urldata structure, but
that should be relatively easy to do.

There would also be a reverse function say, char *curl_join(struct urldata
data);
Giving the data output from the call to curl_spilt, calling curl_join(data)
would then return "http://user@pass:www.blah.com/file.html?query=test". The
user would then call curl_free() on the returned string when it is no longer
needed. Again, this would have to take into account things like if hostname
is an IPv6 IP, [] must be added, only include a port if it wasn't the
default port.

This would at least make the hack of modifying the URL to change the
hostname to an IP to allow the user to control DNS to be much easier, plus
I'm sure others would find uses for this type of function. And as I said,
yes it could be done relatively easy on the client side, but URLs have some
oddities that most people will likely forget to check. Plus I assume libcurl
already has something internally that does something similar to these
functions since curl will undoubtedly need to split apart a URL and possibly
join it back together, so it would be much easier for you to just expose
and/or modify these functions rather than have the user write them on
his/her own.

Any thoughts? Or does this already exist and I just overlooked it?

-- codemastr

-------------------------------------------------------
This SF.net email is sponsored by: Does your code think in ink?
You could win a Tablet PC. Get a free Tablet PC hat just for playing.
What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en
Received on 2003-03-18