Since now config.def.h has been reduced we don't have any more unused
variables and thus the manual fiddling with error-levels is no longer
necessary.
To get a completely clean result though we have to still cast some
variables here and there.
The config.h-interface has proven to be very effective for a lot of
suckless tools, but it just does not make too much sense for a web
server like quark.
$ quark
If you run multiple instances of it, you want to see in the command line
(or top) what it does, and given the amount of options it's logical to
just express them as options given in the command line.
It also is a problem if you can modify quark via the config.h,
contradicting the manual. Just saying "Well, then don't touch config.h"
is also not good, as the vhost and map options were only exposed via
this interface.
What is left in config.h are mime-types and two constants relating to
the incoming HTTP-header-limits.
In order to introduce these changes, some structs and safe utility
functions were added and imported from OpenBSD respectively.
This makes quark's vhost-handling very powerful while still being
simple.
Imagine you have a website with a subdomain you really want
to move back to your main domain.
Say the subdomain is called "old.example.org" and you want to serve it
under "example.org" but in the subdirectory "old/", i.e. you want to
redirect a request "old.example.org/subdir/" to "example.org/old/subdir".
For a vhost-handler that only takes 4 arguments for each vhost this is
actually pretty powerful.
This ensures that quark really does not care if the incoming connection
is plain HTTP or relayed TLS-traffic from a proxy or tunnel. Depending
on the previous negotiation, the client will make the right decision on
which scheme to use in a given context.
To make the code a bit more flexible, let's get rid of the forking-code
in serve() and do it in main(). This way, we are more liberal in the
future to possibly handle it in a different way.
And many other things, too many to list here. For example, it now
properly logs uds instead of erroring out.
Separating concerns in many places definitely improves the readability.
- add missing header netinet/in.h for socket declarations (POSIX).
- rename sendfile to responsefile, sendfile(2) is a syscall on FreeBSD.
- remove _XOPEN_SOURCE: this will give a warning about strptime on Linux
glibc, but unbreaks the build on NetBSD and FreeBSD.
thanks also to josuah and quinq for testing!
Thanks Michael Forney for reporting this! We cannot use identifiers
beginning with an underscore, says the C99-standard, section 7.1.3:
"All identifiers that begin with an underscore are always reserved for
use as identifiers with file scope in both the ordinary and tag name
spaces."
We go around this by putting the underscore at the end.
The (c)-symbol has become more of a remnant after the Berne convention
has been signed. Given the ISC exploits some simplifications introduced
with the Berne convention, it just makes sense to drop this relict as
well and just state our Copyright without much ado about nothing.
https://opensource.org/licenses/ISC
Check for its presence and bail out if found.
If the socket file is present, either a server is already bound to it,
or the last one errored out and we'd want to inspect this.
Also it could be an unrelated file given by error.