1
0
Fork 0
Commit Graph

98 Commits

Author SHA1 Message Date
Xavier Del Campo Romero 65031ca350
Send HTTP headers to payload callback
Even if libweb already parses some common headers, such as
Content-Length, some users might find it interesting to inspect which
headers were received from a request.

Since HTTP/1.1 does not define a limit on the number of maximum headers
a client can send, for security reasons a maximum value must be provided
by the user. Any extra headers shall be then discarded by libweb.

An example application showing this new feature is also provided.
2023-11-18 01:03:12 +01:00
Xavier Del Campo Romero b71a6174e1
http.c: Fix more issues with partial boundaries
- http_memmem must not check strlen(a) > n because, in case of a partial
boundary, it would wrongfully return NULL.
- If one or more characters from a partial boundary are found at the end
of a buffer, but the next buffer does not start with the rest of the
boundary, the accumulated boundary must be reset, and then look for a
new boundary.
2023-11-12 23:31:57 +01:00
Xavier Del Campo Romero 7d02b225fe
http.c: Fix several issues with partial boundaries
- Writing to m->boundary[len] did not make any sense, as len is not
meant to change between calls to read_mf_boundary_byte.
- For the same reason, memset(3)ing "len + 1" did not make any sense.
- When a partial boundary is found, http_memmem must still return st.
- Calling reset_boundary with prev == 0 did not make sense, since that
case typically means a partial boundary was found on a previous
iteration, so m->blen must not be reset.
2023-11-12 06:52:48 +01:00
Xavier Del Campo Romero 9e1779eacd
doc: Add man3 page for http_decode_url
Suprisingly, this man page was missing on the 0.1.0 release.

The recent signature changes on http_decode_url have already been
reflected.
2023-11-12 01:29:55 +01:00
Xavier Del Campo Romero 9ac68fd76c
http: Make http_decode_url return int
So far, it was not possible callers to distinguish between decoding
errors, as caused by ill-formed input, from fatal errors.
2023-11-12 01:29:54 +01:00
Xavier Del Campo Romero 957ac188e5
http.c: Avoid use of dynstr_append_or_ret_nonzero
This macro would return a positive integer on failure. However,
functions called by http_update should only return a positive integer
for user input-related errors, not fatal errors such as those related to
failed memory allocations.
2023-11-12 01:29:54 +01:00
Xavier Del Campo Romero 28ba2de389
http.c: Avoid writing body for HEAD requests
As opposed to GET or POST requests, HEAD must not write any body bytes.
2023-11-12 01:29:54 +01:00
Xavier Del Campo Romero 747911416e
Bump dynstr
The commit below is relevant to fix CMake builds:

Author: Xavier Del Campo Romero <xavi.dcr@tutanota.com>
Date:   Fri Nov 10 14:43:39 2023 +0100

    CMakeLists.txt: Fix missing parameter names

    VERSION must be indicated when passing a version string to project().
    Also, LANGUAGES must be also be passed when the language name is not the
    only argument to project() (apart from the project name itself).
2023-11-10 14:47:05 +01:00
Xavier Del Campo Romero 69d615df3d
CMakeLists.txt: Fix missing LANGUAGES
When the language name is not the only argument for project() (other
than the project name itself), LANGUAGES must be indicated.
2023-11-10 14:45:46 +01:00
Xavier Del Campo Romero dbdaac757f
Makefile: Replace -Og with -O1
Only the latter is defined by POSIX.1-2008. Even if there are still some
non-portable flags defined by CFLAGS, it is a good idea to reduce them.
2023-10-25 22:07:11 +02:00
Xavier Del Campo Romero 662d6e1c14
Bump dynstr to v0.1.0-rc4 2023-10-25 22:07:07 +02:00
Xavier Del Campo Romero 3e004fa6a1
Adhere to GNU Make directory variables 2023-10-25 21:57:22 +02:00
Xavier Del Campo Romero aaa0ba2755
Makefile: Build libweb also as a shared library 2023-10-25 21:57:10 +02:00
Xavier Del Campo Romero f0464acecb
Bump dynstr to v0.1.0-rc3 2023-10-25 14:10:52 +02:00
Xavier Del Campo Romero c74888906d
CMakeLists.txt: set project VERSION 2023-10-25 14:10:52 +02:00
Xavier Del Campo Romero c6083ca223
examples: Fix wrong library name 2023-10-25 14:10:52 +02:00
Xavier Del Campo Romero 280d400877
CMake: Use in-tree dynstr if not available 2023-10-16 01:22:12 +02:00
Xavier Del Campo Romero 584de479cb
Bump dynstr to v0.1.0-rc2 2023-10-16 01:17:55 +02:00
Xavier Del Campo Romero d9e9164922
libweb.pc: Fix wrong -l flag 2023-10-16 00:29:52 +02:00
Xavier Del Campo Romero 0222b75e85
Rename project from slweb to libweb
It was found out there was another project of the same name around
(https://git.sr.ht/~strahinja/slweb/), also related to website
generation.

In order to avoid confusion, a new name has been chosen for this
project. Surprisingly, libweb was not in use by any distributions
(according to https://repology.org and AUR index), and it should
reflect well the intention behind this project i.e., being a library
to build web-related stuff.
2023-10-11 00:07:13 +02:00
Xavier Del Campo Romero 832e198f8c
server.c: Replace sequential calls with loop 2023-10-10 23:16:11 +02:00
Xavier Del Campo Romero 07e0063870
http: Support HEAD 2023-10-10 23:15:26 +02:00
Xavier Del Campo Romero b43adf9a00
Bump dynstr
dynstr got its v0.1.0-rc1 release, and this commit introduces a fix:

commit 0e779caae658f118d535e9f0a74f0012eefca9a0
Author: Xavier Del Campo Romero <xavi.dcr@tutanota.com>
Date:   Mon Oct 2 14:38:53 2023 +0200

    CMakeLists.txt: add cmake_minimum_required

    This command is mandatory for all CMake projects. 3.0 was chosen since
    dynstr does not require any newer CMake features.
2023-10-02 15:12:20 +02:00
Xavier Del Campo Romero a89d0e4ae3
Install man pages 2023-09-27 21:55:58 +02:00
Xavier Del Campo Romero adb0973bb3
Add man pages 2023-09-27 21:55:58 +02:00
Xavier Del Campo Romero 0d54bbf086
http.h: Remove stale comment
This shall be replaced with more meaningful man pages for all functions
in slweb.
2023-09-27 21:55:58 +02:00
Xavier Del Campo Romero 5659eb6439
Add slweb.pc 2023-09-27 21:55:48 +02:00
Xavier Del Campo Romero 6a72955270
README.md: Add install instructions 2023-09-27 21:55:48 +02:00
Xavier Del Campo Romero 9315328983
Makefile, CMakeLists.txt: Add installation targets 2023-09-27 01:05:04 +02:00
Xavier Del Campo Romero 8b39bc5db9
server.c: Fix build on FreeBSD 2023-09-26 22:58:11 +02:00
Xavier Del Campo Romero d9dbad1bc6
examples/Makefile: Add html example 2023-09-25 00:18:41 +02:00
Xavier Del Campo Romero 70670e129e
Add HTML serializer example 2023-09-15 14:58:37 +02:00
Xavier Del Campo Romero 07c59a83d1
CMakeLists.txt: Fix examples not building
Default value for a CMake option() must always be passed as the third
parameter.
2023-09-15 14:56:34 +02:00
Xavier Del Campo Romero 5be3ffdd3b
http: Use null-terminated string for POST data
application/x-www-form-urlencoded-data is (or should be) always text, so
it is preferrable to define struct http_post member "data" as a null-
terminated string.

For applications already making this assumption, this change should now
remove the need for string duplication.
2023-09-09 02:32:34 +02:00
Xavier Del Campo Romero 1790e70e61
.gitignore: Add examples/hello/hello 2023-09-09 01:20:49 +02:00
Xavier Del Campo Romero 34d716082a
http: Insert name into http_post_file
Whereas slcl, the project where slweb started, ignored this field, some
applications might require it.
2023-09-09 00:39:43 +02:00
Xavier Del Campo Romero 09909c0a3b
http: Allow multiple non-file Content-Disposition
Now, slweb accepts requests such as:

--boundary
Content-Disposition: form-data; name="field1"

value1
--boundary
Content-Disposition: form-data; name="field2"

value2
--boundary
Content-Disposition: form-data; name="field3"; filename="example.txt"

The following breaking changes have been introduced:

Member "dir" from struct http_post was a leftover from the days where
slcl and slweb were one project. It did not make sense for slweb, since
it should not decide which Content-Disposition names are allowed. In
other words, "dir" was only relevant in the scope of slcl.

Member "n" from struct http_post used to have two meanings:

- The length of a URL-encoded request.
- The number of files on a multipart/form-data request.

Since "npairs" had to be introduced to struct http_post, it did not make
sense to keep this dual meaning any more. Therefore, "n" has been
restricted to the former, whereas a new member, called "nfiles", has
been introduced for the latter.
2023-09-09 00:21:42 +02:00
Xavier Del Campo Romero 6c7faa7f90
http.c: Use BUFSIZ instead of arbitrary value
According to C99 7.19.1p3:

BUFSIZ is a macro that expands to an integer constant expression that is
the size of the buffer used by the setbuf function.

In other words, this means BUFSIZ is the most optimal length for a
buffer that reads a file into memory in chunks using fread(3).

Note: the number of bytes sent to the client might be less than BUFSIZ,
so this would act as a bottleneck, no matter how large the buffer passed
to fread(3) is.
2023-09-07 16:01:37 +02:00
Xavier Del Campo Romero f9e3516f50
handler: Define port as unsigned short
Port numbers are unsigned by definition. Fortunately, this was a minor
issues since server_init was doing an implicit cast to unsigned short.
2023-09-07 15:41:46 +02:00
Xavier Del Campo Romero 11df321eda
hello/main.c: Add missing length callback
Even if the feature is unsupported by the application, slweb requires
`length` to be a valid function pointer.
2023-09-07 13:45:10 +02:00
Xavier Del Campo Romero 083dedbb9d
http.c: Return error if check_length fails
Otherwise, fatal errors coming from the h->cfg.length would be
unnoticed, causing slweb to attempt to send a response.
2023-09-07 13:45:10 +02:00
Xavier Del Campo Romero f6562ddab3
http.c: Merge payload_{get,post} into process_payload
Both functions were in fact identical, so there was no reason to keep
two definitions rather than one.
2023-08-13 01:23:48 +02:00
Xavier Del Campo Romero 4ee88984fc
Add hello world example 2023-08-09 00:32:13 +02:00
Xavier Del Campo Romero 83b8b8c2b3
README.md: Add missing CMake build step 2023-08-09 00:31:40 +02:00
Xavier Del Campo Romero d55b84f68b
html.c: Fix wrong encoding for '>' and '<' 2023-08-08 00:34:38 +02:00
Xavier Del Campo Romero 0a3b827961
Bump dynstr 2023-08-02 13:06:55 +02:00
Xavier Del Campo Romero 3a3fdbe8a5
http.c: Remove useless explicit cast 2023-08-01 02:24:28 +02:00
Xavier Del Campo Romero 7428e3fa7f
Do some minor rebranding
Despite designed around portability and minimalism, I feel slweb no
longer aligns with the philosophical views from the suckless project.
Therefore, I think it was appropriate to unlink its branding from it.
2023-08-01 02:23:41 +02:00
Xavier Del Campo Romero 2d879d92e1
Bump dynstr
A recent commit introduced a "clean" target to its Makefile.
2023-08-01 02:19:54 +02:00
Xavier Del Campo Romero 1ce153b9a4
html.c: Make serialize_node static 2023-07-28 01:33:20 +02:00