2022-07-07 18:25:26 +00:00
|
|
|
/* radare - LGPL - Copyright 2010-2022 - pancake */
|
2010-02-25 23:37:49 +00:00
|
|
|
|
2017-05-26 00:43:26 +00:00
|
|
|
#include <config.h>
|
2014-03-17 23:05:44 +00:00
|
|
|
#include <r_core.h>
|
2010-02-25 23:37:49 +00:00
|
|
|
|
2017-03-25 01:30:00 +00:00
|
|
|
static RCorePlugin *cmd_static_plugins[] = {
|
|
|
|
R_CORE_STATIC_PLUGINS
|
|
|
|
};
|
2010-02-25 23:37:49 +00:00
|
|
|
|
2021-10-28 22:01:36 +00:00
|
|
|
R_API void r_core_plugin_fini(RCmd *cmd) {
|
2022-08-22 22:21:23 +00:00
|
|
|
r_return_if_fail (cmd);
|
2022-07-07 18:25:26 +00:00
|
|
|
if (cmd->plist) {
|
|
|
|
RListIter *iter;
|
|
|
|
RCorePlugin *plugin;
|
|
|
|
r_list_foreach (cmd->plist, iter, plugin) {
|
|
|
|
if (plugin && plugin->fini) {
|
|
|
|
plugin->fini (cmd, NULL);
|
|
|
|
}
|
2014-04-28 15:40:09 +00:00
|
|
|
}
|
2022-07-07 18:25:26 +00:00
|
|
|
r_list_free (cmd->plist);
|
|
|
|
cmd->plist = NULL;
|
2014-04-28 15:40:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-20 22:37:45 +00:00
|
|
|
R_API bool r_core_plugin_add(RCmd *cmd, RCorePlugin *plugin) {
|
|
|
|
r_return_val_if_fail (cmd && plugin, false);
|
|
|
|
if (plugin->init && !plugin->init (cmd, NULL)) {
|
2015-09-14 10:35:38 +00:00
|
|
|
return false;
|
2016-06-17 12:26:24 +00:00
|
|
|
}
|
2010-02-25 23:37:49 +00:00
|
|
|
r_list_append (cmd->plist, plugin);
|
2015-09-14 10:35:38 +00:00
|
|
|
return true;
|
2010-02-25 23:37:49 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 22:37:45 +00:00
|
|
|
R_API bool r_core_plugin_init(RCmd *cmd) {
|
2022-08-22 22:21:23 +00:00
|
|
|
r_return_val_if_fail (cmd, false);
|
2020-12-20 22:37:45 +00:00
|
|
|
size_t i;
|
2014-11-18 15:35:12 +00:00
|
|
|
cmd->plist = r_list_newf (NULL); // memleak or dblfree
|
2017-03-25 01:30:00 +00:00
|
|
|
for (i = 0; cmd_static_plugins[i]; i++) {
|
2014-04-01 15:09:07 +00:00
|
|
|
if (!r_core_plugin_add (cmd, cmd_static_plugins[i])) {
|
2022-07-07 18:25:26 +00:00
|
|
|
R_LOG_ERROR ("loading cmd plugin");
|
2015-09-14 10:35:38 +00:00
|
|
|
return false;
|
2010-02-25 23:37:49 +00:00
|
|
|
}
|
2010-05-28 00:44:51 +00:00
|
|
|
}
|
2015-09-14 10:35:38 +00:00
|
|
|
return true;
|
2010-02-25 23:37:49 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 22:37:45 +00:00
|
|
|
R_API bool r_core_plugin_check(RCmd *cmd, const char *a0) {
|
2022-08-22 22:21:23 +00:00
|
|
|
r_return_val_if_fail (cmd && a0, false);
|
2010-02-25 23:37:49 +00:00
|
|
|
RListIter *iter;
|
2014-04-01 15:09:07 +00:00
|
|
|
RCorePlugin *cp;
|
2012-02-14 17:19:16 +00:00
|
|
|
r_list_foreach (cmd->plist, iter, cp) {
|
2021-10-28 22:01:36 +00:00
|
|
|
return cp->call (NULL, a0);
|
2010-02-25 23:37:49 +00:00
|
|
|
}
|
2015-09-14 10:35:38 +00:00
|
|
|
return false;
|
2010-02-25 23:37:49 +00:00
|
|
|
}
|