mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Broker changes: adopt to recent IntrusivePtr API changes
This commit is contained in:
parent
d9de6c4522
commit
f080c8c294
4 changed files with 30 additions and 34 deletions
|
@ -586,14 +586,14 @@ void Attributes::CheckAttr(Attr* a)
|
|||
break;
|
||||
}
|
||||
|
||||
if ( a->AttrExpr()->Type()->Tag() != TYPE_STRING )
|
||||
if ( a->GetExpr()->GetType()->Tag() != TYPE_STRING )
|
||||
{
|
||||
Error("&broker_store must take a string argument");
|
||||
break;
|
||||
}
|
||||
|
||||
// Temporary since Broker does not support ListVals - and we cannot easily convert to set/vector
|
||||
if ( type->AsTableType()->IndexTypes()->length() != 1 )
|
||||
if ( type->AsTableType()->IndexTypes().size() != 1 )
|
||||
{
|
||||
Error("&broker_store only supports one-element set/table indexes");
|
||||
}
|
||||
|
|
20
src/Val.cc
20
src/Val.cc
|
@ -1488,12 +1488,12 @@ void TableVal::SetAttrs(IntrusivePtr<Attributes> a)
|
|||
if ( cf )
|
||||
change_func = cf->GetExpr();
|
||||
|
||||
auto bs = attrs->FindAttr(ATTR_BROKER_STORE);
|
||||
auto bs = attrs->Find(ATTR_BROKER_STORE);
|
||||
if ( bs && broker_store.empty() ) // this does not mesh well with being updated several times
|
||||
{
|
||||
IntrusivePtr<Val> c = bs->AttrExpr()->Eval(nullptr);
|
||||
IntrusivePtr<Val> c = bs->GetExpr()->Eval(nullptr);
|
||||
assert(c);
|
||||
assert(c->Type()->Tag() == TYPE_STRING);
|
||||
assert(c->GetType()->Tag() == TYPE_STRING);
|
||||
broker_store = c->AsStringVal()->AsString()->CheckString();
|
||||
broker_mgr->AddForwardedStore(broker_store, {NewRef{}, this});
|
||||
}
|
||||
|
@ -2113,7 +2113,6 @@ void TableVal::CallChangeFunc(const Val* index,
|
|||
in_change_func = false;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
void TableVal::SendToStore(const Val* index, const Val* new_value, OnChangeType tpe)
|
||||
{
|
||||
if ( broker_store.empty() || ! index )
|
||||
|
@ -2129,7 +2128,7 @@ void TableVal::SendToStore(const Val* index, const Val* new_value, OnChangeType
|
|||
// we wither get passed the raw index_val - or a ListVal with exactly one element.
|
||||
// Since broker does not support ListVals, we have to unoll this in the second case.
|
||||
const Val* index_val;
|
||||
if ( index->Type()->Tag() == TYPE_LIST )
|
||||
if ( index->GetType()->Tag() == TYPE_LIST )
|
||||
{
|
||||
if ( index->AsListVal()->Length() != 1 )
|
||||
{
|
||||
|
@ -2137,7 +2136,7 @@ void TableVal::SendToStore(const Val* index, const Val* new_value, OnChangeType
|
|||
return;
|
||||
}
|
||||
|
||||
index_val = index->AsListVal()->Index(0);
|
||||
index_val = index->AsListVal()->Idx(0).get();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2187,10 +2186,7 @@ void TableVal::SendToStore(const Val* index, const Val* new_value, OnChangeType
|
|||
}
|
||||
}
|
||||
|
||||
IntrusivePtr<Val> TableVal::Delete(const Val* index)
|
||||
=======
|
||||
IntrusivePtr<Val> TableVal::Remove(const Val& index)
|
||||
>>>>>>> origin/master
|
||||
{
|
||||
auto k = MakeHashKey(index);
|
||||
TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k.get()) : nullptr;
|
||||
|
@ -2207,7 +2203,7 @@ IntrusivePtr<Val> TableVal::Remove(const Val& index)
|
|||
Modified();
|
||||
|
||||
if ( ! broker_store.empty() )
|
||||
SendToStore(index, nullptr, ELEMENT_REMOVED);
|
||||
SendToStore(&index, nullptr, ELEMENT_REMOVED);
|
||||
if ( change_func )
|
||||
CallChangeFunc(&index, va, ELEMENT_REMOVED);
|
||||
|
||||
|
@ -2237,14 +2233,10 @@ IntrusivePtr<Val> TableVal::Remove(const HashKey& k)
|
|||
if ( ( change_func && va ) || ( ! broker_store.empty() ) )
|
||||
{
|
||||
auto index = table_hash->RecoverVals(k);
|
||||
<<<<<<< HEAD
|
||||
if ( ! broker_store.empty() )
|
||||
SendToStore(index.get(), nullptr, ELEMENT_REMOVED);
|
||||
if ( change_func && va )
|
||||
CallChangeFunc(index.get(), va.get(), ELEMENT_REMOVED);
|
||||
=======
|
||||
CallChangeFunc(index.get(), va, ELEMENT_REMOVED);
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
|
||||
return va;
|
||||
|
|
|
@ -967,7 +967,7 @@ void Manager::ProcessStoreEvent(const broker::topic& topic, broker::data msg)
|
|||
auto data = insert.value();
|
||||
|
||||
DBG_LOG(DBG_BROKER, "Insert Data: %s:%s (%s:%s)", to_string(insert.key()).c_str(), to_string(insert.value()).c_str(), insert.key().get_type_name(), insert.value().get_type_name());
|
||||
if ( table->Type()->IsSet() && data.get_type() != broker::data::type::none )
|
||||
if ( table->GetType()->IsSet() && data.get_type() != broker::data::type::none )
|
||||
{
|
||||
reporter->Error("ProcessStoreEvent Insert got %s when expecting set", data.get_type_name());
|
||||
return;
|
||||
|
@ -978,28 +978,29 @@ void Manager::ProcessStoreEvent(const broker::topic& topic, broker::data msg)
|
|||
return;
|
||||
|
||||
// FIXME: expiry!
|
||||
assert( table->Type()->AsTableType()->IndexTypes()->length() == 1 );
|
||||
auto zeek_key = data_to_val(std::move(key), (*(table->Type()->AsTableType()->IndexTypes()))[0]);
|
||||
const auto& its = table->GetType()->AsTableType()->IndexTypes();
|
||||
assert( its.size() == 1 );
|
||||
auto zeek_key = data_to_val(std::move(key), its[0].get());
|
||||
if ( ! zeek_key )
|
||||
{
|
||||
reporter->Error("ProcessStoreEvent: failed to convert key");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( table->Type()->IsSet() )
|
||||
if ( table->GetType()->IsSet() )
|
||||
{
|
||||
table->Assign(zeek_key.get(), nullptr);
|
||||
table->Assign(zeek_key, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
// it is a table
|
||||
auto zeek_value = data_to_val(std::move(data), table->Type()->YieldType());
|
||||
auto zeek_value = data_to_val(std::move(data), table->GetType()->Yield().get());
|
||||
if ( ! zeek_value )
|
||||
{
|
||||
reporter->Error("ProcessStoreEvent: failed to convert value");
|
||||
return;
|
||||
}
|
||||
table->Assign(zeek_key.get(), zeek_value);
|
||||
table->Assign(zeek_key, zeek_value);
|
||||
}
|
||||
else if ( auto update = broker::store_event::update::make(msg) )
|
||||
{
|
||||
|
@ -1007,7 +1008,7 @@ void Manager::ProcessStoreEvent(const broker::topic& topic, broker::data msg)
|
|||
auto data = update.new_value();
|
||||
|
||||
DBG_LOG(DBG_BROKER, "Update Data: %s->%s (%s)", to_string(update.old_value()).c_str(), to_string(update.new_value()).c_str(), update.new_value().get_type_name());
|
||||
if ( table->Type()->IsSet() && data.get_type() != broker::data::type::none )
|
||||
if ( table->GetType()->IsSet() && data.get_type() != broker::data::type::none )
|
||||
{
|
||||
reporter->Error("ProcessStoreEvent Update got %s when expecting set", data.get_type_name());
|
||||
return;
|
||||
|
@ -1017,28 +1018,29 @@ void Manager::ProcessStoreEvent(const broker::topic& topic, broker::data msg)
|
|||
if ( update.publisher() == storehandle->store_pid )
|
||||
return;
|
||||
|
||||
assert( table->Type()->AsTableType()->IndexTypes()->length() == 1 );
|
||||
auto zeek_key = data_to_val(std::move(key), (*(table->Type()->AsTableType()->IndexTypes()))[0]);
|
||||
const auto& its = table->GetType()->AsTableType()->IndexTypes();
|
||||
assert( its.size() == 1 );
|
||||
auto zeek_key = data_to_val(std::move(key), its[0].get());
|
||||
if ( ! zeek_key )
|
||||
{
|
||||
reporter->Error("ProcessStoreEvent: failed to convert key");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( table->Type()->IsSet() )
|
||||
if ( table->GetType()->IsSet() )
|
||||
{
|
||||
table->Assign(zeek_key.get(), nullptr);
|
||||
table->Assign(zeek_key, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
// it is a table
|
||||
auto zeek_value = data_to_val(std::move(data), table->Type()->YieldType());
|
||||
auto zeek_value = data_to_val(std::move(data), table->GetType()->Yield().get());
|
||||
if ( ! zeek_value )
|
||||
{
|
||||
reporter->Error("ProcessStoreEvent: failed to convert value");
|
||||
return;
|
||||
}
|
||||
table->Assign(zeek_key.get(), zeek_value);
|
||||
table->Assign(zeek_key, zeek_value);
|
||||
}
|
||||
else if ( auto erase = broker::store_event::erase::make(msg) )
|
||||
{
|
||||
|
@ -1049,14 +1051,15 @@ void Manager::ProcessStoreEvent(const broker::topic& topic, broker::data msg)
|
|||
return;
|
||||
|
||||
auto key = erase.key();
|
||||
assert( table->Type()->AsTableType()->IndexTypes()->length() == 1 );
|
||||
auto zeek_key = data_to_val(std::move(key), (*(table->Type()->AsTableType()->IndexTypes()))[0]);
|
||||
const auto& its = table->GetType()->AsTableType()->IndexTypes();
|
||||
assert( its.size() == 1 );
|
||||
auto zeek_key = data_to_val(std::move(key), its[0].get());
|
||||
if ( ! zeek_key )
|
||||
{
|
||||
reporter->Error("ProcessStoreEvent: failed to convert key");
|
||||
return;
|
||||
}
|
||||
table->Delete(zeek_key.get());
|
||||
table->Remove(*zeek_key);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
class Frame;
|
||||
class Func;
|
||||
class VectorType;
|
||||
class TableVal;
|
||||
|
||||
namespace bro_broker {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue