Merge remote-tracking branch 'origin/topic/awelzel/2709-colon-colon-for-global'

* origin/topic/awelzel/2709-colon-colon-for-global:
  ci: Bust Ubuntu 22.10 image cache
  Support :: prefix to reference global namespace, deprecate GLOBAL::
This commit is contained in:
Arne Welzel 2023-07-12 17:29:26 +02:00
commit b6bff8aa37
29 changed files with 486 additions and 22 deletions

View file

@ -1,3 +1,11 @@
6.1.0-dev.202 | 2023-07-12 17:29:26 +0200
* ci: Bust Ubuntu 22.10 image cache (Arne Welzel, Corelight)
Cirrus jobs failing to pull the image, try rebuilding.
* GH-2709: Support :: prefix to reference global namespace, deprecate GLOBAL:: (Arne Welzel, Corelight)
6.1.0-dev.198 | 2023-07-11 16:16:56 -0700 6.1.0-dev.198 | 2023-07-11 16:16:56 -0700
* dce-rpc: Test cases for unbounded state growth (Arne Welzel, Corelight) * dce-rpc: Test cases for unbounded state growth (Arne Welzel, Corelight)

7
NEWS
View file

@ -39,6 +39,10 @@ New Functionality
table is prefixed with "module " and their value will have the ``type_name`` table is prefixed with "module " and their value will have the ``type_name``
field set to "module". field set to "module".
- Identifiers in the global scope can now be referenced and defined from within
modules by prefixing their names with ``::``. Previously, these required an
explicit ``GLOBAL::`` prefix to be used. Using ``GLOBAL::`` has been deprecated.
Changed Functionality Changed Functionality
--------------------- ---------------------
@ -55,6 +59,9 @@ Removed Functionality
Deprecated Functionality Deprecated Functionality
------------------------ ------------------------
- Accessing globals with ``GLOBAL::name`` has been deprecated and will be
removed with Zeek 7.1. Use ``::name`` instead.
Zeek 6.0.0 Zeek 6.0.0
========== ==========

View file

@ -1 +1 @@
6.1.0-dev.198 6.1.0-dev.202

View file

@ -4,7 +4,7 @@ ENV DEBIAN_FRONTEND="noninteractive" TZ="America/Los_Angeles"
# A version field to invalidate Cirrus's build cache when needed, as suggested in # A version field to invalidate Cirrus's build cache when needed, as suggested in
# https://github.com/cirruslabs/cirrus-ci-docs/issues/544#issuecomment-566066822 # https://github.com/cirruslabs/cirrus-ci-docs/issues/544#issuecomment-566066822
ENV DOCKERFILE_VERSION 20230413 ENV DOCKERFILE_VERSION 20230711
RUN apt-get update && apt-get -y install \ RUN apt-get update && apt-get -y install \
bc \ bc \

View file

@ -108,22 +108,47 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const
const IDPtr& lookup_ID(const char* name, const char* curr_module, bool no_global, const IDPtr& lookup_ID(const char* name, const char* curr_module, bool no_global,
bool same_module_only, bool check_export) bool same_module_only, bool check_export)
{ {
bool explicit_global = zeek::util::starts_with(name, "::");
// Ad-hoc deprecation if a name starts with "GLOBAL::". In v7.1 we could
// tweak {ID} to reject GLOBAL::, or switch this warning to error instead.
static std::string deprecated_prefix = util::fmt("%s::", GLOBAL_MODULE_NAME);
if ( zeek::util::starts_with(name, deprecated_prefix) )
reporter->Deprecation(util::fmt("Remove in v7.1: Use :: instead of %s (%s)",
deprecated_prefix.c_str(), name));
std::string fullname = make_full_var_name(curr_module, name); std::string fullname = make_full_var_name(curr_module, name);
std::string ID_module = extract_module_name(fullname.c_str()); std::string ID_module = extract_module_name(fullname.c_str());
bool need_export = check_export &&
(ID_module != GLOBAL_MODULE_NAME && ID_module != curr_module);
for ( auto s_i = scopes.rbegin(); s_i != scopes.rend(); ++s_i ) // This is mostly for sanity (and should be covered by syntax)
if ( explicit_global && same_module_only && ID_module != GLOBAL_MODULE_NAME )
{ {
const auto& id = (*s_i)->Find(fullname); reporter->Error("lookup_ID for %s with :: prefix for non-global module called", name);
return ID::nil;
}
if ( id ) if ( explicit_global && no_global )
{
reporter->Error("lookup_ID for %s with :: prefix, but no_global=true", name);
return ID::nil;
}
if ( ! explicit_global )
{
bool need_export = check_export &&
(ID_module != GLOBAL_MODULE_NAME && ID_module != curr_module);
for ( auto s_i = scopes.rbegin(); s_i != scopes.rend(); ++s_i )
{ {
if ( need_export && ! id->IsExport() && ! in_debug ) const auto& id = (*s_i)->Find(fullname);
reporter->Error("identifier is not exported: %s", fullname.c_str());
return id; if ( id )
{
if ( need_export && ! id->IsExport() && ! in_debug )
reporter->Error("identifier is not exported: %s", fullname.c_str());
return id;
}
} }
} }

View file

@ -28,6 +28,7 @@ TEST_CASE("module_util streq")
TEST_CASE("module_util extract_module_name") TEST_CASE("module_util extract_module_name")
{ {
CHECK(extract_module_name("mod") == GLOBAL_MODULE_NAME); CHECK(extract_module_name("mod") == GLOBAL_MODULE_NAME);
CHECK(extract_module_name("::var") == GLOBAL_MODULE_NAME);
CHECK(extract_module_name("mod::") == "mod"); CHECK(extract_module_name("mod::") == "mod");
CHECK(extract_module_name("mod::var") == "mod"); CHECK(extract_module_name("mod::var") == "mod");
} }
@ -38,7 +39,7 @@ string extract_module_name(const char* name)
string module_name = name; string module_name = name;
string::size_type pos = module_name.rfind("::"); string::size_type pos = module_name.rfind("::");
if ( pos == string::npos ) if ( pos == string::npos || pos == 0 )
return GLOBAL_MODULE_NAME; return GLOBAL_MODULE_NAME;
module_name.erase(pos); module_name.erase(pos);
@ -89,16 +90,18 @@ TEST_CASE("module_util make_full_var_name")
CHECK(make_full_var_name(nullptr, "GLOBAL::var") == "var"); CHECK(make_full_var_name(nullptr, "GLOBAL::var") == "var");
CHECK(make_full_var_name(GLOBAL_MODULE_NAME, "var") == "var"); CHECK(make_full_var_name(GLOBAL_MODULE_NAME, "var") == "var");
CHECK(make_full_var_name(nullptr, "notglobal::var") == "notglobal::var"); CHECK(make_full_var_name(nullptr, "notglobal::var") == "notglobal::var");
CHECK(make_full_var_name(nullptr, "::var") == "::var"); CHECK(make_full_var_name(nullptr, "::var") == "var");
CHECK(make_full_var_name("module", "var") == "module::var"); CHECK(make_full_var_name("module", "var") == "module::var");
CHECK(make_full_var_name("module::", "var") == "module::var"); CHECK(make_full_var_name("module::", "var") == "module::var");
CHECK(make_full_var_name("", "var") == "::var"); CHECK(make_full_var_name("", "var") == "var");
CHECK(make_full_var_name("", "::var") == "var");
} }
string make_full_var_name(const char* module_name, const char* var_name) string make_full_var_name(const char* module_name, const char* var_name)
{ {
if ( ! module_name || streq(module_name, GLOBAL_MODULE_NAME) || strstr(var_name, "::") ) if ( ! module_name || streq(module_name, "") || streq(module_name, GLOBAL_MODULE_NAME) ||
strstr(var_name, "::") )
{ {
if ( streq(GLOBAL_MODULE_NAME, extract_module_name(var_name).c_str()) ) if ( streq(GLOBAL_MODULE_NAME, extract_module_name(var_name).c_str()) )
return extract_var_name(var_name); return extract_var_name(var_name);

View file

@ -21,6 +21,7 @@
%token TOK_STRING TOK_SUBNET TOK_SWITCH TOK_TABLE %token TOK_STRING TOK_SUBNET TOK_SWITCH TOK_TABLE
%token TOK_TIME TOK_TIMEOUT TOK_TYPE TOK_VECTOR TOK_WHEN %token TOK_TIME TOK_TIMEOUT TOK_TYPE TOK_VECTOR TOK_WHEN
%token TOK_WHILE TOK_AS TOK_IS %token TOK_WHILE TOK_AS TOK_IS
%token TOK_GLOBAL_ID
%token TOK_ATTR_ADD_FUNC TOK_ATTR_DEFAULT TOK_ATTR_OPTIONAL TOK_ATTR_REDEF %token TOK_ATTR_ADD_FUNC TOK_ATTR_DEFAULT TOK_ATTR_OPTIONAL TOK_ATTR_REDEF
%token TOK_ATTR_DEL_FUNC TOK_ATTR_EXPIRE_FUNC %token TOK_ATTR_DEL_FUNC TOK_ATTR_EXPIRE_FUNC
@ -55,7 +56,7 @@
%nonassoc TOK_AS TOK_IS %nonassoc TOK_AS TOK_IS
%type <b> opt_no_test opt_no_test_block opt_deep when_flavor %type <b> opt_no_test opt_no_test_block opt_deep when_flavor
%type <str> TOK_ID TOK_PATTERN_TEXT %type <str> TOK_ID TOK_PATTERN_TEXT TOK_GLOBAL_ID lookup_identifier
%type <id> local_id global_id def_global_id event_id global_or_event_id resolve_id begin_lambda case_type %type <id> local_id global_id def_global_id event_id global_or_event_id resolve_id begin_lambda case_type
%type <id_l> local_id_list case_type_list %type <id_l> local_id_list case_type_list
%type <ic> init_class %type <ic> init_class
@ -925,7 +926,7 @@ expr:
$$ = new ScheduleExpr({AdoptRef{}, $2}, {AdoptRef{}, $4}); $$ = new ScheduleExpr({AdoptRef{}, $2}, {AdoptRef{}, $4});
} }
| TOK_ID | lookup_identifier
{ {
set_location(@1); set_location(@1);
auto id = lookup_ID($1, current_module.c_str()); auto id = lookup_ID($1, current_module.c_str());
@ -1977,7 +1978,7 @@ stmt_list:
; ;
event: event:
TOK_ID '(' opt_expr_list ')' lookup_identifier '(' opt_expr_list ')'
{ {
set_location(@1, @4); set_location(@1, @4);
const auto& id = lookup_ID($1, current_module.c_str()); const auto& id = lookup_ID($1, current_module.c_str());
@ -2180,7 +2181,7 @@ event_id:
; ;
global_or_event_id: global_or_event_id:
TOK_ID lookup_identifier
{ {
set_location(@1); set_location(@1);
auto id = lookup_ID($1, current_module.c_str(), false, auto id = lookup_ID($1, current_module.c_str(), false,
@ -2218,7 +2219,7 @@ global_or_event_id:
resolve_id: resolve_id:
TOK_ID lookup_identifier
{ {
set_location(@1); set_location(@1);
auto id = lookup_ID($1, current_module.c_str()); auto id = lookup_ID($1, current_module.c_str());
@ -2231,6 +2232,20 @@ resolve_id:
} }
; ;
lookup_identifier:
TOK_ID
|
TOK_GLOBAL_ID
{
if ( is_export )
{
reporter->Error("cannot use :: prefix in export section: %s", $1);
YYERROR;
}
}
;
opt_assert_msg: opt_assert_msg:
',' expr ',' expr
{ $$ = $2; } { $$ = $2; }

View file

@ -233,6 +233,8 @@ D [0-9]+
HEX [0-9a-fA-F]+ HEX [0-9a-fA-F]+
IDCOMPONENT [A-Za-z_][A-Za-z_0-9]* IDCOMPONENT [A-Za-z_][A-Za-z_0-9]*
ID {IDCOMPONENT}(::{IDCOMPONENT})* ID {IDCOMPONENT}(::{IDCOMPONENT})*
/* Token including including :: prefix for lookups of global identifiers */
GLOBAL_ID ::{IDCOMPONENT}
IP6 ("["({HEX}:){7}{HEX}"]")|("["0x{HEX}({HEX}|:)*"::"({HEX}|:)*"]")|("["({HEX}|:)*"::"({HEX}|:)*"]")|("["({HEX}:){6}({D}"."){3}{D}"]")|("["({HEX}|:)*"::"({HEX}|:)*({D}"."){3}{D}"]") IP6 ("["({HEX}:){7}{HEX}"]")|("["0x{HEX}({HEX}|:)*"::"({HEX}|:)*"]")|("["({HEX}|:)*"::"({HEX}|:)*"]")|("["({HEX}:){6}({D}"."){3}{D}"]")|("["({HEX}|:)*"::"({HEX}|:)*({D}"."){3}{D}"]")
FILE [^ \t\r\n]+ FILE [^ \t\r\n]+
PREFIX [^ \t\r\n]+ PREFIX [^ \t\r\n]+
@ -549,6 +551,12 @@ F RET_CONST(zeek::val_mgr->False()->Ref())
return TOK_ID; return TOK_ID;
} }
{GLOBAL_ID} {
yylval.str = zeek::util::copy_string(yytext);
last_id_tok = yylval.str;
return TOK_GLOBAL_ID;
}
{D} { {D} {
RET_CONST(zeek::val_mgr->Count(static_cast<zeek_uint_t>(strtoull(yytext, (char**) NULL, 10))).release()) RET_CONST(zeek::val_mgr->Count(static_cast<zeek_uint_t>(strtoull(yytext, (char**) NULL, 10))).release())
} }

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/deprecate-global.zeek, line 22: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::test_function)
warning in <...>/deprecate-global.zeek, line 26: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::X)

View file

@ -0,0 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
X, shadows ::X (42)
::X, 42
GLOBAL::X, 42

View file

@ -0,0 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
::zeek_init()

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 3: syntax error, at or near "::disabling_analyzer"

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 5: cannot use :: prefix in export section: ::c

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 2: syntax error, at or near "::a"

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 4: unknown identifier ::missing, at or near "::missing"

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 9: unknown identifier MyModule::f, at or near "MyModule::f"

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 7: syntax error, at or near "::a"

View file

@ -0,0 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
connection, MyModule::connection, {
[y] = [type_name=count, log=F, value=<uninitialized>, default_val=<uninitialized>, optional=T]
}
::connection, connection, [type_name=count, log=F, value=<uninitialized>, default_val=<uninitialized>, optional=T]

View file

@ -0,0 +1,9 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/global-colon-colon.zeek, line 67: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::X)
warning in <...>/global-colon-colon.zeek, line 75: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::my_hook)
warning in <...>/global-colon-colon.zeek, line 82: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::func)
warning in <...>/global-colon-colon.zeek, line 89: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::funcX)
warning in <...>/global-colon-colon.zeek, line 110: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::X)
warning in <...>/global-colon-colon.zeek, line 118: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::my_hook)
warning in <...>/global-colon-colon.zeek, line 125: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::func)
warning in <...>/global-colon-colon.zeek, line 132: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::funcX)

View file

@ -0,0 +1,75 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
(MyModule) print X
MyModule X
(MyModule) print MyModule::X
MyModule X
(MyModule) print GLOBAL::X
global X
(MyModule) print ::X
global X
(MyModule) hook my_hook()
MyModule::my_hook() (in GLOBAL)
MyModule::my_hook()
(MyModule) hook MyModule::my_hook()
MyModule::my_hook() (in GLOBAL)
MyModule::my_hook()
(MyModule) hook GLOBAL::my_hook()
my_hook() (in GLOBAL)
::my_hook() (in GLOBAL)
::my_hook() (in MyModule using ::)
(MyModule) hook ::my_hook()
my_hook() (in GLOBAL)
::my_hook() (in GLOBAL)
::my_hook() (in MyModule using ::)
(MyModule) call func()
MyModule::func()
(MyModule) call GLOBAL::func()
GLOBAL::func()
(MyModule) call ::func()
GLOBAL::func()
(MyModule) call funcX()
::funcX() (in MyModule)
(MyModule) call GLOBAL::funcX()
::funcX() (in MyModule)
(MyModule) call ::funcX()
::funcX() (in MyModule)
(G) print X
global X
(G) print MyModule::X
MyModule X
(G) print GLOBAL::X
global X
(G) print ::X
global X
(G) hook my_hook()
my_hook() (in GLOBAL)
::my_hook() (in GLOBAL)
::my_hook() (in MyModule using ::)
(G) MyModule::my_hook()
MyModule::my_hook() (in GLOBAL)
MyModule::my_hook()
(G) hook GLOBAL::my_hook()
my_hook() (in GLOBAL)
::my_hook() (in GLOBAL)
::my_hook() (in MyModule using ::)
(G) hook ::my_hook()
my_hook() (in GLOBAL)
::my_hook() (in GLOBAL)
::my_hook() (in MyModule using ::)
(G) call func()
GLOBAL::func()
(G) call GLOBAL::func()
GLOBAL::func()
(G) call ::func()
GLOBAL::func()
(G) call funcX()
::funcX() (in MyModule)
(G) call GLOBAL::funcX()
::funcX() (in MyModule)
(G) call ::funcX()
::funcX() (in MyModule)
MyModule::my_event() (in MyModule)
MyModule::my_event() (in GLOBAL)
my_event() (in GLOBAL)
::my_event() in (in GLOBAL)
::my_event() (in MyModule)

View file

@ -0,0 +1,27 @@
# @TEST-DOC: Adapt in v7.1 to check for errors upon GLOBAL accesses.
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
module GLOBAL;
function test_function() { }
global X = 42;
module MyModule;
global X = fmt("shadows ::X (%s)", ::X);
event zeek_init()
{
test_function();
::test_function();
GLOBAL::test_function();
print "X", X;
print "::X", ::X;
print "GLOBAL::X", GLOBAL::X;
}

View file

@ -11,4 +11,4 @@ export {
type foo: enum { a, b }; type foo: enum { a, b };
} }
print GLOBAL::a, GLOBAL::b, a, b, c; print ::a, ::b, a, b, c;

View file

@ -0,0 +1,23 @@
# @TEST-DOC: Shadow zeek_init() event, demonstrate ::zeek_init() usage.
#
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: btest-diff .stderr
module MyModule;
export {
## MyModule::zeek_init() shadows global zeek_init() event.
global zeek_init: event();
}
# This is never invoked!
event zeek_init()
{
print "MyModule::zeek_init() - FAIL";
}
event ::zeek_init()
{
print "::zeek_init()";
}

View file

@ -0,0 +1,45 @@
# @TEST-EXEC-FAIL: zeek -b %INPUT >&2
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
event zeek_init()
{
# Do not allow local variables with ::prefix.
local ::a = 1;
}
@TEST-START-NEXT
# Do not allow :: prefix for an identifier containing a module.
hook ::Analyzer::disabling_analyzer(c: connection, atype: AllAnalyzers::Tag, aid: count) { }
@TEST-START-NEXT
# Do not allow exporting names with ::
module MyModule;
export {
global ::c = 1;
global ::h: hook();
}
@TEST-START-NEXT
# Do not allow :: prefix on parameter names.
function f(::a: string) { }
@TEST-START-NEXT
# Non-existing global identifier.
event zeek_init()
{
print ::missing;
}
@TEST-START-NEXT
module MyModule;
function ::f() {
}
event zeek_init()
{
MyModule::f();
}

View file

@ -0,0 +1,26 @@
# @TEST-DOC: redef of ::type works when global type is shadowed by module.
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: btest-diff .stderr
module MyModule;
# Module private connection type.
type connection: record { };
# Redefing the moduleconnection record.
redef record connection += {
y: count &optional;
};
# Redefing the global connection record.
redef record ::connection += {
x: count &optional;
};
event zeek_init()
{
print "connection", connection, record_fields(connection);
print "::connection", ::connection, record_fields(::connection)["x"];
}

View file

@ -0,0 +1,165 @@
# @TEST-DOC: GLOBAL:: and just :: are the same, adapt with v7.1 to remove GLOBAL:: usage.
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
module GLOBAL;
global X = "global X";
global my_hook: hook();
global my_event: event();
function func() {
print " GLOBAL::func()";
}
module MyModule;
export {
global X = "MyModule X";
global my_hook: hook();
global my_event: event();
global func: function();
}
# This implements MyModule::my_hook()
hook my_hook() &priority=9
{
print " MyModule::my_hook()";
}
# This implements GLOBAL::my_hook()
hook ::my_hook() &priority=8
{
print " ::my_hook() (in MyModule using ::)";
}
event my_event() &priority=9
{
print " MyModule::my_event() (in MyModule)";
}
event ::my_event() &priority=8
{
print " ::my_event() (in MyModule)";
}
function func()
{
print " MyModule::func()";
}
# This one is a bit funky: Defines a global function while in a module.
function ::funcX()
{
print " ::funcX() (in MyModule)";
}
event zeek_init() &priority=5
{
print "(MyModule) print X";
print fmt(" %s", X);
print "(MyModule) print MyModule::X";
print fmt(" %s", MyModule::X);
print "(MyModule) print GLOBAL::X";
print fmt(" %s", GLOBAL::X);
print "(MyModule) print ::X";
print fmt(" %s", ::X);
print "(MyModule) hook my_hook()";
hook my_hook(); # This uses MyModule::my_hook();
print "(MyModule) hook MyModule::my_hook()";
hook MyModule::my_hook(); # This uses MyModule::hook();
print "(MyModule) hook GLOBAL::my_hook()";
hook GLOBAL::my_hook();
print "(MyModule) hook ::my_hook()";
hook ::my_hook();
print "(MyModule) call func()";
func();
print "(MyModule) call GLOBAL::func()";
GLOBAL::func();
print "(MyModule) call ::func()";
::func();
print "(MyModule) call funcX()";
funcX();
print "(MyModule) call GLOBAL::funcX()";
GLOBAL::funcX();
print "(MyModule) call ::funcX()";
::funcX();
# This schedules MyEvent::my_event()
event my_event();
# This schedules the GLOBAL::my_event();
event ::my_event();
}
module GLOBAL;
event zeek_init() &priority=5
{
print "(G) print X";
print fmt(" %s", X);
print "(G) print MyModule::X";
print fmt(" %s", MyModule::X);
print "(G) print GLOBAL::X";
print fmt(" %s", GLOBAL::X);
print "(G) print ::X";
print fmt(" %s", ::X);
print "(G) hook my_hook()";
hook my_hook(); # This uses GLOBAL::my_hook();
print "(G) MyModule::my_hook()";
hook MyModule::my_hook(); # This uses MyModule::hook();
print "(G) hook GLOBAL::my_hook()";
hook GLOBAL::my_hook();
print "(G) hook ::my_hook()";
hook ::my_hook();
print "(G) call func()";
func();
print "(G) call GLOBAL::func()";
GLOBAL::func();
print "(G) call ::func()";
::func();
print "(G) call funcX()";
funcX();
print "(G) call GLOBAL::funcX()";
GLOBAL::funcX();
print "(G) call ::funcX()";
::funcX();
}
hook my_hook() &priority=10
{
print " my_hook() (in GLOBAL)";
}
hook ::my_hook() &priority=10
{
print " ::my_hook() (in GLOBAL)";
}
hook MyModule::my_hook() &priority=10
{
print " MyModule::my_hook() (in GLOBAL)";
}
event MyModule::my_event() &priority=9
{
print " MyModule::my_event() (in GLOBAL)";
}
event my_event() &priority=10
{
print " my_event() (in GLOBAL)";
}
event ::my_event() &priority=10
{
print " ::my_event() in (in GLOBAL)";
}

View file

@ -28,7 +28,7 @@ event zeek_init()
{ {
test_case( "function", T ); test_case( "function", T );
test_case( "global variable", num == 123 ); test_case( "global variable", num == 123 );
test_case( "fully qualified global variable", GLOBAL::num == 123 ); # test for BIT-1758 : GLOBAL scope ID discovery bug test_case( "fully qualified global variable", ::num == 123 );
test_case( "const", daysperyear == 365 ); test_case( "const", daysperyear == 365 );
event testevent( "foo" ); event testevent( "foo" );
} }