summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/fetch.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2000-05-11 13:31:02 +0000
committerdes <des@FreeBSD.org>2000-05-11 13:31:02 +0000
commita9ed660f51d2b2b40897b782d076227c7097ed87 (patch)
tree70e025aca6f28347e785da29894bb1396ca02883 /lib/libfetch/fetch.c
parent5c2106e7d4ea48dbde851e51ae9a14717355a402 (diff)
downloadFreeBSD-src-a9ed660f51d2b2b40897b782d076227c7097ed87.zip
FreeBSD-src-a9ed660f51d2b2b40897b782d076227c7097ed87.tar.gz
Reorganize some of the http code and split it into more functions.
Implement fetchStatHTTP(). Unbungle struct url, and add fetchFreeURL(). Document it.
Diffstat (limited to 'lib/libfetch/fetch.c')
-rw-r--r--lib/libfetch/fetch.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/lib/libfetch/fetch.c b/lib/libfetch/fetch.c
index bc2f565..c7e46a9 100644
--- a/lib/libfetch/fetch.c
+++ b/lib/libfetch/fetch.c
@@ -152,7 +152,7 @@ fetchGetURL(char *URL, char *flags)
f = fetchGet(u, flags);
- free(u);
+ fetchFreeURL(u);
return f;
}
@@ -171,7 +171,7 @@ fetchPutURL(char *URL, char *flags)
f = fetchPut(u, flags);
- free(u);
+ fetchFreeURL(u);
return f;
}
@@ -189,7 +189,7 @@ fetchStatURL(char *URL, struct url_stat *us, char *flags)
s = fetchStat(u, us, flags);
- free(u);
+ fetchFreeURL(u);
return s;
}
@@ -207,7 +207,7 @@ fetchListURL(char *URL, char *flags)
ue = fetchList(u, flags);
- free(u);
+ fetchFreeURL(u);
return ue;
}
@@ -282,19 +282,13 @@ fetchParseURL(char *URL)
nohost:
/* document */
- if (*p) {
- struct url *t;
- t = realloc(u, sizeof *u + strlen(p) - 1);
- if (t == NULL) {
- errno = ENOMEM;
- _fetch_syserr();
- goto ouch;
- }
- u = t;
- strcpy(u->doc, p);
- } else {
- u->doc[0] = '/';
- u->doc[1] = 0;
+ if (!*p)
+ p = "/";
+
+ if ((u->doc = strdup(p)) == NULL) {
+ errno = ENOMEM;
+ _fetch_syserr();
+ goto ouch;
}
DEBUG(fprintf(stderr,
@@ -313,3 +307,13 @@ ouch:
free(u);
return NULL;
}
+
+/*
+ * Free a URL
+ */
+void
+fetchFreeURL(struct url *u)
+{
+ free(u->doc);
+ free(u);
+}
OpenPOWER on IntegriCloud