diff options
author | Mark Michelson <mmichelson@digium.com> | 2013-09-13 14:50:38 +0000 |
---|---|---|
committer | Mark Michelson <mmichelson@digium.com> | 2013-09-13 14:50:38 +0000 |
commit | 9deb416397ff8df1fe9a4bd13da88c7bb6002db8 (patch) | |
tree | 824adb6ec4b6dd579710df20c0acd61b7e2fe8bf /res | |
parent | bbf5fbbd8c6aa4ec2e8b48da1926b24a32632ca5 (diff) |
Create more accurate Contact headers for dialogs when we are the UAS.
(closes issue AST-1207)
reported by John Bigelow
Review: https://reviewboard.asterisk.org/r/2842
........
Merged revisions 399083 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@399084 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r-- | res/res_pjsip.c | 34 | ||||
-rw-r--r-- | res/res_pjsip.exports.in | 3 | ||||
-rw-r--r-- | res/res_pjsip_pubsub.c | 4 | ||||
-rw-r--r-- | res/res_pjsip_session.c | 5 |
4 files changed, 40 insertions, 6 deletions
diff --git a/res/res_pjsip.c b/res/res_pjsip.c index 2af6a331b..d579d0cbd 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -1324,7 +1324,7 @@ static int sip_get_tpselector_from_uri(const char *uri, pjsip_tpselector *select return 0; } -pjsip_dialog *ast_sip_create_dialog(const struct ast_sip_endpoint *endpoint, const char *uri, const char *request_user) +pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, const char *uri, const char *request_user) { pj_str_t local_uri = { "sip:temp@temp", 13 }, remote_uri; pjsip_dialog *dlg = NULL; @@ -1386,6 +1386,38 @@ pjsip_dialog *ast_sip_create_dialog(const struct ast_sip_endpoint *endpoint, con return dlg; } +pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata) +{ + pjsip_dialog *dlg; + pj_str_t contact; + pjsip_transport_type_e type = rdata->tp_info.transport->key.type; + pj_status_t status; + + contact.ptr = pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE); + contact.slen = pj_ansi_snprintf(contact.ptr, PJSIP_MAX_URL_SIZE, + "<%s:%s%.*s%s:%d%s%s>", + (pjsip_transport_get_flag_from_type(type) & PJSIP_TRANSPORT_SECURE) ? "sips" : "sip", + (type & PJSIP_TRANSPORT_IPV6) ? "[" : "", + (int)rdata->tp_info.transport->local_name.host.slen, + rdata->tp_info.transport->local_name.host.ptr, + (type & PJSIP_TRANSPORT_IPV6) ? "]" : "", + rdata->tp_info.transport->local_name.port, + (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? ";transport=" : "", + (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? pjsip_transport_get_type_name(type) : ""); + + status = pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, &contact, &dlg); + if (status != PJ_SUCCESS) { + char err[PJ_ERR_MSG_SIZE]; + + pjsip_strerror(status, err, sizeof(err)); + ast_log(LOG_ERROR, "Could not create dialog with endpoint %s. %s\n", + ast_sorcery_object_get_id(endpoint), err); + return NULL; + } + + return dlg; +} + /* PJSIP doesn't know about the INFO method, so we have to define it ourselves */ static const pjsip_method info_method = {PJSIP_OTHER_METHOD, {"INFO", 4} }; static const pjsip_method message_method = {PJSIP_OTHER_METHOD, {"MESSAGE", 7} }; diff --git a/res/res_pjsip.exports.in b/res/res_pjsip.exports.in index f3b4f0eec..a4b23bc7e 100644 --- a/res/res_pjsip.exports.in +++ b/res/res_pjsip.exports.in @@ -32,7 +32,8 @@ LINKER_SYMBOL_PREFIXast_sip_get_endpoints; LINKER_SYMBOL_PREFIXast_copy_pj_str; LINKER_SYMBOL_PREFIXast_sip_get_sorcery; - LINKER_SYMBOL_PREFIXast_sip_create_dialog; + LINKER_SYMBOL_PREFIXast_sip_create_dialog_uac; + LINKER_SYMBOL_PREFIXast_sip_create_dialog_uas; LINKER_SYMBOL_PREFIXast_sip_location_retrieve_aor; LINKER_SYMBOL_PREFIXast_sip_location_retrieve_first_aor_contact; LINKER_SYMBOL_PREFIXast_sip_location_retrieve_contact_from_aor_list; diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c index ecc005996..4daacd42c 100644 --- a/res/res_pjsip_pubsub.c +++ b/res/res_pjsip_pubsub.c @@ -282,7 +282,7 @@ struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_su } sub->role = role; if (role == AST_SIP_NOTIFIER) { - pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dlg); + dlg = ast_sip_create_dialog_uas(endpoint, rdata); } else { RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup); @@ -293,7 +293,7 @@ struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_su ao2_ref(sub, -1); return NULL; } - dlg = ast_sip_create_dialog(endpoint, contact->uri, NULL); + dlg = ast_sip_create_dialog_uac(endpoint, contact->uri, NULL); } if (!dlg) { ast_log(LOG_WARNING, "Unable to create dialog for SIP subscription\n"); diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index 226e43f3e..c6c395361 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -1185,7 +1185,7 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint return NULL; } - if (!(dlg = ast_sip_create_dialog(endpoint, uri, request_user))) { + if (!(dlg = ast_sip_create_dialog_uac(endpoint, uri, request_user))) { return NULL; } @@ -1337,7 +1337,8 @@ static pjsip_inv_session *pre_session_setup(pjsip_rx_data *rdata, const struct a } return NULL; } - if (pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dlg) != PJ_SUCCESS) { + dlg = ast_sip_create_dialog_uas(endpoint, rdata); + if (!dlg) { pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL); return NULL; } |