pax_global_header00006660000000000000000000000064144655202470014523gustar00rootroot0000000000000052 comment=ffc8b55d09a3488f4f6be38034b33bc64bf8b0ce orcania-2.3.3/000077500000000000000000000000001446552024700131445ustar00rootroot00000000000000orcania-2.3.3/.github/000077500000000000000000000000001446552024700145045ustar00rootroot00000000000000orcania-2.3.3/.github/workflows/000077500000000000000000000000001446552024700165415ustar00rootroot00000000000000orcania-2.3.3/.github/workflows/ccpp.yml000066400000000000000000000012021446552024700202040ustar00rootroot00000000000000on: [push, pull_request] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: install dependencies run: | sudo apt-get update sudo apt-get install -y cmake pkg-config check libsubunit-dev cppcheck doxygen valgrind - name: cppcheck run: cppcheck --force --enable=warning,missingInclude --error-exitcode=1 . - name: build run: | mkdir build cd build cmake -DBUILD_ORCANIA_TESTING=on -DBUILD_ORCANIA_DOCUMENTATION=on .. make test package doc sudo make install cd .. make make clean check orcania-2.3.3/.github/workflows/codeql-analysis.yml000066400000000000000000000035111446552024700223540ustar00rootroot00000000000000name: "CodeQL V1" on: push: branches: [master, ] pull_request: # The branches below must be a subset of the branches above branches: [master] schedule: - cron: '0 20 * * 2' jobs: analyse: name: Analyse runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. fetch-depth: 2 # If this run was triggered by a pull request event, then checkout # the head of the pull request instead of the merge commit. - run: git checkout HEAD^2 if: ${{ github.event_name == 'pull_request' }} # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v1 # Override language selection by uncommenting this and choosing your languages # with: # languages: go, javascript, csharp, python, cpp, java # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) #- name: Autobuild # uses: github/codeql-action/autobuild@v1 # â„šī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines # and modify them (or add more) to build your code if your project # uses a compiled language - run: | sudo apt-get update sudo apt-get install -y cmake pkg-config doxygen mkdir build cd build cmake -DBUILD_ORCANIA_DOCUMENTATION=on .. make make doc sudo make install - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 orcania-2.3.3/.github/workflows/codeql-v2.yml000066400000000000000000000067421446552024700210710ustar00rootroot00000000000000# For most projects, this workflow file will not need changing; you simply need # to commit it to your repository. # # You may wish to alter this file to override the set of languages analyzed, # or to provide custom queries or build logic. # # ******** NOTE ******** # We have attempted to detect the languages in your repository. Please check # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # name: "CodeQL V2" on: push: branches: [ "master" ] pull_request: # The branches below must be a subset of the branches above branches: [ "master" ] schedule: - cron: '42 7 * * 0' jobs: analyze: name: Analyze # Runner size impacts CodeQL analysis time. To learn more, please see: # - https://gh.io/recommended-hardware-resources-for-running-codeql # - https://gh.io/supported-runners-and-hardware-resources # - https://gh.io/using-larger-runners # Consider using larger runners for possible analysis time improvements. runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: [ 'cpp' ] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] # Use only 'java' to analyze code written in Java, Kotlin or both # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support steps: - name: Checkout repository uses: actions/checkout@v3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs # queries: security-extended,security-and-quality # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild uses: github/codeql-action/autobuild@v2 # â„šī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun # If the Autobuild fails above, remove it and uncomment the following three lines. # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - run: | sudo apt-get update sudo apt-get install -y cmake pkg-config doxygen mkdir build cd build cmake -DBUILD_ORCANIA_DOCUMENTATION=on .. make make doc sudo make install - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 with: category: "/language:${{matrix.language}}" orcania-2.3.3/.gitignore000066400000000000000000000000551446552024700151340ustar00rootroot00000000000000*.o *.so *.so.* *.a *.pc *.log orcania-cfg.h orcania-2.3.3/API.md000066400000000000000000000014301446552024700140750ustar00rootroot00000000000000# Orcania library Potluck with different functions for different purposes that can be shared among C programs. This is a small library intended to provide low-level functionalities in my other libraries and programs. The functionalities are divided into 4 categories: ## String functions - Wrappers for `string.h`: functions like `strcpy`, `strcmp` or `strchr` that will not segfault if a parameter is `NULL` - `split_string` and afiliated functions: split a string using a separator match or join a split string ## Pointer list structure Simple structure to store and manipulate any kind of pointer in an array. ## Base64 functions Encode, decode in base64 and base64url format. ## Memory functions Replace glib `malloc/realloc/free` functions with user-defined memory functions. orcania-2.3.3/CHANGELOG.md000066400000000000000000000047441446552024700147660ustar00rootroot00000000000000# Orcania Changelog ## 2.3.3 - Enforce base64decode ## 2.3.2 - Improve cmake script and MSVC support - Build with flag `-Wconversion` ## 2.3.1 - Minor bugfixes ## 2.3.0 - Add `o_base64_encode_alloc`, `o_base64_decode_alloc`, `o_base64url_encode_alloc`, `o_base64url_decode_alloc`, `o_base64url_2_base64_alloc`, `o_base64_2_base64url_alloc` - Fix pkg-config file with absolute path for `CMAKE_INSTALL_{INCLUDE,LIB}DIR`, Closes #27 ## 2.2.2 - Add `o_strnullempty` - Breaking: `trimwhitespace` now returns `const char *` instead of `char *`, might give compiler warning - Refactor `o_base64*` functions ## 2.2.1 - Add ld flags in liborcania.pc on static build ## 2.2.0 - Add command-line tool `base64url` which is similar to GNU `base64` tool but for `base64url` format ## 2.1.1 - Harmonize and fix license - Fix doc generator - Rework mstrcatf - Fix pkgconfig install on Makefile - Add simple API documentation summary ## 2.1.0 - Add doxygen documentation - Add functions `pointer_list_clean_free`, `pointer_list_remove_at_free` and `pointer_list_remove_pointer_free` - `split_string` returns `size_t` - Add functions `o_strnchr` and `o_strrnchr` - Add function `trimcharacter` - Improve `o_base64_decode` if input data is invalid ## 2.0.1 - Fix double free() on `pointer_list_remove_at` - Fix build for MacOSX (thanks JohnAZoidberg!) - Clean build process - Fix config option STRTSR so cmake and makefile will use the same name ## 2.0.0 - Add struct _pointer_list to manage arrays of pointers - Add string_array_join, string_array_size - Add o_base64url_encode and o_base64url_decode, and o_base64url_2_base64 to convert base64 url format to base64 - Remove jansson related functions and dependency - Install pkgconfig file when using Makefile ## 1.2.9 - Add build flag to force inline implementation of strstr if the host system is not known to implement strstr but isn't listed as so, like FreeRTOS Thanks to Dirk Uhlemann - Avoid babelouest/ulfius#84 ## 1.2.8 - Fix build with Makefile - Improve build config file and install headers ## 1.2.7 - Add config file orcania-cfg.h dynamically built with the options ## 1.2.6 - Add Travis CI - Change cmake option BUILD_TESTING to BUILD_YDER_TESTING - Add RPM in CMake script package ## 1.2.5 - Fix pkgconfig file ## 1.2.4 - Fix CMake build when /usr/local is not present in default build path ## 1.2.3 - Fix Makefile soname ## 1.2.2 - Upgrade Makefile ## 1.2.1 - Fix string_array_has_trimmed_value ## 1.2.0 - Add CMake installation script orcania-2.3.3/CMakeLists.txt000066400000000000000000000323431446552024700157110ustar00rootroot00000000000000# # Orcania library # # CMake file used to build all programs # # Copyright 2018 Silvio Clecio # Copyright 2018-2022 Nicolas Mora # # This program is free software; you can redistribute it and/or # modify it under the terms of the MIT License # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # cmake_minimum_required(VERSION 3.5) project(orcania C) set(CMAKE_C_STANDARD 99) if (NOT MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") endif() # library info set(PROJECT_DESCRIPTION "Potluck with different functions for different purposes that can be shared among programs") set(PROJECT_HOMEPAGE_URL "https://github.com/babelouest/orcania/") set(PROJECT_BUGREPORT_PATH "https://github.com/babelouest/orcania/issues") set(LIBRARY_VERSION_MAJOR "2") set(LIBRARY_VERSION_MINOR "3") set(LIBRARY_VERSION_PATCH "3") set(PROJECT_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") set(PROJECT_VERSION_MAJOR ${LIBRARY_VERSION_MAJOR}) set(PROJECT_VERSION_MINOR ${LIBRARY_VERSION_MINOR}) set(PROJECT_VERSION_PATCH ${LIBRARY_VERSION_PATCH}) set(ORCANIA_LIBS) if (${LIBRARY_VERSION_MAJOR} VERSION_LESS 10) set (LIBRARY_VERSION_MAJOR_PAD "0${LIBRARY_VERSION_MAJOR}") else () set (LIBRARY_VERSION_MAJOR_PAD "${LIBRARY_VERSION_MAJOR}") endif () if (${LIBRARY_VERSION_MINOR} VERSION_LESS 10) set (LIBRARY_VERSION_MINOR_PAD "0${LIBRARY_VERSION_MINOR}") else () set (LIBRARY_VERSION_MINOR_PAD "${LIBRARY_VERSION_MINOR}") endif () if (${LIBRARY_VERSION_PATCH} VERSION_LESS 10) set (LIBRARY_VERSION_PATCH_PAD "0${LIBRARY_VERSION_PATCH}") else () set (LIBRARY_VERSION_PATCH_PAD "${LIBRARY_VERSION_PATCH}") endif () set(PROJECT_VERSION_NUMBER "${LIBRARY_VERSION_MAJOR_PAD}${LIBRARY_VERSION_MINOR_PAD}${LIBRARY_VERSION_PATCH_PAD}") set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") set(LIBRARY_SOVERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}") # cmake modules set(O_CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules) list(APPEND CMAKE_MODULE_PATH "${O_CMAKE_MODULE_PATH}") include(GNUInstallDirs) include(CheckSymbolExists) include(CMakePackageConfigHelpers) # check if _GNU_SOURCE is available if (NOT _GNU_SOURCE) check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE) if (NOT _GNU_SOURCE) unset(_GNU_SOURCE CACHE) check_symbol_exists(_GNU_SOURCE "features.h" _GNU_SOURCE) endif () endif () if (_GNU_SOURCE) add_definitions(-D_GNU_SOURCE) endif () # directories and source set(INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set(BASE64URL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools/base64url) set(LIB_SRC ${INC_DIR}/orcania.h # allow many IDEs to find and edit it ${SRC_DIR}/base64.c ${SRC_DIR}/memory.c ${SRC_DIR}/orcania.c) option(WITH_STRSTR "Use inline implementation of strstr" OFF) if (WITH_STRSTR) set(O_STRSTR ON) else () set(O_STRSTR OFF) endif () set(PKGCONF_REQ "") set(PKGCONF_REQ_PRIVATE "") # build orcania-cfg.h file configure_file(${INC_DIR}/orcania-cfg.h.in ${PROJECT_BINARY_DIR}/orcania-cfg.h) set (CMAKE_EXTRA_INCLUDE_FILES ${PROJECT_BINARY_DIR}) option(BUILD_SHARED "Build shared library." ON) option(BUILD_STATIC "Build static library." OFF) if (NOT BUILD_STATIC AND NOT BUILD_SHARED) message(FATAL_ERROR "BUILD_SHARED and BUILD_STATIC cannot be both disabled") endif () # static library if (BUILD_STATIC) add_library(orcania_static STATIC ${LIB_SRC}) add_library(Orcania::Orcania-static ALIAS orcania_static) target_include_directories(orcania_static PUBLIC "$" PUBLIC "$" PUBLIC "$") target_link_libraries(orcania_static PRIVATE ${ORCANIA_LIBS}) target_compile_definitions(orcania_static PUBLIC O_STATIC_LIBRARY) set_target_properties(orcania_static PROPERTIES PUBLIC_HEADER "${INC_DIR}/orcania.h;${PROJECT_BINARY_DIR}/orcania-cfg.h" OUTPUT_NAME orcania EXPORT_NAME Orcania-static) if (MSVC) set_target_properties(orcania_static PROPERTIES OUTPUT_NAME orcania-static) endif () if (NOT MSVC) target_compile_options(orcania_static PRIVATE -Wextra -Wconversion) endif () set(orcania_lib orcania_static) endif () # shared library if (BUILD_SHARED) add_library(orcania SHARED ${LIB_SRC}) add_library(Orcania::Orcania ALIAS orcania) target_include_directories(orcania PUBLIC "$" PUBLIC "$" PUBLIC "$") target_link_libraries(orcania PRIVATE ${ORCANIA_LIBS}) set_target_properties(orcania PROPERTIES PUBLIC_HEADER "${INC_DIR}/orcania.h;${PROJECT_BINARY_DIR}/orcania-cfg.h" VERSION "${LIBRARY_VERSION}" SOVERSION "${LIBRARY_SOVERSION}" WINDOWS_EXPORT_ALL_SYMBOLS TRUE EXPORT_NAME Orcania) if (WIN32) set_target_properties(orcania PROPERTIES SUFFIX "-${LIBRARY_VERSION_MAJOR}.dll") endif () if (NOT MSVC) target_compile_options(orcania PRIVATE -Wextra -Wconversion) endif () set(orcania_lib orcania) endif () # documentation option(BUILD_ORCANIA_DOCUMENTATION "Build the documentation." OFF) if (BUILD_ORCANIA_DOCUMENTATION) find_package(Doxygen) if (DOXYGEN_FOUND) set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen.cfg) set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/doxyfile) configure_file(${doxyfile_in} ${doxyfile} @ONLY) add_custom_target(doc COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile_in} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Generating documentation with Doxygen" VERBATIM) else () message(FATAL_ERROR "Doxygen is needed to build the documentation.") endif () endif () # build base64url option(BUILD_BASE64URL "Build base64url application." ON) if (BUILD_BASE64URL) add_executable(base64url ${BASE64URL_DIR}/base64url.c ${INC_DIR}/orcania.h ${PROJECT_BINARY_DIR}/orcania-cfg.h) set_target_properties(base64url PROPERTIES SKIP_BUILD_RPATH TRUE) if (NOT MSVC) target_compile_options(base64url PRIVATE -Wextra -Wconversion) endif () target_link_libraries(base64url PRIVATE ${orcania_lib}) install(TARGETS base64url RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES ${BASE64URL_DIR}/base64url.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT runtime) endif () # tests option(BUILD_ORCANIA_TESTING "Build the testing tree." OFF) # because we do not use include(CTest) if (BUILD_ORCANIA_TESTING) find_package(Check) if (CHECK_FOUND) if (NOT WIN32 AND NOT APPLE) find_package(Subunit REQUIRED) endif () enable_testing() set(CMAKE_CTEST_COMMAND ctest -V) set(TST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test) set(TEST_LIBS ${orcania_lib} Check::Check) if (NOT WIN32) find_package(Threads REQUIRED) list(APPEND TEST_LIBS Threads::Threads m) endif () if (NOT APPLE AND NOT MSVC) list(APPEND TEST_LIBS rt) endif () if (NOT WIN32 AND NOT APPLE) list(APPEND TEST_LIBS Subunit::Subunit rt) endif () set(TESTS str_test split_test memory_test pointer_list_test) configure_file( "${O_CMAKE_MODULE_PATH}/CTestCustom.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake" @ONLY) foreach (t ${TESTS}) add_executable(${t} EXCLUDE_FROM_ALL ${TST_DIR}/${t}.c) target_include_directories(${t} PUBLIC ${TST_DIR}) target_link_libraries(${t} PRIVATE ${TEST_LIBS}) add_test(NAME ${t} WORKING_DIRECTORY ${TST_DIR} COMMAND ${t}) endforeach () endif () endif () # install target if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") set(PKGCONFIG_TARGET_INCLUDES "${CMAKE_INSTALL_INCLUDEDIR}") else() set(PKGCONFIG_TARGET_INCLUDES "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") endif() if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") set(PKGCONFIG_TARGET_LIBDIR "${CMAKE_INSTALL_LIBDIR}") else() set(PKGCONFIG_TARGET_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}") endif() option(INSTALL_HEADER "Install the header files" ON) # Install orcania.h or not configure_file(liborcania.pc.in liborcania.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/liborcania.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) set(TARGETS ) if (BUILD_SHARED) list(APPEND TARGETS orcania) endif () if (BUILD_STATIC) list(APPEND TARGETS orcania_static) endif () if (INSTALL_HEADER) install(TARGETS ${TARGETS} EXPORT OrcaniaExports RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) else () install(TARGETS ${TARGETS} EXPORT OrcaniaExports RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif () if (INSTALL_HEADER) set(ORCANIA_INSTALL_CMAKEDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}/cmake/Orcania") if (WIN32 AND NOT MINGW) set(ORCANIA_INSTALL_CMAKEDIR_DEFAULT "cmake") endif () set(ORCANIA_INSTALL_CMAKEDIR ${ORCANIA_INSTALL_CMAKEDIR_DEFAULT} CACHE STRING "Location where to install the cmake config files") install(EXPORT OrcaniaExports DESTINATION "${ORCANIA_INSTALL_CMAKEDIR}" NAMESPACE "Orcania::" FILE "OrcaniaTargets.cmake") configure_package_config_file(cmake-modules/OrcaniaConfig.cmake.in OrcaniaConfig.cmake INSTALL_DESTINATION "${ORCANIA_INSTALL_CMAKEDIR}") write_basic_package_version_file(OrcaniaConfigVersion.cmake COMPATIBILITY AnyNewerVersion) install(FILES "${PROJECT_BINARY_DIR}/OrcaniaConfig.cmake" "${PROJECT_BINARY_DIR}/OrcaniaConfigVersion.cmake" DESTINATION "${ORCANIA_INSTALL_CMAKEDIR}") endif () # uninstall target if (NOT TARGET uninstall) configure_file( "${O_CMAKE_MODULE_PATH}/CMakeUninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif () # packaging set(CPACK_PACKAGE_VERSION_MAJOR ${LIBRARY_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${LIBRARY_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${LIBRARY_VERSION_PATCH}) if (INSTALL_HEADER) set(PACKAGE_FILE_NAME "lib${CMAKE_PROJECT_NAME}-dev_${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") else () set(PACKAGE_FILE_NAME "lib${CMAKE_PROJECT_NAME}_${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") endif () set(PACKAGE_IGNORED_FILES "${CMAKE_CURRENT_BINARY_DIR}/;/.git/;.gitignore;~$;${CPACK_SOURCE_IGNORE_FILES}") set(CPACK_PACKAGE_NAME "liborcania") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Potluck for C programs") set(CPACK_GENERATOR "TGZ;DEB") set(CPACK_PACKAGE_VERSION_MAJOR ${LIBRARY_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${LIBRARY_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${LIBRARY_VERSION_PATCH}) option(BUILD_RPM "Build a RPM for your system" OFF) if (BUILD_RPM) set(CPACK_GENERATOR "TGZ;DEB;RPM") set(CPACK_RPM_PACKAGE_LICENSE "LGPL") set(CPACK_RPM_PACKAGE_URL "http://babelouest.github.io/orcania/") endif () set(CPACK_DEBIAN_PACKAGE_MAINTAINER "mail@babelouest.org") set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION}) set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/babelouest/orcania") set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.4)") set(CPACK_PACKAGE_FILE_NAME ${PACKAGE_FILE_NAME}) set(CPACK_PACKAGE_FILE_NAME ${PACKAGE_FILE_NAME}) set(CPACK_SOURCE_GENERATOR "TGZ") set(CPACK_SOURCE_PACKAGE_FILE_NAME ${PACKAGE_FILE_NAME}) set(CPACK_SOURCE_IGNORE_FILES ${PACKAGE_IGNORED_FILES}) include(CPack) add_custom_target(dist_o COMMAND ${CMAKE_MAKE_PROGRAM} package_source) message(STATUS "Force inline implementation of strstr: ${WITH_STRSTR}") message(STATUS "Build shared library: ${BUILD_SHARED}") message(STATUS "Build static library: ${BUILD_STATIC}") message(STATUS "Build testing tree: ${BUILD_ORCANIA_TESTING}") message(STATUS "Install the header files: ${INSTALL_HEADER}") message(STATUS "Build RPM package: ${BUILD_RPM}") message(STATUS "Build documentation: ${BUILD_ORCANIA_DOCUMENTATION}") message(STATUS "Build base64url application: ${BUILD_BASE64URL}") orcania-2.3.3/LICENSE000066400000000000000000000635351446552024700141650ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. (This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.) Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} Copyright (C) {year} {fullname} This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. {signature of Ty Coon}, 1 April 1990 Ty Coon, President of Vice That's all there is to it! orcania-2.3.3/Makefile000066400000000000000000000030521446552024700146040ustar00rootroot00000000000000# # Orcania Framework # # Makefile used to build all programs # # Copyright 2017-2022 Nicolas Mora # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License # as published by the Free Software Foundation; # version 2.1 of the License. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # # You should have received a copy of the GNU General Public # License along with this library. If not, see . # LIBORCANIA_LOCATION=./src TESTS_LOCATION=./test BASE64URL_LOCATION=./tools/base64url/ all: target target: cd $(LIBORCANIA_LOCATION) && $(MAKE) $* cd $(BASE64URL_LOCATION) && $(MAKE) $* debug: cd $(LIBORCANIA_LOCATION) && $(MAKE) debug $* cd $(BASE64URL_LOCATION) && $(MAKE) debug $* clean: cd $(LIBORCANIA_LOCATION) && $(MAKE) clean cd $(TESTS_LOCATION) && $(MAKE) clean cd $(BASE64URL_LOCATION) && $(MAKE) clean rm -rf doc/html/ check: cd $(LIBORCANIA_LOCATION) && $(MAKE) debug $* cd $(TESTS_LOCATION) && $(MAKE) test $* cd $(BASE64URL_LOCATION) && $(MAKE) test $* install: cd $(LIBORCANIA_LOCATION) && $(MAKE) install $* cd $(BASE64URL_LOCATION) && $(MAKE) install $* uninstall: cd $(LIBORCANIA_LOCATION) && $(MAKE) uninstall $* cd $(BASE64URL_LOCATION) && $(MAKE) uninstall $* doxygen: doxygen doc/doxygen.cfg release: target orcania-2.3.3/README.md000066400000000000000000000051261446552024700144270ustar00rootroot00000000000000# Orcania Potluck with different functions for different purposes that can be shared among C programs. ![.github/workflows/ccpp.yml](https://github.com/babelouest/orcania/workflows/.github/workflows/ccpp.yml/badge.svg) ## Documentation Library documentation is available in the [online documentation](https://babelouest.github.io/orcania/). ## Installation ### Distribution packages [![Packaging status](https://repology.org/badge/vertical-allrepos/orcania.svg)](https://repology.org/metapackage/orcania) Orcania is available in multiple distributions as official package. Check out your distribution documentation to install the package automatically. ### Pre-compiled packages You can install Orcania with a pre-compiled package available in the [release pages](https://github.com/babelouest/orcania/releases/latest/). ### Build from source Download Orcania source code from GitHub: ```shell $ git clone https://github.com/babelouest/orcania.git $ cd orcania ``` #### CMake - Multi architecture [CMake](https://cmake.org/download/) minimum 3.5 is required. Run the CMake script in a sub-directory, example: ```shell $ git clone https://github.com/babelouest/orcania.git $ cd orcania/ $ mkdir build $ cd build $ cmake .. $ make && sudo make install ``` The available options for CMake are: - `-DBUILD_STATIC=[on|off]` (default `off`): Build the static archive in addition to the shared library - `-DWITH_STRSTR=[on|off]` (default `off`): Force using inline implementation of strstr - `-DBUILD_ORCANIA_TESTING=[on|off]` (default `off`): Build unit tests - `-DINSTALL_HEADER=[on|off]` (default `on`): Install header file `orcania.h` - `-DBUILD_RPM=[on|off]` (default `off`): Build RPM package when running `make package` - `-DBUILD_ORCANIA_DOCUMENTATION=[on|off]` (default `off`): Build the documentation, doxygen is required - `-DCMAKE_BUILD_TYPE=[Debug|Release]` (default `Release`): Compile with debugging symbols or not #### Good ol' Makefile - Linux only Go to `src/` directory, compile and install: ```shell $ cd src $ make && sudo make install ``` This will install Orcania's files under `/usr/local/` DESTDIR. If you want to force using inline implementation of `strstr`, you can append the build option `STRSTRFLAG=1`. This is useful if your system doesn't have an implementation of the function `strstr` but isn't listed as one in Orcania. Like FreeRTOS. ``` $ cd src $ make STRSTRFLAG=1 ``` To build and install as a static archive, use the make commands `make static*`: ```shell $ cd src $ make static && sudo make static-install # or make DESTDIR=/tmp static-install if you want to install in `/tmp/lib` ``` orcania-2.3.3/_config.yml000066400000000000000000000000311446552024700152650ustar00rootroot00000000000000theme: jekyll-theme-slateorcania-2.3.3/cmake-modules/000077500000000000000000000000001446552024700156725ustar00rootroot00000000000000orcania-2.3.3/cmake-modules/CMakeUninstall.cmake.in000066400000000000000000000020641446552024700221550ustar00rootroot00000000000000if (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") endif (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) string(REGEX REPLACE "\n" ";" files "${files}") foreach (file ${files}) message(STATUS "Uninstalling $ENV{DESTDIR}${file}") if (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") exec_program( "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" OUTPUT_VARIABLE rm_out RETURN_VALUE rm_retval ) if (NOT "${rm_retval}" STREQUAL 0) message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") endif (NOT "${rm_retval}" STREQUAL 0) else (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") message(STATUS "File $ENV{DESTDIR}${file} does not exist.") endif (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") endforeach (file) orcania-2.3.3/cmake-modules/CTestCustom.cmake.in000066400000000000000000000001421446552024700215130ustar00rootroot00000000000000string(REPLACE ";" " " TESTS "@TESTS@") set(CTEST_CUSTOM_PRE_TEST "@CMAKE_MAKE_PROGRAM@ ${TESTS}")orcania-2.3.3/cmake-modules/FindCheck.cmake000066400000000000000000000054631446552024700205220ustar00rootroot00000000000000#.rst: # FindCheck # ----------- # # Find Check # # Find Check headers and libraries. # # :: # # CHECK_FOUND - True if Check found. # CHECK_INCLUDE_DIRS - Where to find check.h. # CHECK_LIBRARIES - List of libraries when using Check. # CHECK_VERSION_STRING - The version of Check found. #============================================================================= # Copyright 2018 Silvio Clecio # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License # as published by the Free Software Foundation; # version 2.1 of the License. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # # You should have received a copy of the GNU General Public # License along with this library. If not, see . #============================================================================= # Sat Jan 20 23:33:47 -03 2018 find_package(PkgConfig QUIET) pkg_check_modules(PC_CHECK QUIET check) find_path(CHECK_INCLUDE_DIR NAMES check.h HINTS ${PC_CHECK_INCLUDEDIR} ${PC_CHECK_INCLUDE_DIRS}) find_library(CHECK_LIBRARY NAMES check libcheck HINTS ${PC_CHECK_LIBDIR} ${PC_CHECK_LIBRARY_DIRS}) if (PC_CHECK_VERSION) set(CHECK_VERSION_STRING ${PC_CHECK_VERSION}) elseif (CHECK_INCLUDE_DIR AND EXISTS "${CHECK_INCLUDE_DIR}/check.h") set(check_version_list MAJOR MINOR MICRO) foreach (v ${check_version_list}) set(regex_check_version "^#define CHECK_${v}_VERSION +\\(?([0-9]+)\\)?$") file(STRINGS "${CHECK_INCLUDE_DIR}/check.h" check_version_${v} REGEX "${regex_check_version}") string(REGEX REPLACE "${regex_check_version}" "\\1" check_version_${v} "${check_version_${v}}") unset(regex_check_version) endforeach () set(CHECK_VERSION_STRING "${check_version_MAJOR}.${check_version_MINOR}.${check_version_MICRO}") foreach (v check_version_list) unset(check_version_${v}) endforeach () unset(check_version_list) endif () include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Check REQUIRED_VARS CHECK_LIBRARY CHECK_INCLUDE_DIR VERSION_VAR CHECK_VERSION_STRING) if (CHECK_FOUND) set(CHECK_LIBRARIES ${CHECK_LIBRARY}) set(CHECK_INCLUDE_DIRS ${CHECK_INCLUDE_DIR}) if (NOT TARGET Check::Check) add_library(Check::Check IMPORTED UNKNOWN) set_target_properties(Check::Check PROPERTIES IMPORTED_LOCATION "${CHECK_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${CHECK_INCLUDE_DIR}") endif () endif () mark_as_advanced(CHECK_INCLUDE_DIR CHECK_LIBRARY)orcania-2.3.3/cmake-modules/FindSubunit.cmake000066400000000000000000000043041446552024700211270ustar00rootroot00000000000000#.rst: # FindSubunit # ----------- # # Find Subunit # # Find Subunit headers and libraries. # # :: # # SUBUNIT_FOUND - True if Subunit found. # SUBUNIT_INCLUDE_DIRS - Where to find subunit/child.h. # SUBUNIT_LIBRARIES - List of libraries when using Subunit. # SUBUNIT_VERSION_STRING - The version of Subunit found. #============================================================================= # Copyright 2018 Silvio Clecio # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License # as published by the Free Software Foundation; # version 2.1 of the License. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # # You should have received a copy of the GNU General Public # License along with this library. If not, see . #============================================================================= # Fri Jan 19 22:27:51 -03 2018 find_package(PkgConfig QUIET) pkg_check_modules(PC_SUBUNIT QUIET libsubunit) set(SUBUNIT_VERSION_STRING "${PC_SUBUNIT_VERSION}") find_path(SUBUNIT_INCLUDE_DIR NAMES child.h HINTS ${PC_SUBUNIT_INCLUDEDIR} ${PC_SUBUNIT_INCLUDE_DIRS} PATH_SUFFIXES subunit) find_library(SUBUNIT_LIBRARY NAMES subunit libsubunit HINTS ${PC_SUBUNIT_LIBDIR} ${PC_SUBUNIT_LIBRARY_DIRS}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Subunit REQUIRED_VARS SUBUNIT_LIBRARY SUBUNIT_INCLUDE_DIR VERSION_VAR SUBUNIT_VERSION_STRING) if (SUBUNIT_FOUND) set(SUBUNIT_LIBRARIES ${SUBUNIT_LIBRARY}) set(SUBUNIT_INCLUDE_DIRS ${SUBUNIT_INCLUDE_DIR}) if (NOT TARGET Subunit::Subunit) add_library(Subunit::Subunit IMPORTED UNKNOWN) set_target_properties(Subunit::Subunit PROPERTIES IMPORTED_LOCATION "${SUBUNIT_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${SUBUNIT_INCLUDE_DIR}") endif () endif () mark_as_advanced(SUBUNIT_INCLUDE_DIR SUBUNIT_LIBRARY)orcania-2.3.3/cmake-modules/OrcaniaConfig.cmake.in000066400000000000000000000010121446552024700217750ustar00rootroot00000000000000@PACKAGE_INIT@ include("${CMAKE_CURRENT_LIST_DIR}/OrcaniaTargets.cmake") if(TARGET Orcania::Orcania-static) set(ORCANIA_INCLUDE_DIRS $) set(ORCANIA_LIBRARIES Orcania::Orcania-static) endif() if(TARGET Orcania::Orcania) set(ORCANIA_INCLUDE_DIRS $) set(ORCANIA_LIBRARIES Orcania::Orcania) endif() set(ORCANIA_VERSION_STRING "@PROJECT_VERSION@") set(Orcania_FOUND TRUE) orcania-2.3.3/doc/000077500000000000000000000000001446552024700137115ustar00rootroot00000000000000orcania-2.3.3/doc/doxygen.cfg000066400000000000000000000052621446552024700160540ustar00rootroot00000000000000# Doxyfile 1.9.1 PROJECT_NAME = Orcania PROJECT_BRIEF = "Potluck with different functions for different purposes that can be shared among C programs" INPUT = API.md \ ./src/ \ ./include/ \ tools/base64url/README.md USE_MDFILE_AS_MAINPAGE = API.md #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 OUTPUT_DIRECTORY = doc CREATE_SUBDIRS = NO ALLOW_UNICODE_NAMES = NO OUTPUT_LANGUAGE = English BRIEF_MEMBER_DESC = YES REPEAT_BRIEF = YES ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ "The $name file" \ is \ provides \ specifies \ contains \ represents \ a \ an \ the TAB_SIZE = 4 OPTIMIZE_OUTPUT_FOR_C = YES OPTIMIZE_OUTPUT_JAVA = NO OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_OUTPUT_VHDL = NO OPTIMIZE_OUTPUT_SLICE = NO #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- EXTRACT_ALL = YES EXTRACT_PRIVATE = NO #--------------------------------------------------------------------------- # Configuration options related to the input files #--------------------------------------------------------------------------- INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.c \ *.h \ *.md RECURSIVE = YES #--------------------------------------------------------------------------- # Configuration options related to the HTML output #--------------------------------------------------------------------------- GENERATE_HTML = YES HTML_OUTPUT = html HTML_FILE_EXTENSION = .html HTML_COLORSTYLE_HUE = 220 HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_GAMMA = 80 HTML_TIMESTAMP = NO HTML_DYNAMIC_MENUS = YES HTML_DYNAMIC_SECTIONS = NO GENERATE_LATEX = NO GENERATE_RTF = NO GENERATE_MAN = NO GENERATE_XML = NO GENERATE_DOCBOOK = NO GENERATE_AUTOGEN_DEF = NO GENERATE_PERLMOD = NO ENABLE_PREPROCESSING = YES MACRO_EXPANSION = NO EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES HAVE_DOT = NO orcania-2.3.3/include/000077500000000000000000000000001446552024700145675ustar00rootroot00000000000000orcania-2.3.3/include/orcania-cfg.h.in000066400000000000000000000024731446552024700175240ustar00rootroot00000000000000/** * * Orcania library * * Different functions for different purposes but that can be shared between * other projects * * orcania-cfg.h.in: configuration file * * Copyright 2018-2022 Nicolas Mora * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU General Public * License along with this library. If not, see . * */ #ifndef _ORCANIA_CFG_H_ #define _ORCANIA_CFG_H_ #define ORCANIA_VERSION ${PROJECT_VERSION} #define ORCANIA_VERSION_STR "${PROJECT_VERSION}" #define ORCANIA_VERSION_MAJOR ${PROJECT_VERSION_MAJOR} #define ORCANIA_VERSION_MINOR ${PROJECT_VERSION_MINOR} #define ORCANIA_VERSION_PATCH ${PROJECT_VERSION_PATCH} #define ORCANIA_VERSION_NUMBER ((ORCANIA_VERSION_MAJOR << 16) | (ORCANIA_VERSION_MINOR << 8) | (ORCANIA_VERSION_PATCH << 0)) #cmakedefine O_STRSTR #endif /* _ORCANIA_CFG_H_ */ orcania-2.3.3/include/orcania.h000066400000000000000000000562701446552024700163660ustar00rootroot00000000000000/** * * @file orcania.h * @brief Orcania library * * Different functions for different purposes but that can be shared between * other projects * * orcania.h: public header file * * Copyright 2015-2022 Nicolas Mora * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU General Public * License along with this library. If not, see . * */ #ifndef __ORCANIA_H__ #define __ORCANIA_H__ #ifdef __cplusplus extern "C" { #endif #include "orcania-cfg.h" #include #include struct _o_datum { size_t size; unsigned char * data; }; /** * @defgroup str string functions * These functions are used for string manipulation * Types of functions available: * - crash safe version of library * - build heap allocated strings using printf-like format * @{ */ /** * char * str_replace(const char * source, char * old, char * new) * replace all occurences of old by new in the string source * return a char * with the new value * @param source: the source string * @param str_old string to be replaced in source * @param str_new new string to replace * @return a heap-allocated string with the replacements applied * return NULL on error * returned value must be free'd after use */ char * str_replace(const char * source, const char * str_old, const char * str_new); /** * o_strdup * a modified strdup function that don't crash when source is NULL, instead return NULL * @param source the source string to duplicate * @return a heap-allocated string * Returned value must be free'd after use */ char * o_strdup(const char * source); /** * o_strndup * a modified strndup function that don't crash when source is NULL, instead return NULL * @param source the source string to duplicate * @param len the maximum length of the string source to duplicate * @return a heap-allocated string * Returned value must be free'd after use */ char * o_strndup(const char * source, size_t len); /** * o_strcmp * a modified strcmp function that don't crash when p1 is NULL or p2 us NULL * @param p1 the first string to compare * @param p2 the second string to compare * @return 0 if p1 is equal to p2, negative number if p1 is inferior to p2, positive number otherwise */ int o_strcmp(const char * p1, const char * p2); /** * o_strncmp * a modified strncmp function that don't crash when p1 is NULL or p2 us NULL * @param p1 the first string to compare * @param p2 the second string to compare * @param n the maximum number of char to compare * @return 0 if p1 is equal to p2, negative number if p1 is inferior to p2, positive number otherwise */ int o_strncmp(const char * p1, const char * p2, size_t n); /** * o_strcpy * a modified strcpy function that don't crash when p1 is NULL or p2 us NULL * @param p1 the string to copy p2 * @param p2 the source string to be copied * @return p1 */ char * o_strcpy(char * p1, const char * p2); /** * o_strncpy * @param p1 the string to copy p2 * @param p2 the source string to be copied * @param n the maximum characters to copy from p2 to p1 * @return p1 * a modified strncpy function that don't crash when p1 is NULL or p2 us NULL */ char * o_strncpy(char * p1, const char * p2, size_t n); /** * o_strcasecmp * a modified strcasecmp function that don't crash when p1 is NULL or p2 us NULL * @param p1 the first string to compare * @param p2 the second string to compare * @return 0 if p1 is equal to p2, negative number if p1 is inferior to p2, positive number otherwise */ int o_strcasecmp(const char * p1, const char * p2); /** * o_strncasecmp * a modified strncasecmp function that don't crash when p1 is NULL or p2 us NULL * @param p1 the first string to compare * @param p2 the second string to compare * @param n the maximum number of char to compare * @return 0 if p1 is equal to p2, negative number if p1 is inferior to p2, positive number otherwise */ int o_strncasecmp(const char * p1, const char * p2, size_t n); /** * o_strstr * a modified strstr function that don't crash when haystack is NULL or needle us NULL * @param haystack the string to be looked for * @param needle the string to search in haystack * @return the pointer to the first occurence of needle in haystack or NULL if not found */ char * o_strstr(const char * haystack, const char * needle); /** * o_strnstr * a modified strnstr function that don't crash when haystack is NULL or needle us NULL * @param haystack the string to be looked for * @param needle the string to search in haystack * @param len the maximum length to look for in haystack * @return the pointer to the first occurence of needle in haystack or NULL if not found */ char * o_strnstr(const char * haystack, const char * needle, size_t len); /** * o_strcasestr * a modified strcasestr function that don't crash when haystack is NULL or needle us NULL * @param haystack the string to be looked for * @param needle the string to search in haystack * @return the pointer to the first occurence of needle in haystack or NULL if not found */ char * o_strcasestr(const char * haystack, const char * needle); /** * o_strchr * a modified strchr function that don't crash when haystack is NULL * @param haystack the string to be looked for * @param c the character to look for in haystack * @return the pointer to the first occurence of c in haystack or NULL if not found */ char * o_strchr(const char * haystack, int c); /** * o_strnchr * a modified strnchr function that don't crash when haystack is NULL * @param haystack the string to be looked for * @param len the maxmimum length of characters to look for in haystack * @param c the character to look for in haystack * @return the pointer to the first occurence of c in haystack or NULL if not found */ const char * o_strnchr(const char * haystack, size_t len, char c); /** * o_strrchr * a modified strrchr function that don't crash when haystack is NULL * @param haystack the string to be looked for * @param c the character to look for in haystack * @return the pointer to the last occurence of c in haystack or NULL if not found */ char * o_strrchr(const char * haystack, int c); /** * o_strrnchr * a modified strrnchr function that don't crash when haystack is NULL * @param haystack the string to be looked for * @param len the maxmimum length of characters to look for in haystack * @param c the character to look for in haystack * @return the pointer to the last occurence of c in haystack or NULL if not found */ const char * o_strrnchr(const char * haystack, size_t len, char c); /** * o_strnullempty * return true if s is NULL or empty string, false otherwise */ int o_strnullempty(const char * s); /** * o_strlen * a modified version of strlen that don't crash when s is NULL * @param s the string to calculate length * @return the length of s, 0 if s is NULL */ size_t o_strlen(const char * s); /** * Remove string of beginning and ending whitespaces * the string str will be modified * @param str the string to trim * @return the trimmed str */ const char * trimwhitespace(char * str); /** * Remove string of beginning and ending given character * the string str will be modified * @param str the string to trim * @param to_remove the character to trim * @return the trimmed str */ char * trimcharacter(char * str, char to_remove); /** * char * msprintf(const char * message, ...) * Implementation of sprintf that return a malloc'd char * with the string construction * because life is too short to use 3 lines instead of 1 * but don't forget to free the returned value after use! * Disclaimer: When I made this function, I didn't know * asprintf existed. If I did I surely wouldn't make msprintf * although, msprintf has the advantage to work with o_malloc and o_free * so it can use specific memory allocation functions * @param message the message format to concat to source, printf format * @return a heap-allocated char * containing the result string */ char * msprintf(const char * message, ...); /** * char * mstrcatf((char * source, const char * message, ...) * A combination of strcat and msprintf that will concat source and message formatted * and return the combination as a new allocated char * * and will o_free source * but don't forget to free the returned value after use! * @param source the source string to concat message, source will be free'd during the process * @param message the message format to concat to source, printf format * @return a heap-allocated char * containing the result string */ char * mstrcatf(char * source, const char * message, ...); /** * @} */ /** * @defgroup split split string and string array functions * @{ */ /** * Split a string into an array of strings using separator string * return the number of elements to be returned, 0 on error * @param string the string to split * @param separator the string separator, will not be included in the result * @param return_array an reference to a char ** that will be heap-allocated by the function * The last element in return_array will be NULL * @return the number of string elements in result_array * if return_array is not NULL, set the returned array in it * return_array is an array of char * ending with a NULL value * return_array must be free'd after use * you can use free_string_array to free return_array */ size_t split_string(const char * string, const char * separator, char *** return_array); /** * Clean an array of strings * @param array an array of char * to free using o_free for each element * the last element of array must be a NULL */ void free_string_array(char ** array); /** * Count the number of elements in an array of strings * @param array an array of char * with NULL in the last element * @return the number of string elements in array */ size_t string_array_size(char ** array); /** * Check if an array of string has a specified value, case sensitive * @param array an array of char * with NULL in the last element * @param needle the value to look for in array * @return 1 if needle exists in array, 0 otherwise */ int string_array_has_value(const char ** array, const char * needle); /** * Check if an array of string has a specified value, case insensitive * @param array an array of char * with NULL in the last element * @param needle the value to look for in array * @return 1 if needle exists in array, 0 otherwise */ int string_array_has_value_case(const char ** array, const char * needle); /** * Check if an array of string has a specified value, case sensitive, limit to len characters * @param array an array of char * with NULL in the last element * @param needle the value to look for in array * @param len the length of needle * @return 1 if needle exists in array, 0 otherwise */ int string_array_has_value_n(const char ** array, const char * needle, size_t len); /** * Check if an array of string has a specified value, case insensitive, limit to len characters * @param array an array of char * with NULL in the last element * @param needle the value to look for in array * @param len the length of needle * @return 1 if needle exists in array, 0 otherwise */ int string_array_has_value_ncase(const char ** array, const char * needle, size_t len); /** * Check if an array of string has a specified trimmed value * @param array an array of char * with NULL in the last element * @param needle the value to look for in array * @return 1 if needle exists in array, 0 otherwise */ int string_array_has_trimmed_value(const char ** array, const char * needle); /** * Join a string array into a single string * @param array an array of char * with NULL in the last element * @param separator a string to put between the elements * @return a heap allocated string */ char * string_array_join(const char ** array, const char * separator); /** * @} */ /** * @defgroup plist _pointer_list structure * @{ */ struct _pointer_list { size_t size; /* size of the list */ void ** list; /* list of pointers */ }; /** * pointer_list_init * Initialize a pointer list structure * @param pointer_list a pointer list to initialize */ void pointer_list_init(struct _pointer_list * pointer_list); /** * pointer_list_clean * Clean a pointer list structure * @param pointer_list a pointer list to clean */ void pointer_list_clean(struct _pointer_list * pointer_list); /** * pointer_list_clean_free * Clean a pointer list structure * Free all elements using the free_function given in parameters * @param pointer_list a pointer list to clean * @param free_function a function to use for freeing values */ void pointer_list_clean_free(struct _pointer_list * pointer_list, void (* free_function)(void * elt)); /** * pointer_list_size * @param pointer_list a pointer list * @return the size of a pointer list */ size_t pointer_list_size(struct _pointer_list * pointer_list); /** * pointer_list_append * Appends an element at the end of a pointer list * @param pointer_list a pointer list * @param element an element to append * @return 1 on success, 0 on error */ int pointer_list_append(struct _pointer_list * pointer_list, void * element); /** * pointer_list_get_at * @param pointer_list a pointer list * @param index the index of the element in pointer_list * @return an element of a pointer list at the specified index or NULL if non valid index */ void * pointer_list_get_at(struct _pointer_list * pointer_list, size_t index); /** * pointer_list_remove_at * Removes an element of a pointer list at the specified index * @param pointer_list a pointer list * @param index the index of the element in pointer_list * @return 1 on success, 0 on error or non valid index */ int pointer_list_remove_at(struct _pointer_list * pointer_list, size_t index); /** * pointer_list_remove_at_free * Removes an element of a pointer list at the specified index * Free the element using the free_function given in parameters * @param pointer_list a pointer list * @param index the index of the element in pointer_list * @param free_function the function to use to free the element * @return 1 on success, 0 on error or non valid index */ int pointer_list_remove_at_free(struct _pointer_list * pointer_list, size_t index, void (* free_function)(void * elt)); /** * pointer_list_insert_at * Inserts an element at the specified index of a pointer list * @param pointer_list a pointer list * @param element the element to set at index * @param index the index of the element in pointer_list * @return 1 on success, 0 on error or non valid inde */ int pointer_list_insert_at(struct _pointer_list * pointer_list, void * element, size_t index); /** * pointer_list_remove_pointer * Removes an element of a pointer list corresponding to the specified element * @param pointer_list a pointer list * @param element the element to set at index * @return 1 on success, 0 on error or non valid inde */ int pointer_list_remove_pointer(struct _pointer_list * pointer_list, void * element); /** * pointer_list_remove_pointer_free * Removes an element of a pointer list corresponding to the specified element * Free the element using the free_function given in parameters * @param pointer_list a pointer list * @param element the element to set at index * @param free_function the function to use to free the element * @return 1 on success, 0 on error or non valid inde */ int pointer_list_remove_pointer_free(struct _pointer_list * pointer_list, void * element, void (* free_function)(void * elt)); /** * @} */ /** * @defgroup mem Memory functions * @{ */ /* C89 allows these to be macros */ #undef malloc #undef realloc #undef free /** * typedefs use to replace glib's memory functions */ typedef void *(*o_malloc_t)(size_t); typedef void *(*o_realloc_t)(void *, size_t); typedef void (*o_free_t)(void *); /** * Allocate a memory block * @param size the size of the block to allocate in memory * @return a pointer to the new allocated block */ void * o_malloc(size_t size); /** * Reallocate a memory block * @param ptr the previous memory block that will be free'd * @param size the size of the block to allocate in memory * @return a pointer to the new allocated block with a copy of the data previously in ptr */ void * o_realloc(void * ptr, size_t size); /** * Free a block allocated by o_malloc */ void o_free(void * ptr); /** * Updates the memory functions by user-specific ones * @param malloc_fn a pointer to a malloc function, if NULL, will use current function * @param realloc_fn a pointer to a realloc function, if NULL, will use current function * @param free_fn a pointer to a free function, if NULL, will use current function */ void o_set_alloc_funcs(o_malloc_t malloc_fn, o_realloc_t realloc_fn, o_free_t free_fn); /** * Gets the pointer to current memory functions * @param malloc_fn reference to a pointer to a malloc function * @param realloc_fn reference to a pointer to a realloc function * @param free_fn reference to a pointer to a free function */ void o_get_alloc_funcs(o_malloc_t * malloc_fn, o_realloc_t * realloc_fn, o_free_t * free_fn); /** * @} */ /** * @defgroup base64 Base64 encode and decode functions * @{ */ /** * o_base64_encode - Base64 encode * @param src Data to be encoded * @param len Length of the data to be encoded * @param out Pointer to output variable, you might add up to 2 bytes to out length than expected for safety * @param out_len Pointer to output length variable * @return 1 on success, 0 on failure * * The nul terminator is not included in out_len. */ int o_base64_encode(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len); /** * o_base64_decode - Base64 decode * @param src Data to be decoded * @param len Length of the data to be decoded * @param out Pointer to output variable, you might add up to 2 bytes to out length than expected for safety * @param out_len Pointer to output length variable * @return 1 on success, 0 on failure * * The nul terminator is not included in out_len. */ int o_base64_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len); /** * o_base64url_encode - Base64url encode (url format) * @param src Data to be encoded * @param len Length of the data to be encoded * @param out Pointer to output variable, you might add up to 2 bytes to out length than expected for safety * @param out_len Pointer to output length variable * @return 1 on success, 0 on failure * * The nul terminator is not included in out_len. */ int o_base64url_encode(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len); /** * o_base64url_decode - Base64 decode (url format) * @param src Data to be decoded * @param len Length of the data to be decoded * @param out Pointer to output variable, you might add up to 2 bytes to out length than expected for safety * @param out_len Pointer to output length variable * @return 1 on success, 0 on failure * * The nul terminator is not included in out_len. */ int o_base64url_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len); /** * o_base64url_2_base64 - Convert a base64 url format to base64 format - Does not check if src is a valid base64 * @param src Data to be decoded * @param len Length of the data to be decoded * @param out Pointer to output variable * @param out_len Pointer to output length variable * @return 1 on success, 0 on failure * * The nul terminator is not included in out_len. * out must be at least len+2 */ int o_base64url_2_base64(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len); /** * o_base64_2_base64url - Convert a base64 url format to base64 format - Does not check if src is a valid base64url * @param src Data to be decoded * @param len Length of the data to be decoded * @param out Pointer to output variable * @param out_len Pointer to output length variable * @return 1 on success, 0 on failure * * The nul terminator is not included in out_len. * out must be at least len+2 */ int o_base64_2_base64url(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len); /** * o_base64_encode_alloc - Base64 encode - allocate data result in a struct _o_datum * * @param src Data to be encoded * @param len Length of the data to be encoded * @param dat Pointer to a struct _o_datum * to store result * @return 1 on success, 0 on failure * * dat->data must be o_free'd after use * The nul terminator is not included in dat->data. */ int o_base64_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); /** * o_base64_decode_alloc - Base64 decode - allocate data result in a struct _o_datum * * @param src Data to be decoded * @param len Length of the data to be decoded * @param dat Pointer to a struct _o_datum * to store result * @return 1 on success, 0 on failure * * dat->data must be o_free'd after use * The nul terminator is not included in dat->data. */ int o_base64_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); /** * o_base64url_encode_alloc - Base64url encode (url format) - allocate data result in a struct _o_datum * * @param src Data to be encoded * @param len Length of the data to be encoded * @param dat Pointer to a struct _o_datum * to store result * @return 1 on success, 0 on failure * * dat->data must be o_free'd after use * The nul terminator is not included in dat->data. */ int o_base64url_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); /** * o_base64url_decode_alloc - Base64 decode (url format) - allocate data result in a struct _o_datum * * @param src Data to be decoded * @param len Length of the data to be decoded * @param dat Pointer to a struct _o_datum * to store result * @return 1 on success, 0 on failure * * dat->data must be o_free'd after use * The nul terminator is not included in dat->data. */ int o_base64url_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); /** * o_base64url_2_base64_alloc - Convert a base64 url format to base64 format - allocate data result in a struct _o_datum * * @param src Data to be decoded * @param len Length of the data to be decoded * @param dat Pointer to a struct _o_datum * to store result * @return 1 on success, 0 on failure * * dat->data must be o_free'd after use * The nul terminator is not included in dat->data. */ int o_base64url_2_base64_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); /** * o_base64_2_base64url_alloc - Convert a base64 format to base64 url format - allocate data result in a struct _o_datum * * @param src Data to be decoded * @param len Length of the data to be decoded * @param dat Pointer to a struct _o_datum * to store result * @return 1 on success, 0 on failure * * dat->data must be o_free'd after use * The nul terminator is not included in dat->data. */ int o_base64_2_base64url_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); /** * @} */ #ifdef __cplusplus } #endif #endif // __ORCANIA_H__ orcania-2.3.3/liborcania.pc.in000066400000000000000000000005741446552024700162060ustar00rootroot00000000000000prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ libdir=@PKGCONFIG_TARGET_LIBDIR@ includedir=@PKGCONFIG_TARGET_INCLUDES@ Name: @PROJECT_NAME@ Description: @PROJECT_DESCRIPTION@ URL: @PROJECT_BUGREPORT_PATH@ Version: @LIBRARY_VERSION@ Requires: @PKGCONF_REQ@ Requires.private: @PKGCONF_REQ_PRIVATE@ Libs: -L${libdir} -lorcania @LIB_STATIC@ Cflags: -I${includedir} orcania-2.3.3/src/000077500000000000000000000000001446552024700137335ustar00rootroot00000000000000orcania-2.3.3/src/Makefile000066400000000000000000000117221446552024700153760ustar00rootroot00000000000000# # Orcania Library # # Makefile used to build the software # # Copyright 2014-2022 Nicolas Mora # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License # as published by the Free Software Foundation; # version 2.1 of the License. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # # You should have received a copy of the GNU General Public # License along with this library. If not, see . # PROJECT_NAME=orcania PROJECT_DESCRIPTION=Potluck with different functions for different purposes that can be shared among programs PROJECT_BUGREPORT_PATH=https://github.com/babelouest/orcania/issues PKGCONF_REQ= PKGCONF_REQ_PRIVATE= DESTDIR=/usr/local ORCANIA_INCLUDE=../include CONFIG_TEMPLATE=$(ORCANIA_INCLUDE)/orcania-cfg.h.in CONFIG_FILE=$(ORCANIA_INCLUDE)/orcania-cfg.h PKGCONFIG_FILE=../liborcania.pc PKGCONFIG_TEMPLATE=../liborcania.pc.in CC=gcc CFLAGS+=-c -fPIC -Wall -Werror -Wextra -Wpedantic -Wconversion -I$(ORCANIA_INCLUDE) -D_REENTRANT $(ADDITIONALFLAGS) $(CPPFLAGS) OUTPUT=liborcania.so VERSION_MAJOR=2 VERSION_MINOR=3 VERSION_PATCH=3 OBJECTS=orcania.o memory.o base64.o LIBSDEP=-lm LIBS=-lc SONAME = -soname ifeq ($(shell uname -s),Darwin) SONAME = -install_name endif ifdef STRSTRFLAG STRSTR=1 else STRSTR=0 endif all: release $(CONFIG_FILE): @cp $(CONFIG_TEMPLATE) $(CONFIG_FILE) @echo Config file $(CONFIG_FILE) generated @sed -i -e 's/$${PROJECT_VERSION}/$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)/g' $(CONFIG_FILE) @sed -i -e 's/$${PROJECT_VERSION_MAJOR}/$(VERSION_MAJOR)/g' $(CONFIG_FILE) @sed -i -e 's/$${PROJECT_VERSION_MINOR}/$(VERSION_MINOR)/g' $(CONFIG_FILE) @sed -i -e 's/$${PROJECT_VERSION_PATCH}/$(VERSION_PATCH)/g' $(CONFIG_FILE) @sed -i -e 's/$${PROJECT_VERSION_NUMBER}/$(shell printf '%02d' $(VERSION_MAJOR))$(shell printf '%02d' $(VERSION_MINOR))$(shell printf '%02d' $(VERSION_PATCH))/g' $(CONFIG_FILE) @if [ "$(STRSTR)" = "1" ]; then \ sed -i -e 's/\#cmakedefine O_STRSTR/\#define O_STRSTR/g' $(CONFIG_FILE); \ echo "FORCE IMPLEMENT STRSTR ENABLED"; \ else \ sed -i -e 's/\#cmakedefine O_STRSTR/\/* #undef O_STRSTR *\//g' $(CONFIG_FILE); \ echo "FORCE IMPLEMENT STRSTR DISABLED"; \ fi $(PKGCONFIG_FILE): @cp $(PKGCONFIG_TEMPLATE) $(PKGCONFIG_FILE) @echo Pkgconfig file $(PKGCONFIG_FILE) generated @sed -i -e 's#@CMAKE_INSTALL_PREFIX@#$(DESTDIR)#g' $(PKGCONFIG_FILE) @sed -i -e 's#@PKGCONFIG_TARGET_LIBDIR@#$${prefix}/lib#g' $(PKGCONFIG_FILE) @sed -i -e 's#@PKGCONFIG_TARGET_INCLUDES@#$${prefix}/include#g' $(PKGCONFIG_FILE) @sed -i -e 's/@PROJECT_NAME@/$(PROJECT_NAME)/g' $(PKGCONFIG_FILE) @sed -i -e 's/@PROJECT_DESCRIPTION@/$(PROJECT_DESCRIPTION)/g' $(PKGCONFIG_FILE) @sed -i -e 's|@PROJECT_BUGREPORT_PATH@|$(PROJECT_BUGREPORT_PATH)|g' $(PKGCONFIG_FILE) @sed -i -e 's/@LIBRARY_VERSION@/$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)/g' $(PKGCONFIG_FILE) @sed -i -e 's/@PKGCONF_REQ@/$(PKGCONF_REQ)/g' $(PKGCONFIG_FILE) @sed -i -e 's/@PKGCONF_REQ_PRIVATE@/$(PKGCONF_REQ_PRIVATE)/g' $(PKGCONFIG_FILE) @sed -i -e 's/@LIB_STATIC@/$(LIB_STATIC)/g' $(PKGCONFIG_FILE) liborcania.so: $(OBJECTS) $(PKGCONFIG_FILE) $(CC) -shared -fPIC -Wl,$(SONAME),$(OUTPUT) -o $(OUTPUT).$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) $(OBJECTS) $(LIBS) $(LIBSDEP) $(LDFLAGS) ln -sf $(OUTPUT).$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) $(OUTPUT) liborcania.a: $(OBJECTS) $(PKGCONFIG_FILE) ar rcs liborcania.a $(OBJECTS) %.o: %.c $(CONFIG_FILE) ../include/orcania.h $(CC) $(CFLAGS) $< clean: rm -f *.o *.so *.a $(OUTPUT) $(OUTPUT).* $(CONFIG_FILE) $(PKGCONFIG_FILE) install: all install $(OUTPUT).$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) $(DESTDIR)/lib mkdir -p $(DESTDIR)/lib/pkgconfig/ $(DESTDIR)/include install -m644 $(PKGCONFIG_FILE) $(DESTDIR)/lib/pkgconfig/ install -m644 ../include/orcania.h $(DESTDIR)/include install -m644 $(CONFIG_FILE) $(DESTDIR)/include -ldconfig $(DESTDIR)/lib static-install: static install liborcania.a $(DESTDIR)/lib mkdir -p $(DESTDIR)/lib/pkgconfig/ $(DESTDIR)/include install -m644 $(PKGCONFIG_FILE) $(DESTDIR)/lib/pkgconfig install -m644 ../include/orcania.h $(DESTDIR)/include install -m644 $(CONFIG_FILE) $(DESTDIR)/include uninstall: rm -f $(DESTDIR)/lib/$(OUTPUT) $(DESTDIR)/lib/liborcania.a rm -f $(DESTDIR)/lib/$(OUTPUT).* rm -f $(DESTDIR)/include/orcania.h rm -f $(DESTDIR)/include/$(CONFIG_FILE) rm -f $(DESTDIR)/lib/pkgconfig/$(PKGCONFIG_FILE) debug: ADDITIONALFLAGS=-DDEBUG -g -O0 debug: liborcania.so release: ADDITIONALFLAGS=-O3 release: liborcania.so static-debug: ADDITIONALFLAGS=-DDEBUG -g -O0 static-debug: liborcania.a static-debug: LIB_STATIC=$(LIBSDEP) static: ADDITIONALFLAGS=-O3 static: liborcania.a static: LIB_STATIC=$(LIBSDEP) orcania-2.3.3/src/base64.c000066400000000000000000000211561446552024700151700ustar00rootroot00000000000000/* * Base64 encoding/decoding (RFC1341) * Copyright (c) 2005-2011, Jouni Malinen * Copyright (c) 2017-2022, Nicolas Mora * * This software may be distributed under the terms of the BSD license. */ #include #include "orcania.h" static const unsigned char base64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const unsigned char base64_url_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; static size_t table_size = 65; static int _o_base64_encode_agnostic(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len, const unsigned char * table, int right_pad) { unsigned char * pos; const unsigned char * end, * in; size_t olen; int line_len; olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */ olen += olen / 72; /* line feeds */ olen++; /* nul termination */ if (olen < len || src == NULL || out_len == NULL) { return 0; } end = src + len; in = src; pos = out; line_len = 0; *out_len = 0; while (end - in >= 3) { if (pos != NULL) { *pos++ = (unsigned char)(table[in[0] >> 2]); *pos++ = (unsigned char)(table[((in[0] & 0x03) << 4) | (in[1] >> 4)]); *pos++ = (unsigned char)(table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]); *pos++ = (unsigned char)(table[in[2] & 0x3f]); } (*out_len) += 4; in += 3; line_len += 4; if (line_len >= 72) { line_len = 0; } } if (end - in) { if (pos != NULL) { *pos++ = (unsigned char)(table[in[0] >> 2]); } (*out_len)++; if (end - in == 1) { if (pos != NULL) { *pos++ = (unsigned char)(table[(in[0] & 0x03) << 4]); if (right_pad) { *pos++ = '='; } } if (right_pad) { (*out_len) += 2; } else { (*out_len)++; } } else { if (pos != NULL) { *pos++ = (unsigned char)(table[((in[0] & 0x03) << 4) | (in[1] >> 4)]); *pos++ = (unsigned char)(table[(in[1] & 0x0f) << 2]); } (*out_len) += 2; } if (pos != NULL && right_pad) { *pos++ = '='; } if (right_pad) { (*out_len)++; } } return 1; } static int o_base64_decode_agnostic(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len, const unsigned char * table, int right_pad) { unsigned char dtable[256], *pos = out, block[4] = {0}, tmp; size_t i, count, unpad = 0; int pad = 0; if (src == NULL || !len || out_len == NULL) { return 0; } if (len % 4 == 2) { unpad = 2; } else if (len % 4 == 3) { unpad = 1; } memset(dtable, 0x80, 256); for (i = 0; i < table_size - 1; i++) { dtable[table[i]] = (unsigned char) i; } dtable['='] = 0; count = 0; for (i = 0; i < len; i++) { if (dtable[src[i]] != 0x80) { count++; } } if (right_pad && (count == 0 || count % 4)) { return 0; } count = 0; *out_len = 0; for (i = 0; i < len; i++) { if (!o_strnchr((const char *)table, table_size, (char)src[i]) && ((src[i] != '=')||(!right_pad && src[i] == '=')) && src[i] != '\n' && src[i] != '\t' && src[i] != ' ') { // character invalid return 0; } tmp = dtable[src[i]]; if (tmp == 0x80) { continue; } if (src[i] == '=') { pad++; } block[count] = tmp; count++; if (i == len-1) { count = 4; (*out_len) -= unpad; } if (count == 4) { if (pos != NULL) { *pos++ = (unsigned char)((block[0] << 2)) | (unsigned char)((block[1] >> 4)); *pos++ = (unsigned char)((block[1] << 4)) | (unsigned char)((block[2] >> 2)); *pos++ = (unsigned char)((block[2] << 6)) | (unsigned char)(block[3]); } (*out_len)+=3; count = 0; if (pad) { if (pad == 1) { if (pos != NULL) { pos--; } (*out_len)--; } else if (pad == 2) { if (pos != NULL) { pos -= 2; } (*out_len) -= 2; } else { /* Invalid padding */ return 0; } break; } memset(block, 0, 4); } } return 1; } int o_base64_encode(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len) { return _o_base64_encode_agnostic(src, len, out, out_len, base64_table, 1); } int o_base64_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len) { return o_base64_decode_agnostic(src, len, out, out_len, base64_table, 1); } int o_base64url_encode(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len) { return _o_base64_encode_agnostic(src, len, out, out_len, base64_url_table, 0); } int o_base64url_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len) { return o_base64_decode_agnostic(src, len, out, out_len, base64_url_table, 0); } int o_base64url_2_base64(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len) { int res = 0; size_t index; if (src != NULL && len && out != NULL && out_len != NULL) { memcpy(out, src, len); *out_len = len; for (index = 0; index < len; index++) { if (out[index] == '-') { out[index] = '+'; } else if (out[index] == '_') { out[index] = '/'; } } if (len % 4 == 2) { out[len] = '='; out[len+1] = '='; (*out_len) += 2; } else if (len % 4 == 3) { out[len] = '='; (*out_len)++; } res = 1; } return res; } int o_base64_2_base64url(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len) { int res = 0; size_t index; if (src) { memcpy(out, src, len); *out_len = len; for (index = 0; index < len; index++) { if (out[index] == '+') { out[index] = '-'; } else if (out[index] == '/') { out[index] = '_'; } } while (out[(*out_len)-1] == '=') { (*out_len)--; } res = 1; } return res; } int o_base64_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { int ret = 0; if (dat != NULL) { dat->size = 0; if ((ret = o_base64_encode(src, len, NULL, &dat->size)) && dat->size) { if ((dat->data = o_malloc(dat->size+2)) != NULL) { memset(dat->data, 0, dat->size+2); ret = o_base64_encode(src, len, dat->data, &dat->size); } else { ret = 0; } } } return ret; } int o_base64_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { int ret = 0; if (dat != NULL) { dat->size = 0; if ((ret = o_base64_decode(src, len, NULL, &dat->size)) && dat->size) { if ((dat->data = o_malloc(dat->size+2)) != NULL) { memset(dat->data, 0, dat->size+2); ret = o_base64_decode(src, len, dat->data, &dat->size); } else { ret = 0; } } } return ret; } int o_base64url_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { int ret = 0; if (dat != NULL) { dat->size = 0; if ((ret = o_base64url_encode(src, len, NULL, &dat->size)) && dat->size) { if ((dat->data = o_malloc(dat->size+2)) != NULL) { memset(dat->data, 0, dat->size+2); ret = o_base64url_encode(src, len, dat->data, &dat->size); } else { ret = 0; } } } return ret; } int o_base64url_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { int ret = 0; if (dat != NULL) { dat->size = 0; if ((ret = o_base64url_decode(src, len, NULL, &dat->size)) && dat->size) { if ((dat->data = o_malloc(dat->size+2)) != NULL) { memset(dat->data, 0, dat->size+2); ret = o_base64url_decode(src, len, dat->data, &dat->size); } else { ret = 0; } } } return ret; } int o_base64url_2_base64_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { int ret = 0; unsigned char * out = NULL; if (dat != NULL) { dat->size = 0; if ((out = o_malloc(len+4)) != NULL) { if ((ret = o_base64url_2_base64(src, len, out, &dat->size)) && dat->size) { if ((dat->data = o_malloc(dat->size)) != NULL) { memcpy(dat->data, out, dat->size); } } } } o_free(out); return ret; } int o_base64_2_base64url_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { int ret = 0; unsigned char * out = NULL; if (dat != NULL) { dat->size = 0; if ((out = o_malloc(len)) != NULL) { if ((ret = o_base64_2_base64url(src, len, out, &dat->size)) && dat->size) { if ((dat->data = o_malloc(dat->size)) != NULL) { memcpy(dat->data, out, dat->size); } } } } o_free(out); return ret; } orcania-2.3.3/src/memory.c000066400000000000000000000024411446552024700154100ustar00rootroot00000000000000/** * Copyright (c) 2017-2022 Nicolas Mora * Copyright (c) 2009-2014 Petri Lehtinen * Copyright (c) 2011-2012 Basile Starynkevitch * * Inspired by jansson memory.c * Jansson is free software; you can redistribute it and/or modify it * under the terms of the MIT license. See LICENSE for details. */ #include #include "orcania.h" /* memory function pointers */ static o_malloc_t do_malloc = malloc; static o_realloc_t do_realloc = realloc; static o_free_t do_free = free; void * o_malloc(size_t size) { if (!size) { return NULL; } else { return (*do_malloc)(size); } } void * o_realloc(void * ptr, size_t size) { if (!size) { return NULL; } else { return (*do_realloc)(ptr, size); } } void o_free(void * ptr) { if (ptr == NULL) { return; } else { (*do_free)(ptr); } } void o_set_alloc_funcs(o_malloc_t malloc_fn, o_realloc_t realloc_fn, o_free_t free_fn) { do_malloc = malloc_fn; do_realloc = realloc_fn; do_free = free_fn; } void o_get_alloc_funcs(o_malloc_t * malloc_fn, o_realloc_t * realloc_fn, o_free_t * free_fn) { if (malloc_fn) { *malloc_fn = do_malloc; } if (realloc_fn) { *realloc_fn = do_realloc; } if (free_fn) { *free_fn = do_free; } } orcania-2.3.3/src/orcania.c000066400000000000000000000403701446552024700155170ustar00rootroot00000000000000/** * * Orcania library * * Different functions for different purposes but that can be shared between * other projects * * orcania.c: main functions definitions * * Copyright 2015-2022 Nicolas Mora * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU General Public * License along with this library. If not, see . * */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include #include #include #include "orcania.h" #ifdef _MSC_VER #define strncasecmp _strnicmp #define strcasecmp _stricmp #endif #ifdef _MSC_VER #include typedef SSIZE_T ssize_t; #endif /** * * Orcania library * * Different functions for different purposes but that can be shared between * other projects * */ char * str_replace(const char * source, const char * str_old, const char * str_new) { char * to_return, * ptr, * pre, * next; size_t len, pre_len; if (source == NULL || str_old == NULL || str_new == NULL) { return NULL; } ptr = strstr(source, str_old); if (ptr == NULL) { return o_strdup(source); } else { pre_len = (size_t)(ptr-source); pre = o_malloc((pre_len+1)); if (pre == NULL) { return NULL; } memcpy(pre, source, pre_len); pre[pre_len] = '\0'; next = str_replace(source+o_strlen(pre)+o_strlen(str_old), str_old, str_new); if (next == NULL) { o_free(pre); return NULL; } len = (((size_t)(ptr-source))+o_strlen(str_new)+o_strlen(next)); to_return = o_malloc((len+1)); if (to_return == NULL) { o_free(pre); o_free(next); return NULL; } if (snprintf(to_return, (len+1), "%s%s%s", pre, str_new, next) < 0) { o_free(pre); o_free(next); o_free(to_return); return NULL; } o_free(pre); o_free(next); return to_return; } } char * msprintf(const char * message, ...) { va_list argp, argp_cpy; size_t out_len = 0; char * out = NULL; if (message != NULL) { va_start(argp, message); va_copy(argp_cpy, argp); // We make a copy because in some architectures, vsnprintf can modify argp out_len = (size_t)vsnprintf(NULL, 0, message, argp); out = o_malloc(out_len+1); if (out == NULL) { va_end(argp); va_end(argp_cpy); return NULL; } vsnprintf(out, (out_len+1), message, argp_cpy); va_end(argp); va_end(argp_cpy); } return out; } char * mstrcatf(char * source, const char * message, ...) { va_list argp, argp_cpy; char * out = NULL, * message_formatted = NULL; size_t message_formatted_len = 0, out_len = 0; if (message != NULL) { va_start(argp, message); va_copy(argp_cpy, argp); // We make a copy because in some architectures, vsnprintf can modify argp if (source != NULL) { message_formatted_len = (size_t)vsnprintf(NULL, 0, message, argp); message_formatted = o_malloc(message_formatted_len+1); if (message_formatted != NULL) { memset(message_formatted, 0, message_formatted_len+1); vsnprintf(message_formatted, (message_formatted_len+1), message, argp_cpy); out = msprintf("%s%s", source, message_formatted); o_free(message_formatted); o_free(source); } } else { out_len = (size_t)vsnprintf(NULL, 0, message, argp); out = o_malloc(out_len+1); if (out != NULL) { vsnprintf(out, (out_len+1), message, argp_cpy); } } va_end(argp); va_end(argp_cpy); } return out; } char * o_strdup(const char * source) { return (source==NULL?NULL:o_strndup(source, strlen(source))); } char * o_strndup(const char * source, size_t len) { char *new_str; if (source == NULL) { return NULL; } else { new_str = o_malloc(len + 1); if(!new_str) { return NULL; } memcpy(new_str, source, len); new_str[len] = '\0'; return new_str; } } int o_strcmp(const char * p1, const char * p2) { if (p1 == NULL && p2 == NULL) { return 0; } else if (p1 != NULL && p2 == NULL) { return -1; } else if (p1 == NULL) { return 1; } else { return strcmp(p1, p2); } } int o_strncmp(const char * p1, const char * p2, size_t n) { if ((p1 == NULL && p2 == NULL) || n <= 0) { return 0; } else if (p1 != NULL && p2 == NULL) { return -1; } else if (p1 == NULL) { return 1; } else { return strncmp(p1, p2, n); } } char * o_strcpy(char * p1, const char * p2) { if (p1 == NULL || p2 == NULL) { return NULL; } else { return strcpy(p1, p2); } } char * o_strncpy(char * p1, const char * p2, size_t n) { if (p1 == NULL || p2 == NULL) { return NULL; } else { return strncpy(p1, p2, n); } } int o_strcasecmp(const char * p1, const char * p2) { if (p1 == NULL && p2 == NULL) { return 0; } else if (p1 != NULL && p2 == NULL) { return -1; } else if (p1 == NULL && p2 != NULL) { return 1; } else { return strcasecmp(p1, p2); } } int o_strncasecmp(const char * p1, const char * p2, size_t n) { if ((p1 == NULL && p2 == NULL) || n <= 0) { return 0; } else if (p1 != NULL && p2 == NULL) { return -1; } else if (p1 == NULL && p2 != NULL) { return 1; } else { return strncasecmp(p1, p2, n); } } char * o_strstr(const char * haystack, const char * needle) { if (haystack == NULL || needle == NULL) { return NULL; } else { return strstr(haystack, needle); } } char * o_strchr(const char * haystack, int c) { if (haystack == NULL) { return NULL; } else { return strchr(haystack, c); } } const char * o_strnchr(const char * haystack, size_t len, char c) { size_t offset; if (haystack != NULL && len > 0) { for (offset = 0; offset < len && offset < o_strlen(haystack); offset++) { if (haystack[offset] == c) { return (haystack+offset); } } } return NULL; } /** * o_strrchr * a modified strrchr function that don't crash when haystack is NULL */ char * o_strrchr(const char * haystack, int c) { if (haystack == NULL) { return NULL; } else { return strrchr(haystack, c); } } const char * o_strrnchr(const char * haystack, size_t len, char c) { ssize_t offset; if (haystack != NULL && len > 0) { for (offset = ((ssize_t)o_strlen(haystack))-1; offset>=0 && (o_strlen(haystack) - 1 - (size_t)offset < len); offset--) { if (haystack[offset] == c) { return (haystack+offset); } } } return NULL; } #if defined(__linux__) || defined(__GLIBC__) || defined(_WIN32) || defined(O_STRSTR) static char *strnstr(const char *haystack, const char *needle, size_t len) { int i; size_t needle_len; /* segfault here if needle is not NULL terminated */ if (0 == (needle_len = o_strlen(needle))) return (char *)haystack; for (i=0; i<=(int)(len - needle_len); i++) { if ((haystack[0] == needle[0]) && (0 == strncmp(haystack, needle, needle_len))) return (char *)haystack; haystack++; } return NULL; } #endif #ifdef _WIN32 static char *strcasestr(const char *haystack, const char *needle) { size_t n; if (haystack == NULL || needle == NULL) { return NULL; } n = o_strlen(needle); while (*haystack) { if (!strnicmp(haystack++, needle, n)) { return (char *)(haystack-1); } } return NULL; } #endif char * o_strnstr(const char * haystack, const char * needle, size_t len) { if (haystack == NULL || needle == NULL) { return NULL; } else { return strnstr(haystack, needle, len); } } char * o_strcasestr(const char * haystack, const char * needle) { if (haystack == NULL || needle == NULL) { return NULL; } else { return strcasestr(haystack, needle); } } size_t o_strlen(const char * s) { if (s == NULL) { return 0; } else { return strlen(s); } } int o_strnullempty(const char * s) { return (s == NULL || s[0] == '\0'); } size_t split_string(const char * string, const char * separator, char *** return_array) { size_t result = 0; char * token; const char * begin = string; if (string != NULL && separator != NULL) { if (return_array != NULL) { *return_array = NULL; } result = 1; token = strstr(begin, separator); while (token != NULL) { if (return_array != NULL) { (*return_array) = o_realloc((*return_array), (result + 1)*sizeof(char*)); if ((*return_array) != NULL) { (*return_array)[result-1] = o_strndup(begin, (size_t)(token-begin)); (*return_array)[result] = NULL; } } result++; begin = token+o_strlen(separator); token = strstr(begin, separator); } if (return_array != NULL) { (*return_array) = o_realloc((*return_array), (result + 1)*sizeof(char*)); if ((*return_array) != NULL) { (*return_array)[result-1] = o_strdup(begin); (*return_array)[result] = NULL; } } } return result; } void free_string_array(char ** array) { int i; if (array != NULL) { for (i=0; array[i] != NULL; i++) { o_free(array[i]); array[i] = NULL; } o_free(array); } } size_t string_array_size(char ** array) { size_t ret = 0; if (array != NULL) { for (;array[ret] != NULL; ret++); } return ret; } char * string_array_join(const char ** array, const char * separator) { char * to_return = NULL, * tmp; int i; if (array != NULL && separator != NULL) { for (i=0; array[i] != NULL; i++) { if (to_return == NULL) { to_return = o_strdup(array[i]); } else { tmp = msprintf("%s%s%s", to_return, separator, array[i]); o_free(to_return); to_return = tmp; } } } return to_return; } const char * trimwhitespace(char * str) { char * end; if (str == NULL) { return NULL; } else if(*str == 0) { return str; } while(isspace((unsigned char)*str)) str++; end = str + o_strlen(str) - 1; while(end > str && isspace((unsigned char)*end)) { end--; } *(end+1) = 0; return str; } char * trimcharacter(char * str, char to_remove) { char * end; if (str == NULL) { return NULL; } else if(*str == 0) { return str; } while(*str == to_remove) str++; end = str + o_strlen(str) - 1; while(end > str && (*end == to_remove)) { end--; } *(end+1) = 0; return str; } int string_array_has_value(const char ** array, const char * needle) { int i; if (array != NULL && needle != NULL) { for (i=0; array[i] != NULL; i++) { if (o_strcmp(array[i], needle) == 0) { return 1; } } return 0; } else { return 0; } } int string_array_has_value_case(const char ** array, const char * needle) { int i; if (array != NULL && needle != NULL) { for (i=0; array[i] != NULL; i++) { if (o_strcasecmp(array[i], needle) == 0) { return 1; } } return 0; } else { return 0; } } int string_array_has_value_n(const char ** array, const char * needle, size_t len) { int i; if (array != NULL && needle != NULL) { for (i=0; array[i] != NULL; i++) { if (o_strncmp(array[i], needle, len) == 0) { return 1; } } return 0; } else { return 0; } } int string_array_has_value_ncase(const char ** array, const char * needle, size_t len) { int i; if (array != NULL && needle != NULL) { for (i=0; array[i] != NULL; i++) { if (o_strncasecmp(array[i], needle, len) == 0) { return 1; } } return 0; } else { return 0; } } int string_array_has_trimmed_value(const char ** array, const char * needle) { int i, to_return = 0; char * duplicate_needle, * duplicate_value; const char * trimmed_needle, * trimmed_value; if (array != NULL && needle != NULL) { duplicate_needle = o_strdup(needle); if (duplicate_needle != NULL) { trimmed_needle = trimwhitespace(duplicate_needle); for (i=0; array[i] != NULL && !to_return; i++) { duplicate_value = o_strdup(array[i]); if (duplicate_value == NULL) { break; } else { trimmed_value = trimwhitespace(duplicate_value); if (o_strcmp(trimmed_value, trimmed_needle) == 0) { to_return = 1; } } o_free(duplicate_value); } } o_free(duplicate_needle); } return to_return; } void pointer_list_init(struct _pointer_list * pointer_list) { if (pointer_list != NULL) { pointer_list->size = 0; pointer_list->list = NULL; } } void pointer_list_clean(struct _pointer_list * pointer_list) { size_t i; if (pointer_list != NULL) { for (i=pointer_list_size(pointer_list); i; i--) { pointer_list_remove_at(pointer_list, (i-1)); } } } void pointer_list_clean_free(struct _pointer_list * pointer_list, void (* free_function)(void * elt)) { size_t i; if (pointer_list != NULL) { for (i=pointer_list_size(pointer_list); i; i--) { free_function(pointer_list_get_at(pointer_list, i-1)); pointer_list_remove_at(pointer_list, (i-1)); } } } size_t pointer_list_size(struct _pointer_list * pointer_list) { if (pointer_list != NULL) { return pointer_list->size; } else { return 0; } } int pointer_list_append(struct _pointer_list * pointer_list, void * element) { if (pointer_list) { pointer_list->list = o_realloc(pointer_list->list, (pointer_list->size+1)*sizeof(void *)); if (pointer_list->list != NULL) { pointer_list->list[pointer_list->size] = element; pointer_list->size++; return 1; } else { o_free(pointer_list->list); pointer_list->list = NULL; return 0; } } else { return 0; } } void * pointer_list_get_at(struct _pointer_list * pointer_list, size_t index) { if (pointer_list != NULL && index < pointer_list->size) { return pointer_list->list[index]; } else { return NULL; } } int pointer_list_remove_at(struct _pointer_list * pointer_list, size_t index) { size_t i; if (pointer_list != NULL && index < pointer_list->size) { for (i=index; isize-1; i++) { pointer_list->list[i] = pointer_list->list[i+1]; } if (pointer_list->size > 1) { pointer_list->list = o_realloc(pointer_list->list, (pointer_list->size-1)*sizeof(void *)); } else { o_free(pointer_list->list); pointer_list->list = NULL; } pointer_list->size--; return 1; } else { return 0; } } int pointer_list_remove_at_free(struct _pointer_list * pointer_list, size_t index, void (* free_function)(void * elt)) { if (pointer_list != NULL && index < pointer_list->size) { free_function(pointer_list_get_at(pointer_list, index)); return pointer_list_remove_at(pointer_list, index); } else { return 0; } } int pointer_list_insert_at(struct _pointer_list * pointer_list, void * element, size_t index) { size_t i; if (pointer_list != NULL && index <= pointer_list->size) { pointer_list->list = o_realloc(pointer_list->list, (pointer_list->size + 1)*sizeof(void *)); if (pointer_list->list != NULL) { for (i=pointer_list->size; i>index; i--) { pointer_list->list[i] = pointer_list->list[i-1]; } pointer_list->list[index] = element; pointer_list->size++; return 1; } else { return 0; } } else { return 0; } } int pointer_list_remove_pointer(struct _pointer_list * pointer_list, void * element) { size_t index; if (pointer_list != NULL) { for (index=0; indexsize; index++) { if (pointer_list->list[index] == element) { return pointer_list_remove_at(pointer_list, index); } } return 0; } else { return 0; } } int pointer_list_remove_pointer_free(struct _pointer_list * pointer_list, void * element, void (* free_function)(void * elt)) { size_t index; if (pointer_list != NULL) { for (index=0; indexsize; index++) { if (pointer_list->list[index] == element) { free_function(element); return pointer_list_remove_at(pointer_list, index); } } return 0; } else { return 0; } } orcania-2.3.3/test/000077500000000000000000000000001446552024700141235ustar00rootroot00000000000000orcania-2.3.3/test/.gitignore000066400000000000000000000001001446552024700161020ustar00rootroot00000000000000valgrind*.txt str_test split_test memory_test pointer_list_test orcania-2.3.3/test/Makefile000066400000000000000000000023551446552024700155700ustar00rootroot00000000000000# # Public domain, no copyright. Use at your own risk. # CC=gcc CFLAGS+=-Wall -D_REENTRANT -DDEBUG -g -O0 -I$(INCLUDE_LOCATION) $(CPPFLAGS) ORCANIA_LOCATION=../src INCLUDE_LOCATION=../include ORCANIA_LIBRARY=$(ORCANIA_LOCATION)/liborcania.so LDFLAGS=-lc -lorcania $(shell pkg-config --libs check) -L$(ORCANIA_LOCATION) VALGRIND_COMMAND=valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all TARGET=str_test split_test memory_test pointer_list_test VERBOSE=0 MEMCHECK=0 all: test clean: rm -f *.o $(TARGET) *.log valgrind-*.txt $(ORCANIA_LIBRARY): $(ORCANIA_LOCATION)/orcania.c $(ORCANIA_LOCATION)/memory.c $(ORCANIA_LOCATION)/base64.c cd $(ORCANIA_LOCATION) && $(MAKE) debug $* %: %.c $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) test: $(ORCANIA_LIBRARY) $(TARGET) test_str_test test_split_test test_memory_test test_pointer_list_test check: test test_%: % $(ORCANIA_LIBRARY) @if [ "$(VERBOSE)" = "0" ] && [ "$(MEMCHECK)" = "0" ]; then \ LD_LIBRARY_PATH=$(ORCANIA_LOCATION):${LD_LIBRARY_PATH} ./run_test.sh ./$^; \ elif [ "$(MEMCHECK)" = "0" ]; then \ LD_LIBRARY_PATH=$(ORCANIA_LOCATION):${LD_LIBRARY_PATH} ./$^ ; \ else \ CK_FORK=no LD_LIBRARY_PATH=$(ORCANIA_LOCATION):${LD_LIBRARY_PATH} $(VALGRIND_COMMAND) ./$^ 2>valgrind-$@.txt; \ fi orcania-2.3.3/test/memory_test.c000066400000000000000000000022021446552024700166320ustar00rootroot00000000000000/* Public domain, no copyright. Use at your own risk. */ #include #include #include #include #include #include #include "orcania.h" START_TEST(test_o_malloc) { void * var; var = o_malloc(8); ck_assert_ptr_ne(var, NULL); o_free(var); } END_TEST START_TEST(test_o_realloc) { void * var; var = o_malloc(8); ck_assert_ptr_ne(var, NULL); var = o_realloc(var, 16); ck_assert_ptr_ne(var, NULL); if (var != NULL) { o_free(var); } } END_TEST static Suite *orcania_suite(void) { Suite *s; TCase *tc_core; s = suite_create("Orcania tests memory functions"); tc_core = tcase_create("test_orcania_memory"); tcase_add_test(tc_core, test_o_malloc); tcase_add_test(tc_core, test_o_realloc); tcase_set_timeout(tc_core, 30); suite_add_tcase(s, tc_core); return s; } int main(int argc, char *argv[]) { int number_failed; Suite *s; SRunner *sr; s = orcania_suite(); sr = srunner_create(s); srunner_run_all(sr, CK_VERBOSE); number_failed = srunner_ntests_failed(sr); srunner_free(sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } orcania-2.3.3/test/pointer_list_test.c000066400000000000000000000226411446552024700200460ustar00rootroot00000000000000/* Public domain, no copyright. Use at your own risk. */ #include #include #include #include #include #include #include "orcania.h" int counter = 0; void free_with_test(void * ptr) { counter++; o_free(ptr); } START_TEST(test_pointer_list_init) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list->size, 0); ck_assert_ptr_eq(pointer_list->list, NULL); pointer_list_clean(pointer_list); o_free(pointer_list); } END_TEST START_TEST(test_pointer_list_append) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list->size, 0); ck_assert_ptr_eq(pointer_list->list, NULL); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x42), 1); ck_assert_int_eq(pointer_list_append(NULL, (void *)0x42), 0); ck_assert_int_eq(pointer_list->size, 1); ck_assert_int_eq(pointer_list_append(NULL, (void *)0x43), 0); ck_assert_int_eq(pointer_list_append(pointer_list, NULL), 1); ck_assert_int_eq(pointer_list->size, 2); pointer_list_clean(pointer_list); o_free(pointer_list); } END_TEST START_TEST(test_pointer_list_size) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x42), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x43), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x44), 1); ck_assert_int_eq(pointer_list_size(pointer_list), 3); ck_assert_int_eq(pointer_list_size(pointer_list), pointer_list->size); pointer_list_clean(pointer_list); o_free(pointer_list); } END_TEST START_TEST(test_pointer_list_get_at) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x42), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x43), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x44), 1); ck_assert_int_eq(pointer_list->size, 3); ck_assert_ptr_ne(pointer_list_get_at(pointer_list, 0), NULL); ck_assert_ptr_eq(pointer_list_get_at(pointer_list, 0), (void *)0x42); ck_assert_ptr_ne(pointer_list_get_at(pointer_list, 1), NULL); ck_assert_ptr_eq(pointer_list_get_at(pointer_list, 1), (void *)0x43); ck_assert_ptr_ne(pointer_list_get_at(pointer_list, 2), NULL); ck_assert_ptr_eq(pointer_list_get_at(pointer_list, 2), (void *)0x44); ck_assert_ptr_eq(pointer_list_get_at(pointer_list, 3), NULL); pointer_list_clean(pointer_list); o_free(pointer_list); } END_TEST START_TEST(test_pointer_list_remove_at) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x42), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x43), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x44), 1); ck_assert_int_eq(pointer_list->size, 3); ck_assert_int_eq(pointer_list_remove_at(pointer_list, 0), 1); ck_assert_int_eq(pointer_list_remove_at(pointer_list, 4), 0); ck_assert_int_eq(pointer_list->size, 2); pointer_list_clean(pointer_list); o_free(pointer_list); } END_TEST START_TEST(test_pointer_list_remove_at_free) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list_append(pointer_list, o_strdup("test1")), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x43), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x44), 1); ck_assert_int_eq(pointer_list->size, 3); counter = 0; ck_assert_int_eq(pointer_list_remove_at_free(pointer_list, 0, &free_with_test), 1); ck_assert_int_eq(counter, 1); ck_assert_int_eq(pointer_list_remove_at_free(pointer_list, 4, &free_with_test), 0); ck_assert_int_eq(counter, 1); ck_assert_int_eq(pointer_list->size, 2); pointer_list_clean(pointer_list); o_free(pointer_list); } END_TEST START_TEST(test_pointer_list_insert_at) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x42), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x43), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x44), 1); ck_assert_int_eq(pointer_list->size, 3); ck_assert_int_eq(pointer_list_insert_at(pointer_list, (void *)0x45, 0), 1); ck_assert_int_eq(pointer_list->size, 4); ck_assert_ptr_eq(pointer_list_get_at(pointer_list, 0), (void *)0x45); ck_assert_ptr_eq(pointer_list_get_at(pointer_list, 1), (void *)0x42); ck_assert_int_eq(pointer_list_insert_at(pointer_list, (void *)0x46, 3), 1); ck_assert_int_eq(pointer_list->size, 5); ck_assert_ptr_eq(pointer_list_get_at(pointer_list, 0), (void *)0x45); ck_assert_ptr_eq(pointer_list_get_at(pointer_list, 1), (void *)0x42); ck_assert_ptr_eq(pointer_list_get_at(pointer_list, 3), (void *)0x46); ck_assert_int_eq(pointer_list_insert_at(pointer_list, (void *)0x47, 10), 0); pointer_list_clean(pointer_list); o_free(pointer_list); } END_TEST START_TEST(test_pointer_list_remove_pointer) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x42), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x43), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x44), 1); ck_assert_int_eq(pointer_list->size, 3); ck_assert_int_eq(pointer_list_remove_pointer(pointer_list, (void *)0x42), 1); ck_assert_int_eq(pointer_list->size, 2); ck_assert_int_eq(pointer_list_remove_pointer(pointer_list, (void *)0x42), 0); ck_assert_int_eq(pointer_list->size, 2); ck_assert_int_eq(pointer_list_remove_pointer(pointer_list, (void *)0x44), 1); ck_assert_int_eq(pointer_list->size, 1); pointer_list_clean(pointer_list); o_free(pointer_list); } END_TEST START_TEST(test_pointer_list_remove_pointer_free) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); char * test1 = o_strdup("test1"), * test3 = o_strdup("test3"); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list_append(pointer_list, test1), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x43), 1); ck_assert_int_eq(pointer_list_append(pointer_list, test3), 1); ck_assert_int_eq(pointer_list->size, 3); counter = 0; ck_assert_int_eq(pointer_list_remove_pointer_free(pointer_list, test1, &free_with_test), 1); ck_assert_int_eq(counter, 1); ck_assert_int_eq(pointer_list->size, 2); ck_assert_int_eq(pointer_list_remove_pointer(pointer_list, (void *)0x42), 0); ck_assert_int_eq(pointer_list->size, 2); ck_assert_int_eq(pointer_list_remove_pointer_free(pointer_list, test3, &free_with_test), 1); ck_assert_int_eq(counter, 2); ck_assert_int_eq(pointer_list->size, 1); pointer_list_clean(pointer_list); o_free(pointer_list); } END_TEST START_TEST(test_pointer_list_clean) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x42), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x43), 1); ck_assert_int_eq(pointer_list_append(pointer_list, (void *)0x44), 1); ck_assert_int_eq(pointer_list->size, 3); pointer_list_clean(pointer_list); ck_assert_int_eq(pointer_list->size, 0); o_free(pointer_list); } END_TEST START_TEST(test_pointer_list_clean_free) { struct _pointer_list * pointer_list = o_malloc(sizeof(struct _pointer_list)); pointer_list_init(pointer_list); ck_assert_int_eq(pointer_list_append(pointer_list, o_strdup("test1")), 1); ck_assert_int_eq(pointer_list_append(pointer_list, o_strdup("test2")), 1); ck_assert_int_eq(pointer_list_append(pointer_list, o_strdup("test3")), 1); ck_assert_int_eq(pointer_list->size, 3); counter = 0; pointer_list_clean_free(pointer_list, &free_with_test); ck_assert_int_eq(pointer_list->size, 0); ck_assert_int_eq(counter, 3); o_free(pointer_list); } END_TEST static Suite *orcania_suite(void) { Suite *s; TCase *tc_core; s = suite_create("Orcania tests pointer list structure functions"); tc_core = tcase_create("test_pointer_list"); tcase_add_test(tc_core, test_pointer_list_init); tcase_add_test(tc_core, test_pointer_list_append); tcase_add_test(tc_core, test_pointer_list_size); tcase_add_test(tc_core, test_pointer_list_get_at); tcase_add_test(tc_core, test_pointer_list_remove_at); tcase_add_test(tc_core, test_pointer_list_remove_at_free); tcase_add_test(tc_core, test_pointer_list_insert_at); tcase_add_test(tc_core, test_pointer_list_remove_pointer); tcase_add_test(tc_core, test_pointer_list_remove_pointer_free); tcase_add_test(tc_core, test_pointer_list_clean); tcase_add_test(tc_core, test_pointer_list_clean_free); tcase_set_timeout(tc_core, 30); suite_add_tcase(s, tc_core); return s; } int main(int argc, char *argv[]) { int number_failed; Suite *s; SRunner *sr; s = orcania_suite(); sr = srunner_create(s); srunner_run_all(sr, CK_VERBOSE); number_failed = srunner_ntests_failed(sr); srunner_free(sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } orcania-2.3.3/test/run_test.sh000077500000000000000000000005751446552024700163340ustar00rootroot00000000000000#!/bin/bash printf_new() { str=$1 num=$2 v=$(printf "%-${num}s" "$str") printf "${v// / }" } RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color COMMAND=$1 CHRLEN=${#COMMAND} NBSP=$((32-$CHRLEN)) printf "Run $1" printf_new " " $NBSP $1 $2 $3 $4 $5 $6 $7 $8 $9 1>$1.log 2>&1 if [ $? -ne 0 ] then printf "${RED}FAIL${NC}\n" else printf "${GREEN}SUCCESS${NC}\n" fi orcania-2.3.3/test/split_test.c000066400000000000000000000063331446552024700164660ustar00rootroot00000000000000/* Public domain, no copyright. Use at your own risk. */ #include #include #include #include #include #include #include "orcania.h" START_TEST(test_split_string) { char * str = "ab,cd,ef,gghhii,jkl", * str_2 = "ab, cd,ef,gghhii, jkl", * separator = ",", * long_separator = ", ", ** splitted; int nb_elt; nb_elt = split_string(str, separator, &splitted); ck_assert_ptr_ne(splitted, NULL); ck_assert_int_eq(nb_elt, 5); ck_assert_int_eq(split_string(str, "nope", NULL), 1); ck_assert_str_eq(splitted[0], "ab"); free_string_array(splitted); nb_elt = split_string(str_2, long_separator, &splitted); ck_assert_ptr_ne(splitted, NULL); ck_assert_int_eq(nb_elt, 3); free_string_array(splitted); nb_elt = split_string(str_2, "yolo", &splitted); ck_assert_ptr_ne(splitted, NULL); ck_assert_int_eq(nb_elt, 1); free_string_array(splitted); nb_elt = split_string("john", "and-yolo", &splitted); ck_assert_ptr_ne(splitted, NULL); ck_assert_int_eq(nb_elt, 1); free_string_array(splitted); } END_TEST START_TEST(test_string_array_has_value) { char * str = "ab,cd,ef,gghhii,jkl", * separator = ",", ** splitted; ck_assert_int_eq(split_string(str, separator, &splitted), 5); ck_assert_int_eq(string_array_has_value((const char **)splitted, "ab"), 1); ck_assert_int_eq(string_array_has_value((const char **)splitted, "nope"), 0); ck_assert_int_eq(string_array_has_value((const char **)splitted, NULL), 0); ck_assert_int_eq(string_array_has_value(NULL, "ab"), 0); free_string_array(splitted); } END_TEST START_TEST(test_string_array_join) { char * str = "ab,cd,ef,gghhii,jkl", * separator = ",", * join, ** splitted; ck_assert_int_eq(split_string(str, separator, &splitted), 5); join = string_array_join((const char **)splitted, " "); ck_assert_str_eq(join, "ab cd ef gghhii jkl"); ck_assert_ptr_eq(string_array_join(NULL, " "), NULL); ck_assert_ptr_eq(string_array_join((const char **)splitted, NULL), NULL); ck_assert_ptr_eq(string_array_join(NULL, NULL), NULL); free_string_array(splitted); o_free(join); } END_TEST START_TEST(test_string_array_size) { char * str = "ab,cd,ef,gghhii,jkl", * separator = ",", ** splitted, ** empty_array = {NULL}; ck_assert_int_eq(split_string(str, separator, &splitted), 5); ck_assert_int_eq(string_array_size(splitted), 5); ck_assert_int_eq(string_array_size(NULL), 0); ck_assert_int_eq(string_array_size(empty_array), 0); free_string_array(splitted); } END_TEST static Suite *orcania_suite(void) { Suite *s; TCase *tc_core; s = suite_create("Orcania tests split string functions"); tc_core = tcase_create("test_orcania_split"); tcase_add_test(tc_core, test_split_string); tcase_add_test(tc_core, test_string_array_has_value); tcase_add_test(tc_core, test_string_array_join); tcase_add_test(tc_core, test_string_array_size); tcase_set_timeout(tc_core, 30); suite_add_tcase(s, tc_core); return s; } int main(int argc, char *argv[]) { int number_failed; Suite *s; SRunner *sr; s = orcania_suite(); sr = srunner_create(s); srunner_run_all(sr, CK_VERBOSE); number_failed = srunner_ntests_failed(sr); srunner_free(sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } orcania-2.3.3/test/str_test.c000066400000000000000000001152641446552024700161470ustar00rootroot00000000000000/* Public domain, no copyright. Use at your own risk. */ #include #include #include #include #include #include #include "orcania.h" static void run_test_base64(const unsigned char * src, size_t src_len, const unsigned char * b64_expected, size_t b64_expected_len, const unsigned char * b64url_expected, size_t b64url_expected_len) { unsigned char out[256] = {0}, * out_m; size_t out_len = 0; memset(out, 0, 256); out_len = 0; ck_assert_int_eq(o_base64_encode(src, src_len, out, &out_len), 1); ck_assert_int_eq(out_len, b64_expected_len); ck_assert_str_eq((const char *)out, (const char *)b64_expected); out_len = 0; ck_assert_int_eq(o_base64_encode(src, src_len, NULL, &out_len), 1); ck_assert_int_eq(out_len, b64_expected_len); out_m = o_malloc(out_len); out_len = 0; ck_assert_int_eq(o_base64_encode(src, src_len, out_m, &out_len), 1); o_free(out_m); memset(out, 0, 256); out_len = 0; ck_assert_int_eq(o_base64_decode(b64_expected, b64_expected_len, out, &out_len), 1); ck_assert_int_eq(out_len, src_len); ck_assert_int_eq(0, memcmp(src, out, out_len)); out_len = 0; ck_assert_int_eq(o_base64_decode(b64_expected, b64_expected_len, NULL, &out_len), 1); ck_assert_int_eq(out_len, src_len); out_m = o_malloc(out_len+2); out_len = 0; ck_assert_int_eq(o_base64_decode(b64_expected, b64_expected_len, out_m, &out_len), 1); o_free(out_m); memset(out, 0, 256); out_len = 0; ck_assert_int_eq(o_base64url_encode(src, src_len, out, &out_len), 1); ck_assert_int_eq(out_len, b64url_expected_len); ck_assert_str_eq((const char *)out, (const char *)b64url_expected); out_len = 0; ck_assert_int_eq(o_base64url_encode(src, src_len, NULL, &out_len), 1); ck_assert_int_eq(out_len, b64url_expected_len); out_m = o_malloc(out_len); out_len = 0; ck_assert_int_eq(o_base64url_encode(src, src_len, out_m, &out_len), 1); o_free(out_m); memset(out, 0, 256); out_len = 0; ck_assert_int_eq(o_base64url_decode(b64url_expected, b64url_expected_len, out, &out_len), 1); ck_assert_int_eq(out_len, src_len); ck_assert_int_eq(0, memcmp(src, out, out_len)); out_len = 0; ck_assert_int_eq(o_base64url_decode(b64url_expected, b64url_expected_len, NULL, &out_len), 1); ck_assert_int_eq(out_len, src_len); out_m = o_malloc(out_len+2); out_len = 0; ck_assert_int_eq(o_base64url_decode(b64url_expected, b64url_expected_len, out_m, &out_len), 1); o_free(out_m); memset(out, 0, 256); out_len = 0; ck_assert_int_eq(o_base64_2_base64url(b64_expected, b64_expected_len, out, &out_len), 1); ck_assert_int_eq(out_len, b64url_expected_len); ck_assert_int_eq(0, memcmp(b64url_expected, out, out_len)); memset(out, 0, 256); out_len = 0; ck_assert_int_eq(o_base64url_2_base64(b64url_expected, b64url_expected_len, out, &out_len), 1); ck_assert_int_eq(out_len, b64_expected_len); ck_assert_int_eq(0, memcmp(b64_expected, out, out_len)); } static void run_test_base64_alloc(const unsigned char * src, size_t src_len, const unsigned char * b64_expected, size_t b64_expected_len, const unsigned char * b64url_expected, size_t b64url_expected_len) { struct _o_datum dat = {0, NULL}; ck_assert_int_eq(o_base64_encode_alloc(src, src_len, &dat), 1); ck_assert_int_eq(b64_expected_len, dat.size); ck_assert_str_eq((const char *)dat.data, (const char *)b64_expected); o_free(dat.data); dat.data = NULL; dat.size = 0; ck_assert_int_eq(o_base64_decode_alloc(b64_expected, b64_expected_len, &dat), 1); ck_assert_int_eq(dat.size, src_len); ck_assert_int_eq(0, memcmp(src, dat.data, dat.size)); o_free(dat.data); dat.data = NULL; dat.size = 0; ck_assert_int_eq(o_base64url_encode_alloc(src, src_len, &dat), 1); ck_assert_int_eq(dat.size, b64url_expected_len); ck_assert_str_eq((const char *)dat.data, (const char *)b64url_expected); o_free(dat.data); dat.data = NULL; dat.size = 0; ck_assert_int_eq(o_base64url_decode_alloc(b64url_expected, b64url_expected_len, &dat), 1); ck_assert_int_eq(dat.size, src_len); ck_assert_int_eq(0, memcmp(src, dat.data, dat.size)); o_free(dat.data); dat.data = NULL; dat.size = 0; ck_assert_int_eq(o_base64_2_base64url_alloc(b64_expected, b64_expected_len, &dat), 1); ck_assert_int_eq(dat.size, b64url_expected_len); ck_assert_int_eq(0, memcmp(b64url_expected, dat.data, dat.size)); o_free(dat.data); dat.data = NULL; dat.size = 0; ck_assert_int_eq(o_base64url_2_base64_alloc(b64url_expected, b64url_expected_len, &dat), 1); ck_assert_int_eq(dat.size, b64_expected_len); ck_assert_int_eq(0, memcmp(b64_expected, dat.data, dat.size)); o_free(dat.data); dat.data = NULL; dat.size = 0; } START_TEST(test_str_replace) { char * str = "abcdeffedcba", * old_1 = "cd", * new_1 = "gh", * old_2 = "f", * target; target = str_replace(str, old_1, new_1); ck_assert_str_eq(target, "abgheffedcba"); ck_assert_ptr_eq(str_replace(NULL, old_1, new_1), NULL); ck_assert_ptr_eq(str_replace(str, NULL, new_1), NULL); ck_assert_ptr_eq(str_replace(str, old_1, NULL), NULL); o_free(target); target = str_replace(str, old_2, new_1); ck_assert_str_eq(target, "abcdeghghedcba"); o_free(target); target = str_replace(str, str, ""); ck_assert_str_eq(target, ""); o_free(target); } END_TEST START_TEST(test_o_strdup) { char * str = "abcdeffedcba", * target; target = o_strdup(str); ck_assert_str_eq(target, str); o_free(target); ck_assert_ptr_eq(o_strdup(NULL), NULL); } END_TEST START_TEST(test_o_strndup) { char * str = "abcdeffedcba", * target; target = o_strndup(str, o_strlen(str)); ck_assert_str_eq(target, str); o_free(target); target = o_strndup(str, o_strlen(str)-2); ck_assert_str_eq(target, "abcdeffedc"); o_free(target); ck_assert_ptr_eq(o_strndup(NULL, 12), NULL); target = o_strndup("abcdeffedc", 0); ck_assert_ptr_ne(target, NULL); o_free(target); } END_TEST START_TEST(test_o_strcmp) { char * str_1 = "abcdeffedcba", * str_2 = "bob", * str_3 = "abcdeffedcba"; ck_assert_int_eq(o_strcmp(str_1, str_3), 0); ck_assert_int_ne(o_strcmp(str_1, str_2), 0); ck_assert_int_ne(o_strcmp(str_1, NULL), 0); ck_assert_int_ne(o_strcmp(NULL, str_1), 0); ck_assert_int_eq(o_strcmp(NULL, NULL), 0); } END_TEST START_TEST(test_o_strncmp) { char * str_1 = "abcdeffedcba", * str_2 = "abc", * str_3 = "abcdeffedcba"; ck_assert_int_eq(o_strncmp(str_1, str_3, o_strlen(str_3)), 0); ck_assert_int_eq(o_strncmp(str_1, str_2, o_strlen(str_2)), 0); ck_assert_int_ne(o_strncmp(str_1, str_2, o_strlen(str_1)), 0); ck_assert_int_ne(o_strncmp(str_1, NULL, o_strlen(str_1)), 0); ck_assert_int_ne(o_strncmp(NULL, str_1, o_strlen(str_1)), 0); ck_assert_int_eq(o_strncmp(NULL, NULL, 0), 0); ck_assert_int_eq(o_strncmp(NULL, NULL, 1), 0); } END_TEST START_TEST(test_o_strcasecmp) { char * str_1 = "abcdeffedcba", * str_2 = "bob", * str_3 = "AbcdeFfedcba"; ck_assert_int_eq(o_strcasecmp(str_1, str_3), 0); ck_assert_int_ne(o_strcasecmp(str_1, str_2), 0); ck_assert_int_ne(o_strcasecmp(str_1, NULL), 0); ck_assert_int_ne(o_strcasecmp(NULL, str_1), 0); ck_assert_int_eq(o_strcasecmp(NULL, NULL), 0); } END_TEST START_TEST(test_o_strncasecmp) { char * str_1 = "abcdeFfedcba", * str_2 = "abC", * str_3 = "abCdeffedCba"; ck_assert_int_eq(o_strncasecmp(str_1, str_3, o_strlen(str_3)), 0); ck_assert_int_eq(o_strncasecmp(str_1, str_2, o_strlen(str_2)), 0); ck_assert_int_ne(o_strncasecmp(str_1, str_2, o_strlen(str_1)), 0); ck_assert_int_ne(o_strncasecmp(str_1, NULL, o_strlen(str_1)), 0); ck_assert_int_ne(o_strncasecmp(NULL, str_1, o_strlen(str_1)), 0); ck_assert_int_eq(o_strncasecmp(NULL, NULL, 0), 0); ck_assert_int_eq(o_strncasecmp(NULL, NULL, 1), 0); } END_TEST START_TEST(test_o_strcpy) { char * src = "abcd", target[5]; ck_assert_ptr_ne(o_strcpy(target, src), NULL); ck_assert_str_eq(target, src); ck_assert_ptr_eq(o_strcpy(target, NULL), NULL); ck_assert_ptr_eq(o_strcpy(NULL, src), NULL); ck_assert_ptr_eq(o_strcpy(NULL, NULL), NULL); } END_TEST START_TEST(test_o_strncpy) { char * src = "abcd", target[5] = {0}; ck_assert_ptr_ne(o_strncpy(target, src, 3), NULL); ck_assert_str_eq(target, "abc"); ck_assert_ptr_eq(o_strncpy(target, NULL, 4), NULL); ck_assert_ptr_eq(o_strncpy(NULL, src, 4), NULL); ck_assert_ptr_eq(o_strncpy(NULL, NULL, 4), NULL); } END_TEST START_TEST(test_o_strstr) { char * str_1 = "abcdeffedcba", * str_2 = "def", * str_3 = "bob"; ck_assert_ptr_ne(o_strstr(str_1, str_2), NULL); ck_assert_ptr_eq(o_strstr(str_1, str_3), NULL); ck_assert_ptr_eq(o_strstr(NULL, str_3), NULL); ck_assert_ptr_eq(o_strstr(str_1, NULL), NULL); ck_assert_ptr_eq(o_strstr(NULL, NULL), NULL); } END_TEST START_TEST(test_o_strnstr) { char * str_1 = "abcdeffedcba", * str_2 = "def", * str_3 = "bob"; ck_assert_ptr_ne(o_strnstr(str_1, str_2, o_strlen(str_1)), NULL); ck_assert_ptr_eq(o_strnstr(str_1, str_3, o_strlen(str_1)), NULL); ck_assert_ptr_eq(o_strnstr(str_1, str_3, 0), NULL); ck_assert_ptr_eq(o_strnstr(NULL, str_3, o_strlen(str_3)), NULL); ck_assert_ptr_eq(o_strnstr(str_1, NULL, o_strlen(str_1)), NULL); ck_assert_ptr_eq(o_strnstr(NULL, NULL, o_strlen(str_3)), NULL); } END_TEST START_TEST(test_o_strchr) { char * str_1 = "abcdef", str_2 = 'd', str_3 = 'g'; ck_assert_ptr_ne(o_strchr(str_1, str_2), NULL); ck_assert_ptr_eq(o_strchr(str_1, str_3), NULL); ck_assert_ptr_eq(o_strchr(NULL, str_3), NULL); } END_TEST START_TEST(test_o_strnchr) { char * str_1 = "abcdef", str_2 = 'd'; ck_assert_ptr_ne(o_strnchr(str_1, 5, str_2), NULL); ck_assert_ptr_eq(o_strnchr(str_1, 2, str_2), NULL); ck_assert_ptr_eq(o_strnchr(str_1, 0, str_2), NULL); ck_assert_ptr_ne(o_strnchr(str_1, 8, str_2), NULL); ck_assert_ptr_eq(o_strnchr(NULL, 4, str_2), NULL); } END_TEST START_TEST(test_o_strrchr) { char * str_1 = "abcdef", str_2 = 'd', str_3 = 'g'; ck_assert_ptr_ne(o_strrchr(str_1, str_2), NULL); ck_assert_ptr_eq(o_strrchr(str_1, str_3), NULL); ck_assert_ptr_ne(o_strrchr(str_1, str_2), NULL); ck_assert_ptr_eq(o_strrchr(NULL, str_3), NULL); } END_TEST START_TEST(test_o_strrnchr) { char * str_1 = "abcdef", str_2 = 'd'; ck_assert_ptr_ne(o_strrnchr(str_1, 5, str_2), NULL); ck_assert_ptr_eq(o_strrnchr(str_1, 2, str_2), NULL); ck_assert_ptr_eq(o_strrnchr(str_1, 0, str_2), NULL); ck_assert_ptr_ne(o_strrnchr(str_1, 8, str_2), NULL); ck_assert_ptr_eq(o_strrnchr(NULL, 4, str_2), NULL); } END_TEST START_TEST(test_o_strlen) { ck_assert_int_eq(o_strlen("abcdef"), 6); ck_assert_int_eq(o_strlen(NULL), 0); ck_assert_int_eq(o_strlen(""), 0); } END_TEST START_TEST(test_msprintf) { char * target; char tmp[100]; target = msprintf("target1 %s %d %s %p", "str1", 42, "pl\342\230\272op", NULL); sprintf(tmp, "target1 %s %d %s %p", "str1", 42, "pl\342\230\272op", NULL); ck_assert_str_eq(target, tmp); o_free(target); ck_assert_ptr_eq(msprintf(NULL, "str1", 42, "pl\342\230\272op", NULL), NULL); } END_TEST START_TEST(test_mstrcatf) { char * target; char tmp[200]; target = msprintf("target1 %s %d %s %p", "str1", 42, "pl\342\230\272op", NULL); target = mstrcatf(target, "target2 %s %d %p", "str2", 42, NULL); sprintf(tmp, "target1 str1 42 %s %ptarget2 %s 42 %p", "pl\342\230\272op", NULL, "str2", NULL); ck_assert_str_eq(target, tmp); o_free(target); ck_assert_ptr_eq(msprintf(NULL, NULL, "str1", 42, NULL), NULL); target = NULL; target = mstrcatf(target, "target2 %s %d %s %p", "str2", 42, "pl\342\230\272op", NULL); sprintf(tmp, "target2 %s 42 %s %p", "str2", "pl\342\230\272op", NULL); ck_assert_str_eq(target, tmp); o_free(target); } END_TEST START_TEST(test_trimwhitespace) { char * test1 = o_strdup(" bob trimmed "), * test2 = o_strdup(" \t \t"), * test3 = o_strdup(""); ck_assert_str_eq(trimwhitespace(test1), "bob trimmed"); ck_assert_str_eq(trimwhitespace(test2), ""); ck_assert_str_eq(trimwhitespace(test3), ""); ck_assert_ptr_eq(trimwhitespace(NULL), NULL); o_free(test1); o_free(test2); o_free(test3); } END_TEST START_TEST(test_trimcharacter) { char test1[] = "3bob trimmed33", test2[] = "333", test3[] = ""; ck_assert_str_eq(trimcharacter(test1, '3'), "bob trimmed"); ck_assert_str_eq(trimcharacter(test2, '3'), ""); ck_assert_str_eq(trimcharacter(test3, '3'), ""); ck_assert_ptr_eq(trimcharacter(NULL, '3'), NULL); } END_TEST START_TEST(test_split_string) { char ** array; ck_assert_int_eq(split_string("Alice,Bob,Carol,Dave,Eve,Isaac", ",", &array), 6); free_string_array(array); array = NULL; ck_assert_int_eq(split_string("Alice,Bob,Carol,Dave,Eve,Isaac", " ", &array), 1); free_string_array(array); array = NULL; ck_assert_int_eq(split_string("Alice,Bob,Carol,Dave,Eve,Isaac", ",D", &array), 2); free_string_array(array); array = NULL; ck_assert_int_eq(split_string("Alice,Bob,Carol,Dave,Eve,Isaac", ",g", &array), 1); free_string_array(array); array = NULL; ck_assert_int_eq(split_string("", ",", &array), 1); free_string_array(array); array = NULL; ck_assert_int_eq(split_string(NULL, ",", &array), 0); } END_TEST START_TEST(test_string_array) { char ** array, * str_orig = "Alice,Bob,Carol,Dave,Eve,Isaac"; int size = split_string(str_orig, ",", &array); ck_assert_int_eq(size, 6); ck_assert_int_eq(string_array_has_value((const char **)array, "Alice"), 1); ck_assert_int_eq(string_array_has_value((const char **)array, "Ali"), 0); ck_assert_int_eq(string_array_has_value((const char **)array, "Mallory"), 0); ck_assert_int_eq(string_array_has_value_case((const char **)array, "alice"), 1); ck_assert_int_eq(string_array_has_value_case((const char **)array, "ali"), 0); ck_assert_int_eq(string_array_has_value_case((const char **)array, "mallory"), 0); ck_assert_int_eq(string_array_has_value_n((const char **)array, "Ali", 3), 1); ck_assert_int_eq(string_array_has_value_n((const char **)array, "Aliceeee", 5), 1); ck_assert_int_eq(string_array_has_value_n((const char **)array, "Malloryyyy", 7), 0); ck_assert_int_eq(string_array_has_value_ncase((const char **)array, "aliceeee", 5), 1); ck_assert_int_eq(string_array_has_value_ncase((const char **)array, "malloryyyy", 7), 0); free_string_array(array); } END_TEST START_TEST(test_string_array_has_trimmed_value) { char ** array, * str_orig = "Alice,Bob,Carol,Dave,Eve,Isaac", * str_match_ok = "Carol", * str_match_not_found = "Sam"; int size = split_string(str_orig, ",", &array); ck_assert_int_eq(size, 6); ck_assert_int_eq(string_array_has_trimmed_value((const char **)array, str_match_ok), 1); ck_assert_int_eq(string_array_has_trimmed_value((const char **)array, str_match_not_found), 0); ck_assert_int_eq(string_array_has_trimmed_value((const char **)array, NULL), 0); ck_assert_int_eq(string_array_has_trimmed_value(NULL, str_match_ok), 0); ck_assert_int_eq(string_array_has_trimmed_value(NULL, NULL), 0); free_string_array(array); } END_TEST START_TEST(test_base64) { char * src = "source string", encoded[128] = {0}, decoded[128] = {0}, b64_error[] = ";error;", b64_error_2[] = "c291cmNlIHN0cmluZw=="; size_t encoded_size, decoded_size, b64_error_2_len = 20; ck_assert_int_eq(o_base64_encode((unsigned char *)src, o_strlen(src), (unsigned char *)encoded, &encoded_size), 1); ck_assert_str_eq(encoded, "c291cmNlIHN0cmluZw=="); ck_assert_int_eq(20, encoded_size); ck_assert_int_eq(o_base64_decode((unsigned char *)encoded, encoded_size, (unsigned char *)decoded, &decoded_size), 1); ck_assert_str_eq(decoded, src); ck_assert_int_eq(decoded_size, o_strlen(src)); ck_assert_int_eq(o_base64_decode((unsigned char *)b64_error, o_strlen(b64_error), NULL, &decoded_size), 0); ck_assert_int_eq(o_base64_decode((unsigned char *)b64_error, o_strlen(b64_error), (unsigned char *)decoded, &decoded_size), 0); ck_assert_int_eq(o_base64_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 1); // Insert invalid characters b64_error_2[4] = 0; ck_assert_int_eq(o_base64_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = 2; ck_assert_int_eq(o_base64_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = 11; ck_assert_int_eq(o_base64_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = 128; ck_assert_int_eq(o_base64_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = '='; ck_assert_int_eq(o_base64_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 1); ck_assert_int_gt(o_strlen(src), decoded_size); b64_error_2[4] = '-'; ck_assert_int_eq(o_base64_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = '_'; ck_assert_int_eq(o_base64_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); } END_TEST START_TEST(test_base64_more_test_cases) { const unsigned char message1[] = "C combines the power and performance of assembly language with the flexibility and ease-of-use of assembly language.", message2[] = "Bryan is in\nthe kitchen", message3[] = {0}, message4[] = {0, 0}, message5[] = {0, 0, 0}, message6[] = {0x32, 0x0, 0x0}, message7[] = "ė•„ėŋ ė•„ íŦ니", message8[] = {0x76, 0x65, 0x72, 0x79, 0x00, 0x20, 0x75, 0x6e, 0x75, 0x73, 0x75, 0x61, 0x6c, 0x9b, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67}, message9[] = "\377", message10[] = "\377\377", message11[] = "\377\377\377", message12[] = "\xff\xef"; const unsigned char message1_b64[] = "QyBjb21iaW5lcyB0aGUgcG93ZXIgYW5kIHBlcmZvcm1hbmNlIG9mIGFzc2VtYmx5IGxhbmd1YWdlIHdpdGggdGhlIGZsZXhpYmlsaXR5IGFuZCBlYXNlLW9mLXVzZSBvZiBhc3NlbWJseSBsYW5ndWFnZS4=", message2_b64[] = "QnJ5YW4gaXMgaW4KdGhlIGtpdGNoZW4=", message3_b64[] = "AA==", message4_b64[] = "AAA=", message5_b64[] = "AAAA", message6_b64[] = "MgAA", message7_b64[] = "7JWE7L+g7JWEIO2PrOuLiAA=", message8_b64[] = "dmVyeQAgdW51c3VhbJsgc3RyaW5n", message9_b64[] = "/w==", message10_b64[] = "//8=", message11_b64[] = "////", message12_b64[] = "/+8="; const unsigned char message1_b64url[] = "QyBjb21iaW5lcyB0aGUgcG93ZXIgYW5kIHBlcmZvcm1hbmNlIG9mIGFzc2VtYmx5IGxhbmd1YWdlIHdpdGggdGhlIGZsZXhpYmlsaXR5IGFuZCBlYXNlLW9mLXVzZSBvZiBhc3NlbWJseSBsYW5ndWFnZS4", message2_b64url[] = "QnJ5YW4gaXMgaW4KdGhlIGtpdGNoZW4", message3_b64url[] = "AA", message4_b64url[] = "AAA", message5_b64url[] = "AAAA", message6_b64url[] = "MgAA", message7_b64url[] = "7JWE7L-g7JWEIO2PrOuLiAA", message8_b64url[] = "dmVyeQAgdW51c3VhbJsgc3RyaW5n", message9_b64url[] = "_w", message10_b64url[] = "__8", message11_b64url[] = "____", message12_b64url[] = "_-8"; run_test_base64(message1, o_strlen((const char *)message1), message1_b64, o_strlen((const char *)message1_b64), message1_b64url, o_strlen((const char *)message1_b64url)); run_test_base64(message2, o_strlen((const char *)message2), message2_b64, o_strlen((const char *)message2_b64), message2_b64url, o_strlen((const char *)message2_b64url)); run_test_base64(message3, sizeof(message3), message3_b64, o_strlen((const char *)message3_b64), message3_b64url, o_strlen((const char *)message3_b64url)); run_test_base64(message4, sizeof(message4), message4_b64, o_strlen((const char *)message4_b64), message4_b64url, o_strlen((const char *)message4_b64url)); run_test_base64(message5, sizeof(message5), message5_b64, o_strlen((const char *)message5_b64), message5_b64url, o_strlen((const char *)message5_b64url)); run_test_base64(message6, sizeof(message6), message6_b64, o_strlen((const char *)message6_b64), message6_b64url, o_strlen((const char *)message6_b64url)); run_test_base64(message7, sizeof(message7), message7_b64, o_strlen((const char *)message7_b64), message7_b64url, o_strlen((const char *)message7_b64url)); run_test_base64(message8, sizeof(message8), message8_b64, o_strlen((const char *)message8_b64), message8_b64url, o_strlen((const char *)message8_b64url)); run_test_base64(message9, o_strlen((const char *)message9), message9_b64, o_strlen((const char *)message9_b64), message9_b64url, o_strlen((const char *)message9_b64url)); run_test_base64(message10, o_strlen((const char *)message10), message10_b64, o_strlen((const char *)message10_b64), message10_b64url, o_strlen((const char *)message10_b64url)); run_test_base64(message11, o_strlen((const char *)message11), message11_b64, o_strlen((const char *)message11_b64), message11_b64url, o_strlen((const char *)message11_b64url)); run_test_base64(message12, o_strlen((const char *)message12), message12_b64, o_strlen((const char *)message12_b64), message12_b64url, o_strlen((const char *)message12_b64url)); } END_TEST START_TEST(test_base64url) { char * src = "source string", encoded[128] = {0}, decoded[128] = {0}, b64_error[] = ";error;", b64_error_2[] = "c291cmNlIHN0cmluZw"; size_t encoded_size, decoded_size, b64_error_2_len = 18; ck_assert_int_eq(o_base64url_encode((unsigned char *)src, o_strlen(src), (unsigned char *)encoded, &encoded_size), 1); ck_assert_str_eq(encoded, "c291cmNlIHN0cmluZw"); ck_assert_int_eq(18, encoded_size); ck_assert_int_eq(o_base64url_decode((unsigned char *)encoded, encoded_size, (unsigned char *)decoded, &decoded_size), 1); ck_assert_str_eq(decoded, src); ck_assert_int_eq(decoded_size, o_strlen(src)); ck_assert_int_eq(o_base64url_decode((unsigned char *)b64_error, o_strlen(b64_error), NULL, &decoded_size), 0); ck_assert_int_eq(o_base64url_decode((unsigned char *)b64_error, o_strlen(b64_error), (unsigned char *)decoded, &decoded_size), 0); ck_assert_int_eq(o_base64url_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 1); // Insert invalid characters b64_error_2[4] = 0; ck_assert_int_eq(o_base64url_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = 2; ck_assert_int_eq(o_base64url_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = 11; ck_assert_int_eq(o_base64url_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = 128; ck_assert_int_eq(o_base64url_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = '='; ck_assert_int_eq(o_base64url_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = '+'; ck_assert_int_eq(o_base64url_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); b64_error_2[4] = '/'; ck_assert_int_eq(o_base64url_decode((unsigned char *)b64_error_2, b64_error_2_len, (unsigned char *)decoded, &decoded_size), 0); } END_TEST START_TEST(test_base64url_2_base64) { unsigned char src[10] = {0x6f, 0x5b, 0x70, 0x29, 0x27, 0x2d, 0x3d, 0x40, 0x7e, 0x0}, encoded[21] = {0}, encoded_url[21] = {0}, encoded_new[19] = {0}; size_t encoded_size = 0, encoded_new_size = 0; ck_assert_int_eq(o_base64_encode(src, 10, encoded, &encoded_size), 1); ck_assert_int_gt(encoded_size, 0); encoded[encoded_size] = '\0'; // should be "b1twKSctPUB+AA==" ck_assert_int_eq(o_base64url_encode(src, 10, encoded_url, &encoded_size), 1); ck_assert_int_gt(encoded_size, 0); encoded_url[encoded_size] = '\0'; // should be "b1twKSctPUB-AA" ck_assert_str_ne((const char *)encoded_url, (const char *)encoded); ck_assert_int_eq(o_base64url_2_base64(encoded_url, encoded_size, encoded_new, &encoded_new_size), 1); encoded_new[encoded_new_size] = '\0'; ck_assert_str_eq((const char *)encoded_new, (const char *)encoded); } END_TEST START_TEST(test_base64_2_base64url) { unsigned char src[10] = {0x6f, 0x5b, 0x70, 0x29, 0x27, 0x2d, 0x3d, 0x40, 0x7e, 0x0}, encoded[21] = {0}, encoded_url[21] = {0}, encoded_new[19] = {0}; size_t encoded_size = 0, encoded_new_size = 0; ck_assert_int_eq(o_base64url_encode(src, 10, encoded, &encoded_size), 1); ck_assert_int_gt(encoded_size, 0); encoded[encoded_size] = '\0'; // should be "b1twKSctPUB-AA" ck_assert_int_eq(o_base64_encode(src, 10, encoded_url, &encoded_size), 1); ck_assert_int_gt(encoded_size, 0); encoded_url[encoded_size] = '\0'; // should be "b1twKSctPUB+AA==" ck_assert_str_ne((const char *)encoded_url, (const char *)encoded); ck_assert_int_eq(o_base64_2_base64url(encoded_url, encoded_size, encoded_new, &encoded_new_size), 1); encoded_new[encoded_new_size] = '\0'; ck_assert_str_eq((const char *)encoded_new, (const char *)encoded); } END_TEST START_TEST(test_base64_len) { char * src1 = "a", * src2 = "aa", * src3 = "aaa", * src4 = "aaaa", * src5 = "aaaaa", * src = "source string", encoded[128] = {0}; char * src1_enc = "YQ==", * src2_enc = "YWE=", * src3_enc = "YWFh", *src4_enc = "YWFhYQ==", *src5_enc = "YWFhYWE="; size_t encoded_size, decoded_size; ck_assert_int_eq(o_base64_encode((unsigned char *)src, o_strlen(src), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 20); ck_assert_int_eq(o_base64_encode((unsigned char *)src, o_strlen(src), (unsigned char *)encoded, &encoded_size), 1); ck_assert_int_eq(o_base64_decode((unsigned char *)encoded, encoded_size, NULL, &decoded_size), 1); ck_assert_int_eq(decoded_size, 13); ck_assert_int_eq(o_base64url_encode((unsigned char *)src, o_strlen(src), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 18); ck_assert_int_eq(o_base64url_encode((unsigned char *)src, o_strlen(src), (unsigned char *)encoded, &encoded_size), 1); ck_assert_int_eq(o_base64url_decode((unsigned char *)encoded, encoded_size, NULL, &decoded_size), 1); ck_assert_int_eq(decoded_size, 13); ck_assert_int_eq(o_base64_encode((unsigned char *)src1, o_strlen(src1), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 4); ck_assert_int_eq(o_base64_encode((unsigned char *)src2, o_strlen(src2), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 4); ck_assert_int_eq(o_base64_encode((unsigned char *)src3, o_strlen(src3), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 4); ck_assert_int_eq(o_base64_encode((unsigned char *)src4, o_strlen(src4), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 8); ck_assert_int_eq(o_base64_encode((unsigned char *)src5, o_strlen(src5), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 8); ck_assert_int_eq(o_base64url_encode((unsigned char *)src1, o_strlen(src1), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 2); ck_assert_int_eq(o_base64url_encode((unsigned char *)src2, o_strlen(src2), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 3); ck_assert_int_eq(o_base64url_encode((unsigned char *)src3, o_strlen(src3), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 4); ck_assert_int_eq(o_base64url_encode((unsigned char *)src4, o_strlen(src4), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 6); ck_assert_int_eq(o_base64url_encode((unsigned char *)src5, o_strlen(src5), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 7); ck_assert_int_eq(o_base64_decode((unsigned char *)src1_enc, o_strlen(src1_enc), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 1); ck_assert_int_eq(o_base64_decode((unsigned char *)src2_enc, o_strlen(src2_enc), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 2); ck_assert_int_eq(o_base64_decode((unsigned char *)src3_enc, o_strlen(src3_enc), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 3); ck_assert_int_eq(o_base64_decode((unsigned char *)src4_enc, o_strlen(src4_enc), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 4); ck_assert_int_eq(o_base64_decode((unsigned char *)src5_enc, o_strlen(src5_enc), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 5); ck_assert_int_eq(o_base64url_decode((unsigned char *)src1_enc, o_strlen(src1_enc)-2, NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 1); ck_assert_int_eq(o_base64url_decode((unsigned char *)src2_enc, o_strlen(src2_enc)-1, NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 2); ck_assert_int_eq(o_base64url_decode((unsigned char *)src3_enc, o_strlen(src3_enc), NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 3); ck_assert_int_eq(o_base64url_decode((unsigned char *)src4_enc, o_strlen(src4_enc)-2, NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 4); ck_assert_int_eq(o_base64url_decode((unsigned char *)src5_enc, o_strlen(src5_enc)-1, NULL, &encoded_size), 1); ck_assert_int_eq(encoded_size, 5); } END_TEST START_TEST(test_base64_alloc) { char * src = "source string", b64_error[] = ";error;"; struct _o_datum dat = {0, NULL}, dat_dec = {0, NULL}; ck_assert_int_eq(o_base64_encode_alloc((unsigned char *)src, o_strlen(src), &dat), 1); ck_assert_int_eq(20, dat.size); ck_assert_int_eq(0, o_strncmp((const char *)dat.data, "c291cmNlIHN0cmluZw==", dat.size)); ck_assert_int_eq(o_base64_decode_alloc(dat.data, dat.size, &dat_dec), 1); ck_assert_int_eq(dat_dec.size, o_strlen(src)); ck_assert_int_eq(0, o_strncmp((const char *)dat_dec.data, src, dat_dec.size)); ck_assert_int_eq(o_base64_decode_alloc((unsigned char *)b64_error, o_strlen(b64_error), &dat_dec), 0); o_free(dat.data); o_free(dat_dec.data); } END_TEST START_TEST(test_base64url_alloc) { char * src = "source string", b64_error[] = ";error;"; struct _o_datum dat = {0, NULL}, dat_dec = {0, NULL}; ck_assert_int_eq(o_base64url_encode_alloc((unsigned char *)src, o_strlen(src), &dat), 1); ck_assert_int_eq(18, dat.size); ck_assert_int_eq(0, o_strncmp((const char *)dat.data, "c291cmNlIHN0cmluZw", dat.size)); ck_assert_int_eq(o_base64url_decode_alloc(dat.data, dat.size, &dat_dec), 1); ck_assert_int_eq(dat_dec.size, o_strlen(src)); ck_assert_int_eq(0, o_strncmp((const char *)dat_dec.data, src, dat_dec.size)); ck_assert_int_eq(o_base64url_decode_alloc((unsigned char *)b64_error, o_strlen(b64_error), &dat_dec), 0); o_free(dat.data); o_free(dat_dec.data); } END_TEST START_TEST(test_base64_more_test_cases_alloc) { const unsigned char message1[] = "C combines the power and performance of assembly language with the flexibility and ease-of-use of assembly language.", message2[] = "Bryan is in\nthe kitchen", message3[] = {0}, message4[] = {0, 0}, message5[] = {0, 0, 0}, message6[] = {0x32, 0x0, 0x0}, message7[] = "ė•„ėŋ ė•„ íŦ니", message8[] = {0x76, 0x65, 0x72, 0x79, 0x00, 0x20, 0x75, 0x6e, 0x75, 0x73, 0x75, 0x61, 0x6c, 0x9b, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67}, message9[] = "\377", message10[] = "\377\377", message11[] = "\377\377\377", message12[] = "\xff\xef"; const unsigned char message1_b64[] = "QyBjb21iaW5lcyB0aGUgcG93ZXIgYW5kIHBlcmZvcm1hbmNlIG9mIGFzc2VtYmx5IGxhbmd1YWdlIHdpdGggdGhlIGZsZXhpYmlsaXR5IGFuZCBlYXNlLW9mLXVzZSBvZiBhc3NlbWJseSBsYW5ndWFnZS4=", message2_b64[] = "QnJ5YW4gaXMgaW4KdGhlIGtpdGNoZW4=", message3_b64[] = "AA==", message4_b64[] = "AAA=", message5_b64[] = "AAAA", message6_b64[] = "MgAA", message7_b64[] = "7JWE7L+g7JWEIO2PrOuLiAA=", message8_b64[] = "dmVyeQAgdW51c3VhbJsgc3RyaW5n", message9_b64[] = "/w==", message10_b64[] = "//8=", message11_b64[] = "////", message12_b64[] = "/+8="; const unsigned char message1_b64url[] = "QyBjb21iaW5lcyB0aGUgcG93ZXIgYW5kIHBlcmZvcm1hbmNlIG9mIGFzc2VtYmx5IGxhbmd1YWdlIHdpdGggdGhlIGZsZXhpYmlsaXR5IGFuZCBlYXNlLW9mLXVzZSBvZiBhc3NlbWJseSBsYW5ndWFnZS4", message2_b64url[] = "QnJ5YW4gaXMgaW4KdGhlIGtpdGNoZW4", message3_b64url[] = "AA", message4_b64url[] = "AAA", message5_b64url[] = "AAAA", message6_b64url[] = "MgAA", message7_b64url[] = "7JWE7L-g7JWEIO2PrOuLiAA", message8_b64url[] = "dmVyeQAgdW51c3VhbJsgc3RyaW5n", message9_b64url[] = "_w", message10_b64url[] = "__8", message11_b64url[] = "____", message12_b64url[] = "_-8"; run_test_base64_alloc(message1, o_strlen((const char *)message1), message1_b64, o_strlen((const char *)message1_b64), message1_b64url, o_strlen((const char *)message1_b64url)); run_test_base64_alloc(message2, o_strlen((const char *)message2), message2_b64, o_strlen((const char *)message2_b64), message2_b64url, o_strlen((const char *)message2_b64url)); run_test_base64_alloc(message3, sizeof(message3), message3_b64, o_strlen((const char *)message3_b64), message3_b64url, o_strlen((const char *)message3_b64url)); run_test_base64_alloc(message4, sizeof(message4), message4_b64, o_strlen((const char *)message4_b64), message4_b64url, o_strlen((const char *)message4_b64url)); run_test_base64_alloc(message5, sizeof(message5), message5_b64, o_strlen((const char *)message5_b64), message5_b64url, o_strlen((const char *)message5_b64url)); run_test_base64_alloc(message6, sizeof(message6), message6_b64, o_strlen((const char *)message6_b64), message6_b64url, o_strlen((const char *)message6_b64url)); run_test_base64_alloc(message7, sizeof(message7), message7_b64, o_strlen((const char *)message7_b64), message7_b64url, o_strlen((const char *)message7_b64url)); run_test_base64_alloc(message8, sizeof(message8), message8_b64, o_strlen((const char *)message8_b64), message8_b64url, o_strlen((const char *)message8_b64url)); run_test_base64_alloc(message9, o_strlen((const char *)message9), message9_b64, o_strlen((const char *)message9_b64), message9_b64url, o_strlen((const char *)message9_b64url)); run_test_base64_alloc(message10, o_strlen((const char *)message10), message10_b64, o_strlen((const char *)message10_b64), message10_b64url, o_strlen((const char *)message10_b64url)); run_test_base64_alloc(message11, o_strlen((const char *)message11), message11_b64, o_strlen((const char *)message11_b64), message11_b64url, o_strlen((const char *)message11_b64url)); run_test_base64_alloc(message12, o_strlen((const char *)message12), message12_b64, o_strlen((const char *)message12_b64), message12_b64url, o_strlen((const char *)message12_b64url)); } END_TEST START_TEST(test_base64url_2_base64_alloc) { unsigned char src[10] = {0x6f, 0x5b, 0x70, 0x29, 0x27, 0x2d, 0x3d, 0x40, 0x7e, 0x0}; struct _o_datum dat = {0, NULL}, dat_url = {0, NULL}, dat_conv = {0, NULL}; ck_assert_int_eq(o_base64_encode_alloc(src, 10, &dat), 1); ck_assert_int_gt(dat.size, 0); ck_assert_int_eq(o_base64url_encode_alloc(src, 10, &dat_url), 1); ck_assert_int_gt(dat_url.size, 0); ck_assert_int_ne(0, memcmp((const char *)dat.data, (const char *)dat_url.data, dat.size)); ck_assert_int_eq(o_base64url_2_base64_alloc(dat_url.data, dat_url.size, &dat_conv), 1); ck_assert_int_eq(dat.size, dat_conv.size); ck_assert_int_eq(0, memcmp(dat_conv.data, dat.data, dat_conv.size)); o_free(dat.data); o_free(dat_url.data); o_free(dat_conv.data); } END_TEST START_TEST(test_base64_2_base64url_alloc) { unsigned char src[10] = {0x6f, 0x5b, 0x70, 0x29, 0x27, 0x2d, 0x3d, 0x40, 0x7e, 0x0}; struct _o_datum dat = {0, NULL}, dat_url = {0, NULL}, dat_conv = {0, NULL}; ck_assert_int_eq(o_base64_encode_alloc(src, 10, &dat), 1); ck_assert_int_gt(dat.size, 0); ck_assert_int_eq(o_base64url_encode_alloc(src, 10, &dat_url), 1); ck_assert_int_gt(dat_url.size, 0); ck_assert_int_ne(0, memcmp((const char *)dat.data, (const char *)dat_url.data, dat.size)); ck_assert_int_eq(o_base64_2_base64url_alloc(dat.data, dat.size, &dat_conv), 1); ck_assert_int_eq(dat_url.size, dat_conv.size); ck_assert_int_eq(0, memcmp(dat_conv.data, dat_url.data, dat_conv.size)); o_free(dat.data); o_free(dat_url.data); o_free(dat_conv.data); } END_TEST START_TEST(test_str_null_or_empty) { char a[1] = {0}, * b = NULL, c[] = "test"; ck_assert_int_eq(1, o_strnullempty(a)); ck_assert_int_eq(1, o_strnullempty(b)); ck_assert_int_eq(0, o_strnullempty(c)); c[2] = '\0'; ck_assert_int_eq(0, o_strnullempty(c)); c[0] = '\0'; ck_assert_int_eq(1, o_strnullempty(c)); } END_TEST static Suite *orcania_suite(void) { Suite *s; TCase *tc_core; s = suite_create("Orcania tests string functions"); tc_core = tcase_create("test_orcania_str"); tcase_add_test(tc_core, test_str_replace); tcase_add_test(tc_core, test_o_strdup); tcase_add_test(tc_core, test_o_strndup); tcase_add_test(tc_core, test_o_strcmp); tcase_add_test(tc_core, test_o_strncmp); tcase_add_test(tc_core, test_o_strcasecmp); tcase_add_test(tc_core, test_o_strncasecmp); tcase_add_test(tc_core, test_o_strcpy); tcase_add_test(tc_core, test_o_strncpy); tcase_add_test(tc_core, test_o_strstr); tcase_add_test(tc_core, test_o_strnstr); tcase_add_test(tc_core, test_o_strchr); tcase_add_test(tc_core, test_o_strnchr); tcase_add_test(tc_core, test_o_strrchr); tcase_add_test(tc_core, test_o_strrnchr); tcase_add_test(tc_core, test_o_strlen); tcase_add_test(tc_core, test_msprintf); tcase_add_test(tc_core, test_mstrcatf); tcase_add_test(tc_core, test_trimwhitespace); tcase_add_test(tc_core, test_trimcharacter); tcase_add_test(tc_core, test_base64); tcase_add_test(tc_core, test_base64_more_test_cases); tcase_add_test(tc_core, test_base64url); tcase_add_test(tc_core, test_base64url_2_base64); tcase_add_test(tc_core, test_base64_2_base64url); tcase_add_test(tc_core, test_base64_len); tcase_add_test(tc_core, test_base64_alloc); tcase_add_test(tc_core, test_base64url_alloc); tcase_add_test(tc_core, test_base64_more_test_cases_alloc); tcase_add_test(tc_core, test_base64url_2_base64_alloc); tcase_add_test(tc_core, test_base64_2_base64url_alloc); tcase_add_test(tc_core, test_split_string); tcase_add_test(tc_core, test_string_array); tcase_add_test(tc_core, test_string_array_has_trimmed_value); tcase_add_test(tc_core, test_str_null_or_empty); tcase_set_timeout(tc_core, 30); suite_add_tcase(s, tc_core); return s; } int main(int argc, char *argv[]) { int number_failed; Suite *s; SRunner *sr; s = orcania_suite(); sr = srunner_create(s); srunner_run_all(sr, CK_VERBOSE); number_failed = srunner_ntests_failed(sr); srunner_free(sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } orcania-2.3.3/tools/000077500000000000000000000000001446552024700143045ustar00rootroot00000000000000orcania-2.3.3/tools/base64url/000077500000000000000000000000001446552024700161135ustar00rootroot00000000000000orcania-2.3.3/tools/base64url/.gitignore000066400000000000000000000000301446552024700200740ustar00rootroot00000000000000base64url valgrind*.txt orcania-2.3.3/tools/base64url/Makefile000066400000000000000000000045031446552024700175550ustar00rootroot00000000000000# # base64url: Base64Url encode or decode FILE, or standard input, to standard output. # # Makefile used to build the software # # Copyright 2021-2022 Nicolas Mora # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU GENERAL PUBLIC LICENSE # License as published by the Free Software Foundation; # version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # # You should have received a copy of the GNU General Public # License along with this program. If not, see . # CC=gcc ORCANIA_INCLUDE=../../include ORCANIA_LOCATION=../../src DESTDIR=/usr/local CFLAGS+=-Wall -I$(ORCANIA_INCLUDE) $(ADDITIONALFLAGS) $(CPPFLAGS) LIBS=-lc -lorcania -L$(ORCANIA_LOCATION) ORCANIA_LIBRARY=../../src/liborcania.so VALGRIND_COMMAND=valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes all: base64url all: ADDITIONALFLAGS= -O3 clean: rm -f *.o base64url *.b64 debug: base64url debug: ADDITIONALFLAGS=-DDEBUG -g -O0 $(ORCANIA_LIBRARY): cd $(ORCANIA_LOCATION) && $(MAKE) debug base64url: $(ORCANIA_LIBRARY) base64url.c $(CC) -o base64url $(CFLAGS) base64url.c $(LIBS) install: base64url mkdir -p $(DESTDIR)/bin $(DESTDIR)/man/man1/ install -m755 base64url $(DESTDIR)/bin install -m644 base64url.1 $(DESTDIR)/man/man1/ uninstall: rm -f $(DESTDIR)/bin/base64url manpage: base64url help2man ./base64url -s 1 -n "Base64Url encode or decode FILE, or standard input, to standard output." > base64url.1 test: base64url echo plop | LD_LIBRARY_PATH=$(ORCANIA_LOCATION) $(VALGRIND_COMMAND) ./base64url LD_LIBRARY_PATH=$(ORCANIA_LOCATION) $(VALGRIND_COMMAND) ./base64url -f README.md LD_LIBRARY_PATH=$(ORCANIA_LOCATION) $(VALGRIND_COMMAND) ./base64url -f error || true echo ";error;" | LD_LIBRARY_PATH=$(ORCANIA_LOCATION) $(VALGRIND_COMMAND) ./base64url -d || true echo Z3J1dAo | LD_LIBRARY_PATH=$(ORCANIA_LOCATION) $(VALGRIND_COMMAND) ./base64url -d echo ZuJ1dAo | LD_LIBRARY_PATH=$(ORCANIA_LOCATION) $(VALGRIND_COMMAND) ./base64url -d -i echo plop | LD_LIBRARY_PATH=$(ORCANIA_LOCATION) $(VALGRIND_COMMAND) ./base64url -w 2 orcania-2.3.3/tools/base64url/README.md000066400000000000000000000012611446552024700173720ustar00rootroot00000000000000# base64url: Base64Url encode or decode FILE, or standard input, to standard output. Copyright 2021-2022 Nicolas Mora This program is free software; you can redistribute it and/or modify it under the terms of the GPL3 License. ## Options Options available: ```shell -d, --decode Decode data -i, --ignore-garbage when decoding, ignore non-alphabet characters -w, --wrap wrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping -f, --file Encode or decode FILE_NAME content - if this option is missing, red from stdin -h, --help display this help and exit -v, --version output version information and exit ``` orcania-2.3.3/tools/base64url/base64url.1000066400000000000000000000027761446552024700200200ustar00rootroot00000000000000.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.1. .TH BASE64URL "1" "March 2022" "base64url 0.9" "User Commands" .SH NAME base64url \- Base64Url encode or decode FILE, or standard input, to standard output. .SH SYNOPSIS .B base64url [\fI\,OPTIONS\/\fR] .SH DESCRIPTION base64url \- Base64Url encode or decode FILE, or standard input, to standard output. .PP Version 0.9 .SH COPYRIGHT Copyright 2021\-2022 Nicolas Mora .PP This program is free software; you can redistribute it and/or modify it under the terms of the GPL 3 .PP Command\-line options: .PP \fB\-d\fR, \fB\-\-decode\fR .IP Decode data .PP \fB\-i\fR, \fB\-\-ignore\-garbage\fR .IP when decoding, ignore non\-alphabet characters .PP \fB\-w\fR, \fB\-\-wrap\fR .TP wrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping .PP \fB\-f\fR, \fB\-\-file\fR .IP Encode or decode FILE_NAME content \- if this option is missing, red from stdin .PP \fB\-h\fR, \fB\-\-help\fR .IP display this help and exit .PP \fB\-v\fR, \fB\-\-version\fR .IP output version information and exit .PP .br Copyright 2021\-2022 Nicolas Mora This program is free software; you can redistribute it and/or modify it under the terms of the GPL 3 .SH "SEE ALSO" The full documentation for .B base64url is maintained as a Texinfo manual. If the .B info and .B base64url programs are properly installed at your site, the command .IP .B info base64url .PP should give you access to the complete manual. orcania-2.3.3/tools/base64url/base64url.c000066400000000000000000000204351446552024700200720ustar00rootroot00000000000000/** * * base64url: Base64Url encode or decode FILE, or standard input, to standard output. * * Copyright 2021-2022 Nicolas Mora * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; * version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see . * */ #include #include #include #include #include #ifdef _MSC_VER #include #include typedef SSIZE_T ssize_t; #else #include #endif #define _BASE64URL_VERSION "0.9" #define ACTION_ENCODE 0 #define ACTION_DECODE 1 #define DEFAULT_WRAP 76 #define SIZE 100 static void print_output(const unsigned char * output, size_t output_len, unsigned long int wrap, short int ignore) { size_t i; for (i=0; i\n"); fprintf(output, "\n"); fprintf(output, "This program is free software; you can redistribute it and/or\n"); fprintf(output, "modify it under the terms of the GPL 3\n"); fprintf(output, "\n"); fprintf(output, "Command-line options:\n"); fprintf(output, "\n"); fprintf(output, "-d, --decode\n"); fprintf(output, "\tDecode data\n"); fprintf(output, "-i, --ignore-garbage\n"); fprintf(output, "\twhen decoding, ignore non-alphabet characters\n"); fprintf(output, "-w, --wrap \n"); fprintf(output, "\twrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping\n"); fprintf(output, "-f, --file \n"); fprintf(output, "\tEncode or decode FILE_NAME content - if this option is missing, red from stdin\n"); fprintf(output, "-h, --help\n"); fprintf(output, "\tdisplay this help and exit\n"); fprintf(output, "-v, --version\n"); fprintf(output, "\toutput version information and exit\n"); } static unsigned char * get_file_content(const char * file_path, size_t * length) { unsigned char * buffer = NULL; size_t res; FILE * f; f = fopen (file_path, "rb"); if (f) { fseek (f, 0, SEEK_END); *length = (size_t)ftell (f); fseek (f, 0, SEEK_SET); buffer = o_malloc(((*length)+1)*sizeof(char)); if (buffer) { res = fread (buffer, 1, *length, f); if (res != *length) { fprintf(stderr, "fread warning, reading %zu while expecting %zu", res, *length); } } fclose (f); } else { fprintf(stderr, "error opening file %s\n", file_path); } return buffer; } static unsigned char * get_stdin_content(size_t * length) { unsigned char * out = NULL, buffer[SIZE]; ssize_t read_length; *length = 0; while ((read_length = read(0, buffer, SIZE)) > 0) { out = o_realloc(out, (*length)+(size_t)read_length+1); memcpy(out+(*length), buffer, (size_t)read_length); (*length) += (size_t)read_length; out[(*length)] = '\0'; } if ((*length) && (out[(*length)-1] == '\n' || out[(*length)-1] == '\r')) { out[(*length)-1] = '\0'; (*length)--; } return out; } int main(int argc, char ** argv) { short int action = ACTION_ENCODE, ignore = 0; unsigned long int wrap = DEFAULT_WRAP; long unsigned int s_wrap = 0; const char * short_options = "d::i::w:f:v::h"; int next_option, ret = 0, exit_loop = 0; char * file = NULL, * endptr = NULL, * tmp = NULL; unsigned char * input = NULL, * output = NULL; size_t input_len = 0, output_len = 0; static const struct option long_options[]= { {"decode", no_argument, NULL, 'd'}, {"ignore-garbage", no_argument, NULL, 'i'}, {"wrap", required_argument, NULL, 'w'}, {"file", required_argument, NULL, 'f'}, {"version", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; do { next_option = getopt_long(argc, argv, short_options, long_options, NULL); switch (next_option) { case 'd': action = ACTION_DECODE; break; case 'i': ignore = 1; break; case 'w': s_wrap = strtoul(optarg, &endptr, 10); if (*endptr == '\0' && s_wrap) { wrap = (unsigned long int)s_wrap; } else { print_help(stderr, argv[0]); exit_loop = 1; ret = 1; } break; case 'f': o_free(file); file = o_strdup(optarg); break; case 'v': fprintf(stdout, "%s %s\n", argv[0], _BASE64URL_VERSION); fprintf(stdout, "Copyright 2021-2022 Nicolas Mora \n"); fprintf(stdout, "This program is free software; you can redistribute it and/or\n"); fprintf(stdout, "modify it under the terms of the GPL 3\n"); exit_loop = 1; break; case 'h': print_help(stdout, argv[0]); exit_loop = 1; break; default: break; } } while (next_option != -1 && !exit_loop); if (!exit_loop) { if (file != NULL) { input = get_file_content(file, &input_len); } else { input = get_stdin_content(&input_len); } if (input != NULL && input_len) { if (action == ACTION_ENCODE) { if (o_base64url_encode(input, input_len, NULL, &output_len)) { if (output_len) { if ((output = o_malloc(output_len+4)) != NULL) { if (o_base64url_encode(input, input_len, output, &output_len)) { print_output(output, output_len, wrap, ignore); } else { fprintf(stderr, "%s: Error encoding\n", argv[0]); } } else { fprintf(stderr, "%s: Error encoding\n", argv[0]); } } else { fprintf(stderr, "%s: Error encoding\n", argv[0]); } } else { fprintf(stderr, "%s: Error encoding\n", argv[0]); } } else { tmp = str_replace((const char *)input, " ", ""); o_free(input); input = (unsigned char *)tmp; tmp = str_replace((const char *)input, "\n", ""); o_free(input); input = (unsigned char *)tmp; tmp = str_replace((const char *)input, "\t", ""); o_free(input); input = (unsigned char *)tmp; tmp = str_replace((const char *)input, "\v", ""); o_free(input); input = (unsigned char *)tmp; tmp = str_replace((const char *)input, "\f", ""); o_free(input); input = (unsigned char *)tmp; tmp = str_replace((const char *)input, "\r", ""); o_free(input); input = (unsigned char *)tmp; input_len = o_strlen((const char *)input); if (o_base64url_decode(input, input_len, NULL, &output_len)) { if (output_len) { if ((output = o_malloc(output_len+4)) != NULL) { if (o_base64url_decode(input, input_len, output, &output_len)) { print_output(output, output_len, 0, ignore); } else { fprintf(stderr, "%s: invalid input\n", argv[0]); ret = 1; } } else { fprintf(stderr, "%s: Error decoding\n", argv[0]); ret = 1; } } else { fprintf(stderr, "%s: invalid input\n", argv[0]); ret = 1; } } else { fprintf(stderr, "%s: invalid input\n", argv[0]); ret = 1; } } } else { fprintf(stderr, "-- Error no input --\n"); print_help(stderr, argv[0]); ret = 1; } o_free(input); o_free(output); } o_free(file); return ret; }