Commit 1d2cb7b1 authored by johan's avatar johan

Merge branch 'master' into pr1813

parents 8cb89254 7f6ab2d8
......@@ -144,10 +144,6 @@ if(ENABLE_STATIC)
list(APPEND BCTOOLBOX_CPPFLAGS "-DBCTBX_STATIC")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/config.h PROPERTIES GENERATED ON)
add_definitions("-DHAVE_CONFIG_H")
bc_init_compilation_flags(STRICT_OPTIONS_CPP STRICT_OPTIONS_C STRICT_OPTIONS_CXX ENABLE_STRICT)
if(CMAKE_VERSION VERSION_LESS 3.1 AND NOT APPLE AND NOT MSVC)
list(APPEND STRICT_OPTIONS_CXX "-std=c++11")
......@@ -163,6 +159,10 @@ check_library_exists("rt" "clock_gettime" "" HAVE_LIBRT)
check_library_exists("dl" "dladdr" "" HAVE_LIBDL)
check_include_file("execinfo.h" HAVE_EXECINFO)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/config.h PROPERTIES GENERATED ON)
add_definitions("-DHAVE_CONFIG_H")
add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_TESTS AND ENABLE_TESTS_COMPONENT)
......
......@@ -6,7 +6,7 @@
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>bctoolbox</string>
<string>${MACOSX_FRAMEWORK_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>${MACOSX_BUNDLE_INFO_STRING}</string>
<key>CFBundleIconFile</key>
......
......@@ -57,12 +57,16 @@ Libraries and headers required to develop software with bctoolbox
%setup -n %{name}-%{version}%{?build_number_ext}
%build
%{expand:%%%cmake_name} . -DCMAKE_BUILD_TYPE=@CMAKE_BUILD_TYPE@ -DCMAKE_INSTALL_LIBDIR:PATH=%{_libdir} -DCMAKE_PREFIX_PATH:PATH=%{_prefix} @RPM_ALL_CMAKE_OPTIONS@
%{expand:%%%cmake_name} . -DCMAKE_BUILD_TYPE=@CMAKE_BUILD_TYPE@ -DCMAKE_PREFIX_PATH:PATH=%{_prefix} @RPM_ALL_CMAKE_OPTIONS@
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
# Dirty workaround to give exec rights for all shared libraries. Debian packaging needs this
# TODO : set CMAKE_INSTALL_SO_NO_EXE for a cleaner workaround
chmod +x `find %{buildroot} *.so.*`
%check
%{ctest_name} -V %{?_smp_mflags}
......@@ -105,5 +109,9 @@ rm -rf $RPM_BUILD_ROOT
%endif
%changelog
* Tue Nov 27 2018 ronan.abhamon <ronan.abhamon@belledonne-communications.com>
- Do not set CMAKE_INSTALL_LIBDIR and never with _libdir!
* Tue Jan 16 2018 Ghislain MARY <ghislain.mary@belledonne-communications.com>
- Initial RPM release.
......@@ -108,22 +108,24 @@ macro(bc_project_build_version PROJECT_VERSION PROJECT_BUILD_VERSION)
endmacro()
macro(bc_generate_rpm_specfile SOURCE DEST)
set(BC_PACKAGE_NAME_PREFIX "" CACHE STRING "Prefix for name of package.")
if(UNIX AND NOT APPLE AND NOT ANDROID)
set(BC_PACKAGE_NAME_PREFIX "" CACHE STRING "Prefix for name of package.")
get_cmake_property(_variableNames VARIABLES)
set(RPM_ALL_CMAKE_OPTIONS "")
foreach(_variableName ${_variableNames})
if(_variableName MATCHES "^ENABLE_")
if(${_variableName})
set(${_variableName} 1)
else()
set(${_variableName} 0)
get_cmake_property(_variableNames VARIABLES)
set(RPM_ALL_CMAKE_OPTIONS "")
foreach(_variableName ${_variableNames})
if(_variableName MATCHES "^ENABLE_")
if(${_variableName})
set(${_variableName} 1)
else()
set(${_variableName} 0)
endif()
set(RPM_ALL_CMAKE_OPTIONS "${RPM_ALL_CMAKE_OPTIONS} -D${_variableName}=${${_variableName}}")
endif()
set(RPM_ALL_CMAKE_OPTIONS "${RPM_ALL_CMAKE_OPTIONS} -D${_variableName}=${${_variableName}}")
endif()
endforeach()
configure_file(${SOURCE} ${DEST} @ONLY)
unset(RPM_ALL_CMAKE_OPTIONS)
unset(_variableNames)
endforeach()
configure_file(${SOURCE} ${DEST} @ONLY)
unset(RPM_ALL_CMAKE_OPTIONS)
unset(_variableNames)
endif()
endmacro()
......@@ -21,26 +21,31 @@
############################################################################
set(HEADER_FILES
crypto.h
charconv.h
compiler.h
defs.h
exception.hh
list.h
logging.h
map.h
port.h
vfs.h
vconnect.h
parser.h
port.h
regex.h
charconv.h
exception.hh
vconnect.h
vfs.h
)
if(MBEDTLS_FOUND OR POLARSSL_FOUND)
list(APPEND HEADER_FILES crypto.h)
endif()
if(ENABLE_TESTS_COMPONENT)
list(APPEND HEADER_FILES tester.h)
endif()
set(BCTOOLBOX_HEADER_FILES )
foreach(HEADER_FILE ${HEADER_FILES})
list(APPEND BCTOOLBOX_HEADER_FILES "${CMAKE_CURRENT_LIST_DIR}/bctoolbox/${HEADER_FILE}")
list(APPEND BCTOOLBOX_HEADER_FILES "${CMAKE_CURRENT_LIST_DIR}/bctoolbox/${HEADER_FILE}")
endforeach()
set(BCTOOLBOX_HEADER_FILES ${BCTOOLBOX_HEADER_FILES} PARENT_SCOPE)
......
/*
bctoolbox
Copyright (C) 2016 Belledonne Communications SARL.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
* charconv.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* 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 02110-1301, USA.
*/
#ifndef BCTBX_CHARCONV_H
......@@ -25,10 +26,24 @@
extern "C" {
#endif
/**
* @brief Set the default encoding for the application.
*
* @param[in] encoding default encoding, "locale" to set it to the system's locale
*/
BCTBX_PUBLIC void bctbx_set_default_encoding (const char *encoding);
/**
* @brief Return the default encoding for the application.
*
* @return a pointer to a null-terminated string containing the default encoding.
*/
BCTBX_PUBLIC const char *bctbx_get_default_encoding ();
/**
* @brief Convert the given string from system locale to UTF8.
*
* @param[in] str string to convert
* @param[in] str string to convert
*
* @return a pointer to a null-terminated string containing the converted string. This buffer must then be freed
* by caller. NULL on failure.
......@@ -38,7 +53,7 @@ BCTBX_PUBLIC char *bctbx_locale_to_utf8 (const char *str);
/**
* @brief Convert the given string from UTF8 to system locale.
*
* @param[in] str string to convert
* @param[in] str string to convert
*
* @return a pointer to a null-terminated string containing the converted string. This buffer must then be freed
* by caller. NULL on failure.
......@@ -48,8 +63,8 @@ BCTBX_PUBLIC char *bctbx_utf8_to_locale (const char *str);
/**
* @brief Convert the given string.
*
* @param[in] str string to convert
* @param[in] encoding charset of the string
* @param[in] str string to convert
* @param[in] encoding charset of the string
*
* @return a pointer to a null-terminated string containing the converted string. This buffer must then be freed
* by caller. NULL on failure.
......
/*
* compiler.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* 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 02110-1301, USA.
*/
#ifndef COMPILER_H
#define COMPILER_H
#ifdef __has_feature
#if __has_feature(address_sanitizer)
#define BCTBX_ASAN_ENABLED
#endif // if __has_feature(address_sanitizer)
#elif defined(__SANITIZE_ADDRESS__)
#define BCTBX_ASAN_ENABLED
#endif // ifdef __has_feature
#ifdef BCTBX_ASAN_ENABLED
#define BCTBX_DISABLE_ASAN __attribute__((no_sanitize_address))
#else
#define BCTBX_DISABLE_ASAN
#endif // ifdef BCTBX_ASAN_ENABLED
#ifdef __has_attribute
#if __has_attribute(no_sanitize)
#define BCTBX_DISABLE_UBSAN __attribute__((no_sanitize("undefined")))
#else
#define BCTBX_DISABLE_UBSAN
#endif // __has_attribute(no_sanitize)
#elif defined(__GNUC__) && !defined(__MINGW32__) && GCC_VERSION >= 40900
#define BCTBX_DISABLE_UBSAN __attribute__((no_sanitize_undefined))
#else
#define BCTBX_DISABLE_UBSAN
#endif // ifdef __has_attribute
#endif // ifdef COMPILER_H
......@@ -772,7 +772,7 @@ BCTBX_PUBLIC void bctbx_DestroyEDDSAContext(bctbx_EDDSAContext_t *context);
* @param[in/out] signatureLength The size of the signature buffer as input, the size of the actual signature as output
*
*/
BCTBX_PUBLIC void bctbx_EDDSA_sign(bctbx_EDDSAContext_t *context, const uint8_t *message, const size_t messageLength, const uint8_t *AssociatedData, const size_t associatedDataLength, uint8_t *signature, size_t *signatureLength);
BCTBX_PUBLIC void bctbx_EDDSA_sign(bctbx_EDDSAContext_t *context, const uint8_t *message, const size_t messageLength, const uint8_t *AssociatedData, const uint8_t associatedDataLength, uint8_t *signature, size_t *signatureLength);
/**
*
......@@ -808,7 +808,7 @@ BCTBX_PUBLIC void bctbx_EDDSA_setSecretKey(bctbx_EDDSAContext_t *context, const
*
* @return BCTBX_VERIFY_SUCCESS or BCTBX_VERIFY_FAILED
*/
BCTBX_PUBLIC int bctbx_EDDSA_verify(bctbx_EDDSAContext_t *context, const uint8_t *message, size_t messageLength, const uint8_t *associatedData, const size_t associatedDataLength, const uint8_t *signature, size_t signatureLength);
BCTBX_PUBLIC int bctbx_EDDSA_verify(bctbx_EDDSAContext_t *context, const uint8_t *message, size_t messageLength, const uint8_t *associatedData, const uint8_t associatedDataLength, const uint8_t *signature, size_t signatureLength);
/**
......
/*
bctoolbox
Copyright (C) 2016 Belledonne Communications SARL.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -22,6 +22,13 @@
#include <exception>
#include <sstream>
#include "bctoolbox/port.h"
#ifdef _WIN32
#pragma warning (push)
#pragma warning (disable : 4275 4251)
#endif
/**
* @brief General pupose exception saving backtrace.
*
......@@ -34,7 +41,7 @@
*
*
*/
class BctbxException : public std::exception {
class BCTBX_PUBLIC BctbxException : public std::exception {
public:
BctbxException(const std::string &message = "");
BctbxException(const BctbxException &other);
......@@ -49,9 +56,7 @@ public:
const char *what() const noexcept override;
std::string str() const {
return mOs.str();
}
const std::string& str() const;
/* same as osstringstream, but as osstream does not have cp contructor, BctbxException can't inherit from
* osstream*/
......@@ -64,9 +69,15 @@ private:
void *mArray[20];
size_t mSize;
std::ostringstream mOs;
mutable std::string mMessage;
};
std::ostream &operator<<(std::ostream &__os, const BctbxException &e);
BCTBX_PUBLIC std::ostream &operator<<(std::ostream &__os, const BctbxException &e);
#define BCTBX_EXCEPTION BctbxException() << " " << __FILE__ << ":" << __LINE__ << " "
#ifdef _WIN32
#pragma warning (pop)
#endif
#endif /* exception_h */
......@@ -369,7 +369,8 @@ BCTBX_PUBLIC char *bctbx_strdup_printf(const char *fmt,...);
BCTBX_PUBLIC char *bctbx_strdup_vprintf(const char *fmt, va_list ap);
BCTBX_PUBLIC char *bctbx_strcat_printf(char *dst, const char *fmt,...);
BCTBX_PUBLIC char *bctbx_strcat_vprintf(char *dst, const char *fmt, va_list ap);
BCTBX_PUBLIC char *bctbx_concat (const char *str, ...) ;
BCTBX_PUBLIC char *bctbx_concat(const char *str, ...);
BCTBX_PUBLIC char *bctbx_replace(char *str, char c, char n);
/**
* Portable version of the dirname function from libgen.h
......
......@@ -73,6 +73,9 @@ BCTBX_PUBLIC void bc_tester_init(void (*ftester_printf)(int level, const char *f
BCTBX_PUBLIC void bc_tester_helper(const char *name, const char* additionnal_helper);
BCTBX_PUBLIC int bc_tester_parse_args(int argc, char** argv, int argid);
BCTBX_PUBLIC int bc_tester_start(const char* prog_name);
BCTBX_PUBLIC int bc_tester_register_suites(void);
BCTBX_PUBLIC int bc_tester_register_suite_by_name(const char *suite_name);
BCTBX_PUBLIC void bc_tester_add_suite(test_suite_t *suite);
BCTBX_PUBLIC void bc_tester_uninit(void);
BCTBX_PUBLIC void bc_tester_printf(int level, const char *fmt, ...);
......@@ -81,6 +84,10 @@ BCTBX_PUBLIC void bc_tester_set_resource_dir_prefix(const char *name);
BCTBX_PUBLIC const char * bc_tester_get_writable_dir_prefix(void);
BCTBX_PUBLIC void bc_tester_set_writable_dir_prefix(const char *name);
BCTBX_PUBLIC void bc_tester_set_silent_func(int (*func)(const char*));
BCTBX_PUBLIC void bc_tester_set_verbose_func(int (*func)(const char*));
BCTBX_PUBLIC void bc_tester_set_logfile_func(int (*func)(const char*));
BCTBX_PUBLIC int bc_tester_nb_suites(void);
BCTBX_PUBLIC int bc_tester_nb_tests(const char* name);
BCTBX_PUBLIC void bc_tester_list_suites(void);
......@@ -94,12 +101,15 @@ BCTBX_PUBLIC const char * bc_tester_current_suite_name(void);
BCTBX_PUBLIC const char * bc_tester_current_test_name(void);
BCTBX_PUBLIC const char ** bc_tester_current_test_tags(void);
BCTBX_PUBLIC char* bc_sprintfva(const char* format, va_list args);
BCTBX_PUBLIC char* bc_sprintf(const char* format, ...);
BCTBX_PUBLIC void bc_free(void *ptr);
BCTBX_PUBLIC char * bc_tester_get_failed_asserts(void);
BCTBX_PUBLIC unsigned int bc_get_number_of_failures(void);
BCTBX_PUBLIC void bc_set_trace_handler(void(*handler)(int, const char*, va_list));
/**
* Get full path to the given resource
*
......
......@@ -23,17 +23,17 @@
set(BCTOOLBOX_C_SOURCE_FILES
containers/list.c
logging/logging.c
parser.c
utils/port.c
vfs.c
vconnect.c
parser.c
vfs.c
)
set(BCTOOLBOX_CXX_SOURCE_FILES
containers/map.cc
crypto/ecc.cc
utils/regex.cc
conversion/charconv_encoding.cc
utils/exception.cc
utils/regex.cc
)
if(ANDROID)
......@@ -49,6 +49,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()
if(MBEDTLS_FOUND OR POLARSSL_FOUND)
list(APPEND BCTOOLBOX_C_SOURCE_FILES crypto/crypto.c)
list(APPEND BCTOOLBOX_CXX_SOURCE_FILES crypto/ecc.cc)
endif()
if(MBEDTLS_FOUND)
list(APPEND BCTOOLBOX_C_SOURCE_FILES crypto/mbedtls.c)
......@@ -75,6 +76,7 @@ if(ENABLE_STATIC)
add_library(bctoolbox-static STATIC ${BCTOOLBOX_SOURCE_FILES} ${BCTOOLBOX_HEADER_FILES})
target_link_libraries(bctoolbox-static INTERFACE ${CMAKE_THREAD_LIBS_INIT})
if(APPLE)
target_link_libraries(bctoolbox-static INTERFACE "-framework Foundation" "-framework AVFoundation")
target_include_directories(bctoolbox-static PRIVATE ${ICONV_INCLUDE_DIRS})
target_link_libraries(bctoolbox-static INTERFACE ${ICONV_LIBRARIES})
endif()
......@@ -108,15 +110,15 @@ if(ENABLE_SHARED)
else()
set(MIN_OS ${CMAKE_OSX_DEPLOYMENT_TARGET})
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/osx/")
set_target_properties(bctoolbox PROPERTIES
FRAMEWORK TRUE
MACOSX_FRAMEWORK_IDENTIFIER org.linphone.bctoolbox
MACOSX_FRAMEWORK_INFO_PLIST Info.plist.in
MACOSX_FRAMEWORK_INFO_PLIST "${CMAKE_SOURCE_DIR}/build/osx/Info.plist.in"
PUBLIC_HEADER "${BCTOOLBOX_HEADER_FILES}"
)
endif()
if(APPLE)
target_link_libraries(bctoolbox PRIVATE "-framework Foundation" "-framework AVFoundation")
target_include_directories(bctoolbox PRIVATE ${ICONV_INCLUDE_DIRS})
target_link_libraries(bctoolbox PRIVATE ${ICONV_LIBRARIES})
endif()
......@@ -216,6 +218,7 @@ if(ENABLE_TESTS_COMPONENT)
set_target_properties(bctoolbox-tester PROPERTIES
FRAMEWORK TRUE
MACOSX_FRAMEWORK_IDENTIFIER com.belledonne-communications.bctoolbox-tester
MACOSX_FRAMEWORK_INFO_PLIST "${CMAKE_SOURCE_DIR}/build/osx/Info.plist.in"
PUBLIC_HEADER "${BCTOOLBOX_HEADER_FILES}"
)
endif()
......
/*
bctoolbox
Copyright (C) 2016 Belledonne Communications SARL
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, see <http://www.gnu.org/licenses/>.
*/
* charconv.cc
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* 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 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
......@@ -26,9 +27,9 @@
#include <locale.h>
#include <string.h>
#include "bctoolbox/charconv.h"
#include "bctoolbox/logging.h"
#include "bctoolbox/port.h"
#include "bctoolbox/charconv.h"
static char *convert_from_to (const char *str, const char *from, const char *to) {
if (!from || !to)
......@@ -43,15 +44,10 @@ static char *convert_from_to (const char *str, const char *from, const char *to)
size_t out_left = in_left + in_left/10; // leave a marge of 10%
iconv_t cd;
#ifdef __APPLE__
const char* r_from = strcasecmp("locale", from) == 0 ? "" : from;
const char* r_to = strcasecmp("locale", to) == 0 ? "" : to;
#else
setlocale(LC_CTYPE, "");
const char* r_from = strcasecmp("locale", from) == 0 ? nl_langinfo(CODESET) : from;
const char* r_to = strcasecmp("locale", to) == 0 ? nl_langinfo(CODESET) : to;
#endif
if (strcasecmp(r_from, r_to) == 0) {
return bctbx_strdup(str);
......@@ -80,22 +76,34 @@ static char *convert_from_to (const char *str, const char *from, const char *to)
if (ret == (size_t)-1 && errno != E2BIG) {
bctbx_error("Error while converting a string from '%s' to '%s': %s", from, to, strerror(errno));
bctbx_free(ptr);
return NULL;
return bctbx_strdup(str);
}
} else {
bctbx_error("Unable to open iconv content descriptor from '%s' to '%s': %s", from, to, strerror(errno));
return NULL;
return bctbx_strdup(str);
}
return ptr;
}
char *bctbx_locale_to_utf8 (const char *str) {
return convert_from_to(str, "locale", "UTF-8");
const char *default_encoding = bctbx_get_default_encoding();
if (!strcmp(default_encoding, "UTF-8"))
return bctbx_strdup(str);
return convert_from_to(str, default_encoding, "UTF-8");
}
char *bctbx_utf8_to_locale (const char *str) {
return convert_from_to(str, "UTF-8", "locale");
const char *default_encoding = bctbx_get_default_encoding();
if (!strcmp(default_encoding, "UTF-8"))
return bctbx_strdup(str);
return convert_from_to(str, "UTF-8", default_encoding);
}
char *bctbx_convert_any_to_utf8 (const char *str, const char *encoding) {
......
/*
bctoolbox
Copyright (C) 2016 Belledonne Communications SARL
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, see <http://www.gnu.org/licenses/>.
*/
* charconv_android.cc
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* 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 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "bctoolbox/charconv.h"
#include "bctoolbox/logging.h"
#include "bctoolbox/port.h"
#include "bctoolbox/charconv.h"
char *bctbx_locale_to_utf8 (const char *str) {
// TODO remove this part when the NDK will contain a usable iconv
......
/*
* charconv_encoding.cc
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* 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 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef __APPLE__
#include "TargetConditionals.h"
#endif
#include "bctoolbox/charconv.h"
#include "bctoolbox/logging.h"
#include "bctoolbox/port.h"
namespace {
std::string defaultEncoding = "";
}
void bctbx_set_default_encoding (const char *encoding) {
defaultEncoding = encoding;
}
const char *bctbx_get_default_encoding () {
if (!defaultEncoding.empty())
return defaultEncoding.c_str();
#if defined(__ANDROID__) || TARGET_OS_IPHONE
return "UTF-8";
#else
return "locale";
#endif
}
/*
bctoolbox
Copyright (C) 2016 Belledonne Communications SARL
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, see <http://www.gnu.org/licenses/>.
*/
* charconv_windows.cc
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* 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 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
......@@ -23,9 +24,9 @@
#include <algorithm>
#include <unordered_map>
#include "bctoolbox/charconv.h"
#include "bctoolbox/logging.h"
#include "bctoolbox/port.h"
#include "bctoolbox/charconv.h"
static std::unordered_map <std::string, UINT> windowsCharset {
{ "LOCALE", CP_ACP },
......@@ -158,11 +159,21 @@ static char *convertFromTo (const char *str, const char *from, const char *to) {
}
char *bctbx_locale_to_utf8 (const char *str) {
return convertFromTo(str, "locale", "UTF-8");
const char *defaultEncoding = bctbx_get_default_encoding();
if (!strcmp(defaultEncoding, "UTF-8"))
return bctbx_strdup(str);
return convertFromTo(str, defaultEncoding, "UTF-8");
}
char *bctbx_utf8_to_locale (const char *str) {
return convertFromTo(str, "UTF-8", "locale");
const char *defaultEncoding = bctbx_get_default_encoding();
if (!strcmp(defaultEncoding, "UTF-8"))
return bctbx_strdup(str);
return convertFromTo(str, "UTF-8", defaultEncoding);
}
char *bctbx_convert_any_to_utf8 (const char *str, const char *encoding) {
......
......@@ -343,7 +343,7 @@ void bctbx_DestroyEDDSAContext(bctbx_EDDSAContext_t *context) {
* @param[in/out] signatureLength The size of the signature buffer as input, the size of the actual signature as output
*
*/
void bctbx_EDDSA_sign(bctbx_EDDSAContext_t *context, const uint8_t *message, const size_t messageLength, const uint8_t *associatedData, const size_t associatedDataLength, uint8_t *signature, size_t *signatureLength) {
void bctbx_EDDSA_sign(bctbx_EDDSAContext_t *context, const uint8_t *message, const size_t messageLength, const uint8_t *associatedData, const uint8_t associatedDataLength, uint8_t *signature, size_t *signatureLength) {
if (context!=NULL) {