From: Dan Winship Date: Thu, 8 Jul 2004 18:15:37 +0000 (+0000) Subject: Basic SOAP test, using Aonaware's SOAP->DICT gateway X-Git-Tag: LIBSOUP_2_1_12~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b72bbbe3b5e87b959ccd81609cc7962a28b0dd5;p=platform%2Fupstream%2Flibsoup.git Basic SOAP test, using Aonaware's SOAP->DICT gateway 2004-07-08 Dan Winship * tests/dict.c: Basic SOAP test, using Aonaware's SOAP->DICT gateway 2004-07-07 Fernando Herrera * libsoup/soup-soap-response.c: (finalize), (init), (soup_soap_response_from_string): Use a parse context for the xml document, so we can safely use the option to ignore blank spaces and '\n'. --- diff --git a/ChangeLog b/ChangeLog index 3fc2fe6..0c8e47e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2004-07-08 Dan Winship + + * tests/dict.c: Basic SOAP test, using Aonaware's SOAP->DICT + gateway + +2004-07-07 Fernando Herrera + + * libsoup/soup-soap-response.c: (finalize), (init), + (soup_soap_response_from_string): Use a parse context for the + xml document, so we can safely use the option to ignore + blank spaces and '\n'. + 2004-07-06 Dan Winship * libsoup/soup-uri.c (soup_uri_new_with_base): if the protocol is diff --git a/libsoup/soup-soap-response.c b/libsoup/soup-soap-response.c index b0746d1..a7842b8 100644 --- a/libsoup/soup-soap-response.c +++ b/libsoup/soup-soap-response.c @@ -15,6 +15,7 @@ struct _SoupSoapResponsePrivate { /* the XML document */ xmlDocPtr xmldoc; + xmlParserCtxtPtr ctxt; xmlNodePtr xml_root; xmlNodePtr xml_body; xmlNodePtr xml_method; @@ -34,6 +35,11 @@ finalize (GObject *object) xmlFreeDoc (response->priv->xmldoc); response->priv->xmldoc = NULL; } + if (response->priv->ctxt) { + xmlFreeParserCtxt (response->priv->ctxt); + response->priv->ctxt = NULL; + } + response->priv->xml_root = NULL; response->priv->xml_body = NULL; @@ -66,6 +72,7 @@ init (SoupSoapResponse *response, SoupSoapResponseClass *klass) { response->priv = g_new0 (SoupSoapResponsePrivate, 1); + response->priv->ctxt = xmlNewParserCtxt (); response->priv->xmldoc = xmlNewDoc ("1.0"); } @@ -152,8 +159,9 @@ soup_soap_response_from_string (SoupSoapResponse *response, const char *xmlstr) if (response->priv->xmldoc) old_doc = response->priv->xmldoc; - /* parse the string */ - response->priv->xmldoc = xmlParseMemory (xmlstr, strlen (xmlstr)); + /* parse the string. We are using a parse context to make libxml + * ignore blanks and '\n' for this document. */ + response->priv->xmldoc = xmlCtxtReadMemory (response->priv->ctxt, xmlstr, strlen (xmlstr), NULL, NULL, XML_PARSE_NOBLANKS); if (!response->priv->xmldoc) { response->priv->xmldoc = old_doc; return FALSE; diff --git a/tests/.cvsignore b/tests/.cvsignore index 87e6da0..674da08 100644 --- a/tests/.cvsignore +++ b/tests/.cvsignore @@ -1,6 +1,7 @@ Makefile Makefile.in auth-test +dict dns get revserver diff --git a/tests/Makefile.am b/tests/Makefile.am index 7d32ac3..1d7ed7f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,11 +1,13 @@ INCLUDES = \ -I$(top_srcdir) \ + $(XML_CFLAGS) \ $(GLIB_CFLAGS) LIBS = $(top_builddir)/libsoup/libsoup-$(SOUP_API_VERSION).la noinst_PROGRAMS = \ auth-test \ + dict \ dns \ get \ revserver \ @@ -14,11 +16,12 @@ noinst_PROGRAMS = \ uri-parsing auth_test_SOURCES = auth-test.c +dict_SOURCES = dict.c dns_SOURCES = dns.c get_SOURCES = get.c +revserver_SOURCES = revserver.c simple_httpd_SOURCES = simple-httpd.c simple_proxy_SOURCES = simple-proxy.c -revserver_SOURCES = revserver.c uri_parsing_SOURCES = uri-parsing.c EXTRA_DIST = libsoup.supp test-cert.pem test-key.pem diff --git a/tests/dict.c b/tests/dict.c new file mode 100644 index 0000000..afaed0e --- /dev/null +++ b/tests/dict.c @@ -0,0 +1,164 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2001-2003, Ximian, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +SoupSession *session; +GMainLoop *loop; + +static void +got_response (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) +{ + 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_add_header (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; +}