Wed, 21 Apr 2004 01:34:26 +0000
[gaim-migrate @ 9490]
Patch by Jonathan Champ to corect the vairous speling mistakes we hav e in
the coments and documentaion. Thansk Jonathan!
committer: Christian Hammond <chipx86@chipx86.com>
| 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
280b3b85a28a
[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
280b3b85a28a
[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
280b3b85a28a
[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
280b3b85a28a
[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
280b3b85a28a
[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
280b3b85a28a
[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
280b3b85a28a
[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
280b3b85a28a
[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
280b3b85a28a
[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 | ||
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8584
diff
changeset
|
308 | /* this is a confirmation of yahoo_chat_online(); */ |
| 6729 | 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: | |
| 8410 | 360 | room = yahoo_string_decode(gc, pair->value, TRUE); |
| 6729 | 361 | break; |
| 362 | case 105: | |
| 8410 | 363 | topic = yahoo_string_decode(gc, pair->value, TRUE); |
| 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; | |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8584
diff
changeset
|
381 | case 61: /*this looks similar to 130 */ |
| 6729 | 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
280b3b85a28a
[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) |
| 8410 | 460 | room = yahoo_string_decode(gc, pair->value, TRUE); |
| 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
280b3b85a28a
[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; |
| 8410 | 479 | int msgtype = 1, utf8 = 1; /* default to utf8 */ |
| 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: |
| 8410 | 492 | room = yahoo_string_decode(gc, pair->value, TRUE); |
| 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: | |
| 8410 | 547 | room = yahoo_string_decode(gc, pair->value, TRUE); |
| 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
280b3b85a28a
[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
280b3b85a28a
[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; |
| 8410 | 717 | gboolean utf8 = 1; |
| 7827 | 718 | |
| 8410 | 719 | eroom = yahoo_string_encode(gc, room, &utf8); |
| 6729 | 720 | |
| 721 | pkt = yahoo_packet_new(YAHOO_SERVICE_CHATEXIT, YAHOO_STATUS_AVAILABLE, 0); | |
| 722 | ||
| 7827 | 723 | yahoo_packet_hash(pkt, 104, eroom); |
| 6729 | 724 | yahoo_packet_hash(pkt, 109, dn); |
| 725 | yahoo_packet_hash(pkt, 108, "1"); | |
| 726 | yahoo_packet_hash(pkt, 112, "0"); /* what does this one mean? */ | |
| 727 | ||
| 728 | yahoo_send_packet(yd, pkt); | |
| 729 | ||
| 730 | yahoo_packet_free(pkt); | |
| 731 | ||
| 732 | yd->in_chat = 0; | |
| 733 | if (yd->chat_name) { | |
| 734 | g_free(yd->chat_name); | |
| 735 | yd->chat_name = NULL; | |
| 736 | } | |
| 737 | ||
| 7186 | 738 | if ((c = gaim_find_chat(gc, YAHOO_CHAT_ID))) |
| 739 | serv_got_chat_left(gc, YAHOO_CHAT_ID); | |
| 740 | ||
| 741 | if (!logout) | |
| 742 | return; | |
| 743 | ||
| 744 | pkt = yahoo_packet_new(YAHOO_SERVICE_CHATLOGOUT, | |
| 745 | YAHOO_STATUS_AVAILABLE, 0); | |
| 746 | yahoo_packet_hash(pkt, 1, dn); | |
| 747 | yahoo_send_packet(yd, pkt); | |
| 748 | yahoo_packet_free(pkt); | |
| 749 | ||
| 750 | yd->chat_online = 0; | |
| 7827 | 751 | g_free(eroom); |
| 6729 | 752 | } |
| 753 | ||
| 6804 | 754 | /* borrowed from gtkconv.c */ |
| 755 | static gboolean | |
| 756 | meify(char *message, size_t len) | |
| 757 | { | |
| 758 | /* | |
| 759 | * Read /me-ify: If the message (post-HTML) starts with /me, | |
| 760 | * remove the "/me " part of it (including that space) and return TRUE. | |
| 761 | */ | |
| 762 | char *c; | |
| 763 | gboolean inside_html = 0; | |
| 764 | ||
| 765 | /* Umm.. this would be very bad if this happens. */ | |
| 766 | g_return_val_if_fail(message != NULL, FALSE); | |
| 767 | ||
| 768 | if (len == -1) | |
| 769 | len = strlen(message); | |
| 770 | ||
| 771 | for (c = message; *c != '\0'; c++, len--) { | |
| 772 | if (inside_html) { | |
| 773 | if (*c == '>') | |
| 774 | inside_html = FALSE; | |
| 775 | } | |
| 776 | else { | |
| 777 | if (*c == '<') | |
| 778 | inside_html = TRUE; | |
| 779 | else | |
| 780 | break; | |
| 781 | } | |
| 782 | } | |
| 783 | ||
| 784 | if (*c != '\0' && !g_ascii_strncasecmp(c, "/me ", 4)) { | |
| 785 | memmove(c, c + 4, len - 3); | |
| 786 | ||
| 787 | return TRUE; | |
| 788 | } | |
| 789 | ||
| 790 | return FALSE; | |
| 791 | } | |
| 792 | ||
| 7827 | 793 | static int yahoo_chat_send(GaimConnection *gc, const char *dn, const char *room, const char *what) |
| 6729 | 794 | { |
| 7827 | 795 | struct yahoo_data *yd = gc->proto_data; |
| 6729 | 796 | struct yahoo_packet *pkt; |
| 797 | int me = 0; | |
| 7827 | 798 | char *msg1, *msg2, *room2; |
| 799 | gboolean utf8 = TRUE; | |
| 6804 | 800 | |
| 801 | msg1 = g_strdup(what); | |
| 6729 | 802 | |
| 6804 | 803 | if (meify(msg1, -1)) |
| 6729 | 804 | me = 1; |
| 6804 | 805 | |
| 806 | msg2 = yahoo_html_to_codes(msg1); | |
| 807 | g_free(msg1); | |
| 7827 | 808 | msg1 = yahoo_string_encode(gc, msg2, &utf8); |
| 809 | g_free(msg2); | |
| 810 | room2 = yahoo_string_encode(gc, room, NULL); | |
| 6729 | 811 | |
| 812 | pkt = yahoo_packet_new(YAHOO_SERVICE_COMMENT, YAHOO_STATUS_AVAILABLE, 0); | |
| 813 | ||
| 814 | yahoo_packet_hash(pkt, 1, dn); | |
| 7827 | 815 | yahoo_packet_hash(pkt, 104, room2); |
| 816 | yahoo_packet_hash(pkt, 117, msg1); | |
| 6729 | 817 | if (me) |
| 818 | yahoo_packet_hash(pkt, 124, "2"); | |
| 819 | else | |
| 820 | yahoo_packet_hash(pkt, 124, "1"); | |
| 821 | /* fixme: what about /think? (124=3) */ | |
| 7827 | 822 | if (utf8) |
| 823 | yahoo_packet_hash(pkt, 97, "1"); | |
| 6729 | 824 | |
| 825 | yahoo_send_packet(yd, pkt); | |
| 826 | yahoo_packet_free(pkt); | |
| 7827 | 827 | g_free(msg1); |
| 828 | g_free(room2); | |
| 6729 | 829 | |
| 830 | return 0; | |
| 831 | } | |
| 832 | ||
| 7827 | 833 | static void yahoo_chat_join(GaimConnection *gc, const char *dn, const char *room, const char *topic) |
| 6729 | 834 | { |
| 7827 | 835 | struct yahoo_data *yd = gc->proto_data; |
| 6729 | 836 | struct yahoo_packet *pkt; |
| 7827 | 837 | char *room2; |
| 8410 | 838 | gboolean utf8 = TRUE; |
| 7827 | 839 | |
| 8410 | 840 | /* apparently room names are always utf8, or else always not utf8, |
| 841 | * so we don't have to actually pass the flag in the packet. Or something. */ | |
| 842 | room2 = yahoo_string_encode(gc, room, &utf8); | |
| 6729 | 843 | |
| 844 | pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YAHOO_STATUS_AVAILABLE, 0); | |
| 845 | ||
| 7868 | 846 | yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
| 6729 | 847 | yahoo_packet_hash(pkt, 62, "2"); |
| 7827 | 848 | yahoo_packet_hash(pkt, 104, room2); |
| 6729 | 849 | yahoo_packet_hash(pkt, 129, "0"); |
| 850 | ||
| 851 | yahoo_send_packet(yd, pkt); | |
| 852 | ||
| 853 | yahoo_packet_free(pkt); | |
| 7827 | 854 | g_free(room2); |
| 6729 | 855 | } |
| 856 | ||
| 7827 | 857 | static void yahoo_chat_invite(GaimConnection *gc, const char *dn, const char *buddy, |
| 6729 | 858 | const char *room, const char *msg) |
| 859 | { | |
| 7827 | 860 | struct yahoo_data *yd = gc->proto_data; |
| 6729 | 861 | struct yahoo_packet *pkt; |
| 7827 | 862 | char *room2, *msg2 = NULL; |
| 8410 | 863 | gboolean utf8 = TRUE; |
| 6729 | 864 | |
| 8410 | 865 | room2 = yahoo_string_encode(gc, room, &utf8); |
| 7827 | 866 | if (msg) |
| 867 | msg2 = yahoo_string_encode(gc, msg, NULL); | |
| 6729 | 868 | pkt = yahoo_packet_new(YAHOO_SERVICE_CHATADDINVITE, YAHOO_STATUS_AVAILABLE, 0); |
| 869 | ||
| 870 | yahoo_packet_hash(pkt, 1, dn); | |
| 871 | yahoo_packet_hash(pkt, 118, buddy); | |
| 7827 | 872 | yahoo_packet_hash(pkt, 104, room2); |
| 873 | yahoo_packet_hash(pkt, 117, (msg2?msg2:"")); | |
| 6729 | 874 | yahoo_packet_hash(pkt, 129, "0"); |
| 875 | ||
| 876 | yahoo_send_packet(yd, pkt); | |
| 877 | yahoo_packet_free(pkt); | |
| 7827 | 878 | |
| 879 | g_free(room2); | |
| 880 | if (msg2) | |
| 881 | g_free(msg2); | |
| 6729 | 882 | } |
| 883 | ||
| 884 | void yahoo_chat_goto(GaimConnection *gc, const char *name) | |
| 885 | { | |
| 886 | struct yahoo_data *yd; | |
| 887 | struct yahoo_packet *pkt; | |
| 888 | ||
| 889 | yd = gc->proto_data; | |
| 890 | ||
| 891 | if (!yd->chat_online) | |
| 892 | yahoo_chat_online(gc); | |
| 893 | ||
| 894 | pkt = yahoo_packet_new(YAHOO_SERVICE_CHATGOTO, YAHOO_STATUS_AVAILABLE, 0); | |
| 895 | ||
| 896 | yahoo_packet_hash(pkt, 109, name); | |
| 897 | yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
| 898 | yahoo_packet_hash(pkt, 62, "2"); | |
| 899 | ||
| 900 | yahoo_send_packet(yd, pkt); | |
| 901 | yahoo_packet_free(pkt); | |
| 902 | } | |
| 903 | /* | |
| 904 | * These are the functions registered with the core | |
| 905 | * which get called for both chats and conferences. | |
| 906 | */ | |
| 907 | ||
| 908 | void yahoo_c_leave(GaimConnection *gc, int id) | |
| 909 | { | |
| 910 | struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
| 911 | GaimConversation *c; | |
| 912 | ||
| 913 | if (!yd) | |
| 914 | return; | |
| 915 | ||
| 916 | ||
| 917 | c = gaim_find_chat(gc, id); | |
| 918 | if (!c) | |
| 919 | return; | |
| 920 | ||
| 921 | if (id != YAHOO_CHAT_ID) { | |
| 922 | yahoo_conf_leave(yd, gaim_conversation_get_name(c), | |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
923 | gaim_connection_get_display_name(gc), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c))); |
| 6729 | 924 | yd->confs = g_slist_remove(yd->confs, c); |
| 925 | } else { | |
| 7186 | 926 | yahoo_chat_leave(gc, gaim_conversation_get_name(c), gaim_connection_get_display_name(gc), TRUE); |
| 6729 | 927 | } |
| 928 | ||
| 929 | serv_got_chat_left(gc, id); | |
| 930 | } | |
| 931 | ||
| 932 | int yahoo_c_send(GaimConnection *gc, int id, const char *what) | |
| 933 | { | |
| 934 | GaimConversation *c; | |
| 935 | int ret; | |
| 936 | struct yahoo_data *yd; | |
| 937 | ||
| 938 | yd = (struct yahoo_data *) gc->proto_data; | |
| 939 | if (!yd) | |
| 940 | return -1; | |
| 941 | ||
| 942 | c = gaim_find_chat(gc, id); | |
| 943 | if (!c) | |
| 944 | return -1; | |
| 945 | ||
| 946 | if (id != YAHOO_CHAT_ID) { | |
| 7827 | 947 | ret = yahoo_conf_send(gc, gaim_connection_get_display_name(gc), |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
948 | gaim_conversation_get_name(c), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)), what); |
| 6729 | 949 | } else { |
| 7827 | 950 | ret = yahoo_chat_send(gc, gaim_connection_get_display_name(gc), |
| 6804 | 951 | gaim_conversation_get_name(c), what); |
| 6729 | 952 | if (!ret) |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
953 | serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), |
| 6729 | 954 | gaim_connection_get_display_name(gc), 0, what, time(NULL)); |
| 955 | } | |
| 956 | return ret; | |
| 957 | } | |
| 958 | ||
| 959 | GList *yahoo_c_info(GaimConnection *gc) | |
| 960 | { | |
| 961 | GList *m = NULL; | |
| 962 | struct proto_chat_entry *pce; | |
| 963 | ||
| 964 | pce = g_new0(struct proto_chat_entry, 1); | |
|
7841
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7827
diff
changeset
|
965 | pce->label = _("_Room:"); |
| 6729 | 966 | pce->identifier = "room"; |
| 967 | m = g_list_append(m, pce); | |
| 968 | ||
| 969 | return m; | |
| 970 | } | |
| 971 | ||
| 972 | void yahoo_c_join(GaimConnection *gc, GHashTable *data) | |
| 973 | { | |
| 974 | struct yahoo_data *yd; | |
| 975 | char *room, *topic, *members, *type; | |
| 976 | int id; | |
| 977 | GaimConversation *c; | |
| 978 | ||
| 979 | yd = (struct yahoo_data *) gc->proto_data; | |
| 980 | if (!yd) | |
| 981 | return; | |
| 982 | ||
| 983 | room = g_hash_table_lookup(data, "room"); | |
| 984 | if (!room) | |
| 985 | return; | |
| 986 | ||
| 987 | topic = g_hash_table_lookup(data, "topic"); | |
| 988 | if (!topic) | |
| 989 | topic = ""; | |
| 990 | ||
| 991 | members = g_hash_table_lookup(data, "members"); | |
| 992 | ||
| 993 | ||
| 994 | if ((type = g_hash_table_lookup(data, "type")) && !strcmp(type, "Conference")) { | |
| 995 | id = yd->conf_id++; | |
| 996 | c = serv_got_joined_chat(gc, id, room); | |
| 997 | yd->confs = g_slist_prepend(yd->confs, c); | |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
998 | gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), gaim_connection_get_display_name(gc), topic); |
| 6729 | 999 | yahoo_conf_join(yd, c, gaim_connection_get_display_name(gc), room, topic, members); |
| 1000 | return; | |
| 1001 | } else { | |
| 1002 | if (yd->in_chat) | |
| 7186 | 1003 | yahoo_chat_leave(gc, room, |
| 1004 | gaim_connection_get_display_name(gc), | |
| 1005 | FALSE); | |
| 6729 | 1006 | if (!yd->chat_online) |
| 1007 | yahoo_chat_online(gc); | |
| 7827 | 1008 | yahoo_chat_join(gc, gaim_connection_get_display_name(gc), room, topic); |
| 6729 | 1009 | return; |
| 1010 | } | |
| 1011 | } | |
| 1012 | ||
| 1013 | void yahoo_c_invite(GaimConnection *gc, int id, const char *msg, const char *name) | |
| 1014 | { | |
| 1015 | GaimConversation *c; | |
| 1016 | ||
| 1017 | c = gaim_find_chat(gc, id); | |
| 1018 | if (!c || !c->name) | |
| 1019 | return; | |
| 1020 | ||
| 1021 | if (id != YAHOO_CHAT_ID) { | |
| 7827 | 1022 | yahoo_conf_invite(gc, c, gaim_connection_get_display_name(gc), name, |
| 6729 | 1023 | gaim_conversation_get_name(c), msg); |
| 1024 | } else { | |
| 7827 | 1025 | yahoo_chat_invite(gc, gaim_connection_get_display_name(gc), name, |
| 6729 | 1026 | gaim_conversation_get_name(c), msg); |
| 1027 | } | |
| 1028 | } | |
| 1029 | ||
| 8113 | 1030 | |
| 1031 | struct yahoo_roomlist { | |
| 1032 | int fd; | |
| 1033 | int inpa; | |
| 1034 | guchar *rxqueue; | |
| 1035 | int rxlen; | |
| 1036 | gboolean started; | |
| 1037 | char *path; | |
| 1038 | char *host; | |
| 1039 | GaimRoomlist *list; | |
| 1040 | GaimRoomlistRoom *cat; | |
| 1041 | GaimRoomlistRoom *ucat; | |
| 1042 | GMarkupParseContext *parse; | |
| 1043 | ||
| 1044 | }; | |
| 1045 | ||
| 1046 | static void yahoo_roomlist_destroy(struct yahoo_roomlist *yrl) | |
| 1047 | { | |
| 1048 | if (yrl->inpa) | |
| 1049 | gaim_input_remove(yrl->inpa); | |
| 1050 | if (yrl->rxqueue) | |
| 1051 | g_free(yrl->rxqueue); | |
| 1052 | if (yrl->path) | |
| 1053 | g_free(yrl->path); | |
| 1054 | if (yrl->host) | |
| 1055 | g_free(yrl->host); | |
| 1056 | if (yrl->parse) | |
| 1057 | g_markup_parse_context_free(yrl->parse); | |
| 1058 | } | |
| 1059 | ||
| 1060 | enum yahoo_room_type { | |
| 1061 | yrt_yahoo, | |
| 1062 | yrt_user, | |
| 1063 | }; | |
| 1064 | ||
| 1065 | struct yahoo_chatxml_state { | |
| 1066 | GaimRoomlist *list; | |
| 1067 | struct yahoo_roomlist *yrl; | |
| 1068 | GQueue *q; | |
| 1069 | struct { | |
| 1070 | enum yahoo_room_type type; | |
| 1071 | char *name; | |
| 1072 | char *topic; | |
| 1073 | char *id; | |
| 1074 | int users, voices, webcams; | |
| 1075 | } room; | |
| 1076 | }; | |
| 1077 | ||
| 1078 | struct yahoo_lobby { | |
| 1079 | int count, users, voices, webcams; | |
| 1080 | }; | |
| 1081 | ||
| 1082 | static struct yahoo_chatxml_state *yahoo_chatxml_state_new(GaimRoomlist *list, struct yahoo_roomlist *yrl) | |
| 1083 | { | |
| 1084 | struct yahoo_chatxml_state *s; | |
| 1085 | ||
| 1086 | s = g_new0(struct yahoo_chatxml_state, 1); | |
| 1087 | ||
| 1088 | s->list = list; | |
| 1089 | s->yrl = yrl; | |
| 1090 | s->q = g_queue_new(); | |
| 1091 | ||
| 1092 | return s; | |
| 1093 | } | |
| 1094 | ||
| 1095 | static void yahoo_chatxml_state_destroy(struct yahoo_chatxml_state *s) | |
| 1096 | { | |
| 1097 | g_queue_free(s->q); | |
| 1098 | if (s->room.name) | |
| 1099 | g_free(s->room.name); | |
| 1100 | if (s->room.topic) | |
| 1101 | g_free(s->room.topic); | |
| 1102 | if (s->room.id) | |
| 1103 | g_free(s->room.id); | |
| 1104 | g_free(s); | |
| 1105 | } | |
| 1106 | ||
| 1107 | static void yahoo_chatlist_start_element(GMarkupParseContext *context, const gchar *ename, | |
| 1108 | const gchar **anames, const gchar **avalues, | |
| 1109 | gpointer user_data, GError **error) | |
| 1110 | { | |
| 1111 | struct yahoo_chatxml_state *s = user_data; | |
| 1112 | GaimRoomlist *list = s->list; | |
| 1113 | GaimRoomlistRoom *r; | |
| 1114 | GaimRoomlistRoom *parent; | |
| 1115 | int i; | |
| 1116 | ||
| 1117 | if (!strcmp(ename, "category")) { | |
| 1118 | const gchar *name = NULL, *id = NULL; | |
| 1119 | ||
| 1120 | for (i = 0; anames[i]; i++) { | |
| 1121 | if (!strcmp(anames[i], "id")) | |
| 1122 | id = avalues[i]; | |
| 1123 | if (!strcmp(anames[i], "name")) | |
| 1124 | name = avalues[i]; | |
| 1125 | } | |
| 1126 | if (!name || !id) | |
| 1127 | return; | |
| 1128 | ||
| 1129 | parent = g_queue_peek_head(s->q); | |
| 8584 | 1130 | r = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATEGORY, name, parent); |
| 8113 | 1131 | gaim_roomlist_room_add_field(list, r, (gpointer)name); |
| 1132 | gaim_roomlist_room_add_field(list, r, (gpointer)id); | |
| 1133 | gaim_roomlist_room_add(list, r); | |
| 1134 | g_queue_push_head(s->q, r); | |
| 1135 | } else if (!strcmp(ename, "room")) { | |
| 1136 | s->room.users = s->room.voices = s->room.webcams = 0; | |
| 1137 | ||
| 1138 | for (i = 0; anames[i]; i++) { | |
| 1139 | if (!strcmp(anames[i], "id")) { | |
| 1140 | if (s->room.id) | |
| 1141 | g_free(s->room.id); | |
| 1142 | s->room.id = g_strdup(avalues[i]); | |
| 1143 | } else if (!strcmp(anames[i], "name")) { | |
| 1144 | if (s->room.name) | |
| 1145 | g_free(s->room.name); | |
| 1146 | s->room.name = g_strdup(avalues[i]); | |
| 1147 | } else if (!strcmp(anames[i], "topic")) { | |
| 1148 | if (s->room.topic) | |
| 1149 | g_free(s->room.topic); | |
| 1150 | s->room.topic = g_strdup(avalues[i]); | |
| 1151 | } else if (!strcmp(anames[i], "type")) { | |
| 1152 | if (!strcmp("yahoo", avalues[i])) | |
| 1153 | s->room.type = yrt_yahoo; | |
| 1154 | else | |
| 1155 | s->room.type = yrt_user; | |
| 1156 | } | |
| 1157 | } | |
| 1158 | ||
| 1159 | } else if (!strcmp(ename, "lobby")) { | |
| 1160 | struct yahoo_lobby *lob = g_new0(struct yahoo_lobby, 1); | |
| 1161 | ||
| 1162 | for (i = 0; anames[i]; i++) { | |
| 1163 | if (!strcmp(anames[i], "count")) { | |
| 1164 | lob->count = strtol(avalues[i], NULL, 10); | |
| 1165 | } else if (!strcmp(anames[i], "users")) { | |
| 1166 | s->room.users += lob->users = strtol(avalues[i], NULL, 10); | |
| 1167 | } else if (!strcmp(anames[i], "voices")) { | |
| 1168 | s->room.voices += lob->voices = strtol(avalues[i], NULL, 10); | |
| 1169 | } else if (!strcmp(anames[i], "webcams")) { | |
| 1170 | s->room.webcams += lob->webcams = strtol(avalues[i], NULL, 10); | |
| 1171 | } | |
| 1172 | } | |
| 1173 | ||
| 1174 | g_queue_push_head(s->q, lob); | |
| 1175 | } | |
| 1176 | ||
| 1177 | } | |
| 1178 | ||
| 1179 | static void yahoo_chatlist_end_element(GMarkupParseContext *context, const gchar *ename, | |
| 1180 | gpointer user_data, GError **error) | |
| 1181 | { | |
| 1182 | struct yahoo_chatxml_state *s = user_data; | |
| 1183 | ||
| 1184 | if (!strcmp(ename, "category")) { | |
| 1185 | g_queue_pop_head(s->q); | |
| 1186 | } else if (!strcmp(ename, "room")) { | |
| 1187 | struct yahoo_lobby *lob; | |
| 1188 | GaimRoomlistRoom *r, *l; | |
| 1189 | ||
| 1190 | if (s->room.type == yrt_yahoo) | |
| 8584 | 1191 | r = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATEGORY|GAIM_ROOMLIST_ROOMTYPE_ROOM, |
| 8113 | 1192 | s->room.name, s->yrl->cat); |
| 1193 | else | |
| 8584 | 1194 | r = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATEGORY|GAIM_ROOMLIST_ROOMTYPE_ROOM, |
| 8113 | 1195 | s->room.name, s->yrl->ucat); |
| 1196 | ||
| 1197 | gaim_roomlist_room_add_field(s->list, r, s->room.name); | |
| 1198 | gaim_roomlist_room_add_field(s->list, r, s->room.id); | |
| 1199 | gaim_roomlist_room_add_field(s->list, r, GINT_TO_POINTER(s->room.users)); | |
| 1200 | gaim_roomlist_room_add_field(s->list, r, GINT_TO_POINTER(s->room.voices)); | |
| 1201 | gaim_roomlist_room_add_field(s->list, r, GINT_TO_POINTER(s->room.webcams)); | |
| 1202 | gaim_roomlist_room_add_field(s->list, r, s->room.topic); | |
| 1203 | gaim_roomlist_room_add(s->list, r); | |
| 1204 | ||
| 1205 | while ((lob = g_queue_pop_head(s->q))) { | |
| 1206 | char *name = g_strdup_printf("%s:%d", s->room.name, lob->count); | |
| 1207 | l = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, name, r); | |
| 1208 | ||
| 1209 | gaim_roomlist_room_add_field(s->list, l, name); | |
| 1210 | gaim_roomlist_room_add_field(s->list, l, s->room.id); | |
| 1211 | gaim_roomlist_room_add_field(s->list, l, GINT_TO_POINTER(lob->users)); | |
| 1212 | gaim_roomlist_room_add_field(s->list, l, GINT_TO_POINTER(lob->voices)); | |
| 1213 | gaim_roomlist_room_add_field(s->list, l, GINT_TO_POINTER(lob->webcams)); | |
| 1214 | gaim_roomlist_room_add_field(s->list, l, s->room.topic); | |
| 1215 | gaim_roomlist_room_add(s->list, l); | |
| 1216 | ||
| 1217 | g_free(name); | |
| 1218 | g_free(lob); | |
| 1219 | } | |
| 1220 | ||
| 1221 | } | |
| 1222 | ||
| 1223 | } | |
| 1224 | ||
| 1225 | static GMarkupParser parser = { | |
| 1226 | yahoo_chatlist_start_element, | |
| 1227 | yahoo_chatlist_end_element, | |
| 1228 | NULL, | |
| 1229 | NULL, | |
| 1230 | NULL | |
| 1231 | }; | |
| 1232 | ||
| 1233 | static void yahoo_roomlist_cleanup(GaimRoomlist *list, struct yahoo_roomlist *yrl) | |
| 1234 | { | |
| 1235 | gaim_roomlist_set_in_progress(list, FALSE); | |
| 1236 | ||
| 1237 | if (yrl) { | |
| 1238 | list->proto_data = g_list_remove(list->proto_data, yrl); | |
| 1239 | yahoo_roomlist_destroy(yrl); | |
| 1240 | } | |
| 1241 | ||
| 1242 | gaim_roomlist_unref(list); | |
| 1243 | } | |
| 1244 | ||
| 1245 | static void yahoo_roomlist_pending(gpointer data, gint source, GaimInputCondition cond) | |
| 1246 | { | |
| 1247 | struct yahoo_roomlist *yrl = data; | |
| 1248 | GaimRoomlist *list = yrl->list; | |
| 1249 | char buf[1024]; | |
| 1250 | int len; | |
| 1251 | guchar *start; | |
| 1252 | struct yahoo_chatxml_state *s; | |
| 1253 | ||
| 1254 | len = read(yrl->fd, buf, sizeof(buf)); | |
| 1255 | ||
| 1256 | if (len <= 0) { | |
| 1257 | if (yrl->parse) | |
| 1258 | g_markup_parse_context_end_parse(yrl->parse, NULL); | |
| 1259 | yahoo_roomlist_cleanup(list, yrl); | |
| 1260 | return; | |
| 1261 | } | |
| 1262 | ||
| 1263 | ||
| 1264 | yrl->rxqueue = g_realloc(yrl->rxqueue, len + yrl->rxlen); | |
| 1265 | memcpy(yrl->rxqueue + yrl->rxlen, buf, len); | |
| 1266 | yrl->rxlen += len; | |
| 1267 | ||
| 1268 | if (!yrl->started) { | |
| 1269 | yrl->started = TRUE; | |
| 1270 | start = g_strstr_len(yrl->rxqueue, yrl->rxlen, "\r\n\r\n"); | |
| 1271 | if (!start || (start - yrl->rxqueue + 4) >= yrl->rxlen) | |
| 1272 | return; | |
| 1273 | start += 4; | |
| 1274 | } else { | |
| 1275 | start = yrl->rxqueue; | |
| 1276 | } | |
| 1277 | ||
| 1278 | if (yrl->parse == NULL) { | |
| 1279 | s = yahoo_chatxml_state_new(list, yrl); | |
| 1280 | yrl->parse = g_markup_parse_context_new(&parser, 0, s, | |
| 1281 | (GDestroyNotify)yahoo_chatxml_state_destroy); | |
| 1282 | } | |
| 1283 | ||
| 1284 | if (!g_markup_parse_context_parse(yrl->parse, start, (yrl->rxlen - (start - yrl->rxqueue)), NULL)) { | |
| 1285 | ||
| 1286 | yahoo_roomlist_cleanup(list, yrl); | |
| 1287 | return; | |
| 1288 | } | |
| 1289 | ||
| 1290 | yrl->rxlen = 0; | |
| 1291 | } | |
| 1292 | ||
| 1293 | static void yahoo_roomlist_got_connected(gpointer data, gint source, GaimInputCondition cond) | |
| 1294 | { | |
| 1295 | struct yahoo_roomlist *yrl = data; | |
| 1296 | GaimRoomlist *list = yrl->list; | |
| 1297 | char *buf, *cookie; | |
| 1298 | struct yahoo_data *yd = gaim_account_get_connection(list->account)->proto_data; | |
| 1299 | ||
| 1300 | if (source < 0) { | |
| 1301 | gaim_notify_error(gaim_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed.")); | |
| 1302 | yahoo_roomlist_cleanup(list, yrl); | |
| 1303 | return; | |
| 1304 | } | |
| 1305 | ||
| 1306 | yrl->fd = source; | |
| 1307 | ||
| 1308 | cookie = g_strdup_printf("Y=%s; T=%s", yd->cookie_y, yd->cookie_t); | |
| 1309 | buf = g_strdup_printf("GET /%s HTTP/1.0\r\nHost: %s\r\nCookie: %s\r\n\r\n", yrl->path, yrl->host, cookie); | |
| 1310 | write(yrl->fd, buf, strlen(buf)); | |
| 1311 | g_free(cookie); | |
| 1312 | g_free(buf); | |
| 1313 | yrl->inpa = gaim_input_add(yrl->fd, GAIM_INPUT_READ, yahoo_roomlist_pending, yrl); | |
| 1314 | ||
| 1315 | } | |
| 1316 | ||
| 1317 | GaimRoomlist *yahoo_roomlist_get_list(GaimConnection *gc) | |
| 1318 | { | |
| 1319 | struct yahoo_roomlist *yrl; | |
| 1320 | GaimRoomlist *rl; | |
| 1321 | char *url; | |
| 1322 | GList *fields = NULL; | |
| 1323 | GaimRoomlistField *f; | |
| 1324 | ||
| 1325 | url = g_strdup_printf("%s?chatcat=0", | |
| 1326 | gaim_account_get_string( | |
| 1327 | gaim_connection_get_account(gc), | |
| 1328 | "room_list", YAHOO_ROOMLIST_URL)); | |
| 1329 | ||
| 1330 | yrl = g_new0(struct yahoo_roomlist, 1); | |
| 1331 | rl = gaim_roomlist_new(gaim_connection_get_account(gc)); | |
| 1332 | yrl->list = rl; | |
| 1333 | ||
| 1334 | gaim_url_parse(url, &(yrl->host), NULL, &(yrl->path)); | |
| 1335 | g_free(url); | |
| 1336 | ||
| 1337 | f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "room", TRUE); | |
| 1338 | fields = g_list_append(fields, f); | |
| 1339 | ||
| 1340 | f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "id", TRUE); | |
| 1341 | fields = g_list_append(fields, f); | |
| 1342 | ||
| 1343 | f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Users"), "users", FALSE); | |
| 1344 | fields = g_list_append(fields, f); | |
| 1345 | ||
| 1346 | f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Voices"), "voices", FALSE); | |
| 1347 | fields = g_list_append(fields, f); | |
| 1348 | ||
| 1349 | f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Webcams"), "webcams", FALSE); | |
| 1350 | fields = g_list_append(fields, f); | |
| 1351 | ||
| 1352 | f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Topic"), "topic", FALSE); | |
| 1353 | fields = g_list_append(fields, f); | |
| 1354 | ||
| 1355 | gaim_roomlist_set_fields(rl, fields); | |
| 1356 | ||
| 1357 | if (gaim_proxy_connect(gaim_connection_get_account(gc), | |
| 1358 | yrl->host, 80, yahoo_roomlist_got_connected, yrl) != 0) | |
| 1359 | { | |
| 1360 | gaim_notify_error(gc, NULL, _("Connection problem"), _("Unable to fetch room list.")); | |
| 1361 | yahoo_roomlist_cleanup(rl, yrl); | |
| 1362 | return NULL; | |
| 1363 | } | |
| 1364 | ||
| 1365 | rl->proto_data = g_list_append(rl->proto_data, yrl); | |
| 1366 | ||
| 1367 | gaim_roomlist_set_in_progress(rl, TRUE); | |
| 1368 | return rl; | |
| 1369 | } | |
| 1370 | ||
| 1371 | void yahoo_roomlist_cancel(GaimRoomlist *list) | |
| 1372 | { | |
| 1373 | GList *l, *k; | |
| 1374 | ||
| 1375 | k = l = list->proto_data; | |
| 1376 | list->proto_data = NULL; | |
| 1377 | ||
| 1378 | gaim_roomlist_set_in_progress(list, FALSE); | |
| 1379 | ||
| 1380 | for (; l; l = l->next) { | |
| 1381 | yahoo_roomlist_destroy(l->data); | |
| 1382 | gaim_roomlist_unref(l->data); | |
| 1383 | } | |
| 1384 | g_list_free(k); | |
| 1385 | } | |
| 1386 | ||
| 8584 | 1387 | void yahoo_roomlist_expand_category(GaimRoomlist *list, GaimRoomlistRoom *category) |
| 8113 | 1388 | { |
| 1389 | struct yahoo_roomlist *yrl; | |
| 1390 | char *url; | |
| 1391 | char *id; | |
| 1392 | ||
| 8584 | 1393 | if (category->type != GAIM_ROOMLIST_ROOMTYPE_CATEGORY) |
| 8113 | 1394 | return; |
| 1395 | ||
| 8584 | 1396 | if (!(id = g_list_nth_data(category->fields, 1))) { |
| 8113 | 1397 | gaim_roomlist_set_in_progress(list, FALSE); |
| 1398 | return; | |
| 1399 | } | |
| 1400 | ||
| 1401 | url = g_strdup_printf("%s?chatroom_%s=0", | |
| 1402 | gaim_account_get_string( | |
| 1403 | list->account, | |
| 1404 | "room_list", YAHOO_ROOMLIST_URL), id); | |
| 1405 | ||
| 1406 | yrl = g_new0(struct yahoo_roomlist, 1); | |
| 1407 | yrl->list = list; | |
| 8584 | 1408 | yrl->cat = category; |
| 8113 | 1409 | list->proto_data = g_list_append(list->proto_data, yrl); |
| 1410 | ||
| 1411 | gaim_url_parse(url, &(yrl->host), NULL, &(yrl->path)); | |
| 1412 | g_free(url); | |
| 1413 | ||
| 8584 | 1414 | yrl->ucat = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_CATEGORY, _("User Rooms"), yrl->cat); |
| 8113 | 1415 | gaim_roomlist_room_add(list, yrl->ucat); |
| 1416 | ||
| 1417 | if (gaim_proxy_connect(list->account, | |
| 1418 | yrl->host, 80, yahoo_roomlist_got_connected, yrl) != 0) | |
| 1419 | { | |
| 1420 | gaim_notify_error(gaim_account_get_connection(list->account), | |
| 1421 | NULL, _("Connection problem"), _("Unable to fetch room list.")); | |
| 1422 | yahoo_roomlist_cleanup(list, yrl); | |
| 1423 | return; | |
| 1424 | } | |
| 1425 | ||
| 1426 | gaim_roomlist_set_in_progress(list, TRUE); | |
| 1427 | gaim_roomlist_ref(list); | |
| 1428 | } | |
| 1429 |