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

Author: Peter Dunkley <[email protected]>
Committer: Peter Dunkley <[email protected]>
Date:   Wed May  2 17:55:50 2012 +0100

modules_k/rls: Tidied up the use of (start|end|abort)_transaction

---

 modules_k/rls/notify.c          |   62 +++++++++++++++++++--------------------
 modules_k/rls/resource_notify.c |    3 +-
 modules_k/rls/rls_db.c          |   27 +----------------
 3 files changed, 32 insertions(+), 60 deletions(-)

diff --git a/modules_k/rls/notify.c b/modules_k/rls/notify.c
index 1e06d57..a460fa0 100644
--- a/modules_k/rls/notify.c
+++ b/modules_k/rls/notify.c
@@ -121,6 +121,11 @@ int send_full_notify(subs_t* subs, xmlNodePtr rl_node, 
str* rl_uri,
        result_cols[pres_state_col= n_result_cols++]= &str_presence_state_col;
        result_cols[auth_state_col= n_result_cols++]= &str_auth_state_col;
        result_cols[reason_col= n_result_cols++]= &str_reason_col;
+
+       update_cols[0]= &str_updated_col;
+       update_vals[0].type = DB1_INT;
+       update_vals[0].nul = 0;
+       update_vals[0].val.int_val= NO_UPDATE_TYPE; 
        
        if (rlpres_dbf.use_table(rlpres_db, &rlpres_table) < 0) 
        {
@@ -143,8 +148,30 @@ int send_full_notify(subs_t* subs, xmlNodePtr rl_node, 
str* rl_uri,
                LM_ERR("in sql query\n");
                goto error;
        }
-       if(result== NULL)
+       if(result == NULL)
+       {
+               LM_ERR("bad result\n");
                goto error;
+       }
+
+       if (result->n > 0)
+       {
+               if(rlpres_dbf.update(rlpres_db, query_cols, 0, query_vals,
+                                    update_cols, update_vals, 1, 1) < 0)
+               {
+                       LM_ERR("in sql update\n");
+                       goto error;
+               }
+       }
+
+       if (dbmode == RLS_DB_ONLY && rlpres_dbf.end_transaction)
+       {
+               if (rlpres_dbf.end_transaction(rlpres_db) < 0)
+               {
+                       LM_ERR("in end_transaction\n");
+                       goto error;
+               }
+       }
 
        /* Allocate an initial buffer for the multipart body.
         * This buffer will be reallocated if neccessary */
@@ -238,9 +265,6 @@ int send_full_notify(subs_t* subs, xmlNodePtr rl_node, str* 
rl_uri,
                        &rlmi_cont->len, (rls_max_notify_body_len == 0));
        xmlFreeDoc(rlmi_body);
 
-       rlpres_dbf.free_result(rlpres_db, result);
-       result= NULL;
-
        if(agg_body_sendn_update(rl_uri, boundary_string, rlmi_cont,
                multipart_body, subs, hash_code)< 0)
        {
@@ -248,33 +272,6 @@ int send_full_notify(subs_t* subs, xmlNodePtr rl_node, 
str* rl_uri,
                goto error;
        }
 
-       /* update updated col in rlpres_table*/
-       update_cols[0]= &str_updated_col;
-       update_vals[0].type = DB1_INT;
-       update_vals[0].nul = 0;
-       update_vals[0].val.int_val= NO_UPDATE_TYPE; 
-       
-       if (rlpres_dbf.use_table(rlpres_db, &rlpres_table) < 0) 
-       {
-               LM_ERR("in use_table\n");
-               goto error;
-       }
-       if(rlpres_dbf.update(rlpres_db, query_cols, 0, query_vals, update_cols,
-                                       update_vals, 1, 1)< 0)
-       {
-               LM_ERR("in sql update\n");
-               goto error;
-       }
-
-       if (dbmode == RLS_DB_ONLY && rlpres_dbf.end_transaction)
-       {
-               if (rlpres_dbf.end_transaction(rlpres_db) < 0)
-               {
-                       LM_ERR("in end_transaction\n");
-                       goto error;
-               }
-       }
-
        xmlFree(rlmi_cont->s);
        pkg_free(rlmi_cont);
 
@@ -286,7 +283,8 @@ int send_full_notify(subs_t* subs, xmlNodePtr rl_node, str* 
rl_uri,
        }
        multipart_body_size = 0;
        pkg_free(rlsubs_did.s);
-
+       rlpres_dbf.free_result(rlpres_db, result);
+       
        return 0;
 error:
        if(rlmi_cont)
diff --git a/modules_k/rls/resource_notify.c b/modules_k/rls/resource_notify.c
index 310b0af..ba4af35 100644
--- a/modules_k/rls/resource_notify.c
+++ b/modules_k/rls/resource_notify.c
@@ -1063,10 +1063,9 @@ static void timer_send_update_notifies(int round)
                LM_ERR("in sql query\n");
                goto done;
        }
-       if(result== NULL || result->n<= 0)
+       if(result == NULL || result->n <= 0)
                goto done;
 
-       /* update the rlpres table */
        if(rlpres_dbf.update(rlpres_db, query_cols, 0, query_vals, update_cols,
                                        update_vals, 1, 1)< 0)
        {
diff --git a/modules_k/rls/rls_db.c b/modules_k/rls/rls_db.c
index cabd164..a4e7327 100644
--- a/modules_k/rls/rls_db.c
+++ b/modules_k/rls/rls_db.c
@@ -148,15 +148,6 @@ int delete_expired_subs_rlsdb( void )
        result_cols[r_to_tag_col=n_result_cols++] = &str_to_tag_col;
        result_cols[r_from_tag_col=n_result_cols++] = &str_from_tag_col;
 
-       if (rls_dbf.start_transaction)
-       {
-               if (rls_dbf.start_transaction(rls_db) < 0)
-               {
-                       LM_ERR("in start_transaction\n");
-                       goto error;
-               }
-       }
-
        if(rls_dbf.query(rls_db, query_cols, query_ops, query_vals, 
result_cols, 
                                n_query_cols, n_result_cols, 0, &result )< 0)
        {
@@ -221,28 +212,12 @@ int delete_expired_subs_rlsdb( void )
                pkg_free(rlsubs_did.s);
        }
 
-       if (rls_dbf.end_transaction)
-       {
-               if (rls_dbf.end_transaction(rls_db) < 0)
-               {
-                       LM_ERR("in end_transaction\n");
-                       goto error;
-               }
-       }
-
-       if(result) rls_dbf.free_result(rls_db, result);
+       rls_dbf.free_result(rls_db, result);
        return 1;
 
 error:
        if (result) rls_dbf.free_result(rls_db, result);
        if (rlsubs_did.s) pkg_free(rlsubs_did.s);
-
-       if (rls_dbf.abort_transaction)
-       {
-               if (rls_dbf.abort_transaction(rls_db) < 0)
-                       LM_ERR("in abort_transaction\n");
-       }
-
        return -1;
 }
 


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

Reply via email to