X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibrewrite%2Fcontext.c;h=c5770de8928385d5e81278f52aa06f3183581a24;hb=ec24e6293fac6a4c196f49a8575707b5dedefd1d;hp=281fbb4550c7761a3830a17f12801f0dcc788d88;hpb=fbba83b20f3a645b2dc19b8ec4a0026f71f5b15c;p=openldap diff --git a/libraries/librewrite/context.c b/libraries/librewrite/context.c index 281fbb4550..c5770de892 100644 --- a/libraries/librewrite/context.c +++ b/libraries/librewrite/context.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2000-2003 The OpenLDAP Foundation. + * Copyright 2000-2005 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -218,10 +218,10 @@ rewrite_context_apply( assert( op->lo_depth > 0 ); Debug( LDAP_DEBUG_TRACE, "==> rewrite_context_apply" - " [depth=%d] string='%s'\n%s", - op->lo_depth, string, "" ); + " [depth=%d] string='%s'\n", + op->lo_depth, string, 0 ); - s = strdup( string ); + s = (char *)string; for ( rule = context->lc_rule->lr_next; rule != NULL && op->lo_num_passes < info->li_max_passes; @@ -321,7 +321,9 @@ rewrite_context_apply( if ( res != NULL ) { struct rewrite_action *action; - free( s ); + if ( s != string && s != res ) { + free( s ); + } s = res; for ( action = rule->lr_action; @@ -357,6 +359,15 @@ rewrite_context_apply( goto rc_end_of_context; } break; + + /* + * This ends the rewrite context + * and returns a user-defined + * error code + */ + case REWRITE_ACTION_USER: + return_code = ((int *)action->la_args)[ 0 ]; + goto rc_end_of_context; default: /* ... */ @@ -385,10 +396,17 @@ rewrite_context_apply( * This will instruct the server to return * an `unwilling to perform' error message */ - case REWRITE_REGEXEC_UNWILLING: + case REWRITE_REGEXEC_UNWILLING: return_code = REWRITE_REGEXEC_UNWILLING; goto rc_end_of_context; + /* + * A user-defined error code has propagated ... + */ + default: + assert( rc >= REWRITE_REGEXEC_USER ); + goto rc_end_of_context; + } rc_continue:; /* sent here by actions that require to continue */ @@ -415,7 +433,7 @@ rewrite_context_free( { struct rewrite_context *context = (struct rewrite_context *)tmp; - assert( tmp ); + assert( tmp != NULL ); rewrite_context_destroy( &context ); } @@ -428,12 +446,12 @@ rewrite_context_destroy( struct rewrite_context *context; struct rewrite_rule *r; - assert( pcontext ); - assert( *pcontext ); + assert( pcontext != NULL ); + assert( *pcontext != NULL ); context = *pcontext; - assert( context->lc_rule ); + assert( context->lc_rule != NULL ); for ( r = context->lc_rule->lr_next; r; ) { struct rewrite_rule *cr = r; @@ -445,7 +463,7 @@ rewrite_context_destroy( free( context->lc_rule ); context->lc_rule = NULL; - assert( context->lc_name ); + assert( context->lc_name != NULL ); free( context->lc_name ); context->lc_name = NULL;