Skip to content

Commit

Permalink
dialog: Improvements to recent set/unset profile additions
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed May 17, 2023
1 parent 1421afc commit e0bdf59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
24 changes: 7 additions & 17 deletions modules/dialog/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static int w_match_dialog(struct sip_msg *msg, void *seq_match_mode_val);
static int api_match_dialog(struct sip_msg *msg, int _seq_match_mode);
static int w_validate_dialog(struct sip_msg*);
static int w_fix_route_dialog(struct sip_msg*);
static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value, str *remove_value);
static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value, int *clear_values);
static int w_unset_dlg_profile(struct sip_msg *msg, str *prof_name, str *value);
static int w_is_in_profile(struct sip_msg *msg, str *prof_name, str *value);
static int w_get_profile_size(struct sip_msg *msg, str *prof_name,
Expand Down Expand Up @@ -189,7 +189,7 @@ static const cmd_export_t cmds[]={
{"set_dlg_profile", (cmd_function)w_set_dlg_profile, {
{CMD_PARAM_STR,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}},
{CMD_PARAM_INT|CMD_PARAM_OPT,0,0}, {0,0,0}},
REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE},
{"unset_dlg_profile", (cmd_function)w_unset_dlg_profile, {
{CMD_PARAM_STR,0,0},
Expand Down Expand Up @@ -1127,7 +1127,7 @@ static int w_fix_route_dialog(struct sip_msg *req)
}


static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value, str *remove_value)
static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value, int *clear_values)
{
struct dlg_cell *dlg;
struct dlg_profile_table *profile;
Expand All @@ -1149,15 +1149,10 @@ static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value, st
return -1;
}

if (remove_value) {
if (remove_value->len == 0) {
if (unset_dlg_profile_all_values(dlg, profile) < 0) {
LM_DBG("dialog not found in profile %.*s\n",
prof_name->len, prof_name->s);
}
} else if (unset_dlg_profile( dlg, remove_value, profile) < 0) {
LM_WARN("dialog not found in profile %.*s with value %.*s\n",
prof_name->len, prof_name->s, remove_value->len, remove_value->s);
if (clear_values && *clear_values) {
if (unset_dlg_profile_all_values(dlg, profile) < 0) {
LM_DBG("dialog not found in profile %.*s\n",
prof_name->len, prof_name->s);
}
}

Expand Down Expand Up @@ -1193,11 +1188,6 @@ static int w_unset_dlg_profile(struct sip_msg *msg, str *prof_name, str *value)

if (profile->has_value) {
if (!value) {
LM_WARN("missing value\n");
return -1;
}

if (value->len == 0) {
if (unset_dlg_profile_all_values(dlg, profile) < 0) {
LM_DBG("dialog not found in profile %.*s\n",
prof_name->len, prof_name->s);
Expand Down
35 changes: 18 additions & 17 deletions modules/dialog/doc/dialog_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ if (load_dialog_ctx("$var(callid)")) {

<section id="func_set_dlg_profile" xreflabel="set_dlg_profile()">
<title>
<function moreinfo="none">set_dlg_profile(profile,[value],[remove_value])</function>
<function moreinfo="none">set_dlg_profile(profile, [value], [clear_values])</function>
</title>
<para>
Inserts the current dialog into a profile. Note that if the profile does
Expand All @@ -1976,9 +1976,9 @@ if (load_dialog_ctx("$var(callid)")) {
</para>
</listitem>
<listitem>
<para><emphasis>remove_value (string, optional)</emphasis> - optional profile value
to remove before setting the new value. If it is an empty string ("") all values for the profile
will be removed before setting the new value.
<para><emphasis>clear_values (boolean, optional)</emphasis> - if set to
<emphasis>true</emphasis> (1), all values of the profile will be cleared
before setting the given value. Default: <emphasis>false</emphasis>.
</para>
</listitem>
</itemizedlist>
Expand All @@ -1991,13 +1991,12 @@ if (load_dialog_ctx("$var(callid)")) {
<programlisting format="linespecific">
...
set_dlg_profile("inboundCall");
set_dlg_profile("caller",$fu);
...
#Set a new value while removing an old value
set_dlg_profile("caller",$fu,$var(old_fu));
...
#Set a new value while removing all old values
set_dlg_profile("caller",$fu,"");

# Set a new value (all other values are kept intact)
set_dlg_profile("caller", $fu);

# Set a new value while removing all previous values
set_dlg_profile("caller", $fu, true);
...
</programlisting>
</example>
Expand All @@ -2006,7 +2005,7 @@ set_dlg_profile("caller",$fu,"");

<section id="func_unset_dlg_profile" xreflabel="unset_dlg_profile()">
<title>
<function moreinfo="none">unset_dlg_profile(profile,[value],[remove_all])</function>
<function moreinfo="none">unset_dlg_profile(profile, [value])</function>
</title>
<para>
Removes the current dialog from a profile.
Expand All @@ -2025,8 +2024,10 @@ set_dlg_profile("caller",$fu,"");
<listitem>
<para><emphasis>value (string, optional)</emphasis> - string value to
define the belonging of the dialog to the profile - note that the
profile must support values. If set to an empty string ("") all values for
the profile will be removed.
profile must support values.
</para>
<para>NEW in 3.4: for profiles with value, by omitting this parameter
you can now clear all values of the given profile.
</para>
</listitem>
</itemizedlist>
Expand All @@ -2039,10 +2040,10 @@ set_dlg_profile("caller",$fu,"");
<programlisting format="linespecific">
...
unset_dlg_profile("inboundCall");
unset_dlg_profile("caller",$fu);
unset_dlg_profile("caller", $fu);
...
#Remove all values in a profile
unset_dlg_profile("caller","");
# Remove all values in a profile
unset_dlg_profile("caller");
...
</programlisting>
</example>
Expand Down

0 comments on commit e0bdf59

Please sign in to comment.