summaryrefslogtreecommitdiff
path: root/funcs/func_base64.c
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2009-04-29 18:53:01 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2009-04-29 18:53:01 +0000
commita866a7590085a1f635ca92459c3917e5cded257a (patch)
tree972bdf8f96c18f1b9667469307af69385f4a75f3 /funcs/func_base64.c
parent0ea83eab4811c8519e4e04bf4c59b1744cf1efc9 (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: https://origsvn.digium.com/svn/asterisk/trunk@191140 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'funcs/func_base64.c')
-rw-r--r--funcs/func_base64.c50
1 files changed, 36 insertions, 14 deletions
diff --git a/funcs/func_base64.c b/funcs/func_base64.c
index 28805b943..a68cf9bda 100644
--- a/funcs/func_base64.c
+++ b/funcs/func_base64.c
@@ -29,6 +29,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#include "asterisk/pbx.h" /* function register/unregister */
#include "asterisk/utils.h"
+#include "asterisk/strings.h"
/*** DOCUMENTATION
<function name="BASE64_ENCODE" language="en_US">
@@ -59,40 +60,61 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
</function>
***/
-static int base64_encode(struct ast_channel *chan, const char *cmd, char *data,
- char *buf, size_t len)
+static int base64_helper(struct ast_channel *chan, const char *cmd, char *data,
+ char *buf, struct ast_str **str, ssize_t len)
{
if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Syntax: BASE64_ENCODE(<data>) - missing argument!\n");
+ ast_log(LOG_WARNING, "Syntax: %s(<data>) - missing argument!\n", cmd);
return -1;
}
- ast_base64encode(buf, (unsigned char *) data, strlen(data), len);
+ if (cmd[7] == 'E') {
+ if (buf) {
+ ast_base64encode(buf, (unsigned char *) data, strlen(data), len);
+ } else {
+ if (len >= 0) {
+ ast_str_make_space(str, len ? len : ast_str_strlen(*str) + strlen(data) * 4 / 3 + 2);
+ }
+ ast_base64encode(ast_str_buffer(*str) + ast_str_strlen(*str), (unsigned char *) data, strlen(data), ast_str_size(*str) - ast_str_strlen(*str));
+ ast_str_update(*str);
+ }
+ } else {
+ if (buf) {
+ ast_base64decode((unsigned char *) buf, data, len);
+ } else {
+ if (len >= 0) {
+ ast_str_make_space(str, len ? len : ast_str_strlen(*str) + strlen(data) * 3 / 4 + 2);
+ }
+ ast_base64decode((unsigned char *) ast_str_buffer(*str) + ast_str_strlen(*str), data, ast_str_size(*str) - ast_str_strlen(*str));
+ ast_str_update(*str);
+ }
+ }
return 0;
}
-static int base64_decode(struct ast_channel *chan, const char *cmd, char *data,
+static int base64_buf_helper(struct ast_channel *chan, const char *cmd, char *data,
char *buf, size_t len)
{
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Syntax: BASE64_DECODE(<base_64 string>) - missing argument!\n");
- return -1;
- }
-
- ast_base64decode((unsigned char *) buf, data, len);
+ return base64_helper(chan, cmd, data, buf, NULL, len);
+}
- return 0;
+static int base64_str_helper(struct ast_channel *chan, const char *cmd, char *data,
+ struct ast_str **buf, ssize_t len)
+{
+ return base64_helper(chan, cmd, data, NULL, buf, len);
}
static struct ast_custom_function base64_encode_function = {
.name = "BASE64_ENCODE",
- .read = base64_encode,
+ .read = base64_buf_helper,
+ .read2 = base64_str_helper,
};
static struct ast_custom_function base64_decode_function = {
.name = "BASE64_DECODE",
- .read = base64_decode,
+ .read = base64_buf_helper,
+ .read2 = base64_str_helper,
};
static int unload_module(void)