[hackers] [quark] Refactor responsefile() || FRIGN
commit f915f82a40cfc45a74cf3df58036f0e88dee3995
Author: FRIGN <dev_AT_frign.de>
Date: Fri Aug 8 15:37:27 2014 +0200
Refactor responsefile()
Add some comments and improve coding-style.
diff --git a/quark.c b/quark.c
index cbd7bc5..0946f1c 100644
--- a/quark.c
+++ b/quark.c
_AT_@ -189,9 +189,9 @@ responsefile(void) {
struct stat st;
time_t t;
- r = stat(reqbuf, &st);
- if(r == -1 || (ffd = open(reqbuf, O_RDONLY)) == -1) {
- logerrmsg("%s requests unknown path %s
", host, reqbuf);
+ if((r = stat(reqbuf, &st)) == -1 || (ffd = open(reqbuf, O_RDONLY)) == -1) {
+ /* file not found */
+ logerrmsg("%s requests unknown file %s
", host, reqbuf);
if(putresentry(HEADER, HttpNotFound, tstamp())
|| putresentry(CONTENTTYPE, texthtml))
return;
_AT_@ -199,13 +199,14 @@ responsefile(void) {
writetext("
<html><body>404 Not Found</body></html>
");
}
else {
+ /* check if modified */
t = st.st_mtim.tv_sec;
memcpy(mod, asctime(gmtime(&t)), 24);
mod[24] = 0;
- if(!strcmp(reqmod, mod)) {
- if(putresentry(HEADER, HttpNotModified, tstamp()))
- return;
+ if(!strcmp(reqmod, mod) && !putresentry(HEADER, HttpNotModified, tstamp())) {
+ /* not modified, we're done here*/
} else {
+ /* determine mime-type */
if((p = strrchr(reqbuf, '.'))) {
p++;
for(i = 0; i < LENGTH(servermimes); i++)
_AT_@ -214,6 +215,7 @@ responsefile(void) {
break;
}
}
+ /* serve file */
if(putresentry(HEADER, HttpOk, tstamp())
|| putresentry(MODIFIED, mod)
|| putresentry(CONTENTLEN, st.st_size)
Received on Fri Aug 08 2014 - 15:36:08 CEST
This archive was generated by hypermail 2.3.0
: Fri Aug 08 2014 - 15:36:18 CEST