Browse Source

cfg_rpc: group can be specified for cfg.list

- cfg.list without any parameter lists all the cfg variables.
- cfg.list <group name> lists only the variables of the specific group.
Miklos Tirpak 15 years ago
parent
commit
f6f6e6c813
3 changed files with 16 additions and 5 deletions
  1. 2 2
      modules/cfg_rpc/README
  2. 12 2
      modules/cfg_rpc/cfg_rpc.c
  3. 2 1
      modules/cfg_rpc/doc/rpc.xml

+ 2 - 2
modules/cfg_rpc/README

@@ -60,8 +60,8 @@ Miklos Tirpak
        can optionally contain the group instance id, for example foo[5].
      * cfg.help - Print the description of a configuration variable. The
        function accepts two parameters: group name, variable name.
-     * cfg.list - List the configuration variables. The function does not
-       have any parameters.
+     * cfg.list - List the configuration variables. The function has one
+       optional parameter: group name.
      * cfg.diff - List the pending configuration changes that have not
        been committed yet. The function does not have any parameters.
      * cfg.add_group_inst - Add a new instance to an existing

+ 12 - 2
modules/cfg_rpc/cfg_rpc.c

@@ -353,11 +353,21 @@ static void rpc_list(rpc_t* rpc, void* c)
 	str		gname;
 	cfg_def_t	*def;
 	int		i;
+	str		group;
+
+	if (rpc->scan(c, "*S", &group) < 1) {
+		group.s = NULL;
+		group.len = 0;
+	}
 
 	cfg_get_group_init(&h);
 	while(cfg_get_group_next(&h, &gname, &def))
-		for (i=0; def[i].name; i++)
-			rpc->printf(c, "%.*s: %s", gname.len, gname.s, def[i].name);
+		if (!group.len
+			|| ((gname.len == group.len)
+				&& (memcmp(gname.s, group.s, group.len) == 0))
+		)
+			for (i=0; def[i].name; i++)
+				rpc->printf(c, "%.*s: %s", gname.len, gname.s, def[i].name);
 }
 
 static const char* rpc_diff_doc[2] = {

+ 2 - 1
modules/cfg_rpc/doc/rpc.xml

@@ -100,7 +100,8 @@
 	<listitem>
 	    <para>
 		<emphasis>cfg.list</emphasis> - List the configuration
-		variables. The function does not have any parameters.
+		variables. The function has one optional parameter:
+		group name.
 	    </para>
 	</listitem>
 	<listitem>