[ADD/WIP] Matrix<->XMPP DMs.

There is still this fun issue with the blocking XML parser leaking
memory on pthread_cancel, I'll try to deal with that later, maybe with a
test stanza.

I also apologise for swearing in the last commit. I promise it won't
happen again, Prosody.
This commit is contained in:
LDA 2024-06-18 20:59:35 +02:00
commit 2cc4b0ed17
11 changed files with 325 additions and 63 deletions

View file

@ -24,7 +24,6 @@ ASVerifyRequest(ParseeHttpArg *arg)
if (!authorisation || strncmp(authorisation, "Bearer ", 7))
{
Log(LOG_INFO, "Bad auth %s", authorisation);
HttpResponseStatus(arg->ctx, HTTP_FORBIDDEN);
ret = MatrixCreateError("M_MISSING_TOKEN", "No 'hs_token' given in.");
goto end;
@ -42,7 +41,7 @@ end:
}
void
ASAuthenticateRequest(ParseeConfig *data, HttpClientContext *ctx)
ASAuthenticateRequest(const ParseeConfig *data, HttpClientContext *ctx)
{
char *bearer;
if (!data || !ctx)
@ -55,7 +54,7 @@ ASAuthenticateRequest(ParseeConfig *data, HttpClientContext *ctx)
Free(bearer);
}
bool
ASRegisterUser(ParseeConfig *conf, char *user)
ASRegisterUser(const ParseeConfig *conf, char *user)
{
HttpClientContext *ctx = NULL;
HashMap *json = NULL;
@ -100,7 +99,6 @@ ASPing(const ParseeConfig *conf)
return;
}
Log(LOG_NOTICE, "Pinging...");
path = StrConcat(3,
"/_matrix/client/v1/appservice/",
"Parsee%20XMPP",
@ -118,14 +116,13 @@ ASPing(const ParseeConfig *conf)
JsonFree(json);
}
void
ASJoin(ParseeConfig *conf, char *id, char *masquerade)
ASJoin(const ParseeConfig *conf, char *id, char *masquerade)
{
HttpClientContext *ctx = NULL;
HashMap *json = NULL;
char *path;
if (!conf || !id || !masquerade)
{
Log(LOG_ERR, "Bad values %p %p", conf, id);
return;
}
@ -134,7 +131,6 @@ ASJoin(ParseeConfig *conf, char *id, char *masquerade)
"user_id=", masquerade
);
Log(LOG_INFO, "%s", path);
ctx = ParseeCreateRequest(
conf,
HTTP_POST, path
@ -148,40 +144,29 @@ ASJoin(ParseeConfig *conf, char *id, char *masquerade)
JsonFree(json);
}
void
ASSend(ParseeConfig *conf, char *id, char *user, char *type, HashMap *c)
ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c)
{
HttpClientContext *ctx = NULL;
HashMap *json = NULL, *params_obj;
Stream *s;
char *path, *params;
char *txn;
if (!conf || !id || !type || !c)
if (!conf || !id || !type || !user || !c)
{
return;
}
txn = StrRandom(16);
params_obj = HashMapCreate();
if (user)
{
HashMapSet(params_obj, "user_id", user);
}
params = HttpParamEncode(params_obj);
HashMapFree(params_obj);
path = StrConcat(8,
path = StrConcat(9,
"/_matrix/client/v3/rooms/",
id, "/send/", type, "/", txn, "?",
params
"user_id=", user
);
Log(LOG_INFO, "Sending %s", path);
Free(params);
Free(txn);
ctx = ParseeCreateRequest(conf, HTTP_PUT, path);
Free(path);
json = HashMapCreate();
ASAuthenticateRequest(conf, ctx);
Log(LOG_INFO, "%d", ParseeSetRequestJSON(ctx, c));
ParseeSetRequestJSON(ctx, c);
HttpClientContextFree(ctx);
JsonFree(c);
}