[MOD] Cache XEP-0421 support

This commit is contained in:
LDA 2024-08-29 23:47:31 +02:00
commit 063314b081
4 changed files with 33 additions and 3 deletions

View file

@ -27,6 +27,9 @@ ParseeInitData(XMPPComponent *comp)
data->jabber = comp; data->jabber = comp;
data->handler = CommandCreateRouter(); data->handler = CommandCreateRouter();
data->oid_servers = HashMapCreate();
pthread_mutex_init(&data->oidl, NULL);
if (data->config->db_size) if (data->config->db_size)
{ {
data->db = DbOpenLMDB(data->config->db_path, data->config->db_size); data->db = DbOpenLMDB(data->config->db_path, data->config->db_size);
@ -71,6 +74,8 @@ ParseeFreeData(ParseeData *data)
return; return;
} }
HashMapFree(data->oid_servers);
pthread_mutex_destroy(&data->oidl);
Free(data->id); Free(data->id);
XMPPEndCompStream(data->jabber); XMPPEndCompStream(data->jabber);
DbClose(data->db); DbClose(data->db);

View file

@ -48,7 +48,13 @@ GetRandomQuote(void)
"XMPP kinda sucks.", "XMPP kinda sucks.",
"Matrix kinda sucks.", "Matrix kinda sucks.",
"Throw jabs!" "Throw jabs!",
"'Won't you hold my <presence/> safe?' - Kanako",
NAME ": the federated world's little little kobashi",
"Go take a look at your stanzas!",
"Go take a look at your objects!"
}; };
const size_t count = sizeof(quotes)/sizeof(*quotes); const size_t count = sizeof(quotes)/sizeof(*quotes);

View file

@ -123,7 +123,7 @@ ServerHasXEP421(ParseeData *data, char *from)
{ {
char *server = NULL, *parsee; char *server = NULL, *parsee;
XMLElement *disco; XMLElement *disco;
bool ret; bool ret = false;
if (!data || !from) if (!data || !from)
{ {
return false; return false;
@ -138,17 +138,33 @@ ServerHasXEP421(ParseeData *data, char *from)
{ {
server++; server++;
} }
server = StrDuplicate(server);
server = StrDuplicate(server);
if (strchr(server, '/')) if (strchr(server, '/'))
{ {
*(strchr(server, '/')) = '\0'; *(strchr(server, '/')) = '\0';
} }
pthread_mutex_lock(&data->oidl);
ret = HashMapGet(data->oid_servers, server);
pthread_mutex_unlock(&data->oidl);
if (ret)
{
Log(LOG_DEBUG, "XEP-0421 is cached for '%s'", server);
Free(server);
return ret;
}
parsee = ParseeJID(data); parsee = ParseeJID(data);
disco = XMPPSendDisco(data->jabber, parsee, server); disco = XMPPSendDisco(data->jabber, parsee, server);
ret = XMPPDiscoAdvertises(disco, "urn:xmpp:occupant-id:0"); ret = XMPPDiscoAdvertises(disco, "urn:xmpp:occupant-id:0");
if (ret)
{
pthread_mutex_lock(&data->oidl);
HashMapSet(data->oid_servers, server, server);
pthread_mutex_unlock(&data->oidl);
}
XMLFreeElement(disco); XMLFreeElement(disco);
Free(parsee); Free(parsee);

View file

@ -63,6 +63,9 @@ typedef struct ParseeData {
char *id; char *id;
int verbosity; int verbosity;
HashMap *oid_servers;
pthread_mutex_t oidl;
} ParseeData; } ParseeData;
typedef struct Argument { typedef struct Argument {