Made proxy settings and consumer key/secret configurable via config file
This commit is contained in:
parent
db3a434e62
commit
3256e6e10c
3 changed files with 51 additions and 19 deletions
|
@ -10,6 +10,7 @@
|
|||
#include "twitcurl.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
|
@ -32,6 +33,15 @@ class TwitterPlugin : public NetworkPlugin {
|
|||
|
||||
TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() {
|
||||
this->config = config;
|
||||
|
||||
if(CONFIG_HAS_KEY(config, "twitter.consumer_key") == false ||
|
||||
CONFIG_HAS_KEY(config, "twitter.consumer_secret") == false) {
|
||||
LOG4CXX_ERROR(logger, "Couldn't find consumer key and/or secret. Please check config file.");
|
||||
exit(0);
|
||||
}
|
||||
consumerKey = CONFIG_STRING(config, "twitter.consumer_key");
|
||||
consumerSecret = CONFIG_STRING(config, "twitter.consumer_secret");
|
||||
|
||||
m_factories = new Swift::BoostNetworkFactories(loop);
|
||||
m_conn = m_factories->getConnectionFactory()->createConnection();
|
||||
m_conn->onDataRead.connect(boost::bind(&TwitterPlugin::_handleDataRead, this, _1));
|
||||
|
@ -70,13 +80,6 @@ class TwitterPlugin : public NetworkPlugin {
|
|||
}
|
||||
|
||||
LOG4CXX_INFO(logger, std::string("Received login request for ") + user)
|
||||
//twitCurl &twitterObj = sessions[user];
|
||||
//std::string myOAuthAccessTokenSecret, myOAuthAccessTokenKey;
|
||||
//twitterObj.getOAuth().getOAuthTokenKey( myOAuthAccessTokenKey );
|
||||
//twitterObj.getOAuth().getOAuthTokenSecret( myOAuthAccessTokenSecret );
|
||||
|
||||
//if(myOAuthAccessTokenSecret.size() && myOAuthAccessTokenKey.size()) {
|
||||
//}
|
||||
|
||||
std::string username = user.substr(0,user.find('@'));
|
||||
std::string passwd = password;
|
||||
|
@ -85,22 +88,33 @@ class TwitterPlugin : public NetworkPlugin {
|
|||
sessions[user] = new twitCurl();
|
||||
handleConnected(user);
|
||||
handleBuddyChanged(user, "twitter-account", "twitter", std::vector<std::string>(), pbnetwork::STATUS_ONLINE);
|
||||
|
||||
// std::string ip = "10.93.0.36";
|
||||
// std::string port = "3128";
|
||||
// std::string puser = "cs09s022";
|
||||
// std::string ppasswd = "";
|
||||
// sessions[user]->setProxyServerIp(ip);
|
||||
// sessions[user]->setProxyServerPort(port);
|
||||
// sessions[user]->setProxyUserName(puser);
|
||||
// sessions[user]->setProxyPassword(ppasswd);
|
||||
|
||||
if(CONFIG_HAS_KEY(config,"proxy.server")) {
|
||||
std::string ip = CONFIG_STRING(config,"proxy.server");
|
||||
|
||||
std::ostringstream out;
|
||||
out << CONFIG_INT(config,"proxy.port");
|
||||
std::string port = out.str();
|
||||
|
||||
std::string puser = CONFIG_STRING(config,"proxy.user");
|
||||
std::string ppasswd = CONFIG_STRING(config,"proxy.password");
|
||||
|
||||
LOG4CXX_INFO(logger, ip << " " << port << " " << puser << " " << ppasswd)
|
||||
|
||||
sessions[user]->setProxyServerIp(ip);
|
||||
sessions[user]->setProxyServerPort(port);
|
||||
sessions[user]->setProxyUserName(puser);
|
||||
sessions[user]->setProxyPassword(ppasswd);
|
||||
}
|
||||
connectionState[user] = NEW;
|
||||
|
||||
sessions[user]->setTwitterUsername(username);
|
||||
sessions[user]->setTwitterPassword(passwd);
|
||||
sessions[user]->getOAuth().setConsumerKey( std::string( "qxfSCX7WN7SZl7dshqGZA" ) );
|
||||
sessions[user]->getOAuth().setConsumerSecret( std::string( "ypWapSj87lswvnksZ46hMAoAZvST4ePGPxAQw6S2o" ) );
|
||||
sessions[user]->getOAuth().setConsumerKey(consumerKey);
|
||||
sessions[user]->getOAuth().setConsumerSecret(consumerSecret);
|
||||
|
||||
// sessions[user]->getOAuth().setConsumerKey( std::string( "qxfSCX7WN7SZl7dshqGZA" ) );
|
||||
// sessions[user]->getOAuth().setConsumerSecret( std::string( "ypWapSj87lswvnksZ46hMAoAZvST4ePGPxAQw6S2o" ) );
|
||||
|
||||
if(registeredUsers.count(user) == 0) {
|
||||
std::string authUrl;
|
||||
|
@ -157,7 +171,6 @@ class TwitterPlugin : public NetworkPlugin {
|
|||
return;
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, "Updating status for " << user << ": " << data);
|
||||
std::string replyMsg;
|
||||
if( sessions[user]->statusUpdate( data ) ) {
|
||||
sessions[user]->getLastWebResponse( replyMsg );
|
||||
|
@ -167,6 +180,8 @@ class TwitterPlugin : public NetworkPlugin {
|
|||
sessions[user]->getLastCurlError( replyMsg );
|
||||
LOG4CXX_INFO(logger, "twitterClient:: twitCurl::statusUpdate error: " << replyMsg );
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, "Updated status for " << user << ": " << data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -184,6 +199,8 @@ class TwitterPlugin : public NetworkPlugin {
|
|||
enum status {NEW, WAITING_FOR_PIN, CONNECTED, DISCONNECTED};
|
||||
Config *config;
|
||||
UserDB *db;
|
||||
std::string consumerKey;
|
||||
std::string consumerSecret;
|
||||
std::set<std::string> registeredUsers;
|
||||
std::map<std::string, twitCurl*> sessions;
|
||||
std::map<std::string, status> connectionState;
|
||||
|
|
|
@ -39,3 +39,11 @@ prefix=icq
|
|||
#user=root
|
||||
#password=yourrootsqlpassword
|
||||
#encryption_key=hanzzik
|
||||
[twitter]
|
||||
consumer_key=qxfSCX7WN7SZl7dshqGZA
|
||||
consumer_secret=ypWapSj87lswvnksZ46hMAoAZvST4ePGPxAQw6S2o
|
||||
[proxy]
|
||||
server=10.93.0.36
|
||||
port=3128
|
||||
user=cs09s022
|
||||
password=your_proxy_password
|
||||
|
|
|
@ -112,6 +112,13 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
|
|||
("backend.default_avatar", value<std::string>()->default_value(""), "Full path to default avatar")
|
||||
("backend.avatars_directory", value<std::string>()->default_value(""), "Path to directory with avatars")
|
||||
("backend.no_vcard_fetch", value<bool>()->default_value(false), "True if VCards for buddies should not be fetched. Only avatars will be forwarded.")
|
||||
("twitter.consumer_key", value<std::string>()->default_value(""), "Twitter APP Consumer Key.")
|
||||
("twitter.consumer_secret", value<std::string>()->default_value(""), "Twitter APP Consumer Secret")
|
||||
("proxy.server", value<std::string>()->default_value("localhost"), "Proxy IP.")
|
||||
("proxy.user", value<std::string>()->default_value(""), "Proxy user.")
|
||||
("proxy.password", value<std::string>()->default_value(""), "Proxy Password.")
|
||||
("proxy.port", value<int>()->default_value(0), "Proxy port.")
|
||||
|
||||
;
|
||||
|
||||
parsed_options parsed = parse_config_file(ifs, opts, true);
|
||||
|
|
Loading…
Add table
Reference in a new issue