Browse code

dispatcher: ds_load_mode - control behaviour when adding destinations

- 0 (default) - skip when failing to add a destination address (current
behaviour)
- 1 - throw error when failing to add a destination address

Daniel-Constantin Mierla authored on 08/02/2019 14:10:35
Showing 2 changed files
... ...
@@ -91,6 +91,7 @@ extern int ds_ping_latency_stats;
91 91
 extern float ds_latency_estimator_alpha;
92 92
 extern int ds_attrs_none;
93 93
 extern param_t *ds_db_extra_attrs_list;
94
+extern int ds_load_mode;
94 95
 
95 96
 static db_func_t ds_dbf;
96 97
 static db1_con_t *ds_db_handle = NULL;
... ...
@@ -829,12 +830,16 @@ int ds_load_list(char *lfile)
829 829
 			p++;
830 830
 		attrs.len = p - attrs.s;
831 831
 
832
-	add_destination:
832
+add_destination:
833 833
 		if(add_dest2list(id, uri, flags, priority, &attrs, *next_idx, &setn)
834
-				!= 0)
834
+				!= 0) {
835 835
 			LM_WARN("unable to add destination %.*s to set %d -- skipping\n",
836 836
 					uri.len, uri.s, id);
837
-	next_line:
837
+			if(ds_load_mode==1) {
838
+				goto error;
839
+			}
840
+		}
841
+next_line:
838 842
 		p = fgets(line, 1024, f);
839 843
 	}
840 844
 
... ...
@@ -1081,6 +1086,9 @@ int ds_load_db(void)
1081 1081
 			dest_errs++;
1082 1082
 			LM_WARN("unable to add destination %.*s to set %d -- skipping\n",
1083 1083
 					uri.len, uri.s, id);
1084
+			if(ds_load_mode==1) {
1085
+				goto err2;
1086
+			}
1084 1087
 		}
1085 1088
 	}
1086 1089
 	if(reindex_dests(ds_lists[*next_idx]) != 0) {
... ...
@@ -2345,8 +2353,13 @@ int ds_update_dst(struct sip_msg *msg, int upos, int mode)
2345 2345
 void ds_add_dest_cb(ds_set_t *node, int i)
2346 2346
 {
2347 2347
 	int setn;
2348
-	add_dest2list(node->id, node->dlist[i].uri, node->dlist[i].flags, node->dlist[i].priority,
2349
-		&node->dlist[i].attrs.body, *next_idx, &setn);
2348
+
2349
+	if(add_dest2list(node->id, node->dlist[i].uri, node->dlist[i].flags,
2350
+			node->dlist[i].priority, &node->dlist[i].attrs.body, *next_idx,
2351
+			&setn) != 0) {
2352
+		LM_WARN("failed to add destination in group %d - %.*s\n",
2353
+				node->id, node->dlist[i].uri.len, node->dlist[i].uri.s);
2354
+	}
2350 2355
 	return;
2351 2356
 }
2352 2357
 
... ...
@@ -2369,8 +2382,12 @@ int ds_add_dst(int group, str *address, int flags)
2369 2369
 
2370 2370
 	// add new destination
2371 2371
 	if(add_dest2list(group, *address, flags, priority, &attrs,
2372
-		*next_idx, &setn) != 0)
2372
+			*next_idx, &setn) != 0) {
2373 2373
 		LM_WARN("unable to add destination %.*s to set %d", address->len, address->s, group);
2374
+		if(ds_load_mode==1) {
2375
+			goto error;
2376
+		}
2377
+	}
2374 2378
 
2375 2379
 	if(reindex_dests(ds_lists[*next_idx]) != 0) {
2376 2380
 		LM_ERR("error on reindex\n");
... ...
@@ -116,6 +116,7 @@ int ds_hash_initexpire = 7200;
116 116
 int ds_hash_check_interval = 30;
117 117
 int ds_timer_mode = 0;
118 118
 int ds_attrs_none = 0;
119
+int ds_load_mode = 0;
119 120
 
120 121
 str ds_outbound_proxy = STR_NULL;
121 122
 
... ...
@@ -269,6 +270,7 @@ static param_export_t params[]={
269 269
 	{"event_callback",     PARAM_STR, &ds_event_callback},
270 270
 	{"ds_attrs_none",      PARAM_INT, &ds_attrs_none},
271 271
 	{"ds_db_extra_attrs",  PARAM_STR, &ds_db_extra_attrs},
272
+	{"ds_load_mode",       PARAM_INT, &ds_load_mode},
272 273
 	{0,0,0}
273 274
 };
274 275