├── .gitignore
├── bctoolbox.pc.in
├── bctoolbox-tester.pc.in
├── src
├── utils.h
├── utils
│ ├── ios_utils_app.hh
│ ├── ios_utils_stub.hh
│ ├── regex.cc
│ ├── ios_utils_app.mm
│ ├── exception.cc
│ ├── ios_utils.mm
│ └── utils.cc
├── conversion
│ ├── charconv_android.cc
│ ├── charconv_encoding.cc
│ ├── charconv.cc
│ └── charconv_windows.cc
├── param_string.c
├── vfs
│ ├── vfs_encryption_module.hh
│ ├── vfs_encryption_module_dummy.hh
│ ├── vfs_encryption_module_aes256gcm_sha256.hh
│ ├── vfs_standard.c
│ └── vfs_encryption_module_aes256gcm_sha256.cc
├── parser.c
├── logging
│ └── log-tags.cc
├── crypto
│ └── crypto.c
└── vconnect.c
├── cmake
├── gitversion.h.in
├── MakeArchive.cmake
├── ConfigureSpecfile.cmake
├── BCGitVersion.cmake
├── FindDecaf.cmake
├── BCToolboxConfig.cmake.in
├── FindBCUnit.cmake
└── FindMbedTLS.cmake
├── .clang-format
├── include
├── bctoolbox
│ ├── vfs_standard.h
│ ├── defs.h
│ ├── regex.h
│ ├── compiler.h
│ ├── ios_utils.hh
│ ├── param_string.h
│ ├── exception.hh
│ ├── utils.hh
│ ├── parser.h
│ ├── ownership.hh
│ ├── list.h
│ ├── charconv.h
│ ├── map.h
│ ├── vconnect.h
│ └── vfs_encrypted.hh
└── CMakeLists.txt
├── config.h.cmake
├── tester
├── ios_utils.cc
├── bctoolbox_tester.h
├── parser.c
├── CMakeLists.txt
├── param_string.c
├── bctoolbox_tester.c
├── logger.cc
└── containers.cc
├── CHANGELOG.md
├── README.md
├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.yml
└── CMakeLists.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | bctoolbox.spec
2 | .*.swp
3 |
--------------------------------------------------------------------------------
/bctoolbox.pc.in:
--------------------------------------------------------------------------------
1 | # This is a comment
2 | prefix=@CMAKE_INSTALL_PREFIX@
3 | exec_prefix=@CMAKE_INSTALL_PREFIX@
4 |
5 | Name: bctoolbox
6 | Description: A common set of tools used by Belledonne Communication's softwares
7 | Version: @PROJECT_VERSION@
8 | Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lbctoolbox
9 | Libs.private: @LIBS_PRIVATE@
10 | Cflags: -I@CMAKE_INSTALL_FULL_INCLUDEDIR@
11 |
--------------------------------------------------------------------------------
/bctoolbox-tester.pc.in:
--------------------------------------------------------------------------------
1 | # This is a comment
2 | prefix=@CMAKE_INSTALL_PREFIX@
3 | exec_prefix=@CMAKE_INSTALL_PREFIX@
4 | Name: bctoolbox-tester
5 | Description: A common set of tester wrappers used by Belledonne Communications's softwares
6 | Requires.private: @TESTER_REQUIRES_PRIVATE@
7 | Version: @PROJECT_VERSION@
8 | Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lbctoolbox-tester
9 | Cflags: -I@CMAKE_INSTALL_FULL_INCLUDEDIR@
10 |
--------------------------------------------------------------------------------
/src/utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include "bctoolbox/port.h"
--------------------------------------------------------------------------------
/cmake/gitversion.h.in:
--------------------------------------------------------------------------------
1 | /*
2 | linphone
3 | Copyright (C) 2010-2017 Belledonne Communications SARL
4 |
5 | This program is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU General Public License
7 | as published by the Free Software Foundation; either version 2
8 | of the License, or (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 |
21 | #define @PREFIX_GIT_VERSION@_GIT_VERSION "@PROJECT_GIT_VERSION@"
--------------------------------------------------------------------------------
/.clang-format:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2010-2023 Belledonne Communications SARL.
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 |
16 | ---
17 | Language: Cpp
18 | BasedOnStyle: LLVM
19 | AccessModifierOffset: -4
20 | AllowShortFunctionsOnASingleLine: None
21 | AllowShortIfStatementsOnASingleLine: AllIfsAndElse
22 | AlwaysBreakTemplateDeclarations: Yes
23 | BinPackParameters: false
24 | ColumnLimit: 120
25 | PointerAlignment: Right
26 | IndentCaseLabels: true
27 | IndentWidth: 4
28 | Standard: c++14
29 | TabWidth: 4
30 | UseTab: ForIndentation
31 | ...
32 |
--------------------------------------------------------------------------------
/include/bctoolbox/vfs_standard.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef BCTBX_VFS_STANDARD_H
21 | #define BCTBX_VFS_STANDARD_H
22 |
23 | #include "bctoolbox/port.h"
24 | #include "bctoolbox/vfs.h"
25 |
26 | #ifdef __cplusplus
27 | extern "C" {
28 | #endif
29 |
30 | /**
31 | * Virtual File sytem provided
32 | */
33 | extern BCTBX_PUBLIC bctbx_vfs_t bcStandardVfs;
34 |
35 | #ifdef __cplusplus
36 | }
37 | #endif
38 |
39 | #endif /* BCTBX_VFS_STANDARD_H */
40 |
--------------------------------------------------------------------------------
/src/utils/ios_utils_app.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Belledonne Communications SARL.
3 | *
4 | * This file is part of Liblinphone.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include "bctoolbox/ios_utils.hh"
23 |
24 | namespace bctoolbox {
25 |
26 | class IOSUtilsApp : public IOSUtilsInterface {
27 | public:
28 | unsigned long beginBackgroundTask(const char *name, std::function cb) override;
29 | void endBackgroundTask(unsigned long id) override;
30 | bool isApplicationStateActive() override;
31 | };
32 |
33 | } // namespace bctoolbox
34 |
--------------------------------------------------------------------------------
/src/utils/ios_utils_stub.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Belledonne Communications SARL.
3 | *
4 | * This file is part of Liblinphone.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include "bctoolbox/ios_utils.hh"
23 |
24 | namespace bctoolbox {
25 |
26 | class IOSUtilsStub : public IOSUtilsInterface {
27 | public:
28 | unsigned long beginBackgroundTask(const char *name, std::function cb) override;
29 | void endBackgroundTask(unsigned long id) override;
30 | bool isApplicationStateActive() override;
31 | };
32 |
33 | } // namespace bctoolbox
34 |
--------------------------------------------------------------------------------
/config.h.cmake:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * config.h.cmake
3 | * Copyright (C) 2010-2022 Belledonne Communications, Grenoble France
4 | *
5 | ****************************************************************************
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * as published by the Free Software Foundation; either version 2
10 | * of the License, or (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 | *
21 | ****************************************************************************/
22 |
23 | #cmakedefine HAVE_DTLS_SRTP 1
24 | #cmakedefine HAVE_DECAF 1
25 | #cmakedefine HAVE_MBEDTLS 1
26 | #cmakedefine HAVE_OPENSSL 1
27 | #cmakedefine HAVE_CTR_DRGB_FREE 1
28 | #cmakedefine HAVE_CU_GET_SUITE 1
29 | #cmakedefine HAVE_CU_CURSES 1
30 | #cmakedefine HAVE_CU_SET_TRACE_HANDLER 1
31 | #cmakedefine ENABLE_DEFAULT_LOG_HANDLER 1
32 |
33 | #cmakedefine HAVE_LIBRT 1
34 |
35 | #cmakedefine HAVE_EXECINFO
36 |
--------------------------------------------------------------------------------
/tester/ios_utils.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include "bctoolbox/ios_utils.hh"
21 | #include "bctoolbox_tester.h"
22 | #include
23 |
24 | using namespace bctoolbox;
25 |
26 | static void ios_utils_return_values(void) {
27 | auto &iOSUtils = IOSUtils::getUtils();
28 | BC_ASSERT_EQUAL(iOSUtils.beginBackgroundTask(nullptr, nullptr), 0, unsigned long, "%lu");
29 | BC_ASSERT_EQUAL(iOSUtils.isApplicationStateActive(), false, bool, "%d");
30 | }
31 |
32 | static test_t ios_utils_tests[] = {
33 | TEST_NO_TAG("Return values for stubbed functions", ios_utils_return_values),
34 | };
35 |
36 | test_suite_t ios_utils_test_suite = {
37 | "iOS Utilities", NULL, NULL, NULL, NULL, sizeof(ios_utils_tests) / sizeof(ios_utils_tests[0]), ios_utils_tests, 0};
38 |
--------------------------------------------------------------------------------
/include/bctoolbox/defs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef BCTBX_DEFS_H_
21 | #define BCTBX_DEFS_H_
22 |
23 | /* Macro telling GCC that a 'break' statement has been deliberately omitted
24 | * in switch block */
25 | #ifndef BCTBX_NO_BREAK
26 | #if defined(__GNUC__) && __GNUC__ >= 7
27 | #define BCTBX_NO_BREAK __attribute__((fallthrough))
28 | #else
29 | #define BCTBX_NO_BREAK
30 | #endif // __GNUC__
31 | #endif // BCTBX_NO_BREAK
32 |
33 | #ifndef BCTBX_UNUSED
34 | #if (!defined(_WIN32) && (defined(__GNUC__) || defined(__clang__)))
35 | #define BCTBX_UNUSED(x) x __attribute__((__unused__))
36 | #else
37 | #define BCTBX_UNUSED(x) x
38 | #endif //(!defined(_MSC_VER) && (defined(__GNUC__) || defined(__clang__)))
39 | #endif // BCTBX_UNUSED
40 |
41 | #endif /* BCTBX_DEFS_H_ */
42 |
--------------------------------------------------------------------------------
/include/bctoolbox/regex.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef BCTBX_REGEX_H
21 | #define BCTBX_REGEX_H
22 |
23 | #include "bctoolbox/port.h"
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | BCTBX_PUBLIC bool_t bctbx_is_matching_regex(const char *entry, const char *regex);
30 | BCTBX_PUBLIC bool_t bctbx_is_matching_regex_log(const char *entry, const char *regex, bool_t show_log);
31 | BCTBX_PUBLIC bool_t bctbx_is_matching_regex_log_context(const char *entry,
32 | const char *regex,
33 | bool_t show_log,
34 | const char *context);
35 |
36 | #ifdef __cplusplus
37 | }
38 | #endif
39 |
40 | #endif /* BCTBX_REGEX_H */
41 |
--------------------------------------------------------------------------------
/cmake/MakeArchive.cmake:
--------------------------------------------------------------------------------
1 | ############################################################################
2 | # MakeArchive.cmake
3 | # Copyright (C) 2010-2019 Belledonne Communications, Grenoble France
4 | #
5 | ############################################################################
6 | #
7 | # This program is free software; you can redistribute it and/or
8 | # modify it under the terms of the GNU General Public License
9 | # as published by the Free Software Foundation; either version 2
10 | # of the License, or (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program; if not, write to the Free Software
19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 | #
21 | ############################################################################
22 |
23 | include("${BCToolbox_CMAKE_UTILS}")
24 | bc_compute_full_version(version)
25 | set(archive_name "${CPACK_PACKAGE_NAME}-${version}")
26 | set(archive_path "${PROJECT_BINARY_DIR}/${archive_name}.tar.gz")
27 |
28 | find_program(TAR tar)
29 |
30 | set(EXCLUDE_ARGS )
31 | foreach (pattern ${EXCLUDE_PATTERNS})
32 | list(APPEND EXCLUDE_ARGS "--exclude=${pattern}")
33 | endforeach()
34 |
35 | execute_process(COMMAND ${TAR} -C "${PROJECT_SOURCE_DIR}" -cz -f "${archive_path}" "--transform" "s,^\\.,${archive_name}," ${EXCLUDE_ARGS} .)
36 |
--------------------------------------------------------------------------------
/tester/bctoolbox_tester.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef _BCTOOLBOX_TESTER_H
21 | #define _BCTOOLBOX_TESTER_H
22 |
23 | #include "bctoolbox/logging.h"
24 | #include "bctoolbox/tester.h"
25 |
26 | #ifdef __cplusplus
27 |
28 | #define SLOGD BCTBX_SLOGD("bctoolbox-tester")
29 | #define SLOGI BCTBX_SLOGI("bctoolbox-tester")
30 | #define SLOGW BCTBX_SLOGW("bctoolbox-tester")
31 | #define SLOGE BCTBX_SLOGE("bctoolbox-tester")
32 |
33 | extern "C" {
34 | #endif
35 |
36 | extern test_suite_t containers_test_suite;
37 | extern test_suite_t utils_test_suite;
38 | extern test_suite_t crypto_test_suite;
39 | extern test_suite_t parser_test_suite;
40 | extern test_suite_t ios_utils_test_suite;
41 | extern test_suite_t encrypted_vfs_test_suite;
42 | extern test_suite_t param_string_test_suite;
43 | extern test_suite_t vfs_test_suite;
44 | extern test_suite_t logger_test_suite;
45 |
46 | #ifdef __cplusplus
47 | };
48 | #endif
49 |
50 | #endif /* _BCTOOLBOX_TESTER_H */
51 |
--------------------------------------------------------------------------------
/cmake/ConfigureSpecfile.cmake:
--------------------------------------------------------------------------------
1 | ############################################################################
2 | # ConfigureSpecfile.cmake
3 | # Copyright (C) 2010-2019 Belledonne Communications, Grenoble France
4 | #
5 | ############################################################################
6 | #
7 | # This program is free software; you can redistribute it and/or
8 | # modify it under the terms of the GNU General Public License
9 | # as published by the Free Software Foundation; either version 2
10 | # of the License, or (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program; if not, write to the Free Software
19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 | #
21 | ############################################################################
22 |
23 | include("${BCToolbox_CMAKE_UTILS}")
24 |
25 | set(FULL_VERSION )
26 | bc_compute_full_version(FULL_VERSION)
27 |
28 | set(version_major )
29 | set(version_minor )
30 | set(version_patch )
31 | set(identifiers )
32 | set(metadata )
33 |
34 | bc_parse_full_version("${FULL_VERSION}" version_major version_minor version_patch identifiers metadata)
35 |
36 | set(RPM_VERSION ${version_major}.${version_minor}.${version_patch})
37 | if (NOT identifiers)
38 | set(RPM_RELEASE 1)
39 | else()
40 | string(SUBSTRING "${identifiers}" 1 -1 identifiers)
41 | set(RPM_RELEASE "0.${identifiers}${metadata}")
42 | endif()
43 |
44 | configure_file("${SRC}" "${DEST}")
45 |
--------------------------------------------------------------------------------
/include/bctoolbox/compiler.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef COMPILER_H
21 | #define COMPILER_H
22 |
23 | #ifdef __has_feature
24 | #if __has_feature(address_sanitizer)
25 | #define BCTBX_ASAN_ENABLED
26 | #endif // if __has_feature(address_sanitizer)
27 | #elif defined(__SANITIZE_ADDRESS__)
28 | #define BCTBX_ASAN_ENABLED
29 | #endif // ifdef __has_feature
30 |
31 | #ifdef BCTBX_ASAN_ENABLED
32 | #define BCTBX_DISABLE_ASAN __attribute__((no_sanitize_address))
33 | #else
34 | #define BCTBX_DISABLE_ASAN
35 | #endif // ifdef BCTBX_ASAN_ENABLED
36 |
37 | #ifdef __has_attribute
38 | #if __has_attribute(no_sanitize)
39 | #define BCTBX_DISABLE_UBSAN __attribute__((no_sanitize("undefined")))
40 | #else
41 | #define BCTBX_DISABLE_UBSAN
42 | #endif // __has_attribute(no_sanitize)
43 | #elif defined(__GNUC__) && !defined(__MINGW32__) && GCC_VERSION >= 40900
44 | #define BCTBX_DISABLE_UBSAN __attribute__((no_sanitize_undefined))
45 | #else
46 | #define BCTBX_DISABLE_UBSAN
47 | #endif // ifdef __has_attribute
48 |
49 | #endif // ifdef COMPILER_H
50 |
--------------------------------------------------------------------------------
/tester/parser.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include "bctoolbox/parser.h"
21 | #include "bctoolbox_tester.h"
22 |
23 | static void simple_escaping(void) {
24 | char *my_escaped_string;
25 | bctbx_noescape_rules_t my_rules = {0};
26 | bctbx_noescape_rules_add_alfanums(my_rules);
27 | my_escaped_string = bctbx_escape("François", my_rules);
28 | BC_ASSERT_TRUE(strcmp("Fran%c3%a7ois", my_escaped_string) == 0);
29 | bctbx_free(my_escaped_string);
30 | }
31 |
32 | static void simple_unescaping(void) {
33 | char *my_unescaped_string;
34 | my_unescaped_string = bctbx_unescaped_string("Fran%c3%a7ois");
35 | BC_ASSERT_TRUE(strcmp("François", my_unescaped_string) == 0);
36 | bctbx_free(my_unescaped_string);
37 | }
38 |
39 | static test_t container_tests[] = {
40 | TEST_NO_TAG("simple escaping", simple_escaping),
41 | TEST_NO_TAG("simple unescaping", simple_unescaping),
42 | };
43 |
44 |
45 | test_suite_t parser_test_suite = {
46 | "Parsing", NULL, NULL, NULL, NULL, sizeof(container_tests) / sizeof(container_tests[0]), container_tests, 0};
47 |
--------------------------------------------------------------------------------
/include/bctoolbox/ios_utils.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Belledonne Communications SARL.
3 | *
4 | * This file is part of Liblinphone.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include
23 |
24 | namespace bctoolbox {
25 |
26 | class IOSUtilsInterface {
27 | public:
28 | virtual unsigned long beginBackgroundTask(const char *name, std::function cb) = 0;
29 | virtual void endBackgroundTask(unsigned long id) = 0;
30 | virtual bool isApplicationStateActive() = 0;
31 |
32 | virtual ~IOSUtilsInterface() = default;
33 | };
34 |
35 | class IOSUtils {
36 | public:
37 | unsigned long beginBackgroundTask(const char *name, std::function cb);
38 | void endBackgroundTask(unsigned long id);
39 | bool isApplicationStateActive();
40 | bool isApp();
41 | int getOSMajorVersion() const;
42 | static IOSUtils &getUtils();
43 |
44 | IOSUtils(const IOSUtils &) = delete;
45 | IOSUtils &operator=(const IOSUtils &) = delete;
46 | ~IOSUtils();
47 |
48 | private:
49 | void *mHandle;
50 | IOSUtilsInterface *mUtils;
51 | bool mIsApp;
52 | static std::unique_ptr sInstance;
53 | IOSUtils();
54 |
55 | void openDynamicLib();
56 | void *loadSymbol(const char *symbol);
57 | };
58 |
59 | } // namespace bctoolbox
60 |
--------------------------------------------------------------------------------
/include/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | ############################################################################
2 | # CMakeLists.txt
3 | # Copyright (C) 2016 Belledonne Communications, Grenoble France
4 | #
5 | ############################################################################
6 | #
7 | # This program is free software; you can redistribute it and/or
8 | # modify it under the terms of the GNU General Public License
9 | # as published by the Free Software Foundation; either version 2
10 | # of the License, or (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program; if not, write to the Free Software
19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 | #
21 | ############################################################################
22 |
23 | set(HEADER_FILES
24 | charconv.h
25 | compiler.h
26 | defs.h
27 | exception.hh
28 | utils.hh
29 | list.h
30 | logging.h
31 | map.h
32 | ownership.hh
33 | parser.h
34 | port.h
35 | regex.h
36 | vconnect.h
37 | vfs.h
38 | vfs_standard.h
39 | vfs_encrypted.hh
40 | param_string.h
41 | )
42 |
43 | if(APPLE)
44 | list(APPEND HEADER_FILES ios_utils.hh)
45 | endif()
46 |
47 | if(MbedTLS_FOUND OR OPENSSL_FOUND)
48 | list(APPEND HEADER_FILES crypto.h)
49 | list(APPEND HEADER_FILES crypto.hh)
50 | endif()
51 |
52 | if(ENABLE_TESTS_COMPONENT)
53 | list(APPEND HEADER_FILES tester.h)
54 | endif()
55 |
56 | set(BCTOOLBOX_HEADER_FILES )
57 | foreach(HEADER_FILE ${HEADER_FILES})
58 | list(APPEND BCTOOLBOX_HEADER_FILES "${CMAKE_CURRENT_LIST_DIR}/bctoolbox/${HEADER_FILE}")
59 | endforeach()
60 | set(BCTOOLBOX_HEADER_FILES ${BCTOOLBOX_HEADER_FILES} PARENT_SCOPE)
61 |
62 | install(FILES ${BCTOOLBOX_HEADER_FILES}
63 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/bctoolbox
64 | PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
65 | )
66 |
--------------------------------------------------------------------------------
/src/conversion/charconv_android.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifdef HAVE_CONFIG_H
21 | #include "config.h"
22 | #endif
23 |
24 | #include "bctoolbox/charconv.h"
25 | #include "bctoolbox/defs.h"
26 | #include "bctoolbox/logging.h"
27 | #include "bctoolbox/port.h"
28 |
29 | char *bctbx_locale_to_utf8(const char *str) {
30 | // TODO remove this part when the NDK will contain a usable iconv
31 | return bctbx_strdup(str);
32 | }
33 |
34 | char *bctbx_utf8_to_locale(const char *str) {
35 | // TODO remove this part when the NDK will contain a usable iconv
36 | return bctbx_strdup(str);
37 | }
38 |
39 | char *bctbx_convert_any_to_utf8(const char *str, BCTBX_UNUSED(const char *encoding)) {
40 | // TODO change this part when the NDK will contain a usable iconv
41 | return bctbx_strdup(str);
42 | }
43 |
44 | char *bctbx_convert_utf8_to_any(const char *str, BCTBX_UNUSED(const char *encoding)) {
45 | // TODO change this part when the NDK will contain a usable iconv
46 | return bctbx_strdup(str);
47 | }
48 |
49 | char *
50 | bctbx_convert_string(const char *str, BCTBX_UNUSED(const char *from_encoding), BCTBX_UNUSED(const char *to_encoding)) {
51 | // TODO change this part when the NDK will contain a usable iconv
52 | return bctbx_strdup(str);
53 | }
54 |
55 | unsigned int bctbx_get_code_page(BCTBX_UNUSED(const char *encoding)) {
56 | bctbx_error("Getting code page is not implemented");
57 | return 0;
58 | }
59 |
--------------------------------------------------------------------------------
/cmake/BCGitVersion.cmake:
--------------------------------------------------------------------------------
1 | ############################################################################
2 | # BCGitVersion.cmake
3 | # Copyright (C) 2017-2023 Belledonne Communications, Grenoble France
4 | #
5 | ############################################################################
6 | #
7 | # This program is free software; you can redistribute it and/or
8 | # modify it under the terms of the GNU General Public License
9 | # as published by the Free Software Foundation; either version 2
10 | # of the License, or (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program; if not, write to the Free Software
19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 | #
21 | ############################################################################
22 |
23 | if(GIT_EXECUTABLE)
24 | macro(GIT_COMMAND OUTPUT_VAR)
25 | set(GIT_ARGS ${ARGN})
26 | execute_process(
27 | COMMAND ${GIT_EXECUTABLE} ${ARGN}
28 | WORKING_DIRECTORY ${WORK_DIR}
29 | OUTPUT_VARIABLE ${OUTPUT_VAR}
30 | OUTPUT_STRIP_TRAILING_WHITESPACE
31 | )
32 | endmacro()
33 |
34 | GIT_COMMAND(GIT_DESCRIBE describe --always)
35 | GIT_COMMAND(GIT_TAG describe --abbrev=0)
36 | GIT_COMMAND(GIT_REVISION rev-parse HEAD)
37 | endif()
38 |
39 | string(TOUPPER "${PROJECT_NAME}" PREFIX_GIT_VERSION)
40 | string(REPLACE "-" "_" PREFIX_GIT_VERSION "${PREFIX_GIT_VERSION}")
41 | if(GIT_DESCRIBE)
42 | if(NOT GIT_TAG STREQUAL PROJECT_VERSION)
43 | message(WARNING "Project version (${PROJECT_VERSION}) and git tag (${GIT_TAG}) differ. Please put them identical")
44 | endif()
45 | set(PROJECT_GIT_VERSION "${GIT_DESCRIBE}")
46 | configure_file("${TEMPLATE_DIR}/gitversion.h.in" "${OUTPUT_DIR}/gitversion.h" @ONLY)
47 | elseif(GIT_REVISION)
48 | set(PROJECT_GIT_VERSION "${LINPHONE_VERSION}_${GIT_REVISION}")
49 | configure_file("${TEMPLATE_DIR}/gitversion.h.in" "${OUTPUT_DIR}/gitversion.h" @ONLY)
50 | else()
51 | if(NOT EXISTS "${OUTPUT_DIR}/gitversion.h")
52 | execute_process(COMMAND ${CMAKE_COMMAND} -E touch "${OUTPUT_DIR}/gitversion.h")
53 | endif()
54 | endif()
55 |
--------------------------------------------------------------------------------
/src/conversion/charconv_encoding.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifdef HAVE_CONFIG_H
21 | #include "config.h"
22 | #endif
23 |
24 | #ifdef __APPLE__
25 | #include "TargetConditionals.h"
26 | #endif
27 |
28 | #include "bctoolbox/charconv.h"
29 | #include "bctoolbox/logging.h"
30 | #include "bctoolbox/port.h"
31 |
32 | #include
33 | #include
34 |
35 | namespace {
36 | std::string &defaultEncodingPrivate() {
37 | static std::string defaultEncoding;
38 | return defaultEncoding;
39 | }
40 | } // namespace
41 |
42 | void bctbx_set_default_encoding(const char *encoding) {
43 | defaultEncodingPrivate() = encoding;
44 | }
45 |
46 | const char *bctbx_get_default_encoding(void) {
47 | if (!defaultEncodingPrivate().empty()) return defaultEncodingPrivate().c_str();
48 |
49 | #if defined(__ANDROID__) || TARGET_OS_IPHONE
50 | return "UTF-8";
51 | #else
52 | return "locale";
53 | #endif
54 | }
55 |
56 | wchar_t *bctbx_string_to_wide_string(const char *str) {
57 | wchar_t *wstr;
58 | size_t sz = mbstowcs(NULL, str, 0);
59 | if (sz == (size_t)-1) {
60 | return NULL;
61 | }
62 | sz += 1;
63 | wstr = (wchar_t *)bctbx_malloc(sz * sizeof(wchar_t));
64 | sz = mbstowcs(wstr, str, sz);
65 | if (sz == (size_t)-1) {
66 | bctbx_free(wstr);
67 | return NULL;
68 | }
69 | return wstr;
70 | }
71 |
72 | char *bctbx_wide_string_to_string(const wchar_t *wstr) {
73 | size_t sz;
74 | char *str;
75 | sz = wcstombs(NULL, wstr, 0);
76 | if (sz == (size_t)-1) {
77 | return NULL;
78 | }
79 | sz += 1;
80 | str = (char *)bctbx_malloc(sz);
81 | sz = wcstombs(str, wstr, sz);
82 | if (sz == (size_t)-1) {
83 | bctbx_free(str);
84 | return NULL;
85 | }
86 | return str;
87 | }
88 |
--------------------------------------------------------------------------------
/include/bctoolbox/param_string.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef BCTBX_PARAM_STRING_H_
21 | #define BCTBX_PARAM_STRING_H_
22 |
23 | #include "bctoolbox/port.h"
24 |
25 | // This file provides string manipulation utility when handling a parameter string of the from
26 | // "param1;param2=120;param3=true"
27 |
28 | /**
29 | * Parses a fmtp string such as "profile=0;level=10", finds the value matching
30 | * parameter param_name, and writes it into result.
31 | * If a parameter name is found multiple times, only the value of the last occurence is returned.
32 | * @param paramString the fmtp line (format parameters)
33 | * @param param_name the parameter to search for
34 | * @param result the value given for the parameter (if found)
35 | * @param result_len the size allocated to hold the result string
36 | * @return TRUE if the parameter was found, else FALSE.
37 | **/
38 | BCTBX_PUBLIC bool_t bctbx_param_string_get_value(const char *paramString,
39 | const char *param_name,
40 | char *result,
41 | size_t result_len);
42 |
43 | /**
44 | * Parses a fmtp string such as "profile=0;level=10". If the value is "true" or "false", returns the corresponding
45 | *boolean
46 | * @param paramString the fmtp line (format parameters)
47 | * @param param_name the parameter to search for
48 | * @return FALSE if parameter was not found, else TRUE if the parameter value was "true", FALSE if it was "false"
49 | **/
50 | BCTBX_PUBLIC bool_t bctbx_param_string_get_bool_value(const char *paramString, const char *param_name);
51 | #endif /*BCTBX_PARAM_STRING_H_*/
52 |
--------------------------------------------------------------------------------
/cmake/FindDecaf.cmake:
--------------------------------------------------------------------------------
1 | ############################################################################
2 | # FindDecaf.cmake
3 | # Copyright (C) 2017-2023 Belledonne Communications, Grenoble France
4 | #
5 | ############################################################################
6 | #
7 | # This program is free software; you can redistribute it and/or
8 | # modify it under the terms of the GNU General Public License
9 | # as published by the Free Software Foundation; either version 2
10 | # of the License, or (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program; if not, write to the Free Software
19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 | #
21 | ############################################################################
22 | #
23 | # Find the decaf library.
24 | #
25 | # Targets
26 | # ^^^^^^^
27 | #
28 | # The following targets may be defined:
29 | #
30 | # decaf - If the decaf library has been found
31 | #
32 | #
33 | # Result variables
34 | # ^^^^^^^^^^^^^^^^
35 | #
36 | # This module will set the following variables in your project:
37 | #
38 | # Decaf_FOUND - The decaf library has been found
39 | # Decaf_TARGET - The name of the CMake target for the decaf library
40 |
41 |
42 | if(TARGET decaf OR TARGET decaf-static)
43 |
44 | if(TARGET decaf-static)
45 | set(Decaf_TARGET decaf-static)
46 | elseif(TARGET decaf)
47 | set(Decaf_TARGET decaf)
48 | endif()
49 |
50 | include(FindPackageHandleStandardArgs)
51 | find_package_handle_standard_args(Decaf
52 | DEFAULT_MSG
53 | Decaf_TARGET
54 | )
55 | mark_as_advanced(Decaf_TARGET)
56 |
57 | else()
58 |
59 | set(_OPTIONS CONFIG)
60 | if(Decaf_FIND_REQUIRED)
61 | list(APPEND _OPTIONS REQUIRED)
62 | endif()
63 | if(Decaf_FIND_QUIETLY)
64 | list(APPEND _OPTIONS QUIET)
65 | endif()
66 | if(Decaf_FIND_VERSION)
67 | list(PREPEND _OPTIONS "${Decaf_FIND_VERSION}")
68 | endif()
69 | if(Decaf_FIND_EXACT)
70 | list(APPEND _OPTIONS EXACT)
71 | endif()
72 |
73 | find_package(Decaf ${_OPTIONS})
74 |
75 | if(TARGET decaf-static)
76 | set(Decaf_TARGET decaf-static)
77 | elseif(TARGET decaf)
78 | set(Decaf_TARGET decaf)
79 | endif()
80 |
81 | endif()
82 |
--------------------------------------------------------------------------------
/tester/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | ############################################################################
2 | # CMakeLists.txt
3 | # Copyright (C) 2020 Belledonne Communications, Grenoble France
4 | #
5 | ############################################################################
6 | #
7 | # This program is free software; you can redistribute it and/or
8 | # modify it under the terms of the GNU General Public License
9 | # as published by the Free Software Foundation; either version 2
10 | # of the License, or (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program; if not, write to the Free Software
19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 | #
21 | ############################################################################
22 |
23 | if(ENABLE_UNIT_TESTS AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND NOT ANDROID)
24 | set(TESTER_SOURCES
25 | bctoolbox_tester.c
26 | bctoolbox_tester.h
27 | containers.cc
28 | logger.cc
29 | port.c
30 | parser.c
31 | param_string.c
32 | vfs.c
33 | )
34 | if(MbedTLS_FOUND OR OPENSSL_FOUND)
35 | list(APPEND TESTER_SOURCES
36 | crypto.cc
37 | encrypted_vfs.cc)
38 | endif()
39 | if(APPLE)
40 | list(APPEND TESTER_SOURCES ios_utils.cc)
41 | endif()
42 |
43 | bc_apply_compile_flags(TESTER_SOURCE STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
44 | add_executable(bctoolbox-tester-exe ${TESTER_SOURCES})
45 | set_target_properties(bctoolbox-tester-exe PROPERTIES OUTPUT_NAME bctoolbox-tester)
46 | target_link_libraries(bctoolbox-tester-exe PRIVATE bctoolbox bctoolbox-tester)
47 | if(MbedTLS_FOUND)
48 | target_link_libraries(bctoolbox-tester-exe PRIVATE ${MbedTLS_TARGET})
49 | endif()
50 | set_target_properties(bctoolbox-tester-exe PROPERTIES XCODE_ATTRIBUTE_WARNING_CFLAGS "")
51 | add_test(NAME bctoolbox_tester COMMAND bctoolbox_tester --verbose)
52 | if(NOT IOS)
53 | install(TARGETS bctoolbox-tester-exe
54 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
55 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
56 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
57 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
58 | )
59 | endif()
60 | endif()
61 |
--------------------------------------------------------------------------------
/include/bctoolbox/exception.hh:
--------------------------------------------------------------------------------
1 | /*
2 | bctoolbox
3 | Copyright (C) 2016 Belledonne Communications SARL.
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Affero General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Affero General Public License for more details.
14 |
15 | You should have received a copy of the GNU Affero General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | #ifndef exception_h
20 | #define exception_h
21 |
22 | #include
23 | #include
24 |
25 | #include "bctoolbox/port.h"
26 |
27 | #ifdef _WIN32
28 | #pragma warning(push)
29 | #pragma warning(disable : 4275 4251)
30 | #endif
31 |
32 | /**
33 | * @brief General pupose exception saving backtrace.
34 | *
35 | * sample of use:
36 | * try {
37 | * throw BCTBX_EXCEPTION << "Hello, this is my exception";
38 | * } catch (BctbxException e&) {
39 | * BCTOOLBOX_SLOGD("mylogdomain") << "Exception cauth"<< e;
40 | * }
41 | *
42 | *
43 | */
44 | class BCTBX_PUBLIC BctbxException : public std::exception {
45 | public:
46 | BctbxException(const std::string &message = "");
47 | BctbxException(const BctbxException &other);
48 | virtual ~BctbxException() = default;
49 |
50 | /**
51 | * print stack strace to stderr
52 | * */
53 | void printStackTrace() const;
54 |
55 | void printStackTrace(std::ostream &os) const;
56 |
57 | const char *what() const noexcept override;
58 |
59 | const std::string &str() const;
60 |
61 | /* same as osstringstream, but as osstream does not have cp contructor, BctbxException can't inherit from
62 | * osstream*/
63 | template
64 | BctbxException &operator<<(const T2 &val) {
65 | mOs << val;
66 | return *this;
67 | }
68 |
69 | private:
70 | void *mArray[20];
71 | size_t mSize;
72 | std::ostringstream mOs;
73 | mutable std::string mMessage;
74 | };
75 |
76 | BCTBX_PUBLIC std::ostream &operator<<(std::ostream &__os, const BctbxException &e);
77 |
78 | #define BCTBX_EXCEPTION BctbxException() << " " << __FILE__ << ":" << __LINE__ << " "
79 |
80 | #ifdef _WIN32
81 | #pragma warning(pop)
82 | #endif
83 |
84 | #endif /* exception_h */
85 |
--------------------------------------------------------------------------------
/tester/param_string.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include "bctoolbox/param_string.h"
21 | #include "bctoolbox_tester.h"
22 |
23 | static void get_value_test(void) {
24 | size_t result_len = 10;
25 | char *result = bctbx_malloc(result_len);
26 |
27 | char *paramString = "";
28 | BC_ASSERT_FALSE(bctbx_param_string_get_value(paramString, "param", result, result_len));
29 |
30 | paramString = "param=true";
31 | BC_ASSERT_TRUE(bctbx_param_string_get_value(paramString, "param", result, result_len));
32 | BC_ASSERT_TRUE(strcmp(result, "true") == 0);
33 | BC_ASSERT_FALSE(bctbx_param_string_get_value(paramString, "notparam", result, result_len));
34 |
35 | paramString = "test;param=true;test";
36 | BC_ASSERT_TRUE(bctbx_param_string_get_value(paramString, "param", result, result_len));
37 | BC_ASSERT_TRUE(strcmp(result, "true") == 0);
38 | BC_ASSERT_FALSE(bctbx_param_string_get_value(paramString, "notparam", result, result_len));
39 |
40 | bctbx_free(result);
41 | }
42 |
43 | static void get_bool_value_test(void) {
44 | char *paramString = "";
45 | BC_ASSERT_FALSE(bctbx_param_string_get_bool_value(paramString, "param"));
46 | paramString = "param=false";
47 | BC_ASSERT_FALSE(bctbx_param_string_get_bool_value(paramString, "param"));
48 | paramString = "param=42";
49 | BC_ASSERT_FALSE(bctbx_param_string_get_bool_value(paramString, "param"));
50 | paramString = "param=true";
51 | BC_ASSERT_TRUE(bctbx_param_string_get_bool_value(paramString, "param"));
52 | }
53 |
54 | static test_t param_string_tests[] = {TEST_NO_TAG("Get value", get_value_test),
55 | TEST_NO_TAG("Get bool value", get_bool_value_test)};
56 |
57 | test_suite_t param_string_test_suite = {
58 | "Param string", NULL, NULL, NULL, NULL, sizeof(param_string_tests) / sizeof(param_string_tests[0]),
59 | param_string_tests, 0};
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | All notable changes to this project will be documented in this file.
3 |
4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6 |
7 |
8 | ## [5.4.0] - 2025-03-11
9 |
10 | ### Added
11 | - Now requires mbedtls 3.6/
12 | - Added support for openssl as an alternative to mbedtls.
13 |
14 | ### Changed
15 | - List copy optimisations.
16 |
17 | ### Removed
18 | - Crypto: remove polarssl support.
19 |
20 |
21 | ## [5.3.68] - 2024-07-10
22 |
23 | ### Added
24 | - Use locale encoding from setlocale() on Windows and fallback to CP_APC if not found.
25 |
26 | ## [5.2.0] - 2022-11-14
27 |
28 | ### Added
29 | - Crypto: add support for post-quantum algorithms.
30 | - Crash handler and backtrace logger for Windows.
31 |
32 | ### Changed
33 | - minor changes.
34 |
35 |
36 | ## [5.1.0] - 2022-02-14
37 |
38 | ### Added
39 | - new vfs read2/write2 functions without offset parameter, to easy mapping with standard libc functions.
40 |
41 | ### Changed
42 | - optimized C++ logging macros.
43 |
44 |
45 | ## [5.0.0] - 2021-07-08
46 |
47 | ### Added
48 | - Tester API: add API to set maximum number of failed tests.
49 |
50 | ### Fixed
51 | - Few bugfixes (see git log)
52 |
53 |
54 | ## [4.5.0] - 2021-03-29
55 |
56 | ### Added
57 | - Encrypted VFS API.
58 |
59 | ### Changed
60 | - Callback for client certificate query is now passed with the full list of subjects.
61 | - miscellaneous small things, see git commits for details.
62 |
63 |
64 | ## [4.4.0] - 2020-6-09
65 |
66 | ### Changed
67 | - Version number now follows linphone-sdk's versionning.
68 |
69 | ### Removed
70 | - Polarssl 1.2 support.
71 |
72 |
73 | ## [0.6.0] - 2017-07-20
74 | ### Added
75 | - Add API to escape/unescape strings (SIP, VCARD).
76 |
77 |
78 | ## [0.5.1] - 2017-02-22
79 | ### Added
80 | - "const char * to void *" map feature
81 |
82 | ### Fixed
83 | - security bugfix: TLS session could be successfully established whereas the common
84 | name did not match the server name.
85 |
86 | ## [0.2.0] - 2016-08-08
87 | ### Added
88 | - Creating a Virtual File System bctbx_vfs allowing direct file access and I/Os.
89 | - integrate OS abstraction layer, list API, logging API from oRTP
90 | - integrate getaddrinfo() abstraction api, in order to provide consistent getaddrinfo() support on all platforms.
91 |
92 |
93 | ## [0.0.1] - 2016-01-01
94 | ### Added
95 | - Initial release.
96 |
97 | ### Changed
98 |
99 | ### Removed
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | **CAUTION: this git repository is no longer updated. The project has been merged into the linphone-sdk ([Gitlab](https://gitlab.linphone.org/BC/public/linphone-sdk), [Github](https://github.com/BelledonneCommunications/linphone-sdk)) git repository and will continue his life there.**
2 |
3 | **Versions up to 5.4 (included) are still kept into this repository, that will remain active on 'release/5.4' branch until the end of life of release 5.4.**
4 |
5 | [](https://gitlab.linphone.org/BC/public/bctoolbox/commits/master)
6 |
7 | BcToolbox
8 | =========
9 |
10 | Utilities library used by Belledonne Communications softwares like belle-sip, mediastreamer2 and liblinphone.
11 |
12 |
13 | Depends
14 | -------
15 |
16 | - **mbedtls[1]**: implementation of TLS interface of BcToolbox. For backward
17 | compatibility, support of mbedtlsv2 is also provided.
18 | - **bcunit[2]** for unitary test tools. (optional)
19 | - **openssl[3]** alternate TLS and crypto implementation. (optional)
20 |
21 |
22 | To compile
23 | ----------
24 |
25 | cmake . -DCMAKE_INSTALL_PREFIX= -DCMAKE_PREFIX_PATH=
26 |
27 | make
28 | make install
29 |
30 |
31 | To make an rpm package
32 | ----------------------
33 |
34 | cmake . -DCMAKE_INSTALL_PREFIX=/usr -DCPACK_GENERATOR="RPM"
35 |
36 | make package
37 |
38 |
39 | Options
40 | -------
41 |
42 | - `CMAKE_INSTALL_PREFIX=`: install prefix.
43 | - `CMAKE_PREFIX_PATH=`: search path prefix for dependencies e.g. mbedtls.
44 | - `ENABLE_MBEDTLS=NO`: do not look for mbedtls.
45 | - `ENABLE_OPENSSL=NO`: do not look for openssl.
46 | - `ENABLE_STRICT=NO`: do not build with strict compilator flags e.g. `-Wall -Werror`.
47 | - `ENABLE_UNIT_TESTS=NO`: do not build testing binaries.
48 | - `ENABLE_TESTS_COMPONENT=NO`: do not build libbctoolbox-tester.
49 |
50 |
51 | Notes
52 | -----
53 |
54 | For backward compatibility with distributions not having the required 2.8.12 cmake version, an automake/autoconf build system is also available.
55 | It is maintained as a best effort and then should be used only in last resort.
56 |
57 |
58 | Note for packagers
59 | ------------------
60 |
61 | Our CMake scripts may automatically add some paths into research paths of generated binaries.
62 | To ensure that the installed binaries are striped of any rpath, use `-DCMAKE_SKIP_INSTALL_RPATH=ON`
63 | while you invoke cmake.
64 |
65 | --------------------
66 |
67 | - [1]
68 | - [2] git://git.linphone.org/bctoolbox.git or
69 | - [3]
70 |
71 |
--------------------------------------------------------------------------------
/include/bctoolbox/utils.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2021 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef BCTBX_UTILS_H
21 | #define BCTBX_UTILS_H
22 |
23 | #include
24 | #include
25 | #include
26 |
27 | #include "bctoolbox/port.h"
28 |
29 | namespace bctoolbox {
30 |
31 | namespace Utils {
32 | BCTBX_PUBLIC std::vector split(const std::string &str, const std::string &delimiter);
33 |
34 | BCTBX_PUBLIC inline std::vector split(const std::string &str, char delimiter) {
35 | return split(str, std::string(1, delimiter));
36 | }
37 |
38 | template
39 | inline const T &getEmptyConstRefObject() {
40 | static const T object{};
41 | return object;
42 | }
43 |
44 | BCTBX_PUBLIC std::string fold(const std::string &str);
45 | BCTBX_PUBLIC std::string unfold(const std::string &str);
46 |
47 | // Replace all "from" by "to" in source. Use 'recursive' to avoid replacing what has been replaced.
48 | BCTBX_PUBLIC void
49 | replace(std::string &source, const std::string &from, const std::string &to, const bool recursive = true);
50 |
51 | // Return the current state of memory as a string. This is currently implemented only for Windows.
52 | BCTBX_PUBLIC std::string getMemoryReportAsString();
53 |
54 | // Replace const_cast in order to be adapted from types. Be carefull when using it.
55 | template
56 | class auto_cast {
57 | public:
58 | explicit constexpr auto_cast(From const &t) noexcept : val{t} {
59 | }
60 |
61 | template
62 | constexpr operator To() const noexcept(noexcept(const_cast(std::declval()))) {
63 | return const_cast(val);
64 | }
65 |
66 | private:
67 | From const &val;
68 | };
69 |
70 | // Checks if the executable is installed by looking if the resource exists at
71 | // /../share//
72 | BCTBX_PUBLIC bool isExecutableInstalled(const std::string &executable, const std::string &resource);
73 |
74 | } // namespace Utils
75 |
76 | } // namespace bctoolbox
77 |
78 | #endif /* BCTBX_UTILS_H */
79 |
--------------------------------------------------------------------------------
/src/param_string.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include "bctoolbox/param_string.h"
21 | #include "bctoolbox/port.h"
22 |
23 | static const char *find_param_occurence_of(const char *fmtp, const char *param) {
24 | const char *pos = fmtp;
25 | int param_len = (int)strlen(param);
26 | do {
27 | pos = strstr(pos, param);
28 | if (pos) {
29 | /*check that the occurence found is not a subword of a parameter name*/
30 | if (pos == fmtp) {
31 | if (pos[param_len] == '=') break; /* found it */
32 | } else if ((pos[-1] == ';' || pos[-1] == ' ') && pos[param_len] == '=') {
33 | break; /* found it */
34 | }
35 | pos += strlen(param);
36 | }
37 | } while (pos != NULL);
38 | return pos;
39 | }
40 |
41 | static const char *find_last_param_occurence_of(const char *fmtp, const char *param) {
42 | const char *pos = fmtp;
43 | const char *lastpos = NULL;
44 | do {
45 | pos = find_param_occurence_of(pos, param);
46 | if (pos) {
47 | lastpos = pos;
48 | pos += strlen(param);
49 | }
50 | } while (pos != NULL);
51 | return lastpos;
52 | }
53 |
54 | bool_t bctbx_param_string_get_value(const char *paramString, const char *param_name, char *result, size_t result_len) {
55 | const char *pos = find_last_param_occurence_of(paramString, param_name);
56 | memset(result, '\0', result_len);
57 | if (pos) {
58 | const char *equal = strchr(pos, '=');
59 | if (equal) {
60 | int copied;
61 | const char *end = strchr(equal + 1, ';');
62 | if (end == NULL) end = paramString + strlen(paramString); /*assuming this is the last param */
63 | copied = MIN((int)(result_len - 1), (int)(end - (equal + 1)));
64 | strncpy(result, equal + 1, copied);
65 | result[copied] = '\0';
66 | return TRUE;
67 | }
68 | }
69 | return FALSE;
70 | }
71 |
72 | bool_t bctbx_param_string_get_bool_value(const char *paramString, const char *param_name) {
73 | size_t result_len = 5;
74 | char *result = bctbx_malloc(result_len);
75 | // True if param is found, false if not
76 | bool_t res = bctbx_param_string_get_value(paramString, param_name, result, result_len);
77 | res = res && strcmp(result, "true") == 0;
78 | free(result);
79 | return res;
80 | }
81 |
--------------------------------------------------------------------------------
/cmake/BCToolboxConfig.cmake.in:
--------------------------------------------------------------------------------
1 | ############################################################################
2 | # BCToolboxConfig.cmake
3 | # Copyright (C) 2010-2023 Belledonne Communications, Grenoble France
4 | #
5 | ############################################################################
6 | #
7 | # This program is free software; you can redistribute it and/or
8 | # modify it under the terms of the GNU General Public License
9 | # as published by the Free Software Foundation; either version 2
10 | # of the License, or (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program; if not, write to the Free Software
19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 | #
21 | ############################################################################
22 | #
23 | # Config file for the bctoolbox package.
24 | #
25 | # Components
26 | # ^^^^^^^^^^
27 | #
28 | # This config file will define the component: tester.
29 | #
30 | #
31 | # Targets
32 | # ^^^^^^^
33 | #
34 | # The following targets are always defined:
35 | # bctoolbox - The bctoolbox library target
36 | #
37 | # The following targets may be defined according to the asked components:
38 | # bctoolbox-tester - The bctoolbox-tester library target (defined if the tester is asked for)
39 | #
40 | #
41 | # Result variables
42 | # ^^^^^^^^^^^^^^^^
43 | #
44 | # This config file will set the following variables in your project:
45 | #
46 | # BCToolbox_FOUND - The bctoolbox library has been found
47 | # BCToolbox_TARGET - The name of the CMake target for the bctoolbox library
48 | # BCToolbox_CMAKE_DIR - The bctoolbox CMake directory
49 | # BCToolbox_CMAKE_UTILS - The path to the bctoolbox CMake utils script
50 | # BCToolbox_tester_FOUND - The bctoolbox-tester library has been found
51 | # BCToolbox_tester_TARGET - The name of the CMake target for the bctoolbox-tester library
52 |
53 | @PACKAGE_INIT@
54 |
55 | include(CMakeFindDependencyMacro)
56 | include("${CMAKE_CURRENT_LIST_DIR}/BCToolboxTargets.cmake")
57 |
58 | set(BCToolbox_TARGET bctoolbox)
59 |
60 | if(@ENABLE_TESTS_COMPONENT@)
61 | set(BCToolbox_tester_FOUND TRUE)
62 | set(BCToolbox_tester_TARGET bctoolbox-tester)
63 | endif()
64 |
65 | # We must propagate the public dependencies and the private dependencies for static build
66 | include(CMakeFindDependencyMacro)
67 | if(@BUILD_SHARED_LIBS@)
68 | else()
69 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
70 | if(@Iconv_FOUND@)
71 | find_dependency(Iconv)
72 | endif()
73 | if(@MbedTLS_FOUND@)
74 | find_dependency(MbedTLS)
75 | endif()
76 | if(@Decaf_FOUND@)
77 | find_dependency(Decaf)
78 | endif()
79 | find_dependency(BCUnit)
80 | endif()
81 |
82 | set_and_check(BCToolbox_CMAKE_DIR "@PACKAGE_CMAKE_MODULES_INSTALL_DIR@")
83 | set_and_check(BCToolbox_CMAKE_UTILS "@PACKAGE_CMAKE_MODULES_INSTALL_DIR@/BCToolboxCMakeUtils.cmake")
84 | include("${BCToolbox_CMAKE_UTILS}")
85 |
86 | check_required_components(BCToolbox)
87 |
--------------------------------------------------------------------------------
/cmake/FindBCUnit.cmake:
--------------------------------------------------------------------------------
1 | ############################################################################
2 | # FindBCUnit.cmake
3 | # Copyright (C) 2017-2023 Belledonne Communications, Grenoble France
4 | #
5 | ############################################################################
6 | #
7 | # This program is free software; you can redistribute it and/or
8 | # modify it under the terms of the GNU General Public License
9 | # as published by the Free Software Foundation; either version 2
10 | # of the License, or (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program; if not, write to the Free Software
19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 | #
21 | ############################################################################
22 | #
23 | # Find the bcunit library.
24 | #
25 | # Targets
26 | # ^^^^^^^
27 | #
28 | # The following targets may be defined:
29 | #
30 | # bcunit - If the bcunit library has been found
31 | #
32 | #
33 | # Result variables
34 | # ^^^^^^^^^^^^^^^^
35 | #
36 | # This module will set the following variables in your project:
37 | #
38 | # BCUnit_FOUND - The bcunit library has been found
39 | # BCUnit_TARGET - The name of the CMake target for the bcunit library
40 | # HAVE_CU_GET_SUITE - If the bcunit library includes the CU_get_suite symbol
41 | # HAVE_CU_CURSES - If the bcunit library includes the CU_curses_run_tests symbol
42 | # HAVE_CU_SET_TRACE_HANDLER - If the bcunit library includes the CU_set_trace_handler symbol
43 |
44 |
45 | if(TARGET bcunit)
46 |
47 | include(FindPackageHandleStandardArgs)
48 | set(BCUnit_TARGET bcunit)
49 | set(HAVE_CU_GET_SUITE TRUE)
50 | set(HAVE_CU_CURSES ${ENABLE_BCUNIT_CURSES})
51 | set(HAVE_CU_SET_TRACE_HANDLER ${ENABLE_BCUNIT_BASIC})
52 | set(_BCUnit_REQUIRED_VARS BCUnit_TARGET HAVE_CU_GET_SUITE)
53 | set(_BCUnit_CACHE_VARS
54 | ${_BCUnit_REQUIRED_VARS} HAVE_CU_CURSES HAVE_CU_SET_TRACE_HANDLER
55 | )
56 | find_package_handle_standard_args(BCUnit
57 | REQUIRED_VARS ${_BCUnit_REQUIRED_VARS}
58 | )
59 | mark_as_advanced(${_BCUnit_CACHE_VARS})
60 |
61 | else()
62 |
63 | set(_OPTIONS CONFIG)
64 | if(BCUnit_FIND_REQUIRED)
65 | list(APPEND _OPTIONS REQUIRED)
66 | endif()
67 | if(BCUnit_FIND_QUIETLY)
68 | list(APPEND _OPTIONS QUIET)
69 | endif()
70 | if(BCUnit_FIND_VERSION)
71 | list(PREPEND _OPTIONS "${BCUnit_FIND_VERSION}")
72 | endif()
73 | if(BCUnit_FIND_EXACT)
74 | list(APPEND _OPTIONS EXACT)
75 | endif()
76 |
77 | find_package(BCUnit ${_OPTIONS})
78 |
79 | cmake_push_check_state(RESET)
80 | get_target_property(BCUnit_INCLUDE_DIRS "${BCUnit_TARGET}" INTERFACE_INCLUDE_DIRECTORIES)
81 | list(APPEND CMAKE_REQUIRED_INCLUDES ${BCUnit_INCLUDE_DIRS})
82 | list(APPEND CMAKE_REQUIRED_LIBRARIES "${BCUnit_TARGET}")
83 | check_symbol_exists("CU_get_suite" "BCUnit/BCUnit.h" HAVE_CU_GET_SUITE)
84 | check_symbol_exists("CU_curses_run_tests" "BCUnit/BCUnit.h" HAVE_CU_CURSES)
85 | check_symbol_exists("CU_set_trace_handler" "BCUnit/Util.h" HAVE_CU_SET_TRACE_HANDLER)
86 | cmake_pop_check_state()
87 |
88 | endif()
89 |
--------------------------------------------------------------------------------
/src/utils/regex.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifdef HAVE_CONFIG_H
21 | #include "config.h"
22 | #endif
23 |
24 | #include
25 |
26 | #include "bctoolbox/logging.h"
27 | #include "bctoolbox/regex.h"
28 |
29 | /*
30 | This part is needed since CentOS7 have an old gcc compiler.
31 | TODO: Remove this code when all supported platorms have gcc 4.9.0 or more
32 | */
33 | #if __cplusplus >= 201103L && \
34 | (!defined(__GLIBCXX__) || (__cplusplus >= 201402L) || \
35 | (defined(_GLIBCXX_REGEX_DFS_QUANTIFIERS_LIMIT) || defined(_GLIBCXX_REGEX_STATE_LIMIT) || \
36 | (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE > 4))) && \
37 | !defined(__ANDROID__) || \
38 | defined(_WIN32)
39 | #define HAVE_WORKING_REGEX 1
40 | #else
41 | #define HAVE_WORKING_REGEX 0
42 | #include
43 | #endif
44 |
45 | extern "C" bool_t
46 | bctbx_is_matching_regex_log_context(const char *entry, const char *regex, bool_t show_log, const char *context) {
47 | #if HAVE_WORKING_REGEX
48 | try {
49 | std::regex entry_regex(regex, std::regex_constants::extended | std::regex_constants::nosubs);
50 | std::cmatch m;
51 | return std::regex_match(entry, m, entry_regex);
52 | } catch (const std::regex_error &e) {
53 | if (show_log)
54 | bctbx_error("Could not compile regex '%s'%s: %s", regex,
55 | (context ? ("[" + std::string(context) + "]").c_str() : ""), e.what());
56 | return FALSE;
57 | }
58 | #else
59 | regex_t regex_pattern;
60 | char err_msg[256];
61 | int res;
62 | res = regcomp(®ex_pattern, regex, REG_EXTENDED | REG_NOSUB);
63 | if (res != 0) {
64 | if (show_log) {
65 | regerror(res, ®ex_pattern, err_msg, sizeof(err_msg));
66 | bctbx_error("Could not compile regex '%s'%s: %s", regex,
67 | (context ? ("[" + std::string(context) + "]").c_str() : ""), err_msg);
68 | }
69 | return FALSE;
70 | }
71 | res = regexec(®ex_pattern, entry, 0, NULL, 0);
72 | regfree(®ex_pattern);
73 | return (res != REG_NOMATCH);
74 | #endif
75 | }
76 |
77 | extern "C" bool_t bctbx_is_matching_regex_log(const char *entry, const char *regex, bool_t show_log) {
78 | return bctbx_is_matching_regex_log_context(entry, regex, show_log, NULL);
79 | }
80 |
81 | extern "C" bool_t bctbx_is_matching_regex(const char *entry, const char *regex) {
82 | return bctbx_is_matching_regex_log(entry, regex, TRUE);
83 | }
84 |
--------------------------------------------------------------------------------
/src/vfs/vfs_encryption_module.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef BCTBX_VFS_ENCRYPTION_MODULE_HH
21 | #define BCTBX_VFS_ENCRYPTION_MODULE_HH
22 |
23 | #include "bctoolbox/vfs_encrypted.hh"
24 |
25 | namespace bctoolbox {
26 | /**
27 | * Define the interface any encryption suite must provide
28 | */
29 | class VfsEncryptionModule {
30 | public:
31 | /**
32 | * @return the size in bytes of the chunk header
33 | */
34 | virtual size_t getChunkHeaderSize() const noexcept = 0;
35 | /**
36 | * @return the size in bytes of file header module data
37 | */
38 | virtual size_t getModuleFileHeaderSize() const noexcept = 0;
39 | /**
40 | * @return the encryptionSuite implemented by the module
41 | */
42 | virtual EncryptionSuite getEncryptionSuite() const noexcept = 0;
43 |
44 | /**
45 | * Get from the module the data to store in the file header
46 | */
47 | virtual const std::vector getModuleFileHeader(const VfsEncryption &fileContext) const = 0;
48 |
49 | /**
50 | * Set in the module, the secret material used for encryption
51 | */
52 | virtual void setModuleSecretMaterial(const std::vector &secret) = 0;
53 |
54 | /**
55 | * Get the size of the secret material needed by this module
56 | */
57 | virtual size_t getSecretMaterialSize() const noexcept = 0;
58 |
59 | /**
60 | * Decrypt a data chunk
61 | * @param[in] a vector which size shall be chunkHeaderSize + chunkSize holding the raw data read from disk
62 | * @return the decrypted data chunk
63 | */
64 | virtual std::vector decryptChunk(const uint32_t chunkIndex, const std::vector &rawChunk) = 0;
65 |
66 | /**
67 | * ReEncrypt a data chunk
68 | * @param[in/out] rawChunk The existing encrypted chunk
69 | * @param[in] plainData The plain text to be encrypted
70 | */
71 | virtual void
72 | encryptChunk(const uint32_t chunkIndex, std::vector &rawChunk, const std::vector &plainData) = 0;
73 | /**
74 | * Encrypt a new data chunk
75 | * @param[in] chunkIndex The chunk index
76 | * @param[in] plainData The plain text to be encrypted
77 | * @return the encrypted chunk
78 | */
79 | virtual std::vector encryptChunk(const uint32_t chunkIndex, const std::vector &plainData) = 0;
80 |
81 | /**
82 | * Check the integrity over the whole file
83 | * @param[in] fileContext a way to access the file content
84 | *
85 | * @return true if the integrity check successfully passed, false otherwise
86 | */
87 | virtual bool checkIntegrity(const VfsEncryption &fileContext) = 0;
88 |
89 | virtual ~VfsEncryptionModule(){};
90 | };
91 |
92 | } // namespace bctoolbox
93 | #endif // BCTBX_VFS_ENCRYPTION_MODULE_HH
94 |
--------------------------------------------------------------------------------
/src/utils/ios_utils_app.mm:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Belledonne Communications SARL.
3 | *
4 | * This file is part of Liblinphone.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 |
22 | #if TARGET_OS_IPHONE
23 |
24 | #include
25 | #include
26 | #include "ios_utils_app.hh"
27 | #include "bctoolbox/logging.h"
28 |
29 | namespace bctoolbox {
30 |
31 | unsigned long IOSUtilsApp::beginBackgroundTask(const char *name, std::function cb) {
32 | __block UIBackgroundTaskIdentifier bgid = UIBackgroundTaskInvalid;
33 |
34 | UIApplication *app=[UIApplication sharedApplication];
35 |
36 | @try {
37 | if (cb==nullptr){
38 | bctbx_error("belle_sip_begin_background_task(): the callback must not be NULL. Application must be aware that the background task needs to be terminated.");
39 | bgid = UIBackgroundTaskInvalid;
40 | @throw([NSException exceptionWithName:@"LinphoneCoreException" reason:@"Background task has no callback" userInfo:nil]);
41 | }
42 |
43 | void (^handler)() = ^{
44 | cb();
45 | };
46 |
47 | if([app respondsToSelector:@selector(beginBackgroundTaskWithName:expirationHandler:)]){
48 | bgid = [app beginBackgroundTaskWithName:[NSString stringWithUTF8String:name] expirationHandler:handler];
49 | } else {
50 | bgid = [app beginBackgroundTaskWithExpirationHandler:handler];
51 | }
52 |
53 | if (bgid==UIBackgroundTaskInvalid){
54 | bctbx_error("Could not start background task %s.", name);
55 | bgid = 0;
56 | @throw([NSException exceptionWithName:@"LinphoneCoreException" reason:@"Could not start background task" userInfo:nil]);
57 | }
58 |
59 | // backgroundTimeRemaining is properly set only when running background... but not immediately!
60 | // removed app.applicationState check because not thread safe
61 | if (app.backgroundTimeRemaining == DBL_MAX) {
62 | bctbx_message("Background task %s started. Unknown remaining time since application is not fully in background.", name);
63 | } else {
64 | bctbx_message("Background task %s started. Remaining time %.1f secs", name, app.backgroundTimeRemaining);
65 | }
66 | }
67 | @catch (NSException*) {
68 | // do nothing
69 | }
70 |
71 | return (unsigned long)bgid;
72 | }
73 |
74 | void IOSUtilsApp::endBackgroundTask(unsigned long id) {
75 | UIApplication *app=[UIApplication sharedApplication];
76 | if (id != UIBackgroundTaskInvalid){
77 | [app endBackgroundTask:(UIBackgroundTaskIdentifier)id];
78 | }
79 | }
80 |
81 | bool IOSUtilsApp::isApplicationStateActive() {
82 | return ([UIApplication sharedApplication].applicationState == UIApplicationStateActive);
83 | }
84 |
85 | } //namespace bctoolbox
86 |
87 | extern "C" {
88 | bctoolbox::IOSUtilsInterface *bctbx_create_ios_utils_app() {
89 | return new bctoolbox::IOSUtilsApp;
90 | }
91 |
92 | void bctbx_destroy_ios_utils_app(bctoolbox::IOSUtilsInterface* p) {
93 | delete p;
94 | }
95 | }
96 |
97 | #endif
98 |
--------------------------------------------------------------------------------
/src/utils/exception.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifdef HAVE_CONFIG_H
21 | #include "config.h"
22 | #endif // ifdef HAVE_CONFIG_H
23 |
24 | #ifdef HAVE_EXECINFO
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #endif
31 |
32 | #include "bctoolbox/exception.hh"
33 | #include "bctoolbox/logging.h"
34 |
35 | using namespace std;
36 |
37 | #ifdef HAVE_EXECINFO
38 | static void uncaught_handler() {
39 | std::exception_ptr p = current_exception();
40 | try {
41 | rethrow_exception(p);
42 | } catch (BctbxException &e) {
43 | BCTBX_SLOGE << e;
44 | } catch (std::exception &ee) {
45 | BCTBX_SLOGE << "Unexpected exception [" << ee.what() << " ] use BctbxException for better debug";
46 | }
47 | abort();
48 | }
49 | #endif
50 |
51 | BctbxException::BctbxException(const std::string &message) : mSize(0) {
52 | #ifdef HAVE_EXECINFO
53 | mSize = backtrace(mArray, sizeof(mArray) / sizeof(void *));
54 | #else
55 | mSize = 0;
56 | #endif
57 | if (!message.empty()) mOs << message;
58 | #ifdef HAVE_EXECINFO
59 | #if __clang
60 | if (get_terminate() != uncaught_handler)
61 | #endif
62 | set_terminate(uncaught_handler); // invoke in case of uncautch exception for this thread
63 | #endif
64 |
65 | #ifndef HAVE_EXECINFO
66 | /* Warn about exception as soon as it is created. Exceptions are not usual events and may be difficult to locate if
67 | * stacktrace is not available. */
68 | BCTBX_SLOGW << "BctbxException occurred at : " << mOs.str();
69 | #endif
70 | }
71 |
72 | BctbxException::BctbxException(const BctbxException &other) : mSize(other.mSize) {
73 | memcpy(mArray, other.mArray, sizeof(mArray));
74 | mOs << other.str();
75 | }
76 |
77 | void BctbxException::printStackTrace() const {
78 | #ifdef HAVE_EXECINFO
79 | backtrace_symbols_fd(mArray + 1, mSize - 1, STDERR_FILENO);
80 | #else
81 | std::cerr << "stack trace not available on this platform" << std::endl;
82 | #endif
83 | }
84 |
85 | void BctbxException::printStackTrace(std::ostream &os) const {
86 | #ifdef HAVE_EXECINFO
87 | char **bt = backtrace_symbols(mArray, mSize);
88 | int position = 0;
89 | for (unsigned int i = 1; i < mSize; ++i) {
90 | Dl_info info;
91 | char *demangled = NULL;
92 | int status = -1;
93 | if (dladdr(mArray[i], &info) && info.dli_sname) {
94 | demangled = abi::__cxa_demangle(info.dli_sname, NULL, 0, &status);
95 | os << position++ << setw(20) << basename((char *)info.dli_fname) << setw(16) << info.dli_saddr;
96 | os << " ";
97 | if (demangled) {
98 | os << demangled;
99 | free(demangled);
100 | } else {
101 | os << info.dli_sname;
102 | }
103 | } else {
104 | os << bt[i];
105 | }
106 | os << std::endl;
107 | }
108 | free(bt);
109 | #else
110 | os << "[stack trace not available on this platform]";
111 | #endif
112 | }
113 |
114 | const char *BctbxException::what() const noexcept {
115 | return str().c_str();
116 | }
117 |
118 | const std::string &BctbxException::str() const {
119 | mMessage = mOs.str();
120 | return mMessage;
121 | }
122 |
123 | std::ostream &operator<<(std::ostream &__os, const BctbxException &e) {
124 | __os << e.str() << std::endl;
125 | e.printStackTrace(__os);
126 | return __os;
127 | }
128 |
--------------------------------------------------------------------------------
/src/vfs/vfs_encryption_module_dummy.hh:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef BCTBX_VFS_ENCRYPTION_MODULE_DUMMY_HH
21 | #define BCTBX_VFS_ENCRYPTION_MODULE_DUMMY_HH
22 | #include "bctoolbox/vfs_encrypted.hh"
23 | #include "vfs_encryption_module.hh"
24 |
25 | namespace bctoolbox {
26 | class VfsEncryptionModuleDummy : public VfsEncryptionModule {
27 | private:
28 | /**
29 | * Store the file header and secret
30 | */
31 | std::vector mFileHeader;
32 | std::vector mFileHeaderIntegrity;
33 | std::vector mSecret;
34 |
35 | /**
36 | * Compute the integrity tag in the given chunk
37 | */
38 | std::vector chunkIntegrityTag(const std::vector &chunk) const;
39 |
40 | /**
41 | * Get the chunk index from the given chunk
42 | */
43 | uint32_t getChunkIndex(const std::vector &chunk) const;
44 |
45 | /**
46 | * Get global IV. Part of IV common to all chunks
47 | * The last 8 bytes of the file header
48 | */
49 | std::vector globalIV() const;
50 |
51 | public:
52 | /**
53 | * @return the size in bytes of file header module data
54 | */
55 | static size_t moduleFileHeaderSize() noexcept;
56 |
57 | /**
58 | * @return the size in bytes of the chunk header
59 | */
60 | size_t getChunkHeaderSize() const noexcept override;
61 |
62 | /**
63 | * @return the size in bytes of file header module data
64 | */
65 | size_t getModuleFileHeaderSize() const noexcept override;
66 |
67 | /**
68 | * @return the EncryptionSuite provided by this module
69 | */
70 | EncryptionSuite getEncryptionSuite() const noexcept override {
71 | return EncryptionSuite::dummy;
72 | }
73 |
74 | /**
75 | * @return the secret material size
76 | */
77 | size_t getSecretMaterialSize() const noexcept override;
78 |
79 | /**
80 | * Decrypt a chunk of data
81 | * @param[in] a vector which size shall be chunkHeaderSize + chunkSize holding the raw data read from disk
82 | * @return the decrypted data chunk
83 | */
84 | std::vector decryptChunk(const uint32_t chunkIndex, const std::vector &rawChunk) override;
85 |
86 | void encryptChunk(const uint32_t chunkIndex,
87 | std::vector &rawChunk,
88 | const std::vector &plainData) override;
89 | std::vector encryptChunk(const uint32_t chunkIndex, const std::vector &plainData) override;
90 |
91 | const std::vector getModuleFileHeader(const VfsEncryption &fileContext) const override;
92 |
93 | void setModuleSecretMaterial(const std::vector &secret) override;
94 |
95 | /**
96 | * Check the integrity over the whole file
97 | * @param[in] fileContext a way to access the file content
98 | *
99 | * @return true if the integrity check successfully passed, false otherwise
100 | */
101 | bool checkIntegrity(const VfsEncryption &fileContext) override;
102 |
103 | /**
104 | * constructors
105 | */
106 | // At file creation
107 | VfsEncryptionModuleDummy();
108 | // Opening an existing file
109 | VfsEncryptionModuleDummy(const std::vector &moduleFileHeader);
110 |
111 | ~VfsEncryptionModuleDummy(){};
112 | };
113 |
114 | } // namespace bctoolbox
115 | #endif // BCTBX_VFS_ENCRYPTION_MODULE_DUMMY
116 |
--------------------------------------------------------------------------------
/src/parser.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifdef HAVE_CONFIG_H
21 | #include "config.h"
22 | #endif
23 |
24 | #include "bctoolbox/logging.h"
25 | #include "bctoolbox/parser.h"
26 | #include "bctoolbox/port.h"
27 |
28 | char *bctbx_escape(const char *buff, const bctbx_noescape_rules_t noescapes) {
29 | size_t outbuf_size = strlen(buff);
30 | size_t orig_size = outbuf_size;
31 | char *output_buff = (char *)bctbx_malloc(outbuf_size + 1);
32 | int i;
33 | size_t out_buff_index = 0;
34 |
35 | for (i = 0; buff[i] != '\0'; i++) {
36 | int c = ((unsigned char *)buff)[i];
37 | if (outbuf_size < out_buff_index + 3) {
38 | // we will possibly add 3 chars
39 | outbuf_size += MAX(orig_size / 2, 3);
40 | output_buff = bctbx_realloc(output_buff, outbuf_size + 1);
41 | }
42 | if (noescapes[c] == 1) {
43 | output_buff[out_buff_index++] = c;
44 | } else {
45 | // this will write 3 characters
46 | out_buff_index += snprintf(output_buff + out_buff_index, outbuf_size + 1 - out_buff_index, "%%%02x", c);
47 | }
48 | }
49 | output_buff[out_buff_index] = '\0';
50 | return output_buff;
51 | }
52 |
53 | void bctbx_noescape_rules_add_list(bctbx_noescape_rules_t noescapes, const char *allowed) {
54 | while (*allowed) {
55 | noescapes[(unsigned int)*allowed] = 1;
56 | ++allowed;
57 | }
58 | }
59 |
60 | void bctbx_noescape_rules_add_range(bctbx_noescape_rules_t noescapes, char first, char last) {
61 | memset(noescapes + (unsigned int)first, 1, last - first + 1);
62 | }
63 |
64 | void bctbx_noescape_rules_add_alfanums(bctbx_noescape_rules_t noescapes) {
65 | bctbx_noescape_rules_add_range(noescapes, '0', '9');
66 | bctbx_noescape_rules_add_range(noescapes, 'A', 'Z');
67 | bctbx_noescape_rules_add_range(noescapes, 'a', 'z');
68 | }
69 |
70 | static int is_escaped_char(const char *a) {
71 | return a[0] == '%' && a[1] != '\0' && a[2] != '\0';
72 | }
73 |
74 | size_t bctbx_get_char(const char *a, char *out) {
75 | if (is_escaped_char(a)) {
76 | unsigned int tmp;
77 | sscanf(a + 1, "%02x", &tmp);
78 | *out = (char)tmp;
79 | return 3;
80 | } else {
81 | *out = *a;
82 | return 1;
83 | }
84 | }
85 |
86 | char *bctbx_unescaped_string(const char *buff) {
87 | char *output_buff = bctbx_malloc(strlen(buff) + 1);
88 | size_t i;
89 | size_t out_buff_index = 0;
90 |
91 | for (i = 0; buff[i] != '\0'; out_buff_index++) {
92 | i += bctbx_get_char(buff + i, output_buff + out_buff_index);
93 | }
94 |
95 | output_buff[out_buff_index] = '\0';
96 | return output_buff;
97 | }
98 |
99 | char *bctbx_unescaped_string_only_chars_in_rules(const char *buff, const bctbx_noescape_rules_t unescape) {
100 | size_t max_len = strlen(buff) + 1;
101 | char *output_buff = bctbx_malloc(max_len);
102 | size_t i;
103 | size_t out_buff_index = 0;
104 |
105 | for (i = 0; buff[i] != '\0';) {
106 | i += bctbx_get_char(buff + i, output_buff + out_buff_index);
107 |
108 | int c = ((unsigned char *)output_buff)[out_buff_index];
109 | if (unescape[c] == 0 && is_escaped_char(buff + i)) {
110 | // we unescaped a character that should stay escaped
111 | max_len += 3;
112 | output_buff = bctbx_realloc(output_buff, max_len);
113 | out_buff_index += snprintf(output_buff + out_buff_index, max_len - out_buff_index, "%%%02x", c);
114 | } else {
115 | out_buff_index += 1;
116 | }
117 | }
118 |
119 | output_buff[out_buff_index] = '\0';
120 | return output_buff;
121 | }
--------------------------------------------------------------------------------
/tester/bctoolbox_tester.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020 Belledonne Communications SARL.
3 | *
4 | * This file is part of bctoolbox.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 | #ifdef HAVE_CONFIG_H
20 | #include "config.h"
21 | #endif
22 | #include "bctoolbox/logging.h"
23 | #include "bctoolbox_tester.h"
24 |
25 | static const char *log_domain = "bctoolbox-tester";
26 |
27 | static void log_handler(int lev, const char *fmt, va_list args) {
28 | #ifdef _WIN32
29 | /* We must use stdio to avoid log formatting (for autocompletion etc.) */
30 | vfprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, fmt, args);
31 | fprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, "\n");
32 | #else
33 | va_list cap;
34 | va_copy(cap, args);
35 | vfprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, fmt, cap);
36 | fprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, "\n");
37 | va_end(cap);
38 | #endif
39 |
40 | bctbx_logv(log_domain, lev, fmt, args);
41 | }
42 |
43 | void bctoolbox_tester_init(void (*ftester_printf)(int level, const char *fmt, va_list args)) {
44 | bc_tester_init(log_handler, BCTBX_LOG_MESSAGE, BCTBX_LOG_ERROR, NULL);
45 | bc_tester_add_suite(&containers_test_suite);
46 | bc_tester_add_suite(&utils_test_suite);
47 | #if (HAVE_MBEDTLS || HAVE_OPENSSL)
48 | bc_tester_add_suite(&crypto_test_suite);
49 | bc_tester_add_suite(&encrypted_vfs_test_suite);
50 | #endif
51 | bc_tester_add_suite(&parser_test_suite);
52 | #ifdef __APPLE__
53 | bc_tester_add_suite(&ios_utils_test_suite);
54 | #endif
55 | bc_tester_add_suite(¶m_string_test_suite);
56 | bc_tester_add_suite(&vfs_test_suite);
57 | bc_tester_add_suite(&logger_test_suite);
58 | }
59 |
60 | void bctoolbox_tester_uninit(void) {
61 | bc_tester_uninit();
62 | }
63 |
64 | void bctoolbox_tester_before_each() {
65 | }
66 |
67 | int bctoolbox_tester_set_log_file(const char *filename) {
68 | int res = 0;
69 | char *dir = bctbx_dirname(filename);
70 | char *base = bctbx_basename(filename);
71 | bctbx_message("Redirecting traces to file [%s]", filename);
72 | bctbx_log_handler_t *filehandler = bctbx_create_file_log_handler(0, dir, base);
73 | if (filehandler == NULL) {
74 | res = -1;
75 | goto end;
76 | }
77 | bctbx_add_log_handler(filehandler);
78 |
79 | end:
80 | bctbx_free(dir);
81 | bctbx_free(base);
82 | return res;
83 | }
84 |
85 | #if !defined(__ANDROID__) && !(defined(BCTBX_WINDOWS_PHONE) || defined(BCTBX_WINDOWS_UNIVERSAL))
86 |
87 | static const char *bctoolbox_helper = "\t\t\t--verbose\n"
88 | "\t\t\t--silent\n"
89 | "\t\t\t--log-file