⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 charcnv.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	size_t ret;	if (dest_len == (size_t)-1)		dest_len = sizeof(pstring);	if (flags & STR_TERMINATE) {		if (src_len == (size_t)-1) {			src_len = strlen(src) + 1;		} else {			size_t len = strnlen(src, src_len);			if (len < src_len)				len++;			src_len = len;		}	}	ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len, True);	if (ret == (size_t)-1) {		dest_len = 0;	}	if (dest_len)		dest[MIN(ret, dest_len-1)] = 0;	else 		dest[0] = 0;	return src_len;}size_t pull_ascii_pstring(char *dest, const void *src){	return pull_ascii(dest, src, sizeof(pstring), -1, STR_TERMINATE);}size_t pull_ascii_fstring(char *dest, const void *src){	return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE);}/* When pulling an nstring it can expand into a larger size (dos cp -> utf8). Cope with this. */size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src){	return pull_ascii(dest, src, dest_len, sizeof(nstring)-1, STR_TERMINATE);}/** * Copy a string from a char* src to a unicode destination. * * @returns the number of bytes occupied by the string in the destination. * * @param flags can have: * * <dl> * <dt>STR_TERMINATE <dd>means include the null termination. * <dt>STR_UPPER     <dd>means uppercase in the destination. * <dt>STR_NOALIGN   <dd>means don't do alignment. * </dl> * * @param dest_len is the maximum length allowed in the * destination. If dest_len is -1 then no maxiumum is used. **/size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags){	size_t len=0;	size_t src_len;	size_t ret;	/* treat a pstring as "unlimited" length */	if (dest_len == (size_t)-1)		dest_len = sizeof(pstring);	if (flags & STR_TERMINATE)		src_len = (size_t)-1;	else		src_len = strlen(src);	if (ucs2_align(base_ptr, dest, flags)) {		*(char *)dest = 0;		dest = (void *)((char *)dest + 1);		if (dest_len)			dest_len--;		len++;	}	/* ucs2 is always a multiple of 2 bytes */	dest_len &= ~1;	ret =  convert_string(CH_UNIX, CH_UCS2, src, src_len, dest, dest_len, True);	if (ret == (size_t)-1) {		return 0;	}	len += ret;	if (flags & STR_UPPER) {		smb_ucs2_t *dest_ucs2 = dest;		size_t i;		for (i = 0; i < (dest_len / 2) && dest_ucs2[i]; i++) {			smb_ucs2_t v = toupper_w(dest_ucs2[i]);			if (v != dest_ucs2[i]) {				dest_ucs2[i] = v;			}		}	}	return len;}/** * Copy a string from a unix char* src to a UCS2 destination, * allocating a buffer using talloc(). * * @param dest always set at least to NULL  * * @returns The number of bytes occupied by the string in the destination *         or -1 in case of error. **/size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src){	size_t src_len = strlen(src)+1;	*dest = NULL;	return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, (void **)dest, True);}/** * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer * * @param dest always set at least to NULL  * * @returns The number of bytes occupied by the string in the destination *         or -1 in case of error. **/size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src){	size_t src_len = strlen(src)+1;	*dest = NULL;	return convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, src_len, (void **)dest, True);}/** Copy a string from a char* src to a UTF-8 destination. Return the number of bytes occupied by the string in the destination Flags can have:  STR_TERMINATE means include the null termination  STR_UPPER     means uppercase in the destination dest_len is the maximum length allowed in the destination. If dest_len is -1 then no maxiumum is used.**/static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags){	size_t src_len = strlen(src);	pstring tmpbuf;	/* treat a pstring as "unlimited" length */	if (dest_len == (size_t)-1)		dest_len = sizeof(pstring);	if (flags & STR_UPPER) {		pstrcpy(tmpbuf, src);		strupper_m(tmpbuf);		src = tmpbuf;	}	if (flags & STR_TERMINATE)		src_len++;	return convert_string(CH_UNIX, CH_UTF8, src, src_len, dest, dest_len, True);}size_t push_utf8_fstring(void *dest, const char *src){	return push_utf8(dest, src, sizeof(fstring), STR_TERMINATE);}/** * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc * * @param dest always set at least to NULL  * * @returns The number of bytes occupied by the string in the destination **/size_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src){	size_t src_len = strlen(src)+1;	*dest = NULL;	return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void**)dest, True);}/** * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer * * @param dest always set at least to NULL  * * @returns The number of bytes occupied by the string in the destination **/size_t push_utf8_allocate(char **dest, const char *src){	size_t src_len = strlen(src)+1;	*dest = NULL;	return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, True);	}/** Copy a string from a ucs2 source to a unix char* destination. Flags can have:  STR_TERMINATE means the string in src is null terminated.  STR_NOALIGN   means don't try to align. if STR_TERMINATE is set then src_len is ignored if it is -1. src_len is the length of the source area in bytes Return the number of bytes occupied by the string in src. The resulting string in "dest" is always null terminated.**/size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags){	size_t ret;	if (dest_len == (size_t)-1)		dest_len = sizeof(pstring);	if (ucs2_align(base_ptr, src, flags)) {		src = (const void *)((const char *)src + 1);		if (src_len != (size_t)-1)			src_len--;	}	if (flags & STR_TERMINATE) {		/* src_len -1 is the default for null terminated strings. */		if (src_len != (size_t)-1) {			size_t len = strnlen_w(src, src_len/2);			if (len < src_len/2)				len++;			src_len = len*2;		}	}	/* ucs2 is always a multiple of 2 bytes */	if (src_len != (size_t)-1)		src_len &= ~1;		ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len, True);	if (ret == (size_t)-1) {		return 0;	}	if (src_len == (size_t)-1)		src_len = ret*2;			if (dest_len)		dest[MIN(ret, dest_len-1)] = 0;	else 		dest[0] = 0;	return src_len;}size_t pull_ucs2_pstring(char *dest, const void *src){	return pull_ucs2(NULL, dest, src, sizeof(pstring), -1, STR_TERMINATE);}size_t pull_ucs2_fstring(char *dest, const void *src){	return pull_ucs2(NULL, dest, src, sizeof(fstring), -1, STR_TERMINATE);}/** * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL  * * @returns The number of bytes occupied by the string in the destination **/size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src){	size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);	*dest = NULL;	return convert_string_talloc(ctx, CH_UCS2, CH_UNIX, src, src_len, (void **)dest, True);}/** * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer * * @param dest always set at least to NULL  * * @returns The number of bytes occupied by the string in the destination **/size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src){	size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);	*dest = NULL;	return convert_string_allocate(NULL, CH_UCS2, CH_UNIX, src, src_len, (void **)dest, True);}/** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL  * * @returns The number of bytes occupied by the string in the destination **/size_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src){	size_t src_len = strlen(src)+1;	*dest = NULL;	return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True);}/** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer * * @param dest always set at least to NULL  * * @returns The number of bytes occupied by the string in the destination **/size_t pull_utf8_allocate(char **dest, const char *src){	size_t src_len = strlen(src)+1;	*dest = NULL;	return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True);} /** * Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc * * @param dest always set at least to NULL  * * @returns The number of bytes occupied by the string in the destination **/size_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src){	size_t src_len = strlen(src)+1;	*dest = NULL;	return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, True);}/** Copy a string from a char* src to a unicode or ascii dos codepage destination choosing unicode or ascii based on the  flags in the SMB buffer starting at base_ptr. Return the number of bytes occupied by the string in the destination. flags can have:  STR_TERMINATE means include the null termination.  STR_UPPER     means uppercase in the destination.  STR_ASCII     use ascii even with unicode packet.  STR_NOALIGN   means don't do alignment. dest_len is the maximum length allowed in the destination. If dest_len is -1 then no maxiumum is used.**/size_t push_string_fn(const char *function, unsigned int line, const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags){#ifdef DEVELOPER	/* We really need to zero fill here, not clobber	 * region, as we want to ensure that valgrind thinks	 * all of the outgoing buffer has been written to	 * so a send() or write() won't trap an error.	 * JRA.	 */#if 0	if (dest_len != (size_t)-1)		clobber_region(function, line, dest, dest_len);#else	if (dest_len != (size_t)-1)		memset(dest, '\0', dest_len);#endif#endif	if (!(flags & STR_ASCII) && \	    ((flags & STR_UNICODE || \	      (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) {		return push_ucs2(base_ptr, dest, src, dest_len, flags);	}	return push_ascii(dest, src, dest_len, flags);}/** Copy a string from a unicode or ascii source (depending on the packet flags) to a char* destination. Flags can have:  STR_TERMINATE means the string in src is null terminated.  STR_UNICODE   means to force as unicode.  STR_ASCII     use ascii even with unicode packet.  STR_NOALIGN   means don't do alignment. if STR_TERMINATE is set then src_len is ignored is it is -1 src_len is the length of the source area in bytes. Return the number of bytes occupied by the string in src. The resulting string in "dest" is always null terminated.**/size_t pull_string_fn(const char *function, unsigned int line, const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags){#ifdef DEVELOPER	if (dest_len != (size_t)-1)		clobber_region(function, line, dest, dest_len);#endif	if (!(flags & STR_ASCII) && \	    ((flags & STR_UNICODE || \	      (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) {		return pull_ucs2(base_ptr, dest, src, dest_len, src_len, flags);	}	return pull_ascii(dest, src, dest_len, src_len, flags);}size_t align_string(const void *base_ptr, const char *p, int flags){	if (!(flags & STR_ASCII) && \	    ((flags & STR_UNICODE || \	      (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) {		return ucs2_align(base_ptr, p, flags);	}	return 0;}/**************************************************************** Calculate the size (in bytes) of the next multibyte character in our internal character set. Note that p must be pointing to a valid mb char, not within one.****************************************************************/size_t next_mb_char_size(const char *s){	size_t i;	if (!(*s & 0x80))		return 1; /* ascii. */	conv_silent = True;	for ( i = 1; i <=4; i++ ) {		smb_ucs2_t uc;		if (convert_string(CH_UNIX, CH_UCS2, s, i, &uc, 2, False) == 2) {#if 0 /* JRATEST */			DEBUG(10,("next_mb_char_size: size %u at string %s\n",				(unsigned int)i, s));#endif			conv_silent = False;			return i;		}	}	/* We're hosed - we don't know how big this is... */	DEBUG(10,("next_mb_char_size: unknown size at string %s\n", s));	conv_silent = False;	return 1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -