From 45f7cc5d27b338dae1d36c211cc5720c82f3de35 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 20 Mar 2015 10:57:03 +0400 Subject: Change file architecture --- src/ParserClass/AbstractIDManager.cpp | 39 ++++++++ src/ParserClass/AbstractIDManager.hpp | 59 ++++++++++++ src/ParserClass/FileManContainer/Website.cpp | 67 ++++++++++++++ src/ParserClass/FileManContainer/Website.hpp | 83 +++++++++++++++++ src/ParserClass/FileManParser.cpp | 132 +++++++++++++++++++++++++++ src/ParserClass/FileManParser.hpp | 114 +++++++++++++++++++++++ 6 files changed, 494 insertions(+) create mode 100644 src/ParserClass/AbstractIDManager.cpp create mode 100644 src/ParserClass/AbstractIDManager.hpp create mode 100644 src/ParserClass/FileManContainer/Website.cpp create mode 100644 src/ParserClass/FileManContainer/Website.hpp create mode 100644 src/ParserClass/FileManParser.cpp create mode 100644 src/ParserClass/FileManParser.hpp (limited to 'src/ParserClass') diff --git a/src/ParserClass/AbstractIDManager.cpp b/src/ParserClass/AbstractIDManager.cpp new file mode 100644 index 0000000..e1c5e13 --- /dev/null +++ b/src/ParserClass/AbstractIDManager.cpp @@ -0,0 +1,39 @@ +/** + * @file AbstractIDManager.cpp + * @brief AbstractIDManager class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implémentations of AbstractIDManager class. + * + */ + +#include "AbstractIDManager.hpp" + +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; +} + +std::string AbstractIDManager::generateId(){ + boost::uuids::uuid uuid = boost::uuids::random_generator()(); + std::stringstream ss; + ss << uuid; + return ss.str(); +} + +std::string AbstractIDManager::getId() const{ + return this->id; +} diff --git a/src/ParserClass/AbstractIDManager.hpp b/src/ParserClass/AbstractIDManager.hpp new file mode 100644 index 0000000..67d5f6f --- /dev/null +++ b/src/ParserClass/AbstractIDManager.hpp @@ -0,0 +1,59 @@ +/** + * @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 +#include + + +//----- boost ----- +#include // uuid class +#include // generators +#include // streaming operators etc. + + + + +/** + * @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() const; + void setId(std::string id); + + + private: + //Generate and random id + std::string generateId(); + + std::string id; ///< String id attribute + + }; diff --git a/src/ParserClass/FileManContainer/Website.cpp b/src/ParserClass/FileManContainer/Website.cpp new file mode 100644 index 0000000..f65a66d --- /dev/null +++ b/src/ParserClass/FileManContainer/Website.cpp @@ -0,0 +1,67 @@ +/** + * @file Website.cpp + * @brief Website class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implementations of Website class. + * + */ + + +#include "Website.hpp" + + +//Constructor +Website::Website(){ + +} + + + +//----- Getters ----- +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; +} + + + +//----- Setters ----- +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; +} + + + +//Equality comparator +bool Website::operator==(const Website& website) const{ + if((this->getId()).compare(website.getId())==0){ + return true; + } + return false; +} + diff --git a/src/ParserClass/FileManContainer/Website.hpp b/src/ParserClass/FileManContainer/Website.hpp new file mode 100644 index 0000000..cb293d4 --- /dev/null +++ b/src/ParserClass/FileManContainer/Website.hpp @@ -0,0 +1,83 @@ +/** + * @file Website.hpp + * @brief Website class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of Website class. + * + */ + +#ifndef __WEBSITE__ +#define __WEBSITE__ + +#include + + +/** + * @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 +#include "AbstractIDManager.hpp" + +/** + * @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 AbstractIDManager { + + + public: + + Website(); + + /** + * @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); + + + /** + * @brief Equality comparator + */ + bool operator==(const Website& website) const; + + private: + + 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 + std::string description; ///< Description of the website +}; + + +#endif diff --git a/src/ParserClass/FileManParser.cpp b/src/ParserClass/FileManParser.cpp new file mode 100644 index 0000000..57a485a --- /dev/null +++ b/src/ParserClass/FileManParser.cpp @@ -0,0 +1,132 @@ +/** + * @file FileManParser.cpp + * @brief FileManParser class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implementations of FileManParser class. + * + */ + + +#include "FileManParser.hpp" + + +FileManParser::FileManParser(std::string data){ + + //String to stringstream + (this->dataStream) << data; + + //Create parser + //parser.parse_stream(dataStream); + (this->parser).parse_file("Doxygen/doc.xml"); + + //Retrieve document + this->document=(this->parser).get_document(); + + //Init root Node + this->rootNode=(this->document)->get_root_node(); + + //Init container: + this->initWebsites(); + + + +} + + +std::string FileManParser::getDocument(){ + std::string data=(this->document)->write_to_string(); + return data; +} + + +std::vector* FileManParser::getWebsites(){ + return this->websites; +} + + + + +//----------------Container part------------------------ +void FileManParser::initWebsites(){ + this->websites=new std::vector; + + std::vector websitesNodeSet=this->rootNode->find("//websites"); + this->websitesNode=websitesNodeSet.at(0); + + std::vector websiteNodeSet=this->websitesNode->find("*"); + + for(int i=0;iget_attribute_value("id")); + + std::vector websiteChildren=current->find("*"); + + for(int j=0;j contentNodes=currentChild->get_children(); + xmlpp::CdataNode* cdataNode=(xmlpp::CdataNode*)contentNodes.front(); + std::string cdataContent=cdataNode->get_content(); + + + if(currentChild->get_name().compare("title")==0){ + newWebsite.setTitle(cdataContent); + } + else if(currentChild->get_name().compare("url")==0){ + newWebsite.setUrl(cdataContent); + } + else if(currentChild->get_name().compare("username")==0){ + newWebsite.setUsername(cdataContent); + } + else if(currentChild->get_name().compare("password")==0){ + newWebsite.setPassword(cdataContent); + } + else if(currentChild->get_name().compare("description")==0){ + newWebsite.setDescription(cdataContent); + } + } + this->websites->push_back(newWebsite); + } +} + + + + + + + + + +void FileManParser::updateParser(){ + this->rootNode->remove_child(this->websitesNode); + + xmlpp::Element* websitesNode=this->rootNode->add_child("websites"); + this->websitesNode=(xmlpp::Node*)websitesNode; + + for(int i=0;iwebsites->size();i++){ + xmlpp::Element* current=this->websitesNode->add_child("website"); + Website currentWebsite=this->websites->at(i); + + current->set_attribute("id", currentWebsite.getId()); + xmlpp::Element* title=current->add_child("title"); + title->add_child_cdata(currentWebsite.getTitle()); + + xmlpp::Element* url=current->add_child("url"); + url->add_child_cdata(currentWebsite.getUrl()); + + xmlpp::Element* username=current->add_child("username"); + username->add_child_cdata(currentWebsite.getUsername()); + + xmlpp::Element* password=current->add_child("password"); + password->add_child_cdata(currentWebsite.getPassword()); + + xmlpp::Element* description=current->add_child("description"); + description->add_child_cdata(currentWebsite.getDescription()); + + } +} diff --git a/src/ParserClass/FileManParser.hpp b/src/ParserClass/FileManParser.hpp new file mode 100644 index 0000000..f0d01e5 --- /dev/null +++ b/src/ParserClass/FileManParser.hpp @@ -0,0 +1,114 @@ +/** + * @file FileManParser.hpp + * @brief FileManParser class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of FileManParser class. + * + */ + + + +#ifndef __FileManParser__ +#define __FileManParser__ + + + +//----- std ----- +#include +#include +#include +#include + +//----- class ----- +#include "Website.hpp" + +//----- libxml++ ----- +#include +#include + + + +/** + * @class FileManParser FileManParser.hpp "/ParserClass/FileManContainer/FileManParser.hpp" + * @brief Class for parser un xml file in a string. + * @author manzerbredes + * + * Parse string using libxml++ library. + * + */ +class FileManParser{ + + + public: + + //Constructor + FileManParser(std::string data); + + + /** + * @brief Get document in string + * + * @return a string that contain the document + * + * Return current document. + * To have an up-to-date document, please run updateParser() before. + * + */ + std::string getDocument(); + + + /** + * @brief Write data in encrypted file. + * + * @return vector pointer that point to the vector of website in document + * + * You can modified this vector, and for apply change run updateParser() + * + */ + std::vector* getWebsites(); + + + + /** + * @brief Update the parser + * + * Apply all modifications you have made on the vector object (example std::vector* websites). + * + */ + void updateParser(); + + + private: + + + /** + * @brief Instanciate websites vector + * + * Read the document and create all Website object and put them into + * the websites vector attribute. + * + */ + void initWebsites(); + + + //Parser attributes + std::stringstream dataStream; ///< Contain the document you want to parse + xmlpp::DomParser parser; ///< Contain the parser + + + + //Document attributes + xmlpp::Document* document; ///< Contain the document (generate by the parser and dataStream) + xmlpp::Node* rootNode; ///< Contain the root node of the document + + + //Website attributes + xmlpp::Node* websitesNode; ///< Contain the websites node of the document + std::vector *websites; ///< Contain all website of the document (you can modify it and run updateParser to apply all modifications). + +}; + + +#endif -- cgit v1.2.3