From: Xu Wang <cngesaint(a)gmail.com>
Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 155 +++++++++++++++++++++++++++++++++++----------
libxkutil/device_parsing.h | 1 +
2 files changed, 121 insertions(+), 35 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 8edd2e3..c77f3e5 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -202,6 +202,7 @@ static void cleanup_graphics_device(struct graphics_device *dev)
cleanup_vnc_device(dev);
free(dev->type);
+ cleanup_others(dev->others);
}
static void cleanup_path_device(struct path_device *dev)
@@ -1631,17 +1632,6 @@ static int parse_mem_device(xmlNode *node, struct virt_device
**vdevs)
return ret;
}
-static char *get_attr_value_default(xmlNode *node, char *attrname,
- const char *default_value)
-{
- char *ret = get_attr_value(node, attrname);
-
- if (ret == NULL && default_value != NULL)
- ret = strdup(default_value);
-
- return ret;
-}
-
static int parse_console_device(xmlNode *node, struct virt_device **vdevs)
{
struct virt_device *vdev = NULL;
@@ -1916,28 +1906,91 @@ static int parse_graphics_device(xmlNode *node, struct virt_device
**vdevs)
{
struct virt_device *vdev = NULL;
struct graphics_device *gdev = NULL;
- xmlNode *child = NULL;
int ret;
+ CU_DEBUG("Enter parse_graphics_device().");
+
vdev = calloc(1, sizeof(*vdev));
- if (vdev == NULL)
+ if (vdev == NULL) {
+ CU_DEBUG("calloc failed.");
goto err;
+ }
gdev = &(vdev->dev.graphics);
- gdev->type = get_attr_value(node, "type");
- if (gdev->type == NULL)
+ gdev->others = parse_data_to_others(gdev->others,
+ node,
+ 0,
+ BAD_CAST "devices");
+ if (gdev->others == NULL) {
+ CU_DEBUG("parse data to others failed.");
goto err;
+ }
+
+ /* fetch out <graphics> tag from others. It will be removed
+ * after others management finished. */
+ fetch_from_others(&gdev->others,
+ -1,
+ "graphics",
+ TYPE_NODE,
+ -1,
+ "devices");
+ fetch_from_others(&gdev->others,
+ -1,
+ "serial",
+ TYPE_NODE,
+ -1,
+ "devices");
+
+ gdev->type = fetch_from_others(&gdev->others,
+ -1,
+ "type",
+ TYPE_PROP,
+ -1,
+ (char *)node->name);
+ if (gdev->type == NULL) {
+ CU_DEBUG("no type");
+ goto err;
+ }
CU_DEBUG("graphics device type = %s", gdev->type);
if (STREQC(gdev->type, "vnc")) {
- gdev->dev.vnc.port = get_attr_value_default(node, "port",
- "-1");
- gdev->dev.vnc.host = get_attr_value_default(node, "listen",
- "127.0.0.1");
- gdev->dev.vnc.keymap = get_attr_value(node, "keymap");
- gdev->dev.vnc.passwd = get_attr_value(node, "passwd");
+ gdev->dev.vnc.port = fetch_from_others(&gdev->others,
+ -1,
+ "port",
+ TYPE_PROP,
+ -1,
+ (char *)node->name);
+
+ if (gdev->dev.vnc.port == NULL) {
+ gdev->dev.vnc.port = strdup("-1");
+ }
+
+ gdev->dev.vnc.host = fetch_from_others(&gdev->others,
+ -1,
+ "listen",
+ TYPE_PROP,
+ -1,
+ (char *)node->name);
+
+ if (gdev->dev.vnc.host == NULL) {
+ gdev->dev.vnc.host = strdup("127.0.0.1");
+ }
+
+ gdev->dev.vnc.keymap = fetch_from_others(&gdev->others,
+ -1,
+ "keymap",
+ TYPE_PROP,
+ -1,
+ (char *)node->name);
+
+ gdev->dev.vnc.passwd = fetch_from_others(&gdev->others,
+ -1,
+ "passwd",
+ TYPE_PROP,
+ -1,
+ (char *)node->name);
if (gdev->dev.vnc.port == NULL || gdev->dev.vnc.host == NULL) {
CU_DEBUG("Error vnc port '%p' host
'%p'",
@@ -1946,27 +1999,59 @@ static int parse_graphics_device(xmlNode *node, struct virt_device
**vdevs)
}
}
else if (STREQC(gdev->type, "sdl")) {
- gdev->dev.sdl.display = get_attr_value(node, "display");
- gdev->dev.sdl.xauth = get_attr_value(node, "xauth");
- gdev->dev.sdl.fullscreen = get_attr_value(node,
"fullscreen");
+ gdev->dev.sdl.display = fetch_from_others(&gdev->others,
+ -1,
+ "display",
+ TYPE_PROP,
+ -1,
+ (char *)node->name);
+
+ gdev->dev.sdl.xauth = fetch_from_others(&gdev->others,
+ -1,
+ "xauth",
+ TYPE_PROP,
+ -1,
+ (char *)node->name);
+
+ gdev->dev.sdl.fullscreen = fetch_from_others(&gdev->others,
+ -1,
+ "fullscreen",
+ TYPE_PROP,
+ -1,
+ (char *)node->name);
}
else if (STREQC(gdev->type, "pty")) {
- if (node->name == NULL)
- goto err;
-
/* Change type to serial, console, etc. It will be converted
* back in xmlgen.c */
free(gdev->type);
gdev->type = strdup((char *)node->name);
- for (child = node->children; child != NULL;
- child = child->next) {
- if (XSTREQ(child->name, "source"))
- gdev->dev.vnc.host = get_attr_value(child,
"path");
- else if (XSTREQ(child->name, "target")) {
- gdev->dev.vnc.port =
- get_attr_value(child, "port");
- }
+ if (seek_in_others(&gdev->others,
+ -1,
+ "source",
+ TYPE_NODE,
+ -1,
+ (char *)node->name)) {
+ gdev->dev.vnc.host = fetch_from_others(&gdev->others,
+ -1,
+ "path",
+ TYPE_PROP,
+ -1,
+ "source");
+ }
+
+ if (seek_in_others(&gdev->others,
+ -1,
+ "target",
+ TYPE_NODE,
+ -1,
+ (char *)node->name)) {
+ gdev->dev.vnc.port = fetch_from_others(&gdev->others,
+ -1,
+ "port",
+ TYPE_PROP,
+ -1,
+ "target");
}
}
else {
diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h
index 24b7c1d..b29e58c 100644
--- a/libxkutil/device_parsing.h
+++ b/libxkutil/device_parsing.h
@@ -143,6 +143,7 @@ struct graphics_device {
struct vnc_device vnc;
struct sdl_device sdl;
} dev;
+ struct others *others;
};
struct path_device {
--
1.8.3.1