Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2023 Savoir-faire Linux Inc. |
| 3 | * |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 4 | * This program is free software: you can redistribute it and/or modify |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 5 | * it under the terms of the GNU General Public License as published by |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 6 | * the Free Software Foundation, either version 3 of the License, or |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 16 | */ |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 17 | #pragma once |
| 18 | |
| 19 | #include "ip_utils.h" |
| 20 | |
| 21 | #include <utility> |
| 22 | #include <string> |
| 23 | #include <vector> |
| 24 | #include <cstring> // strcmp |
Adrien Béraud | e48fd6d | 2023-07-18 16:29:35 -0400 | [diff] [blame] | 25 | #include <memory> |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 26 | |
Adrien Béraud | 9e0f84f | 2023-07-27 16:02:21 -0400 | [diff] [blame] | 27 | extern "C" { |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 28 | #include <pjlib.h> |
Adrien Béraud | 9e0f84f | 2023-07-27 16:02:21 -0400 | [diff] [blame] | 29 | } |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 30 | |
Adrien Béraud | 1ae60aa | 2023-07-07 09:55:09 -0400 | [diff] [blame] | 31 | namespace dhtnet { |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 32 | namespace sip_utils { |
| 33 | |
| 34 | using namespace std::literals; |
| 35 | |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 36 | std::string_view sip_strerror(pj_status_t code); |
| 37 | |
| 38 | // Helper function that return a constant pj_str_t from an array of any types |
| 39 | // that may be statically casted into char pointer. |
| 40 | // Per convention, the input array is supposed to be null terminated. |
| 41 | template<typename T, std::size_t N> |
| 42 | constexpr const pj_str_t |
| 43 | CONST_PJ_STR(T (&a)[N]) noexcept |
| 44 | { |
| 45 | return {const_cast<char*>(a), N - 1}; |
| 46 | } |
| 47 | |
| 48 | inline const pj_str_t |
| 49 | CONST_PJ_STR(const std::string& str) noexcept |
| 50 | { |
| 51 | return {const_cast<char*>(str.c_str()), (pj_ssize_t) str.size()}; |
| 52 | } |
| 53 | |
| 54 | inline constexpr pj_str_t |
| 55 | CONST_PJ_STR(const std::string_view& str) noexcept |
| 56 | { |
| 57 | return {const_cast<char*>(str.data()), (pj_ssize_t) str.size()}; |
| 58 | } |
| 59 | |
| 60 | inline constexpr std::string_view |
| 61 | as_view(const pj_str_t& str) noexcept |
| 62 | { |
| 63 | return {str.ptr, (size_t) str.slen}; |
| 64 | } |
| 65 | |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 66 | } // namespace sip_utils |
Sébastien Blin | 464bdff | 2023-07-19 08:02:53 -0400 | [diff] [blame] | 67 | } // namespace dhtnet |