Module: kamailio
Branch: master
Commit: 771ce9436adb250a398e1fd337e712c0d5c67745
URL: 
https://github.com/kamailio/kamailio/commit/771ce9436adb250a398e1fd337e712c0d5c67745

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2021-09-21T10:23:53+02:00

posops: added idx0 mod param

- set the value to return by function when position is at index 0
- default -255

---

Modified: src/modules/posops/doc/posops_admin.xml
Modified: src/modules/posops/posops_mod.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/771ce9436adb250a398e1fd337e712c0d5c67745.diff
Patch: 
https://github.com/kamailio/kamailio/commit/771ce9436adb250a398e1fd337e712c0d5c67745.patch

---

diff --git a/src/modules/posops/doc/posops_admin.xml 
b/src/modules/posops/doc/posops_admin.xml
index 9e532d7bf3..4628b0cb29 100644
--- a/src/modules/posops/doc/posops_admin.xml
+++ b/src/modules/posops/doc/posops_admin.xml
@@ -54,6 +54,31 @@
        </section>
        </section>
 
+       <section>
+       <title>Parameters</title>
+       <section id="posops.p.idx0">
+               <title><varname>idx0</varname> (int)</title>
+               <para>
+                       The value to return by functions seeking a position 
when the index
+                       is 0 (note: returning 0 is stopping the execution of 
configuration
+                       file like 'exit', but for KEMI usage it is ok).
+               </para>
+               <para>
+               <emphasis>
+                       Default value is -255.
+               </emphasis>
+               </para>
+               <example>
+               <title>Set <varname>idx0</varname> parameter</title>
+               <programlisting format="linespecific">
+...
+modparam("posops", "idx0", -200)
+...
+</programlisting>
+               </example>
+       </section>
+       </section>
+
        <section>
        <title>Functions</title>
                <section id="posops.f.pos_append">
diff --git a/src/modules/posops/posops_mod.c b/src/modules/posops/posops_mod.c
index fc62679afd..3a8746a2a5 100644
--- a/src/modules/posops/posops_mod.c
+++ b/src/modules/posops/posops_mod.c
@@ -51,6 +51,8 @@ typedef struct posops_data {
        int idx;
 } posops_data_t;
 
+static int posops_idx0 = -255;
+
 static int pv_posops_get_pos(sip_msg_t *msg, pv_param_t *param, pv_value_t 
*res);
 static int pv_posops_parse_pos_name(pv_spec_t *sp, str *in);
 
@@ -87,6 +89,7 @@ static cmd_export_t cmds[]={
 };
 
 static param_export_t params[]={
+       {"idx0",     PARAM_INT,   &posops_idx0},
 
        {0, 0, 0}
 };
@@ -309,7 +312,7 @@ static int ki_posops_pos_headers_start(sip_msg_t* msg)
        }
 
        _posops_data.idx = msg->first_line.len;
-       _posops_data.ret = (_posops_data.idx==0)?-255:_posops_data.idx;
+       _posops_data.ret = (_posops_data.idx==0)?posops_idx0:_posops_data.idx;
 
        return _posops_data.ret;
 }
@@ -334,7 +337,7 @@ static int ki_posops_pos_headers_end(sip_msg_t* msg)
        }
 
        _posops_data.idx = msg->unparsed - msg->buf;
-       _posops_data.ret = (_posops_data.idx==0)?-255:_posops_data.idx;
+       _posops_data.ret = (_posops_data.idx==0)?posops_idx0:_posops_data.idx;
 
        return _posops_data.ret;
 }
@@ -367,7 +370,7 @@ static int ki_posops_pos_body_start(sip_msg_t* msg)
        }
        _posops_data.idx = body - msg->buf;
 
-       _posops_data.ret = (_posops_data.idx==0)?-255:_posops_data.idx;
+       _posops_data.ret = (_posops_data.idx==0)?posops_idx0:_posops_data.idx;
 
        return _posops_data.ret;
 }
@@ -397,7 +400,7 @@ static int ki_posops_pos_body_end(sip_msg_t* msg)
        }
 
        _posops_data.idx = msg->len;
-       _posops_data.ret = (_posops_data.idx==0)?-255:_posops_data.idx;
+       _posops_data.ret = (_posops_data.idx==0)?posops_idx0:_posops_data.idx;
 
        return _posops_data.ret;
 }


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to