mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:45:10 +00:00
[MOD/WIP] Try doing fallbacks
This commit is contained in:
parent
fe77906cde
commit
cc85859cca
5 changed files with 56 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Cytoplasm/Log.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <Routes.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
|
||||
#include <Parsee.h>
|
||||
#include <XML.h>
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -60,4 +60,5 @@ extern void XMPPFreeMUCInfo(MUCInfo info);
|
|||
|
||||
/* Checks if a stanza has an x-parsee element */
|
||||
extern bool XMPPIsParseeStanza(XMLElement *);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue