[sr-dev] git:master:aedd970a: usrloc: add module option to support preload using server_id as filter

Victor Seva linuxmaniac at torreviejawireless.org
Mon Jul 6 09:03:18 CEST 2015


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

Author: Victor Seva <linuxmaniac at torreviejawireless.org>
Committer: Victor Seva <linuxmaniac at torreviejawireless.org>
Date: 2015-07-04T09:43:41+02:00

usrloc: add module option to support preload using server_id as filter

---

Modified: modules/usrloc/udomain.c
Modified: modules/usrloc/ul_mod.c
Modified: modules/usrloc/ul_mod.h

---

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

---

diff --git a/modules/usrloc/udomain.c b/modules/usrloc/udomain.c
index 2bb1707..9b31a3b 100644
--- a/modules/usrloc/udomain.c
+++ b/modules/usrloc/udomain.c
@@ -379,6 +379,9 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d)
 	db_row_t *row;
 	db_key_t columns[21];
 	db1_res_t* res = NULL;
+	db_key_t keys[1]; /* where */
+	db_val_t vals[1];
+	db_op_t  ops[1];
 	str user, contact;
 	char* domain;
 	int i;
@@ -418,9 +421,21 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d)
 	LM_NOTICE("load start time [%d]\n", (int)time(NULL));
 #endif
 
+	if (ul_db_srvid) {
+		LM_NOTICE("filtered by server_id[%d]\n", server_id);
+		keys[0] = &srv_id_col;
+		ops[0] = OP_EQ;
+		vals[0].type = DB1_INT;
+		vals[0].nul = 0;
+		vals[0].val.int_val = server_id;
+	}
+
 	if (DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) {
-		if (ul_dbf.query(_c, 0, 0, 0, columns, 0, (use_domain)?(21):(20), 0,
-		0) < 0) {
+		if (ul_dbf.query(_c, (ul_db_srvid)?(keys):(0),
+							(ul_db_srvid)?(ops):(0), (ul_db_srvid)?(vals):(0),
+							columns, (ul_db_srvid)?(1):(0),
+							(use_domain)?(21):(20), 0, 0) < 0)
+		{
 			LM_ERR("db_query (1) failed\n");
 			return -1;
 		}
@@ -429,8 +444,11 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d)
 			return -1;
 		}
 	} else {
-		if (ul_dbf.query(_c, 0, 0, 0, columns, 0, (use_domain)?(21):(20), 0,
-		&res) < 0) {
+		if (ul_dbf.query(_c, (ul_db_srvid)?(keys):(0),
+							(ul_db_srvid)?(ops):(0), (ul_db_srvid)?(vals):(0),
+							columns, (ul_db_srvid)?(1):(0),
+							(use_domain)?(21):(20), 0, &res) < 0)
+		{
 			LM_ERR("db_query failed\n");
 			return -1;
 		}
diff --git a/modules/usrloc/ul_mod.c b/modules/usrloc/ul_mod.c
index 1ad69e3..f0728c5 100644
--- a/modules/usrloc/ul_mod.c
+++ b/modules/usrloc/ul_mod.c
@@ -173,7 +173,8 @@ unsigned int init_flag = 0;
 db1_con_t* ul_dbh = 0; /* Database connection handle */
 db_func_t ul_dbf;
 
-
+/* filter on load by server id */
+unsigned int ul_db_srvid = 0;
 
 /*! \brief
  * Exported functions
@@ -229,6 +230,7 @@ static param_export_t params[] = {
 	{"expires_type",        PARAM_INT, &ul_expires_type},
 	{"db_raw_fetch_type",   PARAM_INT, &ul_db_raw_fetch_type},
 	{"db_insert_null",      PARAM_INT, &ul_db_insert_null},
+	{"server_id_filter",    PARAM_INT, &ul_db_srvid},
 	{0, 0, 0}
 };
 
diff --git a/modules/usrloc/ul_mod.h b/modules/usrloc/ul_mod.h
index 1e3b08d..3809cf8 100644
--- a/modules/usrloc/ul_mod.h
+++ b/modules/usrloc/ul_mod.h
@@ -98,6 +98,8 @@ extern str ul_xavp_contact_name;
 extern db1_con_t* ul_dbh;   /* Database connection handle */
 extern db_func_t ul_dbf;
 
+/* filter on load by server id */
+extern unsigned int ul_db_srvid;
 
 /*
  * Matching algorithms




More information about the sr-dev mailing list