Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Functions | Variables
func_base64.c File Reference

Use the base64 as functions. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/strings.h"
Include dependency graph for func_base64.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int base64_buf_helper (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)
 
static int base64_str_helper (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "base64 encode/decode dialplan functions" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function base64_decode_function
 
static struct ast_custom_function base64_encode_function
 

Detailed Description

Use the base64 as functions.

Definition in file func_base64.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 166 of file func_base64.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 166 of file func_base64.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 166 of file func_base64.c.

◆ base64_buf_helper()

static int base64_buf_helper ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 130 of file func_base64.c.

132{
133 return base64_helper(chan, cmd, data, buf, NULL, len);
134}
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static int base64_helper(struct ast_channel *chan, const char *cmd, char *data, char *buf, struct ast_str **str, ssize_t len)
Definition func_base64.c:81
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define NULL
Definition resample.c:96

References base64_helper(), buf, len(), and NULL.

◆ base64_helper()

static int base64_helper ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
struct ast_str **  str,
ssize_t  len 
)
static

Definition at line 81 of file func_base64.c.

83{
84 if (ast_strlen_zero(data)) {
85 ast_log(LOG_WARNING, "Syntax: %s(<data>) - missing argument!\n", cmd);
86 return -1;
87 }
88
89 if (cmd[7] == 'E') {
90 if (buf) {
91 ast_base64encode(buf, (unsigned char *) data, strlen(data), len);
92 } else {
93 if (len >= 0) {
94 /* This calculation accounts for padding and the trailing 0 byte. Borrowed
95 from utils.c */
96 size_t bytes_needed_to_encode_data = ((strlen(data) * 4 / 3 + 3) & ~3) + 1;
97 ast_str_make_space(str, len ? len : ast_str_strlen(*str) + bytes_needed_to_encode_data);
98 }
99 ast_base64encode(ast_str_buffer(*str) + ast_str_strlen(*str), (unsigned char *) data, strlen(data), ast_str_size(*str) - ast_str_strlen(*str));
101 }
102 } else {
103 int decoded_len;
104 if (buf) {
105 decoded_len = ast_base64decode((unsigned char *) buf, data, len);
106 /* add a terminating null at the end of buf, or at the
107 * end of our decoded string, which ever is less */
108 buf[decoded_len <= (len - 1) ? decoded_len : len - 1] = '\0';
109 } else {
110 if (len >= 0) {
111 ast_str_make_space(str, len ? len : ast_str_strlen(*str) + strlen(data) * 3 / 4 + 2);
112 }
113 decoded_len = ast_base64decode((unsigned char *) ast_str_buffer(*str) + ast_str_strlen(*str), data, ast_str_size(*str) - ast_str_strlen(*str));
114 if (len)
115 /* add a terminating null at the end of our
116 * buffer, or at the end of our decoded string,
117 * which ever is less */
118 ast_str_buffer(*str)[decoded_len <= (len - 1) ? decoded_len : len - 1] = '\0';
119 else
120 /* space for the null is allocated above */
121 ast_str_buffer(*str)[decoded_len] = '\0';
122
124 }
125 }
126
127 return 0;
128}
const char * str
Definition app_jack.c:150
#define ast_log
Definition astobj2.c:42
#define LOG_WARNING
size_t attribute_pure ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition strings.h:730
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
#define ast_str_make_space(buf, new_len)
Definition strings.h:828
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition strings.h:703
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
size_t attribute_pure ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition strings.h:742
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
Definition utils.c:296
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
Definition utils.c:406

References ast_base64decode(), ast_base64encode(), ast_log, ast_str_buffer(), ast_str_make_space, ast_str_size(), ast_str_strlen(), ast_str_update(), ast_strlen_zero(), buf, len(), LOG_WARNING, and str.

Referenced by base64_buf_helper(), and base64_str_helper().

◆ base64_str_helper()

static int base64_str_helper ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  len 
)
static

Definition at line 136 of file func_base64.c.

138{
139 return base64_helper(chan, cmd, data, NULL, buf, len);
140}

References base64_helper(), buf, len(), and NULL.

◆ load_module()

static int load_module ( void  )
static

Definition at line 160 of file func_base64.c.

161{
164}
static struct ast_custom_function base64_decode_function
static struct ast_custom_function base64_encode_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1562

References ast_custom_function_register, base64_decode_function, and base64_encode_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 154 of file func_base64.c.

155{
158}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), base64_decode_function, and base64_encode_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "base64 encode/decode dialplan functions" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 166 of file func_base64.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 166 of file func_base64.c.

◆ base64_decode_function

struct ast_custom_function base64_decode_function
static
Initial value:
= {
.name = "BASE64_DECODE",
}
static int base64_buf_helper(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int base64_str_helper(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)

Definition at line 148 of file func_base64.c.

148 {
149 .name = "BASE64_DECODE",
150 .read = base64_buf_helper,
151 .read2 = base64_str_helper,
152};

Referenced by load_module(), and unload_module().

◆ base64_encode_function

struct ast_custom_function base64_encode_function
static
Initial value:
= {
.name = "BASE64_ENCODE",
}

Definition at line 142 of file func_base64.c.

142 {
143 .name = "BASE64_ENCODE",
144 .read = base64_buf_helper,
145 .read2 = base64_str_helper,
146};

Referenced by load_module(), and unload_module().