Skip to content

Commit

Permalink
b2b_entities: make 'reason' param mandatory for ua_session_reply
Browse files Browse the repository at this point in the history
Omiting the 'reason' parameter for the ua_session_reply MI command would
cause a crash in the tm module.
  • Loading branch information
rvlad-patrascu committed May 31, 2023
1 parent 2847160 commit 19b6d3e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
7 changes: 1 addition & 6 deletions modules/b2b_entities/b2b_entities.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static const param_export_t params[]={
/* mandatory parameters */
#define UA_START_MI_PARAMS "ruri", "to", "from"
#define UA_UPDATE_MI_PARAMS "key", "method"
#define UA_REPLY_MI_PARAMS "key", "method", "code"
#define UA_REPLY_MI_PARAMS "key", "method", "code", "reason"

static const mi_export_t mi_cmds[] = {
{ "b2be_list", 0,0,0,{
Expand Down Expand Up @@ -250,15 +250,10 @@ static const mi_export_t mi_cmds[] = {
},
{ "ua_session_reply", 0, 0, 0, {
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, 0}},
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, "reason", 0}},
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, "body", 0}},
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, "extra_headers", 0}},
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, "reason", "body", 0}},
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, "reason", "extra_headers", 0}},
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, "body", "content_type", 0}},
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, "body", "extra_headers", 0}},
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, "reason", "body", "content_type", 0}},
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, "reason", "body", "extra_headers", 0}},
{b2b_ua_mi_reply, {UA_REPLY_MI_PARAMS, "body", "content_type",
"extra_headers", 0}},
{EMPTY_MI_RECIPE}}
Expand Down
2 changes: 1 addition & 1 deletion modules/b2b_entities/doc/b2b_entities_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ opensips-cli -x mi ua_session_update key=B2B.436.1925389.1649338095 method=OPTIO
<emphasis>code </emphasis> - reply code
</para></listitem>
<listitem><para>
<emphasis>reason (optional)</emphasis> - reply reason string
<emphasis>reason</emphasis> - reply reason string
</para></listitem>
<listitem><para>
<emphasis>body (optional)</emphasis> - body to include in the
Expand Down
16 changes: 4 additions & 12 deletions modules/b2b_entities/ua_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,16 +1035,9 @@ mi_response_t *b2b_ua_mi_reply(const mi_params_t *params,
return init_mi_param_error();
if (get_mi_int_param(params, "code", &code) < 0)
return init_mi_param_error();

switch (try_get_mi_string_param(params, "reason", &reason.s, &reason.len)) {
case 0:
break;
case -1:
reason.s = NULL;
break;
default:
if (get_mi_string_param(params, "reason", &reason.s, &reason.len) < 0)
return init_mi_param_error();
}

switch (try_get_mi_string_param(params, "body", &body.s, &body.len)) {
case 0:
break;
Expand Down Expand Up @@ -1077,9 +1070,8 @@ mi_response_t *b2b_ua_mi_reply(const mi_params_t *params,

parse_method(method.s, method.s+method.len, &method_value);

if (ua_send_reply(B2B_NONE, &key, method_value, code,
reason.s?&reason:NULL, body.s?&body:NULL,
content_type.s?&content_type:NULL,
if (ua_send_reply(B2B_NONE, &key, method_value, code, &reason,
body.s?&body:NULL, content_type.s?&content_type:NULL,
extra_headers.s?&extra_headers:NULL) < 0) {
LM_ERR("Failed to send reply\n");
return init_mi_error(500, MI_SSTR("Failed to send reply"));
Expand Down

0 comments on commit 19b6d3e

Please sign in to comment.