type CHANGE make type_check_hints() public for type plugins API
Rename the function to ly_type_check_hints(), the function is in general
useful for implementation of ly_type_store_clb in type plugins.
diff --git a/src/plugins_types.c b/src/plugins_types.c
index 4aebfcd..9b32b6f 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -689,14 +689,13 @@
}
}
-/**
- * @brief Answer if the type is suitable for the parser's hit (if any) in the specified format
- */
-static LY_ERR
-type_check_hints(uint32_t hints, const char *value, size_t value_len, LY_DATA_TYPE type, int *base, struct ly_err_item **err)
+API LY_ERR
+ly_type_check_hints(uint32_t hints, const char *value, size_t value_len, LY_DATA_TYPE type, int *base, struct ly_err_item **err)
{
LY_ERR ret = LY_SUCCESS;
+ LY_CHECK_ARG_RET(NULL, value, err, LY_EINVAL);
+
switch (type) {
case LY_TYPE_UINT8:
case LY_TYPE_UINT16:
@@ -704,6 +703,8 @@
case LY_TYPE_INT8:
case LY_TYPE_INT16:
case LY_TYPE_INT32:
+ LY_CHECK_ARG_RET(NULL, base, LY_EINVAL);
+
if (!(hints & (LYD_VALHINT_DECNUM | LYD_VALHINT_OCTNUM | LYD_VALHINT_HEXNUM))) {
ret = LY_EVALID;
*err = ly_err_msg_create(&ret, LYVE_DATA, NULL, NULL,
@@ -715,6 +716,8 @@
break;
case LY_TYPE_UINT64:
case LY_TYPE_INT64:
+ LY_CHECK_ARG_RET(NULL, base, LY_EINVAL);
+
if (!(hints & LYD_VALHINT_NUM64)) {
ret = LY_EVALID;
*err = ly_err_msg_create(&ret, LYVE_DATA, NULL, NULL,
@@ -784,7 +787,7 @@
struct lysc_type_num *type_num = (struct lysc_type_num *)type;
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, &base, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, &base, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
switch (type->basetype) {
@@ -846,7 +849,7 @@
char *str;
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, &base, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, &base, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
switch (type->basetype) {
@@ -912,7 +915,7 @@
}
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, NULL, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
ret = ly_type_parse_dec64(type_dec->fraction_digits, value, value_len, &d, err);
@@ -980,7 +983,7 @@
LY_CHECK_ARG_RET(ctx, value, LY_EINVAL);
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, NULL, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
/* validate characters and remember the number of octets for length validation */
@@ -1079,7 +1082,7 @@
struct lysc_type_str *type_str = (struct lysc_type_str *)type;
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, NULL, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
/* length restriction of the string */
@@ -1142,7 +1145,7 @@
const char *can = NULL;
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, NULL, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup_value);
/* remember the present items for further work */
@@ -1312,7 +1315,7 @@
struct lysc_type_enum *type_enum = (struct lysc_type_enum *)type;
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, NULL, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
/* find the matching enumeration value item */
@@ -1365,7 +1368,7 @@
int8_t i;
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, NULL, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
if ((value_len == ly_strlen_const("true")) && !strncmp(value, "true", ly_strlen_const("true"))) {
@@ -1411,7 +1414,7 @@
LY_ERR ret = LY_SUCCESS;
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, NULL, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
if (value_len) {
@@ -1495,7 +1498,7 @@
ly_bool dyn;
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, NULL, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup);
/* locate prefix if any */
@@ -1676,7 +1679,7 @@
*err = NULL;
/* check hints */
- ret = type_check_hints(hints, value, value_len, type->basetype, NULL, err);
+ ret = ly_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
LY_CHECK_GOTO(ret != LY_SUCCESS, cleanup_value);
switch (format) {
diff --git a/src/plugins_types.h b/src/plugins_types.h
index aaff4be..ff81961 100644
--- a/src/plugins_types.h
+++ b/src/plugins_types.h
@@ -102,6 +102,24 @@
void ly_err_free(void *ptr);
/**
+ * @brief Check that the type is suitable for the parser's hints (if any) in the specified format
+ *
+ * Use only in implementations of ::ly_type_store_clb which provide all the necessary parameters for this function.
+ *
+ * @param[in] hints Bitmap of [value hints](@ref lydvalhints) of all the allowed value types provided by parsers
+ * to ::ly_type_store_clb.
+ * @param[in] value Lexical representation of the value to be stored.
+ * @param[in] value_len Length (number of bytes) of the given \p value.
+ * @param[in] type Expected base type of the @p value by the caller.
+ * @param[out] base Pointer to store the numeric base for parsing numeric values using strtol()/strtoll() function.
+ * Returned (and required) only for numeric @p type values.
+ * @param[out] err Pointer to store error information in case of failure.
+ * @return LY_ERR value
+ */
+LY_ERR ly_type_check_hints(uint32_t hints, const char *value, size_t value_len, LY_DATA_TYPE type, int *base,
+ struct ly_err_item **err);
+
+/**
* @brief Resolve format-specific prefixes to modules.
*
* Use only in implementations of ::ly_type_store_clb which provide all the necessary parameters for this function.
diff --git a/tests/utests/types/string.c b/tests/utests/types/string.c
index cc58f68..21551c9 100644
--- a/tests/utests/types/string.c
+++ b/tests/utests/types/string.c
@@ -1090,7 +1090,7 @@
val_text = "20";
ly_ret = type->store(UTEST_LYCTX, &lysc_type_test, val_text, strlen(val_text),
0, LY_PREF_XML, NULL, LYD_VALHINT_STRING, NULL, &value, NULL, &err);
- assert_int_equal(LY_EVALID, ly_ret);
+ assert_int_equal(LY_EINVAL, ly_ret);
ly_err_free(err);
/* ERROR TESTS */