[ADD/WIP] Dot-separated fetching, respect 'rooms'
Some checks failed
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Has been cancelled

That should get me to filter events, senders, and other things
This commit is contained in:
LDA 2024-07-20 17:45:12 +02:00
parent d46e418ec1
commit 6f045083a2
3 changed files with 93 additions and 2 deletions

View file

@ -360,3 +360,71 @@ MatrixClientWellKnown(char *base, char *identity)
return response;
}
JsonValue *
MatrixGetJSON(HashMap *json, char *string)
{
JsonValue *retVal;
HashMap *currentObj;
char *field, *fieldTemp;
size_t i, length;
if (!json || !string)
{
return NULL;
}
currentObj = json;
retVal = NULL;
length = strlen(string);
field = NULL;
#define Append(ch) do \
{ \
char chb[2] = { ch, 0 }; \
fieldTemp = field; \
field = StrConcat(2, field, chb); \
Free(fieldTemp); \
} while (0)
/* We include the 0-terminator as a valid separator. */
for (i = 0; i < length + 1; i++)
{
char currentChar = string[i];
char escape;
if (currentChar == '\\' && (escape = string[i+1]))
{
if (escape != '.' && escape != '\\')
{
Append('\\');
}
Append(escape);
i++;
continue;
}
else if (currentChar == '.' || currentChar == '\0')
{
if (!field || !currentObj)
{
Free(field);
return NULL;
}
retVal = HashMapGet(currentObj, field);
currentObj = JsonValueAsObject(retVal);
Free(field);
field = NULL;
continue;
}
Append(currentChar);
}
#undef Append
if (field)
{
/* This is weird. */
Free(field);
}
return retVal;
}

View file

@ -59,6 +59,7 @@ StripStateEventSync(HashMap *pdu)
return ret;
}
/* Verify whenever a room is filtered out by a filter given in. */
static bool
IsRoomFiltered(Filter *filter, char *roomID)
{
@ -77,7 +78,20 @@ IsRoomFiltered(Filter *filter, char *roomID)
return true;
}
}
/* TODO: Consider rooms */
count = ArraySize(filter->room.rooms);
if (count)
{
for (i = 0; i < count; i++)
{
char *room = ArrayGet(filter->room.rooms, i);
if (StrEquals(roomID, room))
{
return false;
}
}
return true;
}
return false;
}

View file

@ -39,8 +39,9 @@
#include <Cytoplasm/HttpServer.h>
#include <Cytoplasm/HttpRouter.h>
#include <Cytoplasm/Log.h>
#include <Cytoplasm/HashMap.h>
#include <Cytoplasm/Json.h>
#include <Cytoplasm/Log.h>
#include <Config.h>
#include <Cytoplasm/Db.h>
@ -154,4 +155,12 @@ extern HashMap * MatrixRateLimit(HttpServerContext *, Db *);
*/
extern HashMap * MatrixClientWellKnown(char *, char *);
/**
* Decodes a dot-separated path (as defined by the Specification) and
* tries to retrieve it from a JSON object hashmap, failing with NULL
* if it cannot be found, like Cytoplasm's
* .Fn JsonGet .
*/
extern JsonValue * MatrixGetJSON(HashMap *, char *);
#endif