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