Asterisk - The Open Source Telephony Project  18.5.0
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 = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 157 of file func_base64.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 157 of file func_base64.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 157 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 121 of file func_base64.c.

References base64_helper(), and NULL.

123 {
124  return base64_helper(chan, cmd, data, buf, NULL, len);
125 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define NULL
Definition: resample.c:96
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:75
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

◆ 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 75 of file func_base64.c.

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, and LOG_WARNING.

Referenced by base64_buf_helper(), and base64_str_helper().

77 {
78  if (ast_strlen_zero(data)) {
79  ast_log(LOG_WARNING, "Syntax: %s(<data>) - missing argument!\n", cmd);
80  return -1;
81  }
82 
83  if (cmd[7] == 'E') {
84  if (buf) {
85  ast_base64encode(buf, (unsigned char *) data, strlen(data), len);
86  } else {
87  if (len >= 0) {
88  ast_str_make_space(str, len ? len : ast_str_strlen(*str) + strlen(data) * 4 / 3 + 2);
89  }
90  ast_base64encode(ast_str_buffer(*str) + ast_str_strlen(*str), (unsigned char *) data, strlen(data), ast_str_size(*str) - ast_str_strlen(*str));
91  ast_str_update(*str);
92  }
93  } else {
94  int decoded_len;
95  if (buf) {
96  decoded_len = ast_base64decode((unsigned char *) buf, data, len);
97  /* add a terminating null at the end of buf, or at the
98  * end of our decoded string, which ever is less */
99  buf[decoded_len <= (len - 1) ? decoded_len : len - 1] = '\0';
100  } else {
101  if (len >= 0) {
102  ast_str_make_space(str, len ? len : ast_str_strlen(*str) + strlen(data) * 3 / 4 + 2);
103  }
104  decoded_len = ast_base64decode((unsigned char *) ast_str_buffer(*str) + ast_str_strlen(*str), data, ast_str_size(*str) - ast_str_strlen(*str));
105  if (len)
106  /* add a terminating null at the end of our
107  * buffer, or at the end of our decoded string,
108  * which ever is less */
109  ast_str_buffer(*str)[decoded_len <= (len - 1) ? decoded_len : len - 1] = '\0';
110  else
111  /* space for the null is allocated above */
112  ast_str_buffer(*str)[decoded_len] = '\0';
113 
114  ast_str_update(*str);
115  }
116  }
117 
118  return 0;
119 }
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:699
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define ast_str_make_space(buf, new_len)
Definition: strings.h:780
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
Definition: main/utils.c:294
#define ast_log
Definition: astobj2.c:42
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
Definition: main/utils.c:404
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
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:663

◆ 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 127 of file func_base64.c.

References base64_helper(), and NULL.

129 {
130  return base64_helper(chan, cmd, data, NULL, buf, len);
131 }
#define NULL
Definition: resample.c:96
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:75
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

◆ load_module()

static int load_module ( void  )
static

Definition at line 151 of file func_base64.c.

References ast_custom_function_register.

152 {
155 }
static struct ast_custom_function base64_decode_function
Definition: func_base64.c:139
static struct ast_custom_function base64_encode_function
Definition: func_base64.c:133
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 145 of file func_base64.c.

References ast_custom_function_unregister().

146 {
149 }
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static struct ast_custom_function base64_decode_function
Definition: func_base64.c:139
static struct ast_custom_function base64_encode_function
Definition: func_base64.c:133

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 = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 157 of file func_base64.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 157 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)
Definition: func_base64.c:121
static int base64_str_helper(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_base64.c:127

Definition at line 139 of file func_base64.c.

◆ base64_encode_function

struct ast_custom_function base64_encode_function
static
Initial value:
= {
.name = "BASE64_ENCODE",
}
static int base64_buf_helper(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_base64.c:121
static int base64_str_helper(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_base64.c:127

Definition at line 133 of file func_base64.c.