diff --git a/tools/bifcl/CMakeLists.txt b/tools/bifcl/CMakeLists.txt index a716e07ef7..e111d5454d 100644 --- a/tools/bifcl/CMakeLists.txt +++ b/tools/bifcl/CMakeLists.txt @@ -17,7 +17,7 @@ if ( MISSING_PREREQS ) endif () include_directories(BEFORE - ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR} ) @@ -39,9 +39,9 @@ set(bifcl_SRCS ${BISON_BIFParser_OUTPUTS} ${FLEX_BIFScanner_OUTPUTS} bif_arg.cc - bif_arg.h + include/bif_arg.h module_util.cc - module_util.h + include/module_util.h ) add_executable(bifcl ${bifcl_SRCS}) diff --git a/tools/bifcl/include/bif_arg.h b/tools/bifcl/include/bif_arg.h new file mode 100644 index 0000000000..906cfd9c6a --- /dev/null +++ b/tools/bifcl/include/bif_arg.h @@ -0,0 +1,51 @@ +#ifndef bif_arg_h +#define bif_arg_h + +#include + +enum builtin_func_arg_type { +#define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, accessor, constructor) \ + id, +#include "bif_type.def" +#undef DEFINE_BIF_TYPE +/* + TYPE_ANY, + TYPE_BOOL, + TYPE_COUNT, + TYPE_INT, + TYPE_STRING, + TYPE_PATTERN, + TYPE_PORT, + TYPE_OTHER, +*/ +}; + +extern const char* builtin_func_arg_type_bro_name[]; + +class BuiltinFuncArg { +public: + BuiltinFuncArg(const char* arg_name, int arg_type); + BuiltinFuncArg(const char* arg_name, const char* arg_type_str, + const char* arg_attr_str = ""); + + void SetAttrStr(const char* arg_attr_str) + { + attr_str = arg_attr_str; + }; + + const char* Name() const { return name; } + int Type() const { return type; } + + void PrintBro(FILE* fp); + void PrintCDef(FILE* fp, int n); + void PrintCArg(FILE* fp, int n); + void PrintBroValConstructor(FILE* fp); + +protected: + const char* name; + int type; + const char* type_str; + const char* attr_str; +}; + +#endif diff --git a/tools/bifcl/include/bif_type.def b/tools/bifcl/include/bif_type.def new file mode 100644 index 0000000000..9b17011cc3 --- /dev/null +++ b/tools/bifcl/include/bif_type.def @@ -0,0 +1,22 @@ +// DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, accessor, constructor) + +DEFINE_BIF_TYPE(TYPE_ADDR, "addr", "addr", "AddrVal*", "%s->AsAddrVal()", "%s") +DEFINE_BIF_TYPE(TYPE_ANY, "any", "any", "Val*", "%s", "%s") +DEFINE_BIF_TYPE(TYPE_BOOL, "bool", "bool", "int", "%s->AsBool()", "val_mgr->GetBool(%s)") +DEFINE_BIF_TYPE(TYPE_CONN_ID, "conn_id", "conn_id", "Val*", "%s", "%s") +DEFINE_BIF_TYPE(TYPE_CONNECTION, "connection", "connection", "Connection*", "%s->AsRecordVal()->GetOrigin()", "%s->BuildConnVal()") +DEFINE_BIF_TYPE(TYPE_COUNT, "count", "count", "bro_uint_t", "%s->AsCount()", "val_mgr->GetCount(%s)") +DEFINE_BIF_TYPE(TYPE_DOUBLE, "double", "double", "double", "%s->AsDouble()", "new Val(%s, TYPE_DOUBLE)") +DEFINE_BIF_TYPE(TYPE_FILE, "file", "file", "BroFile*", "%s->AsFile()", "new Val(%s)") +DEFINE_BIF_TYPE(TYPE_INT, "int", "int", "bro_int_t", "%s->AsInt()", "val_mgr->GetInt(%s)") +DEFINE_BIF_TYPE(TYPE_INTERVAL, "interval", "interval", "double", "%s->AsInterval()", "new IntervalVal(%s, Seconds)") +DEFINE_BIF_TYPE(TYPE_PACKET, "packet", "packet", "TCP_TracePacket*", "%s->AsRecordVal()->GetOrigin()", "%s->PacketVal()") +DEFINE_BIF_TYPE(TYPE_PATTERN, "pattern", "pattern", "RE_Matcher*", "%s->AsPattern()", "new PatternVal(%s)") +// DEFINE_BIF_TYPE(TYPE_PORT, "port", "port", "uint32", "%s->AsPortVal()->Port()", "incomplete data") +DEFINE_BIF_TYPE(TYPE_PORT, "port", "port", "PortVal*", "%s->AsPortVal()", "%s") +DEFINE_BIF_TYPE(TYPE_PORTVAL, "portval", "port", "PortVal*", "%s->AsPortVal()", "%s") +DEFINE_BIF_TYPE(TYPE_STRING, "string", "string", "StringVal*", "%s->AsStringVal()", "%s") +// DEFINE_BIF_TYPE(TYPE_STRING, "string", "string", "BroString*", "%s->AsString()", "new StringVal(%s)") +DEFINE_BIF_TYPE(TYPE_SUBNET, "subnet", "subnet", "SubNetVal*", "%s->AsSubNetVal()", "%s") +DEFINE_BIF_TYPE(TYPE_TIME, "time", "time", "double", "%s->AsTime()", "new Val(%s, TYPE_TIME)") +DEFINE_BIF_TYPE(TYPE_OTHER, "", "", "Val*", "%s", "%s") diff --git a/tools/bifcl/include/module_util.h b/tools/bifcl/include/module_util.h new file mode 100644 index 0000000000..8475c86f9d --- /dev/null +++ b/tools/bifcl/include/module_util.h @@ -0,0 +1,17 @@ +// +// These functions are used by both Zeek and bifcl. +// + +#include + +using namespace std; + +static const char* GLOBAL_MODULE_NAME = "GLOBAL"; + +extern string extract_module_name(const char* name); +extern string extract_var_name(const char* name); +extern string normalized_module_name(const char* module_name); // w/o :: + +// Concatenates module_name::var_name unless var_name is already fully +// qualified, in which case it is returned unmodified. +extern string make_full_var_name(const char* module_name, const char* var_name);