diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h index 495733a6d0d99ab980a92d03d033431f36874fbb..b43c5ee94380531b81a9d6bc43d331735b6b0c17 100644 --- a/include/asterisk/astobj2.h +++ b/include/asterisk/astobj2.h @@ -1938,54 +1938,4 @@ void __ao2_cleanup_debug(void *obj, const char *file, int line, const char *func #endif void ao2_iterator_cleanup(struct ao2_iterator *iter); - -/* XXX TODO BUGBUG and all the other things... - * These functions should eventually be moved elsewhere, but the utils folder - * won't compile with them in strings.h - */ - -/*! - * \since 12 - * \brief Allocates a hash container for bare strings - * - * \param buckets The number of buckets to use for the hash container - * - * \retval AO2 container for strings - * \retval NULL if allocation failed - */ -#define ast_str_container_alloc(buckets) ast_str_container_alloc_options(AO2_ALLOC_OPT_LOCK_MUTEX, buckets) - -/*! - * \since 12 - * \brief Allocates a hash container for bare strings - * - * \param opts Options to be provided to the container - * \param buckets The number of buckets to use for the hash container - * - * \retval AO2 container for strings - * \retval NULL if allocation failed - */ -struct ao2_container *ast_str_container_alloc_options(enum ao2_container_opts opts, int buckets); - -/*! - * \since 12 - * \brief Adds a string to a string container allocated by ast_str_container_alloc - * - * \param str_container The container to which to add a string - * \param add The string to add to the container - * - * \retval zero on success - * \retval non-zero if the operation failed - */ -int ast_str_container_add(struct ao2_container *str_container, const char *add); - -/*! - * \since 12 - * \brief Removes a string from a string container allocated by ast_str_container_alloc - * - * \param str_container The container from which to remove a string - * \param remove The string to remove from the container - */ -void ast_str_container_remove(struct ao2_container *str_container, const char *remove); - #endif /* _ASTERISK_ASTOBJ2_H */ diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 30d2503d82211c6c5c0b7343bee5cfaee79080a3..fc92d4889f5567bd8341c7190a766e3954445df4 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -29,6 +29,7 @@ #include "asterisk/utils.h" #include "asterisk/threadstorage.h" +#include "asterisk/astobj2.h" #if defined(DEBUG_OPAQUE) #define __AST_STR_USED used2 @@ -1109,4 +1110,48 @@ static force_inline char *attribute_pure ast_str_to_upper(char *str) return str_orig; } +/*! + * \since 12 + * \brief Allocates a hash container for bare strings + * + * \param buckets The number of buckets to use for the hash container + * + * \retval AO2 container for strings + * \retval NULL if allocation failed + */ +#define ast_str_container_alloc(buckets) ast_str_container_alloc_options(AO2_ALLOC_OPT_LOCK_MUTEX, buckets) + +/*! + * \since 12 + * \brief Allocates a hash container for bare strings + * + * \param opts Options to be provided to the container + * \param buckets The number of buckets to use for the hash container + * + * \retval AO2 container for strings + * \retval NULL if allocation failed + */ +struct ao2_container *ast_str_container_alloc_options(enum ao2_container_opts opts, int buckets); + +/*! + * \since 12 + * \brief Adds a string to a string container allocated by ast_str_container_alloc + * + * \param str_container The container to which to add a string + * \param add The string to add to the container + * + * \retval zero on success + * \retval non-zero if the operation failed + */ +int ast_str_container_add(struct ao2_container *str_container, const char *add); + +/*! + * \since 12 + * \brief Removes a string from a string container allocated by ast_str_container_alloc + * + * \param str_container The container from which to remove a string + * \param remove The string to remove from the container + */ +void ast_str_container_remove(struct ao2_container *str_container, const char *remove); + #endif /* _ASTERISK_STRINGS_H */ diff --git a/main/astobj2.c b/main/astobj2.c index 5bfba4e68ad51eb6d840cca80cac6a18a393384b..bbe77859d1979821695e8292890e3ea76ac2c534 100644 --- a/main/astobj2.c +++ b/main/astobj2.c @@ -5797,40 +5797,3 @@ int astobj2_init(void) return 0; } -/* XXX TODO BUGBUG and all the other things... - * These functions should eventually be moved elsewhere, but the utils folder - * won't compile with them in strings.h - */ -static int str_hash(const void *obj, const int flags) -{ - return ast_str_hash(obj); -} - -static int str_cmp(void *lhs, void *rhs, int flags) -{ - return strcmp(lhs, rhs) ? 0 : CMP_MATCH; -} - -struct ao2_container *ast_str_container_alloc_options(enum ao2_container_opts opts, int buckets) -{ - return ao2_container_alloc_options(opts, buckets, str_hash, str_cmp); -} - -int ast_str_container_add(struct ao2_container *str_container, const char *add) -{ - RAII_VAR(char *, ao2_add, ao2_alloc(strlen(add) + 1, NULL), ao2_cleanup); - - if (!ao2_add) { - return -1; - } - - /* safe strcpy */ - strcpy(ao2_add, add); - ao2_link(str_container, ao2_add); - return 0; -} - -void ast_str_container_remove(struct ao2_container *str_container, const char *remove) -{ - ao2_find(str_container, remove, OBJ_KEY | OBJ_NODATA | OBJ_UNLINK); -} diff --git a/main/strings.c b/main/strings.c index d004da2278f2504284064f3f8ebba85d591f17b8..6633d5982b4a7513dd786289182c73b5fc3ebbfc 100644 --- a/main/strings.c +++ b/main/strings.c @@ -160,4 +160,36 @@ char *__ast_str_helper2(struct ast_str **buf, ssize_t maxlen, const char *src, s return (*buf)->__AST_STR_STR; } +static int str_hash(const void *obj, const int flags) +{ + return ast_str_hash(obj); +} + +static int str_cmp(void *lhs, void *rhs, int flags) +{ + return strcmp(lhs, rhs) ? 0 : CMP_MATCH; +} + +struct ao2_container *ast_str_container_alloc_options(enum ao2_container_opts opts, int buckets) +{ + return ao2_container_alloc_options(opts, buckets, str_hash, str_cmp); +} +int ast_str_container_add(struct ao2_container *str_container, const char *add) +{ + RAII_VAR(char *, ao2_add, ao2_alloc(strlen(add) + 1, NULL), ao2_cleanup); + + if (!ao2_add) { + return -1; + } + + /* safe strcpy */ + strcpy(ao2_add, add); + ao2_link(str_container, ao2_add); + return 0; +} + +void ast_str_container_remove(struct ao2_container *str_container, const char *remove) +{ + ao2_find(str_container, remove, OBJ_KEY | OBJ_NODATA | OBJ_UNLINK); +} diff --git a/utils/Makefile b/utils/Makefile index e60917b6a6320819500a88d23ca32cc4244bb3c3..11905fb5cb061406bf33490b0b16ad268aa62124 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -180,7 +180,7 @@ threadstorage.c: $(ASTTOPDIR)/main/threadstorage.c $(CMD_PREFIX) cp "$<" "$@" -refcounter: refcounter.o md5.o hashtab.o lock.o utils.o strings.o sha1.o strcompat.o threadstorage.o clicompat.o poll.o version.o +refcounter: refcounter.o md5.o hashtab.o lock.o utils.o strings.o sha1.o strcompat.o threadstorage.o clicompat.o poll.o version.o astobj2.o refcounter.o: _ASTCFLAGS+=-O0 extconf.o: extconf.c diff --git a/utils/refcounter.c b/utils/refcounter.c index fab906c5077cb920b69a95125e8377874f7a19f5..2f17b9c85da04f623a37a4258a28b1c3313177e8 100644 --- a/utils/refcounter.c +++ b/utils/refcounter.c @@ -310,4 +310,13 @@ void *__ast_bt_destroy(struct ast_bt *bt) { return NULL; } + +void ast_log_backtrace(void) +{ +} + +int ast_register_atexit(void (*func)(void)) +{ + return 0; +} #endif