[asterisk-commits] twilson: branch twilson/sip_binarification r314594 - in /team/twilson/sip_bin...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 20 21:15:02 CDT 2011


Author: twilson
Date: Wed Apr 20 21:15:00 2011
New Revision: 314594

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=314594
Log:
Add ast_buf_dup() and fix some const issues

Modified:
    team/twilson/sip_binarification/include/asterisk/buffers.h
    team/twilson/sip_binarification/main/buffers.c
    team/twilson/sip_binarification/tests/test_buffers.c

Modified: team/twilson/sip_binarification/include/asterisk/buffers.h
URL: http://svnview.digium.com/svn/asterisk/team/twilson/sip_binarification/include/asterisk/buffers.h?view=diff&rev=314594&r1=314593&r2=314594
==============================================================================
--- team/twilson/sip_binarification/include/asterisk/buffers.h (original)
+++ team/twilson/sip_binarification/include/asterisk/buffers.h Wed Apr 20 21:15:00 2011
@@ -122,13 +122,19 @@
  * \param dst The address of a pointer to an ast_buf created with ast_buf_create() to copy to
  * \param src The buffer to copy
  */
-int ast_buf_copy_buffer(struct ast_buf **dst, struct ast_buf *src);
+int ast_buf_copy_buffer(struct ast_buf **dst, const struct ast_buf *src);
+
+/*!\brief Duplicate a buffer
+ * \param buf The buffer to duplicate
+ * \return A malloc'd duplicate of the buf
+ */
+struct ast_buf * attribute_malloc ast_buf_dup(const struct ast_buf *buf);
 
 /*!\brief Compare two ast_bufs
  * \retval -1 Not equal
  * \retval 0 Eual
  */
-int ast_buf_cmp(struct ast_buf *one, struct ast_buf *two);
+int ast_buf_cmp(const struct ast_buf *one, const struct ast_buf *two);
 
 /*!
  * \brief Retrieve a thread locally stored dynamic buffer

Modified: team/twilson/sip_binarification/main/buffers.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/sip_binarification/main/buffers.c?view=diff&rev=314594&r1=314593&r2=314594
==============================================================================
--- team/twilson/sip_binarification/main/buffers.c (original)
+++ team/twilson/sip_binarification/main/buffers.c Wed Apr 20 21:15:00 2011
@@ -207,7 +207,7 @@
 }
 #endif
 
-int ast_buf_copy_buffer(struct ast_buf **dst, struct ast_buf *src)
+int ast_buf_copy_buffer(struct ast_buf **dst, const struct ast_buf *src)
 {
 
 	/* make sure our destination is large enough */
@@ -222,7 +222,23 @@
 	return 0;
 }
 
-int ast_buf_cmp(struct ast_buf *one, struct ast_buf *two)
+struct ast_buf *ast_buf_dup(const struct ast_buf *buf)
+{
+	struct ast_buf *copy;
+
+	if (!(copy = ast_buf_create(ast_buf_size(buf)))) {
+		return NULL;
+	}
+
+	if (ast_buf_copy_buffer(&copy, buf)) {
+		ast_free(copy);
+		copy = NULL;
+	}
+
+	return copy;
+}
+
+int ast_buf_cmp(const struct ast_buf *one, const struct ast_buf *two)
 {
 	return one->used == two->used ? memcmp(one->buffer, two->buffer, one->used) : -1;
 }

Modified: team/twilson/sip_binarification/tests/test_buffers.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/sip_binarification/tests/test_buffers.c?view=diff&rev=314594&r1=314593&r2=314594
==============================================================================
--- team/twilson/sip_binarification/tests/test_buffers.c (original)
+++ team/twilson/sip_binarification/tests/test_buffers.c Wed Apr 20 21:15:00 2011
@@ -194,6 +194,15 @@
 		fail_with_message(test, res, cleanup, "Copied more bytes to buffer than limit\n");
 	}
 
+	ast_free(bufcopy);
+	if (!(bufcopy = ast_buf_dup(buf))) {
+		fail_with_message(test, res, cleanup, "Could not duplicate buffer\n");
+	}
+
+	if (ast_buf_cmp(buf, bufcopy)) {
+		fail_with_message(test, res, cleanup, "Duplicated buffer differs from original\n");
+	}
+
 	/* alloca'd tests */
 	if (!(tmpbuf = ast_buf_alloca(TEST_BUF_INITIAL_SIZE))) {
 		fail_with_message(test, res, cleanup, "Couldn't alloca a buf\n");




More information about the asterisk-commits mailing list