[sr-dev] git:carstenbock/ims: - New function: is_registered("domain", "uri")

Carsten Bock carsten at bock.info
Thu Mar 10 13:16:11 CET 2011


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

Author: Carsten Bock <carsten at bock.info>
Committer: Carsten Bock <carsten at bock.info>
Date:   Wed Mar  9 15:13:51 2011 +0100

- New function: is_registered("domain", "uri")

---

 modules_k/registrar/doc/registrar_admin.xml |   41 ++++++++++++++++++++++++++-
 modules_k/registrar/lookup.c                |   37 +++++++++++++++++++++++-
 modules_k/registrar/lookup.h                |    5 +++
 modules_k/registrar/reg_mod.c               |   11 +++++--
 modules_k/registrar/reg_mod.h               |   11 +++++++
 5 files changed, 99 insertions(+), 6 deletions(-)

diff --git a/modules_k/registrar/doc/registrar_admin.xml b/modules_k/registrar/doc/registrar_admin.xml
index ec553ed..091e36a 100644
--- a/modules_k/registrar/doc/registrar_admin.xml
+++ b/modules_k/registrar/doc/registrar_admin.xml
@@ -812,7 +812,7 @@ switch ($retcode) {
 		<para>
 		The function returns true if the AOR in the Request-URI is 
 		registered, false otherwise.  The function does not modify the 
-		message being process, it neither rewrites the Request-URI if a 
+		message being processed, it neither rewrites the Request-URI if a 
 		contact is found not append branches.
 		</para>
 		<para>Meaning of the parameters is as follows:</para>
@@ -842,6 +842,45 @@ if (registered("location")) {
 
 	<section>
 		<title>
+		<function moreinfo="none">registered(domain, uri)</function>
+		</title>
+		<para>
+		The function returns true if the provided URI is 
+		registered, false otherwise. 
+		The function does not modify the 
+		message being processed, it neither rewrites the Request-URI if a 
+		contact is found not append branches.
+		</para>
+		<para>Meaning of the parameters is as follows:</para>
+		<itemizedlist>
+		<listitem>
+			<para>
+			<emphasis>domain</emphasis> - Name of table that should be 
+			used for the lookup.
+			</para>
+			<para>
+			<emphasis>uri</emphasis> - URI used for lookup
+			</para>
+		</listitem>
+		</itemizedlist>
+		<para>
+		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
+		</para>
+		<example>
+		<title><function>registered</function> usage</title>
+		<programlisting format="linespecific">
+...
+if (!registered("location", "$fu")) {
+	sl_send_reply("407", "You must register first");
+	...
+};
+...
+</programlisting>
+		</example>
+	</section>
+
+	<section>
+		<title>
 		<function moreinfo="none">add_sock_hdr(hdr_name)</function>
 		</title>
 		<para>
diff --git a/modules_k/registrar/lookup.c b/modules_k/registrar/lookup.c
index cfab8d6..4f18944 100644
--- a/modules_k/registrar/lookup.c
+++ b/modules_k/registrar/lookup.c
@@ -47,6 +47,8 @@
 #include "lookup.h"
 #include "config.h"
 
+#include "../../mod_fix.h"
+
 #define allowed_method(_msg, _c) \
 	( !method_filtering || ((_msg)->REQ_METHOD)&((_c)->methods) )
 
@@ -181,7 +183,7 @@ done:
  * it is similar to lookup but registered neither rewrites
  * the Request-URI nor appends branches
  */
-int registered(struct sip_msg* _m, char* _t, char* _s)
+int r_registered(struct sip_msg* _m, char* _t, str * _uri)
 {
 	str uri, aor;
 	urecord_t* r;
@@ -189,7 +191,8 @@ int registered(struct sip_msg* _m, char* _t, char* _s)
 	int res;
 	int_str match_callid=(int_str)0;
 
-	if (_m->new_uri.s) uri = _m->new_uri;
+	if (_uri) uri = *_uri;
+	else if (_m->new_uri.s) uri = _m->new_uri;
 	else uri = _m->first_line.u.request.uri;
 	
 	if (extract_aor(&uri, &aor) < 0) {
@@ -235,3 +238,33 @@ int registered(struct sip_msg* _m, char* _t, char* _s)
 	LM_DBG("'%.*s' not found in usrloc\n", aor.len, ZSW(aor.s));
 	return -1;
 }
+
+/*! \brief the is_registered() function
+ * Return true if the AOR in the Request-URI is registered,
+ * it is similar to lookup but registered neither rewrites
+ * the Request-URI nor appends branches
+ */
+int registered(struct sip_msg* _m, char* _t, char* _s)
+{
+	return r_registered(_m, _t, 0);
+}
+
+/*! \brief the is_registered() function
+ * Return true if the AOR in the second Parameter ist registered.
+ */
+int registered2(struct sip_msg* _m, char* _t, char* _uri)
+{
+	str uri;
+	if(fixup_get_svalue(_m, (gparam_p)_uri, &uri)!=0)
+	{
+		LM_ERR("unable to get URI\n");
+		return -1;
+	}
+	if(uri.s==NULL || uri.len == 0)
+	{
+		LM_ERR("invalid URI parameter\n");
+		return -1;
+	}
+	return r_registered(_m, _t, &uri);
+}
+
diff --git a/modules_k/registrar/lookup.h b/modules_k/registrar/lookup.h
index 2cafbbf..2afdfa7 100644
--- a/modules_k/registrar/lookup.h
+++ b/modules_k/registrar/lookup.h
@@ -49,5 +49,10 @@ int lookup(struct sip_msg* _m, udomain_t* _d);
  */
 int registered(struct sip_msg* _m, char* _t, char* _s);
 
+/*! \brief the is_registered() function
+ * Return true if the AOR in the second Parameter ist registered.
+ */
+int registered2(struct sip_msg* _m, char* _t, char* _uri);
+
 
 #endif /* LOOKUP_H */
diff --git a/modules_k/registrar/reg_mod.c b/modules_k/registrar/reg_mod.c
index db8e43f..f84a8f7 100644
--- a/modules_k/registrar/reg_mod.c
+++ b/modules_k/registrar/reg_mod.c
@@ -93,11 +93,13 @@ static int w_lookup(struct sip_msg* _m, char* _d, char* _p2);
 /*! \brief Fixup functions */
 static int domain_fixup(void** param, int param_no);
 static int save_fixup(void** param, int param_no);
-static int unreg_fixup(void** param, int param_no);
+static int reg_fixup(void** param, int param_no);
 static int fetchc_fixup(void** param, int param_no);
 /*! \brief Functions */
 static int add_sock_hdr(struct sip_msg* msg, char *str, char *foo);
 
+static int reg_avp_param(modparam_t type, void* val);
+
 int tcp_persistent_flag = -1;			/*!< if the TCP connection should be kept open */
 int method_filtering = 0;			/*!< if the looked up contacts should be filtered based on supported methods */
 int path_enabled = 0;				/*!< if the Path HF should be handled */
@@ -162,9 +164,11 @@ static cmd_export_t cmds[] = {
 			REQUEST_ROUTE | FAILURE_ROUTE },
 	{"registered",   (cmd_function)registered,   1,  domain_fixup, 0,
 			REQUEST_ROUTE | FAILURE_ROUTE },
+	{"registered",   (cmd_function)registered2,  2,  reg_fixup, 0,
+			REQUEST_ROUTE | FAILURE_ROUTE },
 	{"add_sock_hdr", (cmd_function)add_sock_hdr, 1,fixup_str_null, 0,
 			REQUEST_ROUTE },
-	{"unregister",   (cmd_function)unregister,   2,   unreg_fixup, 0,
+	{"unregister",   (cmd_function)unregister,   2,   reg_fixup, 0,
 			REQUEST_ROUTE| FAILURE_ROUTE },
 	{"reg_fetch_contacts", (cmd_function)pv_fetch_contacts, 3, 
 			fetchc_fixup, 0,
@@ -203,6 +207,7 @@ static param_export_t params[] = {
 	{"use_path",           INT_PARAM, &path_enabled        					},
 	{"path_mode",          INT_PARAM, &path_mode           					},
 	{"path_use_received",  INT_PARAM, &path_use_params     					},
+	{"reg_avp",            STR_PARAM|USE_FUNC_PARAM, (void*)reg_avp_param},
 	{0, 0, 0}
 };
 
@@ -427,7 +432,7 @@ static int domain_fixup(void** param, int param_no)
  * Convert char* parameter to udomain_t* pointer
  * Convert char* parameter to pv_elem_t* pointer
  */
-static int unreg_fixup(void** param, int param_no)
+static int reg_fixup(void** param, int param_no)
 {
 	if (param_no == 1) {
 		return domain_fixup(param, 1);
diff --git a/modules_k/registrar/reg_mod.h b/modules_k/registrar/reg_mod.h
index 7355f8b..2ac81c4 100644
--- a/modules_k/registrar/reg_mod.h
+++ b/modules_k/registrar/reg_mod.h
@@ -98,4 +98,15 @@ extern stat_var *rejected_registrations;
 extern stat_var *default_expire_stat;
 extern stat_var *max_expires_stat;
 
+int_str billing_cust_limit_2_avp_name;
+unsigned short billing_cust_limit_2_avp_type;
+
+/*! \brief Structure to handle the AVPs to be stored to a contact */
+struct reg_avp {
+	int_str avp_name;
+	unsigned short type;
+	struct reg_avp* next;
+};
+struct reg_avp * reg_avp_list;
+
 #endif /* REG_MOD_H */




More information about the sr-dev mailing list