about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/cmd_defs.c13
-rw-r--r--src/command/cmd_funcs.c27
-rw-r--r--src/command/cmd_funcs.h1
-rw-r--r--src/xmpp/connection.c13
-rw-r--r--src/xmpp/iq.c30
-rw-r--r--src/xmpp/stanza.c37
-rw-r--r--src/xmpp/stanza.h6
-rw-r--r--src/xmpp/xmpp.h2
-rw-r--r--tests/unittests/xmpp/stub_xmpp.c10
9 files changed, 138 insertions, 1 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 49c9bf95..3493b214 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2564,6 +2564,19 @@ static struct cmd_t command_defs[] = {
       CMD_NOEXAMPLES
     },
 
+    { "/changepassword",
+      parse_args, 0, 0, NULL,
+      CMD_NOSUBFUNCS
+      CMD_MAINFUNC(cmd_change_password)
+      CMD_NOTAGS
+      CMD_SYN(
+              "/changepassword")
+      CMD_DESC(
+              "Change password of logged in account")
+      CMD_NOARGS
+      CMD_NOEXAMPLES
+    },
+
     // NEXT-COMMAND (search helper)
 };
 
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 60b7010b..77422dc6 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -9298,3 +9298,30 @@ cmd_mam(ProfWin* window, const char* const command, gchar** args)
 
     return TRUE;
 }
+
+gboolean
+cmd_change_password(ProfWin* window, const char* const command, gchar** args)
+{
+    jabber_conn_status_t conn_status = connection_get_status();
+
+    if (conn_status != JABBER_CONNECTED) {
+        cons_show("You are not currently connected.");
+        return TRUE;
+    }
+
+    char* user = connection_get_user();
+    char* passwd = ui_ask_password(false);
+    char* confirm_passwd = ui_ask_password(true);
+
+    if (g_strcmp0(passwd, confirm_passwd) == 0) {
+        iq_register_change_password(user, passwd);
+    } else {
+        cons_show("Aborted! The new password and the confirmed password do not match.");
+    }
+
+    free(user);
+    free(passwd);
+    free(confirm_passwd);
+
+    return TRUE;
+}
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index bcd634da..5a192efb 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -159,6 +159,7 @@ gboolean cmd_charset(ProfWin* window, const char* const command, gchar** args);
 gboolean cmd_console(ProfWin* window, const char* const command, gchar** args);
 gboolean cmd_command_list(ProfWin* window, const char* const command, gchar** args);
 gboolean cmd_command_exec(ProfWin* window, const char* const command, gchar** args);
+gboolean cmd_change_password(ProfWin* window, const char* const command, gchar** args);
 
 gboolean cmd_plugins(ProfWin* window, const char* const command, gchar** args);
 gboolean cmd_plugins_sourcepath(ProfWin* window, const char* const command, gchar** args);
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index d34f9a4f..c188498c 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -451,6 +451,19 @@ connection_get_barejid(void)
     return result;
 }
 
+char*
+connection_get_user(void)
+{
+    const char* jid = connection_get_fulljid();
+    char* result;
+    result = strdup(jid);
+
+    char* split = strchr(result, '@');
+    *split = '\0';
+
+    return result;
+}
+
 void
 connection_features_received(const char* const jid)
 {
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 5012d1a5..8556d63d 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -149,6 +149,7 @@ static int _room_list_id_handler(xmpp_stanza_t* const stanza, void* const userda
 static int _command_list_result_handler(xmpp_stanza_t* const stanza, void* const userdata);
 static int _command_exec_response_handler(xmpp_stanza_t* const stanza, void* const userdata);
 static int _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
+static int _register_change_password_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
 
 static void _iq_free_room_data(ProfRoomInfoData* roominfo);
 static void _iq_free_affiliation_set(ProfPrivilegeSet* affiliation_set);
@@ -2616,3 +2617,32 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
 
     return 0;
 }
+
+void
+iq_register_change_password(const char* const user, const char* const password)
+{
+    xmpp_ctx_t* const ctx = connection_get_ctx();
+    xmpp_stanza_t* iq = stanza_change_password(ctx, user, password);
+
+    const char* id = xmpp_stanza_get_id(iq);
+    iq_id_handler_add(id, _register_change_password_result_id_handler, NULL, NULL);
+
+    iq_send_stanza(iq);
+    xmpp_stanza_release(iq);
+}
+
+static int
+_register_change_password_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
+{
+    const char* type = xmpp_stanza_get_type(stanza);
+    if (g_strcmp0(type, "error") == 0) {
+        char* error_message = stanza_get_error_message(stanza);
+        cons_show_error("Server error: %s", error_message);
+        log_debug("Password change error: %s", error_message);
+        free(error_message);
+    } else {
+        cons_show("Password successfully changed.");
+        log_debug("Password successfully changed.");
+    }
+    return 0;
+}
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 2b39a023..f13d784b 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -2739,3 +2739,40 @@ stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const s
 
     return iq;
 }
+
+xmpp_stanza_t*
+stanza_change_password(xmpp_ctx_t* ctx, const char* const user, const char* const password)
+{
+    char* id = connection_create_stanza_id();
+    xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
+
+    xmpp_stanza_t* change_password = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(change_password, STANZA_NAME_QUERY);
+    xmpp_stanza_set_ns(change_password, STANZA_NS_REGISTER);
+
+    xmpp_stanza_t* username_st = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(username_st, STANZA_NAME_USERNAME);
+    xmpp_stanza_t* username_text = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_text(username_text, user);
+    xmpp_stanza_add_child(username_st, username_text);
+    xmpp_stanza_release(username_text);
+
+    xmpp_stanza_t* password_st = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(password_st, STANZA_NAME_PASSWORD);
+    xmpp_stanza_t* password_text = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_text(password_text, password);
+    xmpp_stanza_add_child(password_st, password_text);
+    xmpp_stanza_release(password_text);
+
+    xmpp_stanza_add_child(change_password, username_st);
+    xmpp_stanza_release(username_st);
+
+    xmpp_stanza_add_child(change_password, password_st);
+    xmpp_stanza_release(password_st);
+
+    xmpp_stanza_add_child(iq, change_password);
+    xmpp_stanza_release(change_password);
+
+    return iq;
+}
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index a4ac6b33..0634f1ad 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -116,6 +116,7 @@
 #define STANZA_NAME_FIN              "fin"
 #define STANZA_NAME_LAST             "last"
 #define STANZA_NAME_AFTER            "after"
+#define STANZA_NAME_USERNAME         "username"
 
 // error conditions
 #define STANZA_NAME_BAD_REQUEST             "bad-request"
@@ -224,6 +225,7 @@
 #define STANZA_NS_MAM2                    "urn:xmpp:mam:2"
 #define STANZA_NS_EXT_GAJIM_BOOKMARKS     "xmpp:gajim.org/bookmarks"
 #define STANZA_NS_RSM                     "http://jabber.org/protocol/rsm"
+#define STANZA_NS_REGISTER                "jabber:iq:register"
 
 #define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
 
@@ -383,6 +385,8 @@ void stanza_free_caps(XMPPCaps* caps);
 
 xmpp_stanza_t* stanza_create_avatar_retrieve_data_request(xmpp_ctx_t* ctx, const char* stanza_id, const char* const item_id, const char* const jid);
 
-xmpp_stanza_t* stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const startdate, const char *const lastid);
+xmpp_stanza_t* stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const startdate, const char* const lastid);
+
+xmpp_stanza_t* stanza_change_password(xmpp_ctx_t* ctx, const char* const user, const char* const password);
 
 #endif
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index cc93c51a..d4d32836 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -186,6 +186,7 @@ char* connection_get_presence_msg(void);
 void connection_set_presence_msg(const char* const message);
 const char* connection_get_fulljid(void);
 char* connection_get_barejid(void);
+char* connection_get_user(void);
 char* connection_create_uuid(void);
 void connection_free_uuid(char* uuid);
 #ifdef HAVE_LIBMESODE
@@ -256,6 +257,7 @@ void iq_http_upload_request(HTTPUpload* upload);
 void iq_command_list(const char* const target);
 void iq_command_exec(const char* const target, const char* const command);
 void iq_mam_request(ProfChatWin* win);
+void iq_register_change_password(const char* const user, const char* const password);
 
 EntityCapabilities* caps_lookup(const char* const jid);
 void caps_close(void);
diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c
index e1b6fdd8..0a0f3fc6 100644
--- a/tests/unittests/xmpp/stub_xmpp.c
+++ b/tests/unittests/xmpp/stub_xmpp.c
@@ -62,6 +62,12 @@ connection_get_barejid(void)
     return mock_ptr_type(char*);
 }
 
+char*
+connection_get_user(void)
+{
+    return mock_ptr_type(char*);
+}
+
 const char*
 connection_get_domain(void)
 {
@@ -393,6 +399,10 @@ void
 iq_command_exec(const char* const target, const char* const command)
 {
 }
+void
+iq_register_change_password(const char* const user, const char* const password)
+{
+}
 
 // caps functions
 void
t;hut@lavabit.com> 2010-02-16 02:03:46 +0100 incremented version number and updated pydoc html files' href='/akspecs/ranger/commit/doc/pydoc/ranger.gui.displayable.html?h=v1.5.2&id=34a60763e79546e0f84e30fbcc430632f3dbb39e'>34a60763 ^
4c13e1f2 ^
34a60763 ^
4c13e1f2 ^



f07bb12f ^
62cd83ba ^
f07bb12f ^






4c13e1f2 ^















f07bb12f ^





4c13e1f2 ^
f07bb12f ^
34a60763 ^
f07bb12f ^




4c13e1f2 ^
f07bb12f ^








f07bb12f ^



4c13e1f2 ^
f07bb12f ^


62cd83ba ^

f07bb12f ^




4c13e1f2 ^
f07bb12f ^
4c13e1f2 ^

f07bb12f ^



f07bb12f ^















4c13e1f2 ^

f07bb12f ^
4c13e1f2 ^
f07bb12f ^
34a60763 ^
f07bb12f ^
34a60763 ^
f07bb12f ^
4c13e1f2 ^
f07bb12f ^

4c13e1f2 ^
62cd83ba ^
4c13e1f2 ^

f07bb12f ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294