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