committing 5924 with minor white space changes
authorMatt O'Gorman <mogorman@digium.com>
Tue, 10 Jan 2006 01:52:34 +0000 (01:52 +0000)
committerMatt O'Gorman <mogorman@digium.com>
Tue, 10 Jan 2006 01:52:34 +0000 (01:52 +0000)
and adding it to the Makefile for functions.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7921 65c4cc65-6c06-0410-ace0-fbb531ad65f3

funcs/Makefile
funcs/func_base64.c [new file with mode: 0644]

index 1934be5..60ef951 100644 (file)
@@ -23,7 +23,8 @@ BUILTINS=func_md5.o \
          func_db.o \
          func_timeout.o \
          func_language.o \
-         func_moh.o
+         func_moh.o \
+        func_base64.o
 
 AVAILABLE_FUNCS=$(filter-out $(BUILTINS),$(patsubst %.c,%.o,$(wildcard func*.c)))
 
diff --git a/funcs/func_base64.c b/funcs/func_base64.c
new file mode 100644 (file)
index 0000000..be335e3
--- /dev/null
@@ -0,0 +1,85 @@
+/*\r
+ * Asterisk -- An open source telephony toolkit.\r
+ *\r
+ * Copyright (C) 2005, Digium, Inc.\r
+ * Copyright (C) 2005, Claude Patry\r
+ *\r
+ * See http://www.asterisk.org for more information about\r
+ * the Asterisk project. Please do not directly contact\r
+ * any of the maintainers of this project for assistance;\r
+ * the project provides a web site, mailing lists and IRC\r
+ * channels for your use.\r
+ *\r
+ * This program is free software, distributed under the terms of\r
+ * the GNU General Public License Version 2. See the LICENSE file\r
+ * at the top of the source tree.\r
+ */\r
+\r
+/*! \file\r
+ *\r
+ * \brief Use the base64 as functions\r
+ * \r
+ */\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <sys/types.h>\r
+\r
+#include "asterisk.h"\r
+\r
+/* ASTERISK_FILE_VERSION(__FILE__, "Revision: 7221 ") */\r
+\r
+#include "asterisk/channel.h"\r
+#include "asterisk/pbx.h"\r
+#include "asterisk/logger.h"\r
+#include "asterisk/utils.h"\r
+#include "asterisk/app.h"\r
+\r
+static char *builtin_function_base64_encode(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) \r
+{\r
+       int res = 0;\r
+\r
+       if (ast_strlen_zero(data) ) {\r
+               ast_log(LOG_WARNING, "Syntax: BASE64_ENCODE(<data>) - missing argument!\n");\r
+               return NULL;\r
+       }\r
+\r
+       ast_log(LOG_DEBUG, "data=%s\n",data);\r
+       res = ast_base64encode(buf, data, strlen(data), len);\r
+       ast_log(LOG_DEBUG, "res=%d\n", res);\r
+       return buf;\r
+}\r
+\r
+static char *builtin_function_base64_decode(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) \r
+{\r
+       if (ast_strlen_zero(data) ) {\r
+               ast_log(LOG_WARNING, "Syntax: BASE64_DECODE(<base_64 string>) - missing argument!\n");\r
+               return NULL;\r
+       }\r
+\r
+       ast_log(LOG_DEBUG, "data=%s\n", data);\r
+       ast_base64decode(buf, data, len);\r
+       return buf;\r
+}\r
+\r
+#ifndef BUILTIN_FUNC\r
+static\r
+#endif\r
+struct ast_custom_function base64_encode_function = {\r
+       .name = "BASE64_ENCODE",\r
+       .synopsis = "Encode a string in base64",\r
+       .desc = "Returns the base64 string\n",\r
+       .syntax = "BASE64_ENCODE(<string>)",\r
+       .read = builtin_function_base64_encode,\r
+};\r
+\r
+#ifndef BUILTIN_FUNC\r
+static\r
+#endif\r
+struct ast_custom_function base64_decode_function = {\r
+       .name = "BASE64_DECODE",\r
+       .synopsis = "Decode a base64 string",\r
+       .desc = "Returns the plain text string\n",\r
+       .syntax = "BASE64_DECODE(<base64_string>)",\r
+       .read = builtin_function_base64_decode,\r
+};\r