netatalk  4.4.0dev
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
charcnv.c File Reference

Character-set conversion routines built on our iconv. More...

#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <unistd.h>
#include <atalk/logger.h>
#include <atalk/unicode.h>
#include <atalk/util.h>
#include <atalk/compat.h>
#include <atalk/byteorder.h>

Macros

#define MAX_CHARSETS   20
#define CHECK_FLAGS(a, b)
#define hextoint(c)

Functions

static const char * charset_name (charset_t ch)
int set_charset_name (charset_t ch, const char *name)
void free_charset_names (void)
static struct charset_functionsget_charset_functions (charset_t ch)
static void lazy_initialize_conv (void)
charset_t add_charset (const char *name)
void init_iconv (void)
static size_t add_null (charset_t to, char *buf, size_t bytesleft, size_t len)
static size_t convert_string_internal (charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen)
size_t convert_string (charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen)
static size_t convert_string_allocate_internal (charset_t from, charset_t to, void const *src, size_t srclen, char **dest)
size_t convert_string_allocate (charset_t from, charset_t to, void const *src, size_t srclen, char **dest)
size_t charset_strupper (charset_t ch, const char *src, size_t srclen, char *dest, size_t destlen)
size_t charset_strlower (charset_t ch, const char *src, size_t srclen, char *dest, size_t destlen)
size_t ucs2_to_charset (charset_t ch, const ucs2_t *src, char *dest, size_t destlen)
size_t ucs2_to_charset_allocate (charset_t ch, char **dest, const ucs2_t *src)
size_t charset_precompose (charset_t ch, char *src, size_t inlen, char *dst, size_t outlen)
size_t charset_decompose (charset_t ch, char *src, size_t inlen, char *dst, size_t outlen)
static size_t pull_charset_flags (charset_t from_set, charset_t to_set, charset_t cap_set, const char *src, size_t srclen, char *dest, size_t destlen, uint16_t *flags)
static size_t push_charset_flags (charset_t to_set, charset_t cap_set, char *src, size_t srclen, char *dest, size_t destlen, uint16_t *flags)
size_t convert_charset (charset_t from_set, charset_t to_set, charset_t cap_charset, const char *src, size_t src_len, char *dest, size_t dest_len, uint16_t *flags)

Variables

static atalk_iconv_t conv_handles [MAX_CHARSETS][MAX_CHARSETS]
static char * charset_names [MAX_CHARSETS]
static struct charset_functionscharsets [MAX_CHARSETS]
static char hexdig [] = "0123456789abcdef"

Detailed Description

Character-set conversion routines built on our iconv.

Note
Samba's internal character set (at least in the 3.0 series) is always the same as the one for the Unix filesystem. It is not necessarily UTF-8 and may be different on machines that need i18n filenames to be compatible with Unix software. It does have to be a superset of ASCII. All multibyte sequences must start with a byte with the high bit set.
See also
lib/iconv.c

Macro Definition Documentation

◆ CHECK_FLAGS

#define CHECK_FLAGS ( a,
b )
Value:
(((a)!=NULL) ? (*(a) & (b)) : 0 )

◆ hextoint

#define hextoint ( c)
Value:
( isdigit( c ) ? c - '0' : c + 10 - 'a' )

◆ MAX_CHARSETS

#define MAX_CHARSETS   20

Function Documentation

◆ add_charset()

charset_t add_charset ( const char * name)

◆ add_null()

size_t add_null ( charset_t to,
char * buf,
size_t bytesleft,
size_t len )
static

◆ charset_decompose()

size_t charset_decompose ( charset_t ch,
char * src,
size_t inlen,
char * dst,
size_t outlen )

◆ charset_name()

const char * charset_name ( charset_t ch)
static

Return the name of a charset to give to iconv().

◆ charset_precompose()

size_t charset_precompose ( charset_t ch,
char * src,
size_t inlen,
char * dst,
size_t outlen )

◆ charset_strlower()

size_t charset_strlower ( charset_t ch,
const char * src,
size_t srclen,
char * dest,
size_t destlen )

◆ charset_strupper()

size_t charset_strupper ( charset_t ch,
const char * src,
size_t srclen,
char * dest,
size_t destlen )

◆ convert_charset()

size_t convert_charset ( charset_t from_set,
charset_t to_set,
charset_t cap_charset,
const char * src,
size_t src_len,
char * dest,
size_t dest_len,
uint16_t * flags )

◆ convert_string()

size_t convert_string ( charset_t from,
charset_t to,
void const * src,
size_t srclen,
void * dest,
size_t destlen )

◆ convert_string_allocate()

size_t convert_string_allocate ( charset_t from,
charset_t to,
void const * src,
size_t srclen,
char ** dest )

◆ convert_string_allocate_internal()

size_t convert_string_allocate_internal ( charset_t from,
charset_t to,
void const * src,
size_t srclen,
char ** dest )
static

Convert between character sets, allocating a new buffer for the result.

Parameters
fromsource character set
todestination character set
srcpointer to source string (multibyte or singlebyte)
srclenlength of source buffer.
destalways set at least to NULL
Note
-1 is not accepted for srclen.
Returns
Size in bytes of the converted string; or -1 in case of error.

◆ convert_string_internal()

size_t convert_string_internal ( charset_t from,
charset_t to,
void const * src,
size_t srclen,
void * dest,
size_t destlen )
static

Convert string from one encoding to another, making error checking etc

Parameters
fromsource character set
todestination character set
srcpointer to source string (multibyte or singlebyte)
srclenlength of the source string in bytes
destpointer to destination string (multibyte or singlebyte)
destlenmaximal length allowed for string
Returns
the number of bytes occupied in the destination

◆ free_charset_names()

void free_charset_names ( void )

◆ get_charset_functions()

struct charset_functions * get_charset_functions ( charset_t ch)
static

◆ init_iconv()

void init_iconv ( void )

Initialize iconv conversion descriptors.

This is called the first time it is needed, and also called again every time the configuration is reloaded, because the charset or codepage might have changed.

◆ lazy_initialize_conv()

void lazy_initialize_conv ( void )
static

◆ pull_charset_flags()

size_t pull_charset_flags ( charset_t from_set,
charset_t to_set,
charset_t cap_set,
const char * src,
size_t srclen,
char * dest,
size_t destlen,
uint16_t * flags )
static

inbuf

◆ push_charset_flags()

size_t push_charset_flags ( charset_t to_set,
charset_t cap_set,
char * src,
size_t srclen,
char * dest,
size_t destlen,
uint16_t * flags )
static

◆ set_charset_name()

int set_charset_name ( charset_t ch,
const char * name )

◆ ucs2_to_charset()

size_t ucs2_to_charset ( charset_t ch,
const ucs2_t * src,
char * dest,
size_t destlen )

Copy a string from a UCS2 src to a unix char * destination, allocating a buffer

Parameters
destalways set at least to NULL
Returns
The number of bytes occupied by the string in the destination

◆ ucs2_to_charset_allocate()

size_t ucs2_to_charset_allocate ( charset_t ch,
char ** dest,
const ucs2_t * src )

Variable Documentation

◆ charset_names

char* charset_names[MAX_CHARSETS]
static

◆ charsets

struct charset_functions* charsets[MAX_CHARSETS]
static

◆ conv_handles

atalk_iconv_t conv_handles[MAX_CHARSETS][MAX_CHARSETS]
static

◆ hexdig

char hexdig[] = "0123456789abcdef"
static