Module: sip-router
Branch: master
Commit: cd29cc777996b8100680fb8ea96eb302e21f8c4c
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=cd29cc777996b8100680fb8ea96eb302e21f8c4c

Author: Miklos Tirpak <[email protected]>
Committer: Miklos Tirpak <[email protected]>
Date:   Wed Jan  5 15:10:06 2011 +0100

cfg_rpc: RPC commands for value deletion

Two RPC commands added for deleting a configuration value from
a group instance:

cfg.del group[id] var
cfg.del_delayed group[id] var

---

 modules/cfg_rpc/README      |   11 +++++++++
 modules/cfg_rpc/cfg_rpc.c   |   50 +++++++++++++++++++++++++++++++++++++++++++
 modules/cfg_rpc/doc/rpc.xml |   22 +++++++++++++++++++
 3 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/modules/cfg_rpc/README b/modules/cfg_rpc/README
index 3bec8f0..9c71c66 100644
--- a/modules/cfg_rpc/README
+++ b/modules/cfg_rpc/README
@@ -35,6 +35,11 @@ Miklos Tirpak
        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.del - Delete the value of a configuration variable from a group
+       instance and commit the change immediately. The value is reset to
+       the default value and it follows the changes of that. The function
+       accepts two parameters: group name, variable name. The group name
+       must 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.
@@ -51,6 +56,12 @@ Miklos Tirpak
        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.del_delayed - Prepare the deletion of the value of a
+       configuration variable from a group instance, but does not commit
+       the change yet. The value is reset to the default value and it
+       follows the changes of that. The function accepts two parameters:
+       group name, variable name. The group name must 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 23cba03..31cc901 100644
--- a/modules/cfg_rpc/cfg_rpc.c
+++ b/modules/cfg_rpc/cfg_rpc.c
@@ -156,6 +156,30 @@ static void rpc_set(rpc_t* rpc, void* c)
        }
 }
 
+static const char* rpc_del_now_doc[2] = {
+        "Delete the value of a configuration variable from a group instance 
and commit the change immediately",
+        0
+};
+
+static void rpc_del(rpc_t* rpc, void* c)
+{
+       str     group, var;
+       unsigned int    *group_id;
+
+       if (rpc->scan(c, "SS", &group, &var) < 2)
+               return;
+
+       if (get_group_id(&group, &group_id) || !group_id) {
+               rpc->fault(c, 400, "Wrong group syntax. Use \"group[id]\"");
+               return;
+       }
+
+       if (cfg_del_now(ctx, &group, group_id, &var)) {
+               rpc->fault(c, 400, "Failed to delete the value");
+               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
@@ -229,6 +253,30 @@ static void rpc_set_delayed(rpc_t* rpc, void* c)
        }
 }
 
+static const char* rpc_del_delayed_doc[2] = {
+        "Prepare the deletion of the value of a configuration variable from a 
group instance, but does not commit the change yet",
+        0
+};
+
+static void rpc_del_delayed(rpc_t* rpc, void* c)
+{
+       str     group, var;
+       unsigned int    *group_id;
+
+       if (rpc->scan(c, "SS", &group, &var) < 2)
+               return;
+
+       if (get_group_id(&group, &group_id) || !group_id) {
+               rpc->fault(c, 400, "Wrong group syntax. Use \"group[id]\"");
+               return;
+       }
+
+       if (cfg_del_delayed(ctx, &group, group_id, &var)) {
+               rpc->fault(c, 400, "Failed to delete the value");
+               return;
+       }
+}
+
 static const char* rpc_commit_doc[2] = {
         "Commit the previously prepared configuration changes",
         0
@@ -488,9 +536,11 @@ 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.del",             rpc_del,                rpc_del_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.del_delayed",     rpc_del_delayed,        rpc_del_delayed_doc,    
0},
        {"cfg.commit",          rpc_commit,             rpc_commit_doc,         
0},
        {"cfg.rollback",        rpc_rollback,           rpc_rollback_doc,       
0},
        {"cfg.get",             rpc_get,                rpc_get_doc,            
0},
diff --git a/modules/cfg_rpc/doc/rpc.xml b/modules/cfg_rpc/doc/rpc.xml
index 4491184..ae3c548 100644
--- a/modules/cfg_rpc/doc/rpc.xml
+++ b/modules/cfg_rpc/doc/rpc.xml
@@ -41,6 +41,17 @@
        </listitem>
        <listitem>
            <para>
+               <emphasis>cfg.del</emphasis> - Delete the value of
+               a configuration variable from a group instance and commit the 
change immediately.
+               The value is reset to the default value and it follows the 
changes
+               of that.
+               The function accepts two parameters: group name, variable
+               name. The group name must 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
@@ -70,6 +81,17 @@
        </listitem>
        <listitem>
            <para>
+               <emphasis>cfg.del_delayed</emphasis> - Prepare the deletion of 
the value of
+               a configuration variable from a group instance, but does not 
commit the change yet.
+               The value is reset to the default value and it follows the 
changes
+               of that.
+               The function accepts two parameters: group name, variable
+               name. The group name must 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.


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to