libgsf r980 - in trunk: . gsf gsf-gnome



Author: mortenw
Date: Thu Apr 10 02:51:57 2008
New Revision: 980
URL: http://svn.gnome.org/viewvc/libgsf?rev=980&view=rev

Log:
2008-04-09  Morten Welinder  <terra gnome org>

	* configure.in: Reorganize gnome-vfs/bonobo checks.

	* gsf-gnome/gsf-input-gnomevfs.c (gsf_input_gnomevfs_new_uri):
	Prepare for making this a simple wrapper over gio.

	* gsf/gsf-utils.c (gsf_base64_decode_step): Use
	g_base64_decode_step when available.
	(gsf_base64_encode_step): Use g_base64_encode_step when available.
	(gsf_base64_encode_close): Use g_base64_encode_close when available.



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/configure.in
   trunk/gsf-gnome/gsf-input-gnomevfs.c
   trunk/gsf-gnome/gsf-input-gnomevfs.h
   trunk/gsf/gsf-utils.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Thu Apr 10 02:51:57 2008
@@ -3,6 +3,10 @@
 Dom:
 	* Revitalize gio support.
 
+Morten:
+	* Use g_base64_-routines from glib when available.
+	* Prepare for using gio to simulate gnome-vfs interface.
+
 --------------------------------------------------------------------------
 libgsf 1.14.8
 

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Thu Apr 10 02:51:57 2008
@@ -178,6 +178,7 @@
 SAVE_LIBS=$LIBS
 CFLAGS="$CFLAGS $LIBGSF_CFLAGS"
 LIBS="$LIBGSF_LIBS $LIBS"
+AC_CHECK_FUNCS(g_base64_encode)
 AC_MSG_CHECKING([for g_chmod])
 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <glib/gstdio.h>]], [[(void)g_chmod("/xxx",0777);]])],
                [AC_DEFINE(HAVE_G_CHMOD, 1, [Define if g_chmod is available as macro or function])
@@ -353,50 +354,7 @@
 
 AC_SUBST(BZ2_LIBS)
 
-dnl ***********************************************************************************
-
-dnl gnome
-dnl
-want_gnome=auto
-AC_ARG_WITH(gnome,
-	[--{with,without}-gnome   Build additional wrappers for GNOME-VFS and BONOBO],
-	[case $withval in
-	yes) want_gnome=yes;;
-	no) want_gnome=no;;
-	esac[]dnl
-])
-
-have_bonobo=no
-have_gnome=no
-if  test $want_gnome = no ; then 
-    AC_MSG_WARN([GNOME support disabled, as requested (Use --with-gnome to enable)])
-else
-    dnl check for bonobo
-    AC_ARG_WITH(bonobo,
-	AC_HELP_STRING([--without-bonobo],[disable the use of bonobo]),
-	[case "${withval}" in
-	yes) have_bonobo=yes ;;
-	no) have_bonobo=no ;;
-	*) AC_MSG_ERROR(bad value ${withval} for --with-bonobo) ;;
-	esac],
-	[have_bonobo=yes]) dnl Default value
-
-    if test $have_bonobo = yes; then
-	libgsf_gnome_reqs="$libgsf_gnome_reqs libbonobo-2.0 >= 2.0.0"
-    fi
-
-    PKG_CHECK_MODULES(LIBGSF_GNOME, $libgsf_gnome_reqs,
-	[have_gnome=yes],
-	[if test $want_gnome = yes; then
-	    AC_MSG_ERROR([GNOME support requested, but not available.])
-	 else
-	    AC_MSG_WARN([GNOME support disabled, unable to find required version of VFS and/or Bonobo])
-	 fi])
-fi
-AM_CONDITIONAL(WITH_LIBGSF_GNOME, test $have_gnome = yes)
-AM_CONDITIONAL(WITH_LIBGSF_BONOBO, test $have_bonobo = yes)
-
-dnl ***********************************************************************************
+dnl ****************************************************************************
 
 dnl gio
 dnl
@@ -422,6 +380,64 @@
 	 fi])
 fi
 AM_CONDITIONAL(WITH_GIO, test $have_gio = yes)
+want_gio=$have_gio
+
+dnl ****************************************************************************
+
+dnl gnome
+dnl
+
+want_gnome=no
+
+want_gnome_vfs=auto
+AC_ARG_WITH(gnome_vfs,
+	[--{with,without}-gnome-vfs   Build wrappers for GNOME-VFS],
+	[case $withval in
+	yes) want_gnome_vfs=yes;;
+	no) want_gnome_vfs=no;;
+	esac[]dnl
+])
+if test $want_gnome_vfs = auto -a "DISABLED$want_gio" = yes; then
+   	want_gnome_vfs=yes
+fi
+if test $want_gnome_vfs = yes; then
+   	if test "DISABLED$want_gio" = yes; then
+	   	AC_DEFINE(LIBGSF_GNOMEVFS_VIA_GIO, 1, [Define if gio is used to implement gnome-vfs api])
+	else
+	        libgsf_gnome_reqs="$libgsf_gnome_reqs gnome-vfs-2.0 >= 2.2.0"
+        	libgsf_gnome_reqs="$libgsf_gnome_reqs gnome-vfs-module-2.0 >= 2.2.0"
+	fi
+   	want_gnome=yes
+fi
+
+
+want_bonobo=no
+dnl check for bonobo
+AC_ARG_WITH(bonobo,
+    AC_HELP_STRING([--without-bonobo],[disable the use of bonobo]),
+    [case "${withval}" in
+    yes) want_bonobo=yes ;;
+    no) want_bonobo=no ;;
+    *) AC_MSG_ERROR(bad value ${withval} for --with-bonobo) ;;
+    esac],
+    [want_bonobo=yes]) dnl Default value
+
+if test $want_bonobo = yes; then
+    libgsf_gnome_reqs="$libgsf_gnome_reqs libbonobo-2.0 >= 2.0.0"
+    want_gnome=yes
+fi
+
+
+have_gnome=no
+if test $want_gnome = no ; then 
+    AC_MSG_WARN([GNOME support disabled, as requested (Use --with-gnome-vfs and/or --with-bonobo to enable)])
+else
+    PKG_CHECK_MODULES(LIBGSF_GNOME, $libgsf_gnome_reqs,
+	[have_gnome=yes],
+	[AC_MSG_ERROR([GNOME support requested, but not available.])])
+fi
+AM_CONDITIONAL(WITH_LIBGSF_GNOME, test $have_gnome = yes)
+AM_CONDITIONAL(WITH_LIBGSF_BONOBO, test $want_bonobo = yes)
 
 # ===================
 # GConf configuration

Modified: trunk/gsf-gnome/gsf-input-gnomevfs.c
==============================================================================
--- trunk/gsf-gnome/gsf-input-gnomevfs.c	(original)
+++ trunk/gsf-gnome/gsf-input-gnomevfs.c	Thu Apr 10 02:51:57 2008
@@ -22,11 +22,18 @@
 #include <gsf-config.h>
 #include <string.h>
 
+#ifdef LIBGSF_GNOMEVFS_VIA_GIO
+#include <gsf/gsf-input-gio.h>
+#define GnomeVFSHandle void
+#define GnomeVFSURI void
+#else
+#include <libgnomevfs/gnome-vfs-method.h>
+#endif
+
 #include <gsf-gnome/gsf-input-gnomevfs.h>
 #include <gsf/gsf-input-memory.h>
 #include <gsf/gsf-input-impl.h>
 #include <gsf/gsf-impl-utils.h>
-#include <libgnomevfs/gnome-vfs-method.h>
 
 struct _GsfInputGnomeVFS {
 	GsfInput input;
@@ -40,6 +47,56 @@
 
 typedef GsfInputClass GsfInputGnomeVFSClass;
 
+
+#ifdef LIBGSF_GNOMEVFS_VIA_GIO
+
+GType
+gsf_input_gnomevfs_get_type (void)
+{
+	return gsf_input_gio_get_type ();
+}
+
+GsfInput *
+gsf_input_gnomevfs_new (char const *uri, GError **error)
+{
+	return gsf_input_gio_new_for_path (uri, error);
+}
+
+GsfInput *
+gsf_input_gnomevfs_new_uri (GnomeVFSURI *uri, GError **error)
+{
+	static gboolean tried = FALSE;
+	static char * (*h_g_vfs_uri_to_string) (const GnomeVFSURI *uri, int);
+
+	if (!tried) {
+		gpointer p;
+		GModule *module;
+
+		tried = TRUE;
+		module = g_module_open (NULL, 0);
+		if (module) {
+			if (g_module_symbol (module, "gnome_vfs_uri_to_string",
+					     &p))
+				h_g_vfs_uri_to_string = p;
+			g_module_close (module);
+		}
+	}
+
+	if (h_g_vfs_uri_to_string) {
+		char *uritxt = h_g_vfs_uri_to_string (uri, 0);
+		g_printerr ("uri=[%s]\n", uritxt);
+		GsfInput *res = gsf_input_gio_new_for_path (uritxt, error);
+		g_free (uritxt);
+		return res;
+	}
+
+	g_set_error (error, gsf_input_error_id (), 0,
+		     "Failed to interface to gnome-vfs");
+	return NULL;
+}
+
+#else
+
 /**
  * gsf_input_gnomevfs_new_uri:
  * @uri : uri you wish to open.
@@ -307,3 +364,5 @@
 GSF_CLASS (GsfInputGnomeVFS, gsf_input_gnomevfs,
 	   gsf_input_gnomevfs_class_init, gsf_input_gnomevfs_init,
 	   GSF_INPUT_TYPE)
+
+#endif

Modified: trunk/gsf-gnome/gsf-input-gnomevfs.h
==============================================================================
--- trunk/gsf-gnome/gsf-input-gnomevfs.h	(original)
+++ trunk/gsf-gnome/gsf-input-gnomevfs.h	Thu Apr 10 02:51:57 2008
@@ -23,7 +23,13 @@
 #define GSF_INPUT_GNOMEVFS_H
 
 #include <gsf/gsf-input.h>
+#ifndef LIBGSF_GNOMEVFS_VIA_GIO
+/*
+ * The installed version will always do this.  For our emulation layer, we
+ * want to avoid it.
+ */
 #include <libgnomevfs/gnome-vfs.h>
+#endif
 
 G_BEGIN_DECLS
 

Modified: trunk/gsf/gsf-utils.c
==============================================================================
--- trunk/gsf/gsf-utils.c	(original)
+++ trunk/gsf/gsf-utils.c	Thu Apr 10 02:51:57 2008
@@ -80,7 +80,9 @@
 #endif
 
 
+#ifndef HAVE_G_BASE64_ENCODE
 static void base64_init (void);
+#endif
 
 #ifdef G_OS_WIN32
 #include <windows.h>
@@ -131,7 +133,9 @@
 #endif
 
 	g_type_init ();
+#ifndef HAVE_G_BASE64_ENCODE
 	base64_init ();
+#endif
 
 #ifdef _GSF_GTYPE_THREADING_FIXED
 	if (NULL == static_type_module) {
@@ -593,6 +597,7 @@
 	return result;
 }
 
+#ifndef HAVE_G_BASE64_ENCODE
 /***************************************************************************/
 /* some code taken from evolution/camel/camel-mime-utils.c */
 
@@ -603,7 +608,7 @@
  *           Jeffrey Stedfast <fejj ximian com>
  *
  * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
+ * modify it under the terms of version 2 of the GNU Lesser General Public
  * License as published by the Free Software Foundation.
  *
  * This program is distributed in the hope that it will be useful,
@@ -638,6 +643,7 @@
 	}
 	camel_mime_base64_rank['='] = 0;
 }
+#endif
 
 /**
  * gsf_base64_encode_close :
@@ -657,8 +663,14 @@
 gsf_base64_encode_close (guint8 const *in, size_t inlen,
 			 gboolean break_lines, guint8 *out, int *state, unsigned int *save)
 {
-	int c1, c2;
 	guint8 *outptr = out;
+#ifdef HAVE_G_BASE64_ENCODE
+	if (inlen > 0)
+		outptr += gsf_base64_encode_step (in, inlen, break_lines,
+						  outptr, state, save);
+	outptr += g_base64_encode_close (break_lines, outptr, state, save);
+#else
+	int c1, c2;
 
 	if (inlen>0)
 		outptr += gsf_base64_encode_step(in, inlen, break_lines, outptr, state, save);
@@ -692,6 +704,7 @@
 	*save = 0;
 	*state = 0;
 
+#endif
 	return outptr-out;
 }
 
@@ -714,6 +727,9 @@
 gsf_base64_encode_step (guint8 const *in, size_t len,
 			gboolean break_lines, guint8 *out, int *state, unsigned int *save)
 {
+#ifdef HAVE_G_BASE64_ENCODE
+	return g_base64_encode_step (in, len, break_lines, out, state, save);
+#else
 	register guint8 const *inptr;
 	register guint8 *outptr;
 
@@ -785,6 +801,7 @@
 		 (int)((char *)save)[2]));
 
 	return outptr-out;
+#endif
 }
 
 
@@ -804,6 +821,9 @@
 gsf_base64_decode_step (guint8 const *in, size_t len, guint8 *out,
 			int *state, guint *save)
 {
+#ifdef HAVE_G_BASE64_ENCODE
+	return g_base64_decode_step (in, len, out, state, save);
+#else
 	register guint8 const *inptr;
 	register guint8 *outptr, c;
 	register unsigned int v;
@@ -848,6 +868,7 @@
 
 	/* if i!= 0 then there is a truncation error! */
 	return outptr-out;
+#endif
 }
 
 /**
@@ -863,17 +884,17 @@
 gsf_base64_encode_simple (guint8 const *data, size_t len)
 {
 	guint8 *out;
-	int state = 0, outlen;
-	unsigned int save = 0;
-	gboolean break_lines = TRUE;
+	int state = 0;
+	guint save = 0;
+	gboolean break_lines = TRUE;  /* This differs from g_base64_encode */
+	size_t outlen = len * 4 / 3 + 5;
 
-	outlen = len * 4 / 3 + 5;
 	if (break_lines)
-		outlen += outlen / BASE64_LINE_LEN + 1;
+		outlen += outlen / 72 + 1;
 	out = g_new (guint8, outlen);
 	outlen = gsf_base64_encode_close (data, len, break_lines,
 					  out, &state, &save);
-	out [outlen] = '\0';
+	out[outlen] = '\0';
 	return out;
 }
 
@@ -890,7 +911,7 @@
 gsf_base64_decode_simple (guint8 *data, size_t len)
 {
 	int state = 0;
-	unsigned int save = 0;
+	guint save = 0;
 	return gsf_base64_decode_step (data, len, data, &state, &save);
 }
 



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