mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:45:10 +00:00
[MOD] Cache disco
This commit is contained in:
parent
063314b081
commit
9d9453f96a
7 changed files with 44 additions and 25 deletions
|
|
@ -69,11 +69,17 @@ ParseeInitData(XMPPComponent *comp)
|
||||||
void
|
void
|
||||||
ParseeFreeData(ParseeData *data)
|
ParseeFreeData(ParseeData *data)
|
||||||
{
|
{
|
||||||
|
char *entity;
|
||||||
|
XMLElement *disco;
|
||||||
if (!data)
|
if (!data)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (HashMapIterate(data->oid_servers, &entity, (void **) &disco))
|
||||||
|
{
|
||||||
|
XMLFreeElement(disco);
|
||||||
|
}
|
||||||
HashMapFree(data->oid_servers);
|
HashMapFree(data->oid_servers);
|
||||||
pthread_mutex_destroy(&data->oidl);
|
pthread_mutex_destroy(&data->oidl);
|
||||||
Free(data->id);
|
Free(data->id);
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ RouteHead(RouteRoot, arr, argp)
|
||||||
P("Some clicky links relating to %s:", NAME);
|
P("Some clicky links relating to %s:", NAME);
|
||||||
P("<ul>");
|
P("<ul>");
|
||||||
{
|
{
|
||||||
const char *fedi = "https://ak.ari.lt/parsee";
|
const char *fedi = "https://tengu.kappach.at/parsee";
|
||||||
const char *icon = "https://kappach.at/parsee.gif";
|
const char *icon = "https://kappach.at/parsee.gif";
|
||||||
P("<li><a href='%s'>Repository</a></li>", REPOSITORY);
|
P("<li><a href='%s'>Repository</a></li>", REPOSITORY);
|
||||||
P("<li><a href='%s'>Fediverse</a></li>", fedi);
|
P("<li><a href='%s'>Fediverse</a></li>", fedi);
|
||||||
|
|
|
||||||
|
|
@ -235,21 +235,31 @@ XMPPHasError(XMLElement *stanza, char *type)
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLElement *
|
XMLElement *
|
||||||
XMPPSendDisco(XMPPComponent *jabber, char *from, char *to)
|
XMPPSendDisco(ParseeData *data, char *from, char *to)
|
||||||
{
|
{
|
||||||
|
XMPPComponent *jabber = data ? data->jabber : NULL;
|
||||||
XMLElement *ret, *iq;
|
XMLElement *ret, *iq;
|
||||||
char *identifier;
|
char *identifier;
|
||||||
|
|
||||||
if (!jabber || !from || !to)
|
if (!data || !jabber || !from || !to)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&data->oidl);
|
||||||
|
if ((ret = HashMapGet(data->oid_servers, to)))
|
||||||
|
{
|
||||||
|
ret = XMLCopy(ret);
|
||||||
|
pthread_mutex_unlock(&data->oidl);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&data->oidl);
|
||||||
|
|
||||||
iq = XMLCreateTag("iq");
|
iq = XMLCreateTag("iq");
|
||||||
XMLAddAttr(iq, "type", "get");
|
XMLAddAttr(iq, "type", "get");
|
||||||
XMLAddAttr(iq, "from", from);
|
XMLAddAttr(iq, "from", from);
|
||||||
XMLAddAttr(iq, "to", to);
|
XMLAddAttr(iq, "to", to);
|
||||||
XMLAddAttr(iq, "id", (identifier = StrRandom(69)));
|
XMLAddAttr(iq, "id", (identifier = StrRandom(64)));
|
||||||
{
|
{
|
||||||
XMLElement *query = XMLCreateTag("query");
|
XMLElement *query = XMLCreateTag("query");
|
||||||
XMLAddAttr(query, "xmlns", "http://jabber.org/protocol/disco#info");
|
XMLAddAttr(query, "xmlns", "http://jabber.org/protocol/disco#info");
|
||||||
|
|
@ -264,6 +274,15 @@ XMPPSendDisco(XMPPComponent *jabber, char *from, char *to)
|
||||||
|
|
||||||
ret = ParseeAwaitStanza(identifier, 1.25 SECONDS);
|
ret = ParseeAwaitStanza(identifier, 1.25 SECONDS);
|
||||||
Free(identifier);
|
Free(identifier);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
/* TODO: On my own instance, disco replies are _really_ expensive.
|
||||||
|
* About 120KB. This is sad. Really sad. */
|
||||||
|
pthread_mutex_lock(&data->oidl);
|
||||||
|
XMLFreeElement(HashMapSet(data->oid_servers, to, ret));
|
||||||
|
ret = XMLCopy(ret);
|
||||||
|
pthread_mutex_unlock(&data->oidl);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
bool
|
bool
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ FormDelAdminCallback(XMPPCommandManager *m, XMPPCommand *cmd, char *from)
|
||||||
DbRef *admins;
|
DbRef *admins;
|
||||||
Array *admin_list;
|
Array *admin_list;
|
||||||
size_t i;
|
size_t i;
|
||||||
XMPPOption *admin_opt;
|
XMPPOption *admin_opt = NULL;
|
||||||
char *trimmed = ParseeTrimJID(from);
|
char *trimmed = ParseeTrimJID(from);
|
||||||
|
|
||||||
if (!ParseeIsAdmin(data, trimmed))
|
if (!ParseeIsAdmin(data, trimmed))
|
||||||
|
|
@ -104,14 +104,17 @@ FormDelAdminCallback(XMPPCommandManager *m, XMPPCommand *cmd, char *from)
|
||||||
}
|
}
|
||||||
Free(trimmed);
|
Free(trimmed);
|
||||||
|
|
||||||
admin_opt = XMPPCreateList(true, false, "glob", "[NVM!]");
|
|
||||||
|
|
||||||
admins = DbLock(data->db, 1, "admins");
|
admins = DbLock(data->db, 1, "admins");
|
||||||
admin_list = GrabArray(DbJson(admins), 1, "admins");
|
admin_list = GrabArray(DbJson(admins), 1, "admins");
|
||||||
for (i = 0; i < ArraySize(admin_list); i++)
|
for (i = 0; i < ArraySize(admin_list); i++)
|
||||||
{
|
{
|
||||||
char *glob = JsonValueAsString(ArrayGet(admin_list, i));
|
char *glob = JsonValueAsString(ArrayGet(admin_list, i));
|
||||||
|
|
||||||
|
if (!admin_opt)
|
||||||
|
{
|
||||||
|
admin_opt = XMPPCreateList(true, false, "glob", glob);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
XMPPAddListOption(admin_opt, glob);
|
XMPPAddListOption(admin_opt, glob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,26 +145,10 @@ ServerHasXEP421(ParseeData *data, char *from)
|
||||||
*(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, 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);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
* <p>TODO: Consider separating some declarations here...</p>
|
* <p>TODO: Consider separating some declarations here...</p>
|
||||||
* --------
|
* --------
|
||||||
* Writren-By: LDA */
|
* Writren-By: LDA */
|
||||||
|
typedef struct ParseeData ParseeData;
|
||||||
|
|
||||||
#include <Cytoplasm/HttpServer.h>
|
#include <Cytoplasm/HttpServer.h>
|
||||||
#include <Cytoplasm/HttpRouter.h>
|
#include <Cytoplasm/HttpRouter.h>
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,13 @@ extern void XMPPAnnotatePresence(XMLElement *presence);
|
||||||
|
|
||||||
extern bool XMPPHasError(XMLElement *stanza, char *type);
|
extern bool XMPPHasError(XMLElement *stanza, char *type);
|
||||||
|
|
||||||
extern XMLElement * XMPPSendDisco(XMPPComponent *jabber, char *from, char *to);
|
#include <Parsee.h>
|
||||||
|
/** Sends a XMPP discovery request to an entity, and caches it if possible.
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
* Returns: a valid XML element[HEAP]
|
||||||
|
* Modifies: the {data}'s cache
|
||||||
|
* Thrasher: XMLFreeElement */
|
||||||
|
extern XMLElement * XMPPSendDisco(ParseeData *data, char *from, char *to);
|
||||||
|
|
||||||
extern bool XMPPDiscoAdvertises(XMLElement *disco, char *var);
|
extern bool XMPPDiscoAdvertises(XMLElement *disco, char *var);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue