xref: /titanic_41/usr/src/uts/common/smbsrv/string.h (revision 6a3e8e8695d5c7d1d18c6800d676990d7f61a2a4)
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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_SMBSRV_STRING_H
26 #define	_SMBSRV_STRING_H
27 
28 #include <sys/types.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define	_smb_between(l, c, u) ((l) <= (c) && (c) <= (u))
35 
36 #define	smb_isalpha(c)	(smb_islower(c) || smb_isupper(c))
37 #define	smb_isdigit(c)	_smb_between('0', (c), '9')
38 #define	smb_isalnum(c)	(smb_isalpha(c) || smb_isdigit(c))
39 #define	smb_isxdigit(c)	(smb_isdigit(c) ||			\
40     _smb_between('a', (c), 'f') ||				\
41     _smb_between('A', (c), 'F'))
42 #define	smb_isblank(c)	((c) == ' ' || (c) == '\t')
43 #define	smb_isspace(c)  ((c) == ' ' ||		\
44 	    (c) == '\t' ||			\
45 	    (c) == '\n' ||			\
46 	    (c) == '\r' ||			\
47 	    (c) == '\f')
48 #define	smb_isascii(c)	(!((c) &~ 0x7F))
49 
50 /* These macros only apply to ASCII */
51 #define	smb_isalpha_ascii(c)	\
52 	(_smb_between('a', (c), 'z') || _smb_between('A', (c), 'Z'))
53 #define	smb_isalnum_ascii(c)	(smb_isalpha_ascii(c) || smb_isdigit(c))
54 
55 #define	smb_isprint(c)	_smb_between('!', (c), '~')
56 #define	smb_iscntrl(c)	((((c) >= 0) && ((c) <= 0x1f)) || ((c) == 0x7f))
57 #define	smb_ispunct(c)  (smb_isprint(c) && !smb_isxdigit(c) && !smb_isspace(c))
58 
59 /*
60  * These id's should correspond to oemcpg_table smb_oem.c.
61  */
62 typedef enum codepage_id {
63 	OEM_CPG_850 = 0,
64 	OEM_CPG_950,
65 	OEM_CPG_1252,
66 	OEM_CPG_949,
67 	OEM_CPG_936,
68 	OEM_CPG_932,
69 	OEM_CPG_852,
70 	OEM_CPG_1250,
71 	OEM_CPG_1253,
72 	OEM_CPG_737,
73 	OEM_CPG_1254,
74 	OEM_CPG_857,
75 	OEM_CPG_1251,
76 	OEM_CPG_866,
77 	OEM_CPG_1255,
78 	OEM_CPG_862,
79 	OEM_CPG_1256,
80 	OEM_CPG_720
81 } codepage_id_t;
82 
83 /*
84  * Maximum number of bytes per multi-byte character.
85  */
86 #define	MTS_MB_CUR_MAX		3
87 #define	MTS_MB_CHAR_MAX		MTS_MB_CUR_MAX
88 
89 typedef	uint16_t smb_wchar_t;
90 
91 /*
92  * Labels to define whether a code page table entry is an uppercase
93  * character, a lowercase character or neither. One of these values
94  * should appear in the ctype field of the code page tables.
95  */
96 #define	CODEPAGE_ISNONE		0x00
97 #define	CODEPAGE_ISUPPER	0x01
98 #define	CODEPAGE_ISLOWER	0x02
99 
100 /*
101  * The structure of a code page entry. Each code page table will
102  * consist of an array of 256 codepage entries.
103  *
104  * ctype indicates case of the value.
105  * upper indicates the uppercase equivalent value.
106  * lower indicates the lowercase equivalent value.
107  */
108 typedef struct smb_codepage {
109 	unsigned char ctype;
110 	smb_wchar_t upper;
111 	smb_wchar_t lower;
112 } smb_codepage_t;
113 
114 void smb_codepage_init(void);
115 
116 int smb_isupper(int);
117 int smb_islower(int);
118 int smb_toupper(int);
119 int smb_tolower(int);
120 char *smb_strupr(char *);
121 char *smb_strlwr(char *);
122 int smb_isstrupr(const char *);
123 int smb_isstrlwr(const char *);
124 int smb_strcasecmp(const char *, const char *, size_t);
125 
126 boolean_t smb_match(char *, char *);
127 boolean_t smb_match_ci(char *, char *);
128 
129 size_t smb_mbstowcs(smb_wchar_t *, const char *, size_t);
130 size_t smb_wcstombs(char *, const smb_wchar_t *, size_t);
131 int smb_mbtowc(smb_wchar_t *, const char *, size_t);
132 int smb_wctomb(char *, smb_wchar_t);
133 
134 size_t smb_wcequiv_strlen(const char *);
135 size_t smb_sbequiv_strlen(const char *);
136 
137 int smb_stombs(char *, char *, int);
138 int smb_mbstos(char *, const char *);
139 
140 size_t ucstooem(char *, const smb_wchar_t *, size_t, uint32_t);
141 size_t oemtoucs(smb_wchar_t *, const char *, size_t, uint32_t);
142 
143 char *strsubst(char *, char, char);
144 char *strsep(char **, const char *);
145 char *strcanon(char *, const char *);
146 
147 typedef struct smb_unc {
148 	char		 *unc_server;
149 	char		 *unc_share;
150 	char		 *unc_path;
151 	char		 *unc_buf;
152 } smb_unc_t;
153 
154 int smb_unc_init(const char *, smb_unc_t *);
155 void smb_unc_free(smb_unc_t *);
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif	/* _SMBSRV_STRING_H */
162