Unified function to jsonify the plugin meta + more fields ##api

This commit is contained in:
pancake 2024-11-22 17:21:34 +01:00
parent b60135be09
commit b895e9707e
4 changed files with 38 additions and 51 deletions

View File

@ -483,17 +483,7 @@ static int cmd_plugins(void *data, const char *input) {
switch (mode) {
case 'j':
pj_o (pj);
pj_ks (pj, "name", item->meta.name);
pj_ks (pj, "desc", item->meta.desc);
if (item->meta.author) {
pj_ks (pj, "author", item->meta.author);
}
if (item->meta.version) {
pj_ks (pj, "version", item->meta.version);
}
if (item->meta.license) {
pj_ks (pj, "license", item->meta.license);
}
r_lib_meta_pj (pj, &item->meta);
if (item->arch) {
pj_ks (pj, "arch", item->arch);
}
@ -632,19 +622,7 @@ static int cmd_plugins(void *data, const char *input) {
pj_a (pj);
r_list_foreach (core->rcmd->plist, iter, cp) {
pj_o (pj);
if (cp->meta.name) {
pj_ks (pj, "name", cp->meta.name);
}
if (cp->meta.desc) {
pj_ks (pj, "desc", cp->meta.desc);
}
if (cp->meta.version) {
pj_ks (pj, "version", cp->meta.version);
}
pj_ks (pj, "license", cp->meta.license? cp->meta.license: "???");
if (cp->meta.author) {
pj_ks (pj, "author", cp->meta.author);
}
r_lib_meta_pj (pj, &cp->meta);
pj_end (pj);
}
pj_end (pj);

View File

@ -444,16 +444,7 @@ static int cmd_mount(void *data, const char *_input) {
pj_a (pj);
r_list_foreach (core->fs->plugins, iter, plug) {
pj_o (pj);
pj_ks (pj, "name", plug->meta.name);
if (plug->meta.desc) {
pj_ks (pj, "description", plug->meta.desc);
}
if (plug->meta.license) {
pj_ks (pj, "license", plug->meta.license);
}
if (plug->meta.author) {
pj_ks (pj, "author", plug->meta.author);
}
pj_lib_meta_pj (pj, &plug->meta);
pj_end (pj);
}
pj_end (pj);

View File

@ -48,11 +48,11 @@ typedef struct r_plugin_meta_t {
char *author;
char *version;
char *license;
// char *contact // email/mastodon/addr
// char *copyright // 2024-2025 ..?
char *contact; // email/mastodon/addr
char *copyright; // 2024-2025 ..?
RPluginStatus status;
} RPluginMeta;
// rename to RLibPluginMeta ?
// R2_600 discuss rename to RLibPluginMeta ?
/* store list of loaded plugins */
typedef struct r_lib_plugin_t {
@ -151,6 +151,9 @@ R_API int r_lib_close(RLib *lib, const char *file);
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);
#endif
#ifdef __cplusplus

View File

@ -210,21 +210,10 @@ R_API int r_lib_run_handler(RLib *lib, RLibPlugin *plugin, RLibStruct *symbol) {
}
R_API RLibHandler *r_lib_get_handler(RLib *lib, int type) {
#if 1
if (type < 0 || type >= R_LIB_TYPE_LAST) {
return NULL;
}
return lib->handlers_bytype[type];
#else
RListIter *iter;
RLibHandler *h;
r_list_foreach (lib->handlers, iter, h) {
if (h->type == type) {
return h;
}
}
#endif
return NULL;
}
R_API int r_lib_close(RLib *lib, const char *file) {
@ -253,14 +242,14 @@ R_API int r_lib_close(RLib *lib, const char *file) {
}
// delete similar plugin name
r_list_foreach (lib->plugins, iter, p) {
eprintf("similar p->file: %s\n", p->file);
R_LOG_DEBUG ("similar p->file: %s", p->file);
if (strstr (p->file, file)) {
int ret = 0;
if (p->handler && p->handler->destructor) {
ret = p->handler->destructor (p,
p->handler->user, p->data);
}
eprintf("similar deleting: %s\n", p->file);
R_LOG_DEBUG ("similar deleting: %s", p->file);
free (p->file);
r_list_delete (lib->plugins, iter);
{
@ -493,7 +482,7 @@ R_API bool r_lib_add_handler(RLib *lib, int type, const char *desc, LibCB cb, Li
R_API bool r_lib_del_handler(RLib *lib, int type) {
RLibHandler *h = NULL;
RListIter *iter;
#if R2_590
#if R2_600
// XXX slow - delete plugin by name, by filename or by type >? wtf this function is broken
{
bool found;
@ -526,3 +515,29 @@ R_API void r_lib_list(RLib *lib) {
p->dl_handler, p->file);
}
}
// TODO: pj_o should be inside rlibmetapj
R_API void r_lib_meta_pj(PJ *pj, RPluginMeta *meta) {
R_RETURN_IF_FAIL (pj && meta);
if (meta->name) {
pj_ks (pj, "name", meta->name);
}
if (meta->desc) {
pj_ks (pj, "desc", meta->desc);
}
if (meta->copyright) {
pj_ks (pj, "copyright", meta->copyright);
}
if (meta->contact) {
pj_ks (pj, "contact", meta->contact);
}
if (meta->author) {
pj_ks (pj, "author", meta->author);
}
if (meta->version) {
pj_ks (pj, "version", meta->version);
}
if (meta->license) {
pj_ks (pj, "license", meta->license);
}
}