diff options
| author | xengineering <me@xengineering.eu> | 2022-12-04 13:31:33 +0100 | 
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2022-12-04 13:31:33 +0100 | 
| commit | d84ad1e1d7dc8dde2a0731c639d0ef3dd56cb72d (patch) | |
| tree | bf78df896c9440fcca5af536f7694675febc02d8 | |
| parent | a985fb91e9d559f2520633f962028b856631c020 (diff) | |
| download | limox-d84ad1e1d7dc8dde2a0731c639d0ef3dd56cb72d.tar limox-d84ad1e1d7dc8dde2a0731c639d0ef3dd56cb72d.tar.zst limox-d84ad1e1d7dc8dde2a0731c639d0ef3dd56cb72d.zip | |
Implement client stream header sending
This starts the XML stream via the XMPP connection.
| -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");  } | 
