diff options
-rw-r--r-- | include/modules.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/include/modules.h b/include/modules.h index 4f21a6000..84895177b 100644 --- a/include/modules.h +++ b/include/modules.h @@ -76,6 +76,31 @@ enum MessageType { MSG_NOTICE = 1 }; +/** Used to represent an allow/deny module result. + * Not constructed as an enum because it reverses the value logic of some functions; + * the compiler will inline accesses to have the same efficiency as integer operations. + */ +struct ModResult { + int res; + explicit ModResult(int r) : res(r) {} + bool operator==(const ModResult& r) const + { + return res == r.res; + } + bool operator!=(const ModResult& r) const + { + return res != r.res; + } + bool operator!() const + { + return !res; + } +}; + +#define MOD_RES_ALLOW (ModResult(1)) +#define MOD_RES_PASSTHRU (ModResult(0)) +#define MOD_RES_DENY (ModResult(-1)) + /** If you change the module API, change this value. */ #define API_VERSION 13000 @@ -240,6 +265,16 @@ do { \ } \ } while(0) +#define FIRST_MOD_RESULT(z,n,v,args) do { \ + v = MOD_RES_PASSTHRU; \ + DO_EACH_HOOK(z,n,v,args) \ + { \ + if (v != MOD_RES_PASSTHRU) \ + break; \ + } \ + WHILE_EACH_HOOK(z,n); \ +} while (0) + /** Represents a non-local user. * (in fact, any FD less than -1 does) */ |