Blame SOURCES/0040-vm-Set-ticket-expiry-using-OvirtXmlElement-struct.patch

2aba60
From 3a92d61ba92b85c0d31aa836713344085dab813e Mon Sep 17 00:00:00 2001
2aba60
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
2aba60
Date: Wed, 10 May 2017 15:16:27 -0300
2aba60
Subject: [PATCH] vm: Set 'ticket/expiry' using OvirtXmlElement struct
2aba60
2aba60
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2aba60
---
2aba60
 govirt/ovirt-vm.c | 56 +++++++++++++++++++++++++++++++------------------------
2aba60
 1 file changed, 32 insertions(+), 24 deletions(-)
2aba60
2aba60
diff --git a/govirt/ovirt-vm.c b/govirt/ovirt-vm.c
2aba60
index 95c1e4d..8cd482b 100644
2aba60
--- a/govirt/ovirt-vm.c
2aba60
+++ b/govirt/ovirt-vm.c
2aba60
@@ -381,48 +381,56 @@ gboolean ovirt_vm_stop(OvirtVm *vm, OvirtProxy *proxy, GError **error)
2aba60
 
2aba60
 static gboolean parse_ticket_status(RestXmlNode *root, OvirtResource *resource, GError **error)
2aba60
 {
2aba60
-    OvirtVm *vm;
2aba60
-    RestXmlNode *node;
2aba60
-    const char *ticket_key = g_intern_string("ticket");
2aba60
-    const char *value_key = g_intern_string("value");
2aba60
-    const char *expiry_key = g_intern_string("expiry");
2aba60
     OvirtVmDisplay *display;
2aba60
+    gchar *ticket = NULL;
2aba60
+    guint expiry = 0;
2aba60
+    gboolean ret = FALSE;
2aba60
+    OvirtXmlElement ticket_elements[] = {
2aba60
+        { .prop_name = "ticket",
2aba60
+          .xml_path = "value",
2aba60
+        },
2aba60
+        { .prop_name = "expiry",
2aba60
+          .xml_path = "expiry",
2aba60
+        },
2aba60
+        { NULL, },
2aba60
+    };
2aba60
 
2aba60
     g_return_val_if_fail(root != NULL, FALSE);
2aba60
     g_return_val_if_fail(OVIRT_IS_VM(resource), FALSE);
2aba60
     g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
2aba60
 
2aba60
-    vm = OVIRT_VM(resource);
2aba60
-    root = g_hash_table_lookup(root->children, ticket_key);
2aba60
+    g_object_get(G_OBJECT(resource), "display", &display, NULL);
2aba60
+    g_return_val_if_fail(display != NULL, FALSE);
2aba60
+
2aba60
+    root = rest_xml_node_find(root, "ticket");
2aba60
     if (root == NULL) {
2aba60
         g_set_error(error, OVIRT_ERROR, OVIRT_ERROR_PARSING_FAILED,
2aba60
                     _("Could not find 'ticket' node"));
2aba60
-        g_return_val_if_reached(FALSE);
2aba60
+        goto end;
2aba60
     }
2aba60
-    node = g_hash_table_lookup(root->children, value_key);
2aba60
-    if (node == NULL) {
2aba60
+
2aba60
+    ovirt_rest_xml_node_parse(root, G_OBJECT(display), ticket_elements);
2aba60
+
2aba60
+    g_object_get(G_OBJECT(display), "ticket", &ticket, "expiry", &expiry, NULL);
2aba60
+
2aba60
+    if (ticket == NULL) {
2aba60
         g_set_error(error, OVIRT_ERROR, OVIRT_ERROR_PARSING_FAILED,
2aba60
                     _("Could not find 'value' node"));
2aba60
-        g_return_val_if_reached(FALSE);
2aba60
+        goto end;
2aba60
     }
2aba60
+    g_free(ticket);
2aba60
 
2aba60
-    g_object_get(G_OBJECT(vm), "display", &display, NULL);
2aba60
-    g_return_val_if_fail(display != NULL, FALSE);
2aba60
-    g_object_set(G_OBJECT(display), "ticket", node->content, NULL);
2aba60
-
2aba60
-    node = g_hash_table_lookup(root->children, expiry_key);
2aba60
-    if (node == NULL) {
2aba60
+    if (expiry == 0) {
2aba60
         g_set_error(error, OVIRT_ERROR, OVIRT_ERROR_PARSING_FAILED,
2aba60
                     _("Could not find 'expiry' node"));
2aba60
-        g_object_unref(G_OBJECT(display));
2aba60
-        g_return_val_if_reached(FALSE);
2aba60
+        goto end;
2aba60
     }
2aba60
-    g_object_set(G_OBJECT(display),
2aba60
-                 "expiry", strtoul(node->content, NULL, 0),
2aba60
-                 NULL);
2aba60
+
2aba60
+    ret = TRUE;
2aba60
+
2aba60
+end:
2aba60
     g_object_unref(G_OBJECT(display));
2aba60
-
2aba60
-    return TRUE;
2aba60
+    return ret;
2aba60
 }
2aba60
 
2aba60
 
2aba60
-- 
2aba60
2.14.4
2aba60