diff --git a/Cytoplasm/tools/j2s.c b/Cytoplasm/tools/j2s.c index 8899242..cc617b0 100644 --- a/Cytoplasm/tools/j2s.c +++ b/Cytoplasm/tools/j2s.c @@ -37,6 +37,13 @@ #define MAX_DEPENDENCIES 32 +static char * +Trim(char c, char *str) +{ + while (*str == c) str++; + return str; +} + static JsonType TypeToJsonType(char *type) { @@ -610,11 +617,11 @@ Main(Array * args) JsonType jsonType = isEnum ? JSON_STRING : TypeToJsonType(fieldType); char *jsonTypeStr = JsonTypeToStr(jsonType); - StreamPrintf(implFile, " val = HashMapGet(json, \"%s\");\n", key); + StreamPrintf(implFile, " val = HashMapGet(json, \"%s\");\n", Trim('_', key)); StreamPrintf(implFile, " if (val)\n {\n"); StreamPrintf(implFile, " if (JsonValueType(val) != %s)\n {\n", jsonTypeStr); - StreamPrintf(implFile, " *errp = \"%s.%s must be of type %s.\";\n", type, key, fieldType); + StreamPrintf(implFile, " *errp = \"%s.%s must be of type %s.\";\n", type, Trim('_', key), fieldType); StreamPrintf(implFile, " return 0;\n"); StreamPrintf(implFile, " }\n\n"); if (StrEquals(fieldType, "array")) @@ -853,12 +860,12 @@ Main(Array * args) StreamPrintf(implFile, " {\n"); StreamPrintf(implFile, " ArrayAdd(jsonArr, JsonValueDuplicate(ArrayGet(val->%s, i)));\n", key); StreamPrintf(implFile, " }\n"); - StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueArray(jsonArr))\n", key); + StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueArray(jsonArr));\n", Trim('_', key)); StreamPrintf(implFile, " }\n"); } else if (StrEquals(fieldType, "object")) { - StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueObject(JsonDuplicate(val->%s)));\n", key, key); + StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueObject(JsonDuplicate(val->%s)));\n", Trim('_', key), key); } else if (*fieldType == '[' && fieldType[strlen(fieldType) - 1] == ']') { @@ -920,7 +927,7 @@ Main(Array * args) } StreamPrintf(implFile, " }\n"); - StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueArray(jsonArr));\n", key); + StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueArray(jsonArr));\n", Trim('_', key)); StreamPrintf(implFile, " }\n"); fieldType[strlen(fieldType)] = ']'; @@ -931,17 +938,17 @@ Main(Array * args) { if (isEnum) { - StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueString(%sToStr(val->%s)));\n", key, fieldType, key); + StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueString(%sToStr(val->%s)));\n", Trim('_', key), fieldType, key); } else { - StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueObject(%sToJson(&val->%s)));\n", key, fieldType, key); + StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueObject(%sToJson(&val->%s)));\n", Trim('_', key), fieldType, key); } } else { *fieldType = toupper(*fieldType); - StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValue%s(val->%s));\n", key, fieldType, key); + StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValue%s(val->%s));\n", Trim('_', key), fieldType, key); *fieldType = tolower(*fieldType); } } @@ -1034,7 +1041,7 @@ Main(Array * args) StreamPrintf(implFile, " if"); } - StreamPrintf(implFile, " (StrEquals(str, \"%s\"))\n {\n", key); + StreamPrintf(implFile, " (StrEquals(str, \"%s\"))\n {\n", Trim('_', key)); StreamPrintf(implFile, " return %s;\n", JsonValueAsString(JsonGet(fields, 2, key, "name"))); StreamPrintf(implFile, " }\n"); } @@ -1053,7 +1060,7 @@ Main(Array * args) char *name = JsonValueAsString(JsonGet(fields, 2, key, "name")); StreamPrintf(implFile, " case %s:\n", name); - StreamPrintf(implFile, " return \"%s\";\n", key); + StreamPrintf(implFile, " return \"%s\";\n", Trim('_', key)); } StreamPrintf(implFile, " default:\n"); StreamPrintf(implFile, " return NULL;\n"); diff --git a/Schema/ClientEvent.json b/Schema/ClientEvent.json new file mode 100644 index 0000000..967e806 --- /dev/null +++ b/Schema/ClientEvent.json @@ -0,0 +1,58 @@ +{ + "guard": "TELODENDRIA_SCHEMA_CLIENTEVENT_H", + "header": "Schema/ClientEvent.h", + "types": { + "ClientEventUnsignedData": { + "type": "struct", + "fields": { + "age": { + "type": "integer" + }, + "prev_content": { + "type": "object" + }, + "redacted_because": { + "type": "object" + }, + "transaction_id": { + "type": "string" + } + } + }, + "ClientEvent": { + "type": "struct", + "fields": { + "content": { + "type": "object", + "required": true + }, + "event_id": { + "type": "string", + "required": true + }, + "origin_server_ts": { + "type": "integer", + "required": true + }, + "room_id": { + "type": "string", + "required": true + }, + "sender": { + "type": "string", + "required": true + }, + "state_key": { + "type": "string" + }, + "type": { + "type": "string", + "required": true + }, + "_unsigned": { + "type": "ClientEventUnsignedData" + } + } + } + } +} diff --git a/Schema/PduV1.json b/Schema/PduV1.json new file mode 100644 index 0000000..eaf17a8 --- /dev/null +++ b/Schema/PduV1.json @@ -0,0 +1,81 @@ +{ + "guard": "TELODENDRIA_SCHEMA_PDUV1_H", + "header": "Schema/PduV1.h", + "types": { + "PduV1EventHash": { + "type": "struct", + "fields": { + "sha256": { + "type": "string", + "required": true + } + } + }, + "PduV1UnsignedData": { + "type": "struct", + "fields": { + "age": { + "type": "integer" + } + } + }, + "PduV1": { + "type": "struct", + "fields": { + "auth_events": { + "type": "array", + "required": true + }, + "content": { + "type": "object", + "required": true + }, + "depth": { + "type": "integer", + "required": true + }, + "event_id": { + "type": "string", + "required": true + }, + "hashes": { + "type": "PduV1EventHash", + "required": true + }, + "origin_server_ts": { + "type": "integer", + "required": true + }, + "prev_events": { + "type": "array", + "required": true + }, + "redacts": { + "type": "string" + }, + "room_id": { + "type": "string", + "required": true + }, + "sender": { + "type": "string", + "required": true + }, + "signatures": { + "type": "object", + "required": true + }, + "state_key": { + "type": "string" + }, + "type": { + "type": "string", + "required": true + }, + "_unsigned": { + "type": "PduV1UnsignedData" + } + } + } + } +} diff --git a/Schema/PduV3.json b/Schema/PduV3.json new file mode 100644 index 0000000..94694e3 --- /dev/null +++ b/Schema/PduV3.json @@ -0,0 +1,77 @@ +{ + "guard": "TELODENDRIA_SCHEMA_PDUV3_H", + "header": "Schema/PduV3.h", + "types": { + "PduV3EventHash": { + "type": "struct", + "fields": { + "sha256": { + "type": "string", + "required": true + } + } + }, + "PduV3UnsignedData": { + "type": "struct", + "fields": { + "age": { + "type": "integer" + } + } + }, + "PduV3": { + "type": "struct", + "fields": { + "auth_events": { + "type": "[string]", + "required": true + }, + "content": { + "type": "object", + "required": true + }, + "depth": { + "type": "integer", + "required": true + }, + "hashes": { + "type": "PduV3EventHash", + "required": true + }, + "origin_server_ts": { + "type": "integer", + "required": true + }, + "prev_events": { + "type": "[string]", + "required": true + }, + "redacts": { + "type": "string" + }, + "room_id": { + "type": "string", + "required": true + }, + "sender": { + "type": "string", + "required": true + }, + "signatures": { + "type": "object", + "required": true + }, + "state_key": { + "type": "string" + }, + "type": { + "type": "string", + "required": true + }, + "_unsigned": { + "type": "PduV3UnsignedData" + } + } + } + } +} diff --git a/src/Routes/RouteAliasDirectory.c b/src/Routes/RouteAliasDirectory.c index 4e960c9..77d5cea 100644 --- a/src/Routes/RouteAliasDirectory.c +++ b/src/Routes/RouteAliasDirectory.c @@ -141,6 +141,7 @@ ROUTE_IMPL(RouteAliasDirectory, path, argp) response = MatrixErrorCreate(M_UNAUTHORIZED, NULL); goto finish; } + JsonValueFree(HashMapDelete(JsonValueAsObject(HashMapGet(aliases, "alias")), alias)); } response = HashMapCreate(); diff --git a/src/include/State.h b/src/include/State.h index 08f13b4..e34493e 100644 --- a/src/include/State.h +++ b/src/include/State.h @@ -38,6 +38,16 @@ #include +/** + * Retrieve the value of a state tuple. + */ +extern char *StateGet(HashMap *, char *, char *); + +/** + * Set a state tuple to a value. + */ +extern char *StateSet(HashMap *, char *, char *, char *); + /** * Compute the room state before the specified event was sent. */