Merge branch 'master' of github.com:hanzz/libtransport

This commit is contained in:
Jan Kaluza 2012-09-06 08:43:25 +02:00
commit 80816f9517
7 changed files with 71 additions and 7 deletions

View file

@ -1528,7 +1528,9 @@ static void gotAttention(PurpleAccount *account, const char *who, PurpleConversa
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;
}
@ -1538,7 +1540,7 @@ static bool initPurple() {
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", "./");

View file

@ -1,6 +1,11 @@
#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;
@ -138,9 +143,19 @@ purple_account_option_get_type_wrapped_fnc purple_account_option_get_type_wrappe
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");

View file

@ -1,4 +1,6 @@
#pragma once
#include <string>
#if PURPLE_RUNTIME
#include <Windows.h>
@ -570,5 +572,5 @@ extern wpurple_g_io_channel_win32_new_socket_wrapped_fnc wpurple_g_io_channel_wi
#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);

View file

@ -28,6 +28,7 @@
#include "purple.h"
#include <algorithm>
#include <iostream>
#include <vector>
#include "errno.h"
@ -54,6 +55,10 @@
#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) {
@ -156,3 +161,34 @@ int create_socket(const char *host, int portno) {
// 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

View file

@ -31,3 +31,7 @@ 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

View file

@ -2,9 +2,9 @@ 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()

View file

@ -138,6 +138,11 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
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);
}