@@ -70,6 +70,7 @@ extern int done;
7070LYD_FORMAT output_format = LYD_XML ;
7171uint32_t output_flag ;
7272char * config_editor ;
73+ char * ext_data_path ;
7374struct nc_session * session ;
7475volatile int interleave ;
7576int timed ;
@@ -462,6 +463,27 @@ cli_send_recv(struct nc_rpc *rpc, FILE *output, NC_WD_MODE wd_mode, int timeout_
462463 return ret ;
463464}
464465
466+ static LY_ERR
467+ cli_ext_data_clb (const struct lysc_ext_instance * ext , void * user_data , void * * ext_data , ly_bool * ext_data_free )
468+ {
469+ const char * path = user_data ;
470+ struct lyd_node * data ;
471+ LY_ERR r ;
472+
473+ if (strcmp (ext -> def -> module -> name , "ietf-yang-schema-mount" ) || strcmp (ext -> def -> name , "mount-point" )) {
474+ return LY_EINVAL ;
475+ }
476+
477+ /* parse the data file */
478+ if ((r = lyd_parse_data_path (ext -> def -> module -> ctx , path , 0 , LYD_PARSE_STRICT , LYD_VALIDATE_PRESENT , & data ))) {
479+ return r ;
480+ }
481+
482+ * ext_data = data ;
483+ * ext_data_free = 1 ;
484+ return LY_SUCCESS ;
485+ }
486+
465487static char *
466488trim_top_elem (char * data , const char * top_elem , const char * top_elem_ns )
467489{
@@ -1255,6 +1277,12 @@ cmd_userrpc_help(void)
12551277 printf ("user-rpc [--help] [--content <file>] [--out <file>] [--rpc-timeout <seconds>]\n" );
12561278}
12571279
1280+ static void
1281+ cmd_extdata_help (void )
1282+ {
1283+ printf ("ext-data [--help] [--path <file>]\n" );
1284+ }
1285+
12581286static void
12591287cmd_timed_help (void )
12601288{
@@ -1742,6 +1770,10 @@ cmd_connect_listen_ssh(struct arglist *cmd, int is_connect)
17421770 }
17431771 }
17441772
1773+ if (ext_data_path ) {
1774+ ly_ctx_set_ext_data_clb ((struct ly_ctx * )nc_session_get_ctx (session ), cli_ext_data_clb , ext_data_path );
1775+ }
1776+
17451777 return EXIT_SUCCESS ;
17461778}
17471779
@@ -2558,6 +2590,10 @@ cmd_connect_listen_tls(struct arglist *cmd, int is_connect)
25582590 }
25592591 }
25602592
2593+ if (ext_data_path ) {
2594+ ly_ctx_set_ext_data_clb ((struct ly_ctx * )nc_session_get_ctx (session ), cli_ext_data_clb , ext_data_path );
2595+ }
2596+
25612597 ret = EXIT_SUCCESS ;
25622598
25632599error_cleanup :
@@ -2618,6 +2654,10 @@ cmd_connect_listen_unix(struct arglist *cmd, int is_connect)
26182654 goto error_cleanup ;
26192655 }
26202656
2657+ if (ext_data_path ) {
2658+ ly_ctx_set_ext_data_clb ((struct ly_ctx * )nc_session_get_ctx (session ), cli_ext_data_clb , ext_data_path );
2659+ }
2660+
26212661 ret = EXIT_SUCCESS ;
26222662
26232663error_cleanup :
@@ -6609,6 +6649,35 @@ cmd_userrpc(const char *arg, char **tmp_config_file)
66096649 return ret ;
66106650}
66116651
6652+ static int
6653+ cmd_extdata (const char * arg , char * * UNUSED (tmp_config_file ))
6654+ {
6655+ char * cmd , * args = strdupa (arg ), * ptr = NULL ;
6656+
6657+ cmd = strtok_r (args , " " , & ptr );
6658+ cmd = strtok_r (NULL , " " , & ptr );
6659+ if (cmd == NULL ) {
6660+ printf ("Current file: " );
6661+ printf ("%s\n" , ext_data_path );
6662+ } else if ((strcmp (cmd , "--help" ) == 0 ) || (strcmp (cmd , "-h" ) == 0 )) {
6663+ cmd_extdata_help ();
6664+ } else {
6665+ if (access (cmd , F_OK ) == -1 ) {
6666+ ERROR (__func__ , "Unable to access file \"%s\" (%s)." , cmd , strerror (errno ));
6667+ return EXIT_FAILURE ;
6668+ }
6669+
6670+ free (ext_data_path );
6671+ ext_data_path = strdup (cmd );
6672+ }
6673+
6674+ if (session ) {
6675+ ly_ctx_set_ext_data_clb ((struct ly_ctx * )nc_session_get_ctx (session ), cli_ext_data_clb , ext_data_path );
6676+ }
6677+
6678+ return EXIT_SUCCESS ;
6679+ }
6680+
66126681static int
66136682cmd_timed (const char * arg , char * * UNUSED (tmp_config_file ))
66146683{
@@ -6679,6 +6748,7 @@ COMMAND commands[] = {
66796748 "ietf-subscribed-notifications <modify-subscription> operation with ietf-yang-push augments" },
66806749 {"resync-sub" , cmd_resyncsub , cmd_resyncsub_help , "ietf-yang-push <resync-subscription> operation" },
66816750 {"user-rpc" , cmd_userrpc , cmd_userrpc_help , "Send your own content in an RPC envelope" },
6751+ {"ext-data" , cmd_extdata , cmd_extdata_help , "Set path to a data file with libyang ext data" },
66826752 {"timed" , cmd_timed , cmd_timed_help , "Time all the commands (that communicate with a server) from issuing an RPC"
66836753 " to getting a reply" },
66846754 /* synonyms for previous commands */
0 commit comments