Mercurial > pidgin
annotate src/protocols/yahoo/yahoochat.c @ 9642:8901ef16f310
[gaim-migrate @ 10490]
Some changes that don't affect anything. Ethan might want to do
something with this function? I'm too lazy to read the gaim-devel
emails in detail.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 02 Aug 2004 03:33:00 +0000 |
| parents | 1a9157d70ec0 |
| children | db62420a53a2 |
| 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 /* this is slow, and different from the gaim_* version in that it (hopefully) won't add a user twice */ | |
| 9376 | 73 void yahoo_chat_add_users(GaimConvChat *chat, GList *newusers) |
| 6729 | 74 { |
| 9554 | 75 GList *i; |
| 6729 | 76 |
| 77 for (i = newusers; i; i = i->next) { | |
| 9554 | 78 if (gaim_conv_chat_find_user(chat, i->data)) |
| 6729 | 79 continue; |
| 9554 | 80 gaim_conv_chat_add_user(chat, i->data, NULL, GAIM_CBFLAGS_NONE); |
| 6729 | 81 } |
| 82 } | |
| 83 | |
| 9376 | 84 void yahoo_chat_add_user(GaimConvChat *chat, const char *user, const char *reason) |
| 6729 | 85 { |
| 9554 | 86 if (gaim_conv_chat_find_user(chat, user)) |
| 6729 | 87 return; |
| 88 | |
| 9554 | 89 gaim_conv_chat_add_user(chat, user, reason, GAIM_CBFLAGS_NONE); |
| 6729 | 90 } |
| 91 | |
| 92 static GaimConversation *yahoo_find_conference(GaimConnection *gc, const char *name) | |
| 93 { | |
| 94 struct yahoo_data *yd; | |
| 95 GSList *l; | |
| 96 | |
| 97 yd = gc->proto_data; | |
| 98 | |
| 99 for (l = yd->confs; l; l = l->next) { | |
| 100 GaimConversation *c = l->data; | |
| 101 if (!gaim_utf8_strcasecmp(gaim_conversation_get_name(c), name)) | |
| 102 return c; | |
| 103 } | |
| 104 return NULL; | |
| 105 } | |
| 106 | |
| 107 | |
| 108 void yahoo_process_conference_invite(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 109 { | |
| 110 GSList *l; | |
| 111 char *room = NULL; | |
| 112 char *who = NULL; | |
| 113 char *msg = NULL; | |
| 114 GString *members = NULL; | |
| 115 GHashTable *components; | |
| 116 | |
| 117 | |
| 118 if (pkt->status == 2) | |
| 119 return; /* XXX */ | |
| 120 | |
| 121 members = g_string_sized_new(512); | |
| 122 | |
| 123 for (l = pkt->hash; l; l = l->next) { | |
| 124 struct yahoo_pair *pair = l->data; | |
| 125 | |
| 126 switch (pair->key) { | |
| 127 case 1: /* us, but we already know who we are */ | |
| 128 break; | |
| 129 case 57: | |
| 7827 | 130 room = yahoo_string_decode(gc, pair->value, FALSE); |
| 6729 | 131 break; |
| 132 case 50: /* inviter */ | |
| 133 who = pair->value; | |
| 134 g_string_append_printf(members, "%s\n", who); | |
| 135 break; | |
| 136 case 52: /* members */ | |
| 137 g_string_append_printf(members, "%s\n", pair->value); | |
| 138 break; | |
| 139 case 58: | |
| 7827 | 140 msg = yahoo_string_decode(gc, pair->value, FALSE); |
| 6729 | 141 break; |
| 142 case 13: /* ? */ | |
| 143 break; | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 if (!room) { | |
| 148 g_string_free(members, TRUE); | |
| 149 return; | |
| 150 } | |
| 151 | |
| 152 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 7827 | 153 g_hash_table_replace(components, g_strdup("room"), room); |
| 6729 | 154 if (msg) |
| 7827 | 155 g_hash_table_replace(components, g_strdup("topic"), msg); |
| 6729 | 156 g_hash_table_replace(components, g_strdup("type"), g_strdup("Conference")); |
| 157 if (members) { | |
| 158 g_hash_table_replace(components, g_strdup("members"), g_strdup(members->str)); | |
| 159 } | |
| 160 serv_got_chat_invite(gc, room, who, msg, components); | |
| 161 | |
| 162 g_string_free(members, TRUE); | |
| 163 } | |
| 164 | |
| 165 void yahoo_process_conference_decline(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 166 { | |
| 167 GSList *l; | |
| 168 char *room = NULL; | |
| 169 char *who = NULL; | |
| 170 char *msg = NULL; | |
| 171 | |
| 172 for (l = pkt->hash; l; l = l->next) { | |
| 173 struct yahoo_pair *pair = l->data; | |
| 174 | |
| 175 switch (pair->key) { | |
| 176 case 57: | |
| 7827 | 177 room = yahoo_string_decode(gc, pair->value, FALSE); |
| 6729 | 178 break; |
| 179 case 54: | |
| 180 who = pair->value; | |
| 181 break; | |
| 182 case 14: | |
| 7827 | 183 msg = yahoo_string_decode(gc, pair->value, FALSE); |
| 6729 | 184 break; |
| 185 } | |
| 186 } | |
| 187 | |
| 188 if (who && room) { | |
| 9575 | 189 /* make sure we're in the room before we process a decline message for it */ |
| 9576 | 190 if(yahoo_find_conference(gc, room)) { |
| 9575 | 191 char *tmp; |
| 6729 | 192 |
| 9575 | 193 tmp = g_strdup_printf(_("%s declined your conference invitation to room \"%s\" because \"%s\"."), |
| 194 who, room, msg?msg:""); | |
| 195 gaim_notify_info(gc, NULL, _("Invitation Rejected"), tmp); | |
| 196 g_free(tmp); | |
| 197 } | |
| 198 | |
| 7827 | 199 g_free(room); |
| 200 if (msg) | |
| 201 g_free(msg); | |
| 6729 | 202 } |
| 203 } | |
| 204 | |
| 205 void yahoo_process_conference_logon(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 206 { | |
| 207 GSList *l; | |
| 208 char *room = NULL; | |
| 209 char *who = NULL; | |
| 210 GaimConversation *c; | |
| 211 | |
| 212 for (l = pkt->hash; l; l = l->next) { | |
| 213 struct yahoo_pair *pair = l->data; | |
| 214 | |
| 215 switch (pair->key) { | |
| 216 case 57: | |
| 7827 | 217 room = yahoo_string_decode(gc, pair->value, FALSE); |
| 6729 | 218 break; |
| 219 case 53: | |
| 220 who = pair->value; | |
| 221 break; | |
| 222 } | |
| 223 } | |
| 224 | |
| 225 if (who && room) { | |
| 226 c = yahoo_find_conference(gc, room); | |
| 227 if (c) | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
228 yahoo_chat_add_user(GAIM_CONV_CHAT(c), who, NULL); |
| 7827 | 229 g_free(room); |
| 6729 | 230 } |
| 231 } | |
| 232 | |
| 233 void yahoo_process_conference_logoff(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 234 { | |
| 235 GSList *l; | |
| 236 char *room = NULL; | |
| 237 char *who = NULL; | |
| 238 GaimConversation *c; | |
| 239 | |
| 240 for (l = pkt->hash; l; l = l->next) { | |
| 241 struct yahoo_pair *pair = l->data; | |
| 242 | |
| 243 switch (pair->key) { | |
| 244 case 57: | |
| 7827 | 245 room = yahoo_string_decode(gc, pair->value, FALSE); |
| 6729 | 246 break; |
| 247 case 56: | |
| 248 who = pair->value; | |
| 249 break; | |
| 250 } | |
| 251 } | |
| 252 | |
| 253 if (who && room) { | |
| 254 c = yahoo_find_conference(gc, room); | |
| 255 if (c) | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
256 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); |
| 7827 | 257 g_free(room); |
| 6729 | 258 } |
| 259 } | |
| 260 | |
| 261 void yahoo_process_conference_message(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 262 { | |
| 263 GSList *l; | |
| 264 char *room = NULL; | |
| 265 char *who = NULL; | |
| 266 char *msg = NULL; | |
| 7827 | 267 char *msg2; |
| 268 int utf8 = 0; | |
| 6729 | 269 GaimConversation *c; |
| 270 | |
| 271 for (l = pkt->hash; l; l = l->next) { | |
| 272 struct yahoo_pair *pair = l->data; | |
| 273 | |
| 274 switch (pair->key) { | |
| 275 case 57: | |
| 7827 | 276 room = yahoo_string_decode(gc, pair->value, FALSE); |
| 6729 | 277 break; |
| 278 case 3: | |
| 279 who = pair->value; | |
| 280 break; | |
| 281 case 14: | |
| 282 msg = pair->value; | |
| 283 break; | |
| 7827 | 284 case 97: |
| 285 utf8 = strtol(pair->value, NULL, 10); | |
| 286 break; | |
| 6729 | 287 } |
| 288 } | |
| 289 | |
| 290 if (room && who && msg) { | |
| 7827 | 291 msg2 = yahoo_string_decode(gc, msg, utf8); |
| 6729 | 292 c = yahoo_find_conference(gc, room); |
| 293 if (!c) | |
| 294 return; | |
| 7827 | 295 msg = yahoo_codes_to_html(msg2); |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
296 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), who, 0, msg, time(NULL)); |
| 6729 | 297 g_free(msg); |
| 7827 | 298 g_free(msg2); |
| 6729 | 299 } |
| 7827 | 300 if (room) |
| 301 g_free(room); | |
| 6729 | 302 } |
| 303 | |
| 304 | |
|
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8584
diff
changeset
|
305 /* this is a confirmation of yahoo_chat_online(); */ |
| 6729 | 306 void yahoo_process_chat_online(GaimConnection *gc, struct yahoo_packet *pkt) |
| 307 { | |
| 308 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
| 309 | |
| 310 if (pkt->status == 1) | |
| 311 yd->chat_online = 1; | |
| 312 } | |
| 313 | |
| 314 /* this is basicly the opposite of chat_online */ | |
| 315 void yahoo_process_chat_logout(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 316 { | |
| 317 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
| 7186 | 318 GSList *l; |
| 7827 | 319 |
| 7186 | 320 for (l = pkt->hash; l; l = l->next) { |
| 321 struct yahoo_pair *pair = l->data; | |
| 6729 | 322 |
| 7186 | 323 if (pair->key == 1) |
| 324 if (g_ascii_strcasecmp(pair->value, | |
| 325 gaim_connection_get_display_name(gc))) | |
| 326 return; | |
| 327 } | |
| 7827 | 328 |
| 7186 | 329 if (pkt->status == 1) { |
| 6729 | 330 yd->chat_online = 0; |
| 7186 | 331 if (yd->in_chat) |
| 332 yahoo_c_leave(gc, YAHOO_CHAT_ID); | |
| 333 } | |
| 6729 | 334 } |
| 335 | |
| 336 void yahoo_process_chat_join(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 337 { | |
| 338 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
| 339 GaimConversation *c = NULL; | |
| 340 GSList *l; | |
| 341 GList *members = NULL; | |
| 342 char *room = NULL; | |
| 343 char *topic = NULL; | |
| 344 char *someid, *someotherid, *somebase64orhashosomething, *somenegativenumber; | |
| 345 | |
| 346 if (pkt->status == -1) { | |
| 347 gaim_notify_error(gc, NULL, _("Failed to join chat"), _("Maybe the room is full?")); | |
| 348 return; | |
| 349 } | |
| 350 | |
| 351 for (l = pkt->hash; l; l = l->next) { | |
| 352 struct yahoo_pair *pair = l->data; | |
| 353 | |
| 354 switch (pair->key) { | |
| 355 | |
| 356 case 104: | |
| 8410 | 357 room = yahoo_string_decode(gc, pair->value, TRUE); |
| 6729 | 358 break; |
| 359 case 105: | |
| 8410 | 360 topic = yahoo_string_decode(gc, pair->value, TRUE); |
| 6729 | 361 break; |
| 362 case 128: | |
| 363 someid = pair->value; | |
| 364 break; | |
| 365 case 108: /* number of joiners */ | |
| 366 break; | |
| 367 case 129: | |
| 368 someotherid = pair->value; | |
| 369 break; | |
| 370 case 130: | |
| 371 somebase64orhashosomething = pair->value; | |
| 372 break; | |
| 373 case 126: | |
| 374 somenegativenumber = pair->value; | |
| 375 break; | |
| 376 case 13: /* this is 1. maybe its the type of room? (normal, user created, private, etc?) */ | |
| 377 break; | |
|
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8584
diff
changeset
|
378 case 61: /*this looks similar to 130 */ |
| 6729 | 379 break; |
| 380 | |
| 381 /* the previous section was just room info. this next section is | |
| 382 info about individual room members, (including us) */ | |
| 383 | |
| 384 case 109: /* the yahoo id */ | |
| 385 members = g_list_append(members, pair->value); | |
| 386 break; | |
| 387 case 110: /* age */ | |
| 388 break; | |
| 389 case 141: /* nickname */ | |
| 390 break; | |
| 391 case 142: /* location */ | |
| 392 break; | |
| 393 case 113: /* bitmask */ | |
| 394 break; | |
| 395 } | |
| 396 } | |
| 397 | |
| 398 | |
| 9329 | 399 if (room && yd->chat_name && gaim_utf8_strcasecmp(room, yd->chat_name)) |
| 7186 | 400 yahoo_chat_leave(gc, room, |
| 401 gaim_connection_get_display_name(gc), FALSE); | |
| 6729 | 402 |
| 403 c = gaim_find_chat(gc, YAHOO_CHAT_ID); | |
| 404 | |
| 9329 | 405 if (room && (!c || gaim_conv_chat_has_left(GAIM_CONV_CHAT(c))) && members && |
| 8357 | 406 ((g_list_length(members) > 1) || |
| 407 !g_ascii_strcasecmp(members->data, gaim_connection_get_display_name(gc)))) { | |
| 9554 | 408 int i; |
| 409 GList *flags = NULL; | |
| 410 for (i = 0; i < g_list_length(members); i++) | |
| 411 flags = g_list_append(flags, GINT_TO_POINTER(GAIM_CBFLAGS_NONE)); | |
| 8357 | 412 if (c && gaim_conv_chat_has_left(GAIM_CONV_CHAT(c))) { |
| 413 /* this might be a hack, but oh well, it should nicely */ | |
| 414 char *tmpmsg; | |
| 415 | |
| 416 gaim_conversation_set_name(c, room); | |
| 417 | |
| 418 c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); | |
| 419 if (topic) | |
| 420 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); | |
| 421 yd->in_chat = 1; | |
| 422 yd->chat_name = g_strdup(room); | |
| 9554 | 423 gaim_conv_chat_add_users(GAIM_CONV_CHAT(c), members, flags); |
| 8357 | 424 |
| 425 tmpmsg = g_strdup_printf(_("You are now chatting in %s."), room); | |
| 426 gaim_conv_chat_write(GAIM_CONV_CHAT(c), "", tmpmsg, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 427 g_free(tmpmsg); | |
| 428 } else { | |
| 429 c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); | |
| 430 if (topic) | |
| 431 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); | |
| 432 yd->in_chat = 1; | |
| 433 yd->chat_name = g_strdup(room); | |
| 9554 | 434 gaim_conv_chat_add_users(GAIM_CONV_CHAT(c), members, flags); |
| 8357 | 435 } |
| 7186 | 436 } else if (c) { |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
437 yahoo_chat_add_users(GAIM_CONV_CHAT(c), members); |
| 6729 | 438 } |
| 439 | |
| 440 g_list_free(members); | |
| 7827 | 441 g_free(room); |
| 442 if (topic) | |
| 443 g_free(topic); | |
| 6729 | 444 } |
| 445 | |
| 446 void yahoo_process_chat_exit(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 447 { | |
| 448 char *who = NULL; | |
| 7186 | 449 char *room = NULL; |
| 6729 | 450 GSList *l; |
| 451 struct yahoo_data *yd; | |
| 452 | |
| 453 yd = gc->proto_data; | |
| 454 | |
| 455 for (l = pkt->hash; l; l = l->next) { | |
| 456 struct yahoo_pair *pair = l->data; | |
| 457 | |
| 7186 | 458 if (pair->key == 104) |
| 8410 | 459 room = yahoo_string_decode(gc, pair->value, TRUE); |
| 6729 | 460 if (pair->key == 109) |
| 461 who = pair->value; | |
| 462 } | |
| 463 | |
| 464 | |
| 7186 | 465 if (who && room) { |
| 6729 | 466 GaimConversation *c = gaim_find_chat(gc, YAHOO_CHAT_ID); |
| 7186 | 467 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
|
468 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); |
| 6729 | 469 |
| 470 } | |
| 7827 | 471 if (room) |
| 472 g_free(room); | |
| 6729 | 473 } |
| 474 | |
| 475 void yahoo_process_chat_message(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 476 { | |
| 7827 | 477 char *room = NULL, *who = NULL, *msg = NULL, *msg2; |
| 8410 | 478 int msgtype = 1, utf8 = 1; /* default to utf8 */ |
| 6729 | 479 GaimConversation *c = NULL; |
| 480 GSList *l; | |
| 481 | |
| 482 for (l = pkt->hash; l; l = l->next) { | |
| 483 struct yahoo_pair *pair = l->data; | |
| 484 | |
| 485 switch (pair->key) { | |
| 486 | |
| 7827 | 487 case 97: |
| 488 utf8 = strtol(pair->value, NULL, 10); | |
| 489 break; | |
| 6729 | 490 case 104: |
| 8410 | 491 room = yahoo_string_decode(gc, pair->value, TRUE); |
| 6729 | 492 break; |
| 493 case 109: | |
| 494 who = pair->value; | |
| 495 break; | |
| 496 case 117: | |
| 497 msg = pair->value; | |
| 498 break; | |
| 499 case 124: | |
| 500 msgtype = strtol(pair->value, NULL, 10); | |
| 501 break; | |
| 502 } | |
| 503 } | |
| 504 | |
| 505 | |
| 506 c = gaim_find_chat(gc, YAHOO_CHAT_ID); | |
| 7827 | 507 if (!who || !c) { |
| 508 if (room) | |
| 509 g_free(room); | |
| 6729 | 510 /* we still get messages after we part, funny that */ |
| 511 return; | |
| 512 } | |
| 513 | |
| 514 if (!msg) { | |
| 515 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Got a message packet with no message.\nThis probably means something important, but we're ignoring it.\n"); | |
| 516 return; | |
| 517 } | |
| 7827 | 518 msg2 = yahoo_string_decode(gc, msg, utf8); |
| 519 msg = yahoo_codes_to_html(msg2); | |
| 520 g_free(msg2); | |
| 6729 | 521 |
| 522 if (msgtype == 2 || msgtype == 3) { | |
| 523 char *tmp; | |
| 524 tmp = g_strdup_printf("/me %s", msg); | |
| 525 g_free(msg); | |
| 526 msg = tmp; | |
| 527 } | |
| 528 | |
| 529 serv_got_chat_in(gc, YAHOO_CHAT_ID, who, 0, msg, time(NULL)); | |
| 530 g_free(msg); | |
| 531 } | |
| 532 | |
| 533 void yahoo_process_chat_addinvite(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 534 { | |
| 535 GSList *l; | |
| 536 char *room = NULL; | |
| 537 char *msg = NULL; | |
| 538 char *who = NULL; | |
| 539 | |
| 540 | |
| 541 for (l = pkt->hash; l; l = l->next) { | |
| 542 struct yahoo_pair *pair = l->data; | |
| 543 | |
| 544 switch (pair->key) { | |
| 545 case 104: | |
| 8410 | 546 room = yahoo_string_decode(gc, pair->value, TRUE); |
| 6729 | 547 break; |
| 548 case 129: /* room id? */ | |
| 549 break; | |
| 550 case 126: /* ??? */ | |
| 551 break; | |
| 552 case 117: | |
| 7827 | 553 msg = yahoo_string_decode(gc, pair->value, FALSE); |
| 6729 | 554 break; |
| 555 case 119: | |
| 556 who = pair->value; | |
| 557 break; | |
| 558 case 118: /* us */ | |
| 559 break; | |
| 560 } | |
| 561 } | |
| 562 | |
| 563 if (room && who) { | |
| 564 GHashTable *components; | |
| 565 | |
| 566 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 567 g_hash_table_replace(components, g_strdup("room"), g_strdup(room)); | |
| 568 serv_got_chat_invite(gc, room, who, msg, components); | |
| 569 } | |
| 7827 | 570 if (room) |
| 571 g_free(room); | |
| 572 if (msg) | |
| 573 g_free(msg); | |
| 6729 | 574 } |
| 575 | |
| 576 void yahoo_process_chat_goto(GaimConnection *gc, struct yahoo_packet *pkt) | |
| 577 { | |
| 578 if (pkt->status == -1) | |
| 579 gaim_notify_error(gc, NULL, _("Failed to join buddy in chat"), | |
| 580 _("Maybe they're not in a chat?")); | |
| 581 } | |
| 582 | |
| 583 | |
| 584 /* | |
| 585 * Functions dealing with conferences | |
| 7827 | 586 * I think conference names are always ascii. |
| 6729 | 587 */ |
| 588 | |
| 589 static void yahoo_conf_leave(struct yahoo_data *yd, const char *room, const char *dn, GList *who) | |
| 590 { | |
| 591 struct yahoo_packet *pkt; | |
| 592 GList *w; | |
| 593 | |
| 594 | |
| 595 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGOFF, YAHOO_STATUS_AVAILABLE, 0); | |
| 596 | |
| 597 yahoo_packet_hash(pkt, 1, dn); | |
| 598 for (w = who; w; w = w->next) { | |
| 9554 | 599 const char *name = gaim_conv_chat_cb_get_name(w->data); |
| 600 yahoo_packet_hash(pkt, 3, name); | |
| 6729 | 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); | |
| 9554 | 626 for (who = members; who; who = who->next) { |
| 627 const char *name = gaim_conv_chat_cb_get_name(who->data); | |
| 628 yahoo_packet_hash(pkt, 53, name); | |
| 629 } | |
| 6729 | 630 yahoo_packet_hash(pkt, 57, room); |
| 7827 | 631 yahoo_packet_hash(pkt, 14, msg2); |
| 632 if (utf8) | |
| 633 yahoo_packet_hash(pkt, 97, "1"); /* utf-8 */ | |
| 6729 | 634 |
| 635 yahoo_send_packet(yd, pkt); | |
| 636 | |
| 637 yahoo_packet_free(pkt); | |
| 6804 | 638 g_free(msg); |
| 7827 | 639 g_free(msg2); |
| 6729 | 640 |
| 641 return 0; | |
| 642 } | |
| 643 | |
| 644 static void yahoo_conf_join(struct yahoo_data *yd, GaimConversation *c, const char *dn, const char *room, | |
| 645 const char *topic, const char *members) | |
| 646 { | |
| 647 struct yahoo_packet *pkt; | |
| 648 char **memarr = NULL; | |
| 649 int i; | |
| 650 | |
| 651 if (members) | |
| 652 memarr = g_strsplit(members, "\n", 0); | |
| 653 | |
| 654 | |
| 655 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGON, YAHOO_STATUS_AVAILABLE, 0); | |
| 656 | |
| 657 yahoo_packet_hash(pkt, 1, dn); | |
| 658 yahoo_packet_hash(pkt, 3, dn); | |
| 659 yahoo_packet_hash(pkt, 57, room); | |
| 660 if (memarr) { | |
| 661 for(i = 0 ; memarr[i]; i++) { | |
| 662 if (!strcmp(memarr[i], "") || !strcmp(memarr[i], dn)) | |
| 663 continue; | |
| 664 yahoo_packet_hash(pkt, 3, memarr[i]); | |
| 9554 | 665 gaim_conv_chat_add_user(GAIM_CONV_CHAT(c), memarr[i], NULL, GAIM_CBFLAGS_NONE); |
| 6729 | 666 } |
| 667 } | |
| 668 yahoo_send_packet(yd, pkt); | |
| 669 | |
| 670 yahoo_packet_free(pkt); | |
| 671 | |
| 672 if (memarr) | |
| 673 g_strfreev(memarr); | |
| 674 } | |
| 675 | |
| 7827 | 676 static void yahoo_conf_invite(GaimConnection *gc, GaimConversation *c, |
| 6729 | 677 const char *dn, const char *buddy, const char *room, const char *msg) |
| 678 { | |
| 7827 | 679 struct yahoo_data *yd = gc->proto_data; |
| 6729 | 680 struct yahoo_packet *pkt; |
| 681 GList *members; | |
| 7827 | 682 char *msg2 = NULL; |
| 683 | |
| 684 if (msg) | |
| 685 msg2 = yahoo_string_encode(gc, msg, NULL); | |
| 6729 | 686 |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
687 members = gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)); |
| 6729 | 688 |
| 689 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE, YAHOO_STATUS_AVAILABLE, 0); | |
| 690 | |
| 691 yahoo_packet_hash(pkt, 1, dn); | |
| 692 yahoo_packet_hash(pkt, 51, buddy); | |
| 693 yahoo_packet_hash(pkt, 57, room); | |
| 7827 | 694 yahoo_packet_hash(pkt, 58, msg?msg2:""); |
| 6729 | 695 yahoo_packet_hash(pkt, 13, "0"); |
| 696 for(; members; members = members->next) { | |
| 9554 | 697 const char *name = gaim_conv_chat_cb_get_name(members->data); |
| 698 if (!strcmp(name, dn)) | |
| 6729 | 699 continue; |
| 9554 | 700 yahoo_packet_hash(pkt, 52, name); |
| 701 yahoo_packet_hash(pkt, 53, name); | |
| 6729 | 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 } |
