annotate mcabber/mcabber/xmpp_iq.c @ 2210:ea90906cb691

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