Browse code

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

Miklos Tirpak authored on 05/01/2011 14:10:06
Showing 3 changed files
... ...
@@ -35,6 +35,11 @@ Miklos Tirpak
35 35
        The function accepts three parameters: group name, variable name,
36 36
        int/string value. The group name can optionally contain the group
37 37
        instance id, for example foo[5].
38
+     * cfg.del - Delete the value of a configuration variable from a group
39
+       instance and commit the change immediately. The value is reset to
40
+       the default value and it follows the changes of that. The function
41
+       accepts two parameters: group name, variable name. The group name
42
+       must contain the group instance id, for example foo[5].
38 43
      * cfg.set_delayed_int - Prepare the change of a configuration
39 44
        variable, but does not commit the new value yet. The function
40 45
        accepts three parameters: group name, variable name, integer value.
... ...
@@ -51,6 +56,12 @@ Miklos Tirpak
51 51
        type of the value provided. The function accepts three parameters:
52 52
        group name, variable name, int/string value. The group name can
53 53
        optionally contain the group instance id, for example foo[5].
54
+     * cfg.del_delayed - Prepare the deletion of the value of a
55
+       configuration variable from a group instance, but does not commit
56
+       the change yet. The value is reset to the default value and it
57
+       follows the changes of that. The function accepts two parameters:
58
+       group name, variable name. The group name must contain the group
59
+       instance id, for example foo[5].
54 60
      * cfg.commit - Commit the previously prepared configuration changes.
55 61
        The function does not have any parameters.
56 62
      * cfg.rollback - Drop the prepared configuration changes. The
... ...
@@ -156,6 +156,30 @@ static void rpc_set(rpc_t* rpc, void* c)
156 156
 	}
157 157
 }
158 158
 
159
+static const char* rpc_del_now_doc[2] = {
160
+        "Delete the value of a configuration variable from a group instance and commit the change immediately",
161
+        0
162
+};
163
+
164
+static void rpc_del(rpc_t* rpc, void* c)
165
+{
166
+	str	group, var;
167
+	unsigned int	*group_id;
168
+
169
+	if (rpc->scan(c, "SS", &group, &var) < 2)
170
+		return;
171
+
172
+	if (get_group_id(&group, &group_id) || !group_id) {
173
+		rpc->fault(c, 400, "Wrong group syntax. Use \"group[id]\"");
174
+		return;
175
+	}
176
+
177
+	if (cfg_del_now(ctx, &group, group_id, &var)) {
178
+		rpc->fault(c, 400, "Failed to delete the value");
179
+		return;
180
+	}
181
+}
182
+
159 183
 static const char* rpc_set_delayed_doc[2] = {
160 184
         "Prepare the change of a configuration variable, but does not commit the new value yet",
161 185
         0
... ...
@@ -229,6 +253,30 @@ static void rpc_set_delayed(rpc_t* rpc, void* c)
229 229
 	}
230 230
 }
231 231
 
232
+static const char* rpc_del_delayed_doc[2] = {
233
+        "Prepare the deletion of the value of a configuration variable from a group instance, but does not commit the change yet",
234
+        0
235
+};
236
+
237
+static void rpc_del_delayed(rpc_t* rpc, void* c)
238
+{
239
+	str	group, var;
240
+	unsigned int	*group_id;
241
+
242
+	if (rpc->scan(c, "SS", &group, &var) < 2)
243
+		return;
244
+
245
+	if (get_group_id(&group, &group_id) || !group_id) {
246
+		rpc->fault(c, 400, "Wrong group syntax. Use \"group[id]\"");
247
+		return;
248
+	}
249
+
250
+	if (cfg_del_delayed(ctx, &group, group_id, &var)) {
251
+		rpc->fault(c, 400, "Failed to delete the value");
252
+		return;
253
+	}
254
+}
255
+
232 256
 static const char* rpc_commit_doc[2] = {
233 257
         "Commit the previously prepared configuration changes",
234 258
         0
... ...
@@ -488,9 +536,11 @@ static rpc_export_t rpc_calls[] = {
488 488
 	{"cfg.set",		rpc_set,		rpc_set_now_doc,	0},
489 489
 	{"cfg.set_now_int",	rpc_set_now_int,	rpc_set_now_doc,	0},
490 490
 	{"cfg.set_now_string",	rpc_set_now_string,	rpc_set_now_doc,	0},
491
+	{"cfg.del",		rpc_del,		rpc_del_now_doc,	0},
491 492
 	{"cfg.set_delayed",	rpc_set_delayed,	rpc_set_delayed_doc,	0},
492 493
 	{"cfg.set_delayed_int",	rpc_set_delayed_int,	rpc_set_delayed_doc,	0},
493 494
 	{"cfg.set_delayed_string",	rpc_set_delayed_string,	rpc_set_delayed_doc,	0},
495
+	{"cfg.del_delayed",	rpc_del_delayed,	rpc_del_delayed_doc,	0},
494 496
 	{"cfg.commit",		rpc_commit,		rpc_commit_doc,		0},
495 497
 	{"cfg.rollback",	rpc_rollback,		rpc_rollback_doc,	0},
496 498
 	{"cfg.get",		rpc_get,		rpc_get_doc,		0},
... ...
@@ -41,6 +41,17 @@
41 41
 	</listitem>
42 42
 	<listitem>
43 43
 	    <para>
44
+		<emphasis>cfg.del</emphasis> - Delete the value of
45
+		a configuration variable from a group instance and commit the change immediately.
46
+		The value is reset to the default value and it follows the changes
47
+		of that.
48
+		The function accepts two parameters: group name, variable
49
+		name. The group name must contain the
50
+		group instance id, for example foo[5].
51
+	    </para>
52
+	</listitem>
53
+	<listitem>
54
+	    <para>
44 55
 		<emphasis>cfg.set_delayed_int</emphasis> - Prepare the change of
45 56
 		a configuration variable, but does not commit the new value yet.
46 57
 		The function accepts three parameters: group name, variable
... ...
@@ -70,6 +81,17 @@
70 70
 	</listitem>
71 71
 	<listitem>
72 72
 	    <para>
73
+		<emphasis>cfg.del_delayed</emphasis> - Prepare the deletion of the value of
74
+		a configuration variable from a group instance, but does not commit the change yet.
75
+		The value is reset to the default value and it follows the changes
76
+		of that.
77
+		The function accepts two parameters: group name, variable
78
+		name. The group name must contain the
79
+		group instance id, for example foo[5].
80
+	    </para>
81
+	</listitem>
82
+	<listitem>
83
+	    <para>
73 84
 		<emphasis>cfg.commit</emphasis> - Commit the previously
74 85
 		prepared configuration changes. The function does not have
75 86
 		any parameters.