mirror of
https://git.kappach.at/lda/Parsee.git
synced 2025-05-12 22:53:46 +02:00
144 lines
5.1 KiB
C
144 lines
5.1 KiB
C
#ifndef PARSEE_XMPP_H
|
|
#define PARSEE_XMPP_H
|
|
|
|
/*-*
|
|
* Functions used to communicate with an XMPP server over an JCP stream.
|
|
* --------
|
|
* Writren-By: LDA */
|
|
|
|
#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);
|
|
|
|
/** Writes an XML stanza through a component, while making sure any locking
|
|
* work is done. If {max} is non-zero, then this function will not send
|
|
* stanzas beyond {max} bytes.
|
|
* -----------------------
|
|
* Modifies: {comp}, the XMPP stream
|
|
* See-Also: XMPPInitialiseCompStream, XMPPAuthenticateCompStream, XMPP-core RFC */
|
|
extern void XMPPSendStanza(XMPPComponent *comp, XMLElement *stanza, size_t max);
|
|
|
|
/* Makes a user join/leave a MUC */
|
|
extern bool XMPPJoinMUC(XMPPComponent *comp, char *fr, char *muc, char *hash, int secs, bool ret);
|
|
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 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);
|
|
|
|
#include <Parsee.h>
|
|
/** Sends a XMPP discovery request to an entity, and caches it if possible.
|
|
* ------------------------------------------------------------------------
|
|
* Returns: a valid XML element[HEAP]
|
|
* Modifies: the {data}'s cache
|
|
* Thrasher: XMLFreeElement */
|
|
extern XMLElement * XMPPSendDisco(ParseeData *data, char *from, char *to);
|
|
|
|
extern bool XMPPDiscoAdvertises(XMLElement *disco, char *var);
|
|
|
|
/** Requests for 'voice' in a moderated MUC as a user by sending a specific
|
|
* form.
|
|
* -----------
|
|
* Returns: NOTHING
|
|
* Modifies: the XMPP MUCs state
|
|
* See-Also: https://xmpp.org/extensions/xep-0045.html#requestvoice */
|
|
extern void XMPPRequestVoice(XMPPComponent *jabber, char *from, char *muc);
|
|
|
|
/** Retrieves the error type in a stanza if existent.
|
|
* -----------------
|
|
* Returns: a valid string error type[stanza] | NULL
|
|
* Modifies: NOTHING
|
|
* See-Also: XMPPGetErrtext */
|
|
extern char * XMPPGetErrtype(XMLElement *stanza);
|
|
|
|
/** Retrieves the error text in a stanza if existent.
|
|
* -----------------
|
|
* Returns: a valid string error text[stanza] | NULL
|
|
* Modifies: NOTHING
|
|
* See-Also: XMPPGetErrtype */
|
|
extern char * XMPPGetErrtext(XMLElement *stanza);
|
|
#endif
|