Add ping to cli example, misc debug

This commit is contained in:
Olof hagsand 2024-12-05 15:37:09 +01:00
parent 379644a570
commit 30f9e174fa
7 changed files with 74 additions and 8 deletions

View file

@ -47,7 +47,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <time.h>
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include <dirent.h> #include <dirent.h>
#include <syslog.h> #include <syslog.h>
@ -83,6 +82,7 @@
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* @note this calls cligen_regfd which may callback on cli command interpretator * @note this calls cligen_regfd which may callback on cli command interpretator
* @note NYI: On stop, should call close_session on event socket, see https://github.com/clicon/clixon/issues/578
*/ */
int int
cli_notification_register(clixon_handle h, cli_notification_register(clixon_handle h,
@ -127,8 +127,8 @@ cli_notification_register(clixon_handle h,
cligen_unregfd(s_exist); cligen_unregfd(s_exist);
} }
clicon_hash_del(cdat, logname); clicon_hash_del(cdat, logname);
#if 0 /* cant turn off */ #ifdef NYI
if (clicon_rpc_create_subscription(h, status, stream, format, filter, NULL) < 0) if (clicon_rpc_close_session(h) < 0)
goto done; goto done;
#endif #endif
} }
@ -909,7 +909,6 @@ cli_start_program(clixon_handle h,
goto done; goto done;
} }
} }
done: done:
if(buf) if(buf)
free(buf); free(buf);
@ -1622,7 +1621,6 @@ cli_notification_cb(int s,
* @code * @code
* cmd("comment"), cli_notify("mystream","1","xml"); * cmd("comment"), cli_notify("mystream","1","xml");
* @endcode * @endcode
* XXX: format is a memory leak
*/ */
int int
cli_notify(clixon_handle h, cli_notify(clixon_handle h,
@ -2087,6 +2085,43 @@ cli_process_control(clixon_handle h,
return retval; return retval;
} }
int
cli_ping(clixon_handle h,
cvec *cvv,
cvec *argv)
{
int retval = -1;
cbuf *cb = NULL;
cxobj *xret = NULL;
cxobj *xerr;
if ((cb = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
cprintf(cb, "<rpc xmlns=\"%s\" username=\"%s\" %s>",
NETCONF_BASE_NAMESPACE,
clicon_username_get(h),
NETCONF_MESSAGE_ID_ATTR);
cprintf(cb, "<ping xmlns=\"%s\"/>", CLIXON_LIB_NS);
cprintf(cb, "</rpc>");
if (clicon_rpc_netconf(h, cbuf_get(cb), &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto done;
}
if (clixon_xml2file(stdout, xml_child_i(xret, 0), 0, 1, NULL, cligen_output, 0, 1) < 0)
goto done;
retval = 0;
done:
if (xret)
xml_free(xret);
if (cb)
cbuf_free(cb);
return retval;
}
/*! Alias function /*! Alias function
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle

View file

@ -167,3 +167,4 @@ no("Negate") notify("Get notifications from backend"), cli_notify("EXAMPLE", "0"
lock,cli_lock("candidate"); lock,cli_lock("candidate");
unlock,cli_unlock("candidate"); unlock,cli_unlock("candidate");
restart <plugin:string>, cli_restart_plugin(); restart <plugin:string>, cli_restart_plugin();
ping("Check packend liveness"), cli_ping();

View file

@ -217,7 +217,7 @@ typedef int (plgreset_t)(clixon_handle h, const char *db);
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] xpath Part of state requested * @param[in] xpath Part of state requested
* @param[in] nsc XPath namespace context. * @param[in] nsc XPath namespace context.
* @param[out] xtop XML tree where data is added * @param[out] xconfig XML tree where data is added
* @retval 0 OK * @retval 0 OK
* @retval -1 Fatal error * @retval -1 Fatal error
* *
@ -225,7 +225,7 @@ typedef int (plgreset_t)(clixon_handle h, const char *db);
* @note The system does not validate the xml, unless CLICON_VALIDATE_STATE_XML is set * @note The system does not validate the xml, unless CLICON_VALIDATE_STATE_XML is set
* @see clixon_pagination_cb_register for special paginated state data callback * @see clixon_pagination_cb_register for special paginated state data callback
*/ */
typedef int (plgstatedata_t)(clixon_handle h, cvec *nsc, char *xpath, cxobj *xtop); typedef int (plgstatedata_t)(clixon_handle h, cvec *nsc, char *xpath, cxobj *xconfig);
/*! Pagination-data type /*! Pagination-data type
* *

View file

@ -327,6 +327,7 @@ int yang_order(yang_stmt *y);
int yang_print_cb(FILE *f, yang_stmt *yn, clicon_output_cb *fn); int yang_print_cb(FILE *f, yang_stmt *yn, clicon_output_cb *fn);
int yang_print(FILE *f, yang_stmt *yn); int yang_print(FILE *f, yang_stmt *yn);
int yang_print_cbuf(cbuf *cb, yang_stmt *yn, int marginal, int pretty); int yang_print_cbuf(cbuf *cb, yang_stmt *yn, int marginal, int pretty);
int yang_dump1(FILE *f, yang_stmt *yn);
int yang_deviation(yang_stmt *ys, void *arg); int yang_deviation(yang_stmt *ys, void *arg);
int yang_spec_print(FILE *f, yang_stmt *yspec); int yang_spec_print(FILE *f, yang_stmt *yspec);
int yang_spec_dump(yang_stmt *yspec, int debuglevel); int yang_spec_dump(yang_stmt *yspec, int debuglevel);

View file

@ -1959,7 +1959,6 @@ netconf_hello_server(clixon_handle h,
return retval; return retval;
} }
/*! Add internal error info to existing netconf error message by rewriting /*! Add internal error info to existing netconf error message by rewriting
* *
* If a eg sanity check detects errors in internal messages passing, such as from a plugin or * If a eg sanity check detects errors in internal messages passing, such as from a plugin or

View file

@ -1496,6 +1496,7 @@ yn_insert1(yang_stmt *ys_parent,
* ...ynext... * ...ynext...
* } * }
* @endcode * @endcode
* @note NULL children are skipped, which means inext may increment by more than 1
*/ */
yang_stmt * yang_stmt *
yn_iter(yang_stmt *yparent, yn_iter(yang_stmt *yparent,
@ -2496,6 +2497,22 @@ yang_spec_dump(yang_stmt *yspec,
return retval; return retval;
} }
/*! Dump pointers to children, debug function
*/
int
yang_dump1(FILE *f,
yang_stmt *yn)
{
yang_stmt *ys;
int inext;
inext = 0;
while ((ys = yn_iter(yn, &inext)) != NULL) {
fprintf(stderr, "%2d %p %s %s\n", inext-1, ys, yang_key2str(yang_keyword_get(ys)), yang_argument_get(ys));
}
return 0;
}
/*! Print yang specification to cligen buf /*! Print yang specification to cligen buf
* *
* @param[in] cb Cligen buffer. This is where the pretty print is. * @param[in] cb Cligen buffer. This is where the pretty print is.

View file

@ -908,6 +908,7 @@ yang_schema_yspec_rm(clixon_handle h,
int retval = -1; int retval = -1;
yang_stmt *yspec = NULL; yang_stmt *yspec = NULL;
char *xpath = NULL; char *xpath = NULL;
int ret; int ret;
if ((ret = xml_yang_mount_get(h, xmnt, NULL, &xpath, &yspec)) < 0) if ((ret = xml_yang_mount_get(h, xmnt, NULL, &xpath, &yspec)) < 0)
@ -915,6 +916,18 @@ yang_schema_yspec_rm(clixon_handle h,
if (ret == 1 && xpath != NULL && yspec != NULL){ if (ret == 1 && xpath != NULL && yspec != NULL){
if (yang_cvec_rm(yspec, xpath) < 0) if (yang_cvec_rm(yspec, xpath) < 0)
goto done; goto done;
#if 0
cvec *cvv;
/* see https://github.com/clicon/clixon-controller/issues/169
* cannot remove yspec since it may still be in use by caches
*/
cvv = yang_cvec_get(yspec);
if (cvv && cvec_len(cvv) == 0){
ys_prune_self(yspec);
ys_free(yspec);
yspec = NULL;
}
#endif
} }
retval = 0; retval = 0;
done: done: