mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-14 00:45:10 +00:00
[ADD/WIP] Push all the Janet changes
This is still unstable(and I still need to design/document the exposed API)! Do(n't) go and use it!
This commit is contained in:
parent
960599d983
commit
ca87972b3a
50 changed files with 3550 additions and 92 deletions
81
src/include/Extension.h
Normal file
81
src/include/Extension.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#ifndef PARSEE_EXTENSION_H
|
||||
#define PARSEE_EXTENSION_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <Cytoplasm/Json.h>
|
||||
|
||||
#include <XML.h>
|
||||
|
||||
typedef struct ParseeData ParseeData;
|
||||
|
||||
typedef struct Extensions Extensions;
|
||||
typedef struct Extension Extension;
|
||||
|
||||
typedef enum StanzaType {
|
||||
STANZA_RAW = 0,
|
||||
STANZA_MESSAGE = 1,
|
||||
STANZA_IQ = 2,
|
||||
STANZA_PRESENCE = 3,
|
||||
|
||||
STANZA_TYPE_COUNT
|
||||
} StanzaType;
|
||||
|
||||
/** Verifies if extensions are enabled with the Parsee binary.
|
||||
* Functions here <strong>WILL</strong> fail if this function
|
||||
* returns false!
|
||||
* -------------------
|
||||
* Returns: true IFF extensions are enabled */
|
||||
extern bool ExtensionEnabled(void);
|
||||
|
||||
/* Creates an extension context. */
|
||||
extern Extensions * ExtensionCreateContext(struct ParseeData *data);
|
||||
|
||||
/** Destroys the entire extension context, and all of its extensions.
|
||||
* -------------------------------------
|
||||
* Returns: NOTHING
|
||||
* Thrashes: ctx */
|
||||
extern void ExtensionDestroyContext(Extensions *ctx);
|
||||
|
||||
/** Loads a basic extension from a simple Janet file.
|
||||
* ----------------------------
|
||||
* Returns: An extension handle[ctx] | NULL */
|
||||
extern Extension * ExtensionLoadBasic(Extensions *ctx, char *id, char *file);
|
||||
|
||||
/** Reloads an extension from an ID.
|
||||
* ---------------------------
|
||||
* Returns: NOTHING */
|
||||
extern void ExtensionReload(Extensions *ctx, char *id);
|
||||
|
||||
/** Loads extensions from a directory. The directory's Janet files are loaded
|
||||
* (with the part before the .janet extension denoting the identifier).
|
||||
* -----------------------------------
|
||||
* Returns: NOTHING */
|
||||
extern void ExtensionLoadDir(Extensions *ctx, char *dir);
|
||||
|
||||
/** Broadcasts a stanza received to all extensions(by calling the
|
||||
* on-stanza function).
|
||||
* -----------------------------------------
|
||||
* Returns: NOTHING
|
||||
* Modifies: the extensions */
|
||||
extern bool ExtensionPushStanza(Extensions *ctx, XMLElement *stanza, StanzaType t);
|
||||
|
||||
/** Broadcasts a Matrix event to all extensions, akin to ExtensionPushStanza.
|
||||
* -----------
|
||||
* Returns: NOTHING
|
||||
* Modifies: the extensions */
|
||||
extern bool ExtensionPushEvent(Extensions *ctx, HashMap *obj);
|
||||
|
||||
/** Calls "on-xmpp-cmd" on extensions' Janet side, with no arguments.
|
||||
* ----------
|
||||
* Returns: NOTHING
|
||||
* Modifies: the extensions */
|
||||
extern void ExtensionRequestCommands(Extensions *ctx);
|
||||
|
||||
extern void
|
||||
ExtensionShoveCommands(Extensions *ctx, char *jid, XMLElement *query, XMLElement *stanza);
|
||||
|
||||
extern void
|
||||
ExtensionManageCommands(Extensions *ctx, XMLElement *stanza);
|
||||
|
||||
#endif
|
||||
|
|
@ -15,6 +15,7 @@ typedef struct ParseeData ParseeData;
|
|||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <Extension.h>
|
||||
#include <Command.h>
|
||||
#include <XMPP.h>
|
||||
|
||||
|
|
@ -50,6 +51,7 @@ typedef struct ParseeConfig {
|
|||
/* ------- DB -------- */
|
||||
char *db_path;
|
||||
size_t db_size;
|
||||
char *extensions;
|
||||
|
||||
/* - COMMAND-LINE FLAGS - */
|
||||
int xmpp_threads, http_threads;
|
||||
|
|
@ -72,8 +74,10 @@ typedef struct ParseeData {
|
|||
pthread_mutex_t oidl;
|
||||
|
||||
/* If Parsee was intentionally halted */
|
||||
bool halted;
|
||||
volatile bool halted;
|
||||
pthread_mutex_t halt_lock;
|
||||
|
||||
Extensions *exts;
|
||||
} ParseeData;
|
||||
|
||||
typedef struct Argument {
|
||||
|
|
@ -93,6 +97,8 @@ typedef struct Argument {
|
|||
#define GrabObject(obj, ...) JsonValueAsObject(JsonGet(obj, __VA_ARGS__))
|
||||
#define GrabArray(obj, ...) JsonValueAsArray(JsonGet(obj, __VA_ARGS__))
|
||||
|
||||
#define IterateReentrant(h, k, v, i) HashMapIterateReentrant(h, &k, (void **) &v, &i)
|
||||
|
||||
/* Milliseconds to UNIT macros, to be used like 30 SECONDS and 1 MINUTES
|
||||
* in timestamps */
|
||||
#define SECONDS * 1000
|
||||
|
|
@ -121,6 +127,7 @@ extern const char *parsee_ascii[PARSEE_ASCII_LINES];
|
|||
* Modifies: the logger output */
|
||||
extern void ParseePrintASCII(void);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if two versions of Parsee can be considered "compatible".
|
||||
* This is mainly used for things like database operations. TODO:
|
||||
|
|
@ -276,6 +283,12 @@ extern char * ParseeGetRoomID(ParseeData *, char *chat_id);
|
|||
/* Finds the MUC JID from a chat ID */
|
||||
extern char * ParseeGetMUCID(ParseeData *, char *chat_id);
|
||||
|
||||
/** Verifies if a JID maps to a chatroom through Service Discovery.
|
||||
* ----------------
|
||||
* Returns: whenever the JID is a real MUC
|
||||
* Modifies: the XMPP stream */
|
||||
extern bool ParseeIsMUC(ParseeData *data, char *jid);
|
||||
|
||||
/** Fetches a configuration value from a key in a chat(given a Chat ID),
|
||||
* as a string or NULL. Keys are to be stored like Java packages(reveres DNS).
|
||||
* Parsee has the right over any key with the <code>'p.'</code> prefix.
|
||||
|
|
@ -321,6 +334,14 @@ ParseeIsMediaEnabled(ParseeData *data, char *chat_id);
|
|||
extern void ParseePushStanza(ParseeData *, char *chat_id, char *stanza_id, char *origin_id, char *event, char *sender);
|
||||
extern void ParseePushDMStanza(ParseeData *, char *room_id, char *stanza_id, char *origin_id, char *event, char *sender);
|
||||
|
||||
/** Automatically pushes the link between a stanza and a bridged Matrix event.
|
||||
* It behaves like {ParseePushStanza} and {ParseePushDMStanza}, but the routing
|
||||
* is done automatically.
|
||||
* ----------------------------
|
||||
* Returns: NOTHING
|
||||
* Modifies: the database */
|
||||
extern void ParseePushAllStanza(ParseeData *args, XMLElement *stanza, char *event);
|
||||
|
||||
/* Checks if a stanza is not duplicated in a chat ID */
|
||||
extern bool ParseeVerifyStanza(ParseeData *, char *chat_id, char *stanza_id);
|
||||
|
||||
|
|
@ -488,4 +509,8 @@ extern void ParseeUnlinkRoom(ParseeData *data, char *chat_id);
|
|||
* Modifies: NOTHING */
|
||||
extern bool ParseeIsMUCWhitelisted(ParseeData *data, char *muc);
|
||||
|
||||
/* TODO */
|
||||
extern char * ParseeGetBridgedUserI(ParseeData *data, XMLElement *stanza, char *force);
|
||||
#define ParseeGetBridgedUser(data, stanza) ParseeGetBridgedUserI(data, stanza, NULL)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
typedef struct XMPPCommandManager XMPPCommandManager;
|
||||
#ifndef PARSEE_XMPPCOMMAND_H
|
||||
#define PARSEE_XMPPCOMMAND_H
|
||||
|
||||
|
|
@ -7,11 +8,16 @@
|
|||
#include <Parsee.h>
|
||||
#include <XML.h>
|
||||
|
||||
typedef struct XMPPCommandManager XMPPCommandManager;
|
||||
typedef enum XMPPCommandFlags {
|
||||
XMPPCMD_ALL = 0,
|
||||
XMPPCMD_MUC , /* Only for MUCs */
|
||||
XMPPCMD_ADMINS /* Only for administrators */
|
||||
} XMPPCommandFlags;
|
||||
|
||||
typedef struct XMPPCommand XMPPCommand;
|
||||
typedef struct XMPPOption XMPPOption;
|
||||
typedef void (*XMPPCmdCallback)(XMPPCommandManager *, char *, XMLElement *, XMLElement *);
|
||||
typedef void (*XMPPOptionWriter)(XMPPCommandManager *, XMPPCommand *, char *);
|
||||
typedef void (*XMPPCmdCallback)(XMPPCommandManager *, char *, XMLElement *, XMLElement *, char *);
|
||||
typedef void (*XMPPOptionWriter)(XMPPCommandManager *, XMPPCommand *, char *, char *);
|
||||
typedef bool (*XMPPCmdFilter)(XMPPCommandManager *, char *id, XMLElement *stanza);
|
||||
|
||||
/** Creates a simple XMPP command manager, which routes commands
|
||||
|
|
@ -39,7 +45,7 @@ XMPPManagerSetFilter(XMPPCommandManager *manager, XMPPCmdFilter filter);
|
|||
* Modifies: NOTHING
|
||||
* See-Also: XMPPRegisterCommand */
|
||||
extern XMPPCommand *
|
||||
XMPPBasicCmd(char *node, char *name, XMPPCmdCallback cb);
|
||||
XMPPBasicCmd(XMPPCommandFlags flags, char *node, char *name, XMPPCmdCallback cb);
|
||||
extern void
|
||||
XMPPCmdOptionsCreator(XMPPCommand *cmd, XMPPOptionWriter writer);
|
||||
extern void XMPPAddOption(XMPPCommand *cmd, XMPPOption *opt);
|
||||
|
|
@ -49,7 +55,7 @@ extern char * XMPPGetCommandDesc(XMPPCommand *cmd);
|
|||
extern void XMPPSetFormInstruction(XMPPCommand *cmd, char *instruction);
|
||||
extern void XMPPSetFormTitle(XMPPCommand *cmd, char *title);
|
||||
extern bool XMPPCommandRequiresForm(XMPPCommand *cmd);
|
||||
extern void XMPPExecuteCommand(XMPPCommandManager *m, XMPPCommand *cmd, char *from, XMLElement *to, XMLElement *form);
|
||||
extern void XMPPExecuteCommand(XMPPCommandManager *m, XMPPCommand *cmd, char *from, XMLElement *to, XMLElement *form, char *node);
|
||||
|
||||
/** Create a basic option.
|
||||
* -----------------------------------------------------
|
||||
|
|
@ -91,6 +97,12 @@ extern void XMPPRegisterCommand(XMPPCommandManager *m, XMPPCommand *cmd);
|
|||
* See-Also: XMPPCreateManager */
|
||||
extern void XMPPShoveCommandList(XMPPCommandManager *m, char *jid, XMLElement *p, XMLElement *s);
|
||||
|
||||
/** Returns the flags associated to a command.
|
||||
* ----------------
|
||||
* Returns: some flags
|
||||
* Modifies: NOTHING */
|
||||
extern XMPPCommandFlags XMPPGetCommandFlags(XMPPCommandManager *m, char *id);
|
||||
|
||||
/** Destroys all memory related to the command {manager}.
|
||||
* -----------------------------------------------------
|
||||
* Returns: NOTHING
|
||||
|
|
@ -111,11 +123,11 @@ extern bool XMPPManageCommand(XMPPCommandManager *m, XMLElement *stanza, ParseeD
|
|||
|
||||
#define XMPP_COMMAND(f,l,n,t,s) \
|
||||
extern void \
|
||||
f(XMPPCommandManager *, char *, XMLElement *, XMLElement *); \
|
||||
f(XMPPCommandManager *, char *, XMLElement *, XMLElement *, char *); \
|
||||
/* This symbol might not exist. We do, however, not care, as
|
||||
* it is not always done. */ \
|
||||
extern void \
|
||||
Form##f(XMPPCommandManager *, XMPPCommand *, char *); \
|
||||
Form##f(XMPPCommandManager *, XMPPCommand *, char *, char *); \
|
||||
|
||||
#include "XMPPCommands.x.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,4 @@
|
|||
/* C X-macro file */
|
||||
typedef enum XMPPCommandFlags {
|
||||
XMPPCMD_ALL = 0,
|
||||
XMPPCMD_MUC , /* Only for MUCs */
|
||||
XMPPCMD_ADMINS /* Only for administrators */
|
||||
} XMPPCommandFlags;
|
||||
#define XMPPCOMMANDS \
|
||||
XMPP_COMMAND(StatusCallback, XMPPCMD_ALL, "stats", "Get Parsee statistics", {}) \
|
||||
XMPP_COMMAND(CleanCallback, XMPPCMD_ADMINS, "clean", "Cleanup temporary Parsee data", {}) \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue