Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dhtnet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
dhtnet
Commits
9fab9906
Commit
9fab9906
authored
1 year ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
sip utils: cleanup
Change-Id: I509dde22a2c7fa76a7eea946aaa4fc3852bf52ef
parent
55abf077
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/connectionmanager.cpp
+0
-8
0 additions, 8 deletions
src/connectionmanager.cpp
src/sip_utils.h
+0
-105
0 additions, 105 deletions
src/sip_utils.h
with
0 additions
and
113 deletions
src/connectionmanager.cpp
+
0
−
8
View file @
9fab9906
...
@@ -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
*/
*/
...
...
This diff is collapsed.
Click to expand it.
src/sip_utils.h
+
0
−
105
View file @
9fab9906
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment