diff --git a/src/HttParsee.c b/src/HttParsee.c index d6fd86b..1f9ade9 100644 --- a/src/HttParsee.c +++ b/src/HttParsee.c @@ -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 * diff --git a/src/Main.c b/src/Main.c index 226a9e4..ced6c59 100644 --- a/src/Main.c +++ b/src/Main.c @@ -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); diff --git a/src/MatrixEventHandler.c b/src/MatrixEventHandler.c index ce24854..f8dddc5 100644 --- a/src/MatrixEventHandler.c +++ b/src/MatrixEventHandler.c @@ -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; diff --git a/src/Parsee/Data.c b/src/Parsee/Data.c index e92e3e4..855f401 100644 --- a/src/Parsee/Data.c +++ b/src/Parsee/Data.c @@ -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) diff --git a/src/XMPP/Component.c b/src/XMPP/Component.c index e32c921..abf255c 100644 --- a/src/XMPP/Component.c +++ b/src/XMPP/Component.c @@ -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, "%s", handshake); StreamFlush(stream); XMLFreeEvent(ev); diff --git a/src/XMPPThread/ReListener.c b/src/XMPPThread/ReListener.c index 85bcc44..62ff10b 100644 --- a/src/XMPPThread/ReListener.c +++ b/src/XMPPThread/ReListener.c @@ -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)); diff --git a/src/include/Parsee.h b/src/include/Parsee.h index a98913c..a7c6fe4 100644 --- a/src/include/Parsee.h +++ b/src/include/Parsee.h @@ -55,6 +55,7 @@ typedef struct ParseeData { XMPPComponent *jabber; Db *db; + char *id; } ParseeData; #define GrabString(obj, ...) JsonValueAsString(JsonGet(obj, __VA_ARGS__))