@@ -719,7 +719,7 @@ lydjson_metadata_finish(struct lyd_json_ctx *lydctx, struct lyd_node **first_p)
719719}
720720
721721/**
722- * @brief Parse a metadata member.
722+ * @brief Parse a metadata member/attribute .
723723 *
724724 * @param[in] lydctx JSON data parser context.
725725 * @param[in] snode Schema node of the metadata parent.
@@ -730,7 +730,7 @@ lydjson_metadata_finish(struct lyd_json_ctx *lydctx, struct lyd_node **first_p)
730730 * @return Various LY_ERR values in case of failure.
731731 */
732732static LY_ERR
733- lydjson_metadata (struct lyd_json_ctx * lydctx , const struct lysc_node * snode , struct lyd_node * node )
733+ lydjson_meta_attr (struct lyd_json_ctx * lydctx , const struct lysc_node * snode , struct lyd_node * node )
734734{
735735 LY_ERR rc = LY_SUCCESS , r ;
736736 enum LYJSON_PARSER_STATUS status ;
@@ -1188,21 +1188,20 @@ lydjson_parse_attribute(struct lyd_json_ctx *lydctx, struct lyd_node *attr_node,
11881188 enum LYJSON_PARSER_STATUS * status_p , struct lyd_node * * first_p , struct lyd_node * * node_p )
11891189{
11901190 LY_ERR r ;
1191- const char * opaq_name , * mod_name ;
1192- size_t opaq_name_len ;
1191+ const char * opaq_name , * mod_name , * attr_mod ;
1192+ size_t opaq_name_len , attr_mod_len ;
11931193
1194- if (!snode && !prefix ) {
1195- /* set the prefix */
1196- if (parent ) {
1197- lydjson_get_node_prefix (parent , NULL , 0 , & prefix , & prefix_len );
1198- } else {
1199- prefix = "" ;
1200- prefix_len = 0 ;
1194+ if (!attr_node ) {
1195+ /* learn the attribute module name */
1196+ if (!snode ) {
1197+ if (!prefix ) {
1198+ lydjson_get_node_prefix (parent , NULL , 0 , & attr_mod , & attr_mod_len );
1199+ } else {
1200+ attr_mod = prefix ;
1201+ attr_mod_len = prefix_len ;
1202+ }
12011203 }
1202- }
12031204
1204- /* parse as an attribute to a (opaque) node */
1205- if (!attr_node ) {
12061205 /* try to find the instance */
12071206 LY_LIST_FOR (parent ? lyd_child (parent ) : * first_p , attr_node ) {
12081207 if (snode ) {
@@ -1217,21 +1216,22 @@ lydjson_parse_attribute(struct lyd_json_ctx *lydctx, struct lyd_node *attr_node,
12171216 }
12181217 }
12191218 } else {
1219+ /* get the node module name */
12201220 if (attr_node -> schema ) {
1221- if (!ly_strncmp (LYD_NAME (attr_node ), name , name_len ) &&
1222- !ly_strncmp (attr_node -> schema -> module -> name , prefix , prefix_len )) {
1223- break ;
1224- }
1221+ mod_name = attr_node -> schema -> module -> name ;
12251222 } else {
12261223 mod_name = ((struct lyd_node_opaq * )attr_node )-> name .module_name ;
1227- if (!ly_strncmp (LYD_NAME (attr_node ), name , name_len ) && mod_name &&
1228- !ly_strncmp (mod_name , prefix , prefix_len )) {
1229- break ;
1230- }
1224+ }
1225+
1226+ /* check the attribute belongs to this node */
1227+ if (!ly_strncmp (LYD_NAME (attr_node ), name , name_len ) && mod_name && attr_mod &&
1228+ !ly_strncmp (mod_name , attr_mod , attr_mod_len )) {
1229+ break ;
12311230 }
12321231 }
12331232 }
12341233 }
1234+
12351235 if (!attr_node ) {
12361236 /* parse just as an opaq node with the name beginning with @,
12371237 * later we have to check that it belongs to a standard node
@@ -1251,7 +1251,7 @@ lydjson_parse_attribute(struct lyd_json_ctx *lydctx, struct lyd_node *attr_node,
12511251 lydctx -> parse_opts = prev_opts ;
12521252 LY_CHECK_RET (r );
12531253 } else {
1254- LY_CHECK_RET (lydjson_metadata (lydctx , snode , attr_node ));
1254+ LY_CHECK_RET (lydjson_meta_attr (lydctx , snode , attr_node ));
12551255 }
12561256
12571257 return LY_SUCCESS ;
@@ -1651,11 +1651,6 @@ lydjson_subtree_r(struct lyd_json_ctx *lydctx, struct lyd_node *parent, struct l
16511651 rc = r ;
16521652 goto cleanup ;
16531653 }
1654-
1655- if (!snode ) {
1656- /* we will not be parsing it as metadata */
1657- is_meta = 0 ;
1658- }
16591654 }
16601655
16611656 if (is_meta ) {
0 commit comments