From d84ad1e1d7dc8dde2a0731c639d0ef3dd56cb72d Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 4 Dec 2022 13:31:33 +0100 Subject: Implement client stream header sending This starts the XML stream via the XMPP connection. --- xmpp.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/xmpp.c b/xmpp.c index 240dfc1..1546cdc 100644 --- a/xmpp.c +++ b/xmpp.c @@ -17,6 +17,7 @@ */ +#define _GNU_SOURCE #include #include #include @@ -99,6 +100,38 @@ struct addrinfo *get_addrinfo(char *domain) return NULL; } +/* + * 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 = ""; + + 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 * @@ -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"); } -- cgit v1.2.3-70-g09d2