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