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: https://origsvn.digium.com/svn/asterisk/trunk@191140 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher
2009-04-29 18:53:01 +00:00
parent 0ea83eab48
commit a866a75900
38 changed files with 13291 additions and 13141 deletions

View File

@@ -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;
}