浏览代码

usrloc(k): new parameter 'preload'

- can be used to specify list of location table to be initiated at
  startup, even they are not used by registrar module functions
- good for using the usrloc module from other modules
Daniel-Constantin Mierla 15 年之前
父节点
当前提交
16679e6dfe
共有 3 个文件被更改,包括 77 次插入0 次删除
  1. 18 0
      modules_k/usrloc/README
  2. 23 0
      modules_k/usrloc/doc/usrloc_admin.xml
  3. 36 0
      modules_k/usrloc/ul_mod.c

+ 18 - 0
modules_k/usrloc/README

@@ -62,6 +62,7 @@ Bogdan-Andrei Iancu
               3.22. cseq_delay (integer)
               3.23. fetch_rows (integer)
               3.24. hash_size (integer)
+              3.25. preload (string)
 
         4. Exported Functions
         5. Exported MI Functions
@@ -130,6 +131,7 @@ Bogdan-Andrei Iancu
    1.22. Set cseq_delay parameter
    1.23. Set fetch_rows parameter
    1.24. Set hash_size parameter
+   1.25. Set preload parameter
 
 Chapter 1. Admin Guide
 
@@ -170,6 +172,7 @@ Chapter 1. Admin Guide
         3.22. cseq_delay (integer)
         3.23. fetch_rows (integer)
         3.24. hash_size (integer)
+        3.25. preload (string)
 
    4. Exported Functions
    5. Exported MI Functions
@@ -270,6 +273,7 @@ Chapter 1. Admin Guide
    3.22. cseq_delay (integer)
    3.23. fetch_rows (integer)
    3.24. hash_size (integer)
+   3.25. preload (string)
 
 3.1. nat_bflag (integer)
 
@@ -600,6 +604,20 @@ modparam("usrloc", "fetch_rows", 3000)
 modparam("usrloc", "hash_size", 10)
 ...
 
+3.25. preload (string)
+
+   Preload location table given as value. A location table is loaded based
+   on fixup of registrar functions, therefore you need to use this
+   parameter only to load tables that are not used by registrar module
+   directly in configuration file.
+
+   Default value is “NULL”.
+
+   Example 1.25. Set preload parameter
+...
+modparam("usrloc", "preload", "location")
+...
+
 4. Exported Functions
 
    There are no exported functions that could be used in scripts.

+ 23 - 0
modules_k/usrloc/doc/usrloc_admin.xml

@@ -690,6 +690,29 @@ modparam("usrloc", "hash_size", 10)
 		</example>
 	</section>
 
+	<section id="preload">
+		<title><varname>preload</varname> (string)</title>
+		<para>
+		Preload location table given as value. A location table is loaded
+		based on fixup of registrar functions, therefore you need to use this
+		parameter only to load tables that are not used by registrar module
+		directly in configuration file.
+		</para>
+		<para>
+		<emphasis>
+			Default value is <quote>NULL</quote>.
+		</emphasis>
+		</para>
+		<example>
+		<title>Set <varname>preload</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("usrloc", "preload", "location")
+...
+</programlisting>
+		</example>
+	</section>
+
 	</section>
 
 	<section>

+ 36 - 0
modules_k/usrloc/ul_mod.c

@@ -92,6 +92,11 @@ static void timer(unsigned int ticks, void* param); /*!< Timer handler */
 static int child_init(int rank);                    /*!< Per-child init function */
 static int mi_child_init(void);
 
+#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);
+
 extern int bind_usrloc(usrloc_api_t* api);
 extern int ul_locks_no;
 /*
@@ -168,6 +173,7 @@ static param_export_t params[] = {
 	{"fetch_rows",        INT_PARAM, &ul_fetch_rows   },
 	{"hash_size",         INT_PARAM, &ul_hash_size    },
 	{"nat_bflag",         INT_PARAM, &nat_bflag       },
+	{"preload",           STR_PARAM|USE_FUNC_PARAM, (void*)ul_preload_param },
 	{0, 0, 0}
 };
 
@@ -216,6 +222,9 @@ struct module_exports exports = {
  */
 static int mod_init(void)
 {
+	int i;
+	udomain_t* d;
+
 #ifdef STATISTICS
 	/* register statistics */
 	if (register_module_stats( exports.name, mod_stats)!=0 ) {
@@ -311,6 +320,12 @@ static int mod_init(void)
 		nat_bflag = 1<<nat_bflag;
 	}
 
+	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;
+		}
+	}
 	init_flag = 1;
 
 	return 0;
@@ -419,3 +434,24 @@ static void timer(unsigned int ticks, void* param)
 	}
 }
 
+/*! \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;
+}