Charset conversions. More...
#include "asterisk.h"
#include <ctype.h>
#include <iconv.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
Go to the source code of this file.
Defines | |
#define | AST_ICONV_CAST void * |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | iconv_read (struct ast_channel *chan, const char *cmd, char *arguments, char *buf, size_t len) |
static int | load_module (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info __MODULE_INFO_SECTION | __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Charset conversions" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_custom_function | iconv_function |
Charset conversions.
Definition in file func_iconv.c.
#define AST_ICONV_CAST void * |
Some systems define the second arg to iconv() as (const char *), while others define it as (char *). Cast it to a (void *) to suppress compiler warnings about it.
Definition at line 75 of file func_iconv.c.
Referenced by iconv_read().
static void __reg_module | ( | void | ) | [static] |
Definition at line 143 of file func_iconv.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 143 of file func_iconv.c.
static int iconv_read | ( | struct ast_channel * | chan, |
const char * | cmd, | ||
char * | arguments, | ||
char * | buf, | ||
size_t | len | ||
) | [static] |
Definition at line 77 of file func_iconv.c.
References AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, AST_ICONV_CAST, ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), errno, len(), LOG_ERROR, LOG_WARNING, parse(), and text.
{ AST_DECLARE_APP_ARGS(args, AST_APP_ARG(in_charset); AST_APP_ARG(out_charset); AST_APP_ARG(text); ); iconv_t cd; size_t incount, outcount = len; char *parse; if (ast_strlen_zero(arguments)) { ast_log(LOG_WARNING, "Syntax: ICONV(<in-charset>,<out-charset>,<text>) - missing arguments!\n"); return -1; } parse = ast_strdupa(arguments); AST_STANDARD_APP_ARGS(args, parse); if (args.argc < 3) { ast_log(LOG_WARNING, "Syntax: ICONV(<in-charset>,<out-charset>,<text>) %d\n", args.argc); return -1; } incount = strlen(args.text); ast_debug(1, "Iconv: \"%s\" %s -> %s\n", args.text, args.in_charset, args.out_charset); cd = iconv_open(args.out_charset, args.in_charset); if (cd == (iconv_t) -1) { ast_log(LOG_ERROR, "conversion from '%s' to '%s' not available. type 'iconv -l' in a shell to list the supported charsets.\n", args.in_charset, args.out_charset); return -1; } if (iconv(cd, (AST_ICONV_CAST) &args.text, &incount, &buf, &outcount) == (size_t) -1) { if (errno == E2BIG) ast_log(LOG_WARNING, "Iconv: output buffer too small.\n"); else if (errno == EILSEQ) ast_log(LOG_WARNING, "Iconv: illegal character.\n"); else if (errno == EINVAL) ast_log(LOG_WARNING, "Iconv: incomplete character sequence.\n"); else ast_log(LOG_WARNING, "Iconv: error %d: %s.\n", errno, strerror(errno)); } iconv_close(cd); return 0; }
static int load_module | ( | void | ) | [static] |
Definition at line 138 of file func_iconv.c.
References ast_custom_function_register.
{ return ast_custom_function_register(&iconv_function); }
static int unload_module | ( | void | ) | [static] |
Definition at line 133 of file func_iconv.c.
References ast_custom_function_unregister().
{ return ast_custom_function_unregister(&iconv_function); }
struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Charset conversions" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static] |
Definition at line 143 of file func_iconv.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 143 of file func_iconv.c.
struct ast_custom_function iconv_function [static] |
{ .name = "ICONV", .read = iconv_read }
Definition at line 128 of file func_iconv.c.