[MOD/ADD] Start element/XMPPwerk

XML gave me an aneurysm. I hate this.
This commit is contained in:
LDA 2024-06-15 14:29:50 +02:00
commit 138932d637
4 changed files with 204 additions and 0 deletions

View file

@ -3,6 +3,7 @@
#include <Cytoplasm/HashMap.h>
#include <Cytoplasm/Stream.h>
#include <Cytoplasm/Array.h>
typedef struct XMLexer XMLexer;
typedef struct XMLEvent {
@ -33,4 +34,39 @@ extern XMLexer * XMLCreateLexer(Stream *, bool);
extern XMLEvent * XMLCrank(XMLexer *);
extern void XMLFreeEvent(XMLEvent *);
extern void XMLFreeLexer(XMLexer *);
typedef struct XMLElement {
enum {
XML_ELEMENT_UNKNOWN = 0,
XML_ELEMENT_TAG,
XML_ELEMENT_DATA,
XML_ELEMENT_PI,
XML_ELEMENT_CDATA
} type;
/* Only set when the type is a TAG. */
char *name;
HashMap *attrs;
Array *children;
/* Only set when the type is DATA or
* CDATA */
char *data;
} XMLElement;
/* Decodes 1 element off a stream. */
extern XMLElement * XMLDecode(Stream *stream, bool autofree);
extern XMLElement * XMLCreateTag(char *name);
extern XMLElement * XMLCreateText(char *data);
extern void XMLAddAttr(XMLElement *element, char *key, char *val);
extern void XMLAddChild(XMLElement *element, XMLElement *child);
/* Frees an XML element properly. */
extern void XMLFreeElement(XMLElement *element);
/* Encodes an XML element to a stream */
extern void XMLEncode(Stream *stream, XMLElement *element);
#endif

19
src/include/XMPP.h Normal file
View file

@ -0,0 +1,19 @@
#ifndef PARSEE_XMPP_H
#define PARSEE_XMPP_H
#include <Cytoplasm/Stream.h>
/* 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);
/* 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 *shared);
/* TODO: XMPP stuff, I don't fucking know, I'm not a Jabbernerd. */
/* Closes a raw component stream. */
extern void XMPPEndCompStream(Stream *stream);
#endif