blob: 0349b04ac09f80986a6641cb67a601a221b7a102 [file] [log] [blame]
Adrien Béraud612b55b2023-05-29 10:42:04 -04001/*
2 * Copyright (C) 2004-2023 Savoir-faire Linux Inc.
3 *
Adrien Béraudcb753622023-07-17 22:32:49 -04004 * This program is free software: you can redistribute it and/or modify
Adrien Béraud612b55b2023-05-29 10:42:04 -04005 * it under the terms of the GNU General Public License as published by
Adrien Béraudcb753622023-07-17 22:32:49 -04006 * the Free Software Foundation, either version 3 of the License, or
Adrien Béraud612b55b2023-05-29 10:42:04 -04007 * (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éraudcb753622023-07-17 22:32:49 -040011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Adrien Béraud612b55b2023-05-29 10:42:04 -040012 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
Adrien Béraudcb753622023-07-17 22:32:49 -040015 * along with this program. If not, see <https://www.gnu.org/licenses/>.
Adrien Béraud612b55b2023-05-29 10:42:04 -040016 */
Adrien Béraud612b55b2023-05-29 10:42:04 -040017#pragma once
18
19#include "ip_utils.h"
20
21#include <utility>
22#include <string>
23#include <vector>
24#include <cstring> // strcmp
Adrien Béraude48fd6d2023-07-18 16:29:35 -040025#include <memory>
Adrien Béraud612b55b2023-05-29 10:42:04 -040026
Adrien Béraud612b55b2023-05-29 10:42:04 -040027#include <pjlib.h>
Adrien Béraud612b55b2023-05-29 10:42:04 -040028
Adrien Béraud1ae60aa2023-07-07 09:55:09 -040029namespace dhtnet {
Adrien Béraud612b55b2023-05-29 10:42:04 -040030namespace sip_utils {
31
32using namespace std::literals;
33
Adrien Béraud612b55b2023-05-29 10:42:04 -040034std::string_view sip_strerror(pj_status_t code);
35
36// Helper function that return a constant pj_str_t from an array of any types
37// that may be statically casted into char pointer.
38// Per convention, the input array is supposed to be null terminated.
39template<typename T, std::size_t N>
40constexpr const pj_str_t
41CONST_PJ_STR(T (&a)[N]) noexcept
42{
43 return {const_cast<char*>(a), N - 1};
44}
45
46inline const pj_str_t
47CONST_PJ_STR(const std::string& str) noexcept
48{
49 return {const_cast<char*>(str.c_str()), (pj_ssize_t) str.size()};
50}
51
52inline constexpr pj_str_t
53CONST_PJ_STR(const std::string_view& str) noexcept
54{
55 return {const_cast<char*>(str.data()), (pj_ssize_t) str.size()};
56}
57
58inline constexpr std::string_view
59as_view(const pj_str_t& str) noexcept
60{
61 return {str.ptr, (size_t) str.slen};
62}
63
Adrien Béraud612b55b2023-05-29 10:42:04 -040064} // namespace sip_utils
Sébastien Blin464bdff2023-07-19 08:02:53 -040065} // namespace dhtnet