[MOD/WIP] Try doing fallbacks

This commit is contained in:
LDA 2024-06-24 02:05:11 +02:00
commit cc85859cca
5 changed files with 56 additions and 2 deletions

View file

@ -19,7 +19,7 @@ static HttpServer *server = NULL;
static pthread_t xmpp_thr; static pthread_t xmpp_thr;
static XMPPComponent *jabber = NULL; static XMPPComponent *jabber = NULL;
extern int ParseeFindDatastart(char *data);
int int
Main(void) Main(void)
{ {
@ -38,7 +38,7 @@ Main(void)
ParseeConfigLoad("parsee.json"); ParseeConfigLoad("parsee.json");
ParseeConfigInit(); ParseeConfigInit();
/* Write out the config file to a YAML document */ /* Write out the config file to a YAML document */
yaml = StreamOpen("parsee.yaml", "w"); yaml = StreamOpen("parsee.yaml", "w");
ParseeExportConfigYAML(yaml); ParseeExportConfigYAML(yaml);

View file

@ -6,6 +6,8 @@
#include <Cytoplasm/Log.h> #include <Cytoplasm/Log.h>
#include <Cytoplasm/Str.h> #include <Cytoplasm/Str.h>
#include <string.h>
#include <Routes.h> #include <Routes.h>
ParseeData * ParseeData *
@ -99,3 +101,34 @@ ParseeCleanup(void *datp)
DbListFree(chats); DbListFree(chats);
/* TODO */ /* 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);
}

View file

@ -4,6 +4,7 @@
#include <Cytoplasm/Str.h> #include <Cytoplasm/Str.h>
#include <Cytoplasm/Log.h> #include <Cytoplasm/Log.h>
#include <Parsee.h>
#include <XML.h> #include <XML.h>
void void
@ -52,11 +53,27 @@ XMPPSendPlain(XMPPComponent *comp, char *fr, char *to, char *msg, char *type, ch
if (rst && rse) if (rst && rse)
{ {
int off = ParseeFindDatastart(msg);
char *ostr = StrInt(off);
XMLElement *reply = XMLCreateTag("reply"); XMLElement *reply = XMLCreateTag("reply");
XMLElement *fallback = XMLCreateTag("fallback");
XMLElement *fall_body = XMLCreateTag("body");
XMLAddAttr(reply, "to", rse); XMLAddAttr(reply, "to", rse);
XMLAddAttr(reply, "id", rst); XMLAddAttr(reply, "id", rst);
XMLAddAttr(reply, "xmlns", "urn:xmpp:reply:0"); 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, reply);
XMLAddChild(message, fallback);
Free(ostr);
} }
XMLAddChild(message, body); XMLAddChild(message, body);

View file

@ -160,4 +160,7 @@ extern bool ParseeInitialiseSignals(HttpServer *, pthread_t, XMPPComponent *);
/* Job used to cleanup Parsee data that isn't necessary anymore. */ /* Job used to cleanup Parsee data that isn't necessary anymore. */
extern void ParseeCleanup(void *data); extern void ParseeCleanup(void *data);
/* Finds the offset of the first line without a '>' at its start. */
extern int ParseeFindDatastart(char *data);
#endif #endif

View file

@ -60,4 +60,5 @@ extern void XMPPFreeMUCInfo(MUCInfo info);
/* Checks if a stanza has an x-parsee element */ /* Checks if a stanza has an x-parsee element */
extern bool XMPPIsParseeStanza(XMLElement *); extern bool XMPPIsParseeStanza(XMLElement *);
#endif #endif