Skip to content
Snippets Groups Projects
Commit 9fab9906 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

sip utils: cleanup

Change-Id: I509dde22a2c7fa76a7eea946aaa4fc3852bf52ef
parent 55abf077
No related branches found
No related tags found
No related merge requests found
...@@ -204,14 +204,6 @@ public: ...@@ -204,14 +204,6 @@ public:
*/ */
IpAddr publishedIp_[2] {}; IpAddr publishedIp_[2] {};
// This will be stored in the configuration
std::string publishedIpAddress_ {};
/**
* Published port, used only if defined by the user
*/
pj_uint16_t publishedPort_ {sip_utils::DEFAULT_SIP_PORT};
/** /**
* interface name on which this account is bound * interface name on which this account is bound
*/ */
......
...@@ -24,81 +24,13 @@ ...@@ -24,81 +24,13 @@
#include <cstring> // strcmp #include <cstring> // strcmp
#include <memory> #include <memory>
#include <pjsip/sip_msg.h>
#include <pjlib.h> #include <pjlib.h>
#include <pj/pool.h>
#include <pjsip/sip_endpoint.h>
#include <pjsip/sip_dialog.h>
namespace dhtnet { namespace dhtnet {
namespace sip_utils { namespace sip_utils {
using namespace std::literals; using namespace std::literals;
// SIP methods. Only list methods that need to be explicitly
// handled
namespace SIP_METHODS {
constexpr std::string_view MESSAGE = "MESSAGE"sv;
constexpr std::string_view INFO = "INFO"sv;
constexpr std::string_view OPTIONS = "OPTIONS"sv;
constexpr std::string_view PUBLISH = "PUBLISH"sv;
constexpr std::string_view REFER = "REFER"sv;
constexpr std::string_view NOTIFY = "NOTIFY"sv;
} // namespace SIP_METHODS
static constexpr int DEFAULT_SIP_PORT {5060};
static constexpr int DEFAULT_SIP_TLS_PORT {5061};
static constexpr int DEFAULT_AUTO_SELECT_PORT {0};
/// PjsipErrorCategory - a PJSIP error category for std::error_code
class PjsipErrorCategory final : public std::error_category
{
public:
const char* name() const noexcept override { return "pjsip"; }
std::string message(int condition) const override;
};
/// PJSIP related exception
/// Based on std::system_error with code() returning std::error_code with PjsipErrorCategory category
class PjsipFailure : public std::system_error
{
private:
static constexpr const char* what_ = "PJSIP call failed";
public:
PjsipFailure()
: std::system_error(std::error_code(PJ_EUNKNOWN, PjsipErrorCategory()), what_)
{}
explicit PjsipFailure(pj_status_t status)
: std::system_error(std::error_code(status, PjsipErrorCategory()), what_)
{}
};
/**
* Helper function to parser header from incoming sip messages
* @return Header from SIP message
*/
/*std::string fetchHeaderValue(pjsip_msg* msg, const std::string& field);
pjsip_route_hdr* createRouteSet(const std::string& route, pj_pool_t* hdr_pool);
std::string_view stripSipUriPrefix(std::string_view sipUri);
std::string parseDisplayName(const pjsip_name_addr* sip_name_addr);
std::string parseDisplayName(const pjsip_from_hdr* header);
std::string parseDisplayName(const pjsip_contact_hdr* header);
std::string_view getHostFromUri(std::string_view sipUri);
void addContactHeader(const std::string& contact, pjsip_tx_data* tdata);
void addUserAgentHeader(const std::string& userAgent, pjsip_tx_data* tdata);
std::string_view getPeerUserAgent(const pjsip_rx_data* rdata);
std::vector<std::string> getPeerAllowMethods(const pjsip_rx_data* rdata);
void logMessageHeaders(const pjsip_hdr* hdr_list);*/
std::string_view sip_strerror(pj_status_t code); std::string_view sip_strerror(pj_status_t code);
// Helper function that return a constant pj_str_t from an array of any types // Helper function that return a constant pj_str_t from an array of any types
...@@ -129,42 +61,5 @@ as_view(const pj_str_t& str) noexcept ...@@ -129,42 +61,5 @@ as_view(const pj_str_t& str) noexcept
return {str.ptr, (size_t) str.slen}; return {str.ptr, (size_t) str.slen};
} }
// PJSIP dialog locking in RAII way
// Usage: declare local variable like this: sip_utils::PJDialogLock lock {dialog};
// The lock is kept until the local variable is deleted
class PJDialogLock
{
public:
explicit PJDialogLock(pjsip_dialog* dialog)
: dialog_(dialog)
{
pjsip_dlg_inc_lock(dialog_);
}
~PJDialogLock() { pjsip_dlg_dec_lock(dialog_); }
private:
PJDialogLock(const PJDialogLock&) = delete;
PJDialogLock& operator=(const PJDialogLock&) = delete;
pjsip_dialog* dialog_ {nullptr};
};
// Helper on PJSIP memory pool allocation from endpoint
// This encapsulate the allocated memory pool inside a unique_ptr
static inline std::unique_ptr<pj_pool_t, decltype(pj_pool_release)&>
smart_alloc_pool(pjsip_endpoint* endpt, const char* const name, pj_size_t initial, pj_size_t inc)
{
auto pool = pjsip_endpt_create_pool(endpt, name, initial, inc);
if (not pool)
throw std::bad_alloc();
return std::unique_ptr<pj_pool_t, decltype(pj_pool_release)&>(pool, pj_pool_release);
}
void sockaddr_to_host_port(pj_pool_t* pool, pjsip_host_port* host_port, const pj_sockaddr* addr);
static constexpr int POOL_TP_INIT {512};
static constexpr int POOL_TP_INC {512};
static constexpr int TRANSPORT_INFO_LENGTH {64};
} // namespace sip_utils } // namespace sip_utils
} // namespace dhtnet } // namespace dhtnet
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment