diff options
author | Richard Mudgett <rmudgett@digium.com> | 2016-10-11 18:14:39 -0500 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2016-10-13 18:11:36 -0500 |
commit | 9621c9bcbca70f61605606db8517a789f53f8600 (patch) | |
tree | abe9d0283acaf7d438642abe071cb0ed3e72f7b8 /include | |
parent | 3633c7926cdc102570a5f179aae8a9017bd0a034 (diff) |
json: Add UTF-8 check call.
Since the json library does not make the check function public we
recreate/copy the function in our interface module.
ASTERISK-26466
Reported by: Richard Mudgett
Change-Id: I36d3d750b6f5f1a110bc69ea92b435ecdeeb2a99
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/json.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/include/asterisk/json.h b/include/asterisk/json.h index 28ebfbd51..cfd9a2997 100644 --- a/include/asterisk/json.h +++ b/include/asterisk/json.h @@ -217,6 +217,41 @@ const char *ast_json_typename(enum ast_json_type type); /*!@{*/ /*! + * \brief Check the string of the given length for UTF-8 format. + * \since 13.12.0 + * + * \param str String to check. + * \param len Length of string to check. + * + * \retval 0 if not UTF-8 encoded or str is NULL. + * \retval 1 if UTF-8 encoded. + */ +int ast_json_utf8_check_len(const char *str, size_t len); + +/*! + * \brief Check the nul terminated string for UTF-8 format. + * \since 13.12.0 + * + * \param str String to check. + * + * \retval 0 if not UTF-8 encoded or str is NULL. + * \retval 1 if UTF-8 encoded. + */ +int ast_json_utf8_check(const char *str); + +/*! + * \brief Check str for UTF-8 and replace with an empty string if fails the check. + * + * \note The convenience macro is normally used with ast_json_pack() + * or a function wrapper that calls ast_json_vpack(). + */ +#define AST_JSON_UTF8_VALIDATE(str) (ast_json_utf8_check(str) ? (str) : "") + +/*!@}*/ + +/*!@{*/ + +/*! * \brief Get the JSON true value. * \since 12.0.0 * |