From d7fc19c2cb8a7be149627ef6e5b864cb558125df Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Wed, 11 Mar 2015 10:31:29 +0400 Subject: [PATCH 01/11] Add FileManParser to manage decrypted files from FileManIOFile --- ParserClass/FileManParser.cpp | 0 ParserClass/FileManParser.hpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 ParserClass/FileManParser.cpp create mode 100644 ParserClass/FileManParser.hpp diff --git a/ParserClass/FileManParser.cpp b/ParserClass/FileManParser.cpp new file mode 100644 index 0000000..e69de29 diff --git a/ParserClass/FileManParser.hpp b/ParserClass/FileManParser.hpp new file mode 100644 index 0000000..e69de29 From aa249b570082cc60d79661ebafcb9dd18527c129 Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Wed, 11 Mar 2015 10:52:05 +0400 Subject: [PATCH 02/11] Make directory tree --- ParserClass/FileManContainer/Website.cpp | 9 +++++++++ ParserClass/FileManContainer/Website.hpp | 24 ++++++++++++++++++++++++ ParserClass/FileManParser.cpp | 9 +++++++++ ParserClass/FileManParser.hpp | 24 ++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 ParserClass/FileManContainer/Website.cpp create mode 100644 ParserClass/FileManContainer/Website.hpp diff --git a/ParserClass/FileManContainer/Website.cpp b/ParserClass/FileManContainer/Website.cpp new file mode 100644 index 0000000..94fbc04 --- /dev/null +++ b/ParserClass/FileManContainer/Website.cpp @@ -0,0 +1,9 @@ +/** + * @file Website.cpp + * @brief Website class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implementations of Website class. + * + */ diff --git a/ParserClass/FileManContainer/Website.hpp b/ParserClass/FileManContainer/Website.hpp new file mode 100644 index 0000000..2e76df3 --- /dev/null +++ b/ParserClass/FileManContainer/Website.hpp @@ -0,0 +1,24 @@ +/** + * @file Website.hpp + * @brief Website class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of Website class. + * + */ + + +class Website{ + + + public: + + + + + + + private: + +} diff --git a/ParserClass/FileManParser.cpp b/ParserClass/FileManParser.cpp index e69de29..43b3302 100644 --- a/ParserClass/FileManParser.cpp +++ b/ParserClass/FileManParser.cpp @@ -0,0 +1,9 @@ +/** + * @file FileManParser.cpp + * @brief FileManParser class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implementations of FileManParser class. + * + */ diff --git a/ParserClass/FileManParser.hpp b/ParserClass/FileManParser.hpp index e69de29..0b35e38 100644 --- a/ParserClass/FileManParser.hpp +++ b/ParserClass/FileManParser.hpp @@ -0,0 +1,24 @@ +/** + * @file FileManParser.hpp + * @brief FileManParser class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of FileManParser class. + * + */ + + +class FileManParser{ + + + public: + + + + + + + private: + +} From c93be89ea6060537340028c7f012fe8f0e2d2a49 Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Wed, 11 Mar 2015 16:12:56 +0400 Subject: [PATCH 03/11] Begin parser... --- ParserClass/FileManContainer/Website.cpp | 37 ++++++++++ ParserClass/FileManContainer/Website.hpp | 57 ++++++++++++++- ParserClass/FileManParser.cpp | 92 ++++++++++++++++++++++++ ParserClass/FileManParser.hpp | 35 ++++++++- main.cpp | 31 ++++++-- 5 files changed, 244 insertions(+), 8 deletions(-) diff --git a/ParserClass/FileManContainer/Website.cpp b/ParserClass/FileManContainer/Website.cpp index 94fbc04..0d25344 100644 --- a/ParserClass/FileManContainer/Website.cpp +++ b/ParserClass/FileManContainer/Website.cpp @@ -7,3 +7,40 @@ * Contain all implementations of Website class. * */ + + +#include "Website.hpp" + +std::string Website::getTitle(){ + return this->title; +} +std::string Website::getUrl(){ + return this->url; +} +std::string Website::getUsername(){ + return this->username; +} +std::string Website::getPassword(){ + return this->password; +} +std::string Website::getDescription(){ + return this->description; +} + + + +void Website::setTitle(std::string title){ + this->title = title; +} +void Website::setUrl(std::string url){ + this->url = url; +} +void Website::setUsername(std::string username){ + this->username = username; +} +void Website::setPassword(std::string password){ + this->password = password; +} +void Website::setDescription(std::string description){ + this->description = description; +} diff --git a/ParserClass/FileManContainer/Website.hpp b/ParserClass/FileManContainer/Website.hpp index 2e76df3..01c41f9 100644 --- a/ParserClass/FileManContainer/Website.hpp +++ b/ParserClass/FileManContainer/Website.hpp @@ -8,17 +8,70 @@ * */ +#ifndef __WEBSITE__ +#define __WEBSITE__ +#include <string> + + +/** + * @class FileManIOFile FileManIOFile.hpp "/CryptClass/FileManIOFile.hpp" + * @brief Class for quick open and close encrypted file. + * @author manzerbredes + * + * -----File organisation----- + * + * 16 first bytes : md5 of decrypted file + * rest of the file : data encrypted (ASE for now) + * + */ + +#include <string> + + + +/** + * @class Website Website.hpp "/ParserClass/FileManContainer/Website.hpp" + * @brief Class for quick open and close encrypted file. + * @author manzerbredes + * + * Container for website data. + * + */ class Website{ public: + /** + * @brief Containner getters. + */ + + std::string getTitle(); + std::string getUrl(); + std::string getUsername(); + std::string getPassword(); + std::string getDescription(); - + /** + * @brief Containner setters. + */ + void setTitle(std::string title); + void setUrl(std::string url); + void setUsername(std::string username); + void setPassword(std::string password); + void setDescription(std::string description); private: -} + std::string title; ///< Title en the website + std::string url; ///< Url of the website + std::string username; ///< username of the account + std::string password; ///< password of the account + std::string description; ///< Description of the website +}; + + +#endif diff --git a/ParserClass/FileManParser.cpp b/ParserClass/FileManParser.cpp index 43b3302..00db891 100644 --- a/ParserClass/FileManParser.cpp +++ b/ParserClass/FileManParser.cpp @@ -7,3 +7,95 @@ * Contain all implementations of FileManParser class. * */ + + +#include "FileManParser.hpp" + + +FileManParser::FileManParser(std::string data){ + this->data=data; + + try { + xercesc::XMLPlatformUtils::Initialize(); + } + catch (const xercesc::XMLException& toCatch) { + // Do your failure processing here + + } + + + xercesc::XercesDOMParser *parser = new xercesc::XercesDOMParser(); + xercesc::MemBufInputSource myxml_buf((const XMLByte*)this->data.c_str(), this->data.size(), "dummy",false); + + parser->parse("Doxygen/doc.xml"); + + + this->document=parser->getDocument(); + this->root=this->document->getDocumentElement(); + + this->initWebsites(); + + + +} + + + +std::vector<Website> FileManParser::getWebsites(){ + return this->websites; +} + + +std::string FileManParser::getData(){ return this->data;}; + + + +void FileManParser::initWebsites(){ + + xercesc::DOMElement* websitesElement=this->getChildByTagName(this->root, "websites"); + + + xercesc::DOMNodeList* nodeList=websitesElement->getChildNodes(); + XMLSize_t nodeCount = nodeList->getLength(); + + for(int i=0;i<nodeCount;i++){ + + xercesc::DOMNode* current=nodeList->item(i); + std::string TagName=xercesc::XMLString::transcode(current->getNodeName()); + + if( current->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) { + + std::cout << this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"title"); + std::cout << this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"url"); + + } + } +} + + +xercesc::DOMElement* FileManParser::getChildByTagName(xercesc::DOMElement* node, std::string TagName){ + xercesc::DOMNodeList* nodeList=node->getChildNodes(); + XMLSize_t nodeCount = nodeList->getLength(); + xercesc::DOMElement* returnElement=NULL; + + for(int i=0;i<nodeCount;i++){ + + xercesc::DOMNode* current=nodeList->item(i); + std::string currentTagName=xercesc::XMLString::transcode(current->getNodeName()); + + if( current->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) { + if(currentTagName.compare(TagName)==0){ + returnElement=dynamic_cast< xercesc::DOMElement* >( current ); + break; + } + } + } + + return returnElement; +} + + +std::string FileManParser::getContentOfChild(xercesc::DOMElement* node,std::string TagName){ + xercesc::DOMElement* child=this->getChildByTagName(node,TagName); + return xercesc::XMLString::transcode(child->getTextContent()); +} diff --git a/ParserClass/FileManParser.hpp b/ParserClass/FileManParser.hpp index 0b35e38..88c959e 100644 --- a/ParserClass/FileManParser.hpp +++ b/ParserClass/FileManParser.hpp @@ -8,17 +8,50 @@ * */ +//----- std ----- +#include <iostream> +#include <string> +#include <vector> + +//----- class ----- +#include "Website.hpp" + +//----- xerces ----- +#include <xercesc/parsers/XercesDOMParser.hpp> +#include <xercesc/dom/DOM.hpp> +#include <xercesc/framework/MemBufInputSource.hpp> +#include <xercesc/sax/HandlerBase.hpp> +#include <xercesc/util/XMLString.hpp> +#include <xercesc/util/PlatformUtils.hpp> +#include <xercesc/util/XercesDefs.hpp> + + class FileManParser{ public: + FileManParser(std::string data); + std::vector<Website> getWebsites(); + void initWebsites(); + std::string getData(); + + xercesc::DOMElement* getChildByTagName(xercesc::DOMElement* node, std::string TagName); + std::string getContentOfChild(xercesc::DOMElement* node,std::string TagName); private: -} + xercesc::DOMDocument* document; ///< contain the document + + xercesc::DOMElement* root; + + std::vector<Website> websites; ///< contain all websites entries + + std::string data; ///< contain data to parse + +}; diff --git a/main.cpp b/main.cpp index 6b1bf23..9a3b3f1 100644 --- a/main.cpp +++ b/main.cpp @@ -17,10 +17,8 @@ #include <string> //----- class ----- -#include "AESCrypt.hpp" -#include "HASHCrypt.hpp" #include "FileManIOFile.hpp" - +#include "FileManParser.hpp" /** @@ -33,7 +31,30 @@ */ int main(int argc, char *argv[]){ - std::string chaine="It's work !"; + + + + std::string xml="<?xml version=\"1.0\" standalone=\"yes\" ?>\n\ +<forgetIt> \n\ +<websites> \n\ + \n\ + </websites> \n\ +</forgetIt> \n\ + "; + + + FileManParser parser(xml); + + + + //std::cout << std::endl << parser.getData() << std::endl; + + + + + + + /*std::string chaine="It's work !"; std::string key="loic"; AESCrypt aes; @@ -45,7 +66,7 @@ int main(int argc, char *argv[]){ fichier.read(key); if(fichier.isReadable()) - std::cout << fichier.getData(); + std::cout << fichier.getData();*/ return 0; From 2166479d44beceba7fbf393f56b441d1f9597861 Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Wed, 11 Mar 2015 19:52:59 +0400 Subject: [PATCH 04/11] Add global container --- ParserClass/AbstractContainer.cpp | 39 +++++++++++++++++++ ParserClass/AbstractContainer.hpp | 0 .../FileManContainer/FileManContainer.cpp | 0 .../FileManContainer/FileManContainer.hpp | 0 4 files changed, 39 insertions(+) create mode 100644 ParserClass/AbstractContainer.cpp create mode 100644 ParserClass/AbstractContainer.hpp create mode 100644 ParserClass/FileManContainer/FileManContainer.cpp create mode 100644 ParserClass/FileManContainer/FileManContainer.hpp diff --git a/ParserClass/AbstractContainer.cpp b/ParserClass/AbstractContainer.cpp new file mode 100644 index 0000000..370fc06 --- /dev/null +++ b/ParserClass/AbstractContainer.cpp @@ -0,0 +1,39 @@ +/** + * @file AbstractFileContainer.hpp + * @brief FileManContainer class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of FileManContainer class. + * + */ + +#ifndef __FileManContainer__ +#define __FileManContainer__ + + + +/** + * @class Website Website.hpp "/ParserClass/FileManContainer/Website.hpp" + * @brief Class for manager all FileMan container (websites etc...) + * @author manzerbredes + * + * + * + */ + +class FileManContainer{ + + public: + FileManContainer(); + + void addWebsite(Website website); + std::vector<Website> getWebsites(); + + private: + + std::vector<Website> websites; +}; + + +#endif diff --git a/ParserClass/AbstractContainer.hpp b/ParserClass/AbstractContainer.hpp new file mode 100644 index 0000000..e69de29 diff --git a/ParserClass/FileManContainer/FileManContainer.cpp b/ParserClass/FileManContainer/FileManContainer.cpp new file mode 100644 index 0000000..e69de29 diff --git a/ParserClass/FileManContainer/FileManContainer.hpp b/ParserClass/FileManContainer/FileManContainer.hpp new file mode 100644 index 0000000..e69de29 From 41897f295fbaf4d715a6fc099c81d4e15b48e19b Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Wed, 11 Mar 2015 19:53:47 +0400 Subject: [PATCH 05/11] Update ParserClass files --- .../FileManContainer/FileManContainer.cpp | 25 ++++++++++ .../FileManContainer/FileManContainer.hpp | 46 +++++++++++++++++++ ParserClass/FileManContainer/Website.cpp | 17 +++++++ ParserClass/FileManContainer/Website.hpp | 11 ++++- ParserClass/FileManParser.cpp | 24 ++++++++-- ParserClass/FileManParser.hpp | 5 +- main.cpp | 8 +++- 7 files changed, 128 insertions(+), 8 deletions(-) diff --git a/ParserClass/FileManContainer/FileManContainer.cpp b/ParserClass/FileManContainer/FileManContainer.cpp index e69de29..7f04be4 100644 --- a/ParserClass/FileManContainer/FileManContainer.cpp +++ b/ParserClass/FileManContainer/FileManContainer.cpp @@ -0,0 +1,25 @@ +/** + * @file FileManContainer.cpp + * @brief FileManContainer class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implementation of FileManContainer class. + * + */ + + +#include "FileManContainer.hpp" + +FileManContainer::FileManContainer(){ +} + + + +void FileManContainer::addWebsite(Website website){ + this->websites.push_back(website); +} + +std::vector<Website> FileManContainer::getWebsites(){ + return this->websites; +} diff --git a/ParserClass/FileManContainer/FileManContainer.hpp b/ParserClass/FileManContainer/FileManContainer.hpp index e69de29..d5be276 100644 --- a/ParserClass/FileManContainer/FileManContainer.hpp +++ b/ParserClass/FileManContainer/FileManContainer.hpp @@ -0,0 +1,46 @@ +/** + * @file FileManContainer.hpp + * @brief FileManContainer class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of FileManContainer class. + * + */ + +#ifndef __FileManContainer__ +#define __FileManContainer__ + +//----- std ----- + +#include <string> +#include <vector> + +//----- class ----- +#include "Website.hpp" + + +/** + * @class Website Website.hpp "/ParserClass/FileManContainer/Website.hpp" + * @brief Class for manager all FileMan container (websites etc...) + * @author manzerbredes + * + * + * + */ + +class FileManContainer{ + + public: + FileManContainer(); + + void addWebsite(Website website); + std::vector<Website> getWebsites(); + + private: + + std::vector<Website> websites; +}; + + +#endif diff --git a/ParserClass/FileManContainer/Website.cpp b/ParserClass/FileManContainer/Website.cpp index 0d25344..0e1a670 100644 --- a/ParserClass/FileManContainer/Website.cpp +++ b/ParserClass/FileManContainer/Website.cpp @@ -11,6 +11,20 @@ #include "Website.hpp" + +Website::Website(){ + boost::uuids::uuid uuid = boost::uuids::random_generator()(); + std::stringstream ss; + ss << uuid; + this->id=ss.str(); +} + + + + +std::string Website::getId(){ + return this->id; +} std::string Website::getTitle(){ return this->title; } @@ -29,6 +43,9 @@ std::string Website::getDescription(){ +void Website::setId(std::string id){ + this->id = id; +} void Website::setTitle(std::string title){ this->title = title; } diff --git a/ParserClass/FileManContainer/Website.hpp b/ParserClass/FileManContainer/Website.hpp index 01c41f9..ceb21ad 100644 --- a/ParserClass/FileManContainer/Website.hpp +++ b/ParserClass/FileManContainer/Website.hpp @@ -27,6 +27,10 @@ */ #include <string> +#include <sstream> +#include <boost/uuid/uuid.hpp> // uuid class +#include <boost/uuid/uuid_generators.hpp> // generators +#include <boost/uuid/uuid_io.hpp> // streaming operators etc. @@ -43,10 +47,13 @@ class Website{ public: + Website(); + /** * @brief Containner getters. */ + std::string getId(); std::string getTitle(); std::string getUrl(); std::string getUsername(); @@ -57,6 +64,7 @@ class Website{ /** * @brief Containner setters. */ + void setId(std::string title); void setTitle(std::string title); void setUrl(std::string url); void setUsername(std::string username); @@ -66,7 +74,8 @@ class Website{ private: - std::string title; ///< Title en the website + std::string id; ///< id of the website + std::string title; ///< Title of the website std::string url; ///< Url of the website std::string username; ///< username of the account std::string password; ///< password of the account diff --git a/ParserClass/FileManParser.cpp b/ParserClass/FileManParser.cpp index 00db891..8cc72b5 100644 --- a/ParserClass/FileManParser.cpp +++ b/ParserClass/FileManParser.cpp @@ -41,8 +41,8 @@ FileManParser::FileManParser(std::string data){ -std::vector<Website> FileManParser::getWebsites(){ - return this->websites; +FileManContainer FileManParser::getContainer(){ + return this->container; } @@ -64,9 +64,25 @@ void FileManParser::initWebsites(){ std::string TagName=xercesc::XMLString::transcode(current->getNodeName()); if( current->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) { + Website newWebsite; - std::cout << this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"title"); - std::cout << this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"url"); + newWebsite.setTitle(\ + this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"title")); + + newWebsite.setUrl(\ + this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"url")); + + newWebsite.setUsername(\ + this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"username")); + + newWebsite.setPassword(\ + this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"password")); + + newWebsite.setDescription(\ + this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"description")); + + + this->container.addWebsite(newWebsite); } } diff --git a/ParserClass/FileManParser.hpp b/ParserClass/FileManParser.hpp index 88c959e..6a977db 100644 --- a/ParserClass/FileManParser.hpp +++ b/ParserClass/FileManParser.hpp @@ -15,6 +15,7 @@ //----- class ----- #include "Website.hpp" +#include "FileManContainer.hpp" //----- xerces ----- #include <xercesc/parsers/XercesDOMParser.hpp> @@ -35,7 +36,7 @@ class FileManParser{ - std::vector<Website> getWebsites(); + FileManContainer getContainer(); void initWebsites(); @@ -50,7 +51,7 @@ class FileManParser{ xercesc::DOMElement* root; - std::vector<Website> websites; ///< contain all websites entries + FileManContainer container; ///< contain all container std::string data; ///< contain data to parse diff --git a/main.cpp b/main.cpp index 9a3b3f1..5b4c74d 100644 --- a/main.cpp +++ b/main.cpp @@ -15,11 +15,13 @@ #include <iostream> #include <string> +#include <vector> //----- class ----- #include "FileManIOFile.hpp" #include "FileManParser.hpp" - +#include "FileManContainer.hpp" +#include "Website.hpp" /** * @fn int main(int argc, char *argv[]) @@ -68,6 +70,10 @@ int main(int argc, char *argv[]){ if(fichier.isReadable()) std::cout << fichier.getData();*/ + FileManContainer container= parser.getContainer(); + std::vector<Website> websites= container.getWebsites(); + std::cout << websites.at(1).getId(); + return 0; } From 8a14c386555b5b9ccd8d850713bd7732cdeb3fa3 Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Wed, 11 Mar 2015 20:06:26 +0400 Subject: [PATCH 06/11] Rename for better understanding --- ParserClass/{AbstractContainer.cpp => AbstractIDManager.cpp} | 0 ParserClass/{AbstractContainer.hpp => AbstractIDManager.hpp} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename ParserClass/{AbstractContainer.cpp => AbstractIDManager.cpp} (100%) rename ParserClass/{AbstractContainer.hpp => AbstractIDManager.hpp} (100%) diff --git a/ParserClass/AbstractContainer.cpp b/ParserClass/AbstractIDManager.cpp similarity index 100% rename from ParserClass/AbstractContainer.cpp rename to ParserClass/AbstractIDManager.cpp diff --git a/ParserClass/AbstractContainer.hpp b/ParserClass/AbstractIDManager.hpp similarity index 100% rename from ParserClass/AbstractContainer.hpp rename to ParserClass/AbstractIDManager.hpp From 6fcf2131d319d8c9a7bff67defb83098e4fe5cab Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Wed, 11 Mar 2015 21:32:36 +0400 Subject: [PATCH 07/11] Update ParserClass --- ParserClass/AbstractIDManager.cpp | 47 ++++++++++-------------- ParserClass/AbstractIDManager.hpp | 36 ++++++++++++++++++ ParserClass/FileManContainer/Website.cpp | 13 ++----- ParserClass/FileManContainer/Website.hpp | 12 +----- 4 files changed, 60 insertions(+), 48 deletions(-) diff --git a/ParserClass/AbstractIDManager.cpp b/ParserClass/AbstractIDManager.cpp index 370fc06..852c201 100644 --- a/ParserClass/AbstractIDManager.cpp +++ b/ParserClass/AbstractIDManager.cpp @@ -1,39 +1,30 @@ /** - * @file AbstractFileContainer.hpp - * @brief FileManContainer class definitions + * @file AbstractIDManager.cpp + * @brief AbstractIDManager class definitions * @author manzerbredes * @date 11 Mars 2015 * - * Contain all definitions of FileManContainer class. + * Contain all implémentations of AbstractIDManager class. * */ -#ifndef __FileManContainer__ -#define __FileManContainer__ +#include "AbstractIDManager.hpp" +AbstractIDManager::AbstractIDManager(){ + this->id=this->generateId(); +} +void AbstractIDManager::setId(std::string id){ + this->id = id; +} -/** - * @class Website Website.hpp "/ParserClass/FileManContainer/Website.hpp" - * @brief Class for manager all FileMan container (websites etc...) - * @author manzerbredes - * - * - * - */ +std::string AbstractIDManager::generateId(){ + boost::uuids::uuid uuid = boost::uuids::random_generator()(); + std::stringstream ss; + ss << uuid; + return ss.str(); +} -class FileManContainer{ - - public: - FileManContainer(); - - void addWebsite(Website website); - std::vector<Website> getWebsites(); - - private: - - std::vector<Website> websites; -}; - - -#endif +std::string AbstractIDManager::getId(){ + return this->id; +} diff --git a/ParserClass/AbstractIDManager.hpp b/ParserClass/AbstractIDManager.hpp index e69de29..9281915 100644 --- a/ParserClass/AbstractIDManager.hpp +++ b/ParserClass/AbstractIDManager.hpp @@ -0,0 +1,36 @@ +/** + * @file AbstractIDManager.cpp + * @brief AbstractIDManager class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of AbstractIDManager class. + * + */ + +#include <string> +#include <sstream> +#include <boost/uuid/uuid.hpp> // uuid class +#include <boost/uuid/uuid_generators.hpp> // generators +#include <boost/uuid/uuid_io.hpp> // streaming operators etc. + + + + + + class AbstractIDManager{ + + + public: + AbstractIDManager(); + + std::string getId(); + void setId(std::string id); + + std::string generateId(); + + private: + + std::string id; + + }; diff --git a/ParserClass/FileManContainer/Website.cpp b/ParserClass/FileManContainer/Website.cpp index 0e1a670..d54e28a 100644 --- a/ParserClass/FileManContainer/Website.cpp +++ b/ParserClass/FileManContainer/Website.cpp @@ -13,18 +13,13 @@ Website::Website(){ - boost::uuids::uuid uuid = boost::uuids::random_generator()(); - std::stringstream ss; - ss << uuid; - this->id=ss.str(); + } -std::string Website::getId(){ - return this->id; -} + std::string Website::getTitle(){ return this->title; } @@ -43,9 +38,7 @@ std::string Website::getDescription(){ -void Website::setId(std::string id){ - this->id = id; -} + void Website::setTitle(std::string title){ this->title = title; } diff --git a/ParserClass/FileManContainer/Website.hpp b/ParserClass/FileManContainer/Website.hpp index ceb21ad..c370f3b 100644 --- a/ParserClass/FileManContainer/Website.hpp +++ b/ParserClass/FileManContainer/Website.hpp @@ -27,12 +27,7 @@ */ #include <string> -#include <sstream> -#include <boost/uuid/uuid.hpp> // uuid class -#include <boost/uuid/uuid_generators.hpp> // generators -#include <boost/uuid/uuid_io.hpp> // streaming operators etc. - - +#include "AbstractIDManager.hpp" /** * @class Website Website.hpp "/ParserClass/FileManContainer/Website.hpp" @@ -42,7 +37,7 @@ * Container for website data. * */ -class Website{ +class Website : public AbstractIDManager { public: @@ -53,7 +48,6 @@ class Website{ * @brief Containner getters. */ - std::string getId(); std::string getTitle(); std::string getUrl(); std::string getUsername(); @@ -64,7 +58,6 @@ class Website{ /** * @brief Containner setters. */ - void setId(std::string title); void setTitle(std::string title); void setUrl(std::string url); void setUsername(std::string username); @@ -74,7 +67,6 @@ class Website{ private: - std::string id; ///< id of the website std::string title; ///< Title of the website std::string url; ///< Url of the website std::string username; ///< username of the account From 80f1e1ce67332a82f03e092b6b2396b0834efad9 Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Thu, 12 Mar 2015 20:59:12 +0400 Subject: [PATCH 08/11] Checking comments --- CryptClass/HASHCrypt.cpp | 53 +++++++++++++++++++++++----------------- CryptClass/HASHCrypt.hpp | 26 ++++++++++++-------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/CryptClass/HASHCrypt.cpp b/CryptClass/HASHCrypt.cpp index cd0dab6..eed9cb5 100644 --- a/CryptClass/HASHCrypt.cpp +++ b/CryptClass/HASHCrypt.cpp @@ -8,13 +8,12 @@ * */ + //----- class ----- #include "HASHCrypt.hpp" - - //Constructor HASHCrypt::HASHCrypt(){ } @@ -25,6 +24,7 @@ HASHCrypt::~HASHCrypt(){ +//Contruct MD5 over 128 bits and put it into digest void HASHCrypt::getMD5_128(std::string chain, byte* digest, int size){ //Digest size controller @@ -37,6 +37,8 @@ void HASHCrypt::getMD5_128(std::string chain, byte* digest, int size){ } + +//Contruct SHA-256 and put it into digest void HASHCrypt::getSHA_256(std::string chain, byte* digest, int size){ //Digest size controller @@ -50,27 +52,6 @@ void HASHCrypt::getSHA_256(std::string chain, byte* digest, int size){ } -//Check the size of the digest -void HASHCrypt::checkDigestSize(int sizeRequired, int size){ - try{ - if(size !=sizeRequired){ - throw this->getInvalidDigestSizeError(sizeRequired, size); - } - - } - catch(std::string erreur){ - std::cerr << erreur <<std::endl; - std::exit(EXIT_FAILURE); - } -} - -//Make the error -std::string HASHCrypt::getInvalidDigestSizeError(int sizeRequired, int size){ - std::ostringstream erreurStream; - erreurStream << "Invalid digest size ! ("<< sizeRequired <<" bytes required and "<< size <<" given)"; - return erreurStream.str(); -} - //Compare 2 digest (same size) bool HASHCrypt::compareDigest(byte* digest1, byte* digest2, int size){ @@ -96,6 +77,7 @@ bool HASHCrypt::compareDigest(byte* digest1, byte* digest2, int size){ } + //Convert digest to string std::string HASHCrypt::digestToString(byte* digest, int size){ @@ -107,3 +89,28 @@ std::string HASHCrypt::digestToString(byte* digest, int size){ return output; } + + + +//Check the size of the digest +void HASHCrypt::checkDigestSize(int sizeRequired, int size){ + try{ + if(size !=sizeRequired){ + throw this->getInvalidDigestSizeError(sizeRequired, size); + } + + } + catch(std::string erreur){ + std::cerr << erreur <<std::endl; + std::exit(EXIT_FAILURE); + } +} + + + +//Make the error +std::string HASHCrypt::getInvalidDigestSizeError(int sizeRequired, int size){ + std::ostringstream erreurStream; + erreurStream << "Invalid digest size ! ("<< sizeRequired <<" bytes required and "<< size <<" given)"; + return erreurStream.str(); +} diff --git a/CryptClass/HASHCrypt.hpp b/CryptClass/HASHCrypt.hpp index 2c17d3d..3eafb2f 100644 --- a/CryptClass/HASHCrypt.hpp +++ b/CryptClass/HASHCrypt.hpp @@ -45,27 +45,31 @@ class HASHCrypt{ */ ~HASHCrypt(); + /** * @brief Create an MD5 over 128 bits on a digest array of bytes. * * @param chain : Chain to hash * @param digest : An array of bytes (8 bits) - * @param size : Length of the array digest + * @param size : Length of digest * * **Warning** digest will be modified. * Digest must be an array of byte with 16 entries + * Invalid size can cause "Segmentation Fault" */ void getMD5_128(std::string chain, byte* digest, int size); + /** * @brief Create an SHA over 256 bits on a digest array of bytes. * * @param chain : Chain to hash * @param digest : An array of bytes (8 bits) - * @param size : Length of the array digest + * @param size : Length of digest * * **Warning** digest will be modified. * Digest must be an array of byte with 32 entries + * Invalid size can cause "Segmentation Fault" */ void getSHA_256(std::string chain, byte* digest, int size); //Return SHA_256 @@ -73,14 +77,15 @@ class HASHCrypt{ /** * @brief Convert digest to a string of HEX characters * - * @param digest : An array of bytes (8 bits) - * @param size : Length of the array digest + * @param digest : an array of bytes (8 bits) + * @param size : length of digest * - * @return a string of hex digest equivalent + * @return return a string of hex digest equivalent * - * Digest must be an array of byte with 16 entries + * Digest must be an array of byte. */ - std::string digestToString(byte* digest, int size); //Return a string of a digest + std::string digestToString(byte* digest, int size); //Return a string + /** * @brief Compare 2 digest @@ -89,10 +94,11 @@ class HASHCrypt{ * @param digest2 : An array of bytes (8 bits) * @param size : Length of the array digest1 or digest2 * - * @return a boolean if digest1 equals to digest2 + * @return return a boolean (true if digest1 equals to digest2 and false else) * * **Warning** if sizeof(digest1) != sizeof(digest 2) : segmentation fault ! * Compare the two digest. + * */ bool compareDigest(byte* digest1, byte* digest2, int size); @@ -105,7 +111,7 @@ class HASHCrypt{ * @param sizeRequired : Digest size expected * @param size : Given digest size * - * Throw an exception, and stop the programm if + * Throw an exception, and stop the program if * sizeRequired != size * Use getInvalidDigestSizeError method. */ @@ -113,7 +119,7 @@ class HASHCrypt{ /** - * @brief Make and error message. + * @brief Make "invalid digest size" error message. * * @param sizeRequired : Digest size expected * @param size : Given digest size From 00ed5faf673fa24e9525a894a7af34657ea066d8 Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Thu, 12 Mar 2015 21:04:49 +0400 Subject: [PATCH 09/11] Check comments, and code. --- CryptClass/AbstractSKA.hpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/CryptClass/AbstractSKA.hpp b/CryptClass/AbstractSKA.hpp index ca7230b..5a23c36 100644 --- a/CryptClass/AbstractSKA.hpp +++ b/CryptClass/AbstractSKA.hpp @@ -7,28 +7,33 @@ * Specify which method the algorithm must be implement. * */ + #ifndef __AbstractSKA__ #define __AbstractSKA__ + +//----- std ----- #include <string> + /** * @class AbstractSKA AbstractSKA.hpp "/CryptClass/AbstractSKA.hpp" * @brief Class for Symmetric-Key Algorithm (SKA) * @author manzerbredes * - * This class should not be instanciate directly. + * This class should not be instantiate directly. * */ - class AbstractSKA { public: - AbstractSKA(){ - } - ~AbstractSKA(){ - } + //Constructor + AbstractSKA(); + + //Destructor + ~AbstractSKA(); + /** * @brief Encrypt data. @@ -42,6 +47,7 @@ class AbstractSKA { */ virtual std::string encrypt(std::string key, std::string data) = 0; + /** * @brief Decrypt data. * From 40c659f6810b712c366e50139046995af46f42cc Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Fri, 13 Mar 2015 10:52:34 +0400 Subject: [PATCH 10/11] Update class --- CryptClass/AESCrypt.cpp | 1 + CryptClass/AbstractSKA.hpp | 7 ------- ParserClass/AbstractIDManager.cpp | 9 +++++++++ ParserClass/AbstractIDManager.hpp | 31 +++++++++++++++++++++++++++---- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/CryptClass/AESCrypt.cpp b/CryptClass/AESCrypt.cpp index 0222e9a..30e501a 100644 --- a/CryptClass/AESCrypt.cpp +++ b/CryptClass/AESCrypt.cpp @@ -21,6 +21,7 @@ AESCrypt::AESCrypt(){ //Destructor AESCrypt::~AESCrypt(){ + } diff --git a/CryptClass/AbstractSKA.hpp b/CryptClass/AbstractSKA.hpp index 5a23c36..7622ab4 100644 --- a/CryptClass/AbstractSKA.hpp +++ b/CryptClass/AbstractSKA.hpp @@ -28,13 +28,6 @@ class AbstractSKA { public: - //Constructor - AbstractSKA(); - - //Destructor - ~AbstractSKA(); - - /** * @brief Encrypt data. * diff --git a/ParserClass/AbstractIDManager.cpp b/ParserClass/AbstractIDManager.cpp index 852c201..01e3c3d 100644 --- a/ParserClass/AbstractIDManager.cpp +++ b/ParserClass/AbstractIDManager.cpp @@ -14,6 +14,15 @@ AbstractIDManager::AbstractIDManager(){ this->id=this->generateId(); } +AbstractIDManager::AbstractIDManager(std::string id){ + this->id=id; +} +AbstractIDManager::~AbstractIDManager(){ + this->id=id; +} + + + void AbstractIDManager::setId(std::string id){ this->id = id; } diff --git a/ParserClass/AbstractIDManager.hpp b/ParserClass/AbstractIDManager.hpp index 9281915..a18d1b2 100644 --- a/ParserClass/AbstractIDManager.hpp +++ b/ParserClass/AbstractIDManager.hpp @@ -1,15 +1,21 @@ /** - * @file AbstractIDManager.cpp + * @file AbstractIDManager.hpp * @brief AbstractIDManager class definitions * @author manzerbredes * @date 11 Mars 2015 * * Contain all definitions of AbstractIDManager class. + * If you want to manage id in class (like container), use + * this class as superclass. * */ +//----- std ----- #include <string> #include <sstream> + + +//----- boost ----- #include <boost/uuid/uuid.hpp> // uuid class #include <boost/uuid/uuid_generators.hpp> // generators #include <boost/uuid/uuid_io.hpp> // streaming operators etc. @@ -17,20 +23,37 @@ - +/** + * @class AbstractIDManager AbstractIDManager.hpp "/CryptClass/AbstractIDManager.hpp" + * @brief Managing ID + * @author manzerbredes + * + * This class should not be instantiate directly. + * + */ class AbstractIDManager{ public: + //Constructor AbstractIDManager(); + //Constructor, init with id + AbstractIDManager(std::string); + + //Destructor + ~AbstractIDManager(); + + + //Getters and setters std::string getId(); void setId(std::string id); - std::string generateId(); private: + //Generate and random id + std::string generateId(); - std::string id; + std::string id; ///< String id attribute }; From c113e7b5f46a3434f017de3f2c9f83a002b246f1 Mon Sep 17 00:00:00 2001 From: manzerbredes <loic.guegan_secondary@yahoo.fr> Date: Fri, 13 Mar 2015 15:06:36 +0400 Subject: [PATCH 11/11] Update parser --- ParserClass/FileManParser.cpp | 26 +++++++++++++++++++++----- main.cpp | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ParserClass/FileManParser.cpp b/ParserClass/FileManParser.cpp index 8cc72b5..66e3c52 100644 --- a/ParserClass/FileManParser.cpp +++ b/ParserClass/FileManParser.cpp @@ -52,36 +52,52 @@ std::string FileManParser::getData(){ return this->data;}; void FileManParser::initWebsites(){ + //Get websites élément xercesc::DOMElement* websitesElement=this->getChildByTagName(this->root, "websites"); + //Make list of website + xercesc::DOMNodeList* websiteList=websitesElement->getChildNodes(); + XMLSize_t websiteCount = websiteList->getLength(); - xercesc::DOMNodeList* nodeList=websitesElement->getChildNodes(); - XMLSize_t nodeCount = nodeList->getLength(); - for(int i=0;i<nodeCount;i++){ + //Read the list of website + for(int i=0;i<websiteCount;i++){ - xercesc::DOMNode* current=nodeList->item(i); + xercesc::DOMNode* current=websiteList->item(i); std::string TagName=xercesc::XMLString::transcode(current->getNodeName()); if( current->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) { Website newWebsite; + //Get id + XMLCh* idXMLCh=(XMLCh*)((xercesc::DOMElement*)current)->getAttribute((XMLCh*) xercesc::XMLString::transcode("id")); + //Convert id to string from XMLCh + std::string id=xercesc::XMLString::transcode(idXMLCh); + + //Assign id + newWebsite.setId(id); + + //Assign title newWebsite.setTitle(\ this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"title")); + //Assign url newWebsite.setUrl(\ this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"url")); + //Assign username newWebsite.setUsername(\ this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"username")); + //Assign password newWebsite.setPassword(\ this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"password")); + //Assign description newWebsite.setDescription(\ this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"description")); - + //Add website to container this->container.addWebsite(newWebsite); } diff --git a/main.cpp b/main.cpp index 5b4c74d..dd455a5 100644 --- a/main.cpp +++ b/main.cpp @@ -72,7 +72,7 @@ int main(int argc, char *argv[]){ FileManContainer container= parser.getContainer(); std::vector<Website> websites= container.getWebsites(); - std::cout << websites.at(1).getId(); + std::cout << websites.at(0).getId(); return 0;