]> git.sur5r.net Git - ngadmin/blobdiff - cli/com_firmware.c
Fix crash when reading the wrong type of VLAN
[ngadmin] / cli / com_firmware.c
index f697af699160461b354542cd95a64a80d3b0f299..3d5e76c2437ec2161fca9a83a064fd82aa2a53a3 100644 (file)
@@ -1,64 +1,59 @@
 
-#include "common.h"
-
-
-
-
-static bool do_firmware_show (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
- const struct swi_attr *sa;
- bool ret=true;
- if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
-  printf("must be logged\n");
-  ret=false;
-  goto end;
- }
- puts(sa->firmware);
- end:
- return ret;
+#include "commands.h"
+
+
+int do_firmware_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+       const struct swi_attr *sa;
+       int ret = 0;
+       
+       
+       if (argc > 0) {
+               printf("this command takes no argument\n");
+               ret = 1;
+               goto end;
+       }
+       
+       sa = ngadmin_getCurrentSwitch(nga);
+       if (sa == NULL) {
+               printf("must be logged\n");
+               ret = 1;
+               goto end;
+       }
+       
+       puts(sa->firmware);
+       
+end:
+       
+       return ret;
 }
 
 
-
-static bool do_firmware_upgrade (const struct TreeNode *tn UNUSED, int nb, const char **com UNUSED, struct ngadmin *nga) {
const struct swi_attr *sa;
- bool ret=true;
- if ( nb!=1 ) {
-  printf("Usage: firmware upgrade <file>\n");
-  ret=false;
- }
- if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
-  printf("must be logged\n");
-  ret=false;
-  goto end;
- }
- printf("not implemented yet\n");
- end:
- return ret;
+int do_firmware_upgrade (int argc, const char **argv, struct ngadmin *nga)
+{
+       const struct swi_attr *sa;
      int i, ret = 0;
+       
+       
+       if (argc != 1) {
+               printf("usage: firmware upgrade <file>\n");
+               ret = 1;
+               goto end;
      }
+       
+       sa = ngadmin_getCurrentSwitch(nga);
+       if (sa == NULL) {
+               printf("must be logged\n");
+               ret = 1;
+               goto end;
+       }
+       
+       i = ngadmin_upgradeFirmware(nga, argv[0]);
+       printErrCode(i);
+       
+end:
+       
+       return ret;
 }
 
 
-
-static const struct TreeNode com_firmware_show=COM("show", do_firmware_show, false, NULL);
-static const struct TreeNode com_firmware_upgrade=COM("upgrade", do_firmware_upgrade, true, NULL);
-
-const struct TreeNode com_firmware=COM("firmware", NULL, false, &com_firmware_show, &com_firmware_upgrade, NULL);
-
-
-