Browse code

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

Daniel-Constantin Mierla authored on 31/01/2011 00:19:23
Showing 3 changed files
... ...
@@ -2012,6 +2012,9 @@ int ds_mark_dst(struct sip_msg *msg, int mode)
2012 2012
 	return (ret==0)?1:-1;
2013 2013
 }
2014 2014
 
2015
+/**
2016
+ *
2017
+ */
2015 2018
 int ds_set_state(int group, str *address, int state, int type)
2016 2019
 {
2017 2020
 	int i=0;
... ...
@@ -2075,6 +2078,44 @@ int ds_set_state(int group, str *address, int state, int type)
2075 2078
 	return -1;
2076 2079
 }
2077 2080
 
2081
+/**
2082
+ *
2083
+ */
2084
+int ds_reinit_state(int group, str *address, int state)
2085
+{
2086
+	int i=0;
2087
+	ds_set_t *idx = NULL;
2088
+
2089
+	if(_ds_list==NULL || _ds_list_nr<=0)
2090
+	{
2091
+		LM_ERR("the list is null\n");
2092
+		return -1;
2093
+	}
2094
+
2095
+	/* get the index of the set */
2096
+	if(ds_get_index(group, &idx)!=0)
2097
+	{
2098
+		LM_ERR("destination set [%d] not found\n", group);
2099
+		return -1;
2100
+	}
2101
+
2102
+	for(i=0; i<idx->nr; i++)
2103
+	{
2104
+		if(idx->dlist[i].uri.len==address->len
2105
+				&& strncasecmp(idx->dlist[i].uri.s, address->s,
2106
+					address->len)==0)
2107
+		{
2108
+			idx->dlist[i].flags |= state;
2109
+			return 0;
2110
+		}
2111
+	}
2112
+	LM_ERR("destination address [%d : %.*s] not found\n", group,
2113
+			address->len, address->s);
2114
+	return -1;
2115
+}
2116
+/**
2117
+ *
2118
+ */
2078 2119
 int ds_print_list(FILE *fout)
2079 2120
 {
2080 2121
 	int j;
... ...
@@ -2298,6 +2339,9 @@ void ds_check_timer(unsigned int ticks, void* param)
2298 2339
 	{
2299 2340
 		for(j=0; j<list->nr; j++)
2300 2341
 		{
2342
+			/* skip addresses set in disabled state by admin */
2343
+			if((list->dlist[j].flags&DS_DISABLED_DST) != 0)
2344
+				continue;
2301 2345
 			/* If the Flag of the entry has "Probing set, send a probe:	*/
2302 2346
 			if (ds_probing_mode==1 ||
2303 2347
 					(list->dlist[j].flags&DS_PROBING_DST) != 0)
... ...
@@ -51,7 +51,8 @@
51 51
 
52 52
 #define DS_INACTIVE_DST		1  /*!< inactive destination */
53 53
 #define DS_PROBING_DST		2  /*!< checking destination */
54
-#define DS_RESET_FAIL_DST	4  /*!< Reset-Failure-Counter */
54
+#define DS_DISABLED_DST		4  /*!< admin disabled destination */
55
+#define DS_RESET_FAIL_DST	8  /*!< Reset-Failure-Counter */
55 56
 
56 57
 extern str ds_db_url;
57 58
 extern str ds_table_name;
... ...
@@ -98,6 +99,7 @@ int ds_destroy_list(void);
98 99
 int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
99 100
 int ds_next_dst(struct sip_msg *msg, int mode);
100 101
 int ds_set_state(int group, str *address, int state, int type);
102
+int ds_reinit_state(int group, str *address, int state);
101 103
 int ds_mark_dst(struct sip_msg *msg, int mode);
102 104
 int ds_print_list(FILE *fout);
103 105
 int ds_print_mi_list(struct mi_node* rpl);
... ...
@@ -640,20 +640,34 @@ static struct mi_root* ds_mi_set(struct mi_root* cmd_tree, void* param)
640 640
 
641 641
 	node = cmd_tree->node.kids;
642 642
 	if(node == NULL)
643
-		return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
643
+		return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
644 644
 	sp = node->value;
645 645
 	if(sp.len<=0 || !sp.s)
646 646
 	{
647 647
 		LM_ERR("bad state value\n");
648
-		return init_mi_tree( 500, "bad state value", 15);
648
+		return init_mi_tree(500, "bad state value", 15);
649 649
 	}
650 650
 
651
-	state = 1;
652
-	if(sp.s[0]=='0' || sp.s[0]=='I' || sp.s[0]=='i')
653
-		state = 0;
651
+	state = 0;
652
+	if(sp.s[0]=='0' || sp.s[0]=='I' || sp.s[0]=='i') {
653
+		/* set inactive */
654
+		state |= DS_INACTIVE_DST;
655
+		if((sp.len>1) && (sp.s[1]=='P' || sp.s[1]=='p'))
656
+			state |= DS_PROBING_DST;
657
+	} else if(sp.s[0]=='1' || sp.s[0]=='A' || sp.s[0]=='a') {
658
+		/* set active */
659
+		if((sp.len>1) && (sp.s[1]=='P' || sp.s[1]=='p'))
660
+			state |= DS_PROBING_DST;
661
+	} else if(sp.s[0]=='2' || sp.s[0]=='D' || sp.s[0]=='d') {
662
+		/* set disabled */
663
+		state |= DS_DISABLED_DST;
664
+	} else {
665
+		LM_ERR("unknow state value\n");
666
+		return init_mi_tree(500, "unknown state value", 19);
667
+	}
654 668
 	node = node->next;
655 669
 	if(node == NULL)
656
-		return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
670
+		return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
657 671
 	sp = node->value;
658 672
 	if(sp.s == NULL)
659 673
 	{
... ...
@@ -676,10 +690,7 @@ static struct mi_root* ds_mi_set(struct mi_root* cmd_tree, void* param)
676 690
 		return init_mi_tree(500,"address not found", 18 );
677 691
 	}
678 692
 
679
-	if(state==1)
680
-		ret = ds_set_state(group, &sp, DS_INACTIVE_DST, 0);
681
-	else
682
-		ret = ds_set_state(group, &sp, DS_INACTIVE_DST, 1);
693
+	ret = ds_reinit_state(group, &sp, state);
683 694
 
684 695
 	if(ret!=0)
685 696
 	{