mothra: handle http compression out of band

This commit is contained in:
cinap_lenrek 2012-04-30 22:09:57 +02:00
parent a2e26ffd4c
commit 9c79deb130
3 changed files with 11 additions and 16 deletions

View file

@ -825,6 +825,7 @@ int readstr(char *buf, int nbuf, char *base, char *name){
int urlopen(Url *url, int method, char *body){ int urlopen(Url *url, int method, char *body){
int conn, ctlfd, fd, n; int conn, ctlfd, fd, n;
char buf[1024+1], *p; char buf[1024+1], *p;
char encoding[64];
if(debug) fprint(2, "urlopen %s (%s)\n", url->reltext, url->basename); if(debug) fprint(2, "urlopen %s (%s)\n", url->reltext, url->basename);
@ -863,11 +864,19 @@ int urlopen(Url *url, int method, char *body){
} }
snprint(buf, sizeof buf, "%s/%d/body", mtpt, conn); snprint(buf, sizeof buf, "%s/%d/body", mtpt, conn);
if((fd = open(buf, OREAD)) < 0) if((fd = open(buf, OREAD)) < 0)
goto ErrOut; goto ErrOut;
snprint(buf, sizeof buf, "%s/%d/parsed", mtpt, conn); snprint(buf, sizeof buf, "%s/%d/parsed", mtpt, conn);
readstr(url->fullname, sizeof(url->fullname), buf, "url"); readstr(url->fullname, sizeof(url->fullname), buf, "url");
readstr(url->tag, sizeof(url->tag), buf, "fragment"); readstr(url->tag, sizeof(url->tag), buf, "fragment");
snprint(buf, sizeof buf, "%s/%d", mtpt, conn);
readstr(encoding, sizeof(encoding), buf, "contentencoding");
close(ctlfd); close(ctlfd);
if(!cistrcmp(encoding, "compress"))
fd = pipeline("/bin/uncompress", fd);
else if(!cistrcmp(encoding, "gzip"))
fd = pipeline("/bin/gunzip", fd);
else if(!cistrcmp(encoding, "bzip2"))
fd = pipeline("/bin/bunzip2", fd);
return fd; return fd;
} }
@ -955,17 +964,8 @@ void geturl(char *urlname, int method, char *body, int plumb, int map){
message("getting %s", selection->fullname); message("getting %s", selection->fullname);
if(mothmode && !plumb) if(mothmode && !plumb)
typ = -1; typ = -1;
else { else
typ = snooptype(fd); typ = snooptype(fd);
if(typ == GUNZIP){
fd=pipeline("/bin/gunzip", fd);
typ = snooptype(fd);
}
if(typ == COMPRESS){
fd=pipeline("/bin/uncompress", fd);
typ = snooptype(fd);
}
}
switch(typ){ switch(typ){
default: default:
if(plumb){ if(plumb){

View file

@ -52,8 +52,6 @@ enum{
BMP, BMP,
ICO, ICO,
GUNZIP,
COMPRESS,
PAGE, PAGE,
}; };

View file

@ -102,9 +102,6 @@ snooptype(int fd)
"image/bmp", BMP, "image/bmp", BMP,
"image/x-icon", ICO, "image/x-icon", ICO,
"application/x-gzip", GUNZIP,
"application/x-compress", COMPRESS,
"application/pdf", PAGE, "application/pdf", PAGE,
"application/postscript", PAGE, "application/postscript", PAGE,
"application/ghostscript", PAGE, "application/ghostscript", PAGE,