diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | libsoup/Makefile.am | 4 | ||||
-rw-r--r-- | libsoup/soup-message-headers.c | 2 | ||||
-rw-r--r-- | libsoup/soup-misc.c | 18 | ||||
-rw-r--r-- | libsoup/soup-misc.h | 3 | ||||
-rw-r--r-- | libsoup/soup-soap-message.c | 818 | ||||
-rw-r--r-- | libsoup/soup-soap-message.h | 96 | ||||
-rw-r--r-- | libsoup/soup-soap-response.c | 554 | ||||
-rw-r--r-- | libsoup/soup-soap-response.h | 66 | ||||
-rw-r--r-- | libsoup/soup-xmlrpc.c | 45 | ||||
-rw-r--r-- | libsoup/soup.h | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/dict.c | 164 | ||||
-rw-r--r-- | tests/xmlrpc-test.c | 2 |
15 files changed, 47 insertions, 1745 deletions
@@ -1,5 +1,19 @@ 2008-01-06 Dan Winship <danw@gnome.org> + * libsoup/soup-soap-message.c: + * libsoup/soup-soap-response.c: For the second time, remove SOAP + support from libsoup... These APIs are not really all that helpful + in the grand scheme of SOAPiness, and are only used by the + Evolution GroupWise backend, which can just import this code and + integrate it better there. + + * libsoup/soup-misc.c (soup_xml_real_node): + * libsoup/soup-xmlrpc.c: Move soup_xml_real_node out of soup-misc + to soup-xmlrpc, and make it private. libxml is no longer exposed + in the public API. + +2008-01-06 Dan Winship <danw@gnome.org> + * libsoup/soup-date.c (soup_date_new_from_now): new method to generate a date relative to now. (soup_date_new, etc): document SoupDate methods @@ -8,7 +8,7 @@ Features: * Proxy support, including authentication and SSL tunneling * Client support for Digest, NTLM, and Basic authentication * Server support for Digest and Basic authentication - * Basic client-side SOAP and XML-RPC support + * XML-RPC support See the documentation in docs/reference/ and the test programs in tests/ for simple examples of how to use the code. The diff --git a/libsoup/Makefile.am b/libsoup/Makefile.am index e407a09c..b5d1148c 100644 --- a/libsoup/Makefile.am +++ b/libsoup/Makefile.am @@ -65,8 +65,6 @@ soup_headers = \ soup-session.h \ soup-session-async.h \ soup-session-sync.h \ - soup-soap-message.h \ - soup-soap-response.h \ soup-socket.h \ soup-status.h \ soup-types.h \ @@ -137,8 +135,6 @@ libsoup_2_4_la_SOURCES = \ soup-session-async.c \ soup-session-private.h \ soup-session-sync.c \ - soup-soap-message.c \ - soup-soap-response.c \ soup-socket.c \ soup-ssl.h \ soup-status.c \ diff --git a/libsoup/soup-message-headers.c b/libsoup/soup-message-headers.c index ae8df970..9e7ae04b 100644 --- a/libsoup/soup-message-headers.c +++ b/libsoup/soup-message-headers.c @@ -5,6 +5,8 @@ * Copyright (C) 2007, 2008 Red Hat, Inc. */ +#include <stdio.h> + #include "soup-message-headers.h" #include "soup-misc.h" diff --git a/libsoup/soup-misc.c b/libsoup/soup-misc.c index ce925db6..4c9e7330 100644 --- a/libsoup/soup-misc.c +++ b/libsoup/soup-misc.c @@ -190,21 +190,3 @@ soup_add_timeout (GMainContext *async_context, g_source_unref (source); return source; } - -/** - * soup_xml_real_node: - * @node: an %xmlNodePtr - * - * Finds the first "real" node (ie, not a comment or whitespace) at or - * after @node at its level in the tree. - * - * Return: a node, or %NULL - **/ -xmlNode * -soup_xml_real_node (xmlNode *node) -{ - while (node && (node->type == XML_COMMENT_NODE || - xmlIsBlankNode (node))) - node = node->next; - return node; -} diff --git a/libsoup/soup-misc.h b/libsoup/soup-misc.h index 3bb9804e..f35a56c6 100644 --- a/libsoup/soup-misc.h +++ b/libsoup/soup-misc.h @@ -7,7 +7,6 @@ #define SOUP_MISC_H 1 #include <glib-object.h> -#include <libxml/tree.h> G_BEGIN_DECLS @@ -36,8 +35,6 @@ guint soup_str_case_hash (gconstpointer key); gboolean soup_str_case_equal (gconstpointer v1, gconstpointer v2); -xmlNode *soup_xml_real_node (xmlNode *node); - /** * soup_ssl_supported: * diff --git a/libsoup/soup-soap-message.c b/libsoup/soup-soap-message.c deleted file mode 100644 index 60f4cdfc..00000000 --- a/libsoup/soup-soap-message.c +++ /dev/null @@ -1,818 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003, Novell, Inc. - */ - -#include <string.h> -#include "soup-misc.h" -#include "soup-soap-message.h" -#include "soup-uri.h" - -G_DEFINE_TYPE (SoupSoapMessage, soup_soap_message, SOUP_TYPE_MESSAGE) - -typedef struct { - /* Serialization fields */ - xmlDocPtr doc; - xmlNodePtr last_node; - xmlNsPtr soap_ns; - xmlNsPtr xsi_ns; - xmlChar *env_prefix; - xmlChar *env_uri; - gboolean body_started; - gchar *action; -} SoupSoapMessagePrivate; -#define SOUP_SOAP_MESSAGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUP_TYPE_SOAP_MESSAGE, SoupSoapMessagePrivate)) - -static void -finalize (GObject *object) -{ - SoupSoapMessagePrivate *priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (object); - - if (priv->doc) - xmlFreeDoc (priv->doc); - if (priv->action) - g_free (priv->action); - if (priv->env_uri) - xmlFree (priv->env_uri); - if (priv->env_prefix) - xmlFree (priv->env_prefix); - - G_OBJECT_CLASS (soup_soap_message_parent_class)->finalize (object); -} - -static void -soup_soap_message_class_init (SoupSoapMessageClass *soup_soap_message_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (soup_soap_message_class); - - g_type_class_add_private (soup_soap_message_class, sizeof (SoupSoapMessagePrivate)); - - object_class->finalize = finalize; -} - -static void -soup_soap_message_init (SoupSoapMessage *msg) -{ - SoupSoapMessagePrivate *priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - /* initialize XML structures */ - priv->doc = xmlNewDoc ((const xmlChar *)"1.0"); - priv->doc->standalone = FALSE; - priv->doc->encoding = xmlCharStrdup ("UTF-8"); -} - - -static xmlNsPtr -fetch_ns (SoupSoapMessage *msg, const char *prefix, const char *ns_uri) -{ - SoupSoapMessagePrivate *priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - xmlNsPtr ns = NULL; - - if (prefix && ns_uri) - ns = xmlNewNs (priv->last_node, (const xmlChar *)ns_uri, (const xmlChar *)prefix); - else if (prefix && !ns_uri) { - ns = xmlSearchNs (priv->doc, priv->last_node, (const xmlChar *)prefix); - if (!ns) - ns = xmlNewNs (priv->last_node, (const xmlChar *)"", (const xmlChar *)prefix); - } - - return ns; -} - -/** - * soup_soap_message_new: - * @method: the HTTP method for the created request. - * @uri_string: the destination endpoint (as a string). - * @standalone: ??? FIXME - * @xml_encoding: ??? FIXME - * @env_prefix: ??? FIXME - * @env_uri: ??? FIXME - * - * Creates a new empty #SoupSoapMessage, which will connect to @uri_string. - * - * Returns: the new #SoupSoapMessage (or %NULL if @uri_string could not be - * parsed). - */ -SoupSoapMessage * -soup_soap_message_new (const char *method, const char *uri_string, - gboolean standalone, const char *xml_encoding, - const char *env_prefix, const char *env_uri) -{ - SoupSoapMessage *msg; - SoupURI *uri; - - uri = soup_uri_new (uri_string); - if (!uri) - return NULL; - - msg = soup_soap_message_new_from_uri (method, uri, standalone, - xml_encoding, env_prefix, env_uri); - - soup_uri_free (uri); - - return msg; -} - -/** - * soup_soap_message_new_from_uri: - * @method: the HTTP method for the created request. - * @uri: the destination endpoint (as a #SoupURI). - * @standalone: ??? FIXME - * @xml_encoding: ??? FIXME - * @env_prefix: ??? FIXME - * @env_uri: ??? FIXME - * - * Creates a new empty #SoupSoapMessage, which will connect to @uri - * - * Returns: the new #SoupSoapMessage - */ -SoupSoapMessage * -soup_soap_message_new_from_uri (const char *method, SoupURI *uri, - gboolean standalone, const char *xml_encoding, - const char *env_prefix, const char *env_uri) -{ - SoupSoapMessage *msg; - SoupSoapMessagePrivate *priv; - - msg = g_object_new (SOUP_TYPE_SOAP_MESSAGE, - SOUP_MESSAGE_METHOD, method, - SOUP_MESSAGE_URI, uri, - NULL); - - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - priv->doc->standalone = standalone; - - if (xml_encoding) { - xmlFree ((xmlChar *)priv->doc->encoding); - priv->doc->encoding = xmlCharStrdup (xml_encoding); - } - - if (env_prefix) - priv->env_prefix = xmlCharStrdup (env_prefix); - if (env_uri) - priv->env_uri = xmlCharStrdup (env_uri); - - return msg; -} - -/** - * soup_soap_message_start_envelope: - * @msg: the %SoupSoapMessage. - * - * Starts the top level SOAP Envelope element. - */ -void -soup_soap_message_start_envelope (SoupSoapMessage *msg) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - priv->last_node = priv->doc->xmlRootNode = - xmlNewDocNode (priv->doc, NULL, (const xmlChar *)"Envelope", NULL); - - priv->soap_ns = xmlNewNs (priv->doc->xmlRootNode, - priv->env_uri ? priv->env_uri : - (const xmlChar *)"http://schemas.xmlsoap.org/soap/envelope/", - priv->env_prefix ? priv->env_prefix : (const xmlChar *)"SOAP-ENV"); - if (priv->env_uri) { - xmlFree (priv->env_uri); - priv->env_uri = NULL; - } - if (priv->env_prefix) { - xmlFree (priv->env_prefix); - priv->env_prefix = NULL; - } - - xmlSetNs (priv->doc->xmlRootNode, priv->soap_ns); - - xmlNewNs (priv->doc->xmlRootNode, - (const xmlChar *)"http://schemas.xmlsoap.org/soap/encoding/", - (const xmlChar *)"SOAP-ENC"); - xmlNewNs (priv->doc->xmlRootNode, - (const xmlChar *)"http://www.w3.org/1999/XMLSchema", - (const xmlChar *)"xsd"); - xmlNewNs (priv->doc->xmlRootNode, - (const xmlChar *)"http://schemas.xmlsoap.org/soap/envelope/", - (const xmlChar *)"SOAP-ENV"); - priv->xsi_ns = xmlNewNs (priv->doc->xmlRootNode, - (const xmlChar *)"http://www.w3.org/1999/XMLSchema-instance", - (const xmlChar *)"xsi"); -} - -/** - * soup_soap_message_end_envelope: - * @msg: the %SoupSoapMessage. - * - * Closes the top level SOAP Envelope element. - */ -void -soup_soap_message_end_envelope (SoupSoapMessage *msg) -{ - soup_soap_message_end_element (msg); -} - -/** - * soup_soap_message_start_body: - * @msg: the %SoupSoapMessage. - * - * Starts the SOAP Body element. - */ -void -soup_soap_message_start_body (SoupSoapMessage *msg) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - if (priv->body_started) - return; - - priv->last_node = xmlNewChild (priv->last_node, - priv->soap_ns, - (const xmlChar *)"Body", NULL); - - priv->body_started = TRUE; -} - -/** - * soup_soap_message_end_body: - * @msg: the %SoupSoapMessage. - * - * Closes the SOAP Body element. - */ -void -soup_soap_message_end_body (SoupSoapMessage *msg) -{ - soup_soap_message_end_element (msg); -} - -/** - * soup_soap_message_start_element: - * @msg: the #SoupSoapMessage. - * @name: the element name. - * @prefix: the namespace prefix - * @ns_uri: the namespace URI - * - * Starts a new arbitrary message element, with @name as the element - * name, @prefix as the XML Namespace prefix, and @ns_uri as the XML - * Namespace uri for * the created element. - * - * Passing @prefix with no @ns_uri will cause a recursive search for - * an existing namespace with the same prefix. Failing that a new ns - * will be created with an empty uri. - * - * Passing both @prefix and @ns_uri always causes new namespace - * attribute creation. - * - * Passing NULL for both @prefix and @ns_uri causes no prefix to be - * used, and the element will be in the default namespace. - */ -void -soup_soap_message_start_element (SoupSoapMessage *msg, - const char *name, - const char *prefix, - const char *ns_uri) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - priv->last_node = xmlNewChild (priv->last_node, NULL, (const xmlChar *)name, NULL); - - xmlSetNs (priv->last_node, fetch_ns (msg, prefix, ns_uri)); - - if (priv->body_started && !priv->action) - priv->action = g_strconcat (ns_uri ? ns_uri : "", - "#", name, NULL); -} - -/** - * soup_soap_message_end_element: - * @msg: the #SoupSoapMessage. - * - * Closes the current message element. - */ -void -soup_soap_message_end_element (SoupSoapMessage *msg) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - priv->last_node = priv->last_node->parent; -} - -/** - * soup_soap_message_start_fault: - * @msg: the #SoupSoapMessage. - * @faultcode: faultcode element value - * @faultstring: faultstring element value - * @faultfactor: faultfactor element value - * - * Starts a new SOAP Fault element, creating faultcode, faultstring, - * and faultfactor child elements. - * - * If you wish to add the faultdetail element, use - * soup_soap_message_start_fault_detail(), and then - * soup_soap_message_start_element() to add arbitrary sub-elements. - */ -void -soup_soap_message_start_fault (SoupSoapMessage *msg, - const char *faultcode, - const char *faultstring, - const char *faultfactor) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - priv->last_node = xmlNewChild (priv->last_node, - priv->soap_ns, - (const xmlChar *)"Fault", NULL); - xmlNewChild (priv->last_node, priv->soap_ns, (const xmlChar *)"faultcode", (const xmlChar *)faultcode); - xmlNewChild (priv->last_node, priv->soap_ns, (const xmlChar *)"faultstring", (const xmlChar *)faultstring); - - priv->last_node = xmlNewChild (priv->last_node, priv->soap_ns, - (const xmlChar *)"faultfactor", (const xmlChar *)faultfactor); - if (!faultfactor) - soup_soap_message_set_null (msg); - - soup_soap_message_end_element (msg); -} - -/** - * soup_soap_message_end_fault: - * @msg: the #SoupSoapMessage. - * - * Closes the current SOAP Fault element. - */ -void -soup_soap_message_end_fault (SoupSoapMessage *msg) -{ - soup_soap_message_end_element (msg); -} - -/** - * soup_soap_message_start_fault_detail: - * @msg: the #SoupSoapMessage. - * - * Start the faultdetail child element of the current SOAP Fault - * element. The faultdetail element allows arbitrary data to be sent - * in a returned fault. - **/ -void -soup_soap_message_start_fault_detail (SoupSoapMessage *msg) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - priv->last_node = xmlNewChild (priv->last_node, - priv->soap_ns, - (const xmlChar *)"detail", - NULL); -} - -/** - * soup_soap_message_end_fault_detail: - * @msg: the #SoupSoapMessage. - * - * Closes the current SOAP faultdetail element. - */ -void -soup_soap_message_end_fault_detail (SoupSoapMessage *msg) -{ - soup_soap_message_end_element (msg); -} - -/** - * soup_soap_message_start_header: - * @msg: the #SoupSoapMessage. - * - * Creates a new SOAP Header element. You can call - * soup_soap_message_start_header_element() after this to add a new - * header child element. SOAP Header elements allow out-of-band data - * to be transferred while not interfering with the message body. - * - * This should be called after soup_soap_message_start_envelope() and - * before soup_soap_message_start_body(). - */ -void -soup_soap_message_start_header (SoupSoapMessage *msg) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - priv->last_node = xmlNewChild (priv->last_node, priv->soap_ns, - (const xmlChar *)"Header", NULL); -} - -/** - * soup_soap_message_end_header: - * @msg: the #SoupSoapMessage. - * - * Closes the current SOAP Header element. - */ -void -soup_soap_message_end_header (SoupSoapMessage *msg) -{ - soup_soap_message_end_element (msg); -} - -/** - * soup_soap_message_start_header_element: - * @msg: the #SoupSoapMessage. - * @name: name of the header element - * @must_understand: whether the recipient must understand the header in order - * to proceed with processing the message - * @actor_uri: the URI which represents the destination actor for this header. - * @prefix: the namespace prefix - * @ns_uri: the namespace URI - * - * Starts a new SOAP arbitrary header element. - */ -void -soup_soap_message_start_header_element (SoupSoapMessage *msg, - const char *name, - gboolean must_understand, - const char *actor_uri, - const char *prefix, - const char *ns_uri) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - soup_soap_message_start_element (msg, name, prefix, ns_uri); - if (actor_uri) - xmlNewNsProp (priv->last_node, priv->soap_ns, (const xmlChar *)"actorUri", (const xmlChar *)actor_uri); - if (must_understand) - xmlNewNsProp (priv->last_node, priv->soap_ns, (const xmlChar *)"mustUnderstand", (const xmlChar *)"1"); -} - -/** - * soup_soap_message_end_header_element: - * @msg: the #SoupSoapMessage. - * - * Closes the current SOAP header element. - */ -void -soup_soap_message_end_header_element (SoupSoapMessage *msg) -{ - soup_soap_message_end_element (msg); -} - -/** - * soup_soap_message_write_int: - * @msg: the #SoupSoapMessage. - * @i: the integer value to write. - * - * Writes the stringified value of @i as the current element's content. - */ -void -soup_soap_message_write_int (SoupSoapMessage *msg, glong i) -{ - char *str = g_strdup_printf ("%ld", i); - soup_soap_message_write_string (msg, str); - g_free (str); -} - -/** - * soup_soap_message_write_double: - * @msg: the #SoupSoapMessage. - * @d: the double value to write. - * - * Writes the stringified value of @d as the current element's content. - */ -void -soup_soap_message_write_double (SoupSoapMessage *msg, double d) -{ - char *str = g_strdup_printf ("%f", d); - soup_soap_message_write_string (msg, str); - g_free (str); -} - -/** - * soup_soap_message_write_base64: - * @msg: the #SoupSoapMessage - * @string: the binary data buffer to encode - * @len: the length of data to encode - * - * Writes the Base-64 encoded value of @string as the current - * element's content. - **/ -void -soup_soap_message_write_base64 (SoupSoapMessage *msg, const char *string, int len) -{ - gchar *str = g_base64_encode ((const guchar *)string, len); - soup_soap_message_write_string (msg, str); - g_free (str); -} - -/** - * soup_soap_message_write_time: - * @msg: the #SoupSoapMessage. - * @timeval: pointer to a time_t to encode - * - * Writes the stringified value of @timeval as the current element's - * content. - **/ -void -soup_soap_message_write_time (SoupSoapMessage *msg, const time_t *timeval) -{ - gchar *str = g_strchomp (ctime (timeval)); - soup_soap_message_write_string (msg, str); -} - -/** - * soup_soap_message_write_string: - * @msg: the #SoupSoapMessage. - * @string: string to write. - * - * Writes the @string as the current element's content. - */ -void -soup_soap_message_write_string (SoupSoapMessage *msg, const char *string) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - xmlNodeAddContent (priv->last_node, (const xmlChar *)string); -} - -/** - * soup_soap_message_write_buffer: - * @msg: the #SoupSoapMessage. - * @buffer: the string data buffer to write. - * @len: length of @buffer. - * - * Writes the string buffer pointed to by @buffer as the current - * element's content. - */ -void -soup_soap_message_write_buffer (SoupSoapMessage *msg, const char *buffer, int len) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - xmlNodeAddContentLen (priv->last_node, (const xmlChar *)buffer, len); -} - -/** - * soup_soap_message_set_element_type: - * @msg: the #SoupSoapMessage. - * @xsi_type: the type name for the element. - * - * Sets the current element's XML schema xsi:type attribute, which - * specifies the element's type name. - */ -void -soup_soap_message_set_element_type (SoupSoapMessage *msg, const char *xsi_type) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - xmlNewNsProp (priv->last_node, priv->xsi_ns, (const xmlChar *)"type", (const xmlChar *)xsi_type); -} - -/** - * soup_soap_message_set_null: - * @msg: the #SoupSoapMessage. - * - * Sets the current element's XML Schema xsi:null attribute. - */ -void -soup_soap_message_set_null (SoupSoapMessage *msg) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - xmlNewNsProp (priv->last_node, priv->xsi_ns, (const xmlChar *)"null", (const xmlChar *)"1"); -} - -/** - * soup_soap_message_add_attribute: - * @msg: the #SoupSoapMessage. - * @name: name of the attribute - * @value: value of the attribute - * @prefix: the namespace prefix - * @ns_uri: the namespace URI - * - * Adds an XML attribute to the current element. - */ -void -soup_soap_message_add_attribute (SoupSoapMessage *msg, - const char *name, - const char *value, - const char *prefix, - const char *ns_uri) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - xmlNewNsProp (priv->last_node, - fetch_ns (msg, prefix, ns_uri), - (const xmlChar *)name, (const xmlChar *)value); -} - -/** - * soup_soap_message_add_namespace: - * @msg: the #SoupSoapMessage. - * @prefix: the namespace prefix - * @ns_uri: the namespace URI, or NULL for empty namespace - * - * Adds a new XML namespace to the current element. - */ -void -soup_soap_message_add_namespace (SoupSoapMessage *msg, const char *prefix, const char *ns_uri) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - xmlNewNs (priv->last_node, (const xmlChar *)(ns_uri ? ns_uri : ""), (const xmlChar *)prefix); -} - -/** - * soup_soap_message_set_default_namespace: - * @msg: the #SoupSoapMessage. - * @ns_uri: the namespace URI. - * - * Sets the default namespace to the URI specified in @ns_uri. The - * default namespace becomes the namespace all non-explicitly - * namespaced child elements fall into. - */ -void -soup_soap_message_set_default_namespace (SoupSoapMessage *msg, const char *ns_uri) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - soup_soap_message_add_namespace (msg, NULL, ns_uri); -} - -/** - * soup_soap_message_set_encoding_style: - * @msg: the #SoupSoapMessage. - * @enc_style: the new encodingStyle value - * - * Sets the encodingStyle attribute on the current element to the - * value of @enc_style. - */ -void -soup_soap_message_set_encoding_style (SoupSoapMessage *msg, const char *enc_style) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - xmlNewNsProp (priv->last_node, priv->soap_ns, (const xmlChar *)"encodingStyle", (const xmlChar *)enc_style); -} - -/** - * soup_soap_message_reset: - * @msg: the #SoupSoapMessage. - * - * Resets the internal XML representation of the SOAP message. - */ -void -soup_soap_message_reset (SoupSoapMessage *msg) -{ - SoupSoapMessagePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - xmlFreeDoc (priv->doc); - priv->doc = xmlNewDoc ((const xmlChar *)"1.0"); - priv->last_node = NULL; - - g_free (priv->action); - priv->action = NULL; - priv->body_started = FALSE; - - if (priv->env_uri) - xmlFree (priv->env_uri); - priv->env_uri = NULL; - - if (priv->env_prefix) - xmlFree (priv->env_prefix); - priv->env_prefix = NULL; -} - -/** - * soup_soap_message_persist: - * @msg: the #SoupSoapMessage. - * - * Writes the serialized XML tree to the #SoupMessage's buffer. - */ -void -soup_soap_message_persist (SoupSoapMessage *msg) -{ - SoupSoapMessagePrivate *priv; - xmlChar *body; - int len; - - g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg)); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - xmlDocDumpMemory (priv->doc, &body, &len); - - /* serialize to SoupMessage class */ - soup_message_set_request (SOUP_MESSAGE (msg), "text/xml", - SOUP_MEMORY_TAKE, (char *)body, len); -} - -/** - * soup_soap_message_get_namespace_prefix: - * @msg: the #SoupSoapMessage. - * @ns_uri: the namespace URI. - * - * Returns the namespace prefix for @ns_uri (or an empty string if - * @ns_uri is set to the default namespace) - * - * Return value: The namespace prefix, or %NULL if no namespace exists - * for the URI given. - */ -const char * -soup_soap_message_get_namespace_prefix (SoupSoapMessage *msg, const char *ns_uri) -{ - SoupSoapMessagePrivate *priv; - xmlNsPtr ns = NULL; - - g_return_val_if_fail (SOUP_IS_SOAP_MESSAGE (msg), NULL); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - g_return_val_if_fail (ns_uri != NULL, NULL); - - ns = xmlSearchNsByHref (priv->doc, priv->last_node, (const xmlChar *)ns_uri); - if (ns) { - if (ns->prefix) - return (const char *)ns->prefix; - else - return ""; - } - - return NULL; -} - -/** - * soup_soap_message_get_xml_doc: - * @msg: the #SoupSoapMessage. - * - * Returns the internal XML representation tree of the - * #SoupSoapMessage pointed to by @msg. - * - * Return value: the #xmlDocPtr representing the SOAP message. - */ -xmlDocPtr -soup_soap_message_get_xml_doc (SoupSoapMessage *msg) -{ - SoupSoapMessagePrivate *priv; - - g_return_val_if_fail (SOUP_IS_SOAP_MESSAGE (msg), NULL); - priv = SOUP_SOAP_MESSAGE_GET_PRIVATE (msg); - - return priv->doc; -} - -/** - * soup_soap_message_parse_response: - * @msg: the #SoupSoapMessage. - * - * Parses the response returned by the server. - * - * Return value: a #SoupSoapResponse representing the response from - * the server, or %NULL if there was an error. - */ -SoupSoapResponse * -soup_soap_message_parse_response (SoupSoapMessage *msg) -{ - g_return_val_if_fail (SOUP_IS_SOAP_MESSAGE (msg), NULL); - - return soup_soap_response_new_from_string (SOUP_MESSAGE (msg)->response_body->data); -} diff --git a/libsoup/soup-soap-message.h b/libsoup/soup-soap-message.h deleted file mode 100644 index 0b9e4ecb..00000000 --- a/libsoup/soup-soap-message.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003, Novell, Inc. - */ - -#ifndef SOUP_SOAP_MESSAGE_H -#define SOUP_SOAP_MESSAGE_H 1 - -#include <time.h> -#include <libxml/tree.h> -#include <libsoup/soup-message.h> -#include <libsoup/soup-soap-response.h> - -G_BEGIN_DECLS - -#define SOUP_TYPE_SOAP_MESSAGE (soup_soap_message_get_type ()) -#define SOUP_SOAP_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_SOAP_MESSAGE, SoupSoapMessage)) -#define SOUP_SOAP_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_SOAP_MESSAGE, SoupSoapMessageClass)) -#define SOUP_IS_SOAP_MESSAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_SOAP_MESSAGE)) -#define SOUP_IS_SOAP_MESSAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SOUP_TYPE_SOAP_MESSAGE)) -#define SOUP_SOAP_MESSAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOUP_TYPE_SOAP_MESSAGE, SoupSoapMessageClass)) - -typedef struct { - SoupMessage parent; - -} SoupSoapMessage; - -typedef struct { - SoupMessageClass parent_class; -} SoupSoapMessageClass; - -GType soup_soap_message_get_type (void); - -SoupSoapMessage *soup_soap_message_new (const char *method, const char *uri_string, - gboolean standalone, const char *xml_encoding, - const char *env_prefix, const char *env_uri); -SoupSoapMessage *soup_soap_message_new_from_uri (const char *method, SoupURI *uri, - gboolean standalone, const char *xml_encoding, - const char *env_prefix, const char *env_uri); - -void soup_soap_message_start_envelope (SoupSoapMessage *msg); -void soup_soap_message_end_envelope (SoupSoapMessage *msg); -void soup_soap_message_start_body (SoupSoapMessage *msg); -void soup_soap_message_end_body (SoupSoapMessage *msg); -void soup_soap_message_start_element (SoupSoapMessage *msg, - const char *name, - const char *prefix, - const char *ns_uri); -void soup_soap_message_end_element (SoupSoapMessage *msg); -void soup_soap_message_start_fault (SoupSoapMessage *msg, - const char *faultcode, - const char *faultstring, - const char *faultfactor); -void soup_soap_message_end_fault (SoupSoapMessage *msg); -void soup_soap_message_start_fault_detail (SoupSoapMessage *msg); -void soup_soap_message_end_fault_detail (SoupSoapMessage *msg); -void soup_soap_message_start_header (SoupSoapMessage *msg); -void soup_soap_message_end_header (SoupSoapMessage *msg); -void soup_soap_message_start_header_element (SoupSoapMessage *msg, - const char *name, - gboolean must_understand, - const char *actor_uri, - const char *prefix, - const char *ns_uri); -void soup_soap_message_end_header_element (SoupSoapMessage *msg); -void soup_soap_message_write_int (SoupSoapMessage *msg, glong i); -void soup_soap_message_write_double (SoupSoapMessage *msg, double d); -void soup_soap_message_write_base64 (SoupSoapMessage *msg, const char *string, int len); -void soup_soap_message_write_time (SoupSoapMessage *msg, const time_t *timeval); -void soup_soap_message_write_string (SoupSoapMessage *msg, const char *string); -void soup_soap_message_write_buffer (SoupSoapMessage *msg, const char *buffer, int len); -void soup_soap_message_set_element_type (SoupSoapMessage *msg, const char *xsi_type); -void soup_soap_message_set_null (SoupSoapMessage *msg); -void soup_soap_message_add_attribute (SoupSoapMessage *msg, - const char *name, - const char *value, - const char *prefix, - const char *ns_uri); -void soup_soap_message_add_namespace (SoupSoapMessage *msg, - const char *prefix, - const char *ns_uri); -void soup_soap_message_set_default_namespace (SoupSoapMessage *msg, - const char *ns_uri); -void soup_soap_message_set_encoding_style (SoupSoapMessage *msg, const char *enc_style); -void soup_soap_message_reset (SoupSoapMessage *msg); -void soup_soap_message_persist (SoupSoapMessage *msg); - -const char *soup_soap_message_get_namespace_prefix (SoupSoapMessage *msg, const char *ns_uri); - -xmlDocPtr soup_soap_message_get_xml_doc (SoupSoapMessage *msg); - -SoupSoapResponse *soup_soap_message_parse_response (SoupSoapMessage *msg); - -G_END_DECLS - -#endif diff --git a/libsoup/soup-soap-response.c b/libsoup/soup-soap-response.c deleted file mode 100644 index 65b77aad..00000000 --- a/libsoup/soup-soap-response.c +++ /dev/null @@ -1,554 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003, Novell, Inc. - */ - -#include <stdlib.h> -#include <string.h> -#include <libxml/tree.h> -#include "soup-misc.h" -#include "soup-soap-response.h" -#include "soup-types.h" - -G_DEFINE_TYPE (SoupSoapResponse, soup_soap_response, G_TYPE_OBJECT) - -typedef struct { - /* the XML document */ - xmlDocPtr xmldoc; - xmlNodePtr xml_root; - xmlNodePtr xml_body; - xmlNodePtr xml_method; - xmlNodePtr soap_fault; - GList *parameters; -} SoupSoapResponsePrivate; -#define SOUP_SOAP_RESPONSE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUP_TYPE_SOAP_RESPONSE, SoupSoapResponsePrivate)) - -static void -finalize (GObject *object) -{ - SoupSoapResponsePrivate *priv = SOUP_SOAP_RESPONSE_GET_PRIVATE (object); - - if (priv->xmldoc) - xmlFreeDoc (priv->xmldoc); - if (priv->parameters != NULL) - g_list_free (priv->parameters); - - G_OBJECT_CLASS (soup_soap_response_parent_class)->finalize (object); -} - -static void -soup_soap_response_class_init (SoupSoapResponseClass *soup_soap_response_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (soup_soap_response_class); - - g_type_class_add_private (soup_soap_response_class, sizeof (SoupSoapResponsePrivate)); - - object_class->finalize = finalize; -} - -static void -soup_soap_response_init (SoupSoapResponse *response) -{ - SoupSoapResponsePrivate *priv = SOUP_SOAP_RESPONSE_GET_PRIVATE (response); - - priv->xmldoc = xmlNewDoc ((const xmlChar *)"1.0"); -} - - -/** - * soup_soap_response_new: - * - * Create a new empty #SoupSoapResponse object, which can be modified - * with the accessor functions provided with this class. - * - * Return value: the new #SoupSoapResponse (or %NULL if there was an - * error). - */ -SoupSoapResponse * -soup_soap_response_new (void) -{ - SoupSoapResponse *response; - - response = g_object_new (SOUP_TYPE_SOAP_RESPONSE, NULL); - return response; -} - -/** - * soup_soap_response_new_from_string: - * @xmlstr: the XML string to parse. - * - * Create a new #SoupSoapResponse object from the XML string contained - * in @xmlstr. - * - * Return value: the new #SoupSoapResponse (or %NULL if there was an - * error). - */ -SoupSoapResponse * -soup_soap_response_new_from_string (const char *xmlstr) -{ - SoupSoapResponse *response; - - g_return_val_if_fail (xmlstr != NULL, NULL); - - response = g_object_new (SOUP_TYPE_SOAP_RESPONSE, NULL); - if (!soup_soap_response_from_string (response, xmlstr)) { - g_object_unref (response); - return NULL; - } - - return response; -} - -static void -parse_parameters (SoupSoapResponsePrivate *priv, xmlNodePtr xml_method) -{ - xmlNodePtr tmp; - - for (tmp = soup_xml_real_node (xml_method->children); - tmp != NULL; - tmp = soup_xml_real_node (tmp->next)) { - if (!strcmp ((const char *)tmp->name, "Fault")) { - priv->soap_fault = tmp; - continue; - } else { - /* regular parameters */ - priv->parameters = g_list_append (priv->parameters, tmp); - } - } -} - -/** - * soup_soap_response_from_string: - * @response: the #SoupSoapResponse object. - * @xmlstr: XML string to parse. - * - * Parses the string contained in @xmlstr and sets all properties from - * it in the @response object. - * - * Return value: %TRUE if successful, %FALSE otherwise. - */ -gboolean -soup_soap_response_from_string (SoupSoapResponse *response, const char *xmlstr) -{ - SoupSoapResponsePrivate *priv; - xmlDocPtr old_doc = NULL; - xmlNodePtr xml_root, xml_body, xml_method = NULL; - - g_return_val_if_fail (SOUP_IS_SOAP_RESPONSE (response), FALSE); - priv = SOUP_SOAP_RESPONSE_GET_PRIVATE (response); - g_return_val_if_fail (xmlstr != NULL, FALSE); - - /* clear the previous contents */ - if (priv->xmldoc) - old_doc = priv->xmldoc; - - /* parse the string */ - priv->xmldoc = xmlParseMemory (xmlstr, strlen (xmlstr)); - if (!priv->xmldoc) { - priv->xmldoc = old_doc; - return FALSE; - } - - xml_root = xmlDocGetRootElement (priv->xmldoc); - if (!xml_root) { - xmlFreeDoc (priv->xmldoc); - priv->xmldoc = old_doc; - return FALSE; - } - - if (strcmp ((const char *)xml_root->name, "Envelope") != 0) { - xmlFreeDoc (priv->xmldoc); - priv->xmldoc = old_doc; - return FALSE; - } - - xml_body = soup_xml_real_node (xml_root->children); - if (xml_body != NULL) { - if (strcmp ((const char *)xml_body->name, "Header") == 0) - xml_body = soup_xml_real_node (xml_body->next); - if (strcmp ((const char *)xml_body->name, "Body") != 0) { - xmlFreeDoc (priv->xmldoc); - priv->xmldoc = old_doc; - return FALSE; - } - - xml_method = soup_xml_real_node (xml_body->children); - - /* read all parameters */ - if (xml_method) - parse_parameters (priv, xml_method); - } - - xmlFreeDoc (old_doc); - - priv->xml_root = xml_root; - priv->xml_body = xml_body; - priv->xml_method = xml_method; - - return TRUE; -} - -/** - * soup_soap_response_get_method_name: - * @response: the #SoupSoapResponse object. - * - * Gets the method name from the SOAP response. - * - * Return value: the method name. - */ -const char * -soup_soap_response_get_method_name (SoupSoapResponse *response) -{ - SoupSoapResponsePrivate *priv; - - g_return_val_if_fail (SOUP_IS_SOAP_RESPONSE (response), NULL); - priv = SOUP_SOAP_RESPONSE_GET_PRIVATE (response); - g_return_val_if_fail (priv->xml_method != NULL, NULL); - - return (const char *) priv->xml_method->name; -} - -/** - * soup_soap_response_set_method_name: - * @response: the #SoupSoapResponse object. - * @method_name: the method name to set. - * - * Sets the method name on the given #SoupSoapResponse. - */ -void -soup_soap_response_set_method_name (SoupSoapResponse *response, const char *method_name) -{ - SoupSoapResponsePrivate *priv; - - g_return_if_fail (SOUP_IS_SOAP_RESPONSE (response)); - priv = SOUP_SOAP_RESPONSE_GET_PRIVATE (response); - g_return_if_fail (priv->xml_method != NULL); - g_return_if_fail (method_name != NULL); - - xmlNodeSetName (priv->xml_method, (const xmlChar *)method_name); -} - -/** - * soup_soap_parameter_get_name: - * @param: the parameter - * - * Returns the parameter name. - * - * Return value: the parameter name. - */ -const char * -soup_soap_parameter_get_name (SoupSoapParameter *param) -{ - g_return_val_if_fail (param != NULL, NULL); - - return (const char *) param->name; -} - -/** - * soup_soap_parameter_get_int_value: - * @param: the parameter - * - * Returns the parameter's (integer) value. - * - * Return value: the parameter value as an integer - */ -int -soup_soap_parameter_get_int_value (SoupSoapParameter *param) -{ - int i; - xmlChar *s; - g_return_val_if_fail (param != NULL, -1); - - s = xmlNodeGetContent (param); - if (s) { - i = atoi ((char *)s); - xmlFree (s); - - return i; - } - - return -1; -} - -/** - * soup_soap_parameter_get_string_value: - * @param: the parameter - * - * Returns the parameter's value. - * - * Return value: the parameter value as a string, which must be freed - * by the caller. - */ -char * -soup_soap_parameter_get_string_value (SoupSoapParameter *param) -{ - xmlChar *xml_s; - char *s; - g_return_val_if_fail (param != NULL, NULL); - - xml_s = xmlNodeGetContent (param); - s = g_strdup ((char *)xml_s); - xmlFree (xml_s); - - return s; -} - -/** - * soup_soap_parameter_get_first_child: - * @param: A #SoupSoapParameter. - * - * Gets the first child of the given #SoupSoapParameter. This is used - * for compound data types, which can contain several parameters - * themselves. - * - * Return value: the first child or %NULL if there are no children. - */ -SoupSoapParameter * -soup_soap_parameter_get_first_child (SoupSoapParameter *param) -{ - g_return_val_if_fail (param != NULL, NULL); - - return soup_xml_real_node (param->children); -} - -/** - * soup_soap_parameter_get_first_child_by_name: - * @param: A #SoupSoapParameter. - * @name: The name of the child parameter to look for. - * - * Gets the first child of the given #SoupSoapParameter whose name is - * @name. - * - * Return value: the first child with the given name or %NULL if there - * are no children. - */ -SoupSoapParameter * -soup_soap_parameter_get_first_child_by_name (SoupSoapParameter *param, const char *name) -{ - SoupSoapParameter *tmp; - - g_return_val_if_fail (param != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - for (tmp = soup_soap_parameter_get_first_child (param); - tmp != NULL; - tmp = soup_soap_parameter_get_next_child (tmp)) { - if (!strcmp (name, (const char *)tmp->name)) - return tmp; - } - - return NULL; -} - -/** - * soup_soap_parameter_get_next_child: - * @param: A #SoupSoapParameter. - * - * Gets the next sibling of the given #SoupSoapParameter. This is used - * for compound data types, which can contain several parameters - * themselves. - * - * FIXME: the name of this method is wrong - * - * Return value: the next sibling, or %NULL if there are no more - * siblings. - */ -SoupSoapParameter * -soup_soap_parameter_get_next_child (SoupSoapParameter *param) -{ - g_return_val_if_fail (param != NULL, NULL); - - return soup_xml_real_node (param->next); -} - -/** - * soup_soap_parameter_get_next_child_by_name: - * @param: A #SoupSoapParameter. - * @name: The name of the sibling parameter to look for. - * - * Gets the next sibling of the given #SoupSoapParameter whose name is - * @name. - * - * FIXME: the name of this method is wrong - * - * Return value: the next sibling with the given name, or %NULL - */ -SoupSoapParameter * -soup_soap_parameter_get_next_child_by_name (SoupSoapParameter *param, - const char *name) -{ - SoupSoapParameter *tmp; - - g_return_val_if_fail (param != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - for (tmp = soup_soap_parameter_get_next_child (param); - tmp != NULL; - tmp = soup_soap_parameter_get_next_child (tmp)) { - if (!strcmp (name, (const char *)tmp->name)) - return tmp; - } - - return NULL; -} - -/** - * soup_soap_parameter_get_property: - * @param: the parameter - * @prop_name: Name of the property to retrieve. - * - * Returns the named property of @param. - * - * Return value: the property, which must be freed by the caller. - */ -char * -soup_soap_parameter_get_property (SoupSoapParameter *param, const char *prop_name) -{ - xmlChar *xml_s; - char *s; - - g_return_val_if_fail (param != NULL, NULL); - g_return_val_if_fail (prop_name != NULL, NULL); - - xml_s = xmlGetProp (param, (const xmlChar *)prop_name); - s = g_strdup ((char *)xml_s); - xmlFree (xml_s); - - return s; -} - -/** - * soup_soap_response_get_parameters: - * @response: the #SoupSoapResponse object. - * - * Returns the list of parameters received in the SOAP response. - * - * Return value: a list of #SoupSoapParameter - */ -const GList * -soup_soap_response_get_parameters (SoupSoapResponse *response) -{ - SoupSoapResponsePrivate *priv; - - g_return_val_if_fail (SOUP_IS_SOAP_RESPONSE (response), NULL); - priv = SOUP_SOAP_RESPONSE_GET_PRIVATE (response); - - return (const GList *) priv->parameters; -} - -/** - * soup_soap_response_get_first_parameter: - * @response: the #SoupSoapResponse object. - * - * Retrieves the first parameter contained in the SOAP response. - * - * Return value: a #SoupSoapParameter representing the first - * parameter, or %NULL if there are no parameters. - */ -SoupSoapParameter * -soup_soap_response_get_first_parameter (SoupSoapResponse *response) -{ - SoupSoapResponsePrivate *priv; - - g_return_val_if_fail (SOUP_IS_SOAP_RESPONSE (response), NULL); - priv = SOUP_SOAP_RESPONSE_GET_PRIVATE (response); - - return priv->parameters ? priv->parameters->data : NULL; -} - -/** - * soup_soap_response_get_first_parameter_by_name: - * @response: the #SoupSoapResponse object. - * @name: the name of the parameter to look for. - * - * Retrieves the first parameter contained in the SOAP response whose - * name is @name. - * - * Return value: a #SoupSoapParameter representing the first parameter - * with the given name, or %NULL. - */ -SoupSoapParameter * -soup_soap_response_get_first_parameter_by_name (SoupSoapResponse *response, - const char *name) -{ - SoupSoapResponsePrivate *priv; - GList *l; - - g_return_val_if_fail (SOUP_IS_SOAP_RESPONSE (response), NULL); - priv = SOUP_SOAP_RESPONSE_GET_PRIVATE (response); - g_return_val_if_fail (name != NULL, NULL); - - for (l = priv->parameters; l != NULL; l = l->next) { - SoupSoapParameter *param = (SoupSoapParameter *) l->data; - - if (!strcmp (name, (const char *)param->name)) - return param; - } - - return NULL; -} - -/** - * soup_soap_response_get_next_parameter: - * @response: the #SoupSoapResponse object. - * @from: the parameter to start from. - * - * Retrieves the parameter following @from in the #SoupSoapResponse - * object. - * - * Return value: a #SoupSoapParameter representing the parameter. - */ -SoupSoapParameter * -soup_soap_response_get_next_parameter (SoupSoapResponse *response, - SoupSoapParameter *from) -{ - SoupSoapResponsePrivate *priv; - GList *l; - - g_return_val_if_fail (SOUP_IS_SOAP_RESPONSE (response), NULL); - priv = SOUP_SOAP_RESPONSE_GET_PRIVATE (response); - g_return_val_if_fail (from != NULL, NULL); - - l = g_list_find (priv->parameters, (gconstpointer) from); - if (!l) - return NULL; - - return l->next ? (SoupSoapParameter *) l->next->data : NULL; -} - -/** - * soup_soap_response_get_next_parameter_by_name: - * @response: the #SoupSoapResponse object. - * @from: the parameter to start from. - * @name: the name of the parameter to look for. - * - * Retrieves the first parameter following @from in the - * #SoupSoapResponse object whose name matches @name. - * - * Return value: a #SoupSoapParameter representing the parameter. - */ -SoupSoapParameter * -soup_soap_response_get_next_parameter_by_name (SoupSoapResponse *response, - SoupSoapParameter *from, - const char *name) -{ - SoupSoapParameter *param; - - g_return_val_if_fail (SOUP_IS_SOAP_RESPONSE (response), NULL); - g_return_val_if_fail (from != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - param = soup_soap_response_get_next_parameter (response, from); - while (param) { - const char *param_name = soup_soap_parameter_get_name (param); - - if (param_name) { - if (!strcmp (name, param_name)) - return param; - } - - param = soup_soap_response_get_next_parameter (response, param); - } - - return NULL; -} diff --git a/libsoup/soup-soap-response.h b/libsoup/soup-soap-response.h deleted file mode 100644 index 32427e27..00000000 --- a/libsoup/soup-soap-response.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003, Novell, Inc. - */ - -#ifndef SOUP_SOAP_RESPONSE_H -#define SOUP_SOAP_RESPONSE_H - -#include <glib-object.h> -#include <libxml/tree.h> - -G_BEGIN_DECLS - -#define SOUP_TYPE_SOAP_RESPONSE (soup_soap_response_get_type ()) -#define SOUP_SOAP_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_SOAP_RESPONSE, SoupSoapResponse)) -#define SOUP_SOAP_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_SOAP_RESPONSE, SoupSoapResponseClass)) -#define SOUP_IS_SOAP_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_SOAP_RESPONSE)) -#define SOUP_IS_SOAP_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SOUP_TYPE_SOAP_RESPONSE)) -#define SOUP_SOAP_RESPONSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOUP_TYPE_SOAP_RESPONSE, SoupSoapResponseClass)) - -typedef struct { - GObject parent; - -} SoupSoapResponse; - -typedef struct { - GObjectClass parent_class; -} SoupSoapResponseClass; - -GType soup_soap_response_get_type (void); - -SoupSoapResponse *soup_soap_response_new (void); -SoupSoapResponse *soup_soap_response_new_from_string (const char *xmlstr); - -gboolean soup_soap_response_from_string (SoupSoapResponse *response, const char *xmlstr); - -const char *soup_soap_response_get_method_name (SoupSoapResponse *response); -void soup_soap_response_set_method_name (SoupSoapResponse *response, - const char *method_name); - -typedef xmlNode SoupSoapParameter; - -const char *soup_soap_parameter_get_name (SoupSoapParameter *param); -int soup_soap_parameter_get_int_value (SoupSoapParameter *param); -char *soup_soap_parameter_get_string_value (SoupSoapParameter *param); -SoupSoapParameter *soup_soap_parameter_get_first_child (SoupSoapParameter *param); -SoupSoapParameter *soup_soap_parameter_get_first_child_by_name (SoupSoapParameter *param, - const char *name); -SoupSoapParameter *soup_soap_parameter_get_next_child (SoupSoapParameter *param); -SoupSoapParameter *soup_soap_parameter_get_next_child_by_name (SoupSoapParameter *param, - const char *name); -char *soup_soap_parameter_get_property (SoupSoapParameter *param, const char *prop_name); - -const GList *soup_soap_response_get_parameters (SoupSoapResponse *response); -SoupSoapParameter *soup_soap_response_get_first_parameter (SoupSoapResponse *response); -SoupSoapParameter *soup_soap_response_get_first_parameter_by_name (SoupSoapResponse *response, - const char *name); -SoupSoapParameter *soup_soap_response_get_next_parameter (SoupSoapResponse *response, - SoupSoapParameter *from); -SoupSoapParameter *soup_soap_response_get_next_parameter_by_name (SoupSoapResponse *response, - SoupSoapParameter *from, - const char *name); - -G_END_DECLS - -#endif diff --git a/libsoup/soup-xmlrpc.c b/libsoup/soup-xmlrpc.c index 6cce45c5..66f614bc 100644 --- a/libsoup/soup-xmlrpc.c +++ b/libsoup/soup-xmlrpc.c @@ -21,6 +21,8 @@ #include "soup-misc.h" #include "soup-session.h" +static xmlNode *find_real_node (xmlNode *node); + static gboolean insert_value (xmlNode *parent, GValue *value); static void @@ -413,7 +415,7 @@ parse_value (xmlNode *xmlvalue, GValue *value) memset (value, 0, sizeof (GValue)); - typenode = soup_xml_real_node (xmlvalue->children); + typenode = find_real_node (xmlvalue->children); if (!typenode) { /* If no type node, it's a string */ content = xmlNodeGetContent (typenode); @@ -469,9 +471,9 @@ parse_value (xmlNode *xmlvalue, GValue *value) GValue mgval; hash = soup_value_hash_new (); - for (member = soup_xml_real_node (typenode->children); + for (member = find_real_node (typenode->children); member; - member = soup_xml_real_node (member->next)) { + member = find_real_node (member->next)) { if (strcmp ((const char *)member->name, "member") != 0) { g_hash_table_destroy (hash); return FALSE; @@ -479,9 +481,9 @@ parse_value (xmlNode *xmlvalue, GValue *value) mname = mxval = NULL; memset (&mgval, 0, sizeof (mgval)); - for (child = soup_xml_real_node (member->children); + for (child = find_real_node (member->children); child; - child = soup_xml_real_node (child->next)) { + child = find_real_node (child->next)) { if (!strcmp ((const char *)child->name, "name")) mname = child; else if (!strcmp ((const char *)child->name, "value")) @@ -506,14 +508,14 @@ parse_value (xmlNode *xmlvalue, GValue *value) GValueArray *array; GValue gval; - data = soup_xml_real_node (typenode->children); + data = find_real_node (typenode->children); if (!data || strcmp ((const char *)data->name, "data") != 0) return FALSE; array = g_value_array_new (1); - for (xval = soup_xml_real_node (data->children); + for (xval = find_real_node (data->children); xval; - xval = soup_xml_real_node (xval->next)) { + xval = find_real_node (xval->next)) { memset (&gval, 0, sizeof (gval)); if (strcmp ((const char *)xval->name, "value") != 0 || !parse_value (xval, &gval)) { @@ -565,19 +567,19 @@ soup_xmlrpc_parse_method_call (const char *method_call, int length, if (!node || strcmp ((const char *)node->name, "methodCall") != 0) goto fail; - node = soup_xml_real_node (node->children); + node = find_real_node (node->children); if (!node || strcmp ((const char *)node->name, "methodName") != 0) goto fail; xmlMethodName = xmlNodeGetContent (node); - node = soup_xml_real_node (node->next); + node = find_real_node (node->next); if (!node || strcmp ((const char *)node->name, "params") != 0) goto fail; *params = g_value_array_new (1); - param = soup_xml_real_node (node->children); + param = find_real_node (node->children); while (param && !strcmp ((const char *)param->name, "param")) { - xval = soup_xml_real_node (param->children); + xval = find_real_node (param->children); if (!xval || !strcmp ((const char *)xval->name, "value") || !parse_value (xval, &value)) { g_value_array_free (*params); @@ -672,7 +674,7 @@ soup_xmlrpc_parse_method_response (const char *method_response, int length, if (!node || strcmp ((const char *)node->name, "methodResponse") != 0) goto fail; - node = soup_xml_real_node (node->children); + node = find_real_node (node->children); if (!node) goto fail; @@ -680,9 +682,9 @@ soup_xmlrpc_parse_method_response (const char *method_response, int length, int fault_code = -1; xmlChar *fault_string = NULL; - for (node = soup_xml_real_node (node->children); + for (node = find_real_node (node->children); node; - node = soup_xml_real_node (node->next)) { + node = find_real_node (node->next)) { if (!strcmp ((const char *)node->name, "faultCode")) { xmlChar *content = xmlNodeGetContent (node); fault_code = atoi ((char *)content); @@ -702,10 +704,10 @@ soup_xmlrpc_parse_method_response (const char *method_response, int length, if (fault_string) xmlFree (fault_string); } else if (!strcmp ((const char *)node->name, "params")) { - node = soup_xml_real_node (node->children); + node = find_real_node (node->children); if (!node || strcmp ((const char *)node->name, "param") != 0) goto fail; - node = soup_xml_real_node (node->children); + node = find_real_node (node->children); if (!node || strcmp ((const char *)node->name, "value") != 0) goto fail; if (!parse_value (node, value)) @@ -777,3 +779,12 @@ soup_xmlrpc_fault_quark (void) error = g_quark_from_static_string ("soup_xmlrpc_fault_quark"); return error; } + +static xmlNode * +find_real_node (xmlNode *node) +{ + while (node && (node->type == XML_COMMENT_NODE || + xmlIsBlankNode (node))) + node = node->next; + return node; +} diff --git a/libsoup/soup.h b/libsoup/soup.h index 0dc31d13..5363d0fd 100644 --- a/libsoup/soup.h +++ b/libsoup/soup.h @@ -25,8 +25,6 @@ extern "C" { #include <libsoup/soup-server.h> #include <libsoup/soup-session-async.h> #include <libsoup/soup-session-sync.h> -#include <libsoup/soup-soap-message.h> -#include <libsoup/soup-soap-response.h> #include <libsoup/soup-socket.h> #include <libsoup/soup-status.h> #include <libsoup/soup-uri.h> diff --git a/tests/Makefile.am b/tests/Makefile.am index 5a0a8a5c..6fcb346e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -11,7 +11,6 @@ noinst_PROGRAMS = \ context-test \ continue-test \ date \ - dict \ dns \ get \ getbug \ @@ -30,7 +29,6 @@ auth_test_SOURCES = auth-test.c apache-wrapper.c apache-wrapper.h context_test_SOURCES = context-test.c continue_test_SOURCES = continue-test.c date_SOURCES = date.c -dict_SOURCES = dict.c dns_SOURCES = dns.c get_SOURCES = get.c getbug_SOURCES = getbug.c diff --git a/tests/dict.c b/tests/dict.c deleted file mode 100644 index af261fa6..00000000 --- a/tests/dict.c +++ /dev/null @@ -1,164 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2001-2003, Ximian, Inc. - */ - -#include <ctype.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> -#include <unistd.h> - -#include <libsoup/soup.h> -#include <libsoup/soup-soap-message.h> -#include <libsoup/soup-soap-response.h> - -GMainLoop *loop; - -static void -got_response (SoupSession *session, SoupMessage *msg, gpointer user_data) -{ - SoupSoapResponse *response; - SoupSoapParameter *param, *subparam; - char *word, *dict, *def; - int count = 0; - - if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { - fprintf (stderr, "%d %s\n", msg->status_code, msg->reason_phrase); - exit (1); - } - - response = soup_soap_message_parse_response (SOUP_SOAP_MESSAGE (msg)); - if (!response) { - fprintf (stderr, "Could not parse SOAP response\n"); - exit (1); - } - - param = soup_soap_response_get_first_parameter_by_name (response, "DefineResult"); - if (!param) { - fprintf (stderr, "Could not find result in SOAP response\n"); - exit (1); - } - - param = soup_soap_parameter_get_first_child_by_name (param, "Definitions"); - if (!param) - goto done; - - for (param = soup_soap_parameter_get_first_child_by_name (param, "Definition"); - param; - param = soup_soap_parameter_get_next_child_by_name (param, "Definition")) { - subparam = soup_soap_parameter_get_first_child_by_name (param, "Word"); - if (!subparam) - continue; - word = soup_soap_parameter_get_string_value (subparam); - - subparam = soup_soap_parameter_get_first_child_by_name (param, "Dictionary"); - if (subparam) - subparam = soup_soap_parameter_get_first_child_by_name (subparam, "Name"); - if (subparam) - dict = soup_soap_parameter_get_string_value (subparam); - else - dict = NULL; - - printf ("% 2d. %s (%s):\n", ++count, word, dict); - g_free (word); - g_free (dict); - - subparam = soup_soap_parameter_get_first_child_by_name (param, "WordDefinition"); - if (subparam) { - def = soup_soap_parameter_get_string_value (subparam); - printf ("%s\n", def); - g_free (def); - } - } - - done: - if (count == 0) - printf ("No definition\n"); - - g_object_unref (response); - g_main_quit (loop); -} - -static void -usage (void) -{ - fprintf (stderr, "Usage: dict [-p proxy_uri] WORD\n"); - exit (1); -} - -int -main (int argc, char **argv) -{ - SoupSession *session; - SoupURI *proxy = NULL; - SoupSoapMessage *msg; - int opt; - - g_type_init (); - g_thread_init (NULL); - - while ((opt = getopt (argc, argv, "p:")) != -1) { - switch (opt) { - case 'p': - proxy = soup_uri_new (optarg); - if (!proxy) { - fprintf (stderr, "Could not parse %s as URI\n", - optarg); - exit (1); - } - break; - - case '?': - usage (); - break; - } - } - argc -= optind; - argv += optind; - - if (argc != 1) - usage (); - - session = soup_session_async_new_with_options ( - SOUP_SESSION_PROXY_URI, proxy, - NULL); - - msg = soup_soap_message_new ("POST", - "http://services.aonaware.com/DictService/DictService.asmx", - FALSE, NULL, NULL, NULL); - if (!msg) { - fprintf (stderr, "Could not create web service request\n"); - exit (1); - } - - soup_message_headers_append (SOUP_MESSAGE (msg)->request_headers, "SOAPAction", - "http://services.aonaware.com/webservices/Define"); - - soup_soap_message_start_envelope (msg); - soup_soap_message_start_body (msg); - - soup_soap_message_start_element (msg, "Define", NULL, - "http://services.aonaware.com/webservices/"); - soup_soap_message_add_namespace (msg, NULL, "http://services.aonaware.com/webservices/"); - soup_soap_message_start_element (msg, "word", NULL, NULL); - soup_soap_message_write_string (msg, argv[0]); - soup_soap_message_end_element (msg); - soup_soap_message_end_element (msg); - - soup_soap_message_end_body (msg); - soup_soap_message_end_envelope (msg); - soup_soap_message_persist (msg); - - soup_session_queue_message (session, SOUP_MESSAGE (msg), - got_response, NULL); - - loop = g_main_loop_new (NULL, TRUE); - g_main_run (loop); - g_main_loop_unref (loop); - - return 0; -} diff --git a/tests/xmlrpc-test.c b/tests/xmlrpc-test.c index 3a7df5b0..88959518 100644 --- a/tests/xmlrpc-test.c +++ b/tests/xmlrpc-test.c @@ -3,6 +3,8 @@ * Copyright (C) 2001-2003, Ximian, Inc. */ +#include <stdio.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> |