So we look for them using strcasestr instead fo strstr.
If this ever becomes a bottleneck, it can probably be optimized by only
trying to match the words right after "\r\n".
It should be duplicated by who's going to use it, otherwise the
duplicated string will simply leak. Add function to free it, because why
not.
This also fixes a compiler warning about losing the const qualifier.
In order to accept a file from stdin, it is necessary to buffer it in
its entirety, so that the final size is known and can be included in the
HTTP header.
As it stands, the stream mode for mmap_file, when used for reading
files, is not extremely useful.
Also:
- files.c: look at fwrite error.
- mmap_file.c: disable buffering for FILE stream.
The feature test macro for POSIX.2001 is used in other source files
already, we should just use it when appropriate.
strdup() declaration is obtained by defining _XOPEN_SOURCE=500. Need (?)
to find out if there libcs that define it for POSIX.2008 but not for
X/Open.5.
This was enabled by duplicating the socket fd and creating a write
stream for it using fdopen(). Pushing the write() error checking to libc
is much better than avoiding the additional allocation.
Redirects are implemented as a callback_header function pointer, so each
application using "PURRLIB" can have its own callbacks. However, when
and how the callbacks are called is defined by ssl_to_mmap, according to
the protocol.
Probably won't continue work on this, since I discovered.
https://github.com/MasterQ32/gurl . It also can't use TOFU, depends on
proper certificate chain.
Also fixed up makefile.
The changes here at least make it possible to support protocols other
than HTTP in the receiving functions.
- IO errors are acceptable, since we instead trust the HTTP payload to
be self terminated
- Add more checking around content-length: it's now a fatal failure if
unavailable
Add base64 encoding per the pattern expected by the web interface.
Fix some pointers and file size things in purr/files.
TODO: files are cut off at random points, despite the efforts to remove
verification of null characters in libbaseencode.
Main one was using file->data instead of file->cursor in
write_into_mmap.
Switching to ftruncate in place of posix_fallocate was done for compat
reasons (posix_fallocate isn't available everywhere _and_ it can fail on
some file systems).