@@ -253,10 +253,13 @@ lyplg_type_validate_instanceid(const struct ly_ctx *ctx, const struct lysc_type
253253}
254254
255255LIBYANG_API_DEF const void *
256- lyplg_type_print_instanceid (const struct ly_ctx * UNUSED ( ctx ) , const struct lyd_value * value , LY_VALUE_FORMAT format ,
256+ lyplg_type_print_instanceid (const struct ly_ctx * ctx , const struct lyd_value * value , LY_VALUE_FORMAT format ,
257257 void * prefix_data , ly_bool * dynamic , size_t * value_len )
258258{
259- char * ret ;
259+ char * ret = NULL ;
260+ struct ly_path * p = NULL ;
261+ const struct ly_path * target ;
262+ struct ly_err_item * err ;
260263
261264 if ((format == LY_VALUE_CANON ) || (format == LY_VALUE_JSON ) || (format == LY_VALUE_LYB )) {
262265 if (dynamic ) {
@@ -268,31 +271,64 @@ lyplg_type_print_instanceid(const struct ly_ctx *UNUSED(ctx), const struct lyd_v
268271 return value -> _canonical ;
269272 }
270273
274+ if (!value -> target ) {
275+ /* schema default value, compile it first */
276+ if (lyplg_type_lypath_new (ctx , value -> _canonical , strlen (value -> _canonical ), 0 , LY_VALUE_JSON , NULL , NULL ,
277+ NULL , & p , & err )) {
278+ if (err ) {
279+ ly_err_print (ctx , err );
280+ ly_err_free (err );
281+ }
282+ goto cleanup ;
283+ }
284+
285+ target = p ;
286+ } else {
287+ target = value -> target ;
288+ }
289+
271290 /* print the value in the specific format */
272- if (instanceid_path2str (value -> target , format , prefix_data , & ret )) {
273- return NULL ;
291+ if (instanceid_path2str (target , format , prefix_data , & ret )) {
292+ goto cleanup ;
274293 }
294+
275295 * dynamic = 1 ;
276296 if (value_len ) {
277297 * value_len = strlen (ret );
278298 }
299+
300+ cleanup :
301+ ly_path_free (p );
279302 return ret ;
280303}
281304
282305LIBYANG_API_DEF LY_ERR
283306lyplg_type_dup_instanceid (const struct ly_ctx * ctx , const struct lyd_value * original , struct lyd_value * dup )
284307{
285308 LY_ERR ret ;
309+ struct ly_err_item * err ;
286310
287311 memset (dup , 0 , sizeof * dup );
288312
289313 /* canonical value */
290314 ret = lydict_insert (ctx , original -> _canonical , 0 , & dup -> _canonical );
291315 LY_CHECK_GOTO (ret , error );
292316
293- /* copy path */
294- ret = ly_path_dup (ctx , original -> target , & dup -> target );
295- LY_CHECK_GOTO (ret , error );
317+ if (!original -> target ) {
318+ /* schema default value, needs to be compiled */
319+ if (lyplg_type_lypath_new (ctx , original -> _canonical , strlen (original -> _canonical ), 0 , LY_VALUE_JSON , NULL , NULL ,
320+ NULL , & dup -> target , & err )) {
321+ if (err ) {
322+ ly_err_print (ctx , err );
323+ ly_err_free (err );
324+ }
325+ goto error ;
326+ }
327+ } else {
328+ /* copy path */
329+ ret = ly_path_dup (ctx , original -> target , & dup -> target );
330+ LY_CHECK_GOTO (ret , error );
331+ }
296332
297333 dup -> realtype = original -> realtype ;
298334 return LY_SUCCESS ;
0 commit comments