Begin parser...
This commit is contained in:
parent
aa249b5700
commit
c93be89ea6
5 changed files with 244 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
};
|
||||
|
|
31
main.cpp
31
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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue