Mercurial > pidgin
annotate src/protocols/yahoo/yahoochat.c @ 8113:d60272410bd5
[gaim-migrate @ 8817]
Tim 'marv' Ringenbach wrote us a wonderful core/ui split chat room list
thing-a-ma-jig. I've taken the liberty of adding jabber support to it
as well.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 15 Jan 2004 22:20:29 +0000 |
parents | fa6395637e2c |
children | 1f56ea865926 |
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 | |
7186 | 410 if (!c && members && ((g_list_length(members) > 1) || |
411 !g_ascii_strcasecmp(members->data, | |
412 gaim_connection_get_display_name(gc)))) { | |
6729 | 413 c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); |
414 if (topic) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
415 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); |
6729 | 416 yd->in_chat = 1; |
417 yd->chat_name = g_strdup(room); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
418 gaim_conv_chat_add_users(GAIM_CONV_CHAT(c), members); |
7186 | 419 } else if (c) { |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
420 yahoo_chat_add_users(GAIM_CONV_CHAT(c), members); |
6729 | 421 } |
422 | |
423 g_list_free(members); | |
7827 | 424 g_free(room); |
425 if (topic) | |
426 g_free(topic); | |
6729 | 427 } |
428 | |
429 void yahoo_process_chat_exit(GaimConnection *gc, struct yahoo_packet *pkt) | |
430 { | |
431 char *who = NULL; | |
7186 | 432 char *room = NULL; |
6729 | 433 GSList *l; |
434 struct yahoo_data *yd; | |
435 | |
436 yd = gc->proto_data; | |
437 | |
438 for (l = pkt->hash; l; l = l->next) { | |
439 struct yahoo_pair *pair = l->data; | |
440 | |
7186 | 441 if (pair->key == 104) |
7827 | 442 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 443 if (pair->key == 109) |
444 who = pair->value; | |
445 } | |
446 | |
447 | |
7186 | 448 if (who && room) { |
6729 | 449 GaimConversation *c = gaim_find_chat(gc, YAHOO_CHAT_ID); |
7186 | 450 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
|
451 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); |
6729 | 452 |
453 } | |
7827 | 454 if (room) |
455 g_free(room); | |
6729 | 456 } |
457 | |
458 void yahoo_process_chat_message(GaimConnection *gc, struct yahoo_packet *pkt) | |
459 { | |
7827 | 460 char *room = NULL, *who = NULL, *msg = NULL, *msg2; |
461 int msgtype = 1, utf8 = 0; | |
6729 | 462 GaimConversation *c = NULL; |
463 GSList *l; | |
464 | |
465 for (l = pkt->hash; l; l = l->next) { | |
466 struct yahoo_pair *pair = l->data; | |
467 | |
468 switch (pair->key) { | |
469 | |
7827 | 470 case 97: |
471 utf8 = strtol(pair->value, NULL, 10); | |
472 break; | |
6729 | 473 case 104: |
7827 | 474 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 475 break; |
476 case 109: | |
477 who = pair->value; | |
478 break; | |
479 case 117: | |
480 msg = pair->value; | |
481 break; | |
482 case 124: | |
483 msgtype = strtol(pair->value, NULL, 10); | |
484 break; | |
485 } | |
486 } | |
487 | |
488 | |
489 c = gaim_find_chat(gc, YAHOO_CHAT_ID); | |
7827 | 490 if (!who || !c) { |
491 if (room) | |
492 g_free(room); | |
6729 | 493 /* we still get messages after we part, funny that */ |
494 return; | |
495 } | |
496 | |
497 if (!msg) { | |
498 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Got a message packet with no message.\nThis probably means something important, but we're ignoring it.\n"); | |
499 return; | |
500 } | |
7827 | 501 msg2 = yahoo_string_decode(gc, msg, utf8); |
502 msg = yahoo_codes_to_html(msg2); | |
503 g_free(msg2); | |
6729 | 504 |
505 if (msgtype == 2 || msgtype == 3) { | |
506 char *tmp; | |
507 tmp = g_strdup_printf("/me %s", msg); | |
508 g_free(msg); | |
509 msg = tmp; | |
510 } | |
511 | |
512 serv_got_chat_in(gc, YAHOO_CHAT_ID, who, 0, msg, time(NULL)); | |
513 g_free(msg); | |
514 } | |
515 | |
516 void yahoo_process_chat_addinvite(GaimConnection *gc, struct yahoo_packet *pkt) | |
517 { | |
518 GSList *l; | |
519 char *room = NULL; | |
520 char *msg = NULL; | |
521 char *who = NULL; | |
522 | |
523 | |
524 for (l = pkt->hash; l; l = l->next) { | |
525 struct yahoo_pair *pair = l->data; | |
526 | |
527 switch (pair->key) { | |
528 case 104: | |
7827 | 529 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 530 break; |
531 case 129: /* room id? */ | |
532 break; | |
533 case 126: /* ??? */ | |
534 break; | |
535 case 117: | |
7827 | 536 msg = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 537 break; |
538 case 119: | |
539 who = pair->value; | |
540 break; | |
541 case 118: /* us */ | |
542 break; | |
543 } | |
544 } | |
545 | |
546 if (room && who) { | |
547 GHashTable *components; | |
548 | |
549 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
550 g_hash_table_replace(components, g_strdup("room"), g_strdup(room)); | |
551 serv_got_chat_invite(gc, room, who, msg, components); | |
552 } | |
7827 | 553 if (room) |
554 g_free(room); | |
555 if (msg) | |
556 g_free(msg); | |
6729 | 557 } |
558 | |
559 void yahoo_process_chat_goto(GaimConnection *gc, struct yahoo_packet *pkt) | |
560 { | |
561 if (pkt->status == -1) | |
562 gaim_notify_error(gc, NULL, _("Failed to join buddy in chat"), | |
563 _("Maybe they're not in a chat?")); | |
564 } | |
565 | |
566 | |
567 /* | |
568 * Functions dealing with conferences | |
7827 | 569 * I think conference names are always ascii. |
6729 | 570 */ |
571 | |
572 static void yahoo_conf_leave(struct yahoo_data *yd, const char *room, const char *dn, GList *who) | |
573 { | |
574 struct yahoo_packet *pkt; | |
575 GList *w; | |
576 | |
577 | |
578 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGOFF, YAHOO_STATUS_AVAILABLE, 0); | |
579 | |
580 yahoo_packet_hash(pkt, 1, dn); | |
581 for (w = who; w; w = w->next) { | |
582 yahoo_packet_hash(pkt, 3, (char *)w->data); | |
583 } | |
584 | |
585 yahoo_packet_hash(pkt, 57, room); | |
586 | |
587 yahoo_send_packet(yd, pkt); | |
588 | |
589 yahoo_packet_free(pkt); | |
590 } | |
591 | |
7827 | 592 static int yahoo_conf_send(GaimConnection *gc, const char *dn, const char *room, |
6729 | 593 GList *members, const char *what) |
594 { | |
7827 | 595 struct yahoo_data *yd = gc->proto_data; |
6729 | 596 struct yahoo_packet *pkt; |
597 GList *who; | |
7827 | 598 char *msg, *msg2; |
599 int utf8 = 1; | |
6804 | 600 |
601 msg = yahoo_html_to_codes(what); | |
7827 | 602 msg2 = yahoo_string_encode(gc, msg, &utf8); |
603 | |
6729 | 604 |
605 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFMSG, YAHOO_STATUS_AVAILABLE, 0); | |
606 | |
607 yahoo_packet_hash(pkt, 1, dn); | |
608 for (who = members; who; who = who->next) | |
609 yahoo_packet_hash(pkt, 53, (char *)who->data); | |
610 yahoo_packet_hash(pkt, 57, room); | |
7827 | 611 yahoo_packet_hash(pkt, 14, msg2); |
612 if (utf8) | |
613 yahoo_packet_hash(pkt, 97, "1"); /* utf-8 */ | |
6729 | 614 |
615 yahoo_send_packet(yd, pkt); | |
616 | |
617 yahoo_packet_free(pkt); | |
6804 | 618 g_free(msg); |
7827 | 619 g_free(msg2); |
6729 | 620 |
621 return 0; | |
622 } | |
623 | |
624 static void yahoo_conf_join(struct yahoo_data *yd, GaimConversation *c, const char *dn, const char *room, | |
625 const char *topic, const char *members) | |
626 { | |
627 struct yahoo_packet *pkt; | |
628 char **memarr = NULL; | |
629 int i; | |
630 | |
631 if (members) | |
632 memarr = g_strsplit(members, "\n", 0); | |
633 | |
634 | |
635 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGON, YAHOO_STATUS_AVAILABLE, 0); | |
636 | |
637 yahoo_packet_hash(pkt, 1, dn); | |
638 yahoo_packet_hash(pkt, 3, dn); | |
639 yahoo_packet_hash(pkt, 57, room); | |
640 if (memarr) { | |
641 for(i = 0 ; memarr[i]; i++) { | |
642 if (!strcmp(memarr[i], "") || !strcmp(memarr[i], dn)) | |
643 continue; | |
644 yahoo_packet_hash(pkt, 3, memarr[i]); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
645 gaim_conv_chat_add_user(GAIM_CONV_CHAT(c), memarr[i], NULL); |
6729 | 646 } |
647 } | |
648 yahoo_send_packet(yd, pkt); | |
649 | |
650 yahoo_packet_free(pkt); | |
651 | |
652 if (memarr) | |
653 g_strfreev(memarr); | |
654 } | |
655 | |
7827 | 656 static void yahoo_conf_invite(GaimConnection *gc, GaimConversation *c, |
6729 | 657 const char *dn, const char *buddy, const char *room, const char *msg) |
658 { | |
7827 | 659 struct yahoo_data *yd = gc->proto_data; |
6729 | 660 struct yahoo_packet *pkt; |
661 GList *members; | |
7827 | 662 char *msg2 = NULL; |
663 | |
664 if (msg) | |
665 msg2 = yahoo_string_encode(gc, msg, NULL); | |
6729 | 666 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
667 members = gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)); |
6729 | 668 |
669 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE, YAHOO_STATUS_AVAILABLE, 0); | |
670 | |
671 yahoo_packet_hash(pkt, 1, dn); | |
672 yahoo_packet_hash(pkt, 51, buddy); | |
673 yahoo_packet_hash(pkt, 57, room); | |
7827 | 674 yahoo_packet_hash(pkt, 58, msg?msg2:""); |
6729 | 675 yahoo_packet_hash(pkt, 13, "0"); |
676 for(; members; members = members->next) { | |
677 if (!strcmp(members->data, dn)) | |
678 continue; | |
679 yahoo_packet_hash(pkt, 52, (char *)members->data); | |
680 yahoo_packet_hash(pkt, 53, (char *)members->data); | |
681 } | |
682 yahoo_send_packet(yd, pkt); | |
683 | |
684 yahoo_packet_free(pkt); | |
7827 | 685 if (msg) |
686 g_free(msg2); | |
6729 | 687 } |
688 | |
689 /* | |
690 * Functions dealing with chats | |
691 */ | |
692 | |
7186 | 693 static void yahoo_chat_leave(GaimConnection *gc, const char *room, const char *dn, gboolean logout) |
6729 | 694 { |
7186 | 695 struct yahoo_data *yd = gc->proto_data; |
6729 | 696 struct yahoo_packet *pkt; |
7186 | 697 GaimConversation *c; |
7827 | 698 char *eroom; |
699 | |
700 eroom = yahoo_string_encode(gc, room, NULL); | |
6729 | 701 |
702 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATEXIT, YAHOO_STATUS_AVAILABLE, 0); | |
703 | |
7827 | 704 yahoo_packet_hash(pkt, 104, eroom); |
6729 | 705 yahoo_packet_hash(pkt, 109, dn); |
706 yahoo_packet_hash(pkt, 108, "1"); | |
707 yahoo_packet_hash(pkt, 112, "0"); /* what does this one mean? */ | |
708 | |
709 yahoo_send_packet(yd, pkt); | |
710 | |
711 yahoo_packet_free(pkt); | |
712 | |
713 yd->in_chat = 0; | |
714 if (yd->chat_name) { | |
715 g_free(yd->chat_name); | |
716 yd->chat_name = NULL; | |
717 } | |
718 | |
7186 | 719 if ((c = gaim_find_chat(gc, YAHOO_CHAT_ID))) |
720 serv_got_chat_left(gc, YAHOO_CHAT_ID); | |
721 | |
722 if (!logout) | |
723 return; | |
724 | |
725 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATLOGOUT, | |
726 YAHOO_STATUS_AVAILABLE, 0); | |
727 yahoo_packet_hash(pkt, 1, dn); | |
728 yahoo_send_packet(yd, pkt); | |
729 yahoo_packet_free(pkt); | |
730 | |
731 yd->chat_online = 0; | |
7827 | 732 g_free(eroom); |
6729 | 733 } |
734 | |
6804 | 735 /* borrowed from gtkconv.c */ |
736 static gboolean | |
737 meify(char *message, size_t len) | |
738 { | |
739 /* | |
740 * Read /me-ify: If the message (post-HTML) starts with /me, | |
741 * remove the "/me " part of it (including that space) and return TRUE. | |
742 */ | |
743 char *c; | |
744 gboolean inside_html = 0; | |
745 | |
746 /* Umm.. this would be very bad if this happens. */ | |
747 g_return_val_if_fail(message != NULL, FALSE); | |
748 | |
749 if (len == -1) | |
750 len = strlen(message); | |
751 | |
752 for (c = message; *c != '\0'; c++, len--) { | |
753 if (inside_html) { | |
754 if (*c == '>') | |
755 inside_html = FALSE; | |
756 } | |
757 else { | |
758 if (*c == '<') | |
759 inside_html = TRUE; | |
760 else | |
761 break; | |
762 } | |
763 } | |
764 | |
765 if (*c != '\0' && !g_ascii_strncasecmp(c, "/me ", 4)) { | |
766 memmove(c, c + 4, len - 3); | |
767 | |
768 return TRUE; | |
769 } | |
770 | |
771 return FALSE; | |
772 } | |
773 | |
7827 | 774 static int yahoo_chat_send(GaimConnection *gc, const char *dn, const char *room, const char *what) |
6729 | 775 { |
7827 | 776 struct yahoo_data *yd = gc->proto_data; |
6729 | 777 struct yahoo_packet *pkt; |
778 int me = 0; | |
7827 | 779 char *msg1, *msg2, *room2; |
780 gboolean utf8 = TRUE; | |
6804 | 781 |
782 msg1 = g_strdup(what); | |
6729 | 783 |
6804 | 784 if (meify(msg1, -1)) |
6729 | 785 me = 1; |
6804 | 786 |
787 msg2 = yahoo_html_to_codes(msg1); | |
788 g_free(msg1); | |
7827 | 789 msg1 = yahoo_string_encode(gc, msg2, &utf8); |
790 g_free(msg2); | |
791 room2 = yahoo_string_encode(gc, room, NULL); | |
6729 | 792 |
793 pkt = yahoo_packet_new(YAHOO_SERVICE_COMMENT, YAHOO_STATUS_AVAILABLE, 0); | |
794 | |
795 yahoo_packet_hash(pkt, 1, dn); | |
7827 | 796 yahoo_packet_hash(pkt, 104, room2); |
797 yahoo_packet_hash(pkt, 117, msg1); | |
6729 | 798 if (me) |
799 yahoo_packet_hash(pkt, 124, "2"); | |
800 else | |
801 yahoo_packet_hash(pkt, 124, "1"); | |
802 /* fixme: what about /think? (124=3) */ | |
7827 | 803 if (utf8) |
804 yahoo_packet_hash(pkt, 97, "1"); | |
6729 | 805 |
806 yahoo_send_packet(yd, pkt); | |
807 yahoo_packet_free(pkt); | |
7827 | 808 g_free(msg1); |
809 g_free(room2); | |
6729 | 810 |
811 return 0; | |
812 } | |
813 | |
7827 | 814 static void yahoo_chat_join(GaimConnection *gc, const char *dn, const char *room, const char *topic) |
6729 | 815 { |
7827 | 816 struct yahoo_data *yd = gc->proto_data; |
6729 | 817 struct yahoo_packet *pkt; |
7827 | 818 char *room2; |
819 | |
820 room2 = yahoo_string_encode(gc, room, NULL); | |
6729 | 821 |
822 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YAHOO_STATUS_AVAILABLE, 0); | |
823 | |
7868 | 824 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
6729 | 825 yahoo_packet_hash(pkt, 62, "2"); |
7827 | 826 yahoo_packet_hash(pkt, 104, room2); |
6729 | 827 yahoo_packet_hash(pkt, 129, "0"); |
828 | |
829 yahoo_send_packet(yd, pkt); | |
830 | |
831 yahoo_packet_free(pkt); | |
7827 | 832 g_free(room2); |
6729 | 833 } |
834 | |
7827 | 835 static void yahoo_chat_invite(GaimConnection *gc, const char *dn, const char *buddy, |
6729 | 836 const char *room, const char *msg) |
837 { | |
7827 | 838 struct yahoo_data *yd = gc->proto_data; |
6729 | 839 struct yahoo_packet *pkt; |
7827 | 840 char *room2, *msg2 = NULL; |
6729 | 841 |
7827 | 842 room2 = yahoo_string_encode(gc, room, NULL); |
843 if (msg) | |
844 msg2 = yahoo_string_encode(gc, msg, NULL); | |
6729 | 845 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATADDINVITE, YAHOO_STATUS_AVAILABLE, 0); |
846 | |
847 yahoo_packet_hash(pkt, 1, dn); | |
848 yahoo_packet_hash(pkt, 118, buddy); | |
7827 | 849 yahoo_packet_hash(pkt, 104, room2); |
850 yahoo_packet_hash(pkt, 117, (msg2?msg2:"")); | |
6729 | 851 yahoo_packet_hash(pkt, 129, "0"); |
852 | |
853 yahoo_send_packet(yd, pkt); | |
854 yahoo_packet_free(pkt); | |
7827 | 855 |
856 g_free(room2); | |
857 if (msg2) | |
858 g_free(msg2); | |
6729 | 859 } |
860 | |
861 void yahoo_chat_goto(GaimConnection *gc, const char *name) | |
862 { | |
863 struct yahoo_data *yd; | |
864 struct yahoo_packet *pkt; | |
865 | |
866 yd = gc->proto_data; | |
867 | |
868 if (!yd->chat_online) | |
869 yahoo_chat_online(gc); | |
870 | |
871 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATGOTO, YAHOO_STATUS_AVAILABLE, 0); | |
872 | |
873 yahoo_packet_hash(pkt, 109, name); | |
874 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
875 yahoo_packet_hash(pkt, 62, "2"); | |
876 | |
877 yahoo_send_packet(yd, pkt); | |
878 yahoo_packet_free(pkt); | |
879 } | |
880 /* | |
881 * These are the functions registered with the core | |
882 * which get called for both chats and conferences. | |
883 */ | |
884 | |
885 void yahoo_c_leave(GaimConnection *gc, int id) | |
886 { | |
887 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
888 GaimConversation *c; | |
889 | |
890 if (!yd) | |
891 return; | |
892 | |
893 | |
894 c = gaim_find_chat(gc, id); | |
895 if (!c) | |
896 return; | |
897 | |
898 if (id != YAHOO_CHAT_ID) { | |
899 yahoo_conf_leave(yd, gaim_conversation_get_name(c), | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
900 gaim_connection_get_display_name(gc), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c))); |
6729 | 901 yd->confs = g_slist_remove(yd->confs, c); |
902 } else { | |
7186 | 903 yahoo_chat_leave(gc, gaim_conversation_get_name(c), gaim_connection_get_display_name(gc), TRUE); |
6729 | 904 } |
905 | |
906 serv_got_chat_left(gc, id); | |
907 } | |
908 | |
909 int yahoo_c_send(GaimConnection *gc, int id, const char *what) | |
910 { | |
911 GaimConversation *c; | |
912 int ret; | |
913 struct yahoo_data *yd; | |
914 | |
915 yd = (struct yahoo_data *) gc->proto_data; | |
916 if (!yd) | |
917 return -1; | |
918 | |
919 c = gaim_find_chat(gc, id); | |
920 if (!c) | |
921 return -1; | |
922 | |
923 if (id != YAHOO_CHAT_ID) { | |
7827 | 924 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
|
925 gaim_conversation_get_name(c), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)), what); |
6729 | 926 } else { |
7827 | 927 ret = yahoo_chat_send(gc, gaim_connection_get_display_name(gc), |
6804 | 928 gaim_conversation_get_name(c), what); |
6729 | 929 if (!ret) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
930 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), |
6729 | 931 gaim_connection_get_display_name(gc), 0, what, time(NULL)); |
932 } | |
933 return ret; | |
934 } | |
935 | |
936 GList *yahoo_c_info(GaimConnection *gc) | |
937 { | |
938 GList *m = NULL; | |
939 struct proto_chat_entry *pce; | |
940 | |
941 pce = g_new0(struct proto_chat_entry, 1); | |
7841 | 942 pce->label = _("_Room:"); |
6729 | 943 pce->identifier = "room"; |
944 m = g_list_append(m, pce); | |
945 | |
946 return m; | |
947 } | |
948 | |
949 void yahoo_c_join(GaimConnection *gc, GHashTable *data) | |
950 { | |
951 struct yahoo_data *yd; | |
952 char *room, *topic, *members, *type; | |
953 int id; | |
954 GaimConversation *c; | |
955 | |
956 yd = (struct yahoo_data *) gc->proto_data; | |
957 if (!yd) | |
958 return; | |
959 | |
960 room = g_hash_table_lookup(data, "room"); | |
961 if (!room) | |
962 return; | |
963 | |
964 topic = g_hash_table_lookup(data, "topic"); | |
965 if (!topic) | |
966 topic = ""; | |
967 | |
968 members = g_hash_table_lookup(data, "members"); | |
969 | |
970 | |
971 if ((type = g_hash_table_lookup(data, "type")) && !strcmp(type, "Conference")) { | |
972 id = yd->conf_id++; | |
973 c = serv_got_joined_chat(gc, id, room); | |
974 yd->confs = g_slist_prepend(yd->confs, c); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
975 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), gaim_connection_get_display_name(gc), topic); |
6729 | 976 yahoo_conf_join(yd, c, gaim_connection_get_display_name(gc), room, topic, members); |
977 return; | |
978 } else { | |
979 if (yd->in_chat) | |
7186 | 980 yahoo_chat_leave(gc, room, |
981 gaim_connection_get_display_name(gc), | |
982 FALSE); | |
6729 | 983 if (!yd->chat_online) |
984 yahoo_chat_online(gc); | |
7827 | 985 yahoo_chat_join(gc, gaim_connection_get_display_name(gc), room, topic); |
6729 | 986 return; |
987 } | |
988 } | |
989 | |
990 void yahoo_c_invite(GaimConnection *gc, int id, const char *msg, const char *name) | |
991 { | |
992 GaimConversation *c; | |
993 | |
994 c = gaim_find_chat(gc, id); | |
995 if (!c || !c->name) | |
996 return; | |
997 | |
998 if (id != YAHOO_CHAT_ID) { | |
7827 | 999 yahoo_conf_invite(gc, c, gaim_connection_get_display_name(gc), name, |
6729 | 1000 gaim_conversation_get_name(c), msg); |
1001 } else { | |
7827 | 1002 yahoo_chat_invite(gc, gaim_connection_get_display_name(gc), name, |
6729 | 1003 gaim_conversation_get_name(c), msg); |
1004 } | |
1005 } | |
1006 | |
8113 | 1007 |
1008 struct yahoo_roomlist { | |
1009 int fd; | |
1010 int inpa; | |
1011 guchar *rxqueue; | |
1012 int rxlen; | |
1013 gboolean started; | |
1014 char *path; | |
1015 char *host; | |
1016 GaimRoomlist *list; | |
1017 GaimRoomlistRoom *cat; | |
1018 GaimRoomlistRoom *ucat; | |
1019 GMarkupParseContext *parse; | |
1020 | |
1021 }; | |
1022 | |
1023 static void yahoo_roomlist_destroy(struct yahoo_roomlist *yrl) | |
1024 { | |
1025 if (yrl->inpa) | |
1026 gaim_input_remove(yrl->inpa); | |
1027 if (yrl->rxqueue) | |
1028 g_free(yrl->rxqueue); | |
1029 if (yrl->path) | |
1030 g_free(yrl->path); | |
1031 if (yrl->host) | |
1032 g_free(yrl->host); | |
1033 if (yrl->parse) | |
1034 g_markup_parse_context_free(yrl->parse); | |
1035 } | |
1036 | |
1037 enum yahoo_room_type { | |
1038 yrt_yahoo, | |
1039 yrt_user, | |
1040 }; | |
1041 | |
1042 struct yahoo_chatxml_state { | |
1043 GaimRoomlist *list; | |
1044 struct yahoo_roomlist *yrl; | |
1045 GQueue *q; | |
1046 struct { | |
1047 enum yahoo_room_type type; | |
1048 char *name; | |
1049 char *topic; | |
1050 char *id; | |
1051 int users, voices, webcams; | |
1052 } room; | |
1053 }; | |
1054 | |
1055 struct yahoo_lobby { | |
1056 int count, users, voices, webcams; | |
1057 }; | |
1058 | |
1059 static struct yahoo_chatxml_state *yahoo_chatxml_state_new(GaimRoomlist *list, struct yahoo_roomlist *yrl) | |
1060 { | |
1061 struct yahoo_chatxml_state *s; | |
1062 | |
1063 s = g_new0(struct yahoo_chatxml_state, 1); | |
1064 | |
1065 s->list = list; | |
1066 s->yrl = yrl; | |
1067 s->q = g_queue_new(); | |
1068 | |
1069 return s; | |
1070 } | |
1071 | |
1072 static void yahoo_chatxml_state_destroy(struct yahoo_chatxml_state *s) | |
1073 { | |
1074 g_queue_free(s->q); | |
1075 if (s->room.name) | |
1076 g_free(s->room.name); | |
1077 if (s->room.topic) | |
1078 g_free(s->room.topic); | |
1079 if (s->room.id) | |
1080 g_free(s->room.id); | |
1081 g_free(s); | |
1082 } | |
1083 | |
1084 static void yahoo_chatlist_start_element(GMarkupParseContext *context, const gchar *ename, | |
1085 const gchar **anames, const gchar **avalues, | |
1086 gpointer user_data, GError **error) | |
1087 { | |
1088 struct yahoo_chatxml_state *s = user_data; | |
1089 GaimRoomlist *list = s->list; | |
1090 GaimRoomlistRoom *r; | |
1091 GaimRoomlistRoom *parent; | |
1092 int i; | |
1093 | |
1094 if (!strcmp(ename, "category")) { | |
1095 const gchar *name = NULL, *id = NULL; | |
1096 | |
1097 for (i = 0; anames[i]; i++) { | |
1098 if (!strcmp(anames[i], "id")) | |
1099 id = avalues[i]; | |
1100 if (!strcmp(anames[i], "name")) | |
1101 name = avalues[i]; | |
1102 } | |
1103 if (!name || !id) | |
1104 return; | |
1105 | |
1106 parent = g_queue_peek_head(s->q); | |
1107 r = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATAGORY, name, parent); | |
1108 gaim_roomlist_room_add_field(list, r, (gpointer)name); | |
1109 gaim_roomlist_room_add_field(list, r, (gpointer)id); | |
1110 gaim_roomlist_room_add(list, r); | |
1111 g_queue_push_head(s->q, r); | |
1112 } else if (!strcmp(ename, "room")) { | |
1113 s->room.users = s->room.voices = s->room.webcams = 0; | |
1114 | |
1115 for (i = 0; anames[i]; i++) { | |
1116 if (!strcmp(anames[i], "id")) { | |
1117 if (s->room.id) | |
1118 g_free(s->room.id); | |
1119 s->room.id = g_strdup(avalues[i]); | |
1120 } else if (!strcmp(anames[i], "name")) { | |
1121 if (s->room.name) | |
1122 g_free(s->room.name); | |
1123 s->room.name = g_strdup(avalues[i]); | |
1124 } else if (!strcmp(anames[i], "topic")) { | |
1125 if (s->room.topic) | |
1126 g_free(s->room.topic); | |
1127 s->room.topic = g_strdup(avalues[i]); | |
1128 } else if (!strcmp(anames[i], "type")) { | |
1129 if (!strcmp("yahoo", avalues[i])) | |
1130 s->room.type = yrt_yahoo; | |
1131 else | |
1132 s->room.type = yrt_user; | |
1133 } | |
1134 } | |
1135 | |
1136 } else if (!strcmp(ename, "lobby")) { | |
1137 struct yahoo_lobby *lob = g_new0(struct yahoo_lobby, 1); | |
1138 | |
1139 for (i = 0; anames[i]; i++) { | |
1140 if (!strcmp(anames[i], "count")) { | |
1141 lob->count = strtol(avalues[i], NULL, 10); | |
1142 } else if (!strcmp(anames[i], "users")) { | |
1143 s->room.users += lob->users = strtol(avalues[i], NULL, 10); | |
1144 } else if (!strcmp(anames[i], "voices")) { | |
1145 s->room.voices += lob->voices = strtol(avalues[i], NULL, 10); | |
1146 } else if (!strcmp(anames[i], "webcams")) { | |
1147 s->room.webcams += lob->webcams = strtol(avalues[i], NULL, 10); | |
1148 } | |
1149 } | |
1150 | |
1151 g_queue_push_head(s->q, lob); | |
1152 } | |
1153 | |
1154 } | |
1155 | |
1156 static void yahoo_chatlist_end_element(GMarkupParseContext *context, const gchar *ename, | |
1157 gpointer user_data, GError **error) | |
1158 { | |
1159 struct yahoo_chatxml_state *s = user_data; | |
1160 | |
1161 if (!strcmp(ename, "category")) { | |
1162 g_queue_pop_head(s->q); | |
1163 } else if (!strcmp(ename, "room")) { | |
1164 struct yahoo_lobby *lob; | |
1165 GaimRoomlistRoom *r, *l; | |
1166 | |
1167 if (s->room.type == yrt_yahoo) | |
1168 r = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATAGORY|GAIM_ROOMLIST_ROOMTYPE_ROOM, | |
1169 s->room.name, s->yrl->cat); | |
1170 else | |
1171 r = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATAGORY|GAIM_ROOMLIST_ROOMTYPE_ROOM, | |
1172 s->room.name, s->yrl->ucat); | |
1173 | |
1174 gaim_roomlist_room_add_field(s->list, r, s->room.name); | |
1175 gaim_roomlist_room_add_field(s->list, r, s->room.id); | |
1176 gaim_roomlist_room_add_field(s->list, r, GINT_TO_POINTER(s->room.users)); | |
1177 gaim_roomlist_room_add_field(s->list, r, GINT_TO_POINTER(s->room.voices)); | |
1178 gaim_roomlist_room_add_field(s->list, r, GINT_TO_POINTER(s->room.webcams)); | |
1179 gaim_roomlist_room_add_field(s->list, r, s->room.topic); | |
1180 gaim_roomlist_room_add(s->list, r); | |
1181 | |
1182 while ((lob = g_queue_pop_head(s->q))) { | |
1183 char *name = g_strdup_printf("%s:%d", s->room.name, lob->count); | |
1184 l = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, name, r); | |
1185 | |
1186 gaim_roomlist_room_add_field(s->list, l, name); | |
1187 gaim_roomlist_room_add_field(s->list, l, s->room.id); | |
1188 gaim_roomlist_room_add_field(s->list, l, GINT_TO_POINTER(lob->users)); | |
1189 gaim_roomlist_room_add_field(s->list, l, GINT_TO_POINTER(lob->voices)); | |
1190 gaim_roomlist_room_add_field(s->list, l, GINT_TO_POINTER(lob->webcams)); | |
1191 gaim_roomlist_room_add_field(s->list, l, s->room.topic); | |
1192 gaim_roomlist_room_add(s->list, l); | |
1193 | |
1194 g_free(name); | |
1195 g_free(lob); | |
1196 } | |
1197 | |
1198 } | |
1199 | |
1200 } | |
1201 | |
1202 static GMarkupParser parser = { | |
1203 yahoo_chatlist_start_element, | |
1204 yahoo_chatlist_end_element, | |
1205 NULL, | |
1206 NULL, | |
1207 NULL | |
1208 }; | |
1209 | |
1210 static void yahoo_roomlist_cleanup(GaimRoomlist *list, struct yahoo_roomlist *yrl) | |
1211 { | |
1212 gaim_roomlist_set_in_progress(list, FALSE); | |
1213 | |
1214 if (yrl) { | |
1215 list->proto_data = g_list_remove(list->proto_data, yrl); | |
1216 yahoo_roomlist_destroy(yrl); | |
1217 } | |
1218 | |
1219 gaim_roomlist_unref(list); | |
1220 } | |
1221 | |
1222 static void yahoo_roomlist_pending(gpointer data, gint source, GaimInputCondition cond) | |
1223 { | |
1224 struct yahoo_roomlist *yrl = data; | |
1225 GaimRoomlist *list = yrl->list; | |
1226 char buf[1024]; | |
1227 int len; | |
1228 guchar *start; | |
1229 struct yahoo_chatxml_state *s; | |
1230 | |
1231 len = read(yrl->fd, buf, sizeof(buf)); | |
1232 | |
1233 if (len <= 0) { | |
1234 if (yrl->parse) | |
1235 g_markup_parse_context_end_parse(yrl->parse, NULL); | |
1236 yahoo_roomlist_cleanup(list, yrl); | |
1237 return; | |
1238 } | |
1239 | |
1240 | |
1241 yrl->rxqueue = g_realloc(yrl->rxqueue, len + yrl->rxlen); | |
1242 memcpy(yrl->rxqueue + yrl->rxlen, buf, len); | |
1243 yrl->rxlen += len; | |
1244 | |
1245 if (!yrl->started) { | |
1246 yrl->started = TRUE; | |
1247 start = g_strstr_len(yrl->rxqueue, yrl->rxlen, "\r\n\r\n"); | |
1248 if (!start || (start - yrl->rxqueue + 4) >= yrl->rxlen) | |
1249 return; | |
1250 start += 4; | |
1251 } else { | |
1252 start = yrl->rxqueue; | |
1253 } | |
1254 | |
1255 if (yrl->parse == NULL) { | |
1256 s = yahoo_chatxml_state_new(list, yrl); | |
1257 yrl->parse = g_markup_parse_context_new(&parser, 0, s, | |
1258 (GDestroyNotify)yahoo_chatxml_state_destroy); | |
1259 } | |
1260 | |
1261 if (!g_markup_parse_context_parse(yrl->parse, start, (yrl->rxlen - (start - yrl->rxqueue)), NULL)) { | |
1262 | |
1263 yahoo_roomlist_cleanup(list, yrl); | |
1264 return; | |
1265 } | |
1266 | |
1267 yrl->rxlen = 0; | |
1268 } | |
1269 | |
1270 static void yahoo_roomlist_got_connected(gpointer data, gint source, GaimInputCondition cond) | |
1271 { | |
1272 struct yahoo_roomlist *yrl = data; | |
1273 GaimRoomlist *list = yrl->list; | |
1274 char *buf, *cookie; | |
1275 struct yahoo_data *yd = gaim_account_get_connection(list->account)->proto_data; | |
1276 | |
1277 if (source < 0) { | |
1278 gaim_notify_error(gaim_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed.")); | |
1279 yahoo_roomlist_cleanup(list, yrl); | |
1280 return; | |
1281 } | |
1282 | |
1283 yrl->fd = source; | |
1284 | |
1285 cookie = g_strdup_printf("Y=%s; T=%s", yd->cookie_y, yd->cookie_t); | |
1286 buf = g_strdup_printf("GET /%s HTTP/1.0\r\nHost: %s\r\nCookie: %s\r\n\r\n", yrl->path, yrl->host, cookie); | |
1287 write(yrl->fd, buf, strlen(buf)); | |
1288 g_free(cookie); | |
1289 g_free(buf); | |
1290 yrl->inpa = gaim_input_add(yrl->fd, GAIM_INPUT_READ, yahoo_roomlist_pending, yrl); | |
1291 | |
1292 } | |
1293 | |
1294 GaimRoomlist *yahoo_roomlist_get_list(GaimConnection *gc) | |
1295 { | |
1296 struct yahoo_roomlist *yrl; | |
1297 GaimRoomlist *rl; | |
1298 char *url; | |
1299 GList *fields = NULL; | |
1300 GaimRoomlistField *f; | |
1301 | |
1302 url = g_strdup_printf("%s?chatcat=0", | |
1303 gaim_account_get_string( | |
1304 gaim_connection_get_account(gc), | |
1305 "room_list", YAHOO_ROOMLIST_URL)); | |
1306 | |
1307 yrl = g_new0(struct yahoo_roomlist, 1); | |
1308 rl = gaim_roomlist_new(gaim_connection_get_account(gc)); | |
1309 yrl->list = rl; | |
1310 | |
1311 gaim_url_parse(url, &(yrl->host), NULL, &(yrl->path)); | |
1312 g_free(url); | |
1313 | |
1314 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "room", TRUE); | |
1315 fields = g_list_append(fields, f); | |
1316 | |
1317 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "id", TRUE); | |
1318 fields = g_list_append(fields, f); | |
1319 | |
1320 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Users"), "users", FALSE); | |
1321 fields = g_list_append(fields, f); | |
1322 | |
1323 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Voices"), "voices", FALSE); | |
1324 fields = g_list_append(fields, f); | |
1325 | |
1326 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Webcams"), "webcams", FALSE); | |
1327 fields = g_list_append(fields, f); | |
1328 | |
1329 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Topic"), "topic", FALSE); | |
1330 fields = g_list_append(fields, f); | |
1331 | |
1332 gaim_roomlist_set_fields(rl, fields); | |
1333 | |
1334 if (gaim_proxy_connect(gaim_connection_get_account(gc), | |
1335 yrl->host, 80, yahoo_roomlist_got_connected, yrl) != 0) | |
1336 { | |
1337 gaim_notify_error(gc, NULL, _("Connection problem"), _("Unable to fetch room list.")); | |
1338 yahoo_roomlist_cleanup(rl, yrl); | |
1339 return NULL; | |
1340 } | |
1341 | |
1342 rl->proto_data = g_list_append(rl->proto_data, yrl); | |
1343 | |
1344 gaim_roomlist_set_in_progress(rl, TRUE); | |
1345 return rl; | |
1346 } | |
1347 | |
1348 void yahoo_roomlist_cancel(GaimRoomlist *list) | |
1349 { | |
1350 GList *l, *k; | |
1351 | |
1352 k = l = list->proto_data; | |
1353 list->proto_data = NULL; | |
1354 | |
1355 gaim_roomlist_set_in_progress(list, FALSE); | |
1356 | |
1357 for (; l; l = l->next) { | |
1358 yahoo_roomlist_destroy(l->data); | |
1359 gaim_roomlist_unref(l->data); | |
1360 } | |
1361 g_list_free(k); | |
1362 } | |
1363 | |
1364 void yahoo_roomlist_expand_catagory(GaimRoomlist *list, GaimRoomlistRoom *catagory) | |
1365 { | |
1366 struct yahoo_roomlist *yrl; | |
1367 char *url; | |
1368 char *id; | |
1369 | |
1370 if (catagory->type != GAIM_ROOMLIST_ROOMTYPE_CATAGORY) | |
1371 return; | |
1372 | |
1373 if (!(id = g_list_nth_data(catagory->fields, 1))) { | |
1374 gaim_roomlist_set_in_progress(list, FALSE); | |
1375 return; | |
1376 } | |
1377 | |
1378 url = g_strdup_printf("%s?chatroom_%s=0", | |
1379 gaim_account_get_string( | |
1380 list->account, | |
1381 "room_list", YAHOO_ROOMLIST_URL), id); | |
1382 | |
1383 yrl = g_new0(struct yahoo_roomlist, 1); | |
1384 yrl->list = list; | |
1385 yrl->cat = catagory; | |
1386 list->proto_data = g_list_append(list->proto_data, yrl); | |
1387 | |
1388 gaim_url_parse(url, &(yrl->host), NULL, &(yrl->path)); | |
1389 g_free(url); | |
1390 | |
1391 yrl->ucat = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATAGORY, _("User Rooms"), yrl->cat); | |
1392 gaim_roomlist_room_add(list, yrl->ucat); | |
1393 | |
1394 if (gaim_proxy_connect(list->account, | |
1395 yrl->host, 80, yahoo_roomlist_got_connected, yrl) != 0) | |
1396 { | |
1397 gaim_notify_error(gaim_account_get_connection(list->account), | |
1398 NULL, _("Connection problem"), _("Unable to fetch room list.")); | |
1399 yahoo_roomlist_cleanup(list, yrl); | |
1400 return; | |
1401 } | |
1402 | |
1403 gaim_roomlist_set_in_progress(list, TRUE); | |
1404 gaim_roomlist_ref(list); | |
1405 } | |
1406 |