mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:35:10 +00:00
[ADD/WIP] Begin XMPPwerk
The fuck is a stanza? Presence? Why did Prosody not tell me I'm an idiot when I clearly made a MALFORMED XML document? This and much more, in the next commit!
This commit is contained in:
parent
f7eace20c7
commit
868f0e4d9c
7 changed files with 207 additions and 11 deletions
|
|
@ -1,12 +1,82 @@
|
|||
#include <XML.h>
|
||||
|
||||
#include <Cytoplasm/Log.h>
|
||||
|
||||
/* TODO: The rest of all that. */
|
||||
|
||||
XMLElement *
|
||||
XMLDecode(Stream *stream, bool autofree)
|
||||
{
|
||||
/* TODO: Use the existing SAX parser to decode everything */
|
||||
return NULL;
|
||||
#define push(x) ArrayAdd(stack, x)
|
||||
#define pop(x) ArrayDelete(stack, ArraySize(stack) - 1)
|
||||
#define peek(x) ArrayGet(stack, ArraySize(stack) - 1)
|
||||
XMLexer *lexer;
|
||||
XMLEvent *event;
|
||||
XMLElement *ret = NULL;
|
||||
XMLElement *top;
|
||||
char *key, *val;
|
||||
|
||||
Array *stack;
|
||||
|
||||
if (!stream)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
lexer = XMLCreateLexer(stream, autofree);
|
||||
stack = ArrayCreate();
|
||||
while ((event = XMLCrank(lexer)) && (!ret || ArraySize(stack)))
|
||||
{
|
||||
switch (event->type)
|
||||
{
|
||||
case XML_LEXER_STARTELEM:
|
||||
/* Create a new element that will populated. */
|
||||
top = XMLCreateTag(event->element);
|
||||
Log(LOG_INFO, "<%s>", top->name);
|
||||
XMLAddChild(peek(), top);
|
||||
while (HashMapIterate(event->attrs, &key, (void **) &val))
|
||||
{
|
||||
XMLAddAttr(top, key, val);
|
||||
}
|
||||
if (!ret)
|
||||
{
|
||||
/* If we didn't have any element before, this one is
|
||||
* going to be our top of the stack */
|
||||
ret = top;
|
||||
}
|
||||
push(top);
|
||||
break;
|
||||
case XML_LEXER_ELEM:
|
||||
/* Create a new element that will populated. */
|
||||
top = XMLCreateTag(event->element);
|
||||
XMLAddChild(peek(), top);
|
||||
Log(LOG_INFO, "<%s />", top->name);
|
||||
while (HashMapIterate(event->attrs, &key, (void **) &val))
|
||||
{
|
||||
XMLAddAttr(top, key, val);
|
||||
}
|
||||
if (!ret)
|
||||
{
|
||||
/* If we didn't have any element before, this one is
|
||||
* going to be our top of the stack */
|
||||
ret = top;
|
||||
}
|
||||
push(top);
|
||||
/* Fallthrough */
|
||||
case XML_LEXER_ENDELEM:
|
||||
/* Pop out an element out of the DOM. */
|
||||
Log(LOG_INFO, "</>");
|
||||
pop();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
XMLFreeEvent(event);
|
||||
event = NULL;
|
||||
}
|
||||
XMLFreeEvent(event);
|
||||
ArrayFree(stack);
|
||||
XMLFreeLexer(lexer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Array.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
|
@ -24,7 +23,8 @@ struct XMLexer {
|
|||
|
||||
XML_STATE_ATTR,
|
||||
XML_STATE_ATTRHEAD_PROP,
|
||||
XML_STATE_ATTRTAIL
|
||||
XML_STATE_ATTRTAIL,
|
||||
XML_STATE_PI
|
||||
} state;
|
||||
|
||||
struct {
|
||||
|
|
@ -161,6 +161,17 @@ XMLCrank(XMLexer *lexer)
|
|||
lexer->state = XML_STATE_ATTRTAIL;
|
||||
break;
|
||||
}
|
||||
else if (XMLookahead(lexer, "<?", true))
|
||||
{
|
||||
if (lexer->data.str)
|
||||
{
|
||||
XMLFreeEvent(event);
|
||||
event = XMLCreateData(lexer);
|
||||
}
|
||||
|
||||
lexer->state = XML_STATE_PI;
|
||||
break;
|
||||
}
|
||||
else if (XMLookahead(lexer, "<", true))
|
||||
{
|
||||
if (lexer->data.str)
|
||||
|
|
@ -189,6 +200,14 @@ XMLCrank(XMLexer *lexer)
|
|||
return NULL;
|
||||
}
|
||||
break;
|
||||
case XML_STATE_PI:
|
||||
if (XMLookahead(lexer, "?>", true))
|
||||
{
|
||||
lexer->state = XML_STATE_NONE;
|
||||
break;
|
||||
}
|
||||
XMLGetc(lexer);
|
||||
break;
|
||||
case XML_STATE_ATTR:
|
||||
attrname = XMLParseName(lexer);
|
||||
if (!attrname)
|
||||
|
|
@ -250,7 +269,6 @@ XMLFreeEvent(XMLEvent *event)
|
|||
void *val;
|
||||
while (HashMapIterate(event->attrs, &key, &val))
|
||||
{
|
||||
Log(LOG_INFO, "Trying to free %s", val);
|
||||
Free(val);
|
||||
}
|
||||
HashMapFree(event->attrs);
|
||||
|
|
@ -640,6 +658,8 @@ XMLParseAttQuote(XMLexer *lexer)
|
|||
|
||||
point = XMLInitialiseBuffer(lexer);
|
||||
|
||||
/* TODO: My Prosody is actually trolling me.
|
||||
* GIVE ME A FUCKING STREAM ID YOU RETARD. */
|
||||
while ((c = XMLGetc(lexer)))
|
||||
{
|
||||
if (!IsNormalQ(c))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue