Changeset - 80816f9517d4
[Not reviewed]
Merge
0 8 0
Jan Kaluza - 13 years ago 2012-09-06 08:43:25
hanzz.k@gmail.com
Merge branch 'master' of github.com:hanzz/libtransport
7 files changed with 71 insertions and 7 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -1483,107 +1483,109 @@ static void printDebug(PurpleDebugLevel level, const char *category, const char
 
/*
 
 * Ops....
 
 */
 
static PurpleDebugUiOps debugUiOps =
 
{
 
	printDebug,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
static void buddyTyping(PurpleAccount *account, const char *who, gpointer null) {
 
	std::string w = purple_normalize_wrapped(account, who);
 
	size_t pos = w.find("/");
 
	if (pos != std::string::npos)
 
		w.erase((int) pos, w.length() - (int) pos);
 
	np->handleBuddyTyping(np->m_accounts[account], w);
 
}
 

	
 
static void buddyTyped(PurpleAccount *account, const char *who, gpointer null) {
 
	std::string w = purple_normalize_wrapped(account, who);
 
	size_t pos = w.find("/");
 
	if (pos != std::string::npos)
 
		w.erase((int) pos, w.length() - (int) pos);
 
	np->handleBuddyTyped(np->m_accounts[account], w);
 
}
 

	
 
static void buddyTypingStopped(PurpleAccount *account, const char *who, gpointer null){
 
	std::string w = purple_normalize_wrapped(account, who);
 
	size_t pos = w.find("/");
 
	if (pos != std::string::npos)
 
		w.erase((int) pos, w.length() - (int) pos);
 
	np->handleBuddyStoppedTyping(np->m_accounts[account], w);
 
}
 

	
 
static void gotAttention(PurpleAccount *account, const char *who, PurpleConversation *conv, guint type) {
 
	std::string w = purple_normalize_wrapped(account, who);
 
	size_t pos = w.find("/");
 
	if (pos != std::string::npos)
 
		w.erase((int) pos, w.length() - (int) pos);
 
	np->handleAttention(np->m_accounts[account], w, "");
 
}
 

	
 
static bool initPurple() {
 
	bool ret;
 

	
 
	if (!resolvePurpleFunctions()) {
 
	std::string libPurpleDllPath = CONFIG_STRING_DEFAULTED(config, "purple.libpurple_dll_path", "");
 

	
 
	if (!resolvePurpleFunctions(libPurpleDllPath)) {
 
		LOG4CXX_ERROR(logger, "Unable to load libpurple.dll or some of the needed methods");
 
		return false;
 
	}
 

	
 
	std::string pluginsDir = CONFIG_STRING_DEFAULTED(config, "purple.plugins_dir", "./plugins");
 
	LOG4CXX_INFO(logger, "Setting libpurple plugins directory to: " << pluginsDir);
 
	purple_plugins_add_search_path_wrapped(pluginsDir.c_str());
 

	
 
	std::string cacertsDir = CONFIG_STRING_DEFAULTED(config, "purple.cacerts_dir", "./ca-certs");
 
	LOG4CXX_INFO(logger, "Setting libpurple plugins directory to: " << cacertsDir);
 
	LOG4CXX_INFO(logger, "Setting libpurple cacerts directory to: " << cacertsDir);
 
	purple_certificate_add_ca_search_path_wrapped(cacertsDir.c_str());
 
 
 
	std::string userDir = CONFIG_STRING_DEFAULTED(config, "service.working_dir", "./");
 
	LOG4CXX_INFO(logger, "Setting libpurple user directory to: " << userDir);
 

	
 
	purple_util_set_user_dir_wrapped(userDir.c_str());
 
	remove("./accounts.xml");
 
	remove("./blist.xml");
 

	
 
	purple_debug_set_ui_ops_wrapped(&debugUiOps);
 
	purple_debug_set_verbose_wrapped(true);
 

	
 
	purple_core_set_ui_ops_wrapped(&coreUiOps);
 
	if (CONFIG_STRING_DEFAULTED(config, "service.eventloop", "") == "libev") {
 
		LOG4CXX_INFO(logger, "Will use libev based event loop");
 
	}
 
	else {
 
		LOG4CXX_INFO(logger, "Will use glib based event loop");
 
	}
 
	purple_eventloop_set_ui_ops_wrapped(getEventLoopUiOps(CONFIG_STRING_DEFAULTED(config, "service.eventloop", "") == "libev"));
 

	
 
	ret = purple_core_init_wrapped("spectrum");
 
	if (ret) {
 
		static int blist_handle;
 
		static int conversation_handle;
 

	
 
		purple_set_blist_wrapped(purple_blist_new_wrapped());
 
		purple_blist_load_wrapped();
 

	
 
		purple_prefs_load_wrapped();
 

	
 
		/* Good default preferences */
 
		/* The combination of these two settings mean that libpurple will never
 
		 * (of its own accord) set all the user accounts idle.
 
		 */
 
		purple_prefs_set_bool_wrapped("/purple/away/away_when_idle", false);
 
		/*
 
		 * This must be set to something not "none" for idle reporting to work
 
		 * for, e.g., the OSCAR prpl. We don't implement the UI ops, so this is
 
		 * okay for now.
 
		 */
 
		purple_prefs_set_string_wrapped("/purple/away/idle_reporting", "system");
 

	
 
		/* Disable all logging */
 
		purple_prefs_set_bool_wrapped("/purple/logging/log_ims", false);
 
		purple_prefs_set_bool_wrapped("/purple/logging/log_chats", false);
 
		purple_prefs_set_bool_wrapped("/purple/logging/log_system", false);
 

	
backends/libpurple/purple_defs.cpp
Show inline comments
 
#include "purple_defs.h"
 
#include "utils.h"
 

	
 
#if PURPLE_RUNTIME
 

	
 
using std::string;
 
using std::wstring;
 

	
 
static HMODULE f_hPurple = NULL;
 
purple_debug_set_ui_ops_wrapped_fnc purple_debug_set_ui_ops_wrapped = NULL;
 
purple_debug_set_verbose_wrapped_fnc purple_debug_set_verbose_wrapped = NULL;
 
purple_request_set_ui_ops_wrapped_fnc purple_request_set_ui_ops_wrapped = NULL;
 
purple_imgstore_get_data_wrapped_fnc purple_imgstore_get_data_wrapped = NULL;
 
purple_imgstore_get_size_wrapped_fnc purple_imgstore_get_size_wrapped = NULL;
 
purple_imgstore_unref_wrapped_fnc purple_imgstore_unref_wrapped = NULL;
 
purple_markup_escape_text_wrapped_fnc purple_markup_escape_text_wrapped = NULL;
 
purple_markup_strip_html_wrapped_fnc purple_markup_strip_html_wrapped = NULL;
 
purple_normalize_wrapped_fnc purple_normalize_wrapped = NULL;
 
purple_strdup_withhtml_wrapped_fnc purple_strdup_withhtml_wrapped = NULL;
 
purple_markup_html_to_xhtml_wrapped_fnc purple_markup_html_to_xhtml_wrapped = NULL;
 
purple_utf8_try_convert_wrapped_fnc purple_utf8_try_convert_wrapped = NULL;
 
purple_util_set_user_dir_wrapped_fnc purple_util_set_user_dir_wrapped = NULL;
 
purple_blist_node_get_type_wrapped_fnc purple_blist_node_get_type_wrapped = NULL;
 
purple_buddy_get_alias_wrapped_fnc purple_buddy_get_alias_wrapped = NULL;
 
purple_buddy_get_server_alias_wrapped_fnc purple_buddy_get_server_alias_wrapped = NULL;
 
purple_find_buddy_wrapped_fnc purple_find_buddy_wrapped = NULL;
 
purple_buddy_get_group_wrapped_fnc purple_buddy_get_group_wrapped = NULL;
 
purple_blist_remove_buddy_wrapped_fnc purple_blist_remove_buddy_wrapped = NULL;
 
purple_blist_alias_buddy_wrapped_fnc purple_blist_alias_buddy_wrapped = NULL;
 
purple_blist_server_alias_buddy_wrapped_fnc purple_blist_server_alias_buddy_wrapped = NULL;
 
purple_find_group_wrapped_fnc purple_find_group_wrapped = NULL;
 
purple_group_new_wrapped_fnc purple_group_new_wrapped = NULL;
 
purple_blist_add_contact_wrapped_fnc purple_blist_add_contact_wrapped = NULL;
 
purple_buddy_get_contact_wrapped_fnc purple_buddy_get_contact_wrapped = NULL;
 
purple_buddy_new_wrapped_fnc purple_buddy_new_wrapped = NULL;
 
purple_blist_add_buddy_wrapped_fnc purple_blist_add_buddy_wrapped = NULL;
 
purple_blist_find_chat_wrapped_fnc purple_blist_find_chat_wrapped = NULL;
 
purple_chat_get_components_wrapped_fnc purple_chat_get_components_wrapped = NULL;
 
purple_buddy_get_presence_wrapped_fnc purple_buddy_get_presence_wrapped = NULL;
 
purple_buddy_get_account_wrapped_fnc purple_buddy_get_account_wrapped = NULL;
 
purple_buddy_get_name_wrapped_fnc purple_buddy_get_name_wrapped = NULL;
 
purple_find_buddies_wrapped_fnc purple_find_buddies_wrapped = NULL;
 
purple_group_get_name_wrapped_fnc purple_group_get_name_wrapped = NULL;
 
purple_blist_set_ui_ops_wrapped_fnc purple_blist_set_ui_ops_wrapped = NULL;
 
purple_set_blist_wrapped_fnc purple_set_blist_wrapped = NULL;
 
purple_blist_new_wrapped_fnc purple_blist_new_wrapped = NULL;
 
purple_blist_load_wrapped_fnc purple_blist_load_wrapped = NULL;
 
purple_blist_get_handle_wrapped_fnc purple_blist_get_handle_wrapped = NULL;
 
purple_xfer_ui_ready_wrapped_fnc purple_xfer_ui_ready_wrapped = NULL;
 
purple_xfer_request_accepted_wrapped_fnc purple_xfer_request_accepted_wrapped = NULL;
 
purple_xfer_request_denied_wrapped_fnc purple_xfer_request_denied_wrapped = NULL;
 
purple_certificate_add_ca_search_path_wrapped_fnc purple_certificate_add_ca_search_path_wrapped = NULL;
 
purple_xfer_get_account_wrapped_fnc purple_xfer_get_account_wrapped = NULL;
 
purple_xfer_get_filename_wrapped_fnc purple_xfer_get_filename_wrapped = NULL;
 
purple_xfer_get_size_wrapped_fnc purple_xfer_get_size_wrapped = NULL;
 
purple_xfer_unref_wrapped_fnc purple_xfer_unref_wrapped = NULL;
 
@@ -93,99 +98,109 @@ purple_account_add_buddy_wrapped_fnc purple_account_add_buddy_wrapped = NULL;
 
purple_account_get_name_for_display_wrapped_fnc purple_account_get_name_for_display_wrapped = NULL;
 
purple_accounts_set_ui_ops_wrapped_fnc purple_accounts_set_ui_ops_wrapped = NULL;
 
purple_status_type_get_id_wrapped_fnc purple_status_type_get_id_wrapped = NULL;
 
purple_presence_get_active_status_wrapped_fnc purple_presence_get_active_status_wrapped = NULL;
 
purple_status_type_get_primitive_wrapped_fnc purple_status_type_get_primitive_wrapped = NULL;
 
purple_status_get_type_wrapped_fnc purple_status_get_type_wrapped = NULL;
 
purple_status_get_attr_string_wrapped_fnc purple_status_get_attr_string_wrapped = NULL;
 
serv_get_info_wrapped_fnc serv_get_info_wrapped = NULL;
 
serv_alias_buddy_wrapped_fnc serv_alias_buddy_wrapped = NULL;
 
serv_send_typing_wrapped_fnc serv_send_typing_wrapped = NULL;
 
serv_join_chat_wrapped_fnc serv_join_chat_wrapped = NULL;
 
purple_dnsquery_set_ui_ops_wrapped_fnc purple_dnsquery_set_ui_ops_wrapped = NULL;
 
purple_conversation_get_im_data_wrapped_fnc purple_conversation_get_im_data_wrapped = NULL;
 
purple_conversation_get_chat_data_wrapped_fnc purple_conversation_get_chat_data_wrapped = NULL;
 
purple_find_conversation_with_account_wrapped_fnc purple_find_conversation_with_account_wrapped = NULL;
 
purple_conversation_new_wrapped_fnc purple_conversation_new_wrapped = NULL;
 
purple_conversation_get_type_wrapped_fnc purple_conversation_get_type_wrapped = NULL;
 
purple_conv_im_send_wrapped_fnc purple_conv_im_send_wrapped = NULL;
 
purple_conv_chat_send_wrapped_fnc purple_conv_chat_send_wrapped = NULL;
 
purple_conversation_destroy_wrapped_fnc purple_conversation_destroy_wrapped = NULL;
 
purple_conversation_get_account_wrapped_fnc purple_conversation_get_account_wrapped = NULL;
 
purple_conversation_get_name_wrapped_fnc purple_conversation_get_name_wrapped = NULL;
 
purple_conversations_set_ui_ops_wrapped_fnc purple_conversations_set_ui_ops_wrapped = NULL;
 
purple_conversations_get_handle_wrapped_fnc purple_conversations_get_handle_wrapped = NULL;
 
purple_plugin_action_free_wrapped_fnc purple_plugin_action_free_wrapped = NULL;
 
purple_plugins_add_search_path_wrapped_fnc purple_plugins_add_search_path_wrapped = NULL;
 
purple_connection_get_state_wrapped_fnc purple_connection_get_state_wrapped = NULL;
 
purple_connection_get_account_wrapped_fnc purple_connection_get_account_wrapped = NULL;
 
purple_connection_get_display_name_wrapped_fnc purple_connection_get_display_name_wrapped = NULL;
 
purple_connections_set_ui_ops_wrapped_fnc purple_connections_set_ui_ops_wrapped = NULL;
 
purple_connections_get_handle_wrapped_fnc purple_connections_get_handle_wrapped = NULL;
 
purple_core_set_ui_ops_wrapped_fnc purple_core_set_ui_ops_wrapped = NULL;
 
purple_core_init_wrapped_fnc purple_core_init_wrapped = NULL;
 
purple_input_add_wrapped_fnc purple_input_add_wrapped = NULL;
 
purple_timeout_add_wrapped_fnc purple_timeout_add_wrapped = NULL;
 
purple_timeout_add_seconds_wrapped_fnc purple_timeout_add_seconds_wrapped = NULL;
 
purple_timeout_remove_wrapped_fnc purple_timeout_remove_wrapped = NULL;
 
purple_eventloop_set_ui_ops_wrapped_fnc purple_eventloop_set_ui_ops_wrapped = NULL;
 
purple_input_remove_wrapped_fnc purple_input_remove_wrapped = NULL;
 
purple_privacy_deny_wrapped_fnc purple_privacy_deny_wrapped = NULL;
 
purple_privacy_allow_wrapped_fnc purple_privacy_allow_wrapped = NULL;
 
purple_privacy_check_wrapped_fnc purple_privacy_check_wrapped = NULL;
 
purple_find_prpl_wrapped_fnc purple_find_prpl_wrapped = NULL;
 
purple_prpl_send_attention_wrapped_fnc purple_prpl_send_attention_wrapped = NULL;
 
purple_account_option_get_type_wrapped_fnc purple_account_option_get_type_wrapped = NULL;
 
purple_account_option_get_setting_wrapped_fnc purple_account_option_get_setting_wrapped = NULL;
 
wpurple_g_io_channel_win32_new_socket_wrapped_fnc wpurple_g_io_channel_win32_new_socket_wrapped = NULL;
 
#endif
 
bool resolvePurpleFunctions() {
 
bool resolvePurpleFunctions(const std::string& libPurpleDllPath) {
 
#if PURPLE_RUNTIME
 
	f_hPurple = LoadLibrary(L"libpurple.dll");
 
	std::wstring dllPath;
 
	if (!libPurpleDllPath.empty())
 
	{
 
		dllPath = utf8ToUtf16(libPurpleDllPath);
 
	}
 
	else
 
	{
 
		// No path was specified, so try loading libpurple from the current working directory
 
		dllPath = L"libpurple.dll";
 
	}
 
	f_hPurple = LoadLibrary(dllPath.c_str());
 
	if (!f_hPurple)
 
			return false;
 
	purple_debug_set_ui_ops_wrapped = (purple_debug_set_ui_ops_wrapped_fnc)GetProcAddress(f_hPurple, "purple_debug_set_ui_ops");
 
	if (!purple_debug_set_ui_ops_wrapped)
 
		return false;
 

	
 
	purple_debug_set_verbose_wrapped = (purple_debug_set_verbose_wrapped_fnc)GetProcAddress(f_hPurple, "purple_debug_set_verbose");
 
	if (!purple_debug_set_verbose_wrapped)
 
		return false;
 

	
 
	purple_request_set_ui_ops_wrapped = (purple_request_set_ui_ops_wrapped_fnc)GetProcAddress(f_hPurple, "purple_request_set_ui_ops");
 
	if (!purple_request_set_ui_ops_wrapped)
 
		return false;
 

	
 
	purple_imgstore_get_data_wrapped = (purple_imgstore_get_data_wrapped_fnc)GetProcAddress(f_hPurple, "purple_imgstore_get_data");
 
	if (!purple_imgstore_get_data_wrapped)
 
		return false;
 

	
 
	purple_imgstore_get_size_wrapped = (purple_imgstore_get_size_wrapped_fnc)GetProcAddress(f_hPurple, "purple_imgstore_get_size");
 
	if (!purple_imgstore_get_size_wrapped)
 
		return false;
 

	
 
	purple_imgstore_unref_wrapped = (purple_imgstore_unref_wrapped_fnc)GetProcAddress(f_hPurple, "purple_imgstore_unref");
 
	if (!purple_imgstore_unref_wrapped)
 
		return false;
 

	
 
	purple_markup_escape_text_wrapped = (purple_markup_escape_text_wrapped_fnc)GetProcAddress(f_hPurple, "purple_markup_escape_text");
 
	if (!purple_markup_escape_text_wrapped)
 
		return false;
 

	
 
	purple_markup_strip_html_wrapped = (purple_markup_strip_html_wrapped_fnc)GetProcAddress(f_hPurple, "purple_markup_strip_html");
 
	if (!purple_markup_strip_html_wrapped)
 
		return false;
 

	
 
	purple_normalize_wrapped = (purple_normalize_wrapped_fnc)GetProcAddress(f_hPurple, "purple_normalize");
 
	if (!purple_normalize_wrapped)
 
		return false;
 

	
 
	purple_strdup_withhtml_wrapped = (purple_strdup_withhtml_wrapped_fnc)GetProcAddress(f_hPurple, "purple_strdup_withhtml");
 
	if (!purple_strdup_withhtml_wrapped)
 
		return false;
 

	
 
	purple_markup_html_to_xhtml_wrapped = (purple_markup_html_to_xhtml_wrapped_fnc)GetProcAddress(f_hPurple, "purple_markup_html_to_xhtml");
 
	if (!purple_markup_html_to_xhtml_wrapped)
 
		return false;
 

	
 
	purple_utf8_try_convert_wrapped = (purple_utf8_try_convert_wrapped_fnc)GetProcAddress(f_hPurple, "purple_utf8_try_convert");
 
	if (!purple_utf8_try_convert_wrapped)
backends/libpurple/purple_defs.h
Show inline comments
 
#pragma once
 
#include <string>
 

	
 
#if PURPLE_RUNTIME
 

	
 
#include <Windows.h>
 
#include <purple.h>
 

	
 
#define PURPLE_BLIST_NODE_IS_CHAT_WRAPPED(n)    (purple_blist_node_get_type_wrapped(n) == PURPLE_BLIST_CHAT_NODE)
 
#define PURPLE_BLIST_NODE_IS_BUDDY_WRAPPED(n)   (purple_blist_node_get_type_wrapped(n) == PURPLE_BLIST_BUDDY_NODE)
 
#define PURPLE_BLIST_NODE_IS_CONTACT_WRAPPED(n) (purple_blist_node_get_type_wrapped(n) == PURPLE_BLIST_CONTACT_NODE)
 
#define PURPLE_BLIST_NODE_IS_GROUP_WRAPPED(n)   (purple_blist_node_get_type_wrapped(n) == PURPLE_BLIST_GROUP_NODE)
 

	
 
#define PURPLE_CONV_IM_WRAPPED(c) (purple_conversation_get_im_data_wrapped(c))
 
#define PURPLE_CONV_CHAT_WRAPPED(c) (purple_conversation_get_chat_data_wrapped(c))
 

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

	
 
typedef void  (_cdecl * purple_debug_set_ui_ops_wrapped_fnc)(PurpleDebugUiOps *ops);
 
extern purple_debug_set_ui_ops_wrapped_fnc purple_debug_set_ui_ops_wrapped;
 

	
 
typedef void  (_cdecl * purple_debug_set_verbose_wrapped_fnc)(gboolean verbose);
 
extern purple_debug_set_verbose_wrapped_fnc purple_debug_set_verbose_wrapped;
 

	
 
typedef void  (_cdecl * purple_request_set_ui_ops_wrapped_fnc)(PurpleRequestUiOps *ops);
 
extern purple_request_set_ui_ops_wrapped_fnc purple_request_set_ui_ops_wrapped;
 

	
 
typedef gconstpointer  (_cdecl * purple_imgstore_get_data_wrapped_fnc)(PurpleStoredImage *img);
 
extern purple_imgstore_get_data_wrapped_fnc purple_imgstore_get_data_wrapped;
 

	
 
typedef size_t  (_cdecl * purple_imgstore_get_size_wrapped_fnc)(PurpleStoredImage *img);
 
extern purple_imgstore_get_size_wrapped_fnc purple_imgstore_get_size_wrapped;
 

	
 
typedef PurpleStoredImage * (_cdecl * purple_imgstore_unref_wrapped_fnc)(PurpleStoredImage *img);
 
extern purple_imgstore_unref_wrapped_fnc purple_imgstore_unref_wrapped;
 

	
 
typedef gchar * (_cdecl * purple_markup_escape_text_wrapped_fnc)(const gchar *text, gssize length);
 
extern purple_markup_escape_text_wrapped_fnc purple_markup_escape_text_wrapped;
 

	
 
typedef char * (_cdecl * purple_markup_strip_html_wrapped_fnc)(const char *str);
 
extern purple_markup_strip_html_wrapped_fnc purple_markup_strip_html_wrapped;
 

	
 
typedef const char * (_cdecl * purple_normalize_wrapped_fnc)(const PurpleAccount *account, const char *str);
 
extern purple_normalize_wrapped_fnc purple_normalize_wrapped;
 

	
 
typedef gchar * (_cdecl * purple_strdup_withhtml_wrapped_fnc)(const gchar *src);
 
extern purple_strdup_withhtml_wrapped_fnc purple_strdup_withhtml_wrapped;
 

	
 
typedef void  (_cdecl * purple_markup_html_to_xhtml_wrapped_fnc)(const char *html, char **dest_xhtml, char **dest_plain);
 
extern purple_markup_html_to_xhtml_wrapped_fnc purple_markup_html_to_xhtml_wrapped;
 

	
 
@@ -525,50 +527,50 @@ extern wpurple_g_io_channel_win32_new_socket_wrapped_fnc wpurple_g_io_channel_wi
 
#define purple_status_type_get_id_wrapped purple_status_type_get_id
 
#define purple_presence_get_active_status_wrapped purple_presence_get_active_status
 
#define purple_status_type_get_primitive_wrapped purple_status_type_get_primitive
 
#define purple_status_get_type_wrapped purple_status_get_type
 
#define purple_status_get_attr_string_wrapped purple_status_get_attr_string
 
#define serv_get_info_wrapped serv_get_info
 
#define serv_alias_buddy_wrapped serv_alias_buddy
 
#define serv_send_typing_wrapped serv_send_typing
 
#define serv_join_chat_wrapped serv_join_chat
 
#define purple_dnsquery_set_ui_ops_wrapped purple_dnsquery_set_ui_ops
 
#define purple_conversation_get_im_data_wrapped purple_conversation_get_im_data
 
#define purple_conversation_get_chat_data_wrapped purple_conversation_get_chat_data
 
#define purple_find_conversation_with_account_wrapped purple_find_conversation_with_account
 
#define purple_conversation_new_wrapped purple_conversation_new
 
#define purple_conversation_get_type_wrapped purple_conversation_get_type
 
#define purple_conv_im_send_wrapped purple_conv_im_send
 
#define purple_conv_chat_send_wrapped purple_conv_chat_send
 
#define purple_conversation_destroy_wrapped purple_conversation_destroy
 
#define purple_conversation_get_account_wrapped purple_conversation_get_account
 
#define purple_conversation_get_name_wrapped purple_conversation_get_name
 
#define purple_conversations_set_ui_ops_wrapped purple_conversations_set_ui_ops
 
#define purple_conversations_get_handle_wrapped purple_conversations_get_handle
 
#define purple_plugin_action_free_wrapped purple_plugin_action_free
 
#define purple_certificate_add_ca_search_path_wrapped purple_certificate_add_ca_search_path
 
#define purple_plugins_add_search_path_wrapped purple_plugins_add_search_path
 
#define purple_connection_get_state_wrapped purple_connection_get_state
 
#define purple_connection_get_account_wrapped purple_connection_get_account
 
#define purple_connection_get_display_name_wrapped purple_connection_get_display_name
 
#define purple_connections_set_ui_ops_wrapped purple_connections_set_ui_ops
 
#define purple_connections_get_handle_wrapped purple_connections_get_handle
 
#define purple_core_set_ui_ops_wrapped purple_core_set_ui_ops
 
#define purple_core_init_wrapped purple_core_init
 
#define purple_input_add_wrapped purple_input_add
 
#define purple_timeout_add_wrapped purple_timeout_add
 
#define purple_timeout_add_seconds_wrapped purple_timeout_add_seconds
 
#define purple_timeout_remove_wrapped purple_timeout_remove
 
#define purple_eventloop_set_ui_ops_wrapped purple_eventloop_set_ui_ops
 
#define purple_input_remove_wrapped purple_input_remove
 
#define purple_privacy_deny_wrapped purple_privacy_deny
 
#define purple_privacy_allow_wrapped purple_privacy_allow
 
#define purple_privacy_check_wrapped purple_privacy_check
 
#define purple_find_prpl_wrapped purple_find_prpl
 
#define purple_prpl_send_attention_wrapped purple_prpl_send_attention
 
#define purple_account_option_get_type_wrapped purple_account_option_get_type
 
#define purple_account_option_get_setting_wrapped purple_account_option_get_setting
 
#define wpurple_g_io_channel_win32_new_socket_wrapped wpurple_g_io_channel_win32_new_socket
 
#endif
 

	
 
bool resolvePurpleFunctions();
 
bool resolvePurpleFunctions(const std::string& libPurpleDllPath);
 

	
backends/libpurple/utils.cpp
Show inline comments
 
/**
 
 * libtransport -- C++ library for easy XMPP Transports development
 
 *
 
 * Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
// win32/libc_interface.h defines its own socket(), read() and so on.
 
// We don't want to use it here.
 
#define _LIBC_INTERFACE_H_ 1
 

	
 
#include "utils.h"
 

	
 
#include "glib.h"
 
#include "purple.h"
 
#include <algorithm>
 
#include <iostream>
 
#include <vector>
 

	
 
#include "errno.h"
 

	
 
#ifndef WIN32 
 
#include "sys/wait.h"
 
#include "sys/signal.h"
 
#include <netinet/if_ether.h>
 
#include <netinet/ip.h>
 
#include <netinet/ip6.h>
 
#include <netinet/udp.h>
 
#include <netinet/tcp.h>
 
#include <netinet/ether.h>
 
#include "sys/socket.h"
 
#include <netdb.h>
 
#include <unistd.h>
 
#include <fcntl.h>
 
#else 
 
#include <process.h>
 
#define getpid _getpid 
 
#define ssize_t SSIZE_T
 
#include "win32/win32dep.h"
 
#define close closesocket
 
#endif
 

	
 
#include "purple_defs.h"
 

	
 
#include <boost/numeric/conversion/cast.hpp>
 

	
 
using std::vector;
 

	
 
static GHashTable *ui_info = NULL;
 

	
 
void execute_purple_plugin_action(PurpleConnection *gc, const std::string &name) {
 
	PurplePlugin *plugin = gc && PURPLE_CONNECTION_IS_CONNECTED_WRAPPED(gc) ? gc->prpl : NULL;
 
	if (plugin && PURPLE_PLUGIN_HAS_ACTIONS(plugin)) {
 
		PurplePluginAction *action = NULL;
 
		GList *actions, *l;
 

	
 
		actions = PURPLE_PLUGIN_ACTIONS(plugin, gc);
 

	
 
		for (l = actions; l != NULL; l = l->next) {
 
			if (l->data) {
 
				action = (PurplePluginAction *) l->data;
 
				action->plugin = plugin;
 
				action->context = gc;
 
				if ((std::string) action->label == name) {
 
					action->callback(action);
 
				}
 
				purple_plugin_action_free_wrapped(action);
 
			}
 
		}
 
	}
 
}
 

	
 
GHashTable *spectrum_ui_get_info(void)
 
{
 
	if(NULL == ui_info) {
 
		ui_info = g_hash_table_new(g_str_hash, g_str_equal);
 

	
 
		g_hash_table_insert(ui_info, g_strdup("name"), g_strdup("Spectrum"));
 
		g_hash_table_insert(ui_info, g_strdup("version"), g_strdup("0.5"));
 
		g_hash_table_insert(ui_info, g_strdup("website"), g_strdup("http://spectrum.im"));
 
		g_hash_table_insert(ui_info, g_strdup("dev_website"), g_strdup("http://spectrum.im"));
 
		g_hash_table_insert(ui_info, g_strdup("client_type"), g_strdup("pc"));
 

	
 
		/*
 
		 * This is the client key for "Pidgin."  It is owned by the AIM
 
		 * account "markdoliner."  Please don't use this key for other
 
		 * applications.  You can either not specify a client key, in
 
		 * which case the default "libpurple" key will be used, or you
 
		 * can register for your own client key at
 
		 * http://developer.aim.com/manageKeys.jsp
 
		 */
 
		g_hash_table_insert(ui_info, g_strdup("prpl-aim-clientkey"), g_strdup("ma1cSASNCKFtrdv9"));
 
		g_hash_table_insert(ui_info, g_strdup("prpl-icq-clientkey"), g_strdup("ma1cSASNCKFtrdv9"));
 

	
 
		/*
 
		 * This is the distid for Pidgin, given to us by AOL.  Please
 
@@ -111,48 +116,79 @@ GHashTable *spectrum_ui_get_info(void)
 

	
 
	return ui_info;
 
}
 

	
 
#ifndef WIN32
 
void spectrum_sigchld_handler(int sig)
 
{
 
	int status;
 
	pid_t pid;
 

	
 
	do {
 
		pid = waitpid(-1, &status, WNOHANG);
 
	} while (pid != 0 && pid != (pid_t)-1);
 

	
 
	if ((pid == (pid_t) - 1) && (errno != ECHILD)) {
 
		char errmsg[BUFSIZ];
 
		snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid);
 
		perror(errmsg);
 
	}
 
}
 
#endif
 

	
 
int create_socket(const char *host, int portno) {
 
	struct sockaddr_in serv_addr;
 
	
 
	int main_socket = socket(AF_INET, SOCK_STREAM, 0);
 
	memset((char *) &serv_addr, 0, sizeof(serv_addr));
 
	serv_addr.sin_family = AF_INET;
 
	serv_addr.sin_port = htons(portno);
 

	
 
	hostent *hos;  // Resolve name
 
	if ((hos = gethostbyname(host)) == NULL) {
 
		// strerror() will not work for gethostbyname() and hstrerror() 
 
		// is supposedly obsolete
 
		exit(1);
 
	}
 
	serv_addr.sin_addr.s_addr = *((unsigned long *) hos->h_addr_list[0]);
 

	
 
	if (connect(main_socket, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
 
		close(main_socket);
 
		main_socket = 0;
 
	}
 

	
 
// 	int flags = fcntl(main_socket, F_GETFL);
 
// 	flags |= O_NONBLOCK;
 
// 	fcntl(main_socket, F_SETFL, flags);
 
	return main_socket;
 
}
 

	
 
#ifdef _WIN32
 
std::wstring utf8ToUtf16(const std::string& str)
 
{
 
	try
 
	{
 
		if (str.empty())
 
			return L"";
 

	
 
		// First request the size of the required UTF-16 buffer
 
		int numRequiredBytes = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), boost::numeric_cast<int>(str.size()), NULL, 0);
 
		if (!numRequiredBytes)
 
			return L"";
 

	
 
		// Allocate memory for the UTF-16 string
 
		std::vector<wchar_t> utf16Str(numRequiredBytes);
 

	
 
		int numConverted = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), boost::numeric_cast<int>(str.size()), &utf16Str[0], numRequiredBytes);
 
		if (!numConverted)
 
			return L"";
 

	
 
		std::wstring wstr(&utf16Str[0], numConverted);
 
		return wstr;
 
	}
 
	catch (...)
 
	{
 
		// I don't believe libtransport is exception-safe so we'll just return an empty string instead
 
		return L"";
 
	}
 
}
 
#endif // _WIN32
backends/libpurple/utils.h
Show inline comments
 
/**
 
 * libtransport -- C++ library for easy XMPP Transports development
 
 *
 
 * Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
 
 *
 
 * This program is free software; you can redistribute it and/or modify
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include "purple.h"
 
#include <string>
 

	
 
#ifndef WIN32
 
void spectrum_sigchld_handler(int sig);
 
#endif
 

	
 
int create_socket(const char *host, int portno);
 
GHashTable *spectrum_ui_get_info(void);
 

	
 
void execute_purple_plugin_action(PurpleConnection *gc, const std::string &name);
 

	
 
#ifdef _WIN32
 
	std::wstring utf8ToUtf16(const std::string& str);
 
#endif
cmake_modules/purpleConfig.cmake
Show inline comments
 
FIND_LIBRARY(PURPLE_LIBRARY NAMES purple)
 
FIND_PATH(PURPLE_INCLUDE_DIR NAMES "purple.h" PATH_SUFFIXES libpurple )
 

	
 
if(WIN32 AND PURPLE_INCLUDE_DIR )
 
	if (PURPLE_NOT_RUNTIME)
 
	if (NOT PURPLE_NOT_RUNTIME)
 
		set(PURPLE_LIBRARY "")
 
	endif(PURPLE_NOT_RUNTIME)
 
	endif(NOT PURPLE_NOT_RUNTIME)
 
	set(PURPLE_FOUND 1)
 
	message(STATUS "Using purple: ${PURPLE_INCLUDE_DIR} ${PURPLE_LIBRARY}")
 
else()
 

	
 
if( PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR )
 
    message( STATUS "Found libpurple: ${PURPLE_LIBRARY}, ${PURPLE_INCLUDE_DIR}")
 
    set( PURPLE_FOUND 1 )
 
else( PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR )
 
    message( STATUS "Could NOT find libpurple" )
 
endif( PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR )
 

	
 
endif()
src/config.cpp
Show inline comments
 
@@ -93,96 +93,101 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
		("service.reuse_old_backends", value<bool>()->default_value(true), "True if Spectrum should use old backends which were full in the past.")
 
		("service.idle_reconnect_time", value<int>()->default_value(0), "Time in seconds after which idle users are reconnected to let their backend die.")
 
		("service.memory_collector_time", value<int>()->default_value(0), "Time in seconds after which backend with most memory is set to die.")
 
		("service.more_resources", value<bool>()->default_value(false), "Allow more resources to be connected in server mode at the same time.")
 
		("service.enable_privacy_lists", value<bool>()->default_value(true), "")
 
		("service.enable_xhtml", value<bool>()->default_value(true), "")
 
		("vhosts.vhost", value<std::vector<std::string> >()->multitoken(), "")
 
		("identity.name", value<std::string>()->default_value("Spectrum 2 Transport"), "Name showed in service discovery.")
 
		("identity.category", value<std::string>()->default_value("gateway"), "Disco#info identity category. 'gateway' by default.")
 
		("identity.type", value<std::string>()->default_value(""), "Type of transport ('icq','msn','gg','irc', ...)")
 
		("registration.enable_public_registration", value<bool>()->default_value(true), "True if users should be able to register.")
 
		("registration.language", value<std::string>()->default_value("en"), "Default language for registration form")
 
		("registration.instructions", value<std::string>()->default_value("Enter your legacy network username and password."), "Instructions showed to user in registration form")
 
		("registration.username_label", value<std::string>()->default_value("Legacy network username:"), "Label for username field")
 
		("registration.username_mask", value<std::string>()->default_value(""), "Username mask")
 
		("registration.allowed_usernames", value<std::string>()->default_value(""), "Allowed usernames")
 
		("registration.auto_register", value<bool>()->default_value(false), "Register new user automatically when the presence arrives.")
 
		("registration.encoding", value<std::string>()->default_value("utf8"), "Default encoding in registration form")
 
		("registration.require_local_account", value<bool>()->default_value(false), "True if users have to have a local account to register to this transport from remote servers.")
 
		("registration.local_username_label", value<std::string>()->default_value("Local username:"), "Label for local usernme field")
 
		("registration.local_account_server", value<std::string>()->default_value("localhost"), "The server on which the local accounts will be checked for validity")
 
		("registration.local_account_server_timeout", value<int>()->default_value(10000), "Timeout when checking local user on local_account_server (msecs)")
 
		("gateway_responder.prompt", value<std::string>()->default_value("Contact ID"), "Value of <prompt> </promt> field")
 
		("gateway_responder.label", value<std::string>()->default_value("Enter legacy network contact ID."), "Label for add contact ID field")
 
		("database.type", value<std::string>()->default_value("none"), "Database type.")
 
		("database.database", value<std::string>()->default_value("/var/lib/spectrum2/$jid/database.sql"), "Database used to store data")
 
		("database.server", value<std::string>()->default_value("localhost"), "Database server.")
 
		("database.user", value<std::string>()->default_value(""), "Database user.")
 
		("database.password", value<std::string>()->default_value(""), "Database Password.")
 
		("database.port", value<int>()->default_value(0), "Database port.")
 
		("database.prefix", value<std::string>()->default_value(""), "Prefix of tables in database")
 
		("database.encryption_key", value<std::string>()->default_value(""), "Encryption key.")
 
		("logging.config", value<std::string>()->default_value(""), "Path to log4cxx config file which is used for Spectrum 2 instance")
 
		("logging.backend_config", value<std::string>()->default_value(""), "Path to log4cxx config file which is used for backends")
 
		("backend.default_avatar", value<std::string>()->default_value(""), "Full path to default avatar")
 
		("backend.avatars_directory", value<std::string>()->default_value(""), "Path to directory with avatars")
 
		("backend.no_vcard_fetch", value<bool>()->default_value(false), "True if VCards for buddies should not be fetched. Only avatars will be forwarded.")
 
		("proxy.server", value<std::string>()->default_value("localhost"), "Proxy IP.")
 
		("proxy.user", value<std::string>()->default_value(""), "Proxy user.")
 
		("proxy.password", value<std::string>()->default_value(""), "Proxy Password.")
 
		("proxy.port", value<int>()->default_value(0), "Proxy port.")
 

	
 
	;
 

	
 
	// Load configs passed by command line
 
	if (m_argc != 0 && m_argv) {
 
		basic_command_line_parser<char> parser = command_line_parser(m_argc, m_argv).options(opts).allow_unregistered();
 
		parsed_options parsed = parser.run();
 
		BOOST_FOREACH(option &opt, parsed.options) {
 
			if (opt.unregistered && !opt.value.empty()) {
 
				m_unregistered[opt.string_key] = variable_value(opt.value[0], false);
 
			}
 
		}
 
		store(parsed, m_variables);
 
	}
 

	
 
	parsed_options parsed = parse_config_file(ifs, opts, true);
 

	
 
	bool found_working = false;
 
	bool found_pidfile = false;
 
	bool found_portfile = false;
 
	bool found_backend_port = false;
 
	bool found_database = false;
 
	std::string jid = "";
 
	BOOST_FOREACH(option &opt, parsed.options) {
 
		if (opt.string_key == "service.jid") {
 
			if (_jid.empty()) {
 
				jid = opt.value[0];
 
			}
 
			else {
 
				opt.value[0] = _jid;
 
				jid = _jid;
 
			}
 
		}
 
		else if (opt.string_key == "service.backend_port") {
 
			found_backend_port = true;
 
			if (opt.value[0] == "0") {
 
				opt.value[0] = boost::lexical_cast<std::string>(getRandomPort(_jid.empty() ? jid : _jid));
 
			}
 
		}
 
		else if (opt.string_key == "service.working_dir") {
 
			found_working = true;
 
		}
 
		else if (opt.string_key == "service.pidfile") {
 
			found_pidfile = true;
 
		}
 
		else if (opt.string_key == "service.portfile") {
 
			found_portfile = true;
 
		}
 
		else if (opt.string_key == "database.database") {
 
			found_database = true;
 
		}
 
	}
 

	
 
	if (!found_working) {
 
		std::vector<std::string> value;
 
		value.push_back("/var/lib/spectrum2/$jid");
 
		parsed.options.push_back(boost::program_options::basic_option<char>("service.working_dir", value));
 
	}
 
	if (!found_pidfile) {
 
		std::vector<std::string> value;
0 comments (0 inline, 0 general)