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