1#ifndef _ATALK_UNICODE_H 2#define _ATALK_UNICODE_H 1 3 4#include <sys/cdefs.h> 5#include <netatalk/endian.h> 6#include <errno.h> 7#include <sys/param.h> 8 9#define ucs2_t u_int16_t 10 11#ifndef MIN 12#define MIN(a,b) ((a)<(b)?(a):(b)) 13#endif /* ! MIN */ 14 15#ifndef MAX 16#define MAX(a,b) ((a)>(b)?(a):(b)) 17#endif /* ! MIN */ 18 19#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) 20 21#ifndef EILSEQ 22#define EILSEQ 84 /* Illegal byte sequence. */ 23#endif 24 25/* generic iconv conversion structure */ 26typedef struct { 27 size_t (*direct)(void *cd, char **inbuf, size_t *inbytesleft, 28 char **outbuf, size_t *outbytesleft); 29 size_t (*pull)(void *cd, char **inbuf, size_t *inbytesleft, 30 char **outbuf, size_t *outbytesleft); 31 size_t (*push)(void *cd, char **inbuf, size_t *inbytesleft, 32 char **outbuf, size_t *outbytesleft); 33 void *cd_direct, *cd_pull, *cd_push; 34 char *from_name, *to_name; 35} *atalk_iconv_t; 36 37#define CHARSET_CLIENT 1 38#define CHARSET_VOLUME 2 39#define CHARSET_PRECOMPOSED 4 40#define CHARSET_DECOMPOSED 8 41#define CHARSET_MULTIBYTE 16 42#define CHARSET_WIDECHAR 32 43#define CHARSET_ICONV 64 44 45#define IGNORE_CHAR '_' 46 47/* conversion flags */ 48#define CONV_IGNORE (1<<0) /* return the first convertable characters. */ 49#define CONV_ESCAPEHEX (1<<1) /* escape unconvertable chars with :[UCS2HEX], */ 50 /* also escape '/'. Escape ':' if also CONV_ALLOW_COLON, */ 51 /* else ':' raises EILSEQ */ 52#define CONV_ESCAPEDOTS (1<<2) /* escape leading dots with :2600 */ 53#define CONV_UNESCAPEHEX (1<<3) 54#define CONV_TOUPPER (1<<4) /* convert to UPPERcase */ 55#define CONV_TOLOWER (1<<5) /* convert to lowercase */ 56#define CONV_PRECOMPOSE (1<<6) /* precompose */ 57#define CONV_DECOMPOSE (1<<7) /* precompose */ 58#define CONV_FORCE (1<<8) /* force convertion */ 59#define CONV__EILSEQ (1<<9) /* ignore EILSEQ, replace with IGNORE_CHAR (try USC2) */ 60#define CONV_ALLOW_COLON (1<<10) /* Allow ':' in name. Needed for Extended Attributes */ 61 62/* conversion return flags */ 63#define CONV_REQMANGLE (1<<14) /* mangling of returned name is required */ 64#define CONV_REQESCAPE (1<<15) /* espace unconvertable chars with :[UCS2HEX] */ 65 66/* this defines the charset types used in samba */ 67typedef enum {CH_UCS2=0, CH_UTF8=1, CH_MAC=2, CH_UNIX=3, CH_UTF8_MAC=4} charset_t; 68 69#define NUM_CHARSETS 5 70 71/* 72 * for each charset we have a function that pulls from that charset to 73 * a ucs2 buffer, and a function that pushes to a ucs2 buffer 74 */ 75 76struct charset_functions { 77 const char *name; 78 const long kTextEncoding; 79 size_t (*pull)(void *, char **inbuf, size_t *inbytesleft, 80 char **outbuf, size_t *outbytesleft); 81 size_t (*push)(void *, char **inbuf, size_t *inbytesleft, 82 char **outbuf, size_t *outbytesleft); 83 u_int32_t flags; 84 const char *iname; 85 struct charset_functions *prev, *next; 86}; 87 88/* from iconv.c */ 89extern atalk_iconv_t atalk_iconv_open (const char *, const char *); 90extern size_t atalk_iconv (atalk_iconv_t, const char **, size_t *, char **, size_t *); 91extern int atalk_iconv_close (atalk_iconv_t); 92extern struct charset_functions *find_charset_functions (const char *); 93extern int atalk_register_charset (struct charset_functions *); 94 95/* from utf16_case.c */ 96extern ucs2_t toupper_w (ucs2_t); 97extern u_int32_t toupper_sp (u_int32_t); 98extern ucs2_t tolower_w (ucs2_t); 99extern u_int32_t tolower_sp (u_int32_t); 100 101/* from util_unistr.c */ 102extern int strupper_w (ucs2_t *); 103extern int strlower_w (ucs2_t *); 104extern int islower_w (ucs2_t); 105extern int isupper_w (ucs2_t); 106extern size_t strlen_w (const ucs2_t *); 107extern size_t strnlen_w (const ucs2_t *, size_t); 108extern ucs2_t* strchr_w (const ucs2_t *, ucs2_t); 109extern ucs2_t *strcasechr_w (const ucs2_t *s, ucs2_t c); 110extern int strcmp_w (const ucs2_t *, const ucs2_t *); 111extern int strncmp_w (const ucs2_t *, const ucs2_t *, size_t); 112extern int strcasecmp_w (const ucs2_t *, const ucs2_t *); 113extern int strncasecmp_w (const ucs2_t *, const ucs2_t *, size_t); 114extern ucs2_t *strstr_w (const ucs2_t *s, const ucs2_t *ins); 115extern ucs2_t *strcasestr_w (const ucs2_t *, const ucs2_t *); 116extern ucs2_t *strndup_w (const ucs2_t *, size_t); 117extern ucs2_t *strdup_w (const ucs2_t *); 118extern ucs2_t *strncpy_w (ucs2_t *, const ucs2_t *, const size_t); 119extern ucs2_t *strncat_w (ucs2_t *, const ucs2_t *, const size_t); 120extern ucs2_t *strcat_w (ucs2_t *, const ucs2_t *); 121extern size_t precompose_w (ucs2_t *, size_t, ucs2_t *,size_t *); 122extern size_t decompose_w (ucs2_t *, size_t, ucs2_t *,size_t *); 123extern size_t utf8_charlen ( char* ); 124extern size_t utf8_strlen_validate ( char *); 125 126/* from charcnv.c */ 127extern void init_iconv (void); 128extern size_t convert_string (charset_t, charset_t, void const *, size_t, void *, size_t); 129extern size_t convert_string_allocate (charset_t, charset_t, void const *, size_t, char **); 130extern size_t utf8_strupper (const char *, size_t, char *, size_t); 131extern size_t utf8_strlower (const char *, size_t, char *, size_t); 132extern size_t unix_strupper (const char *, size_t, char *, size_t); 133extern size_t unix_strlower (const char *, size_t, char *, size_t); 134extern size_t charset_strupper (charset_t, const char *, size_t, char *, size_t); 135extern size_t charset_strlower (charset_t, const char *, size_t, char *, size_t); 136 137extern size_t charset_to_ucs2_allocate (charset_t, ucs2_t **dest, const char *src); 138extern size_t charset_to_utf8_allocate (charset_t, char **dest, const char *src); 139extern size_t ucs2_to_charset_allocate (charset_t, char **dest, const ucs2_t *src); 140extern size_t utf8_to_charset_allocate (charset_t, char **dest, const char *src); 141extern size_t ucs2_to_charset (charset_t, const ucs2_t *src, char *dest, size_t); 142 143extern size_t convert_charset (charset_t, charset_t, charset_t, const char *, size_t, char *, size_t, u_int16_t *); 144 145extern size_t charset_precompose ( charset_t, char *, size_t, char *, size_t); 146extern size_t charset_decompose ( charset_t, char *, size_t, char *, size_t); 147extern size_t utf8_precompose ( char *, size_t, char *, size_t); 148extern size_t utf8_decompose ( char *, size_t, char *, size_t); 149 150extern charset_t add_charset (const char* name); 151 152#endif /* _ATALK_UNICODE_H */ 153