This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "system/iconv.h"
+#include "param/param.h"
/**
* @file
* @sa lib/iconv.c
*/
+char *unix_charset = NULL;
+char *dos_charset = NULL;
+char *display_charset = NULL;
+
/**
* Return the name of a charset to give to iconv().
**/
static const char *charset_name(charset_t ch)
{
- const char *ret = NULL;
-
- if (ch == CH_UTF16) ret = "UTF-16LE";
- else if (ch == CH_UNIX) ret = lp_unix_charset();
- else if (ch == CH_DOS) ret = lp_dos_charset();
- else if (ch == CH_DISPLAY) ret = lp_display_charset();
- else if (ch == CH_UTF8) ret = "UTF8";
- else if (ch == CH_UTF16BE) ret = "UTF-16BE";
-
- if (!ret || !*ret) ret = "ASCII";
- return ret;
+ switch (ch) {
+ case CH_UTF16: return "UTF-16LE";
+ case CH_UNIX: return unix_charset;
+ case CH_DOS: return dos_charset;
+ case CH_DISPLAY: return display_charset;
+ case CH_UTF8: return "UTF8";
+ case CH_UTF16BE: return "UTF-16BE";
+ default:
+ return "ASCII";
+ }
}
static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
smb_iconv_t descriptor;
if (srclen == (size_t)-1)
- srclen = strlen(src)+1;
+ srclen = strlen(inbuf)+1;
descriptor = get_conv_handle(from, to);
* @param dest_len the maximum length in bytes allowed in the
* destination. If @p dest_len is -1 then no maximum is used.
**/
-_PUBLIC_ ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
+static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
{
size_t src_len;
ssize_t ret;
_PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
{
size_t src_len = strlen(src)+1;
-
*dest = NULL;
return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest);
}
* @param src_len is the length of the source area in bytes.
* @returns the number of bytes occupied by the string in @p src.
**/
-_PUBLIC_ ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
+static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
size_t ret;
if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) {
if (src_len == (size_t)-1) {
- src_len = strlen(src) + 1;
+ src_len = strlen((const char *)src) + 1;
} else {
- size_t len = strnlen(src, src_len);
+ size_t len = strnlen((const char *)src, src_len);
if (len < src_len)
len++;
src_len = len;
* @param dest_len is the maximum length allowed in the
* destination. If dest_len is -1 then no maxiumum is used.
**/
-_PUBLIC_ ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags)
+static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags)
{
size_t len=0;
size_t src_len = strlen(src);
_PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
{
size_t src_len = strlen(src)+1;
-
*dest = NULL;
return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest);
}
The resulting string in "dest" is always null terminated.
**/
-_PUBLIC_ size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
+static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
{
size_t ret;
return src_len;
}
+/**
+ * Copy a string from a ASCII src to a unix char * destination, allocating a buffer using talloc
+ *
+ * @param dest always set at least to NULL
+ *
+ * @returns The number of bytes occupied by the string in the destination
+ **/
+
+_PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
+{
+ size_t src_len = strlen(src)+1;
+ *dest = NULL;
+ return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest);
+}
+
/**
* Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc
*
/* this looks a little strange, but it is needed to cope
with codepoints above 64k */
olen = 2;
- outbuf = buf;
+ outbuf = (char *)buf;
smb_iconv(descriptor, &str, &ilen, &outbuf, &olen);
if (olen == 2) {
olen = 4;
- outbuf = buf;
+ outbuf = (char *)buf;
smb_iconv(descriptor, &str, &ilen, &outbuf, &olen);
if (olen == 4) {
/* we didn't convert any bytes */
if (c < 0x10000) {
ilen = 2;
olen = 5;
- inbuf = buf;
+ inbuf = (char *)buf;
SSVAL(buf, 0, c);
smb_iconv(descriptor, &inbuf, &ilen, &str, &olen);
if (ilen != 0) {
ilen = 4;
olen = 5;
- inbuf = buf;
+ inbuf = (char *)buf;
smb_iconv(descriptor, &inbuf, &ilen, &str, &olen);
if (ilen != 0) {