Do not allocate one OpaqueType per OpaqueVal.

Instead, we now allocate type information globally in NetVar.cc.

Addresses #986.
This commit is contained in:
Matthias Vallentin 2013-05-03 15:48:06 -07:00
parent e78c20c0f8
commit 9ac00f8c79
6 changed files with 29 additions and 9 deletions

View file

@ -149,6 +149,11 @@ RecordType* OS_version;
EnumType* OS_version_inference;
TableVal* generate_OS_version_event;
OpaqueType* md5_type;
OpaqueType* sha1_type;
OpaqueType* sha256_type;
OpaqueType* entropy_type;
double table_expire_interval;
double table_expire_delay;
int table_incremental_step;
@ -253,6 +258,11 @@ void init_event_handlers()
void init_general_global_var()
{
md5_type = new OpaqueType("md5");
sha1_type = new OpaqueType("sha1");
sha256_type = new OpaqueType("sha256");
entropy_type = new OpaqueType("entropy");
table_expire_interval = opt_internal_double("table_expire_interval");
table_expire_delay = opt_internal_double("table_expire_delay");
table_incremental_step = opt_internal_int("table_incremental_step");

View file

@ -152,6 +152,12 @@ extern RecordType* OS_version;
extern EnumType* OS_version_inference;
extern TableVal* generate_OS_version_event;
class OpaqueType;
extern OpaqueType* md5_type;
extern OpaqueType* sha1_type;
extern OpaqueType* sha256_type;
extern OpaqueType* entropy_type;
extern double table_expire_interval;
extern double table_expire_delay;
extern int table_incremental_step;

View file

@ -1,4 +1,5 @@
#include "OpaqueVal.h"
#include "NetVar.h"
#include "Reporter.h"
#include "Serializer.h"
@ -72,6 +73,8 @@ bool HashVal::DoUnserialize(UnserialInfo* info)
return UNSERIALIZE(&valid);
}
MD5Val::MD5Val() : HashVal(md5_type) { }
void MD5Val::digest(val_list& vlist, u_char result[MD5_DIGEST_LENGTH])
{
MD5_CTX h;
@ -189,6 +192,8 @@ bool MD5Val::DoUnserialize(UnserialInfo* info)
return true;
}
SHA1Val::SHA1Val() : HashVal(sha1_type) { }
void SHA1Val::digest(val_list& vlist, u_char result[SHA_DIGEST_LENGTH])
{
SHA_CTX h;
@ -297,6 +302,8 @@ bool SHA1Val::DoUnserialize(UnserialInfo* info)
return true;
}
SHA256Val::SHA256Val() : HashVal(sha256_type) { }
void SHA256Val::digest(val_list& vlist, u_char result[SHA256_DIGEST_LENGTH])
{
SHA256_CTX h;
@ -410,6 +417,7 @@ bool SHA256Val::DoUnserialize(UnserialInfo* info)
return true;
}
EntropyVal::EntropyVal() : OpaqueVal(entropy_type) { }
bool EntropyVal::Feed(const void* data, size_t size)
{

View file

@ -36,7 +36,7 @@ public:
u_char key[MD5_DIGEST_LENGTH],
u_char result[MD5_DIGEST_LENGTH]);
MD5Val() : HashVal(new OpaqueType("md5")) { }
MD5Val();
protected:
friend class Val;
@ -55,7 +55,7 @@ class SHA1Val : public HashVal {
public:
static void digest(val_list& vlist, u_char result[SHA_DIGEST_LENGTH]);
SHA1Val() : HashVal(new OpaqueType("sha1")) { }
SHA1Val();
protected:
friend class Val;
@ -74,7 +74,7 @@ class SHA256Val : public HashVal {
public:
static void digest(val_list& vlist, u_char result[SHA256_DIGEST_LENGTH]);
SHA256Val() : HashVal(new OpaqueType("sha256")) { }
SHA256Val();
protected:
friend class Val;
@ -91,7 +91,7 @@ private:
class EntropyVal : public OpaqueVal {
public:
EntropyVal() : OpaqueVal(new OpaqueType("entropy")) { }
EntropyVal();
bool Feed(const void* data, size_t size);
bool Get(double *r_ent, double *r_chisq, double *r_mean,

View file

@ -3125,13 +3125,12 @@ void VectorVal::ValDescribe(ODesc* d) const
d->Add("]");
}
OpaqueVal::OpaqueVal(OpaqueType* t) : Val(t), type(t)
OpaqueVal::OpaqueVal(OpaqueType* t) : Val(t)
{
}
OpaqueVal::~OpaqueVal()
{
Unref(type);
}
IMPLEMENT_SERIAL(OpaqueVal, SER_OPAQUE_VAL);

View file

@ -1024,9 +1024,6 @@ protected:
OpaqueVal() { }
DECLARE_SERIAL(OpaqueVal);
private:
OpaqueType* type;
};
// Checks the given value for consistency with the given type. If an