forked from Telodendria/Telodendria
[FIX] Remove generated Schema files.
Oops, how did I *not* catch this?
This commit is contained in:
parent
a3eb5b8aa2
commit
e4952a8f33
5 changed files with 0 additions and 3181 deletions
|
@ -1,299 +0,0 @@
|
|||
/* 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
1193
src/Schema/Filter.c
File diff suppressed because it is too large
Load diff
|
@ -1,477 +0,0 @@
|
|||
/* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,500 +0,0 @@
|
|||
/* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,712 +0,0 @@
|
|||
/* 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);
|
||||
}
|
||||
|
Loading…
Reference in a new issue