[asterisk-commits] tilghman: branch tilghman/str_substitution r174368 - in /team/tilghman/str_su...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Feb 9 19:01:35 CST 2009
Author: tilghman
Date: Mon Feb 9 19:01:34 2009
New Revision: 174368
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=174368
Log:
And a few more...
Modified:
team/tilghman/str_substitution/cdr/cdr_custom.c
team/tilghman/str_substitution/res/res_agi.c
Modified: team/tilghman/str_substitution/cdr/cdr_custom.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/cdr/cdr_custom.c?view=diff&rev=174368&r1=174367&r2=174368
==============================================================================
--- team/tilghman/str_substitution/cdr/cdr_custom.c (original)
+++ team/tilghman/str_substitution/cdr/cdr_custom.c Mon Feb 9 19:01:34 2009
@@ -44,6 +44,8 @@
#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"
@@ -51,6 +53,8 @@
AST_MUTEX_DEFINE_STATIC(lock);
AST_MUTEX_DEFINE_STATIC(mf_lock);
+
+AST_THREADSTORAGE(custom_buf);
static char *name = "cdr-custom";
@@ -110,35 +114,37 @@
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;
}
Modified: team/tilghman/str_substitution/res/res_agi.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/res/res_agi.c?view=diff&rev=174368&r1=174367&r2=174368
==============================================================================
--- team/tilghman/str_substitution/res/res_agi.c (original)
+++ team/tilghman/str_substitution/res/res_agi.c Mon Feb 9 19:01:34 2009
@@ -1810,24 +1810,31 @@
static int handle_getvariablefull(struct ast_channel *chan, AGI *agi, int argc, char **argv)
{
- char tmp[4096];
- struct ast_channel *chan2=NULL;
-
- if ((argc != 4) && (argc != 5))
- return RESULT_SHOWUSAGE;
+ struct ast_channel *chan2 = NULL;
+
+ if ((argc != 4) && (argc != 5)) {
+ return RESULT_SHOWUSAGE;
+ }
if (argc == 5) {
chan2 = ast_get_channel_by_name_locked(argv[4]);
} else {
chan2 = chan;
}
if (chan2) {
- pbx_substitute_variables_helper(chan2, argv[3], tmp, sizeof(tmp) - 1);
- ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", tmp);
+ struct ast_str *str = ast_str_create(16);
+ if (!str) {
+ ast_agi_send(agi->fd, chan, "200 result=0\n");
+ return RESULT_SUCCESS;
+ }
+ ast_str_substitute_variables(&str, 0, chan2, argv[3]);
+ ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", ast_str_buffer(str));
+ ast_free(str);
} else {
ast_agi_send(agi->fd, chan, "200 result=0\n");
}
- if (chan2 && (chan2 != chan))
+ if (chan2 && (chan2 != chan)) {
ast_channel_unlock(chan2);
+ }
return RESULT_SUCCESS;
}
More information about the asterisk-commits
mailing list