[asterisk-commits] dlee: branch dlee/endpoints r386453 - in /team/dlee/endpoints: include/asteri...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 24 15:08:19 CDT 2013
Author: dlee
Date: Wed Apr 24 15:08:15 2013
New Revision: 386453
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386453
Log:
Merging r386446 from https://origsvn.digium.com/svn/asterisk/team/dlee/ast_str_container
Modified:
team/dlee/endpoints/include/asterisk/astobj2.h
team/dlee/endpoints/main/astobj2.c
Modified: team/dlee/endpoints/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/astobj2.h?view=diff&rev=386453&r1=386452&r2=386453
==============================================================================
--- team/dlee/endpoints/include/asterisk/astobj2.h (original)
+++ team/dlee/endpoints/include/asterisk/astobj2.h Wed Apr 24 15:08:15 2013
@@ -1883,4 +1883,55 @@
#define ao2_cleanup(obj) __ao2_cleanup(obj)
#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 */
Modified: team/dlee/endpoints/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/astobj2.c?view=diff&rev=386453&r1=386452&r2=386453
==============================================================================
--- team/dlee/endpoints/main/astobj2.c (original)
+++ team/dlee/endpoints/main/astobj2.c Wed Apr 24 15:08:15 2013
@@ -5779,3 +5779,41 @@
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);
+}
More information about the asterisk-commits
mailing list