Finished and deployed CORBA sandbox separation
authorshort <>
Sun, 4 May 2003 12:03:33 +0000 (12:03 +0000)
committershort <>
Sun, 4 May 2003 12:03:33 +0000 (12:03 +0000)
39 files changed:
NEWS
TODO
src/client/cmdline/cmd_quit.c
src/client/cmdline/main.c
src/client/cmdline/main.h
src/libcaptive/client/directory.c
src/libcaptive/client/directory.h
src/libcaptive/client/file.c
src/libcaptive/client/file.h
src/libcaptive/client/init.c
src/libcaptive/client/options.c
src/libcaptive/client/vfs.c
src/libcaptive/client/vfs.h
src/libcaptive/include/captive/Makefile.am
src/libcaptive/include/captive/options.h
src/libcaptive/include/captive/parent-Directory.h [new file with mode: 0644]
src/libcaptive/include/captive/parent-File.h [new file with mode: 0644]
src/libcaptive/include/captive/parent-Vfs.h [new file with mode: 0644]
src/libcaptive/include/captive/storage.h
src/libcaptive/sandbox/FileInfo.c [new file with mode: 0644]
src/libcaptive/sandbox/FileInfo.h [new file with mode: 0644]
src/libcaptive/sandbox/Makefile.am
src/libcaptive/sandbox/parent-Directory.c [new file with mode: 0644]
src/libcaptive/sandbox/parent-File.c [new file with mode: 0644]
src/libcaptive/sandbox/parent-Vfs.c [new file with mode: 0644]
src/libcaptive/sandbox/sandbox.idl
src/libcaptive/sandbox/server-Directory.c
src/libcaptive/sandbox/server-Directory.h
src/libcaptive/sandbox/server-File.c
src/libcaptive/sandbox/server-File.h
src/libcaptive/sandbox/server-GlibLogFunc.c
src/libcaptive/sandbox/server-GlibLogFunc.h
src/libcaptive/sandbox/server-Vfs.c [new file with mode: 0644]
src/libcaptive/sandbox/server-Vfs.h [moved from src/libcaptive/include/captive/sandbox.h with 57% similarity]
src/libcaptive/sandbox/split.c
src/libcaptive/sandbox/split.h
src/libcaptive/storage/cdrom.c
src/libcaptive/storage/disk.c
src/libcaptive/storage/media.c

diff --git a/NEWS b/NEWS
index 8c75f37..04a4fb8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ $Id$
 NEWS for captive-0.9
 --------------------
 
+* Multifilesystem capability by new CaptiveVfsObject
+* Finished and deployed CORBA sandbox separation
 
 
 NEWS for captive-0.8 (2003-05-02)
diff --git a/TODO b/TODO
index 3ad7f1e..b98f1a2 100644 (file)
--- a/TODO
+++ b/TODO
@@ -4,6 +4,4 @@ $Id$
 TODO
 ----
 
-* Finish src/libcaptive/sandbox/ CORBA interface
-  * Implement backward GIOChannel CORBA interface
-* reentrancy of captive_init() to return non-static GObject captive_vfs
+* Implement backward GIOChannel CORBA interface
index 6cef446..a924eb4 100644 (file)
 #include <glib/gerror.h>
 #include <popt.h>
 #include <stdlib.h>
+#include <glib-object.h>
 
 #include "cmd_quit.h"  /* self */
+#include "main.h"
 
 
 GQuark cmdline_cmd_quit_error_quark(void)
@@ -48,5 +50,5 @@ void cmd_quit(const char **cmd_argv,GError **errp)
 {
        g_return_if_fail(!errp || !*errp);
 
-       exit(EXIT_SUCCESS);
+       main_exit();
 }
index 32e7945..a9fe5d8 100644 (file)
@@ -194,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;
index 138f531..e9cd88f 100644 (file)
@@ -55,6 +55,7 @@ extern CaptiveVfsObject *cmdline_captive_vfs_object;
 void invoke_cmd(int cmd_argc,const char **cmd_argv);
 void err_cleanup(GError **errp);
 gboolean errvfsresult_to_gerr(GError **errp,GnomeVFSResult errvfsresult);
+void main_exit(void);
 
 
 #endif /* _CAPTIVE_CLIENT_CMDLINE_MAIN_H */
index 36322c9..7960091 100644 (file)
 #include "reactos/ntos/types.h"        /* for HANDLE */
 #include "reactos/ddk/iotypes.h"       /* for IO_STATUS_BLOCK */
 #include "reactos/ddk/iofuncs.h"       /* for IoCreateFile() */
-#include "captive/sandbox.h"
 #include "result.h"
 #include "captive/leave.h"
 #include "captive/usecount.h"
+#include "vfs.h"
+#include "captive/parent-Directory.h"
 
 
 static gpointer captive_directory_object_parent_class=NULL;
@@ -40,12 +41,9 @@ static GnomeVFSResult captive_directory_close(CaptiveDirectoryObject *captive_di
 
 static void captive_directory_object_finalize(CaptiveDirectoryObject *captive_directory_object)
 {
-GnomeVFSResult errvfsresult;
-
        g_return_if_fail(captive_directory_object!=NULL);
 
-       errvfsresult=captive_directory_close(captive_directory_object);
-       g_assert(errvfsresult==GNOME_VFS_OK);
+       captive_directory_close(captive_directory_object);      /* errors ignored */
 
        G_OBJECT_CLASS(captive_directory_object_parent_class)->finalize((GObject *)captive_directory_object);
 }
@@ -94,22 +92,18 @@ static const GTypeInfo captive_directory_object_info={
 }
 
 
-static GnomeVFSResult captive_directory_new_internal(CaptiveDirectoryObject **captive_directory_object_return,
-               CaptiveVfsObject *captive_vfs_object,const gchar *pathname,gboolean create,guint create_perm)
+static GnomeVFSResult captive_directory_new_internal
+               (CaptiveDirectoryObject *captive_directory_object,const gchar *pathname,gboolean create,guint create_perm)
 {
 GnomeVFSResult errvfsresult;
 OBJECT_ATTRIBUTES dir_ObjectAttributes;
 HANDLE dir_Handle;
 IO_STATUS_BLOCK dir_IoStatusBlock;
 NTSTATUS err;
-CaptiveDirectoryObject *captive_directory_object;
 
-       g_return_val_if_fail(captive_directory_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_directory_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
-       *captive_directory_object_return=NULL;
-
        errvfsresult=captive_ObjectAttributes_init(pathname,&dir_ObjectAttributes);
        g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
        
@@ -145,14 +139,8 @@ CaptiveDirectoryObject *captive_directory_object;
                                        ==(!create ? FILE_OPENED : FILE_CREATED),
                        GNOME_VFS_ERROR_GENERIC);
 
-       captive_directory_object=g_object_new(
-                       CAPTIVE_DIRECTORY_TYPE_OBJECT,  /* object_type */
-                       NULL);  /* first_property_name; FIXME: support properties */
-
-       captive_directory_object->vfs=captive_vfs_object;
        captive_directory_object->dir_Handle=dir_Handle;
 
-       *captive_directory_object_return=captive_directory_object;
        return GNOME_VFS_OK;
 }
 
@@ -161,21 +149,31 @@ GnomeVFSResult captive_directory_new_open(CaptiveDirectoryObject **captive_direc
                CaptiveVfsObject *captive_vfs_object,const gchar *pathname)
 {
 GnomeVFSResult r;
-
-       if (CAPTIVE_IS_SANDBOX_PARENT())
-               return captive_sandbox_parent_directory_new_open(captive_directory_object_return,pathname);
+CaptiveDirectoryObject *captive_directory_object;
 
        g_return_val_if_fail(captive_directory_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
-       r=captive_directory_new_internal(captive_directory_object_return,captive_vfs_object,pathname,
+       captive_directory_object=g_object_new(
+                       CAPTIVE_DIRECTORY_TYPE_OBJECT,  /* object_type */
+                       NULL);  /* first_property_name; FIXME: support properties */
+       captive_directory_object->dir_Handle=NULL;
+       captive_directory_object->vfs=captive_vfs_object;
+       *captive_directory_object_return=captive_directory_object;
+
+       if (captive_vfs_object->is_sandbox_parent)
+               return captive_sandbox_parent_directory_new_open(captive_directory_object,pathname);
+
+       r=captive_directory_new_internal(captive_directory_object,pathname,
                        FALSE,  /* create */
                        0);     /* create_perm; ignored */
 
        captive_leave();
        if (r==GNOME_VFS_OK)
                captive_usecount(+1);
+       else
+               g_object_unref(captive_directory_object);
        return r;
 }
 
@@ -184,18 +182,31 @@ GnomeVFSResult captive_directory_new_make(CaptiveDirectoryObject **captive_direc
                CaptiveVfsObject *captive_vfs_object,const gchar *pathname,guint perm)
 {
 GnomeVFSResult r;
+CaptiveDirectoryObject *captive_directory_object;
 
        g_return_val_if_fail(captive_directory_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
-       r=captive_directory_new_internal(captive_directory_object_return,captive_vfs_object,pathname,
+       captive_directory_object=g_object_new(
+                       CAPTIVE_DIRECTORY_TYPE_OBJECT,  /* object_type */
+                       NULL);  /* first_property_name; FIXME: support properties */
+       captive_directory_object->dir_Handle=NULL;
+       captive_directory_object->vfs=captive_vfs_object;
+       *captive_directory_object_return=captive_directory_object;
+
+       if (captive_vfs_object->is_sandbox_parent)
+               return captive_sandbox_parent_directory_new_make(captive_directory_object,pathname,perm);
+
+       r=captive_directory_new_internal(captive_directory_object,pathname,
                        TRUE,   /* create */
                        perm);  /* create_perm; ignored */
 
        captive_leave();
        if (r==GNOME_VFS_OK)
                captive_usecount(+1);
+       else
+               g_object_unref(captive_directory_object);
        return r;
 }
 
@@ -348,18 +359,19 @@ static GnomeVFSResult captive_directory_close(CaptiveDirectoryObject *captive_di
 NTSTATUS err;
 HANDLE dir_Handle;
 
-       if (CAPTIVE_IS_SANDBOX_PARENT())
-               return captive_sandbox_parent_directory_close(captive_directory_object);
-
        g_return_val_if_fail(captive_directory_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(captive_directory_object->dir_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);        /* already closed */
 
-       captive_usecount(-1);   /* close() errors notwithstanding */
+       if (captive_directory_object->vfs->is_sandbox_parent)
+               return captive_sandbox_parent_directory_close(captive_directory_object);
 
-       dir_Handle=captive_directory_object->dir_Handle;
-       captive_directory_object->dir_Handle=NULL;
-       err=NtClose(dir_Handle);
-       g_return_val_if_fail(NT_SUCCESS(err),GNOME_VFS_ERROR_GENERIC);
+       if (captive_directory_object->dir_Handle!=NULL) {       /* not yet already closed */
+               captive_usecount(-1);   /* close() errors notwithstanding */
+
+               dir_Handle=captive_directory_object->dir_Handle;
+               captive_directory_object->dir_Handle=NULL;
+               err=NtClose(dir_Handle);
+               g_return_val_if_fail(NT_SUCCESS(err),GNOME_VFS_ERROR_GENERIC);
+               }
 
        captive_leave();
        return GNOME_VFS_OK;
@@ -374,12 +386,13 @@ FILE_ID_BOTH_DIR_INFORMATION *FileIdBothDirInformation;
 FILE_BOTH_DIR_INFORMATION *FileBothDirInformation;
 GnomeVFSResult errvfsresult;
 
-       if (CAPTIVE_IS_SANDBOX_PARENT())
+       g_return_val_if_fail(captive_directory_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(file_info!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       if (captive_directory_object->vfs->is_sandbox_parent)
                return captive_sandbox_parent_directory_read(captive_directory_object,file_info);
 
-       g_return_val_if_fail(captive_directory_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(captive_directory_object->dir_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(file_info!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
        FileIdBothDirInformation=(void *)captive_directory_object->QueryDirectory_buf.FileIdBothDirInformation;
 retry:
@@ -468,6 +481,10 @@ IO_STATUS_BLOCK dir_IoStatusBlock;
 GnomeVFSResult errvfsresult;
 
        g_return_val_if_fail(captive_directory_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       if (captive_directory_object->vfs->is_sandbox_parent)
+               return captive_sandbox_parent_directory_remove(captive_directory_object);
+
        g_return_val_if_fail(captive_directory_object->dir_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
        FileDispositionInformation_struct.DoDeleteFile=TRUE;
index b96868f..0083fcb 100644 (file)
@@ -26,6 +26,7 @@
 #include "reactos/napi/types.h"        /* for NTSTATUS */
 #include "reactos/ntos/zwtypes.h"      /* for FILE_ID_BOTH_DIR_INFORMATION */
 #include "captive/client-vfs.h"
+#include "../sandbox/sandbox.h"
 
 
 G_BEGIN_DECLS
@@ -35,6 +36,7 @@ struct _CaptiveDirectoryObject {
 
        /*< private >*/
        CaptiveVfsObject *vfs;
+       Captive_Directory corba_Directory_object;
        HANDLE dir_Handle;
        gboolean read_first;
        /* 'QueryDirectory_buf' for NtQueryDirectoryFile() must be persistent
index ff2da21..80df600 100644 (file)
 #include "reactos/ntos/types.h"        /* for HANDLE */
 #include "reactos/ddk/iotypes.h"       /* for IO_STATUS_BLOCK */
 #include "reactos/ddk/iofuncs.h"       /* for IoCreateFile() */
-#include "captive/sandbox.h"
 #include "result.h"
 #include "captive/client-directory.h"
 #include "reactos/ddk/obfuncs.h"       /* for ObReferenceObjectByHandle() */
 #include "captive/macros.h"
 #include "captive/leave.h"
 #include "captive/usecount.h"
+#include "vfs.h"
+#include "captive/parent-File.h"
 
 
 static gpointer captive_file_object_parent_class=NULL;
@@ -44,12 +45,9 @@ static GnomeVFSResult captive_file_close(CaptiveFileObject *captive_file_object)
 
 static void captive_file_object_finalize(CaptiveFileObject *captive_file_object)
 {
-GnomeVFSResult errvfsresult;
-
        g_return_if_fail(captive_file_object!=NULL);
 
-       errvfsresult=captive_file_close(captive_file_object);
-       g_assert(errvfsresult==GNOME_VFS_OK);
+       captive_file_close(captive_file_object);        /* errors ignored */
 
        G_OBJECT_CLASS(captive_file_object_parent_class)->finalize((GObject *)captive_file_object);
 }
@@ -95,26 +93,18 @@ static const GTypeInfo captive_file_object_info={
 }
 
 
-static GnomeVFSResult captive_file_new_internal(CaptiveFileObject **captive_file_object_return,
-               CaptiveVfsObject *captive_vfs_object,
+static GnomeVFSResult captive_file_new_internal(CaptiveFileObject *captive_file_object,
                const gchar *pathname,GnomeVFSOpenMode mode,gboolean create,gboolean create_exclusive,guint create_perm)
 {
 IO_STATUS_BLOCK file_IoStatusBlock;
 GnomeVFSResult errvfsresult;
 OBJECT_ATTRIBUTES file_ObjectAttributes;
 HANDLE file_Handle;
-CaptiveFileObject *captive_file_object;
 NTSTATUS err;
 
-       if (CAPTIVE_IS_SANDBOX_PARENT())
-               return captive_sandbox_parent_file_new_open(captive_file_object_return,pathname,mode);
-
-       g_return_val_if_fail(captive_file_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
-       *captive_file_object_return=NULL;
-
        errvfsresult=captive_ObjectAttributes_init(pathname,&file_ObjectAttributes);
        g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
        
@@ -154,15 +144,8 @@ NTSTATUS err;
                                        ==(!create ? FILE_OPENED : FILE_CREATED),
                        GNOME_VFS_ERROR_GENERIC);
 
-       captive_file_object=g_object_new(
-                       CAPTIVE_FILE_TYPE_OBJECT,       /* object_type */
-                       NULL);  /* first_property_name; FIXME: support properties */
-
-       captive_file_object->vfs=captive_vfs_object;
        captive_file_object->file_Handle=file_Handle;
-       captive_file_object->offset=0;
 
-       *captive_file_object_return=captive_file_object;
        return GNOME_VFS_OK;
 }
 
@@ -171,12 +154,24 @@ GnomeVFSResult captive_file_new_open(CaptiveFileObject **captive_file_object_ret
                CaptiveVfsObject *captive_vfs_object,const gchar *pathname,GnomeVFSOpenMode mode)
 {
 GnomeVFSResult r;
+CaptiveFileObject *captive_file_object;
 
        g_return_val_if_fail(captive_file_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
-       r=captive_file_new_internal(captive_file_object_return,captive_vfs_object,pathname,mode,
+       captive_file_object=g_object_new(
+                       CAPTIVE_FILE_TYPE_OBJECT,       /* object_type */
+                       NULL);  /* first_property_name; FIXME: support properties */
+       captive_file_object->vfs=captive_vfs_object;
+       captive_file_object->file_Handle=NULL;
+       captive_file_object->offset=0;
+       *captive_file_object_return=captive_file_object;
+
+       if (captive_vfs_object->is_sandbox_parent)
+               return captive_sandbox_parent_file_new_open(captive_file_object,pathname,mode);
+
+       r=captive_file_new_internal(captive_file_object,pathname,mode,
                        FALSE,  /* create */
                        FALSE,  /* create_exclusive; ignored */
                        0);     /* create_perm; ignored */
@@ -184,6 +179,8 @@ GnomeVFSResult r;
        captive_leave();
        if (r==GNOME_VFS_OK)
                captive_usecount(+1);
+       else
+               g_object_unref(captive_file_object);
        return r;
 }
 
@@ -192,12 +189,24 @@ GnomeVFSResult captive_file_new_create(CaptiveFileObject **captive_file_object_r
                CaptiveVfsObject *captive_vfs_object,const gchar *pathname,GnomeVFSOpenMode mode,gboolean exclusive,guint perm)
 {
 GnomeVFSResult r;
+CaptiveFileObject *captive_file_object;
 
        g_return_val_if_fail(captive_file_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
-       r=captive_file_new_internal(captive_file_object_return,captive_vfs_object,pathname,mode,
+       captive_file_object=g_object_new(
+                       CAPTIVE_FILE_TYPE_OBJECT,       /* object_type */
+                       NULL);  /* first_property_name; FIXME: support properties */
+       captive_file_object->vfs=captive_vfs_object;
+       captive_file_object->file_Handle=NULL;
+       captive_file_object->offset=0;
+       *captive_file_object_return=captive_file_object;
+
+       if (captive_vfs_object->is_sandbox_parent)
+               return captive_sandbox_parent_file_new_create(captive_file_object,pathname,mode,exclusive,perm);
+
+       r=captive_file_new_internal(captive_file_object,pathname,mode,
                        TRUE,   /* create */
                        exclusive,      /* create_exclusive */
                        perm);  /* create_perm */
@@ -205,6 +214,8 @@ GnomeVFSResult r;
        captive_leave();
        if (r==GNOME_VFS_OK)
                captive_usecount(+1);
+       else
+               g_object_unref(captive_file_object);
        return r;
 }
 
@@ -214,18 +225,19 @@ static GnomeVFSResult captive_file_close(CaptiveFileObject *captive_file_object)
 NTSTATUS err;
 HANDLE file_Handle;
 
-       if (CAPTIVE_IS_SANDBOX_PARENT())
-               return captive_sandbox_parent_file_close(captive_file_object);
-
        g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);    /* already closed */
 
-       captive_usecount(-1);   /* close() errors notwithstanding */
+       if (captive_file_object->vfs->is_sandbox_parent)
+               return captive_sandbox_parent_file_close(captive_file_object);
 
-       file_Handle=captive_file_object->file_Handle;
-       captive_file_object->file_Handle=NULL;
-       err=NtClose(file_Handle);
-       g_return_val_if_fail(NT_SUCCESS(err),GNOME_VFS_ERROR_GENERIC);
+       if (captive_file_object->file_Handle!=NULL) {   /* not yet already closed */
+               captive_usecount(-1);   /* close() errors notwithstanding */
+
+               file_Handle=captive_file_object->file_Handle;
+               captive_file_object->file_Handle=NULL;
+               err=NtClose(file_Handle);
+               g_return_val_if_fail(NT_SUCCESS(err),GNOME_VFS_ERROR_GENERIC);
+               }
 
        captive_leave();
        return GNOME_VFS_OK;
@@ -240,15 +252,16 @@ IO_STATUS_BLOCK file_IoStatusBlock;
 LARGE_INTEGER file_offset;
 GnomeVFSResult errvfsresult;
 
-       if (CAPTIVE_IS_SANDBOX_PARENT())
-               return captive_sandbox_parent_file_read(captive_file_object,buffer,num_bytes,bytes_read_return);
-
        g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(buffer!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(bytes_read_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(num_bytes==(ULONG)num_bytes,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
+       if (captive_file_object->vfs->is_sandbox_parent)
+               return captive_sandbox_parent_file_read(captive_file_object,buffer,num_bytes,bytes_read_return);
+
+       g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
        file_offset.QuadPart=captive_file_object->offset;
        err=NtReadFile(
                        captive_file_object->file_Handle,       /* FileHandle */
@@ -289,15 +302,16 @@ GnomeVFSFileInfo file_info;
 GnomeVFSFileSize endoffile_wanted;
 GnomeVFSResult errvfsresult;
 
-       if (CAPTIVE_IS_SANDBOX_PARENT())
-               return captive_sandbox_parent_file_write(captive_file_object,buffer,num_bytes,bytes_written_return);
-
        g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(buffer!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(bytes_written_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(num_bytes==(ULONG)num_bytes,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
+       if (captive_file_object->vfs->is_sandbox_parent)
+               return captive_sandbox_parent_file_write(captive_file_object,buffer,num_bytes,bytes_written_return);
+
+       g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
        if ((GnomeVFSFileOffset)(captive_file_object->offset+num_bytes) < captive_file_object->offset)
                return GNOME_VFS_ERROR_TOO_BIG;
        endoffile_wanted=captive_file_object->offset+num_bytes;
@@ -333,10 +347,11 @@ GnomeVFSResult errvfsresult;
 GnomeVFSResult captive_file_seek
                (CaptiveFileObject *captive_file_object,GnomeVFSSeekPosition whence,GnomeVFSFileOffset offset)
 {
-       if (CAPTIVE_IS_SANDBOX_PARENT())
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       if (captive_file_object->vfs->is_sandbox_parent)
                return captive_sandbox_parent_file_seek(captive_file_object,whence,offset);
 
-       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
        switch (whence) {
@@ -364,12 +379,13 @@ GnomeVFSResult captive_file_seek
 
 GnomeVFSResult captive_file_tell(CaptiveFileObject *captive_file_object,GnomeVFSFileOffset *offset_return)
 {
-       if (CAPTIVE_IS_SANDBOX_PARENT())
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(offset_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       if (captive_file_object->vfs->is_sandbox_parent)
                return captive_sandbox_parent_file_tell(captive_file_object,offset_return);
 
-       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(offset_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
        *offset_return=captive_file_object->offset;
        captive_leave();
@@ -385,6 +401,10 @@ IO_STATUS_BLOCK file_IoStatusBlock;
 GnomeVFSResult errvfsresult;
 
        g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       if (captive_file_object->vfs->is_sandbox_parent)
+               return captive_sandbox_parent_file_remove(captive_file_object);
+
        g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
        FileDispositionInformation_struct.DoDeleteFile=TRUE;
@@ -524,9 +544,13 @@ char QueryFile_buf[sizeof(FILE_NAME_INFORMATION)
                +0x1000 /* max 'FileName' length, 255 should be enough */ * sizeof(WCHAR /* *FILE_ALL_INFORMATION.NameInformation.FileName */ )];
 
        g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(file_info!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
+       if (captive_file_object->vfs->is_sandbox_parent)
+               return captive_sandbox_parent_file_file_info_get(captive_file_object,file_info);
+
+       g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
        /* ntfs.sys of NT-5.1sp1 has *(FILE_BASIC_INFORMATION *)FILE_ALL_INFORMATION.BasicInformation
         * size 0x28 although reactos includes and all the information says 0x24.
         * fastfat.sys of NT-5.1sp1 also has the 'official' sizeof 0x24.
@@ -593,9 +617,13 @@ GnomeVFSResult captive_file_file_info_set(CaptiveFileObject *captive_file_object
     const GnomeVFSFileInfo *info,GnomeVFSSetFileInfoMask mask)
 {
        g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(info!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
+       if (captive_file_object->vfs->is_sandbox_parent)
+               return captive_sandbox_parent_file_file_info_set(captive_file_object,info,mask);
+
+       g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
        if (mask & GNOME_VFS_SET_FILE_INFO_NAME) {
 gchar *name_dirname,*name_basename;
 UNICODE_STRING *name_UnicodeString;
@@ -729,6 +757,10 @@ IO_STATUS_BLOCK file_IoStatusBlock;
 GnomeVFSResult errvfsresult;
 
        g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       if (captive_file_object->vfs->is_sandbox_parent)
+               return captive_sandbox_parent_file_truncate(captive_file_object,file_size);
+
        g_return_val_if_fail(captive_file_object->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
        FileEndOfFileInformation_struct.EndOfFile.QuadPart=file_size;
@@ -757,9 +789,13 @@ GnomeVFSResult errvfsresult;
 OBJECT_ATTRIBUTES pathname_new_ObjectAttributes;
 
        g_return_val_if_fail(captive_file_object_old!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
-       g_return_val_if_fail(captive_file_object_old->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(pathname_new!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
+       if (captive_file_object_old->vfs->is_sandbox_parent)
+               return captive_sandbox_parent_file_move(captive_file_object_old,pathname_new,force_replace);
+
+       g_return_val_if_fail(captive_file_object_old->file_Handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
        errvfsresult=captive_ObjectAttributes_init(pathname_new,&pathname_new_ObjectAttributes);
        g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
 
index 629937c..16eebf8 100644 (file)
@@ -25,6 +25,7 @@
 #include <glib/gtypes.h>
 #include "reactos/napi/types.h"        /* for NTSTATUS */
 #include "captive/client-vfs.h"
+#include "../sandbox/sandbox.h"
 
 
 G_BEGIN_DECLS
@@ -34,6 +35,7 @@ struct _CaptiveFileObject {
 
        /*< private >*/
        CaptiveVfsObject *vfs;
+       Captive_File corba_File_object;
        HANDLE file_Handle;
        GnomeVFSFileOffset offset;
        };
index b3de39e..bfeb479 100644 (file)
@@ -41,7 +41,6 @@
 #include <popt.h>
 #include <glib/gstrfuncs.h>
 #include <glib/glist.h>
-#include <glib/gutils.h>       /* for g_atexit() */
 #include "giochannel-blind.h"
 #include <glib-object.h>
 #include "reactos/internal/se.h"       /* for SeInit2() */
@@ -66,10 +65,6 @@ PVOID captive_DriverObject_ReinitRoutine_Context;
 static TOP_LEVEL_IRP TopLevelIrp;      /* TODO:thread */
 
 
-/* Non-blinded original GIOChannel for flushing during shutdown. */
-static GIOChannel *captive_options_image_iochannel_orig;
-
-
 void *_local_unwind2_addr;
 
 
@@ -91,13 +86,13 @@ GIOStatus erriostatus;
        g_return_val_if_fail(captive_options!=NULL,FALSE);
        g_return_val_if_fail(captive_options->filesystem!=NULL,FALSE);
 
-       erriostatus=g_io_channel_set_encoding(captive_options->image_iochannel,
+       erriostatus=g_io_channel_set_encoding(captive_image_iochannel,
                        NULL,   /* encoding; force binary data */
                        NULL);  /* error */
        g_assert(erriostatus==G_IO_STATUS_NORMAL);
 
        /* captive_giochannel_size() only _after_ g_io_channel_set_encoding() ! */
-       captive_image_size=captive_giochannel_size(captive_options->image_iochannel);
+       captive_image_size=captive_giochannel_size(captive_image_iochannel);
        g_return_val_if_fail(captive_image_size>0,FALSE);
 
        /* Part of reactos/ntoskrnl/ke/main.c/KiSystemStartup() begins. */
@@ -219,9 +214,6 @@ NTSTATUS err;
 }
 
 
-static void captive_shutdown_atexit(void);
-
-
 static void    log_discard_func(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
 {
        /* NOP */
@@ -264,6 +256,7 @@ gboolean errbool;
                                0       /* log_levels */
                                                | G_LOG_FLAG_RECURSION
                                                | G_LOG_FLAG_FATAL
+                                               /* The same mask is in libcaptive/sandbox/server-GlibLogFunc.c ! */
                                                | G_LOG_LEVEL_MESSAGE
                                                | G_LOG_LEVEL_INFO
                                                | G_LOG_LEVEL_DEBUG,
@@ -271,9 +264,10 @@ gboolean errbool;
                                NULL);  /* user_data */
                }
 
-       captive_options_image_iochannel_orig=captive_options->image_iochannel;
        if (captive_options->rwmode==CAPTIVE_OPTION_RWMODE_BLIND)
-               captive_options->image_iochannel=(GIOChannel *)captive_giochannel_blind_new(captive_options->image_iochannel);
+               captive_image_iochannel=(GIOChannel *)captive_giochannel_blind_new(captive_options->image_iochannel);
+       else
+               captive_image_iochannel=captive_options->image_iochannel;
 
        /* Do not initialize 'captive_image_size' by captive_giochannel_size() here
         * as we yet need to do g_io_channel_set_encoding().
@@ -282,8 +276,6 @@ gboolean errbool;
        errbool=captive_w32_init();
        g_return_val_if_fail(errbool==TRUE,FALSE);
 
-       g_atexit(captive_shutdown_atexit);
-
        active=TRUE;
        return TRUE;
 }
@@ -296,7 +288,7 @@ void captive_cc_flush(void);
  * captive_shutdown:
  *
  * Closes down %libcaptive. It should flush all pending buffers and successfuly
- * close the filesystem. Variable #captive_options->image_iochannel will be set to %NULL,
+ * close the filesystem. Variable #captive_options->image_iochannel will not be set to %NULL,
  * you should close such channel yourself.
  *
  * Returns: %TRUE if successfuly shutdown.
@@ -306,6 +298,7 @@ gboolean captive_shutdown(void)
 GIOStatus erriostatus;
 
        g_return_val_if_fail(active==TRUE,FALSE);
+       g_return_val_if_fail(captive_image_iochannel!=NULL,FALSE);
        g_return_val_if_fail(captive_options->image_iochannel!=NULL,FALSE);
 
        /* Invoke all pending idle functions just to not to forget for anything... */
@@ -341,27 +334,21 @@ GIOStatus erriostatus;
 
        /* libcaptive is not authorized to shutdown 'captive_image_channel'. */
        erriostatus=g_io_channel_flush(
-                       captive_options->image_iochannel,       /* channel */
+                       captive_image_iochannel,        /* channel */
                        NULL);  /* error */
        g_assert(erriostatus==G_IO_STATUS_NORMAL);
 
-       /* 'captive_options->image_iochannel' may be blinded wrapper. */
-       if (captive_options->image_iochannel!=captive_options_image_iochannel_orig) {
+       /* 'captive_image_iochannel' may be blinded wrapper of 'captive_options->image_iochannel'. */
+       if (captive_image_iochannel!=captive_options->image_iochannel) {
                erriostatus=g_io_channel_flush(
-                               captive_options_image_iochannel_orig,   /* channel */
+                               captive_options->image_iochannel,       /* channel */
                                NULL);  /* error */
                g_assert(erriostatus==G_IO_STATUS_NORMAL);
+               g_io_channel_unref(captive_image_iochannel);
                }
 
-       captive_options->image_iochannel=NULL;
+       captive_image_iochannel=NULL;
 
        active=FALSE;
        return TRUE;
 }
-
-
-static void captive_shutdown_atexit(void)
-{
-       if (active)
-               captive_shutdown();
-}
index 457fbcb..fd71a87 100644 (file)
@@ -35,6 +35,7 @@ void captive_options_init(struct captive_options *options)
        options->media=CAPTIVE_OPTION_MEDIA_DISK;
        options->debug_messages=FALSE;
        options->load_module=NULL;
+       options->sandbox=TRUE;
 }
 
 
@@ -101,6 +102,11 @@ static void arg_debug_messages(void)
        captive_options->debug_messages=TRUE;
 }
 
+static void arg_no_sandbox(void)
+{
+       captive_options->sandbox=FALSE;
+}
+
 
 static void captive_popt_callback
                (poptContext con,enum poptCallbackReason reason,const struct poptOption *opt,const char *arg,const void *data);
@@ -132,6 +138,7 @@ const struct poptOption captive_popt[]={
                CAPTIVE_POPT_NONE(  "cdrom"         ,N_("Media type: CD-ROM")),
                CAPTIVE_POPT_NONE(  "disk"          ,N_("Media type: Disk (default)")),
                CAPTIVE_POPT_NONE(  "debug-messages",N_("Turn on debugging messages")),
+               CAPTIVE_POPT_NONE(  "no-sandbox"    ,N_("Turn off sandboxing feature (default on)")),
 
 #undef CAPTIVE_POPT_NONE
 #undef CAPTIVE_POPT_STRING
@@ -155,6 +162,7 @@ static void (*const popt_func_table[])(void)={
                arg_cdrom,
                arg_disk,
                arg_debug_messages,
+               arg_no_sandbox,
                };
 
 
index bb3cd97..e31ce55 100644 (file)
@@ -23,8 +23,9 @@
 #include "vfs.h"       /* self-priv */
 #include <glib/gmessages.h>
 #include "captive/macros.h"
-#include "captive/sandbox.h"
 #include "init.h"
+#include "captive/parent-Vfs.h"
+#include "../sandbox/server-Vfs.h"     /* for captive_corba_child_options */
 
 
 static gpointer captive_vfs_object_parent_class=NULL;
@@ -34,12 +35,9 @@ static GnomeVFSResult captive_vfs_close(CaptiveVfsObject *captive_vfs_object);
 
 static void captive_vfs_object_finalize(CaptiveVfsObject *captive_vfs_object)
 {
-GnomeVFSResult errvfsresult;
-
        g_return_if_fail(captive_vfs_object!=NULL);
 
-       errvfsresult=captive_vfs_close(captive_vfs_object);
-       g_assert(errvfsresult==GNOME_VFS_OK);
+       captive_vfs_close(captive_vfs_object);  /* errors ignored */
 
        G_OBJECT_CLASS(captive_vfs_object_parent_class)->finalize((GObject *)captive_vfs_object);
 }
@@ -102,13 +100,18 @@ gboolean errbool;
 
        captive_options_copy(&captive_vfs_object->options,options);
 
+       *captive_vfs_object_return=captive_vfs_object;
+
+       /* We are sandboxing && we are the master */
+       if (options->sandbox && !captive_corba_child_options)
+               return captive_sandbox_parent_vfs_new(captive_vfs_object);
+
        g_assert(captive_options==NULL);
        captive_options=&captive_vfs_object->options;
 
        errbool=captive_init();
        g_assert(errbool==TRUE);
 
-       *captive_vfs_object_return=captive_vfs_object;
        return GNOME_VFS_OK;
 }
 
@@ -117,11 +120,11 @@ static GnomeVFSResult captive_vfs_close(CaptiveVfsObject *captive_vfs_object)
 {
 gboolean errbool;
 
-       if (CAPTIVE_IS_SANDBOX_PARENT())
-               return captive_sandbox_parent_vfs_close(captive_vfs_object);
-
        g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
+       if (captive_vfs_object->is_sandbox_parent)
+               return captive_sandbox_parent_vfs_close(captive_vfs_object);
+
        g_assert(captive_options==&captive_vfs_object->options);
        errbool=captive_shutdown();
        g_assert(errbool==TRUE);
index b1103e4..9b39311 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <glib/gmacros.h>
 #include <glib/gtypes.h>
+#include <glib-object.h>
+#include "../sandbox/sandbox.h"
 
 
 G_BEGIN_DECLS
@@ -32,6 +34,11 @@ struct _CaptiveVfsObject {
 
        /*< private >*/
        struct captive_options options;
+
+       gboolean is_sandbox_parent;
+               Captive_Vfs corba_Vfs_object;
+               Captive_GlibLogFunc corba_GlibLogFunc_object;
+               int corba_parentheart_fds_1;
        };
 struct _CaptiveVfsObjectClass {
        GObjectClass parent_class;
index a8cd87b..c658ebc 100644 (file)
@@ -31,9 +31,11 @@ pkginclude_HEADERS+= \
                macros.h \
                mm.h \
                options.h \
+               parent-Directory.h \
+               parent-File.h \
+               parent-Vfs.h \
                ps_reactos.h \
                rtl-file.h \
-               sandbox.h \
                signal.h \
                storage.h \
                unicode.h \
index 41c1e15..fcec917 100644 (file)
@@ -52,6 +52,7 @@ struct captive_options {
        gboolean debug_messages;
        GIOChannel *image_iochannel;
        GList *load_module;     /* of 'gchar *' */
+       gboolean sandbox;
        };
 
 /**
diff --git a/src/libcaptive/include/captive/parent-Directory.h b/src/libcaptive/include/captive/parent-Directory.h
new file mode 100644 (file)
index 0000000..5458075
--- /dev/null
@@ -0,0 +1,44 @@
+/* $Id$
+ * Include file for CORBA/ORBit server side of Directory object of sandbox_parent()
+ * 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_PARENT_DIRECTORY_H
+#define _CAPTIVE_CLIENT_PARENT_DIRECTORY_H 1
+
+
+#include <glib/gmacros.h>
+#include <glib-object.h>
+#include <libgnomevfs/gnome-vfs-result.h>      /* for GnomeVFSResult */
+#include "captive/client-directory.h"
+
+
+G_BEGIN_DECLS
+
+GnomeVFSResult captive_sandbox_parent_directory_new_open
+               (CaptiveDirectoryObject *captive_directory_object,const gchar *pathname);
+GnomeVFSResult captive_sandbox_parent_directory_new_make
+               (CaptiveDirectoryObject *captive_directory_object,const gchar *pathname,guint perm);
+GnomeVFSResult captive_sandbox_parent_directory_close(CaptiveDirectoryObject *captive_directory_object);
+GnomeVFSResult captive_sandbox_parent_directory_read
+               (CaptiveDirectoryObject *captive_directory_object,GnomeVFSFileInfo *file_info_captive);
+GnomeVFSResult captive_sandbox_parent_directory_remove(CaptiveDirectoryObject *captive_directory_object);
+
+G_END_DECLS
+
+
+#endif /* _CAPTIVE_CLIENT_PARENT_DIRECTORY_H */
diff --git a/src/libcaptive/include/captive/parent-File.h b/src/libcaptive/include/captive/parent-File.h
new file mode 100644 (file)
index 0000000..a93c2e3
--- /dev/null
@@ -0,0 +1,56 @@
+/* $Id$
+ * Include file for CORBA/ORBit server side of File object of sandbox_parent()
+ * 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_PARENT_FILE_H
+#define _CAPTIVE_CLIENT_PARENT_FILE_H 1
+
+
+#include <glib/gmacros.h>
+#include <glib-object.h>
+#include <libgnomevfs/gnome-vfs-result.h>      /* for GnomeVFSResult */
+#include "captive/client-file.h"
+
+
+G_BEGIN_DECLS
+
+GnomeVFSResult captive_sandbox_parent_file_new_open(CaptiveFileObject *captive_file_object,
+               const gchar *pathname,GnomeVFSOpenMode mode);
+GnomeVFSResult captive_sandbox_parent_file_new_create(CaptiveFileObject *captive_file_object,
+               const gchar *pathname,GnomeVFSOpenMode mode,gboolean exclusive,guint perm);
+GnomeVFSResult captive_sandbox_parent_file_close(CaptiveFileObject *captive_file_object);
+GnomeVFSResult captive_sandbox_parent_file_read(CaptiveFileObject *captive_file_object,
+               gpointer buffer,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_read_return);
+GnomeVFSResult captive_sandbox_parent_file_write(CaptiveFileObject *captive_file_object,
+               gconstpointer buffer,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_written_return);
+GnomeVFSResult captive_sandbox_parent_file_seek
+               (CaptiveFileObject *captive_file_object,GnomeVFSSeekPosition whence,GnomeVFSFileOffset offset);
+GnomeVFSResult captive_sandbox_parent_file_tell(CaptiveFileObject *captive_file_object,GnomeVFSFileOffset *offset_return);
+GnomeVFSResult captive_sandbox_parent_file_remove(CaptiveFileObject *captive_file_object);
+GnomeVFSResult captive_sandbox_parent_file_file_info_get(CaptiveFileObject *captive_file_object,
+               GnomeVFSFileInfo *file_info);
+GnomeVFSResult captive_sandbox_parent_file_file_info_set(CaptiveFileObject *captive_file_object,
+    const GnomeVFSFileInfo *info,GnomeVFSSetFileInfoMask mask);
+GnomeVFSResult captive_sandbox_parent_file_truncate(CaptiveFileObject *captive_file_object,GnomeVFSFileSize file_size);
+GnomeVFSResult captive_sandbox_parent_file_move
+               (CaptiveFileObject *captive_file_object_old,const gchar *pathname_new,gboolean force_replace);
+
+G_END_DECLS
+
+
+#endif /* _CAPTIVE_CLIENT_PARENT_FILE_H */
diff --git a/src/libcaptive/include/captive/parent-Vfs.h b/src/libcaptive/include/captive/parent-Vfs.h
new file mode 100644 (file)
index 0000000..09fbef8
--- /dev/null
@@ -0,0 +1,38 @@
+/* $Id$
+ * Include file for CORBA/ORBit server side of Vfs object of sandbox_parent()
+ * 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_PARENT_VFS_H
+#define _CAPTIVE_CLIENT_PARENT_VFS_H 1
+
+
+#include <glib/gmacros.h>
+#include <glib-object.h>
+#include <libgnomevfs/gnome-vfs-result.h>      /* for GnomeVFSResult */
+#include "captive/client-vfs.h"
+
+
+G_BEGIN_DECLS
+
+GnomeVFSResult captive_sandbox_parent_vfs_new(CaptiveVfsObject *captive_vfs_object);
+GnomeVFSResult captive_sandbox_parent_vfs_close(CaptiveVfsObject *captive_vfs_object);
+
+G_END_DECLS
+
+
+#endif /* _CAPTIVE_CLIENT_PARENT_VFS_H */
index af4597c..f96b295 100644 (file)
 G_BEGIN_DECLS
 
 /**
+ * captive_image_iochannel
+ *
+ * The readl #GIOChannel to be used for accessing the disk image.
+ * It may be either directly #captive_options->image_iochannel
+ * or the wrapper by #giochannel-blind.
+ */
+extern GIOChannel *captive_image_iochannel;
+
+
+/**
  * captive_image_size:
  *
  * Size of #captive_image_iochannel. Empty files are rejected and therefore
diff --git a/src/libcaptive/sandbox/FileInfo.c b/src/libcaptive/sandbox/FileInfo.c
new file mode 100644 (file)
index 0000000..b44f4fd
--- /dev/null
@@ -0,0 +1,93 @@
+/* $Id$
+ * CORBA/ORBit server side of GnomeVFSFileInfo handling
+ * 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 "FileInfo.h"  /* self */
+#include <glib/gmessages.h>
+
+
+GnomeVFSResult captive_sandbox_file_info_corba_to_captive
+               (GnomeVFSFileInfo *file_info_captive,const Captive_GnomeVFSFileInfo *file_info_corba)
+{
+       g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(file_info_corba!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       file_info_captive->valid_fields=0;
+       file_info_captive->name=g_strdup(file_info_corba->name);
+       if (file_info_corba->type_valid) {
+               file_info_captive->type=file_info_corba->type;
+               file_info_captive->valid_fields|=GNOME_VFS_FILE_INFO_FIELDS_TYPE;
+               }
+       if (file_info_corba->permissions_valid) {
+               file_info_captive->permissions=file_info_corba->permissions;
+               file_info_captive->valid_fields|=GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS;
+               }
+       if (file_info_corba->size_valid) {
+               file_info_captive->size=file_info_corba->size;
+               file_info_captive->valid_fields|=GNOME_VFS_FILE_INFO_FIELDS_SIZE;
+               }
+       if (file_info_corba->block_count_valid) {
+               file_info_captive->block_count=file_info_corba->block_count;
+               file_info_captive->valid_fields|=GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT;
+               }
+       if (file_info_corba->atime) {
+               file_info_captive->atime=file_info_corba->atime;
+               file_info_captive->valid_fields|=GNOME_VFS_FILE_INFO_FIELDS_ATIME;
+               }
+       if (file_info_corba->mtime) {
+               file_info_captive->mtime=file_info_corba->mtime;
+               file_info_captive->valid_fields|=GNOME_VFS_FILE_INFO_FIELDS_MTIME;
+               }
+       if (file_info_corba->ctime) {
+               file_info_captive->ctime=file_info_corba->ctime;
+               file_info_captive->valid_fields|=GNOME_VFS_FILE_INFO_FIELDS_CTIME;
+               }
+       if (file_info_corba->flags_valid) {
+               file_info_captive->flags=file_info_corba->flags;
+               file_info_captive->valid_fields|=GNOME_VFS_FILE_INFO_FIELDS_FLAGS;
+               }
+
+       return GNOME_VFS_OK;
+}
+
+
+GnomeVFSResult captive_sandbox_file_info_captive_to_corba
+               (Captive_GnomeVFSFileInfo *file_info_corba,const GnomeVFSFileInfo *file_info_captive)
+{
+       g_return_val_if_fail(file_info_corba!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       file_info_corba->name=CORBA_string_dup(file_info_captive->name);
+       if ((file_info_corba->type_valid=!!(file_info_captive->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_TYPE)))
+               file_info_corba->type=file_info_captive->type;
+       if ((file_info_corba->permissions_valid=!!(file_info_captive->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)))
+               file_info_corba->permissions=file_info_captive->permissions;
+       if ((file_info_corba->size_valid=!!(file_info_captive->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SIZE)))
+               file_info_corba->size=file_info_captive->size;
+       if ((file_info_corba->block_count_valid=!!(file_info_captive->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT)))
+               file_info_corba->block_count=file_info_captive->block_count;
+       file_info_corba->atime=(!(file_info_captive->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ATIME) ? 0 : file_info_captive->atime);
+       file_info_corba->mtime=(!(file_info_captive->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MTIME) ? 0 : file_info_captive->mtime);
+       file_info_corba->ctime=(!(file_info_captive->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_CTIME) ? 0 : file_info_captive->ctime);
+       if ((file_info_corba->flags_valid=!!(file_info_captive->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_FLAGS)))
+               file_info_corba->flags=file_info_captive->flags;
+
+       return GNOME_VFS_OK;
+}
diff --git a/src/libcaptive/sandbox/FileInfo.h b/src/libcaptive/sandbox/FileInfo.h
new file mode 100644 (file)
index 0000000..c222c81
--- /dev/null
@@ -0,0 +1,39 @@
+/* $Id$
+ * Include file for CORBA/ORBit server side of GnomeVFSFileInfo handling
+ * 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 _SERVER_FILEINFO_H
+#define _SERVER_FILEINFO_H 1
+
+
+#include <glib/gmacros.h>
+#include "sandbox.h"
+#include <libgnomevfs/gnome-vfs-file-info.h>
+
+
+G_BEGIN_DECLS
+
+GnomeVFSResult captive_sandbox_file_info_corba_to_captive
+               (GnomeVFSFileInfo *file_info_captive,const Captive_GnomeVFSFileInfo *file_info_corba);
+GnomeVFSResult captive_sandbox_file_info_captive_to_corba
+               (Captive_GnomeVFSFileInfo *file_info_corba,const GnomeVFSFileInfo *file_info_captive);
+
+G_END_DECLS
+
+
+#endif /* _SERVER_FILEINFO_H */
index 42e5705..c72e532 100644 (file)
@@ -28,6 +28,11 @@ SANDBOX_IDL_SOURCES= \
 noinst_LTLIBRARIES=libsandbox.la
 libsandbox_la_SOURCES= \
                $(SANDBOX_IDL_SOURCES) \
+               FileInfo.c \
+               FileInfo.h \
+               parent-Directory.c \
+               parent-File.c \
+               parent-Vfs.c \
                split.c \
                split.h \
                server-GlibLogFunc.c \
diff --git a/src/libcaptive/sandbox/parent-Directory.c b/src/libcaptive/sandbox/parent-Directory.c
new file mode 100644 (file)
index 0000000..a21a9d6
--- /dev/null
@@ -0,0 +1,107 @@
+/* $Id$
+ * CORBA/ORBit server side of Directory object of sandbox_parent()
+ * 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 "captive/parent-Directory.h"  /* self */
+#include <glib/gmessages.h>
+#include "split.h"
+#include "sandbox.h"
+#include "../client/directory.h"
+#include "../client/vfs.h"
+#include "FileInfo.h"
+
+
+GnomeVFSResult captive_sandbox_parent_directory_new_open
+               (CaptiveDirectoryObject *captive_directory_object,const gchar *pathname)
+{
+       g_return_val_if_fail(captive_directory_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_directory_object->dir_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       captive_directory_object->corba_Directory_object=Captive_Vfs_directory_new_open(
+                       captive_directory_object->vfs->corba_Vfs_object,pathname,&captive_corba_ev);
+
+       return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+}
+
+
+GnomeVFSResult captive_sandbox_parent_directory_new_make
+               (CaptiveDirectoryObject *captive_directory_object,const gchar *pathname,guint perm)
+{
+       g_return_val_if_fail(captive_directory_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_directory_object->dir_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       captive_directory_object->corba_Directory_object=Captive_Vfs_directory_new_make(
+                       captive_directory_object->vfs->corba_Vfs_object,pathname,perm,&captive_corba_ev);
+
+       return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+}
+
+
+GnomeVFSResult captive_sandbox_parent_directory_close(CaptiveDirectoryObject *captive_directory_object)
+{
+       g_return_val_if_fail(captive_directory_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_directory_object->dir_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       CORBA_Object_release((CORBA_Object)captive_directory_object->corba_Directory_object,&captive_corba_ev);
+       captive_directory_object->corba_Directory_object=CORBA_OBJECT_NIL;
+
+       return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+}
+
+
+GnomeVFSResult captive_sandbox_parent_directory_read
+               (CaptiveDirectoryObject *captive_directory_object,GnomeVFSFileInfo *file_info_captive)
+{
+Captive_GnomeVFSFileInfo *file_info_corba;
+GnomeVFSResult r;
+
+       g_return_val_if_fail(captive_directory_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_directory_object->dir_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       Captive_Directory_read(captive_directory_object->corba_Directory_object,&file_info_corba,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       if (GNOME_VFS_OK!=(r=captive_sandbox_file_info_corba_to_captive(file_info_captive,file_info_corba)))
+               return r;       /* 'file_info_corba' leak */
+
+       Captive_GnomeVFSFileInfo__freekids(file_info_corba,NULL/* 'd'; meaning? */);
+       CORBA_free(file_info_corba);
+
+       return GNOME_VFS_OK;
+}
+
+
+GnomeVFSResult captive_sandbox_parent_directory_remove(CaptiveDirectoryObject *captive_directory_object)
+{
+GnomeVFSResult r;
+
+       g_return_val_if_fail(captive_directory_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_directory_object->dir_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       Captive_Directory_remove(captive_directory_object->corba_Directory_object,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       return GNOME_VFS_OK;
+}
diff --git a/src/libcaptive/sandbox/parent-File.c b/src/libcaptive/sandbox/parent-File.c
new file mode 100644 (file)
index 0000000..507467c
--- /dev/null
@@ -0,0 +1,254 @@
+/* $Id$
+ * CORBA/ORBit server side of File object of sandbox_parent()
+ * 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 "captive/parent-File.h"       /* self */
+#include <glib/gmessages.h>
+#include "split.h"
+#include "sandbox.h"
+#include "../client/file.h"
+#include "../client/vfs.h"
+#include "FileInfo.h"
+
+
+GnomeVFSResult captive_sandbox_parent_file_new_open(CaptiveFileObject *captive_file_object,
+               const gchar *pathname,GnomeVFSOpenMode mode)
+{
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       captive_file_object->corba_File_object=Captive_Vfs_file_new_open(
+                       captive_file_object->vfs->corba_Vfs_object,pathname,mode,&captive_corba_ev);
+
+       return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_new_create(CaptiveFileObject *captive_file_object,
+               const gchar *pathname,GnomeVFSOpenMode mode,gboolean exclusive,guint perm)
+{
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       captive_file_object->corba_File_object=Captive_Vfs_file_new_create(
+                       captive_file_object->vfs->corba_Vfs_object,pathname,mode,exclusive,perm,&captive_corba_ev);
+
+       return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_close(CaptiveFileObject *captive_file_object)
+{
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       CORBA_Object_release((CORBA_Object)captive_file_object->corba_File_object,&captive_corba_ev);
+       captive_file_object->corba_File_object=CORBA_OBJECT_NIL;
+
+       return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_read(CaptiveFileObject *captive_file_object,
+               gpointer buffer_captive,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_read_return)
+{
+GnomeVFSResult r;
+Captive_Bytes *buffer_corba;
+
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(buffer_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(bytes_read_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(num_bytes==(ULONG)num_bytes,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       *bytes_read_return=0;
+
+       Captive_File_read(captive_file_object->corba_File_object,&buffer_corba,num_bytes,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       g_return_val_if_fail(buffer_corba->_length<=num_bytes,GNOME_VFS_ERROR_GENERIC);
+       memcpy(buffer_captive,buffer_corba->_buffer,buffer_corba->_length);
+       *bytes_read_return=buffer_corba->_length;
+
+       Captive_Bytes__freekids(buffer_corba,NULL/* 'd'; meaning? */);
+       CORBA_free(buffer_corba);
+
+       return GNOME_VFS_OK;
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_write(CaptiveFileObject *captive_file_object,
+               gconstpointer buffer_captive,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_written_return)
+{
+GnomeVFSResult r;
+Captive_Bytes buffer_corba_local;
+Captive_GnomeVFSFileSize bytes_written_corba;
+
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(buffer_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(bytes_written_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(num_bytes==(ULONG)num_bytes,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       *bytes_written_return=0;
+
+       buffer_corba_local._maximum=num_bytes;
+       buffer_corba_local._length=num_bytes;
+       buffer_corba_local._buffer=(/* de-const */gpointer)buffer_captive;
+       buffer_corba_local._release=FALSE;
+
+       Captive_File_write(captive_file_object->corba_File_object,&buffer_corba_local,&bytes_written_corba,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       *bytes_written_return=bytes_written_corba;
+
+       return GNOME_VFS_OK;
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_seek
+               (CaptiveFileObject *captive_file_object,GnomeVFSSeekPosition whence,GnomeVFSFileOffset offset)
+{
+GnomeVFSResult r;
+
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       Captive_File_seek(captive_file_object->corba_File_object,whence,offset,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       return GNOME_VFS_OK;
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_tell(CaptiveFileObject *captive_file_object,GnomeVFSFileOffset *offset_return)
+{
+Captive_GnomeVFSFileOffset offset_corba;
+GnomeVFSResult r;
+
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(offset_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       Captive_File_tell(captive_file_object->corba_File_object,&offset_corba,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       *offset_return=offset_corba;
+
+       return GNOME_VFS_OK;
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_remove(CaptiveFileObject *captive_file_object)
+{
+GnomeVFSResult r;
+
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       Captive_File_remove(captive_file_object->corba_File_object,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       return GNOME_VFS_OK;
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_file_info_get(CaptiveFileObject *captive_file_object,
+               GnomeVFSFileInfo *file_info_captive)
+{
+Captive_GnomeVFSFileInfo *file_info_corba;
+GnomeVFSResult r;
+
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       Captive_File_file_info_get(captive_file_object->corba_File_object,&file_info_corba,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       r=captive_sandbox_file_info_corba_to_captive(file_info_captive,file_info_corba);
+       Captive_GnomeVFSFileInfo__freekids(file_info_corba,NULL/* 'd'; meaning? */);
+       CORBA_free(file_info_corba);
+       if (r!=GNOME_VFS_OK)
+               return r;
+
+       return GNOME_VFS_OK;
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_file_info_set(CaptiveFileObject *captive_file_object,
+    const GnomeVFSFileInfo *file_info_captive,GnomeVFSSetFileInfoMask mask)
+{
+Captive_GnomeVFSFileInfo file_info_corba;
+GnomeVFSResult r;
+
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       if (GNOME_VFS_OK!=(r=captive_sandbox_file_info_captive_to_corba(&file_info_corba,file_info_captive)))
+               return r;
+
+       Captive_File_file_info_set(captive_file_object->corba_File_object,&file_info_corba,mask,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       Captive_GnomeVFSFileInfo__freekids(&file_info_corba,NULL/* 'd'; meaning? */);
+
+       return GNOME_VFS_OK;
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_truncate(CaptiveFileObject *captive_file_object,GnomeVFSFileSize file_size)
+{
+GnomeVFSResult r;
+
+       g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       Captive_File_truncate(captive_file_object->corba_File_object,file_size,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       return GNOME_VFS_OK;
+}
+
+
+GnomeVFSResult captive_sandbox_parent_file_move
+               (CaptiveFileObject *captive_file_object_old,const gchar *pathname_new,gboolean force_replace)
+{
+GnomeVFSResult r;
+
+       g_return_val_if_fail(captive_file_object_old!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(pathname_new!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(captive_file_object_old->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       Captive_File_move(captive_file_object_old->corba_File_object,pathname_new,force_replace,&captive_corba_ev);
+       if (GNOME_VFS_OK!=(r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev)))
+               return r;
+
+       return GNOME_VFS_OK;
+}
diff --git a/src/libcaptive/sandbox/parent-Vfs.c b/src/libcaptive/sandbox/parent-Vfs.c
new file mode 100644 (file)
index 0000000..304a423
--- /dev/null
@@ -0,0 +1,72 @@
+/* $Id$
+ * CORBA/ORBit server side of Vfs object of sandbox_parent()
+ * 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 "captive/parent-Vfs.h"        /* self */
+#include <glib/gmessages.h>
+#include "split.h"
+#include "../client/vfs.h"
+#include "sandbox.h"
+#include <unistd.h>
+
+
+GnomeVFSResult captive_sandbox_parent_vfs_new(CaptiveVfsObject *captive_vfs_object)
+{
+gboolean errbool;
+
+       g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       captive_vfs_object->is_sandbox_parent=TRUE;
+
+       errbool=captive_sandbox_spawn(
+                       captive_vfs_object,     /* child_captive_vfs_object */
+                       &captive_vfs_object->corba_Vfs_object,  /* corba_Vfs_object_return */
+                       &captive_vfs_object->corba_GlibLogFunc_object,  /* corba_GlibLogFunc_object_return */
+                       &captive_vfs_object->corba_parentheart_fds_1);  /* parentheart_fds_1_return */
+       g_return_val_if_fail(errbool==TRUE,GNOME_VFS_ERROR_GENERIC);
+
+       return GNOME_VFS_OK;
+}
+
+
+gboolean corba_shutdown(CORBA_Environment *evp,CORBA_ORB *orbp,PortableServer_POA *poap);
+
+GnomeVFSResult captive_sandbox_parent_vfs_close(CaptiveVfsObject *captive_vfs_object)
+{
+GnomeVFSResult r;
+int errint;
+
+       g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       Captive_Vfs_shutdown(captive_vfs_object->corba_Vfs_object,&captive_corba_ev);
+       r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+
+       CORBA_Object_release(captive_vfs_object->corba_Vfs_object,&captive_corba_ev);
+       g_assert(validate_CORBA_Environment(&captive_corba_ev));
+
+       /* Shutdown 'GlibLogFunc' servant */
+       CORBA_Object_release(captive_vfs_object->corba_GlibLogFunc_object,&captive_corba_ev);
+       g_assert(validate_CORBA_Environment(&captive_corba_ev));
+
+       errint=close(captive_vfs_object->corba_parentheart_fds_1);      /* close parentheart_fd_write */
+       g_return_val_if_fail(errint==0,FALSE);
+
+       return r;
+}
index e57dfed..b6dafcb 100644 (file)
@@ -73,7 +73,7 @@ module Captive
 
 
        interface Directory {
-               GnomeVFSFileInfo read()
+               void read(out GnomeVFSFileInfo file_info)
                        raises (GnomeVFSResultException,GlibLogMessageFatal);
                void remove()
                        raises (GnomeVFSResultException,GlibLogMessageFatal);
@@ -81,7 +81,7 @@ module Captive
 
 
        interface File {
-               void read(out Bytes buffer,in GnomeVFSFileSize num_bytes,out GnomeVFSFileSize bytes_read_return)
+               void read(out Bytes buffer,in GnomeVFSFileSize num_bytes)
                        raises (GnomeVFSResultException,GlibLogMessageFatal);
                void write(in Bytes buffer,out GnomeVFSFileSize bytes_written_return)
                        raises (GnomeVFSResultException,GlibLogMessageFatal);
@@ -104,6 +104,7 @@ module Captive
 
        interface Vfs {
                void registerGlibLogFunc(in GlibLogFunc glib_log_func);
+               void shutdown();
                Directory directory_new_open(in string pathname)
                        raises (GnomeVFSResultException,GlibLogMessageFatal);
                Directory directory_new_make(in string pathname,in GnomeVFSFilePermissions perm)
index f863540..75f9ff6 100644 (file)
 #include "sandbox.h"
 #include <glib/gmessages.h>
 #include "captive/macros.h"
+#include "../client/directory.h"
+#include "FileInfo.h"
+#include "split.h"
 
 
-typedef struct {
-       POA_Captive_Directory servant;
-       PortableServer_POA poa;
-       } impl_POA_Captive_Directory;
+static void impl_Captive_Directory_fini(impl_POA_Captive_Directory *servant,CORBA_Environment *ev);
+static void impl_Captive_Directory_read
+               (impl_POA_Captive_Directory *servant,Captive_GnomeVFSFileInfo **file_info,CORBA_Environment *ev);
+static void impl_Captive_Directory_remove(impl_POA_Captive_Directory *servant,CORBA_Environment *ev);
 
-static Captive_GnomeVFSFileInfo *impl_Captive_Directory_read
-               (impl_POA_Captive_Directory *servant,CORBA_Environment *ev);
 
 static PortableServer_ServantBase__epv impl_Captive_Directory_base_epv={
        NULL,   /* _private data */
-       NULL,   /* finalize routine */
+       (gpointer)&impl_Captive_Directory_fini, /* finalize routine */
        NULL,   /* default_POA routine */
        };
 static POA_Captive_Directory__epv impl_Captive_Directory_epv={
        NULL,   /* _private */
        (gpointer)&impl_Captive_Directory_read,
+       (gpointer)&impl_Captive_Directory_remove,
        };
 static POA_Captive_Directory__vepv impl_Captive_Directory_vepv={
        &impl_Captive_Directory_base_epv,
@@ -57,6 +59,7 @@ PortableServer_ObjectId *objid;
        captive_new0(newservant);       /* FIXME: leak */
        newservant->servant.vepv=&impl_Captive_Directory_vepv;
        newservant->poa=poa;
+       newservant->captive_directory_object=NULL;
        POA_Captive_Directory__init((PortableServer_Servant)newservant,ev);
        objid=PortableServer_POA_activate_object(poa,newservant,ev);
        CORBA_free(objid);
@@ -66,21 +69,111 @@ PortableServer_ObjectId *objid;
 }
 
 
-static Captive_GnomeVFSFileInfo *impl_Captive_Directory_read
-               (impl_POA_Captive_Directory *servant,CORBA_Environment *ev)
+static void impl_Captive_Directory_fini(impl_POA_Captive_Directory *servant,CORBA_Environment *ev)
 {
-Captive_GnomeVFSFileInfo *retval;
-
-       retval=Captive_GnomeVFSFileInfo__alloc();
-/*
-               CORBA_string name;
-               Captive_Directory_GnomeVFSFileType type;
-               Captive_Directory_GnomeVFSFilePermissions permissions;
-               Captive_Directory_GnomeVFSFileSize size;
-               Captive_Directory_GnomeVFSFileSize block_count;
-               Captive_Directory_time_t atime;
-               Captive_Directory_time_t mtime;
-               Captive_Directory_time_t ctime;
-*/
+       if (servant->captive_directory_object) {
+               g_object_unref(servant->captive_directory_object);
+               servant->captive_directory_object=NULL;
+               }
+}
+
+
+static void impl_Captive_Directory__destroy(impl_POA_Captive_Directory *servant,CORBA_Environment *ev)
+{
+PortableServer_ObjectId *objid;
+
+       objid=PortableServer_POA_servant_to_id(servant->poa,servant,ev);
+       PortableServer_POA_deactivate_object(servant->poa,objid,ev);
+       CORBA_free(objid);
+       impl_Captive_Directory_fini(servant,ev);
+       g_free(servant);
+}
+
+
+Captive_Directory impl_Captive_Vfs_directory_new_open
+               (impl_POA_Captive_Vfs *servant,const CORBA_char *pathname,CORBA_Environment *ev)
+{
+Captive_Directory retval;
+impl_POA_Captive_Directory *retval_servant;
+GnomeVFSResult errvfsresult;
+
+       retval=impl_Captive_Directory__create(servant->poa,ev);
+       if (ev->_major!=CORBA_NO_EXCEPTION)
+               return NULL;
+
+       retval_servant=PortableServer_POA_reference_to_servant(servant->poa,retval,ev);
+       if (ev->_major!=CORBA_NO_EXCEPTION)
+               return NULL;    /* 'retval' leak */
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_directory_new_open(&retval_servant->captive_directory_object,
+                       servant->captive_vfs_object,pathname))) {
+               impl_Captive_Directory__destroy(retval_servant,ev);
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return NULL;
+               }
+
        return retval;
 }
+
+
+Captive_Directory impl_Captive_Vfs_directory_new_make(impl_POA_Captive_Vfs *servant,
+               const CORBA_char *pathname,const Captive_GnomeVFSFilePermissions perm,CORBA_Environment *ev)
+{
+Captive_Directory retval;
+impl_POA_Captive_Directory *retval_servant;
+GnomeVFSResult errvfsresult;
+
+       retval=impl_Captive_Directory__create(servant->poa,ev);
+       if (ev->_major!=CORBA_NO_EXCEPTION)
+               return NULL;
+
+       retval_servant=PortableServer_POA_reference_to_servant(servant->poa,retval,ev);
+       if (ev->_major!=CORBA_NO_EXCEPTION)
+               return NULL;    /* 'retval' leak */
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_directory_new_make(&retval_servant->captive_directory_object,
+                       servant->captive_vfs_object,pathname,perm))) {
+               impl_Captive_Directory__destroy(retval_servant,ev);
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return NULL;
+               }
+
+       return retval;
+}
+
+
+static void impl_Captive_Directory_read
+               (impl_POA_Captive_Directory *servant,Captive_GnomeVFSFileInfo **file_info_corba_return,CORBA_Environment *ev)
+{
+GnomeVFSFileInfo file_info_captive;
+Captive_GnomeVFSFileInfo *file_info_corba;
+GnomeVFSResult errvfsresult;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_directory_read(servant->captive_directory_object,&file_info_captive))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+
+       file_info_corba=Captive_GnomeVFSFileInfo__alloc();
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_sandbox_file_info_captive_to_corba(
+                       file_info_corba,&file_info_captive))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               Captive_GnomeVFSFileInfo__freekids(file_info_corba,NULL/* 'd'; meaning? */);
+               CORBA_free(file_info_corba);
+               return;
+               }
+
+       *file_info_corba_return=file_info_corba;
+}
+
+
+static void impl_Captive_Directory_remove(impl_POA_Captive_Directory *servant,CORBA_Environment *ev)
+{
+GnomeVFSResult errvfsresult;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_directory_remove(servant->captive_directory_object))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+}
index e5fe465..462e312 100644 (file)
 
 #include <glib/gmacros.h>
 #include "sandbox.h"
+#include "captive/client-directory.h"
+#include "server-Vfs.h"
 
 
 G_BEGIN_DECLS
 
+typedef struct {
+       POA_Captive_Directory servant;
+       PortableServer_POA poa;
+       CaptiveDirectoryObject *captive_directory_object;
+       } impl_POA_Captive_Directory;
+
+
 Captive_Directory impl_Captive_Directory__create(PortableServer_POA poa,CORBA_Environment *ev);
+Captive_Directory impl_Captive_Vfs_directory_new_open
+               (impl_POA_Captive_Vfs *servant,const CORBA_char *pathname,CORBA_Environment *ev);
+Captive_Directory impl_Captive_Vfs_directory_new_make(impl_POA_Captive_Vfs *servant,
+               const CORBA_char *pathname,const Captive_GnomeVFSFilePermissions perm,CORBA_Environment *ev);
 
 G_END_DECLS
 
index 056ac74..b897855 100644 (file)
 #include "sandbox.h"
 #include <glib/gmessages.h>
 #include "captive/macros.h"
+#include "split.h"
+#include "FileInfo.h"
 
 
-typedef struct {
-       POA_Captive_File servant;
-       PortableServer_POA poa;
-       } impl_POA_Captive_File;
+static void impl_Captive_File_fini(impl_POA_Captive_File *servant,CORBA_Environment *ev);
+static void impl_Captive_File_read(impl_POA_Captive_File *servant,Captive_Bytes **buffer,
+               const Captive_GnomeVFSFileSize num_bytes,CORBA_Environment *ev);
+static void impl_Captive_File_write(impl_POA_Captive_File *servant,
+               const Captive_Bytes *buffer,Captive_GnomeVFSFileSize *bytes_written_return,CORBA_Environment *ev);
+static void impl_Captive_File_seek(impl_POA_Captive_File *servant,
+               const Captive_GnomeVFSSeekPosition whence,const Captive_GnomeVFSFileOffset offset,CORBA_Environment *ev);
+static void impl_Captive_File_tell
+               (impl_POA_Captive_File *servant,Captive_GnomeVFSFileOffset *offset_return,CORBA_Environment *ev);
+static void impl_Captive_File_remove(impl_POA_Captive_File *servant,CORBA_Environment *ev);
+static void impl_Captive_File_file_info_get
+               (impl_POA_Captive_File *servant,Captive_GnomeVFSFileInfo **file_info,CORBA_Environment *ev);
+static void impl_Captive_File_file_info_set(impl_POA_Captive_File *servant,
+               const Captive_GnomeVFSFileInfo *file_info,const Captive_GnomeVFSSetFileInfoMask mask,CORBA_Environment *ev);
+static void impl_Captive_File_truncate
+               (impl_POA_Captive_File *servant,const Captive_GnomeVFSFileSize file_size,CORBA_Environment *ev);
+static void impl_Captive_File_move
+               (impl_POA_Captive_File *servant,const CORBA_char *pathname_new,const CORBA_boolean force_replace,CORBA_Environment *ev);
 
-static Captive_GnomeVFSFileInfo *impl_Captive_File_read
-               (impl_POA_Captive_File *servant,CORBA_Environment *ev);
 
 static PortableServer_ServantBase__epv impl_Captive_File_base_epv={
        NULL,   /* _private data */
-       NULL,   /* finalize routine */
+       (gpointer)&impl_Captive_File_fini,      /* finalize routine */
        NULL,   /* default_POA routine */
        };
 static POA_Captive_File__epv impl_Captive_File_epv={
        NULL,   /* _private */
        (gpointer)&impl_Captive_File_read,
+       (gpointer)&impl_Captive_File_write,
+       (gpointer)&impl_Captive_File_seek,
+       (gpointer)&impl_Captive_File_tell,
+       (gpointer)&impl_Captive_File_remove,
+       (gpointer)&impl_Captive_File_file_info_get,
+       (gpointer)&impl_Captive_File_file_info_set,
+       (gpointer)&impl_Captive_File_truncate,
+       (gpointer)&impl_Captive_File_move,
        };
 static POA_Captive_File__vepv impl_Captive_File_vepv={
        &impl_Captive_File_base_epv,
@@ -57,6 +79,7 @@ PortableServer_ObjectId *objid;
        captive_new0(newservant);       /* FIXME: leak */
        newservant->servant.vepv=&impl_Captive_File_vepv;
        newservant->poa=poa;
+       newservant->captive_file_object=NULL;
        POA_Captive_File__init((PortableServer_Servant)newservant,ev);
        objid=PortableServer_POA_activate_object(poa,newservant,ev);
        CORBA_free(objid);
@@ -66,21 +89,223 @@ PortableServer_ObjectId *objid;
 }
 
 
-static Captive_GnomeVFSFileInfo *impl_Captive_File_read
-               (impl_POA_Captive_File *servant,CORBA_Environment *ev)
+static void impl_Captive_File_fini(impl_POA_Captive_File *servant,CORBA_Environment *ev)
 {
-Captive_GnomeVFSFileInfo *retval;
-
-       retval=Captive_GnomeVFSFileInfo__alloc();
-/*
-               CORBA_string name;
-               Captive_File_GnomeVFSFileType type;
-               Captive_File_GnomeVFSFilePermissions permissions;
-               Captive_File_GnomeVFSFileSize size;
-               Captive_File_GnomeVFSFileSize block_count;
-               Captive_File_time_t atime;
-               Captive_File_time_t mtime;
-               Captive_File_time_t ctime;
-*/
+       if (servant->captive_file_object) {
+               g_object_unref(servant->captive_file_object);
+               servant->captive_file_object=NULL;
+               }
+}
+
+
+static void impl_Captive_File__destroy(impl_POA_Captive_File *servant,CORBA_Environment *ev)
+{
+PortableServer_ObjectId *objid;
+
+       objid=PortableServer_POA_servant_to_id(servant->poa,servant,ev);
+       PortableServer_POA_deactivate_object(servant->poa,objid,ev);
+       CORBA_free(objid);
+       impl_Captive_File_fini(servant,ev);
+       g_free(servant);
+}
+
+
+Captive_File impl_Captive_Vfs_file_new_open
+               (impl_POA_Captive_Vfs *servant,const CORBA_char *pathname,const Captive_GnomeVFSOpenMode mode,CORBA_Environment *ev)
+{
+Captive_File retval;
+impl_POA_Captive_File *retval_servant;
+GnomeVFSResult errvfsresult;
+
+       retval=impl_Captive_File__create(servant->poa,ev);
+       if (ev->_major!=CORBA_NO_EXCEPTION)
+               return NULL;
+
+       retval_servant=PortableServer_POA_reference_to_servant(servant->poa,retval,ev);
+       if (ev->_major!=CORBA_NO_EXCEPTION)
+               return NULL;    /* 'retval' leak */
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_new_open(&retval_servant->captive_file_object,
+                       servant->captive_vfs_object,pathname,mode))) {
+               impl_Captive_File__destroy(retval_servant,ev);
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return NULL;
+               }
+
        return retval;
 }
+
+
+Captive_File impl_Captive_Vfs_file_new_create(impl_POA_Captive_Vfs *servant,const CORBA_char *pathname,
+               const Captive_GnomeVFSOpenMode mode,const CORBA_boolean exclusive,const CORBA_unsigned_long perm,CORBA_Environment *ev)
+{
+Captive_File retval;
+impl_POA_Captive_File *retval_servant;
+GnomeVFSResult errvfsresult;
+
+       retval=impl_Captive_File__create(servant->poa,ev);
+       if (ev->_major!=CORBA_NO_EXCEPTION)
+               return NULL;
+
+       retval_servant=PortableServer_POA_reference_to_servant(servant->poa,retval,ev);
+       if (ev->_major!=CORBA_NO_EXCEPTION)
+               return NULL;    /* 'retval' leak */
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_new_create(&retval_servant->captive_file_object,
+                       servant->captive_vfs_object,pathname,mode,exclusive,perm))) {
+               impl_Captive_File__destroy(retval_servant,ev);
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return NULL;
+               }
+
+       return retval;
+}
+
+
+static void impl_Captive_File_read(impl_POA_Captive_File *servant,Captive_Bytes **buffer_corba_return,
+               const Captive_GnomeVFSFileSize num_bytes,CORBA_Environment *ev)
+{
+Captive_Bytes *buffer_corba;
+GnomeVFSFileSize bytes_read;
+GnomeVFSResult errvfsresult;
+
+       buffer_corba=Captive_Bytes__alloc();
+       buffer_corba->_maximum=num_bytes;
+       buffer_corba->_length=0;
+       buffer_corba->_buffer=Captive_Bytes_allocbuf(buffer_corba->_maximum);
+       buffer_corba->_release=TRUE;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_read(servant->captive_file_object,
+                       buffer_corba->_buffer,num_bytes,&bytes_read))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               Captive_Bytes__freekids(buffer_corba,NULL/* 'd'; meaning? */);
+               CORBA_free(buffer_corba);
+               return;
+               }
+
+       buffer_corba->_length=bytes_read;
+       *buffer_corba_return=buffer_corba;
+}
+
+
+static void impl_Captive_File_write(impl_POA_Captive_File *servant,
+               const Captive_Bytes *buffer_corba,Captive_GnomeVFSFileSize *bytes_written_return,CORBA_Environment *ev)
+{
+GnomeVFSFileSize bytes_written;
+GnomeVFSResult errvfsresult;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_write(servant->captive_file_object,
+                       buffer_corba->_buffer,buffer_corba->_length,&bytes_written))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+
+       *bytes_written_return=bytes_written;
+}
+
+
+static void impl_Captive_File_seek(impl_POA_Captive_File *servant,
+               const Captive_GnomeVFSSeekPosition whence,const Captive_GnomeVFSFileOffset offset,CORBA_Environment *ev)
+{
+GnomeVFSResult errvfsresult;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_seek(servant->captive_file_object,whence,offset))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+}
+
+
+static void impl_Captive_File_tell
+               (impl_POA_Captive_File *servant,Captive_GnomeVFSFileOffset *offset_return,CORBA_Environment *ev)
+{
+GnomeVFSFileOffset offset_captive;
+GnomeVFSResult errvfsresult;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_tell(servant->captive_file_object,&offset_captive))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+       
+       *offset_return=offset_captive;
+}
+
+
+static void impl_Captive_File_remove(impl_POA_Captive_File *servant,CORBA_Environment *ev)
+{
+GnomeVFSResult errvfsresult;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_remove(servant->captive_file_object))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+}
+
+
+static void impl_Captive_File_file_info_get
+               (impl_POA_Captive_File *servant,Captive_GnomeVFSFileInfo **file_info_corba_return,CORBA_Environment *ev)
+{
+GnomeVFSFileInfo file_info_captive;
+GnomeVFSResult errvfsresult;
+Captive_GnomeVFSFileInfo *file_info_corba;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_file_info_get(servant->captive_file_object,&file_info_captive))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+
+       file_info_corba=Captive_GnomeVFSFileInfo__alloc();
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_sandbox_file_info_captive_to_corba(
+                       file_info_corba,&file_info_captive))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               Captive_GnomeVFSFileInfo__freekids(file_info_corba,NULL/* 'd'; meaning? */);
+               CORBA_free(file_info_corba);
+               return;
+               }
+
+       *file_info_corba_return=file_info_corba;
+}
+
+
+static void impl_Captive_File_file_info_set(impl_POA_Captive_File *servant,
+               const Captive_GnomeVFSFileInfo *file_info_corba,const Captive_GnomeVFSSetFileInfoMask mask,CORBA_Environment *ev)
+{
+GnomeVFSFileInfo file_info_captive;
+GnomeVFSResult errvfsresult;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_sandbox_file_info_corba_to_captive(
+                       &file_info_captive,file_info_corba))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_file_info_set(servant->captive_file_object,&file_info_captive,mask))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+}
+
+
+static void impl_Captive_File_truncate
+               (impl_POA_Captive_File *servant,const Captive_GnomeVFSFileSize file_size,CORBA_Environment *ev)
+{
+GnomeVFSResult errvfsresult;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_truncate(servant->captive_file_object,file_size))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+}
+
+
+static void impl_Captive_File_move
+               (impl_POA_Captive_File *servant,const CORBA_char *pathname_new,const CORBA_boolean force_replace,CORBA_Environment *ev)
+{
+GnomeVFSResult errvfsresult;
+
+       if (GNOME_VFS_OK!=(errvfsresult=captive_file_move(servant->captive_file_object,pathname_new,force_replace))) {
+               captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
+               return;
+               }
+}
index 4be50af..c96a7e5 100644 (file)
  */
 
 
-#ifndef _SERVER_DIRECTORY_H
-#define _SERVER_DIRECTORY_H 1
+#ifndef _SERVER_FILE_H
+#define _SERVER_FILE_H 1
 
 
 #include <glib/gmacros.h>
 #include "sandbox.h"
+#include "captive/client-file.h"
+#include "server-Vfs.h"
 
 
 G_BEGIN_DECLS
 
+typedef struct {
+       POA_Captive_File servant;
+       PortableServer_POA poa;
+       CaptiveFileObject *captive_file_object;
+       } impl_POA_Captive_File;
+
+
 Captive_File impl_Captive_File__create(PortableServer_POA poa,CORBA_Environment *ev);
+Captive_File impl_Captive_Vfs_file_new_open
+               (impl_POA_Captive_Vfs *servant,const CORBA_char *pathname,const Captive_GnomeVFSOpenMode mode,CORBA_Environment *ev);
+Captive_File impl_Captive_Vfs_file_new_create(impl_POA_Captive_Vfs *servant,const CORBA_char *pathname,
+               const Captive_GnomeVFSOpenMode mode,const CORBA_boolean exclusive,const CORBA_unsigned_long perm,CORBA_Environment *ev);
 
 G_END_DECLS
 
 
-#endif /* _SERVER_DIRECTORY_H */
+#endif /* _SERVER_FILE_H */
index dd68980..cc2dca3 100644 (file)
@@ -70,7 +70,21 @@ PortableServer_ObjectId *objid;
 static void impl_Captive_GlibLogFunc_glibLogFunc
                (impl_POA_Captive_GlibLogFunc *servant,const Captive_GlibLogMessage *glib_log_message,CORBA_Environment *ev)
 {
-       g_log(G_LOG_DOMAIN,glib_log_message->log_level,"%s",glib_log_message->message);
+GLogLevelFlags log_level_use;
+gboolean fatal;
+
+       log_level_use=glib_log_message->log_level;
+       /* Downgrade always-fatal 'ERROR' to 'CRITICAL' level */
+       if (log_level_use&G_LOG_LEVEL_ERROR) {
+               log_level_use=(log_level_use|G_LOG_LEVEL_CRITICAL)&~G_LOG_LEVEL_ERROR;
+               fatal=TRUE;
+               }
+       if (log_level_use&G_LOG_FLAG_FATAL) {
+               log_level_use&=~G_LOG_FLAG_FATAL;
+               fatal=TRUE;
+               }
+
+       g_log(G_LOG_DOMAIN,log_level_use,"%s%s",(!fatal ? "" : "FATAL: "),glib_log_message->message);
 }
 
 
@@ -80,28 +94,61 @@ static void impl_Captive_Vfs_registerGlibLogFunc_log_func
 CORBA_Environment ev;
 Captive_GlibLogMessage glib_log_message;
 
-       /* Init 'ev' */
        CORBA_exception_init(&ev);
-
        glib_log_message.log_level=log_level;
        glib_log_message.message=(CORBA_string)message;
        Captive_GlibLogFunc_glibLogFunc(obj,&glib_log_message,&ev);
        g_assert(validate_CORBA_Environment(&ev));
-
-       /* Shutdown 'ev' */
        CORBA_exception_free(&ev);
 }
 
 
+static gboolean impl_Captive_Vfs_registerGlibLogFunc_handled=FALSE;
+static guint impl_Captive_Vfs_registerGlibLogFunc_handler_id;
+static Captive_GlibLogFunc glib_log_func_copy;
+
+
 void impl_Captive_Vfs_registerGlibLogFunc
                (impl_POA_Captive_Vfs *servant,const Captive_GlibLogFunc glib_log_func,CORBA_Environment *ev)
 {
-       g_log_set_handler(
+       g_assert(impl_Captive_Vfs_registerGlibLogFunc_handled==FALSE);
+
+       glib_log_func_copy=CORBA_Object_duplicate(glib_log_func,ev);
+       if (ev->_major!=CORBA_NO_EXCEPTION)
+               return;
+
+       impl_Captive_Vfs_registerGlibLogFunc_handler_id=g_log_set_handler(
                        G_LOG_DOMAIN,   /* log_domain; "Captive" */
                        0       /* log_levels */
-                                       | 0 /* !G_LOG_FLAG_RECURSION */
+                                       | 0     /* !G_LOG_FLAG_RECURSION */
                                        | G_LOG_FLAG_FATAL
-                                       | G_LOG_LEVEL_MASK,
+                                       | (G_LOG_LEVEL_MASK & ~(captive_options->debug_messages ? 0 : 0
+                                                       /* The same mask is in libcaptive/client/init.c ! */
+                                                       | G_LOG_LEVEL_MESSAGE
+                                                       | G_LOG_LEVEL_INFO
+                                                       | G_LOG_LEVEL_DEBUG)),
                        (GLogFunc)impl_Captive_Vfs_registerGlibLogFunc_log_func,        /* log_func */
-                       (gpointer)glib_log_func);       /* user_data */
+                       (gpointer)glib_log_func_copy);  /* user_data */
+
+       impl_Captive_Vfs_registerGlibLogFunc_handled=TRUE;
+}
+
+
+/* Called during child shutdown where our CORBA peer is no longer responding. */
+void impl_Captive_Vfs_registerGlibLogFunc_disable(void)
+{
+CORBA_Environment ev;
+
+       if (!impl_Captive_Vfs_registerGlibLogFunc_handled)
+               return;
+
+       g_log_remove_handler(
+                       G_LOG_DOMAIN,   /* log_domain; "Captive" */
+                       impl_Captive_Vfs_registerGlibLogFunc_handler_id);       /* handler_id */
+       CORBA_exception_init(&ev);
+       CORBA_Object_release(glib_log_func_copy,&ev);
+       g_assert(validate_CORBA_Environment(&ev));
+       CORBA_exception_free(&ev);
+
+       impl_Captive_Vfs_registerGlibLogFunc_handled=FALSE;
 }
index 90dd962..1ecbf82 100644 (file)
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 void impl_Captive_Vfs_registerGlibLogFunc
                (impl_POA_Captive_Vfs *servant,const Captive_GlibLogFunc glib_log_func,CORBA_Environment *ev);
 Captive_GlibLogFunc impl_Captive_GlibLogFunc__create(PortableServer_POA poa,CORBA_Environment *ev);
+void impl_Captive_Vfs_registerGlibLogFunc_disable(void);
 
 G_END_DECLS
 
diff --git a/src/libcaptive/sandbox/server-Vfs.c b/src/libcaptive/sandbox/server-Vfs.c
new file mode 100644 (file)
index 0000000..621a5a3
--- /dev/null
@@ -0,0 +1,98 @@
+/* $Id$
+ * CORBA/ORBit server side of Vfs object, ran by sandbox_child()
+ * 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 "server-Vfs.h"        /* self */
+#include "server-GlibLogFunc.h"        /* for impl_Captive_Vfs_registerGlibLogFunc() */
+#include "sandbox.h"
+#include <glib/gmessages.h>
+#include "captive/macros.h"
+#include "server-Directory.h"
+#include "server-File.h"
+#include "split.h"
+
+
+static void impl_Captive_Vfs_shutdown(impl_POA_Captive_Vfs *servant,CORBA_Environment *ev);
+
+static PortableServer_ServantBase__epv impl_Captive_Vfs_base_epv={
+       NULL,   /* _private data */
+       NULL,   /* finalize routine */
+       NULL,   /* default_POA routine */
+       };
+static POA_Captive_Vfs__epv impl_Captive_Vfs_epv={
+       NULL,   /* _private */
+       (gpointer)&impl_Captive_Vfs_registerGlibLogFunc,
+       (gpointer)&impl_Captive_Vfs_shutdown,
+       (gpointer)&impl_Captive_Vfs_directory_new_open,
+       (gpointer)&impl_Captive_Vfs_directory_new_make,
+       (gpointer)&impl_Captive_Vfs_file_new_open,
+       (gpointer)&impl_Captive_Vfs_file_new_create,
+       };
+static POA_Captive_Vfs__vepv impl_Captive_Vfs_vepv={
+       &impl_Captive_Vfs_base_epv,
+       &impl_Captive_Vfs_epv,
+       };
+
+
+struct captive_options *captive_corba_child_options;
+
+
+Captive_Vfs impl_Captive_Vfs__create(PortableServer_POA poa,CORBA_Environment *ev)
+{
+Captive_Vfs retval;
+impl_POA_Captive_Vfs *newservant;
+PortableServer_ObjectId *objid;
+GnomeVFSResult errvfsresult;
+
+       captive_new0(newservant);       /* FIXME: leak */
+       newservant->servant.vepv=&impl_Captive_Vfs_vepv;
+       newservant->poa=poa;
+       if (GNOME_VFS_OK!=(errvfsresult=captive_vfs_new(&newservant->captive_vfs_object,captive_corba_child_options))) {
+               g_free(newservant);
+               CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Captive_GnomeVFSResultException,GINT_TO_POINTER((gint)errvfsresult));
+               return NULL;
+               }
+       POA_Captive_Vfs__init((PortableServer_Servant)newservant,ev);
+       objid=PortableServer_POA_activate_object(poa,newservant,ev);
+       CORBA_free(objid);
+       retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
+
+       return retval;
+}
+
+
+static gboolean impl_Captive_Vfs_shutdown_idle(gpointer data /* unused */)
+{
+       sandbox_child_shutdown();
+
+       return FALSE;   /* remove me */
+}
+
+static void impl_Captive_Vfs_shutdown(impl_POA_Captive_Vfs *servant,CORBA_Environment *ev)
+{
+       /* Do not call sandbox_child_shutdown() directly as we would fail
+        * to finish this CORBA method call properly.
+        */
+       g_idle_add_full(
+                       G_PRIORITY_LOW, /* priority */
+                       impl_Captive_Vfs_shutdown_idle, /* function */
+                       NULL,   /* data */
+                       NULL);  /* notify */
+}
similarity index 57%
rename from src/libcaptive/include/captive/sandbox.h
rename to src/libcaptive/sandbox/server-Vfs.h
index 18cb09d..4585acd 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$
- * Include file for reactos sandboxing of libcaptive
- * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
+ * Include file for CORBA/ORBit server side of Vfs object
+ * 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
  */
 
 
-#ifndef _CAPTIVE_SANDBOX_H
-#define _CAPTIVE_SANDBOX_H 1
+#ifndef _SERVER_VFS_H
+#define _SERVER_VFS_H 1
 
 
-#include <glib/gtypes.h>
+#include <glib/gmacros.h>
+#include "sandbox.h"
+#include "captive/client-vfs.h"
 
 
 G_BEGIN_DECLS
 
-/* TODO: Not yet finished */
-#define CAPTIVE_IS_SANDBOX_PARENT() (FALSE)
+typedef struct {
+       POA_Captive_Vfs servant;
+       PortableServer_POA poa;
+       CaptiveVfsObject *captive_vfs_object;
+       } impl_POA_Captive_Vfs;
+
+
+extern struct captive_options *captive_corba_child_options;
+
+
+Captive_Vfs impl_Captive_Vfs__create(PortableServer_POA poa,CORBA_Environment *ev);
 
 G_END_DECLS
 
 
-#endif /* _CAPTIVE_SANDBOX_H */
+#endif /* _SERVER_VFS_H */
index 021d03f..29186fe 100644 (file)
@@ -32,6 +32,7 @@
 #include "server-GlibLogFunc.h"
 #include "server-Directory.h"
 #include "server-Vfs.h"
+#include "../client/vfs.h"
 
 
 /* CONFIG: */
@@ -47,9 +48,15 @@ gboolean validate_CORBA_Environment(const CORBA_Environment *evp)
        return TRUE;
 }
 
+CORBA_Environment captive_corba_ev;
+CORBA_ORB captive_corba_orb;
+PortableServer_POA captive_corba_poa;
+
+static void corba_shutdown_atexit(void);
 
 static gboolean corba_init(const char *pname,CORBA_Environment *evp,CORBA_ORB *orbp,PortableServer_POA *poap)
 {
+static gboolean done=FALSE;
 int orb_argc=1;
 gchar *orb_argv[]={
                (gchar *)captive_strdup_alloca(pname),
@@ -59,6 +66,9 @@ gchar *orb_argv[]={
        g_return_val_if_fail(orbp!=NULL,FALSE);
        g_return_val_if_fail(poap!=NULL,FALSE);
 
+       if (done)
+               return TRUE;
+
        /* Init 'ev' */
        CORBA_exception_init(evp);
 
@@ -80,13 +90,16 @@ PortableServer_POAManager poa_mgr;
                g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
                }
 
+       g_atexit(corba_shutdown_atexit);
+
+       done=TRUE;
        return TRUE;
 }
 
 
 static CORBA_ORB heartbeat_source_callback_orb=CORBA_OBJECT_NIL;
 
-static gboolean corba_shutdown(CORBA_Environment *evp,CORBA_ORB *orbp,PortableServer_POA *poap)
+gboolean corba_shutdown(CORBA_Environment *evp,CORBA_ORB *orbp,PortableServer_POA *poap)
 {
 PortableServer_POA poa;
 CORBA_ORB orb;
@@ -114,63 +127,53 @@ CORBA_ORB orb;
        return TRUE;
 }
 
-
-static gboolean corba_servant_object_destroy(PortableServer_POA poa,CORBA_Object reference,CORBA_Environment *evp)
+static void corba_shutdown_atexit(void)
 {
-PortableServer_ObjectId *objid;
-PortableServer_Servant servant;
+gboolean errbool;
 
-       g_return_val_if_fail(poa!=CORBA_OBJECT_NIL,FALSE);
-       g_return_val_if_fail(reference!=CORBA_OBJECT_NIL,FALSE);
-       g_return_val_if_fail(evp!=NULL,FALSE);
+       errbool=corba_shutdown(&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
+       g_assert(errbool==TRUE);
+}
 
-       objid=PortableServer_POA_reference_to_id(poa,reference,evp);
-       g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
-       servant=PortableServer_POA_reference_to_servant(poa,reference,evp);
-       g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
-       PortableServer_POA_deactivate_object(poa,objid,evp);
-       g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
-       CORBA_free(objid);
-       (*((PortableServer_ServantBase *)servant)->vepv[0]->finalize)(servant,evp);
-       g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
-       g_free(servant);
 
-       return TRUE;
+void sandbox_child_shutdown(void)
+{
+       /* Do not fail by passing logging messages to the master. */
+       impl_Captive_Vfs_registerGlibLogFunc_disable();
+
+       g_main_loop_quit(linc_main_get_loop());
 }
 
 
 static gboolean heartbeat_source_callback(gpointer data /* unused */)
 {
-CORBA_Environment ev;
-
        g_return_val_if_fail(heartbeat_source_callback_orb!=CORBA_OBJECT_NIL,FALSE);    /* the source should be removed */
 
-       CORBA_exception_init(&ev);
-       /* CORBA_ORB_shutdown() is not enough as 'init_level' still >0 */
-       CORBA_ORB_destroy(
-                       heartbeat_source_callback_orb,  /* orb */
-                       &ev);   /* ev */
-       g_assert(validate_CORBA_Environment(&ev));
-       CORBA_exception_free(&ev);
+       sandbox_child_shutdown();
 
        return FALSE;   /* the source should be removed */
 }
 
 
-static void sandbox_child(int Vfs_IOR_fd_write,GSource *gsource) G_GNUC_NORETURN;
-static void sandbox_child(int Vfs_IOR_fd_write,GSource *gsource)
+static void sandbox_child(int Vfs_IOR_fd_write,GSource *gsource,CaptiveVfsObject *child_captive_vfs_object) G_GNUC_NORETURN;
+static void sandbox_child(int Vfs_IOR_fd_write,GSource *gsource,CaptiveVfsObject *child_captive_vfs_object)
 {
-CORBA_Environment ev;
-CORBA_ORB orb;
-PortableServer_POA poa;
 Captive_Vfs Vfs_object;
 gboolean errbool;
 int errint;
 guint errguint;
 
-       errbool=corba_init("sandbox_child",&ev,&orb,&poa);
-       g_assert(errbool==TRUE);
-       heartbeat_source_callback_orb=orb;
+       errint=close(0);        /* STDIN */
+       g_assert(errint==0);
+       errint=close(1);        /* STDOUT */
+       g_assert(errint==0);
+       errint=close(2);        /* STDERR */
+       g_assert(errint==0);
+
+       g_assert(captive_corba_child_options==NULL);
+       captive_corba_child_options=&child_captive_vfs_object->options;
+
+       heartbeat_source_callback_orb=captive_corba_orb;
 
        /* linc_main_get_loop() makes sense only after corba_init() -> CORBA_ORB_init() */
        errguint=g_source_attach(
@@ -179,14 +182,14 @@ guint errguint;
        g_assert(errguint!=0);
 
        /* Init 'Vfs_object' */
-       Vfs_object=impl_Captive_Vfs__create(poa,&ev);
-       g_assert(validate_CORBA_Environment(&ev));
+       Vfs_object=impl_Captive_Vfs__create(captive_corba_poa,&captive_corba_ev);
+       g_assert(validate_CORBA_Environment(&captive_corba_ev));
 
        /* pass IOR to our parent */
        {
 char *Vfs_IOR;
-               Vfs_IOR=CORBA_ORB_object_to_string(orb,Vfs_object,&ev);
-               g_assert(validate_CORBA_Environment(&ev));
+               Vfs_IOR=CORBA_ORB_object_to_string(captive_corba_orb,Vfs_object,&captive_corba_ev);
+               g_assert(validate_CORBA_Environment(&captive_corba_ev));
                g_assert(Vfs_IOR!=NULL);
                errint=write(Vfs_IOR_fd_write,Vfs_IOR,strlen(Vfs_IOR)+1);
                g_assert((unsigned)errint==strlen(Vfs_IOR)+1);
@@ -198,34 +201,31 @@ char *Vfs_IOR;
        /* CORBA_ORB_run() -> linc_main_loop_run() -> g_main_loop_run()
         * and therefore we should be safe with glib events handling.
         */
-       CORBA_ORB_run(orb,&ev);
-       g_assert(validate_CORBA_Environment(&ev));
+       CORBA_ORB_run(captive_corba_orb,&captive_corba_ev);
+       g_assert(validate_CORBA_Environment(&captive_corba_ev));
 
        /* Shutdown 'Vfs' servant */
-       errbool=corba_servant_object_destroy(poa,Vfs_object,&ev);
-       g_assert(errbool==TRUE);
+       CORBA_Object_release(Vfs_object,&captive_corba_ev);
+       g_assert(validate_CORBA_Environment(&captive_corba_ev));
 
-       errbool=corba_shutdown(&ev,&orb,&poa);
+       errbool=corba_shutdown(&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
        g_assert(errbool==TRUE);
 
        _exit(EXIT_SUCCESS);
 }
 
-static void sandbox_parent(int Vfs_IOR_fd_read)
+static void sandbox_parent
+               (int Vfs_IOR_fd_read,Captive_Vfs *corba_Vfs_object_return,Captive_GlibLogFunc *corba_GlibLogFunc_object_return)
 {
-CORBA_Environment ev;
-CORBA_ORB orb;
-PortableServer_POA poa;
-gboolean errbool;
 char *Vfs_IOR;
 gsize Vfs_IOR_size;
-Captive_Directory directory_object;
 Captive_Vfs Vfs_object;
 Captive_GlibLogFunc GlibLogFunc_object;
 int errint;
 
-       errbool=corba_init("sandbox_parent",&ev,&orb,&poa);
-       g_return_if_fail(errbool==TRUE);
+       g_return_if_fail(Vfs_IOR_fd_read!=-1);
+       g_return_if_fail(corba_Vfs_object_return!=NULL);
+       g_return_if_fail(corba_GlibLogFunc_object_return!=NULL);
 
        Vfs_IOR=captive_rtl_file_read(Vfs_IOR_fd_read,&Vfs_IOR_size);
        g_assert(Vfs_IOR!=NULL);
@@ -234,29 +234,18 @@ int errint;
        errint=close(Vfs_IOR_fd_read);
        g_assert(errint==0);
 
-       Vfs_object=CORBA_ORB_string_to_object(orb,Vfs_IOR,&ev);
-       g_assert(validate_CORBA_Environment(&ev));
+       Vfs_object=CORBA_ORB_string_to_object(captive_corba_orb,Vfs_IOR,&captive_corba_ev);
+       g_assert(validate_CORBA_Environment(&captive_corba_ev));
        g_free(Vfs_IOR);
 
        /* Init 'GlibLogFunc_object' */
-       GlibLogFunc_object=impl_Captive_GlibLogFunc__create(poa,&ev);
-       g_assert(validate_CORBA_Environment(&ev));
-       Captive_Vfs_registerGlibLogFunc(Vfs_object,GlibLogFunc_object,&ev);
-       g_assert(validate_CORBA_Environment(&ev));
-
-       directory_object=Captive_Vfs_directory_new_open(Vfs_object,"/directory",&ev);
-       g_assert(validate_CORBA_Environment(&ev));
-       puts("TEST DONE");
+       GlibLogFunc_object=impl_Captive_GlibLogFunc__create(captive_corba_poa,&captive_corba_ev);
+       g_assert(validate_CORBA_Environment(&captive_corba_ev));
+       Captive_Vfs_registerGlibLogFunc(Vfs_object,GlibLogFunc_object,&captive_corba_ev);
+       g_assert(validate_CORBA_Environment(&captive_corba_ev));
 
-       /* Shutdown 'GlibLogFunc' servant */
-       errbool=corba_servant_object_destroy(poa,GlibLogFunc_object,&ev);
-       g_assert(errbool==TRUE);
-
-       CORBA_Object_release(Vfs_object,&ev);
-       g_assert(validate_CORBA_Environment(&ev));
-
-       errbool=corba_shutdown(&ev,&orb,&poa);
-       g_assert(errbool==TRUE);
+       *corba_Vfs_object_return=Vfs_object;
+       *corba_GlibLogFunc_object_return=GlibLogFunc_object;
 }
 
 static gboolean heartbeat_source_prepare(GSource *source,gint *timeout)
@@ -287,35 +276,55 @@ static GSourceFuncs heartbeat_source_watch_funcs={
                };
 
 
-void captive_sandbox_init(void)
+gboolean captive_sandbox_spawn(CaptiveVfsObject *child_captive_vfs_object,
+               Captive_Vfs *corba_Vfs_object_return,Captive_GlibLogFunc *corba_GlibLogFunc_object_return,int *parentheart_fds_1_return)
 {
 /* Vfs_IOR_fds[0] for reading by sandbox_parent() - client,
  * Vfs_IOR_fds[1] for writing by sandbox_child()  - server
  */
 int Vfs_IOR_fds[2],parentheart_fds[2];
 int errint;
+gboolean errbool;
+
+       g_return_val_if_fail(child_captive_vfs_object!=NULL,FALSE);
+       g_return_val_if_fail(corba_Vfs_object_return!=NULL,FALSE);
+       g_return_val_if_fail(corba_GlibLogFunc_object_return!=NULL,FALSE);
+       g_return_val_if_fail(parentheart_fds_1_return!=NULL,FALSE);
 
        errint=pipe(Vfs_IOR_fds);
-       g_assert(errint==0);
+       g_return_val_if_fail(errint==0,FALSE);
        errint=pipe(parentheart_fds);
-       g_assert(errint==0);
+       g_return_val_if_fail(errint==0,FALSE);
+
+       /* We cannot initialize 'parent' and 'child' name specifically as
+        * we need to have persistence master and its children will be already
+        * CORBA-initialized during their spawn.
+        */
+       errbool=corba_init("captive-sandbox",&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
+       g_return_val_if_fail(errbool==TRUE,FALSE);
+
+       /* Currently never called anywhere:
+        *     errbool=corba_shutdown(&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
+        *     g_assert(errbool==TRUE);
+        */
+
        switch (fork()) {
                case -1:        /* error */
-                       g_assert_not_reached();
+                       g_return_val_if_reached(FALSE);
 
                case 0: { /* child */
 GSource *gsource;
 
                        errint=close(Vfs_IOR_fds[0]);   /* close Vfs_IOR_fd_read */
-                       g_assert(errint==0);
+                       g_return_val_if_fail(errint==0,FALSE);
                        errint=close(parentheart_fds[1]);       /* close parentheart_fd_write */
-                       g_assert(errint==0);
+                       g_return_val_if_fail(errint==0,FALSE);
 
                        /* attach heartbeat_source_callback() to watch for any abnormalities
                         * on our open pipe 'parentheart_fds' and terminate the child if parent dies.
                         */
                        gsource=g_source_new(&heartbeat_source_watch_funcs,sizeof(GSource));
-                       g_assert(gsource!=NULL);
+                       g_return_val_if_fail(gsource!=NULL,FALSE);
                        g_source_set_callback(
                                        gsource,        /* source */
                                        heartbeat_source_callback,      /* func */
@@ -325,23 +334,62 @@ GSource *gsource;
                        heartbeat_source_check_gpollfd.events=HEARTBEAT_SOURCE_CHECK_EVENTS;
                        heartbeat_source_check_gpollfd.revents=0;
                        g_source_add_poll(gsource,&heartbeat_source_check_gpollfd);
-                       sandbox_child(Vfs_IOR_fds[1],gsource);  /* pass Vfs_IOR_fd_write */
+                       sandbox_child(Vfs_IOR_fds[1],gsource,child_captive_vfs_object); /* pass Vfs_IOR_fd_write */
+                       g_return_val_if_reached(FALSE);
                        } /* NOTREACHED */
 
                default:        /* parent */
                        errint=close(Vfs_IOR_fds[1]);   /* close Vfs_IOR_fd_write */
-                       g_assert(errint==0);
+                       g_return_val_if_fail(errint==0,FALSE);
                        errint=close(parentheart_fds[0]);       /* close parentheart_fd_read */
-                       g_assert(errint==0);
+                       g_return_val_if_fail(errint==0,FALSE);
                        errint=fcntl(parentheart_fds[1],F_SETFD,FD_CLOEXEC);
                        /* This fcntl(2) may not be enough - some fork(2) may duplicate this
                         * write descriptor and even if we do some process finish the child
                         * may remain alone connected with some unknown fork(2)er from us.
                         * Currently I am not aware such case would occur.
                         */
-                       g_assert(errint==0);
-                       sandbox_parent(Vfs_IOR_fds[0]); /* pass Vfs_IOR_fd_read, it will be closed there */
-                       break;
+                       g_return_val_if_fail(errint==0,FALSE);
+                       *parentheart_fds_1_return=parentheart_fds[1];
+                       sandbox_parent(
+                                       Vfs_IOR_fds[0], /* Vfs_IOR_fd_read */
+                                       corba_Vfs_object_return,        /* corba_Vfs_object_return */
+                                       corba_GlibLogFunc_object_return);       /* corba_GlibLogFunc_object_return */
+                       /* 'parentheart_fds[1]' - parentheart_fd_write - is left open here */
+                       return TRUE;
+               }
+       /* NOTREACHED */
+       g_return_val_if_reached(FALSE);
+}
+
+
+GnomeVFSResult captive_sandbox_parent_return_from_CORBA_Environment(CORBA_Environment *evp)
+{
+GnomeVFSResult r;
+
+       if (evp->_major==CORBA_NO_EXCEPTION)
+               return GNOME_VFS_OK;
+
+       if (!strcmp(ex_Captive_GnomeVFSResultException,CORBA_exception_id(evp)))
+               r=((Captive_GnomeVFSResultException *)CORBA_exception_value(evp))->gnome_vfs_result;
+       else {
+               r=GNOME_VFS_ERROR_GENERIC;
+               g_warning(_("CORBA Exception occured: id=\"%s\", value=%p"),
+                               CORBA_exception_id(evp),CORBA_exception_value(evp));
                }
-       /* 'parentheart_fds[1]' - parentheart_fd_write - is left open here */
+       CORBA_exception_free(evp);
+
+       return r;
+}
+
+
+void captive_sandbox_child_GnomeVFSResultException_throw(CORBA_Environment *evp,GnomeVFSResult errvfsresult)
+{
+Captive_GnomeVFSResultException *gnome_vfs_result_exception;
+
+       g_return_if_fail(evp!=NULL);
+
+       gnome_vfs_result_exception=Captive_GnomeVFSResultException__alloc();
+       gnome_vfs_result_exception->gnome_vfs_result=errvfsresult;
+       CORBA_exception_set(evp,CORBA_USER_EXCEPTION,ex_Captive_GnomeVFSResultException,gnome_vfs_result_exception);
 }
index 263ff43..33fd4bc 100644 (file)
 
 #include <glib/gmacros.h>
 #include "sandbox.h"
+#include "captive/client-vfs.h"
 
 
 G_BEGIN_DECLS
 
+extern CORBA_Environment captive_corba_ev;
+extern CORBA_ORB captive_corba_orb;
+extern PortableServer_POA captive_corba_poa;
+
+gboolean captive_sandbox_spawn(CaptiveVfsObject *child_captive_vfs_object,
+               Captive_Vfs *corba_Vfs_object_return,Captive_GlibLogFunc *corba_GlibLogFunc_object_return,int *parentheart_fds_1_return);
 gboolean validate_CORBA_Environment(const CORBA_Environment *evp);
+GnomeVFSResult captive_sandbox_parent_return_from_CORBA_Environment(CORBA_Environment *evp);
+void captive_sandbox_child_GnomeVFSResultException_throw(CORBA_Environment *evp,GnomeVFSResult errvfsresult);
+void sandbox_child_shutdown(void);
 
 G_END_DECLS
 
index e149b57..e7d8e09 100644 (file)
@@ -31,7 +31,7 @@
  * captive_cdrom_init:
  *
  * Creates system device "\Device\CdRom%d" providing readonly access
- * to the given #image_iochannel as emulation of CD-ROM driver.
+ * to the given #captive_image_iochannel as emulation of CD-ROM driver.
  *
  * libcaptive currently supports just one drive and thus "\Device\CdRom0"
  * is always created. It is forbidden to call this function twice.
@@ -43,7 +43,7 @@ gboolean captive_cdrom_init(void)
 static struct captive_DriverObject cdrom_captive_DriverObject;
 NTSTATUS err;
 
-       g_return_val_if_fail(captive_options->image_iochannel!=NULL,FALSE);
+       g_return_val_if_fail(captive_image_iochannel!=NULL,FALSE);
 
        cdrom_captive_DriverObject.DiskGeometry.BytesPerSector=2048;
        cdrom_captive_DriverObject.DiskGeometry.MediaType=RemovableMedia;
index 384dda0..2bc4d37 100644 (file)
  * captive_disk_init:
  *
  * Creates system device "\Device\CaptiveHarddisk%d" providing readwrite access
- * to the given #image_iochannel as emulation of harddisk driver.
+ * to the given #captive_image_iochannel as emulation of harddisk driver.
  * reactos initializes "\Device\Harddisk%d\Partition0" as the whole disk
  * and each partition it founds by IoReadPartitionTable() it will create
  * as "\Device\Harddisk%d\Partition1", "\Device\Harddisk%d\Partition2" etc.
  *
  * libcaptive does not (yet?) support any partitions and it will always create
- * just the disk device for the whole given #image_iochannel.
+ * just the disk device for the whole given #captive_image_iochannel.
  * As this behaviour is a bit specific we rather create some non-standard name
  * of the device; anyway I have seen some "\Device\Harddisk%dVolume%d" on W32
  * system.
@@ -52,7 +52,7 @@ gboolean captive_disk_init(void)
 static struct captive_DriverObject disk_captive_DriverObject;
 NTSTATUS err;
 
-       g_return_val_if_fail(captive_options->image_iochannel!=NULL,FALSE);
+       g_return_val_if_fail(captive_image_iochannel!=NULL,FALSE);
 
        disk_captive_DriverObject.DiskGeometry.BytesPerSector=512;
        disk_captive_DriverObject.DiskGeometry.MediaType=FixedMedia;
index 543638e..8f03d1b 100644 (file)
@@ -33,6 +33,7 @@
 #include "captive/options.h"
 
 
+GIOChannel *captive_image_iochannel;
 guint64 captive_image_size;
 
 
@@ -393,7 +394,7 @@ const struct MajorFunction_READ_WRITE_func_Parameters *Parameters=NULL;     /* Preve
                        G_STRLOC,(IrpStack->MajorFunction==IRP_MJ_READ ? "IRP_MJ_READ" : "IRP_MJ_WRITE"),
                        (guint64)Parameters->ByteOffset.QuadPart,(gulong)Parameters->Length);
 
-       erriostatus=g_io_channel_seek_position(captive_options->image_iochannel,
+       erriostatus=g_io_channel_seek_position(captive_image_iochannel,
                        Parameters->ByteOffset.QuadPart,        /* offset */
                        G_SEEK_SET,     /* type */
                        NULL);  /* error */
@@ -403,7 +404,7 @@ const struct MajorFunction_READ_WRITE_func_Parameters *Parameters=NULL;     /* Preve
                case IRP_MJ_READ: {
 gsize bytesread;
 
-                       erriostatus=g_io_channel_read_chars(captive_options->image_iochannel,
+                       erriostatus=g_io_channel_read_chars(captive_image_iochannel,
                                        buffer, /* buf */
                                        Parameters->Length,     /* count */
                                        &bytesread,     /* bytesread */
@@ -415,7 +416,7 @@ gsize bytesread;
                case IRP_MJ_WRITE: {
 gsize byteswritten;
 
-                       erriostatus=g_io_channel_write_chars(captive_options->image_iochannel,
+                       erriostatus=g_io_channel_write_chars(captive_image_iochannel,
                                        buffer, /* buf */
                                        Parameters->Length,     /* count */
                                        &byteswritten,  /* byteswritten */
@@ -457,7 +458,7 @@ struct captive_DriverObject *captive_DriverObject;
 
        /* libcaptive is not authorized to shutdown 'captive_image_channel'. */
        erriostatus=g_io_channel_flush(
-                       captive_options->image_iochannel,       /* channel */
+                       captive_image_iochannel,        /* channel */
                        NULL);  /* error */
        g_assert(erriostatus==G_IO_STATUS_NORMAL);