Re: BonoboStream from Moniker [Patch]



Hi Michael,

On 29 Jan 2002, Michael Meeks wrote:
>
> 	Sounds great - can you re-hash the patch though ? we also don't want to
> be adding the ',' to the escaped whatnots I think - that looks broken to
> me.

I've reworked the patch, it's attached.

ERDI Gergo wrote:
> I thought Bonobo was API-frozen?

Why this patch?
--------------
Well, does API-frozen mean: Don't fix bugs? You are right this patch maybe
considered an API addition, but I think it's more a bugfix. The reason is,
that in Gnome 1.4 you can use the BonoboStream interface for creating,
reading and writing files. This is an exposed API which is used by others
and which we should support. But in it's current state bonobo for Gnome
2.0 does *only* allow reading of files, nothing more.

Without this patch we make it hard for people porting their application to
Gnome 2.0 when using the BonoboStream interface.

What impact has this patch?
---------------------------
I admit this patch has impacts, but IMO they are _very_ minor. As
explained in my previous mail there occur problems when you try to
read/write/create a file which has one of the following suffixes: ',w+',
',r+', ',w' or ',r' (eg. /foobar,r+). This will be interpreted as open
file /foobar for reading and writing. If you always add the stream option
to the filename, then this can be prevented (eg. /foobar,r+,w means open
file /foobar,r+ for writing). And once again: You are only forced to add
these options if your filename ends _exactly_ with one of the four
suffixes above. Otherwise you get exactly the same behavour than without
the patch. This means: nearly no one is negativly affected by this, but we
can ease the porting effort for a lot of people.

Regards,

   Jens

-- 
"Wer die Freiheit aufgibt, um Sicherheit zu gewinnen, wird am Ende beides
verlieren." -- Benjamin Franklin
Index: monikers/ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-vfs/monikers/ChangeLog,v
retrieving revision 1.42
diff -u -p -r1.42 ChangeLog
--- monikers/ChangeLog	2002/01/17 17:59:25	1.42
+++ monikers/ChangeLog	2002/01/29 17:36:30
@@ -1,3 +1,10 @@
+2002-01-29  Jens Finke <jens triq net>
+
+	* bonobo-moniker-file.c (bonobo_moniker_file_resolve): Consider
+	stream/storage options.
+	(get_storage_options): New function. Extracts storage/stream
+	options from the moniker string.
+	
 2002-01-17  Darin Adler  <darin bentspoon com>
 
 	* bonobo-storage-fs.c: Added an include of <string.h>, needed because
Index: monikers/bonobo-moniker-file.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/monikers/bonobo-moniker-file.c,v
retrieving revision 1.18
diff -u -p -r1.18 bonobo-moniker-file.c
--- monikers/bonobo-moniker-file.c	2001/07/10 12:04:03	1.18
+++ monikers/bonobo-moniker-file.c	2002/01/29 17:36:31
@@ -18,52 +18,93 @@
 #include "bonobo-stream-fs.h"
 #include "bonobo-storage-fs.h"
 
+static char*
+get_storage_options (const char *fname, int *options)
+{
+	char *pos;
+	int len;
+
+	*options = Bonobo_Storage_READ; /* default */
+
+	pos = strrchr (fname, ',');
+	if (!pos) return g_strdup (fname);
+
+	len = strlen (pos);
+	if (len > 3) return g_strdup (fname);
+
+	if (!strcmp (pos, ",r+"))
+		*options = Bonobo_Storage_READ | Bonobo_Storage_WRITE;
+	else if (!strcmp (pos, ",w+"))
+		*options = Bonobo_Storage_WRITE | Bonobo_Storage_CREATE;
+	else if (!strcmp (pos, ",r") && len==2)
+		 *options = Bonobo_Storage_READ;
+	else if (!strcmp (pos, ",w") && len==2)
+		*options = Bonobo_Storage_WRITE;
+	else 
+		return g_strdup (fname);
+
+	return g_strndup (fname, pos - fname);
+}
+
 Bonobo_Unknown
 bonobo_moniker_file_resolve (BonoboMoniker               *moniker,
 			     const Bonobo_ResolveOptions *options,
 			     const CORBA_char            *requested_interface,
 			     CORBA_Environment           *ev)
 {
-	const char    *fname = bonobo_moniker_get_name (moniker);
+	int            storage_opts;
+	char           *fname; 
 	Bonobo_Unknown retval;
+	
+	fname = get_storage_options (bonobo_moniker_get_name (moniker),
+				     &storage_opts);
 
 	if (!strcmp (requested_interface, "IDL:Bonobo/Stream:1.0")) {
 		BonoboObject *stream;
-		
+
 		stream = BONOBO_OBJECT (bonobo_stream_fs_open (
-			fname, Bonobo_Storage_READ, 0664, ev));
+			fname, storage_opts, 0664, ev));
 
-		if (BONOBO_EX (ev))
+		if (BONOBO_EX (ev)) {
+			g_free (fname);
 			return CORBA_OBJECT_NIL;
+		}
 
 		if (!stream) {
 			g_warning ("Failed to open stream '%s'", fname);
 			CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
 					     ex_Bonobo_Moniker_InterfaceNotFound, NULL);
+			g_free (fname);
 			return CORBA_OBJECT_NIL;
 		}
 
+		g_free (fname);
 		return CORBA_Object_duplicate (BONOBO_OBJREF (stream), ev);
 
 	} else if (!strcmp (requested_interface, "IDL:Bonobo/Storage:1.0")) {
 		BonoboObject *storage;
 		
 		storage = BONOBO_OBJECT (bonobo_storage_fs_open (
-			fname, Bonobo_Storage_READ, 0664, ev));
+			fname, storage_opts, 0664, ev));
 
-		if (BONOBO_EX (ev))
+		if (BONOBO_EX (ev)) {
+			g_free (fname);
 			return CORBA_OBJECT_NIL;
+		}
 
 		if (!storage) {
 			g_warning ("Failed to open storage '%s'", fname);
 			CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
 					     ex_Bonobo_Moniker_InterfaceNotFound, NULL);
+			g_free (fname);
 			return CORBA_OBJECT_NIL;
 		}
 
+		g_free (fname);
 		return CORBA_Object_duplicate (BONOBO_OBJREF (storage), ev);
 	}
-
+	g_free (fname);
+			
 	retval = bonobo_moniker_use_extender (
 		"OAFIID:Bonobo_MonikerExtender_file",
 		moniker, options, requested_interface, ev);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]