14 if(cistrncmp(url->basename, "file:", 5) == 0)
15 base = url->basename+5;
16 if(cistrncmp(url->reltext, "file:", 5) == 0)
18 if(rel == nil && base == nil)
22 if(base && base[0] == '/' && rel[0] != '/'){
23 if(x = strrchr(base, '/'))
25 snprint(url->fullname, sizeof(url->fullname), "%s/%s", base, rel);
28 snprint(url->fullname, sizeof(url->fullname), "%s", rel);
30 if(x = strrchr(url->fullname, '#')){
32 nstrcpy(url->tag, x, sizeof(url->tag));
34 base = cleanname(url->fullname);
35 x = base + strlen(base)+1;
36 if((x - base) > sizeof(url->fullname)-5)
38 memmove(url->fullname+5, base, x - base);
39 memmove(url->fullname, "file:", 5);
40 return open(url->fullname+5, OREAD);
43 char *mtpt="/mnt/web";
46 webclone(Url *url, char *buf, int nbuf)
50 snprint(buf, nbuf, "%s/clone", mtpt);
51 if((fd = open(buf, ORDWR)) < 0)
53 if((n = read(fd, buf, nbuf-1)) <= 0){
59 if(url && url->reltext[0]){
61 n = snprint(buf, nbuf, "baseurl %s", url->basename);
64 n = snprint(buf, nbuf, "url %s", url->reltext);
65 if(write(fd, buf, n) < 0){
70 snprint(buf, nbuf, "%s/%d", mtpt, conn);
75 readstr(char *path, char *buf, int nbuf){
79 if((fd = open(path, OREAD)) >= 0){
80 if((n = read(fd, buf, nbuf-1)) < 0)
89 urlpost(Url *url, char *ctype)
94 if((fd = webclone(url, buf, sizeof(buf))) < 0)
97 fprint(fd, "contenttype %s", ctype);
99 snprint(buf+n, sizeof(buf)-n, "/postbody");
100 n = open(buf, OWRITE);
106 urlget(Url *url, int body)
112 if((fd = fileget(url)) >= 0)
114 if((fd = webclone(url, buf, sizeof(buf))) < 0)
119 if(fd2path(body, buf, sizeof(buf))){
123 if(x = strrchr(buf, '/'))
125 fd = open(buf, OREAD);
129 snprint(buf+n, sizeof(buf)-n, "/body");
130 body = open(buf, OREAD);
136 snprint(buf+n, sizeof(buf)-n, "/parsed/url");
137 readstr(buf, url->fullname, sizeof(url->fullname));
139 snprint(buf+n, sizeof(buf)-n, "/parsed/fragment");
140 readstr(buf, url->tag, sizeof(url->tag));
142 snprint(buf+n, sizeof(buf)-n, "/contentencoding");
143 readstr(buf, buf, sizeof(buf));
145 if(!cistrcmp(buf, "compress"))
146 fd = pipeline(fd, "exec uncompress");
147 else if(!cistrcmp(buf, "gzip"))
148 fd = pipeline(fd, "exec gunzip");
149 else if(!cistrcmp(buf, "bzip2"))
150 fd = pipeline(fd, "exec bunzip2");
161 if((fd = webclone(url, buf, sizeof(buf))) < 0)
164 snprint(buf+n, sizeof(buf)-n, "/parsed/url");
165 readstr(buf, url->fullname, sizeof(url->fullname));
166 snprint(buf+n, sizeof(buf)-n, "/parsed/fragment");
167 readstr(buf, url->tag, sizeof(url->tag));