Ver Fonte

p_usrloc: Add new modparam 'preload'

Useful when using kemi with p_usrloc, in order to preload
location table.
Stefan-Cristian Mititelu há 1 ano atrás
pai
commit
4efd1fc33c
1 ficheiros alterados com 36 adições e 0 exclusões
  1. 36 0
      src/modules/p_usrloc/p_usrloc_mod.c

+ 36 - 0
src/modules/p_usrloc/p_usrloc_mod.c

@@ -88,6 +88,11 @@ static int child_init(int rank); /*!< Per-child init function */
 extern int bind_usrloc(usrloc_api_t *api);
 extern int ul_locks_no;
 
+#define UL_PRELOAD_SIZE 8
+static char *ul_preload_list[UL_PRELOAD_SIZE];
+static int ul_preload_index = 0;
+static int ul_preload_param(modparam_t type, void *val);
+
 /*
  * Module parameters and their default values
  */
@@ -269,6 +274,7 @@ static param_export_t params[] = {{"ruid_column", PARAM_STR, &ruid_col},
 		{"db_update_as_insert", INT_PARAM,
 				&default_p_usrloc_cfg.db_update_as_insert},
 		{"mdb_availability_control", INT_PARAM, &mdb_availability_control},
+		{"preload", PARAM_STRING | USE_FUNC_PARAM, (void *)ul_preload_param},
 		{0, 0, 0}};
 
 
@@ -310,6 +316,8 @@ struct module_exports exports = {
  */
 static int mod_init(void)
 {
+	int i = 0;
+	udomain_t *d;
 	int matching_mode_cfg = cfg_get(p_usrloc, p_usrloc_cfg, matching_mode);
 
 #ifdef STATISTICS
@@ -352,6 +360,14 @@ static int mod_init(void)
 		return -1;
 	}
 
+	/* preload tables */
+	for(i = 0; i < ul_preload_index; i++) {
+		if(register_udomain((const char *)ul_preload_list[i], &d) < 0) {
+			LM_ERR("cannot register preloaded table %s\n", ul_preload_list[i]);
+			return -1;
+		}
+	}
+
 	if(db_mode != DB_ONLY) {
 		LM_ERR("DB_ONLY is the only mode possible for partitioned usrloc. "
 			   "Please set db_mode to 3\n");
@@ -513,3 +529,23 @@ time_t ul_db_datetime_get(time_t v)
 		return v;
 	}
 }
+
+/*! \brief
+ * preload module parameter handler
+ */
+static int ul_preload_param(modparam_t type, void *val)
+{
+	if(val == NULL) {
+		LM_ERR("invalid parameter\n");
+		goto error;
+	}
+	if(ul_preload_index >= UL_PRELOAD_SIZE) {
+		LM_ERR("too many preloaded tables\n");
+		goto error;
+	}
+	ul_preload_list[ul_preload_index] = (char *)val;
+	ul_preload_index++;
+	return 0;
+error:
+	return -1;
+}