netatalk: unicode.h Source File

netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
unicode.h
Go to the documentation of this file.
1#ifndef _ATALK_UNICODE_H
2#define _ATALK_UNICODE_H 1
3
4#include <errno.h>
5#include <stdint.h>
6#include <sys/param.h>
7
8#define ucs2_t uint16_t
9
10#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
11
12#ifndef EILSEQ
13#define EILSEQ 84
14#endif
15
17 typedef struct {
18 size_t (*direct)(void *cd, char **inbuf, size_t *inbytesleft,
19 char **outbuf, size_t *outbytesleft);
20 size_t (*pull)(void *cd, char **inbuf, size_t *inbytesleft,
21 char **outbuf, size_t *outbytesleft);
22 size_t (*push)(void *cd, char **inbuf, size_t *inbytesleft,
23 char **outbuf, size_t *outbytesleft);
24 void *cd_direct, *cd_pull, *cd_push;
25 char *from_name, *to_name;
26} *atalk_iconv_t;
27
28#define CHARSET_CLIENT 1
29#define CHARSET_VOLUME 2
30#define CHARSET_PRECOMPOSED 4
31#define CHARSET_DECOMPOSED 8
32#define CHARSET_MULTIBYTE 16
33#define CHARSET_WIDECHAR 32
34#define CHARSET_ICONV 64
35
36#define IGNORE_CHAR '_'
37
38/* conversion flags */
39#define CONV_IGNORE (1<<0)
40#define CONV_ESCAPEHEX (1<<1)
43#define CONV_ESCAPEDOTS (1<<2)
44#define CONV_UNESCAPEHEX (1<<3)
45#define CONV_TOUPPER (1<<4)
46#define CONV_TOLOWER (1<<5)
47#define CONV_PRECOMPOSE (1<<6)
48#define CONV_DECOMPOSE (1<<7)
49#define CONV_FORCE (1<<8)
50#define CONV__EILSEQ (1<<9)
51
52/* conversion return flags */
53#define CONV_REQMANGLE (1<<14)
54#define CONV_REQESCAPE (1<<15)
55
57 typedef enum {CH_UCS2 = 0, CH_UTF8 = 1, CH_MAC = 2, CH_UNIX = 3, CH_UTF8_MAC = 4} charset_t;
58
59#define NUM_CHARSETS 5
60
61/*
62 * for each charset we have a function that pulls from that charset to
63 * a ucs2 buffer, and a function that pushes to a ucs2 buffer
64 */
65
66 struct charset_functions {
67 const char *name;
68 const long kTextEncoding;
69 size_t (*pull)(void *, char **inbuf, size_t *inbytesleft,
70 char **outbuf, size_t *outbytesleft);
71 size_t (*push)(void *, char **inbuf, size_t *inbytesleft,
72 char **outbuf, size_t *outbytesleft);
73 uint32_t flags;
74 const char *iname;
75 struct charset_functions *prev, *next;
76};
77
78/* from iconv.c */
79extern atalk_iconv_t atalk_iconv_open(const char *, const char *);
80extern size_t atalk_iconv(atalk_iconv_t, const char **, size_t *, char **,
81 size_t *);
82extern int atalk_iconv_close(atalk_iconv_t);
83extern struct charset_functions *find_charset_functions(const char *);
84extern int atalk_register_charset(struct charset_functions *);
85
86/* from utf16_case.c */
87extern ucs2_t toupper_w(ucs2_t);
88extern uint32_t toupper_sp(uint32_t);
89extern ucs2_t tolower_w(ucs2_t);
90extern uint32_t tolower_sp(uint32_t);
91
92/* from util_unistr.c */
93extern int strupper_w(ucs2_t *);
94extern int strlower_w(ucs2_t *);
95extern size_t strlen_w(const ucs2_t *);
96extern size_t strnlen_w(const ucs2_t *, size_t);
97extern ucs2_t *strchr_w(const ucs2_t *, ucs2_t);
98extern ucs2_t *strcasechr_w(const ucs2_t *s, ucs2_t c);
99extern int strcmp_w(const ucs2_t *, const ucs2_t *);
100extern int strncmp_w(const ucs2_t *, const ucs2_t *, size_t);
101extern int strcasecmp_w(const ucs2_t *, const ucs2_t *);
102extern int strncasecmp_w(const ucs2_t *, const ucs2_t *, size_t);
103extern ucs2_t *strstr_w(const ucs2_t *s, const ucs2_t *ins);
104extern ucs2_t *strcasestr_w(const ucs2_t *, const ucs2_t *);
105extern ucs2_t *strndup_w(const ucs2_t *, size_t);
106extern ucs2_t *strdup_w(const ucs2_t *);
107extern size_t precompose_w(ucs2_t *, size_t, ucs2_t *, size_t *);
108extern size_t decompose_w(ucs2_t *, size_t, ucs2_t *, size_t *);
109
110/* from charcnv.c */
111extern int set_charset_name(charset_t, const char *);
112extern void free_charset_names(void);
113extern void init_iconv(void);
114extern size_t convert_string(charset_t, charset_t, void const *, size_t,
115 void *, size_t);
116extern size_t convert_string_allocate(charset_t, charset_t, void const *,
117 size_t, char **);
118extern size_t charset_strupper(charset_t, const char *, size_t, char *,
119 size_t);
120extern size_t charset_strlower(charset_t, const char *, size_t, char *,
121 size_t);
122extern size_t ucs2_to_charset_allocate(charset_t, char **dest,
123 const ucs2_t *src);
124extern size_t ucs2_to_charset(charset_t, const ucs2_t *src, char *dest,
125 size_t);
126
127extern size_t convert_charset(charset_t, charset_t, charset_t, const char *,
128 size_t, char *, size_t, uint16_t *);
129extern size_t charset_precompose(charset_t, char *, size_t, char *, size_t);
130extern size_t charset_decompose(charset_t, char *, size_t, char *, size_t);
131
132extern charset_t add_charset(const char *name);
133
134#endif /* _ATALK_UNICODE_H */
c
size_t c
Definition dircache.c:257
atalk_iconv_t
Definition unicode.h:17
atalk_iconv_t::direct
size_t(* direct)(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Definition unicode.h:18
atalk_iconv_t::from_name
char * from_name
Definition unicode.h:25
atalk_iconv_t::cd_pull
void * cd_pull
Definition unicode.h:24
atalk_iconv_t::pull
size_t(* pull)(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Definition unicode.h:20
atalk_iconv_t::push
size_t(* push)(void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Definition unicode.h:22
atalk_iconv_t::to_name
char * to_name
Definition unicode.h:25
atalk_iconv_t::cd_direct
void * cd_direct
Definition unicode.h:24
atalk_iconv_t::cd_push
void * cd_push
Definition unicode.h:24
charset_functions
Definition unicode.h:66
charset_functions::name
const char * name
Definition unicode.h:67
charset_functions::push
size_t(* push)(void *, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Definition unicode.h:71
charset_functions::prev
struct charset_functions * prev
Definition unicode.h:75
charset_functions::kTextEncoding
const long kTextEncoding
Definition unicode.h:68
charset_functions::pull
size_t(* pull)(void *, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Definition unicode.h:69
charset_functions::flags
uint32_t flags
Definition unicode.h:73
charset_functions::next
struct charset_functions * next
Definition unicode.h:75
charset_functions::iname
const char * iname
Definition unicode.h:74
set_charset_name
int set_charset_name(charset_t, const char *)
Definition charcnv.c:86
ucs2_to_charset
size_t ucs2_to_charset(charset_t, const ucs2_t *src, char *dest, size_t)
Copy a string from a UCS2 src to a unix char * destination, allocating a buffer.
Definition charcnv.c:560
precompose_w
size_t precompose_w(ucs2_t *, size_t, ucs2_t *, size_t *)
pre|decomposition
Definition util_unistr.c:541
ucs2_t
#define ucs2_t
Definition unicode.h:8
atalk_iconv
size_t atalk_iconv(atalk_iconv_t, const char **, size_t *, char **, size_t *)
This is a simple portable iconv() implementaion.
Definition iconv.c:215
free_charset_names
void free_charset_names(void)
Definition charcnv.c:96
toupper_sp
uint32_t toupper_sp(uint32_t)
Definition utf16_case.c:82
strndup_w
ucs2_t * strndup_w(const ucs2_t *, size_t)
wide strndup()
Definition util_unistr.c:383
strupper_w
int strupper_w(ucs2_t *)
Convert a string to upper case.
Definition util_unistr.c:71
strdup_w
ucs2_t * strdup_w(const ucs2_t *)
wide strdup()
Definition util_unistr.c:409
strcmp_w
int strcmp_w(const ucs2_t *, const ucs2_t *)
wide strcmp()
Definition util_unistr.c:201
find_charset_functions
struct charset_functions * find_charset_functions(const char *)
Definition iconv.c:123
toupper_w
ucs2_t toupper_w(ucs2_t)
Definition utf16_case.c:18
init_iconv
void init_iconv(void)
Initialize iconv conversion descriptors.
Definition charcnv.c:186
charset_decompose
size_t charset_decompose(charset_t, char *, size_t, char *, size_t)
Definition charcnv.c:605
strnlen_w
size_t strnlen_w(const ucs2_t *, size_t)
wide strnlen()
Definition util_unistr.c:125
atalk_iconv_open
atalk_iconv_t atalk_iconv_open(const char *, const char *)
Definition iconv.c:256
strcasechr_w
ucs2_t * strcasechr_w(const ucs2_t *s, ucs2_t c)
wide strcasechr()
Definition util_unistr.c:159
charset_precompose
size_t charset_precompose(charset_t, char *, size_t, char *, size_t)
Definition charcnv.c:575
strcasestr_w
ucs2_t * strcasestr_w(const ucs2_t *, const ucs2_t *)
wide strcasestr()
Definition util_unistr.c:262
charset_strlower
size_t charset_strlower(charset_t, const char *, size_t, char *, size_t)
Definition charcnv.c:526
decompose_w
size_t decompose_w(ucs2_t *, size_t, ucs2_t *, size_t *)
Definition util_unistr.c:654
strcasecmp_w
int strcasecmp_w(const ucs2_t *, const ucs2_t *)
wide strcasecmp()
Definition util_unistr.c:307
atalk_iconv_close
int atalk_iconv_close(atalk_iconv_t)
Definition iconv.c:356
charset_strupper
size_t charset_strupper(charset_t, const char *, size_t, char *, size_t)
Definition charcnv.c:503
tolower_sp
uint32_t tolower_sp(uint32_t)
Definition utf16_case.c:190
strlower_w
int strlower_w(ucs2_t *)
Convert a string to lower case.
Definition util_unistr.c:34
strncmp_w
int strncmp_w(const ucs2_t *, const ucs2_t *, size_t)
wide strncmp()
Definition util_unistr.c:218
convert_charset
size_t convert_charset(charset_t, charset_t, charset_t, const char *, size_t, char *, size_t, uint16_t *)
Definition charcnv.c:988
strncasecmp_w
int strncasecmp_w(const ucs2_t *, const ucs2_t *, size_t)
wide strncasecmp()
Definition util_unistr.c:343
strlen_w
size_t strlen_w(const ucs2_t *)
wide strlen()
Definition util_unistr.c:109
add_charset
charset_t add_charset(const char *name)
Definition charcnv.c:127
tolower_w
ucs2_t tolower_w(ucs2_t)
Definition utf16_case.c:130
strchr_w
ucs2_t * strchr_w(const ucs2_t *, ucs2_t)
wide strchr()
Definition util_unistr.c:138
strstr_w
ucs2_t * strstr_w(const ucs2_t *s, const ucs2_t *ins)
wide strstr()
Definition util_unistr.c:235
atalk_register_charset
int atalk_register_charset(struct charset_functions *)
Definition iconv.c:138
ucs2_to_charset_allocate
size_t ucs2_to_charset_allocate(charset_t, char **dest, const ucs2_t *src)
Definition charcnv.c:568
charset_t
charset_t
Definition unicode.h:57
CH_MAC
@ CH_MAC
Definition unicode.h:57
CH_UNIX
@ CH_UNIX
Definition unicode.h:57
CH_UCS2
@ CH_UCS2
Definition unicode.h:57
CH_UTF8
@ CH_UTF8
Definition unicode.h:57
CH_UTF8_MAC
@ CH_UTF8_MAC
Definition unicode.h:57
convert_string_allocate
size_t convert_string_allocate(charset_t, charset_t, void const *, size_t, char **)
Definition charcnv.c:458
convert_string
size_t convert_string(charset_t, charset_t, void const *, size_t, void *, size_t)
Definition charcnv.c:302