[libsoup/wip/xmlrpc-variant: 6/11] xmlrpc: Port soup_xmlrpc_build_fault() to GVariant



commit 9e8dd52b97a0fc5de21acf7b559438affb3c8dc4
Author: Xavier Claessens <xavier claessens collabora com>
Date:   Mon Jul 27 16:17:34 2015 -0400

    xmlrpc: Port soup_xmlrpc_build_fault() to GVariant
    
    https://bugzilla.gnome.org/show_bug.cgi?id=746495

 docs/reference/libsoup-2.4-sections.txt |    3 +-
 libsoup/libsoup-2.4.sym                 |    1 +
 libsoup/soup-xmlrpc-old.c               |  163 -----------------------------
 libsoup/soup-xmlrpc-old.h               |   29 -----
 libsoup/soup-xmlrpc.c                   |  172 ++++++++++++++++++++++++++++++-
 libsoup/soup-xmlrpc.h                   |   37 ++++++-
 6 files changed, 209 insertions(+), 196 deletions(-)
---
diff --git a/docs/reference/libsoup-2.4-sections.txt b/docs/reference/libsoup-2.4-sections.txt
index c9bdaad..184fc95 100644
--- a/docs/reference/libsoup-2.4-sections.txt
+++ b/docs/reference/libsoup-2.4-sections.txt
@@ -849,7 +849,7 @@ soup_xmlrpc_parse_request_full
 soup_xmlrpc_build_response
 soup_xmlrpc_build_fault
 soup_xmlrpc_message_set_response
-soup_xmlrpc_set_fault
+soup_xmlrpc_message_set_fault
 <SUBSECTION>
 soup_xmlrpc_build_method_call
 soup_xmlrpc_request_new
@@ -859,6 +859,7 @@ soup_xmlrpc_parse_method_call
 soup_xmlrpc_extract_method_call
 soup_xmlrpc_build_method_response
 soup_xmlrpc_set_response
+soup_xmlrpc_set_fault
 <SUBSECTION Private>
 soup_xmlrpc_error_quark
 soup_xmlrpc_fault_quark
diff --git a/libsoup/libsoup-2.4.sym b/libsoup/libsoup-2.4.sym
index 472f64f..eacd2d5 100644
--- a/libsoup/libsoup-2.4.sym
+++ b/libsoup/libsoup-2.4.sym
@@ -552,6 +552,7 @@ soup_xmlrpc_extract_method_response
 soup_xmlrpc_fault_get_type
 soup_xmlrpc_fault_quark
 soup_xmlrpc_message_new
+soup_xmlrpc_message_set_fault
 soup_xmlrpc_message_set_response
 soup_xmlrpc_new_custom
 soup_xmlrpc_new_datetime
diff --git a/libsoup/soup-xmlrpc-old.c b/libsoup/soup-xmlrpc-old.c
index afc75a1..0bd72ef 100644
--- a/libsoup/soup-xmlrpc-old.c
+++ b/libsoup/soup-xmlrpc-old.c
@@ -291,84 +291,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
@@ -397,35 +319,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.
- **/
-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));
-}
-
-
-
 static gboolean
 parse_value (xmlNode *xmlvalue, GValue *value)
 {
@@ -807,62 +700,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-old.h b/libsoup/soup-xmlrpc-old.h
index f96deec..23db502 100644
--- a/libsoup/soup-xmlrpc-old.h
+++ b/libsoup/soup-xmlrpc-old.h
@@ -37,9 +37,6 @@ gboolean     soup_xmlrpc_extract_method_call     (const char   *method_call,
                                                  char        **method_name,
                                                  ...);
 char        *soup_xmlrpc_build_method_response   (GValue       *value);
-char        *soup_xmlrpc_build_fault             (int           fault_code,
-                                                 const char   *fault_format,
-                                                 ...) G_GNUC_PRINTF (2, 3);
 void         soup_xmlrpc_set_response            (SoupMessage  *msg,
                                                  GType         type,
                                                  ...);
@@ -48,32 +45,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_OLD_H */
diff --git a/libsoup/soup-xmlrpc.c b/libsoup/soup-xmlrpc.c
index c13f133..bfa667d 100644
--- a/libsoup/soup-xmlrpc.c
+++ b/libsoup/soup-xmlrpc.c
@@ -413,6 +413,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.
+ *
+ * Since: 2.52
+ **/
+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.
+ **/
+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
@@ -421,7 +551,7 @@ soup_xmlrpc_build_response (GVariant *value, GError **error)
  *
  * Sets the status code and response body of @msg to indicate a
  * successful XML-RPC call, with a return value given by @value. To set a
- * fault response, use soup_xmlrpc_set_fault().
+ * fault response, use soup_xmlrpc_message_set_fault().
  *
  * See soup_xmlrpc_build_request() for serialization details.
  *
@@ -1350,3 +1480,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 5819f1f..aa94339 100644
--- a/libsoup/soup-xmlrpc.h
+++ b/libsoup/soup-xmlrpc.h
@@ -36,12 +36,12 @@ GVariant    *soup_xmlrpc_params_parse         (SoupXMLRPCParams  *self,
                                               const char       *signature,
                                               GError           **error);
 SOUP_AVAILABLE_IN_2_52
-char       *soup_xmlrpc_parse_request        (const gchar       *method_call,
+char       *soup_xmlrpc_parse_request        (const char       *method_call,
                                               int               length,
                                               SoupXMLRPCParams **params,
                                               GError           **error);
 SOUP_AVAILABLE_IN_2_52
-char       *soup_xmlrpc_parse_request_full   (const gchar       *method_call,
+char       *soup_xmlrpc_parse_request_full   (const char       *method_call,
                                               int               length,
                                               const char       *signature,
                                               GVariant         **parameters,
@@ -49,10 +49,18 @@ char       *soup_xmlrpc_parse_request_full   (const gchar       *method_call,
 SOUP_AVAILABLE_IN_2_52
 char       *soup_xmlrpc_build_response       (GVariant          *value,
                                               GError           **error);
+char       *soup_xmlrpc_build_fault          (int               fault_code,
+                                              const char       *fault_format,
+                                              ...) G_GNUC_PRINTF (2, 3);
 SOUP_AVAILABLE_IN_2_52
 gboolean     soup_xmlrpc_message_set_response (SoupMessage       *msg,
                                               GVariant          *value,
                                               GError           **error);
+SOUP_AVAILABLE_IN_2_52
+void         soup_xmlrpc_message_set_fault    (SoupMessage       *msg,
+                                              int               fault_code,
+                                              const char       *fault_format,
+                                              ...) G_GNUC_PRINTF (3, 4);
 
 /* Utils */
 SOUP_AVAILABLE_IN_2_52
@@ -61,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_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]