Skip to content

Commit

Permalink
Fixed increasing the CSEQ for in-dialog generated message when uac_au…
Browse files Browse the repository at this point in the history
…th is used in combination with the dialog module

(cherry picked from commit d9d254a)
  • Loading branch information
vladpaiu authored and razvancrainea committed Sep 11, 2015
1 parent 7a32301 commit 2f6abab
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 26 deletions.
26 changes: 21 additions & 5 deletions modules/dialog/dlg_handlers.c
Expand Up @@ -327,7 +327,7 @@ static inline void push_reply_in_dialog(struct sip_msg *rpl, struct cell* t,
struct dlg_cell *dlg,str *mangled_from,str *mangled_to)
{
str tag,contact,rr_set;
unsigned int leg, skip_rrs;
unsigned int leg, skip_rrs,cseq_no;

/* get to tag*/
if ( !rpl->to && ((parse_headers(rpl,HDR_TO_F,0)<0) || !rpl->to) ){
Expand Down Expand Up @@ -383,6 +383,17 @@ static inline void push_reply_in_dialog(struct sip_msg *rpl, struct cell* t,
/* set this branch as primary */
if (!dlg->legs_no[DLG_LEG_200OK])
dlg->legs_no[DLG_LEG_200OK] = leg;

if (dlg->flags & DLG_FLAG_CSEQ_ENFORCE) {
/* increase all future requests going to this leg */
if (str2int(&(((struct cseq_body *)t->uas.request->cseq->parsed)->number),&cseq_no) < 0) {
LM_ERR("Failed to convert cseq to integer \n");
} else {
/* XXX - fix this */
dlg->legs[dlg->legs_no[DLG_LEG_200OK]].last_gen_cseq = cseq_no + 1;
}
}

/* update routing info */
if(dlg->mod_flags & TOPOH_ONGOING)
skip_rrs = 0; /* changed here for contact - it was 1 */
Expand Down Expand Up @@ -1149,7 +1160,8 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)

LM_DBG("BYE successfully processed - dst_leg = %d\n",dst_leg);

if (dlg->flags & DLG_FLAG_PING_CALLER || dlg->flags & DLG_FLAG_PING_CALLEE) {
if (dlg->flags & DLG_FLAG_PING_CALLER || dlg->flags & DLG_FLAG_PING_CALLEE ||
dlg->flags & DLG_FLAG_CSEQ_ENFORCE) {
dlg_lock (d_table,d_entry);

if (dlg->legs[dst_leg].last_gen_cseq) {
Expand Down Expand Up @@ -1265,7 +1277,8 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
}

if (dlg->flags & DLG_FLAG_PING_CALLER ||
dlg->flags & DLG_FLAG_PING_CALLEE) {
dlg->flags & DLG_FLAG_PING_CALLEE ||
dlg->flags & DLG_FLAG_CSEQ_ENFORCE ) {

dlg_lock (d_table, d_entry);

Expand Down Expand Up @@ -1295,7 +1308,8 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
else
{
if (dlg->flags & DLG_FLAG_PING_CALLER ||
dlg->flags & DLG_FLAG_PING_CALLEE) {
dlg->flags & DLG_FLAG_PING_CALLEE ||
dlg->flags & DLG_FLAG_CSEQ_ENFORCE) {

dlg_lock (d_table, d_entry);

Expand All @@ -1315,7 +1329,9 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
if ( event!=DLG_EVENT_REQACK) {
/* register callback for the replies of this request */

if (dlg->flags & DLG_FLAG_PING_CALLER || dlg->flags & DLG_FLAG_PING_CALLEE) {
if (dlg->flags & DLG_FLAG_PING_CALLER ||
dlg->flags & DLG_FLAG_PING_CALLEE ||
dlg->flags & DLG_FLAG_CSEQ_ENFORCE) {
dlg_lock( d_table, d_entry);
if (dlg->legs[dst_leg].last_gen_cseq) {
/* ref the dialog as registered into the transaction callback.
Expand Down
1 change: 1 addition & 0 deletions modules/dialog/dlg_hash.h
Expand Up @@ -72,6 +72,7 @@
#define DLG_FLAG_TOPHIDING (1<<7)
#define DLG_FLAG_VP_CHANGED (1<<8)
#define DLG_FLAG_DB_DELETED (1<<9)
#define DLG_FLAG_CSEQ_ENFORCE (1<<10)

#define DLG_CALLER_LEG 0
#define DLG_FIRST_CALLEE_LEG 1
Expand Down
3 changes: 2 additions & 1 deletion modules/dialog/dlg_req_within.c
Expand Up @@ -72,7 +72,8 @@ dlg_t * build_dlg_t(struct dlg_cell * cell, int dst_leg, int src_leg)
memset(td, 0, sizeof(dlg_t));

if ((dst_leg == DLG_CALLER_LEG && (cell->flags & DLG_FLAG_PING_CALLER)) ||
(dst_leg == callee_idx(cell) && (cell->flags & DLG_FLAG_PING_CALLEE)))
(dst_leg == callee_idx(cell) && (cell->flags & DLG_FLAG_PING_CALLEE)) ||
cell->flags & DLG_FLAG_CSEQ_ENFORCE)
{
dlg_lock_dlg(cell);
if (cell->legs[dst_leg].last_gen_cseq == 0)
Expand Down
47 changes: 28 additions & 19 deletions modules/uac/auth.c
Expand Up @@ -38,6 +38,7 @@
#include "../../parser/parse_authenticate.h"
#include "../tm/tm_load.h"
#include "../uac_auth/uac_auth.h"
#include "../dialog/dlg_load.h"
#include "auth.h"


Expand All @@ -46,6 +47,7 @@ extern struct tm_binds uac_tmb;
extern uac_auth_api_t uac_auth_api;
extern str rr_uac_cseq_param;
extern struct rr_binds uac_rrb;
extern struct dlg_binds dlg_api;

static inline int apply_urihdr_changes( struct sip_msg *req,
str *uri, str *hdr)
Expand Down Expand Up @@ -157,7 +159,7 @@ int apply_cseq_op(struct sip_msg *msg,int val)
((struct cseq_body *)msg->cseq->parsed)->number.s,pkg_cseq.len,
pkg_cseq.s);

return 0;
return cseq_no;
}

void apply_cseq_decrement(struct cell* t, int type, struct tmcb_params *p)
Expand All @@ -182,12 +184,14 @@ int uac_auth( struct sip_msg *msg)
static struct authenticate_nc_cnonce auth_nc_cnonce;
struct uac_credential *crd;
int code, branch;
unsigned int new_cseq;
struct sip_msg *rpl;
struct cell *t;
HASHHEX response;
str *new_hdr;
str param;
char *p;
struct dlg_cell *dlg;

/* get transaction */
t = uac_tmb.t_gett();
Expand Down Expand Up @@ -265,7 +269,7 @@ int uac_auth( struct sip_msg *msg)
goto error;
}

if ( apply_cseq_op(msg,1) < 0) {
if ( (new_cseq = apply_cseq_op(msg,1)) < 0) {
LM_WARN("Failure to increment the CSEQ header - continue \n");
goto error;
}
Expand All @@ -280,31 +284,36 @@ int uac_auth( struct sip_msg *msg)
}
}

param.len=rr_uac_cseq_param.len+3;
param.s=pkg_malloc(param.len);
if (!param.s) {
LM_ERR("No more pkg mem \n");
goto error;
}
if (dlg_api.get_dlg && (dlg = dlg_api.get_dlg())) {
/* dlg->legs[dlg->legs_no[DLG_LEGS_USED]-1].last_gen_cseq = new_cseq; */
dlg->flags |= DLG_FLAG_CSEQ_ENFORCE;
} else {
param.len=rr_uac_cseq_param.len+3;
param.s=pkg_malloc(param.len);
if (!param.s) {
LM_ERR("No more pkg mem \n");
goto error;
}

p = param.s;
*p++=';';
memcpy(p,rr_uac_cseq_param.s,rr_uac_cseq_param.len);
p+=rr_uac_cseq_param.len;
*p++='=';
*p++='1';
p = param.s;
*p++=';';
memcpy(p,rr_uac_cseq_param.s,rr_uac_cseq_param.len);
p+=rr_uac_cseq_param.len;
*p++='=';
*p++='1';

if (uac_rrb.add_rr_param( msg, &param)!=0) {
LM_ERR("add_RR_param failed\n");
pkg_free(param.s);
goto error;
}

if (uac_rrb.add_rr_param( msg, &param)!=0) {
LM_ERR("add_RR_param failed\n");
pkg_free(param.s);
goto error;
}

msg->msg_flags |= FL_USE_UAC_CSEQ;
t->uas.request->msg_flags |= FL_USE_UAC_CSEQ;

pkg_free(param.s);
new_hdr->s = NULL; new_hdr->len = 0;
return 0;
error:
return -1;
Expand Down
11 changes: 10 additions & 1 deletion modules/uac/uac.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2005-2009 Voice Sistem SRL
*
*
* This file is part of opensips, a free SIP server.
*
* UAC OpenSIPS-module is free software; you can redistribute it and/or
Expand Down Expand Up @@ -195,6 +195,7 @@ static int mod_init(void)
{
LM_INFO("initializing...\n");
int rr_api_loaded=0;
int dlg_api_loaded=0;

if ( is_script_func_used("uac_auth", -1) ) {
/* load the UAC_AUTH API as uac_auth() is invoked from script */
Expand Down Expand Up @@ -265,6 +266,8 @@ static int mod_init(void)
}
LM_DBG("failed to find dialog API - is dialog module loaded?\n");
} else {
dlg_api_loaded=1;

if ( (parse_store_bavp(&store_to_bavp, &to_bavp_spec) ||
parse_store_bavp(&store_from_bavp, &from_bavp_spec))) {
LM_ERR("cannot set correct store parameters\n");
Expand Down Expand Up @@ -297,6 +300,12 @@ static int mod_init(void)
goto error;
}
}
if (!dlg_api_loaded) {
if (load_dlg_api(&dlg_api)!=0) {
LM_ERR("Can't load dlg API \n");
}
}

if (!uac_rrb.append_fromtag) {
LM_ERR("'append_fromtag' RR param is not enabled!"
" - required by uac_auth() restore mode\n");
Expand Down

0 comments on commit 2f6abab

Please sign in to comment.