Commit Graph

16 Commits

Author SHA1 Message Date
Érico Nogueira 910b69f6b2 Respect that HTTP headers are case insensitive.
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".
2021-05-21 02:23:56 -03:00
Érico Rolim 0b1a4c2fa5 Fix gemini header parsing.
Old gemini spec allowed for server responses to use tabs instead of
spaces.
2020-10-24 03:40:08 -03:00
Érico Rolim b85aaae164 Fix memory leak with redirect_link.
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.
2020-10-15 22:29:48 -03:00
Érico Rolim 7803af405c Clear up input file code in purr.
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.
2020-10-01 19:09:27 -03:00
Érico Rolim 0b7243174c Add comment to FTMs, use less varied ones.
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.
2020-10-01 16:41:12 -03:00
Érico Rolim 90c99403f5 Replace write() loops with fwrite() calls.
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.
2020-10-01 16:25:43 -03:00
Érico Rolim 27d1e68ae8 Add gemini error code parsing, deal with redirects
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.
2020-09-25 02:03:33 -03:00
Érico Rolim 72585a68ca Enable streams for read_from_mmap.
Not working, but also not used for now.

Required changing the API (for the better), now copies into the caller's buffer.
2020-09-24 03:40:38 -03:00
Érico Rolim 696bd8daf2 Fix where no_strip output is sent. 2020-09-18 19:53:37 -03:00
Érico Rolim a39d94dd32 Add very simple gemini client.
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.
2020-09-18 19:52:42 -03:00
Érico Rolim 6eff41606d Clean up connection error handling.
- 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
2020-09-17 10:46:30 -03:00
Érico Rolim 06eb9d4222 Split mmap_file implementation.
Also add some useful definitions.
2020-09-14 00:32:16 -03:00
Érico Rolim 94f8f4f61d Enable encrypted pastes properly.
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.
2020-09-13 18:05:43 -03:00
Érico Rolim 1b4c19665c Fix some issues with the mmap impl.
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).
2020-09-13 16:08:40 -03:00
Érico Rolim baa013afae Move to mmap implementation.
Using FILE* is error prone and limited.
2020-09-13 13:32:28 -03:00
Érico Rolim f3069bb932 Split functionality into different files. 2020-09-10 23:33:52 -03:00