annotate mcabber/src/jab_iq.c @ 1414:366ef500c522

Update copyrights
author Mikael Berthe <mikael@lilotux.net>
date Sat, 19 Jan 2008 16:30:39 +0100
parents d431cd75eb53
children 317f8d181626
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
1 /*
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
2 * jab_iq.c -- Jabber protocol IQ-related fonctions
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 387
diff changeset
3 *
1414
366ef500c522 Update copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1395
diff changeset
4 * Copyright (C) 2005-2008 Mikael Berthe <mikael@lilotux.net>
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
5 * Some parts initially came from the centericq project:
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
6 * Copyright (C) 2002-2005 by Konstantin Klyagin <konst@konst.org.ua>
1361
0562106d20c1 Update some copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
7 * Some small parts come from the Pidgin project <http://pidgin.im/>
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
8 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or (at
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
12 * your option) any later version.
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
13 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
17 * General Public License for more details.
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
18 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
22 * USA
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
23 */
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
24
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
25 #include <sys/utsname.h>
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
26 #include <glib.h>
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
27
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
28 #include "jabglue.h"
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
29 #include "jab_priv.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
30 #include "roster.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
31 #include "utils.h"
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
32 #include "screen.h"
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
33 #include "settings.h"
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
34 #include "hbuf.h"
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
35 #include "commands.h"
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
36 #include "hooks.h"
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
37
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
38 #ifdef ENABLE_HGCSET
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
39 # include "hgcset.h"
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
40 #endif
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
41
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
42
1008
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
43 // Bookmarks for IQ:private storage
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
44 xmlnode bookmarks;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
45 // Roster notes for IQ:private storage
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
46 xmlnode rosternotes;
1008
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
47
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
48 static GSList *iqs_list;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
49
1254
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
50 time_t iqlast; // last message/status change time
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
51
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
52 // Enum for vCard attributes
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
53 enum vcard_attr {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
54 vcard_home = 1<<0,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
55 vcard_work = 1<<1,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
56 vcard_postal = 1<<2,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
57 vcard_voice = 1<<3,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
58 vcard_fax = 1<<4,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
59 vcard_cell = 1<<5,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
60 vcard_inet = 1<<6,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
61 vcard_pref = 1<<7,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
62 };
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
63
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
64 static void handle_iq_command_set_status(jconn conn, char *from,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
65 const char *id, xmlnode xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
66
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
67 static void handle_iq_command_leave_groupchats(jconn conn, char *from,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
68 const char *id, xmlnode xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
69
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
70 typedef void (*adhoc_command_callback)(jconn, char*, const char*, xmlnode);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
71
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
72 struct adhoc_command {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
73 char *name;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
74 char *description;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
75 bool only_for_self;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
76 adhoc_command_callback callback;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
77 };
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
78
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
79 const struct adhoc_command adhoc_command_list[] = {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
80 { "http://jabber.org/protocol/rc#set-status",
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
81 "Change client status",
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
82 1,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
83 &handle_iq_command_set_status },
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
84 { "http://jabber.org/protocol/rc#leave-groupchats",
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
85 "Leave groupchat(s)",
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
86 1,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
87 &handle_iq_command_leave_groupchats },
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
88 { NULL, NULL, 0, NULL },
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
89 };
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
90
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
91 struct adhoc_status {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
92 char *name; // the name used by adhoc
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
93 char *description;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
94 char *status; // the string, used by setstus
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
95 };
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
96
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
97 const struct adhoc_status adhoc_status_list[] = {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
98 {"online", "Online", "avail"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
99 {"chat", "Chat", "free"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
100 {"away", "Away", "away"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
101 {"xd", "Extended away", "notavail"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
102 {"dnd", "Do not disturb", "dnd"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
103 {"invisible", "Invisible", "invisible"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
104 {"offline", "Offline", "offline"},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
105 {NULL, NULL, NULL},
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
106 };
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
107
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
108 // entity_version()
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
109 // Return a static version string for Entity Capabilities.
1218
ab5de2ed2b7e Simplify entity_version()
Mikael Berthe <mikael@lilotux.net>
parents: 1217
diff changeset
110 // It should be specific to the client version, please change the id
ab5de2ed2b7e Simplify entity_version()
Mikael Berthe <mikael@lilotux.net>
parents: 1217
diff changeset
111 // if you alter mcabber's disco support (or add something to the version
ab5de2ed2b7e Simplify entity_version()
Mikael Berthe <mikael@lilotux.net>
parents: 1217
diff changeset
112 // number) so that it doesn't conflict with the official client.
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
113 const char *entity_version(void)
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
114 {
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
115 static char *ver;
1334
f8cfa22cedc2 Ready for release 0.9.4
Mikael Berthe <mikael@lilotux.net>
parents: 1333
diff changeset
116 const char *PVERSION = PACKAGE_VERSION; // "+xxx";
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
117
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
118 if (ver)
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
119 return ver;
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
120
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
121 #ifdef HGCSET
1255
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
122 ver = g_strdup_printf("%s-%s", PVERSION, HGCSET);
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
123 #else
1255
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
124 ver = g_strdup(PVERSION);
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
125 #endif
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
126
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
127 return ver;
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
128 }
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
129
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
130 // iqs_new(type, namespace, prefix, timeout)
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
131 // Create a query (GET, SET) IQ structure. This function should not be used
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
132 // for RESULT packets.
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
133 eviqs *iqs_new(guint8 type, const char *ns, const char *prefix, time_t tmout)
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
134 {
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
135 static guint iqs_idn;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
136 eviqs *new_iqs;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
137 time_t now_t;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
138
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
139 iqs_idn++;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
140
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
141 new_iqs = g_new0(eviqs, 1);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
142 time(&now_t);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
143 new_iqs->ts_create = now_t;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
144 if (tmout)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
145 new_iqs->ts_expire = now_t + tmout;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
146 new_iqs->type = type;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
147 new_iqs->xmldata = jutil_iqnew(type, (char*)ns);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
148 if (prefix)
687
426145046b93 Minor format change in IQ id string
Mikael Berthe <mikael@lilotux.net>
parents: 686
diff changeset
149 new_iqs->id = g_strdup_printf("%s_%d", prefix, iqs_idn);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
150 else
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
151 new_iqs->id = g_strdup_printf("%d", iqs_idn);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
152 xmlnode_put_attrib(new_iqs->xmldata, "id", new_iqs->id);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
153
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
154 iqs_list = g_slist_append(iqs_list, new_iqs);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
155 return new_iqs;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
156 }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
157
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
158 int iqs_del(const char *iqid)
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
159 {
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
160 GSList *p;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
161 eviqs *i;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
162
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
163 if (!iqid) return 1;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
164
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
165 for (p = iqs_list; p; p = g_slist_next(p)) {
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
166 i = p->data;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
167 if (!strcmp(iqid, i->id))
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
168 break;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
169 }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
170 if (p) {
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
171 g_free(i->id);
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
172 xmlnode_free(i->xmldata);
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
173 g_free(i->data);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
174 g_free(i);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
175 iqs_list = g_slist_remove(iqs_list, p->data);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
176 return 0; // Ok, deleted
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
177 }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
178 return -1; // Not found
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
179 }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
180
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
181 static eviqs *iqs_find(const char *iqid)
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
182 {
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
183 GSList *p;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
184 eviqs *i;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
185
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
186 if (!iqid) return NULL;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
187
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
188 for (p = iqs_list; p; p = g_slist_next(p)) {
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
189 i = p->data;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
190 if (!strcmp(iqid, i->id))
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
191 return i;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
192 }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
193 return NULL;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
194 }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
195
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
196 // iqs_callback(iqid, xml_result, iqcontext)
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
197 // Callback processing for the iqid message.
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
198 // If we've received an answer, xml_result should point to the xmldata packet.
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
199 // If this is a timeout, xml_result should be NULL.
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
200 // Return 0 in case of success, -1 if the iqid hasn't been found.
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
201 int iqs_callback(const char *iqid, xmlnode xml_result, guint iqcontext)
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
202 {
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
203 eviqs *i;
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
204 int retval = 0;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
205
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
206 i = iqs_find(iqid);
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
207 if (!i) return -1;
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
208
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
209 // IQ processing
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
210 // Note: If xml_result is NULL, this is a timeout
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
211 if (i->callback)
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
212 retval = (*i->callback)(i, xml_result, iqcontext);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
213
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
214 iqs_del(iqid);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
215 return retval;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
216 }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
217
705
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
218 void iqs_check_timeout(time_t now_t)
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
219 {
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
220 GSList *p;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
221 eviqs *i;
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
222
705
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
223 p = iqs_list;
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
224 while (p) {
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
225 i = p->data;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
226 // We must get next IQ eviqs element now because the current one
705
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
227 // could be freed.
603b43e4f56a Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents: 704
diff changeset
228 p = g_slist_next(p);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
229
965
1bdf0f1b16c0 Use U suffix for unsigned defines
Mikael Berthe <mikael@lilotux.net>
parents: 959
diff changeset
230 if ((!i->ts_expire && now_t > i->ts_create + (time_t)IQS_MAX_TIMEOUT) ||
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
231 (i->ts_expire && now_t > i->ts_expire)) {
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
232 iqs_callback(i->id, NULL, IQS_CONTEXT_TIMEOUT);
683
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
233 }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
234 }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
235 }
c5e0d8c3f00c Introduce new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
236
689
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
237 void jb_iqs_display_list(void)
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
238 {
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
239 GSList *p;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
240 eviqs *i;
689
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
241
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
242 scr_LogPrint(LPRINT_LOGNORM, "IQ list:");
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
243 for (p = iqs_list; p; p = g_slist_next(p)) {
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
244 i = p->data;
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
245 scr_LogPrint(LPRINT_LOGNORM, "Id [%s]", i->id);
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
246 }
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
247 scr_LogPrint(LPRINT_LOGNORM, "End of IQ list.");
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
248 }
281aab5aef50 Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents: 688
diff changeset
249
606
0b4ed231ebc2 Code cleanup + remove deprecated Agents list IQ request
Mikael Berthe <mikael@lilotux.net>
parents: 605
diff changeset
250 static void handle_iq_roster(xmlnode x)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
251 {
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
252 xmlnode y;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
253 const char *fjid, *name, *group, *sub, *ask;
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
254 char *cleanalias;
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
255 enum subscr esub;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
256 int need_refresh = FALSE;
613
a6b8b373e4de Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
257 guint roster_type;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
258
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
259 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
1348
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
260 char *name_tmp = NULL;
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
261
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
262 fjid = xmlnode_get_attrib(y, "jid");
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
263 name = xmlnode_get_attrib(y, "name");
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
264 sub = xmlnode_get_attrib(y, "subscription");
605
2a4fefb98511 Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
265 ask = xmlnode_get_attrib(y, "ask");
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
266
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
267 group = xmlnode_get_tag_data(y, "group");
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
268
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
269 if (!fjid)
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
270 continue;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
271
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
272 cleanalias = jidtodisp(fjid);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
273
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
274 esub = sub_none;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
275 if (sub) {
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
276 if (!strcmp(sub, "to")) esub = sub_to;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
277 else if (!strcmp(sub, "from")) esub = sub_from;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
278 else if (!strcmp(sub, "both")) esub = sub_both;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
279 else if (!strcmp(sub, "remove")) esub = sub_remove;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
280 }
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
281
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
282 if (esub == sub_remove) {
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
283 roster_del_user(cleanalias);
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
284 scr_LogPrint(LPRINT_LOGNORM, "Buddy <%s> has been removed "
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
285 "from the roster", cleanalias);
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
286 g_free(cleanalias);
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
287 need_refresh = TRUE;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
288 continue;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
289 }
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
290
605
2a4fefb98511 Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
291 if (ask && !strcmp(ask, "subscribe"))
2a4fefb98511 Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
292 esub |= sub_pending;
2a4fefb98511 Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
293
1348
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
294 if (!name) {
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
295 if (!settings_opt_get_int("roster_hide_domain")) {
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
296 name = cleanalias;
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
297 } else {
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
298 char *p;
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
299 name = name_tmp = g_strdup(cleanalias);
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
300 p = strchr(name_tmp, JID_DOMAIN_SEPARATOR);
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
301 if (p) *p = '\0';
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
302 }
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
303 }
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
304
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 965
diff changeset
305 // Tricky... :-\ My guess is that if there is no JID_DOMAIN_SEPARATOR,
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 965
diff changeset
306 // this is an agent.
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 965
diff changeset
307 if (strchr(cleanalias, JID_DOMAIN_SEPARATOR))
613
a6b8b373e4de Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
308 roster_type = ROSTER_TYPE_USER;
a6b8b373e4de Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
309 else
a6b8b373e4de Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
310 roster_type = ROSTER_TYPE_AGENT;
a6b8b373e4de Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
311
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1353
diff changeset
312 roster_add_user(cleanalias, name, group, roster_type, esub, 1);
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
313
1348
26d1dd2c948f Add option 'roster_hide_domain'
Mikael Berthe <mikael@lilotux.net>
parents: 1340
diff changeset
314 g_free(name_tmp);
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
315 g_free(cleanalias);
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
316 }
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
317
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
318 buddylist_build();
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
319 update_roster = TRUE;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 597
diff changeset
320 if (need_refresh)
959
8bf36cef8aa6 Do not enter chat mode after command "/del"
Mikael Berthe <mikael@lilotux.net>
parents: 871
diff changeset
321 scr_UpdateBuddyWindow();
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
322 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
323
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
324 // This callback is reached when mcabber receives the first roster update
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
325 // after the connection.
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
326 static int iqscallback_gotroster(eviqs *iqp, xmlnode xml_result, guint iqcontext)
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
327 {
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
328 xmlnode x;
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
329 char *ns;
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
330
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
331 // Leave now if we cannot process xml_result
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
332 if (!xml_result || iqcontext) return -1;
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
333
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
334 // Only execute the hook if the roster has been successfully retrieved
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
335 if (iqcontext != IQS_CONTEXT_RESULT)
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
336 return 0;
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
337
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
338 x = xmlnode_get_tag(xml_result, "query");
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
339 if (!x)
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
340 return -1;
1365
c7e709719c43 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1361
diff changeset
341
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
342 ns = xmlnode_get_attrib(x, "xmlns");
1365
c7e709719c43 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1361
diff changeset
343 if (ns && !strcmp(ns, NS_ROSTER))
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
344 handle_iq_roster(x);
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
345
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
346 // Post-login stuff
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
347 jb_setprevstatus();
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
348 hook_execute_internal("hook-post-connect");
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
349
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
350 return 0;
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
351 }
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
352
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
353 static void request_roster(void)
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
354 {
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
355 eviqs *iqn = iqs_new(JPACKET__GET, NS_ROSTER, "Roster", IQS_DEFAULT_TIMEOUT);
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
356 iqn->callback = &iqscallback_gotroster;
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
357 jab_send(jc, iqn->xmldata);
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
358 }
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
359
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
360 static int iqscallback_version(eviqs *iqp, xmlnode xml_result, guint iqcontext)
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
361 {
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
362 xmlnode ansqry;
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
363 char *p;
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
364 char *bjid;
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
365 char *buf;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
366
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
367 // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
368 if (!xml_result || iqcontext) return -1;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
369
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
370 ansqry = xmlnode_get_tag(xml_result, "query");
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
371 if (!ansqry) {
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
372 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result!");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
373 return 0;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
374 }
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
375 // Display IQ result sender...
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
376 p = xmlnode_get_attrib(xml_result, "from");
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
377 if (!p) {
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
378 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name).");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
379 return 0;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
380 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
381 bjid = p;
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
382
782
19121d9f4aa2 Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents: 776
diff changeset
383 buf = g_strdup_printf("Received IQ:version result from <%s>", bjid);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
384 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
385
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
386 // bjid should now really be the "bare JID", let's strip the resource
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 965
diff changeset
387 p = strchr(bjid, JID_RESOURCE_SEPARATOR);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
388 if (p) *p = '\0';
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
389
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
390 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
391 g_free(buf);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
392
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
393 // Get result data...
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
394 p = xmlnode_get_tag_data(ansqry, "name");
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
395 if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
396 buf = g_strdup_printf("Name: %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
397 scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
398 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
399 g_free(buf);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
400 }
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
401 p = xmlnode_get_tag_data(ansqry, "version");
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
402 if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
403 buf = g_strdup_printf("Version: %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
404 scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
405 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
406 g_free(buf);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
407 }
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
408 p = xmlnode_get_tag_data(ansqry, "os");
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
409 if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
410 buf = g_strdup_printf("OS: %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
411 scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
412 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
413 g_free(buf);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
414 }
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
415 return 0;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
416 }
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
417
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
418 void request_version(const char *fulljid)
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
419 {
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
420 eviqs *iqn;
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
421
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
422 iqn = iqs_new(JPACKET__GET, NS_VERSION, "version", IQS_DEFAULT_TIMEOUT);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
423 xmlnode_put_attrib(iqn->xmldata, "to", fulljid);
690
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
424 iqn->callback = &iqscallback_version;
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
425 jab_send(jc, iqn->xmldata);
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
426 }
3e965a1186c7 Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 689
diff changeset
427
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
428 static int iqscallback_time(eviqs *iqp, xmlnode xml_result, guint iqcontext)
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
429 {
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
430 xmlnode ansqry;
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
431 char *p;
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
432 char *bjid;
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
433 char *buf;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
434
698
60522cf6d325 Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents: 692
diff changeset
435 // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
436 if (!xml_result || iqcontext) return -1;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
437
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
438 ansqry = xmlnode_get_tag(xml_result, "query");
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
439 if (!ansqry) {
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
440 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result!");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
441 return 0;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
442 }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
443 // Display IQ result sender...
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
444 p = xmlnode_get_attrib(xml_result, "from");
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
445 if (!p) {
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
446 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result (no sender name).");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
447 return 0;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
448 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
449 bjid = p;
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
450
782
19121d9f4aa2 Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents: 776
diff changeset
451 buf = g_strdup_printf("Received IQ:time result from <%s>", bjid);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
452 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
453
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
454 // bjid should now really be the "bare JID", let's strip the resource
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 965
diff changeset
455 p = strchr(bjid, JID_RESOURCE_SEPARATOR);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
456 if (p) *p = '\0';
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
457
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
458 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0);
704
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
459 g_free(buf);
4118a66f2c02 Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents: 703
diff changeset
460
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
461 // Get result data...
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
462 p = xmlnode_get_tag_data(ansqry, "utc");
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
463 if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
464 buf = g_strdup_printf("UTC: %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
465 scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
466 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
467 g_free(buf);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
468 }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
469 p = xmlnode_get_tag_data(ansqry, "tz");
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
470 if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
471 buf = g_strdup_printf("TZ: %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
472 scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
473 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
474 g_free(buf);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
475 }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
476 p = xmlnode_get_tag_data(ansqry, "display");
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
477 if (p) {
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
478 buf = g_strdup_printf("Time: %s", p);
1333
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
479 scr_WriteIncomingMessage(bjid, buf,
e30a9d907105 Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
480 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1030
923cf5a92b44 [BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents: 965
diff changeset
481 g_free(buf);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
482 }
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
483 return 0;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
484 }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
485
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
486 void request_time(const char *fulljid)
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
487 {
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
488 eviqs *iqn;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
489
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
490 iqn = iqs_new(JPACKET__GET, NS_TIME, "time", IQS_DEFAULT_TIMEOUT);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 746
diff changeset
491 xmlnode_put_attrib(iqn->xmldata, "to", fulljid);
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
492 iqn->callback = &iqscallback_time;
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
493 jab_send(jc, iqn->xmldata);
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
494 }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 690
diff changeset
495
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
496 static int iqscallback_last(eviqs *iqp, xmlnode xml_result, guint iqcontext)
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
497 {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
498 xmlnode ansqry;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
499 char *p;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
500 char *bjid;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
501 char *buf;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
502
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
503 // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
504 if (!xml_result || iqcontext) return -1;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
505
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
506 ansqry = xmlnode_get_tag(xml_result, "query");
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
507 if (!ansqry) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
508 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result!");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
509 return 0;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
510 }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
511 // Display IQ result sender...
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
512 p = xmlnode_get_attrib(xml_result, "from");
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
513 if (!p) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
514 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result (no sender name).");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
515 return 0;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
516 }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
517 bjid = p;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
518
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
519 buf = g_strdup_printf("Received IQ:last result from <%s>", bjid);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
520 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
521
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
522 // bjid should now really be the "bare JID", let's strip the resource
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
523 p = strchr(bjid, JID_RESOURCE_SEPARATOR);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
524 if (p) *p = '\0';
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
525
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
526 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0);
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
527 g_free(buf);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
528
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
529 // Get result data...
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
530 p = xmlnode_get_attrib(ansqry, "seconds");
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
531 if (p) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
532 long int s;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
533 GString *sbuf;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
534 sbuf = g_string_new("Idle time: ");
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
535 s = atol(p);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
536 // Days
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
537 if (s > 86400L) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
538 g_string_append_printf(sbuf, "%ldd ", s/86400L);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
539 s %= 86400L;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
540 }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
541 // hh:mm:ss
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
542 g_string_append_printf(sbuf, "%02ld:", s/3600L);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
543 s %= 3600L;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
544 g_string_append_printf(sbuf, "%02ld:%02ld", s/60L, s%60L);
1268
dbc907b2d92f Add configurable colors for info and incoming messages (Michal 'vorner' Vaner)
Mikael Berthe <mikael@lilotux.net>
parents: 1261
diff changeset
545 scr_WriteIncomingMessage(bjid, sbuf->str,
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
546 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
547 g_string_free(sbuf, TRUE);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
548 } else {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
549 scr_WriteIncomingMessage(bjid, "No idle time reported.",
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
550 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
551 }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
552 p = xmlnode_get_data(ansqry);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
553 if (p) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
554 buf = g_strdup_printf("Status message: %s", p);
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
555 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0);
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
556 g_free(buf);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
557 }
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
558 return 0;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
559 }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
560
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
561 void request_last(const char *fulljid)
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
562 {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
563 eviqs *iqn;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
564
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
565 iqn = iqs_new(JPACKET__GET, NS_LAST, "last", IQS_DEFAULT_TIMEOUT);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
566 xmlnode_put_attrib(iqn->xmldata, "to", fulljid);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
567 iqn->callback = &iqscallback_last;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
568 jab_send(jc, iqn->xmldata);
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
569 }
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
570
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
571 static void display_vcard_item(const char *bjid, const char *label,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
572 enum vcard_attr vcard_attrib, const char *text)
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
573 {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
574 char *buf;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
575
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
576 if (!text || !bjid || !label)
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
577 return;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
578
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
579 buf = g_strdup_printf("%s: %s%s%s%s%s%s%s%s%s%s", label,
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
580 (vcard_attrib & vcard_home ? "[home]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
581 (vcard_attrib & vcard_work ? "[work]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
582 (vcard_attrib & vcard_postal ? "[postal]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
583 (vcard_attrib & vcard_voice ? "[voice]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
584 (vcard_attrib & vcard_fax ? "[fax]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
585 (vcard_attrib & vcard_cell ? "[cell]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
586 (vcard_attrib & vcard_inet ? "[inet]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
587 (vcard_attrib & vcard_pref ? "[pref]" : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
588 (vcard_attrib ? " " : ""),
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
589 text);
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
590 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO | HBB_PREFIX_CONT, 0);
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
591 g_free(buf);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
592 }
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
593
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
594 static void handle_vcard_node(const char *barejid, xmlnode vcardnode)
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
595 {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
596 xmlnode x;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
597 const char *p;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
598
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
599 x = xmlnode_get_firstchild(vcardnode);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
600 for ( ; x; x = xmlnode_get_nextsibling(x)) {
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
601 const char *data;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
602 enum vcard_attr vcard_attrib = 0;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
603
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
604 p = xmlnode_get_name(x);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
605 data = xmlnode_get_data(x);
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
606 if (!p || !data)
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
607 continue;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
608
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
609 if (!strcmp(p, "FN"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
610 display_vcard_item(barejid, "Name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
611 else if (!strcmp(p, "NICKNAME"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
612 display_vcard_item(barejid, "Nickname", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
613 else if (!strcmp(p, "URL"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
614 display_vcard_item(barejid, "URL", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
615 else if (!strcmp(p, "BDAY"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
616 display_vcard_item(barejid, "Birthday", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
617 else if (!strcmp(p, "TZ"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
618 display_vcard_item(barejid, "Timezone", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
619 else if (!strcmp(p, "TITLE"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
620 display_vcard_item(barejid, "Title", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
621 else if (!strcmp(p, "ROLE"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
622 display_vcard_item(barejid, "Role", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
623 else if (!strcmp(p, "DESC"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
624 display_vcard_item(barejid, "Comment", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
625 else if (!strcmp(p, "N")) {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
626 data = xmlnode_get_tag_data(x, "FAMILY");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
627 display_vcard_item(barejid, "Family Name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
628 data = xmlnode_get_tag_data(x, "GIVEN");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
629 display_vcard_item(barejid, "Given Name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
630 data = xmlnode_get_tag_data(x, "MIDDLE");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
631 display_vcard_item(barejid, "Middle Name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
632 } else if (!strcmp(p, "ORG")) {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
633 data = xmlnode_get_tag_data(x, "ORGNAME");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
634 display_vcard_item(barejid, "Organisation name", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
635 data = xmlnode_get_tag_data(x, "ORGUNIT");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
636 display_vcard_item(barejid, "Organisation unit", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
637 } else {
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
638 // The HOME, WORK and PREF attributes are common to the remaining fields
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
639 // (ADR, TEL & EMAIL)
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
640 if (xmlnode_get_tag(x, "HOME"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
641 vcard_attrib |= vcard_home;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
642 if (xmlnode_get_tag(x, "WORK"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
643 vcard_attrib |= vcard_work;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
644 if (xmlnode_get_tag(x, "PREF"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
645 vcard_attrib |= vcard_pref;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
646 if (!strcmp(p, "ADR")) { // Address
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
647 if (xmlnode_get_tag(x, "POSTAL"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
648 vcard_attrib |= vcard_postal;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
649 data = xmlnode_get_tag_data(x, "EXTADD");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
650 display_vcard_item(barejid, "Addr (ext)", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
651 data = xmlnode_get_tag_data(x, "STREET");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
652 display_vcard_item(barejid, "Street", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
653 data = xmlnode_get_tag_data(x, "LOCALITY");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
654 display_vcard_item(barejid, "Locality", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
655 data = xmlnode_get_tag_data(x, "REGION");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
656 display_vcard_item(barejid, "Region", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
657 data = xmlnode_get_tag_data(x, "PCODE");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
658 display_vcard_item(barejid, "Postal code", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
659 data = xmlnode_get_tag_data(x, "CTRY");
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
660 display_vcard_item(barejid, "Country", vcard_attrib, data);
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
661 } else if (!strcmp(p, "TEL")) { // Telephone
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
662 data = xmlnode_get_tag_data(x, "NUMBER");
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
663 if (data) {
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
664 if (xmlnode_get_tag(x, "VOICE"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
665 vcard_attrib |= vcard_voice;
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
666 if (xmlnode_get_tag(x, "FAX"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
667 vcard_attrib |= vcard_fax;
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
668 if (xmlnode_get_tag(x, "CELL"))
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
669 vcard_attrib |= vcard_cell;
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
670 display_vcard_item(barejid, "Phone", vcard_attrib, data);
1005
e5c10cc29660 Improve vcard support
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
671 }
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
672 } else if (!strcmp(p, "EMAIL")) { // Email
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
673 if (xmlnode_get_tag(x, "INTERNET"))
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
674 vcard_attrib |= vcard_inet;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
675 data = xmlnode_get_tag_data(x, "USERID");
1006
f61131cd86a0 Clean up vcard code
Mikael Berthe <mikael@lilotux.net>
parents: 1005
diff changeset
676 display_vcard_item(barejid, "Email", vcard_attrib, data);
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
677 }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
678 }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
679 }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
680 }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
681
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
682 static int iqscallback_vcard(eviqs *iqp, xmlnode xml_result, guint iqcontext)
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
683 {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
684 xmlnode ansqry;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
685 char *p;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
686 char *bjid;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
687 char *buf;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
688
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
689 // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
690 if (!xml_result || iqcontext) return -1;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
691
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
692 // Display IQ result sender...
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
693 p = xmlnode_get_attrib(xml_result, "from");
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
694 if (!p) {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
695 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:vCard result (no sender name).");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
696 return 0;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
697 }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
698 bjid = p;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
699
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
700 buf = g_strdup_printf("Received IQ:vCard result from <%s>", bjid);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
701 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
702
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
703 // Get the vCard node
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
704 ansqry = xmlnode_get_tag(xml_result, "vCard");
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
705 if (!ansqry) {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
706 scr_LogPrint(LPRINT_LOGNORM, "Empty IQ:vCard result!");
1340
2031f4b2cced Fix a small memory leak
Mikael Berthe <mikael@lilotux.net>
parents: 1334
diff changeset
707 g_free(buf);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
708 return 0;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
709 }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
710
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
711 // bjid should really be the "bare JID", let's strip the resource
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
712 p = strchr(bjid, JID_RESOURCE_SEPARATOR);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
713 if (p) *p = '\0';
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
714
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1283
diff changeset
715 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO, 0);
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
716 g_free(buf);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
717
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
718 // Get result data...
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
719 handle_vcard_node(bjid, ansqry);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
720 return 0;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
721 }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
722
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
723 void request_vcard(const char *bjid)
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
724 {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
725 eviqs *iqn;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
726
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
727 // Create a new IQ structure. We use NULL for the namespace because
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
728 // we'll have to use a special tag, not the usual "query" one.
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
729 iqn = iqs_new(JPACKET__GET, NULL, "vcard", IQS_DEFAULT_TIMEOUT);
1310
a5336c44d4e2 Allow vcard requests to a full jid
Mikael Berthe <mikael@lilotux.net>
parents: 1290
diff changeset
730 xmlnode_put_attrib(iqn->xmldata, "to", bjid);
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
731 // Remove the useless <query/> tag, and insert a vCard one.
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
732 xmlnode_hide(xmlnode_get_tag(iqn->xmldata, "query"));
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
733 xmlnode_put_attrib(xmlnode_insert_tag(iqn->xmldata, "vCard"),
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
734 "xmlns", NS_VCARD);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
735 iqn->callback = &iqscallback_vcard;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
736 jab_send(jc, iqn->xmldata);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
737 }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1002
diff changeset
738
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
739 static void storage_bookmarks_parse_conference(xmlnode xmldata)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
740 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
741 const char *fjid, *name, *autojoin;
1379
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
742 const char *pstatus, *awhois;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
743 char *bjid;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
744 GSList *room_elt;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
745
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
746 fjid = xmlnode_get_attrib(xmldata, "jid");
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
747 if (!fjid)
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
748 return;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
749 name = xmlnode_get_attrib(xmldata, "name");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
750 autojoin = xmlnode_get_attrib(xmldata, "autojoin");
1379
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
751 awhois = xmlnode_get_attrib(xmldata, "autowhois");
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
752 pstatus = xmlnode_get_tag_data(xmldata, "print_status");
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
753
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
754 bjid = jidtodisp(fjid); // Bare jid
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
755
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
756 // Make sure this is a room (it can be a conversion user->room)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
757 room_elt = roster_find(bjid, jidsearch, 0);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
758 if (!room_elt) {
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1353
diff changeset
759 room_elt = roster_add_user(bjid, name, NULL, ROSTER_TYPE_ROOM,
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1353
diff changeset
760 sub_none, -1);
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
761 } else {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
762 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
763 /*
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
764 // If the name is available, should we use it?
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
765 // I don't think so, it would be confusing because this item is already
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
766 // in the roster.
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
767 if (name)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
768 buddy_setname(room_elt->data, name);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
769 */
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
770 }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
771
1379
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
772 // Set the print_status and auto_whois values
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
773 if (pstatus) {
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
774 enum room_printstatus i;
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
775 for (i = status_none; i <= status_all; i++)
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
776 if (!strcasecmp(pstatus, strprintstatus[i]))
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
777 break;
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
778 if (i <= status_all)
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
779 buddy_setprintstatus(room_elt->data, i);
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
780 }
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
781 if (awhois) {
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
782 enum room_autowhois i = autowhois_default;
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
783 if (!strcmp(awhois, "1"))
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
784 i = autowhois_on;
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
785 else if (!strcmp(awhois, "0"))
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
786 i = autowhois_off;
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
787 if (i != autowhois_default)
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
788 buddy_setautowhois(room_elt->data, i);
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
789 }
74b7621537d7 MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
790
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
791 // Is autojoin set?
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
792 // If it is, we'll look up for more information (nick? password?) and
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
793 // try to join the room.
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
794 if (autojoin && !strcmp(autojoin, "1")) {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
795 char *nick, *passwd;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
796 char *tmpnick = NULL;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
797 nick = xmlnode_get_tag_data(xmldata, "nick");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
798 passwd = xmlnode_get_tag_data(xmldata, "password");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
799 if (!nick || !*nick)
1395
d431cd75eb53 Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 1393
diff changeset
800 nick = tmpnick = default_muc_nickname(NULL);
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
801 // Let's join now
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
802 scr_LogPrint(LPRINT_LOGNORM, "Auto-join bookmark <%s>", bjid);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
803 jb_room_join(bjid, nick, passwd);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
804 g_free(tmpnick);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
805 }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
806 g_free(bjid);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
807 }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
808
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
809 static int iqscallback_storage_bookmarks(eviqs *iqp, xmlnode xml_result,
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
810 guint iqcontext)
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
811 {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
812 xmlnode x, ansqry;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
813 char *p;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
814
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
815 if (iqcontext == IQS_CONTEXT_ERROR) {
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
816 // No server support, or no bookmarks?
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
817 p = xmlnode_get_name(xmlnode_get_firstchild(xml_result));
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
818 if (p && !strcmp(p, "item-not-found")) {
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
819 // item-no-found means the server has Private Storage, but it's
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
820 // currently empty.
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
821 xmlnode_free(bookmarks);
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
822 bookmarks = xmlnode_new_tag("storage");
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
823 xmlnode_put_attrib(bookmarks, "xmlns", "storage:bookmarks");
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
824 // We return 0 so that the IQ error message be
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
825 // not displayed, as it isn't a real error.
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
826 return 0;
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
827 }
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
828 return -1; // Unhandled error
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
829 }
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
830
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
831 // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
832 if (!xml_result || iqcontext) return 0;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
833
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
834 ansqry = xmlnode_get_tag(xml_result, "query");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
835 ansqry = xmlnode_get_tag(ansqry, "storage");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
836 if (!ansqry) {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
837 scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! (storage:bookmarks)");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
838 return 0;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
839 }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
840
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
841 // Walk through the storage tags
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
842 x = xmlnode_get_firstchild(ansqry);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
843 for ( ; x; x = xmlnode_get_nextsibling(x)) {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
844 p = xmlnode_get_name(x);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
845 // If the current node is a conference item, parse it and update the roster
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
846 if (p && !strcmp(p, "conference"))
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
847 storage_bookmarks_parse_conference(x);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
848 }
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
849 // Copy the bookmarks node
1008
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
850 xmlnode_free(bookmarks);
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
851 bookmarks = xmlnode_dup(ansqry);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
852 return 0;
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
853 }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
854
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
855 static void request_storage_bookmarks(void)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
856 {
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
857 eviqs *iqn;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
858 xmlnode x;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
859
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
860 iqn = iqs_new(JPACKET__GET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
861
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
862 x = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "storage");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
863 xmlnode_put_attrib(x, "xmlns", "storage:bookmarks");
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
864
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
865 iqn->callback = &iqscallback_storage_bookmarks;
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
866 jab_send(jc, iqn->xmldata);
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
867 }
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
868
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
869 static int iqscallback_storage_rosternotes(eviqs *iqp, xmlnode xml_result,
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
870 guint iqcontext)
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
871 {
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
872 xmlnode ansqry;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
873
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
874 if (iqcontext == IQS_CONTEXT_ERROR) {
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
875 const char *p;
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
876 // No server support, or no roster notes?
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
877 p = xmlnode_get_name(xmlnode_get_firstchild(xml_result));
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
878 if (p && !strcmp(p, "item-not-found")) {
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
879 // item-no-found means the server has Private Storage, but it's
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
880 // currently empty.
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
881 xmlnode_free(rosternotes);
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
882 rosternotes = xmlnode_new_tag("storage");
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
883 xmlnode_put_attrib(rosternotes, "xmlns", "storage:rosternotes");
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
884 // We return 0 so that the IQ error message be
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
885 // not displayed, as it isn't a real error.
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
886 return 0;
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
887 }
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
888 return -1; // Unhandled error
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
889 }
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
890
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
891 // Leave now if we cannot process xml_result
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
892 if (!xml_result || iqcontext) return 0;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
893
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
894 ansqry = xmlnode_get_tag(xml_result, "query");
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
895 ansqry = xmlnode_get_tag(ansqry, "storage");
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
896 if (!ansqry) {
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
897 scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! "
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
898 "(storage:rosternotes)");
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
899 return 0;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
900 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
901 // Copy the rosternotes node
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
902 xmlnode_free(rosternotes);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
903 rosternotes = xmlnode_dup(ansqry);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
904 return 0;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
905 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
906
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
907 static void request_storage_rosternotes(void)
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
908 {
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
909 eviqs *iqn;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
910 xmlnode x;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
911
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
912 iqn = iqs_new(JPACKET__GET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
913
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
914 x = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "storage");
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
915 xmlnode_put_attrib(x, "xmlns", "storage:rosternotes");
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
916
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
917 iqn->callback = &iqscallback_storage_rosternotes;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
918 jab_send(jc, iqn->xmldata);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
919 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
920
1224
fb0460a3cf4b Fix iqscallback_auth() when authentication fails
Mikael Berthe <mikael@lilotux.net>
parents: 1218
diff changeset
921 int iqscallback_auth(eviqs *iqp, xmlnode xml_result, guint iqcontext)
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
922 {
1224
fb0460a3cf4b Fix iqscallback_auth() when authentication fails
Mikael Berthe <mikael@lilotux.net>
parents: 1218
diff changeset
923 if (iqcontext == IQS_CONTEXT_ERROR)
fb0460a3cf4b Fix iqscallback_auth() when authentication fails
Mikael Berthe <mikael@lilotux.net>
parents: 1218
diff changeset
924 return -1;
fb0460a3cf4b Fix iqscallback_auth() when authentication fails
Mikael Berthe <mikael@lilotux.net>
parents: 1218
diff changeset
925
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
926 if (jstate == STATE_GETAUTH) {
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 705
diff changeset
927 eviqs *iqn;
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
928
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
929 if (xml_result) {
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
930 xmlnode x = xmlnode_get_tag(xml_result, "query");
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
931 if (x && !xmlnode_get_tag(x, "digest"))
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
932 jc->sid = 0;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
933 }
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
934
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
935 iqn = iqs_new(JPACKET__SET, NS_AUTH, "auth", IQS_DEFAULT_TIMEOUT);
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
936 iqn->callback = &iqscallback_auth;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
937 jab_auth_mcabber(jc, iqn->xmldata);
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
938 jab_send(jc, iqn->xmldata);
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
939 jstate = STATE_SENDAUTH;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
940 } else if (jstate == STATE_SENDAUTH) {
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
941 request_roster();
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
942 request_storage_bookmarks();
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
943 request_storage_rosternotes();
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
944 jstate = STATE_LOGGED;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
945 }
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
946 return 0;
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
947 }
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 685
diff changeset
948
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
949 static void handle_iq_result(jconn conn, char *from, xmlnode xmldata)
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
950 {
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
951 char *id = xmlnode_get_attrib(xmldata, "id");
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
952
685
f033345d1315 Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
953 if (!id) {
596
6c7fd289648f Clean up handle_iq_result()
Mikael Berthe <mikael@lilotux.net>
parents: 595
diff changeset
954 scr_LogPrint(LPRINT_LOG, "IQ result stanza with no ID, ignored.");
6c7fd289648f Clean up handle_iq_result()
Mikael Berthe <mikael@lilotux.net>
parents: 595
diff changeset
955 return;
6c7fd289648f Clean up handle_iq_result()
Mikael Berthe <mikael@lilotux.net>
parents: 595
diff changeset
956 }
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
957
1353
7caedca15e50 Add post-connect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1348
diff changeset
958 (void)iqs_callback(id, xmldata, IQS_CONTEXT_RESULT);
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
959 }
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
960
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
961 // FIXME highly duplicated code
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
962 static void send_iq_not_implemented(jconn conn, char *from, xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
963 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
964 xmlnode x, y, z;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
965 // Not implemented.
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
966 x = xmlnode_dup(xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
967 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
968 xmlnode_hide_attrib(x, "from");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
969
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
970 xmlnode_put_attrib(x, "type", TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
971 y = xmlnode_insert_tag(x, TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
972 xmlnode_put_attrib(y, "code", "501");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
973 xmlnode_put_attrib(y, "type", "cancel");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
974 z = xmlnode_insert_tag(y, "feature-not-implemented");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
975 xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
976
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
977 jab_send(conn, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
978 xmlnode_free(x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
979 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
980
1261
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
981 // FIXME highly duplicated code
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
982 static void send_iq_not_available(jconn conn, char *from, xmlnode xmldata)
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
983 {
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
984 xmlnode x, y, z;
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
985 // Not available.
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
986 x = xmlnode_dup(xmldata);
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
987 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
988 xmlnode_hide_attrib(x, "from");
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
989
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
990 xmlnode_put_attrib(x, "type", TMSG_ERROR);
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
991 y = xmlnode_insert_tag(x, TMSG_ERROR);
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
992 xmlnode_put_attrib(y, "code", "503");
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
993 xmlnode_put_attrib(y, "type", "cancel");
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
994 z = xmlnode_insert_tag(y, "service-unavailable");
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
995 xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
996
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
997 jab_send(conn, x);
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
998 xmlnode_free(x);
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
999 }
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
1000
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1001 /*
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1002 static void send_iq_commands_bad_action(jconn conn, char *from, xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1003 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1004 xmlnode x, y, z;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1005
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1006 x = xmlnode_dup(xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1007 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1008 xmlnode_hide_attrib(x, "from");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1009
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1010 xmlnode_put_attrib(x, "type", TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1011 y = xmlnode_insert_tag(x, TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1012 xmlnode_put_attrib(y, "code", "400");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1013 xmlnode_put_attrib(y, "type", "modify");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1014 z = xmlnode_insert_tag(y, "bad-request");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1015 xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1016 z = xmlnode_insert_tag(y, "bad-action");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1017 xmlnode_put_attrib(z, "xmlns", NS_COMMANDS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1018
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1019 jab_send(conn, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1020 xmlnode_free(x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1021 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1022 */
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1023
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1024 static void send_iq_forbidden(jconn conn, char *from, xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1025 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1026 xmlnode x, y, z;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1027
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1028 x = xmlnode_dup(xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1029 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1030 xmlnode_hide_attrib(x, "from");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1031
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1032 xmlnode_put_attrib(x, "type", TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1033 y = xmlnode_insert_tag(x, TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1034 xmlnode_put_attrib(y, "code", "403");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1035 xmlnode_put_attrib(y, "type", "cancel");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1036 z = xmlnode_insert_tag(y, "forbidden");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1037 xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1038
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1039 jab_send(conn, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1040 xmlnode_free(x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1041 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1042
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1043 static void send_iq_commands_malformed_action(jconn conn, char *from,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1044 xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1045 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1046 xmlnode x, y, z;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1047
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1048 x = xmlnode_dup(xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1049 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1050 xmlnode_hide_attrib(x, "from");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1051
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1052 xmlnode_put_attrib(x, "type", TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1053 y = xmlnode_insert_tag(x, TMSG_ERROR);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1054 xmlnode_put_attrib(y, "code", "400");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1055 xmlnode_put_attrib(y, "type", "modify");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1056 z = xmlnode_insert_tag(y, "bad-request");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1057 xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1058 z = xmlnode_insert_tag(y, "malformed-action");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1059 xmlnode_put_attrib(z, "xmlns", NS_COMMANDS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1060
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1061 jab_send(conn, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1062 xmlnode_free(x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1063 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1064
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1065 static void handle_iq_commands_list(jconn conn, char *from, const char *id,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1066 xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1067 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1068 xmlnode x;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1069 xmlnode myquery;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1070 jid requester_jid;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1071 const struct adhoc_command *command;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1072 bool from_self;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1073 x = jutil_iqnew(JPACKET__RESULT, NS_DISCO_ITEMS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1074 xmlnode_put_attrib(x, "id", id);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1075 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1076 myquery = xmlnode_get_tag(x, "query");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1077
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1078 requester_jid = jid_new(conn->p, xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1079 from_self = !jid_cmpx(conn->user, requester_jid, JID_USER | JID_SERVER);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1080
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1081 for (command = adhoc_command_list ; command->name ; command++) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1082 if (!command->only_for_self || from_self) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1083 xmlnode item;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1084 item = xmlnode_insert_tag(myquery, "item");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1085 xmlnode_put_attrib(item, "node", command->name);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1086 xmlnode_put_attrib(item, "name", command->description);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1087 xmlnode_put_attrib(item, "jid", jid_full(conn->user));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1088 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1089 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1090
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1091 jab_send(jc, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1092 xmlnode_free(x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1093 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1094
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1095 static void xmlnode_insert_dataform_result_message(xmlnode node, char *message)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1096 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1097 xmlnode x = xmlnode_insert_tag(node, "x");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1098 xmlnode_put_attrib(x, "type", "result");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1099 xmlnode_put_attrib(x, "xmlns", "jabber:x:data");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1100
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1101 xmlnode field = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1102 xmlnode_put_attrib(field, "type", "text-single");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1103 xmlnode_put_attrib(field, "var", "message");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1104
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1105 xmlnode value = xmlnode_insert_tag(field, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1106 xmlnode_insert_cdata(value, message, -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1107 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1108
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1109 static char *generate_session_id(char *prefix)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1110 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1111 char *result;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1112 static int counter = 0;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1113 counter++;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1114 // TODO better use timezone ?
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1115 result = g_strdup_printf("%s-%i", prefix, counter);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1116 return result;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1117 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1118
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1119 static void handle_iq_command_set_status(jconn conn, char *from, const char *id,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1120 xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1121 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1122 char *action, *node, *sessionid;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1123 xmlnode iq, command, x, y;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1124 const struct adhoc_status *s;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1125
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1126 x = xmlnode_get_tag(xmldata, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1127 action = xmlnode_get_attrib(x, "action");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1128 node = xmlnode_get_attrib(x, "node");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1129 sessionid = xmlnode_get_attrib(x, "sessionid");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1130
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1131 iq = xmlnode_new_tag("iq");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1132 command = xmlnode_insert_tag(iq, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1133 xmlnode_put_attrib(command, "node", node);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1134 xmlnode_put_attrib(command, "xmlns", NS_COMMANDS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1135
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1136 if (!sessionid) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1137 sessionid = generate_session_id("set-status");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1138 xmlnode_put_attrib(command, "sessionid", sessionid);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1139 g_free(sessionid);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1140 xmlnode_put_attrib(command, "status", "executing");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1141
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1142 x = xmlnode_insert_tag(command, "x");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1143 xmlnode_put_attrib(x, "type", "form");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1144 xmlnode_put_attrib(x, "xmlns", "jabber:x:data");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1145
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1146 y = xmlnode_insert_tag(x, "title");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1147 xmlnode_insert_cdata(y, "Change Status", -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1148
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1149 y = xmlnode_insert_tag(x, "instructions");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1150 xmlnode_insert_cdata(y, "Choose the status and status message", -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1151
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1152 // TODO see if factorisation is possible
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1153 // (with xmlnode_insert_dataform_result_message)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1154 y = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1155 xmlnode_put_attrib(y, "type", "hidden");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1156 xmlnode_put_attrib(y, "var", "FORM_TYPE");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1157
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1158 xmlnode value = xmlnode_insert_tag(y, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1159 xmlnode_insert_cdata(value, "http://jabber.org/protocol/rc", -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1160
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1161 y = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1162 xmlnode_put_attrib(y, "type", "list-single");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1163 xmlnode_put_attrib(y, "var", "status");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1164 xmlnode_put_attrib(y, "label", "Status");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1165 xmlnode_insert_tag(y, "required");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1166
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1167 value = xmlnode_insert_tag(y, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1168 // TODO current status
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1169 xmlnode_insert_cdata(value, "online", -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1170 for (s = adhoc_status_list; s->name; s++) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1171 xmlnode option = xmlnode_insert_tag(y, "option");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1172 value = xmlnode_insert_tag(option, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1173 xmlnode_insert_cdata(value, s->name, -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1174 xmlnode_put_attrib(option, "label", s->description);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1175 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1176 // TODO add priority ?
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1177 // I do not think this is useful, user should not have to care of the
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1178 // priority like gossip and gajim do (misc)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1179 y = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1180 xmlnode_put_attrib(y, "type", "text-multi");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1181 xmlnode_put_attrib(y, "var", "status-message");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1182 xmlnode_put_attrib(y, "label", "Message");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1183 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1184 else // (if sessionid)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1185 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1186 y = xmlnode_get_tag(x, "x?xmlns=jabber:x:data");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1187 if (y) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1188 char *value, *message;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1189 value = xmlnode_get_tag_data(xmlnode_get_tag(y, "field?var=status"),
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1190 "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1191 message = xmlnode_get_tag_data(xmlnode_get_tag(y,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1192 "field?var=status-message"), "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1193 for (s = adhoc_status_list; !s->name || strcmp(s->name, value); s++);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1194 if (s->name) {
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1195 char *status = g_strdup_printf("%s %s", s->status,
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1196 message ? message : "");
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1197 setstatus(NULL, status);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1198 g_free(status);
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1199 xmlnode_put_attrib(command, "status", "completed");
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1200 xmlnode_put_attrib(iq, "type", "result");
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1201 xmlnode_insert_dataform_result_message(command,
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1202 "Status has been changed");
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1203 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1204 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1205 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1206 xmlnode_put_attrib(iq, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1207 xmlnode_put_attrib(iq, "id", id);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1208 jab_send(jc, iq);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1209 xmlnode_free(iq);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1210 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1211
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1212 static void _callback_foreach_buddy_groupchat(gpointer rosterdata, void *param)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1213 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1214 xmlnode value;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1215 xmlnode *field;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1216 const char *room_jid, *nickname;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1217 char *desc;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1218
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1219 room_jid = buddy_getjid(rosterdata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1220 if (!room_jid) return;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1221 nickname = buddy_getnickname(rosterdata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1222 if (!nickname) return;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1223 field = param;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1224
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1225 xmlnode option = xmlnode_insert_tag(*field, "option");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1226 value = xmlnode_insert_tag(option, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1227 xmlnode_insert_cdata(value, room_jid, -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1228 desc = g_strdup_printf("%s on %s", nickname, room_jid);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1229 xmlnode_put_attrib(option, "label", desc);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1230 g_free(desc);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1231 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1232
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1233 static void handle_iq_command_leave_groupchats(jconn conn, char *from,
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1234 const char *id, xmlnode xmldata)
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1235 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1236 char *action, *node, *sessionid;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1237 xmlnode iq, command, x;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1238
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1239 x = xmlnode_get_tag(xmldata, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1240 action = xmlnode_get_attrib(x, "action");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1241 node = xmlnode_get_attrib(x, "node");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1242 sessionid = xmlnode_get_attrib(x, "sessionid");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1243
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1244 iq = xmlnode_new_tag("iq");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1245 command = xmlnode_insert_tag(iq, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1246 xmlnode_put_attrib(command, "node", node);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1247 xmlnode_put_attrib(command, "xmlns", NS_COMMANDS);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1248
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1249 if (!sessionid) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1250 sessionid = generate_session_id("leave-groupchats");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1251 xmlnode_put_attrib(command, "sessionid", sessionid);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1252 g_free(sessionid);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1253 xmlnode_put_attrib(command, "status", "executing");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1254
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1255 x = xmlnode_insert_tag(command, "x");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1256 xmlnode_put_attrib(x, "type", "form");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1257 xmlnode_put_attrib(x, "xmlns", "jabber:x:data");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1258
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1259 xmlnode title = xmlnode_insert_tag(x, "title");
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1260 xmlnode_insert_cdata(title, "Leave groupchat(s)", -1);
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1261
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1262 xmlnode instructions = xmlnode_insert_tag(x, "instructions");
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1263 xmlnode_insert_cdata(instructions, "What groupchats do you want to leave?",
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1264 -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1265
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1266 xmlnode field = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1267 xmlnode_put_attrib(field, "type", "hidden");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1268 xmlnode_put_attrib(field, "var", "FORM_TYPE");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1269
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1270 xmlnode value = xmlnode_insert_tag(field, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1271 xmlnode_insert_cdata(value, "http://jabber.org/protocol/rc", -1);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1272
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1273 field = xmlnode_insert_tag(x, "field");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1274 xmlnode_put_attrib(field, "type", "list-multi");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1275 xmlnode_put_attrib(field, "var", "groupchats");
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1276 xmlnode_put_attrib(field, "label", "Groupchats: ");
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1277 xmlnode_insert_tag(field, "required");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1278
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1279 foreach_buddy(ROSTER_TYPE_ROOM, &_callback_foreach_buddy_groupchat, &field);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1280 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1281 else // (if sessionid)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1282 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1283 xmlnode form = xmlnode_get_tag(x, "x?xmlns=jabber:x:data");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1284 if (form) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1285 xmlnode_put_attrib(command, "status", "completed");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1286 xmlnode gc = xmlnode_get_tag(form, "field?var=groupchats");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1287 xmlnode x;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1288
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1289 for (x = xmlnode_get_firstchild(gc) ; x ; x = xmlnode_get_nextsibling(x))
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1290 {
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1291 char* to_leave = xmlnode_get_tag_data(x, "value");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1292 if (to_leave) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1293 GList* b = buddy_search_jid(to_leave);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1294 if (b)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1295 room_leave(b->data, "Asked by remote command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1296 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1297 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1298 xmlnode_put_attrib(iq, "type", "result");
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1299 xmlnode_insert_dataform_result_message(command,
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1300 "Groupchats have been left");
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1301 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1302 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1303 xmlnode_put_attrib(iq, "to", xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1304 xmlnode_put_attrib(iq, "id", id);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1305 jab_send(jc, iq);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1306 xmlnode_free(iq);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1307 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1308
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1309 static void handle_iq_commands(jconn conn, char *from, const char *id,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1310 xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1311 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1312 jid requester_jid;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1313 xmlnode x;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1314 const struct adhoc_command *command;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1315
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1316 requester_jid = jid_new(conn->p, xmlnode_get_attrib(xmldata, "from"));
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1317 x = xmlnode_get_tag(xmldata, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1318 if (!jid_cmpx(conn->user, requester_jid, JID_USER | JID_SERVER) ) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1319 char *action, *node;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1320 action = xmlnode_get_attrib(x, "action");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1321 node = xmlnode_get_attrib(x, "node");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1322 // action can be NULL, in which case it seems to take the default,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1323 // ie execute
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1324 if (!action || !strcmp(action, "execute") || !strcmp(action, "cancel")
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1325 || !strcmp(action, "next") || !strcmp(action, "complete")) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1326 for (command = adhoc_command_list; command->name; command++) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1327 if (!strcmp(node, command->name))
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1328 command->callback(conn, from, id, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1329 }
1159
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1330 // "prev" action will get there, as we do not implement it,
53c0c5be43fa Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1331 // and do not authorize it
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1332 } else {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1333 send_iq_commands_malformed_action(conn, from, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1334 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1335 } else {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1336 send_iq_forbidden(conn, from, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1337 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1338 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1339
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1340 static void handle_iq_disco_items(jconn conn, char *from, const char *id,
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1341 xmlnode xmldata)
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1342 {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1343 xmlnode x;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1344 char *node;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1345 x = xmlnode_get_tag(xmldata, "query");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1346 node = xmlnode_get_attrib(x, "node");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1347 if (node) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1348 if (!strcmp(node, NS_COMMANDS)) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1349 handle_iq_commands_list(conn, from, id, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1350 } else {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1351 send_iq_not_implemented(conn, from, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1352 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1353 } else {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1354 // not sure about this one
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1355 send_iq_not_implemented(conn, from, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1356 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1357 }
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1358
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1359 // disco_info_set_ext(ansquery, ext)
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1360 // Add features attributes to ansquery for extension ext.
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1361 static void disco_info_set_ext(xmlnode ansquery, const char *ext)
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1362 {
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1363 char *nodename;
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1364 nodename = g_strdup_printf("%s#%s", MCABBER_CAPS_NODE, ext);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1365 xmlnode_put_attrib(ansquery, "node", nodename);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1366 g_free(nodename);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1367 if (!strcasecmp(ext, "csn")) {
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1368 // I guess it's ok to send this even if it's not compiled in.
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1369 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1370 "var", NS_CHATSTATES);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1371 }
1255
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
1372 if (!strcasecmp(ext, "iql")) {
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
1373 // I guess it's ok to send this even if it's not compiled in.
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
1374 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
1375 "var", NS_LAST);
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
1376 }
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1377 }
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1378
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1379 // disco_info_set_default(ansquery, entitycaps)
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1380 // Add features attributes to ansquery. If entitycaps is TRUE, assume
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1381 // that we're answering an Entity Caps request (if not, the request was
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1382 // a basic discovery query).
1218
ab5de2ed2b7e Simplify entity_version()
Mikael Berthe <mikael@lilotux.net>
parents: 1217
diff changeset
1383 // Please change the entity version string if you modify mcabber disco
ab5de2ed2b7e Simplify entity_version()
Mikael Berthe <mikael@lilotux.net>
parents: 1217
diff changeset
1384 // source code, so that it doesn't conflict with the upstream client.
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1385 static void disco_info_set_default(xmlnode ansquery, guint entitycaps)
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1386 {
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1387 xmlnode y;
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1388 char *eversion;
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1389
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1390 eversion = g_strdup_printf("%s#%s", MCABBER_CAPS_NODE, entity_version());
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1391 xmlnode_put_attrib(ansquery, "node", eversion);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1392 g_free(eversion);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1393
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1394 y = xmlnode_insert_tag(ansquery, "identity");
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1395 xmlnode_put_attrib(y, "category", "client");
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1396 xmlnode_put_attrib(y, "type", "pc");
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1397 xmlnode_put_attrib(y, "name", PACKAGE_NAME);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1398
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1399 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1400 "var", NS_DISCO_INFO);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1401 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1402 "var", NS_MUC);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1403 #ifdef JEP0085
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1404 // Advertise ChatStates only if we're not using Entity Capabilities
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1405 if (!entitycaps)
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1406 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1407 "var", NS_CHATSTATES);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1408 #endif
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1409 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1410 "var", NS_TIME);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1411 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
1283
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1412 "var", NS_XMPP_TIME);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1413 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1414 "var", NS_VERSION);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1415 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1416 "var", NS_PING);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1417 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1418 "var", NS_COMMANDS);
1255
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
1419 if (!entitycaps)
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
1420 xmlnode_put_attrib(xmlnode_insert_tag(ansquery, "feature"),
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
1421 "var", NS_LAST);
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1422 }
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1423
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1424 static void handle_iq_disco_info(jconn conn, char *from, const char *id,
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1425 xmlnode xmldata)
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1426 {
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1427 xmlnode x;
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1428 xmlnode myquery;
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1429 char *node;
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1430
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1431 x = jutil_iqnew(JPACKET__RESULT, NS_DISCO_INFO);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1432 xmlnode_put_attrib(x, "id", id);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1433 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1434 myquery = xmlnode_get_tag(x, "query");
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1435
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1436 node = xmlnode_get_attrib(xmlnode_get_tag(xmldata, "query"), "node");
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1437 if (node && startswith(node, MCABBER_CAPS_NODE "#", FALSE)) {
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1438 const char *param = node+strlen(MCABBER_CAPS_NODE)+1;
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1439 if (!strcmp(param, entity_version()))
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1440 disco_info_set_default(myquery, TRUE); // client#version
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1441 else
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1442 disco_info_set_ext(myquery, param); // client#extension
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1443 } else {
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1444 // Basic discovery request
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1445 disco_info_set_default(myquery, FALSE);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
1446 }
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1447
1134
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1448 jab_send(jc, x);
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1449 xmlnode_free(x);
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1450 }
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1451
1254
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1452 inline double seconds_since_last_use(void)
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1453 {
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1454 return difftime(time(NULL), iqlast);
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1455 }
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1456
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1457 static void handle_iq_last(jconn conn, char *from, const char *id,
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1458 xmlnode xmldata)
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1459 {
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1460 xmlnode x;
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1461 xmlnode myquery;
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1462 char *seconds;
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1463
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1464 scr_LogPrint(LPRINT_LOGNORM, "Received an IQ last time request from <%s>",
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1465 from);
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1466
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1467 x = jutil_iqnew(JPACKET__RESULT, NS_LAST);
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1468 xmlnode_put_attrib(x, "id", id);
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1469 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1470 myquery = xmlnode_get_tag(x, "query");
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1471 seconds = g_strdup_printf("%.0f", seconds_since_last_use());
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1472 xmlnode_put_attrib(myquery, "seconds", seconds);
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1473 g_free(seconds);
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1474
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1475 jab_send(jc, x);
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1476 xmlnode_free(x);
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1477 }
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1224
diff changeset
1478
1134
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1479 static void handle_iq_ping(jconn conn, char *from, const char *id,
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1480 xmlnode xmldata)
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1481 {
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1482 xmlnode x;
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1483 x = jutil_iqresult(xmldata);
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1484 jab_send(jc, x);
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1485 }
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1486
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1487 static void handle_iq_version(jconn conn, char *from, const char *id,
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1488 xmlnode xmldata)
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1489 {
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1490 xmlnode x;
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1491 xmlnode myquery;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1492 char *os = NULL;
814
109dcf5fc111 Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 782
diff changeset
1493 char *ver = mcabber_version();
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1494
692
d3511f846d47 Cosmetics (line wrapping)
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
1495 scr_LogPrint(LPRINT_LOGNORM, "Received an IQ version request from <%s>",
d3511f846d47 Cosmetics (line wrapping)
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
1496 from);
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1497
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1498 if (!settings_opt_get_int("iq_version_hide_os")) {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1499 struct utsname osinfo;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1500 uname(&osinfo);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1501 os = g_strdup_printf("%s %s %s", osinfo.sysname, osinfo.release,
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1502 osinfo.machine);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1503 }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1504
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1505 x = jutil_iqnew(JPACKET__RESULT, NS_VERSION);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1506 xmlnode_put_attrib(x, "id", id);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1507 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1508 myquery = xmlnode_get_tag(x, "query");
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1509
814
109dcf5fc111 Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 782
diff changeset
1510 xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "name"), PACKAGE_NAME, -1);
109dcf5fc111 Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 782
diff changeset
1511 xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "version"), ver, -1);
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1512 if (os) {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1513 xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "os"), os, -1);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1514 g_free(os);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1515 }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1516
814
109dcf5fc111 Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents: 782
diff changeset
1517 g_free(ver);
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1518 jab_send(jc, x);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1519 xmlnode_free(x);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1520 }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1521
1361
0562106d20c1 Update some copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
1522 // This function borrows some code from the Pidgin project
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1523 static void handle_iq_time(jconn conn, char *from, const char *id,
1283
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1524 xmlnode xmldata)
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1525 {
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1526 xmlnode x;
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1527 xmlnode myquery;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1528 char *buf, *utf8_buf;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1529 time_t now_t;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1530 struct tm *now;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1531
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1532 time(&now_t);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1533
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1534 scr_LogPrint(LPRINT_LOGNORM, "Received an IQ time request from <%s>", from);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1535
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1536 buf = g_new0(char, 512);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1537
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1538 x = jutil_iqnew(JPACKET__RESULT, NS_TIME);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1539 xmlnode_put_attrib(x, "id", id);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1540 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1541 myquery = xmlnode_get_tag(x, "query");
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1542
703
8cbcbff8de7d Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
1543 now = gmtime(&now_t);
8cbcbff8de7d Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
1544
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1545 strftime(buf, 512, "%Y%m%dT%T", now);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1546 xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "utc"), buf, -1);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1547
703
8cbcbff8de7d Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
1548 now = localtime(&now_t);
8cbcbff8de7d Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
1549
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1550 strftime(buf, 512, "%Z", now);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1551 if ((utf8_buf = to_utf8(buf))) {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1552 xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "tz"), utf8_buf, -1);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1553 g_free(utf8_buf);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1554 }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1555
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1556 strftime(buf, 512, "%d %b %Y %T", now);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1557 if ((utf8_buf = to_utf8(buf))) {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1558 xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "display"), utf8_buf, -1);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1559 g_free(utf8_buf);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1560 }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1561
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1562 jab_send(jc, x);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1563 xmlnode_free(x);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1564 g_free(buf);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1565 }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1566
1361
0562106d20c1 Update some copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
1567 // This function borrows some code from the Pidgin project
1283
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1568 static void handle_iq_time202(jconn conn, char *from, const char *id,
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1569 xmlnode xmldata)
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1570 {
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1571 xmlnode x;
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1572 xmlnode myquery;
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1573 char *buf, *utf8_buf;
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1574 time_t now_t;
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1575 struct tm *now;
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1576 char const *sign;
1393
216b4da93e08 Do not use struct tm's tm_gmtoff if not available
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
1577 int diff = 0;
1283
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1578
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1579 time(&now_t);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1580
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1581 scr_LogPrint(LPRINT_LOGNORM, "Received an IQ time request from <%s>", from);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1582
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1583 buf = g_new0(char, 512);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1584
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1585 x = jutil_iqnew(JPACKET__RESULT, NULL);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1586 xmlnode_hide(xmlnode_get_tag(x, "query"));
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1587 xmlnode_put_attrib(xmlnode_insert_tag(x, "time"), "xmlns", NS_XMPP_TIME);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1588 xmlnode_put_attrib(x, "id", id);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1589 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1590 myquery = xmlnode_get_tag(x, "time");
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1591
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1592 now = localtime(&now_t);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1593
1393
216b4da93e08 Do not use struct tm's tm_gmtoff if not available
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
1594 if (now->tm_isdst >= 0) {
216b4da93e08 Do not use struct tm's tm_gmtoff if not available
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
1595 #if defined HAVE_TM_GMTOFF
1283
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1596 diff = now->tm_gmtoff;
1393
216b4da93e08 Do not use struct tm's tm_gmtoff if not available
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
1597 #elif defined HAVE_TIMEZONE
216b4da93e08 Do not use struct tm's tm_gmtoff if not available
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
1598 tzset();
216b4da93e08 Do not use struct tm's tm_gmtoff if not available
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
1599 diff = -timezone;
216b4da93e08 Do not use struct tm's tm_gmtoff if not available
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
1600 #endif
216b4da93e08 Do not use struct tm's tm_gmtoff if not available
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
1601 }
216b4da93e08 Do not use struct tm's tm_gmtoff if not available
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
1602
1283
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1603 if (diff < 0) {
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1604 sign = "-";
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1605 diff = -diff;
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1606 } else {
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1607 sign = "+";
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1608 }
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1609 diff /= 60;
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1610 snprintf(buf, 512, "%c%02d:%02d", *sign, diff / 60, diff % 60);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1611 if ((utf8_buf = to_utf8(buf))) {
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1612 xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "tzo"), utf8_buf, -1);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1613 g_free(utf8_buf);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1614 }
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1615
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1616 now = gmtime(&now_t);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1617
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1618 strftime(buf, 512, "%Y-%m-%dT%TZ", now);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1619 xmlnode_insert_cdata(xmlnode_insert_tag(myquery, "utc"), buf, -1);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1620
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1621 jab_send(jc, x);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1622 xmlnode_free(x);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1623 g_free(buf);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1624 }
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1625
1361
0562106d20c1 Update some copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
1626 // This function borrows some code from the Pidgin project
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
1627 static void handle_iq_get(jconn conn, char *from, xmlnode xmldata)
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1628 {
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1629 const char *id, *ns;
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1630 xmlnode x;
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1631 guint iq_not_implemented = FALSE;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1632
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
1633 id = xmlnode_get_attrib(xmldata, "id");
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1634 if (!id) {
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1635 scr_LogPrint(LPRINT_LOG, "IQ get stanza with no ID, ignored.");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1636 return;
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1637 }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1638
1134
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1639 x = xmlnode_get_tag(xmldata, "ping");
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1640 ns = xmlnode_get_attrib(x, "xmlns");
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1641 if (ns && !strcmp(ns, NS_PING)) {
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1642 handle_iq_ping(conn, from, id, xmldata);
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1643 return;
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1644 }
995dde656033 Response to XMPP Ping (XEP-0199)
misc@mandriva.org
parents: 1058
diff changeset
1645
1283
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1646 x = xmlnode_get_tag(xmldata, "time");
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1647 ns = xmlnode_get_attrib(x, "xmlns");
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1648 if (ns && !strcmp(ns, NS_XMPP_TIME)) {
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1649 handle_iq_time202(conn, from, id, xmldata);
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1650 return;
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1651 }
2faf179166f3 Implement XEP-0202 (Entity Time)
Mikael Berthe <mikael@lilotux.net>
parents: 1268
diff changeset
1652
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1653 x = xmlnode_get_tag(xmldata, "query");
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1654 ns = xmlnode_get_attrib(x, "xmlns");
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1655 if (ns && !strcmp(ns, NS_DISCO_INFO)) {
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1656 handle_iq_disco_info(conn, from, id, xmldata);
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1657 } else if (ns && !strcmp(ns, NS_DISCO_ITEMS)) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1658 handle_iq_disco_items(conn, from, id, xmldata);
995
c89e7993c4d9 Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
1659 } else if (ns && !strcmp(ns, NS_VERSION)) {
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1660 handle_iq_version(conn, from, id, xmldata);
1261
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
1661 } else if (ns && !strcmp(ns, NS_LAST)) {
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
1662 if (!settings_opt_get_int("iq_last_disable") &&
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
1663 (!settings_opt_get_int("iq_last_disable_when_notavail") ||
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
1664 jb_getstatus() != notavail))
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
1665 handle_iq_last(conn, from, id, xmldata);
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
1666 else
704adf4df2d0 Send service-unavailable when Last Activity is disabled
Mikael Berthe <mikael@lilotux.net>
parents: 1255
diff changeset
1667 send_iq_not_available(conn, from, xmldata);
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1668 } else if (ns && !strcmp(ns, NS_TIME)) {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1669 handle_iq_time(conn, from, id, xmldata);
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1670 } else {
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1671 iq_not_implemented = TRUE;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1672 }
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1673
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1674 if (!iq_not_implemented)
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1675 return;
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1676
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1677 send_iq_not_implemented(conn, from, xmldata);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1678 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1679
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
1680 static void handle_iq_set(jconn conn, char *from, xmlnode xmldata)
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1681 {
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1682 const char *id, *ns;
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1683 xmlnode x;
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1684 guint iq_not_implemented = FALSE;
595
0c1d37300862 IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents: 582
diff changeset
1685
0c1d37300862 IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents: 582
diff changeset
1686 id = xmlnode_get_attrib(xmldata, "id");
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1687 if (!id)
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1688 scr_LogPrint(LPRINT_LOG, "IQ set stanza with no ID...");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1689
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1690 x = xmlnode_get_tag(xmldata, "query");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1691 ns = xmlnode_get_attrib(x, "xmlns");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1692 if (ns && !strcmp(ns, NS_ROSTER)) {
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1693 handle_iq_roster(x);
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1694 } else {
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1695 x = xmlnode_get_tag(xmldata, "command");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1696 ns = xmlnode_get_attrib(x, "xmlns");
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1697 if (ns && !strcmp(ns, NS_COMMANDS)) {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1698 handle_iq_commands(conn, from, id, xmldata);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1699 } else {
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1700 iq_not_implemented = TRUE;
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1701 }
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1702 }
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1703
595
0c1d37300862 IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents: 582
diff changeset
1704 if (!id) return;
0c1d37300862 IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents: 582
diff changeset
1705
619
44ddf9bec3a5 Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
1706 if (!iq_not_implemented) {
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1707 x = xmlnode_new_tag("iq");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1708 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1709 xmlnode_put_attrib(x, "type", "result");
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1710 xmlnode_put_attrib(x, "id", id);
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1711 jab_send(conn, x);
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1712 xmlnode_free(x);
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1713 } else {
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1134
diff changeset
1714 send_iq_not_implemented(conn, from, xmldata);
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 606
diff changeset
1715 }
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
1716 }
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1717
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
1718 void handle_packet_iq(jconn conn, char *type, char *from, xmlnode xmldata)
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
1719 {
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1720 if (!type)
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1721 return;
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1722
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1723 if (!strcmp(type, "result")) {
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
1724 handle_iq_result(conn, from, xmldata);
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1725 } else if (!strcmp(type, "get")) {
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
1726 handle_iq_get(conn, from, xmldata);
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1727 } else if (!strcmp(type, "set")) {
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
1728 handle_iq_set(conn, from, xmldata);
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1729 } else if (!strcmp(type, TMSG_ERROR)) {
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
1730 // Display a message only if the error isn't caught by a callback.
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
1731 xmlnode x = xmlnode_get_tag(xmldata, TMSG_ERROR);
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
1732 if (iqs_callback(xmlnode_get_attrib(xmldata, "id"), x, IQS_CONTEXT_ERROR))
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1733 display_server_error(x);
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1734 }
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1735 }
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1736
1008
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1737 // send_storage_bookmarks()
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1738 // Send the current bookmarks node to update the server.
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1739 // Note: the sender should check we're online.
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1740 void send_storage_bookmarks(void)
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1741 {
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1742 eviqs *iqn;
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1743
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1744 if (!bookmarks) return;
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1745
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1746 iqn = iqs_new(JPACKET__SET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT);
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1747 xmlnode_insert_node(xmlnode_get_tag(iqn->xmldata, "query"), bookmarks);
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1748
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1749 jab_send(jc, iqn->xmldata);
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1750 iqs_del(iqn->id); // XXX
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1751 }
bbf53cd43fbb Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1006
diff changeset
1752
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1753 // send_storage_rosternotes()
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1754 // Send the current rosternotes node to update the server.
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1755 // Note: the sender should check we're online.
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1756 void send_storage_rosternotes(void)
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1757 {
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1758 eviqs *iqn;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1759
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1760 if (!rosternotes) return;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1761
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1762 iqn = iqs_new(JPACKET__SET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1763 xmlnode_insert_node(xmlnode_get_tag(iqn->xmldata, "query"), rosternotes);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1764
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1765 jab_send(jc, iqn->xmldata);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1766 iqs_del(iqn->id); // XXX
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1767 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
1768
580
fed6d1e4d7a9 Fix modelines
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1769 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */