[libsoup/wip/xclaesse/xmlrpc: 10/10] xmlrpc: Port soup_xmlrpc_build_fault() implementation to GVariant
- From: Xavier Claessens <xclaesse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/wip/xclaesse/xmlrpc: 10/10] xmlrpc: Port soup_xmlrpc_build_fault() implementation to GVariant
- Date: Tue, 23 Jun 2015 14:47:56 +0000 (UTC)
commit fee136e8b354282e20b7cb0e3fa5a1fd53062d99
Author: Xavier Claessens <xavier claessens collabora com>
Date: Tue Jun 23 09:50:52 2015 -0400
xmlrpc: Port soup_xmlrpc_build_fault() implementation to GVariant
This moves remaining not deprecated code from soup-xmlrpc-gvalue.c
to soup-xmlrpc.c
libsoup/soup-value-utils.c | 5 +
libsoup/soup-xmlrpc-gvalue.c | 193 +-----------------------------------------
libsoup/soup-xmlrpc-gvalue.h | 26 ------
libsoup/soup-xmlrpc.c | 170 +++++++++++++++++++++++++++++++++++++
libsoup/soup-xmlrpc.h | 27 ++++++-
5 files changed, 202 insertions(+), 219 deletions(-)
---
diff --git a/libsoup/soup-value-utils.c b/libsoup/soup-value-utils.c
index 2afb0e9..711d71b 100644
--- a/libsoup/soup-value-utils.c
+++ b/libsoup/soup-value-utils.c
@@ -53,6 +53,9 @@
* Deprecated: Use #GVariant API instead.
**/
+/* This whole file is deprecated and replaced by GVariant API */
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
static void
soup_value_hash_value_free (gpointer val)
{
@@ -522,3 +525,5 @@ soup_byte_array_free (GByteArray *ba)
**/
typedef GByteArray SoupByteArray;
G_DEFINE_BOXED_TYPE (SoupByteArray, soup_byte_array, soup_byte_array_copy, soup_byte_array_free)
+
+G_GNUC_END_IGNORE_DEPRECATIONS
diff --git a/libsoup/soup-xmlrpc-gvalue.c b/libsoup/soup-xmlrpc-gvalue.c
index 6e742c0..e81f56b 100644
--- a/libsoup/soup-xmlrpc-gvalue.c
+++ b/libsoup/soup-xmlrpc-gvalue.c
@@ -22,8 +22,7 @@
*
**/
-/* This whole file is pretty much deprecated and replaced by
- * soup-xmlrpc-variant.c */
+/* This whole file is deprecated and replaced by soup-xmlrpc.c */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static xmlNode *find_real_node (xmlNode *node);
@@ -287,84 +286,6 @@ soup_xmlrpc_build_method_response (GValue *value)
return body;
}
-static char *
-soup_xmlrpc_build_faultv (int fault_code,
- const char *fault_format,
- va_list args) G_GNUC_PRINTF (2, 0);
-
-static char *
-soup_xmlrpc_build_faultv (int fault_code, const char *fault_format, va_list args)
-{
- xmlDoc *doc;
- xmlNode *node, *member;
- GValue value;
- xmlChar *xmlbody;
- char *fault_string, *body;
- int len;
-
- fault_string = g_strdup_vprintf (fault_format, args);
-
- doc = xmlNewDoc ((const xmlChar *)"1.0");
- doc->standalone = FALSE;
- doc->encoding = xmlCharStrdup ("UTF-8");
-
- node = xmlNewDocNode (doc, NULL,
- (const xmlChar *)"methodResponse", NULL);
- xmlDocSetRootElement (doc, node);
- node = xmlNewChild (node, NULL, (const xmlChar *)"fault", NULL);
- node = xmlNewChild (node, NULL, (const xmlChar *)"value", NULL);
- node = xmlNewChild (node, NULL, (const xmlChar *)"struct", NULL);
-
- memset (&value, 0, sizeof (value));
-
- member = xmlNewChild (node, NULL, (const xmlChar *)"member", NULL);
- xmlNewChild (member, NULL,
- (const xmlChar *)"name", (const xmlChar *)"faultCode");
- g_value_init (&value, G_TYPE_INT);
- g_value_set_int (&value, fault_code);
- insert_value (member, &value);
- g_value_unset (&value);
-
- member = xmlNewChild (node, NULL, (const xmlChar *)"member", NULL);
- xmlNewChild (member, NULL,
- (const xmlChar *)"name", (const xmlChar *)"faultString");
- g_value_init (&value, G_TYPE_STRING);
- g_value_take_string (&value, fault_string);
- insert_value (member, &value);
- g_value_unset (&value);
-
- xmlDocDumpMemory (doc, &xmlbody, &len);
- body = g_strndup ((char *)xmlbody, len);
- xmlFree (xmlbody);
- xmlFreeDoc (doc);
-
- return body;
-}
-
-/**
- * soup_xmlrpc_build_fault:
- * @fault_code: the fault code
- * @fault_format: a printf()-style format string
- * @...: the parameters to @fault_format
- *
- * This creates an XML-RPC fault response and returns it as a string.
- * (To create a successful response, use
- * soup_xmlrpc_build_method_response().)
- *
- * Return value: the text of the fault
- **/
-char *
-soup_xmlrpc_build_fault (int fault_code, const char *fault_format, ...)
-{
- va_list args;
- char *body;
-
- va_start (args, fault_format);
- body = soup_xmlrpc_build_faultv (fault_code, fault_format, args);
- va_end (args);
- return body;
-}
-
/**
* soup_xmlrpc_set_response:
* @msg: an XML-RPC request
@@ -395,62 +316,6 @@ soup_xmlrpc_set_response (SoupMessage *msg, GType type, ...)
body, strlen (body));
}
-/**
- * soup_xmlrpc_set_fault:
- * @msg: an XML-RPC request
- * @fault_code: the fault code
- * @fault_format: a printf()-style format string
- * @...: the parameters to @fault_format
- *
- * Sets the status code and response body of @msg to indicate an
- * unsuccessful XML-RPC call, with the error described by @fault_code
- * and @fault_format.
- *
- * Deprecated: Use soup_xmlrpc_message_set_fault() instead.
- **/
-void
-soup_xmlrpc_set_fault (SoupMessage *msg, int fault_code,
- const char *fault_format, ...)
-{
- va_list args;
- char *body;
-
- va_start (args, fault_format);
- body = soup_xmlrpc_build_faultv (fault_code, fault_format, args);
- va_end (args);
-
- soup_message_set_status (msg, SOUP_STATUS_OK);
- soup_message_set_response (msg, "text/xml", SOUP_MEMORY_TAKE,
- body, strlen (body));
-}
-
-/**
- * soup_xmlrpc_message_set_fault:
- * @msg: an XML-RPC request
- * @fault_code: the fault code
- * @fault_format: a printf()-style format string
- * @...: the parameters to @fault_format
- *
- * Sets the status code and response body of @msg to indicate an
- * unsuccessful XML-RPC call, with the error described by @fault_code
- * and @fault_format.
- **/
-void
-soup_xmlrpc_message_set_fault (SoupMessage *msg, int fault_code,
- const char *fault_format, ...)
-{
- va_list args;
- char *body;
-
- va_start (args, fault_format);
- body = soup_xmlrpc_build_faultv (fault_code, fault_format, args);
- va_end (args);
-
- soup_message_set_status (msg, SOUP_STATUS_OK);
- soup_message_set_response (msg, "text/xml", SOUP_MEMORY_TAKE,
- body, strlen (body));
-}
-
static gboolean
parse_value (xmlNode *xmlvalue, GValue *value)
{
@@ -819,62 +684,6 @@ soup_xmlrpc_extract_method_response (const char *method_response, int length,
return TRUE;
}
-
-GQuark
-soup_xmlrpc_error_quark (void)
-{
- static GQuark error;
- if (!error)
- error = g_quark_from_static_string ("soup_xmlrpc_error_quark");
- return error;
-}
-
-/**
- * SOUP_XMLRPC_FAULT:
- *
- * A #GError domain representing an XML-RPC fault code. Used with
- * #SoupXMLRPCFault (although servers may also return fault codes not
- * in that enumeration).
- */
-
-/**
- * SoupXMLRPCFault:
- * @SOUP_XMLRPC_FAULT_PARSE_ERROR_NOT_WELL_FORMED: request was not
- * well-formed
- * @SOUP_XMLRPC_FAULT_PARSE_ERROR_UNSUPPORTED_ENCODING: request was in
- * an unsupported encoding
- * @SOUP_XMLRPC_FAULT_PARSE_ERROR_INVALID_CHARACTER_FOR_ENCODING:
- * request contained an invalid character
- * @SOUP_XMLRPC_FAULT_SERVER_ERROR_INVALID_XML_RPC: request was not
- * valid XML-RPC
- * @SOUP_XMLRPC_FAULT_SERVER_ERROR_REQUESTED_METHOD_NOT_FOUND: method
- * not found
- * @SOUP_XMLRPC_FAULT_SERVER_ERROR_INVALID_METHOD_PARAMETERS: invalid
- * parameters
- * @SOUP_XMLRPC_FAULT_SERVER_ERROR_INTERNAL_XML_RPC_ERROR: internal
- * error
- * @SOUP_XMLRPC_FAULT_APPLICATION_ERROR: start of reserved range for
- * application error codes
- * @SOUP_XMLRPC_FAULT_SYSTEM_ERROR: start of reserved range for
- * system error codes
- * @SOUP_XMLRPC_FAULT_TRANSPORT_ERROR: start of reserved range for
- * transport error codes
- *
- * Pre-defined XML-RPC fault codes from <ulink
- *
url="http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php">http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php</ulink>.
- * These are an extension, not part of the XML-RPC spec; you can't
- * assume servers will use them.
- */
-
-GQuark
-soup_xmlrpc_fault_quark (void)
-{
- static GQuark error;
- if (!error)
- error = g_quark_from_static_string ("soup_xmlrpc_fault_quark");
- return error;
-}
-
static xmlNode *
find_real_node (xmlNode *node)
{
diff --git a/libsoup/soup-xmlrpc-gvalue.h b/libsoup/soup-xmlrpc-gvalue.h
index d28bea6..34db645 100644
--- a/libsoup/soup-xmlrpc-gvalue.h
+++ b/libsoup/soup-xmlrpc-gvalue.h
@@ -54,32 +54,6 @@ void soup_xmlrpc_set_fault (SoupMessage *msg,
const char *fault_format,
...) G_GNUC_PRINTF (3, 4);
-
-/* Errors */
-#define SOUP_XMLRPC_ERROR soup_xmlrpc_error_quark()
-GQuark soup_xmlrpc_error_quark (void);
-
-typedef enum {
- SOUP_XMLRPC_ERROR_ARGUMENTS,
- SOUP_XMLRPC_ERROR_RETVAL
-} SoupXMLRPCError;
-
-#define SOUP_XMLRPC_FAULT soup_xmlrpc_fault_quark()
-GQuark soup_xmlrpc_fault_quark (void);
-
-typedef enum {
- SOUP_XMLRPC_FAULT_PARSE_ERROR_NOT_WELL_FORMED = -32700,
- SOUP_XMLRPC_FAULT_PARSE_ERROR_UNSUPPORTED_ENCODING = -32701,
- SOUP_XMLRPC_FAULT_PARSE_ERROR_INVALID_CHARACTER_FOR_ENCODING = -32702,
- SOUP_XMLRPC_FAULT_SERVER_ERROR_INVALID_XML_RPC = -32600,
- SOUP_XMLRPC_FAULT_SERVER_ERROR_REQUESTED_METHOD_NOT_FOUND = -32601,
- SOUP_XMLRPC_FAULT_SERVER_ERROR_INVALID_METHOD_PARAMETERS = -32602,
- SOUP_XMLRPC_FAULT_SERVER_ERROR_INTERNAL_XML_RPC_ERROR = -32603,
- SOUP_XMLRPC_FAULT_APPLICATION_ERROR = -32500,
- SOUP_XMLRPC_FAULT_SYSTEM_ERROR = -32400,
- SOUP_XMLRPC_FAULT_TRANSPORT_ERROR = -32300
-} SoupXMLRPCFault;
-
G_END_DECLS
#endif /* SOUP_XMLRPC_GVALUE_H */
diff --git a/libsoup/soup-xmlrpc.c b/libsoup/soup-xmlrpc.c
index e7a7c19..0984965 100644
--- a/libsoup/soup-xmlrpc.c
+++ b/libsoup/soup-xmlrpc.c
@@ -415,6 +415,136 @@ soup_xmlrpc_build_response (GVariant *value, GError **error)
return body;
}
+static char *
+soup_xmlrpc_build_faultv (int fault_code,
+ const char *fault_format,
+ va_list args) G_GNUC_PRINTF (2, 0);
+
+static char *
+soup_xmlrpc_build_faultv (int fault_code, const char *fault_format, va_list args)
+{
+ xmlDoc *doc;
+ xmlNode *node, *member;
+ GVariant *value;
+ xmlChar *xmlbody;
+ char *fault_string, *body;
+ int len;
+
+ fault_string = g_strdup_vprintf (fault_format, args);
+
+ doc = xmlNewDoc ((const xmlChar *)"1.0");
+ doc->standalone = FALSE;
+ doc->encoding = xmlCharStrdup ("UTF-8");
+
+ node = xmlNewDocNode (doc, NULL,
+ (const xmlChar *)"methodResponse", NULL);
+ xmlDocSetRootElement (doc, node);
+ node = xmlNewChild (node, NULL, (const xmlChar *)"fault", NULL);
+ node = xmlNewChild (node, NULL, (const xmlChar *)"value", NULL);
+ node = xmlNewChild (node, NULL, (const xmlChar *)"struct", NULL);
+
+ member = xmlNewChild (node, NULL, (const xmlChar *)"member", NULL);
+ xmlNewChild (member, NULL,
+ (const xmlChar *)"name", (const xmlChar *)"faultCode");
+ value = g_variant_new_int32 (fault_code);
+ insert_value (member, value, NULL);
+ g_variant_unref (value);
+
+ member = xmlNewChild (node, NULL, (const xmlChar *)"member", NULL);
+ xmlNewChild (member, NULL,
+ (const xmlChar *)"name", (const xmlChar *)"faultString");
+ value = g_variant_new_take_string (fault_string);
+ insert_value (member, value, NULL);
+ g_variant_unref (value);
+
+ xmlDocDumpMemory (doc, &xmlbody, &len);
+ body = g_strndup ((char *)xmlbody, len);
+ xmlFree (xmlbody);
+ xmlFreeDoc (doc);
+
+ return body;
+}
+
+/**
+ * soup_xmlrpc_build_fault:
+ * @fault_code: the fault code
+ * @fault_format: a printf()-style format string
+ * @...: the parameters to @fault_format
+ *
+ * This creates an XML-RPC fault response and returns it as a string.
+ * (To create a successful response, use
+ * soup_xmlrpc_build_method_response().)
+ *
+ * Return value: the text of the fault
+ **/
+char *
+soup_xmlrpc_build_fault (int fault_code, const char *fault_format, ...)
+{
+ va_list args;
+ char *body;
+
+ va_start (args, fault_format);
+ body = soup_xmlrpc_build_faultv (fault_code, fault_format, args);
+ va_end (args);
+ return body;
+}
+
+/**
+ * soup_xmlrpc_message_set_fault:
+ * @msg: an XML-RPC request
+ * @fault_code: the fault code
+ * @fault_format: a printf()-style format string
+ * @...: the parameters to @fault_format
+ *
+ * Sets the status code and response body of @msg to indicate an
+ * unsuccessful XML-RPC call, with the error described by @fault_code
+ * and @fault_format.
+ **/
+void
+soup_xmlrpc_message_set_fault (SoupMessage *msg, int fault_code,
+ const char *fault_format, ...)
+{
+ va_list args;
+ char *body;
+
+ va_start (args, fault_format);
+ body = soup_xmlrpc_build_faultv (fault_code, fault_format, args);
+ va_end (args);
+
+ soup_message_set_status (msg, SOUP_STATUS_OK);
+ soup_message_set_response (msg, "text/xml", SOUP_MEMORY_TAKE,
+ body, strlen (body));
+}
+
+/**
+ * soup_xmlrpc_set_fault:
+ * @msg: an XML-RPC request
+ * @fault_code: the fault code
+ * @fault_format: a printf()-style format string
+ * @...: the parameters to @fault_format
+ *
+ * Sets the status code and response body of @msg to indicate an
+ * unsuccessful XML-RPC call, with the error described by @fault_code
+ * and @fault_format.
+ *
+ * Deprecated: Use soup_xmlrpc_message_set_fault() instead.
+ **/
+void
+soup_xmlrpc_set_fault (SoupMessage *msg, int fault_code,
+ const char *fault_format, ...)
+{
+ va_list args;
+ char *body;
+
+ va_start (args, fault_format);
+ body = soup_xmlrpc_build_faultv (fault_code, fault_format, args);
+ va_end (args);
+
+ soup_message_set_status (msg, SOUP_STATUS_OK);
+ soup_message_set_response (msg, "text/xml", SOUP_MEMORY_TAKE,
+ body, strlen (body));
+}
+
/**
* soup_xmlrpc_message_set_response:
* @msg: an XML-RPC request
@@ -1327,3 +1457,43 @@ soup_xmlrpc_new_datetime (time_t timestamp)
return variant;
}
+
+/**
+ * SOUP_XMLRPC_FAULT:
+ *
+ * A #GError domain representing an XML-RPC fault code. Used with
+ * #SoupXMLRPCFault (although servers may also return fault codes not
+ * in that enumeration).
+ */
+
+/**
+ * SoupXMLRPCFault:
+ * @SOUP_XMLRPC_FAULT_PARSE_ERROR_NOT_WELL_FORMED: request was not
+ * well-formed
+ * @SOUP_XMLRPC_FAULT_PARSE_ERROR_UNSUPPORTED_ENCODING: request was in
+ * an unsupported encoding
+ * @SOUP_XMLRPC_FAULT_PARSE_ERROR_INVALID_CHARACTER_FOR_ENCODING:
+ * request contained an invalid character
+ * @SOUP_XMLRPC_FAULT_SERVER_ERROR_INVALID_XML_RPC: request was not
+ * valid XML-RPC
+ * @SOUP_XMLRPC_FAULT_SERVER_ERROR_REQUESTED_METHOD_NOT_FOUND: method
+ * not found
+ * @SOUP_XMLRPC_FAULT_SERVER_ERROR_INVALID_METHOD_PARAMETERS: invalid
+ * parameters
+ * @SOUP_XMLRPC_FAULT_SERVER_ERROR_INTERNAL_XML_RPC_ERROR: internal
+ * error
+ * @SOUP_XMLRPC_FAULT_APPLICATION_ERROR: start of reserved range for
+ * application error codes
+ * @SOUP_XMLRPC_FAULT_SYSTEM_ERROR: start of reserved range for
+ * system error codes
+ * @SOUP_XMLRPC_FAULT_TRANSPORT_ERROR: start of reserved range for
+ * transport error codes
+ *
+ * Pre-defined XML-RPC fault codes from <ulink
+ *
url="http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php">http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php</ulink>.
+ * These are an extension, not part of the XML-RPC spec; you can't
+ * assume servers will use them.
+ */
+
+G_DEFINE_QUARK (soup_xmlrpc_fault_quark, soup_xmlrpc_fault);
+G_DEFINE_QUARK (soup_xmlrpc_error_quark, soup_xmlrpc_error);
diff --git a/libsoup/soup-xmlrpc.h b/libsoup/soup-xmlrpc.h
index e03e37d..f9ce5ae 100644
--- a/libsoup/soup-xmlrpc.h
+++ b/libsoup/soup-xmlrpc.h
@@ -69,6 +69,31 @@ GVariant *soup_xmlrpc_new_custom (const char *type,
SOUP_AVAILABLE_IN_2_52
GVariant *soup_xmlrpc_new_datetime (time_t timestamp);
+/* Errors */
+#define SOUP_XMLRPC_ERROR soup_xmlrpc_error_quark()
+GQuark soup_xmlrpc_error_quark (void);
+
+typedef enum {
+ SOUP_XMLRPC_ERROR_ARGUMENTS,
+ SOUP_XMLRPC_ERROR_RETVAL
+} SoupXMLRPCError;
+
+#define SOUP_XMLRPC_FAULT soup_xmlrpc_fault_quark()
+GQuark soup_xmlrpc_fault_quark (void);
+
+typedef enum {
+ SOUP_XMLRPC_FAULT_PARSE_ERROR_NOT_WELL_FORMED = -32700,
+ SOUP_XMLRPC_FAULT_PARSE_ERROR_UNSUPPORTED_ENCODING = -32701,
+ SOUP_XMLRPC_FAULT_PARSE_ERROR_INVALID_CHARACTER_FOR_ENCODING = -32702,
+ SOUP_XMLRPC_FAULT_SERVER_ERROR_INVALID_XML_RPC = -32600,
+ SOUP_XMLRPC_FAULT_SERVER_ERROR_REQUESTED_METHOD_NOT_FOUND = -32601,
+ SOUP_XMLRPC_FAULT_SERVER_ERROR_INVALID_METHOD_PARAMETERS = -32602,
+ SOUP_XMLRPC_FAULT_SERVER_ERROR_INTERNAL_XML_RPC_ERROR = -32603,
+ SOUP_XMLRPC_FAULT_APPLICATION_ERROR = -32500,
+ SOUP_XMLRPC_FAULT_SYSTEM_ERROR = -32400,
+ SOUP_XMLRPC_FAULT_TRANSPORT_ERROR = -32300
+} SoupXMLRPCFault;
+
G_END_DECLS
-#endif /* SOUP_XMLRPC_VARIANT_H */
+#endif /* SOUP_XMLRPC_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]