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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
|
/*
* libyahoo2 wrapper to BitlBee
*
* Mostly Copyright 2004-2012 Wilmer van der Gaast <wilmer@gaast.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 02110-1301 USA
*
*/
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/stat.h>
#include <ctype.h>
#include "nogaim.h"
#include "yahoo2.h"
#include "yahoo2_callbacks.h"
#define BYAHOO_DEFAULT_GROUP "Buddies"
/* A hack to handle removal of buddies not in the group "Buddies" correctly */
struct byahoo_buddygroups {
char *buddy;
char *group;
};
struct byahoo_data {
int y2_id;
int current_status;
gboolean logged_in;
GSList *buddygroups;
};
struct byahoo_input_data {
int h;
void *d;
};
struct byahoo_conf_invitation {
char *name;
struct groupchat *c;
int yid;
YList *members;
struct im_connection *ic;
};
static GSList *byahoo_inputs = NULL;
static int byahoo_chat_id = 0;
static char *byahoo_strip(const char *in)
{
int len;
/* This should get rid of the markup noise at the beginning of the string. */
while (*in) {
if (g_strncasecmp(in, "<font", 5) == 0 ||
g_strncasecmp(in, "<fade", 5) == 0 ||
g_strncasecmp(in, "<alt", 4) == 0) {
char *s = strchr(in, '>');
if (!s) {
break;
}
in = s + 1;
} else if (strncmp(in, "\e[", 2) == 0) {
const char *s;
for (s = in + 2; *s && *s != 'm'; s++) {
;
}
if (*s != 'm') {
break;
}
in = s + 1;
} else {
break;
}
}
/* This is supposed to get rid of the noise at the end of the line. */
len = strlen(in);
while (len > 0 && (in[len - 1] == '>' || in[len - 1] == 'm')) {
int blen = len;
const char *search;
if (in[len - 1] == '>') {
search = "</";
} else {
search = "\e[";
}
len -= 3;
while (len > 0 && strncmp(in + len, search, 2) != 0) {
len--;
}
if (len <= 0 && strncmp(in, search, 2) != 0) {
len = blen;
break;
}
}
return(g_strndup(in, len));
}
static void byahoo_init(account_t *acc)
{
set_t *s;
s = set_add(&acc->set, "mail_notifications", "false", set_eval_bool, acc);
s->flags |= ACC_SET_OFFLINE_ONLY;
s = set_add(&acc->set, "notify_handle", NULL, NULL, acc);
s->flags |= ACC_SET_OFFLINE_ONLY | SET_NULL_OK;
acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE;
}
static void byahoo_login(account_t *acc)
{
struct im_connection *ic = imcb_new(acc);
struct byahoo_data *yd = ic->proto_data = g_new0(struct byahoo_data, 1);
char *s;
yd->logged_in = FALSE;
yd->current_status = YAHOO_STATUS_AVAILABLE;
if ((s = strchr(acc->user, '@')) && g_strcasecmp(s, "@yahoo.com") == 0) {
imcb_error(ic, "Your Yahoo! username should just be a username. "
"Do not include any @domain part.");
}
imcb_log(ic, "Connecting");
yd->y2_id = yahoo_init(acc->user, acc->pass);
yahoo_login(yd->y2_id, yd->current_status);
if (set_getbool(&acc->set, "mail_notifications") && set_getstr(&acc->set, "notify_handle")) {
imcb_add_buddy(ic, set_getstr(&acc->set, "notify_handle"), NULL);
}
}
static void byahoo_logout(struct im_connection *ic)
{
struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data;
GSList *l;
while (ic->groupchats) {
imcb_chat_free(ic->groupchats->data);
}
for (l = yd->buddygroups; l; l = l->next) {
struct byahoo_buddygroups *bg = l->data;
g_free(bg->buddy);
g_free(bg->group);
g_free(bg);
}
g_slist_free(yd->buddygroups);
yahoo_logoff(yd->y2_id);
g_free(yd);
}
static void byahoo_get_info(struct im_connection *ic, char *who)
{
/* Just make an URL and let the user fetch the info */
imcb_log(ic, "%s\n%s: %s%s", _("User Info"),
_("For now, fetch yourself"), yahoo_get_profile_url(),
who);
}
static int byahoo_buddy_msg(struct im_connection *ic, char *who, char *what, int flags)
{
struct byahoo_data *yd = ic->proto_data;
yahoo_send_im(yd->y2_id, NULL, who, what, 1, 0);
return 1;
}
static int byahoo_send_typing(struct im_connection *ic, char *who, int typing)
{
struct byahoo_data *yd = ic->proto_data;
yahoo_send_typing(yd->y2_id, NULL, who, (typing & OPT_TYPING) != 0);
return 1;
}
static void byahoo_set_away(struct im_connection *ic, char *state, char *msg)
{
struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data;
if (state && msg == NULL) {
/* Use these states only if msg doesn't contain additional
info since away messages are only supported with CUSTOM. */
if (g_strcasecmp(state, "Be Right Back") == 0) {
yd->current_status = YAHOO_STATUS_BRB;
} else if (g_strcasecmp(state, "Busy") == 0) {
yd->current_status = YAHOO_STATUS_BUSY;
} else if (g_strcasecmp(state, "Not At Home") == 0) {
yd->current_status = YAHOO_STATUS_NOTATHOME;
} else if (g_strcasecmp(state, "Not At Desk") == 0) {
yd->current_status = YAHOO_STATUS_NOTATDESK;
} else if (g_strcasecmp(state, "Not In Office") == 0) {
yd->current_status = YAHOO_STATUS_NOTINOFFICE;
} else if (g_strcasecmp(state, "On Phone") == 0) {
yd->current_status = YAHOO_STATUS_ONPHONE;
} else if (g_strcasecmp(state, "On Vacation") == 0) {
yd->current_status = YAHOO_STATUS_ONVACATION;
} else if (g_strcasecmp(state, "Out To Lunch") == 0) {
yd->current_status = YAHOO_STATUS_OUTTOLUNCH;
} else if (g_strcasecmp(state, "Stepped Out") == 0) {
yd->current_status = YAHOO_STATUS_STEPPEDOUT;
} else if (g_strcasecmp(state, "Invisible") == 0) {
yd->current_status = YAHOO_STATUS_INVISIBLE;
} else {
yd->current_status = YAHOO_STATUS_CUSTOM;
}
} else if (msg) {
yd->current_status = YAHOO_STATUS_CUSTOM;
} else {
yd->current_status = YAHOO_STATUS_AVAILABLE;
}
yahoo_set_away(yd->y2_id, yd->current_status, msg, state ? 2 : 0);
}
static GList *byahoo_away_states(struct im_connection *ic)
{
static GList *m = NULL;
if (m == NULL) {
m = g_list_append(m, "Be Right Back");
m = g_list_append(m, "Busy");
m = g_list_append(m, "Not At Home");
m = g_list_append(m, "Not At Desk");
m = g_list_append(m, "Not In Office");
m = g_list_append(m, "On Phone");
m = g_list_append(m, "On Vacation");
m = g_list_append(m, "Out To Lunch");
m = g_list_append(m, "Stepped Out");
m = g_list_append(m, "Invisible");
}
return m;
}
static void byahoo_keepalive(struct im_connection *ic)
{
struct byahoo_data *yd = ic->proto_data;
yahoo_keepalive(yd->y2_id);
}
static void byahoo_add_buddy(struct im_connection *ic, char *who, char *group)
{
struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data;
bee_user_t *bu;
if (group && (bu = bee_user_by_handle(ic->bee, ic, who)) && bu->group) {
GSList *bgl;
/* If the person is in our list already, this is a group change. */
yahoo_change_buddy_group(yd->y2_id, who, bu->group->name, group);
/* No idea how often people have people in multiple groups and
BitlBee doesn't currently support this anyway .. but keep
this struct up-to-date for now. */
for (bgl = yd->buddygroups; bgl; bgl = bgl->next) {
struct byahoo_buddygroups *bg = bgl->data;
if (g_strcasecmp(bg->buddy, who) == 0 &&
g_strcasecmp(bg->group, bu->group->name) == 0) {
g_free(bg->group);
bg->group = g_strdup(group);
}
}
} else {
yahoo_add_buddy(yd->y2_id, who, group ? group : BYAHOO_DEFAULT_GROUP, NULL);
}
}
static void byahoo_remove_buddy(struct im_connection *ic, char *who, char *group)
{
struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data;
GSList *bgl;
yahoo_remove_buddy(yd->y2_id, who, BYAHOO_DEFAULT_GROUP);
for (bgl = yd->buddygroups; bgl; bgl = bgl->next) {
struct byahoo_buddygroups *bg = bgl->data;
if (g_strcasecmp(bg->buddy, who) == 0) {
yahoo_remove_buddy(yd->y2_id, who, bg->group);
}
}
}
static void byahoo_chat_msg(struct groupchat *c, char *message, int flags)
{
struct byahoo_data *yd = (struct byahoo_data *) c->ic->proto_data;
yahoo_conference_message(yd->y2_id, NULL, c->data, c->title, message, 1);
}
static void byahoo_chat_invite(struct groupchat *c, char *who, char *msg)
{
struct byahoo_data *yd = (struct byahoo_data *) c->ic->proto_data;
yahoo_conference_invite(yd->y2_id, NULL, c->data, c->title, msg ? msg : "");
}
static void byahoo_chat_leave(struct groupchat *c)
{
struct byahoo_data *yd = (struct byahoo_data *) c->ic->proto_data;
yahoo_conference_logoff(yd->y2_id, NULL, c->data, c->title);
imcb_chat_free(c);
}
static struct groupchat *byahoo_chat_with(struct im_connection *ic, char *who)
{
struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data;
struct groupchat *c;
char *roomname;
YList *members;
roomname = g_strdup_printf("%s-Bee-%d", ic->acc->user, byahoo_chat_id);
c = imcb_chat_new(ic, roomname);
imcb_chat_add_buddy(c, ic->acc->user);
/* FIXME: Free this thing when the chat's destroyed. We can't *always*
do this because it's not always created here. */
c->data = members = g_new0(YList, 1);
members->data = g_strdup(who);
yahoo_conference_invite(yd->y2_id, NULL, members, roomname, "Please join my groupchat...");
g_free(roomname);
return c;
}
static void byahoo_auth_allow(struct im_connection *ic, const char *who)
{
struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data;
yahoo_confirm_buddy(yd->y2_id, who, 0, "");
}
static void byahoo_auth_deny(struct im_connection *ic, const char *who)
{
struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data;
yahoo_confirm_buddy(yd->y2_id, who, 1, "");
}
void byahoo_initmodule()
{
struct prpl *ret = g_new0(struct prpl, 1);
ret->name = "yahoo";
ret->mms = 832; /* this guess taken from libotr UPGRADING file */
ret->init = byahoo_init;
ret->login = byahoo_login;
ret->keepalive = byahoo_keepalive;
ret->logout = byahoo_logout;
ret->buddy_msg = byahoo_buddy_msg;
ret->get_info = byahoo_get_info;
ret->away_states = byahoo_away_states;
ret->set_away = byahoo_set_away;
ret->add_buddy = byahoo_add_buddy;
ret->remove_buddy = byahoo_remove_buddy;
ret->send_typing = byahoo_send_typing;
ret->chat_msg = byahoo_chat_msg;
ret->chat_invite = byahoo_chat_invite;
ret->chat_leave = byahoo_chat_leave;
ret->chat_with = byahoo_chat_with;
ret->handle_cmp = g_strcasecmp;
ret->auth_allow = byahoo_auth_allow;
ret->auth_deny = byahoo_auth_deny;
register_protocol(ret);
}
static struct im_connection *byahoo_get_ic_by_id(int id)
{
GSList *l;
struct im_connection *ic;
struct byahoo_data *yd;
for (l = get_connections(); l; l = l->next) {
ic = l->data;
yd = ic->proto_data;
if (strcmp(ic->acc->prpl->name, "yahoo") == 0 && yd->y2_id == id) {
return(ic);
}
}
return(NULL);
}
/* Now it's callback time! */
struct byahoo_connect_callback_data {
int fd;
yahoo_connect_callback callback;
gpointer data;
int id;
};
void byahoo_connect_callback(gpointer data, gint source, b_input_condition cond)
{
struct byahoo_connect_callback_data *d = data;
if (!byahoo_get_ic_by_id(d->id)) {
g_free(d);
return;
}
d->callback(NULL + d->fd, 0, d->data);
g_free(d);
}
struct byahoo_read_ready_data {
int id;
int fd;
int tag;
gpointer data;
};
gboolean byahoo_read_ready_callback(gpointer data, gint source, b_input_condition cond)
{
struct byahoo_read_ready_data *d = data;
if (!byahoo_get_ic_by_id(d->id)) {
/* WTF doesn't libyahoo clean this up? */
return FALSE;
}
yahoo_read_ready(d->id, NULL + d->fd, d->data);
return TRUE;
}
struct byahoo_write_ready_data {
int id;
int fd;
int tag;
gpointer data;
};
gboolean byahoo_write_ready_callback(gpointer data, gint source, b_input_condition cond)
{
struct byahoo_write_ready_data *d = data;
return yahoo_write_ready(d->id, NULL + d->fd, d->data);
}
void ext_yahoo_login_response(int id, int succ, const char *url)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
struct byahoo_data *yd = NULL;
if (ic == NULL) {
/* libyahoo2 seems to call this one twice when something
went wrong sometimes. Don't know why. Because we clean
up the connection on the first failure, the second
should be ignored. */
return;
}
yd = (struct byahoo_data *) ic->proto_data;
if (succ == YAHOO_LOGIN_OK) {
imcb_connected(ic);
yd->logged_in = TRUE;
} else {
char *errstr;
int allow_reconnect = FALSE;
yd->logged_in = FALSE;
if (succ == YAHOO_LOGIN_UNAME) {
errstr = "Incorrect Yahoo! username";
} else if (succ == YAHOO_LOGIN_PASSWD) {
errstr = "Incorrect Yahoo! password";
} else if (succ == YAHOO_LOGIN_LOCK) {
errstr = "Yahoo! account locked";
} else if (succ == 1236) {
errstr = "Yahoo! account locked or machine temporarily banned";
} else if (succ == YAHOO_LOGIN_DUPL) {
errstr = "Logged in on a different machine or device";
} else if (succ == YAHOO_LOGIN_SOCK) {
errstr = "Socket problem";
allow_reconnect = TRUE;
} else {
errstr = "Unknown error";
}
if (url && *url) {
imcb_error(ic, "Error %d (%s). See %s for more information.", succ, errstr, url);
} else {
imcb_error(ic, "Error %d (%s)", succ, errstr);
}
imc_logout(ic, allow_reconnect);
}
}
void ext_yahoo_got_buddies(int id, YList *buds)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
struct byahoo_data *yd = ic->proto_data;
YList *bl = buds;
while (bl) {
struct yahoo_buddy *b = bl->data;
struct byahoo_buddygroups *bg;
if (strcmp(b->group, BYAHOO_DEFAULT_GROUP) != 0) {
bg = g_new0(struct byahoo_buddygroups, 1);
bg->buddy = g_strdup(b->id);
bg->group = g_strdup(b->group);
yd->buddygroups = g_slist_append(yd->buddygroups, bg);
}
imcb_add_buddy(ic, b->id, b->group);
imcb_rename_buddy(ic, b->id, b->real_name);
bl = bl->next;
}
}
void ext_yahoo_got_identities(int id, YList *ids)
{
}
void ext_yahoo_got_cookies(int id)
{
}
void ext_yahoo_status_changed(int id, const char *who, int stat, const char *msg, int away, int idle, int mobile)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
char *state_string = NULL;
int flags = OPT_LOGGED_IN;
if (away) {
flags |= OPT_AWAY;
}
if (mobile) {
flags |= OPT_MOBILE;
}
switch (stat) {
case YAHOO_STATUS_BRB:
state_string = "Be Right Back";
break;
case YAHOO_STATUS_BUSY:
state_string = "Busy";
break;
case YAHOO_STATUS_NOTATHOME:
state_string = "Not At Home";
break;
case YAHOO_STATUS_NOTATDESK:
state_string = "Not At Desk";
break;
case YAHOO_STATUS_NOTINOFFICE:
state_string = "Not In Office";
break;
case YAHOO_STATUS_ONPHONE:
state_string = "On Phone";
break;
case YAHOO_STATUS_ONVACATION:
state_string = "On Vacation";
break;
case YAHOO_STATUS_OUTTOLUNCH:
state_string = "Out To Lunch";
break;
case YAHOO_STATUS_STEPPEDOUT:
state_string = "Stepped Out";
break;
case YAHOO_STATUS_INVISIBLE:
state_string = "Invisible";
break;
case YAHOO_STATUS_CUSTOM:
state_string = "Away";
break;
case YAHOO_STATUS_IDLE:
state_string = "Idle";
break;
case YAHOO_STATUS_OFFLINE:
state_string = "Offline";
flags = 0;
break;
}
imcb_buddy_status(ic, who, flags, state_string, msg);
if (stat == YAHOO_STATUS_IDLE) {
imcb_buddy_times(ic, who, 0, idle);
}
}
void ext_yahoo_got_buzz(int id, const char *me, const char *who, long tm)
{
}
void ext_yahoo_got_im(int id, const char *me, const char *who, const char *msg, long tm, int stat, int utf8)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
char *m;
if (msg) {
m = byahoo_strip(msg);
imcb_buddy_msg(ic, (char *) who, (char *) m, 0, 0);
g_free(m);
}
}
void ext_yahoo_got_file(int id, const char *ignored, const char *who, const char *msg,
const char *fname, unsigned long fesize, char *trid)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
imcb_log(ic, "Got a file transfer (file = %s) from %s. Ignoring for now due to lack of support.", fname, who);
}
void ext_yahoo_got_ft_data(int id, const unsigned char *in, int len, void *data)
{
}
void ext_yahoo_file_transfer_done(int id, int result, void *data)
{
}
void ext_yahoo_typing_notify(int id, const char *ignored, const char *who, int stat)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
if (stat == 1) {
imcb_buddy_typing(ic, (char *) who, OPT_TYPING);
} else {
imcb_buddy_typing(ic, (char *) who, 0);
}
}
void ext_yahoo_system_message(int id, const char *me, const char *who, const char *msg)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
imcb_log(ic, "Yahoo! system message: %s", msg);
}
void ext_yahoo_webcam_invite(int id, const char *ignored, const char *from)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
imcb_log(ic, "Got a webcam invitation from %s. IRC+webcams is a no-no though...", from);
}
void ext_yahoo_error(int id, const char *err, int fatal, int num)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
imcb_error(ic, "%s", err);
}
/* TODO: Clear up the mess of inp and d structures */
int ext_yahoo_add_handler(int id, void *fd_, yahoo_input_condition cond, void *data)
{
struct byahoo_input_data *inp = g_new0(struct byahoo_input_data, 1);
int fd = (long) fd_;
if (cond == YAHOO_INPUT_READ) {
struct byahoo_read_ready_data *d = g_new0(struct byahoo_read_ready_data, 1);
d->id = id;
d->fd = fd;
d->data = data;
inp->d = d;
d->tag = inp->h = b_input_add(fd, B_EV_IO_READ, (b_event_handler) byahoo_read_ready_callback,
(gpointer) d);
} else if (cond == YAHOO_INPUT_WRITE) {
struct byahoo_write_ready_data *d = g_new0(struct byahoo_write_ready_data, 1);
d->id = id;
d->fd = fd;
d->data = data;
inp->d = d;
d->tag = inp->h =
b_input_add(fd, B_EV_IO_WRITE, (b_event_handler) byahoo_write_ready_callback,
(gpointer) d);
} else {
g_free(inp);
return -1;
/* Panic... */
}
byahoo_inputs = g_slist_append(byahoo_inputs, inp);
return inp->h;
}
void ext_yahoo_remove_handler(int id, int tag)
{
struct byahoo_input_data *inp;
GSList *l = byahoo_inputs;
while (l) {
inp = l->data;
if (inp->h == tag) {
byahoo_inputs = g_slist_remove(byahoo_inputs, inp);
g_free(inp->d);
g_free(inp);
break;
}
l = l->next;
}
b_event_remove(tag);
}
int ext_yahoo_connect_async(int id, const char *host, int port, yahoo_connect_callback callback, void *data,
int use_ssl)
{
struct byahoo_connect_callback_data *d;
int fd;
d = g_new0(struct byahoo_connect_callback_data, 1);
if ((fd = proxy_connect(host, port, (b_event_handler) byahoo_connect_callback, (gpointer) d)) < 0) {
g_free(d);
return(fd);
}
d->fd = fd;
d->callback = callback;
d->data = data;
d->id = id;
return fd;
}
char *ext_yahoo_get_ip_addr(const char *domain)
{
return NULL;
}
int ext_yahoo_write(void *fd, char *buf, int len)
{
return write((long) fd, buf, len);
}
int ext_yahoo_read(void *fd, char *buf, int len)
{
return read((long) fd, buf, len);
}
void ext_yahoo_close(void *fd)
{
close((long) fd);
}
void ext_yahoo_got_buddy_change_group(int id, const char *me, const char *who,
const char *old_group, const char *new_group)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
imcb_add_buddy(ic, who, new_group);
}
static void byahoo_accept_conf(void *data)
{
struct byahoo_conf_invitation *inv = data;
struct groupchat *b = NULL;
GSList *l;
for (l = inv->ic->groupchats; l; l = l->next) {
b = l->data;
if (b == inv->c) {
break;
}
}
if (b != NULL) {
yahoo_conference_logon(inv->yid, NULL, inv->members, inv->name);
imcb_chat_add_buddy(inv->c, inv->ic->acc->user);
} else {
imcb_log(inv->ic, "Duplicate/corrupted invitation to `%s'.", inv->name);
}
g_free(inv->name);
g_free(inv);
}
static void byahoo_reject_conf(void *data)
{
struct byahoo_conf_invitation *inv = data;
yahoo_conference_decline(inv->yid, NULL, inv->members, inv->name, "User rejected groupchat");
imcb_chat_free(inv->c);
g_free(inv->name);
g_free(inv);
}
void ext_yahoo_got_conf_invite(int id, const char *ignored,
const char *who, const char *room, const char *msg, YList *members)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
struct byahoo_conf_invitation *inv;
char txt[1024];
YList *m;
if (g_strcasecmp(who, ic->acc->user) == 0) {
/* WTF, Yahoo! seems to echo these now? */
return;
}
inv = g_malloc(sizeof(struct byahoo_conf_invitation));
memset(inv, 0, sizeof(struct byahoo_conf_invitation));
inv->name = g_strdup(room);
inv->c = imcb_chat_new(ic, (char *) room);
inv->c->data = members;
inv->yid = id;
inv->members = members;
inv->ic = ic;
for (m = members; m; m = m->next) {
if (g_strcasecmp(m->data, ic->acc->user) != 0) {
imcb_chat_add_buddy(inv->c, m->data);
}
}
g_snprintf(txt, 1024, "Got an invitation to chatroom %s from %s: %s", room, who, msg);
imcb_ask(ic, txt, inv, byahoo_accept_conf, byahoo_reject_conf);
}
void ext_yahoo_conf_userdecline(int id, const char *ignored, const char *who, const char *room, const char *msg)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
imcb_log(ic, "Invite to chatroom %s rejected by %s: %s", room, who, msg);
}
void ext_yahoo_conf_userjoin(int id, const char *ignored, const char *who, const char *room)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
struct groupchat *c = bee_chat_by_title(ic->bee, ic, room);
if (c) {
imcb_chat_add_buddy(c, (char *) who);
}
}
void ext_yahoo_conf_userleave(int id, const char *ignored, const char *who, const char *room)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
struct groupchat *c = bee_chat_by_title(ic->bee, ic, room);
if (c) {
imcb_chat_remove_buddy(c, (char *) who, "");
}
}
void ext_yahoo_conf_message(int id, const char *ignored, const char *who, const char *room, const char *msg, int utf8)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
char *m = byahoo_strip(msg);
struct groupchat *c = bee_chat_by_title(ic->bee, ic, room);
if (c) {
imcb_chat_msg(c, (char *) who, (char *) m, 0, 0);
}
g_free(m);
}
void ext_yahoo_chat_cat_xml(int id, const char *xml)
{
}
void ext_yahoo_chat_join(int id, const char *who, const char *room, const char *topic, YList *members, void *fd)
{
}
void ext_yahoo_chat_userjoin(int id, const char *me, const char *room, struct yahoo_chat_member *who)
{
free(who->id);
free(who->alias);
free(who->location);
free(who);
}
void ext_yahoo_chat_userleave(int id, const char *me, const char *room, const char *who)
{
}
void ext_yahoo_chat_message(int id, const char *me, const char *who, const char *room, const char *msg, int msgtype,
int utf8)
{
}
void ext_yahoo_chat_yahoologout(int id, const char *me)
{
}
void ext_yahoo_chat_yahooerror(int id, const char *me)
{
}
void ext_yahoo_contact_added(int id, const char *myid, const char *who, const char *msg)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
imcb_ask_auth(ic, who, msg);
}
void ext_yahoo_rejected(int id, const char *who, const char *msg)
{
}
void ext_yahoo_game_notify(int id, const char *me, const char *who, int stat, const char *msg)
{
}
void ext_yahoo_mail_notify(int id, const char *from, const char *subj, int cnt)
{
struct im_connection *ic = byahoo_get_ic_by_id(id);
if (from && subj) {
imcb_notify_email(ic, "Received e-mail message from %s with subject `%s'", from, subj);
} else if (cnt > 0) {
imcb_notify_email(ic, "Received %d new e-mails", cnt);
}
}
void ext_yahoo_webcam_invite_reply(int id, const char *me, const char *from, int accept)
{
}
void ext_yahoo_webcam_closed(int id, const char *who, int reason)
{
}
void ext_yahoo_got_search_result(int id, int found, int start, int total, YList *contacts)
{
}
void ext_yahoo_webcam_viewer(int id, const char *who, int connect)
{
}
void ext_yahoo_webcam_data_request(int id, int send)
{
}
int ext_yahoo_log(const char *fmt, ...)
{
return(0);
}
void ext_yahoo_got_webcam_image(int id, const char * who, const unsigned char *image, unsigned int image_size,
unsigned int real_size, unsigned int timestamp)
{
}
void ext_yahoo_got_ping(int id, const char *msg)
{
}
void ext_yahoo_got_buddyicon(int id, const char *me, const char *who, const char *url, int checksum)
{
}
void ext_yahoo_got_buddyicon_checksum(int id, const char *me, const char *who, int checksum)
{
}
void ext_yahoo_got_buddyicon_request(int id, const char *me, const char *who)
{
}
void ext_yahoo_buddyicon_uploaded(int id, const char *url)
{
}
|