Blame SOURCES/0039-vm-display-Move-XML-parsing-from-ovirt-vm-xml.c-file.patch

080a59
From c81f18b9dd4888145ac979addb4ef5d73585a176 Mon Sep 17 00:00:00 2001
080a59
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
080a59
Date: Tue, 19 Sep 2017 12:02:32 -0300
080a59
Subject: [PATCH] vm-display: Move XML parsing from ovirt-vm-xml.c file
080a59
080a59
Following the model of other resources, the code for parsing the XML
080a59
elements for the OvirtVmDisplay object where it really belongs to.
080a59
080a59
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
080a59
---
080a59
 govirt/Makefile.am        |  1 -
080a59
 govirt/ovirt-vm-display.c | 60 +++++++++++++++++++++++++++++
080a59
 govirt/ovirt-vm-display.h |  2 +
080a59
 govirt/ovirt-vm-xml.c     | 96 -----------------------------------------------
080a59
 govirt/ovirt-vm.c         | 15 ++++++--
080a59
 5 files changed, 74 insertions(+), 100 deletions(-)
080a59
 delete mode 100644 govirt/ovirt-vm-xml.c
080a59
080a59
diff --git a/govirt/Makefile.am b/govirt/Makefile.am
080a59
index 9bf0eba..1a59f2c 100644
080a59
--- a/govirt/Makefile.am
080a59
+++ b/govirt/Makefile.am
080a59
@@ -73,7 +73,6 @@ libgovirt_la_SOURCES =						\
080a59
 	ovirt-utils.c						\
080a59
 	ovirt-vm.c						\
080a59
 	ovirt-vm-display.c					\
080a59
-	ovirt-vm-xml.c						\
080a59
 	ovirt-vm-pool.c						\
080a59
 	$(NULL)
080a59
 
080a59
diff --git a/govirt/ovirt-vm-display.c b/govirt/ovirt-vm-display.c
080a59
index b03c303..ebb04c2 100644
080a59
--- a/govirt/ovirt-vm-display.c
080a59
+++ b/govirt/ovirt-vm-display.c
080a59
@@ -24,6 +24,7 @@
080a59
 
080a59
 #include "ovirt-enum-types.h"
080a59
 #include "ovirt-vm-display.h"
080a59
+#include "ovirt-utils.h"
080a59
 
080a59
 #define OVIRT_VM_DISPLAY_GET_PRIVATE(obj)                         \
080a59
         (G_TYPE_INSTANCE_GET_PRIVATE((obj), OVIRT_TYPE_VM_DISPLAY, OvirtVmDisplayPrivate))
080a59
@@ -303,3 +304,62 @@ OvirtVmDisplay *ovirt_vm_display_new(void)
080a59
 {
080a59
     return OVIRT_VM_DISPLAY(g_object_new(OVIRT_TYPE_VM_DISPLAY, NULL));
080a59
 }
080a59
+
080a59
+static gboolean ovirt_vm_display_set_from_xml(OvirtVmDisplay *display, RestXmlNode *node)
080a59
+{
080a59
+    OvirtVmDisplayType type;
080a59
+    OvirtXmlElement display_elements[] = {
080a59
+        { .prop_name = "type",
080a59
+          .xml_path = "type",
080a59
+        },
080a59
+        { .prop_name = "address",
080a59
+          .xml_path = "address",
080a59
+        },
080a59
+        { .prop_name = "port",
080a59
+          .xml_path = "port",
080a59
+        },
080a59
+        { .prop_name = "secure-port",
080a59
+          .xml_path = "secure_port",
080a59
+        },
080a59
+        { .prop_name = "monitor-count",
080a59
+          .xml_path = "monitors",
080a59
+        },
080a59
+        { .prop_name = "smartcard",
080a59
+          .xml_path = "smartcard_enabled",
080a59
+        },
080a59
+        { .prop_name = "allow-override",
080a59
+          .xml_path = "allow_override",
080a59
+        },
080a59
+        { .prop_name = "host-subject",
080a59
+          .xml_path = "certificate/subject",
080a59
+        },
080a59
+        { .prop_name = "proxy-url",
080a59
+          .xml_path = "proxy",
080a59
+        },
080a59
+        { NULL, },
080a59
+    };
080a59
+
080a59
+    ovirt_rest_xml_node_parse(node, G_OBJECT(display), display_elements);
080a59
+    g_object_get(G_OBJECT(display), "type", &type, NULL);
080a59
+    if (type == OVIRT_VM_DISPLAY_INVALID) {
080a59
+        return FALSE;
080a59
+    }
080a59
+
080a59
+    return TRUE;
080a59
+}
080a59
+
080a59
+OvirtVmDisplay *ovirt_vm_display_new_from_xml(RestXmlNode *node)
080a59
+{
080a59
+    OvirtVmDisplay *display;
080a59
+
080a59
+    g_return_val_if_fail(node != NULL, NULL);
080a59
+
080a59
+    display = ovirt_vm_display_new();
080a59
+
080a59
+    if (!ovirt_vm_display_set_from_xml(display, node)) {
080a59
+        g_object_unref(display);
080a59
+        return NULL;
080a59
+    }
080a59
+
080a59
+    return display;
080a59
+}
080a59
diff --git a/govirt/ovirt-vm-display.h b/govirt/ovirt-vm-display.h
080a59
index 38ef9b7..11a5074 100644
080a59
--- a/govirt/ovirt-vm-display.h
080a59
+++ b/govirt/ovirt-vm-display.h
080a59
@@ -24,6 +24,7 @@
080a59
 
080a59
 #include <glib-object.h>
080a59
 #include <govirt/ovirt-types.h>
080a59
+#include <rest/rest-xml-node.h>
080a59
 
080a59
 G_BEGIN_DECLS
080a59
 
080a59
@@ -61,6 +62,7 @@ typedef enum {
080a59
 
080a59
 GType ovirt_vm_display_get_type(void);
080a59
 OvirtVmDisplay *ovirt_vm_display_new(void);
080a59
+OvirtVmDisplay *ovirt_vm_display_new_from_xml(RestXmlNode *node);
080a59
 
080a59
 G_END_DECLS
080a59
 
080a59
diff --git a/govirt/ovirt-vm-xml.c b/govirt/ovirt-vm-xml.c
080a59
deleted file mode 100644
080a59
index 0603427..0000000
080a59
--- a/govirt/ovirt-vm-xml.c
080a59
+++ /dev/null
080a59
@@ -1,96 +0,0 @@
080a59
-/*
080a59
- * ovirt-vm-xml.c
080a59
- *
080a59
- * Copyright (C) 2011, 2013 Red Hat, Inc.
080a59
- *
080a59
- * This library is free software; you can redistribute it and/or
080a59
- * modify it under the terms of the GNU Lesser General Public
080a59
- * License as published by the Free Software Foundation; either
080a59
- * version 2.1 of the License, or (at your option) any later version.
080a59
- *
080a59
- * This library is distributed in the hope that it will be useful,
080a59
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
080a59
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
080a59
- * Lesser General Public License for more details.
080a59
- *
080a59
- * You should have received a copy of the GNU Lesser General Public
080a59
- * License along with this library. If not, see
080a59
- * <http://www.gnu.org/licenses/>.
080a59
- *
080a59
- * Author: Christophe Fergeau <cfergeau@redhat.com>
080a59
- */
080a59
-#include <config.h>
080a59
-
080a59
-#include <stdlib.h>
080a59
-#include <string.h>
080a59
-
080a59
-#include "ovirt-enum-types.h"
080a59
-#include "ovirt-utils.h"
080a59
-#include "ovirt-vm.h"
080a59
-#include "ovirt-vm-display.h"
080a59
-#include "ovirt-vm-private.h"
080a59
-
080a59
-static gboolean vm_set_display_from_xml(OvirtVm *vm,
080a59
-                                        RestXmlNode *root)
080a59
-{
080a59
-    OvirtVmDisplay *display;
080a59
-    OvirtVmDisplayType type;
080a59
-    OvirtXmlElement display_elements[] = {
080a59
-        { .prop_name = "type",
080a59
-          .xml_path = "type",
080a59
-        },
080a59
-        { .prop_name = "address",
080a59
-          .xml_path = "address",
080a59
-        },
080a59
-        { .prop_name = "port",
080a59
-          .xml_path = "port",
080a59
-        },
080a59
-        { .prop_name = "secure-port",
080a59
-          .xml_path = "secure_port",
080a59
-        },
080a59
-        { .prop_name = "monitor-count",
080a59
-          .xml_path = "monitors",
080a59
-        },
080a59
-        { .prop_name = "smartcard",
080a59
-          .xml_path = "smartcard_enabled",
080a59
-        },
080a59
-        { .prop_name = "allow-override",
080a59
-          .xml_path = "allow_override",
080a59
-        },
080a59
-        { .prop_name = "host-subject",
080a59
-          .xml_path = "certificate/subject",
080a59
-        },
080a59
-        { .prop_name = "proxy-url",
080a59
-          .xml_path = "proxy",
080a59
-        },
080a59
-        { NULL, },
080a59
-    };
080a59
-
080a59
-    if (root == NULL) {
080a59
-        return FALSE;
080a59
-    }
080a59
-    root = rest_xml_node_find(root, "display");
080a59
-    if (root == NULL) {
080a59
-        g_debug("Could not find 'display' node");
080a59
-        return FALSE;
080a59
-    }
080a59
-    display = ovirt_vm_display_new();
080a59
-    ovirt_rest_xml_node_parse(root, G_OBJECT(display), display_elements);
080a59
-    g_object_get(G_OBJECT(display), "type", &type, NULL);
080a59
-    if (type == OVIRT_VM_DISPLAY_INVALID) {
080a59
-        return FALSE;
080a59
-    }
080a59
-
080a59
-    /* FIXME: this overrides the ticket/expiry which may
080a59
-     * already be set
080a59
-     */
080a59
-    g_object_set(G_OBJECT(vm), "display", display, NULL);
080a59
-    g_object_unref(G_OBJECT(display));
080a59
-
080a59
-    return TRUE;
080a59
-}
080a59
-
080a59
-G_GNUC_INTERNAL gboolean ovirt_vm_refresh_from_xml(OvirtVm *vm, RestXmlNode *node)
080a59
-{
080a59
-    return vm_set_display_from_xml(vm, node);
080a59
-}
080a59
diff --git a/govirt/ovirt-vm.c b/govirt/ovirt-vm.c
080a59
index f30022d..95c1e4d 100644
080a59
--- a/govirt/ovirt-vm.c
080a59
+++ b/govirt/ovirt-vm.c
080a59
@@ -180,7 +180,8 @@ static gboolean ovirt_vm_init_from_xml(OvirtResource *resource,
080a59
                                        RestXmlNode *node,
080a59
                                        GError **error)
080a59
 {
080a59
-    gboolean parsed_ok;
080a59
+    OvirtVmDisplay *display;
080a59
+    RestXmlNode *display_node;
080a59
     OvirtResourceClass *parent_class;
080a59
     OvirtXmlElement vm_elements[] = {
080a59
         { .prop_name = "host-href",
080a59
@@ -205,11 +206,19 @@ static gboolean ovirt_vm_init_from_xml(OvirtResource *resource,
080a59
         { NULL, },
080a59
     };
080a59
 
080a59
-    parsed_ok = ovirt_vm_refresh_from_xml(OVIRT_VM(resource), node);
080a59
-    if (!parsed_ok) {
080a59
+    display_node = rest_xml_node_find(node, "display");
080a59
+    if (display_node == NULL) {
080a59
+        g_debug("Could not find 'display' node");
080a59
         return FALSE;
080a59
     }
080a59
 
080a59
+    display = ovirt_vm_display_new_from_xml(display_node);
080a59
+    if (display == NULL)
080a59
+        return FALSE;
080a59
+
080a59
+    g_object_set(G_OBJECT(resource), "display", display, NULL);
080a59
+    g_object_unref(G_OBJECT(display));
080a59
+
080a59
     if (!ovirt_rest_xml_node_parse(node, G_OBJECT(resource), vm_elements))
080a59
         return FALSE;
080a59
 
080a59
-- 
080a59
2.14.4
080a59