2
0
mirror of https://github.com/msantos/xmppipe synced 2024-11-13 13:10:32 +00:00

Exit on connection failure

No point shutting down nicely if the connection has failed: exit
immediately and print out an error.

The error is the same whether the connection has failed due to a DNS
lookup, TCP connection or authentication failure. Running in debug mode
can show the reason for failure. libstrophe has an enum indicating the
connection state; maybe this can be used for better error reporting.
This commit is contained in:
Michael Santos 2015-05-15 10:00:38 -04:00
parent 353951298e
commit c983814007

View File

@ -55,6 +55,7 @@ main(int argc, char **argv)
char *pass = NULL;
int ch = 0;
int exit_status = 0;
state = xmppipe_calloc(1, sizeof(xmppipe_state_t));
@ -162,20 +163,19 @@ main(int argc, char **argv)
xmpp_connect_client(conn, NULL, 0, handle_connection, state);
if (xmppipe_connect_init(state) < 0)
goto XMPPIPE_ERR;
errx(EXIT_FAILURE, "connection failed");
if (xmppipe_muc_init(state) < 0)
goto XMPPIPE_ERR;
errx(EXIT_FAILURE, "failed to join MUC");
if (xmppipe_presence_init(state) < 0)
goto XMPPIPE_ERR;
errx(EXIT_FAILURE, "publishing presence failed");
if (state->subject)
xmppipe_muc_subject(state, state->subject);
event_loop(state);
XMPPIPE_ERR:
xmpp_conn_release(conn);
xmpp_ctx_free(state->ctx);
xmpp_shutdown();