浏览代码

Merge branch 'master' of ssh://git.sip-router.org/sip-router

Andreas Granig 13 年之前
父节点
当前提交
385befa3d7

+ 17 - 0
lib/srdb1/db.h

@@ -473,5 +473,22 @@ int db_fetch_query(db_func_t *dbf, int frows,
 int db_fetch_next(db_func_t *dbf, int frows, db1_con_t* _h,
 		db1_res_t** _r);
 
+/**
+ * \brief wrapper around db raw_query to perform BEGIN
+ * \return -1 error; 0 OK with no raw_query capability; 1 OK with raw_query capability
+ */
+int db_begin(db_func_t *dbf, db1_con_t* _h);
+
+/**
+ * \brief wrapper around db raw_query to perform COMMIT
+ * \return -1 error; 0 OK with no raw_query capability; 1 OK with raw_query capability
+ */     
+int db_commit(db_func_t *dbf, db1_con_t* _h);
+
+/**
+ * \wrapper around db raw_query to perform ROLLBACK
+ * \return -1 error; 0 OK with no raw_query capability; 1 OK with raw_query capability
+ */
+int db_rollback(db_func_t *dbf, db1_con_t* _h);
 
 #endif /* DB1_H */

+ 69 - 0
lib/srdb1/db_query.c

@@ -456,3 +456,72 @@ error:
 	}
 	return -1;
 }
+
+/**
+ * wrapper around db raw_query to perform BEGIN
+ * return: -1 error; 0 OK with no raw_query capability; 1 OK with raw_query capability
+ */
+int db_begin(db_func_t *dbf, db1_con_t* _h)
+{
+	db1_res_t *res = NULL;
+	int ret = 0;
+	str query_str = str_init("BEGIN");
+
+	if (DB_CAPABILITY(*dbf, DB_CAP_RAW_QUERY)) {
+		if (dbf->raw_query(_h, &query_str, &res)) {
+			LM_ERR("unable to run raw query\n");
+			ret = -1;
+			goto done;
+		}
+		ret = 1;
+	}
+done:
+	if (res) dbf->free_result(_h, res);
+	return ret;
+}
+
+/**
+ * wrapper around db raw_query to perform COMMIT
+ * return: -1 error; 0 OK with no raw_query capability; 1 OK with raw_query capability
+ */
+int db_commit(db_func_t *dbf, db1_con_t* _h)
+{
+	db1_res_t *res = NULL;
+	int ret = 0;
+	str query_str = str_init("COMMIT");
+
+	if (DB_CAPABILITY(*dbf, DB_CAP_RAW_QUERY)) {
+		if (dbf->raw_query(_h, &query_str, &res)) {
+			LM_ERR("unable to run raw query\n");
+			ret = -1;
+			goto done;
+		}
+		ret = 1;
+	}
+done:
+	if (res) dbf->free_result(_h, res);
+	return ret;
+}
+
+/**
+ * wrapper around db raw_query to perform ROLLBACK
+ * return: -1 error; 0 OK with no raw_query capability; 1 OK with raw_query capability
+ */
+int db_rollback(db_func_t *dbf, db1_con_t* _h)
+{
+	db1_res_t *res = NULL;
+	int ret = 0;
+	str query_str = str_init("COMMIT");
+
+	if (DB_CAPABILITY(*dbf, DB_CAP_RAW_QUERY)) {
+		if (dbf->raw_query(_h, &query_str, &res)) {
+			LM_ERR("unable to run raw query\n");
+			ret = -1;
+			goto done;
+		}
+		ret = 1;
+	}
+done:
+	if (res) dbf->free_result(_h, res);
+	return ret;
+}

+ 1 - 1
modules/db_postgres/README

@@ -85,7 +85,7 @@ Chapter 1. Admin Guide
 
    Example 1.1. Set retries parameter
 ...
-modparam("db_mysql", "retries", 3)
+modparam("db_postgres", "retries", 3)
 ...
 
 4. Functions

+ 1 - 1
modules/db_postgres/doc/db_postgres_admin.xml

@@ -76,7 +76,7 @@
 		<title>Set <varname>retries</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
-modparam("db_mysql", "retries", 3)
+modparam("db_postgres", "retries", 3)
 ...
 </programlisting>
 		</example>

+ 2 - 0
modules/tm/t_suspend.c

@@ -133,6 +133,8 @@ int t_continue(unsigned int hash_index, unsigned int label,
 		/* The transaction has already been canceled,
 		 * needless to continue */
 		UNREF(t); /* t_unref would kill the transaction */
+		/* reset T as we have no working T anymore */
+		set_t(T_UNDEFINED, T_BR_UNDEFINED);
 		return 1;
 	}
 

+ 12 - 0
modules_k/rls/notify.c

@@ -128,6 +128,12 @@ int send_full_notify(subs_t* subs, xmlNodePtr rl_node, str* rl_uri,
 		goto error;
 	}
 
+	if (db_begin(&rlpres_dbf, rlpres_db) < 0)
+	{
+		LM_ERR("in BEGIN\n");
+		goto error;
+	}
+
 	if(rlpres_dbf.query(rlpres_db, query_cols, 0, query_vals, result_cols,
 					1, n_result_cols, &str_resource_uri_col, &result )< 0)
 	{
@@ -257,6 +263,12 @@ int send_full_notify(subs_t* subs, xmlNodePtr rl_node, str* rl_uri,
 		goto error;
 	}
 
+	if (db_commit(&rlpres_dbf, rlpres_db) < 0)
+	{
+		LM_ERR("in COMMIT\n");
+		goto error;
+	}
+
 	xmlFree(rlmi_cont->s);
 	pkg_free(rlmi_cont);
 

+ 24 - 0
modules_k/rls/resource_notify.c

@@ -893,6 +893,12 @@ static void timer_send_full_state_notifies(int round)
 		goto done;
 	}
 
+	if (db_begin(&rls_dbf, rls_db) < 0)
+	{
+		LM_ERR("in BEGIN\n");
+		goto done;
+	}
+
 	/* Step 1: Find rls_watchers that require full-state notification */
 	if (rls_dbf.query(rls_db, query_cols, 0, query_vals, result_cols,
 				1, n_result_cols, 0, &result) < 0)
@@ -912,6 +918,12 @@ static void timer_send_full_state_notifies(int round)
 		goto done;
 	}
 
+	if (db_commit(&rls_dbf, rls_db) < 0)
+	{
+		LM_ERR("in COMMIT\n");
+		goto done;
+	}
+
 	/* Step 3: Full-state notify each watcher we found */
 	rows = RES_ROWS(result);
 	for (i = 0; i < RES_ROW_N(result); i++)
@@ -1025,6 +1037,12 @@ static void timer_send_update_notifies(int round)
 		goto done;
 	}
 
+	if (db_begin(&rlpres_dbf, rlpres_db) < 0)
+	{
+		LM_ERR("in BEGIN\n");
+		goto error;
+	}
+
 	if(rlpres_dbf.query(rlpres_db, query_cols, 0, query_vals, result_cols,
 					1, n_result_cols, &str_rlsubs_did_col, &result)< 0)
 	{
@@ -1042,6 +1060,12 @@ static void timer_send_update_notifies(int round)
 		goto error;
 	}
 
+	if (db_commit(&rlpres_dbf, rlpres_db) < 0)
+	{
+		LM_ERR("in COMMIT\n");
+		goto error;
+	}
+
 	send_notifies(result, did_col, resource_uri_col, auth_state_col, reason_col,
                   pres_state_col, content_type_col);
 error:

+ 21 - 0
modules_k/rls/rls_db.c

@@ -124,6 +124,7 @@ int delete_expired_subs_rlsdb( void )
 	int i;
 	subs_t subs;
 	str rlsubs_did = {0, 0};
+	int transaction_started = 0;
 
 	if(rls_db == NULL)
 	{
@@ -148,6 +149,13 @@ 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 (db_begin(&rls_dbf, rls_db) < 0)
+	{
+		LM_ERR("in BEGIN\n");
+		goto error;
+	}
+	transaction_started = 1;
+
 	if(rls_dbf.query(rls_db, query_cols, query_ops, query_vals, result_cols, 
 				n_query_cols, n_result_cols, 0, &result )< 0)
 	{
@@ -213,12 +221,25 @@ int delete_expired_subs_rlsdb( void )
 		pkg_free(rlsubs_did.s);
 	}
 
+	if (db_commit(&rls_dbf, rls_db) < 0)
+	{
+		LM_ERR("in COMMIT\n");
+		goto error;
+	}
+
 	if(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 (transaction_started)
+	{
+		if (db_commit(&rls_dbf, rls_db) < 0)
+			LM_ERR("in COMMIT\n");
+	}
+
 	return -1;
 }