Browse code

mtree: mt_reload updated

- reload function takes in consideration the operation mode

Daniel-Constantin Mierla authored on 15/03/2010 11:16:58
Showing 1 changed files
... ...
@@ -726,42 +726,52 @@ static struct mi_root* mt_mi_reload(struct mi_root *cmd_tree, void *param)
726 726
 	m_tree_t *pt;
727 727
 	struct mi_node* node = NULL;
728 728
 
729
-	if(!mt_defined_trees())
729
+	if(db_table.len>0)
730 730
 	{
731
-		LM_ERR("empty tree list\n");
732
-		return init_mi_tree( 500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN);
733
-	}
731
+		/* re-loading all information from database */
732
+		if(mt_load_db_trees()!=0)
733
+		{
734
+			LM_ERR("cannot re-load info from database\n");
735
+			goto error;
736
+		}
737
+	} else {
738
+		if(!mt_defined_trees())
739
+		{
740
+			LM_ERR("empty tree list\n");
741
+			return init_mi_tree( 500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN);
742
+		}
734 743
 
735
-	/* read tree name */
736
-	node = cmd_tree->node.kids;
737
-	if(node != NULL)
738
-	{
739
-		tname = node->value;
740
-		if(tname.s == NULL || tname.len== 0)
741
-			return init_mi_tree( 404, "domain not found", 16);
744
+		/* read tree name */
745
+		node = cmd_tree->node.kids;
746
+		if(node != NULL)
747
+		{
748
+			tname = node->value;
749
+			if(tname.s == NULL || tname.len== 0)
750
+				return init_mi_tree( 404, "domain not found", 16);
742 751
 
743
-		if(*tname.s=='.') {
744
-			tname.s = 0;
745
-			tname.len = 0;
752
+			if(*tname.s=='.') {
753
+				tname.s = 0;
754
+				tname.len = 0;
755
+			}
746 756
 		}
747
-	}
748 757
 
749
-	pt = mt_get_first_tree();
758
+		pt = mt_get_first_tree();
750 759
 	
751
-	while(pt!=NULL)
752
-	{
753
-		if(tname.s==NULL || 
754
-			(tname.s!=NULL && pt->tname.len>=tname.len && 
755
-			 strncmp(pt->tname.s, tname.s, tname.len)==0))
760
+		while(pt!=NULL)
756 761
 		{
757
-			/* re-loading table from database */
758
-			if(mt_load_db(&pt->tname)!=0)
762
+			if(tname.s==NULL
763
+				|| (tname.s!=NULL && pt->tname.len>=tname.len
764
+					&& strncmp(pt->tname.s, tname.s, tname.len)==0))
759 765
 			{
760
-				LM_ERR("cannot re-load info from database\n");	
761
-				goto error;
766
+				/* re-loading table from database */
767
+				if(mt_load_db(&pt->tname)!=0)
768
+				{
769
+					LM_ERR("cannot re-load info from database\n");	
770
+					goto error;
771
+				}
762 772
 			}
773
+			pt = pt->next;
763 774
 		}
764
-		pt = pt->next;
765 775
 	}
766 776
 	
767 777
 	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);