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 | |
| AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Charset conversions") | |
| 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_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().
| AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
| "Charset conversions" | ||||
| ) |
| 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, LOG_ERROR, LOG_WARNING, parse(), and text.
00078 { 00079 AST_DECLARE_APP_ARGS(args, 00080 AST_APP_ARG(in_charset); 00081 AST_APP_ARG(out_charset); 00082 AST_APP_ARG(text); 00083 ); 00084 iconv_t cd; 00085 size_t incount, outcount = len; 00086 char *parse; 00087 00088 if (ast_strlen_zero(arguments)) { 00089 ast_log(LOG_WARNING, "Syntax: ICONV(<in-charset>,<out-charset>,<text>) - missing arguments!\n"); 00090 return -1; 00091 } 00092 00093 parse = ast_strdupa(arguments); 00094 AST_STANDARD_APP_ARGS(args, parse); 00095 00096 if (args.argc < 3) { 00097 ast_log(LOG_WARNING, "Syntax: ICONV(<in-charset>,<out-charset>,<text>) %d\n", args.argc); 00098 return -1; 00099 } 00100 00101 incount = strlen(args.text); 00102 00103 ast_debug(1, "Iconv: \"%s\" %s -> %s\n", args.text, args.in_charset, args.out_charset); 00104 00105 cd = iconv_open(args.out_charset, args.in_charset); 00106 00107 if (cd == (iconv_t) -1) { 00108 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); 00109 return -1; 00110 } 00111 00112 if (iconv(cd, (AST_ICONV_CAST) &args.text, &incount, &buf, &outcount) == (size_t) -1) { 00113 if (errno == E2BIG) 00114 ast_log(LOG_WARNING, "Iconv: output buffer too small.\n"); 00115 else if (errno == EILSEQ) 00116 ast_log(LOG_WARNING, "Iconv: illegal character.\n"); 00117 else if (errno == EINVAL) 00118 ast_log(LOG_WARNING, "Iconv: incomplete character sequence.\n"); 00119 else 00120 ast_log(LOG_WARNING, "Iconv: error %d: %s.\n", errno, strerror(errno)); 00121 } 00122 iconv_close(cd); 00123 00124 return 0; 00125 }
| static int load_module | ( | void | ) | [static] |
Definition at line 138 of file func_iconv.c.
References ast_custom_function_register.
00139 { 00140 return ast_custom_function_register(&iconv_function); 00141 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 133 of file func_iconv.c.
References ast_custom_function_unregister().
00134 { 00135 return ast_custom_function_unregister(&iconv_function); 00136 }
struct ast_custom_function iconv_function [static] |
{
.name = "ICONV",
.read = iconv_read
}
Definition at line 128 of file func_iconv.c.
1.6.1