Merge branch dispatcher and broke out pagination callbacks to use it
* Merge branch 'dcornejo-master' * Broke out pagination callback API from state data callbacks * New pagination callback API uses new dispatcher from netgate, thanks @dcornejo * Register callback with: `clixon_pagination_cb_register()` * Use accessor functions `pagination_offset()`, `pagination_limit()`, etc * Reverted state data callback API to pre-5.3 (see C/CLI API changes below)
This commit is contained in:
commit
ce06f25be7
19 changed files with 996 additions and 123 deletions
|
|
@ -108,6 +108,7 @@ extern "C" {
|
|||
#include <clixon/clixon_xml_nsctx.h>
|
||||
#include <clixon/clixon_xml_vec.h>
|
||||
#include <clixon/clixon_client.h>
|
||||
#include <clixon/clixon_dispatcher.h>
|
||||
|
||||
/*
|
||||
* Global variables generated by Makefile
|
||||
|
|
|
|||
|
|
@ -61,10 +61,15 @@ typedef struct {
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
/* Generic clixon data API the form <name>=<val> where <val> is string */
|
||||
int clicon_data_get(clicon_handle h, const char *name, char **val);
|
||||
int clicon_data_set(clicon_handle h, const char *name, char *val);
|
||||
int clicon_data_del(clicon_handle h, const char *name);
|
||||
|
||||
int clicon_ptr_get(clicon_handle h, const char *name, void **ptr);
|
||||
int clicon_ptr_set(clicon_handle h, const char *name, void *ptr);
|
||||
int clicon_ptr_del(clicon_handle h, const char *name);
|
||||
|
||||
cvec *clicon_data_cvec_get(clicon_handle h, const char *name);
|
||||
int clicon_data_cvec_set(clicon_handle h, const char *name, cvec *cvv);
|
||||
int clicon_data_cvec_del(clicon_handle h, const char *name);
|
||||
|
|
|
|||
75
lib/clixon/clixon_dispatcher.h
Normal file
75
lib/clixon/clixon_dispatcher.h
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright 2021 Rubicon Communications LLC (Netgate)
|
||||
* @see https://github.com/dcornejo/dispatcher
|
||||
*/
|
||||
|
||||
#ifndef DISPATCH_DISPATCHER_H
|
||||
#define DISPATCH_DISPATCHER_H
|
||||
|
||||
/*! prototype for a function to handle a path
|
||||
* minimally needs the path it's working on, but probably
|
||||
* we want to hand down cached data somehow
|
||||
* @param[in] h Generic handler
|
||||
* @param[in] xpath Registered XPath using canonical prefixes
|
||||
* @param[in] userargs Per-call user arguments
|
||||
* @param[in] arg Per-path user argument
|
||||
*/
|
||||
typedef int (*handler_function)(void *handle, char *path, void *userargs, void *arg);
|
||||
|
||||
/*
|
||||
* this structure is used to map a handler to a path
|
||||
*/
|
||||
typedef struct {
|
||||
char *dd_path;
|
||||
handler_function dd_handler;
|
||||
} dispatcher_definition;
|
||||
|
||||
/*
|
||||
* the dispatcher_entry_t is the structure created from
|
||||
* the registered dispatcher_definitions
|
||||
*/
|
||||
struct _dispatcher_entry;
|
||||
typedef struct _dispatcher_entry dispatcher_entry_t;
|
||||
|
||||
struct _dispatcher_entry {
|
||||
/*
|
||||
* the name of this node, NOT the complete path
|
||||
*/
|
||||
char *node_name;
|
||||
|
||||
/*
|
||||
* peer points at peer to the right of this one
|
||||
* if NULL then this is the rightmost and last on list
|
||||
*/
|
||||
dispatcher_entry_t *peer;
|
||||
|
||||
/*
|
||||
* peer_head points at leftmost peer at this level
|
||||
* if NULL, then this is the leftmost and first on the list
|
||||
*/
|
||||
dispatcher_entry_t *peer_head;
|
||||
|
||||
/*
|
||||
* points at peer_head of children list
|
||||
* if NULL, then no children
|
||||
*/
|
||||
dispatcher_entry_t *children;
|
||||
|
||||
/*
|
||||
* pointer to handler function for this node
|
||||
*/
|
||||
handler_function handler;
|
||||
|
||||
/*
|
||||
* End-user argument
|
||||
*/
|
||||
void *arg;
|
||||
};
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int dispatcher_register_handler(dispatcher_entry_t **root, dispatcher_definition *x);
|
||||
int dispatcher_call_handlers(dispatcher_entry_t *root, void *handle, char *path, void *user_args);
|
||||
|
||||
#endif /* DISPATCH_DISPATCHER_H */
|
||||
|
|
@ -217,24 +217,21 @@ enum pagination_mode{
|
|||
typedef enum pagination_mode pagination_mode_t;
|
||||
|
||||
/* Plugin statedata
|
||||
* @param[in] Clicon handle
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] xpath Part of state requested
|
||||
* @param[in] nsc XPATH namespace context.
|
||||
* @param[in] pagmode List pagination mode
|
||||
* @param[in] offset Offset, for list pagination
|
||||
* @param[in] limit Limit, for list pagination
|
||||
* @param[out] remaining Remaining elements (if limit is non-zero)
|
||||
* @param[out] xtop XML tree where statedata is added
|
||||
* @retval -1 Fatal error
|
||||
* @retval 0 OK
|
||||
*/
|
||||
typedef int (plgstatedata_t)(clicon_handle h, cvec *nsc, char *xpath,
|
||||
pagination_mode_t pagmode,
|
||||
uint32_t offset, uint32_t limit,
|
||||
uint32_t *remaining,
|
||||
cxobj *xtop);
|
||||
typedef int (plgstatedata_t)(clicon_handle h, cvec *nsc, char *xpath, cxobj *xtop);
|
||||
|
||||
/*! Lock databse status has changed status
|
||||
/* Pagination-data type
|
||||
* @see pagination_data_t in clixon_backend_transaction.h for full pagination API
|
||||
*/
|
||||
typedef void *pagination_data;
|
||||
|
||||
/*! Lock database status has changed status
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] db Database name (eg "running")
|
||||
* @param[in] lock Lock status: 0: unlocked, 1: locked
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue