From 95fd3ea3d0916dce520e33b5d9697649f4529bee Mon Sep 17 00:00:00 2001 From: Markus Kohlhase Date: Wed, 15 Feb 2012 01:26:09 +0100 Subject: [PATCH] added host parameter; replaced tabs with whitespace --- examples/basic.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/examples/basic.c b/examples/basic.c index af36205..0a317ee 100644 --- a/examples/basic.c +++ b/examples/basic.c @@ -1,7 +1,7 @@ /* basic.c ** libstrophe XMPP client library -- basic usage example ** -** Copyright (C) 2005-2009 Collecta, Inc. +** Copyright (C) 2005-2009 Collecta, Inc. ** ** This software is provided AS-IS with no warranty, either express ** or implied. @@ -18,19 +18,19 @@ /* define a handler for connection events */ -void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, - const int error, xmpp_stream_error_t * const stream_error, - void * const userdata) +void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, + const int error, xmpp_stream_error_t * const stream_error, + void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; if (status == XMPP_CONN_CONNECT) { - fprintf(stderr, "DEBUG: connected\n"); - xmpp_disconnect(conn); + fprintf(stderr, "DEBUG: connected\n"); + xmpp_disconnect(conn); } else { - fprintf(stderr, "DEBUG: disconnected\n"); - xmpp_stop(ctx); + fprintf(stderr, "DEBUG: disconnected\n"); + xmpp_stop(ctx); } } @@ -39,17 +39,21 @@ int main(int argc, char **argv) xmpp_ctx_t *ctx; xmpp_conn_t *conn; xmpp_log_t *log; - char *jid, *pass; + char *jid, *pass, *host; /* take a jid and password on the command line */ - if (argc != 3) { - fprintf(stderr, "Usage: basic \n\n"); - return 1; + if (argc < 3 || argc > 4) { + fprintf(stderr, "Usage: basic []\n\n"); + return 1; } - + jid = argv[1]; pass = argv[2]; - + host = NULL; + + if (argc == 4) + host = argv[3]; + /* init library */ xmpp_initialize(); @@ -65,9 +69,9 @@ int main(int argc, char **argv) xmpp_conn_set_pass(conn, pass); /* initiate connection */ - xmpp_connect_client(conn, NULL, 0, conn_handler, ctx); + xmpp_connect_client(conn, host, 0, conn_handler, ctx); - /* enter the event loop - + /* enter the event loop - our connect handler will trigger an exit */ xmpp_run(ctx);