summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/smbsrv/string.h
blob: 21f9e98afc43682e5814963c5a71ea4c76670c89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_SMBSRV_STRING_H
#define	_SMBSRV_STRING_H

#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

#define	_smb_between(l, c, u) ((l) <= (c) && (c) <= (u))

#define	smb_isalpha(c)	(smb_islower(c) || smb_isupper(c))
#define	smb_isdigit(c)	_smb_between('0', (c), '9')
#define	smb_isalnum(c)	(smb_isalpha(c) || smb_isdigit(c))
#define	smb_isxdigit(c)	(smb_isdigit(c) ||			\
    _smb_between('a', (c), 'f') ||				\
    _smb_between('A', (c), 'F'))
#define	smb_isblank(c)	((c) == ' ' || (c) == '\t')
#define	smb_isspace(c)  ((c) == ' ' ||		\
	    (c) == '\t' ||			\
	    (c) == '\n' ||			\
	    (c) == '\r' ||			\
	    (c) == '\f')
#define	smb_isascii(c)	(!((c) &~ 0x7F))

/* These macros only apply to ASCII */
#define	smb_isalpha_ascii(c)	\
	(_smb_between('a', (c), 'z') || _smb_between('A', (c), 'Z'))
#define	smb_isalnum_ascii(c)	(smb_isalpha_ascii(c) || smb_isdigit(c))

#define	smb_isprint(c)	_smb_between('!', (c), '~')
#define	smb_iscntrl(c)	((((c) >= 0) && ((c) <= 0x1f)) || ((c) == 0x7f))
#define	smb_ispunct(c)  (smb_isprint(c) && !smb_isxdigit(c) && !smb_isspace(c))

/*
 * These id's should correspond to oemcpg_table smb_oem.c.
 */
typedef enum codepage_id {
	OEM_CPG_850 = 0,
	OEM_CPG_950,
	OEM_CPG_1252,
	OEM_CPG_949,
	OEM_CPG_936,
	OEM_CPG_932,
	OEM_CPG_852,
	OEM_CPG_1250,
	OEM_CPG_1253,
	OEM_CPG_737,
	OEM_CPG_1254,
	OEM_CPG_857,
	OEM_CPG_1251,
	OEM_CPG_866,
	OEM_CPG_1255,
	OEM_CPG_862,
	OEM_CPG_1256,
	OEM_CPG_720
} codepage_id_t;

/*
 * Maximum number of bytes per multi-byte character.
 */
#define	MTS_MB_CUR_MAX		3
#define	MTS_MB_CHAR_MAX		MTS_MB_CUR_MAX

typedef	uint16_t smb_wchar_t;

/*
 * Labels to define whether a code page table entry is an uppercase
 * character, a lowercase character or neither. One of these values
 * should appear in the ctype field of the code page tables.
 */
#define	CODEPAGE_ISNONE		0x00
#define	CODEPAGE_ISUPPER	0x01
#define	CODEPAGE_ISLOWER	0x02

/*
 * The structure of a code page entry. Each code page table will
 * consist of an array of 256 codepage entries.
 *
 * ctype indicates case of the value.
 * upper indicates the uppercase equivalent value.
 * lower indicates the lowercase equivalent value.
 */
typedef struct smb_codepage {
	unsigned char ctype;
	smb_wchar_t upper;
	smb_wchar_t lower;
} smb_codepage_t;

void smb_codepage_init(void);

int smb_isupper(int);
int smb_islower(int);
int smb_toupper(int);
int smb_tolower(int);
char *smb_strupr(char *);
char *smb_strlwr(char *);
int smb_isstrupr(const char *);
int smb_isstrlwr(const char *);
int smb_strcasecmp(const char *, const char *, size_t);

int smb_match(char *patn, char *str);
int smb_match_ci(char *patn, char *str);
int smb_match83(char *patn, char *str83);

size_t smb_mbstowcs(smb_wchar_t *, const char *, size_t);
size_t smb_wcstombs(char *, const smb_wchar_t *, size_t);
int smb_mbtowc(smb_wchar_t *, const char *, size_t);
int smb_wctomb(char *, smb_wchar_t);

size_t smb_wcequiv_strlen(const char *);
size_t smb_sbequiv_strlen(const char *);

int smb_stombs(char *, char *, int);
int smb_mbstos(char *, const char *);

size_t ucstooem(char *, const smb_wchar_t *, size_t, uint32_t);
size_t oemtoucs(smb_wchar_t *, const char *, size_t, uint32_t);

char *strsubst(char *, char, char);
char *strsep(char **, const char *);
char *strcanon(char *, const char *);

typedef struct smb_unc {
	char		 *unc_server;
	char		 *unc_share;
	char		 *unc_path;
	char		 *unc_buf;
} smb_unc_t;

int smb_unc_init(const char *, smb_unc_t *);
void smb_unc_free(smb_unc_t *);

#ifdef __cplusplus
}
#endif

#endif	/* _SMBSRV_STRING_H */