3 * centerim yahoo! protocol handling class
4 * $Id: yahoohook.cc,v 1.112 2004/12/20 00:54:02 konst Exp $
6 * Copyright (C) 2003-2004 by Konstantin Klyagin <k@thekonst.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include "icqcommon.h"
29 #include "yahoohook.h"
34 #include "icqcontacts.h"
35 #include "icqgroups.h"
37 #include "accountmanager.h"
38 #include "eventmanager.h"
44 #include <sys/socket.h>
45 #include <netinet/in.h>
47 #define PERIOD_REFRESH 60
48 #define PERIOD_CLOSE 6
52 int yahoohook::yfd::connection_tags
= 0;
54 char pager_host
[255], pager_port
[255], filetransfer_host
[255],
55 filetransfer_port
[255], webcam_host
[255], webcam_port
[255],
56 local_host
[255], webcam_description
[255];
62 static int stat2int
[imstatus_size
] = {
64 YAHOO_STATUS_AVAILABLE
,
65 YAHOO_STATUS_INVISIBLE
,
68 YAHOO_STATUS_NOTATDESK
,
69 YAHOO_STATUS_NOTATHOME
,
71 YAHOO_STATUS_OUTTOLUNCH
,
74 yahoohook::yahoohook() : abstracthook(yahoo
), fonline(false), cid(0) {
75 fcapabs
.insert(hookcapab::setaway
);
76 fcapabs
.insert(hookcapab::fetchaway
);
77 fcapabs
.insert(hookcapab::directadd
);
78 // fcapabs.insert(hookcapab::files);
79 // fcapabs.insert(hookcapab::conferencing);
80 // fcapabs.insert(hookcapab::conferencesaretemporary);
81 fcapabs
.insert(hookcapab::ssl
);
82 fcapabs
.insert(hookcapab::authrequests
);
84 pager_host
[0] = pager_port
[0] = filetransfer_host
[0] =
85 filetransfer_port
[0] = webcam_host
[0] = webcam_port
[0] =
89 yahoohook::~yahoohook() {
92 void yahoohook::init() {
93 manualstatus
= conf
->getstatus(proto
);
95 static struct yahoo_callbacks c
;
97 memset(&c
, 0, sizeof(c
));
99 c
.ext_yahoo_login_response
= &login_response
;
100 c
.ext_yahoo_got_buddies
= &got_buddies
;
101 c
.ext_yahoo_status_changed
= &status_changed
;
102 c
.ext_yahoo_got_im
= &got_im
;
103 c
.ext_yahoo_got_conf_invite
= &got_conf_invite
;
104 c
.ext_yahoo_conf_userdecline
= &conf_userdecline
;
105 c
.ext_yahoo_conf_userjoin
= &conf_userjoin
;
106 c
.ext_yahoo_conf_userleave
= &conf_userleave
;
107 c
.ext_yahoo_conf_message
= &conf_message
;
108 c
.ext_yahoo_got_file
= &got_file
;
109 c
.ext_yahoo_contact_added
= &contact_added
;
110 c
.ext_yahoo_game_notify
= &game_notify
;
111 c
.ext_yahoo_mail_notify
= &mail_notify
;
112 c
.ext_yahoo_system_message
= &system_message
;
113 c
.ext_yahoo_error
= &error
;
114 c
.ext_yahoo_add_handler
= &add_handler
;
115 c
.ext_yahoo_remove_handler
= &remove_handler
;
116 c
.ext_yahoo_connect_async
= &connect_async
;
117 c
.ext_yahoo_read
= &y_read
;
118 c
.ext_yahoo_write
= &y_write
;
119 c
.ext_yahoo_close
= &y_close
;
120 c
.ext_yahoo_got_identities
= &got_identities
;
121 c
.ext_yahoo_got_ignore
= &got_ignore
;
122 c
.ext_yahoo_got_cookies
= &got_cookies
;
123 c
.ext_yahoo_chat_cat_xml
= &chat_cat_xml
;
124 c
.ext_yahoo_chat_join
= &chat_join
;
125 c
.ext_yahoo_chat_userjoin
= &chat_userjoin
;
126 c
.ext_yahoo_chat_userleave
= &chat_userleave
;
127 c
.ext_yahoo_chat_message
= &chat_message
;
128 c
.ext_yahoo_rejected
= &rejected
;
129 c
.ext_yahoo_typing_notify
= &typing_notify
;
130 c
.ext_yahoo_got_webcam_image
= &got_webcam_image
;
131 c
.ext_yahoo_webcam_invite
= &webcam_invite
;
132 c
.ext_yahoo_webcam_invite_reply
= &webcam_invite_reply
;
133 c
.ext_yahoo_webcam_closed
= &webcam_closed
;
134 c
.ext_yahoo_webcam_viewer
= &webcam_viewer
;
135 c
.ext_yahoo_webcam_data_request
= &webcam_data_request
;
136 c
.ext_yahoo_got_search_result
= &got_search_result
;
137 c
.ext_yahoo_got_ping
= &got_ping
;
138 c
.ext_yahoo_log
= &ylog
;
139 c
.ext_yahoo_got_buddyicon_request
= &got_buddyicon_request
;
140 c
.ext_yahoo_got_buddyicon
= &got_buddyicon
;
141 c
.ext_yahoo_buddyicon_uploaded
= &buddyicon_uploaded
;
142 c
.ext_yahoo_chat_yahooerror
= &chat_yahooerror
;
143 c
.ext_yahoo_chat_yahoologout
= &chat_yahoologout
;
144 c
.ext_yahoo_connect
= &yahoo_connect
;
145 c
.ext_yahoo_file_transfer_done
= &file_transfer_done
;
146 c
.ext_yahoo_get_ip_addr
= &get_ip_addr
;
147 c
.ext_yahoo_got_buddy_change_group
= &got_buddy_change_group
;
148 c
.ext_yahoo_got_buddyicon_checksum
= &got_buddyicon_checksum
;
149 c
.ext_yahoo_got_buzz
= &got_buzz
;
150 c
.ext_yahoo_got_ft_data
= &got_ft_data
;
151 c
.ext_yahoo_auth_request
= &auth_request
;
153 yahoo_register_callbacks(&c
);
156 void yahoohook::connect() {
157 icqconf::imaccount acc
= conf
->getourid(proto
);
167 cid
= yahoo_init_with_attributes(acc
.nickname
.c_str(), acc
.password
.c_str(),
168 "pager_host", acc
.server
.c_str(),
169 "pager_port", acc
.port
,
172 yahoo_login(cid
, stat2int
[manualstatus
]);
175 string msg
= _("+ [yahoo] cannot connect: ");
178 case -1: msg
+= _("could not resolve hostname"); break;
179 case -2: msg
+= _("could not create socket"); break;
180 default: msg
+= _("verify the pager host and port entered"); break;
190 void yahoohook::main() {
191 vector
<yfd
>::iterator i
;
200 tv
.tv_sec
= tv
.tv_usec
= 0;
203 for(i
= fds
.begin(); i
!= fds
.end(); ++i
) {
204 struct y_c ic
= i
->con
;
205 if (i
->cond
& YAHOO_INPUT_READ
)
207 if (i
->cond
& YAHOO_INPUT_WRITE
)
209 hsock
= max(hsock
, ic
.fd
);
212 if(select(hsock
+1, &rs
, &ws
, 0, &tv
) > 0) {
213 for(i
= fds
.begin(); i
!= fds
.end(); ++i
) {
215 if (!cw_nb_connect(i
->con
.fd
, NULL
, 0, i
->con
.ssl
, &i
->con
.state
))
217 if (i
->con
.state
& CW_CONNECT_WANT_SOMETHING
)
225 struct y_c tc
= i
->con
;
226 connect_complete(i
->data
, &tc
);
230 if(FD_ISSET(i
->con
.fd
, &rs
)) {
231 yahoo_read_ready(cid
, &i
->con
, i
->data
);
234 if(FD_ISSET(i
->con
.fd
, &ws
)) {
235 yahoo_write_ready(cid
, &i
->con
, i
->data
);
242 void yahoohook::getsockets(fd_set
&rs
, fd_set
&ws
, fd_set
&es
, int &hsocket
) const {
244 vector
<yfd
>::const_iterator i
;
246 for(i
= fds
.begin(); i
!= fds
.end(); ++i
) {
247 if (i
->cond
& YAHOO_INPUT_READ
)
248 FD_SET(i
->con
.fd
, &rs
);
249 if (i
->cond
& YAHOO_INPUT_WRITE
)
250 FD_SET(i
->con
.fd
, &ws
);
251 hsocket
= max(hsocket
, i
->con
.fd
);
256 bool yahoohook::isoursocket(fd_set
&rs
, fd_set
&ws
, fd_set
&es
) const {
257 vector
<yfd
>::const_iterator i
;
259 for(i
= fds
.begin(); i
!= fds
.end(); ++i
)
261 if(i
->cond
& YAHOO_INPUT_READ
&& FD_ISSET(i
->con
.fd
, &rs
))
264 if(i
->cond
& YAHOO_INPUT_WRITE
&& FD_ISSET(i
->con
.fd
, &ws
))
270 void yahoohook::disconnect() {
277 void yahoohook::disconnected() {
279 vector
<yfd
>::const_iterator i
;
280 for(i
= fds
.begin(); i
!= fds
.end(); ++i
)
287 logger
.putourstatus(proto
, getstatus(), ourstatus
= offline
);
288 clist
.setoffline(proto
);
290 log(logDisconnected
);
295 void yahoohook::exectimers() {
296 vector
<pair
<Action
, string
> >::iterator it
;
298 for(it
= tobedone
.begin(); it
!= tobedone
.end(); ++it
) {
301 /* TODO: investigate if copy is really needed here */
302 char *room
= strdup(it
->second
.c_str());
303 yahoo_conference_logon(cid
, 0, getmembers(it
->second
), room
);
312 if(timer_current
-timer_refresh
> PERIOD_REFRESH
) {
314 yahoo_keepalive(cid
);
315 timer_refresh
= timer_current
;
317 } else if(timer_close
&& timer_current
-timer_close
> PERIOD_CLOSE
) {
325 struct tm
*yahoohook::timestamp() {
326 return localtime(&timer_current
);
329 bool yahoohook::send(const imevent
&ev
) {
330 icqcontact
*c
= clist
.get(ev
.getcontact());
334 if(ev
.gettype() == imevent::message
) {
335 const immessage
*m
= static_cast<const immessage
*>(&ev
);
336 if(m
) text
= rushtmlconv("ku", m
->gettext());
338 } else if(ev
.gettype() == imevent::url
) {
339 const imurl
*m
= static_cast<const imurl
*>(&ev
);
340 if(m
) text
= rushtmlconv("ku", m
->geturl()) + "\n\n" + rusconv("kw", m
->getdescription());
342 } else if(ev
.gettype() == imevent::file
) {
343 const imfile
*m
= static_cast<const imfile
*>(&ev
);
344 vector
<imfile::record
> files
= m
->getfiles();
345 vector
<imfile::record
>::const_iterator ir
;
347 for(ir
= files
.begin(); ir
!= files
.end(); ++ir
) {
348 sfiles
.push_back(strdup(ir
->fname
.c_str()));
349 srfiles
[sfiles
.back()] = *m
;
351 yahoo_send_file(cid
, ev
.getcontact().nickname
.c_str(),
352 m
->getmessage().c_str(), justfname(ir
->fname
).c_str(),
353 ir
->size
, &get_fd
, sfiles
.back());
357 } else if (ev
.gettype() == imevent::authorization
) {
358 const imauthorization
*m
= static_cast<const imauthorization
*> (&ev
);
360 switch(m
->getauthtype()) {
361 case imauthorization::Granted
:
362 yahoo_confirm_buddy(cid
, ev
.getcontact().nickname
.c_str(), 0, 0);
365 case imauthorization::Rejected
:
366 yahoo_confirm_buddy(cid
, ev
.getcontact().nickname
.c_str(), 1, 0);
374 yahoo_send_im(cid
, 0, ev
.getcontact().nickname
.c_str(), text
.c_str(), 0, 0);
376 yahoo_conference_message(cid
, 0, getmembers(ev
.getcontact().nickname
.substr(1)),
377 ev
.getcontact().nickname
.c_str()+1, text
.c_str(), 0);
386 bool yahoohook::online() const {
390 bool yahoohook::logged() const {
391 return fonline
&& flogged
;
394 bool yahoohook::isconnecting() const {
395 return fonline
&& !flogged
;
398 void yahoohook::sendnewuser(const imcontact
&ic
) {
399 sendnewuser(ic
, true);
402 void yahoohook::sendnewuser(const imcontact
&ic
, bool report
) {
403 if(online() && !ischannel(ic
)) {
406 const YList
*buddies
= yahoo_get_buddylist(cid
);
407 const YList
*bud
= 0;
409 for(bud
= buddies
; bud
&& !found
; bud
= y_list_next(bud
))
410 found
= ic
.nickname
== static_cast<yahoo_buddy
*>(bud
->data
)->id
;
413 if(report
) log(logContactAdd
, ic
.nickname
.c_str());
416 vector
<icqgroup
>::const_iterator ig
= find(groups
.begin(), groups
.end(), clist
.get(ic
)->getgroupid());
417 if (ig
== groups
.end())
419 yahoo_add_buddy(cid
, ic
.nickname
.c_str(), ig
->getname().c_str(), "");
428 void yahoohook::removeuser(const imcontact
&ic
) {
429 removeuser(ic
, true);
432 void yahoohook::removeuser(const imcontact
&ic
, bool report
) {
435 if(report
) log(logContactRemove
, ic
.nickname
.c_str());
437 const YList
*buddies
= yahoo_get_buddylist(cid
);
438 const YList
*bud
= 0;
440 for(bud
= buddies
; bud
; bud
= y_list_next(bud
)) {
441 if(ic
.nickname
== ((yahoo_buddy
*) bud
->data
)->id
)
442 yahoo_remove_buddy(cid
,
443 ((yahoo_buddy
*) bud
->data
)->id
,
444 ((yahoo_buddy
*) bud
->data
)->group
);
448 face
.log(_("+ [yahoo] leaving the %s conference"),
449 ic
.nickname
.c_str());
451 yahoo_conference_logoff(cid
, 0, getmembers(ic
.nickname
.substr(1)), ic
.nickname
.c_str()+1);
456 imstatus
yahoohook::yahoo2imstatus(int status
) {
457 imstatus st
= offline
;
460 case YAHOO_STATUS_AVAILABLE
:
463 case YAHOO_STATUS_BUSY
:
466 case YAHOO_STATUS_CUSTOM
:
467 case YAHOO_STATUS_BRB
:
468 case YAHOO_STATUS_IDLE
:
469 case YAHOO_STATUS_ONPHONE
:
472 case YAHOO_STATUS_NOTATDESK
:
475 case YAHOO_STATUS_NOTATHOME
:
476 case YAHOO_STATUS_NOTINOFFICE
:
477 case YAHOO_STATUS_ONVACATION
:
478 case YAHOO_STATUS_STEPPEDOUT
:
481 case YAHOO_STATUS_OUTTOLUNCH
:
484 case YAHOO_STATUS_INVISIBLE
:
495 bool yahoohook::enabled() const {
499 void yahoohook::setautostatus(imstatus st
) {
501 if(getstatus() != offline
) {
505 if(getstatus() == offline
) {
509 logger
.putourstatus(proto
, getstatus(), ourstatus
= st
);
511 if(st
== freeforchat
) {
512 /* TODO copy should not be needed here ?*/
513 char *msg
= strdup("free for chat");
514 yahoo_set_away(cid
, (yahoo_status
) stat2int
[st
], msg
, 0);
517 } else if(st
!= away
) {
518 yahoo_set_away(cid
, (yahoo_status
) stat2int
[st
], 0, 0);
521 char *msg
= strdup(rusconv("ku", conf
->getawaymsg(proto
)).c_str());
522 yahoo_set_away(cid
, (yahoo_status
) stat2int
[st
], msg
, 1);
530 imstatus
yahoohook::getstatus() const {
531 return online() ? ourstatus
: offline
;
534 void yahoohook::requestinfo(const imcontact
&ic
) {
535 requestfromfound(ic
);
537 icqcontact
*c
= clist
.get(ic
);
538 if(!c
) c
= clist
.get(contactroot
);
540 icqcontact::moreinfo m
= c
->getmoreinfo();
541 icqcontact::basicinfo b
= c
->getbasicinfo();
543 m
.homepage
= "http://profiles.yahoo.com/" + ic
.nickname
;
544 b
.email
= ic
.nickname
+ "@yahoo.com";
550 void yahoohook::userstatus(const string
&nick
, int st
, const string
&message
, bool away
) {
551 imcontact
ic(nick
, proto
);
552 icqcontact
*c
= clist
.get(ic
);
554 awaymessages
[nick
] = rusconv("wk", message
);
557 c
= clist
.addnew(ic
, false);
561 logger
.putonline(ic
, c
->getstatus(), yahoo2imstatus(st
));
562 c
->setstatus(yahoo2imstatus(st
));
566 YList
*yahoohook::getmembers(const string
&room
) {
568 static YList
*smemb
= 0;
569 vector
<string
>::iterator ic
;
570 map
<string
, vector
<string
> >::iterator im
;
573 for(YList
*n
= smemb
; n
; n
= y_list_next(n
))
580 if((im
= confmembers
.find(room
)) != confmembers
.end())
581 for(ic
= im
->second
.begin(); ic
!= im
->second
.end(); ++ic
)
582 smemb
= y_list_append(smemb
, strdup(ic
->c_str()));
587 string
yahoohook::decode(string text
, bool utf
) {
590 text
= rushtmlconv(utf
? "uk" : "wk", text
);
592 while((npos
= text
.find("\e[")) != -1) {
593 if((mpos
= text
.substr(npos
).find("m")) == -1)
594 mpos
= text
.size()-npos
-1;
596 text
.erase(npos
, mpos
+1);
602 bool yahoohook::knowntransfer(const imfile
&fr
) const {
603 return fvalid
.find(fr
) != fvalid
.end();
606 void yahoohook::replytransfer(const imfile
&fr
, bool accept
, const string
&localpath
) {
608 string localname = localpath + "/";
609 localname += fr.getfiles()[0].fname;
610 sfiles.push_back(strdup(localname.c_str()));
611 srfiles[sfiles.back()] = fr;
612 yahoo_get_url_handle(cid, fvalid[fr].c_str(), &get_url, sfiles.back());
620 void yahoohook::aborttransfer(const imfile
&fr
) {
621 face
.transferupdate(fr
.getfiles().begin()->fname
, fr
, icqface::tsCancel
, 0, 0);
625 void yahoohook::lookup(const imsearchparams
¶ms
, verticalmenu
&dest
) {
628 vector
<string
>::const_iterator i
;
630 while(!foundguys
.empty()) {
631 delete foundguys
.back();
632 foundguys
.pop_back();
635 yahoo_search_gender gender
= YAHOO_GENDER_NONE
;
637 switch(params
.gender
) {
638 case genderMale
: gender
= YAHOO_GENDER_MALE
; break;
639 case genderFemale
: gender
= YAHOO_GENDER_FEMALE
; break;
642 searchonlineonly
= params
.onlineonly
;
645 if(!params
.kwords
.empty()) {
646 yahoo_search(cid
, YAHOO_SEARCH_KEYWORD
, decode(params
.kwords
, false).c_str(),
647 gender
, YAHOO_AGERANGE_NONE
, params
.photo
? 1 : 0, 1);
649 } else if(!params
.firstname
.empty()) {
650 yahoo_search(cid
, YAHOO_SEARCH_NAME
, decode(params
.firstname
, false).c_str(),
651 gender
, YAHOO_AGERANGE_NONE
, params
.photo
? 1 : 0, 1);
653 } else if(!params
.room
.empty()) {
654 room
= params
.room
.substr(1);
655 i
= confmembers
[room
].begin();
657 while(i
!= confmembers
[room
].end()) {
658 if(c
= clist
.get(imcontact(*i
, proto
)))
659 searchdest
->additem(conf
->getcolor(cp_clist_yahoo
),
660 c
, (string
) " " + *i
);
666 log(logConfMembers
, searchdest
->getcount());
668 searchdest
->redraw();
674 void yahoohook::conferencecreate(const imcontact
&confid
, const vector
<imcontact
> &lst
) {
676 string room
= confid
.nickname
.substr(1);
680 vector
<imcontact
>::const_iterator il
= lst
.begin();
681 while(il
!= lst
.end()) {
682 who
= y_list_append(who
, strdup(il
->nickname
.c_str()));
686 yahoo_conference_invite(cid
, 0, who
, room
.c_str(), _("Please join my conference."));
688 for(YList
*w
= who
; w
; w
= y_list_next(w
))
694 void yahoohook::requestawaymsg(const imcontact
&ic
) {
695 icqcontact
*c
= clist
.get(ic
);
698 if(awaymessages
.find(ic
.nickname
) != awaymessages
.end()) {
699 em
.store(imnotification(ic
, string() + _("Custom status message:") + "\n\n" +
700 awaymessages
[ic
.nickname
]));
703 face
.log(_("+ [yahoo] cannot fetch away msg from %s, %s (maybe no away msg set)"),
704 c
->getdispnick().c_str(), ic
.totext().c_str());
710 void yahoohook::checkinlist(imcontact ic
) {
712 icqcontact
*c
= clist
.get(ic
);
716 const YList
*buddies
= yahoo_get_buddylist(cid
);
718 for(const YList
*bud
= buddies
; bud
&& !found
; ) {
719 yahoo_buddy
*yb
= (yahoo_buddy
*) bud
->data
;
720 found
= (c
->getdesc().nickname
== yb
->id
);
721 bud
= y_list_next(bud
);
724 if(!found
) sendnewuser(ic
, false);
728 void yahoohook::updatecontact(icqcontact
*c
) {
729 if(logged() && conf
->getgroupmode() != icqconf::nogroups
) {
731 const YList
*buddies
= yahoo_get_buddylist(cid
);
732 string newgroupname
= groups
.getname(c
->getgroupid());
734 for(const YList
*bud
= buddies
; bud
; ) {
735 yahoo_buddy
*yb
= (yahoo_buddy
*) bud
->data
;
737 if(c
->getdesc().nickname
== yb
->id
) {
739 if(newgroupname
!= yb
->group
)
740 yahoo_change_buddy_group(cid
, yb
->id
, yb
->group
, newgroupname
.c_str());
744 yahoo_remove_buddy(cid
, yb
->id
, yb
->group
);
748 bud
= y_list_next(bud
);
753 void yahoohook::renamegroup(const string
&oldname
, const string
&newname
) {
755 string tempname
= oldname
+ "___" + i2str(getpid()) + "_temp";
756 yahoo_group_rename(cid
, oldname
.c_str(), tempname
.c_str());
757 yahoo_group_rename(cid
, tempname
.c_str(), newname
.c_str());
761 // ----------------------------------------------------------------------------
763 void yahoohook::login_response(int id
, int succ
, const char *url
) {
764 vector
<string
>::iterator in
;
768 yhook
.flogged
= true;
769 logger
.putourstatus(yahoo
, offline
, yhook
.ourstatus
= yhook
.manualstatus
);
770 yhook
.log(logLogged
);
771 time(&yhook
.timer_refresh
);
772 yhook
.setautostatus(yhook
.manualstatus
);
773 yhook
.timer_close
= 0;
776 case YAHOO_LOGIN_LOGOFF
:
777 yhook
.fonline
= yhook
.fonline
= false;
778 yahoo_close(yhook
.cid
);
779 face
.log(_("+ [yahoo] cannot login"));
782 case YAHOO_LOGIN_PASSWD
:
783 yhook
.fonline
= yhook
.fonline
= false;
784 yahoo_close(yhook
.cid
);
785 face
.log(_("+ [yahoo] cannot login: username and password mismatch"));
788 case YAHOO_LOGIN_UNAME
:
789 yhook
.fonline
= yhook
.fonline
= false;
790 yahoo_close(yhook
.cid
);
791 face
.log(_("+ [yahoo] cannot login: username doesn't exist"));
794 case YAHOO_LOGIN_LOCK
:
795 yhook
.fonline
= yhook
.fonline
= false;
796 yahoo_close(yhook
.cid
);
797 face
.log(_("+ [yahoo] cannot login: the account has been blocked"));
798 face
.log(_("+ to reactivate visit %s"), url
);
801 case YAHOO_LOGIN_DUPL
:
802 face
.log(_("+ [yahoo] another logon detected"));
803 yahoo_logoff(yhook
.cid
);
804 yhook
.manualstatus
= offline
;
807 case YAHOO_LOGIN_UNKNOWN
:
808 case YAHOO_LOGIN_SOCK
:
809 face
.log(_("+ [yahoo] server closed socket"));
810 yhook
.disconnected();
817 void yahoohook::got_buddies(int id
, YList
*buds
) {
820 for(buddy
= buds
; buddy
; buddy
= y_list_next(buddy
)) {
821 yahoo_buddy
*bud
= static_cast<yahoo_buddy
*>(buddy
->data
);
823 clist
.updateEntry(imcontact(bud
->id
, yahoo
), bud
->group
? bud
->group
: "");
827 void yahoohook::got_identities(int id
, YList
*buds
) {
830 void yahoohook::status_changed(int id
, const char *who
, int stat
, const char *msg
, int away
, int idle
, int mobile
) {
831 yhook
.userstatus(who
, stat
, msg
? msg
: "", (bool) away
);
834 void yahoohook::got_im(int id
, const char *me
, const char *who
, const char *msg
, long tm
, int stat
, int utf8
) {
835 imcontact
ic(who
, yahoo
);
836 string text
= cuthtml(msg
, chCutBR
| chLeaveLinks
);
838 yhook
.checkinlist(ic
);
839 text
= yhook
.decode(text
, utf8
);
842 em
.store(immessage(ic
, imevent::incoming
, text
, tm
));
846 void yahoohook::got_search_result(int id
, int found
, int start
, int total
, YList
*contacts
) {
847 yahoo_found_contact
*fc
;
852 if(!yhook
.searchdest
)
855 for(ir
= contacts
; ir
; ir
= ir
->next
) {
856 fc
= (yahoo_found_contact
*) ir
->data
;
858 if(yhook
.searchonlineonly
&& !fc
->online
)
861 c
= new icqcontact(imcontact(fc
->id
, yahoo
));
863 icqcontact::basicinfo binfo
= c
->getbasicinfo();
864 icqcontact::moreinfo minfo
= c
->getmoreinfo();
866 if(!fc
->id
|| !fc
->gender
)
870 c
->setdispnick(c
->getnick());
873 if(sg
== "MALE") minfo
.gender
= genderMale
;
874 else if(sg
== "FEMALE") minfo
.gender
= genderFemale
;
877 if(fc
->location
) binfo
.street
= fc
->location
;
879 line
= (fc
->online
? "o " : " ") + c
->getnick();
881 if(fc
->age
|| fc
->location
|| strlen(fc
->gender
) >= 4) {
883 if(fc
->age
) line
+= i2str(fc
->age
);
885 if(strlen(fc
->gender
) >= 4) {
886 if(fc
->age
) line
+= ", ";
890 if(fc
->location
&& strlen(fc
->location
)) {
891 if(fc
->age
|| strlen(fc
->gender
) >= 4) line
+= ", ";
892 line
+= fc
->location
;
898 c
->setbasicinfo(binfo
);
899 c
->setmoreinfo(minfo
);
901 yhook
.foundguys
.push_back(c
);
902 yhook
.searchdest
->additem(conf
->getcolor(cp_clist_yahoo
), c
, line
);
905 yhook
.searchdest
->redraw();
907 if(start
+ found
>= total
) {
909 yhook
.log(logSearchFinished
, yhook
.foundguys
.size());
910 yhook
.searchdest
= 0;
912 yahoo_search_again(yhook
.cid
, -1);
916 void yahoohook::got_conf_invite(int id
, const char *me
, const char *who
, const char *room
, const char *msg
, YList
*members
) {
917 icqconf::imaccount acc
= conf
->getourid(yahoo
);
918 string confname
= (string
) "#" + room
, inviter
, text
;
919 vector
<string
>::iterator ic
;
923 imcontact
cont(confname
, yahoo
);
924 icqcontact
*c
= clist
.get(cont
);
925 if(!c
) c
= clist
.addnew(cont
);
927 inviter
= confname
.substr(1);
928 if((i
= inviter
.rfind("-")) != -1) {
932 snprintf(buf
, NOTIFBUF
, _("The user %s has invited you to the %s conference, the topic there is: %s"),
933 yhook
.rusconv("wk", inviter
).c_str(),
934 yhook
.rusconv("wk", room
).c_str(),
935 yhook
.rusconv("wk", msg
).c_str());
937 text
= (string
) buf
+ "\n\n" + _("Current conference members are: ");
938 yhook
.confmembers
[room
].push_back(inviter
);
940 for(YList
*m
= members
; m
; m
= y_list_next(m
)) {
941 string id
= (char *) m
->data
;
943 if(id
!= acc
.nickname
)
944 if(find(yhook
.confmembers
[room
].begin(), yhook
.confmembers
[room
].end(), id
) == yhook
.confmembers
[room
].end()) {
945 yhook
.confmembers
[room
].push_back(id
);
949 for(ic
= yhook
.confmembers
[room
].begin(); ic
!= yhook
.confmembers
[room
].end(); ) {
951 if(++ic
!= yhook
.confmembers
[room
].end())
955 c
->setstatus(available
);
956 em
.store(imnotification(cont
, text
));
957 em
.store(imnotification(cont
, _("Auto-joined the conference")));
959 yhook
.tobedone
.push_back(make_pair(tbdConfLogon
, room
));
962 void yahoohook::conf_userdecline(int id
, const char *me
, const char *who
, const char *room
, const char *msg
) {
963 icqcontact
*c
= clist
.get(imcontact((string
) "#" + room
, yahoo
));
967 snprintf(buf
, NOTIFBUF
, _("The user %s has declined your invitation to join the conference"), who
);
968 em
.store(imnotification(c
, buf
));
972 void yahoohook::conf_userjoin(int id
, const char *me
, const char *who
, const char *room
) {
973 icqcontact
*c
= clist
.get(imcontact((string
) "#" + room
, yahoo
));
977 snprintf(buf
, NOTIFBUF
, _("The user %s has joined the conference"), who
);
979 if(find(yhook
.confmembers
[room
].begin(), yhook
.confmembers
[room
].end(), who
) == yhook
.confmembers
[room
].end())
980 yhook
.confmembers
[room
].push_back(who
);
982 em
.store(imnotification(c
, buf
));
986 void yahoohook::conf_userleave(int id
, const char *me
, const char *who
, const char *room
) {
987 icqcontact
*c
= clist
.get(imcontact((string
) "#" + room
, yahoo
));
989 vector
<string
>::iterator im
;
992 snprintf(buf
, NOTIFBUF
, _("The user %s has left the conference"), who
);
993 em
.store(imnotification(c
, buf
));
995 im
= find(yhook
.confmembers
[room
].begin(), yhook
.confmembers
[room
].end(), who
);
996 if(im
!= yhook
.confmembers
[room
].end()) yhook
.confmembers
[room
].erase(im
);
1000 void yahoohook::conf_message(int id
, const char *me
, const char *who
, const char *room
, const char *msg
, int utf8
) {
1001 icqcontact
*c
= clist
.get(imcontact((string
) "#" + room
, yahoo
));
1003 string text
= (string
) who
+ ": " + cuthtml(msg
, chCutBR
| chLeaveLinks
);
1004 text
= yhook
.decode(text
, utf8
);
1006 if(c
) em
.store(immessage(c
, imevent::incoming
, text
));
1009 void yahoohook::got_file(int id
, const char *me
, const char *who
, const char *msg
, const char *fname
, unsigned long fesize
, char *trid
) {
1010 if(!who
|| !fname
|| !trid
)
1017 if(!fesize
) r
.size
= -1;
1019 if((pos
= r
.fname
.find('?')) != -1)
1022 imfile
fr(imcontact(who
, yahoo
), imevent::incoming
, "",
1023 vector
<imfile::record
>(1, r
));
1025 yhook
.fvalid
[fr
] = trid
;
1028 face
.transferupdate(fname
, fr
, icqface::tsInit
, fesize
, 0);
1031 void yahoohook::contact_added(int id
, const char *myid
, const char *who
, const char *msg
) {
1032 string text
= _("The user has added you to his/her contact list");
1036 text
+= (string
) ", " + _("the message was: ") + msg
;
1039 em
.store(imnotification(imcontact(who
, yahoo
), text
));
1042 void yahoohook::typing_notify(int id
, const char *me
, const char *who
, int stat
) {
1043 icqcontact
*c
= clist
.get(imcontact(who
, yahoo
));
1044 if(c
) c
->setlasttyping(stat
? timer_current
: 0);
1047 void yahoohook::game_notify(int id
, const char *me
, const char *who
, int stat
, const char *msg
) {
1050 void yahoohook::mail_notify(int id
, const char *from
, const char *subj
, int cnt
) {
1054 snprintf(buf
, NOTIFBUF
, _("+ [yahoo] e-mail from %s, %s"), from
, subj
);
1056 clist
.get(contactroot
)->playsound(imevent::email
);
1060 void yahoohook::system_message(int id
, const char *me
, const char *who
, const char *msg
) {
1061 face
.log(_("+ [yahoo] system (%s): %s"), who
, msg
);
1064 void yahoohook::got_ping(int id
, const char *msg
) {
1065 // face.log(_("+ [yahoo] ping: %s"), msg);
1068 void yahoohook::error(int id
, const char *err
, int fatal
, int num
) {
1070 face
.log(_("+ [yahoo] fatal error: %s"), err
);
1071 yhook
.disconnected();
1074 face
.log(_("[yahoo] error %s"), err
);
1078 int yahoohook::add_handler(int id
, void *fd
, yahoo_input_condition cond
, void *data
) {
1080 struct y_c
*con
= (struct y_c
*)fd
;
1082 yhook
.fds
.push_back(yfd(con
->fd
, data
, con
->ssl
, cond
));
1083 tag
= yhook
.fds
.back().tag
;
1088 void yahoohook::remove_handler(int id
, int tag
) {
1089 vector
<yfd
>::iterator i
;
1091 i
= find(yhook
.fds
.begin(), yhook
.fds
.end(), tag
);
1092 if(i
!= yhook
.fds
.end())
1096 int yahoohook::connect_async(int id
, const char *host
, int port
, yahoo_connect_callback callback
, void *data
, int use_ssl
) {
1097 struct sockaddr_in serv_addr
;
1098 static struct hostent
*server
;
1100 struct connect_callback_data
* ccd
;
1103 if(!(server
= gethostbyname(host
))) {
1108 if((servfd
= socket(AF_INET
, SOCK_STREAM
, 0)) < 0) {
1112 memset(&serv_addr
, 0, sizeof(serv_addr
));
1113 serv_addr
.sin_family
= AF_INET
;
1114 memcpy(&serv_addr
.sin_addr
.s_addr
, *server
->h_addr_list
, server
->h_length
);
1115 serv_addr
.sin_port
= htons(port
);
1119 struct y_c
*con
= new struct y_c(servfd
, use_ssl
, state
);
1120 error
= cw_nb_connect(servfd
, (struct sockaddr
*) &serv_addr
, sizeof(serv_addr
), use_ssl
, &state
);
1123 if(!error
&& !state
) {
1124 int f
= fcntl(servfd
, F_GETFL
);
1125 fcntl(servfd
, F_SETFL
, f
| O_NONBLOCK
);
1126 callback(con
, 0, data
);
1128 } else if((error
== -1 && errno
== EINPROGRESS
) || (state
& CW_CONNECT_STARTED
)){
1129 ccd
= new connect_callback_data
;
1130 ccd
->callback
= callback
;
1131 ccd
->callback_data
= data
;
1134 ccd
->tag
= add_handler(id
, con
, YAHOO_INPUT_WRITE
, ccd
);
1139 callback(NULL
, 0, data
);
1146 void yahoohook::connect_complete(void *data
, struct y_c
*con
) {
1147 connect_callback_data
*ccd
= (connect_callback_data
*) data
;
1149 socklen_t err_size
= sizeof(so_error
);
1151 remove_handler(0, ccd
->tag
);
1152 if(getsockopt(con
->fd
, SOL_SOCKET
, SO_ERROR
, (char *) &so_error
, &err_size
) == -1 || so_error
!= 0) {
1154 face
.log(_("+ [yahoo] direct connection failed"));
1158 ccd
->callback(con
, so_error
, ccd
->callback_data
);
1164 int yahoohook::y_write(void *fd
, char *buf
, int len
)
1168 struct y_c
*con
= (struct y_c
*)fd
;
1169 return cw_write(con
->fd
, buf
, len
, con
->ssl
);
1172 int yahoohook::y_read(void *fd
, char *buf
, int len
)
1176 struct y_c
*con
= (struct y_c
*)fd
;
1177 return cw_read(con
->fd
, buf
, len
, con
->ssl
);
1181 void yahoohook::y_close(void *fd
)
1183 struct y_c
*con
= (struct y_c
*)fd
;
1188 void yahoohook::got_ignore(int id
, YList
* igns
) {
1191 void yahoohook::got_cookies(int id
) {
1194 void yahoohook::chat_cat_xml(int id
, const char *xml
) {
1195 face
.log(_("+ [yahoo] chat_cat_xml"));
1198 void yahoohook::chat_join(int id
, const char *me
, const char *room
, const char *topic
, YList
*members
, void *fd
) {
1199 face
.log(_("+ [yahoo] chat_join"));
1202 void yahoohook::chat_userjoin(int id
, const char *me
, const char *room
, struct yahoo_chat_member
*who
) {
1203 face
.log(_("+ [yahoo] chat_userjoin"));
1206 void yahoohook::chat_userleave(int id
, const char *me
, const char *room
, const char *who
) {
1207 face
.log(_("+ [yahoo] chat_userleave"));
1210 void yahoohook::chat_message(int id
, const char *me
, const char *who
, const char *room
, const char *msg
, int msgtype
, int utf8
) {
1211 face
.log(_("+ [yahoo] chat_message from %s"), who
);
1214 void yahoohook::rejected(int id
, const char *who
, const char *msg
) {
1215 imcontact
ic(who
, yahoo
);
1216 string text
= cuthtml(msg
?msg
: "", chCutBR
| chLeaveLinks
);
1217 string message
= "The user has rejected your authorization request";
1226 em
.store(imnotification(ic
, message
));
1229 void yahoohook::got_webcam_image(int id
, const char * who
, const unsigned char *image
, unsigned int image_size
, unsigned int real_size
, unsigned int timestamp
) {
1232 void yahoohook::webcam_invite(int id
, const char *me
, const char *from
) {
1235 void yahoohook::webcam_invite_reply(int id
, const char *me
, const char *from
, int accept
) {
1238 void yahoohook::webcam_closed(int id
, const char *who
, int reason
) {
1241 void yahoohook::webcam_viewer(int id
, const char *who
, int connect
) {
1244 void yahoohook::webcam_data_request(int id
, int send
) {
1247 void yahoohook::got_buddyicon_request(int id
, const char *me
, const char *who
) {
1250 void yahoohook::got_buddyicon(int id
, const char *me
, const char *who
, const char *url
, int checksum
) {
1253 void yahoohook::buddyicon_uploaded(int id
, const char *url
) {
1256 void yahoohook::chat_yahooerror(int id
, const char *me
) {
1257 face
.log(_("+ [yahoo] chat_yahooerror"));
1260 void yahoohook::chat_yahoologout(int id
, const char *me
) {
1261 face
.log(_("+ [yahoo] chat_yahoologout"));
1264 int yahoohook::yahoo_connect(const char *host
, int port
) {
1265 face
.log(_("+ [yahoo] yahoo connect"));
1269 void yahoohook::file_transfer_done(int id
, int result
, void *data
) {
1272 char *yahoohook::get_ip_addr(const char *domain
) {
1273 face
.log(_("+ [yahoo] get_ip_addr %s"), domain
);
1277 void yahoohook::got_buddy_change_group(int id
, const char *me
, const char *who
, const char *old_group
, const char *new_group
) {
1278 face
.log(_("+ [yahoo] yahoo buddy_change_group %s from %s to %s"), who
, old_group
, new_group
);
1281 void yahoohook::got_buddyicon_checksum(int id
, char const *me
, const char *who
, int checksum
) {
1284 void yahoohook::got_buzz(int id
, const char *me
, const char *who
, long tm
) {
1285 imcontact
ic(who
, yahoo
);
1287 em
.store(imnotification(ic
, (string
)
1288 _("The user has buzzed you")));
1291 void yahoohook::got_ft_data(int id
, const unsigned char *in
, int len
, void *data
) {
1294 void yahoohook::auth_request(int id
, const char *who
, const char *msg
) {
1295 imcontact
ic(who
, yahoo
);
1296 string text
= cuthtml(msg
?msg
: "", chCutBR
| chLeaveLinks
);
1298 yhook
.checkinlist(ic
);
1299 text
= yhook
.decode(text
, true);
1301 em
.store(imauthorization(ic
, imevent::incoming
, imauthorization::Request
, text
));
1304 int yahoohook::ylog(const char *fmt
, ...) {
1305 if(conf
->getdebug()) {
1310 vsnprintf(buf
, NOTIFBUF
, fmt
, ap
);
1319 void yahoohook::get_fd(int id
, void *fd
, int error
, void *data
) {
1320 const char *fname
= (const char *) data
;
1321 struct y_c
*con
= (struct y_c
*)fd
;
1331 cw_write(con
->fd
, buf
, f
.tellg(), con
->ssl
);
1338 map
<const char *, imfile
>::iterator ir
= yhook
.srfiles
.find(fname
);
1339 if(ir
!= yhook
.srfiles
.end()) {
1340 face
.transferupdate(fname
, ir
->second
,
1341 error
? icqface::tsError
: icqface::tsFinish
,
1344 yhook
.srfiles
.erase(ir
);
1347 vector
<char *>::iterator i
= find(yhook
.sfiles
.begin(), yhook
.sfiles
.end(), fname
);
1348 if(i
!= yhook
.sfiles
.end()) {
1350 yhook
.sfiles
.erase(i
);
1354 void yahoohook::get_url(int id
, int fd
, int error
, const char *filename
, unsigned long size
, void *data
) {
1356 const char *localname
= (const char *) data
;
1359 vector
<char *>::iterator i
= find(yhook
.sfiles
.begin(), yhook
.sfiles
.end(), localname
);
1360 if(i
!= yhook
.sfiles
.end()) {
1361 ofstream
f(localname
);
1366 FILE *fp
= fdopen(fd
, "r");
1369 r
= fread(buf
, 1, 1024, fp
);
1370 if(r
> 0) f
.write(buf
, r
);
1381 yhook
.sfiles
.erase(i
);
1385 map
<const char *, imfile
>::iterator ir
= yhook
.srfiles
.find(localname
);
1386 if(ir
!= yhook
.srfiles
.end()) {
1387 face
.transferupdate(justfname(localname
), ir
->second
,
1388 error
? icqface::tsError
: icqface::tsFinish
,
1391 yhook
.srfiles
.erase(ir
);