[Libvirt-cim] [PATCH 33/47] Fix xml generation algorithm in graphics_pty_xml()

Xu Wang gesaint at linux.vnet.ibm.com
Tue Oct 8 06:14:07 UTC 2013


Signed-off-by: Xu Wang <gesaint at linux.vnet.ibm.com>
---
 libxkutil/xmlgen.c |   65 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 5bfdc81..6b07b00 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -1199,28 +1199,67 @@ static const char *graphics_vnc_xml(xmlNodePtr root,
 static const char *graphics_pty_xml(xmlNodePtr root,
                        struct graphics_device *dev)
 {
-        xmlNodePtr pty = NULL;
-        xmlNodePtr tmp = NULL;
+        CU_DEBUG("Enter graphics_pty_xml()");
+
+        dev->others = add_node_to_others(dev->others,
+                                         dev->type,
+                                         NULL,
+                                         TYPE_NODE,
+                                         "devices");
 
-        pty = xmlNewChild(root, NULL, BAD_CAST dev->type, NULL);
-        if (pty == NULL)
+        if (dev->others == NULL) {
+                CU_DEBUG("add node <%s> failed.", dev->type);
                 return XML_ERROR;
+        }
 
-        xmlNewProp(pty, BAD_CAST "type", BAD_CAST "pty");
+        dev->others = add_node_to_others(dev->others,
+                                         "type",
+                                         "pty",
+                                         TYPE_PROP,
+                                         dev->type);
 
-        tmp = xmlNewChild(pty, NULL, BAD_CAST "source", NULL);
-        if (tmp == NULL)
+        dev->others = add_node_to_others(dev->others,
+                                         "source",
+                                         NULL,
+                                         TYPE_NODE,
+                                         dev->type);
+
+        if (dev->others == NULL) {
+                CU_DEBUG("add node <source> failed.");
                 return XML_ERROR;
+        }
+
+        if(dev->dev.vnc.host) {
+                dev->others = add_node_to_others(dev->others,
+                                                 "path",
+                                                 dev->dev.vnc.host,
+                                                 TYPE_PROP,
+                                                 "source");
+        }
 
-        if(dev->dev.vnc.host)
-                xmlNewProp(tmp, BAD_CAST "path", BAD_CAST dev->dev.vnc.host);
+        dev->others = add_node_to_others(dev->others,
+                                         "target",
+                                         NULL,
+                                         TYPE_NODE,
+                                         dev->type);
 
-        tmp = xmlNewChild(pty, NULL, BAD_CAST "target", NULL);
-        if (tmp == NULL)
+        if (dev->others == NULL) {
+                CU_DEBUG("add node <target> failed.");
                 return XML_ERROR;
+        }
 
-        if(dev->dev.vnc.port)
-                xmlNewProp(tmp, BAD_CAST "port", BAD_CAST dev->dev.vnc.port);
+        if(dev->dev.vnc.port) {
+                dev->others = add_node_to_others(dev->others,
+                                                 "port",
+                                                 dev->dev.vnc.port,
+                                                 TYPE_PROP,
+                                                 "target");
+        }
+
+        dev->others = others_to_xml(root, dev->others, "devices");
+        if (dev->others) {
+                CU_DEBUG("others_to_xml failed.");
+        }
 
         return NULL;
 }
-- 
1.7.1




More information about the Libvirt-cim mailing list