Module: sip-router
Branch: master
Commit: 618712b6ee69ebc41b963754957303d8b1e0aca2
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=618712b6ee69ebc41b963754957303d8b1e0aca2

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date:   Wed Nov 17 12:53:18 2010 +0100

tm: added export structure for extra API

- used for not-so-common inter-module API functions
- initial tm API structure got quite big and not all functions are very
  used

---

 modules/tm/tm.c      |   23 +++++++++++++++++------
 modules/tm/tm_load.c |   19 +++++++++++++++++++
 modules/tm/tm_load.h |   41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 6 deletions(-)

diff --git a/modules/tm/tm.c b/modules/tm/tm.c
index e5ca753..e8ef946 100644
--- a/modules/tm/tm.c
+++ b/modules/tm/tm.c
@@ -292,12 +292,12 @@ static int t_branch_timeout(struct sip_msg* msg, char*, 
char*);
 static int t_branch_replied(struct sip_msg* msg, char*, char*);
 static int t_any_timeout(struct sip_msg* msg, char*, char*);
 static int t_any_replied(struct sip_msg* msg, char*, char*);
-static int t_is_canceled(struct sip_msg* msg, char*, char*);
+static int w_t_is_canceled(struct sip_msg* msg, char*, char*);
 static int t_is_expired(struct sip_msg* msg, char*, char*);
 static int t_grep_status(struct sip_msg* msg, char*, char*);
 static int w_t_drop_replies(struct sip_msg* msg, char* foo, char* bar);
 static int w_t_save_lumps(struct sip_msg* msg, char* foo, char* bar);
-static int t_check_trans(struct sip_msg* msg, char* foo, char* bar);
+static int w_t_check_trans(struct sip_msg* msg, char* foo, char* bar);
 
 
 /* by default the fr timers avps are not set, so that the avps won't be
@@ -448,7 +448,7 @@ static cmd_export_t cmds[]={
                        
REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
        {"t_any_replied",     t_any_replied,            0, 0, 
                        
REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
-       {"t_is_canceled",     t_is_canceled,            0, 0,
+       {"t_is_canceled",     w_t_is_canceled,          0, 0,
                        
REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
        {"t_is_expired",      t_is_expired,             0, 0,
                        
REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
@@ -460,7 +460,7 @@ static cmd_export_t cmds[]={
                        FAILURE_ROUTE},
        {"t_save_lumps",      w_t_save_lumps,           0, 0,
                        REQUEST_ROUTE},
-       {"t_check_trans",       t_check_trans,                          0, 0,
+       {"t_check_trans",         w_t_check_trans,                      0, 0,
                        REQUEST_ROUTE|TM_ONREPLY_ROUTE|BRANCH_ROUTE },
 
        {"t_load_contacts", t_load_contacts,            0, 0,
@@ -470,6 +470,7 @@ static cmd_export_t cmds[]={
 
        /* not applicable from the script */
        {"load_tm",            (cmd_function)load_tm,           NO_SCRIPT,   0, 
0},
+       {"load_xtm",           (cmd_function)load_xtm,          NO_SCRIPT,   0, 
0},
        {0,0,0,0,0}
 };
 
@@ -1755,7 +1756,7 @@ int t_branch_replied(struct sip_msg* msg, char* foo, 
char* bar)
 
 
 /* script function, returns: 1 if the transaction was canceled, -1 if not */
-int t_is_canceled(struct sip_msg* msg, char* foo, char* bar)
+int t_is_canceled(struct sip_msg* msg)
 {
        struct cell *t;
        int ret;
@@ -1773,6 +1774,11 @@ int t_is_canceled(struct sip_msg* msg, char* foo, char* 
bar)
        return ret;
 }
 
+static int w_t_is_canceled(struct sip_msg* msg, char* foo, char* bar)
+{
+       return t_is_canceled(msg);
+}
+
 /* script function, returns: 1 if the transaction lifetime interval has 
already elapsed, -1 if not */
 int t_is_expired(struct sip_msg* msg, char* foo, char* bar)
 {
@@ -1937,7 +1943,7 @@ int w_t_reply_wrp(struct sip_msg *m, unsigned int code, 
char *txt)
  *       reliable: if the ACK  is delayed the proxied transaction might
  *       be already deleted when it reaches the proxy (wait_timeout))
  */
-static int t_check_trans(struct sip_msg* msg, char* foo, char* bar)
+int t_check_trans(struct sip_msg* msg)
 {
        struct cell* t;
        
@@ -1976,6 +1982,11 @@ static int t_check_trans(struct sip_msg* msg, char* foo, 
char* bar)
        return -1;
 }
 
+static int w_t_check_trans(struct sip_msg* msg, char* foo, char* bar)
+{
+       return t_check_trans(msg);
+}
+
 static int hexatoi(str *s, unsigned int* result)
 {
        int i, xv, fact;
diff --git a/modules/tm/tm_load.c b/modules/tm/tm_load.c
index 58fd440..d57fd45 100644
--- a/modules/tm/tm_load.c
+++ b/modules/tm/tm_load.c
@@ -145,3 +145,22 @@ int load_tm( struct tm_binds *tmb)
 #endif
        return 1;
 }
+
+int load_xtm(tm_xapi_t *xapi)
+{
+       if(xapi==NULL)
+       {
+               LM_ERR("invalid parameter\n");
+               return -1;
+       }
+
+       memset(xapi, 0, sizeof(tm_xapi_t));
+
+       xapi->t_on_failure    = t_on_negative;
+       xapi->t_on_branch     = t_on_branch;
+       xapi->t_on_reply      = t_on_reply;
+       xapi->t_check_trans   = t_check_trans;
+       xapi->t_is_canceled   = t_is_canceled;
+
+       return 0;
+}
diff --git a/modules/tm/tm_load.h b/modules/tm/tm_load.h
index e4829ac..aad979b 100644
--- a/modules/tm/tm_load.h
+++ b/modules/tm/tm_load.h
@@ -163,4 +163,45 @@ static inline int tm_load_api(tm_api_t *tmb)
        return load_tm_api(tmb);
 }
 
+/**
+ * eXtra API - not common used in other modules
+ */
+
+typedef void (*t_on_route_f)(unsigned int);
+typedef int (*t_no_param_f)(struct sip_msg *);
+
+int t_check_trans(struct sip_msg* msg);
+int t_is_canceled(struct sip_msg* msg);
+
+typedef struct tm_xbinds {
+       t_on_route_f t_on_failure;
+       t_on_route_f t_on_branch;
+       t_on_route_f t_on_reply;
+       t_no_param_f t_check_trans;
+       t_no_param_f t_is_canceled;
+} tm_xapi_t;
+
+typedef int(*load_xtm_f)( tm_xapi_t *xtmb );
+int load_xtm(tm_xapi_t *xtmb);
+
+static inline int tm_load_xapi(tm_xapi_t *xtmb)
+{
+       load_xtm_f load_xtm;
+
+       /* import the TM auto-loading function */
+       load_xtm = (load_xtm_f)find_export("load_xtm", NO_SCRIPT, 0);
+
+       if (load_tm == NULL) {
+               LOG(L_WARN, "Cannot import load_xtm function from tm module\n");
+               return -1;
+       }
+
+       /* let the auto-loading function load all extra TM stuff */
+       if (load_xtm(xtmb) < 0) {
+               LOG(L_WARN, "Cannot bind xapi from tm module\n");
+               return -1;
+       }
+       return 0;
+}
+
 #endif


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to