Browse code

posops: added idx0 mod param

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

Daniel-Constantin Mierla authored on 21/09/2021 08:23:53
Showing 2 changed files
... ...
@@ -54,6 +54,31 @@
54 54
 	</section>
55 55
 	</section>
56 56
 
57
+	<section>
58
+	<title>Parameters</title>
59
+	<section id="posops.p.idx0">
60
+		<title><varname>idx0</varname> (int)</title>
61
+		<para>
62
+			The value to return by functions seeking a position when the index
63
+			is 0 (note: returning 0 is stopping the execution of configuration
64
+			file like 'exit', but for KEMI usage it is ok).
65
+		</para>
66
+		<para>
67
+		<emphasis>
68
+			Default value is -255.
69
+		</emphasis>
70
+		</para>
71
+		<example>
72
+		<title>Set <varname>idx0</varname> parameter</title>
73
+		<programlisting format="linespecific">
74
+...
75
+modparam("posops", "idx0", -200)
76
+...
77
+</programlisting>
78
+		</example>
79
+	</section>
80
+	</section>
81
+
57 82
 	<section>
58 83
 	<title>Functions</title>
59 84
 		<section id="posops.f.pos_append">
... ...
@@ -51,6 +51,8 @@ typedef struct posops_data {
51 51
 	int idx;
52 52
 } posops_data_t;
53 53
 
54
+static int posops_idx0 = -255;
55
+
54 56
 static int pv_posops_get_pos(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
55 57
 static int pv_posops_parse_pos_name(pv_spec_t *sp, str *in);
56 58
 
... ...
@@ -87,6 +89,7 @@ static cmd_export_t cmds[]={
87 89
 };
88 90
 
89 91
 static param_export_t params[]={
92
+	{"idx0",     PARAM_INT,   &posops_idx0},
90 93
 
91 94
 	{0, 0, 0}
92 95
 };
... ...
@@ -309,7 +312,7 @@ static int ki_posops_pos_headers_start(sip_msg_t* msg)
309 312
 	}
310 313
 
311 314
 	_posops_data.idx = msg->first_line.len;
312
-	_posops_data.ret = (_posops_data.idx==0)?-255:_posops_data.idx;
315
+	_posops_data.ret = (_posops_data.idx==0)?posops_idx0:_posops_data.idx;
313 316
 
314 317
 	return _posops_data.ret;
315 318
 }
... ...
@@ -334,7 +337,7 @@ static int ki_posops_pos_headers_end(sip_msg_t* msg)
334 337
 	}
335 338
 
336 339
 	_posops_data.idx = msg->unparsed - msg->buf;
337
-	_posops_data.ret = (_posops_data.idx==0)?-255:_posops_data.idx;
340
+	_posops_data.ret = (_posops_data.idx==0)?posops_idx0:_posops_data.idx;
338 341
 
339 342
 	return _posops_data.ret;
340 343
 }
... ...
@@ -367,7 +370,7 @@ static int ki_posops_pos_body_start(sip_msg_t* msg)
367 370
 	}
368 371
 	_posops_data.idx = body - msg->buf;
369 372
 
370
-	_posops_data.ret = (_posops_data.idx==0)?-255:_posops_data.idx;
373
+	_posops_data.ret = (_posops_data.idx==0)?posops_idx0:_posops_data.idx;
371 374
 
372 375
 	return _posops_data.ret;
373 376
 }
... ...
@@ -397,7 +400,7 @@ static int ki_posops_pos_body_end(sip_msg_t* msg)
397 400
 	}
398 401
 
399 402
 	_posops_data.idx = msg->len;
400
-	_posops_data.ret = (_posops_data.idx==0)?-255:_posops_data.idx;
403
+	_posops_data.ret = (_posops_data.idx==0)?posops_idx0:_posops_data.idx;
401 404
 
402 405
 	return _posops_data.ret;
403 406
 }