diff --git a/pandora_agents/ChangeLog b/pandora_agents/ChangeLog index eed60f2cbd..b1dc603f13 100644 --- a/pandora_agents/ChangeLog +++ b/pandora_agents/ChangeLog @@ -1,3 +1,10 @@ +2010-07-14 Dario Rodriguez + + * 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 * win32/configure.in, Makefile.am: Modified to compile executable with diff --git a/pandora_agents/win32/pandora_agent_conf.cc b/pandora_agents/win32/pandora_agent_conf.cc index f3694202c6..c60346517c 100644 --- a/pandora_agents/win32/pandora_agent_conf.cc +++ b/pandora_agents/win32/pandora_agent_conf.cc @@ -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(); +} diff --git a/pandora_agents/win32/pandora_agent_conf.h b/pandora_agents/win32/pandora_agent_conf.h index 165dcaaf32..8739e8489c 100644 --- a/pandora_agents/win32/pandora_agent_conf.h +++ b/pandora_agents/win32/pandora_agent_conf.h @@ -39,6 +39,7 @@ namespace Pandora { private: list *key_values; list *collection_list; + list::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 (); }; } diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index 689ba4d8c1..8780592866 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -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"<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"); diff --git a/pandora_agents/win32/pandora_windows_service.h b/pandora_agents/win32/pandora_windows_service.h index bc161e9a0b..fb2ae5b743 100644 --- a/pandora_agents/win32/pandora_windows_service.h +++ b/pandora_agents/win32/pandora_windows_service.h @@ -68,6 +68,7 @@ namespace Pandora { void recvDataFile (string filename); void recvTentacleDataFile (string host, string filename); + void checkCollections (); void checkConfig (); Pandora_Windows_Service ();