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.

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 __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 struct ast_module_infoast_module_info = &__mod_info
static struct ast_custom_function iconv_function


Detailed Description

Charset conversions.

Author:
Sven Slezak <sunny@mezzo.net>

Definition in file func_iconv.c.


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

00079 {
00080    AST_DECLARE_APP_ARGS(args,
00081       AST_APP_ARG(in_charset);
00082       AST_APP_ARG(out_charset);
00083       AST_APP_ARG(text);
00084    );
00085    iconv_t cd;
00086    size_t incount, outcount = len;
00087    char *parse;
00088 
00089    if (ast_strlen_zero(arguments)) {
00090       ast_log(LOG_WARNING, "Syntax: ICONV(<in-charset>,<out-charset>,<text>) - missing arguments!\n");
00091       return -1;
00092    }
00093 
00094    parse = ast_strdupa(arguments);
00095    AST_STANDARD_APP_ARGS(args, parse);
00096 
00097    if (args.argc < 3) {
00098       ast_log(LOG_WARNING, "Syntax: ICONV(<in-charset>,<out-charset>,<text>) %u\n", args.argc);
00099       return -1;
00100    }
00101 
00102    incount = strlen(args.text);
00103 
00104    ast_debug(1, "Iconv: \"%s\" %s -> %s\n", args.text, args.in_charset, args.out_charset);
00105 
00106    cd = iconv_open(args.out_charset, args.in_charset);
00107 
00108    if (cd == (iconv_t) -1) {
00109       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);
00110       return -1;
00111    }
00112 
00113    if (iconv(cd, (AST_ICONV_CAST) &args.text, &incount, &buf, &outcount) == (size_t) -1) {
00114       if (errno == E2BIG)
00115          ast_log(LOG_WARNING, "Iconv: output buffer too small.\n");
00116       else if (errno == EILSEQ)
00117          ast_log(LOG_WARNING,  "Iconv: illegal character.\n");
00118       else if (errno == EINVAL)
00119          ast_log(LOG_WARNING,  "Iconv: incomplete character sequence.\n");
00120       else
00121          ast_log(LOG_WARNING,  "Iconv: error %d: %s.\n", errno, strerror(errno));
00122    }
00123    iconv_close(cd);
00124 
00125    return 0;
00126 }

static int load_module ( void   )  [static]

Definition at line 139 of file func_iconv.c.

References ast_custom_function_register.

00140 {
00141    return ast_custom_function_register(&iconv_function);
00142 }

static int unload_module ( void   )  [static]

Definition at line 134 of file func_iconv.c.

References ast_custom_function_unregister().

00135 {
00136    return ast_custom_function_unregister(&iconv_function);
00137 }


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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 144 of file func_iconv.c.

Definition at line 144 of file func_iconv.c.

Initial value:

 {
   .name = "ICONV",
   .read = iconv_read
}

Definition at line 129 of file func_iconv.c.


Generated on Thu Apr 16 06:31:18 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6