X-Git-Url: https://git.sur5r.net/?p=ngadmin;a=blobdiff_plain;f=cli%2Fcom_stormfilter.c;h=6f2f5165adb30a6935ae7df95861a76364b4d1a2;hp=76076bfe517c0838be0d556b5ea6643ef5c0ffd1;hb=ba1e16863bdedc5f52b077932aa7301ed14a0f06;hpb=8d96dbb186138459117b82268407c0fb45339e8f diff --git a/cli/com_stormfilter.c b/cli/com_stormfilter.c index 76076bf..6f2f516 100644 --- a/cli/com_stormfilter.c +++ b/cli/com_stormfilter.c @@ -2,12 +2,17 @@ #include "commands.h" -bool do_stormfilter_enable (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_stormfilter_enable (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); @@ -22,12 +27,17 @@ bool do_stormfilter_enable (int nb UNUSED, const char **com UNUSED, struct ngadm } -bool do_stormfilter_disable (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_stormfilter_disable (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); @@ -42,15 +52,15 @@ bool do_stormfilter_disable (int nb UNUSED, const char **com UNUSED, struct ngad } -bool do_stormfilter_set (int nb, const char **com, struct ngadmin *nga) +bool do_stormfilter_set (int argc, const char **argv, struct ngadmin *nga) { int i, d = BITRATE_UNSPEC, p, *ports = NULL; const struct swi_attr *sa; bool ret = true; - if (nb < 2) { - printf("Usage: stormfilt set (all )|( [ ...])\n"); + if (argc < 2) { + printf("usage: stormfilt set (all )|( [ ...])\n"); ret = false; goto end; } @@ -62,24 +72,28 @@ bool do_stormfilter_set (int nb, const char **com, struct ngadmin *nga) goto end; } - ports=malloc(sa->ports * sizeof(int)); + ports = malloc(sa->ports * sizeof(int)); - if (strcmp(com[0], "all") == 0) { - d = parseBitrate(com[1]); - com += 2; - nb -= 2; + /* read defaults */ + if (strcmp(argv[0], "all") == 0) { + d = parseBitrate(argv[1]); + argv += 2; + argc -= 2; } + /* apply defaults */ for (i = 0; i < sa->ports; i++) ports[i] = d; - for (i = 0; i < nb; i += 2) { - p = strtol(com[i], NULL, 0); + /* read and apply port specifics */ + for (i = 0; i < argc - 1; i += 2) { + p = strtol(argv[i], NULL, 0); if (p < 1 || p > sa->ports) continue; - ports[p - 1] = parseBitrate(com[i + 1]); + ports[p - 1] = parseBitrate(argv[i + 1]); } + /* send the new configuration to the switch */ i = ngadmin_setStormFilterValues(nga, ports); printErrCode(i); @@ -90,12 +104,18 @@ end: } -bool do_stormfilter_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_stormfilter_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i, s, ret = true, *ports = NULL; const struct swi_attr *sa; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n");