libyahoo2 skeleton
This commit is contained in:
parent
cc1d4ac9db
commit
bdf9537a89
1 changed files with 404 additions and 3 deletions
|
@ -3,6 +3,13 @@
|
|||
#include "transport/networkplugin.h"
|
||||
#include "transport/logging.h"
|
||||
|
||||
// Yahoo2
|
||||
#include <yahoo2.h>
|
||||
#include <yahoo2_callbacks.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Swiften
|
||||
#include "Swiften/Swiften.h"
|
||||
|
||||
|
@ -18,6 +25,35 @@ using namespace boost::filesystem;
|
|||
using namespace boost::program_options;
|
||||
using namespace Transport;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
boost::shared_ptr<Swift::Connection> conn;
|
||||
int status;
|
||||
std::string msg;
|
||||
std::string buffer;
|
||||
} yahoo_local_account;
|
||||
|
||||
static std::string *currently_read_data;
|
||||
|
||||
typedef struct {
|
||||
std::string yahoo_id;
|
||||
std::string name;
|
||||
int status;
|
||||
int away;
|
||||
std::string msg;
|
||||
std::string group;
|
||||
} yahoo_account;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
char *label;
|
||||
} yahoo_idlabel;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
char *who;
|
||||
} yahoo_authorize_data;
|
||||
|
||||
DEFINE_LOGGER(logger, "Yahoo2");
|
||||
|
||||
// eventloop
|
||||
|
@ -55,9 +91,19 @@ class YahooPlugin : public NetworkPlugin {
|
|||
}
|
||||
|
||||
void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
|
||||
handleConnected(user);
|
||||
LOG4CXX_INFO(logger, user << ": Added buddy - Echo.");
|
||||
handleBuddyChanged(user, "echo", "Echo", std::vector<std::string>(), pbnetwork::STATUS_ONLINE);
|
||||
yahoo_local_account *account = new yahoo_local_account;
|
||||
m_users[user] = account;
|
||||
|
||||
account->id = yahoo_init_with_attributes(legacyName.c_str(), password.c_str(),
|
||||
"local_host", "",
|
||||
"pager_port", 5050,
|
||||
NULL);
|
||||
m_ids[account->id] = user;
|
||||
|
||||
account->status = YAHOO_STATUS_OFFLINE;
|
||||
yahoo_login(account->id, YAHOO_STATUS_AVAILABLE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void handleLogoutRequest(const std::string &user, const std::string &legacyName) {
|
||||
|
@ -79,8 +125,38 @@ class YahooPlugin : public NetworkPlugin {
|
|||
|
||||
}
|
||||
|
||||
void _yahoo_connect_finished(yahoo_local_account *account, yahoo_connect_callback callback, void *data, bool error) {
|
||||
if (error) {
|
||||
callback(NULL, 0, data);
|
||||
}
|
||||
else {
|
||||
callback(account->conn.get(), 0, data);
|
||||
}
|
||||
}
|
||||
|
||||
void _yahoo_data_read(yahoo_local_account *account, boost::shared_ptr<Swift::SafeByteArray> data) {
|
||||
std::string d(data->begin(), data->end());
|
||||
currently_read_data = &d;
|
||||
yahoo_read_ready(account->id, account->conn.get(), NULL);
|
||||
}
|
||||
|
||||
int _yahoo_connect_async(int id, const char *host, int port, yahoo_connect_callback callback, void *data, int use_ssl) {
|
||||
yahoo_local_account *account = m_users[m_ids[id]];
|
||||
if (!account) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
account->conn = m_factories->getConnectionFactory()->createConnection();
|
||||
m_conn->onConnectFinished.connect(boost::bind(&YahooPlugin::_yahoo_connect_finished, this, account, callback, data, _1));
|
||||
m_conn->onDataRead.connect(boost::bind(&YahooPlugin::_yahoo_data_read, this, account, _1));
|
||||
account->conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port));
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
Config *config;
|
||||
std::map<std::string, yahoo_local_account *> m_users;
|
||||
std::map<int, std::string> m_ids;
|
||||
};
|
||||
|
||||
static void spectrum_sigchld_handler(int sig)
|
||||
|
@ -99,6 +175,329 @@ static void spectrum_sigchld_handler(int sig)
|
|||
}
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_conf_invite(int id, const char *me, const char *who, const char *room, const char *msg, YList *members) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_conf_userdecline(int id, const char *me, const char *who, const char *room, const char *msg) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_conf_userjoin(int id, const char *me, const char *who, const char *room) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_conf_userleave(int id, const char *me, const char *who, const char *room) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_conf_message(int id, const char *me, const char *who, const char *room, const char *msg, int utf8) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_cat_xml(int id, const char *xml) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_join(int id, const char *me, const char *room, const char * topic, YList *members, void *fd) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_userjoin(int id, const char *me, const char *room, struct yahoo_chat_member *who) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_userleave(int id, const char *me, const char *room, const char *who) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_message(int id, const char *me, const char *who, const char *room, const char *msg, int msgtype, int utf8) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_status_changed(int id, const char *who, int stat, const char *msg, int away, int idle, int mobile) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buddies(int id, YList * buds) {
|
||||
// while(buddies) {
|
||||
// FREE(buddies->data);
|
||||
// buddies = buddies->next;
|
||||
// if(buddies)
|
||||
// FREE(buddies->prev);
|
||||
// }
|
||||
// for(; buds; buds = buds->next) {
|
||||
// yahoo_account *ya = y_new0(yahoo_account, 1);
|
||||
// struct yahoo_buddy *bud = buds->data;
|
||||
// strncpy(ya->yahoo_id, bud->id, 255);
|
||||
// if(bud->real_name)
|
||||
// strncpy(ya->name, bud->real_name, 255);
|
||||
// strncpy(ya->group, bud->group, 255);
|
||||
// ya->status = YAHOO_STATUS_OFFLINE;
|
||||
// buddies = y_list_append(buddies, ya);
|
||||
//
|
||||
// /* print_message(("%s is %s", bud->id, bud->real_name));*/
|
||||
// }
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_ignore(int id, YList * igns)
|
||||
{
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buzz(int id, const char *me, const char *who, long tm) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_im(int id, const char *me, const char *who, const char *msg, long tm, int stat, int utf8) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_rejected(int id, const char *who, const char *msg) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_contact_added(int id, const char *myid, const char *who, const char *msg) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_typing_notify(int id, const char* me, const char *who, int stat) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_game_notify(int id, const char *me, const char *who, int stat, const char *msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void ext_yahoo_mail_notify(int id, const char *from, const char *subj, int cnt) {
|
||||
}
|
||||
|
||||
static 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) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_webcam_viewer(int id, const char *who, int connect) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_webcam_closed(int id, const char *who, int reason) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_webcam_data_request(int id, int send) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_webcam_invite(int id, const char *me, const char *from) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_webcam_invite_reply(int id, const char *me, const char *from, int accept) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_system_message(int id, const char *me, const char *who, const char *msg) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_cookies(int id) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_login_response(int id, int succ, const char *url) {
|
||||
// char buff[1024];
|
||||
//
|
||||
// if(succ == YAHOO_LOGIN_OK) {
|
||||
// ylad->status = yahoo_current_status(id);
|
||||
// print_message(("logged in"));
|
||||
// return;
|
||||
//
|
||||
// } else if(succ == YAHOO_LOGIN_UNAME) {
|
||||
//
|
||||
// snprintf(buff, sizeof(buff), "Could not log into Yahoo service - username not recognised. Please verify that your username is correctly typed.");
|
||||
// } else if(succ == YAHOO_LOGIN_PASSWD) {
|
||||
//
|
||||
// snprintf(buff, sizeof(buff), "Could not log into Yahoo service - password incorrect. Please verify that your password is correctly typed.");
|
||||
//
|
||||
// } else if(succ == YAHOO_LOGIN_LOCK) {
|
||||
//
|
||||
// snprintf(buff, sizeof(buff), "Could not log into Yahoo service. Your account has been locked.\nVisit %s to reactivate it.", url);
|
||||
//
|
||||
// } else if(succ == YAHOO_LOGIN_DUPL) {
|
||||
//
|
||||
// snprintf(buff, sizeof(buff), "You have been logged out of the yahoo service, possibly due to a duplicate login.");
|
||||
// } else if(succ == YAHOO_LOGIN_SOCK) {
|
||||
//
|
||||
// snprintf(buff, sizeof(buff), "The server closed the socket.");
|
||||
// } else {
|
||||
// snprintf(buff, sizeof(buff), "Could not log in, unknown reason: %d.", succ);
|
||||
// }
|
||||
//
|
||||
// ylad->status = YAHOO_STATUS_OFFLINE;
|
||||
// print_message((buff));
|
||||
// yahoo_logout();
|
||||
// poll_loop=0;
|
||||
}
|
||||
|
||||
static void ext_yahoo_error(int id, const char *_err, int fatal, int num) {
|
||||
std::string err(_err);
|
||||
std::string msg("Yahoo Error: ");
|
||||
msg += err + " - ";
|
||||
switch(num) {
|
||||
case E_UNKNOWN:
|
||||
msg += "unknown error " + err;
|
||||
break;
|
||||
case E_CUSTOM:
|
||||
msg += "custom error " + err;
|
||||
break;
|
||||
case E_CONFNOTAVAIL:
|
||||
msg += err + " is not available for the conference";
|
||||
break;
|
||||
case E_IGNOREDUP:
|
||||
msg += err + " is already ignored";
|
||||
break;
|
||||
case E_IGNORENONE:
|
||||
msg += err +" is not in the ignore list";
|
||||
break;
|
||||
case E_IGNORECONF:
|
||||
msg += err + " is in buddy list - cannot ignore ";
|
||||
break;
|
||||
case E_SYSTEM:
|
||||
msg += "system error " + err;
|
||||
break;
|
||||
case E_CONNECTION:
|
||||
msg += err + "server connection error %s";
|
||||
break;
|
||||
}
|
||||
LOG4CXX_ERROR(logger, msg);
|
||||
// if(fatal)
|
||||
// yahoo_logout();
|
||||
}
|
||||
|
||||
static int ext_yahoo_connect(const char *host, int port) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int ext_yahoo_add_handler(int id, void *d, yahoo_input_condition cond, void *data) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_remove_handler(int id, int tag) {
|
||||
}
|
||||
|
||||
static int ext_yahoo_write(void *_conn, char *buf, int len) {
|
||||
std::string string(buf, len);
|
||||
Swift::Connection *conn = (Swift::Connection *) _conn;
|
||||
conn->write(Swift::createSafeByteArray(string));
|
||||
return len;
|
||||
}
|
||||
|
||||
static int ext_yahoo_read(void *fd, char *buf, int len) {
|
||||
if (currently_read_data->size() < len) {
|
||||
len = currently_read_data->size();
|
||||
}
|
||||
strncpy(buf, currently_read_data->c_str(), len);
|
||||
currently_read_data->erase(0, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
static void ext_yahoo_close(void *fd) {
|
||||
}
|
||||
|
||||
static int ext_yahoo_connect_async(int id, const char *host, int port, yahoo_connect_callback callback, void *data, int use_ssl) {
|
||||
return np->_yahoo_connect_async(id, host, port, callback, data, use_ssl);
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_file(int id, const char *me, const char *who, const char *msg, const char *fname, unsigned long fesize, char *trid) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_file_transfer_done(int id, int response, void *data) {
|
||||
}
|
||||
|
||||
static char *ext_yahoo_get_ip_addr(const char *domain) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_ft_data(int id, const unsigned char *in, int count, void *data) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_identities(int id, YList * ids) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_yahoologout(int id, const char *me) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_chat_yahooerror(int id, const char *me) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_ping(int id, const char *errormsg){
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_search_result(int id, int found, int start, int total, YList *contacts) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buddyicon_checksum(int id, const char *a, const char *b, int checksum) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buddy_change_group(int id, const char *me, const char *who, const char *old_group, const char *new_group) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buddyicon(int id, const char *a, const char *b, const char *c, int checksum) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_buddyicon_uploaded(int id, const char *url) {
|
||||
}
|
||||
|
||||
static void ext_yahoo_got_buddyicon_request(int id, const char *me, const char *who) {
|
||||
}
|
||||
|
||||
static int ext_yahoo_log(const char *fmt,...)
|
||||
{
|
||||
static char log[8192];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
|
||||
vsnprintf(log, 8191, fmt, ap);
|
||||
LOG4CXX_INFO(logger, log);
|
||||
fflush(stderr);
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void register_callbacks()
|
||||
{
|
||||
static struct yahoo_callbacks yc;
|
||||
|
||||
yc.ext_yahoo_login_response = ext_yahoo_login_response;
|
||||
yc.ext_yahoo_got_buddies = ext_yahoo_got_buddies;
|
||||
yc.ext_yahoo_got_ignore = ext_yahoo_got_ignore;
|
||||
yc.ext_yahoo_got_identities = ext_yahoo_got_identities;
|
||||
yc.ext_yahoo_got_cookies = ext_yahoo_got_cookies;
|
||||
yc.ext_yahoo_status_changed = ext_yahoo_status_changed;
|
||||
yc.ext_yahoo_got_im = ext_yahoo_got_im;
|
||||
yc.ext_yahoo_got_buzz = ext_yahoo_got_buzz;
|
||||
yc.ext_yahoo_got_conf_invite = ext_yahoo_got_conf_invite;
|
||||
yc.ext_yahoo_conf_userdecline = ext_yahoo_conf_userdecline;
|
||||
yc.ext_yahoo_conf_userjoin = ext_yahoo_conf_userjoin;
|
||||
yc.ext_yahoo_conf_userleave = ext_yahoo_conf_userleave;
|
||||
yc.ext_yahoo_conf_message = ext_yahoo_conf_message;
|
||||
yc.ext_yahoo_chat_cat_xml = ext_yahoo_chat_cat_xml;
|
||||
yc.ext_yahoo_chat_join = ext_yahoo_chat_join;
|
||||
yc.ext_yahoo_chat_userjoin = ext_yahoo_chat_userjoin;
|
||||
yc.ext_yahoo_chat_userleave = ext_yahoo_chat_userleave;
|
||||
yc.ext_yahoo_chat_message = ext_yahoo_chat_message;
|
||||
yc.ext_yahoo_chat_yahoologout = ext_yahoo_chat_yahoologout;
|
||||
yc.ext_yahoo_chat_yahooerror = ext_yahoo_chat_yahooerror;
|
||||
yc.ext_yahoo_got_webcam_image = ext_yahoo_got_webcam_image;
|
||||
yc.ext_yahoo_webcam_invite = ext_yahoo_webcam_invite;
|
||||
yc.ext_yahoo_webcam_invite_reply = ext_yahoo_webcam_invite_reply;
|
||||
yc.ext_yahoo_webcam_closed = ext_yahoo_webcam_closed;
|
||||
yc.ext_yahoo_webcam_viewer = ext_yahoo_webcam_viewer;
|
||||
yc.ext_yahoo_webcam_data_request = ext_yahoo_webcam_data_request;
|
||||
yc.ext_yahoo_got_file = ext_yahoo_got_file;
|
||||
yc.ext_yahoo_got_ft_data = ext_yahoo_got_ft_data;
|
||||
yc.ext_yahoo_get_ip_addr = ext_yahoo_get_ip_addr;
|
||||
yc.ext_yahoo_file_transfer_done = ext_yahoo_file_transfer_done;
|
||||
yc.ext_yahoo_contact_added = ext_yahoo_contact_added;
|
||||
yc.ext_yahoo_rejected = ext_yahoo_rejected;
|
||||
yc.ext_yahoo_typing_notify = ext_yahoo_typing_notify;
|
||||
yc.ext_yahoo_game_notify = ext_yahoo_game_notify;
|
||||
yc.ext_yahoo_mail_notify = ext_yahoo_mail_notify;
|
||||
yc.ext_yahoo_got_search_result = ext_yahoo_got_search_result;
|
||||
yc.ext_yahoo_system_message = ext_yahoo_system_message;
|
||||
yc.ext_yahoo_error = ext_yahoo_error;
|
||||
yc.ext_yahoo_log = ext_yahoo_log;
|
||||
yc.ext_yahoo_add_handler = ext_yahoo_add_handler;
|
||||
yc.ext_yahoo_remove_handler = ext_yahoo_remove_handler;
|
||||
yc.ext_yahoo_connect = ext_yahoo_connect;
|
||||
yc.ext_yahoo_connect_async = ext_yahoo_connect_async;
|
||||
yc.ext_yahoo_read = ext_yahoo_read;
|
||||
yc.ext_yahoo_write = ext_yahoo_write;
|
||||
yc.ext_yahoo_close = ext_yahoo_close;
|
||||
yc.ext_yahoo_got_buddyicon = ext_yahoo_got_buddyicon;
|
||||
yc.ext_yahoo_got_buddyicon_checksum = ext_yahoo_got_buddyicon_checksum;
|
||||
yc.ext_yahoo_buddyicon_uploaded = ext_yahoo_buddyicon_uploaded;
|
||||
yc.ext_yahoo_got_buddyicon_request = ext_yahoo_got_buddyicon_request;
|
||||
yc.ext_yahoo_got_ping = ext_yahoo_got_ping;
|
||||
yc.ext_yahoo_got_buddy_change_group = ext_yahoo_got_buddy_change_group;
|
||||
|
||||
yahoo_register_callbacks(&yc);
|
||||
}
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
std::string host;
|
||||
|
@ -144,6 +543,8 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
Logging::initBackendLogging(&config);
|
||||
|
||||
register_callbacks();
|
||||
|
||||
Swift::SimpleEventLoop eventLoop;
|
||||
loop_ = &eventLoop;
|
||||
np = new YahooPlugin(&config, &eventLoop, host, port);
|
||||
|
|
Loading…
Add table
Reference in a new issue