Changeset - a06b8a919721
[Not reviewed]
0 1 0
vitalyster - 9 years ago 2016-05-25 02:31:00
vitalyster@gmail.com
libpurple: fix oauth sender
1 file changed with 4 insertions and 2 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -310,48 +310,52 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
				if (!CONFIG_STRING_DEFAULTED(config, "proxy.username", "").empty()) {
 
					purple_proxy_info_set_username_wrapped(info, CONFIG_STRING_DEFAULTED(config, "proxy.username", "").c_str());
 
				}
 

	
 
				if (!CONFIG_STRING_DEFAULTED(config, "proxy.password", "").empty()) {
 
					purple_proxy_info_set_password_wrapped(info, CONFIG_STRING_DEFAULTED(config, "proxy.password", "").c_str());
 
				}
 

	
 
				purple_account_set_proxy_info_wrapped(account, info);
 
			}
 
		}
 

	
 
		void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
 
			PurpleAccount *account = NULL;
 

	
 
			std::string name;
 
			std::string protocol;
 
			getProtocolAndName(legacyName, name, protocol);
 

	
 
			if (password.empty() && protocol != "prpl-telegram" && protocol != "prpl-hangouts") {
 
				LOG4CXX_INFO(logger,  name.c_str() << ": Empty password");
 
				np->handleDisconnected(user, 1, "Empty password.");
 
				return;
 
			}
 
			if (protocol == "prpl-hangouts") {
 
			        adminLegacyName = "hangouts";
 
			        adminAlias = "hangouts";
 
			}
 

	
 
			if (!purple_find_prpl_wrapped(protocol.c_str())) {
 
				LOG4CXX_INFO(logger,  name.c_str() << ": Invalid protocol '" << protocol << "'");
 
				np->handleDisconnected(user, 1, "Invalid protocol " + protocol);
 
				return;
 
			}
 

	
 
			if (purple_accounts_find_wrapped(name.c_str(), protocol.c_str()) != NULL) {
 
				account = purple_accounts_find_wrapped(name.c_str(), protocol.c_str());
 
				if (m_accounts.find(account) != m_accounts.end() && m_accounts[account] != user) {
 
					LOG4CXX_INFO(logger, "Account '" << name << "' is already used by '" << m_accounts[account] << "'");
 
					np->handleDisconnected(user, 1, "Account '" + name + "' is already used by '" + m_accounts[account] + "'");
 
					return;
 
				}
 
				LOG4CXX_INFO(logger, "Using previously created account with name '" << name.c_str() << "' and protocol '" << protocol << "'");
 
			}
 
			else {
 
				LOG4CXX_INFO(logger, "Creating account with name '" << name.c_str() << "' and protocol '" << protocol << "'");
 
				account = purple_account_new_wrapped(name.c_str(), protocol.c_str());
 
				purple_accounts_add_wrapped(account);
 
			}
 

	
 
			m_sessions[user] = account;
 
			m_accounts[account] = user;
 
@@ -361,50 +365,48 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 

	
 
			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);
 

	
 
			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
 

	
 
			// Set the status
 
			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") {
 
				adminLegacyName = "hangouts";
 
				adminAlias = "hangouts";
 
				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];
 
			if (account) {
 
				if (account->ui_data) {
 
					NodeCache *cache = (NodeCache *) account->ui_data;
 
					purple_timeout_remove_wrapped(cache->timer);
 
					delete cache;
 
					account->ui_data = NULL;
 
				}
 
				if (purple_account_get_int_wrapped(account, "version", 0) != 0) {
 
					std::string data = stringOf(purple_account_get_int_wrapped(account, "version", 0));
 
					g_file_set_contents ("gfire.cfg", data.c_str(), data.size(), NULL);
 
				}
 
// 				VALGRIND_DO_LEAK_CHECK;
 
				m_sessions.erase(user);
 
				purple_account_disconnect_wrapped(account);
 
				purple_account_set_enabled_wrapped(account, "spectrum", FALSE);
 

	
 
				m_accounts.erase(account);
0 comments (0 inline, 0 general)