[Asterisk-code-review] res_pjsip: Add TEL URI support for basic calls. (asterisk[20])
Benjamin Keith Ford
asteriskteam at digium.com
Mon Sep 12 10:21:40 CDT 2022
Benjamin Keith Ford has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19236 )
Change subject: res_pjsip: Add TEL URI support for basic calls.
......................................................................
res_pjsip: Add TEL URI support for basic calls.
This change allows TEL URI requests to come through for basic calls. The
allowed requests are INVITE, ACK, BYE, and CANCEL. The From and To
headers will now allow TEL URIs, as well as the request URI.
Support is only for TEL URIs present in traffic from a remote party.
Asterisk does not generate any TEL URIs on its own.
ASTERISK-26894
Change-Id: If5729e6cd583be7acf666373bf9f1b9d653ec29a
---
M channels/chan_pjsip.c
M configs/samples/pjsip.conf.sample
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
M res/res_pjsip/pjsip_distributor.c
M res/res_pjsip/pjsip_message_filter.c
M res/res_pjsip/pjsip_options.c
M res/res_pjsip_caller_id.c
M res/res_pjsip_dialog_info_body_generator.c
M res/res_pjsip_diversion.c
M res/res_pjsip_endpoint_identifier_anonymous.c
M res/res_pjsip_endpoint_identifier_user.c
M res/res_pjsip_messaging.c
M res/res_pjsip_nat.c
M res/res_pjsip_outbound_registration.c
M res/res_pjsip_path.c
M res/res_pjsip_pubsub.c
M res/res_pjsip_session.c
18 files changed, 238 insertions(+), 73 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/36/19236/1
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 07b9088..3e8abd2 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -3009,11 +3009,11 @@
static void set_sipdomain_variable(struct ast_sip_session *session)
{
- pjsip_sip_uri *sip_ruri = pjsip_uri_get_uri(session->request_uri);
- size_t size = pj_strlen(&sip_ruri->host) + 1;
+ const pj_str_t *host = ast_sip_pjsip_uri_get_hostname(session->request_uri);
+ size_t size = pj_strlen(host) + 1;
char *domain = ast_alloca(size);
- ast_copy_pj_str(domain, &sip_ruri->host, size);
+ ast_copy_pj_str(domain, host, size);
pbx_builtin_setvar_helper(session->channel, "SIPDOMAIN", domain);
return;
diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample
index bf9f78c..6fbdb8b 100644
--- a/configs/samples/pjsip.conf.sample
+++ b/configs/samples/pjsip.conf.sample
@@ -1587,3 +1587,16 @@
;mailbox_state_filter= ; Optional regular expression used to filter what
; mailboxes we accept events for.
+
+
+;================================TEL URIs=====================================
+;
+; Asterisk has TEL URI support, but with limited scope. Support is only for
+; TEL URIs present in traffic from a remote party. Asterisk does not generate
+; any TEL URIs of its own.
+;
+; Currently, the allowed request types are INVITE, ACK, BYE, and CANCEL. Any
+; other request type that contains a TEL URI will behave as it did before.
+; TEL URIs are allowed in the request, From, and To headers.
+;
+; You can match a TEL URI From header by IP, header, or auth_username.
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index e688494..dcdf2b3 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -105,6 +105,8 @@
AST_VECTOR(ast_sip_service_route_vector, char *);
+static const pj_str_t AST_PJ_STR_EMPTY = { "", 0 };
+
/*!
* \brief Structure for SIP transport information
*/
@@ -3692,4 +3694,65 @@
*/
void ast_sip_transport_state_unregister(struct ast_sip_tpmgr_state_callback *element);
+/*!
+ * \brief Check whether a pjsip_uri is SIP/SIPS or not
+ * \since 16.28.0
+ *
+ * \param uri The pjsip_uri to check
+ *
+ * \retval 1 if true
+ * \retval 0 if false
+ */
+int ast_sip_is_uri_sip_sips(pjsip_uri *uri);
+
+/*!
+ * \brief Check whether a pjsip_uri is allowed or not
+ * \since 16.28.0
+ *
+ * \param uri The pjsip_uri to check
+ *
+ * \retva; 1 if allowed
+ * \retval 0 if not allowed
+ */
+int ast_sip_is_allowed_uri(pjsip_uri *uri);
+
+/*!
+ * \brief Get the user portion of the pjsip_uri
+ * \since 16.28.0
+ *
+ * \param uri The pjsip_uri to get the user from
+ *
+ * \note This function will check what kind of URI it receives and return
+ * the user based off of that
+ *
+ * \return User string or empty string if not present
+ */
+const pj_str_t *ast_sip_pjsip_uri_get_username(pjsip_uri *uri);
+
+/*!
+ * \brief Get the host portion of the pjsip_uri
+ * \since 16.28.0
+ *
+ * \param uri The pjsip_uri to get the host from
+ *
+ * \note This function will check what kind of URI it receives and return
+ * the host based off of that
+ *
+ * \return Host string or empty string if not present
+ */
+const pj_str_t *ast_sip_pjsip_uri_get_hostname(pjsip_uri *uri);
+
+/*!
+ * \brief Get the other_param portion of the pjsip_uri
+ * \since 16.28.0
+ *
+ * \param uri The pjsip_uri to get hte other_param from
+ *
+ * \note This function will check what kind of URI it receives and return
+ * the other_param based off of that
+ *
+ * \return other_param or NULL if not present
+ */
+struct pjsip_param *ast_sip_pjsip_uri_get_other_param(pjsip_uri *uri, const pj_str_t *param_str);
+
#endif /* _RES_PJSIP_H */
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 2febf3d..c6d9a89 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -2472,6 +2472,69 @@
return sip_threadpool;
}
+int ast_sip_is_uri_sip_sips(pjsip_uri *uri)
+{
+ return (PJSIP_URI_SCHEME_IS_SIP(uri) || PJSIP_URI_SCHEME_IS_SIPS(uri));
+}
+
+int ast_sip_is_allowed_uri(pjsip_uri *uri)
+{
+ return (ast_sip_is_uri_sip_sips(uri) || PJSIP_URI_SCHEME_IS_TEL(uri));
+}
+
+const pj_str_t *ast_sip_pjsip_uri_get_username(pjsip_uri *uri)
+{
+ if (ast_sip_is_uri_sip_sips(uri)) {
+ pjsip_sip_uri *sip_uri = pjsip_uri_get_uri(uri);
+ if (!sip_uri) {
+ return &AST_PJ_STR_EMPTY;
+ }
+ return &sip_uri->user;
+ } else if (PJSIP_URI_SCHEME_IS_TEL(uri)) {
+ pjsip_tel_uri *tel_uri = pjsip_uri_get_uri(uri);
+ if (!tel_uri) {
+ return &AST_PJ_STR_EMPTY;
+ }
+ return &tel_uri->number;
+ }
+
+ return &AST_PJ_STR_EMPTY;
+}
+
+const pj_str_t *ast_sip_pjsip_uri_get_hostname(pjsip_uri *uri)
+{
+ if (ast_sip_is_uri_sip_sips(uri)) {
+ pjsip_sip_uri *sip_uri = pjsip_uri_get_uri(uri);
+ if (!sip_uri) {
+ return &AST_PJ_STR_EMPTY;
+ }
+ return &sip_uri->host;
+ } else if (PJSIP_URI_SCHEME_IS_TEL(uri)) {
+ return &AST_PJ_STR_EMPTY;
+ }
+
+ return &AST_PJ_STR_EMPTY;
+}
+
+struct pjsip_param *ast_sip_pjsip_uri_get_other_param(pjsip_uri *uri, const pj_str_t *param_str)
+{
+ if (ast_sip_is_uri_sip_sips(uri)) {
+ pjsip_sip_uri *sip_uri = pjsip_uri_get_uri(uri);
+ if (!sip_uri) {
+ return NULL;
+ }
+ return pjsip_param_find(&sip_uri->other_param, param_str);
+ } else if (PJSIP_URI_SCHEME_IS_TEL(uri)) {
+ pjsip_tel_uri *tel_uri = pjsip_uri_get_uri(uri);
+ if (!tel_uri) {
+ return NULL;
+ }
+ return pjsip_param_find(&tel_uri->other_param, param_str);
+ }
+
+ return NULL;
+}
+
#ifdef TEST_FRAMEWORK
AST_TEST_DEFINE(xml_sanitization_end_null)
{
diff --git a/res/res_pjsip/pjsip_distributor.c b/res/res_pjsip/pjsip_distributor.c
index ea8fb02..092e012 100644
--- a/res/res_pjsip/pjsip_distributor.c
+++ b/res/res_pjsip/pjsip_distributor.c
@@ -763,9 +763,8 @@
char name[AST_UUID_STR_LEN] = "";
pjsip_uri *from = rdata->msg_info.from->uri;
- if (PJSIP_URI_SCHEME_IS_SIP(from) || PJSIP_URI_SCHEME_IS_SIPS(from)) {
- pjsip_sip_uri *sip_from = pjsip_uri_get_uri(from);
- ast_copy_pj_str(name, &sip_from->user, sizeof(name));
+ if (ast_sip_is_allowed_uri(from)) {
+ ast_copy_pj_str(name, ast_sip_pjsip_uri_get_username(from), sizeof(name));
}
unid = ao2_find(unidentified_requests, rdata->pkt_info.src_name, OBJ_SEARCH_KEY);
@@ -833,6 +832,7 @@
*addrs = NULL;
return 0;
}
+
if (!PJSIP_URI_SCHEME_IS_SIP(contact->uri) && !PJSIP_URI_SCHEME_IS_SIPS(contact->uri)) {
*addrs = NULL;
return 0;
diff --git a/res/res_pjsip/pjsip_message_filter.c b/res/res_pjsip/pjsip_message_filter.c
index edac55f..7f1b7d7 100644
--- a/res/res_pjsip/pjsip_message_filter.c
+++ b/res/res_pjsip/pjsip_message_filter.c
@@ -190,7 +190,7 @@
pjsip_hdr *hdr;
if (tdata->msg->type == PJSIP_REQUEST_MSG) {
- if (is_sip_uri(tdata->msg->line.req.uri)) {
+ if (ast_sip_is_uri_sip_sips(tdata->msg->line.req.uri)) {
uri = pjsip_uri_get_uri(tdata->msg->line.req.uri);
print_sanitize_debug("Sanitizing Request", PJSIP_URI_IN_REQ_URI, uri);
while ((x_transport = pjsip_param_find(&uri->other_param, &x_name))) {
@@ -201,7 +201,7 @@
for (hdr = tdata->msg->hdr.next; hdr != &tdata->msg->hdr; hdr = hdr->next) {
if (hdr->type == PJSIP_H_TO || hdr->type == PJSIP_H_FROM) {
- if (is_sip_uri(((pjsip_fromto_hdr *) hdr)->uri)) {
+ if (ast_sip_is_uri_sip_sips(((pjsip_fromto_hdr *) hdr)->uri)) {
uri = pjsip_uri_get_uri(((pjsip_fromto_hdr *) hdr)->uri);
print_sanitize_debug("Sanitizing From/To header", PJSIP_URI_IN_FROMTO_HDR, uri);
while ((x_transport = pjsip_param_find(&uri->other_param, &x_name))) {
@@ -209,7 +209,7 @@
}
}
} else if (hdr->type == PJSIP_H_CONTACT) {
- if (!((pjsip_contact_hdr *) hdr)->star && is_sip_uri(((pjsip_contact_hdr *) hdr)->uri)) {
+ if (!((pjsip_contact_hdr *) hdr)->star && ast_sip_is_uri_sip_sips(((pjsip_contact_hdr *) hdr)->uri)) {
uri = pjsip_uri_get_uri(((pjsip_contact_hdr *) hdr)->uri);
print_sanitize_debug("Sanitizing Contact header", PJSIP_URI_IN_CONTACT_HDR, uri);
while ((x_transport = pjsip_param_find(&uri->other_param, &x_name))) {
@@ -288,7 +288,7 @@
if (tdata->msg->type == PJSIP_REQUEST_MSG || !(cseq = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL)) ||
pj_strcmp2(&cseq->method.name, "REGISTER")) {
pjsip_contact_hdr *contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
- if (contact && (PJSIP_URI_SCHEME_IS_SIP(contact->uri) || PJSIP_URI_SCHEME_IS_SIPS(contact->uri))
+ if (contact && ast_sip_is_uri_sip_sips(contact->uri)
&& !(tdata->msg->type == PJSIP_RESPONSE_MSG && tdata->msg->line.status.code / 100 == 3)) {
pjsip_sip_uri *uri = pjsip_uri_get_uri(contact->uri);
@@ -440,6 +440,10 @@
return;
}
+ if (PJSIP_URI_SCHEME_IS_TEL(header_uri)) {
+ return;
+ }
+
uri = pjsip_uri_get_uri(header_uri);
if (!uri) {
return;
@@ -458,6 +462,25 @@
}
}
+/* An allow list helper function for tel URI requests */
+static int is_allowed_tel_uri_request(pjsip_rx_data *rdata)
+{
+ struct pjsip_request_line req = rdata->msg_info.msg->line.req;
+ const pjsip_method method = (const pjsip_method)req.method;
+
+ if (pjsip_method_cmp(&method, pjsip_get_invite_method())) {
+ return 1;
+ } else if (pjsip_method_cmp(&method, pjsip_get_ack_method())) {
+ return 1;
+ } else if (pjsip_method_cmp(&method, pjsip_get_bye_method())) {
+ return 1;
+ } else if (pjsip_method_cmp(&method, pjsip_get_cancel_method())) {
+ return 1;
+ }
+
+ return 0;
+}
+
static pj_bool_t on_rx_process_uris(pjsip_rx_data *rdata)
{
pjsip_contact_hdr *contact = NULL;
@@ -466,7 +489,8 @@
return PJ_FALSE;
}
- if (!is_sip_uri(rdata->msg_info.msg->line.req.uri)) {
+ if (PJSIP_URI_SCHEME_IS_TEL(rdata->msg_info.msg->line.req.uri)
+ && !is_allowed_tel_uri_request(rdata)) {
print_uri_debug(URI_TYPE_REQUEST, rdata, NULL);
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
@@ -474,7 +498,7 @@
}
remove_x_ast_params(rdata->msg_info.msg->line.req.uri);
- if (!is_sip_uri(rdata->msg_info.from->uri)) {
+ if (!ast_sip_is_allowed_uri(rdata->msg_info.from->uri)) {
print_uri_debug(URI_TYPE_FROM, rdata, (pjsip_hdr *)rdata->msg_info.from);
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
@@ -482,7 +506,7 @@
}
remove_x_ast_params(rdata->msg_info.from->uri);
- if (!is_sip_uri(rdata->msg_info.to->uri)) {
+ if (!ast_sip_is_allowed_uri(rdata->msg_info.to->uri)) {
print_uri_debug(URI_TYPE_TO, rdata, (pjsip_hdr *)rdata->msg_info.to);
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata,
PJSIP_SC_UNSUPPORTED_URI_SCHEME, NULL, NULL, NULL);
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index 4f48257..7632dea 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -269,7 +269,6 @@
{
RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
pjsip_uri *ruri;
- pjsip_sip_uri *sip_ruri;
char exten[AST_MAX_EXTENSION];
if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_options_method)) {
@@ -281,13 +280,12 @@
}
ruri = rdata->msg_info.msg->line.req.uri;
- if (!PJSIP_URI_SCHEME_IS_SIP(ruri) && !PJSIP_URI_SCHEME_IS_SIPS(ruri)) {
+ if (!ast_sip_is_allowed_uri(ruri)) {
send_options_response(rdata, 416);
return PJ_TRUE;
}
- sip_ruri = pjsip_uri_get_uri(ruri);
- ast_copy_pj_str(exten, &sip_ruri->user, sizeof(exten));
+ ast_copy_pj_str(exten, ast_sip_pjsip_uri_get_username(ruri), sizeof(exten));
/*
* We may want to match in the dialplan without any user
diff --git a/res/res_pjsip_caller_id.c b/res/res_pjsip_caller_id.c
index 96e2cf9..64fd8c7 100644
--- a/res/res_pjsip_caller_id.c
+++ b/res/res_pjsip_caller_id.c
@@ -45,13 +45,11 @@
{
char cid_name[AST_CHANNEL_NAME];
char cid_num[AST_CHANNEL_NAME];
- pjsip_sip_uri *uri;
pjsip_name_addr *id_name_addr = (pjsip_name_addr *) hdr->uri;
char *semi;
- uri = pjsip_uri_get_uri(id_name_addr);
ast_copy_pj_str(cid_name, &id_name_addr->display, sizeof(cid_name));
- ast_copy_pj_str(cid_num, &uri->user, sizeof(cid_num));
+ ast_copy_pj_str(cid_num, ast_sip_pjsip_uri_get_username(hdr->uri), sizeof(cid_num));
/* Always truncate caller-id number at a semicolon. */
semi = strchr(cid_num, ';');
diff --git a/res/res_pjsip_dialog_info_body_generator.c b/res/res_pjsip_dialog_info_body_generator.c
index 972b908..9efb154 100644
--- a/res/res_pjsip_dialog_info_body_generator.c
+++ b/res/res_pjsip_dialog_info_body_generator.c
@@ -183,7 +183,6 @@
int remote_connected_num_restricted;
char *local_caller_num;
pjsip_dialog *dlg = ast_sip_subscription_get_dialog(state_data->sub);
- pjsip_sip_uri *dlg_remote_fromhdr = pjsip_uri_get_uri(dlg->local.info->uri);
char remote_target[PJSIP_MAX_URL_SIZE + 32];
char dlg_remote_uri[PJSIP_MAX_URL_SIZE];
char *from_domain_stripped;
@@ -191,7 +190,7 @@
pj_xml_node *remote_node, *remote_identity_node, *remote_target_node;
/* We use the local dialog URI to determine the domain to use in the XML itself */
- ast_copy_pj_str(dlg_remote_uri, &dlg_remote_fromhdr->host, sizeof(dlg_remote_uri));
+ ast_copy_pj_str(dlg_remote_uri, ast_sip_pjsip_uri_get_hostname(dlg->local.info->uri), sizeof(dlg_remote_uri));
from_domain_stripped = ast_strip_quoted(dlg_remote_uri, "<", ">");
ast_sip_sanitize_xml(from_domain_stripped, from_domain_sanitized, sizeof(from_domain_sanitized));
diff --git a/res/res_pjsip_diversion.c b/res/res_pjsip_diversion.c
index 1cc6e08..b5191a9 100644
--- a/res/res_pjsip_diversion.c
+++ b/res/res_pjsip_diversion.c
@@ -327,15 +327,15 @@
struct ast_party_redirecting_reason *data)
{
static const pj_str_t cause_name = { "cause", 5 };
- pjsip_sip_uri *uri = pjsip_uri_get_uri(name_addr);
+ pjsip_uri *uri = name_addr->uri;
pjsip_param *cause = NULL;
unsigned long cause_value = 0;
- if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri)) {
+ if (!ast_sip_is_allowed_uri(uri)) {
return;
}
- cause = pjsip_param_find(&uri->other_param, &cause_name);
+ cause = ast_sip_pjsip_uri_get_other_param(uri, &cause_name);
if (!cause) {
return;
@@ -507,7 +507,6 @@
pjsip_fromto_hdr *hdr;
pjsip_name_addr *name_addr;
- pjsip_sip_uri *uri;
pjsip_param *param;
pjsip_fromto_hdr *old_hdr;
const char *reason_str;
@@ -534,10 +533,9 @@
hdr->sname = hdr->name = diversion_name;
name_addr = pjsip_uri_clone(tdata->pool, base);
- uri = pjsip_uri_get_uri(name_addr->uri);
pj_strdup2(tdata->pool, &name_addr->display, id->name.str);
- pj_strdup2(tdata->pool, &uri->user, id->number.str);
+ pj_strdup2(tdata->pool, (pj_str_t *)ast_sip_pjsip_uri_get_username(name_addr->uri), id->number.str);
param = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);
param->name = reason_name;
diff --git a/res/res_pjsip_endpoint_identifier_anonymous.c b/res/res_pjsip_endpoint_identifier_anonymous.c
index 63fc405..cc4cd4b 100644
--- a/res/res_pjsip_endpoint_identifier_anonymous.c
+++ b/res/res_pjsip_endpoint_identifier_anonymous.c
@@ -33,12 +33,10 @@
static int get_endpoint_details(pjsip_rx_data *rdata, char *domain, size_t domain_size)
{
pjsip_uri *from = rdata->msg_info.from->uri;
- pjsip_sip_uri *sip_from;
- if (!PJSIP_URI_SCHEME_IS_SIP(from) && !PJSIP_URI_SCHEME_IS_SIPS(from)) {
+ if (!ast_sip_is_uri_sip_sips(from)) {
return -1;
}
- sip_from = (pjsip_sip_uri *) pjsip_uri_get_uri(from);
- ast_copy_pj_str(domain, &sip_from->host, domain_size);
+ ast_copy_pj_str(domain, ast_sip_pjsip_uri_get_hostname(from), domain_size);
return 0;
}
diff --git a/res/res_pjsip_endpoint_identifier_user.c b/res/res_pjsip_endpoint_identifier_user.c
index 46e82db..481cd3b 100644
--- a/res/res_pjsip_endpoint_identifier_user.c
+++ b/res/res_pjsip_endpoint_identifier_user.c
@@ -32,14 +32,14 @@
static int get_from_header(pjsip_rx_data *rdata, char *username, size_t username_size, char *domain, size_t domain_size)
{
pjsip_uri *from = rdata->msg_info.from->uri;
- pjsip_sip_uri *sip_from;
- if (!PJSIP_URI_SCHEME_IS_SIP(from) && !PJSIP_URI_SCHEME_IS_SIPS(from)) {
+ if (!ast_sip_is_uri_sip_sips(from)) {
return -1;
}
- sip_from = (pjsip_sip_uri *) pjsip_uri_get_uri(from);
- ast_copy_pj_str(username, &sip_from->user, username_size);
- ast_copy_pj_str(domain, &sip_from->host, domain_size);
+
+ ast_copy_pj_str(username, ast_sip_pjsip_uri_get_username(from), username_size);
+ ast_copy_pj_str(domain, ast_sip_pjsip_uri_get_hostname(from), domain_size);
+
return 0;
}
diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c
index f0db27c..336d392 100644
--- a/res/res_pjsip_messaging.c
+++ b/res/res_pjsip_messaging.c
@@ -1055,7 +1055,6 @@
{
RAII_VAR(struct ast_sip_endpoint *, endpt, NULL, ao2_cleanup);
pjsip_uri *ruri = rdata->msg_info.msg->line.req.uri;
- pjsip_sip_uri *sip_ruri;
pjsip_name_addr *name_addr;
char buf[MAX_BODY_SIZE];
const char *field;
@@ -1064,12 +1063,11 @@
int res = 0;
int size;
- if (!PJSIP_URI_SCHEME_IS_SIP(ruri) && !PJSIP_URI_SCHEME_IS_SIPS(ruri)) {
+ if (!ast_sip_is_allowed_uri(ruri)) {
return PJSIP_SC_UNSUPPORTED_URI_SCHEME;
}
- sip_ruri = pjsip_uri_get_uri(ruri);
- ast_copy_pj_str(exten, &sip_ruri->user, AST_MAX_EXTENSION);
+ ast_copy_pj_str(exten, ast_sip_pjsip_uri_get_username(ruri), AST_MAX_EXTENSION);
/*
* We may want to match in the dialplan without any user
diff --git a/res/res_pjsip_nat.c b/res/res_pjsip_nat.c
index 2d5e6a7..59223f7 100644
--- a/res/res_pjsip_nat.c
+++ b/res/res_pjsip_nat.c
@@ -112,7 +112,6 @@
* for the subsequent requests and responses & then be able to properly update
* the dialog object for all required events.
*/
-
static int rewrite_route_set(pjsip_rx_data *rdata, pjsip_dialog *dlg)
{
pjsip_rr_hdr *rr = NULL;
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index 20a4761..0c9b1ee 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -511,14 +511,9 @@
static struct pjsip_param *get_uri_option_line(const void *uri)
{
- pjsip_sip_uri *pjuri;
static const pj_str_t LINE_STR = { "line", 4 };
- if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri)) {
- return NULL;
- }
- pjuri = pjsip_uri_get_uri(uri);
- return pjsip_param_find(&pjuri->other_param, &LINE_STR);
+ return ast_sip_pjsip_uri_get_other_param((pjsip_uri *)uri, &LINE_STR);
}
/*! \brief Endpoint identifier which uses the 'line' parameter to establish a relationship to an outgoing registration */
diff --git a/res/res_pjsip_path.c b/res/res_pjsip_path.c
index 5eb3d49..5272a5c 100644
--- a/res/res_pjsip_path.c
+++ b/res/res_pjsip_path.c
@@ -39,7 +39,8 @@
static struct ast_sip_aor *find_aor(struct ast_sip_endpoint *endpoint, pjsip_uri *uri)
{
char *configured_aors, *aor_name;
- pjsip_sip_uri *sip_uri;
+ const pj_str_t *uri_username;
+ const pj_str_t *uri_hostname;
char *domain_name;
char *username;
struct ast_str *id = NULL;
@@ -48,11 +49,13 @@
return NULL;
}
- sip_uri = pjsip_uri_get_uri(uri);
- domain_name = ast_alloca(sip_uri->host.slen + 1);
- ast_copy_pj_str(domain_name, &sip_uri->host, sip_uri->host.slen + 1);
- username = ast_alloca(sip_uri->user.slen + 1);
- ast_copy_pj_str(username, &sip_uri->user, sip_uri->user.slen + 1);
+ uri_hostname = ast_sip_pjsip_uri_get_hostname(uri);
+ domain_name = ast_alloca(uri_hostname->slen + 1);
+ ast_copy_pj_str(domain_name, uri_hostname, uri_hostname->slen + 1);
+
+ uri_username = ast_sip_pjsip_uri_get_username(uri);
+ username = ast_alloca(uri_username->slen + 1);
+ ast_copy_pj_str(username, uri_username, uri_username->slen + 1);
/*
* We may want to match without any user options getting
@@ -74,7 +77,7 @@
break;
}
- if (!id && !(id = ast_str_create(strlen(username) + sip_uri->host.slen + 2))) {
+ if (!id && !(id = ast_str_create(strlen(username) + uri_hostname->slen + 2))) {
aor_name = NULL;
break;
}
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index 4086445..d767269 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -1596,17 +1596,17 @@
struct ast_sip_pubsub_body_generator *generator;
struct ast_sip_subscription_handler *handler;
char *resource;
- pjsip_sip_uri *request_uri;
size_t resource_size;
int resp;
struct resource_tree tree;
pjsip_expires_hdr *expires_header;
int64_t expires;
+ const pj_str_t *user;
- request_uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
- resource_size = pj_strlen(&request_uri->user) + 1;
+ user = ast_sip_pjsip_uri_get_username(rdata->msg_info.msg->line.req.uri);
+ resource_size = pj_strlen(user) + 1;
resource = ast_alloca(resource_size);
- ast_copy_pj_str(resource, &request_uri->user, resource_size);
+ ast_copy_pj_str(resource, user, resource_size);
/*
* We may want to match without any user options getting
@@ -3015,11 +3015,11 @@
struct ast_sip_pubsub_body_generator *generator;
char *resource;
pjsip_uri *request_uri;
- pjsip_sip_uri *request_uri_sip;
size_t resource_size;
int resp;
struct resource_tree tree;
pj_status_t dlg_status;
+ const pj_str_t *user;
endpoint = ast_pjsip_rdata_get_endpoint(rdata);
ast_assert(endpoint != NULL);
@@ -3032,7 +3032,7 @@
request_uri = rdata->msg_info.msg->line.req.uri;
- if (!PJSIP_URI_SCHEME_IS_SIP(request_uri) && !PJSIP_URI_SCHEME_IS_SIPS(request_uri)) {
+ if (!ast_sip_is_uri_sip_sips(request_uri)) {
char uri_str[PJSIP_MAX_URL_SIZE];
pjsip_uri_print(PJSIP_URI_IN_REQ_URI, request_uri, uri_str, sizeof(uri_str));
@@ -3041,10 +3041,10 @@
return PJ_TRUE;
}
- request_uri_sip = pjsip_uri_get_uri(request_uri);
- resource_size = pj_strlen(&request_uri_sip->user) + 1;
+ user = ast_sip_pjsip_uri_get_username(request_uri);
+ resource_size = pj_strlen(user) + 1;
resource = ast_alloca(resource_size);
- ast_copy_pj_str(resource, &request_uri_sip->user, resource_size);
+ ast_copy_pj_str(resource, user, resource_size);
/*
* We may want to match without any user options getting
@@ -3260,12 +3260,12 @@
RAII_VAR(struct ast_sip_publication_resource *, resource, NULL, ao2_cleanup);
struct ast_variable *event_configuration_name = NULL;
pjsip_uri *request_uri;
- pjsip_sip_uri *request_uri_sip;
int resp;
+ const pj_str_t *user;
request_uri = rdata->msg_info.msg->line.req.uri;
- if (!PJSIP_URI_SCHEME_IS_SIP(request_uri) && !PJSIP_URI_SCHEME_IS_SIPS(request_uri)) {
+ if (!ast_sip_is_uri_sip_sips(request_uri)) {
char uri_str[PJSIP_MAX_URL_SIZE];
pjsip_uri_print(PJSIP_URI_IN_REQ_URI, request_uri, uri_str, sizeof(uri_str));
@@ -3274,10 +3274,10 @@
return NULL;
}
- request_uri_sip = pjsip_uri_get_uri(request_uri);
- resource_size = pj_strlen(&request_uri_sip->user) + 1;
+ user = ast_sip_pjsip_uri_get_username(request_uri);
+ resource_size = pj_strlen(user) + 1;
resource_name = ast_alloca(resource_size);
- ast_copy_pj_str(resource_name, &request_uri_sip->user, resource_size);
+ ast_copy_pj_str(resource_name, user, resource_size);
/*
* We may want to match without any user options getting
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index d4a857f..858faf3 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -3665,16 +3665,14 @@
static enum sip_get_destination_result get_destination(struct ast_sip_session *session, pjsip_rx_data *rdata)
{
pjsip_uri *ruri = rdata->msg_info.msg->line.req.uri;
- pjsip_sip_uri *sip_ruri;
struct ast_features_pickup_config *pickup_cfg;
const char *pickupexten;
- if (!PJSIP_URI_SCHEME_IS_SIP(ruri) && !PJSIP_URI_SCHEME_IS_SIPS(ruri)) {
+ if (!ast_sip_is_allowed_uri(ruri)) {
return SIP_GET_DEST_UNSUPPORTED_URI;
}
- sip_ruri = pjsip_uri_get_uri(ruri);
- ast_copy_pj_str(session->exten, &sip_ruri->user, sizeof(session->exten));
+ ast_copy_pj_str(session->exten, ast_sip_pjsip_uri_get_username(ruri), sizeof(session->exten));
/*
* We may want to match in the dialplan without any user
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19236
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 20
Gerrit-Change-Id: If5729e6cd583be7acf666373bf9f1b9d653ec29a
Gerrit-Change-Number: 19236
Gerrit-PatchSet: 1
Gerrit-Owner: Benjamin Keith Ford <bford at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220912/6386ab4f/attachment-0001.html>
More information about the asterisk-code-review
mailing list