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