diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 5f0ddcca..9fb3e1c1 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -47,7 +47,6 @@ #include #include #include - #include #include #include @@ -83,6 +82,7 @@ * @retval 0 OK * @retval -1 Error * @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 cli_notification_register(clixon_handle h, @@ -127,8 +127,8 @@ cli_notification_register(clixon_handle h, cligen_unregfd(s_exist); } clicon_hash_del(cdat, logname); -#if 0 /* cant turn off */ - if (clicon_rpc_create_subscription(h, status, stream, format, filter, NULL) < 0) +#ifdef NYI + if (clicon_rpc_close_session(h) < 0) goto done; #endif } @@ -909,7 +909,6 @@ cli_start_program(clixon_handle h, goto done; } } - done: if(buf) free(buf); @@ -1622,7 +1621,6 @@ cli_notification_cb(int s, * @code * cmd("comment"), cli_notify("mystream","1","xml"); * @endcode - * XXX: format is a memory leak */ int cli_notify(clixon_handle h, @@ -2087,6 +2085,43 @@ cli_process_control(clixon_handle h, 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, "", + NETCONF_BASE_NAMESPACE, + clicon_username_get(h), + NETCONF_MESSAGE_ID_ATTR); + cprintf(cb, "", CLIXON_LIB_NS); + cprintf(cb, ""); + 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 * * @param[in] h Clixon handle diff --git a/example/main/example_cli.cli b/example/main/example_cli.cli index 70ba95bd..3b184e07 100644 --- a/example/main/example_cli.cli +++ b/example/main/example_cli.cli @@ -167,3 +167,4 @@ no("Negate") notify("Get notifications from backend"), cli_notify("EXAMPLE", "0" lock,cli_lock("candidate"); unlock,cli_unlock("candidate"); restart , cli_restart_plugin(); +ping("Check packend liveness"), cli_ping(); diff --git a/lib/clixon/clixon_plugin.h b/lib/clixon/clixon_plugin.h index 5cffa5f0..9c97c5ef 100644 --- a/lib/clixon/clixon_plugin.h +++ b/lib/clixon/clixon_plugin.h @@ -217,7 +217,7 @@ typedef int (plgreset_t)(clixon_handle h, const char *db); * @param[in] h Clixon handle * @param[in] xpath Part of state requested * @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 -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 * @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 * diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h index 5fb5ce5f..7fd828b6 100644 --- a/lib/clixon/clixon_yang.h +++ b/lib/clixon/clixon_yang.h @@ -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(FILE *f, yang_stmt *yn); 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_spec_print(FILE *f, yang_stmt *yspec); int yang_spec_dump(yang_stmt *yspec, int debuglevel); diff --git a/lib/src/clixon_netconf_lib.c b/lib/src/clixon_netconf_lib.c index 5d76b50d..5e37013f 100644 --- a/lib/src/clixon_netconf_lib.c +++ b/lib/src/clixon_netconf_lib.c @@ -1959,7 +1959,6 @@ netconf_hello_server(clixon_handle h, return retval; } - /*! 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 diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index ee1ce23e..31609270 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -1496,6 +1496,7 @@ yn_insert1(yang_stmt *ys_parent, * ...ynext... * } * @endcode + * @note NULL children are skipped, which means inext may increment by more than 1 */ yang_stmt * yn_iter(yang_stmt *yparent, @@ -2496,6 +2497,22 @@ yang_spec_dump(yang_stmt *yspec, 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 * * @param[in] cb Cligen buffer. This is where the pretty print is. diff --git a/lib/src/clixon_yang_schema_mount.c b/lib/src/clixon_yang_schema_mount.c index 6d7f6df5..2d29600c 100644 --- a/lib/src/clixon_yang_schema_mount.c +++ b/lib/src/clixon_yang_schema_mount.c @@ -908,6 +908,7 @@ yang_schema_yspec_rm(clixon_handle h, int retval = -1; yang_stmt *yspec = NULL; char *xpath = NULL; + int ret; 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 (yang_cvec_rm(yspec, xpath) < 0) 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; done: