Skip to content

Commit

Permalink
broker/Eventhandler: Deprecate Broker::auto_publish() for v8.1
Browse files Browse the repository at this point in the history
Relates to zeek#3637
  • Loading branch information
awelzel committed Nov 14, 2024
1 parent 455e05b commit 6abb9d7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
==========

Expand Down
4 changes: 2 additions & 2 deletions scripts/base/frameworks/broker/main.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -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.
##
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/EventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ class EventHandler {

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

Expand Down
6 changes: 6 additions & 0 deletions src/broker/Manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/broker/Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class Manager : public iosource::IOSource {
* @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);

/**
Expand All @@ -251,6 +252,7 @@ class Manager : public iosource::IOSource {
* @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);

/**
Expand Down Expand Up @@ -483,7 +485,7 @@ class Manager : public iosource::IOSource {
telemetry::CounterPtr num_logs_outgoing_metric;
telemetry::CounterPtr num_ids_incoming_metric;
telemetry::CounterPtr num_ids_outgoing_metric;
};
}; // namespace zeek

} // namespace Broker

Expand Down
6 changes: 6 additions & 0 deletions src/broker/messaging.bif
Original file line number Diff line number Diff line change
Expand Up @@ -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);
%}

Expand Down

0 comments on commit 6abb9d7

Please sign in to comment.