GPtrArray *create_derivation_array(const gchar *distributed_derivation_file) { /* Declarations */ xmlDocPtr doc; xmlNodePtr node_root; xmlXPathObjectPtr result; GPtrArray *derivation_array = NULL; /* Parse the XML document */ if((doc = xmlParseFile(distributed_derivation_file)) == NULL) { g_printerr("Error with parsing the distributed derivation XML file!\n"); xmlCleanupParser(); return NULL; } /* Retrieve root element */ node_root = xmlDocGetRootElement(doc); if(node_root == NULL) { g_printerr("The distributed derivation XML file is empty!\n"); xmlFreeDoc(doc); xmlCleanupParser(); return NULL; } /* Query the mapping elements */ result = executeXPathQuery(doc, "/distributedderivation/build/mapping"); /* Iterate over all the mapping elements and add them to the array */ if(result) { xmlNodeSetPtr nodeset = result->nodesetval; unsigned int i; /* Create a derivation array */ derivation_array = g_ptr_array_new(); /* Iterate over all the mapping elements */ for(i = 0; i < nodeset->nodeNr; i++) { xmlNodePtr mapping_children = nodeset->nodeTab[i]->children; DerivationItem *item = (DerivationItem*)g_malloc(sizeof(DerivationItem)); gchar *derivation = NULL, *target = NULL; /* Iterate over all the mapping item children (derivation and target elements) */ while(mapping_children != NULL) { if(xmlStrcmp(mapping_children->name, (xmlChar*) "derivation") == 0) derivation = duplicate_node_text(mapping_children); else if(xmlStrcmp(mapping_children->name, (xmlChar*) "target") == 0) target = duplicate_node_text(mapping_children); mapping_children = mapping_children->next; } /* Added the mapping to the array */ item->derivation = derivation; item->target = target; item->result = NULL; if(item->derivation == NULL || item->target == NULL) { /* Check if all mandatory properties have been provided */ g_printerr("A mandatory property seems to be missing. Have you provided a correct\n"); g_printerr("distributed derivation file?\n"); delete_derivation_array(derivation_array); derivation_array = NULL; break; } else g_ptr_array_add(derivation_array, item); /* Add item to the array */ } xmlXPathFreeObject(result); } /* Cleanup */ xmlFreeDoc(doc); xmlCleanupParser(); /* Return the derivation array */ return derivation_array; }
GPtrArray *generate_target_array(const gchar *manifest_file) { /* Declarations */ xmlDocPtr doc; xmlNodePtr node_root; xmlXPathObjectPtr result; GPtrArray *targets_array = NULL; /* Parse the XML document */ if((doc = xmlParseFile(manifest_file)) == NULL) { g_printerr("Error with parsing the manifest XML file!\n"); xmlCleanupParser(); return NULL; } /* Retrieve root element */ node_root = xmlDocGetRootElement(doc); if(node_root == NULL) { g_printerr("The manifest XML file is empty!\n"); xmlFreeDoc(doc); xmlCleanupParser(); return NULL; } /* Query the targets elements */ result = executeXPathQuery(doc, "/manifest/targets/target"); /* Iterate over all the targets elements and add them to the array */ if(result) { unsigned int i; xmlNodeSetPtr nodeset = result->nodesetval; /* Create a targets array */ targets_array = g_ptr_array_new(); /* Iterate over all the target elements */ for(i = 0; i < nodeset->nodeNr; i++) { xmlNodePtr targets_children = nodeset->nodeTab[i]->children; Target *target = (Target*)g_malloc(sizeof(Target)); gchar *system = NULL; gchar *client_interface = NULL; gchar *target_property = NULL; int num_of_cores = 0; int available_cores = 0; GPtrArray *properties = NULL; GPtrArray *containers = NULL; while(targets_children != NULL) { if(xmlStrcmp(targets_children->name, (xmlChar*) "system") == 0) system = duplicate_node_text(targets_children); else if(xmlStrcmp(targets_children->name, (xmlChar*) "clientInterface") == 0) client_interface = duplicate_node_text(targets_children); else if(xmlStrcmp(targets_children->name, (xmlChar*) "targetProperty") == 0) target_property = duplicate_node_text(targets_children); else if(xmlStrcmp(targets_children->name, (xmlChar*) "numOfCores") == 0) { gchar *num_of_cores_str = duplicate_node_text(targets_children); if(num_of_cores_str != NULL) { num_of_cores = atoi((char*)num_of_cores_str); available_cores = num_of_cores; g_free(num_of_cores_str); } } else if(xmlStrcmp(targets_children->name, (xmlChar*) "properties") == 0) { xmlNodePtr properties_children = targets_children->children; properties = g_ptr_array_new(); /* Iterate over all properties */ while(properties_children != NULL) { TargetProperty *target_property = (TargetProperty*)g_malloc(sizeof(TargetProperty)); target_property->name = g_strdup((gchar*)properties_children->name); target_property->value = duplicate_node_text(properties_children); g_ptr_array_add(properties, target_property); properties_children = properties_children->next; } /* Sort the target properties */ g_ptr_array_sort(properties, (GCompareFunc)compare_target_property); } else if(xmlStrcmp(targets_children->name, (xmlChar*) "containers") == 0) { xmlNodePtr container_children = targets_children->children; containers = g_ptr_array_new(); /* Iterate over all containers */ while(container_children != NULL) { Container *container = (Container*)g_malloc(sizeof(Container)); container->name = g_strdup((gchar*)container_children->name); if(container_children->children == NULL) container->properties = NULL; else { xmlNodePtr properties_children = container_children->children; GPtrArray *properties = g_ptr_array_new(); /* Iterate over all properties */ while(properties_children != NULL) { TargetProperty *target_property = (TargetProperty*)g_malloc(sizeof(TargetProperty)); target_property->name = g_strdup((gchar*)properties_children->name); target_property->value = duplicate_node_text(properties_children); g_ptr_array_add(properties, target_property); properties_children = properties_children->next; } /* Sort the target properties */ g_ptr_array_sort(properties, (GCompareFunc)compare_target_property); container->properties = properties; } g_ptr_array_add(containers, container); container_children = container_children->next; } /* Sort the containers */ g_ptr_array_sort(containers, (GCompareFunc)compare_container); } targets_children = targets_children->next; } target->system = system; target->client_interface = client_interface; target->target_property = target_property; target->num_of_cores = num_of_cores; target->available_cores = available_cores; target->properties = properties; target->containers = containers; if(target->system == NULL || target->client_interface == NULL || target->target_property == NULL) { /* Check if all mandatory properties have been provided */ g_printerr("A mandatory property seems to be missing. Have you provided a correct\n"); g_printerr("manifest file?\n"); delete_target_array(targets_array); targets_array = NULL; break; } else g_ptr_array_add(targets_array, target); /* Add target item to the targets array */ } /* Sort the targets array */ if(targets_array != NULL) g_ptr_array_sort(targets_array, (GCompareFunc)compare_target); /* Cleanup */ xmlXPathFreeObject(result); } /* Cleanup */ xmlFreeDoc(doc); xmlCleanupParser(); /* Sort the targets array */ if(targets_array != NULL) g_ptr_array_sort(targets_array, (GCompareFunc)compare_target); /* Return the targets array */ return targets_array; }
GPtrArray *create_snapshots_array(const gchar *manifest_file, const gchar *container_filter, const gchar *component_filter) { xmlDocPtr doc; xmlNodePtr node_root; xmlXPathObjectPtr result; GPtrArray *snapshots_array; /* Parse the XML document */ if((doc = xmlParseFile(manifest_file)) == NULL) { g_printerr("Error with parsing the manifest XML file!\n"); xmlCleanupParser(); return NULL; } /* Retrieve root element */ node_root = xmlDocGetRootElement(doc); if(node_root == NULL) { g_printerr("The distribution manifest XML file is empty!\n"); xmlFreeDoc(doc); xmlCleanupParser(); return NULL; } /* Query the distribution elements */ result = executeXPathQuery(doc, "/manifest/snapshots/mapping"); /* Initialize snapshots array */ snapshots_array = g_ptr_array_new(); /* Iterate over all the distribution elements and add them to the array */ if(result) { xmlNodeSetPtr nodeset = result->nodesetval; unsigned int i; /* Iterate over all the mapping elements */ for(i = 0; i < nodeset->nodeNr; i++) { xmlNodePtr mapping_children = nodeset->nodeTab[i]->children; gchar *component = NULL; gchar *container = NULL; gchar *target = NULL; gchar *service = NULL; gchar *type = NULL; SnapshotMapping *mapping = (SnapshotMapping*)g_malloc(sizeof(SnapshotMapping)); /* Iterate over all the mapping item children (service,target,targetProperty,type,dependsOn elements) */ while(mapping_children != NULL) { if(xmlStrcmp(mapping_children->name, (xmlChar*) "component") == 0) component = duplicate_node_text(mapping_children); else if(xmlStrcmp(mapping_children->name, (xmlChar*) "container") == 0) container = duplicate_node_text(mapping_children); else if(xmlStrcmp(mapping_children->name, (xmlChar*) "target") == 0) target = duplicate_node_text(mapping_children); else if(xmlStrcmp(mapping_children->name, (xmlChar*) "service") == 0) service = duplicate_node_text(mapping_children); else if(xmlStrcmp(mapping_children->name, (xmlChar*) "type") == 0) type = duplicate_node_text(mapping_children); mapping_children = mapping_children->next; } mapping->component = component; mapping->container = container; mapping->target = target; mapping->service = service; mapping->type = type; mapping->transferred = FALSE; if(mapping_is_selected(mapping, container_filter, component_filter)) { if(component == NULL || container == NULL || target == NULL || service == NULL || type == NULL) { /* Check if all mandatory properties have been provided */ g_printerr("A mandatory property seems to be missing. Have you provided a correct\n"); g_printerr("manifest file?\n"); delete_snapshots_array(snapshots_array); snapshots_array = NULL; break; } else g_ptr_array_add(snapshots_array, mapping); /* Add the mapping to the array */ } else delete_snapshot_mapping(mapping); } xmlXPathFreeObject(result); } /* Cleanup */ xmlFreeDoc(doc); xmlCleanupParser(); /* Sort the snapshots array */ if(snapshots_array != NULL) g_ptr_array_sort(snapshots_array, (GCompareFunc)compare_snapshot_mapping); /* Return the snapshots array */ return snapshots_array; }