#include #include #include #include #include void XMPPSendPlain(XMPPComponent *comp, char *fr, char *to, char *msg, char *type) { XMLElement *message, *body, *data; char *from; if (!comp || !fr || !to || !msg) { return; } 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 XMPPSendMUC(XMPPComponent *comp, char *fr, char *as, char *to, char *msg, char *type) { XMLElement *message, *body, *data; char *from, *id; if (!comp || !fr || !to || !as || !msg) { return; } message = XMLCreateTag("message"); XMLAddAttr(message, "from", (from = StrConcat(5, fr, "@", comp->host, "/", as))); XMLAddAttr(message, "to", to); XMLAddAttr(message, "type", type); XMLAddAttr(message, "id", (id = StrRandom(8))); body = XMLCreateTag("body"); data = XMLCreateText(msg); XMLAddChild(message, body); XMLAddChild(body, data); XMLEncode(comp->stream, message); StreamFlush(comp->stream); XMLFreeElement(message); Free(from); Free(id); } void XMPPJoinMUC(XMPPComponent *comp, char *fr, char *muc) { XMLElement *presence, *x; char *from, *id; if (!comp || !fr || !muc) { return; } presence = XMLCreateTag("presence"); x = XMLCreateTag("x"); XMLAddAttr(presence, "from", (from = StrConcat(3, fr, "@", comp->host))); XMLAddAttr(presence, "to", muc); XMLAddAttr(presence, "id", (id = StrRandom(8))); XMLAddAttr(x, "xmlns", "http://jabber.org/protocol/muc"); XMLAddChild(presence, x); XMLEncode(comp->stream, presence); StreamFlush(comp->stream); XMLFreeElement(presence); Free(from); Free(id); } void XMPPKillThread(XMPPComponent *jabber, char *killer) { XMLElement *message, *body, *data; char *from; if (!jabber || !killer) { return; } from = StrConcat(3, killer, "@", jabber->host); message = XMLCreateTag("message"); XMLAddAttr(message, "from", from); XMLAddAttr(message, "to", from); XMLAddAttr(message, "type", "kill_parsee"); body = XMLCreateTag("body"); XMLAddChild(message, body); XMLEncode(jabber->stream, message); StreamFlush(jabber->stream); XMLFreeElement(message); Free(from); } bool XMPPIsKiller(XMLElement *stanza) { if (!stanza) { return false; } return StrEquals( HashMapGet(stanza->attrs, "from"), HashMapGet(stanza->attrs, "to")); }