Skip to content

Commit

Permalink
dispatcher: new function ds_select(setid, alg, [limit])
Browse files Browse the repository at this point in the history
- puts the addresses from destination set in the internal avps lists,
  without updating dst-uri or r-uri
  • Loading branch information
miconda committed Mar 24, 2016
1 parent 1d401e0 commit 53a5596
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
23 changes: 17 additions & 6 deletions modules/dispatcher/dispatch.c
Expand Up @@ -1749,16 +1749,25 @@ static inline int ds_update_dst(struct sip_msg *msg, str *uri,
act.type = SET_HOSTALL_T;
act.val[0].type = STRING_ST;
if(uri->len>4
&& strncasecmp(uri->s,"sip:",4)==0)
&& strncasecmp(uri->s,"sip:",4)==0) {
act.val[0].u.string = uri->s+4;
else
} else if(uri->len>5
&& strncasecmp(uri->s,"sips:",5)==0) {
act.val[0].u.string = uri->s+5;
} else {
act.val[0].u.string = uri->s;
}
init_run_actions_ctx(&ra_ctx);
if (do_action(&ra_ctx, &act, msg) < 0) {
LM_ERR("error while setting host\n");
return -1;
}
break;

case 2:
/* no update to d-uri/r-uri */
return 0;

default:
if (set_dst_uri(msg, uri) < 0) {
LM_ERR("error while setting dst uri\n");
Expand Down Expand Up @@ -1792,7 +1801,7 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode)
int ds_select_dst_limit(sip_msg_t *msg, int set, int alg, unsigned int limit, int mode)
{
int i, cnt;
unsigned int hash;
unsigned int hash, lhash;
int_str avp_val;
ds_set_t *idx = NULL;
char buf[2+16+1];
Expand Down Expand Up @@ -2036,8 +2045,7 @@ int ds_select_dst_limit(sip_msg_t *msg, int set, int alg, unsigned int limit, in
cnt++;
}

/* add to avp */

/* add to avp in reverse order */
for(i=hash-1; i>=0 && cnt<limit; i--)
{
if(ds_skip_dst(idx->dlist[i].flags)
Expand Down Expand Up @@ -2086,7 +2094,10 @@ int ds_select_dst_limit(sip_msg_t *msg, int set, int alg, unsigned int limit, in
cnt++;
}

for(i=idx->nr-1; i>hash && cnt<limit; i--)
lhash = hash;
/* if addr was not set to dst/uri, add it via last operation */
if(mode==2) lhash--;
for(i=idx->nr-1; i>lhash && cnt<limit; i--)
{
if(ds_skip_dst(idx->dlist[i].flags)
|| (ds_use_default!=0 && i==(idx->nr-1)))
Expand Down
51 changes: 42 additions & 9 deletions modules/dispatcher/dispatcher.c
Expand Up @@ -143,6 +143,8 @@ static int child_init(int);
static int ds_parse_reply_codes();
static int ds_init_rpc(void);

static int w_ds_select(sip_msg_t*, char*, char*);
static int w_ds_select_limit(sip_msg_t*, char*, char*, char*);
static int w_ds_select_dst(struct sip_msg*, char*, char*);
static int w_ds_select_dst_limit(struct sip_msg*, char*, char*, char*);
static int w_ds_select_domain(struct sip_msg*, char*, char*);
Expand Down Expand Up @@ -173,14 +175,18 @@ static struct mi_root* ds_mi_reload(struct mi_root* cmd_tree, void* param);
static int mi_child_init(void);

static cmd_export_t cmds[]={
{"ds_select", (cmd_function)w_ds_select, 2,
fixup_igp_igp, 0, ANY_ROUTE},
{"ds_select", (cmd_function)w_ds_select_limit, 3,
fixup_igp_all, 0, REQUEST_ROUTE|FAILURE_ROUTE},
{"ds_select_dst", (cmd_function)w_ds_select_dst, 2,
fixup_igp_igp, 0, REQUEST_ROUTE|FAILURE_ROUTE},
{"ds_select_dst", (cmd_function)w_ds_select_dst_limit, 3,
fixup_igp_null, 0, REQUEST_ROUTE|FAILURE_ROUTE},
fixup_igp_all, 0, REQUEST_ROUTE|FAILURE_ROUTE},
{"ds_select_domain", (cmd_function)w_ds_select_domain, 2,
fixup_igp_igp, 0, REQUEST_ROUTE|FAILURE_ROUTE},
{"ds_select_domain", (cmd_function)w_ds_select_domain_limit, 3,
fixup_igp_null, 0, REQUEST_ROUTE|FAILURE_ROUTE},
fixup_igp_all, 0, REQUEST_ROUTE|FAILURE_ROUTE},
{"ds_next_dst", (cmd_function)w_ds_next_dst, 0,
ds_warn_fixup, 0, REQUEST_ROUTE|FAILURE_ROUTE},
{"ds_next_domain", (cmd_function)w_ds_next_domain, 0,
Expand Down Expand Up @@ -630,7 +636,8 @@ int ds_parse_flags( char* flag_str, int flag_len )
/**
*
*/
static int w_ds_select(struct sip_msg* msg, char* set, char* alg, char* limit, int mode)
static int w_ds_select_addr(sip_msg_t* msg, char* set, char* alg, char* limit,
int mode)
{
unsigned int algo_flags, set_flags, limit_flags;
str s_algo = STR_NULL;
Expand Down Expand Up @@ -672,36 +679,62 @@ static int w_ds_select(struct sip_msg* msg, char* set, char* alg, char* limit, i

return ds_select_dst_limit(msg, s, a, (unsigned int)l, mode);
}

/**
*
*/
static int w_ds_select(struct sip_msg* msg, char* set, char* alg)
{
return w_ds_select_addr(msg, set, alg, 0 /* limit number of dst*/,
2 /*set no dst/uri*/);
}

/**
*
*/
static int w_ds_select_limit(struct sip_msg* msg, char* set, char* alg,
char* limit)
{
return w_ds_select_addr(msg, set, alg, limit /* limit number of dst*/,
2 /*set no dst/uri*/);
}

/**
*
*/
static int w_ds_select_dst(struct sip_msg* msg, char* set, char* alg)
{
return w_ds_select(msg, set, alg, 0 /* limit number of dst*/, 0 /*set dst uri*/);
return w_ds_select_addr(msg, set, alg, 0 /* limit number of dst*/,
0 /*set dst uri*/);
}

/**
*
*/
static int w_ds_select_dst_limit(struct sip_msg* msg, char* set, char* alg, char* limit)
static int w_ds_select_dst_limit(struct sip_msg* msg, char* set, char* alg,
char* limit)
{
return w_ds_select(msg, set, alg, limit /* limit number of dst*/, 0 /*set dst uri*/);
return w_ds_select_addr(msg, set, alg, limit /* limit number of dst*/,
0 /*set dst uri*/);
}

/**
*
*/
static int w_ds_select_domain(struct sip_msg* msg, char* set, char* alg)
{
return w_ds_select(msg, set, alg, 0 /* limit number of dst*/, 1 /*set host port*/);
return w_ds_select_addr(msg, set, alg, 0 /* limit number of dst*/,
1 /*set host port*/);
}

/**
*
*/
static int w_ds_select_domain_limit(struct sip_msg* msg, char* set, char* alg, char* limit)
static int w_ds_select_domain_limit(struct sip_msg* msg, char* set, char* alg,
char* limit)
{
return w_ds_select(msg, set, alg, limit /* limit number of dst*/, 1 /*set host port*/);
return w_ds_select_addr(msg, set, alg, limit /* limit number of dst*/,
1 /*set host port*/);
}

/**
Expand Down

0 comments on commit 53a5596

Please sign in to comment.