mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 18:45:11 +00:00
[FIX/ADD] Fix deadlock and DMs.
This commit is contained in:
parent
c5df636bdb
commit
59d5ad6780
7 changed files with 57 additions and 34 deletions
35
src/AS.c
35
src/AS.c
|
|
@ -118,6 +118,41 @@ ASPing(const ParseeConfig *conf)
|
||||||
JsonFree(json);
|
JsonFree(json);
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
|
ASInvite(const ParseeConfig *conf, char *id, char *invited)
|
||||||
|
{
|
||||||
|
HttpClientContext *ctx = NULL;
|
||||||
|
HashMap *json = NULL;
|
||||||
|
char *path, *bridge;
|
||||||
|
if (!conf || !id || !invited)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bridge = StrConcat(4,
|
||||||
|
"@", conf->sender_localpart,
|
||||||
|
":", conf->homeserver_host
|
||||||
|
);
|
||||||
|
path = StrConcat(5,
|
||||||
|
"/_matrix/client/v3/rooms/", id, "/invite",
|
||||||
|
"?user_id=", bridge
|
||||||
|
);
|
||||||
|
Free(bridge);
|
||||||
|
|
||||||
|
ctx = ParseeCreateRequest(
|
||||||
|
conf,
|
||||||
|
HTTP_POST, path
|
||||||
|
);
|
||||||
|
Free(path);
|
||||||
|
json = HashMapCreate();
|
||||||
|
HashMapSet(json, "user_id", JsonValueString(invited));
|
||||||
|
HashMapSet(json, "reason", JsonValueString("Pass over."));
|
||||||
|
ASAuthenticateRequest(conf, ctx);
|
||||||
|
ParseeSetRequestJSON(ctx, json);
|
||||||
|
|
||||||
|
HttpClientContextFree(ctx);
|
||||||
|
JsonFree(json);
|
||||||
|
}
|
||||||
|
void
|
||||||
ASBan(const ParseeConfig *conf, char *id, char *banned)
|
ASBan(const ParseeConfig *conf, char *id, char *banned)
|
||||||
{
|
{
|
||||||
HttpClientContext *ctx = NULL;
|
HttpClientContext *ctx = NULL;
|
||||||
|
|
|
||||||
|
|
@ -26,19 +26,22 @@ ParseeMemberHandler(ParseeData *data, HashMap *event)
|
||||||
DbRef *ref;
|
DbRef *ref;
|
||||||
HashMap *json;
|
HashMap *json;
|
||||||
char *jid;
|
char *jid;
|
||||||
|
bool direct = GrabBoolean(event, 2, "content", "is_direct");
|
||||||
bool bot = !strncmp(sender + 1, local, strlen(local));
|
bool bot = !strncmp(sender + 1, local, strlen(local));
|
||||||
ASJoin(conf, room_id, state_key);
|
ASJoin(conf, room_id, state_key);
|
||||||
|
|
||||||
jid = ParseeDecodeLocalJID(conf, state_key);
|
jid = ParseeDecodeLocalJID(conf, state_key);
|
||||||
|
|
||||||
ref = DbCreate(data->db, 3, "rooms", room_id, "data");
|
if (direct && !bot)
|
||||||
json = DbJson(ref);
|
{
|
||||||
HashMapSet(json, "is_direct", JsonValueBoolean(!bot));
|
ref = DbCreate(data->db, 3, "rooms", room_id, "data");
|
||||||
HashMapSet(json, "xmpp_user", JsonValueString(jid));
|
json = DbJson(ref);
|
||||||
DbUnlock(data->db, ref);
|
HashMapSet(json, "is_direct", JsonValueBoolean(direct && !bot));
|
||||||
|
HashMapSet(json, "xmpp_user", JsonValueString(jid));
|
||||||
|
DbUnlock(data->db, ref);
|
||||||
|
ParseePushDMRoom(data, sender, jid, room_id);
|
||||||
|
}
|
||||||
|
|
||||||
ParseePushDMRoom(data, sender, jid, room_id);
|
|
||||||
/* Pretend everything is a dm, ignoring is_direct */
|
|
||||||
if (jid)
|
if (jid)
|
||||||
{
|
{
|
||||||
Free(jid);
|
Free(jid);
|
||||||
|
|
@ -170,7 +173,9 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
|
||||||
char *user = GrabString(json, 1, "xmpp_user");
|
char *user = GrabString(json, 1, "xmpp_user");
|
||||||
char *local = ParseeEncodeMXID(sender);
|
char *local = ParseeEncodeMXID(sender);
|
||||||
|
|
||||||
XMPPSendPlain(jabber, local, user, body, NULL, NULL, NULL, ev_id, NULL, NULL);
|
Log(LOG_INFO," Sending to %s as %s", user, local);
|
||||||
|
|
||||||
|
XMPPSendPlain(jabber, local, user, body, "chat", NULL, NULL, ev_id, NULL, NULL);
|
||||||
|
|
||||||
DbUnlock(data->db, ref);
|
DbUnlock(data->db, ref);
|
||||||
Free(chat_id);
|
Free(chat_id);
|
||||||
|
|
|
||||||
|
|
@ -427,27 +427,9 @@ ParseePushMUC(ParseeData *data, char *room_id, char *jid)
|
||||||
}
|
}
|
||||||
j = DbJson(ref);
|
j = DbJson(ref);
|
||||||
{
|
{
|
||||||
HashMap *table;
|
|
||||||
|
|
||||||
table = JsonValueAsObject(HashMapGet(j, "mucs"));
|
JsonSet(j, JsonValueString(chatid), 2, "mucs", jid);
|
||||||
if (!table)
|
JsonSet(j, JsonValueString(chatid), 2, "rooms", room_id);
|
||||||
{
|
|
||||||
table = HashMapCreate();
|
|
||||||
}
|
|
||||||
HashMapSet(table, jid, JsonValueString(chatid));
|
|
||||||
HashMapSet(j, "mucs", JsonValueObject(table));
|
|
||||||
|
|
||||||
|
|
||||||
table = JsonValueAsObject(HashMapGet(j, "rooms"));
|
|
||||||
if (!table)
|
|
||||||
{
|
|
||||||
table = HashMapCreate();
|
|
||||||
}
|
|
||||||
HashMapSet(table, room_id, JsonValueString(chatid));
|
|
||||||
HashMapSet(j, "rooms", JsonValueObject(table));
|
|
||||||
|
|
||||||
DbJsonSet(ref, (j = JsonDuplicate(j)));
|
|
||||||
JsonFree(j);
|
|
||||||
}
|
}
|
||||||
DbUnlock(data->db, ref);
|
DbUnlock(data->db, ref);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@ RouteHead(RouteRoomAck, arr, argp)
|
||||||
char *room = ArrayGet(arr, 0), *muc = NULL, *id = NULL;
|
char *room = ArrayGet(arr, 0), *muc = NULL, *id = NULL;
|
||||||
char *creator = NULL, *muc_name = NULL, *chatid = NULL;
|
char *creator = NULL, *muc_name = NULL, *chatid = NULL;
|
||||||
|
|
||||||
Log(LOG_INFO, "Ack");
|
|
||||||
|
|
||||||
response = ASVerifyRequest(args);
|
response = ASVerifyRequest(args);
|
||||||
if (response)
|
if (response)
|
||||||
|
|
@ -111,7 +110,6 @@ RouteHead(RouteRoomAck, arr, argp)
|
||||||
|
|
||||||
/* Creates a mapping */
|
/* Creates a mapping */
|
||||||
chatid = ParseePushMUC(args->data, id, muc);
|
chatid = ParseePushMUC(args->data, id, muc);
|
||||||
Log(LOG_INFO, "Chat ID=%s", chatid);
|
|
||||||
|
|
||||||
response = HashMapCreate();
|
response = HashMapCreate();
|
||||||
end:
|
end:
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ XMPPKillThread(XMPPComponent *jabber, char *killer)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&jabber->write_lock);
|
//pthread_mutex_lock(&jabber->write_lock);
|
||||||
|
|
||||||
from = StrConcat(3, killer, "@", jabber->host);
|
from = StrConcat(3, killer, "@", jabber->host);
|
||||||
message = XMLCreateTag("message");
|
message = XMLCreateTag("message");
|
||||||
|
|
@ -211,7 +211,7 @@ XMPPKillThread(XMPPComponent *jabber, char *killer)
|
||||||
XMLFreeElement(message);
|
XMLFreeElement(message);
|
||||||
Free(from);
|
Free(from);
|
||||||
|
|
||||||
pthread_mutex_unlock(&jabber->write_lock);
|
//pthread_mutex_unlock(&jabber->write_lock);
|
||||||
}
|
}
|
||||||
bool
|
bool
|
||||||
XMPPIsKiller(XMLElement *stanza)
|
XMPPIsKiller(XMLElement *stanza)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
AdvertiseSimple("urn:xmpp:reactions:0") \
|
AdvertiseSimple("urn:xmpp:reactions:0") \
|
||||||
AdvertiseSimple("urn:xmpp:styling:0") \
|
AdvertiseSimple("urn:xmpp:styling:0") \
|
||||||
AdvertiseSimple("urn:xmpp:reply:0") \
|
AdvertiseSimple("urn:xmpp:reply:0") \
|
||||||
AdvertiseSimple("urn:xmpp:sid:0") \
|
|
||||||
AdvertiseSimple("jabber:x:oob") \
|
AdvertiseSimple("jabber:x:oob") \
|
||||||
AdvertiseSimple("urn:parsee:x-parsee:0") \
|
AdvertiseSimple("urn:parsee:x-parsee:0") \
|
||||||
AdvertiseSimple("urn:parsee:jealousy:0")
|
AdvertiseSimple("urn:parsee:jealousy:0")
|
||||||
|
|
@ -98,6 +97,7 @@ MessageStanza(ParseeData *args, XMLElement *stanza)
|
||||||
|
|
||||||
ASRegisterUser(args->config, encoded);
|
ASRegisterUser(args->config, encoded);
|
||||||
ASSetName(args->config, encoded, res);
|
ASSetName(args->config, encoded, res);
|
||||||
|
ASInvite(args->config, mroom_id, encoded);
|
||||||
ASJoin(args->config, mroom_id, encoded);
|
ASJoin(args->config, mroom_id, encoded);
|
||||||
|
|
||||||
/* Check if it is a media link */
|
/* Check if it is a media link */
|
||||||
|
|
@ -288,6 +288,7 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
|
||||||
char *jid = item ? HashMapGet(item->attrs, "jid") : NULL;
|
char *jid = item ? HashMapGet(item->attrs, "jid") : NULL;
|
||||||
char *oid = HashMapGet(stanza->attrs, "from");
|
char *oid = HashMapGet(stanza->attrs, "from");
|
||||||
|
|
||||||
|
|
||||||
if (jid)
|
if (jid)
|
||||||
{
|
{
|
||||||
ParseePushJIDTable(oid, jid);
|
ParseePushJIDTable(oid, jid);
|
||||||
|
|
@ -330,7 +331,6 @@ ParseeXMPPThread(void *argp)
|
||||||
from = HashMapGet(stanza->attrs, "from");
|
from = HashMapGet(stanza->attrs, "from");
|
||||||
if (!strncmp(from, killer, strlen(killer)))
|
if (!strncmp(from, killer, strlen(killer)))
|
||||||
{
|
{
|
||||||
Log(LOG_INFO, "Killer detected.");
|
|
||||||
XMLFreeElement(stanza);
|
XMLFreeElement(stanza);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ extern void ASJoin(const ParseeConfig *, char *, char *);
|
||||||
/* Bans from a room a specific user */
|
/* Bans from a room a specific user */
|
||||||
extern void ASBan(const ParseeConfig *, char *, char *);
|
extern void ASBan(const ParseeConfig *, char *, char *);
|
||||||
|
|
||||||
|
/* Invites from a room a specific user */
|
||||||
|
extern void ASInvite(const ParseeConfig *, char *, char *);
|
||||||
|
|
||||||
/* Finds an event from a room ID and event ID */
|
/* Finds an event from a room ID and event ID */
|
||||||
extern HashMap * ASFind(const ParseeConfig *, char *, char *);
|
extern HashMap * ASFind(const ParseeConfig *, char *, char *);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue