2006-02-11 03:14:05 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 - 2006, Digium, Inc.
|
|
|
|
* Copyright (C) 2005, Claude Patry
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file
|
|
|
|
*
|
|
|
|
* \brief Use the base64 as functions
|
|
|
|
*
|
2007-01-24 09:05:29 +00:00
|
|
|
* \ingroup functions
|
2006-02-11 03:14:05 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-14 20:28:54 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-02-11 03:14:05 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
git migration: Refactor the ASTERISK_FILE_VERSION macro
Git does not support the ability to replace a token with a version
string during check-in. While it does have support for replacing a
token on clone, this is somewhat sub-optimal: the token is replaced
with the object hash, which is not particularly easy for human
consumption. What's more, in practice, the source file version was often
not terribly useful. Generally, when triaging bugs, the overall version
of Asterisk is far more useful than an individual SVN version of a file. As a
result, this patch removes Asterisk's support for showing source file
versions.
Specifically, it does the following:
* Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and
remove passing the version in with the macro. Other facilities
than 'core show file version' make use of the file names, such as
setting a debug level only on a specific file. As such, the act of
registering source files with the Asterisk core still has use. The
macro rename now reflects the new macro purpose.
* main/asterisk:
- Refactor the file_version structure to reflect that it no longer
tracks a version field.
- Remove the "core show file version" CLI command. Without the file
version, it is no longer useful.
- Remove the ast_file_version_find function. The file version is no
longer tracked.
- Rename ast_register_file_version/ast_unregister_file_version to
ast_register_file/ast_unregister_file, respectively.
* main/manager: Remove value from the Version key of the ModuleCheck
Action. The actual key itself has not been removed, as doing so would
absolutely constitute a backwards incompatible change. However, since
the file version is no longer tracked, there is no need to attempt to
include it in the Version key.
* UPGRADE: Add notes for:
- Modification to the ModuleCheck AMI Action
- Removal of the "core show file version" CLI command
Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-12 02:38:22 +00:00
|
|
|
ASTERISK_REGISTER_FILE()
|
2006-02-11 03:14:05 +00:00
|
|
|
|
|
|
|
#include "asterisk/module.h"
|
2007-11-19 20:42:06 +00:00
|
|
|
#include "asterisk/pbx.h" /* function register/unregister */
|
2006-02-11 03:14:05 +00:00
|
|
|
#include "asterisk/utils.h"
|
2009-04-29 18:53:01 +00:00
|
|
|
#include "asterisk/strings.h"
|
2006-02-11 03:14:05 +00:00
|
|
|
|
2008-11-01 21:10:07 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<function name="BASE64_ENCODE" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Encode a string in base64.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="string" required="true">
|
|
|
|
<para>Input string</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Returns the base64 string.</para>
|
|
|
|
</description>
|
2011-01-14 19:39:22 +00:00
|
|
|
<see-also>
|
2011-01-14 20:07:02 +00:00
|
|
|
<ref type="function">BASE64_DECODE</ref>
|
|
|
|
<ref type="function">AES_DECRYPT</ref>
|
|
|
|
<ref type="function">AES_ENCRYPT</ref>
|
2011-01-14 19:39:22 +00:00
|
|
|
</see-also>
|
2008-11-01 21:10:07 +00:00
|
|
|
</function>
|
|
|
|
<function name="BASE64_DECODE" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Decode a base64 string.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="string" required="true">
|
|
|
|
<para>Input string.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Returns the plain text string.</para>
|
|
|
|
</description>
|
2011-01-14 19:39:22 +00:00
|
|
|
<see-also>
|
2011-01-14 20:07:02 +00:00
|
|
|
<ref type="function">BASE64_ENCODE</ref>
|
|
|
|
<ref type="function">AES_DECRYPT</ref>
|
|
|
|
<ref type="function">AES_ENCRYPT</ref>
|
2011-01-14 19:39:22 +00:00
|
|
|
</see-also>
|
2008-11-01 21:10:07 +00:00
|
|
|
</function>
|
|
|
|
***/
|
|
|
|
|
2009-04-29 18:53:01 +00:00
|
|
|
static int base64_helper(struct ast_channel *chan, const char *cmd, char *data,
|
|
|
|
char *buf, struct ast_str **str, ssize_t len)
|
2006-02-11 03:14:05 +00:00
|
|
|
{
|
2006-02-12 04:28:58 +00:00
|
|
|
if (ast_strlen_zero(data)) {
|
2009-04-29 18:53:01 +00:00
|
|
|
ast_log(LOG_WARNING, "Syntax: %s(<data>) - missing argument!\n", cmd);
|
2006-02-12 04:28:58 +00:00
|
|
|
return -1;
|
2006-02-11 03:14:05 +00:00
|
|
|
}
|
|
|
|
|
2009-04-29 18:53:01 +00:00
|
|
|
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 {
|
2009-11-06 19:47:11 +00:00
|
|
|
int decoded_len;
|
2009-04-29 18:53:01 +00:00
|
|
|
if (buf) {
|
2009-11-06 19:47:11 +00:00
|
|
|
decoded_len = ast_base64decode((unsigned char *) buf, data, len);
|
|
|
|
/* add a terminating null at the end of buf, or at the
|
|
|
|
* end of our decoded string, which ever is less */
|
|
|
|
buf[decoded_len <= (len - 1) ? decoded_len : len - 1] = '\0';
|
2009-04-29 18:53:01 +00:00
|
|
|
} else {
|
|
|
|
if (len >= 0) {
|
|
|
|
ast_str_make_space(str, len ? len : ast_str_strlen(*str) + strlen(data) * 3 / 4 + 2);
|
|
|
|
}
|
2009-11-06 19:47:11 +00:00
|
|
|
decoded_len = ast_base64decode((unsigned char *) ast_str_buffer(*str) + ast_str_strlen(*str), data, ast_str_size(*str) - ast_str_strlen(*str));
|
|
|
|
if (len)
|
|
|
|
/* add a terminating null at the end of our
|
|
|
|
* buffer, or at the end of our decoded string,
|
|
|
|
* which ever is less */
|
|
|
|
ast_str_buffer(*str)[decoded_len <= (len - 1) ? decoded_len : len - 1] = '\0';
|
|
|
|
else
|
|
|
|
/* space for the null is allocated above */
|
|
|
|
ast_str_buffer(*str)[decoded_len] = '\0';
|
|
|
|
|
2009-04-29 18:53:01 +00:00
|
|
|
ast_str_update(*str);
|
|
|
|
}
|
|
|
|
}
|
2006-02-12 04:28:58 +00:00
|
|
|
|
|
|
|
return 0;
|
2006-02-11 03:14:05 +00:00
|
|
|
}
|
|
|
|
|
2009-04-29 18:53:01 +00:00
|
|
|
static int base64_buf_helper(struct ast_channel *chan, const char *cmd, char *data,
|
2006-02-12 04:28:58 +00:00
|
|
|
char *buf, size_t len)
|
2006-02-11 03:14:05 +00:00
|
|
|
{
|
2009-04-29 18:53:01 +00:00
|
|
|
return base64_helper(chan, cmd, data, buf, NULL, len);
|
|
|
|
}
|
2006-02-12 04:28:58 +00:00
|
|
|
|
2009-04-29 18:53:01 +00:00
|
|
|
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);
|
2006-02-11 03:14:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_custom_function base64_encode_function = {
|
|
|
|
.name = "BASE64_ENCODE",
|
2009-04-29 18:53:01 +00:00
|
|
|
.read = base64_buf_helper,
|
|
|
|
.read2 = base64_str_helper,
|
2006-02-11 03:14:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct ast_custom_function base64_decode_function = {
|
|
|
|
.name = "BASE64_DECODE",
|
2009-04-29 18:53:01 +00:00
|
|
|
.read = base64_buf_helper,
|
|
|
|
.read2 = base64_str_helper,
|
2006-02-11 03:14:05 +00:00
|
|
|
};
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2006-02-11 03:14:05 +00:00
|
|
|
{
|
2006-02-12 04:28:58 +00:00
|
|
|
return ast_custom_function_unregister(&base64_encode_function) |
|
2006-02-11 03:14:05 +00:00
|
|
|
ast_custom_function_unregister(&base64_decode_function);
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2006-02-11 03:14:05 +00:00
|
|
|
{
|
2006-02-12 04:28:58 +00:00
|
|
|
return ast_custom_function_register(&base64_encode_function) |
|
2006-02-11 03:14:05 +00:00
|
|
|
ast_custom_function_register(&base64_decode_function);
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "base64 encode/decode dialplan functions");
|