[evolution-patches] Re: [Evolution-hackers] Libsoup encode problem



Hi, Dan,

   The patch is ok for me. Thanks.

   Will you plan to check in this patch soon?

Best Regards

Alfred Peng

Dan Winship wrote:

On Mon, 2004-08-02 at 17:35 +0800, alfred.peng wrote:
Hi, Dan,

   I've hacked soup-uri.[ch], and made a patch to solve the problem.

   Would you please help me to review the patch?

I'm attaching an alternate patch. Can you see if it works for you?

I changed the name of the flag to "broken_encoding" and added a comment
saying "Don't use this", because various other parts of libsoup assume
that SoupUri parts are always stored unencoded, and using the flag may
cause things to fail. There are also various other complications you
need to deal with; for instance, you need to prevent SoupSession from
handling redirects for you automatically, since you may need to encode
the redirect URL specially.

I think the right long-term fix (which won't happen for evo 2.0) is to
make SoupUri an object and allow it to be subclassed. (This would let us
get rid of E2kUri in Connector as well.)

-- Dan

------------------------------------------------------------------------

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libsoup/ChangeLog,v
retrieving revision 1.438
diff -u -r1.438 ChangeLog
--- ChangeLog	19 Jul 2004 20:07:18 -0000	1.438
+++ ChangeLog	2 Aug 2004 17:20:28 -0000
@@ -1,3 +1,11 @@
+2004-08-02  Dan Winship  <danw novell com>
+
+	* libsoup/soup-uri.h: Add flag "broken_encoding" to SoupUri.
+
+	* libsoup/soup-uri.c: (soup_uri_to_string): if broken_encoding is
+	set, don't re-encode the URL parts. Based on a patch by
+ Alfred Peng Sun COM +
2004-07-19  JP Rosevear  <jpr novell com>

	* configure.in: bump version, libtool number
Index: libsoup/soup-uri.c
===================================================================
RCS file: /cvs/gnome/libsoup/libsoup/soup-uri.c,v
retrieving revision 1.29
diff -u -r1.29 soup-uri.c
--- libsoup/soup-uri.c	7 Jul 2004 15:27:24 -0000	1.29
+++ libsoup/soup-uri.c	2 Aug 2004 17:20:28 -0000
@@ -11,6 +11,8 @@

#include "soup-uri.h"

+static void append_uri_encoded (GString *str, const char *in, const char *extra_enc_chars);
+
static inline SoupProtocol
soup_uri_get_protocol (const char *proto, int len)
{
@@ -40,8 +42,6 @@
		return 0;
}

-static void append_uri_encoded (GString *str, const char *in, const char *extra_enc_chars);
-
/**
 * soup_uri_new_with_base:
 * @base: a base URI
@@ -255,6 +255,17 @@
	return uri;
}

+
+static inline void
+append_uri (GString *str, const char *in, const char *extra_enc_chars,
+	    gboolean pre_encoded)
+{
+	if (pre_encoded)
+		g_string_append (str, in);
+	else
+		append_uri_encoded (str, in, extra_enc_chars);
+}
+
/**
 * soup_uri_to_string:
 * @uri: a #SoupUri
@@ -267,6 +278,7 @@
{
	GString *str;
	char *return_result;
+	gboolean pre_encoded = uri->broken_encoding;

	/* IF YOU CHANGE ANYTHING IN THIS FUNCTION, RUN
	 * tests/uri-parsing AFTERWARD.
@@ -279,10 +291,10 @@
	if (uri->host && !just_path) {
		g_string_append (str, "//");
		if (uri->user) {
-			append_uri_encoded (str, uri->user, ":;@/");
+			append_uri (str, uri->user, ":;@/", pre_encoded);
			g_string_append_c (str, '@');
		}
-		append_uri_encoded (str, uri->host, ":/");
+		append_uri (str, uri->host, ":/", pre_encoded);
		if (uri->port && uri->port != soup_protocol_default_port (uri->protocol))
			g_string_append_printf (str, ":%d", uri->port);
		if (!uri->path && (uri->query || uri->fragment))
@@ -290,17 +302,17 @@
	}

	if (uri->path && *uri->path)
-		append_uri_encoded (str, uri->path, "?");
+		append_uri (str, uri->path, "?", pre_encoded);
	else if (just_path)
		g_string_append_c (str, '/');

	if (uri->query) {
		g_string_append_c (str, '?');
-		append_uri_encoded (str, uri->query, NULL);
+		append_uri (str, uri->query, NULL, pre_encoded);
	}
	if (uri->fragment && !just_path) {
		g_string_append_c (str, '#');
-		append_uri_encoded (str, uri->fragment, NULL);
+		append_uri (str, uri->fragment, NULL, pre_encoded);
	}

	return_result = str->str;
@@ -325,6 +337,8 @@
	dup->path     = g_strdup (uri->path);
	dup->query    = g_strdup (uri->query);
	dup->fragment = g_strdup (uri->fragment);
+
+	dup->broken_encoding = uri->broken_encoding;

	return dup;
}
Index: libsoup/soup-uri.h
===================================================================
RCS file: /cvs/gnome/libsoup/libsoup/soup-uri.h,v
retrieving revision 1.17
diff -u -r1.17 soup-uri.h
--- libsoup/soup-uri.h	10 Sep 2003 21:39:06 -0000	1.17
+++ libsoup/soup-uri.h	2 Aug 2004 17:20:28 -0000
@@ -28,6 +28,9 @@
	char         *query;

	char         *fragment;
+
+	/* Don't use this */
+	gboolean      broken_encoding;
};

SoupUri  *soup_uri_new_with_base     (const SoupUri *base,





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