forked from Telodendria/Telodendria
Add schema for PDUs v1 and v3, the only unique PDU formats.
All other room versions use one of these two PDU formats.
This commit is contained in:
parent
bc71a7ec01
commit
d565640455
6 changed files with 244 additions and 10 deletions
|
@ -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");
|
||||
|
|
58
Schema/ClientEvent.json
Normal file
58
Schema/ClientEvent.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
81
Schema/PduV1.json
Normal file
81
Schema/PduV1.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
77
Schema/PduV3.json
Normal file
77
Schema/PduV3.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -38,6 +38,16 @@
|
|||
|
||||
#include <Room.h>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue