Module: sip-router Branch: master Commit: 644902198d7727d8c283109d84de36babf5544ad URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=64490219...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Tue Jan 8 22:34:00 2013 +0100
dialog: add contact header in REFER for dlg_bridge()
- some UAs reject the REFER if there is no contact header
---
modules_k/dialog/dialog.c | 7 ++++++ modules_k/dialog/dlg_transfer.c | 46 ++++++++++++++++++++++++++++++++++---- modules_k/dialog/dlg_transfer.h | 2 + 3 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/modules_k/dialog/dialog.c b/modules_k/dialog/dialog.c index 13fa807..cd7dec6 100644 --- a/modules_k/dialog/dialog.c +++ b/modules_k/dialog/dialog.c @@ -112,6 +112,8 @@ int dlg_event_rt[DLG_EVENTRT_MAX];
str dlg_bridge_controller = {"sip:controller@kamailio.org", 27};
+str dlg_bridge_contact = {"sip:controller@kamailio.org:5060", 32}; + str ruri_pvar_param = {"$ru", 3}; pv_elem_t * ruri_param_model = NULL;
@@ -269,6 +271,7 @@ static param_export_t mod_params[]={ { "profiles_with_value", STR_PARAM, &profiles_wv_s }, { "profiles_no_value", STR_PARAM, &profiles_nv_s }, { "bridge_controller", STR_PARAM, &dlg_bridge_controller.s }, + { "bridge_contact", PARAM_STR, &dlg_bridge_contact }, { "ruri_pvar", STR_PARAM, &ruri_pvar_param.s }, { "initial_cbs_inscript", INT_PARAM, &initial_cbs_inscript }, { "send_bye", INT_PARAM, &dlg_send_bye }, @@ -469,6 +472,9 @@ static int mod_init(void) if(faked_msg_init()<0) return -1;
+ if(dlg_bridge_init_hdrs()<0) + return -1; + if (timeout_spec.s) timeout_spec.len = strlen(timeout_spec.s);
@@ -744,6 +750,7 @@ static void mod_destroy(void) dialog_update_db(0, 0); destroy_dlg_db(); } + dlg_bridge_destroy_hdrs(); /* no DB interaction from now on */ dlg_db_mode = DB_MODE_NONE; destroy_dlg_table(); diff --git a/modules_k/dialog/dlg_transfer.c b/modules_k/dialog/dlg_transfer.c index a0c35cf..25d9e8d 100644 --- a/modules_k/dialog/dlg_transfer.c +++ b/modules_k/dialog/dlg_transfer.c @@ -40,10 +40,47 @@ #define DLG_HOLD_SDP "v=0\r\no=kamailio-bridge 0 0 IN IP4 0.0.0.0\r\ns=kamailio\r\nc=IN IP4 0.0.0.0\r\nt=0 0\r\nm=audio 9 RTP/AVP 8 0\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:0 PCMU/8000\r\n" #define DLG_HOLD_SDP_LEN (sizeof(DLG_HOLD_SDP)-1)
+/* #define DLG_HOLD_CT_HDR "Contact: sip:kamailio.org:5060\r\nContent-Type: application/sdp\r\n" #define DLG_HOLD_CT_HDR_LEN (sizeof(DLG_HOLD_CT_HDR)-1) +*/
extern str dlg_bridge_controller; +extern str dlg_bridge_contact; + +static char *dlg_bridge_hdrs_buf = NULL; +static str dlg_bridge_inv_hdrs = {0}; +static str dlg_bridge_ref_hdrs = {0}; + +int dlg_bridge_init_hdrs(void) +{ + if(dlg_bridge_hdrs_buf!=NULL) + return 0; + dlg_bridge_hdrs_buf = (char*)pkg_malloc((dlg_bridge_contact.len + 46) + * sizeof(char)); + if(dlg_bridge_hdrs_buf==NULL) { + LM_ERR("no more pkg memory\n"); + return -1; + } + strncpy(dlg_bridge_hdrs_buf, + "Contact: <", 10); + strncpy(dlg_bridge_hdrs_buf + 10, + dlg_bridge_contact.s, dlg_bridge_contact.len); + strncpy(dlg_bridge_hdrs_buf + 10 + dlg_bridge_contact.len, + ">\r\nContent-Type: application/sdp\r\n", 34); + dlg_bridge_hdrs_buf[dlg_bridge_contact.len+44] = '\0'; + dlg_bridge_inv_hdrs.s = dlg_bridge_hdrs_buf; + dlg_bridge_inv_hdrs.len = dlg_bridge_contact.len + 44; + dlg_bridge_ref_hdrs.s = dlg_bridge_hdrs_buf; + dlg_bridge_ref_hdrs.len = dlg_bridge_contact.len + 13; + return 0; +} + +void dlg_bridge_destroy_hdrs(void) +{ + if(dlg_bridge_hdrs_buf!=NULL) + pkg_free(dlg_bridge_hdrs_buf); +}
void dlg_transfer_ctx_free(dlg_transfer_ctx_t *dtc) { @@ -145,7 +182,7 @@ static int dlg_refer_callee(dlg_transfer_ctx_t *dtc) }
hdrs.len = 23 + 2*CRLF_LEN + dlg_bridge_controller.len - + dtc->to.len; + + dtc->to.len + dlg_bridge_ref_hdrs.len; LM_DBG("sending REFER [%d] <%.*s>\n", hdrs.len, dtc->to.len, dtc->to.s); hdrs.s = (char*)pkg_malloc(hdrs.len*sizeof(char)); if(hdrs.s == NULL) @@ -158,6 +195,8 @@ static int dlg_refer_callee(dlg_transfer_ctx_t *dtc) dtc->to.len); memcpy(hdrs.s+23+dlg_bridge_controller.len+CRLF_LEN+dtc->to.len, CRLF, CRLF_LEN); + memcpy(hdrs.s+23+dlg_bridge_controller.len+CRLF_LEN+dtc->to.len+CRLF_LEN, + dlg_bridge_controller.s, dlg_bridge_controller.len);
memset(&uac_r, '\0', sizeof(uac_req_t)); set_uac_req(&uac_r, &met, &hdrs, NULL, dialog_info, TMCB_LOCAL_COMPLETED, @@ -278,7 +317,6 @@ int dlg_bridge(str *from, str *to, str *op) int ret; str s_method = {"INVITE", 6}; str s_body; - str s_hdrs; uac_req_t uac_r;
dtc = (dlg_transfer_ctx_t*)shm_malloc(sizeof(dlg_transfer_ctx_t)); @@ -314,12 +352,10 @@ int dlg_bridge(str *from, str *to, str *op) dtc->to.len, dtc->to.s); s_body.s = DLG_HOLD_SDP; s_body.len = DLG_HOLD_SDP_LEN; - s_hdrs.s = DLG_HOLD_CT_HDR; - s_hdrs.len = DLG_HOLD_CT_HDR_LEN;
memset(&uac_r, '\0', sizeof(uac_req_t)); uac_r.method = &s_method; - uac_r.headers = &s_hdrs; + uac_r.headers = &dlg_bridge_inv_hdrs; uac_r.body = &s_body; uac_r.cb_flags = TMCB_LOCAL_COMPLETED; uac_r.cb = dlg_bridge_tm_callback; diff --git a/modules_k/dialog/dlg_transfer.h b/modules_k/dialog/dlg_transfer.h index 3845e7c..ef05eeb 100644 --- a/modules_k/dialog/dlg_transfer.h +++ b/modules_k/dialog/dlg_transfer.h @@ -34,5 +34,7 @@ typedef struct _dlg_transfer_ctx {
int dlg_bridge(str *from, str *to, str *op); int dlg_transfer(struct dlg_cell *dlg, str *to, int side); +int dlg_bridge_init_hdrs(void); +void dlg_bridge_destroy_hdrs(void);
#endif