mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00
clang-format: Set IndentCaseBlocks to false
This commit is contained in:
parent
02206f3215
commit
4423574d26
58 changed files with 4729 additions and 4766 deletions
|
@ -841,28 +841,28 @@ bool Manager::IsCompatibleType(Type* t, bool atomic_only)
|
|||
return ! atomic_only;
|
||||
|
||||
case TYPE_TABLE:
|
||||
{
|
||||
if ( atomic_only )
|
||||
return false;
|
||||
{
|
||||
if ( atomic_only )
|
||||
return false;
|
||||
|
||||
if ( ! t->IsSet() )
|
||||
return false;
|
||||
if ( ! t->IsSet() )
|
||||
return false;
|
||||
|
||||
const auto& indices = t->AsSetType()->GetIndices();
|
||||
const auto& indices = t->AsSetType()->GetIndices();
|
||||
|
||||
if ( indices->GetTypes().size() != 1 )
|
||||
return false;
|
||||
if ( indices->GetTypes().size() != 1 )
|
||||
return false;
|
||||
|
||||
return IsCompatibleType(indices->GetPureType().get(), true);
|
||||
}
|
||||
return IsCompatibleType(indices->GetPureType().get(), true);
|
||||
}
|
||||
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
if ( atomic_only )
|
||||
return false;
|
||||
{
|
||||
if ( atomic_only )
|
||||
return false;
|
||||
|
||||
return IsCompatibleType(t->AsVectorType()->Yield().get(), true);
|
||||
}
|
||||
return IsCompatibleType(t->AsVectorType()->Yield().get(), true);
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
@ -1999,65 +1999,65 @@ int Manager::GetValueLength(const Value* val) const
|
|||
|
||||
case TYPE_STRING:
|
||||
case TYPE_ENUM:
|
||||
{
|
||||
length += val->val.string_val.length + 1;
|
||||
break;
|
||||
}
|
||||
{
|
||||
length += val->val.string_val.length + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_ADDR:
|
||||
{
|
||||
switch ( val->val.addr_val.family )
|
||||
{
|
||||
switch ( val->val.addr_val.family )
|
||||
{
|
||||
case IPv4:
|
||||
length += sizeof(val->val.addr_val.in.in4);
|
||||
break;
|
||||
case IPv6:
|
||||
length += sizeof(val->val.addr_val.in.in6);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
case IPv4:
|
||||
length += sizeof(val->val.addr_val.in.in4);
|
||||
break;
|
||||
case IPv6:
|
||||
length += sizeof(val->val.addr_val.in.in6);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case TYPE_SUBNET:
|
||||
{
|
||||
switch ( val->val.subnet_val.prefix.family )
|
||||
{
|
||||
switch ( val->val.subnet_val.prefix.family )
|
||||
{
|
||||
case IPv4:
|
||||
length += sizeof(val->val.subnet_val.prefix.in.in4) +
|
||||
sizeof(val->val.subnet_val.length);
|
||||
break;
|
||||
case IPv6:
|
||||
length += sizeof(val->val.subnet_val.prefix.in.in6) +
|
||||
sizeof(val->val.subnet_val.length);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
case IPv4:
|
||||
length += sizeof(val->val.subnet_val.prefix.in.in4) +
|
||||
sizeof(val->val.subnet_val.length);
|
||||
break;
|
||||
case IPv6:
|
||||
length += sizeof(val->val.subnet_val.prefix.in.in6) +
|
||||
sizeof(val->val.subnet_val.length);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case TYPE_PATTERN:
|
||||
{
|
||||
length += strlen(val->val.pattern_text_val) + 1;
|
||||
break;
|
||||
}
|
||||
{
|
||||
length += strlen(val->val.pattern_text_val) + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_TABLE:
|
||||
{
|
||||
for ( int i = 0; i < val->val.set_val.size; i++ )
|
||||
length += GetValueLength(val->val.set_val.vals[i]);
|
||||
break;
|
||||
}
|
||||
{
|
||||
for ( int i = 0; i < val->val.set_val.size; i++ )
|
||||
length += GetValueLength(val->val.set_val.vals[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
int j = val->val.vector_val.size;
|
||||
for ( int i = 0; i < j; i++ )
|
||||
length += GetValueLength(val->val.vector_val.vals[i]);
|
||||
break;
|
||||
}
|
||||
{
|
||||
int j = val->val.vector_val.size;
|
||||
for ( int i = 0; i < j; i++ )
|
||||
length += GetValueLength(val->val.vector_val.vals[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
reporter->InternalError("unsupported type %d for GetValueLength", val->type);
|
||||
|
@ -2084,16 +2084,16 @@ int Manager::CopyValue(char* data, const int startpos, const Value* val) const
|
|||
return sizeof(val->val.uint_val);
|
||||
|
||||
case TYPE_PORT:
|
||||
{
|
||||
int length = 0;
|
||||
memcpy(data + startpos, (const void*)&(val->val.port_val.port),
|
||||
sizeof(val->val.port_val.port));
|
||||
length += sizeof(val->val.port_val.port);
|
||||
memcpy(data + startpos + length, (const void*)&(val->val.port_val.proto),
|
||||
sizeof(val->val.port_val.proto));
|
||||
length += sizeof(val->val.port_val.proto);
|
||||
return length;
|
||||
}
|
||||
{
|
||||
int length = 0;
|
||||
memcpy(data + startpos, (const void*)&(val->val.port_val.port),
|
||||
sizeof(val->val.port_val.port));
|
||||
length += sizeof(val->val.port_val.port);
|
||||
memcpy(data + startpos + length, (const void*)&(val->val.port_val.proto),
|
||||
sizeof(val->val.port_val.proto));
|
||||
length += sizeof(val->val.port_val.proto);
|
||||
return length;
|
||||
}
|
||||
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_TIME:
|
||||
|
@ -2104,92 +2104,92 @@ int Manager::CopyValue(char* data, const int startpos, const Value* val) const
|
|||
|
||||
case TYPE_STRING:
|
||||
case TYPE_ENUM:
|
||||
{
|
||||
memcpy(data + startpos, val->val.string_val.data, val->val.string_val.length);
|
||||
// Add a \0 to the end. To be able to hash zero-length
|
||||
// strings and differentiate from !present.
|
||||
memset(data + startpos + val->val.string_val.length, 0, 1);
|
||||
return val->val.string_val.length + 1;
|
||||
}
|
||||
{
|
||||
memcpy(data + startpos, val->val.string_val.data, val->val.string_val.length);
|
||||
// Add a \0 to the end. To be able to hash zero-length
|
||||
// strings and differentiate from !present.
|
||||
memset(data + startpos + val->val.string_val.length, 0, 1);
|
||||
return val->val.string_val.length + 1;
|
||||
}
|
||||
|
||||
case TYPE_ADDR:
|
||||
{
|
||||
int length = 0;
|
||||
switch ( val->val.addr_val.family )
|
||||
{
|
||||
int length = 0;
|
||||
switch ( val->val.addr_val.family )
|
||||
{
|
||||
case IPv4:
|
||||
length = sizeof(val->val.addr_val.in.in4);
|
||||
memcpy(data + startpos, (const char*)&(val->val.addr_val.in.in4), length);
|
||||
break;
|
||||
case IPv4:
|
||||
length = sizeof(val->val.addr_val.in.in4);
|
||||
memcpy(data + startpos, (const char*)&(val->val.addr_val.in.in4), length);
|
||||
break;
|
||||
|
||||
case IPv6:
|
||||
length = sizeof(val->val.addr_val.in.in6);
|
||||
memcpy(data + startpos, (const char*)&(val->val.addr_val.in.in6), length);
|
||||
break;
|
||||
case IPv6:
|
||||
length = sizeof(val->val.addr_val.in.in6);
|
||||
memcpy(data + startpos, (const char*)&(val->val.addr_val.in.in6), length);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
return length;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
case TYPE_SUBNET:
|
||||
{
|
||||
int length = 0;
|
||||
switch ( val->val.subnet_val.prefix.family )
|
||||
{
|
||||
int length = 0;
|
||||
switch ( val->val.subnet_val.prefix.family )
|
||||
{
|
||||
case IPv4:
|
||||
length = sizeof(val->val.addr_val.in.in4);
|
||||
memcpy(data + startpos, (const char*)&(val->val.subnet_val.prefix.in.in4),
|
||||
length);
|
||||
break;
|
||||
case IPv4:
|
||||
length = sizeof(val->val.addr_val.in.in4);
|
||||
memcpy(data + startpos, (const char*)&(val->val.subnet_val.prefix.in.in4),
|
||||
length);
|
||||
break;
|
||||
|
||||
case IPv6:
|
||||
length = sizeof(val->val.addr_val.in.in6);
|
||||
memcpy(data + startpos, (const char*)&(val->val.subnet_val.prefix.in.in6),
|
||||
length);
|
||||
break;
|
||||
case IPv6:
|
||||
length = sizeof(val->val.addr_val.in.in6);
|
||||
memcpy(data + startpos, (const char*)&(val->val.subnet_val.prefix.in.in6),
|
||||
length);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
int lengthlength = sizeof(val->val.subnet_val.length);
|
||||
memcpy(data + startpos + length, (const char*)&(val->val.subnet_val.length),
|
||||
lengthlength);
|
||||
length += lengthlength;
|
||||
|
||||
return length;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
int lengthlength = sizeof(val->val.subnet_val.length);
|
||||
memcpy(data + startpos + length, (const char*)&(val->val.subnet_val.length),
|
||||
lengthlength);
|
||||
length += lengthlength;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
case TYPE_PATTERN:
|
||||
{
|
||||
// include null-terminator
|
||||
int length = strlen(val->val.pattern_text_val) + 1;
|
||||
memcpy(data + startpos, val->val.pattern_text_val, length);
|
||||
return length;
|
||||
}
|
||||
{
|
||||
// include null-terminator
|
||||
int length = strlen(val->val.pattern_text_val) + 1;
|
||||
memcpy(data + startpos, val->val.pattern_text_val, length);
|
||||
return length;
|
||||
}
|
||||
|
||||
case TYPE_TABLE:
|
||||
{
|
||||
int length = 0;
|
||||
int j = val->val.set_val.size;
|
||||
for ( int i = 0; i < j; i++ )
|
||||
length += CopyValue(data, startpos + length, val->val.set_val.vals[i]);
|
||||
{
|
||||
int length = 0;
|
||||
int j = val->val.set_val.size;
|
||||
for ( int i = 0; i < j; i++ )
|
||||
length += CopyValue(data, startpos + length, val->val.set_val.vals[i]);
|
||||
|
||||
return length;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
int length = 0;
|
||||
int j = val->val.vector_val.size;
|
||||
for ( int i = 0; i < j; i++ )
|
||||
length += CopyValue(data, startpos + length, val->val.vector_val.vals[i]);
|
||||
{
|
||||
int length = 0;
|
||||
int j = val->val.vector_val.size;
|
||||
for ( int i = 0; i < j; i++ )
|
||||
length += CopyValue(data, startpos + length, val->val.vector_val.vals[i]);
|
||||
|
||||
return length;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
default:
|
||||
reporter->InternalError("unsupported type %d for CopyValue", val->type);
|
||||
|
@ -2284,134 +2284,133 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, Type* request_type,
|
|||
return new IntervalVal(val->val.double_val);
|
||||
|
||||
case TYPE_STRING:
|
||||
{
|
||||
String* s = new String((const u_char*)val->val.string_val.data,
|
||||
val->val.string_val.length, true);
|
||||
return new StringVal(s);
|
||||
}
|
||||
{
|
||||
String* s = new String((const u_char*)val->val.string_val.data,
|
||||
val->val.string_val.length, true);
|
||||
return new StringVal(s);
|
||||
}
|
||||
|
||||
case TYPE_PORT:
|
||||
return val_mgr->Port(val->val.port_val.port, val->val.port_val.proto)->Ref();
|
||||
|
||||
case TYPE_ADDR:
|
||||
{
|
||||
IPAddr* addr = nullptr;
|
||||
switch ( val->val.addr_val.family )
|
||||
{
|
||||
IPAddr* addr = nullptr;
|
||||
switch ( val->val.addr_val.family )
|
||||
{
|
||||
case IPv4:
|
||||
addr = new IPAddr(val->val.addr_val.in.in4);
|
||||
break;
|
||||
case IPv4:
|
||||
addr = new IPAddr(val->val.addr_val.in.in4);
|
||||
break;
|
||||
|
||||
case IPv6:
|
||||
addr = new IPAddr(val->val.addr_val.in.in6);
|
||||
break;
|
||||
case IPv6:
|
||||
addr = new IPAddr(val->val.addr_val.in.in6);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
auto* addrval = new AddrVal(*addr);
|
||||
delete addr;
|
||||
return addrval;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
auto* addrval = new AddrVal(*addr);
|
||||
delete addr;
|
||||
return addrval;
|
||||
}
|
||||
|
||||
case TYPE_SUBNET:
|
||||
{
|
||||
IPAddr* addr = nullptr;
|
||||
switch ( val->val.subnet_val.prefix.family )
|
||||
{
|
||||
IPAddr* addr = nullptr;
|
||||
switch ( val->val.subnet_val.prefix.family )
|
||||
{
|
||||
case IPv4:
|
||||
addr = new IPAddr(val->val.subnet_val.prefix.in.in4);
|
||||
break;
|
||||
case IPv4:
|
||||
addr = new IPAddr(val->val.subnet_val.prefix.in.in4);
|
||||
break;
|
||||
|
||||
case IPv6:
|
||||
addr = new IPAddr(val->val.subnet_val.prefix.in.in6);
|
||||
break;
|
||||
case IPv6:
|
||||
addr = new IPAddr(val->val.subnet_val.prefix.in.in6);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
auto* subnetval = new SubNetVal(*addr, val->val.subnet_val.length);
|
||||
delete addr;
|
||||
return subnetval;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
auto* subnetval = new SubNetVal(*addr, val->val.subnet_val.length);
|
||||
delete addr;
|
||||
return subnetval;
|
||||
}
|
||||
|
||||
case TYPE_PATTERN:
|
||||
{
|
||||
auto* re = new RE_Matcher(val->val.pattern_text_val);
|
||||
re->Compile();
|
||||
return new PatternVal(re);
|
||||
}
|
||||
{
|
||||
auto* re = new RE_Matcher(val->val.pattern_text_val);
|
||||
re->Compile();
|
||||
return new PatternVal(re);
|
||||
}
|
||||
|
||||
case TYPE_TABLE:
|
||||
{
|
||||
// all entries have to have the same type...
|
||||
const auto& type = request_type->AsTableType()->GetIndices()->GetPureType();
|
||||
auto set_index = make_intrusive<TypeList>(type);
|
||||
set_index->Append(type);
|
||||
auto s = make_intrusive<SetType>(std::move(set_index), nullptr);
|
||||
auto t = make_intrusive<TableVal>(std::move(s));
|
||||
for ( int j = 0; j < val->val.set_val.size; j++ )
|
||||
{
|
||||
// all entries have to have the same type...
|
||||
const auto& type = request_type->AsTableType()->GetIndices()->GetPureType();
|
||||
auto set_index = make_intrusive<TypeList>(type);
|
||||
set_index->Append(type);
|
||||
auto s = make_intrusive<SetType>(std::move(set_index), nullptr);
|
||||
auto t = make_intrusive<TableVal>(std::move(s));
|
||||
for ( int j = 0; j < val->val.set_val.size; j++ )
|
||||
{
|
||||
Val* assignval =
|
||||
ValueToVal(i, val->val.set_val.vals[j], type.get(), have_error);
|
||||
Val* assignval = ValueToVal(i, val->val.set_val.vals[j], type.get(), have_error);
|
||||
|
||||
if ( have_error )
|
||||
return nullptr;
|
||||
if ( have_error )
|
||||
return nullptr;
|
||||
|
||||
t->Assign({AdoptRef{}, assignval}, nullptr);
|
||||
}
|
||||
|
||||
return t.release();
|
||||
t->Assign({AdoptRef{}, assignval}, nullptr);
|
||||
}
|
||||
|
||||
return t.release();
|
||||
}
|
||||
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
// all entries have to have the same type...
|
||||
const auto& type = request_type->AsVectorType()->Yield();
|
||||
auto vt = make_intrusive<VectorType>(type);
|
||||
auto v = make_intrusive<VectorVal>(std::move(vt));
|
||||
|
||||
for ( int j = 0; j < val->val.vector_val.size; j++ )
|
||||
{
|
||||
// all entries have to have the same type...
|
||||
const auto& type = request_type->AsVectorType()->Yield();
|
||||
auto vt = make_intrusive<VectorType>(type);
|
||||
auto v = make_intrusive<VectorVal>(std::move(vt));
|
||||
auto el = ValueToVal(i, val->val.vector_val.vals[j], type.get(), have_error);
|
||||
|
||||
for ( int j = 0; j < val->val.vector_val.size; j++ )
|
||||
{
|
||||
auto el = ValueToVal(i, val->val.vector_val.vals[j], type.get(), have_error);
|
||||
if ( have_error )
|
||||
return nullptr;
|
||||
|
||||
if ( have_error )
|
||||
return nullptr;
|
||||
|
||||
v->Assign(j, {AdoptRef{}, el});
|
||||
}
|
||||
|
||||
return v.release();
|
||||
v->Assign(j, {AdoptRef{}, el});
|
||||
}
|
||||
|
||||
return v.release();
|
||||
}
|
||||
|
||||
case TYPE_ENUM:
|
||||
{
|
||||
// Convert to string first to not have to deal with missing
|
||||
// \0's...
|
||||
string enum_string(val->val.string_val.data, val->val.string_val.length);
|
||||
|
||||
string module = zeek::detail::extract_module_name(enum_string.c_str());
|
||||
string var = zeek::detail::extract_var_name(enum_string.c_str());
|
||||
|
||||
// Well, this is kind of stupid, because EnumType just
|
||||
// mangles the module name and the var name together again...
|
||||
// but well.
|
||||
bro_int_t index = request_type->AsEnumType()->Lookup(module, var.c_str());
|
||||
if ( index == -1 )
|
||||
{
|
||||
// Convert to string first to not have to deal with missing
|
||||
// \0's...
|
||||
string enum_string(val->val.string_val.data, val->val.string_val.length);
|
||||
Warning(i, "Value '%s' for stream '%s' is not a valid enum.", enum_string.c_str(),
|
||||
i->name.c_str());
|
||||
|
||||
string module = zeek::detail::extract_module_name(enum_string.c_str());
|
||||
string var = zeek::detail::extract_var_name(enum_string.c_str());
|
||||
|
||||
// Well, this is kind of stupid, because EnumType just
|
||||
// mangles the module name and the var name together again...
|
||||
// but well.
|
||||
bro_int_t index = request_type->AsEnumType()->Lookup(module, var.c_str());
|
||||
if ( index == -1 )
|
||||
{
|
||||
Warning(i, "Value '%s' for stream '%s' is not a valid enum.",
|
||||
enum_string.c_str(), i->name.c_str());
|
||||
|
||||
have_error = true;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto rval = request_type->AsEnumType()->GetEnumVal(index);
|
||||
return rval.release();
|
||||
have_error = true;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto rval = request_type->AsEnumType()->GetEnumVal(index);
|
||||
return rval.release();
|
||||
}
|
||||
|
||||
default:
|
||||
reporter->InternalError("Unsupported type for input_read in stream %s",
|
||||
i->name.c_str());
|
||||
|
|
|
@ -281,59 +281,59 @@ bool Ascii::DoUpdate()
|
|||
switch ( Info().mode )
|
||||
{
|
||||
case MODE_REREAD:
|
||||
{
|
||||
// check if the file has changed
|
||||
struct stat sb;
|
||||
if ( stat(fname.c_str(), &sb) == -1 )
|
||||
{
|
||||
// check if the file has changed
|
||||
struct stat sb;
|
||||
if ( stat(fname.c_str(), &sb) == -1 )
|
||||
{
|
||||
FailWarn(fail_on_file_problem, Fmt("Could not get stat for %s", fname.c_str()),
|
||||
true);
|
||||
FailWarn(fail_on_file_problem, Fmt("Could not get stat for %s", fname.c_str()),
|
||||
true);
|
||||
|
||||
file.close();
|
||||
return ! fail_on_file_problem;
|
||||
}
|
||||
|
||||
if ( sb.st_ino == ino && sb.st_mtime == mtime )
|
||||
// no change
|
||||
return true;
|
||||
|
||||
// Warn again in case of trouble if the file changes. The comparison to 0
|
||||
// is to suppress an extra warning that we'd otherwise get on the initial
|
||||
// inode assignment.
|
||||
if ( ino != 0 )
|
||||
StopWarningSuppression();
|
||||
|
||||
mtime = sb.st_mtime;
|
||||
ino = sb.st_ino;
|
||||
// File changed. Fall through to re-read.
|
||||
file.close();
|
||||
return ! fail_on_file_problem;
|
||||
}
|
||||
|
||||
if ( sb.st_ino == ino && sb.st_mtime == mtime )
|
||||
// no change
|
||||
return true;
|
||||
|
||||
// Warn again in case of trouble if the file changes. The comparison to 0
|
||||
// is to suppress an extra warning that we'd otherwise get on the initial
|
||||
// inode assignment.
|
||||
if ( ino != 0 )
|
||||
StopWarningSuppression();
|
||||
|
||||
mtime = sb.st_mtime;
|
||||
ino = sb.st_ino;
|
||||
// File changed. Fall through to re-read.
|
||||
}
|
||||
|
||||
case MODE_MANUAL:
|
||||
case MODE_STREAM:
|
||||
{
|
||||
// dirty, fix me. (well, apparently after trying seeking, etc
|
||||
// - this is not that bad)
|
||||
if ( file.is_open() )
|
||||
{
|
||||
// dirty, fix me. (well, apparently after trying seeking, etc
|
||||
// - this is not that bad)
|
||||
if ( file.is_open() )
|
||||
if ( Info().mode == MODE_STREAM )
|
||||
{
|
||||
if ( Info().mode == MODE_STREAM )
|
||||
file.clear(); // remove end of file evil bits
|
||||
if ( ! ReadHeader(true) )
|
||||
{
|
||||
file.clear(); // remove end of file evil bits
|
||||
if ( ! ReadHeader(true) )
|
||||
{
|
||||
return ! fail_on_file_problem; // header reading failed
|
||||
}
|
||||
|
||||
break;
|
||||
return ! fail_on_file_problem; // header reading failed
|
||||
}
|
||||
|
||||
file.close();
|
||||
break;
|
||||
}
|
||||
|
||||
OpenFile();
|
||||
|
||||
break;
|
||||
file.close();
|
||||
}
|
||||
|
||||
OpenFile();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
|
|
@ -134,12 +134,12 @@ threading::Value* Benchmark::EntryToVal(TypeTag type, TypeTag subtype)
|
|||
assert(false); // no enums, please.
|
||||
|
||||
case TYPE_STRING:
|
||||
{
|
||||
std::string rnd = RandomString(10);
|
||||
val->val.string_val.data = util::copy_string(rnd.c_str());
|
||||
val->val.string_val.length = rnd.size();
|
||||
break;
|
||||
}
|
||||
{
|
||||
std::string rnd = RandomString(10);
|
||||
val->val.string_val.data = util::copy_string(rnd.c_str());
|
||||
val->val.string_val.length = rnd.size();
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_BOOL:
|
||||
val->val.int_val = 1; // we never lie.
|
||||
|
@ -168,10 +168,10 @@ threading::Value* Benchmark::EntryToVal(TypeTag type, TypeTag subtype)
|
|||
break;
|
||||
|
||||
case TYPE_SUBNET:
|
||||
{
|
||||
val->val.subnet_val.prefix = ascii->ParseAddr("192.168.17.1");
|
||||
val->val.subnet_val.length = 16;
|
||||
}
|
||||
{
|
||||
val->val.subnet_val.prefix = ascii->ParseAddr("192.168.17.1");
|
||||
val->val.subnet_val.length = 16;
|
||||
}
|
||||
break;
|
||||
|
||||
case TYPE_ADDR:
|
||||
|
|
|
@ -199,20 +199,20 @@ bool Binary::DoUpdate()
|
|||
switch ( Info().mode )
|
||||
{
|
||||
case MODE_REREAD:
|
||||
{
|
||||
switch ( UpdateModificationTime() )
|
||||
{
|
||||
switch ( UpdateModificationTime() )
|
||||
{
|
||||
case -1:
|
||||
return false; // error
|
||||
case 0:
|
||||
return true; // no change
|
||||
case 1:
|
||||
break; // file changed. reread.
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
// fallthrough
|
||||
case -1:
|
||||
return false; // error
|
||||
case 0:
|
||||
return true; // no change
|
||||
case 1:
|
||||
break; // file changed. reread.
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
// fallthrough
|
||||
}
|
||||
|
||||
case MODE_MANUAL:
|
||||
case MODE_STREAM:
|
||||
|
|
|
@ -118,54 +118,54 @@ bool Config::DoUpdate()
|
|||
switch ( Info().mode )
|
||||
{
|
||||
case MODE_REREAD:
|
||||
{
|
||||
// check if the file has changed
|
||||
struct stat sb;
|
||||
if ( stat(Info().source, &sb) == -1 )
|
||||
{
|
||||
// check if the file has changed
|
||||
struct stat sb;
|
||||
if ( stat(Info().source, &sb) == -1 )
|
||||
{
|
||||
FailWarn(fail_on_file_problem, Fmt("Could not get stat for %s", Info().source),
|
||||
true);
|
||||
FailWarn(fail_on_file_problem, Fmt("Could not get stat for %s", Info().source),
|
||||
true);
|
||||
|
||||
file.close();
|
||||
return ! fail_on_file_problem;
|
||||
}
|
||||
|
||||
if ( sb.st_ino == ino && sb.st_mtime == mtime )
|
||||
// no change
|
||||
return true;
|
||||
|
||||
// Warn again in case of trouble if the file changes. The comparison to 0
|
||||
// is to suppress an extra warning that we'd otherwise get on the initial
|
||||
// inode assignment.
|
||||
if ( ino != 0 )
|
||||
StopWarningSuppression();
|
||||
|
||||
mtime = sb.st_mtime;
|
||||
ino = sb.st_ino;
|
||||
// File changed. Fall through to re-read.
|
||||
file.close();
|
||||
return ! fail_on_file_problem;
|
||||
}
|
||||
|
||||
if ( sb.st_ino == ino && sb.st_mtime == mtime )
|
||||
// no change
|
||||
return true;
|
||||
|
||||
// Warn again in case of trouble if the file changes. The comparison to 0
|
||||
// is to suppress an extra warning that we'd otherwise get on the initial
|
||||
// inode assignment.
|
||||
if ( ino != 0 )
|
||||
StopWarningSuppression();
|
||||
|
||||
mtime = sb.st_mtime;
|
||||
ino = sb.st_ino;
|
||||
// File changed. Fall through to re-read.
|
||||
}
|
||||
|
||||
case MODE_MANUAL:
|
||||
case MODE_STREAM:
|
||||
{
|
||||
// dirty, fix me. (well, apparently after trying seeking, etc
|
||||
// - this is not that bad)
|
||||
if ( file.is_open() )
|
||||
{
|
||||
// dirty, fix me. (well, apparently after trying seeking, etc
|
||||
// - this is not that bad)
|
||||
if ( file.is_open() )
|
||||
if ( Info().mode == MODE_STREAM )
|
||||
{
|
||||
if ( Info().mode == MODE_STREAM )
|
||||
{
|
||||
file.clear(); // remove end of file evil bits
|
||||
break;
|
||||
}
|
||||
|
||||
file.close();
|
||||
file.clear(); // remove end of file evil bits
|
||||
break;
|
||||
}
|
||||
|
||||
OpenFile();
|
||||
|
||||
break;
|
||||
file.close();
|
||||
}
|
||||
|
||||
OpenFile();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
|
|
@ -558,27 +558,27 @@ bool Raw::DoUpdate()
|
|||
switch ( Info().mode )
|
||||
{
|
||||
case MODE_REREAD:
|
||||
{
|
||||
assert(childpid == -1); // mode may not be used to execute child programs
|
||||
// check if the file has changed
|
||||
struct stat sb;
|
||||
if ( stat(fname.c_str(), &sb) == -1 )
|
||||
{
|
||||
assert(childpid == -1); // mode may not be used to execute child programs
|
||||
// check if the file has changed
|
||||
struct stat sb;
|
||||
if ( stat(fname.c_str(), &sb) == -1 )
|
||||
{
|
||||
Error(Fmt("Could not get stat for %s", fname.c_str()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( sb.st_ino == ino && sb.st_mtime == mtime )
|
||||
// no change
|
||||
return true;
|
||||
|
||||
mtime = sb.st_mtime;
|
||||
ino = sb.st_ino;
|
||||
// file changed. reread.
|
||||
//
|
||||
// fallthrough
|
||||
Error(Fmt("Could not get stat for %s", fname.c_str()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( sb.st_ino == ino && sb.st_mtime == mtime )
|
||||
// no change
|
||||
return true;
|
||||
|
||||
mtime = sb.st_mtime;
|
||||
ino = sb.st_ino;
|
||||
// file changed. reread.
|
||||
//
|
||||
// fallthrough
|
||||
}
|
||||
|
||||
case MODE_MANUAL:
|
||||
case MODE_STREAM:
|
||||
if ( Info().mode == MODE_STREAM && file )
|
||||
|
|
|
@ -136,40 +136,40 @@ Value* SQLite::EntryToVal(sqlite3_stmt* st, const threading::Field* field, int p
|
|||
{
|
||||
case TYPE_ENUM:
|
||||
case TYPE_STRING:
|
||||
{
|
||||
const char* text = (const char*)sqlite3_column_text(st, pos);
|
||||
int length = sqlite3_column_bytes(st, pos);
|
||||
{
|
||||
const char* text = (const char*)sqlite3_column_text(st, pos);
|
||||
int length = sqlite3_column_bytes(st, pos);
|
||||
|
||||
char* out = new char[length];
|
||||
memcpy(out, text, length);
|
||||
char* out = new char[length];
|
||||
memcpy(out, text, length);
|
||||
|
||||
val->val.string_val.length = length;
|
||||
val->val.string_val.data = out;
|
||||
break;
|
||||
}
|
||||
val->val.string_val.length = length;
|
||||
val->val.string_val.data = out;
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_BOOL:
|
||||
{
|
||||
if ( sqlite3_column_type(st, pos) != SQLITE_INTEGER )
|
||||
{
|
||||
if ( sqlite3_column_type(st, pos) != SQLITE_INTEGER )
|
||||
{
|
||||
Error("Invalid data type for boolean - expected Integer");
|
||||
delete val;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int res = sqlite3_column_int(st, pos);
|
||||
|
||||
if ( res == 0 || res == 1 )
|
||||
val->val.int_val = res;
|
||||
else
|
||||
{
|
||||
Error(Fmt("Invalid value for boolean: %d", res));
|
||||
delete val;
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
Error("Invalid data type for boolean - expected Integer");
|
||||
delete val;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int res = sqlite3_column_int(st, pos);
|
||||
|
||||
if ( res == 0 || res == 1 )
|
||||
val->val.int_val = res;
|
||||
else
|
||||
{
|
||||
Error(Fmt("Invalid value for boolean: %d", res));
|
||||
delete val;
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_INT:
|
||||
val->val.int_val = sqlite3_column_int64(st, pos);
|
||||
break;
|
||||
|
@ -185,54 +185,54 @@ Value* SQLite::EntryToVal(sqlite3_stmt* st, const threading::Field* field, int p
|
|||
break;
|
||||
|
||||
case TYPE_PORT:
|
||||
{
|
||||
val->val.port_val.port = sqlite3_column_int(st, pos);
|
||||
val->val.port_val.proto = TRANSPORT_UNKNOWN;
|
||||
if ( subpos != -1 )
|
||||
{
|
||||
val->val.port_val.port = sqlite3_column_int(st, pos);
|
||||
val->val.port_val.proto = TRANSPORT_UNKNOWN;
|
||||
if ( subpos != -1 )
|
||||
{
|
||||
const char* text = (const char*)sqlite3_column_text(st, subpos);
|
||||
const char* text = (const char*)sqlite3_column_text(st, subpos);
|
||||
|
||||
if ( text == 0 )
|
||||
Error("Port protocol definition did not contain text");
|
||||
else
|
||||
{
|
||||
std::string s(text, sqlite3_column_bytes(st, subpos));
|
||||
val->val.port_val.proto = io->ParseProto(s);
|
||||
}
|
||||
if ( text == 0 )
|
||||
Error("Port protocol definition did not contain text");
|
||||
else
|
||||
{
|
||||
std::string s(text, sqlite3_column_bytes(st, subpos));
|
||||
val->val.port_val.proto = io->ParseProto(s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_SUBNET:
|
||||
{
|
||||
const char* text = (const char*)sqlite3_column_text(st, pos);
|
||||
std::string s(text, sqlite3_column_bytes(st, pos));
|
||||
int pos = s.find('/');
|
||||
int width = atoi(s.substr(pos + 1).c_str());
|
||||
std::string addr = s.substr(0, pos);
|
||||
{
|
||||
const char* text = (const char*)sqlite3_column_text(st, pos);
|
||||
std::string s(text, sqlite3_column_bytes(st, pos));
|
||||
int pos = s.find('/');
|
||||
int width = atoi(s.substr(pos + 1).c_str());
|
||||
std::string addr = s.substr(0, pos);
|
||||
|
||||
val->val.subnet_val.prefix = io->ParseAddr(addr);
|
||||
val->val.subnet_val.length = width;
|
||||
break;
|
||||
}
|
||||
val->val.subnet_val.prefix = io->ParseAddr(addr);
|
||||
val->val.subnet_val.length = width;
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_ADDR:
|
||||
{
|
||||
const char* text = (const char*)sqlite3_column_text(st, pos);
|
||||
std::string s(text, sqlite3_column_bytes(st, pos));
|
||||
val->val.addr_val = io->ParseAddr(s);
|
||||
break;
|
||||
}
|
||||
{
|
||||
const char* text = (const char*)sqlite3_column_text(st, pos);
|
||||
std::string s(text, sqlite3_column_bytes(st, pos));
|
||||
val->val.addr_val = io->ParseAddr(s);
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_TABLE:
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
const char* text = (const char*)sqlite3_column_text(st, pos);
|
||||
std::string s(text, sqlite3_column_bytes(st, pos));
|
||||
delete val;
|
||||
val = io->ParseValue(s, "", field->type, field->subtype);
|
||||
break;
|
||||
}
|
||||
{
|
||||
const char* text = (const char*)sqlite3_column_text(st, pos);
|
||||
std::string s(text, sqlite3_column_bytes(st, pos));
|
||||
delete val;
|
||||
val = io->ParseValue(s, "", field->type, field->subtype);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
Error(Fmt("unsupported field format %d", field->type));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue