Skip to content

Commit

Permalink
posops: added idx0 mod param
Browse files Browse the repository at this point in the history
- set the value to return by function when position is at index 0
- default -255
  • Loading branch information
miconda committed Sep 21, 2021
1 parent 10b014b commit 771ce94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/modules/posops/doc/posops_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
11 changes: 7 additions & 4 deletions src/modules/posops/posops_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -87,6 +89,7 @@ static cmd_export_t cmds[]={
};

static param_export_t params[]={
{"idx0", PARAM_INT, &posops_idx0},

{0, 0, 0}
};
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 771ce94

Please sign in to comment.