Mercurial > pidgin.yaz
annotate src/protocols/yahoo/yahoochat.c @ 8046:fa6395637e2c
[gaim-migrate @ 8730]
John Silverstri did this for me.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 10 Jan 2004 04:04:57 +0000 |
parents | adcd6208ff43 |
children | d60272410bd5 |
rev | line source |
---|---|
6729 | 1 /* |
2 * gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
7 * | |
6729 | 8 * Some code copyright 2003 Tim Ringenbach <omarvo@hotmail.com> |
9 * (marv on irc.freenode.net) | |
10 * Some code borrowed from libyahoo2, copyright (C) 2002, Philip | |
11 * S Tellis <philip . tellis AT gmx . net> | |
12 * | |
13 * This program is free software; you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation; either version 2 of the License, or | |
16 * (at your option) any later version. | |
17 * | |
18 * This program is distributed in the hope that it will be useful, | |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 * GNU General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU General Public License | |
24 * along with this program; if not, write to the Free Software | |
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
26 * | |
27 */ | |
28 | |
29 #ifdef HAVE_CONFIG_H | |
30 #include "config.h" | |
31 #endif | |
32 | |
33 #include "debug.h" | |
34 #include "prpl.h" | |
35 | |
36 #include "conversation.h" | |
37 #include "notify.h" | |
38 #include "util.h" | |
39 #include "multi.h" | |
40 #include "internal.h" | |
41 | |
42 #include "yahoo.h" | |
43 #include "yahoochat.h" | |
44 | |
45 #define YAHOO_CHAT_ID (1) | |
46 | |
7186 | 47 /* prototype(s) */ |
48 static void yahoo_chat_leave(GaimConnection *gc, const char *room, const char *dn, gboolean logout); | |
49 | |
6729 | 50 /* special function to log us on to the yahoo chat service */ |
51 static void yahoo_chat_online(GaimConnection *gc) | |
52 { | |
53 struct yahoo_data *yd = gc->proto_data; | |
54 struct yahoo_packet *pkt; | |
55 | |
56 | |
57 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATONLINE, YAHOO_STATUS_AVAILABLE,0); | |
58 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
59 yahoo_packet_hash(pkt, 109, gaim_connection_get_display_name(gc)); | |
60 yahoo_packet_hash(pkt, 6, "abcde"); | |
61 | |
62 yahoo_send_packet(yd, pkt); | |
63 | |
64 yahoo_packet_free(pkt); | |
65 } | |
66 | |
67 static gint _mystrcmpwrapper(gconstpointer a, gconstpointer b) | |
68 { | |
69 return strcmp(a, b); | |
70 } | |
71 | |
72 /* this is slow, and different from the gaim_* version in that it (hopefully) won't add a user twice */ | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
73 static void yahoo_chat_add_users(GaimConvChat *chat, GList *newusers) |
6729 | 74 { |
75 GList *users, *i, *j; | |
76 | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
77 users = gaim_conv_chat_get_users(chat); |
6729 | 78 |
79 for (i = newusers; i; i = i->next) { | |
80 j = g_list_find_custom(users, i->data, _mystrcmpwrapper); | |
81 if (j) | |
82 continue; | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
83 gaim_conv_chat_add_user(chat, i->data, NULL); |
6729 | 84 } |
85 } | |
86 | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
87 static void yahoo_chat_add_user(GaimConvChat *chat, const char *user, const char *reason) |
6729 | 88 { |
89 GList *users; | |
90 | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
91 users = gaim_conv_chat_get_users(chat); |
6729 | 92 |
93 if ((g_list_find_custom(users, user, _mystrcmpwrapper))) | |
94 return; | |
95 | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
96 gaim_conv_chat_add_user(chat, user, reason); |
6729 | 97 } |
98 | |
99 static GaimConversation *yahoo_find_conference(GaimConnection *gc, const char *name) | |
100 { | |
101 struct yahoo_data *yd; | |
102 GSList *l; | |
103 | |
104 yd = gc->proto_data; | |
105 | |
106 for (l = yd->confs; l; l = l->next) { | |
107 GaimConversation *c = l->data; | |
108 if (!gaim_utf8_strcasecmp(gaim_conversation_get_name(c), name)) | |
109 return c; | |
110 } | |
111 return NULL; | |
112 } | |
113 | |
114 | |
115 void yahoo_process_conference_invite(GaimConnection *gc, struct yahoo_packet *pkt) | |
116 { | |
117 GSList *l; | |
118 char *room = NULL; | |
119 char *who = NULL; | |
120 char *msg = NULL; | |
121 GString *members = NULL; | |
122 GHashTable *components; | |
123 | |
124 | |
125 if (pkt->status == 2) | |
126 return; /* XXX */ | |
127 | |
128 members = g_string_sized_new(512); | |
129 | |
130 for (l = pkt->hash; l; l = l->next) { | |
131 struct yahoo_pair *pair = l->data; | |
132 | |
133 switch (pair->key) { | |
134 case 1: /* us, but we already know who we are */ | |
135 break; | |
136 case 57: | |
7827 | 137 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 138 break; |
139 case 50: /* inviter */ | |
140 who = pair->value; | |
141 g_string_append_printf(members, "%s\n", who); | |
142 break; | |
143 case 52: /* members */ | |
144 g_string_append_printf(members, "%s\n", pair->value); | |
145 break; | |
146 case 58: | |
7827 | 147 msg = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 148 break; |
149 case 13: /* ? */ | |
150 break; | |
151 } | |
152 } | |
153 | |
154 if (!room) { | |
155 g_string_free(members, TRUE); | |
156 return; | |
157 } | |
158 | |
159 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
7827 | 160 g_hash_table_replace(components, g_strdup("room"), room); |
6729 | 161 if (msg) |
7827 | 162 g_hash_table_replace(components, g_strdup("topic"), msg); |
6729 | 163 g_hash_table_replace(components, g_strdup("type"), g_strdup("Conference")); |
164 if (members) { | |
165 g_hash_table_replace(components, g_strdup("members"), g_strdup(members->str)); | |
166 } | |
167 serv_got_chat_invite(gc, room, who, msg, components); | |
168 | |
169 g_string_free(members, TRUE); | |
170 } | |
171 | |
172 void yahoo_process_conference_decline(GaimConnection *gc, struct yahoo_packet *pkt) | |
173 { | |
174 GSList *l; | |
175 char *room = NULL; | |
176 char *who = NULL; | |
177 char *msg = NULL; | |
178 | |
179 for (l = pkt->hash; l; l = l->next) { | |
180 struct yahoo_pair *pair = l->data; | |
181 | |
182 switch (pair->key) { | |
183 case 57: | |
7827 | 184 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 185 break; |
186 case 54: | |
187 who = pair->value; | |
188 break; | |
189 case 14: | |
7827 | 190 msg = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 191 break; |
192 } | |
193 } | |
194 | |
195 if (who && room) { | |
196 char *tmp; | |
197 | |
198 tmp = g_strdup_printf(_("%s declined your conference invitation to room \"%s\" because \"%s\"."), | |
199 who, room, msg?msg:""); | |
200 gaim_notify_info(gc, NULL, _("Invitation Rejected"), tmp); | |
201 g_free(tmp); | |
7827 | 202 g_free(room); |
203 if (msg) | |
204 g_free(msg); | |
6729 | 205 } |
206 } | |
207 | |
208 void yahoo_process_conference_logon(GaimConnection *gc, struct yahoo_packet *pkt) | |
209 { | |
210 GSList *l; | |
211 char *room = NULL; | |
212 char *who = NULL; | |
213 GaimConversation *c; | |
214 | |
215 for (l = pkt->hash; l; l = l->next) { | |
216 struct yahoo_pair *pair = l->data; | |
217 | |
218 switch (pair->key) { | |
219 case 57: | |
7827 | 220 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 221 break; |
222 case 53: | |
223 who = pair->value; | |
224 break; | |
225 } | |
226 } | |
227 | |
228 if (who && room) { | |
229 c = yahoo_find_conference(gc, room); | |
230 if (c) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
231 yahoo_chat_add_user(GAIM_CONV_CHAT(c), who, NULL); |
7827 | 232 g_free(room); |
6729 | 233 } |
234 } | |
235 | |
236 void yahoo_process_conference_logoff(GaimConnection *gc, struct yahoo_packet *pkt) | |
237 { | |
238 GSList *l; | |
239 char *room = NULL; | |
240 char *who = NULL; | |
241 GaimConversation *c; | |
242 | |
243 for (l = pkt->hash; l; l = l->next) { | |
244 struct yahoo_pair *pair = l->data; | |
245 | |
246 switch (pair->key) { | |
247 case 57: | |
7827 | 248 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 249 break; |
250 case 56: | |
251 who = pair->value; | |
252 break; | |
253 } | |
254 } | |
255 | |
256 if (who && room) { | |
257 c = yahoo_find_conference(gc, room); | |
258 if (c) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
259 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); |
7827 | 260 g_free(room); |
6729 | 261 } |
262 } | |
263 | |
264 void yahoo_process_conference_message(GaimConnection *gc, struct yahoo_packet *pkt) | |
265 { | |
266 GSList *l; | |
267 char *room = NULL; | |
268 char *who = NULL; | |
269 char *msg = NULL; | |
7827 | 270 char *msg2; |
271 int utf8 = 0; | |
6729 | 272 GaimConversation *c; |
273 | |
274 for (l = pkt->hash; l; l = l->next) { | |
275 struct yahoo_pair *pair = l->data; | |
276 | |
277 switch (pair->key) { | |
278 case 57: | |
7827 | 279 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 280 break; |
281 case 3: | |
282 who = pair->value; | |
283 break; | |
284 case 14: | |
285 msg = pair->value; | |
286 break; | |
7827 | 287 case 97: |
288 utf8 = strtol(pair->value, NULL, 10); | |
289 break; | |
6729 | 290 } |
291 } | |
292 | |
293 if (room && who && msg) { | |
7827 | 294 msg2 = yahoo_string_decode(gc, msg, utf8); |
6729 | 295 c = yahoo_find_conference(gc, room); |
296 if (!c) | |
297 return; | |
7827 | 298 msg = yahoo_codes_to_html(msg2); |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
299 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), who, 0, msg, time(NULL)); |
6729 | 300 g_free(msg); |
7827 | 301 g_free(msg2); |
6729 | 302 } |
7827 | 303 if (room) |
304 g_free(room); | |
6729 | 305 } |
306 | |
307 | |
308 /* this is a comfirmation of yahoo_chat_online(); */ | |
309 void yahoo_process_chat_online(GaimConnection *gc, struct yahoo_packet *pkt) | |
310 { | |
311 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
312 | |
313 if (pkt->status == 1) | |
314 yd->chat_online = 1; | |
315 } | |
316 | |
317 /* this is basicly the opposite of chat_online */ | |
318 void yahoo_process_chat_logout(GaimConnection *gc, struct yahoo_packet *pkt) | |
319 { | |
320 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
7186 | 321 GSList *l; |
7827 | 322 |
7186 | 323 for (l = pkt->hash; l; l = l->next) { |
324 struct yahoo_pair *pair = l->data; | |
6729 | 325 |
7186 | 326 if (pair->key == 1) |
327 if (g_ascii_strcasecmp(pair->value, | |
328 gaim_connection_get_display_name(gc))) | |
329 return; | |
330 } | |
7827 | 331 |
7186 | 332 if (pkt->status == 1) { |
6729 | 333 yd->chat_online = 0; |
7186 | 334 if (yd->in_chat) |
335 yahoo_c_leave(gc, YAHOO_CHAT_ID); | |
336 } | |
6729 | 337 } |
338 | |
339 void yahoo_process_chat_join(GaimConnection *gc, struct yahoo_packet *pkt) | |
340 { | |
341 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
342 GaimConversation *c = NULL; | |
343 GSList *l; | |
344 GList *members = NULL; | |
345 char *room = NULL; | |
346 char *topic = NULL; | |
347 char *someid, *someotherid, *somebase64orhashosomething, *somenegativenumber; | |
348 | |
349 if (pkt->status == -1) { | |
350 gaim_notify_error(gc, NULL, _("Failed to join chat"), _("Maybe the room is full?")); | |
351 return; | |
352 } | |
353 | |
354 for (l = pkt->hash; l; l = l->next) { | |
355 struct yahoo_pair *pair = l->data; | |
356 | |
357 switch (pair->key) { | |
358 | |
359 case 104: | |
7827 | 360 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 361 break; |
362 case 105: | |
7827 | 363 topic = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 364 break; |
365 case 128: | |
366 someid = pair->value; | |
367 break; | |
368 case 108: /* number of joiners */ | |
369 break; | |
370 case 129: | |
371 someotherid = pair->value; | |
372 break; | |
373 case 130: | |
374 somebase64orhashosomething = pair->value; | |
375 break; | |
376 case 126: | |
377 somenegativenumber = pair->value; | |
378 break; | |
379 case 13: /* this is 1. maybe its the type of room? (normal, user created, private, etc?) */ | |
380 break; | |
381 case 61: /*this looks similiar to 130 */ | |
382 break; | |
383 | |
384 /* the previous section was just room info. this next section is | |
385 info about individual room members, (including us) */ | |
386 | |
387 case 109: /* the yahoo id */ | |
388 members = g_list_append(members, pair->value); | |
389 break; | |
390 case 110: /* age */ | |
391 break; | |
392 case 141: /* nickname */ | |
393 break; | |
394 case 142: /* location */ | |
395 break; | |
396 case 113: /* bitmask */ | |
397 break; | |
398 } | |
399 } | |
400 | |
401 if (!room) | |
402 return; | |
403 | |
404 if (yd->chat_name && gaim_utf8_strcasecmp(room, yd->chat_name)) | |
7186 | 405 yahoo_chat_leave(gc, room, |
406 gaim_connection_get_display_name(gc), FALSE); | |
6729 | 407 |
408 c = gaim_find_chat(gc, YAHOO_CHAT_ID); | |
409 | |
7186 | 410 if (!c && members && ((g_list_length(members) > 1) || |
411 !g_ascii_strcasecmp(members->data, | |
412 gaim_connection_get_display_name(gc)))) { | |
6729 | 413 c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); |
414 if (topic) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
415 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); |
6729 | 416 yd->in_chat = 1; |
417 yd->chat_name = g_strdup(room); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
418 gaim_conv_chat_add_users(GAIM_CONV_CHAT(c), members); |
7186 | 419 } else if (c) { |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
420 yahoo_chat_add_users(GAIM_CONV_CHAT(c), members); |
6729 | 421 } |
422 | |
423 g_list_free(members); | |
7827 | 424 g_free(room); |
425 if (topic) | |
426 g_free(topic); | |
6729 | 427 } |
428 | |
429 void yahoo_process_chat_exit(GaimConnection *gc, struct yahoo_packet *pkt) | |
430 { | |
431 char *who = NULL; | |
7186 | 432 char *room = NULL; |
6729 | 433 GSList *l; |
434 struct yahoo_data *yd; | |
435 | |
436 yd = gc->proto_data; | |
437 | |
438 for (l = pkt->hash; l; l = l->next) { | |
439 struct yahoo_pair *pair = l->data; | |
440 | |
7186 | 441 if (pair->key == 104) |
7827 | 442 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 443 if (pair->key == 109) |
444 who = pair->value; | |
445 } | |
446 | |
447 | |
7186 | 448 if (who && room) { |
6729 | 449 GaimConversation *c = gaim_find_chat(gc, YAHOO_CHAT_ID); |
7186 | 450 if (c && !gaim_utf8_strcasecmp(gaim_conversation_get_name(c), room)) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
451 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); |
6729 | 452 |
453 } | |
7827 | 454 if (room) |
455 g_free(room); | |
6729 | 456 } |
457 | |
458 void yahoo_process_chat_message(GaimConnection *gc, struct yahoo_packet *pkt) | |
459 { | |
7827 | 460 char *room = NULL, *who = NULL, *msg = NULL, *msg2; |
461 int msgtype = 1, utf8 = 0; | |
6729 | 462 GaimConversation *c = NULL; |
463 GSList *l; | |
464 | |
465 for (l = pkt->hash; l; l = l->next) { | |
466 struct yahoo_pair *pair = l->data; | |
467 | |
468 switch (pair->key) { | |
469 | |
7827 | 470 case 97: |
471 utf8 = strtol(pair->value, NULL, 10); | |
472 break; | |
6729 | 473 case 104: |
7827 | 474 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 475 break; |
476 case 109: | |
477 who = pair->value; | |
478 break; | |
479 case 117: | |
480 msg = pair->value; | |
481 break; | |
482 case 124: | |
483 msgtype = strtol(pair->value, NULL, 10); | |
484 break; | |
485 } | |
486 } | |
487 | |
488 | |
489 c = gaim_find_chat(gc, YAHOO_CHAT_ID); | |
7827 | 490 if (!who || !c) { |
491 if (room) | |
492 g_free(room); | |
6729 | 493 /* we still get messages after we part, funny that */ |
494 return; | |
495 } | |
496 | |
497 if (!msg) { | |
498 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Got a message packet with no message.\nThis probably means something important, but we're ignoring it.\n"); | |
499 return; | |
500 } | |
7827 | 501 msg2 = yahoo_string_decode(gc, msg, utf8); |
502 msg = yahoo_codes_to_html(msg2); | |
503 g_free(msg2); | |
6729 | 504 |
505 if (msgtype == 2 || msgtype == 3) { | |
506 char *tmp; | |
507 tmp = g_strdup_printf("/me %s", msg); | |
508 g_free(msg); | |
509 msg = tmp; | |
510 } | |
511 | |
512 serv_got_chat_in(gc, YAHOO_CHAT_ID, who, 0, msg, time(NULL)); | |
513 g_free(msg); | |
514 } | |
515 | |
516 void yahoo_process_chat_addinvite(GaimConnection *gc, struct yahoo_packet *pkt) | |
517 { | |
518 GSList *l; | |
519 char *room = NULL; | |
520 char *msg = NULL; | |
521 char *who = NULL; | |
522 | |
523 | |
524 for (l = pkt->hash; l; l = l->next) { | |
525 struct yahoo_pair *pair = l->data; | |
526 | |
527 switch (pair->key) { | |
528 case 104: | |
7827 | 529 room = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 530 break; |
531 case 129: /* room id? */ | |
532 break; | |
533 case 126: /* ??? */ | |
534 break; | |
535 case 117: | |
7827 | 536 msg = yahoo_string_decode(gc, pair->value, FALSE); |
6729 | 537 break; |
538 case 119: | |
539 who = pair->value; | |
540 break; | |
541 case 118: /* us */ | |
542 break; | |
543 } | |
544 } | |
545 | |
546 if (room && who) { | |
547 GHashTable *components; | |
548 | |
549 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
550 g_hash_table_replace(components, g_strdup("room"), g_strdup(room)); | |
551 serv_got_chat_invite(gc, room, who, msg, components); | |
552 } | |
7827 | 553 if (room) |
554 g_free(room); | |
555 if (msg) | |
556 g_free(msg); | |
6729 | 557 } |
558 | |
559 void yahoo_process_chat_goto(GaimConnection *gc, struct yahoo_packet *pkt) | |
560 { | |
561 if (pkt->status == -1) | |
562 gaim_notify_error(gc, NULL, _("Failed to join buddy in chat"), | |
563 _("Maybe they're not in a chat?")); | |
564 } | |
565 | |
566 | |
567 /* | |
568 * Functions dealing with conferences | |
7827 | 569 * I think conference names are always ascii. |
6729 | 570 */ |
571 | |
572 static void yahoo_conf_leave(struct yahoo_data *yd, const char *room, const char *dn, GList *who) | |
573 { | |
574 struct yahoo_packet *pkt; | |
575 GList *w; | |
576 | |
577 | |
578 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGOFF, YAHOO_STATUS_AVAILABLE, 0); | |
579 | |
580 yahoo_packet_hash(pkt, 1, dn); | |
581 for (w = who; w; w = w->next) { | |
582 yahoo_packet_hash(pkt, 3, (char *)w->data); | |
583 } | |
584 | |
585 yahoo_packet_hash(pkt, 57, room); | |
586 | |
587 yahoo_send_packet(yd, pkt); | |
588 | |
589 yahoo_packet_free(pkt); | |
590 } | |
591 | |
7827 | 592 static int yahoo_conf_send(GaimConnection *gc, const char *dn, const char *room, |
6729 | 593 GList *members, const char *what) |
594 { | |
7827 | 595 struct yahoo_data *yd = gc->proto_data; |
6729 | 596 struct yahoo_packet *pkt; |
597 GList *who; | |
7827 | 598 char *msg, *msg2; |
599 int utf8 = 1; | |
6804 | 600 |
601 msg = yahoo_html_to_codes(what); | |
7827 | 602 msg2 = yahoo_string_encode(gc, msg, &utf8); |
603 | |
6729 | 604 |
605 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFMSG, YAHOO_STATUS_AVAILABLE, 0); | |
606 | |
607 yahoo_packet_hash(pkt, 1, dn); | |
608 for (who = members; who; who = who->next) | |
609 yahoo_packet_hash(pkt, 53, (char *)who->data); | |
610 yahoo_packet_hash(pkt, 57, room); | |
7827 | 611 yahoo_packet_hash(pkt, 14, msg2); |
612 if (utf8) | |
613 yahoo_packet_hash(pkt, 97, "1"); /* utf-8 */ | |
6729 | 614 |
615 yahoo_send_packet(yd, pkt); | |
616 | |
617 yahoo_packet_free(pkt); | |
6804 | 618 g_free(msg); |
7827 | 619 g_free(msg2); |
6729 | 620 |
621 return 0; | |
622 } | |
623 | |
624 static void yahoo_conf_join(struct yahoo_data *yd, GaimConversation *c, const char *dn, const char *room, | |
625 const char *topic, const char *members) | |
626 { | |
627 struct yahoo_packet *pkt; | |
628 char **memarr = NULL; | |
629 int i; | |
630 | |
631 if (members) | |
632 memarr = g_strsplit(members, "\n", 0); | |
633 | |
634 | |
635 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFLOGON, YAHOO_STATUS_AVAILABLE, 0); | |
636 | |
637 yahoo_packet_hash(pkt, 1, dn); | |
638 yahoo_packet_hash(pkt, 3, dn); | |
639 yahoo_packet_hash(pkt, 57, room); | |
640 if (memarr) { | |
641 for(i = 0 ; memarr[i]; i++) { | |
642 if (!strcmp(memarr[i], "") || !strcmp(memarr[i], dn)) | |
643 continue; | |
644 yahoo_packet_hash(pkt, 3, memarr[i]); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
645 gaim_conv_chat_add_user(GAIM_CONV_CHAT(c), memarr[i], NULL); |
6729 | 646 } |
647 } | |
648 yahoo_send_packet(yd, pkt); | |
649 | |
650 yahoo_packet_free(pkt); | |
651 | |
652 if (memarr) | |
653 g_strfreev(memarr); | |
654 } | |
655 | |
7827 | 656 static void yahoo_conf_invite(GaimConnection *gc, GaimConversation *c, |
6729 | 657 const char *dn, const char *buddy, const char *room, const char *msg) |
658 { | |
7827 | 659 struct yahoo_data *yd = gc->proto_data; |
6729 | 660 struct yahoo_packet *pkt; |
661 GList *members; | |
7827 | 662 char *msg2 = NULL; |
663 | |
664 if (msg) | |
665 msg2 = yahoo_string_encode(gc, msg, NULL); | |
6729 | 666 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
667 members = gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)); |
6729 | 668 |
669 pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE, YAHOO_STATUS_AVAILABLE, 0); | |
670 | |
671 yahoo_packet_hash(pkt, 1, dn); | |
672 yahoo_packet_hash(pkt, 51, buddy); | |
673 yahoo_packet_hash(pkt, 57, room); | |
7827 | 674 yahoo_packet_hash(pkt, 58, msg?msg2:""); |
6729 | 675 yahoo_packet_hash(pkt, 13, "0"); |
676 for(; members; members = members->next) { | |
677 if (!strcmp(members->data, dn)) | |
678 continue; | |
679 yahoo_packet_hash(pkt, 52, (char *)members->data); | |
680 yahoo_packet_hash(pkt, 53, (char *)members->data); | |
681 } | |
682 yahoo_send_packet(yd, pkt); | |
683 | |
684 yahoo_packet_free(pkt); | |
7827 | 685 if (msg) |
686 g_free(msg2); | |
6729 | 687 } |
688 | |
689 /* | |
690 * Functions dealing with chats | |
691 */ | |
692 | |
7186 | 693 static void yahoo_chat_leave(GaimConnection *gc, const char *room, const char *dn, gboolean logout) |
6729 | 694 { |
7186 | 695 struct yahoo_data *yd = gc->proto_data; |
6729 | 696 struct yahoo_packet *pkt; |
7186 | 697 GaimConversation *c; |
7827 | 698 char *eroom; |
699 | |
700 eroom = yahoo_string_encode(gc, room, NULL); | |
6729 | 701 |
702 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATEXIT, YAHOO_STATUS_AVAILABLE, 0); | |
703 | |
7827 | 704 yahoo_packet_hash(pkt, 104, eroom); |
6729 | 705 yahoo_packet_hash(pkt, 109, dn); |
706 yahoo_packet_hash(pkt, 108, "1"); | |
707 yahoo_packet_hash(pkt, 112, "0"); /* what does this one mean? */ | |
708 | |
709 yahoo_send_packet(yd, pkt); | |
710 | |
711 yahoo_packet_free(pkt); | |
712 | |
713 yd->in_chat = 0; | |
714 if (yd->chat_name) { | |
715 g_free(yd->chat_name); | |
716 yd->chat_name = NULL; | |
717 } | |
718 | |
7186 | 719 if ((c = gaim_find_chat(gc, YAHOO_CHAT_ID))) |
720 serv_got_chat_left(gc, YAHOO_CHAT_ID); | |
721 | |
722 if (!logout) | |
723 return; | |
724 | |
725 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATLOGOUT, | |
726 YAHOO_STATUS_AVAILABLE, 0); | |
727 yahoo_packet_hash(pkt, 1, dn); | |
728 yahoo_send_packet(yd, pkt); | |
729 yahoo_packet_free(pkt); | |
730 | |
731 yd->chat_online = 0; | |
7827 | 732 g_free(eroom); |
6729 | 733 } |
734 | |
6804 | 735 /* borrowed from gtkconv.c */ |
736 static gboolean | |
737 meify(char *message, size_t len) | |
738 { | |
739 /* | |
740 * Read /me-ify: If the message (post-HTML) starts with /me, | |
741 * remove the "/me " part of it (including that space) and return TRUE. | |
742 */ | |
743 char *c; | |
744 gboolean inside_html = 0; | |
745 | |
746 /* Umm.. this would be very bad if this happens. */ | |
747 g_return_val_if_fail(message != NULL, FALSE); | |
748 | |
749 if (len == -1) | |
750 len = strlen(message); | |
751 | |
752 for (c = message; *c != '\0'; c++, len--) { | |
753 if (inside_html) { | |
754 if (*c == '>') | |
755 inside_html = FALSE; | |
756 } | |
757 else { | |
758 if (*c == '<') | |
759 inside_html = TRUE; | |
760 else | |
761 break; | |
762 } | |
763 } | |
764 | |
765 if (*c != '\0' && !g_ascii_strncasecmp(c, "/me ", 4)) { | |
766 memmove(c, c + 4, len - 3); | |
767 | |
768 return TRUE; | |
769 } | |
770 | |
771 return FALSE; | |
772 } | |
773 | |
7827 | 774 static int yahoo_chat_send(GaimConnection *gc, const char *dn, const char *room, const char *what) |
6729 | 775 { |
7827 | 776 struct yahoo_data *yd = gc->proto_data; |
6729 | 777 struct yahoo_packet *pkt; |
778 int me = 0; | |
7827 | 779 char *msg1, *msg2, *room2; |
780 gboolean utf8 = TRUE; | |
6804 | 781 |
782 msg1 = g_strdup(what); | |
6729 | 783 |
6804 | 784 if (meify(msg1, -1)) |
6729 | 785 me = 1; |
6804 | 786 |
787 msg2 = yahoo_html_to_codes(msg1); | |
788 g_free(msg1); | |
7827 | 789 msg1 = yahoo_string_encode(gc, msg2, &utf8); |
790 g_free(msg2); | |
791 room2 = yahoo_string_encode(gc, room, NULL); | |
6729 | 792 |
793 pkt = yahoo_packet_new(YAHOO_SERVICE_COMMENT, YAHOO_STATUS_AVAILABLE, 0); | |
794 | |
795 yahoo_packet_hash(pkt, 1, dn); | |
7827 | 796 yahoo_packet_hash(pkt, 104, room2); |
797 yahoo_packet_hash(pkt, 117, msg1); | |
6729 | 798 if (me) |
799 yahoo_packet_hash(pkt, 124, "2"); | |
800 else | |
801 yahoo_packet_hash(pkt, 124, "1"); | |
802 /* fixme: what about /think? (124=3) */ | |
7827 | 803 if (utf8) |
804 yahoo_packet_hash(pkt, 97, "1"); | |
6729 | 805 |
806 yahoo_send_packet(yd, pkt); | |
807 yahoo_packet_free(pkt); | |
7827 | 808 g_free(msg1); |
809 g_free(room2); | |
6729 | 810 |
811 return 0; | |
812 } | |
813 | |
7827 | 814 static void yahoo_chat_join(GaimConnection *gc, const char *dn, const char *room, const char *topic) |
6729 | 815 { |
7827 | 816 struct yahoo_data *yd = gc->proto_data; |
6729 | 817 struct yahoo_packet *pkt; |
7827 | 818 char *room2; |
819 | |
820 room2 = yahoo_string_encode(gc, room, NULL); | |
6729 | 821 |
822 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATJOIN, YAHOO_STATUS_AVAILABLE, 0); | |
823 | |
7868 | 824 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
6729 | 825 yahoo_packet_hash(pkt, 62, "2"); |
7827 | 826 yahoo_packet_hash(pkt, 104, room2); |
6729 | 827 yahoo_packet_hash(pkt, 129, "0"); |
828 | |
829 yahoo_send_packet(yd, pkt); | |
830 | |
831 yahoo_packet_free(pkt); | |
7827 | 832 g_free(room2); |
6729 | 833 } |
834 | |
7827 | 835 static void yahoo_chat_invite(GaimConnection *gc, const char *dn, const char *buddy, |
6729 | 836 const char *room, const char *msg) |
837 { | |
7827 | 838 struct yahoo_data *yd = gc->proto_data; |
6729 | 839 struct yahoo_packet *pkt; |
7827 | 840 char *room2, *msg2 = NULL; |
6729 | 841 |
7827 | 842 room2 = yahoo_string_encode(gc, room, NULL); |
843 if (msg) | |
844 msg2 = yahoo_string_encode(gc, msg, NULL); | |
6729 | 845 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATADDINVITE, YAHOO_STATUS_AVAILABLE, 0); |
846 | |
847 yahoo_packet_hash(pkt, 1, dn); | |
848 yahoo_packet_hash(pkt, 118, buddy); | |
7827 | 849 yahoo_packet_hash(pkt, 104, room2); |
850 yahoo_packet_hash(pkt, 117, (msg2?msg2:"")); | |
6729 | 851 yahoo_packet_hash(pkt, 129, "0"); |
852 | |
853 yahoo_send_packet(yd, pkt); | |
854 yahoo_packet_free(pkt); | |
7827 | 855 |
856 g_free(room2); | |
857 if (msg2) | |
858 g_free(msg2); | |
6729 | 859 } |
860 | |
861 void yahoo_chat_goto(GaimConnection *gc, const char *name) | |
862 { | |
863 struct yahoo_data *yd; | |
864 struct yahoo_packet *pkt; | |
865 | |
866 yd = gc->proto_data; | |
867 | |
868 if (!yd->chat_online) | |
869 yahoo_chat_online(gc); | |
870 | |
871 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATGOTO, YAHOO_STATUS_AVAILABLE, 0); | |
872 | |
873 yahoo_packet_hash(pkt, 109, name); | |
874 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | |
875 yahoo_packet_hash(pkt, 62, "2"); | |
876 | |
877 yahoo_send_packet(yd, pkt); | |
878 yahoo_packet_free(pkt); | |
879 } | |
880 /* | |
881 * These are the functions registered with the core | |
882 * which get called for both chats and conferences. | |
883 */ | |
884 | |
885 void yahoo_c_leave(GaimConnection *gc, int id) | |
886 { | |
887 struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; | |
888 GaimConversation *c; | |
889 | |
890 if (!yd) | |
891 return; | |
892 | |
893 | |
894 c = gaim_find_chat(gc, id); | |
895 if (!c) | |
896 return; | |
897 | |
898 if (id != YAHOO_CHAT_ID) { | |
899 yahoo_conf_leave(yd, gaim_conversation_get_name(c), | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
900 gaim_connection_get_display_name(gc), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c))); |
6729 | 901 yd->confs = g_slist_remove(yd->confs, c); |
902 } else { | |
7186 | 903 yahoo_chat_leave(gc, gaim_conversation_get_name(c), gaim_connection_get_display_name(gc), TRUE); |
6729 | 904 } |
905 | |
906 serv_got_chat_left(gc, id); | |
907 } | |
908 | |
909 int yahoo_c_send(GaimConnection *gc, int id, const char *what) | |
910 { | |
911 GaimConversation *c; | |
912 int ret; | |
913 struct yahoo_data *yd; | |
914 | |
915 yd = (struct yahoo_data *) gc->proto_data; | |
916 if (!yd) | |
917 return -1; | |
918 | |
919 c = gaim_find_chat(gc, id); | |
920 if (!c) | |
921 return -1; | |
922 | |
923 if (id != YAHOO_CHAT_ID) { | |
7827 | 924 ret = yahoo_conf_send(gc, gaim_connection_get_display_name(gc), |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
925 gaim_conversation_get_name(c), gaim_conv_chat_get_users(GAIM_CONV_CHAT(c)), what); |
6729 | 926 } else { |
7827 | 927 ret = yahoo_chat_send(gc, gaim_connection_get_display_name(gc), |
6804 | 928 gaim_conversation_get_name(c), what); |
6729 | 929 if (!ret) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
930 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(c)), |
6729 | 931 gaim_connection_get_display_name(gc), 0, what, time(NULL)); |
932 } | |
933 return ret; | |
934 } | |
935 | |
936 GList *yahoo_c_info(GaimConnection *gc) | |
937 { | |
938 GList *m = NULL; | |
939 struct proto_chat_entry *pce; | |
940 | |
941 pce = g_new0(struct proto_chat_entry, 1); | |
7841 | 942 pce->label = _("_Room:"); |
6729 | 943 pce->identifier = "room"; |
944 m = g_list_append(m, pce); | |
945 | |
946 return m; | |
947 } | |
948 | |
949 void yahoo_c_join(GaimConnection *gc, GHashTable *data) | |
950 { | |
951 struct yahoo_data *yd; | |
952 char *room, *topic, *members, *type; | |
953 int id; | |
954 GaimConversation *c; | |
955 | |
956 yd = (struct yahoo_data *) gc->proto_data; | |
957 if (!yd) | |
958 return; | |
959 | |
960 room = g_hash_table_lookup(data, "room"); | |
961 if (!room) | |
962 return; | |
963 | |
964 topic = g_hash_table_lookup(data, "topic"); | |
965 if (!topic) | |
966 topic = ""; | |
967 | |
968 members = g_hash_table_lookup(data, "members"); | |
969 | |
970 | |
971 if ((type = g_hash_table_lookup(data, "type")) && !strcmp(type, "Conference")) { | |
972 id = yd->conf_id++; | |
973 c = serv_got_joined_chat(gc, id, room); | |
974 yd->confs = g_slist_prepend(yd->confs, c); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6804
diff
changeset
|
975 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), gaim_connection_get_display_name(gc), topic); |
6729 | 976 yahoo_conf_join(yd, c, gaim_connection_get_display_name(gc), room, topic, members); |
977 return; | |
978 } else { | |
979 if (yd->in_chat) | |
7186 | 980 yahoo_chat_leave(gc, room, |
981 gaim_connection_get_display_name(gc), | |
982 FALSE); | |
6729 | 983 if (!yd->chat_online) |
984 yahoo_chat_online(gc); | |
7827 | 985 yahoo_chat_join(gc, gaim_connection_get_display_name(gc), room, topic); |
6729 | 986 return; |
987 } | |
988 } | |
989 | |
990 void yahoo_c_invite(GaimConnection *gc, int id, const char *msg, const char *name) | |
991 { | |
992 GaimConversation *c; | |
993 | |
994 c = gaim_find_chat(gc, id); | |
995 if (!c || !c->name) | |
996 return; | |
997 | |
998 if (id != YAHOO_CHAT_ID) { | |
7827 | 999 yahoo_conf_invite(gc, c, gaim_connection_get_display_name(gc), name, |
6729 | 1000 gaim_conversation_get_name(c), msg); |
1001 } else { | |
7827 | 1002 yahoo_chat_invite(gc, gaim_connection_get_display_name(gc), name, |
6729 | 1003 gaim_conversation_get_name(c), msg); |
1004 } | |
1005 } | |
1006 |