Mercurial > pidgin
annotate src/protocols/jabber/iq.c @ 12645:fc28451f5d96
[gaim-migrate @ 14983]
SF Patch #1314512 from Sadrul (who has a patch for everything)
"This patch introduces a flag for protocol plugins that
support offline messages (like Y!M and ICQ). This was
encouraged by the following conversation:
<sadrul> should offline buddies be listed/enabled in
the send-to menu?
<rekkanoryo> i would think only for protocols that
support offline messaging, if it's indicated that the
buddy is offline
-- <snip> --
<Bleeter> sadrul: personally, I'd like to see a
'supports offline' flag of some description
<Bleeter> one could then redirect (via plugins) through
email or alternative methods
<Bleeter> just a thought
<Paco-Paco> yeah, that sounds like a reasonble thing to have
This patch uses this flag to disable the buddies in the
send-to menu who are offline and the protocol doesn't
support offline messages."
I made this make the label insensitive instead of the whole menuitem. This
should address SimGuy's concerns about inconsistency (i.e. you could create a
conversation with someone via the buddy list that you couldn't create via the
Send To menu). I also hacked up some voodoo to show the label as sensitive when
moused-over, as that looks better (given the label-insensitive thing is itself a
hack). I think this works quite well.
BUG NOTE:
This makes more obvious an existing bug. The Send To menu isn't updated when
buddies sign on or off or change status (at least under some circumstances).
We need to fix that anyway, so I'm not going to let it hold up this commit.
Switching tabs will clear it up. I'm thinking we just might want to build the
contents of that menu when it is selected. That would save us a mess of
inefficient signal callbacks that update the Send To menus in open windows all
the time.
AIM NOTE:
This assumes that AIM can't offline message. That's not strictly true. You can
message invisible users on AIM. However, by design, we can't tell when a user
is invisible without resorting to dirty hackery. In practice, this isn't a
problem, as you can still select the AIM user from the menu. And really, how
often will you be choosing the Invisible contact, rather than the user going
Invisible in the middle of a conversation or IMing you while they're Invisible?
JABBER NOTE:
This assumes that Jabber can always offline message. This isn't strictly true.
Sadrul said:
I have updated Jabber according to this link which seems to
talk about how to determine the existence offline-message
support in a server:
http://www.jabber.org/jeps/jep-0013.html#discover
However, jabber.org doesn't seem to send the required
info. So I am not sure about it.
He later said:
I talked to Nathan and he said offline message support is
mostly assumed for most jabber servers. GTalk doesn't yet
support it, but they are working on it. So I have made
jabber to always return TRUE.
If there is truly no way to detect offline messaging capability, then this is
an acceptable solution. We could special case Google Talk because of its
popularity, and remove that later. It's probably not worth it though.
MSN NOTE:
This assumes that MSN can never offline message. That's effectively true, but
to be technically correct, MSN can offline message if there's already a
switchboard conversation open with a user. We could write an offline_message
function in the MSN prpl to detect that, but it'd be of limited usefulness,
especially given that under most circumstances (where this might matter), the
switchboard connection will be closed almost immediately.
CVS NOTE:
I'm writing to share a tragic little story.
I have a PC that I use for Gaim development. One day, I was writing a commit
message on it, when all of a suddent it went berserk. The screen started
flashing, and the whole commit message just disappeared. All of it. And it was
a good commit message! I had to cram and rewrite it really quickly. Needless to
say, my rushed commit message wasn't nearly as good, and I blame the PC for that.
Seriously, though, what kind of version control system loses your commit
message on a broken connection to the server? Stupid!
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 23 Dec 2005 19:26:04 +0000 |
parents | ecd471d1eeec |
children | e1e5462b7d81 |
rev | line source |
---|---|
7014 | 1 /* |
2 * gaim - Jabber Protocol Plugin | |
3 * | |
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 #include "internal.h" | |
22 #include "debug.h" | |
23 #include "prefs.h" | |
10941 | 24 #include "util.h" |
7014 | 25 |
7395 | 26 #include "buddy.h" |
8312 | 27 #include "disco.h" |
7014 | 28 #include "iq.h" |
7170 | 29 #include "oob.h" |
7014 | 30 #include "roster.h" |
7395 | 31 #include "si.h" |
7014 | 32 |
7058
06e7697f3fae
[gaim-migrate @ 7621]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7014
diff
changeset
|
33 #ifdef _WIN32 |
06e7697f3fae
[gaim-migrate @ 7621]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7014
diff
changeset
|
34 #include "utsname.h" |
06e7697f3fae
[gaim-migrate @ 7621]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7014
diff
changeset
|
35 #endif |
7014 | 36 |
37 JabberIq *jabber_iq_new(JabberStream *js, JabberIqType type) | |
38 { | |
39 JabberIq *iq; | |
40 | |
41 iq = g_new0(JabberIq, 1); | |
42 | |
43 iq->type = type; | |
44 | |
45 iq->node = xmlnode_new("iq"); | |
46 switch(iq->type) { | |
47 case JABBER_IQ_SET: | |
48 xmlnode_set_attrib(iq->node, "type", "set"); | |
49 break; | |
50 case JABBER_IQ_GET: | |
51 xmlnode_set_attrib(iq->node, "type", "get"); | |
52 break; | |
53 case JABBER_IQ_ERROR: | |
54 xmlnode_set_attrib(iq->node, "type", "error"); | |
55 break; | |
56 case JABBER_IQ_RESULT: | |
57 xmlnode_set_attrib(iq->node, "type", "result"); | |
58 break; | |
59 case JABBER_IQ_NONE: | |
60 /* this shouldn't ever happen */ | |
61 break; | |
62 } | |
63 | |
64 iq->js = js; | |
65 | |
66 if(type == JABBER_IQ_GET || type == JABBER_IQ_SET) { | |
67 iq->id = jabber_get_next_id(js); | |
68 xmlnode_set_attrib(iq->node, "id", iq->id); | |
69 } | |
70 | |
71 return iq; | |
72 } | |
73 | |
74 JabberIq *jabber_iq_new_query(JabberStream *js, JabberIqType type, | |
75 const char *xmlns) | |
76 { | |
77 JabberIq *iq = jabber_iq_new(js, type); | |
78 xmlnode *query; | |
79 | |
80 query = xmlnode_new_child(iq->node, "query"); | |
81 xmlnode_set_attrib(query, "xmlns", xmlns); | |
82 | |
83 return iq; | |
84 } | |
85 | |
7395 | 86 typedef struct _JabberCallbackData { |
87 JabberIqCallback *callback; | |
88 gpointer data; | |
89 } JabberCallbackData; | |
90 | |
91 void | |
92 jabber_iq_set_callback(JabberIq *iq, JabberIqCallback *callback, gpointer data) | |
7014 | 93 { |
94 iq->callback = callback; | |
7395 | 95 iq->callback_data = data; |
7014 | 96 } |
97 | |
98 void jabber_iq_set_id(JabberIq *iq, const char *id) | |
99 { | |
100 if(iq->id) | |
101 g_free(iq->id); | |
102 | |
103 if(id) { | |
104 xmlnode_set_attrib(iq->node, "id", id); | |
105 iq->id = g_strdup(id); | |
106 } else { | |
107 xmlnode_remove_attrib(iq->node, "id"); | |
108 iq->id = NULL; | |
109 } | |
110 } | |
111 | |
112 void jabber_iq_send(JabberIq *iq) | |
113 { | |
7395 | 114 JabberCallbackData *jcd; |
7014 | 115 g_return_if_fail(iq != NULL); |
116 | |
117 jabber_send(iq->js, iq->node); | |
118 | |
7395 | 119 if(iq->id && iq->callback) { |
120 jcd = g_new0(JabberCallbackData, 1); | |
121 jcd->callback = iq->callback; | |
122 jcd->data = iq->callback_data; | |
8312 | 123 g_hash_table_insert(iq->js->iq_callbacks, g_strdup(iq->id), jcd); |
7395 | 124 } |
7014 | 125 |
126 jabber_iq_free(iq); | |
127 } | |
128 | |
129 void jabber_iq_free(JabberIq *iq) | |
130 { | |
131 g_return_if_fail(iq != NULL); | |
132 | |
133 g_free(iq->id); | |
134 xmlnode_free(iq->node); | |
135 g_free(iq); | |
136 } | |
137 | |
8312 | 138 static void jabber_iq_last_parse(JabberStream *js, xmlnode *packet) |
7014 | 139 { |
140 JabberIq *iq; | |
8006 | 141 const char *type; |
7014 | 142 const char *from; |
143 const char *id; | |
144 xmlnode *query; | |
145 char *idle_time; | |
146 | |
8006 | 147 type = xmlnode_get_attrib(packet, "type"); |
7014 | 148 from = xmlnode_get_attrib(packet, "from"); |
149 id = xmlnode_get_attrib(packet, "id"); | |
150 | |
8006 | 151 if(type && !strcmp(type, "get")) { |
152 iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:last"); | |
153 jabber_iq_set_id(iq, id); | |
154 xmlnode_set_attrib(iq->node, "to", from); | |
7014 | 155 |
8006 | 156 query = xmlnode_get_child(iq->node, "query"); |
7014 | 157 |
8006 | 158 idle_time = g_strdup_printf("%ld", js->idle ? time(NULL) - js->idle : 0); |
159 xmlnode_set_attrib(query, "seconds", idle_time); | |
160 g_free(idle_time); | |
7401 | 161 |
8006 | 162 jabber_iq_send(iq); |
163 } | |
7014 | 164 } |
165 | |
8312 | 166 static void jabber_iq_time_parse(JabberStream *js, xmlnode *packet) |
7014 | 167 { |
8006 | 168 const char *type, *from, *id; |
7014 | 169 JabberIq *iq; |
170 char buf[1024]; | |
171 xmlnode *query; | |
172 time_t now_t; | |
9709 | 173 struct tm *now; |
9722 | 174 |
7014 | 175 time(&now_t); |
9709 | 176 now = localtime(&now_t); |
7014 | 177 |
8006 | 178 type = xmlnode_get_attrib(packet, "type"); |
7014 | 179 from = xmlnode_get_attrib(packet, "from"); |
180 id = xmlnode_get_attrib(packet, "id"); | |
181 | |
8006 | 182 if(type && !strcmp(type, "get")) { |
10941 | 183 char *utf8; |
7014 | 184 |
8006 | 185 iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:time"); |
186 jabber_iq_set_id(iq, id); | |
187 xmlnode_set_attrib(iq->node, "to", from); | |
188 | |
189 query = xmlnode_get_child(iq->node, "query"); | |
7014 | 190 |
9709 | 191 strftime(buf, sizeof(buf), "%Y%m%dT%T", now); |
8006 | 192 xmlnode_insert_data(xmlnode_new_child(query, "utc"), buf, -1); |
10941 | 193 |
9709 | 194 strftime(buf, sizeof(buf), "%Z", now); |
10941 | 195 if((utf8 = gaim_utf8_try_convert(buf))) { |
196 xmlnode_insert_data(xmlnode_new_child(query, "tz"), utf8, -1); | |
197 g_free(utf8); | |
198 } | |
199 | |
9709 | 200 strftime(buf, sizeof(buf), "%d %b %Y %T", now); |
10941 | 201 if((utf8 = gaim_utf8_try_convert(buf))) { |
202 xmlnode_insert_data(xmlnode_new_child(query, "display"), utf8, -1); | |
203 g_free(utf8); | |
204 } | |
7014 | 205 |
8006 | 206 jabber_iq_send(iq); |
207 } | |
7014 | 208 } |
209 | |
8312 | 210 static void jabber_iq_version_parse(JabberStream *js, xmlnode *packet) |
7014 | 211 { |
212 JabberIq *iq; | |
8006 | 213 const char *type, *from, *id; |
7014 | 214 xmlnode *query; |
10941 | 215 char *os = NULL; |
7014 | 216 |
8006 | 217 type = xmlnode_get_attrib(packet, "type"); |
218 | |
219 if(type && !strcmp(type, "get")) { | |
10941 | 220 |
8006 | 221 if(!gaim_prefs_get_bool("/plugins/prpl/jabber/hide_os")) { |
222 struct utsname osinfo; | |
7014 | 223 |
8006 | 224 uname(&osinfo); |
225 os = g_strdup_printf("%s %s %s", osinfo.sysname, osinfo.release, | |
226 osinfo.machine); | |
227 } | |
10941 | 228 |
8006 | 229 from = xmlnode_get_attrib(packet, "from"); |
230 id = xmlnode_get_attrib(packet, "id"); | |
7014 | 231 |
8006 | 232 iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:version"); |
233 xmlnode_set_attrib(iq->node, "to", from); | |
234 jabber_iq_set_id(iq, id); | |
7014 | 235 |
8006 | 236 query = xmlnode_get_child(iq->node, "query"); |
7014 | 237 |
8006 | 238 xmlnode_insert_data(xmlnode_new_child(query, "name"), PACKAGE, -1); |
239 xmlnode_insert_data(xmlnode_new_child(query, "version"), VERSION, -1); | |
240 if(os) { | |
241 xmlnode_insert_data(xmlnode_new_child(query, "os"), os, -1); | |
242 g_free(os); | |
243 } | |
10941 | 244 |
8006 | 245 jabber_iq_send(iq); |
7014 | 246 } |
247 } | |
248 | |
249 void jabber_iq_parse(JabberStream *js, xmlnode *packet) | |
250 { | |
7395 | 251 JabberCallbackData *jcd; |
8169 | 252 xmlnode *query, *error, *x; |
7014 | 253 const char *xmlns; |
8135 | 254 const char *type, *id, *from; |
7014 | 255 |
256 query = xmlnode_get_child(packet, "query"); | |
8043 | 257 type = xmlnode_get_attrib(packet, "type"); |
8135 | 258 from = xmlnode_get_attrib(packet, "from"); |
8312 | 259 id = xmlnode_get_attrib(packet, "id"); |
260 | |
261 /* First, lets see if a special callback got registered */ | |
262 | |
263 if(type && (!strcmp(type, "result") || !strcmp(type, "error"))) { | |
264 if(id && *id && (jcd = g_hash_table_lookup(js->iq_callbacks, id))) { | |
265 jcd->callback(js, packet, jcd->data); | |
266 g_hash_table_remove(js->iq_callbacks, id); | |
8314 | 267 return; |
8312 | 268 } |
269 } | |
270 | |
271 /* Apparently not, so lets see if we have a pre-defined handler */ | |
7014 | 272 |
8043 | 273 if(type && query && (xmlns = xmlnode_get_attrib(query, "xmlns"))) { |
274 if(!strcmp(type, "set")) { | |
275 if(!strcmp(xmlns, "jabber:iq:roster")) { | |
276 jabber_roster_parse(js, packet); | |
277 return; | |
278 } else if(!strcmp(xmlns, "jabber:iq:oob")) { | |
279 jabber_oob_parse(js, packet); | |
280 return; | |
8262 | 281 } else if(!strcmp(xmlns, "http://jabber.org/protocol/bytestreams")) { |
282 jabber_bytestreams_parse(js, packet); | |
283 return; | |
8043 | 284 } |
285 } else if(!strcmp(type, "get")) { | |
286 if(!strcmp(xmlns, "jabber:iq:last")) { | |
8312 | 287 jabber_iq_last_parse(js, packet); |
8043 | 288 return; |
289 } else if(!strcmp(xmlns, "jabber:iq:time")) { | |
8312 | 290 jabber_iq_time_parse(js, packet); |
8043 | 291 return; |
292 } else if(!strcmp(xmlns, "jabber:iq:version")) { | |
8312 | 293 jabber_iq_version_parse(js, packet); |
8043 | 294 return; |
295 } else if(!strcmp(xmlns, "http://jabber.org/protocol/disco#info")) { | |
296 jabber_disco_info_parse(js, packet); | |
297 return; | |
298 } else if(!strcmp(xmlns, "http://jabber.org/protocol/disco#items")) { | |
299 jabber_disco_items_parse(js, packet); | |
300 return; | |
301 } | |
302 } else if(!strcmp(type, "result")) { | |
303 if(!strcmp(xmlns, "jabber:iq:roster")) { | |
304 jabber_roster_parse(js, packet); | |
305 return; | |
306 } else if(!strcmp(xmlns, "jabber:iq:register")) { | |
307 jabber_register_parse(js, packet); | |
308 return; | |
309 } else if(!strcmp(xmlns, "http://jabber.org/protocol/disco#info")) { | |
310 jabber_disco_info_parse(js, packet); | |
311 return; | |
312 } | |
7395 | 313 } |
8262 | 314 } else { |
8312 | 315 if(xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si")) { |
8262 | 316 jabber_si_parse(js, packet); |
317 return; | |
318 } | |
7395 | 319 } |
320 | |
8312 | 321 /* If we get here, send the default error reply mandated by XMPP-CORE */ |
8315 | 322 if(type && (!strcmp(type, "set") || !strcmp(type, "get"))) { |
323 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); | |
8135 | 324 |
8315 | 325 xmlnode_free(iq->node); |
326 iq->node = xmlnode_copy(packet); | |
327 xmlnode_set_attrib(iq->node, "to", from); | |
11825 | 328 xmlnode_remove_attrib(iq->node, "from"); |
8315 | 329 xmlnode_set_attrib(iq->node, "type", "error"); |
330 error = xmlnode_new_child(iq->node, "error"); | |
331 xmlnode_set_attrib(error, "type", "cancel"); | |
332 xmlnode_set_attrib(error, "code", "501"); | |
333 x = xmlnode_new_child(error, "feature-not-implemented"); | |
334 xmlnode_set_attrib(x, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas"); | |
8169 | 335 |
8315 | 336 jabber_iq_send(iq); |
337 } | |
7014 | 338 } |
339 |