mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 18:15:11 +00:00
105 lines
3.8 KiB
C
105 lines
3.8 KiB
C
#ifndef PARSEE_XMPP_H
|
|
#define PARSEE_XMPP_H
|
|
|
|
#include <Cytoplasm/Stream.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <XML.h>
|
|
|
|
typedef struct XMPPComponent {
|
|
/* A lock for all write operations */
|
|
pthread_mutex_t write_lock;
|
|
|
|
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 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(XMPPComponent *comp, char *shared);
|
|
|
|
/* Makes a user join/leave a MUC */
|
|
extern bool XMPPJoinMUC(XMPPComponent *comp, char *fr, char *muc);
|
|
extern void XMPPLeaveMUC(XMPPComponent *comp, char *fr, char *muc, char *r);
|
|
|
|
/* TODO: XMPP stuff, I don't fucking know, I'm not a Jabbernerd. */
|
|
extern void XMPPSendPlain(XMPPComponent *comp, char *fr, char *to, char *msg, char *type, char *rst, char *rse, char *event_id, char *oob, char *id);
|
|
extern void XMPPSendPlainID(XMPPComponent *comp, char *fr, char *to, char *msg, char *type, char *rst, char *rse, char *event_id, char *oob, char *id, char *sid);
|
|
extern void XMPPRetract(XMPPComponent *comp, char *fr, char *to, char *type, char *redact);
|
|
|
|
/* Finishes a component stream, and doesn't free it. */
|
|
extern void XMPPFinishCompStream(XMPPComponent *stream);
|
|
|
|
/* Frees a raw component stream. */
|
|
extern void XMPPEndCompStream(XMPPComponent *stream);
|
|
|
|
typedef struct MUCInfo {
|
|
bool exists;
|
|
|
|
XMPPComponent *jabber;
|
|
XMLElement *iq_reply;
|
|
} MUCInfo;
|
|
|
|
/** Queries a MUC's existence, and if {out} is set, stores information
|
|
* pertaining the MUC itself from an IQ query.
|
|
* ----------------------------------------------------------------------
|
|
* Modifies: *out[TBFB:XMPPFreeMUCInfo]
|
|
* See-Also: XMPPGetMUCName, XMPPFreeMUCInfo */
|
|
extern bool XMPPQueryMUC(XMPPComponent *jabber, char *muc, MUCInfo *out);
|
|
|
|
/** Retrieves the MUC's name from an IQ reply
|
|
* ----------------------------------------------------------------------
|
|
* Returns: The MUC's name[LA:HEAP] | NULL
|
|
* Modifies: NOTHING
|
|
* See-Also: XMPPQueryMUC, XMPPFreeMUCInfo */
|
|
extern char * XMPPGetMUCName(MUCInfo info);
|
|
|
|
extern void XMPPFreeMUCInfo(MUCInfo info);
|
|
|
|
/* Checks if a stanza has an x-parsee element */
|
|
extern bool XMPPIsParseeStanza(XMLElement *);
|
|
|
|
/* Returns the stanza ID of a stanza, if existent */
|
|
extern char * XMPPGetStanzaID(XMLElement *);
|
|
|
|
/* Returns the origin ID of a stanza, if existent */
|
|
extern char * XMPPGetOriginID(XMLElement *);
|
|
|
|
/* Returns the origin ID of the replaced stanza, if the current one
|
|
* is a replacement notice */
|
|
extern char * XMPPGetReplacedID(XMLElement *);
|
|
extern char * XMPPGetRetractedID(XMLElement *);
|
|
|
|
/* Get the replied-to stanza ID, if existent. */
|
|
extern char * XMPPGetReply(XMLElement *elem);
|
|
|
|
/** Get the moderated message ID(as a stanza ID/plain ID) from a moderation
|
|
* stanza, that lives *alongside* the stanza itself.
|
|
* ----------------------------------------------------------------------
|
|
* Returns: The stanza ID[LA:stanza] | NULL
|
|
* Modifies: NOTHING
|
|
* See-Also: https://xmpp.org/extensions/xep-0425.html */
|
|
extern char * XMPPGetModeration(XMLElement *stanza);
|
|
|
|
/** Generate the B64-encoded SHA-256 hash for the 'ver' field in caps.
|
|
* --------
|
|
* Returns: A base64 encoded ver hash[LA:HEAP]
|
|
* Modifies: NOTHING
|
|
* See-Also: https://xmpp.org/extensions/xep-0115.html */
|
|
extern char * XMPPGenerateVer(void);
|
|
|
|
/* Annotates a presence with https://xmpp.org/extensions/xep-0115.html */
|
|
extern void XMPPAnnotatePresence(XMLElement *presence);
|
|
|
|
extern bool XMPPHasError(XMLElement *stanza, char *type);
|
|
|
|
extern XMLElement * XMPPSendDisco(XMPPComponent *jabber, char *from, char *to);
|
|
|
|
extern bool XMPPDiscoAdvertises(XMLElement *disco, char *var);
|
|
#endif
|