Finished and deployed CORBA sandbox separation
[captive.git] / src / libcaptive / client / vfs.c
1 /* $Id$
2  * captive vfs 'vfs' interface to reactos
3  * Copyright (C) 2002-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 "captive/client-vfs.h" /* self */
23 #include "vfs.h"        /* self-priv */
24 #include <glib/gmessages.h>
25 #include "captive/macros.h"
26 #include "init.h"
27 #include "captive/parent-Vfs.h"
28 #include "../sandbox/server-Vfs.h"      /* for captive_corba_child_options */
29
30
31 static gpointer captive_vfs_object_parent_class=NULL;
32
33
34 static GnomeVFSResult captive_vfs_close(CaptiveVfsObject *captive_vfs_object);
35
36 static void captive_vfs_object_finalize(CaptiveVfsObject *captive_vfs_object)
37 {
38         g_return_if_fail(captive_vfs_object!=NULL);
39
40         captive_vfs_close(captive_vfs_object);  /* errors ignored */
41
42         G_OBJECT_CLASS(captive_vfs_object_parent_class)->finalize((GObject *)captive_vfs_object);
43 }
44
45
46 static void captive_vfs_object_class_init(CaptiveVfsObjectClass *class)
47 {
48 GObjectClass *gobject_class=G_OBJECT_CLASS(class);
49
50         captive_vfs_object_parent_class=g_type_class_ref(G_TYPE_OBJECT);
51         gobject_class->finalize=(void (*)(GObject *object))captive_vfs_object_finalize;
52 }
53
54
55 static void captive_vfs_object_init(CaptiveVfsObject *captive_vfs_object)
56 {
57         CAPTIVE_MEMZERO(&captive_vfs_object->options);
58 }
59
60
61 GType captive_vfs_object_get_type(void)
62 {
63 static GType captive_vfs_object_type=0;
64
65         if (!captive_vfs_object_type) {
66 static const GTypeInfo captive_vfs_object_info={
67                                 sizeof(CaptiveVfsObjectClass),
68                                 NULL,   /* base_init */
69                                 NULL,   /* base_finalize */
70                                 (GClassInitFunc)captive_vfs_object_class_init,
71                                 NULL,   /* class_finalize */
72                                 NULL,   /* class_data */
73                                 sizeof(CaptiveVfsObject),
74                                 5,      /* n_preallocs */
75                                 (GInstanceInitFunc)captive_vfs_object_init,
76                                 };
77
78                 captive_vfs_object_type=g_type_register_static(G_TYPE_OBJECT,
79                                 "CaptiveVfsObject",&captive_vfs_object_info,0);
80                 }
81
82         return captive_vfs_object_type;
83 }
84
85
86 GnomeVFSResult captive_vfs_new
87                 (CaptiveVfsObject **captive_vfs_object_return,const struct captive_options *options)
88 {
89 CaptiveVfsObject *captive_vfs_object;
90 gboolean errbool;
91
92         g_return_val_if_fail(captive_vfs_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
93         g_return_val_if_fail(options!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
94
95         *captive_vfs_object_return=NULL;
96
97         captive_vfs_object=g_object_new(
98                         CAPTIVE_VFS_TYPE_OBJECT,        /* object_type */
99                         NULL);  /* first_property_name; FIXME: support properties */
100
101         captive_options_copy(&captive_vfs_object->options,options);
102
103         *captive_vfs_object_return=captive_vfs_object;
104
105         /* We are sandboxing && we are the master */
106         if (options->sandbox && !captive_corba_child_options)
107                 return captive_sandbox_parent_vfs_new(captive_vfs_object);
108
109         g_assert(captive_options==NULL);
110         captive_options=&captive_vfs_object->options;
111
112         errbool=captive_init();
113         g_assert(errbool==TRUE);
114
115         return GNOME_VFS_OK;
116 }
117
118
119 static GnomeVFSResult captive_vfs_close(CaptiveVfsObject *captive_vfs_object)
120 {
121 gboolean errbool;
122
123         g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
124
125         if (captive_vfs_object->is_sandbox_parent)
126                 return captive_sandbox_parent_vfs_close(captive_vfs_object);
127
128         g_assert(captive_options==&captive_vfs_object->options);
129         errbool=captive_shutdown();
130         g_assert(errbool==TRUE);
131
132         captive_options=NULL;
133         captive_options_free(&captive_vfs_object->options);
134
135         return GNOME_VFS_OK;
136 }