xref: /titanic_41/usr/src/uts/common/smbsrv/string.h (revision ea394cb00fd96864e34d2841b4a22357b621c78f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SMBSRV_STRING_H
27 #define	_SMBSRV_STRING_H
28 
29 #include <sys/types.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define	_smb_between(l, c, u) ((l) <= (c) && (c) <= (u))
36 
37 #define	smb_isalpha(c)	(smb_islower(c) || smb_isupper(c))
38 #define	smb_isdigit(c)	_smb_between('0', (c), '9')
39 #define	smb_isalnum(c)	(smb_isalpha(c) || smb_isdigit(c))
40 #define	smb_isxdigit(c)	(smb_isdigit(c) ||			\
41     _smb_between('a', (c), 'f') ||				\
42     _smb_between('A', (c), 'F'))
43 #define	smb_isblank(c)	((c) == ' ' || (c) == '\t')
44 #define	smb_isspace(c)  ((c) == ' ' ||		\
45 	    (c) == '\t' ||			\
46 	    (c) == '\n' ||			\
47 	    (c) == '\r' ||			\
48 	    (c) == '\f')
49 #define	smb_isascii(c)	(!((c) &~ 0x7F))
50 
51 /* These macros only apply to ASCII */
52 #define	smb_isalpha_ascii(c)	\
53 	(_smb_between('a', (c), 'z') || _smb_between('A', (c), 'Z'))
54 #define	smb_isalnum_ascii(c)	(smb_isalpha_ascii(c) || smb_isdigit(c))
55 
56 #define	smb_isprint(c)	_smb_between('!', (c), '~')
57 #define	smb_iscntrl(c)	((((c) >= 0) && ((c) <= 0x1f)) || ((c) == 0x7f))
58 #define	smb_ispunct(c)  (smb_isprint(c) && !smb_isxdigit(c) && !smb_isspace(c))
59 
60 /*
61  * These id's should correspond to oemcpg_table smb_oem.c.
62  */
63 typedef enum codepage_id {
64 	OEM_CPG_850 = 0,
65 	OEM_CPG_950,
66 	OEM_CPG_1252,
67 	OEM_CPG_949,
68 	OEM_CPG_936,
69 	OEM_CPG_932,
70 	OEM_CPG_852,
71 	OEM_CPG_1250,
72 	OEM_CPG_1253,
73 	OEM_CPG_737,
74 	OEM_CPG_1254,
75 	OEM_CPG_857,
76 	OEM_CPG_1251,
77 	OEM_CPG_866,
78 	OEM_CPG_1255,
79 	OEM_CPG_862,
80 	OEM_CPG_1256,
81 	OEM_CPG_720
82 } codepage_id_t;
83 
84 /*
85  * Maximum number of bytes per multi-byte character.
86  */
87 #define	MTS_MB_CUR_MAX		3
88 #define	MTS_MB_CHAR_MAX		MTS_MB_CUR_MAX
89 
90 typedef	uint16_t smb_wchar_t;
91 
92 /*
93  * Labels to define whether a code page table entry is an uppercase
94  * character, a lowercase character or neither. One of these values
95  * should appear in the ctype field of the code page tables.
96  */
97 #define	CODEPAGE_ISNONE		0x00
98 #define	CODEPAGE_ISUPPER	0x01
99 #define	CODEPAGE_ISLOWER	0x02
100 
101 /*
102  * The structure of a code page entry. Each code page table will
103  * consist of an array of 256 codepage entries.
104  *
105  * ctype indicates case of the value.
106  * upper indicates the uppercase equivalent value.
107  * lower indicates the lowercase equivalent value.
108  */
109 typedef struct smb_codepage {
110 	unsigned char ctype;
111 	smb_wchar_t upper;
112 	smb_wchar_t lower;
113 } smb_codepage_t;
114 
115 void smb_codepage_init(void);
116 
117 int smb_isupper(int);
118 int smb_islower(int);
119 int smb_toupper(int);
120 int smb_tolower(int);
121 char *smb_strupr(char *);
122 char *smb_strlwr(char *);
123 int smb_isstrupr(const char *);
124 int smb_isstrlwr(const char *);
125 int smb_strcasecmp(const char *, const char *, size_t);
126 
127 int smb_match(char *patn, char *str);
128 int smb_match_ci(char *patn, char *str);
129 int smb_match83(char *patn, char *str83);
130 
131 size_t smb_mbstowcs(smb_wchar_t *, const char *, size_t);
132 size_t smb_wcstombs(char *, const smb_wchar_t *, size_t);
133 int smb_mbtowc(smb_wchar_t *, const char *, size_t);
134 int smb_wctomb(char *, smb_wchar_t);
135 
136 size_t smb_wcequiv_strlen(const char *);
137 size_t smb_sbequiv_strlen(const char *);
138 
139 int smb_stombs(char *, char *, int);
140 int smb_mbstos(char *, const char *);
141 
142 size_t ucstooem(char *, const smb_wchar_t *, size_t, uint32_t);
143 size_t oemtoucs(smb_wchar_t *, const char *, size_t, uint32_t);
144 
145 char *strsubst(char *, char, char);
146 char *strsep(char **, const char *);
147 char *strcanon(char *, const char *);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif	/* _SMBSRV_STRING_H */
154