146 lines
2.9 KiB
C
146 lines
2.9 KiB
C
|
#pragma once
|
||
|
#include <string>
|
||
|
#include "expat.h"
|
||
|
#include <vector>
|
||
|
#include <map>
|
||
|
#include "BPBinary.h"
|
||
|
|
||
|
using namespace std;
|
||
|
class JobContent
|
||
|
{
|
||
|
public:
|
||
|
struct Version
|
||
|
{
|
||
|
unsigned int major;
|
||
|
unsigned int minor;
|
||
|
unsigned int revision;
|
||
|
explicit Version() {
|
||
|
major = 2;
|
||
|
minor = 0;
|
||
|
revision = 0;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
enum EncryptionScheme {
|
||
|
PreSharedPassPhrase,
|
||
|
Materialise0001
|
||
|
};
|
||
|
|
||
|
struct EncryptedContent
|
||
|
{
|
||
|
string encryption_scheme;
|
||
|
string initialization_vector; //Base64 string containing 128 bit data
|
||
|
string cipher_text;
|
||
|
};
|
||
|
|
||
|
struct SessionKey
|
||
|
{
|
||
|
map<string, EncryptedContent*> encrypted_contents_map;
|
||
|
~SessionKey() {
|
||
|
for (map<string, EncryptedContent*>::iterator it = encrypted_contents_map.begin(); it != encrypted_contents_map.end(); it++) {
|
||
|
delete it->second;
|
||
|
}
|
||
|
encrypted_contents_map.clear();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct EncryptionStrategy {
|
||
|
string id;
|
||
|
string method;
|
||
|
SessionKey* session_key;
|
||
|
string initialization_vector;
|
||
|
EncryptionStrategy() {
|
||
|
session_key = new SessionKey();
|
||
|
}
|
||
|
|
||
|
~EncryptionStrategy() {
|
||
|
delete session_key;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct MetadataFile
|
||
|
{
|
||
|
string file_name;
|
||
|
string encryption_strategy_ref;
|
||
|
};
|
||
|
|
||
|
struct BinaryFile {
|
||
|
string file_name;
|
||
|
string encryption_strategy_ref;
|
||
|
bool is_outside_container;
|
||
|
};
|
||
|
|
||
|
struct ContainerFiles
|
||
|
{
|
||
|
MetadataFile* metadata_file;
|
||
|
vector<BinaryFile*> binary_files;
|
||
|
ContainerFiles() {
|
||
|
metadata_file = new MetadataFile();
|
||
|
}
|
||
|
|
||
|
~ContainerFiles() {
|
||
|
delete metadata_file;
|
||
|
for (size_t i = 0; i < binary_files.size(); ++i) {
|
||
|
delete binary_files[i];
|
||
|
binary_files[i] = NULL;
|
||
|
}
|
||
|
binary_files.clear();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct ParseAssist {
|
||
|
unsigned int depth;
|
||
|
string tempValue;
|
||
|
map<int, string> depthMap;
|
||
|
EncryptionStrategy* lastEncryptionStrategy;
|
||
|
EncryptedContent* lastEncryptedContent;
|
||
|
ParseAssist() {
|
||
|
depth = 0;
|
||
|
tempValue = "";
|
||
|
lastEncryptionStrategy = NULL;
|
||
|
lastEncryptedContent = NULL;
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
struct ContainerContent {
|
||
|
Version* version;
|
||
|
map<string, EncryptionStrategy*> encryption_strategies;
|
||
|
ContainerFiles* container_files;
|
||
|
ParseAssist parseAssist;
|
||
|
ContainerContent() {
|
||
|
version = new Version();
|
||
|
container_files = new ContainerFiles();
|
||
|
}
|
||
|
~ContainerContent() {
|
||
|
delete version;
|
||
|
map<string, EncryptionStrategy*>::iterator it;
|
||
|
for (it = encryption_strategies.begin(); it != encryption_strategies.end(); ++it) {
|
||
|
delete it->second;
|
||
|
}
|
||
|
encryption_strategies.clear();
|
||
|
delete container_files;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
public:
|
||
|
JobContent();
|
||
|
~JobContent();
|
||
|
bool LoadFile(string str);
|
||
|
string GetMetadataFileName();
|
||
|
string GetBinaryFileName(vector<BPBinary::BFileInfo>& bfiles);
|
||
|
|
||
|
private:
|
||
|
static void XMLCALL StartElement(void *userData, const XML_Char *name, const XML_Char **attrs);
|
||
|
static void XMLCALL EndElement(void *userData, const XML_Char *name);
|
||
|
static void XMLCALL DataHandler(void *userData, const XML_Char *s, int len);
|
||
|
|
||
|
public:
|
||
|
ContainerContent* m_container_content;
|
||
|
|
||
|
private:
|
||
|
string m_file_path;
|
||
|
XML_Parser m_Parser;
|
||
|
};
|
||
|
|