[Bro-Dev] Hooks (Re: [Bro-Commits] [git/bro] topic/jsiwek/hook: Add new function flavor called a "hook". (e0fb9eb))

Robin Sommer robin at icir.org
Fri Nov 16 18:56:00 PST 2012


That was fast! :)

> +        hook myhook(s: string) &priority=10
> +            {
> +            print "priority 10 myhook handler", s;
> +            s = "bye";
> +            }
> +
> +        hook myhook(s: string)
> +            {
> +            print "break out of myhook handling", s;
> +            break;
> +            }
> +
> +        hook myhook(s: string) &priority=-5
> +            {
> +            print "not going to happen", s;
> +            }

[...]
> +        hook myhook("hi");

I haven't looked too closely yet but I want to mention one thing Seth
and I discussed earlier this week: we could give hooks a mandatory
boolean return value and use that instead of the "break" command:
"return T" would continue with the next hook, and "return F" stops. In
addition, the hook statement becomes an expression that returns the
boolean (i.e., T if all ran through, and F is one stopped execution).

Thinking now about it, I believe either way is fine. The boolean hook
would convey a bit more information back to the caller and allow
simple yes/no decisions that way. But I'm not sure we need that. On
the other hand, Seth didn't like the "break" so that would go away.

Wanted to put that up for discussion, not leaning strnonly either way
right now.

Robin

-- 
Robin Sommer * Phone +1 (510) 722-6541 * robin at icir.org
ICSI/LBNL    * Fax   +1 (510) 666-2956 *   www.icir.org


More information about the bro-dev mailing list