Browse Source

Implement -h option for konfd protocol. It defines the maximal depth of output for --dump command.

git-svn-id: https://klish.googlecode.com/svn/trunk@465 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
f6e29b07f4
7 changed files with 35 additions and 8 deletions
  1. 2 1
      bin/konfd.c
  2. 1 0
      clish/shell/shell_var.c
  3. 1 0
      konf/query.h
  4. 2 1
      konf/query/private.h
  5. 22 1
      konf/query/query.c
  6. 2 1
      konf/tree.h
  7. 5 4
      konf/tree/tree.c

+ 2 - 1
bin/konfd.c

@@ -413,7 +413,7 @@ static char * process_query(int sock, konf_tree_t * conf, char *str)
 
 #ifdef DEBUG
 	/* Print whole tree */
-	konf_tree_fprintf(conf, stderr, NULL, -1, BOOL_TRUE, 0);
+	konf_tree_fprintf(conf, stderr, NULL, -1, -1, BOOL_TRUE, 0);
 #endif
 
 	/* Free resources */
@@ -478,6 +478,7 @@ static int dump_running_config(int sock, konf_tree_t *conf, konf_query_t *query)
 		fd,
 		konf_query__get_pattern(query),
 		konf_query__get_pwdc(query) - 1,
+		konf_query__get_depth(query),
 		konf_query__get_seq(query),
 		0);
 	if (!filename) {

+ 1 - 0
clish/shell/shell_var.c

@@ -38,6 +38,7 @@ void clish_shell__expand_viewid(const char *viewid, lub_bintree_t *tree,
 		var = clish_var_new(q);
 		lub_bintree_insert(tree, var);
 		clish_var__set_value(var, value);
+printf("%s=%s\n", q, value);
 	}
 	lub_string_free(expanded);
 }

+ 1 - 0
konf/query.h

@@ -34,5 +34,6 @@ bool_t konf_query__get_splitter(konf_query_t *instance);
 bool_t konf_query__get_seq(konf_query_t *instance);
 unsigned short konf_query__get_seq_num(konf_query_t *instance);
 bool_t konf_query__get_unique(konf_query_t *instance);
+int konf_query__get_depth(konf_query_t *instance);
 
 #endif

+ 2 - 1
konf/query/private.h

@@ -10,13 +10,14 @@ struct konf_query_s {
 	unsigned short priority;
 	bool_t seq; /* sequence aka auto priority */
 	unsigned short seq_num; /* sequence number */
-	unsigned pwdc;
+	unsigned int pwdc;
 	char **pwd;
 	char *line;
 	char *lower_line;
 	char *path;
 	bool_t splitter;
 	bool_t unique;
+	int depth;
 };
 
 #endif

+ 22 - 1
konf/query/query.c

@@ -35,6 +35,7 @@ konf_query_t *konf_query_new(void)
 	this->path = NULL;
 	this->splitter = BOOL_TRUE;
 	this->unique = BOOL_TRUE;
+	this->depth = -1;
 
 	return this;
 }
@@ -83,7 +84,7 @@ int konf_query_parse(konf_query_t *this, int argc, char **argv)
 	unsigned i = 0;
 	int pwdc = 0;
 
-	static const char *shortopts = "suoedtp:q:r:l:f:in";
+	static const char *shortopts = "suoedtp:q:r:l:f:inh:";
 #ifdef HAVE_GETOPT_H
 	static const struct option longopts[] = {
 		{"set",		0, NULL, 's'},
@@ -99,6 +100,7 @@ int konf_query_parse(konf_query_t *this, int argc, char **argv)
 		{"file",	1, NULL, 'f'},
 		{"splitter",	0, NULL, 'i'},
 		{"non-unique",	0, NULL, 'n'},
+		{"depth",	1, NULL, 'h'},
 		{NULL,		0, NULL, 0}
 	};
 #endif
@@ -175,6 +177,19 @@ int konf_query_parse(konf_query_t *this, int argc, char **argv)
 		case 'n':
 			this->unique = BOOL_FALSE;
 			break;
+		case 'h':
+			{
+			long val = 0;
+			char *endptr;
+
+			val = strtol(optarg, &endptr, 0);
+			if (endptr == optarg)
+				break;
+			if ((val > 0xffff) || (val < 0))
+				break;
+			this->depth = (unsigned short)val;
+			break;
+			}
 		default:
 			break;
 		}
@@ -297,3 +312,9 @@ bool_t konf_query__get_unique(konf_query_t *this)
 {
 	return this->unique;
 }
+
+/*-------------------------------------------------------- */
+int konf_query__get_depth(konf_query_t *this)
+{
+	return this->depth;
+}

+ 2 - 1
konf/tree.h

@@ -38,7 +38,8 @@ konf_tree_t *konf_tree_new(const char *line, unsigned short priority);
  *----------------- */
 void konf_tree_delete(konf_tree_t * instance);
 void konf_tree_fprintf(konf_tree_t * instance, FILE * stream,
-	const char *pattern, int depth, bool_t seq, unsigned char prev_pri_hi);
+	const char *pattern, int top_depth, int depth,
+	bool_t seq, unsigned char prev_pri_hi);
 konf_tree_t *konf_tree_new_conf(konf_tree_t * instance,
 	const char *line, unsigned short priority,
 	bool_t seq, unsigned short seq_num);

+ 5 - 4
konf/tree/tree.c

@@ -104,8 +104,8 @@ void konf_tree_delete(konf_tree_t * this)
 }
 
 /*--------------------------------------------------------- */
-void konf_tree_fprintf(konf_tree_t * this, FILE * stream,
-	const char *pattern, int top_depth,
+void konf_tree_fprintf(konf_tree_t *this, FILE *stream,
+	const char *pattern, int top_depth, int depth,
 	bool_t seq, unsigned char prev_pri_hi)
 {
 	konf_tree_t *conf;
@@ -114,7 +114,8 @@ void konf_tree_fprintf(konf_tree_t * this, FILE * stream,
 	regex_t regexp;
 
 	if (this->line && (*(this->line) != '\0') &&
-		(this->depth > top_depth)) {
+		(this->depth > top_depth) &&
+		((depth < 0 ) || (this->depth <= (top_depth + depth)))) {
 		char *space = NULL;
 		unsigned space_num = this->depth - top_depth - 1;
 		if (space_num > 0) {
@@ -144,7 +145,7 @@ void konf_tree_fprintf(konf_tree_t * this, FILE * stream,
 		conf = (konf_tree_t *)lub_list_node__get_data(iter);
 		if (pattern && (0 != regexec(&regexp, conf->line, 0, NULL, 0)))
 			continue;
-		konf_tree_fprintf(conf, stream, NULL, top_depth, seq, pri);
+		konf_tree_fprintf(conf, stream, NULL, top_depth, depth, seq, pri);
 		pri = konf_tree__get_priority_hi(conf);
 	}
 	if (pattern)