From a1a0d9c88007a49e864f49a41d713e6e08bab11c Mon Sep 17 00:00:00 2001 From: LDA Date: Sat, 15 Jun 2024 14:51:12 +0200 Subject: [PATCH] [MOD] Continue XM{PP,L}werk. I think I'll actually geninuely start my break as soon as I'm finished with the encoder/decoder(given our current SAX lexer). --- src/XML/Parser.c | 17 ++++++++++++ src/XMPP/Component.c | 62 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 src/XML/Parser.c diff --git a/src/XML/Parser.c b/src/XML/Parser.c new file mode 100644 index 0000000..9e7e79e --- /dev/null +++ b/src/XML/Parser.c @@ -0,0 +1,17 @@ +#include + +/* TODO: The rest of all that. */ + +XMLElement * +XMLDecode(Stream *stream, bool autofree) +{ + /* TODO: Use the existing SAX parser to decode everything */ + return NULL; +} + +void +XMLEncode(Stream *stream, XMLElement *element) +{ + /* TODO: Write the entire XML element. This shouldn't be + * too hard. */ +} diff --git a/src/XMPP/Component.c b/src/XMPP/Component.c index 248f6b9..eda6270 100644 --- a/src/XMPP/Component.c +++ b/src/XMPP/Component.c @@ -1,5 +1,12 @@ #include +#include +#include +#include +#include +#include +#include + #include /* TODO: Write the stream system once we have our XML implementation @@ -15,9 +22,53 @@ Stream * XMPPInitialiseCompStream(char *host, int port) { /* TODO */ - (void) host; - (void) port; - return NULL; + int sd = -1; + struct addrinfo hints, *res, *res0; + int error; + char serv[8]; + Stream *stream; + + snprintf(serv, sizeof(serv), "%hu", port); + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + error = getaddrinfo(host, serv, &hints, &res0); + + for (res = res0; res; res = res->ai_next) + { + sd = socket(res->ai_family, res->ai_socktype, + res->ai_protocol); + + if (sd < 0) + { + continue; + } + + if (connect(sd, res->ai_addr, res->ai_addrlen) < 0) + { + close(sd); + sd = -1; + continue; + } + + break; + } + + if (sd < 0) + { + return NULL; + } + freeaddrinfo(res0); + + stream = StreamFd(sd); + if (!stream) + { + close(sd); + return NULL; + } + + return stream; } bool @@ -26,12 +77,11 @@ XMPPAuthenticateCompStream(Stream *stream, char *shared) /* TODO */ (void) stream; (void) shared; - return NULL; + return false; } void XMPPEndCompStream(Stream *stream) { - (void) stream; - return NULL; + StreamClose(stream); }