mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 11:38:20 +00:00
Base: Clean up explicit uses of namespaces in places where they're not necessary.
This commit covers all of the common and base classes.
This commit is contained in:
parent
9f802b2a4d
commit
fe0c22c789
240 changed files with 6823 additions and 6787 deletions
|
@ -20,11 +20,11 @@ BasicThread::BasicThread()
|
|||
killed = false;
|
||||
|
||||
buf_len = STD_FMT_BUF_LEN;
|
||||
buf = (char*) zeek::util::safe_malloc(buf_len);
|
||||
buf = (char*) util::safe_malloc(buf_len);
|
||||
|
||||
strerr_buffer = nullptr;
|
||||
|
||||
name = zeek::util::copy_string(zeek::util::fmt("thread-%" PRIu64, ++thread_counter));
|
||||
name = util::copy_string(util::fmt("thread-%" PRIu64, ++thread_counter));
|
||||
|
||||
thread_mgr->AddThread(this);
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ BasicThread::~BasicThread()
|
|||
void BasicThread::SetName(const char* arg_name)
|
||||
{
|
||||
delete [] name;
|
||||
name = zeek::util::copy_string(arg_name);
|
||||
name = util::copy_string(arg_name);
|
||||
}
|
||||
|
||||
void BasicThread::SetOSName(const char* arg_name)
|
||||
{
|
||||
static_assert(std::is_same<std::thread::native_handle_type, pthread_t>::value, "libstdc++ doesn't use pthread_t");
|
||||
zeek::util::detail::set_thread_name(arg_name, thread.native_handle());
|
||||
util::detail::set_thread_name(arg_name, thread.native_handle());
|
||||
}
|
||||
|
||||
const char* BasicThread::Fmt(const char* format, ...)
|
||||
|
@ -55,7 +55,7 @@ const char* BasicThread::Fmt(const char* format, ...)
|
|||
if ( buf_len > 10 * STD_FMT_BUF_LEN )
|
||||
{
|
||||
// Shrink back to normal.
|
||||
buf = (char*) zeek::util::safe_realloc(buf, STD_FMT_BUF_LEN);
|
||||
buf = (char*) util::safe_realloc(buf, STD_FMT_BUF_LEN);
|
||||
buf_len = STD_FMT_BUF_LEN;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ const char* BasicThread::Fmt(const char* format, ...)
|
|||
if ( (unsigned int) n >= buf_len )
|
||||
{ // Not enough room, grow the buffer.
|
||||
buf_len = n + 32;
|
||||
buf = (char*) zeek::util::safe_realloc(buf, buf_len);
|
||||
buf = (char*) util::safe_realloc(buf, buf_len);
|
||||
|
||||
// Is it portable to restart?
|
||||
va_start(al, format);
|
||||
|
@ -83,7 +83,7 @@ const char* BasicThread::Strerror(int err)
|
|||
if ( ! strerr_buffer )
|
||||
strerr_buffer = new char[256];
|
||||
|
||||
zeek::util::zeek_strerror_r(err, strerr_buffer, 256);
|
||||
util::zeek_strerror_r(err, strerr_buffer, 256);
|
||||
return strerr_buffer;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ void BasicThread::Start()
|
|||
|
||||
thread = std::thread(&BasicThread::launcher, this);
|
||||
|
||||
DBG_LOG(zeek::DBG_THREADING, "Started thread %s", name);
|
||||
DBG_LOG(DBG_THREADING, "Started thread %s", name);
|
||||
|
||||
OnStart();
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ void BasicThread::SignalStop()
|
|||
if ( terminating )
|
||||
return;
|
||||
|
||||
DBG_LOG(zeek::DBG_THREADING, "Signaling thread %s to terminate ...", name);
|
||||
DBG_LOG(DBG_THREADING, "Signaling thread %s to terminate ...", name);
|
||||
|
||||
OnSignalStop();
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ void BasicThread::WaitForStop()
|
|||
if ( ! started )
|
||||
return;
|
||||
|
||||
DBG_LOG(zeek::DBG_THREADING, "Waiting for thread %s to terminate and process last queue items...", name);
|
||||
DBG_LOG(DBG_THREADING, "Waiting for thread %s to terminate and process last queue items...", name);
|
||||
|
||||
OnWaitForStop();
|
||||
|
||||
|
@ -142,10 +142,10 @@ void BasicThread::Join()
|
|||
}
|
||||
catch ( const std::system_error& e )
|
||||
{
|
||||
zeek::reporter->FatalError("Failure joining thread %s with error %s", name, e.what());
|
||||
reporter->FatalError("Failure joining thread %s with error %s", name, e.what());
|
||||
}
|
||||
|
||||
DBG_LOG(zeek::DBG_THREADING, "Joined with thread %s", name);
|
||||
DBG_LOG(DBG_THREADING, "Joined with thread %s", name);
|
||||
}
|
||||
|
||||
void BasicThread::Kill()
|
||||
|
@ -160,7 +160,7 @@ void BasicThread::Kill()
|
|||
|
||||
void BasicThread::Done()
|
||||
{
|
||||
DBG_LOG(zeek::DBG_THREADING, "Thread %s has finished", name);
|
||||
DBG_LOG(DBG_THREADING, "Thread %s has finished", name);
|
||||
|
||||
terminating = true;
|
||||
killed = true;
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
* internal formatting.
|
||||
*
|
||||
*/
|
||||
explicit Formatter(threading::MsgThread* t);
|
||||
explicit Formatter(MsgThread* t);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
|
@ -49,8 +49,8 @@ public:
|
|||
* @return Returns true on success, false on error. Errors must also
|
||||
* be flagged via the thread.
|
||||
*/
|
||||
virtual bool Describe(zeek::ODesc* desc, int num_fields, const threading::Field* const * fields,
|
||||
threading::Value** vals) const = 0;
|
||||
virtual bool Describe(ODesc* desc, int num_fields, const Field* const * fields,
|
||||
Value** vals) const = 0;
|
||||
|
||||
/**
|
||||
* Convert a single threading value into an implementation-specific
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
* @return Returns true on success, false on error. Errors are also
|
||||
* flagged via the thread.
|
||||
*/
|
||||
virtual bool Describe(zeek::ODesc* desc, threading::Value* val, const std::string& name = "") const = 0;
|
||||
virtual bool Describe(ODesc* desc, Value* val, const std::string& name = "") const = 0;
|
||||
|
||||
/**
|
||||
* Convert an implementation-specific textual representation of a
|
||||
|
@ -79,7 +79,8 @@ public:
|
|||
* @return The new value, or null on error. Errors must also be
|
||||
* flagged via the thread.
|
||||
*/
|
||||
virtual threading::Value* ParseValue(const std::string& s, const std::string& name, zeek::TypeTag type, zeek::TypeTag subtype = zeek::TYPE_ERROR) const = 0;
|
||||
virtual Value* ParseValue(const std::string& s, const std::string& name, TypeTag type,
|
||||
TypeTag subtype = TYPE_ERROR) const = 0;
|
||||
|
||||
/**
|
||||
* Convert an IP address into a string.
|
||||
|
@ -90,7 +91,7 @@ public:
|
|||
*
|
||||
* @return An ASCII representation of the address.
|
||||
*/
|
||||
static std::string Render(const threading::Value::addr_t& addr);
|
||||
static std::string Render(const Value::addr_t& addr);
|
||||
|
||||
/**
|
||||
* Convert an subnet value into a string.
|
||||
|
@ -101,7 +102,7 @@ public:
|
|||
*
|
||||
* @return An ASCII representation of the subnet.
|
||||
*/
|
||||
static std::string Render(const threading::Value::subnet_t& subnet);
|
||||
static std::string Render(const Value::subnet_t& subnet);
|
||||
|
||||
/**
|
||||
* Convert a double into a string. This renders the double with Bro's
|
||||
|
@ -149,17 +150,17 @@ public:
|
|||
* @return The address, which will be all-zero on error. Errors are
|
||||
* also flagged via the thread.
|
||||
*/
|
||||
threading::Value::addr_t ParseAddr(const std::string &addr) const;
|
||||
Value::addr_t ParseAddr(const std::string &addr) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Returns the thread associated with the formatter via the
|
||||
* constructor.
|
||||
*/
|
||||
threading::MsgThread* GetThread() const { return thread; }
|
||||
MsgThread* GetThread() const { return thread; }
|
||||
|
||||
private:
|
||||
threading::MsgThread* thread;
|
||||
MsgThread* thread;
|
||||
};
|
||||
|
||||
} // namespace zeek::threading
|
||||
|
|
|
@ -25,7 +25,7 @@ void HeartbeatTimer::Dispatch(double t, bool is_expire)
|
|||
|
||||
Manager::Manager()
|
||||
{
|
||||
DBG_LOG(zeek::DBG_THREADING, "Creating thread manager ...");
|
||||
DBG_LOG(DBG_THREADING, "Creating thread manager ...");
|
||||
|
||||
did_process = true;
|
||||
next_beat = 0;
|
||||
|
@ -40,7 +40,7 @@ Manager::~Manager()
|
|||
|
||||
void Manager::Terminate()
|
||||
{
|
||||
DBG_LOG(zeek::DBG_THREADING, "Terminating thread manager ...");
|
||||
DBG_LOG(DBG_THREADING, "Terminating thread manager ...");
|
||||
terminating = true;
|
||||
|
||||
// First process remaining thread output for the message threads.
|
||||
|
@ -68,7 +68,7 @@ void Manager::Terminate()
|
|||
|
||||
void Manager::AddThread(BasicThread* thread)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_THREADING, "Adding thread %s ...", thread->Name());
|
||||
DBG_LOG(DBG_THREADING, "Adding thread %s ...", thread->Name());
|
||||
all_threads.push_back(thread);
|
||||
|
||||
if ( ! heartbeat_timer_running )
|
||||
|
@ -77,13 +77,13 @@ void Manager::AddThread(BasicThread* thread)
|
|||
|
||||
void Manager::AddMsgThread(MsgThread* thread)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_THREADING, "%s is a MsgThread ...", thread->Name());
|
||||
DBG_LOG(DBG_THREADING, "%s is a MsgThread ...", thread->Name());
|
||||
msg_threads.push_back(thread);
|
||||
}
|
||||
|
||||
void Manager::KillThreads()
|
||||
{
|
||||
DBG_LOG(zeek::DBG_THREADING, "Killing threads ...");
|
||||
DBG_LOG(DBG_THREADING, "Killing threads ...");
|
||||
|
||||
for ( all_thread_list::iterator i = all_threads.begin(); i != all_threads.end(); i++ )
|
||||
(*i)->Kill();
|
||||
|
@ -91,7 +91,7 @@ void Manager::KillThreads()
|
|||
|
||||
void Manager::KillThread(BasicThread* thread)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_THREADING, "Killing thread %s ...", thread->Name());
|
||||
DBG_LOG(DBG_THREADING, "Killing thread %s ...", thread->Name());
|
||||
thread->Kill();
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ void Manager::SendHeartbeats()
|
|||
void Manager::StartHeartbeatTimer()
|
||||
{
|
||||
heartbeat_timer_running = true;
|
||||
zeek::detail::timer_mgr->Add(new detail::HeartbeatTimer(zeek::run_state::network_time + zeek::BifConst::Threading::heartbeat_interval));
|
||||
zeek::detail::timer_mgr->Add(new detail::HeartbeatTimer(run_state::network_time + BifConst::Threading::heartbeat_interval));
|
||||
}
|
||||
|
||||
// Raise everything in here as warnings so it is passed to scriptland without
|
||||
|
@ -139,16 +139,16 @@ void Manager::StartHeartbeatTimer()
|
|||
// one reporter message.
|
||||
bool Manager::SendEvent(MsgThread* thread, const std::string& name, const int num_vals, Value* *vals) const
|
||||
{
|
||||
zeek::EventHandler* handler = zeek::event_registry->Lookup(name);
|
||||
EventHandler* handler = event_registry->Lookup(name);
|
||||
if ( handler == nullptr )
|
||||
{
|
||||
zeek::reporter->Warning("Thread %s: Event %s not found", thread->Name(), name.c_str());
|
||||
reporter->Warning("Thread %s: Event %s not found", thread->Name(), name.c_str());
|
||||
Value::delete_value_ptr_array(vals, num_vals);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
DBG_LOG(zeek::DBG_INPUT, "Thread %s: SendEvent for event %s with %d vals",
|
||||
DBG_LOG(DBG_INPUT, "Thread %s: SendEvent for event %s with %d vals",
|
||||
thread->Name(), name.c_str(), num_vals);
|
||||
#endif
|
||||
|
||||
|
@ -156,20 +156,20 @@ bool Manager::SendEvent(MsgThread* thread, const std::string& name, const int nu
|
|||
int num_event_vals = type->NumFields();
|
||||
if ( num_vals != num_event_vals )
|
||||
{
|
||||
zeek::reporter->Warning("Thread %s: Wrong number of values for event %s", thread->Name(), name.c_str());
|
||||
reporter->Warning("Thread %s: Wrong number of values for event %s", thread->Name(), name.c_str());
|
||||
Value::delete_value_ptr_array(vals, num_vals);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool convert_error = false;
|
||||
|
||||
zeek::Args vl;
|
||||
Args vl;
|
||||
vl.reserve(num_vals);
|
||||
|
||||
for ( int j = 0; j < num_vals; j++)
|
||||
{
|
||||
zeek::Val* v = Value::ValueToVal(std::string("thread ") + thread->Name(), vals[j], convert_error);
|
||||
vl.emplace_back(zeek::AdoptRef{}, v);
|
||||
Val* v = Value::ValueToVal(std::string("thread ") + thread->Name(), vals[j], convert_error);
|
||||
vl.emplace_back(AdoptRef{}, v);
|
||||
|
||||
if ( v && ! convert_error && ! same_type(type->GetFieldType(j), v->GetType()) )
|
||||
{
|
||||
|
@ -183,7 +183,7 @@ bool Manager::SendEvent(MsgThread* thread, const std::string& name, const int nu
|
|||
if ( convert_error )
|
||||
return false;
|
||||
else if ( handler )
|
||||
zeek::event_mgr.Enqueue(handler, std::move(vl), zeek::util::detail::SOURCE_LOCAL);
|
||||
event_mgr.Enqueue(handler, std::move(vl), util::detail::SOURCE_LOCAL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -192,10 +192,10 @@ void Manager::Flush()
|
|||
{
|
||||
bool do_beat = false;
|
||||
|
||||
if ( zeek::run_state::network_time && (zeek::run_state::network_time > next_beat || ! next_beat) )
|
||||
if ( run_state::network_time && (run_state::network_time > next_beat || ! next_beat) )
|
||||
{
|
||||
do_beat = true;
|
||||
next_beat = ::zeek::run_state::network_time + zeek::BifConst::Threading::heartbeat_interval;
|
||||
next_beat = run_state::network_time + BifConst::Threading::heartbeat_interval;
|
||||
}
|
||||
|
||||
did_process = false;
|
||||
|
@ -214,13 +214,13 @@ void Manager::Flush()
|
|||
|
||||
if ( msg->Process() )
|
||||
{
|
||||
if ( zeek::run_state::network_time )
|
||||
if ( run_state::network_time )
|
||||
did_process = true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
zeek::reporter->Error("%s failed, terminating thread", msg->Name());
|
||||
reporter->Error("%s failed, terminating thread", msg->Name());
|
||||
t->SignalStop();
|
||||
}
|
||||
|
||||
|
@ -254,8 +254,8 @@ void Manager::Flush()
|
|||
delete t;
|
||||
}
|
||||
|
||||
// fprintf(stderr, "P %.6f %.6f do_beat=%d did_process=%d next_next=%.6f\n", zeek::run_state::network_time,
|
||||
// zeek::detail::timer_mgr->Time(), do_beat, (int)did_process, next_beat);
|
||||
// fprintf(stderr, "P %.6f %.6f do_beat=%d did_process=%d next_next=%.6f\n", run_state::network_time,
|
||||
// detail::timer_mgr->Time(), do_beat, (int)did_process, next_beat);
|
||||
}
|
||||
|
||||
const threading::Manager::msg_stats_list& threading::Manager::GetMsgThreadStats()
|
||||
|
|
|
@ -102,7 +102,7 @@ public:
|
|||
* @param vals Values passed to the event
|
||||
* @returns True on success false on failure.
|
||||
*/
|
||||
bool SendEvent(MsgThread* thread, const std::string& name, const int num_vals, threading::Value* *vals) const;
|
||||
bool SendEvent(MsgThread* thread, const std::string& name, const int num_vals, Value* *vals) const;
|
||||
|
||||
protected:
|
||||
friend class BasicThread;
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
|
||||
ReporterMessage(Type arg_type, MsgThread* thread, const char* arg_msg)
|
||||
: OutputMessage<MsgThread>("ReporterMessage", thread)
|
||||
{ type = arg_type; msg = zeek::util::copy_string(arg_msg); }
|
||||
{ type = arg_type; msg = util::copy_string(arg_msg); }
|
||||
|
||||
~ReporterMessage() override { delete [] msg; }
|
||||
|
||||
|
@ -110,9 +110,9 @@ public:
|
|||
class DebugMessage final : public OutputMessage<MsgThread>
|
||||
{
|
||||
public:
|
||||
DebugMessage(zeek::DebugStream arg_stream, MsgThread* thread, const char* arg_msg)
|
||||
DebugMessage(DebugStream arg_stream, MsgThread* thread, const char* arg_msg)
|
||||
: OutputMessage<MsgThread>("DebugMessage", thread)
|
||||
{ stream = arg_stream; msg = zeek::util::copy_string(arg_msg); }
|
||||
{ stream = arg_stream; msg = util::copy_string(arg_msg); }
|
||||
|
||||
~DebugMessage() override { delete [] msg; }
|
||||
|
||||
|
@ -123,7 +123,7 @@ public:
|
|||
}
|
||||
private:
|
||||
const char* msg;
|
||||
zeek::DebugStream stream;
|
||||
DebugStream stream;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -132,7 +132,7 @@ class SendEventMessage final : public OutputMessage<MsgThread> {
|
|||
public:
|
||||
SendEventMessage(MsgThread* thread, const char* name, const int num_vals, Value* *val)
|
||||
: OutputMessage<MsgThread>("SendEvent", thread),
|
||||
name(zeek::util::copy_string(name)), num_vals(num_vals), val(val) {}
|
||||
name(util::copy_string(name)), num_vals(num_vals), val(val) {}
|
||||
|
||||
~SendEventMessage() override { delete [] name; }
|
||||
|
||||
|
@ -141,7 +141,7 @@ public:
|
|||
bool success = thread_mgr->SendEvent(Object(), name, num_vals, val);
|
||||
|
||||
if ( ! success )
|
||||
zeek::reporter->Error("SendEvent for event %s failed", name);
|
||||
reporter->Error("SendEvent for event %s failed", name);
|
||||
|
||||
return true; // We do not want to die if sendEvent fails because the event did not return.
|
||||
}
|
||||
|
@ -157,35 +157,35 @@ bool ReporterMessage::Process()
|
|||
switch ( type ) {
|
||||
|
||||
case INFO:
|
||||
zeek::reporter->Info("%s: %s", Object()->Name(), msg);
|
||||
reporter->Info("%s: %s", Object()->Name(), msg);
|
||||
break;
|
||||
|
||||
case WARNING:
|
||||
zeek::reporter->Warning("%s: %s", Object()->Name(), msg);
|
||||
reporter->Warning("%s: %s", Object()->Name(), msg);
|
||||
break;
|
||||
|
||||
case ERROR:
|
||||
zeek::reporter->Error("%s: %s", Object()->Name(), msg);
|
||||
reporter->Error("%s: %s", Object()->Name(), msg);
|
||||
break;
|
||||
|
||||
case FATAL_ERROR:
|
||||
zeek::reporter->FatalError("%s: %s", Object()->Name(), msg);
|
||||
reporter->FatalError("%s: %s", Object()->Name(), msg);
|
||||
break;
|
||||
|
||||
case FATAL_ERROR_WITH_CORE:
|
||||
zeek::reporter->FatalErrorWithCore("%s: %s", Object()->Name(), msg);
|
||||
reporter->FatalErrorWithCore("%s: %s", Object()->Name(), msg);
|
||||
break;
|
||||
|
||||
case INTERNAL_WARNING:
|
||||
zeek::reporter->InternalWarning("%s: %s", Object()->Name(), msg);
|
||||
reporter->InternalWarning("%s: %s", Object()->Name(), msg);
|
||||
break;
|
||||
|
||||
case INTERNAL_ERROR :
|
||||
zeek::reporter->InternalError("%s: %s", Object()->Name(), msg);
|
||||
reporter->InternalError("%s: %s", Object()->Name(), msg);
|
||||
break;
|
||||
|
||||
default:
|
||||
zeek::reporter->InternalError("unknown ReporterMessage type %d", type);
|
||||
reporter->InternalError("unknown ReporterMessage type %d", type);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -209,8 +209,8 @@ MsgThread::MsgThread() : BasicThread(), queue_in(this, nullptr), queue_out(nullp
|
|||
failed = false;
|
||||
thread_mgr->AddMsgThread(this);
|
||||
|
||||
if ( ! zeek::iosource_mgr->RegisterFd(flare.FD(), this) )
|
||||
zeek::reporter->FatalError("Failed to register MsgThread fd with iosource_mgr");
|
||||
if ( ! iosource_mgr->RegisterFd(flare.FD(), this) )
|
||||
reporter->FatalError("Failed to register MsgThread fd with iosource_mgr");
|
||||
|
||||
SetClosed(false);
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ MsgThread::~MsgThread()
|
|||
{
|
||||
// Unregister this thread from the iosource manager so it doesn't wake
|
||||
// up the main poll anymore.
|
||||
zeek::iosource_mgr->UnregisterFd(flare.FD(), this);
|
||||
iosource_mgr->UnregisterFd(flare.FD(), this);
|
||||
}
|
||||
|
||||
void MsgThread::OnSignalStop()
|
||||
|
@ -229,7 +229,7 @@ void MsgThread::OnSignalStop()
|
|||
|
||||
child_sent_finish = true;
|
||||
// Signal thread to terminate.
|
||||
SendIn(new detail::FinishMessage(this, zeek::run_state::network_time), true);
|
||||
SendIn(new detail::FinishMessage(this, run_state::network_time), true);
|
||||
}
|
||||
|
||||
void MsgThread::OnWaitForStop()
|
||||
|
@ -276,7 +276,7 @@ void MsgThread::OnWaitForStop()
|
|||
assert ( msg );
|
||||
|
||||
if ( ! msg->Process() )
|
||||
zeek::reporter->Error("%s failed during thread termination", msg->Name());
|
||||
reporter->Error("%s failed during thread termination", msg->Name());
|
||||
|
||||
delete msg;
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ void MsgThread::Heartbeat()
|
|||
if ( child_sent_finish )
|
||||
return;
|
||||
|
||||
SendIn(new detail::HeartbeatMessage(this, zeek::run_state::network_time, zeek::util::current_time()));
|
||||
SendIn(new detail::HeartbeatMessage(this, run_state::network_time, util::current_time()));
|
||||
}
|
||||
|
||||
void MsgThread::Finished()
|
||||
|
@ -351,7 +351,7 @@ void MsgThread::InternalError(const char* msg)
|
|||
|
||||
#ifdef DEBUG
|
||||
|
||||
void MsgThread::Debug(zeek::DebugStream stream, const char* msg)
|
||||
void MsgThread::Debug(DebugStream stream, const char* msg)
|
||||
{
|
||||
SendOut(new detail::DebugMessage(stream, this, msg));
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ void MsgThread::SendIn(BasicInputMessage* msg, bool force)
|
|||
return;
|
||||
}
|
||||
|
||||
DBG_LOG(zeek::DBG_THREADING, "Sending '%s' to %s ...", msg->Name(), Name());
|
||||
DBG_LOG(DBG_THREADING, "Sending '%s' to %s ...", msg->Name(), Name());
|
||||
|
||||
queue_in.Put(msg);
|
||||
++cnt_sent_in;
|
||||
|
@ -399,7 +399,7 @@ BasicOutputMessage* MsgThread::RetrieveOut()
|
|||
if ( ! msg )
|
||||
return nullptr;
|
||||
|
||||
DBG_LOG(zeek::DBG_THREADING, "Retrieved '%s' from %s", msg->Name(), Name());
|
||||
DBG_LOG(DBG_THREADING, "Retrieved '%s' from %s", msg->Name(), Name());
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
@ -413,7 +413,7 @@ BasicInputMessage* MsgThread::RetrieveIn()
|
|||
|
||||
#ifdef DEBUG
|
||||
std::string s = Fmt("Retrieved '%s' in %s", msg->Name(), Name());
|
||||
Debug(zeek::DBG_THREADING, s.c_str());
|
||||
Debug(DBG_THREADING, s.c_str());
|
||||
#endif
|
||||
|
||||
return msg;
|
||||
|
@ -450,7 +450,7 @@ void MsgThread::Run()
|
|||
// anymore.
|
||||
if ( ! child_finished && ! Killed() )
|
||||
{
|
||||
OnFinish(zeek::run_state::network_time);
|
||||
OnFinish(run_state::network_time);
|
||||
Finished();
|
||||
}
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ void MsgThread::Process()
|
|||
|
||||
if ( ! msg->Process() )
|
||||
{
|
||||
zeek::reporter->Error("%s failed, terminating thread", msg->Name());
|
||||
reporter->Error("%s failed, terminating thread", msg->Name());
|
||||
SignalStop();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class KillMeMessage;
|
|||
* that happens, the thread stops accepting any new messages, finishes
|
||||
* processes all remaining ones still in the queue, and then exits.
|
||||
*/
|
||||
class MsgThread : public BasicThread, public zeek::iosource::IOSource
|
||||
class MsgThread : public BasicThread, public iosource::IOSource
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -88,7 +88,7 @@ public:
|
|||
*
|
||||
* @param vals the values to be given to the event
|
||||
*/
|
||||
void SendEvent(const char* name, const int num_vals, threading::Value* *vals);
|
||||
void SendEvent(const char* name, const int num_vals, Value* *vals);
|
||||
|
||||
/**
|
||||
* Reports an informational message from the child thread. The main
|
||||
|
@ -186,7 +186,7 @@ public:
|
|||
*
|
||||
* @param msg The message. It will be prefixed with the thread's name.
|
||||
*/
|
||||
void Debug(zeek::DebugStream stream, const char* msg);
|
||||
void Debug(DebugStream stream, const char* msg);
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -386,7 +386,7 @@ protected:
|
|||
* mainly for debugging purposes.
|
||||
*/
|
||||
explicit Message(const char* arg_name)
|
||||
{ name = zeek::util::copy_string(arg_name); }
|
||||
{ name = util::copy_string(arg_name); }
|
||||
|
||||
private:
|
||||
const char* name;
|
||||
|
|
|
@ -127,7 +127,7 @@ inline static std::unique_lock<std::mutex> acquire_lock(std::mutex& m)
|
|||
}
|
||||
catch ( const std::system_error& e )
|
||||
{
|
||||
zeek::reporter->FatalErrorWithCore("cannot lock mutex: %s", e.what());
|
||||
reporter->FatalErrorWithCore("cannot lock mutex: %s", e.what());
|
||||
// Never gets here.
|
||||
throw std::exception();
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ inline std::vector<std::unique_lock<std::mutex>> Queue<T>::LocksForAllQueues()
|
|||
|
||||
catch ( const std::system_error& e )
|
||||
{
|
||||
zeek::reporter->FatalErrorWithCore("cannot lock all mutexes: %s", e.what());
|
||||
reporter->FatalErrorWithCore("cannot lock all mutexes: %s", e.what());
|
||||
// Never gets here.
|
||||
throw std::exception();
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
namespace zeek::threading {
|
||||
|
||||
bool Field::Read(zeek::detail::SerializationFormat* fmt)
|
||||
bool Field::Read(detail::SerializationFormat* fmt)
|
||||
{
|
||||
int t;
|
||||
int st;
|
||||
|
@ -32,7 +32,7 @@ bool Field::Read(zeek::detail::SerializationFormat* fmt)
|
|||
if ( ! fmt->Read(&tmp_secondary_name, "secondary_name") )
|
||||
return false;
|
||||
|
||||
secondary_name = zeek::util::copy_string(tmp_secondary_name.c_str());
|
||||
secondary_name = util::copy_string(tmp_secondary_name.c_str());
|
||||
}
|
||||
else
|
||||
secondary_name = nullptr;
|
||||
|
@ -45,15 +45,15 @@ bool Field::Read(zeek::detail::SerializationFormat* fmt)
|
|||
if ( ! success )
|
||||
return false;
|
||||
|
||||
name = zeek::util::copy_string(tmp_name.c_str());
|
||||
name = util::copy_string(tmp_name.c_str());
|
||||
|
||||
type = static_cast<zeek::TypeTag>(t);
|
||||
subtype = static_cast<zeek::TypeTag>(st);
|
||||
type = static_cast<TypeTag>(t);
|
||||
subtype = static_cast<TypeTag>(st);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Field::Write(zeek::detail::SerializationFormat* fmt) const
|
||||
bool Field::Write(detail::SerializationFormat* fmt) const
|
||||
{
|
||||
assert(name);
|
||||
|
||||
|
@ -79,15 +79,15 @@ std::string Field::TypeName() const
|
|||
|
||||
// We do not support tables, if the internal Bro type is table it
|
||||
// always is a set.
|
||||
if ( type == zeek::TYPE_TABLE )
|
||||
if ( type == TYPE_TABLE )
|
||||
n = "set";
|
||||
else
|
||||
n = zeek::type_name(type);
|
||||
n = type_name(type);
|
||||
|
||||
if ( (type == zeek::TYPE_TABLE) || (type == zeek::TYPE_VECTOR) )
|
||||
if ( (type == TYPE_TABLE) || (type == TYPE_VECTOR) )
|
||||
{
|
||||
n += "[";
|
||||
n += zeek::type_name(subtype);
|
||||
n += type_name(subtype);
|
||||
n += "]";
|
||||
}
|
||||
|
||||
|
@ -99,13 +99,13 @@ Value::~Value()
|
|||
if ( ! present )
|
||||
return;
|
||||
|
||||
if ( type == zeek::TYPE_ENUM || type == zeek::TYPE_STRING || type == zeek::TYPE_FILE || type == zeek::TYPE_FUNC )
|
||||
if ( type == TYPE_ENUM || type == TYPE_STRING || type == TYPE_FILE || type == TYPE_FUNC )
|
||||
delete [] val.string_val.data;
|
||||
|
||||
else if ( type == zeek::TYPE_PATTERN )
|
||||
else if ( type == TYPE_PATTERN )
|
||||
delete [] val.pattern_text_val;
|
||||
|
||||
else if ( type == zeek::TYPE_TABLE )
|
||||
else if ( type == TYPE_TABLE )
|
||||
{
|
||||
for ( bro_int_t i = 0; i < val.set_val.size; i++ )
|
||||
delete val.set_val.vals[i];
|
||||
|
@ -113,7 +113,7 @@ Value::~Value()
|
|||
delete [] val.set_val.vals;
|
||||
}
|
||||
|
||||
else if ( type == zeek::TYPE_VECTOR )
|
||||
else if ( type == TYPE_VECTOR )
|
||||
{
|
||||
for ( bro_int_t i = 0; i < val.vector_val.size; i++ )
|
||||
delete val.vector_val.vals[i];
|
||||
|
@ -122,31 +122,31 @@ Value::~Value()
|
|||
}
|
||||
}
|
||||
|
||||
bool Value::IsCompatibleType(zeek::Type* t, bool atomic_only)
|
||||
bool Value::IsCompatibleType(Type* t, bool atomic_only)
|
||||
{
|
||||
if ( ! t )
|
||||
return false;
|
||||
|
||||
switch ( t->Tag() ) {
|
||||
case zeek::TYPE_BOOL:
|
||||
case zeek::TYPE_INT:
|
||||
case zeek::TYPE_COUNT:
|
||||
case zeek::TYPE_PORT:
|
||||
case zeek::TYPE_SUBNET:
|
||||
case zeek::TYPE_ADDR:
|
||||
case zeek::TYPE_DOUBLE:
|
||||
case zeek::TYPE_TIME:
|
||||
case zeek::TYPE_INTERVAL:
|
||||
case zeek::TYPE_ENUM:
|
||||
case zeek::TYPE_STRING:
|
||||
case zeek::TYPE_FILE:
|
||||
case zeek::TYPE_FUNC:
|
||||
case TYPE_BOOL:
|
||||
case TYPE_INT:
|
||||
case TYPE_COUNT:
|
||||
case TYPE_PORT:
|
||||
case TYPE_SUBNET:
|
||||
case TYPE_ADDR:
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_TIME:
|
||||
case TYPE_INTERVAL:
|
||||
case TYPE_ENUM:
|
||||
case TYPE_STRING:
|
||||
case TYPE_FILE:
|
||||
case TYPE_FUNC:
|
||||
return true;
|
||||
|
||||
case zeek::TYPE_RECORD:
|
||||
case TYPE_RECORD:
|
||||
return ! atomic_only;
|
||||
|
||||
case zeek::TYPE_TABLE:
|
||||
case TYPE_TABLE:
|
||||
{
|
||||
if ( atomic_only )
|
||||
return false;
|
||||
|
@ -157,7 +157,7 @@ bool Value::IsCompatibleType(zeek::Type* t, bool atomic_only)
|
|||
return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true);
|
||||
}
|
||||
|
||||
case zeek::TYPE_VECTOR:
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
if ( atomic_only )
|
||||
return false;
|
||||
|
@ -172,28 +172,28 @@ bool Value::IsCompatibleType(zeek::Type* t, bool atomic_only)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Value::Read(zeek::detail::SerializationFormat* fmt)
|
||||
bool Value::Read(detail::SerializationFormat* fmt)
|
||||
{
|
||||
int ty, sty;
|
||||
|
||||
if ( ! (fmt->Read(&ty, "type") && fmt->Read(&sty, "subtype") && fmt->Read(&present, "present")) )
|
||||
return false;
|
||||
|
||||
type = static_cast<zeek::TypeTag>(ty);
|
||||
subtype = static_cast<zeek::TypeTag>(sty);
|
||||
type = static_cast<TypeTag>(ty);
|
||||
subtype = static_cast<TypeTag>(sty);
|
||||
|
||||
if ( ! present )
|
||||
return true;
|
||||
|
||||
switch ( type ) {
|
||||
case zeek::TYPE_BOOL:
|
||||
case zeek::TYPE_INT:
|
||||
case TYPE_BOOL:
|
||||
case TYPE_INT:
|
||||
return fmt->Read(&val.int_val, "int");
|
||||
|
||||
case zeek::TYPE_COUNT:
|
||||
case TYPE_COUNT:
|
||||
return fmt->Read(&val.uint_val, "uint");
|
||||
|
||||
case zeek::TYPE_PORT: {
|
||||
case TYPE_PORT: {
|
||||
int proto;
|
||||
if ( ! (fmt->Read(&val.port_val.port, "port") && fmt->Read(&proto, "proto") ) ) {
|
||||
return false;
|
||||
|
@ -219,7 +219,7 @@ bool Value::Read(zeek::detail::SerializationFormat* fmt)
|
|||
return true;
|
||||
}
|
||||
|
||||
case zeek::TYPE_ADDR:
|
||||
case TYPE_ADDR:
|
||||
{
|
||||
char family;
|
||||
|
||||
|
@ -241,7 +241,7 @@ bool Value::Read(zeek::detail::SerializationFormat* fmt)
|
|||
abort();
|
||||
}
|
||||
|
||||
case zeek::TYPE_SUBNET:
|
||||
case TYPE_SUBNET:
|
||||
{
|
||||
char length;
|
||||
char family;
|
||||
|
@ -266,18 +266,18 @@ bool Value::Read(zeek::detail::SerializationFormat* fmt)
|
|||
abort();
|
||||
}
|
||||
|
||||
case zeek::TYPE_DOUBLE:
|
||||
case zeek::TYPE_TIME:
|
||||
case zeek::TYPE_INTERVAL:
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_TIME:
|
||||
case TYPE_INTERVAL:
|
||||
return fmt->Read(&val.double_val, "double");
|
||||
|
||||
case zeek::TYPE_ENUM:
|
||||
case zeek::TYPE_STRING:
|
||||
case zeek::TYPE_FILE:
|
||||
case zeek::TYPE_FUNC:
|
||||
case TYPE_ENUM:
|
||||
case TYPE_STRING:
|
||||
case TYPE_FILE:
|
||||
case TYPE_FUNC:
|
||||
return fmt->Read(&val.string_val.data, &val.string_val.length, "string");
|
||||
|
||||
case zeek::TYPE_TABLE:
|
||||
case TYPE_TABLE:
|
||||
{
|
||||
if ( ! fmt->Read(&val.set_val.size, "set_size") )
|
||||
return false;
|
||||
|
@ -295,7 +295,7 @@ bool Value::Read(zeek::detail::SerializationFormat* fmt)
|
|||
return true;
|
||||
}
|
||||
|
||||
case zeek::TYPE_VECTOR:
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
if ( ! fmt->Read(&val.vector_val.size, "vector_size") )
|
||||
return false;
|
||||
|
@ -314,14 +314,14 @@ bool Value::Read(zeek::detail::SerializationFormat* fmt)
|
|||
}
|
||||
|
||||
default:
|
||||
zeek::reporter->InternalError("unsupported type %s in Value::Read",
|
||||
zeek::type_name(type));
|
||||
reporter->InternalError("unsupported type %s in Value::Read",
|
||||
type_name(type));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Value::Write(zeek::detail::SerializationFormat* fmt) const
|
||||
bool Value::Write(detail::SerializationFormat* fmt) const
|
||||
{
|
||||
if ( ! (fmt->Write((int)type, "type") &&
|
||||
fmt->Write((int)subtype, "subtype") &&
|
||||
|
@ -332,17 +332,17 @@ bool Value::Write(zeek::detail::SerializationFormat* fmt) const
|
|||
return true;
|
||||
|
||||
switch ( type ) {
|
||||
case zeek::TYPE_BOOL:
|
||||
case zeek::TYPE_INT:
|
||||
case TYPE_BOOL:
|
||||
case TYPE_INT:
|
||||
return fmt->Write(val.int_val, "int");
|
||||
|
||||
case zeek::TYPE_COUNT:
|
||||
case TYPE_COUNT:
|
||||
return fmt->Write(val.uint_val, "uint");
|
||||
|
||||
case zeek::TYPE_PORT:
|
||||
case TYPE_PORT:
|
||||
return fmt->Write(val.port_val.port, "port") && fmt->Write(val.port_val.proto, "proto");
|
||||
|
||||
case zeek::TYPE_ADDR:
|
||||
case TYPE_ADDR:
|
||||
{
|
||||
switch ( val.addr_val.family ) {
|
||||
case IPv4:
|
||||
|
@ -358,7 +358,7 @@ bool Value::Write(zeek::detail::SerializationFormat* fmt) const
|
|||
abort();
|
||||
}
|
||||
|
||||
case zeek::TYPE_SUBNET:
|
||||
case TYPE_SUBNET:
|
||||
{
|
||||
if ( ! fmt->Write((char)val.subnet_val.length, "subnet-length") )
|
||||
return false;
|
||||
|
@ -377,18 +377,18 @@ bool Value::Write(zeek::detail::SerializationFormat* fmt) const
|
|||
abort();
|
||||
}
|
||||
|
||||
case zeek::TYPE_DOUBLE:
|
||||
case zeek::TYPE_TIME:
|
||||
case zeek::TYPE_INTERVAL:
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_TIME:
|
||||
case TYPE_INTERVAL:
|
||||
return fmt->Write(val.double_val, "double");
|
||||
|
||||
case zeek::TYPE_ENUM:
|
||||
case zeek::TYPE_STRING:
|
||||
case zeek::TYPE_FILE:
|
||||
case zeek::TYPE_FUNC:
|
||||
case TYPE_ENUM:
|
||||
case TYPE_STRING:
|
||||
case TYPE_FILE:
|
||||
case TYPE_FUNC:
|
||||
return fmt->Write(val.string_val.data, val.string_val.length, "string");
|
||||
|
||||
case zeek::TYPE_TABLE:
|
||||
case TYPE_TABLE:
|
||||
{
|
||||
if ( ! fmt->Write(val.set_val.size, "set_size") )
|
||||
return false;
|
||||
|
@ -402,7 +402,7 @@ bool Value::Write(zeek::detail::SerializationFormat* fmt) const
|
|||
return true;
|
||||
}
|
||||
|
||||
case zeek::TYPE_VECTOR:
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
if ( ! fmt->Write(val.vector_val.size, "vector_size") )
|
||||
return false;
|
||||
|
@ -417,8 +417,8 @@ bool Value::Write(zeek::detail::SerializationFormat* fmt) const
|
|||
}
|
||||
|
||||
default:
|
||||
zeek::reporter->InternalError("unsupported type %s in Value::Write",
|
||||
zeek::type_name(type));
|
||||
reporter->InternalError("unsupported type %s in Value::Write",
|
||||
type_name(type));
|
||||
}
|
||||
|
||||
// unreachable
|
||||
|
@ -433,7 +433,7 @@ void Value::delete_value_ptr_array(Value** vals, int num_fields)
|
|||
delete [] vals;
|
||||
}
|
||||
|
||||
zeek::Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_error)
|
||||
Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_error)
|
||||
{
|
||||
if ( have_error )
|
||||
return nullptr;
|
||||
|
@ -442,107 +442,107 @@ zeek::Val* Value::ValueToVal(const std::string& source, const Value* val, bool&
|
|||
return nullptr; // unset field
|
||||
|
||||
switch ( val->type ) {
|
||||
case zeek::TYPE_BOOL:
|
||||
return zeek::val_mgr->Bool(val->val.int_val)->Ref();
|
||||
case TYPE_BOOL:
|
||||
return val_mgr->Bool(val->val.int_val)->Ref();
|
||||
|
||||
case zeek::TYPE_INT:
|
||||
return zeek::val_mgr->Int(val->val.int_val).release();
|
||||
case TYPE_INT:
|
||||
return val_mgr->Int(val->val.int_val).release();
|
||||
|
||||
case zeek::TYPE_COUNT:
|
||||
return zeek::val_mgr->Count(val->val.int_val).release();
|
||||
case TYPE_COUNT:
|
||||
return val_mgr->Count(val->val.int_val).release();
|
||||
|
||||
case zeek::TYPE_DOUBLE:
|
||||
return new zeek::DoubleVal(val->val.double_val);
|
||||
case TYPE_DOUBLE:
|
||||
return new DoubleVal(val->val.double_val);
|
||||
|
||||
case zeek::TYPE_TIME:
|
||||
return new zeek::TimeVal(val->val.double_val);
|
||||
case TYPE_TIME:
|
||||
return new TimeVal(val->val.double_val);
|
||||
|
||||
case zeek::TYPE_INTERVAL:
|
||||
return new zeek::IntervalVal(val->val.double_val);
|
||||
case TYPE_INTERVAL:
|
||||
return new IntervalVal(val->val.double_val);
|
||||
|
||||
case zeek::TYPE_STRING:
|
||||
case TYPE_STRING:
|
||||
{
|
||||
auto* s = new zeek::String((const u_char*)val->val.string_val.data, val->val.string_val.length, true);
|
||||
return new zeek::StringVal(s);
|
||||
auto* s = new String((const u_char*)val->val.string_val.data, val->val.string_val.length, true);
|
||||
return new StringVal(s);
|
||||
}
|
||||
|
||||
case zeek::TYPE_PORT:
|
||||
return zeek::val_mgr->Port(val->val.port_val.port, val->val.port_val.proto)->Ref();
|
||||
case TYPE_PORT:
|
||||
return val_mgr->Port(val->val.port_val.port, val->val.port_val.proto)->Ref();
|
||||
|
||||
case zeek::TYPE_ADDR:
|
||||
case TYPE_ADDR:
|
||||
{
|
||||
zeek::IPAddr* addr = nullptr;
|
||||
IPAddr* addr = nullptr;
|
||||
switch ( val->val.addr_val.family ) {
|
||||
case IPv4:
|
||||
addr = new zeek::IPAddr(val->val.addr_val.in.in4);
|
||||
addr = new IPAddr(val->val.addr_val.in.in4);
|
||||
break;
|
||||
|
||||
case IPv6:
|
||||
addr = new zeek::IPAddr(val->val.addr_val.in.in6);
|
||||
addr = new IPAddr(val->val.addr_val.in.in6);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
auto* addrval = new zeek::AddrVal(*addr);
|
||||
auto* addrval = new AddrVal(*addr);
|
||||
delete addr;
|
||||
return addrval;
|
||||
}
|
||||
|
||||
case zeek::TYPE_SUBNET:
|
||||
case TYPE_SUBNET:
|
||||
{
|
||||
zeek::IPAddr* addr = nullptr;
|
||||
IPAddr* addr = nullptr;
|
||||
switch ( val->val.subnet_val.prefix.family ) {
|
||||
case IPv4:
|
||||
addr = new zeek::IPAddr(val->val.subnet_val.prefix.in.in4);
|
||||
addr = new IPAddr(val->val.subnet_val.prefix.in.in4);
|
||||
break;
|
||||
|
||||
case IPv6:
|
||||
addr = new zeek::IPAddr(val->val.subnet_val.prefix.in.in6);
|
||||
addr = new IPAddr(val->val.subnet_val.prefix.in.in6);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
auto* subnetval = new zeek::SubNetVal(*addr, val->val.subnet_val.length);
|
||||
auto* subnetval = new SubNetVal(*addr, val->val.subnet_val.length);
|
||||
delete addr;
|
||||
return subnetval;
|
||||
}
|
||||
|
||||
case zeek::TYPE_PATTERN:
|
||||
case TYPE_PATTERN:
|
||||
{
|
||||
auto* re = new zeek::RE_Matcher(val->val.pattern_text_val);
|
||||
auto* re = new RE_Matcher(val->val.pattern_text_val);
|
||||
re->Compile();
|
||||
return new zeek::PatternVal(re);
|
||||
return new PatternVal(re);
|
||||
}
|
||||
|
||||
case zeek::TYPE_TABLE:
|
||||
case TYPE_TABLE:
|
||||
{
|
||||
zeek::TypeListPtr set_index;
|
||||
if ( val->val.set_val.size == 0 && val->subtype == zeek::TYPE_VOID )
|
||||
TypeListPtr set_index;
|
||||
if ( val->val.set_val.size == 0 && val->subtype == TYPE_VOID )
|
||||
// don't know type - unspecified table.
|
||||
set_index = zeek::make_intrusive<zeek::TypeList>();
|
||||
set_index = make_intrusive<TypeList>();
|
||||
else
|
||||
{
|
||||
// all entries have to have the same type...
|
||||
zeek::TypeTag stag = val->subtype;
|
||||
if ( stag == zeek::TYPE_VOID )
|
||||
TypeTag stag = val->subtype;
|
||||
if ( stag == TYPE_VOID )
|
||||
stag = val->val.set_val.vals[0]->type;
|
||||
|
||||
zeek::TypePtr index_type;
|
||||
TypePtr index_type;
|
||||
|
||||
if ( stag == zeek::TYPE_ENUM )
|
||||
if ( stag == TYPE_ENUM )
|
||||
{
|
||||
// Enums are not a base-type, so need to look it up.
|
||||
const auto& sv = val->val.set_val.vals[0]->val.string_val;
|
||||
std::string enum_name(sv.data, sv.length);
|
||||
const auto& enum_id = zeek::detail::global_scope()->Find(enum_name);
|
||||
const auto& enum_id = detail::global_scope()->Find(enum_name);
|
||||
|
||||
if ( ! enum_id )
|
||||
{
|
||||
zeek::reporter->Warning("Value '%s' of source '%s' is not a valid enum.",
|
||||
reporter->Warning("Value '%s' of source '%s' is not a valid enum.",
|
||||
enum_name.data(), source.c_str());
|
||||
|
||||
have_error = true;
|
||||
|
@ -552,73 +552,73 @@ zeek::Val* Value::ValueToVal(const std::string& source, const Value* val, bool&
|
|||
index_type = enum_id->GetType();
|
||||
}
|
||||
else
|
||||
index_type = zeek::base_type(stag);
|
||||
index_type = base_type(stag);
|
||||
|
||||
set_index = zeek::make_intrusive<zeek::TypeList>(index_type);
|
||||
set_index = make_intrusive<TypeList>(index_type);
|
||||
set_index->Append(std::move(index_type));
|
||||
}
|
||||
|
||||
auto s = zeek::make_intrusive<zeek::SetType>(std::move(set_index), nullptr);
|
||||
auto* t = new zeek::TableVal(std::move(s));
|
||||
auto s = make_intrusive<SetType>(std::move(set_index), nullptr);
|
||||
auto* t = new TableVal(std::move(s));
|
||||
for ( int j = 0; j < val->val.set_val.size; j++ )
|
||||
{
|
||||
zeek::Val* assignval = ValueToVal(source, val->val.set_val.vals[j], have_error);
|
||||
t->Assign({zeek::AdoptRef{}, assignval}, nullptr);
|
||||
Val* assignval = ValueToVal(source, val->val.set_val.vals[j], have_error);
|
||||
t->Assign({AdoptRef{}, assignval}, nullptr);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
case zeek::TYPE_VECTOR:
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
zeek::TypePtr type;
|
||||
TypePtr type;
|
||||
|
||||
if ( val->val.vector_val.size == 0 && val->subtype == zeek::TYPE_VOID )
|
||||
if ( val->val.vector_val.size == 0 && val->subtype == TYPE_VOID )
|
||||
// don't know type - unspecified table.
|
||||
type = zeek::base_type(zeek::TYPE_ANY);
|
||||
type = base_type(TYPE_ANY);
|
||||
else
|
||||
{
|
||||
// all entries have to have the same type...
|
||||
if ( val->subtype == zeek::TYPE_VOID )
|
||||
type = zeek::base_type(val->val.vector_val.vals[0]->type);
|
||||
if ( val->subtype == TYPE_VOID )
|
||||
type = base_type(val->val.vector_val.vals[0]->type);
|
||||
else
|
||||
type = zeek::base_type(val->subtype);
|
||||
type = base_type(val->subtype);
|
||||
}
|
||||
|
||||
auto vt = zeek::make_intrusive<zeek::VectorType>(std::move(type));
|
||||
auto v = zeek::make_intrusive<zeek::VectorVal>(std::move(vt));
|
||||
auto vt = make_intrusive<VectorType>(std::move(type));
|
||||
auto v = make_intrusive<VectorVal>(std::move(vt));
|
||||
|
||||
for ( int j = 0; j < val->val.vector_val.size; j++ )
|
||||
{
|
||||
auto el = ValueToVal(source, val->val.vector_val.vals[j], have_error);
|
||||
v->Assign(j, {zeek::AdoptRef{}, el});
|
||||
v->Assign(j, {AdoptRef{}, el});
|
||||
}
|
||||
|
||||
return v.release();
|
||||
}
|
||||
|
||||
case zeek::TYPE_ENUM: {
|
||||
case TYPE_ENUM: {
|
||||
// Convert to string first to not have to deal with missing
|
||||
// \0's...
|
||||
std::string enum_string(val->val.string_val.data, val->val.string_val.length);
|
||||
|
||||
// let's try looking it up by global ID.
|
||||
const auto& id = zeek::detail::lookup_ID(enum_string.c_str(), zeek::detail::GLOBAL_MODULE_NAME);
|
||||
const auto& id = detail::lookup_ID(enum_string.c_str(), detail::GLOBAL_MODULE_NAME);
|
||||
|
||||
if ( ! id || ! id->IsEnumConst() )
|
||||
{
|
||||
zeek::reporter->Warning("Value '%s' for source '%s' is not a valid enum.",
|
||||
reporter->Warning("Value '%s' for source '%s' is not a valid enum.",
|
||||
enum_string.c_str(), source.c_str());
|
||||
|
||||
have_error = true;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
zeek::EnumType* t = id->GetType()->AsEnumType();
|
||||
EnumType* t = id->GetType()->AsEnumType();
|
||||
int intval = t->Lookup(id->ModuleName(), id->Name());
|
||||
if ( intval < 0 )
|
||||
{
|
||||
zeek::reporter->Warning("Enum value '%s' for source '%s' not found.",
|
||||
reporter->Warning("Enum value '%s' for source '%s' not found.",
|
||||
enum_string.c_str(), source.c_str());
|
||||
|
||||
have_error = true;
|
||||
|
@ -630,7 +630,7 @@ zeek::Val* Value::ValueToVal(const std::string& source, const Value* val, bool&
|
|||
}
|
||||
|
||||
default:
|
||||
zeek::reporter->InternalError("Unsupported type in SerialTypes::ValueToVal from source %s", source.c_str());
|
||||
reporter->InternalError("Unsupported type in SerialTypes::ValueToVal from source %s", source.c_str());
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
|
|
@ -21,24 +21,24 @@ struct Field {
|
|||
//! Needed by input framework. Port fields have two names (one for the
|
||||
//! port, one for the type), and this specifies the secondary name.
|
||||
const char* secondary_name;
|
||||
zeek::TypeTag type; //! Type of the field.
|
||||
zeek::TypeTag subtype; //! Inner type for sets and vectors.
|
||||
TypeTag type; //! Type of the field.
|
||||
TypeTag subtype; //! Inner type for sets and vectors.
|
||||
bool optional; //! True if field is optional.
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
Field(const char* name, const char* secondary_name, zeek::TypeTag type, zeek::TypeTag subtype, bool optional)
|
||||
: name(name ? zeek::util::copy_string(name) : nullptr),
|
||||
secondary_name(secondary_name ? zeek::util::copy_string(secondary_name) : nullptr),
|
||||
Field(const char* name, const char* secondary_name, TypeTag type, TypeTag subtype, bool optional)
|
||||
: name(name ? util::copy_string(name) : nullptr),
|
||||
secondary_name(secondary_name ? util::copy_string(secondary_name) : nullptr),
|
||||
type(type), subtype(subtype), optional(optional) { }
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
Field(const Field& other)
|
||||
: name(other.name ? zeek::util::copy_string(other.name) : nullptr),
|
||||
secondary_name(other.secondary_name ? zeek::util::copy_string(other.secondary_name) : nullptr),
|
||||
: name(other.name ? util::copy_string(other.name) : nullptr),
|
||||
secondary_name(other.secondary_name ? util::copy_string(other.secondary_name) : nullptr),
|
||||
type(other.type), subtype(other.subtype), optional(other.optional) { }
|
||||
|
||||
~Field()
|
||||
|
@ -85,8 +85,8 @@ private:
|
|||
* those Vals supported).
|
||||
*/
|
||||
struct Value {
|
||||
zeek::TypeTag type; //! The type of the value.
|
||||
zeek::TypeTag subtype; //! Inner type for sets and vectors.
|
||||
TypeTag type; //! The type of the value.
|
||||
TypeTag subtype; //! Inner type for sets and vectors.
|
||||
bool present; //! False for optional record fields that are not set.
|
||||
|
||||
struct set_t { bro_int_t size; Value** vals; };
|
||||
|
@ -141,8 +141,8 @@ struct Value {
|
|||
* arg_present: False if the value represents an optional record field
|
||||
* that is not set.
|
||||
*/
|
||||
Value(zeek::TypeTag arg_type = zeek::TYPE_ERROR, bool arg_present = true)
|
||||
: type(arg_type), subtype(zeek::TYPE_VOID), present(arg_present)
|
||||
Value(TypeTag arg_type = TYPE_ERROR, bool arg_present = true)
|
||||
: type(arg_type), subtype(TYPE_VOID), present(arg_present)
|
||||
{}
|
||||
|
||||
/**
|
||||
|
@ -155,7 +155,7 @@ struct Value {
|
|||
* arg_present: False if the value represents an optional record field
|
||||
* that is not set.
|
||||
*/
|
||||
Value(zeek::TypeTag arg_type, zeek::TypeTag arg_subtype, bool arg_present = true)
|
||||
Value(TypeTag arg_type, TypeTag arg_subtype, bool arg_present = true)
|
||||
: type(arg_type), subtype(arg_subtype), present(arg_present)
|
||||
{}
|
||||
|
||||
|
@ -187,7 +187,7 @@ struct Value {
|
|||
* Returns true if the type can be represented by a Value. If
|
||||
* `atomic_only` is true, will not permit composite types. This
|
||||
* method is thread-safe. */
|
||||
static bool IsCompatibleType(zeek::Type* t, bool atomic_only=false);
|
||||
static bool IsCompatibleType(Type* t, bool atomic_only=false);
|
||||
|
||||
/**
|
||||
* Convenience function to delete an array of value pointers.
|
||||
|
@ -207,7 +207,7 @@ struct Value {
|
|||
* immediately aborts.
|
||||
* @return Val representation of the threading::Value. nullptr on error.
|
||||
*/
|
||||
static zeek::Val* ValueToVal(const std::string& source, const threading::Value* val, bool& have_error);
|
||||
static Val* ValueToVal(const std::string& source, const threading::Value* val, bool& have_error);
|
||||
|
||||
private:
|
||||
friend class IPAddr;
|
||||
|
|
|
@ -16,13 +16,13 @@ namespace zeek::threading::formatter {
|
|||
// If the value we'd write out would match exactly the a reserved string, we
|
||||
// escape the first character so that the output won't be ambigious. If this
|
||||
// function returns true, it has added an escaped version of data to desc.
|
||||
static inline bool escapeReservedContent(zeek::ODesc* desc, const string& reserved, const char* data, int size)
|
||||
static inline bool escapeReservedContent(ODesc* desc, const string& reserved, const char* data, int size)
|
||||
{
|
||||
if ( size != (int)reserved.size() || memcmp(data, reserved.data(), size) != 0 )
|
||||
return false;
|
||||
|
||||
char hex[4] = {'\\', 'x', '0', '0'};
|
||||
zeek::util::bytetohex(*data, hex + 2);
|
||||
util::bytetohex(*data, hex + 2);
|
||||
desc->AddRaw(hex, 4);
|
||||
desc->AddN(data + 1, size - 1);
|
||||
return true;
|
||||
|
@ -48,7 +48,7 @@ Ascii::SeparatorInfo::SeparatorInfo(const string& arg_separator,
|
|||
empty_field = arg_empty_field;
|
||||
}
|
||||
|
||||
Ascii::Ascii(zeek::threading::MsgThread* t, const SeparatorInfo& info) : zeek::threading::Formatter(t)
|
||||
Ascii::Ascii(MsgThread* t, const SeparatorInfo& info) : Formatter(t)
|
||||
{
|
||||
separators = info;
|
||||
}
|
||||
|
@ -57,8 +57,8 @@ Ascii::~Ascii()
|
|||
{
|
||||
}
|
||||
|
||||
bool Ascii::Describe(zeek::ODesc* desc, int num_fields, const zeek::threading::Field* const * fields,
|
||||
zeek::threading::Value** vals) const
|
||||
bool Ascii::Describe(ODesc* desc, int num_fields, const Field* const * fields,
|
||||
Value** vals) const
|
||||
{
|
||||
for ( int i = 0; i < num_fields; i++ )
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ bool Ascii::Describe(zeek::ODesc* desc, int num_fields, const zeek::threading::F
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Ascii::Describe(zeek::ODesc* desc, zeek::threading::Value* val, const string& name) const
|
||||
bool Ascii::Describe(ODesc* desc, Value* val, const string& name) const
|
||||
{
|
||||
if ( ! val->present )
|
||||
{
|
||||
|
@ -82,49 +82,49 @@ bool Ascii::Describe(zeek::ODesc* desc, zeek::threading::Value* val, const strin
|
|||
|
||||
switch ( val->type ) {
|
||||
|
||||
case zeek::TYPE_BOOL:
|
||||
case TYPE_BOOL:
|
||||
desc->Add(val->val.int_val ? "T" : "F");
|
||||
break;
|
||||
|
||||
case zeek::TYPE_INT:
|
||||
case TYPE_INT:
|
||||
desc->Add(val->val.int_val);
|
||||
break;
|
||||
|
||||
case zeek::TYPE_COUNT:
|
||||
case TYPE_COUNT:
|
||||
desc->Add(val->val.uint_val);
|
||||
break;
|
||||
|
||||
case zeek::TYPE_PORT:
|
||||
case TYPE_PORT:
|
||||
desc->Add(val->val.port_val.port);
|
||||
break;
|
||||
|
||||
case zeek::TYPE_SUBNET:
|
||||
case TYPE_SUBNET:
|
||||
desc->Add(Render(val->val.subnet_val));
|
||||
break;
|
||||
|
||||
case zeek::TYPE_ADDR:
|
||||
case TYPE_ADDR:
|
||||
desc->Add(Render(val->val.addr_val));
|
||||
break;
|
||||
|
||||
case zeek::TYPE_DOUBLE:
|
||||
case TYPE_DOUBLE:
|
||||
// Rendering via Add() truncates trailing 0s after the
|
||||
// decimal point. The difference with TIME/INTERVAL is mainly
|
||||
// to keep the log format consistent.
|
||||
desc->Add(val->val.double_val, true);
|
||||
break;
|
||||
|
||||
case zeek::TYPE_INTERVAL:
|
||||
case zeek::TYPE_TIME:
|
||||
case TYPE_INTERVAL:
|
||||
case TYPE_TIME:
|
||||
// Rendering via Render() keeps trailing 0s after the decimal
|
||||
// point. The difference with DOUBLE is mainly to keep the
|
||||
// log format consistent.
|
||||
desc->Add(Render(val->val.double_val));
|
||||
break;
|
||||
|
||||
case zeek::TYPE_ENUM:
|
||||
case zeek::TYPE_STRING:
|
||||
case zeek::TYPE_FILE:
|
||||
case zeek::TYPE_FUNC:
|
||||
case TYPE_ENUM:
|
||||
case TYPE_STRING:
|
||||
case TYPE_FILE:
|
||||
case TYPE_FUNC:
|
||||
{
|
||||
int size = val->val.string_val.length;
|
||||
const char* data = val->val.string_val.data;
|
||||
|
@ -145,7 +145,7 @@ bool Ascii::Describe(zeek::ODesc* desc, zeek::threading::Value* val, const strin
|
|||
break;
|
||||
}
|
||||
|
||||
case zeek::TYPE_TABLE:
|
||||
case TYPE_TABLE:
|
||||
{
|
||||
if ( ! val->val.set_val.size )
|
||||
{
|
||||
|
@ -172,7 +172,7 @@ bool Ascii::Describe(zeek::ODesc* desc, zeek::threading::Value* val, const strin
|
|||
break;
|
||||
}
|
||||
|
||||
case zeek::TYPE_VECTOR:
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
if ( ! val->val.vector_val.size )
|
||||
{
|
||||
|
@ -208,30 +208,30 @@ bool Ascii::Describe(zeek::ODesc* desc, zeek::threading::Value* val, const strin
|
|||
}
|
||||
|
||||
|
||||
zeek::threading::Value* Ascii::ParseValue(const string& s, const string& name, zeek::TypeTag type, zeek::TypeTag subtype) const
|
||||
Value* Ascii::ParseValue(const string& s, const string& name, TypeTag type, TypeTag subtype) const
|
||||
{
|
||||
if ( ! separators.unset_field.empty() && s.compare(separators.unset_field) == 0 ) // field is not set...
|
||||
return new zeek::threading::Value(type, false);
|
||||
return new Value(type, false);
|
||||
|
||||
zeek::threading::Value* val = new zeek::threading::Value(type, subtype, true);
|
||||
Value* val = new Value(type, subtype, true);
|
||||
const char* start = s.c_str();
|
||||
char* end = nullptr;
|
||||
errno = 0;
|
||||
size_t pos;
|
||||
|
||||
switch ( type ) {
|
||||
case zeek::TYPE_ENUM:
|
||||
case zeek::TYPE_STRING:
|
||||
case TYPE_ENUM:
|
||||
case TYPE_STRING:
|
||||
{
|
||||
string unescaped = zeek::util::get_unescaped_string(s);
|
||||
string unescaped = util::get_unescaped_string(s);
|
||||
val->val.string_val.length = unescaped.size();
|
||||
val->val.string_val.data = zeek::util::copy_string(unescaped.c_str());
|
||||
val->val.string_val.data = util::copy_string(unescaped.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
case zeek::TYPE_BOOL:
|
||||
case TYPE_BOOL:
|
||||
{
|
||||
auto stripped = zeek::util::strstrip(s);
|
||||
auto stripped = util::strstrip(s);
|
||||
if ( stripped == "T" || stripped == "1" )
|
||||
val->val.int_val = 1;
|
||||
else if ( stripped == "F" || stripped == "0" )
|
||||
|
@ -245,42 +245,42 @@ zeek::threading::Value* Ascii::ParseValue(const string& s, const string& name, z
|
|||
break;
|
||||
}
|
||||
|
||||
case zeek::TYPE_INT:
|
||||
case TYPE_INT:
|
||||
val->val.int_val = strtoll(start, &end, 10);
|
||||
if ( CheckNumberError(start, end) )
|
||||
goto parse_error;
|
||||
break;
|
||||
|
||||
case zeek::TYPE_DOUBLE:
|
||||
case zeek::TYPE_TIME:
|
||||
case zeek::TYPE_INTERVAL:
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_TIME:
|
||||
case TYPE_INTERVAL:
|
||||
val->val.double_val = strtod(start, &end);
|
||||
if ( CheckNumberError(start, end) )
|
||||
goto parse_error;
|
||||
break;
|
||||
|
||||
case zeek::TYPE_COUNT:
|
||||
case TYPE_COUNT:
|
||||
val->val.uint_val = strtoull(start, &end, 10);
|
||||
if ( CheckNumberError(start, end) )
|
||||
goto parse_error;
|
||||
break;
|
||||
|
||||
case zeek::TYPE_PORT:
|
||||
case TYPE_PORT:
|
||||
{
|
||||
auto stripped = zeek::util::strstrip(s);
|
||||
auto stripped = util::strstrip(s);
|
||||
val->val.port_val.proto = TRANSPORT_UNKNOWN;
|
||||
pos = stripped.find('/');
|
||||
string numberpart;
|
||||
if ( pos != std::string::npos && stripped.length() > pos + 1 )
|
||||
{
|
||||
auto proto = stripped.substr(pos+1);
|
||||
if ( zeek::util::strtolower(proto) == "tcp" )
|
||||
if ( util::strtolower(proto) == "tcp" )
|
||||
val->val.port_val.proto = TRANSPORT_TCP;
|
||||
else if ( zeek::util::strtolower(proto) == "udp" )
|
||||
else if ( util::strtolower(proto) == "udp" )
|
||||
val->val.port_val.proto = TRANSPORT_UDP;
|
||||
else if ( zeek::util::strtolower(proto) == "icmp" )
|
||||
else if ( util::strtolower(proto) == "icmp" )
|
||||
val->val.port_val.proto = TRANSPORT_ICMP;
|
||||
else if ( zeek::util::strtolower(proto) == "unknown" )
|
||||
else if ( util::strtolower(proto) == "unknown" )
|
||||
val->val.port_val.proto = TRANSPORT_UNKNOWN;
|
||||
else
|
||||
GetThread()->Warning(GetThread()->Fmt("Port '%s' contained unknown protocol '%s'", s.c_str(), proto.c_str()));
|
||||
|
@ -297,9 +297,9 @@ zeek::threading::Value* Ascii::ParseValue(const string& s, const string& name, z
|
|||
}
|
||||
break;
|
||||
|
||||
case zeek::TYPE_SUBNET:
|
||||
case TYPE_SUBNET:
|
||||
{
|
||||
string unescaped = zeek::util::strstrip(zeek::util::get_unescaped_string(s));
|
||||
string unescaped = util::strstrip(util::get_unescaped_string(s));
|
||||
size_t pos = unescaped.find('/');
|
||||
if ( pos == unescaped.npos )
|
||||
{
|
||||
|
@ -320,16 +320,16 @@ zeek::threading::Value* Ascii::ParseValue(const string& s, const string& name, z
|
|||
break;
|
||||
}
|
||||
|
||||
case zeek::TYPE_ADDR:
|
||||
case TYPE_ADDR:
|
||||
{
|
||||
string unescaped = zeek::util::strstrip(zeek::util::get_unescaped_string(s));
|
||||
string unescaped = util::strstrip(util::get_unescaped_string(s));
|
||||
val->val.addr_val = ParseAddr(unescaped);
|
||||
break;
|
||||
}
|
||||
|
||||
case zeek::TYPE_PATTERN:
|
||||
case TYPE_PATTERN:
|
||||
{
|
||||
string candidate = zeek::util::get_unescaped_string(s);
|
||||
string candidate = util::get_unescaped_string(s);
|
||||
// A string is a candidate pattern iff it begins and ends with
|
||||
// a '/'. Rather or not the rest of the string is legal will
|
||||
// be determined later when it is given to the RE engine.
|
||||
|
@ -341,7 +341,7 @@ zeek::threading::Value* Ascii::ParseValue(const string& s, const string& name, z
|
|||
// Remove the '/'s
|
||||
candidate.erase(0, 1);
|
||||
candidate.erase(candidate.size() - 1);
|
||||
val->val.pattern_text_val = zeek::util::copy_string(candidate.c_str());
|
||||
val->val.pattern_text_val = util::copy_string(candidate.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -350,8 +350,8 @@ zeek::threading::Value* Ascii::ParseValue(const string& s, const string& name, z
|
|||
goto parse_error;
|
||||
}
|
||||
|
||||
case zeek::TYPE_TABLE:
|
||||
case zeek::TYPE_VECTOR:
|
||||
case TYPE_TABLE:
|
||||
case TYPE_VECTOR:
|
||||
// First - common initialization
|
||||
// Then - initialization for table.
|
||||
// Then - initialization for vector.
|
||||
|
@ -374,15 +374,15 @@ zeek::threading::Value* Ascii::ParseValue(const string& s, const string& name, z
|
|||
if ( separators.empty_field.empty() && s.empty() )
|
||||
length = 0;
|
||||
|
||||
zeek::threading::Value** lvals = new zeek::threading::Value* [length];
|
||||
Value** lvals = new Value* [length];
|
||||
|
||||
if ( type == zeek::TYPE_TABLE )
|
||||
if ( type == TYPE_TABLE )
|
||||
{
|
||||
val->val.set_val.vals = lvals;
|
||||
val->val.set_val.size = length;
|
||||
}
|
||||
|
||||
else if ( type == zeek::TYPE_VECTOR )
|
||||
else if ( type == TYPE_VECTOR )
|
||||
{
|
||||
val->val.vector_val.vals = lvals;
|
||||
val->val.vector_val.size = length;
|
||||
|
@ -410,7 +410,7 @@ zeek::threading::Value* Ascii::ParseValue(const string& s, const string& name, z
|
|||
break;
|
||||
}
|
||||
|
||||
zeek::threading::Value* newval = ParseValue(element, name, subtype);
|
||||
Value* newval = ParseValue(element, name, subtype);
|
||||
if ( newval == nullptr )
|
||||
{
|
||||
GetThread()->Warning("Error while reading set or vector");
|
||||
|
@ -475,7 +475,7 @@ parse_error:
|
|||
|
||||
bool Ascii::CheckNumberError(const char* start, const char* end) const
|
||||
{
|
||||
zeek::threading::MsgThread* thread = GetThread();
|
||||
MsgThread* thread = GetThread();
|
||||
|
||||
if ( end == start && *end != '\0' ) {
|
||||
thread->Warning(thread->Fmt("String '%s' contained no parseable number", start));
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace zeek::threading::formatter {
|
||||
|
||||
class Ascii final : public zeek::threading::Formatter {
|
||||
class Ascii final : public Formatter {
|
||||
public:
|
||||
/**
|
||||
* A struct to pass the necessary configuration values to the
|
||||
|
@ -44,14 +44,14 @@ public:
|
|||
* @param info SeparatorInfo structure defining the necessary
|
||||
* separators.
|
||||
*/
|
||||
Ascii(zeek::threading::MsgThread* t, const SeparatorInfo& info);
|
||||
Ascii(MsgThread* t, const SeparatorInfo& info);
|
||||
virtual ~Ascii();
|
||||
|
||||
virtual bool Describe(zeek::ODesc* desc, zeek::threading::Value* val, const std::string& name = "") const;
|
||||
virtual bool Describe(zeek::ODesc* desc, int num_fields, const zeek::threading::Field* const * fields,
|
||||
zeek::threading::Value** vals) const;
|
||||
virtual zeek::threading::Value* ParseValue(const std::string& s, const std::string& name,
|
||||
zeek::TypeTag type, zeek::TypeTag subtype = zeek::TYPE_ERROR) const;
|
||||
virtual bool Describe(ODesc* desc, Value* val, const std::string& name = "") const;
|
||||
virtual bool Describe(ODesc* desc, int num_fields, const Field* const * fields,
|
||||
Value** vals) const;
|
||||
virtual Value* ParseValue(const std::string& s, const std::string& name,
|
||||
TypeTag type, TypeTag subtype = TYPE_ERROR) const;
|
||||
|
||||
private:
|
||||
bool CheckNumberError(const char* start, const char* end) const;
|
||||
|
|
|
@ -26,7 +26,7 @@ bool JSON::NullDoubleWriter::Double(double d)
|
|||
return rapidjson::Writer<rapidjson::StringBuffer>::Double(d);
|
||||
}
|
||||
|
||||
JSON::JSON(zeek::threading::MsgThread* t, TimeFormat tf) : zeek::threading::Formatter(t), surrounding_braces(true)
|
||||
JSON::JSON(MsgThread* t, TimeFormat tf) : Formatter(t), surrounding_braces(true)
|
||||
{
|
||||
timestamps = tf;
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ JSON::~JSON()
|
|||
{
|
||||
}
|
||||
|
||||
bool JSON::Describe(zeek::ODesc* desc, int num_fields, const zeek::threading::Field* const * fields,
|
||||
zeek::threading::Value** vals) const
|
||||
bool JSON::Describe(ODesc* desc, int num_fields, const Field* const * fields,
|
||||
Value** vals) const
|
||||
{
|
||||
rapidjson::StringBuffer buffer;
|
||||
NullDoubleWriter writer(buffer);
|
||||
|
@ -55,7 +55,7 @@ bool JSON::Describe(zeek::ODesc* desc, int num_fields, const zeek::threading::Fi
|
|||
return true;
|
||||
}
|
||||
|
||||
bool JSON::Describe(zeek::ODesc* desc, zeek::threading::Value* val, const std::string& name) const
|
||||
bool JSON::Describe(ODesc* desc, Value* val, const std::string& name) const
|
||||
{
|
||||
if ( desc->IsBinary() )
|
||||
{
|
||||
|
@ -78,14 +78,14 @@ bool JSON::Describe(zeek::ODesc* desc, zeek::threading::Value* val, const std::s
|
|||
return true;
|
||||
}
|
||||
|
||||
zeek::threading::Value* JSON::ParseValue(const std::string& s, const std::string& name,
|
||||
zeek::TypeTag type, zeek::TypeTag subtype) const
|
||||
Value* JSON::ParseValue(const std::string& s, const std::string& name,
|
||||
TypeTag type, TypeTag subtype) const
|
||||
{
|
||||
GetThread()->Error("JSON formatter does not support parsing yet.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void JSON::BuildJSON(NullDoubleWriter& writer, zeek::threading::Value* val, const std::string& name) const
|
||||
void JSON::BuildJSON(NullDoubleWriter& writer, Value* val, const std::string& name) const
|
||||
{
|
||||
if ( ! val->present )
|
||||
{
|
||||
|
@ -98,36 +98,36 @@ void JSON::BuildJSON(NullDoubleWriter& writer, zeek::threading::Value* val, cons
|
|||
|
||||
switch ( val->type )
|
||||
{
|
||||
case zeek::TYPE_BOOL:
|
||||
case TYPE_BOOL:
|
||||
writer.Bool(val->val.int_val != 0);
|
||||
break;
|
||||
|
||||
case zeek::TYPE_INT:
|
||||
case TYPE_INT:
|
||||
writer.Int64(val->val.int_val);
|
||||
break;
|
||||
|
||||
case zeek::TYPE_COUNT:
|
||||
case TYPE_COUNT:
|
||||
writer.Uint64(val->val.uint_val);
|
||||
break;
|
||||
|
||||
case zeek::TYPE_PORT:
|
||||
case TYPE_PORT:
|
||||
writer.Uint64(val->val.port_val.port);
|
||||
break;
|
||||
|
||||
case zeek::TYPE_SUBNET:
|
||||
case TYPE_SUBNET:
|
||||
writer.String(Formatter::Render(val->val.subnet_val));
|
||||
break;
|
||||
|
||||
case zeek::TYPE_ADDR:
|
||||
case TYPE_ADDR:
|
||||
writer.String(Formatter::Render(val->val.addr_val));
|
||||
break;
|
||||
|
||||
case zeek::TYPE_DOUBLE:
|
||||
case zeek::TYPE_INTERVAL:
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_INTERVAL:
|
||||
writer.Double(val->val.double_val);
|
||||
break;
|
||||
|
||||
case zeek::TYPE_TIME:
|
||||
case TYPE_TIME:
|
||||
{
|
||||
if ( timestamps == TS_ISO8601 )
|
||||
{
|
||||
|
@ -169,17 +169,17 @@ void JSON::BuildJSON(NullDoubleWriter& writer, zeek::threading::Value* val, cons
|
|||
break;
|
||||
}
|
||||
|
||||
case zeek::TYPE_ENUM:
|
||||
case zeek::TYPE_STRING:
|
||||
case zeek::TYPE_FILE:
|
||||
case zeek::TYPE_FUNC:
|
||||
case TYPE_ENUM:
|
||||
case TYPE_STRING:
|
||||
case TYPE_FILE:
|
||||
case TYPE_FUNC:
|
||||
{
|
||||
writer.String(zeek::util::json_escape_utf8(
|
||||
writer.String(util::json_escape_utf8(
|
||||
std::string(val->val.string_val.data, val->val.string_val.length)));
|
||||
break;
|
||||
}
|
||||
|
||||
case zeek::TYPE_TABLE:
|
||||
case TYPE_TABLE:
|
||||
{
|
||||
writer.StartArray();
|
||||
|
||||
|
@ -190,7 +190,7 @@ void JSON::BuildJSON(NullDoubleWriter& writer, zeek::threading::Value* val, cons
|
|||
break;
|
||||
}
|
||||
|
||||
case zeek::TYPE_VECTOR:
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
writer.StartArray();
|
||||
|
||||
|
@ -202,7 +202,7 @@ void JSON::BuildJSON(NullDoubleWriter& writer, zeek::threading::Value* val, cons
|
|||
}
|
||||
|
||||
default:
|
||||
zeek::reporter->Warning("Unhandled type in JSON::BuildJSON");
|
||||
reporter->Warning("Unhandled type in JSON::BuildJSON");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace zeek::threading::formatter {
|
|||
* A thread-safe class for converting values into a JSON representation
|
||||
* and vice versa.
|
||||
*/
|
||||
class JSON : public zeek::threading::Formatter {
|
||||
class JSON : public Formatter {
|
||||
public:
|
||||
enum TimeFormat {
|
||||
TS_EPOCH, // Doubles that represents seconds from the UNIX epoch.
|
||||
|
@ -22,14 +22,14 @@ public:
|
|||
TS_MILLIS // Milliseconds from the UNIX epoch. Some consumers need this (e.g., elasticsearch).
|
||||
};
|
||||
|
||||
JSON(zeek::threading::MsgThread* t, TimeFormat tf);
|
||||
JSON(MsgThread* t, TimeFormat tf);
|
||||
~JSON() override;
|
||||
|
||||
bool Describe(zeek::ODesc* desc, zeek::threading::Value* val, const std::string& name = "") const override;
|
||||
bool Describe(zeek::ODesc* desc, int num_fields, const zeek::threading::Field* const * fields,
|
||||
zeek::threading::Value** vals) const override;
|
||||
zeek::threading::Value* ParseValue(const std::string& s, const std::string& name, zeek::TypeTag type,
|
||||
zeek::TypeTag subtype = zeek::TYPE_ERROR) const override;
|
||||
bool Describe(ODesc* desc, Value* val, const std::string& name = "") const override;
|
||||
bool Describe(ODesc* desc, int num_fields, const Field* const * fields,
|
||||
Value** vals) const override;
|
||||
Value* ParseValue(const std::string& s, const std::string& name, TypeTag type,
|
||||
TypeTag subtype = TYPE_ERROR) const override;
|
||||
|
||||
class NullDoubleWriter : public rapidjson::Writer<rapidjson::StringBuffer> {
|
||||
public:
|
||||
|
@ -38,7 +38,7 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
void BuildJSON(NullDoubleWriter& writer, zeek::threading::Value* val, const std::string& name = "") const;
|
||||
void BuildJSON(NullDoubleWriter& writer, Value* val, const std::string& name = "") const;
|
||||
|
||||
TimeFormat timestamps;
|
||||
bool surrounding_braces;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue