Преглед изворни кода

cfg_rpc: configuration reset function has been implemented

- rpc_reset function enables to reset all the variables of a certain group to their initial values.
  e.g.: kamcmd cfg.reset core.
  Above given example will reset all variables of the configuration group "core".
Huseyin Dikme пре 8 година
родитељ
комит
245a28b666
2 измењених фајлова са 72 додато и 0 уклоњено
  1. 56 0
      src/modules/cfg_rpc/cfg_rpc.c
  2. 16 0
      src/modules/cfg_rpc/doc/rpc.xml

+ 56 - 0
src/modules/cfg_rpc/cfg_rpc.c

@@ -355,6 +355,61 @@ static void rpc_get(rpc_t* rpc, void* c)
 	}
 	}
 
 
 }
 }
+static const char* rpc_reset_doc[2] = {
+       "Reset all the values of a configuration group and commit the change immediately",
+       0
+};
+
+static void rpc_reset(rpc_t* rpc, void* c)
+{
+	void	*h;
+	str	gname, var;
+	cfg_def_t	*def;
+	void	*val;
+	int	i, ret;
+	str	group;
+	char	*ch;
+	unsigned int	*group_id;
+	unsigned int	val_type;
+	unsigned int	input_type;
+
+	if (rpc->scan(c, "S", &group) < 1)
+		return;
+
+	if (get_group_id(&group, &group_id)) {
+		rpc->fault(c, 400, "Wrong group syntax. Use either \"group\", or \"group[id]\"");
+	return;
+	}
+
+	cfg_get_group_init(&h);
+	while(cfg_get_group_next(&h, &gname, &def))
+		if (((gname.len == group.len) && (memcmp(gname.s, group.s, group.len) == 0)))
+		{
+			for (i=0; def[i].name; i++){
+
+				var.s = def[i].name;
+				var.len = (int)strlen(def[i].name);
+				ret = cfg_get_default_value_by_name(ctx, &gname, group_id, &var,
+						&val, &val_type);
+
+				if (ret != 0)
+					continue;
+
+				if (cfg_help(ctx, &group, &var,
+							&ch, &input_type)
+					) {
+					rpc->fault(c, 400, "Failed to get the variable description");
+					return;
+				}
+
+				if (input_type == CFG_INPUT_INT)
+					cfg_set_now_int(ctx, &gname, group_id, &var, val);
+				else if (input_type == CFG_INPUT_STRING)
+					cfg_set_now_string(ctx, &gname, group_id, &var, val);
+			}
+		}
+}
+
 
 
 static const char* rpc_help_doc[2] = {
 static const char* rpc_help_doc[2] = {
         "Print the description of a configuration variable",
         "Print the description of a configuration variable",
@@ -546,6 +601,7 @@ static rpc_export_t rpc_calls[] = {
 	{"cfg.commit",		rpc_commit,		rpc_commit_doc,		0},
 	{"cfg.commit",		rpc_commit,		rpc_commit_doc,		0},
 	{"cfg.rollback",	rpc_rollback,		rpc_rollback_doc,	0},
 	{"cfg.rollback",	rpc_rollback,		rpc_rollback_doc,	0},
 	{"cfg.get",		rpc_get,		rpc_get_doc,		0},
 	{"cfg.get",		rpc_get,		rpc_get_doc,		0},
+	{"cfg.reset",           rpc_reset,              rpc_reset_doc,          0},
 	{"cfg.help",		rpc_help,		rpc_help_doc,		0},
 	{"cfg.help",		rpc_help,		rpc_help_doc,		0},
 	{"cfg.list",		rpc_list,		rpc_list_doc,		0},
 	{"cfg.list",		rpc_list,		rpc_list_doc,		0},
 	{"cfg.diff",		rpc_diff,		rpc_diff_doc,		0},
 	{"cfg.diff",		rpc_diff,		rpc_diff_doc,		0},

+ 16 - 0
src/modules/cfg_rpc/doc/rpc.xml

@@ -87,6 +87,22 @@
 ...
 ...
 # &kamcmd; cfg.sets voicemail srv_ip "1.2.3.4"
 # &kamcmd; cfg.sets voicemail srv_ip "1.2.3.4"
 ...
 ...
+</programlisting>
+                </example>
+        </section>
+        <section id="cfg_rpc.rpc.reset">
+    <title>cfg.reset</title>
+            <para>
+                <emphasis>cfg.reset</emphasis> - Reset the variable values of
+                a configuration group. The function accepts only one parameter:
+                group name.
+            </para>
+                <example>
+                <title>Use <varname>cfg.reset</varname> RPC command</title>
+                <programlisting format="linespecific">
+...
+# &sercmd; cfg.reset core
+...
 </programlisting>
 </programlisting>
 		</example>
 		</example>
 	</section>
 	</section>