summaryrefslogtreecommitdiff
path: root/main/strings.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2013-08-02 14:08:34 +0000
committerKinsey Moore <kmoore@digium.com>2013-08-02 14:08:34 +0000
commit41d6be2432a77cf9da5dbb3f0590a74340a2c54e (patch)
tree50fe2992b81e196c5efc84d71fdd00a90ebf8a01 /main/strings.c
parentf8622e7c5cbdda91a5efad230a9e3af593378c7c (diff)
Move ast_str_container_alloc and friends
This moves ast_str_container_alloc, ast_str_container_add, ast_str_container_remove, and related private functions into strings.c/h since they really don't belong in astobj2.c/h. As a result of this move, utils also had to be updated. Review: https://reviewboard.asterisk.org/r/2719/ (closes issue ASTERISK-22041) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396105 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/strings.c')
-rw-r--r--main/strings.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/main/strings.c b/main/strings.c
index d004da227..6633d5982 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);
+}