12 static int plumbsendfd;
13 static int plumbwebfd;
14 static Channel *plumbchan;
16 static void plumbwebproc(void*);
17 static void plumbwebthread(void*);
18 static void plumbsendproc(void*);
23 plumbsendfd = plumbopen("send", OWRITE|OCEXEC);
24 plumbwebfd = plumbopen("web", OREAD|OCEXEC);
30 plumbchan = chancreate(sizeof(Plumbmsg*), 0);
31 proccreate(plumbwebproc, nil, STACK);
32 threadcreate(plumbwebthread, nil, STACK);
45 base = plumblookup(m->attr, "baseurl");
48 plumburl(m->data, base);
59 m = plumbrecv(plumbwebfd);
67 addattr(Plumbmsg *m, char *name, char *value)
71 a = malloc(sizeof(Plumbattr));
79 freeattrs(Plumbmsg *m)
98 { "application/msword", "doc" },
99 { "application/pdf", "pdf" },
100 { "application/postscript", "ps" },
101 { "application/rtf", "rtf" },
102 { "image/gif", "gif" },
103 { "image/jpeg", "jpg" },
104 { "image/png", "png" },
105 { "image/ppm", "ppm" },
106 { "image/tiff", "tiff" },
107 { "text/html", "html" },
108 { "text/plain", "txt" },
109 { "text/xml", "xml" },
117 char name[128], *ctype, *ext, *p;
121 m = emalloc(sizeof(Plumbmsg));
127 addattr(m, "url", c->url->url);
128 ctype = c->contenttype;
131 addattr(m, "content-type", ctype);
132 for(i = 0; i < nelem(ctypes); i++) {
133 if(strcmp(ctype, ctypes[i].ctype) == 0) {
140 p = strrchr(c->url->url, '/');
142 p = strrchr(p+1, '.');
143 if(p != nil && strlen(p) <= 5)
146 ext = "txt"; /* punt */
149 if(0)fprint(2, "content type %s -> extension .%s\n", ctype, ext);
150 m->ndata = snprint(name, sizeof name, "/mnt/web/%d/body.%s", c->num, ext);
151 m->data = estrdup(name);
152 proccreate(plumbsendproc, m, STACK); /* separate proc to avoid a deadlock */
156 plumbsendproc(void *x)
161 plumbsend(plumbsendfd, m);