Mercurial > pidgin
annotate src/protocols/yahoo/yahoochat.c @ 8375:1556970088d4
[gaim-migrate @ 9102]
quoth marv:
" I like "What You Get Is What You Get" better.
This fixes a problem where yahoo was sending < and > to
the core when it wasn't html, and so gtkimhtml wasn't
displaying part of the message. It's fixed by making
the prpl escape it first.
While I was add it, it made it display "Buzz!!" when
someone buzzes you, instead of it saying that they said
<ding>.
Note that the official client uses red letters, all
caps, and 3 !'s, and makes the window shake, so what we
do is pretty mild.
I also fixed a compile warning."
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Mon, 01 Mar 2004 05:13:45 +0000 |
parents | 1f56ea865926 |
children | 3c07b7d0084c |
rev | line source |
---|---|
6729 | 1 /* |
2 * gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
7 * | |
6729 | 8 * Some code copyright 2003 Tim Ringenbach <omarvo@hotmail.com> |
9 * (marv on irc.freenode.net) | |
10 * Some code borrowed from libyahoo2, copyright (C) 2002, Philip | |
11 * S Tellis <philip . tellis AT gmx . net> | |
12 * | |
13 * This program is free software; you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation; either version 2 of the License, or | |
16 * (at your option) any later version. | |
17 * | |
18 * This program is distributed in the hope that it will be useful, | |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 * GNU General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU General Public License | |
24 * along with this program; if not, write to the Free Software | |
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
26 * | |
27 */ | |
28 | |
29 #ifdef HAVE_CONFIG_H | |
30 #include "config.h" | |
31 #endif | |
32 | |
33 #include "debug.h" | |
34 #include "prpl.h" | |
35 | |
36 #include "conversation.h" | |
37 #include "notify.h" | |
38 #include "util.h" | |
39 #include "multi.h" | |
40 #include "internal.h" | |
41 | |
42 #include "yahoo.h" | |
43 #include "yahoochat.h" | |
44 | |
45 #define YAHOO_CHAT_ID (1) | |
46 | |
7186 | 47 /* prototype(s) */ |
48 static void yahoo_chat_leave(GaimConnection *gc, const char *room, const char *dn, gboolean logout); | |
49 | |
6729 | 50 /* special function to log us on to the yahoo chat service */ |
51 static void yahoo_chat_online(GaimConnection *gc) | |
52 { | |
53 struct yahoo_data *yd = gc->proto_data; | |
54 struct yahoo_packet *pkt; | |
55 | |
56 | |
57 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATONLINE, YAHOO_STATUS_AVAILABLE,0); | |
58 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
59 yahoo_packet_hash(pkt, 109, gaim_connection_get_display_name(gc)); | |
60 yahoo_packet_hash(pkt, 6, "abcde"); | |
61 | |
62 yahoo_send_packet(yd, pkt); | |
63 | |
64 yahoo_packet_free(pkt); | |
65 } | |
66 | |
67 static gint _mystrcmpwrapper(gconstpointer a, gconstpointer b) | |
68 { | |
69 return strcmp(a, b); | |
70 } | |
71 | |
72 /* this is slow, and different from the gaim_* version in that it (hopefully) won't add a user twice */ | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
73 static void yahoo_chat_add_users(GaimConvChat *chat, GList *newusers) |
6729 | 74 { |
75 GList *users, *i, *j; | |
76 | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
77 users = gaim_conv_chat_get_users(chat); |
6729 | 78 |
79 for (i = newusers; i; i = i->next) { | |
80 j = g_list_find_custom(users, i->data, _mystrcmpwrapper); | |
81 if (j) | |
82 continue; | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
83 gaim_conv_chat_add_user(chat, i->data, NULL); |
6729 | 84 } |
85 } | |
86 | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
87 static void yahoo_chat_add_user(GaimConvChat *chat, const char *user, const char *reason) |
6729 | 88 { |
89 GList *users; | |
90 | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
91 users = gaim_conv_chat_get_users(chat); |
6729 | 92 |
93 if ((g_list_find_custom(users, user, _mystrcmpwrapper))) | |
94 return; | |
95 | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
96 gaim_conv_chat_add_user(chat, user, reason); |
6729 | 97 } |
98 | |
99 static GaimConversation *yahoo_find_conference(GaimConnection *gc, const char *name) | |
100 { | |
101 struct yahoo_data *yd; | |
102 GSList *l; | |
103 | |
104 yd = gc->proto_data; | |
105 | |
106 for (l = yd->confs; l; l = l->next) { | |
107 GaimConversation *c = l->data; | |
108 if (!gaim_utf8_strcasecmp(gaim_conversation_get_name(c), name)) | |
109 return c; | |
110 } | |
111 return NULL; | |
112 } | |
113 | |
114 | |
115 void yahoo_process_conference_invite(GaimConnection *gc, struct yahoo_packet *pkt) | |
116 { | |
117 GSList *l; | |
118 char *room = NULL; | |
119 char *who = NULL; | |
120 char *msg = NULL; | |
121 GString *members = NULL; | |
122 GHashTable *components; | |
123 | |
124 | |
125 if (pkt->status == 2) | |
126 return; /* XXX */ | |
127 | |
128 members = g_string_sized_new(512); | |
129 | |
130 for (l = pkt->hash; l; l = l->next) { | |
131 struct yahoo_pair *pair = l->data; | |
132 | |
133 switch (pair->key) { | |
134 case 1: /* us, but we already know who we are */ | |
135 break; | |
136 case 57: | |
7827 | 137 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 138 break; |
139 case 50: /* inviter */ | |
140 who = pair->value; | |
141 g_string_append_printf(members, "%s\n", who); | |
142 break; | |
143 case 52: /* members */ | |
144 g_string_append_printf(members, "%s\n", pair->value); | |
145 break; | |
146 case 58: | |
7827 | 147 msg = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 148 break; |
149 case 13: /* ? */ | |
150 break; | |
151 } | |
152 } | |
153 | |
154 if (!room) { | |
155 g_string_free(members, TRUE); | |
156 return; | |
157 } | |
158 | |
159 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
7827 | 160 g_hash_table_replace(components, g_strdup("room"), room); |
6729 | 161 if (msg) |
7827 | 162 g_hash_table_replace(components, g_strdup("topic"), msg); |
6729 | 163 g_hash_table_replace(components, g_strdup("type"), g_strdup("Conference")); |
164 if (members) { | |
165 g_hash_table_replace(components, g_strdup("members"), g_strdup(members->str)); | |
166 } | |
167 serv_got_chat_invite(gc, room, who, msg, components); | |
168 | |
169 g_string_free(members, TRUE); | |
170 } | |
171 | |
172 void yahoo_process_conference_decline(GaimConnection *gc, struct yahoo_packet *pkt) | |
173 { | |
174 GSList *l; | |
175 char *room = NULL; | |
176 char *who = NULL; | |
177 char *msg = NULL; | |
178 | |
179 for (l = pkt->hash; l; l = l->next) { | |
180 struct yahoo_pair *pair = l->data; | |
181 | |
182 switch (pair->key) { | |
183 case 57: | |
7827 | 184 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 185 break; |
186 case 54: | |
187 who = pair->value; | |
188 break; | |
189 case 14: | |
7827 | 190 msg = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 191 break; |
192 } | |
193 } | |
194 | |
195 if (who && room) { | |
196 char *tmp; | |
197 | |
198 tmp = g_strdup_printf(_("%s declined your conference invitation to room \"%s\" because \"%s\"."), | |
199 who, room, msg?msg:""); | |
200 gaim_notify_info(gc, NULL, _("Invitation Rejected"), tmp); | |
201 g_free(tmp); | |
7827 | 202 g_free(room); |
203 if (msg) | |
204 g_free(msg); | |
6729 | 205 } |
206 } | |
207 | |
208 void yahoo_process_conference_logon(GaimConnection *gc, struct yahoo_packet *pkt) | |
209 { | |
210 GSList *l; | |
211 char *room = NULL; | |
212 char *who = NULL; | |
213 GaimConversation *c; | |
214 | |
215 for (l = pkt->hash; l; l = l->next) { | |
216 struct yahoo_pair *pair = l->data; | |
217 | |
218 switch (pair->key) { | |
219 case 57: | |
7827 | 220 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 221 break; |
222 case 53: | |
223 who = pair->value; | |
224 break; | |
225 } | |
226 } | |
227 | |
228 if (who && room) { | |
229 c = yahoo_find_conference(gc, room); | |
230 if (c) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
231 yahoo_chat_add_user(GAIM_CONV_CHAT(c), who, NULL); |
7827 | 232 g_free(room); |
6729 | 233 } |
234 } | |
235 | |
236 void yahoo_process_conference_logoff(GaimConnection *gc, struct yahoo_packet *pkt) | |
237 { | |
238 GSList *l; | |
239 char *room = NULL; | |
240 char *who = NULL; | |
241 GaimConversation *c; | |
242 | |
243 for (l = pkt->hash; l; l = l->next) { | |
244 struct yahoo_pair *pair = l->data; | |
245 | |
246 switch (pair->key) { | |
247 case 57: | |
7827 | 248 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 249 break; |
250 case 56: | |
251 who = pair->value; | |
252 break; | |
253 } | |
254 } | |
255 | |
256 if (who && room) { | |
257 c = yahoo_find_conference(gc, room); | |
258 if (c) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
259 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); |
7827 | 260 g_free(room); |
6729 | 261 } |
262 } | |
263 | |
264 void yahoo_process_conference_message(GaimConnection *gc, struct yahoo_packet *pkt) | |
265 { | |
266 GSList *l; | |
267 char *room = NULL; | |
268 char *who = NULL; | |
269 char *msg = NULL; | |
7827 | 270 char *msg2; |
271 int utf8 = 0; | |
6729 | 272 GaimConversation *c; |
273 | |
274 for (l = pkt->hash; l; l = l->next) { | |
275 struct yahoo_pair *pair = l->data; | |
276 | |
277 switch (pair->key) { | |
278 case 57: | |
7827 | 279 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 280 break; |
281 case 3: | |
282 who = pair->value; | |
283 break; | |
284 case 14: | |
285 msg = pair->value; | |
286 break; | |
7827 | 287 case 97: |
288 utf8 = strtol(pair->value, NULL, 10); | |
289 break; | |
6729 | 290 } |
291 } | |
292 | |
293 if (room && who && msg) { | |
7827 | 294 msg2 = yahoo_string_decode(gc, msg, utf8); |
6729 | 295 c = yahoo_find_conference(gc, room); |
296 if (!c) | |
297 return; | |
7827 | 298 msg = yahoo_codes_to_html(msg2); |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
299 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), who, 0, msg, time(NULL)); |
6729 | 300 g_free(msg); |
7827 | 301 g_free(msg2); |
6729 | 302 } |
7827 | 303 if (room) |
304 g_free(room); | |
6729 | 305 } |
306 | |
307 | |
308 /* this is a comfirmation of yahoo_chat_online(); */ | |
309 void yahoo_process_chat_online(GaimConnection *gc, struct yahoo_packet *pkt) | |
310 { | |
311 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
312 | |
313 if (pkt->status == 1) | |
314 yd->chat_online = 1; | |
315 } | |
316 | |
317 /* this is basicly the opposite of chat_online */ | |
318 void yahoo_process_chat_logout(GaimConnection *gc, struct yahoo_packet *pkt) | |
319 { | |
320 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
7186 | 321 GSList *l; |
7827 | 322 |
7186 | 323 for (l = pkt->hash; l; l = l->next) { |
324 struct yahoo_pair *pair = l->data; | |
6729 | 325 |
7186 | 326 if (pair->key == 1) |
327 if (g_ascii_strcasecmp(pair->value, | |
328 gaim_connection_get_display_name(gc))) | |
329 return; | |
330 } | |
7827 | 331 |
7186 | 332 if (pkt->status == 1) { |
6729 | 333 yd->chat_online = 0; |
7186 | 334 if (yd->in_chat) |
335 yahoo_c_leave(gc, YAHOO_CHAT_ID); | |
336 } | |
6729 | 337 } |
338 | |
339 void yahoo_process_chat_join(GaimConnection *gc, struct yahoo_packet *pkt) | |
340 { | |
341 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
342 GaimConversation *c = NULL; | |
343 GSList *l; | |
344 GList *members = NULL; | |
345 char *room = NULL; | |
346 char *topic = NULL; | |
347 char *someid, *someotherid, *somebase64orhashosomething, *somenegativenumber; | |
348 | |
349 if (pkt->status == -1) { | |
350 gaim_notify_error(gc, NULL, _("Failed to join chat"), _("Maybe the room is full?")); | |
351 return; | |
352 } | |
353 | |
354 for (l = pkt->hash; l; l = l->next) { | |
355 struct yahoo_pair *pair = l->data; | |
356 | |
357 switch (pair->key) { | |
358 | |
359 case 104: | |
7827 | 360 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 361 break; |
362 case 105: | |
7827 | 363 topic = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 364 break; |
365 case 128: | |
366 someid = pair->value; | |
367 break; | |
368 case 108: /* number of joiners */ | |
369 break; | |
370 case 129: | |
371 someotherid = pair->value; | |
372 break; | |
373 case 130: | |
374 somebase64orhashosomething = pair->value; | |
375 break; | |
376 case 126: | |
377 somenegativenumber = pair->value; | |
378 break; | |
379 case 13: /* this is 1. maybe its the type of room? (normal, user created, private, etc?) */ | |
380 break; | |
381 case 61: /*this looks similiar to 130 */ | |
382 break; | |
383 | |
384 /* the previous section was just room info. this next section is | |
385 info about individual room members, (including us) */ | |
386 | |
387 case 109: /* the yahoo id */ | |
388 members = g_list_append(members, pair->value); | |
389 break; | |
390 case 110: /* age */ | |
391 break; | |
392 case 141: /* nickname */ | |
393 break; | |
394 case 142: /* location */ | |
395 break; | |
396 case 113: /* bitmask */ | |
397 break; | |
398 } | |
399 } | |
400 | |
401 if (!room) | |
402 return; | |
403 | |
404 if (yd->chat_name && gaim_utf8_strcasecmp(room, yd->chat_name)) | |
7186 | 405 yahoo_chat_leave(gc, room, |
406 gaim_connection_get_display_name(gc), FALSE); | |
6729 | 407 |
408 c = gaim_find_chat(gc, YAHOO_CHAT_ID); | |
409 | |
8357 | 410 if ((!c || gaim_conv_chat_has_left(GAIM_CONV_CHAT(c))) && members && |
411 ((g_list_length(members) > 1) || | |
412 !g_ascii_strcasecmp(members->data, gaim_connection_get_display_name(gc)))) { | |
413 if (c && gaim_conv_chat_has_left(GAIM_CONV_CHAT(c))) { | |
414 /* this might be a hack, but oh well, it should nicely */ | |
415 char *tmpmsg; | |
416 | |
417 gaim_conversation_set_name(c, room); | |
418 | |
419 c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); | |
420 if (topic) | |
421 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); | |
422 yd->in_chat = 1; | |
423 yd->chat_name = g_strdup(room); | |
424 gaim_conv_chat_add_users(GAIM_CONV_CHAT(c), members); | |
425 | |
426 tmpmsg = g_strdup_printf(_("You are now chatting in %s."), room); | |
427 gaim_conv_chat_write(GAIM_CONV_CHAT(c), "", tmpmsg, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
428 g_free(tmpmsg); | |
429 } else { | |
430 c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); | |
431 if (topic) | |
432 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); | |
433 yd->in_chat = 1; | |
434 yd->chat_name = g_strdup(room); | |
435 gaim_conv_chat_add_users(GAIM_CONV_CHAT(c), members); | |
436 } | |
7186 | 437 } else if (c) { |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
438 yahoo_chat_add_users(GAIM_CONV_CHAT(c), members); |
6729 | 439 } |
440 | |
441 g_list_free(members); | |
7827 | 442 g_free(room); |
443 if (topic) | |
444 g_free(topic); | |
6729 | 445 } |
446 | |
447 void yahoo_process_chat_exit(GaimConnection *gc, struct yahoo_packet *pkt) | |
448 { | |
449 char *who = NULL; | |
7186 | 450 char *room = NULL; |
6729 | 451 GSList *l; |
452 struct yahoo_data *yd; | |
453 | |
454 yd = gc->proto_data; | |
455 | |
456 for (l = pkt->hash; l; l = l->next) { | |
457 struct yahoo_pair *pair = l->data; | |
458 | |
7186 | 459 if (pair->key == 104) |
7827 | 460 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 461 if (pair->key == 109) |
462 who = pair->value; | |
463 } | |
464 | |
465 | |
7186 | 466 if (who && room) { |
6729 | 467 GaimConversation *c = gaim_find_chat(gc, YAHOO_CHAT_ID); |
7186 | 468 if (c && !gaim_utf8_strcasecmp(gaim_conversation_get_name(c), room)) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
469 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); |
6729 | 470 |
471 } | |
7827 | 472 if (room) |
473 g_free(room); | |
6729 | 474 } |
475 | |
476 void yahoo_process_chat_message(GaimConnection *gc, struct yahoo_packet *pkt) | |
477 { | |
7827 | 478 char *room = NULL, *who = NULL, *msg = NULL, *msg2; |
479 int msgtype = 1, utf8 = 0; | |
6729 | 480 GaimConversation *c = NULL; |
481 GSList *l; | |
482 | |
483 for (l = pkt->hash; l; l = l->next) { | |
484 struct yahoo_pair *pair = l->data; | |
485 | |
486 switch (pair->key) { | |
487 | |
7827 | 488 case 97: |
489 utf8 = strtol(pair->value, NULL, 10); | |
490 break; | |
6729 | 491 case 104: |
7827 | 492 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 493 break; |
494 case 109: | |
495 who = pair->value; | |
496 break; | |
497 case 117: | |
498 msg = pair->value; | |
499 break; | |
500 case 124: | |
501 msgtype = strtol(pair->value, NULL, 10); | |
502 break; | |
503 } | |
504 } | |
505 | |
506 | |
507 c = gaim_find_chat(gc, YAHOO_CHAT_ID); | |
7827 | 508 if (!who || !c) { |
509 if (room) | |
510 g_free(room); | |
6729 | 511 /* we still get messages after we part, funny that */ |
512 return; | |
513 } | |
514 | |
515 if (!msg) { | |
516 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Got a message packet with no message.\nThis probably means something important, but we're ignoring it.\n"); | |
517 return; | |
518 } | |
7827 | 519 msg2 = yahoo_string_decode(gc, msg, utf8); |
520 msg = yahoo_codes_to_html(msg2); | |
521 g_free(msg2); | |
6729 | 522 |
523 if (msgtype == 2 || msgtype == 3) { | |
524 char *tmp; | |
525 tmp = g_strdup_printf("/me %s", msg); | |
526 g_free(msg); | |
527 msg = tmp; | |
528 } | |
529 | |
530 serv_got_chat_in(gc, YAHOO_CHAT_ID, who, 0, msg, time(NULL)); | |
531 g_free(msg); | |
532 } | |
533 | |
534 void yahoo_process_chat_addinvite(GaimConnection *gc, struct yahoo_packet *pkt) | |
535 { | |
536 GSList *l; | |
537 char *room = NULL; | |
538 char *msg = NULL; | |
539 char *who = NULL; | |
540 | |
541 | |
542 for (l = pkt->hash; l; l = l->next) { | |
543 struct yahoo_pair *pair = l->data; | |
544 | |
545 switch (pair->key) { | |
546 case 104: | |
7827 | 547 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 548 break; |
549 case 129: /* room id? */ | |
550 break; | |
551 case 126: /* ??? */ | |
552 break; | |
553 case 117: | |
7827 | 554 msg = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 555 break; |
556 case 119: | |
557 who = pair->value; | |
558 break; | |
559 case 118: /* us */ | |
560 break; | |
561 } | |
562 } | |
563 | |
564 if (room && who) { | |
565 GHashTable *components; | |
566 | |
567 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
568 g_hash_table_replace(components, g_strdup("room"), g_strdup(room)); | |
569 serv_got_chat_invite(gc, room, who, msg, components); | |
570 } | |
7827 | 571 if (room) |
572 g_free(room); | |
573 if (msg) | |
574 g_free(msg); | |
6729 | 575 } |
576 | |
577 void yahoo_process_chat_goto(GaimConnection *gc, struct yahoo_packet *pkt) | |
578 { | |
579 if (pkt->status == -1) | |
580 gaim_notify_error(gc, NULL, _("Failed to join buddy in chat"), | |
581 _("Maybe they're not in a chat?")); | |
582 } | |
583 | |
584 | |
585 /* | |
586 * Functions dealing with conferences | |
7827 | 587 * I think conference names are always ascii. |
6729 | 588 */ |
589 | |
590 static void yahoo_conf_leave(struct yahoo_data *yd, const char *room, const char *dn, GList *who) | |
591 { | |
592 struct yahoo_packet *pkt; | |
593 GList *w; | |
594 | |
595 | |
596 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGOFF, YAHOO_STATUS_AVAILABLE, 0); | |
597 | |
598 yahoo_packet_hash(pkt, 1, dn); | |
599 for (w = who; w; w = w->next) { | |
600 yahoo_packet_hash(pkt, 3, (char *)w->data); | |
601 } | |
602 | |
603 yahoo_packet_hash(pkt, 57, room); | |
604 | |
605 yahoo_send_packet(yd, pkt); | |
606 | |
607 yahoo_packet_free(pkt); | |
608 } | |
609 | |
7827 | 610 static int yahoo_conf_send(GaimConnection *gc, const char *dn, const char *room, |
6729 | 611 GList *members, const char *what) |
612 { | |
7827 | 613 struct yahoo_data *yd = gc->proto_data; |
6729 | 614 struct yahoo_packet *pkt; |
615 GList *who; | |
7827 | 616 char *msg, *msg2; |
617 int utf8 = 1; | |
6804 | 618 |
619 msg = yahoo_html_to_codes(what); | |
7827 | 620 msg2 = yahoo_string_encode(gc, msg, &utf8); |
621 | |
6729 | 622 |
623 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFMSG, YAHOO_STATUS_AVAILABLE, 0); | |
624 | |
625 yahoo_packet_hash(pkt, 1, dn); | |
626 for (who = members; who; who = who->next) | |
627 yahoo_packet_hash(pkt, 53, (char *)who->data); | |
628 yahoo_packet_hash(pkt, 57, room); | |
7827 | 629 yahoo_packet_hash(pkt, 14, msg2); |
630 if (utf8) | |
631 yahoo_packet_hash(pkt, 97, "1"); /* utf-8 */ | |
6729 | 632 |
633 yahoo_send_packet(yd, pkt); | |
634 | |
635 yahoo_packet_free(pkt); | |
6804 | 636 g_free(msg); |
7827 | 637 g_free(msg2); |
6729 | 638 |
639 return 0; | |
640 } | |
641 | |
642 static void yahoo_conf_join(struct yahoo_data *yd, GaimConversation *c, const char *dn, const char *room, | |
643 const char *topic, const char *members) | |
644 { | |
645 struct yahoo_packet *pkt; | |
646 char **memarr = NULL; | |
647 int i; | |
648 | |
649 if (members) | |
650 memarr = g_strsplit(members, "\n", 0); | |
651 | |
652 | |
653 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGON, YAHOO_STATUS_AVAILABLE, 0); | |
654 | |
655 yahoo_packet_hash(pkt, 1, dn); | |
656 yahoo_packet_hash(pkt, 3, dn); | |
657 yahoo_packet_hash(pkt, 57, room); | |
658 if (memarr) { | |
659 for(i = 0 ; memarr[i]; i++) { | |
660 if (!strcmp(memarr[i], "") || !strcmp(memarr[i], dn)) | |
661 continue; | |
662 yahoo_packet_hash(pkt, 3, memarr[i]); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
663 gaim_conv_chat_add_user(GAIM_CONV_CHAT(c), memarr[i], NULL); |
6729 | 664 } |
665 } | |
666 yahoo_send_packet(yd, pkt); | |
667 | |
668 yahoo_packet_free(pkt); | |
669 | |
670 if (memarr) | |
671 g_strfreev(memarr); | |
672 } | |
673 | |
7827 | 674 static void yahoo_conf_invite(GaimConnection *gc, GaimConversation *c, |
6729 | 675 const char *dn, const char *buddy, const char *room, const char *msg) |
676 { | |
7827 | 677 struct yahoo_data *yd = gc->proto_data; |
6729 | 678 struct yahoo_packet *pkt; |
679 GList *members; | |
7827 | 680 char *msg2 = NULL; |
681 | |
682 if (msg) | |
683 msg2 = yahoo_string_encode(gc, msg, NULL); | |
6729 | 684 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
685 members = gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)); |
6729 | 686 |
687 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE, YAHOO_STATUS_AVAILABLE, 0); | |
688 | |
689 yahoo_packet_hash(pkt, 1, dn); | |
690 yahoo_packet_hash(pkt, 51, buddy); | |
691 yahoo_packet_hash(pkt, 57, room); | |
7827 | 692 yahoo_packet_hash(pkt, 58, msg?msg2:""); |
6729 | 693 yahoo_packet_hash(pkt, 13, "0"); |
694 for(; members; members = members->next) { | |
695 if (!strcmp(members->data, dn)) | |
696 continue; | |
697 yahoo_packet_hash(pkt, 52, (char *)members->data); | |
698 yahoo_packet_hash(pkt, 53, (char *)members->data); | |
699 } | |
700 yahoo_send_packet(yd, pkt); | |
701 | |
702 yahoo_packet_free(pkt); | |
7827 | 703 if (msg) |
704 g_free(msg2); | |
6729 | 705 } |
706 | |
707 /* | |
708 * Functions dealing with chats | |
709 */ | |
710 | |
7186 | 711 static void yahoo_chat_leave(GaimConnection *gc, const char *room, const char *dn, gboolean logout) |
6729 | 712 { |
7186 | 713 struct yahoo_data *yd = gc->proto_data; |
6729 | 714 struct yahoo_packet *pkt; |
7186 | 715 GaimConversation *c; |
7827 | 716 char *eroom; |
717 | |
718 eroom = yahoo_string_encode(gc, room, NULL); | |
6729 | 719 |
720 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATEXIT, YAHOO_STATUS_AVAILABLE, 0); | |
721 | |
7827 | 722 yahoo_packet_hash(pkt, 104, eroom); |
6729 | 723 yahoo_packet_hash(pkt, 109, dn); |
724 yahoo_packet_hash(pkt, 108, "1"); | |
725 yahoo_packet_hash(pkt, 112, "0"); /* what does this one mean? */ | |
726 | |
727 yahoo_send_packet(yd, pkt); | |
728 | |
729 yahoo_packet_free(pkt); | |
730 | |
731 yd->in_chat = 0; | |
732 if (yd->chat_name) { | |
733 g_free(yd->chat_name); | |
734 yd->chat_name = NULL; | |
735 } | |
736 | |
7186 | 737 if ((c = gaim_find_chat(gc, YAHOO_CHAT_ID))) |
738 serv_got_chat_left(gc, YAHOO_CHAT_ID); | |
739 | |
740 if (!logout) | |
741 return; | |
742 | |
743 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATLOGOUT, | |
744 YAHOO_STATUS_AVAILABLE, 0); | |
745 yahoo_packet_hash(pkt, 1, dn); | |
746 yahoo_send_packet(yd, pkt); | |
747 yahoo_packet_free(pkt); | |
748 | |
749 yd->chat_online = 0; | |
7827 | 750 g_free(eroom); |
6729 | 751 } |
752 | |
6804 | 753 /* borrowed from gtkconv.c */ |
754 static gboolean | |
755 meify(char *message, size_t len) | |
756 { | |
757 /* | |
758 * Read /me-ify: If the message (post-HTML) starts with /me, | |
759 * remove the "/me " part of it (including that space) and return TRUE. | |
760 */ | |
761 char *c; | |
762 gboolean inside_html = 0; | |
763 | |
764 /* Umm.. this would be very bad if this happens. */ | |
765 g_return_val_if_fail(message != NULL, FALSE); | |
766 | |
767 if (len == -1) | |
768 len = strlen(message); | |
769 | |
770 for (c = message; *c != '\0'; c++, len--) { | |
771 if (inside_html) { | |
772 if (*c == '>') | |
773 inside_html = FALSE; | |
774 } | |
775 else { | |
776 if (*c == '<') | |
777 inside_html = TRUE; | |
778 else | |
779 break; | |
780 } | |
781 } | |
782 | |
783 if (*c != '\0' && !g_ascii_strncasecmp(c, "/me ", 4)) { | |
784 memmove(c, c + 4, len - 3); | |
785 | |
786 return TRUE; | |
787 } | |
788 | |
789 return FALSE; | |
790 } | |
791 | |
7827 | 792 static int yahoo_chat_send(GaimConnection *gc, const char *dn, const char *room, const char *what) |
6729 | 793 { |
7827 | 794 struct yahoo_data *yd = gc->proto_data; |
6729 | 795 struct yahoo_packet *pkt; |
796 int me = 0; | |
7827 | 797 char *msg1, *msg2, *room2; |
798 gboolean utf8 = TRUE; | |
6804 | 799 |
800 msg1 = g_strdup(what); | |
6729 | 801 |
6804 | 802 if (meify(msg1, -1)) |
6729 | 803 me = 1; |
6804 | 804 |
805 msg2 = yahoo_html_to_codes(msg1); | |
806 g_free(msg1); | |
7827 | 807 msg1 = yahoo_string_encode(gc, msg2, &utf8); |
808 g_free(msg2); | |
809 room2 = yahoo_string_encode(gc, room, NULL); | |
6729 | 810 |
811 pkt = yahoo_packet_new(YAHOO_SERVICE_COMMENT, YAHOO_STATUS_AVAILABLE, 0); | |
812 | |
813 yahoo_packet_hash(pkt, 1, dn); | |
7827 | 814 yahoo_packet_hash(pkt, 104, room2); |
815 yahoo_packet_hash(pkt, 117, msg1); | |
6729 | 816 if (me) |
817 yahoo_packet_hash(pkt, 124, "2"); | |
818 else | |
819 yahoo_packet_hash(pkt, 124, "1"); | |
820 /* fixme: what about /think? (124=3) */ | |
7827 | 821 if (utf8) |
822 yahoo_packet_hash(pkt, 97, "1"); | |
6729 | 823 |
824 yahoo_send_packet(yd, pkt); | |
825 yahoo_packet_free(pkt); | |
7827 | 826 g_free(msg1); |
827 g_free(room2); | |
6729 | 828 |
829 return 0; | |
830 } | |
831 | |
7827 | 832 static void yahoo_chat_join(GaimConnection *gc, const char *dn, const char *room, const char *topic) |
6729 | 833 { |
7827 | 834 struct yahoo_data *yd = gc->proto_data; |
6729 | 835 struct yahoo_packet *pkt; |
7827 | 836 char *room2; |
837 | |
838 room2 = yahoo_string_encode(gc, room, NULL); | |
6729 | 839 |
840 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YAHOO_STATUS_AVAILABLE, 0); | |
841 | |
7868 | 842 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
6729 | 843 yahoo_packet_hash(pkt, 62, "2"); |
7827 | 844 yahoo_packet_hash(pkt, 104, room2); |
6729 | 845 yahoo_packet_hash(pkt, 129, "0"); |
846 | |
847 yahoo_send_packet(yd, pkt); | |
848 | |
849 yahoo_packet_free(pkt); | |
7827 | 850 g_free(room2); |
6729 | 851 } |
852 | |
7827 | 853 static void yahoo_chat_invite(GaimConnection *gc, const char *dn, const char *buddy, |
6729 | 854 const char *room, const char *msg) |
855 { | |
7827 | 856 struct yahoo_data *yd = gc->proto_data; |
6729 | 857 struct yahoo_packet *pkt; |
7827 | 858 char *room2, *msg2 = NULL; |
6729 | 859 |
7827 | 860 room2 = yahoo_string_encode(gc, room, NULL); |
861 if (msg) | |
862 msg2 = yahoo_string_encode(gc, msg, NULL); | |
6729 | 863 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATADDINVITE, YAHOO_STATUS_AVAILABLE, 0); |
864 | |
865 yahoo_packet_hash(pkt, 1, dn); | |
866 yahoo_packet_hash(pkt, 118, buddy); | |
7827 | 867 yahoo_packet_hash(pkt, 104, room2); |
868 yahoo_packet_hash(pkt, 117, (msg2?msg2:"")); | |
6729 | 869 yahoo_packet_hash(pkt, 129, "0"); |
870 | |
871 yahoo_send_packet(yd, pkt); | |
872 yahoo_packet_free(pkt); | |
7827 | 873 |
874 g_free(room2); | |
875 if (msg2) | |
876 g_free(msg2); | |
6729 | 877 } |
878 | |
879 void yahoo_chat_goto(GaimConnection *gc, const char *name) | |
880 { | |
881 struct yahoo_data *yd; | |
882 struct yahoo_packet *pkt; | |
883 | |
884 yd = gc->proto_data; | |
885 | |
886 if (!yd->chat_online) | |
887 yahoo_chat_online(gc); | |
888 | |
889 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATGOTO, YAHOO_STATUS_AVAILABLE, 0); | |
890 | |
891 yahoo_packet_hash(pkt, 109, name); | |
892 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
893 yahoo_packet_hash(pkt, 62, "2"); | |
894 | |
895 yahoo_send_packet(yd, pkt); | |
896 yahoo_packet_free(pkt); | |
897 } | |
898 /* | |
899 * These are the functions registered with the core | |
900 * which get called for both chats and conferences. | |
901 */ | |
902 | |
903 void yahoo_c_leave(GaimConnection *gc, int id) | |
904 { | |
905 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
906 GaimConversation *c; | |
907 | |
908 if (!yd) | |
909 return; | |
910 | |
911 | |
912 c = gaim_find_chat(gc, id); | |
913 if (!c) | |
914 return; | |
915 | |
916 if (id != YAHOO_CHAT_ID) { | |
917 yahoo_conf_leave(yd, gaim_conversation_get_name(c), | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
918 gaim_connection_get_display_name(gc), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c))); |
6729 | 919 yd->confs = g_slist_remove(yd->confs, c); |
920 } else { | |
7186 | 921 yahoo_chat_leave(gc, gaim_conversation_get_name(c), gaim_connection_get_display_name(gc), TRUE); |
6729 | 922 } |
923 | |
924 serv_got_chat_left(gc, id); | |
925 } | |
926 | |
927 int yahoo_c_send(GaimConnection *gc, int id, const char *what) | |
928 { | |
929 GaimConversation *c; | |
930 int ret; | |
931 struct yahoo_data *yd; | |
932 | |
933 yd = (struct yahoo_data *) gc->proto_data; | |
934 if (!yd) | |
935 return -1; | |
936 | |
937 c = gaim_find_chat(gc, id); | |
938 if (!c) | |
939 return -1; | |
940 | |
941 if (id != YAHOO_CHAT_ID) { | |
7827 | 942 ret = yahoo_conf_send(gc, gaim_connection_get_display_name(gc), |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
943 gaim_conversation_get_name(c), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)), what); |
6729 | 944 } else { |
7827 | 945 ret = yahoo_chat_send(gc, gaim_connection_get_display_name(gc), |
6804 | 946 gaim_conversation_get_name(c), what); |
6729 | 947 if (!ret) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
948 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), |
6729 | 949 gaim_connection_get_display_name(gc), 0, what, time(NULL)); |
950 } | |
951 return ret; | |
952 } | |
953 | |
954 GList *yahoo_c_info(GaimConnection *gc) | |
955 { | |
956 GList *m = NULL; | |
957 struct proto_chat_entry *pce; | |
958 | |
959 pce = g_new0(struct proto_chat_entry, 1); | |
7841 | 960 pce->label = _("_Room:"); |
6729 | 961 pce->identifier = "room"; |
962 m = g_list_append(m, pce); | |
963 | |
964 return m; | |
965 } | |
966 | |
967 void yahoo_c_join(GaimConnection *gc, GHashTable *data) | |
968 { | |
969 struct yahoo_data *yd; | |
970 char *room, *topic, *members, *type; | |
971 int id; | |
972 GaimConversation *c; | |
973 | |
974 yd = (struct yahoo_data *) gc->proto_data; | |
975 if (!yd) | |
976 return; | |
977 | |
978 room = g_hash_table_lookup(data, "room"); | |
979 if (!room) | |
980 return; | |
981 | |
982 topic = g_hash_table_lookup(data, "topic"); | |
983 if (!topic) | |
984 topic = ""; | |
985 | |
986 members = g_hash_table_lookup(data, "members"); | |
987 | |
988 | |
989 if ((type = g_hash_table_lookup(data, "type")) && !strcmp(type, "Conference")) { | |
990 id = yd->conf_id++; | |
991 c = serv_got_joined_chat(gc, id, room); | |
992 yd->confs = g_slist_prepend(yd->confs, c); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
993 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), gaim_connection_get_display_name(gc), topic); |
6729 | 994 yahoo_conf_join(yd, c, gaim_connection_get_display_name(gc), room, topic, members); |
995 return; | |
996 } else { | |
997 if (yd->in_chat) | |
7186 | 998 yahoo_chat_leave(gc, room, |
999 gaim_connection_get_display_name(gc), | |
1000 FALSE); | |
6729 | 1001 if (!yd->chat_online) |
1002 yahoo_chat_online(gc); | |
7827 | 1003 yahoo_chat_join(gc, gaim_connection_get_display_name(gc), room, topic); |
6729 | 1004 return; |
1005 } | |
1006 } | |
1007 | |
1008 void yahoo_c_invite(GaimConnection *gc, int id, const char *msg, const char *name) | |
1009 { | |
1010 GaimConversation *c; | |
1011 | |
1012 c = gaim_find_chat(gc, id); | |
1013 if (!c || !c->name) | |
1014 return; | |
1015 | |
1016 if (id != YAHOO_CHAT_ID) { | |
7827 | 1017 yahoo_conf_invite(gc, c, gaim_connection_get_display_name(gc), name, |
6729 | 1018 gaim_conversation_get_name(c), msg); |
1019 } else { | |
7827 | 1020 yahoo_chat_invite(gc, gaim_connection_get_display_name(gc), name, |
6729 | 1021 gaim_conversation_get_name(c), msg); |
1022 } | |
1023 } | |
1024 | |
8113 | 1025 |
1026 struct yahoo_roomlist { | |
1027 int fd; | |
1028 int inpa; | |
1029 guchar *rxqueue; | |
1030 int rxlen; | |
1031 gboolean started; | |
1032 char *path; | |
1033 char *host; | |
1034 GaimRoomlist *list; | |
1035 GaimRoomlistRoom *cat; | |
1036 GaimRoomlistRoom *ucat; | |
1037 GMarkupParseContext *parse; | |
1038 | |
1039 }; | |
1040 | |
1041 static void yahoo_roomlist_destroy(struct yahoo_roomlist *yrl) | |
1042 { | |
1043 if (yrl->inpa) | |
1044 gaim_input_remove(yrl->inpa); | |
1045 if (yrl->rxqueue) | |
1046 g_free(yrl->rxqueue); | |
1047 if (yrl->path) | |
1048 g_free(yrl->path); | |
1049 if (yrl->host) | |
1050 g_free(yrl->host); | |
1051 if (yrl->parse) | |
1052 g_markup_parse_context_free(yrl->parse); | |
1053 } | |
1054 | |
1055 enum yahoo_room_type { | |
1056 yrt_yahoo, | |
1057 yrt_user, | |
1058 }; | |
1059 | |
1060 struct yahoo_chatxml_state { | |
1061 GaimRoomlist *list; | |
1062 struct yahoo_roomlist *yrl; | |
1063 GQueue *q; | |
1064 struct { | |
1065 enum yahoo_room_type type; | |
1066 char *name; | |
1067 char *topic; | |
1068 char *id; | |
1069 int users, voices, webcams; | |
1070 } room; | |
1071 }; | |
1072 | |
1073 struct yahoo_lobby { | |
1074 int count, users, voices, webcams; | |
1075 }; | |
1076 | |
1077 static struct yahoo_chatxml_state *yahoo_chatxml_state_new(GaimRoomlist *list, struct yahoo_roomlist *yrl) | |
1078 { | |
1079 struct yahoo_chatxml_state *s; | |
1080 | |
1081 s = g_new0(struct yahoo_chatxml_state, 1); | |
1082 | |
1083 s->list = list; | |
1084 s->yrl = yrl; | |
1085 s->q = g_queue_new(); | |
1086 | |
1087 return s; | |
1088 } | |
1089 | |
1090 static void yahoo_chatxml_state_destroy(struct yahoo_chatxml_state *s) | |
1091 { | |
1092 g_queue_free(s->q); | |
1093 if (s->room.name) | |
1094 g_free(s->room.name); | |
1095 if (s->room.topic) | |
1096 g_free(s->room.topic); | |
1097 if (s->room.id) | |
1098 g_free(s->room.id); | |
1099 g_free(s); | |
1100 } | |
1101 | |
1102 static void yahoo_chatlist_start_element(GMarkupParseContext *context, const gchar *ename, | |
1103 const gchar **anames, const gchar **avalues, | |
1104 gpointer user_data, GError **error) | |
1105 { | |
1106 struct yahoo_chatxml_state *s = user_data; | |
1107 GaimRoomlist *list = s->list; | |
1108 GaimRoomlistRoom *r; | |
1109 GaimRoomlistRoom *parent; | |
1110 int i; | |
1111 | |
1112 if (!strcmp(ename, "category")) { | |
1113 const gchar *name = NULL, *id = NULL; | |
1114 | |
1115 for (i = 0; anames[i]; i++) { | |
1116 if (!strcmp(anames[i], "id")) | |
1117 id = avalues[i]; | |
1118 if (!strcmp(anames[i], "name")) | |
1119 name = avalues[i]; | |
1120 } | |
1121 if (!name || !id) | |
1122 return; | |
1123 | |
1124 parent = g_queue_peek_head(s->q); | |
1125 r = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATAGORY, name, parent); | |
1126 gaim_roomlist_room_add_field(list, r, (gpointer)name); | |
1127 gaim_roomlist_room_add_field(list, r, (gpointer)id); | |
1128 gaim_roomlist_room_add(list, r); | |
1129 g_queue_push_head(s->q, r); | |
1130 } else if (!strcmp(ename, "room")) { | |
1131 s->room.users = s->room.voices = s->room.webcams = 0; | |
1132 | |
1133 for (i = 0; anames[i]; i++) { | |
1134 if (!strcmp(anames[i], "id")) { | |
1135 if (s->room.id) | |
1136 g_free(s->room.id); | |
1137 s->room.id = g_strdup(avalues[i]); | |
1138 } else if (!strcmp(anames[i], "name")) { | |
1139 if (s->room.name) | |
1140 g_free(s->room.name); | |
1141 s->room.name = g_strdup(avalues[i]); | |
1142 } else if (!strcmp(anames[i], "topic")) { | |
1143 if (s->room.topic) | |
1144 g_free(s->room.topic); | |
1145 s->room.topic = g_strdup(avalues[i]); | |
1146 } else if (!strcmp(anames[i], "type")) { | |
1147 if (!strcmp("yahoo", avalues[i])) | |
1148 s->room.type = yrt_yahoo; | |
1149 else | |
1150 s->room.type = yrt_user; | |
1151 } | |
1152 } | |
1153 | |
1154 } else if (!strcmp(ename, "lobby")) { | |
1155 struct yahoo_lobby *lob = g_new0(struct yahoo_lobby, 1); | |
1156 | |
1157 for (i = 0; anames[i]; i++) { | |
1158 if (!strcmp(anames[i], "count")) { | |
1159 lob->count = strtol(avalues[i], NULL, 10); | |
1160 } else if (!strcmp(anames[i], "users")) { | |
1161 s->room.users += lob->users = strtol(avalues[i], NULL, 10); | |
1162 } else if (!strcmp(anames[i], "voices")) { | |
1163 s->room.voices += lob->voices = strtol(avalues[i], NULL, 10); | |
1164 } else if (!strcmp(anames[i], "webcams")) { | |
1165 s->room.webcams += lob->webcams = strtol(avalues[i], NULL, 10); | |
1166 } | |
1167 } | |
1168 | |
1169 g_queue_push_head(s->q, lob); | |
1170 } | |
1171 | |
1172 } | |
1173 | |
1174 static void yahoo_chatlist_end_element(GMarkupParseContext *context, const gchar *ename, | |
1175 gpointer user_data, GError **error) | |
1176 { | |
1177 struct yahoo_chatxml_state *s = user_data; | |
1178 | |
1179 if (!strcmp(ename, "category")) { | |
1180 g_queue_pop_head(s->q); | |
1181 } else if (!strcmp(ename, "room")) { | |
1182 struct yahoo_lobby *lob; | |
1183 GaimRoomlistRoom *r, *l; | |
1184 | |
1185 if (s->room.type == yrt_yahoo) | |
1186 r = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATAGORY|GAIM_ROOMLIST_ROOMTYPE_ROOM, | |
1187 s->room.name, s->yrl->cat); | |
1188 else | |
1189 r = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATAGORY|GAIM_ROOMLIST_ROOMTYPE_ROOM, | |
1190 s->room.name, s->yrl->ucat); | |
1191 | |
1192 gaim_roomlist_room_add_field(s->list, r, s->room.name); | |
1193 gaim_roomlist_room_add_field(s->list, r, s->room.id); | |
1194 gaim_roomlist_room_add_field(s->list, r, GINT_TO_POINTER(s->room.users)); | |
1195 gaim_roomlist_room_add_field(s->list, r, GINT_TO_POINTER(s->room.voices)); | |
1196 gaim_roomlist_room_add_field(s->list, r, GINT_TO_POINTER(s->room.webcams)); | |
1197 gaim_roomlist_room_add_field(s->list, r, s->room.topic); | |
1198 gaim_roomlist_room_add(s->list, r); | |
1199 | |
1200 while ((lob = g_queue_pop_head(s->q))) { | |
1201 char *name = g_strdup_printf("%s:%d", s->room.name, lob->count); | |
1202 l = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, name, r); | |
1203 | |
1204 gaim_roomlist_room_add_field(s->list, l, name); | |
1205 gaim_roomlist_room_add_field(s->list, l, s->room.id); | |
1206 gaim_roomlist_room_add_field(s->list, l, GINT_TO_POINTER(lob->users)); | |
1207 gaim_roomlist_room_add_field(s->list, l, GINT_TO_POINTER(lob->voices)); | |
1208 gaim_roomlist_room_add_field(s->list, l, GINT_TO_POINTER(lob->webcams)); | |
1209 gaim_roomlist_room_add_field(s->list, l, s->room.topic); | |
1210 gaim_roomlist_room_add(s->list, l); | |
1211 | |
1212 g_free(name); | |
1213 g_free(lob); | |
1214 } | |
1215 | |
1216 } | |
1217 | |
1218 } | |
1219 | |
1220 static GMarkupParser parser = { | |
1221 yahoo_chatlist_start_element, | |
1222 yahoo_chatlist_end_element, | |
1223 NULL, | |
1224 NULL, | |
1225 NULL | |
1226 }; | |
1227 | |
1228 static void yahoo_roomlist_cleanup(GaimRoomlist *list, struct yahoo_roomlist *yrl) | |
1229 { | |
1230 gaim_roomlist_set_in_progress(list, FALSE); | |
1231 | |
1232 if (yrl) { | |
1233 list->proto_data = g_list_remove(list->proto_data, yrl); | |
1234 yahoo_roomlist_destroy(yrl); | |
1235 } | |
1236 | |
1237 gaim_roomlist_unref(list); | |
1238 } | |
1239 | |
1240 static void yahoo_roomlist_pending(gpointer data, gint source, GaimInputCondition cond) | |
1241 { | |
1242 struct yahoo_roomlist *yrl = data; | |
1243 GaimRoomlist *list = yrl->list; | |
1244 char buf[1024]; | |
1245 int len; | |
1246 guchar *start; | |
1247 struct yahoo_chatxml_state *s; | |
1248 | |
1249 len = read(yrl->fd, buf, sizeof(buf)); | |
1250 | |
1251 if (len <= 0) { | |
1252 if (yrl->parse) | |
1253 g_markup_parse_context_end_parse(yrl->parse, NULL); | |
1254 yahoo_roomlist_cleanup(list, yrl); | |
1255 return; | |
1256 } | |
1257 | |
1258 | |
1259 yrl->rxqueue = g_realloc(yrl->rxqueue, len + yrl->rxlen); | |
1260 memcpy(yrl->rxqueue + yrl->rxlen, buf, len); | |
1261 yrl->rxlen += len; | |
1262 | |
1263 if (!yrl->started) { | |
1264 yrl->started = TRUE; | |
1265 start = g_strstr_len(yrl->rxqueue, yrl->rxlen, "\r\n\r\n"); | |
1266 if (!start || (start - yrl->rxqueue + 4) >= yrl->rxlen) | |
1267 return; | |
1268 start += 4; | |
1269 } else { | |
1270 start = yrl->rxqueue; | |
1271 } | |
1272 | |
1273 if (yrl->parse == NULL) { | |
1274 s = yahoo_chatxml_state_new(list, yrl); | |
1275 yrl->parse = g_markup_parse_context_new(&parser, 0, s, | |
1276 (GDestroyNotify)yahoo_chatxml_state_destroy); | |
1277 } | |
1278 | |
1279 if (!g_markup_parse_context_parse(yrl->parse, start, (yrl->rxlen - (start - yrl->rxqueue)), NULL)) { | |
1280 | |
1281 yahoo_roomlist_cleanup(list, yrl); | |
1282 return; | |
1283 } | |
1284 | |
1285 yrl->rxlen = 0; | |
1286 } | |
1287 | |
1288 static void yahoo_roomlist_got_connected(gpointer data, gint source, GaimInputCondition cond) | |
1289 { | |
1290 struct yahoo_roomlist *yrl = data; | |
1291 GaimRoomlist *list = yrl->list; | |
1292 char *buf, *cookie; | |
1293 struct yahoo_data *yd = gaim_account_get_connection(list->account)->proto_data; | |
1294 | |
1295 if (source < 0) { | |
1296 gaim_notify_error(gaim_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed.")); | |
1297 yahoo_roomlist_cleanup(list, yrl); | |
1298 return; | |
1299 } | |
1300 | |
1301 yrl->fd = source; | |
1302 | |
1303 cookie = g_strdup_printf("Y=%s; T=%s", yd->cookie_y, yd->cookie_t); | |
1304 buf = g_strdup_printf("GET /%s HTTP/1.0\r\nHost: %s\r\nCookie: %s\r\n\r\n", yrl->path, yrl->host, cookie); | |
1305 write(yrl->fd, buf, strlen(buf)); | |
1306 g_free(cookie); | |
1307 g_free(buf); | |
1308 yrl->inpa = gaim_input_add(yrl->fd, GAIM_INPUT_READ, yahoo_roomlist_pending, yrl); | |
1309 | |
1310 } | |
1311 | |
1312 GaimRoomlist *yahoo_roomlist_get_list(GaimConnection *gc) | |
1313 { | |
1314 struct yahoo_roomlist *yrl; | |
1315 GaimRoomlist *rl; | |
1316 char *url; | |
1317 GList *fields = NULL; | |
1318 GaimRoomlistField *f; | |
1319 | |
1320 url = g_strdup_printf("%s?chatcat=0", | |
1321 gaim_account_get_string( | |
1322 gaim_connection_get_account(gc), | |
1323 "room_list", YAHOO_ROOMLIST_URL)); | |
1324 | |
1325 yrl = g_new0(struct yahoo_roomlist, 1); | |
1326 rl = gaim_roomlist_new(gaim_connection_get_account(gc)); | |
1327 yrl->list = rl; | |
1328 | |
1329 gaim_url_parse(url, &(yrl->host), NULL, &(yrl->path)); | |
1330 g_free(url); | |
1331 | |
1332 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "room", TRUE); | |
1333 fields = g_list_append(fields, f); | |
1334 | |
1335 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "id", TRUE); | |
1336 fields = g_list_append(fields, f); | |
1337 | |
1338 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Users"), "users", FALSE); | |
1339 fields = g_list_append(fields, f); | |
1340 | |
1341 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Voices"), "voices", FALSE); | |
1342 fields = g_list_append(fields, f); | |
1343 | |
1344 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Webcams"), "webcams", FALSE); | |
1345 fields = g_list_append(fields, f); | |
1346 | |
1347 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Topic"), "topic", FALSE); | |
1348 fields = g_list_append(fields, f); | |
1349 | |
1350 gaim_roomlist_set_fields(rl, fields); | |
1351 | |
1352 if (gaim_proxy_connect(gaim_connection_get_account(gc), | |
1353 yrl->host, 80, yahoo_roomlist_got_connected, yrl) != 0) | |
1354 { | |
1355 gaim_notify_error(gc, NULL, _("Connection problem"), _("Unable to fetch room list.")); | |
1356 yahoo_roomlist_cleanup(rl, yrl); | |
1357 return NULL; | |
1358 } | |
1359 | |
1360 rl->proto_data = g_list_append(rl->proto_data, yrl); | |
1361 | |
1362 gaim_roomlist_set_in_progress(rl, TRUE); | |
1363 return rl; | |
1364 } | |
1365 | |
1366 void yahoo_roomlist_cancel(GaimRoomlist *list) | |
1367 { | |
1368 GList *l, *k; | |
1369 | |
1370 k = l = list->proto_data; | |
1371 list->proto_data = NULL; | |
1372 | |
1373 gaim_roomlist_set_in_progress(list, FALSE); | |
1374 | |
1375 for (; l; l = l->next) { | |
1376 yahoo_roomlist_destroy(l->data); | |
1377 gaim_roomlist_unref(l->data); | |
1378 } | |
1379 g_list_free(k); | |
1380 } | |
1381 | |
1382 void yahoo_roomlist_expand_catagory(GaimRoomlist *list, GaimRoomlistRoom *catagory) | |
1383 { | |
1384 struct yahoo_roomlist *yrl; | |
1385 char *url; | |
1386 char *id; | |
1387 | |
1388 if (catagory->type != GAIM_ROOMLIST_ROOMTYPE_CATAGORY) | |
1389 return; | |
1390 | |
1391 if (!(id = g_list_nth_data(catagory->fields, 1))) { | |
1392 gaim_roomlist_set_in_progress(list, FALSE); | |
1393 return; | |
1394 } | |
1395 | |
1396 url = g_strdup_printf("%s?chatroom_%s=0", | |
1397 gaim_account_get_string( | |
1398 list->account, | |
1399 "room_list", YAHOO_ROOMLIST_URL), id); | |
1400 | |
1401 yrl = g_new0(struct yahoo_roomlist, 1); | |
1402 yrl->list = list; | |
1403 yrl->cat = catagory; | |
1404 list->proto_data = g_list_append(list->proto_data, yrl); | |
1405 | |
1406 gaim_url_parse(url, &(yrl->host), NULL, &(yrl->path)); | |
1407 g_free(url); | |
1408 | |
1409 yrl->ucat = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATAGORY, _("User Rooms"), yrl->cat); | |
1410 gaim_roomlist_room_add(list, yrl->ucat); | |
1411 | |
1412 if (gaim_proxy_connect(list->account, | |
1413 yrl->host, 80, yahoo_roomlist_got_connected, yrl) != 0) | |
1414 { | |
1415 gaim_notify_error(gaim_account_get_connection(list->account), | |
1416 NULL, _("Connection problem"), _("Unable to fetch room list.")); | |
1417 yahoo_roomlist_cleanup(list, yrl); | |
1418 return; | |
1419 } | |
1420 | |
1421 gaim_roomlist_set_in_progress(list, TRUE); | |
1422 gaim_roomlist_ref(list); | |
1423 } | |
1424 |