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
 
@@ -1525,23 +1525,25 @@ static void gotAttention(PurpleAccount *account, const char *who, PurpleConversa
 
	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());
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;
 
@@ -135,15 +140,25 @@ 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;
 

	
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)
 
@@ -567,8 +569,8 @@ extern wpurple_g_io_channel_win32_new_socket_wrapped_fnc wpurple_g_io_channel_wi
 
#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
 
@@ -25,12 +25,13 @@
 
#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"
 
@@ -51,12 +52,16 @@
 
#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;
 
@@ -153,6 +158,37 @@ int create_socket(const char *host, int portno) {
 

	
 
// 	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
 
@@ -28,6 +28,10 @@ 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}")
src/config.cpp
Show inline comments
 
@@ -135,12 +135,17 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
	;
 

	
 
	// 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;
0 comments (0 inline, 0 general)