[sr-dev] git:master:d7bac1de: modules/tsilo: use use_domain inherited from usrloc

Federico Cabiddu fcabiddu at orange-vallee.net
Tue Apr 21 16:45:19 CEST 2015


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

Author: Federico Cabiddu <fcabiddu at orange-vallee.net>
Committer: Federico Cabiddu <fcabiddu at orange-vallee.net>
Date: 2015-04-21T16:41:29+02:00

modules/tsilo: use use_domain inherited from usrloc

- if usrloc use_domain is set, use the domain part of the ruri to store
the transaction, otherwise (the default) use only the username part.

---

Modified: modules/tsilo/ts_store.c
Modified: modules/tsilo/tsilo.c
Modified: modules/tsilo/tsilo.h

---

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

---

diff --git a/modules/tsilo/ts_store.c b/modules/tsilo/ts_store.c
index 48d1441..67dc2d6 100644
--- a/modules/tsilo/ts_store.c
+++ b/modules/tsilo/ts_store.c
@@ -37,44 +37,62 @@
 #include "ts_hash.h"
 #include "ts_store.h"
 
+extern int use_domain;
+
 int ts_store(struct sip_msg* msg) {
-	struct cell     *t;
-	str ruri;
+	struct cell		*t;
+	str aor;
+	struct sip_uri ruri;
+
 	ts_urecord_t* r;
 	int res;
 
-	t = _tmb.t_gett();
-	ruri = msg->first_line.u.request.uri;
 
+
+	if (use_domain) {
+		aor = msg->first_line.u.request.uri;
+	}
+	else {
+		if (parse_uri(msg->first_line.u.request.uri.s, msg->first_line.u.request.uri.len, &ruri)!=0)
+		{
+			LM_ERR("bad uri [%.*s]\n",
+					msg->first_line.u.request.uri.len,
+					msg->first_line.u.request.uri.s);
+			return -1;
+		}
+		aor = ruri.user;
+	}
+
+	t = _tmb.t_gett();
 	if (!t || t==T_UNDEFINED) {
-		LM_ERR("no transaction defined for %.*s\n", ruri.len, ruri.s);
+		LM_ERR("no transaction defined for %.*s\n", aor.len, aor.s);
 		return -1;
 	}
-	
-	LM_DBG("storing transaction %u:%u for r-uri: %.*s\n", t->hash_index, t->label, ruri.len, ruri.s);
 
-	lock_entry_by_ruri(&ruri);
+	LM_DBG("storing transaction %u:%u for r-uri: %.*s\n", t->hash_index, t->label, aor.len, aor.s);
+
+	lock_entry_by_ruri(&aor);
 
-	res = get_ts_urecord(&ruri, &r);
+	res = get_ts_urecord(&aor, &r);
 
 	if (res < 0) {
-		LM_ERR("failed to retrieve record for %.*s\n", ruri.len, ruri.s);
-		unlock_entry_by_ruri(&ruri);
+		LM_ERR("failed to retrieve record for %.*s\n", aor.len, aor.s);
+		unlock_entry_by_ruri(&aor);
 		return -1;
 	}
 
 	if (res != 0) { /* entry not found for the ruri */
-		if (insert_ts_urecord(&ruri, &r) < 0) {
+		if (insert_ts_urecord(&aor, &r) < 0) {
 			LM_ERR("failed to insert new record structure\n");
-			unlock_entry_by_ruri(&ruri);
+			unlock_entry_by_ruri(&aor);
 			return -1;
 		}
 	}
 
 	insert_ts_transaction(t, msg, r);
-	unlock_entry_by_ruri(&ruri);
+	unlock_entry_by_ruri(&aor);
 
-	LM_DBG("transaction %u:%u (ruri: %.*s) inserted\n", t->hash_index, t->label, ruri.len, ruri.s);
+	LM_DBG("transaction %u:%u (ruri: %.*s) inserted\n", t->hash_index, t->label, aor.len, aor.s);
 
 	return 1;
 }
diff --git a/modules/tsilo/tsilo.c b/modules/tsilo/tsilo.c
index fd38deb..7dbce56 100644
--- a/modules/tsilo/tsilo.c
+++ b/modules/tsilo/tsilo.c
@@ -30,6 +30,7 @@
 #include "../../script_cb.h"
 #include "../../modules/tm/tm_load.h"
 #include "../../modules/registrar/api.h"
+#include "../../modules/usrloc/usrloc.h"
 #include "../../dset.h"
 #include "../../rpc_lookup.h"
 
@@ -46,6 +47,10 @@ MODULE_VERSION
 struct tm_binds _tmb;
 /** REGISTRAR bind **/
 registrar_api_t _regapi;
+/** USRLOC BIND **/
+usrloc_api_t _ul;
+
+int use_domain = 0;
 
 /** parameters */
 static int hash_size = 2048;
@@ -98,6 +103,7 @@ struct module_exports exports= {
 static int mod_init(void)
 {
 	unsigned int n;
+	bind_usrloc_t bind_usrloc;
 
 	/* register the RPC methods */
 	if(rpc_register_array(rpc_methods)!=0)
@@ -116,6 +122,20 @@ static int mod_init(void)
 		LM_ERR("cannot load REGISTRAR API\n");
 		return -1;
 	}
+	/* load UL-Bindings */
+	bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
+
+	if (!bind_usrloc) {
+		LM_ERR("could not load the USRLOC API\n");
+		return -1;
+	}
+
+	if (bind_usrloc(&_ul) < 0) {
+		LM_ERR("could not load the USRLOC API\n");
+		return -1;
+	}
+
+	use_domain = _ul.use_domain;
 	/* sanitize hash_size */
     if (hash_size < 1){
         LM_WARN("hash_size is smaller "
diff --git a/modules/tsilo/tsilo.h b/modules/tsilo/tsilo.h
index 511cb72..90c965c 100644
--- a/modules/tsilo/tsilo.h
+++ b/modules/tsilo/tsilo.h
@@ -23,10 +23,15 @@
 
 #include "../../modules/tm/tm_load.h"
 #include "../../modules/registrar/api.h"
+#include "../../modules/usrloc/usrloc.h"
 
 /** TM bind */
 extern struct tm_binds _tmb;
 /** REGISTRAR bind */
 extern registrar_api_t _regapi;
+/** USRLOC BIND **/
+extern usrloc_api_t _ul;
+
+extern int use_domain;
 
 #endif




More information about the sr-dev mailing list