[ADD] WIP: User directory from #70 + .gitignore.

Still as WIP as the original however!
This commit is contained in:
lda 2023-09-06 07:31:45 +02:00
parent 0b820b80f7
commit b9e5d885f4
14 changed files with 3700 additions and 0 deletions

6
.gitignore vendored
View file

@ -1,3 +1,4 @@
<<<<<<< HEAD
build
data
.env
@ -12,3 +13,8 @@ contrib/.vagrant
src/Schema
src/include/Schema
man/mandoc.db
=======
# Telodendria .gitignore
build/*
Cytoplasm/build/*
>>>>>>> b099a3e ([ADD] WIP: User directory from #70 + .gitignore.)

View file

@ -71,6 +71,7 @@ RouterBuild(void)
R("/_matrix/client/v3/profile/(.*)", RouteUserProfile);
R("/_matrix/client/v3/profile/(.*)/(avatar_url|displayname)", RouteUserProfile);
R("/_matrix/client/v3/user_directory/search", RouteUserDirectory);
R("/_matrix/client/v3/user/(.*)/filter", RouteFilter);
R("/_matrix/client/v3/user/(.*)/filter/(.*)", RouteFilter);

View file

@ -0,0 +1,209 @@
/*
* Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <Routes.h>
#include <Array.h>
#include <HashMap.h>
#include <Json.h>
#include <Str.h>
#include <Memory.h>
#include <User.h>
#include <Db.h>
ROUTE_IMPL(RouteUserDirectory, path, argp)
{
RouteArgs *args = argp;
HashMap *response = NULL;
HashMap *request = NULL;
Array *users = NULL;
Array *results = NULL;
Db *db = args->matrixArgs->db;
Config *config = NULL;
User *user = NULL;
JsonValue *val = NULL;
char *token = NULL;
char *searchTerm = NULL;
char *requesterName = NULL;
size_t limit = 10;
size_t i, included;
(void) path;
if (HttpRequestMethodGet(args->context) != HTTP_POST)
{
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED);
goto finish;
}
request = JsonDecode(HttpServerStream(args->context));
if (!request)
{
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_NOT_JSON);
goto finish;
}
response = MatrixGetAccessToken(args->context, &token);
if (response)
{
return response;
}
/* TODO: Actually use information related to the user. */
user = UserAuthenticate(db, token);
if (!user)
{
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
goto finish;
}
requesterName = UserGetName(user);
/* Parse limit and search_term */
if (!(val = JsonGet(request, 1, "search_term")) ||
JsonValueType(val) != JSON_STRING)
{
/* The Spec requires search_term to be set to a string. */
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON);
goto finish;
}
searchTerm = StrLower(JsonValueAsString(val));
if ((val = JsonGet(request, 1, "limit")) &&
JsonValueType(val) == JSON_INTEGER)
{
/* It is however far more leinent on limit, with 10 by default. */
limit = JsonValueAsInteger(val);
}
response = HashMapCreate();
results = ArrayCreate();
/* TODO: Check for users matching search term and users outside our
* local server. */
users = DbList(db, 1, "users");
/* Offending line? */
config = ConfigLock(db);
if (!config)
{
Log(LOG_ERR, "Directory endpoint failed to lock configuration.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
response = MatrixErrorCreate(M_UNKNOWN);
goto finish;
}
for (i = 0, included = 0; i < ArraySize(users) && included < limit; i++)
{
HashMap *obj;
User *currentUser;
char *name = ArrayGet(users, i);
char *displayName;
char *lowerDisplayName;
char *avatarUrl;
if (!StrEquals(name, requesterName))
{
currentUser = UserLock(db, name);
}
else
{
currentUser = user;
}
displayName = UserGetProfile(currentUser, "displayname");
lowerDisplayName = StrLower(displayName);
avatarUrl = UserGetProfile(currentUser, "avatar_url");
/* Check for the user ID and display name. */
if (strstr(name, searchTerm) ||
(lowerDisplayName && strstr(lowerDisplayName, searchTerm)))
{
included++;
obj = HashMapCreate();
if (displayName)
{
JsonSet(obj, JsonValueString(displayName), 1, "display_name");
}
if (avatarUrl)
{
JsonSet(obj, JsonValueString(displayName), 1, "avatar_url");
}
if (name)
{
char *userID = StrConcat(4, "@", name, ":", config->serverName);
JsonSet(obj, JsonValueString(userID), 1, "user_id");
Free(userID);
}
ArrayAdd(results, JsonValueObject(obj));
}
if (lowerDisplayName)
{
Free(lowerDisplayName);
}
if (!StrEquals(name, requesterName))
{
UserUnlock(currentUser);
}
}
JsonSet(response, JsonValueArray(results), 1, "results");
JsonSet(response, JsonValueBoolean(included == limit), 1, "limited");
finish:
if (user)
{
UserUnlock(user);
}
if (request)
{
JsonFree(request);
}
if (searchTerm)
{
Free(searchTerm);
}
if (users)
{
DbListFree(users);
}
if (config)
{
ConfigUnlock(config);
}
return response;
}

299
src/Schema/ClientEvent.c Normal file
View file

@ -0,0 +1,299 @@
/* Generated by j2s */
#include <Schema/ClientEvent.h>
#include <Memory.h>
#include <Json.h>
#include <Str.h>
int
ClientEventUnsignedDataFromJson(HashMap *json, ClientEventUnsignedData *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to ClientEventUnsignedDataFromJson()";
return 0;
}
val = HashMapGet(json, "redacted_because");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "ClientEventUnsignedData.redacted_because must be of type object.";
return 0;
}
out->redacted_because = JsonValueAsObject(JsonValueDuplicate(val));
}
val = HashMapGet(json, "transaction_id");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "ClientEventUnsignedData.transaction_id must be of type string.";
return 0;
}
out->transaction_id = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "prev_content");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "ClientEventUnsignedData.prev_content must be of type object.";
return 0;
}
out->prev_content = JsonValueAsObject(JsonValueDuplicate(val));
}
val = HashMapGet(json, "age");
if (val)
{
if (JsonValueType(val) != JSON_INTEGER)
{
*errp = "ClientEventUnsignedData.age must be of type integer.";
return 0;
}
out->age = JsonValueAsInteger(val);
}
return 1;
}
HashMap *
ClientEventUnsignedDataToJson(ClientEventUnsignedData *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
HashMapSet(json, "redacted_because", JsonValueObject(JsonDuplicate(val->redacted_because)));
HashMapSet(json, "transaction_id", JsonValueString(val->transaction_id));
HashMapSet(json, "prev_content", JsonValueObject(JsonDuplicate(val->prev_content)));
HashMapSet(json, "age", JsonValueInteger(val->age));
return json;
}
void
ClientEventUnsignedDataFree(ClientEventUnsignedData *val)
{
if (!val)
{
return;
}
JsonFree(val->redacted_because);
Free(val->transaction_id);
JsonFree(val->prev_content);
}
int
ClientEventFromJson(HashMap *json, ClientEvent *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to ClientEventFromJson()";
return 0;
}
val = HashMapGet(json, "origin_server_ts");
if (val)
{
if (JsonValueType(val) != JSON_INTEGER)
{
*errp = "ClientEvent.origin_server_ts must be of type integer.";
return 0;
}
out->origin_server_ts = JsonValueAsInteger(val);
}
else
{
*errp = "ClientEvent.origin_server_ts is required.";
return 0;
}
val = HashMapGet(json, "content");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "ClientEvent.content must be of type object.";
return 0;
}
out->content = JsonValueAsObject(JsonValueDuplicate(val));
}
else
{
*errp = "ClientEvent.content is required.";
return 0;
}
val = HashMapGet(json, "room_id");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "ClientEvent.room_id must be of type string.";
return 0;
}
out->room_id = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "ClientEvent.room_id is required.";
return 0;
}
val = HashMapGet(json, "sender");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "ClientEvent.sender must be of type string.";
return 0;
}
out->sender = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "ClientEvent.sender is required.";
return 0;
}
val = HashMapGet(json, "state_key");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "ClientEvent.state_key must be of type string.";
return 0;
}
out->state_key = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "event_id");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "ClientEvent.event_id must be of type string.";
return 0;
}
out->event_id = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "ClientEvent.event_id is required.";
return 0;
}
val = HashMapGet(json, "type");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "ClientEvent.type must be of type string.";
return 0;
}
out->type = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "ClientEvent.type is required.";
return 0;
}
val = HashMapGet(json, "unsigned");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "ClientEvent.unsigned must be of type ClientEventUnsignedData.";
return 0;
}
if (!ClientEventUnsignedDataFromJson(JsonValueAsObject(val), &out->_unsigned, errp))
{
return 0;
}
}
return 1;
}
HashMap *
ClientEventToJson(ClientEvent *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
HashMapSet(json, "origin_server_ts", JsonValueInteger(val->origin_server_ts));
HashMapSet(json, "content", JsonValueObject(JsonDuplicate(val->content)));
HashMapSet(json, "room_id", JsonValueString(val->room_id));
HashMapSet(json, "sender", JsonValueString(val->sender));
HashMapSet(json, "state_key", JsonValueString(val->state_key));
HashMapSet(json, "event_id", JsonValueString(val->event_id));
HashMapSet(json, "type", JsonValueString(val->type));
HashMapSet(json, "unsigned", JsonValueObject(ClientEventUnsignedDataToJson(&val->_unsigned)));
return json;
}
void
ClientEventFree(ClientEvent *val)
{
if (!val)
{
return;
}
JsonFree(val->content);
Free(val->room_id);
Free(val->sender);
Free(val->state_key);
Free(val->event_id);
Free(val->type);
ClientEventUnsignedDataFree(&val->_unsigned);
}

1193
src/Schema/Filter.c Normal file

File diff suppressed because it is too large Load diff

477
src/Schema/PduV1.c Normal file
View file

@ -0,0 +1,477 @@
/* Generated by j2s */
#include <Schema/PduV1.h>
#include <Memory.h>
#include <Json.h>
#include <Str.h>
int
PduV1EventHashFromJson(HashMap *json, PduV1EventHash *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to PduV1EventHashFromJson()";
return 0;
}
val = HashMapGet(json, "sha256");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV1EventHash.sha256 must be of type string.";
return 0;
}
out->sha256 = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "PduV1EventHash.sha256 is required.";
return 0;
}
return 1;
}
HashMap *
PduV1EventHashToJson(PduV1EventHash *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
HashMapSet(json, "sha256", JsonValueString(val->sha256));
return json;
}
void
PduV1EventHashFree(PduV1EventHash *val)
{
if (!val)
{
return;
}
Free(val->sha256);
}
int
PduV1FromJson(HashMap *json, PduV1 *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to PduV1FromJson()";
return 0;
}
val = HashMapGet(json, "origin_server_ts");
if (val)
{
if (JsonValueType(val) != JSON_INTEGER)
{
*errp = "PduV1.origin_server_ts must be of type integer.";
return 0;
}
out->origin_server_ts = JsonValueAsInteger(val);
}
else
{
*errp = "PduV1.origin_server_ts is required.";
return 0;
}
val = HashMapGet(json, "content");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "PduV1.content must be of type object.";
return 0;
}
out->content = JsonValueAsObject(JsonValueDuplicate(val));
}
else
{
*errp = "PduV1.content is required.";
return 0;
}
val = HashMapGet(json, "redacts");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV1.redacts must be of type string.";
return 0;
}
out->redacts = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "sender");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV1.sender must be of type string.";
return 0;
}
out->sender = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "PduV1.sender is required.";
return 0;
}
val = HashMapGet(json, "depth");
if (val)
{
if (JsonValueType(val) != JSON_INTEGER)
{
*errp = "PduV1.depth must be of type integer.";
return 0;
}
out->depth = JsonValueAsInteger(val);
}
else
{
*errp = "PduV1.depth is required.";
return 0;
}
val = HashMapGet(json, "prev_events");
if (val)
{
if (JsonValueType(val) != JSON_ARRAY)
{
*errp = "PduV1.prev_events must be of type array.";
return 0;
}
out->prev_events = JsonValueAsArray(JsonValueDuplicate(val));
}
else
{
*errp = "PduV1.prev_events is required.";
return 0;
}
val = HashMapGet(json, "type");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV1.type must be of type string.";
return 0;
}
out->type = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "PduV1.type is required.";
return 0;
}
val = HashMapGet(json, "unsigned");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "PduV1.unsigned must be of type PduV1UnsignedData.";
return 0;
}
if (!PduV1UnsignedDataFromJson(JsonValueAsObject(val), &out->_unsigned, errp))
{
return 0;
}
}
val = HashMapGet(json, "auth_events");
if (val)
{
if (JsonValueType(val) != JSON_ARRAY)
{
*errp = "PduV1.auth_events must be of type array.";
return 0;
}
out->auth_events = JsonValueAsArray(JsonValueDuplicate(val));
}
else
{
*errp = "PduV1.auth_events is required.";
return 0;
}
val = HashMapGet(json, "room_id");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV1.room_id must be of type string.";
return 0;
}
out->room_id = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "PduV1.room_id is required.";
return 0;
}
val = HashMapGet(json, "state_key");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV1.state_key must be of type string.";
return 0;
}
out->state_key = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "signatures");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "PduV1.signatures must be of type object.";
return 0;
}
out->signatures = JsonValueAsObject(JsonValueDuplicate(val));
}
else
{
*errp = "PduV1.signatures is required.";
return 0;
}
val = HashMapGet(json, "event_id");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV1.event_id must be of type string.";
return 0;
}
out->event_id = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "PduV1.event_id is required.";
return 0;
}
val = HashMapGet(json, "hashes");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "PduV1.hashes must be of type PduV1EventHash.";
return 0;
}
if (!PduV1EventHashFromJson(JsonValueAsObject(val), &out->hashes, errp))
{
return 0;
}
}
else
{
*errp = "PduV1.hashes is required.";
return 0;
}
return 1;
}
HashMap *
PduV1ToJson(PduV1 *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
HashMapSet(json, "origin_server_ts", JsonValueInteger(val->origin_server_ts));
HashMapSet(json, "content", JsonValueObject(JsonDuplicate(val->content)));
HashMapSet(json, "redacts", JsonValueString(val->redacts));
HashMapSet(json, "sender", JsonValueString(val->sender));
HashMapSet(json, "depth", JsonValueInteger(val->depth));
if (val->prev_events)
{
size_t i;
Array *jsonArr = ArrayCreate();
if (!jsonArr)
{
JsonFree(json);
return NULL;
}
for (i = 0; i < ArraySize(val->prev_events); i++)
{
ArrayAdd(jsonArr, JsonValueDuplicate(ArrayGet(val->prev_events, i)));
}
HashMapSet(json, "prev_events", JsonValueArray(jsonArr));
}
HashMapSet(json, "type", JsonValueString(val->type));
HashMapSet(json, "unsigned", JsonValueObject(PduV1UnsignedDataToJson(&val->_unsigned)));
if (val->auth_events)
{
size_t i;
Array *jsonArr = ArrayCreate();
if (!jsonArr)
{
JsonFree(json);
return NULL;
}
for (i = 0; i < ArraySize(val->auth_events); i++)
{
ArrayAdd(jsonArr, JsonValueDuplicate(ArrayGet(val->auth_events, i)));
}
HashMapSet(json, "auth_events", JsonValueArray(jsonArr));
}
HashMapSet(json, "room_id", JsonValueString(val->room_id));
HashMapSet(json, "state_key", JsonValueString(val->state_key));
HashMapSet(json, "signatures", JsonValueObject(JsonDuplicate(val->signatures)));
HashMapSet(json, "event_id", JsonValueString(val->event_id));
HashMapSet(json, "hashes", JsonValueObject(PduV1EventHashToJson(&val->hashes)));
return json;
}
void
PduV1Free(PduV1 *val)
{
if (!val)
{
return;
}
JsonFree(val->content);
Free(val->redacts);
Free(val->sender);
if (val->prev_events)
{
size_t i;
for (i = 0; i < ArraySize(val->prev_events); i++)
{
JsonValueFree(ArrayGet(val->prev_events, i));
}
ArrayFree(val->prev_events);
}
Free(val->type);
PduV1UnsignedDataFree(&val->_unsigned);
if (val->auth_events)
{
size_t i;
for (i = 0; i < ArraySize(val->auth_events); i++)
{
JsonValueFree(ArrayGet(val->auth_events, i));
}
ArrayFree(val->auth_events);
}
Free(val->room_id);
Free(val->state_key);
JsonFree(val->signatures);
Free(val->event_id);
PduV1EventHashFree(&val->hashes);
}
int
PduV1UnsignedDataFromJson(HashMap *json, PduV1UnsignedData *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to PduV1UnsignedDataFromJson()";
return 0;
}
val = HashMapGet(json, "age");
if (val)
{
if (JsonValueType(val) != JSON_INTEGER)
{
*errp = "PduV1UnsignedData.age must be of type integer.";
return 0;
}
out->age = JsonValueAsInteger(val);
}
return 1;
}
HashMap *
PduV1UnsignedDataToJson(PduV1UnsignedData *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
HashMapSet(json, "age", JsonValueInteger(val->age));
return json;
}
void
PduV1UnsignedDataFree(PduV1UnsignedData *val)
{
if (!val)
{
return;
}
}

500
src/Schema/PduV3.c Normal file
View file

@ -0,0 +1,500 @@
/* Generated by j2s */
#include <Schema/PduV3.h>
#include <Memory.h>
#include <Json.h>
#include <Str.h>
int
PduV3EventHashFromJson(HashMap *json, PduV3EventHash *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to PduV3EventHashFromJson()";
return 0;
}
val = HashMapGet(json, "sha256");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV3EventHash.sha256 must be of type string.";
return 0;
}
out->sha256 = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "PduV3EventHash.sha256 is required.";
return 0;
}
return 1;
}
HashMap *
PduV3EventHashToJson(PduV3EventHash *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
HashMapSet(json, "sha256", JsonValueString(val->sha256));
return json;
}
void
PduV3EventHashFree(PduV3EventHash *val)
{
if (!val)
{
return;
}
Free(val->sha256);
}
int
PduV3FromJson(HashMap *json, PduV3 *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to PduV3FromJson()";
return 0;
}
val = HashMapGet(json, "origin_server_ts");
if (val)
{
if (JsonValueType(val) != JSON_INTEGER)
{
*errp = "PduV3.origin_server_ts must be of type integer.";
return 0;
}
out->origin_server_ts = JsonValueAsInteger(val);
}
else
{
*errp = "PduV3.origin_server_ts is required.";
return 0;
}
val = HashMapGet(json, "content");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "PduV3.content must be of type object.";
return 0;
}
out->content = JsonValueAsObject(JsonValueDuplicate(val));
}
else
{
*errp = "PduV3.content is required.";
return 0;
}
val = HashMapGet(json, "redacts");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV3.redacts must be of type string.";
return 0;
}
out->redacts = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "sender");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV3.sender must be of type string.";
return 0;
}
out->sender = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "PduV3.sender is required.";
return 0;
}
val = HashMapGet(json, "depth");
if (val)
{
if (JsonValueType(val) != JSON_INTEGER)
{
*errp = "PduV3.depth must be of type integer.";
return 0;
}
out->depth = JsonValueAsInteger(val);
}
else
{
*errp = "PduV3.depth is required.";
return 0;
}
val = HashMapGet(json, "prev_events");
if (val)
{
if (JsonValueType(val) != JSON_ARRAY)
{
*errp = "PduV3.prev_events must be of type [string].";
return 0;
}
out->prev_events = ArrayCreate();
if (!out->prev_events)
{
*errp = "Failed to allocate memory for PduV3.prev_events.";
return 0;
}
else
{
Array *arr = JsonValueAsArray(val);
size_t i;
for (i = 0; i <ArraySize(arr); i++)
{
JsonValue *v = ArrayGet(arr, i);
if (JsonValueType(v) != JSON_STRING)
{
*errp = "PduV3.prev_events[] contains an invalid value.";
return 0;
}
ArrayAdd(out->prev_events, StrDuplicate(JsonValueAsString(v)));
}
}
}
else
{
*errp = "PduV3.prev_events is required.";
return 0;
}
val = HashMapGet(json, "type");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV3.type must be of type string.";
return 0;
}
out->type = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "PduV3.type is required.";
return 0;
}
val = HashMapGet(json, "unsigned");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "PduV3.unsigned must be of type PduV3UnsignedData.";
return 0;
}
if (!PduV3UnsignedDataFromJson(JsonValueAsObject(val), &out->_unsigned, errp))
{
return 0;
}
}
val = HashMapGet(json, "auth_events");
if (val)
{
if (JsonValueType(val) != JSON_ARRAY)
{
*errp = "PduV3.auth_events must be of type [string].";
return 0;
}
out->auth_events = ArrayCreate();
if (!out->auth_events)
{
*errp = "Failed to allocate memory for PduV3.auth_events.";
return 0;
}
else
{
Array *arr = JsonValueAsArray(val);
size_t i;
for (i = 0; i <ArraySize(arr); i++)
{
JsonValue *v = ArrayGet(arr, i);
if (JsonValueType(v) != JSON_STRING)
{
*errp = "PduV3.auth_events[] contains an invalid value.";
return 0;
}
ArrayAdd(out->auth_events, StrDuplicate(JsonValueAsString(v)));
}
}
}
else
{
*errp = "PduV3.auth_events is required.";
return 0;
}
val = HashMapGet(json, "room_id");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV3.room_id must be of type string.";
return 0;
}
out->room_id = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "PduV3.room_id is required.";
return 0;
}
val = HashMapGet(json, "state_key");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "PduV3.state_key must be of type string.";
return 0;
}
out->state_key = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "signatures");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "PduV3.signatures must be of type object.";
return 0;
}
out->signatures = JsonValueAsObject(JsonValueDuplicate(val));
}
else
{
*errp = "PduV3.signatures is required.";
return 0;
}
val = HashMapGet(json, "hashes");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "PduV3.hashes must be of type PduV3EventHash.";
return 0;
}
if (!PduV3EventHashFromJson(JsonValueAsObject(val), &out->hashes, errp))
{
return 0;
}
}
else
{
*errp = "PduV3.hashes is required.";
return 0;
}
return 1;
}
HashMap *
PduV3ToJson(PduV3 *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
HashMapSet(json, "origin_server_ts", JsonValueInteger(val->origin_server_ts));
HashMapSet(json, "content", JsonValueObject(JsonDuplicate(val->content)));
HashMapSet(json, "redacts", JsonValueString(val->redacts));
HashMapSet(json, "sender", JsonValueString(val->sender));
HashMapSet(json, "depth", JsonValueInteger(val->depth));
if (val->prev_events)
{
size_t i;
Array *jsonArr = ArrayCreate();
if (!jsonArr)
{
JsonFree(json);
return NULL;
}
for (i = 0; i < ArraySize(val->prev_events); i++)
{
ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->prev_events, i)));
}
HashMapSet(json, "prev_events", JsonValueArray(jsonArr));
}
HashMapSet(json, "type", JsonValueString(val->type));
HashMapSet(json, "unsigned", JsonValueObject(PduV3UnsignedDataToJson(&val->_unsigned)));
if (val->auth_events)
{
size_t i;
Array *jsonArr = ArrayCreate();
if (!jsonArr)
{
JsonFree(json);
return NULL;
}
for (i = 0; i < ArraySize(val->auth_events); i++)
{
ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->auth_events, i)));
}
HashMapSet(json, "auth_events", JsonValueArray(jsonArr));
}
HashMapSet(json, "room_id", JsonValueString(val->room_id));
HashMapSet(json, "state_key", JsonValueString(val->state_key));
HashMapSet(json, "signatures", JsonValueObject(JsonDuplicate(val->signatures)));
HashMapSet(json, "hashes", JsonValueObject(PduV3EventHashToJson(&val->hashes)));
return json;
}
void
PduV3Free(PduV3 *val)
{
if (!val)
{
return;
}
JsonFree(val->content);
Free(val->redacts);
Free(val->sender);
if (val->prev_events)
{
size_t i;
for (i = 0; i < ArraySize(val->prev_events); i++)
{
Free(ArrayGet(val->prev_events, i));
}
ArrayFree(val->prev_events);
}
Free(val->type);
PduV3UnsignedDataFree(&val->_unsigned);
if (val->auth_events)
{
size_t i;
for (i = 0; i < ArraySize(val->auth_events); i++)
{
Free(ArrayGet(val->auth_events, i));
}
ArrayFree(val->auth_events);
}
Free(val->room_id);
Free(val->state_key);
JsonFree(val->signatures);
PduV3EventHashFree(&val->hashes);
}
int
PduV3UnsignedDataFromJson(HashMap *json, PduV3UnsignedData *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to PduV3UnsignedDataFromJson()";
return 0;
}
val = HashMapGet(json, "age");
if (val)
{
if (JsonValueType(val) != JSON_INTEGER)
{
*errp = "PduV3UnsignedData.age must be of type integer.";
return 0;
}
out->age = JsonValueAsInteger(val);
}
return 1;
}
HashMap *
PduV3UnsignedDataToJson(PduV3UnsignedData *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
HashMapSet(json, "age", JsonValueInteger(val->age));
return json;
}
void
PduV3UnsignedDataFree(PduV3UnsignedData *val)
{
if (!val)
{
return;
}
}

View file

@ -0,0 +1,712 @@
/* Generated by j2s */
#include <Schema/RoomCreateRequest.h>
#include <Memory.h>
#include <Json.h>
#include <Str.h>
int
RoomVisibilityFromStr(char *str)
{
if (StrEquals(str, "public"))
{
return ROOM_PUBLIC;
}
else if (StrEquals(str, "private"))
{
return ROOM_PRIVATE;
}
else
{
return -1;
}
}
char *
RoomVisibilityToStr(RoomVisibility val)
{
switch (val)
{
case ROOM_PUBLIC:
return "public";
case ROOM_PRIVATE:
return "private";
default:
return NULL;
}
}
int
RoomCreateRequestFromJson(HashMap *json, RoomCreateRequest *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to RoomCreateRequestFromJson()";
return 0;
}
val = HashMapGet(json, "invite");
if (val)
{
if (JsonValueType(val) != JSON_ARRAY)
{
*errp = "RoomCreateRequest.invite must be of type [string].";
return 0;
}
out->invite = ArrayCreate();
if (!out->invite)
{
*errp = "Failed to allocate memory for RoomCreateRequest.invite.";
return 0;
}
else
{
Array *arr = JsonValueAsArray(val);
size_t i;
for (i = 0; i <ArraySize(arr); i++)
{
JsonValue *v = ArrayGet(arr, i);
if (JsonValueType(v) != JSON_STRING)
{
*errp = "RoomCreateRequest.invite[] contains an invalid value.";
return 0;
}
ArrayAdd(out->invite, StrDuplicate(JsonValueAsString(v)));
}
}
}
val = HashMapGet(json, "room_version");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomCreateRequest.room_version must be of type string.";
return 0;
}
out->room_version = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "invite_3pid");
if (val)
{
if (JsonValueType(val) != JSON_ARRAY)
{
*errp = "RoomCreateRequest.invite_3pid must be of type [RoomInvite3Pid].";
return 0;
}
out->invite_3pid = ArrayCreate();
if (!out->invite_3pid)
{
*errp = "Failed to allocate memory for RoomCreateRequest.invite_3pid.";
return 0;
}
else
{
Array *arr = JsonValueAsArray(val);
size_t i;
for (i = 0; i <ArraySize(arr); i++)
{
JsonValue *v = ArrayGet(arr, i);
RoomInvite3Pid *parsed;
if (JsonValueType(v) != JSON_OBJECT)
{
*errp = "RoomCreateRequest.invite_3pid[] contains an invalid value.";
return 0;
}
parsed = Malloc(sizeof(RoomInvite3Pid));
if (!parsed)
{
*errp = "Unable to allocate memory for array value.";
return 0;
}
if (!RoomInvite3PidFromJson(JsonValueAsObject(v), parsed, errp))
{
RoomInvite3PidFree(parsed);
Free(parsed);
return 0;
}
ArrayAdd(out->invite_3pid, parsed);
}
}
}
val = HashMapGet(json, "topic");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomCreateRequest.topic must be of type string.";
return 0;
}
out->topic = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "visibility");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomCreateRequest.visibility must be of type RoomVisibility.";
return 0;
}
enumParseRes = RoomVisibilityFromStr(JsonValueAsString(val));
if (enumParseRes == -1)
{
*errp = "Invalid value for RoomCreateRequest.visibility.";
return 0;
}
out->visibility = enumParseRes;
}
val = HashMapGet(json, "creation_content");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "RoomCreateRequest.creation_content must be of type object.";
return 0;
}
out->creation_content = JsonValueAsObject(JsonValueDuplicate(val));
}
val = HashMapGet(json, "is_direct");
if (val)
{
if (JsonValueType(val) != JSON_BOOLEAN)
{
*errp = "RoomCreateRequest.is_direct must be of type boolean.";
return 0;
}
out->is_direct = JsonValueAsBoolean(val);
}
val = HashMapGet(json, "name");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomCreateRequest.name must be of type string.";
return 0;
}
out->name = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "initial_state");
if (val)
{
if (JsonValueType(val) != JSON_ARRAY)
{
*errp = "RoomCreateRequest.initial_state must be of type [RoomStateEvent].";
return 0;
}
out->initial_state = ArrayCreate();
if (!out->initial_state)
{
*errp = "Failed to allocate memory for RoomCreateRequest.initial_state.";
return 0;
}
else
{
Array *arr = JsonValueAsArray(val);
size_t i;
for (i = 0; i <ArraySize(arr); i++)
{
JsonValue *v = ArrayGet(arr, i);
RoomStateEvent *parsed;
if (JsonValueType(v) != JSON_OBJECT)
{
*errp = "RoomCreateRequest.initial_state[] contains an invalid value.";
return 0;
}
parsed = Malloc(sizeof(RoomStateEvent));
if (!parsed)
{
*errp = "Unable to allocate memory for array value.";
return 0;
}
if (!RoomStateEventFromJson(JsonValueAsObject(v), parsed, errp))
{
RoomStateEventFree(parsed);
Free(parsed);
return 0;
}
ArrayAdd(out->initial_state, parsed);
}
}
}
val = HashMapGet(json, "power_level_content_override");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "RoomCreateRequest.power_level_content_override must be of type object.";
return 0;
}
out->power_level_content_override = JsonValueAsObject(JsonValueDuplicate(val));
}
val = HashMapGet(json, "room_alias_name");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomCreateRequest.room_alias_name must be of type string.";
return 0;
}
out->room_alias_name = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "preset");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomCreateRequest.preset must be of type RoomCreatePreset.";
return 0;
}
enumParseRes = RoomCreatePresetFromStr(JsonValueAsString(val));
if (enumParseRes == -1)
{
*errp = "Invalid value for RoomCreateRequest.preset.";
return 0;
}
out->preset = enumParseRes;
}
return 1;
}
HashMap *
RoomCreateRequestToJson(RoomCreateRequest *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
if (val->invite)
{
size_t i;
Array *jsonArr = ArrayCreate();
if (!jsonArr)
{
JsonFree(json);
return NULL;
}
for (i = 0; i < ArraySize(val->invite); i++)
{
ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->invite, i)));
}
HashMapSet(json, "invite", JsonValueArray(jsonArr));
}
HashMapSet(json, "room_version", JsonValueString(val->room_version));
if (val->invite_3pid)
{
size_t i;
Array *jsonArr = ArrayCreate();
if (!jsonArr)
{
JsonFree(json);
return NULL;
}
for (i = 0; i < ArraySize(val->invite_3pid); i++)
{
ArrayAdd(jsonArr, JsonValueObject(RoomInvite3PidToJson(ArrayGet(val->invite_3pid, i))));
}
HashMapSet(json, "invite_3pid", JsonValueArray(jsonArr));
}
HashMapSet(json, "topic", JsonValueString(val->topic));
HashMapSet(json, "visibility", JsonValueString(RoomVisibilityToStr(val->visibility)));
HashMapSet(json, "creation_content", JsonValueObject(JsonDuplicate(val->creation_content)));
HashMapSet(json, "is_direct", JsonValueBoolean(val->is_direct));
HashMapSet(json, "name", JsonValueString(val->name));
if (val->initial_state)
{
size_t i;
Array *jsonArr = ArrayCreate();
if (!jsonArr)
{
JsonFree(json);
return NULL;
}
for (i = 0; i < ArraySize(val->initial_state); i++)
{
ArrayAdd(jsonArr, JsonValueObject(RoomStateEventToJson(ArrayGet(val->initial_state, i))));
}
HashMapSet(json, "initial_state", JsonValueArray(jsonArr));
}
HashMapSet(json, "power_level_content_override", JsonValueObject(JsonDuplicate(val->power_level_content_override)));
HashMapSet(json, "room_alias_name", JsonValueString(val->room_alias_name));
HashMapSet(json, "preset", JsonValueString(RoomCreatePresetToStr(val->preset)));
return json;
}
void
RoomCreateRequestFree(RoomCreateRequest *val)
{
if (!val)
{
return;
}
if (val->invite)
{
size_t i;
for (i = 0; i < ArraySize(val->invite); i++)
{
Free(ArrayGet(val->invite, i));
}
ArrayFree(val->invite);
}
Free(val->room_version);
if (val->invite_3pid)
{
size_t i;
for (i = 0; i < ArraySize(val->invite_3pid); i++)
{
RoomInvite3PidFree(ArrayGet(val->invite_3pid, i));
Free(ArrayGet(val->invite_3pid, i));
}
ArrayFree(val->invite_3pid);
}
Free(val->topic);
JsonFree(val->creation_content);
Free(val->name);
if (val->initial_state)
{
size_t i;
for (i = 0; i < ArraySize(val->initial_state); i++)
{
RoomStateEventFree(ArrayGet(val->initial_state, i));
Free(ArrayGet(val->initial_state, i));
}
ArrayFree(val->initial_state);
}
JsonFree(val->power_level_content_override);
Free(val->room_alias_name);
}
int
RoomInvite3PidFromJson(HashMap *json, RoomInvite3Pid *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to RoomInvite3PidFromJson()";
return 0;
}
val = HashMapGet(json, "id_access_token");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomInvite3Pid.id_access_token must be of type string.";
return 0;
}
out->id_access_token = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "RoomInvite3Pid.id_access_token is required.";
return 0;
}
val = HashMapGet(json, "address");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomInvite3Pid.address must be of type string.";
return 0;
}
out->address = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "RoomInvite3Pid.address is required.";
return 0;
}
val = HashMapGet(json, "medium");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomInvite3Pid.medium must be of type Room3PidMedium.";
return 0;
}
enumParseRes = Room3PidMediumFromStr(JsonValueAsString(val));
if (enumParseRes == -1)
{
*errp = "Invalid value for RoomInvite3Pid.medium.";
return 0;
}
out->medium = enumParseRes;
}
else
{
*errp = "RoomInvite3Pid.medium is required.";
return 0;
}
val = HashMapGet(json, "id_server");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomInvite3Pid.id_server must be of type string.";
return 0;
}
out->id_server = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "RoomInvite3Pid.id_server is required.";
return 0;
}
return 1;
}
HashMap *
RoomInvite3PidToJson(RoomInvite3Pid *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
HashMapSet(json, "id_access_token", JsonValueString(val->id_access_token));
HashMapSet(json, "address", JsonValueString(val->address));
HashMapSet(json, "medium", JsonValueString(Room3PidMediumToStr(val->medium)));
HashMapSet(json, "id_server", JsonValueString(val->id_server));
return json;
}
void
RoomInvite3PidFree(RoomInvite3Pid *val)
{
if (!val)
{
return;
}
Free(val->id_access_token);
Free(val->address);
Free(val->id_server);
}
int
Room3PidMediumFromStr(char *str)
{
if (StrEquals(str, "msisdn"))
{
return ROOM_3PID_MSISDN;
}
else if (StrEquals(str, "email"))
{
return ROOM_3PID_EMAIL;
}
else
{
return -1;
}
}
char *
Room3PidMediumToStr(Room3PidMedium val)
{
switch (val)
{
case ROOM_3PID_MSISDN:
return "msisdn";
case ROOM_3PID_EMAIL:
return "email";
default:
return NULL;
}
}
int
RoomCreatePresetFromStr(char *str)
{
if (StrEquals(str, "public_chat"))
{
return ROOM_CREATE_PUBLIC;
}
else if (StrEquals(str, "trusted_private_chat"))
{
return ROOM_CREATE_TRUSTED;
}
else if (StrEquals(str, "private_chat"))
{
return ROOM_CREATE_PRIVATE;
}
else
{
return -1;
}
}
char *
RoomCreatePresetToStr(RoomCreatePreset val)
{
switch (val)
{
case ROOM_CREATE_PUBLIC:
return "public_chat";
case ROOM_CREATE_TRUSTED:
return "trusted_private_chat";
case ROOM_CREATE_PRIVATE:
return "private_chat";
default:
return NULL;
}
}
int
RoomStateEventFromJson(HashMap *json, RoomStateEvent *out, char **errp)
{
JsonValue *val;
int enumParseRes;
(void) enumParseRes;
if (!json | !out)
{
*errp = "Invalid pointers passed to RoomStateEventFromJson()";
return 0;
}
val = HashMapGet(json, "content");
if (val)
{
if (JsonValueType(val) != JSON_OBJECT)
{
*errp = "RoomStateEvent.content must be of type object.";
return 0;
}
out->content = JsonValueAsObject(JsonValueDuplicate(val));
}
else
{
*errp = "RoomStateEvent.content is required.";
return 0;
}
val = HashMapGet(json, "state_key");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomStateEvent.state_key must be of type string.";
return 0;
}
out->state_key = StrDuplicate(JsonValueAsString(val));
}
val = HashMapGet(json, "type");
if (val)
{
if (JsonValueType(val) != JSON_STRING)
{
*errp = "RoomStateEvent.type must be of type string.";
return 0;
}
out->type = StrDuplicate(JsonValueAsString(val));
}
else
{
*errp = "RoomStateEvent.type is required.";
return 0;
}
return 1;
}
HashMap *
RoomStateEventToJson(RoomStateEvent *val)
{
HashMap *json;
if (!val)
{
return NULL;
}
json = HashMapCreate();
if (!json)
{
return NULL;
}
HashMapSet(json, "content", JsonValueObject(JsonDuplicate(val->content)));
HashMapSet(json, "state_key", JsonValueString(val->state_key));
HashMapSet(json, "type", JsonValueString(val->type));
return json;
}
void
RoomStateEventFree(RoomStateEvent *val)
{
if (!val)
{
return;
}
JsonFree(val->content);
Free(val->state_key);
Free(val->type);
}

View file

@ -85,6 +85,7 @@ ROUTE(RouteChangePwd);
ROUTE(RouteDeactivate);
ROUTE(RouteTokenValid);
ROUTE(RouteUserProfile);
ROUTE(RouteUserDirectory);
ROUTE(RouteRequestToken);
ROUTE(RouteUiaFallback);

View file

@ -0,0 +1,39 @@
/* Generated by j2s */
#ifndef TELODENDRIA_SCHEMA_CLIENTEVENT_H
#define TELODENDRIA_SCHEMA_CLIENTEVENT_H
#include <Array.h>
#include <HashMap.h>
#include <Int64.h>
typedef struct ClientEventUnsignedData
{
HashMap * redacted_because;
char * transaction_id;
HashMap * prev_content;
Int64 age;
} ClientEventUnsignedData;
typedef struct ClientEvent
{
Int64 origin_server_ts;
HashMap * content;
char * room_id;
char * sender;
char * state_key;
char * event_id;
char * type;
ClientEventUnsignedData _unsigned;
} ClientEvent;
extern int ClientEventUnsignedDataFromJson(HashMap *, ClientEventUnsignedData *, char **);
extern HashMap * ClientEventUnsignedDataToJson(ClientEventUnsignedData *);
extern void ClientEventUnsignedDataFree(ClientEventUnsignedData *);
extern int ClientEventFromJson(HashMap *, ClientEvent *, char **);
extern HashMap * ClientEventToJson(ClientEvent *);
extern void ClientEventFree(ClientEvent *);
#endif /* TELODENDRIA_SCHEMA_CLIENTEVENT_H */

View file

@ -0,0 +1,80 @@
/* Generated by j2s */
#ifndef TELODENDRIA_SCHEMA_FILTER_H
#define TELODENDRIA_SCHEMA_FILTER_H
#include <Array.h>
#include <HashMap.h>
#include <Int64.h>
typedef struct FilterEvent
{
Array * not_senders;
Int64 limit;
Array * senders;
Array * types;
Array * not_types;
} FilterEvent;
typedef enum FilterEventFormat
{
FILTER_FORMAT_FEDERATION,
FILTER_FORMANT_CLIENT
} FilterEventFormat;
typedef struct FilterRoomEvent
{
Array * not_rooms;
Array * not_senders;
Int64 limit;
Array * senders;
int include_redundant_members;
Array * types;
Array * rooms;
int lazy_load_members;
Array * not_types;
int contains_url;
int unread_thread_notifications;
} FilterRoomEvent;
typedef struct FilterRoom
{
Array * not_rooms;
FilterRoomEvent state;
int include_leave;
FilterRoomEvent timeline;
FilterRoomEvent account_data;
Array * rooms;
FilterRoomEvent ephemeral;
} FilterRoom;
typedef struct Filter
{
FilterEventFormat event_format;
FilterEvent presence;
FilterEvent account_data;
FilterRoom room;
Array * event_fields;
} Filter;
extern int FilterRoomFromJson(HashMap *, FilterRoom *, char **);
extern HashMap * FilterRoomToJson(FilterRoom *);
extern void FilterRoomFree(FilterRoom *);
extern int FilterEventFormatFromStr(char *);
extern char * FilterEventFormatToStr(FilterEventFormat);
extern int FilterEventFromJson(HashMap *, FilterEvent *, char **);
extern HashMap * FilterEventToJson(FilterEvent *);
extern void FilterEventFree(FilterEvent *);
extern int FilterFromJson(HashMap *, Filter *, char **);
extern HashMap * FilterToJson(Filter *);
extern void FilterFree(Filter *);
extern int FilterRoomEventFromJson(HashMap *, FilterRoomEvent *, char **);
extern HashMap * FilterRoomEventToJson(FilterRoomEvent *);
extern void FilterRoomEventFree(FilterRoomEvent *);
#endif /* TELODENDRIA_SCHEMA_FILTER_H */

View file

@ -0,0 +1,51 @@
/* Generated by j2s */
#ifndef TELODENDRIA_SCHEMA_PDUV1_H
#define TELODENDRIA_SCHEMA_PDUV1_H
#include <Array.h>
#include <HashMap.h>
#include <Int64.h>
typedef struct PduV1UnsignedData
{
Int64 age;
} PduV1UnsignedData;
typedef struct PduV1EventHash
{
char * sha256;
} PduV1EventHash;
typedef struct PduV1
{
Int64 origin_server_ts;
HashMap * content;
char * redacts;
char * sender;
Int64 depth;
Array * prev_events;
char * type;
PduV1UnsignedData _unsigned;
Array * auth_events;
char * room_id;
char * state_key;
HashMap * signatures;
char * event_id;
PduV1EventHash hashes;
} PduV1;
extern int PduV1EventHashFromJson(HashMap *, PduV1EventHash *, char **);
extern HashMap * PduV1EventHashToJson(PduV1EventHash *);
extern void PduV1EventHashFree(PduV1EventHash *);
extern int PduV1FromJson(HashMap *, PduV1 *, char **);
extern HashMap * PduV1ToJson(PduV1 *);
extern void PduV1Free(PduV1 *);
extern int PduV1UnsignedDataFromJson(HashMap *, PduV1UnsignedData *, char **);
extern HashMap * PduV1UnsignedDataToJson(PduV1UnsignedData *);
extern void PduV1UnsignedDataFree(PduV1UnsignedData *);
#endif /* TELODENDRIA_SCHEMA_PDUV1_H */

View file

@ -0,0 +1,50 @@
/* Generated by j2s */
#ifndef TELODENDRIA_SCHEMA_PDUV3_H
#define TELODENDRIA_SCHEMA_PDUV3_H
#include <Array.h>
#include <HashMap.h>
#include <Int64.h>
typedef struct PduV3UnsignedData
{
Int64 age;
} PduV3UnsignedData;
typedef struct PduV3EventHash
{
char * sha256;
} PduV3EventHash;
typedef struct PduV3
{
Int64 origin_server_ts;
HashMap * content;
char * redacts;
char * sender;
Int64 depth;
Array * prev_events;
char * type;
PduV3UnsignedData _unsigned;
Array * auth_events;
char * room_id;
char * state_key;
HashMap * signatures;
PduV3EventHash hashes;
} PduV3;
extern int PduV3EventHashFromJson(HashMap *, PduV3EventHash *, char **);
extern HashMap * PduV3EventHashToJson(PduV3EventHash *);
extern void PduV3EventHashFree(PduV3EventHash *);
extern int PduV3FromJson(HashMap *, PduV3 *, char **);
extern HashMap * PduV3ToJson(PduV3 *);
extern void PduV3Free(PduV3 *);
extern int PduV3UnsignedDataFromJson(HashMap *, PduV3UnsignedData *, char **);
extern HashMap * PduV3UnsignedDataToJson(PduV3UnsignedData *);
extern void PduV3UnsignedDataFree(PduV3UnsignedData *);
#endif /* TELODENDRIA_SCHEMA_PDUV3_H */

View file

@ -0,0 +1,82 @@
/* Generated by j2s */
#ifndef TELODENDRIA_SCHEMA_ROOMCREATE_H
#define TELODENDRIA_SCHEMA_ROOMCREATE_H
#include <Array.h>
#include <HashMap.h>
#include <Int64.h>
typedef enum Room3PidMedium
{
ROOM_3PID_MSISDN,
ROOM_3PID_EMAIL
} Room3PidMedium;
typedef enum RoomCreatePreset
{
ROOM_CREATE_PUBLIC,
ROOM_CREATE_TRUSTED,
ROOM_CREATE_PRIVATE
} RoomCreatePreset;
typedef struct RoomStateEvent
{
HashMap * content;
char * state_key;
char * type;
} RoomStateEvent;
typedef struct RoomInvite3Pid
{
char * id_access_token;
char * address;
Room3PidMedium medium;
char * id_server;
} RoomInvite3Pid;
typedef enum RoomVisibility
{
ROOM_PUBLIC,
ROOM_PRIVATE
} RoomVisibility;
typedef struct RoomCreateRequest
{
Array * invite;
char * room_version;
Array * invite_3pid;
char * topic;
RoomVisibility visibility;
HashMap * creation_content;
int is_direct;
char * name;
Array * initial_state;
HashMap * power_level_content_override;
char * room_alias_name;
RoomCreatePreset preset;
} RoomCreateRequest;
extern int RoomVisibilityFromStr(char *);
extern char * RoomVisibilityToStr(RoomVisibility);
extern int RoomCreateRequestFromJson(HashMap *, RoomCreateRequest *, char **);
extern HashMap * RoomCreateRequestToJson(RoomCreateRequest *);
extern void RoomCreateRequestFree(RoomCreateRequest *);
extern int RoomInvite3PidFromJson(HashMap *, RoomInvite3Pid *, char **);
extern HashMap * RoomInvite3PidToJson(RoomInvite3Pid *);
extern void RoomInvite3PidFree(RoomInvite3Pid *);
extern int Room3PidMediumFromStr(char *);
extern char * Room3PidMediumToStr(Room3PidMedium);
extern int RoomCreatePresetFromStr(char *);
extern char * RoomCreatePresetToStr(RoomCreatePreset);
extern int RoomStateEventFromJson(HashMap *, RoomStateEvent *, char **);
extern HashMap * RoomStateEventToJson(RoomStateEvent *);
extern void RoomStateEventFree(RoomStateEvent *);
#endif /* TELODENDRIA_SCHEMA_ROOMCREATE_H */