2 * CORBA/ORBit client side of File object of sandbox_parent()
3 * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
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
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.
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
22 #include "captive/parent-File.h" /* self */
23 #include <glib/gmessages.h>
26 #include "../client/file.h"
27 #include "../client/vfs.h"
29 #include "captive/macros.h"
32 GnomeVFSResult captive_sandbox_parent_file_new_open(CaptiveFileObject *captive_file_object,
33 const gchar *pathname,GnomeVFSOpenMode mode)
35 xmlNode *xml_action=NULL;
37 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
38 g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
40 if (captive_file_object->vfs->corba_bug_action) {
41 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_new_open",NULL);
42 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
43 xmlNewProp(xml_action,"pathname",pathname);
44 xmlNewProp(xml_action,"mode",captive_printf_alloca("%u",(unsigned)mode));
47 captive_file_object->corba_File_object=Captive_Vfs_file_new_open(
48 captive_file_object->vfs->corba_Vfs_object,pathname,mode,&captive_corba_ev);
50 xmlNewProp(xml_action,"result",(captive_corba_ev._major==CORBA_NO_EXCEPTION ? "1" : "0"));
52 return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
56 GnomeVFSResult captive_sandbox_parent_file_new_create(CaptiveFileObject *captive_file_object,
57 const gchar *pathname,GnomeVFSOpenMode mode,gboolean exclusive,guint perm)
59 xmlNode *xml_action=NULL;
61 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
62 g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
64 if (captive_file_object->vfs->corba_bug_action) {
65 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_new_create",NULL);
66 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
67 xmlNewProp(xml_action,"pathname",pathname);
68 xmlNewProp(xml_action,"mode",captive_printf_alloca("%u",(unsigned)mode));
69 xmlNewProp(xml_action,"exclusive",captive_printf_alloca("%u",(unsigned)exclusive));
70 xmlNewProp(xml_action,"perm",captive_printf_alloca("%u",(unsigned)perm));
73 captive_file_object->corba_File_object=Captive_Vfs_file_new_create(
74 captive_file_object->vfs->corba_Vfs_object,pathname,mode,exclusive,perm,&captive_corba_ev);
76 xmlNewProp(xml_action,"result",(captive_corba_ev._major==CORBA_NO_EXCEPTION ? "1" : "0"));
78 return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
82 GnomeVFSResult captive_sandbox_parent_file_close(CaptiveFileObject *captive_file_object)
85 xmlNode *xml_action=NULL;
87 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
88 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
90 if (captive_file_object->vfs->corba_bug_action) {
91 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_close",NULL);
92 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
95 Captive_File_shutdown(captive_file_object->corba_File_object,&captive_corba_ev);
96 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
98 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
102 CORBA_Object_release((CORBA_Object)captive_file_object->corba_File_object,&captive_corba_ev);
103 captive_file_object->corba_File_object=CORBA_OBJECT_NIL;
105 return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
109 GnomeVFSResult captive_sandbox_parent_file_read(CaptiveFileObject *captive_file_object,
110 gpointer buffer_captive,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_read_return)
113 Captive_Bytes *buffer_corba;
114 xmlNode *xml_action=NULL;
116 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
117 g_return_val_if_fail(buffer_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
118 g_return_val_if_fail(bytes_read_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
119 g_return_val_if_fail(num_bytes==(ULONG)num_bytes,GNOME_VFS_ERROR_BAD_PARAMETERS);
120 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
122 *bytes_read_return=0;
124 if (captive_file_object->vfs->corba_bug_action) {
125 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_read",NULL);
126 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
127 xmlNewProp(xml_action,"num_bytes",captive_printf_alloca("%lu",(unsigned long)num_bytes));
130 Captive_File_read(captive_file_object->corba_File_object,&buffer_corba,num_bytes,&captive_corba_ev);
131 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
133 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
137 g_return_val_if_fail(buffer_corba->_length<=num_bytes,GNOME_VFS_ERROR_GENERIC);
138 memcpy(buffer_captive,buffer_corba->_buffer,buffer_corba->_length);
139 *bytes_read_return=buffer_corba->_length;
141 Captive_Bytes__freekids(buffer_corba,NULL/* 'd'; meaning? */);
142 CORBA_free(buffer_corba);
145 xmlNewProp(xml_action,"bytes_read_return",captive_printf_alloca("%lu",(unsigned long)*bytes_read_return));
151 GnomeVFSResult captive_sandbox_parent_file_write(CaptiveFileObject *captive_file_object,
152 gconstpointer buffer_captive,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_written_return)
155 Captive_Bytes buffer_corba_local;
156 Captive_GnomeVFSFileSize bytes_written_corba;
157 xmlNode *xml_action=NULL;
159 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
160 g_return_val_if_fail(buffer_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
161 g_return_val_if_fail(bytes_written_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
162 g_return_val_if_fail(num_bytes==(ULONG)num_bytes,GNOME_VFS_ERROR_BAD_PARAMETERS);
163 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
165 *bytes_written_return=0;
167 if (captive_file_object->vfs->corba_bug_action) {
168 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_write",NULL);
169 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
170 xmlNewProp(xml_action,"num_bytes",captive_printf_alloca("%lu",(unsigned long)num_bytes));
173 buffer_corba_local._maximum=num_bytes;
174 buffer_corba_local._length=num_bytes;
175 buffer_corba_local._buffer=(/* de-const */gpointer)buffer_captive;
176 buffer_corba_local._release=FALSE;
178 Captive_File_write(captive_file_object->corba_File_object,&buffer_corba_local,&bytes_written_corba,&captive_corba_ev);
179 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
181 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
185 *bytes_written_return=bytes_written_corba;
188 xmlNewProp(xml_action,"bytes_written_return",captive_printf_alloca("%lu",(unsigned long)*bytes_written_return));
194 GnomeVFSResult captive_sandbox_parent_file_seek
195 (CaptiveFileObject *captive_file_object,GnomeVFSSeekPosition whence,GnomeVFSFileOffset offset)
198 xmlNode *xml_action=NULL;
200 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
201 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
203 if (captive_file_object->vfs->corba_bug_action) {
204 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_seek",NULL);
205 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
206 xmlNewProp(xml_action,"whence",
207 (whence==GNOME_VFS_SEEK_START ? "start" :
208 (whence==GNOME_VFS_SEEK_CURRENT ? "current" :
209 (whence==GNOME_VFS_SEEK_END ? "end" : captive_printf_alloca("%lu",(unsigned long)whence)))));
210 xmlNewProp(xml_action,"offset",captive_printf_alloca("%" G_GINT64_FORMAT,(gint64)offset));
213 Captive_File_seek(captive_file_object->corba_File_object,whence,offset,&captive_corba_ev);
214 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
216 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
224 GnomeVFSResult captive_sandbox_parent_file_tell(CaptiveFileObject *captive_file_object,GnomeVFSFileOffset *offset_return)
226 Captive_GnomeVFSFileOffset offset_corba;
228 xmlNode *xml_action=NULL;
230 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
231 g_return_val_if_fail(offset_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
232 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
234 if (captive_file_object->vfs->corba_bug_action) {
235 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_tell",NULL);
236 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
239 Captive_File_tell(captive_file_object->corba_File_object,&offset_corba,&captive_corba_ev);
240 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
242 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
246 *offset_return=offset_corba;
249 xmlNewProp(xml_action,"offset_return",captive_printf_alloca("%" G_GINT64_FORMAT,(gint64)*offset_return));
255 GnomeVFSResult captive_sandbox_parent_file_remove(CaptiveFileObject *captive_file_object)
258 xmlNode *xml_action=NULL;
260 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
261 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
263 if (captive_file_object->vfs->corba_bug_action) {
264 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_remove",NULL);
265 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
268 Captive_File_remove(captive_file_object->corba_File_object,&captive_corba_ev);
269 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
271 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
279 GnomeVFSResult captive_sandbox_parent_file_file_info_get(CaptiveFileObject *captive_file_object,
280 GnomeVFSFileInfo *file_info_captive)
282 Captive_GnomeVFSFileInfo *file_info_corba;
284 xmlNode *xml_action=NULL;
286 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
287 g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
288 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
290 if (captive_file_object->vfs->corba_bug_action) {
291 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_file_info_get",NULL);
292 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
295 Captive_File_file_info_get(captive_file_object->corba_File_object,&file_info_corba,&captive_corba_ev);
296 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
298 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
302 r=captive_sandbox_file_info_corba_to_captive(file_info_captive,file_info_corba);
303 Captive_GnomeVFSFileInfo__freekids(file_info_corba,NULL/* 'd'; meaning? */);
304 CORBA_free(file_info_corba);
306 xmlSetProp(xml_action,"result",gnome_vfs_result_to_string(r));
314 GnomeVFSResult captive_sandbox_parent_file_file_info_set(CaptiveFileObject *captive_file_object,
315 const GnomeVFSFileInfo *file_info_captive,GnomeVFSSetFileInfoMask mask)
317 Captive_GnomeVFSFileInfo file_info_corba;
319 xmlNode *xml_action=NULL;
321 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
322 g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
323 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
325 if (captive_file_object->vfs->corba_bug_action) {
326 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_file_info_set",NULL);
327 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
328 xmlNewProp(xml_action,"mask",captive_printf_alloca("%u",(unsigned)mask));
331 if (GNOME_VFS_OK!=(r=captive_sandbox_file_info_captive_to_corba(&file_info_corba,file_info_captive)))
334 Captive_File_file_info_set(captive_file_object->corba_File_object,&file_info_corba,mask,&captive_corba_ev);
335 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
337 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
341 Captive_GnomeVFSFileInfo__freekids(&file_info_corba,NULL/* 'd'; meaning? */);
347 GnomeVFSResult captive_sandbox_parent_file_truncate(CaptiveFileObject *captive_file_object,GnomeVFSFileSize file_size)
350 xmlNode *xml_action=NULL;
352 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
353 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
355 if (captive_file_object->vfs->corba_bug_action) {
356 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_truncate",NULL);
357 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
358 xmlNewProp(xml_action,"file_size",captive_printf_alloca("%" G_GUINT64_FORMAT,(guint64)file_size));
361 Captive_File_truncate(captive_file_object->corba_File_object,file_size,&captive_corba_ev);
362 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
364 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
372 GnomeVFSResult captive_sandbox_parent_file_move
373 (CaptiveFileObject *captive_file_object_old,const gchar *pathname_new,gboolean force_replace)
376 xmlNode *xml_action=NULL;
378 g_return_val_if_fail(captive_file_object_old!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
379 g_return_val_if_fail(pathname_new!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
380 g_return_val_if_fail(captive_file_object_old->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
382 if (captive_file_object_old->vfs->corba_bug_action) {
383 xml_action=xmlNewTextChild(captive_file_object_old->vfs->corba_bug_action,NULL,"file_truncate",NULL);
384 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object_old));
385 xmlNewProp(xml_action,"pathname_new",pathname_new);
386 xmlNewProp(xml_action,"force_replace",captive_printf_alloca("%u",(unsigned)force_replace));
389 Captive_File_move(captive_file_object_old->corba_File_object,pathname_new,force_replace,&captive_corba_ev);
390 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
392 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));