mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 18:35:11 +00:00
[MOD] Make functions for creating a "killer stanza"
Cleaning up the mop...
This commit is contained in:
parent
14ebef53ce
commit
e089cea02a
4 changed files with 46 additions and 16 deletions
16
src/Main.c
16
src/Main.c
|
|
@ -34,21 +34,8 @@ SignalHandler(int signal)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Create a loopback stanza, forcing the thread to die */
|
/* Create a loopback stanza, forcing the thread to die */
|
||||||
from = StrConcat(2, "jabber_die@", jabber->host);
|
XMPPKillThread(jabber);
|
||||||
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);
|
|
||||||
|
|
||||||
HttpServerStop(server);
|
HttpServerStop(server);
|
||||||
//pthread_cancel(xmpp_thr);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -84,6 +71,7 @@ Main(void)
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
Log(LOG_ERR, "Could not connect to XMPP...");
|
Log(LOG_ERR, "Could not connect to XMPP...");
|
||||||
|
XMPPEndCompStream(jabber);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,3 +54,37 @@ XMPPSendPresence(XMPPComponent *comp, char *fr, char *to)
|
||||||
XMLFreeElement(presence);
|
XMLFreeElement(presence);
|
||||||
Free(from);
|
Free(from);
|
||||||
}
|
}
|
||||||
|
void
|
||||||
|
XMPPKillThread(XMPPComponent *jabber)
|
||||||
|
{
|
||||||
|
XMLElement *message, *body, *data;
|
||||||
|
char *from;
|
||||||
|
|
||||||
|
if (!jabber)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
from = StrConcat(2, "jabber_die@", 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"));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,7 @@ ParseeXMPPThread(void *argp)
|
||||||
if (StrEquals(stanza->name, "message"))
|
if (StrEquals(stanza->name, "message"))
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
if (StrEquals(HashMapGet(stanza->attrs, "from"),
|
if (XMPPIsKiller(stanza))
|
||||||
HashMapGet(stanza->attrs, "to")))
|
|
||||||
{
|
{
|
||||||
/* There's not a lot of scenarios where we loopback */
|
/* There's not a lot of scenarios where we loopback */
|
||||||
Log(LOG_INFO, "Dropping thread...");
|
Log(LOG_INFO, "Dropping thread...");
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <Cytoplasm/Stream.h>
|
#include <Cytoplasm/Stream.h>
|
||||||
|
|
||||||
|
#include <XML.h>
|
||||||
|
|
||||||
typedef struct XMPPComponent {
|
typedef struct XMPPComponent {
|
||||||
char *host;
|
char *host;
|
||||||
Stream *stream;
|
Stream *stream;
|
||||||
|
|
@ -25,4 +27,11 @@ extern void XMPPSendPlain(XMPPComponent *c, char *f, char *t, char *m, char *typ
|
||||||
|
|
||||||
/* Closes a raw component stream. */
|
/* Closes 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);
|
||||||
|
|
||||||
|
/* Checks if a stanza is a "killstanza". */
|
||||||
|
extern bool XMPPIsKiller(XMLElement *);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue