@@ -340,16 +340,18 @@ lydjson_get_snode(struct lyd_json_ctx *lydctx, ly_bool is_attr, const char *pref
340340/**
341341 * @brief Get the hint for the data type parsers according to the current JSON parser context.
342342 *
343- * @param[in] jsonctx JSON parser context. The context is supposed to be on a value .
343+ * @param[in] lydctx JSON data parser context.
344344 * @param[in,out] status Pointer to the current context status,
345345 * in some circumstances the function manipulates with the context so the status is updated.
346346 * @param[out] type_hint_p Pointer to the variable to store the result.
347347 * @return LY_SUCCESS in case of success.
348348 * @return LY_EINVAL in case of invalid context status not referring to a value.
349349 */
350350static LY_ERR
351- lydjson_value_type_hint (struct lyjson_ctx * jsonctx , enum LYJSON_PARSER_STATUS * status_p , uint32_t * type_hint_p )
351+ lydjson_value_type_hint (struct lyd_json_ctx * lydctx , enum LYJSON_PARSER_STATUS * status_p , uint32_t * type_hint_p )
352352{
353+ struct lyjson_ctx * jsonctx = lydctx -> jsonctx ;
354+
353355 * type_hint_p = 0 ;
354356
355357 if (* status_p == LYJSON_ARRAY ) {
@@ -383,6 +385,10 @@ lydjson_value_type_hint(struct lyjson_ctx *jsonctx, enum LYJSON_PARSER_STATUS *s
383385 return LY_EINVAL ;
384386 }
385387
388+ if (lydctx -> parse_opts & LYD_PARSE_JSON_STRING_DATATYPES ) {
389+ * type_hint_p |= LYD_VALHINT_STRING_DATATYPES ;
390+ }
391+
386392 return LY_SUCCESS ;
387393}
388394
@@ -391,15 +397,16 @@ lydjson_value_type_hint(struct lyjson_ctx *jsonctx, enum LYJSON_PARSER_STATUS *s
391397 *
392398 * Checks for all the list's keys. Function does not revert the context state.
393399 *
394- * @param[in] jsonctx JSON parser context.
400+ * @param[in] lydctx JSON data parser context.
395401 * @param[in] list List schema node corresponding to the input data object.
396402 * @return LY_SUCCESS in case the data are ok for the @p list
397403 * @return LY_ENOT in case the input data are not sufficient to fully parse the list instance.
398404 */
399405static LY_ERR
400- lydjson_check_list (struct lyjson_ctx * jsonctx , const struct lysc_node * list )
406+ lydjson_check_list (struct lyd_json_ctx * lydctx , const struct lysc_node * list )
401407{
402408 LY_ERR rc = LY_SUCCESS ;
409+ struct lyjson_ctx * jsonctx = lydctx -> jsonctx ;
403410 enum LYJSON_PARSER_STATUS status = lyjson_ctx_status (jsonctx );
404411 struct ly_set key_set = {0 };
405412 const struct lysc_node * snode ;
@@ -451,7 +458,7 @@ lydjson_check_list(struct lyjson_ctx *jsonctx, const struct lysc_node *list)
451458 goto cleanup ;
452459 }
453460
454- rc = lydjson_value_type_hint (jsonctx , & status , & hints );
461+ rc = lydjson_value_type_hint (lydctx , & status , & hints );
455462 LY_CHECK_GOTO (rc , cleanup );
456463 rc = ly_value_validate (NULL , snode , jsonctx -> value , jsonctx -> value_len , LY_VALUE_JSON , NULL , hints );
457464 LY_CHECK_GOTO (rc , cleanup );
@@ -521,7 +528,7 @@ lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *sno
521528 case LYS_LEAFLIST :
522529 case LYS_LEAF :
523530 /* value may not be valid in which case we parse it as an opaque node */
524- if ((ret = lydjson_value_type_hint (jsonctx , & status , type_hint_p ))) {
531+ if ((ret = lydjson_value_type_hint (lydctx , & status , type_hint_p ))) {
525532 break ;
526533 }
527534
@@ -533,14 +540,14 @@ lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *sno
533540 break ;
534541 case LYS_LIST :
535542 /* lists may not have all its keys */
536- if (lydjson_check_list (jsonctx , snode )) {
543+ if (lydjson_check_list (lydctx , snode )) {
537544 /* invalid list, parse as opaque if it misses/has invalid some keys */
538545 ret = LY_ENOT ;
539546 }
540547 break ;
541548 }
542549 } else if (snode -> nodetype & LYD_NODE_TERM ) {
543- ret = lydjson_value_type_hint (jsonctx , & status , type_hint_p );
550+ ret = lydjson_value_type_hint (lydctx , & status , type_hint_p );
544551 }
545552
546553 /* restore parser */
@@ -852,7 +859,7 @@ lydjson_metadata(struct lyd_json_ctx *lydctx, const struct lysc_node *snode, str
852859 LY_CHECK_GOTO (rc = lyjson_ctx_next (lydctx -> jsonctx , & status ), cleanup );
853860
854861 /* get value hints */
855- LY_CHECK_GOTO (rc = lydjson_value_type_hint (lydctx -> jsonctx , & status , & val_hints ), cleanup );
862+ LY_CHECK_GOTO (rc = lydjson_value_type_hint (lydctx , & status , & val_hints ), cleanup );
856863
857864 if (node -> schema ) {
858865 /* create metadata */
@@ -981,7 +988,7 @@ lydjson_create_opaq(struct lyd_json_ctx *lydctx, const char *name, size_t name_l
981988 dynamic = lydctx -> jsonctx -> dynamic ;
982989 lydctx -> jsonctx -> dynamic = 0 ;
983990
984- LY_CHECK_RET (lydjson_value_type_hint (lydctx -> jsonctx , status_inner_p , & type_hint ));
991+ LY_CHECK_RET (lydjson_value_type_hint (lydctx , status_inner_p , & type_hint ));
985992 }
986993
987994 /* get the module name */
0 commit comments