Mercurial > hg
annotate mcabber/src/xmpp_iq.c @ 1617:9ca672ee884f
Fix previous commit :)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 11 Oct 2009 22:47:12 +0200 |
parents | 171ae5a258fa |
children | e38300775548 |
rev | line source |
---|---|
1599 | 1 /* |
2 * xmpp_iq.c -- Jabber protocol IQ-related stuff | |
3 * | |
4 * Copyright (C) 2008-2009 Frank Zschockelt <mcabber@freakysoft.de> | |
5 * Copyright (C) 2005-2009 Mikael Berthe <mikael@lilotux.net> | |
6 * Parts come from the centericq project: | |
7 * Copyright (C) 2002-2005 by Konstantin Klyagin <konst@konst.org.ua> | |
8 * Some small parts come from the Pidgin project <http://pidgin.im/> | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or (at | |
13 * your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, but | |
16 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 * General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
23 * USA | |
24 */ | |
1598 | 25 |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
26 #include <string.h> |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
27 #include <sys/utsname.h> |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
28 |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
29 #include "xmpp_helper.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
30 #include "commands.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
31 #include "screen.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
32 #include "utils.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
33 #include "logprint.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
34 #include "settings.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
35 #include "caps.h" |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
36 |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
37 extern struct xmpp_error xmpp_errors[]; |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
38 |
1598 | 39 static LmHandlerResult handle_iq_command_set_status(LmMessageHandler *h, |
40 LmConnection *c, | |
41 LmMessage *m, | |
42 gpointer ud); | |
29 | 43 |
1598 | 44 static LmHandlerResult handle_iq_command_leave_groupchats(LmMessageHandler *h, |
45 LmConnection *c, | |
46 LmMessage *m, | |
47 gpointer ud); | |
29 | 48 |
1598 | 49 inline double seconds_since_last_use(void); |
29 | 50 |
1598 | 51 struct adhoc_command { |
52 char *name; | |
53 char *description; | |
54 bool only_for_self; | |
55 LmHandleMessageFunction callback; | |
1378 | 56 }; |
57 | |
1598 | 58 const struct adhoc_command adhoc_command_list[] = { |
59 { "http://jabber.org/protocol/rc#set-status", | |
60 "Change client status", | |
61 1, | |
62 &handle_iq_command_set_status }, | |
63 { "http://jabber.org/protocol/rc#leave-groupchats", | |
64 "Leave groupchat(s)", | |
65 1, | |
66 &handle_iq_command_leave_groupchats }, | |
67 { NULL, NULL, 0, NULL }, | |
68 }; | |
1383 | 69 |
1598 | 70 struct adhoc_status { |
71 char *name; // the name used by adhoc | |
72 char *description; | |
73 char *status; // the string, used by setstus | |
74 }; | |
75 // It has to match imstatus of roster.h! | |
76 const struct adhoc_status adhoc_status_list[] = { | |
77 {"offline", "Offline", "offline"}, | |
78 {"online", "Online", "avail"}, | |
79 {"chat", "Chat", "free"}, | |
80 {"dnd", "Do not disturb", "dnd"}, | |
81 {"xd", "Extended away", "notavail"}, | |
82 {"away", "Away", "away"}, | |
83 {"invisible", "Invisible", "invisible"}, | |
84 {NULL, NULL, NULL}, | |
85 }; | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
86 |
1598 | 87 static char *generate_session_id(char *prefix) |
29 | 88 { |
1598 | 89 char *result; |
90 static int counter = 0; | |
91 counter++; | |
92 // TODO better use timestamp? | |
93 result = g_strdup_printf("%s-%i", prefix, counter); | |
94 return result; | |
29 | 95 } |
96 | |
1598 | 97 static LmMessage *lm_message_new_iq_error(LmMessage *m, guint error) |
29 | 98 { |
1598 | 99 LmMessage *r; |
100 LmMessageNode *err; | |
101 int i; | |
102 | |
103 for (i = 0; xmpp_errors[i].code; ++i) | |
104 if (xmpp_errors[i].code == error) | |
105 break; | |
106 g_return_val_if_fail(xmpp_errors[i].code > 0, NULL); | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
107 |
1598 | 108 r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_ERROR); |
109 err = lm_message_node_add_child(r->node, "error", NULL); | |
110 lm_message_node_set_attribute(err, "code", xmpp_errors[i].code_str); | |
111 lm_message_node_set_attribute(err, "type", xmpp_errors[i].type); | |
112 lm_message_node_set_attribute | |
113 (lm_message_node_add_child(err, | |
114 xmpp_errors[i].condition, NULL), | |
115 "xmlns", NS_XMPP_STANZAS); | |
634
f3c05d5fe459
Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
633
diff
changeset
|
116 |
1598 | 117 return r; |
436 | 118 } |
119 | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
120 void send_iq_error(LmConnection *c, LmMessage *m, guint error) |
1001
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
121 { |
1598 | 122 LmMessage *r; |
123 r = lm_message_new_iq_error(m, error); | |
124 lm_connection_send(c, r, NULL); | |
125 lm_message_unref(r); | |
1001
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
126 } |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
127 |
1598 | 128 static void lm_message_node_add_dataform_result(LmMessageNode *node, |
129 const char *message) | |
29 | 130 { |
1598 | 131 LmMessageNode *x, *field; |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
132 |
1598 | 133 x = lm_message_node_add_child(node, "x", NULL); |
134 lm_message_node_set_attributes(x, | |
135 "type", "result", | |
136 "xmlns", "jabber:x:data", | |
137 NULL); | |
138 field = lm_message_node_add_child(x, "field", NULL); | |
139 lm_message_node_set_attributes(field, | |
140 "type", "text-single", | |
141 "var", "message", | |
142 NULL); | |
143 lm_message_node_add_child(field, "value", message); | |
144 } | |
1439
fd09c95bc2b5
Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents:
1435
diff
changeset
|
145 |
1598 | 146 static LmHandlerResult handle_iq_commands_list(LmMessageHandler *h, |
147 LmConnection *c, | |
148 LmMessage *m, gpointer ud) | |
149 { | |
150 LmMessage *iq; | |
151 LmMessageNode *query; | |
152 const char *requester_jid; | |
153 const struct adhoc_command *command; | |
154 const char *node; | |
155 gboolean from_self; | |
940 | 156 |
1598 | 157 iq = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); |
158 query = lm_message_node_add_child(iq->node, "query", NULL); | |
159 node = lm_message_node_get_attribute | |
160 (lm_message_node_get_child(m->node, "query"), | |
161 "node"); | |
162 if (node) | |
163 lm_message_node_set_attribute(query, "node", node); | |
29 | 164 |
1598 | 165 requester_jid = lm_message_get_from(m); |
166 from_self = jid_equal(lm_connection_get_jid(c), requester_jid); | |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
167 |
1598 | 168 for (command = adhoc_command_list ; command->name ; command++) { |
169 if (!command->only_for_self || from_self) { | |
170 lm_message_node_set_attributes | |
171 (lm_message_node_add_child(query, "item", NULL), | |
172 "node", command->name, | |
173 "name", command->description, | |
174 "jid", lm_connection_get_jid(c), | |
175 NULL); | |
29 | 176 } |
177 } | |
178 | |
1598 | 179 lm_connection_send(c, iq, NULL); |
180 lm_message_unref(iq); | |
181 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
534 | 182 } |
183 | |
1598 | 184 static LmHandlerResult handle_iq_command_set_status(LmMessageHandler *h, |
185 LmConnection *c, | |
186 LmMessage *m, gpointer ud) | |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
187 { |
1598 | 188 const char *action, *node; |
189 char *sessionid; | |
190 LmMessage *iq; | |
191 LmMessageNode *command, *x, *y; | |
192 const struct adhoc_status *s; | |
193 | |
194 x = lm_message_node_get_child(m->node, "command"); | |
195 action = lm_message_node_get_attribute(x, "action"); | |
196 node = lm_message_node_get_attribute(x, "node"); | |
197 sessionid = (char *)lm_message_node_get_attribute(x, "sessionid"); | |
198 | |
199 iq = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); | |
200 command = lm_message_node_add_child(iq->node, "command", NULL); | |
201 lm_message_node_set_attribute(command, "node", node); | |
202 lm_message_node_set_attribute(command, "xmlns", NS_COMMANDS); | |
203 | |
204 if (!sessionid) { | |
205 sessionid = generate_session_id("set-status"); | |
206 lm_message_node_set_attribute(command, "sessionid", sessionid); | |
207 g_free(sessionid); | |
208 sessionid = NULL; | |
209 lm_message_node_set_attribute(command, "status", "executing"); | |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
210 |
1598 | 211 x = lm_message_node_add_child(command, "x", NULL); |
212 lm_message_node_set_attribute(x, "type", "form"); | |
213 lm_message_node_set_attribute(x, "xmlns", "jabber:x:data"); | |
214 | |
215 lm_message_node_add_child(x, "title", "Change Status"); | |
216 | |
217 lm_message_node_add_child(x, "instructions", | |
218 "Choose the status and status message"); | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
219 |
1598 | 220 // TODO see if factorisation is possible |
221 y = lm_message_node_add_child(x, "field", NULL); | |
222 lm_message_node_set_attribute(y, "type", "hidden"); | |
223 lm_message_node_set_attribute(y, "var", "FORM_TYPE"); | |
224 | |
225 lm_message_node_add_child(y, "value", "http://jabber.org/protocol/rc"); | |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1053
diff
changeset
|
226 |
1598 | 227 y = lm_message_node_add_child(x, "field", NULL); |
228 lm_message_node_set_attributes(y, | |
229 "type", "list-single", | |
230 "var", "status", | |
231 "label", "Status", | |
232 NULL); | |
233 lm_message_node_add_child(y, "required", NULL); | |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
234 |
1598 | 235 // XXX: ugly |
236 lm_message_node_add_child(y, "value", | |
237 adhoc_status_list[xmpp_getstatus()].name); | |
238 for (s = adhoc_status_list; s->name; s++) { | |
239 LmMessageNode *option = lm_message_node_add_child(y, "option", NULL); | |
240 lm_message_node_add_child(option, "value", s->name); | |
241 lm_message_node_set_attribute(option, "label", s->description); | |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
242 } |
1598 | 243 // TODO add priority ? |
244 // I do not think this is useful, user should not have to care of the | |
245 // priority like gossip and gajim do (misc) | |
246 lm_message_node_set_attributes | |
247 (lm_message_node_add_child(x, "field", NULL), | |
248 "type", "text-multi", | |
249 "var", "status-message", | |
250 "label", "Message", | |
251 NULL); | |
252 } else if (action && !strcmp(action, "cancel")) { | |
253 lm_message_node_set_attribute(command, "status", "canceled"); | |
254 } else { // (if sessionid and not canceled) | |
255 y = lm_message_node_find_xmlns(x, "jabber:x:data"); //x?xmlns=jabber:x:data | |
256 if (y) { | |
257 const char *value=NULL, *message=NULL; | |
258 LmMessageNode *fields, *field; | |
259 field = fields = lm_message_node_get_child(y, "field"); //field?var=status | |
260 while (field && strcmp("status", | |
261 lm_message_node_get_attribute(field, "var"))) | |
262 field = field->next; | |
263 field = lm_message_node_get_child(field, "value"); | |
264 if (field) | |
265 value = lm_message_node_get_value(field); | |
266 field = fields; //field?var=status-message | |
267 while (field && strcmp("status-message", | |
268 lm_message_node_get_attribute(field, "var"))) | |
269 field = field->next; | |
270 field = lm_message_node_get_child(field, "value"); | |
271 if (field) | |
272 message = lm_message_node_get_value(field); | |
273 if (value) { | |
274 for (s = adhoc_status_list; !s->name || strcmp(s->name, value); s++); | |
275 if (s->name) { | |
276 char *status = g_strdup_printf("%s %s", s->status, | |
277 message ? message : ""); | |
278 cmd_setstatus(NULL, status); | |
279 g_free(status); | |
280 lm_message_node_set_attribute(command, "status", "completed"); | |
281 lm_message_node_add_dataform_result(command, | |
282 "Status has been changed"); | |
1197 | 283 } |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
284 } |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
285 } |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
286 } |
1598 | 287 if (sessionid) |
288 lm_message_node_set_attribute(command, "sessionid", sessionid); | |
289 lm_connection_send(c, iq, NULL); | |
290 lm_message_unref(iq); | |
291 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
292 } | |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
293 |
1598 | 294 static void _callback_foreach_buddy_groupchat(gpointer rosterdata, void *param) |
295 { | |
296 LmMessageNode *field, *value, *option; | |
297 const char *room_jid, *nickname; | |
298 char *desc; | |
299 | |
300 room_jid = buddy_getjid(rosterdata); | |
301 if (!room_jid) return; | |
302 nickname = buddy_getnickname(rosterdata); | |
303 if (!nickname) return; | |
304 field = param; | |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
305 |
1598 | 306 option = lm_message_node_add_child(field, "option", NULL); |
307 value = lm_message_node_add_child(option, "value", room_jid); | |
308 desc = g_strdup_printf("%s on %s", nickname, room_jid); | |
309 lm_message_node_set_attribute(option, "label", desc); | |
310 g_free(desc); | |
311 } | |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
312 |
1598 | 313 static LmHandlerResult handle_iq_command_leave_groupchats(LmMessageHandler *h, |
314 LmConnection *c, | |
315 LmMessage *m, | |
316 gpointer ud) | |
317 { | |
318 const char *action, *node; | |
319 char *sessionid; | |
320 LmMessage *iq; | |
321 LmMessageNode *command, *x; | |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
322 |
1598 | 323 x = lm_message_node_get_child(m->node, "command"); |
324 action = lm_message_node_get_attribute(x, "action"); | |
325 node = lm_message_node_get_attribute(x, "node"); | |
326 sessionid = (char*)lm_message_node_get_attribute(x, "sessionid"); | |
327 | |
328 iq = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); | |
329 command = lm_message_node_add_child(iq->node, "command", NULL); | |
330 lm_message_node_set_attributes(command, | |
331 "node", node, | |
332 "xmlns", NS_COMMANDS, | |
333 NULL); | |
334 | |
335 if (!sessionid) { | |
336 LmMessageNode *field; | |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
337 |
1598 | 338 sessionid = generate_session_id("leave-groupchats"); |
339 lm_message_node_set_attribute(command, "sessionid", sessionid); | |
340 g_free(sessionid); | |
341 sessionid = NULL; | |
342 lm_message_node_set_attribute(command, "status", "executing"); | |
343 | |
344 x = lm_message_node_add_child(command, "x", NULL); | |
345 lm_message_node_set_attributes(x, | |
346 "type", "form", | |
347 "xmlns", "jabber:x:data", | |
348 NULL); | |
349 | |
350 lm_message_node_add_child(x, "title", "Leave groupchat(s)"); | |
351 | |
352 lm_message_node_add_child(x, "instructions", | |
353 "What groupchats do you want to leave?"); | |
354 | |
355 field = lm_message_node_add_child(x, "field", NULL); | |
356 lm_message_node_set_attributes(field, | |
357 "type", "hidden", | |
358 "var", "FORM_TYPE", | |
359 NULL); | |
360 | |
361 lm_message_node_add_child(field, "value", | |
362 "http://jabber.org/protocol/rc"); | |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
363 |
1598 | 364 field = lm_message_node_add_child(x, "field", NULL); |
365 lm_message_node_set_attributes(field, | |
366 "type", "list-multi", | |
367 "var", "groupchats", | |
368 "label", "Groupchats: ", | |
369 NULL); | |
370 lm_message_node_add_child(field, "required", NULL); | |
371 | |
372 foreach_buddy(ROSTER_TYPE_ROOM, &_callback_foreach_buddy_groupchat, field); | |
373 //TODO: return an error if we are not connected to groupchats | |
374 } else if (action && !strcmp(action, "cancel")) { | |
375 lm_message_node_set_attribute(command, "status", "canceled"); | |
376 } else { // (if sessionid and not canceled) | |
377 LmMessageNode *form = lm_message_node_find_xmlns(x, "jabber:x:data");//TODO | |
378 if (form) { | |
379 LmMessageNode *field; | |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
380 |
1598 | 381 lm_message_node_set_attribute(command, "status", "completed"); |
382 //TODO: implement sth. like "field?var=groupchats" in xmlnode... | |
383 field = lm_message_node_get_child(form, "field"); | |
384 while (field && strcmp("groupchats", | |
385 lm_message_node_get_attribute(field, "var"))) | |
386 field = field->next; | |
387 | |
388 for (x = field->children ; x ; x = x->next) | |
389 { | |
390 LmMessageNode *to_leave = lm_message_node_get_child(x, "value"); | |
391 if (to_leave) { | |
392 GList* b = buddy_search_jid(lm_message_node_get_value(to_leave)); | |
393 if (b) | |
394 cmd_room_leave(b->data, "Requested by remote command"); | |
395 } | |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
396 } |
1598 | 397 lm_message_node_add_dataform_result(command, |
398 "Groupchats have been left"); | |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
399 } |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
400 } |
1598 | 401 if (sessionid) |
402 lm_message_node_set_attribute(command, "sessionid", sessionid); | |
403 lm_connection_send(c, iq, NULL); | |
404 lm_message_unref(iq); | |
405 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
406 } | |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
407 |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
408 LmHandlerResult handle_iq_commands(LmMessageHandler *h, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
409 LmConnection *c, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
410 LmMessage *m, gpointer ud) |
1598 | 411 { |
412 const char *requester_jid = NULL; | |
413 LmMessageNode *cmd; | |
414 const struct adhoc_command *command; | |
415 | |
416 // mcabber has only partial XEP-0146 support... | |
417 if (LM_MESSAGE_SUB_TYPE_SET != lm_message_get_sub_type(m)) | |
418 return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; | |
419 | |
420 requester_jid = lm_message_get_from(m); | |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
421 |
1598 | 422 cmd = lm_message_node_get_child(m->node, "command"); |
423 if (jid_equal(lm_connection_get_jid(c), requester_jid)) { | |
424 const char *action, *node; | |
425 action = lm_message_node_get_attribute(cmd, "action"); | |
426 node = lm_message_node_get_attribute(cmd, "node"); | |
427 // action can be NULL, in which case it seems to take the default, | |
428 // ie execute | |
429 if (!action || !strcmp(action, "execute") || !strcmp(action, "cancel") | |
430 || !strcmp(action, "next") || !strcmp(action, "complete")) { | |
431 for (command = adhoc_command_list; command->name; command++) { | |
432 if (!strcmp(node, command->name)) | |
433 command->callback(h, c, m, ud); | |
434 } | |
435 // "prev" action will get there, as we do not implement it, | |
436 // and do not authorize it | |
437 } else { | |
438 LmMessage *r; | |
439 LmMessageNode *err; | |
440 r = lm_message_new_iq_error(m, XMPP_ERROR_BAD_REQUEST); | |
441 err = lm_message_node_get_child(r->node, "error"); | |
442 lm_message_node_set_attribute | |
443 (lm_message_node_add_child(err, "malformed-action", NULL), | |
444 "xmlns", NS_COMMANDS); | |
445 lm_connection_send(c, r, NULL); | |
446 lm_message_unref(r); | |
447 } | |
448 } else { | |
449 send_iq_error(c, m, XMPP_ERROR_FORBIDDEN); | |
450 } | |
451 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
35 | 452 } |
453 | |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
454 |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
455 LmHandlerResult handle_iq_disco_items(LmMessageHandler *h, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
456 LmConnection *c, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
457 LmMessage *m, gpointer ud) |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
458 { |
1598 | 459 LmMessageNode *query; |
460 const char *node; | |
461 query = lm_message_node_get_child(m->node, "query"); | |
462 node = lm_message_node_get_attribute(query, "node"); | |
463 if (node) { | |
464 if (!strcmp(node, NS_COMMANDS)) { | |
465 return handle_iq_commands_list(NULL, c, m, ud); | |
466 } else { | |
467 send_iq_error(c, m, XMPP_ERROR_NOT_IMPLEMENTED); | |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
468 } |
1598 | 469 } else { |
470 // not sure about this one | |
471 send_iq_error(c, m, XMPP_ERROR_NOT_IMPLEMENTED); | |
205 | 472 } |
1598 | 473 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
474 } |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
475 |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
476 |
1600 | 477 void _disco_add_feature_helper(gpointer data, gpointer user_data) |
1163
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
478 { |
1600 | 479 LmMessageNode *node = user_data; |
480 lm_message_node_set_attribute | |
481 (lm_message_node_add_child(node, "feature", NULL), "var", data); | |
1016 | 482 } |
483 | |
1600 | 484 // disco_info_set_caps(ansquery, entitycaps) |
485 // Add features attributes to ansquery. entitycaps should either be a | |
486 // valid capabilities hash or NULL. If it is NULL, the node attribute won't | |
487 // be added to the query child and Entity Capabilities will be announced | |
488 // as a feature. | |
1598 | 489 // Please change the entity version string if you modify mcabber disco |
490 // source code, so that it doesn't conflict with the upstream client. | |
1600 | 491 static void disco_info_set_caps(LmMessageNode *ansquery, |
492 const char *entitycaps) | |
1016 | 493 { |
1600 | 494 if (entitycaps) { |
495 char *eversion; | |
496 eversion = g_strdup_printf("%s#%s", MCABBER_CAPS_NODE, entitycaps); | |
497 lm_message_node_set_attribute(ansquery, "node", eversion); | |
498 g_free(eversion); | |
499 } | |
1016 | 500 |
1600 | 501 lm_message_node_set_attributes |
502 (lm_message_node_add_child(ansquery, "identity", NULL), | |
503 "category", "client", | |
504 "name", PACKAGE_STRING, | |
505 "type", "pc", | |
506 NULL); | |
1016 | 507 |
1600 | 508 if (entitycaps) |
509 caps_foreach_feature(entitycaps, _disco_add_feature_helper, ansquery); | |
510 else { | |
511 caps_foreach_feature(entity_version(xmpp_getstatus()), | |
512 _disco_add_feature_helper, | |
513 ansquery); | |
1598 | 514 lm_message_node_set_attribute |
515 (lm_message_node_add_child(ansquery, "feature", NULL), | |
1600 | 516 "var", NS_CAPS); |
517 } | |
1016 | 518 } |
519 | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
520 LmHandlerResult handle_iq_disco_info(LmMessageHandler *h, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
521 LmConnection *c, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
522 LmMessage *m, gpointer ud) |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
523 { |
1598 | 524 LmMessage *r; |
525 LmMessageNode *query, *tmp; | |
526 const char *node = NULL; | |
1600 | 527 const char *param = NULL; |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
528 |
1598 | 529 r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); |
530 query = lm_message_node_add_child(r->node, "query", NULL); | |
531 lm_message_node_set_attribute(query, "xmlns", NS_DISCO_INFO); | |
532 tmp = lm_message_node_find_child(m->node, "query"); | |
1600 | 533 if (tmp) { |
1598 | 534 node = lm_message_node_get_attribute(tmp, "node"); |
1600 | 535 param = node+strlen(MCABBER_CAPS_NODE)+1; |
536 } | |
537 if (node && startswith(node, MCABBER_CAPS_NODE "#", FALSE)) | |
538 disco_info_set_caps(query, param); // client#version | |
539 else | |
1598 | 540 // Basic discovery request |
1600 | 541 disco_info_set_caps(query, NULL); |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
542 |
1598 | 543 lm_connection_send(c, r, NULL); |
544 lm_message_unref(r); | |
545 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
546 } |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
547 |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
548 LmHandlerResult handle_iq_roster(LmMessageHandler *h, LmConnection *c, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
549 LmMessage *m, gpointer ud) |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
550 { |
1598 | 551 LmMessageNode *y; |
552 const char *fjid, *name, *group, *sub, *ask; | |
553 char *cleanalias; | |
554 enum subscr esub; | |
555 int need_refresh = FALSE; | |
556 guint roster_type; | |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
557 |
1598 | 558 for (y = lm_message_node_find_child(lm_message_node_find_xmlns |
559 (m->node, NS_ROSTER), | |
560 "item"); | |
561 y; | |
562 y = y->next) { | |
563 char *name_tmp = NULL; | |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
564 |
1598 | 565 fjid = lm_message_node_get_attribute(y, "jid"); |
566 name = lm_message_node_get_attribute(y, "name"); | |
567 sub = lm_message_node_get_attribute(y, "subscription"); | |
568 ask = lm_message_node_get_attribute(y, "ask"); | |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
569 |
1598 | 570 if (lm_message_node_find_child(y, "group")) |
571 group = lm_message_node_get_value(lm_message_node_find_child(y, "group")); | |
572 else | |
573 group = NULL; | |
1396
8f9928839a36
Automatically unlock new rooms (suggested by Michael Weiser)
Mikael Berthe <mikael@lilotux.net>
parents:
1395
diff
changeset
|
574 |
1598 | 575 if (!fjid) |
576 continue; | |
577 | |
578 cleanalias = jidtodisp(fjid); | |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
579 |
1598 | 580 esub = sub_none; |
581 if (sub) { | |
582 if (!strcmp(sub, "to")) esub = sub_to; | |
583 else if (!strcmp(sub, "from")) esub = sub_from; | |
584 else if (!strcmp(sub, "both")) esub = sub_both; | |
585 else if (!strcmp(sub, "remove")) esub = sub_remove; | |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
586 } |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
587 |
1598 | 588 if (esub == sub_remove) { |
589 roster_del_user(cleanalias); | |
590 scr_LogPrint(LPRINT_LOGNORM, "Buddy <%s> has been removed " | |
591 "from the roster", cleanalias); | |
592 g_free(cleanalias); | |
593 need_refresh = TRUE; | |
594 continue; | |
595 } | |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
596 |
1598 | 597 if (ask && !strcmp(ask, "subscribe")) |
598 esub |= sub_pending; | |
599 | |
600 if (!name) { | |
601 if (!settings_opt_get_int("roster_hide_domain")) { | |
602 name = cleanalias; | |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
603 } else { |
1598 | 604 char *p; |
605 name = name_tmp = g_strdup(cleanalias); | |
606 p = strchr(name_tmp, JID_DOMAIN_SEPARATOR); | |
607 if (p) *p = '\0'; | |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
608 } |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
609 } |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
610 |
1598 | 611 // Tricky... :-\ My guess is that if there is no JID_DOMAIN_SEPARATOR, |
612 // this is an agent. | |
613 if (strchr(cleanalias, JID_DOMAIN_SEPARATOR)) | |
614 roster_type = ROSTER_TYPE_USER; | |
615 else | |
616 roster_type = ROSTER_TYPE_AGENT; | |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
617 |
1598 | 618 roster_add_user(cleanalias, name, group, roster_type, esub, 1); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
619 |
1598 | 620 g_free(name_tmp); |
621 g_free(cleanalias); | |
1446
49c8be874344
Add option 'ignore_self_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1439
diff
changeset
|
622 } |
49c8be874344
Add option 'ignore_self_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1439
diff
changeset
|
623 |
1598 | 624 buddylist_build(); |
625 update_roster = TRUE; | |
626 if (need_refresh) | |
627 scr_UpdateBuddyWindow(); | |
628 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
629 } | |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
630 |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
631 LmHandlerResult handle_iq_ping(LmMessageHandler *h, LmConnection *c, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
632 LmMessage *m, gpointer ud) |
1598 | 633 { |
634 LmMessage *r; | |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
635 |
1598 | 636 r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); |
637 lm_connection_send(c, r, NULL); | |
638 lm_message_unref(r); | |
639 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
640 } | |
641 | |
642 double seconds_since_last_use(void) | |
643 { | |
644 return difftime(time(NULL), iqlast); | |
645 } | |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
646 |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
647 LmHandlerResult handle_iq_last(LmMessageHandler *h, LmConnection *c, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
648 LmMessage *m, gpointer ud) |
1598 | 649 { |
650 LmMessage *r; | |
651 LmMessageNode *query; | |
652 char *seconds; | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
653 |
1598 | 654 if (!settings_opt_get_int("iq_hide_requests")) { |
655 scr_LogPrint(LPRINT_LOGNORM, "Received an IQ last time request from <%s>", | |
656 lm_message_get_from(m)); | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
657 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
658 |
1598 | 659 if (settings_opt_get_int("iq_last_disable") || |
660 (settings_opt_get_int("iq_last_disable_when_notavail") && | |
661 xmpp_getstatus() == notavail)) | |
662 { | |
663 send_iq_error(c, m, XMPP_ERROR_SERVICE_UNAVAILABLE); | |
664 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
665 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
666 |
1598 | 667 r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); |
668 query = lm_message_node_add_child(r->node, "query", NULL); | |
669 seconds = g_strdup_printf("%.0f", seconds_since_last_use()); | |
670 lm_message_node_set_attribute(query, "seconds", seconds); | |
671 g_free(seconds); | |
1236
f7b35b1c343d
Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1215
diff
changeset
|
672 |
1598 | 673 lm_connection_send(c, r, NULL); |
674 lm_message_unref(r); | |
675 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
1128 | 676 } |
677 | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
678 LmHandlerResult handle_iq_version(LmMessageHandler *h, LmConnection *c, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
679 LmMessage *m, gpointer ud) |
1128 | 680 { |
1598 | 681 LmMessage *r; |
682 LmMessageNode *query; | |
683 char *os = NULL; | |
684 char *ver = mcabber_version(); | |
1128 | 685 |
1598 | 686 if (!settings_opt_get_int("iq_hide_requests")) { |
687 scr_LogPrint(LPRINT_LOGNORM, "Received an IQ version request from <%s>", | |
688 lm_message_get_from(m)); | |
689 } | |
690 if (!settings_opt_get_int("iq_version_hide_os")) { | |
691 struct utsname osinfo; | |
692 uname(&osinfo); | |
693 os = g_strdup_printf("%s %s %s", osinfo.sysname, osinfo.release, | |
694 osinfo.machine); | |
1128 | 695 } |
1598 | 696 |
697 r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); | |
698 | |
699 query = lm_message_node_add_child(r->node, "query", NULL); | |
700 | |
701 lm_message_node_add_child(query, "name", PACKAGE_NAME); | |
702 lm_message_node_add_child(query, "version", ver); | |
703 if (os) { | |
704 lm_message_node_add_child(query, "os", os); | |
705 g_free(os); | |
706 } | |
707 | |
708 g_free(ver); | |
709 lm_connection_send(c, r, NULL); | |
710 lm_message_unref(r); | |
711 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
1128 | 712 } |
713 | |
1598 | 714 // This function borrows some code from the Pidgin project |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
715 LmHandlerResult handle_iq_time(LmMessageHandler *h, LmConnection *c, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
716 LmMessage *m, gpointer ud) |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
717 { |
1598 | 718 LmMessage *r; |
719 LmMessageNode *query; | |
720 char *buf, *utf8_buf; | |
721 time_t now_t; | |
722 struct tm *now; | |
1528
4b4b3948420c
MUC fix: the topic couldn't be cleared
Mikael Berthe <mikael@lilotux.net>
parents:
1525
diff
changeset
|
723 |
1598 | 724 time(&now_t); |
725 | |
726 if (!settings_opt_get_int("iq_hide_requests")) { | |
727 scr_LogPrint(LPRINT_LOGNORM, "Received an IQ time request from <%s>", | |
728 lm_message_get_from(m)); | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
729 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
730 |
1598 | 731 buf = g_new0(char, 512); |
732 | |
733 r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); | |
734 query = lm_message_node_add_child(r->node, "query", NULL); | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
735 |
1598 | 736 now = gmtime(&now_t); |
1128 | 737 |
1598 | 738 strftime(buf, 512, "%Y%m%dT%T", now); |
739 lm_message_node_add_child(query, "utc", buf); | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
740 |
1598 | 741 now = localtime(&now_t); |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
742 |
1598 | 743 strftime(buf, 512, "%Z", now); |
744 if ((utf8_buf = to_utf8(buf))) { | |
745 lm_message_node_add_child(query, "tz", utf8_buf); | |
746 g_free(utf8_buf); | |
747 } | |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
748 |
1598 | 749 strftime(buf, 512, "%d %b %Y %T", now); |
750 if ((utf8_buf = to_utf8(buf))) { | |
751 lm_message_node_add_child(query, "display", utf8_buf); | |
752 g_free(utf8_buf); | |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
753 } |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
754 |
1598 | 755 lm_connection_send(c, r, NULL); |
756 lm_message_unref(r); | |
757 g_free(buf); | |
758 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
759 } | |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
760 |
1598 | 761 // This function borrows some code from the Pidgin project |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
762 LmHandlerResult handle_iq_time202(LmMessageHandler *h, LmConnection *c, |
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1600
diff
changeset
|
763 LmMessage *m, gpointer ud) |
1598 | 764 { |
765 LmMessage *r; | |
766 LmMessageNode *query; | |
767 char *buf, *utf8_buf; | |
768 time_t now_t; | |
769 struct tm *now; | |
770 char const *sign; | |
771 int diff = 0; | |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
772 |
1598 | 773 time(&now_t); |
774 | |
775 if (!settings_opt_get_int("iq_hide_requests")) { | |
776 scr_LogPrint(LPRINT_LOGNORM, "Received an IQ time request from <%s>", | |
777 lm_message_get_from(m)); | |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
778 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
779 |
1598 | 780 buf = g_new0(char, 512); |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
781 |
1598 | 782 r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); |
783 query = lm_message_node_add_child(r->node, "time", NULL); | |
784 lm_message_node_set_attribute(query, "xmlns", NS_XMPP_TIME); | |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
785 |
1598 | 786 now = localtime(&now_t); |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
787 |
1598 | 788 if (now->tm_isdst >= 0) { |
789 #if defined HAVE_TM_GMTOFF | |
790 diff = now->tm_gmtoff; | |
791 #elif defined HAVE_TIMEZONE | |
792 tzset(); | |
793 diff = -timezone; | |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
794 #endif |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
795 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
796 |
1598 | 797 if (diff < 0) { |
798 sign = "-"; | |
799 diff = -diff; | |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
800 } else { |
1598 | 801 sign = "+"; |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
802 } |
1598 | 803 diff /= 60; |
804 snprintf(buf, 512, "%c%02d:%02d", *sign, diff / 60, diff % 60); | |
805 if ((utf8_buf = to_utf8(buf))) { | |
806 lm_message_node_add_child(query, "tzo", utf8_buf); | |
807 g_free(utf8_buf); | |
1128 | 808 } |
809 | |
1598 | 810 now = gmtime(&now_t); |
818
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
811 |
1598 | 812 strftime(buf, 512, "%Y-%m-%dT%TZ", now); |
813 lm_message_node_add_child(query, "utc", buf); | |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
814 |
1598 | 815 lm_connection_send(c, r, NULL); |
816 lm_message_unref(r); | |
817 g_free(buf); | |
818 return LM_HANDLER_RESULT_REMOVE_MESSAGE; | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
819 } |
1599 | 820 |
1615
171ae5a258fa
Add dummy vcard IQ handler
Mikael Berthe <mikael@lilotux.net>
parents:
1604
diff
changeset
|
821 LmHandlerResult handle_iq_vcard(LmMessageHandler *h, LmConnection *c, |
171ae5a258fa
Add dummy vcard IQ handler
Mikael Berthe <mikael@lilotux.net>
parents:
1604
diff
changeset
|
822 LmMessage *m, gpointer ud) |
171ae5a258fa
Add dummy vcard IQ handler
Mikael Berthe <mikael@lilotux.net>
parents:
1604
diff
changeset
|
823 { |
171ae5a258fa
Add dummy vcard IQ handler
Mikael Berthe <mikael@lilotux.net>
parents:
1604
diff
changeset
|
824 send_iq_error(c, m, XMPP_ERROR_SERVICE_UNAVAILABLE); |
171ae5a258fa
Add dummy vcard IQ handler
Mikael Berthe <mikael@lilotux.net>
parents:
1604
diff
changeset
|
825 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
171ae5a258fa
Add dummy vcard IQ handler
Mikael Berthe <mikael@lilotux.net>
parents:
1604
diff
changeset
|
826 } |
171ae5a258fa
Add dummy vcard IQ handler
Mikael Berthe <mikael@lilotux.net>
parents:
1604
diff
changeset
|
827 |
1599 | 828 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |