Skip to content

Commit

Permalink
[dialog] add $DLG_del_delay for per-call delete delaying
Browse files Browse the repository at this point in the history
The $DLG_del_delay variable allows per call setting of the delete delaying (see delete_delay modparam)
  • Loading branch information
bogdan-iancu committed May 8, 2023
1 parent 24bfdf4 commit a2fefe4
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 9 deletions.
27 changes: 21 additions & 6 deletions modules/dialog/README
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ dialog Module
1.10.6. $DLG_did
1.10.7. $DLG_end_reason
1.10.8. $DLG_timeout
1.10.9. $DLG_json
1.10.10. $DLG_ctx_json
1.10.11. $dlg_val(name)
1.10.9. $DLG_del_delay
1.10.10. $DLG_json
1.10.11. $DLG_ctx_json
1.10.12. $dlg_val(name)

1.11. Exported Events

Expand Down Expand Up @@ -536,6 +537,9 @@ modparam("dialog", "dlg_match_mode", 0)
it will still be able to match and route late in-dialog
requests.

This global value may be per-call changed via the DLG_del_delay
“$DLG_del_delay” ($DLG_del_delay) script variable.

Default value is “0” (disabled).

Example 1.8. Set delete_delay parameter
Expand Down Expand Up @@ -2347,7 +2351,18 @@ GIwZjAzNGM1ZDY
NULL will be returned if there is no dialog for the request,
otherwise the number of seconds until the dialog expiration.

1.10.9. $DLG_json
1.10.9. $DLG_del_delay

Used to set the dialog deletion delay (in seconds) for the
current dialog (in a per-call manner). When read, the variable
returns the number of seconds that were set for the call or the
default value ( see the “delete_delay” - delete_delay) module
param) for the delete delaying.

The variable must be used when the context of a dialog is
available in script.

1.10.10. $DLG_json

The variable is read-only and exposes a JSON variable
containing all the information that the dlg_list MI function
Expand All @@ -2356,7 +2371,7 @@ GIwZjAzNGM1ZDY
NULL will be returned if there is no dialog for the request,
otherwise the JSON will be returned.

1.10.10. $DLG_ctx_json
1.10.11. $DLG_ctx_json

The variable is read-only and exposes a JSON variable
containing all the information that the dlg_list_ctx MI
Expand All @@ -2367,7 +2382,7 @@ GIwZjAzNGM1ZDY
NULL will be returned if there is no dialog for the request,
otherwise the JSON will be returned.

1.10.11. $dlg_val(name)
1.10.12. $dlg_val(name)

This is a read/write variable that allows access to the dialog
attribute named name. It can hold a string or integer value.
Expand Down
75 changes: 74 additions & 1 deletion modules/dialog/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,19 @@ static int dlg_send_sequential(struct sip_msg* msg, str *method, int leg,
int pv_get_dlg_lifetime(struct sip_msg *msg,pv_param_t *param,pv_value_t *res);
int pv_get_dlg_status(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
int pv_get_dlg_flags(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
int pv_get_dlg_timeout(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
int pv_get_dlg_timeout(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
int pv_get_dlg_deldelay(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
int pv_get_dlg_dir(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
int pv_get_dlg_did(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
int pv_get_dlg_end_reason(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
int pv_set_dlg_flags(struct sip_msg *msg, pv_param_t *param, int op,
pv_value_t *val);
int pv_set_dlg_timeout(struct sip_msg *msg, pv_param_t *param, int op,
pv_value_t *val);
int pv_set_dlg_deldelay(struct sip_msg *msg, pv_param_t *param, int op,
pv_value_t *val);
int pv_get_dlg_json(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
int pv_get_dlg_ctx_json(struct sip_msg *msg, pv_param_t *param,
Expand Down Expand Up @@ -454,6 +459,8 @@ static const pv_export_t mod_items[] = {
pv_get_dlg_json, 0, 0, 0, 0, 0 },
{ {"DLG_ctx_json", sizeof("DLG_ctx_json")-1}, 1000,
pv_get_dlg_ctx_json, 0, 0, 0, 0, 0 },
{ {"DLG_del_delay", sizeof("DLG_del_delay")-1}, 1000,
pv_get_dlg_deldelay, pv_set_dlg_deldelay, 0, 0, 0, 0 },
{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
};

Expand Down Expand Up @@ -1623,6 +1630,35 @@ int pv_get_dlg_timeout(struct sip_msg *msg, pv_param_t *param,
return 0;
}

int pv_get_dlg_deldelay(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
int l = 0;
char *ch = NULL;
struct dlg_cell *dlg;

if(res==NULL)
return -1;

if ( (dlg=get_current_dialog())!=NULL ) {
l = dlg->del_delay;
if (l==0)
l = dlg_del_delay;
} else {
return pv_get_null( msg, param, res);
}

res->ri = l;

ch = int2str( (unsigned long)res->ri, &l);
res->rs.s = ch;
res->rs.len = l;

res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;

return 0;
}

int pv_get_dlg_dir(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
Expand Down Expand Up @@ -1793,6 +1829,43 @@ int pv_set_dlg_timeout(struct sip_msg *msg, pv_param_t *param,
return 0;
}

int pv_set_dlg_deldelay(struct sip_msg *msg, pv_param_t *param,
int op, pv_value_t *val)
{
struct dlg_cell *dlg;
int delay;

if (val==NULL || val->flags & PV_VAL_NULL) {
LM_ERR("cannot assign dialog timeout to NULL\n");
return -1;
}

if (!(val->flags&PV_VAL_INT)){
/* try parsing the string */
if (str2sint(&val->rs, &delay) < 0) {
LM_ERR("assigning non-int value to dialog del delay\n");
return -1;
}
} else {
delay = val->ri;
}

if (delay < 0) {
LM_ERR("cannot set a negative timeout\n");
return -1;
}

if ((dlg = get_current_dialog()) != NULL) {
dlg->del_delay = delay;
} else {
LM_ERR("dialog not found - have you created it?\n");
return -1;
}

return 0;
}


#define DLG_CTX_JSON_BUFF_SIZE 8192
#define DEC_AND_CHECK_LEN(_curr,_size) \
do { \
Expand Down
7 changes: 5 additions & 2 deletions modules/dialog/dlg_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ struct dlg_cell
unsigned int initial_t_hash_index;
unsigned int initial_t_label;
unsigned int replicated; /* indicates if the dialog is replicated */
unsigned int del_delay; /* if any custom delay should be done
* when deleting this dialog */
struct dlg_tl tl;
struct dlg_tl del_tl;
struct dlg_ping_list *pl;
Expand Down Expand Up @@ -330,8 +332,9 @@ void destroy_dlg(struct dlg_cell *dlg);
if ((_dlg)->ref<=0) { \
/* dlg good to be destried, but be sure it went first
* via the delete timer */ \
if (dlg_del_delay==0 || \
insert_attempt_dlg_del_timer(&_dlg->del_tl, dlg_del_delay)==-2) {\
if ((dlg_del_delay==0 && (_dlg)->del_delay==0) || \
insert_attempt_dlg_del_timer(&_dlg->del_tl, \
(_dlg)->del_delay?(_dlg)->del_delay:dlg_del_delay)==-2) {\
/* no delay on del or not in del timer anymore -> destroy */ \
LM_DBG("Destroying dialog %p\n",_dlg); \
unlink_unsafe_dlg( _d_entry, _dlg);\
Expand Down
22 changes: 22 additions & 0 deletions modules/dialog/doc/dialog_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ modparam("dialog", "dlg_match_mode", 0)
be kept in a read only state (no action, no changes), but it will
still be able to match and route late in-dialog requests.
</para>
<para>
This global value may be per-call changed via the DLG_del_delay
<quote>$DLG_del_delay</quote> (<xref linkend="pv_DLG_del_delay"/>)
script variable.
</para>
<para>
<emphasis>
Default value is <quote>0</quote> (disabled).
Expand Down Expand Up @@ -3310,6 +3315,23 @@ event_route[E_RTPPROXY_DTMF] {
</para>
</section>

<section id="pv_DLG_del_delay" xreflabel="$DLG_del_delay">
<title><varname>$DLG_del_delay</varname></title>
<para>
Used to set the dialog deletion delay (in seconds) for the
current dialog (in a per-call manner). When read, the variable
returns the number of seconds that were set for the call or
the default value ( see the
<quote>delete_delay</quote> - <xref linkend="param_delete_delay"/>)
module param) for the delete delaying.
</para>
<para>
The variable must be used when the context of a dialog is
available in script.
</para>
</section>


<section id="pv_DLG_json" xreflabel="$DLG_json">
<title><varname>$DLG_json</varname></title>
<para>
Expand Down

0 comments on commit a2fefe4

Please sign in to comment.