Asterisk - The Open Source Telephony Project GIT-master-a358458
Functions | Variables
res_pjsip_path.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_ua.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
#include "asterisk/module.h"
#include "asterisk/strings.h"
Include dependency graph for res_pjsip_path.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int add_supported (pjsip_tx_data *tdata)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static struct ast_sip_aorfind_aor (struct ast_sip_contact *contact)
 
static int load_module (void)
 
static int path_get_string (pj_pool_t *pool, struct ast_sip_contact *contact, pj_str_t *path_str)
 Get the path string associated with this contact and tdata. More...
 
static void path_outgoing_request (struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, pjsip_tx_data *tdata)
 
static void path_outgoing_response (struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, pjsip_tx_data *tdata)
 
static void path_session_outgoing_request (struct ast_sip_session *session, pjsip_tx_data *tdata)
 
static void path_session_outgoing_response (struct ast_sip_session *session, pjsip_tx_data *tdata)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP Path Header Support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, .requires = "res_pjsip,res_pjsip_session", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const pj_str_t PATH_NAME = { "Path", 4 }
 
static struct ast_sip_session_supplement path_session_supplement
 
static struct ast_sip_supplement path_supplement
 
static pj_str_t PATH_SUPPORTED_NAME = { "path", 4 }
 

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 215 of file res_pjsip_path.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 215 of file res_pjsip_path.c.

◆ add_supported()

static int add_supported ( pjsip_tx_data *  tdata)
static

Definition at line 71 of file res_pjsip_path.c.

72{
73 pjsip_supported_hdr *hdr;
74 int i;
75
76 hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_SUPPORTED, NULL);
77 if (!hdr) {
78 /* insert a new Supported header */
79 hdr = pjsip_supported_hdr_create(tdata->pool);
80 if (!hdr) {
81 return -1;
82 }
83
84 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
85 }
86
87 /* Don't add the value if it's already there */
88 for (i = 0; i < hdr->count; ++i) {
89 if (pj_stricmp(&hdr->values[i], &PATH_SUPPORTED_NAME) == 0) {
90 return 0;
91 }
92 }
93
94 if (hdr->count >= PJSIP_GENERIC_ARRAY_MAX_COUNT) {
95 return -1;
96 }
97
98 /* add on to the existing Supported header */
99 pj_strassign(&hdr->values[hdr->count++], &PATH_SUPPORTED_NAME);
100
101 return 0;
102}
static pj_str_t PATH_SUPPORTED_NAME
#define NULL
Definition: resample.c:96

References NULL, and PATH_SUPPORTED_NAME.

Referenced by path_outgoing_request(), and path_outgoing_response().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 215 of file res_pjsip_path.c.

◆ find_aor()

static struct ast_sip_aor * find_aor ( struct ast_sip_contact contact)
static

Definition at line 39 of file res_pjsip_path.c.

40{
41 if (!contact) {
42 return NULL;
43 }
44 if (ast_strlen_zero(contact->aor)) {
45 return NULL;
46 }
47
48 return ast_sip_location_retrieve_aor(contact->aor);
49}
struct ast_sip_aor * ast_sip_location_retrieve_aor(const char *aor_name)
Retrieve a named AOR.
Definition: location.c:147
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
const ast_string_field aor
Definition: res_pjsip.h:414

References ast_sip_contact::aor, ast_sip_location_retrieve_aor(), ast_strlen_zero(), and NULL.

Referenced by path_outgoing_request(), and path_outgoing_response().

◆ load_module()

static int load_module ( void  )
static

Definition at line 194 of file res_pjsip_path.c.

195{
198
200}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
void ast_sip_register_supplement(struct ast_sip_supplement *supplement)
Register a supplement to SIP out of dialog processing.
Definition: res_pjsip.c:1456
static struct ast_sip_supplement path_supplement
static struct ast_sip_session_supplement path_session_supplement
#define ast_sip_session_register_supplement(supplement)

References AST_MODULE_LOAD_SUCCESS, ast_sip_register_supplement(), ast_sip_session_register_supplement, path_session_supplement, and path_supplement.

◆ path_get_string()

static int path_get_string ( pj_pool_t *  pool,
struct ast_sip_contact contact,
pj_str_t *  path_str 
)
static

Get the path string associated with this contact and tdata.

Parameters
pool
contactThe URI identifying the associated contact
path_strThe place to store the retrieved path information
Return values
zeroon success
non-zeroon failure or no available path information

Definition at line 61 of file res_pjsip_path.c.

62{
63 if (!contact || ast_strlen_zero(contact->path)) {
64 return -1;
65 }
66
67 *path_str = pj_strdup3(pool, contact->path);
68 return 0;
69}
const ast_string_field path
Definition: res_pjsip.h:414

References ast_strlen_zero(), and ast_sip_contact::path.

Referenced by path_outgoing_response().

◆ path_outgoing_request()

static void path_outgoing_request ( struct ast_sip_endpoint endpoint,
struct ast_sip_contact contact,
pjsip_tx_data *  tdata 
)
static

Definition at line 113 of file res_pjsip_path.c.

114{
115 RAII_VAR(struct ast_sip_aor *, aor, NULL, ao2_cleanup);
116
117 if (!endpoint) {
118 return;
119 }
120
121 aor = find_aor(contact);
122 if (!aor || !aor->support_path) {
123 return;
124 }
125
126 if (add_supported(tdata)) {
127 return;
128 }
129
130 if (contact && !ast_strlen_zero(contact->path)) {
131 ast_sip_set_outbound_proxy(tdata, contact->path);
132 }
133}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
int ast_sip_set_outbound_proxy(pjsip_tx_data *tdata, const char *proxy)
Set the outbound proxy for an outbound SIP message.
Definition: res_pjsip.c:1992
static struct ast_sip_aor * find_aor(struct ast_sip_contact *contact)
static int add_supported(pjsip_tx_data *tdata)
A SIP address of record.
Definition: res_pjsip.h:478
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References add_supported(), ao2_cleanup, ast_sip_set_outbound_proxy(), ast_strlen_zero(), find_aor(), NULL, ast_sip_contact::path, and RAII_VAR.

Referenced by path_session_outgoing_request().

◆ path_outgoing_response()

static void path_outgoing_response ( struct ast_sip_endpoint endpoint,
struct ast_sip_contact contact,
pjsip_tx_data *  tdata 
)
static

Definition at line 148 of file res_pjsip_path.c.

149{
150 struct pjsip_status_line status = tdata->msg->line.status;
151 pj_str_t path_dup;
152 pjsip_generic_string_hdr *path_hdr;
153 RAII_VAR(struct ast_sip_aor *, aor, NULL, ao2_cleanup);
154 pjsip_cseq_hdr *cseq = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL);
155 const pj_str_t REGISTER_METHOD = {"REGISTER", 8};
156
157 if (!endpoint
158 || !pj_stristr(&REGISTER_METHOD, &cseq->method.name)
159 || !PJSIP_IS_STATUS_IN_CLASS(status.code, 200)) {
160 return;
161 }
162
163 aor = find_aor(contact);
164 if (!aor || !aor->support_path || add_supported(tdata)
165 || path_get_string(tdata->pool, contact, &path_dup)) {
166 return;
167 }
168
169 path_hdr = pjsip_generic_string_hdr_create(tdata->pool, &PATH_NAME, &path_dup);
170 if (!path_hdr) {
171 return;
172 }
173
174 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)path_hdr);
175}
jack_status_t status
Definition: app_jack.c:146
static int path_get_string(pj_pool_t *pool, struct ast_sip_contact *contact, pj_str_t *path_str)
Get the path string associated with this contact and tdata.
static const pj_str_t PATH_NAME

References add_supported(), ao2_cleanup, find_aor(), NULL, path_get_string(), PATH_NAME, RAII_VAR, and status.

Referenced by path_session_outgoing_response().

◆ path_session_outgoing_request()

static void path_session_outgoing_request ( struct ast_sip_session session,
pjsip_tx_data *  tdata 
)
static

Definition at line 135 of file res_pjsip_path.c.

136{
137 path_outgoing_request(session->endpoint, session->contact, tdata);
138}
static struct ast_mansession session
static void path_outgoing_request(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, pjsip_tx_data *tdata)

References path_outgoing_request(), and session.

◆ path_session_outgoing_response()

static void path_session_outgoing_response ( struct ast_sip_session session,
pjsip_tx_data *  tdata 
)
static

Definition at line 177 of file res_pjsip_path.c.

178{
179 path_outgoing_response(session->endpoint, session->contact, tdata);
180}
static void path_outgoing_response(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, pjsip_tx_data *tdata)

References path_outgoing_response(), and session.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 202 of file res_pjsip_path.c.

203{
206 return 0;
207}
void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement)
Unregister a an supplement to SIP out of dialog processing.
Definition: res_pjsip.c:1476
void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
Unregister a an supplement to SIP session processing.
Definition: pjsip_session.c:63

References ast_sip_session_unregister_supplement(), ast_sip_unregister_supplement(), path_session_supplement, and path_supplement.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP Path Header Support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, .requires = "res_pjsip,res_pjsip_session", }
static

Definition at line 215 of file res_pjsip_path.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 215 of file res_pjsip_path.c.

◆ PATH_NAME

const pj_str_t PATH_NAME = { "Path", 4 }
static

Definition at line 36 of file res_pjsip_path.c.

Referenced by path_outgoing_response().

◆ path_session_supplement

struct ast_sip_session_supplement path_session_supplement
static
Initial value:
= {
.outgoing_request = path_session_outgoing_request,
.outgoing_response = path_session_outgoing_response,
}
@ AST_SIP_SUPPLEMENT_PRIORITY_CHANNEL
Definition: res_pjsip.h:3186
static void path_session_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata)
static void path_session_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)

Definition at line 188 of file res_pjsip_path.c.

Referenced by load_module(), and unload_module().

◆ path_supplement

struct ast_sip_supplement path_supplement
static
Initial value:
= {
.outgoing_request = path_outgoing_request,
.outgoing_response = path_outgoing_response,
}

Definition at line 182 of file res_pjsip_path.c.

Referenced by load_module(), and unload_module().

◆ PATH_SUPPORTED_NAME

pj_str_t PATH_SUPPORTED_NAME = { "path", 4 }
static

Definition at line 37 of file res_pjsip_path.c.

Referenced by add_supported().