Changeset - d93cc2ce66eb
backends/libpurple/main.cpp
Show inline comments
 
@@ -188,13 +188,13 @@ static std::string OAUTH_TOKEN = "hangouts_oauth_token";
 

	
 
static bool getUserOAuthToken(const std::string user, std::string &token)
 
{
 
	boost::mutex::scoped_lock lock(dblock);
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
    LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		return false;
 
	}
 
	token = "";
 
	int type = TYPE_STRING;
 
	storagebackend->getUserSetting((long)info.id, OAUTH_TOKEN, type, token);
 
	return true;
 
@@ -202,13 +202,13 @@ static bool getUserOAuthToken(const std::string user, std::string &token)
 

	
 
static bool storeUserOAuthToken(const std::string user, const std::string OAuthToken)
 
{
 
	boost::mutex::scoped_lock lock(dblock);
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
    LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		return false;
 
	}
 
	storagebackend->updateUserSetting((long)info.id, OAUTH_TOKEN, OAuthToken);
 
	return true;
 
}
 

	
 
@@ -427,13 +427,13 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			const PurpleStatusType *status_type = purple_account_get_status_type_with_primitive_wrapped(account, PURPLE_STATUS_AVAILABLE);
 
			if (status_type != NULL) {
 
				purple_account_set_status_wrapped(account, purple_status_type_get_id_wrapped(status_type), TRUE, NULL);
 
			}
 
			// OAuth helper
 
			if (protocol == "prpl-hangouts") {
 
				LOG4CXX_INFO(logger, user << ": Adding Buddy " << adminLegacyName << " " << adminAlias)
 
				LOG4CXX_INFO(logger, user << ": Adding Buddy " << adminLegacyName << " " << adminAlias);
 
				handleBuddyChanged(user, adminLegacyName, adminAlias, std::vector<std::string>(), pbnetwork::STATUS_ONLINE);
 
			}
 
		}
 

	
 
		void handleLogoutRequest(const std::string &user, const std::string &legacyName) {
 
			PurpleAccount *account = m_sessions[user];
 
@@ -2284,13 +2284,13 @@ int main(int argc, char **argv) {
 
		if (storagebackend == NULL) {
 
			LOG4CXX_ERROR(logger, "Error creating StorageBackend! " << error);
 
			LOG4CXX_ERROR(logger, "Hangouts backend needs storage backend configured to work! " << error);
 
			return NetworkPlugin::StorageBackendNeeded;
 
		}
 
		else if (!storagebackend->connect()) {
 
			LOG4CXX_ERROR(logger, "Can't connect to database!")
 
			LOG4CXX_ERROR(logger, "Can't connect to database!");
 
			return -1;
 
		}
 
	}
 

	
 
	initPurple();
 

	
backends/smstools3/main.cpp
Show inline comments
 
@@ -79,13 +79,13 @@ class SMSNetworkPlugin : public NetworkPlugin {
 
			storageBackend->getUser(INTERNAL_USER, info);
 
			m_internalUser = info.id;
 
		}
 

	
 

	
 
		void handleSMS(const std::string &sms) {
 
			LOG4CXX_INFO(logger, "Handling SMS " << sms << ".")
 
			LOG4CXX_INFO(logger, "Handling SMS " << sms << ".");
 
			std::ifstream t(sms.c_str());
 
			std::string str;
 

	
 
			t.seekg(0, std::ios::end);
 
			str.reserve(t.tellg());
 
			t.seekg(0, std::ios::beg);
backends/twitter/HTTPRequest.cpp
Show inline comments
 
@@ -8,13 +8,13 @@ bool HTTPRequest::init()
 
		curlhandle = curl_easy_init();
 
		curl_easy_setopt(curlhandle, CURLOPT_PROXY, NULL);
 
		curl_easy_setopt(curlhandle, CURLOPT_PROXYUSERPWD, NULL);
 
		curl_easy_setopt(curlhandle, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
 
		return true;
 
	}
 
	LOG4CXX_ERROR(logger, "Couldn't Initialize curl!")
 
	LOG4CXX_ERROR(logger, "Couldn't Initialize curl!");
 
	return false;
 
}
 

	
 
void HTTPRequest::setProxy(std::string IP, std::string port, std::string username, std::string password)
 
{
 
	if(curlhandle) {
 
@@ -22,13 +22,13 @@ void HTTPRequest::setProxy(std::string IP, std::string port, std::string usernam
 
		curl_easy_setopt(curlhandle, CURLOPT_PROXY, proxyIpPort.c_str());
 
		if(username.length() && password.length()) {
 
			std::string proxyUserPass = username + ":" + password;
 
			curl_easy_setopt(curlhandle, CURLOPT_PROXYUSERPWD, proxyUserPass.c_str());
 
		}
 
	} else {
 
		LOG4CXX_ERROR(logger, "Trying to set proxy while CURL isn't initialized")
 
		LOG4CXX_ERROR(logger, "Trying to set proxy while CURL isn't initialized");
 
	}
 
}
 

	
 
int HTTPRequest::curlCallBack(char* data, size_t size, size_t nmemb, HTTPRequest* obj)
 
{
 
	int writtenSize = 0;
 
@@ -62,11 +62,11 @@ bool HTTPRequest::GET(std::string url, 	std::string &data)
 
		/* Send http request and return status*/
 
		if(CURLE_OK == curl_easy_perform(curlhandle)) {
 
			data = callbackdata;
 
			return true;
 
		}
 
	} else {
 
		LOG4CXX_ERROR(logger, "CURL not initialized!")
 
		LOG4CXX_ERROR(logger, "CURL not initialized!");
 
		strcpy(curl_errorbuffer, "CURL not initialized!");
 
	}
 
	return false;
 
}
backends/twitter/Requests/CreateFriendRequest.cpp
Show inline comments
 
#include "CreateFriendRequest.h"
 
#include "../HTTPRequest.h"
 
DEFINE_LOGGER(logger, "CreateFriendRequest")
 

	
 
void CreateFriendRequest::run()
 
{
 
	LOG4CXX_INFO(logger, user << " - Sending follow request for " << frnd)
 
	LOG4CXX_INFO(logger, user << " - Sending follow request for " << frnd);
 
	replyMsg = "";
 
	success = twitObj->friendshipCreate(frnd, false);
 
	if(success) {
 
		twitObj->getLastWebResponse(replyMsg);
 

	
 
		LOG4CXX_INFO(logger, user << replyMsg)		
 
		LOG4CXX_INFO(logger, user << replyMsg);
 

	
 
	   	friendInfo = getUser(replyMsg);
 
		if(friendInfo.getScreenName() == "") {LOG4CXX_INFO(logger, user << " - Was unable to fetch user info for " << frnd)}
 
		if(friendInfo.getScreenName() == "") LOG4CXX_INFO(logger, user << " - Was unable to fetch user info for " << frnd);
 

	
 
		HTTPRequest req;
 
		std::string img;
 

	
 
		req.init();
 
		req.setProxy(twitObj->getProxyServerIp(), twitObj->getProxyServerPort(), twitObj->getProxyUserName(), twitObj->getProxyPassword());
 
@@ -34,17 +34,17 @@ void CreateFriendRequest::finalize()
 
{
 
	Error error;
 
	if(!success) {
 
		std::string curlerror;
 
		twitObj->getLastCurlError(curlerror);
 
		error.setMessage(curlerror);
 
		LOG4CXX_ERROR(logger, user << " - Curl error: " << curlerror)
 
		LOG4CXX_ERROR(logger, user << " - Curl error: " << curlerror);
 
		callBack(user, friendInfo, profileImg, error);
 
	} else {
 
		error = getErrorMessage(replyMsg);
 
		if(error.getMessage().length()) {
 
			LOG4CXX_ERROR(logger, user << " - " << error.getMessage())
 
			LOG4CXX_ERROR(logger, user << " - " << error.getMessage());
 
		}
 
		else LOG4CXX_INFO(logger, user << ": Now following " << frnd)
 
		else LOG4CXX_INFO(logger, user << ": Now following " << frnd);
 
		callBack(user, friendInfo, profileImg, error);
 
	}
 
}
backends/twitter/Requests/DestroyFriendRequest.cpp
Show inline comments
 
@@ -5,13 +5,13 @@ void DestroyFriendRequest::run()
 
{
 
	replyMsg = "";
 
	success = twitObj->friendshipDestroy(frnd, false);
 
	if(success) {
 
		twitObj->getLastWebResponse(replyMsg);
 

	
 
		LOG4CXX_INFO(logger, user << replyMsg)		
 
		LOG4CXX_INFO(logger, user << replyMsg);
 

	
 

	
 
	   	friendInfo = getUser(replyMsg);
 
		if(friendInfo.getScreenName() == "") LOG4CXX_INFO(logger, user << " - Was unable to fetch user info for " << frnd);
 
	}
 
}
 
@@ -20,14 +20,14 @@ void DestroyFriendRequest::finalize()
 
{
 
	Error error;
 
	if(!success) {
 
		std::string curlerror;
 
		twitObj->getLastCurlError(curlerror);
 
		error.setMessage(curlerror);
 
		LOG4CXX_ERROR(logger, user << " Curl error: " << curlerror)
 
		LOG4CXX_ERROR(logger, user << " Curl error: " << curlerror);
 
		callBack(user, friendInfo, error);
 
	} else {
 
		error = getErrorMessage(replyMsg);
 
		if(error.getMessage().length()) LOG4CXX_ERROR(logger, user << " - " << error.getMessage())
 
		if(error.getMessage().length()) LOG4CXX_ERROR(logger, user << " - " << error.getMessage());
 
		callBack(user, friendInfo, error);
 
	}
 
}
backends/twitter/Requests/DirectMessageRequest.cpp
Show inline comments
 
@@ -22,11 +22,14 @@ void DirectMessageRequest::finalize()
 
		twitObj->getLastCurlError(curlerror);
 
		error.setMessage(curlerror);
 
		LOG4CXX_ERROR(logger, user << " Curl error: " << curlerror);
 
		callBack(user, username, messages, error);
 
	} else {
 
		error = getErrorMessage(replyMsg);
 
		if(error.getMessage().length()) LOG4CXX_ERROR(logger,  user << " - " << error.getMessage())
 
		else LOG4CXX_INFO(logger, user << " - " << replyMsg)
 
		if(error.getMessage().length()) {
 
			LOG4CXX_ERROR(logger,  user << " - " << error.getMessage());
 
		} else {
 
			LOG4CXX_INFO(logger, user << " - " << replyMsg);
 
		}
 
		callBack(user, username, messages, error);
 
	}
 
}
backends/twitter/Requests/FetchFriends.cpp
Show inline comments
 
@@ -25,26 +25,26 @@ void FetchFriends::run()
 

	
 
	for(int i=0 ; i<friends.size() ; i++) {
 
		std::string img;
 
		friendAvatars.push_back("");
 
		if(req.GET(friends[i].getProfileImgURL(), img)) friendAvatars[i] = img;
 
		else {
 
			LOG4CXX_INFO(logger, "Warning: Couldn't fetch Profile Image for " << user << "'s friend " << friends[i].getScreenName())
 
			LOG4CXX_INFO(logger, "Warning: Couldn't fetch Profile Image for " << user << "'s friend " << friends[i].getScreenName());
 
		}
 
	}
 
}
 

	
 
void FetchFriends::finalize()
 
{
 
	Error error;
 
	if(!success) {
 
		std::string curlerror;
 
		twitObj->getLastCurlError(curlerror);
 
		error.setMessage(curlerror);
 
		LOG4CXX_ERROR(logger,  user << " - " << curlerror)
 
		LOG4CXX_ERROR(logger,  user << " - " << curlerror);
 
		callBack(user, friends, friendAvatars, error);
 
	} else {
 
		error = getErrorMessage(replyMsg);
 
		if(error.getMessage().length()) LOG4CXX_ERROR(logger,  user << " - " << error.getMessage())
 
		if(error.getMessage().length()) LOG4CXX_ERROR(logger,  user << " - " << error.getMessage());
 
		callBack(user, friends, friendAvatars, error);
 
	}
 
}
backends/twitter/Requests/PINExchangeProcess.cpp
Show inline comments
 
#include "PINExchangeProcess.h"
 
DEFINE_LOGGER(logger, "PINExchangeProcess")
 
void PINExchangeProcess::run()
 
{
 
	LOG4CXX_INFO(logger, user << ": Sending PIN " << data) 
 
	LOG4CXX_INFO(logger, user << " " << twitObj->getProxyServerIp() << " " << twitObj->getProxyServerPort())
 
	LOG4CXX_INFO(logger, user << ": Sending PIN " << data);
 
	LOG4CXX_INFO(logger, user << " " << twitObj->getProxyServerIp() << " " << twitObj->getProxyServerPort());
 
	twitObj->getOAuth().setOAuthPin( data );
 
	success = twitObj->oAuthAccessToken();
 
}
 

	
 
void PINExchangeProcess::finalize()
 
{
 
	if(!success) {
 
		LOG4CXX_ERROR(logger, user << ": Error while exchanging PIN for Access Token!")
 
		LOG4CXX_ERROR(logger, user << ": Error while exchanging PIN for Access Token!");
 
		np->handleMessage(user, "twitter.com", "Error while exchanging PIN for Access Token!");
 
		np->handleLogoutRequest(user, "");
 
	} else {
 
		std::string replyMsg;
 
		while(replyMsg.length() == 0) {
 
			twitObj->getLastWebResponse(replyMsg);
 
		}
 

	
 
		Error error = getErrorMessage(replyMsg);
 
		if(error.getMessage().length()) {
 
			LOG4CXX_ERROR(logger, user << ": Error while exchanging PIN for Access Token! " << error.getMessage())
 
			LOG4CXX_ERROR(logger, user << ": Error while exchanging PIN for Access Token! " << error.getMessage());
 
			np->handleMessage(user, "twitter.com", error.getMessage());
 
			np->handleLogoutRequest(user, "");
 
			return;
 
		}
 

	
 

	
 
@@ -44,24 +44,24 @@ void PINExchangeProcess::finalize()
 
	}
 
}
 

	
 
/*void handlePINExchange(const std::string &user, std::string &data) {
 
	sessions[user]->getOAuth().setOAuthPin( data );
 
	if (sessions[user]->oAuthAccessToken() == false) {
 
		LOG4CXX_ERROR(logger, user << ": Error while exchanging PIN for Access Token!")
 
		LOG4CXX_ERROR(logger, user << ": Error while exchanging PIN for Access Token!");
 
		handleLogoutRequest(user, "");
 
		return;
 
	}
 

	
 
	std::string OAuthAccessTokenKey, OAuthAccessTokenSecret;
 
	sessions[user]->getOAuth().getOAuthTokenKey( OAuthAccessTokenKey );
 
	sessions[user]->getOAuth().getOAuthTokenSecret( OAuthAccessTokenSecret );
 

	
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		handleLogoutRequest(user, "");
 
		return;
 
	}
 

	
 
	storagebackend->updateUserSetting((long)info.id, OAUTH_KEY, OAuthAccessTokenKey);
 
	storagebackend->updateUserSetting((long)info.id, OAUTH_SECRET, OAuthAccessTokenSecret);
backends/twitter/Requests/ProfileImageRequest.cpp
Show inline comments
 
@@ -11,13 +11,13 @@ void ProfileImageRequest::run()
 
}
 

	
 
void ProfileImageRequest::finalize()
 
{
 
	Error errResponse;
 
	if(!success) {
 
		LOG4CXX_ERROR(logger,  user << " - " << error)
 
		LOG4CXX_ERROR(logger,  user << " - " << error);
 
		img = "";
 
		errResponse.setMessage(error);
 
		callBack(user, buddy, img, reqID, errResponse);
 
	} else {
 
		LOG4CXX_INFO(logger, user << " - " << callbackdata);
 
		img = callbackdata;
backends/twitter/Requests/RetweetRequest.cpp
Show inline comments
 
#include "RetweetRequest.h"
 
DEFINE_LOGGER(logger, "RetweetRequest")
 
void RetweetRequest::run()
 
{
 
	LOG4CXX_INFO(logger, user << " Retweeting " << data)
 
	LOG4CXX_INFO(logger, user << " Retweeting " << data);
 
	success = twitObj->retweetById( data );
 
}
 

	
 
void RetweetRequest::finalize()
 
{
 
	Error error;
 
	if(!success) {
 
		std::string curlerror;
 
		twitObj->getLastCurlError(curlerror);
 
		error.setMessage(curlerror);
 
		LOG4CXX_ERROR(logger, user << " Curl error: " << curlerror)
 
		LOG4CXX_ERROR(logger, user << " Curl error: " << curlerror);
 
		callBack(user, error);
 
	} else {
 
		twitObj->getLastWebResponse(replyMsg);
 
		error = getErrorMessage(replyMsg);
 
		if(error.getMessage().length()) LOG4CXX_ERROR(logger, user << " - " << error.getMessage())
 
		else LOG4CXX_INFO(logger, user << " " << replyMsg);
 
		if(error.getMessage().length()) {
 
			LOG4CXX_ERROR(logger, user << " - " << error.getMessage());
 
		} else {
 
			LOG4CXX_INFO(logger, user << " " << replyMsg);
 
		}
 
		callBack(user, error);
 
	}
 
}
backends/twitter/Requests/StatusUpdateRequest.cpp
Show inline comments
 
@@ -20,11 +20,14 @@ void StatusUpdateRequest::finalize()
 
		twitObj->getLastCurlError(curlerror);
 
		error.setMessage(curlerror);
 
		LOG4CXX_ERROR(logger, user << " - Curl error: " << curlerror);
 
		callBack(user, error);
 
	} else {
 
		error = getErrorMessage(replyMsg);
 
		if(error.getMessage().length()) LOG4CXX_ERROR(logger, user << " - " << error.getMessage())
 
		else LOG4CXX_INFO(logger, "Updated status for " << user << ": " << data);
 
		if(error.getMessage().length()) {
 
			LOG4CXX_ERROR(logger, user << " - " << error.getMessage());
 
		} else {
 
			LOG4CXX_INFO(logger, "Updated status for " << user << ": " << data);
 
		}
 
		callBack(user, error);
 
	}
 
}
backends/twitter/Requests/TimelineRequest.cpp
Show inline comments
 
#include "TimelineRequest.h"
 
DEFINE_LOGGER(logger, "TimelineRequest")
 
void TimelineRequest::run()
 
{
 
	LOG4CXX_INFO(logger, "Sending timeline request for user " << userRequested)
 
	LOG4CXX_INFO(logger, "Sending timeline request for user " << userRequested);
 

	
 
	if(userRequested != "") success = twitObj->timelineUserGet(false, false, 20, userRequested, false);
 
	else success = twitObj->timelineHomeGet(since_id);
 

	
 
	if(!success) return;
 

	
 
@@ -19,14 +19,14 @@ void TimelineRequest::finalize()
 
{
 
	Error error;
 
	if(!success) {
 
		std::string curlerror;
 
		twitObj->getLastCurlError(curlerror);
 
		error.setMessage(curlerror);
 
		LOG4CXX_ERROR(logger,  user << " - Curl error: " << curlerror)
 
		LOG4CXX_ERROR(logger,  user << " - Curl error: " << curlerror);
 
		callBack(user, userRequested, tweets, error);
 
	} else {
 
		error = getErrorMessage(replyMsg);
 
		if(error.getMessage().length()) LOG4CXX_ERROR(logger,  user << " - " << error.getMessage())
 
		if(error.getMessage().length()) LOG4CXX_ERROR(logger,  user << " - " << error.getMessage());
 
		callBack(user, userRequested, tweets, error);
 
	}
 
}
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -127,37 +127,37 @@ void TwitterPlugin::_handleDataRead(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::
 
// User trying to login into his twitter account
 
void TwitterPlugin::handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password)
 
{
 
	if(userdb.count(user) && (userdb[user].connectionState == NEW ||
 
										userdb[user].connectionState == CONNECTED ||
 
										userdb[user].connectionState == WAITING_FOR_PIN)) {
 
		LOG4CXX_INFO(logger, std::string("A session corresponding to ") + user + std::string(" is already active"))
 
		LOG4CXX_INFO(logger, std::string("A session corresponding to ") + user + std::string(" is already active"));
 
		return;
 
	}
 

	
 
	LOG4CXX_INFO(logger, std::string("Received login request for ") + user)	
 
	LOG4CXX_INFO(logger, std::string("Received login request for ") + user);
 
	initUserSession(user, legacyName, password);
 
	handleConnected(user);
 

	
 
	LOG4CXX_INFO(logger, "SPECTRUM 1 USER? - " << (userdb[user].spectrum1User? "true" : "false")) 
 
	LOG4CXX_INFO(logger, "SPECTRUM 1 USER? - " << (userdb[user].spectrum1User? "true" : "false"));
 

	
 
	LOG4CXX_INFO(logger, user << ": Adding Buddy " << adminLegacyName << " " << adminAlias)
 
	LOG4CXX_INFO(logger, user << ": Adding Buddy " << adminLegacyName << " " << adminAlias);
 
	handleBuddyChanged(user, adminLegacyName, adminAlias, std::vector<std::string>(), pbnetwork::STATUS_ONLINE);
 
	userdb[user].nickName = "";
 

	
 
	LOG4CXX_INFO(logger, "Querying database for usersettings of " << user)
 
	LOG4CXX_INFO(logger, "Querying database for usersettings of " << user);
 
	std::string key, secret;
 
	getUserOAuthKeyAndSecret(user, key, secret);
 

	
 
	if(key == "" || secret == "") {
 
		LOG4CXX_INFO(logger, "Intiating OAuth Flow for user " << user)
 
		LOG4CXX_INFO(logger, "Intiating OAuth Flow for user " << user);
 
		setTwitterMode(user, 0);
 
		tp->runAsThread(new OAuthFlow(np, userdb[user].sessions, user, userdb[user].sessions->getTwitterUsername()));
 
	} else {
 
		LOG4CXX_INFO(logger, user << " is already registerd. Using the stored oauth key and secret")
 
		LOG4CXX_INFO(logger, key << " " << secret)	
 
		LOG4CXX_INFO(logger, user << " is already registerd. Using the stored oauth key and secret");
 
		LOG4CXX_INFO(logger, key << " " << secret);
 
		pinExchangeComplete(user, key, secret);
 
	}
 
}
 

	
 
// User logging out
 
void TwitterPlugin::handleLogoutRequest(const std::string &user, const std::string &legacyName)
 
@@ -174,43 +174,43 @@ void TwitterPlugin::handleLogoutRequest(const std::string &user, const std::stri
 
}
 

	
 
// User joining a Chatroom
 
void TwitterPlugin::handleJoinRoomRequest(const std::string &user, const std::string &room, const std::string &nickname, const std::string &password)
 
{
 
	if(room == adminChatRoom) {
 
		LOG4CXX_INFO(logger, "Received Join Twitter room request for " << user << " '" << nickname << "'")
 
		LOG4CXX_INFO(logger, "Received Join Twitter room request for " << user << " '" << nickname << "'");
 

	
 
		setTwitterMode(user, 2);
 
		handleParticipantChanged(user, nickname, room, 0, pbnetwork::STATUS_ONLINE);
 
		handleParticipantChanged(user, adminNickName, room, 0, pbnetwork::STATUS_ONLINE);
 
		userdb[user].nickName = nickname;
 
		handleMessage(user, adminChatRoom, "Connected to Twitter room! Populating your followers list", adminNickName);
 
		tp->runAsThread(new FetchFriends(userdb[user].sessions, user,
 
										 boost::bind(&TwitterPlugin::populateRoster, this, _1, _2, _3, _4)));
 
	} else {
 
		setTwitterMode(user, 0);
 
		LOG4CXX_ERROR(logger, "Couldn't connect to chatroom - " << room <<"! Try twitter-chatroom as the chatroom to access Twitter account")
 
		LOG4CXX_ERROR(logger, "Couldn't connect to chatroom - " << room <<"! Try twitter-chatroom as the chatroom to access Twitter account");
 
		handleMessage(user, adminLegacyName, "Couldn't connect to chatroom! Try twitter-chatroom as the chatroom to access Twitter account");
 
	}
 
}
 

	
 
// User leaving a Chatroom
 
void TwitterPlugin::handleLeaveRoomRequest(const std::string &user, const std::string &room)
 
{
 
	if(room == adminChatRoom && onlineUsers.count(user)) {
 
		LOG4CXX_INFO(logger, "Leaving chatroom! Switching back to default mode 0")
 
		LOG4CXX_INFO(logger, "Leaving chatroom! Switching back to default mode 0");
 
		setTwitterMode(user, 0);
 
		handleBuddyChanged(user, adminLegacyName, adminAlias, std::vector<std::string>(), pbnetwork::STATUS_ONLINE);
 
	}
 
}
 

	
 
// Messages to be sent to Twitter
 
void TwitterPlugin::handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml, const std::string &/*id*/)
 
{
 

	
 
	LOG4CXX_INFO(logger, "Received " << user << " --> " << legacyName << " - " << message)
 
	LOG4CXX_INFO(logger, "Received " << user << " --> " << legacyName << " - " << message);
 

	
 
	if(legacyName == adminLegacyName || legacyName == adminChatRoom)  {
 
		std::string cmd = "", data = "";
 

	
 
		/** Parsing the message - Assuming message format to be <cmd>[ ]*<data>**/
 
		int i;
 
@@ -262,13 +262,13 @@ void TwitterPlugin::handleMessageSendRequest(const std::string &user, const std:
 
			else if(userdb[user].twitterMode == MULTIPLECONTACT)
 
				tp->runAsThread(new FetchFriends(userdb[user].sessions, user, boost::bind(&TwitterPlugin::populateRoster, this, _1, _2, _3, _4)));
 

	
 
			handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
								std::string("Changed mode to ") + data, userdb[user].twitterMode == CHATROOM ? adminNickName : "");
 

	
 
			LOG4CXX_INFO(logger, user << ": Changed mode to " << data  << " <" << (userdb[user].twitterMode == CHATROOM ? adminNickName : "") << ">" )
 
			LOG4CXX_INFO(logger, user << ": Changed mode to " << data  << " <" << (userdb[user].twitterMode == CHATROOM ? adminNickName : "") << ">" );
 
		}
 

	
 
		else if(userdb[user].twitterMode == CHATROOM) {
 
			std::string buddy = message.substr(0, message.find(":"));
 
			if(userdb[user].buddies.count(buddy) == 0) {
 
				tp->runAsThread(new StatusUpdateRequest(userdb[user].sessions, user, message,
 
@@ -293,46 +293,46 @@ void TwitterPlugin::handleMessageSendRequest(const std::string &user, const std:
 
	}
 
}
 

	
 
void TwitterPlugin::handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::vector<std::string> &groups)
 
{
 
	if(userdb[user].connectionState != CONNECTED) {
 
		LOG4CXX_ERROR(logger, user << " is not connected to twitter!")
 
		LOG4CXX_ERROR(logger, user << " is not connected to twitter!");
 
		return;
 
	}
 

	
 
	LOG4CXX_INFO(logger, user << " - Adding Twitter contact " << buddyName)
 
	LOG4CXX_INFO(logger, user << " - Adding Twitter contact " << buddyName);
 
	tp->runAsThread(new CreateFriendRequest(userdb[user].sessions, user, buddyName,
 
											boost::bind(&TwitterPlugin::createFriendResponse, this, _1, _2, _3, _4)));
 
}
 

	
 
void TwitterPlugin::handleBuddyRemovedRequest(const std::string &user, const std::string &buddyName, const std::vector<std::string> &groups)
 
{
 
	if(userdb[user].connectionState != CONNECTED) {
 
		LOG4CXX_ERROR(logger, user << " is not connected to twitter!")
 
		LOG4CXX_ERROR(logger, user << " is not connected to twitter!");
 
		return;
 
	}
 

	
 
	if (getTwitterMode(user) == MULTIPLECONTACT) {
 
		LOG4CXX_ERROR(logger, user << " not removing Twitter contact " << buddyName << ", because the mode is not MULTIPLECONTACT")
 
		LOG4CXX_ERROR(logger, user << " not removing Twitter contact " << buddyName << ", because the mode is not MULTIPLECONTACT");
 
		return;
 
	}
 

	
 
	LOG4CXX_INFO(logger, user << " - Removing Twitter contact " << buddyName)
 
	LOG4CXX_INFO(logger, user << " - Removing Twitter contact " << buddyName);
 
	tp->runAsThread(new DestroyFriendRequest(userdb[user].sessions, user, buddyName,
 
											 boost::bind(&TwitterPlugin::deleteFriendResponse, this, _1, _2, _3)));
 
}
 

	
 
void TwitterPlugin::handleVCardRequest(const std::string &user, const std::string &legacyName, unsigned int id)
 
{
 
	if(userdb[user].connectionState != CONNECTED) {
 
		LOG4CXX_ERROR(logger, user << " is not connected to twitter!")
 
		LOG4CXX_ERROR(logger, user << " is not connected to twitter!");
 
		return;
 
	}
 

	
 
	LOG4CXX_INFO(logger, user << " - VCardRequest for " << legacyName << ", " << userdb[user].buddiesInfo[legacyName].getProfileImgURL())
 
	LOG4CXX_INFO(logger, user << " - VCardRequest for " << legacyName << ", " << userdb[user].buddiesInfo[legacyName].getProfileImgURL());
 

	
 
	if(getTwitterMode(user) != SINGLECONTACT && userdb[user].buddies.count(legacyName)
 
		&& userdb[user].buddiesInfo[legacyName].getProfileImgURL().length()) {
 
		if(userdb[user].buddiesImgs.count(legacyName) == 0) {
 
			tp->runAsThread(new ProfileImageRequest(config, user, legacyName, userdb[user].buddiesInfo[legacyName].getProfileImgURL(), id,
 
													boost::bind(&TwitterPlugin::profileImageResponse, this, _1, _2, _3, _4, _5)));
 
@@ -371,13 +371,13 @@ void TwitterPlugin::pollForDirectMessages()
 
bool TwitterPlugin::getUserOAuthKeyAndSecret(const std::string user, std::string &key, std::string &secret)
 
{
 
	boost::mutex::scoped_lock lock(dblock);
 

	
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		return false;
 
	}
 

	
 
	key="", secret=""; int type = TYPE_STRING;;
 
	storagebackend->getUserSetting((long)info.id, OAUTH_KEY, type, key);
 
	storagebackend->getUserSetting((long)info.id, OAUTH_SECRET, type, secret);
 
@@ -387,33 +387,33 @@ bool TwitterPlugin::getUserOAuthKeyAndSecret(const std::string user, std::string
 
bool TwitterPlugin::checkSpectrum1User(const std::string user)
 
{
 
	boost::mutex::scoped_lock lock(dblock);
 

	
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		return false;
 
	}
 

	
 
	std::string first_synchronization_done = "";
 
	int type = TYPE_STRING;
 
	storagebackend->getUserSetting((long)info.id, "first_synchronization_done", type, first_synchronization_done);
 

	
 
	LOG4CXX_INFO(logger, "first_synchronization_done: " << first_synchronization_done)
 
	LOG4CXX_INFO(logger, "first_synchronization_done: " << first_synchronization_done);
 

	
 
	if(first_synchronization_done.length()) return true;
 
	return false;
 
}
 

	
 
int TwitterPlugin::getTwitterMode(const std::string user)
 
{
 
	boost::mutex::scoped_lock lock(dblock);
 

	
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		return -1;
 
	}
 

	
 
	int type = TYPE_STRING; int m;
 
	std::string s_m;
 
	storagebackend->getUserSetting((long)info.id, MODE, type, s_m);
 
@@ -428,38 +428,38 @@ int TwitterPlugin::getTwitterMode(const std::string user)
 
bool TwitterPlugin::setTwitterMode(const std::string user, int m)
 
{
 
	boost::mutex::scoped_lock lock(dblock);
 

	
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		return false;
 
	}
 

	
 
	if(m < 0 || m > 2) {
 
		LOG4CXX_ERROR(logger, "Unknown mode " << m <<". Using default mode 0")
 
		LOG4CXX_ERROR(logger, "Unknown mode " << m <<". Using default mode 0");
 
		m = 0;
 
	}
 

	
 
	userdb[user].twitterMode = (mode)m;
 

	
 
	//int type;
 
	std::string s_m = std::string(1,m+'0');
 
	LOG4CXX_INFO(logger, "Storing mode " << m <<" for user " << user)
 
	LOG4CXX_INFO(logger, "Storing mode " << m <<" for user " << user);
 
	storagebackend->updateUserSetting((long)info.id, MODE, s_m);
 
	return true;
 
}
 

	
 
bool TwitterPlugin::storeUserOAuthKeyAndSecret(const std::string user, const std::string OAuthKey, const std::string OAuthSecret)
 
{
 

	
 
	boost::mutex::scoped_lock lock(dblock);
 

	
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		return false;
 
	}
 

	
 
	storagebackend->updateUserSetting((long)info.id, OAUTH_KEY, OAuthKey);
 
	storagebackend->updateUserSetting((long)info.id, OAUTH_SECRET, OAuthSecret);
 
	return true;
 
@@ -468,26 +468,26 @@ bool TwitterPlugin::storeUserOAuthKeyAndSecret(const std::string user, const std
 
void TwitterPlugin::initUserSession(const std::string user, const std::string legacyName, const std::string password)
 
{
 
	boost::mutex::scoped_lock lock(userlock);
 

	
 
	std::string username = legacyName;
 
	std::string passwd = password;
 
	LOG4CXX_INFO(logger, username + "  " + passwd)
 
	LOG4CXX_INFO(logger, username + "  " + passwd);
 

	
 
	userdb[user].sessions = new twitCurl();
 
	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)
 
		LOG4CXX_INFO(logger, ip << " " << port << " " << puser << " " << ppasswd);
 

	
 
		if(ip != "localhost" && port != "0") {
 
			userdb[user].sessions->setProxyServerIp(ip);
 
			userdb[user].sessions->setProxyServerPort(port);
 
			userdb[user].sessions->setProxyUserName(puser);
 
			userdb[user].sessions->setProxyPassword(ppasswd);
 
@@ -542,13 +542,13 @@ void TwitterPlugin::updateLastTweetID(const std::string user, const std::string
 
{
 
	boost::mutex::scoped_lock lock(userlock);
 
	userdb[user].mostRecentTweetID = ID;
 

	
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		return;
 
	}
 

	
 
	storagebackend->updateUserSetting((long)info.id, "twitter_last_tweet", ID);
 
}
 

	
 
@@ -558,13 +558,13 @@ std::string TwitterPlugin::getMostRecentTweetIDUnsafe(const std::string user)
 
	if(onlineUsers.count(user)) {
 
		ID = userdb[user].mostRecentTweetID;
 
		if (ID.empty()) {
 
			int type = TYPE_STRING;
 
			UserInfo info;
 
			if(storagebackend->getUser(user, info) == false) {
 
				LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
				LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
			}
 
			else {
 
				storagebackend->getUserSetting(info.id, "twitter_last_tweet", type, ID);
 
			}
 
		}
 
	}
 
@@ -581,13 +581,13 @@ void TwitterPlugin::updateLastDMID(const std::string user, const std::string ID)
 
{
 
	boost::mutex::scoped_lock lock(userlock);
 
	userdb[user].mostRecentDirectMessageID = ID;
 

	
 
	UserInfo info;
 
	if(storagebackend->getUser(user, info) == false) {
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
		LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
		return;
 
	}
 

	
 
	storagebackend->updateUserSetting((long)info.id, "twitter_last_dm", ID);
 
}
 

	
 
@@ -596,13 +596,13 @@ std::string TwitterPlugin::getMostRecentDMIDUnsafe(const std::string user) {
 
	if(onlineUsers.count(user)) {
 
		ID = userdb[user].mostRecentDirectMessageID;
 
		if (ID.empty()) {
 
			int type = TYPE_STRING;
 
			UserInfo info;
 
			if(storagebackend->getUser(user, info) == false) {
 
				LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!")
 
				LOG4CXX_ERROR(logger, "Didn't find entry for " << user << " in the database!");
 
			}
 
			else {
 
				storagebackend->getUserSetting(info.id, "twitter_last_dm", type, ID);
 
			}
 
		}
 
	}
 
@@ -810,13 +810,13 @@ void TwitterPlugin::directMessageResponse(std::string &user, std::string &userna
 
				else
 
					handleMessage(user, adminChatRoom, messages[i].getMessage() + " - <Direct Message>", messages[i].getSenderData().getScreenName());
 
				if(cmp(maxID, messages[i].getID()) == -1) maxID = messages[i].getID();
 
			}
 
		}
 

	
 
		if(maxID == getMostRecentDMID(user)) LOG4CXX_INFO(logger, "No new direct messages for " << user)
 
		if(maxID == getMostRecentDMID(user)) LOG4CXX_INFO(logger, "No new direct messages for " << user);
 
		updateLastDMID(user, maxID);
 
	}
 
}
 

	
 
void TwitterPlugin::createFriendResponse(std::string &user, User &frnd, std::string &img, Error &errMsg)
 
{
 
@@ -834,13 +834,13 @@ void TwitterPlugin::createFriendResponse(std::string &user, User &frnd, std::str
 
						std::string("You are now following ") + frnd.getScreenName(), userdb[user].twitterMode == CHATROOM ? adminNickName : "");
 

	
 
	userdb[user].buddies.insert(frnd.getScreenName());
 
	userdb[user].buddiesInfo[frnd.getScreenName()] = frnd;
 
	userdb[user].buddiesImgs[frnd.getScreenName()] = img;
 

	
 
	LOG4CXX_INFO(logger, user << " - " << frnd.getScreenName() << ", " << frnd.getProfileImgURL())
 
	LOG4CXX_INFO(logger, user << " - " << frnd.getScreenName() << ", " << frnd.getProfileImgURL());
 
	if(userdb[user].twitterMode == MULTIPLECONTACT) {
 
#if HAVE_SWIFTEN_3
 
		handleBuddyChanged(user, frnd.getScreenName(), frnd.getUserName(), std::vector<std::string>(), pbnetwork::STATUS_ONLINE, "", Swift::byteArrayToString(cryptoProvider->getSHA1Hash(Swift::createByteArray(img))));
 
#else
 
		handleBuddyChanged(user, frnd.getScreenName(), frnd.getUserName(), std::vector<std::string>(), pbnetwork::STATUS_ONLINE, "", SHA(img));
 
#endif
 
@@ -858,13 +858,13 @@ void TwitterPlugin::deleteFriendResponse(std::string &user, User &frnd, Error &e
 
		}
 
		handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
							errMsg.getMessage(), userdb[user].twitterMode == CHATROOM ? adminNickName : "");
 
		return;
 
	}
 

	
 
	LOG4CXX_INFO(logger, user << " - " << frnd.getScreenName() << ", " << frnd.getProfileImgURL())
 
	LOG4CXX_INFO(logger, user << " - " << frnd.getScreenName() << ", " << frnd.getProfileImgURL());
 
	userdb[user].buddies.erase(frnd.getScreenName());
 

	
 
	handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
						std::string("You are not following ") + frnd.getScreenName() + " anymore", userdb[user].twitterMode == CHATROOM ? adminNickName : "");
 

	
 
	if (userdb[user].twitterMode == CHATROOM) {
 
@@ -899,10 +899,10 @@ void TwitterPlugin::profileImageResponse(std::string &user, std::string &buddy,
 
			handleDisconnected(user, 3, errMsg.getMessage());
 
			return;
 
		}
 
		handleMessage(user, userdb[user].twitterMode == CHATROOM ? adminChatRoom : adminLegacyName,
 
							errMsg.getMessage(), userdb[user].twitterMode == CHATROOM ? adminNickName : "");
 
	} else {
 
		LOG4CXX_INFO(logger, user << " - Sending VCard for " << buddy)
 
		LOG4CXX_INFO(logger, user << " - Sending VCard for " << buddy);
 
		handleVCard(user, reqID, buddy, buddy, "", img);
 
	}
 
}
backends/twitter/TwitterResponseParser.cpp
Show inline comments
 
@@ -50,13 +50,13 @@ static std::string toIsoTime(std::string in) {
 
}
 

	
 
EmbeddedStatus getEmbeddedStatus(const rapidjson::Value &element)
 
{
 
	EmbeddedStatus status;
 
	if(!element.IsObject()) {
 
		LOG4CXX_ERROR(logger, "Not a status element!")
 
		LOG4CXX_ERROR(logger, "Not a status element!");
 
		return status;
 
	}
 
	status.setCreationTime( toIsoTime ( std::string( element[TwitterReponseTypes::created_at.c_str()].GetString() ) ) );
 
	status.setID( stringOf( element[TwitterReponseTypes::id.c_str()].GetInt64() ) );
 
	status.setTweet( unescape ( std::string( element[TwitterReponseTypes::text.c_str()].GetString() ), getUrlEntities(element) ) );
 
	status.setTruncated( element[TwitterReponseTypes::truncated.c_str()].GetBool());
 
@@ -73,13 +73,13 @@ EmbeddedStatus getEmbeddedStatus(const rapidjson::Value &element)
 
}
 

	
 
User getUser(const rapidjson::Value &element)
 
{
 
	User user;
 
	if(!element.IsObject()) {
 
		LOG4CXX_ERROR(logger, "Not a user element!")
 
		LOG4CXX_ERROR(logger, "Not a user element!");
 
		return user;
 
	}
 

	
 
	user.setUserID( stringOf( element[TwitterReponseTypes::id.c_str()].GetInt64() ) );
 
	user.setScreenName( tolowercase( std::string( element[TwitterReponseTypes::screen_name.c_str()].GetString() ) ) );
 
	user.setUserName( std::string( element[TwitterReponseTypes::name.c_str()].GetString() ) );
 
@@ -139,20 +139,20 @@ DirectMessage getDirectMessage(const rapidjson::Value &element)
 
std::vector<Status> getTimeline(std::string &json)
 
{
 
	std::vector<Status> statuses;
 
	rapidjson::Document rootElement;
 

	
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON");
 
		LOG4CXX_ERROR(logger, json);
 
		return statuses;
 
	}
 

	
 
	if(!rootElement.IsArray()) {
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to timeline:")
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to timeline:");
 
		LOG4CXX_ERROR(logger, json);
 
		return statuses;
 
	}
 

	
 
	for(rapidjson::SizeType i = 0; i < rootElement.Size(); i++) {
 
		statuses.push_back(getStatus(rootElement[i]));
 
	}
 
@@ -163,20 +163,20 @@ std::vector<DirectMessage> getDirectMessages(std::string &json)
 
{
 
	std::vector<DirectMessage> DMs;
 
	rapidjson::Document rootElement;
 

	
 

	
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON");
 
		LOG4CXX_ERROR(logger, json);
 
		return DMs;
 
	}
 

	
 
	if(!rootElement.IsArray()) {
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to direct messages:")
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to direct messages:");
 
		LOG4CXX_ERROR(logger, json);
 
		return DMs;
 
	}
 

	
 
	for(rapidjson::SizeType i = 0; i < rootElement.Size(); i++) {
 
		DMs.push_back(getDirectMessage(rootElement[i]));
 
	}
 
@@ -187,20 +187,20 @@ std::vector<User> getUsers(std::string &json)
 
{
 
	std::vector<User> users;
 
	rapidjson::Document rootElement;
 

	
 

	
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON");
 
		LOG4CXX_ERROR(logger, json);
 
		return users;
 
	}
 

	
 
	if(!rootElement.IsArray()) {
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to user list:")
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to user list:");
 
		LOG4CXX_ERROR(logger, json);
 
		return users;
 
	}
 

	
 
	for(rapidjson::SizeType i = 0; i < rootElement.Size(); i++) {
 
		users.push_back(getUser(rootElement[i]));
 
	}
 
@@ -210,40 +210,40 @@ std::vector<User> getUsers(std::string &json)
 
User getUser(std::string &json)
 
{
 
	User user;
 
	rapidjson::Document rootElement;
 

	
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON");
 
		LOG4CXX_ERROR(logger, json);
 
		return user;
 
	}
 

	
 
	if(!rootElement.IsObject()) {
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to user object")
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to user object");
 
		LOG4CXX_ERROR(logger, json);
 
		return user;
 
	}
 

	
 
	return user = getUser(rootElement);
 
}
 

	
 
std::vector<std::string> getIDs(std::string &json)
 
{
 
	std::vector<std::string> IDs;
 
	rapidjson::Document rootElement;
 

	
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON");
 
		LOG4CXX_ERROR(logger, json);
 
		return IDs;
 
	}
 

	
 
	if(!rootElement.IsObject()) {
 
		LOG4CXX_ERROR(logger, "JSON doesn't correspond to id_list");
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, json);
 
		return IDs;
 
	}
 

	
 
	const rapidjson::Value & ids = rootElement[TwitterReponseTypes::ids.c_str()];
 

	
 
	for(int i=0 ; i<ids.Size() ; i++) {
 
@@ -257,14 +257,14 @@ Error getErrorMessage(std::string &json)
 
	std::string error = "";
 
	std::string code = "0";
 
	Error resp;
 
	rapidjson::Document rootElement;
 

	
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON");
 
		LOG4CXX_ERROR(logger, json);
 
		return resp;
 
	}
 
	if (rootElement.IsObject()) {
 
		if (!rootElement["errors"].IsNull()) {
 
			const rapidjson::Value &errorElement = rootElement["errors"][0u]; // first error
 
			error = std::string(errorElement["message"].GetString());
backends/twitter/main.cpp
Show inline comments
 
@@ -45,13 +45,13 @@ int main (int argc, char* argv[]) {
 
		LOG4CXX_ERROR(logger, "Error creating StorageBackend! " << error);
 
		LOG4CXX_ERROR(logger, "Twitter backend needs storage backend configured to work! " << error);
 
		return NetworkPlugin::StorageBackendNeeded;
 
	}
 

	
 
	else if (!storagebackend->connect()) {
 
		LOG4CXX_ERROR(logger, "Can't connect to database!")
 
		LOG4CXX_ERROR(logger, "Can't connect to database!");
 
		return -1;
 
	}
 

	
 
	Swift::SimpleEventLoop eventLoop;
 
	loop_ = &eventLoop;
 
	np = new TwitterPlugin(cfg, &eventLoop, storagebackend, host, port);
libtransport/HTTPRequest.cpp
Show inline comments
 
@@ -37,26 +37,26 @@ bool HTTPRequest::init() {
 
		curl_easy_setopt(curlhandle, CURLOPT_PROXY, NULL);
 
		curl_easy_setopt(curlhandle, CURLOPT_PROXYUSERPWD, NULL);
 
		curl_easy_setopt(curlhandle, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
 
		return true;
 
	}
 

	
 
	LOG4CXX_ERROR(logger, "Couldn't Initialize curl!")
 
	LOG4CXX_ERROR(logger, "Couldn't Initialize curl!");
 
	return false;
 
}
 

	
 
void HTTPRequest::setProxy(std::string IP, std::string port, std::string username, std::string password) {
 
	if (curlhandle) {
 
		std::string proxyIpPort = IP + ":" + port;
 
		curl_easy_setopt(curlhandle, CURLOPT_PROXY, proxyIpPort.c_str());
 
		if(username.length() && password.length()) {
 
			std::string proxyUserPass = username + ":" + password;
 
			curl_easy_setopt(curlhandle, CURLOPT_PROXYUSERPWD, proxyUserPass.c_str());
 
		}
 
	} else {
 
		LOG4CXX_ERROR(logger, "Trying to set proxy while CURL isn't initialized")
 
		LOG4CXX_ERROR(logger, "Trying to set proxy while CURL isn't initialized");
 
	}
 
}
 

	
 
int HTTPRequest::curlCallBack(char* data, size_t size, size_t nmemb, HTTPRequest* obj) {
 
	int writtenSize = 0;
 
	if (obj && data) {
 
@@ -88,13 +88,13 @@ bool HTTPRequest::GET(std::string url, 	std::string &data) {
 
		/* Send http request and return status*/
 
		if(CURLE_OK == curl_easy_perform(curlhandle)) {
 
			data = callbackdata;
 
			return true;
 
		}
 
	} else {
 
		LOG4CXX_ERROR(logger, "CURL not initialized!")
 
		LOG4CXX_ERROR(logger, "CURL not initialized!");
 
		strcpy(curl_errorbuffer, "CURL not initialized!");
 
	}
 
	LOG4CXX_ERROR(logger, "Error fetching " << url);
 
	return false;
 
}
 

	
libtransport/ThreadPool.cpp
Show inline comments
 
@@ -76,13 +76,13 @@ void ThreadPool::releaseThread(int i)
 

	
 
	pool_lock.unlock();
 
}
 

	
 
void ThreadPool::cleandUp(Thread *t, int wid)
 
{
 
	LOG4CXX_INFO(logger, "Cleaning up thread #" << t->getThreadID())
 
	LOG4CXX_INFO(logger, "Cleaning up thread #" << t->getThreadID());
 
	t->finalize();
 
	delete t;
 
	releaseThread(wid);
 
	onWorkerAvailable();
 
}
 

	
 
@@ -90,13 +90,13 @@ void ThreadPool::scheduleFromQueue()
 
{
 
	criticalregion.lock();
 
	while(!requestQueue.empty()) {
 
		int  w = getFreeThread();
 
		if(w == -1) break;
 

	
 
		LOG4CXX_INFO(logger, "Worker Available. Creating thread #" << w)
 
		LOG4CXX_INFO(logger, "Worker Available. Creating thread #" << w);
 
		Thread *t = requestQueue.front(); requestQueue.pop();
 
		t->setThreadID(w);
 
		worker[w] = new boost::thread(boost::bind(&ThreadPool::workerBody, this, _1, _2), t, w, loop);
 
		updateActiveThreadCount(-1);
 
	}
 
	criticalregion.unlock();
 
@@ -104,24 +104,24 @@ void ThreadPool::scheduleFromQueue()
 

	
 

	
 
void ThreadPool::runAsThread(Thread *t)
 
{
 
	int w;
 
	if((w = getFreeThread()) != -1) {
 
		LOG4CXX_INFO(logger, "Creating thread #" << w)
 
		LOG4CXX_INFO(logger, "Creating thread #" << w);
 
		t->setThreadID(w);
 
		worker[w] = new boost::thread(boost::bind(&ThreadPool::workerBody, this, _1, _2), t, w, loop);
 
		updateActiveThreadCount(-1);
 
	}
 
	else {
 
		LOG4CXX_INFO(logger, "No workers available! adding to queue.")
 
		LOG4CXX_INFO(logger, "No workers available! adding to queue.");
 
		requestQueue.push(t);
 
	}
 
}
 

	
 
void ThreadPool::workerBody(Thread *t, int wid) {
 
	LOG4CXX_INFO(logger, "Starting thread " << wid)
 
	LOG4CXX_INFO(logger, "Starting thread " << wid);
 
	t->run();
 
	loop->postEvent(boost::bind(&ThreadPool::cleandUp, this, t, wid), SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::EventOwner>());
 
}
 

	
 
}
libtransport/User.cpp
Show inline comments
 
@@ -177,13 +177,13 @@ void User::handlePresence(Swift::Presence::ref presence, bool forceJoin) {
 
		std::string value = "";
 
		int type = (int) TYPE_STRING;
 
		if (m_storageBackend) {
 
			m_storageBackend->getUserSetting(m_userInfo.id, "photohash", type, value);
 
		}
 
		if (value != vcardUpdate->getPhotoHash()) {
 
			LOG4CXX_INFO(logger, m_jid.toString() << ": Requesting VCard")
 
			LOG4CXX_INFO(logger, m_jid.toString() << ": Requesting VCard");
 
			if (m_storageBackend) {
 
				m_storageBackend->updateUserSetting(m_userInfo.id, "photohash", vcardUpdate->getPhotoHash());
 
			}
 
			requestVCard();
 
		}
 
	}
spectrum/src/frontends/slack/SlackSession.cpp
Show inline comments
 
@@ -226,13 +226,13 @@ void SlackSession::leaveRoom(const std::string &channel_) {
 
	if (channel[0] == '#') {
 
		channel.erase(0, 1);
 
	}
 
	std::string channelId = m_idManager->getId(channel);
 
	std::string to = m_channel2jid[channelId];
 
	if (to.empty()) {
 
		LOG4CXX_ERROR(logger, "Spectrum 2 is not configured to transport this Slack channel.")
 
		LOG4CXX_ERROR(logger, "Spectrum 2 is not configured to transport this Slack channel.");
 
		return;
 
	}
 

	
 
	LOG4CXX_INFO(logger, m_uinfo.jid << ": Leaving the legacy network room " << to);
 

	
 
	Swift::Presence::ref presence = Swift::Presence::create();
spectrum/src/frontends/xmpp/XMPPUserRegistration.cpp
Show inline comments
 
@@ -263,13 +263,13 @@ bool XMPPUserRegistration::handleGetRequest(const Swift::JID& from, const Swift:
 
		return true;
 
	}
 

	
 
	if (!CONFIG_BOOL(m_config,"registration.enable_public_registration")) {
 
		std::vector<std::string> const &x = CONFIG_VECTOR(m_config,"service.allowed_servers");
 
		if (std::find(x.begin(), x.end(), from.getDomain()) == x.end()) {
 
			LOG4CXX_INFO(logger, from.toBare().toString() << ": This user has no permissions to register an account")
 
			LOG4CXX_INFO(logger, from.toBare().toString() << ": This user has no permissions to register an account");
 
			sendError(from, id, ErrorPayload::BadRequest, ErrorPayload::Modify);
 
			return true;
 
		}
 
	}
 

	
 
	SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<InBandRegistrationPayload> reg = generateInBandRegistrationPayload(from);
 
@@ -287,13 +287,13 @@ bool XMPPUserRegistration::handleSetRequest(const Swift::JID& from, const Swift:
 

	
 
	std::string barejid = from.toBare().toString();
 

	
 
	if (!CONFIG_BOOL(m_config,"registration.enable_public_registration")) {
 
		std::vector<std::string> const &x = CONFIG_VECTOR(m_config,"service.allowed_servers");
 
		if (std::find(x.begin(), x.end(), from.getDomain()) == x.end()) {
 
			LOG4CXX_INFO(logger, barejid << ": This user has no permissions to register an account")
 
			LOG4CXX_INFO(logger, barejid << ": This user has no permissions to register an account");
 
			sendError(from, id, ErrorPayload::BadRequest, ErrorPayload::Modify);
 
			return true;
 
		}
 
	}
 

	
 
	UserInfo res;
0 comments (0 inline, 0 general)