renamed plugin_find/each to clixon_plugin_find/each
This commit is contained in:
parent
2e00411621
commit
0907574acf
5 changed files with 41 additions and 31 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
### Major changes:
|
### Major changes:
|
||||||
* Restructure and more generic plugin API (cli,backend,restconf,netconf) as preparation for authorization RFC8341
|
* Restructure and more generic plugin API (cli,backend,restconf,netconf) as preparation for authorization RFC8341
|
||||||
* New design with single `clixon_plugin_init()` returning an api struct with function pointers, see example below. This means that there are no hardcoded plugin functions, except `clixon_plugin_init()`.
|
* New design change `plugin_init()` to a single `clixon_plugin_init()` returning an api struct with function pointers, see example below. This means that there are no hardcoded plugin functions, except `clixon_plugin_init()`.
|
||||||
* Plugin RPC callback interface have been unified between backend, netconf and restconf.
|
* Plugin RPC callback interface have been unified between backend, netconf and restconf.
|
||||||
* Backend RPC register callback function (Netconf RPC or restconf operation POST) has been changed from: `backend_rpc_cb_register()` to `rpc_callback_register()`
|
* Backend RPC register callback function (Netconf RPC or restconf operation POST) has been changed from: `backend_rpc_cb_register()` to `rpc_callback_register()`
|
||||||
* Backend RPC callback signature has been changed from: `int cb(clicon_handle h, cxobj *xe, struct client_entry *ce, cbuf *cbret, void *arg)` has been changed to : `int cb(clicon_handle h, cxobj *xe, struct client_entry *ce, cbuf *cbret, void *arg)`
|
* Backend RPC callback signature has been changed from: `int cb(clicon_handle h, cxobj *xe, struct client_entry *ce, cbuf *cbret, void *arg)` has been changed to : `int cb(clicon_handle h, cxobj *xe, struct client_entry *ce, cbuf *cbret, void *arg)`
|
||||||
|
|
@ -45,6 +45,9 @@ static clixon_plugin_api api = {
|
||||||
plugin_start,
|
plugin_start,
|
||||||
plugin_exit,
|
plugin_exit,
|
||||||
NULL, /* auth N/A for backend */
|
NULL, /* auth N/A for backend */
|
||||||
|
NULL, /* cli_prompthook_t */
|
||||||
|
NULL, /* cligen_susp_cb_t */
|
||||||
|
NULL, /* cligen_interrupt_cb_t */
|
||||||
plugin_reset,
|
plugin_reset,
|
||||||
plugin_statedata,
|
plugin_statedata,
|
||||||
transaction_begin,
|
transaction_begin,
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ clixon_plugin_reset(clicon_handle h,
|
||||||
plgreset_t *resetfn; /* Plugin auth */
|
plgreset_t *resetfn; /* Plugin auth */
|
||||||
int retval = 1;
|
int retval = 1;
|
||||||
|
|
||||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
if ((resetfn = cp->cp_api.ca_reset) == NULL)
|
if ((resetfn = cp->cp_api.ca_reset) == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((retval = resetfn(h, db)) < 0) {
|
if ((retval = resetfn(h, db)) < 0) {
|
||||||
|
|
@ -150,7 +150,7 @@ clixon_plugin_statedata(clicon_handle h,
|
||||||
clicon_err(OE_CFG, ENOENT, "XML tree expected");
|
clicon_err(OE_CFG, ENOENT, "XML tree expected");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
if ((fn = cp->cp_api.ca_statedata) == NULL)
|
if ((fn = cp->cp_api.ca_statedata) == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((x = xml_new("config", NULL, NULL)) == NULL)
|
if ((x = xml_new("config", NULL, NULL)) == NULL)
|
||||||
|
|
@ -246,7 +246,7 @@ plugin_transaction_begin(clicon_handle h,
|
||||||
clixon_plugin *cp = NULL;
|
clixon_plugin *cp = NULL;
|
||||||
trans_cb_t *fn;
|
trans_cb_t *fn;
|
||||||
|
|
||||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
if ((fn = cp->cp_api.ca_trans_begin) == NULL)
|
if ((fn = cp->cp_api.ca_trans_begin) == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((retval = fn(h, (transaction_data)td)) < 0){
|
if ((retval = fn(h, (transaction_data)td)) < 0){
|
||||||
|
|
@ -274,7 +274,7 @@ plugin_transaction_validate(clicon_handle h,
|
||||||
clixon_plugin *cp = NULL;
|
clixon_plugin *cp = NULL;
|
||||||
trans_cb_t *fn;
|
trans_cb_t *fn;
|
||||||
|
|
||||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
if ((fn = cp->cp_api.ca_trans_validate) == NULL)
|
if ((fn = cp->cp_api.ca_trans_validate) == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((retval = fn(h, (transaction_data)td)) < 0){
|
if ((retval = fn(h, (transaction_data)td)) < 0){
|
||||||
|
|
@ -303,7 +303,7 @@ plugin_transaction_complete(clicon_handle h,
|
||||||
clixon_plugin *cp = NULL;
|
clixon_plugin *cp = NULL;
|
||||||
trans_cb_t *fn;
|
trans_cb_t *fn;
|
||||||
|
|
||||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
if ((fn = cp->cp_api.ca_trans_complete) == NULL)
|
if ((fn = cp->cp_api.ca_trans_complete) == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((retval = fn(h, (transaction_data)td)) < 0){
|
if ((retval = fn(h, (transaction_data)td)) < 0){
|
||||||
|
|
@ -349,7 +349,7 @@ plugin_transaction_revert(clicon_handle h,
|
||||||
tr.td_scvec = td->td_tcvec;
|
tr.td_scvec = td->td_tcvec;
|
||||||
tr.td_tcvec = td->td_scvec;
|
tr.td_tcvec = td->td_scvec;
|
||||||
|
|
||||||
while ((cp = plugin_each_revert(h, cp, nr)) != NULL) {
|
while ((cp = clixon_plugin_each_revert(h, cp, nr)) != NULL) {
|
||||||
if ((fn = cp->cp_api.ca_trans_commit) == NULL)
|
if ((fn = cp->cp_api.ca_trans_commit) == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((retval = fn(h, (transaction_data)td)) < 0){
|
if ((retval = fn(h, (transaction_data)td)) < 0){
|
||||||
|
|
@ -379,7 +379,7 @@ plugin_transaction_commit(clicon_handle h,
|
||||||
trans_cb_t *fn;
|
trans_cb_t *fn;
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
i++;
|
i++;
|
||||||
if ((fn = cp->cp_api.ca_trans_commit) == NULL)
|
if ((fn = cp->cp_api.ca_trans_commit) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -409,7 +409,7 @@ plugin_transaction_end(clicon_handle h,
|
||||||
clixon_plugin *cp = NULL;
|
clixon_plugin *cp = NULL;
|
||||||
trans_cb_t *fn;
|
trans_cb_t *fn;
|
||||||
|
|
||||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
if ((fn = cp->cp_api.ca_trans_end) == NULL)
|
if ((fn = cp->cp_api.ca_trans_end) == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((retval = fn(h, (transaction_data)td)) < 0){
|
if ((retval = fn(h, (transaction_data)td)) < 0){
|
||||||
|
|
@ -436,7 +436,7 @@ plugin_transaction_abort(clicon_handle h,
|
||||||
clixon_plugin *cp = NULL;
|
clixon_plugin *cp = NULL;
|
||||||
trans_cb_t *fn;
|
trans_cb_t *fn;
|
||||||
|
|
||||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
if ((fn = cp->cp_api.ca_trans_abort) == NULL)
|
if ((fn = cp->cp_api.ca_trans_abort) == NULL)
|
||||||
continue;
|
continue;
|
||||||
fn(h, (transaction_data)td); /* dont abort on error */
|
fn(h, (transaction_data)td); /* dont abort on error */
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ cli_load_syntax(clicon_handle h,
|
||||||
mode = cvec_find_str(cvv, "CLICON_MODE");
|
mode = cvec_find_str(cvv, "CLICON_MODE");
|
||||||
|
|
||||||
if (plgnam != NULL) { /* Find plugin for callback resolving */
|
if (plgnam != NULL) { /* Find plugin for callback resolving */
|
||||||
if ((cp = plugin_find(h, plgnam)) != NULL)
|
if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
|
||||||
handle = cp->cp_handle;
|
handle = cp->cp_handle;
|
||||||
if (handle == NULL){
|
if (handle == NULL){
|
||||||
clicon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s\n",
|
clicon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s\n",
|
||||||
|
|
@ -379,7 +379,7 @@ cli_syntax_load (clicon_handle h)
|
||||||
|
|
||||||
/* Set susp and interrupt callbacks into CLIgen */
|
/* Set susp and interrupt callbacks into CLIgen */
|
||||||
cp = NULL;
|
cp = NULL;
|
||||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
if (fns==NULL && (fns = cp->cp_api.ca_suspend) != NULL)
|
if (fns==NULL && (fns = cp->cp_api.ca_suspend) != NULL)
|
||||||
if (cli_susp_hook(h, fns) < 0)
|
if (cli_susp_hook(h, fns) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -589,7 +589,7 @@ clicon_cliread(clicon_handle h)
|
||||||
mode = stx->stx_active_mode;
|
mode = stx->stx_active_mode;
|
||||||
/* Get prompt from plugin callback? */
|
/* Get prompt from plugin callback? */
|
||||||
cp = NULL;
|
cp = NULL;
|
||||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
if ((fn = cp->cp_api.ca_prompt) == NULL)
|
if ((fn = cp->cp_api.ca_prompt) == NULL)
|
||||||
continue;
|
continue;
|
||||||
pfmt = fn(h, mode->csm_name);
|
pfmt = fn(h, mode->csm_name);
|
||||||
|
|
|
||||||
|
|
@ -50,13 +50,19 @@
|
||||||
/* Dynamicically loadable plugin object handle. @see return value of dlopen(3) */
|
/* Dynamicically loadable plugin object handle. @see return value of dlopen(3) */
|
||||||
typedef void *plghndl_t;
|
typedef void *plghndl_t;
|
||||||
|
|
||||||
/* Registered RPC callback function */
|
/*! Registered RPC callback function
|
||||||
|
* @param[in] h Clicon handle
|
||||||
|
* @param[in] xn Request: <rpc><xn></rpc>
|
||||||
|
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
|
||||||
|
* @param[in] arg Domain specific arg, ec client-entry or FCGX_Request
|
||||||
|
* @param[in] regarg User argument given at rpc_callback_register()
|
||||||
|
*/
|
||||||
typedef int (*clicon_rpc_cb)(
|
typedef int (*clicon_rpc_cb)(
|
||||||
clicon_handle h, /* Clicon handle */
|
clicon_handle h,
|
||||||
cxobj *xn, /* Request: <rpc><xn></rpc> */
|
cxobj *xn,
|
||||||
cbuf *cbret, /* Return xml tree, eg <rpc-reply>..., <rpc-error.. */
|
cbuf *cbret,
|
||||||
void *arg, /* Domain specific arg, ec client-entry */
|
void *arg,
|
||||||
void *regarg /* User argument given at rpc_callback_register() */
|
void *regarg
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -155,11 +161,11 @@ typedef struct clixon_plugin clixon_plugin;
|
||||||
*/
|
*/
|
||||||
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
|
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
|
||||||
|
|
||||||
clixon_plugin *plugin_each(clicon_handle h, clixon_plugin *cpprev);
|
clixon_plugin *clixon_plugin_each(clicon_handle h, clixon_plugin *cpprev);
|
||||||
|
|
||||||
clixon_plugin *plugin_each_revert(clicon_handle h, clixon_plugin *cpprev, int nr);
|
clixon_plugin *clixon_plugin_each_revert(clicon_handle h, clixon_plugin *cpprev, int nr);
|
||||||
|
|
||||||
clixon_plugin *plugin_find(clicon_handle h, char *name);
|
clixon_plugin *clixon_plugin_find(clicon_handle h, char *name);
|
||||||
|
|
||||||
int clixon_plugins_load(clicon_handle h, char *function, char *dir);
|
int clixon_plugins_load(clicon_handle h, char *function, char *dir);
|
||||||
|
|
||||||
|
|
@ -171,6 +177,7 @@ int clixon_plugin_auth(clicon_handle h, void *arg);
|
||||||
|
|
||||||
/* rpc callback API */
|
/* rpc callback API */
|
||||||
int rpc_callback_register(clicon_handle h, clicon_rpc_cb cb, void *arg, char *tag);
|
int rpc_callback_register(clicon_handle h, clicon_rpc_cb cb, void *arg, char *tag);
|
||||||
|
|
||||||
int rpc_callback_delete_all(void);
|
int rpc_callback_delete_all(void);
|
||||||
|
|
||||||
int rpc_callback_call(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg);
|
int rpc_callback_call(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg);
|
||||||
|
|
|
||||||
|
|
@ -76,15 +76,15 @@ static int _clixon_nplugins = 0; /* Number of plugins */
|
||||||
* @param[in] plugin previous plugin, or NULL on init
|
* @param[in] plugin previous plugin, or NULL on init
|
||||||
* @code
|
* @code
|
||||||
* clicon_plugin *cp = NULL;
|
* clicon_plugin *cp = NULL;
|
||||||
* while ((cp = plugin_each(h, cp)) != NULL) {
|
* while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
* @note Not optimized, alwasy iterates from the start of the list
|
* @note Not optimized, alwasy iterates from the start of the list
|
||||||
*/
|
*/
|
||||||
clixon_plugin *
|
clixon_plugin *
|
||||||
plugin_each(clicon_handle h,
|
clixon_plugin_each(clicon_handle h,
|
||||||
clixon_plugin *cpprev)
|
clixon_plugin *cpprev)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
clixon_plugin *cp;
|
clixon_plugin *cp;
|
||||||
|
|
@ -114,16 +114,16 @@ plugin_each(clicon_handle h,
|
||||||
* @param[in] plugin previous plugin, or NULL on init
|
* @param[in] plugin previous plugin, or NULL on init
|
||||||
* @code
|
* @code
|
||||||
* clicon_plugin *cp = NULL;
|
* clicon_plugin *cp = NULL;
|
||||||
* while ((cp = plugin_each_revert(h, cp, nr)) != NULL) {
|
* while ((cp = clixon_plugin_each_revert(h, cp, nr)) != NULL) {
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
* @note Not optimized, alwasy iterates from the start of the list
|
* @note Not optimized, alwasy iterates from the start of the list
|
||||||
*/
|
*/
|
||||||
clixon_plugin *
|
clixon_plugin *
|
||||||
plugin_each_revert(clicon_handle h,
|
clixon_plugin_each_revert(clicon_handle h,
|
||||||
clixon_plugin *cpprev,
|
clixon_plugin *cpprev,
|
||||||
int nr)
|
int nr)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
clixon_plugin *cp;
|
clixon_plugin *cp;
|
||||||
|
|
@ -151,8 +151,8 @@ plugin_each_revert(clicon_handle h,
|
||||||
* @retval NULL Not found
|
* @retval NULL Not found
|
||||||
*/
|
*/
|
||||||
clixon_plugin *
|
clixon_plugin *
|
||||||
plugin_find(clicon_handle h,
|
clixon_plugin_find(clicon_handle h,
|
||||||
char *name)
|
char *name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
clixon_plugin *cp = NULL;
|
clixon_plugin *cp = NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue