ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -I. -DUCI_PREFIX="${CMAKE_INSTALL_PREFIX}")
-OPTION(UCI_PLUGIN_SUPPORT "plugin support" ON)
OPTION(UCI_DEBUG "debugging support" OFF)
OPTION(UCI_DEBUG_TYPECAST "typecast debugging support" OFF)
-OPTION(BUILD_LUA "build Lua plugin" ON)
+OPTION(BUILD_LUA "build Lua binding" ON)
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/uci_config.h.in ${CMAKE_SOURCE_DIR}/uci_config.h )
CLI_FLAG_NOCOMMIT = (1 << 2),
CLI_FLAG_BATCH = (1 << 3),
CLI_FLAG_SHOW_EXT = (1 << 4),
- CLI_FLAG_NOPLUGINS= (1 << 5),
} flags;
static FILE *input;
"\t-c <path> set the search path for config files (default: /etc/config)\n"
"\t-d <str> set the delimiter for list values in uci show\n"
"\t-f <file> use <file> as input instead of stdin\n"
- "\t-L do not load any plugins\n"
"\t-m when importing, merge data into an existing package\n"
"\t-n name unnamed sections on export (default)\n"
"\t-N don't name unnamed sections\n"
return 1;
}
break;
- case 'L':
- flags |= CLI_FLAG_NOPLUGINS;
- break;
case 'm':
flags |= CLI_FLAG_MERGE;
break;
return 0;
}
- if (!(flags & CLI_FLAG_NOPLUGINS))
- uci_load_plugins(ctx, NULL);
-
ret = uci_cmd(argc - 1, argv + 1);
if (input != stdin)
fclose(input);
[UCI_ERR_UNKNOWN] = "Unknown error",
};
-static void uci_unload_plugin(struct uci_context *ctx, struct uci_plugin *p);
-
#include "uci_internal.h"
#include "list.c"
uci_list_init(&ctx->delta_path);
uci_list_init(&ctx->backends);
uci_list_init(&ctx->hooks);
- uci_list_init(&ctx->plugins);
ctx->flags = UCI_FLAG_STRICT | UCI_FLAG_SAVED_DELTA;
ctx->confdir = (char *) uci_confdir;
uci_free_element(e);
}
UCI_TRAP_RESTORE(ctx);
- uci_foreach_element_safe(&ctx->root, tmp, e) {
- uci_unload_plugin(ctx, uci_to_plugin(e));
- }
free(ctx);
ignore:
return 0;
}
-#ifdef UCI_PLUGIN_SUPPORT
-
-__plugin int uci_add_backend(struct uci_context *ctx, struct uci_backend *b)
-{
- struct uci_element *e;
- UCI_HANDLE_ERR(ctx);
-
- e = uci_lookup_list(&ctx->backends, b->e.name);
- if (e)
- UCI_THROW(ctx, UCI_ERR_DUPLICATE);
-
- e = uci_malloc(ctx, sizeof(struct uci_backend));
- memcpy(e, b, sizeof(struct uci_backend));
-
- uci_list_add(&ctx->backends, &e->list);
- return 0;
-}
-
-__plugin int uci_del_backend(struct uci_context *ctx, struct uci_backend *b)
-{
- struct uci_element *e, *tmp;
-
- UCI_HANDLE_ERR(ctx);
-
- e = uci_lookup_list(&ctx->backends, b->e.name);
- if (!e || uci_to_backend(e)->ptr != b->ptr)
- UCI_THROW(ctx, UCI_ERR_NOTFOUND);
- b = uci_to_backend(e);
-
- if (ctx->backend && ctx->backend->ptr == b->ptr)
- ctx->backend = &uci_file_backend;
-
- uci_foreach_element_safe(&ctx->root, tmp, e) {
- struct uci_package *p = uci_to_package(e);
-
- if (!p->backend)
- continue;
-
- if (p->backend->ptr == b->ptr)
- UCI_INTERNAL(uci_unload, ctx, p);
- }
-
- uci_list_del(&b->e.list);
- free(b);
-
- return 0;
-}
-
-#endif
-
int uci_set_backend(struct uci_context *ctx, const char *name)
{
struct uci_element *e;
}
return UCI_ERR_NOTFOUND;
}
-
-int uci_load_plugin(struct uci_context *ctx, const char *filename)
-{
- struct uci_plugin *p;
- const struct uci_plugin_ops *ops;
- void *dlh;
-
- UCI_HANDLE_ERR(ctx);
- dlh = dlopen(filename, RTLD_GLOBAL|RTLD_NOW);
- if (!dlh)
- UCI_THROW(ctx, UCI_ERR_NOTFOUND);
-
- ops = dlsym(dlh, "uci_plugin");
- if (!ops || !ops->attach || (ops->attach(ctx) != 0)) {
- if (!ops)
- fprintf(stderr, "No ops\n");
- else if (!ops->attach)
- fprintf(stderr, "No attach\n");
- else
- fprintf(stderr, "Other weirdness\n");
- dlclose(dlh);
- UCI_THROW(ctx, UCI_ERR_INVAL);
- }
-
- p = uci_alloc_element(ctx, plugin, filename, 0);
- p->dlh = dlh;
- p->ops = ops;
- uci_list_add(&ctx->plugins, &p->e.list);
-
- return 0;
-}
-
-static void uci_unload_plugin(struct uci_context *ctx, struct uci_plugin *p)
-{
- if (p->ops->detach)
- p->ops->detach(ctx);
- dlclose(p->dlh);
- uci_free_element(&p->e);
-}
-
-int uci_load_plugins(struct uci_context *ctx, const char *pattern)
-{
- glob_t gl;
- int i;
-
- if (!pattern)
- pattern = UCI_PREFIX "/lib/uci_*.so";
-
- memset(&gl, 0, sizeof(gl));
- glob(pattern, 0, NULL, &gl);
- for (i = 0; i < gl.gl_pathc; i++)
- uci_load_plugin(ctx, gl.gl_pathv[i]);
-
- return 0;
-}
uci_free_element(&s->e);
}
-__plugin struct uci_package *
+__private struct uci_package *
uci_alloc_package(struct uci_context *ctx, const char *name)
{
struct uci_package *p;
return uci_push_status(L, ctx, false);
}
-static int
-uci_lua_load_plugins(lua_State *L)
-{
- struct uci_context *ctx;
- int offset = 0;
- const char *str = NULL;
-
- ctx = find_context(L, &offset);
- if (lua_isstring(L, -1))
- str = lua_tostring(L, -1);
- uci_load_plugins(ctx, str);
- return uci_push_status(L, ctx, false);
-}
-
static int
uci_lua_set_savedir(lua_State *L)
{
{ "foreach", uci_lua_foreach },
{ "add_history", uci_lua_add_delta },
{ "add_delta", uci_lua_add_delta },
- { "load_plugins", uci_lua_load_plugins },
{ "get_confdir", uci_lua_get_confdir },
{ "set_confdir", uci_lua_set_confdir },
{ "get_savedir", uci_lua_get_savedir },
};
struct uci_ptr;
-struct uci_plugin;
struct uci_hook_ops;
struct uci_element;
struct uci_package;
*/
extern int uci_remove_hook(struct uci_context *ctx, const struct uci_hook_ops *ops);
-/**
- * uci_load_plugin: load an uci plugin
- * @ctx: uci context
- * @filename: path to the uci plugin
- *
- * NB: plugin will be unloaded automatically when the context is freed
- */
-int uci_load_plugin(struct uci_context *ctx, const char *filename);
-
-/**
- * uci_load_plugins: load all uci plugins from a directory
- * @ctx: uci context
- * @pattern: pattern of uci plugin files (optional)
- *
- * if pattern is NULL, then uci_load_plugins will call uci_load_plugin
- * for uci_*.so in <prefix>/lib/
- */
-int uci_load_plugins(struct uci_context *ctx, const char *pattern);
-
/**
* uci_parse_ptr: parse a uci string into a uci_ptr
* @ctx: uci context
UCI_TYPE_BACKEND = 6,
UCI_TYPE_ITEM = 7,
UCI_TYPE_HOOK = 8,
- UCI_TYPE_PLUGIN = 9,
};
enum uci_option_type {
int bufsz;
struct uci_list hooks;
- struct uci_list plugins;
};
struct uci_package
const struct uci_hook_ops *ops;
};
-struct uci_plugin_ops
-{
- int (*attach)(struct uci_context *ctx);
- void (*detach)(struct uci_context *ctx);
-};
-
-struct uci_plugin
-{
- struct uci_element e;
- const struct uci_plugin_ops *ops;
- void *dlh;
-};
-
struct uci_parse_option {
const char *name;
enum uci_option_type type;
#define uci_type_section UCI_TYPE_SECTION
#define uci_type_option UCI_TYPE_OPTION
#define uci_type_hook UCI_TYPE_HOOK
-#define uci_type_plugin UCI_TYPE_PLUGIN
/* element typecasting */
#ifdef UCI_DEBUG_TYPECAST
[uci_type_section] = "section",
[uci_type_option] = "option",
[uci_type_hook] = "hook",
- [uci_type_plugin] = "plugin",
};
static void uci_typecast_error(int from, int to)
BUILD_CAST(section)
BUILD_CAST(option)
BUILD_CAST(hook)
-BUILD_CAST(plugin)
#else
#define uci_to_backend(ptr) container_of(ptr, struct uci_backend, e)
#define uci_to_section(ptr) container_of(ptr, struct uci_section, e)
#define uci_to_option(ptr) container_of(ptr, struct uci_option, e)
#define uci_to_hook(ptr) container_of(ptr, struct uci_hook, e)
-#define uci_to_plugin(ptr) container_of(ptr, struct uci_plugin, e)
#endif
/**
-#cmakedefine UCI_PLUGIN_SUPPORT 1
#cmakedefine UCI_DEBUG 1
#cmakedefine UCI_DEBUG_TYPECAST 1
#define __private __attribute__((visibility("hidden")))
#define __public
-#ifdef UCI_PLUGIN_SUPPORT
-#define __plugin extern
-#else
-#define __plugin __private
-#endif
struct uci_parse_context
{
extern const char *uci_confdir;
extern const char *uci_savedir;
-__plugin void *uci_malloc(struct uci_context *ctx, size_t size);
-__plugin void *uci_realloc(struct uci_context *ctx, void *ptr, size_t size);
-__plugin char *uci_strdup(struct uci_context *ctx, const char *str);
-__plugin bool uci_validate_str(const char *str, bool name);
-__plugin void uci_add_delta(struct uci_context *ctx, struct uci_list *list, int cmd, const char *section, const char *option, const char *value);
-__plugin void uci_free_delta(struct uci_delta *h);
-__plugin struct uci_package *uci_alloc_package(struct uci_context *ctx, const char *name);
+__private void *uci_malloc(struct uci_context *ctx, size_t size);
+__private void *uci_realloc(struct uci_context *ctx, void *ptr, size_t size);
+__private char *uci_strdup(struct uci_context *ctx, const char *str);
+__private bool uci_validate_str(const char *str, bool name);
+__private void uci_add_delta(struct uci_context *ctx, struct uci_list *list, int cmd, const char *section, const char *option, const char *value);
+__private void uci_free_delta(struct uci_delta *h);
+__private struct uci_package *uci_alloc_package(struct uci_context *ctx, const char *name);
__private FILE *uci_open_stream(struct uci_context *ctx, const char *filename, int pos, bool write, bool create);
__private void uci_close_stream(FILE *stream);
*
* The default backend is "file", which uses /etc/config for config storage
*/
-__plugin int uci_add_backend(struct uci_context *ctx, struct uci_backend *b);
+__private int uci_add_backend(struct uci_context *ctx, struct uci_backend *b);
/**
* uci_add_backend: add an extra backend
*
* The default backend is "file", which uses /etc/config for config storage
*/
-__plugin int uci_del_backend(struct uci_context *ctx, struct uci_backend *b);
+__private int uci_del_backend(struct uci_context *ctx, struct uci_backend *b);
#endif
#define UCI_BACKEND(_var, _name, ...) \
#include "uci.h"
#include "uci_internal.h"
-__plugin void *uci_malloc(struct uci_context *ctx, size_t size)
+__private void *uci_malloc(struct uci_context *ctx, size_t size)
{
void *ptr;
return ptr;
}
-__plugin void *uci_realloc(struct uci_context *ctx, void *ptr, size_t size)
+__private void *uci_realloc(struct uci_context *ctx, void *ptr, size_t size)
{
ptr = realloc(ptr, size);
if (!ptr)
return ptr;
}
-__plugin char *uci_strdup(struct uci_context *ctx, const char *str)
+__private char *uci_strdup(struct uci_context *ctx, const char *str)
{
char *ptr;
* for names, only alphanum and _ is allowed (shell compatibility)
* for types, we allow more characters
*/
-__plugin bool uci_validate_str(const char *str, bool name)
+__private bool uci_validate_str(const char *str, bool name)
{
if (!*str)
return false;