Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 129 +++++++++++++++++++++++++++++++++-----------
1 files changed, 98 insertions(+), 31 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index d41ad53..c4e4ef7 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -1140,43 +1140,85 @@ static int parse_mem_device(xmlNode *node, struct virt_device
**vdevs)
return 0;
}
-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_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(node, 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,
+ "graphics",
+ TYPE_NODE,
+ "devices");
+
+ fetch_from_others(&gdev->others,
+ "console",
+ TYPE_NODE,
+ "devices");
+
+ fetch_from_others(&gdev->others,
+ "serial",
+ TYPE_NODE,
+ "devices");
+
+ gdev->type = fetch_from_others(&gdev->others,
+ "type",
+ TYPE_PROP,
+ (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,
+ "port",
+ TYPE_PROP,
+ (char *)node->name);
+
+ if (gdev->dev.vnc.port == NULL) {
+ gdev->dev.vnc.port = strdup("-1");
+ }
+
+ gdev->dev.vnc.host = fetch_from_others(&gdev->others,
+ "listen",
+ TYPE_PROP,
+ (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,
+ "keymap",
+ TYPE_PROP,
+ (char *)node->name);
+
+ gdev->dev.vnc.passwd = fetch_from_others(&gdev->others,
+ "passwd",
+ TYPE_PROP,
+ (char *)node->name);
if (gdev->dev.vnc.port == NULL || gdev->dev.vnc.host == NULL) {
CU_DEBUG("Error vnc port '%p' host
'%p'",
@@ -1185,25 +1227,50 @@ 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,
+ "display",
+ TYPE_PROP,
+ (char *)node->name);
+
+ gdev->dev.sdl.xauth = fetch_from_others(&gdev->others,
+ "xauth",
+ TYPE_PROP,
+ (char *)node->name);
+
+ gdev->dev.sdl.fullscreen = fetch_from_others(&gdev->others,
+ "fullscreen",
+ TYPE_PROP,
+ (char *)node->name);
}
else if (STREQC(gdev->type, "pty")) {
- if (node->name == NULL)
+ if (node->name == NULL) {
+ CU_DEBUG("no name");
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,
+ "source",
+ TYPE_NODE,
+ (char *)node->name)) {
+ gdev->dev.vnc.host = fetch_from_others(&gdev->others,
+ "path",
+ TYPE_PROP,
+ "source");
+ }
+
+ if (seek_in_others(&gdev->others,
+ "target",
+ TYPE_NODE,
+ (char *)node->name)) {
+ gdev->dev.vnc.port = fetch_from_others(&gdev->others,
+ "port",
+ TYPE_PROP,
+ "target");
}
}
else {
--
1.7.1