Browse code

Merge 136f321c3609b56a4d9120fe98ea6a16fee46c82 into f0e8898d83c54e5e4383b70ba54ad340c5ae13b6

Stefan Mititelu authored on 18/10/2021 11:57:03 • GitHub committed on 18/10/2021 11:57:03
Showing 2 changed files
... ...
@@ -50,6 +50,7 @@ static void cr_rpc_reload_routes(rpc_t *rpc, void *c) {
50 50
 		if (carrierroute_dbh==NULL) {
51 51
 			carrierroute_dbh = carrierroute_dbf.init(&carrierroute_db_url);
52 52
 			if(carrierroute_dbh==0 ) {
53
+				rpc->fault(c, 500, "Internal error -- cannot initialize database connection");
53 54
 				LM_ERR("cannot initialize database connection\n");
54 55
 				return;
55 56
 			}
... ...
@@ -57,6 +58,7 @@ static void cr_rpc_reload_routes(rpc_t *rpc, void *c) {
57 58
 	}
58 59
 
59 60
 	if ( (reload_route_data())!=0 ) {
61
+		rpc->fault(c, 500, "Internal error -- failed to load routing data\n");
60 62
 		LM_ERR("failed to load routing data\n");
61 63
 		return;
62 64
 	}
... ...
@@ -235,13 +235,13 @@ int dump_tree_recursor (rpc_t* rpc, void* ctx, void *gh,
235 235
 			struct dtrie_node_t *node, char *prefix)
236 236
 {
237 237
 	char s[256];
238
-	char rbuf[1024];
239 238
 	char *p;
240 239
 	int i,len;
241 240
 	struct route_flags *rf;
242 241
 	struct route_rule *rr;
243 242
 	struct route_rule_p_list * rl;
244 243
 	double prob;
244
+	void* hh, *ih;
245 245
 
246 246
 	len=strlen(prefix);
247 247
 	if (len > 254) {
... ...
@@ -267,39 +267,45 @@ int dump_tree_recursor (rpc_t* rpc, void* ctx, void *gh,
267 267
 			} else {
268 268
 				prob = rr->prob;
269 269
 			}
270
-			snprintf(rbuf, 1024,
271
-					"%10s: %0.3f %%, '%.*s': %s, '%i', '%.*s', '%.*s', '%.*s'",
272
-					len > 0 ? prefix : "NULL", prob * 100,
273
-					rr->host.len, rr->host.s,
274
-					(rr->status ? "ON" : "OFF"), rr->strip,
275
-					rr->local_prefix.len, rr->local_prefix.s,
276
-					rr->local_suffix.len, rr->local_suffix.s,
277
-					rr->comment.len, rr->comment.s);
278
-			if (rpc->array_add(gh, "s", rbuf)<0)
270
+
271
+			if (rpc->array_add(gh, "{", &hh)<0)
279 272
 			{
280 273
 				rpc->fault(ctx, 500, "Failed to add data to response");
281 274
 				return -1;
282 275
 			}
283 276
 
277
+			if(rpc->struct_add(hh, "sfSsdSSS",
278
+					"prefix", len > 0 ? prefix : "NULL",
279
+					"prob", prob * 100,
280
+					"host",  &rr->host,
281
+					"status",(rr->status ? "ON" : "OFF"),
282
+					"strip", rr->strip,
283
+					"prefix", &rr->local_prefix,
284
+					"suffix", &rr->local_suffix,
285
+					"comment", &rr->comment)<0)
286
+			{
287
+				rpc->fault(ctx, 500, "Internal error - routes structure");
288
+								return -1;
289
+			}
290
+
284 291
 			if(!rr->status && rr->backup && rr->backup->rr){
285
-				snprintf(rbuf, 1024,
286
-						"            Rule is backed up by: %.*s",
287
-						rr->backup->rr->host.len, rr->backup->rr->host.s);
288
-				if (rpc->array_add(gh, "s", rbuf)<0)
292
+				if (rpc->struct_add(hh, "S", "backup_by", &rr->backup->rr->host)<0)
289 293
 				{
290 294
 					rpc->fault(ctx, 500, "Failed to add backup by info to response");
291 295
 					return -1;
292 296
 				}
293 297
 			}
294 298
 			if(rr->backed_up){
299
+				if (rpc->struct_add(hh, "[", "backup_for", &ih)<0)
300
+				{
301
+					rpc->fault(ctx, 500, "Failed to add backup for data to response");
302
+					return -1;
303
+				}
295 304
 				rl = rr->backed_up;
296 305
 				i=0;
297 306
 				while(rl){
298 307
 					if(rl->rr){
299
-						snprintf(rbuf, 1024,
300
-								"            Rule is backup for: %.*s",
301
-								rl->rr->host.len, rl->rr->host.s);
302
-						if (rpc->array_add(gh, "s", rbuf)<0)
308
+						if (rpc->array_add(ih, "S", &rl->rr->host)<0)
303 309
 						{
304 310
 							rpc->fault(ctx, 500, "Failed to add backup for data to response");
305 311
 							return -1;