[svn-commits] branch jcollie/bug7021 r26984 - in /team/jcollie/bug7021: ./ funcs/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu May 11 10:11:39 MST 2006


Author: jcollie
Date: Thu May 11 12:11:38 2006
New Revision: 26984

URL: http://svn.digium.com/view/asterisk?rev=26984&view=rev
Log:
Apply patch from bug 7021.  Note that if you try out this patch (or merge it to trunk) you'll need to regenerate the autoconf files by running bootstrap.sh

Modified:
    team/jcollie/bug7021/configure.ac
    team/jcollie/bug7021/funcs/func_strings.c

Modified: team/jcollie/bug7021/configure.ac
URL: http://svn.digium.com/view/asterisk/team/jcollie/bug7021/configure.ac?rev=26984&r1=26983&r2=26984&view=diff
==============================================================================
--- team/jcollie/bug7021/configure.ac (original)
+++ team/jcollie/bug7021/configure.ac Thu May 11 12:11:38 2006
@@ -654,7 +654,7 @@
 AC_HEADER_DIRENT
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h termios.h unistd.h utime.h])
+AC_CHECK_HEADERS([arpa/inet.h fcntl.h iconv.h inttypes.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h termios.h unistd.h utime.h])
 
 AC_SYS_LARGEFILE
 

Modified: team/jcollie/bug7021/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/team/jcollie/bug7021/funcs/func_strings.c?rev=26984&r1=26983&r2=26984&view=diff
==============================================================================
--- team/jcollie/bug7021/funcs/func_strings.c (original)
+++ team/jcollie/bug7021/funcs/func_strings.c Thu May 11 12:11:38 2006
@@ -29,6 +29,11 @@
 #include <string.h>
 #include <sys/types.h>
 #include <regex.h>
+
+#ifdef HAVE_ICONV_H
+#include <iconv.h>
+#include <errno.h>
+#endif
 
 #include "asterisk.h"
 
@@ -422,6 +427,58 @@
 	.desc = "Example:  ${KEYPADHASH(Les)} returns \"537\"\n",
 };
 
+#ifdef HAVE_ICONV_H
+static int acf_iconv(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+	int ret = 0;
+	iconv_t cd;
+	char *input;
+	size_t inputlen;
+	char *output = buf;
+	size_t outputlen = len;
+
+	AST_DECLARE_APP_ARGS(args,
+			     AST_APP_ARG(input);
+			     AST_APP_ARG(fromcode);
+			     AST_APP_ARG(tocode);
+		);
+	
+	AST_STANDARD_APP_ARGS(args, data);
+	
+	if ((cd = iconv_open(args.tocode, args.fromcode)) == (iconv_t) -1) {
+		ast_log(LOG_ERROR, "Unable to open iconv conversion descriptor.\n");
+		return -1;
+	}
+
+	input = args.input;
+	inputlen = strlen(input);
+
+	if (iconv(cd, &input, &inputlen, &output, &outputlen) == -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.\n");
+		}
+		ret = -1;
+	}
+	iconv_close(cd);
+	*output = '\0';
+	return ret;
+}
+
+static struct ast_custom_function iconv_function = {
+	.name = "ICONV",
+	.synopsis = "Convert character sets.",
+	.syntax = "ICONV(<input>|<fromcharset>|<tocharset>)",
+	.read = acf_iconv,
+	.desc = "Convert character sets.\n",
+};
+#endif
+
 static char *tdesc = "String handling dialplan functions";
 
 static int unload_module(void *mod)
@@ -438,7 +495,9 @@
 	res |= ast_custom_function_unregister(&strptime_function);
 	res |= ast_custom_function_unregister(&eval_function);
 	res |= ast_custom_function_unregister(&keypadhash_function);
-
+#ifdef HAVE_ICONV_H
+	res |= ast_custom_function_unregister(&iconv_function);
+#endif
 	return res;
 }
 
@@ -456,7 +515,9 @@
 	res |= ast_custom_function_register(&strptime_function);
 	res |= ast_custom_function_register(&eval_function);
 	res |= ast_custom_function_register(&keypadhash_function);
-
+#ifdef HAVE_ICONV_H
+	res |= ast_custom_function_register(&iconv_function);
+#endif
 	return res;
 }
 



More information about the svn-commits mailing list