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 "parent-File.h" /* self */
23 #include <glib/gmessages.h>
26 #include "../client/file.h"
27 #include "../client/vfs.h"
29 #include "captive/macros.h"
30 #include "reactos/ntos/types.h" /* for ULONG */
33 GnomeVFSResult captive_sandbox_parent_file_new_open(CaptiveFileParentObject *captive_file_parent_object,
34 const gchar *pathname,GnomeVFSOpenMode mode)
36 xmlNode *xml_action=NULL;
37 CaptiveVfsParentObject *captive_vfs_parent_object;
39 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
40 g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
42 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
44 if (captive_vfs_parent_object->corba_bug_action) {
45 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_new_open",NULL);
46 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
47 xmlNewProp(xml_action,"pathname",pathname);
48 xmlNewProp(xml_action,"mode",captive_printf_alloca("%u",(unsigned)mode));
51 captive_file_parent_object->corba_File_object=Captive_Vfs_file_new_open(
52 captive_vfs_parent_object->corba_Vfs_object,pathname,mode,&captive_corba_ev);
54 xmlNewProp(xml_action,"result",(captive_corba_ev._major==CORBA_NO_EXCEPTION ? "1" : "0"));
56 return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
60 GnomeVFSResult captive_sandbox_parent_file_new_create(CaptiveFileParentObject *captive_file_parent_object,
61 const gchar *pathname,GnomeVFSOpenMode mode,gboolean exclusive,guint perm)
63 xmlNode *xml_action=NULL;
64 CaptiveVfsParentObject *captive_vfs_parent_object;
66 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
67 g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
69 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
71 if (captive_vfs_parent_object->corba_bug_action) {
72 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_new_create",NULL);
73 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
74 xmlNewProp(xml_action,"pathname",pathname);
75 xmlNewProp(xml_action,"mode",captive_printf_alloca("%u",(unsigned)mode));
76 xmlNewProp(xml_action,"exclusive",captive_printf_alloca("%u",(unsigned)exclusive));
77 xmlNewProp(xml_action,"perm",captive_printf_alloca("%u",(unsigned)perm));
80 captive_file_parent_object->corba_File_object=Captive_Vfs_file_new_create(
81 captive_vfs_parent_object->corba_Vfs_object,pathname,mode,exclusive,perm,&captive_corba_ev);
83 xmlNewProp(xml_action,"result",(captive_corba_ev._major==CORBA_NO_EXCEPTION ? "1" : "0"));
85 return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
89 GnomeVFSResult captive_sandbox_parent_file_close(CaptiveFileParentObject *captive_file_parent_object)
92 xmlNode *xml_action=NULL;
93 CaptiveVfsParentObject *captive_vfs_parent_object;
95 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
97 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
99 if (captive_vfs_parent_object->corba_bug_action) {
100 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_close",NULL);
101 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
104 Captive_File_shutdown(captive_file_parent_object->corba_File_object,&captive_corba_ev);
105 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
107 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
111 CORBA_Object_release((CORBA_Object)captive_file_parent_object->corba_File_object,&captive_corba_ev);
112 captive_file_parent_object->corba_File_object=CORBA_OBJECT_NIL;
114 return captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
118 GnomeVFSResult captive_sandbox_parent_file_read(CaptiveFileParentObject *captive_file_parent_object,
119 gpointer buffer_captive,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_read_return)
122 Captive_Bytes *buffer_corba;
123 xmlNode *xml_action=NULL;
124 CaptiveVfsParentObject *captive_vfs_parent_object;
126 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
127 g_return_val_if_fail(buffer_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
128 g_return_val_if_fail(bytes_read_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
129 g_return_val_if_fail(num_bytes==(ULONG)num_bytes,GNOME_VFS_ERROR_BAD_PARAMETERS);
131 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
133 *bytes_read_return=0;
135 if (captive_vfs_parent_object->corba_bug_action) {
136 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_read",NULL);
137 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
138 xmlNewProp(xml_action,"num_bytes",captive_printf_alloca("%lu",(unsigned long)num_bytes));
141 Captive_File_read(captive_file_parent_object->corba_File_object,&buffer_corba,num_bytes,&captive_corba_ev);
142 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
144 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
148 g_return_val_if_fail(buffer_corba->_length<=num_bytes,GNOME_VFS_ERROR_GENERIC);
149 memcpy(buffer_captive,buffer_corba->_buffer,buffer_corba->_length);
150 *bytes_read_return=buffer_corba->_length;
152 Captive_Bytes__freekids(buffer_corba,NULL/* 'd'; meaning? */);
153 CORBA_free(buffer_corba);
156 xmlNewProp(xml_action,"bytes_read_return",captive_printf_alloca("%lu",(unsigned long)*bytes_read_return));
162 GnomeVFSResult captive_sandbox_parent_file_write(CaptiveFileParentObject *captive_file_parent_object,
163 gconstpointer buffer_captive,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_written_return)
166 Captive_Bytes buffer_corba_local;
167 Captive_GnomeVFSFileSize bytes_written_corba;
168 xmlNode *xml_action=NULL;
169 CaptiveVfsParentObject *captive_vfs_parent_object;
171 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
172 g_return_val_if_fail(buffer_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
173 g_return_val_if_fail(bytes_written_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
174 g_return_val_if_fail(num_bytes==(ULONG)num_bytes,GNOME_VFS_ERROR_BAD_PARAMETERS);
176 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
178 *bytes_written_return=0;
180 if (captive_vfs_parent_object->corba_bug_action) {
181 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_write",NULL);
182 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
183 xmlNewProp(xml_action,"num_bytes",captive_printf_alloca("%lu",(unsigned long)num_bytes));
186 buffer_corba_local._maximum=num_bytes;
187 buffer_corba_local._length=num_bytes;
188 buffer_corba_local._buffer=(/* de-const */gpointer)buffer_captive;
189 buffer_corba_local._release=FALSE;
191 Captive_File_write(captive_file_parent_object->corba_File_object,&buffer_corba_local,&bytes_written_corba,&captive_corba_ev);
192 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
194 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
198 *bytes_written_return=bytes_written_corba;
201 xmlNewProp(xml_action,"bytes_written_return",captive_printf_alloca("%lu",(unsigned long)*bytes_written_return));
207 GnomeVFSResult captive_sandbox_parent_file_seek
208 (CaptiveFileParentObject *captive_file_parent_object,GnomeVFSSeekPosition whence,GnomeVFSFileOffset offset)
211 xmlNode *xml_action=NULL;
212 CaptiveVfsParentObject *captive_vfs_parent_object;
214 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
216 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
218 if (captive_vfs_parent_object->corba_bug_action) {
219 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_seek",NULL);
220 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
221 xmlNewProp(xml_action,"whence",
222 (whence==GNOME_VFS_SEEK_START ? "start" :
223 (whence==GNOME_VFS_SEEK_CURRENT ? "current" :
224 (whence==GNOME_VFS_SEEK_END ? "end" : captive_printf_alloca("%lu",(unsigned long)whence)))));
225 xmlNewProp(xml_action,"offset",captive_printf_alloca("%" G_GINT64_FORMAT,(gint64)offset));
228 Captive_File_seek(captive_file_parent_object->corba_File_object,whence,offset,&captive_corba_ev);
229 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
231 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
239 GnomeVFSResult captive_sandbox_parent_file_tell(CaptiveFileParentObject *captive_file_parent_object,GnomeVFSFileOffset *offset_return)
241 Captive_GnomeVFSFileOffset offset_corba;
243 xmlNode *xml_action=NULL;
244 CaptiveVfsParentObject *captive_vfs_parent_object;
246 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
247 g_return_val_if_fail(offset_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
249 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
251 if (captive_vfs_parent_object->corba_bug_action) {
252 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_tell",NULL);
253 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
256 Captive_File_tell(captive_file_parent_object->corba_File_object,&offset_corba,&captive_corba_ev);
257 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
259 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
263 *offset_return=offset_corba;
266 xmlNewProp(xml_action,"offset_return",captive_printf_alloca("%" G_GINT64_FORMAT,(gint64)*offset_return));
272 GnomeVFSResult captive_sandbox_parent_file_remove(CaptiveFileParentObject *captive_file_parent_object)
275 xmlNode *xml_action=NULL;
276 CaptiveVfsParentObject *captive_vfs_parent_object;
278 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
280 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
282 if (captive_vfs_parent_object->corba_bug_action) {
283 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_remove",NULL);
284 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
287 Captive_File_remove(captive_file_parent_object->corba_File_object,&captive_corba_ev);
288 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
290 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
298 GnomeVFSResult captive_sandbox_parent_file_file_info_get(CaptiveFileParentObject *captive_file_parent_object,
299 GnomeVFSFileInfo *file_info_captive)
301 Captive_GnomeVFSFileInfo *file_info_corba;
303 xmlNode *xml_action=NULL;
304 CaptiveVfsParentObject *captive_vfs_parent_object;
306 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
307 g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
309 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
311 if (captive_vfs_parent_object->corba_bug_action) {
312 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_file_info_get",NULL);
313 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
316 Captive_File_file_info_get(captive_file_parent_object->corba_File_object,&file_info_corba,&captive_corba_ev);
317 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
319 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
323 r=captive_sandbox_file_info_corba_to_captive(file_info_captive,file_info_corba);
324 Captive_GnomeVFSFileInfo__freekids(file_info_corba,NULL/* 'd'; meaning? */);
325 CORBA_free(file_info_corba);
327 xmlSetProp(xml_action,"result",gnome_vfs_result_to_string(r));
335 GnomeVFSResult captive_sandbox_parent_file_file_info_set(CaptiveFileParentObject *captive_file_parent_object,
336 const GnomeVFSFileInfo *file_info_captive,GnomeVFSSetFileInfoMask mask)
338 Captive_GnomeVFSFileInfo file_info_corba;
340 xmlNode *xml_action=NULL;
341 CaptiveVfsParentObject *captive_vfs_parent_object;
343 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
344 g_return_val_if_fail(file_info_captive!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
346 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
348 if (captive_vfs_parent_object->corba_bug_action) {
349 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_file_info_set",NULL);
350 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
351 xmlNewProp(xml_action,"mask",captive_printf_alloca("%u",(unsigned)mask));
354 if (GNOME_VFS_OK!=(r=captive_sandbox_file_info_captive_to_corba(&file_info_corba,file_info_captive)))
357 Captive_File_file_info_set(captive_file_parent_object->corba_File_object,&file_info_corba,mask,&captive_corba_ev);
358 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
360 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
364 Captive_GnomeVFSFileInfo__freekids(&file_info_corba,NULL/* 'd'; meaning? */);
370 GnomeVFSResult captive_sandbox_parent_file_truncate(CaptiveFileParentObject *captive_file_parent_object,GnomeVFSFileSize file_size)
373 xmlNode *xml_action=NULL;
374 CaptiveVfsParentObject *captive_vfs_parent_object;
376 g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
378 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
380 if (captive_vfs_parent_object->corba_bug_action) {
381 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_truncate",NULL);
382 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
383 xmlNewProp(xml_action,"file_size",captive_printf_alloca("%" G_GUINT64_FORMAT,(guint64)file_size));
386 Captive_File_truncate(captive_file_parent_object->corba_File_object,file_size,&captive_corba_ev);
387 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
389 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
397 GnomeVFSResult captive_sandbox_parent_file_move
398 (CaptiveFileParentObject *captive_file_parent_object_old,const gchar *pathname_new,gboolean force_replace)
401 xmlNode *xml_action=NULL;
402 CaptiveVfsParentObject *captive_vfs_parent_object;
404 g_return_val_if_fail(captive_file_parent_object_old!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
405 g_return_val_if_fail(pathname_new!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
407 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object_old)->vfs);
409 if (captive_vfs_parent_object->corba_bug_action) {
410 xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_truncate",NULL);
411 xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object_old));
412 xmlNewProp(xml_action,"pathname_new",pathname_new);
413 xmlNewProp(xml_action,"force_replace",captive_printf_alloca("%u",(unsigned)force_replace));
416 Captive_File_move(captive_file_parent_object_old->corba_File_object,pathname_new,force_replace,&captive_corba_ev);
417 r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
419 xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));