From cc85859cca97b96b69e9632af3507b4bba89fe29 Mon Sep 17 00:00:00 2001 From: LDA Date: Mon, 24 Jun 2024 02:05:11 +0200 Subject: [PATCH] [MOD/WIP] Try doing fallbacks --- src/Main.c | 4 ++-- src/Parsee/Data.c | 33 +++++++++++++++++++++++++++++++++ src/XMPP/Stanza.c | 17 +++++++++++++++++ src/include/Parsee.h | 3 +++ src/include/XMPP.h | 1 + 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/Main.c b/src/Main.c index 18472c9..6be7a24 100644 --- a/src/Main.c +++ b/src/Main.c @@ -19,7 +19,7 @@ static HttpServer *server = NULL; static pthread_t xmpp_thr; static XMPPComponent *jabber = NULL; - +extern int ParseeFindDatastart(char *data); int Main(void) { @@ -38,7 +38,7 @@ Main(void) ParseeConfigLoad("parsee.json"); ParseeConfigInit(); - + /* Write out the config file to a YAML document */ yaml = StreamOpen("parsee.yaml", "w"); ParseeExportConfigYAML(yaml); diff --git a/src/Parsee/Data.c b/src/Parsee/Data.c index 74dc425..08de33e 100644 --- a/src/Parsee/Data.c +++ b/src/Parsee/Data.c @@ -6,6 +6,8 @@ #include #include +#include + #include ParseeData * @@ -99,3 +101,34 @@ ParseeCleanup(void *datp) DbListFree(chats); /* TODO */ } +int +ParseeFindDatastart(char *data) +{ + char *startline; + bool found = false; + if (!data) + { + return 0; + } + + startline = data; + while (startline) + { + char *endline = strchr(startline, '\n'); + + if (*startline != '>') + { + found = true; + break; + } + + startline = endline ? endline + 1 : NULL; + } + + if (!found) + { + return 0; + } + + return (int) (startline - data); +} diff --git a/src/XMPP/Stanza.c b/src/XMPP/Stanza.c index 73be3ba..6c765b4 100644 --- a/src/XMPP/Stanza.c +++ b/src/XMPP/Stanza.c @@ -4,6 +4,7 @@ #include #include +#include #include void @@ -52,11 +53,27 @@ XMPPSendPlain(XMPPComponent *comp, char *fr, char *to, char *msg, char *type, ch if (rst && rse) { + int off = ParseeFindDatastart(msg); + char *ostr = StrInt(off); XMLElement *reply = XMLCreateTag("reply"); + XMLElement *fallback = XMLCreateTag("fallback"); + XMLElement *fall_body = XMLCreateTag("body"); + XMLAddAttr(reply, "to", rse); XMLAddAttr(reply, "id", rst); XMLAddAttr(reply, "xmlns", "urn:xmpp:reply:0"); + + XMLAddAttr(fallback, "xmlns", "urn:xmpp:feature-fallback:0"); + XMLAddAttr(fallback, "for", "urn:xmpp:reply:0"); + + XMLAddAttr(fall_body, "start", "0"); + XMLAddAttr(fall_body, "end", ostr); + XMLAddChild(fallback, fall_body); + XMLAddChild(message, reply); + XMLAddChild(message, fallback); + + Free(ostr); } XMLAddChild(message, body); diff --git a/src/include/Parsee.h b/src/include/Parsee.h index 14cc605..14e832d 100644 --- a/src/include/Parsee.h +++ b/src/include/Parsee.h @@ -160,4 +160,7 @@ extern bool ParseeInitialiseSignals(HttpServer *, pthread_t, XMPPComponent *); /* Job used to cleanup Parsee data that isn't necessary anymore. */ extern void ParseeCleanup(void *data); + +/* Finds the offset of the first line without a '>' at its start. */ +extern int ParseeFindDatastart(char *data); #endif diff --git a/src/include/XMPP.h b/src/include/XMPP.h index b8cef94..9c3710b 100644 --- a/src/include/XMPP.h +++ b/src/include/XMPP.h @@ -60,4 +60,5 @@ extern void XMPPFreeMUCInfo(MUCInfo info); /* Checks if a stanza has an x-parsee element */ extern bool XMPPIsParseeStanza(XMLElement *); + #endif