* examples/lm-send-async.c:
authormr <mr>
Tue, 22 Aug 2006 23:33:06 +0000
changeset 167 7bcccfa734e2
parent 166 2e6fae54b2fb
child 168 ac1affcd5d22
* 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.
ChangeLog
examples/lm-send-async.c
examples/lm-send-sync.c
examples/test-lm.c
--- 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  <martyn@imendio.com>
+
+	* 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  <micke@imendio.com>
 
 	* loudmouth/lm-message-node.c: (lm_message_node_to_string):
--- 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;
--- 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);
--- 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,