mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 19:45:11 +00:00
[MOD/WIP] Start getting into intents
This commit is contained in:
parent
31305cdb23
commit
de8fd53a6f
4 changed files with 43 additions and 40 deletions
26
src/Main.c
26
src/Main.c
|
|
@ -80,21 +80,19 @@ Main(Array *args, HashMap *env)
|
|||
ParseeExportConfigYAML(yaml);
|
||||
StreamClose(yaml);
|
||||
|
||||
Log(LOG_NOTICE, "Connecting to XMPP...");
|
||||
jabber = XMPPInitialiseCompStream(
|
||||
parsee_conf->component_host,
|
||||
parsee_conf->component_port
|
||||
);
|
||||
if (!XMPPAuthenticateCompStream(
|
||||
jabber,
|
||||
parsee_conf->shared_comp_secret
|
||||
))
|
||||
{
|
||||
Log(LOG_NOTICE, "Connecting to XMPP...");
|
||||
jabber = XMPPInitialiseCompStream(
|
||||
parsee_conf->component_host,
|
||||
parsee_conf->component_port
|
||||
);
|
||||
if (!XMPPAuthenticateCompStream(
|
||||
jabber,
|
||||
parsee_conf->shared_comp_secret
|
||||
))
|
||||
{
|
||||
Log(LOG_ERR, "Could not connect to XMPP...");
|
||||
XMPPEndCompStream(jabber);
|
||||
goto end;
|
||||
}
|
||||
Log(LOG_ERR, "Could not connect to XMPP...");
|
||||
XMPPEndCompStream(jabber);
|
||||
goto end;
|
||||
}
|
||||
|
||||
Log(LOG_NOTICE, "Creating volatile tables...");
|
||||
|
|
|
|||
|
|
@ -174,7 +174,10 @@ GetXMPPInformation(ParseeData *data, HashMap *event, char **from, char **to)
|
|||
|
||||
chat_id = ParseeGetFromRoomID(data, room_id);
|
||||
|
||||
room_data = DbLock(data->db, 3, "rooms", room_id, "data");
|
||||
room_data = DbLockIntent(data->db,
|
||||
DB_HINT_READONLY,
|
||||
3, "rooms", room_id, "data"
|
||||
);
|
||||
data_json = DbJson(room_data);
|
||||
direct = GrabBoolean(data_json, 1, "is_direct");
|
||||
type = direct ? "chat" : "groupchat";
|
||||
|
|
@ -259,17 +262,16 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
|
|||
/* TODO: This ref should be marked as read-only,
|
||||
* as LMDB doesn't seem to like having two concurrent RW
|
||||
* transactions running. */
|
||||
ref = DbLock(data->db, 3, "rooms", id, "data");
|
||||
json = JsonDuplicate(DbJson(ref));
|
||||
ref = DbLockIntent(data->db, DB_HINT_READONLY, 3, "rooms", id, "data");
|
||||
json = DbJson(ref);
|
||||
direct = JsonValueAsBoolean(HashMapGet(json, "is_direct"));
|
||||
DbUnlock(data->db, ref);
|
||||
ref = NULL;
|
||||
|
||||
if (!direct && !chat_id)
|
||||
{
|
||||
ParseeBotHandler(data, event);
|
||||
|
||||
JsonFree(json);
|
||||
DbUnlock(data->db, ref);
|
||||
ref = NULL;
|
||||
Free(chat_id);
|
||||
Free(reply_id);
|
||||
Free(xepd);
|
||||
|
|
@ -365,7 +367,8 @@ end:
|
|||
Free(unauth);
|
||||
Free(unedited_id);
|
||||
|
||||
JsonFree(json);
|
||||
DbUnlock(data->db, ref);
|
||||
ref = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -88,7 +88,10 @@ ParseeCleanup(void *datp)
|
|||
for (j = 0; j < ArraySize(field##_list); j++) \
|
||||
{ \
|
||||
char *f = ArrayGet(field##_list, j); \
|
||||
ref = DbLock(data->db, 4, "chats", chat, #field"s", f); \
|
||||
ref = DbLockIntent(data->db, \
|
||||
DB_HINT_READONLY, \
|
||||
4, "chats", chat, #field"s", f \
|
||||
); \
|
||||
HashMap *obj = DbJson(ref); \
|
||||
uint64_t age = JsonValueAsInteger(HashMapGet(obj, "age")); \
|
||||
uint64_t dur = ts - age; \
|
||||
|
|
@ -563,7 +566,10 @@ ParseeVerifyDMStanza(ParseeData *data, char *room_id, char *id)
|
|||
return true;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 3, "rooms", room_id, "data");
|
||||
ref = DbLockIntent(data->db,
|
||||
DB_HINT_READONLY,
|
||||
3, "rooms", room_id, "data"
|
||||
);
|
||||
j = DbJson(ref);
|
||||
if (!ref)
|
||||
{
|
||||
|
|
@ -584,17 +590,13 @@ end:
|
|||
bool
|
||||
ParseeVerifyStanza(ParseeData *data, char *chat_id, char *stanza_id)
|
||||
{
|
||||
DbRef *ref = NULL;
|
||||
bool ret = true;
|
||||
if (!data || !chat_id || !stanza_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 4, "chats", chat_id, "stanzas", stanza_id);
|
||||
ret = !ref;
|
||||
|
||||
DbUnlock(data->db, ref);
|
||||
ret = !DbExists(data->db, 4, "chats", chat_id, "stanzas", stanza_id);
|
||||
return ret;
|
||||
}
|
||||
char *
|
||||
|
|
|
|||
|
|
@ -323,7 +323,7 @@ ParseeFindDMRoom(ParseeData *data, char *mxid, char *jid)
|
|||
return NULL;
|
||||
}
|
||||
dmid = ParseeGetDMID(mxid, jid);
|
||||
ref = DbLock(data->db, 2, "users", dmid);
|
||||
ref = DbLockIntent(data->db, DB_HINT_READONLY, 2, "users", dmid);
|
||||
j = DbJson(ref);
|
||||
|
||||
room = StrDuplicate(JsonValueAsString(HashMapGet(j, "room")));
|
||||
|
|
@ -415,7 +415,7 @@ ParseePushMUC(ParseeData *data, char *room_id, char *jid)
|
|||
DbUnlock(data->db, ref);
|
||||
|
||||
/* Create a double-mapping */
|
||||
ref = DbLock(data->db, 1, "chats");
|
||||
ref = DbLockIntent(data->db, DB_HINT_WRITE, 1, "chats");
|
||||
if (!ref)
|
||||
{
|
||||
ref = DbCreate(data->db, 1, "chats");
|
||||
|
|
@ -446,7 +446,7 @@ ParseeGetFromMUCID(ParseeData *data, char *jid)
|
|||
|
||||
jid = ParseeTrimJID(jid);
|
||||
|
||||
ref = DbLock(data->db, 1, "chats");
|
||||
ref = DbLockIntent(data->db, DB_HINT_READONLY, 1, "chats");
|
||||
j = DbJson(ref);
|
||||
|
||||
cid = JsonValueAsString(JsonGet(j, 2, "mucs", jid));
|
||||
|
|
@ -469,7 +469,7 @@ ParseeGetFromRoomID(ParseeData *data, char *room_id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 1, "chats");
|
||||
ref = DbLockIntent(data->db, DB_HINT_READONLY, 1, "chats");
|
||||
j = DbJson(ref);
|
||||
|
||||
cid = JsonValueAsString(JsonGet(j, 2, "rooms", room_id));
|
||||
|
|
@ -490,7 +490,7 @@ ParseeGetRoomID(ParseeData *data, char *chat_id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 2, "chats", chat_id);
|
||||
ref = DbLockIntent(data->db, DB_HINT_READONLY, 2, "chats", chat_id);
|
||||
j = DbJson(ref);
|
||||
|
||||
ret = StrDuplicate(JsonValueAsString(HashMapGet(j, "room_id")));
|
||||
|
|
@ -510,7 +510,7 @@ ParseeGetMUCID(ParseeData *data, char *chat_id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 2, "chats", chat_id);
|
||||
ref = DbLockIntent(data->db, DB_HINT_READONLY, 2, "chats", chat_id);
|
||||
j = DbJson(ref);
|
||||
|
||||
ret = StrDuplicate(JsonValueAsString(HashMapGet(j, "jabber_id")));
|
||||
|
|
@ -531,7 +531,7 @@ ParseeSendPresence(ParseeData *data)
|
|||
{
|
||||
return;
|
||||
}
|
||||
ref = DbLock(data->db, 1, "chats");
|
||||
ref = DbLockIntent(data->db, DB_HINT_READONLY, 1, "chats");
|
||||
j = DbJson(ref);
|
||||
mucs = JsonValueAsObject(HashMapGet(j, "mucs"));
|
||||
|
||||
|
|
@ -558,7 +558,7 @@ ParseeGetDMStanzaInfo(ParseeData *data, char *room_id, char *ev, char **st, char
|
|||
return false;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 3, "rooms", room_id, "data");
|
||||
ref = DbLockIntent(data->db, 3, DB_HINT_READONLY, "rooms", room_id, "data");
|
||||
j = DbJson(ref);
|
||||
if (!ref)
|
||||
{
|
||||
|
|
@ -589,7 +589,7 @@ ParseeGetStanzaInfo(ParseeData *data, char *chat_id, char *ev, char **st, char *
|
|||
return false;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 4, "chats", chat_id, "events", ev);
|
||||
ref = DbLockIntent(data->db, DB_HINT_READONLY, 4, "chats", chat_id, "events", ev);
|
||||
j = DbJson(ref);
|
||||
if (!ref)
|
||||
{
|
||||
|
|
@ -615,7 +615,7 @@ ParseeGetDMOrigin(ParseeData *data, char *room_id, char *ev, char **o)
|
|||
return false;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 3, "rooms", room_id, "data");
|
||||
ref = DbLockIntent(data->db, DB_HINT_READONLY, 3, "rooms", room_id, "data");
|
||||
j = DbJson(ref);
|
||||
if (!ref)
|
||||
{
|
||||
|
|
@ -646,7 +646,7 @@ ParseeGetOrigin(ParseeData *data, char *chat_id, char *ev, char **o)
|
|||
return false;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 4, "chats", chat_id, "events", ev);
|
||||
ref = DbLockIntent(data->db, DB_HINT_READONLY, 4, "chats", chat_id, "events", ev);
|
||||
j = DbJson(ref);
|
||||
if (!ref)
|
||||
{
|
||||
|
|
@ -714,7 +714,7 @@ ParseeIsAdmin(ParseeData *data, char *user)
|
|||
return false;
|
||||
}
|
||||
|
||||
admins = DbLock(data->db, 1, "admins");
|
||||
admins = DbLockIntent(data->db, DB_HINT_READONLY, 1, "admins");
|
||||
json = DbJson(admins);
|
||||
|
||||
values = GrabArray(json, 1, "admins");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue