broker/Eventhandler: Deprecate Broker::auto_publish() for v8.1

Relates to #3637
This commit is contained in:
Arne Welzel 2024-11-06 15:15:04 +01:00
parent 455e05bc2e
commit 6abb9d7eda
6 changed files with 29 additions and 5 deletions

4
NEWS
View file

@ -109,6 +109,10 @@ Removed Functionality
Deprecated Functionality
------------------------
* The ``Broker::auto_publish()`` function has been deprecated and should
be replaced with explicit ``Broker::publish()`` invocations that are
potentially guarded with appropriate ``@if`` or ``@ifdef`` directives.
Zeek 7.0.0
==========

View file

@ -395,7 +395,7 @@ export {
## ev: a Zeek event value.
##
## Returns: true if automatic event sending is now enabled.
global auto_publish: function(topic: string, ev: any): bool;
global auto_publish: function(topic: string, ev: any): bool &deprecated="Remove in v8.1. Switch to explicit Broker::publish() calls. Auto-publish won't work with all cluster backends.";
## Stop automatically sending an event to peers upon local dispatch.
##
@ -405,7 +405,7 @@ export {
##
## Returns: true if automatic events will not occur for the topic/event
## pair.
global auto_unpublish: function(topic: string, ev: any): bool;
global auto_unpublish: function(topic: string, ev: any): bool &deprecated="Remove in v8.1. See Broker::auto_publish()";
}
@load base/bif/comm.bif

View file

@ -35,9 +35,15 @@ public:
void SetFunc(FuncPtr f);
void AutoPublish(std::string topic) { auto_publish.insert(std::move(topic)); }
[[deprecated("Remove in v8.1, use explicit Publish().")]]
void AutoPublish(std::string topic) {
auto_publish.insert(std::move(topic));
}
void AutoUnpublish(const std::string& topic) { auto_publish.erase(topic); }
[[deprecated("Remove in v8.1.")]]
void AutoUnpublish(const std::string& topic) {
auto_publish.erase(topic);
}
void Call(zeek::Args* vl, bool no_remote = false, double ts = run_state::network_time);

View file

@ -811,7 +811,10 @@ bool Manager::AutoPublishEvent(string topic, Val* event) {
}
DBG_LOG(DBG_BROKER, "Enabling auto-publishing of event %s to topic %s", handler->Name(), topic.c_str());
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
handler->AutoPublish(std::move(topic));
#pragma GCC diagnostic pop
return true;
}
@ -837,7 +840,10 @@ bool Manager::AutoUnpublishEvent(const string& topic, Val* event) {
}
DBG_LOG(DBG_BROKER, "Disabling auto-publishing of event %s to topic %s", handler->Name(), topic.c_str());
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
handler->AutoUnpublish(topic);
#pragma GCC diagnostic pop
return true;
}

View file

@ -243,6 +243,7 @@ public:
* @param event a Zeek event value.
* @return true if automatic event sending is now enabled.
*/
[[deprecated("Remove in v8.1, use explicit Publish().")]]
bool AutoPublishEvent(std::string topic, Val* event);
/**
@ -251,6 +252,7 @@ public:
* @param event an event originally given to zeek::Broker::Manager::AutoPublish().
* @return true if automatic events will no occur for the topic/event pair.
*/
[[deprecated("Remove in v8.1.")]]
bool AutoUnpublishEvent(const std::string& topic, Val* event);
/**
@ -483,7 +485,7 @@ private:
telemetry::CounterPtr num_logs_outgoing_metric;
telemetry::CounterPtr num_ids_incoming_metric;
telemetry::CounterPtr num_ids_outgoing_metric;
};
}; // namespace zeek
} // namespace Broker

View file

@ -136,14 +136,20 @@ function Broker::__publish_id%(topic: string, id: string%): bool
function Broker::__auto_publish%(topic: string, ev: any%): bool
%{
zeek::Broker::Manager::ScriptScopeGuard ssg;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
auto rval = zeek::broker_mgr->AutoPublishEvent(topic->CheckString(), ev);
#pragma GCC diagnostic pop
return zeek::val_mgr->Bool(rval);
%}
function Broker::__auto_unpublish%(topic: string, ev: any%): bool
%{
zeek::Broker::Manager::ScriptScopeGuard ssg;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
auto rval = zeek::broker_mgr->AutoUnpublishEvent(topic->CheckString(), ev);
#pragma GCC diagnostic pop
return zeek::val_mgr->Bool(rval);
%}