libsoup r1228 - in branches/gnome-2-24: . docs/reference libsoup tests



Author: danw
Date: Mon Jan 12 22:36:48 2009
New Revision: 1228
URL: http://svn.gnome.org/viewvc/libsoup?rev=1228&view=rev

Log:
pull-ups from trunk


Modified:
   branches/gnome-2-24/   (props changed)
   branches/gnome-2-24/ChangeLog
   branches/gnome-2-24/docs/reference/client-howto.xml
   branches/gnome-2-24/gtk-doc.make
   branches/gnome-2-24/libsoup/soup-auth-manager.c
   branches/gnome-2-24/libsoup/soup-cookie-jar.c
   branches/gnome-2-24/libsoup/soup-form.c
   branches/gnome-2-24/libsoup/soup-message-headers.c
   branches/gnome-2-24/libsoup/soup-server.c
   branches/gnome-2-24/tests/auth-test.c

Modified: branches/gnome-2-24/docs/reference/client-howto.xml
==============================================================================
--- branches/gnome-2-24/docs/reference/client-howto.xml	(original)
+++ branches/gnome-2-24/docs/reference/client-howto.xml	Mon Jan 12 22:36:48 2009
@@ -178,7 +178,7 @@
 <informalexample><programlisting>
 	guint status;
 
-	status = soup_session_send (session, msg);
+	status = soup_session_send_message (session, msg);
 </programlisting></informalexample>
 
 <para>

Modified: branches/gnome-2-24/gtk-doc.make
==============================================================================
--- branches/gnome-2-24/gtk-doc.make	(original)
+++ branches/gnome-2-24/gtk-doc.make	Mon Jan 12 22:36:48 2009
@@ -7,9 +7,11 @@
 if GTK_DOC_USE_LIBTOOL
 GTKDOC_CC = $(LIBTOOL) --mode=compile $(CC) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 GTKDOC_LD = $(LIBTOOL) --mode=link $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS)
+GTKDOC_RUN = $(LIBTOOL) --mode=execute
 else
 GTKDOC_CC = $(CC) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 GTKDOC_LD = $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS)
+GTKDOC_RUN = sh -c
 endif
 
 # We set GPATH here; this gives us semantics for GNU make
@@ -53,6 +55,8 @@
 
 docs: html-build.stamp
 
+$(REPORT_FILES): sgml-build.stamp
+
 #### scan ####
 
 scan-build.stamp: $(HFILE_GLOB) $(CFILE_GLOB)
@@ -61,7 +65,7 @@
 	cd $(srcdir) && \
 	  gtkdoc-scan --module=$(DOC_MODULE) --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="$(IGNORE_HFILES)" $(SCAN_OPTIONS) $(EXTRA_HFILES)
 	if grep -l '^..*$$' $(srcdir)/$(DOC_MODULE).types > /dev/null 2>&1 ; then \
-	    CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" CFLAGS="$(GTKDOC_CFLAGS)" LDFLAGS="$(GTKDOC_LIBS)" gtkdoc-scangobj $(SCANGOBJ_OPTIONS) --module=$(DOC_MODULE) --output-dir=$(srcdir) ; \
+	    CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" RUN="$(GTKDOC_RUN)" CFLAGS="$(GTKDOC_CFLAGS) $(CFLAGS)" LDFLAGS="$(GTKDOC_LIBS) $(LDFLAGS)" gtkdoc-scangobj $(SCANGOBJ_OPTIONS) --module=$(DOC_MODULE) --output-dir=$(srcdir) ; \
 	else \
 	    cd $(srcdir) ; \
 	    for i in $(SCANOBJ_FILES) ; do \
@@ -107,7 +111,12 @@
 	@-chmod -R u+w $(srcdir)
 	rm -rf $(srcdir)/html
 	mkdir $(srcdir)/html
-	cd $(srcdir)/html && gtkdoc-mkhtml $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE)
+	mkhtml_options=""; \
+	gtkdoc-mkhtml 2>&1 --help | grep  >/dev/null "\-\-path"; \
+	if test "$(?)" = "0"; then \
+	  mkhtml_options=--path="$(srcdir)"; \
+	fi
+	cd $(srcdir)/html && gtkdoc-mkhtml $(mkhtml_options) $(MKHTML_OPTIONS) $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE)
 	test "x$(HTML_IMAGES)" = "x" || ( cd $(srcdir) && cp $(HTML_IMAGES) html )
 	@echo 'gtk-doc: Fixing cross-references'
 	cd $(srcdir) && gtkdoc-fixxref --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS)
@@ -128,24 +137,37 @@
 	cd $(srcdir) && rm -rf xml html
 
 install-data-local:
-	-installfiles=`echo $(srcdir)/html/*`; \
+	installfiles=`echo $(srcdir)/html/*`; \
 	if test "$$installfiles" = '$(srcdir)/html/*'; \
 	then echo '-- Nothing to install' ; \
 	else \
-	  $(mkinstalldirs) $(DESTDIR)$(TARGET_DIR); \
+	  if test -n "$(DOC_MODULE_VERSION)"; then \
+	    installdir="$(DESTDIR)$(TARGET_DIR)-$(DOC_MODULE_VERSION)"; \
+	  else \
+	    installdir="$(DESTDIR)$(TARGET_DIR)"; \
+	  fi; \
+	  $(mkinstalldirs) $${installdir} ; \
 	  for i in $$installfiles; do \
 	    echo '-- Installing '$$i ; \
-	    $(INSTALL_DATA) $$i $(DESTDIR)$(TARGET_DIR); \
+	    $(INSTALL_DATA) $$i $${installdir}; \
 	  done; \
-	  echo '-- Installing $(srcdir)/html/index.sgml' ; \
-	  $(INSTALL_DATA) $(srcdir)/html/index.sgml $(DESTDIR)$(TARGET_DIR) || :; \
-	  which gtkdoc-rebase >/dev/null && \
-	    gtkdoc-rebase --relative --dest-dir=$(DESTDIR) --html-dir=$(DESTDIR)$(TARGET_DIR) ; \
+	  if test -n "$(DOC_MODULE_VERSION)"; then \
+	    mv -f $${installdir}/$(DOC_MODULE).devhelp2 \
+	      $${installdir}/$(DOC_MODULE)-$(DOC_MODULE_VERSION).devhelp2; \
+	    mv -f $${installdir}/$(DOC_MODULE).devhelp \
+	      $${installdir}/$(DOC_MODULE)-$(DOC_MODULE_VERSION).devhelp; \
+	  fi; \
+	  ! which gtkdoc-rebase >/dev/null 2>&1 || \
+	    gtkdoc-rebase --relative --dest-dir=$(DESTDIR) --html-dir=$${installdir} ; \
 	fi
-	
 
 uninstall-local:
-	rm -f $(DESTDIR)$(TARGET_DIR)/*
+	if test -n "$(DOC_MODULE_VERSION)"; then \
+	  installdir="$(DESTDIR)$(TARGET_DIR)-$(DOC_MODULE_VERSION)"; \
+	else \
+	  installdir="$(DESTDIR)$(TARGET_DIR)"; \
+	fi; \
+	rm -rf $${installdir}
 
 #
 # Require gtk-doc when making dist
@@ -168,6 +190,7 @@
 	-cp $(srcdir)/$(DOC_MODULE).types $(distdir)/
 	-cp $(srcdir)/$(DOC_MODULE)-sections.txt $(distdir)/
 	cd $(distdir) && rm -f $(DISTCLEANFILES)
-	-gtkdoc-rebase --online --relative --html-dir=$(distdir)/html
+	! which gtkdoc-rebase >/dev/null 2>&1 || \
+	  gtkdoc-rebase --online --relative --html-dir=$(distdir)/html
 
 .PHONY : dist-hook-local docs

Modified: branches/gnome-2-24/libsoup/soup-auth-manager.c
==============================================================================
--- branches/gnome-2-24/libsoup/soup-auth-manager.c	(original)
+++ branches/gnome-2-24/libsoup/soup-auth-manager.c	Mon Jan 12 22:36:48 2009
@@ -150,7 +150,7 @@
 	SoupAuthClass **auth1 = (SoupAuthClass **)a;
 	SoupAuthClass **auth2 = (SoupAuthClass **)b;
 
-	return (*auth2)->strength - (*auth1)->strength;
+	return (*auth1)->strength - (*auth2)->strength;
 }
 
 void

Modified: branches/gnome-2-24/libsoup/soup-cookie-jar.c
==============================================================================
--- branches/gnome-2-24/libsoup/soup-cookie-jar.c	(original)
+++ branches/gnome-2-24/libsoup/soup-cookie-jar.c	Mon Jan 12 22:36:48 2009
@@ -299,9 +299,12 @@
 	char *cookies;
 
 	cookies = soup_cookie_jar_get_cookies (jar, soup_message_get_uri (msg), TRUE);
-	soup_message_headers_replace (msg->request_headers,
-				      "Cookie", cookies);
-	g_free (cookies);
+	if (cookies) {
+		soup_message_headers_replace (msg->request_headers,
+					      "Cookie", cookies);
+		g_free (cookies);
+	} else
+		soup_message_headers_remove (msg->request_headers, "Cookie");
 }
 
 static void

Modified: branches/gnome-2-24/libsoup/soup-form.c
==============================================================================
--- branches/gnome-2-24/libsoup/soup-form.c	(original)
+++ branches/gnome-2-24/libsoup/soup-form.c	Mon Jan 12 22:36:48 2009
@@ -63,15 +63,15 @@
 	for (i = 0; pairs[i]; i++) {
 		name = pairs[i];
 		eq = strchr (name, '=');
-		if (!form_decode (name)) {
-			g_free (name);
-			continue;
-		}
 		if (eq) {
 			*eq = '\0';
 			value = eq + 1;
 		} else
 			value = NULL;
+		if (!form_decode (name) || (value && !form_decode (value))) {
+			g_free (name);
+			continue;
+		}
 
 		g_hash_table_insert (form_data_set, name, value);
 	}

Modified: branches/gnome-2-24/libsoup/soup-message-headers.c
==============================================================================
--- branches/gnome-2-24/libsoup/soup-message-headers.c	(original)
+++ branches/gnome-2-24/libsoup/soup-message-headers.c	Mon Jan 12 22:36:48 2009
@@ -150,6 +150,9 @@
 	SoupHeader header;
 	SoupHeaderSetter setter;
 
+	g_return_if_fail (name != NULL);
+	g_return_if_fail (value != NULL);
+
 	header.name = intern_header_name (name, &setter);
 	header.value = g_strdup (value);
 	g_array_append_val (hdrs->array, header);
@@ -204,6 +207,8 @@
 	SoupHeaderSetter setter;
 	int index;
 
+	g_return_if_fail (name != NULL);
+
 	name = intern_header_name (name, &setter);
 	while ((index = find_header (hdr_array, name, 0)) != -1) {
 		g_free (hdr_array[index].value);
@@ -238,6 +243,8 @@
 	char *value;
 	int index, i;
 
+	g_return_val_if_fail (name != NULL, NULL);
+
 	name = intern_header_name (name, NULL);
 	if (hdrs->concat) {
 		value = g_hash_table_lookup (hdrs->concat, name);

Modified: branches/gnome-2-24/libsoup/soup-server.c
==============================================================================
--- branches/gnome-2-24/libsoup/soup-server.c	(original)
+++ branches/gnome-2-24/libsoup/soup-server.c	Mon Jan 12 22:36:48 2009
@@ -1251,7 +1251,7 @@
 	g_return_if_fail (SOUP_IS_SERVER (server));
 	priv = SOUP_SERVER_GET_PRIVATE (server);
 
-	priv->auth_domains = g_slist_prepend (priv->auth_domains, auth_domain);
+	priv->auth_domains = g_slist_append (priv->auth_domains, auth_domain);
 	g_object_ref (auth_domain);
 }
 

Modified: branches/gnome-2-24/tests/auth-test.c
==============================================================================
--- branches/gnome-2-24/tests/auth-test.c	(original)
+++ branches/gnome-2-24/tests/auth-test.c	Mon Jan 12 22:36:48 2009
@@ -543,6 +543,215 @@
 	g_free (uri);
 }
 
+typedef struct {
+	const char *password;
+	struct {
+		const char *headers;
+		const char *response;
+	} round[2];
+} SelectAuthData;
+
+static void
+select_auth_authenticate (SoupSession *session, SoupMessage *msg,
+			  SoupAuth *auth, gboolean retrying, gpointer data)
+{
+	SelectAuthData *sad = data;
+	const char *header, *basic, *digest;
+	int round = retrying ? 1 : 0;
+
+	header = soup_message_headers_get (msg->response_headers, "WWW-Authenticate");
+	basic = strstr (header, "Basic");
+	digest = strstr (header, "Digest");
+	if (basic && digest) {
+		if (basic < digest)
+			sad->round[round].headers = "Basic, Digest";
+		else
+			sad->round[round].headers = "Digest, Basic";
+	} else if (basic)
+		sad->round[round].headers = "Basic";
+	else if (digest)
+		sad->round[round].headers = "Digest";
+
+	sad->round[round].response = soup_auth_get_scheme_name (auth);
+	if (sad->password && !retrying)
+		soup_auth_authenticate (auth, "user", sad->password);
+}
+
+static void
+select_auth_test_one (SoupURI *uri, const char *password,
+		      const char *first_headers, const char *first_response,
+		      const char *second_headers, const char *second_response,
+		      guint final_status)
+{
+	SelectAuthData sad;
+	SoupMessage *msg;
+	SoupSession *session;
+
+	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+	g_signal_connect (session, "authenticate",
+			  G_CALLBACK (select_auth_authenticate), &sad);
+	memset (&sad, 0, sizeof (sad));
+	sad.password = password;
+
+	msg = soup_message_new_from_uri ("GET", uri);
+	soup_session_send_message (session, msg);
+
+	if (strcmp (sad.round[0].headers, first_headers) != 0) {
+		debug_printf (1, "    Header order wrong: expected %s, got %s\n",
+			      first_headers, sad.round[0].headers);
+		errors++;
+	}
+	if (strcmp (sad.round[0].response, first_response) != 0) {
+		debug_printf (1, "    Selected auth type wrong: expected %s, got %s\n",
+			      first_response, sad.round[0].response);
+		errors++;
+	}
+
+	if (second_headers && !sad.round[1].headers) {
+		debug_printf (1, "    Expected a second round!\n");
+		errors++;
+	} else if (!second_headers && sad.round[1].headers) {
+		debug_printf (1, "    Didn't expect a second round!\n");
+		errors++;
+	} else if (second_headers) {
+		if (strcmp (sad.round[1].headers, second_headers) != 0) {
+			debug_printf (1, "    Second round header order wrong: expected %s, got %s\n",
+				      second_headers, sad.round[1].headers);
+			errors++;
+		}
+		if (strcmp (sad.round[1].response, second_response) != 0) {
+			debug_printf (1, "    Second round selected auth type wrong: expected %s, got %s\n",
+				      second_response, sad.round[1].response);
+			errors++;
+		}
+	}
+
+	if (msg->status_code != final_status) {
+		debug_printf (1, "    Final status wrong: expected %u, got %u\n",
+			      final_status, msg->status_code);
+		errors++;
+	}
+
+	g_object_unref (msg);
+	soup_test_session_abort_unref (session);
+}
+
+static void
+server_callback (SoupServer *server, SoupMessage *msg,
+		 const char *path, GHashTable *query,
+		 SoupClientContext *context, gpointer data)
+{
+	soup_message_set_response (msg, "text/plain",
+				   SOUP_MEMORY_STATIC,
+				   "OK\r\n", 4);
+	soup_message_set_status (msg, SOUP_STATUS_OK);
+}
+
+static gboolean
+server_basic_auth_callback (SoupAuthDomain *auth_domain, SoupMessage *msg,
+			    const char *username, const char *password, gpointer data)
+{
+	return FALSE;
+}
+
+static char *
+server_digest_auth_callback (SoupAuthDomain *auth_domain, SoupMessage *msg,
+			     const char *username, gpointer data)
+{
+	if (strcmp (username, "user") != 0)
+		return NULL;
+	return soup_auth_domain_digest_encode_password ("user",
+							"auth-test",
+							"good");
+}
+
+static void
+do_select_auth_test (void)
+{
+	SoupServer *server;
+	SoupAuthDomain *basic_auth_domain, *digest_auth_domain;
+	SoupURI *uri;
+
+	debug_printf (1, "\nTesting selection among multiple auths:\n");
+
+	/* It doesn't seem to be possible to configure Apache to serve
+	 * multiple auth types for a single URL. So we have to use
+	 * SoupServer here. We know that SoupServer handles the server
+	 * side of this scenario correctly, because we test it against
+	 * curl in server-auth-test.
+	 */
+	server = soup_test_server_new (FALSE);
+	soup_server_add_handler (server, NULL,
+				 server_callback, NULL, NULL);
+
+	uri = soup_uri_new ("http://localhost/";);
+	soup_uri_set_port (uri, soup_server_get_port (server));
+
+	basic_auth_domain = soup_auth_domain_basic_new (
+		SOUP_AUTH_DOMAIN_REALM, "auth-test",
+		SOUP_AUTH_DOMAIN_ADD_PATH, "/",
+		SOUP_AUTH_DOMAIN_BASIC_AUTH_CALLBACK, server_basic_auth_callback,
+		NULL);
+	soup_server_add_auth_domain (server, basic_auth_domain);
+
+	digest_auth_domain = soup_auth_domain_digest_new (
+		SOUP_AUTH_DOMAIN_REALM, "auth-test",
+		SOUP_AUTH_DOMAIN_ADD_PATH, "/",
+		SOUP_AUTH_DOMAIN_DIGEST_AUTH_CALLBACK, server_digest_auth_callback,
+		NULL);
+	soup_server_add_auth_domain (server, digest_auth_domain);
+
+	/* FIXME: when we support disabling auth types in the session,
+	 * test that too.
+	 */
+
+	debug_printf (1, "  Testing with no auth\n");
+	select_auth_test_one (uri, NULL,
+			      "Basic, Digest", "Digest",
+			      NULL, NULL,
+			      SOUP_STATUS_UNAUTHORIZED);
+
+	debug_printf (1, "  Testing with bad password\n");
+	select_auth_test_one (uri, "bad",
+			      "Basic, Digest", "Digest",
+			      "Basic, Digest", "Digest",
+			      SOUP_STATUS_UNAUTHORIZED);
+
+	debug_printf (1, "  Testing with good password\n");
+	select_auth_test_one (uri, "good",
+			      "Basic, Digest", "Digest",
+			      NULL, NULL,
+			      SOUP_STATUS_OK);
+
+	/* Now flip the order of the domains, verify that this flips
+	 * the order of the headers, and make sure that digest auth
+	 * *still* gets used.
+	 */
+
+	soup_server_remove_auth_domain (server, basic_auth_domain);
+	soup_server_remove_auth_domain (server, digest_auth_domain);
+	soup_server_add_auth_domain (server, digest_auth_domain);
+	soup_server_add_auth_domain (server, basic_auth_domain);
+
+	debug_printf (1, "  Testing flipped with no auth\n");
+	select_auth_test_one (uri, NULL,
+			      "Digest, Basic", "Digest",
+			      NULL, NULL,
+			      SOUP_STATUS_UNAUTHORIZED);
+
+	debug_printf (1, "  Testing flipped with bad password\n");
+	select_auth_test_one (uri, "bad",
+			      "Digest, Basic", "Digest",
+			      "Digest, Basic", "Digest",
+			      SOUP_STATUS_UNAUTHORIZED);
+
+	debug_printf (1, "  Testing flipped with good password\n");
+	select_auth_test_one (uri, "good",
+			      "Digest, Basic", "Digest",
+			      NULL, NULL,
+			      SOUP_STATUS_OK);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -727,6 +936,9 @@
 	/* Async auth */
 	do_async_auth_test (base_uri);
 
+	/* Selecting correct auth when multiple auth types are available */
+	do_select_auth_test ();
+
 	g_main_loop_unref (loop);
 
 	test_cleanup ();



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