Plan 9 from Bell Labs’s /usr/web/sources/contrib/akumar/α/httpd/save.c.diff

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


63a64,88
> int
> logdata(HConnect *c, char *s, char *fn)
> {
> 	int n, fd;
> 
> 	if(strlen(s) > MaxLog)
> 		s[MaxLog] = '\0';
> 	n = snprint(c->xferbuf, HBufSize, "at %ld %s\n", time(0), s);
> 
> 	fd = openLocked(fn, OWRITE);
> 	if(fd < 0){
> 		errstr(c->xferbuf, sizeof c->xferbuf);
> 		if(strstr(c->xferbuf, "locked") != nil)
> 			hfail(c, HTempFail, c->req.uri);
> 		else
> 			hfail(c, HNotFound, c->req.uri);
> 		return -1;
> 	}
> 	seek(fd, 0, 2);
> 	write(fd, c->xferbuf, n);
> 	close(fd);
> 	return 0;
> }
> 
> 
70,71c95,98
< 	char *s, *t, *fn;
< 	int n, nfn, datafd, htmlfd;
---
> 	HFields *type[2];
> 	char *m, *b, *s, *fn;
> 	int n, nfn, nm, datafd, htmlfd;
> 	int file;
73a101
> 	anonymous(c);	/* protection */
105,107d132
< 		t = strchr(s, '\n');
< 		if(t != nil)
< 			*t = '\0';
118,120c143,149
< 	if(strlen(s) > MaxLog)
< 		s[MaxLog] = '\0';
< 	n = snprint(c->xferbuf, HBufSize, "at %ld %s\n", time(0), s);
---
> 	if((type[0] = c->head.conttype) && (type[1] = type[0]->next){
> 		nm = strlen(type[0]->s)+strlen(type[1]->s)+1;
> 		m = halloc(c, nm);
> 		snprint(m, nm, "%s/%s", type[0]->s, type[1]->s);
> 		if(!strcmp(type[1]->params->s, "boundary))
> 			b = hstrdup(c, type[1]->params->t);
> 	}		
129c158
< 	snprint(fn, nfn, "/usr/web/save/%s.html", c->req.uri);
---
> 	snprint(fn, nfn, "/%s.html", c->req.uri);
137,149c166,170
< 	snprint(fn, nfn, "/usr/web/save/%s.data", c->req.uri);
< 	datafd = openLocked(fn, OWRITE);
< 	if(datafd < 0){
< 		errstr(c->xferbuf, sizeof c->xferbuf);
< 		if(strstr(c->xferbuf, "locked") != nil)
< 			hfail(c, HTempFail, c->req.uri);
< 		else
< 			hfail(c, HNotFound, c->req.uri);
< 		exits("failed");
< 	}
< 	seek(datafd, 0, 2);
< 	write(datafd, c->xferbuf, n);
< 	close(datafd);
---
> 	if(strcmp(m, "multipart/form-data") == 0 && b){
> 		snprint(fn, nfn, /%s.file, c->req.uri);
> 		
> 	snprint(fn, nfn, "/%s.data", c->req.uri);
> 	logdata(c, s, fn);

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].