#include #include "rule.h" int rule_is_option(QString value) { if (value == "chained") return 1; if (value == "goto") return 1; if (value == "id") return 1; if (value == "last") return 1; if (value == "optgoto") return 1; if (value == "revision") return 1; if (value == "silent") return 1; return 0; } Rule::Rule(const QString &buffer, const QString &raw_buffer) : _buffer(buffer), _raw_buffer(raw_buffer) { } void Rule::addLogSample(const QString &line) { _log_samples << line; } void Rule::setRegex(const QString ®ex) { _regex = regex; } int Rule::addOption(const QString &key, const QString &value) { _dict[key] = value; return 0; } int Rule::setRuleOption(QString opt, QString value) { _options_dict[opt] = value; return 0; } int Rule::hasRuleOption(const QString opt) const { return _options_dict.contains(opt); } ostream & operator << (ostream &os, const Rule *r) { int i; // example logs for (int i=0; i_log_samples.size(); i++) { os << "#LOG:" << qPrintable(r->_log_samples.at(i)) << std::endl; } // regex os << "regex=" << qPrintable(r->_regex); // idmef values QMap::const_iterator it = r->_dict.constBegin(); while (it != r->_dict.constEnd()) { os << "; \\" << std::endl; os << " " << qPrintable(it.key()) << "=" << qPrintable(it.value()); ++it; } // keywords it = r->_options_dict.constBegin(); while (it != r->_options_dict.constEnd()) { os << "; \\" << std::endl; os << " " << qPrintable(it.key()); if ( !(it.key() == "chained" || it.key() == "last" || it.key() == "silent") ) { os << "=" << qPrintable(it.value()); } ++it; } os << std::endl; return os; }