Signed-off-by: Xu Wang <gesaint(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 135 +++++++++++++++++++++++++++++++++++--------
1 files changed, 110 insertions(+), 25 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index b8a0c73..b345db2 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -1826,10 +1826,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)
{
- const char *action = (char *)xmlNodeGetContent(child);
-
if (action == NULL)
*val = CIM_VSSD_RECOVERY_NONE;
else if (STREQ(action, "destroy"))
@@ -1846,30 +1844,117 @@ static int parse_domain(xmlNodeSet *nsv, struct domain *dominfo)
{
xmlNode **nodes = nsv->nodeTab;
xmlNode *child;
+ xmlAttrPtr xmlAttr = NULL;
+ struct others *new_others = 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,
+ nodes[0]->name);
+ xmlAttr = xmlAttr->next;
+ }
+
+ dominfo->typestr = fetch_from_others(&dominfo->others,
+ "type",
+ TYPE_PROP,
+ (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 {
+ new_others = parse_data_to_others(child, nodes[0]->name);
+ dominfo->others = combine_others(dominfo->others,
+ new_others);
+ }
+ }
- dominfo->typestr = get_attr_value(nodes[0], "type");
+ dominfo->name = fetch_from_others(&dominfo->others,
+ "name",
+ TYPE_NODE,
+ (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,
+ "uuid",
+ TYPE_NODE,
+ (char *)nodes[0]->name);
+
+ dominfo->bootloader = fetch_from_others(&dominfo->others,
+ "bootloader",
+ TYPE_NODE,
+ (char *)nodes[0]->name);
+
+ dominfo->bootloader_args = fetch_from_others(&dominfo->others,
+ "bootloader_args",
+ TYPE_NODE,
+ (char *)nodes[0]->name);
+
+ if (seek_in_others(&dominfo->others,
+ "os",
+ TYPE_NODE,
+ (char *)nodes[0]->name)) {
+ /* parse_os(); */
+ }
+
+ action = fetch_from_others(&dominfo->others,
+ "on_poweroff",
+ TYPE_NODE,
+ (char *)nodes[0]->name);
+ if (action) {
+ set_action(&dominfo->on_poweroff, action);
+ free(action);
+ }
+
+ action = fetch_from_others(&dominfo->others,
+ "on_reboot",
+ TYPE_NODE,
+ (char *)nodes[0]->name);
+ if (action) {
+ set_action(&dominfo->on_reboot, action);
+ free(action);
+ }
+
+ action = fetch_from_others(&dominfo->others,
+ "on_crash",
+ TYPE_NODE,
+ (char *)nodes[0]->name);
+ if (action) {
+ set_action(&dominfo->on_crash, action);
+ free(action);
+ }
+
+ if (seek_in_others(&dominfo->others,
+ "clock",
+ TYPE_NODE,
+ (char *)nodes[0]->name)) {
+ dominfo->clock = fetch_from_others(&dominfo->others,
+ "offset",
+ TYPE_PROP,
+ "clock");
+ }
+
+ if (seek_in_others(&dominfo->others,
+ "features",
+ TYPE_NODE,
+ (char *)nodes[0]->name)) {
+ /* parse_features(); */
}
return 1;
--
1.7.1