Changeset - 4bb54c18310b
[Not reviewed]
0 1 0
HanzZ - 14 years ago 2011-08-11 23:28:02
hanzz.k@gmail.com
set privacy type to deny_users
1 file changed with 2 insertions and 0 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -126,192 +126,194 @@ static void *requestAction(const char *title, const char *primary, const char *s
 
	if (t == "SSL Certificate Verification") {
 
		LOG4CXX_INFO(logger,  "accepting SSL certificate");
 
		va_arg(actions, char *);
 
		((PurpleRequestActionCb) va_arg(actions, GCallback)) (user_data, 2);
 
	}
 
	else {
 
		if (title) {
 
			std::string headerString(title);
 
			LOG4CXX_INFO(logger,  "header string: " << headerString);
 
			if (headerString == "SSL Certificate Verification") {
 
				va_arg(actions, char *);
 
				((PurpleRequestActionCb) va_arg(actions, GCallback)) (user_data, 2);
 
			}
 
		}
 
	}
 
	return NULL;
 
}
 

	
 
static std::string getAlias(PurpleBuddy *m_buddy) {
 
	std::string alias;
 
	PurpleContact *contact = PURPLE_CONTACT(PURPLE_BLIST_NODE(m_buddy)->parent);
 
	if (contact && contact->alias) {
 
		alias = contact->alias;
 
	}
 
	else if (purple_buddy_get_alias(m_buddy)) {
 
		alias = (std::string) purple_buddy_get_alias(m_buddy);
 
	}
 
	else {
 
		alias = (std::string) purple_buddy_get_server_alias(m_buddy);
 
	}
 
	return alias;
 
}
 

	
 
class SpectrumNetworkPlugin : public NetworkPlugin {
 
	public:
 
		SpectrumEventLoop *m_loop;
 
		SpectrumNetworkPlugin(Config *config, SpectrumEventLoop *loop, const std::string &host, int port) : NetworkPlugin(loop, host, port) {
 
			this->config = config;
 
			m_loop = loop;
 
		}
 

	
 
		void handleExit() {
 
			m_loop->stop();
 
		}
 

	
 
		void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
 
			PurpleAccount *account = NULL;
 
			
 
			std::string name = legacyName;
 
			std::string protocol = CONFIG_STRING(config, "service.protocol");
 
			if (CONFIG_STRING(config, "service.protocol") == "any") {
 
				protocol = name.substr(0, name.find("."));
 
				name = name.substr(name.find(".") + 1);
 
			}
 

	
 
			LOG4CXX_INFO(logger,  "Creating account with name '" << name.c_str() << "' and protocol '" << protocol << "'");
 
			if (purple_accounts_find(name.c_str(), protocol.c_str()) != NULL){
 
// 				Log(user, "this account already exists");
 
				account = purple_accounts_find(name.c_str(), protocol.c_str());
 
// 				User *u = (User *) account->ui_data;
 
// 				if (u && u != user) {
 
// 					Log(userInfo.jid, "This account is already connected by another jid " << user->getJID());
 
// 					return;
 
// 				}
 
			}
 
			else {
 
// 				Log(user, "creating new account");
 
				account = purple_account_new(name.c_str(), protocol.c_str());
 

	
 
				purple_accounts_add(account);
 
			}
 

	
 
			m_sessions[user] = account;
 

	
 
			// Default avatar
 
			char* contents;
 
			gsize length;
 
			gboolean ret = false;
 
			if (!CONFIG_STRING(config, "backend.avatars_directory").empty()) {
 
				std::string f = CONFIG_STRING(config, "backend.avatars_directory") + "/" + legacyName;
 
				ret = g_file_get_contents (f.c_str(), &contents, &length, NULL);
 
			}
 

	
 
			if (!CONFIG_STRING(config, "backend.default_avatar").empty() && !ret) {
 
				ret = g_file_get_contents (CONFIG_STRING(config, "backend.default_avatar").c_str(),
 
											&contents, &length, NULL);
 
			}
 

	
 
			if (ret) {
 
				purple_buddy_icons_set_account_icon(account, (guchar *) contents, length);
 
			}
 

	
 
			purple_account_set_password(account, password.c_str());
 
			purple_account_set_enabled(account, "spectrum", TRUE);
 
			purple_account_set_bool(account, "custom_smileys", FALSE);
 

	
 
			purple_account_set_privacy_type(account, PURPLE_PRIVACY_DENY_USERS);
 

	
 
			const PurpleStatusType *status_type = purple_account_get_status_type_with_primitive(account, PURPLE_STATUS_AVAILABLE);
 
			if (status_type != NULL) {
 
				purple_account_set_status(account, purple_status_type_get_id(status_type), TRUE, NULL);
 
			}
 
			m_accounts[account] = user;
 
		}
 

	
 
		void handleLogoutRequest(const std::string &user, const std::string &legacyName) {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
// 				VALGRIND_DO_LEAK_CHECK;
 
				m_sessions[user] = NULL;
 
				purple_account_set_enabled(account, "spectrum", FALSE);
 

	
 
				// Remove conversations.
 
				// This has to be called before m_account->ui_data = NULL;, because it uses
 
				// ui_data to call SpectrumMessageHandler::purpleConversationDestroyed() callback.
 
				GList *iter;
 
				for (iter = purple_get_conversations(); iter; ) {
 
					PurpleConversation *conv = (PurpleConversation*) iter->data;
 
					iter = iter->next;
 
					if (purple_conversation_get_account(conv) == account)
 
						purple_conversation_destroy(conv);
 
				}
 

	
 
				g_free(account->ui_data);
 
				account->ui_data = NULL;
 
				m_accounts.erase(account);
 

	
 
				purple_notify_close_with_handle(account);
 
				purple_request_close_with_handle(account);
 

	
 
				purple_accounts_remove(account);
 

	
 
				GSList *buddies = purple_find_buddies(account, NULL);
 
				while(buddies) {
 
					PurpleBuddy *b = (PurpleBuddy *) buddies->data;
 
					purple_blist_remove_buddy(b);
 
					buddies = g_slist_delete_link(buddies, buddies);
 
				}
 

	
 
				/* Remove any open conversation for this account */
 
				for (GList *it = purple_get_conversations(); it; ) {
 
					PurpleConversation *conv = (PurpleConversation *) it->data;
 
					it = it->next;
 
					if (purple_conversation_get_account(conv) == account)
 
						purple_conversation_destroy(conv);
 
				}
 

	
 
				/* Remove this account's pounces */
 
					// purple_pounce_destroy_all_by_account(account);
 

	
 
				/* This will cause the deletion of an old buddy icon. */
 
				purple_buddy_icons_set_account_icon(account, NULL, 0);
 

	
 
				purple_account_destroy(account);
 
				// force returning of memory chunks allocated by libxml2 to kernel
 
				malloc_trim(0);
 
// 				VALGRIND_DO_LEAK_CHECK;
 
			}
 
		}
 

	
 
		void handleStatusChangeRequest(const std::string &user, int status, const std::string &statusMessage) {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
				int st;
 
				switch(status) {
 
					case Swift::StatusShow::Away: {
 
						st = PURPLE_STATUS_AWAY;
 
						if (!purple_account_get_status_type_with_primitive(account, PURPLE_STATUS_AWAY))
 
							st = PURPLE_STATUS_EXTENDED_AWAY;
 
						else
 
							st = PURPLE_STATUS_AWAY;
 
						break;
 
					}
 
					case Swift::StatusShow::DND: {
 
						st = PURPLE_STATUS_UNAVAILABLE;
 
						break;
 
					}
 
					case Swift::StatusShow::XA: {
 
						if (!purple_account_get_status_type_with_primitive(account, PURPLE_STATUS_EXTENDED_AWAY))
 
							st = PURPLE_STATUS_AWAY;
 
						else
 
							st = PURPLE_STATUS_EXTENDED_AWAY;
 
						break;
 
					}
 
					case Swift::StatusShow::None: {
 
						st = PURPLE_STATUS_OFFLINE;
 
						break;
 
					}
 
					default:
 
						st = PURPLE_STATUS_AVAILABLE;
 
						break;
 
				}
 
				gchar *_markup = purple_markup_escape_text(statusMessage.c_str(), -1);
 
				std::string markup(_markup);
0 comments (0 inline, 0 general)