summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vmchooser/inc/functions.h8
-rw-r--r--vmchooser/inc/paths.h14
-rw-r--r--vmchooser/main.cxx233
-rw-r--r--vmchooser/readLinSess.cxx18
-rw-r--r--vmchooser/readXmlDir.cxx68
-rw-r--r--vmchooser/runImage.cxx32
6 files changed, 81 insertions, 292 deletions
diff --git a/vmchooser/inc/functions.h b/vmchooser/inc/functions.h
index 91dfdd1..0e5be33 100644
--- a/vmchooser/inc/functions.h
+++ b/vmchooser/inc/functions.h
@@ -1,19 +1,19 @@
#ifndef _FUNCTIONS_H_
#define _FUNCTIONS_H_
-#include <fltk/Widget.h>
#include <libxml/xpath.h>
#include <glob.h>
#include "DataEntry.h"
+#include <vector>
/* Attention: both return malloced array */
-DataEntry** readXmlDir(char* path);
-DataEntry** readLinSess(char* path);
+std::vector<DataEntry> readXmlDir(char* path);
+std::vector<DataEntry> readLinSess(char* path);
/* This is thought as a callback-function for the Select-Browser */
-void runImage(fltk::Widget* , void* p);
+void runImage(DataEntry);
/* building & executing command for different Virtualizer */
void runImage(DataEntry&, string confxml);
diff --git a/vmchooser/inc/paths.h b/vmchooser/inc/paths.h
index 2b58c1a..6a18ef5 100644
--- a/vmchooser/inc/paths.h
+++ b/vmchooser/inc/paths.h
@@ -1,9 +1,15 @@
#ifndef PATHS_H
#define PATHS_H
-#define VMCHOOSER_PLUGIN_PATH "/opt/openslx/plugin-repo/vmchooser/"
-#define VMCHOOSER_BIN_PATH "/var/opt/openslx/bin/"
-#define VMCHOOSER_ETC_BASE_PATH "/etc/opt/openslx/plugins/vmchooser/"
-#define VMCHOOSER_VMPATH "/var/lib/virt"
+//#define VMCHOOSER_PLUGIN_PATH "/opt/openslx/plugin-repo/vmchooser/"
+//#define VMCHOOSER_BIN_PATH "/var/opt/openslx/bin/"
+//#define VMCHOOSER_ETC_BASE_PATH "/etc/opt/openslx/plugins/vmchooser/"
+//#define VMCHOOSER_VMPATH "/var/lib/virt"
+
+#define VMCHOOSER_PLUGIN_PATH "/home/zwerg/vmchooser/plugin/"
+#define VMCHOOSER_BIN_PATH "/home/zwerg/vmchooser/bin/"
+#define VMCHOOSER_ETC_BASE_PATH "/home/zwerg/vmchooser/etc/"
+#define VMCHOOSER_VMPATH "/home/zwerg/vmchooser/vm/"
+
#endif
diff --git a/vmchooser/main.cxx b/vmchooser/main.cxx
deleted file mode 100644
index cdcd6e1..0000000
--- a/vmchooser/main.cxx
+++ /dev/null
@@ -1,233 +0,0 @@
-
-#include <fltk/run.h>
-
-#include <iostream>
-#include <stdlib.h>
-#include "inc/SWindow.h"
-#include "inc/DataEntry.h"
-#include "inc/functions.h"
-#include "inc/anyoption.h"
-#include "inc/paths.h"
-
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <libxml/xpath.h>
-
-#include <boost/filesystem.hpp>
-
-namespace bfs=boost::filesystem;
-
-using namespace std;
-using namespace fltk;
-
-// defined in readXmlDir.h
-extern DataEntry* get_entry(xmlDoc * doc);
-
-SWindow* mainwin;
-/**
- * MAIN
- *
- * ----------------------
- *
- * main function of vmchooser
- *
- *
- *
- */
-int main(int argc, char** argv) {
- string version = "0.0.13";
- AnyOption* opt = new AnyOption();
- char* xmlpath = NULL;
- char* lsesspath = NULL;
- char* dsession = NULL;
- int width=0, height=0;
-
- //opt->setVerbose();
- opt->autoUsagePrint(false);
-
- opt->addUsage("");
- opt->addUsage("SessionChooser Usage: vmchooser [OPTS|image.xml]");
- opt->addUsage("\t{-d |--default=} name of session to select (part of)");
- opt->addUsage("\t{-p |--path=} path to vmware (.xml) files");
- opt->addUsage("\t{-l |--lpath=} path to linux session (.desktop) files");
- opt->addUsage("\t{-s |--size=} [widthxheight]");
- opt->addUsage("\t{-v |--version} print out version");
- opt->addUsage("\t{-h |--help} prints help");
- opt->addUsage("");
- opt->addUsage("Run with xml-file as additional argument to start image at once.");
-
- opt->setFlag("help",'h');
- opt->setFlag("version",'v');
- opt->setOption("default", 'd');
- opt->setOption("path", 'p');
- opt->setOption("lpath", 'l');
- opt->setOption("size",'s');
-
- opt->processCommandArgs(argc, argv);
-
- /** HELP */
- if(opt->getFlag("help") || opt->getFlag('h')) {
- opt->printUsage();
- return 0;
- }
-
- /**
- * XML - PATH
- *
- * 1. read from stage3.conf
- * 2. option -p
- * 3. option --path
- * 4. default value "/var/lib/virt/vmware/"
- *
- **/
-
- ifstream ifs (
- string(VMCHOOSER_ETC_BASE_PATH).append("vmchooser.conf").c_str(),
- ifstream::in
- );
- if(ifs) {
- int n = 255;
- char buf[n];
- string s = "";
- while(!ifs.eof()) {
- ifs.getline(buf, n);
- s = buf;
- if(s.substr(0,17) == "vmchooser_xmlpath") {
- xmlpath = (char*)strdup(s.substr(19,s.length()-20).append("/").c_str());
- }
- }
-
- }
-
- if(opt->getValue('d')!=NULL) {
- dsession = opt->getValue('d');
- }
-
- if(opt->getValue("default")!= NULL) {
- dsession = opt->getValue("default");
- }
-
- if(opt->getValue('p')!=NULL) {
- xmlpath = opt->getValue('p');
- }
-
- if(opt->getValue("path")!= NULL) {
- xmlpath = opt->getValue("path");
- }
-
- if (xmlpath == NULL) {
- // Default Path comes here
- xmlpath = (char *) VMCHOOSER_VMPATH;
- }
-
- /* VERSION */
- if(opt->getFlag('v') || opt->getFlag("version")) {
- // just print out version information - helps testing
- cout << "virtual machine chooser " << version << endl;
- delete opt;
- return 0;
-
- }
-
- /** LINUX SESSION PATH */
- if(opt->getValue('l')!=NULL) {
- lsesspath = opt->getValue('l');
- }
- if(opt->getValue("lpath")!= NULL) {
- lsesspath = opt->getValue("lpath");
- }
- if (lsesspath == NULL) {
- lsesspath = (char *) "/usr/share/xsessions/";
- }
-
- /** Size of Window */
- string size;
- unsigned int i;
-
- if(opt->getValue('s')!=NULL) {
- size = opt->getValue('s');
- }
- if(opt->getValue("size")!= NULL) {
- size = opt->getValue("size");
- }
-
- if (size.empty()) {
- width = 500;
- height = 550;
- }
- else {
- i = size.find_first_of("x");
- if( i == string::npos) {
- cerr << "Please write <width>x<height> as argument for -s|--size." << endl;
- return 1;
- }
- height = atoi(size.substr(i+1).c_str());
- width = atoi(size.substr(0, size.size()-i).c_str());
- }
-
-
- // additional xml argument -> start image directly
- if(opt->getArgc() > 0) {
- string single_arg = opt->getArgv(0);
- if(bfs::is_directory(single_arg)) {
- fprintf(stderr, "Only argument is a folder, should be a valid xml file!\n");
- return 1;
- }
- // read xml image
- xmlDoc* doc = xmlReadFile(single_arg.c_str(), NULL, XML_PARSE_RECOVER);
- if (doc == NULL) {
- fprintf(stderr, "Error: could not parse file %s\n", single_arg.c_str());
- return 1;
- }
-
- DataEntry* result = get_entry(doc);
- if(result) {
- runImage(*result, single_arg );
- }
- else {
- fprintf(stderr, "Error: can not start image from xml\n\tcheck your <active> setting!\n");
- return 1;
- }
- }
-
- delete opt;
-
-
- /* read xml files */
- DataEntry** sessions = NULL;
- DataEntry** lsessions = NULL;
- sessions = readXmlDir(xmlpath);
- lsessions = readLinSess(lsesspath);
-
- SWindow& win = *SWindow::getInstance(width, height);
- mainwin = &win;
- bool lin_entries=false;
- bool vm_entries=false;
-
- if(lsessions != NULL) {
- win.set_lin_entries(lsessions);
- lin_entries = true;
- }
- if (sessions != NULL) {
- win.set_entries(sessions);
- vm_entries = true;
- }
-
- if(dsession) {
- win.unfold_entries(lin_entries, vm_entries, dsession);
- }
- else {
- win.unfold_entries(lin_entries, vm_entries);
- }
- win.show(); // argc,argv
- win.border(false);
-
-// free(xmlpath);
-
- bool retval = run();
-
- win.free_entries();
-
- return retval;
-}
-
diff --git a/vmchooser/readLinSess.cxx b/vmchooser/readLinSess.cxx
index 0779937..6aa558b 100644
--- a/vmchooser/readLinSess.cxx
+++ b/vmchooser/readLinSess.cxx
@@ -14,6 +14,7 @@
#include <fstream>
#include <iostream>
#include <cstring>
+#include <vector>
#include "inc/DataEntry.h"
#include "inc/functions.h"
@@ -40,7 +41,7 @@ static glob_t* globber(char* path, const char* filetype)
}
-DataEntry** readLinSess(char* path)
+std::vector<DataEntry> readLinSess(char* path)
{
int MAX_LENGTH = 200;
@@ -49,20 +50,21 @@ DataEntry** readLinSess(char* path)
char* val;
if ( path== NULL) {
- return NULL;
+ std::vector<DataEntry>();
}
glob_t *gResult = (glob_t*) malloc(sizeof(glob_t));
gResult = globber(path, "*.desktop");
if ( gResult== NULL) {
- return NULL;
+ return std::vector<DataEntry>();
}
if ( gResult->gl_pathc == 0 ) {
- return NULL;
+ return std::vector<DataEntry>();
}
- DataEntry** result =
- (DataEntry**) malloc(gResult->gl_pathc * sizeof(DataEntry*) +1);
+ std::vector<DataEntry> result;
+ // DataEntry** result =
+ //(DataEntry**) malloc(gResult->gl_pathc * sizeof(DataEntry*) +1);
int c = 0;
@@ -109,14 +111,14 @@ DataEntry** readLinSess(char* path)
}
if(! (de->short_description.empty() || de->command.empty()) ) {
- result[c] = de;
+ result.push_back(*de);
c++;
}
else {
delete de;
}
}
- result[c] = NULL;
+ //result[c] = NULL;
return result;
}
diff --git a/vmchooser/readXmlDir.cxx b/vmchooser/readXmlDir.cxx
index a3952ca..7e90797 100644
--- a/vmchooser/readXmlDir.cxx
+++ b/vmchooser/readXmlDir.cxx
@@ -33,7 +33,8 @@ string env;
vector<string> xmlVec;
xmlXPathObjectPtr evalXPath(xmlDocPtr doc, const char* path) {
- xmlXPathContextPtr xp = xmlXPathNewContext(doc);
+ printf("evalXPath(doc, %s)\n", path);
+ xmlXPathContextPtr xp = xmlXPathNewContext(doc);
string bla = string(path);
if(xp == NULL) {
fprintf(stderr,"Error: unable to create new XPath context\n");
@@ -53,12 +54,11 @@ xmlXPathObjectPtr evalXPath(xmlDocPtr doc, const char* path) {
char* getAttribute(xmlDoc *doc, char* name)
{
- xmlNode* temp;
+ printf("getAttribute(doc, %s)\n", name);
+ xmlNode* temp;
string path = string("/settings/eintrag/")+ string(name)+ string("/@param");
char* cpath = strdup(path.c_str());
- //print_xpath_nodes(xpp->nodesetval, stdout);
-
// Get Attribute via XPath
xmlXPathObjectPtr xpp = evalXPath(
doc,
@@ -66,6 +66,8 @@ char* getAttribute(xmlDoc *doc, char* name)
);
free(cpath);
+ //print_xpath_nodes(xpp->nodesetval, stdout);
+
int size;
size = (xpp->nodesetval) ? xpp->nodesetval->nodeNr: 0;
for (int i= 0; i < size; i++) {
@@ -83,6 +85,7 @@ char* getAttribute(xmlDoc *doc, char* name)
char* getNodeValue(xmlDoc *doc, char* name)
{
+ printf("getNodeValue(doc, %s)", name);
xmlNode* temp;
xmlXPathContextPtr xp = xmlXPathNewContext(doc);
string bla = string("/settings/eintrag/")+ string(name);
@@ -117,13 +120,13 @@ char* getNodeValue(xmlDoc *doc, char* name)
DataEntry* get_entry(xmlDoc * doc)
{
+ printf("get_entry(doc)\n");
char *tempc = NULL;
DataEntry* de = new DataEntry();
tempc = getAttribute(doc,(char *)"short_description");
if (tempc != NULL ) {
de->short_description = tempc;
-
// replace a substring
std::string dest_string, dest1_string;
boost::regex re("\n|\r");
@@ -132,7 +135,10 @@ DataEntry* get_entry(xmlDoc * doc)
de->short_description.end(),
re,
" ");
- }
+ } else {
+ // TODO: fix this
+ de->short_description = "short_description failed";
+ }
tempc = NULL;
if (de->short_description.empty()) {
@@ -265,16 +271,18 @@ DataEntry* get_entry(xmlDoc * doc)
* -> if no xmlfilter.sh is available, it globs for available xmls
* - reads all xml files and creates for each its own DataEntry-struct
*/
-DataEntry** readXmlDir(char* path)
+std::vector<DataEntry> readXmlDir(char* path)
{
const int MAX_LENGTH = 256;
char line[MAX_LENGTH];
char* fpath = getFolderName();
FILE* inp;
+ printf("readXmlDir %s\n", path);
+
LIBXML_TEST_VERSION
if ( path== NULL) {
- return NULL;
+ return std::vector<DataEntry>();
}
bfs::path filter(string(fpath).append("/").append(filterscript));
@@ -313,23 +321,26 @@ DataEntry** readXmlDir(char* path)
char* tstr = 0;
for(int c=0; c<globbuf.gl_pathc; c++) {
+ printf("reading file %s\n", globbuf.gl_pathv[c]);
tdoc = xmlReadFile(globbuf.gl_pathv[c],NULL,XML_PARSE_RECOVER|XML_PARSE_NOERROR);
if(!tdoc) {
cerr << "Error opening xml file " << globbuf.gl_pathv[c] << "!" << endl;
- return 0;
+ return std::vector<DataEntry>();
}
tstr = getAttribute(tdoc, (char*)"pools");
- if(tstr == 0) {
- xmlFreeDoc(tdoc);
- continue;
- }
- if(env == tstr) {
+// if(tstr == 0) {
+// xmlFreeDoc(tdoc);
+// continue;
+// }
+
+// if(env == tstr) {
+ printf("xmlVec.push_back(%s)\n", globbuf.gl_pathv[c]);
xmlVec.push_back(string(globbuf.gl_pathv[c]) );
- }
+// }
xmlFreeDoc(tdoc);
tdoc = 0; tstr = 0;
@@ -345,9 +356,10 @@ DataEntry** readXmlDir(char* path)
// We need to reserve the memory for all the pointers here
if(xmlVec.size() == 0) {
- return NULL;
+ return std::vector<DataEntry>();
}
- DataEntry** result = (DataEntry**) malloc(xmlVec.size() * sizeof(DataEntry*) +1);
+
+ std::vector<DataEntry> result;
for (unsigned int i=0; i < xmlVec.size(); i++) {
loc = xmlVec[i].find( "Vorlage" );
@@ -361,7 +373,7 @@ DataEntry** readXmlDir(char* path)
/* DEBUG */
- //printf("File: %s, COUNT: %d\n", xmlVec[i].c_str(), xmlVec.size());
+ printf("File: %s, COUNT: %d\n", xmlVec[i].c_str(), xmlVec.size());
if ( S_ISDIR(m.st_mode) ) {
continue;
}
@@ -372,22 +384,22 @@ DataEntry** readXmlDir(char* path)
continue;
}
- result[c] = get_entry(doc);
- if (result[c] != 0) {
- result[c]->xml_name = xmlVec[i];
+ result.push_back(*get_entry(doc));
+ //if (result[c] != 0) {
+ result[c].xml_name = xmlVec[i];
c++;
- }
+ //}
/* xmlDoc still needed to write back information for VMware etc. */
// xmlFreeDoc(doc);
}
- result[c] = '\0';
- if(c!= 0) {
+ //result[c] = '\0';
+ //if(c!= 0) {
return result;
- }
- else {
- return NULL;
- }
+ //}
+ //else {
+ // return NULL;
+ //}
}
diff --git a/vmchooser/runImage.cxx b/vmchooser/runImage.cxx
index ee84978..6425fdd 100644
--- a/vmchooser/runImage.cxx
+++ b/vmchooser/runImage.cxx
@@ -1,9 +1,4 @@
-#include <fltk/Widget.h>
-#include <fltk/ask.h>
-#include <fltk/run.h>
-
#include "inc/DataEntry.h"
-#include "inc/SWindow.h"
#include "inc/functions.h"
#include "inc/paths.h"
@@ -18,23 +13,22 @@
/* define MAX_LENGTH for string in getFolderName */
const int MAX_LENGTH = 200;
-extern SWindow* mainwin;
extern string env;
/** *************************************************************
* void runImage runs a (virtual machine) image using fork()
* calling runImage(DataEntry*)
***************************************************************/
-void runImage(fltk::Widget*, void* p)
+void runImage(DataEntry dat)
{
string confxml;
/* printf("runImage called\n"); */
- if ( p == NULL ) {
- return;
- }
+ //if ( e == NULL ) {
+ // return;
+ //}
- DataEntry& dat = *((DataEntry*) p);
+ //DataEntry& dat = *((DataEntry*) e);
if(dat.imgtype == VMWARE || dat.imgtype == VBOX ) {
confxml = writeConfXml(dat);
@@ -52,22 +46,28 @@ void runImage(fltk::Widget*, void* p)
arg1, NULL };
//printf("%s", arg1);
+ // TODO: only fork if we want to display a message (or maybe not fork at all?)
pid = fork();
switch( pid ) {
case -1:
- fltk::alert("Error occured during forking a thread of execution!");
+ // parent: creation of child process failed
+ //fltk::alert("Error occured during forking a thread of execution!");
return;
break;
case 0:
- mainwin->destroy();
- fltk::wait();
+ // child
+ // the only purpose of this child is to display a message
+ //mainwin->destroy();
+ //fltk::wait();
if(dat.imgtype == VMWARE || dat.imgtype == VBOX) {
//cout << "calling " << argv[1] << endl;
execvp(argv[0], argv);
}
break;
default:
+ // parent
+
// this is not really useful, as this
// blocks execution for about 5 seconds
// sometimes ;-)
@@ -76,7 +76,9 @@ void runImage(fltk::Widget*, void* p)
// fltk::alert("Failed to create child thread!");
// return;
//}
- saveSession((DataEntry*)p);
+
+ // TODO: find out what it does and restore this
+ saveSession(&dat);
runImage(dat, confxml);
break;
}