@@ -661,7 +661,7 @@ free_schema_info(struct schema_info *list)
661661}
662662
663663static int
664- build_schema_info_yl (struct nc_session * session , struct schema_info * * result )
664+ build_schema_info_yl (struct nc_session * session , int has_get_data , struct schema_info * * result )
665665{
666666 struct nc_rpc * rpc = NULL ;
667667 struct lyd_node * op = NULL , * envp = NULL ;
@@ -672,16 +672,28 @@ build_schema_info_yl(struct nc_session *session, struct schema_info **result)
672672 uint32_t u , v , submodules_count , feature_count ;
673673 struct lyd_node * iter , * child ;
674674 struct lys_module * mod ;
675- int ret = EXIT_SUCCESS ;
675+ int ret = 0 ;
676+ const char * rpc_name ;
676677
677678 /* get yang-library data from the server */
678- if (nc_session_cpblt (session , "urn:ietf:params:netconf:capability:xpath:1.0" )) {
679- rpc = nc_rpc_getdata ("ietf-datastores:operational" , "/ietf-yang-library:*" , "false" , NULL , 0 , 0 , 0 , 0 , 0 ,
680- NC_PARAMTYPE_CONST );
679+ if (has_get_data ) {
680+ rpc_name = "get-data" ;
681+ if (nc_session_cpblt (session , "urn:ietf:params:netconf:capability:xpath:1.0" )) {
682+ rpc = nc_rpc_getdata ("ietf-datastores:operational" , "/ietf-yang-library:*" , "false" , NULL , 0 , 0 , 0 , 0 , 0 ,
683+ NC_PARAMTYPE_CONST );
684+ } else {
685+ rpc = nc_rpc_getdata ("ietf-datastores:operational" ,
686+ "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"/>" , "false" , NULL , 0 , 0 , 0 , 0 ,
687+ 0 , NC_PARAMTYPE_CONST );
688+ }
681689 } else {
682- rpc = nc_rpc_getdata ("ietf-datastores:operational" ,
683- "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"/>" , "false" , NULL , 0 , 0 , 0 , 0 ,
684- 0 , NC_PARAMTYPE_CONST );
690+ rpc_name = "get" ;
691+ if (nc_session_cpblt (session , "urn:ietf:params:netconf:capability:xpath:1.0" )) {
692+ rpc = nc_rpc_get ("/ietf-yang-library:*" , 0 , NC_PARAMTYPE_CONST );
693+ } else {
694+ rpc = nc_rpc_get ("<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"/>" , 0 ,
695+ NC_PARAMTYPE_CONST );
696+ }
685697 }
686698 if (!rpc ) {
687699 goto cleanup ;
@@ -702,34 +714,34 @@ build_schema_info_yl(struct nc_session *session, struct schema_info **result)
702714 msg = nc_recv_reply (session , rpc , msgid , NC_READ_ACT_TIMEOUT * 1000 , & envp , & op );
703715 } while (msg == NC_MSG_NOTIF || msg == NC_MSG_REPLY_ERR_MSGID );
704716 if (msg == NC_MSG_WOULDBLOCK ) {
705- WRN (session , "Timeout for receiving reply to a <get-data > yang-library data expired." );
717+ WRN (session , "Timeout for receiving reply to a <%s > yang-library data expired." , rpc_name );
706718 goto cleanup ;
707719 } else if (msg == NC_MSG_ERROR ) {
708- WRN (session , "Failed to receive a reply to <get-data > of yang-library data." );
720+ WRN (session , "Failed to receive a reply to <%s > of yang-library data." , rpc_name );
709721 goto cleanup ;
710722 } else if (!op || !lyd_child (op ) || strcmp (lyd_child (op )-> schema -> name , "data" )) {
711- WRN (session , "Unexpected reply without data to a yang-library <get-data > RPC." );
723+ WRN (session , "Unexpected reply without data to a yang-library <%s > RPC." , rpc_name );
712724 goto cleanup ;
713725 }
714726
715727 data = (struct lyd_node_any * )lyd_child (op );
716728 if (data -> value_type != LYD_ANYDATA_DATATREE ) {
717- WRN (session , "Unexpected data in reply to a yang-library <get-data > RPC." );
729+ WRN (session , "Unexpected data in reply to a yang-library <%s > RPC." , rpc_name );
718730 goto cleanup ;
719731 } else if (!data -> value .tree ) {
720- WRN (session , "No data in reply to a yang-library <get-data > RPC." );
732+ WRN (session , "No data in reply to a yang-library <%s > RPC." , rpc_name );
721733 goto cleanup ;
722734 }
723735
724736 if (lyd_find_xpath (data -> value .tree , "/ietf-yang-library:modules-state/module" , & modules )) {
725- WRN (session , "No module information in reply to a yang-library <get-data > RPC." );
737+ WRN (session , "No module information in reply to a yang-library <%s > RPC." , rpc_name );
726738 goto cleanup ;
727739 }
728740
729741 (* result ) = calloc (modules -> count + 1 , sizeof * * result );
730742 if (!(* result )) {
731743 ERRMEM ;
732- ret = EXIT_FAILURE ;
744+ ret = -1 ;
733745 goto cleanup ;
734746 }
735747
@@ -758,7 +770,7 @@ build_schema_info_yl(struct nc_session *session, struct schema_info **result)
758770 ERRMEM ;
759771 free_schema_info (* result );
760772 * result = NULL ;
761- ret = EXIT_FAILURE ;
773+ ret = -1 ;
762774 goto cleanup ;
763775 }
764776 (* result )[u ].features [feature_count ] = strdup (lyd_get_value (iter ));
@@ -775,7 +787,7 @@ build_schema_info_yl(struct nc_session *session, struct schema_info **result)
775787 ERRMEM ;
776788 free_schema_info (* result );
777789 * result = NULL ;
778- ret = EXIT_FAILURE ;
790+ ret = -1 ;
779791 goto cleanup ;
780792 } else {
781793 v = 0 ;
@@ -822,7 +834,7 @@ build_schema_info_cpblts(char **cpblts, struct schema_info **result)
822834 (* result ) = calloc (u + 1 , sizeof * * result );
823835 if (!(* result )) {
824836 ERRMEM ;
825- return EXIT_FAILURE ;
837+ return -1 ;
826838 }
827839
828840 for (u = v = 0 ; cpblts [u ]; ++ u ) {
@@ -878,14 +890,14 @@ build_schema_info_cpblts(char **cpblts, struct schema_info **result)
878890 ++ v ;
879891 }
880892
881- return EXIT_SUCCESS ;
893+ return 0 ;
882894}
883895
884896static int
885897nc_ctx_fill (struct nc_session * session , struct schema_info * modules , ly_module_imp_clb user_clb , void * user_data ,
886898 int has_get_schema )
887899{
888- int ret = EXIT_FAILURE ;
900+ int ret = -1 ;
889901 struct lys_module * mod ;
890902 uint32_t u ;
891903
@@ -916,7 +928,7 @@ nc_ctx_fill(struct nc_session *session, struct schema_info *modules, ly_module_i
916928 }
917929
918930 /* success */
919- ret = EXIT_SUCCESS ;
931+ ret = 0 ;
920932
921933cleanup :
922934 return ret ;
@@ -938,7 +950,7 @@ nc_ctx_fill_ietf_netconf(struct nc_session *session, struct schema_info *modules
938950 }
939951 if (!ietfnc ) {
940952 ERR (session , "Loading base NETCONF schema failed." );
941- return 1 ;
953+ return - 1 ;
942954 }
943955
944956 /* set supported capabilities from ietf-netconf */
@@ -956,7 +968,7 @@ nc_ctx_fill_ietf_netconf(struct nc_session *session, struct schema_info *modules
956968int
957969nc_ctx_check_and_fill (struct nc_session * session )
958970{
959- int i , get_schema_support = 0 , yanglib_support = 0 , ret = -1 ;
971+ int i , get_schema_support = 0 , yanglib_support = 0 , get_data_support = 0 , ret = -1 ;
960972 ly_module_imp_clb old_clb = NULL ;
961973 void * old_data = NULL ;
962974 struct lys_module * mod = NULL ;
@@ -1045,18 +1057,17 @@ nc_ctx_check_and_fill(struct nc_session *session)
10451057 free (revision );
10461058
10471059 /* ietf-netconf-nmda is needed to issue get-data */
1048- if (nc_ctx_load_module (session , "ietf-netconf-nmda" , NULL , server_modules , old_clb , old_data ,
1060+ if (! nc_ctx_load_module (session , "ietf-netconf-nmda" , NULL , server_modules , old_clb , old_data ,
10491061 get_schema_support , & mod )) {
1050- WRN (session , "Loading NETCONF ietf-netconf-nmda schema failed, unable to use get-data to retrieve "
1051- "yang-library data." );
1052- yanglib_support = 0 ;
1062+ VRB (session , "Support for <get-data> from ietf-netcon-nmda found." );
1063+ get_data_support = 1 ;
10531064 }
10541065 }
10551066 }
10561067
10571068 /* prepare structured information about server's schemas */
10581069 if (yanglib_support ) {
1059- if (build_schema_info_yl (session , & sm )) {
1070+ if (build_schema_info_yl (session , get_data_support , & sm )) {
10601071 goto cleanup ;
10611072 } else if (!sm ) {
10621073 VRB (session , "Trying to use capabilities instead of ietf-yang-library data." );
0 commit comments