Re: problem with SoupContexts

Diego González <[email protected]> 31 Aug 2002 22:42:12 +0200
Newsgroups gmane.comp.gnome.ximian.soup
Message-ID <1030826561.29067.4.camel@helios>
On Sat, 2002-08-31 at 21:08, Joe Shaw wrote:
> 
> Soup caches authentication information so it can be sent without having
> to make an extra round trip.  It looks like it only does it on a
> per-path basis, though, and doesn't take into account the username and
> password.  I presume you're using Basic authentication?  It's probably
> just as simple as changing soup_auth_lookup(), soup_auth_invalidate(),
> and soup_auth_set_context() to do path + username + password instead of
> just path.

ok, here is a patch that seems to work
soup-auth.diff (text/x-patch, 2.6 KB)
Index: soup-auth.c
===================================================================
RCS file: /cvs/gnome/soup/src/libsoup/soup-auth.c,v
retrieving revision 1.16.2.2.2.7
diff -u -r1.16.2.2.2.7 soup-auth.c
--- soup-auth.c	7 Aug 2002 22:19:31 -0000	1.16.2.2.2.7
+++ soup-auth.c	31 Aug 2002 20:42:45 -0000
@@ -578,11 +578,17 @@
 {
 	GHashTable *auth_hash = ctx->server->valid_auths;
 	SoupAuth *ret = NULL;
+	const SoupUri *uri = NULL;
 	gchar *mypath, *dir;
 
-	if (!auth_hash) return NULL;
+	if (!auth_hash)  {
+		return NULL;
+	}
 
-	mypath = g_strdup (ctx->uri->path);
+/*	mypath = g_strdup (ctx->uri->path);*/
+	uri = soup_context_get_uri (ctx);
+	
+	mypath = g_strconcat (uri->user, ":", uri->passwd, ":", uri->path, NULL);
 	dir = mypath;
 
         do {
@@ -603,11 +609,13 @@
 	SoupHost *server;
 	const SoupUri *uri;
 	SoupAuth *old_auth;
-	char *old_path;
+	char *old_url, *new_url;
 
 	g_return_if_fail (ctx != NULL);
 	g_return_if_fail (auth != NULL);
 
+	new_url = g_strconcat (uri->user, ":", uri->passwd, ":", uri->path, NULL);
+
 	server = ctx->server;
 
 	if (!server->valid_auths)
@@ -615,13 +623,15 @@
 
 	uri = soup_context_get_uri (ctx);
 	if (g_hash_table_lookup_extended (server->valid_auths,
-					  uri->path,
-					  (gpointer *) &old_path,
+					  new_url,
+					  (gpointer *) &old_url,
 					  (gpointer *) &old_auth)) {
-		g_hash_table_remove (server->valid_auths, old_path);
-		g_free (old_path);
+		g_hash_table_remove (server->valid_auths, old_url);
+		g_free (old_url);
 		soup_auth_free (old_auth);
 	}
+
+	g_free (new_url);
 }
 
 void
@@ -629,8 +639,9 @@
 {
 	SoupHost *server;
 	SoupAuth *old_auth = NULL;
-	gchar *old_path;
+	gchar *old_url;
 	const SoupUri *uri;
+	gchar *new_url;
 
 	g_return_if_fail (ctx != NULL);
 	g_return_if_fail (auth != NULL);
@@ -638,24 +649,26 @@
 	server = ctx->server;
 	uri = soup_context_get_uri (ctx);
 
+	new_url = g_strconcat (uri->user, ":", uri->passwd, ":", uri->path, NULL);
+
 	if (!server->valid_auths) {
 		server->valid_auths = g_hash_table_new (g_str_hash, 
 							g_str_equal);
 	}
 	else if (g_hash_table_lookup_extended (server->valid_auths, 
-					       uri->path,
-					       (gpointer *) &old_path,
+					       new_url,
+					       (gpointer *) &old_url,
 					       (gpointer *) &old_auth)) {
 		if (auth == old_auth)
 			return;
 
-		g_hash_table_remove (server->valid_auths, old_path);
-		g_free (old_path);
+		g_hash_table_remove (server->valid_auths, old_url);
+		g_free (old_url);
 		soup_auth_free (old_auth);
 	}
 
 	g_hash_table_insert (server->valid_auths,
-			     g_strdup (uri->path),
+			     new_url,
 			     auth);
 }
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQA9cSokVdTYZHL1xEIRAt2TAJ9SFCXzy0dhmBh7NxfDzcHUXY9E2wCfQjEH
bw9enfJCQTnzVP6R0eign+E=
=mMlO
-----END PGP SIGNATURE-----