mothra: cleanup
This commit is contained in:
parent
bd6a86a52b
commit
064b082ae0
|
@ -496,10 +496,10 @@ void h_submitindex(Panel *p, char *){
|
||||||
|
|
||||||
void mencodeform(Form *form, int fd){
|
void mencodeform(Form *form, int fd){
|
||||||
char *b, *p, *sep;
|
char *b, *p, *sep;
|
||||||
|
int ifd, n, nb;
|
||||||
Option *o;
|
Option *o;
|
||||||
Field *f;
|
Field *f;
|
||||||
Rune *rp;
|
Rune *rp;
|
||||||
int n;
|
|
||||||
|
|
||||||
sep = "--" BOUNDARY;
|
sep = "--" BOUNDARY;
|
||||||
for(f=form->fields;f;f=f->next)switch(f->type){
|
for(f=form->fields;f;f=f->next)switch(f->type){
|
||||||
|
@ -549,27 +549,28 @@ void mencodeform(Form *form, int fd){
|
||||||
sep = "\r\n--" BOUNDARY;
|
sep = "\r\n--" BOUNDARY;
|
||||||
free(b);
|
free(b);
|
||||||
break;
|
break;
|
||||||
}
|
case FILE:
|
||||||
for(f=form->fields;f;f=f->next)if(f->type == FILE){
|
|
||||||
char buf[1024];
|
|
||||||
int ifd;
|
|
||||||
|
|
||||||
if(f->name==0 || f->value[0]==0)
|
if(f->name==0 || f->value[0]==0)
|
||||||
continue;
|
continue;
|
||||||
if(p = strrchr(f->value, '/'))
|
if(p = strrchr(f->value, '/'))
|
||||||
p++;
|
p++;
|
||||||
if(p == 0 || *p == 0)
|
if(p == 0 || *p == 0)
|
||||||
p = f->value;
|
p = f->value;
|
||||||
if((ifd = open(f->value, OREAD)) < 0)
|
if((b = malloc(nb = 8192)) == nil)
|
||||||
continue;
|
continue;
|
||||||
if(filetype(ifd, buf, sizeof(buf)) < 0)
|
if((ifd = open(f->value, OREAD)) >= 0){
|
||||||
strcpy(buf, "application/octet-stream");
|
if(filetype(ifd, b, nb) < 0)
|
||||||
|
strcpy(b, "application/octet-stream");
|
||||||
fprint(fd, "%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\""
|
fprint(fd, "%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\""
|
||||||
"\r\nContent-Type: %s\r\n\r\n", sep, f->name, p, buf);
|
"\r\nContent-Type: %s\r\n\r\n", sep, f->name, p, b);
|
||||||
while((n = read(ifd, buf, sizeof(buf))) > 0)
|
|
||||||
write(fd, buf, n);
|
|
||||||
close(ifd);
|
|
||||||
sep = "\r\n--" BOUNDARY;
|
sep = "\r\n--" BOUNDARY;
|
||||||
|
while((n = read(ifd, b, nb)) > 0)
|
||||||
|
if(write(fd, b, n) != n)
|
||||||
|
break;
|
||||||
|
close(ifd);
|
||||||
|
}
|
||||||
|
free(b);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
fprint(fd, "%s--\r\n", sep);
|
fprint(fd, "%s--\r\n", sep);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue