diff --git a/README.MD b/README.MD index 2e5ca04..ce9d4b5 100644 --- a/README.MD +++ b/README.MD @@ -42,6 +42,8 @@ TODO we _might_ just manage to get some system that can at least emulate that, and hopefully be reasonably faster than the filesystem, with some added reliability. + - You can always concat paths, and search by prefix with LMDB. ~512 bytes + a key is more than enough. I'll just need to write a good abstraction layer. - Get rid of the '?'-syntax and use another invalid Matrix char/valid XMPP char ('$'?) for escaped diff --git a/src/Main.c b/src/Main.c index 2d18397..66479fc 100644 --- a/src/Main.c +++ b/src/Main.c @@ -75,6 +75,7 @@ Main(void) Log(LOG_NOTICE, "Creating volatile tables..."); ParseeInitialiseJIDTable(); + ParseeInitialiseOIDTable(); ParseeInitialiseHeadTable(); Log(LOG_NOTICE, "Setting up local Matrix user..."); @@ -125,6 +126,7 @@ end: CronStop(cron); CronFree(cron); ParseeFreeData(conf.handlerArgs); + ParseeDestroyOIDTable(); ParseeDestroyHeadTable(); ParseeDestroyJIDTable(); return 0; diff --git a/src/Parsee/JIDTable.c b/src/Parsee/JIDTable.c index c2b98de..772b975 100644 --- a/src/Parsee/JIDTable.c +++ b/src/Parsee/JIDTable.c @@ -129,3 +129,66 @@ ParseeDestroyHeadTable(void) pthread_mutex_unlock(&head_lock); pthread_mutex_destroy(&head_lock); } + + +static pthread_mutex_t oid_lock; +static HashMap *oid_table = NULL; + +void +ParseeInitialiseOIDTable(void) +{ + if (oid_table) + { + return; + } + pthread_mutex_init(&oid_lock, NULL); + pthread_mutex_lock(&oid_lock); + oid_table = HashMapCreate(); + pthread_mutex_unlock(&oid_lock); +} +void +ParseePushOIDTable(char *muc, char *bare) +{ + if (!muc || !bare || !oid_table) + { + return; + } + pthread_mutex_lock(&oid_lock); + bare = StrDuplicate(bare); + Free(HashMapSet(oid_table, muc, bare)); + pthread_mutex_unlock(&oid_lock); +} +char * +ParseeLookupOID(char *muc) +{ + char *bare; + if (!muc || !oid_table) + { + return NULL; + } + pthread_mutex_lock(&oid_lock); + bare = StrDuplicate(HashMapGet(oid_table, muc)); + pthread_mutex_unlock(&oid_lock); + + return bare; +} +void +ParseeDestroyOIDTable(void) +{ + char *key; + void *val; + if (!oid_table) + { + return; + } + pthread_mutex_lock(&oid_lock); + while (HashMapIterate(oid_table, &key, &val)) + { + Free(val); + } + HashMapFree(oid_table); + oid_table = NULL; + pthread_mutex_unlock(&oid_lock); + pthread_mutex_destroy(&oid_lock); +} + diff --git a/src/XMPPThread/Bridged.c b/src/XMPPThread/Bridged.c index 3685c64..f14732b 100644 --- a/src/XMPPThread/Bridged.c +++ b/src/XMPPThread/Bridged.c @@ -5,6 +5,8 @@ #include #include +#include + #include char * @@ -193,7 +195,7 @@ char * ParseeGetBridgedUserI(ParseeData *data, XMLElement *stanza, char *force) { char *user, *xmpp_from, *type; - char *decode_from, *occ_id = NULL; + char *decode_from, *occ_id = NULL, *looked = NULL; bool is_chat, has_anon = false, is_anon = false; if (!data || !stanza) @@ -209,10 +211,10 @@ ParseeGetBridgedUserI(ParseeData *data, XMLElement *stanza, char *force) if (!is_chat) { has_anon = ServerHasXEP421(data, xmpp_from); - is_anon = has_anon && StrEquals(xmpp_from, decode_from); + is_anon = has_anon;// && StrEquals(xmpp_from, decode_from); } - if (is_anon) + if (is_anon || force) { XMLElement *occupant; occupant = XMLookForTKV( @@ -220,6 +222,15 @@ ParseeGetBridgedUserI(ParseeData *data, XMLElement *stanza, char *force) "xmlns", "urn:xmpp:occupant-id:0" ); occ_id = occupant ? HashMapGet(occupant->attrs, "id") : NULL; + if (!occ_id) + { + occ_id = ParseeLookupOID(xmpp_from); + looked = occ_id; + } + else + { + ParseePushOIDTable(xmpp_from, occ_id); + } } if (!occ_id) @@ -230,9 +241,11 @@ ParseeGetBridgedUserI(ParseeData *data, XMLElement *stanza, char *force) type ? is_chat : false ); Free(decode_from); + Free(looked); return user; } Free(decode_from); + Free(looked); return ScrambleOID(data, occ_id); } diff --git a/src/XMPPThread/Stanzas/IQ.c b/src/XMPPThread/Stanzas/IQ.c index f0014c9..c219142 100644 --- a/src/XMPPThread/Stanzas/IQ.c +++ b/src/XMPPThread/Stanzas/IQ.c @@ -248,7 +248,7 @@ IQResult(ParseeData *args, XMLElement *stanza, XMPPThread *thr) /* TODO: More reliable system for telling the difference appart */ if (jid && !StrEquals(from, resource)) { - from_matrix = ParseeEncodeJID(args->config, jid, false); + from_matrix = ParseeGetBridgedUserI(args, stanza, jid); ASSetAvatar(args->config, from_matrix, mxc); } else if (room) diff --git a/src/include/Parsee.h b/src/include/Parsee.h index 5eec8e3..483109e 100644 --- a/src/include/Parsee.h +++ b/src/include/Parsee.h @@ -203,6 +203,11 @@ extern char * ParseeDMEventFromSID(ParseeData *d, char *r_id, char *ori_id); /* Gets a Parsee "shim" link to an MXC, usable as unauth for a limited time */ extern char * ParseeToUnauth(ParseeData *data, char *mxc); +extern void ParseeInitialiseOIDTable(void); +extern void ParseePushOIDTable(char *muc, char *occupant); +extern char *ParseeLookupOID(char *muc); +extern void ParseeDestroyOIDTable(void); + extern void ParseeInitialiseJIDTable(void); extern void ParseePushJIDTable(char *muc, char *bare); extern char *ParseeLookupJID(char *muc);