From a2bc42dd93ab94e97a74156399e0a6dffeb13809 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 2 Jul 2020 14:10:04 -0700 Subject: [PATCH] Move Func up to zeek namespace, rename BroFunc to ScriptFunc --- src/CompHash.cc | 2 +- src/DNS_Mgr.h | 1 - src/DbgBreakpoint.cc | 2 +- src/Debug.cc | 12 ++-- src/Discard.h | 12 ++-- src/EventHandler.cc | 4 +- src/EventHandler.h | 16 +++--- src/Expr.cc | 14 ++--- src/Frame.cc | 12 ++-- src/Frame.h | 20 ++++--- src/Func.cc | 76 +++++++++++++------------- src/Func.h | 46 +++++++++------- src/ID.cc | 4 +- src/ID.h | 10 ++-- src/NFA.h | 2 +- src/Obj.cc | 2 +- src/Stats.cc | 2 +- src/Stats.h | 4 +- src/Traverse.h | 6 +- src/Val.cc | 12 ++-- src/Val.h | 23 ++++---- src/Var.cc | 6 +- src/Var.h | 2 +- src/broker/Data.cc | 10 ++-- src/broker/Manager.cc | 2 +- src/broker/Manager.h | 4 +- src/broker/messaging.bif | 4 +- src/file_analysis/analyzer/x509/X509.h | 4 +- src/input/Manager.cc | 14 ++--- src/input/Manager.h | 4 +- src/logging/Manager.cc | 16 +++--- src/plugin/Manager.cc | 2 +- src/plugin/Manager.h | 2 +- src/plugin/Plugin.cc | 4 +- src/plugin/Plugin.h | 12 ++-- src/zeek.bif | 6 +- 36 files changed, 190 insertions(+), 184 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index e9fb8687fe..47fd0a11d1 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -849,7 +849,7 @@ const char* CompositeHash::RecoverOneVal( const uint32_t* const kp = AlignType(kp0); kp1 = reinterpret_cast(kp+1); - const auto& f = zeek::detail::Func::GetFuncPtrByID(*kp); + const auto& f = zeek::Func::GetFuncPtrByID(*kp); if ( ! f ) reporter->InternalError("failed to look up unique function id %" PRIu32 " in CompositeHash::RecoverOneVal()", *kp); diff --git a/src/DNS_Mgr.h b/src/DNS_Mgr.h index a8f353562e..e4f7d8dc01 100644 --- a/src/DNS_Mgr.h +++ b/src/DNS_Mgr.h @@ -16,7 +16,6 @@ class EventHandler; class DNS_Mgr_Request; -ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(RecordType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(ListVal, zeek); diff --git a/src/DbgBreakpoint.cc b/src/DbgBreakpoint.cc index 2e74961629..eda86b483b 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -351,7 +351,7 @@ void DbgBreakpoint::PrintHitMsg() { ODesc d; zeek::detail::Frame* f = g_frame_stack.back(); - const zeek::detail::BroFunc* func = f->GetFunction(); + const zeek::detail::ScriptFunc* func = f->GetFunction(); if ( func ) func->DescribeDebug (&d, f->GetFuncArgs()); diff --git a/src/Debug.cc b/src/Debug.cc index 4818058648..3322251d83 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -146,7 +146,7 @@ int TraceState::LogTrace(const char* fmt, ...) loc = *stmt->GetLocationInfo(); else { - const zeek::detail::BroFunc* f = g_frame_stack.back()->GetFunction(); + const zeek::detail::ScriptFunc* f = g_frame_stack.back()->GetFunction(); if ( f ) loc = *f->GetLocationInfo(); } @@ -221,8 +221,8 @@ static void parse_function_name(vector& result, return; } - const zeek::detail::Func* func = id->GetVal()->AsFunc(); - const vector& bodies = func->GetBodies(); + const zeek::Func* func = id->GetVal()->AsFunc(); + const vector& bodies = func->GetBodies(); if ( bodies.size() == 0 ) { @@ -731,7 +731,7 @@ static char* get_prompt(bool reset_counter = false) string get_context_description(const zeek::detail::Stmt* stmt, const zeek::detail::Frame* frame) { ODesc d; - const zeek::detail::BroFunc* func = frame ? frame->GetFunction() : nullptr; + const zeek::detail::ScriptFunc* func = frame ? frame->GetFunction() : nullptr; if ( func ) func->DescribeDebug(&d, frame->GetFuncArgs()); @@ -770,7 +770,7 @@ int dbg_handle_debug_input() } zeek::detail::Frame* curr_frame = g_frame_stack.back(); - const zeek::detail::BroFunc* func = curr_frame->GetFunction(); + const zeek::detail::ScriptFunc* func = curr_frame->GetFunction(); if ( func ) zeek::detail::current_module = extract_module_name(func->Name()); else @@ -963,7 +963,7 @@ zeek::ValPtr dbg_eval_expr(const char* expr) if ( ! (frame) ) reporter->InternalError("Assertion failed: frame"); - const zeek::detail::BroFunc* func = frame->GetFunction(); + const zeek::detail::ScriptFunc* func = frame->GetFunction(); if ( func ) { Ref(func->GetScope()); diff --git a/src/Discard.h b/src/Discard.h index 372dd4e317..97b469cbd8 100644 --- a/src/Discard.h +++ b/src/Discard.h @@ -8,10 +8,10 @@ class IP_Hdr; -ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek); -namespace zeek::detail { +namespace zeek { using FuncPtr = zeek::IntrusivePtr; } @@ -27,10 +27,10 @@ public: protected: zeek::Val* BuildData(const u_char* data, int hdrlen, int len, int caplen); - zeek::detail::FuncPtr check_ip; - zeek::detail::FuncPtr check_tcp; - zeek::detail::FuncPtr check_udp; - zeek::detail::FuncPtr check_icmp; + zeek::FuncPtr check_ip; + zeek::FuncPtr check_tcp; + zeek::FuncPtr check_udp; + zeek::FuncPtr check_icmp; // Maximum amount of application data passed to filtering functions. int discarder_maxlen; diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 58b200b256..830a031f0e 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -44,10 +44,10 @@ const zeek::FuncTypePtr& EventHandler::GetType(bool check_export) return type; } -void EventHandler::SetFunc(zeek::detail::FuncPtr f) +void EventHandler::SetFunc(zeek::FuncPtr f) { local = std::move(f); } -void EventHandler::SetLocalHandler(zeek::detail::Func* f) +void EventHandler::SetLocalHandler(zeek::Func* f) { SetFunc({zeek::NewRef{}, f}); } void EventHandler::Call(zeek::Args* vl, bool no_remote) diff --git a/src/EventHandler.h b/src/EventHandler.h index 81918c5679..7e1e96fc6d 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -9,9 +9,9 @@ #include #include -ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); -namespace zeek::detail { -using FuncPtr = zeek::IntrusivePtr; +ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek); +namespace zeek { +using FuncPtr = zeek::IntrusivePtr; } class EventHandler { @@ -20,11 +20,11 @@ public: const char* Name() { return name.data(); } - const zeek::detail::FuncPtr& GetFunc() + const zeek::FuncPtr& GetFunc() { return local; } [[deprecated("Remove in v4.1. Use GetFunc().")]] - zeek::detail::Func* LocalHandler() { return local.get(); } + zeek::Func* LocalHandler() { return local.get(); } const zeek::FuncTypePtr& GetType(bool check_export = true); @@ -32,10 +32,10 @@ public: zeek::FuncType* FType(bool check_export = true) { return GetType().get(); } - void SetFunc(zeek::detail::FuncPtr f); + void SetFunc(zeek::FuncPtr f); [[deprecated("Remove in v4.1. Use SetFunc().")]] - void SetLocalHandler(zeek::detail::Func* f); + void SetLocalHandler(zeek::Func* f); void AutoPublish(std::string topic) { @@ -71,7 +71,7 @@ private: void NewEvent(zeek::Args* vl); // Raise new_event() meta event. std::string name; - zeek::detail::FuncPtr local; + zeek::FuncPtr local; zeek::FuncTypePtr type; bool used; // this handler is indeed used somewhere bool enabled; diff --git a/src/Expr.cc b/src/Expr.cc index ea65a0a03f..09c49c4e52 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4051,8 +4051,8 @@ CallExpr::CallExpr(ExprPtr arg_func, ListExprPtr arg_args, bool in_hook) did_builtin_init && (func_val = func->Eval(nullptr)) ) { - zeek::detail::Func* f = func_val->AsFunc(); - if ( f->GetKind() == zeek::detail::Func::BUILTIN_FUNC && + zeek::Func* f = func_val->AsFunc(); + if ( f->GetKind() == zeek::Func::BUILTIN_FUNC && ! check_built_in_call((BuiltinFunc*) f, this) ) SetError(); } @@ -4072,7 +4072,7 @@ bool CallExpr::IsPure() const if ( ! func_val ) return false; - zeek::detail::Func* f = func_val->AsFunc(); + zeek::Func* f = func_val->AsFunc(); // Only recurse for built-in functions, as recursing on script // functions can lead to infinite recursion if the function being @@ -4080,7 +4080,7 @@ bool CallExpr::IsPure() const // or indirectly). bool pure = false; - if ( f->GetKind() == zeek::detail::Func::BUILTIN_FUNC ) + if ( f->GetKind() == zeek::Func::BUILTIN_FUNC ) pure = f->IsPure() && args->IsPure(); return pure; @@ -4114,7 +4114,7 @@ ValPtr CallExpr::Eval(Frame* f) const if ( func_val && v ) { - const zeek::detail::Func* funcv = func_val->AsFunc(); + const zeek::Func* funcv = func_val->AsFunc(); const CallExpr* current_call = f ? f->GetCall() : nullptr; if ( f ) @@ -4168,7 +4168,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, // Install a dummy version of the function globally for use only // when broker provides a closure. - auto dummy_func = zeek::make_intrusive( + auto dummy_func = zeek::make_intrusive( ingredients->id, ingredients->body, ingredients->inits, @@ -4219,7 +4219,7 @@ Scope* LambdaExpr::GetScope() const ValPtr LambdaExpr::Eval(Frame* f) const { - auto lamb = zeek::make_intrusive( + auto lamb = zeek::make_intrusive( ingredients->id, ingredients->body, ingredients->inits, diff --git a/src/Frame.cc b/src/Frame.cc index 3f5c995477..4328cf49a3 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -15,7 +15,7 @@ std::vector g_frame_stack; namespace zeek::detail { -Frame::Frame(int arg_size, const BroFunc* func, const zeek::Args* fn_args) +Frame::Frame(int arg_size, const ScriptFunc* func, const zeek::Args* fn_args) { size = arg_size; frame = std::make_unique(size); @@ -53,12 +53,12 @@ Frame::~Frame() ClearElement(i); } -void Frame::AddFunctionWithClosureRef(BroFunc* func) +void Frame::AddFunctionWithClosureRef(ScriptFunc* func) { zeek::Ref(func); if ( ! functions_with_closure_frame_reference ) - functions_with_closure_frame_reference = std::make_unique>(); + functions_with_closure_frame_reference = std::make_unique>(); functions_with_closure_frame_reference->emplace_back(func); } @@ -174,7 +174,7 @@ Frame* Frame::Clone() const return other; } -static bool val_is_func(const zeek::ValPtr& v, BroFunc* func) +static bool val_is_func(const zeek::ValPtr& v, ScriptFunc* func) { if ( v->GetType()->Tag() != zeek::TYPE_FUNC ) return false; @@ -182,7 +182,7 @@ static bool val_is_func(const zeek::ValPtr& v, BroFunc* func) return v->AsFunc() == func; } -void Frame::CloneNonFuncElement(int offset, BroFunc* func, Frame* other) const +void Frame::CloneNonFuncElement(int offset, ScriptFunc* func, Frame* other) const { const auto& v = frame[offset].val; @@ -199,7 +199,7 @@ void Frame::CloneNonFuncElement(int offset, BroFunc* func, Frame* other) const other->SetElement(offset, std::move(rval)); } -Frame* Frame::SelectiveClone(const id_list& selection, BroFunc* func) const +Frame* Frame::SelectiveClone(const id_list& selection, ScriptFunc* func) const { if ( selection.length() == 0 ) return nullptr; diff --git a/src/Frame.h b/src/Frame.h index 2f21481789..ff62ee6fc2 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -16,10 +16,12 @@ #include #include -ZEEK_FORWARD_DECLARE_NAMESPACED(BroFunc, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Trigger, zeek::detail::trigger); +namespace zeek::detail { class ScriptFunc; } +using BroFunc [[deprecated("Remove in v4.1. Use zeek::detail::ScriptFunc instead.")]] = zeek::detail::ScriptFunc; + namespace zeek { using ValPtr = zeek::IntrusivePtr; @@ -43,7 +45,7 @@ public: * @param func the function that is creating this frame * @param fn_args the arguments being passed to that function. */ - Frame(int size, const BroFunc* func, const zeek::Args* fn_args); + Frame(int size, const ScriptFunc* func, const zeek::Args* fn_args); /** * Deletes the frame. Unrefs its trigger, the values that it @@ -111,7 +113,7 @@ public: /** * @return the function that the frame is associated with. */ - const BroFunc* GetFunction() const { return function; } + const ScriptFunc* GetFunction() const { return function; } /** * @return the arguments passed to the function that this frame @@ -124,7 +126,7 @@ public: * * @param func the function for the frame to be associated with. */ - void SetFunction(BroFunc* func) { function = func; } + void SetFunction(ScriptFunc* func) { function = func; } /** * Sets the next statement to be executed in the context of the frame. @@ -173,7 +175,7 @@ public: * *selection* have been cloned. All other values are made to be * null. */ - Frame* SelectiveClone(const id_list& selection, BroFunc* func) const; + Frame* SelectiveClone(const id_list& selection, ScriptFunc* func) const; /** * Serializes the Frame into a Broker representation. @@ -246,7 +248,7 @@ public: * weak references prevents unbreakable circular references that * otherwise cause memory leaks. */ - void AddFunctionWithClosureRef(BroFunc* func); + void AddFunctionWithClosureRef(ScriptFunc* func); private: @@ -276,7 +278,7 @@ private: * function (in that case just assigna weak reference). Used to break * circular references between lambda functions and closure frames. */ - void CloneNonFuncElement(int offset, BroFunc* func, Frame* other) const; + void CloneNonFuncElement(int offset, ScriptFunc* func, Frame* other) const; /** * Resets the value at offset 'n' frame (by decrementing reference @@ -327,7 +329,7 @@ private: std::unique_ptr offset_map; /** The function this frame is associated with. */ - const BroFunc* function; + const ScriptFunc* function; /** The arguments to the function that this Frame is associated with. */ const zeek::Args* func_args; @@ -337,7 +339,7 @@ private: zeek::detail::trigger::TriggerPtr trigger; const zeek::detail::CallExpr* call; - std::unique_ptr> functions_with_closure_frame_reference; + std::unique_ptr> functions_with_closure_frame_reference; }; } // namespace detail diff --git a/src/Func.cc b/src/Func.cc index 33c7ab2676..c2f5771ba3 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -71,23 +71,23 @@ extern RETSIGTYPE sig_handler(int signo); -namespace zeek { -namespace detail { - +namespace zeek::detail { std::vector call_stack; bool did_builtin_init = false; - static const std::pair empty_hook_result(false, nullptr); +} // namespace zeek::detail + +namespace zeek { std::string render_call_stack() { std::string rval; int lvl = 0; - if ( ! call_stack.empty() ) + if ( ! detail::call_stack.empty() ) rval += "| "; - for ( auto it = call_stack.rbegin(); it != call_stack.rend(); ++it ) + for ( auto it = detail::call_stack.rbegin(); it != detail::call_stack.rend(); ++it ) { if ( lvl > 0 ) rval += " | "; @@ -119,7 +119,7 @@ std::string render_call_stack() ++lvl; } - if ( ! call_stack.empty() ) + if ( ! detail::call_stack.empty() ) rval += " |"; return rval; @@ -151,7 +151,7 @@ void Func::SetScope(zeek::detail::ScopePtr newscope) scope = std::move(newscope); } -zeek::detail::FuncPtr Func::DoClone() +zeek::FuncPtr Func::DoClone() { // By default, ok just to return a reference. Func does not have any state // that is different across instances. @@ -203,7 +203,7 @@ TraversalCode Func::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_PRE(tc); // FIXME: Traverse arguments to builtin functions, too. - if ( kind == BRO_FUNC && scope ) + if ( kind == SCRIPT_FUNC && scope ) { tc = scope->Traverse(cb); HANDLE_TC_STMT_PRE(tc); @@ -236,7 +236,7 @@ void Func::CopyStateInto(Func* other) const void Func::CheckPluginResult(bool handled, const zeek::ValPtr& hook_result, zeek::FunctionFlavor flavor) const { - // Helper function factoring out this code from BroFunc:Call() for + // Helper function factoring out this code from ScriptFunc:Call() for // better readability. if ( ! handled ) @@ -286,10 +286,18 @@ void Func::CheckPluginResult(bool handled, const zeek::ValPtr& hook_result, } } -BroFunc::BroFunc(const zeek::detail::IDPtr& arg_id, zeek::detail::StmtPtr arg_body, - const std::vector& aggr_inits, - size_t arg_frame_size, int priority) - : Func(BRO_FUNC) +zeek::Val* Func::Call(val_list* args, zeek::detail::Frame* parent) const + { + auto zargs = zeek::val_list_to_args(*args); + return Invoke(&zargs, parent).release(); + }; + +namespace detail { + +ScriptFunc::ScriptFunc(const zeek::detail::IDPtr& arg_id, zeek::detail::StmtPtr arg_body, + const std::vector& aggr_inits, + size_t arg_frame_size, int priority) + : Func(SCRIPT_FUNC) { name = arg_id->Name(); type = arg_id->GetType(); @@ -304,25 +312,19 @@ BroFunc::BroFunc(const zeek::detail::IDPtr& arg_id, zeek::detail::StmtPtr arg_bo } } -BroFunc::~BroFunc() +ScriptFunc::~ScriptFunc() { if ( ! weak_closure_ref ) Unref(closure); } -bool BroFunc::IsPure() const +bool ScriptFunc::IsPure() const { return std::all_of(bodies.begin(), bodies.end(), [](const Body& b) { return b.stmts->IsPure(); }); } -zeek::Val* Func::Call(val_list* args, zeek::detail::Frame* parent) const - { - auto zargs = zeek::val_list_to_args(*args); - return Invoke(&zargs, parent).release(); - }; - -zeek::ValPtr BroFunc::Invoke(zeek::Args* args, zeek::detail::Frame* parent) const +zeek::ValPtr ScriptFunc::Invoke(zeek::Args* args, zeek::detail::Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); @@ -467,9 +469,9 @@ zeek::ValPtr BroFunc::Invoke(zeek::Args* args, zeek::detail::Frame* parent) cons return result; } -void BroFunc::AddBody(zeek::detail::StmtPtr new_body, - const std::vector& new_inits, - size_t new_frame_size, int priority) +void ScriptFunc::AddBody(zeek::detail::StmtPtr new_body, + const std::vector& new_inits, + size_t new_frame_size, int priority) { if ( new_frame_size > frame_size ) frame_size = new_frame_size; @@ -496,7 +498,7 @@ void BroFunc::AddBody(zeek::detail::StmtPtr new_body, sort(bodies.begin(), bodies.end()); } -void BroFunc::AddClosure(id_list ids, zeek::detail::Frame* f) +void ScriptFunc::AddClosure(id_list ids, zeek::detail::Frame* f) { if ( ! f ) return; @@ -505,7 +507,7 @@ void BroFunc::AddClosure(id_list ids, zeek::detail::Frame* f) SetClosureFrame(f); } -bool BroFunc::StrengthenClosureReference(zeek::detail::Frame* f) +bool ScriptFunc::StrengthenClosureReference(zeek::detail::Frame* f) { if ( closure != f ) return false; @@ -518,10 +520,10 @@ bool BroFunc::StrengthenClosureReference(zeek::detail::Frame* f) return true; } -void BroFunc::SetClosureFrame(zeek::detail::Frame* f) +void ScriptFunc::SetClosureFrame(zeek::detail::Frame* f) { if ( closure ) - reporter->InternalError("Tried to override closure for BroFunc %s.", + reporter->InternalError("Tried to override closure for ScriptFunc %s.", Name()); // Have to use weak references initially because otherwise Ref'ing the @@ -536,7 +538,7 @@ void BroFunc::SetClosureFrame(zeek::detail::Frame* f) f->AddFunctionWithClosureRef(this); } -bool BroFunc::UpdateClosure(const broker::vector& data) +bool ScriptFunc::UpdateClosure(const broker::vector& data) { auto result = zeek::detail::Frame::Unserialize(data); @@ -558,11 +560,11 @@ bool BroFunc::UpdateClosure(const broker::vector& data) } -zeek::detail::FuncPtr BroFunc::DoClone() +zeek::FuncPtr ScriptFunc::DoClone() { - // BroFunc could hold a closure. In this case a clone of it must + // ScriptFunc could hold a closure. In this case a clone of it must // store a copy of this closure. - auto other = zeek::IntrusivePtr{zeek::AdoptRef{}, new BroFunc()}; + auto other = zeek::IntrusivePtr{zeek::AdoptRef{}, new ScriptFunc()}; CopyStateInto(other.get()); @@ -574,12 +576,12 @@ zeek::detail::FuncPtr BroFunc::DoClone() return other; } -broker::expected BroFunc::SerializeClosure() const +broker::expected ScriptFunc::SerializeClosure() const { return zeek::detail::Frame::Serialize(closure, outer_ids); } -void BroFunc::Describe(ODesc* d) const +void ScriptFunc::Describe(ODesc* d) const { d->Add(Name()); @@ -592,7 +594,7 @@ void BroFunc::Describe(ODesc* d) const } } -zeek::detail::StmtPtr BroFunc::AddInits( +zeek::detail::StmtPtr ScriptFunc::AddInits( zeek::detail::StmtPtr body, const std::vector& inits) { diff --git a/src/Func.h b/src/Func.h index dc9c2fbc92..a9b2603e7a 100644 --- a/src/Func.h +++ b/src/Func.h @@ -25,6 +25,12 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); +namespace zeek::detail { +using ScopePtr = zeek::IntrusivePtr; +using IDPtr = zeek::IntrusivePtr; +using StmtPtr = zeek::IntrusivePtr; +} + namespace caf { template class expected; } @@ -37,19 +43,16 @@ using caf::expected; namespace zeek { -namespace detail { -using ScopePtr = zeek::IntrusivePtr; -using IDPtr = zeek::IntrusivePtr; -using StmtPtr = zeek::IntrusivePtr; - class Func; using FuncPtr = zeek::IntrusivePtr; class Func : public BroObj { public: + static inline const FuncPtr nil; - enum Kind { BRO_FUNC, BUILTIN_FUNC }; + enum Kind { SCRIPT_FUNC, BUILTIN_FUNC }; + static constexpr auto BRO_FUNC [[deprecated("Remove in v4.1. Use Func::SCRIPT_FUNC instead.")]] = SCRIPT_FUNC; explicit Func(Kind arg_kind); @@ -142,21 +145,22 @@ protected: static inline std::vector unique_ids; }; +namespace detail { -class BroFunc final : public Func { +class ScriptFunc final : public zeek::Func { public: - BroFunc(const zeek::detail::IDPtr& id, zeek::detail::StmtPtr body, + ScriptFunc(const zeek::detail::IDPtr& id, zeek::detail::StmtPtr body, const std::vector& inits, size_t frame_size, int priority); - ~BroFunc() override; + ~ScriptFunc() override; bool IsPure() const override; zeek::ValPtr Invoke(zeek::Args* args, zeek::detail::Frame* parent) const override; /** * Adds adds a closure to the function. Closures are cloned and - * future calls to BroFunc methods will not modify *f*. + * future calls to ScriptFunc methods will not modify *f*. * * @param ids IDs that are captured by the closure. * @param f the closure to be captured. @@ -194,7 +198,7 @@ public: void Describe(ODesc* d) const override; protected: - BroFunc() : Func(BRO_FUNC) {} + ScriptFunc() : zeek::Func(SCRIPT_FUNC) {} zeek::detail::StmtPtr AddInits( zeek::detail::StmtPtr body, const std::vector& inits); @@ -202,7 +206,7 @@ protected: /** * Clones this function along with its closures. */ - FuncPtr DoClone() override; + zeek::FuncPtr DoClone() override; /** * Performs a selective clone of *f* using the IDs that were @@ -217,14 +221,14 @@ private: // List of the outer IDs used in the function. id_list outer_ids; - // The frame the BroFunc was initialized in. + // The frame the ScriptFunc was initialized in. zeek::detail::Frame* closure = nullptr; bool weak_closure_ref = false; }; using built_in_func = BifReturnVal (*)(zeek::detail::Frame* frame, const zeek::Args* args); -class BuiltinFunc final : public Func { +class BuiltinFunc final : public zeek::Func { public: BuiltinFunc(built_in_func func, const char* name, bool is_pure); ~BuiltinFunc() override; @@ -250,7 +254,7 @@ struct CallInfo { const zeek::Args& args; }; -// Struct that collects all the specifics defining a Func. Used for BroFuncs +// Struct that collects all the specifics defining a Func. Used for ScriptFuncs // with closures. struct function_ingredients { @@ -268,13 +272,13 @@ struct function_ingredients { extern std::vector call_stack; -extern std::string render_call_stack(); - // This is set to true after the built-in functions have been initialized. extern bool did_builtin_init; } // namespace detail +extern std::string render_call_stack(); + // These methods are used by BIFs, so they're in the public namespace. extern void emit_builtin_error(const char* msg); extern void emit_builtin_error(const char* msg, zeek::ValPtr); @@ -282,14 +286,14 @@ extern void emit_builtin_error(const char* msg, BroObj* arg); } // namespace zeek -using Func [[deprecated("Remove in v4.1. Use zeek::detail::Func.")]] = zeek::detail::Func; -using BroFunc [[deprecated("Remove in v4.1. Use zeek::detail::BroFunc.")]] = zeek::detail::BroFunc; -using BuiltinFunc [[deprecated("Remove in v4.1. Use zeek::detail::BroFunc.")]] = zeek::detail::BuiltinFunc; +using Func [[deprecated("Remove in v4.1. Use zeek::Func.")]] = zeek::Func; +using BroFunc [[deprecated("Remove in v4.1. Use zeek::detail::ScriptFunc.")]] = zeek::detail::ScriptFunc; +using BuiltinFunc [[deprecated("Remove in v4.1. Use zeek::detail::BuiltinFunc.")]] = zeek::detail::BuiltinFunc; using CallInfo [[deprecated("Remove in v4.1. Use zeek::detail::CallInfo.")]] = zeek::detail::CallInfo; using function_ingredients [[deprecated("Remove in v4.1. Use zeek::detail::function_ingredients.")]] = zeek::detail::function_ingredients; constexpr auto check_built_in_call [[deprecated("Remove in v4.1. Use zeek::detail::check_built_in_call.")]] = zeek::detail::check_built_in_call; -constexpr auto render_call_stack [[deprecated("Remove in v4.1. Use zeek::detail::render_call_stack.")]] = zeek::detail::render_call_stack; +constexpr auto render_call_stack [[deprecated("Remove in v4.1. Use zeek::render_call_stack.")]] = zeek::render_call_stack; // TODO: these are still here because of how all of the bif code gets included in Func.c. There could be a // renamed version inside the namespace, but the way that the code gets included complicates the matter. It diff --git a/src/ID.cc b/src/ID.cc index 79f1234cf7..f4eae447db 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -74,7 +74,7 @@ const zeek::ValPtr& zeek::id::find_const(std::string_view name) return id->GetVal(); } -zeek::detail::FuncPtr zeek::id::find_func(std::string_view name) +zeek::FuncPtr zeek::id::find_func(std::string_view name) { const auto& v = zeek::id::find_val(name); @@ -643,7 +643,7 @@ void ID::UpdateValID() } #endif -void ID::AddOptionHandler(zeek::detail::FuncPtr callback, int priority) +void ID::AddOptionHandler(zeek::FuncPtr callback, int priority) { option_handlers.emplace(priority, std::move(callback)); } diff --git a/src/ID.h b/src/ID.h index 4f3642e5b1..a410debd4a 100644 --- a/src/ID.h +++ b/src/ID.h @@ -13,7 +13,7 @@ #include #include -ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(RecordType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(TableType, zeek); @@ -28,6 +28,7 @@ using TableTypePtr = zeek::IntrusivePtr; using VectorTypePtr = zeek::IntrusivePtr; using EnumTypePtr = zeek::IntrusivePtr; using ValPtr = zeek::IntrusivePtr; +using FuncPtr = zeek::IntrusivePtr; } using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; @@ -37,7 +38,6 @@ namespace zeek::detail { class Attributes; class Expr; using ExprPtr = zeek::IntrusivePtr; -using FuncPtr = zeek::IntrusivePtr; enum InitClass { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, }; enum IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL }; @@ -156,7 +156,7 @@ public: bool HasOptionHandlers() const { return !option_handlers.empty(); } - void AddOptionHandler(zeek::detail::FuncPtr callback, int priority); + void AddOptionHandler(zeek::FuncPtr callback, int priority); std::vector GetOptionHandlers() const; protected: @@ -176,7 +176,7 @@ protected: ValPtr val; AttributesPtr attrs; // contains list of functions that are called when an option changes - std::multimap option_handlers; + std::multimap option_handlers; }; @@ -254,7 +254,7 @@ zeek::IntrusivePtr find_const(std::string_view name) * @param name The identifier name to lookup * @return The current function value the identifier references. */ -zeek::detail::FuncPtr find_func(std::string_view name); +zeek::FuncPtr find_func(std::string_view name); extern RecordTypePtr conn_id; extern RecordTypePtr endpoint; diff --git a/src/NFA.h b/src/NFA.h index 0e24a1daab..27cc7e5096 100644 --- a/src/NFA.h +++ b/src/NFA.h @@ -9,7 +9,7 @@ class CCL; class NFA_State; class EquivClass; -ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek); using NFA_state_list = zeek::PList; diff --git a/src/Obj.cc b/src/Obj.cc index be5f6794d8..daa8734353 100644 --- a/src/Obj.cc +++ b/src/Obj.cc @@ -103,7 +103,7 @@ void BroObj::Internal(const char* msg) const { ODesc d; DoMsg(&d, msg); - auto rcs = zeek::detail::render_call_stack(); + auto rcs = zeek::render_call_stack(); if ( rcs.empty() ) reporter->InternalError("%s", d.Description()); diff --git a/src/Stats.cc b/src/Stats.cc index 9e028b6f1a..b88c083612 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -352,7 +352,7 @@ SampleLogger::~SampleLogger() Unref(load_samples); } -void SampleLogger::FunctionSeen(const zeek::detail::Func* func) +void SampleLogger::FunctionSeen(const zeek::Func* func) { auto idx = zeek::make_intrusive(func->Name()); load_samples->Assign(std::move(idx), nullptr); diff --git a/src/Stats.h b/src/Stats.h index 91dd274e42..b9131d4d10 100644 --- a/src/Stats.h +++ b/src/Stats.h @@ -11,7 +11,7 @@ class BroFile; -ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(TableVal, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Location, zeek::detail); @@ -94,7 +94,7 @@ public: // These are called to report that a given function or location // has been seen during the sampling. - void FunctionSeen(const zeek::detail::Func* func); + void FunctionSeen(const zeek::Func* func); void LocationSeen(const zeek::detail::Location* loc); protected: diff --git a/src/Traverse.h b/src/Traverse.h index 89554c8387..6cdd07f042 100644 --- a/src/Traverse.h +++ b/src/Traverse.h @@ -4,7 +4,7 @@ #include "TraverseTypes.h" -ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Scope, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); @@ -15,8 +15,8 @@ public: TraversalCallback() { current_scope = nullptr; } virtual ~TraversalCallback() {} - virtual TraversalCode PreFunction(const zeek::detail::Func*) { return TC_CONTINUE; } - virtual TraversalCode PostFunction(const zeek::detail::Func*) { return TC_CONTINUE; } + virtual TraversalCode PreFunction(const zeek::Func*) { return TC_CONTINUE; } + virtual TraversalCode PostFunction(const zeek::Func*) { return TC_CONTINUE; } virtual TraversalCode PreStmt(const zeek::detail::Stmt*) { return TC_CONTINUE; } virtual TraversalCode PostStmt(const zeek::detail::Stmt*) { return TC_CONTINUE; } diff --git a/src/Val.cc b/src/Val.cc index 0c4eb92b13..41354830ed 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -44,10 +44,10 @@ using namespace std; namespace zeek { -Val::Val(zeek::detail::Func* f) : Val({NewRef{}, f}) +Val::Val(zeek::Func* f) : Val({NewRef{}, f}) {} -Val::Val(zeek::detail::FuncPtr f) +Val::Val(zeek::FuncPtr f) : val(f.release()), type(val.func_val->GetType()) {} @@ -155,7 +155,7 @@ ValPtr Val::DoClone(CloneState* state) return nullptr; } -zeek::detail::FuncPtr Val::AsFuncPtr() const +zeek::FuncPtr Val::AsFuncPtr() const { CHECK_TAG(type->Tag(), TYPE_FUNC, "Val::Func", type_name) return {NewRef{}, val.func_val}; @@ -1858,7 +1858,7 @@ ValPtr TableVal::Default(const ValPtr& index) return nullptr; } - const zeek::detail::Func* f = def_val->AsFunc(); + const zeek::Func* f = def_val->AsFunc(); Args vl; if ( index->GetType()->Tag() == TYPE_LIST ) @@ -2056,7 +2056,7 @@ void TableVal::CallChangeFunc(const Val* index, return; } - const zeek::detail::Func* f = thefunc->AsFunc(); + const zeek::Func* f = thefunc->AsFunc(); auto lv = index->AsListVal(); Args vl; @@ -2514,7 +2514,7 @@ double TableVal::CallExpireFunc(ListValPtr idx) return 0; } - const zeek::detail::Func* f = vf->AsFunc(); + const zeek::Func* f = vf->AsFunc(); Args vl; const auto& func_args = f->GetType()->ParamList()->GetTypes(); diff --git a/src/Val.h b/src/Val.h index 5a56b4f050..d02998f815 100644 --- a/src/Val.h +++ b/src/Val.h @@ -33,8 +33,10 @@ template using PDict [[deprecated("Remove in v4.1. Use zeek::PDict i ZEEK_FORWARD_DECLARE_NAMESPACED(IterCookie, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(BroString, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); -ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); -ZEEK_FORWARD_DECLARE_NAMESPACED(BroFunc, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek); + +namespace zeek::detail { class ScriptFunc; } +using BroFunc [[deprecated("Remove in v4.1. Use zeek::detail::ScriptFunc instead.")]] = zeek::detail::ScriptFunc; class BroFile; class PrefixTable; @@ -50,10 +52,7 @@ extern double bro_start_network_time; namespace zeek { -namespace detail { using FuncPtr = zeek::IntrusivePtr; -} - using BroFilePtr = zeek::IntrusivePtr; class Val; @@ -98,7 +97,7 @@ union BroValUnion { double double_val; BroString* string_val; - zeek::detail::Func* func_val; + zeek::Func* func_val; BroFile* file_val; RE_Matcher* re_val; zeek::PDict* table_val; @@ -125,7 +124,7 @@ union BroValUnion { constexpr BroValUnion(BroString* value) noexcept : string_val(value) {} - constexpr BroValUnion(zeek::detail::Func* value) noexcept + constexpr BroValUnion(zeek::Func* value) noexcept : func_val(value) {} constexpr BroValUnion(BroFile* value) noexcept @@ -148,8 +147,8 @@ public: {} [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] - explicit Val(zeek::detail::Func* f); - explicit Val(zeek::detail::FuncPtr f); + explicit Val(zeek::Func* f); + explicit Val(zeek::FuncPtr f); [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit Val(BroFile* f); @@ -238,7 +237,7 @@ public: CONST_ACCESSOR2(zeek::TYPE_INTERVAL, double, double_val, AsInterval) CONST_ACCESSOR2(zeek::TYPE_ENUM, int, int_val, AsEnum) CONST_ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString) - CONST_ACCESSOR(zeek::TYPE_FUNC, zeek::detail::Func*, func_val, AsFunc) + CONST_ACCESSOR(zeek::TYPE_FUNC, zeek::Func*, func_val, AsFunc) CONST_ACCESSOR(zeek::TYPE_TABLE, zeek::PDict*, table_val, AsTable) CONST_ACCESSOR(zeek::TYPE_RECORD, std::vector*, record_val, AsRecord) CONST_ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile) @@ -274,12 +273,12 @@ public: // Accessors for mutable values are called AsNonConst* and // are protected to avoid external state changes. // ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString) - ACCESSOR(zeek::TYPE_FUNC, zeek::detail::Func*, func_val, AsFunc) + ACCESSOR(zeek::TYPE_FUNC, zeek::Func*, func_val, AsFunc) ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile) ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) ACCESSOR(zeek::TYPE_VECTOR, std::vector*, vector_val, AsVector) - zeek::detail::FuncPtr AsFuncPtr() const; + zeek::FuncPtr AsFuncPtr() const; const IPPrefix& AsSubNet() { diff --git a/src/Var.cc b/src/Var.cc index a45a3c9ad9..b944ba636c 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -307,7 +307,7 @@ static void make_var(const zeek::detail::IDPtr& id, zeek::TypePtr t, // we can later access the ID even if no implementations have been // defined. std::vector inits; - auto f = zeek::make_intrusive(id, nullptr, inits, 0, 0); + auto f = zeek::make_intrusive(id, nullptr, inits, 0, 0); id->SetVal(zeek::make_intrusive(std::move(f))); } } @@ -655,7 +655,7 @@ void end_func(zeek::detail::StmtPtr body) ingredients->priority); else { - auto f = zeek::make_intrusive( + auto f = zeek::make_intrusive( ingredients->id, ingredients->body, ingredients->inits, @@ -781,7 +781,7 @@ zeek::Type* internal_type(const char* name) return zeek::id::find_type(name).get(); } -zeek::detail::Func* internal_func(const char* name) +zeek::Func* internal_func(const char* name) { const auto& v = zeek::id::find_val(name); diff --git a/src/Var.h b/src/Var.h index 7fd8fdf033..25278c7b8c 100644 --- a/src/Var.h +++ b/src/Var.h @@ -86,7 +86,7 @@ extern zeek::ListVal* internal_list_val(const char* name); extern zeek::Type* internal_type(const char* name); [[deprecated("Remove in v4.1. Use zeek::id::find_func().")]] -extern zeek::detail::Func* internal_func(const char* name); +extern zeek::Func* internal_func(const char* name); [[deprecated("Remove in v4.1. Use event_registry->Register().")]] extern EventHandlerPtr internal_handler(const char* name); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 2978c3b13e..b137b79361 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -370,7 +370,7 @@ struct val_converter { if ( ! frame ) return nullptr; - auto* b = dynamic_cast(rval->AsFunc()); + auto* b = dynamic_cast(rval->AsFunc()); if ( ! b ) return nullptr; @@ -852,7 +852,7 @@ broker::expected bro_broker::val_to_data(const zeek::Val* v) return {string(v->AsFile()->Name())}; case zeek::TYPE_FUNC: { - const zeek::detail::Func* f = v->AsFunc(); + const zeek::Func* f = v->AsFunc(); std::string name(f->Name()); broker::vector rval; @@ -860,8 +860,8 @@ broker::expected bro_broker::val_to_data(const zeek::Val* v) if ( name.find("lambda_<") == 0 ) { - // Only BroFuncs have closures. - if ( auto b = dynamic_cast(f) ) + // Only ScriptFuncs have closures. + if ( auto b = dynamic_cast(f) ) { auto bc = b->SerializeClosure(); if ( ! bc ) @@ -871,7 +871,7 @@ broker::expected bro_broker::val_to_data(const zeek::Val* v) } else { - reporter->InternalWarning("Closure with non-BroFunc"); + reporter->InternalWarning("Closure with non-ScriptFunc"); return broker::ec::invalid_data; } } diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index a3a6764ed8..a0c9797bd7 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -704,7 +704,7 @@ zeek::RecordVal* Manager::MakeEvent(val_list* args, zeek::detail::Frame* frame) auto rval = new zeek::RecordVal(zeek::BifType::Record::Broker::Event); auto arg_vec = zeek::make_intrusive(vector_of_data_type); rval->Assign(1, arg_vec); - zeek::detail::Func* func = nullptr; + zeek::Func* func = nullptr; scoped_reporter_location srl{frame}; for ( auto i = 0; i < args->length(); ++i ) diff --git a/src/broker/Manager.h b/src/broker/Manager.h index 6c4764c49f..ca079ca890 100644 --- a/src/broker/Manager.h +++ b/src/broker/Manager.h @@ -21,7 +21,7 @@ #include "iosource/IOSource.h" #include "logging/WriterBackend.h" -ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(VectorType, zeek); @@ -400,7 +400,7 @@ private: int peer_count; size_t log_batch_size; - zeek::detail::Func* log_topic_func; + zeek::Func* log_topic_func; zeek::VectorTypePtr vector_of_data_type; zeek::EnumType* log_id_type; zeek::EnumType* writer_id_type; diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index fd3bbc43f1..4d6d04bb38 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -182,7 +182,7 @@ type Cluster::Pool: record; ## Returns: true if the message is sent. function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool %{ - static zeek::detail::Func* topic_func = nullptr; + static zeek::Func* topic_func = nullptr; if ( ! topic_func ) topic_func = zeek::detail::global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc(); @@ -219,7 +219,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool ## Returns: true if the message is sent. function Cluster::publish_hrw%(pool: Pool, key: any, ...%): bool %{ - static zeek::detail::Func* topic_func = nullptr; + static zeek::Func* topic_func = nullptr; if ( ! topic_func ) topic_func = zeek::detail::global_scope()->Find("Cluster::hrw_topic")->GetVal()->AsFunc(); diff --git a/src/file_analysis/analyzer/x509/X509.h b/src/file_analysis/analyzer/x509/X509.h index 7d17963920..884e1402d1 100644 --- a/src/file_analysis/analyzer/x509/X509.h +++ b/src/file_analysis/analyzer/x509/X509.h @@ -123,7 +123,7 @@ public: /** * Sets the callback when a certificate cache hit is encountered */ - static void SetCertificateCacheHitCallback(zeek::detail::FuncPtr func) + static void SetCertificateCacheHitCallback(zeek::FuncPtr func) { cache_hit_callback = std::move(func); } protected: @@ -142,7 +142,7 @@ private: /** X509 stores associated with global script-layer values */ inline static std::map x509_stores = std::map(); inline static zeek::TableValPtr certificate_cache = nullptr; - inline static zeek::detail::FuncPtr cache_hit_callback = nullptr; + inline static zeek::FuncPtr cache_hit_callback = nullptr; }; /** diff --git a/src/input/Manager.cc b/src/input/Manager.cc index c765e58714..22201abd3c 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -102,7 +102,7 @@ public: zeek::PDict* currDict; zeek::PDict* lastDict; - zeek::detail::Func* pred; + zeek::Func* pred; EventHandlerPtr event; @@ -320,7 +320,7 @@ bool Manager::CreateEventStream(zeek::RecordVal* fval) auto want_record = fval->GetFieldOrDefault("want_record"); auto ev_val = fval->GetFieldOrDefault("ev"); - zeek::detail::Func* event = ev_val->AsFunc(); + zeek::Func* event = ev_val->AsFunc(); const auto& etype = event->GetType(); @@ -409,7 +409,7 @@ bool Manager::CreateEventStream(zeek::RecordVal* fval) assert(false); auto error_event_val = fval->GetFieldOrDefault("error_ev"); - zeek::detail::Func* error_event = error_event_val ? error_event_val->AsFunc() : nullptr; + zeek::Func* error_event = error_event_val ? error_event_val->AsFunc() : nullptr; if ( ! CheckErrorEventTypes(stream_name, error_event, false) ) return false; @@ -545,7 +545,7 @@ bool Manager::CreateTableStream(zeek::RecordVal* fval) } auto event_val = fval->GetFieldOrDefault("ev"); - zeek::detail::Func* event = event_val ? event_val->AsFunc() : nullptr; + zeek::Func* event = event_val ? event_val->AsFunc() : nullptr; if ( event ) { @@ -618,7 +618,7 @@ bool Manager::CreateTableStream(zeek::RecordVal* fval) } auto error_event_val = fval->GetFieldOrDefault("error_ev"); - zeek::detail::Func* error_event = error_event_val ? error_event_val->AsFunc() : nullptr; + zeek::Func* error_event = error_event_val ? error_event_val->AsFunc() : nullptr; if ( ! CheckErrorEventTypes(stream_name, error_event, true) ) return false; @@ -691,7 +691,7 @@ bool Manager::CreateTableStream(zeek::RecordVal* fval) return true; } -bool Manager::CheckErrorEventTypes(const std::string& stream_name, const zeek::detail::Func* ev, bool table) const +bool Manager::CheckErrorEventTypes(const std::string& stream_name, const zeek::Func* ev, bool table) const { if ( ev == nullptr ) return true; @@ -1756,7 +1756,7 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) return success; } -bool Manager::CallPred(zeek::detail::Func* pred_func, const int numvals, ...) const +bool Manager::CallPred(zeek::Func* pred_func, const int numvals, ...) const { bool result = false; zeek::Args vl; diff --git a/src/input/Manager.h b/src/input/Manager.h index e1c1af100f..55e47243c1 100644 --- a/src/input/Manager.h +++ b/src/input/Manager.h @@ -185,7 +185,7 @@ private: // Check if the types of the error_ev event are correct. If table is // true, check for tablestream type, otherwhise check for eventstream // type. - bool CheckErrorEventTypes(const std::string& stream_name, const zeek::detail::Func* error_event, bool table) const; + bool CheckErrorEventTypes(const std::string& stream_name, const zeek::Func* error_event, bool table) const; // SendEntry implementation for Table stream. int SendEntryTable(Stream* i, const threading::Value* const *vals); @@ -209,7 +209,7 @@ private: void SendEndOfData(const Stream *i); // Call predicate function and return result. - bool CallPred(zeek::detail::Func* pred_func, const int numvals, ...) const; + bool CallPred(zeek::Func* pred_func, const int numvals, ...) const; // Get a hashkey for a set of threading::Values. HashKey* HashValues(const int num_elements, const threading::Value* const *vals) const; diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 4f7860e1c6..d16a1934be 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -34,8 +34,8 @@ struct Manager::Filter { zeek::Val* fval; string name; zeek::EnumVal* id; - zeek::detail::Func* pred; - zeek::detail::Func* path_func; + zeek::Func* pred; + zeek::Func* path_func; string path; zeek::Val* path_val; zeek::EnumVal* writer; @@ -43,12 +43,12 @@ struct Manager::Filter { zeek::TableVal* field_name_map; string scope_sep; string ext_prefix; - zeek::detail::Func* ext_func; + zeek::Func* ext_func; int num_ext_fields; bool local; bool remote; double interval; - zeek::detail::Func* postprocessor; + zeek::Func* postprocessor; int num_fields; threading::Field** fields; @@ -66,7 +66,7 @@ struct Manager::WriterInfo { double open_time; Timer* rotation_timer; double interval; - zeek::detail::Func* postprocessor; + zeek::Func* postprocessor; WriterFrontend* writer; WriterBackend::WriterInfo* info; bool from_remote; @@ -264,7 +264,7 @@ bool Manager::CreateStream(zeek::EnumVal* id, zeek::RecordVal* sval) } const auto& event_val = sval->GetField("ev"); - zeek::detail::Func* event = event_val ? event_val->AsFunc() : nullptr; + zeek::Func* event = event_val ? event_val->AsFunc() : nullptr; if ( event ) { @@ -997,7 +997,7 @@ threading::Value* Manager::ValToLogVal(zeek::Val* val, zeek::Type* ty) case zeek::TYPE_FUNC: { ODesc d; - const zeek::detail::Func* f = val->AsFunc(); + const zeek::Func* f = val->AsFunc(); f->Describe(&d); const char* s = d.Description(); lval->val.string_val.data = copy_string(s); @@ -1517,7 +1517,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con info->Assign(4, zeek::make_intrusive(close)); info->Assign(5, zeek::val_mgr->Bool(terminating)); - zeek::detail::Func* func = winfo->postprocessor; + zeek::Func* func = winfo->postprocessor; if ( ! func ) { const auto& id = zeek::detail::global_scope()->Find("Log::__default_rotation_postprocessor"); diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index 165c27de2a..29b1abf331 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -617,7 +617,7 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const } std::pair -Manager::HookCallFunction(const zeek::detail::Func* func, zeek::detail::Frame* parent, +Manager::HookCallFunction(const zeek::Func* func, zeek::detail::Frame* parent, zeek::Args* vecargs) const { HookArgumentList args; diff --git a/src/plugin/Manager.h b/src/plugin/Manager.h index 3a42c29c3f..09bdbfb65d 100644 --- a/src/plugin/Manager.h +++ b/src/plugin/Manager.h @@ -256,7 +256,7 @@ public: * the method returns null. */ std::pair - HookCallFunction(const zeek::detail::Func* func, zeek::detail::Frame* parent, zeek::Args* args) const; + HookCallFunction(const zeek::Func* func, zeek::detail::Frame* parent, zeek::Args* args) const; /** * Hook that filters the queuing of an event. diff --git a/src/plugin/Plugin.cc b/src/plugin/Plugin.cc index 2f7f734fdc..da890b269c 100644 --- a/src/plugin/Plugin.cc +++ b/src/plugin/Plugin.cc @@ -376,7 +376,7 @@ int Plugin::HookLoadFile(const LoadType type, const std::string& file, const std } std::pair -Plugin::HookFunctionCall(const zeek::detail::Func* func, zeek::detail::Frame* parent, +Plugin::HookFunctionCall(const zeek::Func* func, zeek::detail::Frame* parent, zeek::Args* args) { val_list vlargs(args->size()); @@ -396,7 +396,7 @@ Plugin::HookFunctionCall(const zeek::detail::Func* func, zeek::detail::Frame* pa } std::pair Plugin::HookCallFunction( - const zeek::detail::Func* func, zeek::detail::Frame *parent, val_list* args) + const zeek::Func* func, zeek::detail::Frame *parent, val_list* args) { std::pair result(false, NULL); return result; diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index 816141ce53..f0850401a3 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -19,7 +19,7 @@ class ODesc; class Event; -ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); namespace zeek { @@ -201,7 +201,7 @@ public: /** * Constructor with a function argument. */ - explicit HookArgument(const zeek::detail::Func* a) { type = FUNC; arg.func = a; } + explicit HookArgument(const zeek::Func* a) { type = FUNC; arg.func = a; } /** * Constructor with an integer argument. @@ -286,7 +286,7 @@ public: * Returns the value for a function argument. The argument's type must * match accordingly. */ - const zeek::detail::Func* AsFunc() const { assert(type == FUNC); return arg.func; } + const zeek::Func* AsFunc() const { assert(type == FUNC); return arg.func; } /** * Returns the value for an integer argument. The argument's type must @@ -366,7 +366,7 @@ private: double double_; const Event* event; const Connection* conn; - const zeek::detail::Func* func; + const zeek::Func* func; const zeek::detail::Frame* frame; int int_; const Val* val; @@ -674,10 +674,10 @@ protected: * pair with the first member set to 'false' and null result value. */ virtual std::pair - HookFunctionCall(const zeek::detail::Func* func, zeek::detail::Frame* parent, zeek::Args* args); + HookFunctionCall(const zeek::Func* func, zeek::detail::Frame* parent, zeek::Args* args); [[deprecated("Remove in v4.1. Use HookFunctionCall()")]] - virtual std::pair HookCallFunction(const zeek::detail::Func* func, zeek::detail::Frame *parent, val_list* args); + virtual std::pair HookCallFunction(const zeek::Func* func, zeek::detail::Frame *parent, val_list* args); /** * Hook into raising events. Whenever the script interpreter is about diff --git a/src/zeek.bif b/src/zeek.bif index ed6416d3d1..ba2c85e352 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1327,7 +1327,7 @@ function all_set%(v: any%) : bool %} %%{ -static zeek::detail::Func* sort_function_comp = nullptr; +static zeek::Func* sort_function_comp = nullptr; static std::vector index_map; // used for indirect sorting to support order() bool sort_function(const zeek::ValPtr& a, const zeek::ValPtr& b) @@ -1410,7 +1410,7 @@ function sort%(v: any, ...%) : any } const auto& elt_type = v->GetType()->Yield(); - zeek::detail::Func* comp = nullptr; + zeek::Func* comp = nullptr; if ( @ARG@.size() > 2 ) zeek::emit_builtin_error("sort() called with extraneous argument"); @@ -1480,7 +1480,7 @@ function order%(v: any, ...%) : index_vec } const auto& elt_type = v->GetType()->Yield(); - zeek::detail::Func* comp = nullptr; + zeek::Func* comp = nullptr; if ( @ARG@.size() > 2 ) zeek::emit_builtin_error("order() called with extraneous argument");