Skip to content

Commit

Permalink
dialog: add dlg_inc_cseq function
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Sep 20, 2024
1 parent c69201e commit 393dba7
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
57 changes: 57 additions & 0 deletions modules/dialog/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static int dlg_on_answer(struct sip_msg* msg, void *route_id);
static int dlg_on_hangup(struct sip_msg* msg, void *route_id);
static int dlg_send_sequential(struct sip_msg* msg, str *method, int leg,
str *body, str *ct, str *headers);
static int dlg_inc_cseq(struct sip_msg *msg, str *tag, int *_count);


/* item/pseudo-variables functions */
Expand Down Expand Up @@ -282,6 +283,10 @@ static const cmd_export_t cmds[]={
{CMD_PARAM_STR|CMD_PARAM_OPT, 0, 0},
{CMD_PARAM_STR|CMD_PARAM_OPT, 0, 0}, {0,0,0}},
ALL_ROUTES},
{"dlg_inc_cseq", (cmd_function)dlg_inc_cseq, {
{CMD_PARAM_STR|CMD_PARAM_OPT, 0, 0},
{CMD_PARAM_INT|CMD_PARAM_OPT, 0, 0}, {0,0,0}},
REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
{"load_dlg", (cmd_function)load_dlg, {{0,0,0}}, 0},
{0,0,{{0,0,0}},0}
};
Expand Down Expand Up @@ -2566,3 +2571,55 @@ static int dlg_send_sequential(struct sip_msg* msg, str *method, int leg,
body, ct, headers, NULL, NULL) == 0?1:-1;

}

static int dlg_inc_cseq(struct sip_msg *msg, str *tag, int *_count)
{
struct dlg_cell *dlg;
int count = (_count?*_count:1);
int leg, ret = -1;
str cseq;
unsigned int loc_seq;

if ( (dlg=get_current_dialog())==NULL ) {
LM_DBG("no current dialog found\n");
return -2;
}

if (!tag) {
if ((!msg->to && parse_headers(msg, HDR_TO_F, 0) < 0) || !msg->to) {
LM_ERR("inexisting or invalid to header!\n");
return -1;
}
tag = &get_to(msg)->tag_value;
}
dlg_lock_dlg(dlg);
for (leg = DLG_FIRST_CALLEE_LEG ; leg < dlg->legs_no[DLG_LEGS_USED]; leg++) {
if (str_match(tag, &dlg->legs[leg].tag))
break;
}
if (leg == dlg->legs_no[DLG_LEGS_USED]) {
LM_ERR("leg with tag <%.*s> not found\n", tag->len, tag->s);
goto end;
}
if (dlg->legs[leg].last_gen_cseq == 0) {
/*local sequence number*/
cseq = dlg->legs[leg].r_cseq;
if (!cseq.s || !cseq.len || str2int(&cseq, &loc_seq) != 0){
LM_ERR("invalid cseq\n");
goto end;
}

dlg->legs[leg].last_gen_cseq = loc_seq + count;
} else {
dlg->legs[leg].last_gen_cseq += count;
loc_seq = -1;
}
LM_DBG("increasing leg=%d cseq=%u count=%d gen=%d\n",
leg, loc_seq, count, dlg->legs[leg].last_gen_cseq);
ret = 1;

dlg->flags |= DLG_FLAG_CSEQ_ENFORCE;
end:
dlg_unlock_dlg(dlg);
return ret;
}
39 changes: 39 additions & 0 deletions modules/dialog/doc/dialog_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,45 @@ event_route[E_RTPPROXY_DTMF] {
}
}
...
</programlisting>
</example>
</section>
<section id="func_dlg_inc_cseq" xreflabel="dlg_inc_cseq()">
<title>
<function moreinfo="none">dlg_inc_cseq([tag, ][inc])</function>
</title>
<para>Increments the dialog's generated CSeq associated to the leg
identified by the dialog's tag.
</para>
<para>Parameters:</para>
<itemizedlist>
<listitem><para><emphasis>tag (string, optional)</emphasis> -
the tag to increment the CSeq value for. If missing, the
message's <emphasis>To</emphasis> tag is used to identify
the leg to increment the CSeq for.
</para></listitem>
<listitem><para><emphasis>inc (integer, optional)</emphasis> - the
value used to increment/decrement (if negative) the CSeq of
the identified leg. If not used, the value is incremented with
<emphasis>1</emphasis>.
</para></listitem>
</itemizedlist>
<para>
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE routes.
</para>
<example>
<title><function>dlg_inc_cseq</function> usage</title>
<programlisting format="linespecific">
...
route {
...
if (has_totag()) {
if (loose_route())
dlg_inc_cseq(); # increment upstream CSeq after each in-dialog request
}
}
...
</programlisting>
</example>
</section>
Expand Down

0 comments on commit 393dba7

Please sign in to comment.