]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/webfs/fs.c
git/branch: somewhere in the syncing, the fix for junk files was lost
[plan9front.git] / sys / src / cmd / webfs / fs.c
index fd8b36dab703f09e36bb40d57f9dd81a89ba6eff..e4e08670daba7be2e4feda2f99bcd79cb3428360 100644 (file)
@@ -76,13 +76,15 @@ static char *nametab[] = {
                        nil,
 };
 
+static char *mtpt;
+static char *service;
 static long time0;
 static char *user;
 static char *agent;
 static Client client[64];
 static int nclient;
 
-#define        CLIENTID(c)     (((Client*)(c)) - client)
+#define        CLIENTID(c)     ((int)(((Client*)(c)) - client))
 
 Client*
 newclient(void)
@@ -167,7 +169,7 @@ fsmkqid(Qid *q, int level, void *aux)
        case Qclient:
                q->type = QTDIR;
        default:
-               q->path = (level<<24) | (((ulong)aux ^ time0) & 0x00ffffff);
+               q->path = (level<<24) | (((uintptr)aux ^ time0) & 0x00ffffff);
        }
 }
 
@@ -220,7 +222,7 @@ fsmkdir(Dir *d, int level, void *aux)
                d->length = strlen(((Key*)aux)->val);
                break;
        case Qclient:
-               snprint(buf, sizeof(buf), "%ld", CLIENTID(aux));
+               snprint(buf, sizeof(buf), "%d", CLIENTID(aux));
                d->name = estrdup(buf);
                break;
        case Qctl:
@@ -405,24 +407,6 @@ fsopen(Req *r)
                        if(!lookkey(cl->hdr, "Accept"))
                                cl->hdr = addkey(cl->hdr, "Accept", "*/*");
 
-                       if(!lookkey(cl->hdr, "Referer")){
-                               char *r;
-                               Url *u;
-
-                               /*
-                                * Referer header is often required on broken
-                                * websites even if the spec makes them optional,
-                                * so we make one up.
-                                */
-                               if(u = url("/", cl->url)){
-                                       if(r = smprint("%U", u)){
-                                               cl->hdr = addkey(cl->hdr, "Referer", r);
-                                               free(r);
-                                       }
-                                       freeurl(u);
-                               }
-                       }
-
                        if(!lookkey(cl->hdr, "Connection"))
                                cl->hdr = addkey(cl->hdr, "Connection", "keep-alive");
 
@@ -519,7 +503,7 @@ fsread(Req *r)
                respond(r, nil);
                return;
        case Qctl:
-               snprint(buf, sizeof(buf), "%ld\n", CLIENTID(f->client));
+               snprint(buf, sizeof(buf), "%d\n", CLIENTID(f->client));
                goto String;
        case Qheader:
                snprint(buf, sizeof(buf), "%s", f->key->val);
@@ -737,8 +721,24 @@ fsdestroyfid(Fid *fid)
        }
 }
 
+static void
+fsstart(Srv*)
+{
+       /* drop reference to old webfs mount */
+       if(mtpt != nil)
+               unmount(nil, mtpt);
+}
+
+static void
+fsend(Srv*)
+{
+       postnote(PNGROUP, getpid(), "shutdown");
+       exits(nil);
+}
+
 Srv fs = 
 {
+       .start=fsstart,
        .attach=fsattach,
        .stat=fsstat,
        .walk1=fswalk1,
@@ -748,30 +748,33 @@ Srv fs =
        .write=fswrite,
        .flush=fsflush,
        .destroyfid=fsdestroyfid,
+       .end=fsend,
 };
 
 void
 usage(void)
 {
-       fprint(2, "usage: %s [-D] [-A useragent] [-T timeout] [-m mtpt] [-s srv]\n", argv0);
+       fprint(2, "usage: %s [-Dd] [-A useragent] [-T timeout] [-m mtpt] [-s service]\n", argv0);
        exits("usage");
 }
 
 void
 main(int argc, char *argv[])
 {
-       char *srv, *mtpt, *s;
+       char *s;
 
        quotefmtinstall();
        fmtinstall('U', Ufmt);
+       fmtinstall('N', Nfmt);
+       fmtinstall(']', Mfmt);
        fmtinstall('E', Efmt);
+       fmtinstall('[', encodefmt);
+       fmtinstall('H', encodefmt);
 
-       srv = nil;
        mtpt = "/mnt/web";
        user = getuser();
        time0 = time(0);
        timeout = 10000;
-       agent = nil;
 
        ARGBEGIN {
        case 'D':
@@ -789,7 +792,7 @@ main(int argc, char *argv[])
                mtpt = EARGF(usage());
                break;
        case 's':
-               srv = EARGF(usage());
+               service = EARGF(usage());
                break;
        case 'd':
                debug++;
@@ -801,14 +804,16 @@ main(int argc, char *argv[])
        rfork(RFNOTEG);
 
        if(agent == nil)
-               agent = "hjdicks";
+               agent = "Mozilla/5.0 (compatible; hjdicks)";
        agent = estrdup(agent);
 
        if(s = getenv("httpproxy")){
                proxy = saneurl(url(s, 0));
+               if(proxy == nil || strcmp(proxy->scheme, "http") && strcmp(proxy->scheme, "https"))
+                       sysfatal("invalid httpproxy url: %s", s);
                free(s);
        }
 
-       postmountsrv(&fs, srv, mtpt, MREPL);
-       exits(0);
+       postmountsrv(&fs, service, mtpt, MREPL);
+       exits(nil);
 }