From b9263c4819670708345d29ecbc9c90ff2334aab8 Mon Sep 17 00:00:00 2001 From: LoaD Accumulator Date: Wed, 6 Sep 2023 07:42:17 +0200 Subject: [PATCH] [FIX] Remove generated Schema files. Oops, how did I *not* catch this? --- .gitignore | 1 + src/Schema/ClientEvent.c | 299 -------- src/Schema/Filter.c | 1193 -------------------------------- src/Schema/PduV1.c | 477 ------------- src/Schema/PduV3.c | 500 ------------- src/Schema/RoomCreateRequest.c | 712 ------------------- 6 files changed, 1 insertion(+), 3181 deletions(-) delete mode 100644 src/Schema/ClientEvent.c delete mode 100644 src/Schema/Filter.c delete mode 100644 src/Schema/PduV1.c delete mode 100644 src/Schema/PduV3.c delete mode 100644 src/Schema/RoomCreateRequest.c diff --git a/.gitignore b/.gitignore index d325fae..d1f63a6 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,6 @@ man/mandoc.db ======= # Telodendria .gitignore build/* +src/Schema/* Cytoplasm/build/* >>>>>>> b099a3e ([ADD] WIP: User directory from #70 + .gitignore.) diff --git a/src/Schema/ClientEvent.c b/src/Schema/ClientEvent.c deleted file mode 100644 index f6295af..0000000 --- a/src/Schema/ClientEvent.c +++ /dev/null @@ -1,299 +0,0 @@ -/* Generated by j2s */ - -#include - -#include -#include -#include - -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); -} - diff --git a/src/Schema/Filter.c b/src/Schema/Filter.c deleted file mode 100644 index d6db515..0000000 --- a/src/Schema/Filter.c +++ /dev/null @@ -1,1193 +0,0 @@ -/* Generated by j2s */ - -#include - -#include -#include -#include - -int -FilterRoomFromJson(HashMap *json, FilterRoom *out, char **errp) -{ - JsonValue *val; - int enumParseRes; - - (void) enumParseRes; - - if (!json | !out) - { - *errp = "Invalid pointers passed to FilterRoomFromJson()"; - return 0; - } - - val = HashMapGet(json, "not_rooms"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterRoom.not_rooms must be of type [string]."; - return 0; - } - - out->not_rooms = ArrayCreate(); - if (!out->not_rooms) - { - *errp = "Failed to allocate memory for FilterRoom.not_rooms."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i not_rooms, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "state"); - if (val) - { - if (JsonValueType(val) != JSON_OBJECT) - { - *errp = "FilterRoom.state must be of type FilterRoomEvent."; - return 0; - } - - if (!FilterRoomEventFromJson(JsonValueAsObject(val), &out->state, errp)) - { - return 0; - } - } - - val = HashMapGet(json, "include_leave"); - if (val) - { - if (JsonValueType(val) != JSON_BOOLEAN) - { - *errp = "FilterRoom.include_leave must be of type boolean."; - return 0; - } - - out->include_leave = JsonValueAsBoolean(val); - } - - val = HashMapGet(json, "timeline"); - if (val) - { - if (JsonValueType(val) != JSON_OBJECT) - { - *errp = "FilterRoom.timeline must be of type FilterRoomEvent."; - return 0; - } - - if (!FilterRoomEventFromJson(JsonValueAsObject(val), &out->timeline, errp)) - { - return 0; - } - } - - val = HashMapGet(json, "account_data"); - if (val) - { - if (JsonValueType(val) != JSON_OBJECT) - { - *errp = "FilterRoom.account_data must be of type FilterRoomEvent."; - return 0; - } - - if (!FilterRoomEventFromJson(JsonValueAsObject(val), &out->account_data, errp)) - { - return 0; - } - } - - val = HashMapGet(json, "rooms"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterRoom.rooms must be of type [string]."; - return 0; - } - - out->rooms = ArrayCreate(); - if (!out->rooms) - { - *errp = "Failed to allocate memory for FilterRoom.rooms."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i rooms, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "ephemeral"); - if (val) - { - if (JsonValueType(val) != JSON_OBJECT) - { - *errp = "FilterRoom.ephemeral must be of type FilterRoomEvent."; - return 0; - } - - if (!FilterRoomEventFromJson(JsonValueAsObject(val), &out->ephemeral, errp)) - { - return 0; - } - } - - return 1; -} - -HashMap * -FilterRoomToJson(FilterRoom *val) -{ - HashMap *json; - - if (!val) - { - return NULL; - } - - json = HashMapCreate(); - if (!json) - { - return NULL; - } - - if (val->not_rooms) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->not_rooms); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->not_rooms, i))); - } - HashMapSet(json, "not_rooms", JsonValueArray(jsonArr)); - } - HashMapSet(json, "state", JsonValueObject(FilterRoomEventToJson(&val->state))); - HashMapSet(json, "include_leave", JsonValueBoolean(val->include_leave)); - HashMapSet(json, "timeline", JsonValueObject(FilterRoomEventToJson(&val->timeline))); - HashMapSet(json, "account_data", JsonValueObject(FilterRoomEventToJson(&val->account_data))); - if (val->rooms) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->rooms); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->rooms, i))); - } - HashMapSet(json, "rooms", JsonValueArray(jsonArr)); - } - HashMapSet(json, "ephemeral", JsonValueObject(FilterRoomEventToJson(&val->ephemeral))); - return json; -} - -void -FilterRoomFree(FilterRoom *val) -{ - if (!val) - { - return; - } - - if (val->not_rooms) - { - size_t i; - for (i = 0; i < ArraySize(val->not_rooms); i++) - { - Free(ArrayGet(val->not_rooms, i)); - } - ArrayFree(val->not_rooms); - } - FilterRoomEventFree(&val->state); - FilterRoomEventFree(&val->timeline); - FilterRoomEventFree(&val->account_data); - if (val->rooms) - { - size_t i; - for (i = 0; i < ArraySize(val->rooms); i++) - { - Free(ArrayGet(val->rooms, i)); - } - ArrayFree(val->rooms); - } - FilterRoomEventFree(&val->ephemeral); -} - -int -FilterEventFormatFromStr(char *str) -{ - if (StrEquals(str, "federation")) - { - return FILTER_FORMAT_FEDERATION; - } - else if (StrEquals(str, "client")) - { - return FILTER_FORMANT_CLIENT; - } - else - { - return -1; - } -} - -char * -FilterEventFormatToStr(FilterEventFormat val) -{ - switch (val) - { - case FILTER_FORMAT_FEDERATION: - return "federation"; - case FILTER_FORMANT_CLIENT: - return "client"; - default: - return NULL; - } -} - -int -FilterEventFromJson(HashMap *json, FilterEvent *out, char **errp) -{ - JsonValue *val; - int enumParseRes; - - (void) enumParseRes; - - if (!json | !out) - { - *errp = "Invalid pointers passed to FilterEventFromJson()"; - return 0; - } - - val = HashMapGet(json, "not_senders"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterEvent.not_senders must be of type [string]."; - return 0; - } - - out->not_senders = ArrayCreate(); - if (!out->not_senders) - { - *errp = "Failed to allocate memory for FilterEvent.not_senders."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i not_senders, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "limit"); - if (val) - { - if (JsonValueType(val) != JSON_INTEGER) - { - *errp = "FilterEvent.limit must be of type integer."; - return 0; - } - - out->limit = JsonValueAsInteger(val); - } - - val = HashMapGet(json, "senders"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterEvent.senders must be of type [string]."; - return 0; - } - - out->senders = ArrayCreate(); - if (!out->senders) - { - *errp = "Failed to allocate memory for FilterEvent.senders."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i senders, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "types"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterEvent.types must be of type [string]."; - return 0; - } - - out->types = ArrayCreate(); - if (!out->types) - { - *errp = "Failed to allocate memory for FilterEvent.types."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i types, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "not_types"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterEvent.not_types must be of type [string]."; - return 0; - } - - out->not_types = ArrayCreate(); - if (!out->not_types) - { - *errp = "Failed to allocate memory for FilterEvent.not_types."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i not_types, StrDuplicate(JsonValueAsString(v))); - } - } - } - - return 1; -} - -HashMap * -FilterEventToJson(FilterEvent *val) -{ - HashMap *json; - - if (!val) - { - return NULL; - } - - json = HashMapCreate(); - if (!json) - { - return NULL; - } - - if (val->not_senders) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->not_senders); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->not_senders, i))); - } - HashMapSet(json, "not_senders", JsonValueArray(jsonArr)); - } - HashMapSet(json, "limit", JsonValueInteger(val->limit)); - if (val->senders) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->senders); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->senders, i))); - } - HashMapSet(json, "senders", JsonValueArray(jsonArr)); - } - if (val->types) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->types); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->types, i))); - } - HashMapSet(json, "types", JsonValueArray(jsonArr)); - } - if (val->not_types) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->not_types); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->not_types, i))); - } - HashMapSet(json, "not_types", JsonValueArray(jsonArr)); - } - return json; -} - -void -FilterEventFree(FilterEvent *val) -{ - if (!val) - { - return; - } - - if (val->not_senders) - { - size_t i; - for (i = 0; i < ArraySize(val->not_senders); i++) - { - Free(ArrayGet(val->not_senders, i)); - } - ArrayFree(val->not_senders); - } - if (val->senders) - { - size_t i; - for (i = 0; i < ArraySize(val->senders); i++) - { - Free(ArrayGet(val->senders, i)); - } - ArrayFree(val->senders); - } - if (val->types) - { - size_t i; - for (i = 0; i < ArraySize(val->types); i++) - { - Free(ArrayGet(val->types, i)); - } - ArrayFree(val->types); - } - if (val->not_types) - { - size_t i; - for (i = 0; i < ArraySize(val->not_types); i++) - { - Free(ArrayGet(val->not_types, i)); - } - ArrayFree(val->not_types); - } -} - -int -FilterFromJson(HashMap *json, Filter *out, char **errp) -{ - JsonValue *val; - int enumParseRes; - - (void) enumParseRes; - - if (!json | !out) - { - *errp = "Invalid pointers passed to FilterFromJson()"; - return 0; - } - - val = HashMapGet(json, "event_format"); - if (val) - { - if (JsonValueType(val) != JSON_STRING) - { - *errp = "Filter.event_format must be of type FilterEventFormat."; - return 0; - } - - enumParseRes = FilterEventFormatFromStr(JsonValueAsString(val)); - if (enumParseRes == -1) - { - *errp = "Invalid value for Filter.event_format."; - return 0; - } - out->event_format = enumParseRes; - } - - val = HashMapGet(json, "presence"); - if (val) - { - if (JsonValueType(val) != JSON_OBJECT) - { - *errp = "Filter.presence must be of type FilterEvent."; - return 0; - } - - if (!FilterEventFromJson(JsonValueAsObject(val), &out->presence, errp)) - { - return 0; - } - } - - val = HashMapGet(json, "account_data"); - if (val) - { - if (JsonValueType(val) != JSON_OBJECT) - { - *errp = "Filter.account_data must be of type FilterEvent."; - return 0; - } - - if (!FilterEventFromJson(JsonValueAsObject(val), &out->account_data, errp)) - { - return 0; - } - } - - val = HashMapGet(json, "room"); - if (val) - { - if (JsonValueType(val) != JSON_OBJECT) - { - *errp = "Filter.room must be of type FilterRoom."; - return 0; - } - - if (!FilterRoomFromJson(JsonValueAsObject(val), &out->room, errp)) - { - return 0; - } - } - - val = HashMapGet(json, "event_fields"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "Filter.event_fields must be of type [string]."; - return 0; - } - - out->event_fields = ArrayCreate(); - if (!out->event_fields) - { - *errp = "Failed to allocate memory for Filter.event_fields."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i event_fields, StrDuplicate(JsonValueAsString(v))); - } - } - } - - return 1; -} - -HashMap * -FilterToJson(Filter *val) -{ - HashMap *json; - - if (!val) - { - return NULL; - } - - json = HashMapCreate(); - if (!json) - { - return NULL; - } - - HashMapSet(json, "event_format", JsonValueString(FilterEventFormatToStr(val->event_format))); - HashMapSet(json, "presence", JsonValueObject(FilterEventToJson(&val->presence))); - HashMapSet(json, "account_data", JsonValueObject(FilterEventToJson(&val->account_data))); - HashMapSet(json, "room", JsonValueObject(FilterRoomToJson(&val->room))); - if (val->event_fields) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->event_fields); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->event_fields, i))); - } - HashMapSet(json, "event_fields", JsonValueArray(jsonArr)); - } - return json; -} - -void -FilterFree(Filter *val) -{ - if (!val) - { - return; - } - - FilterEventFree(&val->presence); - FilterEventFree(&val->account_data); - FilterRoomFree(&val->room); - if (val->event_fields) - { - size_t i; - for (i = 0; i < ArraySize(val->event_fields); i++) - { - Free(ArrayGet(val->event_fields, i)); - } - ArrayFree(val->event_fields); - } -} - -int -FilterRoomEventFromJson(HashMap *json, FilterRoomEvent *out, char **errp) -{ - JsonValue *val; - int enumParseRes; - - (void) enumParseRes; - - if (!json | !out) - { - *errp = "Invalid pointers passed to FilterRoomEventFromJson()"; - return 0; - } - - val = HashMapGet(json, "not_rooms"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterRoomEvent.not_rooms must be of type [string]."; - return 0; - } - - out->not_rooms = ArrayCreate(); - if (!out->not_rooms) - { - *errp = "Failed to allocate memory for FilterRoomEvent.not_rooms."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i not_rooms, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "not_senders"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterRoomEvent.not_senders must be of type [string]."; - return 0; - } - - out->not_senders = ArrayCreate(); - if (!out->not_senders) - { - *errp = "Failed to allocate memory for FilterRoomEvent.not_senders."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i not_senders, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "limit"); - if (val) - { - if (JsonValueType(val) != JSON_INTEGER) - { - *errp = "FilterRoomEvent.limit must be of type integer."; - return 0; - } - - out->limit = JsonValueAsInteger(val); - } - - val = HashMapGet(json, "senders"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterRoomEvent.senders must be of type [string]."; - return 0; - } - - out->senders = ArrayCreate(); - if (!out->senders) - { - *errp = "Failed to allocate memory for FilterRoomEvent.senders."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i senders, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "include_redundant_members"); - if (val) - { - if (JsonValueType(val) != JSON_BOOLEAN) - { - *errp = "FilterRoomEvent.include_redundant_members must be of type boolean."; - return 0; - } - - out->include_redundant_members = JsonValueAsBoolean(val); - } - - val = HashMapGet(json, "types"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterRoomEvent.types must be of type [string]."; - return 0; - } - - out->types = ArrayCreate(); - if (!out->types) - { - *errp = "Failed to allocate memory for FilterRoomEvent.types."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i types, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "rooms"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterRoomEvent.rooms must be of type [string]."; - return 0; - } - - out->rooms = ArrayCreate(); - if (!out->rooms) - { - *errp = "Failed to allocate memory for FilterRoomEvent.rooms."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i rooms, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "lazy_load_members"); - if (val) - { - if (JsonValueType(val) != JSON_BOOLEAN) - { - *errp = "FilterRoomEvent.lazy_load_members must be of type boolean."; - return 0; - } - - out->lazy_load_members = JsonValueAsBoolean(val); - } - - val = HashMapGet(json, "not_types"); - if (val) - { - if (JsonValueType(val) != JSON_ARRAY) - { - *errp = "FilterRoomEvent.not_types must be of type [string]."; - return 0; - } - - out->not_types = ArrayCreate(); - if (!out->not_types) - { - *errp = "Failed to allocate memory for FilterRoomEvent.not_types."; - return 0; - } - else - { - Array *arr = JsonValueAsArray(val); - size_t i; - - for (i = 0; i not_types, StrDuplicate(JsonValueAsString(v))); - } - } - } - - val = HashMapGet(json, "contains_url"); - if (val) - { - if (JsonValueType(val) != JSON_BOOLEAN) - { - *errp = "FilterRoomEvent.contains_url must be of type boolean."; - return 0; - } - - out->contains_url = JsonValueAsBoolean(val); - } - - val = HashMapGet(json, "unread_thread_notifications"); - if (val) - { - if (JsonValueType(val) != JSON_BOOLEAN) - { - *errp = "FilterRoomEvent.unread_thread_notifications must be of type boolean."; - return 0; - } - - out->unread_thread_notifications = JsonValueAsBoolean(val); - } - - return 1; -} - -HashMap * -FilterRoomEventToJson(FilterRoomEvent *val) -{ - HashMap *json; - - if (!val) - { - return NULL; - } - - json = HashMapCreate(); - if (!json) - { - return NULL; - } - - if (val->not_rooms) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->not_rooms); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->not_rooms, i))); - } - HashMapSet(json, "not_rooms", JsonValueArray(jsonArr)); - } - if (val->not_senders) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->not_senders); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->not_senders, i))); - } - HashMapSet(json, "not_senders", JsonValueArray(jsonArr)); - } - HashMapSet(json, "limit", JsonValueInteger(val->limit)); - if (val->senders) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->senders); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->senders, i))); - } - HashMapSet(json, "senders", JsonValueArray(jsonArr)); - } - HashMapSet(json, "include_redundant_members", JsonValueBoolean(val->include_redundant_members)); - if (val->types) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->types); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->types, i))); - } - HashMapSet(json, "types", JsonValueArray(jsonArr)); - } - if (val->rooms) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->rooms); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->rooms, i))); - } - HashMapSet(json, "rooms", JsonValueArray(jsonArr)); - } - HashMapSet(json, "lazy_load_members", JsonValueBoolean(val->lazy_load_members)); - if (val->not_types) - { - size_t i; - Array *jsonArr = ArrayCreate(); - if (!jsonArr) - { - JsonFree(json); - return NULL; - } - for (i = 0; i < ArraySize(val->not_types); i++) - { - ArrayAdd(jsonArr, JsonValueString(ArrayGet(val->not_types, i))); - } - HashMapSet(json, "not_types", JsonValueArray(jsonArr)); - } - HashMapSet(json, "contains_url", JsonValueBoolean(val->contains_url)); - HashMapSet(json, "unread_thread_notifications", JsonValueBoolean(val->unread_thread_notifications)); - return json; -} - -void -FilterRoomEventFree(FilterRoomEvent *val) -{ - if (!val) - { - return; - } - - if (val->not_rooms) - { - size_t i; - for (i = 0; i < ArraySize(val->not_rooms); i++) - { - Free(ArrayGet(val->not_rooms, i)); - } - ArrayFree(val->not_rooms); - } - if (val->not_senders) - { - size_t i; - for (i = 0; i < ArraySize(val->not_senders); i++) - { - Free(ArrayGet(val->not_senders, i)); - } - ArrayFree(val->not_senders); - } - if (val->senders) - { - size_t i; - for (i = 0; i < ArraySize(val->senders); i++) - { - Free(ArrayGet(val->senders, i)); - } - ArrayFree(val->senders); - } - if (val->types) - { - size_t i; - for (i = 0; i < ArraySize(val->types); i++) - { - Free(ArrayGet(val->types, i)); - } - ArrayFree(val->types); - } - if (val->rooms) - { - size_t i; - for (i = 0; i < ArraySize(val->rooms); i++) - { - Free(ArrayGet(val->rooms, i)); - } - ArrayFree(val->rooms); - } - if (val->not_types) - { - size_t i; - for (i = 0; i < ArraySize(val->not_types); i++) - { - Free(ArrayGet(val->not_types, i)); - } - ArrayFree(val->not_types); - } -} - diff --git a/src/Schema/PduV1.c b/src/Schema/PduV1.c deleted file mode 100644 index ceb2997..0000000 --- a/src/Schema/PduV1.c +++ /dev/null @@ -1,477 +0,0 @@ -/* Generated by j2s */ - -#include - -#include -#include -#include - -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; - } - -} - diff --git a/src/Schema/PduV3.c b/src/Schema/PduV3.c deleted file mode 100644 index ef2bc8b..0000000 --- a/src/Schema/PduV3.c +++ /dev/null @@ -1,500 +0,0 @@ -/* Generated by j2s */ - -#include - -#include -#include -#include - -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 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 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; - } - -} - diff --git a/src/Schema/RoomCreateRequest.c b/src/Schema/RoomCreateRequest.c deleted file mode 100644 index 6e38dd6..0000000 --- a/src/Schema/RoomCreateRequest.c +++ /dev/null @@ -1,712 +0,0 @@ -/* Generated by j2s */ - -#include - -#include -#include -#include - -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 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 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 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); -} -