summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-12-16 09:20:34 +0000
committerAndrew Tridgell <tridge@samba.org>2003-12-16 09:20:34 +0000
commit7779b1e00022599f9b77dab7f5f983d930514f15 (patch)
treeb1e860ce476e5b15993f5532d5c3a854f912e83e /source4/lib
parent24c22aef90d8534ee2d016b37b2b302f1367d106 (diff)
downloadsamba-7779b1e00022599f9b77dab7f5f983d930514f15.tar.gz
samba-7779b1e00022599f9b77dab7f5f983d930514f15.tar.bz2
samba-7779b1e00022599f9b77dab7f5f983d930514f15.zip
added support for big-endian ucs2 strings (as used by big-endian
msrpc). this was easier than I expected! (This used to be commit a0a51af6b746b1f82faaa49d33c17fea9d708fb0)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/charcnv.c1
-rw-r--r--source4/lib/iconv.c37
2 files changed, 33 insertions, 5 deletions
diff --git a/source4/lib/charcnv.c b/source4/lib/charcnv.c
index 72277b4f2e..11b0e64dce 100644
--- a/source4/lib/charcnv.c
+++ b/source4/lib/charcnv.c
@@ -52,6 +52,7 @@ static const char *charset_name(charset_t ch)
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_UCS2BE) ret = "UCS-2BE";
if (!ret || !*ret) ret = "ASCII";
return ret;
diff --git a/source4/lib/iconv.c b/source4/lib/iconv.c
index 2a0b013257..3f37583e39 100644
--- a/source4/lib/iconv.c
+++ b/source4/lib/iconv.c
@@ -45,16 +45,18 @@
* @sa Samba Developers Guide
**/
-static size_t ascii_pull(void *,const char **, size_t *, char **, size_t *);
-static size_t ascii_push(void *,const char **, size_t *, char **, size_t *);
-static size_t utf8_pull(void *,const char **, size_t *, char **, size_t *);
-static size_t utf8_push(void *,const char **, size_t *, char **, size_t *);
+static size_t ascii_pull (void *,const char **, size_t *, char **, size_t *);
+static size_t ascii_push (void *,const char **, size_t *, char **, size_t *);
+static size_t utf8_pull (void *,const char **, size_t *, char **, size_t *);
+static size_t utf8_push (void *,const char **, size_t *, char **, size_t *);
static size_t ucs2hex_pull(void *,const char **, size_t *, char **, size_t *);
static size_t ucs2hex_push(void *,const char **, size_t *, char **, size_t *);
-static size_t iconv_copy(void *,const char **, size_t *, char **, size_t *);
+static size_t iconv_copy (void *,const char **, size_t *, char **, size_t *);
+static size_t iconv_swab (void *,const char **, size_t *, char **, size_t *);
static struct charset_functions builtin_functions[] = {
{"UCS-2LE", iconv_copy, iconv_copy},
+ {"UCS-2BE", iconv_swab, iconv_swab},
{"UTF8", utf8_pull, utf8_push},
{"ASCII", ascii_pull, ascii_push},
{"UCS2-HEX", ucs2hex_pull, ucs2hex_push},
@@ -404,6 +406,31 @@ static size_t ucs2hex_push(void *cd, const char **inbuf, size_t *inbytesleft,
return 0;
}
+static size_t iconv_swab(void *cd, const char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft)
+{
+ int n;
+
+ n = MIN(*inbytesleft, *outbytesleft);
+
+ swab(*inbuf, *outbuf, (n&~1));
+ if (n&1) {
+ (*outbuf)[n-1] = 0;
+ }
+
+ (*inbytesleft) -= n;
+ (*outbytesleft) -= n;
+ (*inbuf) += n;
+ (*outbuf) += n;
+
+ if (*inbytesleft > 0) {
+ errno = E2BIG;
+ return -1;
+ }
+
+ return 0;
+}
+
static size_t iconv_copy(void *cd, const char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft)