From 483b470aaad60254e6d4969370f58f45a0985f14 Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Fri, 6 Mar 1998 02:38:10 +0000 Subject: [PATCH] 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 --- lib/roken/roken_gethostby.c | 56 ++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/lib/roken/roken_gethostby.c b/lib/roken/roken_gethostby.c index 9167a7011..eccc9c60e 100644 --- a/lib/roken/roken_gethostby.c +++ b/lib/roken/roken_gethostby.c @@ -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*