Finished and deployed CORBA sandbox separation
[captive.git] / src / libcaptive / sandbox / server-Directory.c
1 /* $Id$
2  * CORBA/ORBit server side of Directory 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-Directory.h"   /* self */
23 #include "sandbox.h"
24 #include <glib/gmessages.h>
25 #include "captive/macros.h"
26 #include "../client/directory.h"
27 #include "FileInfo.h"
28 #include "split.h"
29
30
31 static void impl_Captive_Directory_fini(impl_POA_Captive_Directory *servant,CORBA_Environment *ev);
32 static void impl_Captive_Directory_read
33                 (impl_POA_Captive_Directory *servant,Captive_GnomeVFSFileInfo **file_info,CORBA_Environment *ev);
34 static void impl_Captive_Directory_remove(impl_POA_Captive_Directory *servant,CORBA_Environment *ev);
35
36
37 static PortableServer_ServantBase__epv impl_Captive_Directory_base_epv={
38         NULL,   /* _private data */
39         (gpointer)&impl_Captive_Directory_fini, /* finalize routine */
40         NULL,   /* default_POA routine */
41         };
42 static POA_Captive_Directory__epv impl_Captive_Directory_epv={
43         NULL,   /* _private */
44         (gpointer)&impl_Captive_Directory_read,
45         (gpointer)&impl_Captive_Directory_remove,
46         };
47 static POA_Captive_Directory__vepv impl_Captive_Directory_vepv={
48         &impl_Captive_Directory_base_epv,
49         &impl_Captive_Directory_epv,
50         };
51
52
53 Captive_Directory impl_Captive_Directory__create(PortableServer_POA poa,CORBA_Environment *ev)
54 {
55 Captive_Directory retval;
56 impl_POA_Captive_Directory *newservant;
57 PortableServer_ObjectId *objid;
58
59         captive_new0(newservant);       /* FIXME: leak */
60         newservant->servant.vepv=&impl_Captive_Directory_vepv;
61         newservant->poa=poa;
62         newservant->captive_directory_object=NULL;
63         POA_Captive_Directory__init((PortableServer_Servant)newservant,ev);
64         objid=PortableServer_POA_activate_object(poa,newservant,ev);
65         CORBA_free(objid);
66         retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
67
68         return retval;
69 }
70
71
72 static void impl_Captive_Directory_fini(impl_POA_Captive_Directory *servant,CORBA_Environment *ev)
73 {
74         if (servant->captive_directory_object) {
75                 g_object_unref(servant->captive_directory_object);
76                 servant->captive_directory_object=NULL;
77                 }
78 }
79
80
81 static void impl_Captive_Directory__destroy(impl_POA_Captive_Directory *servant,CORBA_Environment *ev)
82 {
83 PortableServer_ObjectId *objid;
84
85         objid=PortableServer_POA_servant_to_id(servant->poa,servant,ev);
86         PortableServer_POA_deactivate_object(servant->poa,objid,ev);
87         CORBA_free(objid);
88         impl_Captive_Directory_fini(servant,ev);
89         g_free(servant);
90 }
91
92
93 Captive_Directory impl_Captive_Vfs_directory_new_open
94                 (impl_POA_Captive_Vfs *servant,const CORBA_char *pathname,CORBA_Environment *ev)
95 {
96 Captive_Directory retval;
97 impl_POA_Captive_Directory *retval_servant;
98 GnomeVFSResult errvfsresult;
99
100         retval=impl_Captive_Directory__create(servant->poa,ev);
101         if (ev->_major!=CORBA_NO_EXCEPTION)
102                 return NULL;
103
104         retval_servant=PortableServer_POA_reference_to_servant(servant->poa,retval,ev);
105         if (ev->_major!=CORBA_NO_EXCEPTION)
106                 return NULL;    /* 'retval' leak */
107
108         if (GNOME_VFS_OK!=(errvfsresult=captive_directory_new_open(&retval_servant->captive_directory_object,
109                         servant->captive_vfs_object,pathname))) {
110                 impl_Captive_Directory__destroy(retval_servant,ev);
111                 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
112                 return NULL;
113                 }
114
115         return retval;
116 }
117
118
119 Captive_Directory impl_Captive_Vfs_directory_new_make(impl_POA_Captive_Vfs *servant,
120                 const CORBA_char *pathname,const Captive_GnomeVFSFilePermissions perm,CORBA_Environment *ev)
121 {
122 Captive_Directory retval;
123 impl_POA_Captive_Directory *retval_servant;
124 GnomeVFSResult errvfsresult;
125
126         retval=impl_Captive_Directory__create(servant->poa,ev);
127         if (ev->_major!=CORBA_NO_EXCEPTION)
128                 return NULL;
129
130         retval_servant=PortableServer_POA_reference_to_servant(servant->poa,retval,ev);
131         if (ev->_major!=CORBA_NO_EXCEPTION)
132                 return NULL;    /* 'retval' leak */
133
134         if (GNOME_VFS_OK!=(errvfsresult=captive_directory_new_make(&retval_servant->captive_directory_object,
135                         servant->captive_vfs_object,pathname,perm))) {
136                 impl_Captive_Directory__destroy(retval_servant,ev);
137                 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
138                 return NULL;
139                 }
140
141         return retval;
142 }
143
144
145 static void impl_Captive_Directory_read
146                 (impl_POA_Captive_Directory *servant,Captive_GnomeVFSFileInfo **file_info_corba_return,CORBA_Environment *ev)
147 {
148 GnomeVFSFileInfo file_info_captive;
149 Captive_GnomeVFSFileInfo *file_info_corba;
150 GnomeVFSResult errvfsresult;
151
152         if (GNOME_VFS_OK!=(errvfsresult=captive_directory_read(servant->captive_directory_object,&file_info_captive))) {
153                 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
154                 return;
155                 }
156
157         file_info_corba=Captive_GnomeVFSFileInfo__alloc();
158
159         if (GNOME_VFS_OK!=(errvfsresult=captive_sandbox_file_info_captive_to_corba(
160                         file_info_corba,&file_info_captive))) {
161                 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
162                 Captive_GnomeVFSFileInfo__freekids(file_info_corba,NULL/* 'd'; meaning? */);
163                 CORBA_free(file_info_corba);
164                 return;
165                 }
166
167         *file_info_corba_return=file_info_corba;
168 }
169
170
171 static void impl_Captive_Directory_remove(impl_POA_Captive_Directory *servant,CORBA_Environment *ev)
172 {
173 GnomeVFSResult errvfsresult;
174
175         if (GNOME_VFS_OK!=(errvfsresult=captive_directory_remove(servant->captive_directory_object))) {
176                 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
177                 return;
178                 }
179 }