diff options
| -rw-r--r-- | xmpp.c | 25 | 
1 files changed, 23 insertions, 2 deletions
| @@ -27,6 +27,7 @@  #include <sys/socket.h>  #include <arpa/inet.h>  #include <netdb.h> +#include <stdbool.h>  /* @@ -135,6 +136,23 @@ int start_stream(int sock_fd, char *jid, char *domainpart)  }  /* + * Get JID and password and return true on success + */ +bool get_credentials(char **jid, char **pwd) +{ +	if (getenv("LIMOX_USER") == NULL || getenv("LIMOX_PWD") == NULL) { +		printf("Failed to connect.\n"); +		printf("Please set the LIMOX_USER and LIMOX_PWD shell variables.\n"); +		return false; +	} + +	*jid = getenv("LIMOX_USER"); +	*pwd = getenv("LIMOX_PWD"); + +	return true; +} + +/*   * Initialize the network connection to the XMPP server and return socket fd   *   * TODO: Error handling is missing. @@ -143,8 +161,11 @@ int xmpp_connect(void)  {  	printf("net_init()\n"); -	char *jid = getenv("LIMOX_USER"); -	char *pwd = getenv("LIMOX_PWD"); +	char *jid; +	char *pwd; +	if (!get_credentials(&jid, &pwd)) { +		return -1; +	}  	printf("Trying to connect as '%s' with '%s'.\n", jid, pwd);  	char *domain = get_domainpart(jid); | 
