[sr-dev] git:tirpi/cfg_framework_multivalue: cfg_rpc: cfg.set and cfg. set_delayed commands added
Miklos Tirpak
miklos at iptel.org
Tue Oct 5 16:20:12 CEST 2010
Module: sip-router
Branch: tirpi/cfg_framework_multivalue
Commit: cd8c0719514877dd1973fa556002e65396afb0b2
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=cd8c0719514877dd1973fa556002e65396afb0b2
Author: Miklos Tirpak <miklos at iptel.org>
Committer: Miklos Tirpak <miklos at iptel.org>
Date: Tue Oct 5 16:15:44 2010 +0200
cfg_rpc: cfg.set and cfg.set_delayed commands added
cfg.set is a shortcut to cfg.set_now_int and cfg.set_now_string
depending on the parameter type, i.e the syntax is:
cfg.set <group> <var> <int/string value>
or
cfg.set <group>[id] <var> <int/string value>
Similarly, cfg.set_delayed is a shortcut to cfg.set_delayed_int/string
---
modules/cfg_rpc/README | 12 +++++++++
modules/cfg_rpc/cfg_rpc.c | 58 +++++++++++++++++++++++++++++++++++++++++++
modules/cfg_rpc/doc/rpc.xml | 22 ++++++++++++++++
3 files changed, 92 insertions(+), 0 deletions(-)
diff --git a/modules/cfg_rpc/README b/modules/cfg_rpc/README
index 4217506..385ee8d 100644
--- a/modules/cfg_rpc/README
+++ b/modules/cfg_rpc/README
@@ -29,6 +29,12 @@ Miklos Tirpak
commit the change immediately. The function accepts three
parameters: group name, variable name, string value. The group name
can optionally contain the group instance id, for example foo[5].
+ * cfg.set - Set the value of a configuration variable and commit the
+ change immediately. This is a wrapper command for cfg.set_now_int
+ and cfg.set_now_string depending on the type of the value provided.
+ The function accepts three parameters: group name, variable name,
+ int/string value. The group name can optionally contain the group
+ instance id, for example foo[5].
* cfg.set_delayed_int - Prepare the change of a configuration
variable, but does not commit the new value yet. The function
accepts three parameters: group name, variable name, integer value.
@@ -39,6 +45,12 @@ Miklos Tirpak
accepts three parameters: group name, variable name, string value.
The group name can optionally contain the group instance id, for
example foo[5].
+ * cfg.set_delayed - Prepare the change of a configuration variable,
+ but does not commit the new value yet. This is a wrapper command
+ for cfg.set_delayed_int and cfg.set_delayed_string depending on the
+ type of the value provided. The function accepts three parameters:
+ group name, variable name, int/string value. The group name can
+ optionally contain the group instance id, for example foo[5].
* cfg.commit - Commit the previously prepared configuration changes.
The function does not have any parameters.
* cfg.rollback - Drop the prepared configuration changes. The
diff --git a/modules/cfg_rpc/cfg_rpc.c b/modules/cfg_rpc/cfg_rpc.c
index f982d40..0ec588f 100644
--- a/modules/cfg_rpc/cfg_rpc.c
+++ b/modules/cfg_rpc/cfg_rpc.c
@@ -128,6 +128,34 @@ static void rpc_set_now_string(rpc_t* rpc, void* c)
}
}
+static void rpc_set(rpc_t* rpc, void* c)
+{
+ str group, var;
+ int i, err;
+ char *ch;
+ unsigned int *group_id;
+
+ if (rpc->scan(c, "SS", &group, &var) < 2)
+ return;
+
+ if (get_group_id(&group, &group_id)) {
+ rpc->fault(c, 400, "Wrong group syntax. Use either \"group\", or \"group[id]\"");
+ return;
+ }
+
+ if (rpc->scan(c, "d", &i) == 1)
+ err = cfg_set_now_int(ctx, &group, group_id, &var, i);
+ else if (rpc->scan(c, "s", &ch) == 1)
+ err = cfg_set_now_string(ctx, &group, group_id, &var, ch);
+ else
+ return; /* error */
+
+ if (err) {
+ rpc->fault(c, 400, "Failed to set the variable");
+ return;
+ }
+}
+
static const char* rpc_set_delayed_doc[2] = {
"Prepare the change of a configuration variable, but does not commit the new value yet",
0
@@ -173,6 +201,34 @@ static void rpc_set_delayed_string(rpc_t* rpc, void* c)
}
}
+static void rpc_set_delayed(rpc_t* rpc, void* c)
+{
+ str group, var;
+ int i, err;
+ char *ch;
+ unsigned int *group_id;
+
+ if (rpc->scan(c, "SS", &group, &var) < 2)
+ return;
+
+ if (get_group_id(&group, &group_id)) {
+ rpc->fault(c, 400, "Wrong group syntax. Use either \"group\", or \"group[id]\"");
+ return;
+ }
+
+ if (rpc->scan(c, "d", &i) == 1)
+ err = cfg_set_delayed_int(ctx, &group, group_id, &var, i);
+ else if (rpc->scan(c, "s", &ch) == 1)
+ err = cfg_set_delayed_string(ctx, &group, group_id, &var, ch);
+ else
+ return; /* error */
+
+ if (err) {
+ rpc->fault(c, 400, "Failed to set the variable");
+ return;
+ }
+}
+
static const char* rpc_commit_doc[2] = {
"Commit the previously prepared configuration changes",
0
@@ -419,8 +475,10 @@ static void rpc_del_group_inst(rpc_t* rpc, void* c)
}
static rpc_export_t rpc_calls[] = {
+ {"cfg.set", rpc_set, rpc_set_now_doc, 0},
{"cfg.set_now_int", rpc_set_now_int, rpc_set_now_doc, 0},
{"cfg.set_now_string", rpc_set_now_string, rpc_set_now_doc, 0},
+ {"cfg.set_delayed", rpc_set_delayed, rpc_set_delayed_doc, 0},
{"cfg.set_delayed_int", rpc_set_delayed_int, rpc_set_delayed_doc, 0},
{"cfg.set_delayed_string", rpc_set_delayed_string, rpc_set_delayed_doc, 0},
{"cfg.commit", rpc_commit, rpc_commit_doc, 0},
diff --git a/modules/cfg_rpc/doc/rpc.xml b/modules/cfg_rpc/doc/rpc.xml
index 47528d3..24c5769 100644
--- a/modules/cfg_rpc/doc/rpc.xml
+++ b/modules/cfg_rpc/doc/rpc.xml
@@ -30,6 +30,17 @@
</listitem>
<listitem>
<para>
+ <emphasis>cfg.set</emphasis> - Set the value of
+ a configuration variable and commit the change immediately.
+ This is a wrapper command for cfg.set_now_int and cfg.set_now_string
+ depending on the type of the value provided.
+ The function accepts three parameters: group name, variable
+ name, int/string value. The group name can optionally contain the
+ group instance id, for example foo[5].
+ </para>
+ </listitem>
+ <listitem>
+ <para>
<emphasis>cfg.set_delayed_int</emphasis> - Prepare the change of
a configuration variable, but does not commit the new value yet.
The function accepts three parameters: group name, variable
@@ -48,6 +59,17 @@
</listitem>
<listitem>
<para>
+ <emphasis>cfg.set_delayed</emphasis> - Prepare the change of
+ a configuration variable, but does not commit the new value yet.
+ This is a wrapper command for cfg.set_delayed_int and cfg.set_delayed_string
+ depending on the type of the value provided.
+ The function accepts three parameters: group name, variable
+ name, int/string value. The group name can optionally contain the
+ group instance id, for example foo[5].
+ </para>
+ </listitem>
+ <listitem>
+ <para>
<emphasis>cfg.commit</emphasis> - Commit the previously
prepared configuration changes. The function does not have
any parameters.
More information about the sr-dev
mailing list