[sr-dev] git:master:245a28b6: cfg_rpc: configuration reset function has been implemented

Huseyin Dikme hueseyin.dikme at 1und1.de
Mon Jul 10 19:24:01 CEST 2017


Module: kamailio
Branch: master
Commit: 245a28b666c027f3d697c92863fd54a837ff4d62
URL: https://github.com/kamailio/kamailio/commit/245a28b666c027f3d697c92863fd54a837ff4d62

Author: Huseyin Dikme <hueseyin.dikme at 1und1.de>
Committer: Huseyin Dikme <hueseyin.dikme at 1und1.de>
Date: 2017-07-04T14:41:37+02:00

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".

---

Modified: src/modules/cfg_rpc/cfg_rpc.c
Modified: src/modules/cfg_rpc/doc/rpc.xml

---

Diff:  https://github.com/kamailio/kamailio/commit/245a28b666c027f3d697c92863fd54a837ff4d62.diff
Patch: https://github.com/kamailio/kamailio/commit/245a28b666c027f3d697c92863fd54a837ff4d62.patch

---

diff --git a/src/modules/cfg_rpc/cfg_rpc.c b/src/modules/cfg_rpc/cfg_rpc.c
index b694d06088..06e775c5c1 100644
--- a/src/modules/cfg_rpc/cfg_rpc.c
+++ b/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] = {
         "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.rollback",	rpc_rollback,		rpc_rollback_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.list",		rpc_list,		rpc_list_doc,		0},
 	{"cfg.diff",		rpc_diff,		rpc_diff_doc,		0},
diff --git a/src/modules/cfg_rpc/doc/rpc.xml b/src/modules/cfg_rpc/doc/rpc.xml
index 9810762c50..9298247d83 100644
--- a/src/modules/cfg_rpc/doc/rpc.xml
+++ b/src/modules/cfg_rpc/doc/rpc.xml
@@ -88,6 +88,22 @@
 # &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>
 		</example>
 	</section>
 	<section id="cfg_rpc.rpc.set_now_string">




More information about the sr-dev mailing list