# HG changeset patch # User mr # Date 1156289586 0 # Node ID 7bcccfa734e25e1566da9404eba0928aa4f4ce35 # Parent 2e6fae54b2fb8adf0f8738ce09634aaa6e64746d * examples/lm-send-async.c: * examples/lm-send-sync.c: * examples/test-lm.c: Make use of lm_connection_set_jid() and make sure we only use the part before the '@' for the username when authenticating, this means that these test clients will now work with GoogleTalk. diff -r 2e6fae54b2fb -r 7bcccfa734e2 ChangeLog --- a/ChangeLog Tue Aug 22 17:57:59 2006 +0000 +++ b/ChangeLog Tue Aug 22 23:33:06 2006 +0000 @@ -1,3 +1,12 @@ +2006-08-23 Martyn Russell + + * examples/lm-send-async.c: + * examples/lm-send-sync.c: + * examples/test-lm.c: Make use of lm_connection_set_jid() and make + sure we only use the part before the '@' for the username when + authenticating, this means that these test clients will now work + with GoogleTalk. + 2006-08-22 Mikael Hallendal * loudmouth/lm-message-node.c: (lm_message_node_to_string): diff -r 2e6fae54b2fb -r 7bcccfa734e2 examples/lm-send-async.c --- a/examples/lm-send-async.c Tue Aug 22 17:57:59 2006 +0000 +++ b/examples/lm-send-async.c Tue Aug 22 23:33:06 2006 +0000 @@ -66,6 +66,21 @@ { NULL } }; +static gchar * +get_part_name (const gchar *username) +{ + const gchar *ch; + + g_return_val_if_fail (username != NULL, NULL); + + ch = strchr (username, '@'); + if (!ch) { + return NULL; + } + + return g_strndup (username, ch - username); +} + static void print_finger (const char *fpr, unsigned int size) @@ -159,15 +174,21 @@ gpointer user_data) { if (success) { - if (!lm_connection_authenticate (connection, username, + gchar *user; + + user = get_part_name (username); + if (!lm_connection_authenticate (connection, user, password, resource, connection_auth_cb, NULL, FALSE, NULL)) { + g_free (user); g_printerr ("LmSendAsync: Failed to send authentication\n"); g_main_loop_quit (main_loop); return; } - + + g_free (user); + g_print ("LmSendAsync: Sent authentication message\n"); } else { g_printerr ("LmSendAsync: Failed to connect\n"); @@ -192,9 +213,15 @@ return EXIT_FAILURE; } + if (username && strchr (username, '@') == NULL) { + g_printerr ("LmSendAsync: Username must have an '@' included\n"); + return EXIT_FAILURE; + } + main_context = g_main_context_new (); connection = lm_connection_new_with_context (server, main_context); lm_connection_set_port (connection, port); + lm_connection_set_jid (connection, username); if (fingerprint) { LmSSL *ssl; diff -r 2e6fae54b2fb -r 7bcccfa734e2 examples/lm-send-sync.c --- a/examples/lm-send-sync.c Tue Aug 22 17:57:59 2006 +0000 +++ b/examples/lm-send-sync.c Tue Aug 22 23:33:06 2006 +0000 @@ -63,6 +63,21 @@ { NULL } }; +static gchar * +get_part_name (const gchar *username) +{ + const gchar *ch; + + g_return_val_if_fail (username != NULL, NULL); + + ch = strchr (username, '@'); + if (!ch) { + return NULL; + } + + return g_strndup (username, ch - username); +} + static void print_finger (const char *fpr, unsigned int size) @@ -125,6 +140,7 @@ GError *error = NULL; LmConnection *connection; LmMessage *m; + gchar *user; context = g_option_context_new ("- test send message synchronously"); g_option_context_add_main_entries (context, entries, NULL); @@ -136,8 +152,14 @@ return EXIT_FAILURE; } + if (username && strchr (username, '@') == NULL) { + g_printerr ("LmSendSync: Username must have an '@' included\n"); + return EXIT_FAILURE; + } + connection = lm_connection_new (server); lm_connection_set_port (connection, port); + lm_connection_set_jid (connection, username); if (fingerprint) { LmSSL *ssl; @@ -166,12 +188,15 @@ return EXIT_FAILURE; } + user = get_part_name (username); if (!lm_connection_authenticate_and_block (connection, - username, password, resource, + user, password, resource, &error)) { + g_free (user); g_printerr ("LmSendSync: Failed to authenticate: %s\n", error->message); return EXIT_FAILURE; } + g_free (user); m = lm_message_new (recipient, LM_MESSAGE_TYPE_MESSAGE); lm_message_node_add_child (m->node, "body", message); diff -r 2e6fae54b2fb -r 7bcccfa734e2 examples/test-lm.c --- a/examples/test-lm.c Tue Aug 22 17:57:59 2006 +0000 +++ b/examples/test-lm.c Tue Aug 22 23:33:06 2006 +0000 @@ -55,6 +55,21 @@ { NULL } }; +static gchar * +get_part_name (const gchar *username) +{ + const gchar *ch; + + g_return_val_if_fail (username != NULL, NULL); + + ch = strchr (username, '@'); + if (!ch) { + return NULL; + } + + return g_strndup (username, ch - username); +} + static void print_finger (const char *fpr, unsigned int size) @@ -141,10 +156,14 @@ gpointer user_data) { if (success) { - lm_connection_authenticate (connection, username, + gchar *user; + + user = get_part_name (username); + lm_connection_authenticate (connection, user, password, resource, connection_auth_cb, NULL, FALSE, NULL); + g_free (user); g_print ("TestLM: Sent authentication message\n"); } else { @@ -218,8 +237,14 @@ return EXIT_FAILURE; } + if (username && strchr (username, '@') == NULL) { + g_printerr ("TestLM: Username must have an '@' included\n"); + return EXIT_FAILURE; + } + connection = lm_connection_new (server); lm_connection_set_port (connection, port); + lm_connection_set_jid (connection, username); handler = lm_message_handler_new (handle_messages, NULL, NULL); lm_connection_register_message_handler (connection, handler,