mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Remove value serialization.
Note - this compiles, but you cannot run Bro anymore - it crashes immediately with a 0-pointer access. The reason behind it is that the required clone functionality does not work anymore.
This commit is contained in:
parent
9b49c7cbc6
commit
474efe9e69
78 changed files with 58 additions and 9185 deletions
68
src/Attr.cc
68
src/Attr.cc
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "Attr.h"
|
||||
#include "Expr.h"
|
||||
#include "Serializer.h"
|
||||
#include "threading/SerialTypes.h"
|
||||
|
||||
const char* attr_name(attr_tag t)
|
||||
|
@ -531,70 +530,3 @@ bool Attributes::operator==(const Attributes& other) const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Attributes::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Attributes* Attributes::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return (Attributes*) SerialObj::Unserialize(info, SER_ATTRIBUTES);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(Attributes, SER_ATTRIBUTES);
|
||||
|
||||
bool Attributes::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_ATTRIBUTES, BroObj);
|
||||
|
||||
info->s->WriteOpenTag("Attributes");
|
||||
assert(type);
|
||||
if ( ! (type->Serialize(info) && SERIALIZE(attrs->length())) )
|
||||
return false;
|
||||
|
||||
loop_over_list((*attrs), i)
|
||||
{
|
||||
Attr* a = (*attrs)[i];
|
||||
|
||||
Expr* e = a->AttrExpr();
|
||||
SERIALIZE_OPTIONAL(e);
|
||||
|
||||
if ( ! SERIALIZE(char(a->Tag())) )
|
||||
return false;
|
||||
}
|
||||
|
||||
info->s->WriteCloseTag("Attributes");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Attributes::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroObj);
|
||||
|
||||
type = BroType::Unserialize(info);
|
||||
if ( ! type )
|
||||
return false;
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
return false;
|
||||
|
||||
attrs = new attr_list(len);
|
||||
while ( len-- )
|
||||
{
|
||||
Expr* e;
|
||||
UNSERIALIZE_OPTIONAL(e, Expr::Unserialize(info))
|
||||
|
||||
char tag;
|
||||
if ( ! UNSERIALIZE(&tag) )
|
||||
{
|
||||
delete e;
|
||||
return false;
|
||||
}
|
||||
|
||||
attrs->append(new Attr((attr_tag)tag, e));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,17 +96,12 @@ public:
|
|||
|
||||
attr_list* Attrs() { return attrs; }
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Attributes* Unserialize(UnserialInfo* info);
|
||||
|
||||
bool operator==(const Attributes& other) const;
|
||||
|
||||
protected:
|
||||
Attributes() : type(), attrs(), in_record() { }
|
||||
void CheckAttr(Attr* attr);
|
||||
|
||||
DECLARE_SERIAL(Attributes);
|
||||
|
||||
BroType* type;
|
||||
attr_list* attrs;
|
||||
bool in_record;
|
||||
|
|
|
@ -247,7 +247,6 @@ set(bro_SRCS
|
|||
Brofiler.cc
|
||||
BroString.cc
|
||||
CCL.cc
|
||||
ChunkedIO.cc
|
||||
CompHash.cc
|
||||
Conn.cc
|
||||
ConvertUTF.c
|
||||
|
@ -302,8 +301,6 @@ set(bro_SRCS
|
|||
SmithWaterman.cc
|
||||
Scope.cc
|
||||
SerializationFormat.cc
|
||||
SerialObj.cc
|
||||
Serializer.cc
|
||||
Sessions.cc
|
||||
StateAccess.cc
|
||||
Stats.cc
|
||||
|
|
1357
src/ChunkedIO.cc
1357
src/ChunkedIO.cc
File diff suppressed because it is too large
Load diff
362
src/ChunkedIO.h
362
src/ChunkedIO.h
|
@ -1,362 +0,0 @@
|
|||
// Implements non-blocking chunk-wise I/O.
|
||||
|
||||
#ifndef CHUNKEDIO_H
|
||||
#define CHUNKEDIO_H
|
||||
|
||||
#include "bro-config.h"
|
||||
#include "List.h"
|
||||
#include "util.h"
|
||||
#include "Flare.h"
|
||||
#include "iosource/FD_Set.h"
|
||||
#include <list>
|
||||
|
||||
#ifdef NEED_KRB5_H
|
||||
# include <krb5.h>
|
||||
#endif
|
||||
|
||||
class CompressedChunkedIO;
|
||||
|
||||
// #define DEBUG_COMMUNICATION 10
|
||||
|
||||
// Abstract base class.
|
||||
class ChunkedIO {
|
||||
public:
|
||||
ChunkedIO();
|
||||
virtual ~ChunkedIO() { }
|
||||
|
||||
struct Chunk {
|
||||
typedef void (*FreeFunc)(char*);
|
||||
static void free_func_free(char* data) { free(data); }
|
||||
static void free_func_delete(char* data) { delete [] data; }
|
||||
|
||||
Chunk()
|
||||
: data(), len(), free_func(free_func_delete)
|
||||
{ }
|
||||
|
||||
// Takes ownership of data.
|
||||
Chunk(char* arg_data, uint32 arg_len,
|
||||
FreeFunc arg_ff = free_func_delete)
|
||||
: data(arg_data), len(arg_len), free_func(arg_ff)
|
||||
{ }
|
||||
|
||||
~Chunk()
|
||||
{ free_func(data); }
|
||||
|
||||
char* data;
|
||||
uint32 len;
|
||||
FreeFunc free_func;
|
||||
};
|
||||
|
||||
// Initialization before any I/O operation is performed. Returns false
|
||||
// on any form of error.
|
||||
virtual bool Init() { return true; }
|
||||
|
||||
// Tries to read the next chunk of data. If it can be read completely,
|
||||
// a pointer to it is returned in 'chunk' (ownership of chunk is
|
||||
// passed). If not, 'chunk' is set to nil. Returns false if any
|
||||
// I/O error occurred (use Eof() to see if it's an end-of-file).
|
||||
// If 'may_block' is true, we explicitly allow blocking.
|
||||
virtual bool Read(Chunk** chunk, bool may_block = false) = 0;
|
||||
|
||||
// Puts the chunk into the write queue and writes as much data
|
||||
// as possible (takes ownership of chunk).
|
||||
// Returns false on any I/O error.
|
||||
virtual bool Write(Chunk* chunk) = 0;
|
||||
|
||||
// Tries to write as much as currently possible.
|
||||
// Returns false on any I/O error.
|
||||
virtual bool Flush() = 0;
|
||||
|
||||
// If an I/O error has been encountered, returns a string describing it.
|
||||
virtual const char* Error() = 0;
|
||||
|
||||
// Return true if there is currently at least one chunk available
|
||||
// for reading.
|
||||
virtual bool CanRead() = 0;
|
||||
|
||||
// Return true if there is currently at least one chunk waiting to be
|
||||
// written.
|
||||
virtual bool CanWrite() = 0;
|
||||
|
||||
// Returns true if source believes that there won't be much data soon.
|
||||
virtual bool IsIdle() = 0;
|
||||
|
||||
// Returns true if internal write buffers are about to fill up.
|
||||
virtual bool IsFillingUp() = 0;
|
||||
|
||||
// Throws away buffered data.
|
||||
virtual void Clear() = 0;
|
||||
|
||||
// Returns true,if end-of-file has been reached.
|
||||
virtual bool Eof() = 0;
|
||||
|
||||
// Returns underlying fd if available, -1 otherwise.
|
||||
virtual int Fd() { return -1; }
|
||||
|
||||
// Returns supplementary file descriptors that become read-ready in order
|
||||
// to signal that there is some work that can be performed.
|
||||
virtual iosource::FD_Set ExtraReadFDs() const
|
||||
{ return iosource::FD_Set(); }
|
||||
|
||||
// Makes sure that no additional protocol data is written into
|
||||
// the output stream. If this is activated, the output cannot
|
||||
// be read again by any of these classes!
|
||||
void MakePure() { pure = true; }
|
||||
bool IsPure() { return pure; }
|
||||
|
||||
// Writes a log message to the error_fd.
|
||||
void Log(const char* str);
|
||||
|
||||
struct Statistics {
|
||||
Statistics()
|
||||
{
|
||||
bytes_read = 0;
|
||||
bytes_written = 0;
|
||||
chunks_read = 0;
|
||||
chunks_written = 0;
|
||||
reads = 0;
|
||||
writes = 0;
|
||||
pending = 0;
|
||||
}
|
||||
|
||||
unsigned long bytes_read;
|
||||
unsigned long bytes_written;
|
||||
unsigned long chunks_read;
|
||||
unsigned long chunks_written;
|
||||
unsigned long reads; // # calls which transferred > 0 bytes
|
||||
unsigned long writes;
|
||||
unsigned long pending;
|
||||
};
|
||||
|
||||
// Returns raw statistics.
|
||||
const Statistics* Stats() const { return &stats; }
|
||||
|
||||
// Puts a formatted string containing statistics into buffer.
|
||||
virtual void Stats(char* buffer, int length);
|
||||
|
||||
#ifdef DEBUG_COMMUNICATION
|
||||
void DumpDebugData(const char* basefnname, bool want_reads);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void InternalError(const char* msg)
|
||||
// We can't use the reporter here as we might be running in a
|
||||
// sub-process.
|
||||
{ fprintf(stderr, "%s", msg); abort(); }
|
||||
|
||||
Statistics stats;
|
||||
const char* tag;
|
||||
|
||||
#ifdef DEBUG_COMMUNICATION
|
||||
void AddToBuffer(char* data, bool is_read)
|
||||
{ AddToBuffer(strlen(data), data, is_read); }
|
||||
void AddToBuffer(uint32 len, char* data, bool is_read);
|
||||
void AddToBuffer(Chunk* chunk, bool is_read);
|
||||
std::list<Chunk*> data_read;
|
||||
std::list<Chunk*> data_written;
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool pure;
|
||||
};
|
||||
|
||||
// Chunked I/O using a file descriptor.
|
||||
class ChunkedIOFd : public ChunkedIO {
|
||||
public:
|
||||
// fd is an open bidirectional file descriptor, tag is used in error
|
||||
// messages, and pid gives a pid to monitor (if the process dies, we
|
||||
// return EOF).
|
||||
ChunkedIOFd(int fd, const char* tag, pid_t pid = 0);
|
||||
~ChunkedIOFd() override;
|
||||
|
||||
bool Read(Chunk** chunk, bool may_block = false) override;
|
||||
bool Write(Chunk* chunk) override;
|
||||
bool Flush() override;
|
||||
const char* Error() override;
|
||||
bool CanRead() override;
|
||||
bool CanWrite() override;
|
||||
bool IsIdle() override;
|
||||
bool IsFillingUp() override;
|
||||
void Clear() override;
|
||||
bool Eof() override { return eof; }
|
||||
int Fd() override { return fd; }
|
||||
iosource::FD_Set ExtraReadFDs() const override;
|
||||
void Stats(char* buffer, int length) override;
|
||||
|
||||
private:
|
||||
|
||||
bool PutIntoWriteBuffer(Chunk* chunk);
|
||||
bool FlushWriteBuffer();
|
||||
Chunk* ExtractChunk();
|
||||
|
||||
// Returns size of next chunk in buffer or 0 if none.
|
||||
uint32 ChunkAvailable();
|
||||
|
||||
// Flushes if it thinks it is time to.
|
||||
bool OptionalFlush();
|
||||
|
||||
// Concatenates the the data of the two chunks forming a new one.
|
||||
// The old chunkds are deleted.
|
||||
Chunk* ConcatChunks(Chunk* c1, Chunk* c2);
|
||||
|
||||
// Reads/writes on chunk of upto BUFFER_SIZE bytes.
|
||||
bool WriteChunk(Chunk* chunk, bool partial);
|
||||
bool ReadChunk(Chunk** chunk, bool may_block);
|
||||
|
||||
int fd;
|
||||
bool eof;
|
||||
double last_flush;
|
||||
int failed_reads;
|
||||
|
||||
// Optimally, this should match the file descriptor's
|
||||
// buffer size (for sockets, it may be helpful to
|
||||
// increase the send/receive buffers).
|
||||
static const unsigned int BUFFER_SIZE = 1024 * 1024 * 1;
|
||||
|
||||
// We 'or' this to the length of a data chunk to mark
|
||||
// that it's part of a larger one. This has to be larger
|
||||
// than BUFFER_SIZE.
|
||||
static const uint32 FLAG_PARTIAL = 0x80000000;
|
||||
|
||||
char* read_buffer;
|
||||
uint32 read_len;
|
||||
uint32 read_pos;
|
||||
Chunk* partial; // when we read an oversized chunk, we store it here
|
||||
|
||||
char* write_buffer;
|
||||
uint32 write_len;
|
||||
uint32 write_pos;
|
||||
|
||||
struct ChunkQueue {
|
||||
Chunk* chunk;
|
||||
ChunkQueue* next;
|
||||
};
|
||||
|
||||
// Chunks that don't fit into our write buffer.
|
||||
ChunkQueue* pending_head;
|
||||
ChunkQueue* pending_tail;
|
||||
|
||||
pid_t pid;
|
||||
bro::Flare write_flare;
|
||||
bro::Flare read_flare;
|
||||
};
|
||||
|
||||
// From OpenSSL. We forward-declare these here to avoid introducing a
|
||||
// dependency on OpenSSL headers just for this header file.
|
||||
typedef struct ssl_ctx_st SSL_CTX;
|
||||
typedef struct ssl_st SSL;
|
||||
|
||||
// Chunked I/O using an SSL connection.
|
||||
class ChunkedIOSSL : public ChunkedIO {
|
||||
public:
|
||||
// Argument is an open socket and a flag indicating whether we are the
|
||||
// server side of the connection.
|
||||
ChunkedIOSSL(int socket, bool server);
|
||||
~ChunkedIOSSL() override;
|
||||
|
||||
bool Init() override;
|
||||
bool Read(Chunk** chunk, bool mayblock = false) override;
|
||||
bool Write(Chunk* chunk) override;
|
||||
bool Flush() override;
|
||||
const char* Error() override;
|
||||
bool CanRead() override;
|
||||
bool CanWrite() override;
|
||||
bool IsIdle() override;
|
||||
bool IsFillingUp() override;
|
||||
void Clear() override;
|
||||
bool Eof() override { return eof; }
|
||||
int Fd() override { return socket; }
|
||||
iosource::FD_Set ExtraReadFDs() const override;
|
||||
void Stats(char* buffer, int length) override;
|
||||
|
||||
private:
|
||||
|
||||
// Only returns true if all data has been read. If not, call
|
||||
// it again with the same parameters as long as error is not
|
||||
// set to true.
|
||||
bool ReadData(char* p, uint32 len, bool* error);
|
||||
// Same for writing.
|
||||
bool WriteData(char* p, uint32 len, bool* error);
|
||||
|
||||
int socket;
|
||||
int last_ret; // last error code
|
||||
bool eof;
|
||||
|
||||
bool server; // are we the server?
|
||||
bool setup; // has the connection been setup successfully?
|
||||
|
||||
SSL* ssl;
|
||||
|
||||
// Write queue.
|
||||
struct Queue {
|
||||
Chunk* chunk;
|
||||
Queue* next;
|
||||
};
|
||||
|
||||
// The chunk part we are reading/writing
|
||||
enum State { LEN, DATA };
|
||||
|
||||
State write_state;
|
||||
Queue* write_head;
|
||||
Queue* write_tail;
|
||||
|
||||
State read_state;
|
||||
Chunk* read_chunk;
|
||||
char* read_ptr;
|
||||
|
||||
// One SSL for all connections.
|
||||
static SSL_CTX* ctx;
|
||||
|
||||
bro::Flare write_flare;
|
||||
};
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
// Wrapper class around a another ChunkedIO which the (un-)compresses data.
|
||||
class CompressedChunkedIO : public ChunkedIO {
|
||||
public:
|
||||
explicit CompressedChunkedIO(ChunkedIO* arg_io) // takes ownership
|
||||
: io(arg_io), zin(), zout(), error(), compress(), uncompress(),
|
||||
uncompressed_bytes_read(), uncompressed_bytes_written() {}
|
||||
~CompressedChunkedIO() override { delete io; }
|
||||
|
||||
bool Init() override; // does *not* call arg_io->Init()
|
||||
bool Read(Chunk** chunk, bool may_block = false) override;
|
||||
bool Write(Chunk* chunk) override;
|
||||
bool Flush() override { return io->Flush(); }
|
||||
const char* Error() override { return error ? error : io->Error(); }
|
||||
bool CanRead() override { return io->CanRead(); }
|
||||
bool CanWrite() override { return io->CanWrite(); }
|
||||
bool IsIdle() override { return io->IsIdle(); }
|
||||
bool IsFillingUp() override { return io->IsFillingUp(); }
|
||||
void Clear() override { return io->Clear(); }
|
||||
bool Eof() override { return io->Eof(); }
|
||||
|
||||
int Fd() override { return io->Fd(); }
|
||||
iosource::FD_Set ExtraReadFDs() const override
|
||||
{ return io->ExtraReadFDs(); }
|
||||
void Stats(char* buffer, int length) override;
|
||||
|
||||
void EnableCompression(int level)
|
||||
{ deflateInit(&zout, level); compress = true; }
|
||||
void EnableDecompression()
|
||||
{ inflateInit(&zin); uncompress = true; }
|
||||
|
||||
protected:
|
||||
// Only compress block with size >= this.
|
||||
static const unsigned int MIN_COMPRESS_SIZE = 30;
|
||||
|
||||
ChunkedIO* io;
|
||||
z_stream zin;
|
||||
z_stream zout;
|
||||
const char* error;
|
||||
|
||||
bool compress;
|
||||
bool uncompress;
|
||||
|
||||
// Keep some statistics.
|
||||
unsigned long uncompressed_bytes_read;
|
||||
unsigned long uncompressed_bytes_written;
|
||||
};
|
||||
|
||||
#endif
|
193
src/Conn.cc
193
src/Conn.cc
|
@ -50,70 +50,10 @@ void ConnectionTimer::Dispatch(double t, int is_expire)
|
|||
reporter->InternalError("reference count inconsistency in ConnectionTimer::Dispatch");
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(ConnectionTimer, SER_CONNECTION_TIMER);
|
||||
|
||||
bool ConnectionTimer::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_CONNECTION_TIMER, Timer);
|
||||
|
||||
// We enumerate all the possible timer functions here ... This
|
||||
// has to match the list is DoUnserialize()!
|
||||
char type = 0;
|
||||
|
||||
if ( timer == timer_func(&Connection::DeleteTimer) )
|
||||
type = 1;
|
||||
else if ( timer == timer_func(&Connection::InactivityTimer) )
|
||||
type = 2;
|
||||
else if ( timer == timer_func(&Connection::StatusUpdateTimer) )
|
||||
type = 3;
|
||||
else if ( timer == timer_func(&Connection::RemoveConnectionTimer) )
|
||||
type = 4;
|
||||
else
|
||||
reporter->InternalError("unknown function in ConnectionTimer::DoSerialize()");
|
||||
|
||||
return conn->Serialize(info) && SERIALIZE(type) && SERIALIZE(do_expire);
|
||||
}
|
||||
|
||||
bool ConnectionTimer::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Timer);
|
||||
|
||||
conn = Connection::Unserialize(info);
|
||||
if ( ! conn )
|
||||
return false;
|
||||
|
||||
char type;
|
||||
|
||||
if ( ! UNSERIALIZE(&type) || ! UNSERIALIZE(&do_expire) )
|
||||
return false;
|
||||
|
||||
switch ( type ) {
|
||||
case 1:
|
||||
timer = timer_func(&Connection::DeleteTimer);
|
||||
break;
|
||||
case 2:
|
||||
timer = timer_func(&Connection::InactivityTimer);
|
||||
break;
|
||||
case 3:
|
||||
timer = timer_func(&Connection::StatusUpdateTimer);
|
||||
break;
|
||||
case 4:
|
||||
timer = timer_func(&Connection::RemoveConnectionTimer);
|
||||
break;
|
||||
default:
|
||||
info->s->Error("unknown connection timer function");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64 Connection::total_connections = 0;
|
||||
uint64 Connection::current_connections = 0;
|
||||
uint64 Connection::external_connections = 0;
|
||||
|
||||
IMPLEMENT_SERIAL(Connection, SER_CONNECTION);
|
||||
|
||||
Connection::Connection(NetSessions* s, HashKey* k, double t, const ConnID* id,
|
||||
uint32 flow, const Packet* pkt,
|
||||
const EncapsulationStack* arg_encap)
|
||||
|
@ -900,139 +840,6 @@ void Connection::IDString(ODesc* d) const
|
|||
d->Add(ntohs(resp_port));
|
||||
}
|
||||
|
||||
bool Connection::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Connection* Connection::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return (Connection*) SerialObj::Unserialize(info, SER_CONNECTION);
|
||||
}
|
||||
|
||||
bool Connection::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_CONNECTION, BroObj);
|
||||
|
||||
// First we write the members which are needed to
|
||||
// create the HashKey.
|
||||
if ( ! SERIALIZE(orig_addr) || ! SERIALIZE(resp_addr) )
|
||||
return false;
|
||||
|
||||
if ( ! SERIALIZE(orig_port) || ! SERIALIZE(resp_port) )
|
||||
return false;
|
||||
|
||||
if ( ! SERIALIZE(timers.length()) )
|
||||
return false;
|
||||
|
||||
loop_over_list(timers, i)
|
||||
if ( ! timers[i]->Serialize(info) )
|
||||
return false;
|
||||
|
||||
SERIALIZE_OPTIONAL(conn_val);
|
||||
|
||||
// FIXME: RuleEndpointState not yet serializable.
|
||||
// FIXME: Analyzers not yet serializable.
|
||||
|
||||
return
|
||||
SERIALIZE(int(proto)) &&
|
||||
SERIALIZE(history) &&
|
||||
SERIALIZE(hist_seen) &&
|
||||
SERIALIZE(start_time) &&
|
||||
SERIALIZE(last_time) &&
|
||||
SERIALIZE(inactivity_timeout) &&
|
||||
SERIALIZE(suppress_event) &&
|
||||
SERIALIZE(login_conn != 0) &&
|
||||
SERIALIZE_BIT(installed_status_timer) &&
|
||||
SERIALIZE_BIT(timers_canceled) &&
|
||||
SERIALIZE_BIT(is_active) &&
|
||||
SERIALIZE_BIT(skip) &&
|
||||
SERIALIZE_BIT(weird) &&
|
||||
SERIALIZE_BIT(finished) &&
|
||||
SERIALIZE_BIT(record_packets) &&
|
||||
SERIALIZE_BIT(record_contents);
|
||||
}
|
||||
|
||||
bool Connection::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroObj);
|
||||
|
||||
// Build the hash key first. Some of the recursive *::Unserialize()
|
||||
// functions may need it.
|
||||
ConnID id;
|
||||
|
||||
if ( ! UNSERIALIZE(&orig_addr) || ! UNSERIALIZE(&resp_addr) )
|
||||
goto error;
|
||||
|
||||
if ( ! UNSERIALIZE(&orig_port) || ! UNSERIALIZE(&resp_port) )
|
||||
goto error;
|
||||
|
||||
id.src_addr = orig_addr;
|
||||
id.dst_addr = resp_addr;
|
||||
// This doesn't work for ICMP. But I guess this is not really important.
|
||||
id.src_port = orig_port;
|
||||
id.dst_port = resp_port;
|
||||
id.is_one_way = 0; // ### incorrect for ICMP
|
||||
key = BuildConnIDHashKey(id);
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
goto error;
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
Timer* t = Timer::Unserialize(info);
|
||||
if ( ! t )
|
||||
goto error;
|
||||
timers.append(t);
|
||||
}
|
||||
|
||||
UNSERIALIZE_OPTIONAL(conn_val,
|
||||
(RecordVal*) Val::Unserialize(info, connection_type));
|
||||
|
||||
int iproto;
|
||||
|
||||
if ( ! (UNSERIALIZE(&iproto) &&
|
||||
UNSERIALIZE(&history) &&
|
||||
UNSERIALIZE(&hist_seen) &&
|
||||
UNSERIALIZE(&start_time) &&
|
||||
UNSERIALIZE(&last_time) &&
|
||||
UNSERIALIZE(&inactivity_timeout) &&
|
||||
UNSERIALIZE(&suppress_event)) )
|
||||
goto error;
|
||||
|
||||
proto = static_cast<TransportProto>(iproto);
|
||||
|
||||
bool has_login_conn;
|
||||
if ( ! UNSERIALIZE(&has_login_conn) )
|
||||
goto error;
|
||||
|
||||
login_conn = has_login_conn ? (LoginConn*) this : 0;
|
||||
|
||||
UNSERIALIZE_BIT(installed_status_timer);
|
||||
UNSERIALIZE_BIT(timers_canceled);
|
||||
UNSERIALIZE_BIT(is_active);
|
||||
UNSERIALIZE_BIT(skip);
|
||||
UNSERIALIZE_BIT(weird);
|
||||
UNSERIALIZE_BIT(finished);
|
||||
UNSERIALIZE_BIT(record_packets);
|
||||
UNSERIALIZE_BIT(record_contents);
|
||||
|
||||
// Hmm... Why does each connection store a sessions ptr?
|
||||
sessions = ::sessions;
|
||||
|
||||
root_analyzer = 0;
|
||||
primary_PIA = 0;
|
||||
conn_timer_mgr = 0;
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
abort();
|
||||
CancelTimers();
|
||||
return false;
|
||||
}
|
||||
|
||||
void Connection::SetRootAnalyzer(analyzer::TransportLayerAnalyzer* analyzer, analyzer::pia::PIA* pia)
|
||||
{
|
||||
root_analyzer = analyzer;
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "Dict.h"
|
||||
#include "Val.h"
|
||||
#include "Timer.h"
|
||||
#include "Serializer.h"
|
||||
#include "RuleMatcher.h"
|
||||
#include "IPAddr.h"
|
||||
#include "TunnelEncapsulation.h"
|
||||
|
@ -235,11 +234,6 @@ public:
|
|||
// Returns true if connection has been received externally.
|
||||
bool IsExternal() const { return conn_timer_mgr != 0; }
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Connection* Unserialize(UnserialInfo* info);
|
||||
|
||||
DECLARE_SERIAL(Connection);
|
||||
|
||||
// Statistics.
|
||||
|
||||
// Just a lower bound.
|
||||
|
@ -385,8 +379,6 @@ protected:
|
|||
|
||||
void Init(Connection* conn, timer_func timer, int do_expire);
|
||||
|
||||
DECLARE_SERIAL(ConnectionTimer);
|
||||
|
||||
Connection* conn;
|
||||
timer_func timer;
|
||||
int do_expire;
|
||||
|
|
|
@ -12,8 +12,7 @@ DebugLogger debug_logger;
|
|||
// Same order here as in DebugStream.
|
||||
DebugLogger::Stream DebugLogger::streams[NUM_DBGS] = {
|
||||
{ "serial", 0, false }, { "rules", 0, false },
|
||||
{ "state", 0, false }, { "chunkedio", 0, false },
|
||||
{"string", 0, false },
|
||||
{ "state", 0, false }, {"string", 0, false },
|
||||
{ "notifiers", 0, false }, { "main-loop", 0, false },
|
||||
{ "dpd", 0, false }, { "tm", 0, false },
|
||||
{ "logging", 0, false }, {"input", 0, false },
|
||||
|
|
|
@ -17,7 +17,6 @@ enum DebugStream {
|
|||
DBG_SERIAL, // Serialization
|
||||
DBG_RULES, // Signature matching
|
||||
DBG_STATE, // StateAccess logging
|
||||
DBG_CHUNKEDIO, // ChunkedIO logging
|
||||
DBG_STRING, // String code
|
||||
DBG_NOTIFIERS, // Notifiers (see StateAccess.h)
|
||||
DBG_MAINLOOP, // Main IOSource loop
|
||||
|
|
|
@ -58,11 +58,12 @@ void Event::Dispatch(bool no_remote)
|
|||
if ( src == SOURCE_BROKER )
|
||||
no_remote = true;
|
||||
|
||||
/* Fixme: johanna
|
||||
if ( event_serializer )
|
||||
{
|
||||
SerialInfo info(event_serializer);
|
||||
event_serializer->Serialize(&info, handler->Name(), &args);
|
||||
}
|
||||
} */
|
||||
|
||||
if ( handler->ErrorHandler() )
|
||||
reporter->BeginErrorHandler();
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#define event_h
|
||||
|
||||
#include "EventRegistry.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
#include "analyzer/Tag.h"
|
||||
#include "analyzer/Analyzer.h"
|
||||
|
|
|
@ -171,23 +171,3 @@ void EventHandler::NewEvent(val_list* vl)
|
|||
mgr.Dispatch(ev);
|
||||
}
|
||||
|
||||
bool EventHandler::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SERIALIZE(name);
|
||||
}
|
||||
|
||||
EventHandler* EventHandler::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
char* name;
|
||||
if ( ! UNSERIALIZE_STR(&name, 0) )
|
||||
return 0;
|
||||
|
||||
EventHandler* h = event_registry->Lookup(name);
|
||||
if ( ! h )
|
||||
{
|
||||
h = new EventHandler(name);
|
||||
event_registry->Register(h);
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
|
||||
class Func;
|
||||
class FuncType;
|
||||
class Serializer;
|
||||
class SerialInfo;
|
||||
class UnserialInfo;
|
||||
|
||||
class EventHandler {
|
||||
public:
|
||||
|
@ -56,11 +53,6 @@ public:
|
|||
void SetGenerateAlways() { generate_always = true; }
|
||||
bool GenerateAlways() { return generate_always; }
|
||||
|
||||
// We don't serialize the handler(s) itself here, but
|
||||
// just the reference to it.
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static EventHandler* Unserialize(UnserialInfo* info);
|
||||
|
||||
private:
|
||||
void NewEvent(val_list* vl); // Raise new_event() meta event.
|
||||
|
||||
|
|
841
src/Expr.cc
841
src/Expr.cc
File diff suppressed because it is too large
Load diff
99
src/Expr.h
99
src/Expr.h
|
@ -189,9 +189,6 @@ public:
|
|||
|
||||
void Describe(ODesc* d) const override;
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Expr* Unserialize(UnserialInfo* info, BroExprTag want = EXPR_ANY);
|
||||
|
||||
virtual TraversalCode Traverse(TraversalCallback* cb) const = 0;
|
||||
|
||||
protected:
|
||||
|
@ -214,8 +211,6 @@ protected:
|
|||
|
||||
void RuntimeErrorWithCallStack(const std::string& msg) const;
|
||||
|
||||
DECLARE_ABSTRACT_SERIAL(Expr);
|
||||
|
||||
BroExprTag tag;
|
||||
BroType* type;
|
||||
|
||||
|
@ -242,8 +237,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(NameExpr);
|
||||
|
||||
ID* id;
|
||||
bool in_const_init;
|
||||
};
|
||||
|
@ -264,8 +257,6 @@ protected:
|
|||
ConstExpr() { val = 0; }
|
||||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
DECLARE_SERIAL(ConstExpr);
|
||||
|
||||
Val* val;
|
||||
};
|
||||
|
||||
|
@ -294,8 +285,6 @@ protected:
|
|||
// Returns the expression folded using the given constant.
|
||||
virtual Val* Fold(Val* v) const;
|
||||
|
||||
DECLARE_SERIAL(UnaryExpr);
|
||||
|
||||
Expr* op;
|
||||
};
|
||||
|
||||
|
@ -357,8 +346,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(BinaryExpr);
|
||||
|
||||
Expr* op1;
|
||||
Expr* op2;
|
||||
};
|
||||
|
@ -373,8 +360,6 @@ protected:
|
|||
CloneExpr() { }
|
||||
|
||||
Val* Fold(Val* v) const override;
|
||||
|
||||
DECLARE_SERIAL(CloneExpr);
|
||||
};
|
||||
|
||||
class IncrExpr : public UnaryExpr {
|
||||
|
@ -388,8 +373,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
IncrExpr() { }
|
||||
|
||||
DECLARE_SERIAL(IncrExpr);
|
||||
};
|
||||
|
||||
class ComplementExpr : public UnaryExpr {
|
||||
|
@ -401,8 +384,6 @@ protected:
|
|||
ComplementExpr() { }
|
||||
|
||||
Val* Fold(Val* v) const override;
|
||||
|
||||
DECLARE_SERIAL(ComplementExpr);
|
||||
};
|
||||
|
||||
class NotExpr : public UnaryExpr {
|
||||
|
@ -414,8 +395,6 @@ protected:
|
|||
NotExpr() { }
|
||||
|
||||
Val* Fold(Val* v) const override;
|
||||
|
||||
DECLARE_SERIAL(NotExpr);
|
||||
};
|
||||
|
||||
class PosExpr : public UnaryExpr {
|
||||
|
@ -427,8 +406,6 @@ protected:
|
|||
PosExpr() { }
|
||||
|
||||
Val* Fold(Val* v) const override;
|
||||
|
||||
DECLARE_SERIAL(PosExpr);
|
||||
};
|
||||
|
||||
class NegExpr : public UnaryExpr {
|
||||
|
@ -440,8 +417,6 @@ protected:
|
|||
NegExpr() { }
|
||||
|
||||
Val* Fold(Val* v) const override;
|
||||
|
||||
DECLARE_SERIAL(NegExpr);
|
||||
};
|
||||
|
||||
class SizeExpr : public UnaryExpr {
|
||||
|
@ -454,7 +429,6 @@ protected:
|
|||
SizeExpr() { }
|
||||
|
||||
Val* Fold(Val* v) const override;
|
||||
DECLARE_SERIAL(SizeExpr);
|
||||
};
|
||||
|
||||
class AddExpr : public BinaryExpr {
|
||||
|
@ -465,9 +439,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
AddExpr() { }
|
||||
|
||||
DECLARE_SERIAL(AddExpr);
|
||||
|
||||
};
|
||||
|
||||
class AddToExpr : public BinaryExpr {
|
||||
|
@ -478,8 +449,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
AddToExpr() { }
|
||||
|
||||
DECLARE_SERIAL(AddToExpr);
|
||||
};
|
||||
|
||||
class RemoveFromExpr : public BinaryExpr {
|
||||
|
@ -490,8 +459,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
RemoveFromExpr() { }
|
||||
|
||||
DECLARE_SERIAL(RemoveFromExpr);
|
||||
};
|
||||
|
||||
class SubExpr : public BinaryExpr {
|
||||
|
@ -501,9 +468,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
SubExpr() { }
|
||||
|
||||
DECLARE_SERIAL(SubExpr);
|
||||
|
||||
};
|
||||
|
||||
class TimesExpr : public BinaryExpr {
|
||||
|
@ -514,9 +478,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
TimesExpr() { }
|
||||
|
||||
DECLARE_SERIAL(TimesExpr);
|
||||
|
||||
};
|
||||
|
||||
class DivideExpr : public BinaryExpr {
|
||||
|
@ -528,9 +489,6 @@ protected:
|
|||
DivideExpr() { }
|
||||
|
||||
Val* AddrFold(Val* v1, Val* v2) const override;
|
||||
|
||||
DECLARE_SERIAL(DivideExpr);
|
||||
|
||||
};
|
||||
|
||||
class ModExpr : public BinaryExpr {
|
||||
|
@ -540,8 +498,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
ModExpr() { }
|
||||
|
||||
DECLARE_SERIAL(ModExpr);
|
||||
};
|
||||
|
||||
class BoolExpr : public BinaryExpr {
|
||||
|
@ -554,8 +510,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
BoolExpr() { }
|
||||
|
||||
DECLARE_SERIAL(BoolExpr);
|
||||
};
|
||||
|
||||
class BitExpr : public BinaryExpr {
|
||||
|
@ -565,8 +519,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
BitExpr() { }
|
||||
|
||||
DECLARE_SERIAL(BitExpr);
|
||||
};
|
||||
|
||||
class EqExpr : public BinaryExpr {
|
||||
|
@ -579,8 +531,6 @@ protected:
|
|||
EqExpr() { }
|
||||
|
||||
Val* Fold(Val* v1, Val* v2) const override;
|
||||
|
||||
DECLARE_SERIAL(EqExpr);
|
||||
};
|
||||
|
||||
class RelExpr : public BinaryExpr {
|
||||
|
@ -591,8 +541,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
RelExpr() { }
|
||||
|
||||
DECLARE_SERIAL(RelExpr);
|
||||
};
|
||||
|
||||
class CondExpr : public Expr {
|
||||
|
@ -615,8 +563,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(CondExpr);
|
||||
|
||||
Expr* op1;
|
||||
Expr* op2;
|
||||
Expr* op3;
|
||||
|
@ -632,8 +578,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
RefExpr() { }
|
||||
|
||||
DECLARE_SERIAL(RefExpr);
|
||||
};
|
||||
|
||||
class AssignExpr : public BinaryExpr {
|
||||
|
@ -657,8 +601,6 @@ protected:
|
|||
bool TypeCheck(attr_list* attrs = 0);
|
||||
bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2);
|
||||
|
||||
DECLARE_SERIAL(AssignExpr);
|
||||
|
||||
int is_init;
|
||||
Val* val; // optional
|
||||
};
|
||||
|
@ -689,8 +631,6 @@ protected:
|
|||
Val* Fold(Val* v1, Val* v2) const override;
|
||||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(IndexExpr);
|
||||
};
|
||||
|
||||
class FieldExpr : public UnaryExpr {
|
||||
|
@ -716,8 +656,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(FieldExpr);
|
||||
|
||||
const char* field_name;
|
||||
const TypeDecl* td;
|
||||
int field; // -1 = attributes
|
||||
|
@ -740,8 +678,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(HasFieldExpr);
|
||||
|
||||
const char* field_name;
|
||||
int field;
|
||||
};
|
||||
|
@ -759,8 +695,6 @@ protected:
|
|||
Val* Fold(Val* v) const override;
|
||||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(RecordConstructorExpr);
|
||||
};
|
||||
|
||||
class TableConstructorExpr : public UnaryExpr {
|
||||
|
@ -781,8 +715,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(TableConstructorExpr);
|
||||
|
||||
Attributes* attrs;
|
||||
};
|
||||
|
||||
|
@ -804,8 +736,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(SetConstructorExpr);
|
||||
|
||||
Attributes* attrs;
|
||||
};
|
||||
|
||||
|
@ -822,8 +752,6 @@ protected:
|
|||
Val* InitVal(const BroType* t, Val* aggr) const override;
|
||||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(VectorConstructorExpr);
|
||||
};
|
||||
|
||||
class FieldAssignExpr : public UnaryExpr {
|
||||
|
@ -841,8 +769,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(FieldAssignExpr);
|
||||
|
||||
string field_name;
|
||||
};
|
||||
|
||||
|
@ -856,8 +782,6 @@ protected:
|
|||
|
||||
Val* FoldSingleVal(Val* v, InternalTypeTag t) const;
|
||||
Val* Fold(Val* v) const override;
|
||||
|
||||
DECLARE_SERIAL(ArithCoerceExpr);
|
||||
};
|
||||
|
||||
class RecordCoerceExpr : public UnaryExpr {
|
||||
|
@ -872,8 +796,6 @@ protected:
|
|||
Val* InitVal(const BroType* t, Val* aggr) const override;
|
||||
Val* Fold(Val* v) const override;
|
||||
|
||||
DECLARE_SERIAL(RecordCoerceExpr);
|
||||
|
||||
// For each super-record slot, gives subrecord slot with which to
|
||||
// fill it.
|
||||
int* map;
|
||||
|
@ -890,8 +812,6 @@ protected:
|
|||
TableCoerceExpr() { }
|
||||
|
||||
Val* Fold(Val* v) const override;
|
||||
|
||||
DECLARE_SERIAL(TableCoerceExpr);
|
||||
};
|
||||
|
||||
class VectorCoerceExpr : public UnaryExpr {
|
||||
|
@ -904,8 +824,6 @@ protected:
|
|||
VectorCoerceExpr() { }
|
||||
|
||||
Val* Fold(Val* v) const override;
|
||||
|
||||
DECLARE_SERIAL(VectorCoerceExpr);
|
||||
};
|
||||
|
||||
// An internal operator for flattening array indices that are records
|
||||
|
@ -920,8 +838,6 @@ protected:
|
|||
|
||||
Val* Fold(Val* v) const override;
|
||||
|
||||
DECLARE_SERIAL(FlattenExpr);
|
||||
|
||||
int num_fields;
|
||||
};
|
||||
|
||||
|
@ -961,8 +877,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(ScheduleExpr);
|
||||
|
||||
Expr* when;
|
||||
EventExpr* event;
|
||||
};
|
||||
|
@ -977,8 +891,6 @@ protected:
|
|||
|
||||
Val* Fold(Val* v1, Val* v2) const override;
|
||||
|
||||
DECLARE_SERIAL(InExpr);
|
||||
|
||||
};
|
||||
|
||||
class CallExpr : public Expr {
|
||||
|
@ -1001,8 +913,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(CallExpr);
|
||||
|
||||
Expr* func;
|
||||
ListExpr* args;
|
||||
};
|
||||
|
@ -1026,8 +936,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(EventExpr);
|
||||
|
||||
string name;
|
||||
EventHandlerPtr handler;
|
||||
ListExpr* args;
|
||||
|
@ -1064,8 +972,6 @@ protected:
|
|||
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(ListExpr);
|
||||
|
||||
expr_list exprs;
|
||||
};
|
||||
|
||||
|
@ -1079,8 +985,6 @@ public:
|
|||
protected:
|
||||
friend class Expr;
|
||||
RecordAssignExpr() { }
|
||||
|
||||
DECLARE_SERIAL(RecordAssignExpr);
|
||||
};
|
||||
|
||||
class CastExpr : public UnaryExpr {
|
||||
|
@ -1093,8 +997,6 @@ protected:
|
|||
|
||||
Val* Eval(Frame* f) const override;
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(CastExpr);
|
||||
};
|
||||
|
||||
class IsExpr : public UnaryExpr {
|
||||
|
@ -1108,7 +1010,6 @@ protected:
|
|||
|
||||
Val* Fold(Val* v) const override;
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
DECLARE_SERIAL(IsExpr);
|
||||
|
||||
private:
|
||||
BroType* t;
|
||||
|
|
142
src/File.cc
142
src/File.cc
|
@ -30,7 +30,6 @@
|
|||
#include "Expr.h"
|
||||
#include "NetVar.h"
|
||||
#include "Net.h"
|
||||
#include "Serializer.h"
|
||||
#include "Event.h"
|
||||
#include "Reporter.h"
|
||||
|
||||
|
@ -828,11 +827,6 @@ void BroFile::UpdateFileSize()
|
|||
current_size = double(s.st_size);
|
||||
}
|
||||
|
||||
bool BroFile::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
BroFile* BroFile::GetFile(const char* name)
|
||||
{
|
||||
for ( BroFile* f = head; f; f = f->next )
|
||||
|
@ -844,139 +838,3 @@ BroFile* BroFile::GetFile(const char* name)
|
|||
return new BroFile(name, "w", 0);
|
||||
}
|
||||
|
||||
BroFile* BroFile::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
BroFile* file = (BroFile*) SerialObj::Unserialize(info, SER_BRO_FILE);
|
||||
|
||||
if ( ! file )
|
||||
return 0;
|
||||
|
||||
if ( file->is_open )
|
||||
return file;
|
||||
|
||||
// If there is already an object for this file, return it.
|
||||
if ( file->name )
|
||||
{
|
||||
for ( BroFile* f = head; f; f = f->next )
|
||||
{
|
||||
if ( f->name && streq(file->name, f->name) )
|
||||
{
|
||||
Unref(file);
|
||||
Ref(f);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, open, but don't clobber.
|
||||
if ( ! file->Open(0, "a") )
|
||||
{
|
||||
info->s->Error(fmt("cannot open %s: %s",
|
||||
file->name, strerror(errno)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Here comes a hack. This method will return a pointer to a newly
|
||||
// instantiated file object. As soon as this pointer is Unref'ed, the
|
||||
// file will be closed. That means that when we unserialize the same
|
||||
// file next time, we will re-open it and thereby delete the first one,
|
||||
// i.e., we will be keeping to delete what we've written just before.
|
||||
//
|
||||
// To avoid this loop, we do an extra Ref here, i.e., this file will
|
||||
// *never* be closed anymore (as long the file cache does not overflow).
|
||||
Ref(file);
|
||||
|
||||
// We deliberately override log rotation attributes with our defaults.
|
||||
file->rotate_interval = log_rotate_interval;
|
||||
file->rotate_size = log_max_size;
|
||||
file->InstallRotateTimer();
|
||||
file->SetBuf(file->buffered);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BroFile, SER_BRO_FILE);
|
||||
|
||||
bool BroFile::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BRO_FILE, BroObj);
|
||||
|
||||
const char* s = name;
|
||||
|
||||
if ( ! okay_to_manage )
|
||||
{
|
||||
// We can handle stdin/stdout/stderr but no others.
|
||||
if ( f == stdin )
|
||||
s = "/dev/stdin";
|
||||
else if ( f == stdout )
|
||||
s = "/dev/stdout";
|
||||
else if ( f == stderr )
|
||||
s = "/dev/stderr";
|
||||
else
|
||||
{
|
||||
// We don't manage the file, and therefore don't
|
||||
// really know how to pass it on to the other side.
|
||||
// However, in order to not abort communication
|
||||
// when this happens, we still send the name if we
|
||||
// have one; or if we don't, we create a special
|
||||
// "dont-have-a-file" file to be created on the
|
||||
// receiver side.
|
||||
if ( ! s )
|
||||
s = "unmanaged-bro-output-file.log";
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! (SERIALIZE(s) && SERIALIZE(buffered)) )
|
||||
return false;
|
||||
|
||||
SERIALIZE_OPTIONAL_STR(access);
|
||||
|
||||
if ( ! t->Serialize(info) )
|
||||
return false;
|
||||
|
||||
SERIALIZE_OPTIONAL(attrs);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BroFile::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroObj);
|
||||
|
||||
if ( ! (UNSERIALIZE_STR(&name, 0) && UNSERIALIZE(&buffered)) )
|
||||
return false;
|
||||
|
||||
UNSERIALIZE_OPTIONAL_STR(access);
|
||||
|
||||
t = BroType::Unserialize(info);
|
||||
if ( ! t )
|
||||
return false;
|
||||
|
||||
UNSERIALIZE_OPTIONAL(attrs, Attributes::Unserialize(info));
|
||||
|
||||
// Parse attributes.
|
||||
SetAttrs(attrs);
|
||||
// SetAttrs() has ref'ed attrs again.
|
||||
Unref(attrs);
|
||||
|
||||
// Bind stdin/stdout/stderr.
|
||||
FILE* file = 0;
|
||||
is_open = false;
|
||||
f = 0;
|
||||
|
||||
if ( streq(name, "/dev/stdin") )
|
||||
file = stdin;
|
||||
else if ( streq(name, "/dev/stdout") )
|
||||
file = stdout;
|
||||
else if ( streq(name, "/dev/stderr") )
|
||||
file = stderr;
|
||||
|
||||
if ( file )
|
||||
{
|
||||
delete [] name;
|
||||
name = 0;
|
||||
f = file;
|
||||
is_open = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -79,9 +79,6 @@ public:
|
|||
void EnableRawOutput() { raw_output = true; }
|
||||
bool IsRawOutput() const { return raw_output; }
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static BroFile* Unserialize(UnserialInfo* info);
|
||||
|
||||
protected:
|
||||
friend class RotateTimer;
|
||||
|
||||
|
@ -124,8 +121,6 @@ protected:
|
|||
// Finalize encryption.
|
||||
void FinishEncrypt();
|
||||
|
||||
DECLARE_SERIAL(BroFile);
|
||||
|
||||
FILE* f;
|
||||
BroType* t;
|
||||
char* name;
|
||||
|
|
134
src/Func.cc
134
src/Func.cc
|
@ -41,7 +41,6 @@
|
|||
#include "analyzer/protocol/login/Login.h"
|
||||
#include "Sessions.h"
|
||||
#include "RE.h"
|
||||
#include "Serializer.h"
|
||||
#include "Event.h"
|
||||
#include "Traverse.h"
|
||||
#include "Reporter.h"
|
||||
|
@ -127,110 +126,6 @@ void Func::AddBody(Stmt* /* new_body */, id_list* /* new_inits */,
|
|||
Internal("Func::AddBody called");
|
||||
}
|
||||
|
||||
bool Func::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Func* Func::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
Func* f = (Func*) SerialObj::Unserialize(info, SER_FUNC);
|
||||
|
||||
// For builtins, we return a reference to the (hopefully) already
|
||||
// existing function.
|
||||
if ( f && f->kind == BUILTIN_FUNC )
|
||||
{
|
||||
const char* name = ((BuiltinFunc*) f)->Name();
|
||||
ID* id = global_scope()->Lookup(name);
|
||||
if ( ! id )
|
||||
{
|
||||
info->s->Error(fmt("can't find built-in %s", name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( ! (id->HasVal() && id->ID_Val()->Type()->Tag() == TYPE_FUNC) )
|
||||
{
|
||||
info->s->Error(fmt("ID %s is not a built-in", name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
Unref(f);
|
||||
f = id->ID_Val()->AsFunc();
|
||||
Ref(f);
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
bool Func::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_FUNC, BroObj);
|
||||
|
||||
if ( ! SERIALIZE(int(bodies.size())) )
|
||||
return false;
|
||||
|
||||
for ( unsigned int i = 0; i < bodies.size(); ++i )
|
||||
{
|
||||
if ( ! bodies[i].stmts->Serialize(info) )
|
||||
return false;
|
||||
if ( ! SERIALIZE(bodies[i].priority) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! SERIALIZE(char(kind) ) )
|
||||
return false;
|
||||
|
||||
if ( ! type->Serialize(info) )
|
||||
return false;
|
||||
|
||||
if ( ! SERIALIZE(Name()) )
|
||||
return false;
|
||||
|
||||
// We don't serialize scope as only global functions are considered here
|
||||
// anyway.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Func::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroObj);
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
return false;
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
Body b;
|
||||
b.stmts = Stmt::Unserialize(info);
|
||||
if ( ! b.stmts )
|
||||
return false;
|
||||
|
||||
if ( ! UNSERIALIZE(&b.priority) )
|
||||
return false;
|
||||
|
||||
bodies.push_back(b);
|
||||
}
|
||||
|
||||
char c;
|
||||
if ( ! UNSERIALIZE(&c) )
|
||||
return false;
|
||||
|
||||
kind = (Kind) c;
|
||||
|
||||
type = BroType::Unserialize(info);
|
||||
if ( ! type )
|
||||
return false;
|
||||
|
||||
const char* n;
|
||||
if ( ! UNSERIALIZE_STR(&n, 0) )
|
||||
return false;
|
||||
|
||||
name = n;
|
||||
delete [] n;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Func::DescribeDebug(ODesc* d, const val_list* args) const
|
||||
{
|
||||
|
@ -584,21 +479,6 @@ Stmt* BroFunc::AddInits(Stmt* body, id_list* inits)
|
|||
return stmt_series;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BroFunc, SER_BRO_FUNC);
|
||||
|
||||
bool BroFunc::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BRO_FUNC, Func);
|
||||
return SERIALIZE(frame_size);
|
||||
}
|
||||
|
||||
bool BroFunc::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Func);
|
||||
|
||||
return UNSERIALIZE(&frame_size);
|
||||
}
|
||||
|
||||
BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name,
|
||||
int arg_is_pure)
|
||||
: Func(BUILTIN_FUNC)
|
||||
|
@ -681,20 +561,6 @@ void BuiltinFunc::Describe(ODesc* d) const
|
|||
d->AddCount(is_pure);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BuiltinFunc, SER_BUILTIN_FUNC);
|
||||
|
||||
bool BuiltinFunc::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BUILTIN_FUNC, Func);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BuiltinFunc::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Func);
|
||||
return true;
|
||||
}
|
||||
|
||||
void builtin_error(const char* msg, BroObj* arg)
|
||||
{
|
||||
auto emit = [=](const CallExpr* ce)
|
||||
|
|
10
src/Func.h
10
src/Func.h
|
@ -59,10 +59,6 @@ public:
|
|||
void Describe(ODesc* d) const override = 0;
|
||||
virtual void DescribeDebug(ODesc* d, const val_list* args) const;
|
||||
|
||||
// This (un-)serializes only a single body (as given in SerialInfo).
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Func* Unserialize(UnserialInfo* info);
|
||||
|
||||
virtual TraversalCode Traverse(TraversalCallback* cb) const;
|
||||
|
||||
uint32 GetUniqueFuncID() const { return unique_id; }
|
||||
|
@ -75,8 +71,6 @@ protected:
|
|||
// Helper function for handling result of plugin hook.
|
||||
std::pair<bool, Val*> HandlePluginResult(std::pair<bool, Val*> plugin_result, val_list* args, function_flavor flavor) const;
|
||||
|
||||
DECLARE_ABSTRACT_SERIAL(Func);
|
||||
|
||||
vector<Body> bodies;
|
||||
Scope* scope;
|
||||
Kind kind;
|
||||
|
@ -106,8 +100,6 @@ protected:
|
|||
BroFunc() : Func(BRO_FUNC) {}
|
||||
Stmt* AddInits(Stmt* body, id_list* inits);
|
||||
|
||||
DECLARE_SERIAL(BroFunc);
|
||||
|
||||
int frame_size;
|
||||
};
|
||||
|
||||
|
@ -127,8 +119,6 @@ public:
|
|||
protected:
|
||||
BuiltinFunc() { func = 0; is_pure = 0; }
|
||||
|
||||
DECLARE_SERIAL(BuiltinFunc);
|
||||
|
||||
built_in_func func;
|
||||
int is_pure;
|
||||
};
|
||||
|
|
205
src/ID.cc
205
src/ID.cc
|
@ -9,7 +9,6 @@
|
|||
#include "Func.h"
|
||||
#include "Scope.h"
|
||||
#include "File.h"
|
||||
#include "Serializer.h"
|
||||
#include "Scope.h"
|
||||
#include "Traverse.h"
|
||||
#include "zeekygen/Manager.h"
|
||||
|
@ -293,11 +292,6 @@ void ID::EvalFunc(Expr* ef, Expr* ev)
|
|||
Unref(ce);
|
||||
}
|
||||
|
||||
bool ID::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return (ID*) SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void ID::CopyFrom(const ID* id)
|
||||
{
|
||||
|
@ -330,205 +324,6 @@ void ID::CopyFrom(const ID* id)
|
|||
#endif
|
||||
#endif
|
||||
|
||||
ID* ID::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
ID* id = (ID*) SerialObj::Unserialize(info, SER_ID);
|
||||
if ( ! id )
|
||||
return 0;
|
||||
|
||||
if ( ! id->IsGlobal() )
|
||||
return id;
|
||||
|
||||
// Globals.
|
||||
ID* current = global_scope()->Lookup(id->name);
|
||||
|
||||
if ( ! current )
|
||||
{
|
||||
if ( ! info->install_globals )
|
||||
{
|
||||
info->s->Error("undefined");
|
||||
Unref(id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ref(id);
|
||||
global_scope()->Insert(id->Name(), id);
|
||||
#ifdef USE_PERFTOOLS_DEBUG
|
||||
heap_checker->IgnoreObject(id);
|
||||
#endif
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
switch ( info->id_policy ) {
|
||||
|
||||
case UnserialInfo::Keep:
|
||||
Unref(id);
|
||||
Ref(current);
|
||||
id = current;
|
||||
break;
|
||||
|
||||
case UnserialInfo::Replace:
|
||||
Unref(current);
|
||||
Ref(id);
|
||||
global_scope()->Insert(id->Name(), id);
|
||||
break;
|
||||
|
||||
case UnserialInfo::CopyNewToCurrent:
|
||||
if ( ! same_type(current->type, id->type) )
|
||||
{
|
||||
info->s->Error("type mismatch");
|
||||
Unref(id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( ! current->weak_ref )
|
||||
Unref(current->val);
|
||||
|
||||
current->val = id->val;
|
||||
current->weak_ref = id->weak_ref;
|
||||
if ( current->val && ! current->weak_ref )
|
||||
Ref(current->val);
|
||||
|
||||
#ifdef DEBUG
|
||||
current->UpdateValID();
|
||||
#endif
|
||||
|
||||
Unref(id);
|
||||
Ref(current);
|
||||
id = current;
|
||||
|
||||
break;
|
||||
|
||||
case UnserialInfo::CopyCurrentToNew:
|
||||
if ( ! same_type(current->type, id->type) )
|
||||
{
|
||||
info->s->Error("type mismatch");
|
||||
return 0;
|
||||
}
|
||||
if ( ! id->weak_ref )
|
||||
Unref(id->val);
|
||||
id->val = current->val;
|
||||
id->weak_ref = current->weak_ref;
|
||||
if ( id->val && ! id->weak_ref )
|
||||
Ref(id->val);
|
||||
|
||||
#ifdef DEBUG
|
||||
id->UpdateValID();
|
||||
#endif
|
||||
|
||||
Unref(current);
|
||||
Ref(id);
|
||||
global_scope()->Insert(id->Name(), id);
|
||||
break;
|
||||
|
||||
case UnserialInfo::InstantiateNew:
|
||||
// Do nothing.
|
||||
break;
|
||||
|
||||
default:
|
||||
reporter->InternalError("unknown type for UnserialInfo::id_policy");
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(ID, SER_ID);
|
||||
|
||||
bool ID::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE_WITH_SUSPEND(SER_ID, BroObj);
|
||||
|
||||
if ( info->cont.NewInstance() )
|
||||
{
|
||||
DisableSuspend suspend(info);
|
||||
|
||||
info->s->WriteOpenTag("ID");
|
||||
|
||||
if ( ! (SERIALIZE(name) &&
|
||||
SERIALIZE(char(scope)) &&
|
||||
SERIALIZE(is_export) &&
|
||||
SERIALIZE(is_const) &&
|
||||
SERIALIZE(is_enum_const) &&
|
||||
SERIALIZE(is_type) &&
|
||||
SERIALIZE(offset) &&
|
||||
SERIALIZE(infer_return_type) &&
|
||||
SERIALIZE(weak_ref) &&
|
||||
type->Serialize(info)) )
|
||||
return false;
|
||||
|
||||
SERIALIZE_OPTIONAL(attrs);
|
||||
}
|
||||
|
||||
SERIALIZE_OPTIONAL(val);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ID::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
bool installed_tmp = false;
|
||||
|
||||
DO_UNSERIALIZE(BroObj);
|
||||
|
||||
char id_scope;
|
||||
|
||||
if ( ! (UNSERIALIZE_STR(&name, 0) &&
|
||||
UNSERIALIZE(&id_scope) &&
|
||||
UNSERIALIZE(&is_export) &&
|
||||
UNSERIALIZE(&is_const) &&
|
||||
UNSERIALIZE(&is_enum_const) &&
|
||||
UNSERIALIZE(&is_type) &&
|
||||
UNSERIALIZE(&offset) &&
|
||||
UNSERIALIZE(&infer_return_type) &&
|
||||
UNSERIALIZE(&weak_ref)
|
||||
) )
|
||||
return false;
|
||||
|
||||
scope = IDScope(id_scope);
|
||||
|
||||
info->s->SetErrorDescr(fmt("unserializing ID %s", name));
|
||||
|
||||
type = BroType::Unserialize(info);
|
||||
if ( ! type )
|
||||
return false;
|
||||
|
||||
UNSERIALIZE_OPTIONAL(attrs, Attributes::Unserialize(info));
|
||||
|
||||
// If it's a global function not currently known,
|
||||
// we temporarily install it in global scope.
|
||||
// This is necessary for recursive functions.
|
||||
if ( IsGlobal() && Type()->Tag() == TYPE_FUNC )
|
||||
{
|
||||
ID* current = global_scope()->Lookup(name);
|
||||
if ( ! current )
|
||||
{
|
||||
installed_tmp = true;
|
||||
global_scope()->Insert(Name(), this);
|
||||
}
|
||||
}
|
||||
|
||||
UNSERIALIZE_OPTIONAL(val, Val::Unserialize(info));
|
||||
#ifdef DEBUG
|
||||
UpdateValID();
|
||||
#endif
|
||||
|
||||
if ( weak_ref )
|
||||
{
|
||||
// At this point at least the serialization cache will hold a
|
||||
// reference so this will not delete the val.
|
||||
assert(val->RefCnt() > 1);
|
||||
Unref(val);
|
||||
}
|
||||
|
||||
if ( installed_tmp && ! global_scope()->Remove(name) )
|
||||
reporter->InternalWarning("missing tmp ID in %s unserialization", name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TraversalCode ID::Traverse(TraversalCallback* cb) const
|
||||
{
|
||||
TraversalCode tc = cb->PreID(this);
|
||||
|
|
6
src/ID.h
6
src/ID.h
|
@ -10,7 +10,6 @@
|
|||
#include <string>
|
||||
|
||||
class Val;
|
||||
class SerialInfo;
|
||||
class Func;
|
||||
|
||||
typedef enum { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, } init_class;
|
||||
|
@ -98,9 +97,6 @@ public:
|
|||
void DescribeReST(ODesc* d, bool roles_only = false) const;
|
||||
void DescribeReSTShort(ODesc* d) const;
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static ID* Unserialize(UnserialInfo* info);
|
||||
|
||||
bool DoInferReturnType() const
|
||||
{ return infer_return_type; }
|
||||
void SetInferReturnType(bool infer)
|
||||
|
@ -124,8 +120,6 @@ protected:
|
|||
void UpdateValID();
|
||||
#endif
|
||||
|
||||
DECLARE_SERIAL(ID);
|
||||
|
||||
const char* name;
|
||||
IDScope scope;
|
||||
bool is_export;
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "Reporter.h"
|
||||
#include "Net.h"
|
||||
#include "Anon.h"
|
||||
#include "Serializer.h"
|
||||
#include "PacketDumper.h"
|
||||
#include "iosource/Manager.h"
|
||||
#include "iosource/PktSrc.h"
|
||||
|
|
65
src/Obj.cc
65
src/Obj.cc
|
@ -5,7 +5,6 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "Obj.h"
|
||||
#include "Serializer.h"
|
||||
#include "Func.h"
|
||||
#include "File.h"
|
||||
#include "plugin/Manager.h"
|
||||
|
@ -14,47 +13,6 @@ Location no_location("<no location>", 0, 0, 0, 0);
|
|||
Location start_location("<start uninitialized>", 0, 0, 0, 0);
|
||||
Location end_location("<end uninitialized>", 0, 0, 0, 0);
|
||||
|
||||
bool Location::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Location* Location::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return (Location*) SerialObj::Unserialize(info, SER_LOCATION);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(Location, SER_LOCATION);
|
||||
|
||||
bool Location::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_LOCATION, SerialObj);
|
||||
info->s->WriteOpenTag("Location");
|
||||
|
||||
if ( ! (SERIALIZE(filename) &&
|
||||
SERIALIZE(first_line) &&
|
||||
SERIALIZE(last_line) &&
|
||||
SERIALIZE(first_column) &&
|
||||
SERIALIZE(last_column)) )
|
||||
return false;
|
||||
|
||||
info->s->WriteCloseTag("Location");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Location::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
delete_data = true;
|
||||
|
||||
return UNSERIALIZE_STR(&filename, 0)
|
||||
&& UNSERIALIZE(&first_line)
|
||||
&& UNSERIALIZE(&last_line)
|
||||
&& UNSERIALIZE(&first_column)
|
||||
&& UNSERIALIZE(&last_column);
|
||||
}
|
||||
|
||||
void Location::Describe(ODesc* d) const
|
||||
{
|
||||
if ( filename )
|
||||
|
@ -228,29 +186,6 @@ void BroObj::PinPoint(ODesc* d, const BroObj* obj2, int pinpoint_only) const
|
|||
d->Add(")");
|
||||
}
|
||||
|
||||
bool BroObj::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BRO_OBJ, SerialObj);
|
||||
|
||||
info->s->WriteOpenTag("Object");
|
||||
|
||||
Location* loc = info->include_locations ? location : 0;
|
||||
SERIALIZE_OPTIONAL(loc);
|
||||
info->s->WriteCloseTag("Object");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BroObj::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
delete location;
|
||||
|
||||
UNSERIALIZE_OPTIONAL(location, Location::Unserialize(info));
|
||||
return true;
|
||||
}
|
||||
|
||||
void print(const BroObj* obj)
|
||||
{
|
||||
static BroFile fstderr(stderr);
|
||||
|
|
21
src/Obj.h
21
src/Obj.h
|
@ -7,12 +7,8 @@
|
|||
|
||||
#include "input.h"
|
||||
#include "Desc.h"
|
||||
#include "SerialObj.h"
|
||||
|
||||
class Serializer;
|
||||
class SerialInfo;
|
||||
|
||||
class Location : SerialObj {
|
||||
class Location {
|
||||
public:
|
||||
Location(const char* fname, int line_f, int line_l, int col_f, int col_l)
|
||||
{
|
||||
|
@ -36,7 +32,7 @@ public:
|
|||
text = 0;
|
||||
}
|
||||
|
||||
~Location() override
|
||||
virtual ~Location()
|
||||
{
|
||||
if ( delete_data )
|
||||
delete [] filename;
|
||||
|
@ -44,9 +40,6 @@ public:
|
|||
|
||||
void Describe(ODesc* d) const;
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Location* Unserialize(UnserialInfo* info);
|
||||
|
||||
bool operator==(const Location& l) const;
|
||||
bool operator!=(const Location& l) const
|
||||
{ return ! (*this == l); }
|
||||
|
@ -59,8 +52,6 @@ public:
|
|||
// Timestamp and text for compatibility with Bison's default yyltype.
|
||||
int timestamp;
|
||||
char* text;
|
||||
protected:
|
||||
DECLARE_SERIAL(Location);
|
||||
};
|
||||
|
||||
#define YYLTYPE yyltype
|
||||
|
@ -86,7 +77,7 @@ inline void set_location(const Location start, const Location end)
|
|||
end_location = end;
|
||||
}
|
||||
|
||||
class BroObj : public SerialObj {
|
||||
class BroObj {
|
||||
public:
|
||||
BroObj()
|
||||
{
|
||||
|
@ -112,7 +103,7 @@ public:
|
|||
SetLocationInfo(&start_location, &end_location);
|
||||
}
|
||||
|
||||
~BroObj() override;
|
||||
virtual ~BroObj();
|
||||
|
||||
// Report user warnings/errors. If obj2 is given, then it's
|
||||
// included in the message, though if pinpoint_only is non-zero,
|
||||
|
@ -168,10 +159,6 @@ public:
|
|||
bool in_ser_cache;
|
||||
|
||||
protected:
|
||||
friend class SerializationCache;
|
||||
|
||||
DECLARE_ABSTRACT_SERIAL(BroObj);
|
||||
|
||||
Location* location; // all that matters in real estate
|
||||
|
||||
private:
|
||||
|
|
359
src/OpaqueVal.cc
359
src/OpaqueVal.cc
|
@ -3,7 +3,6 @@
|
|||
#include "OpaqueVal.h"
|
||||
#include "NetVar.h"
|
||||
#include "Reporter.h"
|
||||
#include "Serializer.h"
|
||||
#include "probabilistic/BloomFilter.h"
|
||||
#include "probabilistic/CardinalityCounter.h"
|
||||
|
||||
|
@ -63,20 +62,6 @@ HashVal::HashVal(OpaqueType* t) : OpaqueVal(t)
|
|||
valid = false;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(HashVal, SER_HASH_VAL);
|
||||
|
||||
bool HashVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_HASH_VAL, OpaqueVal);
|
||||
return SERIALIZE(valid);
|
||||
}
|
||||
|
||||
bool HashVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
return UNSERIALIZE(&valid);
|
||||
}
|
||||
|
||||
MD5Val::MD5Val() : HashVal(md5_type)
|
||||
{
|
||||
}
|
||||
|
@ -147,67 +132,6 @@ StringVal* MD5Val::DoGet()
|
|||
return new StringVal(md5_digest_print(digest));
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(MD5Val, SER_MD5_VAL);
|
||||
|
||||
bool MD5Val::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_MD5_VAL, HashVal);
|
||||
|
||||
if ( ! IsValid() )
|
||||
return true;
|
||||
|
||||
MD5_CTX* md = (MD5_CTX*) EVP_MD_CTX_md_data(ctx);
|
||||
|
||||
if ( ! (SERIALIZE(md->A) &&
|
||||
SERIALIZE(md->B) &&
|
||||
SERIALIZE(md->C) &&
|
||||
SERIALIZE(md->D) &&
|
||||
SERIALIZE(md->Nl) &&
|
||||
SERIALIZE(md->Nh)) )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < MD5_LBLOCK; ++i )
|
||||
{
|
||||
if ( ! SERIALIZE(md->data[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! SERIALIZE(md->num) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MD5Val::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(HashVal);
|
||||
|
||||
if ( ! IsValid() )
|
||||
return true;
|
||||
|
||||
ctx = hash_init(Hash_MD5);
|
||||
MD5_CTX* md = (MD5_CTX*) EVP_MD_CTX_md_data(ctx);
|
||||
|
||||
if ( ! (UNSERIALIZE(&md->A) &&
|
||||
UNSERIALIZE(&md->B) &&
|
||||
UNSERIALIZE(&md->C) &&
|
||||
UNSERIALIZE(&md->D) &&
|
||||
UNSERIALIZE(&md->Nl) &&
|
||||
UNSERIALIZE(&md->Nh)) )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < MD5_LBLOCK; ++i )
|
||||
{
|
||||
if ( ! UNSERIALIZE(&md->data[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! UNSERIALIZE(&md->num) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SHA1Val::SHA1Val() : HashVal(sha1_type)
|
||||
{
|
||||
}
|
||||
|
@ -267,69 +191,6 @@ StringVal* SHA1Val::DoGet()
|
|||
return new StringVal(sha1_digest_print(digest));
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(SHA1Val, SER_SHA1_VAL);
|
||||
|
||||
bool SHA1Val::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_SHA1_VAL, HashVal);
|
||||
|
||||
if ( ! IsValid() )
|
||||
return true;
|
||||
|
||||
SHA_CTX* md = (SHA_CTX*) EVP_MD_CTX_md_data(ctx);
|
||||
|
||||
if ( ! (SERIALIZE(md->h0) &&
|
||||
SERIALIZE(md->h1) &&
|
||||
SERIALIZE(md->h2) &&
|
||||
SERIALIZE(md->h3) &&
|
||||
SERIALIZE(md->h4) &&
|
||||
SERIALIZE(md->Nl) &&
|
||||
SERIALIZE(md->Nh)) )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < SHA_LBLOCK; ++i )
|
||||
{
|
||||
if ( ! SERIALIZE(md->data[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! SERIALIZE(md->num) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHA1Val::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(HashVal);
|
||||
|
||||
if ( ! IsValid() )
|
||||
return true;
|
||||
|
||||
ctx = hash_init(Hash_SHA1);
|
||||
SHA_CTX* md = (SHA_CTX*) EVP_MD_CTX_md_data(ctx);
|
||||
|
||||
if ( ! (UNSERIALIZE(&md->h0) &&
|
||||
UNSERIALIZE(&md->h1) &&
|
||||
UNSERIALIZE(&md->h2) &&
|
||||
UNSERIALIZE(&md->h3) &&
|
||||
UNSERIALIZE(&md->h4) &&
|
||||
UNSERIALIZE(&md->Nl) &&
|
||||
UNSERIALIZE(&md->Nh)) )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < SHA_LBLOCK; ++i )
|
||||
{
|
||||
if ( ! UNSERIALIZE(&md->data[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! UNSERIALIZE(&md->num) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SHA256Val::SHA256Val() : HashVal(sha256_type)
|
||||
{
|
||||
}
|
||||
|
@ -389,74 +250,6 @@ StringVal* SHA256Val::DoGet()
|
|||
return new StringVal(sha256_digest_print(digest));
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(SHA256Val, SER_SHA256_VAL);
|
||||
|
||||
bool SHA256Val::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_SHA256_VAL, HashVal);
|
||||
|
||||
if ( ! IsValid() )
|
||||
return true;
|
||||
|
||||
SHA256_CTX* md = (SHA256_CTX*) EVP_MD_CTX_md_data(ctx);
|
||||
|
||||
for ( int i = 0; i < 8; ++i )
|
||||
{
|
||||
if ( ! SERIALIZE(md->h[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! (SERIALIZE(md->Nl) &&
|
||||
SERIALIZE(md->Nh)) )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < SHA_LBLOCK; ++i )
|
||||
{
|
||||
if ( ! SERIALIZE(md->data[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! (SERIALIZE(md->num) &&
|
||||
SERIALIZE(md->md_len)) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHA256Val::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(HashVal);
|
||||
|
||||
if ( ! IsValid() )
|
||||
return true;
|
||||
|
||||
ctx = hash_init(Hash_SHA256);
|
||||
SHA256_CTX* md = (SHA256_CTX*) EVP_MD_CTX_md_data(ctx);
|
||||
|
||||
for ( int i = 0; i < 8; ++i )
|
||||
{
|
||||
if ( ! UNSERIALIZE(&md->h[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! (UNSERIALIZE(&md->Nl) &&
|
||||
UNSERIALIZE(&md->Nh)) )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < SHA_LBLOCK; ++i )
|
||||
{
|
||||
if ( ! UNSERIALIZE(&md->data[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ( ! (UNSERIALIZE(&md->num) &&
|
||||
UNSERIALIZE(&md->md_len)) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
EntropyVal::EntropyVal() : OpaqueVal(entropy_type)
|
||||
{
|
||||
}
|
||||
|
@ -474,82 +267,6 @@ bool EntropyVal::Get(double *r_ent, double *r_chisq, double *r_mean,
|
|||
return true;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(EntropyVal, SER_ENTROPY_VAL);
|
||||
|
||||
bool EntropyVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_ENTROPY_VAL, OpaqueVal);
|
||||
|
||||
for ( int i = 0; i < 256; ++i )
|
||||
{
|
||||
if ( ! SERIALIZE(state.ccount[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! (SERIALIZE(state.totalc) &&
|
||||
SERIALIZE(state.mp) &&
|
||||
SERIALIZE(state.sccfirst)) )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < RT_MONTEN; ++i )
|
||||
{
|
||||
if ( ! SERIALIZE(state.monte[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! (SERIALIZE(state.inmont) &&
|
||||
SERIALIZE(state.mcount) &&
|
||||
SERIALIZE(state.cexp) &&
|
||||
SERIALIZE(state.montex) &&
|
||||
SERIALIZE(state.montey) &&
|
||||
SERIALIZE(state.montepi) &&
|
||||
SERIALIZE(state.sccu0) &&
|
||||
SERIALIZE(state.scclast) &&
|
||||
SERIALIZE(state.scct1) &&
|
||||
SERIALIZE(state.scct2) &&
|
||||
SERIALIZE(state.scct3)) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EntropyVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
|
||||
for ( int i = 0; i < 256; ++i )
|
||||
{
|
||||
if ( ! UNSERIALIZE(&state.ccount[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! (UNSERIALIZE(&state.totalc) &&
|
||||
UNSERIALIZE(&state.mp) &&
|
||||
UNSERIALIZE(&state.sccfirst)) )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < RT_MONTEN; ++i )
|
||||
{
|
||||
if ( ! UNSERIALIZE(&state.monte[i]) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! (UNSERIALIZE(&state.inmont) &&
|
||||
UNSERIALIZE(&state.mcount) &&
|
||||
UNSERIALIZE(&state.cexp) &&
|
||||
UNSERIALIZE(&state.montex) &&
|
||||
UNSERIALIZE(&state.montey) &&
|
||||
UNSERIALIZE(&state.montepi) &&
|
||||
UNSERIALIZE(&state.sccu0) &&
|
||||
UNSERIALIZE(&state.scclast) &&
|
||||
UNSERIALIZE(&state.scct1) &&
|
||||
UNSERIALIZE(&state.scct2) &&
|
||||
UNSERIALIZE(&state.scct3)) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BloomFilterVal::BloomFilterVal()
|
||||
: OpaqueVal(bloomfilter_type)
|
||||
{
|
||||
|
@ -668,44 +385,6 @@ BloomFilterVal::~BloomFilterVal()
|
|||
delete bloom_filter;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BloomFilterVal, SER_BLOOMFILTER_VAL);
|
||||
|
||||
bool BloomFilterVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BLOOMFILTER_VAL, OpaqueVal);
|
||||
|
||||
bool is_typed = (type != 0);
|
||||
|
||||
if ( ! SERIALIZE(is_typed) )
|
||||
return false;
|
||||
|
||||
if ( is_typed && ! type->Serialize(info) )
|
||||
return false;
|
||||
|
||||
return bloom_filter->Serialize(info);
|
||||
}
|
||||
|
||||
bool BloomFilterVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
|
||||
bool is_typed;
|
||||
if ( ! UNSERIALIZE(&is_typed) )
|
||||
return false;
|
||||
|
||||
if ( is_typed )
|
||||
{
|
||||
BroType* t = BroType::Unserialize(info);
|
||||
if ( ! Typify(t) )
|
||||
return false;
|
||||
|
||||
Unref(t);
|
||||
}
|
||||
|
||||
bloom_filter = probabilistic::BloomFilter::Unserialize(info);
|
||||
return bloom_filter != 0;
|
||||
}
|
||||
|
||||
CardinalityVal::CardinalityVal() : OpaqueVal(cardinality_type)
|
||||
{
|
||||
c = 0;
|
||||
|
@ -728,44 +407,6 @@ CardinalityVal::~CardinalityVal()
|
|||
delete hash;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(CardinalityVal, SER_CARDINALITY_VAL);
|
||||
|
||||
bool CardinalityVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_CARDINALITY_VAL, OpaqueVal);
|
||||
|
||||
bool valid = true;
|
||||
bool is_typed = (type != 0);
|
||||
|
||||
valid &= SERIALIZE(is_typed);
|
||||
|
||||
if ( is_typed )
|
||||
valid &= type->Serialize(info);
|
||||
|
||||
return c->Serialize(info);
|
||||
}
|
||||
|
||||
bool CardinalityVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
|
||||
bool is_typed;
|
||||
if ( ! UNSERIALIZE(&is_typed) )
|
||||
return false;
|
||||
|
||||
if ( is_typed )
|
||||
{
|
||||
BroType* t = BroType::Unserialize(info);
|
||||
if ( ! Typify(t) )
|
||||
return false;
|
||||
|
||||
Unref(t);
|
||||
}
|
||||
|
||||
c = probabilistic::CardinalityCounter::Unserialize(info);
|
||||
return c != 0;
|
||||
}
|
||||
|
||||
bool CardinalityVal::Typify(BroType* arg_type)
|
||||
{
|
||||
if ( type )
|
||||
|
|
|
@ -29,8 +29,6 @@ protected:
|
|||
virtual bool DoFeed(const void* data, size_t size);
|
||||
virtual StringVal* DoGet();
|
||||
|
||||
DECLARE_SERIAL(HashVal);
|
||||
|
||||
private:
|
||||
// This flag exists because Get() can only be called once.
|
||||
bool valid;
|
||||
|
@ -54,8 +52,6 @@ protected:
|
|||
bool DoFeed(const void* data, size_t size) override;
|
||||
StringVal* DoGet() override;
|
||||
|
||||
DECLARE_SERIAL(MD5Val);
|
||||
|
||||
private:
|
||||
EVP_MD_CTX* ctx;
|
||||
};
|
||||
|
@ -74,8 +70,6 @@ protected:
|
|||
bool DoFeed(const void* data, size_t size) override;
|
||||
StringVal* DoGet() override;
|
||||
|
||||
DECLARE_SERIAL(SHA1Val);
|
||||
|
||||
private:
|
||||
EVP_MD_CTX* ctx;
|
||||
};
|
||||
|
@ -94,8 +88,6 @@ protected:
|
|||
bool DoFeed(const void* data, size_t size) override;
|
||||
StringVal* DoGet() override;
|
||||
|
||||
DECLARE_SERIAL(SHA256Val);
|
||||
|
||||
private:
|
||||
EVP_MD_CTX* ctx;
|
||||
};
|
||||
|
@ -111,8 +103,6 @@ public:
|
|||
protected:
|
||||
friend class Val;
|
||||
|
||||
DECLARE_SERIAL(EntropyVal);
|
||||
|
||||
private:
|
||||
RandTest state;
|
||||
};
|
||||
|
@ -139,8 +129,6 @@ protected:
|
|||
BloomFilterVal();
|
||||
explicit BloomFilterVal(OpaqueType* t);
|
||||
|
||||
DECLARE_SERIAL(BloomFilterVal);
|
||||
|
||||
private:
|
||||
// Disable.
|
||||
BloomFilterVal(const BloomFilterVal&);
|
||||
|
@ -171,8 +159,6 @@ private:
|
|||
BroType* type;
|
||||
CompositeHash* hash;
|
||||
probabilistic::CardinalityCounter* c;
|
||||
|
||||
DECLARE_SERIAL(CardinalityVal);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
53
src/RE.cc
53
src/RE.cc
|
@ -9,7 +9,7 @@
|
|||
#include "DFA.h"
|
||||
#include "CCL.h"
|
||||
#include "EquivClass.h"
|
||||
#include "Serializer.h"
|
||||
#include "Reporter.h"
|
||||
|
||||
CCL* curr_ccl = 0;
|
||||
|
||||
|
@ -469,57 +469,6 @@ int RE_Matcher::Compile(int lazy)
|
|||
return re_anywhere->Compile(lazy) && re_exact->Compile(lazy);
|
||||
}
|
||||
|
||||
bool RE_Matcher::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
RE_Matcher* RE_Matcher::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return (RE_Matcher*) SerialObj::Unserialize(info, SER_RE_MATCHER);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(RE_Matcher, SER_RE_MATCHER);
|
||||
|
||||
bool RE_Matcher::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_RE_MATCHER, SerialObj);
|
||||
return SERIALIZE(re_anywhere->PatternText())
|
||||
&& SERIALIZE(re_exact->PatternText());
|
||||
}
|
||||
|
||||
bool RE_Matcher::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
re_anywhere = new Specific_RE_Matcher(MATCH_ANYWHERE);
|
||||
re_exact = new Specific_RE_Matcher(MATCH_EXACTLY);
|
||||
|
||||
const char* pat;
|
||||
if ( ! UNSERIALIZE_STR(&pat, 0) )
|
||||
return false;
|
||||
|
||||
re_anywhere->SetPat(pat);
|
||||
if ( ! re_anywhere->Compile() )
|
||||
{
|
||||
info->s->Error(fmt("Can't compile regexp '%s'", pat));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! UNSERIALIZE_STR(&pat, 0) )
|
||||
return false;
|
||||
|
||||
re_exact->SetPat(pat);
|
||||
if ( ! re_exact->Compile() )
|
||||
{
|
||||
info->s->Error(fmt("Can't compile regexp '%s'", pat));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static RE_Matcher* matcher_merge(const RE_Matcher* re1, const RE_Matcher* re2,
|
||||
const char* merge_op)
|
||||
{
|
||||
|
|
9
src/RE.h
9
src/RE.h
|
@ -171,12 +171,12 @@ protected:
|
|||
int current_pos;
|
||||
};
|
||||
|
||||
class RE_Matcher : SerialObj {
|
||||
class RE_Matcher {
|
||||
public:
|
||||
RE_Matcher();
|
||||
explicit RE_Matcher(const char* pat);
|
||||
RE_Matcher(const char* exact_pat, const char* anywhere_pat);
|
||||
virtual ~RE_Matcher() override;
|
||||
virtual ~RE_Matcher();
|
||||
|
||||
void AddPat(const char* pat);
|
||||
|
||||
|
@ -212,9 +212,6 @@ public:
|
|||
const char* PatternText() const { return re_exact->PatternText(); }
|
||||
const char* AnywherePatternText() const { return re_anywhere->PatternText(); }
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static RE_Matcher* Unserialize(UnserialInfo* info);
|
||||
|
||||
unsigned int MemoryAllocation() const
|
||||
{
|
||||
return padded_sizeof(*this)
|
||||
|
@ -223,8 +220,6 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(RE_Matcher);
|
||||
|
||||
Specific_RE_Matcher* re_anywhere;
|
||||
Specific_RE_Matcher* re_exact;
|
||||
};
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "bro-config.h"
|
||||
|
||||
#include "Reassem.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
static const bool DEBUG_reassem = false;
|
||||
|
||||
|
@ -357,37 +356,3 @@ uint64 Reassembler::MemoryAllocation(ReassemblerType rtype)
|
|||
return Reassembler::sizes[rtype];
|
||||
}
|
||||
|
||||
bool Reassembler::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Reassembler* Reassembler::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return (Reassembler*) SerialObj::Unserialize(info, SER_REASSEMBLER);
|
||||
}
|
||||
|
||||
bool Reassembler::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_REASSEMBLER, BroObj);
|
||||
|
||||
// I'm not sure if it makes sense to actually save the buffered data.
|
||||
// For now, we just remember the seq numbers so that we don't get
|
||||
// complaints about missing content.
|
||||
return SERIALIZE(trim_seq) && SERIALIZE(int(0));
|
||||
}
|
||||
|
||||
bool Reassembler::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroObj);
|
||||
|
||||
blocks = last_block = 0;
|
||||
|
||||
int dummy; // For backwards compatibility.
|
||||
if ( ! UNSERIALIZE(&trim_seq) || ! UNSERIALIZE(&dummy) )
|
||||
return false;
|
||||
|
||||
last_reassem_seq = trim_seq;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -62,9 +62,6 @@ public:
|
|||
|
||||
void Describe(ODesc* d) const override;
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Reassembler* Unserialize(UnserialInfo* info);
|
||||
|
||||
// Sum over all data buffered in some reassembler.
|
||||
static uint64 TotalMemoryAllocation() { return total_size; }
|
||||
|
||||
|
@ -76,8 +73,6 @@ public:
|
|||
protected:
|
||||
Reassembler() { }
|
||||
|
||||
DECLARE_ABSTRACT_SERIAL(Reassembler);
|
||||
|
||||
friend class DataBlock;
|
||||
|
||||
virtual void Undelivered(uint64 up_to_seq);
|
||||
|
|
|
@ -3,13 +3,10 @@
|
|||
#ifndef serialinfo_h
|
||||
#define serialinfo_h
|
||||
|
||||
#include "ChunkedIO.h"
|
||||
|
||||
class SerialInfo {
|
||||
public:
|
||||
SerialInfo(Serializer* arg_s)
|
||||
{
|
||||
chunk = 0;
|
||||
s = arg_s;
|
||||
may_suspend = clear_containers = false;
|
||||
cache = globals_as_names = true;
|
||||
|
@ -21,7 +18,6 @@ public:
|
|||
|
||||
SerialInfo(const SerialInfo& info)
|
||||
{
|
||||
chunk = info.chunk;
|
||||
s = info.s;
|
||||
may_suspend = info.may_suspend;
|
||||
cache = info.cache;
|
||||
|
@ -49,8 +45,6 @@ public:
|
|||
// If true, we support keeping objs in cache permanently.
|
||||
bool new_cache_strategy;
|
||||
|
||||
ChunkedIO::Chunk* chunk; // chunk written right before the serialization
|
||||
|
||||
// Attributes set during serialization.
|
||||
SerialType type; // type of currently serialized object
|
||||
|
||||
|
@ -65,7 +59,6 @@ public:
|
|||
s = arg_s;
|
||||
cache = true;
|
||||
type = SER_NONE;
|
||||
chunk = 0;
|
||||
install_globals = install_conns = true;
|
||||
install_uniques = false;
|
||||
ignore_callbacks = false;
|
||||
|
@ -80,7 +73,6 @@ public:
|
|||
s = info.s;
|
||||
cache = info.cache;
|
||||
type = info.type;
|
||||
chunk = info.chunk;
|
||||
install_globals = info.install_globals;
|
||||
install_uniques = info.install_uniques;
|
||||
install_conns = info.install_conns;
|
||||
|
@ -96,8 +88,6 @@ public:
|
|||
bool cache; // if true, object caching is ok
|
||||
FILE* print; // print read objects to given file (human-readable)
|
||||
|
||||
ChunkedIO::Chunk* chunk; // chunk to parse (rather than reading one)
|
||||
|
||||
bool install_globals; // if true, install unknown globals
|
||||
// in global scope
|
||||
bool install_conns; // if true, add connections to session table
|
||||
|
|
277
src/SerialObj.cc
277
src/SerialObj.cc
|
@ -1,277 +0,0 @@
|
|||
#include "SerialObj.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
TransientID::ID TransientID::counter = 0;
|
||||
|
||||
SerialObj::FactoryMap* SerialObj::factories = 0;
|
||||
SerialObj::ClassNameMap* SerialObj::names = 0;
|
||||
uint64 SerialObj::time_counter = NEVER + ALWAYS + 1;
|
||||
|
||||
SerialObj* SerialObj::Instantiate(SerialType type)
|
||||
{
|
||||
FactoryMap::iterator f = factories->find(type & SER_TYPE_MASK_EXACT);
|
||||
if ( f != factories->end() )
|
||||
{
|
||||
SerialObj* o = (SerialObj*) (*f->second)();
|
||||
#ifdef DEBUG
|
||||
o->serial_type = o->GetSerialType();
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
reporter->Error("Unknown object type 0x%08x", type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* SerialObj::ClassName(SerialType type)
|
||||
{
|
||||
ClassNameMap::iterator f = names->find(type);
|
||||
if ( f != names->end() )
|
||||
return f->second;
|
||||
|
||||
reporter->Error("Unknown object type 0x%08x", type);
|
||||
return "<no-class-name>";
|
||||
}
|
||||
|
||||
void SerialObj::Register(SerialType type, FactoryFunc f, const char* name)
|
||||
{
|
||||
if ( ! factories )
|
||||
{
|
||||
factories = new FactoryMap;
|
||||
names = new ClassNameMap;
|
||||
}
|
||||
|
||||
type = type & SER_TYPE_MASK_EXACT;
|
||||
|
||||
FactoryMap::iterator i = factories->find(type);
|
||||
if ( i != factories->end() )
|
||||
reporter->InternalError("SerialType 0x%08x registered twice", type);
|
||||
|
||||
(*factories)[type] = f;
|
||||
(*names)[type] = name;
|
||||
}
|
||||
|
||||
inline bool SerializePID(SerialInfo* info, bool full, SerializationCache::PermanentID pid)
|
||||
{
|
||||
if ( ! SERIALIZE(full) )
|
||||
return false;
|
||||
|
||||
if ( ! info->pid_32bit )
|
||||
return SERIALIZE(pid);
|
||||
|
||||
// Broccoli compatibility mode with 32bit pids.
|
||||
uint32 tmp = uint32(pid);
|
||||
return SERIALIZE(tmp);
|
||||
}
|
||||
|
||||
bool SerialObj::Serialize(SerialInfo* info) const
|
||||
{
|
||||
assert(info);
|
||||
|
||||
if ( info->cont.NewInstance() )
|
||||
{
|
||||
SerializationCache::PermanentID pid = SerializationCache::NONE;
|
||||
|
||||
const TransientID* tid = GetTID();
|
||||
|
||||
if ( ! tid )
|
||||
reporter->InternalError("no tid - missing DECLARE_SERIAL?");
|
||||
|
||||
if ( info->cache )
|
||||
pid = info->s->Cache()->Lookup(*tid);
|
||||
|
||||
if ( pid != SerializationCache::NONE && info->cache )
|
||||
{
|
||||
DBG_LOG(DBG_SERIAL, "%s [%p, ref pid %lld, tid %lld]", __PRETTY_FUNCTION__, this, (long long) pid, tid->Value() );
|
||||
|
||||
DBG_LOG(DBG_SERIAL, "-- Caching");
|
||||
DBG_PUSH(DBG_SERIAL);
|
||||
|
||||
if ( ! SerializePID(info, false, pid) )
|
||||
{
|
||||
DBG_POP(DBG_SERIAL);
|
||||
return false;
|
||||
}
|
||||
|
||||
DBG_POP(DBG_SERIAL);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( info->cache )
|
||||
pid = info->s->Cache()->Register(this,
|
||||
SerializationCache::NONE,
|
||||
info->new_cache_strategy);
|
||||
|
||||
DBG_LOG(DBG_SERIAL, "%s [%p, new pid %lld, tid %lld]", __PRETTY_FUNCTION__, this, (long long) pid, tid->Value() );
|
||||
DBG_LOG(DBG_SERIAL, "-- Caching");
|
||||
DBG_PUSH(DBG_SERIAL);
|
||||
|
||||
if ( ! SerializePID(info, true, pid) )
|
||||
{
|
||||
DBG_POP(DBG_SERIAL);
|
||||
return false;
|
||||
}
|
||||
|
||||
info->type = SER_NONE;
|
||||
DBG_POP(DBG_SERIAL);
|
||||
}
|
||||
|
||||
DBG_PUSH(DBG_SERIAL);
|
||||
info->cont.SaveContext();
|
||||
bool ret = DoSerialize(info);
|
||||
info->cont.RestoreContext();
|
||||
DBG_POP(DBG_SERIAL);
|
||||
|
||||
if ( info->cont.ChildSuspended() )
|
||||
return ret;
|
||||
|
||||
#ifdef DEBUG
|
||||
if ( debug_logger.IsEnabled(DBG_SERIAL) && IsBroObj(serial_type) )
|
||||
{
|
||||
ODesc desc(DESC_READABLE);
|
||||
((BroObj*)this)->Describe(&desc);
|
||||
DBG_LOG(DBG_SERIAL, "-- Desc: %s", desc.Description());
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SerialObj* SerialObj::Unserialize(UnserialInfo* info, SerialType type)
|
||||
{
|
||||
SerializationCache::PermanentID pid = SerializationCache::NONE;
|
||||
|
||||
DBG_LOG(DBG_SERIAL, "%s", __PRETTY_FUNCTION__);
|
||||
|
||||
bool full_obj;
|
||||
|
||||
DBG_LOG(DBG_SERIAL, "-- Caching");
|
||||
DBG_PUSH(DBG_SERIAL);
|
||||
|
||||
bool result;
|
||||
|
||||
if ( ! info->pid_32bit )
|
||||
result = UNSERIALIZE(&full_obj) && UNSERIALIZE(&pid);
|
||||
else
|
||||
{
|
||||
// Broccoli compatibility mode with 32bit pids.
|
||||
uint32 tmp = 0;
|
||||
result = UNSERIALIZE(&full_obj) && UNSERIALIZE(&tmp);
|
||||
pid = tmp;
|
||||
}
|
||||
|
||||
if ( ! result )
|
||||
{
|
||||
DBG_POP(DBG_SERIAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DBG_POP(DBG_SERIAL);
|
||||
|
||||
DBG_LOG(DBG_SERIAL, "-- [%s pid %lld]", full_obj ? "obj" : "ref", (long long) pid);
|
||||
|
||||
if ( ! full_obj )
|
||||
{
|
||||
// FIXME: Yet another const_cast to check eventually...
|
||||
SerialObj* obj =
|
||||
const_cast<SerialObj*>(info->s->Cache()->Lookup(pid));
|
||||
if ( obj )
|
||||
{
|
||||
if ( obj->IsBroObj() )
|
||||
Ref((BroObj*) obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
// In the following we'd like the format specifier to match
|
||||
// the type of pid; but pid is uint64, for which there's
|
||||
// no portable format specifier. So we upcast it to long long,
|
||||
// which is at least that size, and use a matching format.
|
||||
info->s->Error(fmt("unknown object %lld referenced",
|
||||
(long long) pid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16 stype;
|
||||
if ( ! UNSERIALIZE(&stype) )
|
||||
return 0;
|
||||
|
||||
SerialObj* obj = Instantiate(SerialType(stype));
|
||||
|
||||
if ( ! obj )
|
||||
{
|
||||
info->s->Error("unknown object type");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
obj->serial_type = stype;
|
||||
#endif
|
||||
|
||||
const TransientID* tid = obj->GetTID();
|
||||
if ( ! tid )
|
||||
reporter->InternalError("no tid - missing DECLARE_SERIAL?");
|
||||
|
||||
if ( info->cache )
|
||||
info->s->Cache()->Register(obj, pid, info->new_cache_strategy);
|
||||
|
||||
info->type = stype;
|
||||
|
||||
DBG_PUSH(DBG_SERIAL);
|
||||
if ( ! obj->DoUnserialize(info) )
|
||||
{
|
||||
DBG_POP(DBG_SERIAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DBG_POP(DBG_SERIAL);
|
||||
|
||||
if ( ! SerialObj::CheckTypes(stype, type) )
|
||||
{
|
||||
info->s->Error("type mismatch");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if ( debug_logger.IsEnabled(DBG_SERIAL) && IsBroObj(stype) )
|
||||
{
|
||||
ODesc desc(DESC_READABLE);
|
||||
((BroObj*)obj)->Describe(&desc);
|
||||
DBG_LOG(DBG_SERIAL, "-- Desc: %s", desc.Description());
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
bool SerialObj::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
assert(info->type != SER_NONE);
|
||||
|
||||
#ifdef DEBUG
|
||||
const_cast<SerialObj*>(this)->serial_type = info->type;
|
||||
#endif
|
||||
|
||||
DBG_LOG(DBG_SERIAL, __PRETTY_FUNCTION__);
|
||||
DBG_PUSH(DBG_SERIAL);
|
||||
|
||||
uint16 stype = uint16(info->type);
|
||||
|
||||
if ( ! info->new_cache_strategy )
|
||||
{
|
||||
// This is a bit unfortunate: to make sure we're sending
|
||||
// out the same types as in the past, we need to strip out
|
||||
// the new cache stable bit.
|
||||
stype &= ~SER_IS_CACHE_STABLE;
|
||||
}
|
||||
|
||||
bool ret = SERIALIZE(stype);
|
||||
DBG_POP(DBG_SERIAL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool SerialObj::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DBG_LOG(DBG_SERIAL, __PRETTY_FUNCTION__);
|
||||
return true;
|
||||
}
|
382
src/SerialObj.h
382
src/SerialObj.h
|
@ -1,382 +0,0 @@
|
|||
// Infrastructure for serializable objects.
|
||||
//
|
||||
// How to make objects of class Foo serializable:
|
||||
//
|
||||
// 1. Derive Foo (directly or indirectly) from SerialObj.
|
||||
// 2. Add a SER_FOO constant to SerialTypes in SerialTypes.h.
|
||||
// 3. Add DECLARE_SERIAL(Foo) into class definition.
|
||||
// 4. Add a (preferably protected) default ctor if it doesn't already exist.
|
||||
// 5. For non-abstract classes, add IMPLEMENT_SERIAL(Foo, SER_FOO) to *.cc
|
||||
// 6. Add two methods like this to *.cc (keep names of arguments!)
|
||||
//
|
||||
// bool Foo::DoSerialize(SerialInfo* info) const
|
||||
// {
|
||||
// DO_SERIALIZE(SER_FOO, ParentClassOfFoo);
|
||||
// <... serialize class members via methods in Serializer ...>
|
||||
// return true if everything ok;
|
||||
// }
|
||||
//
|
||||
// bool Foo::DoUnserialize(UnserialInfo* info)
|
||||
// {
|
||||
// DO_UNSERIALIZE(ParentClassOfFoo);
|
||||
// <... unserialize class members via methods in Serializer ...>
|
||||
// return true if everything ok;
|
||||
// }
|
||||
//
|
||||
// (7. If no parent class of Foo already contains Serialize()/Unserialize()
|
||||
// methods, these need to be added somewhere too. But most of the various
|
||||
// parts of the class hierarchy already have them.)
|
||||
|
||||
|
||||
#ifndef SERIALOBJ_H
|
||||
#define SERIALOBJ_H
|
||||
|
||||
#include <map>
|
||||
#include <util.h>
|
||||
|
||||
#include "DebugLogger.h"
|
||||
#include "Continuation.h"
|
||||
#include "SerialTypes.h"
|
||||
#include "bro-config.h"
|
||||
|
||||
#if SIZEOF_LONG_LONG < 8
|
||||
# error "Serialization requires that sizeof(long long) is at least 8. (Remove this message only if you know what you're doing.)"
|
||||
#endif
|
||||
|
||||
class Serializer;
|
||||
class SerialInfo;
|
||||
class UnserialInfo;
|
||||
class SerializationCache;
|
||||
|
||||
// Per-process unique ID.
|
||||
class TransientID {
|
||||
public:
|
||||
TransientID() { id = ++counter; }
|
||||
|
||||
typedef unsigned long long ID;
|
||||
ID Value() const { return id; }
|
||||
|
||||
private:
|
||||
ID id;
|
||||
static ID counter;
|
||||
};
|
||||
|
||||
// Abstract base class for serializable objects.
|
||||
class SerialObj {
|
||||
public:
|
||||
virtual ~SerialObj() { }
|
||||
|
||||
virtual const TransientID* GetTID() const { return 0; }
|
||||
|
||||
virtual SerialType GetSerialType() const { return 0; }
|
||||
|
||||
bool IsBroObj() const { return IsBroObj(GetSerialType()); }
|
||||
bool IsCacheStable() const { return IsCacheStable(GetSerialType()); }
|
||||
|
||||
static const uint64 NEVER = 0;
|
||||
static const uint64 ALWAYS = 1;
|
||||
|
||||
// Returns time of last modification. This "time" is a monotonically
|
||||
// increasing counter which is incremented each time a modification is
|
||||
// performed (more precisely: each time an object is modified which
|
||||
// returns something different than NEVER). Such times can thus be
|
||||
// compared to see whether some modification took place before another.
|
||||
//
|
||||
// There are two special values:
|
||||
// NEVER: This object will never change.
|
||||
// ALWAYS: Always consider this object as changed, i.e., don't
|
||||
// cache it.
|
||||
virtual uint64 LastModified() const { return NEVER; }
|
||||
|
||||
// Instantiate an object of the given type. Return nil
|
||||
// if unknown.
|
||||
static SerialObj* Instantiate(SerialType type);
|
||||
|
||||
static const char* ClassName(SerialType type);
|
||||
|
||||
// Associate a "factory" function with the given type.
|
||||
// A factory is a class or function that creates instances
|
||||
// of a certain type.
|
||||
|
||||
typedef SerialObj* (*FactoryFunc)();
|
||||
static void Register(SerialType type, FactoryFunc f,
|
||||
const char* class_name);
|
||||
|
||||
static bool IsBroObj(SerialType type)
|
||||
{ return type & SER_IS_BRO_OBJ; }
|
||||
|
||||
static bool IsCacheStable(SerialType type)
|
||||
{ return type & SER_IS_CACHE_STABLE; }
|
||||
|
||||
static bool CheckTypes(SerialType type1, SerialType type2)
|
||||
{ return (type1 & SER_TYPE_MASK_PARENT) ==
|
||||
(type2 & SER_TYPE_MASK_PARENT); }
|
||||
|
||||
protected:
|
||||
friend class SerializationCache;
|
||||
|
||||
SerialObj()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
serial_type = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Serializes this object. If info->cache is false, we can use
|
||||
// DECLARE_NON_CACHEABLE_SERIAL (instead of DECLARE_SERIAL) which
|
||||
// avoids storing a per-object id.
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
|
||||
// Unserializes next object.
|
||||
static SerialObj* Unserialize(UnserialInfo* info,
|
||||
SerialType type);
|
||||
|
||||
virtual bool DoSerialize(SerialInfo* info) const;
|
||||
virtual bool DoUnserialize(UnserialInfo* info);
|
||||
|
||||
typedef std::map<SerialType, FactoryFunc> FactoryMap;
|
||||
static FactoryMap* factories;
|
||||
|
||||
typedef std::map<SerialType, const char*> ClassNameMap;
|
||||
static ClassNameMap* names;
|
||||
|
||||
static uint64 time_counter;
|
||||
static uint64 IncreaseTimeCounter() { return ++time_counter; }
|
||||
static uint64 GetTimeCounter() { return time_counter; }
|
||||
|
||||
#ifdef DEBUG
|
||||
SerialType serial_type;
|
||||
#endif
|
||||
};
|
||||
|
||||
// A class that registers a factory function upon instantiation.
|
||||
class SerialTypeRegistrator {
|
||||
public:
|
||||
SerialTypeRegistrator(SerialType type, SerialObj::FactoryFunc func,
|
||||
const char* class_name)
|
||||
{
|
||||
SerialObj::Register(type, func, class_name);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Macro helpers.
|
||||
|
||||
#define DECLARE_ABSTRACT_SERIAL(classname) \
|
||||
bool DoSerialize(SerialInfo*) const override; \
|
||||
bool DoUnserialize(UnserialInfo*) override; \
|
||||
|
||||
#define DECLARE_SERIAL(classname) \
|
||||
static classname* Instantiate(); \
|
||||
static SerialTypeRegistrator register_type; \
|
||||
bool DoSerialize(SerialInfo*) const override; \
|
||||
bool DoUnserialize(UnserialInfo*) override; \
|
||||
const TransientID* GetTID() const override { return &tid; } \
|
||||
SerialType GetSerialType() const override; \
|
||||
TransientID tid;
|
||||
|
||||
// Only needed (and usable) for non-abstract classes.
|
||||
#define IMPLEMENT_SERIAL(classname, classtype) \
|
||||
SerialTypeRegistrator classname::register_type(classtype, \
|
||||
FactoryFunc(&classname::Instantiate), #classname); \
|
||||
SerialType classname::GetSerialType() const { return classtype; }; \
|
||||
classname* classname::Instantiate() { return new classname(); } \
|
||||
|
||||
// Pushes debug level on instantiation and pops when it goes out of scope.
|
||||
class AutoPush {
|
||||
public:
|
||||
AutoPush() { DBG_PUSH(DBG_SERIAL); }
|
||||
~AutoPush() { DBG_POP(DBG_SERIAL); }
|
||||
};
|
||||
|
||||
// Note that by default we disable suspending. Use DO_SERIALIZE_WITH_SUSPEND
|
||||
// to enable, but be careful to make sure that whomever calls us is aware of
|
||||
// the fact (or has already disabled suspension itself).
|
||||
#define DO_SERIALIZE(classtype, super) \
|
||||
DBG_LOG(DBG_SERIAL, __PRETTY_FUNCTION__); \
|
||||
if ( info->type == SER_NONE ) \
|
||||
info->type = classtype; \
|
||||
DisableSuspend suspend(info); \
|
||||
AutoPush auto_push; \
|
||||
if ( ! super::DoSerialize(info) ) \
|
||||
return false;
|
||||
|
||||
// Unfortunately, this is getting quite long. :-(
|
||||
#define DO_SERIALIZE_WITH_SUSPEND(classtype, super) \
|
||||
DBG_LOG(DBG_SERIAL, __PRETTY_FUNCTION__); \
|
||||
if ( info->type == SER_NONE ) \
|
||||
info->type = classtype; \
|
||||
AutoPush auto_push; \
|
||||
\
|
||||
bool call_super = info->cont.NewInstance(); \
|
||||
\
|
||||
if ( info->cont.ChildSuspended() ) \
|
||||
{ \
|
||||
void* user_ptr = info->cont.RestoreState(); \
|
||||
if ( user_ptr == &call_super ) \
|
||||
call_super = true; \
|
||||
} \
|
||||
\
|
||||
if ( call_super ) \
|
||||
{ \
|
||||
info->cont.SaveState(&call_super); \
|
||||
info->cont.SaveContext(); \
|
||||
bool result = super::DoSerialize(info); \
|
||||
info->cont.RestoreContext(); \
|
||||
if ( ! result ) \
|
||||
return false; \
|
||||
if ( info->cont.ChildSuspended() ) \
|
||||
return true; \
|
||||
info->cont.SaveState(0); \
|
||||
} \
|
||||
|
||||
#define DO_UNSERIALIZE(super) \
|
||||
DBG_LOG(DBG_SERIAL, __PRETTY_FUNCTION__); \
|
||||
AutoPush auto_push; \
|
||||
if ( ! super::DoUnserialize(info) ) \
|
||||
return false;
|
||||
|
||||
#define SERIALIZE(x) \
|
||||
info->s->Write(x, #x)
|
||||
|
||||
#define SERIALIZE_STR(x, y) \
|
||||
info->s->Write(x, y, #x)
|
||||
|
||||
#define SERIALIZE_BIT(bit) \
|
||||
info->s->Write(bool(bit), #bit)
|
||||
|
||||
#define UNSERIALIZE(x) \
|
||||
info->s->Read(x, #x)
|
||||
|
||||
#define UNSERIALIZE_STR(x, y) \
|
||||
info->s->Read(x, y, #x)
|
||||
|
||||
#define UNSERIALIZE_BIT(bit) \
|
||||
{ \
|
||||
bool tmp; \
|
||||
if ( ! info->s->Read(&tmp, #bit) ) \
|
||||
return false; \
|
||||
bit = (unsigned int) tmp; \
|
||||
}
|
||||
|
||||
// Some helpers for pointers which may be nil.
|
||||
#define SERIALIZE_OPTIONAL(ptr) \
|
||||
{ \
|
||||
if ( ptr ) \
|
||||
{ \
|
||||
if ( ! info->cont.ChildSuspended() ) \
|
||||
if ( ! info->s->Write(true, "has_" #ptr) ) \
|
||||
return false; \
|
||||
\
|
||||
info->cont.SaveContext(); \
|
||||
bool result = ptr->Serialize(info); \
|
||||
info->cont.RestoreContext(); \
|
||||
if ( ! result ) \
|
||||
return false; \
|
||||
\
|
||||
if ( info->cont.ChildSuspended() ) \
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
else if ( ! info->s->Write(false, "has_" #ptr) ) \
|
||||
return false; \
|
||||
}
|
||||
|
||||
#define SERIALIZE_OPTIONAL_STR(str) \
|
||||
{ \
|
||||
if ( str ) \
|
||||
{ \
|
||||
if ( ! (info->s->Write(true, "has_" #str) && info->s->Write(str, "str")) ) \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
else if ( ! info->s->Write(false, "has_" #str) ) \
|
||||
return false; \
|
||||
}
|
||||
|
||||
#define UNSERIALIZE_OPTIONAL(dst, unserialize) \
|
||||
{ \
|
||||
bool has_it; \
|
||||
if ( ! info->s->Read(&has_it, "has_" #dst) ) \
|
||||
return false; \
|
||||
\
|
||||
if ( has_it ) \
|
||||
{ \
|
||||
dst = unserialize; \
|
||||
if ( ! dst ) \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
else \
|
||||
dst = 0; \
|
||||
}
|
||||
|
||||
#define UNSERIALIZE_OPTIONAL_STR(dst) \
|
||||
{ \
|
||||
bool has_it; \
|
||||
if ( ! info->s->Read(&has_it, "has_" #dst) ) \
|
||||
return false; \
|
||||
\
|
||||
if ( has_it ) \
|
||||
{ \
|
||||
if ( ! info->s->Read(&dst, 0, "has_" #dst) ) \
|
||||
return false; \
|
||||
if ( ! dst ) \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
else \
|
||||
dst = 0; \
|
||||
}
|
||||
|
||||
#define UNSERIALIZE_OPTIONAL_STR_DEL(dst, del) \
|
||||
{ \
|
||||
bool has_it; \
|
||||
if ( ! info->s->Read(&has_it, "has_" #dst) ) \
|
||||
{ \
|
||||
delete del; \
|
||||
return 0; \
|
||||
} \
|
||||
\
|
||||
if ( has_it ) \
|
||||
{ \
|
||||
if ( ! info->s->Read(&dst, 0, "has_" #dst) ) \
|
||||
{ \
|
||||
delete del; \
|
||||
return 0; \
|
||||
} \
|
||||
if ( ! dst ) \
|
||||
{ \
|
||||
delete del; \
|
||||
return 0; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
else \
|
||||
dst = 0; \
|
||||
}
|
||||
|
||||
#define UNSERIALIZE_OPTIONAL_STATIC(dst, unserialize, del) \
|
||||
{ \
|
||||
bool has_it; \
|
||||
if ( ! info->s->Read(&has_it, "has_" #dst) ) \
|
||||
{ \
|
||||
delete del; \
|
||||
return 0; \
|
||||
} \
|
||||
\
|
||||
if ( has_it ) \
|
||||
{ \
|
||||
dst = unserialize; \
|
||||
if ( ! dst ) \
|
||||
{ \
|
||||
delete del; \
|
||||
return 0; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
else \
|
||||
dst = 0; \
|
||||
}
|
||||
|
||||
#endif
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "net_util.h"
|
||||
#include "SerializationFormat.h"
|
||||
#include "Serializer.h"
|
||||
#include "DebugLogger.h"
|
||||
#include "Reporter.h"
|
||||
|
||||
const float SerializationFormat::GROWTH_FACTOR = 2.5;
|
||||
|
|
1059
src/Serializer.cc
1059
src/Serializer.cc
File diff suppressed because it is too large
Load diff
363
src/Serializer.h
363
src/Serializer.h
|
@ -1,363 +0,0 @@
|
|||
#ifndef SERIALIZER_H
|
||||
#define SERIALIZER_H
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <pcap.h>
|
||||
|
||||
#include "ID.h"
|
||||
#include "List.h"
|
||||
#include "Expr.h"
|
||||
#include "ChunkedIO.h"
|
||||
#include "SerializationFormat.h"
|
||||
#include "StateAccess.h"
|
||||
#include "PriorityQueue.h"
|
||||
#include "SerialInfo.h"
|
||||
#include "IP.h"
|
||||
#include "Timer.h"
|
||||
#include "iosource/IOSource.h"
|
||||
#include "Reporter.h"
|
||||
|
||||
class SerializationCache;
|
||||
class SerialInfo;
|
||||
|
||||
class Connection;
|
||||
class Timer;
|
||||
class Packet;
|
||||
|
||||
class Serializer {
|
||||
public:
|
||||
// Currently ID serialization is the only method which may suspend.
|
||||
bool Serialize(SerialInfo* info, const ID& id);
|
||||
bool Serialize(SerialInfo* info, const char* func, val_list* args);
|
||||
bool Serialize(SerialInfo* info, const StateAccess& s);
|
||||
bool Serialize(SerialInfo* info, const Connection& c);
|
||||
bool Serialize(SerialInfo* info, const Timer& t);
|
||||
bool Serialize(SerialInfo* info, const Packet& p);
|
||||
|
||||
// Access to the current cache.
|
||||
SerializationCache* Cache() { return current_cache; }
|
||||
void SetCache(SerializationCache* cache)
|
||||
{ current_cache = cache; }
|
||||
|
||||
// Input/output methods.
|
||||
|
||||
#define DECLARE_READ(type) \
|
||||
bool Read(type* v, const char* tag) { return format->Read(v, tag); }
|
||||
|
||||
#define DECLARE_WRITE(type) \
|
||||
bool Write(type v, const char* tag) \
|
||||
{ return format->Write(v, tag); }
|
||||
|
||||
#define DECLARE_IO(type) \
|
||||
DECLARE_READ(type) \
|
||||
DECLARE_WRITE(type)
|
||||
|
||||
DECLARE_IO(int)
|
||||
DECLARE_IO(uint16)
|
||||
DECLARE_IO(uint32)
|
||||
DECLARE_IO(int64)
|
||||
DECLARE_IO(uint64)
|
||||
DECLARE_IO(char)
|
||||
DECLARE_IO(bool)
|
||||
DECLARE_IO(double)
|
||||
|
||||
bool Read(char** str, int* len, const char* tag)
|
||||
{ return format->Read(str, len, tag); }
|
||||
bool Read(const char** str, int* len, const char* tag)
|
||||
// This cast is ok.
|
||||
{ return format->Read(const_cast<char**>(str), len, tag); }
|
||||
|
||||
bool Read(string* s, const char* tag);
|
||||
bool Read(IPAddr* a, const char* tag) { return format->Read(a, tag); }
|
||||
bool Read(IPPrefix* p, const char* tag) { return format->Read(p, tag); }
|
||||
|
||||
bool Write(const char* s, const char* tag)
|
||||
{ return format->Write(s, tag); }
|
||||
bool Write(const char* buf, int len, const char* tag)
|
||||
{ return format->Write(buf, len, tag); }
|
||||
bool Write(const string& s, const char* tag)
|
||||
{ return format->Write(s.data(), s.size(), tag); }
|
||||
bool Write(const IPAddr& a, const char* tag) { return format->Write(a, tag); }
|
||||
bool Write(const IPPrefix& p, const char* tag) { return format->Write(p, tag); }
|
||||
|
||||
bool WriteOpenTag(const char* tag)
|
||||
{ return format->WriteOpenTag(tag); }
|
||||
bool WriteCloseTag(const char* tag)
|
||||
{ return format->WriteCloseTag(tag); }
|
||||
|
||||
bool WriteSeparator() { return format->WriteSeparator(); }
|
||||
|
||||
void Error(const char* msg);
|
||||
void Warning(const char* msg);
|
||||
|
||||
void SetErrorDescr(const char* descr)
|
||||
{ delete [] error_descr; error_descr = copy_string(descr); }
|
||||
|
||||
protected:
|
||||
// Format defaults to binary serialization.
|
||||
explicit Serializer(SerializationFormat* format = 0);
|
||||
virtual ~Serializer();
|
||||
|
||||
// Reads next object.
|
||||
// If 'block' is true, wait until an object can be read.
|
||||
// Returns 0 if no more object available, -1 on error.
|
||||
int Unserialize(UnserialInfo* info, bool block = false);
|
||||
|
||||
// Callback for error messages.
|
||||
virtual void ReportError(const char* msg) = 0;
|
||||
|
||||
// Callbacks for unserialized objects.
|
||||
|
||||
// id points to ID in global scope, val is unserialized value.
|
||||
virtual void GotID(ID* id, Val* val) = 0;
|
||||
virtual void GotEvent(const char* name, double time,
|
||||
EventHandlerPtr event, val_list* args) = 0;
|
||||
virtual void GotFunctionCall(const char* name, double time,
|
||||
Func* func, val_list* args) = 0;
|
||||
virtual void GotStateAccess(StateAccess* s) = 0;
|
||||
virtual void GotTimer(Timer* t) = 0;
|
||||
virtual void GotConnection(Connection* c) = 0;
|
||||
virtual void GotPacket(Packet* packet) = 0;
|
||||
|
||||
// Magic to recognize state files.
|
||||
static const uint32 MAGIC = 0x42525354;
|
||||
|
||||
// This will be increased whenever there is an incompatible change
|
||||
// in the data format.
|
||||
static const uint32 DATA_FORMAT_VERSION = 26;
|
||||
|
||||
ChunkedIO* io;
|
||||
|
||||
private:
|
||||
bool StartSerialization(SerialInfo* info, const char* descr, char tag);
|
||||
bool EndSerialization(SerialInfo* info);
|
||||
|
||||
bool UnserializeID(UnserialInfo* info);
|
||||
bool UnserializeCall(UnserialInfo* info);
|
||||
bool UnserializeStateAccess(UnserialInfo* info);
|
||||
bool UnserializeTimer(UnserialInfo* info);
|
||||
bool UnserializeConnection(UnserialInfo* info);
|
||||
bool UnserializePacket(UnserialInfo* info);
|
||||
|
||||
SerializationFormat* format;
|
||||
SerializationCache* current_cache;
|
||||
const char* error_descr; // used in error messages
|
||||
};
|
||||
|
||||
|
||||
|
||||
// We maintain an LRU-cache for some of the objects which have already been
|
||||
// serialized. For the cache, we need two types of IDs: TransientIDs (defined
|
||||
// in SerialObj.cc) uniquely reference an object during the lifetime of a
|
||||
// process. PermanentIDs uniquely reference an object within a serialization.
|
||||
|
||||
class SerializationCache {
|
||||
public:
|
||||
typedef uint64 PermanentID;
|
||||
static const PermanentID NONE = 0;
|
||||
|
||||
// If max_cache_size is greater than zero, we'll remove old entries
|
||||
// automatically if limit is reached (LRU expiration).
|
||||
explicit SerializationCache(unsigned int max_cache_size = 0);
|
||||
~SerializationCache();
|
||||
|
||||
PermanentID Register(const SerialObj* obj, PermanentID pid,
|
||||
bool new_cache_strategy);
|
||||
|
||||
const SerialObj* Lookup(PermanentID pid)
|
||||
{
|
||||
PIDMap::const_iterator i = pid_map.find(pid);
|
||||
if ( i == pid_map.end() )
|
||||
return 0;
|
||||
|
||||
assert(i->second);
|
||||
MoveEntryToTail(i->second);
|
||||
return i->second->obj.serial;
|
||||
}
|
||||
|
||||
PermanentID Lookup(const TransientID& tid)
|
||||
{
|
||||
TIDMap::const_iterator i = tid_map.find(tid.Value());
|
||||
if ( i == tid_map.end() )
|
||||
return 0;
|
||||
|
||||
uint64 modified = i->second->obj.serial->LastModified();
|
||||
if ( modified == SerialObj::ALWAYS || modified > i->second->time )
|
||||
return 0;
|
||||
|
||||
assert(i->second);
|
||||
MoveEntryToTail(i->second);
|
||||
return i->second->pid;
|
||||
}
|
||||
|
||||
unsigned int GetMaxCacheSize() const { return max_cache_size; }
|
||||
void SetMaxCacheSize(unsigned int size) { max_cache_size = size; }
|
||||
|
||||
// These methods have to be called at the start/end of the
|
||||
// serialization of an entity. The cache guarentees that objects
|
||||
// registered after Begin() remain valid until End() is called.
|
||||
// After End(), objects which are not derived from BroObj are
|
||||
// discarded; others *may* remain valid.
|
||||
void Begin(bool can_keep_in_cache) { End(can_keep_in_cache); }
|
||||
void End(bool can_keep_in_cache);
|
||||
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
|
||||
struct CacheList;
|
||||
|
||||
struct CacheEntry {
|
||||
union {
|
||||
const SerialObj* serial;
|
||||
const BroObj* bro;
|
||||
} obj;
|
||||
|
||||
bool is_bro_obj;
|
||||
PermanentID pid;
|
||||
TransientID::ID tid;
|
||||
uint64 time;
|
||||
struct CacheList* cache;
|
||||
CacheEntry* prev;
|
||||
CacheEntry* next;
|
||||
|
||||
SerialType stype; // primarily for debugging
|
||||
};
|
||||
|
||||
// We maintain two LRU-sorted lists, one for often-changing objects and
|
||||
// one for only rarely changing objects;
|
||||
struct CacheList {
|
||||
CacheEntry* head;
|
||||
CacheEntry* tail;
|
||||
unsigned int size;
|
||||
};
|
||||
|
||||
void RemoveEntry(CacheEntry* e);
|
||||
void UnlinkEntry(CacheEntry* e);
|
||||
void MoveEntryToTail(CacheEntry* e);
|
||||
|
||||
unsigned int max_cache_size;
|
||||
|
||||
typedef map<PermanentID, CacheEntry*> PIDMap;
|
||||
typedef map<TransientID::ID, CacheEntry*> TIDMap;
|
||||
|
||||
TIDMap tid_map;
|
||||
PIDMap pid_map;
|
||||
|
||||
CacheList cache_stable;
|
||||
CacheList cache_unstable;
|
||||
|
||||
// Objects in the cache which aren't derived from BroObj. These are
|
||||
// always stored in the unstable cache.
|
||||
typedef list<CacheEntry*> VolatileList;
|
||||
VolatileList volatiles;
|
||||
|
||||
PermanentID next_id;
|
||||
};
|
||||
|
||||
// A serializer for cloning objects. Objects can be serialized into
|
||||
// the serializer and unserialized into new objects. An absolutely
|
||||
// minimal implementation of Serializer!
|
||||
class CloneSerializer : public Serializer {
|
||||
public:
|
||||
explicit CloneSerializer(SerializationFormat* format = 0) : Serializer(format) { }
|
||||
~CloneSerializer() override
|
||||
{ }
|
||||
|
||||
protected:
|
||||
void ReportError(const char* msg) override { reporter->Error("%s", msg); }
|
||||
void GotID(ID* id, Val* val) override { }
|
||||
void GotEvent(const char* name, double time, EventHandlerPtr event, val_list* args) override { }
|
||||
void GotFunctionCall(const char* name, double time,
|
||||
Func* func, val_list* args) override { }
|
||||
void GotStateAccess(StateAccess* s) override { delete s; }
|
||||
void GotTimer(Timer* t) override { }
|
||||
void GotConnection(Connection* c) override { }
|
||||
void GotPacket(Packet* packet) override { }
|
||||
};
|
||||
|
||||
// Write values/events to file or fd.
|
||||
class FileSerializer : public Serializer {
|
||||
public:
|
||||
explicit FileSerializer(SerializationFormat* format = 0);
|
||||
~FileSerializer() override;
|
||||
|
||||
// Opens the file for serialization.
|
||||
bool Open(const char* file, bool pure = false);
|
||||
bool Close();
|
||||
|
||||
// Reads the file.
|
||||
bool Read(UnserialInfo* info, const char* file, bool header = true);
|
||||
|
||||
protected:
|
||||
void ReportError(const char* msg) override;
|
||||
void GotID(ID* id, Val* val) override;
|
||||
void GotEvent(const char* name, double time,
|
||||
EventHandlerPtr event, val_list* args) override;
|
||||
void GotFunctionCall(const char* name, double time,
|
||||
Func* func, val_list* args) override;
|
||||
void GotStateAccess(StateAccess* s) override;
|
||||
void GotTimer(Timer* t) override;
|
||||
void GotConnection(Connection* c) override;
|
||||
void GotPacket(Packet* packet) override;
|
||||
|
||||
bool OpenFile(const char* file, bool readonly, bool should_exist = false);
|
||||
void CloseFile();
|
||||
bool ReadFile(const char* file);
|
||||
bool PrepareForWriting();
|
||||
bool ReadHeader(UnserialInfo* info = 0);
|
||||
|
||||
SerializationCache cache;
|
||||
const char* file;
|
||||
int fd;
|
||||
};
|
||||
|
||||
// Abstract interface class for external sources providing a stream of events.
|
||||
class EventSource {
|
||||
public:
|
||||
virtual ~EventSource() { }
|
||||
|
||||
// Returns time of the oldest event (0 if none available).
|
||||
virtual double NextTimestamp(double* local_network_time) = 0;
|
||||
|
||||
// Dispatches the oldest event and removes it.
|
||||
virtual void DispatchNextEvent() = 0;
|
||||
|
||||
// Returns true if there are more events to expect from this source.
|
||||
virtual bool IsActive() = 0;
|
||||
};
|
||||
|
||||
// Plays a file of events back.
|
||||
class EventPlayer : public FileSerializer, public iosource::IOSource {
|
||||
public:
|
||||
explicit EventPlayer(const char* file);
|
||||
~EventPlayer() override;
|
||||
|
||||
void GetFds(iosource::FD_Set* read, iosource::FD_Set* write,
|
||||
iosource::FD_Set* except) override;
|
||||
double NextTimestamp(double* local_network_time) override;
|
||||
void Process() override;
|
||||
const char* Tag() override { return "EventPlayer"; }
|
||||
|
||||
protected:
|
||||
void GotID(ID* id, Val* val) override {}
|
||||
void GotEvent(const char* name, double time,
|
||||
EventHandlerPtr event, val_list* args) override;
|
||||
void GotFunctionCall(const char* name, double time,
|
||||
Func* func, val_list* args) override;
|
||||
|
||||
double stream_time; // time of first captured event
|
||||
double replay_time; // network time of replay start
|
||||
|
||||
// Next event waiting to be dispatched.
|
||||
double ne_time;
|
||||
EventHandlerPtr ne_handler;
|
||||
val_list ne_args;
|
||||
|
||||
};
|
||||
|
||||
extern FileSerializer* event_serializer;
|
||||
extern FileSerializer* state_serializer;
|
||||
|
||||
#endif
|
|
@ -1,6 +1,5 @@
|
|||
#include "Val.h"
|
||||
#include "StateAccess.h"
|
||||
#include "Serializer.h"
|
||||
#include "Event.h"
|
||||
#include "NetVar.h"
|
||||
#include "DebugLogger.h"
|
||||
|
@ -72,7 +71,6 @@ StateAccess::StateAccess(Opcode arg_opcode,
|
|||
}
|
||||
|
||||
StateAccess::StateAccess(const StateAccess& sa)
|
||||
: SerialObj()
|
||||
{
|
||||
opcode = sa.opcode;
|
||||
target_type = sa.target_type;
|
||||
|
@ -408,146 +406,6 @@ ID* StateAccess::Target() const
|
|||
return target_type == TYPE_ID ? target.id : target.val->UniqueID();
|
||||
}
|
||||
|
||||
bool StateAccess::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
StateAccess* StateAccess::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
StateAccess* sa =
|
||||
(StateAccess*) SerialObj::Unserialize(info, SER_STATE_ACCESS);
|
||||
return sa;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(StateAccess, SER_STATE_ACCESS);
|
||||
|
||||
bool StateAccess::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_STATE_ACCESS, SerialObj);
|
||||
|
||||
if ( ! SERIALIZE(char(opcode)) )
|
||||
return false;
|
||||
|
||||
const ID* id =
|
||||
target_type == TYPE_ID ? target.id : target.val->UniqueID();
|
||||
|
||||
if ( ! SERIALIZE(id->Name()) )
|
||||
return false;
|
||||
|
||||
if ( op1_type == TYPE_KEY )
|
||||
{
|
||||
Val* index =
|
||||
id->ID_Val()->AsTableVal()->RecoverIndex(this->op1.key);
|
||||
|
||||
if ( ! index )
|
||||
return false;
|
||||
if ( ! index->Serialize(info) )
|
||||
return false;
|
||||
|
||||
Unref(index);
|
||||
}
|
||||
|
||||
else if ( ! op1.val->Serialize(info) )
|
||||
return false;
|
||||
|
||||
// Don't send the "old" operand if we don't want consistency checks.
|
||||
// Unfortunately, it depends on the opcode which operand that actually
|
||||
// is.
|
||||
|
||||
const Val* null = 0;
|
||||
|
||||
switch ( opcode ) {
|
||||
case OP_PRINT:
|
||||
case OP_EXPIRE:
|
||||
case OP_READ_IDX:
|
||||
// No old.
|
||||
SERIALIZE_OPTIONAL(null);
|
||||
SERIALIZE_OPTIONAL(null);
|
||||
break;
|
||||
|
||||
case OP_INCR:
|
||||
case OP_INCR_IDX:
|
||||
// Always need old.
|
||||
SERIALIZE_OPTIONAL(op2);
|
||||
SERIALIZE_OPTIONAL(op3);
|
||||
break;
|
||||
|
||||
case OP_ASSIGN:
|
||||
case OP_ADD:
|
||||
case OP_DEL:
|
||||
// Op2 is old.
|
||||
SERIALIZE_OPTIONAL(null);
|
||||
SERIALIZE_OPTIONAL(null);
|
||||
break;
|
||||
|
||||
case OP_ASSIGN_IDX:
|
||||
// Op3 is old.
|
||||
SERIALIZE_OPTIONAL(op2);
|
||||
SERIALIZE_OPTIONAL(null);
|
||||
break;
|
||||
|
||||
default:
|
||||
reporter->InternalError("StateAccess::DoSerialize: unknown opcode");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StateAccess::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
char c;
|
||||
if ( ! UNSERIALIZE(&c) )
|
||||
return false;
|
||||
|
||||
opcode = Opcode(c);
|
||||
|
||||
const char* name;
|
||||
if ( ! UNSERIALIZE_STR(&name, 0) )
|
||||
return false;
|
||||
|
||||
target_type = TYPE_ID;
|
||||
target.id = global_scope()->Lookup(name);
|
||||
|
||||
if ( target.id )
|
||||
// Otherwise, we'll delete it below.
|
||||
delete [] name;
|
||||
|
||||
op1_type = TYPE_VAL;
|
||||
op1.val = Val::Unserialize(info);
|
||||
if ( ! op1.val )
|
||||
return false;
|
||||
|
||||
UNSERIALIZE_OPTIONAL(op2, Val::Unserialize(info));
|
||||
UNSERIALIZE_OPTIONAL(op3, Val::Unserialize(info));
|
||||
|
||||
if ( target.id )
|
||||
Ref(target.id);
|
||||
else
|
||||
{
|
||||
// This may happen as long as we haven't agreed on the
|
||||
// unique name for an ID during initial synchronization, or if
|
||||
// the local peer has already deleted the ID.
|
||||
DBG_LOG(DBG_STATE, "state access referenced unknown id %s", name);
|
||||
|
||||
if ( info->install_uniques )
|
||||
{
|
||||
target.id = new ID(name, SCOPE_GLOBAL, true);
|
||||
Ref(target.id);
|
||||
global_scope()->Insert(name, target.id);
|
||||
#ifdef USE_PERFTOOLS_DEBUG
|
||||
heap_checker->IgnoreObject(target.id);
|
||||
#endif
|
||||
}
|
||||
|
||||
delete [] name;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void StateAccess::Describe(ODesc* d) const
|
||||
{
|
||||
const ID* id;
|
||||
|
|
|
@ -7,14 +7,11 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "SerialObj.h"
|
||||
|
||||
class Val;
|
||||
class ID;
|
||||
class MutableVal;
|
||||
class HashKey;
|
||||
class ODesc;
|
||||
class Serializer;
|
||||
class TableVal;
|
||||
|
||||
enum Opcode { // Op1 Op2 Op3 (Vals)
|
||||
|
@ -30,7 +27,7 @@ enum Opcode { // Op1 Op2 Op3 (Vals)
|
|||
OP_READ_IDX, // idx
|
||||
};
|
||||
|
||||
class StateAccess : public SerialObj {
|
||||
class StateAccess {
|
||||
public:
|
||||
StateAccess(Opcode opcode, const ID* target, const Val* op1,
|
||||
const Val* op2 = 0, const Val* op3 = 0);
|
||||
|
@ -48,7 +45,7 @@ public:
|
|||
|
||||
StateAccess(const StateAccess& sa);
|
||||
|
||||
~StateAccess() override;
|
||||
virtual ~StateAccess();
|
||||
|
||||
// Replays this access in the our environment.
|
||||
void Replay();
|
||||
|
@ -58,9 +55,6 @@ public:
|
|||
|
||||
void Describe(ODesc* d) const;
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static StateAccess* Unserialize(UnserialInfo* info);
|
||||
|
||||
// Main entry point when StateAcesses are performed.
|
||||
// For every state-changing operation, this has to be called.
|
||||
static void Log(StateAccess* access);
|
||||
|
@ -76,8 +70,6 @@ private:
|
|||
|
||||
bool MergeTables(TableVal* dst, Val* src);
|
||||
|
||||
DECLARE_SERIAL(StateAccess);
|
||||
|
||||
Opcode opcode;
|
||||
union {
|
||||
ID* id;
|
||||
|
|
525
src/Stmt.cc
525
src/Stmt.cc
|
@ -117,47 +117,6 @@ void Stmt::AccessStats(ODesc* d) const
|
|||
}
|
||||
}
|
||||
|
||||
bool Stmt::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Stmt* Stmt::Unserialize(UnserialInfo* info, BroStmtTag want)
|
||||
{
|
||||
Stmt* stmt = (Stmt*) SerialObj::Unserialize(info, SER_STMT);
|
||||
|
||||
if ( want != STMT_ANY && stmt->tag != want )
|
||||
{
|
||||
info->s->Error("wrong stmt type");
|
||||
Unref(stmt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
bool Stmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_STMT, BroObj);
|
||||
|
||||
return SERIALIZE(char(tag)) && SERIALIZE(last_access)
|
||||
&& SERIALIZE(access_count);
|
||||
}
|
||||
|
||||
bool Stmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroObj);
|
||||
|
||||
char c;
|
||||
if ( ! UNSERIALIZE(&c) )
|
||||
return 0;
|
||||
|
||||
tag = BroStmtTag(c);
|
||||
|
||||
return UNSERIALIZE(&last_access) && UNSERIALIZE(&access_count);
|
||||
}
|
||||
|
||||
|
||||
ExprListStmt::ExprListStmt(BroStmtTag t, ListExpr* arg_l)
|
||||
: Stmt(t)
|
||||
{
|
||||
|
@ -207,19 +166,6 @@ void ExprListStmt::PrintVals(ODesc* d, val_list* vals, int offset) const
|
|||
describe_vals(vals, d, offset);
|
||||
}
|
||||
|
||||
bool ExprListStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_EXPR_LIST_STMT, Stmt);
|
||||
return l->Serialize(info);
|
||||
}
|
||||
|
||||
bool ExprListStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Stmt);
|
||||
l = (ListExpr*) Expr::Unserialize(info, EXPR_LIST);
|
||||
return l != 0;
|
||||
}
|
||||
|
||||
TraversalCode ExprListStmt::Traverse(TraversalCallback* cb) const
|
||||
{
|
||||
TraversalCode tc = cb->PreStmt(this);
|
||||
|
@ -305,20 +251,6 @@ Val* PrintStmt::DoExec(val_list* vals, stmt_flow_type& /* flow */) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(PrintStmt, SER_PRINT_STMT);
|
||||
|
||||
bool PrintStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_PRINT_STMT, ExprListStmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrintStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(ExprListStmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
ExprStmt::ExprStmt(Expr* arg_e) : Stmt(STMT_EXPR)
|
||||
{
|
||||
e = arg_e;
|
||||
|
@ -404,22 +336,6 @@ TraversalCode ExprStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(ExprStmt, SER_EXPR_STMT);
|
||||
|
||||
bool ExprStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_EXPR_STMT, Stmt);
|
||||
SERIALIZE_OPTIONAL(e);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExprStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Stmt);
|
||||
UNSERIALIZE_OPTIONAL(e, Expr::Unserialize(info));
|
||||
return true;
|
||||
}
|
||||
|
||||
IfStmt::IfStmt(Expr* test, Stmt* arg_s1, Stmt* arg_s2) : ExprStmt(STMT_IF, test)
|
||||
{
|
||||
s1 = arg_s1;
|
||||
|
@ -507,25 +423,6 @@ TraversalCode IfStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(IfStmt, SER_IF_STMT);
|
||||
|
||||
bool IfStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_IF_STMT, ExprStmt);
|
||||
return s1->Serialize(info) && s2->Serialize(info);
|
||||
}
|
||||
|
||||
bool IfStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(ExprStmt);
|
||||
s1 = Stmt::Unserialize(info);
|
||||
if ( ! s1 )
|
||||
return false;
|
||||
|
||||
s2 = Stmt::Unserialize(info);
|
||||
return s2 != 0;
|
||||
}
|
||||
|
||||
static BroStmtTag get_last_stmt_tag(const Stmt* stmt)
|
||||
{
|
||||
if ( ! stmt )
|
||||
|
@ -655,67 +552,6 @@ TraversalCode Case::Traverse(TraversalCallback* cb) const
|
|||
return TC_CONTINUE;
|
||||
}
|
||||
|
||||
bool Case::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Case* Case::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return (Case*) SerialObj::Unserialize(info, SER_CASE);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(Case, SER_CASE);
|
||||
|
||||
bool Case::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_CASE, BroObj);
|
||||
|
||||
if ( ! expr_cases->Serialize(info) )
|
||||
return false;
|
||||
|
||||
id_list empty;
|
||||
id_list* types = (type_cases ? type_cases : &empty);
|
||||
|
||||
if ( ! SERIALIZE(types->length()) )
|
||||
return false;
|
||||
|
||||
loop_over_list((*types), i)
|
||||
{
|
||||
if ( ! (*types)[i]->Serialize(info) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->s->Serialize(info);
|
||||
}
|
||||
|
||||
bool Case::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroObj);
|
||||
|
||||
expr_cases = (ListExpr*) Expr::Unserialize(info, EXPR_LIST);
|
||||
if ( ! expr_cases )
|
||||
return false;
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
return false;
|
||||
|
||||
type_cases = new id_list(len);
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
ID* id = ID::Unserialize(info);
|
||||
if ( ! id )
|
||||
return false;
|
||||
|
||||
type_cases->append(id);
|
||||
}
|
||||
|
||||
this->s = Stmt::Unserialize(info);
|
||||
return this->s != 0;
|
||||
}
|
||||
|
||||
static void int_del_func(void* v)
|
||||
{
|
||||
delete (int*) v;
|
||||
|
@ -1028,66 +864,6 @@ TraversalCode SwitchStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(SwitchStmt, SER_SWITCH_STMT);
|
||||
|
||||
bool SwitchStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_SWITCH_STMT, ExprStmt);
|
||||
|
||||
if ( ! SERIALIZE(cases->length()) )
|
||||
return false;
|
||||
|
||||
loop_over_list((*cases), i)
|
||||
if ( ! (*cases)[i]->Serialize(info) )
|
||||
return false;
|
||||
|
||||
if ( ! SERIALIZE(default_case_idx) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SwitchStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(ExprStmt);
|
||||
|
||||
Init();
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
return false;
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
Case* c = Case::Unserialize(info);
|
||||
if ( ! c )
|
||||
return false;
|
||||
|
||||
cases->append(c);
|
||||
}
|
||||
|
||||
if ( ! UNSERIALIZE(&default_case_idx) )
|
||||
return false;
|
||||
|
||||
loop_over_list(*cases, i)
|
||||
{
|
||||
const ListExpr* le = (*cases)[i]->ExprCases();
|
||||
|
||||
if ( ! le )
|
||||
continue;
|
||||
|
||||
const expr_list& exprs = le->Exprs();
|
||||
|
||||
loop_over_list(exprs, j)
|
||||
{
|
||||
if ( ! AddCaseLabelValueMapping(exprs[j]->ExprVal(), i) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
AddStmt::AddStmt(Expr* arg_e) : ExprStmt(STMT_ADD, arg_e)
|
||||
{
|
||||
if ( ! e->CanAdd() )
|
||||
|
@ -1121,20 +897,6 @@ TraversalCode AddStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(AddStmt, SER_ADD_STMT);
|
||||
|
||||
bool AddStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_ADD_STMT, ExprStmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(ExprStmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
DelStmt::DelStmt(Expr* arg_e) : ExprStmt(STMT_DELETE, arg_e)
|
||||
{
|
||||
if ( e->IsError() )
|
||||
|
@ -1170,20 +932,6 @@ TraversalCode DelStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(DelStmt, SER_DEL_STMT);
|
||||
|
||||
bool DelStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_DEL_STMT, ExprStmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DelStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(ExprStmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
EventStmt::EventStmt(EventExpr* arg_e) : ExprStmt(STMT_EVENT, arg_e)
|
||||
{
|
||||
event_expr = arg_e;
|
||||
|
@ -1218,22 +966,6 @@ TraversalCode EventStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(EventStmt, SER_EVENT_STMT);
|
||||
|
||||
bool EventStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_EVENT_STMT, ExprStmt);
|
||||
return event_expr->Serialize(info);
|
||||
}
|
||||
|
||||
bool EventStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(ExprStmt);
|
||||
|
||||
event_expr = (EventExpr*) Expr::Unserialize(info, EXPR_EVENT);
|
||||
return event_expr != 0;
|
||||
}
|
||||
|
||||
WhileStmt::WhileStmt(Expr* arg_loop_condition, Stmt* arg_body)
|
||||
: loop_condition(arg_loop_condition), body(arg_body)
|
||||
{
|
||||
|
@ -1319,30 +1051,6 @@ Val* WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const
|
|||
return rval;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(WhileStmt, SER_WHILE_STMT);
|
||||
|
||||
bool WhileStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_WHILE_STMT, Stmt);
|
||||
|
||||
if ( ! loop_condition->Serialize(info) )
|
||||
return false;
|
||||
|
||||
return body->Serialize(info);
|
||||
}
|
||||
|
||||
bool WhileStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Stmt);
|
||||
loop_condition = Expr::Unserialize(info);
|
||||
|
||||
if ( ! loop_condition )
|
||||
return false;
|
||||
|
||||
body = Stmt::Unserialize(info);
|
||||
return body != 0;
|
||||
}
|
||||
|
||||
ForStmt::ForStmt(id_list* arg_loop_vars, Expr* loop_expr)
|
||||
: ExprStmt(STMT_FOR, loop_expr)
|
||||
{
|
||||
|
@ -1607,47 +1315,6 @@ TraversalCode ForStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(ForStmt, SER_FOR_STMT);
|
||||
|
||||
bool ForStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_FOR_STMT, ExprStmt);
|
||||
|
||||
if ( ! SERIALIZE(loop_vars->length()) )
|
||||
return false;
|
||||
|
||||
loop_over_list((*loop_vars), i)
|
||||
{
|
||||
if ( ! (*loop_vars)[i]->Serialize(info) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return body->Serialize(info);
|
||||
}
|
||||
|
||||
bool ForStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(ExprStmt);
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
return false;
|
||||
|
||||
loop_vars = new id_list(len);
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
ID* id = ID::Unserialize(info);
|
||||
if ( ! id )
|
||||
return false;
|
||||
|
||||
loop_vars->append(id);
|
||||
}
|
||||
|
||||
body = Stmt::Unserialize(info);
|
||||
return body != 0;
|
||||
}
|
||||
|
||||
Val* NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
|
||||
{
|
||||
RegisterAccess();
|
||||
|
@ -1675,20 +1342,6 @@ TraversalCode NextStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(NextStmt, SER_NEXT_STMT);
|
||||
|
||||
bool NextStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_NEXT_STMT, Stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NextStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
Val* BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
|
||||
{
|
||||
RegisterAccess();
|
||||
|
@ -1716,20 +1369,6 @@ TraversalCode BreakStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BreakStmt, SER_BREAK_STMT);
|
||||
|
||||
bool BreakStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BREAK_STMT, Stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BreakStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
Val* FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
|
||||
{
|
||||
RegisterAccess();
|
||||
|
@ -1757,20 +1396,6 @@ TraversalCode FallthroughStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(FallthroughStmt, SER_FALLTHROUGH_STMT);
|
||||
|
||||
bool FallthroughStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_FALLTHROUGH_STMT, Stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FallthroughStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
ReturnStmt::ReturnStmt(Expr* arg_e) : ExprStmt(STMT_RETURN, arg_e)
|
||||
{
|
||||
Scope* s = current_scope();
|
||||
|
@ -1838,20 +1463,6 @@ void ReturnStmt::Describe(ODesc* d) const
|
|||
DescribeDone(d);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(ReturnStmt, SER_RETURN_STMT);
|
||||
|
||||
bool ReturnStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_RETURN_STMT, ExprStmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReturnStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(ExprStmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
StmtList::StmtList() : Stmt(STMT_LIST)
|
||||
{
|
||||
}
|
||||
|
@ -1941,43 +1552,6 @@ TraversalCode StmtList::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(StmtList, SER_STMT_LIST);
|
||||
|
||||
bool StmtList::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_STMT_LIST, Stmt);
|
||||
|
||||
if ( ! SERIALIZE(stmts.length()) )
|
||||
return false;
|
||||
|
||||
loop_over_list(stmts, i)
|
||||
if ( ! stmts[i]->Serialize(info) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StmtList::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Stmt);
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
return false;
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
Stmt* stmt = Stmt::Unserialize(info);
|
||||
if ( ! stmt )
|
||||
return false;
|
||||
|
||||
stmts.append(stmt);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Val* EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const
|
||||
{
|
||||
RegisterAccess();
|
||||
|
@ -2036,20 +1610,6 @@ void EventBodyList::Describe(ODesc* d) const
|
|||
StmtList::Describe(d);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(EventBodyList, SER_EVENT_BODY_LIST);
|
||||
|
||||
bool EventBodyList::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_EVENT_BODY_LIST, StmtList);
|
||||
return SERIALIZE(topmost);
|
||||
}
|
||||
|
||||
bool EventBodyList::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(StmtList);
|
||||
return UNSERIALIZE(&topmost);
|
||||
}
|
||||
|
||||
InitStmt::~InitStmt()
|
||||
{
|
||||
loop_over_list(*inits, i)
|
||||
|
@ -2123,45 +1683,6 @@ TraversalCode InitStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(InitStmt, SER_INIT_STMT);
|
||||
|
||||
bool InitStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_INIT_STMT, Stmt);
|
||||
|
||||
if ( ! SERIALIZE(inits->length()) )
|
||||
return false;
|
||||
|
||||
loop_over_list((*inits), i)
|
||||
{
|
||||
if ( ! (*inits)[i]->Serialize(info) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InitStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Stmt);
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
return false;
|
||||
|
||||
inits = new id_list(len);
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
ID* id = ID::Unserialize(info);
|
||||
if ( ! id )
|
||||
return false;
|
||||
inits->append(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Val* NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
|
||||
{
|
||||
RegisterAccess();
|
||||
|
@ -2191,20 +1712,6 @@ TraversalCode NullStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(NullStmt, SER_NULL_STMT);
|
||||
|
||||
bool NullStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_NULL_STMT, Stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NullStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
WhenStmt::WhenStmt(Expr* arg_cond, Stmt* arg_s1, Stmt* arg_s2,
|
||||
Expr* arg_timeout, bool arg_is_return)
|
||||
: Stmt(STMT_WHEN)
|
||||
|
@ -2320,35 +1827,3 @@ TraversalCode WhenStmt::Traverse(TraversalCallback* cb) const
|
|||
HANDLE_TC_STMT_POST(tc);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(WhenStmt, SER_WHEN_STMT);
|
||||
|
||||
bool WhenStmt::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_WHEN_STMT, Stmt);
|
||||
|
||||
if ( cond->Serialize(info) && s1->Serialize(info) )
|
||||
return false;
|
||||
|
||||
SERIALIZE_OPTIONAL(s2);
|
||||
SERIALIZE_OPTIONAL(timeout);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WhenStmt::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Stmt);
|
||||
|
||||
cond = Expr::Unserialize(info);
|
||||
if ( ! cond )
|
||||
return false;
|
||||
|
||||
s1 = Stmt::Unserialize(info);
|
||||
if ( ! s1 )
|
||||
return false;
|
||||
|
||||
UNSERIALIZE_OPTIONAL(s2, Stmt::Unserialize(info));
|
||||
UNSERIALIZE_OPTIONAL(timeout, Expr::Unserialize(info));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
47
src/Stmt.h
47
src/Stmt.h
|
@ -71,9 +71,6 @@ public:
|
|||
|
||||
virtual unsigned int BPCount() const { return breakpoint_count; }
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Stmt* Unserialize(UnserialInfo* info, BroStmtTag want = STMT_ANY);
|
||||
|
||||
virtual TraversalCode Traverse(TraversalCallback* cb) const = 0;
|
||||
|
||||
protected:
|
||||
|
@ -83,8 +80,6 @@ protected:
|
|||
void AddTag(ODesc* d) const;
|
||||
void DescribeDone(ODesc* d) const;
|
||||
|
||||
DECLARE_ABSTRACT_SERIAL(Stmt);
|
||||
|
||||
BroStmtTag tag;
|
||||
int breakpoint_count; // how many breakpoints on this statement
|
||||
|
||||
|
@ -111,8 +106,6 @@ protected:
|
|||
void Describe(ODesc* d) const override;
|
||||
void PrintVals(ODesc* d, val_list* vals, int offset) const;
|
||||
|
||||
DECLARE_ABSTRACT_SERIAL(ExprListStmt);
|
||||
|
||||
ListExpr* l;
|
||||
};
|
||||
|
||||
|
@ -125,8 +118,6 @@ protected:
|
|||
PrintStmt() {}
|
||||
|
||||
Val* DoExec(val_list* vals, stmt_flow_type& flow) const override;
|
||||
|
||||
DECLARE_SERIAL(PrintStmt);
|
||||
};
|
||||
|
||||
class ExprStmt : public Stmt {
|
||||
|
@ -151,8 +142,6 @@ protected:
|
|||
|
||||
int IsPure() const override;
|
||||
|
||||
DECLARE_SERIAL(ExprStmt);
|
||||
|
||||
Expr* e;
|
||||
};
|
||||
|
||||
|
@ -175,8 +164,6 @@ protected:
|
|||
Val* DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
|
||||
int IsPure() const override;
|
||||
|
||||
DECLARE_SERIAL(IfStmt);
|
||||
|
||||
Stmt* s1;
|
||||
Stmt* s2;
|
||||
};
|
||||
|
@ -197,17 +184,12 @@ public:
|
|||
|
||||
void Describe(ODesc* d) const override;
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Case* Unserialize(UnserialInfo* info);
|
||||
|
||||
TraversalCode Traverse(TraversalCallback* cb) const;
|
||||
|
||||
protected:
|
||||
friend class Stmt;
|
||||
Case() { expr_cases = 0; type_cases = 0; s = 0; }
|
||||
|
||||
DECLARE_SERIAL(Case);
|
||||
|
||||
ListExpr* expr_cases;
|
||||
id_list* type_cases;
|
||||
Stmt* s;
|
||||
|
@ -234,8 +216,6 @@ protected:
|
|||
Val* DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
|
||||
int IsPure() const override;
|
||||
|
||||
DECLARE_SERIAL(SwitchStmt);
|
||||
|
||||
// Initialize composite hash and case label map.
|
||||
void Init();
|
||||
|
||||
|
@ -274,8 +254,6 @@ public:
|
|||
protected:
|
||||
friend class Stmt;
|
||||
AddStmt() {}
|
||||
|
||||
DECLARE_SERIAL(AddStmt);
|
||||
};
|
||||
|
||||
class DelStmt : public ExprStmt {
|
||||
|
@ -290,8 +268,6 @@ public:
|
|||
protected:
|
||||
friend class Stmt;
|
||||
DelStmt() {}
|
||||
|
||||
DECLARE_SERIAL(DelStmt);
|
||||
};
|
||||
|
||||
class EventStmt : public ExprStmt {
|
||||
|
@ -306,8 +282,6 @@ protected:
|
|||
friend class Stmt;
|
||||
EventStmt() { event_expr = 0; }
|
||||
|
||||
DECLARE_SERIAL(EventStmt);
|
||||
|
||||
EventExpr* event_expr;
|
||||
};
|
||||
|
||||
|
@ -331,8 +305,6 @@ protected:
|
|||
|
||||
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
|
||||
|
||||
DECLARE_SERIAL(WhileStmt);
|
||||
|
||||
Expr* loop_condition;
|
||||
Stmt* body;
|
||||
};
|
||||
|
@ -362,8 +334,6 @@ protected:
|
|||
|
||||
Val* DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
|
||||
|
||||
DECLARE_SERIAL(ForStmt);
|
||||
|
||||
id_list* loop_vars;
|
||||
Stmt* body;
|
||||
// Stores the value variable being used for a key value for loop.
|
||||
|
@ -383,7 +353,6 @@ public:
|
|||
TraversalCode Traverse(TraversalCallback* cb) const override;
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(NextStmt);
|
||||
};
|
||||
|
||||
class BreakStmt : public Stmt {
|
||||
|
@ -398,7 +367,6 @@ public:
|
|||
TraversalCode Traverse(TraversalCallback* cb) const override;
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(BreakStmt);
|
||||
};
|
||||
|
||||
class FallthroughStmt : public Stmt {
|
||||
|
@ -413,7 +381,6 @@ public:
|
|||
TraversalCode Traverse(TraversalCallback* cb) const override;
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(FallthroughStmt);
|
||||
};
|
||||
|
||||
class ReturnStmt : public ExprStmt {
|
||||
|
@ -427,8 +394,6 @@ public:
|
|||
protected:
|
||||
friend class Stmt;
|
||||
ReturnStmt() {}
|
||||
|
||||
DECLARE_SERIAL(ReturnStmt);
|
||||
};
|
||||
|
||||
class StmtList : public Stmt {
|
||||
|
@ -448,8 +413,6 @@ public:
|
|||
protected:
|
||||
int IsPure() const override;
|
||||
|
||||
DECLARE_SERIAL(StmtList);
|
||||
|
||||
stmt_list stmts;
|
||||
};
|
||||
|
||||
|
@ -467,9 +430,6 @@ public:
|
|||
// bool IsTopmost() { return topmost; }
|
||||
|
||||
protected:
|
||||
|
||||
DECLARE_SERIAL(EventBodyList);
|
||||
|
||||
bool topmost;
|
||||
};
|
||||
|
||||
|
@ -496,8 +456,6 @@ protected:
|
|||
friend class Stmt;
|
||||
InitStmt() { inits = 0; }
|
||||
|
||||
DECLARE_SERIAL(InitStmt);
|
||||
|
||||
id_list* inits;
|
||||
};
|
||||
|
||||
|
@ -511,9 +469,6 @@ public:
|
|||
void Describe(ODesc* d) const override;
|
||||
|
||||
TraversalCode Traverse(TraversalCallback* cb) const override;
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(NullStmt);
|
||||
};
|
||||
|
||||
class WhenStmt : public Stmt {
|
||||
|
@ -537,8 +492,6 @@ public:
|
|||
protected:
|
||||
WhenStmt() { cond = 0; s1 = s2 = 0; timeout = 0; is_return = 0; }
|
||||
|
||||
DECLARE_SERIAL(WhenStmt);
|
||||
|
||||
Expr* cond;
|
||||
Stmt* s1;
|
||||
Stmt* s2;
|
||||
|
|
36
src/Timer.cc
36
src/Timer.cc
|
@ -5,7 +5,6 @@
|
|||
#include "util.h"
|
||||
#include "Timer.h"
|
||||
#include "Desc.h"
|
||||
#include "Serializer.h"
|
||||
#include "broker/Manager.h"
|
||||
|
||||
// Names of timers in same order than in TimerType.
|
||||
|
@ -53,41 +52,6 @@ void Timer::Describe(ODesc* d) const
|
|||
d->Add(Time());
|
||||
}
|
||||
|
||||
bool Timer::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Timer* Timer::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
Timer* timer = (Timer*) SerialObj::Unserialize(info, SER_TIMER);
|
||||
if ( ! timer )
|
||||
return 0;
|
||||
|
||||
timer_mgr->Add(timer);
|
||||
|
||||
return timer;
|
||||
}
|
||||
|
||||
bool Timer::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_TIMER, SerialObj);
|
||||
char tmp = type;
|
||||
return SERIALIZE(tmp) && SERIALIZE(time);
|
||||
}
|
||||
|
||||
bool Timer::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
char tmp;
|
||||
if ( ! UNSERIALIZE(&tmp) )
|
||||
return false;
|
||||
type = tmp;
|
||||
|
||||
return UNSERIALIZE(&time);
|
||||
}
|
||||
|
||||
unsigned int TimerMgr::current_timers[NUM_TIMER_TYPES];
|
||||
|
||||
TimerMgr::~TimerMgr()
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <string>
|
||||
|
||||
#include <string>
|
||||
#include "SerialObj.h"
|
||||
#include "PriorityQueue.h"
|
||||
|
||||
extern "C" {
|
||||
|
@ -49,10 +48,9 @@ const int NUM_TIMER_TYPES = int(TIMER_TIMERMGR_EXPIRE) + 1;
|
|||
|
||||
extern const char* timer_type_to_string(TimerType type);
|
||||
|
||||
class Serializer;
|
||||
class ODesc;
|
||||
|
||||
class Timer : public SerialObj, public PQ_Element {
|
||||
class Timer : public PQ_Element {
|
||||
public:
|
||||
Timer(double t, TimerType arg_type) : PQ_Element(t)
|
||||
{ type = (char) arg_type; }
|
||||
|
@ -67,14 +65,9 @@ public:
|
|||
|
||||
void Describe(ODesc* d) const;
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Timer* Unserialize(UnserialInfo* info);
|
||||
|
||||
protected:
|
||||
Timer() {}
|
||||
|
||||
DECLARE_ABSTRACT_SERIAL(Timer);
|
||||
|
||||
unsigned int type:8;
|
||||
};
|
||||
|
||||
|
|
518
src/Type.cc
518
src/Type.cc
|
@ -6,7 +6,6 @@
|
|||
#include "Attr.h"
|
||||
#include "Expr.h"
|
||||
#include "Scope.h"
|
||||
#include "Serializer.h"
|
||||
#include "Reporter.h"
|
||||
#include "zeekygen/Manager.h"
|
||||
#include "zeekygen/utils.h"
|
||||
|
@ -124,25 +123,8 @@ BroType::BroType(TypeTag t, bool arg_base_type)
|
|||
|
||||
BroType* BroType::Clone() const
|
||||
{
|
||||
SerializationFormat* form = new BinarySerializationFormat();
|
||||
form->StartWrite();
|
||||
CloneSerializer ss(form);
|
||||
SerialInfo sinfo(&ss);
|
||||
sinfo.cache = false;
|
||||
|
||||
this->Serialize(&sinfo);
|
||||
char* data;
|
||||
uint32 len = form->EndWrite(&data);
|
||||
form->StartRead(data, len);
|
||||
|
||||
UnserialInfo uinfo(&ss);
|
||||
uinfo.cache = false;
|
||||
|
||||
BroType* rval = this->Unserialize(&uinfo, false);
|
||||
assert(rval != this);
|
||||
|
||||
free(data);
|
||||
return rval;
|
||||
// Fixme: Johanna
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int BroType::MatchesIndex(ListExpr*& index) const
|
||||
|
@ -203,124 +185,6 @@ unsigned int BroType::MemoryAllocation() const
|
|||
return padded_sizeof(*this);
|
||||
}
|
||||
|
||||
bool BroType::Serialize(SerialInfo* info) const
|
||||
{
|
||||
// We always send full types (see below).
|
||||
if ( ! SERIALIZE(true) )
|
||||
return false;
|
||||
|
||||
bool ret = SerialObj::Serialize(info);
|
||||
return ret;
|
||||
}
|
||||
|
||||
BroType* BroType::Unserialize(UnserialInfo* info, bool use_existing)
|
||||
{
|
||||
// To avoid external Broccoli clients needing to always send full type
|
||||
// objects, we allow them to give us only the name of a type. To
|
||||
// differentiate between the two cases, we exchange a flag first.
|
||||
bool full_type = true;;
|
||||
if ( ! UNSERIALIZE(&full_type) )
|
||||
return 0;
|
||||
|
||||
if ( ! full_type )
|
||||
{
|
||||
const char* name;
|
||||
if ( ! UNSERIALIZE_STR(&name, 0) )
|
||||
return 0;
|
||||
|
||||
ID* id = global_scope()->Lookup(name);
|
||||
if ( ! id )
|
||||
{
|
||||
info->s->Error(fmt("unknown type %s", name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
BroType* t = id->AsType();
|
||||
if ( ! t )
|
||||
{
|
||||
info->s->Error(fmt("%s is not a type", name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return t->Ref();
|
||||
}
|
||||
|
||||
BroType* t = (BroType*) SerialObj::Unserialize(info, SER_BRO_TYPE);
|
||||
|
||||
if ( ! t || ! use_existing )
|
||||
return t;
|
||||
|
||||
if ( ! t->name.empty() )
|
||||
{
|
||||
// Avoid creating a new type if it's known by name.
|
||||
// Also avoids loss of base type name alias (from condition below).
|
||||
ID* id = global_scope()->Lookup(t->name.c_str());
|
||||
BroType* t2 = id ? id->AsType() : 0;
|
||||
|
||||
if ( t2 )
|
||||
{
|
||||
Unref(t);
|
||||
return t2->Ref();
|
||||
}
|
||||
}
|
||||
|
||||
if ( t->base_type )
|
||||
{
|
||||
BroType* t2 = ::base_type(TypeTag(t->tag));
|
||||
Unref(t);
|
||||
assert(t2);
|
||||
return t2;
|
||||
}
|
||||
|
||||
assert(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BroType, SER_BRO_TYPE)
|
||||
|
||||
bool BroType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BRO_TYPE, BroObj);
|
||||
|
||||
info->s->WriteOpenTag("Type");
|
||||
|
||||
if ( ! (SERIALIZE(char(tag)) && SERIALIZE(char(internal_tag))) )
|
||||
return false;
|
||||
|
||||
if ( ! (SERIALIZE(is_network_order) && SERIALIZE(base_type)) )
|
||||
return false;
|
||||
|
||||
SERIALIZE_STR(name.c_str(), name.size());
|
||||
|
||||
info->s->WriteCloseTag("Type");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BroType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroObj);
|
||||
|
||||
char c1, c2;
|
||||
if ( ! (UNSERIALIZE(&c1) && UNSERIALIZE(&c2) ) )
|
||||
return 0;
|
||||
|
||||
tag = (TypeTag) c1;
|
||||
internal_tag = (InternalTypeTag) c2;
|
||||
|
||||
if ( ! (UNSERIALIZE(&is_network_order) && UNSERIALIZE(&base_type)) )
|
||||
return 0;
|
||||
|
||||
const char* n;
|
||||
if ( ! UNSERIALIZE_STR(&n, 0) )
|
||||
return false;
|
||||
|
||||
name = n;
|
||||
delete [] n;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TypeList::~TypeList()
|
||||
{
|
||||
loop_over_list(types, i)
|
||||
|
@ -383,47 +247,6 @@ void TypeList::Describe(ODesc* d) const
|
|||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(TypeList, SER_TYPE_LIST);
|
||||
|
||||
bool TypeList::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_TYPE_LIST, BroType);
|
||||
|
||||
SERIALIZE_OPTIONAL(pure_type);
|
||||
|
||||
if ( ! SERIALIZE(types.length()) )
|
||||
return false;
|
||||
|
||||
loop_over_list(types, j)
|
||||
{
|
||||
if ( ! types[j]->Serialize(info) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TypeList::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroType);
|
||||
|
||||
UNSERIALIZE_OPTIONAL(pure_type, BroType::Unserialize(info));
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
return false;
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
BroType* t = BroType::Unserialize(info);
|
||||
if ( ! t )
|
||||
return false;
|
||||
|
||||
types.append(t);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
IndexType::~IndexType()
|
||||
{
|
||||
Unref(indices);
|
||||
|
@ -530,25 +353,6 @@ bool IndexType::IsSubNetIndex() const
|
|||
return false;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(IndexType, SER_INDEX_TYPE);
|
||||
|
||||
bool IndexType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_INDEX_TYPE, BroType);
|
||||
|
||||
SERIALIZE_OPTIONAL(yield_type);
|
||||
return indices->Serialize(info);
|
||||
}
|
||||
|
||||
bool IndexType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroType);
|
||||
|
||||
UNSERIALIZE_OPTIONAL(yield_type, BroType::Unserialize(info));
|
||||
indices = (TypeList*) BroType::Unserialize(info);
|
||||
return indices != 0;
|
||||
}
|
||||
|
||||
TableType::TableType(TypeList* ind, BroType* yield)
|
||||
: IndexType(TYPE_TABLE, ind, yield)
|
||||
{
|
||||
|
@ -650,43 +454,11 @@ SetType::SetType(TypeList* ind, ListExpr* arg_elements) : TableType(ind, 0)
|
|||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(TableType, SER_TABLE_TYPE);
|
||||
|
||||
bool TableType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_TABLE_TYPE, IndexType);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TableType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(IndexType);
|
||||
return true;
|
||||
}
|
||||
|
||||
SetType::~SetType()
|
||||
{
|
||||
Unref(elements);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(SetType, SER_SET_TYPE);
|
||||
|
||||
bool SetType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_SET_TYPE, TableType);
|
||||
|
||||
SERIALIZE_OPTIONAL(elements);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(TableType);
|
||||
|
||||
UNSERIALIZE_OPTIONAL(elements, (ListExpr*) Expr::Unserialize(info, EXPR_LIST));
|
||||
return true;
|
||||
}
|
||||
|
||||
FuncType::FuncType(RecordType* arg_args, BroType* arg_yield, function_flavor arg_flavor)
|
||||
: BroType(TYPE_FUNC)
|
||||
{
|
||||
|
@ -822,80 +594,6 @@ void FuncType::DescribeReST(ODesc* d, bool roles_only) const
|
|||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(FuncType, SER_FUNC_TYPE);
|
||||
|
||||
bool FuncType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_FUNC_TYPE, BroType);
|
||||
|
||||
assert(args);
|
||||
assert(arg_types);
|
||||
|
||||
SERIALIZE_OPTIONAL(yield);
|
||||
|
||||
int ser_flavor = 0;
|
||||
|
||||
switch ( flavor ) {
|
||||
|
||||
case FUNC_FLAVOR_FUNCTION:
|
||||
ser_flavor = 0;
|
||||
break;
|
||||
|
||||
case FUNC_FLAVOR_EVENT:
|
||||
ser_flavor = 1;
|
||||
break;
|
||||
|
||||
case FUNC_FLAVOR_HOOK:
|
||||
ser_flavor = 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
reporter->InternalError("Invalid function flavor serialization");
|
||||
break;
|
||||
}
|
||||
|
||||
return args->Serialize(info) &&
|
||||
arg_types->Serialize(info) &&
|
||||
SERIALIZE(ser_flavor);
|
||||
}
|
||||
|
||||
bool FuncType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroType);
|
||||
|
||||
UNSERIALIZE_OPTIONAL(yield, BroType::Unserialize(info));
|
||||
|
||||
args = (RecordType*) BroType::Unserialize(info);
|
||||
if ( ! args )
|
||||
return false;
|
||||
|
||||
arg_types = (TypeList*) BroType::Unserialize(info);
|
||||
if ( ! arg_types )
|
||||
return false;
|
||||
|
||||
int ser_flavor = 0;
|
||||
|
||||
if ( ! UNSERIALIZE(&ser_flavor) )
|
||||
return false;
|
||||
|
||||
switch ( ser_flavor ) {
|
||||
case 0:
|
||||
flavor = FUNC_FLAVOR_FUNCTION;
|
||||
break;
|
||||
case 1:
|
||||
flavor = FUNC_FLAVOR_EVENT;
|
||||
break;
|
||||
case 2:
|
||||
flavor = FUNC_FLAVOR_HOOK;
|
||||
break;
|
||||
default:
|
||||
reporter->InternalError("Invalid function flavor unserialization");
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TypeDecl::TypeDecl(BroType* t, const char* i, attr_list* arg_attrs, bool in_record)
|
||||
{
|
||||
type = t;
|
||||
|
@ -921,35 +619,6 @@ TypeDecl::~TypeDecl()
|
|||
delete [] id;
|
||||
}
|
||||
|
||||
bool TypeDecl::Serialize(SerialInfo* info) const
|
||||
{
|
||||
assert(type);
|
||||
assert(id);
|
||||
|
||||
SERIALIZE_OPTIONAL(attrs);
|
||||
|
||||
if ( ! (type->Serialize(info) && SERIALIZE(id)) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TypeDecl* TypeDecl::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
TypeDecl* t = new TypeDecl(0, 0, 0);
|
||||
|
||||
UNSERIALIZE_OPTIONAL_STATIC(t->attrs, Attributes::Unserialize(info), t);
|
||||
t->type = BroType::Unserialize(info);
|
||||
|
||||
if ( ! (t->type && UNSERIALIZE_STR(&t->id, 0)) )
|
||||
{
|
||||
delete t;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void TypeDecl::DescribeReST(ODesc* d, bool roles_only) const
|
||||
{
|
||||
d->Add(id);
|
||||
|
@ -1253,67 +922,6 @@ void RecordType::DescribeFieldsReST(ODesc* d, bool func_args) const
|
|||
d->PopIndentNoNL();
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(RecordType, SER_RECORD_TYPE)
|
||||
|
||||
bool RecordType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_RECORD_TYPE, BroType);
|
||||
|
||||
if ( ! SERIALIZE(num_fields) )
|
||||
return false;
|
||||
|
||||
if ( types )
|
||||
{
|
||||
if ( ! (SERIALIZE(true) && SERIALIZE(types->length())) )
|
||||
return false;
|
||||
|
||||
loop_over_list(*types, i)
|
||||
{
|
||||
if ( ! (*types)[i]->Serialize(info) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if ( ! SERIALIZE(false) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RecordType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroType);
|
||||
|
||||
if ( ! UNSERIALIZE(&num_fields) )
|
||||
return false;
|
||||
|
||||
bool has_it;
|
||||
if ( ! UNSERIALIZE(&has_it) )
|
||||
return false;
|
||||
|
||||
if ( has_it )
|
||||
{
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
return false;
|
||||
|
||||
types = new type_decl_list(len);
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
TypeDecl* t = TypeDecl::Unserialize(info);
|
||||
if ( ! t )
|
||||
return false;
|
||||
|
||||
types->append(t);
|
||||
}
|
||||
}
|
||||
else
|
||||
types = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SubNetType::SubNetType() : BroType(TYPE_SUBNET)
|
||||
{
|
||||
}
|
||||
|
@ -1326,20 +934,6 @@ void SubNetType::Describe(ODesc* d) const
|
|||
d->Add(int(Tag()));
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(SubNetType, SER_SUBNET_TYPE);
|
||||
|
||||
bool SubNetType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_SUBNET_TYPE, BroType);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SubNetType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroType);
|
||||
return true;
|
||||
}
|
||||
|
||||
FileType::FileType(BroType* yield_type)
|
||||
: BroType(TYPE_FILE)
|
||||
{
|
||||
|
@ -1370,24 +964,6 @@ void FileType::Describe(ODesc* d) const
|
|||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(FileType, SER_FILE_TYPE);
|
||||
|
||||
bool FileType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_FILE_TYPE, BroType);
|
||||
|
||||
assert(yield);
|
||||
return yield->Serialize(info);
|
||||
}
|
||||
|
||||
bool FileType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroType);
|
||||
|
||||
yield = BroType::Unserialize(info);
|
||||
return yield != 0;
|
||||
}
|
||||
|
||||
OpaqueType::OpaqueType(const string& arg_name) : BroType(TYPE_OPAQUE)
|
||||
{
|
||||
name = arg_name;
|
||||
|
@ -1408,28 +984,6 @@ void OpaqueType::DescribeReST(ODesc* d, bool roles_only) const
|
|||
d->Add(fmt(":zeek:type:`%s` of %s", type_name(Tag()), name.c_str()));
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(OpaqueType, SER_OPAQUE_TYPE);
|
||||
|
||||
bool OpaqueType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_OPAQUE_TYPE, BroType);
|
||||
return SERIALIZE_STR(name.c_str(), name.size());
|
||||
}
|
||||
|
||||
bool OpaqueType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroType);
|
||||
|
||||
const char* n;
|
||||
if ( ! UNSERIALIZE_STR(&n, 0) )
|
||||
return false;
|
||||
|
||||
name = n;
|
||||
delete [] n;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
EnumType::EnumType(const string& name)
|
||||
: BroType(TYPE_ENUM)
|
||||
{
|
||||
|
@ -1672,59 +1226,6 @@ void EnumType::DescribeReST(ODesc* d, bool roles_only) const
|
|||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(EnumType, SER_ENUM_TYPE);
|
||||
|
||||
bool EnumType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_ENUM_TYPE, BroType);
|
||||
|
||||
if ( ! (SERIALIZE(counter) && SERIALIZE((unsigned int) names.size()) &&
|
||||
// Dummy boolean for backwards compatibility.
|
||||
SERIALIZE(false)) )
|
||||
return false;
|
||||
|
||||
for ( NameMap::const_iterator iter = names.begin();
|
||||
iter != names.end(); ++iter )
|
||||
{
|
||||
if ( ! SERIALIZE(iter->first) || ! SERIALIZE(iter->second) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EnumType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroType);
|
||||
|
||||
unsigned int len;
|
||||
bool dummy;
|
||||
if ( ! UNSERIALIZE(&counter) ||
|
||||
! UNSERIALIZE(&len) ||
|
||||
// Dummy boolean for backwards compatibility.
|
||||
! UNSERIALIZE(&dummy) )
|
||||
return false;
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
const char* name;
|
||||
bro_int_t val;
|
||||
if ( ! (UNSERIALIZE_STR(&name, 0) && UNSERIALIZE(&val)) )
|
||||
return false;
|
||||
|
||||
names[name] = val;
|
||||
delete [] name; // names[name] converts to std::string
|
||||
// note: the 'vals' map gets populated lazily, which works fine and
|
||||
// also happens to avoid a leak due to circular reference between the
|
||||
// types and vals (there's a special case for unserializing a known
|
||||
// type that will unserialze and then immediately want to unref the
|
||||
// type if we already have it, except that won't delete it as intended
|
||||
// if we've already created circular references to it here).
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
VectorType::VectorType(BroType* element_type)
|
||||
: BroType(TYPE_VECTOR), yield_type(element_type)
|
||||
{
|
||||
|
@ -1791,21 +1292,6 @@ bool VectorType::IsUnspecifiedVector() const
|
|||
return yield_type->Tag() == TYPE_VOID;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(VectorType, SER_VECTOR_TYPE);
|
||||
|
||||
bool VectorType::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_VECTOR_TYPE, BroType);
|
||||
return yield_type->Serialize(info);
|
||||
}
|
||||
|
||||
bool VectorType::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroType);
|
||||
yield_type = BroType::Unserialize(info);
|
||||
return yield_type != 0;
|
||||
}
|
||||
|
||||
void VectorType::Describe(ODesc* d) const
|
||||
{
|
||||
if ( d->IsReadable() )
|
||||
|
|
31
src/Type.h
31
src/Type.h
|
@ -72,7 +72,6 @@ class SubNetType;
|
|||
class FuncType;
|
||||
class ListExpr;
|
||||
class EnumType;
|
||||
class Serializer;
|
||||
class VectorType;
|
||||
class TypeType;
|
||||
class OpaqueType;
|
||||
|
@ -256,9 +255,6 @@ public:
|
|||
|
||||
virtual unsigned MemoryAllocation() const;
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static BroType* Unserialize(UnserialInfo* info, bool use_existing = true);
|
||||
|
||||
void SetName(const string& arg_name) { name = arg_name; }
|
||||
string GetName() const { return name; }
|
||||
|
||||
|
@ -275,8 +271,6 @@ protected:
|
|||
|
||||
void SetError();
|
||||
|
||||
DECLARE_SERIAL(BroType)
|
||||
|
||||
private:
|
||||
TypeTag tag;
|
||||
InternalTypeTag internal_tag;
|
||||
|
@ -325,8 +319,6 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(TypeList)
|
||||
|
||||
BroType* pure_type;
|
||||
type_list types;
|
||||
};
|
||||
|
@ -356,8 +348,6 @@ protected:
|
|||
}
|
||||
~IndexType() override;
|
||||
|
||||
DECLARE_SERIAL(IndexType)
|
||||
|
||||
TypeList* indices;
|
||||
BroType* yield_type;
|
||||
};
|
||||
|
@ -374,8 +364,6 @@ protected:
|
|||
TableType() {}
|
||||
|
||||
TypeList* ExpandRecordIndex(RecordType* rt) const;
|
||||
|
||||
DECLARE_SERIAL(TableType)
|
||||
};
|
||||
|
||||
class SetType : public TableType {
|
||||
|
@ -389,8 +377,6 @@ protected:
|
|||
SetType() {}
|
||||
|
||||
ListExpr* elements;
|
||||
|
||||
DECLARE_SERIAL(SetType)
|
||||
};
|
||||
|
||||
class FuncType : public BroType {
|
||||
|
@ -420,8 +406,6 @@ public:
|
|||
|
||||
protected:
|
||||
FuncType() { args = 0; arg_types = 0; yield = 0; flavor = FUNC_FLAVOR_FUNCTION; }
|
||||
DECLARE_SERIAL(FuncType)
|
||||
|
||||
RecordType* args;
|
||||
TypeList* arg_types;
|
||||
BroType* yield;
|
||||
|
@ -450,9 +434,6 @@ public:
|
|||
const Attr* FindAttr(attr_tag a) const
|
||||
{ return attrs ? attrs->FindAttr(a) : 0; }
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static TypeDecl* Unserialize(UnserialInfo* info);
|
||||
|
||||
virtual void DescribeReST(ODesc* d, bool roles_only = false) const;
|
||||
|
||||
BroType* type;
|
||||
|
@ -501,8 +482,6 @@ public:
|
|||
protected:
|
||||
RecordType() { types = 0; }
|
||||
|
||||
DECLARE_SERIAL(RecordType)
|
||||
|
||||
int num_fields;
|
||||
type_decl_list* types;
|
||||
};
|
||||
|
@ -511,8 +490,6 @@ class SubNetType : public BroType {
|
|||
public:
|
||||
SubNetType();
|
||||
void Describe(ODesc* d) const override;
|
||||
protected:
|
||||
DECLARE_SERIAL(SubNetType)
|
||||
};
|
||||
|
||||
class FileType : public BroType {
|
||||
|
@ -527,8 +504,6 @@ public:
|
|||
protected:
|
||||
FileType() { yield = 0; }
|
||||
|
||||
DECLARE_SERIAL(FileType)
|
||||
|
||||
BroType* yield;
|
||||
};
|
||||
|
||||
|
@ -545,8 +520,6 @@ public:
|
|||
protected:
|
||||
OpaqueType() { }
|
||||
|
||||
DECLARE_SERIAL(OpaqueType)
|
||||
|
||||
string name;
|
||||
};
|
||||
|
||||
|
@ -582,8 +555,6 @@ public:
|
|||
protected:
|
||||
EnumType() { counter = 0; }
|
||||
|
||||
DECLARE_SERIAL(EnumType)
|
||||
|
||||
void AddNameInternal(const string& module_name,
|
||||
const char* name, bro_int_t val, bool is_export);
|
||||
|
||||
|
@ -625,8 +596,6 @@ public:
|
|||
protected:
|
||||
VectorType() { yield_type = 0; }
|
||||
|
||||
DECLARE_SERIAL(VectorType)
|
||||
|
||||
BroType* yield_type;
|
||||
};
|
||||
|
||||
|
|
791
src/Val.cc
791
src/Val.cc
|
@ -20,7 +20,6 @@
|
|||
#include "Scope.h"
|
||||
#include "NetVar.h"
|
||||
#include "Expr.h"
|
||||
#include "Serializer.h"
|
||||
#include "PrefixTable.h"
|
||||
#include "Conn.h"
|
||||
#include "Reporter.h"
|
||||
|
@ -73,243 +72,8 @@ Val::~Val()
|
|||
|
||||
Val* Val::Clone() const
|
||||
{
|
||||
SerializationFormat* form = new BinarySerializationFormat();
|
||||
form->StartWrite();
|
||||
|
||||
CloneSerializer ss(form);
|
||||
SerialInfo sinfo(&ss);
|
||||
sinfo.cache = false;
|
||||
sinfo.include_locations = false;
|
||||
|
||||
if ( ! this->Serialize(&sinfo) )
|
||||
return 0;
|
||||
|
||||
char* data;
|
||||
uint32 len = form->EndWrite(&data);
|
||||
form->StartRead(data, len);
|
||||
|
||||
UnserialInfo uinfo(&ss);
|
||||
uinfo.cache = false;
|
||||
Val* clone = Unserialize(&uinfo, type);
|
||||
|
||||
free(data);
|
||||
return clone;
|
||||
}
|
||||
|
||||
bool Val::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Val* Val::Unserialize(UnserialInfo* info, TypeTag type, const BroType* exact_type)
|
||||
{
|
||||
Val* v = (Val*) SerialObj::Unserialize(info, SER_VAL);
|
||||
if ( ! v )
|
||||
return 0;
|
||||
|
||||
if ( type != TYPE_ANY && (v->Type()->Tag() != type
|
||||
|| (exact_type && ! same_type(exact_type, v->Type()))) )
|
||||
{
|
||||
info->s->Error("type mismatch for value");
|
||||
Unref(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// For MutableVals, we may get a value which, by considering the
|
||||
// globally unique ID, we already know. To keep references correct,
|
||||
// we have to bind to the local version. (FIXME: This is not the
|
||||
// nicest solution. Ideally, DoUnserialize() should be able to pass
|
||||
// us an alternative ptr to the correct object.)
|
||||
if ( v->IsMutableVal() )
|
||||
{
|
||||
MutableVal* mv = v->AsMutableVal();
|
||||
if ( mv->HasUniqueID() )
|
||||
{
|
||||
ID* current =
|
||||
global_scope()->Lookup(mv->UniqueID()->Name());
|
||||
|
||||
if ( current && current != mv->UniqueID() )
|
||||
{
|
||||
DBG_LOG(DBG_STATE, "binding to already existing ID %s\n", current->Name());
|
||||
assert(current->ID_Val());
|
||||
|
||||
// Need to unset the ID here. Otherwise,
|
||||
// when the SerializationCache destroys
|
||||
// the value, the global name will disappear.
|
||||
mv->SetID(0);
|
||||
Unref(v);
|
||||
return current->ID_Val()->Ref();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An enum may be bound to a different internal number remotely than we
|
||||
// do for the same identifier. Check if this is the case, and, if yes,
|
||||
// rebind to our value.
|
||||
if ( v->Type()->Tag() == TYPE_ENUM )
|
||||
{
|
||||
int rv = v->AsEnum();
|
||||
EnumType* rt = v->Type()->AsEnumType();
|
||||
|
||||
const char* name = rt->Lookup(rv);
|
||||
if ( name )
|
||||
{
|
||||
// See if we know the enum locally.
|
||||
ID* local = global_scope()->Lookup(name);
|
||||
if ( local && local->IsEnumConst() )
|
||||
{
|
||||
EnumType* lt = local->Type()->AsEnumType();
|
||||
int lv = lt->Lookup(local->ModuleName(),
|
||||
local->Name());
|
||||
|
||||
// Compare.
|
||||
if ( rv != lv )
|
||||
{
|
||||
// Different, so let's bind the val
|
||||
// to the local type.
|
||||
v->val.int_val = lv;
|
||||
Unref(rt);
|
||||
v->type = lt;
|
||||
::Ref(lt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(Val, SER_VAL);
|
||||
|
||||
bool Val::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_VAL, BroObj);
|
||||
|
||||
if ( ! type->Serialize(info) )
|
||||
return false;
|
||||
|
||||
switch ( type->InternalType() ) {
|
||||
case TYPE_INTERNAL_VOID:
|
||||
info->s->Error("type is void");
|
||||
return false;
|
||||
|
||||
case TYPE_INTERNAL_INT:
|
||||
return SERIALIZE(val.int_val);
|
||||
|
||||
case TYPE_INTERNAL_UNSIGNED:
|
||||
return SERIALIZE(val.uint_val);
|
||||
|
||||
case TYPE_INTERNAL_DOUBLE:
|
||||
return SERIALIZE(val.double_val);
|
||||
|
||||
case TYPE_INTERNAL_STRING:
|
||||
return SERIALIZE_STR((const char*) val.string_val->Bytes(),
|
||||
val.string_val->Len());
|
||||
|
||||
case TYPE_INTERNAL_ADDR:
|
||||
return SERIALIZE(*val.addr_val);
|
||||
|
||||
case TYPE_INTERNAL_SUBNET:
|
||||
return SERIALIZE(*val.subnet_val);
|
||||
|
||||
case TYPE_INTERNAL_OTHER:
|
||||
// Derived classes are responsible for this.
|
||||
// Exception: Functions and files. There aren't any derived
|
||||
// classes.
|
||||
if ( type->Tag() == TYPE_FUNC )
|
||||
if ( ! AsFunc()->Serialize(info) )
|
||||
return false;
|
||||
|
||||
if ( type->Tag() == TYPE_FILE )
|
||||
if ( ! AsFile()->Serialize(info) )
|
||||
return false;
|
||||
return true;
|
||||
|
||||
case TYPE_INTERNAL_ERROR:
|
||||
info->s->Error("type is error");
|
||||
return false;
|
||||
|
||||
default:
|
||||
info->s->Error("type is out of range");
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Val::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BroObj);
|
||||
|
||||
if ( type )
|
||||
Unref(type);
|
||||
|
||||
if ( ! (type = BroType::Unserialize(info)) )
|
||||
return false;
|
||||
|
||||
switch ( type->InternalType() ) {
|
||||
case TYPE_INTERNAL_VOID:
|
||||
info->s->Error("type is void");
|
||||
return false;
|
||||
|
||||
case TYPE_INTERNAL_INT:
|
||||
return UNSERIALIZE(&val.int_val);
|
||||
|
||||
case TYPE_INTERNAL_UNSIGNED:
|
||||
return UNSERIALIZE(&val.uint_val);
|
||||
|
||||
case TYPE_INTERNAL_DOUBLE:
|
||||
return UNSERIALIZE(&val.double_val);
|
||||
|
||||
case TYPE_INTERNAL_STRING:
|
||||
const char* str;
|
||||
int len;
|
||||
if ( ! UNSERIALIZE_STR(&str, &len) )
|
||||
return false;
|
||||
|
||||
val.string_val = new BroString((u_char*) str, len, 1);
|
||||
delete [] str;
|
||||
return true;
|
||||
|
||||
case TYPE_INTERNAL_ADDR:
|
||||
{
|
||||
val.addr_val = new IPAddr();
|
||||
return UNSERIALIZE(val.addr_val);
|
||||
}
|
||||
|
||||
case TYPE_INTERNAL_SUBNET:
|
||||
{
|
||||
val.subnet_val = new IPPrefix();
|
||||
return UNSERIALIZE(val.subnet_val);
|
||||
}
|
||||
|
||||
case TYPE_INTERNAL_OTHER:
|
||||
// Derived classes are responsible for this.
|
||||
// Exception: Functions and files. There aren't any derived
|
||||
// classes.
|
||||
if ( type->Tag() == TYPE_FUNC )
|
||||
{
|
||||
val.func_val = Func::Unserialize(info);
|
||||
return val.func_val != 0;
|
||||
}
|
||||
else if ( type->Tag() == TYPE_FILE )
|
||||
{
|
||||
val.file_val = BroFile::Unserialize(info);
|
||||
return val.file_val != 0;
|
||||
}
|
||||
return true;
|
||||
|
||||
case TYPE_INTERNAL_ERROR:
|
||||
info->s->Error("type is error");
|
||||
return false;
|
||||
|
||||
default:
|
||||
info->s->Error("type out of range");
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
// Fixme: Johanna
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int Val::IsZero() const
|
||||
|
@ -652,61 +416,6 @@ void MutableVal::TransferUniqueID(MutableVal* mv)
|
|||
mv->id = 0;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(MutableVal, SER_MUTABLE_VAL);
|
||||
|
||||
bool MutableVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_MUTABLE_VAL, Val);
|
||||
|
||||
if ( ! SERIALIZE(props) )
|
||||
return false;
|
||||
|
||||
// Don't use ID::Serialize here, that would loop. All we
|
||||
// need is the name, anyway.
|
||||
const char* name = id ? id->Name() : "";
|
||||
if ( ! SERIALIZE(name) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MutableVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Val);
|
||||
|
||||
if ( ! UNSERIALIZE(&props) )
|
||||
return false;
|
||||
|
||||
id = 0;
|
||||
|
||||
const char* name;
|
||||
if ( ! UNSERIALIZE_STR(&name, 0) )
|
||||
return false;
|
||||
|
||||
if ( *name )
|
||||
{
|
||||
id = new ID(name, SCOPE_GLOBAL, true);
|
||||
id->SetVal(this, OP_NONE, true);
|
||||
|
||||
ID* current = global_scope()->Lookup(name);
|
||||
if ( ! current )
|
||||
{
|
||||
global_scope()->Insert(name, id);
|
||||
DBG_LOG(DBG_STATE, "installed formerly unknown ID %s", id->Name());
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG_LOG(DBG_STATE, "got already known ID %s", current->Name());
|
||||
// This means that we already know the value and
|
||||
// that in fact we should bind to the local value.
|
||||
// Val::Unserialize() will take care of this.
|
||||
}
|
||||
}
|
||||
|
||||
delete [] name;
|
||||
return true;
|
||||
}
|
||||
|
||||
IntervalVal::IntervalVal(double quantity, double units) :
|
||||
Val(quantity * units, TYPE_INTERVAL)
|
||||
{
|
||||
|
@ -749,20 +458,6 @@ void IntervalVal::ValDescribe(ODesc* d) const
|
|||
DO_UNIT(Microseconds, "usec")
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(IntervalVal, SER_INTERVAL_VAL);
|
||||
|
||||
bool IntervalVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_INTERVAL_VAL, Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IntervalVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
PortVal* PortManager::Get(uint32 port_num) const
|
||||
{
|
||||
return val_mgr->GetPort(port_num);
|
||||
|
@ -861,20 +556,6 @@ void PortVal::ValDescribe(ODesc* d) const
|
|||
d->Add("/unknown");
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(PortVal, SER_PORT_VAL);
|
||||
|
||||
bool PortVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_PORT_VAL, Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PortVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
AddrVal::AddrVal(const char* text) : Val(TYPE_ADDR)
|
||||
{
|
||||
val.addr_val = new IPAddr(text);
|
||||
|
@ -919,20 +600,6 @@ Val* AddrVal::SizeVal() const
|
|||
return val_mgr->GetCount(128);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(AddrVal, SER_ADDR_VAL);
|
||||
|
||||
bool AddrVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_ADDR_VAL, Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddrVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
SubNetVal::SubNetVal(const char* text) : Val(TYPE_SUBNET)
|
||||
{
|
||||
string s(text);
|
||||
|
@ -1043,20 +710,6 @@ bool SubNetVal::Contains(const IPAddr& addr) const
|
|||
return val.subnet_val->Contains(a);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(SubNetVal, SER_SUBNET_VAL);
|
||||
|
||||
bool SubNetVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_SUBNET_VAL, Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SubNetVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
StringVal::StringVal(BroString* s) : Val(TYPE_STRING)
|
||||
{
|
||||
val.string_val = s;
|
||||
|
@ -1099,20 +752,6 @@ unsigned int StringVal::MemoryAllocation() const
|
|||
return padded_sizeof(*this) + val.string_val->MemoryAllocation();
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(StringVal, SER_STRING_VAL);
|
||||
|
||||
bool StringVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_STRING_VAL, Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StringVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
PatternVal::PatternVal(RE_Matcher* re) : Val(base_type(TYPE_PATTERN))
|
||||
{
|
||||
val.re_val = re;
|
||||
|
@ -1161,22 +800,6 @@ unsigned int PatternVal::MemoryAllocation() const
|
|||
return padded_sizeof(*this) + val.re_val->MemoryAllocation();
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(PatternVal, SER_PATTERN_VAL);
|
||||
|
||||
bool PatternVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_PATTERN_VAL, Val);
|
||||
return AsPattern()->Serialize(info);
|
||||
}
|
||||
|
||||
bool PatternVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Val);
|
||||
|
||||
val.re_val = RE_Matcher::Unserialize(info);
|
||||
return val.re_val != 0;
|
||||
}
|
||||
|
||||
ListVal::ListVal(TypeTag t)
|
||||
: Val(new TypeList(t == TYPE_ANY ? 0 : base_type_no_ref(t)))
|
||||
{
|
||||
|
@ -1259,52 +882,6 @@ void ListVal::Describe(ODesc* d) const
|
|||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(ListVal, SER_LIST_VAL);
|
||||
|
||||
bool ListVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_LIST_VAL, Val);
|
||||
|
||||
if ( ! (SERIALIZE(char(tag)) && SERIALIZE(vals.length())) )
|
||||
return false;
|
||||
|
||||
loop_over_list(vals, i)
|
||||
{
|
||||
if ( ! vals[i]->Serialize(info) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ListVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Val);
|
||||
|
||||
char t;
|
||||
int len;
|
||||
|
||||
if ( ! (UNSERIALIZE(&t) && UNSERIALIZE(&len)) )
|
||||
return false;
|
||||
|
||||
tag = TypeTag(t);
|
||||
|
||||
while ( len-- )
|
||||
{
|
||||
Val* v = Val::Unserialize(info, TYPE_ANY);
|
||||
if ( ! v )
|
||||
return false;
|
||||
|
||||
vals.append(v);
|
||||
}
|
||||
|
||||
// Our dtor will do Unref(type) in addition to Val's dtor.
|
||||
if ( type )
|
||||
type->Ref();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int ListVal::MemoryAllocation() const
|
||||
{
|
||||
unsigned int size = 0;
|
||||
|
@ -1580,7 +1157,6 @@ int TableVal::Assign(Val* index, HashKey* k, Val* new_val, Opcode op)
|
|||
delete old_entry_val;
|
||||
}
|
||||
|
||||
Modified();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -2062,7 +1638,6 @@ Val* TableVal::Delete(const Val* index)
|
|||
delete k;
|
||||
delete v;
|
||||
|
||||
Modified();
|
||||
return va;
|
||||
}
|
||||
|
||||
|
@ -2084,7 +1659,6 @@ Val* TableVal::Delete(const HashKey* k)
|
|||
if ( LoggingAccess() )
|
||||
StateAccess::Log(new StateAccess(OP_DEL, this, k));
|
||||
|
||||
Modified();
|
||||
return va;
|
||||
}
|
||||
|
||||
|
@ -2354,7 +1928,6 @@ void TableVal::DoExpire(double t)
|
|||
tbl->RemoveEntry(k);
|
||||
Unref(v->Value());
|
||||
delete v;
|
||||
Modified();
|
||||
}
|
||||
|
||||
delete k;
|
||||
|
@ -2477,236 +2050,6 @@ void TableVal::ReadOperation(Val* index, TableEntryVal* v)
|
|||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(TableVal, SER_TABLE_VAL);
|
||||
|
||||
// This is getting rather complex due to the ability to suspend even within
|
||||
// deeply-nested values.
|
||||
bool TableVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE_WITH_SUSPEND(SER_TABLE_VAL, MutableVal);
|
||||
|
||||
// The current state of the serialization.
|
||||
struct State {
|
||||
IterCookie* c;
|
||||
TableEntryVal* v; // current value
|
||||
bool did_index; // already wrote the val's index
|
||||
}* state = 0;
|
||||
|
||||
PDict(TableEntryVal)* tbl =
|
||||
const_cast<TableVal*>(this)->AsNonConstTable();
|
||||
|
||||
if ( info->cont.NewInstance() )
|
||||
{
|
||||
// For simplicity, we disable suspension for the objects
|
||||
// serialized here. (In fact we know that *currently*
|
||||
// they won't even try).
|
||||
DisableSuspend suspend(info);
|
||||
|
||||
state = new State;
|
||||
state->c = tbl->InitForIteration();
|
||||
tbl->MakeRobustCookie(state->c);
|
||||
state->v = 0;
|
||||
state->did_index = false;
|
||||
info->s->WriteOpenTag(table_type->IsSet() ? "set" : "table");
|
||||
|
||||
SERIALIZE_OPTIONAL(attrs);
|
||||
SERIALIZE_OPTIONAL(expire_time);
|
||||
SERIALIZE_OPTIONAL(expire_func);
|
||||
|
||||
// Make sure nobody kills us in between.
|
||||
const_cast<TableVal*>(this)->Ref();
|
||||
}
|
||||
|
||||
else if ( info->cont.ChildSuspended() )
|
||||
state = (State*) info->cont.RestoreState();
|
||||
|
||||
else if ( info->cont.Resuming() )
|
||||
{
|
||||
info->cont.Resume();
|
||||
state = (State*) info->cont.RestoreState();
|
||||
}
|
||||
else
|
||||
reporter->InternalError("unknown continuation state");
|
||||
|
||||
HashKey* k = 0;
|
||||
int count = 0;
|
||||
|
||||
assert((!info->cont.ChildSuspended()) || state->v);
|
||||
|
||||
while ( true )
|
||||
{
|
||||
if ( ! state->v )
|
||||
{
|
||||
state->v = tbl->NextEntry(k, state->c);
|
||||
if ( ! state->c )
|
||||
{
|
||||
// No next one.
|
||||
if ( ! SERIALIZE(false) )
|
||||
{
|
||||
delete k;
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// There's a value coming.
|
||||
if ( ! SERIALIZE(true) )
|
||||
{
|
||||
delete k;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( state->v->Value() )
|
||||
state->v->Ref();
|
||||
|
||||
state->did_index = false;
|
||||
}
|
||||
|
||||
// Serialize index.
|
||||
if ( k && ! state->did_index )
|
||||
{
|
||||
// Indices are rather small, so we disable suspension
|
||||
// here again.
|
||||
DisableSuspend suspend(info);
|
||||
info->s->WriteOpenTag("key");
|
||||
ListVal* index = table_hash->RecoverVals(k)->AsListVal();
|
||||
delete k;
|
||||
|
||||
if ( ! index->Serialize(info) )
|
||||
return false;
|
||||
|
||||
Unref(index);
|
||||
info->s->WriteCloseTag("key");
|
||||
|
||||
state->did_index = true;
|
||||
|
||||
// Start serializing data.
|
||||
if ( ! type->IsSet() )
|
||||
info->s->WriteOpenTag("value");
|
||||
}
|
||||
|
||||
if ( ! type->IsSet() )
|
||||
{
|
||||
info->cont.SaveState(state);
|
||||
info->cont.SaveContext();
|
||||
bool result = state->v->val->Serialize(info);
|
||||
info->cont.RestoreContext();
|
||||
|
||||
if ( ! result )
|
||||
return false;
|
||||
|
||||
if ( info->cont.ChildSuspended() )
|
||||
return true;
|
||||
}
|
||||
|
||||
double eat = state->v->ExpireAccessTime();
|
||||
|
||||
if ( ! (SERIALIZE(state->v->last_access_time) &&
|
||||
SERIALIZE(eat)) )
|
||||
return false;
|
||||
|
||||
info->s->WriteCloseTag("value");
|
||||
|
||||
if ( state->v->Value() )
|
||||
state->v->Unref();
|
||||
state->v = 0; // Next value.
|
||||
|
||||
// Suspend if we've done enough for now (which means we
|
||||
// have serialized more than table_incremental_step entries
|
||||
// in a row; if an entry has suspended itself in between,
|
||||
// we start counting from 0).
|
||||
if ( info->may_suspend && ++count > table_incremental_step)
|
||||
{
|
||||
info->cont.SaveState(state);
|
||||
info->cont.Suspend();
|
||||
reporter->Info("TableVals serialization suspended right in the middle.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
info->s->WriteCloseTag(table_type->IsSet() ? "set" : "table");
|
||||
delete state;
|
||||
|
||||
Unref(const_cast<TableVal*>(this));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TableVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(MutableVal);
|
||||
|
||||
Init((TableType*) type);
|
||||
|
||||
UNSERIALIZE_OPTIONAL(attrs, Attributes::Unserialize(info));
|
||||
UNSERIALIZE_OPTIONAL(expire_time, Expr::Unserialize(info));
|
||||
UNSERIALIZE_OPTIONAL(expire_func, Expr::Unserialize(info));
|
||||
|
||||
while ( true )
|
||||
{
|
||||
// Anymore?
|
||||
bool next;
|
||||
if ( ! UNSERIALIZE(&next) )
|
||||
return false;
|
||||
|
||||
if ( ! next )
|
||||
break;
|
||||
|
||||
// Unserialize index.
|
||||
ListVal* index =
|
||||
(ListVal*) Val::Unserialize(info, table_type->Indices());
|
||||
if ( ! index )
|
||||
return false;
|
||||
|
||||
// Unserialize data.
|
||||
Val* entry;
|
||||
if ( ! table_type->IsSet() )
|
||||
{
|
||||
entry = Val::Unserialize(info, type->YieldType());
|
||||
if ( ! entry )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
entry = 0;
|
||||
|
||||
TableEntryVal* entry_val = new TableEntryVal(entry);
|
||||
|
||||
double eat;
|
||||
|
||||
if ( ! UNSERIALIZE(&entry_val->last_access_time) ||
|
||||
! UNSERIALIZE(&eat) )
|
||||
{
|
||||
entry_val->Unref();
|
||||
delete entry_val;
|
||||
return false;
|
||||
}
|
||||
|
||||
entry_val->SetExpireAccess(eat);
|
||||
|
||||
HashKey* key = ComputeHash(index);
|
||||
TableEntryVal* old_entry_val =
|
||||
AsNonConstTable()->Insert(key, entry_val);
|
||||
assert(! old_entry_val);
|
||||
|
||||
delete key;
|
||||
|
||||
if ( subnets )
|
||||
subnets->Insert(index, entry_val);
|
||||
|
||||
Unref(index);
|
||||
}
|
||||
|
||||
// If necessary, activate the expire timer.
|
||||
if ( attrs )
|
||||
{
|
||||
CheckExpireAttr(ATTR_EXPIRE_READ);
|
||||
CheckExpireAttr(ATTR_EXPIRE_WRITE);
|
||||
CheckExpireAttr(ATTR_EXPIRE_CREATE);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TableVal::AddProperties(Properties arg_props)
|
||||
{
|
||||
if ( ! MutableVal::AddProperties(arg_props) )
|
||||
|
@ -2868,7 +2211,6 @@ void RecordVal::Assign(int field, Val* new_val, Opcode op)
|
|||
}
|
||||
|
||||
Unref(old_val);
|
||||
Modified();
|
||||
}
|
||||
|
||||
Val* RecordVal::Lookup(int field) const
|
||||
|
@ -3056,61 +2398,6 @@ void RecordVal::DescribeReST(ODesc* d) const
|
|||
d->Add("}");
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(RecordVal, SER_RECORD_VAL);
|
||||
|
||||
bool RecordVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_RECORD_VAL, MutableVal);
|
||||
|
||||
// We could use the type name as a tag here.
|
||||
info->s->WriteOpenTag("record");
|
||||
|
||||
// We don't need to serialize record_type as it's simply the
|
||||
// casted table_type.
|
||||
// FIXME: What about origin?
|
||||
|
||||
if ( ! SERIALIZE(val.val_list_val->length()) )
|
||||
return false;
|
||||
|
||||
loop_over_list(*val.val_list_val, i)
|
||||
{
|
||||
info->s->WriteOpenTag(record_type->FieldName(i));
|
||||
Val* v = (*val.val_list_val)[i];
|
||||
SERIALIZE_OPTIONAL(v);
|
||||
info->s->WriteCloseTag(record_type->FieldName(i));
|
||||
}
|
||||
|
||||
info->s->WriteCloseTag("record");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RecordVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(MutableVal);
|
||||
|
||||
record_type = (RecordType*) type;
|
||||
origin = 0;
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
{
|
||||
val.val_list_val = new val_list;
|
||||
return false;
|
||||
}
|
||||
|
||||
val.val_list_val = new val_list(len);
|
||||
|
||||
for ( int i = 0; i < len; ++i )
|
||||
{
|
||||
Val* v;
|
||||
UNSERIALIZE_OPTIONAL(v, Val::Unserialize(info));
|
||||
AsNonConstRecord()->append(v); // correct for v==0, too.
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RecordVal::AddProperties(Properties arg_props)
|
||||
{
|
||||
if ( ! MutableVal::AddProperties(arg_props) )
|
||||
|
@ -3172,20 +2459,6 @@ void EnumVal::ValDescribe(ODesc* d) const
|
|||
d->Add(ename);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(EnumVal, SER_ENUM_VAL);
|
||||
|
||||
bool EnumVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_ENUM_VAL, Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EnumVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
VectorVal::VectorVal(VectorType* t) : MutableVal(t)
|
||||
{
|
||||
vector_type = t->Ref()->AsVectorType();
|
||||
|
@ -3262,7 +2535,6 @@ bool VectorVal::Assign(unsigned int index, Val* element, Opcode op)
|
|||
// to do it similarly.
|
||||
(*val.vector_val)[index] = element;
|
||||
|
||||
Modified();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3357,51 +2629,6 @@ bool VectorVal::RemoveProperties(Properties arg_props)
|
|||
return true;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(VectorVal, SER_VECTOR_VAL);
|
||||
|
||||
bool VectorVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_VECTOR_VAL, MutableVal);
|
||||
|
||||
info->s->WriteOpenTag("vector");
|
||||
|
||||
if ( ! SERIALIZE(unsigned(val.vector_val->size())) )
|
||||
return false;
|
||||
|
||||
for ( unsigned int i = 0; i < val.vector_val->size(); ++i )
|
||||
{
|
||||
info->s->WriteOpenTag("value");
|
||||
Val* v = (*val.vector_val)[i];
|
||||
SERIALIZE_OPTIONAL(v);
|
||||
info->s->WriteCloseTag("value");
|
||||
}
|
||||
|
||||
info->s->WriteCloseTag("vector");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VectorVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(MutableVal);
|
||||
|
||||
val.vector_val = new vector<Val*>;
|
||||
vector_type = type->Ref()->AsVectorType();
|
||||
|
||||
int len;
|
||||
if ( ! UNSERIALIZE(&len) )
|
||||
return false;
|
||||
|
||||
for ( int i = 0; i < len; ++i )
|
||||
{
|
||||
Val* v;
|
||||
UNSERIALIZE_OPTIONAL(v, Val::Unserialize(info, TYPE_ANY)); // accept any type
|
||||
Assign(i, v);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VectorVal::ValDescribe(ODesc* d) const
|
||||
{
|
||||
d->Add("[");
|
||||
|
@ -3429,20 +2656,6 @@ OpaqueVal::~OpaqueVal()
|
|||
{
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(OpaqueVal, SER_OPAQUE_VAL);
|
||||
|
||||
bool OpaqueVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_OPAQUE_VAL, Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpaqueVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Val);
|
||||
return true;
|
||||
}
|
||||
|
||||
Val* check_and_promote(Val* v, const BroType* t, int is_init)
|
||||
{
|
||||
if ( ! v )
|
||||
|
|
52
src/Val.h
52
src/Val.h
|
@ -20,6 +20,7 @@
|
|||
#include "Scope.h"
|
||||
#include "StateAccess.h"
|
||||
#include "IPAddr.h"
|
||||
#include "DebugLogger.h"
|
||||
|
||||
// We have four different port name spaces: TCP, UDP, ICMP, and UNKNOWN.
|
||||
// We distinguish between them based on the bits specified in the *_PORT_MASK
|
||||
|
@ -36,7 +37,6 @@ class Func;
|
|||
class BroFile;
|
||||
class RE_Matcher;
|
||||
class PrefixTable;
|
||||
class SerialInfo;
|
||||
|
||||
class PortVal;
|
||||
class AddrVal;
|
||||
|
@ -344,14 +344,6 @@ public:
|
|||
void Describe(ODesc* d) const override;
|
||||
virtual void DescribeReST(ODesc* d) const;
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Val* Unserialize(UnserialInfo* info, TypeTag type = TYPE_ANY)
|
||||
{ return Unserialize(info, type, 0); }
|
||||
static Val* Unserialize(UnserialInfo* info, const BroType* exact_type)
|
||||
{ return Unserialize(info, exact_type->Tag(), exact_type); }
|
||||
|
||||
DECLARE_SERIAL(Val);
|
||||
|
||||
#ifdef DEBUG
|
||||
// For debugging, we keep a reference to the global ID to which a
|
||||
// value has been bound *last*.
|
||||
|
@ -415,10 +407,6 @@ protected:
|
|||
ACCESSOR(TYPE_TABLE, PDict(TableEntryVal)*, table_val, AsNonConstTable)
|
||||
ACCESSOR(TYPE_RECORD, val_list*, val_list_val, AsNonConstRecord)
|
||||
|
||||
// Just an internal helper.
|
||||
static Val* Unserialize(UnserialInfo* info, TypeTag type,
|
||||
const BroType* exact_type);
|
||||
|
||||
BroValUnion val;
|
||||
BroType* type;
|
||||
|
||||
|
@ -544,18 +532,10 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
uint64 LastModified() const override { return last_modified; }
|
||||
|
||||
// Mark value as changed.
|
||||
void Modified()
|
||||
{
|
||||
last_modified = IncreaseTimeCounter();
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit MutableVal(BroType* t) : Val(t)
|
||||
{ props = 0; id = 0; last_modified = SerialObj::ALWAYS; }
|
||||
MutableVal() { props = 0; id = 0; last_modified = SerialObj::ALWAYS; }
|
||||
{ props = 0; id = 0; }
|
||||
MutableVal() { props = 0; id = 0; }
|
||||
~MutableVal() override;
|
||||
|
||||
friend class ID;
|
||||
|
@ -563,8 +543,6 @@ protected:
|
|||
|
||||
void SetID(ID* arg_id) { Unref(id); id = arg_id; }
|
||||
|
||||
DECLARE_SERIAL(MutableVal);
|
||||
|
||||
private:
|
||||
ID* Bind() const;
|
||||
|
||||
|
@ -589,8 +567,6 @@ protected:
|
|||
IntervalVal() {}
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(IntervalVal);
|
||||
};
|
||||
|
||||
|
||||
|
@ -636,8 +612,6 @@ protected:
|
|||
PortVal(uint32 p, bool unused);
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(PortVal);
|
||||
};
|
||||
|
||||
class AddrVal : public Val {
|
||||
|
@ -660,8 +634,6 @@ protected:
|
|||
AddrVal() {}
|
||||
explicit AddrVal(TypeTag t) : Val(t) { }
|
||||
explicit AddrVal(BroType* t) : Val(t) { }
|
||||
|
||||
DECLARE_SERIAL(AddrVal);
|
||||
};
|
||||
|
||||
class SubNetVal : public Val {
|
||||
|
@ -689,8 +661,6 @@ protected:
|
|||
SubNetVal() {}
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(SubNetVal);
|
||||
};
|
||||
|
||||
class StringVal : public Val {
|
||||
|
@ -721,8 +691,6 @@ protected:
|
|||
StringVal() {}
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(StringVal);
|
||||
};
|
||||
|
||||
class PatternVal : public Val {
|
||||
|
@ -741,8 +709,6 @@ protected:
|
|||
PatternVal() {}
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(PatternVal);
|
||||
};
|
||||
|
||||
// ListVals are mainly used to index tables that have more than one
|
||||
|
@ -786,8 +752,6 @@ protected:
|
|||
friend class Val;
|
||||
ListVal() {}
|
||||
|
||||
DECLARE_SERIAL(ListVal);
|
||||
|
||||
val_list vals;
|
||||
TypeTag tag;
|
||||
};
|
||||
|
@ -994,8 +958,6 @@ protected:
|
|||
// Propagates a read operation if necessary.
|
||||
void ReadOperation(Val* index, TableEntryVal *v);
|
||||
|
||||
DECLARE_SERIAL(TableVal);
|
||||
|
||||
TableType* table_type;
|
||||
CompositeHash* table_hash;
|
||||
Attributes* attrs;
|
||||
|
@ -1066,8 +1028,6 @@ protected:
|
|||
bool AddProperties(Properties arg_state) override;
|
||||
bool RemoveProperties(Properties arg_state) override;
|
||||
|
||||
DECLARE_SERIAL(RecordVal);
|
||||
|
||||
RecordType* record_type;
|
||||
BroObj* origin;
|
||||
|
||||
|
@ -1097,8 +1057,6 @@ protected:
|
|||
EnumVal() {}
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(EnumVal);
|
||||
};
|
||||
|
||||
|
||||
|
@ -1158,8 +1116,6 @@ protected:
|
|||
bool RemoveProperties(Properties arg_state) override;
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(VectorVal);
|
||||
|
||||
VectorType* vector_type;
|
||||
};
|
||||
|
||||
|
@ -1174,8 +1130,6 @@ public:
|
|||
protected:
|
||||
friend class Val;
|
||||
OpaqueVal() { }
|
||||
|
||||
DECLARE_SERIAL(OpaqueVal);
|
||||
};
|
||||
|
||||
// Checks the given value for consistency with the given type. If an
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "Func.h"
|
||||
#include "Stmt.h"
|
||||
#include "Scope.h"
|
||||
#include "Serializer.h"
|
||||
#include "EventRegistry.h"
|
||||
#include "Traverse.h"
|
||||
|
||||
|
|
|
@ -444,20 +444,6 @@ void TCP_Reassembler::Overlap(const u_char* b1, const u_char* b2, uint64 n)
|
|||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(TCP_Reassembler, SER_TCP_REASSEMBLER);
|
||||
|
||||
bool TCP_Reassembler::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
reporter->InternalError("TCP_Reassembler::DoSerialize not implemented");
|
||||
return false; // Cannot be reached.
|
||||
}
|
||||
|
||||
bool TCP_Reassembler::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
reporter->InternalError("TCP_Reassembler::DoUnserialize not implemented");
|
||||
return false; // Cannot be reached.
|
||||
}
|
||||
|
||||
void TCP_Reassembler::Deliver(uint64 seq, int len, const u_char* data)
|
||||
{
|
||||
if ( type == Direct )
|
||||
|
|
|
@ -89,8 +89,6 @@ public:
|
|||
private:
|
||||
TCP_Reassembler() { }
|
||||
|
||||
DECLARE_SERIAL(TCP_Reassembler);
|
||||
|
||||
void Undelivered(uint64 up_to_seq) override;
|
||||
void Gap(uint64 seq, uint64 len);
|
||||
|
||||
|
|
29
src/bro.bif
29
src/bro.bif
|
@ -4886,7 +4886,7 @@ function uninstall_dst_net_filter%(snet: subnet%) : bool
|
|||
%}
|
||||
|
||||
## Writes the binary event stream generated by the core to a given file.
|
||||
## Use the ``-x <filename>`` command line switch to replay saved events.
|
||||
## Use the ``-R <filename>`` command line switch to replay saved events.
|
||||
##
|
||||
## filename: The name of the file which stores the events.
|
||||
##
|
||||
|
@ -4895,32 +4895,9 @@ function uninstall_dst_net_filter%(snet: subnet%) : bool
|
|||
## .. zeek:see:: capture_state_updates
|
||||
function capture_events%(filename: string%) : bool
|
||||
%{
|
||||
if ( ! event_serializer )
|
||||
event_serializer = new FileSerializer();
|
||||
else
|
||||
event_serializer->Close();
|
||||
// Fixme: johanna
|
||||
|
||||
return val_mgr->GetBool(event_serializer->Open(
|
||||
(const char*) filename->CheckString()));
|
||||
%}
|
||||
|
||||
## Writes state updates generated by :zeek:attr:`&synchronized` variables to a
|
||||
## file.
|
||||
##
|
||||
## filename: The name of the file which stores the state updates.
|
||||
##
|
||||
## Returns: True if opening the target file succeeds.
|
||||
##
|
||||
## .. zeek:see:: capture_events
|
||||
function capture_state_updates%(filename: string%) : bool
|
||||
%{
|
||||
if ( ! state_serializer )
|
||||
state_serializer = new FileSerializer();
|
||||
else
|
||||
state_serializer->Close();
|
||||
|
||||
return val_mgr->GetBool(state_serializer->Open(
|
||||
(const char*) filename->CheckString()));
|
||||
return val_mgr->GetBool(true);
|
||||
%}
|
||||
|
||||
## Checks whether the last raised event came from a remote peer.
|
||||
|
|
|
@ -128,12 +128,8 @@ struct val_converter {
|
|||
}
|
||||
case TYPE_OPAQUE:
|
||||
{
|
||||
SerializationFormat* form = new BinarySerializationFormat();
|
||||
form->StartRead(a.data(), a.size());
|
||||
CloneSerializer ss(form);
|
||||
UnserialInfo uinfo(&ss);
|
||||
uinfo.cache = false;
|
||||
return Val::Unserialize(&uinfo, type->Tag());
|
||||
// Fixme: Johanna
|
||||
return nullptr;
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
|
@ -511,12 +507,8 @@ struct type_checker {
|
|||
case TYPE_OPAQUE:
|
||||
{
|
||||
// TODO
|
||||
SerializationFormat* form = new BinarySerializationFormat();
|
||||
form->StartRead(a.data(), a.size());
|
||||
CloneSerializer ss(form);
|
||||
UnserialInfo uinfo(&ss);
|
||||
uinfo.cache = false;
|
||||
return Val::Unserialize(&uinfo, type->Tag());
|
||||
// Fixme: johanna
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
|
@ -978,24 +970,10 @@ broker::expected<broker::data> bro_broker::val_to_data(Val* v)
|
|||
broker::vector rval = {p->PatternText(), p->AnywherePatternText()};
|
||||
return {std::move(rval)};
|
||||
}
|
||||
case TYPE_OPAQUE:
|
||||
{
|
||||
SerializationFormat* form = new BinarySerializationFormat();
|
||||
form->StartWrite();
|
||||
CloneSerializer ss(form);
|
||||
SerialInfo sinfo(&ss);
|
||||
sinfo.cache = false;
|
||||
sinfo.include_locations = false;
|
||||
|
||||
if ( ! v->Serialize(&sinfo) )
|
||||
return broker::ec::invalid_data;
|
||||
|
||||
char* data;
|
||||
uint32 len = form->EndWrite(&data);
|
||||
string rval(data, len);
|
||||
free(data);
|
||||
return {std::move(rval)};
|
||||
}
|
||||
// Fixme: johanna
|
||||
// case TYPE_OPAQUE:
|
||||
// {
|
||||
// }
|
||||
default:
|
||||
reporter->Error("unsupported Broker::Data type: %s",
|
||||
type_name(v->Type()->Tag()));
|
||||
|
@ -1131,42 +1109,6 @@ Val* bro_broker::DataVal::castTo(BroType* t)
|
|||
return data_to_val(data, t);
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(bro_broker::DataVal, SER_COMM_DATA_VAL);
|
||||
|
||||
bool bro_broker::DataVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_COMM_DATA_VAL, OpaqueVal);
|
||||
|
||||
std::string buffer;
|
||||
caf::containerbuf<std::string> sb{buffer};
|
||||
caf::stream_serializer<caf::containerbuf<std::string>&> serializer{sb};
|
||||
serializer << data;
|
||||
|
||||
if ( ! SERIALIZE_STR(buffer.data(), buffer.size()) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bro_broker::DataVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
|
||||
const char* serial;
|
||||
int len;
|
||||
|
||||
if ( ! UNSERIALIZE_STR(&serial, &len) )
|
||||
return false;
|
||||
|
||||
caf::arraybuf<char> sb{const_cast<char*>(serial), // will not write
|
||||
static_cast<size_t>(len)};
|
||||
caf::stream_deserializer<caf::arraybuf<char>&> deserializer{sb};
|
||||
deserializer >> data;
|
||||
|
||||
delete [] serial;
|
||||
return true;
|
||||
}
|
||||
|
||||
broker::data bro_broker::threading_field_to_data(const threading::Field* f)
|
||||
{
|
||||
auto name = f->name;
|
||||
|
|
|
@ -120,8 +120,6 @@ public:
|
|||
return script_data_type;
|
||||
}
|
||||
|
||||
DECLARE_SERIAL(DataVal);
|
||||
|
||||
broker::data data;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "logging/Manager.h"
|
||||
#include "DebugLogger.h"
|
||||
#include "iosource/Manager.h"
|
||||
#include "SerializationFormat.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
|
@ -49,48 +49,6 @@ void StoreHandleVal::ValDescribe(ODesc* d) const
|
|||
d->Add("}");
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(StoreHandleVal, SER_COMM_STORE_HANDLE_VAL);
|
||||
|
||||
bool StoreHandleVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_COMM_STORE_HANDLE_VAL, OpaqueVal);
|
||||
|
||||
auto name = store.name();
|
||||
if ( ! SERIALIZE_STR(name.data(), name.size()) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StoreHandleVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
|
||||
const char* name_str;
|
||||
int len;
|
||||
|
||||
if ( ! UNSERIALIZE_STR(&name_str, &len) )
|
||||
return false;
|
||||
|
||||
std::string name(name_str, len);
|
||||
delete [] name_str;
|
||||
|
||||
auto handle = broker_mgr->LookupStore(name);
|
||||
if ( ! handle )
|
||||
{
|
||||
// Passing serialized version of store handles to other Bro processes
|
||||
// doesn't make sense, only allow local clones of the handle val.
|
||||
reporter->Error("failed to look up unserialized store handle %s",
|
||||
name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
store = handle->store;
|
||||
proxy = broker::store::proxy{store};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
broker::backend to_backend_type(BifEnum::Broker::BackendType type)
|
||||
{
|
||||
switch ( type ) {
|
||||
|
|
|
@ -116,8 +116,6 @@ public:
|
|||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
|
||||
DECLARE_SERIAL(StoreHandleVal);
|
||||
|
||||
broker::store store;
|
||||
broker::store::proxy proxy;
|
||||
|
||||
|
|
|
@ -110,19 +110,4 @@ void FileReassembler::Overlap(const u_char* b1, const u_char* b2, uint64 n)
|
|||
{
|
||||
// Not doing anything here yet.
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(FileReassembler, SER_FILE_REASSEMBLER);
|
||||
|
||||
bool FileReassembler::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
reporter->InternalError("FileReassembler::DoSerialize not implemented");
|
||||
return false; // Cannot be reached.
|
||||
}
|
||||
|
||||
bool FileReassembler::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
reporter->InternalError("FileReassembler::DoUnserialize not implemented");
|
||||
return false; // Cannot be reached.
|
||||
}
|
||||
|
||||
} // end file_analysis
|
||||
|
|
|
@ -50,8 +50,6 @@ public:
|
|||
protected:
|
||||
FileReassembler();
|
||||
|
||||
DECLARE_SERIAL(FileReassembler);
|
||||
|
||||
void Undelivered(uint64 up_to_seq) override;
|
||||
void BlockInserted(DataBlock* b) override;
|
||||
void Overlap(const u_char* b1, const u_char* b2, uint64 n) override;
|
||||
|
|
|
@ -28,8 +28,6 @@ X509* helper_sk_X509_value(const STACK_OF(X509)* certs, int i)
|
|||
|
||||
using namespace file_analysis;
|
||||
|
||||
IMPLEMENT_SERIAL(OCSP_RESPVal, SER_OCSP_RESP_VAL);
|
||||
|
||||
#define OCSP_STRING_BUF_SIZE 2048
|
||||
|
||||
static Val* get_ocsp_type(RecordVal* args, const char* name)
|
||||
|
@ -713,31 +711,3 @@ OCSP_RESPONSE* OCSP_RESPVal::GetResp() const
|
|||
return ocsp_resp;
|
||||
}
|
||||
|
||||
bool OCSP_RESPVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_OCSP_RESP_VAL, OpaqueVal);
|
||||
unsigned char *buf = nullptr;
|
||||
int length = i2d_OCSP_RESPONSE(ocsp_resp, &buf);
|
||||
if ( length < 0 )
|
||||
return false;
|
||||
bool res = SERIALIZE_STR(reinterpret_cast<const char*>(buf), length);
|
||||
OPENSSL_free(buf);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool OCSP_RESPVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal)
|
||||
|
||||
int length;
|
||||
unsigned char *ocsp_resp_buf, *opensslbuf;
|
||||
|
||||
if ( ! UNSERIALIZE_STR(reinterpret_cast<char **>(&ocsp_resp_buf), &length) )
|
||||
return false;
|
||||
opensslbuf = ocsp_resp_buf; // OpenSSL likes to shift pointers around. really.
|
||||
ocsp_resp = d2i_OCSP_RESPONSE(nullptr, const_cast<const unsigned char**>(&opensslbuf), length);
|
||||
delete [] ocsp_resp_buf;
|
||||
if ( ! ocsp_resp )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ protected:
|
|||
OCSP_RESPVal();
|
||||
private:
|
||||
OCSP_RESPONSE *ocsp_resp;
|
||||
DECLARE_SERIAL(OCSP_RESPVal);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
using namespace file_analysis;
|
||||
|
||||
IMPLEMENT_SERIAL(X509Val, SER_X509_VAL);
|
||||
|
||||
file_analysis::X509::X509(RecordVal* args, file_analysis::File* file)
|
||||
: file_analysis::X509Common::X509Common(file_mgr->GetComponentTag("X509"), args, file)
|
||||
{
|
||||
|
@ -482,39 +480,3 @@ X509Val::~X509Val()
|
|||
return certificate;
|
||||
}
|
||||
|
||||
bool X509Val::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_X509_VAL, OpaqueVal);
|
||||
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
int length = i2d_X509(certificate, &buf);
|
||||
|
||||
if ( length < 0 )
|
||||
return false;
|
||||
|
||||
bool res = SERIALIZE_STR(reinterpret_cast<const char*>(buf), length);
|
||||
|
||||
OPENSSL_free(buf);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool X509Val::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal)
|
||||
|
||||
int length;
|
||||
unsigned char *certbuf, *opensslbuf;
|
||||
|
||||
if ( ! UNSERIALIZE_STR(reinterpret_cast<char **>(&certbuf), &length) )
|
||||
return false;
|
||||
|
||||
opensslbuf = certbuf; // OpenSSL likes to shift pointers around. really.
|
||||
certificate = d2i_X509(NULL, const_cast<const unsigned char**>(&opensslbuf), length);
|
||||
delete[] certbuf;
|
||||
|
||||
if ( !certificate )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -144,8 +144,6 @@ protected:
|
|||
|
||||
private:
|
||||
::X509* certificate; // the wrapped certificate
|
||||
|
||||
DECLARE_SERIAL(X509Val);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#include "Packet.h"
|
||||
#include "Sessions.h"
|
||||
#include "iosource/Manager.h"
|
||||
#include "SerialInfo.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
extern "C" {
|
||||
#ifdef HAVE_NET_ETHERNET_H
|
||||
|
@ -673,66 +671,3 @@ void Packet::Describe(ODesc* d) const
|
|||
d->Add(ip.DstAddr());
|
||||
}
|
||||
|
||||
bool Packet::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SERIALIZE(uint32(ts.tv_sec)) &&
|
||||
SERIALIZE(uint32(ts.tv_usec)) &&
|
||||
SERIALIZE(uint32(len)) &&
|
||||
SERIALIZE(link_type) &&
|
||||
info->s->Write(tag.c_str(), tag.length(), "tag") &&
|
||||
info->s->Write((const char*)data, cap_len, "data");
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
static iosource::PktDumper* dump = 0;
|
||||
#endif
|
||||
|
||||
Packet* Packet::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
pkt_timeval ts;
|
||||
uint32 len, link_type;
|
||||
|
||||
if ( ! (UNSERIALIZE((uint32 *)&ts.tv_sec) &&
|
||||
UNSERIALIZE((uint32 *)&ts.tv_usec) &&
|
||||
UNSERIALIZE(&len) &&
|
||||
UNSERIALIZE(&link_type)) )
|
||||
return 0;
|
||||
|
||||
char* tag;
|
||||
if ( ! info->s->Read((char**) &tag, 0, "tag") )
|
||||
return 0;
|
||||
|
||||
const u_char* pkt;
|
||||
int caplen;
|
||||
if ( ! info->s->Read((char**) &pkt, &caplen, "data") )
|
||||
{
|
||||
delete [] tag;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Packet *p = new Packet(link_type, &ts, caplen, len, pkt, true,
|
||||
std::string(tag));
|
||||
delete [] tag;
|
||||
|
||||
// For the global timer manager, we take the global network_time as the
|
||||
// packet's timestamp for feeding it into our packet loop.
|
||||
if ( p->tag == "" )
|
||||
p->time = timer_mgr->Time();
|
||||
else
|
||||
p->time = p->ts.tv_sec + double(p->ts.tv_usec) / 1e6;
|
||||
|
||||
#ifdef DEBUG
|
||||
if ( debug_logger.IsEnabled(DBG_TM) )
|
||||
{
|
||||
if ( ! dump )
|
||||
dump = iosource_mgr->OpenPktDumper("tm.pcap", true);
|
||||
|
||||
if ( dump )
|
||||
{
|
||||
dump->Dump(p);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -24,12 +24,6 @@ enum Layer3Proto {
|
|||
|
||||
/**
|
||||
* A link-layer packet.
|
||||
*
|
||||
* Note that for serialization we don't use much of the support provided by
|
||||
* the serialization framework. Serialize/Unserialize do all the work by
|
||||
* themselves. In particular, Packets aren't derived from SerialObj. They are
|
||||
* completely seperate and self-contained entities, and we don't need any of
|
||||
* the sophisticated features like object caching.
|
||||
*/
|
||||
class Packet {
|
||||
public:
|
||||
|
@ -144,16 +138,6 @@ public:
|
|||
*/
|
||||
void Describe(ODesc* d) const;
|
||||
|
||||
/**
|
||||
* Serializes the packet, with standard signature.
|
||||
*/
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
|
||||
/**
|
||||
* Unserializes the packet, with standard signature.
|
||||
*/
|
||||
static Packet* Unserialize(UnserialInfo* info);
|
||||
|
||||
/**
|
||||
* Maximal length of a layer 2 address.
|
||||
*/
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "util.h"
|
||||
#include "threading/SerialTypes.h"
|
||||
#include "SerializationFormat.h"
|
||||
|
||||
#include "Manager.h"
|
||||
#include "WriterBackend.h"
|
||||
|
@ -70,58 +69,6 @@ public:
|
|||
|
||||
using namespace logging;
|
||||
|
||||
bool WriterBackend::WriterInfo::Read(SerializationFormat* fmt)
|
||||
{
|
||||
int size;
|
||||
|
||||
string tmp_path;
|
||||
|
||||
if ( ! (fmt->Read(&tmp_path, "path") &&
|
||||
fmt->Read(&rotation_base, "rotation_base") &&
|
||||
fmt->Read(&rotation_interval, "rotation_interval") &&
|
||||
fmt->Read(&network_time, "network_time") &&
|
||||
fmt->Read(&size, "config_size")) )
|
||||
return false;
|
||||
|
||||
path = copy_string(tmp_path.c_str());
|
||||
|
||||
config.clear();
|
||||
|
||||
while ( size-- )
|
||||
{
|
||||
string value;
|
||||
string key;
|
||||
|
||||
if ( ! (fmt->Read(&value, "config-value") && fmt->Read(&key, "config-key")) )
|
||||
return false;
|
||||
|
||||
config.insert(std::make_pair(copy_string(value.c_str()), copy_string(key.c_str())));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool WriterBackend::WriterInfo::Write(SerializationFormat* fmt) const
|
||||
{
|
||||
int size = config.size();
|
||||
|
||||
if ( ! (fmt->Write(path, "path") &&
|
||||
fmt->Write(rotation_base, "rotation_base") &&
|
||||
fmt->Write(rotation_interval, "rotation_interval") &&
|
||||
fmt->Write(network_time, "network_time") &&
|
||||
fmt->Write(size, "config_size")) )
|
||||
return false;
|
||||
|
||||
for ( config_map::const_iterator i = config.begin(); i != config.end(); ++i )
|
||||
{
|
||||
if ( ! (fmt->Write(i->first, "config-value") && fmt->Write(i->second, "config-key")) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
broker::data WriterBackend::WriterInfo::ToBroker() const
|
||||
{
|
||||
auto t = broker::table();
|
||||
|
|
|
@ -112,8 +112,6 @@ public:
|
|||
|
||||
// Note, these need to be adapted when changing the struct's
|
||||
// fields. They serialize/deserialize the struct.
|
||||
bool Read(SerializationFormat* fmt);
|
||||
bool Write(SerializationFormat* fmt) const;
|
||||
broker::data ToBroker() const;
|
||||
bool FromBroker(broker::data d);
|
||||
|
||||
|
|
38
src/main.cc
38
src/main.cc
|
@ -38,7 +38,6 @@ extern "C" {
|
|||
#include "DFA.h"
|
||||
#include "RuleMatcher.h"
|
||||
#include "Anon.h"
|
||||
#include "Serializer.h"
|
||||
#include "EventRegistry.h"
|
||||
#include "Stats.h"
|
||||
#include "Brofiler.h"
|
||||
|
@ -99,9 +98,9 @@ name_list prefixes;
|
|||
Stmt* stmts;
|
||||
EventHandlerPtr net_done = 0;
|
||||
RuleMatcher* rule_matcher = 0;
|
||||
FileSerializer* event_serializer = 0;
|
||||
FileSerializer* state_serializer = 0;
|
||||
EventPlayer* event_player = 0;
|
||||
// Fixme: Johanna
|
||||
// FileSerializer* event_serializer = 0;
|
||||
// EventPlayer* event_player = 0;
|
||||
EventRegistry* event_registry = 0;
|
||||
ProfileLogger* profiling_logger = 0;
|
||||
ProfileLogger* segment_logger = 0;
|
||||
|
@ -171,7 +170,6 @@ void usage(int code = 1)
|
|||
fprintf(stderr, " -t|--tracefile <tracefile> | activate execution tracing\n");
|
||||
fprintf(stderr, " -v|--version | print version and exit\n");
|
||||
fprintf(stderr, " -w|--writefile <writefile> | write to given tcpdump file\n");
|
||||
fprintf(stderr, " -x|--print-state <file.bst> | print contents of state file\n");
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, " -B|--debug <dbgstreams> | Enable debugging output for selected streams ('-B help' for help)\n");
|
||||
#endif
|
||||
|
@ -353,8 +351,8 @@ void terminate_bro()
|
|||
|
||||
delete zeekygen_mgr;
|
||||
delete timer_mgr;
|
||||
delete event_serializer;
|
||||
delete state_serializer;
|
||||
// Fixme: johanna
|
||||
// delete event_serializer;
|
||||
delete event_registry;
|
||||
delete analyzer_mgr;
|
||||
delete file_mgr;
|
||||
|
@ -424,7 +422,6 @@ int main(int argc, char** argv)
|
|||
name_list interfaces;
|
||||
name_list read_files;
|
||||
name_list rule_files;
|
||||
char* bst_file = 0;
|
||||
char* id_name = 0;
|
||||
char* events_file = 0;
|
||||
char* seed_load_file = getenv("BRO_SEED_FILE");
|
||||
|
@ -455,7 +452,6 @@ int main(int argc, char** argv)
|
|||
{"tracefile", required_argument, 0, 't'},
|
||||
{"writefile", required_argument, 0, 'w'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{"print-state", required_argument, 0, 'x'},
|
||||
{"no-checksums", no_argument, 0, 'C'},
|
||||
{"force-dns", no_argument, 0, 'F'},
|
||||
{"load-seeds", required_argument, 0, 'G'},
|
||||
|
@ -578,10 +574,6 @@ int main(int argc, char** argv)
|
|||
writefile = optarg;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
bst_file = optarg;
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
debug_streams = optarg;
|
||||
break;
|
||||
|
@ -744,7 +736,7 @@ int main(int argc, char** argv)
|
|||
if ( optind == argc &&
|
||||
read_files.length() == 0 &&
|
||||
interfaces.length() == 0 &&
|
||||
! (id_name || bst_file) && ! command_line_policy && ! print_plugins )
|
||||
! id_name && ! command_line_policy && ! print_plugins )
|
||||
add_input_file("-");
|
||||
|
||||
// Process remaining arguments. X=Y arguments indicate script
|
||||
|
@ -796,8 +788,9 @@ int main(int argc, char** argv)
|
|||
|
||||
plugin_mgr->ActivateDynamicPlugins(! bare_mode);
|
||||
|
||||
if ( events_file )
|
||||
event_player = new EventPlayer(events_file);
|
||||
// Fixme: Johanna
|
||||
// if ( events_file )
|
||||
// event_player = new EventPlayer(events_file);
|
||||
|
||||
init_event_handlers();
|
||||
|
||||
|
@ -972,19 +965,6 @@ int main(int argc, char** argv)
|
|||
exit(0);
|
||||
}
|
||||
|
||||
// Just read state file from disk.
|
||||
if ( bst_file )
|
||||
{
|
||||
FileSerializer s;
|
||||
UnserialInfo info(&s);
|
||||
info.print = stdout;
|
||||
info.install_uniques = true;
|
||||
if ( ! s.Read(&info, bst_file) )
|
||||
reporter->Error("Failed to read events from %s\n", bst_file);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Print the ID.
|
||||
if ( id_name )
|
||||
{
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include <limits>
|
||||
|
||||
#include "BitVector.h"
|
||||
#include "Serializer.h"
|
||||
#include "digest.h"
|
||||
|
||||
using namespace probabilistic;
|
||||
|
@ -539,56 +538,3 @@ BitVector::size_type BitVector::find_from(size_type i) const
|
|||
return i * bits_per_block + lowest_bit(bits[i]);
|
||||
}
|
||||
|
||||
bool BitVector::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
BitVector* BitVector::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return reinterpret_cast<BitVector*>(SerialObj::Unserialize(info, SER_BITVECTOR));
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BitVector, SER_BITVECTOR);
|
||||
|
||||
bool BitVector::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BITVECTOR, SerialObj);
|
||||
|
||||
if ( ! SERIALIZE(static_cast<uint64>(bits.size())) )
|
||||
return false;
|
||||
|
||||
for ( size_t i = 0; i < bits.size(); ++i )
|
||||
if ( ! SERIALIZE(static_cast<uint64>(bits[i])) )
|
||||
return false;
|
||||
|
||||
return SERIALIZE(static_cast<uint64>(num_bits));
|
||||
}
|
||||
|
||||
bool BitVector::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
uint64 size;
|
||||
if ( ! UNSERIALIZE(&size) )
|
||||
return false;
|
||||
|
||||
bits.resize(static_cast<size_t>(size));
|
||||
|
||||
for ( size_t i = 0; i < bits.size(); ++i )
|
||||
{
|
||||
uint64 block;
|
||||
if ( ! UNSERIALIZE(&block) )
|
||||
return false;
|
||||
|
||||
bits[i] = static_cast<block_type>(block);
|
||||
}
|
||||
|
||||
uint64 n;
|
||||
if ( ! UNSERIALIZE(&n) )
|
||||
return false;
|
||||
|
||||
num_bits = static_cast<size_type>(n);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -6,16 +6,14 @@
|
|||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
#include "SerialObj.h"
|
||||
|
||||
namespace probabilistic {
|
||||
|
||||
/**
|
||||
* A vector of bits.
|
||||
*/
|
||||
class BitVector : public SerialObj {
|
||||
class BitVector {
|
||||
public:
|
||||
typedef uint64 block_type;
|
||||
typedef uint64_t block_type;
|
||||
typedef size_t size_type;
|
||||
typedef bool const_reference;
|
||||
|
||||
|
@ -281,28 +279,7 @@ public:
|
|||
*
|
||||
* @return The hash.
|
||||
*/
|
||||
uint64 Hash() const;
|
||||
|
||||
/**
|
||||
* Serializes the bit vector.
|
||||
*
|
||||
* @param info The serializaton informationt to use.
|
||||
*
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
|
||||
/**
|
||||
* Unserialize the bit vector.
|
||||
*
|
||||
* @param info The serializaton informationt to use.
|
||||
*
|
||||
* @return The unserialized bit vector, or null if an error occured.
|
||||
*/
|
||||
static BitVector* Unserialize(UnserialInfo* info);
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(BitVector);
|
||||
uint64_t Hash() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
#include "BloomFilter.h"
|
||||
|
||||
#include "CounterVector.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
#include "../util.h"
|
||||
#include "../Reporter.h"
|
||||
|
||||
using namespace probabilistic;
|
||||
|
||||
|
@ -28,31 +28,6 @@ BloomFilter::~BloomFilter()
|
|||
delete hasher;
|
||||
}
|
||||
|
||||
bool BloomFilter::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
BloomFilter* BloomFilter::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return reinterpret_cast<BloomFilter*>(SerialObj::Unserialize(info, SER_BLOOMFILTER));
|
||||
}
|
||||
|
||||
bool BloomFilter::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BLOOMFILTER, SerialObj);
|
||||
|
||||
return hasher->Serialize(info);
|
||||
}
|
||||
|
||||
bool BloomFilter::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
hasher = Hasher::Unserialize(info);
|
||||
return hasher != 0;
|
||||
}
|
||||
|
||||
size_t BasicBloomFilter::M(double fp, size_t capacity)
|
||||
{
|
||||
double ln2 = std::log(2);
|
||||
|
@ -130,21 +105,6 @@ BasicBloomFilter::~BasicBloomFilter()
|
|||
delete bits;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BasicBloomFilter, SER_BASICBLOOMFILTER)
|
||||
|
||||
bool BasicBloomFilter::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BASICBLOOMFILTER, BloomFilter);
|
||||
return bits->Serialize(info);
|
||||
}
|
||||
|
||||
bool BasicBloomFilter::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BloomFilter);
|
||||
bits = BitVector::Unserialize(info);
|
||||
return (bits != 0);
|
||||
}
|
||||
|
||||
void BasicBloomFilter::Add(const HashKey* key)
|
||||
{
|
||||
Hasher::digest_vector h = hasher->Hash(key);
|
||||
|
@ -232,21 +192,6 @@ string CountingBloomFilter::InternalState() const
|
|||
return fmt("%" PRIu64, cells->Hash());
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(CountingBloomFilter, SER_COUNTINGBLOOMFILTER)
|
||||
|
||||
bool CountingBloomFilter::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_COUNTINGBLOOMFILTER, BloomFilter);
|
||||
return cells->Serialize(info);
|
||||
}
|
||||
|
||||
bool CountingBloomFilter::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BloomFilter);
|
||||
cells = CounterVector::Unserialize(info);
|
||||
return (cells != 0);
|
||||
}
|
||||
|
||||
// TODO: Use partitioning in add/count to allow for reusing CMS bounds.
|
||||
void CountingBloomFilter::Add(const HashKey* key)
|
||||
{
|
||||
|
|
|
@ -14,12 +14,12 @@ class CounterVector;
|
|||
/**
|
||||
* The abstract base class for Bloom filters.
|
||||
*/
|
||||
class BloomFilter : public SerialObj {
|
||||
class BloomFilter {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~BloomFilter() override;
|
||||
virtual ~BloomFilter();
|
||||
|
||||
/**
|
||||
* Adds an element to the Bloom filter.
|
||||
|
@ -71,28 +71,7 @@ public:
|
|||
*/
|
||||
virtual string InternalState() const = 0;
|
||||
|
||||
/**
|
||||
* Serializes the Bloom filter.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
|
||||
/**
|
||||
* Unserializes a Bloom filter.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return The unserialized Bloom filter, or null if an error
|
||||
* occured.
|
||||
*/
|
||||
static BloomFilter* Unserialize(UnserialInfo* info);
|
||||
|
||||
protected:
|
||||
DECLARE_ABSTRACT_SERIAL(BloomFilter);
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
|
@ -165,8 +144,6 @@ public:
|
|||
string InternalState() const override;
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(BasicBloomFilter);
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
|
@ -210,8 +187,6 @@ public:
|
|||
string InternalState() const override;
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(CountingBloomFilter);
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "CardinalityCounter.h"
|
||||
#include "Reporter.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
using namespace probabilistic;
|
||||
|
||||
|
@ -197,51 +196,6 @@ uint64_t CardinalityCounter::GetM() const
|
|||
return m;
|
||||
}
|
||||
|
||||
bool CardinalityCounter::Serialize(SerialInfo* info) const
|
||||
{
|
||||
bool valid = true;
|
||||
|
||||
valid &= SERIALIZE(m);
|
||||
valid &= SERIALIZE(V);
|
||||
valid &= SERIALIZE(alpha_m);
|
||||
|
||||
for ( unsigned int i = 0; i < m; i++ )
|
||||
valid &= SERIALIZE((char)buckets[i]);
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
CardinalityCounter* CardinalityCounter::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
uint64_t m;
|
||||
uint64_t V;
|
||||
double alpha_m;
|
||||
|
||||
bool valid = true;
|
||||
valid &= UNSERIALIZE(&m);
|
||||
valid &= UNSERIALIZE(&V);
|
||||
valid &= UNSERIALIZE(&alpha_m);
|
||||
|
||||
CardinalityCounter* c = new CardinalityCounter(m, V, alpha_m);
|
||||
|
||||
vector<uint8_t>& buckets = c->buckets;
|
||||
|
||||
for ( unsigned int i = 0; i < m; i++ )
|
||||
{
|
||||
char c;
|
||||
valid &= UNSERIALIZE(&c);
|
||||
buckets[i] = (uint8_t)c;
|
||||
}
|
||||
|
||||
if ( ! valid )
|
||||
{
|
||||
delete c;
|
||||
c = 0;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* The following function is copied from libc/string/flsll.c from the FreeBSD source
|
||||
* tree. Original copyright message follows
|
||||
|
|
|
@ -84,25 +84,6 @@ public:
|
|||
*/
|
||||
bool Merge(CardinalityCounter* c);
|
||||
|
||||
/**
|
||||
* Serializes the cardinality counter.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
|
||||
/**
|
||||
* Unserializes a cardinality counter.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return The unserialized cardinality counter, or null if an error
|
||||
* occured.
|
||||
*/
|
||||
static CardinalityCounter* Unserialize(UnserialInfo* info);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Return the number of buckets.
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <limits>
|
||||
#include "BitVector.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
using namespace probabilistic;
|
||||
|
||||
|
@ -153,46 +152,8 @@ CounterVector operator|(const CounterVector& x, const CounterVector& y)
|
|||
|
||||
}
|
||||
|
||||
uint64 CounterVector::Hash() const
|
||||
uint64_t CounterVector::Hash() const
|
||||
{
|
||||
return bits->Hash();
|
||||
}
|
||||
|
||||
bool CounterVector::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
CounterVector* CounterVector::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return reinterpret_cast<CounterVector*>(SerialObj::Unserialize(info, SER_COUNTERVECTOR));
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(CounterVector, SER_COUNTERVECTOR)
|
||||
|
||||
bool CounterVector::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_COUNTERVECTOR, SerialObj);
|
||||
|
||||
if ( ! bits->Serialize(info) )
|
||||
return false;
|
||||
|
||||
return SERIALIZE(static_cast<uint64>(width));
|
||||
}
|
||||
|
||||
bool CounterVector::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
bits = BitVector::Unserialize(info);
|
||||
if ( ! bits )
|
||||
return false;
|
||||
|
||||
uint64 w;
|
||||
if ( ! UNSERIALIZE(&w) )
|
||||
return false;
|
||||
|
||||
width = static_cast<size_t>(w);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
#ifndef PROBABILISTIC_COUNTERVECTOR_H
|
||||
#define PROBABILISTIC_COUNTERVECTOR_H
|
||||
|
||||
#include "SerialObj.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace probabilistic {
|
||||
|
||||
|
@ -12,10 +13,10 @@ class BitVector;
|
|||
/**
|
||||
* A vector of counters, each of which has a fixed number of bits.
|
||||
*/
|
||||
class CounterVector : public SerialObj {
|
||||
class CounterVector {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef uint64 count_type;
|
||||
typedef uint64_t count_type;
|
||||
|
||||
/**
|
||||
* Constructs a counter vector having cells of a given width.
|
||||
|
@ -38,7 +39,7 @@ public:
|
|||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~CounterVector() override;
|
||||
virtual ~CounterVector();
|
||||
|
||||
/**
|
||||
* Increments a given cell.
|
||||
|
@ -131,26 +132,7 @@ public:
|
|||
*
|
||||
* @return The hash.
|
||||
*/
|
||||
uint64 Hash() const;
|
||||
|
||||
/**
|
||||
* Serializes the bit vector.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
|
||||
/**
|
||||
* Unserialize the counter vector.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return The unserialized counter vector, or null if an error
|
||||
* occured.
|
||||
*/
|
||||
static CounterVector* Unserialize(UnserialInfo* info);
|
||||
uint64_t Hash() const;
|
||||
|
||||
protected:
|
||||
friend CounterVector operator|(const CounterVector& x,
|
||||
|
@ -158,8 +140,6 @@ protected:
|
|||
|
||||
CounterVector() { }
|
||||
|
||||
DECLARE_SERIAL(CounterVector);
|
||||
|
||||
private:
|
||||
CounterVector& operator=(const CounterVector&); // Disable.
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "Hasher.h"
|
||||
#include "NetVar.h"
|
||||
#include "Serializer.h"
|
||||
#include "digest.h"
|
||||
#include "siphash24.h"
|
||||
|
||||
|
@ -41,52 +40,6 @@ Hasher::digest_vector Hasher::Hash(const HashKey* key) const
|
|||
return Hash(key->Key(), key->Size());
|
||||
}
|
||||
|
||||
bool Hasher::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Hasher* Hasher::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return reinterpret_cast<Hasher*>(SerialObj::Unserialize(info, SER_HASHER));
|
||||
}
|
||||
|
||||
bool Hasher::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_HASHER, SerialObj);
|
||||
|
||||
if ( ! SERIALIZE(static_cast<uint16>(k)) )
|
||||
return false;
|
||||
|
||||
if ( ! SERIALIZE(static_cast<uint64>(seed.h1)) )
|
||||
return false;
|
||||
|
||||
return SERIALIZE(static_cast<uint64>(seed.h2));
|
||||
}
|
||||
|
||||
bool Hasher::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
uint16 serial_k;
|
||||
if ( ! UNSERIALIZE(&serial_k) )
|
||||
return false;
|
||||
|
||||
k = serial_k;
|
||||
assert(k > 0);
|
||||
|
||||
seed_t serial_seed;
|
||||
if ( ! UNSERIALIZE(&serial_seed.h1) )
|
||||
return false;
|
||||
|
||||
if ( ! UNSERIALIZE(&serial_seed.h2) )
|
||||
return false;
|
||||
|
||||
seed = serial_seed;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Hasher::Hasher(size_t arg_k, seed_t arg_seed)
|
||||
{
|
||||
k = arg_k;
|
||||
|
@ -167,31 +120,6 @@ bool DefaultHasher::Equals(const Hasher* other) const
|
|||
return hash_functions == o->hash_functions;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(DefaultHasher, SER_DEFAULTHASHER)
|
||||
|
||||
bool DefaultHasher::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_DEFAULTHASHER, Hasher);
|
||||
|
||||
// Nothing to do here, the base class has all we need serialized already.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DefaultHasher::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Hasher);
|
||||
|
||||
hash_functions.clear();
|
||||
for ( size_t i = 0; i < K(); ++i )
|
||||
{
|
||||
Hasher::seed_t s = Seed();
|
||||
s.h1 += bro_prng(i);
|
||||
hash_functions.push_back(UHF(s));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DoubleHasher::DoubleHasher(size_t k, seed_t seed)
|
||||
: Hasher(k, seed), h1(seed + bro_prng(1)), h2(seed + bro_prng(2))
|
||||
{
|
||||
|
@ -223,22 +151,3 @@ bool DoubleHasher::Equals(const Hasher* other) const
|
|||
return h1 == o->h1 && h2 == o->h2;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(DoubleHasher, SER_DOUBLEHASHER)
|
||||
|
||||
bool DoubleHasher::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_DOUBLEHASHER, Hasher);
|
||||
|
||||
// Nothing to do here, the base class has all we need serialized already.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DoubleHasher::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Hasher);
|
||||
|
||||
h1 = UHF(Seed() + bro_prng(1));
|
||||
h2 = UHF(Seed() + bro_prng(2));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#define PROBABILISTIC_HASHER_H
|
||||
|
||||
#include "Hash.h"
|
||||
#include "SerialObj.h"
|
||||
|
||||
namespace probabilistic {
|
||||
|
||||
|
@ -12,7 +11,7 @@ namespace probabilistic {
|
|||
* Abstract base class for hashers. A hasher creates a family of hash
|
||||
* functions to hash an element *k* times.
|
||||
*/
|
||||
class Hasher : public SerialObj {
|
||||
class Hasher {
|
||||
public:
|
||||
typedef hash_t digest;
|
||||
typedef std::vector<digest> digest_vector;
|
||||
|
@ -43,7 +42,7 @@ public:
|
|||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Hasher() override { }
|
||||
virtual ~Hasher() { }
|
||||
|
||||
/**
|
||||
* Computes hash values for an element.
|
||||
|
@ -99,12 +98,7 @@ public:
|
|||
*/
|
||||
seed_t Seed() const { return seed; }
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Hasher* Unserialize(UnserialInfo* info);
|
||||
|
||||
protected:
|
||||
DECLARE_ABSTRACT_SERIAL(Hasher);
|
||||
|
||||
Hasher() { }
|
||||
|
||||
/**
|
||||
|
@ -208,8 +202,6 @@ public:
|
|||
DefaultHasher* Clone() const final;
|
||||
bool Equals(const Hasher* other) const final;
|
||||
|
||||
DECLARE_SERIAL(DefaultHasher);
|
||||
|
||||
private:
|
||||
DefaultHasher() { }
|
||||
|
||||
|
@ -236,8 +228,6 @@ public:
|
|||
DoubleHasher* Clone() const final;
|
||||
bool Equals(const Hasher* other) const final;
|
||||
|
||||
DECLARE_SERIAL(DoubleHasher);
|
||||
|
||||
private:
|
||||
DoubleHasher() { }
|
||||
|
||||
|
|
|
@ -3,13 +3,10 @@
|
|||
#include "probabilistic/Topk.h"
|
||||
#include "CompHash.h"
|
||||
#include "Reporter.h"
|
||||
#include "Serializer.h"
|
||||
#include "NetVar.h"
|
||||
|
||||
namespace probabilistic {
|
||||
|
||||
IMPLEMENT_SERIAL(TopkVal, SER_TOPK_VAL);
|
||||
|
||||
static void topk_element_hash_delete_func(void* val)
|
||||
{
|
||||
Element* e = (Element*) val;
|
||||
|
@ -183,109 +180,6 @@ void TopkVal::Merge(const TopkVal* value, bool doPrune)
|
|||
}
|
||||
}
|
||||
|
||||
bool TopkVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_TOPK_VAL, OpaqueVal);
|
||||
|
||||
bool v = true;
|
||||
|
||||
v &= SERIALIZE(size);
|
||||
v &= SERIALIZE(numElements);
|
||||
v &= SERIALIZE(pruned);
|
||||
|
||||
bool type_present = (type != 0);
|
||||
v &= SERIALIZE(type_present);
|
||||
|
||||
if ( type_present )
|
||||
v &= type->Serialize(info);
|
||||
else
|
||||
assert(numElements == 0);
|
||||
|
||||
uint64_t i = 0;
|
||||
std::list<Bucket*>::const_iterator it = buckets.begin();
|
||||
while ( it != buckets.end() )
|
||||
{
|
||||
Bucket* b = *it;
|
||||
uint32_t elements_count = b->elements.size();
|
||||
v &= SERIALIZE(elements_count);
|
||||
v &= SERIALIZE(b->count);
|
||||
|
||||
std::list<Element*>::const_iterator eit = b->elements.begin();
|
||||
while ( eit != b->elements.end() )
|
||||
{
|
||||
Element* element = *eit;
|
||||
v &= SERIALIZE(element->epsilon);
|
||||
v &= element->value->Serialize(info);
|
||||
|
||||
eit++;
|
||||
i++;
|
||||
}
|
||||
|
||||
it++;
|
||||
}
|
||||
|
||||
assert(i == numElements);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
bool TopkVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
|
||||
bool v = true;
|
||||
|
||||
v &= UNSERIALIZE(&size);
|
||||
v &= UNSERIALIZE(&numElements);
|
||||
v &= UNSERIALIZE(&pruned);
|
||||
|
||||
bool type_present = false;
|
||||
v &= UNSERIALIZE(&type_present);
|
||||
if ( type_present )
|
||||
{
|
||||
BroType* deserialized_type = BroType::Unserialize(info);
|
||||
|
||||
Typify(deserialized_type);
|
||||
Unref(deserialized_type);
|
||||
assert(type);
|
||||
}
|
||||
else
|
||||
assert(numElements == 0);
|
||||
|
||||
uint64_t i = 0;
|
||||
while ( i < numElements )
|
||||
{
|
||||
Bucket* b = new Bucket();
|
||||
uint32_t elements_count;
|
||||
v &= UNSERIALIZE(&elements_count);
|
||||
v &= UNSERIALIZE(&b->count);
|
||||
b->bucketPos = buckets.insert(buckets.end(), b);
|
||||
|
||||
for ( uint64_t j = 0; j < elements_count; j++ )
|
||||
{
|
||||
Element* e = new Element();
|
||||
v &= UNSERIALIZE(&e->epsilon);
|
||||
e->value = Val::Unserialize(info, type);
|
||||
e->parent = b;
|
||||
|
||||
b->elements.insert(b->elements.end(), e);
|
||||
|
||||
HashKey* key = GetHash(e->value);
|
||||
assert (elementDict->Lookup(key) == 0);
|
||||
|
||||
elementDict->Insert(key, e);
|
||||
delete key;
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(i == numElements);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
VectorVal* TopkVal::GetTopK(int k) const // returns vector
|
||||
{
|
||||
if ( numElements == 0 )
|
||||
|
|
|
@ -161,8 +161,6 @@ private:
|
|||
uint64 size; // how many elements are we tracking?
|
||||
uint64 numElements; // how many elements do we have at the moment
|
||||
bool pruned; // was this data structure pruned?
|
||||
|
||||
DECLARE_SERIAL(TopkVal);
|
||||
};
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue