Windows: improved idle dead time handling
[openafs.git] / src / WINNT / afsd / cm_nls.h
1 /*
2  * Copyright (c) 2008 Secure Endpoints Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24
25 #ifndef OPENAFS_WINNT_AFSD_CM_NLS_H
26 #define OPENAFS_WINNT_AFSD_CM_NLS_H 1
27
28 /* Character types
29
30    There are three character types that we use as implementation
31    types.  These should generally only be referenced by the
32    nationalization code.
33
34    - ::cm_unichar_t
35
36    - ::cm_normchar_t
37
38    - ::cm_utf8char_t
39
40    The character types that are used by code are :
41
42    - ::clientchar_t
43
44    - ::normchar_t
45
46    - ::fschar_t
47
48  */
49
50 /*! \brief Unicode UTF-16 Character */
51 typedef wchar_t cm_unichar_t;
52
53 /*! \brief Unicode UTF-16 Normalized Character (NF-C) */
54 typedef wchar_t cm_normchar_t;
55
56 /*! \brief Unicode UTF-8 Character */
57 typedef unsigned char cm_utf8char_t;
58
59 /*! \brief Client name */
60 typedef cm_unichar_t  clientchar_t;
61
62 /*! \brief File Server name */
63 typedef cm_utf8char_t fschar_t;
64
65 /*! \brief Normalized name */
66 typedef cm_normchar_t normchar_t;
67
68 #define __paste(a,b) a ## b
69 #define _C(s) __paste(L,s)
70 #define _FS(s) s
71 #define _N(s) __paste(L,s)
72
73 #define cm_ClientStringToNormStringAlloc cm_NormalizeStringAlloc
74 #define cm_ClientStringToFsStringAlloc cm_Utf16ToUtf8Alloc
75 #define cm_ClientStringToUtf8Alloc cm_Utf16ToUtf8Alloc
76 #define cm_FsStringToClientStringAlloc cm_Utf8ToUtf16Alloc
77 #define cm_FsStringToNormStringAlloc cm_NormalizeUtf8StringToUtf16Alloc
78 #define cm_Utf8ToNormStringAlloc cm_NormalizeUtf8StringToUtf16Alloc
79 #define cm_Utf8ToClientStringAlloc cm_Utf8ToUtf16Alloc
80
81 #define cm_ClientStringToUtf16 cm_Utf16ToUtf16
82 #define cm_ClientStringToUtf8  cm_Utf16ToUtf8
83 #define cm_ClientStringToFsString cm_Utf16ToUtf8
84 #define cm_ClientStringToNormString cm_NormalizeString
85 #define cm_FsStringToClientString cm_Utf8ToUtf16
86 #define cm_FsStringToNormString cm_NormalizeUtf8StringToUtf16
87 #define cm_Utf8ToClientString cm_Utf8ToUtf16
88 #define cm_OemToClientString(s,cchs,d,cchd) MultiByteToWideChar(CP_OEMCP, 0, s, cchs, d, cchd)
89 #define cm_AnsiToClientString(s,cchs,d,cchd) MultiByteToWideChar(CP_ACP, 0, s, cchs, d, cchd)
90
91 #define cm_ClientStrCmp wcscmp
92 #define cm_ClientStrCmpI cm_stricmp_utf16
93 #define cm_ClientStrCmpIA cm_stricmp_utf16
94 #define cm_ClientStrCmpNI cm_strnicmp_utf16
95 #define cm_ClientStrCmpN wcsncmp
96 #define cm_ClientStrChr wcschr
97 #define cm_ClientStrRChr wcsrchr
98 #define cm_ClientStrCpy(d,cch,s) StringCchCopyW(d,cch,s)
99 #define cm_ClientStrCpyN(d,cch,s,n) StringCchCopyNW(d,cch,s,n)
100 #define cm_ClientStrDup wcsdup
101 #define cm_ClientStrCat(d,cch,s) StringCchCatW(d,cch,s)
102 #define cm_ClientStrCatN(d,cch,s,n) StringCchCatNW(d,cch,s,n)
103 #define cm_ClientStrPrintfN StringCchPrintfW
104 #define cm_ClientStrPrintfV StringCchVPrintfW
105 //#define cm_ClientStrPrintf  swprintf
106 #define cm_ClientStrLen wcslen
107 #define cm_ClientStrLwr cm_strlwr_utf16
108 #define cm_ClientStrUpr cm_strupr_utf16
109 #define cm_ClientStrSpn wcsspn
110 #define cm_ClientStrCSpn wcscspn
111 #define osi_LogSaveClientString osi_LogSaveStringW
112 #define cm_ClientCharThis char_this_utf16
113 #define cm_ClientCharNext char_next_utf16
114 #define cm_ClientCharPrev char_prev_utf16
115
116 #define cm_FsStrDup strdup
117 #define cm_FsStrLen strlen
118 #define cm_FsStrCat StringCchCatA
119 #define cm_FsStrPrintf StringCchPrintfA
120 #define cm_FsStrRChr strrchr
121 #define cm_FsStrChr  strchr
122 #define cm_FsStrCmpIA cm_stricmp_utf8
123 #define cm_FsStrCmpI cm_stricmp_utf8
124 #define cm_FsStrCmpA  strcmp
125 #define cm_FsStrCmp  strcmp
126 #define cm_FsStrCpy(d,cch,s) StringCchCopyA(d,cch,s)
127 #define osi_LogSaveFsString osi_LogSaveString
128 #define cm_FsStrCpyN(d,cch,s,n) StringCchCopyN(d,cch,s,n)
129
130 #define cm_NormStrDup wcsdup
131 #define cm_NormStrCmpI cm_stricmp_utf16
132 #define cm_NormStrCmp wcscmp
133 #define cm_NormCharUpr towupper
134
135 #define cm_IsValidClientString(s) cm_is_valid_utf16((s), -1)
136 #define cm_IsValidNormString(s) cm_is_valid_utf16((s), -1)
137
138 #define cm_Utf16ToClientString cm_Utf16ToUtf16
139
140 extern long cm_InitNormalization(void);
141
142 /* Functions annotated in accordance with sal.h */
143
144 #ifndef __in_z
145
146 #define __out_ecount_full_z(x)
147 #define __out_ecount_full_z_opt(x)
148 #define __in_z
149 #define __out_z
150 #define __inout_z
151
152 #endif
153
154 extern __out_ecount_full_z(*pcch_dest) __checkReturn __success(return != NULL) cm_normchar_t *
155     cm_NormalizeStringAlloc
156     (__in_ecount(cch_src) const cm_unichar_t * s,
157      int cch_src,
158      __out_ecount_full_opt(1) int *pcch_dest);
159
160 extern __success(return != 0) int
161     cm_NormalizeString
162     (__in_ecount(cch_src) const cm_unichar_t * s,
163      int cch_src,
164      __out_ecount_full_z_opt(cch_dest) cm_normchar_t * dest,
165      int cch_dest);
166
167 extern __out_ecount_full_z(*pcch_dest) __checkReturn __success(return != NULL) cm_utf8char_t *
168     cm_Utf16ToUtf8Alloc
169     (__in_ecount(cch_src) const cm_unichar_t * s,
170      int cch_src,
171      __out_ecount_full_opt(1) int *pcch_dest);
172
173 extern __out_ecount_full_z(*pcch_dest) __checkReturn __success(return != NULL) cm_unichar_t *
174     cm_Utf8ToUtf16Alloc
175     (__in_ecount(cch_src) const cm_utf8char_t * src,
176      int cch_src,
177      __out_ecount_full_opt(1) int *pcch_dest);
178
179 extern __success(return != 0) long
180     cm_NormalizeUtf8StringToUtf16
181     (__in_ecount(cch_src) const char * src,
182      int cch_src,
183      __out_ecount_full_z_opt(cch_dest) cm_normchar_t * dest,
184      int cch_dest);
185
186 extern __out_ecount_full_z(*pcch_dest) __checkReturn __success(return != NULL) cm_normchar_t *
187     cm_NormalizeUtf8StringToUtf16Alloc
188     (__in_ecount(cch_src) const cm_utf8char_t * src,
189      int cch_src,
190      __out_ecount_full_opt(1) int *pcch_dest);
191
192 extern __success(return != 0) int
193     cm_Utf8ToUtf16
194     (__in_ecount(cch_src) const cm_utf8char_t * src,
195      int cch_src,
196      __out_ecount_full_z_opt(cch_dest) cm_unichar_t * dest,
197      int cch_dest);
198
199 extern __success(return != 0) int
200     cm_Utf16ToUtf8
201     (__in_ecount(cch_src) const cm_unichar_t * src,
202      int cch_src,
203      __out_ecount_full_z_opt(cch_dest) cm_utf8char_t * dest,
204      int cch_dest);
205
206 extern __success(return != 0) int
207     cm_Utf16ToUtf16
208     (__in_ecount(cch_src) const cm_unichar_t * src,
209      int cch_src,
210      __out_ecount_full_z_opt(cch_dest) cm_unichar_t * dest,
211      int cch_dest);
212
213 extern int
214     cm_strnicmp_utf16
215     (__in_z const cm_unichar_t * str1,
216      __in_z const cm_unichar_t * str2,
217      int len);
218
219 extern int
220     cm_stricmp_utf16
221     (__in_z const cm_unichar_t * str1,
222      __in_z const cm_unichar_t * str2);
223
224 /* The cm_stricmp_utf8N function is identical to cm_stricmp_utf8
225    except it is used in instances where one of the strings is always
226    known to be ASCII. */
227 extern int
228     cm_stricmp_utf8N
229     (__in_z const char * str1,
230      __in_z const char * str2);
231 #define cm_stricmp_utf8N cm_stricmp_utf8
232
233 extern int
234     cm_stricmp_utf8
235     (__in_z const char * str1,
236      __in_z const char * str2);
237
238 /* The cm_strnicmp_utf8N function is identical to cm_strnicmp_utf8
239    except it is used in instances where one of the strings is always
240    known to be ASCII. */
241 extern int
242     cm_strnicmp_utf8N
243     (__in_z const char * str1,
244      __in_z const char * str2, int n);
245 #define cm_strnicmp_utf8N cm_strnicmp_utf8
246
247 extern int
248     cm_strnicmp_utf8
249     (__in_z const char * str1,
250      __in_z const char * str2, int n);
251
252 extern __out_z wchar_t *
253 char_next_utf16
254 (__in_z const wchar_t * c);
255
256 extern __out_z wchar_t *
257 char_prev_utf16
258 (__in_z const wchar_t * c);
259
260 extern __out_z wchar_t *
261 char_this_utf16
262 (__in_z const wchar_t * c);
263
264 extern __out_z cm_unichar_t *
265 cm_strlwr_utf16(__inout_z cm_unichar_t * str);
266
267 extern __out_z cm_unichar_t *
268 cm_strupr_utf16(__inout_z cm_unichar_t * str);
269
270 extern int
271 cm_is_valid_utf16(__in_z const wchar_t * c, int cch);
272
273 #ifdef DEBUG
274 wchar_t * cm_GetRawCharsAlloc(const wchar_t * c, int len);
275 #endif
276
277 #if 0
278
279 extern long cm_NormalizeUtf16StringToUtf8(const wchar_t * src, int cch_src,
280                                           char * adest, int cch_adest);
281
282 extern char * char_next_utf8(const char * c);
283
284 extern char * char_prev_utf8(const char * c);
285
286 extern char * strupr_utf8(char * str, size_t cbstr);
287
288 #endif
289
290 #define lengthof(a) (sizeof(a)/sizeof(a[0]))
291 #endif