関数 | |
static void * | resize_buffer (void *buffer, size_t *size, size_t newsize) |
static void | swap_bytes (char *dst, const char *src, size_t len) |
static void | swap_bytes_inplace (char *cp, size_t len) |
static UniChar * | set_ucbuffer_with_le_copy (UniChar *buffer, size_t *bufsize, const void *data, size_t size, size_t reserve) |
static void | hexdump (const char *label, const char *s, size_t len) |
static size_t | macosxfs_encoding_pull (void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) |
static size_t | macosxfs_encoding_push (void *cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) |
NTSTATUS | charset_macosxfs_init (void) |
変数 | |
static struct charset_functions | macosxfs_encoding_functions |
static void* resize_buffer | ( | void * | buffer, | |
size_t * | size, | |||
size_t | newsize | |||
) | [inline, static] |
charset_macosxfs.c の 61 行で定義されています。
参照元 macosxfs_encoding_pull()・set_ucbuffer_with_le_copy().
00062 { 00063 if (newsize > *size) { 00064 *size = newsize + 128; 00065 buffer = SMB_REALLOC(buffer, *size); 00066 } 00067 return buffer; 00068 }
static void swap_bytes | ( | char * | dst, | |
const char * | src, | |||
size_t | len | |||
) | [inline, static] |
charset_macosxfs.c の 87 行で定義されています。
00088 { 00089 const char *srcend = src + len; 00090 while (src < srcend) { 00091 dst[0] = src[1]; 00092 dst[1] = src[0]; 00093 dst += 2; 00094 src += 2; 00095 } 00096 }
static void swap_bytes_inplace | ( | char * | cp, | |
size_t | len | |||
) | [inline, static] |
charset_macosxfs.c の 97 行で定義されています。
00098 { 00099 char temp; 00100 char *end = cp + len; 00101 while (cp < end) { 00102 temp = cp[1]; 00103 cp[1] = cp[0]; 00104 cp[0] = temp; 00105 cp += 2; 00106 } 00107 }
static UniChar* set_ucbuffer_with_le_copy | ( | UniChar * | buffer, | |
size_t * | bufsize, | |||
const void * | data, | |||
size_t | size, | |||
size_t | reserve | |||
) | [inline, static] |
charset_macosxfs.c の 123 行で定義されています。
参照先 resize_buffer().
00126 { 00127 buffer = resize_buffer(buffer, bufsize, size+reserve); 00128 le_to_native((char*)buffer,data,size); 00129 return buffer; 00130 }
static void hexdump | ( | const char * | label, | |
const char * | s, | |||
size_t | len | |||
) | [static] |
charset_macosxfs.c の 140 行で定義されています。
参照元 macosxfs_encoding_pull()・macosxfs_encoding_push().
00141 { 00142 size_t restlen = len; 00143 debug_out("<<<<<<<\n"); 00144 debug_out(label); 00145 debug_out("\n"); 00146 while (restlen > 0) { 00147 char line[100]; 00148 size_t i, j; 00149 char * d = line; 00150 #undef sprintf 00151 d += sprintf(d, "%04X ", (unsigned)(len-restlen)); 00152 *d++ = ' '; 00153 for( i = 0; i<restlen && i<8; ++i ) { 00154 d += sprintf(d, "%02X ", ((unsigned)s[i]) & 0xFF); 00155 } 00156 for( j = i; j<8; ++j ) { 00157 d += sprintf(d, " "); 00158 } 00159 *d++ = ' '; 00160 for( i = 8; i<restlen && i<16; ++i ) { 00161 d += sprintf(d, "%02X ", ((unsigned)s[i]) & 0xFF); 00162 } 00163 for( j = i; j<16; ++j ) { 00164 d += sprintf(d, " "); 00165 } 00166 *d++ = ' '; 00167 for( i = 0; i<restlen && i<16; ++i ) { 00168 if(s[i] < ' ' || s[i] >= 0x7F || !isprint(s[i])) 00169 *d++ = '.'; 00170 else 00171 *d++ = s[i]; 00172 } 00173 *d++ = '\n'; 00174 *d = 0; 00175 restlen -= i; 00176 s += i; 00177 debug_out(line); 00178 } 00179 debug_out(">>>>>>>\n"); 00180 }
static size_t macosxfs_encoding_pull | ( | void * | cd, | |
char ** | inbuf, | |||
size_t * | inbytesleft, | |||
char ** | outbuf, | |||
size_t * | outbytesleft | |||
) | [static] |
charset_macosxfs.c の 204 行で定義されています。
参照先 errno・hexdump()・resize_buffer().
00208 { 00209 static const int script_code = kCFStringEncodingUTF8; 00210 static CFMutableStringRef cfstring = NULL; 00211 size_t outsize; 00212 CFRange range; 00213 00214 (void) cd; /* UNUSED */ 00215 00216 if (0 == *inbytesleft) { 00217 return 0; 00218 } 00219 00220 if (NULL == cfstring) { 00221 /* 00222 * A version with an external backing store as in the 00223 * push function should have been more efficient, but 00224 * testing shows, that it is actually slower (!). 00225 * Maybe kCFAllocatorDefault gets shortcut evaluation 00226 * internally, while kCFAllocatorNull doesn't. 00227 */ 00228 cfstring = CFStringCreateMutable(kCFAllocatorDefault,0); 00229 } 00230 00231 /* 00232 * Three methods of appending to a CFString, choose the most 00233 * efficient. 00234 */ 00235 if (0 == (*inbuf)[*inbytesleft-1]) { 00236 CFStringAppendCString(cfstring, *inbuf, script_code); 00237 } else if (*inbytesleft <= 255) { 00238 Str255 buffer; 00239 buffer[0] = *inbytesleft; 00240 memcpy(buffer+1, *inbuf, buffer[0]); 00241 CFStringAppendPascalString(cfstring, buffer, script_code); 00242 } else { 00243 /* 00244 * We would like to use a fixed buffer and a loop 00245 * here, but than we can't garantee that the input is 00246 * well-formed UTF-8, as we are supposed to do. 00247 */ 00248 static char *buffer = NULL; 00249 static size_t buflen = 0; 00250 buffer = resize_buffer(buffer, &buflen, *inbytesleft+1); 00251 memcpy(buffer, *inbuf, *inbytesleft); 00252 buffer[*inbytesleft] = 0; 00253 CFStringAppendCString(cfstring, *inbuf, script_code); 00254 } 00255 00256 /* 00257 * Compose characters, using the non-canonical composition 00258 * form. 00259 */ 00260 CFStringNormalize(cfstring, kCFStringNormalizationFormC); 00261 00262 outsize = CFStringGetLength(cfstring); 00263 range = CFRangeMake(0,outsize); 00264 00265 if (outsize == 0) { 00266 /* 00267 * HACK: smbd/mangle_hash2.c:is_legal_name() expects 00268 * errors here. That function will always pass 2 00269 * characters. smbd/open.c:check_for_pipe() cuts a 00270 * patchname to 10 characters blindly. Suppress the 00271 * debug output in those cases. 00272 */ 00273 if(2 != *inbytesleft && 10 != *inbytesleft) { 00274 debug_out("String conversion: " 00275 "An unknown error occurred\n"); 00276 hexdump("UTF8->UTF16LE (old) input", 00277 *inbuf, *inbytesleft); 00278 } 00279 errno = EILSEQ; /* Not sure, but this is what we have 00280 * actually seen. */ 00281 return -1; 00282 } 00283 if (outsize*2 > *outbytesleft) { 00284 CFStringDelete(cfstring, range); 00285 debug_out("String conversion: " 00286 "Output buffer too small\n"); 00287 hexdump("UTF8->UTF16LE (old) input", 00288 *inbuf, *inbytesleft); 00289 errno = E2BIG; 00290 return -1; 00291 } 00292 00293 CFStringGetCharacters(cfstring, range, (UniChar*)*outbuf); 00294 CFStringDelete(cfstring, range); 00295 00296 native_to_le(*outbuf, outsize*2); 00297 00298 /* 00299 * Add a converted null byte, if the CFString conversions 00300 * prevented that until now. 00301 */ 00302 if (0 == (*inbuf)[*inbytesleft-1] && 00303 (0 != (*outbuf)[outsize*2-1] || 0 != (*outbuf)[outsize*2-2])) { 00304 00305 if ((outsize*2+2) > *outbytesleft) { 00306 debug_out("String conversion: " 00307 "Output buffer too small\n"); 00308 hexdump("UTF8->UTF16LE (old) input", 00309 *inbuf, *inbytesleft); 00310 errno = E2BIG; 00311 return -1; 00312 } 00313 00314 (*outbuf)[outsize*2] = (*outbuf)[outsize*2+1] = 0; 00315 outsize += 2; 00316 } 00317 00318 *inbuf += *inbytesleft; 00319 *inbytesleft = 0; 00320 *outbuf += outsize*2; 00321 *outbytesleft -= outsize*2; 00322 00323 return 0; 00324 }
static size_t macosxfs_encoding_push | ( | void * | cd, | |
char ** | inbuf, | |||
size_t * | inbytesleft, | |||
char ** | outbuf, | |||
size_t * | outbytesleft | |||
) | [static] |
charset_macosxfs.c の 326 行で定義されています。
参照先 errno・hexdump()・set_ucbuffer_with_le_copy().
00330 { 00331 static const int script_code = kCFStringEncodingUTF8; 00332 static CFMutableStringRef cfstring = NULL; 00333 static UniChar *buffer = NULL; 00334 static size_t buflen = 0; 00335 CFIndex outsize, cfsize, charsconverted; 00336 00337 (void) cd; /* UNUSED */ 00338 00339 if (0 == *inbytesleft) { 00340 return 0; 00341 } 00342 00343 /* 00344 * We need a buffer that can hold 4 times the original data, 00345 * because that is the theoretical maximum that decomposition 00346 * can create currently (in Unicode 4.0). 00347 */ 00348 buffer = set_ucbuffer_with_le_copy( 00349 buffer, &buflen, *inbuf, *inbytesleft, 3 * *inbytesleft); 00350 00351 if (NULL == cfstring) { 00352 cfstring = CFStringCreateMutableWithExternalCharactersNoCopy( 00353 kCFAllocatorDefault, 00354 buffer, *inbytesleft/2, buflen/2, 00355 kCFAllocatorNull); 00356 } else { 00357 CFStringSetExternalCharactersNoCopy( 00358 cfstring, 00359 buffer, *inbytesleft/2, buflen/2); 00360 } 00361 00362 /* 00363 * Decompose characters, using the non-canonical decomposition 00364 * form. 00365 * 00366 * NB: This isn't exactly what HFS+ wants (see note on 00367 * kCFStringEncodingUseHFSPlusCanonical in 00368 * CFStringEncodingConverter.h), but AFAIK it's the best that 00369 * the official API can do. 00370 */ 00371 CFStringNormalize(cfstring, kCFStringNormalizationFormD); 00372 00373 cfsize = CFStringGetLength(cfstring); 00374 charsconverted = CFStringGetBytes( 00375 cfstring, CFRangeMake(0,cfsize), 00376 script_code, 0, False, 00377 *outbuf, *outbytesleft, &outsize); 00378 00379 if (0 == charsconverted) { 00380 debug_out("String conversion: " 00381 "Buffer too small or not convertable\n"); 00382 hexdump("UTF16LE->UTF8 (old) input", 00383 *inbuf, *inbytesleft); 00384 errno = EILSEQ; /* Probably more likely. */ 00385 return -1; 00386 } 00387 00388 /* 00389 * Add a converted null byte, if the CFString conversions 00390 * prevented that until now. 00391 */ 00392 if (0 == (*inbuf)[*inbytesleft-1] && 0 == (*inbuf)[*inbytesleft-2] && 00393 (0 != (*outbuf)[outsize-1])) { 00394 00395 if (((size_t)outsize+1) > *outbytesleft) { 00396 debug_out("String conversion: " 00397 "Output buffer too small\n"); 00398 hexdump("UTF16LE->UTF8 (old) input", 00399 *inbuf, *inbytesleft); 00400 errno = E2BIG; 00401 return -1; 00402 } 00403 00404 (*outbuf)[outsize] = 0; 00405 ++outsize; 00406 } 00407 00408 *inbuf += *inbytesleft; 00409 *inbytesleft = 0; 00410 *outbuf += outsize; 00411 *outbytesleft -= outsize; 00412 00413 return 0; 00414 }
NTSTATUS charset_macosxfs_init | ( | void | ) |
charset_macosxfs.c の 597 行で定義されています。
参照先 macosxfs_encoding_functions・smb_register_charset().
00598 { 00599 return smb_register_charset(&macosxfs_encoding_functions); 00600 }
struct charset_functions macosxfs_encoding_functions [static] |
初期値:
{ "MACOSXFS", macosxfs_encoding_pull, macosxfs_encoding_push }
charset_macosxfs.c の 593 行で定義されています。