[sr-dev] git:master: registrar: new api function lookup_to_dset

Federico Cabiddu federico.cabiddu at gmail.com
Wed Sep 10 13:21:42 CEST 2014


Module: sip-router
Branch: master
Commit: ccaa53b1227e6ac516efc42db1315ea96fe4e95a
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ccaa53b1227e6ac516efc42db1315ea96fe4e95a

Author: Federico Cabiddu <federico.cabiddu at gmail.com>
Committer: Federico Cabiddu <federico.cabiddu at gmail.com>
Date:   Tue Sep  9 07:32:41 2014 +0000

registrar: new api function lookup_to_dset

---

 modules/registrar/api.c     |   16 ++++++++++++++++
 modules/registrar/api.h     |    2 ++
 modules/registrar/lookup.c  |   22 ++++++++++++++++++++--
 modules/registrar/lookup.h  |   16 ++++++++++++++++
 modules/registrar/reg_mod.c |   17 +++++++++++++++++
 5 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/modules/registrar/api.c b/modules/registrar/api.c
index a8c5b50..564b252 100644
--- a/modules/registrar/api.c
+++ b/modules/registrar/api.c
@@ -125,6 +125,21 @@ int regapi_set_q_override(struct sip_msg *msg, str *new_q)
 /**
  *
  */
+int regapi_lookup_to_dset(struct sip_msg *msg, char *table, str *uri)
+{
+	udomain_t* d;
+
+	if(ul.get_udomain(table, &d)<0)
+	{
+		LM_ERR("usrloc domain [%s] not found\n", table);
+		return -1;
+	}
+	return lookup_to_dset(msg, d, uri);
+}
+
+/**
+ *
+ */
 int bind_registrar(registrar_api_t* api)
 {
 	if (!api) {
@@ -135,6 +150,7 @@ int bind_registrar(registrar_api_t* api)
 	api->save_uri   = regapi_save_uri;
 	api->lookup     = regapi_lookup;
 	api->lookup_uri = regapi_lookup_uri;
+	api->lookup_to_dset = regapi_lookup_to_dset;
 	api->registered = regapi_registered;
 	api->set_q_override = regapi_set_q_override;
 
diff --git a/modules/registrar/api.h b/modules/registrar/api.h
index b3109de..11d8b15 100644
--- a/modules/registrar/api.h
+++ b/modules/registrar/api.h
@@ -42,6 +42,7 @@ int regapi_lookup(struct sip_msg *msg, char *table);
 
 typedef int (*regapi_lookup_uri_f)(struct sip_msg *msg, char *table, str *uri);
 int regapi_lookup_uri(struct sip_msg *msg, char *table, str *uri);
+int regapi_lookup_to_dset(struct sip_msg *msg, char *table, str *uri);
 
 typedef int (*regapi_set_q_override_f)(struct sip_msg *msg, str *new_q);
 int regapi_set_q_override(struct sip_msg *msg, str *new_q);
@@ -54,6 +55,7 @@ typedef struct registrar_api {
 	regapi_save_uri_f   save_uri;
 	regapi_lookup_f     lookup;
 	regapi_lookup_uri_f lookup_uri;
+	regapi_lookup_uri_f lookup_to_dset;
 	regapi_lookup_f     registered;
 	regapi_set_q_override_f set_q_override;
 } registrar_api_t;
diff --git a/modules/registrar/lookup.c b/modules/registrar/lookup.c
index 2b3ad96..794d968 100644
--- a/modules/registrar/lookup.c
+++ b/modules/registrar/lookup.c
@@ -82,12 +82,29 @@ int reg_cmp_instances(str *i1, str *i2)
 }
 
 /*! \brief
+ * Lookup a contact in usrloc and rewrite R-URI if found
+ */
+int lookup(struct sip_msg* _m, udomain_t* _d, str* _uri) {
+     return lookup_helper(_m, _d, _uri, 0);
+}
+
+/*! \brief
+ * Lookup a contact in usrloc and add the records to the dset structure
+ */
+int lookup_to_dset(struct sip_msg* _m, udomain_t* _d, str* _uri) {
+     return lookup_helper(_m, _d, _uri, 1);
+}
+
+/*! \brief
  * Lookup contact in the database and rewrite Request-URI
+ * or not according to _mode value:
+ *  0: rewrite
+ *  1: don't rewrite
  * \return: -1 : not found
  *          -2 : found but method not allowed
  *          -3 : error
  */
-int lookup(struct sip_msg* _m, udomain_t* _d, str* _uri)
+int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
 {
 	urecord_t* r;
 	str aor, uri;
@@ -211,7 +228,8 @@ int lookup(struct sip_msg* _m, udomain_t* _d, str* _uri)
 	}
 
 	ret = 1;
-	if (ptr) {
+	/* don't rewrite r-uri if called by lookup_to_dset */
+	if (_mode == 0 && ptr) {
 		if (rewrite_uri(_m, &ptr->c) < 0) {
 			LM_ERR("unable to rewrite Request-URI\n");
 			ret = -3;
diff --git a/modules/registrar/lookup.h b/modules/registrar/lookup.h
index e2703ad..1a88c94 100644
--- a/modules/registrar/lookup.h
+++ b/modules/registrar/lookup.h
@@ -37,11 +37,27 @@
 
 
 /*! \brief
+ * Lookup contact in the database and rewrite Request-URI
+ * or not according to _mode value:
+ *  0: rewrite
+ *  1: don't rewrite
+ * \return: -1 : not found
+ *          -2 : found but method not allowed
+ *          -3 : error
+ */
+int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode);
+
+/*! \brief
  * Lookup a contact in usrloc and rewrite R-URI if found
  */
 int lookup(struct sip_msg* _m, udomain_t* _d, str* _uri);
 
 /*! \brief
+ * Lookup a contact in usrloc and add the records to the dset structure
+ */
+int lookup_to_dset(struct sip_msg* _m, udomain_t* _d, str* _uri);
+
+/*! \brief
  * Lookup r-uri and additional branches in usrloc
  */
 int lookup_branches(sip_msg_t *msg, udomain_t *d);
diff --git a/modules/registrar/reg_mod.c b/modules/registrar/reg_mod.c
index ce0d823..f187fb3 100644
--- a/modules/registrar/reg_mod.c
+++ b/modules/registrar/reg_mod.c
@@ -91,6 +91,7 @@ static void mod_destroy(void);
 static int w_save2(struct sip_msg* _m, char* _d, char* _cflags);
 static int w_save3(struct sip_msg* _m, char* _d, char* _cflags, char* _uri);
 static int w_lookup(struct sip_msg* _m, char* _d, char* _p2);
+static int w_lookup_to_dset(struct sip_msg* _m, char* _d, char* _p2);
 static int w_lookup_branches(struct sip_msg* _m, char* _d, char* _p2);
 static int w_registered(struct sip_msg* _m, char* _d, char* _uri);
 static int w_unregister(struct sip_msg* _m, char* _d, char* _uri);
@@ -181,6 +182,8 @@ static cmd_export_t cmds[] = {
 			REQUEST_ROUTE | FAILURE_ROUTE },
 	{"lookup",       (cmd_function)w_lookup,      2,  domain_uri_fixup, 0,
 			REQUEST_ROUTE | FAILURE_ROUTE },
+	{"lookup_to_dset",  (cmd_function)w_lookup_to_dset,  1,  domain_uri_fixup, 0,
+			REQUEST_ROUTE | FAILURE_ROUTE },
 	{"registered",   (cmd_function)w_registered,  1,  domain_uri_fixup, 0,
 			REQUEST_ROUTE | FAILURE_ROUTE },
 	{"registered",   (cmd_function)w_registered,  2,  domain_uri_fixup, 0,
@@ -475,6 +478,20 @@ static int w_lookup(struct sip_msg* _m, char* _d, char* _uri)
 }
 
 /*! \brief
+ * Wrapper to lookup_to_dset(location)
+ */
+static int w_lookup_to_dset(struct sip_msg* _m, char* _d, char* _uri)
+{
+	str uri = {0};
+	if(_uri!=NULL && (fixup_get_svalue(_m, (gparam_p)_uri, &uri)!=0 || uri.len<=0))
+	{
+		LM_ERR("invalid uri parameter\n");
+		return -1;
+	}
+
+	return lookup_to_dset(_m, (udomain_t*)_d, (uri.len>0)?&uri:NULL);
+}
+/*! \brief
  * Wrapper to lookup_branches(location)
  */
 static int w_lookup_branches(sip_msg_t* _m, char* _d, char* _p2)




More information about the sr-dev mailing list