LDAP_LUNICODE_F(struct berval *) UTF8bvnormalize(
struct berval *,
struct berval *,
- unsigned );
+ unsigned,
+ void *memctx );
LDAP_LUNICODE_F(int) UTF8bvnormcmp(
struct berval *,
struct berval *,
- unsigned );
+ unsigned,
+ void *memctx );
LDAP_END_DECL
/* mode == 0 for canonical, mode == 1 for compatibility */
static int
uccanoncompatdecomp(const unsigned long *in, int inlen,
- unsigned long **out, int *outlen, short mode)
+ unsigned long **out, int *outlen, short mode, void *ctx)
{
int l, size;
unsigned i, j, k;
unsigned long num, class, *decomp, hangdecomp[3];
- size = inlen;
- *out = (unsigned long *) malloc(size * sizeof(**out));
+ size = inlen * 2;
+ *out = (unsigned long *) ber_memalloc_x(size * sizeof(**out), ctx);
if (*out == NULL)
return *outlen = -1;
if (mode ? uckdecomp(in[j], &num, &decomp) : ucdecomp(in[j], &num, &decomp)) {
if ( size - i < num) {
size = inlen + i - j + num - 1;
- *out = (unsigned long *) realloc(*out, size * sizeof(**out));
+ *out = (unsigned long *) ber_memrealloc_x(*out, size * sizeof(**out), ctx );
if (*out == NULL)
return *outlen = -1;
}
} else if (ucdecomp_hangul(in[j], &num, hangdecomp)) {
if (size - i < num) {
size = inlen + i - j + num - 1;
- *out = (unsigned long *) realloc(*out, size * sizeof(**out));
+ *out = (unsigned long *) ber_memrealloc_x(*out, size * sizeof(**out), ctx);
if (*out == NULL)
return *outlen = -1;
}
} else {
if (size - i < 1) {
size = inlen + i - j;
- *out = (unsigned long *) realloc(*out, size * sizeof(**out));
+ *out = (unsigned long *) ber_memrealloc_x(*out, size * sizeof(**out), ctx);
if (*out == NULL)
return *outlen = -1;
}
int
uccanondecomp(const unsigned long *in, int inlen,
- unsigned long **out, int *outlen)
+ unsigned long **out, int *outlen, void *ctx)
{
- return uccanoncompatdecomp(in, inlen, out, outlen, 0);
+ return uccanoncompatdecomp(in, inlen, out, outlen, 0, ctx);
}
int
uccompatdecomp(const unsigned long *in, int inlen,
- unsigned long **out, int *outlen)
+ unsigned long **out, int *outlen, void *ctx)
{
- return uccanoncompatdecomp(in, inlen, out, outlen, 1);
+ return uccanoncompatdecomp(in, inlen, out, outlen, 1, ctx);
}
/**************************************************************************
*/
LDAP_LUNICODE_F (int)
uccanondecomp LDAP_P((const unsigned long *in, int inlen,
- unsigned long **out, int *outlen));
+ unsigned long **out, int *outlen, void *ctx));
/*
* Equivalent to uccanondecomp() except that it includes compatibility
*/
LDAP_LUNICODE_F (int)
uccompatdecomp LDAP_P((const unsigned long *in, int inlen,
- unsigned long **out, int *outlen));
+ unsigned long **out, int *outlen, void *ctx));
/**************************************************************************
*
#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, *outtmp, *s;
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;
p++;
}
/* normalize ucs of length p - ucs */
- uccompatdecomp( ucs, p - ucs, &ucsout, &ucsoutlen );
+ uccompatdecomp( ucs, p - ucs, &ucsout, &ucsoutlen, ctx );
if ( approx ) {
for ( j = 0; j < ucsoutlen; j++ ) {
if ( ucsout[j] < 0x80 ) {
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;
return l1 > l2 ? 1 : -1; /* what to do??? */
}
} else {
- uccompatdecomp( ucs, ulen, &ucsout1, &l1 );
+ uccompatdecomp( ucs, ulen, &ucsout1, &l1, ctx );
l1 = uccanoncomp( ucsout1, l1 );
}
ucsout2 = ucs;
l2 = ulen;
} else {
- uccompatdecomp( ucs, ulen, &ucsout2, &l2 );
+ uccompatdecomp( ucs, ulen, &ucsout2, &l2, ctx );
l2 = uccanoncomp( ucsout2, l2 );
free( ucs );
}
memsiz = ber_len( op->o_ber ) * 32;
if ( SLAB_SIZE > memsiz ) memsiz = SLAB_SIZE;
- if ( tag != LDAP_REQ_ADD ) {
+ if ( tag == LDAP_REQ_SEARCH ) {
memctx = sl_mem_create( memsiz, ctx );
ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, memctx );
op->o_tmpmemctx = memctx;
flags |= ( ( use & SLAP_MR_EQUALITY_APPROX ) == SLAP_MR_EQUALITY_APPROX )
? LDAP_UTF8_APPROX : 0;
- val = UTF8bvnormalize( val, &tmp, flags );
+ val = UTF8bvnormalize( val, &tmp, flags, ctx );
if( val == NULL ) {
return LDAP_OTHER;
}