diff --git a/include/asterisk/json.h b/include/asterisk/json.h index 011359b92e8018151ffe3dfda9fc5e4046516e3e..02b617e80db5a524a67afea2454053bf993127e9 100644 --- a/include/asterisk/json.h +++ b/include/asterisk/json.h @@ -590,6 +590,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); +/*! + * \brief Get a string field from a JSON object. + * \since 13.26.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. * \since 12.0.0 diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 85393b4f95995d07532dca839cd9218764ec9797..0f0e8910e1b27d34594c42273dbe2f3112e52823 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -1354,6 +1354,21 @@ void ast_str_container_remove(struct ao2_container *str_container, const char *r */ char *ast_generate_random_string(char *buf, size_t size); +/*! + * \brief Compare strings for equality checking for NULL. + * \since 13.26.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 * \since 13.9.0 diff --git a/main/strings.c b/main/strings.c index 8102c3e9d0245d726de5fd9f9c22552d04fe4065..cdb19842d44b75996dabee7d3ff2fd7f8c705b7e 100644 --- a/main/strings.c +++ b/main/strings.c @@ -247,6 +247,15 @@ char *ast_generate_random_string(char *buf, size_t size) 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) { char *internal_op = (char *)op;