[asterisk-commits] mnick: branch 1.4 r221157 - in /branches/1.4: configs/ funcs/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 30 10:41:49 CDT 2009
Author: mnick
Date: Wed Sep 30 10:41:46 2009
New Revision: 221157
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=221157
Log:
added a new dialplan function 'CSV_QUOTE' and changed the cdr_custom.sample.conf
Modified:
branches/1.4/configs/cdr_custom.conf.sample
branches/1.4/funcs/func_strings.c
Modified: branches/1.4/configs/cdr_custom.conf.sample
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/configs/cdr_custom.conf.sample?view=diff&rev=221157&r1=221156&r2=221157
==============================================================================
--- branches/1.4/configs/cdr_custom.conf.sample (original)
+++ branches/1.4/configs/cdr_custom.conf.sample Wed Sep 30 10:41:46 2009
@@ -6,5 +6,5 @@
;
;
;[mappings]
-;Master.csv => "${CDR(clid)}","${CDR(src)}","${CDR(dst)}","${CDR(dcontext)}","${CDR(channel)}","${CDR(dstchannel)}","${CDR(lastapp)}","${CDR(lastdata)}","${CDR(start)}","${CDR(answer)}","${CDR(end)}","${CDR(duration)}","${CDR(billsec)}","${CDR(disposition)}","${CDR(amaflags)}","${CDR(accountcode)}","${CDR(uniqueid)}","${CDR(userfield)}"
+;Master.csv => ${CSV_QUOTE(${CDR(clid)})},${CSV_QUOTE(${CDR(src)})},${CSV_QUOTE(${CDR(dst)})},${CSV_QUOTE(${CDR(dcontext)})},${CSV_QUOTE(${CDR(channel)})},${CSV_QUOTE(${CDR(dstchannel)})},${CSV_QUOTE(${CDR(lastapp)})},${CSV_QUOTE(${CDR(lastdata)})},${CSV_QUOTE(${CDR(start)})},${CSV_QUOTE(${CDR(answer)})},${CSV_QUOTE(${CDR(end)})},${CSV_QUOTE(${CDR(duration)})},${CSV_QUOTE(${CDR(billsec)})},${CSV_QUOTE(${CDR(disposition)})},${CSV_QUOTE(${CDR(amaflags)})},${CSV_QUOTE(${CDR(accountcode)})},${CSV_QUOTE(${CDR(uniqueid)})},${CSV_QUOTE(${CDR(userfield)})}
Modified: branches/1.4/funcs/func_strings.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/funcs/func_strings.c?view=diff&rev=221157&r1=221156&r2=221157
==============================================================================
--- branches/1.4/funcs/func_strings.c (original)
+++ branches/1.4/funcs/func_strings.c Wed Sep 30 10:41:46 2009
@@ -422,6 +422,43 @@
.read = quote,
};
+static int csv_quote(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
+{
+ char *bufptr = buf, *dataptr = data;
+
+ if (len < 3){ /* at least two for quotes and one for binary zero */
+ ast_log(LOG_ERROR, "Not enough buffer");
+ return -1;
+ }
+
+ if (ast_strlen_zero(data)) {
+ ast_log(LOG_WARNING, "No argument specified!\n");
+ ast_copy_string(buf,"\"\"",len);
+ return 0;
+ }
+
+ *bufptr++ = '"';
+ for (; bufptr < buf + len - 3; dataptr++){
+ if (*dataptr == '"') {
+ *bufptr++ = '"';
+ *bufptr++ = '"';
+ } else if (*dataptr == '\0') {
+ break;
+ } else {
+ *bufptr++ = *dataptr;
+ }
+ }
+ *bufptr++ = '"';
+ *bufptr='\0';
+ return 0;
+}
+
+static struct ast_custom_function csv_quote_function = {
+ .name = "CSV_QUOTE",
+ .synopsis = "Quotes a given string for use in a CSV file, escaping embedded quotes as necessary",
+ .syntax = "CSV_QUOTE(<string>)",
+ .read = csv_quote,
+};
static int len(struct ast_channel *chan, char *cmd, char *data, char *buf,
size_t len)
@@ -616,6 +653,7 @@
res |= ast_custom_function_unregister(®ex_function);
res |= ast_custom_function_unregister(&array_function);
res |= ast_custom_function_unregister("e_function);
+ res |= ast_custom_function_unregister(&csv_quote_function);
res |= ast_custom_function_unregister(&len_function);
res |= ast_custom_function_unregister(&strftime_function);
res |= ast_custom_function_unregister(&strptime_function);
@@ -635,6 +673,7 @@
res |= ast_custom_function_register(®ex_function);
res |= ast_custom_function_register(&array_function);
res |= ast_custom_function_register("e_function);
+ res |= ast_custom_function_register(&csv_quote_function);
res |= ast_custom_function_register(&len_function);
res |= ast_custom_function_register(&strftime_function);
res |= ast_custom_function_register(&strptime_function);
More information about the asterisk-commits
mailing list