Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 162 ++++++++++++++++++++++++++++++++++++-------
1 files changed, 135 insertions(+), 27 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 8f1a46c..0bd3cfa 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -2564,10 +2564,8 @@ static int parse_features(struct domain *dominfo, xmlNode
*features)
return 1;
}
-static void set_action(int *val, xmlNode *child)
+static void set_action(int *val, const char *action)
{
- char *action = (char *)xmlNodeGetContent(child);
-
if (action == NULL)
*val = CIM_VSSD_RECOVERY_NONE;
else if (STREQ(action, "destroy"))
@@ -2578,38 +2576,148 @@ static void set_action(int *val, xmlNode *child)
*val = CIM_VSSD_RECOVERY_RESTART;
else
*val = CIM_VSSD_RECOVERY_NONE;
-
- xmlFree(action);
}
static int parse_domain(xmlNodeSet *nsv, struct domain *dominfo)
{
xmlNode **nodes = nsv->nodeTab;
xmlNode *child;
+ xmlAttrPtr xmlAttr = NULL;
+ char *action = NULL;
+
+ CU_DEBUG("Enter parse_domain()");
+
+ /* parsing attributions of domain into others */
+ xmlAttr = nodes[0]->properties;
+ while(xmlAttr) {
+ dominfo->others = add_others(dominfo->others,
+ nodes[0],
+ xmlAttr->name,
+ TYPE_PROP,
+ 0,
+ nodes[0]->name);
+ xmlAttr = xmlAttr->next;
+ }
+
+ dominfo->typestr = fetch_from_others(&dominfo->others,
+ -1,
+ "type",
+ TYPE_PROP,
+ -1,
+ (char *)nodes[0]->name);
+
+ /* parse every item in the field of domain and skip some will be parsed
+ * in other functions. The white list contains:
+ * <memory> (parsed in parse_mem_device())
+ * <currentMemory> (parsed in parse_mem_device())
+ * <vcpu> (parsed in parse_vcpu_device())
+ * <devices> (parsed in other parse_*_device())
+ */
+ for (child = nodes[0]->children; child != NULL; child = child->next) {
+ if (XSTREQ(child->name, "memory") ||
+ XSTREQ(child->name, "currentMemory") ||
+ XSTREQ(child->name, "vcpu") ||
+ XSTREQ(child->name, "devices")) {
+ continue;
+ } else {
+ dominfo->others = parse_data_to_others(dominfo->others,
+ child,
+ 0,
+ nodes[0]->name);
+ }
+ }
- dominfo->typestr = get_attr_value(nodes[0], "type");
+ dominfo->name = fetch_from_others(&dominfo->others,
+ -1,
+ "name",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
- for (child = nodes[0]->children; child != NULL; child = child->next) {
- if (XSTREQ(child->name, "name"))
- STRPROP(dominfo, name, child);
- else if (XSTREQ(child->name, "uuid"))
- STRPROP(dominfo, uuid, child);
- else if (XSTREQ(child->name, "bootloader"))
- STRPROP(dominfo, bootloader, child);
- else if (XSTREQ(child->name, "bootloader_args"))
- STRPROP(dominfo, bootloader_args, child);
- else if (XSTREQ(child->name, "os"))
- parse_os(dominfo, child);
- else if (XSTREQ(child->name, "on_poweroff"))
- set_action(&dominfo->on_poweroff, child);
- else if (XSTREQ(child->name, "on_reboot"))
- set_action(&dominfo->on_reboot, child);
- else if (XSTREQ(child->name, "on_crash"))
- set_action(&dominfo->on_crash, child);
- else if (XSTREQ(child->name, "clock"))
- dominfo->clock = get_attr_value(child, "offset");
- else if (XSTREQ(child->name, "features"))
- parse_features(dominfo, child);
+ dominfo->uuid = fetch_from_others(&dominfo->others,
+ -1,
+ "uuid",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+
+ dominfo->bootloader = fetch_from_others(&dominfo->others,
+ -1,
+ "bootloader",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+
+ dominfo->bootloader_args = fetch_from_others(&dominfo->others,
+ -1,
+ "bootloader_args",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+
+ if (seek_in_others(&dominfo->others,
+ -1,
+ "os",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name)) {
+ /* parse_os(); */
+ }
+
+ action = fetch_from_others(&dominfo->others,
+ -1,
+ "on_poweroff",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+ if (action) {
+ set_action(&dominfo->on_poweroff, action);
+ free(action);
+ }
+
+ action = fetch_from_others(&dominfo->others,
+ -1,
+ "on_reboot",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+ if (action) {
+ set_action(&dominfo->on_reboot, action);
+ free(action);
+ }
+
+ action = fetch_from_others(&dominfo->others,
+ -1,
+ "on_crash",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name);
+ if (action) {
+ set_action(&dominfo->on_crash, action);
+ free(action);
+ }
+
+ if (seek_in_others(&dominfo->others,
+ -1,
+ "clock",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name)) {
+ dominfo->clock = fetch_from_others(&dominfo->others,
+ -1,
+ "offset",
+ TYPE_PROP,
+ -1,
+ "clock");
+ }
+
+ if (seek_in_others(&dominfo->others,
+ -1,
+ "features",
+ TYPE_NODE,
+ -1,
+ (char *)nodes[0]->name)) {
+ /* parse_features(); */
}
return 1;
--
1.7.1