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

Author: Stefan-Cristian Mititelu <stefan-cristian.mitit...@1and1.ro>
Committer: Stefan-Cristian Mititelu <stefan-cristian.mitit...@1and1.ro>
Date: 2024-02-01T14:00:17+02:00

p_usrloc: Add new modparam 'preload'

Useful when using kemi with p_usrloc, in order to preload
location table.

---

Modified: src/modules/p_usrloc/p_usrloc_mod.c

---

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

---

diff --git a/src/modules/p_usrloc/p_usrloc_mod.c 
b/src/modules/p_usrloc/p_usrloc_mod.c
index 8179d12ae14..539ad31b031 100644
--- a/src/modules/p_usrloc/p_usrloc_mod.c
+++ b/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;
+}

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org

Reply via email to