diff options
Diffstat (limited to 'vmchooser/addInfo.cxx')
-rw-r--r-- | vmchooser/addInfo.cxx | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/vmchooser/addInfo.cxx b/vmchooser/addInfo.cxx index 144e061..5d1301d 100644 --- a/vmchooser/addInfo.cxx +++ b/vmchooser/addInfo.cxx @@ -5,6 +5,10 @@ #include <pwd.h> #include <sys/types.h> +#include "boost/filesystem.hpp" + +namespace bfs=boost::filesystem; + /****************************************** * Adds user info and hostname to xml * @@ -12,7 +16,7 @@ * hostnamenode: <hostname param="host" /> * computername: needed for bootpgm <computername .../> ******************************************/ -void addInfo(xmlNode* node) { +void addInfo(xmlNode* node, DataEntry* dat) { if(node == NULL) { return; @@ -31,6 +35,7 @@ void addInfo(xmlNode* node) { xmlNodePtr usernode = NULL; xmlNodePtr hostnamenode = NULL; xmlNodePtr compnamenode = NULL; + xmlNodePtr filenamenode = NULL; xmlNodePtr firstchild = node->children; // just use some standard Linux functions here ... @@ -103,6 +108,51 @@ void addInfo(xmlNode* node) { cerr << "<computername> node could not be created!" << endl; } + + + // We need to add the filename to the xml + cout << "XML file name: " << dat->xml_name << endl; + if(dat->xml_name.empty()) return; + bfs::path path(dat->xml_name); + std::string folder = path.branch_path().string(); + + cout << "XML folder name: " << folder << endl; + + if(folder.empty()) return; + cur = node->children; + + // Get <hostname> node and add "hostname#param" attribute + while(cur != NULL) { + if (!xmlStrcmp(cur->name, (const xmlChar *)"image_name")){ + filenamenode = cur; + break; + } + cur = cur->next; + } + if(! filenamenode) { + //filenamenode = xmlNewNode(NULL, (const xmlChar*) "xmlpath"); + //if(filenamenode != NULL ) { + // xmlNewProp(filenamenode, (const xmlChar*) "param", (const xmlChar*) folder.c_str()); + // xmlAddChild(node, filenamenode); + //} + //else { + // cerr << "<xmlpath> node could not be created!" << endl; + //} + cerr << "There is no node called 'image_name'. " << endl; + } + else { + // add param value to existant hostname-nodea + xmlChar* bla = xmlGetProp(filenamenode, "param"); + if(!bla) { + cerr << "Could not read Attribute 'param' in 'image_name' node." << endl; + return; + } + else { + xmlSetProp(filenamenode, (const xmlChar*) "param", (xmlChar*) folder.append(bla).c_str()); + } + } + + return; } |