[libgovirt] Add ovirt_utils_gerror_from_xml_fault()
- From: Christophe Fergeau <teuf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgovirt] Add ovirt_utils_gerror_from_xml_fault()
- Date: Tue, 8 Oct 2013 17:05:01 +0000 (UTC)
commit 691a941acec291fd17fb4378698e38a7b768dc6d
Author: Christophe Fergeau <cfergeau redhat com>
Date: Thu Aug 29 20:51:08 2013 +0200
Add ovirt_utils_gerror_from_xml_fault()
This moves some code from OvirtVm to ovirt-utils.h as this will
be useful in more situations than just parsing action responses.
govirt/ovirt-utils.c | 33 +++++++++++++++++++++++++++++++++
govirt/ovirt-utils.h | 1 +
govirt/ovirt-vm.c | 21 +--------------------
3 files changed, 35 insertions(+), 20 deletions(-)
---
diff --git a/govirt/ovirt-utils.c b/govirt/ovirt-utils.c
index f165689..618992a 100644
--- a/govirt/ovirt-utils.c
+++ b/govirt/ovirt-utils.c
@@ -28,6 +28,8 @@
#include "ovirt-utils.h"
+#include "ovirt-error.h"
+
RestXmlNode *
ovirt_rest_xml_node_from_call(RestProxyCall *call)
{
@@ -134,3 +136,34 @@ G_GNUC_INTERNAL const char *ovirt_utils_strip_api_base_dir(const char *path)
return path;
}
+
+
+G_GNUC_INTERNAL gboolean ovirt_utils_gerror_from_xml_fault(RestXmlNode *root, GError **error)
+{
+ RestXmlNode *reason_node;
+ RestXmlNode *detail_node;
+ const char *reason_key = g_intern_string("reason");
+ const char *detail_key = g_intern_string("detail");
+
+ g_return_val_if_fail((error == NULL) || (*error == NULL), FALSE);
+
+ if (g_strcmp0(root->name, "fault") != 0)
+ return FALSE;
+
+ reason_node = g_hash_table_lookup(root->children, reason_key);
+ if (reason_node == NULL) {
+ g_set_error(error, OVIRT_ERROR, OVIRT_ERROR_PARSING_FAILED, "could not find 'reason' node");
+ g_return_val_if_reached(FALSE);
+ }
+ g_debug("Reason: %s\n", reason_node->content);
+ detail_node = g_hash_table_lookup(root->children, detail_key);
+ if (detail_node != NULL) {
+ g_set_error(error, OVIRT_ERROR, OVIRT_ERROR_FAILED, "%s: %s",
+ reason_node->content, detail_node->content);
+ } else {
+ g_set_error(error, OVIRT_ERROR, OVIRT_ERROR_FAILED, "%s",
+ reason_node->content);
+ }
+
+ return TRUE;
+}
diff --git a/govirt/ovirt-utils.h b/govirt/ovirt-utils.h
index 5c8d42d..935b029 100644
--- a/govirt/ovirt-utils.h
+++ b/govirt/ovirt-utils.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
RestXmlNode *ovirt_rest_xml_node_from_call(RestProxyCall *call);
const char *ovirt_rest_xml_node_get_content(RestXmlNode *node, ...);
+gboolean ovirt_utils_gerror_from_xml_fault(RestXmlNode *root, GError **error);
const char *ovirt_utils_genum_get_nick (GType enum_type, gint value);
int ovirt_utils_genum_get_value (GType enum_type, const char *nick,
diff --git a/govirt/ovirt-vm.c b/govirt/ovirt-vm.c
index fbcccf6..7437bae 100644
--- a/govirt/ovirt-vm.c
+++ b/govirt/ovirt-vm.c
@@ -446,25 +446,6 @@ static enum OvirtResponseStatus parse_action_status(RestXmlNode *root,
g_return_val_if_reached(OVIRT_RESPONSE_UNKNOWN);
}
-static void parse_fault(RestXmlNode *root, GError **error)
-{
- RestXmlNode *reason_node;
- RestXmlNode *detail_node;
- const char *reason_key = g_intern_string("reason");
- const char *detail_key = g_intern_string("detail");
-
- g_return_if_fail(g_strcmp0(root->name, "fault") == 0);
-
- reason_node = g_hash_table_lookup(root->children, reason_key);
- if (reason_node == NULL) {
- g_set_error(error, OVIRT_ERROR, OVIRT_ERROR_PARSING_FAILED, "could not find 'reason' node");
- g_return_if_reached();
- }
- g_debug("Reason: %s\n", root->content);
- detail_node = g_hash_table_lookup(root->children, detail_key);
- g_set_error(error, OVIRT_ERROR, OVIRT_ERROR_FAILED, "%s: %s", reason_node->content,
- (detail_node == NULL)?"":detail_node->content);
-}
static gboolean
parse_action_response(RestProxyCall *call, OvirtVm *vm,
@@ -493,7 +474,7 @@ parse_action_response(RestProxyCall *call, OvirtVm *vm,
fault_node = g_hash_table_lookup(root->children, fault_key);
if (fault_node != NULL) {
- parse_fault(fault_node, &fault_error);
+ ovirt_utils_gerror_from_xml_fault(fault_node, &fault_error);
if (fault_error != NULL) {
g_clear_error(error);
g_propagate_error(error, fault_error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]