Browse code

dispatcher: add method to reinit state for all destinations in group

Timmo Verlaan authored on 14/01/2018 15:27:07
Showing 2 changed files
... ...
@@ -2605,6 +2605,39 @@ int ds_reinit_state(int group, str *address, int state)
2605 2605
 	return -1;
2606 2606
 }
2607 2607
 
2608
+/**
2609
+ *
2610
+ */
2611
+int ds_reinit_state_all(int group, int state)
2612
+{
2613
+	int i = 0;
2614
+	ds_set_t *idx = NULL;
2615
+
2616
+	if(_ds_list == NULL || _ds_list_nr <= 0) {
2617
+		LM_ERR("the list is null\n");
2618
+		return -1;
2619
+	}
2620
+
2621
+	/* get the index of the set */
2622
+	if(ds_get_index(group, *crt_idx, &idx) != 0) {
2623
+		LM_ERR("destination set [%d] not found\n", group);
2624
+		return -1;
2625
+	}
2626
+
2627
+	for(i = 0; i < idx->nr; i++) {
2628
+		int old_state = idx->dlist[i].flags;
2629
+		/* reset the bits used for states */
2630
+		idx->dlist[i].flags &= ~(DS_STATES_ALL);
2631
+		/* set the new states */
2632
+		idx->dlist[i].flags |= state;
2633
+		if(idx->dlist[i].attrs.rweight > 0) {
2634
+			ds_reinit_rweight_on_state_change(
2635
+					old_state, idx->dlist[i].flags, idx);
2636
+		}
2637
+	}
2638
+	return 0;
2639
+}
2640
+
2608 2641
 /**
2609 2642
  *
2610 2643
  */
... ...
@@ -115,6 +115,7 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
115 115
 int ds_next_dst(struct sip_msg *msg, int mode);
116 116
 int ds_update_state(sip_msg_t *msg, int group, str *address, int state);
117 117
 int ds_reinit_state(int group, str *address, int state);
118
+int ds_reinit_state_all(int group, int state);
118 119
 int ds_mark_dst(struct sip_msg *msg, int mode);
119 120
 int ds_print_list(FILE *fout);
120 121
 int ds_log_sets(void);