Browse code

cfgt: fix detection of jump to previous-previous route

* this happends with onsend_route

Marco Capetta authored on 29/11/2019 08:28:45
Showing 1 changed files
... ...
@@ -327,7 +327,7 @@ void cfgt_save_node(cfgt_node_p node)
327 327
 	}
328 328
 	dest.s[dir] = '\0';
329 329
 	LM_DBG("dir [%s]\n", dest.s);
330
-	if (stat(dest.s, &sb) == 0 && S_ISDIR(sb.st_mode)) {
330
+	if(stat(dest.s, &sb) == 0 && S_ISDIR(sb.st_mode)) {
331 331
 		LM_DBG("dir [%s] already existing\n", dest.s);
332 332
 	} else if(mkdir(dest.s, S_IRWXO | S_IXGRP | S_IRWXU) < 0) {
333 333
 		LM_ERR("failed to make directory: %s\n", strerror(errno));
... ...
@@ -465,9 +465,15 @@ int _cfgt_add_routename(cfgt_node_p node, struct action *a, str *routename)
465 465
 	} else {
466 466
 		LM_DBG("actual routename:[%.*s][%d]\n", node->route->s.len,
467 467
 				node->route->s.s, node->route->type);
468
-		if(node->route->prev)
468
+		if(node->route->prev) {
469
+			if(node->route->prev->prev)
470
+				LM_DBG("prev prev routename:[%.*s][%d]\n",
471
+						node->route->prev->prev->s.len,
472
+						node->route->prev->prev->s.s,
473
+						node->route->prev->prev->type);
469 474
 			LM_DBG("prev routename:[%.*s][%d]\n", node->route->prev->s.len,
470 475
 					node->route->prev->s.s, node->route->prev->type);
476
+		}
471 477
 		if(node->route->next)
472 478
 			LM_DBG("next routename:[%.*s][%d]\n", node->route->next->s.len,
473 479
 					node->route->next->s.s, node->route->next->type);
... ...
@@ -475,12 +481,20 @@ int _cfgt_add_routename(cfgt_node_p node, struct action *a, str *routename)
475 475
 			LM_DBG("same route\n");
476 476
 			_cfgt_set_type(node->route, a);
477 477
 			return 2;
478
-		} else if(node->route->prev
479
-				  && STR_EQ(*routename, node->route->prev->s)) {
480
-			LM_DBG("back to route[%.*s]\n", node->route->prev->s.len,
481
-					node->route->prev->s.s);
482
-			_cfgt_set_type(node->route->prev, a);
483
-			return 3;
478
+		} else if(node->route->prev) {
479
+			if(STR_EQ(*routename, node->route->prev->s)) {
480
+				LM_DBG("back to prev route[%.*s]\n", node->route->prev->s.len,
481
+						node->route->prev->s.s);
482
+				_cfgt_set_type(node->route->prev, a);
483
+				return 3;
484
+			} else if(node->route->prev->prev
485
+					  && STR_EQ(*routename, node->route->prev->prev->s)) {
486
+				LM_DBG("back to prev prev route[%.*s]\n",
487
+						node->route->prev->prev->s.len,
488
+						node->route->prev->prev->s.s);
489
+				_cfgt_set_type(node->route->prev->prev, a);
490
+				return 3;
491
+			}
484 492
 		}
485 493
 		route = pkg_malloc(sizeof(cfgt_str_list_t));
486 494
 		if(!route) {
... ...
@@ -488,6 +502,9 @@ int _cfgt_add_routename(cfgt_node_p node, struct action *a, str *routename)
488 488
 			return -1;
489 489
 		}
490 490
 		memset(route, 0, sizeof(cfgt_str_list_t));
491
+		if(route->prev && node->route->prev) {
492
+			route->prev->prev = node->route->prev;
493
+		}
491 494
 		route->prev = node->route;
492 495
 		node->route->next = route;
493 496
 		node->route = route;