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