Commit graph

454 commits

Author SHA1 Message Date
31866a14b4 Remove some extraneous whitespace from Util.c, not sure how that got there. 2023-05-07 12:08:26 +00:00
ebc3da9b23 Fix some compile warnings. 2023-05-06 23:06:13 +00:00
a2eec3946c I missed an instance of strcmp() 2023-05-06 23:02:46 +00:00
0b11b97022 Add StrEquals(), as equality checking is the most common use for strcmp().
This allows us to get rid of the hideous MATRIX_PATH_PART_EQUALS macro,
and prevents inconsistent usage of strcmp() (for example, !strcmp() vs
strcmp() == 0).

StrEquals() also has sensible behavior for dealing with NULL strings (it
doesn't just segfault like strcmp()).
2023-05-06 22:34:36 +00:00
0e69a12784 Register route. 2023-05-06 22:06:54 +00:00
2a87583d2f Add /_matrix/client/v3/account/deactivate 2023-05-06 22:06:23 +00:00
95ceba0645 Add length calculations to JsonEncode() so we can set Content-Length. 2023-05-06 19:23:13 +00:00
bbea55be6c Document http-debug-server, fixed typo in HttpServer docs. 2023-05-06 18:21:21 +00:00
872fa1aa66 More documentation. It never ends! 2023-04-29 19:52:51 +00:00
e0c94d7bd2 Site now pulls built man pages. 2023-04-29 18:39:01 +00:00
f819093b7d Don't spew unknown expression warnings if @suppress-warnings is set. 2023-04-29 15:28:42 +00:00
0b1b4a8b29 Cope with preprocessor macro usage at the top level of the header.
This workaround allows us to parse the Routes.h properly, although it
notably lacks support for multi-word unknown expressions.
2023-04-29 15:24:46 +00:00
a3cc06ff2a Fix line numbers when parsing multi-line macros. 2023-04-29 15:16:58 +00:00
2d8d5244c4 Document some new headers. 2023-04-29 15:04:16 +00:00
b70c3f0bed Finish converting all existing documentation. Next up is writing new docs. 2023-04-29 02:54:49 +00:00
71fa96d10d Format source code. 2023-04-27 20:05:08 +00:00
a00ded6d06 Add support for parsing global variables, not just function declarations. 2023-04-27 20:04:15 +00:00
9292f1d9da Add docs recipe for generating documentation from the headers.
Note that since all the headers are not documented yet, this will fail
because an undocumented function is a fatal error in hdoc.
2023-04-27 18:39:05 +00:00
9880aac674 Split format recipe into format and license.
Format formats only C source code. License applies the license file to
C source code *and* header files.
2023-04-27 18:03:32 +00:00
24a03ba126 Added some more header documentation. 2023-04-27 18:00:26 +00:00
95cb14213f Add support for return types that are const, structs, or enums. 2023-04-27 16:02:15 +00:00
6e976a2b8d Fix line counts on syntax errors. 2023-04-27 15:54:21 +00:00
72467f6503 Begin moving documentation to headers. 2023-04-27 03:08:39 +00:00
2447bb63cc Add hdoc, a simple tool for generating documentation from a C header.
This is a very early prototype. It works, but it is probably not efficient
or reliable. However, the documentation format it parses is stable, so I
will begin moving the documentation into the headers.
2023-04-27 01:34:49 +00:00
459b2e856f Format source code. 2023-04-25 22:13:28 +00:00
96ca9a725d Finish up capabilities for now. 2023-04-25 22:11:34 +00:00
e1367d5bff Use snprintf() instead of sprintf().
All linker warnings should now be eliminated.
2023-04-25 22:01:58 +00:00
d83db35df0 Use strncpy() instead of strcpy().
The OpenBSD linker is complaining about it. Even though every single
case strcpy() was used is safe, strncpy() provides a little bit of extra
security, and makes the linker happy.
2023-04-25 21:54:51 +00:00
d933d12e1b Make Rand use a provided Mersenne Twister.
This implementation is loosely inspired by the original paper on the
Mersenne Twister, and borrows code from a public-domain implementation of
it, adapting it to fit the style of Telodendria's code, and fixing a few
bugs regarding the size of the data type used.

Neither C nor POSIX provide a good, thread-safe pseudorandom number
generator. The OpenBSD linker started complaining about the use of
rand_r(), and no standard alternative presented itself as worthy of
consideration, so I finally decided it was time to roll my own PRNG.
2023-04-25 21:28:55 +00:00
098eed44a0 Fix bug in MatrixWellKnown(), begin /_matrix/client/v3/capabilities 2023-04-25 18:37:25 +00:00
05cf076ebc Begin debugging OpenSSL. 2023-04-24 17:05:59 +00:00
a525830b64 Telodendria now responds correctly to SIGTERM. 2023-04-24 16:23:50 +00:00
279f261aed Fix race conditions that are possible in Db.
This is accomplished by locking the entire database, and keeping it locked
until the last reference is unlocked. We get rid of per-reference locks,
because those are what cause race conditions.
2023-04-24 16:19:17 +00:00
313249ca88 Fixed some caching bugs in Db.
Note that Db has the potential to deadlock when caching is being used,
and when caching isn't being used, an inconsistent state can occur. Future
changes to Db will fix both of these issues.
2023-04-24 15:43:24 +00:00
737e060243 Finish up Uia fallback. 2023-04-22 15:40:25 +00:00
5431c2cd90 Fix double-free in UiaCleanup(). 2023-04-22 13:45:01 +00:00
2bbe13aaf0 Fix error setting up UIA flows. 2023-04-22 02:06:22 +00:00
866343071a Continued work on UIA fallback. 2023-04-22 00:59:03 +00:00
6a5d89e14b Work on implementing user interactive authentication fallback. 2023-04-21 02:13:06 +00:00
fb24f93aaa Fix bug with TLS where cert and key files were used after freeing them. 2023-04-20 21:12:08 +00:00
0b7282c36a Fix build errors on some compilers due to missing symbols. 2023-04-20 19:19:23 +00:00
ec09882dbe Fix warnings about memset() 2023-04-20 17:50:22 +00:00
3b28af2031 Fix warning on some compilers. 2023-04-20 17:40:14 +00:00
19b0dcac5a Don't build the routing tree until absolutely necessary.
Saves us a lot of time and memory in case of an error.
2023-04-20 17:37:18 +00:00
4a5c7480aa Fix up a few small warnings. 2023-04-20 13:49:25 +00:00
25b7c0d059 Begin documenting Admin API. 2023-04-19 21:45:15 +00:00
ffeb45375e Implement /_telodendria/admin/privileges
Note that it's not exactly as the proposal defines it; theres a bit more
nuance that will be documented soon.
2023-04-19 18:52:05 +00:00
ae38791df2 Format code, remove dataDir from sample production.conf 2023-04-19 02:07:38 +00:00
0cca38115a Move configuration to database, add process control API, fix memory leaks. 2023-04-19 00:33:38 +00:00
ff4d265dcc Registration tokens now determine what privileges a user gets. 2023-04-16 18:32:22 +00:00
582df63a31 Format source code. 2023-04-16 17:51:52 +00:00
4ee66ae3c7 Begin implementing user privileges. 2023-04-16 17:51:03 +00:00
6ca1265076 Begin working on User-Interactive authentication fallback. 2023-04-15 02:36:28 +00:00
e882693c78 Add route for requestToken endpoints. 2023-04-14 23:59:40 +00:00
b21d018daa Move router building function into a more sensible location. 2023-04-14 21:37:00 +00:00
83971dfaff Refactor routing system to use HttpRouter. 2023-04-14 21:20:56 +00:00
a90f7c4b9e Apply #69 2023-04-14 17:50:14 +00:00
1f8df737da Add HttpRouter API; still have to convert the code to use it. 2023-04-06 01:48:32 +00:00
7c865d06fd Format code. 2023-04-01 02:46:59 +00:00
e0c8530b12 Clean up http client enough to replace curl in send-patch. 2023-04-01 02:46:07 +00:00
e592840c99 Clean up some HTTP client stuff. 2023-04-01 02:13:41 +00:00
7b3d537175 Remove UtilStreamCopy() 2023-04-01 00:20:18 +00:00
f341fd2b6e Fix OpenSSL server accept call.
Apparently it can EAGAIN on non-blocking connections... I don't think
LibreSSL's TLS library does this, but something to keep in mind if it
doesn't work for somebody.
2023-03-31 23:10:52 +00:00
eef615fc9a Fix warnings in RouteChangePwd.c 2023-03-28 02:28:58 +00:00
9b21e2460a Accept #67: Add the password modification endpoint. 2023-03-28 01:17:47 +00:00
c6f4a4a546 Fix leak of StreamStdout() when logging to a file. 2023-03-27 17:56:45 +00:00
c37d3801b2 Fix warning about uninitialized variable. 2023-03-25 00:00:53 +00:00
a24c27bf4f Fix leak in TlsOpenSSL. 2023-03-24 17:37:44 +00:00
af776c64a7 Remove duplicate return line. 2023-03-24 14:18:29 +00:00
a25573063f Fix up TlsOpenSSL a little bit.
Server is still broken...
2023-03-24 03:05:12 +00:00
aeb49f80e5 Add support for OpenSSL. This is a good demo of how easy it is to support TLS libraries. 2023-03-24 02:41:01 +00:00
fe32c652cd Fix bug in HttpClient where it wouldn't retry on EAGAIN. 2023-03-24 00:23:49 +00:00
20d41d794b Fix compile error. I had this in here at some point, not sure where it went. 2023-03-23 17:41:02 +00:00
e13442c122 Fix strange behavior in TlsLibreSSL.
tls_read() and tls_write() may return TLS_WANT_POLLIN or TLS_WANT_POLLOUT
if data isn't ready to be read or written yet. We have to account for this
by converting it to EAGAIN, which is how a typical read() or write()
function should behave.

Also installed a SIGPIPE handler; we do not want to be terminated by
SIGPIPE, and it's safe to ignore this signal because it should be
handled thoroughly in the code.
2023-03-23 16:39:15 +00:00
2441f07848 Add support for spinning up multiple HTTP servers.
This is useful for having a TLS and a non-TLS version port, like Synapse.
I verified that the multiple-servers does in fact work as intended,
although the TLS server part is broken; I must be doing something
incorrectly with LibreSSL in setting up the server.
2023-03-23 02:12:45 +00:00
2fab7b55fe Remove obsolete warning about setting root directory.
We don't use chroot() anymore.
2023-03-22 18:30:30 +00:00
089d8d4d94 Only install the memory hook if -v is given.
This way, we can still set the debug level in the configuration, and not
see the log just absolutely flooded with memory allocations and whatnot.
This is helpful because I want debug messages to show up in development,
but not in production, but having all the memory logging makes it
almost impossible to pick anything else out of the log. I want the
feature available, just not on by default because it's useful in limited
circumstances.
2023-03-22 18:29:05 +00:00
9ec330f40a Log once we get the response status, not right when we get the request. 2023-03-22 18:13:59 +00:00
8faf6f2126 Delete TelodendriaConfig.c 2023-03-22 17:20:53 +00:00
fc975e6a93 TelodendriaConfig -> Config 2023-03-22 17:17:30 +00:00
413c7ad803 Start building support for running multiple HTTP servers.
The standard use case for this is going to be running a TLS and a non-TLS
HTTP server. I can't see a need for *more* than two, but it is theoretically
possible.

We shouldn't have to change anything with the database or anything; it
should suffice to simply spin up more HTTP servers, and they should
interact with each other the same way a single HTTP server with multiple
threads will.
2023-03-22 17:00:48 +00:00
e30fa3ee33 Remove remnants of non-global LogConfig from TelodendriaConfig 2023-03-22 16:31:24 +00:00
e6f3dfad18 Add an ArraySet() method for replacing entries in an array.
This is much more efficient than using ArrayDelete() and ArrayInsert(),
and will serve us well in the future.
2023-03-22 16:31:06 +00:00
f3c4c0ac65 Add a global log configuration.
This is the easiest and cleanest way to get logging into some of the
fundamental APIs, such as the database and TLS APIs. We don't want to
have to pass logging functions to those, but they can safely use the
global logging configuration.
2023-03-22 14:52:04 +00:00
8782aa046d Fix compile error in Tls, work on getting certs and keys into HttpServer. 2023-03-22 02:18:31 +00:00
bdaea9872e Format source code. 2023-03-22 01:46:45 +00:00
b58ca7d22e Start working on adding TLS support to HttpServer. 2023-03-22 01:46:24 +00:00
6561b5bae1 Add TLS build support to td. 2023-03-22 01:17:42 +00:00
996356832e Define TLS API, update HttpClient to support optional TLS.
Also added a LibreSSL TLS implementation. Client is verified to work;
server has not been tested yet.
2023-03-22 00:41:21 +00:00
2a92d0de7e Fix bit flag check. 2023-03-22 00:11:24 +00:00
4a27f50538 Remove calls to pledge(), unveil(), and chroot().
Not only does this make us more POSIX, it actually makes things a lot
easier because TLS implementations will need to be able to access the
trusted certificates file, which most likely will not live in the
data directory.
2023-03-20 19:23:37 +00:00
6c9e939b9f Fix broken IoVprintf().
You can't call vsnprintf() on the same va_list more than once! I learned
this the hard way with StreamVprintf().
2023-03-18 14:55:04 +00:00
5289c16e2b Convert all code to new Stream API.
Also made a number of improvmements to tt, making it compatible with more
shells.
2023-03-18 14:32:09 +00:00
a97a593f21 Format code. 2023-03-16 16:53:18 +00:00
27b3b6cdc6 Add StreamPuts(), don't make StreamVprintf() defer to IoVprintf(). 2023-03-16 16:51:41 +00:00
8539a03d5b Add StreamFile() convenience method. 2023-03-16 16:25:24 +00:00
e0a3760a37 Don't buffer in IoWrite(), indicate that fwrite() returns size_t, not ssize_t. 2023-03-16 14:17:04 +00:00
6ee1857f5f Format source code. 2023-03-16 12:29:38 +00:00
7d9770fc12 Add some convenience functions for working with Io and Stream.
Also broke out IoFd into it's own file, and did the same with IoFile.
2023-03-16 12:28:55 +00:00
65f4c90df3 Rename HttpStream() to HttpServerStream() to match HttpClientStream() 2023-03-16 02:17:48 +00:00