mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 11:06:31 +00:00
res_pjsip: Backport pjsip uri utilities.
The following utilities have been backported:
ast_sip_is_uri_sip_sips
ast_sip_is_allowed_uri
ast_sip_pjsip_uri_get_username
ast_sip_pjsip_uri_get_hostname
ast_sip_pjsip_uri_get_other_param
They were originally included in the commit for supporting TEL uris.
Support for TEL uris is NOT included here however.
(cherry picked from commit e1a205074b
)
This commit is contained in:
committed by
Asterisk Development Team
parent
2afd523fc4
commit
27d283c93c
@@ -120,6 +120,8 @@ struct pjsip_tpselector;
|
||||
|
||||
AST_VECTOR(ast_sip_service_route_vector, char *);
|
||||
|
||||
static const pj_str_t AST_PJ_STR_EMPTY = { "", 0 };
|
||||
|
||||
/*!
|
||||
* \brief Structure for SIP transport information
|
||||
*/
|
||||
@@ -3757,6 +3759,79 @@ void ast_sip_transport_state_register(struct ast_sip_tpmgr_state_callback *eleme
|
||||
*/
|
||||
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
|
||||
*
|
||||
* \retval 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 Find an 'other' SIP/SIPS URI parameter by name
|
||||
* \since 16.28.0
|
||||
*
|
||||
* A convenience function to find a named parameter from a SIP/SIPS URI. This
|
||||
* function will not find the following standard SIP/SIPS URI parameters which
|
||||
* are stored separately by PJSIP:
|
||||
*
|
||||
* \li `user`
|
||||
* \li `method`
|
||||
* \li `transport`
|
||||
* \li `ttl`
|
||||
* \li `lr`
|
||||
* \li `maddr`
|
||||
*
|
||||
* \param uri The pjsip_uri to get the parameter from
|
||||
* \param param_str The name of the parameter to find
|
||||
*
|
||||
* \note This function will check what kind of URI it receives and return
|
||||
* the parameter based off of that
|
||||
*
|
||||
* \return Find parameter or NULL if not present
|
||||
*/
|
||||
struct pjsip_param *ast_sip_pjsip_uri_get_other_param(pjsip_uri *uri, const pj_str_t *param_str);
|
||||
|
||||
/*!
|
||||
* \brief Convert name to SIP response code
|
||||
*
|
||||
|
@@ -2504,6 +2504,54 @@ struct ast_threadpool *ast_sip_threadpool(void)
|
||||
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));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct response_code_map {
|
||||
int code;
|
||||
|
Reference in New Issue
Block a user