2004-11-08 Mikael Hallendal <micke@imendio.com>
authorhallski <hallski>
Mon, 08 Nov 2004 13:21:52 +0000
changeset 104 f43fde0f89d4
parent 103 a0341fcc670d
child 105 9eafd0e8c702
2004-11-08 Mikael Hallendal <micke@imendio.com> * examples/lm-change-password.c: Added SSL support * examples/lm-register.c: Added SSL support
.cvsignore
ChangeLog
examples/.cvsignore
examples/lm-change-password.c
examples/lm-register.c
--- a/.cvsignore	Sat Oct 30 23:09:41 2004 +0000
+++ b/.cvsignore	Mon Nov 08 13:21:52 2004 +0000
@@ -12,3 +12,4 @@
 loudmouth.spec
 stamp-h*
 loudmouth-1.0.pc
+*.swp
--- a/ChangeLog	Sat Oct 30 23:09:41 2004 +0000
+++ b/ChangeLog	Mon Nov 08 13:21:52 2004 +0000
@@ -1,3 +1,8 @@
+2004-11-08  Mikael Hallendal  <micke@imendio.com>
+
+	* examples/lm-change-password.c: Added SSL support
+	* examples/lm-register.c: Added SSL support
+
 2004-10-31  Mikael Hallendal  <micke@imendio.com>
 
 	* Release 0.17.2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/.cvsignore	Mon Nov 08 13:21:52 2004 +0000
@@ -0,0 +1,10 @@
+Makefile
+Makefile.in
+lm-change-password
+lm-register
+lm-send-async
+lm-send-sync
+test-http-proxy
+test-lm
+test-tunnel
+*.swp
--- a/examples/lm-change-password.c	Sat Oct 30 23:09:41 2004 +0000
+++ b/examples/lm-change-password.c	Mon Nov 08 13:21:52 2004 +0000
@@ -23,11 +23,20 @@
  */
 
 #include <loudmouth/loudmouth.h>
+#include <string.h>
+
+static LmSSLResponse 
+ssl_func (LmSSL        *ssl,
+	  LmSSLStatus   status,
+	  gpointer      user_data)
+{
+	return LM_SSL_RESPONSE_CONTINUE;
+}
 
 static void
 print_usage (const gchar *exec_name)
 {
-	g_print ("Usage: %s <server> <username> <oldpassword> <newpassword>\n",
+	g_print ("Usage: %s <server> <username> <oldpassword> <newpassword> [--ssl]\n",
 		 exec_name);
 }
 
@@ -42,7 +51,8 @@
 	GError        *error = NULL;
 	LmMessage     *m;
 	LmMessageNode *query;
-
+	gboolean       use_ssl = FALSE;
+	
 	if (argc < 5) {
 		print_usage (argv[0]);
 		return -1;
@@ -53,8 +63,37 @@
 	old_pass = argv[3];
 	new_pass = argv[4];
 
+	if (argc >= 5) {
+		int i;
+
+		for (i = 5; i < argc; ++i) {
+			if (strcmp (argv[i], "-s") == 0 ||
+			    strcmp (argv[i], "--ssl") == 0) {
+				use_ssl = TRUE;
+				break;
+			}
+		}
+	}
+
 	connection = lm_connection_new (server);
 
+	if (use_ssl) {
+		LmSSL *ssl;
+
+		if (!lm_ssl_is_supported ()) {
+			g_print ("This loudmouth installation doesn't support SSL\n");
+			return 1;
+		}
+
+		g_print ("Setting ssl\n");
+		ssl = lm_ssl_new (NULL, ssl_func, NULL, NULL);
+		lm_connection_set_ssl (connection, ssl);
+		lm_ssl_unref (ssl);
+
+		lm_connection_set_port (connection,
+					LM_CONNECTION_DEFAULT_PORT_SSL);
+	}
+
 	if (!lm_connection_open_and_block (connection, &error)) {
 		g_error ("Failed to open: %s\n", error->message);
 	}
--- a/examples/lm-register.c	Sat Oct 30 23:09:41 2004 +0000
+++ b/examples/lm-register.c	Mon Nov 08 13:21:52 2004 +0000
@@ -23,11 +23,20 @@
  */
 
 #include <loudmouth/loudmouth.h>
+#include <string.h>
+
+static LmSSLResponse 
+ssl_func (LmSSL        *ssl,
+	  LmSSLStatus   status,
+	  gpointer      user_data)
+{
+	return LM_SSL_RESPONSE_CONTINUE;
+}
 
 static void
 print_usage (const gchar *exec_name)
 {
-        g_print ("Usage: %s <server> <username> <password>\n",
+        g_print ("Usage: %s <server> <username> <password> [--ssl]\n",
                  exec_name);
 }
 
@@ -41,6 +50,7 @@
         GError        *error = NULL;
         LmMessage     *m, *reply;
         LmMessageNode *query, *node;
+	gboolean       use_ssl = FALSE;
 
         if (argc < 4) {
                 print_usage (argv[0]);
@@ -51,8 +61,37 @@
         username = argv[2];
         pass = argv[3];
 
+	if (argc >= 4) {
+		int i;
+
+		for (i = 4; i < argc; ++i) {
+			if (strcmp (argv[i], "-s") == 0 ||
+			    strcmp (argv[i], "--ssl") == 0) {
+				use_ssl = TRUE;
+				break;
+			}
+		}
+	}
+
         connection = lm_connection_new (server);
 
+	if (use_ssl) {
+		LmSSL *ssl;
+
+		if (!lm_ssl_is_supported ()) {
+			g_print ("This loudmouth installation doesn't support SSL\n");
+			return 1;
+		}
+
+		g_print ("Setting ssl\n");
+		ssl = lm_ssl_new (NULL, ssl_func, NULL, NULL);
+		lm_connection_set_ssl (connection, ssl);
+		lm_ssl_unref (ssl);
+
+		lm_connection_set_port (connection,
+					LM_CONNECTION_DEFAULT_PORT_SSL);
+	}
+
         if (!lm_connection_open_and_block (connection, &error)) {
                 g_error ("Failed to open: %s\n", error->message);
         }