New state plugin callback for pagination.

* You need to change all statedata plugin callback for the new pagination feature
  * If you dont use pagination you can ignore the values of the new parameters
  * See [User manual pagination](https://clixon-docs.readthedocs.io/en/latest/misc.html#pagination)
  * The updated callback signature is as follows:
  ```
  int statedata(clicon_handle     h,
                cvec             *nsc,
	        char             *xpath,
	        pagination_mode_t pagmode,   // NEW
	        uint32_t          offset,    // NEW
	        uint32_t          limit,     // NEW
	        uint32_t         *remaining, // NEW
	        cxobj            *xstate)
  ```
This commit is contained in:
Olof hagsand 2021-09-21 15:02:46 +02:00
parent 384ce70d7c
commit a7a699a8b5
7 changed files with 32 additions and 39 deletions

View file

@ -45,10 +45,8 @@ Expected: September, 2021
* ietf-restconf-list-pagination@2015-01-30.yang
* clixon-netconf-list-pagination@2021-08-27.yang
* ietf-yang-metadata@2016-08-05.yang
* New state callback signature (ca_statedata2)
* The new callback contains parameters for pagination
* Goal is to replace ca_statedata callback
* Updated state callback signature containing parameters for pagination
* See API changes below
* YANG Leafref feature update
* Closer adherence to RFC 7950. Some of this is changed behavior, some is new feature.
* Essentially instead of looking at the referring leaf, context is referred(target) node
@ -77,9 +75,9 @@ Expected: September, 2021
Users may have to change how they access the system
* See changes under new feature "YANG leafref feature update"
* Validation of referred node type (not referring)
* Looser leafref validation checks
* Leafref required-instance must be set to make strict data-node check
* See changes under new feature "YANG leafref feature update"
* Native Restconf
* Native restocnf is now default, not fcgi/nginx
* That is, to configure with fcgi, you need to explicitly configure: `--with-restconf=fcgi`
@ -93,7 +91,21 @@ Users may have to change how they access the system
Developers may need to change their code
* You need to change all statedata plugin callback for the new pagination feature
* If you dont use pagination you can ignore the values of the new parameters
* See [User manual pagination](https://clixon-docs.readthedocs.io/en/latest/misc.html#pagination)
* The updated callback signature is as follows:
```
int statedata(clicon_handle h,
cvec *nsc,
char *xpath,
pagination_mode_t pagmode, // NEW
uint32_t offset, // NEW
uint32_t limit, // NEW
uint32_t *remaining, // NEW
cxobj *xstate)
```
### Minor features
* JSON errors are now labelled with JSON and not XML

View file

@ -261,24 +261,13 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
{
int retval = -1;
plgstatedata_t *fn; /* Plugin statedata fn */
plgstatedata2_t *fn2; /* Plugin statedata fn2, try this first */
cxobj *x = NULL;
clicon_debug(1, "%s %s", __FUNCTION__, clixon_plugin_name_get(cp));
if ((fn2 = clixon_plugin_api_get(cp)->ca_statedata2) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_statedata) != NULL){
if ((x = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
goto done;
if (fn2(h, nsc, xpath, pagmode, offset, limit, remaining, x) < 0){
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, clixon_plugin_name_get(cp));
goto fail; /* Dont quit here on user callbacks */
}
}
else if ((fn = clixon_plugin_api_get(cp)->ca_statedata) != NULL){
if ((x = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
goto done;
if (fn(h, nsc, xpath, x) < 0){
if (fn(h, nsc, xpath, pagmode, offset, limit, remaining, x) < 0){
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, clixon_plugin_name_get(cp));

View file

@ -1119,7 +1119,7 @@ static clixon_plugin_api api = {
.ca_extension=example_extension, /* yang extensions */
.ca_daemon=example_daemon, /* daemon */
.ca_reset=example_reset, /* reset */
.ca_statedata2=example_statedata, /* statedata2 : Note fn is switched if -sS <file> */
.ca_statedata=example_statedata, /* statedata : Note fn is switched if -sS <file> */
.ca_lockdb=example_lockdb, /* Database lock changed state */
.ca_trans_begin=main_begin, /* trans begin */
.ca_trans_validate=main_validate, /* trans validate */
@ -1164,7 +1164,7 @@ clixon_plugin_init(clicon_handle h)
break;
case 'S': /* state file (requires -s) */
_state_file = optarg;
api.ca_statedata2 = example_statefile; /* Switch state data callback */
api.ca_statedata = example_statefile; /* Switch state data callback */
break;
case 'i': /* read state file on init not by request (requires -sS <file> */
_state_file_cached = 1;

View file

@ -180,6 +180,10 @@ int
nacm_statedata(clicon_handle h,
cvec *nsc,
char *xpath,
pagination_mode_t pagmode,
uint32_t offset,
uint32_t limit,
uint32_t *remaining,
cxobj *xstate)
{
int retval = -1;

View file

@ -196,16 +196,6 @@ typedef int (plgauth_t)(clicon_handle h, void *req, clixon_auth_type_t auth_type
*/
typedef int (plgreset_t)(clicon_handle h, const char *db);
/* Plugin statedata
* @param[in] Clicon handle
* @param[in] xpath Part of state requested
* @param[in] nsc XPATH namespace context.
* @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, cxobj *xtop);
/*! List pagination status in the plugin state data callback
*
* List pagination is either enabled or not.
@ -238,7 +228,7 @@ typedef enum pagination_mode pagination_mode_t;
* @retval -1 Fatal error
* @retval 0 OK
*/
typedef int (plgstatedata2_t)(clicon_handle h, cvec *nsc, char *xpath,
typedef int (plgstatedata_t)(clicon_handle h, cvec *nsc, char *xpath,
pagination_mode_t pagmode,
uint32_t offset, uint32_t limit,
uint32_t *remaining,
@ -324,8 +314,8 @@ struct clixon_plugin_api{
plgdaemon_t *cb_pre_daemon; /* Plugin just before daemonization (only daemon) */
plgdaemon_t *cb_daemon; /* Plugin daemonized (always called) */
plgreset_t *cb_reset; /* Reset system status */
plgstatedata_t *cb_statedata; /* Get state data from plugin (backend only) */
plgstatedata2_t *cb_statedata2; /* Get state data from plugin (backend only) */
plglockdb_t *cb_lockdb; /* Database lock changed state */
trans_cb_t *cb_trans_begin; /* Transaction start */
trans_cb_t *cb_trans_validate; /* Transaction validation */
@ -348,7 +338,6 @@ struct clixon_plugin_api{
#define ca_daemon u.cau_backend.cb_daemon
#define ca_reset u.cau_backend.cb_reset
#define ca_statedata u.cau_backend.cb_statedata
#define ca_statedata2 u.cau_backend.cb_statedata2
#define ca_lockdb u.cau_backend.cb_lockdb
#define ca_trans_begin u.cau_backend.cb_trans_begin
#define ca_trans_validate u.cau_backend.cb_trans_validate

View file

@ -22,8 +22,7 @@ fexample=$dir/example-social.yang
# Number of audit-log entries
# Note mem.sh sets it
#: ${perfnr:=20000}
: ${perfnr:=200}
: ${perfnr:=20000}
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">

View file

@ -26,8 +26,8 @@ fstate=$dir/mystate.xml
: ${validatexml:=false}
# Number of audit-log entries
#: ${perfnr:=20000}
: ${perfnr:=200}
: ${perfnr:=20000}
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">