Module: sip-router Branch: master Commit: e237f9573435a8a11672b155c1cf9a64638b87d2 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e237f957...
Author: Jason Penton jason.penton@smilecoms.com Committer: Jason Penton jason.penton@smilecoms.com Date: Wed Apr 17 16:40:32 2013 +0200
modules/dialog_ng: API added function to get current dialog from msg
---
modules/dialog_ng/dialog.c | 1 + modules/dialog_ng/dlg_handlers.c | 26 ++++++++++++++++++++++++++ modules/dialog_ng/dlg_handlers.h | 8 +++++++- modules/dialog_ng/dlg_load.h | 4 ++++ 4 files changed, 38 insertions(+), 1 deletions(-)
diff --git a/modules/dialog_ng/dialog.c b/modules/dialog_ng/dialog.c index 748515d..4042cbf 100644 --- a/modules/dialog_ng/dialog.c +++ b/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; } diff --git a/modules/dialog_ng/dlg_handlers.c b/modules/dialog_ng/dlg_handlers.c index 7536725..7f89bda 100644 --- a/modules/dialog_ng/dlg_handlers.c +++ b/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; +} + + diff --git a/modules/dialog_ng/dlg_handlers.h b/modules/dialog_ng/dlg_handlers.h index 210ed8f..e4d3999 100644 --- a/modules/dialog_ng/dlg_handlers.h +++ b/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 diff --git a/modules/dialog_ng/dlg_load.h b/modules/dialog_ng/dlg_load.h index 80e97d6..dc8407e 100644 --- a/modules/dialog_ng/dlg_load.h +++ b/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; };