@@ -1172,33 +1172,42 @@ nc_ctx_fill_ietf_netconf(struct nc_session *session, struct module_info *modules
11721172 return 0 ;
11731173}
11741174
1175- /**
1176- * @brief Set client session context to support schema-mount if possible.
1177- *
1178- * @param[in] session NC session with the context to modify.
1179- * @param[in] get_data_sup Whether get-data RPC is available or only get.
1180- * @param[in] xpath_sup Whether XPath filter is supported or only subtree filter.
1181- * @return 0 on success.
1182- * @return -1 on error.
1183- */
1184- static int
1185- nc_ctx_schema_mount (struct nc_session * session , int get_data_sup , int xpath_sup )
1175+ API int
1176+ nc_client_set_new_session_context_schema_mount (struct nc_session * session )
11861177{
1187- int rc = 0 ;
1178+ int rc = 0 , yanglib_support = 0 , xpath_support = 0 , nmda_support = 0 ;
11881179 struct lyd_node * oper_data = NULL ;
1180+ const struct lys_module * mod ;
11891181
11901182 if (session -> flags & NC_SESSION_SHAREDCTX ) {
11911183 /* context is already fully set up */
11921184 goto cleanup ;
11931185 }
11941186
1187+ /* check all useful capabilities */
1188+ if (ly_ctx_get_module_implemented (session -> ctx , "ietf-yang-library" )) {
1189+ yanglib_support = 1 ;
1190+ }
1191+ if ((mod = ly_ctx_get_module_implemented (session -> ctx , "ietf-netconf" )) && !lys_feature_value (mod , "xpath" )) {
1192+ xpath_support = 1 ;
1193+ }
1194+ if (ly_ctx_get_module_implemented (session -> ctx , "ietf-netconf-nmda" )) {
1195+ nmda_support = 1 ;
1196+ }
1197+
1198+ if (!yanglib_support ) {
1199+ ERR (session , "Module \"ietf-yang-library\" missing to retrieve schema-mount data." );
1200+ rc = -1 ;
1201+ goto cleanup ;
1202+ }
1203+
11951204 /* get yang-library and schema-mounts operational data */
1196- if (xpath_sup ) {
1197- if ((rc = get_oper_data (session , get_data_sup , "/ietf-yang-library:* | /ietf-yang-schema-mount:*" , & oper_data ))) {
1205+ if (xpath_support ) {
1206+ if ((rc = get_oper_data (session , nmda_support , "/ietf-yang-library:* | /ietf-yang-schema-mount:*" , & oper_data ))) {
11981207 goto cleanup ;
11991208 }
12001209 } else {
1201- if ((rc = get_oper_data (session , get_data_sup ,
1210+ if ((rc = get_oper_data (session , nmda_support ,
12021211 "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"/>"
12031212 "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\"/>" , & oper_data ))) {
12041213 goto cleanup ;
@@ -1218,6 +1227,7 @@ nc_ctx_schema_mount(struct nc_session *session, int get_data_sup, int xpath_sup)
12181227 }
12191228
12201229 /* store the data in the session */
1230+ lyd_free_siblings (session -> opts .client .ext_data );
12211231 session -> opts .client .ext_data = oper_data ;
12221232 oper_data = NULL ;
12231233
@@ -1316,7 +1326,7 @@ nc_ctx_check_and_fill(struct nc_session *session)
13161326
13171327 /* prepare structured information about server's modules */
13181328 if (yanglib_support ) {
1319- if (build_module_info_yl (session , nmda_support , xpath_support , & sm )) {
1329+ if (build_module_info_yl (session , 0 , xpath_support , & sm )) {
13201330 goto cleanup ;
13211331 } else if (!sm ) {
13221332 VRB (session , "Trying to use capabilities instead of ietf-yang-library data." );
@@ -1338,7 +1348,6 @@ nc_ctx_check_and_fill(struct nc_session *session)
13381348 if (nmda_support && nc_ctx_load_module (session , "ietf-netconf-nmda" , NULL , NULL , server_modules , old_clb ,
13391349 old_data , get_schema_support , & mod )) {
13401350 WRN (session , "Loading NMDA module failed, unable to use <get-data>." );
1341- nmda_support = 0 ;
13421351 }
13431352 }
13441353 }
@@ -1357,7 +1366,7 @@ nc_ctx_check_and_fill(struct nc_session *session)
13571366 }
13581367
13591368 /* set support for schema-mount, if possible (requires ietf-yang-library support) */
1360- if (yanglib_support && nc_ctx_schema_mount (session , nmda_support , xpath_support )) {
1369+ if (yanglib_support && nc_client_set_new_session_context_schema_mount (session )) {
13611370 goto cleanup ;
13621371 }
13631372
0 commit comments