summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-06-29 17:51:31 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:23:43 -0500
commitef8706acd1a880a811b65310d01f309d36d9d47e (patch)
treed26952c6c958863ab3ee5997272688d0f2332169 /source3/lib
parentf9df7787e6b1fec9404451eb2220dc34baf5e4a3 (diff)
downloadsamba-ef8706acd1a880a811b65310d01f309d36d9d47e.tar.gz
samba-ef8706acd1a880a811b65310d01f309d36d9d47e.tar.bz2
samba-ef8706acd1a880a811b65310d01f309d36d9d47e.zip
r23662: According to simo, check_dos_char is needed
(This used to be commit c195eccefea69c17169c350a13bbfe845fc6fc44)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/charcnv.c1
-rw-r--r--source3/lib/util_unistr.c52
2 files changed, 52 insertions, 1 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 7be073fafc..35343b2f0a 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -179,6 +179,7 @@ void init_iconv(void)
* codepage changes? */
/* XXX: Is the did_reload test too strict? */
conv_silent = True;
+ init_doschar_table();
init_valid_table();
conv_silent = False;
}
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 0221d19dc1..cf040a2dfc 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -36,6 +36,14 @@ static BOOL lowcase_table_use_unmap;
static BOOL valid_table_use_unmap;
/**
+ * This table says which Unicode characters are valid dos
+ * characters.
+ *
+ * Each value is just a single bit.
+ **/
+static uint8 doschar_table[8192]; /* 65536 characters / 8 bits/byte */
+
+/**
* Destroy global objects allocated by load_case_tables()
**/
void gfree_case_tables(void)
@@ -142,6 +150,21 @@ void load_case_tables(void)
#endif
}
+/*
+ see if a ucs2 character can be mapped correctly to a dos character
+ and mapped back to the same character in ucs2
+*/
+
+int check_dos_char(smb_ucs2_t c)
+{
+ lazy_initialize_conv();
+
+ /* Find the right byte, and right bit within the byte; return
+ * 1 or 0 */
+ return (doschar_table[(c & 0xffff) / 8] & (1 << (c & 7))) != 0;
+}
+
+
static int check_dos_char_slowly(smb_ucs2_t c)
{
char buf[10];
@@ -159,6 +182,33 @@ static int check_dos_char_slowly(smb_ucs2_t c)
return (c == c2);
}
+
+/**
+ * Fill out doschar table the hard way, by examining each character
+ **/
+
+void init_doschar_table(void)
+{
+ int i, j, byteval;
+
+ /* For each byte of packed table */
+
+ for (i = 0; i <= 0xffff; i += 8) {
+ byteval = 0;
+ for (j = 0; j <= 7; j++) {
+ smb_ucs2_t c;
+
+ c = i + j;
+
+ if (check_dos_char_slowly(c)) {
+ byteval |= 1 << j;
+ }
+ }
+ doschar_table[i/8] = byteval;
+ }
+}
+
+
/**
* Load the valid character map table from <tt>valid.dat</tt> or
* create from the configured codepage.
@@ -207,7 +257,7 @@ void init_valid_table(void)
for (;i<0x10000;i++) {
smb_ucs2_t c;
SSVAL(&c, 0, i);
- valid_table[i] = check_dos_char_slowly(c);
+ valid_table[i] = check_dos_char(c);
}
}