Skip to content

Commit

Permalink
b2b_logic: replace letter flags with CSV named flags
Browse files Browse the repository at this point in the history
Replace the single letter flags for the b2b_init_request() and
b2b_bridge() script functions with a CSV list of named flags.
  • Loading branch information
rvlad-patrascu committed Apr 26, 2023
1 parent 819eba0 commit 4cfb798
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 75 deletions.
113 changes: 61 additions & 52 deletions modules/b2b_logic/b2b_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "../../timer.h"
#include "../../pt.h"
#include "../../lib/csv.h"
#include "../../mod_fix.h"

#include "records.h"
#include "b2b_logic.h"
Expand Down Expand Up @@ -814,11 +815,23 @@ static int child_init(int rank)
return 0;
}

static str init_request_flags[] =
{
str_init("transparent-auth"), /* B2BL_FLAG_TRANSPARENT_AUTH */
str_init("preserve-to"), /* B2BL_FLAG_TRANSPARENT_TO */
STR_NULL
};
static str init_request_kv_flags[] =
{
str_init("setup-timeout"),
STR_NULL
};

static int fixup_init_flags(void** param)
{
str *s = (str*)*param;
int st;
struct b2b_params *init_params;
str flag_vals[1] = {STR_NULL};

init_params = pkg_malloc(sizeof *init_params);
if (!init_params) {
Expand All @@ -829,33 +842,29 @@ static int fixup_init_flags(void** param)

init_params->init_timeout = b2bl_th_init_timeout;

*param = (void*)init_params;

if (!s)
if (!s) {
*param = (void*)init_params;
return 0;
}

for( st=0 ; st< s->len ; st++ ) {
switch (s->s[st])
{
case 't':
init_params->init_timeout = 0;
while (st<s->len-1 && isdigit(s->s[st+1])) {
init_params->init_timeout =
init_params->init_timeout*10 + s->s[st+1] - '0';
st++;
}
break;
case 'a':
init_params->flags |= B2BL_FLAG_TRANSPARENT_AUTH;
break;
case 'p':
init_params->flags |= B2BL_FLAG_TRANSPARENT_TO;
break;
default:
LM_WARN("unknown option `%c'\n", s->s[st]);
if (fixup_named_flags(param, init_request_flags, init_request_kv_flags,
flag_vals) < 0) {
LM_ERR("Failed to parse flags\n");
return -1;
}

init_params->flags = (unsigned int)(unsigned long)(void*)*param;
*param = (void*)init_params;

if (flag_vals[0].s) {
if (str2int(&flag_vals[0], &init_params->init_timeout) < 0) {
LM_ERR("timeout is not an integer\n");
return -1;
}
}

LM_DBG("DDD flags=%d lifetime=%d\n", init_params->flags, init_params->init_timeout);

return 0;
}

Expand All @@ -867,11 +876,25 @@ static int fixup_free_init_flags(void** param)
return 0;
}

static str bridge_flags[] =
{
str_init("notify"), /* B2BL_BR_FLAG_NOTIFY */
str_init("rollback-failed"), /* B2BL_BR_FLAG_RETURN_AFTER_FAILURE */
str_init("hold"), /* B2BL_BR_FLAG_HOLD */
str_init("no-late-sdp"), /* B2BL_BR_FLAG_RENEW_SDP */
STR_NULL
};
static str bridge_kv_flags[] =
{
str_init("max_duration"),
STR_NULL
};

static int fixup_bridge_flags(void** param)
{
str *s = (str*)*param;
int st;
struct b2b_bridge_params *bridge_params;
str flag_vals[1] = {STR_NULL};

bridge_params = pkg_malloc(sizeof *bridge_params);
if (!bridge_params) {
Expand All @@ -880,37 +903,23 @@ static int fixup_bridge_flags(void** param)
}
memset(bridge_params, 0, sizeof *bridge_params);

bridge_params->lifetime = 0;
if (!s) {
*param = (void*)bridge_params;
return 0;
}

*param = (void*)bridge_params;
if (fixup_named_flags(param, bridge_flags, bridge_kv_flags, flag_vals) < 0) {
LM_ERR("Failed to parse flags\n");
return -1;
}

if (!s)
return 0;
bridge_params->flags = (unsigned int)(unsigned long)(void*)*param;
*param = (void*)bridge_params;

for( st=0 ; st< s->len ; st++ ) {
switch (s->s[st])
{
case 't':
while (st<s->len-1 && isdigit(s->s[st+1])) {
bridge_params->lifetime =
bridge_params->lifetime*10 + s->s[st+1] - '0';
st++;
}
break;
case 'n':
bridge_params->flags |= B2BL_BR_FLAG_NOTIFY;
break;
case 'f':
bridge_params->flags |= B2BL_BR_FLAG_RETURN_AFTER_FAILURE;
break;
case 'h':
bridge_params->flags |= B2BL_BR_FLAG_HOLD;
break;
case 'r':
bridge_params->flags |= B2BL_BR_FLAG_RENEW_SDP;
break;
default:
LM_WARN("unknown option `%c'\n", s->s[st]);
if (flag_vals[0].s) {
if (str2int(&flag_vals[0], &bridge_params->lifetime) < 0) {
LM_ERR("duration is not an integer\n");
return -1;
}
}

Expand Down
6 changes: 3 additions & 3 deletions modules/b2b_logic/b2b_logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ enum b2b_tuple_state {
/* tuple bridge flags */
#define B2BL_BR_FLAG_NOTIFY (1<<0)
#define B2BL_BR_FLAG_RETURN_AFTER_FAILURE (1<<1)
#define B2BL_BR_FLAG_DONT_DELETE_BRIDGE_INITIATOR (1<<2)
#define B2BL_BR_FLAG_HOLD (1<<3)
#define B2BL_BR_FLAG_RENEW_SDP (1<<4)
#define B2BL_BR_FLAG_HOLD (1<<2)
#define B2BL_BR_FLAG_RENEW_SDP (1<<3)
#define B2BL_BR_FLAG_DONT_DELETE_BRIDGE_INITIATOR (1<<4)
#define B2BL_BR_FLAG_PROV_MEDIA (1<<5)
#define B2BL_BR_FLAG_NO_OLD_ENT (1<<6)

Expand Down
43 changes: 23 additions & 20 deletions modules/b2b_logic/doc/b2b_logic_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -530,18 +530,19 @@ modparam("b2b_logic", "b2bl_early_update", 1)
scripting or dedicated routes are required.
</para></listitem>
<listitem><para>
<emphasis>flags (string, optional)</emphasis> - meanings of the flags is as follows:
<emphasis>flags (string, optional)</emphasis> - CSV list of the following flags:
<itemizedlist>
<listitem><para>
<emphasis>t[nn]</emphasis> - Call setup timeout. 0 sets timeout to max_duration value.
Example: t300.
<emphasis>setup-timeout=[nn]</emphasis> - Call setup timeout. 0 sets
timeout to max_duration value. Example: "setup-timeout=300".
</para></listitem>
<listitem><para>
<emphasis>a</emphasis> - Transparent authentication. In this mode b2b passes your 401
or 407 authentication request to destination server.
<emphasis>transparent-auth</emphasis> - Transparent authentication.
In this mode b2b passes your 401 or 407 authentication request to
destination server.
</para></listitem>
<listitem><para>
<emphasis>p</emphasis> - Preserve To: header.
<emphasis>preserve-to</emphasis> - Preserve To: header.
</para></listitem>
</itemizedlist>
</para></listitem>
Expand Down Expand Up @@ -717,31 +718,33 @@ b2b_client_new("client1", "sip:alice@opensips.org");
media server to be connected with the caller while the callee answers.
</para></listitem>
<listitem><para>
<emphasis>flags (string, optional)</emphasis> - meanings of the flags is as follows:
<emphasis>flags (string, optional)</emphasis> - CSV list of the following flags:
<itemizedlist>
<listitem><para>
<emphasis>t[nn]</emphasis> - Maximum duration of the B2B
<emphasis>max_duration=[nn]</emphasis> - Maximum duration of the B2B
session. If the lifetime expires, the B2BUA will send BYE messages to both
ends and delete the record.
Example: t300.
ends and delete the record. Example: "max_duration=300".
</para></listitem>
<listitem><para>
<emphasis>n</emphasis> - Enable rfc3515 NOTIFY to inform the agent sending the
REFER of the status of the reference.
<emphasis>notify</emphasis> - Enable rfc3515 NOTIFY to inform the agent
sending the REFER of the status of the reference.
</para></listitem>
<listitem><para>
<emphasis>f</emphasis> - Rollback call to state before bridging in case of transfer
failed, don't hangup the call (default behaviour).
<emphasis>rollback-failed</emphasis> - Rollback call to state before
bridging in case of transfer failed, don't hangup the call
(default behaviour).
</para></listitem>
<listitem><para>
<emphasis>h</emphasis> - Put the old entity on hold before bridging it to the
new entity.
<emphasis>hold</emphasis> - Put the old entity on hold before bridging
it to the new entity.
</para></listitem>
<listitem><para>
<emphasis>r</emphasis> - Do not attempt late SDP negociation with the new entity.
Start the bridging by first contacting the new entity using the initial SDP received
from the old entity. After the new entity answers, send a reINVITE without body to
the old entity. Use the current SDP received in this new answer from the old entity to trigger a renegociation with the new entity.
<emphasis>no-late-sdp</emphasis> - Do not attempt late SDP negociation
with the new entity. Start the bridging by first contacting the new entity
using the initial SDP received from the old entity. After the new entity
answers, send a reINVITE without body to the old entity. Use the current
SDP received in this new answer from the old entity to trigger a
renegociation with the new entity.
</para></listitem>
</itemizedlist>
</para></listitem>
Expand Down

0 comments on commit 4cfb798

Please sign in to comment.