2005-02-02 Mikael Hallendal <micke@imendio.com>
* examples/lm-change-password.c: (print_usage), (main):
- Support sending --host which would be the host part of the jid if
the connect server is different.
--- a/ChangeLog Thu Jan 27 13:25:33 2005 +0000
+++ b/ChangeLog Wed Feb 02 15:55:19 2005 +0000
@@ -1,3 +1,9 @@
+2005-02-02 Mikael Hallendal <micke@imendio.com>
+
+ * examples/lm-change-password.c: (print_usage), (main):
+ - Support sending --host which would be the host part of the jid if
+ the connect server is different.
+
2005-01-27 Martyn Russell <mr@gnome.org>
* loudmouth/lm-connection.c (_lm_connection_failed_with_error):
--- a/examples/lm-change-password.c Thu Jan 27 13:25:33 2005 +0000
+++ b/examples/lm-change-password.c Wed Feb 02 15:55:19 2005 +0000
@@ -36,7 +36,7 @@
static void
print_usage (const gchar *exec_name)
{
- g_print ("Usage: %s <server> <username> <oldpassword> <newpassword> [--ssl]\n",
+ g_print ("Usage: %s <server> <username> <oldpassword> <newpassword> [--ssl] [--host <host>]\n",
exec_name);
}
@@ -48,11 +48,14 @@
const gchar *username;
const gchar *old_pass;
const gchar *new_pass;
+ const gchar *host;
GError *error = NULL;
LmMessage *m;
+ LmMessage *reply;
LmMessageNode *query;
gboolean use_ssl = FALSE;
+
if (argc < 5) {
print_usage (argv[0]);
return -1;
@@ -62,6 +65,7 @@
username = argv[2];
old_pass = argv[3];
new_pass = argv[4];
+ host = NULL;
if (argc >= 5) {
int i;
@@ -70,13 +74,31 @@
if (strcmp (argv[i], "-s") == 0 ||
strcmp (argv[i], "--ssl") == 0) {
use_ssl = TRUE;
- break;
+ }
+ else if (strcmp (argv[i], "-h") == 0 ||
+ strcmp (argv[i], "--host") == 0) {
+ if (++i >= argc) {
+ print_usage (argv[0]);
+ return -1;
+ }
+
+ host = argv[i];
+ g_print ("HOST: %s\n", host);
}
}
}
connection = lm_connection_new (server);
+ if (host) {
+ gchar *jid;
+
+ jid = g_strdup_printf ("%s@%s", username, host);
+ g_print ("Setting jid to %s\n", jid);
+ lm_connection_set_jid (connection, jid);
+ g_free (jid);
+ }
+
if (use_ssl) {
LmSSL *ssl;
@@ -114,9 +136,18 @@
NULL);
lm_message_node_add_child (query, "username", username);
lm_message_node_add_child (query, "password", new_pass);
-
- if (!lm_connection_send (connection, m, &error)) {
- g_error ("Failed to send: %s\n", error->message);
+
+ reply = lm_connection_send_with_reply_and_block (connection, m, &error);
+ if (!reply) {
+ g_error ("Failed to change password: %s\n", error->message);
+ }
+
+ if (lm_message_get_sub_type (reply) == LM_MESSAGE_SUB_TYPE_RESULT) {
+ g_print ("Password changed\n");
+ } else {
+ g_print ("Failed to change password\n");
+ /* If this wasn't only an example we should check error code
+ * here to tell the user why it failed */
}
lm_connection_close (connection, NULL);