libsoup r1063 - in trunk: . libsoup tests
- From: danw svn gnome org
- To: svn-commits-list gnome org
- Subject: libsoup r1063 - in trunk: . libsoup tests
- Date: Fri, 1 Feb 2008 15:23:32 +0000 (GMT)
Author: danw
Date: Fri Feb 1 15:23:31 2008
New Revision: 1063
URL: http://svn.gnome.org/viewvc/libsoup?rev=1063&view=rev
Log:
* libsoup/soup-date.c (soup_date_to_time_t): new
* libsoup/soup-form.c (soup_form_decode): Remove "_urlencoded"
from name. (And add back-compat #define.)
(soup_form_encode): New, takes varargs parameters for each form
construction.
(soup_form_encode_hash, soup_form_encode_datalist): renamed, with
back-compat #defines
(soup_form_request_new, soup_form_request_new_from_hash)
(soup_form_request_new_from_datalist): New methods to construct a
GET or POST message with form data.
* libsoup/soup-uri.c (soup_uri_set_query_from_fields): New, takes
varargs like soup_form_encode().
* libsoup/soup-value-utils.c (soup_value_hash_new_with_vals)
(soup_value_hash_insert_vals, soup_value_hash_lookup_vals): New
routines to work with multiple value hash values at once.
(soup_value_array_new): tiny wrapper, for naming consistency
(soup_value_array_new_with_vals, soup_value_array_append_vals):
New routines to work with multiple value array values at once.
Modified:
trunk/ChangeLog
trunk/gtk-doc.make
trunk/libsoup/soup-date.c
trunk/libsoup/soup-date.h
trunk/libsoup/soup-form.c
trunk/libsoup/soup-form.h
trunk/libsoup/soup-uri.c
trunk/libsoup/soup-uri.h
trunk/libsoup/soup-value-utils.c
trunk/libsoup/soup-value-utils.h
trunk/tests/Makefile.am
trunk/tests/query-test.c
Modified: trunk/gtk-doc.make
==============================================================================
--- trunk/gtk-doc.make (original)
+++ trunk/gtk-doc.make Fri Feb 1 15:23:31 2008
@@ -5,11 +5,11 @@
####################################
if GTK_DOC_USE_LIBTOOL
-GTKDOC_CC = $(LIBTOOL) --mode=compile $(CC) $(INCLUDES) $(AM_CFLAGS) $(CFLAGS)
-GTKDOC_LD = $(LIBTOOL) --mode=link $(CC) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS)
+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)
else
-GTKDOC_CC = $(CC) $(INCLUDES) $(AM_CFLAGS) $(CFLAGS)
-GTKDOC_LD = $(CC) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS)
+GTKDOC_CC = $(CC) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+GTKDOC_LD = $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS)
endif
# We set GPATH here; this gives us semantics for GNU make
@@ -38,7 +38,12 @@
$(DOC_MODULE).prerequisites \
$(DOC_MODULE).signals
-CLEANFILES = $(SCANOBJ_FILES) $(DOC_MODULE)-unused.txt $(DOC_STAMPS)
+REPORT_FILES = \
+ $(DOC_MODULE)-undocumented.txt \
+ $(DOC_MODULE)-undeclared.txt \
+ $(DOC_MODULE)-unused.txt
+
+CLEANFILES = $(SCANOBJ_FILES) $(REPORT_FILES) $(DOC_STAMPS)
if ENABLE_GTK_DOC
all-local: html-build.stamp
@@ -79,6 +84,10 @@
tmpl.stamp: tmpl-build.stamp
@true
+tmpl/*.sgml:
+ @true
+
+
#### xml ####
sgml-build.stamp: tmpl.stamp $(HFILE_GLOB) $(CFILE_GLOB) $(DOC_MODULE)-sections.txt $(srcdir)/tmpl/*.sgml $(expand_content_files)
@@ -96,11 +105,11 @@
html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files)
@echo 'gtk-doc: Building HTML'
@-chmod -R u+w $(srcdir)
- rm -rf $(srcdir)/html
+ rm -rf $(srcdir)/html
mkdir $(srcdir)/html
cd $(srcdir)/html && gtkdoc-mkhtml $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE)
test "x$(HTML_IMAGES)" = "x" || ( cd $(srcdir) && cp $(HTML_IMAGES) html )
- @echo 'gtk-doc: Fixing cross-references'
+ @echo 'gtk-doc: Fixing cross-references'
cd $(srcdir) && gtkdoc-fixxref --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS)
touch html-build.stamp
@@ -110,11 +119,16 @@
rm -f *~ *.bak
rm -rf .libs
+distclean-local:
+ cd $(srcdir) && \
+ rm -rf xml $(REPORT_FILES) \
+ $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
+
maintainer-clean-local: clean
- cd $(srcdir) && rm -rf xml html $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
+ 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 \
@@ -125,7 +139,10 @@
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) ; \
fi
+
uninstall-local:
rm -f $(DESTDIR)$(TARGET_DIR)/*
@@ -148,8 +165,9 @@
-cp $(srcdir)/tmpl/*.sgml $(distdir)/tmpl
-cp $(srcdir)/xml/*.xml $(distdir)/xml
cp $(srcdir)/html/* $(distdir)/html
- if test -f $(srcdir)/$(DOC_MODULE).types; then \
- cp $(srcdir)/$(DOC_MODULE).types $(distdir)/$(DOC_MODULE).types; \
- fi
+ -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
.PHONY : dist-hook-local docs
Modified: trunk/libsoup/soup-date.c
==============================================================================
--- trunk/libsoup/soup-date.c (original)
+++ trunk/libsoup/soup-date.c Fri Feb 1 15:23:31 2008
@@ -497,6 +497,57 @@
}
/**
+ * soup_date_to_time_t:
+ * @date: a #SoupDate
+ *
+ * Converts @date to a %time_t
+ *
+ * Return value: @date as a %time_t
+ **/
+time_t
+soup_date_to_time_t (SoupDate *date)
+{
+#ifndef HAVE_TIMEGM
+ time_t tt;
+ static const int days_before[] = {
+ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
+ };
+#endif
+ struct tm tm;
+
+ /* FIXME: offset, etc */
+
+ tm.tm_year = date->year - 1900;
+ tm.tm_mon = date->month - 1;
+ tm.tm_mday = date->day;
+ tm.tm_hour = date->hour;
+ tm.tm_min = date->minute;
+ tm.tm_sec = date->second;
+
+#if HAVE_TIMEGM
+ return timegm (&tm);
+#else
+ /* We check the month because (a) if we don't, the
+ * days_before[] part below may access random memory, and (b)
+ * soup_date_parse() doesn't check the return value of
+ * parse_month(). The caller is responsible for ensuring the
+ * sanity of everything else.
+ */
+ if (tm.tm_mon < 0 || tm.tm_mon > 11)
+ return (time_t)-1;
+
+ tt = (tm.tm_year - 70) * 365;
+ tt += (tm.tm_year - 68) / 4;
+ tt += days_before[tm.tm_mon] + tm.tm_mday - 1;
+ if (tm.tm_year % 4 == 0 && tm.tm_mon < 2)
+ tt--;
+ tt = ((((tt * 24) + tm.tm_hour) * 60) + tm.tm_min) * 60 + tm.tm_sec;
+
+ return tt;
+#endif
+}
+
+/**
* soup_date_copy:
* @date: a #SoupDate
*
Modified: trunk/libsoup/soup-date.h
==============================================================================
--- trunk/libsoup/soup-date.h (original)
+++ trunk/libsoup/soup-date.h Fri Feb 1 15:23:31 2008
@@ -50,6 +50,8 @@
char *soup_date_to_string (SoupDate *date,
SoupDateFormat format);
+time_t soup_date_to_time_t (SoupDate *date);
+
SoupDate *soup_date_copy (SoupDate *date);
void soup_date_free (SoupDate *date);
Modified: trunk/libsoup/soup-form.c
==============================================================================
--- trunk/libsoup/soup-form.c (original)
+++ trunk/libsoup/soup-form.c Fri Feb 1 15:23:31 2008
@@ -12,6 +12,8 @@
#include <string.h>
#include "soup-form.h"
+#include "soup-message.h"
+#include "soup-uri.h"
#define XDIGIT(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10)
#define HEXCHAR(s) ((XDIGIT (s[1]) << 4) + XDIGIT (s[2]))
@@ -39,7 +41,7 @@
}
/**
- * soup_form_decode_urlencoded:
+ * soup_form_decode:
* @encoded_form: data of type "application/x-www-form-urlencoded"
*
* Decodes @form, which is an urlencoded dataset as defined in the
@@ -49,7 +51,7 @@
* @encoded_form, which you can free with g_hash_table_destroy().
**/
GHashTable *
-soup_form_decode_urlencoded (const char *encoded_form)
+soup_form_decode (const char *encoded_form)
{
GHashTable *form_data_set;
char **pairs, *eq, *name, *value;
@@ -111,23 +113,52 @@
}
/**
- * soup_form_encode_urlencoded:
- * @form_data_set: a hash table containing name/value pairs
+ * soup_form_encode:
+ * @first_field: name of the first form field
+ * @...: value of @first_field, followed by additional field names
+ * and values, terminated by %NULL.
+ *
+ * Encodes the given field names and values into a value of type
+ * "application/x-www-form-urlencoded", as defined in the HTML 4.01
+ * spec.
+ *
+ * This method requires you to know the names of the form fields (or
+ * at the very least, the total number of fields) at compile time; for
+ * working with dynamic forms, use soup_form_encode_hash() or
+ * soup_form_encode_datalist().
+ *
+ * Return value: the encoded form
+ **/
+char *
+soup_form_encode (const char *first_field, ...)
+{
+ va_list args;
+ char *encoded;
+
+ va_start (args, first_field);
+ encoded = soup_form_encode_valist (first_field, args);
+ va_end (args);
+
+ return encoded;
+}
+
+/**
+ * soup_form_encode_hash:
+ * @form_data_set: a hash table containing name/value pairs (as strings)
*
* Encodes @form_data_set into a value of type
* "application/x-www-form-urlencoded", as defined in the HTML 4.01
* spec.
*
- * Note that the spec states that "The control names/values are listed
- * in the order they appear in the document." Since
- * soup_form_encode_urlencoded() takes a hash table, this cannot be
- * enforced; if you care about the ordering of the form fields, use
- * soup_form_encode_urlencoded_list().
+ * Note that the HTML spec states that "The control names/values are
+ * listed in the order they appear in the document." Since this method
+ * takes a hash table, it cannot enforce that; if you care about the
+ * ordering of the form fields, use soup_form_encode_datalist().
*
* Return value: the encoded form
**/
char *
-soup_form_encode_urlencoded (GHashTable *form_data_set)
+soup_form_encode_hash (GHashTable *form_data_set)
{
GString *str = g_string_new (NULL);
@@ -142,22 +173,153 @@
}
/**
- * soup_form_encode_urlencoded_list:
- * @form_data_set: a hash table containing name/value pairs
+ * soup_form_encode_datalist:
+ * @form_data_set: a datalist containing name/value pairs
*
* Encodes @form_data_set into a value of type
* "application/x-www-form-urlencoded", as defined in the HTML 4.01
- * spec. Unlike soup_form_encode_urlencoded(), this preserves the
- * ordering of the form elements, which may be required in some
- * situations.
+ * spec. Unlike soup_form_encode_hash(), this preserves the ordering
+ * of the form elements, which may be required in some situations.
*
* Return value: the encoded form
**/
char *
-soup_form_encode_urlencoded_list (GData **form_data_set)
+soup_form_encode_datalist (GData **form_data_set)
{
GString *str = g_string_new (NULL);
g_datalist_foreach (form_data_set, datalist_encode_foreach, str);
return g_string_free (str, FALSE);
}
+
+/**
+ * soup_form_encode_valist:
+ * @first_field: name of the first form field
+ * @args: pointer to additional values, as in soup_form_encode()
+ *
+ * See soup_form_encode(). This is mostly an internal method, used by
+ * various other methods such as soup_uri_set_query_from_fields() and
+ * soup_form_request_new().
+ *
+ * Return value: the encoded form
+ **/
+char *
+soup_form_encode_valist (const char *first_field, va_list args)
+{
+ GString *str = g_string_new (NULL);
+ const char *name, *value;
+
+ name = first_field;
+ value = va_arg (args, const char *);
+ while (name && value) {
+ encode_pair (str, name, value);
+
+ name = va_arg (args, const char *);
+ if (name)
+ value = va_arg (args, const char *);
+ }
+
+ return g_string_free (str, FALSE);
+}
+
+static SoupMessage *
+soup_form_request_for_data (const char *method, const char *uri_string,
+ char *form_data)
+{
+ SoupMessage *msg;
+ SoupURI *uri;
+
+ uri = soup_uri_new (uri_string);
+ if (!uri)
+ return NULL;
+
+ if (!strcmp (method, "GET")) {
+ g_free (uri->query);
+ uri->query = form_data;
+ form_data = NULL;
+ }
+
+ msg = soup_message_new_from_uri (method, uri);
+
+ if (!strcmp (method, "POST")) {
+ soup_message_set_request (
+ msg, "application/x-www-form-urlencoded",
+ SOUP_MEMORY_TAKE,
+ form_data, strlen (form_data));
+ form_data = NULL;
+ }
+
+ if (form_data) {
+ g_warning ("invalid method passed to soup_form_request_new");
+ g_free (form_data);
+ }
+
+ return msg;
+}
+
+/**
+ * soup_form_request_new:
+ * @method: the HTTP method, either "GET" or "POST"
+ * @uri: the URI to send the form data to
+ * @first_field: name of the first form field
+ * @...: value of @first_field, followed by additional field names
+ * and values, terminated by %NULL.
+ *
+ * Creates a new %SoupMessage and sets it up to send the given data
+ * to @uri via @method. (That is, if @method is "GET", it will encode
+ * the form data into @uri's query field, and if @method is "POST", it
+ * will encode it into the %SoupMessage's request_body.)
+ *
+ * Return value: the new %SoupMessage
+ **/
+SoupMessage *
+soup_form_request_new (const char *method, const char *uri,
+ const char *first_field, ...)
+{
+ va_list args;
+ char *form_data;
+
+ va_start (args, first_field);
+ form_data = soup_form_encode_valist (first_field, args);
+ va_end (args);
+
+ return soup_form_request_for_data (method, uri, form_data);
+}
+
+/**
+ * soup_form_request_new_from_hash:
+ * @method: the HTTP method, either "GET" or "POST"
+ * @uri: the URI to send the form data to
+ * @form_data_set: the data to send to @uri
+ *
+ * Creates a new %SoupMessage and sets it up to send @form_data_set to
+ * @uri via @method, as with soup_form_request_new().
+ *
+ * Return value: the new %SoupMessage
+ **/
+SoupMessage *
+soup_form_request_new_from_hash (const char *method, const char *uri,
+ GHashTable *form_data_set)
+{
+ return soup_form_request_for_data (
+ method, uri, soup_form_encode_hash (form_data_set));
+}
+
+/**
+ * soup_form_request_new_from_datalist:
+ * @method: the HTTP method, either "GET" or "POST"
+ * @uri: the URI to send the form data to
+ * @form_data_set: the data to send to @uri
+ *
+ * Creates a new %SoupMessage and sets it up to send @form_data_set to
+ * @uri via @method, as with soup_form_request_new().
+ *
+ * Return value: the new %SoupMessage
+ **/
+SoupMessage *
+soup_form_request_new_from_datalist (const char *method, const char *uri,
+ GData **form_data_set)
+{
+ return soup_form_request_for_data (
+ method, uri, soup_form_encode_datalist (form_data_set));
+}
Modified: trunk/libsoup/soup-form.h
==============================================================================
--- trunk/libsoup/soup-form.h (original)
+++ trunk/libsoup/soup-form.h Fri Feb 1 15:23:31 2008
@@ -10,10 +10,32 @@
G_BEGIN_DECLS
-GHashTable *soup_form_decode_urlencoded (const char *encoded_form);
+GHashTable *soup_form_decode (const char *encoded_form);
-char *soup_form_encode_urlencoded (GHashTable *form_data_set);
-char *soup_form_encode_urlencoded_list (GData **form_data_set);
+char *soup_form_encode (const char *first_field,
+ ...) G_GNUC_NULL_TERMINATED;
+char *soup_form_encode_hash (GHashTable *form_data_set);
+char *soup_form_encode_datalist (GData **form_data_set);
+char *soup_form_encode_valist (const char *first_field,
+ va_list args);
+
+#ifndef LIBSOUP_DISABLE_DEPRECATED
+/* Compatibility with libsoup 2.3.0 */
+#define soup_form_decode_urlencoded soup_form_decode
+#define soup_form_encode_urlencoded soup_form_encode_hash
+#define soup_form_encode_urlencoded_list soup_form_encode_datalist
+#endif
+
+SoupMessage *soup_form_request_new (const char *method,
+ const char *uri,
+ const char *first_field,
+ ...) G_GNUC_NULL_TERMINATED;
+SoupMessage *soup_form_request_new_from_hash (const char *method,
+ const char *uri,
+ GHashTable *form_data_set);
+SoupMessage *soup_form_request_new_from_datalist (const char *method,
+ const char *uri,
+ GData **form_data_set);
G_END_DECLS
Modified: trunk/libsoup/soup-uri.c
==============================================================================
--- trunk/libsoup/soup-uri.c (original)
+++ trunk/libsoup/soup-uri.c Fri Feb 1 15:23:31 2008
@@ -883,8 +883,7 @@
* @form: a #GHashTable containing HTML form information
*
* Sets @uri's query to the result of encoding @form according to the
- * HTML form rules. See soup_form_encode_urlencoded() for more
- * information.
+ * HTML form rules. See soup_form_encode_hash() for more information.
**/
void
soup_uri_set_query_from_form (SoupURI *uri, GHashTable *form)
@@ -894,6 +893,30 @@
}
/**
+ * soup_uri_set_query_from_fields:
+ * @uri: a #SoupURI
+ * @first_field: name of the first form field to encode into query
+ * @...: value of @first_field, followed by additional field names
+ * and values, terminated by %NULL.
+ *
+ * Sets @uri's query to the result of encoding the given form fields
+ * and values according to the * HTML form rules. See
+ * soup_form_encode() for more information.
+ **/
+void
+soup_uri_set_query_from_fields (SoupURI *uri,
+ const char *first_field,
+ ...)
+{
+ va_list args;
+
+ g_free (uri->query);
+ va_start (args, first_field);
+ uri->query = soup_form_encode_valist (first_field, args);
+ va_end (args);
+}
+
+/**
* soup_uri_set_fragment:
* @uri: a #SoupURI
* @fragment: the fragment
Modified: trunk/libsoup/soup-uri.h
==============================================================================
--- trunk/libsoup/soup-uri.h (original)
+++ trunk/libsoup/soup-uri.h Fri Feb 1 15:23:31 2008
@@ -33,46 +33,49 @@
#define SOUP_URI_SCHEME_HTTP (g_intern_static_string ("http"))
#define SOUP_URI_SCHEME_HTTPS (g_intern_static_string ("https"))
-SoupURI *soup_uri_new_with_base (SoupURI *base,
- const char *uri_string);
-SoupURI *soup_uri_new (const char *uri_string);
-
-char *soup_uri_to_string (SoupURI *uri,
- gboolean just_path_and_query);
-
-SoupURI *soup_uri_copy (SoupURI *uri);
-
-gboolean soup_uri_equal (SoupURI *uri1,
- SoupURI *uri2);
-
-void soup_uri_free (SoupURI *uri);
-
-char *soup_uri_encode (const char *part,
- const char *escape_extra);
-char *soup_uri_decode (const char *part);
-char *soup_uri_normalize (const char *part,
- const char *unescape_extra);
-
-gboolean soup_uri_uses_default_port (SoupURI *uri);
-
-void soup_uri_set_scheme (SoupURI *uri,
- const char *scheme);
-void soup_uri_set_user (SoupURI *uri,
- const char *user);
-void soup_uri_set_password (SoupURI *uri,
- const char *password);
-void soup_uri_set_host (SoupURI *uri,
- const char *host);
-void soup_uri_set_port (SoupURI *uri,
- guint port);
-void soup_uri_set_path (SoupURI *uri,
- const char *path);
-void soup_uri_set_query (SoupURI *uri,
- const char *query);
-void soup_uri_set_query_from_form (SoupURI *uri,
- GHashTable *form);
-void soup_uri_set_fragment (SoupURI *uri,
- const char *fragment);
+SoupURI *soup_uri_new_with_base (SoupURI *base,
+ const char *uri_string);
+SoupURI *soup_uri_new (const char *uri_string);
+
+char *soup_uri_to_string (SoupURI *uri,
+ gboolean just_path_and_query);
+
+SoupURI *soup_uri_copy (SoupURI *uri);
+
+gboolean soup_uri_equal (SoupURI *uri1,
+ SoupURI *uri2);
+
+void soup_uri_free (SoupURI *uri);
+
+char *soup_uri_encode (const char *part,
+ const char *escape_extra);
+char *soup_uri_decode (const char *part);
+char *soup_uri_normalize (const char *part,
+ const char *unescape_extra);
+
+gboolean soup_uri_uses_default_port (SoupURI *uri);
+
+void soup_uri_set_scheme (SoupURI *uri,
+ const char *scheme);
+void soup_uri_set_user (SoupURI *uri,
+ const char *user);
+void soup_uri_set_password (SoupURI *uri,
+ const char *password);
+void soup_uri_set_host (SoupURI *uri,
+ const char *host);
+void soup_uri_set_port (SoupURI *uri,
+ guint port);
+void soup_uri_set_path (SoupURI *uri,
+ const char *path);
+void soup_uri_set_query (SoupURI *uri,
+ const char *query);
+void soup_uri_set_query_from_form (SoupURI *uri,
+ GHashTable *form);
+void soup_uri_set_query_from_fields (SoupURI *uri,
+ const char *first_field,
+ ...);
+void soup_uri_set_fragment (SoupURI *uri,
+ const char *fragment);
G_END_DECLS
Modified: trunk/libsoup/soup-value-utils.c
==============================================================================
--- trunk/libsoup/soup-value-utils.c (original)
+++ trunk/libsoup/soup-value-utils.c Fri Feb 1 15:23:31 2008
@@ -57,6 +57,48 @@
g_free, soup_value_hash_value_free);
}
+static void
+soup_value_hash_insert_valist (GHashTable *hash, const char *first_key,
+ va_list args)
+{
+ const char *key;
+ GType type;
+ GValue value;
+
+ key = first_key;
+ while (key) {
+ type = va_arg (args, GType);
+ SOUP_VALUE_SETV (&value, type, args);
+
+ soup_value_hash_insert_value (hash, key, &value);
+ key = va_arg (args, const char *);
+ }
+}
+
+/**
+ * soup_value_hash_new_with_vals:
+ * @first_key: the key for the first value
+ * @...: the type of @first_key, followed by the value, followed
+ * by additional key/type/value triplets, terminated by %NULL
+ *
+ * Creates a #GHashTable whose keys are strings and whose values
+ * are #GValue, and initializes it with the provided data. As
+ * with soup_value_hash_insert(), the keys and values are copied
+ * rather than being inserted directly.
+ **/
+GHashTable *
+soup_value_hash_new_with_vals (const char *first_key, ...)
+{
+ GHashTable *hash = soup_value_hash_new ();
+ va_list args;
+
+ va_start (args, first_key);
+ soup_value_hash_insert_valist (hash, first_key, args);
+ va_end (args);
+
+ return hash;
+}
+
/**
* soup_value_hash_insert_value:
* @hash: a value hash
@@ -99,6 +141,27 @@
}
/**
+ * soup_value_hash_insert_vals:
+ * @hash: a value hash
+ * @first_key: the key for the first value
+ * @...: the type of @first_key, followed by the value, followed
+ * by additional key/type/value triplets, terminated by %NULL
+ *
+ * Inserts the given data into @hash. As with
+ * soup_value_hash_insert(), the keys and values are copied rather
+ * than being inserted directly.
+ **/
+void
+soup_value_hash_insert_vals (GHashTable *hash, const char *first_key, ...)
+{
+ va_list args;
+
+ va_start (args, first_key);
+ soup_value_hash_insert_valist (hash, first_key, args);
+ va_end (args);
+}
+
+/**
* soup_value_hash_lookup:
* @hash: a value hash
* @key: the key to look up
@@ -128,6 +191,51 @@
return TRUE;
}
+/**
+ * soup_value_hash_lookup_vals:
+ * @hash: a value hash
+ * @first_key: the first key to look up
+ * @...: the type of @first_key, a pointer to that type, and
+ * then additional key/type/pointer triplets, terminated
+ * by %NULL.
+ *
+ * Looks up a number of keys in @hash and returns their values.
+ *
+ * Return value: %TRUE if all of the keys were found, %FALSE
+ * if any were missing; note that you will generally need to
+ * initialize each destination variable to a reasonable default
+ * value, since there is no way to tell which keys were found
+ * and which were not.
+ **/
+gboolean
+soup_value_hash_lookup_vals (GHashTable *hash, const char *first_key, ...)
+{
+ va_list args;
+ GValue *value;
+ const char *key;
+ GType type;
+ gboolean found_all = TRUE;
+
+ va_start (args, first_key);
+ key = first_key;
+ while (key) {
+ type = va_arg (args, GType);
+
+ value = g_hash_table_lookup (hash, key);
+ if (!value || !G_VALUE_HOLDS (value, type)) {
+ found_all = FALSE;
+ /* skip a pointer */
+ va_arg (args, gpointer);
+ } else
+ SOUP_VALUE_GETV (value, type, args);
+
+ key = va_arg (args, const char *);
+ }
+ va_end (args);
+
+ return found_all;
+}
+
/**
* soup_value_array_from_args:
@@ -187,6 +295,60 @@
}
/**
+ * soup_value_array_new:
+ *
+ * Creates a new %GValueArray. (This is just a wrapper around
+ * g_value_array_new(), for naming consistency purposes.)
+ *
+ * Return value: a new %GValueArray
+ **/
+GValueArray *
+soup_value_array_new (void)
+{
+ return g_value_array_new (1);
+}
+
+static void
+soup_value_array_append_valist (GValueArray *array,
+ GType first_type, va_list args)
+{
+ GType type;
+ GValue value;
+
+ type = first_type;
+ while (type != G_TYPE_INVALID) {
+ SOUP_VALUE_SETV (&value, type, args);
+
+ g_value_array_append (array, &value);
+ type = va_arg (args, GType);
+ }
+}
+
+/**
+ * soup_value_array_new_with_vals:
+ * @first_type: the type of the first value to add
+ * @...: the first value to add, followed by other type/value
+ * pairs, terminated by %G_TYPE_INVALID
+ *
+ * Creates a new %GValueArray and copies the provided values
+ * into it.
+ *
+ * Return value: a new %GValueArray
+ **/
+GValueArray *
+soup_value_array_new_with_vals (GType first_type, ...)
+{
+ GValueArray *array = soup_value_array_new ();
+ va_list args;
+
+ va_start (args, first_type);
+ soup_value_array_append_valist (array, first_type, args);
+ va_end (args);
+
+ return array;
+}
+
+/**
* soup_value_array_insert:
* @array: a #GValueArray
* @index_: the index to insert at
@@ -232,6 +394,27 @@
}
/**
+ * soup_value_array_append_values:
+ * @array: a #GValueArray
+ * @first_type: the type of the first value to add
+ * @...: the first value to add, followed by other type/value
+ * pairs, terminated by %G_TYPE_INVALID
+ *
+ * Appends the provided values into @array as with
+ * g_value_array_append(). (The provided data is copied rather than
+ * being inserted directly.)
+ **/
+void
+soup_value_array_append_vals (GValueArray *array, GType first_type, ...)
+{
+ va_list args;
+
+ va_start (args, first_type);
+ soup_value_array_append_valist (array, first_type, args);
+ va_end (args);
+}
+
+/**
* soup_value_array_get_nth:
* @array: a #GValueArray
* @index_: the index to look up
Modified: trunk/libsoup/soup-value-utils.h
==============================================================================
--- trunk/libsoup/soup-value-utils.h (original)
+++ trunk/libsoup/soup-value-utils.h Fri Feb 1 15:23:31 2008
@@ -31,37 +31,52 @@
g_free (error); \
} G_STMT_END
-GHashTable *soup_value_hash_new (void);
-void soup_value_hash_insert_value (GHashTable *hash,
- const char *key,
- GValue *value);
-void soup_value_hash_insert (GHashTable *hash,
- const char *key,
- GType type,
- ...);
-gboolean soup_value_hash_lookup (GHashTable *hash,
- const char *key,
- GType type,
- ...);
-
-GValueArray *soup_value_array_from_args (va_list args);
-gboolean soup_value_array_to_args (GValueArray *array,
- va_list args);
-
-void soup_value_array_insert (GValueArray *array,
- guint index_,
- GType type,
- ...);
-void soup_value_array_append (GValueArray *array,
- GType type,
- ...);
-gboolean soup_value_array_get_nth (GValueArray *array,
- guint index_,
- GType type,
- ...);
+GHashTable *soup_value_hash_new (void);
+GHashTable *soup_value_hash_new_with_vals (const char *first_key,
+ ...) G_GNUC_NULL_TERMINATED;
+void soup_value_hash_insert_value (GHashTable *hash,
+ const char *key,
+ GValue *value);
+void soup_value_hash_insert (GHashTable *hash,
+ const char *key,
+ GType type,
+ ...);
+void soup_value_hash_insert_vals (GHashTable *hash,
+ const char *first_key,
+ ...) G_GNUC_NULL_TERMINATED;
+gboolean soup_value_hash_lookup (GHashTable *hash,
+ const char *key,
+ GType type,
+ ...);
+gboolean soup_value_hash_lookup_vals (GHashTable *hash,
+ const char *first_key,
+ ...);
+
+GValueArray *soup_value_array_from_args (va_list args);
+gboolean soup_value_array_to_args (GValueArray *array,
+ va_list args);
+
+GValueArray *soup_value_array_new (void);
+GValueArray *soup_value_array_new_with_vals (GType first_type,
+ ...) G_GNUC_NULL_TERMINATED;
+
+void soup_value_array_insert (GValueArray *array,
+ guint index_,
+ GType type,
+ ...);
+void soup_value_array_append (GValueArray *array,
+ GType type,
+ ...);
+void soup_value_array_append_vals (GValueArray *array,
+ GType first_type,
+ ...) G_GNUC_NULL_TERMINATED;
+gboolean soup_value_array_get_nth (GValueArray *array,
+ guint index_,
+ GType type,
+ ...);
-GType soup_byte_array_get_type (void);
+GType soup_byte_array_get_type (void);
#define SOUP_TYPE_BYTE_ARRAY (soup_byte_array_get_type ())
G_END_DECLS
Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am (original)
+++ trunk/tests/Makefile.am Fri Feb 1 15:23:31 2008
@@ -1,6 +1,7 @@
INCLUDES = \
-I$(top_srcdir) \
-DSRCDIR=\""$(srcdir)"\" \
+ -DLIBSOUP_DISABLE_DEPRECATED \
$(XML_CFLAGS) \
$(GLIB_CFLAGS) \
$(LIBGNUTLS_CFLAGS)
Modified: trunk/tests/query-test.c
==============================================================================
--- trunk/tests/query-test.c (original)
+++ trunk/tests/query-test.c Fri Feb 1 15:23:31 2008
@@ -60,7 +60,6 @@
do_test (int n, gboolean extra, const char *uri)
{
GPtrArray *args;
- GHashTable *form_data_set;
char *title_arg = NULL, *name_arg = NULL;
char *stdout = NULL;
@@ -69,24 +68,16 @@
tests[n].name ? tests[n].name : "(null)",
extra ? " + extra" : "");
- form_data_set = g_hash_table_new (g_str_hash, g_str_equal);
-
args = g_ptr_array_new ();
g_ptr_array_add (args, "curl");
g_ptr_array_add (args, "-G");
if (tests[n].title) {
- g_hash_table_insert (form_data_set, "title", tests[n].title);
- title_arg = soup_form_encode_urlencoded (form_data_set);
- g_hash_table_remove_all (form_data_set);
-
+ title_arg = soup_form_encode ("title", tests[n].title, NULL);
g_ptr_array_add (args, "-d");
g_ptr_array_add (args, title_arg);
}
if (tests[n].name) {
- g_hash_table_insert (form_data_set, "name", tests[n].name);
- name_arg = soup_form_encode_urlencoded (form_data_set);
- g_hash_table_remove_all (form_data_set);
-
+ name_arg = soup_form_encode ("name", tests[n].name, NULL);
g_ptr_array_add (args, "-d");
g_ptr_array_add (args, name_arg);
}
@@ -116,7 +107,6 @@
errors++;
}
g_ptr_array_free (args, TRUE);
- g_hash_table_destroy (form_data_set);
g_free (title_arg);
g_free (name_arg);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]