Finished and deployed CORBA sandbox separation
[captive.git] / src / libcaptive / sandbox / server-Directory.c
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;
+               }
+}