瀏覽代碼

topos: new parameter storage

- specify the storage type to be used
- default value is "db", to use database connectors
Daniel-Constantin Mierla 8 年之前
父節點
當前提交
4fa7a93fb6
共有 1 個文件被更改,包括 24 次插入16 次删除
  1. 24 16
      src/modules/topos/topos_mod.c

+ 24 - 16
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();
 }