Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


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"

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)
 
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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static 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

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

Referenced by iconv_read().

Function Documentation

static void __reg_module ( void  )
static

Definition at line 144 of file func_iconv.c.

static void __unreg_module ( void  )
static

Definition at line 144 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 78 of file func_iconv.c.

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(), errno, len(), LOG_ERROR, LOG_WARNING, parse(), and text.

79 {
81  AST_APP_ARG(in_charset);
82  AST_APP_ARG(out_charset);
84  );
85  iconv_t cd;
86  size_t incount, outcount = len;
87  char *parse;
88 
89  if (ast_strlen_zero(arguments)) {
90  ast_log(LOG_WARNING, "Syntax: ICONV(<in-charset>,<out-charset>,<text>) - missing arguments!\n");
91  return -1;
92  }
93 
94  parse = ast_strdupa(arguments);
96 
97  if (args.argc < 3) {
98  ast_log(LOG_WARNING, "Syntax: ICONV(<in-charset>,<out-charset>,<text>) %u\n", args.argc);
99  return -1;
100  }
101 
102  incount = strlen(args.text);
103 
104  ast_debug(1, "Iconv: \"%s\" %s -> %s\n", args.text, args.in_charset, args.out_charset);
105 
106  cd = iconv_open(args.out_charset, args.in_charset);
107 
108  if (cd == (iconv_t) -1) {
109  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);
110  return -1;
111  }
112 
113  if (iconv(cd, (AST_ICONV_CAST) &args.text, &incount, &buf, &outcount) == (size_t) -1) {
114  if (errno == E2BIG)
115  ast_log(LOG_WARNING, "Iconv: output buffer too small.\n");
116  else if (errno == EILSEQ)
117  ast_log(LOG_WARNING, "Iconv: illegal character.\n");
118  else if (errno == EINVAL)
119  ast_log(LOG_WARNING, "Iconv: incomplete character sequence.\n");
120  else
121  ast_log(LOG_WARNING, "Iconv: error %d: %s.\n", errno, strerror(errno));
122  }
123  iconv_close(cd);
124 
125  return 0;
126 }
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
char * text
Definition: app_queue.c:1091
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define AST_ICONV_CAST
Definition: func_iconv.c:76
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define LOG_ERROR
Definition: logger.h:155
static struct @350 args
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static int load_module ( void  )
static

Definition at line 139 of file func_iconv.c.

References ast_custom_function_register.

140 {
142 }
static struct ast_custom_function iconv_function
Definition: func_iconv.c:129
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
static int unload_module ( void  )
static

Definition at line 134 of file func_iconv.c.

References ast_custom_function_unregister().

135 {
137 }
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
static struct ast_custom_function iconv_function
Definition: func_iconv.c:129

Variable Documentation

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 144 of file func_iconv.c.

Definition at line 144 of file func_iconv.c.

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:78

Definition at line 129 of file func_iconv.c.