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