-
Notifications
You must be signed in to change notification settings - Fork 0
/
libymsg.c
5513 lines (4763 loc) · 159 KB
/
libymsg.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.
*
* 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
*
*/
/*
* Note: When handling the list of struct yahoo_pair's from an incoming
* packet the value might not be UTF-8. You should either validate that
* it is UTF-8 using g_utf8_validate() or use yahoo_string_decode().
*/
#include "internal.h"
#include "account.h"
#include "accountopt.h"
#include "blist.h"
#include "cipher.h"
#include "cmds.h"
#include "core.h"
#include "debug.h"
#include "network.h"
#include "notify.h"
#include "privacy.h"
#include "prpl.h"
#include "proxy.h"
#include "request.h"
#include "server.h"
#include "util.h"
#include "version.h"
#include "xmlnode.h"
#include "libymsg.h"
#include "yahoochat.h"
#include "yahoo_aliases.h"
#include "yahoo_doodle.h"
#include "yahoo_filexfer.h"
#include "yahoo_friend.h"
#include "yahoo_packet.h"
#include "yahoo_picture.h"
#include "ycht.h"
/* #define YAHOO_DEBUG */
/* #define TRY_WEBMESSENGER_LOGIN 0 */
/* One hour */
#define PING_TIMEOUT 3600
/* One minute */
#define KEEPALIVE_TIMEOUT 60
#ifdef TRY_WEBMESSENGER_LOGIN
static void yahoo_login_page_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message);
#endif /* TRY_WEBMESSENGER_LOGIN */
static gboolean yahoo_is_japan(PurpleAccount *account)
{
return purple_strequal(purple_account_get_protocol_id(account), "prpl-yahoojp");
}
static void yahoo_update_status(PurpleConnection *gc, const char *name, YahooFriend *f)
{
char *status = NULL;
if (!gc || !name || !f || !purple_find_buddy(purple_connection_get_account(gc), name))
return;
switch (f->status) {
case YAHOO_STATUS_OFFLINE:
status = YAHOO_STATUS_TYPE_OFFLINE;
break;
case YAHOO_STATUS_AVAILABLE:
status = YAHOO_STATUS_TYPE_AVAILABLE;
break;
case YAHOO_STATUS_BRB:
status = YAHOO_STATUS_TYPE_BRB;
break;
case YAHOO_STATUS_BUSY:
status = YAHOO_STATUS_TYPE_BUSY;
break;
case YAHOO_STATUS_NOTATHOME:
status = YAHOO_STATUS_TYPE_NOTATHOME;
break;
case YAHOO_STATUS_NOTATDESK:
status = YAHOO_STATUS_TYPE_NOTATDESK;
break;
case YAHOO_STATUS_NOTINOFFICE:
status = YAHOO_STATUS_TYPE_NOTINOFFICE;
break;
case YAHOO_STATUS_ONPHONE:
status = YAHOO_STATUS_TYPE_ONPHONE;
break;
case YAHOO_STATUS_ONVACATION:
status = YAHOO_STATUS_TYPE_ONVACATION;
break;
case YAHOO_STATUS_OUTTOLUNCH:
status = YAHOO_STATUS_TYPE_OUTTOLUNCH;
break;
case YAHOO_STATUS_STEPPEDOUT:
status = YAHOO_STATUS_TYPE_STEPPEDOUT;
break;
case YAHOO_STATUS_INVISIBLE: /* this should never happen? */
status = YAHOO_STATUS_TYPE_INVISIBLE;
break;
case YAHOO_STATUS_CUSTOM:
case YAHOO_STATUS_IDLE:
if (!f->away)
status = YAHOO_STATUS_TYPE_AVAILABLE;
else
status = YAHOO_STATUS_TYPE_AWAY;
break;
default:
purple_debug_warning("yahoo", "Warning, unknown status %d\n", f->status);
break;
}
if (status) {
if (f->status == YAHOO_STATUS_CUSTOM)
purple_prpl_got_user_status(purple_connection_get_account(gc), name, status, "message",
yahoo_friend_get_status_message(f), NULL);
else
purple_prpl_got_user_status(purple_connection_get_account(gc), name, status, NULL);
}
if (f->idle != 0)
purple_prpl_got_user_idle(purple_connection_get_account(gc), name, TRUE, f->idle);
else
purple_prpl_got_user_idle(purple_connection_get_account(gc), name, FALSE, 0);
if (f->sms)
purple_prpl_got_user_status(purple_connection_get_account(gc), name, YAHOO_STATUS_TYPE_MOBILE, NULL);
else
purple_prpl_got_user_status_deactive(purple_connection_get_account(gc), name, YAHOO_STATUS_TYPE_MOBILE);
}
static void yahoo_process_status(PurpleConnection *gc, struct yahoo_packet *pkt)
{
PurpleAccount *account = purple_connection_get_account(gc);
GSList *l = pkt->hash;
YahooFriend *f = NULL;
char *name = NULL;
gboolean unicode = FALSE;
char *message = NULL;
YahooFederation fed = YAHOO_FEDERATION_NONE;
char *fedname = NULL;
if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) {
if (!purple_account_get_remember_password(account))
purple_account_set_password(account, NULL);
purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NAME_IN_USE,
_("You have signed on from another location"));
return;
}
while (l) {
struct yahoo_pair *pair = l->data;
switch (pair->key) {
case 0: /* we won't actually do anything with this */
case 1: /* we won't actually do anything with this */
break;
case 8: /* how many online buddies we have */
break;
case 7: /* the current buddy */
/* update the previous buddy before changing the variables */
if (f) {
if (message)
yahoo_friend_set_status_message(f, yahoo_string_decode(gc, message, unicode));
if (name)
yahoo_update_status(gc, name, f);
}
name = message = NULL;
f = NULL;
if (pair->value && g_utf8_validate(pair->value, -1, NULL)) {
GSList *tmplist;
name = pair->value;
/* Look ahead to see if we have the federation info about the buddy */
for (tmplist = l->next; tmplist; tmplist = tmplist->next) {
struct yahoo_pair *p = tmplist->data;
if (p->key == 7)
break;
if (p->key == 241) {
fed = strtol(p->value, NULL, 10);
g_free(fedname);
switch (fed) {
case YAHOO_FEDERATION_MSN:
name = fedname = g_strconcat("msn/", name, NULL);
break;
case YAHOO_FEDERATION_OCS:
name = fedname = g_strconcat("ocs/", name, NULL);
break;
case YAHOO_FEDERATION_IBM:
name = fedname = g_strconcat("ibm/", name, NULL);
break;
case YAHOO_FEDERATION_NONE:
default:
fedname = NULL;
break;
}
break;
}
}
f = yahoo_friend_find_or_new(gc, name);
f->fed = fed;
}
break;
case 10: /* state */
if (!f)
break;
f->status = strtol(pair->value, NULL, 10);
if ((f->status >= YAHOO_STATUS_BRB) && (f->status <= YAHOO_STATUS_STEPPEDOUT))
f->away = 1;
else
f->away = 0;
if (f->status == YAHOO_STATUS_IDLE) {
/* Idle may have already been set in a more precise way in case 137 */
if (f->idle == 0)
{
if(pkt->service == YAHOO_SERVICE_STATUS_15)
f->idle = -1;
else
f->idle = time(NULL);
}
} else
f->idle = 0;
if (f->status != YAHOO_STATUS_CUSTOM)
yahoo_friend_set_status_message(f, NULL);
f->sms = 0;
break;
case 19: /* custom message */
if (f)
message = pair->value;
break;
case 11: /* this is the buddy's session id */
if (f)
f->session_id = strtol(pair->value, NULL, 10);
break;
case 17: /* in chat? */
break;
case 47: /* is custom status away or not? 2=idle*/
if (!f)
break;
/* I have no idea what it means when this is
* set when someone's available, but it doesn't
* mean idle. */
if (f->status == YAHOO_STATUS_AVAILABLE)
break;
f->away = strtol(pair->value, NULL, 10);
if (f->away == 2) {
/* Idle may have already been set in a more precise way in case 137 */
if (f->idle == 0)
{
if(pkt->service == YAHOO_SERVICE_STATUS_15)
f->idle = -1;
else
f->idle = time(NULL);
}
}
break;
case 138: /* when value is 1, either we're not idle, or we are but won't say how long */
if (!f)
break;
if( (strtol(pair->value, NULL, 10) == 1) && (f->idle) )
f->idle = -1;
break;
case 137: /* usually idle time in seconds, sometimes login time */
if (!f)
break;
if (f->status != YAHOO_STATUS_AVAILABLE)
f->idle = time(NULL) - strtol(pair->value, NULL, 10);
break;
case 13: /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */
if (strtol(pair->value, NULL, 10) == 0) {
if (f)
f->status = YAHOO_STATUS_OFFLINE;
if (name) {
purple_prpl_got_user_status(account, name, "offline", NULL);
purple_prpl_got_user_status_deactive(account, name, YAHOO_STATUS_TYPE_MOBILE);
}
break;
}
break;
case 60: /* SMS */
if (f) {
f->sms = strtol(pair->value, NULL, 10);
yahoo_update_status(gc, name, f);
}
break;
case 197: /* Avatars */
{
guchar *decoded;
char *tmp;
gsize len;
if (pair->value) {
decoded = purple_base64_decode(pair->value, &len);
if (decoded && len > 0) {
tmp = purple_str_binary_to_ascii(decoded, len);
purple_debug_info("yahoo", "Got key 197, value = %s\n", tmp);
g_free(tmp);
}
g_free(decoded);
}
break;
}
case 192: /* Pictures, aka Buddy Icons, checksum */
{
/* FIXME: Please, if you know this protocol,
* FIXME: fix up the strtol() stuff if possible. */
int cksum = strtol(pair->value, NULL, 10);
const char *locksum = NULL;
PurpleBuddy *b;
if (!name)
break;
b = purple_find_buddy(gc->account, name);
if (!cksum || (cksum == -1)) {
if (f)
yahoo_friend_set_buddy_icon_need_request(f, TRUE);
purple_buddy_icons_set_for_user(gc->account, name, NULL, 0, NULL);
break;
}
if (!f)
break;
yahoo_friend_set_buddy_icon_need_request(f, FALSE);
if (b) {
locksum = purple_buddy_icons_get_checksum_for_user(b);
if (!locksum || (cksum != strtol(locksum, NULL, 10)))
yahoo_send_picture_request(gc, name);
}
break;
}
case 16: /* Custom error message */
{
char *tmp = yahoo_string_decode(gc, pair->value, TRUE);
purple_notify_error(gc, NULL, tmp, NULL);
g_free(tmp);
}
break;
case 97: /* Unicode status message */
unicode = !strcmp(pair->value, "1");
break;
case 244: /* client version number. Yahoo Client Detection */
if(f && strtol(pair->value, NULL, 10))
f->version_id = strtol(pair->value, NULL, 10);
break;
case 241: /* Federated network buddy belongs to */
break; /* We process this when get '7' */
default:
purple_debug_warning("yahoo",
"Unknown status key %d\n", pair->key);
break;
}
l = l->next;
}
if (f) {
if (pkt->service == YAHOO_SERVICE_LOGOFF)
f->status = YAHOO_STATUS_OFFLINE;
if (message)
yahoo_friend_set_status_message(f, yahoo_string_decode(gc, message, unicode));
if (name) /* update the last buddy */
yahoo_update_status(gc, name, f);
}
g_free(fedname);
}
static void yahoo_do_group_check(PurpleAccount *account, GHashTable *ht, const char *name, const char *group)
{
PurpleBuddy *b;
PurpleGroup *g;
GSList *list, *i;
gboolean onlist = FALSE;
char *oname = NULL;
if (g_hash_table_lookup_extended(ht, name, (gpointer *)&oname, (gpointer *)&list))
g_hash_table_steal(ht, oname);
else
list = purple_find_buddies(account, name);
for (i = list; i; i = i->next) {
b = i->data;
g = purple_buddy_get_group(b);
if (!purple_utf8_strcasecmp(group, purple_group_get_name(g))) {
purple_debug_misc("yahoo",
"Oh good, %s is in the right group (%s).\n", name, group);
list = g_slist_delete_link(list, i);
onlist = TRUE;
break;
}
}
if (!onlist) {
purple_debug_misc("yahoo",
"Uhoh, %s isn't on the list (or not in this group), adding him to group %s.\n", name, group);
if (!(g = purple_find_group(group))) {
g = purple_group_new(group);
purple_blist_add_group(g, NULL);
}
b = purple_buddy_new(account, name, NULL);
purple_blist_add_buddy(b, NULL, g, NULL);
}
if (list) {
if (!oname)
oname = g_strdup(name);
g_hash_table_insert(ht, oname, list);
} else
g_free(oname);
}
static void yahoo_do_group_cleanup(gpointer key, gpointer value, gpointer user_data)
{
char *name = key;
GSList *list = value, *i;
PurpleBuddy *b;
PurpleGroup *g;
for (i = list; i; i = i->next) {
b = i->data;
g = purple_buddy_get_group(b);
purple_debug_misc("yahoo", "Deleting Buddy %s from group %s.\n", name,
purple_group_get_name(g));
purple_blist_remove_buddy(b);
}
}
static char *_getcookie(char *rawcookie)
{
char *cookie = NULL;
char *tmpcookie;
char *cookieend;
if (strlen(rawcookie) < 2)
return NULL;
tmpcookie = g_strdup(rawcookie+2);
cookieend = strchr(tmpcookie, ';');
if (cookieend)
*cookieend = '\0';
cookie = g_strdup(tmpcookie);
g_free(tmpcookie);
return cookie;
}
static void yahoo_process_cookie(YahooData *yd, char *c)
{
if (c[0] == 'Y') {
if (yd->cookie_y)
g_free(yd->cookie_y);
yd->cookie_y = _getcookie(c);
} else if (c[0] == 'T') {
if (yd->cookie_t)
g_free(yd->cookie_t);
yd->cookie_t = _getcookie(c);
} else
purple_debug_info("yahoo", "Unrecognized cookie '%c'\n", c[0]);
yd->cookies = g_slist_prepend(yd->cookies, g_strdup(c));
}
static void yahoo_process_list_15(PurpleConnection *gc, struct yahoo_packet *pkt)
{
GSList *l = pkt->hash;
PurpleAccount *account = purple_connection_get_account(gc);
YahooData *yd = gc->proto_data;
GHashTable *ht;
char *norm_bud = NULL;
char *temp = NULL;
YahooFriend *f = NULL; /* It's your friends. They're going to want you to share your StarBursts. */
/* But what if you had no friends? */
YahooFederation fed = YAHOO_FEDERATION_NONE;
int stealth = 0;
ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_slist_free);
while (l) {
struct yahoo_pair *pair = l->data;
l = l->next;
switch (pair->key) {
case 302:
/* This is always 318 before a group, 319 before the first s/n in a group, 320 before any ignored s/n.
* It is not sent for s/n's in a group after the first.
* All ignored s/n's are listed last, so when we see a 320 we clear the group and begin marking the
* s/n's as ignored. It is always followed by an identical 300 key.
*/
if (pair->value && !strcmp(pair->value, "320")) {
/* No longer in any group; this indicates the start of the ignore list. */
g_free(yd->current_list15_grp);
yd->current_list15_grp = NULL;
}
break;
case 301: /* This is 319 before all s/n's in a group after the first. It is followed by an identical 300. */
if(temp != NULL) {
switch (fed) {
case YAHOO_FEDERATION_MSN:
norm_bud = g_strconcat("msn/", temp, NULL);
break;
case YAHOO_FEDERATION_OCS:
norm_bud = g_strconcat("ocs/", temp, NULL);
break;
case YAHOO_FEDERATION_IBM:
norm_bud = g_strconcat("ibm/", temp, NULL);
break;
case YAHOO_FEDERATION_PBX:
norm_bud = g_strconcat("pbx/", temp, NULL);
break;
case YAHOO_FEDERATION_NONE:
norm_bud = g_strdup(temp);
break;
}
if (yd->current_list15_grp) {
/* This buddy is in a group */
f = yahoo_friend_find_or_new(gc, norm_bud);
if (!purple_find_buddy(account, norm_bud)) {
PurpleBuddy *b;
PurpleGroup *g;
if (!(g = purple_find_group(yd->current_list15_grp))) {
g = purple_group_new(yd->current_list15_grp);
purple_blist_add_group(g, NULL);
}
b = purple_buddy_new(account, norm_bud, NULL);
purple_blist_add_buddy(b, NULL, g, NULL);
}
yahoo_do_group_check(account, ht, norm_bud, yd->current_list15_grp);
if(fed) {
f->fed = fed;
purple_debug_info("yahoo", "Setting federation to %d\n", f->fed);
}
if(stealth == 2)
f->presence = YAHOO_PRESENCE_PERM_OFFLINE;
/* set p2p status not connected and no p2p packet sent */
if(fed == YAHOO_FEDERATION_NONE) {
yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_NOT_CONNECTED);
f->p2p_packet_sent = 0;
} else
yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_DO_NOT_CONNECT);
} else {
/* This buddy is on the ignore list (and therefore in no group) */
purple_debug_info("yahoo", "%s adding %s to the deny list because of the ignore list / no group was found\n",account->username, norm_bud);
purple_privacy_deny_add(account, norm_bud, 1);
}
g_free(norm_bud);
norm_bud=NULL;
fed = YAHOO_FEDERATION_NONE;
stealth = 0;
g_free(temp);
temp = NULL;
}
break;
case 300: /* This is 318 before a group, 319 before any s/n in a group, and 320 before any ignored s/n. */
break;
case 65: /* This is the group */
g_free(yd->current_list15_grp);
yd->current_list15_grp = yahoo_string_decode(gc, pair->value, FALSE);
break;
case 7: /* buddy's s/n */
if (g_utf8_validate(pair->value, -1, NULL)) {
g_free(temp);
temp = g_strdup(purple_normalize(account, pair->value));
} else {
purple_debug_warning("yahoo", "yahoo_process_list_15 "
"got non-UTF-8 string for key %d\n", pair->key);
}
break;
case 241: /* user on federated network */
fed = strtol(pair->value, NULL, 10);
break;
case 59: /* somebody told cookies come here too, but im not sure */
if (g_utf8_validate(pair->value, -1, NULL)) {
yahoo_process_cookie(yd, pair->value);
} else {
purple_debug_warning("yahoo", "yahoo_process_list_15 "
"got non-UTF-8 string for key %d\n", pair->key);
}
break;
case 317: /* Stealth Setting */
stealth = strtol(pair->value, NULL, 10);
break;
/* case 242: */ /* this seems related to 241 */
/* break; */
}
}
g_hash_table_foreach(ht, yahoo_do_group_cleanup, NULL);
/* The reporter of ticket #9745 determined that we weren't retrieving the
* aliases during buddy list retrieval, so we never updated aliases that
* changed while we were signed off. */
yahoo_fetch_aliases(gc);
/* Now that we have processed the buddy list, we can say yahoo has connected */
purple_connection_set_display_name(gc, purple_normalize(account, purple_account_get_username(account)));
yd->logged_in = TRUE;
purple_debug_info("yahoo","Authentication: Connection established\n");
purple_connection_set_state(gc, PURPLE_CONNECTED);
if (yd->picture_upload_todo) {
yahoo_buddy_icon_upload(gc, yd->picture_upload_todo);
yd->picture_upload_todo = NULL;
}
yahoo_set_status(account, purple_account_get_active_status(account));
g_hash_table_destroy(ht);
g_free(temp);
}
static void yahoo_process_list(PurpleConnection *gc, struct yahoo_packet *pkt)
{
GSList *l = pkt->hash;
gboolean got_serv_list = FALSE;
YahooFriend *f = NULL;
PurpleAccount *account = purple_connection_get_account(gc);
YahooData *yd = gc->proto_data;
GHashTable *ht;
char **lines;
char **split;
char **buddies;
char **tmp, **bud, *norm_bud;
char *grp = NULL;
if (pkt->id)
yd->session_id = pkt->id;
while (l) {
struct yahoo_pair *pair = l->data;
l = l->next;
switch (pair->key) {
case 87:
if (!yd->tmp_serv_blist)
yd->tmp_serv_blist = g_string_new(pair->value);
else
g_string_append(yd->tmp_serv_blist, pair->value);
break;
case 88:
if (g_utf8_validate(pair->value, -1, NULL)) {
if (!yd->tmp_serv_ilist)
yd->tmp_serv_ilist = g_string_new(pair->value);
else
g_string_append(yd->tmp_serv_ilist, pair->value);
} else {
purple_debug_warning("yahoo", "yahoo_process_list "
"got non-UTF-8 string for key %d\n", pair->key);
}
break;
case 89:
if (g_utf8_validate(pair->value, -1, NULL)) {
yd->profiles = g_strsplit(pair->value, ",", -1);
} else {
purple_debug_warning("yahoo", "yahoo_process_list "
"got non-UTF-8 string for key %d\n", pair->key);
}
break;
case 59: /* cookies, yum */
if (g_utf8_validate(pair->value, -1, NULL)) {
yahoo_process_cookie(yd, pair->value);
} else {
purple_debug_warning("yahoo", "yahoo_process_list "
"got non-UTF-8 string for key %d\n", pair->key);
}
break;
case YAHOO_SERVICE_PRESENCE_PERM:
if (g_utf8_validate(pair->value, -1, NULL)) {
if (!yd->tmp_serv_plist)
yd->tmp_serv_plist = g_string_new(pair->value);
else
g_string_append(yd->tmp_serv_plist, pair->value);
} else {
purple_debug_warning("yahoo", "yahoo_process_list "
"got non-UTF-8 string for key %d\n", pair->key);
}
break;
}
}
if (pkt->status != 0)
return;
if (yd->tmp_serv_blist) {
ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_slist_free);
lines = g_strsplit(yd->tmp_serv_blist->str, "\n", -1);
for (tmp = lines; *tmp; tmp++) {
split = g_strsplit(*tmp, ":", 2);
if (!split)
continue;
if (!split[0] || !split[1]) {
g_strfreev(split);
continue;
}
grp = yahoo_string_decode(gc, split[0], FALSE);
buddies = g_strsplit(split[1], ",", -1);
for (bud = buddies; bud && *bud; bud++) {
if (!g_utf8_validate(*bud, -1, NULL)) {
purple_debug_warning("yahoo", "yahoo_process_list "
"got non-UTF-8 string for bud\n");
continue;
}
norm_bud = g_strdup(purple_normalize(account, *bud));
f = yahoo_friend_find_or_new(gc, norm_bud);
if (!purple_find_buddy(account, norm_bud)) {
PurpleBuddy *b;
PurpleGroup *g;
if (!(g = purple_find_group(grp))) {
g = purple_group_new(grp);
purple_blist_add_group(g, NULL);
}
b = purple_buddy_new(account, norm_bud, NULL);
purple_blist_add_buddy(b, NULL, g, NULL);
}
yahoo_do_group_check(account, ht, norm_bud, grp);
/* set p2p status not connected and no p2p packet sent */
yahoo_friend_set_p2p_status(f, YAHOO_P2PSTATUS_NOT_CONNECTED);
f->p2p_packet_sent = 0;
g_free(norm_bud);
}
g_strfreev(buddies);
g_strfreev(split);
g_free(grp);
}
g_strfreev(lines);
g_string_free(yd->tmp_serv_blist, TRUE);
yd->tmp_serv_blist = NULL;
g_hash_table_foreach(ht, yahoo_do_group_cleanup, NULL);
g_hash_table_destroy(ht);
}
if (yd->tmp_serv_ilist) {
buddies = g_strsplit(yd->tmp_serv_ilist->str, ",", -1);
for (bud = buddies; bud && *bud; bud++) {
/* The server is already ignoring the user */
got_serv_list = TRUE;
purple_privacy_deny_add(account, *bud, 1);
}
g_strfreev(buddies);
g_string_free(yd->tmp_serv_ilist, TRUE);
yd->tmp_serv_ilist = NULL;
}
if (got_serv_list &&
((account->perm_deny != PURPLE_PRIVACY_ALLOW_BUDDYLIST) &&
(account->perm_deny != PURPLE_PRIVACY_DENY_ALL) &&
(account->perm_deny != PURPLE_PRIVACY_ALLOW_USERS)))
{
account->perm_deny = PURPLE_PRIVACY_DENY_USERS;
purple_debug_info("yahoo", "%s privacy defaulting to PURPLE_PRIVACY_DENY_USERS.\n",
account->username);
}
if (yd->tmp_serv_plist) {
buddies = g_strsplit(yd->tmp_serv_plist->str, ",", -1);
for (bud = buddies; bud && *bud; bud++) {
f = yahoo_friend_find(gc, *bud);
if (f) {
purple_debug_info("yahoo", "%s setting presence for %s to PERM_OFFLINE\n",
account->username, *bud);
f->presence = YAHOO_PRESENCE_PERM_OFFLINE;
}
}
g_strfreev(buddies);
g_string_free(yd->tmp_serv_plist, TRUE);
yd->tmp_serv_plist = NULL;
}
/* Now that we've got the list, request aliases */
yahoo_fetch_aliases(gc);
}
/* pkt_type is YAHOO_PKT_TYPE_SERVER if pkt arrives from yahoo server, YAHOO_PKT_TYPE_P2P if pkt arrives through p2p */
static void yahoo_process_notify(PurpleConnection *gc, struct yahoo_packet *pkt, yahoo_pkt_type pkt_type)
{
PurpleAccount *account;
char *msg = NULL;
char *from = NULL;
char *stat = NULL;
char *game = NULL;
YahooFriend *f = NULL;
GSList *l = pkt->hash;
gint val_11 = 0;
YahooData *yd = gc->proto_data;
YahooFederation fed = YAHOO_FEDERATION_NONE;
account = purple_connection_get_account(gc);
while (l) {
struct yahoo_pair *pair = l->data;
if (pair->key == 4 || pair->key == 1) {
if (g_utf8_validate(pair->value, -1, NULL)) {
from = pair->value;
} else {
purple_debug_warning("yahoo", "yahoo_process_notify "
"got non-UTF-8 string for key %d\n", pair->key);
}
}
if (pair->key == 49)
msg = pair->value;
if (pair->key == 13)
stat = pair->value;
if (pair->key == 14) {
if (g_utf8_validate(pair->value, -1, NULL)) {
game = pair->value;
} else {
purple_debug_warning("yahoo", "yahoo_process_notify "
"got non-UTF-8 string for key %d\n", pair->key);
}
}
if (pair->key == 11)
val_11 = strtol(pair->value, NULL, 10);
if (pair->key == 241)
fed = strtol(pair->value, NULL, 10);
l = l->next;
}
if (!from || !msg)
return;
/* disconnect the peer if connected through p2p and sends wrong value for session id */
if( (pkt_type == YAHOO_PKT_TYPE_P2P) && (val_11 != yd->session_id) ) {
purple_debug_warning("yahoo","p2p: %s sent us notify with wrong session id. Disconnecting p2p connection to peer\n", from);
/* remove from p2p connection lists, also calls yahoo_p2p_disconnect_destroy_data */
g_hash_table_remove(yd->peers, from);
return;
}
if (!g_ascii_strncasecmp(msg, "TYPING", strlen("TYPING"))
&& (purple_privacy_check(account, from)))
{
char *fed_from = from;
switch (fed) {
case YAHOO_FEDERATION_MSN:
fed_from = g_strconcat("msn/", from, NULL);
break;
case YAHOO_FEDERATION_OCS:
fed_from = g_strconcat("ocs/", from, NULL);
break;
case YAHOO_FEDERATION_IBM:
fed_from = g_strconcat("ibm/", from, NULL);
break;
case YAHOO_FEDERATION_PBX:
fed_from = g_strconcat("pbx/", from, NULL);
break;
case YAHOO_FEDERATION_NONE:
default:
break;
}
if (stat && *stat == '1')
serv_got_typing(gc, fed_from, 0, PURPLE_TYPING);
else
serv_got_typing_stopped(gc, fed_from);
if (fed_from != from)
g_free(fed_from);
} else if (!g_ascii_strncasecmp(msg, "GAME", strlen("GAME"))) {
PurpleBuddy *bud = purple_find_buddy(account, from);
if (!bud) {
purple_debug_warning("yahoo",
"%s is playing a game, and doesn't want you to know.\n", from);
}
f = yahoo_friend_find(gc, from);
if (!f)
return; /* if they're not on the list, don't bother */
yahoo_friend_set_game(f, NULL);
if (stat && *stat == '1') {
yahoo_friend_set_game(f, game);
if (bud)
yahoo_update_status(gc, from, f);
}
} else if (!g_ascii_strncasecmp(msg, "WEBCAMINVITE", strlen("WEBCAMINVITE"))) {
PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, from, account);
char *buf = g_strdup_printf(_("%s has sent you a webcam invite, which is not yet supported."), from);
purple_conversation_write(conv, NULL, buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, time(NULL));
g_free(buf);
}
}
struct _yahoo_im {
char *from;
char *active_id;
int time;
int utf8;
int buddy_icon;
char *id;
char *msg;
YahooFederation fed;
char *fed_from;
};
static void yahoo_process_sms_message(PurpleConnection *gc, struct yahoo_packet *pkt)
{
PurpleAccount *account;
GSList *l = pkt->hash;
struct _yahoo_im *sms = NULL;
YahooData *yd;
char *server_msg = NULL;
char *m;
yd = gc->proto_data;
account = purple_connection_get_account(gc);
while (l != NULL) {
struct yahoo_pair *pair = l->data;
if (pair->key == 4) {
if (g_utf8_validate(pair->value, -1, NULL)) {
sms = g_new0(struct _yahoo_im, 1);
sms->from = g_strdup_printf("+%s", pair->value);
sms->time = time(NULL);
sms->utf8 = TRUE;
} else {
purple_debug_warning("yahoo", "yahoo_process_sms_message "
"got non-UTF-8 string for key %d\n", pair->key);
}
}
if (pair->key == 14) {
if (sms)
sms->msg = pair->value;
}
if (pair->key == 68)
if(sms)
g_hash_table_insert(yd->sms_carrier, g_strdup(sms->from), g_strdup(pair->value));
if (pair->key == 16) {
if (g_utf8_validate(pair->value, -1, NULL)) {
server_msg = pair->value;
} else {
purple_debug_warning("yahoo", "yahoo_process_sms_message "
"got non-UTF-8 string for key %d\n", pair->key);
}
}
l = l->next;
}
if(!sms) {
purple_debug_info("yahoo", "Received a malformed SMS packet!\n");
return;
}
if ((int)pkt->status < 0)
pkt->status = YAHOO_STATUS_DISCONNECTED;
if (pkt->status == YAHOO_STATUS_DISCONNECTED) {
if (server_msg) {
PurpleConversation *c;
c = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, sms->from, account);
if (c == NULL)
c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, sms->from);