Commit Graph

126 Commits

Author SHA1 Message Date
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
Xavier Del Campo Romero 3388eb719a
Move dynstr to new URL 2023-07-28 01:32:51 +02:00
Xavier Del Campo Romero 7517312290
README.md: Provide more details about features 2023-07-28 01:27:19 +02:00
Xavier Del Campo Romero 8c3ba33ced
Move header files to subdirectory
Since slweb is meant as a library, it is advisable to keep public header
files under their own directory in order to avoid name clashing i.e.,

 #include "something.h"

Now becomes:

 #include "slweb/something.h"
2023-07-21 01:28:38 +02:00
Xavier Del Campo Romero 4dd531b9ed
Makefile: Adapt to slweb
This project was forked off slcl, a "suckless" cloud solution, so that
its HTTP/1.1 server implementation could be reused by other
applications.
2023-07-21 01:28:38 +02:00
Xavier Del Campo Romero ffd29ca6e5
Add top-level CMakeLists.txt 2023-07-21 01:28:37 +02:00
Xavier Del Campo Romero ec0e6abddd
Add README.md 2023-07-21 01:28:37 +02:00
Xavier Del Campo Romero abedf4f296
Import dynstr 2023-07-20 23:52:56 +02:00
Xavier Del Campo Romero dbeeb2b526
Add .gitignore 2023-07-20 23:52:56 +02:00
Xavier Del Campo Romero 6c6e4c4fec
Makefile: Allow users to define LDFLAGS
This should allow for easier packaging if extra linker flags are
required.
2023-07-20 23:52:56 +02:00
Xavier Del Campo Romero 9cab9431bb
Allow admins to define their own stylesheet
slcl used to provide a hardcoded stylesheet. However, it would be
desirable for some admins to provide a custom stylesheet without having
to rebuild the application.

Now, slcl creates a default stylesheet, namely style.css, into the
target directory, that can be later modified by admins.

While this might contradict the suckless philosophy a bit, hopefully
some admins might find this new feature useful.
2023-07-20 23:52:56 +02:00
Xavier Del Campo Romero 090eccf092
wildcard_cmp.c: Fix out-of-bounds cmp
When the distance between '*' on a wildcard expression was larger than
the string to compare with, this would cause an out-of-bounds read
because `n` was not being limited to the strlen(3) from the input
string.

Example:

- s="c", p="*cc*", casecmp=false

Here, the distance between the first and second '*' is 2 bytes, which is
longer than the input string itself (1 byte, not counting the
terminating null byte '\0').
2023-07-20 23:52:56 +02:00
Xavier Del Campo Romero e0f43ac410
http.c: Disallow forbidden filenames during upload
- '.' or '..' must not be used for filenames.
- Filenames must not contain forward slashes ('/').
- Filenames must not contain asterisks ('*') to avoid confusion with
wildcard expressions.
2023-07-20 23:52:56 +02:00
Xavier Del Campo Romero f136fdd463
http.c: Use case-insensitive compare for Content-Disposition
HTTP headers are case-insensitive, so the implementation must accept
Content-Diposition, content-disposition or any other variation.
2023-07-20 23:52:56 +02:00
Xavier Del Campo Romero 01cebe5917
server.c: Fix typo 2023-07-20 23:52:55 +02:00
Xavier Del Campo Romero 0c0dee59ce
http.c: Accept resources with '&' or '?'
Otherwise, client requests to resources such as '/me & you', '/?' or
'/??preview=1' would fail.
2023-07-20 23:52:55 +02:00
Xavier Del Campo Romero a527164cb5
server.c: Fix undefined behaviour on >1 clients
server.c kept an array of all of its active clients, calling realloc(3)
everytime its size had to be modified. However, reallocating this array
had the undesired consequence of moving other active clients to other
memory locations.

Potentially, this would result in dangling pointers from other
components that also kept pointers to struct server_client instances
e.g.: handler.c.

For this reason, the array-based approach has been completely dropped,
in favour of a doubly-linked list.
2023-07-20 23:52:55 +02:00
Xavier Del Campo Romero ea16427345
wildcard_cmp.c: Fix a couple of bugs
wildcard_cmp would otherwise fail with the following use cases:

s = "mymi", p = "*mi*"
s = "mymi", p = "*mi"
2023-07-20 23:52:55 +02:00
Xavier Del Campo Romero d639e5d269
wildcard_cmp.c: Remove leftovers
These statements had no effect since it was always executed when
n == 0.
2023-07-20 23:52:55 +02:00
Xavier Del Campo Romero 35ced95c36
wildcard_cmp: Allow case-insensitive searches
The new search feature will require them.
2023-07-20 23:52:55 +02:00
Xavier Del Campo Romero 0759122e4c
Split wildcard_cmp into its own component
Future commits will make use of this function outside handler.c.
2023-07-20 23:52:55 +02:00
Xavier Del Campo Romero 3f64235123
Makefile: Use dynstr's own Makefile
dynstr has been recently modified so as to allow building also from
make(1).
2023-07-20 23:52:54 +02:00
Xavier Del Campo Romero f75ff13b31
Avoid crashing on SIGPIPE
Under some circumstances, clients could cause SIGPIPE to slcl. Since
this signal was not handled by server.c (i.e., via sigaction(3)), slcl
would crash without any error messages printed to stderr.

In such situation, SIGPIPE should not be usually considered a fatal
error, so it is preferrable to close the connection and keep working.
2023-07-20 23:52:54 +02:00