2010-07-14 Dario Rodriguez <dario.rodriguez@artica.es>

* win32/pandora_agent_conf.cc, pandora_agent_conf.h: Added functionality
	to get collection from configuration file.
        * win32/pandora_windows_service.cc, pandora_windows_service.h: Added
	support for manage collections



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3007 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
darode 2010-07-14 17:16:08 +00:00
parent 72f87b1699
commit 27891544d9
5 changed files with 212 additions and 1 deletions

View File

@ -1,3 +1,10 @@
2010-07-14 Dario Rodriguez <dario.rodriguez@artica.es>
* win32/pandora_agent_conf.cc, pandora_agent_conf.h: Added functionality
to get collection from configuration file.
* win32/pandora_windows_service.cc, pandora_windows_service.h: Added
support for manage collections.
2010-07-09 Dario Rodriguez <dario.rodriguez@artica.es>
* win32/configure.in, Makefile.am: Modified to compile executable with

View File

@ -139,3 +139,53 @@ Pandora::Pandora_Agent_Conf::getValue (const string key)
return "";
}
/**
* Queries for a collection name.
*
* This method returns the name of the current
* collection pointed by an iterator.
*
* @return The name of the current colletion
*
*/
string
Pandora::Pandora_Agent_Conf::getCurrentCollection() {
string aux;
aux = *collection_it;
return aux;
}
/**
* Set iterator pointing to the first collection of the list.
*
* This method set the iterator pointing to the first collection of the list.
*
*/
void
Pandora::Pandora_Agent_Conf::goFirstCollection() {
collection_it = collection_list->begin();
}
/**
* Move the collection iterator to the next item
*
* This method move the iterator to the next item.
*
*/
void
Pandora::Pandora_Agent_Conf::goNextCollection() {
this->collection_it++;
}
/**
* Compare the iterator with the last collection.
*
* This method return true if the iterator is pointing to the last collection
*
* @return True if the iterator is pointing to the last collection
*
*/
bool
Pandora::Pandora_Agent_Conf::isLastCollection() {
return collection_it == collection_list->end();
}

View File

@ -39,6 +39,7 @@ namespace Pandora {
private:
list<Key_Value> *key_values;
list<string> *collection_list;
list<string>::iterator collection_it;
Pandora_Agent_Conf ();
public:
@ -47,6 +48,12 @@ namespace Pandora {
~Pandora_Agent_Conf ();
void setFile (string filename);
string getValue (const string key);
string getCurrentCollection();
void goFirstCollection ();
void goNextCollection ();
bool isLastCollection ();
};
}

View File

@ -591,6 +591,151 @@ Pandora_Windows_Service::copyLocalDataFile (string remote_path,
}
}
void
Pandora_Windows_Service::checkCollections () {
int flag, i;
char *coll_md5 = NULL, *server_coll_md5 = NULL;
string collection_name, collections_dir, tmp;
string collection_zip, install_dir, temp_dir;
/*Get collections directory*/
install_dir = Pandora::getPandoraInstallDir ();
collections_dir = install_dir+"collections\\";
/* Get temporal directory */
temp_dir = conf->getValue ("temporal");
if (temp_dir[temp_dir.length () - 1] != '\\') {
temp_dir += "\\";
}
/*Set iterator in the firs collection*/
conf->goFirstCollection();
while (! conf->isLastCollection()) {
collection_name = conf->getCurrentCollection();
collection_zip = collection_name+".zip";
collection_name = collection_name + ".md5";
tmp = collections_dir+collection_name;
/*Reading local collection md5*/
try {
if (Pandora_File::readBinFile (tmp, &coll_md5) < 32) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str());
if (coll_md5 != NULL) {
delete[] coll_md5;
}
return;
}
} catch (...) {
/*Getting new md5*/
try {
/*Downloading md5 file*/
recvDataFile (collection_name);
/*Reading new md5 file*/
tmp = temp_dir + collection_name;
if (Pandora_File::readBinFile (tmp, &coll_md5) < 32) {
cout<<"ERROR"<<endl;
pandoraLog ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str());
if (coll_md5 != NULL) {
delete[] coll_md5;
}
return;
}
Pandora_File::removeFile (tmp);
/* Save new md5 file */
tmp = collections_dir + collection_name;
Pandora_File::writeBinFile (tmp, coll_md5, 32);
} catch(...) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_name.c_str());
return;
}
/*Getting new zipped collection*/
try {
/*Downloading zipped collection*/
recvDataFile (collection_zip);
/*Uncompress zipped collection*/
/*NOT YET*/
} catch (...) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_zip.c_str());
return;
}
return;
}
/*Reading server collection md5*/
try {
recvDataFile(collection_name);
tmp = temp_dir+collection_name;
if (Pandora_File::readBinFile (tmp, &server_coll_md5) < 32) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Invalid remote md5", tmp.c_str());
if (server_coll_md5 != NULL) {
delete[] server_coll_md5;
}
return;
}
Pandora_File::removeFile (tmp);
} catch (...) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_name.c_str());
return;
}
/*Check both md5*/
flag = 0;
for (i = 0; i < 32; i++) {
if (coll_md5[i] != server_coll_md5[i]) {
flag = 1;
break;
}
}
/*If the two md5 are equals, exit*/
if (flag == 0) {
return;
}
pandoraLog("Pandora_Windows_Service::checkCollections: Collection %s has changed", collection_name.c_str ());
/*Getting new zipped collection*/
try {
/*Downloading zipped collection*/
recvDataFile (collection_zip);
/*Uncompress zipped collection*/
/*NOT YET*/
} catch (...) {
pandoraLog ("Pandora_Windows_Service::checkCollection: Can not download %s", collection_zip.c_str());
return;
}
/* Save new md5 file */
tmp = collections_dir + collection_name;
Pandora_File::writeBinFile (tmp, server_coll_md5, 32);
/*Free coll_md5*/
if (coll_md5 != NULL) {
delete[] coll_md5;
}
/*Free server_coll_md5*/
if (server_coll_md5 != NULL) {
delete[] server_coll_md5;
}
conf->goNextCollection();
}
}
void
Pandora_Windows_Service::checkConfig () {
int i, conf_size;
@ -862,10 +1007,11 @@ Pandora_Windows_Service::pandora_run () {
pandoraDebug ("Run begin");
conf = this->getConf ();
/* Check for configuration changes */
if (getPandoraDebug () == false) {
this->checkConfig ();
this->checkCollections ();
}
server_addr = conf->getValue ("server_ip");

View File

@ -68,6 +68,7 @@ namespace Pandora {
void recvDataFile (string filename);
void recvTentacleDataFile (string host,
string filename);
void checkCollections ();
void checkConfig ();
Pandora_Windows_Service ();