[sr-dev] git:master: pv: moved in is_int() from utils module

Daniel-Constantin Mierla miconda at gmail.com
Tue Sep 13 11:55:08 CEST 2011


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Tue Sep 13 11:48:49 2011 +0200

pv: moved in is_int() from utils module

- function added by Juha Heinanen in utils module but works on
  pseudo-variables, thus is here is a more appropriate place

---

 modules_k/pv/README           |   46 +++++++++++++++++++++++++++++-----------
 modules_k/pv/doc/pv.xml       |    6 ++++-
 modules_k/pv/doc/pv_admin.xml |   22 +++++++++++++++++++
 modules_k/pv/pv.c             |   22 +++++++++++++++++++
 4 files changed, 82 insertions(+), 14 deletions(-)

diff --git a/modules_k/pv/README b/modules_k/pv/README
index 4485a76..57e824b 100644
--- a/modules_k/pv/README
+++ b/modules_k/pv/README
@@ -11,7 +11,9 @@ Daniel-Constantin Mierla
 
    <daniel at asipto.com>
 
-   Copyright © 2008 Daniel-Constantin Mierla (asipto.com)
+   Copyright © 2008-2011 Daniel-Constantin Mierla (asipto.com)
+
+   Copyright © 2011 Juha Heinanen
      __________________________________________________________________
 
    Table of Contents
@@ -34,6 +36,7 @@ Daniel-Constantin Mierla
 
               4.1. pv_isset(pvar)
               4.2. pv_unset(pvar)
+              4.3. is_int(pvar)
 
         5. MI Commands
 
@@ -47,8 +50,9 @@ Daniel-Constantin Mierla
    1.3. avp_aliases parameter usage
    1.4. pv_isset usage
    1.5. pv_unset usage
-   1.6. shv_set usage
-   1.7. shv_get usage
+   1.6. is_int() usage
+   1.7. shv_set usage
+   1.8. shv_get usage
 
 Chapter 1. Admin Guide
 
@@ -70,6 +74,7 @@ Chapter 1. Admin Guide
 
         4.1. pv_isset(pvar)
         4.2. pv_unset(pvar)
+        4.3. is_int(pvar)
 
    5. MI Commands
 
@@ -113,11 +118,11 @@ Chapter 1. Admin Guide
    _value_
      * _name_: shared variable name
      * _type_: type of the value
-          + “i”: integer value
-          + “s”: string value
+          + "i": integer value
+          + "s": string value
      * _value_: value to be set
 
-   Default value is “NULL”.
+   Default value is "NULL".
 
    Example 1.1. shvset parameter usage
 ...
@@ -134,11 +139,11 @@ modparam("pv", "shvset", "pstngw=s:sip:10.10.10.10")
    _value_
      * _name_: shared variable name
      * _type_: type of the value
-          + “i”: integer value
-          + “s”: string value
+          + "i": integer value
+          + "s": string value
      * _value_: value to be set
 
-   Default value is “NULL”.
+   Default value is "NULL".
 
    Example 1.2. varset parameter usage
 ...
@@ -161,6 +166,7 @@ modparam("pv","avp_aliases","email=s:email_addr;tmp=i:100")
 
    4.1. pv_isset(pvar)
    4.2. pv_unset(pvar)
+   4.3. is_int(pvar)
 
 4.1. pv_isset(pvar)
 
@@ -193,6 +199,20 @@ if(pv_isset("$avp("s:x")"))
 pv_unset("$avp("s:x")");
 ...
 
+4.3. is_int(pvar)
+
+   Function checks if pvar argument contains integer value and returns 1
+   if it does and -1 otherwise.
+
+   Function can be used from all kinds of routes.
+
+   Example 1.6. is_int() usage
+...
+if (is_int("$var(foo)")) {
+    xlog("L_INFO", "variable foo contains integer value\n");
+}
+...
+
 5. MI Commands
 
    5.1. shv_set
@@ -205,8 +225,8 @@ pv_unset("$avp("s:x")");
    Parameters:
      * _name_: shared variable name
      * _type_: type of the value
-          + “int”: integer value
-          + “str”: string value
+          + "int": integer value
+          + "str": string value
      * _value_: value to be set
 
    MI FIFO Command Format:
@@ -216,7 +236,7 @@ pv_unset("$avp("s:x")");
                 _value_
                 _empty_line_
 
-   Example 1.6. shv_set usage
+   Example 1.7. shv_set usage
 ...
 $ kamctl fifo shv_set debug int 0
 ...
@@ -234,7 +254,7 @@ $ kamctl fifo shv_set debug int 0
                 _name_
                 _empty_line_
 
-   Example 1.7. shv_get usage
+   Example 1.8. shv_get usage
 ...
 $ kamctl fifo shv_get debug
 $ kamctl fifo shv_get
diff --git a/modules_k/pv/doc/pv.xml b/modules_k/pv/doc/pv.xml
index c082b99..1ca758a 100644
--- a/modules_k/pv/doc/pv.xml
+++ b/modules_k/pv/doc/pv.xml
@@ -31,9 +31,13 @@
 	    </editor>
 	</authorgroup>
 	<copyright>
-	    <year>2008</year>
+	    <year>2008-2011</year>
 	    <holder>Daniel-Constantin Mierla (asipto.com)</holder>
 	</copyright>
+	<copyright>
+	    <year>2011</year>
+	    <holder>Juha Heinanen</holder>
+	</copyright>
     </bookinfo>
     <toc></toc>
     
diff --git a/modules_k/pv/doc/pv_admin.xml b/modules_k/pv/doc/pv_admin.xml
index 86da6ec..7d56850 100644
--- a/modules_k/pv/doc/pv_admin.xml
+++ b/modules_k/pv/doc/pv_admin.xml
@@ -199,6 +199,28 @@ pv_unset("$avp("s:x")");
 </programlisting>
 		</example>
 		</section>
+		<section>
+			<title>
+				<function moreinfo="none">is_int(pvar)</function>
+			</title>
+			<para>
+			Function checks if pvar argument contains integer value
+			and returns 1 if it does and -1 otherwise.
+	    	        </para>
+			<para>
+			Function can be used from all kinds of routes.
+			</para>
+			<example>
+				<title><function>is_int()</function> usage</title>
+				<programlisting format="linespecific">
+...
+if (is_int("$var(foo)")) {
+    xlog("L_INFO", "variable foo contains integer value\n");
+}
+...
+				</programlisting>
+			</example>
+		</section>
 	</section>
 
 	<section>
diff --git a/modules_k/pv/pv.c b/modules_k/pv/pv.c
index 3beb7bc..c195a06 100644
--- a/modules_k/pv/pv.c
+++ b/modules_k/pv/pv.c
@@ -419,6 +419,7 @@ static int mod_init(void);
 static void mod_destroy(void);
 static int pv_isset(struct sip_msg* msg, char* pvid, char *foo);
 static int pv_unset(struct sip_msg* msg, char* pvid, char *foo);
+static int is_int(struct sip_msg* msg, char* pvar, char* s2);
 
 static cmd_export_t cmds[]={
 	{"pv_isset",  (cmd_function)pv_isset,  1, fixup_pvar_null, 0, 
@@ -429,6 +430,9 @@ static cmd_export_t cmds[]={
 	{"pv_xavp_print",  (cmd_function)pv_xavp_print,  0, 0, 0, 
 		ANY_ROUTE },
 #endif
+	{"is_int", (cmd_function)is_int, 1, fixup_pvar_null, fixup_free_pvar_null,
+		ANY_ROUTE},
+
 	{0,0,0,0,0,0}
 };
 
@@ -509,3 +513,21 @@ static int add_avp_aliases(modparam_t type, void* val)
 	return 0;
 }
 
+/**
+ * Copyright (C) 2011 Juha Heinanen
+ *
+ * Checks if pvar argument contains int value
+ */
+static int is_int(struct sip_msg* msg, char* pvar, char* s2)
+{
+	pv_spec_t *pvar_sp;
+	pv_value_t pv_val;
+
+	pvar_sp = (pv_spec_t *)pvar;
+
+	if (pvar_sp && (pv_get_spec_value(msg, pvar_sp, &pv_val) == 0)) {
+		return (pv_val.flags & PV_VAL_INT)?1:-1;
+	}
+
+	return -1;
+}




More information about the sr-dev mailing list