Module: sip-router Branch: master Commit: 241a05bc65b786084de4c3a93cd22d790ce77148 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=241a05bc...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Mon Jan 31 01:19:23 2011 +0100
dispatcher(k): option to disable destionation
- new flag per destination address to allow disabling destination address completely, so that if auto-pinging is enabled will not be brought back in active state - seting disable state and back to active/inactive mode is possible via mi/rpc commands
---
modules_k/dispatcher/dispatch.c | 44 +++++++++++++++++++++++++++++++++++++ modules_k/dispatcher/dispatch.h | 4 ++- modules_k/dispatcher/dispatcher.c | 31 +++++++++++++++++-------- 3 files changed, 68 insertions(+), 11 deletions(-)
diff --git a/modules_k/dispatcher/dispatch.c b/modules_k/dispatcher/dispatch.c index 19b5fab..34124d0 100644 --- a/modules_k/dispatcher/dispatch.c +++ b/modules_k/dispatcher/dispatch.c @@ -2012,6 +2012,9 @@ int ds_mark_dst(struct sip_msg *msg, int mode) return (ret==0)?1:-1; }
+/** + * + */ int ds_set_state(int group, str *address, int state, int type) { int i=0; @@ -2075,6 +2078,44 @@ int ds_set_state(int group, str *address, int state, int type) return -1; }
+/** + * + */ +int ds_reinit_state(int group, str *address, int state) +{ + int i=0; + ds_set_t *idx = NULL; + + if(_ds_list==NULL || _ds_list_nr<=0) + { + LM_ERR("the list is null\n"); + return -1; + } + + /* get the index of the set */ + if(ds_get_index(group, &idx)!=0) + { + LM_ERR("destination set [%d] not found\n", group); + return -1; + } + + for(i=0; i<idx->nr; i++) + { + if(idx->dlist[i].uri.len==address->len + && strncasecmp(idx->dlist[i].uri.s, address->s, + address->len)==0) + { + idx->dlist[i].flags |= state; + return 0; + } + } + LM_ERR("destination address [%d : %.*s] not found\n", group, + address->len, address->s); + return -1; +} +/** + * + */ int ds_print_list(FILE *fout) { int j; @@ -2298,6 +2339,9 @@ void ds_check_timer(unsigned int ticks, void* param) { for(j=0; j<list->nr; j++) { + /* skip addresses set in disabled state by admin */ + if((list->dlist[j].flags&DS_DISABLED_DST) != 0) + continue; /* If the Flag of the entry has "Probing set, send a probe: */ if (ds_probing_mode==1 || (list->dlist[j].flags&DS_PROBING_DST) != 0) diff --git a/modules_k/dispatcher/dispatch.h b/modules_k/dispatcher/dispatch.h index 7f6637b..f15cfbf 100644 --- a/modules_k/dispatcher/dispatch.h +++ b/modules_k/dispatcher/dispatch.h @@ -51,7 +51,8 @@
#define DS_INACTIVE_DST 1 /*!< inactive destination */ #define DS_PROBING_DST 2 /*!< checking destination */ -#define DS_RESET_FAIL_DST 4 /*!< Reset-Failure-Counter */ +#define DS_DISABLED_DST 4 /*!< admin disabled destination */ +#define DS_RESET_FAIL_DST 8 /*!< Reset-Failure-Counter */
extern str ds_db_url; extern str ds_table_name; @@ -98,6 +99,7 @@ int ds_destroy_list(void); int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode); int ds_next_dst(struct sip_msg *msg, int mode); int ds_set_state(int group, str *address, int state, int type); +int ds_reinit_state(int group, str *address, int state); int ds_mark_dst(struct sip_msg *msg, int mode); int ds_print_list(FILE *fout); int ds_print_mi_list(struct mi_node* rpl); diff --git a/modules_k/dispatcher/dispatcher.c b/modules_k/dispatcher/dispatcher.c index 6f61edf..8ed44bc 100644 --- a/modules_k/dispatcher/dispatcher.c +++ b/modules_k/dispatcher/dispatcher.c @@ -640,20 +640,34 @@ static struct mi_root* ds_mi_set(struct mi_root* cmd_tree, void* param)
node = cmd_tree->node.kids; if(node == NULL) - return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); + return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); sp = node->value; if(sp.len<=0 || !sp.s) { LM_ERR("bad state value\n"); - return init_mi_tree( 500, "bad state value", 15); + return init_mi_tree(500, "bad state value", 15); }
- state = 1; - if(sp.s[0]=='0' || sp.s[0]=='I' || sp.s[0]=='i') - state = 0; + state = 0; + if(sp.s[0]=='0' || sp.s[0]=='I' || sp.s[0]=='i') { + /* set inactive */ + state |= DS_INACTIVE_DST; + if((sp.len>1) && (sp.s[1]=='P' || sp.s[1]=='p')) + state |= DS_PROBING_DST; + } else if(sp.s[0]=='1' || sp.s[0]=='A' || sp.s[0]=='a') { + /* set active */ + if((sp.len>1) && (sp.s[1]=='P' || sp.s[1]=='p')) + state |= DS_PROBING_DST; + } else if(sp.s[0]=='2' || sp.s[0]=='D' || sp.s[0]=='d') { + /* set disabled */ + state |= DS_DISABLED_DST; + } else { + LM_ERR("unknow state value\n"); + return init_mi_tree(500, "unknown state value", 19); + } node = node->next; if(node == NULL) - return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); + return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); sp = node->value; if(sp.s == NULL) { @@ -676,10 +690,7 @@ static struct mi_root* ds_mi_set(struct mi_root* cmd_tree, void* param) return init_mi_tree(500,"address not found", 18 ); }
- if(state==1) - ret = ds_set_state(group, &sp, DS_INACTIVE_DST, 0); - else - ret = ds_set_state(group, &sp, DS_INACTIVE_DST, 1); + ret = ds_reinit_state(group, &sp, state);
if(ret!=0) {