+command "open": Open as[1] file[2] in mode; see 'open --help'.
authorshort <>
Mon, 10 Nov 2003 08:54:30 +0000 (08:54 +0000)
committershort <>
Mon, 10 Nov 2003 08:54:30 +0000 (08:54 +0000)
+command "create": Create as[1] file[2] in mode with perm; see 'create --help'.
+command "close": Close handle[1].

src/client/cmdline/Makefile.am
src/client/cmdline/cmd_close.c [new file with mode: 0644]
src/client/cmdline/cmd_close.h [new file with mode: 0644]
src/client/cmdline/cmd_create.c [new file with mode: 0644]
src/client/cmdline/cmd_create.h [new file with mode: 0644]
src/client/cmdline/cmd_get.c
src/client/cmdline/cmd_open.c [new file with mode: 0644]
src/client/cmdline/cmd_open.h [new file with mode: 0644]
src/client/cmdline/handle.c [new file with mode: 0644]
src/client/cmdline/handle.h [new file with mode: 0644]
src/client/cmdline/main.c

index e246f67..236b4ab 100644 (file)
@@ -21,8 +21,12 @@ include $(top_srcdir)/Makefile-head.am
 captive_cmdline_SOURCES= \
                cmd_cd.c \
                cmd_cd.h \
+               cmd_close.c \
+               cmd_close.h \
                cmd_commit.c \
                cmd_commit.h \
+               cmd_create.c \
+               cmd_create.h \
                cmd_get.c \
                cmd_get.h \
                cmd_help.c \
@@ -37,6 +41,8 @@ captive_cmdline_SOURCES= \
                cmd_mkdir.h \
                cmd_mv.c \
                cmd_mv.h \
+               cmd_open.c \
+               cmd_open.h \
                cmd_put.c \
                cmd_put.h \
                cmd_quit.c \
@@ -51,6 +57,8 @@ captive_cmdline_SOURCES= \
                cmd_volume.h \
                file_info.c \
                file_info.h \
+               handle.c \
+               handle.h \
                main.c \
                main.h
 captive_cmdline_CFLAGS=                   $(GNOME_VFS_CFLAGS)
diff --git a/src/client/cmdline/cmd_close.c b/src/client/cmdline/cmd_close.c
new file mode 100644 (file)
index 0000000..d3438cf
--- /dev/null
@@ -0,0 +1,58 @@
+/* $Id$
+ * client cmdline interface command "close" for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <glib/gerror.h>
+#include <popt.h>
+#include <captive/client-file.h>
+
+#include "cmd_close.h" /* self */
+#include "main.h"
+#include "handle.h"
+
+
+GQuark cmdline_cmd_close_error_quark(void)
+{
+GQuark r=0;
+
+       if (!r)
+               r=g_quark_from_static_string("cmdline-cmd-close");
+
+       return r;
+}
+
+
+const struct poptOption cmd_close_table[]={
+               CMDLINE_POPT_AUTOHELP
+               POPT_TABLEEND
+               };
+
+
+void cmd_close(const char **cmd_argv,GError **errp)
+{
+const gchar *handle_name;
+
+       g_return_if_fail(!errp || !*errp);
+
+       handle_name=cmd_argv[0];
+
+       handle_delete(handle_name,errp);
+}
diff --git a/src/client/cmdline/cmd_close.h b/src/client/cmdline/cmd_close.h
new file mode 100644 (file)
index 0000000..34753e8
--- /dev/null
@@ -0,0 +1,41 @@
+/* $Id$
+ * Include file for client cmdline interface command "close" for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_CMDLINE_CMD_CLOSE_H
+#define _CAPTIVE_CLIENT_CMDLINE_CMD_CLOSE_H 1
+
+
+#include <glib/gerror.h>
+#include <popt.h>
+
+
+#define CMDLINE_CMD_CLOSE_ERROR (cmdline_cmd_close_error_quark())
+GQuark cmdline_cmd_close_error_quark(void);
+
+typedef enum {
+       CMDLINE_CMD_CLOSE_ERROR_UNUSED
+       } CmdlineCmdCloseError;
+
+
+extern const struct poptOption cmd_close_table[];
+
+void cmd_close(const char **cmd_argv,GError **errp);
+
+
+#endif /* _CAPTIVE_CLIENT_CMDLINE_CMD_CLOSE_H */
diff --git a/src/client/cmdline/cmd_create.c b/src/client/cmdline/cmd_create.c
new file mode 100644 (file)
index 0000000..98c2c85
--- /dev/null
@@ -0,0 +1,109 @@
+/* $Id$
+ * client cmdline interface command "create" for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <glib/gerror.h>
+#include <popt.h>
+#include <captive/client-file.h>
+
+#include "cmd_create.h"        /* self */
+#include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
+#include "main.h"
+#include "handle.h"
+
+
+GQuark cmdline_cmd_create_error_quark(void)
+{
+GQuark r=0;
+
+       if (!r)
+               r=g_quark_from_static_string("cmdline-cmd-create");
+
+       return r;
+}
+
+
+static int optarg_read;
+static int optarg_write;
+static int optarg_random;
+static int optarg_exclusive;
+static int optarg_read_only;
+
+const struct poptOption cmd_create_table[]={
+               CMDLINE_POPT("read",'r',POPT_ARG_NONE,&optarg_read,
+                               N_("Create file with 'GNOME_VFS_OPEN_READ' disposition flag"),NULL),
+               CMDLINE_POPT("write",'w',POPT_ARG_NONE,&optarg_write,
+                               N_("Create file with 'GNOME_VFS_OPEN_WRITE' disposition flag"),NULL),
+               CMDLINE_POPT("random",'R',POPT_ARG_NONE,&optarg_random,
+                               N_("Create file with 'GNOME_VFS_OPEN_RANDOM' disposition flag"),NULL),
+               CMDLINE_POPT("exclusive",'x',POPT_ARG_NONE,&optarg_exclusive,
+                               N_("Create file with exclusive access rights"),NULL),
+               CMDLINE_POPT("read-only",0,POPT_ARG_NONE,&optarg_read_only,
+                               N_("Create file with read-only access mode"),NULL),
+               CMDLINE_POPT_AUTOHELP
+               POPT_TABLEEND
+               };
+
+
+void cmd_create(const char **cmd_argv,GError **errp)
+{
+CaptiveFileObject *captive_file_object;
+const gchar *filename;
+GnomeVFSOpenMode mode;
+const gchar *handle_name;
+gboolean exclusive;
+gboolean read_only;
+
+       g_return_if_fail(!errp || !*errp);
+
+       handle_name=cmd_argv[0];
+       filename=cmdline_path_from_cwd(cmd_argv[1]);
+       mode=0
+                       | (!optarg_read   ? 0 : GNOME_VFS_OPEN_READ)
+                       | (!optarg_write  ? 0 : GNOME_VFS_OPEN_WRITE)
+                       | (!optarg_random ? 0 : GNOME_VFS_OPEN_RANDOM);
+       optarg_read=0;
+       optarg_write=0;
+       optarg_random=0;
+       exclusive=!!optarg_exclusive;
+       optarg_exclusive=0;
+       read_only=!!optarg_read_only;
+       optarg_read_only=0;
+
+       if (!handle_check_not_used(handle_name,errp))
+               return;
+
+       if (!errvfsresult_to_gerr(errp,captive_file_new_create(
+                       &captive_file_object,   /* captive_file_object_return */
+                       cmdline_captive_vfs_object,     /* captive_vfs_object */
+                       filename,       /* pathname */
+                       mode,   /* mode */
+                       exclusive,      /* exclusive */
+                       (read_only ? 0400 : 0000)))) {  /* perm */
+               err_cleanup(errp);
+               g_set_error(errp,CMDLINE_CMD_CREATE_ERROR,CMDLINE_CMD_CREATE_ERROR_CREATING_FILE,
+                               _("Error creating guest-os file '%s'"),filename);
+               return;
+               }
+
+       handle_set(handle_name,captive_file_object);
+       g_object_unref(captive_file_object);
+}
diff --git a/src/client/cmdline/cmd_create.h b/src/client/cmdline/cmd_create.h
new file mode 100644 (file)
index 0000000..95d2f11
--- /dev/null
@@ -0,0 +1,41 @@
+/* $Id$
+ * Include file for client cmdline interface command "create" for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_CMDLINE_CMD_CREATE_H
+#define _CAPTIVE_CLIENT_CMDLINE_CMD_CREATE_H 1
+
+
+#include <glib/gerror.h>
+#include <popt.h>
+
+
+#define CMDLINE_CMD_CREATE_ERROR (cmdline_cmd_create_error_quark())
+GQuark cmdline_cmd_create_error_quark(void);
+
+typedef enum {
+       CMDLINE_CMD_CREATE_ERROR_CREATING_FILE
+       } CmdlineCmdCreateError;
+
+
+extern const struct poptOption cmd_create_table[];
+
+void cmd_create(const char **cmd_argv,GError **errp);
+
+
+#endif /* _CAPTIVE_CLIENT_CMDLINE_CMD_CREATE_H */
index 9a5a7de..c852b22 100644 (file)
@@ -107,7 +107,7 @@ char *s;
                                        ,
                        perm))) {       /* mode */
                g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_CANNOT_CREATE_TARGET_HOSTOS_FILE,
-                               _("Cannot create target host-os file: %s"),targetfile);
+                               _("Cannot create target host-os file '%s': %s"),targetfile,g_strerror(errno));
                return;
                }
 
@@ -118,7 +118,7 @@ char *s;
                        GNOME_VFS_OPEN_READ))) {        /* mode */
                err_cleanup(errp);
                g_set_error(errp,CMDLINE_CMD_GET_ERROR,CMDLINE_CMD_GET_ERROR_OPENING_SOURCE_FILE,
-                               _("Error opening source guest-os file '%s': %s"),sourcefile,g_strerror(errno));
+                               _("Error opening source guest-os file: %s"),sourcefile);
                goto err_close_fdtgt;
                }
 
diff --git a/src/client/cmdline/cmd_open.c b/src/client/cmdline/cmd_open.c
new file mode 100644 (file)
index 0000000..f058c7d
--- /dev/null
@@ -0,0 +1,95 @@
+/* $Id$
+ * client cmdline interface command "open" for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <glib/gerror.h>
+#include <popt.h>
+#include <captive/client-file.h>
+
+#include "cmd_open.h"  /* self */
+#include "cmd_cd.h"    /* for cmdline_path_from_cwd() */
+#include "main.h"
+#include "handle.h"
+
+
+GQuark cmdline_cmd_open_error_quark(void)
+{
+GQuark r=0;
+
+       if (!r)
+               r=g_quark_from_static_string("cmdline-cmd-open");
+
+       return r;
+}
+
+
+static int optarg_read;
+static int optarg_write;
+static int optarg_random;
+
+const struct poptOption cmd_open_table[]={
+               CMDLINE_POPT("read",'r',POPT_ARG_NONE,&optarg_read,
+                               N_("Open file with 'GNOME_VFS_OPEN_READ' disposition flag"),NULL),
+               CMDLINE_POPT("write",'w',POPT_ARG_NONE,&optarg_write,
+                               N_("Open file with 'GNOME_VFS_OPEN_WRITE' disposition flag"),NULL),
+               CMDLINE_POPT("random",'R',POPT_ARG_NONE,&optarg_random,
+                               N_("Open file with 'GNOME_VFS_OPEN_RANDOM' disposition flag"),NULL),
+               CMDLINE_POPT_AUTOHELP
+               POPT_TABLEEND
+               };
+
+
+void cmd_open(const char **cmd_argv,GError **errp)
+{
+CaptiveFileObject *captive_file_object;
+const gchar *filename;
+GnomeVFSOpenMode mode;
+const gchar *handle_name;
+
+       g_return_if_fail(!errp || !*errp);
+
+       handle_name=cmd_argv[0];
+       filename=cmdline_path_from_cwd(cmd_argv[1]);
+       mode=0
+                       | (!optarg_read   ? 0 : GNOME_VFS_OPEN_READ)
+                       | (!optarg_write  ? 0 : GNOME_VFS_OPEN_WRITE)
+                       | (!optarg_random ? 0 : GNOME_VFS_OPEN_RANDOM);
+       optarg_read=0;
+       optarg_write=0;
+       optarg_random=0;
+
+       if (!handle_check_not_used(handle_name,errp))
+               return;
+
+       if (!errvfsresult_to_gerr(errp,captive_file_new_open(
+                       &captive_file_object,   /* captive_file_object_return */
+                       cmdline_captive_vfs_object,     /* captive_vfs_object */
+                       filename,       /* pathname */
+                       mode))) {       /* mode */
+               err_cleanup(errp);
+               g_set_error(errp,CMDLINE_CMD_OPEN_ERROR,CMDLINE_CMD_OPEN_ERROR_OPENING_FILE,
+                               _("Error opening guest-os file '%s'"),filename);
+               return;
+               }
+
+       handle_set(handle_name,captive_file_object);
+       g_object_unref(captive_file_object);
+}
diff --git a/src/client/cmdline/cmd_open.h b/src/client/cmdline/cmd_open.h
new file mode 100644 (file)
index 0000000..fcf685e
--- /dev/null
@@ -0,0 +1,41 @@
+/* $Id$
+ * Include file for client cmdline interface command "open" for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_CMDLINE_CMD_OPEN_H
+#define _CAPTIVE_CLIENT_CMDLINE_CMD_OPEN_H 1
+
+
+#include <glib/gerror.h>
+#include <popt.h>
+
+
+#define CMDLINE_CMD_OPEN_ERROR (cmdline_cmd_open_error_quark())
+GQuark cmdline_cmd_open_error_quark(void);
+
+typedef enum {
+       CMDLINE_CMD_OPEN_ERROR_OPENING_FILE
+       } CmdlineCmdOpenError;
+
+
+extern const struct poptOption cmd_open_table[];
+
+void cmd_open(const char **cmd_argv,GError **errp);
+
+
+#endif /* _CAPTIVE_CLIENT_CMDLINE_CMD_OPEN_H */
diff --git a/src/client/cmdline/handle.c b/src/client/cmdline/handle.c
new file mode 100644 (file)
index 0000000..d144009
--- /dev/null
@@ -0,0 +1,128 @@
+/* $Id$
+ * client cmdline named CaptiveFileObject storage for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <glib/gerror.h>
+#include <captive/client-file.h>
+
+#include "handle.h"    /* self */
+
+
+GQuark cmdline_handle_error_quark(void)
+{
+GQuark r=0;
+
+       if (!r)
+               r=g_quark_from_static_string("cmdline-handle");
+
+       return r;
+}
+
+
+static GHashTable *handle_hash;
+
+static void handle_hash_key_destroy_func(gchar *handle_name /* key */)
+{
+       g_return_if_fail(handle_name!=NULL);
+
+       g_free(handle_name);
+}
+
+static void handle_hash_value_destroy_func(CaptiveFileObject *captive_file_object /* value */)
+{
+       g_return_if_fail(CAPTIVE_FILE_IS_OBJECT(captive_file_object));
+
+       g_object_unref(captive_file_object);
+}
+
+static void handle_hash_init(void)
+{
+       if (handle_hash)
+               return;
+       handle_hash=g_hash_table_new_full(
+                       g_str_hash,     /* hash_func */
+                       g_str_equal,    /* key_equal_func */
+                       (GDestroyNotify)handle_hash_key_destroy_func,   /* key_destroy_func */
+                       (GDestroyNotify)handle_hash_value_destroy_func);        /* value_destroy_func */
+}
+
+CaptiveFileObject *handle_get(const gchar *handle_name,GError **errp)
+{
+CaptiveFileObject *r;
+
+       g_return_val_if_fail(handle_name!=NULL,NULL);
+       g_return_val_if_fail(!errp || !*errp,NULL);
+
+       handle_hash_init();
+
+       if (!(r=g_hash_table_lookup(handle_hash,handle_name)))
+               g_set_error(errp,CMDLINE_HANDLE_ERROR,CMDLINE_HANDLE_ERROR_LOOKUP,
+                               _("Error looking up existing handle: %s"),handle_name);
+
+       return r;
+}
+
+/* Returns: TRUE if not used. */
+gboolean handle_check_not_used(const gchar *handle_name,GError **errp)
+{
+gboolean r;
+
+       g_return_val_if_fail(handle_name!=NULL,FALSE);
+       g_return_val_if_fail(!errp || !*errp,FALSE);
+
+       handle_hash_init();
+
+       if (!(r=!g_hash_table_lookup(handle_hash,handle_name)))
+               g_set_error(errp,CMDLINE_HANDLE_ERROR,CMDLINE_HANDLE_ERROR_ALREADY_USED,
+                               _("Specified handle already used: %s"),handle_name);
+
+       return r;
+}
+
+void handle_set(const gchar *handle_name,CaptiveFileObject *captive_file_object)
+{
+       g_return_if_fail(handle_name!=NULL);
+       g_return_if_fail(CAPTIVE_FILE_IS_OBJECT(captive_file_object));
+
+       handle_hash_init();
+
+       g_return_if_fail(NULL==g_hash_table_lookup(handle_hash,handle_name));
+
+       g_hash_table_insert(handle_hash,
+                       g_strdup(handle_name),  /* key */
+                       g_object_ref(captive_file_object));     /* value */
+}
+
+void handle_delete(const gchar *handle_name,GError **errp)
+{
+       g_return_if_fail(handle_name!=NULL);
+       g_return_if_fail(!errp || !*errp);
+
+       handle_hash_init();
+
+       if (!g_hash_table_remove(handle_hash,handle_name)) {
+               g_set_error(errp,CMDLINE_HANDLE_ERROR,CMDLINE_HANDLE_ERROR_DELETE,
+                               _("Handle to be deleted not found: %s"),handle_name);
+               return;
+               }
+
+       g_assert(NULL==g_hash_table_lookup(handle_hash,handle_name));
+}
diff --git a/src/client/cmdline/handle.h b/src/client/cmdline/handle.h
new file mode 100644 (file)
index 0000000..5b5a475
--- /dev/null
@@ -0,0 +1,45 @@
+/* $Id$
+ * Include file for client cmdline named CaptiveFileObject storage for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_CMDLINE_HANDLE_H
+#define _CAPTIVE_CLIENT_CMDLINE_HANDLE_H 1
+
+
+#include <glib/gerror.h>
+#include <captive/client-file.h>
+
+
+#define CMDLINE_HANDLE_ERROR (cmdline_handle_error_quark())
+GQuark cmdline_handle_error_quark(void);
+
+typedef enum {
+       CMDLINE_HANDLE_ERROR_LOOKUP,
+       CMDLINE_HANDLE_ERROR_ALREADY_USED,
+       CMDLINE_HANDLE_ERROR_DELETE
+       } CmdlineHandleError;
+
+
+CaptiveFileObject *handle_get(const gchar *handle_name,GError **errp);
+/* Returns: TRUE if not used. */
+gboolean handle_check_not_used(const gchar *handle_name,GError **errp);
+void handle_set(const gchar *handle_name,CaptiveFileObject *captive_file_object);
+void handle_delete(const gchar *handle_name,GError **errp);
+
+
+#endif /* _CAPTIVE_CLIENT_CMDLINE_FILE_INFO_H */
index 0459c3f..1d3a9b3 100644 (file)
@@ -44,6 +44,9 @@
 #include "cmd_mkdir.h"
 #include "cmd_rmdir.h"
 #include "cmd_commit.h"
+#include "cmd_open.h"
+#include "cmd_create.h"
+#include "cmd_close.h"
 #include "cmd_quit.h"
 #include "cmd_help.h"
 
@@ -70,21 +73,24 @@ static const struct poptOption popt_table[]={
 
 const struct cmdline_command cmdline_command_table[]={
                /* First entry is the default if no command name was specified. */
-               { "shell" ,N_("Interactive commands shell.")                        ,cmd_shell_table ,cmd_shell ,0,0 },
-               { "cd"    ,N_("Print or change current guest-os directory[1].")     ,cmd_cd_table    ,cmd_cd    ,0,1 },
-               { "lcd"   ,N_("Print or change current host-os  directory[1].")     ,cmd_lcd_table   ,cmd_lcd   ,0,1 },
-               { "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 },
-               { "volume",N_("Query information about guest-os volume.")           ,cmd_volume_table,cmd_volume,0,0 },
-               { "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 },
-               { "rmdir" ,N_("Remove guest-os directory[1].")                      ,cmd_rmdir_table ,cmd_rmdir ,1,1 },
-               { "commit",N_("Write any pending changes and remount the volume.")  ,cmd_commit_table,cmd_commit,0,0 },
-               { "quit"  ,N_("Quit this program.")                                 ,cmd_quit_table  ,cmd_quit  ,0,0 },
-               { "help"  ,N_("Show this list of commands or help for command[1].") ,cmd_help_table  ,cmd_help  ,0,1 },
+               { "shell" ,N_("Interactive commands shell.")                                ,cmd_shell_table ,cmd_shell ,0,0 },
+               { "cd"    ,N_("Print or change current guest-os directory[1].")             ,cmd_cd_table    ,cmd_cd    ,0,1 },
+               { "lcd"   ,N_("Print or change current host-os  directory[1].")             ,cmd_lcd_table   ,cmd_lcd   ,0,1 },
+               { "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 },
+               { "volume",N_("Query information about guest-os volume.")                   ,cmd_volume_table,cmd_volume,0,0 },
+               { "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 },
+               { "rmdir" ,N_("Remove guest-os directory[1].")                              ,cmd_rmdir_table ,cmd_rmdir ,1,1 },
+               { "commit",N_("Write any pending changes and remount the volume.")          ,cmd_commit_table,cmd_commit,0,0 },
+               { "open"  ,N_("Open as[1] file[2] in mode; see 'open --help'")              ,cmd_open_table  ,cmd_open  ,2,2 },
+               { "create",N_("Create as[1] file[2] in mode with perm; see 'create --help'"),cmd_create_table,cmd_create,2,2 },
+               { "close" ,N_("Close handle[1]")                                            ,cmd_close_table ,cmd_close ,1,1 },
+               { "quit"  ,N_("Quit this program.")                                         ,cmd_quit_table  ,cmd_quit  ,0,0 },
+               { "help"  ,N_("Show this list of commands or help for command[1].")         ,cmd_help_table  ,cmd_help  ,0,1 },
                { NULL },       /* G_N_ELEMENTS() not usable as sizeof() is not visible for 'extern' */
                };