diff options
author | Sjoerd Simons <sjoerd.simons@collabora.co.uk> | 2009-05-18 17:20:31 +0100 |
---|---|---|
committer | Sjoerd Simons <sjoerd.simons@collabora.co.uk> | 2009-05-18 17:20:31 +0100 |
commit | d00206a4b16948abfbd9f21a370963fedbd4e3bd (patch) | |
tree | da1c4b3f248b297d6b24129261186c1bc1ebaa1f /examples | |
parent | d920590317e61e13d326bf01f480c0fce8521378 (diff) |
Make the example a bit more friendly to use
Diffstat (limited to 'examples')
-rw-r--r-- | examples/connect.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/examples/connect.c b/examples/connect.c index 2ca26fb..f7bfe82 100644 --- a/examples/connect.c +++ b/examples/connect.c @@ -354,17 +354,34 @@ int main (int argc, char **argv) { + gchar *jid; + char *c; + g_type_init (); - g_assert (argc == 4); + if (argc != 3) + { + printf ("Usage: %s <jid> <password>\n", argv[0]); + return -1; + } mainloop = g_main_loop_new (NULL, FALSE); client = g_tcp_client_new (); - server = argv[1]; - username = argv[2]; - password = argv[3]; + jid = g_strdup (argv[1]); + password = argv[2]; + + c = rindex (jid, '@'); + if (c == NULL) + { + printf ("JID should contain an @ sign\n"); + return -1; + } + *c = '\0'; + + server = c + 1; + username = jid; printf ("Connecting to %s\n", server); @@ -372,5 +389,7 @@ main (int argc, "xmpp-client", NULL, tcp_srv_connected, NULL); g_main_loop_run (mainloop); + + g_free (jid); return 0; } |