[sr-dev] git:master: xcap_client: init db con per process

Daniel-Constantin Mierla miconda at gmail.com
Tue Jun 9 13:50:12 CEST 2009


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Tue Jun  9 14:47:15 2009 +0300

xcap_client: init db con per process

- introduced child_init function to init db connection per process
- db connection closed in destroy function
- reported and credits to Pascal Maugeri and Inaki Baz Castillo

---

 modules_k/presence/subscribe.c      |    2 +-
 modules_k/xcap_client/xcap_client.c |   20 ++++++++++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/modules_k/presence/subscribe.c b/modules_k/presence/subscribe.c
index f05300a..3067919 100644
--- a/modules_k/presence/subscribe.c
+++ b/modules_k/presence/subscribe.c
@@ -1610,7 +1610,7 @@ void update_db_subs(db1_con_t *db,db_func_t dbf, shtable_t hash_table,
 			lock_release(&hash_table[i].lock);	
 	}
 
-	update_vals[0].val.int_val= (int)time(NULL)- 10;
+	update_vals[0].val.int_val= (int)time(NULL) - expires_offset;
 	update_ops[0]= OP_LT;
 	if(dbf.delete(db, update_cols, update_ops, update_vals, 1) < 0)
 	{
diff --git a/modules_k/xcap_client/xcap_client.c b/modules_k/xcap_client/xcap_client.c
index 8fde618..55084d8 100644
--- a/modules_k/xcap_client/xcap_client.c
+++ b/modules_k/xcap_client/xcap_client.c
@@ -53,6 +53,7 @@ MODULE_VERSION
 #define XCAP_TABLE_VERSION   3
 
 static int mod_init(void);
+static int child_init(int rank);
 void destroy(void);
 struct mi_root* refreshXcapDoc(struct mi_root* cmd, void* param);
 int get_auid_flag(str auid);
@@ -112,7 +113,7 @@ struct module_exports exports= {
 	mod_init,					/* module initialization function */
 	0,							/* response handling function */
 	(destroy_function) destroy, /* destroy function */
-	0							/* per-child init function */
+	child_init					/* per-child init function */
 };
 
 /**
@@ -149,10 +150,13 @@ static int mod_init(void)
 		return -1;
 	}
 
-	if(db_check_table_version(&xcap_dbf, xcap_db, &xcap_db_table, XCAP_TABLE_VERSION) < 0) {
+	if(db_check_table_version(&xcap_dbf, xcap_db, &xcap_db_table,
+				XCAP_TABLE_VERSION) < 0) {
 		LM_ERR("error during table version check.\n");
 		return -1;
 	}
+	xcap_dbf.close(xcap_db);
+	xcap_db = NULL;
 
 	curl_global_init(CURL_GLOBAL_ALL);
 
@@ -163,9 +167,21 @@ static int mod_init(void)
 	return 0;
 }
 
+static int child_init(int rank)
+{
+	if((xcap_db = xcap_dbf.init(&xcap_db_url))==NULL)
+	{
+		LM_ERR("cannot connect to db\n");
+		return -1;
+	}
+	return -1;
+}
+
 void destroy(void)
 {
 	curl_global_cleanup();
+	if(xcap_db != NULL)
+		xcap_dbf.close(xcap_db);
 }
 
 void query_xcap_update(unsigned int ticks, void* param)




More information about the sr-dev mailing list