diff options
author | des <des@FreeBSD.org> | 2000-05-07 20:51:31 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2000-05-07 20:51:31 +0000 |
commit | 5f7a182a3e3ae0f71bc4f79ba9e256b956a518b7 (patch) | |
tree | 6a344fa3cf861d3cdbe4a10329ac0e30c1f6e2ef | |
parent | 0fdbe14c489ae391a721e80b577190a1d2f502ee (diff) | |
download | FreeBSD-src-5f7a182a3e3ae0f71bc4f79ba9e256b956a518b7.zip FreeBSD-src-5f7a182a3e3ae0f71bc4f79ba9e256b956a518b7.tar.gz |
Implement restart
-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 12f8712..ce57bfa 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 * |