Fix leak in RouteConfig, update documentation.

Closes #15.
This commit is contained in:
Jordan Bancino 2023-11-07 01:26:26 -05:00
parent 6e7f170768
commit 4b90800a2b
3 changed files with 25 additions and 4 deletions

View file

@ -31,6 +31,8 @@ Matrix clients. (#35)
- Implemented `/_telodendria/admin/v1/deactivate/[localpart]` for admins to be able to
deactivate users.
- Added a **PUT** option to `/_telodendria/admin/v1/config` that gives the ability to change
only a subset of the configuration.
- Moved all administrator API endpoints to `/_telodendria/admin/v1`, because later revisions
of the administrator API may break clients, so we want a way to give those breaking revisions
new endpoints.

View file

@ -4,7 +4,7 @@ As mentioned in [Setup](../setup.md), Telodendria's configuration is
intended to be managed via the configuration API. Consult the
[Configuration](../config.md) document for a complete list of supported
configuration options. This document simply describes the API used to
update the configuration.
update the configuration described in that document.
## API Endpoints
@ -40,3 +40,23 @@ configuration with the new one.
|-------|------|-------------|
| `restart_required` | `Boolean` | Whether or not the process needs to be restarted to finish applying the configuration. If this is `true`, then the restart endpoint should be used at a convenient time to apply the configuration.
### **PUT** `/_telodendria/admin/config`
Update the currently installed configuration instead of completely replacing it. This endpoint
validates the request body, merges it on top of the current configuration, validates the resulting
configuration, then updates it in the database. This is useful when only one or two properties
in the configuration needs to be changed.
| Requires Token | Rate Limited |
|----------------|--------------|
| Yes | Yes |
| Response Code | Description |
|---------------|-------------|
| 200 | The new configuration was successfully installed.|
#### 200 Response Format
| Field | Type | Description |
|-------|------|-------------|
| `restart_required` | `Boolean` | Whether or not the process needs to be restarted to finish applying the configuration. If this is `true`, then the restart endpoint should be used at a convenient time to apply the configuration.

View file

@ -135,8 +135,6 @@ ROUTE_IMPL(RouteConfig, path, argp)
newConf = ConfigParse(newJson);
/* TODO: Don't leak newJson. */
if (!newConf)
{
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
@ -169,10 +167,11 @@ ROUTE_IMPL(RouteConfig, path, argp)
ConfigFree(newConf);
JsonFree(request);
JsonFree(newJson);
break;
default:
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
response = MatrixErrorCreate(M_UNRECOGNIZED, "Unknown request method.");
break;
}