mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 03:08:45 +00:00
json.c/strings.c - Add a couple of utility functions
Added 'ast_json_object_string_get' to the JSON wrapper in order to make it a little easier to retrieve a string field from the JSON object. Also added an 'ast_strings_equal' function that safely checks (checks for NULLs) for equality between two strings. Change-Id: I26f0a16d61537505eb41b4b05ef2e6d67fc2541b
This commit is contained in:
@@ -561,6 +561,17 @@ size_t ast_json_object_size(struct ast_json *object);
|
|||||||
*/
|
*/
|
||||||
struct ast_json *ast_json_object_get(struct ast_json *object, const char *key);
|
struct ast_json *ast_json_object_get(struct ast_json *object, const char *key);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Get a string field from a JSON object.
|
||||||
|
* \since 16.3.0
|
||||||
|
*
|
||||||
|
* \param object JSON object.
|
||||||
|
* \param key Key of string field to look up.
|
||||||
|
* \return String value of given \a key.
|
||||||
|
* \return \c NULL on error, or key value is not a string.
|
||||||
|
*/
|
||||||
|
#define ast_json_object_string_get(object, key) ast_json_string_get(ast_json_object_get(object, key))
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Set a field in a JSON object.
|
* \brief Set a field in a JSON object.
|
||||||
* \since 12.0.0
|
* \since 12.0.0
|
||||||
|
@@ -1297,6 +1297,21 @@ void ast_str_container_remove(struct ao2_container *str_container, const char *r
|
|||||||
*/
|
*/
|
||||||
char *ast_generate_random_string(char *buf, size_t size);
|
char *ast_generate_random_string(char *buf, size_t size);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Compare strings for equality checking for NULL.
|
||||||
|
* \since 16.3.0
|
||||||
|
*
|
||||||
|
* This function considers NULL values as non-strings, thus a false condition.
|
||||||
|
* This means that it will return false if one, or both of the given values are
|
||||||
|
* NULL (i.e. two NULLs are not equal strings).
|
||||||
|
*
|
||||||
|
* \param str1 The string to compare to str2
|
||||||
|
* \param str2 The string to compare to str1
|
||||||
|
*
|
||||||
|
* \return true if valid strings and equal, false otherwise.
|
||||||
|
*/
|
||||||
|
int ast_strings_equal(const char *str1, const char *str2);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Compares 2 strings using realtime-style operators
|
* \brief Compares 2 strings using realtime-style operators
|
||||||
* \since 13.9.0
|
* \since 13.9.0
|
||||||
|
@@ -236,6 +236,15 @@ char *ast_generate_random_string(char *buf, size_t size)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ast_strings_equal(const char *str1, const char *str2)
|
||||||
|
{
|
||||||
|
if (!str1 || !str2) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str1 == str2 || !strcmp(str1, str2);
|
||||||
|
}
|
||||||
|
|
||||||
int ast_strings_match(const char *left, const char *op, const char *right)
|
int ast_strings_match(const char *left, const char *op, const char *right)
|
||||||
{
|
{
|
||||||
char *internal_op = (char *)op;
|
char *internal_op = (char *)op;
|
||||||
|
Reference in New Issue
Block a user