2
0
Эх сурвалжийг харах

dialog: option to add custom headers for local requests to callee

- new parameter: lreq_callee_headers
- make topoh to handle properly dialog local requests (e.g., bye):
  lreq_callee_headers set to: 'TH: dlh\r\n'
- reported by Alex Balashov
Daniel-Constantin Mierla 10 жил өмнө
parent
commit
d8c92fd3dc

+ 3 - 0
modules/dialog/dialog.c

@@ -147,6 +147,8 @@ int dlg_ka_timer = 0;
 int dlg_ka_interval = 0;
 int dlg_clean_timer = 90;
 
+str dlg_lreq_callee_headers = {0};
+
 /* db stuff */
 static str db_url = str_init(DEFAULT_DB_URL);
 static unsigned int db_update_period = DB_DEFAULT_UPDATE_PERIOD;
@@ -297,6 +299,7 @@ static param_export_t mod_params[]={
 	{ "timeout_noreset",       INT_PARAM, &dlg_timeout_noreset      },
 	{ "timer_procs",           PARAM_INT, &dlg_timer_procs          },
 	{ "track_cseq_updates",    PARAM_INT, &_dlg_track_cseq_updates  },
+	{ "lreq_callee_headers",   PARAM_STR, &dlg_lreq_callee_headers  },
 	{ 0,0,0 }
 };
 

+ 2 - 2
modules/dialog/dlg_hash.c

@@ -201,9 +201,9 @@ int dlg_ka_run(ticks_t ti)
 			dka = NULL;
 		} else {
 			if(dka->iflags & DLG_IFLAG_KA_SRC)
-				dlg_send_ka(dlg, DLG_CALLER_LEG, 0);
+				dlg_send_ka(dlg, DLG_CALLER_LEG);
 			if(dka->iflags & DLG_IFLAG_KA_DST)
-				dlg_send_ka(dlg, DLG_CALLEE_LEG, 0);
+				dlg_send_ka(dlg, DLG_CALLEE_LEG);
 			dlg_release(dlg);
 		}
 		/* append to tail */

+ 31 - 5
modules/dialog/dlg_req_within.c

@@ -50,7 +50,7 @@
 #define MAX_FWD_HDR_LEN    (sizeof(MAX_FWD_HDR) - 1)
 
 extern str dlg_extra_hdrs;
-
+extern str dlg_lreq_callee_headers;
 
 
 int free_tm_dlg(dlg_t *td)
@@ -280,12 +280,19 @@ static inline int build_extra_hdr(struct dlg_cell * cell, str *extra_hdrs,
 		str *str_hdr)
 {
 	char *p;
+	int blen;
 
 	str_hdr->len = MAX_FWD_HDR_LEN + dlg_extra_hdrs.len;
 	if(extra_hdrs && extra_hdrs->len>0)
 		str_hdr->len += extra_hdrs->len;
 
-	str_hdr->s = (char*)pkg_malloc( str_hdr->len * sizeof(char) );
+	blen = str_hdr->len + 1 /* '\0' */;
+
+	/* reserve space for callee headers in local requests */
+	if(dlg_lreq_callee_headers.len>0)
+		blen += dlg_lreq_callee_headers.len + 2 /* '\r\n' */;
+
+	str_hdr->s = (char*)pkg_malloc( blen * sizeof(char) );
 	if(!str_hdr->s){
 		LM_ERR("out of pkg memory\n");
 		goto error;
@@ -320,6 +327,7 @@ static inline int send_bye(struct dlg_cell * cell, int dir, str *hdrs)
 	str met = {"BYE", 3};
 	int result;
 	dlg_iuid_t *iuid = NULL;
+	str lhdrs;
 
 	/* do not send BYE request for non-confirmed dialogs (not supported) */
 	if (cell->state != DLG_STATE_CONFIRMED_NA && cell->state != DLG_STATE_CONFIRMED) {
@@ -343,7 +351,20 @@ static inline int send_bye(struct dlg_cell * cell, int dir, str *hdrs)
 		goto err;
 	}
 
-	set_uac_req(&uac_r, &met, hdrs, NULL, dialog_info, TMCB_LOCAL_COMPLETED,
+	lhdrs = *hdrs;
+
+	if(dir==DLG_CALLEE_LEG && dlg_lreq_callee_headers.len>0) {
+		/* space allocated in hdrs->s by build_extra_hdrs() */
+		memcpy(lhdrs.s+lhdrs.len, dlg_lreq_callee_headers.s,
+				dlg_lreq_callee_headers.len);
+		lhdrs.len += dlg_lreq_callee_headers.len;
+		if(dlg_lreq_callee_headers.s[dlg_lreq_callee_headers.len-1]!='\n') {
+			strncpy(lhdrs.s+lhdrs.len, CRLF, CRLF_LEN);
+			lhdrs.len += CRLF_LEN;
+		}
+	}
+
+	set_uac_req(&uac_r, &met, &lhdrs, NULL, dialog_info, TMCB_LOCAL_COMPLETED,
 				bye_reply_cb, (void*)iuid);
 	result = d_tmb.t_request_within(&uac_r);
 
@@ -370,7 +391,7 @@ err:
  * 		DLG_CALLER_LEG (0): caller
  * 		DLG_CALLEE_LEG (1): callee
  */
-int dlg_send_ka(dlg_cell_t *dlg, int dir, str *hdrs)
+int dlg_send_ka(dlg_cell_t *dlg, int dir)
 {
 	uac_req_t uac_r;
 	dlg_t* di;
@@ -406,8 +427,13 @@ int dlg_send_ka(dlg_cell_t *dlg, int dir, str *hdrs)
 		goto err;
 	}
 
-	set_uac_req(&uac_r, &met, hdrs, NULL, di, TMCB_LOCAL_COMPLETED,
+	if(dir==DLG_CALLEE_LEG && dlg_lreq_callee_headers.len>0) {
+		set_uac_req(&uac_r, &met, &dlg_lreq_callee_headers, NULL, di,
+				TMCB_LOCAL_COMPLETED, dlg_ka_cb, (void*)iuid);
+	} else {
+		set_uac_req(&uac_r, &met, NULL, NULL, di, TMCB_LOCAL_COMPLETED,
 				dlg_ka_cb, (void*)iuid);
+	}
 	result = d_tmb.t_request_within(&uac_r);
 
 	if(result < 0){

+ 1 - 1
modules/dialog/dlg_req_within.h

@@ -52,6 +52,6 @@ dlg_t* build_dlg_t(struct dlg_cell * cell, int dir);
 int free_tm_dlg(dlg_t *td);
 int dlg_bye(struct dlg_cell *dlg, str *hdrs, int side);
 int dlg_bye_all(struct dlg_cell *dlg, str *hdrs);
-int dlg_send_ka(dlg_cell_t *dlg, int dir, str *hdrs);
+int dlg_send_ka(dlg_cell_t *dlg, int dir);
 
 #endif