Fixed: kill-session cleanup when client none existant, and for all db:s

Added cli_kill_session callback
This commit is contained in:
Olof hagsand 2023-12-22 22:27:54 +01:00
parent 558a0df1f3
commit 7b58c1c562
4 changed files with 48 additions and 11 deletions

View file

@ -58,6 +58,7 @@ Developers may need to change their code
### Corrected Bugs
* Fixed: kill-session cleanup when client none existant, and for all db:s
* Fixed: [Using the characters '<' and '>' might cause an invalid diff](https://github.com/clicon/clixon-controller/issues/73)
## 6.5.0

View file

@ -173,7 +173,6 @@ ce_event_cb(clixon_handle h,
return retval;
}
/*! Unlock all db:s of a client and call user unlock calback
*
* @see xmldb_unlock_all unlocks, but does not call user callbacks which is a backend thing
@ -1015,7 +1014,6 @@ from_client_kill_session(clixon_handle h,
uint32_t id; /* session id */
char *str = NULL;
struct client_entry *ce;
char *db = "running"; /* XXX */
cxobj *x;
int ret;
char *reason = NULL;
@ -1032,16 +1030,10 @@ from_client_kill_session(clixon_handle h,
goto ok;
/* may or may not be in active client list, probably not */
if ((ce = ce_find_byid(backend_client_list(h), id)) != NULL){
if (release_all_dbs(h, id) < 0)
goto done;
backend_client_rm(h, ce); /* Removes client struct */
}
if (xmldb_islocked(h, db) == id){
xmldb_unlock(h, db);
/* user callback */
if (clixon_plugin_lockdb_all(h, db, 0, id) < 0)
if (release_all_dbs(h, id) < 0)
goto done;
}
cprintf(cbret, "<rpc-reply xmlns=\"%s\"><ok/></rpc-reply>", NETCONF_BASE_NAMESPACE);
ok:
retval = 0;

View file

@ -1545,7 +1545,7 @@ cli_lock(clixon_handle h,
* @retval 0 OK
* @retval -1 Error
* @code
* lock("comment"), cli_lock("running");
* lock("comment"), cli_unlock("running");
* @endcode
* XXX: format is a memory leak
*/
@ -1569,6 +1569,49 @@ cli_unlock(clixon_handle h,
return retval;
}
/*! Kill session
*
* @param[in] h Clixon handle
* @param[in] cvv Not used
* @param[in] arg <session-id>
* @retval 0 OK
* @retval -1 Error
* @code
* lock("comment"), cli_kill_session(54);
* @endcode
*/
int
cli_kill_session(clixon_handle h,
cvec *cvv,
cvec *argv)
{
int retval = -1;
char *str;
uint32_t session_id;
int ret;
char *reason = NULL;
if (cvec_len(argv) != 1){
clixon_err(OE_PLUGIN, EINVAL, "Requires arguments: <session-id>");
goto done;
}
if ((str = cv_string_get(cvec_i(argv, 0))) != NULL){
if ((ret = parse_uint32(str, &session_id, NULL)) < 0)
goto done;
if (ret == 0){
cligen_output(stderr, "%s\n", reason);
goto done;
}
else if ((ret = clicon_rpc_kill_session(h, session_id)) < 0)
goto done;
}
retval = 0;
done:
if (reason)
free(reason);
return retval;
}
/*! Copy one configuration object to antother
*
* Works for objects that are items in a yang list with a keyname, eg as:

View file

@ -109,6 +109,7 @@ int cli_notify(clixon_handle h, cvec *cvv, cvec *argv);
int db_copy(clixon_handle h, cvec *cvv, cvec *argv);
int cli_lock(clixon_handle h, cvec *cvv, cvec *argv);
int cli_unlock(clixon_handle h, cvec *cvv, cvec *argv);
int cli_kill_session(clixon_handle h, cvec *cvv, cvec *argv);
int cli_copy_config(clixon_handle h, cvec *cvv, cvec *argv);
int cli_help(clixon_handle h, cvec *vars, cvec *argv);
cvec *cvec_append(cvec *cvv0, cvec *cvv1);