Skip to content

Commit

Permalink
b2b_entities: trigger the E_UA_SESSION event for initial INVITEs
Browse files Browse the repository at this point in the history
Add ability to trigger the E_UA_SESSION event, with the 'NEW' event
type, for initial INVITES handled with the ua_session_server_init().
This can also be suppressed with the 'n' flag.
  • Loading branch information
rvlad-patrascu committed May 31, 2023
1 parent 3102318 commit fb5b358
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/b2b_entities/doc/b2b_entities_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ modparam("b2b_entities", "ua_default_timeout", 7200)
<emphasis>b</emphasis> - provide the body of the SIP request/reply
in the <xref linkend="event_E_UA_SESSION"/> event.
</para></listitem>
<listitem><para>
<emphasis>n</emphasis> - do not trigger the
<xref linkend="event_E_UA_SESSION"/> event (with event_type
<emphasis>NEW</emphasis>) for initial INVITES
handled with this function.
</para></listitem>
</itemizedlist>
</para></listitem>
</itemizedlist>
Expand Down Expand Up @@ -821,6 +827,11 @@ opensips-cli -x mi ua_session_terminate key=B2B.436.1925389.1649338095
<listitem><para>
<emphasis>event_type</emphasis> - the type of event:
<itemizedlist>
<listitem><para>
<emphasis>NEW</emphasis> - for initial INVITE requests,
handled with the <xref linkend="func_ua_session_server_init"/>
function.
</para></listitem>
<listitem><para>
<emphasis>EARLY</emphasis> - for 1xx provisional
responses
Expand Down
11 changes: 11 additions & 0 deletions modules/b2b_entities/ua_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ static int get_all_headers(struct sip_msg *msg, str *hdrs)

/* indexed with the values from enum ua_sess_event_type */
static str event_type_str[] = {
str_init("NEW"),
str_init("EARLY"),
str_init("ANSWERED"),
str_init("REJECTED"),
Expand Down Expand Up @@ -465,6 +466,9 @@ static struct ua_sess_init_params *ua_parse_flags(str *s)
case 'b':
params->flags |= UA_FL_PROVIDE_BODY;
break;
case 'n':
params->flags |= UA_FL_SUPPRESS_NEW;
break;
default:
LM_WARN("unknown option `%c'\n", s->s[st]);
}
Expand Down Expand Up @@ -801,6 +805,13 @@ int b2b_ua_server_init(struct sip_msg *msg, pv_spec_t *key_spec,
}
}

if (!(init_params->flags&UA_FL_SUPPRESS_NEW) &&
raise_ua_sess_event(key_ret, B2B_SERVER, UA_SESS_EV_NEW,
init_params->flags, msg) < 0) {
LM_ERR("Failed to raise E_UA_SESSION event\n");
goto error;
}

pkg_free(key_ret);

return 1;
Expand Down
2 changes: 2 additions & 0 deletions modules/b2b_entities/ua_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
#define UA_FL_DISABLE_AUTO_ACK (1<<3)
#define UA_FL_PROVIDE_HDRS (1<<4)
#define UA_FL_PROVIDE_BODY (1<<5)
#define UA_FL_SUPPRESS_NEW (1<<6)

#define UA_SESSION_DEFAULT_TIMEOUT (60 * 60 * 12)

enum ua_sess_event_type {
UA_SESS_EV_NEW,
UA_SESS_EV_EARLY,
UA_SESS_EV_ANSWERED,
UA_SESS_EV_REJECTED,
Expand Down

0 comments on commit fb5b358

Please sign in to comment.