aboutsummaryrefslogtreecommitdiffstats
path: root/cdr/cdr_custom.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2009-04-29 18:53:01 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2009-04-29 18:53:01 +0000
commit8fc2c0f7245703d3dde31d7fa035f3f28c82daeb (patch)
tree972bdf8f96c18f1b9667469307af69385f4a75f3 /cdr/cdr_custom.c
parent6d9e0aa8817729e7914bb1b3fafe02dc96ae41b5 (diff)
Merge str_substitution branch.
This branch adds additional methods to dialplan functions, whereby the result buffers are now dynamic buffers, which can be expanded to the size of any result. No longer are variable substitutions limited to 4095 bytes of data. In addition, the common case of needing buffers much smaller than that will enable substitution to only take up the amount of memory actually needed. The existing variable substitution routines are still available, but users of those API calls should transition to using the dynamic-buffer APIs. Reviewboard: http://reviewboard.digium.com/r/174/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@191140 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr/cdr_custom.c')
-rw-r--r--cdr/cdr_custom.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/cdr/cdr_custom.c b/cdr/cdr_custom.c
index c7974b0e7..130fa6dd0 100644
--- a/cdr/cdr_custom.c
+++ b/cdr/cdr_custom.c
@@ -44,6 +44,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
+#include "asterisk/threadstorage.h"
+#include "asterisk/strings.h"
#define CUSTOM_LOG_DIR "/cdr_custom"
@@ -52,6 +54,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
AST_MUTEX_DEFINE_STATIC(lock);
AST_MUTEX_DEFINE_STATIC(mf_lock);
+AST_THREADSTORAGE(custom_buf);
+
static char *name = "cdr-custom";
static char master[PATH_MAX];
@@ -110,35 +114,37 @@ static int load_config(int reload)
static int custom_log(struct ast_cdr *cdr)
{
FILE *mf = NULL;
-
- /* Make sure we have a big enough buf */
- char buf[2048];
struct ast_channel dummy;
+ struct ast_str *str;
/* Abort if no master file is specified */
- if (ast_strlen_zero(master))
+ if (ast_strlen_zero(master)) {
return 0;
+ }
+
+ /* Batching saves memory management here. Otherwise, it's the same as doing an allocation and free each time. */
+ if (!(str = ast_str_thread_get(&custom_buf, 16))) {
+ return -1;
+ }
+ ast_str_reset(str);
/* Quite possibly the first use of a static struct ast_channel, we need it so the var funcs will work */
memset(&dummy, 0, sizeof(dummy));
dummy.cdr = cdr;
- pbx_substitute_variables_helper(&dummy, format, buf, sizeof(buf) - 1);
+ ast_str_substitute_variables(&str, 0, &dummy, format);
/* because of the absolutely unconditional need for the
highest reliability possible in writing billing records,
we open write and close the log file each time */
ast_mutex_lock(&mf_lock);
- mf = fopen(master, "a");
- if (mf) {
- fputs(buf, mf);
+ if ((mf = fopen(master, "a"))) {
+ fputs(ast_str_buffer(str), mf);
fflush(mf); /* be particularly anal here */
fclose(mf);
- mf = NULL;
- ast_mutex_unlock(&mf_lock);
} else {
ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", master, strerror(errno));
- ast_mutex_unlock(&mf_lock);
}
+ ast_mutex_unlock(&mf_lock);
return 0;
}