1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Core functions
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//---------------------------------------------------------------------------
#ifndef CheckerH
#define CheckerH
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef TFSXML_NAMESPACE
#define TFSXML_NAMESPACE 1
#endif // TFSXML_NAMESPACE
#include "ThirdParty/tfsxml/tfsxml.h"
#include "Path.h"
#include <string>
#include <vector>
#include <map>
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
namespace MediaConch {
//---------------------------------------------------------------------------
class PolicyChecker
{
public:
PolicyChecker();
~PolicyChecker();
bool full_parse();
bool is_policy_supported();
void add_policy(const std::string& policy);
int analyze(const std::string& report, bool verbose, std::string& out);
private:
class Element
{
public:
typedef enum Level {
LEVEL_NONE = 0,
LEVEL_INFO,
LEVEL_WARN,
LEVEL_FAIL,
};
typedef enum Result {
RESULT_PASS = 0,
RESULT_INFO,
RESULT_WARN,
RESULT_FAIL,
};
Element() {};
virtual ~Element() {};
virtual void resolve()=0;
virtual Result result()=0;
virtual Level error_level()=0;
virtual std::string to_string(size_t level, bool verbose=false)=0;
std::string name;
};
class RuleElement : public Element {
public:
struct Source
{
std::vector<PathElement> path;
std::map<const char*, std::string> values;
std::string scope;
std::string field;
std::string tracktype;
std::string occurrence;
};
RuleElement();
~RuleElement();
void reset();
bool compare(const std::string& v1, const std::string& v2);
virtual void resolve();
virtual Result result();
virtual Level error_level();
virtual std::string to_string(size_t level, bool verbose=false);
std::vector<PathElement> path;
std::string scope;
std::string level;
std::string field;
std::string tracktype;
std::string occurrence;
std::string operand;
std::string xpath;
std::string requested;
std::map<const char*, std::string> values;
std::vector<std::string> failing_values;
Source* source;
size_t tracks;
private:
bool resolved;
bool pass;
};
class PolicyElement : public Element {
public:
PolicyElement();
~PolicyElement();
virtual void resolve();
virtual Result result();
virtual Level error_level();
virtual std::string to_string(size_t level, bool verbose=false);
std::string type;
std::string level;
std::string version;
std::string description;
std::vector<std::string> tags;
std::vector<Element*> children;
private:
bool resolved;
size_t pass_count;
size_t info_count;
size_t warn_count;
size_t fail_count;
};
RuleElement* parse_rule(tfsxml::tfsxml_string& tfsxml_priv);
PolicyElement* parse_policy(tfsxml::tfsxml_string& tfsxml_priv);
void parse_node(tfsxml::tfsxml_string& tfsxml_priv, std::vector<RuleElement*> rules, std::vector<RuleElement*> sources, size_t level);
std::vector<PolicyElement*> policies;
std::vector<RuleElement*> rules;
bool supported;
bool full;
};
}
#endif
|