Finished and deployed CORBA sandbox separation
[captive.git] / src / libcaptive / sandbox / server-Vfs.c
1 /* $Id$
2  * CORBA/ORBit server side of Vfs object, ran by sandbox_child()
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "server-Vfs.h" /* self */
23 #include "server-GlibLogFunc.h" /* for impl_Captive_Vfs_registerGlibLogFunc() */
24 #include "sandbox.h"
25 #include <glib/gmessages.h>
26 #include "captive/macros.h"
27 #include "server-Directory.h"
28 #include "server-File.h"
29 #include "split.h"
30
31
32 static void impl_Captive_Vfs_shutdown(impl_POA_Captive_Vfs *servant,CORBA_Environment *ev);
33
34 static PortableServer_ServantBase__epv impl_Captive_Vfs_base_epv={
35         NULL,   /* _private data */
36         NULL,   /* finalize routine */
37         NULL,   /* default_POA routine */
38         };
39 static POA_Captive_Vfs__epv impl_Captive_Vfs_epv={
40         NULL,   /* _private */
41         (gpointer)&impl_Captive_Vfs_registerGlibLogFunc,
42         (gpointer)&impl_Captive_Vfs_shutdown,
43         (gpointer)&impl_Captive_Vfs_directory_new_open,
44         (gpointer)&impl_Captive_Vfs_directory_new_make,
45         (gpointer)&impl_Captive_Vfs_file_new_open,
46         (gpointer)&impl_Captive_Vfs_file_new_create,
47         };
48 static POA_Captive_Vfs__vepv impl_Captive_Vfs_vepv={
49         &impl_Captive_Vfs_base_epv,
50         &impl_Captive_Vfs_epv,
51         };
52
53
54 struct captive_options *captive_corba_child_options;
55
56
57 Captive_Vfs impl_Captive_Vfs__create(PortableServer_POA poa,CORBA_Environment *ev)
58 {
59 Captive_Vfs retval;
60 impl_POA_Captive_Vfs *newservant;
61 PortableServer_ObjectId *objid;
62 GnomeVFSResult errvfsresult;
63
64         captive_new0(newservant);       /* FIXME: leak */
65         newservant->servant.vepv=&impl_Captive_Vfs_vepv;
66         newservant->poa=poa;
67         if (GNOME_VFS_OK!=(errvfsresult=captive_vfs_new(&newservant->captive_vfs_object,captive_corba_child_options))) {
68                 g_free(newservant);
69                 CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Captive_GnomeVFSResultException,GINT_TO_POINTER((gint)errvfsresult));
70                 return NULL;
71                 }
72         POA_Captive_Vfs__init((PortableServer_Servant)newservant,ev);
73         objid=PortableServer_POA_activate_object(poa,newservant,ev);
74         CORBA_free(objid);
75         retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
76
77         return retval;
78 }
79
80
81 static gboolean impl_Captive_Vfs_shutdown_idle(gpointer data /* unused */)
82 {
83         sandbox_child_shutdown();
84
85         return FALSE;   /* remove me */
86 }
87
88 static void impl_Captive_Vfs_shutdown(impl_POA_Captive_Vfs *servant,CORBA_Environment *ev)
89 {
90         /* Do not call sandbox_child_shutdown() directly as we would fail
91          * to finish this CORBA method call properly.
92          */
93         g_idle_add_full(
94                         G_PRIORITY_LOW, /* priority */
95                         impl_Captive_Vfs_shutdown_idle, /* function */
96                         NULL,   /* data */
97                         NULL);  /* notify */
98 }