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)
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:
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 = u->host){
- u->host = smprint("%H", r);
- free(r);
- }
- 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");
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);
}
}
+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,
.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('H', Hfmt);
+ 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':
mtpt = EARGF(usage());
break;
case 's':
- srv = EARGF(usage());
+ service = EARGF(usage());
break;
case 'd':
debug++;
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);
}