Files @ 16e3bc94250c
Branch filter:

Location: libtransport.git/backends/twitter/TwitterPlugin.h - annotation

Jan Kaluza
set needPassword=false in twitter backend
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
b3f59f9bb668
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
85c28989bdb8
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
6bcaaeb731ef
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
c236c464ffac
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
c79af87410fd
c79af87410fd
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
6e1413bf21d3
6e1413bf21d3
6e1413bf21d3
6e1413bf21d3
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
bdb8aed78f63
bdb8aed78f63
f8a183661cfa
c2fefc36c734
c2fefc36c734
f8a183661cfa
cb62e786889f
cb62e786889f
561a55e96363
561a55e96363
cb62e786889f
cb62e786889f
c0c5673c97b6
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
728517cf2312
c2fefc36c734
728517cf2312
728517cf2312
cb62e786889f
c2fefc36c734
c2fefc36c734
c2fefc36c734
c2fefc36c734
80a0bda3f5bc
80a0bda3f5bc
80a0bda3f5bc
80a0bda3f5bc
80a0bda3f5bc
80a0bda3f5bc
6bcaaeb731ef
c236c464ffac
6bcaaeb731ef
6e1413bf21d3
6bcaaeb731ef
c236c464ffac
6bcaaeb731ef
c236c464ffac
6bcaaeb731ef
c236c464ffac
6bcaaeb731ef
c236c464ffac
6bcaaeb731ef
c236c464ffac
6bcaaeb731ef
c236c464ffac
6bcaaeb731ef
c236c464ffac
6bcaaeb731ef
c236c464ffac
5b13c80ee9ea
5b13c80ee9ea
cb62e786889f
9388d599156c
9388d599156c
cb62e786889f
5b13c80ee9ea
5b13c80ee9ea
cb62e786889f
6e1413bf21d3
80a0bda3f5bc
6e1413bf21d3
6e1413bf21d3
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
80a0bda3f5bc
cb62e786889f
cb62e786889f
cb62e786889f
cb62e786889f
f8a183661cfa
9e70a739b7c2
9e70a739b7c2
c0c5673c97b6
561a55e96363
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
9e70a739b7c2
16e3bc94250c
cb62e786889f
cb62e786889f
#ifndef TWITTER_PLUGIN
#define TWITTER_PLUGIN

#include "transport/config.h"
#include "transport/networkplugin.h"
#include "transport/logging.h"
#include "transport/sqlite3backend.h"
#include "transport/mysqlbackend.h"
#include "transport/pqxxbackend.h"
#include "transport/storagebackend.h"
#include "transport/threadpool.h"

#include "Swiften/Swiften.h"
#include "unistd.h"
#include "signal.h"
#include "sys/wait.h"
#include "sys/signal.h"

#include <boost/algorithm/string.hpp>
#include <boost/signal.hpp>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>

#include "twitcurl.h"
#include "TwitterResponseParser.h"

#include <iostream>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <cstdio>

#include "Swiften/StringCodecs/SHA1.h"

using namespace boost::filesystem;
using namespace boost::program_options;
using namespace Transport;

#define STR(x) (std::string("(") + x.from + ", " + x.to + ", " + x.message + ")")

class TwitterPlugin;
extern TwitterPlugin *np;
extern Swift::SimpleEventLoop *loop_; // Event Loop


class TwitterPlugin : public NetworkPlugin {
	public:
		Swift::BoostNetworkFactories *m_factories;
		Swift::BoostIOServiceThread m_boostIOServiceThread;
		boost::shared_ptr<Swift::Connection> m_conn;
		Swift::Timer::ref tweet_timer;
		Swift::Timer::ref message_timer;
		StorageBackend *storagebackend;

		TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, StorageBackend *storagebackend, const std::string &host, int port);
		~TwitterPlugin();

		// Send data to NetworkPlugin server
		void sendData(const std::string &string);

		// Receive date from the NetworkPlugin server and invoke the appropirate payload handler (implement in the NetworkPlugin class)
		void _handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data);
	
		// User trying to login into his twitter account
		void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password);
		
		// User logging out
		void handleLogoutRequest(const std::string &user, const std::string &legacyName);
		
		void handleJoinRoomRequest(const std::string &/*user*/, const std::string &/*room*/, const std::string &/*nickname*/, const std::string &/*pasword*/);

		void handleLeaveRoomRequest(const std::string &/*user*/, const std::string &/*room*/);

		void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "");

		void handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::vector<std::string> &groups);

		void handleBuddyRemovedRequest(const std::string &user, const std::string &buddyName, const std::vector<std::string> &groups);
		
		void handleVCardRequest(const std::string &/*user*/, const std::string &/*legacyName*/, unsigned int /*id*/);
		
		void pollForTweets();

		void pollForDirectMessages();
		
		bool getUserOAuthKeyAndSecret(const std::string user, std::string &key, std::string &secret);
		
		bool checkSpectrum1User(const std::string user);
		
		bool storeUserOAuthKeyAndSecret(const std::string user, const std::string OAuthKey, const std::string OAuthSecret);
		
		void initUserSession(const std::string user, const std::string legacyName, const std::string password);
		
		void OAuthFlowComplete(const std::string user, twitCurl *obj);
		
		void pinExchangeComplete(const std::string user, const std::string OAuthAccessTokenKey, const std::string OAuthAccessTokenSecret);
		
		void updateLastTweetID(const std::string user, const std::string ID);

		std::string getMostRecentTweetID(const std::string user);

		void updateLastDMID(const std::string user, const std::string ID);
		
		std::string getMostRecentDMID(const std::string user);

		void clearRoster(const std::string user);

		int getTwitterMode(const std::string user);

		bool setTwitterMode(const std::string user, int m);

		/****************** Twitter response handlers **************************************/
		void statusUpdateResponse(std::string &user, Error &errMsg);
		
		void helpMessageResponse(std::string &user, std::string &msg);
		
		void populateRoster(std::string &user, std::vector<User> &friends, std::vector<std::string> &friendAvatars, Error &errMsg);
		
		void displayFriendlist(std::string &user, std::vector<User> &friends, std::vector<std::string> &friendAvatars, Error &errMsg);
		
		void displayTweets(std::string &user, std::string &userRequested, std::vector<Status> &tweets , Error &errMsg);
		
		void directMessageResponse(std::string &user, std::string &username, std::vector<DirectMessage> &messages, Error &errMsg);
		
		void createFriendResponse(std::string &user, User &frnd, std::string &img, Error &errMsg);
		
		void deleteFriendResponse(std::string &user, User &frnd, Error &errMsg);
		
		void RetweetResponse(std::string &user, Error &errMsg);
		
		void profileImageResponse(std::string &user, std::string &buddy, std::string &img, unsigned int reqID, Error &errMsg);
		/***********************************************************************************/

	private:
		std::string getMostRecentTweetIDUnsafe(const std::string user);

		enum status {NEW, WAITING_FOR_PIN, CONNECTED, DISCONNECTED};
		enum mode {SINGLECONTACT, MULTIPLECONTACT, CHATROOM};

		Config *config;
		std::string adminLegacyName;
		std::string adminChatRoom;
		std::string adminNickName;
		std::string adminAlias;

		std::string consumerKey;
		std::string consumerSecret;
		std::string OAUTH_KEY;
		std::string OAUTH_SECRET;
		std::string MODE;

		boost::mutex dblock, userlock;

		ThreadPool *tp;
		std::set<std::string> onlineUsers;
		struct UserData
		{
			std::string legacyName;
			bool spectrum1User; //Legacy support
			User userTwitterObj;
			std::string userImg;
			twitCurl* sessions;		
			status connectionState;
			std::string mostRecentTweetID;
			std::string mostRecentDirectMessageID;
			std::string nickName;
			std::set<std::string> buddies;
			std::map<std::string, User> buddiesInfo;
			std::map<std::string, std::string> buddiesImgs;
			mode twitterMode;

			UserData() { sessions = NULL; }
		};
		std::map<std::string, UserData> userdb;
		bool m_firstPing;
};
#endif