/*
- * Copyright 2000-2002 The OpenLDAP Foundation
+ * Copyright 2000-2003 The OpenLDAP Foundation
* COPYING RESTRICTIONS APPLY. See COPYRIGHT File in top level directory
* of this package for details.
*/
#include <ldap_utf8.h>
#include <ldap_pvt_uc.h>
-#define malloc(x) ber_memalloc(x)
-#define realloc(x,y) ber_memrealloc(x,y)
-#define free(x) ber_memfree(x)
+#define malloc(x) ber_memalloc_x(x,ctx)
+#define realloc(x,y) ber_memrealloc_x(x,y,ctx)
+#define free(x) ber_memfree_x(x,ctx)
int ucstrncmp(
const ldap_unicode_t *u1,
struct berval * UTF8bvnormalize(
struct berval *bv,
struct berval *newbv,
- unsigned flags )
+ unsigned flags,
+ void *ctx )
{
int i, j, len, clen, outpos, ucsoutlen, outsize, last;
- char *out, *s;
+ char *out, *outtmp, *s;
unsigned long *ucs, *p, *ucsout;
unsigned casefold = flags & LDAP_UTF8_CASEFOLD;
len = bv->bv_len;
if ( len == 0 ) {
- return ber_dupbv( newbv, bv );
+ return ber_dupbv_x( newbv, bv, ctx );
}
/* FIXME: Should first check to see if string is already in
}
if ( i == len ) {
- return ber_str2bv( s, len, 1, newbv );
+ return ber_str2bv_x( s, len, 1, newbv, ctx );
}
outsize = len + 7;
i = 0;
}
- p = ucs = (long *) malloc( len * sizeof(*ucs) );
+ p = ucs = malloc( len * sizeof(*ucs) );
if ( ucs == NULL ) {
free(out);
return NULL;
p++;
}
/* normalize ucs of length p - ucs */
- uccanondecomp( ucs, p - ucs, &ucsout, &ucsoutlen );
+ uccompatdecomp( ucs, p - ucs, &ucsout, &ucsoutlen, ctx );
if ( approx ) {
for ( j = 0; j < ucsoutlen; j++ ) {
if ( ucsout[j] < 0x80 ) {
6 bytes and terminator */
if ( outsize - outpos < 7 ) {
outsize = ucsoutlen - j + outpos + 6;
- out = (char *) realloc( out, outsize );
- if ( out == NULL ) {
+ outtmp = (char *) realloc( out, outsize );
+ if ( outtmp == NULL ) {
+ free( out );
free( ucs );
+ free( ucsout );
return NULL;
}
+ out = outtmp;
}
outpos += ldap_x_ucs4_to_utf8( ucsout[j], &out[outpos] );
}
}
+
+ free( ucsout );
+ ucsout = NULL;
if ( i == len ) {
break;
int UTF8bvnormcmp(
struct berval *bv1,
struct berval *bv2,
- unsigned flags )
+ unsigned flags,
+ void *ctx )
{
int i, l1, l2, len, ulen, res = 0;
char *s1, *s2, *done;
* proper normalized form.
*/
- ucs = (long *) malloc( ( ( norm1 || l1 > l2 ) ? l1 : l2 ) * sizeof(*ucs) );
+ ucs = malloc( ( ( norm1 || l1 > l2 ) ? l1 : l2 ) * sizeof(*ucs) );
if ( ucs == NULL ) {
return l1 > l2 ? 1 : -1; /* what to do??? */
}
if ( norm1 ) {
ucsout1 = ucs;
l1 = ulen;
- ucs = (long *) malloc( l2 * sizeof(*ucs) );
+ ucs = malloc( l2 * sizeof(*ucs) );
if ( ucs == NULL ) {
return l1 > l2 ? 1 : -1; /* what to do??? */
}
} else {
- uccanondecomp( ucs, ulen, &ucsout1, &l1 );
+ uccompatdecomp( ucs, ulen, &ucsout1, &l1, ctx );
l1 = uccanoncomp( ucsout1, l1 );
}
ucsout2 = ucs;
l2 = ulen;
} else {
- uccanondecomp( ucs, ulen, &ucsout2, &l2 );
+ uccompatdecomp( ucs, ulen, &ucsout2, &l2, ctx );
l2 = uccanoncomp( ucsout2, l2 );
free( ucs );
}