diff options
-rw-r--r-- | xmpp.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -17,6 +17,7 @@ */ +#define _GNU_SOURCE #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -100,6 +101,38 @@ struct addrinfo *get_addrinfo(char *domain) } /* + * Start XMPP stream via the given socket filedescriptor + * + * Returns 0 in case of success and -1 otherwise. + */ +int xmpp_start_stream(int sock_fd, char *jid, char *domainpart) +{ + const char *tmpl = "<stream:stream\ + from='%s'\ + to='%s'\ + version='1.0'\ + xml:lang='en'\ + xmlns='jabber:client'\ + xmlns:stream='http://etherx.jabber.org/streams'>"; + + char *msg; + asprintf(&msg, tmpl, jid, domainpart); + int len = strlen(msg); + + int sent = send(sock_fd, msg, len, 0); + if (sent == len) { + printf(">>> %s\n", msg); + return 0; + } else if (sent == 0) { + printf("Failed to send any bytes to server!\n"); + return -1; + } else { + printf("Could just send %d bytes of %d bytes to server!\n", sent, len); + return -1; + } +} + +/* * Initialize the network connection to the XMPP server * * TODO: Error handling is missing. @@ -131,4 +164,10 @@ void xmpp_connect(void) } else { printf("Successfully connected.\n"); } + + if (xmpp_start_stream(sock, jid, domain) == -1) { + printf("Failed to init stream!\n"); + return; + } + printf("Stream init sent.\n"); } |