X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-api-so.c;h=408c3f5a87437d271e8a2cd0afc9b83ce8a06e53;hb=779f425daa66d2b0cd431fdc6f7f4ed976cbae15;hp=693385d5aac23cf7c8f9b740f5dc9bd6d51d01b3;hpb=031601a0c5aa944493660f991d66702cc7e52755;p=src%2Fapp-framework-binder.git diff --git a/src/afb-api-so.c b/src/afb-api-so.c index 693385d5..408c3f5a 100644 --- a/src/afb-api-so.c +++ b/src/afb-api-so.c @@ -48,7 +48,7 @@ struct api_so_desc { static int api_timeout = 15; -static const char plugin_register_function[] = "pluginAfbV1Entry"; +static const char plugin_register_function[] = "pluginAfbV1Register"; static void afb_api_so_event_sender_push(struct api_so_desc *desc, const char *name, struct json_object *object) { @@ -141,29 +141,35 @@ static void call(struct api_so_desc *desc, struct afb_req req, struct afb_contex int afb_api_so_add_plugin(const char *path) { + int rc; + void *handle; struct api_so_desc *desc; struct AFB_plugin *(*pluginAfbV1RegisterFct) (const struct AFB_interface *interface); - desc = calloc(1, sizeof *desc); - if (desc == NULL) { - ERROR("out of memory"); - goto error; - } - // This is a loadable library let's check if it's a plugin - desc->handle = dlopen(path, RTLD_NOW | RTLD_LOCAL); - if (desc->handle == NULL) { + rc = 0; + handle = dlopen(path, RTLD_NOW | RTLD_LOCAL); + if (handle == NULL) { ERROR("plugin [%s] not loadable", path); - goto error2; + goto error; } /* retrieves the register function */ - pluginAfbV1RegisterFct = dlsym(desc->handle, plugin_register_function); + pluginAfbV1RegisterFct = dlsym(handle, plugin_register_function); if (!pluginAfbV1RegisterFct) { ERROR("plugin [%s] is not an AFB plugin", path); - goto error3; + goto error2; } INFO("plugin [%s] is a valid AFB plugin", path); + rc = -1; + + /* allocates the description */ + desc = calloc(1, sizeof *desc); + if (desc == NULL) { + ERROR("out of memory"); + goto error2; + } + desc->handle = handle; /* init the interface */ desc->interface.verbosity = 0; @@ -187,6 +193,10 @@ int afb_api_so_add_plugin(const char *path) ERROR("plugin [%s] bad prefix...", path); goto error3; } + if (!afb_apis_is_valid_api_name(desc->plugin->v1.prefix)) { + ERROR("plugin [%s] invalid prefix...", path); + goto error3; + } if (desc->plugin->v1.info == NULL || *desc->plugin->v1.info == 0) { ERROR("plugin [%s] bad description...", path); goto error3; @@ -208,11 +218,11 @@ int afb_api_so_add_plugin(const char *path) return 0; error3: - dlclose(desc->handle); -error2: free(desc); +error2: + dlclose(handle); error: - return -1; + return rc; } static int adddirs(char path[PATH_MAX], size_t end) @@ -256,7 +266,8 @@ static int adddirs(char path[PATH_MAX], size_t end) /* case of files */ if (!strstr(ent.d_name, ".so")) continue; - afb_api_so_add_plugin(path); + if (afb_api_so_add_plugin(path) < 0) + return -1; } } closedir(dir); @@ -305,7 +316,8 @@ int afb_api_so_add_pathset(const char *pathset) p = strsep(&ps, sep); if (!p) return 0; - afb_api_so_add_path(p); - }; + if (afb_api_so_add_path(p) < 0) + return -1; + } }