mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Base: Clean up explicit uses of namespaces in places where they're not necessary.
This commit covers all of the common and base classes.
This commit is contained in:
parent
9f802b2a4d
commit
fe0c22c789
240 changed files with 6823 additions and 6787 deletions
|
@ -45,7 +45,7 @@ void SerializationFormat::StartWrite()
|
|||
|
||||
if ( ! output )
|
||||
{
|
||||
output = (char*)zeek::util::safe_malloc(INITIAL_SIZE);
|
||||
output = (char*)util::safe_malloc(INITIAL_SIZE);
|
||||
output_size = INITIAL_SIZE;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ bool SerializationFormat::ReadData(void* b, size_t count)
|
|||
{
|
||||
if ( input_pos + count > input_len )
|
||||
{
|
||||
zeek::reporter->Error("data underflow during read in binary format");
|
||||
reporter->Error("data underflow during read in binary format");
|
||||
abort();
|
||||
return false;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ bool SerializationFormat::WriteData(const void* b, size_t count)
|
|||
while ( output_pos + count > output_size )
|
||||
output_size *= GROWTH_FACTOR;
|
||||
|
||||
output = (char*)zeek::util::safe_realloc(output, output_size);
|
||||
output = (char*)util::safe_realloc(output, output_size);
|
||||
|
||||
memcpy(output + output_pos, b, count);
|
||||
output_pos += count;
|
||||
|
@ -109,7 +109,7 @@ bool BinarySerializationFormat::Read(int* v, const char* tag)
|
|||
return false;
|
||||
|
||||
*v = (int) ntohl(tmp);
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Read int %d [%s]", *v, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Read int %d [%s]", *v, tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ bool BinarySerializationFormat::Read(uint16_t* v, const char* tag)
|
|||
return false;
|
||||
|
||||
*v = ntohs(*v);
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Read uint16_t %hu [%s]", *v, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Read uint16_t %hu [%s]", *v, tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ bool BinarySerializationFormat::Read(uint32_t* v, const char* tag)
|
|||
return false;
|
||||
|
||||
*v = ntohl(*v);
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Read uint32_t %" PRIu32 " [%s]", *v, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Read uint32_t %" PRIu32 " [%s]", *v, tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ bool BinarySerializationFormat::Read(int64_t* v, const char* tag)
|
|||
return false;
|
||||
|
||||
*v = ((int64_t(ntohl(x[0]))) << 32) | ntohl(x[1]);
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Read int64_t %" PRId64 " [%s]", *v, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Read int64_t %" PRId64 " [%s]", *v, tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ bool BinarySerializationFormat::Read(uint64_t* v, const char* tag)
|
|||
return false;
|
||||
|
||||
*v = ((uint64_t(ntohl(x[0]))) << 32) | ntohl(x[1]);
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Read uint64_t %" PRIu64 " [%s]", *v, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Read uint64_t %" PRIu64 " [%s]", *v, tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ bool BinarySerializationFormat::Read(bool* v, const char* tag)
|
|||
return false;
|
||||
|
||||
*v = c == '\1' ? true : false;
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Read bool %s [%s]", *v ? "true" : "false", tag);
|
||||
DBG_LOG(DBG_SERIAL, "Read bool %s [%s]", *v ? "true" : "false", tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -173,14 +173,14 @@ bool BinarySerializationFormat::Read(double* d, const char* tag)
|
|||
return false;
|
||||
|
||||
*d = ntohd(*d);
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Read double %.6f [%s]", *d, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Read double %.6f [%s]", *d, tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinarySerializationFormat::Read(char* v, const char* tag)
|
||||
{
|
||||
bool ret = ReadData(v, 1);
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Read char %s [%s]", zeek::util::fmt_bytes(v, 1), tag);
|
||||
DBG_LOG(DBG_SERIAL, "Read char %s [%s]", util::fmt_bytes(v, 1), tag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ bool BinarySerializationFormat::Read(char** str, int* len, const char* tag)
|
|||
for ( int i = 0; i < l; i++ )
|
||||
if ( ! s[i] )
|
||||
{
|
||||
zeek::reporter->Error("binary Format: string contains null; replaced by '_'");
|
||||
reporter->Error("binary Format: string contains null; replaced by '_'");
|
||||
s[i] = '_';
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ bool BinarySerializationFormat::Read(char** str, int* len, const char* tag)
|
|||
|
||||
*str = s;
|
||||
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Read %d bytes |%s| [%s]", l, zeek::util::fmt_bytes(*str, l), tag);
|
||||
DBG_LOG(DBG_SERIAL, "Read %d bytes |%s| [%s]", l, util::fmt_bytes(*str, l), tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ bool BinarySerializationFormat::Read(std::string* v, const char* tag)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool BinarySerializationFormat::Read(zeek::IPAddr* addr, const char* tag)
|
||||
bool BinarySerializationFormat::Read(IPAddr* addr, const char* tag)
|
||||
{
|
||||
int n = 0;
|
||||
if ( ! Read(&n, "addr-len") )
|
||||
|
@ -256,22 +256,22 @@ bool BinarySerializationFormat::Read(zeek::IPAddr* addr, const char* tag)
|
|||
}
|
||||
|
||||
if ( n == 1 )
|
||||
*addr = zeek::IPAddr(IPv4, raw, zeek::IPAddr::Network);
|
||||
*addr = IPAddr(IPv4, raw, IPAddr::Network);
|
||||
else
|
||||
*addr = zeek::IPAddr(IPv6, raw, zeek::IPAddr::Network);
|
||||
*addr = IPAddr(IPv6, raw, IPAddr::Network);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinarySerializationFormat::Read(zeek::IPPrefix* prefix, const char* tag)
|
||||
bool BinarySerializationFormat::Read(IPPrefix* prefix, const char* tag)
|
||||
{
|
||||
zeek::IPAddr addr;
|
||||
IPAddr addr;
|
||||
int len;
|
||||
|
||||
if ( ! (Read(&addr, "prefix") && Read(&len, "width")) )
|
||||
return false;
|
||||
|
||||
*prefix = zeek::IPPrefix(addr, len);
|
||||
*prefix = IPPrefix(addr, len);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -303,34 +303,34 @@ bool BinarySerializationFormat::Read(struct in6_addr* addr, const char* tag)
|
|||
|
||||
bool BinarySerializationFormat::Write(char v, const char* tag)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Write char %s [%s]", zeek::util::fmt_bytes(&v, 1), tag);
|
||||
DBG_LOG(DBG_SERIAL, "Write char %s [%s]", util::fmt_bytes(&v, 1), tag);
|
||||
return WriteData(&v, 1);
|
||||
}
|
||||
|
||||
bool BinarySerializationFormat::Write(uint16_t v, const char* tag)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Write uint16_t %hu [%s]", v, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Write uint16_t %hu [%s]", v, tag);
|
||||
v = htons(v);
|
||||
return WriteData(&v, sizeof(v));
|
||||
}
|
||||
|
||||
bool BinarySerializationFormat::Write(uint32_t v, const char* tag)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Write uint32_t %" PRIu32 " [%s]", v, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Write uint32_t %" PRIu32 " [%s]", v, tag);
|
||||
v = htonl(v);
|
||||
return WriteData(&v, sizeof(v));
|
||||
}
|
||||
|
||||
bool BinarySerializationFormat::Write(int v, const char* tag)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Write int %d [%s]", v, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Write int %d [%s]", v, tag);
|
||||
uint32_t tmp = htonl((uint32_t) v);
|
||||
return WriteData(&tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
bool BinarySerializationFormat::Write(uint64_t v, const char* tag)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Write uint64_t %" PRIu64 " [%s]", v, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Write uint64_t %" PRIu64 " [%s]", v, tag);
|
||||
uint32_t x[2];
|
||||
x[0] = htonl(v >> 32);
|
||||
x[1] = htonl(v & 0xffffffff);
|
||||
|
@ -339,7 +339,7 @@ bool BinarySerializationFormat::Write(uint64_t v, const char* tag)
|
|||
|
||||
bool BinarySerializationFormat::Write(int64_t v, const char* tag)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Write int64_t %" PRId64 " [%s]", v, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Write int64_t %" PRId64 " [%s]", v, tag);
|
||||
uint32_t x[2];
|
||||
x[0] = htonl(v >> 32);
|
||||
x[1] = htonl(v & 0xffffffff);
|
||||
|
@ -348,14 +348,14 @@ bool BinarySerializationFormat::Write(int64_t v, const char* tag)
|
|||
|
||||
bool BinarySerializationFormat::Write(double d, const char* tag)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Write double %.6f [%s]", d, tag);
|
||||
DBG_LOG(DBG_SERIAL, "Write double %.6f [%s]", d, tag);
|
||||
d = htond(d);
|
||||
return WriteData(&d, sizeof(d));
|
||||
}
|
||||
|
||||
bool BinarySerializationFormat::Write(bool v, const char* tag)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Write bool %s [%s]", v ? "true" : "false", tag);
|
||||
DBG_LOG(DBG_SERIAL, "Write bool %s [%s]", v ? "true" : "false", tag);
|
||||
char c = v ? '\1' : '\0';
|
||||
return WriteData(&c, 1);
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ bool BinarySerializationFormat::Write(const std::string& s, const char* tag)
|
|||
return Write(s.data(), s.size(), tag);
|
||||
}
|
||||
|
||||
bool BinarySerializationFormat::Write(const zeek::IPAddr& addr, const char* tag)
|
||||
bool BinarySerializationFormat::Write(const IPAddr& addr, const char* tag)
|
||||
{
|
||||
const uint32_t* raw;
|
||||
int n = addr.GetBytes(&raw);
|
||||
|
@ -389,7 +389,7 @@ bool BinarySerializationFormat::Write(const zeek::IPAddr& addr, const char* tag)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool BinarySerializationFormat::Write(const zeek::IPPrefix& prefix, const char* tag)
|
||||
bool BinarySerializationFormat::Write(const IPPrefix& prefix, const char* tag)
|
||||
{
|
||||
return Write(prefix.Prefix(), "prefix") && Write(prefix.Length(), "width");
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ bool BinarySerializationFormat::WriteSeparator()
|
|||
|
||||
bool BinarySerializationFormat::Write(const char* buf, int len, const char* tag)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_SERIAL, "Write bytes |%s| [%s]", zeek::util::fmt_bytes(buf, len), tag);
|
||||
DBG_LOG(DBG_SERIAL, "Write bytes |%s| [%s]", util::fmt_bytes(buf, len), tag);
|
||||
uint32_t l = htonl(len);
|
||||
return WriteData(&l, sizeof(l)) && WriteData(buf, len);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue