Asterisk - The Open Source Telephony Project GIT-master-f36a736
Macros | Functions | Variables
func_iconv.c File Reference

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"
Include dependency graph for func_iconv.c:

Go to the source code of this file.

Macros

#define AST_ICONV_CAST   void *
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (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 __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Charset conversions" , .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 = 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 iconv_function
 

Detailed Description

Charset conversions.

Author
Sven Slezak sunny.nosp@m.@mez.nosp@m.zo.ne.nosp@m.t

Definition in file func_iconv.c.

Macro Definition Documentation

◆ AST_ICONV_CAST

#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 74 of file func_iconv.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 143 of file func_iconv.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 143 of file func_iconv.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 143 of file func_iconv.c.

◆ iconv_read()

static int iconv_read ( struct ast_channel chan,
const char *  cmd,
char *  arguments,
char *  buf,
size_t  len 
)
static

Definition at line 76 of file func_iconv.c.

77{
79 AST_APP_ARG(in_charset);
80 AST_APP_ARG(out_charset);
82 );
83 iconv_t cd;
84 size_t incount, outcount = len - 1;
85 char *parse;
86
87 if (ast_strlen_zero(arguments)) {
88 ast_log(LOG_WARNING, "Syntax: ICONV(<in-charset>,<out-charset>,<text>) - missing arguments!\n");
89 return -1;
90 }
91
92 parse = ast_strdupa(arguments);
94
95 if (args.argc < 3) {
96 ast_log(LOG_WARNING, "Syntax: ICONV(<in-charset>,<out-charset>,<text>) %u\n", args.argc);
97 return -1;
98 }
99
100 incount = strlen(args.text);
101
102 ast_debug(1, "Iconv: \"%s\" %s -> %s\n", args.text, args.in_charset, args.out_charset);
103
104 cd = iconv_open(args.out_charset, args.in_charset);
105
106 if (cd == (iconv_t) -1) {
107 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);
108 return -1;
109 }
110
111 if (iconv(cd, (AST_ICONV_CAST) &args.text, &incount, &buf, &outcount) == (size_t) -1) {
112 if (errno == E2BIG)
113 ast_log(LOG_WARNING, "Iconv: output buffer too small.\n");
114 else if (errno == EILSEQ)
115 ast_log(LOG_WARNING, "Iconv: illegal character.\n");
116 else if (errno == EINVAL)
117 ast_log(LOG_WARNING, "Iconv: incomplete character sequence.\n");
118 else
119 ast_log(LOG_WARNING, "Iconv: error %d: %s.\n", errno, strerror(errno));
120 }
121 *buf = '\0';
122 iconv_close(cd);
123
124 return 0;
125}
char * text
Definition: app_queue.c:1668
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_ICONV_CAST
Definition: func_iconv.c:74
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define LOG_WARNING
int errno
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
const char * args

References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, AST_ICONV_CAST, ast_log, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), buf, errno, len(), LOG_ERROR, LOG_WARNING, and text.

◆ load_module()

static int load_module ( void  )
static

Definition at line 138 of file func_iconv.c.

139{
141}
static struct ast_custom_function iconv_function
Definition: func_iconv.c:128
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

References ast_custom_function_register, and iconv_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 133 of file func_iconv.c.

134{
136}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), and iconv_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Charset conversions" , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 143 of file func_iconv.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 143 of file func_iconv.c.

◆ iconv_function

struct ast_custom_function iconv_function
static
Initial value:
= {
.name = "ICONV",
.read = iconv_read
}
static int iconv_read(struct ast_channel *chan, const char *cmd, char *arguments, char *buf, size_t len)
Definition: func_iconv.c:76

Definition at line 128 of file func_iconv.c.

Referenced by load_module(), and unload_module().