"[%s:%d] rewriteEngine needs 'state'\n%s",
fname, lineno, "" );
return -1;
+
} else if ( argc > 2 ) {
Debug( LDAP_DEBUG_ANY,
"[%s:%d] extra fields in rewriteEngine"
if ( strcasecmp( argv[ 1 ], "on" ) == 0 ) {
info->li_state = REWRITE_ON;
+
} else if ( strcasecmp( argv[ 1 ], "off" ) == 0 ) {
info->li_state = REWRITE_OFF;
+
} else {
Debug( LDAP_DEBUG_ANY,
"[%s:%d] unknown 'state' in rewriteEngine;"
" 'alias'\n%s",
fname, lineno, "" );
return -1;
+
} else if ( argc > 4 ) {
Debug( LDAP_DEBUG_ANY,
"[%s:%d] extra fields in"
rewrite_int_curr_context->lc_alias = aliased;
rewrite_int_curr_context = aliased;
+
} else {
Debug( LDAP_DEBUG_ANY,
"[%s:%d] extra fields"
" 'subst' ['flags']\n%s",
fname, lineno, "" );
return -1;
+
} else if ( argc > 4 ) {
Debug( LDAP_DEBUG_ANY,
"[%s:%d] extra fields in rewriteRule"
case REWRITE_REGEXEC_ERR:
Debug( LDAP_DEBUG_ANY, "==> rewrite_context_apply"
- " error ...\n%s%s%s", "", "", "");
+ " error ...\n", 0, 0, 0);
/*
* Checks for special actions to be taken
case REWRITE_ACTION_IGNORE_ERR:
Debug( LDAP_DEBUG_ANY,
"==> rewrite_context_apply"
- " ignoring error ...\n%s%s%s",
- "", "", "" );
+ " ignoring error ...\n", 0, 0, 0 );
do_continue = 1;
break;
return REWRITE_SUCCESS;
}
+static int
+destroy_action(
+ struct rewrite_action **paction
+)
+{
+ struct rewrite_action *action;
+
+ assert( paction );
+ assert( *paction );
+
+ action = *paction;
+
+ /* do something */
+ switch ( action->la_type ) {
+ case REWRITE_FLAG_GOTO: {
+ int *pi = (int *)action->la_args;
+
+ if ( pi ) {
+ free( pi );
+ }
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ free( action );
+ *paction = NULL;
+
+ return 0;
+}
+
/*
* In case of error it returns NULL and does not free all the memory
* it allocated; as this is a once only phase, and an error at this stage
)
{
struct rewrite_rule *rule;
+ struct rewrite_action *action;
assert( prule );
assert( *prule );
regfree( &rule->lr_regex );
+ for ( action = rule->lr_action; action; ) {
+ struct rewrite_action *curraction = action;
+
+ action = action->la_next;
+ destroy_action( &curraction );
+ }
+
free( rule );
*prule = NULL;
* Take care of substitution string
*/
for ( p = begin = result, subs_len = 0; p[ 0 ] != '\0'; p++ ) {
-
+
/*
* Keep only single escapes '%'
*/
continue;
}
- tmps = (struct berval *)realloc( subs,
+ tmps = ( struct berval * )realloc( subs,
sizeof( struct berval )*( nsub + 1 ) );
if ( tmps == NULL ) {
/* FIXME: cleanup */
* Substitution pattern
*/
if ( isdigit( (unsigned char) p[ 1 ] ) ) {
- int d = p[ 1 ] - '0';
struct rewrite_submatch *tmpsm;
+ int d = p[ 1 ] - '0';
/*
* Add a new value substitution scheme
*/
- tmpsm = realloc( submatch,
- sizeof( struct rewrite_submatch )*( nsub + 1 ) );
+
+ tmpsm = ( struct rewrite_submatch * )realloc( submatch,
+ sizeof( struct rewrite_submatch )*( nsub + 1 ) );
if ( tmpsm == NULL ) {
/* cleanup */
return NULL;
if ( p[ 2 ] != '{' ) {
submatch[ nsub ].ls_type =
REWRITE_SUBMATCH_ASIS;
+ submatch[ nsub ].ls_map = NULL;
begin = ++p + 1;
+
} else {
struct rewrite_map *map;
/* cleanup */
return NULL;
}
- p = begin - 1;
-
submatch[ nsub ].ls_map = map;
+ p = begin - 1;
}
/*
/*
* Add a new value substitution scheme
*/
- tmpsm = realloc( submatch,
+ tmpsm = ( struct rewrite_submatch * )realloc( submatch,
sizeof( struct rewrite_submatch )*( nsub + 1 ) );
if ( tmpsm == NULL ) {
/* cleanup */
submatch = tmpsm;
submatch[ nsub ].ls_type =
REWRITE_SUBMATCH_MAP_W_ARG;
-
submatch[ nsub ].ls_map = map;
}
/*
* Last part of string
*/
- tmps = realloc( subs, sizeof( struct berval )*( nsub + 1 ) );
+ tmps = (struct berval * )realloc( subs, sizeof( struct berval )*( nsub + 1 ) );
if ( tmps == NULL ) {
/*
* XXX need to free the value subst stuff!
*/
- free( submatch );
+ free( subs );
return NULL;
}
subs = tmps;
l = match[ c ].rm_eo - match[ c ].rm_so;
val->bv_len = l;
- val->bv_val = calloc( sizeof( char ), l + 1 );
+ val->bv_val = malloc( l + 1 );
if ( val->bv_val == NULL ) {
return REWRITE_ERR;
}
rc = rewrite_xmap_apply( info, op,
subst->lt_submatch[ n ].ls_map,
&key, &submatch[ n ] );
+ free( key.bv_val );
+ key.bv_val = NULL;
break;
case REWRITE_SUBMATCH_MAP_W_ARG:
rc = rewrite_map_apply( info, op,
subst->lt_submatch[ n ].ls_map,
&key, &submatch[ n ] );
+ free( key.bv_val );
+ key.bv_val = NULL;
break;
default:
* of the subst pattern and initialize it
*/
l += subst->lt_subs_len;
- res = calloc( sizeof( char ), l + 1 );
+ res = malloc( l + 1 );
if ( res == NULL ) {
rc = REWRITE_REGEXEC_ERR;
goto cleanup;
if ( subst->lt_subs[ n ].bv_val != NULL ) {
AC_MEMCPY( res + cl, subst->lt_subs[ n ].bv_val,
subst->lt_subs[ n ].bv_len );
+ cl += subst->lt_subs[ n ].bv_len;
}
+ res[ cl ] = '\0';
val->bv_val = res;
val->bv_len = l;
}
}
+ free( subst->lt_submatch );
+ subst->lt_submatch = NULL;
+
/* last one */
if ( subst->lt_subs[ n ].bv_val ) {
free( subst->lt_subs[ n ].bv_val );
subst->lt_subs[ n ].bv_val = NULL;
}
+ free( subst->lt_subs );
+ subst->lt_subs = NULL;
+
free( subst );
*psubst = NULL;