@@ -1763,7 +1763,7 @@ lyd_diff_apply_metadata(struct lyd_node *node, const struct lyd_node *diff_node)
17631763/**
17641764 * @brief Apply diff subtree on data tree nodes, recursively.
17651765 *
1766- * @param[in,out] first_node First sibling of the data tree .
1766+ * @param[in,out] first_node First sibling of the subtree .
17671767 * @param[in] parent_node Parent of the first sibling.
17681768 * @param[in] diff_node Current diff node.
17691769 * @param[in] diff_cb Optional diff callback.
@@ -1949,6 +1949,41 @@ lyd_diff_apply_all(struct lyd_node **data, const struct lyd_node *diff)
19491949 return lyd_diff_apply_module (data , diff , NULL , NULL , NULL );
19501950}
19511951
1952+ LIBYANG_API_DEF LY_ERR
1953+ lyd_diff_apply_node (struct lyd_node * data_parent , struct lyd_node * * data_first , const struct lyd_node * diff_node )
1954+ {
1955+ LY_ERR ret = LY_SUCCESS ;
1956+ struct ly_ht * dup_inst = NULL ;
1957+
1958+ LY_CHECK_ARG_RET (NULL , data_parent || data_first , diff_node , LY_EINVAL );
1959+
1960+ /* diff_node is top level node, data_parent must be NULL */
1961+ if (!diff_node -> parent && data_parent ) {
1962+ LOGERR (LYD_CTX (diff_node ), LY_EINVAL , "data_parent must be NULL when applying top-level diff_node." );
1963+ return LY_EINVAL ;
1964+ }
1965+
1966+ if (!data_first ) {
1967+ data_first = lyd_node_child_p (data_parent );
1968+ }
1969+
1970+ /* diff_node is top level node, data_first must be set */
1971+ if (!diff_node -> parent && !data_first ) {
1972+ LOGERR (LYD_CTX (diff_node ), LY_EINVAL , "data_first is not set, when working with top-level node." );
1973+ return LY_EINVAL ;
1974+ }
1975+
1976+ if (diff_node -> parent && data_parent && (diff_node -> parent -> schema != data_parent -> schema )) {
1977+ LOGERR (LYD_CTX (diff_node ), LY_EINVAL , "Schemas of data_parent and diff_node do not match." );
1978+ return LY_EINVAL ;
1979+ }
1980+
1981+ ret = lyd_diff_apply_r (data_first , data_parent , diff_node , NULL , NULL , & dup_inst );
1982+
1983+ lyd_dup_inst_free (dup_inst );
1984+ return ret ;
1985+ }
1986+
19521987/**
19531988 * @brief Update operations on a diff node when the new operation is NONE.
19541989 *
0 commit comments