00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 typedef enum {CH_UTF16LE=0, CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4, CH_UTF16BE=5} charset_t;
00024
00025 #define NUM_CHARSETS 6
00026
00027
00028
00029
00030
00031
00032 struct charset_functions {
00033 const char *name;
00034 size_t (*pull)(void *, const char **inbuf, size_t *inbytesleft,
00035 char **outbuf, size_t *outbytesleft);
00036 size_t (*push)(void *, const char **inbuf, size_t *inbytesleft,
00037 char **outbuf, size_t *outbytesleft);
00038 struct charset_functions *prev, *next;
00039 };
00040
00041
00042
00043
00044
00045
00046 struct charset_gap_table {
00047 uint16 start;
00048 uint16 end;
00049 int32 idx;
00050 };
00051
00052
00053
00054
00055
00056
00057
00058
00059 #define SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP(CHARSETNAME) \
00060 static size_t CHARSETNAME ## _push(void *cd, const char **inbuf, size_t *inbytesleft, \
00061 char **outbuf, size_t *outbytesleft) \
00062 { \
00063 while (*inbytesleft >= 2 && *outbytesleft >= 1) { \
00064 int i; \
00065 int done = 0; \
00066 \
00067 uint16 ch = SVAL(*inbuf,0); \
00068 \
00069 for (i=0; from_idx[i].start != 0xffff; i++) { \
00070 if ((from_idx[i].start <= ch) && (from_idx[i].end >= ch)) { \
00071 ((unsigned char*)(*outbuf))[0] = from_ucs2[from_idx[i].idx+ch]; \
00072 (*inbytesleft) -= 2; \
00073 (*outbytesleft) -= 1; \
00074 (*inbuf) += 2; \
00075 (*outbuf) += 1; \
00076 done = 1; \
00077 break; \
00078 } \
00079 } \
00080 if (!done) { \
00081 errno = EINVAL; \
00082 return -1; \
00083 } \
00084 \
00085 } \
00086 \
00087 if (*inbytesleft == 1) { \
00088 errno = EINVAL; \
00089 return -1; \
00090 } \
00091 \
00092 if (*inbytesleft > 1) { \
00093 errno = E2BIG; \
00094 return -1; \
00095 } \
00096 \
00097 return 0; \
00098 } \
00099 \
00100 static size_t CHARSETNAME ## _pull(void *cd, const char **inbuf, size_t *inbytesleft, \
00101 char **outbuf, size_t *outbytesleft) \
00102 { \
00103 while (*inbytesleft >= 1 && *outbytesleft >= 2) { \
00104 *(uint16*)(*outbuf) = to_ucs2[((unsigned char*)(*inbuf))[0]]; \
00105 (*inbytesleft) -= 1; \
00106 (*outbytesleft) -= 2; \
00107 (*inbuf) += 1; \
00108 (*outbuf) += 2; \
00109 } \
00110 \
00111 if (*inbytesleft > 0) { \
00112 errno = E2BIG; \
00113 return -1; \
00114 } \
00115 \
00116 return 0; \
00117 } \
00118 \
00119 struct charset_functions CHARSETNAME ## _functions = \
00120 {#CHARSETNAME, CHARSETNAME ## _pull, CHARSETNAME ## _push}; \
00121 \
00122 NTSTATUS charset_ ## CHARSETNAME ## _init(void); \
00123 NTSTATUS charset_ ## CHARSETNAME ## _init(void) \
00124 { \
00125 return smb_register_charset(& CHARSETNAME ## _functions); \
00126 } \
00127