[ADD] Make and start using an XML encoder

Now, we have basic sanitation!!!!!!
This commit is contained in:
LDA 2024-06-19 02:33:53 +02:00
commit b408cbf224
4 changed files with 110 additions and 19 deletions

View file

@ -1,29 +1,35 @@
#include <XMPP.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Str.h>
#include <XML.h>
void
XMPPSendPlain(XMPPComponent *comp, char *fr, char *to, char *msg, char *type)
{
XMLElement *message, *body, *data;
char *from;
if (!comp || !fr || !to || !msg)
{
return;
}
StreamPrintf(
comp->stream, "<message from='%s@%s' to='%s'",
fr, comp->host, to
);
if (type)
{
StreamPrintf(comp->stream, " type='%s'", type);
}
StreamPrintf(comp->stream, ">");
StreamPrintf(comp->stream,
"<body>"
"%s"
"</body>"
"</message>",
msg
);
message = XMLCreateTag("message");
XMLAddAttr(message, "from", (from = StrConcat(3, fr, "@", comp->host)));
XMLAddAttr(message, "to", to);
XMLAddAttr(message, "type", type);
body = XMLCreateTag("body");
data = XMLCreateText(msg);
XMLAddChild(message, body);
XMLAddChild(body, data);
XMLEncode(comp->stream, message);
StreamFlush(comp->stream);
XMLFreeElement(message);
Free(from);
}
void
XMPPSendPresence(XMPPComponent *comp, char *fr, char *to)