Finished and deployed CORBA sandbox separation
[captive.git] / src / client / cmdline / main.c
index b70e29d..a9fe5d8 100644 (file)
@@ -26,8 +26,9 @@
 #include <popt.h>
 #include <string.h>
 #include <stdio.h>
+#include <locale.h>
 
-#include <captive/client.h>    /* for captive_init() */
+#include <captive/client-vfs.h>
 
 #include "main.h"      /* self */
 #include "cmd_shell.h"
@@ -36,6 +37,7 @@
 #include "cmd_ls.h"
 #include "cmd_get.h"
 #include "cmd_put.h"
+#include "cmd_info.h"
 #include "cmd_rm.h"
 #include "cmd_mv.h"
 #include "cmd_mkdir.h"
@@ -44,6 +46,9 @@
 #include "cmd_help.h"
 
 
+CaptiveVfsObject *cmdline_captive_vfs_object;
+
+
 GQuark cmdline_main_error_quark(void)
 {
 GQuark r=0;
@@ -69,6 +74,7 @@ const struct cmdline_command cmdline_command_table[]={
                { "ls"   ,N_("Directory[1] listing.")                              ,cmd_ls_table   ,cmd_ls   ,0,1 },
                { "get"  ,N_("Copy guest-os file[1] to host-os (opt. file[2]).")   ,cmd_get_table  ,cmd_get  ,1,2 },
                { "put"  ,N_("Copy host-os file[1] to guest-os (opt. file[2]).")   ,cmd_put_table  ,cmd_put  ,1,2 },
+               { "info" ,N_("Query information about guest-os item[1].")          ,cmd_info_table ,cmd_info ,1,1 },
                { "rm"   ,N_("Remove guest-os file[1].")                           ,cmd_rm_table   ,cmd_rm   ,1,1 },
                { "mv"   ,N_("Move (rename) guest-os item[1] to guest-os item[2]."),cmd_mv_table   ,cmd_mv   ,2,2 },
                { "mkdir",N_("Create guest-os directory[1].")                      ,cmd_mkdir_table,cmd_mkdir,1,1 },
@@ -188,6 +194,21 @@ gboolean errvfsresult_to_gerr(GError **errp,GnomeVFSResult errvfsresult)
        return FALSE;
 }
 
+static GIOChannel *main_giochannel;
+
+void main_exit(void)
+{
+       if (cmdline_captive_vfs_object) {
+               g_object_unref(cmdline_captive_vfs_object);
+               cmdline_captive_vfs_object=NULL;
+               }
+       if (main_giochannel) {
+               g_io_channel_unref(main_giochannel);
+               main_giochannel=NULL;
+               }
+       exit(EXIT_SUCCESS);
+}
+
 int main(int argc,char **argv)
 {
 poptContext context;
@@ -196,6 +217,18 @@ const char **cmd_argv,**csp;
 int cmd_argc;
 GError *gerr=NULL;
 const char *cmd_cd_root_args[]={"/",NULL};
+struct captive_options options;
+
+       /* Initialize the i18n stuff */
+       setlocale(LC_ALL,"");
+       bindtextdomain(PACKAGE,LOCALEDIR);
+       textdomain(PACKAGE);
+
+       /* Initialize GObject subsystem of GLib. */
+       g_type_init();
+
+       captive_options_init(&options);
+       captive_options=&options;       /* for parsing by 'CAPTIVE_POPT_INCLUDE' */
 
        context=poptGetContext(
                        PACKAGE,        /* name */
@@ -221,19 +254,31 @@ const char *cmd_cd_root_args[]={"/",NULL};
        for (csp=cmd_argv,cmd_argc=0;csp && *csp;csp++)
                cmd_argc++;
 
-       if (TRUE!=captive_init(NULL,    /* captive_args; already parsed above */
-                       (               /* image_iochannel */
-                                       !cmd_argc ? NULL : g_io_channel_new_file(       /* FIXME: g_io_channel_new_file() is NOT 64-bit compliant! */
-                                                       cmd_argv[0],    /* filename */
-                                                       (captive_option_rwmode==CAPTIVE_OPTION_RWMODE_RW ? "r+" : "r"), /* mode */
-                                                       NULL))))        /* error */
-               g_error(_("captive_init image_iochannel FAIL"));
+       captive_options=NULL;   /* already parsed by 'CAPTIVE_POPT_INCLUDE' */
+
+       /* image_iochannel */
+       if (cmd_argc) {
+               g_assert(options.image_iochannel==NULL);
+               if (!(options.image_iochannel=g_io_channel_new_file(
+                               cmd_argv[0],    /* filename */
+                               (options.rwmode==CAPTIVE_OPTION_RWMODE_RW ? "r+" : "r"),        /* mode */
+                               NULL))) {       /* error */
+                       g_error(_("image_iochannel open failed"));
+                       return EXIT_FAILURE;
+                       }
+               }
        if (cmd_argc>0) {
                /* image file */
                cmd_argc--;
                cmd_argv++;
                }
 
+       if (GNOME_VFS_OK!=captive_vfs_new(&cmdline_captive_vfs_object,&options)) {
+               g_error(_("captive_vfs_new() failed"));
+               return EXIT_FAILURE;
+               }
+       captive_options_free(&options);
+
        cmd_cd(cmd_cd_root_args,&gerr);
        if (gerr) {
                err_cleanup(&gerr);