Bläddra i källkod

Fix sequences in konfd

git-svn-id: https://klish.googlecode.com/svn/trunk@405 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 år sedan
förälder
incheckning
8e0b5091a3
3 ändrade filer med 22 tillägg och 3 borttagningar
  1. 16 3
      konf/tree/tree.c
  2. 1 0
      lub/list.h
  3. 5 0
      lub/list/list.c

+ 16 - 3
konf/tree/tree.c

@@ -197,8 +197,10 @@ konf_tree_t *konf_tree_new_conf(konf_tree_t * this,
 	/* Insert it into the binary tree for this conf */
 	lub_list_add(this->list, newconf);
 
-	if (seq)
+	if (seq) {
 		normalize_seq(this, priority);
+		konf_tree__set_sub_num(newconf, KONF_ENTRY_OK);
+	}
 
 	return newconf;
 }
@@ -210,6 +212,7 @@ konf_tree_t *konf_tree_find_conf(konf_tree_t * this,
 	konf_tree_t *conf;
 	lub_list_node_t *iter;
 	int check_pri = 0;
+	char *lower_line;
 
 	/* If list is empty */
 	if (!(iter = lub_list__get_head(this->list)))
@@ -218,6 +221,7 @@ konf_tree_t *konf_tree_find_conf(konf_tree_t * this,
 	if ((0 != priority) && (0 != seq_num))
 		check_pri = 1;
 	/* Iterate non-empty tree */
+	lower_line = lub_string_tolower(line);
 	do {
 		conf = (konf_tree_t *)lub_list_node__get_data(iter);
 		if (check_pri) {
@@ -230,9 +234,12 @@ konf_tree_t *konf_tree_find_conf(konf_tree_t * this,
 			if (seq_num < conf->seq_num)
 				break;
 		}
-		if (0 == lub_string_nocasecmp(conf->line, line))
-				return conf;
+		if (!strcmp(conf->lower_line, lower_line)) {
+			lub_string_free(lower_line);
+			return conf;
+		}
 	} while ((iter = lub_list_node__get_next(iter)));
+	lub_string_free(lower_line);
 
 	return NULL;
 }
@@ -246,6 +253,7 @@ int konf_tree_del_pattern(konf_tree_t *this,
 	int res = 0;
 	konf_tree_t *conf;
 	lub_list_node_t *iter;
+	lub_list_node_t *tmp;
 	regex_t regexp;
 	int del_cnt = 0; /* how many strings were deleted */
 
@@ -260,6 +268,7 @@ int konf_tree_del_pattern(konf_tree_t *this,
 	regcomp(&regexp, pattern, REG_EXTENDED | REG_ICASE);
 
 	/* Iterate configuration tree */
+	tmp = lub_list_node_new(NULL);
 	do {
 		conf = (konf_tree_t *)lub_list_node__get_data(iter);
 		if ((0 != priority) &&
@@ -278,8 +287,12 @@ int konf_tree_del_pattern(konf_tree_t *this,
 		}
 		lub_list_del(this->list, iter);
 		konf_tree_delete(conf);
+		lub_list_node_copy(tmp, iter);
+		lub_list_node_free(iter);
+		iter = tmp;
 		del_cnt++;
 	} while ((iter = lub_list_node__get_next(iter)));
+	lub_list_node_free(tmp);
 
 	regfree(&regexp);
 

+ 1 - 0
lub/list.h

@@ -81,6 +81,7 @@ lub_list_node_t *lub_list_iterator_next(lub_list_node_t *node);
 lub_list_node_t *lub_list_iterator_prev(lub_list_node_t *node);
 lub_list_node_t *lub_list_add(lub_list_t *list, void *data);
 void lub_list_del(lub_list_t *list, lub_list_node_t *node);
+inline void lub_list_node_copy(lub_list_node_t *dst, lub_list_node_t *src);
 
 #endif				/* _lub_list_h */
 

+ 5 - 0
lub/list/list.c

@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <assert.h>
+#include <string.h>
 
 #include "private.h"
 
@@ -164,4 +165,8 @@ void lub_list_del(lub_list_t *this, lub_list_node_t *node)
 		this->tail = node->prev;
 }
 
+inline void lub_list_node_copy(lub_list_node_t *dst, lub_list_node_t *src)
+{
+	memcpy(dst, src, sizeof(lub_list_node_t));
+}
 /*--------------------------------------------------------- */