Commit Graph

961 Commits

Author SHA1 Message Date
Omar Polo 6d91731552
fmt 2020-12-27 13:27:15 +01:00
Omar Polo f722f3c5aa
typos 2020-12-26 11:22:07 +01:00
Omar Polo 60ff035518
mention IRI in changelong 2020-12-26 10:15:16 +01:00
Omar Polo 00781742c5
reject %00 2020-12-26 00:37:43 +01:00
Omar Polo df6ca41da3
IRI support
This extends the URI parser so it supports full IRI (Internationalized
Resource Identifiers, RFC3987).  Some areas of it can/may be improved,
but here's a start.

Note: we assume UTF-8 encoded IRI.
2020-12-26 00:33:11 +01:00
Omar Polo 043acc97b1
mention the %2F caveat 2020-12-25 13:15:15 +01:00
Omar Polo 33d32d1fd6
implement a valid RFC3986 (URI) parser
Up until now I used a "poor man" approach: the uri parser is barely a
parser, it tries to extract the path from the request, with some minor
checking, and that's all.  This obviously is not RFC3986-compliant.

The new RFC3986 (URI) parser should be fully compliant.  It may accept
some invalid URI, but shouldn't reject or mis-parse valid URI.  (in
particular, the rule for the path is way more relaxed in this parser
than it is in the RFC text).

A difference with RFC3986 is that we don't even try to parse the
(optional) userinfo part of a URI: following the Gemini spec we treat
it as an error.

A further caveats is that %2F in the path part of the URI is
indistinguishable from a literal '/': this is NOT conforming, but due
to the scope and use of gmid, I don't see how treat a %2F sequence in
the path (reject the URI?).
2020-12-25 13:13:12 +01:00
Omar Polo d5aba4c791
added missing copyright stuff 2020-12-24 16:49:55 +01:00
Omar Polo 488f059ac4
moving declarations to header file 2020-12-24 16:48:39 +01:00
Omar Polo 83000e2dd4
improve wording
"concurrently" means at the same time, which can be confusing when we
say that it's single-threaded on a single process.
2020-12-21 15:51:09 +01:00
Omar Polo 51d876f030
always check absolutify_path return 2020-12-21 15:42:06 +01:00
Omar Polo 4f12842dfe
mention change in changelog file 2020-12-21 14:40:04 +01:00
Omar Polo 231bfcdc03
make -d handle correctly non-absolute paths
before the -d option only accepted absolute paths, and this wasn't
documented.  Even more, with the default value of "docs" it won't
work.  Now it transforms all relative paths to absolute paths before
going on.
2020-12-21 14:38:31 +01:00
Omar Polo dd3e110a70
reorder & fmt 2020-12-20 20:03:55 +01:00
Omar Polo d7802bb44a
logging reworked and daemonize by default
The -l option was removed: now it logs on syslog if -f (foreground) is
not passed.
2020-12-02 21:18:01 +01:00
Omar Polo 677afbd3f8
clients certs support for CGI
internally, gmid doesn’t care if the client issued a certificate, but
now we pass that information to the CGI script in some new environment
variables.
2020-12-02 15:17:19 +01:00
Omar Polo c603f1260d
fix bug introduced in last version regarding full URLs
gemini://example.com was incorrectly parsed.
2020-11-18 09:45:28 +01:00
Omar Polo dd3895586f
mention the bugfix and tag 1.3.1 2020-11-18 09:36:18 +01:00
Omar Polo 7cd6880b84
correctly handle also non absolute URLs 2020-11-18 09:34:42 +01:00
Omar Polo ae2ad03ec0
handle //example.com urls 2020-11-18 09:32:07 +01:00
Omar Polo 721e232529
make port number configurable 2020-11-18 09:12:27 +01:00
Omar Polo d431188c66
fixed changelog format for old entries 2020-11-10 18:14:07 +01:00
Omar Polo a5d310bc0d
[cgi] added support for path parameters
enhance the CGI scripting support so that script can take path
parameters.  That is, a script at /cgi/foo is called when the request
path is /cgi/foo/bar/...

This commit also introduce some backward incompatible changes as the
default env variables set for the CGI script changed.
2020-11-10 14:07:36 +01:00
Omar Polo 92e66347ed
regen readme 2020-11-06 18:12:57 +01:00
Omar Polo 0ed5656795
documentation improvements 2020-11-06 18:11:45 +01:00
Omar Polo 72f653b652
[cgi] execute cgi scripts only inside a specific directory
change the meaning of the -x flag: now it takes a string and executes
CGI scripts only if they are inside a directory with the given name,
relatively to the document root.
2020-11-06 18:05:44 +01:00
Omar Polo f65ed01841
[cgi] set QUERY_STRING only if there is a query string 2020-11-06 18:02:41 +01:00
Omar Polo 120381c93d
[debug] print number of connected clients on SIGINFO
or SIGUSR2 for poor peoples
2020-11-06 17:09:30 +01:00
Omar Polo aff8d19010
handle CGI concurrently
don’t stop-the-world-until-cgi-end, but rather poll on the script, so
we can handle other requests in the meantime.
2020-11-06 17:09:14 +01:00
Omar Polo 60ba426e7e
[cgi] setenv instead of building an env + define more env variables 2020-11-06 15:07:33 +01:00
Omar Polo 75d233f00c
pass the query parameter to start_cgi 2020-11-06 15:06:50 +01:00
Omar Polo aa0fe0cf24
extract query parameters from the URL 2020-11-06 15:04:16 +01:00
Omar Polo 3c19febb01
ensure the requested protocol is “gemini”
…and not something else that happens to be 6-bytes long.
2020-11-06 14:24:25 +01:00
Omar Polo e8cac16e03
mark every open file as close-on-exec 2020-11-06 14:18:17 +01:00
Omar Polo 72342dc960
implementing CGI – NOT READY YET!
This is a first try at implementing CGI scripting.  The idea is that,
if CGI is explicitly enabled by the user, when a user requires an
executable file instead of serving it to the client, that file will be
executed and its output fed to the client.

There are various pieces that are still lacking, the firsts that comes
to mind are:

 - performance: the handle_cgi just loops ignoring the
   WANT_POLLIN/POLLOUT and blocking if the child process hasn’t
   outputted anything.
 - we don’t parse query variable (yet)
 - we need to set more variables in the child environment
   side question: it’s better to set the variables using setenv() or
   by providing an explicit environment?
 - document what environment the CGI script will get
 - improve the horrible unveil/pledge(cgi ? …)

but now I can serve “hello-world”-tier script from gmid!
2020-11-06 13:01:31 +01:00
Omar Polo 2c3a40faf8
added option to log to a file 2020-11-06 10:58:30 +01:00
Omar Polo 932b001a3f
typo 2020-11-06 10:45:06 +01:00
Omar Polo 20f688381a
doc: point out that we can handle multiple clients concurrently 2020-11-05 17:06:12 +01:00
Omar Polo dd080e1f75
define a MIME type for xml files 2020-11-05 17:05:28 +01:00
Omar Polo 19f68393e6
update the changelog and tag 1.2 2020-11-03 15:51:13 +01:00
Omar Polo 0cf902af62
ignore SIGPIPE
bad clients can shutdown the socket and we will exit due to a SIGPIPE.
it ain’t fun.
2020-11-03 15:48:26 +01:00
Omar Polo 9468027ba7
initial work for ipv6
make_socket can now return an ipv6 socket, and everything else still
works.  ipv4 is still hardcoded tho.
2020-10-15 13:45:57 +02:00
Omar Polo 4f6eb772cb
new release: 1.1 2020-10-14 10:17:27 +02:00
Omar Polo 2b897a2cea
added a changelog file 2020-10-14 10:14:11 +02:00
Omar Polo f28f931139
switching to mmap() based file handling 2020-10-14 10:09:06 +02:00
Omar Polo 9c56b0a78a
style 2020-10-14 10:09:00 +02:00
Omar Polo 10fed44c79
improve make error message if etags is not found
the ‘|| true’ idiom leads to better make error.  Now the ‘-’ becomes a
bit redundant tho…
2020-10-07 17:59:55 +02:00
Omar Polo 09a1b97896
put back the missing lseek, and change variables name
(I know, changing variables names AND introducing changes is better
done in more commits, but…)

Added back an lseek that was missing.  If TLS_WANT_POLL{IN,OUT}, we
need to re-send that block, but we need also to rewind the file, in
order to read(2) that chunk again.  This doesn’t solve the corruption
in transferring big files, but reduces them.  I still haven’t tracked
down the corruption :/
2020-10-07 17:59:31 +02:00
Omar Polo cc68fe70fc
added support for mime types (by looking at file extension)
At the moment there is an hardcoded table that maps mime types to
extensions.  For the time being this can be OK, as I don’t even
currently serve all those types of file, but in the future I’d like to
let user pass a file with the mapping, like /usr/share/misc/mime.types
on OpenBSD, to map.  However, even in this case, we should hardcode
text/gemini IMHO, since most mime.types listing doesn’t have it yet.
2020-10-07 14:41:32 +02:00
Omar Polo 592fd62453
rewrote the main loop to use poll
We can handle up to MAX_USERS (64 by default) concurrently.

Now, given that we don’t support CGI, it’s not a big deal.  Gemini
requests are small (up to 1024 bytes), and also the replies from the
server are small (one line plus the document — if any), all over TLS
obviously. (but even there, it’s lighter than HTTP because we don’t
need to send the whole chain for the certificate — see TOFU).

Given all the above, this doesn’t really improve the performance in
the real world, but it’s nice to have.  The main use case for this is
to disallow slow clients to stop fast clients.
2020-10-07 14:41:17 +02:00