@@ -340,16 +340,17 @@ 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 ;
353354 * type_hint_p = 0 ;
354355
355356 if (* status_p == LYJSON_ARRAY ) {
@@ -383,6 +384,10 @@ lydjson_value_type_hint(struct lyjson_ctx *jsonctx, enum LYJSON_PARSER_STATUS *s
383384 return LY_EINVAL ;
384385 }
385386
387+ if (lydctx -> parse_opts & LYD_PARSE_JSON_STRING_DATATYPES ) {
388+ * type_hint_p |= LYD_VALHINT_STRING_DATATYPES ;
389+ }
390+
386391 return LY_SUCCESS ;
387392}
388393
@@ -391,15 +396,16 @@ lydjson_value_type_hint(struct lyjson_ctx *jsonctx, enum LYJSON_PARSER_STATUS *s
391396 *
392397 * Checks for all the list's keys. Function does not revert the context state.
393398 *
394- * @param[in] jsonctx JSON parser context.
399+ * @param[in] lydctx JSON data parser context.
395400 * @param[in] list List schema node corresponding to the input data object.
396401 * @return LY_SUCCESS in case the data are ok for the @p list
397402 * @return LY_ENOT in case the input data are not sufficient to fully parse the list instance.
398403 */
399404static LY_ERR
400- lydjson_check_list (struct lyjson_ctx * jsonctx , const struct lysc_node * list )
405+ lydjson_check_list (struct lyd_json_ctx * lydctx , const struct lysc_node * list )
401406{
402407 LY_ERR rc = LY_SUCCESS ;
408+ struct lyjson_ctx * jsonctx = lydctx -> jsonctx ;
403409 enum LYJSON_PARSER_STATUS status = lyjson_ctx_status (jsonctx );
404410 struct ly_set key_set = {0 };
405411 const struct lysc_node * snode ;
@@ -451,7 +457,7 @@ lydjson_check_list(struct lyjson_ctx *jsonctx, const struct lysc_node *list)
451457 goto cleanup ;
452458 }
453459
454- rc = lydjson_value_type_hint (jsonctx , & status , & hints );
460+ rc = lydjson_value_type_hint (lydctx , & status , & hints );
455461 LY_CHECK_GOTO (rc , cleanup );
456462 rc = ly_value_validate (NULL , snode , jsonctx -> value , jsonctx -> value_len , LY_VALUE_JSON , NULL , hints );
457463 LY_CHECK_GOTO (rc , cleanup );
@@ -521,7 +527,7 @@ lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *sno
521527 case LYS_LEAFLIST :
522528 case LYS_LEAF :
523529 /* 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 ))) {
530+ if ((ret = lydjson_value_type_hint (lydctx , & status , type_hint_p ))) {
525531 break ;
526532 }
527533
@@ -533,14 +539,14 @@ lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *sno
533539 break ;
534540 case LYS_LIST :
535541 /* lists may not have all its keys */
536- if (lydjson_check_list (jsonctx , snode )) {
542+ if (lydjson_check_list (lydctx , snode )) {
537543 /* invalid list, parse as opaque if it misses/has invalid some keys */
538544 ret = LY_ENOT ;
539545 }
540546 break ;
541547 }
542548 } else if (snode -> nodetype & LYD_NODE_TERM ) {
543- ret = lydjson_value_type_hint (jsonctx , & status , type_hint_p );
549+ ret = lydjson_value_type_hint (lydctx , & status , type_hint_p );
544550 }
545551
546552 /* restore parser */
@@ -852,7 +858,7 @@ lydjson_metadata(struct lyd_json_ctx *lydctx, const struct lysc_node *snode, str
852858 LY_CHECK_GOTO (rc = lyjson_ctx_next (lydctx -> jsonctx , & status ), cleanup );
853859
854860 /* get value hints */
855- LY_CHECK_GOTO (rc = lydjson_value_type_hint (lydctx -> jsonctx , & status , & val_hints ), cleanup );
861+ LY_CHECK_GOTO (rc = lydjson_value_type_hint (lydctx , & status , & val_hints ), cleanup );
856862
857863 if (node -> schema ) {
858864 /* create metadata */
@@ -981,7 +987,7 @@ lydjson_create_opaq(struct lyd_json_ctx *lydctx, const char *name, size_t name_l
981987 dynamic = lydctx -> jsonctx -> dynamic ;
982988 lydctx -> jsonctx -> dynamic = 0 ;
983989
984- LY_CHECK_RET (lydjson_value_type_hint (lydctx -> jsonctx , status_inner_p , & type_hint ));
990+ LY_CHECK_RET (lydjson_value_type_hint (lydctx , status_inner_p , & type_hint ));
985991 }
986992
987993 /* get the module name */
0 commit comments