[sr-dev] git:master:4fa7a93f: topos: new parameter storage

Daniel-Constantin Mierla miconda at gmail.com
Wed Mar 1 10:19:22 CET 2017


Module: kamailio
Branch: master
Commit: 4fa7a93fb60d8e8468b0f98272c1661d4913c463
URL: https://github.com/kamailio/kamailio/commit/4fa7a93fb60d8e8468b0f98272c1661d4913c463

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-03-01T10:08:50+01:00

topos: new parameter storage

- specify the storage type to be used
- default value is "db", to use database connectors

---

Modified: src/modules/topos/topos_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/4fa7a93fb60d8e8468b0f98272c1661d4913c463.diff
Patch: https://github.com/kamailio/kamailio/commit/4fa7a93fb60d8e8468b0f98272c1661d4913c463.patch

---

diff --git a/src/modules/topos/topos_mod.c b/src/modules/topos/topos_mod.c
index 00f75a6..527b81f 100644
--- a/src/modules/topos/topos_mod.c
+++ b/src/modules/topos/topos_mod.c
@@ -74,6 +74,7 @@ sruid_t _tps_sruid;
 static str _tps_db_url = str_init(DEFAULT_DB_URL);
 int _tps_param_mask_callid = 0;
 int _tps_sanity_checks = 0;
+str _tps_storage = str_init("db");
 
 extern int _tps_branch_expire;
 extern int _tps_dialog_expire;
@@ -103,6 +104,7 @@ static cmd_export_t cmds[]={
 };
 
 static param_export_t params[]={
+	{"storage",			PARAM_STR, &_tps_storage},
 	{"db_url",			PARAM_STR, &_tps_db_url},
 	{"mask_callid",		PARAM_INT, &_tps_param_mask_callid},
 	{"sanity_checks",	PARAM_INT, &_tps_sanity_checks},
@@ -134,15 +136,17 @@ struct module_exports exports= {
  */
 static int mod_init(void)
 {
-	/* Find a database module */
-	if (db_bind_mod(&_tps_db_url, &_tpsdbf)) {
-		LM_ERR("unable to bind database module\n");
-		return -1;
-	}
-	if (!DB_CAPABILITY(_tpsdbf, DB_CAP_ALL)) {
-		LM_CRIT("database modules does not "
-			"provide all functions needed\n");
-		return -1;
+	if(_tps_storage.len==2 && strncmp(_tps_storage.s, "db", 2)==0) {
+		/* Find a database module */
+		if (db_bind_mod(&_tps_db_url, &_tpsdbf)) {
+			LM_ERR("unable to bind database module\n");
+			return -1;
+		}
+		if (!DB_CAPABILITY(_tpsdbf, DB_CAP_ALL)) {
+			LM_CRIT("database modules does not "
+				"provide all functions needed\n");
+			return -1;
+		}
 	}
 
 	if(_tps_sanity_checks!=0) {
@@ -185,10 +189,12 @@ static int child_init(int rank)
 	if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN)
 		return 0; /* do nothing for the main process */
 
-	_tps_db_handle = _tpsdbf.init(&_tps_db_url);
-	if (!_tps_db_handle) {
-		LM_ERR("unable to connect database\n");
-		return -1;
+	if(_tps_storage.len==2 && strncmp(_tps_storage.s, "db", 2)==0) {
+		_tps_db_handle = _tpsdbf.init(&_tps_db_url);
+		if (!_tps_db_handle) {
+			LM_ERR("unable to connect database\n");
+			return -1;
+		}
 	}
 	return 0;
 
@@ -199,9 +205,11 @@ static int child_init(int rank)
  */
 static void destroy(void)
 {
-	if (_tps_db_handle) {
-		_tpsdbf.close(_tps_db_handle);
-		_tps_db_handle = 0;
+	if(_tps_storage.len==2 && strncmp(_tps_storage.s, "db", 2)==0) {
+		if (_tps_db_handle) {
+			_tpsdbf.close(_tps_db_handle);
+			_tps_db_handle = 0;
+		}
 	}
 	tps_storage_lock_set_destroy();
 }




More information about the sr-dev mailing list