mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-14 00:45:10 +00:00
[MOD] One-way Matrix->XMPP comms.
This is not sanitised. I need to make an XML writer.
This commit is contained in:
parent
868f0e4d9c
commit
bdb4fd2f68
17 changed files with 421 additions and 61 deletions
|
|
@ -22,7 +22,7 @@
|
|||
/* The default component port Prosody uses. */
|
||||
#define DEFAULT_PROSODY_PORT 5347
|
||||
|
||||
Stream *
|
||||
XMPPComponent *
|
||||
XMPPInitialiseCompStream(char *host, int port)
|
||||
{
|
||||
/* TODO */
|
||||
|
|
@ -31,6 +31,7 @@ XMPPInitialiseCompStream(char *host, int port)
|
|||
int error;
|
||||
char serv[8];
|
||||
Stream *stream;
|
||||
XMPPComponent *comp;
|
||||
|
||||
snprintf(serv, sizeof(serv), "%hu", port ? port : DEFAULT_PROSODY_PORT);
|
||||
|
||||
|
|
@ -74,7 +75,11 @@ XMPPInitialiseCompStream(char *host, int port)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return stream;
|
||||
comp = Malloc(sizeof(*comp));
|
||||
comp->host = StrDuplicate(host);
|
||||
comp->stream = stream;
|
||||
|
||||
return comp;
|
||||
}
|
||||
|
||||
#include <Cytoplasm/Sha.h>
|
||||
|
|
@ -95,17 +100,22 @@ ComputeHandshake(char *shared, char *stream)
|
|||
return sha;
|
||||
}
|
||||
bool
|
||||
XMPPAuthenticateCompStream(Stream *stream, char *as, char *shared)
|
||||
XMPPAuthenticateCompStream(XMPPComponent *comp, char *shared)
|
||||
{
|
||||
/* TODO */
|
||||
XMLexer *sax;
|
||||
XMLEvent *ev;
|
||||
char *stream_id, *handshake;
|
||||
bool ret = false;
|
||||
if (!stream || !as || !shared)
|
||||
Stream *stream;
|
||||
char *as;
|
||||
if (!comp || !shared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
stream = comp->stream;
|
||||
as = comp->host;
|
||||
StreamPrintf(stream,
|
||||
"<stream:stream "
|
||||
"xmlns='jabber:component:accept' "
|
||||
|
|
@ -171,7 +181,13 @@ end:
|
|||
}
|
||||
|
||||
void
|
||||
XMPPEndCompStream(Stream *stream)
|
||||
XMPPEndCompStream(XMPPComponent *comp)
|
||||
{
|
||||
StreamClose(stream);
|
||||
if (!comp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StreamClose(comp->stream);
|
||||
Free(comp->host);
|
||||
Free(comp);
|
||||
}
|
||||
|
|
|
|||
43
src/XMPP/Stanza.c
Normal file
43
src/XMPP/Stanza.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include <XMPP.h>
|
||||
|
||||
void
|
||||
XMPPSendPlain(XMPPComponent *comp, char *fr, char *to, char *msg, char *type)
|
||||
{
|
||||
if (!comp || !fr || !to || !msg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StreamPrintf(
|
||||
comp->stream, "<message from='%s@%s' to='%s'",
|
||||
fr, comp->host, to
|
||||
);
|
||||
if (type)
|
||||
{
|
||||
StreamPrintf(comp->stream, " type='%s'", type);
|
||||
}
|
||||
StreamPrintf(comp->stream, ">");
|
||||
StreamPrintf(comp->stream,
|
||||
"<body>"
|
||||
"%s"
|
||||
"</body>"
|
||||
"</message>",
|
||||
msg
|
||||
);
|
||||
StreamFlush(comp->stream);
|
||||
}
|
||||
void
|
||||
XMPPSendPresence(XMPPComponent *comp, char *fr, char *to)
|
||||
{
|
||||
if (!comp || !fr || !to)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StreamPrintf(comp->stream,
|
||||
"<presence from='%s@%s' to='%s'>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc'/>"
|
||||
"</presence>",
|
||||
fr, comp->host,
|
||||
to
|
||||
);
|
||||
StreamFlush(comp->stream);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue