@@ -340,16 +340,18 @@ lydjson_get_snode(struct lyd_json_ctx *lydctx, ly_bool is_attr, const char *pref
340
340
/**
341
341
* @brief Get the hint for the data type parsers according to the current JSON parser context.
342
342
*
343
- * @param[in] jsonctx JSON parser context. The context is supposed to be on a value .
343
+ * @param[in] lydctx JSON data parser context.
344
344
* @param[in,out] status Pointer to the current context status,
345
345
* in some circumstances the function manipulates with the context so the status is updated.
346
346
* @param[out] type_hint_p Pointer to the variable to store the result.
347
347
* @return LY_SUCCESS in case of success.
348
348
* @return LY_EINVAL in case of invalid context status not referring to a value.
349
349
*/
350
350
static 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 )
352
352
{
353
+ struct lyjson_ctx * jsonctx = lydctx -> jsonctx ;
354
+
353
355
* type_hint_p = 0 ;
354
356
355
357
if (* status_p == LYJSON_ARRAY ) {
@@ -383,6 +385,10 @@ lydjson_value_type_hint(struct lyjson_ctx *jsonctx, enum LYJSON_PARSER_STATUS *s
383
385
return LY_EINVAL ;
384
386
}
385
387
388
+ if (lydctx -> parse_opts & LYD_PARSE_JSON_STRING_DATATYPES ) {
389
+ * type_hint_p |= LYD_VALHINT_STRING_DATATYPES ;
390
+ }
391
+
386
392
return LY_SUCCESS ;
387
393
}
388
394
@@ -391,15 +397,16 @@ lydjson_value_type_hint(struct lyjson_ctx *jsonctx, enum LYJSON_PARSER_STATUS *s
391
397
*
392
398
* Checks for all the list's keys. Function does not revert the context state.
393
399
*
394
- * @param[in] jsonctx JSON parser context.
400
+ * @param[in] lydctx JSON data parser context.
395
401
* @param[in] list List schema node corresponding to the input data object.
396
402
* @return LY_SUCCESS in case the data are ok for the @p list
397
403
* @return LY_ENOT in case the input data are not sufficient to fully parse the list instance.
398
404
*/
399
405
static 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 )
401
407
{
402
408
LY_ERR rc = LY_SUCCESS ;
409
+ struct lyjson_ctx * jsonctx = lydctx -> jsonctx ;
403
410
enum LYJSON_PARSER_STATUS status = lyjson_ctx_status (jsonctx );
404
411
struct ly_set key_set = {0 };
405
412
const struct lysc_node * snode ;
@@ -451,7 +458,7 @@ lydjson_check_list(struct lyjson_ctx *jsonctx, const struct lysc_node *list)
451
458
goto cleanup ;
452
459
}
453
460
454
- rc = lydjson_value_type_hint (jsonctx , & status , & hints );
461
+ rc = lydjson_value_type_hint (lydctx , & status , & hints );
455
462
LY_CHECK_GOTO (rc , cleanup );
456
463
rc = ly_value_validate (NULL , snode , jsonctx -> value , jsonctx -> value_len , LY_VALUE_JSON , NULL , hints );
457
464
LY_CHECK_GOTO (rc , cleanup );
@@ -521,7 +528,7 @@ lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *sno
521
528
case LYS_LEAFLIST :
522
529
case LYS_LEAF :
523
530
/* 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 ))) {
525
532
break ;
526
533
}
527
534
@@ -533,14 +540,14 @@ lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *sno
533
540
break ;
534
541
case LYS_LIST :
535
542
/* lists may not have all its keys */
536
- if (lydjson_check_list (jsonctx , snode )) {
543
+ if (lydjson_check_list (lydctx , snode )) {
537
544
/* invalid list, parse as opaque if it misses/has invalid some keys */
538
545
ret = LY_ENOT ;
539
546
}
540
547
break ;
541
548
}
542
549
} 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 );
544
551
}
545
552
546
553
/* restore parser */
@@ -852,7 +859,7 @@ lydjson_metadata(struct lyd_json_ctx *lydctx, const struct lysc_node *snode, str
852
859
LY_CHECK_GOTO (rc = lyjson_ctx_next (lydctx -> jsonctx , & status ), cleanup );
853
860
854
861
/* 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 );
856
863
857
864
if (node -> schema ) {
858
865
/* create metadata */
@@ -981,7 +988,7 @@ lydjson_create_opaq(struct lyd_json_ctx *lydctx, const char *name, size_t name_l
981
988
dynamic = lydctx -> jsonctx -> dynamic ;
982
989
lydctx -> jsonctx -> dynamic = 0 ;
983
990
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 ));
985
992
}
986
993
987
994
/* get the module name */
0 commit comments