From 746d3b79a6ebf6678d050fa1135be02c65f5bfc5 Mon Sep 17 00:00:00 2001 From: Bastian Wissler Date: Thu, 26 Feb 2009 16:33:11 +0000 Subject: vmchooser source: * path to xml file included in node 'image_name' git-svn-id: http://svn.openslx.org/svn/openslx/openslx-src-tools/vmchooser/trunk@2644 95ad53e4-c205-0410-b2fa-d234c58c8868 --- vmchooser/addInfo.cxx | 52 ++++++++++++++++++++++++++++++++++++++++++++++- vmchooser/inc/functions.h | 2 +- vmchooser/readXmlDir.cxx | 5 +---- vmchooser/runImage.cxx | 2 +- 4 files changed, 54 insertions(+), 7 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 #include +#include "boost/filesystem.hpp" + +namespace bfs=boost::filesystem; + /****************************************** * Adds user info and hostname to xml * @@ -12,7 +16,7 @@ * hostnamenode: * computername: needed for bootpgm ******************************************/ -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 << " 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 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 << " 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; } diff --git a/vmchooser/inc/functions.h b/vmchooser/inc/functions.h index afccc9b..1ec76f4 100644 --- a/vmchooser/inc/functions.h +++ b/vmchooser/inc/functions.h @@ -27,7 +27,7 @@ char* getFolderName(); /* Adds the elements into xmlNode "printers" (1. argument) */ bool addPrinters(xmlNode* node, char* script); bool addScanners(xmlNode* node, char* script); -void addInfo(xmlNode* node); /* This is defined in addPrinters.cxx */ +void addInfo(xmlNode* node, DataEntry* dat); /* This is defined in addPrinters.cxx */ /* Write configuration xml */ string writeConfXml(DataEntry& dat); diff --git a/vmchooser/readXmlDir.cxx b/vmchooser/readXmlDir.cxx index 44188d1..68febaa 100644 --- a/vmchooser/readXmlDir.cxx +++ b/vmchooser/readXmlDir.cxx @@ -99,10 +99,6 @@ DataEntry* get_entry(xmlDoc * doc) char *tempc = NULL; DataEntry* de = new DataEntry(); - if(doc->name != NULL) { - de->xml_name = string(doc->name); - } - tempc = getAttribute(doc,(char *)"short_description"); if (tempc != NULL ) { de->short_description = tempc; @@ -282,6 +278,7 @@ DataEntry** readXmlDir(char* path) result[c] = get_entry(doc); if (result[c] != NULL) { + result[c]->xml_name = xmlVec[i]; c++; } /* xmlDoc still needed to write back information for VMware etc. */ diff --git a/vmchooser/runImage.cxx b/vmchooser/runImage.cxx index 4b7c3e5..bed42ac 100644 --- a/vmchooser/runImage.cxx +++ b/vmchooser/runImage.cxx @@ -162,7 +162,7 @@ string writeConfXml(DataEntry& dat) { addScanners(root, (char*)pskript.c_str()); // add hostname and username information - addInfo(root); + addInfo(root, &dat); srand(time(NULL)); -- cgit v1.2.3-55-g7522