Make `roken_gethostby_setup' take url-like specification instead of

split up versions. Makes it easier for calling applications.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4556 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1998-03-06 02:38:10 +00:00
parent f5b18a0c01
commit 483b470aaa

View File

@@ -72,10 +72,10 @@ make_address(const char *address, struct in_addr *ip)
return 0;
}
int
roken_gethostby_setup(const char *proxy_host, short proxy_port,
const char *dns_host, short dns_port,
const char *dns_path)
static int
setup_int(const char *proxy_host, short proxy_port,
const char *dns_host, short dns_port,
const char *dns_path)
{
memset(&dns_addr, 0, sizeof(dns_addr));
if(dns_req)
@@ -95,6 +95,54 @@ roken_gethostby_setup(const char *proxy_host, short proxy_port,
return 0;
}
static void
split_spec(const char *spec, char **host, int *port, char **path, int def_port)
{
char *p;
*host = strdup(spec);
p = strchr(*host, ':');
if(p) {
*p++ = '\0';
if(sscanf(p, "%d", port) != 1)
*port = def_port;
} else
*port = def_port;
p = strchr(p ? p : *host, '/');
if(p) {
if(path)
*path = strdup(p);
*p = '\0';
}else
if(path)
*path = NULL;
}
int
roken_gethostby_setup(const char *proxy_spec, const char *dns_spec)
{
char *proxy_host = NULL;
int proxy_port;
char *dns_host, *dns_path;
int dns_port;
char *tmp;
int ret = -1;
split_spec(dns_spec, &dns_host, &dns_port, &dns_path, 80);
if(dns_path == NULL)
goto out;
if(proxy_spec)
split_spec(proxy_spec, &proxy_host, &proxy_port, NULL, 80);
ret = setup_int(proxy_host, proxy_port, dns_host, dns_port, dns_path);
out:
free(proxy_host);
free(dns_host);
free(dns_path);
return ret;
}
/* Try to lookup a name or an ip-address using http as transport
mechanism. See the end of this file for an example program. */
static struct hostent*