aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authormurf <murf@f38db490-d61c-443f-a65b-d21fe96a405b>2006-08-07 18:12:51 +0000
committermurf <murf@f38db490-d61c-443f-a65b-d21fe96a405b>2006-08-07 18:12:51 +0000
commit5704962ab90591dc601df7595bf1a9c978eb28fa (patch)
tree672bc4d780de295bc800541b7f673a04f52e6e56 /include
parentd60591dedf34439cba20312cb2ebc264a91ed123 (diff)
This commit folds in changes to both stringfields (some enhancements to the ...field_set() macro, to optimize setting strings to empty, resetting strings to shorter contents, etc.) and to chan_iax2.c, to use stringfields in the user, peer, and pvt structs. Has been running stably on iaxtel, but while iaxtel has a large registration volume, it doesn't seem to have a high call volume. So far, it seems to reduce heap usage by over half. YMMV\! Please report any IAX bugs that might involve stringfields\!
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@39203 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/stringfields.h36
1 files changed, 33 insertions, 3 deletions
diff --git a/include/asterisk/stringfields.h b/include/asterisk/stringfields.h
index 5a9a58f82..9b5fbc6df 100644
--- a/include/asterisk/stringfields.h
+++ b/include/asterisk/stringfields.h
@@ -218,10 +218,36 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
\return nothing
*/
#define ast_string_field_index_set(x, index, data) do { \
- if (((x)->__begin_field[index] = __ast_string_field_alloc_space(&(x)->__field_mgr, strlen(data) + 1, &(x)->__begin_field[0], ast_string_field_count(x)))) \
- strcpy((char *) (x)->__begin_field[index], data); \
- } while (0)
+ char *__zz__ = (char*)(x)->__begin_field[index]; \
+ int __dlen__ = strlen(data); \
+ if( __dlen__ == 0 ) { (x)->__begin_field[index] = __ast_string_field_empty; \
+ } else { \
+ if( __zz__[0] != 0 && __dlen__ <= strlen(__zz__) ) { \
+ strcpy(__zz__, data); \
+ } else { \
+ if (((x)->__begin_field[index] = __ast_string_field_alloc_space(&(x)->__field_mgr, __dlen__ + 1, &(x)->__begin_field[0], ast_string_field_count(x)))) \
+ strcpy((char*)(x)->__begin_field[index], data); \
+ } \
+ } \
+ } while (0)
+#ifdef FOR_TEST
+#define ast_string_field_index_logset(x, index, data, logstr) do { \
+ char *__zz__ = (char*)(x)->__begin_field[index]; \
+ int __dlen__ = strlen(data); \
+ if( __dlen__ == 0 ) { (x)->__begin_field[index] = __ast_string_field_empty; \
+ } else { \
+ if( __zz__[0] != 0 && __dlen__ <= strlen(__zz__) ) { \
+ ast_verbose("%s: ======replacing '%s' with '%s'\n", logstr, __zz__, data); \
+ strcpy(__zz__, data); \
+ } else { \
+ ast_verbose("%s: ++++++allocating room for '%s' to replace '%s'\n", logstr, data, __zz__); \
+ if (((x)->__begin_field[index] = __ast_string_field_alloc_space(&(x)->__field_mgr, __dlen__ + 1, &(x)->__begin_field[0], ast_string_field_count(x)))) \
+ strcpy((char*)(x)->__begin_field[index], data); \
+ } \
+ } \
+ } while (0)
+#endif
/*!
\brief Set a field to a simple string value
\param x Pointer to a structure containing fields
@@ -232,6 +258,10 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
#define ast_string_field_set(x, field, data) \
ast_string_field_index_set(x, ast_string_field_index(x, field), data)
+#ifdef FOR_TEST
+#define ast_string_field_logset(x, field, data, logstr) \
+ ast_string_field_index_logset(x, ast_string_field_index(x, field), data, logstr)
+#endif
/*!
\brief Set a field to a complex (built) value
\param x Pointer to a structure containing fields