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