Skip to content

Commit

Permalink
Move IO plugin listing from IO to core ##io
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae authored Dec 2, 2024
1 parent cc6e604 commit c938df9
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 95 deletions.
69 changes: 69 additions & 0 deletions libr/core/clist.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,72 @@ R_API void r_core_list_lang(RCore *core, int mode) {
r_table_free (table);
}
}

R_API int r_core_list_io(RCore *core, const char *name, int mode) {
RIOPlugin *plugin;
SdbListIter *iter;
char str[4];
int n = 0;
PJ *pj = NULL;
if (mode == 'j') {
pj = r_core_pj_new (core);
pj_a (pj);
}

ls_foreach (core->io->plugins, iter, plugin) {
const char *plugin_name = r_str_get (plugin->meta.name);
if (name && strcmp (plugin_name, name)) {
continue;
}
if (mode == 'j') {
pj_o (pj);
pj_ks (pj, "permissions", str);
r_lib_meta_pj (pj, &plugin->meta);
if (plugin->uris) {
char *uri;
char *uris = strdup (plugin->uris);
RList *plist = r_str_split_list (uris, ",", 0);
RListIter *piter;
pj_k (pj, "uris");
pj_a (pj);
r_list_foreach (plist, piter, uri) {
pj_s (pj, uri);
}
pj_end (pj);
r_list_free (plist);
free (uris);
}
pj_end (pj);
} else if (name) {
r_cons_printf ("name: %s\n", plugin->meta.name);
r_cons_printf ("auth: %s\n", plugin->meta.author);
r_cons_printf ("lice: %s\n", plugin->meta.license);
r_cons_printf ("desc: %s\n", plugin->meta.desc);
r_cons_printf ("uris: %s\n", plugin->uris);
if (*str) {
r_cons_printf ("perm: %s\n", str);
}
r_cons_printf ("sysc: %s\n", r_str_bool (plugin->system));
} else {
str[0] = 'r';
str[1] = plugin->write ? 'w' : '_';
str[2] = plugin->isdbg ? 'd' : '_';
str[3] = 0;
r_cons_printf ("%s %-8s %s.", str,
r_str_get (plugin->meta.name),
r_str_get (plugin->meta.desc));
if (plugin->uris) {
r_cons_printf (" %s", plugin->uris);
}
r_cons_printf ("\n");
}
n++;
}
if (pj) {
pj_end (pj);
char *s = pj_drain (pj);
r_cons_printf ("%s\n", s);
free (s);
}
return n;
}
6 changes: 1 addition & 5 deletions libr/core/cmd_open.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2209,11 +2209,7 @@ static int cmd_open(void *data, const char *input) {
R_LOG_ERROR ("Oops. Cannot open library");
}
} else {
if ('j' == input[1]) {
r_io_plugin_list_json (core->io);
} else {
r_io_plugin_list (core->io);
}
r_core_list_io (core, NULL, input[1]);
}
break;
case 'u': { // "ou"
Expand Down
2 changes: 1 addition & 1 deletion libr/include/r_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ R_API bool cmd_anal_objc(RCore *core, const char *input, bool auto_anal);
R_API void r_core_anal_cc_init(RCore *core);
R_API void r_core_anal_paths(RCore *core, ut64 from, ut64 to, bool followCalls, int followDepth, bool is_json);

R_API void r_core_list_io(RCore *core);
R_API int r_core_list_io(RCore *core, const char *name, int mode);
R_API void r_core_list_lang(RCore *core, int mode);

R_API void r_core_visual_slides(RCore *core, const char *file);
Expand Down
2 changes: 0 additions & 2 deletions libr/include/r_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ R_API void r_io_free(RIO *io);
R_API bool r_io_plugin_init(RIO *io);
R_API bool r_io_plugin_add(RIO *io, RIOPlugin *plugin);
R_API bool r_io_plugin_remove(RIO *io, RIOPlugin *plugin);
R_API int r_io_plugin_list(RIO *io);
R_API int r_io_plugin_list_json(RIO *io);
R_API int r_io_plugin_read(RIODesc *desc, ut8 *buf, int len);
R_API int r_io_plugin_write(RIODesc *desc, const ut8 *buf, int len);
R_API int r_io_plugin_read_at(RIODesc *desc, ut64 addr, ut8 *buf, int len);
Expand Down
2 changes: 1 addition & 1 deletion libr/include/r_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ R_API const char *r_lib_types_get(int idx);
R_API int r_lib_types_get_i(const char *str);

#include <r_util/pj.h>
R_API void r_lib_meta_pj(PJ *pj, RPluginMeta *meta);
R_API void r_lib_meta_pj(PJ *pj, const RPluginMeta *meta);
#endif

#ifdef __cplusplus
Expand Down
83 changes: 0 additions & 83 deletions libr/io/io_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,89 +64,6 @@ R_API RIOPlugin *r_io_plugin_byname(RIO *io, const char *name) {
return NULL;
}

R_API int r_io_plugin_list(RIO *io) {
RIOPlugin *plugin;
SdbListIter *iter;
char str[4];
int n = 0;

ls_foreach (io->plugins, iter, plugin) {
str[0] = 'r';
str[1] = plugin->write ? 'w' : '_';
str[2] = plugin->isdbg ? 'd' : '_';
str[3] = 0;
io->cb_printf ("%s %-8s %s.", str,
r_str_get (plugin->meta.name),
r_str_get (plugin->meta.desc));
if (plugin->uris) {
io->cb_printf (" %s", plugin->uris);
}
io->cb_printf ("\n");
n++;
}
return n;
}

R_API int r_io_plugin_list_json(RIO *io) {
RIOPlugin *plugin;
SdbListIter *iter;
PJ *pj = pj_new ();
if (!pj) {
return 0;
}

char str[4];
int n = 0;
pj_a (pj);
ls_foreach (io->plugins, iter, plugin) {
str[0] = 'r';
str[1] = plugin->write ? 'w' : '_';
str[2] = plugin->isdbg ? 'd' : '_';
str[3] = 0;

pj_o (pj);
pj_ks (pj, "permissions", str);
if (plugin->meta.name) {
pj_ks (pj, "name", plugin->meta.name);
}
if (plugin->meta.desc) {
pj_ks (pj, "description", plugin->meta.desc);
}
if (plugin->meta.license) {
pj_ks (pj, "license", plugin->meta.license);
}
if (plugin->meta.version) {
pj_ks (pj, "version", plugin->meta.version);
}
if (plugin->uris) {
char *uri;
char *uris = strdup (plugin->uris);
RList *plist = r_str_split_list (uris, ",", 0);
RListIter *piter;
pj_k (pj, "uris");
pj_a (pj);
r_list_foreach (plist, piter, uri) {
pj_s (pj, uri);
}
pj_end (pj);
r_list_free (plist);
free (uris);
}
if (plugin->meta.version) {
pj_ks (pj, "version", plugin->meta.version);
}
if (plugin->meta.author) {
pj_ks (pj, "author", plugin->meta.author);
}
pj_end (pj);
n++;
}
pj_end (pj);
io->cb_printf ("%s", pj_string (pj));
pj_free (pj);
return n;
}

R_API int r_io_plugin_read(RIODesc *desc, ut8 *buf, int len) {
if (!buf || !desc || !desc->plugin || len < 1 || !(desc->perm & R_PERM_R)) {
return 0;
Expand Down
5 changes: 3 additions & 2 deletions libr/main/radare2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,10 +1120,11 @@ R_API int r_main_radare2(int argc, const char **argv) {
if (mr.quiet_leak) {
exit (0);
}
const char *arg = argv[opt.ind];
if (mr.json) {
r_io_plugin_list_json (r->io);
r_core_list_io (r, arg, 'j');
} else {
r_io_plugin_list (r->io);
r_core_list_io (r, arg, 0);
}
r_cons_flush ();
mainr2_fini (&mr);
Expand Down
3 changes: 3 additions & 0 deletions libr/main/rafind2.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,14 @@ R_API int r_main_rafind2(int argc, const char **argv) {
}
}
if (ro.pluglist) {
// list search plugins when implemented
#if 0
if (ro.json) {
r_io_plugin_list_json (ro.io);
} else {
r_io_plugin_list (ro.io);
}
#endif
r_cons_flush ();
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion libr/util/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ R_API void r_lib_list(RLib *lib) {
}

// TODO: pj_o should be inside rlibmetapj
R_API void r_lib_meta_pj(PJ *pj, RPluginMeta *meta) {
R_API void r_lib_meta_pj(PJ *pj, const RPluginMeta *meta) {
R_RETURN_IF_FAIL (pj && meta);
if (meta->name) {
pj_ks (pj, "name", meta->name);
Expand Down

0 comments on commit c938df9

Please sign in to comment.