Changeset - 7799529a903e
[Not reviewed]
0 2 0
Michael Wieland - 7 years ago 2018-06-04 00:27:21
git@selfcoders.com
Store Steam Mobile access token in storage backend
2 files changed with 42 insertions and 2 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -181,24 +181,25 @@ static std::string getAlias(PurpleBuddy *m_buddy) {
 
	}
 
	else if (purple_buddy_get_alias_wrapped(m_buddy)) {
 
		alias = (std::string) purple_buddy_get_alias_wrapped(m_buddy);
 
	}
 
	else {
 
		alias = (std::string) purple_buddy_get_server_alias_wrapped(m_buddy);
 
	}
 
	return alias;
 
}
 

	
 
static boost::mutex dblock;
 
static std::string OAUTH_TOKEN = "hangouts_oauth_token";
 
static std::string STEAM_ACCESS_TOKEN = "steammobile_access_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!");
 
		return false;
 
	}
 
	token = "";
 
	int type = TYPE_STRING;
 
	storagebackend->getUserSetting((long)info.id, OAUTH_TOKEN, type, token);
 
@@ -208,24 +209,50 @@ 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!");
 
		return false;
 
	}
 
	storagebackend->updateUserSetting((long)info.id, OAUTH_TOKEN, OAuthToken);
 
	return true;
 
}
 

	
 
static bool getUserSteamAccessToken(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!");
 
		return false;
 
	}
 
	token = "";
 
	int type = TYPE_STRING;
 
	storagebackend->getUserSetting((long)info.id, STEAM_ACCESS_TOKEN, type, token);
 
	return true;
 
}
 

	
 
static bool storeUserSteamAccessToken(const std::string user, const 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!");
 
		return false;
 
	}
 
	storagebackend->updateUserSetting((long)info.id, STEAM_ACCESS_TOKEN, token);
 
	return true;
 
}
 

	
 
class SpectrumNetworkPlugin : public NetworkPlugin {
 
	public:
 
		SpectrumNetworkPlugin() : NetworkPlugin() {
 
			LOG4CXX_INFO(logger, "Starting libpurple backend " << SPECTRUM_VERSION);
 
		}
 

	
 
		void handleExitRequest() {
 
			LOG4CXX_INFO(logger, "Exiting...");
 
			exit(0);
 
		}
 

	
 
		void getProtocolAndName(const std::string &legacyName, std::string &name, std::string &protocol) {
 
@@ -407,24 +434,30 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			setDefaultAvatar(account, legacyName);
 

	
 
			purple_account_set_password_wrapped(account, password.c_str());
 
			purple_account_set_bool_wrapped(account, "custom_smileys", FALSE);
 
			purple_account_set_bool_wrapped(account, "direct_connect", FALSE);
 
			purple_account_set_bool_wrapped(account, "compat-verification", TRUE);
 
			if (protocol == "prpl-hangouts") {
 
				std::string token;
 
				if (getUserOAuthToken(user, token)) {
 
					purple_account_set_password_wrapped(account, token.c_str());
 
				}
 
			}
 
			else if (protocol == "prpl-steam-mobile") {
 
				std::string token;
 
				if (getUserSteamAccessToken(user, token)) {
 
					purple_account_set_string_wrapped(account, "access_token", token.c_str());
 
				}
 
			}
 

	
 
			setDefaultAccountOptions(account);
 

	
 
			// Enable account + privacy lists
 
			purple_account_set_enabled_wrapped(account, "spectrum", TRUE);
 

	
 
#if PURPLE_MAJOR_VERSION >= 2 && PURPLE_MINOR_VERSION >= 7
 
			if (CONFIG_BOOL(config, "service.enable_privacy_lists")) {
 
				purple_account_set_privacy_type_wrapped(account, PURPLE_PRIVACY_DENY_USERS);
 
			}
 
#endif
 

	
 
@@ -2077,24 +2110,27 @@ static void signed_on(PurpleConnection *gc, gpointer unused) {
 
#if !defined(__FreeBSD__) && !defined(__APPLE__)
 
	// force returning of memory chunks allocated by libxml2 to kernel
 
	malloc_trim(0);
 
#endif
 
#endif
 
	purple_roomlist_get_list_wrapped(gc);
 

	
 
	// For prpl-gg
 
	execute_purple_plugin_action(gc, "Download buddylist from Server");
 
	if (CONFIG_STRING(config, "service.protocol") == "prpl-hangouts") {
 
		storeUserOAuthToken(np->m_accounts[account], purple_account_get_password_wrapped(account));
 
	}
 
	else if (CONFIG_STRING(config, "service.protocol") == "prpl-steam-mobile") {
 
		storeUserSteamAccessToken(np->m_accounts[account], purple_account_get_string_wrapped(account, "access_token", NULL));
 
	}
 
}
 

	
 
static void printDebug(PurpleDebugLevel level, const char *category, const char *arg_s) {
 
	std::string c("");
 
	std::string args(arg_s);
 
	args.erase(args.size() - 1);
 

	
 
	if (category) {
 
		c.append(category);
 
	}
 

	
 
	c.push_back(':');
 
@@ -2305,29 +2341,29 @@ int main(int argc, char **argv) {
 
#endif
 

	
 
	std::string error;
 
	Config *cfg = Config::createFromArgs(argc, argv, error, host, port);
 
	if (cfg == NULL) {
 
		std::cerr << error;
 
		return 1;
 
	}
 

	
 
	config = SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Config>(cfg);
 

	
 
	Logging::initBackendLogging(config.get());
 
	if (CONFIG_STRING(config, "service.protocol") == "prpl-hangouts") {
 
	if (CONFIG_STRING(config, "service.protocol") == "prpl-hangouts" || CONFIG_STRING(config, "service.protocol") == "prpl-steam-mobile") {
 
		storagebackend = StorageBackend::createBackend(config.get(), error);
 
		if (storagebackend == NULL) {
 
			LOG4CXX_ERROR(logger, "Error creating StorageBackend! " << error);
 
			LOG4CXX_ERROR(logger, "Hangouts backend needs storage backend configured to work! " << error);
 
			LOG4CXX_ERROR(logger, "Hangouts and Steam backends need storage backend configured to work! " << error);
 
			return NetworkPlugin::StorageBackendNeeded;
 
		}
 
		else if (!storagebackend->connect()) {
 
			LOG4CXX_ERROR(logger, "Can't connect to database!");
 
			return -1;
 
		}
 
	}
 

	
 
	initPurple();
 

	
 
	main_socket = create_socket(host.c_str(), port);
 
	purple_input_add_wrapped(main_socket, PURPLE_INPUT_READ, &transportDataReceived, NULL);
backends/libpurple/purple_defs.h
Show inline comments
 
@@ -14,24 +14,27 @@
 

	
 
#define PURPLE_CONNECTION_IS_CONNECTED_WRAPPED(gc) 	(purple_connection_get_state_wrapped(gc) == PURPLE_CONNECTED)
 

	
 
typedef void  (_cdecl * purple_account_set_bool_wrapped_fnc)(PurpleAccount *account, const char *name, gboolean value);
 
extern purple_account_set_bool_wrapped_fnc purple_account_set_bool_wrapped;
 

	
 
typedef const char * (_cdecl * purple_account_get_protocol_id_wrapped_fnc)(const PurpleAccount *account);
 
extern purple_account_get_protocol_id_wrapped_fnc purple_account_get_protocol_id_wrapped;
 

	
 
typedef void  (_cdecl * purple_account_set_int_wrapped_fnc)(PurpleAccount *account, const char *name, int value);
 
extern purple_account_set_int_wrapped_fnc purple_account_set_int_wrapped;
 

	
 
typedef const char * (_cdecl * purple_account_get_string_wrapped_fnc)(PurpleAccount *account, const char *name, const char *default_value);
 
extern purple_account_get_string_wrapped_fnc purple_account_get_string_wrapped;
 

	
 
typedef void  (_cdecl * purple_account_set_string_wrapped_fnc)(PurpleAccount *account, const char *name, const char *value);
 
extern purple_account_set_string_wrapped_fnc purple_account_set_string_wrapped;
 

	
 
typedef const char * (_cdecl * purple_account_get_username_wrapped_fnc)(const PurpleAccount *account);
 
extern purple_account_get_username_wrapped_fnc purple_account_get_username_wrapped;
 

	
 
typedef void  (_cdecl * purple_account_set_username_wrapped_fnc)(PurpleAccount *account, const char *username);
 
extern purple_account_set_username_wrapped_fnc purple_account_set_username_wrapped;
 

	
 
typedef void  (_cdecl * purple_account_set_proxy_info_wrapped_fnc)(PurpleAccount *account, PurpleProxyInfo *info);
 
extern purple_account_set_proxy_info_wrapped_fnc purple_account_set_proxy_info_wrapped;
 

	
 
@@ -469,24 +472,25 @@ extern wpurple_g_io_channel_win32_new_socket_wrapped_fnc wpurple_g_io_channel_wi
 
#define PURPLE_BLIST_NODE_IS_BUDDY_WRAPPED PURPLE_BLIST_NODE_IS_BUDDY
 
#define PURPLE_BLIST_NODE_IS_CONTACT_WRAPPED PURPLE_BLIST_NODE_IS_CONTACT
 
#define PURPLE_BLIST_NODE_IS_GROUP_WRAPPED PURPLE_BLIST_NODE_IS_GROUP
 

	
 
#define PURPLE_CONV_IM_WRAPPED PURPLE_CONV_IM
 
#define PURPLE_CONV_CHAT_WRAPPED PURPLE_CONV_CHAT
 

	
 
#define PURPLE_CONNECTION_IS_CONNECTED_WRAPPED PURPLE_CONNECTION_IS_CONNECTED	
 

	
 
#define purple_account_set_bool_wrapped purple_account_set_bool
 
#define purple_account_get_protocol_id_wrapped purple_account_get_protocol_id
 
#define purple_account_set_int_wrapped purple_account_set_int
 
#define purple_account_get_string_wrapped purple_account_get_string
 
#define purple_account_set_string_wrapped purple_account_set_string
 
#define purple_account_get_username_wrapped purple_account_get_username
 
#define purple_account_set_username_wrapped purple_account_set_username
 
#define purple_account_set_proxy_info_wrapped purple_account_set_proxy_info
 
#define purple_accounts_find_wrapped purple_accounts_find
 
#define purple_account_new_wrapped purple_account_new
 
#define purple_accounts_add_wrapped purple_accounts_add
 
#define purple_account_get_password_wrapped purple_account_get_password
 
#define purple_account_set_password_wrapped purple_account_set_password
 
#define purple_account_set_enabled_wrapped purple_account_set_enabled
 
#define purple_account_set_privacy_type_wrapped purple_account_set_privacy_type
 
#define purple_account_get_status_type_with_primitive_wrapped purple_account_get_status_type_with_primitive
0 comments (0 inline, 0 general)