diff options
author | des <des@FreeBSD.org> | 2000-05-25 16:46:09 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2000-05-25 16:46:09 +0000 |
commit | 59892af9b116e3fa452851819517a361c4ab2b0e (patch) | |
tree | efdcc8e69a40d6b4a084ebc71bca62e3be76c214 /lib/libfetch/fetch.c | |
parent | 96ab0c2c8f9f2ca7d3466f5a45d469ba0224c598 (diff) | |
download | FreeBSD-src-59892af9b116e3fa452851819517a361c4ab2b0e.zip FreeBSD-src-59892af9b116e3fa452851819517a361c4ab2b0e.tar.gz |
Add (and document) fetchMakeURL()
Diffstat (limited to 'lib/libfetch/fetch.c')
-rw-r--r-- | lib/libfetch/fetch.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/lib/libfetch/fetch.c b/lib/libfetch/fetch.c index 08efeb8..5d83db5 100644 --- a/lib/libfetch/fetch.c +++ b/lib/libfetch/fetch.c @@ -237,6 +237,48 @@ fetchListURL(char *URL, char *flags) } /* + * Make a URL + */ +struct url * +fetchMakeURL(char *scheme, char *host, int port, char *doc, + char *user, char *pwd) +{ + struct url *u; + + if (!scheme || (!host && !doc)) { + _url_seterr(URL_MALFORMED); + return NULL; + } + + if (port < 0 || port > 65535) { + _url_seterr(URL_BAD_PORT); + return NULL; + } + + /* allocate struct url */ + if ((u = calloc(1, sizeof *u)) == NULL) { + _fetch_syserr(); + return NULL; + } + + if ((u->doc = strdup(doc ? doc : "/")) == NULL) { + _fetch_syserr(); + free(u); + return NULL; + } + +#define seturl(x) snprintf(u->x, sizeof u->x, "%s", x) + seturl(scheme); + seturl(host); + seturl(user); + seturl(pwd); +#undef seturl + u->port = port; + + return u; +} + +/* * Split an URL into components. URL syntax is: * method:[//[user[:pwd]@]host[:port]]/[document] * This almost, but not quite, RFC1738 URL syntax. @@ -250,7 +292,6 @@ fetchParseURL(char *URL) /* allocate struct url */ if ((u = calloc(1, sizeof *u)) == NULL) { - errno = ENOMEM; _fetch_syserr(); return NULL; } @@ -320,7 +361,6 @@ nohost: p = "/"; if ((u->doc = strdup(p)) == NULL) { - errno = ENOMEM; _fetch_syserr(); goto ouch; } |