Removed remaining and replaced pagination-mode with locked parameter

Dispatcher: Added dispatcher_free(), fixed mem-leaks and malloc return
checks
This commit is contained in:
Olof hagsand 2021-10-09 15:50:13 +02:00
parent ce06f25be7
commit edbbb43e1f
14 changed files with 204 additions and 161 deletions

View file

@ -467,11 +467,8 @@ get_list_pagination(clicon_handle h,
char *xpath2; /* With optional pagination predicate */
int ret;
uint32_t iddb; /* DBs lock, if any */
pagination_mode_t pagmode;
int locked;
cxobj *x1 = NULL;
cxobj *xcache = NULL;
uint32_t total = 0;
uint32_t remaining = 0;
/* Check if list/leaf-list */
if (yang_path_arg(yspec, xpath, &ylist) < 0)
@ -588,6 +585,7 @@ get_list_pagination(clicon_handle h,
}/* switch content */
if (list_config){
#ifdef LIST_PAGINATION_REMAINING
/* Get total/remaining
* XXX: Works only for cache
*/
@ -597,15 +595,16 @@ get_list_pagination(clicon_handle h,
if (total >= (offset + limit))
remaining = total - (offset + limit);
}
#endif
}
else {/* Check if running locked (by this session) */
if ((iddb = xmldb_islocked(h, "running")) != 0 &&
iddb == ce->ce_id)
pagmode = PAGINATION_LOCK;
locked = 1;
else
pagmode = PAGINATION_STATELESS;
if ((ret = clixon_pagination_cb_call(h, xpath, pagmode,
offset, limit, &remaining,
locked = 0;
if ((ret = clixon_pagination_cb_call(h, xpath, locked,
offset, limit,
xret)) < 0)
goto done;
if (ret == 0)

View file

@ -131,7 +131,7 @@ backend_terminate(clicon_handle h)
clixon_process_delete_all(h);
xpath_optimize_exit();
clixon_pagination_free(h);
if (pidfile)
unlink(pidfile);
if (sockfamily==AF_UNIX && lstat(sockpath, &st) == 0)

View file

@ -452,23 +452,24 @@ clixon_plugin_lockdb_all(clicon_handle h,
* @param[in] xpath Registered XPath using canonical prefixes
*/
int
clixon_pagination_cb_call(clicon_handle h,
char *xpath,
pagination_mode_t pagmode,
uint32_t offset,
uint32_t limit,
uint32_t *remaining,
cxobj *xstate)
clixon_pagination_cb_call(clicon_handle h,
char *xpath,
int locked,
uint32_t offset,
uint32_t limit,
cxobj *xstate)
{
int retval = -1;
pagination_data_t pd = {pagmode, offset, limit, 0, xstate};
pagination_data_t pd;
dispatcher_entry_t *htable = NULL;
pd.pd_offset = offset;
pd.pd_limit = limit;
pd.pd_locked = locked;
pd.pd_xstate = xstate;
clicon_ptr_get(h, "pagination-entries", (void**)&htable);
if (htable && dispatcher_call_handlers(htable, h, xpath, &pd) < 0)
goto done;
if (remaining)
*remaining = pd.pd_remaining;
retval = 1;
done:
return retval;
@ -503,6 +504,21 @@ clixon_pagination_cb_register(clicon_handle h,
return retval;
}
/*! Free pagination callback structure
*
* @param[in] h Clixon handle
*/
int
clixon_pagination_free(clicon_handle h)
{
dispatcher_entry_t *htable = NULL;
clicon_ptr_get(h, "pagination-entries", (void**)&htable);
if (htable)
dispatcher_free(htable);
return 0;
}
/*! Create and initialize a validate/commit transaction
* @retval td New alloced transaction,
* @retval NULL Error

View file

@ -68,17 +68,22 @@ typedef struct {
} transaction_data_t;
/*! Pagination userdata
* @param[in] pagmode List pagination mode
* Pagination can use a lock/transaction mechanism
* If locking is not used, the plugin cannot expect more pagination calls, and no state or
* caching should be used
* If locking is used, the pagination is part of a session transaction and the plugin may cache
* state (such as a cache) and can expect more pagination calls until the running db-lock is
* released, (see ca_lockdb)
* The transaction is the regular lock/unlock db of running-db of a specific session.
* @param[in] locked "running" datastore is locked by this caller
* @param[in] offset Offset, for list pagination
* @param[in] limit Limit, for list pagination
* @param[out] remaining Remaining elements (if limit is non-zero)
* see also pagination_data in clixon_plugin.h
*/
typedef struct {
pagination_mode_t pd_pagmode; /* Pagination mode, stateless or locked */
uint32_t pd_offset; /* Start of pagination interval */
uint32_t pd_limit; /* Number of elemenents (limit) */
uint32_t pd_remaining; /* If limit, then remaining nr of elements */
int pd_locked; /* Running datastore is locked by this caller */
cxobj *pd_xstate; /* Returned xml state tree */
} pagination_data_t;
@ -96,9 +101,10 @@ int clixon_plugin_statedata_all(clicon_handle h, yang_stmt *yspec, cvec *nsc, ch
int clixon_plugin_lockdb_all(clicon_handle h, char *db, int lock, int id);
int clixon_pagination_cb_register(clicon_handle h, handler_function fn, char *path, void *arg);
int clixon_pagination_cb_call(clicon_handle h, char *xpath, pagination_mode_t pagmode,
uint32_t offset, uint32_t limit, uint32_t *remaining,
int clixon_pagination_cb_call(clicon_handle h, char *xpath, int locked,
uint32_t offset, uint32_t limit,
cxobj *xstate);
int clixon_pagination_free(clicon_handle h);
transaction_data_t * transaction_new(void);
int transaction_free(transaction_data_t *);

View file

@ -285,16 +285,6 @@ transaction_log(clicon_handle h,
return 0;
}
/*! Get pagination data: mode parameter
*
* @param[in] pd Pagination userdata
* @retval mode Pagination mode, stateless or locked
*/
pagination_mode_t
pagination_pagmode(pagination_data pd)
{
return ((pagination_data_t *)pd)->pd_pagmode;
}
/*! Get pagination data: offset parameter
*
@ -318,16 +308,22 @@ pagination_limit(pagination_data pd)
return ((pagination_data_t *)pd)->pd_limit;
}
/*! Set pagination data: remaining nr of elements
/*! Get pagination data: locked parameter
*
* @param[in] pd Pagination userdata
* @param[in] remaining If limit, then remaining nr of elements
* Pagination can use a lock/transaction mechanism
* If locking is not used, the plugin cannot expect more pagination calls, and no state or
* caching should be used
* If locking is used, the pagination is part of a session transaction and the plugin may cache
* state (such as a cache) and can expect more pagination calls until the running db-lock is
* released, (see ca_lockdb)
* The transaction is the regular lock/unlock db of running-db of a specific session.
* @param[in] pd Pagination userdata
* @retval locked 0: unlocked/stateless 1: locked by this caller
*/
int
pagination_remaining_set(pagination_data pd,
uint32_t remaining)
pagination_locked(pagination_data pd)
{
return ((pagination_data_t *)pd)->pd_remaining = remaining;
return ((pagination_data_t *)pd)->pd_locked;
}
/*! Get pagination data: Returned xml state tree

View file

@ -67,10 +67,9 @@ int transaction_log(clicon_handle h, transaction_data th, int level, const char
/* Pagination callbacks
* @see pagination_data_t internal structure
*/
pagination_mode_t pagination_pagmode(pagination_data pd);
int pagination_locked(pagination_data pd);
uint32_t pagination_offset(pagination_data pd);
uint32_t pagination_limit(pagination_data pd);
int pagination_remaining_set(pagination_data pd, uint32_t remaining);
cxobj *pagination_xstate(pagination_data pd);
#endif /* _CLIXON_BACKEND_TRANSACTION_H_ */