[MOD] One-way Matrix->XMPP comms.

This is not sanitised. I need to make an XML writer.
This commit is contained in:
LDA 2024-06-17 18:26:37 +02:00
commit bdb4fd2f68
17 changed files with 421 additions and 61 deletions

View file

@ -20,7 +20,7 @@ extern void ASAuthenticateRequest(ParseeConfig *, HttpClientContext *);
extern bool ASRegisterUser(ParseeConfig *, char *);
/* Pings the homeserver to get attention. */
extern void ASPing(ParseeConfig *);
extern void ASPing(const ParseeConfig *);
/* Joins a room from an ID and a given user we want to masquerade
* as. */

View file

@ -5,8 +5,12 @@
#include <Cytoplasm/HttpRouter.h>
#include <Cytoplasm/HttpClient.h>
#include <Cytoplasm/Stream.h>
#include <Cytoplasm/Db.h>
#include <XMPP.h>
typedef struct ParseeConfig {
/* -------- MATRIX -------- */
char *as_token, *hs_token;
/* id here is "Parsee XMPP". */
char *sender_localpart;
@ -18,11 +22,24 @@ typedef struct ParseeConfig {
/* Homeserver port info */
char *homeserver_host;
int homeserver_port;
/* ------- JABBER -------- */
char *component_host;
char *shared_comp_secret;
int component_port;
/* ------- DB -------- */
char *db_path;
} ParseeConfig;
typedef struct ParseeData {
const ParseeConfig *config;
HttpRouter *router;
XMPPComponent *jabber;
Db *db;
} ParseeData;
/* Initialises a Parsee config from scratch, and writes to it
@ -42,7 +59,7 @@ extern void ParseeExportConfigYAML(Stream *);
extern void ParseeConfigFree(void);
/* Creates and destroys a data structure, stored on the heap. */
extern ParseeData * ParseeInitData(void);
extern ParseeData * ParseeInitData(XMPPComponent *);
extern void ParseeFreeData(ParseeData *);
/* HTTP server handler for Parsee, takes in a config. */
@ -54,8 +71,17 @@ extern HttpClientContext * ParseeCreateRequest(ParseeConfig *, HttpRequestMethod
extern HttpStatus ParseeSetRequestJSON(HttpClientContext *, HashMap *);
/* This function is called on every event received, and routes/manages it. */
extern void ParseeEventHandler(const ParseeConfig *, HashMap *);
extern void ParseeEventHandler(ParseeData *, HashMap *);
/* Verifies if a user is a Parsee puppet user. */
extern bool ParseeIsPuppet(const ParseeConfig *, char *);
/* Decodes a local JID for a user into a string. */
extern char * ParseeDecodeLocalJID(const ParseeConfig *, char *);
/* Gets the localpart of a MXID */
extern char * ParseeGetLocal(char *);
/* Encodes an MXID to a valid Jabber ID head */
extern char * ParseeEncodeMXID(char *);
#endif

View file

@ -11,7 +11,8 @@ typedef struct ParseeHttpArg {
/* A list of all routes. */
#define ROUTES X_ROUTE("/", RouteRoot) \
X_ROUTE("/_matrix/app/v1/transactions/(.*)", RouteTxns) \
X_ROUTE("/_matrix/app/v1/ping", RoutePing)
X_ROUTE("/_matrix/app/v1/ping", RoutePing) \
X_ROUTE("/_matrix/app/v1/users/(.*)", RouteUserAck)
#define X_ROUTE(path, name) extern void * name(Array *, void *);
ROUTES

View file

@ -3,17 +3,26 @@
#include <Cytoplasm/Stream.h>
typedef struct XMPPComponent {
char *host;
Stream *stream;
} XMPPComponent;
/* Initialises a raw component stream to host, with an optional port.
* If said port is 0, then it is set to the default Prosody port */
extern Stream * XMPPInitialiseCompStream(char *host, int port);
extern XMPPComponent * XMPPInitialiseCompStream(char *host, int port);
/* Authenticates a component stream with a given shared secret,
* with a stream ID from the server. This should be called right
* after XMPPInitialiseCompStream. */
extern bool XMPPAuthenticateCompStream(Stream *stream, char *as, char *shared);
extern bool XMPPAuthenticateCompStream(XMPPComponent *comp, char *shared);
/* Sends a presence to a user */
extern void XMPPSendPresence(XMPPComponent *comp, char *fr, char *to);
/* TODO: XMPP stuff, I don't fucking know, I'm not a Jabbernerd. */
extern void XMPPSendPlain(XMPPComponent *c, char *f, char *t, char *m, char *type);
/* Closes a raw component stream. */
extern void XMPPEndCompStream(Stream *stream);
extern void XMPPEndCompStream(XMPPComponent *stream);
#endif