From cf425b30e8b01858a2247f0aacd0569394ae85c6 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sat, 23 Dec 2023 08:16:51 +0100 Subject: [PATCH 01/11] cmake: add RE_LIBS config and add atomic check (#1029) * cmake: add RE_LIBS config and add atomic check * test c11 flag * replace with c++ atomic check * ci/musl: add g++ * fix cxx_source --- .github/workflows/musl.yml | 2 +- CMakeLists.txt | 48 +----------------------- cmake/re-config.cmake | 76 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 47 deletions(-) diff --git a/.github/workflows/musl.yml b/.github/workflows/musl.yml index 58eb63f96..b2e51f464 100644 --- a/.github/workflows/musl.yml +++ b/.github/workflows/musl.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v3 - name: install devel tools run: | - apk add musl-dev git cmake gcc make binutils openssl-dev linux-headers zlib-dev ninja + apk add musl-dev git cmake gcc g++ make binutils openssl-dev linux-headers zlib-dev ninja - name: make run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dca56d73..c6c6a392b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -607,50 +607,6 @@ if(USE_REM) endif() -############################################################################## -# -# Linking LIBS -# - -set(LINKLIBS Threads::Threads ${RESOLV_LIBRARY}) - -if(BACKTRACE_FOUND) - list(APPEND LINKLIBS ${Backtrace_LIBRARIES}) -endif() - -if(ZLIB_FOUND) - list(APPEND LINKLIBS ZLIB::ZLIB) -endif() - -if(USE_OPENSSL) - list(APPEND LINKLIBS OpenSSL::SSL OpenSSL::Crypto) -endif() - -if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - list(APPEND LINKLIBS - "-framework SystemConfiguration" "-framework CoreFoundation" - ) -endif() - -if(WIN32) - list(APPEND LINKLIBS - qwave - iphlpapi - wsock32 - ws2_32 - dbghelp - ) -else() - list(APPEND LINKLIBS m) -endif() - -if(UNIX) - list(APPEND LINKLIBS - ${CMAKE_DL_LIBS} - ) -endif() - - ############################################################################## # # Main target object @@ -675,7 +631,7 @@ target_include_directories(re-objs PRIVATE if(LIBRE_BUILD_SHARED) list(APPEND RE_INSTALL_TARGETS re-shared) add_library(re-shared SHARED $) - target_link_libraries(re-shared PRIVATE ${LINKLIBS}) + target_link_libraries(re-shared PRIVATE ${RE_LIBS}) set_target_properties(re-shared PROPERTIES VERSION ${PROJECT_SOVERSION}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) set_target_properties(re-shared PROPERTIES SOVERSION ${PROJECT_SOVERSION}) @@ -692,7 +648,7 @@ endif() if(LIBRE_BUILD_STATIC) list(APPEND RE_INSTALL_TARGETS re) add_library(re STATIC $) - target_link_libraries(re PUBLIC ${LINKLIBS}) + target_link_libraries(re PUBLIC ${RE_LIBS}) target_include_directories(re PUBLIC $ ) diff --git a/cmake/re-config.cmake b/cmake/re-config.cmake index 6dc0ad8b6..68c0c80cd 100644 --- a/cmake/re-config.cmake +++ b/cmake/re-config.cmake @@ -2,6 +2,7 @@ include(CheckIncludeFile) include(CheckFunctionExists) include(CheckSymbolExists) include(CheckTypeSize) +include(CheckCXXSourceCompiles) option(USE_MBEDTLS "Enable MbedTLS" OFF) @@ -214,3 +215,78 @@ if(NOT ${CMAKE_BUILD_TYPE} MATCHES "[Rr]el") set(CMAKE_ENABLE_EXPORTS ON) endif() endif() + + +############################################################################## +# +# Linking LIBS +# + +set(RE_LIBS Threads::Threads ${RESOLV_LIBRARY}) + +if(BACKTRACE_FOUND) + list(APPEND RE_LIBS ${Backtrace_LIBRARIES}) +endif() + +if(ZLIB_FOUND) + list(APPEND RE_LIBS ZLIB::ZLIB) +endif() + +if(USE_OPENSSL) + list(APPEND RE_LIBS OpenSSL::SSL OpenSSL::Crypto) +endif() + +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + list(APPEND RE_LIBS + "-framework SystemConfiguration" "-framework CoreFoundation" + ) +endif() + +if(WIN32) + list(APPEND RE_LIBS + qwave + iphlpapi + wsock32 + ws2_32 + dbghelp + ) +else() + list(APPEND RE_LIBS m) +endif() + +if(UNIX) + list(APPEND RE_LIBS + ${CMAKE_DL_LIBS} + ) +endif() + + +############################################################################## +# +# Testing Atomic +# + +enable_language(CXX) + +set(ATOMIC_TEST_CODE " + #include + #include + std::atomic n8 (0); // riscv64 + std::atomic n64 (0); // armel, mipsel, powerpc + int main() { + ++n8; + ++n64; + return 0; + }") + +check_cxx_source_compiles("${ATOMIC_TEST_CODE}" atomic_test) + +if(NOT atomic_test) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} atomic) + check_cxx_source_compiles("${ATOMIC_TEST_CODE}" atomic_test_lib) + if(NOT atomic_test_lib) + message(FATAL_ERROR "No builtin or libatomic support") + else() + list(APPEND RE_LIBS atomic) + endif() +endif() From 44d65e1b2ace98b294df3d3bc12dd368b78de222 Mon Sep 17 00:00:00 2001 From: Robert Scheck Date: Mon, 25 Dec 2023 14:49:44 +0100 Subject: [PATCH 02/11] ci: use actions/checkout@v4 (#1031) --- .github/workflows/abi.yml | 4 ++-- .github/workflows/android.yml | 2 +- .github/workflows/build.yml | 2 +- .github/workflows/clang-analyze.yml | 2 +- .github/workflows/cmake_win.yml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/coverage.yml | 2 +- .github/workflows/coverity.yml | 2 +- .github/workflows/fedora.yml | 2 +- .github/workflows/freebsd.yml | 2 +- .github/workflows/ios.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/mingw.yml | 6 +++--- .github/workflows/musl.yml | 2 +- .github/workflows/sanitizers.yml | 2 +- .github/workflows/sonar.yml | 2 +- .github/workflows/ssl.yml | 2 +- .github/workflows/strict-c.yml | 2 +- .github/workflows/valgrind.yml | 2 +- 19 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/abi.yml b/.github/workflows/abi.yml index 4dd1dd74e..4f282c138 100644 --- a/.github/workflows/abi.yml +++ b/.github/workflows/abi.yml @@ -7,12 +7,12 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: 'v3.6.0' path: old - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: path: current diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 435d6c392..fc73f06a5 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: "build openssl" run: | diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 36c20691e..f3f03d15b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: CMAKE_GENERATOR: Ninja steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: openssl path macos if: ${{ runner.os == 'macOS' }} diff --git a/.github/workflows/clang-analyze.yml b/.github/workflows/clang-analyze.yml index b38b91c4c..10de2c285 100644 --- a/.github/workflows/clang-analyze.yml +++ b/.github/workflows/clang-analyze.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: fix flaky azure mirrors if: ${{ runner.os == 'Linux' }} diff --git a/.github/workflows/cmake_win.yml b/.github/workflows/cmake_win.yml index ea4efd484..eb3ae8eb0 100644 --- a/.github/workflows/cmake_win.yml +++ b/.github/workflows/cmake_win.yml @@ -59,7 +59,7 @@ jobs: } steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install OpenSSL if: ${{ matrix.config.openssl }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 552885a78..cf5baf6fb 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Initialize CodeQL uses: github/codeql-action/init@v2 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index efe333be7..96294ba79 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -16,7 +16,7 @@ jobs: CMAKE_GENERATOR: Ninja steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: fix flaky azure mirrors if: ${{ runner.os == 'Linux' }} diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 311e91177..07b23ac2d 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Prepare run: cmake -B ${{github.workspace}}/build - uses: vapier/coverity-scan-action@v1 diff --git a/.github/workflows/fedora.yml b/.github/workflows/fedora.yml index 010a0b96c..66f41db31 100644 --- a/.github/workflows/fedora.yml +++ b/.github/workflows/fedora.yml @@ -23,7 +23,7 @@ jobs: CMAKE_GENERATOR: Ninja steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: install devel tools run: | yum -y install gcc clang cmake make openssl-devel zlib-devel ninja-build diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index 09fbbef61..6e56cb400 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -17,7 +17,7 @@ jobs: CMAKE_GENERATOR: Ninja steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test in FreeBSD id: test diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index fa3865bbc..75fa3e069 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -7,7 +7,7 @@ jobs: runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: build run: | diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d8eeab58a..68d68d01a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: ccheck run: | wget "https://raw.githubusercontent.com/baresip/baresip/main/test/ccheck.py" diff --git a/.github/workflows/mingw.yml b/.github/workflows/mingw.yml index ed01100cf..64d765139 100644 --- a/.github/workflows/mingw.yml +++ b/.github/workflows/mingw.yml @@ -20,7 +20,7 @@ jobs: run: | sudo apt-get update && sudo apt-get install -y mingw-w64 ninja-build - - uses: actions/checkout@v3 # needed for pr checkout + - uses: actions/checkout@v4 # needed for pr checkout - uses: sreimers/pr-dependency-action@v0.6 with: @@ -28,7 +28,7 @@ jobs: repo: https://github.com/baresip/baresip-win32 secret: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: path: baresip-win32/re @@ -61,7 +61,7 @@ jobs: needs: MinGW-w64-build steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/download-artifact@v2 - uses: sreimers/pr-dependency-action@v0.6 with: diff --git a/.github/workflows/musl.yml b/.github/workflows/musl.yml index b2e51f464..7a6191ec0 100644 --- a/.github/workflows/musl.yml +++ b/.github/workflows/musl.yml @@ -17,7 +17,7 @@ jobs: CMAKE_GENERATOR: Ninja steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: install devel tools run: | apk add musl-dev git cmake gcc g++ make binutils openssl-dev linux-headers zlib-dev ninja diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index 988d04142..86f23d5cf 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -23,7 +23,7 @@ jobs: ASAN_OPTIONS: fast_unwind_on_malloc=0 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: fix flaky azure mirrors if: ${{ runner.os == 'Linux' }} diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 0f3e5bdc7..a8b6e85c9 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -14,7 +14,7 @@ jobs: SONAR_SERVER_URL: "https://sonarcloud.io" BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Set up JDK 17 diff --git a/.github/workflows/ssl.yml b/.github/workflows/ssl.yml index 93c0b5a7a..510346c89 100644 --- a/.github/workflows/ssl.yml +++ b/.github/workflows/ssl.yml @@ -15,7 +15,7 @@ jobs: OPENSSL_ROOT_DIR: "assets/${{ matrix.ssl }}" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: fix flaky azure mirrors if: ${{ runner.os == 'Linux' }} diff --git a/.github/workflows/strict-c.yml b/.github/workflows/strict-c.yml index a827e5fc4..e53424650 100644 --- a/.github/workflows/strict-c.yml +++ b/.github/workflows/strict-c.yml @@ -16,7 +16,7 @@ jobs: CMAKE_GENERATOR: Ninja steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: fix flaky azure mirrors if: ${{ runner.os == 'Linux' }} diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 5043e05a1..6cfa3a44e 100644 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -10,7 +10,7 @@ jobs: CMAKE_GENERATOR: Ninja steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: fix flaky azure mirrors if: ${{ runner.os == 'Linux' }} From 4f54d19230079345d9c464742afaca06ad0fd516 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Wed, 27 Dec 2023 13:19:44 +0100 Subject: [PATCH 03/11] ci/abi: bump old release --- .github/workflows/abi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/abi.yml b/.github/workflows/abi.yml index 4f282c138..e3792a5ab 100644 --- a/.github/workflows/abi.yml +++ b/.github/workflows/abi.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - ref: 'v3.6.0' + ref: 'v3.7.0' path: old - uses: actions/checkout@v4 From ff80c865a863af668f09df3ff322ad1cde26482b Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Wed, 27 Dec 2023 13:33:04 +0100 Subject: [PATCH 04/11] release v3.8.0 (#1032) --- CHANGELOG.md | 24 ++++++++++++++++++++++++ CMakeLists.txt | 4 ++-- debian/changelog | 6 ++++++ mk/Doxyfile | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17a9d3612..58f299ab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,30 @@ All notable changes to libre will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [v3.8.0] - 2023-12-27 + +## What's Changed +* Update README.md by @alfredh in https://github.com/baresip/re/pull/1013 +* rem/aufile: aufile_get_length use aufmt_sample_size by @larsimmisch in https://github.com/baresip/re/pull/1011 +* rem/aufile: test and fix aufile_set_position nread by @larsimmisch in https://github.com/baresip/re/pull/1010 +* ci/ssl: bump assets release by @sreimers in https://github.com/baresip/re/pull/1014 +* readme: update supported openssl versions by @sreimers in https://github.com/baresip/re/pull/1015 +* ci: upgrade android to openssl 3.2.0 by @alfredh in https://github.com/baresip/re/pull/1017 +* sipsess/connect: don't create a dialog for 100 responses by @maximilianfridrich in https://github.com/baresip/re/pull/1018 +* aubuf: fix build with re_trace_event by @cspiel1 in https://github.com/baresip/re/pull/1019 +* trace: fix coverity warnings by @alfredh in https://github.com/baresip/re/pull/1024 +* aumix: fix coverity defect in destructor by @alfredh in https://github.com/baresip/re/pull/1025 +* main: fix doxygen comment by @alfredh in https://github.com/baresip/re/pull/1026 +* connect: do not enforce Contact header in 1XX responses with To tag by @maximilianfridrich in https://github.com/baresip/re/pull/1028 +* test/sipsess: test re-INVITE with wait for ACK by @cspiel1 in https://github.com/baresip/re/pull/1027 +* dialog: fix rtags of forking INVITE by @maximilianfridrich in https://github.com/baresip/re/pull/1023 +* cmake: add RE_LIBS config and add atomic check by @sreimers in https://github.com/baresip/re/pull/1029 +* ci: use actions/checkout@v4 by @robert-scheck in https://github.com/baresip/re/pull/1031 + +**Full Changelog**: https://github.com/baresip/re/compare/v3.7.0...v3.8.0 + + ## [v3.7.0] - 2023-11-06 ## What's Changed diff --git a/CMakeLists.txt b/CMakeLists.txt index c6c6a392b..03c82fb36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,13 +14,13 @@ cmake_minimum_required(VERSION 3.13) project(re - VERSION 3.7.0 + VERSION 3.8.0 LANGUAGES C HOMEPAGE_URL https://github.com/baresip/re DESCRIPTION "Generic library for real-time communications" ) -set(PROJECT_SOVERSION 19) # bump if ABI breaks +set(PROJECT_SOVERSION 20) # bump if ABI breaks # Pre-release identifier, comment out on a release # Increment for breaking changes (dev2, dev3...) diff --git a/debian/changelog b/debian/changelog index 8e8dda674..680bcc80e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +libre (3.8.0) unstable; urgency=medium + + * version 3.8.0 + + -- Sebastian Reimers Wed, 27 Dec 2023 14:00:00 +0200 + libre (3.7.0) unstable; urgency=medium * version 3.7.0 diff --git a/mk/Doxyfile b/mk/Doxyfile index 51c960ec7..8ee292170 100644 --- a/mk/Doxyfile +++ b/mk/Doxyfile @@ -4,7 +4,7 @@ # Project related configuration options #--------------------------------------------------------------------------- PROJECT_NAME = libre -PROJECT_NUMBER = 3.7.0 +PROJECT_NUMBER = 3.8.0 OUTPUT_DIRECTORY = ../re-dox CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English From a7defd98e344ce75a67647098fce4b4bfd19a040 Mon Sep 17 00:00:00 2001 From: Christian Spielberger Date: Thu, 28 Dec 2023 10:05:37 +0100 Subject: [PATCH 05/11] http: fix doxygen (#1033) --- src/http/client.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/http/client.c b/src/http/client.c index d878a4dcd..c0e01b3a1 100644 --- a/src/http/client.c +++ b/src/http/client.c @@ -1196,7 +1196,7 @@ int http_client_set_session_reuse(struct http_cli *cli, bool enabled) * Set minimum TLS version * * @param cli HTTP Client - * @param version Minimum version, e.g.: TLS1_2_VERSION + * @param version Minimum version, e.g.: TLS1_2_VERSION * * @return 0 if success, otherwise errorcode */ @@ -1210,10 +1210,10 @@ int http_client_set_tls_min_version(struct http_cli *cli, int version) /** - * Set minimum TLS version + * Set maximum TLS version * * @param cli HTTP Client - * @param version Minimum version, e.g.: TLS1_2_VERSION + * @param version Maximum version, e.g.: TLS1_2_VERSION * * @return 0 if success, otherwise errorcode */ From c64974a8e424b12974c2508eb289b96363c728b5 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Thu, 28 Dec 2023 17:40:56 +0100 Subject: [PATCH 06/11] types: remove old ARRAY_SIZE macro (#1034) --- include/re_types.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/re_types.h b/include/re_types.h index c56ab2ed1..706c7fbad 100644 --- a/include/re_types.h +++ b/include/re_types.h @@ -47,9 +47,6 @@ typedef SSIZE_T ssize_t; /** Get number of elements in an array */ #define RE_ARRAY_SIZE(a) ((sizeof(a))/(sizeof((a)[0]))) -/* Backwards compat */ -#define ARRAY_SIZE RE_ARRAY_SIZE - /** Align a value to the boundary of mask */ #define RE_ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) From 98986222712cfb6ee29373d7be47eb123ccde75b Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 29 Dec 2023 20:43:53 +0100 Subject: [PATCH 07/11] cmake: bump minimum to version 3.14 (#1030) --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03c82fb36..117e2c7b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ # Versioning # -cmake_minimum_required(VERSION 3.13) +cmake_minimum_required(VERSION 3.14) project(re VERSION 3.8.0 From d3f12d439d476f9e1b0c87f1c6ade4011428f844 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 29 Dec 2023 22:50:40 +0100 Subject: [PATCH 08/11] test: use re_is_aligned() (#1035) --- include/re_types.h | 1 - test/mem.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/re_types.h b/include/re_types.h index 706c7fbad..739b1dcf0 100644 --- a/include/re_types.h +++ b/include/re_types.h @@ -53,7 +53,6 @@ typedef SSIZE_T ssize_t; /** Check alignment of pointer (p) and byte count (c) **/ #define re_is_aligned(p, c) (((uintptr_t)(const void *)(p)) % (c) == 0) -#define is_aligned re_is_aligned /** Get the minimal value */ #undef MIN diff --git a/test/mem.c b/test/mem.c index 71d7adda3..4b284e081 100644 --- a/test/mem.c +++ b/test/mem.c @@ -49,7 +49,7 @@ int test_mem(void) obj->pattern = PATTERN; TEST_EQUALS(1, mem_nrefs(obj)); - TEST_ASSERT(is_aligned(obj, mem_alignment)); + TEST_ASSERT(re_is_aligned(obj, mem_alignment)); obj = mem_ref(obj); TEST_EQUALS(2, mem_nrefs(obj)); @@ -67,7 +67,7 @@ int test_mem(void) TEST_ERR(err); } - TEST_ASSERT(is_aligned(obj, mem_alignment)); + TEST_ASSERT(re_is_aligned(obj, mem_alignment)); old = mem_ref(obj); TEST_EQUALS(2, mem_nrefs(obj)); From 89700a8ccfe4d7f8b14e4d3d976b581ea6db55c9 Mon Sep 17 00:00:00 2001 From: Maximilian Fridrich Date: Tue, 2 Jan 2024 13:22:23 +0100 Subject: [PATCH 09/11] sipsess: refactor and simplify SDP negotiation state (#1016) The SDP negotiation state is now tracked in a single enum which is used as a state machine to keep track of the current state of the SDP negotiation. --- include/re_sipsess.h | 10 ++++++ src/sipsess/accept.c | 3 ++ src/sipsess/connect.c | 70 ++++++++++++++++++++++++++++----------- src/sipsess/listen.c | 55 +++++++++++++++++++------------ src/sipsess/modify.c | 77 ++++++++++++++++++++++++++++--------------- src/sipsess/prack.c | 9 ++--- src/sipsess/reply.c | 72 +++++++++++++++++++++++++--------------- src/sipsess/sess.c | 18 ++++++++-- src/sipsess/sipsess.h | 11 +++---- src/sipsess/update.c | 17 +++++++--- test/sipsess.c | 22 ++++++++----- 11 files changed, 239 insertions(+), 125 deletions(-) diff --git a/include/re_sipsess.h b/include/re_sipsess.h index 87006197b..ad4f11544 100644 --- a/include/re_sipsess.h +++ b/include/re_sipsess.h @@ -7,6 +7,15 @@ struct sipsess_sock; struct sipsess; +/* SDP Negotiation state */ +enum sdp_neg_state { + SDP_NEG_NONE = 0, + SDP_NEG_LOCAL_OFFER, /** SDP offer sent */ + SDP_NEG_REMOTE_OFFER, /** SDP offer received */ + SDP_NEG_PREVIEW_ANSWER, /** SDP preview answer sent */ + SDP_NEG_DONE /** SDP negotiation done */ +}; + typedef void (sipsess_conn_h)(const struct sip_msg *msg, void *arg); typedef int (sipsess_desc_h)(struct mbuf **descp, const struct sa *src, @@ -74,3 +83,4 @@ void sipsess_close_all(struct sipsess_sock *sock); struct sip_dialog *sipsess_dialog(const struct sipsess *sess); void sipsess_abort(struct sipsess *sess); bool sipsess_ack_pending(const struct sipsess *sess); +enum sdp_neg_state sipsess_sdp_neg_state(const struct sipsess *sess); diff --git a/src/sipsess/accept.c b/src/sipsess/accept.c index ab50daeff..1f506dc7e 100644 --- a/src/sipsess/accept.c +++ b/src/sipsess/accept.c @@ -99,6 +99,9 @@ int sipsess_accept(struct sipsess **sessp, struct sipsess_sock *sock, if (err) goto out; + if (mbuf_get_left(msg->mb)) + sess->neg_state = SDP_NEG_REMOTE_OFFER; + va_start(ap, fmt); if (scode > 100 && scode < 200) { diff --git a/src/sipsess/connect.c b/src/sipsess/connect.c index a27d323ba..6280ed005 100644 --- a/src/sipsess/connect.c +++ b/src/sipsess/connect.c @@ -68,7 +68,9 @@ static int send_handler(enum sip_transp tp, struct sa *src, *contp = cont; out: - sess->sent_offer = desc != NULL; + if (desc) + sess->neg_state = SDP_NEG_LOCAL_OFFER; + mem_deref(desc); return err; } @@ -89,20 +91,14 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg) if (!msg || err || sip_request_loops(&sess->ls, msg->scode)) goto out; + sdp = mbuf_get_left(msg->mb) > 0; + if (msg->scode < 200) { sess->progrh(msg, sess->arg); - sdp = mbuf_get_left(msg->mb) > 0; if (msg->scode == 100) return; - if (sdp && sess->sent_offer) { - sess->awaiting_answer = false; - err = sess->answerh(msg, sess->arg); - if (err) - goto out; - } - contact = sip_msg_hdr(msg, SIP_HDR_CONTACT); if (pl_isset(&msg->to.tag) && contact) { err = sip_dialog_established(sess->dlg) ? @@ -112,19 +108,40 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg) goto out; } + if (sdp && sess->neg_state == SDP_NEG_LOCAL_OFFER) { + err = sess->answerh(msg, sess->arg); + if (err) + goto out; + } + if (sip_msg_hdr_has_value(msg, SIP_HDR_REQUIRE, "100rel") && sess->rel100_supported) { - if (sdp && !sess->sent_offer) { - sess->modify_pending = false; - err = sess->offerh(&desc, msg, sess->arg); + + if (sess->neg_state == SDP_NEG_NONE && !sdp) + goto out; + + if (sdp) { + if (sess->neg_state == SDP_NEG_LOCAL_OFFER) { + sess->neg_state = SDP_NEG_DONE; + } + else if (sess->neg_state == SDP_NEG_NONE) { + sess->neg_state = SDP_NEG_REMOTE_OFFER; + err = sess->offerh(&desc, msg, + sess->arg); + } } err |= sipsess_prack(sess, msg->cseq.num, msg->rel_seq, &msg->cseq.met, desc); - mem_deref(desc); - sess->desc = mem_deref(sess->desc); if (err) goto out; + + if (sess->neg_state == SDP_NEG_REMOTE_OFFER + && mbuf_get_left(desc)) + sess->neg_state = SDP_NEG_DONE; + + mem_deref(desc); + sess->desc = mem_deref(sess->desc); } return; @@ -139,15 +156,28 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg) if (err) goto out; - if (sess->sent_offer) - err = sess->answerh(msg, sess->arg); - else { - sess->modify_pending = false; - err = sess->offerh(&desc, msg, sess->arg); + if (sdp) { + if (sess->neg_state == SDP_NEG_LOCAL_OFFER) { + sess->neg_state = SDP_NEG_DONE; + err = sess->answerh(msg, sess->arg); + } + else if (sess->neg_state == SDP_NEG_NONE) { + sess->neg_state = SDP_NEG_REMOTE_OFFER; + err = sess->offerh(&desc, msg, sess->arg); + } } err |= sipsess_ack(sess->sock, sess->dlg, msg->cseq.num, - sess->auth, sess->ctype, desc); + sess->auth, sess->ctype, desc); + if (err) + goto out; + + if (sess->neg_state == SDP_NEG_NONE && !sdp) + goto out; + + if (sess->neg_state == SDP_NEG_REMOTE_OFFER + && mbuf_get_left(desc)) + sess->neg_state = SDP_NEG_DONE; sess->established = true; mem_deref(desc); diff --git a/src/sipsess/listen.c b/src/sipsess/listen.c index a47fda866..f50e37289 100644 --- a/src/sipsess/listen.c +++ b/src/sipsess/listen.c @@ -128,14 +128,13 @@ static void bye_handler(struct sipsess_sock *sock, const struct sip_msg *msg) static void ack_handler(struct sipsess_sock *sock, const struct sip_msg *msg) { struct sipsess *sess; - bool awaiting_answer; int err = 0; sess = sipsess_find(sock, msg); if (!sess) return; - if (sipsess_reply_ack(sess, msg, &awaiting_answer)) + if (sipsess_reply_ack(sess, msg)) return; if (sess->terminated) { @@ -146,8 +145,13 @@ static void ack_handler(struct sipsess_sock *sock, const struct sip_msg *msg) return; } - if (awaiting_answer) { - sess->awaiting_answer = false; + if (sess->neg_state == SDP_NEG_LOCAL_OFFER) { + if (!mbuf_get_left(msg->mb)) { + sipsess_terminate(sess, EPROTO, NULL); + return; + } + + sess->neg_state = SDP_NEG_DONE; err = sess->answerh(msg, sess->arg); } @@ -169,15 +173,14 @@ static void ack_handler(struct sipsess_sock *sock, const struct sip_msg *msg) static void prack_handler(struct sipsess_sock *sock, const struct sip_msg *msg) { + bool sdp; struct sipsess *sess; struct mbuf *desc = NULL; - bool awaiting_answer = false; bool awaiting_prack = false; sess = sipsess_find(sock, msg); - if (!sess || sipsess_reply_prack(sess, msg, &awaiting_answer, - &awaiting_prack)) { + if (!sess || sipsess_reply_prack(sess, msg, &awaiting_prack)) { (void)sip_reply(sock->sip, msg, 481, "Transaction Does Not Exist"); return; @@ -192,22 +195,28 @@ static void prack_handler(struct sipsess_sock *sock, const struct sip_msg *msg) return; } - if (awaiting_prack) { - sess->awaiting_prack = false; - sess->refresh_allowed = true; - } + sdp = mbuf_get_left(msg->mb); - if (sess->prackh) - sess->prackh(msg, sess->arg); + if (awaiting_prack) + --sess->prack_waiting_cnt; - if (awaiting_answer) { - sess->awaiting_answer = false; + if (sess->neg_state == SDP_NEG_LOCAL_OFFER) { + if (!sdp) { + sipsess_terminate(sess, EPROTO, NULL); + return; + } + + sess->neg_state = SDP_NEG_DONE; (void)sess->answerh(msg, sess->arg); } - else if (msg && mbuf_get_left(msg->mb)) { + else if (sess->neg_state == SDP_NEG_DONE && sdp) { + sess->neg_state = SDP_NEG_REMOTE_OFFER; (void)sess->offerh(&desc, msg, sess->arg); } + if (sess->prackh) + sess->prackh(msg, sess->arg); + (void)sipsess_reply_2xx(sess, msg, 200, "OK", desc, NULL, NULL); mem_deref(desc); @@ -219,7 +228,7 @@ static void target_refresh_handler(struct sipsess_sock *sock, { struct sip *sip = sock->sip; bool is_invite; - bool got_offer; + bool sdp; struct sipsess *sess; struct mbuf *desc = NULL; char m[256]; @@ -232,14 +241,15 @@ static void target_refresh_handler(struct sipsess_sock *sock, } is_invite = !pl_strcmp(&msg->met, "INVITE"); - got_offer = (mbuf_get_left(msg->mb) > 0); + sdp = (mbuf_get_left(msg->mb) > 0); if (!sip_dialog_rseq_valid(sess->dlg, msg)) { (void)sip_treply(NULL, sip, msg, 500, "Server Internal Error"); return; } - if ((is_invite && sess->st) || sess->awaiting_answer) { + if ((is_invite && sess->st) + || (sdp && sess->neg_state == SDP_NEG_LOCAL_OFFER)) { (void)sip_treplyf(NULL, NULL, sip, msg, false, 500, "Server Internal Error", "Retry-After: 5\r\n" @@ -253,16 +263,19 @@ static void target_refresh_handler(struct sipsess_sock *sock, return; } - if (got_offer && !sipsess_refresh_allowed(sess)) { + if (sdp && !sipsess_refresh_allowed(sess)) { (void)sip_reply(sip, msg, 488, "Not Acceptable Here"); return; } - if (is_invite || got_offer) { + if (is_invite || sdp) { + sess->neg_state = sdp ? SDP_NEG_REMOTE_OFFER : + SDP_NEG_LOCAL_OFFER; err = sess->offerh(&desc, msg, sess->arg); if (err) { (void)sip_reply(sip, msg, 488, str_error(err, m, sizeof(m))); + sess->neg_state = SDP_NEG_DONE; return; } } diff --git a/src/sipsess/modify.c b/src/sipsess/modify.c index 3f7872be8..6bb0e1fbc 100644 --- a/src/sipsess/modify.c +++ b/src/sipsess/modify.c @@ -32,10 +32,13 @@ static void reinvite_resp_handler(int err, const struct sip_msg *msg, struct sipsess *sess = arg; const struct sip_hdr *hdr; struct mbuf *desc = NULL; + bool sdp; if (!msg || err || sip_request_loops(&sess->ls, msg->scode)) goto out; + sdp = mbuf_get_left(msg->mb) > 0; + if (msg->scode < 200) { return; } @@ -43,20 +46,34 @@ static void reinvite_resp_handler(int err, const struct sip_msg *msg, (void)sip_dialog_update(sess->dlg, msg); - if (sess->sent_offer) { - (void)sess->answerh(msg, sess->arg); - } - else { - sess->modify_pending = false; - (void)sess->offerh(&desc, msg, sess->arg); + if (sdp) { + if (sess->neg_state == SDP_NEG_LOCAL_OFFER) { + sess->neg_state = SDP_NEG_DONE; + err = sess->answerh(msg, sess->arg); + } + else if (sess->neg_state == SDP_NEG_NONE) { + sess->neg_state = SDP_NEG_REMOTE_OFFER; + err = sess->offerh(&desc, msg, sess->arg); + } + + if (err) + goto out; } - (void)sipsess_ack(sess->sock, sess->dlg, msg->cseq.num, + err = sipsess_ack(sess->sock, sess->dlg, msg->cseq.num, sess->auth, sess->ctype, desc); + if (err) + goto out; + + if (sess->neg_state == SDP_NEG_REMOTE_OFFER + && mbuf_get_left(desc)) + sess->neg_state = SDP_NEG_DONE; mem_deref(desc); } else { + sess->neg_state = SDP_NEG_DONE; + if (sess->terminated) goto out; @@ -126,28 +143,35 @@ static int send_handler(enum sip_transp tp, struct sa *src, int sipsess_reinvite(struct sipsess *sess, bool reset_ls) { + int err; + if (sess->req) return EPROTO; - sess->sent_offer = sess->desc ? true : false; - sess->modify_pending = false; - if (reset_ls) sip_loopstate_reset(&sess->ls); - return sip_drequestf(&sess->req, sess->sip, true, "INVITE", - sess->dlg, 0, sess->auth, - send_handler, reinvite_resp_handler, sess, - "%s%s%s" - "Content-Length: %zu\r\n" - "\r\n" - "%b", - sess->desc ? "Content-Type: " : "", - sess->desc ? sess->ctype : "", - sess->desc ? "\r\n" : "", - sess->desc ? mbuf_get_left(sess->desc) :(size_t)0, - sess->desc ? mbuf_buf(sess->desc) : NULL, - sess->desc ? mbuf_get_left(sess->desc):(size_t)0); + err = sip_drequestf(&sess->req, sess->sip, true, "INVITE", + sess->dlg, 0, sess->auth, + send_handler, reinvite_resp_handler, sess, + "%s%s%s" + "Content-Length: %zu\r\n" + "\r\n" + "%b", + sess->desc ? "Content-Type: " : "", + sess->desc ? sess->ctype : "", + sess->desc ? "\r\n" : "", + sess->desc ? mbuf_get_left(sess->desc) :(size_t)0, + sess->desc ? mbuf_buf(sess->desc) : NULL, + sess->desc ? mbuf_get_left(sess->desc):(size_t)0); + + if (!err) { + sess->modify_pending = false; + if (sess->desc) + sess->neg_state = SDP_NEG_LOCAL_OFFER; + } + + return err; } @@ -161,12 +185,11 @@ int sipsess_reinvite(struct sipsess *sess, bool reset_ls) */ int sipsess_modify(struct sipsess *sess, struct mbuf *desc) { - if (!sess || sess->terminated || sess->awaiting_answer - || !sip_dialog_established(sess->dlg)) + if (!sess || sess->terminated || !sip_dialog_established(sess->dlg)) return EINVAL; - if (!sess->established && !sess->refresh_allowed - && mbuf_get_left(desc)) + if (mbuf_get_left(desc) && (sess->neg_state != SDP_NEG_DONE + && sess->neg_state != SDP_NEG_NONE)) return EPROTO; mem_deref(sess->desc); diff --git a/src/sipsess/prack.c b/src/sipsess/prack.c index cb23d6f8f..81a59712e 100644 --- a/src/sipsess/prack.c +++ b/src/sipsess/prack.c @@ -68,9 +68,8 @@ static void prack_resp_handler(int err, const struct sip_msg *msg, void *arg) (void)sip_dialog_update(req->sess->dlg, msg); if (mbuf_get_left(msg->mb)) { - if (req->sess->sent_offer) { - req->sess->awaiting_answer = false; - req->sess->refresh_allowed = true; + if (req->sess->neg_state == SDP_NEG_LOCAL_OFFER) { + req->sess->neg_state = SDP_NEG_DONE; (void)req->sess->answerh(msg, req->sess->arg); } @@ -136,10 +135,6 @@ static int prack_request(struct sipsess_prack *prack) if (err == -1) return err; - if (req->sess->sent_offer && !req->sess->awaiting_answer - && (!req->body || !mbuf_get_left(req->body))) - req->sess->refresh_allowed = true; - return sip_drequestf(&req->req, req->sess->sip, true, "PRACK", req->sess->dlg, 0, req->sess->auth, NULL, prack_resp_handler, prack, diff --git a/src/sipsess/reply.c b/src/sipsess/reply.c index efb89089b..3f1d47104 100644 --- a/src/sipsess/reply.c +++ b/src/sipsess/reply.c @@ -26,7 +26,6 @@ struct sipsess_reply { const struct sip_msg *msg; struct mbuf *mb; struct sipsess *sess; - bool awaiting_answer; bool awaiting_prack; uint16_t scode; uint32_t seq; @@ -115,11 +114,17 @@ int sipsess_reply_2xx(struct sipsess *sess, const struct sip_msg *msg, struct sipsess_reply *reply = NULL; struct sip_contact contact; int err = ENOMEM; + bool sdp = mbuf_get_left(msg->mb) > 0; bool non_invite = !pl_strcmp(&msg->met, "PRACK") || !pl_strcmp(&msg->met, "UPDATE"); if (!non_invite) { - if (sess->awaiting_prack) + if (sess->neg_state == SDP_NEG_NONE && !mbuf_get_left(desc)) + return EINVAL; + else if (sess->neg_state == SDP_NEG_DONE) + desc = NULL; + + if (sess->prack_waiting_cnt > 0) return EINVAL; reply = mem_zalloc(sizeof(*reply), destructor); @@ -134,6 +139,9 @@ int sipsess_reply_2xx(struct sipsess *sess, const struct sip_msg *msg, reply->sess = sess; } + if (non_invite && sess->neg_state != SDP_NEG_REMOTE_OFFER) + desc = NULL; + sip_contact_set(&contact, sess->cuser, &msg->dst, msg->tp); err = sip_treplyf(non_invite ? NULL : &sess->st, reply ? &reply->mb : NULL, sess->sip, @@ -160,14 +168,16 @@ int sipsess_reply_2xx(struct sipsess *sess, const struct sip_msg *msg, (void)list_ledata(list_apply(&sess->replyl, false, cancel_1xx_timers, NULL)); + if (mbuf_get_left(desc)) { + if (sdp) + sess->neg_state = SDP_NEG_DONE; + else if (!non_invite) + sess->neg_state = SDP_NEG_LOCAL_OFFER; + } + if (reply) { tmr_start(&reply->tmr, 64 * SIP_T1, tmr_handler, reply); tmr_start(&reply->tmrg, SIP_T1, retransmit_handler, reply); - - if (!mbuf_get_left(msg->mb) && desc) { - reply->awaiting_answer = true; - sess->awaiting_answer = true; - } } out: @@ -205,16 +215,32 @@ int sipsess_reply_1xx(struct sipsess *sess, const struct sip_msg *msg, 421, "Extension required", "Require: 100rel\r\n" "Content-Length: 0\r\n\r\n"); - return -1; + return EPROTO; } else if (rel100_peer == REL100_REQUIRED && !rel100) { (void)sip_treplyf(&sess->st, NULL, sess->sip, msg, false, 420, "Bad Extension", "Unsupported: 100rel\r\n" "Content-Length: 0\r\n\r\n"); - return -1; + return EPROTO; } reliably = rel100 && rel100_peer && scode != 100; + + if (reliably && sess->neg_state == SDP_NEG_NONE + && !mbuf_get_left(desc)) + return EINVAL; + + if (sess->neg_state == SDP_NEG_NONE) { + if (reliably && !mbuf_get_left(desc)) + return EINVAL; + else if (!reliably) + desc = NULL; + } + else if (sess->neg_state == SDP_NEG_DONE + || sess->neg_state == SDP_NEG_LOCAL_OFFER) { + desc = NULL; + } + if (rel100 != REL100_REQUIRED && reliably) { pl_set_str(&require_header, "Require: 100rel\r\n"); } @@ -264,21 +290,19 @@ int sipsess_reply_1xx(struct sipsess *sess, const struct sip_msg *msg, if (reliably) { tmr_start(&reply->tmr, 64 * SIP_T1, tmr_handler, reply); tmr_start(&reply->tmrg, SIP_T1, retransmit_handler, reply); - } - else { - mem_deref(reply); - } - if (desc) { - if (!mbuf_get_left(msg->mb)) { - reply->awaiting_answer = true; - sess->awaiting_answer = true; - } - if (reliably) { - sess->awaiting_prack = true; + if (desc) { + ++sess->prack_waiting_cnt; reply->awaiting_prack = true; + sess->neg_state = mbuf_get_left(msg->mb) ? + SDP_NEG_DONE : SDP_NEG_LOCAL_OFFER; } + } + else { + if (desc && sess->neg_state == SDP_NEG_REMOTE_OFFER) + sess->neg_state = SDP_NEG_PREVIEW_ANSWER; + mem_deref(reply); } out: @@ -312,7 +336,7 @@ static bool cmp_handler(struct le *le, void *arg) int sipsess_reply_prack(struct sipsess *sess, const struct sip_msg *msg, - bool *awaiting_answer, bool *awaiting_prack) + bool *awaiting_prack) { struct sipsess_reply *reply; @@ -321,7 +345,6 @@ int sipsess_reply_prack(struct sipsess *sess, const struct sip_msg *msg, if (!reply) return ENOENT; - *awaiting_answer = reply->awaiting_answer; *awaiting_prack = reply->awaiting_prack; mem_deref(reply); @@ -330,8 +353,7 @@ int sipsess_reply_prack(struct sipsess *sess, const struct sip_msg *msg, } -int sipsess_reply_ack(struct sipsess *sess, const struct sip_msg *msg, - bool *awaiting_answer) +int sipsess_reply_ack(struct sipsess *sess, const struct sip_msg *msg) { struct sipsess_reply *reply; @@ -340,8 +362,6 @@ int sipsess_reply_ack(struct sipsess *sess, const struct sip_msg *msg, if (!reply) return ENOENT; - *awaiting_answer = reply->awaiting_answer; - mem_deref(reply); return 0; diff --git a/src/sipsess/sess.c b/src/sipsess/sess.c index bb62db33c..f394ec92c 100644 --- a/src/sipsess/sess.c +++ b/src/sipsess/sess.c @@ -333,7 +333,7 @@ void sipsess_abort(struct sipsess *sess) */ bool sipsess_awaiting_prack(const struct sipsess *sess) { - return sess ? sess->awaiting_prack : false; + return sess ? sess->prack_waiting_cnt > 0 : false; } @@ -349,8 +349,7 @@ bool sipsess_refresh_allowed(const struct sipsess *sess) if (!sess) return false; - return ((sess->established || sess->refresh_allowed) - && !sess->terminated && !sess->awaiting_answer); + return !sess->terminated && sess->neg_state == SDP_NEG_DONE; } @@ -366,3 +365,16 @@ bool sipsess_ack_pending(const struct sipsess *sess) { return sess && sess->replyl.head ? true : false; } + + +/** + * Get the SDP negotiation state of a SIP Session + * + * @param sess SIP Session + * + * @return SDP negotiation state + */ +enum sdp_neg_state sipsess_sdp_neg_state(const struct sipsess *sess) +{ + return sess ? sess->neg_state : SDP_NEG_NONE; +} diff --git a/src/sipsess/sipsess.h b/src/sipsess/sipsess.h index 884d03705..591bf0329 100644 --- a/src/sipsess/sipsess.h +++ b/src/sipsess/sipsess.h @@ -36,15 +36,13 @@ struct sipsess { void *arg; uint32_t rel_seq; bool owner; - bool sent_offer; - bool awaiting_answer; bool modify_pending; bool established; bool peerterm; bool rel100_supported; - bool awaiting_prack; - bool refresh_allowed; + int prack_waiting_cnt; int terminated; + enum sdp_neg_state neg_state; }; @@ -95,10 +93,9 @@ int sipsess_reply_1xx(struct sipsess *sess, const struct sip_msg *msg, uint16_t scode, const char *reason, enum rel100_mode rel100, struct mbuf *desc, const char *fmt, va_list *ap); -int sipsess_reply_ack(struct sipsess *sess, const struct sip_msg *msg, - bool *awaiting_answer); +int sipsess_reply_ack(struct sipsess *sess, const struct sip_msg *msg); int sipsess_reply_prack(struct sipsess *sess, const struct sip_msg *msg, - bool *awaiting_answer, bool *awaiting_prack); + bool *awaiting_prack); int sipsess_reinvite(struct sipsess *sess, bool reset_ls); int sipsess_update(struct sipsess *sess); int sipsess_bye(struct sipsess *sess, bool reset_ls); diff --git a/src/sipsess/update.c b/src/sipsess/update.c index fbbf25eea..1e982f858 100644 --- a/src/sipsess/update.c +++ b/src/sipsess/update.c @@ -46,15 +46,17 @@ static void update_resp_handler(int err, const struct sip_msg *msg, void *arg) else if (msg->scode < 300) { (void)sip_dialog_update(req->sess->dlg, msg); - if (req->sess->sent_offer) { + if (req->sess->neg_state == SDP_NEG_LOCAL_OFFER) { (void)req->sess->answerh(msg, req->sess->arg); - req->sess->awaiting_answer = false; + req->sess->neg_state = SDP_NEG_DONE; } } else { if (req->sess->terminated) goto out; + req->sess->neg_state = SDP_NEG_DONE; + switch (msg->scode) { case 401: @@ -120,10 +122,12 @@ static int send_handler(enum sip_transp tp, struct sa *src, static int update_request(struct sipsess_request *req) { + int err; + if (!req || req->tmr.th) return -1; - return sip_drequestf(&req->req, req->sess->sip, true, "UPDATE", + err = sip_drequestf(&req->req, req->sess->sip, true, "UPDATE", req->sess->dlg, 0, req->sess->auth, send_handler, update_resp_handler, req, "%s%s%s" @@ -136,6 +140,11 @@ static int update_request(struct sipsess_request *req) req->body ? mbuf_get_left(req->body) :(size_t)0, req->body ? mbuf_buf(req->body) : NULL, req->body ? mbuf_get_left(req->body):(size_t)0); + + if (!err && req->sess->desc) + req->sess->neg_state = SDP_NEG_LOCAL_OFFER; + + return err; } @@ -165,8 +174,6 @@ int sipsess_update(struct sipsess *sess) return err; } - sess->sent_offer = sess->desc ? true : false; - sess->awaiting_answer = sess->sent_offer; sess->modify_pending = false; return err; diff --git a/test/sipsess.c b/test/sipsess.c index ae7613207..0fd63f035 100644 --- a/test/sipsess.c +++ b/test/sipsess.c @@ -16,7 +16,7 @@ typedef void (prack_func)(void *arg); -enum sdp_neg_state { +enum neg_state { INITIAL = 0, OFFER_RECEIVED, ANSWER_RECEIVED, @@ -71,7 +71,7 @@ struct test { bool ack_b; enum rel100_mode rel100_a; enum rel100_mode rel100_b; - enum sdp_neg_state sdp_state; + enum neg_state sdp_state; enum rel100_state rel100_state_a; enum rel100_state rel100_state_b; enum connect_action conn_action; @@ -500,7 +500,7 @@ static void conn_handler(const struct sip_msg *msg, void *arg) else if (test->conn_action & CONN_ANSWER) { err = sipsess_accept(&test->b, test->sock, msg, 200, "OK", test->rel100_b, "b", "application/sdp", - NULL, NULL, NULL, false, offer_handler_b, + desc, NULL, NULL, false, offer_handler_b, answer_handler_b, estab_handler_b, NULL, NULL, close_handler, test, hdrs); if (err != test->answ_ret_code) { @@ -602,7 +602,7 @@ int test_sipsess(void) err = sipsess_connect(&test.a, test.sock, to_uri, NULL, "sip:a@127.0.0.1", "a", NULL, 0, "application/sdp", NULL, NULL, false, - callid, desc_handler, + callid, desc_handler_a, offer_handler_a, answer_handler_a, NULL, estab_handler_a, NULL, NULL, close_handler, &test, NULL); @@ -622,7 +622,9 @@ int test_sipsess(void) ASSERT_TRUE(test.estab_b); ASSERT_TRUE(test.desc); ASSERT_TRUE(test.answr_a); - ASSERT_TRUE(!test.offer_b); + ASSERT_TRUE(test.offer_b); + ASSERT_TRUE(!test.offer_a); + ASSERT_TRUE(!test.answr_b); /* test re-invite with wait for ACK */ test.sdp_state = INITIAL; @@ -782,7 +784,7 @@ int test_sipsess_blind_transfer(void) err = sipsess_connect(&test.a, test.sock, to_uri, NULL, "sip:a@127.0.0.1", "a", NULL, 0, "application/sdp", NULL, NULL, false, - callid, desc_handler, + callid, desc_handler_a, offer_handler_a, answer_handler_a, NULL, estab_handler_a, NULL, NULL, close_handler, &test, NULL); @@ -805,7 +807,9 @@ int test_sipsess_blind_transfer(void) ASSERT_TRUE(test.estab_b); ASSERT_TRUE(test.desc); ASSERT_TRUE(test.answr_a); - ASSERT_TRUE(!test.offer_b); + ASSERT_TRUE(test.offer_b); + ASSERT_TRUE(!test.offer_a); + ASSERT_TRUE(!test.answr_b); out: test.a = mem_deref(test.a); @@ -1121,7 +1125,7 @@ int test_sipsess_100rel_420(void) err = re_main_timeout(200); TEST_ERR(err); - ASSERT_TRUE(test.err == EINVAL); + ASSERT_TRUE(test.err == EPROTO); /* okay here -- verify */ ASSERT_TRUE(!test.b); @@ -1194,7 +1198,7 @@ int test_sipsess_100rel_421(void) err = re_main_timeout(200); TEST_ERR(err); - ASSERT_TRUE(test.err == EINVAL); + ASSERT_TRUE(test.err == EPROTO); /* okay here -- verify */ ASSERT_TRUE(!test.b); From 7bb16f82bafb1af45939371f6a5d510479336077 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Tue, 2 Jan 2024 16:30:30 +0100 Subject: [PATCH 10/11] license: bump year --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 454e30779..901642c72 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ -Copyright (C) 2020 - 2023, Baresip Foundation (https://github.com/baresip) -Copyright (c) 2010 - 2023, Alfred E. Heggestad +Copyright (C) 2020 - 2024, Baresip Foundation (https://github.com/baresip) +Copyright (c) 2010 - 2024, Alfred E. Heggestad Copyright (c) 2010 - 2020, Richard Aas Copyright (c) 2010 - 2020, Creytiv.com All rights reserved. From 6799654faef6280938ed579d7dcd942f33f8ff44 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Tue, 2 Jan 2024 16:30:57 +0100 Subject: [PATCH 11/11] readme: bump year --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aa8fdda4d..49651c986 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ libre README libre is a Generic library for real-time communications with async IO support. - Copyright (C) 2010 - 2020 Creytiv.com -- Copyright (C) 2020 - 2023 Baresip Foundation (https://github.com/baresip) +- Copyright (C) 2020 - 2024 Baresip Foundation (https://github.com/baresip) ![Build](https://github.com/baresip/re/workflows/Build/badge.svg) ![ccheck](https://github.com/baresip/re/workflows/ccheck/badge.svg)