[sr-dev] git:master:45479865: siputils: add is_uri function
lazedo
luis.azedo at factorlusitano.com
Fri Oct 5 07:19:33 CEST 2018
Module: kamailio
Branch: master
Commit: 454798654c2b2acd252df411d64e55bee0a70f52
URL: https://github.com/kamailio/kamailio/commit/454798654c2b2acd252df411d64e55bee0a70f52
Author: lazedo <luis.azedo at factorlusitano.com>
Committer: lazedo <luis.azedo at factorlusitano.com>
Date: 2018-10-04T12:40:11Z
siputils: add is_uri function
---
Modified: src/modules/siputils/checks.c
Modified: src/modules/siputils/checks.h
Modified: src/modules/siputils/doc/siputils_admin.xml
Modified: src/modules/siputils/siputils.c
---
Diff: https://github.com/kamailio/kamailio/commit/454798654c2b2acd252df411d64e55bee0a70f52.diff
Patch: https://github.com/kamailio/kamailio/commit/454798654c2b2acd252df411d64e55bee0a70f52.patch
---
diff --git a/src/modules/siputils/checks.c b/src/modules/siputils/checks.c
index 0a33bddbd6..b700c620c0 100644
--- a/src/modules/siputils/checks.c
+++ b/src/modules/siputils/checks.c
@@ -129,6 +129,37 @@ int w_has_totag(struct sip_msg* _m, char* _foo, char* _bar)
return has_totag(_m);
}
+/*
+ * Check if pseudo variable contains a valid uri
+ */
+int is_uri(struct sip_msg* _m, char* _sp, char* _s2)
+{
+ pv_spec_t *sp;
+ pv_value_t pv_val;
+ sip_uri_t turi;
+
+ sp = (pv_spec_t *)_sp;
+
+ if (sp && (pv_get_spec_value(_m, sp, &pv_val) == 0)) {
+ if (pv_val.flags & PV_VAL_STR) {
+ if (pv_val.rs.len == 0 || pv_val.rs.s == NULL) {
+ LM_DBG("missing argument\n");
+ return -1;
+ }
+ if(parse_uri(pv_val.rs.s, pv_val.rs.len, &turi)!=0) {
+ return -1;
+ }
+ return 1;
+ } else {
+ LM_ERR("pseudo variable value is not string\n");
+ return -1;
+ }
+ } else {
+ LM_ERR("failed to get pseudo variable value\n");
+ return -1;
+ }
+}
+
/*
* Check if the username matches the username in credentials
*/
diff --git a/src/modules/siputils/checks.h b/src/modules/siputils/checks.h
index 39a575d94c..a9186386a2 100644
--- a/src/modules/siputils/checks.h
+++ b/src/modules/siputils/checks.h
@@ -75,6 +75,10 @@ int add_uri_param(struct sip_msg* _msg, char* _param, char* _s2);
*/
int tel2sip(struct sip_msg* _msg, char* _uri, char* _hostpart, char* _res);
+/*
+ * Check if pseudo variable contains a valid uri
+ */
+int is_uri(struct sip_msg* _m, char* _sp, char* _s2);
/*
* Check if user part of URI in pseudo variable is an e164 number
diff --git a/src/modules/siputils/doc/siputils_admin.xml b/src/modules/siputils/doc/siputils_admin.xml
index a882c3b069..58dd81adcf 100644
--- a/src/modules/siputils/doc/siputils_admin.xml
+++ b/src/modules/siputils/doc/siputils_admin.xml
@@ -608,6 +608,33 @@ if (is_uri_user_e164("$avp(i:705)") {
</example>
</section>
+ <section id="siputils.f.is_uri">
+ <title>
+ <function moreinfo="none">is_uri(pseudo-variable)</function>
+ </title>
+ <para>
+ Checks if string value of pseudo variable argument is a
+ valid uri.
+ </para>
+ <para>
+ This function can be used from ANY_ROUTE.
+ </para>
+ <example>
+ <title><function>is_uri</function> usage</title>
+ <programlisting format="linespecific">
+...
+if (is_uri("$var(x)")) { # Check if variable contains a uri
+ ...
+}
+if (is_uri("$avp(i:705)") {
+ # Check value stored in avp i:705
+ ...
+};
+...
+</programlisting>
+ </example>
+ </section>
+
<section id="siputils.f.is_tel_number">
<title>
<function moreinfo="none">is_tel_number(tval)</function>
diff --git a/src/modules/siputils/siputils.c b/src/modules/siputils/siputils.c
index af8cb29d4b..50cd7425aa 100644
--- a/src/modules/siputils/siputils.c
+++ b/src/modules/siputils/siputils.c
@@ -137,6 +137,8 @@ static cmd_export_t cmds[]={
free_fixup_get_uri_param, REQUEST_ROUTE|LOCAL_ROUTE},
{"tel2sip", (cmd_function)tel2sip, 3, fixup_tel2sip, 0,
REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE},
+ {"is_uri", (cmd_function)is_uri, 1, fixup_pvar_null,
+ fixup_free_pvar_null, ANY_ROUTE},
{"is_e164", (cmd_function)is_e164, 1, fixup_pvar_null,
fixup_free_pvar_null, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
{"is_uri_user_e164", (cmd_function)w_is_uri_user_e164, 1, fixup_pvar_null,
More information about the sr-dev
mailing list