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:
|
||||
* 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.
|
||||
* 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)`
|
||||
|
|
@ -45,6 +45,9 @@ static clixon_plugin_api api = {
|
|||
plugin_start,
|
||||
plugin_exit,
|
||||
NULL, /* auth N/A for backend */
|
||||
NULL, /* cli_prompthook_t */
|
||||
NULL, /* cligen_susp_cb_t */
|
||||
NULL, /* cligen_interrupt_cb_t */
|
||||
plugin_reset,
|
||||
plugin_statedata,
|
||||
transaction_begin,
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ clixon_plugin_reset(clicon_handle h,
|
|||
plgreset_t *resetfn; /* Plugin auth */
|
||||
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)
|
||||
continue;
|
||||
if ((retval = resetfn(h, db)) < 0) {
|
||||
|
|
@ -150,7 +150,7 @@ clixon_plugin_statedata(clicon_handle h,
|
|||
clicon_err(OE_CFG, ENOENT, "XML tree expected");
|
||||
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)
|
||||
continue;
|
||||
if ((x = xml_new("config", NULL, NULL)) == NULL)
|
||||
|
|
@ -246,7 +246,7 @@ plugin_transaction_begin(clicon_handle h,
|
|||
clixon_plugin *cp = NULL;
|
||||
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)
|
||||
continue;
|
||||
if ((retval = fn(h, (transaction_data)td)) < 0){
|
||||
|
|
@ -274,7 +274,7 @@ plugin_transaction_validate(clicon_handle h,
|
|||
clixon_plugin *cp = NULL;
|
||||
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)
|
||||
continue;
|
||||
if ((retval = fn(h, (transaction_data)td)) < 0){
|
||||
|
|
@ -303,7 +303,7 @@ plugin_transaction_complete(clicon_handle h,
|
|||
clixon_plugin *cp = NULL;
|
||||
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)
|
||||
continue;
|
||||
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_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)
|
||||
continue;
|
||||
if ((retval = fn(h, (transaction_data)td)) < 0){
|
||||
|
|
@ -379,7 +379,7 @@ plugin_transaction_commit(clicon_handle h,
|
|||
trans_cb_t *fn;
|
||||
int i=0;
|
||||
|
||||
while ((cp = plugin_each(h, cp)) != NULL) {
|
||||
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||
i++;
|
||||
if ((fn = cp->cp_api.ca_trans_commit) == NULL)
|
||||
continue;
|
||||
|
|
@ -409,7 +409,7 @@ plugin_transaction_end(clicon_handle h,
|
|||
clixon_plugin *cp = NULL;
|
||||
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)
|
||||
continue;
|
||||
if ((retval = fn(h, (transaction_data)td)) < 0){
|
||||
|
|
@ -436,7 +436,7 @@ plugin_transaction_abort(clicon_handle h,
|
|||
clixon_plugin *cp = NULL;
|
||||
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)
|
||||
continue;
|
||||
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");
|
||||
|
||||
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;
|
||||
if (handle == NULL){
|
||||
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 */
|
||||
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 (cli_susp_hook(h, fns) < 0)
|
||||
goto done;
|
||||
|
|
@ -589,7 +589,7 @@ clicon_cliread(clicon_handle h)
|
|||
mode = stx->stx_active_mode;
|
||||
/* Get prompt from plugin callback? */
|
||||
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)
|
||||
continue;
|
||||
pfmt = fn(h, mode->csm_name);
|
||||
|
|
|
|||
|
|
@ -50,13 +50,19 @@
|
|||
/* Dynamicically loadable plugin object handle. @see return value of dlopen(3) */
|
||||
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)(
|
||||
clicon_handle h, /* Clicon handle */
|
||||
cxobj *xn, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Return xml tree, eg <rpc-reply>..., <rpc-error.. */
|
||||
void *arg, /* Domain specific arg, ec client-entry */
|
||||
void *regarg /* User argument given at rpc_callback_register() */
|
||||
clicon_handle h,
|
||||
cxobj *xn,
|
||||
cbuf *cbret,
|
||||
void *arg,
|
||||
void *regarg
|
||||
);
|
||||
|
||||
/*
|
||||
|
|
@ -155,11 +161,11 @@ typedef struct clixon_plugin clixon_plugin;
|
|||
*/
|
||||
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);
|
||||
|
||||
|
|
@ -171,6 +177,7 @@ int clixon_plugin_auth(clicon_handle h, void *arg);
|
|||
|
||||
/* rpc callback API */
|
||||
int rpc_callback_register(clicon_handle h, clicon_rpc_cb cb, void *arg, char *tag);
|
||||
|
||||
int rpc_callback_delete_all(void);
|
||||
|
||||
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
|
||||
* @code
|
||||
* clicon_plugin *cp = NULL;
|
||||
* while ((cp = plugin_each(h, cp)) != NULL) {
|
||||
* while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||
* ...
|
||||
* }
|
||||
* @endcode
|
||||
* @note Not optimized, alwasy iterates from the start of the list
|
||||
*/
|
||||
clixon_plugin *
|
||||
plugin_each(clicon_handle h,
|
||||
clixon_plugin *cpprev)
|
||||
clixon_plugin_each(clicon_handle h,
|
||||
clixon_plugin *cpprev)
|
||||
{
|
||||
int i;
|
||||
clixon_plugin *cp;
|
||||
|
|
@ -114,16 +114,16 @@ plugin_each(clicon_handle h,
|
|||
* @param[in] plugin previous plugin, or NULL on init
|
||||
* @code
|
||||
* clicon_plugin *cp = NULL;
|
||||
* while ((cp = plugin_each_revert(h, cp, nr)) != NULL) {
|
||||
* while ((cp = clixon_plugin_each_revert(h, cp, nr)) != NULL) {
|
||||
* ...
|
||||
* }
|
||||
* @endcode
|
||||
* @note Not optimized, alwasy iterates from the start of the list
|
||||
*/
|
||||
clixon_plugin *
|
||||
plugin_each_revert(clicon_handle h,
|
||||
clixon_plugin *cpprev,
|
||||
int nr)
|
||||
clixon_plugin_each_revert(clicon_handle h,
|
||||
clixon_plugin *cpprev,
|
||||
int nr)
|
||||
{
|
||||
int i;
|
||||
clixon_plugin *cp;
|
||||
|
|
@ -151,8 +151,8 @@ plugin_each_revert(clicon_handle h,
|
|||
* @retval NULL Not found
|
||||
*/
|
||||
clixon_plugin *
|
||||
plugin_find(clicon_handle h,
|
||||
char *name)
|
||||
clixon_plugin_find(clicon_handle h,
|
||||
char *name)
|
||||
{
|
||||
int i;
|
||||
clixon_plugin *cp = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue