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