diff options
| author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-05-07 20:51:31 +0000 |
|---|---|---|
| committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-05-07 20:51:31 +0000 |
| commit | 3d2a847151d0d4b222e4abedaf8c6640b91200d6 (patch) | |
| tree | 9ec450116722ca1e3aefdd46362028f939f8dfc0 /lib/libfetch | |
| parent | 3594c3a0013ebab08b358e2d768d48922dd471f9 (diff) | |
Notes
Diffstat (limited to 'lib/libfetch')
| -rw-r--r-- | lib/libfetch/http.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index 12f871297402..ce57bfa56e73 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -79,6 +79,9 @@ extern char *__progname; #define ENDL "\r\n" +#define HTTP_OK 200 +#define HTTP_PARTIAL 206 + struct cookie { FILE *real_f; @@ -299,6 +302,7 @@ fetchGetHTTP(struct url *URL, char *flags) char *ln, *p, *px, *q; FILE *f, *cf; size_t len; + off_t pos = 0; direct = (flags && strchr(flags, 'd')); verbose = (flags && strchr(flags, 'v')); @@ -389,6 +393,8 @@ fetchGetHTTP(struct url *URL, char *flags) } _http_cmd(f, "Host: %s:%d" ENDL, URL->host, URL->port); _http_cmd(f, "User-Agent: %s " _LIBFETCH_VER ENDL, __progname); + if (URL->offset) + _http_cmd(f, "Range: bytes=%lld-" ENDL, URL->offset); _http_cmd(f, "Connection: close" ENDL ENDL); /* get response */ @@ -409,7 +415,7 @@ fetchGetHTTP(struct url *URL, char *flags) DEBUG(fprintf(stderr, "code: [\033[1m%d\033[m]\n", e)); /* add code to handle redirects later */ - if (e != 200) { + if (e != (URL->offset ? HTTP_PARTIAL : HTTP_OK)) { _http_seterr(e); goto fouch; } @@ -446,6 +452,23 @@ fetchGetHTTP(struct url *URL, char *flags) DEBUG(fprintf(stderr, "conttype: [\033[1m%s\033[m]\n", c->content_type)); #undef CONTTYPE +#define CONTRANGE "Content-Range:" +#define BYTES "bytes " + } else if (strncasecmp(ln, CONTRANGE, sizeof CONTRANGE - 1) == 0) { + p = ln + sizeof CONTRANGE - 1; + while ((p < ln + len) && isspace(*p)) + p++; + if (strncasecmp(p, BYTES, sizeof BYTES - 1) != 0 + || (p += 6) >= ln + len) + goto fouch; + while ((p < ln + len) && isdigit(*p)) + pos = pos * 10 + (*p++ - '0'); + /* XXX wouldn't hurt to be slightly more paranoid here */ + DEBUG(fprintf(stderr, "contrange: [\033[1m%lld-\033[m]\n", pos)); + if (pos > URL->offset) + goto fouch; +#undef BYTES +#undef CONTRANGE } } @@ -459,6 +482,10 @@ fetchGetHTTP(struct url *URL, char *flags) if (cf == NULL) goto fouch; + while (pos < URL->offset) + if (fgetc(cf) == EOF) + goto cfouch; + return cf; ouch: @@ -472,6 +499,10 @@ fouch: free(c); _http_seterr(999); /* XXX do this properly RSN */ return NULL; +cfouch: + fclose(cf); + _http_seterr(999); /* XXX do this properly RSN */ + return NULL; } FILE * |
