include/charset.h

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    charset defines
00004    Copyright (C) Andrew Tridgell 2001
00005    Copyright (C) Jelmer Vernooij 2002
00006    
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011    
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016    
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 */
00021 
00022 /* this defines the charset types used in samba */
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  *   for each charset we have a function that pushes from that charset to a ucs2
00029  *   buffer, and a function that pulls from ucs2 buffer to that  charset.
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  * This is auxiliary struct used by source/script/gen-8-bit-gap.sh script
00043  * during generation of an encoding table for charset module
00044  *     */
00045 
00046 struct charset_gap_table {
00047   uint16 start;
00048   uint16 end;
00049   int32 idx;
00050 };
00051 
00052 /*
00053  *   Define stub for charset module which implements 8-bit encoding with gaps.
00054  *   Encoding tables for such module should be produced from glibc's CHARMAPs
00055  *   using script source/script/gen-8bit-gap.sh
00056  *   CHARSETNAME is CAPITALIZED charset name
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 

Sambaに対してSat Aug 29 21:22:54 2009に生成されました。  doxygen 1.4.7