From a7a699a8b58987476b6f54d90cb465d7957d4044 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 21 Sep 2021 15:02:46 +0200 Subject: [PATCH] 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) ``` --- CHANGELOG.md | 26 +++++++++++++++++++------- apps/backend/backend_plugin.c | 15 ++------------- example/main/example_backend.c | 4 ++-- example/main/example_backend_nacm.c | 4 ++++ lib/clixon/clixon_plugin.h | 15 ++------------- test/test_pagination_config.sh | 3 +-- test/test_pagination_state.sh | 4 ++-- 7 files changed, 32 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 334f2409..8c300aa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index eeca7141..9e1e68b5 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -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)); diff --git a/example/main/example_backend.c b/example/main/example_backend.c index 942d9052..a96babfb 100644 --- a/example/main/example_backend.c +++ b/example/main/example_backend.c @@ -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 */ + .ca_statedata=example_statedata, /* statedata : Note fn is switched if -sS */ .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 */ _state_file_cached = 1; diff --git a/example/main/example_backend_nacm.c b/example/main/example_backend_nacm.c index e8b6c58b..655e4d1b 100644 --- a/example/main/example_backend_nacm.c +++ b/example/main/example_backend_nacm.c @@ -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; diff --git a/lib/clixon/clixon_plugin.h b/lib/clixon/clixon_plugin.h index cc7b8700..95b4029e 100644 --- a/lib/clixon/clixon_plugin.h +++ b/lib/clixon/clixon_plugin.h @@ -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 diff --git a/test/test_pagination_config.sh b/test/test_pagination_config.sh index e9725bb9..c20916ce 100755 --- a/test/test_pagination_config.sh +++ b/test/test_pagination_config.sh @@ -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 < $cfg diff --git a/test/test_pagination_state.sh b/test/test_pagination_state.sh index c744fb68..fcefc593 100755 --- a/test/test_pagination_state.sh +++ b/test/test_pagination_state.sh @@ -26,8 +26,8 @@ fstate=$dir/mystate.xml : ${validatexml:=false} # Number of audit-log entries -#: ${perfnr:=20000} -: ${perfnr:=200} +: ${perfnr:=20000} + cat < $cfg