|
|
@ -276,6 +276,17 @@ AST_THREADSTORAGE(result_buf);
|
|
|
|
<para>Example: ${QUOTE(ab"c"de)} will return "abcde"</para>
|
|
|
|
<para>Example: ${QUOTE(ab"c"de)} will return "abcde"</para>
|
|
|
|
</description>
|
|
|
|
</description>
|
|
|
|
</function>
|
|
|
|
</function>
|
|
|
|
|
|
|
|
<function name="CSV_QUOTE" language="en_US">
|
|
|
|
|
|
|
|
<synopsis>
|
|
|
|
|
|
|
|
Quotes a given string for use in a CSV file, escaping embedded quotes as necessary
|
|
|
|
|
|
|
|
</synopsis>
|
|
|
|
|
|
|
|
<syntax>
|
|
|
|
|
|
|
|
<parameter name="string" required="true" />
|
|
|
|
|
|
|
|
</syntax>
|
|
|
|
|
|
|
|
<description>
|
|
|
|
|
|
|
|
<para>Example: ${CSV_QUOTE("a,b" 123)} will return """a,b"" 123"</para>
|
|
|
|
|
|
|
|
</description>
|
|
|
|
|
|
|
|
</function>
|
|
|
|
<function name="SHIFT" language="en_US">
|
|
|
|
<function name="SHIFT" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
<synopsis>
|
|
|
|
Removes and returns the first item off of a variable containing delimited text
|
|
|
|
Removes and returns the first item off of a variable containing delimited text
|
|
|
@ -862,6 +873,12 @@ static struct ast_custom_function array_function = {
|
|
|
|
static int quote(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
|
|
|
|
static int quote(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char *bufptr = buf, *dataptr = data;
|
|
|
|
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)) {
|
|
|
|
if (ast_strlen_zero(data)) {
|
|
|
|
ast_log(LOG_WARNING, "No argument specified!\n");
|
|
|
|
ast_log(LOG_WARNING, "No argument specified!\n");
|
|
|
|
ast_copy_string(buf, "\"\"", len);
|
|
|
|
ast_copy_string(buf, "\"\"", len);
|
|
|
@ -869,7 +886,7 @@ static int quote(struct ast_channel *chan, const char *cmd, char *data, char *bu
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*bufptr++ = '"';
|
|
|
|
*bufptr++ = '"';
|
|
|
|
for (; bufptr < buf + len - 1; dataptr++) {
|
|
|
|
for (; bufptr < buf + len - 3; dataptr++) {
|
|
|
|
if (*dataptr == '\\') {
|
|
|
|
if (*dataptr == '\\') {
|
|
|
|
*bufptr++ = '\\';
|
|
|
|
*bufptr++ = '\\';
|
|
|
|
*bufptr++ = '\\';
|
|
|
|
*bufptr++ = '\\';
|
|
|
@ -892,9 +909,43 @@ static struct ast_custom_function quote_function = {
|
|
|
|
.read = quote,
|
|
|
|
.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",
|
|
|
|
|
|
|
|
.read = csv_quote,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf,
|
|
|
|
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
|
|
|
|
size_t buflen)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int length = 0;
|
|
|
|
int length = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -1262,6 +1313,7 @@ static int unload_module(void)
|
|
|
|
res |= ast_custom_function_unregister(®ex_function);
|
|
|
|
res |= ast_custom_function_unregister(®ex_function);
|
|
|
|
res |= ast_custom_function_unregister(&array_function);
|
|
|
|
res |= ast_custom_function_unregister(&array_function);
|
|
|
|
res |= ast_custom_function_unregister("e_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(&len_function);
|
|
|
|
res |= ast_custom_function_unregister(&strftime_function);
|
|
|
|
res |= ast_custom_function_unregister(&strftime_function);
|
|
|
|
res |= ast_custom_function_unregister(&strptime_function);
|
|
|
|
res |= ast_custom_function_unregister(&strptime_function);
|
|
|
@ -1290,6 +1342,7 @@ static int load_module(void)
|
|
|
|
res |= ast_custom_function_register(®ex_function);
|
|
|
|
res |= ast_custom_function_register(®ex_function);
|
|
|
|
res |= ast_custom_function_register(&array_function);
|
|
|
|
res |= ast_custom_function_register(&array_function);
|
|
|
|
res |= ast_custom_function_register("e_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(&len_function);
|
|
|
|
res |= ast_custom_function_register(&strftime_function);
|
|
|
|
res |= ast_custom_function_register(&strftime_function);
|
|
|
|
res |= ast_custom_function_register(&strptime_function);
|
|
|
|
res |= ast_custom_function_register(&strptime_function);
|
|
|
|