Add HookAddConstString() and friends.

Also EfunctionAddPChar() -> EfunctionAddString(), and callbacks etc.
This commit is contained in:
Bram Matthys 2021-09-10 11:58:48 +02:00
parent a3bfa210e9
commit edfdfe4a03
No known key found for this signature in database
GPG key ID: BF8116B163EAAE98
8 changed files with 52 additions and 39 deletions

View file

@ -576,6 +576,7 @@ struct Hook {
int (*intfunc)();
void (*voidfunc)();
char *(*stringfunc)();
const char *(*conststringfunc)();
} func;
Module *owner;
};
@ -588,6 +589,7 @@ struct Callback {
void (*voidfunc)();
void *(*pvoidfunc)();
char *(*stringfunc)();
const char *(*conststringfunc)();
} func;
Module *owner;
char willberemoved; /* will be removed on next rehash? (eg the 'old'/'current' one) */
@ -609,6 +611,7 @@ struct Efunction {
void (*voidfunc)();
void *(*pvoidfunc)();
char *(*stringfunc)();
const char *(*conststringfunc)();
} func;
Module *owner;
char willberemoved; /* will be removed on next rehash? (eg the 'old'/'current' one) */
@ -790,30 +793,36 @@ extern HistoryBackend *HistoryBackendAdd(Module *module, HistoryBackendInfo *mre
extern void HistoryBackendDel(HistoryBackend *m);
#ifndef GCC_TYPECHECKING
#define HookAdd(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, func, NULL, NULL)
#define HookAddVoid(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, func, NULL)
#define HookAddString(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, NULL, func)
#define HookAdd(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, func, NULL, NULL, NULL)
#define HookAddVoid(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, func, NULL, NULL)
#define HookAddString(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, NULL, func, NULL)
#define HookAddConstString(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, NULL, NULL, func)
#else
#define HookAdd(module, hooktype, priority, func) \
__extension__ ({ \
ValidateHooks(hooktype, func); \
HookAddMain(module, hooktype, priority, func, NULL, NULL); \
HookAddMain(module, hooktype, priority, func, NULL, NULL, NULL); \
})
#define HookAddVoid(module, hooktype, priority, func) \
__extension__ ({ \
ValidateHooks(hooktype, func); \
HookAddMain(module, hooktype, priority, NULL, func, NULL); \
HookAddMain(module, hooktype, priority, NULL, func, NULL, NULL); \
})
#define HookAddString(module, hooktype, priority, func) \
__extension__ ({ \
ValidateHooks(hooktype, func); \
HookAddMain(module, hooktype, priority, NULL, NULL, func); \
HookAddMain(module, hooktype, priority, NULL, NULL, func, NULL); \
})
#define HookAddConstString(module, hooktype, priority, func) \
__extension__ ({ \
ValidateHooks(hooktype, func); \
HookAddMain(module, hooktype, priority, NULL, NULL, NULL, func); \
})
#endif /* GCC_TYPCHECKING */
extern Hook *HookAddMain(Module *module, int hooktype, int priority, int (*intfunc)(), void (*voidfunc)(), char *(*stringfunc)());
extern Hook *HookAddMain(Module *module, int hooktype, int priority, int (*intfunc)(), void (*voidfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)());
extern Hook *HookDel(Hook *hook);
extern Hooktype *HooktypeAdd(Module *module, char *string, int *type);
@ -911,24 +920,22 @@ extern void HooktypeDel(Hooktype *hooktype, Module *module);
#define RunHook7(hooktype,a,b,c,d,e,f,g) do { Hook *hook; for (hook = Hooks[hooktype]; hook; hook = hook->next) (*(hook->func.intfunc))(a,b,c,d,e,f,g); } while(0)
#define RunHook8(hooktype,a,b,c,d,e,f,g,h) do { Hook *hook; for (hook = Hooks[hooktype]; hook; hook = hook->next) (*(hook->func.intfunc))(a,b,c,d,e,f,g,h); } while(0)
#define CallbackAdd(cbtype, func) CallbackAddMain(NULL, cbtype, func, NULL, NULL, NULL)
#define CallbackAddVoid(cbtype, func) CallbackAddMain(NULL, cbtype, NULL, func, NULL, NULL)
#define CallbackAddPVoid(cbtype, func) CallbackAddMain(NULL, cbtype, NULL, NULL, func, NULL)
#define CallbackAddPChar(cbtype, func) CallbackAddMain(NULL, cbtype, NULL, NULL, NULL, func)
#define CallbackAddEx(module, cbtype, func) CallbackAddMain(module, cbtype, func, NULL, NULL, NULL)
#define CallbackAddVoidEx(module, cbtype, func) CallbackAddMain(module, cbtype, NULL, func, NULL, NULL)
#define CallbackAddPVoidEx(module, cbtype, func) CallbackAddMain(module, cbtype, NULL, NULL, func, NULL)
#define CallbackAddPCharEx(module, cbtype, func) CallbackAddMain(module, cbtype, NULL, NULL, NULL, func)
#define CallbackAddEx(module, cbtype, func) CallbackAddMain(module, cbtype, func, NULL, NULL, NULL, NULL)
#define CallbackAddVoidEx(module, cbtype, func) CallbackAddMain(module, cbtype, NULL, func, NULL, NULL, NULL)
#define CallbackAddPVoidEx(module, cbtype, func) CallbackAddMain(module, cbtype, NULL, NULL, func, NULL, NULL)
#define CallbackAddStringEx(module, cbtype, func) CallbackAddMain(module, cbtype, NULL, NULL, NULL, func, NULL)
#define CallbackAddConstStringEx(module, cbtype, func) CallbackAddMain(module, cbtype, NULL, NULL, NULL, NULL, func)
extern Callback *CallbackAddMain(Module *module, int cbtype, int (*func)(), void (*vfunc)(), void *(*pvfunc)(), char *(*stringfunc)());
extern Callback *CallbackAddMain(Module *module, int cbtype, int (*func)(), void (*vfunc)(), void *(*pvfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)());
extern Callback *CallbackDel(Callback *cb);
#define EfunctionAdd(module, cbtype, func) EfunctionAddMain(module, cbtype, func, NULL, NULL, NULL)
#define EfunctionAddVoid(module, cbtype, func) EfunctionAddMain(module, cbtype, NULL, func, NULL, NULL)
#define EfunctionAddPVoid(module, cbtype, func) EfunctionAddMain(module, cbtype, NULL, NULL, func, NULL)
#define EfunctionAddPChar(module, cbtype, func) EfunctionAddMain(module, cbtype, NULL, NULL, NULL, func)
#define EfunctionAdd(module, cbtype, func) EfunctionAddMain(module, cbtype, func, NULL, NULL, NULL, NULL)
#define EfunctionAddVoid(module, cbtype, func) EfunctionAddMain(module, cbtype, NULL, func, NULL, NULL, NULL)
#define EfunctionAddPVoid(module, cbtype, func) EfunctionAddMain(module, cbtype, NULL, NULL, func, NULL, NULL)
#define EfunctionAddString(module, cbtype, func) EfunctionAddMain(module, cbtype, NULL, NULL, NULL, func, NULL)
#define EfunctionAddConstString(module, cbtype, func) EfunctionAddMain(module, cbtype, NULL, NULL, NULL, NULL, func)
extern Efunction *EfunctionAddMain(Module *module, EfunctionType eftype, int (*intfunc)(), void (*voidfunc)(), void *(*pvoidfunc)(), char *(*stringfunc)());
extern Efunction *EfunctionAddMain(Module *module, EfunctionType eftype, int (*intfunc)(), void (*voidfunc)(), void *(*pvoidfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)());
extern Efunction *EfunctionDel(Efunction *cb);
extern Command *CommandAdd(Module *module, char *cmd, CmdFunc func, unsigned char params, int flags);

View file

@ -134,7 +134,7 @@ int (*watch_check)(Client *client, int reply, int (*watch_notify)(Client *client
void (*do_unreal_log_remote_deliver)(LogLevel loglevel, char *subsystem, char *event_id, MultiLine *msg, char *json_serialized);
char *(*get_chmodes_for_user)(Client *client, int flags);
Efunction *EfunctionAddMain(Module *module, EfunctionType eftype, int (*func)(), void (*vfunc)(), void *(*pvfunc)(), char *(*cfunc)())
Efunction *EfunctionAddMain(Module *module, EfunctionType eftype, int (*func)(), void (*vfunc)(), void *(*pvfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)())
{
Efunction *p;
@ -152,8 +152,10 @@ Efunction *EfunctionAddMain(Module *module, EfunctionType eftype, int (*func)(),
p->func.voidfunc = vfunc;
if (pvfunc)
p->func.pvoidfunc = pvfunc;
if (cfunc)
p->func.stringfunc = cfunc;
if (stringfunc)
p->func.stringfunc = stringfunc;
if (conststringfunc)
p->func.conststringfunc = conststringfunc;
p->type = eftype;
p->owner = module;
AddListItem(p, Efunctions[eftype]);

View file

@ -985,7 +985,7 @@ void VersionflagDel(Versionflag *vflag, Module *module)
}
}
Hook *HookAddMain(Module *module, int hooktype, int priority, int (*func)(), void (*vfunc)(), char *(*cfunc)())
Hook *HookAddMain(Module *module, int hooktype, int priority, int (*func)(), void (*vfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)())
{
Hook *p;
@ -994,8 +994,10 @@ Hook *HookAddMain(Module *module, int hooktype, int priority, int (*func)(), voi
p->func.intfunc = func;
if (vfunc)
p->func.voidfunc = vfunc;
if (cfunc)
p->func.stringfunc = cfunc;
if (stringfunc)
p->func.stringfunc = stringfunc;
if (conststringfunc)
p->func.conststringfunc = conststringfunc;
p->type = hooktype;
p->owner = module;
p->priority = priority;
@ -1049,7 +1051,7 @@ int cnt = 0;
return cnt;
}
Callback *CallbackAddMain(Module *module, int cbtype, int (*func)(), void (*vfunc)(), void *(*pvfunc)(), char *(*cfunc)())
Callback *CallbackAddMain(Module *module, int cbtype, int (*func)(), void (*vfunc)(), void *(*pvfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)())
{
Callback *p;
@ -1067,8 +1069,10 @@ Callback *CallbackAddMain(Module *module, int cbtype, int (*func)(), void (*vfun
p->func.voidfunc = vfunc;
if (pvfunc)
p->func.pvoidfunc = pvfunc;
if (cfunc)
p->func.stringfunc = cfunc;
if (stringfunc)
p->func.stringfunc = stringfunc;
if (conststringfunc)
p->func.conststringfunc = conststringfunc;
p->type = cbtype;
p->owner = module;
AddListItem(p, Callbacks[cbtype]);

View file

@ -189,7 +189,7 @@ MOD_TEST()
MARK_AS_OFFICIAL_MODULE(modinfo);
EfunctionAdd(modinfo->handle, EFUNC_DO_NICK_NAME, _do_nick_name);
EfunctionAdd(modinfo->handle, EFUNC_DO_REMOTE_NICK_NAME, _do_remote_nick_name);
EfunctionAddPChar(modinfo->handle, EFUNC_CHARSYS_GET_CURRENT_LANGUAGES, _charsys_get_current_languages);
EfunctionAddString(modinfo->handle, EFUNC_CHARSYS_GET_CURRENT_LANGUAGES, _charsys_get_current_languages);
charsys_reset();
charsys_reset_pretest();
HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, charsys_config_test);

View file

@ -39,7 +39,7 @@ MOD_TEST()
{
MARK_AS_OFFICIAL_MODULE(modinfo);
EfunctionAddPChar(modinfo->handle, EFUNC_MTAGS_TO_STRING, _mtags_to_string);
EfunctionAddString(modinfo->handle, EFUNC_MTAGS_TO_STRING, _mtags_to_string);
EfunctionAddVoid(modinfo->handle, EFUNC_PARSE_MESSAGE_TAGS, _parse_message_tags);
return 0;

View file

@ -46,8 +46,8 @@ ModuleHeader MOD_HEADER
MOD_TEST()
{
MARK_AS_OFFICIAL_MODULE(modinfo);
EfunctionAddPChar(modinfo->handle, EFUNC_STRIPCOLORS, _StripColors);
EfunctionAddPChar(modinfo->handle, EFUNC_STRIPCONTROLCODES, _StripControlCodes);
EfunctionAddString(modinfo->handle, EFUNC_STRIPCOLORS, _StripColors);
EfunctionAddString(modinfo->handle, EFUNC_STRIPCONTROLCODES, _StripControlCodes);
EfunctionAdd(modinfo->handle, EFUNC_CAN_SEND_TO_CHANNEL, _can_send_to_channel);
return MOD_SUCCESS;
}

View file

@ -58,13 +58,13 @@ ModuleHeader MOD_HEADER = {
MOD_TEST()
{
cloak = CallbackAddPCharEx(modinfo->handle, CALLBACKTYPE_CLOAK_EX, hidehost);
cloak = CallbackAddStringEx(modinfo->handle, CALLBACKTYPE_CLOAK_EX, hidehost);
if (!cloak)
{
config_error("cloak: Error while trying to install cloaking callback!");
return MOD_FAILED;
}
cloak_csum = CallbackAddPCharEx(modinfo->handle, CALLBACKTYPE_CLOAKKEYCSUM, cloakcsum);
cloak_csum = CallbackAddStringEx(modinfo->handle, CALLBACKTYPE_CLOAKKEYCSUM, cloakcsum);
if (!cloak_csum)
{
config_error("cloak: Error while trying to install cloaking checksum callback!");

View file

@ -163,8 +163,8 @@ MOD_TEST()
EfunctionAdd(modinfo->handle, EFUNC_TKL_HASH, _tkl_hash);
EfunctionAdd(modinfo->handle, EFUNC_TKL_TYPETOCHAR, TO_INTFUNC(_tkl_typetochar));
EfunctionAdd(modinfo->handle, EFUNC_TKL_CHARTOTYPE, TO_INTFUNC(_tkl_chartotype));
EfunctionAddPChar(modinfo->handle, EFUNC_TKL_TYPE_STRING, _tkl_type_string);
EfunctionAddPChar(modinfo->handle, EFUNC_TKL_TYPE_CONFIG_STRING, _tkl_type_config_string);
EfunctionAddString(modinfo->handle, EFUNC_TKL_TYPE_STRING, _tkl_type_string);
EfunctionAddString(modinfo->handle, EFUNC_TKL_TYPE_CONFIG_STRING, _tkl_type_config_string);
EfunctionAddPVoid(modinfo->handle, EFUNC_TKL_ADD_SERVERBAN, TO_PVOIDFUNC(_tkl_add_serverban));
EfunctionAddPVoid(modinfo->handle, EFUNC_TKL_ADD_BANEXCEPTION, TO_PVOIDFUNC(_tkl_add_banexception));
EfunctionAddPVoid(modinfo->handle, EFUNC_TKL_ADD_NAMEBAN, TO_PVOIDFUNC(_tkl_add_nameban));
@ -195,7 +195,7 @@ MOD_TEST()
EfunctionAddVoid(modinfo->handle, EFUNC_SENDNOTICE_TKL_ADD, _sendnotice_tkl_add);
EfunctionAddVoid(modinfo->handle, EFUNC_SENDNOTICE_TKL_DEL, _sendnotice_tkl_del);
EfunctionAdd(modinfo->handle, EFUNC_FIND_TKL_EXCEPTION, _find_tkl_exception);
EfunctionAddPChar(modinfo->handle, EFUNC_TKL_UHOST, _tkl_uhost);
EfunctionAddString(modinfo->handle, EFUNC_TKL_UHOST, _tkl_uhost);
return MOD_SUCCESS;
}