Skip to content

Commit a4c8d9d

Browse files
authored
Merge pull request #3084 from rrb3942/dialog_profile_remove_all
Add options to set_dlg_profile and unset_dlg_profile to remove all values on a profile
2 parents 75a17b4 + e0bdf59 commit a4c8d9d

File tree

4 files changed

+100
-11
lines changed

4 files changed

+100
-11
lines changed

modules/dialog/dialog.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static int w_match_dialog(struct sip_msg *msg, void *seq_match_mode_val);
123123
static int api_match_dialog(struct sip_msg *msg, int _seq_match_mode);
124124
static int w_validate_dialog(struct sip_msg*);
125125
static int w_fix_route_dialog(struct sip_msg*);
126-
static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value);
126+
static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value, int *clear_values);
127127
static int w_unset_dlg_profile(struct sip_msg *msg, str *prof_name, str *value);
128128
static int w_is_in_profile(struct sip_msg *msg, str *prof_name, str *value);
129129
static int w_get_profile_size(struct sip_msg *msg, str *prof_name,
@@ -189,7 +189,8 @@ static const cmd_export_t cmds[]={
189189
REQUEST_ROUTE},
190190
{"set_dlg_profile", (cmd_function)w_set_dlg_profile, {
191191
{CMD_PARAM_STR,0,0},
192-
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}},
192+
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
193+
{CMD_PARAM_INT|CMD_PARAM_OPT,0,0}, {0,0,0}},
193194
REQUEST_ROUTE| FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE},
194195
{"unset_dlg_profile", (cmd_function)w_unset_dlg_profile, {
195196
{CMD_PARAM_STR,0,0},
@@ -1135,7 +1136,7 @@ static int w_fix_route_dialog(struct sip_msg *req)
11351136
}
11361137

11371138

1138-
static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value)
1139+
static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value, int *clear_values)
11391140
{
11401141
struct dlg_cell *dlg;
11411142
struct dlg_profile_table *profile;
@@ -1156,6 +1157,14 @@ static int w_set_dlg_profile(struct sip_msg *msg, str *prof_name, str *value)
11561157
LM_WARN("missing value\n");
11571158
return -1;
11581159
}
1160+
1161+
if (clear_values && *clear_values) {
1162+
if (unset_dlg_profile_all_values(dlg, profile) < 0) {
1163+
LM_DBG("dialog not found in profile %.*s\n",
1164+
prof_name->len, prof_name->s);
1165+
}
1166+
}
1167+
11591168
if ( set_dlg_profile( dlg, value, profile, 0) < 0 ) {
11601169
LM_ERR("failed to set profile\n");
11611170
return -1;
@@ -1188,10 +1197,12 @@ static int w_unset_dlg_profile(struct sip_msg *msg, str *prof_name, str *value)
11881197

11891198
if (profile->has_value) {
11901199
if (!value) {
1191-
LM_WARN("missing value\n");
1192-
return -1;
1193-
}
1194-
if ( unset_dlg_profile( dlg, value, profile) < 0 ) {
1200+
if (unset_dlg_profile_all_values(dlg, profile) < 0) {
1201+
LM_DBG("dialog not found in profile %.*s\n",
1202+
prof_name->len, prof_name->s);
1203+
return -1;
1204+
}
1205+
} else if (unset_dlg_profile( dlg, value, profile) < 0) {
11951206
LM_WARN("dialog not found in profile %.*s with value %.*s\n",
11961207
prof_name->len, prof_name->s, value->len, value->s);
11971208
return -1;

modules/dialog/dlg_profile.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,65 @@ int unset_dlg_profile(struct dlg_cell *dlg, str *value,
954954
return 1;
955955
}
956956

957+
/*Unset all values set for a dialog on a profile*/
958+
int unset_dlg_profile_all_values(struct dlg_cell *dlg, struct dlg_profile_table *profile)
959+
{
960+
struct dlg_profile_link *linker;
961+
struct dlg_profile_link *linker_prev;
962+
struct dlg_entry *d_entry;
963+
int found = -1;
964+
965+
/* get current dialog */
966+
if (dlg==NULL) {
967+
LM_ERR("dialog was not yet created - script error\n");
968+
return -1;
969+
}
970+
971+
/* check the dialog linkers */
972+
d_entry = &d_table->entries[dlg->h_entry];
973+
/* lock dialog (if not already locked via a callback triggering)*/
974+
if (dlg->locked_by!=process_no)
975+
dlg_lock( d_table, d_entry);
976+
977+
linker = dlg->profile_links;
978+
linker_prev = NULL;
979+
while (linker) {
980+
if (linker->profile==profile) {
981+
found = 1;
982+
983+
/* Take the linker to remove and advance linker for next iter */
984+
struct dlg_profile_link *tmp = linker;
985+
linker = linker->next;
986+
987+
/* Fixup list integrity */
988+
if (linker_prev == NULL) {
989+
dlg->profile_links = linker;
990+
} else {
991+
linker_prev->next = linker;
992+
}
993+
994+
/* Dealloc linker */
995+
dlg->flags |= DLG_FLAG_VP_CHANGED;
996+
destroy_linker(tmp, dlg, 1);
997+
shm_free(tmp);
998+
999+
if (profile->has_value==0) {
1000+
break;
1001+
}
1002+
1003+
/* keep searching to remove all instances */
1004+
continue;
1005+
}
1006+
1007+
linker_prev = linker;
1008+
linker = linker->next;
1009+
}
1010+
1011+
if (dlg->locked_by!=process_no)
1012+
dlg_unlock( d_table, d_entry);
1013+
1014+
return found;
1015+
}
9571016

9581017
int is_dlg_in_profile(struct dlg_cell *dlg, struct dlg_profile_table *profile,
9591018
str *value)

modules/dialog/dlg_profile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ int set_dlg_profile(struct dlg_cell *dlg, str *value,
118118
int unset_dlg_profile(struct dlg_cell *dlg, str *value,
119119
struct dlg_profile_table *profile);
120120

121+
int unset_dlg_profile_all_values(struct dlg_cell *dlg, struct dlg_profile_table *profile);
122+
121123
int is_dlg_in_profile(struct dlg_cell *dlg, struct dlg_profile_table *profile,
122124
str *value);
123125

modules/dialog/doc/dialog_admin.xml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ if (load_dialog_ctx("$var(callid)")) {
19511951

19521952
<section id="func_set_dlg_profile" xreflabel="set_dlg_profile()">
19531953
<title>
1954-
<function moreinfo="none">set_dlg_profile(profile,[value])</function>
1954+
<function moreinfo="none">set_dlg_profile(profile, [value], [clear_values])</function>
19551955
</title>
19561956
<para>
19571957
Inserts the current dialog into a profile. Note that if the profile does
@@ -1975,6 +1975,12 @@ if (load_dialog_ctx("$var(callid)")) {
19751975
profile must support values.
19761976
</para>
19771977
</listitem>
1978+
<listitem>
1979+
<para><emphasis>clear_values (boolean, optional)</emphasis> - if set to
1980+
<emphasis>true</emphasis> (1), all values of the profile will be cleared
1981+
before setting the given value. Default: <emphasis>false</emphasis>.
1982+
</para>
1983+
</listitem>
19781984
</itemizedlist>
19791985
<para>
19801986
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
@@ -1985,7 +1991,12 @@ if (load_dialog_ctx("$var(callid)")) {
19851991
<programlisting format="linespecific">
19861992
...
19871993
set_dlg_profile("inboundCall");
1988-
set_dlg_profile("caller",$fu);
1994+
1995+
# Set a new value (all other values are kept intact)
1996+
set_dlg_profile("caller", $fu);
1997+
1998+
# Set a new value while removing all previous values
1999+
set_dlg_profile("caller", $fu, true);
19892000
...
19902001
</programlisting>
19912002
</example>
@@ -1994,7 +2005,7 @@ set_dlg_profile("caller",$fu);
19942005

19952006
<section id="func_unset_dlg_profile" xreflabel="unset_dlg_profile()">
19962007
<title>
1997-
<function moreinfo="none">unset_dlg_profile(profile,[value])</function>
2008+
<function moreinfo="none">unset_dlg_profile(profile, [value])</function>
19982009
</title>
19992010
<para>
20002011
Removes the current dialog from a profile.
@@ -2015,6 +2026,9 @@ set_dlg_profile("caller",$fu);
20152026
define the belonging of the dialog to the profile - note that the
20162027
profile must support values.
20172028
</para>
2029+
<para>NEW in 3.4: for profiles with value, by omitting this parameter
2030+
you can now clear all values of the given profile.
2031+
</para>
20182032
</listitem>
20192033
</itemizedlist>
20202034
<para>
@@ -2026,7 +2040,10 @@ set_dlg_profile("caller",$fu);
20262040
<programlisting format="linespecific">
20272041
...
20282042
unset_dlg_profile("inboundCall");
2029-
unset_dlg_profile("caller",$fu);
2043+
unset_dlg_profile("caller", $fu);
2044+
...
2045+
# Remove all values in a profile
2046+
unset_dlg_profile("caller");
20302047
...
20312048
</programlisting>
20322049
</example>

0 commit comments

Comments
 (0)