mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:25:11 +00:00
[ADD/WIP] Continue MUCwerk
oh man this is gonna be painful to do... xmpp is fine iff youre doing DMs isnt it?
This commit is contained in:
parent
3ac11fd269
commit
d3b7f2fee0
19 changed files with 707 additions and 44 deletions
|
|
@ -1,5 +1,8 @@
|
|||
#include <Parsee.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
|
|
@ -9,6 +12,28 @@
|
|||
#include <XML.h>
|
||||
#include <AS.h>
|
||||
|
||||
|
||||
static pthread_mutex_t cond_var_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
void
|
||||
ParseeWakeupThread(void)
|
||||
{
|
||||
pthread_mutex_lock(&cond_var_lock);
|
||||
pthread_cond_signal(&cond_var);
|
||||
pthread_mutex_unlock(&cond_var_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
ParseeDMHandler(char *room, char *from, XMLElement *data, const ParseeConfig *c)
|
||||
{
|
||||
Log(LOG_INFO, "Trying to send %s %s", room, from);
|
||||
ASSend(
|
||||
c, room, from,
|
||||
"m.room.message", MatrixCreateMessage(data->data)
|
||||
);
|
||||
}
|
||||
|
||||
void *
|
||||
ParseeXMPPThread(void *argp)
|
||||
{
|
||||
|
|
@ -21,26 +46,41 @@ ParseeXMPPThread(void *argp)
|
|||
XMLElement *body = NULL;
|
||||
XMLElement *data = NULL;
|
||||
char *to, *room, *from, *from_matrix;
|
||||
char *chat_id, *mroom_id;
|
||||
|
||||
/* Decoding XML is blocking, which will cause memory issues when we
|
||||
* want to murder this thread.
|
||||
* We could ping the server, and die on a "response" stanza, however.
|
||||
*/
|
||||
stanza = XMLDecode(jabber->stream, false);
|
||||
if (!stanza)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (StrEquals(stanza->name, "presence"))
|
||||
{
|
||||
XMLFreeElement(stanza);
|
||||
continue;
|
||||
}
|
||||
if (StrEquals(stanza->name, "message"))
|
||||
{
|
||||
size_t i;
|
||||
if (XMPPIsKiller(stanza))
|
||||
{
|
||||
/* There's not a lot of scenarios where we loopback */
|
||||
Log(LOG_INFO, "Dropping thread...");
|
||||
XMLFreeElement(stanza);
|
||||
break;
|
||||
const char *killer = "killer";
|
||||
const char *suspend="suspend";
|
||||
from = HashMapGet(stanza->attrs, "from");
|
||||
if (!strncmp(from, killer, strlen(killer)))
|
||||
{
|
||||
Log(LOG_INFO, "Dropping thread...");
|
||||
XMLFreeElement(stanza);
|
||||
break;
|
||||
}
|
||||
else if (!strncmp(from, suspend, strlen(suspend)))
|
||||
{
|
||||
XMLFreeElement(stanza);
|
||||
pthread_mutex_lock(&cond_var_lock);
|
||||
pthread_cond_wait(&cond_var, &cond_var_lock);
|
||||
pthread_mutex_unlock(&cond_var_lock);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < ArraySize(stanza->children); i++)
|
||||
{
|
||||
|
|
@ -56,6 +96,8 @@ ParseeXMPPThread(void *argp)
|
|||
XMLFreeElement(stanza);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* TODO: Check the type */
|
||||
to = ParseeDecodeMXID(HashMapGet(stanza->attrs, "to"));
|
||||
from = HashMapGet(stanza->attrs, "from");
|
||||
from_matrix = ParseeEncodeJID(args->config, from);
|
||||
|
|
@ -63,10 +105,20 @@ ParseeXMPPThread(void *argp)
|
|||
data = ArrayGet(body->children, 0);
|
||||
|
||||
/* TODO: Consider having rich messages */
|
||||
ASSend(
|
||||
args->config, room, from_matrix,
|
||||
"m.room.message", MatrixCreateMessage(data->data)
|
||||
);
|
||||
chat_id = ParseeGetFromMUCID(args, from);
|
||||
mroom_id = ParseeGetRoomID(args, chat_id);
|
||||
if (room)
|
||||
{
|
||||
ParseeDMHandler(room, from_matrix, data, args->config);
|
||||
}
|
||||
if (mroom_id)
|
||||
{
|
||||
Log(LOG_INFO, "Send to %s", mroom_id);
|
||||
/* TODO: Grab username, create a puppet, and go from
|
||||
* there */
|
||||
}
|
||||
Free(chat_id);
|
||||
Free(mroom_id);
|
||||
Free(from_matrix);
|
||||
Free(room);
|
||||
Free(to);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue