[libsoupmm] Fix Message ctor, Add XML-RPC support
- From: Siavash Safi <siavashs src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libsoupmm] Fix Message ctor, Add XML-RPC support
- Date: Mon, 31 Aug 2009 14:37:19 +0000 (UTC)
commit 502ebab98ea852195955146a1b48b349ed05d56b
Author: Siavash Safi <siavash siavashs org>
Date: Mon Aug 31 18:48:56 2009 +0430
Fix Message ctor, Add XML-RPC support
* .gitignore:
* codegen/m4/convert_libsoup.m4:
* libsoup/libsoupmm/filelist.am:
* libsoup/libsoupmm/xmlrpc.cc:
* libsoup/libsoupmm/xmlrpc.h:
* libsoup/src/message.ccg:
* libsoup/src/message.hg: Removed the default ctor since there's no
property to set the uri string directly.
Hand coded create() since the default ctor is removed. We create a URI
from the uri string and pass it to the other create function(similar to
what the C API does).
Add create_xmlrpc_request() to create a Message wich contains an XML-RPC
request.
Add "got-chunk" signal.
* libsoup/src/uri.ccg:
* libsoup/src/uri.hg: Rename the ctor argument.
.gitignore | 1 +
codegen/m4/convert_libsoup.m4 | 2 +
libsoup/libsoupmm/filelist.am | 4 +-
libsoup/libsoupmm/xmlrpc.cc | 48 +++++++++++++++++++++++++++++++++++++++++
libsoup/libsoupmm/xmlrpc.h | 31 ++++++++++++++++++++++++++
libsoup/src/message.ccg | 20 +++++++++++++++++
libsoup/src/message.hg | 14 ++++++++++-
libsoup/src/uri.ccg | 4 +-
libsoup/src/uri.hg | 2 +-
9 files changed, 119 insertions(+), 7 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index d9598e7..e8aef45 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,4 @@ stamp-h?
/libtool
/*.lineno
/codegen/extradefs/generate_extra_defs
+/examples/dns/example
diff --git a/codegen/m4/convert_libsoup.m4 b/codegen/m4/convert_libsoup.m4
index 494c4b7..f6c9405 100644
--- a/codegen/m4/convert_libsoup.m4
+++ b/codegen/m4/convert_libsoup.m4
@@ -4,8 +4,10 @@ dnl This file is part of libsoupmm.
_CONVERSION(`SoupAuth*',`const Glib::RefPtr<Auth>&',`Glib::wrap($3)')
_CONVERSION(`const Glib::RefPtr<Auth>&',`SoupAuth*',__CONVERT_REFPTR_TO_P)
+_CONVERSION(`Buffer',`SoupBuffer*',($3).gobj())
_CONVERSION(`Buffer&',`SoupBuffer*',($3).gobj())
_CONVERSION(`SoupBuffer*',`Buffer',($2)($3))
+_CONVERSION(`SoupBuffer*',`Buffer&',($2)($3))
_CONVERSION(`SoupMessage*',`Glib::RefPtr<Message>',`Glib::wrap($3)')
_CONVERSION(`SoupMessage*',`const Glib::RefPtr<Message>&',`Glib::wrap($3)')
diff --git a/libsoup/libsoupmm/filelist.am b/libsoup/libsoupmm/filelist.am
index 8d08476..389534b 100644
--- a/libsoup/libsoupmm/filelist.am
+++ b/libsoup/libsoupmm/filelist.am
@@ -3,6 +3,6 @@
files_built_cc = $(files_hg:.hg=.cc) wrap_init.cc
files_built_h = $(files_hg:.hg=.h)
files_built_ph = $(patsubst %.hg,private/%_p.h,$(files_hg))
-files_extra_cc = status.cc
-files_extra_h = status.h wrap_init.h
+files_extra_cc = status.cc xmlrpc.cc
+files_extra_h = status.h wrap_init.h xmlrpc.cc
files_extra_ph =
diff --git a/libsoup/libsoupmm/xmlrpc.cc b/libsoup/libsoupmm/xmlrpc.cc
new file mode 100644
index 0000000..4641cb9
--- /dev/null
+++ b/libsoup/libsoupmm/xmlrpc.cc
@@ -0,0 +1,48 @@
+/* Copyright (c) 2009 Siavash Safi <siavashs siavashs org>
+ *
+ * This file is part of libsoupmm.
+ *
+ * libsoupmm is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 2.1 of the License,
+ * or (at your option) any later version.
+ *
+ * libsoupmm is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glibmm.h>
+#include <libsoupmm/xmlrpc.h>
+#include <libsoup/soup-xmlrpc.h>
+
+namespace Soup
+{
+
+std::string xmlrpc_build_method_call(const std::string& method, const std::list<Glib::ValueBase>& parameters)
+{
+ GValueArray *params = g_value_array_new(1);
+
+ for(std::list<Glib::ValueBase>::const_iterator iter = parameters.begin(); iter != parameters.end(); ++iter)
+ {
+ g_value_array_append(params, iter->gobj());
+ }
+
+ std::string method_call = Glib::convert_const_gchar_ptr_to_stdstring(soup_xmlrpc_build_method_call(method.c_str(), params->values, params->n_values));
+ g_value_array_free (params);
+
+ return method_call;
+}
+
+bool xmlrpc_parse_method_response(const std::string response, Glib::ValueBase& value, Glib::Error& error)
+{
+ GError* c_error = error.gobj();
+ return soup_xmlrpc_parse_method_response(response.c_str(), response.size(), value.gobj(), &c_error);
+}
+
+} // namespace Soup
+
diff --git a/libsoup/libsoupmm/xmlrpc.h b/libsoup/libsoupmm/xmlrpc.h
new file mode 100644
index 0000000..166b341
--- /dev/null
+++ b/libsoup/libsoupmm/xmlrpc.h
@@ -0,0 +1,31 @@
+/* Copyright (c) 2009 Siavash Safi <siavashs siavashs org>
+ *
+ * This file is part of libsoupmm.
+ *
+ * libsoupmm is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 2.1 of the License,
+ * or (at your option) any later version.
+ *
+ * libsoupmm is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LIBSOUPMM_XMLRPC_H_INCLUDED
+#define LIBSOUPMM_XMLRPC_H_INCLUDED
+
+namespace Soup
+{
+
+std::string xmlrpc_build_method_call(const std::string& method, const std::list<Glib::ValueBase>& parameters);
+
+bool xmlrpc_parse_method_response(const std::string response, Glib::ValueBase& value, Glib::Error& error);
+
+} // namespace Soup
+
+#endif /* !LIBSOUPMM_XMLRPC_H_INCLUDED */
diff --git a/libsoup/src/message.ccg b/libsoup/src/message.ccg
index 0904b3f..c61b8f8 100644
--- a/libsoup/src/message.ccg
+++ b/libsoup/src/message.ccg
@@ -16,9 +16,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <libsoupmm/xmlrpc.h>
+
namespace Soup
{
+Glib::RefPtr<Message>
+Message::create(const std::string& method, const std::string& uri_string)
+{
+ return create(method, URI(uri_string));
+}
+
+Glib::RefPtr<Message>
+Message::create_xmlrpc_request(const std::string& uri_string, const std::string& method_name, const std::list<Glib::ValueBase>& params)
+{
+ std::string body = Soup::xmlrpc_build_method_call(method_name, params);
+ if(body.empty())
+ return Glib::RefPtr<Message>(0);
+
+ Glib::RefPtr<Message> msg = create("POST", uri_string);
+ msg->set_request("text/xml", Soup::MEMORY_COPY, body);
+ return msg;
+}
+
void
Message::set_request(const std::string& type, MemoryUse use, const std::string& body)
{
diff --git a/libsoup/src/message.hg b/libsoup/src/message.hg
index 3d288f2..15d92fc 100644
--- a/libsoup/src/message.hg
+++ b/libsoup/src/message.hg
@@ -35,13 +35,22 @@ class Message : public Glib::Object
_STRUCT_NOT_HIDDEN
protected:
- _WRAP_CTOR(Message(const std::string& method, const std::string& uri), soup_message_new)
+ // We can't wrap soup_message_new since there's no property to set the uri string
_WRAP_CTOR(Message(const std::string& method, const URI& uri), soup_message_new_from_uri)
public:
- _WRAP_CREATE(const std::string& method, const std::string& uri)
_WRAP_CREATE(const std::string& method, const URI& uri)
+ static Glib::RefPtr<Message> create(const std::string& method, const std::string& uri_string);
+ static Glib::RefPtr<Message> create_xmlrpc_request(const std::string& uri_string, const std::string& method_name, const std::list<Glib::ValueBase>& params);
+ // TODO: Check if all types of MemoryUse work, e.g. what happens when we use MEMORY_TAKE ?
+ /** Convenience function to set the request body of a Soup::Message.
+ * If type is empty, the request body must be empty as well.
+ *
+ * @param type MIME Content-Tpe of the body
+ * @param use a Soup::MemoryUse describing how to handle the body
+ * @param body a data buffer containing the message request.
+ */
void set_request(const std::string& type, MemoryUse use, const std::string& body);
_WRAP_METHOD(void set_http_version(HTTPVersion version), soup_message_set_http_version)
_WRAP_METHOD(HTTPVersion get_http_version(), soup_message_get_http_version)
@@ -56,6 +65,7 @@ public:
_WRAP_SIGNAL(void finished(), "finished")
_WRAP_SIGNAL(void got_body(), "got-body")
+ _WRAP_SIGNAL(void got_chunk(Buffer& buffer), "got-chunk")
_WRAP_SIGNAL(void got_headers(), "got-headers")
_WRAP_SIGNAL(void got_informational(), "got-informational")
_WRAP_SIGNAL(void restarted(), "restarted")
diff --git a/libsoup/src/uri.ccg b/libsoup/src/uri.ccg
index 38bfce3..e0b6c18 100644
--- a/libsoup/src/uri.ccg
+++ b/libsoup/src/uri.ccg
@@ -21,9 +21,9 @@
namespace Soup
{
-URI::URI(const std::string& uri)
+URI::URI(const std::string& uri_string)
{
- gobject_ = soup_uri_new(uri.c_str());
+ gobject_ = soup_uri_new(uri_string.c_str());
}
} // namespace Soup
diff --git a/libsoup/src/uri.hg b/libsoup/src/uri.hg
index d4eeb73..859521f 100644
--- a/libsoup/src/uri.hg
+++ b/libsoup/src/uri.hg
@@ -28,7 +28,7 @@ class URI
_IGNORE(soup_uri_copy, soup_uri_free)
public:
- explicit URI(const std::string& uri);
+ explicit URI(const std::string& uri_string);
_WRAP_METHOD(std::string to_string(bool just_path_and_query=true) const, soup_uri_to_string)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]