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:
Tim Wojtulewicz 2021-09-16 12:39:46 -07:00
parent 4f9f46a0c4
commit 331161138a
46 changed files with 352 additions and 955 deletions

View file

@ -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})

View file

@ -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;
}

View file

@ -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()>;

View file

@ -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")
{
}

View file

@ -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:
/**

View file

@ -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)) { }
}

View file

@ -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