diff --git a/src/Signal.c b/src/Signal.c index dd31a51..86142f5 100644 --- a/src/Signal.c +++ b/src/Signal.c @@ -31,7 +31,8 @@ SignalHandler(int signal) /* TODO: Better way to break out. */ Log(LOG_INFO, "Killing thread..."); - XMPPKillThread(jabber, "killer"); + //XMPPKillThread(jabber, "killer"); + XMPPFinishCompStream(jabber); pthread_join(xmpp_thr, NULL); valid = false; Log(LOG_INFO, "Stopping server..."); diff --git a/src/XMPP/Component.c b/src/XMPP/Component.c index a2b405c..d1ca9cf 100644 --- a/src/XMPP/Component.c +++ b/src/XMPP/Component.c @@ -187,6 +187,18 @@ end: return ret; } +void +XMPPFinishCompStream(XMPPComponent *comp) +{ + if (!comp) + { + return; + } + pthread_mutex_lock(&comp->write_lock); + StreamPrintf(comp->stream, ""); + StreamFlush(comp->stream); + pthread_mutex_unlock(&comp->write_lock); +} void XMPPEndCompStream(XMPPComponent *comp) { diff --git a/src/XMPP/Stanza.c b/src/XMPP/Stanza.c index c4c861d..d96b4ad 100644 --- a/src/XMPP/Stanza.c +++ b/src/XMPP/Stanza.c @@ -201,44 +201,6 @@ XMPPJoinMUC(XMPPComponent *comp, char *fr, char *muc) pthread_mutex_unlock(&comp->write_lock); } -void -XMPPKillThread(XMPPComponent *jabber, char *killer) -{ - XMLElement *message, *body; - char *from; - - if (!jabber || !killer) - { - return; - } - - //pthread_mutex_lock(&jabber->write_lock); - - 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); - - //pthread_mutex_unlock(&jabber->write_lock); -} -bool -XMPPIsKiller(XMLElement *stanza) -{ - if (!stanza) - { - return false; - } - return StrEquals( HashMapGet(stanza->attrs, "from"), - HashMapGet(stanza->attrs, "to")); -} bool XMPPIsParseeStanza(XMLElement *stanza) { diff --git a/src/XMPPThread.c b/src/XMPPThread.c index 99ae001..656b2d5 100644 --- a/src/XMPPThread.c +++ b/src/XMPPThread.c @@ -656,7 +656,10 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr) XMLElement *event = XMLookForUnique(parsee, "event-id"); XMLElement *e_d = ArrayGet(event ? event->children : NULL, 0); - ParseePushAllStanza(args, stanza, e_d->data); + if (e_d) + { + ParseePushAllStanza(args, stanza, e_d->data); + } } end: Free(mroom_id); @@ -1192,12 +1195,12 @@ ParseeXMPPThread(void *argp) while (true) { - char *from, *id; + char *id; stanza = XMLDecode(jabber->stream, false); if (!stanza) { - continue; + break; } id = HashMapGet(stanza->attrs, "id"); @@ -1221,18 +1224,6 @@ ParseeXMPPThread(void *argp) pthread_mutex_unlock(&await_lock); } - - if (StrEquals(stanza->name, "message") && XMPPIsKiller(stanza)) - { - const char *killer = "killer"; - from = HashMapGet(stanza->attrs, "from"); - if (!strncmp(from, killer, strlen(killer))) - { - XMLFreeElement(stanza); - break; - } - } - PushStanza(&info, stanza); } diff --git a/src/include/XMPP.h b/src/include/XMPP.h index 9a3d5e9..51124f5 100644 --- a/src/include/XMPP.h +++ b/src/include/XMPP.h @@ -31,16 +31,12 @@ extern void XMPPJoinMUC(XMPPComponent *comp, char *fr, char *muc); extern void XMPPSendPlain(XMPPComponent *comp, char *fr, char *to, char *msg, char *type, char *rst, char *rse, char *event_id, char *oob, char *id); extern void XMPPSendPlainID(XMPPComponent *comp, char *fr, char *to, char *msg, char *type, char *rst, char *rse, char *event_id, char *oob, char *id, char *sid); -/* Closes a raw component stream. */ +/* Finishes a component stream, and doesn't free it. */ +extern void XMPPFinishCompStream(XMPPComponent *stream); + +/* Frees a raw component stream. */ extern void XMPPEndCompStream(XMPPComponent *stream); -/* Sends a loopback stanza (a "killstanza"), used to kill an XMPP listener - * thread. */ -extern void XMPPKillThread(XMPPComponent *jabber, char *killer); - -/* Checks if a stanza is a "killstanza". */ -extern bool XMPPIsKiller(XMLElement *); - typedef struct MUCInfo { bool exists;