/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2000-2003 The OpenLDAP Foundation.
+ * Copyright 2000-2006 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
struct rewrite_subst *
rewrite_subst_compile(
struct rewrite_info *info,
- const char *result
+ const char *str
)
{
size_t subs_len;
struct rewrite_subst *s = NULL;
- const char *begin, *p;
+ char *result, *begin, *p;
int nsub = 0, l;
assert( info != NULL );
- assert( result != NULL );
+ assert( str != NULL );
+
+ result = strdup( str );
+ if ( result == NULL ) {
+ return NULL;
+ }
/*
* Take care of substitution string
/*
* Keep only single escapes '%'
*/
- if ( p[ 0 ] != REWRITE_SUBMATCH_ESCAPE ) {
+ if ( !IS_REWRITE_SUBMATCH_ESCAPE( p[ 0 ] ) ) {
continue;
}
- if ( p[ 1 ] == REWRITE_SUBMATCH_ESCAPE ) {
+ if ( IS_REWRITE_SUBMATCH_ESCAPE( p[ 1 ] ) ) {
/* Pull &p[1] over p, including the trailing '\0' */
AC_MEMCPY((char *)p, &p[ 1 ], strlen( p ) );
continue;
tmps = ( struct berval * )realloc( subs,
sizeof( struct berval )*( nsub + 1 ) );
if ( tmps == NULL ) {
- /* FIXME: cleanup */
- return NULL;
+ goto cleanup;
}
subs = tmps;
subs[ nsub ].bv_len = l;
subs[ nsub ].bv_val = malloc( l + 1 );
if ( subs[ nsub ].bv_val == NULL ) {
- return NULL;
+ goto cleanup;
}
AC_MEMCPY( subs[ nsub ].bv_val, begin, l );
subs[ nsub ].bv_val[ l ] = '\0';
tmpsm = ( struct rewrite_submatch * )realloc( submatch,
sizeof( struct rewrite_submatch )*( nsub + 1 ) );
if ( tmpsm == NULL ) {
- /* cleanup */
- return NULL;
+ goto cleanup;
}
submatch = tmpsm;
submatch[ nsub ].ls_submatch = d;
REWRITE_SUBMATCH_XMAP;
map = rewrite_xmap_parse( info,
- p + 3, &begin );
+ p + 3, (const char **)&begin );
if ( map == NULL ) {
- /* cleanup */
- return NULL;
+ goto cleanup;
}
submatch[ nsub ].ls_map = map;
p = begin - 1;
struct rewrite_map *map;
struct rewrite_submatch *tmpsm;
- map = rewrite_map_parse( info, p + 2, &begin );
+ map = rewrite_map_parse( info, p + 2,
+ (const char **)&begin );
if ( map == NULL ) {
- /* cleanup */
- return NULL;
+ goto cleanup;
}
p = begin - 1;
tmpsm = ( struct rewrite_submatch * )realloc( submatch,
sizeof( struct rewrite_submatch )*( nsub + 1 ) );
if ( tmpsm == NULL ) {
- /* cleanup */
- return NULL;
+ goto cleanup;
}
submatch = tmpsm;
submatch[ nsub ].ls_type =
REWRITE_SUBMATCH_MAP_W_ARG;
submatch[ nsub ].ls_map = map;
+
+ /*
+ * Escape '%' ...
+ */
+ } else if ( p[ 1 ] == '%' ) {
+ AC_MEMCPY( &p[ 1 ], &p[ 2 ], strlen( &p[ 1 ] ) );
+ continue;
+
+ } else {
+ goto cleanup;
}
nsub++;
* XXX need to free the value subst stuff!
*/
free( subs );
- return NULL;
+ goto cleanup;
}
subs = tmps;
l = p - begin;
s = calloc( sizeof( struct rewrite_subst ), 1 );
if ( s == NULL ) {
- /* cleanup */
- return NULL;
+ goto cleanup;
}
s->lt_subs_len = subs_len;
s->lt_num_submatch = nsub;
s->lt_submatch = submatch;
+cleanup:;
+ free( result );
+
return s;
}
}
if ( rc != REWRITE_SUCCESS ) {
- rc = REWRITE_REGEXEC_ERR;
goto cleanup;
}
break;
rc = REWRITE_ERR;
break;
}
-
+
if ( rc != REWRITE_SUCCESS ) {
rc = REWRITE_REGEXEC_ERR;
+ goto cleanup;
}
/*
int n;
struct rewrite_subst *subst;
- assert( psubst );
- assert( *psubst );
+ assert( psubst != NULL );
+ assert( *psubst != NULL );
subst = *psubst;