65 && !strchr(
"-.!%*_+`'~", *str)) {
122 pjsip_supported_hdr *hdr;
125 hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_SUPPORTED,
NULL);
128 hdr = pjsip_supported_hdr_create(tdata->pool);
133 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
139 for (i = 0; i < hdr->count; ++i) {
145 if (hdr->count >= PJSIP_GENERIC_ARRAY_MAX_COUNT) {
192 static const pj_str_t from_name = {
"From", 4 };
194 pjsip_generic_string_hdr *hdr;
198 if (!(hdr = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &
diversion_name,
NULL))) {
202 pj_strdup_with_null(rdata->tp_info.pool, &value, &hdr->hvalue);
205 return pjsip_parse_hdr(rdata->tp_info.pool, &from_name, value.ptr,
206 pj_strlen(&value), &size);
217 static const pj_str_t from_name = {
"From", 4 };
218 pjsip_fromto_hdr * result_hdr =
NULL;
220 pjsip_generic_string_hdr *hdr =
NULL;
229 static const pj_str_t index_name = {
"index", 5 };
232 pjsip_fromto_hdr * fromto_hdr =
NULL;
233 pjsip_param * index =
NULL;
235 pj_strdup_with_null(rdata->tp_info.pool, &value, &hdr->hvalue);
238 fromto_hdr = pjsip_parse_hdr(rdata->tp_info.pool, &from_name, value.ptr,
239 pj_strlen(&value), &size);
241 if (fromto_hdr ==
NULL) {
245 index = pjsip_param_find(&fromto_hdr->other_param, &index_name);
248 if (!pj_strcmp2(&index->value,
"1")) {
257 result_hdr = fromto_hdr;
259 }
while ((hdr = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &
history_info_name, hdr->next)));
276 pjsip_sip_uri *uri = pjsip_uri_get_uri(name_addr->uri);
280 uri_user = uri->user;
283 semi = pj_strchr(&uri_user,
';');
296 pj_strset(&uri_user, (
char *) pj_strbuf(&uri_user), semi - pj_strbuf(&uri_user));
299 if (pj_strlen(&uri_user)) {
305 if (pj_strlen(&name_addr->display)) {
329 static const pj_str_t cause_name = {
"cause", 5 };
330 pjsip_sip_uri *uri = pjsip_uri_get_uri(name_addr);
332 unsigned long cause_value = 0;
334 if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri)) {
338 cause = pjsip_param_find(&uri->other_param, &cause_name);
344 cause_value = pj_strtoul(&cause->value);
354 static const pj_str_t reason_name = {
"reason", 6 };
355 pjsip_param *reason = pjsip_param_find(&from_info->other_param, &reason_name);
373 if (*reason_str ==
'"') {
378 if (data->
code < 0) {
387 pjsip_fromto_hdr *from_info,
388 pjsip_name_addr *to_info)
398 memset(&update, 0,
sizeof(update));
421 if (session->
inv_session->role == PJSIP_ROLE_UAC) {
433 PJSIP_MSG_TO_HDR(rdata->msg_info.msg)->uri);
435 pjsip_fromto_hdr *history_info_to;
436 pjsip_fromto_hdr *history_info_from;
439 if (history_info_to) {
443 set_redirecting(session, history_info_from, (pjsip_name_addr*)history_info_to->uri);
452 static const pj_str_t contact_name = {
"Contact", 7 };
453 static const pj_str_t contact_name_s = {
"m", 1 };
455 pjsip_status_line
status = rdata->msg_info.msg->line.status;
456 pjsip_fromto_hdr *div_hdr;
457 pjsip_fromto_hdr *history_info_to;
458 pjsip_fromto_hdr *history_info_from;
459 pjsip_contact_hdr *contact_hdr;
461 if ((status.code != 302) && (status.code != 181)) {
471 if (history_info_to) {
475 set_redirecting(session, history_info_from, (pjsip_name_addr*)history_info_to->uri);
479 div_hdr = PJSIP_MSG_TO_HDR(rdata->msg_info.msg);
484 if (status.code == 302) {
486 contact_hdr = pjsip_msg_find_hdr_by_names(rdata->msg_info.msg, &contact_name, &contact_name_s,
NULL);
488 set_redirecting(session, div_hdr, contact_hdr ? (pjsip_name_addr*)contact_hdr->uri :
489 (pjsip_name_addr*)PJSIP_MSG_FROM_HDR(rdata->msg_info.msg)->uri);
493 div_hdr ? (pjsip_name_addr*)div_hdr->uri :
NULL);
506 static const pj_str_t reason_name = {
"reason", 6 };
508 pjsip_fromto_hdr *hdr;
509 pjsip_name_addr *name_addr;
512 pjsip_fromto_hdr *old_hdr;
513 const char *reason_str;
514 const char *quote_str;
519 if (tdata->msg->type == PJSIP_REQUEST_MSG) {
526 base = PJSIP_MSG_FROM_HDR(tdata->msg)->uri;
532 hdr = pjsip_from_hdr_create(tdata->pool);
533 hdr->type = PJSIP_H_OTHER;
536 name_addr = pjsip_uri_clone(tdata->pool, base);
537 uri = pjsip_uri_get_uri(name_addr->uri);
539 pj_strdup2(tdata->pool, &name_addr->display, id->
name.
str);
540 pj_strdup2(tdata->pool, &uri->user, id->
number.
str);
542 param = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);
543 param->name = reason_name;
548 quote_str = *reason_str ==
'\"' ||
sip_is_token(reason_str) ?
"" :
"\"";
550 reason_buf = pj_pool_alloc(tdata->pool, strlen(reason_str) + 3);
551 sprintf(reason_buf,
"%s%s%s", quote_str, reason_str, quote_str);
553 param->value = pj_str(reason_buf);
555 pj_list_insert_before(&hdr->other_param, param);
557 hdr->uri = (pjsip_uri *) name_addr;
560 pj_list_erase(old_hdr);
562 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
574 static const pj_str_t index_name = {
"index", 5 };
575 static const pj_str_t cause_name = {
"cause", 5 };
576 static const pj_str_t first_index = {
"1", 1 };
577 static const pj_str_t last_index = {
"1.1", 3 };
579 pjsip_fromto_hdr *hdr;
580 pjsip_name_addr *name_addr;
583 pjsip_fromto_hdr *old_hdr;
590 pjsip_uri *base = PJSIP_MSG_TO_HDR(tdata->msg)->uri;
593 hdr = pjsip_from_hdr_create(tdata->pool);
594 hdr->type = PJSIP_H_OTHER;
597 name_addr = pjsip_uri_clone(tdata->pool, base);
598 uri = pjsip_uri_get_uri(name_addr->uri);
602 pj_strdup2(tdata->pool, &name_addr->display, from->
name.
str);
603 pj_strdup2(tdata->pool, &uri->user, from->
number.
str);
606 param = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);
607 param->name = index_name;
608 param->value = first_index;
611 pj_list_insert_before(&hdr->other_param, param);
612 hdr->uri = (pjsip_uri *) name_addr;
615 pj_list_erase(old_hdr);
618 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
624 hdr = pjsip_from_hdr_create(tdata->pool);
625 hdr->type = PJSIP_H_OTHER;
628 name_addr = pjsip_uri_clone(tdata->pool, base);
629 uri = pjsip_uri_get_uri(name_addr->uri);
631 pj_strdup2(tdata->pool, &name_addr->display, to->
name.
str);
632 pj_strdup2(tdata->pool, &uri->user, to->
number.
str);
634 param = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);
635 param->name = index_name;
636 param->value = last_index;
637 pj_list_insert_before(&hdr->other_param, param);
639 param = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);
640 param->name = cause_name;
642 cause_buf = pj_pool_alloc(tdata->pool, 4);
643 snprintf(cause_buf, 4,
"%ud", cause);
644 param->value = pj_str(cause_buf);
645 pj_list_insert_before(&uri->other_param, param);
646 hdr->uri = (pjsip_uri *) name_addr;
648 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
689 struct pjsip_status_line status = tdata->msg->line.status;
692 if (PJSIP_IS_STATUS_IN_CLASS(status.code, 300) || (status.code == 181)) {
729 .requires =
"res_pjsip,res_pjsip_session",
static void copy_redirecting_id(struct ast_party_id *dst, const struct ast_party_id *src, struct ast_set_party_id *update)
Information needed to identify an endpoint in a call.
struct ast_sip_endpoint * endpoint
char * str
Subscriber phone number (Malloced)
static const char * reason_code_to_str(const struct ast_party_redirecting_reason *reason)
unsigned int send_history_info
Asterisk main include file. File version handling, generic pbx functions.
static const unsigned int reason_code_to_cause(const struct ast_party_redirecting_reason *reason)
static void add_history_info_header(pjsip_tx_data *tdata, struct ast_party_redirecting *data)
static int sip_is_token(const char *str)
String manipulation functions.
static void diversion_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
static void set_redirecting_reason_by_cause(pjsip_name_addr *name_addr, struct ast_party_redirecting_reason *data)
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
struct ast_party_name name
Subscriber name.
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
static int unload_module(void)
int ast_redirecting_reason_parse(const char *data)
Convert redirecting reason text code to value (used in config file parsing)
void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src)
Copy the source party id information to the destination party id.
static pj_str_t HISTINFO_SUPPORTED_NAME
struct ast_set_party_id priv_orig
char * str
Subscriber name (Malloced)
static void add_diversion_header(pjsip_tx_data *tdata, struct ast_party_redirecting *data)
static const struct reasons reason_table[]
#define ast_strdup(str)
A wrapper for strdup()
void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
Copy a pj_str_t into a standard character buffer.
void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
Unregister a an supplement to SIP session processing.
static pjsip_fromto_hdr * get_history_info_header(pjsip_rx_data *rdata, const unsigned int first)
static int add_supported(pjsip_tx_data *tdata)
struct pjsip_inv_session * inv_session
static int diversion_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
int code
enum AST_REDIRECTING_REASON value for redirection
A structure describing a SIP session.
static void set_redirecting_value(char **dst, const pj_str_t *src)
#define ast_strlen_zero(foo)
static void set_redirecting(struct ast_sip_session *session, pjsip_fromto_hdr *from_info, pjsip_name_addr *to_info)
struct ast_set_party_id from
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
static const pj_str_t history_info_name
Diversion header reasons.
General Asterisk PBX channel definitions.
static struct ast_mansession session
#define ast_strdupa(s)
duplicate a string in memory from the stack
struct ast_channel * channel
void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Set the redirecting id information in the Asterisk channel.
#define ast_malloc(len)
A wrapper for malloc()
enum AST_REDIRECTING_REASON code
AST_REDIRECTING_REASON
redirecting reason codes.
static void diversion_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata)
struct ast_sip_endpoint_id_configuration id
Redirecting reason information.
Indicate what information in ast_party_id should be set.
struct ast_set_party_id priv_from
#define ast_module_shutdown_ref(mod)
Prevent unload of the module before shutdown.
struct sla_ringing_trunk * first
Redirecting Line information. RDNIS (Redirecting Directory Number Information Service) Where a call d...
static void set_redirecting_reason(pjsip_fromto_hdr *from_info, pjsip_name_addr *to_info, struct ast_party_redirecting_reason *data)
char * str
a string value for the redirecting reason
static void get_redirecting_add_diversion(struct ast_sip_session *session, pjsip_tx_data *tdata)
static enum AST_REDIRECTING_REASON cause_to_reason(const unsigned long cause)
struct ast_party_redirecting_reason reason
Reason for the redirection.
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
A supplement to SIP message processing.
static struct ast_sip_session_supplement diversion_supplement
void ast_party_redirecting_free(struct ast_party_redirecting *doomed)
Destroy the redirecting information contents.
struct ast_set_party_id to
Indicate what information in ast_party_redirecting should be set.
int count
Number of times the call was redirected.
static void diversion_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata)
struct ast_party_id to
Call is redirecting to a new party (Sent to the caller)
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
static void set_redirecting_id(pjsip_name_addr *name_addr, struct ast_party_id *data, struct ast_set_party_id *update)
struct ast_set_party_id priv_to
static pjsip_fromto_hdr * get_diversion_header(pjsip_rx_data *rdata)
void ast_channel_queue_redirecting_update(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Queue a redirecting update frame on a channel.
unsigned char valid
TRUE if the name information is valid/present.
void ast_set_party_id_all(struct ast_set_party_id *update_id)
Set the update marker to update all information of a corresponding party id.
static const pj_str_t diversion_name
static int load_module(void)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
unsigned char valid
TRUE if the number information is valid/present.
#define ast_sip_session_register_supplement(supplement)
struct ast_party_number number
Subscriber phone number.
unsigned int send_diversion