Browse Source

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.
Federico Cabiddu 10 năm trước cách đây
mục cha
commit
d7bac1deed
3 tập tin đã thay đổi với 58 bổ sung15 xóa
  1. 33 15
      modules/tsilo/ts_store.c
  2. 20 0
      modules/tsilo/tsilo.c
  3. 5 0
      modules/tsilo/tsilo.h

+ 33 - 15
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;
 }

+ 20 - 0
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 "

+ 5 - 0
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