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)`
* Frontend netconf and restconf plugins can register callbacks as well with same API as backends.
This commit is contained in:
parent
7a4371e76f
commit
d541c49c6f
20 changed files with 323 additions and 229 deletions
|
|
@ -909,10 +909,10 @@ from_client_msg(clicon_handle h,
|
|||
}
|
||||
else{
|
||||
clicon_err_reset();
|
||||
if ((ret = backend_rpc_cb_call(h, xe, ce, cbret)) < 0){
|
||||
if ((ret = rpc_callback_call(h, xe, cbret, ce)) < 0){
|
||||
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
|
||||
goto done;
|
||||
clicon_log(LOG_NOTICE, "%s Error in backend_rpc_call:%s", __FUNCTION__, xml_name(xe));
|
||||
clicon_log(LOG_NOTICE, "%s Error in rpc_callback_call:%s", __FUNCTION__, xml_name(xe));
|
||||
goto reply; /* Dont quit here on user callbacks */
|
||||
}
|
||||
if (ret == 0){ /* not handled by callback */
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ backend_terminate(clicon_handle h)
|
|||
yspec_free(yspec);
|
||||
clixon_plugin_exit(h);
|
||||
/* Delete all backend plugin RPC callbacks */
|
||||
backend_rpc_cb_delete_all();
|
||||
rpc_callback_delete_all();
|
||||
if (pidfile)
|
||||
unlink(pidfile);
|
||||
if (sockpath)
|
||||
|
|
|
|||
|
|
@ -430,110 +430,3 @@ subscription_each(clicon_handle h,
|
|||
return hs;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
* Backend netconf rpc callbacks
|
||||
*/
|
||||
typedef struct {
|
||||
qelem_t rc_qelem; /* List header */
|
||||
backend_rpc_cb rc_callback; /* RPC Callback */
|
||||
void *rc_arg; /* Application specific argument to cb */
|
||||
char *rc_tag; /* Xml tag when matched, callback called */
|
||||
} backend_rpc_cb_entry;
|
||||
|
||||
/* List of backend rpc callback entries */
|
||||
static backend_rpc_cb_entry *rpc_cb_list = NULL;
|
||||
|
||||
/*! Register netconf backend rpc callback
|
||||
* Called from plugin to register a callback for a specific netconf XML tag.
|
||||
*
|
||||
* @param[in] h clicon handle
|
||||
* @param[in] cb, Callback called
|
||||
* @param[in] arg, Arg to send to callback
|
||||
* @param[in] tag Xml tag when callback is made
|
||||
* @see backend_rpc_cb_call
|
||||
*/
|
||||
int
|
||||
backend_rpc_cb_register(clicon_handle h,
|
||||
backend_rpc_cb cb,
|
||||
void *arg,
|
||||
char *tag)
|
||||
{
|
||||
backend_rpc_cb_entry *rc;
|
||||
|
||||
if ((rc = malloc(sizeof(backend_rpc_cb_entry))) == NULL) {
|
||||
clicon_err(OE_DB, errno, "malloc: %s", strerror(errno));
|
||||
goto catch;
|
||||
}
|
||||
memset (rc, 0, sizeof (*rc));
|
||||
rc->rc_callback = cb;
|
||||
rc->rc_arg = arg;
|
||||
rc->rc_tag = strdup(tag); /* XXX strdup memleak */
|
||||
INSQ(rc, rpc_cb_list);
|
||||
return 0;
|
||||
catch:
|
||||
if (rc){
|
||||
if (rc->rc_tag)
|
||||
free(rc->rc_tag);
|
||||
free(rc);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! Search netconf backend callbacks and invoke if match
|
||||
* This is internal system call, plugin is invoked (does not call) this functino
|
||||
* @param[in] h clicon handle
|
||||
* @param[in] xe Sub-tree (under xorig) at child of rpc: <rpc><xn></rpc>.
|
||||
* @param[in] ce Client (session) entry
|
||||
* @param[out] cbret Return XML, error or OK as cbuf
|
||||
*
|
||||
* @retval -1 Error
|
||||
* @retval 0 OK, not found handler.
|
||||
* @retval 1 OK, handler called
|
||||
* @see backend_rpc_cb_register
|
||||
*/
|
||||
int
|
||||
backend_rpc_cb_call(clicon_handle h,
|
||||
cxobj *xe,
|
||||
struct client_entry *ce,
|
||||
cbuf *cbret)
|
||||
{
|
||||
backend_rpc_cb_entry *rc;
|
||||
int retval = -1;
|
||||
|
||||
if (rpc_cb_list == NULL)
|
||||
return 0;
|
||||
rc = rpc_cb_list;
|
||||
do {
|
||||
if (strcmp(rc->rc_tag, xml_name(xe)) == 0){
|
||||
if ((retval = rc->rc_callback(h, xe, ce, cbret, rc->rc_arg)) < 0){
|
||||
clicon_debug(1, "%s Error in: %s", __FUNCTION__, rc->rc_tag);
|
||||
goto done;
|
||||
}
|
||||
else{
|
||||
retval = 1; /* handled */
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
rc = NEXTQ(backend_rpc_cb_entry *, rc);
|
||||
} while (rc != rpc_cb_list);
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Delete all state data callbacks.
|
||||
*/
|
||||
int
|
||||
backend_rpc_cb_delete_all(void)
|
||||
{
|
||||
backend_rpc_cb_entry *rc;
|
||||
|
||||
while((rc = rpc_cb_list) != NULL) {
|
||||
DELQ(rc, rpc_cb_list, backend_rpc_cb_entry *);
|
||||
if (rc->rc_tag)
|
||||
free(rc->rc_tag);
|
||||
free(rc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,30 +43,6 @@
|
|||
/*
|
||||
* Types
|
||||
*/
|
||||
struct client_entry;
|
||||
typedef int (*backend_rpc_cb)(
|
||||
clicon_handle h, /* CLicon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
struct client_entry *ce, /* Client session */
|
||||
cbuf *cbret,/* Reply eg <rpc-reply>... */
|
||||
void *arg /* Argument given at register */
|
||||
);
|
||||
typedef backend_rpc_cb backend_netconf_cb_t; /* XXX backward compat */
|
||||
|
||||
|
||||
/*! Generic downcall registration.
|
||||
* Enables any function to be called from (cli) frontend
|
||||
* to backend. Like an RPC on application-level.
|
||||
*/
|
||||
typedef int (*downcall_cb)(clicon_handle h, uint16_t op, uint16_t len,
|
||||
void *arg, uint16_t *retlen, void **retarg);
|
||||
|
||||
/*
|
||||
* Log for netconf notify function (config_client.c)
|
||||
*/
|
||||
int backend_notify(clicon_handle h, char *stream, int level, char *txt);
|
||||
int backend_notify_xml(clicon_handle h, char *stream, int level, cxobj *x);
|
||||
|
||||
/* subscription callback */
|
||||
typedef int (*subscription_fn_t)(clicon_handle, void *filter, void *arg);
|
||||
|
||||
|
|
@ -82,6 +58,14 @@ struct handle_subscription{
|
|||
void *hs_arg; /* Callback argument */
|
||||
};
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
/* Log for netconf notify function (config_client.c) */
|
||||
int backend_notify(clicon_handle h, char *stream, int level, char *txt);
|
||||
int backend_notify_xml(clicon_handle h, char *stream, int level, cxobj *x);
|
||||
|
||||
|
||||
struct handle_subscription *subscription_add(clicon_handle h, char *stream,
|
||||
enum format_enum format, char *filter,
|
||||
subscription_fn_t fn, void *arg);
|
||||
|
|
@ -92,12 +76,4 @@ int subscription_delete(clicon_handle h, char *stream,
|
|||
struct handle_subscription *subscription_each(clicon_handle h,
|
||||
struct handle_subscription *hprev);
|
||||
|
||||
int backend_rpc_cb_register(clicon_handle h, backend_rpc_cb cb, void *arg,
|
||||
char *tag);
|
||||
|
||||
int backend_rpc_cb_call(clicon_handle h, cxobj *xe, struct client_entry *ce,
|
||||
cbuf *cbret);
|
||||
|
||||
int backend_rpc_cb_delete_all(void);
|
||||
|
||||
#endif /* _CLIXON_BACKEND_HANDLE_H_ */
|
||||
|
|
|
|||
|
|
@ -41,16 +41,8 @@
|
|||
#define _CLIXON_BACKEND_TRANSACTION_H_
|
||||
|
||||
/*
|
||||
* Types
|
||||
* Prototypes
|
||||
*/
|
||||
|
||||
/*! Generic downcall registration.
|
||||
* Enables any function to be called from (cli) frontend
|
||||
* to backend. Like an RPC on application-level.
|
||||
*/
|
||||
typedef int (*downcall_cb)(clicon_handle h, uint16_t op, uint16_t len,
|
||||
void *arg, uint16_t *retlen, void **retarg);
|
||||
|
||||
/* Transaction callback data accessors for client plugins
|
||||
* (defined in config_dbdep.c)
|
||||
* @see transaction_data_t internal structure
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue