Mercurial > hg
annotate mcabber/src/jab_iq.c @ 1161:45d3b9dda43d
Fix a MUC problem with some servers
Do not assume the role is set to None when somebody leaves a room.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 16 Feb 2007 16:05:02 +0100 |
parents | 53c0c5be43fa |
children | 3a2ac3d96eed |
rev | line source |
---|---|
29 | 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 | 3 * |
699 | 4 * Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.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 | 6 * Copyright (C) 2002-2005 by Konstantin Klyagin <konst@konst.org.ua> |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
7 * Some small parts come from the Gaim project <http://gaim.sourceforge.net/> |
29 | 8 * |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or (at | |
12 * your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 * USA | |
23 */ | |
24 | |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
25 #include <sys/utsname.h> |
603 | 26 #include <glib.h> |
27 | |
29 | 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 | 30 #include "roster.h" |
29 | 31 #include "utils.h" |
603 | 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" |
164 | 36 |
683 | 37 |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
38 // Bookmarks for IQ:private storage |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
39 xmlnode bookmarks; |
1016 | 40 // Roster notes for IQ:private storage |
41 xmlnode rosternotes; | |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
42 |
683 | 43 static GSList *iqs_list; |
44 | |
1006 | 45 // Enum for vCard attributes |
46 enum vcard_attr { | |
47 vcard_home = 1<<0, | |
48 vcard_work = 1<<1, | |
49 vcard_postal = 1<<2, | |
50 vcard_voice = 1<<3, | |
51 vcard_fax = 1<<4, | |
52 vcard_cell = 1<<5, | |
53 vcard_inet = 1<<6, | |
54 vcard_pref = 1<<7, | |
55 }; | |
683 | 56 |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
57 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
|
58 const char *id, xmlnode xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
59 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
60 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
|
61 const char *id, xmlnode xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
62 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
63 typedef void (*adhoc_command_callback)(jconn, char*, const char*, xmlnode); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
64 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
65 struct adhoc_command { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
66 char *name; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
67 char *description; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
68 bool only_for_self; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
69 adhoc_command_callback callback; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
70 }; |
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 const struct adhoc_command adhoc_command_list[] = { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
73 { "http://jabber.org/protocol/rc#set-status", |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
74 "Change client status", |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
75 1, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
76 &handle_iq_command_set_status }, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
77 { "http://jabber.org/protocol/rc#leave-groupchats", |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
78 "Leave groupchat(s)", |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
79 1, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
80 &handle_iq_command_leave_groupchats }, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
81 { NULL, NULL, 0, NULL }, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
82 }; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
83 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
84 struct adhoc_status { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
85 char *name; // the name used by adhoc |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
86 char *description; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
87 char *status; // the string, used by setstus |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
88 }; |
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 const struct adhoc_status adhoc_status_list[] = { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
91 {"online", "Online", "avail"}, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
92 {"chat", "Chat", "free"}, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
93 {"away", "Away", "away"}, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
94 {"xd", "Extended away", "notavail"}, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
95 {"dnd", "Do not disturb", "dnd"}, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
96 {"invisible", "Invisible", "invisible"}, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
97 {"offline", "Offline", "offline"}, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
98 {NULL, NULL, NULL}, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
99 }; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
100 |
683 | 101 // iqs_new(type, namespace, prefix, timeout) |
102 // Create a query (GET, SET) IQ structure. This function should not be used | |
103 // for RESULT packets. | |
1058 | 104 eviqs *iqs_new(guint8 type, const char *ns, const char *prefix, time_t tmout) |
683 | 105 { |
106 static guint iqs_idn; | |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
107 eviqs *new_iqs; |
683 | 108 time_t now_t; |
109 | |
110 iqs_idn++; | |
111 | |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
112 new_iqs = g_new0(eviqs, 1); |
683 | 113 time(&now_t); |
114 new_iqs->ts_create = now_t; | |
1058 | 115 if (tmout) |
116 new_iqs->ts_expire = now_t + tmout; | |
683 | 117 new_iqs->type = type; |
118 new_iqs->xmldata = jutil_iqnew(type, (char*)ns); | |
119 if (prefix) | |
687
426145046b93
Minor format change in IQ id string
Mikael Berthe <mikael@lilotux.net>
parents:
686
diff
changeset
|
120 new_iqs->id = g_strdup_printf("%s_%d", prefix, iqs_idn); |
683 | 121 else |
122 new_iqs->id = g_strdup_printf("%d", iqs_idn); | |
123 xmlnode_put_attrib(new_iqs->xmldata, "id", new_iqs->id); | |
124 | |
125 iqs_list = g_slist_append(iqs_list, new_iqs); | |
126 return new_iqs; | |
127 } | |
128 | |
129 int iqs_del(const char *iqid) | |
130 { | |
131 GSList *p; | |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
132 eviqs *i; |
683 | 133 |
134 if (!iqid) return 1; | |
135 | |
136 for (p = iqs_list; p; p = g_slist_next(p)) { | |
137 i = p->data; | |
138 if (!strcmp(iqid, i->id)) | |
139 break; | |
140 } | |
141 if (p) { | |
142 g_free(i->id); | |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
143 xmlnode_free(i->xmldata); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
144 g_free(i->data); |
683 | 145 g_free(i); |
146 iqs_list = g_slist_remove(iqs_list, p->data); | |
147 return 0; // Ok, deleted | |
148 } | |
149 return -1; // Not found | |
150 } | |
151 | |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
152 static eviqs *iqs_find(const char *iqid) |
683 | 153 { |
154 GSList *p; | |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
155 eviqs *i; |
683 | 156 |
157 if (!iqid) return NULL; | |
158 | |
159 for (p = iqs_list; p; p = g_slist_next(p)) { | |
160 i = p->data; | |
161 if (!strcmp(iqid, i->id)) | |
162 return i; | |
163 } | |
164 return NULL; | |
165 } | |
166 | |
698
60522cf6d325
Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
692
diff
changeset
|
167 // iqs_callback(iqid, xml_result, iqcontext) |
683 | 168 // Callback processing for the iqid message. |
169 // If we've received an answer, xml_result should point to the xmldata packet. | |
170 // If this is a timeout, xml_result should be NULL. | |
171 // 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
|
172 int iqs_callback(const char *iqid, xmlnode xml_result, guint iqcontext) |
683 | 173 { |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
174 eviqs *i; |
683 | 175 |
176 i = iqs_find(iqid); | |
177 if (!i) return -1; | |
178 | |
179 // IQ processing | |
180 // Note: If xml_result is NULL, this is a timeout | |
181 if (i->callback) | |
698
60522cf6d325
Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
692
diff
changeset
|
182 (*i->callback)(i, xml_result, iqcontext); |
683 | 183 |
184 iqs_del(iqid); | |
185 return 0; | |
186 } | |
187 | |
705
603b43e4f56a
Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents:
704
diff
changeset
|
188 void iqs_check_timeout(time_t now_t) |
683 | 189 { |
190 GSList *p; | |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
191 eviqs *i; |
683 | 192 |
705
603b43e4f56a
Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents:
704
diff
changeset
|
193 p = iqs_list; |
603b43e4f56a
Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents:
704
diff
changeset
|
194 while (p) { |
603b43e4f56a
Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents:
704
diff
changeset
|
195 i = p->data; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
196 // 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
|
197 // could be freed. |
603b43e4f56a
Fix a bug in iqs_check_timeout()
Mikael Berthe <mikael@lilotux.net>
parents:
704
diff
changeset
|
198 p = g_slist_next(p); |
683 | 199 |
965
1bdf0f1b16c0
Use U suffix for unsigned defines
Mikael Berthe <mikael@lilotux.net>
parents:
959
diff
changeset
|
200 if ((!i->ts_expire && now_t > i->ts_create + (time_t)IQS_MAX_TIMEOUT) || |
683 | 201 (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
|
202 iqs_callback(i->id, NULL, IQS_CONTEXT_TIMEOUT); |
683 | 203 } |
204 } | |
205 } | |
206 | |
689
281aab5aef50
Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents:
688
diff
changeset
|
207 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
|
208 { |
281aab5aef50
Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents:
688
diff
changeset
|
209 GSList *p; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
210 eviqs *i; |
689
281aab5aef50
Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents:
688
diff
changeset
|
211 |
281aab5aef50
Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents:
688
diff
changeset
|
212 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
|
213 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
|
214 i = p->data; |
281aab5aef50
Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents:
688
diff
changeset
|
215 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
|
216 } |
281aab5aef50
Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents:
688
diff
changeset
|
217 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
|
218 } |
281aab5aef50
Introduce jb_iqs_display_list() helper function for debugging
Mikael Berthe <mikael@lilotux.net>
parents:
688
diff
changeset
|
219 |
606
0b4ed231ebc2
Code cleanup + remove deprecated Agents list IQ request
Mikael Berthe <mikael@lilotux.net>
parents:
605
diff
changeset
|
220 static void request_roster(void) |
29 | 221 { |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
222 eviqs *iqn = iqs_new(JPACKET__GET, NS_ROSTER, "Roster", IQS_DEFAULT_TIMEOUT); |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
683
diff
changeset
|
223 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
683
diff
changeset
|
224 iqs_del(iqn->id); // XXX |
29 | 225 } |
226 | |
606
0b4ed231ebc2
Code cleanup + remove deprecated Agents list IQ request
Mikael Berthe <mikael@lilotux.net>
parents:
605
diff
changeset
|
227 static void handle_iq_roster(xmlnode x) |
29 | 228 { |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
229 xmlnode y; |
1058 | 230 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
|
231 char *cleanalias; |
603 | 232 enum subscr esub; |
233 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
|
234 guint roster_type; |
29 | 235 |
236 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { | |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
237 |
1058 | 238 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
|
239 name = xmlnode_get_attrib(y, "name"); |
603 | 240 sub = xmlnode_get_attrib(y, "subscription"); |
605
2a4fefb98511
Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents:
603
diff
changeset
|
241 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
|
242 |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
243 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
|
244 |
1058 | 245 if (!fjid) |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
246 continue; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
247 |
1058 | 248 cleanalias = jidtodisp(fjid); |
29 | 249 |
603 | 250 esub = sub_none; |
251 if (sub) { | |
252 if (!strcmp(sub, "to")) esub = sub_to; | |
253 else if (!strcmp(sub, "from")) esub = sub_from; | |
254 else if (!strcmp(sub, "both")) esub = sub_both; | |
255 else if (!strcmp(sub, "remove")) esub = sub_remove; | |
256 } | |
257 | |
258 if (esub == sub_remove) { | |
259 roster_del_user(cleanalias); | |
260 scr_LogPrint(LPRINT_LOGNORM, "Buddy <%s> has been removed " | |
261 "from the roster", cleanalias); | |
262 g_free(cleanalias); | |
263 need_refresh = TRUE; | |
264 continue; | |
265 } | |
266 | |
605
2a4fefb98511
Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents:
603
diff
changeset
|
267 if (ask && !strcmp(ask, "subscribe")) |
2a4fefb98511
Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents:
603
diff
changeset
|
268 esub |= sub_pending; |
2a4fefb98511
Set the subscription pending flag
Mikael Berthe <mikael@lilotux.net>
parents:
603
diff
changeset
|
269 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
746
diff
changeset
|
270 if (!name) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
746
diff
changeset
|
271 name = cleanalias; |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
272 |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
965
diff
changeset
|
273 // 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
|
274 // this is an agent. |
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
965
diff
changeset
|
275 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
|
276 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
|
277 else |
a6b8b373e4de
Try to guess if a roster item is an agent
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
278 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
|
279 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
746
diff
changeset
|
280 roster_add_user(cleanalias, name, group, roster_type, esub); |
603 | 281 |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
282 g_free(cleanalias); |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
283 } |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
284 |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
285 buddylist_build(); |
603 | 286 update_roster = TRUE; |
287 if (need_refresh) | |
959
8bf36cef8aa6
Do not enter chat mode after command "/del"
Mikael Berthe <mikael@lilotux.net>
parents:
871
diff
changeset
|
288 scr_UpdateBuddyWindow(); |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
289 } |
29 | 290 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
746
diff
changeset
|
291 static void iqscallback_version(eviqs *iqp, xmlnode xml_result, guint iqcontext) |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
292 { |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
293 xmlnode ansqry; |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
294 char *p; |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
295 char *bjid; |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
296 char *buf; |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
297 |
698
60522cf6d325
Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
692
diff
changeset
|
298 // Leave now if we cannot process xml_result |
60522cf6d325
Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
692
diff
changeset
|
299 if (!xml_result || iqcontext) return; |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
300 |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
301 ansqry = xmlnode_get_tag(xml_result, "query"); |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
302 if (!ansqry) { |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
303 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result!"); |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
304 return; |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
305 } |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
306 // Display IQ result sender... |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
307 p = xmlnode_get_attrib(xml_result, "from"); |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
308 if (!p) { |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
309 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:version result (no sender name)."); |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
310 return; |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
311 } |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
746
diff
changeset
|
312 bjid = p; |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
313 |
782
19121d9f4aa2
Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents:
776
diff
changeset
|
314 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
|
315 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
|
316 |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
317 // 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
|
318 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
|
319 if (p) *p = '\0'; |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
320 |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
321 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO); |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
322 g_free(buf); |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
323 |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
324 // Get result data... |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
325 p = xmlnode_get_tag_data(ansqry, "name"); |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
326 if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
327 buf = g_strdup_printf("Name: %s", p); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
328 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
329 g_free(buf); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
330 } |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
331 p = xmlnode_get_tag_data(ansqry, "version"); |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
332 if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
333 buf = g_strdup_printf("Version: %s", p); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
334 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
335 g_free(buf); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
336 } |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
337 p = xmlnode_get_tag_data(ansqry, "os"); |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
338 if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
339 buf = g_strdup_printf("OS: %s", p); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
340 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
341 g_free(buf); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
342 } |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
343 } |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
344 |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
345 void request_version(const char *fulljid) |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
346 { |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
347 eviqs *iqn; |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
348 |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
349 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
|
350 xmlnode_put_attrib(iqn->xmldata, "to", fulljid); |
690
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
351 iqn->callback = &iqscallback_version; |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
352 jab_send(jc, iqn->xmldata); |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
353 } |
3e965a1186c7
Implement IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
689
diff
changeset
|
354 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
746
diff
changeset
|
355 static void iqscallback_time(eviqs *iqp, xmlnode xml_result, guint iqcontext) |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
356 { |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
357 xmlnode ansqry; |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
358 char *p; |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
359 char *bjid; |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
360 char *buf; |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
361 |
698
60522cf6d325
Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
692
diff
changeset
|
362 // Leave now if we cannot process xml_result |
60522cf6d325
Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
692
diff
changeset
|
363 if (!xml_result || iqcontext) return; |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
364 |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
365 ansqry = xmlnode_get_tag(xml_result, "query"); |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
366 if (!ansqry) { |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
367 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result!"); |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
368 return; |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
369 } |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
370 // Display IQ result sender... |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
371 p = xmlnode_get_attrib(xml_result, "from"); |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
372 if (!p) { |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
373 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:time result (no sender name)."); |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
374 return; |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
375 } |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
746
diff
changeset
|
376 bjid = p; |
704
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
377 |
782
19121d9f4aa2
Nicer message when receiving IQ result packet
Mikael Berthe <mikael@lilotux.net>
parents:
776
diff
changeset
|
378 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
|
379 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
|
380 |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
381 // 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
|
382 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
|
383 if (p) *p = '\0'; |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
384 |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
385 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO); |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
386 g_free(buf); |
4118a66f2c02
Display IQ results (time, version) in the chat window
Mikael Berthe <mikael@lilotux.net>
parents:
703
diff
changeset
|
387 |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
388 // Get result data... |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
389 p = xmlnode_get_tag_data(ansqry, "utc"); |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
390 if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
391 buf = g_strdup_printf("UTC: %s", p); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
392 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
393 g_free(buf); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
394 } |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
395 p = xmlnode_get_tag_data(ansqry, "tz"); |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
396 if (p) { |
1030
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
397 buf = g_strdup_printf("TZ: %s", p); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
398 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
399 g_free(buf); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
400 } |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
401 p = xmlnode_get_tag_data(ansqry, "display"); |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
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("Time: %s", p); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
404 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE); |
923cf5a92b44
[BP-dd9e7eb5f8a8] Remove old UTF-8 conversions
Mikael Berthe <mikael@lilotux.net>
parents:
965
diff
changeset
|
405 g_free(buf); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
406 } |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
407 } |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
408 |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
409 void request_time(const char *fulljid) |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
410 { |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
411 eviqs *iqn; |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
412 |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
413 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
|
414 xmlnode_put_attrib(iqn->xmldata, "to", fulljid); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
415 iqn->callback = &iqscallback_time; |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
416 jab_send(jc, iqn->xmldata); |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
417 } |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
690
diff
changeset
|
418 |
1015 | 419 static void iqscallback_last(eviqs *iqp, xmlnode xml_result, guint iqcontext) |
420 { | |
421 xmlnode ansqry; | |
422 char *p; | |
423 char *bjid; | |
424 char *buf; | |
425 | |
426 // Leave now if we cannot process xml_result | |
427 if (!xml_result || iqcontext) return; | |
428 | |
429 ansqry = xmlnode_get_tag(xml_result, "query"); | |
430 if (!ansqry) { | |
431 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result!"); | |
432 return; | |
433 } | |
434 // Display IQ result sender... | |
435 p = xmlnode_get_attrib(xml_result, "from"); | |
436 if (!p) { | |
437 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:last result (no sender name)."); | |
438 return; | |
439 } | |
440 bjid = p; | |
441 | |
442 buf = g_strdup_printf("Received IQ:last result from <%s>", bjid); | |
443 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); | |
444 | |
445 // bjid should now really be the "bare JID", let's strip the resource | |
446 p = strchr(bjid, JID_RESOURCE_SEPARATOR); | |
447 if (p) *p = '\0'; | |
448 | |
449 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO); | |
450 g_free(buf); | |
451 | |
452 // Get result data... | |
453 p = xmlnode_get_attrib(ansqry, "seconds"); | |
454 if (p) { | |
455 long int s; | |
456 GString *sbuf; | |
457 sbuf = g_string_new("Idle time: "); | |
458 s = atol(p); | |
459 // Days | |
460 if (s > 86400L) { | |
461 g_string_append_printf(sbuf, "%ldd ", s/86400L); | |
462 s %= 86400L; | |
463 } | |
464 // hh:mm:ss | |
465 g_string_append_printf(sbuf, "%02ld:", s/3600L); | |
466 s %= 3600L; | |
467 g_string_append_printf(sbuf, "%02ld:%02ld", s/60L, s%60L); | |
468 scr_WriteIncomingMessage(bjid, sbuf->str, 0, HBB_PREFIX_NONE); | |
469 g_string_free(sbuf, TRUE); | |
470 } else { | |
471 scr_WriteIncomingMessage(bjid, "No idle time reported.", | |
472 0, HBB_PREFIX_NONE); | |
473 } | |
474 p = xmlnode_get_data(ansqry); | |
475 if (p) { | |
476 buf = g_strdup_printf("Status message: %s", p); | |
477 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO); | |
478 g_free(buf); | |
479 } | |
480 } | |
481 | |
482 void request_last(const char *fulljid) | |
483 { | |
484 eviqs *iqn; | |
485 | |
486 iqn = iqs_new(JPACKET__GET, NS_LAST, "last", IQS_DEFAULT_TIMEOUT); | |
487 xmlnode_put_attrib(iqn->xmldata, "to", fulljid); | |
488 iqn->callback = &iqscallback_last; | |
489 jab_send(jc, iqn->xmldata); | |
490 } | |
491 | |
1006 | 492 static void display_vcard_item(const char *bjid, const char *label, |
493 enum vcard_attr vcard_attrib, const char *text) | |
494 { | |
495 char *buf; | |
496 | |
497 if (!text || !bjid || !label) | |
498 return; | |
499 | |
500 buf = g_strdup_printf("%s: %s%s%s%s%s%s%s%s%s%s", label, | |
501 (vcard_attrib & vcard_home ? "[home]" : ""), | |
502 (vcard_attrib & vcard_work ? "[work]" : ""), | |
503 (vcard_attrib & vcard_postal ? "[postal]" : ""), | |
504 (vcard_attrib & vcard_voice ? "[voice]" : ""), | |
505 (vcard_attrib & vcard_fax ? "[fax]" : ""), | |
506 (vcard_attrib & vcard_cell ? "[cell]" : ""), | |
507 (vcard_attrib & vcard_inet ? "[inet]" : ""), | |
508 (vcard_attrib & vcard_pref ? "[pref]" : ""), | |
509 (vcard_attrib ? " " : ""), | |
510 text); | |
511 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_NONE); | |
512 g_free(buf); | |
513 } | |
514 | |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
515 static void handle_vcard_node(const char *barejid, xmlnode vcardnode) |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
516 { |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
517 xmlnode x; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
518 const char *p; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
519 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
520 x = xmlnode_get_firstchild(vcardnode); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
521 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
1006 | 522 const char *data; |
523 enum vcard_attr vcard_attrib = 0; | |
524 | |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
525 p = xmlnode_get_name(x); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
526 data = xmlnode_get_data(x); |
1006 | 527 if (!p || !data) |
528 continue; | |
529 | |
530 if (!strcmp(p, "FN")) | |
531 display_vcard_item(barejid, "Name", vcard_attrib, data); | |
532 else if (!strcmp(p, "NICKNAME")) | |
533 display_vcard_item(barejid, "Nickname", vcard_attrib, data); | |
534 else if (!strcmp(p, "URL")) | |
535 display_vcard_item(barejid, "URL", vcard_attrib, data); | |
536 else if (!strcmp(p, "BDAY")) | |
537 display_vcard_item(barejid, "Birthday", vcard_attrib, data); | |
538 else if (!strcmp(p, "TZ")) | |
539 display_vcard_item(barejid, "Timezone", vcard_attrib, data); | |
540 else if (!strcmp(p, "TITLE")) | |
541 display_vcard_item(barejid, "Title", vcard_attrib, data); | |
542 else if (!strcmp(p, "ROLE")) | |
543 display_vcard_item(barejid, "Role", vcard_attrib, data); | |
544 else if (!strcmp(p, "DESC")) | |
545 display_vcard_item(barejid, "Comment", vcard_attrib, data); | |
546 else if (!strcmp(p, "N")) { | |
547 data = xmlnode_get_tag_data(x, "FAMILY"); | |
548 display_vcard_item(barejid, "Family Name", vcard_attrib, data); | |
549 data = xmlnode_get_tag_data(x, "GIVEN"); | |
550 display_vcard_item(barejid, "Given Name", vcard_attrib, data); | |
551 data = xmlnode_get_tag_data(x, "MIDDLE"); | |
552 display_vcard_item(barejid, "Middle Name", vcard_attrib, data); | |
553 } else if (!strcmp(p, "ORG")) { | |
554 data = xmlnode_get_tag_data(x, "ORGNAME"); | |
555 display_vcard_item(barejid, "Organisation name", vcard_attrib, data); | |
556 data = xmlnode_get_tag_data(x, "ORGUNIT"); | |
557 display_vcard_item(barejid, "Organisation unit", vcard_attrib, data); | |
558 } else { | |
559 // The HOME, WORK and PREF attributes are common to the remaining fields | |
560 // (ADR, TEL & EMAIL) | |
561 if (xmlnode_get_tag(x, "HOME")) | |
562 vcard_attrib |= vcard_home; | |
563 if (xmlnode_get_tag(x, "WORK")) | |
564 vcard_attrib |= vcard_work; | |
565 if (xmlnode_get_tag(x, "PREF")) | |
566 vcard_attrib |= vcard_pref; | |
567 if (!strcmp(p, "ADR")) { // Address | |
1005 | 568 if (xmlnode_get_tag(x, "POSTAL")) |
1006 | 569 vcard_attrib |= vcard_postal; |
570 data = xmlnode_get_tag_data(x, "EXTADD"); | |
571 display_vcard_item(barejid, "Addr (ext)", vcard_attrib, data); | |
572 data = xmlnode_get_tag_data(x, "STREET"); | |
573 display_vcard_item(barejid, "Street", vcard_attrib, data); | |
574 data = xmlnode_get_tag_data(x, "LOCALITY"); | |
575 display_vcard_item(barejid, "Locality", vcard_attrib, data); | |
576 data = xmlnode_get_tag_data(x, "REGION"); | |
577 display_vcard_item(barejid, "Region", vcard_attrib, data); | |
578 data = xmlnode_get_tag_data(x, "PCODE"); | |
579 display_vcard_item(barejid, "Postal code", vcard_attrib, data); | |
580 data = xmlnode_get_tag_data(x, "CTRY"); | |
581 display_vcard_item(barejid, "Country", vcard_attrib, data); | |
582 } else if (!strcmp(p, "TEL")) { // Telephone | |
1005 | 583 data = xmlnode_get_tag_data(x, "NUMBER"); |
584 if (data) { | |
585 if (xmlnode_get_tag(x, "VOICE")) | |
1006 | 586 vcard_attrib |= vcard_voice; |
1005 | 587 if (xmlnode_get_tag(x, "FAX")) |
1006 | 588 vcard_attrib |= vcard_fax; |
1005 | 589 if (xmlnode_get_tag(x, "CELL")) |
1006 | 590 vcard_attrib |= vcard_cell; |
591 display_vcard_item(barejid, "Phone", vcard_attrib, data); | |
1005 | 592 } |
1006 | 593 } else if (!strcmp(p, "EMAIL")) { // Email |
594 if (xmlnode_get_tag(x, "INTERNET")) | |
595 vcard_attrib |= vcard_inet; | |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
596 data = xmlnode_get_tag_data(x, "USERID"); |
1006 | 597 display_vcard_item(barejid, "Email", vcard_attrib, data); |
1003
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 } |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
600 } |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
601 } |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
602 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
603 static void iqscallback_vcard(eviqs *iqp, xmlnode xml_result, guint iqcontext) |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
604 { |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
605 xmlnode ansqry; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
606 char *p; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
607 char *bjid; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
608 char *buf; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
609 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
610 // Leave now if we cannot process xml_result |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
611 if (!xml_result || iqcontext) return; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
612 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
613 // Display IQ result sender... |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
614 p = xmlnode_get_attrib(xml_result, "from"); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
615 if (!p) { |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
616 scr_LogPrint(LPRINT_LOGNORM, "Invalid IQ:vCard result (no sender name)."); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
617 return; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
618 } |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
619 bjid = p; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
620 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
621 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
|
622 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
623 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
624 // Get the vCard node |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
625 ansqry = xmlnode_get_tag(xml_result, "vCard"); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
626 if (!ansqry) { |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
627 scr_LogPrint(LPRINT_LOGNORM, "Empty IQ:vCard result!"); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
628 return; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
629 } |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
630 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
631 // 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
|
632 p = strchr(bjid, JID_RESOURCE_SEPARATOR); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
633 if (p) *p = '\0'; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
634 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
635 scr_WriteIncomingMessage(bjid, buf, 0, HBB_PREFIX_INFO); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
636 g_free(buf); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
637 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
638 // Get result data... |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
639 handle_vcard_node(bjid, ansqry); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
640 } |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
641 |
1058 | 642 void request_vcard(const char *bjid) |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
643 { |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
644 eviqs *iqn; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
645 char *barejid; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
646 |
1058 | 647 barejid = jidtodisp(bjid); |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
648 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
649 // 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
|
650 // 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
|
651 iqn = iqs_new(JPACKET__GET, NULL, "vcard", IQS_DEFAULT_TIMEOUT); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
652 xmlnode_put_attrib(iqn->xmldata, "to", barejid); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
653 // Remove the useless <query/> tag, and insert a vCard one. |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
654 xmlnode_hide(xmlnode_get_tag(iqn->xmldata, "query")); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
655 xmlnode_put_attrib(xmlnode_insert_tag(iqn->xmldata, "vCard"), |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
656 "xmlns", NS_VCARD); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
657 iqn->callback = &iqscallback_vcard; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
658 jab_send(jc, iqn->xmldata); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
659 |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
660 g_free(barejid); |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
661 } |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1002
diff
changeset
|
662 |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
663 static void storage_bookmarks_parse_conference(xmlnode xmldata) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
664 { |
1058 | 665 const char *fjid, *name, *autojoin; |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
666 char *bjid; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
667 GSList *room_elt; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
668 |
1058 | 669 fjid = xmlnode_get_attrib(xmldata, "jid"); |
670 if (!fjid) | |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
671 return; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
672 name = xmlnode_get_attrib(xmldata, "name"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
673 autojoin = xmlnode_get_attrib(xmldata, "autojoin"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
674 |
1058 | 675 bjid = jidtodisp(fjid); // Bare jid |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
676 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
677 // 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
|
678 room_elt = roster_find(bjid, jidsearch, 0); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
679 if (!room_elt) { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
680 room_elt = roster_add_user(bjid, name, NULL, ROSTER_TYPE_ROOM, sub_none); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
681 } else { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
682 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
683 /* |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
684 // If the name is available, should we use it? |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
685 // 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
|
686 // in the roster. |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
687 if (name) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
688 buddy_setname(room_elt->data, name); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
689 */ |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
690 } |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
691 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
692 // Is autojoin set? |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
693 // 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
|
694 // try to join the room. |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
695 if (autojoin && !strcmp(autojoin, "1")) { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
696 char *nick, *passwd; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
697 char *tmpnick = NULL; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
698 nick = xmlnode_get_tag_data(xmldata, "nick"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
699 passwd = xmlnode_get_tag_data(xmldata, "password"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
700 if (!nick || !*nick) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
701 nick = tmpnick = default_muc_nickname(); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
702 // Let's join now |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
703 scr_LogPrint(LPRINT_LOGNORM, "Auto-join bookmark <%s>", bjid); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
704 jb_room_join(bjid, nick, passwd); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
705 g_free(tmpnick); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
706 } |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
707 g_free(bjid); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
708 } |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
709 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
710 static void iqscallback_storage_bookmarks(eviqs *iqp, xmlnode xml_result, |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
711 guint iqcontext) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
712 { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
713 xmlnode x, ansqry; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
714 char *p; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
715 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
716 // Leave now if we cannot process xml_result |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
717 if (!xml_result || iqcontext) return; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
718 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
719 ansqry = xmlnode_get_tag(xml_result, "query"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
720 ansqry = xmlnode_get_tag(ansqry, "storage"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
721 if (!ansqry) { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
722 scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! (storage:bookmarks)"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
723 return; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
724 } |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
725 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
726 // Walk through the storage tags |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
727 x = xmlnode_get_firstchild(ansqry); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
728 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
729 p = xmlnode_get_name(x); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
730 // 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
|
731 if (p && !strcmp(p, "conference")) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
732 storage_bookmarks_parse_conference(x); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
733 } |
1016 | 734 // Copy the bookmarks node |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
735 xmlnode_free(bookmarks); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
736 bookmarks = xmlnode_dup(ansqry); |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
737 } |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
738 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
739 static void request_storage_bookmarks(void) |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
740 { |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
741 eviqs *iqn; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
742 xmlnode x; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
743 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
744 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
|
745 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
746 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
|
747 xmlnode_put_attrib(x, "xmlns", "storage:bookmarks"); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
748 |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
749 iqn->callback = &iqscallback_storage_bookmarks; |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
750 jab_send(jc, iqn->xmldata); |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
751 } |
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
752 |
1016 | 753 static void iqscallback_storage_rosternotes(eviqs *iqp, xmlnode xml_result, |
754 guint iqcontext) | |
755 { | |
756 xmlnode ansqry; | |
757 | |
758 // Leave now if we cannot process xml_result | |
759 if (!xml_result || iqcontext) return; | |
760 | |
761 ansqry = xmlnode_get_tag(xml_result, "query"); | |
762 ansqry = xmlnode_get_tag(ansqry, "storage"); | |
763 if (!ansqry) { | |
764 scr_LogPrint(LPRINT_LOG, "Invalid IQ:private result! " | |
765 "(storage:rosternotes)"); | |
766 return; | |
767 } | |
768 // Copy the rosternotes node | |
769 xmlnode_free(rosternotes); | |
770 rosternotes = xmlnode_dup(ansqry); | |
771 } | |
772 | |
773 static void request_storage_rosternotes(void) | |
774 { | |
775 eviqs *iqn; | |
776 xmlnode x; | |
777 | |
778 iqn = iqs_new(JPACKET__GET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT); | |
779 | |
780 x = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "storage"); | |
781 xmlnode_put_attrib(x, "xmlns", "storage:rosternotes"); | |
782 | |
783 iqn->callback = &iqscallback_storage_rosternotes; | |
784 jab_send(jc, iqn->xmldata); | |
785 } | |
786 | |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
787 void iqscallback_auth(eviqs *iqp, xmlnode xml_result) |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
788 { |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
789 if (jstate == STATE_GETAUTH) { |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
705
diff
changeset
|
790 eviqs *iqn; |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
791 |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
792 if (xml_result) { |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
793 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
|
794 if (x && !xmlnode_get_tag(x, "digest")) |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
795 jc->sid = 0; |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
796 } |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
797 |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
798 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
|
799 iqn->callback = &iqscallback_auth; |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
800 jab_auth_mcabber(jc, iqn->xmldata); |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
801 jab_send(jc, iqn->xmldata); |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
802 jstate = STATE_SENDAUTH; |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
803 } else if (jstate == STATE_SENDAUTH) { |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
804 request_roster(); |
1004
b57a01ffeed6
Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
805 request_storage_bookmarks(); |
1016 | 806 request_storage_rosternotes(); |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
807 jstate = STATE_LOGGED; |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
808 } |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
809 } |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
685
diff
changeset
|
810 |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
811 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
|
812 { |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
813 xmlnode x; |
685
f033345d1315
Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
814 char *id; |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
815 char *ns; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
816 |
685
f033345d1315
Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
817 id = xmlnode_get_attrib(xmldata, "id"); |
f033345d1315
Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
818 if (!id) { |
596
6c7fd289648f
Clean up handle_iq_result()
Mikael Berthe <mikael@lilotux.net>
parents:
595
diff
changeset
|
819 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
|
820 return; |
6c7fd289648f
Clean up handle_iq_result()
Mikael Berthe <mikael@lilotux.net>
parents:
595
diff
changeset
|
821 } |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
822 |
698
60522cf6d325
Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
692
diff
changeset
|
823 if (!iqs_callback(id, xmldata, IQS_CONTEXT_RESULT)) |
685
f033345d1315
Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
824 return; |
f033345d1315
Call IQ callback function when receiving a RESULT packet
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
825 |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
826 x = xmlnode_get_tag(xmldata, "query"); |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
827 if (!x) return; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
828 |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
829 ns = xmlnode_get_attrib(x, "xmlns"); |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
830 if (!ns) return; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
831 |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
832 if (!strcmp(ns, NS_ROSTER)) { |
606
0b4ed231ebc2
Code cleanup + remove deprecated Agents list IQ request
Mikael Berthe <mikael@lilotux.net>
parents:
605
diff
changeset
|
833 handle_iq_roster(x); |
603 | 834 |
607 | 835 // Post-login stuff |
836 // Usually we request the roster only at connection time | |
837 // so we should be there only once. (That's ugly, however) | |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1008
diff
changeset
|
838 jb_setprevstatus(); |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
839 } |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
840 } |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
841 |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
842 // FIXME highly duplicated code |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
843 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
|
844 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
845 xmlnode x, y, z; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
846 // Not implemented. |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
847 x = xmlnode_dup(xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
848 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from")); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
849 xmlnode_hide_attrib(x, "from"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
850 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
851 xmlnode_put_attrib(x, "type", TMSG_ERROR); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
852 y = xmlnode_insert_tag(x, TMSG_ERROR); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
853 xmlnode_put_attrib(y, "code", "501"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
854 xmlnode_put_attrib(y, "type", "cancel"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
855 z = xmlnode_insert_tag(y, "feature-not-implemented"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
856 xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
857 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
858 jab_send(conn, x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
859 xmlnode_free(x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
860 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
861 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
862 /* |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
863 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
|
864 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
865 xmlnode x, y, z; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
866 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
867 x = xmlnode_dup(xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
868 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from")); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
869 xmlnode_hide_attrib(x, "from"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
870 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
871 xmlnode_put_attrib(x, "type", TMSG_ERROR); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
872 y = xmlnode_insert_tag(x, TMSG_ERROR); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
873 xmlnode_put_attrib(y, "code", "400"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
874 xmlnode_put_attrib(y, "type", "modify"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
875 z = xmlnode_insert_tag(y, "bad-request"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
876 xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
877 z = xmlnode_insert_tag(y, "bad-action"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
878 xmlnode_put_attrib(z, "xmlns", NS_COMMANDS); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
879 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
880 jab_send(conn, x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
881 xmlnode_free(x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
882 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
883 */ |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
884 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
885 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
|
886 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
887 xmlnode x, y, z; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
888 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
889 x = xmlnode_dup(xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
890 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from")); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
891 xmlnode_hide_attrib(x, "from"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
892 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
893 xmlnode_put_attrib(x, "type", TMSG_ERROR); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
894 y = xmlnode_insert_tag(x, TMSG_ERROR); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
895 xmlnode_put_attrib(y, "code", "403"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
896 xmlnode_put_attrib(y, "type", "cancel"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
897 z = xmlnode_insert_tag(y, "forbidden"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
898 xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
899 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
900 jab_send(conn, x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
901 xmlnode_free(x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
902 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
903 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
904 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
|
905 xmlnode xmldata) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
906 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
907 xmlnode x, y, z; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
908 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
909 x = xmlnode_dup(xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
910 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from")); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
911 xmlnode_hide_attrib(x, "from"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
912 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
913 xmlnode_put_attrib(x, "type", TMSG_ERROR); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
914 y = xmlnode_insert_tag(x, TMSG_ERROR); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
915 xmlnode_put_attrib(y, "code", "400"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
916 xmlnode_put_attrib(y, "type", "modify"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
917 z = xmlnode_insert_tag(y, "bad-request"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
918 xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
919 z = xmlnode_insert_tag(y, "malformed-action"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
920 xmlnode_put_attrib(z, "xmlns", NS_COMMANDS); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
921 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
922 jab_send(conn, x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
923 xmlnode_free(x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
924 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
925 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
926 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
|
927 xmlnode xmldata) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
928 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
929 xmlnode x; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
930 xmlnode myquery; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
931 jid requester_jid; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
932 const struct adhoc_command *command; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
933 bool from_self; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
934 x = jutil_iqnew(JPACKET__RESULT, NS_DISCO_ITEMS); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
935 xmlnode_put_attrib(x, "id", id); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
936 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from")); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
937 myquery = xmlnode_get_tag(x, "query"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
938 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
939 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
|
940 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
|
941 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
942 for (command = adhoc_command_list ; command->name ; command++) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
943 if (!command->only_for_self || from_self) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
944 xmlnode item; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
945 item = xmlnode_insert_tag(myquery, "item"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
946 xmlnode_put_attrib(item, "node", command->name); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
947 xmlnode_put_attrib(item, "name", command->description); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
948 xmlnode_put_attrib(item, "jid", jid_full(conn->user)); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
949 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
950 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
951 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
952 jab_send(jc, x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
953 xmlnode_free(x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
954 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
955 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
956 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
|
957 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
958 xmlnode x = xmlnode_insert_tag(node, "x"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
959 xmlnode_put_attrib(x, "type", "result"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
960 xmlnode_put_attrib(x, "xmlns", "jabber:x:data"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
961 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
962 xmlnode field = xmlnode_insert_tag(x, "field"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
963 xmlnode_put_attrib(field, "type", "text-single"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
964 xmlnode_put_attrib(field, "var", "message"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
965 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
966 xmlnode value = xmlnode_insert_tag(field, "value"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
967 xmlnode_insert_cdata(value, message, -1); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
968 } |
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 static char *generate_session_id(char *prefix) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
971 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
972 char *result; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
973 static int counter = 0; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
974 counter++; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
975 // TODO better use timezone ? |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
976 result = g_strdup_printf("%s-%i", prefix, counter); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
977 return result; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
978 } |
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 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
|
981 xmlnode xmldata) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
982 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
983 char *action, *node, *sessionid; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
984 xmlnode iq, command, x, y; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
985 const struct adhoc_status *s; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
986 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
987 x = xmlnode_get_tag(xmldata, "command"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
988 action = xmlnode_get_attrib(x, "action"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
989 node = xmlnode_get_attrib(x, "node"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
990 sessionid = xmlnode_get_attrib(x, "sessionid"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
991 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
992 iq = xmlnode_new_tag("iq"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
993 command = xmlnode_insert_tag(iq, "command"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
994 xmlnode_put_attrib(command, "node", node); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
995 xmlnode_put_attrib(command, "xmlns", NS_COMMANDS); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
996 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
997 if (!sessionid) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
998 sessionid = generate_session_id("set-status"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
999 xmlnode_put_attrib(command, "sessionid", sessionid); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1000 g_free(sessionid); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1001 xmlnode_put_attrib(command, "status", "executing"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1002 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1003 x = xmlnode_insert_tag(command, "x"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1004 xmlnode_put_attrib(x, "type", "form"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1005 xmlnode_put_attrib(x, "xmlns", "jabber:x:data"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1006 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1007 y = xmlnode_insert_tag(x, "title"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1008 xmlnode_insert_cdata(y, "Change Status", -1); |
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 y = xmlnode_insert_tag(x, "instructions"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1011 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
|
1012 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1013 // TODO see if factorisation is possible |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1014 // (with xmlnode_insert_dataform_result_message) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1015 y = xmlnode_insert_tag(x, "field"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1016 xmlnode_put_attrib(y, "type", "hidden"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1017 xmlnode_put_attrib(y, "var", "FORM_TYPE"); |
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 xmlnode value = xmlnode_insert_tag(y, "value"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1020 xmlnode_insert_cdata(value, "http://jabber.org/protocol/rc", -1); |
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 y = xmlnode_insert_tag(x, "field"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1023 xmlnode_put_attrib(y, "type", "list-single"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1024 xmlnode_put_attrib(y, "var", "status"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1025 xmlnode_put_attrib(y, "label", "Status"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1026 xmlnode_insert_tag(y, "required"); |
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 value = xmlnode_insert_tag(y, "value"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1029 // TODO current status |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1030 xmlnode_insert_cdata(value, "online", -1); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1031 for (s = adhoc_status_list; s->name; s++) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1032 xmlnode option = xmlnode_insert_tag(y, "option"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1033 value = xmlnode_insert_tag(option, "value"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1034 xmlnode_insert_cdata(value, s->name, -1); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1035 xmlnode_put_attrib(option, "label", s->description); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1036 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1037 // TODO add priority ? |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1038 // 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
|
1039 // priority like gossip and gajim do (misc) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1040 y = xmlnode_insert_tag(x, "field"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1041 xmlnode_put_attrib(y, "type", "text-multi"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1042 xmlnode_put_attrib(y, "var", "status-message"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1043 xmlnode_put_attrib(y, "label", "Message"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1044 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1045 else // (if sessionid) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1046 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1047 y = xmlnode_get_tag(x, "x?xmlns=jabber:x:data"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1048 if (y) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1049 char *value, *message; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1050 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
|
1051 "value"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1052 message = xmlnode_get_tag_data(xmlnode_get_tag(y, |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1053 "field?var=status-message"), "value"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1054 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
|
1055 if (s->name) { |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1056 char *status = g_strdup_printf("%s %s", s->status, |
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1057 message ? message : ""); |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1058 setstatus(NULL, status); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1059 g_free(status); |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1060 xmlnode_put_attrib(command, "status", "completed"); |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1061 xmlnode_put_attrib(iq, "type", "result"); |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1062 xmlnode_insert_dataform_result_message(command, |
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1063 "Status has been changed"); |
1158
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 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1066 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1067 xmlnode_put_attrib(iq, "to", xmlnode_get_attrib(xmldata, "from")); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1068 xmlnode_put_attrib(iq, "id", id); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1069 jab_send(jc, iq); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1070 xmlnode_free(iq); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1071 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1072 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1073 static void _callback_foreach_buddy_groupchat(gpointer rosterdata, void *param) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1074 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1075 xmlnode value; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1076 xmlnode *field; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1077 const char *room_jid, *nickname; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1078 char *desc; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1079 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1080 room_jid = buddy_getjid(rosterdata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1081 if (!room_jid) return; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1082 nickname = buddy_getnickname(rosterdata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1083 if (!nickname) return; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1084 field = param; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1085 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1086 xmlnode option = xmlnode_insert_tag(*field, "option"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1087 value = xmlnode_insert_tag(option, "value"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1088 xmlnode_insert_cdata(value, room_jid, -1); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1089 desc = g_strdup_printf("%s on %s", nickname, room_jid); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1090 xmlnode_put_attrib(option, "label", desc); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1091 g_free(desc); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1092 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1093 |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1094 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
|
1095 const char *id, xmlnode xmldata) |
1158
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 char *action, *node, *sessionid; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1098 xmlnode iq, command, x; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1099 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1100 x = xmlnode_get_tag(xmldata, "command"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1101 action = xmlnode_get_attrib(x, "action"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1102 node = xmlnode_get_attrib(x, "node"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1103 sessionid = xmlnode_get_attrib(x, "sessionid"); |
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 iq = xmlnode_new_tag("iq"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1106 command = xmlnode_insert_tag(iq, "command"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1107 xmlnode_put_attrib(command, "node", node); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1108 xmlnode_put_attrib(command, "xmlns", NS_COMMANDS); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1109 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1110 if (!sessionid) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1111 sessionid = generate_session_id("leave-groupchats"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1112 xmlnode_put_attrib(command, "sessionid", sessionid); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1113 g_free(sessionid); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1114 xmlnode_put_attrib(command, "status", "executing"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1115 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1116 x = xmlnode_insert_tag(command, "x"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1117 xmlnode_put_attrib(x, "type", "form"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1118 xmlnode_put_attrib(x, "xmlns", "jabber:x:data"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1119 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1120 xmlnode title = xmlnode_insert_tag(x, "title"); |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1121 xmlnode_insert_cdata(title, "Leave groupchat(s)", -1); |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1122 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1123 xmlnode instructions = xmlnode_insert_tag(x, "instructions"); |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1124 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
|
1125 -1); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1126 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1127 xmlnode field = xmlnode_insert_tag(x, "field"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1128 xmlnode_put_attrib(field, "type", "hidden"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1129 xmlnode_put_attrib(field, "var", "FORM_TYPE"); |
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 xmlnode value = xmlnode_insert_tag(field, "value"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1132 xmlnode_insert_cdata(value, "http://jabber.org/protocol/rc", -1); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1133 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1134 field = xmlnode_insert_tag(x, "field"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1135 xmlnode_put_attrib(field, "type", "list-multi"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1136 xmlnode_put_attrib(field, "var", "groupchats"); |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1137 xmlnode_put_attrib(field, "label", "Groupchats: "); |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1138 xmlnode_insert_tag(field, "required"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1139 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1140 foreach_buddy(ROSTER_TYPE_ROOM, &_callback_foreach_buddy_groupchat, &field); |
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 else // (if sessionid) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1143 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1144 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
|
1145 if (form) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1146 xmlnode_put_attrib(command, "status", "completed"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1147 xmlnode gc = xmlnode_get_tag(form, "field?var=groupchats"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1148 xmlnode x; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1149 |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1150 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
|
1151 { |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1152 char* to_leave = xmlnode_get_tag_data(x, "value"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1153 if (to_leave) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1154 GList* b = buddy_search_jid(to_leave); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1155 if (b) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1156 room_leave(b->data, "Asked by remote command"); |
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 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1159 xmlnode_put_attrib(iq, "type", "result"); |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1160 xmlnode_insert_dataform_result_message(command, |
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1161 "Groupchats have been left"); |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1162 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1163 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1164 xmlnode_put_attrib(iq, "to", xmlnode_get_attrib(xmldata, "from")); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1165 xmlnode_put_attrib(iq, "id", id); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1166 jab_send(jc, iq); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1167 xmlnode_free(iq); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1168 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1169 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1170 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
|
1171 xmlnode xmldata) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1172 { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1173 jid requester_jid; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1174 xmlnode x; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1175 const struct adhoc_command *command; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1176 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1177 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
|
1178 x = xmlnode_get_tag(xmldata, "command"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1179 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
|
1180 char *action, *node; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1181 action = xmlnode_get_attrib(x, "action"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1182 node = xmlnode_get_attrib(x, "node"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1183 // 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
|
1184 // ie execute |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1185 if (!action || !strcmp(action, "execute") || !strcmp(action, "cancel") |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1186 || !strcmp(action, "next") || !strcmp(action, "complete")) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1187 for (command = adhoc_command_list; command->name; command++) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1188 if (!strcmp(node, command->name)) |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1189 command->callback(conn, from, id, xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1190 } |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1158
diff
changeset
|
1191 // "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
|
1192 // and do not authorize it |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1193 } else { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1194 send_iq_commands_malformed_action(conn, from, xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1195 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1196 } else { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1197 send_iq_forbidden(conn, from, xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1198 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1199 } |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1200 |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1201 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
|
1202 xmlnode xmldata) |
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 xmlnode x; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1205 char *node; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1206 x = xmlnode_get_tag(xmldata, "query"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1207 node = xmlnode_get_attrib(x, "node"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1208 if (node) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1209 if (!strcmp(node, NS_COMMANDS)) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1210 handle_iq_commands_list(conn, from, id, xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1211 } else { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1212 send_iq_not_implemented(conn, from, xmldata); |
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 } else { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1215 // not sure about this one |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1216 send_iq_not_implemented(conn, from, xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1217 } |
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 |
995
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1220 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
|
1221 xmlnode xmldata) |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1222 { |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1223 xmlnode x, y; |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1224 xmlnode myquery; |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1225 |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1226 x = jutil_iqnew(JPACKET__RESULT, NS_DISCO_INFO); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1227 xmlnode_put_attrib(x, "id", id); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1228 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
|
1229 myquery = xmlnode_get_tag(x, "query"); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1230 |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1231 y = xmlnode_insert_tag(myquery, "identity"); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1232 xmlnode_put_attrib(y, "category", "client"); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1233 xmlnode_put_attrib(y, "type", "pc"); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1234 xmlnode_put_attrib(y, "name", PACKAGE_NAME); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1235 |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1236 xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"), |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1237 "var", NS_DISCO_INFO); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1238 xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"), |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1239 "var", NS_MUC); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1240 xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"), |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1241 "var", NS_CHATSTATES); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1242 xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"), |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1243 "var", NS_TIME); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1244 xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"), |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1245 "var", NS_VERSION); |
1134 | 1246 xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"), |
1247 "var", NS_PING); | |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1248 xmlnode_put_attrib(xmlnode_insert_tag(myquery, "feature"), |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1249 "var", NS_COMMANDS); |
1134 | 1250 jab_send(jc, x); |
1251 xmlnode_free(x); | |
1252 } | |
995
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1253 |
1134 | 1254 static void handle_iq_ping(jconn conn, char *from, const char *id, |
1255 xmlnode xmldata) | |
1256 { | |
1257 xmlnode x; | |
1258 x = jutil_iqresult(xmldata); | |
995
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1259 jab_send(jc, x); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1260 xmlnode_free(x); |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1261 } |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1262 |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1263 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
|
1264 xmlnode xmldata) |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1265 { |
995
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1266 xmlnode x; |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1267 xmlnode myquery; |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1268 char *os = NULL; |
814
109dcf5fc111
Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
782
diff
changeset
|
1269 char *ver = mcabber_version(); |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1270 |
692
d3511f846d47
Cosmetics (line wrapping)
Mikael Berthe <mikael@lilotux.net>
parents:
691
diff
changeset
|
1271 scr_LogPrint(LPRINT_LOGNORM, "Received an IQ version request from <%s>", |
d3511f846d47
Cosmetics (line wrapping)
Mikael Berthe <mikael@lilotux.net>
parents:
691
diff
changeset
|
1272 from); |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1273 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1274 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
|
1275 struct utsname osinfo; |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1276 uname(&osinfo); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1277 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
|
1278 osinfo.machine); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1279 } |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1280 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1281 x = jutil_iqnew(JPACKET__RESULT, NS_VERSION); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1282 xmlnode_put_attrib(x, "id", id); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1283 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
|
1284 myquery = xmlnode_get_tag(x, "query"); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1285 |
814
109dcf5fc111
Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
782
diff
changeset
|
1286 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
|
1287 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
|
1288 if (os) { |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1289 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
|
1290 g_free(os); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1291 } |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1292 |
814
109dcf5fc111
Use hgcset (if available) when answering to IQ:version requests
Mikael Berthe <mikael@lilotux.net>
parents:
782
diff
changeset
|
1293 g_free(ver); |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1294 jab_send(jc, x); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1295 xmlnode_free(x); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1296 } |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1297 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1298 // This function borrows some code from the Gaim project |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1299 static void handle_iq_time(jconn conn, char *from, const char *id, |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1300 xmlnode xmldata) |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1301 { |
995
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1302 xmlnode x; |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1303 xmlnode myquery; |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1304 char *buf, *utf8_buf; |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1305 time_t now_t; |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1306 struct tm *now; |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1307 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1308 time(&now_t); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1309 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1310 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
|
1311 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1312 buf = g_new0(char, 512); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1313 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1314 x = jutil_iqnew(JPACKET__RESULT, NS_TIME); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1315 xmlnode_put_attrib(x, "id", id); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1316 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
|
1317 myquery = xmlnode_get_tag(x, "query"); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1318 |
703
8cbcbff8de7d
Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1319 now = gmtime(&now_t); |
8cbcbff8de7d
Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1320 |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1321 strftime(buf, 512, "%Y%m%dT%T", now); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1322 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
|
1323 |
703
8cbcbff8de7d
Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1324 now = localtime(&now_t); |
8cbcbff8de7d
Fix UTC time in IQ:version queries
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1325 |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1326 strftime(buf, 512, "%Z", now); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1327 if ((utf8_buf = to_utf8(buf))) { |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1328 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
|
1329 g_free(utf8_buf); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1330 } |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1331 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1332 strftime(buf, 512, "%d %b %Y %T", now); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1333 if ((utf8_buf = to_utf8(buf))) { |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1334 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
|
1335 g_free(utf8_buf); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1336 } |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1337 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1338 jab_send(jc, x); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1339 xmlnode_free(x); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1340 g_free(buf); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1341 } |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1342 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1343 // This function borrows some code from the Gaim project |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1344 static void handle_iq_get(jconn conn, char *from, xmlnode xmldata) |
31 | 1345 { |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1346 const char *id, *ns; |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1347 xmlnode x; |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1348 guint iq_not_implemented = FALSE; |
31 | 1349 |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1350 id = xmlnode_get_attrib(xmldata, "id"); |
607 | 1351 if (!id) { |
1352 scr_LogPrint(LPRINT_LOG, "IQ get stanza with no ID, ignored."); | |
1353 return; | |
1354 } | |
31 | 1355 |
1134 | 1356 x = xmlnode_get_tag(xmldata, "ping"); |
1357 ns = xmlnode_get_attrib(x, "xmlns"); | |
1358 if (ns && !strcmp(ns, NS_PING)) { | |
1359 handle_iq_ping(conn, from, id, xmldata); | |
1360 return; | |
1361 } | |
1362 | |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1363 x = xmlnode_get_tag(xmldata, "query"); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1364 ns = xmlnode_get_attrib(x, "xmlns"); |
995
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1365 if (ns && !strcmp(ns, NS_DISCO_INFO)) { |
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1366 handle_iq_disco_info(conn, from, id, xmldata); |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1367 } else if (ns && !strcmp(ns, NS_DISCO_ITEMS)) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1368 handle_iq_disco_items(conn, from, id, xmldata); |
995
c89e7993c4d9
Answer IQ disco#info queries
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1369 } else if (ns && !strcmp(ns, NS_VERSION)) { |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1370 handle_iq_version(conn, from, id, xmldata); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1371 } else if (ns && !strcmp(ns, NS_TIME)) { |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1372 handle_iq_time(conn, from, id, xmldata); |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1373 } else { |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1374 iq_not_implemented = TRUE; |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1375 } |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1376 |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1377 if (!iq_not_implemented) |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1378 return; |
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1379 |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1380 send_iq_not_implemented(conn, from, xmldata); |
31 | 1381 } |
1382 | |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1383 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
|
1384 { |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1385 const char *id, *ns; |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1386 xmlnode x; |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1387 guint iq_not_implemented = FALSE; |
595
0c1d37300862
IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents:
582
diff
changeset
|
1388 |
0c1d37300862
IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents:
582
diff
changeset
|
1389 id = xmlnode_get_attrib(xmldata, "id"); |
607 | 1390 if (!id) |
1391 scr_LogPrint(LPRINT_LOG, "IQ set stanza with no ID..."); | |
1392 | |
1393 x = xmlnode_get_tag(xmldata, "query"); | |
1394 ns = xmlnode_get_attrib(x, "xmlns"); | |
1395 if (ns && !strcmp(ns, NS_ROSTER)) { | |
1396 handle_iq_roster(x); | |
1397 } else { | |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1398 x = xmlnode_get_tag(xmldata, "command"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1399 ns = xmlnode_get_attrib(x, "xmlns"); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1400 if (ns && !strcmp(ns, NS_COMMANDS)) { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1401 handle_iq_commands(conn, from, id, xmldata); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1402 } else { |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1403 iq_not_implemented = TRUE; |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1404 } |
607 | 1405 } |
1406 | |
595
0c1d37300862
IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents:
582
diff
changeset
|
1407 if (!id) return; |
0c1d37300862
IQ: send feature-not-implemented error stanzas
Mikael Berthe <mikael@lilotux.net>
parents:
582
diff
changeset
|
1408 |
619
44ddf9bec3a5
Answer IQ:version & IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
613
diff
changeset
|
1409 if (!iq_not_implemented) { |
607 | 1410 x = xmlnode_new_tag("iq"); |
1411 xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from")); | |
1412 xmlnode_put_attrib(x, "type", "result"); | |
1413 xmlnode_put_attrib(x, "id", id); | |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1414 jab_send(conn, x); |
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1415 xmlnode_free(x); |
607 | 1416 } else { |
1158
c30c315dc447
XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents:
1134
diff
changeset
|
1417 send_iq_not_implemented(conn, from, xmldata); |
607 | 1418 } |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1419 } |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1420 |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1421 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
|
1422 { |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1423 if (!type) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1424 return; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1425 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1426 if (!strcmp(type, "result")) { |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1427 handle_iq_result(conn, from, xmldata); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1428 } else if (!strcmp(type, "get")) { |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1429 handle_iq_get(conn, from, xmldata); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1430 } else if (!strcmp(type, "set")) { |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1431 handle_iq_set(conn, from, xmldata); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1432 } else if (!strcmp(type, TMSG_ERROR)) { |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1433 xmlnode x = xmlnode_get_tag(xmldata, TMSG_ERROR); |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1434 if (x) |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1435 display_server_error(x); |
698
60522cf6d325
Propagate context to IQ callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
692
diff
changeset
|
1436 iqs_callback(xmlnode_get_attrib(xmldata, "id"), NULL, IQS_CONTEXT_ERROR); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1437 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1438 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1439 |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1440 // send_storage_bookmarks() |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1441 // Send the current bookmarks node to update the server. |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1442 // Note: the sender should check we're online. |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1443 void send_storage_bookmarks(void) |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1444 { |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1445 eviqs *iqn; |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1446 |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1447 if (!bookmarks) return; |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1448 |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1449 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
|
1450 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
|
1451 |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1452 jab_send(jc, iqn->xmldata); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1453 iqs_del(iqn->id); // XXX |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1454 } |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1006
diff
changeset
|
1455 |
1016 | 1456 // send_storage_rosternotes() |
1457 // Send the current rosternotes node to update the server. | |
1458 // Note: the sender should check we're online. | |
1459 void send_storage_rosternotes(void) | |
1460 { | |
1461 eviqs *iqn; | |
1462 | |
1463 if (!rosternotes) return; | |
1464 | |
1465 iqn = iqs_new(JPACKET__SET, NS_PRIVATE, "storage", IQS_DEFAULT_TIMEOUT); | |
1466 xmlnode_insert_node(xmlnode_get_tag(iqn->xmldata, "query"), rosternotes); | |
1467 | |
1468 jab_send(jc, iqn->xmldata); | |
1469 iqs_del(iqn->id); // XXX | |
1470 } | |
1471 | |
580 | 1472 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |