Module: sip-router
Branch: master
Commit: 80d27be832ff175e31257c612f5b51ce643d4437
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=80d27be…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Sun May 3 23:25:05 2009 +0200
a bunch of small refactorings in the dialog module
- move populate_leg_info declaration to the proper header file
- unify mostly identical dlg_seq_up_onreply, dlg_seq_down_onreply functions
- make unref_new_dialog static, this is not used outside the implementation file
- compact variable declarations in dlg_onroute and a few other functions
- the get_dlg_tl_payload macro is only used once, integrate it into the code
---
modules_k/dialog/dlg_handlers.c | 71 +++++++++++++++---------------------
modules_k/dialog/dlg_handlers.h | 15 ++++++++
modules_k/dialog/dlg_req_within.h | 3 --
modules_k/dialog/dlg_transfer.c | 1 +
4 files changed, 46 insertions(+), 44 deletions(-)
diff --git a/modules_k/dialog/dlg_handlers.c b/modules_k/dialog/dlg_handlers.c
index 6b3bc3d..2b3d53d 100644
--- a/modules_k/dialog/dlg_handlers.c
+++ b/modules_k/dialog/dlg_handlers.c
@@ -293,10 +293,7 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params
*param)
{
struct sip_msg *rpl;
struct dlg_cell *dlg;
- int new_state;
- int old_state;
- int unref;
- int event;
+ int new_state, old_state, unref, event;
str tag;
dlg = (struct dlg_cell *)(*param->param);
@@ -403,12 +400,16 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params
*param)
/*!
- * \brief Run dialog callbacks on forwarded requests in upstream direction
+ * \brief Helper function that run dialog callbacks on forwarded requests
+ * \see dlg_seq_up_onreply
+ * \see dlg_seq_down_onreply
* \param t transaction, unused
* \param type type of the callback, should be TMCB_RESPONSE_FWDED
* \param param saved dialog structure inside the callback
+ * \param direction direction of the request
*/
-static void dlg_seq_up_onreply(struct cell* t, int type, struct tmcb_params *param)
+static void dlg_seq_onreply_helper(struct cell* t, int type,
+ struct tmcb_params *param, const int direction)
{
struct dlg_cell *dlg;
@@ -418,7 +419,7 @@ static void dlg_seq_up_onreply(struct cell* t, int type, struct
tmcb_params *par
if (type==TMCB_RESPONSE_FWDED) {
run_dlg_callbacks(DLGCB_RESPONSE_WITHIN, dlg, param->rpl,
- DLG_DIR_UPSTREAM, 0);
+ direction, 0);
return;
}
@@ -427,26 +428,28 @@ static void dlg_seq_up_onreply(struct cell* t, int type, struct
tmcb_params *par
/*!
- * \brief Run dialog callbacks on forwarded requests in downstream direction
+ * \brief Run dialog callbacks on forwarded requests in upstream direction
+ * \see dlg_seq_onreply_helper
* \param t transaction, unused
* \param type type of the callback, should be TMCB_RESPONSE_FWDED
* \param param saved dialog structure inside the callback
*/
-static void dlg_seq_down_onreply(struct cell* t, int type, struct tmcb_params *param)
+static void dlg_seq_up_onreply(struct cell* t, int type, struct tmcb_params *param)
{
- struct dlg_cell *dlg;
-
- dlg = (struct dlg_cell *)(*param->param);
- if (shutdown_done || dlg==0)
- return;
+ return dlg_seq_onreply_helper(t, type, param, DLG_DIR_UPSTREAM);
+}
- if (type==TMCB_RESPONSE_FWDED) {
- run_dlg_callbacks(DLGCB_RESPONSE_WITHIN, dlg, param->rpl,
- DLG_DIR_DOWNSTREAM, 0);
- return;
- }
- return;
+/*!
+ * \brief Run dialog callbacks on forwarded requests in downstream direction
+ * \see dlg_seq_onreply_helper
+ * \param t transaction, unused
+ * \param type type of the callback, should be TMCB_RESPONSE_FWDED
+ * \param param saved dialog structure inside the callback
+ */
+static void dlg_seq_down_onreply(struct cell* t, int type, struct tmcb_params *param)
+{
+ return dlg_seq_onreply_helper(t, type, param, DLG_DIR_DOWNSTREAM);
}
@@ -492,7 +495,7 @@ void dlg_onreq(struct cell* t, int type, struct tmcb_params *param)
* \see dlg_onreq
* \param dialog unreferenced dialog
*/
-void unref_new_dialog(void *dialog)
+static void unref_new_dialog(void *dialog)
{
struct tmcb_params p;
@@ -755,17 +758,8 @@ static void unreference_dialog(void *dialog)
void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
{
struct dlg_cell *dlg;
- str val;
- str callid;
- str ftag;
- str ttag;
- int h_entry;
- int h_id;
- int new_state;
- int old_state;
- int unref;
- int event;
- int timeout;
+ str val, callid, ftag, ttag;
+ int h_entry, h_id, new_state, old_state, unref, event, timeout;
unsigned int dir;
int ret = 0;
@@ -956,11 +950,6 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void
*param)
}
-
-#define get_dlg_tl_payload(_tl_) ((struct dlg_cell*)((char *)(_tl_)- \
- (unsigned long)(&((struct dlg_cell*)0)->tl)))
-
-
/*!
* \brief Timer function that removes expired dialogs, run timeout route
* \param tl dialog timer list
@@ -968,12 +957,12 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void
*param)
void dlg_ontimeout( struct dlg_tl *tl)
{
struct dlg_cell *dlg;
- int new_state;
- int old_state;
- int unref;
+ int new_state, old_state, unref;
struct sip_msg *fmsg;
- dlg = get_dlg_tl_payload(tl);
+ /* get the dialog tl payload */
+ dlg = ((struct dlg_cell*)((char *)(tl) -
+ (unsigned long)(&((struct dlg_cell*)0)->tl)));
if(dlg->toroute>0 && dlg->toroute<RT_NO)
{
diff --git a/modules_k/dialog/dlg_handlers.h b/modules_k/dialog/dlg_handlers.h
index e0804ba..277db0b 100644
--- a/modules_k/dialog/dlg_handlers.h
+++ b/modules_k/dialog/dlg_handlers.h
@@ -71,6 +71,21 @@ void destroy_dlg_handlers(void);
/*!
+ * \brief Parse SIP message and populate leg informations
+ *
+ * Parse SIP message and populate leg informations.
+ * \param dlg the dialog to add cseq, contact & record_route
+ * \param msg sip message
+ * \param flag 0-for a request(INVITE), 1- for a reply(200 ok)
+ * \return 0 on success, -1 on failure
+ * \note for a request: get record route in normal order, for a reply get
+ * in reverse order, skipping the ones from the request and the proxies' own
+ */
+int populate_leg_info( struct dlg_cell *dlg, struct sip_msg *msg,
+ struct cell* t, unsigned int leg, str *tag);
+
+
+/*!
* \brief Function that is registered as TM callback and called on requests
* \param t transaction, used to created the dialog
* \param type type of the entered callback
diff --git a/modules_k/dialog/dlg_req_within.h b/modules_k/dialog/dlg_req_within.h
index df7d334..732f430 100644
--- a/modules_k/dialog/dlg_req_within.h
+++ b/modules_k/dialog/dlg_req_within.h
@@ -49,9 +49,6 @@ struct mi_root * mi_terminate_dlg(struct mi_root *cmd_tree, void *param
);
dlg_t* build_dlg_t(struct dlg_cell * cell, int dir);
int free_tm_dlg(dlg_t *td);
-int populate_leg_info( struct dlg_cell *dlg, struct sip_msg *msg,
- struct cell* t, unsigned int leg, str *tag);
-
int dlg_bye(struct dlg_cell *dlg, str *hdrs, int side);
int dlg_bye_all(struct dlg_cell *dlg, str *hdrs);
diff --git a/modules_k/dialog/dlg_transfer.c b/modules_k/dialog/dlg_transfer.c
index 2348590..df6f5d1 100644
--- a/modules_k/dialog/dlg_transfer.c
+++ b/modules_k/dialog/dlg_transfer.c
@@ -34,6 +34,7 @@
#include "../../modules/tm/tm_load.h"
#include "dlg_req_within.h"
+#include "dlg_handlers.h"
#include "dlg_transfer.h"
#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"