From 53a55967e98d6152acedb32547cbc1028e30d684 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Thu, 24 Mar 2016 10:00:04 +0100 Subject: [PATCH] dispatcher: new function ds_select(setid, alg, [limit]) - puts the addresses from destination set in the internal avps lists, without updating dst-uri or r-uri --- modules/dispatcher/dispatch.c | 23 +++++++++++---- modules/dispatcher/dispatcher.c | 51 +++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/modules/dispatcher/dispatch.c b/modules/dispatcher/dispatch.c index 60c91219c55..cec1d46e319 100644 --- a/modules/dispatcher/dispatch.c +++ b/modules/dispatcher/dispatch.c @@ -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"); @@ -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]; @@ -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 && cntdlist[i].flags) @@ -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 && cntnr-1; i>lhash && cntdlist[i].flags) || (ds_use_default!=0 && i==(idx->nr-1))) diff --git a/modules/dispatcher/dispatcher.c b/modules/dispatcher/dispatcher.c index 2a0ddbc34ca..5220fdbe5c9 100644 --- a/modules/dispatcher/dispatcher.c +++ b/modules/dispatcher/dispatcher.c @@ -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*); @@ -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, @@ -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; @@ -672,20 +679,43 @@ 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*/); } /** @@ -693,15 +723,18 @@ static int w_ds_select_dst_limit(struct sip_msg* msg, char* set, char* alg, char */ 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*/); } /**