Skip to content

Commit 90c7891

Browse files
committed
dialog: Change create_dialog() to use explicit flag names
1 parent 84ad647 commit 90c7891

3 files changed

Lines changed: 99 additions & 76 deletions

File tree

modules/dialog/dialog.c

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "../../script_var.h"
4040
#include "../../mem/mem.h"
4141
#include "../../mi/mi.h"
42+
#include "../../lib/csv.h"
4243
#include "../rr/api.h"
4344
#include "../../bin_interface.h"
4445
#include "../clusterer/api.h"
@@ -118,7 +119,7 @@ static int pv_get_dlg_count( struct sip_msg *msg, pv_param_t *param,
118119
pv_value_t *res);
119120

120121
/* commands wrappers and fixups */
121-
static int w_create_dialog(struct sip_msg*, str *flags_str);
122+
static int w_create_dialog(struct sip_msg*, void *flags_param);
122123
static int w_match_dialog(struct sip_msg *msg, void *seq_match_mode_val);
123124
static int api_match_dialog(struct sip_msg *msg, int _seq_match_mode);
124125
static int w_validate_dialog(struct sip_msg*);
@@ -134,6 +135,7 @@ static int fixup_check_avp(void** param);
134135
static int fixup_check_var(void** param);
135136
static int fixup_lmode(void **param);
136137
static int fixup_leg(void **param);
138+
static int fixup_create_dlg_flags(void **param);
137139
static int w_set_dlg_flag(struct sip_msg *msg, void *mask);
138140
static int w_reset_dlg_flag(struct sip_msg *msg, void *mask);
139141
static int w_is_dlg_flag_set(struct sip_msg *msg, void *mask);
@@ -186,7 +188,7 @@ int pv_get_dlg_ctx_json(struct sip_msg *msg, pv_param_t *param,
186188

187189
static const cmd_export_t cmds[]={
188190
{"create_dialog", (cmd_function)w_create_dialog, {
189-
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}},
191+
{CMD_PARAM_STR|CMD_PARAM_OPT,fixup_create_dlg_flags,0}, {0,0,0}},
190192
REQUEST_ROUTE},
191193
{"set_dlg_profile", (cmd_function)w_set_dlg_profile, {
192194
{CMD_PARAM_STR,0,0},
@@ -599,6 +601,64 @@ static int free_fixup_route(void** param)
599601
return 0;
600602
}
601603

604+
/*
605+
* Keep this array in sync with create_dlg_flags[] below: if you add, remove
606+
* or reorder a create_dialog() flag here, make the identical change there.
607+
*/
608+
static str create_dlg_flag_names[] = {
609+
str_init("bye-on-timeout"), /* DLG_FLAG_BYEONTIMEOUT */
610+
str_init("options-ping-caller"), /* DLG_FLAG_PING_CALLER */
611+
str_init("options-ping-callee"), /* DLG_FLAG_PING_CALLEE */
612+
str_init("reinvite-ping-caller"), /* DLG_FLAG_REINVITE_PING_CALLER */
613+
str_init("reinvite-ping-callee"), /* DLG_FLAG_REINVITE_PING_CALLEE */
614+
str_init("end-on-race-condition"), /* DLG_FLAG_END_ON_RACE_CONDITION */
615+
str_init("auto-prack"), /* DLG_FLAG_AUTOPRACK */
616+
STR_NULL
617+
};
618+
619+
static int fixup_create_dlg_flags(void **param)
620+
{
621+
static const unsigned int create_dlg_flags[] = {
622+
DLG_FLAG_BYEONTIMEOUT,
623+
DLG_FLAG_PING_CALLER,
624+
DLG_FLAG_PING_CALLEE,
625+
DLG_FLAG_REINVITE_PING_CALLER,
626+
DLG_FLAG_REINVITE_PING_CALLEE,
627+
DLG_FLAG_END_ON_RACE_CONDITION,
628+
DLG_FLAG_AUTOPRACK
629+
};
630+
str *flags_str = (str *)*param;
631+
csv_record *list, *rec;
632+
unsigned int flags = 0;
633+
int i;
634+
635+
list = parse_csv_record(flags_str);
636+
if (!list) {
637+
LM_ERR("Failed to parse list of create_dialog flags\n");
638+
return -1;
639+
}
640+
641+
for (rec = list; rec; rec = rec->next) {
642+
for (i = 0; create_dlg_flag_names[i].s; i++) {
643+
if (str_strcasecmp(&rec->s, &create_dlg_flag_names[i]) == 0) {
644+
flags |= create_dlg_flags[i];
645+
break;
646+
}
647+
}
648+
649+
if (!create_dlg_flag_names[i].s) {
650+
LM_ERR("Unknown create_dialog flag: %.*s\n",
651+
rec->s.len, rec->s.s);
652+
free_csv_record(list);
653+
return -1;
654+
}
655+
}
656+
657+
free_csv_record(list);
658+
*param = (void *)(unsigned long)flags;
659+
return 0;
660+
}
661+
602662

603663
static int create_dialog_wrapper(struct sip_msg *req,int flags)
604664
{
@@ -1008,12 +1068,12 @@ static void mod_destroy(void)
10081068
}
10091069

10101070

1011-
static int w_create_dialog(struct sip_msg *req, str *flags_str)
1071+
static int w_create_dialog(struct sip_msg *req, void *flags_param)
10121072
{
10131073
struct cell *t;
1014-
int flags;
1074+
unsigned int flags;
10151075

1016-
flags = flags_str? parse_create_dlg_flags(flags_str): 0;
1076+
flags = flags_param ? (unsigned int)(unsigned long)flags_param : 0;
10171077

10181078
/* don't allow both Re-INVITE and OPTIONS pinging */
10191079
if ((flags & (DLG_FLAG_PING_CALLER|DLG_FLAG_REINVITE_PING_CALLER)) ==

modules/dialog/dlg_hash.h

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -349,54 +349,6 @@ void destroy_dlg(struct dlg_cell *dlg);
349349
}\
350350
}while(0)
351351

352-
/*
353-
* @input - str
354-
* @return - integer flag bitmask
355-
*/
356-
#define parse_create_dlg_flags(input) \
357-
({ \
358-
char *___p; \
359-
int ___flags = 0; \
360-
for (___p=(input)->s; ___p < (input)->s + (input)->len; ___p++) \
361-
{ \
362-
switch (*___p) \
363-
{ \
364-
case 'P': \
365-
___flags |= DLG_FLAG_PING_CALLER; \
366-
LM_DBG("will ping caller\n"); \
367-
break; \
368-
case 'p': \
369-
___flags |= DLG_FLAG_PING_CALLEE; \
370-
LM_DBG("will ping callee\n"); \
371-
break; \
372-
case 'B': \
373-
___flags |= DLG_FLAG_BYEONTIMEOUT; \
374-
LM_DBG("bye on timeout activated\n"); \
375-
break; \
376-
case 'R': \
377-
___flags |= DLG_FLAG_REINVITE_PING_CALLER; \
378-
LM_DBG("re-invite ping caller activated\n"); \
379-
break; \
380-
case 'r': \
381-
___flags |= DLG_FLAG_REINVITE_PING_CALLEE; \
382-
LM_DBG("re-invite ping callee activated\n"); \
383-
break; \
384-
case 'E': \
385-
___flags |= DLG_FLAG_END_ON_RACE_CONDITION; \
386-
LM_DBG("ending call on 200OK race conditions \n"); \
387-
break; \
388-
case 'L': \
389-
___flags |= DLG_FLAG_AUTOPRACK; \
390-
LM_DBG("auto-PRACK for reliable provisional replies activated\n"); \
391-
break; \
392-
default: \
393-
LM_DBG("unknown create_dialog flag : [%c] ." \
394-
"Skipping\n", *___p); \
395-
} \
396-
} \
397-
___flags; \
398-
})
399-
400352
int dialog_cleanup( struct sip_msg *msg, void *param );
401353

402354
int init_dlg_table(unsigned int size);

modules/dialog/doc/dialog_admin.xml

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,45 +1439,56 @@ modparam("dialog", "cluster_auto_sync", 0)
14391439
<itemizedlist>
14401440
<listitem><para>
14411441
<emphasis>flags (string, optional)</emphasis>
1442-
Possible values here are :
1442+
Possible values here are:
14431443
<itemizedlist>
14441444
<listitem><para>
1445-
B - Upon reaching dialog lifetime, BYEs will be triggered
1446-
both ways
1445+
<quote>bye-on-timeout</quote> - upon reaching dialog lifetime,
1446+
BYEs will be triggered both ways
14471447
</para></listitem>
14481448
<listitem><para>
1449-
P - Ping caller side with OPTIONS messages, once every
1450-
options_ping_interval seconds
1449+
<quote>options-ping-caller</quote> - ping caller side with
1450+
OPTIONS messages, once every
1451+
<varname>options_ping_interval</varname> seconds
14511452
</para></listitem>
14521453
<listitem><para>
1453-
p - Ping callee side with OPTIONS messages, once every
1454-
options_ping_interval seconds
1454+
<quote>options-ping-callee</quote> - ping callee side with
1455+
OPTIONS messages, once every
1456+
<varname>options_ping_interval</varname> seconds
14551457
</para></listitem>
14561458
<listitem><para>
1457-
R - Ping caller side with RE-INVITE messages, once every
1458-
reinvite_ping_interval seconds
1459+
<quote>reinvite-ping-caller</quote> - ping caller side with
1460+
RE-INVITE messages, once every
1461+
<varname>reinvite_ping_interval</varname> seconds
14591462
</para></listitem>
14601463
<listitem><para>
1461-
r - Ping callee side with RE-INVITE messages, once every
1462-
reinvite_ping_interval seconds
1464+
<quote>reinvite-ping-callee</quote> - ping callee side with
1465+
RE-INVITE messages, once every
1466+
<varname>reinvite_ping_interval</varname> seconds
14631467
</para></listitem>
14641468
<listitem><para>
1465-
E - Upon detecting a SIP Race condition (see RFC 5407),
1466-
end the call after race_condition_timeout seconds
1469+
<quote>end-on-race-condition</quote> - upon detecting a SIP
1470+
Race condition (see RFC 5407), end the call after
1471+
<varname>race_condition_timeout</varname> seconds
14671472
</para></listitem>
14681473
<listitem><para>
1469-
L - Automatically generate PRACK requests for reliable
1470-
101-199 provisional INVITE replies carrying an RSeq header
1474+
<quote>auto-prack</quote> - automatically generate PRACK
1475+
requests for reliable 101-199 provisional INVITE replies
1476+
carrying an RSeq header
14711477
</para></listitem>
14721478
</itemizedlist>
1473-
Multiple string flags can be used at the same time,
1474-
ie. passing "BPp" flags will enable all 3 flags.
1479+
Multiple string flags can be used at the same time as a CSV,
1480+
i.e. passing
1481+
<quote>bye-on-timeout,options-ping-caller,options-ping-callee</quote>
1482+
will enable all 3 flags.
14751483
</para></listitem>
14761484
</itemizedlist>
14771485
<para>
14781486
NOTE: both RE-INVITE and OPTIONS pinging cannot be enabled at the same time
1479-
for a single dialog leg. If both flags ("<emphasis>PR</emphasis>" or
1480-
"<emphasis>pr</emphasis>") are provided only RE-INVITE pinging will be used.
1487+
for a single dialog leg. If both flags for the same leg are provided
1488+
(for example
1489+
<quote>options-ping-caller,reinvite-ping-caller</quote> or
1490+
<quote>options-ping-callee,reinvite-ping-callee</quote>),
1491+
only RE-INVITE pinging will be used.
14811492
</para>
14821493
<para>
14831494
The function returns true if the dialog was successfully created or
@@ -1493,16 +1504,16 @@ modparam("dialog", "cluster_auto_sync", 0)
14931504
create_dialog();
14941505
...
14951506
#ping caller
1496-
create_dialog("P");
1507+
create_dialog("options-ping-caller");
14971508
...
14981509
#ping caller and callee
1499-
create_dialog("Pp");
1510+
create_dialog("options-ping-caller,options-ping-callee");
15001511

15011512
#bye on timeout
1502-
create_dialog("B");
1513+
create_dialog("bye-on-timeout");
15031514

15041515
#auto-PRACK reliable provisional replies
1505-
create_dialog("L");
1516+
create_dialog("auto-prack");
15061517
...
15071518
</programlisting>
15081519
</example>

0 commit comments

Comments
 (0)