Commit 978e4176 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Make some additional UTF8 public

Remove lint
parent da2f6f68
......@@ -44,8 +44,8 @@
#endif
/* use ldap_pvt_strtok instead of strtok or strtok_r! */
LDAP_F(char *) ldap_pvt_strtok LDAP_P(( char *str, const char *delim,
char **pos ));
LDAP_F(char *) ldap_pvt_strtok LDAP_P(( char *str,
const char *delim, char **pos ));
#ifndef HAVE_STRDUP
/* strdup() is missing, declare our own version */
......
......@@ -24,6 +24,8 @@
#undef LDAP_VENDOR_VERSION_PATCH
/*
** WORK IN PROGRESS!
**
** OpenLDAP reentrancy/thread-safeness should be dynamically
** checked using ldap_get_option().
**
......
......@@ -21,6 +21,8 @@
#define LDAP_VENDOR_VERSION_PATCH X
/*
** WORK IN PROGRESS!
**
** OpenLDAP reentrancy/thread-safeness should be dynamically
** checked using ldap_get_option().
**
......
......@@ -12,6 +12,7 @@
/*
* ldap_pvt_uc.h - Header for Unicode functions.
* These are meant to be used by the OpenLDAP distribution only.
* These should be named ldap_pvt_....()
*/
#ifndef _LDAP_PVT_UC_H
......@@ -32,18 +33,10 @@ LDAP_BEGIN_DECL
* UTF-8 (in utf-8.c)
*/
typedef ber_int_t ldap_ucs4_t;
#define LDAP_UCS4_INVALID (0x80000000U)
typedef short ldap_ucs2_t;
/* UCDATA uses UCS-2 passed in an unsigned long */
typedef unsigned long ldap_unicode_t;
/* conversion routines */
LDAP_F( ldap_ucs4_t ) ldap_utf8_to_ucs4( const char * p );
LDAP_F( int ) ldap_ucs4_to_utf8( ldap_ucs4_t c, char *buf );
#define ldap_utf8_to_unicode( p ) ldap_utf8_to_ucs4((p))
#define ldap_unicode_to_utf8( c, buf ) ldap_ucs4_to_ucs4((c),(buf))
......
......@@ -12,6 +12,7 @@
/*
* ldap-schema.h - Header for basic schema handling functions that can be
* used by both clients and servers.
* these routines should be renamed ldap_x_...
*/
#ifndef _LDAP_SCHEMA_H
......
......@@ -29,36 +29,45 @@
#ifndef _LDAP_UTF8_H
#define _LDAP_UTF8_H
LDAP_BEGIN_DECL
#include <lber_types.h> /* get ber_*_t */
/*
* UTF-8 Utility Routines
*/
LDAP_BEGIN_DECL
#define LDAP_UCS4_INVALID (0x80000000U)
typedef ber_int_t ldap_ucs4_t;
/* LDAP_MAX_UTF8_LEN is 3 or 6 depending on size of wchar_t */
#define LDAP_MAX_UTF8_LEN ( sizeof(wchar_t) * 3/2 )
/* Unicode conversion routines */
LDAP_F( ldap_ucs4_t ) ldap_x_utf8_to_ucs4( LDAP_CONST char * p );
LDAP_F( int ) ldap_x_ucs4_to_utf8( ldap_ucs4_t c, char *buf );
/*
* Wide Char / UTF-8 Conversion Routines
*/
/* UTF-8 character to Wide Char */
LDAP_F(int)
ldap_x_utf8_to_wc ( wchar_t *wchar, const char *utf8char );
ldap_x_utf8_to_wc LDAP_P(( wchar_t *wchar, LDAP_CONST char *utf8char ));
/* UTF-8 string to Wide Char string */
LDAP_F(int)
ldap_x_utf8s_to_wcs ( wchar_t *wcstr, const char *utf8str, size_t count );
ldap_x_utf8s_to_wcs LDAP_P(( wchar_t *wcstr, LDAP_CONST char *utf8str, size_t count ));
/* Wide Char to UTF-8 character */
LDAP_F(int)
ldap_x_wc_to_utf8 ( char *utf8char, wchar_t wchar, size_t count );
ldap_x_wc_to_utf8 LDAP_P(( char *utf8char, wchar_t wchar, size_t count ));
/* Wide Char string to UTF-8 string */
LDAP_F(int)
ldap_x_wcs_to_utf8s ( char *utf8str, const wchar_t *wcstr, size_t count );
ldap_x_wcs_to_utf8s LDAP_P(( char *utf8str, LDAP_CONST wchar_t *wcstr, size_t count ));
/*
* MultiByte Char / UTF-8 Conversion Routines
......@@ -66,23 +75,23 @@ ldap_x_wcs_to_utf8s ( char *utf8str, const wchar_t *wcstr, size_t count );
/* UTF-8 character to MultiByte character */
LDAP_F(int)
ldap_x_utf8_to_mb ( char *mbchar, const char *utf8char,
int (*f_wctomb)(char *mbchar, wchar_t wchar) );
ldap_x_utf8_to_mb LDAP_P(( char *mbchar, LDAP_CONST char *utf8char,
int (*f_wctomb)(char *mbchar, wchar_t wchar) ));
/* UTF-8 string to MultiByte string */
LDAP_F(int)
ldap_x_utf8s_to_mbs ( char *mbstr, const char *utf8str, size_t count,
size_t (*f_wcstombs)(char *mbstr, const wchar_t *wcstr, size_t count) );
ldap_x_utf8s_to_mbs LDAP_P(( char *mbstr, LDAP_CONST char *utf8str, size_t count,
size_t (*f_wcstombs)(char *mbstr, LDAP_CONST wchar_t *wcstr, size_t count) ));
/* MultiByte character to UTF-8 character */
LDAP_F(int)
ldap_x_mb_to_utf8 ( char *utf8char, const char *mbchar, size_t mbsize,
int (*f_mbtowc)(wchar_t *wchar, const char *mbchar, size_t count) );
ldap_x_mb_to_utf8 LDAP_P(( char *utf8char, LDAP_CONST char *mbchar, size_t mbsize,
int (*f_mbtowc)(wchar_t *wchar, LDAP_CONST char *mbchar, size_t count) ));
/* MultiByte string to UTF-8 string */
LDAP_F(int)
ldap_x_mbs_to_utf8s ( char *utf8str, const char *mbstr, size_t count,
size_t (*f_mbstowcs)(wchar_t *wcstr, const char *mbstr, size_t count) );
ldap_x_mbs_to_utf8s LDAP_P(( char *utf8str, LDAP_CONST char *mbstr, size_t count,
size_t (*f_mbstowcs)(wchar_t *wcstr, LDAP_CONST char *mbstr, size_t count) ));
LDAP_END_DECL
......
......@@ -305,7 +305,7 @@ ber_log_dump(
int inout )
{
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( !ber_log_check( errlvl, loglvl )) {
return 0;
......@@ -324,7 +324,7 @@ ber_dump(
ber_len_t len;
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( inout == 1 ) {
len = ber_pvt_ber_remaining(ber);
......
......@@ -42,7 +42,7 @@ ber_get_tag( BerElement *ber )
unsigned int i;
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) {
return LBER_DEFAULT;
......@@ -85,7 +85,7 @@ ber_skip_tag( BerElement *ber, ber_len_t *len )
assert( ber != NULL );
assert( len != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
/*
* Any ber element looks like this: tag length contents.
......@@ -175,7 +175,7 @@ ber_getnint(
assert( ber != NULL );
assert( num != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
/*
* The tag and length have already been stripped off. We should
......@@ -221,7 +221,7 @@ ber_get_int(
ber_len_t len;
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
......@@ -252,7 +252,7 @@ ber_get_stringb(
ber_tag_t tag;
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
......@@ -282,7 +282,7 @@ ber_get_stringa( BerElement *ber, char **buf )
assert( ber != NULL );
assert( buf != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
*buf = NULL;
......@@ -312,7 +312,7 @@ ber_get_stringal( BerElement *ber, struct berval **bv )
assert( ber != NULL );
assert( bv != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
*bv = NULL;
......@@ -363,7 +363,7 @@ ber_get_bitstringa(
assert( buf != NULL );
assert( blen != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
*buf = NULL;
......@@ -398,7 +398,7 @@ ber_get_null( BerElement *ber )
ber_tag_t tag;
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
......@@ -422,7 +422,7 @@ ber_get_boolean(
assert( ber != NULL );
assert( boolval != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
rc = ber_get_int( ber, &longbool );
*boolval = longbool;
......@@ -465,7 +465,7 @@ ber_next_element(
assert( len != NULL );
assert( last != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( ber->ber_ptr == last ) {
return LBER_DEFAULT;
......@@ -497,7 +497,7 @@ ber_scanf ( BerElement *ber,
assert( ber != NULL );
assert( fmt != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
fmt_reset = fmt;
......
......@@ -73,7 +73,7 @@ ber_put_tag(
unsigned char nettag[sizeof(ber_tag_t)];
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
taglen = ber_calc_taglen( tag );
......@@ -125,7 +125,7 @@ ber_put_len( BerElement *ber, ber_len_t len, int nosos )
unsigned char netlen[sizeof(ber_len_t)];
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
/*
* short len if it's less than 128 - one byte giving the len,
......@@ -184,7 +184,7 @@ ber_put_int_or_enum(
unsigned char netnum[sizeof(ber_uint_t)];
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
sign = (num < 0);
unum = num; /* Bit fiddling should be done with unsigned values */
......@@ -244,7 +244,7 @@ ber_put_enum(
ber_tag_t tag )
{
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( tag == LBER_DEFAULT ) {
tag = LBER_ENUMERATED;
......@@ -260,7 +260,7 @@ ber_put_int(
ber_tag_t tag )
{
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( tag == LBER_DEFAULT ) {
tag = LBER_INTEGER;
......@@ -282,7 +282,7 @@ ber_put_ostring(
assert( ber != NULL );
assert( str != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( tag == LBER_DEFAULT ) {
tag = LBER_OCTETSTRING;
......@@ -309,7 +309,7 @@ ber_put_berval(
ber_tag_t tag )
{
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if( bv == NULL || bv->bv_len == 0 ) {
return ber_put_ostring( ber, "", (ber_len_t) 0, tag );
......@@ -327,7 +327,7 @@ ber_put_string(
assert( ber != NULL );
assert( str != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
return ber_put_ostring( ber, str, strlen( str ), tag );
}
......@@ -345,7 +345,7 @@ ber_put_bitstring(
assert( ber != NULL );
assert( str != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( tag == LBER_DEFAULT ) {
tag = LBER_BITSTRING;
......@@ -379,7 +379,7 @@ ber_put_null( BerElement *ber, ber_tag_t tag )
ber_len_t taglen;
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( tag == LBER_DEFAULT ) {
tag = LBER_NULL;
......@@ -407,7 +407,7 @@ ber_put_boolean(
unsigned char falseval = 0;
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( tag == LBER_DEFAULT )
tag = LBER_BOOLEAN;
......@@ -439,7 +439,7 @@ ber_start_seqorset(
Seqorset *new;
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
new = (Seqorset *) LBER_CALLOC( 1, sizeof(Seqorset) );
......@@ -468,7 +468,7 @@ int
ber_start_seq( BerElement *ber, ber_tag_t tag )
{
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( tag == LBER_DEFAULT ) {
tag = LBER_SEQUENCE;
......@@ -481,7 +481,7 @@ int
ber_start_set( BerElement *ber, ber_tag_t tag )
{
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( tag == LBER_DEFAULT ) {
tag = LBER_SET;
......@@ -502,7 +502,7 @@ ber_put_seqorset( BerElement *ber )
Seqorset **sos = &ber->ber_sos;
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
/*
* If this is the toplevel sequence or set, we need to actually
......@@ -655,7 +655,7 @@ int
ber_put_seq( BerElement *ber )
{
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
return ber_put_seqorset( ber );
}
......@@ -664,7 +664,7 @@ int
ber_put_set( BerElement *ber )
{
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
return ber_put_seqorset( ber );
}
......@@ -686,7 +686,7 @@ ber_printf( BerElement *ber, LDAP_CONST char *fmt, ... )
assert( ber != NULL );
assert( fmt != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
va_start( ap, fmt );
......
......@@ -34,7 +34,7 @@
#include "lber-int.h"
#define EXBUFSIZ 1024
#define LBER_EXBUFSIZ 1024
static ber_slen_t
BerRead(
......@@ -75,7 +75,7 @@ ber_read(
assert( ber != NULL );
assert( buf != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
nleft = ber_pvt_ber_remaining( ber );
actuallen = nleft < len ? nleft : len;
......@@ -97,7 +97,7 @@ ber_write(
assert( ber != NULL );
assert( buf != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( nosos || ber->ber_sos == NULL ) {
if ( ber->ber_ptr + len > ber->ber_end ) {
......@@ -131,12 +131,12 @@ ber_realloc( BerElement *ber, ber_len_t len )
assert( ber != NULL );
assert( len > 0 );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
total = ber_pvt_ber_total( ber );
have = total / EXBUFSIZ;
need = (len < EXBUFSIZ ? 1 : (len + (EXBUFSIZ - 1)) / EXBUFSIZ);
total = have * EXBUFSIZ + need * EXBUFSIZ;
have = total / LBER_EXBUFSIZ;
need = len < LBER_EXBUFSIZ ? 1 : (len + (LBER_EXBUFSIZ - 1)) / LBER_EXBUFSIZ;
total = have * LBER_EXBUFSIZ + need * LBER_EXBUFSIZ;
oldbuf = ber->ber_buf;
......@@ -181,7 +181,7 @@ ber_free( BerElement *ber, int freebuf )
return;
}
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( freebuf ) {
Seqorset *s, *next;
......@@ -210,7 +210,7 @@ ber_flush( Sockbuf *sb, BerElement *ber, int freeit )
assert( ber != NULL );
assert( SOCKBUF_VALID( sb ) );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( ber->ber_rwptr == NULL ) {
ber->ber_rwptr = ber->ber_buf;
......@@ -269,7 +269,7 @@ ber_alloc_t( int options )
ber->ber_options = options;
ber->ber_debug = ber_int_debug;
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
return ber;
}
......@@ -291,7 +291,7 @@ ber_dup( BerElement *ber )
BerElement *new;
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( (new = ber_alloc_t( ber->ber_options )) == NULL ) {
return NULL;
......@@ -299,7 +299,7 @@ ber_dup( BerElement *ber )
*new = *ber;
assert( BER_VALID( new ) );
assert( LBER_VALID( new ) );
return( new );
}
......@@ -318,7 +318,7 @@ ber_init_w_nullc( BerElement *ber, int options )
ber->ber_options = (char) options;
ber->ber_debug = ber_int_debug;
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
}
/* New C-API ber_init() */
......@@ -410,7 +410,7 @@ void
ber_reset( BerElement *ber, int was_writing )
{
assert( ber != NULL );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
if ( was_writing ) {
ber->ber_end = ber->ber_ptr;
......@@ -440,7 +440,7 @@ ber_get_next(
assert( ber != NULL );
assert( SOCKBUF_VALID( sb ) );
assert( BER_VALID( ber ) );
assert( LBER_VALID( ber ) );
#ifdef NEW_LOGGING
LDAP_LOG(( "liblber", LDAP_LEVEL_ENTRY, "ber_get_next: enter\n" ));
......
......@@ -72,7 +72,7 @@ struct berelement {
struct seqorset *ber_sos;
char *ber_rwptr;
};
#define BER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
#define LBER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
#define ber_pvt_ber_remaining(ber) ((ber)->ber_end - (ber)->ber_ptr)
#define ber_pvt_ber_total(ber) ((ber)->ber_end - (ber)->ber_buf)
......@@ -92,8 +92,6 @@ struct sockbuf {
#define SOCKBUF_VALID( sb ) ( (sb)->sb_valid == LBER_VALID_SOCKBUF )
#define READBUFSIZ 8192
struct seqorset {
BerElement *sos_ber;
ber_len_t sos_clen;
......
......@@ -53,9 +53,9 @@ struct ber_mem_hdr {
};
/* Pattern at top of allocated space */
#define BER_MEM_JUNK 0xdeaddadaU
#define LLBER_MEM_JUNK 0xdeaddadaU
static const struct ber_mem_hdr ber_int_mem_hdr = { BER_MEM_JUNK, 0, 0 };
static const struct ber_mem_hdr ber_int_mem_hdr = { LBER_MEM_JUNK, 0, 0 };
/* Note sequence and ber_int_options.lbu_meminuse are counters, but are not
* thread safe. If you want to use these values for multithreaded applications,
......@@ -140,7 +140,7 @@ ber_memfree( void *p )
#ifdef LDAP_MEMORY_DEBUG
struct ber_mem_hdr *mh = (struct ber_mem_hdr *)
((char *)p - sizeof(struct ber_mem_hdr));
assert( mh->bm_top == BER_MEM_JUNK);
assert( mh->bm_top == LBER_MEM_JUNK);
assert( testdatatop( mh));
assert( testend( (char *)&mh[1] + mh->bm_length) );
ber_int_options.lbo_meminuse -= mh->bm_length;
......@@ -204,7 +204,7 @@ ber_memalloc( ber_len_t s )
struct ber_mem_hdr *mh = malloc(s + sizeof(struct ber_mem_hdr) + sizeof( ber_int_t));
if( mh == NULL ) return NULL;
mh->bm_top = BER_MEM_JUNK;
mh->bm_top = LBER_MEM_JUNK;
mh->bm_length = s;
setdatatop( mh);
setend( (char *)&mh[1] + mh->bm_length );
......@@ -256,7 +256,7 @@ ber_memcalloc( ber_len_t n, ber_len_t s )
(n * s) + sizeof(struct ber_mem_hdr) + sizeof(ber_int_t) );
if( mh == NULL ) return NULL;
mh->bm_top = BER_MEM_JUNK;
mh->bm_top = LBER_MEM_JUNK;
mh->bm_length = n*s;
setdatatop( mh);
setend( (char *)&mh[1] + mh->bm_length );
......@@ -310,7 +310,7 @@ ber_memrealloc( void* p, ber_len_t s )
ber_int_t oldlen;
struct ber_mem_hdr *mh = (struct ber_mem_hdr *)
((char *)p - sizeof(struct ber_mem_hdr));
assert( mh->bm_top == BER_MEM_JUNK);
assert( mh->bm_top == LBER_MEM_JUNK);
assert( testdatatop( mh));
assert( testend( (char *)&mh[1] + mh->bm_length) );
oldlen = mh->bm_length;
......@@ -329,7 +329,7 @@ ber_memrealloc( void* p, ber_len_t s )
memset( (char *)&mh[1] + oldlen, 0xff, s - oldlen);
}
assert( mh->bm_top == BER_MEM_JUNK);
assert( mh->bm_top == LBER_MEM_JUNK);
assert( testdatatop( mh));
ber_int_options.lbo_meminuse += s - oldlen;
......
......@@ -11,78 +11,77 @@
#include <winsock.h>
#endif /* HAVE_WINSOCK(2) */
#undef __RETSTR
#define __RETSTR( x ) case x: return #x;
#define LBER_RETSTR( x ) case x: return #x;
char *ber_pvt_wsa_err2string( int err )
{
switch( err )
{
__RETSTR( WSAEINTR )
__RETSTR( WSAEBADF )
__RETSTR( WSAEACCES )
__RETSTR( WSAEFAULT )
__RETSTR( WSAEINVAL )
__RETSTR( WSAEMFILE )
__RETSTR( WSAEWOULDBLOCK )
__RETSTR( WSAEINPROGRESS )