Changeset - 2b338d77da37
[Not reviewed]
0 3 0
Jan Kaluza - 14 years ago 2011-05-25 16:46:40
hanzz.k@gmail.com
Messaging using libpurple backend works again
3 files changed with 7 insertions and 5 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -53,96 +53,98 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
	public:
 
		SpectrumNetworkPlugin(Config *config, SpectrumEventLoop *loop, const std::string &host, int port) : NetworkPlugin(loop, host, port) {
 
			this->config = config;
 
		}
 

	
 
		void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
 
			PurpleAccount *account = NULL;
 
			const char *protocol = CONFIG_STRING(config, "service.protocol").c_str();
 
			if (purple_accounts_find(legacyName.c_str(), protocol) != NULL){
 
				Log(user, "this account already exists");
 
				account = purple_accounts_find(legacyName.c_str(), protocol);
 
// 				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(legacyName.c_str(), protocol);
 

	
 
				purple_accounts_add(account);
 
			}
 

	
 
			m_sessions[user] = account;
 
			purple_account_set_password(account, password.c_str());
 
			purple_account_set_enabled(account, "spectrum", TRUE);
 
			
 
			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) {
 
			const char *protocol = CONFIG_STRING(config, "service.protocol").c_str();
 
			PurpleAccount *account = purple_accounts_find(legacyName.c_str(), protocol);
 
			if (account) {
 
				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);
 
			}
 
		}
 

	
 
		void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message) {
 
			const char *protocol = CONFIG_STRING(config, "service.protocol").c_str();
 
			PurpleAccount *account = purple_accounts_find(user.c_str(), protocol);
 
			std::cout << user << "\n";
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
				PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, legacyName.c_str(), account);
 
				if (!conv) {
 
					conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, legacyName.c_str());
 
				}
 
				gchar *_markup = purple_markup_escape_text(message.c_str(), -1);
 
				purple_conv_im_send(PURPLE_CONV_IM(conv), _markup);
 
				g_free(_markup);
 
			}
 
		}
 

	
 
		std::map<std::string, PurpleAccount *> m_sessions;
 
		std::map<PurpleAccount *, std::string> m_accounts;
 
	private:
 
		Config *config;
 
};
 

	
 
static std::string getAlias(PurpleBuddy *m_buddy) {
 
	std::string alias;
 
	if (purple_buddy_get_server_alias(m_buddy))
 
		alias = (std::string) purple_buddy_get_server_alias(m_buddy);
 
	else
 
		alias = (std::string) purple_buddy_get_alias(m_buddy);
 
	return alias;
 
}
 

	
 
static std::string getName(PurpleBuddy *m_buddy) {
 
	std::string name(purple_buddy_get_name(m_buddy));
 
	if (name.empty()) {
 
		Log("getName", "Name is EMPTY!");
 
	}
 
	return name;
 
}
 

	
 
static bool getStatus(PurpleBuddy *m_buddy, Swift::StatusShow &status, std::string &statusMessage) {
 
	PurplePresence *pres = purple_buddy_get_presence(m_buddy);
docs/Doxyfile
Show inline comments
 
@@ -1424,49 +1424,49 @@ CALL_GRAPH             = NO
 

	
 
CALLER_GRAPH           = NO
 

	
 
# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen 
 
# will graphical hierarchy of all classes instead of a textual one.
 

	
 
GRAPHICAL_HIERARCHY    = YES
 

	
 
# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES 
 
# then doxygen will show the dependencies a directory has on other directories 
 
# in a graphical way. The dependency relations are determined by the #include 
 
# relations between the files in the directories.
 

	
 
DIRECTORY_GRAPH        = YES
 

	
 
# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images 
 
# generated by dot. Possible values are png, jpg, or gif 
 
# If left blank png will be used.
 

	
 
DOT_IMAGE_FORMAT       = png
 

	
 
# The tag DOT_PATH can be used to specify the path where the dot tool can be 
 
# found. If left blank, it is assumed the dot tool can be found in the path.
 

	
 
DOT_PATH               = "/usr/bin"
 
DOT_PATH               = ""
 

	
 
# The DOTFILE_DIRS tag can be used to specify one or more directories that 
 
# contain dot files that are included in the documentation (see the 
 
# \dotfile command).
 

	
 
DOTFILE_DIRS           = 
 

	
 
# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of 
 
# nodes that will be shown in the graph. If the number of nodes in a graph 
 
# becomes larger than this value, doxygen will truncate the graph, which is 
 
# visualized by representing a node as a red box. Note that doxygen if the 
 
# number of direct children of the root node in a graph is already larger than 
 
# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note 
 
# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
 

	
 
DOT_GRAPH_MAX_NODES    = 50
 

	
 
# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the 
 
# graphs generated by dot. A depth value of 3 means that only nodes reachable 
 
# from the root by following a path via at most 3 edges will be shown. Nodes 
 
# that lay further from the root node will be omitted. Note that setting this 
 
# option to 1 or 2 may greatly reduce the computation time needed for large 
 
# code bases. Also note that the size of a graph can be further restricted by 
 
# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
spectrum/src/sample.cfg
Show inline comments
 
[service]
 
jid = localhost
 
password = secret
 
server = 127.0.0.1
 
port = 5222
 
server_mode = 1
 
#backend=../../backends/libpurple/libpurple_backend
 
backend=../../backends/libircclient-qt/libircclient-qt_backend
 
backend=../../backends/libpurple/libpurple_backend
 
#backend=../../backends/libircclient-qt/libircclient-qt_backend
 
protocol=prpl-jabber
 

	
 
[database]
 
database = test.sql
 
prefix=icq
0 comments (0 inline, 0 general)