+ logreq(&data);
+}
+
+static int passdata(FILE *in, FILE *out, off_t *passed)
+{
+ size_t read;
+ off_t total;
+ char buf[8192];
+
+ total = 0;
+ while(!feof(in)) {
+ read = fread(buf, 1, sizeof(buf), in);
+ if(ferror(in))
+ return(-1);
+ if(fwrite(buf, 1, read, out) != read)
+ return(-1);
+ total += read;
+ }
+ if(passed)
+ *passed = total;
+ return(0);
+}
+
+static void filterreq(struct muth *mt, va_list args)
+{
+ vavar(struct hthead *, req);
+ vavar(int, fd);
+ int pfds[2];
+ struct hthead *resp;
+ FILE *cl, *hd;
+ struct logdata data;
+
+ hd = NULL;
+ resp = NULL;
+ data = defdata;
+ data.req = req;
+ gettimeofday(&data.start, NULL);
+ cl = mtstdopen(fd, 1, 600, "r+");
+ if(socketpair(PF_UNIX, SOCK_STREAM, 0, pfds))
+ goto out;
+ hd = mtstdopen(pfds[1], 1, 600, "r+");
+ if(sendreq(ch, req, pfds[0])) {
+ close(pfds[0]);
+ goto out;
+ }
+ close(pfds[0]);
+
+ if(passdata(cl, hd, &data.bytesin))
+ goto out;
+ shutdown(pfds[1], SHUT_WR);
+ if((resp = parseresponse(hd)) == NULL)
+ goto out;
+ data.resp = resp;
+ writeresp(cl, resp);
+ fprintf(cl, "\r\n");
+ if(passdata(hd, cl, &data.bytesout))
+ goto out;
+ gettimeofday(&data.end, NULL);
+
+out:
+ logreq(&data);
+
+ freehthead(req);
+ if(resp != NULL)
+ freehthead(resp);
+ fclose(cl);
+ if(hd != NULL)
+ fclose(hd);