added host parameter; replaced tabs with whitespace

This commit is contained in:
Markus Kohlhase
2012-02-15 01:26:09 +01:00
parent 713cfa245a
commit 95fd3ea3d0

View File

@@ -1,7 +1,7 @@
/* basic.c /* basic.c
** libstrophe XMPP client library -- basic usage example ** 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 ** This software is provided AS-IS with no warranty, either express
** or implied. ** or implied.
@@ -18,19 +18,19 @@
/* define a handler for connection events */ /* define a handler for connection events */
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
const int error, xmpp_stream_error_t * const stream_error, const int error, xmpp_stream_error_t * const stream_error,
void * const userdata) void * const userdata)
{ {
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
if (status == XMPP_CONN_CONNECT) { if (status == XMPP_CONN_CONNECT) {
fprintf(stderr, "DEBUG: connected\n"); fprintf(stderr, "DEBUG: connected\n");
xmpp_disconnect(conn); xmpp_disconnect(conn);
} }
else { else {
fprintf(stderr, "DEBUG: disconnected\n"); fprintf(stderr, "DEBUG: disconnected\n");
xmpp_stop(ctx); xmpp_stop(ctx);
} }
} }
@@ -39,17 +39,21 @@ int main(int argc, char **argv)
xmpp_ctx_t *ctx; xmpp_ctx_t *ctx;
xmpp_conn_t *conn; xmpp_conn_t *conn;
xmpp_log_t *log; xmpp_log_t *log;
char *jid, *pass; char *jid, *pass, *host;
/* take a jid and password on the command line */ /* take a jid and password on the command line */
if (argc != 3) { if (argc < 3 || argc > 4) {
fprintf(stderr, "Usage: basic <jid> <pass>\n\n"); fprintf(stderr, "Usage: basic <jid> <pass> [<host>]\n\n");
return 1; return 1;
} }
jid = argv[1]; jid = argv[1];
pass = argv[2]; pass = argv[2];
host = NULL;
if (argc == 4)
host = argv[3];
/* init library */ /* init library */
xmpp_initialize(); xmpp_initialize();
@@ -65,9 +69,9 @@ int main(int argc, char **argv)
xmpp_conn_set_pass(conn, pass); xmpp_conn_set_pass(conn, pass);
/* initiate connection */ /* 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 */ our connect handler will trigger an exit */
xmpp_run(ctx); xmpp_run(ctx);