diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index 4e12dca5..ca06b68b 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -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", "./"); diff --git a/backends/libpurple/purple_defs.cpp b/backends/libpurple/purple_defs.cpp index 4546ff07..bca0c2ff 100644 --- a/backends/libpurple/purple_defs.cpp +++ b/backends/libpurple/purple_defs.cpp @@ -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"); diff --git a/backends/libpurple/purple_defs.h b/backends/libpurple/purple_defs.h index ba1745a3..4d740d8c 100644 --- a/backends/libpurple/purple_defs.h +++ b/backends/libpurple/purple_defs.h @@ -1,4 +1,6 @@ #pragma once +#include + #if PURPLE_RUNTIME #include @@ -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); diff --git a/backends/libpurple/utils.cpp b/backends/libpurple/utils.cpp index 4cb02509..7b935e35 100644 --- a/backends/libpurple/utils.cpp +++ b/backends/libpurple/utils.cpp @@ -28,6 +28,7 @@ #include "purple.h" #include #include +#include #include "errno.h" @@ -54,6 +55,10 @@ #include "purple_defs.h" +#include + +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(str.size()), NULL, 0); + if (!numRequiredBytes) + return L""; + + // Allocate memory for the UTF-16 string + std::vector utf16Str(numRequiredBytes); + + int numConverted = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), boost::numeric_cast(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 diff --git a/backends/libpurple/utils.h b/backends/libpurple/utils.h index 956b86f6..8324f46a 100644 --- a/backends/libpurple/utils.h +++ b/backends/libpurple/utils.h @@ -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 diff --git a/cmake_modules/purpleConfig.cmake b/cmake_modules/purpleConfig.cmake index 72ff99fd..96f58a19 100644 --- a/cmake_modules/purpleConfig.cmake +++ b/cmake_modules/purpleConfig.cmake @@ -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() diff --git a/src/config.cpp b/src/config.cpp index 234ed5cf..23c3656d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -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 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); }