Skip to content

Commit

Permalink
[sipmsgops] added append_body_to_reply() function
Browse files Browse the repository at this point in the history
...to add a body to any reply generated by OpenSIPS for the current reply, disregarding if you are using a stateless, statefull or generic send_reply() wrapper for that.
  • Loading branch information
bogdan-iancu committed Jul 24, 2023
1 parent 4de0a54 commit 227852c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
37 changes: 37 additions & 0 deletions modules/sipmsgops/doc/sipmsgops_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,43 @@ append_to_reply("Foo: $rm at $Ts\r\n");
</example>
</section>

<section id="func_append_body_to_reply" xreflabel="append_body_to_reply()">
<title>
<function moreinfo="none">append_body_to_reply(txt)</function>
</title>
<para>
Append 'txt' as body to all replies that will be generated by
OpenSIPS for this request.
</para>
<para>
Multiple calls will override the already set body.
</para>
<para>
NOTE: the function does not add any Content-Type hdr to match the body,
so you should use "append_to_reply()" to do that.
</para>
<para>Meaning of the parameters is as follows:</para>
<itemizedlist>
<listitem>
<para><emphasis>txt (string)</emphasis> - body of the SIP reply
</para>
</listitem>
</itemizedlist>
<para>
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE and ERROR_ROUTE.
</para>
<example>
<title><function>append_to_reply</function> usage</title>
<programlisting format="linespecific">
...
append_body_to_reply( $var(sdp_body) );
...
</programlisting>
</example>
</section>


<section id="func_append_hf" xreflabel="append_hf()">
<title>
<function moreinfo="none">append_hf(txt[, hdr_anchor])</function>
Expand Down
26 changes: 26 additions & 0 deletions modules/sipmsgops/sipmsgops.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static int get_glob_headers_values(struct sip_msg* msg, str* pattern,pv_spec_t*
static int remove_hf_match_f(struct sip_msg* msg, void* pattern, int is_regex);
static int is_present_hf(struct sip_msg* msg, void* _match_hf);
static int append_to_reply_f(struct sip_msg* msg, str* key);
static int append_body_to_reply_f(struct sip_msg* msg, str* key);
static int append_hf(struct sip_msg *msg, str *str1, void *str2);
static int insert_hf(struct sip_msg *msg, str *str1, void *str2);
static int append_urihf(struct sip_msg *msg, str *str1, str *str2);
Expand Down Expand Up @@ -122,6 +123,10 @@ static const cmd_export_t cmds[]={
{CMD_PARAM_STR, 0, 0}, {0, 0, 0}},
REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ERROR_ROUTE},

{"append_body_to_reply", (cmd_function)append_body_to_reply_f, {
{CMD_PARAM_STR, 0, 0}, {0, 0, 0}},
REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ERROR_ROUTE},

{"append_hf", (cmd_function)append_hf, {
{CMD_PARAM_STR, 0, 0},
{CMD_PARAM_STR|CMD_PARAM_OPT, fixup_parse_hname, fixup_free_pkg},
Expand Down Expand Up @@ -542,6 +547,27 @@ static int append_to_reply_f(struct sip_msg* msg, str* key)
}


static int append_body_to_reply_f(struct sip_msg* msg, str* body)
{
struct lump_rpl *l;

l = get_lump_rpl( msg, LUMP_RPL_BODY);
if (l) {
if (replace_lump_rpl(l, body->s, body->len, LUMP_RPL_BODY)!=0) {
LM_ERR("unable to replace existing body lump_rl\n");
return -1;
}
} else {
if (add_lump_rpl( msg, body->s, body->len, LUMP_RPL_BODY)==NULL) {
LM_ERR("unable to create new body lump_rl\n");
return -1;
}
}

return 1;
}


/* add str1 to end of header or str1.r-uri.str2 */

static int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,
Expand Down

0 comments on commit 227852c

Please sign in to comment.