mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Unify all of the Tag types into one type
- Remove tag types for each component type (analyzer, etc) - Add deprecated versions of the old types - Remove unnecessary tag element from templates for TaggedComponent and ComponentManager - Enable TaggedComponent to pass an EnumType when initializing Tag objects - Update some tests that are affected by the tag enum values changing order
This commit is contained in:
parent
4f9f46a0c4
commit
331161138a
46 changed files with 352 additions and 955 deletions
|
@ -379,7 +379,7 @@ set(MAIN_SRCS
|
|||
|
||||
plugin/Component.cc
|
||||
plugin/ComponentManager.h
|
||||
plugin/TaggedComponent.h
|
||||
plugin/TaggedComponent.cc
|
||||
plugin/Manager.cc
|
||||
plugin/Plugin.cc
|
||||
|
||||
|
|
13
src/Tag.cc
13
src/Tag.cc
|
@ -7,12 +7,15 @@
|
|||
namespace zeek
|
||||
{
|
||||
|
||||
const Tag Tag::Error;
|
||||
|
||||
Tag::Tag(type_t arg_type, subtype_t arg_subtype) : Tag(nullptr, arg_type, arg_subtype) { }
|
||||
|
||||
Tag::Tag(const EnumTypePtr& etype, type_t arg_type, subtype_t arg_subtype)
|
||||
: type(arg_type), subtype(arg_subtype), etype(etype)
|
||||
{
|
||||
assert(arg_type > 0);
|
||||
|
||||
type = arg_type;
|
||||
subtype = arg_subtype;
|
||||
int64_t i = (int64_t)(type) | ((int64_t)subtype << 31);
|
||||
val = etype->GetEnumVal(i);
|
||||
}
|
||||
|
@ -68,11 +71,13 @@ Tag& Tag::operator=(const Tag&& other) noexcept
|
|||
return *this;
|
||||
}
|
||||
|
||||
const EnumValPtr& Tag::AsVal(const EnumTypePtr& etype) const
|
||||
const EnumValPtr& Tag::AsVal() const
|
||||
{
|
||||
// TODO: this probably isn't valid, and we should just return the null val
|
||||
// if it's null.
|
||||
if ( ! val )
|
||||
{
|
||||
assert(type == 0 && subtype == 0);
|
||||
assert(type == 0 && subtype == 0 && etype != nullptr);
|
||||
val = etype->GetEnumVal(0);
|
||||
}
|
||||
|
||||
|
|
84
src/Tag.h
84
src/Tag.h
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "zeek/zeek-config.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "zeek/IntrusivePtr.h"
|
||||
|
@ -14,9 +14,9 @@ namespace zeek
|
|||
{
|
||||
|
||||
class EnumVal;
|
||||
using EnumValPtr = IntrusivePtr<EnumVal>;
|
||||
class EnumType;
|
||||
using EnumTypePtr = IntrusivePtr<EnumType>;
|
||||
using EnumValPtr = IntrusivePtr<EnumVal>;
|
||||
|
||||
/**
|
||||
* Class to identify an analyzer type.
|
||||
|
@ -59,28 +59,53 @@ public:
|
|||
*/
|
||||
subtype_t Subtype() const { return subtype; }
|
||||
|
||||
/**
|
||||
* Returns the numerical values for main and subtype inside a string
|
||||
* suitable for printing. This is primarily for debugging.
|
||||
*/
|
||||
std::string AsString() const;
|
||||
|
||||
protected:
|
||||
/*
|
||||
* Copy constructor.
|
||||
*/
|
||||
Tag(const Tag& other);
|
||||
|
||||
/**
|
||||
* Default constructor. This initializes the tag with an error value
|
||||
* that will make \c operator \c bool return false.
|
||||
*/
|
||||
Tag();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param etype the script-layer enum type associated with the tag.
|
||||
*
|
||||
* @param type The main type. Note that the manager class manages the
|
||||
* the value space internally, so noone else should assign main types.
|
||||
*
|
||||
* @param subtype The sub type, which is left to an analyzer for
|
||||
* interpretation. By default it's set to zero.
|
||||
*/
|
||||
Tag(const EnumTypePtr& etype, type_t type, subtype_t subtype = 0);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param type The main type. Note that the \a analyzer::Manager
|
||||
* manages the value space internally, so noone else should assign
|
||||
* any main types.
|
||||
*
|
||||
* @param subtype The sub type, which is left to an analyzer for
|
||||
* interpretation. By default it's set to zero.
|
||||
*/
|
||||
explicit Tag(type_t type, subtype_t subtype = 0);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param val An enum value of script type \c Analyzer::Tag.
|
||||
*/
|
||||
explicit Tag(EnumValPtr val);
|
||||
|
||||
/*
|
||||
* Copy constructor.
|
||||
*/
|
||||
Tag(const Tag& other);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Tag();
|
||||
virtual ~Tag();
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
|
@ -116,38 +141,33 @@ protected:
|
|||
return type != other.type ? type < other.type : (subtype < other.subtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numerical values for main and subtype inside a string
|
||||
* suitable for printing. This is primarily for debugging.
|
||||
*/
|
||||
std::string AsString() const;
|
||||
|
||||
/**
|
||||
* Returns the script-layer enum that corresponds to this tag.
|
||||
* The returned value does not have its ref-count increased.
|
||||
*
|
||||
* @param etype the script-layer enum type associated with the tag.
|
||||
*/
|
||||
const EnumValPtr& AsVal(const EnumTypePtr& etype) const;
|
||||
const EnumValPtr& AsVal() const;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param etype the script-layer enum type associated with the tag.
|
||||
*
|
||||
* @param type The main type. Note that the manager class manages the
|
||||
* the value space internally, so noone else should assign main types.
|
||||
*
|
||||
* @param subtype The sub type, which is left to an analyzer for
|
||||
* interpretation. By default it's set to zero.
|
||||
* Returns false if the tag represents an error value rather than a
|
||||
* legal analyzer type.
|
||||
*/
|
||||
Tag(const EnumTypePtr& etype, type_t type, subtype_t subtype = 0);
|
||||
explicit operator bool() const { return *this != Error; }
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param val An enum value of script type \c Analyzer::Tag.
|
||||
*/
|
||||
explicit Tag(EnumValPtr val);
|
||||
static const Tag Error;
|
||||
|
||||
private:
|
||||
type_t type; // Main type.
|
||||
subtype_t subtype; // Subtype.
|
||||
mutable EnumValPtr val; // Script-layer value.
|
||||
mutable EnumTypePtr etype;
|
||||
};
|
||||
|
||||
} // namespace zeek
|
||||
|
|
|
@ -12,11 +12,9 @@ set(analyzer_SRCS
|
|||
Analyzer.cc
|
||||
Manager.cc
|
||||
Component.cc
|
||||
Tag.cc
|
||||
)
|
||||
|
||||
bif_target(analyzer.bif)
|
||||
|
||||
bro_add_subdir_library(analyzer ${analyzer_SRCS})
|
||||
add_dependencies(bro_analyzer generate_outputs)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ Component::Component(const std::string& name, factory_callback arg_factory,
|
|||
bool arg_adapter)
|
||||
: plugin::Component(
|
||||
arg_adapter ? plugin::component::SESSION_ADAPTER : plugin::component::ANALYZER, name),
|
||||
plugin::TaggedComponent<analyzer::Tag>(arg_subtype)
|
||||
plugin::TaggedComponent(arg_subtype, analyzer_mgr->GetTagType())
|
||||
{
|
||||
factory = arg_factory;
|
||||
enabled = arg_enabled;
|
||||
|
|
|
@ -25,7 +25,7 @@ class Analyzer;
|
|||
* A plugin can provide a specific protocol analyzer by registering this
|
||||
* analyzer component, describing the analyzer.
|
||||
*/
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent<analyzer::Tag>
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent
|
||||
{
|
||||
public:
|
||||
using factory_callback = Analyzer* (*)(Connection* conn);
|
||||
|
|
|
@ -56,9 +56,7 @@ bool Manager::ConnIndex::operator<(const ConnIndex& other) const
|
|||
return false;
|
||||
}
|
||||
|
||||
Manager::Manager() : plugin::ComponentManager<analyzer::Tag, analyzer::Component>("Analyzer", "Tag")
|
||||
{
|
||||
}
|
||||
Manager::Manager() : plugin::ComponentManager<analyzer::Component>("Analyzer", "Tag") { }
|
||||
|
||||
Manager::~Manager()
|
||||
{
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace analyzer
|
|||
* respecting well-known ports, and tracking any analyzers specifically
|
||||
* scheduled for individidual connections.
|
||||
*/
|
||||
class Manager : public plugin::ComponentManager<Tag, Component>
|
||||
class Manager : public plugin::ComponentManager<Component>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "zeek/analyzer/Tag.h"
|
||||
|
||||
#include "zeek/analyzer/Manager.h"
|
||||
|
||||
namespace zeek::analyzer
|
||||
{
|
||||
|
||||
const Tag Tag::Error;
|
||||
|
||||
Tag::Tag(type_t type, subtype_t subtype) : zeek::Tag(analyzer_mgr->GetTagType(), type, subtype) { }
|
||||
|
||||
Tag& Tag::operator=(const Tag& other)
|
||||
{
|
||||
zeek::Tag::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const EnumValPtr& Tag::AsVal() const
|
||||
{
|
||||
return zeek::Tag::AsVal(analyzer_mgr->GetTagType());
|
||||
}
|
||||
|
||||
Tag::Tag(EnumValPtr val) : zeek::Tag(std::move(val)) { }
|
||||
|
||||
} // namespace zeek::analyzer
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#pragma once
|
||||
|
@ -7,109 +6,9 @@
|
|||
|
||||
#include "zeek/Tag.h"
|
||||
|
||||
namespace zeek
|
||||
namespace zeek::analyzer
|
||||
{
|
||||
|
||||
class EnumVal;
|
||||
using Tag [[deprecated("Remove in v5.1. Use zeek::Tag.")]] = zeek::Tag;
|
||||
|
||||
namespace plugin
|
||||
{
|
||||
|
||||
template <class T> class TaggedComponent;
|
||||
template <class T, class C> class ComponentManager;
|
||||
|
||||
} // namespace plugin
|
||||
|
||||
namespace analyzer
|
||||
{
|
||||
|
||||
class Manager;
|
||||
class Component;
|
||||
|
||||
/**
|
||||
* Class to identify a protocol analyzer type.
|
||||
*
|
||||
* The script-layer analogue is Analyzer::Tag.
|
||||
*/
|
||||
class Tag : public zeek::Tag
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Copy constructor.
|
||||
*/
|
||||
Tag(const Tag& other) : zeek::Tag(other) { }
|
||||
|
||||
/**
|
||||
* Default constructor. This initializes the tag with an error value
|
||||
* that will make \c operator \c bool return false.
|
||||
*/
|
||||
Tag() : zeek::Tag() { }
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Tag() { }
|
||||
|
||||
/**
|
||||
* Returns false if the tag represents an error value rather than a
|
||||
* legal analyzer type.
|
||||
*/
|
||||
explicit operator bool() const { return *this != Error; }
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
Tag& operator=(const Tag& other);
|
||||
|
||||
/**
|
||||
* Compares two tags for equality.
|
||||
*/
|
||||
bool operator==(const Tag& other) const { return zeek::Tag::operator==(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for inequality.
|
||||
*/
|
||||
bool operator!=(const Tag& other) const { return zeek::Tag::operator!=(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for less-than relationship.
|
||||
*/
|
||||
bool operator<(const Tag& other) const { return zeek::Tag::operator<(other); }
|
||||
|
||||
/**
|
||||
* Returns the \c Analyzer::Tag enum that corresponds to this tag.
|
||||
* The returned value does not have its ref-count increased.
|
||||
*
|
||||
* @param etype the script-layer enum type associated with the tag.
|
||||
*/
|
||||
const EnumValPtr& AsVal() const;
|
||||
|
||||
static const Tag Error;
|
||||
|
||||
protected:
|
||||
friend class analyzer::Manager;
|
||||
friend class plugin::ComponentManager<Tag, Component>;
|
||||
friend class plugin::TaggedComponent<Tag>;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param type The main type. Note that the \a analyzer::Manager
|
||||
* manages the value space internally, so noone else should assign
|
||||
* any main types.
|
||||
*
|
||||
* @param subtype The sub type, which is left to an analyzer for
|
||||
* interpretation. By default it's set to zero.
|
||||
*/
|
||||
explicit Tag(type_t type, subtype_t subtype = 0);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param val An enum value of script type \c Analyzer::Tag.
|
||||
*/
|
||||
explicit Tag(EnumValPtr val);
|
||||
};
|
||||
|
||||
} // namespace analyzer
|
||||
} // namespace zeek
|
||||
} // namespace zeek::analyzer
|
||||
|
|
|
@ -15,7 +15,6 @@ set(file_analysis_SRCS
|
|||
Analyzer.cc
|
||||
AnalyzerSet.cc
|
||||
Component.cc
|
||||
Tag.cc
|
||||
)
|
||||
|
||||
bif_target(file_analysis.bif)
|
||||
|
|
|
@ -11,8 +11,9 @@ namespace zeek::file_analysis
|
|||
|
||||
Component::Component(const std::string& name, factory_function arg_factory, Tag::subtype_t subtype,
|
||||
bool arg_enabled)
|
||||
: plugin::Component(plugin::component::FILE_ANALYZER, name),
|
||||
plugin::TaggedComponent<file_analysis::Tag>(subtype)
|
||||
: plugin::Component(plugin::component::FILE_ANALYZER, name), plugin::TaggedComponent(
|
||||
subtype,
|
||||
file_mgr->GetTagType())
|
||||
{
|
||||
factory_func = arg_factory;
|
||||
enabled = arg_enabled;
|
||||
|
|
|
@ -27,7 +27,7 @@ class Manager;
|
|||
* A plugin can provide a specific file analyzer by registering this
|
||||
* analyzer component, describing the analyzer.
|
||||
*/
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent<file_analysis::Tag>
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent
|
||||
{
|
||||
public:
|
||||
using factory_function = Analyzer* (*)(RecordValPtr args, File* file);
|
||||
|
|
|
@ -27,7 +27,6 @@ namespace file_analysis
|
|||
{
|
||||
|
||||
class FileReassembler;
|
||||
class Tag;
|
||||
|
||||
/**
|
||||
* Wrapper class around \c fa_file record values from script layer.
|
||||
|
|
|
@ -19,8 +19,8 @@ namespace zeek::file_analysis
|
|||
{
|
||||
|
||||
Manager::Manager()
|
||||
: plugin::ComponentManager<file_analysis::Tag, file_analysis::Component>("Files", "Tag"),
|
||||
current_file_id(), magic_state(), cumulative_files(0), max_files(0)
|
||||
: plugin::ComponentManager<file_analysis::Component>("Files", "Tag"), current_file_id(),
|
||||
magic_state(), cumulative_files(0), max_files(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace analyzer
|
|||
{
|
||||
|
||||
class Analyzer;
|
||||
class Tag;
|
||||
|
||||
} // namespace analyzer
|
||||
|
||||
|
@ -31,12 +30,11 @@ namespace file_analysis
|
|||
{
|
||||
|
||||
class File;
|
||||
class Tag;
|
||||
|
||||
/**
|
||||
* Main entry point for interacting with file analysis.
|
||||
*/
|
||||
class Manager : public plugin::ComponentManager<Tag, Component>
|
||||
class Manager : public plugin::ComponentManager<Component>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "zeek/file_analysis/Tag.h"
|
||||
|
||||
#include "zeek/file_analysis/Manager.h"
|
||||
|
||||
namespace zeek::file_analysis
|
||||
{
|
||||
|
||||
const Tag Tag::Error;
|
||||
|
||||
Tag::Tag(type_t type, subtype_t subtype) : zeek::Tag(file_mgr->GetTagType(), type, subtype) { }
|
||||
|
||||
Tag& Tag::operator=(const Tag& other)
|
||||
{
|
||||
zeek::Tag::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const EnumValPtr& Tag::AsVal() const
|
||||
{
|
||||
return zeek::Tag::AsVal(file_mgr->GetTagType());
|
||||
}
|
||||
|
||||
Tag::Tag(EnumValPtr val) : zeek::Tag(std::move(val)) { }
|
||||
|
||||
} // namespace zeek::file_analysis
|
|
@ -6,105 +6,9 @@
|
|||
|
||||
#include "zeek/Tag.h"
|
||||
|
||||
namespace zeek::plugin
|
||||
{
|
||||
template <class T> class TaggedComponent;
|
||||
template <class T, class C> class ComponentManager;
|
||||
}
|
||||
|
||||
namespace zeek
|
||||
namespace zeek::file_analysis
|
||||
{
|
||||
|
||||
class EnumVal;
|
||||
using Tag [[deprecated("Remove in v5.1. Use zeek::Tag.")]] = zeek::Tag;
|
||||
|
||||
namespace file_analysis
|
||||
{
|
||||
|
||||
class Component;
|
||||
|
||||
/**
|
||||
* Class to identify a file analyzer type.
|
||||
*
|
||||
* The script-layer analogue is Files::Tag.
|
||||
*/
|
||||
class Tag : public zeek::Tag
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Copy constructor.
|
||||
*/
|
||||
Tag(const Tag& other) : zeek::Tag(other) { }
|
||||
|
||||
/**
|
||||
* Default constructor. This initializes the tag with an error value
|
||||
* that will make \c operator \c bool return false.
|
||||
*/
|
||||
Tag() : zeek::Tag() { }
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Tag() { }
|
||||
|
||||
/**
|
||||
* Returns false if the tag represents an error value rather than a
|
||||
* legal analyzer type.
|
||||
*/
|
||||
explicit operator bool() const { return *this != Error; }
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
Tag& operator=(const Tag& other);
|
||||
|
||||
/**
|
||||
* Compares two tags for equality.
|
||||
*/
|
||||
bool operator==(const Tag& other) const { return zeek::Tag::operator==(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for inequality.
|
||||
*/
|
||||
bool operator!=(const Tag& other) const { return zeek::Tag::operator!=(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for less-than relationship.
|
||||
*/
|
||||
bool operator<(const Tag& other) const { return zeek::Tag::operator<(other); }
|
||||
|
||||
/**
|
||||
* Returns the \c Files::Tag enum that corresponds to this tag.
|
||||
* The returned value does not have its ref-count increased.
|
||||
*
|
||||
* @param etype the script-layer enum type associated with the tag.
|
||||
*/
|
||||
const EnumValPtr& AsVal() const;
|
||||
|
||||
static const Tag Error;
|
||||
|
||||
protected:
|
||||
friend class plugin::ComponentManager<Tag, Component>;
|
||||
friend class plugin::TaggedComponent<Tag>;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param type The main type. Note that the \a file_analysis::Manager
|
||||
* manages the value space internally, so noone else should assign
|
||||
* main types.
|
||||
*
|
||||
* @param subtype The sub type, which is left to an analyzer for
|
||||
* interpretation. By default it's set to zero.
|
||||
*/
|
||||
explicit Tag(type_t type, subtype_t subtype = 0);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param val An enum value of script type \c Files::Tag.
|
||||
*/
|
||||
explicit Tag(EnumValPtr val);
|
||||
};
|
||||
|
||||
} // namespace file_analysis
|
||||
} // namespace zeek
|
||||
} // namespace zeek::file_analysis
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace file_analysis
|
|||
{
|
||||
|
||||
class File;
|
||||
class Tag;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
|
|
@ -13,11 +13,9 @@ set(input_SRCS
|
|||
Manager.cc
|
||||
ReaderBackend.cc
|
||||
ReaderFrontend.cc
|
||||
Tag.cc
|
||||
)
|
||||
|
||||
bif_target(input.bif)
|
||||
|
||||
bro_add_subdir_library(input ${input_SRCS})
|
||||
add_dependencies(bro_input generate_outputs)
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ namespace zeek::input
|
|||
{
|
||||
|
||||
Component::Component(const std::string& name, factory_callback arg_factory)
|
||||
: plugin::Component(plugin::component::READER, name)
|
||||
: plugin::Component(plugin::component::READER, name), plugin::TaggedComponent(
|
||||
0, input_mgr->GetTagType())
|
||||
{
|
||||
factory = arg_factory;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class ReaderBackend;
|
|||
/**
|
||||
* Component description for plugins providing log readers.
|
||||
*/
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent<Tag>
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent
|
||||
{
|
||||
public:
|
||||
using factory_callback = ReaderBackend* (*)(ReaderFrontend* frontend);
|
||||
|
|
|
@ -179,7 +179,7 @@ Manager::AnalysisStream::AnalysisStream() : Manager::Stream::Stream(ANALYSIS_STR
|
|||
|
||||
Manager::AnalysisStream::~AnalysisStream() { }
|
||||
|
||||
Manager::Manager() : plugin::ComponentManager<input::Tag, input::Component>("Input", "Reader")
|
||||
Manager::Manager() : plugin::ComponentManager<input::Component>("Input", "Reader")
|
||||
{
|
||||
end_of_data = event_registry->Register("Input::end_of_data");
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class ReaderBackend;
|
|||
/**
|
||||
* Singleton class for managing input streams.
|
||||
*/
|
||||
class Manager : public plugin::ComponentManager<Tag, Component>
|
||||
class Manager : public plugin::ComponentManager<Component>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "zeek/input/Tag.h"
|
||||
|
||||
#include "zeek/input/Manager.h"
|
||||
|
||||
namespace zeek::input
|
||||
{
|
||||
|
||||
const Tag Tag::Error;
|
||||
|
||||
Tag::Tag(type_t type, subtype_t subtype) : zeek::Tag(input_mgr->GetTagType(), type, subtype) { }
|
||||
|
||||
Tag& Tag::operator=(const Tag& other)
|
||||
{
|
||||
zeek::Tag::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const EnumValPtr& Tag::AsVal() const
|
||||
{
|
||||
return zeek::Tag::AsVal(input_mgr->GetTagType());
|
||||
}
|
||||
|
||||
Tag::Tag(EnumValPtr val) : zeek::Tag(std::move(val)) { }
|
||||
|
||||
} // namespace zeek::input
|
105
src/input/Tag.h
105
src/input/Tag.h
|
@ -6,108 +6,9 @@
|
|||
|
||||
#include "zeek/Tag.h"
|
||||
|
||||
namespace zeek
|
||||
namespace zeek::input
|
||||
{
|
||||
|
||||
class EnumVal;
|
||||
using Tag [[deprecated("Remove in v5.1. Use zeek::Tag.")]] = zeek::Tag;
|
||||
|
||||
namespace plugin
|
||||
{
|
||||
|
||||
template <class T> class TaggedComponent;
|
||||
template <class T, class C> class ComponentManager;
|
||||
|
||||
} // namespace plugin
|
||||
|
||||
namespace input
|
||||
{
|
||||
|
||||
class Manager;
|
||||
class Component;
|
||||
|
||||
/**
|
||||
* Class to identify a reader type.
|
||||
*
|
||||
* The script-layer analogue is Input::Reader.
|
||||
*/
|
||||
class Tag : public zeek::Tag
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Copy constructor.
|
||||
*/
|
||||
Tag(const Tag& other) : zeek::Tag(other) { }
|
||||
|
||||
/**
|
||||
* Default constructor. This initializes the tag with an error value
|
||||
* that will make \c operator \c bool return false.
|
||||
*/
|
||||
Tag() : zeek::Tag() { }
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Tag() { }
|
||||
|
||||
/**
|
||||
* Returns false if the tag represents an error value rather than a
|
||||
* legal reader type.
|
||||
*/
|
||||
explicit operator bool() const { return *this != Error; }
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
Tag& operator=(const Tag& other);
|
||||
|
||||
/**
|
||||
* Compares two tags for equality.
|
||||
*/
|
||||
bool operator==(const Tag& other) const { return zeek::Tag::operator==(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for inequality.
|
||||
*/
|
||||
bool operator!=(const Tag& other) const { return zeek::Tag::operator!=(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for less-than relationship.
|
||||
*/
|
||||
bool operator<(const Tag& other) const { return zeek::Tag::operator<(other); }
|
||||
|
||||
/**
|
||||
* Returns the \c Input::Reader enum that corresponds to this tag.
|
||||
* The returned value does not have its ref-count increased.
|
||||
*
|
||||
* @param etype the script-layer enum type associated with the tag.
|
||||
*/
|
||||
const EnumValPtr& AsVal() const;
|
||||
|
||||
static const Tag Error;
|
||||
|
||||
protected:
|
||||
friend class plugin::ComponentManager<Tag, Component>;
|
||||
friend class plugin::TaggedComponent<Tag>;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param type The main type. Note that the \a input::Manager
|
||||
* manages the value space internally, so noone else should assign
|
||||
* any main types.
|
||||
*
|
||||
* @param subtype The sub type, which is left to an reader for
|
||||
* interpretation. By default it's set to zero.
|
||||
*/
|
||||
explicit Tag(type_t type, subtype_t subtype = 0);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param val An enum value of script type \c Input::Reader.
|
||||
*/
|
||||
explicit Tag(EnumValPtr val);
|
||||
};
|
||||
|
||||
} // namespace input
|
||||
} // namespace zeek
|
||||
} // namespace zeek::input
|
||||
|
|
|
@ -15,11 +15,9 @@ set(logging_SRCS
|
|||
Manager.cc
|
||||
WriterBackend.cc
|
||||
WriterFrontend.cc
|
||||
Tag.cc
|
||||
)
|
||||
|
||||
bif_target(logging.bif)
|
||||
|
||||
bro_add_subdir_library(logging ${logging_SRCS})
|
||||
add_dependencies(bro_logging generate_outputs)
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ namespace zeek::logging
|
|||
{
|
||||
|
||||
Component::Component(const std::string& name, factory_callback arg_factory)
|
||||
: plugin::Component(plugin::component::WRITER, name)
|
||||
: plugin::Component(plugin::component::WRITER, name), plugin::TaggedComponent(
|
||||
0, log_mgr->GetTagType())
|
||||
{
|
||||
factory = arg_factory;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class WriterBackend;
|
|||
/**
|
||||
* Component description for plugins providing log writers.
|
||||
*/
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent<logging::Tag>
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent
|
||||
{
|
||||
public:
|
||||
using factory_callback = WriterBackend* (*)(WriterFrontend* frontend);
|
||||
|
|
|
@ -132,7 +132,7 @@ Manager::Stream::~Stream()
|
|||
delete *f;
|
||||
}
|
||||
|
||||
Manager::Manager() : plugin::ComponentManager<logging::Tag, logging::Component>("Log", "Writer")
|
||||
Manager::Manager() : plugin::ComponentManager<logging::Component>("Log", "Writer")
|
||||
{
|
||||
rotations_pending = 0;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class RotationTimer;
|
|||
/**
|
||||
* Singleton class for managing log streams.
|
||||
*/
|
||||
class Manager : public plugin::ComponentManager<Tag, Component>
|
||||
class Manager : public plugin::ComponentManager<Component>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "zeek/logging/Tag.h"
|
||||
|
||||
#include "zeek/logging/Manager.h"
|
||||
|
||||
namespace zeek::logging
|
||||
{
|
||||
|
||||
const Tag Tag::Error;
|
||||
|
||||
Tag::Tag(type_t type, subtype_t subtype) : zeek::Tag(log_mgr->GetTagType(), type, subtype) { }
|
||||
|
||||
Tag& Tag::operator=(const Tag& other)
|
||||
{
|
||||
zeek::Tag::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Tag& Tag::operator=(const Tag&& other) noexcept
|
||||
{
|
||||
zeek::Tag::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const EnumValPtr& Tag::AsVal() const
|
||||
{
|
||||
return zeek::Tag::AsVal(log_mgr->GetTagType());
|
||||
}
|
||||
|
||||
Tag::Tag(EnumValPtr val) : zeek::Tag(std::move(val)) { }
|
||||
|
||||
} // namespace zeek::logging
|
|
@ -6,113 +6,9 @@
|
|||
|
||||
#include "zeek/Tag.h"
|
||||
|
||||
namespace zeek
|
||||
namespace zeek::logging
|
||||
{
|
||||
|
||||
class EnumVal;
|
||||
using Tag [[deprecated("Remove in v5.1. Use zeek::Tag.")]] = zeek::Tag;
|
||||
|
||||
namespace plugin
|
||||
{
|
||||
|
||||
template <class T> class TaggedComponent;
|
||||
template <class T, class C> class ComponentManager;
|
||||
|
||||
} // namespace plugin
|
||||
|
||||
namespace logging
|
||||
{
|
||||
|
||||
class Manager;
|
||||
class Component;
|
||||
|
||||
/**
|
||||
* Class to identify a writer type.
|
||||
*
|
||||
* The script-layer analogue is Log::Writer.
|
||||
*/
|
||||
class Tag : public zeek::Tag
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Copy constructor.
|
||||
*/
|
||||
Tag(const Tag& other) : zeek::Tag(other) { }
|
||||
|
||||
/**
|
||||
* Default constructor. This initializes the tag with an error value
|
||||
* that will make \c operator \c bool return false.
|
||||
*/
|
||||
Tag() : zeek::Tag() { }
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Tag() { }
|
||||
|
||||
/**
|
||||
* Returns false if the tag represents an error value rather than a
|
||||
* legal writer type.
|
||||
*/
|
||||
explicit operator bool() const { return *this != Error; }
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
Tag& operator=(const Tag& other);
|
||||
|
||||
/**
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Tag& operator=(const Tag&& other) noexcept;
|
||||
|
||||
/**
|
||||
* Compares two tags for equality.
|
||||
*/
|
||||
bool operator==(const Tag& other) const { return zeek::Tag::operator==(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for inequality.
|
||||
*/
|
||||
bool operator!=(const Tag& other) const { return zeek::Tag::operator!=(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for less-than relationship.
|
||||
*/
|
||||
bool operator<(const Tag& other) const { return zeek::Tag::operator<(other); }
|
||||
|
||||
/**
|
||||
* Returns the \c Log::Writer enum that corresponds to this tag.
|
||||
* The returned value does not have its ref-count increased.
|
||||
*
|
||||
* @param etype the script-layer enum type associated with the tag.
|
||||
*/
|
||||
const EnumValPtr& AsVal() const;
|
||||
|
||||
static const Tag Error;
|
||||
|
||||
protected:
|
||||
friend class plugin::ComponentManager<Tag, Component>;
|
||||
friend class plugin::TaggedComponent<Tag>;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param type The main type. Note that the \a logging::Manager
|
||||
* manages the value space internally, so noone else should assign
|
||||
* any main types.
|
||||
*
|
||||
* @param subtype The sub type, which is left to an writer for
|
||||
* interpretation. By default it's set to zero.
|
||||
*/
|
||||
explicit Tag(type_t type, subtype_t subtype = 0);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param val An enum value of script type \c Log::Writer.
|
||||
*/
|
||||
explicit Tag(EnumValPtr val);
|
||||
};
|
||||
|
||||
} // namespace logging
|
||||
} // namespace zeek
|
||||
} // namespace zeek::logging
|
||||
|
|
|
@ -13,7 +13,6 @@ set(packet_analysis_SRCS
|
|||
Dispatcher.cc
|
||||
Manager.cc
|
||||
Component.cc
|
||||
Tag.cc
|
||||
)
|
||||
|
||||
bro_add_subdir_library(packet_analysis ${packet_analysis_SRCS})
|
||||
|
|
|
@ -9,8 +9,9 @@ using namespace zeek::packet_analysis;
|
|||
|
||||
Component::Component(const std::string& name, factory_callback arg_factory,
|
||||
Tag::subtype_t arg_subtype)
|
||||
: plugin::Component(plugin::component::PACKET_ANALYZER, name),
|
||||
plugin::TaggedComponent<packet_analysis::Tag>(arg_subtype)
|
||||
: plugin::Component(plugin::component::PACKET_ANALYZER, name), plugin::TaggedComponent(
|
||||
arg_subtype,
|
||||
packet_mgr->GetTagType())
|
||||
{
|
||||
factory = arg_factory;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace zeek::packet_analysis
|
|||
class Analyzer;
|
||||
using AnalyzerPtr = std::shared_ptr<Analyzer>;
|
||||
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent<packet_analysis::Tag>
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent
|
||||
{
|
||||
public:
|
||||
using factory_callback = std::function<AnalyzerPtr()>;
|
||||
|
|
|
@ -13,9 +13,7 @@
|
|||
|
||||
using namespace zeek::packet_analysis;
|
||||
|
||||
Manager::Manager()
|
||||
: plugin::ComponentManager<packet_analysis::Tag, packet_analysis::Component>("PacketAnalyzer",
|
||||
"Tag")
|
||||
Manager::Manager() : plugin::ComponentManager<packet_analysis::Component>("PacketAnalyzer", "Tag")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace packet_analysis
|
|||
class Analyzer;
|
||||
using AnalyzerPtr = std::shared_ptr<Analyzer>;
|
||||
|
||||
class Manager : public plugin::ComponentManager<Tag, Component>
|
||||
class Manager : public plugin::ComponentManager<Component>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "zeek/packet_analysis/Tag.h"
|
||||
|
||||
#include "zeek/packet_analysis/Manager.h"
|
||||
|
||||
namespace zeek::packet_analysis
|
||||
{
|
||||
|
||||
Tag Tag::Error;
|
||||
|
||||
Tag::Tag(type_t type, subtype_t subtype) : zeek::Tag(packet_mgr->GetTagType(), type, subtype) { }
|
||||
|
||||
Tag& Tag::operator=(const Tag& other)
|
||||
{
|
||||
zeek::Tag::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const IntrusivePtr<EnumVal>& Tag::AsVal() const
|
||||
{
|
||||
return zeek::Tag::AsVal(packet_mgr->GetTagType());
|
||||
}
|
||||
|
||||
Tag::Tag(IntrusivePtr<EnumVal> val) : zeek::Tag(std::move(val)) { }
|
||||
|
||||
}
|
|
@ -6,99 +6,9 @@
|
|||
|
||||
#include "zeek/Tag.h"
|
||||
|
||||
namespace zeek::plugin
|
||||
{
|
||||
template <class T> class TaggedComponent;
|
||||
template <class T, class C> class ComponentManager;
|
||||
}
|
||||
|
||||
namespace zeek::packet_analysis
|
||||
{
|
||||
|
||||
class Manager;
|
||||
class Component;
|
||||
using Tag [[deprecated("Remove in v5.1. Use zeek::Tag.")]] = zeek::Tag;
|
||||
|
||||
/**
|
||||
* Class to identify a protocol analyzer type.
|
||||
*/
|
||||
class Tag : public zeek::Tag
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Copy constructor.
|
||||
*/
|
||||
Tag(const Tag& other) : zeek::Tag(other) { }
|
||||
|
||||
/**
|
||||
* Default constructor. This initializes the tag with an error value
|
||||
* that will make \c operator \c bool return false.
|
||||
*/
|
||||
Tag() : zeek::Tag() { }
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Tag() = default;
|
||||
|
||||
/**
|
||||
* Returns false if the tag represents an error value rather than a
|
||||
* legal analyzer type.
|
||||
*/
|
||||
explicit operator bool() const { return *this != Tag(); }
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
Tag& operator=(const Tag& other);
|
||||
|
||||
/**
|
||||
* Compares two tags for equality.
|
||||
*/
|
||||
bool operator==(const Tag& other) const { return zeek::Tag::operator==(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for inequality.
|
||||
*/
|
||||
bool operator!=(const Tag& other) const { return zeek::Tag::operator!=(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for less-than relationship.
|
||||
*/
|
||||
bool operator<(const Tag& other) const { return zeek::Tag::operator<(other); }
|
||||
|
||||
/**
|
||||
* Returns the \c Analyzer::Tag enum that corresponds to this tag.
|
||||
* The returned value does not have its ref-count increased.
|
||||
*
|
||||
* @param etype the script-layer enum type associated with the tag.
|
||||
*/
|
||||
const IntrusivePtr<EnumVal>& AsVal() const;
|
||||
|
||||
static Tag Error;
|
||||
|
||||
protected:
|
||||
friend class packet_analysis::Manager;
|
||||
friend class plugin::ComponentManager<Tag, Component>;
|
||||
friend class plugin::TaggedComponent<Tag>;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param type The main type. Note that the \a zeek::packet_analysis::Manager
|
||||
* manages the value space internally, so noone else should assign any main
|
||||
* types.
|
||||
*
|
||||
* @param subtype The sub type, which is left to an analyzer for
|
||||
* interpretation. By default it's set to zero.
|
||||
*/
|
||||
explicit Tag(type_t type, subtype_t subtype = 0);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param val An enum value of script type \c Analyzer::Tag.
|
||||
*/
|
||||
explicit Tag(IntrusivePtr<EnumVal> val);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace zeek::packet_analysis
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "zeek/DebugLogger.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/Scope.h"
|
||||
#include "zeek/Tag.h"
|
||||
#include "zeek/Type.h"
|
||||
#include "zeek/Val.h"
|
||||
#include "zeek/Var.h" // for add_type()
|
||||
|
@ -20,10 +21,9 @@ namespace zeek::plugin
|
|||
* installs identifiers in the script-layer to identify them by a unique tag,
|
||||
* (a script-layer enum value).
|
||||
*
|
||||
* @tparam T A ::Tag type or derivative.
|
||||
* @tparam C A plugin::TaggedComponent type derivative.
|
||||
*/
|
||||
template <class T, class C> class ComponentManager
|
||||
template <class C> class ComponentManager
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
* @param tag A component's tag.
|
||||
* @return The canonical component name.
|
||||
*/
|
||||
const std::string& GetComponentName(T tag) const;
|
||||
const std::string& GetComponentName(zeek::Tag tag) const;
|
||||
|
||||
/**
|
||||
* Get a component name from it's enum value.
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
* @return The component's tag, or a tag representing an error if
|
||||
* no such component assoicated with the name exists.
|
||||
*/
|
||||
T GetComponentTag(const std::string& name) const;
|
||||
zeek::Tag GetComponentTag(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* Get a component tag from its enum value.
|
||||
|
@ -85,7 +85,7 @@ public:
|
|||
* @return The component's tag, or a tag representing an error if
|
||||
* no such component assoicated with the value exists.
|
||||
*/
|
||||
T GetComponentTag(Val* v) const;
|
||||
zeek::Tag GetComponentTag(Val* v) const;
|
||||
|
||||
/**
|
||||
* Add a component the internal maps used to keep track of it and create
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
* @return The component associated with the tag or a null pointer if no
|
||||
* such component exists.
|
||||
*/
|
||||
C* Lookup(const T& tag) const;
|
||||
C* Lookup(const zeek::Tag& tag) const;
|
||||
|
||||
/**
|
||||
* @param name A component's enum value.
|
||||
|
@ -123,12 +123,12 @@ private:
|
|||
std::string module; /**< Script layer module in which component tags live. */
|
||||
EnumTypePtr tag_enum_type; /**< Enum type of component tags. */
|
||||
std::map<std::string, C*> components_by_name;
|
||||
std::map<T, C*> components_by_tag;
|
||||
std::map<zeek::Tag, C*> components_by_tag;
|
||||
std::map<int, C*> components_by_val;
|
||||
};
|
||||
|
||||
template <class T, class C>
|
||||
ComponentManager<T, C>::ComponentManager(const std::string& arg_module, const std::string& local_id)
|
||||
template <class C>
|
||||
ComponentManager<C>::ComponentManager(const std::string& arg_module, const std::string& local_id)
|
||||
: module(arg_module), tag_enum_type(make_intrusive<EnumType>(module + "::" + local_id))
|
||||
{
|
||||
auto id = zeek::detail::install_ID(local_id.c_str(), module.c_str(), true, true);
|
||||
|
@ -136,15 +136,15 @@ ComponentManager<T, C>::ComponentManager(const std::string& arg_module, const st
|
|||
zeek::detail::zeekygen_mgr->Identifier(std::move(id));
|
||||
}
|
||||
|
||||
template <class T, class C> const std::string& ComponentManager<T, C>::GetModule() const
|
||||
template <class C> const std::string& ComponentManager<C>::GetModule() const
|
||||
{
|
||||
return module;
|
||||
}
|
||||
|
||||
template <class T, class C> std::list<C*> ComponentManager<T, C>::GetComponents() const
|
||||
template <class C> std::list<C*> ComponentManager<C>::GetComponents() const
|
||||
{
|
||||
std::list<C*> rval;
|
||||
typename std::map<T, C*>::const_iterator i;
|
||||
typename std::map<zeek::Tag, C*>::const_iterator i;
|
||||
|
||||
for ( i = components_by_tag.begin(); i != components_by_tag.end(); ++i )
|
||||
rval.push_back(i->second);
|
||||
|
@ -152,12 +152,12 @@ template <class T, class C> std::list<C*> ComponentManager<T, C>::GetComponents(
|
|||
return rval;
|
||||
}
|
||||
|
||||
template <class T, class C> const EnumTypePtr& ComponentManager<T, C>::GetTagType() const
|
||||
template <class C> const EnumTypePtr& ComponentManager<C>::GetTagType() const
|
||||
{
|
||||
return tag_enum_type;
|
||||
}
|
||||
|
||||
template <class T, class C> const std::string& ComponentManager<T, C>::GetComponentName(T tag) const
|
||||
template <class C> const std::string& ComponentManager<C>::GetComponentName(zeek::Tag tag) const
|
||||
{
|
||||
static const std::string error = "<error>";
|
||||
|
||||
|
@ -173,45 +173,44 @@ template <class T, class C> const std::string& ComponentManager<T, C>::GetCompon
|
|||
return error;
|
||||
}
|
||||
|
||||
template <class T, class C>
|
||||
const std::string& ComponentManager<T, C>::GetComponentName(EnumValPtr val) const
|
||||
template <class C> const std::string& ComponentManager<C>::GetComponentName(EnumValPtr val) const
|
||||
{
|
||||
return GetComponentName(T(std::move(val)));
|
||||
return GetComponentName(zeek::Tag(std::move(val)));
|
||||
}
|
||||
|
||||
template <class T, class C> T ComponentManager<T, C>::GetComponentTag(const std::string& name) const
|
||||
template <class C> zeek::Tag ComponentManager<C>::GetComponentTag(const std::string& name) const
|
||||
{
|
||||
C* c = Lookup(name);
|
||||
return c ? c->Tag() : T();
|
||||
return c ? c->Tag() : zeek::Tag();
|
||||
}
|
||||
|
||||
template <class T, class C> T ComponentManager<T, C>::GetComponentTag(Val* v) const
|
||||
template <class C> zeek::Tag ComponentManager<C>::GetComponentTag(Val* v) const
|
||||
{
|
||||
C* c = Lookup(v->AsEnumVal());
|
||||
return c ? c->Tag() : T();
|
||||
return c ? c->Tag() : zeek::Tag();
|
||||
}
|
||||
|
||||
template <class T, class C> C* ComponentManager<T, C>::Lookup(const std::string& name) const
|
||||
template <class C> C* ComponentManager<C>::Lookup(const std::string& name) const
|
||||
{
|
||||
typename std::map<std::string, C*>::const_iterator i = components_by_name.find(
|
||||
util::to_upper(name));
|
||||
return i != components_by_name.end() ? i->second : 0;
|
||||
}
|
||||
|
||||
template <class T, class C> C* ComponentManager<T, C>::Lookup(const T& tag) const
|
||||
template <class C> C* ComponentManager<C>::Lookup(const zeek::Tag& tag) const
|
||||
{
|
||||
typename std::map<T, C*>::const_iterator i = components_by_tag.find(tag);
|
||||
typename std::map<zeek::Tag, C*>::const_iterator i = components_by_tag.find(tag);
|
||||
return i != components_by_tag.end() ? i->second : 0;
|
||||
}
|
||||
|
||||
template <class T, class C> C* ComponentManager<T, C>::Lookup(EnumVal* val) const
|
||||
template <class C> C* ComponentManager<C>::Lookup(EnumVal* val) const
|
||||
{
|
||||
typename std::map<int, C*>::const_iterator i = components_by_val.find(val->InternalInt());
|
||||
return i != components_by_val.end() ? i->second : 0;
|
||||
}
|
||||
|
||||
template <class T, class C>
|
||||
void ComponentManager<T, C>::RegisterComponent(C* component, const std::string& prefix)
|
||||
template <class C>
|
||||
void ComponentManager<C>::RegisterComponent(C* component, const std::string& prefix)
|
||||
{
|
||||
std::string cname = component->CanonicalName();
|
||||
|
||||
|
|
36
src/plugin/TaggedComponent.cc
Normal file
36
src/plugin/TaggedComponent.cc
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "zeek/plugin/TaggedComponent.h"
|
||||
|
||||
#include "zeek/IntrusivePtr.h"
|
||||
#include "zeek/Type.h"
|
||||
|
||||
namespace zeek::plugin
|
||||
{
|
||||
|
||||
Tag::type_t TaggedComponent::type_counter(0);
|
||||
|
||||
TaggedComponent::TaggedComponent(Tag::subtype_t subtype, EnumTypePtr etype)
|
||||
: tag(etype, 1, 0), subtype(subtype), initialized(false), etype(std::move(etype))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes tag by creating the unique tag value for thos componend.
|
||||
* Has to be called exactly once.
|
||||
*/
|
||||
void TaggedComponent::InitializeTag()
|
||||
{
|
||||
assert(initialized == false);
|
||||
initialized = true;
|
||||
tag = zeek::Tag(etype, ++type_counter, subtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The component's tag.
|
||||
*/
|
||||
zeek::Tag TaggedComponent::Tag() const
|
||||
{
|
||||
assert(initialized);
|
||||
return tag;
|
||||
}
|
||||
|
||||
} // namespace zeek::plugin
|
|
@ -2,15 +2,16 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
#include "zeek/Tag.h"
|
||||
#include "zeek/Type.h"
|
||||
|
||||
namespace zeek::plugin
|
||||
{
|
||||
|
||||
/**
|
||||
* A class which has a tag of a given type associated with it.
|
||||
*
|
||||
* @tparam T A ::Tag type or derivative.
|
||||
*/
|
||||
template <class T> class TaggedComponent
|
||||
class TaggedComponent
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -24,7 +25,7 @@ public:
|
|||
* and component instances can accordingly access it via Tag().
|
||||
* If not used, leave at zero.
|
||||
*/
|
||||
explicit TaggedComponent(typename T::subtype_t subtype = 0);
|
||||
explicit TaggedComponent(Tag::subtype_t subtype = 0, zeek::EnumTypePtr etype = nullptr);
|
||||
|
||||
/**
|
||||
* Initializes tag by creating the unique tag value for thos componend.
|
||||
|
@ -35,36 +36,15 @@ public:
|
|||
/**
|
||||
* @return The component's tag.
|
||||
*/
|
||||
T Tag() const;
|
||||
zeek::Tag Tag() const;
|
||||
|
||||
private:
|
||||
T tag; /**< The automatically assigned analyzer tag. */
|
||||
typename T::subtype_t subtype;
|
||||
zeek::Tag tag; /**< The automatically assigned analyzer tag. */
|
||||
Tag::subtype_t subtype;
|
||||
bool initialized;
|
||||
static typename T::type_t type_counter; /**< Used to generate globally
|
||||
EnumTypePtr etype;
|
||||
static Tag::type_t type_counter; /**< Used to generate globally
|
||||
unique tags. */
|
||||
};
|
||||
|
||||
template <class T> TaggedComponent<T>::TaggedComponent(typename T::subtype_t subtype)
|
||||
{
|
||||
tag = T(1, 0);
|
||||
this->subtype = subtype;
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
template <class T> void TaggedComponent<T>::InitializeTag()
|
||||
{
|
||||
assert(initialized == false);
|
||||
initialized = true;
|
||||
tag = T(++type_counter, subtype);
|
||||
}
|
||||
|
||||
template <class T> T TaggedComponent<T>::Tag() const
|
||||
{
|
||||
assert(initialized);
|
||||
return tag;
|
||||
}
|
||||
|
||||
template <class T> typename T::type_t TaggedComponent<T>::type_counter(0);
|
||||
|
||||
} // namespace zeek::plugin
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
#open XXXX-XX-XX-XX-XX-XX
|
||||
#fields ts fuid tx_hosts rx_hosts conn_uids source depth analyzers mime_type filename duration local_orig is_orig seen_bytes total_bytes missing_bytes overflow_bytes timedout parent_fuid md5 sha1 sha256
|
||||
#types time string set[addr] set[addr] set[string] string count set[string] string string interval bool bool count count count count bool string string string string
|
||||
XXXXXXXXXX.XXXXXX FgN3AE3of2TRIqaeQe 74.125.239.129 192.168.4.149 CHhAvVGS1DHFjwGM9 SSL 0 SHA256,X509,SHA1,MD5 application/x-x509-user-cert - 0.000000 - F 1859 - 0 0 F - 7af07aca6d5c6e8e87fe4bb34786edc0 548b9e03bc183d1cd39f93a37985cb3950f8f06f 6bacfa4536150ed996f2b0c05ab6e345a257225f449aeb9d2018ccd88f4ede43
|
||||
XXXXXXXXXX.XXXXXX Fv2Agc4z5boBOacQi6 74.125.239.129 192.168.4.149 CHhAvVGS1DHFjwGM9 SSL 0 SHA256,X509,SHA1,MD5 application/x-x509-ca-cert - 0.000000 - F 1032 - 0 0 F - 9e4ac96474245129d9766700412a1f89 d83c1a7f4d0446bb2081b81a1670f8183451ca24 a047a37fa2d2e118a4f5095fe074d6cfe0e352425a7632bf8659c03919a6c81d
|
||||
XXXXXXXXXX.XXXXXX Ftmyeg2qgI2V38Dt3g 74.125.239.129 192.168.4.149 CHhAvVGS1DHFjwGM9 SSL 0 SHA256,X509,SHA1,MD5 application/x-x509-ca-cert - 0.000000 - F 897 - 0 0 F - 2e7db2a31d0e3da4b25f49b9542a2e1a 7359755c6df9a0abc3060bce369564c8ec4542a3 3c35cc963eb004451323d3275d05b353235053490d9cd83729a2faf5e7ca1cc0
|
||||
XXXXXXXXXX.XXXXXX FUFNf84cduA0IJCp07 74.125.239.129 192.168.4.149 ClEkJM2Vm5giqnMf4h SSL 0 SHA256,X509,SHA1,MD5 application/x-x509-user-cert - 0.000000 - F 1859 - 0 0 F - 7af07aca6d5c6e8e87fe4bb34786edc0 548b9e03bc183d1cd39f93a37985cb3950f8f06f 6bacfa4536150ed996f2b0c05ab6e345a257225f449aeb9d2018ccd88f4ede43
|
||||
XXXXXXXXXX.XXXXXX F1H4bd2OKGbLPEdHm4 74.125.239.129 192.168.4.149 ClEkJM2Vm5giqnMf4h SSL 0 SHA256,X509,SHA1,MD5 application/x-x509-ca-cert - 0.000000 - F 1032 - 0 0 F - 9e4ac96474245129d9766700412a1f89 d83c1a7f4d0446bb2081b81a1670f8183451ca24 a047a37fa2d2e118a4f5095fe074d6cfe0e352425a7632bf8659c03919a6c81d
|
||||
XXXXXXXXXX.XXXXXX Fgsbci2jxFXYMOHOhi 74.125.239.129 192.168.4.149 ClEkJM2Vm5giqnMf4h SSL 0 SHA256,X509,SHA1,MD5 application/x-x509-ca-cert - 0.000000 - F 897 - 0 0 F - 2e7db2a31d0e3da4b25f49b9542a2e1a 7359755c6df9a0abc3060bce369564c8ec4542a3 3c35cc963eb004451323d3275d05b353235053490d9cd83729a2faf5e7ca1cc0
|
||||
XXXXXXXXXX.XXXXXX FgN3AE3of2TRIqaeQe 74.125.239.129 192.168.4.149 CHhAvVGS1DHFjwGM9 SSL 0 X509,SHA256,SHA1,MD5 application/x-x509-user-cert - 0.000000 - F 1859 - 0 0 F - 7af07aca6d5c6e8e87fe4bb34786edc0 548b9e03bc183d1cd39f93a37985cb3950f8f06f 6bacfa4536150ed996f2b0c05ab6e345a257225f449aeb9d2018ccd88f4ede43
|
||||
XXXXXXXXXX.XXXXXX Fv2Agc4z5boBOacQi6 74.125.239.129 192.168.4.149 CHhAvVGS1DHFjwGM9 SSL 0 X509,SHA256,SHA1,MD5 application/x-x509-ca-cert - 0.000000 - F 1032 - 0 0 F - 9e4ac96474245129d9766700412a1f89 d83c1a7f4d0446bb2081b81a1670f8183451ca24 a047a37fa2d2e118a4f5095fe074d6cfe0e352425a7632bf8659c03919a6c81d
|
||||
XXXXXXXXXX.XXXXXX Ftmyeg2qgI2V38Dt3g 74.125.239.129 192.168.4.149 CHhAvVGS1DHFjwGM9 SSL 0 X509,SHA256,SHA1,MD5 application/x-x509-ca-cert - 0.000000 - F 897 - 0 0 F - 2e7db2a31d0e3da4b25f49b9542a2e1a 7359755c6df9a0abc3060bce369564c8ec4542a3 3c35cc963eb004451323d3275d05b353235053490d9cd83729a2faf5e7ca1cc0
|
||||
XXXXXXXXXX.XXXXXX FUFNf84cduA0IJCp07 74.125.239.129 192.168.4.149 ClEkJM2Vm5giqnMf4h SSL 0 X509,SHA256,SHA1,MD5 application/x-x509-user-cert - 0.000000 - F 1859 - 0 0 F - 7af07aca6d5c6e8e87fe4bb34786edc0 548b9e03bc183d1cd39f93a37985cb3950f8f06f 6bacfa4536150ed996f2b0c05ab6e345a257225f449aeb9d2018ccd88f4ede43
|
||||
XXXXXXXXXX.XXXXXX F1H4bd2OKGbLPEdHm4 74.125.239.129 192.168.4.149 ClEkJM2Vm5giqnMf4h SSL 0 X509,SHA256,SHA1,MD5 application/x-x509-ca-cert - 0.000000 - F 1032 - 0 0 F - 9e4ac96474245129d9766700412a1f89 d83c1a7f4d0446bb2081b81a1670f8183451ca24 a047a37fa2d2e118a4f5095fe074d6cfe0e352425a7632bf8659c03919a6c81d
|
||||
XXXXXXXXXX.XXXXXX Fgsbci2jxFXYMOHOhi 74.125.239.129 192.168.4.149 ClEkJM2Vm5giqnMf4h SSL 0 X509,SHA256,SHA1,MD5 application/x-x509-ca-cert - 0.000000 - F 897 - 0 0 F - 2e7db2a31d0e3da4b25f49b9542a2e1a 7359755c6df9a0abc3060bce369564c8ec4542a3 3c35cc963eb004451323d3275d05b353235053490d9cd83729a2faf5e7ca1cc0
|
||||
#close XXXX-XX-XX-XX-XX-XX
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue