Browse code

dispatcher: rework attrs parameter in rpc 'add' command

Federico Cabiddu authored on 28/05/2020 08:41:32 • Henning Westerholt committed on 29/05/2020 06:41:44
Showing 2 changed files
... ...
@@ -2426,10 +2426,6 @@ int ds_add_dst(int group, str *address, int flags, str *attrs)
2426 2426
 	setn = _ds_list_nr;
2427 2427
 	priority = 0;
2428 2428
 
2429
-	if (attrs->len == 0) {
2430
-		attrs->s = 0;
2431
-	}
2432
-
2433 2429
 	*next_idx = (*crt_idx + 1) % 2;
2434 2430
 	ds_avl_destroy(&ds_lists[*next_idx]);
2435 2431
 
... ...
@@ -1798,15 +1798,19 @@ static const char *dispatcher_rpc_add_doc[2] = {
1798 1798
  */
1799 1799
 static void dispatcher_rpc_add(rpc_t *rpc, void *ctx)
1800 1800
 {
1801
-	int group, flags;
1801
+	int group, flags, nparams;
1802 1802
 	str dest;
1803
-  str attrs;
1803
+	str attrs;
1804 1804
 
1805 1805
 	flags = 0;
1806 1806
 
1807
-	if(rpc->scan(ctx, "dS*d", &group, &dest, &flags, &attrs) < 3) {
1807
+	nparams = rpc->scan(ctx, "dS*dS", &group, &dest, &flags, &attrs);
1808
+	if(nparams < 2) {
1808 1809
 		rpc->fault(ctx, 500, "Invalid Parameters");
1809 1810
 		return;
1811
+	} else if (nparams < 3) {
1812
+		attrs.s = 0;
1813
+		attrs.len = 0;
1810 1814
 	}
1811 1815
 
1812 1816
 	if(ds_add_dst(group, &dest, flags, &attrs) != 0) {