diff options
Diffstat (limited to 'ParserClass')
| -rw-r--r-- | ParserClass/AbstractIDManager.cpp | 39 | ||||
| -rw-r--r-- | ParserClass/AbstractIDManager.hpp | 59 | ||||
| -rw-r--r-- | ParserClass/FileManContainer/FileManContainer.cpp | 25 | ||||
| -rw-r--r-- | ParserClass/FileManContainer/FileManContainer.hpp | 46 | ||||
| -rw-r--r-- | ParserClass/FileManContainer/Website.cpp | 56 | ||||
| -rw-r--r-- | ParserClass/FileManContainer/Website.hpp | 78 | ||||
| -rw-r--r-- | ParserClass/FileManParser.cpp | 133 | ||||
| -rw-r--r-- | ParserClass/FileManParser.hpp | 58 |
8 files changed, 494 insertions, 0 deletions
diff --git a/ParserClass/AbstractIDManager.cpp b/ParserClass/AbstractIDManager.cpp new file mode 100644 index 0000000..01e3c3d --- /dev/null +++ b/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(){ + return this->id; +} diff --git a/ParserClass/AbstractIDManager.hpp b/ParserClass/AbstractIDManager.hpp new file mode 100644 index 0000000..a18d1b2 --- /dev/null +++ b/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 <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. + + + + +/** + * @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); + + + private: + //Generate and random id + std::string generateId(); + + std::string id; ///< String id attribute + + }; diff --git a/ParserClass/FileManContainer/FileManContainer.cpp b/ParserClass/FileManContainer/FileManContainer.cpp new file mode 100644 index 0000000..7f04be4 --- /dev/null +++ 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 new file mode 100644 index 0000000..d5be276 --- /dev/null +++ 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 new file mode 100644 index 0000000..d54e28a --- /dev/null +++ b/ParserClass/FileManContainer/Website.cpp @@ -0,0 +1,56 @@ +/** + * @file Website.cpp + * @brief Website class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implementations of Website class. + * + */ + + +#include "Website.hpp" + + +Website::Website(){ + +} + + + + + +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 new file mode 100644 index 0000000..c370f3b --- /dev/null +++ b/ParserClass/FileManContainer/Website.hpp @@ -0,0 +1,78 @@ +/** + * @file Website.hpp + * @brief Website class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of Website class. + * + */ + +#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> +#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); + + + 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/ParserClass/FileManParser.cpp b/ParserClass/FileManParser.cpp new file mode 100644 index 0000000..66e3c52 --- /dev/null +++ b/ParserClass/FileManParser.cpp @@ -0,0 +1,133 @@ +/** + * @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){ + 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(); + + + +} + + + +FileManContainer FileManParser::getContainer(){ + return this->container; +} + + +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(); + + + //Read the list of website + for(int i=0;i<websiteCount;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); + + } + } +} + + +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 new file mode 100644 index 0000000..6a977db --- /dev/null +++ b/ParserClass/FileManParser.hpp @@ -0,0 +1,58 @@ +/** + * @file FileManParser.hpp + * @brief FileManParser class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of FileManParser class. + * + */ + +//----- std ----- +#include <iostream> +#include <string> +#include <vector> + +//----- class ----- +#include "Website.hpp" +#include "FileManContainer.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); + + + + FileManContainer getContainer(); + + 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; + + FileManContainer container; ///< contain all container + + std::string data; ///< contain data to parse + +}; |
