3 typedef struct DEntry DEntry;
25 static Cache *downloadcache;
28 parseurl(char *url, char **path)
33 if(memcmp(url, "http://", 7) != 0)
35 p = strchr(url+7, '/');
39 host = emalloc(len+1);
40 memmove(host, url+7, len);
49 download(char *url, HTTPHeader *hdr)
53 char buf[] = "/var/tmp/smugfs.XXXXXX";
58 if(downloadcache == nil)
59 downloadcache = newcache(sizeof(DEntry), 128, dfree);
61 host = parseurl(url, &path);
65 d = (DEntry*)cachelookup(downloadcache, url, 1);
69 return dup(d->fd, -1);
71 d->fd = -1; // paranoia
73 if((fd = opentemp(buf, ORDWR|ORCLOSE)) < 0){
79 fmtprint(&fmt, "GET %s HTTP/1.0\r\n", path);
80 fmtprint(&fmt, "Host: %s\r\n", host);
81 fmtprint(&fmt, "User-Agent: " USER_AGENT "\r\n");
82 fmtprint(&fmt, "\r\n");
83 req = fmtstrflush(&fmt);
85 fprint(2, "Get %s\n", url);
87 if(httptofile(&http, host, req, hdr, fd) < 0){
94 d->tmpfile = estrdup(buf);
101 downloadflush(char *substr)
104 cacheflush(downloadcache, substr);