Commit graph

57 commits

Author SHA1 Message Date
sin
8fdfa36914 Ignore SIGPIPE
If there's no reading end (client closed connection) and quark
tries to write to the socket, it will get a SIGPIPE.  Just ignore it.
2014-08-14 09:57:03 +02:00
sin
5d20e3dc27 No need for MAXBUFLEN+1
Return -1 if writedata() fails.
2014-08-14 09:56:23 +02:00
sin
21ec61991f Ensure mod is properly initialized
Fixes a segfault.
2014-08-14 09:54:37 +02:00
FRIGN
a1fa707eec Fix streaming errors
Streaming a file (through mplayer for instance), the socket would
block, because mplayer fills its buffer sequentially.
We would've never gotten to a write(.., n) == n.

Instead, do it like we read from files and accept the fact clients
can accept data chunk-wise, too.

The reason why this error went unnoticed is that I added a faulty
printf-directive (%ls for ssize_t), which silently produced
no output.
Thanks to sin for fixing the %ls -> %zd error, as it made me look
at the code again.
2014-08-14 09:47:23 +02:00
FRIGN
a0a2b864a6 Don't let r be uninitialized
Restore the functionality before the do-while-loop was removed.
2014-08-13 21:05:53 +02:00
FRIGN
411705dfc0 set host[0] = 0 at the beginning for more safety 2014-08-13 19:37:36 +02:00
FRIGN
8001703f50 Fortify error-cases
We don't want to play with our luck here.
2014-08-12 19:17:19 +02:00
FRIGN
390b5855f5 Streamline the code 2014-08-12 10:34:06 +02:00
FRIGN
ef51cd3355 HTTP 401 -> 403
When the client requests a hidden file, we forbid access.
401 is mostly used when a login is required and hasn't been provided.
Thus, given we don't offer a login-prompt to access hidden and bogus
files but categorically reject them, 403 makes more sense here.
2014-08-11 16:59:27 +02:00
FRIGN
9e2662c5e9 Get rid of getnameinfo and use inet_ntop instead
Compiling quark against musl slowed down request-times considerably.
After further analysis, I found out that the library does a DNS-
request on each address passed to getnameinfo.
Given we chroot into a folder, the /etc/resolv.conf was missing,
which led to the really long response-times (~3-5s).
After hardlinking the /etc/resolv.conf inside the chroot, the
times dropped to ~200ms, as now the library knew which NS to
contact directly.

This obviously isn't fast enough.

Thanks to Hiltjo's useful tips I rewrote the section using
inet_ntop (POSIX 2001).
Now the response-times are back to 1-2ms and we don't need
to copy /etc/resolv.conf everywhere we go.

FYI: This is not a bug in musl, but rather different behaviour.
2014-08-11 16:16:37 +02:00
FRIGN
55912e14bf Change tstamp() to allow passing time_t
then use this to remove duplicate code in the last-modified-section.
2014-08-11 15:37:45 +02:00
FRIGN
54a95cd229 Rectify error-handling 2014-08-11 15:23:48 +02:00
FRIGN
00e2aa8da6 Change HTTP-status-codes to defines
Doesn't change binary-size, but allows using them inside the
error-page-generation-routines.
2014-08-11 13:48:37 +02:00
FRIGN
d5af6424f1 Reordering function-prototypes and functions and size_t-correctness 2014-08-11 13:29:29 +02:00
FRIGN
b00fc1454f Add strftime to modified-date-check 2014-08-11 13:12:53 +02:00
FRIGN
5c7155255c Use gmtime() instead of localtime()
%Z is a GNU extension, so we avoid it here by these means.

Thanks Hiltjo!
2014-08-09 22:33:11 +02:00
FRIGN
34b584e2cb Fix mime-handling with default mime
Now it should work. It doesn't make much sense to tweak the default
mime-type, given octet-stream is the default and there are
no real alternatives which would make sense.

Thanks Hiltjo and sin!
2014-08-09 22:29:08 +02:00
FRIGN
dc82dd9705 Fix mime-check
For "" to actually go through, strcmp should only check for the length
of the extension string.
2014-08-09 21:42:31 +02:00
FRIGN
93f27cd081 Change default mimetype to application/octet-stream
and move it to config.def.h instead of hiding it in the code.
2014-08-09 21:14:40 +02:00
FRIGN
bd544952fd Switch to strftime 2014-08-09 21:03:55 +02:00
FRIGN
f142064a17 Simplify logging
For a server, a solid logging-facility is very important.
Reading quark's logs isn't very pleasant, given it prints out
more vocabulary than necessary.
This patch fixes this problem by bringing the logs into a
readable and even parsable form:

-timestamp-   -keyword-  [-message-]

Keywords now take the role as carriers of information.
Instead of writing that we're redirecting, we just
print a line with a status 304 and what the requested
location was. The subsequent 200-response shows the
redirected location.
This also makes clearer what happens in the background.

The tab-separation allows easy parsing.
2014-08-09 18:32:48 +02:00
FRIGN
10416a352b Coding style 2014-08-08 16:46:01 +02:00
FRIGN
f915f82a40 Refactor responsefile()
Add some comments and improve coding-style.
2014-08-08 15:37:27 +02:00
FRIGN
68535cc04f Use ssize_t for read- and write-return-values 2014-08-08 14:23:12 +02:00
FRIGN
a345c63a59 Refactor sighandler
You can't handle SIGKILL. Given we have control over which
signals are passed to the sighandler, it's enough to catch SIGCHLD
and do standard behaviour than building a big switch for that.
2014-08-07 17:24:39 +02:00
FRIGN
92b8bc27da Refactor loop inside writedata()
Use for for this stuff.
2014-08-07 17:02:03 +02:00
FRIGN
76834092d7 Unify return values
This is the first step for unifying the return-values inside quark.

 1: error
 0: success
-1: not found (non-fatal, for instance, if you run getresentry
               on a non-essential entry)
2014-08-07 16:56:28 +02:00
FRIGN
5ffad8984a Use named indices for the response-entry-array
It was actually sitting right in front of my eyes in the
sighandler-funtion.
This will help sort out ambiguities or mixing up array-indices.
2014-08-07 16:34:46 +02:00
FRIGN
1e23378afd Use strsignal() for signal-logging
This also makes clearer what happens when you do not know the
abbreviations well.
2014-08-07 16:28:01 +02:00
Adria Garriga
abec80e6ce Fixed buffer overflow when p-res==targetlen in function getreqentry 2014-08-07 02:20:13 +02:00
FRIGN
e9408312e1 Refactor response-constructors
Instead of providing a function for each entry-type, use a small
static lookup-table and one function to rule them all.
In the future, in case the list grows, we might think about
implementing it with a small hash-lookup, but currently,
it's easy enough synchronizing the enum and the array.

While at it, improve the logic in the code itself
by using logical OR's instead of AND's.
2014-08-06 17:47:56 +02:00
FRIGN
6d5bedd72a Refactor request()
Unite duplicate code in the getreqentry() function, making error-checking
much easier, and, more importantly, drastically increase the readability.
2014-07-28 15:30:56 +02:00
FRIGN
c3d007756e Add arg-parser and move copyright-info to LICENSE 2014-07-28 13:42:26 +02:00
FRIGN
dfd68c48be Add arg.h 2014-07-28 13:33:58 +02:00
Hiltjo Posthuma
7cd3150df7 implement http not modified
On each request send "last-modified" header with the modification time of
each file. the client will store this field and send it on the next
request(s). On the server check the "if-modified-since" field with the
modified date sent by the client, depending on this send all the data or
the "304 not modified" http status.

CAVEAT: it is assumed the exact field will be send by the client, no date/time
conversion is done for simplicity sake, as far as that's possible with http ;)
2014-07-27 11:37:25 +01:00
Hiltjo Posthuma
dfda73adf1 remove unused code 2014-07-27 11:37:21 +01:00
Jakob Kramer
101a5b5eaf correct information in README 2014-04-12 12:26:14 +01:00
Hiltjo Posthuma
31e023dcb4 http status moved permanently is code 301
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-03-07 15:06:03 +00:00
garbeam@gmail.com
22b5b3cfa6 applied cls' follow up fix 2011-06-26 10:57:34 +01:00
garbeam@gmail.com
3a9701d828 applied rransom's quark patch for FreeBSD compliance, thanks 2011-06-26 10:51:42 +01:00
Anselm R Garbe
d6cbb5b9d9 preparing Request abstraction, ongoing 2011-02-16 20:29:55 +00:00
Anselm R Garbe
a61a51b91d applied Szabolcs patch, added him to LICENSE 2011-02-13 12:46:34 +00:00
Anselm R Garbe
0c7cc24c83 removed non-existent man page install 2010-04-10 21:34:05 +01:00
Anselm R Garbe
5e9814c847 made simple CGI working, quark can be used to run werc 2010-03-28 11:31:30 +00:00
Anselm R Garbe
18c6c2451d some minor fix 2010-03-28 02:18:34 +00:00
Anselm R Garbe
3e45a7c0ba added command line interface 2010-03-28 02:14:01 +00:00
Anselm R Garbe
a20243ea7c added basic HEAD support, some bug fixes 2010-03-28 01:57:44 +00:00
Anselm R Garbe
07db66c273 implemented very basic cgi support 2010-03-28 01:09:14 +00:00
Anselm R Garbe
c19e5e6724 moved signal handlers before port binding 2009-08-16 13:33:02 +01:00
Anselm R Garbe
1301be6ce8 superflous, stderr is unbuffered 2009-08-16 11:51:14 +01:00