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);
134 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
138 g_return_val_if_fail(buffer_corba->_length<=num_bytes,GNOME_VFS_ERROR_GENERIC);
139 memcpy(buffer_captive,buffer_corba->_buffer,buffer_corba->_length);
140 *bytes_read_return=buffer_corba->_length;
142 Captive_Bytes__freekids(buffer_corba,NULL/* 'd'; meaning? */);
143 CORBA_free(buffer_corba);
146 xmlNewProp(xml_action,"bytes_read_return",captive_printf_alloca("%lu",(unsigned long)*bytes_read_return));
152 GnomeVFSResult captive_sandbox_parent_file_write(CaptiveFileObject *captive_file_object,
153 gconstpointer buffer_captive,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_written_return)
156 Captive_Bytes buffer_corba_local;
157 Captive_GnomeVFSFileSize bytes_written_corba;
158 xmlNode *xml_action=NULL;
160 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
161 g_return_val_if_fail(buffer_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
162 g_return_val_if_fail(bytes_written_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
163 g_return_val_if_fail(num_bytes==(ULONG)num_bytes,GNOME_VFS_ERROR_BAD_PARAMETERS);
164 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
166 *bytes_written_return=0;
168 if (captive_file_object->vfs->corba_bug_action) {
169 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_write",NULL);
170 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
171 xmlNewProp(xml_action,"num_bytes",captive_printf_alloca("%lu",(unsigned long)num_bytes));
174 buffer_corba_local._maximum=num_bytes;
175 buffer_corba_local._length=num_bytes;
176 buffer_corba_local._buffer=(/* de-const */gpointer)buffer_captive;
177 buffer_corba_local._release=FALSE;
179 Captive_File_write(captive_file_object->corba_File_object,&buffer_corba_local,&bytes_written_corba,&captive_corba_ev);
180 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
182 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
186 *bytes_written_return=bytes_written_corba;
189 xmlNewProp(xml_action,"bytes_written_return",captive_printf_alloca("%lu",(unsigned long)*bytes_written_return));
195 GnomeVFSResult captive_sandbox_parent_file_seek
196 (CaptiveFileObject *captive_file_object,GnomeVFSSeekPosition whence,GnomeVFSFileOffset offset)
199 xmlNode *xml_action=NULL;
201 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
202 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
204 if (captive_file_object->vfs->corba_bug_action) {
205 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_seek",NULL);
206 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
207 xmlNewProp(xml_action,"whence",
208 (whence==GNOME_VFS_SEEK_START ? "start" :
209 (whence==GNOME_VFS_SEEK_CURRENT ? "current" :
210 (whence==GNOME_VFS_SEEK_END ? "end" : captive_printf_alloca("%lu",(unsigned long)whence)))));
211 xmlNewProp(xml_action,"offset",captive_printf_alloca("%" G_GINT64_FORMAT,(gint64)offset));
214 Captive_File_seek(captive_file_object->corba_File_object,whence,offset,&captive_corba_ev);
215 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
217 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
225 GnomeVFSResult captive_sandbox_parent_file_tell(CaptiveFileObject *captive_file_object,GnomeVFSFileOffset *offset_return)
227 Captive_GnomeVFSFileOffset offset_corba;
229 xmlNode *xml_action=NULL;
231 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
232 g_return_val_if_fail(offset_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
233 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
235 if (captive_file_object->vfs->corba_bug_action) {
236 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_tell",NULL);
237 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
240 Captive_File_tell(captive_file_object->corba_File_object,&offset_corba,&captive_corba_ev);
241 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
243 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
247 *offset_return=offset_corba;
250 xmlNewProp(xml_action,"offset_return",captive_printf_alloca("%" G_GINT64_FORMAT,(gint64)*offset_return));
256 GnomeVFSResult captive_sandbox_parent_file_remove(CaptiveFileObject *captive_file_object)
259 xmlNode *xml_action=NULL;
261 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
262 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
264 if (captive_file_object->vfs->corba_bug_action) {
265 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_remove",NULL);
266 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
269 Captive_File_remove(captive_file_object->corba_File_object,&captive_corba_ev);
270 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
272 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
280 GnomeVFSResult captive_sandbox_parent_file_file_info_get(CaptiveFileObject *captive_file_object,
281 GnomeVFSFileInfo *file_info_captive)
283 Captive_GnomeVFSFileInfo *file_info_corba;
285 xmlNode *xml_action=NULL;
287 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
288 g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
289 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
291 if (captive_file_object->vfs->corba_bug_action) {
292 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_file_info_get",NULL);
293 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
296 Captive_File_file_info_get(captive_file_object->corba_File_object,&file_info_corba,&captive_corba_ev);
297 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
299 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
303 r=captive_sandbox_file_info_corba_to_captive(file_info_captive,file_info_corba);
304 Captive_GnomeVFSFileInfo__freekids(file_info_corba,NULL/* 'd'; meaning? */);
305 CORBA_free(file_info_corba);
307 xmlSetProp(xml_action,"result",gnome_vfs_result_to_string(r));
315 GnomeVFSResult captive_sandbox_parent_file_file_info_set(CaptiveFileObject *captive_file_object,
316 const GnomeVFSFileInfo *file_info_captive,GnomeVFSSetFileInfoMask mask)
318 Captive_GnomeVFSFileInfo file_info_corba;
320 xmlNode *xml_action=NULL;
322 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
323 g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
324 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
326 if (captive_file_object->vfs->corba_bug_action) {
327 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_file_info_set",NULL);
328 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
329 xmlNewProp(xml_action,"mask",captive_printf_alloca("%u",(unsigned)mask));
332 if (GNOME_VFS_OK!=(r=captive_sandbox_file_info_captive_to_corba(&file_info_corba,file_info_captive)))
335 Captive_File_file_info_set(captive_file_object->corba_File_object,&file_info_corba,mask,&captive_corba_ev);
336 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
338 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
342 Captive_GnomeVFSFileInfo__freekids(&file_info_corba,NULL/* 'd'; meaning? */);
348 GnomeVFSResult captive_sandbox_parent_file_truncate(CaptiveFileObject *captive_file_object,GnomeVFSFileSize file_size)
351 xmlNode *xml_action=NULL;
353 g_return_val_if_fail(captive_file_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
354 g_return_val_if_fail(captive_file_object->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
356 if (captive_file_object->vfs->corba_bug_action) {
357 xml_action=xmlNewTextChild(captive_file_object->vfs->corba_bug_action,NULL,"file_truncate",NULL);
358 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object));
359 xmlNewProp(xml_action,"file_size",captive_printf_alloca("%" G_GUINT64_FORMAT,(guint64)file_size));
362 Captive_File_truncate(captive_file_object->corba_File_object,file_size,&captive_corba_ev);
363 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
365 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
373 GnomeVFSResult captive_sandbox_parent_file_move
374 (CaptiveFileObject *captive_file_object_old,const gchar *pathname_new,gboolean force_replace)
377 xmlNode *xml_action=NULL;
379 g_return_val_if_fail(captive_file_object_old!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
380 g_return_val_if_fail(pathname_new!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
381 g_return_val_if_fail(captive_file_object_old->file_Handle==NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
383 if (captive_file_object_old->vfs->corba_bug_action) {
384 xml_action=xmlNewTextChild(captive_file_object_old->vfs->corba_bug_action,NULL,"file_truncate",NULL);
385 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_object_old));
386 xmlNewProp(xml_action,"pathname_new",pathname_new);
387 xmlNewProp(xml_action,"force_replace",captive_printf_alloca("%u",(unsigned)force_replace));
390 Captive_File_move(captive_file_object_old->corba_File_object,pathname_new,force_replace,&captive_corba_ev);
391 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
393 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));