mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:45:10 +00:00
[ADD/WIP] Parsee IDs, -v flag
This commit is contained in:
parent
a8f1031a79
commit
aa9b68e02d
7 changed files with 56 additions and 13 deletions
|
|
@ -29,14 +29,14 @@ ParseeRequest(HttpServerContext *ctx, void *argp)
|
|||
|
||||
arg.stream = stream;
|
||||
|
||||
Log(LOG_NOTICE, "%s %s",
|
||||
Log(LOG_DEBUG, "%s %s",
|
||||
HttpRequestMethodToString(HttpRequestMethodGet(ctx)),
|
||||
path
|
||||
);
|
||||
|
||||
if (!HttpRouterRoute(data->router, path, &arg, (void **) &response))
|
||||
{
|
||||
Log(LOG_NOTICE, "Couldn't route %s", path);
|
||||
Log(LOG_DEBUG, "Couldn't route %s", path);
|
||||
HttpResponseStatus(ctx, HTTP_NOT_FOUND);
|
||||
JsonFree(response);
|
||||
|
||||
|
|
@ -56,8 +56,11 @@ ParseeRequest(HttpServerContext *ctx, void *argp)
|
|||
HttpSendHeaders(ctx);
|
||||
JsonEncode(response, stream, JSON_DEFAULT);
|
||||
JsonFree(response);
|
||||
return;
|
||||
}
|
||||
Log(LOG_DEBUG, "%s %s (%d)",
|
||||
HttpRequestMethodToString(HttpRequestMethodGet(ctx)),
|
||||
path, HttpResponseStatusGet(ctx)
|
||||
);
|
||||
}
|
||||
|
||||
HttpClientContext *
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ Main(Array *args, HashMap *env)
|
|||
int http = 8;
|
||||
|
||||
ArgParseStateInit(&state);
|
||||
while ((flag = ArgParse(&state, args, "gH:J:")) != -1)
|
||||
while ((flag = ArgParse(&state, args, "vgH:J:")) != -1)
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
|
|
@ -73,6 +73,9 @@ Main(Array *args, HashMap *env)
|
|||
ParseeExportConfigYAML(yaml);
|
||||
StreamClose(yaml);
|
||||
goto end;
|
||||
case 'v':
|
||||
LogConfigLevelSet(LogConfigGlobal(), LOG_DEBUG);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ParseeSetThreads(xmpp, http);
|
||||
|
|
|
|||
|
|
@ -247,6 +247,7 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
|
|||
char *sender = NULL;
|
||||
char *unedited_id = MatrixGetEdit(event);
|
||||
char *url = GrabString(event, 2, "content", "url");
|
||||
char *encoded_from = NULL;
|
||||
|
||||
bool direct = false;
|
||||
|
||||
|
|
@ -284,9 +285,13 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
|
|||
type = direct ? "chat" : "groupchat";
|
||||
user = GrabString(json, 1, "xmpp_user");
|
||||
unauth = ParseeToUnauth(data, url);
|
||||
|
||||
encoded_from = ParseeEncodeMXID(m_sender);
|
||||
xmppified_user = StrConcat(3,
|
||||
encoded_from, "@", jabber->host
|
||||
);
|
||||
if (direct)
|
||||
{
|
||||
xmppified_user = ParseeEncodeMXID(m_sender);
|
||||
to = StrDuplicate(user);
|
||||
|
||||
Free(chat_id);
|
||||
|
|
@ -300,7 +305,6 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
|
|||
{
|
||||
goto end;
|
||||
}
|
||||
xmppified_user = ParseeEncodeMXID(m_sender);
|
||||
|
||||
/* TODO: Check the name's validity.
|
||||
* Is there a good way to check for that that isn't
|
||||
|
|
@ -308,7 +312,7 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
|
|||
name = ASGetName(data->config, id, m_sender);
|
||||
rev = StrConcat(4, muc_id, "/", name, "[p]");
|
||||
|
||||
XMPPJoinMUC(jabber, xmppified_user, rev);
|
||||
XMPPJoinMUC(jabber, encoded_from, rev);
|
||||
|
||||
to = muc_id;
|
||||
|
||||
|
|
@ -342,7 +346,7 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
|
|||
char *xmpp_ident = StrRandom(32);
|
||||
builder = CreateStanzaBuilder(xmppified_user, to, xmpp_ident);
|
||||
SetStanzaType(builder, type);
|
||||
SetStanzaBody(builder, xepd ? xepd : body);
|
||||
SetStanzaBody(builder, unauth ? unauth : (xepd ? xepd : body));
|
||||
SetStanzaReply(builder, stanza, sender);
|
||||
SetStanzaLink(builder, unauth);
|
||||
SetStanzaEdit(builder, origin_id);
|
||||
|
|
@ -372,6 +376,7 @@ end:
|
|||
Free(sender);
|
||||
Free(unauth);
|
||||
Free(unedited_id);
|
||||
Free(encoded_from);
|
||||
|
||||
DbUnlock(data->db, ref);
|
||||
ref = NULL;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ ParseeData *
|
|||
ParseeInitData(XMPPComponent *comp)
|
||||
{
|
||||
ParseeData *data;
|
||||
DbRef *ref;
|
||||
if (!ParseeConfigGet())
|
||||
{
|
||||
return NULL;
|
||||
|
|
@ -39,6 +40,18 @@ ParseeInitData(XMPPComponent *comp)
|
|||
data->db = DbOpen(data->config->db_path, 0);
|
||||
}
|
||||
|
||||
if (!(ref = DbLock(data->db, 1, "info")))
|
||||
{
|
||||
char *id = StrRandom(8);
|
||||
ref = DbCreate(data->db, 1, "info");
|
||||
HashMapSet(DbJson(ref), "identifier", JsonValueString(id));
|
||||
Free(id);
|
||||
}
|
||||
|
||||
data->id = StrDuplicate(GrabString(DbJson(ref), 1, "identifier"));
|
||||
Log(LOG_DEBUG, "- Parsee ID: %s", data->id);
|
||||
DbUnlock(data->db, ref);
|
||||
|
||||
#define X_ROUTE(path, func) do {\
|
||||
if (!HttpRouterAdd(data->router, path, func))\
|
||||
{\
|
||||
|
|
@ -61,6 +74,7 @@ ParseeFreeData(ParseeData *data)
|
|||
return;
|
||||
}
|
||||
|
||||
Free(data->id);
|
||||
XMPPEndCompStream(data->jabber);
|
||||
DbClose(data->db);
|
||||
HttpRouterFree(data->router);
|
||||
|
|
@ -76,8 +90,9 @@ ParseeCleanup(void *datp)
|
|||
char *chat;
|
||||
size_t i;
|
||||
uint64_t ts = UtilTsMillis();
|
||||
size_t entries = 0;
|
||||
|
||||
Log(LOG_NOTICE, "Cleaning up...");
|
||||
Log(LOG_DEBUG, "Cleaning up...");
|
||||
|
||||
chats = DbList(data->db, 1, "chats");
|
||||
|
||||
|
|
@ -121,6 +136,7 @@ ParseeCleanup(void *datp)
|
|||
if (cleaned > threshold) \
|
||||
{ \
|
||||
DbDelete(data->db, 4, "chats", chat, #field"s", field); \
|
||||
entries++; \
|
||||
} \
|
||||
Free(field); \
|
||||
} \
|
||||
|
|
@ -174,6 +190,7 @@ ParseeCleanup(void *datp)
|
|||
if (cleaned > threshold) \
|
||||
{ \
|
||||
JsonValueFree(HashMapDelete(field##s, field)); \
|
||||
entries++; \
|
||||
} \
|
||||
Free(field); \
|
||||
} \
|
||||
|
|
@ -188,6 +205,7 @@ ParseeCleanup(void *datp)
|
|||
DbUnlock(data->db, ref);
|
||||
}
|
||||
DbListFree(chats);
|
||||
Log(LOG_DEBUG, "Cleant up %d entries...", entries);
|
||||
}
|
||||
int
|
||||
ParseeFindDatastart(char *data)
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ XMPPAuthenticateCompStream(XMPPComponent *comp, char *shared)
|
|||
stream_id = StrDuplicate(HashMapGet(ev->attrs, "id"));
|
||||
handshake = ComputeHandshake(shared, stream_id);
|
||||
|
||||
Log(LOG_NOTICE, "- sID='%s'", stream_id);
|
||||
Log(LOG_DEBUG, "- sID='%s'", stream_id);
|
||||
StreamPrintf(stream, "<handshake>%s</handshake>", handshake);
|
||||
StreamFlush(stream);
|
||||
XMLFreeEvent(ev);
|
||||
|
|
|
|||
|
|
@ -170,7 +170,10 @@ ParseeXMPPThread(void *argp)
|
|||
pthread_t *thr = &info.dispatchers[i].thr;
|
||||
info.dispatchers[i].info = &info;
|
||||
|
||||
pthread_create(thr, NULL, XMPPDispatcher, &info.dispatchers[i]);
|
||||
if (pthread_create(thr, NULL, XMPPDispatcher, &info.dispatchers[i]))
|
||||
{
|
||||
Achievement("COULDNT INITIALISE XMPP DISPATCHERS", true);
|
||||
}
|
||||
}
|
||||
|
||||
while (true)
|
||||
|
|
@ -213,15 +216,25 @@ ParseeXMPPThread(void *argp)
|
|||
}
|
||||
|
||||
info.running = false;
|
||||
Log(LOG_INFO, "Joining subthreads...");
|
||||
for (i = 0; i < info.available_dispatchers; i++)
|
||||
{
|
||||
pthread_t thr = info.dispatchers[i].thr;
|
||||
pthread_join(thr, NULL);
|
||||
if (pthread_join(thr, NULL))
|
||||
{
|
||||
Achievement("COULDNT JOIN XMPP DISPATCHER", true);
|
||||
}
|
||||
|
||||
Log(LOG_DEBUG, "- joined %d/%d...",
|
||||
i + 1, info.available_dispatchers
|
||||
);
|
||||
}
|
||||
Log(LOG_INFO, "Joined subthreads...");
|
||||
Free(info.dispatchers);
|
||||
|
||||
if (ArraySize(info.stanzas))
|
||||
{
|
||||
Log(LOG_DEBUG, "(%d unprocessed stanzas)", ArraySize(info.stanzas));
|
||||
}
|
||||
for (i = 0; i < ArraySize(info.stanzas); i++)
|
||||
{
|
||||
XMLFreeElement(ArrayGet(info.stanzas, i));
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ typedef struct ParseeData {
|
|||
XMPPComponent *jabber;
|
||||
|
||||
Db *db;
|
||||
char *id;
|
||||
} ParseeData;
|
||||
|
||||
#define GrabString(obj, ...) JsonValueAsString(JsonGet(obj, __VA_ARGS__))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue