浏览代码

modules/dialog_ng: API added function to get current dialog from msg

Jason Penton 12 年之前
父节点
当前提交
e237f95734
共有 4 个文件被更改,包括 38 次插入1 次删除
  1. 1 0
      modules/dialog_ng/dialog.c
  2. 26 0
      modules/dialog_ng/dlg_handlers.c
  3. 7 1
      modules/dialog_ng/dlg_handlers.h
  4. 4 0
      modules/dialog_ng/dlg_load.h

+ 1 - 0
modules/dialog_ng/dialog.c

@@ -252,6 +252,7 @@ int load_dlg(struct dlg_binds *dlgb) {
     dlgb->get_dlg_var = api_get_dlg_variable;
     dlgb->terminate_dlg = w_api_terminate_dlg;
     dlgb->get_dlg_expires = api_get_dlg_expires;
+    dlgb->get_dlg = dlg_get_msg_dialog;
 
     return 1;
 }

+ 26 - 0
modules/dialog_ng/dlg_handlers.c

@@ -1423,3 +1423,29 @@ void print_all_dlgs() {
 
 }
 
+struct dlg_cell *dlg_get_msg_dialog(sip_msg_t *msg)
+{
+	struct dlg_cell *dlg = NULL;
+	str callid;
+	str ftag;
+	str ttag;
+	unsigned int dir;
+
+	/* Retrieve the current dialog */
+	dlg = dlg_get_ctx_dialog();
+	if (dlg != NULL )
+		return dlg;
+
+	if (pre_match_parse(msg, &callid, &ftag, &ttag, 0) < 0)
+		return NULL ;
+	dir = DLG_DIR_NONE;
+	dlg = get_dlg(&callid, &ftag, &ttag, &dir);
+	if (dlg == NULL ) {
+		LM_DBG("dlg with callid '%.*s' not found\n",
+				msg->callid->body.len, msg->callid->body.s);
+		return NULL ;
+	}
+	return dlg;
+}
+
+

+ 7 - 1
modules/dialog_ng/dlg_handlers.h

@@ -179,7 +179,13 @@ void print_all_dlgs();
  * \param dlg dialog cell
  * \return void
  */
-
 void internal_print_all_dlg(struct dlg_cell *dlg);
 
+/*!
+ * \get the current dialog based on the current SIP message
+ * \param msg SIP message
+ * \return current dialog, null if none.
+ */
+struct dlg_cell *dlg_get_msg_dialog(sip_msg_t *msg);
+
 #endif

+ 4 - 0
modules/dialog_ng/dlg_load.h

@@ -35,6 +35,9 @@
 /* terminate_dlg function prototype */
 typedef int (*terminate_dlg_f)(str *callid, str *ftag, str *ttag, str *hdrs, str *reason);
 
+/* get the current dialog based on message function prototype */
+typedef struct dlg_cell *(*get_dlg_f)(struct sip_msg *msg);
+
 /* get_dlg_lifetime function prototype */
 typedef time_t (*get_dlg_expires_f)(str *callid, str *ftag, str *ttag);
 
@@ -45,6 +48,7 @@ struct dlg_binds {
 	set_dlg_variable_f 		set_dlg_var;
 	get_dlg_variable_f 		get_dlg_var;
 	get_dlg_expires_f 		get_dlg_expires;
+	get_dlg_f				get_dlg;
 };