[DEL] Remove killstanzas

Shinobis are no longer allowed, we're no longer on the Heian era, and as
such, we get rid of weird things like Heian Aliens.

In other, more serious news, this should increase reliability, as Parsee
now cleans after itself gracefully, instead of just killing off the
stream.
This commit is contained in:
LDA 2024-07-06 02:55:11 +02:00
commit 3eae6c15ed
5 changed files with 24 additions and 62 deletions

View file

@ -31,7 +31,8 @@ SignalHandler(int signal)
/* TODO: Better way to break out. */ /* TODO: Better way to break out. */
Log(LOG_INFO, "Killing thread..."); Log(LOG_INFO, "Killing thread...");
XMPPKillThread(jabber, "killer"); //XMPPKillThread(jabber, "killer");
XMPPFinishCompStream(jabber);
pthread_join(xmpp_thr, NULL); pthread_join(xmpp_thr, NULL);
valid = false; valid = false;
Log(LOG_INFO, "Stopping server..."); Log(LOG_INFO, "Stopping server...");

View file

@ -187,6 +187,18 @@ end:
return ret; return ret;
} }
void
XMPPFinishCompStream(XMPPComponent *comp)
{
if (!comp)
{
return;
}
pthread_mutex_lock(&comp->write_lock);
StreamPrintf(comp->stream, "<stream:stream/>");
StreamFlush(comp->stream);
pthread_mutex_unlock(&comp->write_lock);
}
void void
XMPPEndCompStream(XMPPComponent *comp) XMPPEndCompStream(XMPPComponent *comp)
{ {

View file

@ -201,44 +201,6 @@ XMPPJoinMUC(XMPPComponent *comp, char *fr, char *muc)
pthread_mutex_unlock(&comp->write_lock); 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 bool
XMPPIsParseeStanza(XMLElement *stanza) XMPPIsParseeStanza(XMLElement *stanza)
{ {

View file

@ -656,7 +656,10 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
XMLElement *event = XMLookForUnique(parsee, "event-id"); XMLElement *event = XMLookForUnique(parsee, "event-id");
XMLElement *e_d = ArrayGet(event ? event->children : NULL, 0); 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: end:
Free(mroom_id); Free(mroom_id);
@ -1192,12 +1195,12 @@ ParseeXMPPThread(void *argp)
while (true) while (true)
{ {
char *from, *id; char *id;
stanza = XMLDecode(jabber->stream, false); stanza = XMLDecode(jabber->stream, false);
if (!stanza) if (!stanza)
{ {
continue; break;
} }
id = HashMapGet(stanza->attrs, "id"); id = HashMapGet(stanza->attrs, "id");
@ -1221,18 +1224,6 @@ ParseeXMPPThread(void *argp)
pthread_mutex_unlock(&await_lock); 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); PushStanza(&info, stanza);
} }

View file

@ -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 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); 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); 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 { typedef struct MUCInfo {
bool exists; bool exists;