Back to index

openldap  2.4.31
Classes | Defines | Typedefs | Functions
rewrite.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rewrite_mapper

Defines

#define REWRITE_DEFAULT_CONTEXT   "default"
#define REWRITE_OFF   0x0000
#define REWRITE_ON   0x0001
#define REWRITE_DEFAULT   REWRITE_OFF
#define REWRITE_SUCCESS   LDAP_SUCCESS
#define REWRITE_ERR   LDAP_OTHER
#define REWRITE_MODE_ERR   0x0010
#define REWRITE_MODE_OK   0x0011
#define REWRITE_MODE_COPY_INPUT   0x0012
#define REWRITE_MODE_USE_DEFAULT   0x0013
#define REWRITE_REGEXEC_OK   (0)
#define REWRITE_REGEXEC_ERR   (-1)
#define REWRITE_REGEXEC_STOP   (-2)
#define REWRITE_REGEXEC_UNWILLING   (-3)
#define REWRITE_REGEXEC_USER   (1) /* and above: LDAP errors */
#define REWRITE_VAR_NONE   0x0000
#define REWRITE_VAR_INSERT   0x0001
#define REWRITE_VAR_UPDATE   0x0002
#define REWRITE_VAR_COPY_NAME   0x0004
#define REWRITE_VAR_COPY_VALUE   0x0008
#define rewrite_session_var_set(info, cookie, name, value)

Typedefs

typedef void *( rewrite_mapper_config )(const char *fname, int lineno, int argc, char **argv)
typedef intrewrite_mapper_apply )(void *ctx, const char *arg, struct berval *retval)
typedef intrewrite_mapper_destroy )(void *ctx)
typedef struct rewrite_mapper rewrite_mapper

Functions

LDAP_BEGIN_DECL rewrite_info_init (int mode)
 rewrite_info_delete (struct rewrite_info **info)
 rewrite_parse (struct rewrite_info *info, const char *fname, int lineno, int argc, char **argv)
 rewrite_read (FILE *fin, struct rewrite_info *info)
 rewrite (struct rewrite_info *info, const char *rewriteContext, const char *string, char **result)
 rewrite_session (struct rewrite_info *info, const char *rewriteContext, const char *string, const void *cookie, char **result)
 rewrite_session_init (struct rewrite_info *info, const void *cookie)
 rewrite_session_var_set_f (struct rewrite_info *info, const void *cookie, const char *name, const char *value, int flags)
 rewrite_session_delete (struct rewrite_info *info, const void *cookie)
 rewrite_param_set (struct rewrite_info *info, const char *name, const char *value)
 rewrite_param_get (struct rewrite_info *info, const char *name, struct berval *value)
 rewrite_param_destroy (struct rewrite_info *info)
 rewrite_mapper_register (const rewrite_mapper *map)
 rewrite_mapper_unregister (const rewrite_mapper *map)
 rewrite_mapper_find (const char *name)

Class Documentation

struct rewrite_mapper

Definition at line 276 of file rewrite.h.

Class Members
rewrite_mapper_apply * rm_apply
rewrite_mapper_config * rm_config
rewrite_mapper_destroy * rm_destroy
char * rm_name

Define Documentation

Definition at line 35 of file rewrite.h.

#define REWRITE_DEFAULT_CONTEXT   "default"

Definition at line 28 of file rewrite.h.

#define REWRITE_ERR   LDAP_OTHER

Definition at line 41 of file rewrite.h.

#define REWRITE_MODE_COPY_INPUT   0x0012

Definition at line 54 of file rewrite.h.

#define REWRITE_MODE_ERR   0x0010

Definition at line 52 of file rewrite.h.

#define REWRITE_MODE_OK   0x0011

Definition at line 53 of file rewrite.h.

#define REWRITE_MODE_USE_DEFAULT   0x0013

Definition at line 55 of file rewrite.h.

#define REWRITE_OFF   0x0000

Definition at line 33 of file rewrite.h.

#define REWRITE_ON   0x0001

Definition at line 34 of file rewrite.h.

#define REWRITE_REGEXEC_ERR   (-1)

Definition at line 69 of file rewrite.h.

#define REWRITE_REGEXEC_OK   (0)

Definition at line 68 of file rewrite.h.

#define REWRITE_REGEXEC_STOP   (-2)

Definition at line 70 of file rewrite.h.

#define REWRITE_REGEXEC_UNWILLING   (-3)

Definition at line 71 of file rewrite.h.

#define REWRITE_REGEXEC_USER   (1) /* and above: LDAP errors */

Definition at line 72 of file rewrite.h.

#define rewrite_session_var_set (   info,
  cookie,
  name,
  value 
)

Definition at line 40 of file rewrite.h.

#define REWRITE_VAR_COPY_NAME   0x0004

Definition at line 96 of file rewrite.h.

#define REWRITE_VAR_COPY_VALUE   0x0008

Definition at line 97 of file rewrite.h.

#define REWRITE_VAR_INSERT   0x0001

Definition at line 94 of file rewrite.h.

#define REWRITE_VAR_NONE   0x0000

Definition at line 93 of file rewrite.h.

#define REWRITE_VAR_UPDATE   0x0002

Definition at line 95 of file rewrite.h.


Typedef Documentation

typedef int( rewrite_mapper_apply)(void *ctx, const char *arg, struct berval *retval)

Definition at line 268 of file rewrite.h.

typedef void*( rewrite_mapper_config)(const char *fname, int lineno, int argc, char **argv)

Definition at line 262 of file rewrite.h.

Definition at line 273 of file rewrite.h.


Function Documentation

rewrite ( struct rewrite_info info,
const char *  rewriteContext,
const char *  string,
char **  result 
)

Definition at line 158 of file info.c.

{
       return rewrite_session( info, rewriteContext, 
                     string, NULL, result );
}

Here is the call graph for this function:

rewrite_info_delete ( struct rewrite_info **  info)

Definition at line 103 of file info.c.

{
       struct rewrite_info  *info;

       assert( pinfo != NULL );
       assert( *pinfo != NULL );

       info = *pinfo;
       
       if ( info->li_context ) {
              avl_free( info->li_context, rewrite_context_free );
       }
       info->li_context = NULL;

       if ( info->li_maps ) {
              avl_free( info->li_maps, rewrite_builtin_map_free );
       }
       info->li_maps = NULL;

       rewrite_session_destroy( info );

#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_destroy( &info->li_cookies_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       rewrite_param_destroy( info );
       
#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_destroy( &info->li_params_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       free( info );
       *pinfo = NULL;

       return REWRITE_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 39 of file info.c.

{
       struct rewrite_info *info;
       struct rewrite_context *context;

       switch ( mode ) {
       case REWRITE_MODE_ERR:
       case REWRITE_MODE_OK:
       case REWRITE_MODE_COPY_INPUT:
       case REWRITE_MODE_USE_DEFAULT:
              break;
       default:
              mode = REWRITE_MODE_USE_DEFAULT;
              break;
              /* return NULL */
       }

       /*
        * Resets the running context for parsing ...
        */
       rewrite_int_curr_context = NULL;

       info = calloc( sizeof( struct rewrite_info ), 1 );
       if ( info == NULL ) {
              return NULL;
       }

       info->li_state = REWRITE_DEFAULT;
       info->li_max_passes = REWRITE_MAX_PASSES;
       info->li_max_passes_per_rule = REWRITE_MAX_PASSES;
       info->li_rewrite_mode = mode;

       /*
        * Add the default (empty) rule
        */
       context = rewrite_context_create( info, REWRITE_DEFAULT_CONTEXT );
       if ( context == NULL ) {
              free( info );
              return NULL;
       }

#ifdef USE_REWRITE_LDAP_PVT_THREADS
       if ( ldap_pvt_thread_rdwr_init( &info->li_cookies_mutex ) ) {
              avl_free( info->li_context, rewrite_context_free );
              free( info );
              return NULL;
       }
       if ( ldap_pvt_thread_rdwr_init( &info->li_params_mutex ) ) {
              ldap_pvt_thread_rdwr_destroy( &info->li_cookies_mutex );
              avl_free( info->li_context, rewrite_context_free );
              free( info );
              return NULL;
       }
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
       
       return info;
}

Here is the call graph for this function:

Here is the caller graph for this function:

rewrite_mapper_find ( const char *  name)

Definition at line 533 of file map.c.

{
       int i;

       if ( !strcasecmp( name, "ldap" ))
              return &rewrite_ldap_mapper;

       for (i=0; i<num_mappers; i++)
              if ( !strcasecmp( name, mappers[i]->rm_name ))
                     return mappers[i];
       return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 549 of file map.c.

{
       if ( num_mappers % MAPPER_ALLOC == 0 ) {
              const rewrite_mapper **mnew;
              mnew = realloc( mappers, (num_mappers + MAPPER_ALLOC) *
                     sizeof( rewrite_mapper * ));
              if ( mnew )
                     mappers = mnew;
              else
                     return -1;
       }
       mappers[num_mappers++] = map;
       return 0;
}

Here is the caller graph for this function:

Definition at line 567 of file map.c.

{
       int i;

       for (i = 0; i<num_mappers; i++) {
              if ( mappers[i] == map ) {
                     num_mappers--;
                     mappers[i] = mappers[num_mappers];
                     mappers[num_mappers] = NULL;
                     return 0;
              }
       }
       /* not found */
       return -1;
}
rewrite_param_destroy ( struct rewrite_info info)

Definition at line 128 of file params.c.

{
       int count;

       assert( info != NULL );
       
#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_wlock( &info->li_params_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
       
       count = avl_free( info->li_params, rewrite_param_free );
       info->li_params = NULL;

#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       return REWRITE_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

rewrite_param_get ( struct rewrite_info info,
const char *  name,
struct berval value 
)

Definition at line 71 of file params.c.

{
       struct rewrite_var *var;
       int rc = REWRITE_SUCCESS;

       assert( info != NULL );
       assert( name != NULL );
       assert( value != NULL );

       value->bv_val = NULL;
       value->bv_len = 0;
       
#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_rlock( &info->li_params_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
       
       var = rewrite_var_find( info->li_params, name );
       if ( var != NULL ) {
              value->bv_val = strdup( var->lv_value.bv_val );
              value->bv_len = var->lv_value.bv_len;
       }

       if ( var == NULL || value->bv_val == NULL ) {
              rc = REWRITE_ERR;
       }
       
#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_runlock( &info->li_params_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       return REWRITE_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

rewrite_param_set ( struct rewrite_info info,
const char *  name,
const char *  value 
)

Definition at line 28 of file params.c.

{
       struct rewrite_var *var;
       int rc = REWRITE_SUCCESS;

       assert( info != NULL );
       assert( name != NULL );
       assert( value != NULL );

#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_wlock( &info->li_params_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       var = rewrite_var_find( info->li_params, name );
       if ( var != NULL ) {
              assert( var->lv_value.bv_val != NULL );
              free( var->lv_value.bv_val );
              var->lv_value.bv_val = strdup( value );
              var->lv_value.bv_len = strlen( value );

       } else {
              var = rewrite_var_insert( &info->li_params, name, value );
       }

       if ( var == NULL || var->lv_value.bv_val == NULL ) {
              rc = REWRITE_ERR;
       }
       
#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

rewrite_parse ( struct rewrite_info info,
const char *  fname,
int  lineno,
int  argc,
char **  argv 
)

Definition at line 49 of file config.c.

{
       int rc = -1;

       assert( info != NULL );
       assert( fname != NULL );
       assert( argv != NULL );
       assert( argc > 0 );
       
       /*
        * Switch on the rewrite engine
        */
       if ( strcasecmp( argv[ 0 ], "rewriteEngine" ) == 0 ) {
              if ( argc < 2 ) {
                     Debug( LDAP_DEBUG_ANY,
                                   "[%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"
                                   " will be discarded\n%s",
                                   fname, lineno, "" );
              }

              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;"
                                   " assuming 'on'\n%s",
                                   fname, lineno, "" );
                     info->li_state = REWRITE_ON;
              }
              rc = REWRITE_SUCCESS;
       
       /*
        * Alter max passes
        */
       } else if ( strcasecmp( argv[ 0 ], "rewriteMaxPasses" ) == 0 ) {
              if ( argc < 2 ) {
                     Debug( LDAP_DEBUG_ANY,
                                   "[%s:%d] rewriteMaxPasses needs 'value'\n%s",
                                   fname, lineno, "" );
                     return -1;
              }

              if ( lutil_atoi( &info->li_max_passes, argv[ 1 ] ) != 0 ) {
                     Debug( LDAP_DEBUG_ANY,
                                   "[%s:%d] unable to parse rewriteMaxPasses=\"%s\"\n",
                                   fname, lineno, argv[ 1 ] );
                     return -1;
              }

              if ( info->li_max_passes <= 0 ) {
                     Debug( LDAP_DEBUG_ANY,
                                   "[%s:%d] negative or null rewriteMaxPasses\n",
                                   fname, lineno, 0 );
                     return -1;
              }

              if ( argc > 2 ) {
                     if ( lutil_atoi( &info->li_max_passes_per_rule, argv[ 2 ] ) != 0 ) {
                            Debug( LDAP_DEBUG_ANY,
                                          "[%s:%d] unable to parse rewriteMaxPassesPerRule=\"%s\"\n",
                                          fname, lineno, argv[ 2 ] );
                            return -1;
                     }

                     if ( info->li_max_passes_per_rule <= 0 ) {
                            Debug( LDAP_DEBUG_ANY,
                                          "[%s:%d] negative or null rewriteMaxPassesPerRule\n",
                                          fname, lineno, 0 );
                            return -1;
                     }

              } else {
                     info->li_max_passes_per_rule = info->li_max_passes;
              }
              rc = REWRITE_SUCCESS;
       
       /*
        * Start a new rewrite context and set current context
        */
       } else if ( strcasecmp( argv[ 0 ], "rewriteContext" ) == 0 ) {
              if ( argc < 2 ) {
                     Debug( LDAP_DEBUG_ANY,
                                   "[%s:%d] rewriteContext needs 'name'\n%s",
                                   fname, lineno, "" );
                     return -1;
              } 

              /*
               * Checks for existence (lots of contexts should be
               * available by default ...)
               */
               rewrite_int_curr_context = rewrite_context_find( info, argv[ 1 ] );
               if ( rewrite_int_curr_context == NULL ) {
                      rewrite_int_curr_context = rewrite_context_create( info,
                                    argv[ 1 ] );                       
               }
               if ( rewrite_int_curr_context == NULL ) {
                      return -1;
               }
                                          
               if ( argc > 2 ) {

                      /*
                       * A context can alias another (e.g., the `builtin'
                       * contexts for backend operations, if not defined,
                       * alias the `default' rewrite context (with the
                       * notable exception of the searchResult context,
                       * which can be undefined)
                       */
                      if ( strcasecmp( argv[ 2 ], "alias" ) == 0 ) {
                             struct rewrite_context *aliased;
                             
                             if ( argc == 3 ) {
                                    Debug( LDAP_DEBUG_ANY,
                                                  "[%s:%d] rewriteContext"
                                                  " needs 'name' after"
                                                  " 'alias'\n%s",
                                                  fname, lineno, "" );
                                    return -1;

                             } else if ( argc > 4 ) {
                                    Debug( LDAP_DEBUG_ANY,
                                                  "[%s:%d] extra fields in"
                                                  " rewriteContext"
                                                  " after aliased name"
                                                  " will be"
                                                  " discarded\n%s",
                                                  fname, lineno, "" );
                             }
                             
                             aliased = rewrite_context_find( info, 
                                           argv[ 3 ] );
                             if ( aliased == NULL ) {
                                    Debug( LDAP_DEBUG_ANY,
                                                  "[%s:%d] aliased"
                                                  " rewriteContext '%s'"
                                                  " does not exists\n",
                                                  fname, lineno,
                                                  argv[ 3 ] );
                                    return -1;
                             }
                             
                             rewrite_int_curr_context->lc_alias = aliased;
                             rewrite_int_curr_context = aliased;

                      } else {
                             Debug( LDAP_DEBUG_ANY,
                                           "[%s:%d] extra fields"
                                           " in rewriteContext"
                                           " will be discarded\n%s",
                                           fname, lineno, "" );
                      }
               }
               rc = REWRITE_SUCCESS;
               
       /*
        * Compile a rule in current context
        */
       } else if ( strcasecmp( argv[ 0 ], "rewriteRule" ) == 0 ) {
              if ( argc < 3 ) {
                     Debug( LDAP_DEBUG_ANY,
                                   "[%s:%d] rewriteRule needs 'pattern'"
                                   " 'subst' ['flags']\n%s",
                                   fname, lineno, "" );
                     return -1;

              } else if ( argc > 4 ) {
                     Debug( LDAP_DEBUG_ANY,
                                   "[%s:%d] extra fields in rewriteRule"
                                   " will be discarded\n%s",
                                   fname, lineno, "" );
              }

              if ( rewrite_int_curr_context == NULL ) {
                     Debug( LDAP_DEBUG_ANY,
                                   "[%s:%d] rewriteRule outside a"
                                   " context; will add to default\n%s",
                                   fname, lineno, "" );
                     rewrite_int_curr_context = rewrite_context_find( info,
                                   REWRITE_DEFAULT_CONTEXT );

                     /*
                      * Default context MUST exist in a properly initialized
                      * struct rewrite_info
                      */
                     assert( rewrite_int_curr_context != NULL );
              }
              
              rc = rewrite_rule_compile( info, rewrite_int_curr_context, argv[ 1 ],
                            argv[ 2 ], ( argc == 4 ? argv[ 3 ] : "" ) );
       
       /*
        * Add a plugin map to the map tree
        */
       } else if ( strcasecmp( argv[ 0 ], "rewriteMap" ) == 0 ) {
              if ( argc < 3 ) {
                     Debug( LDAP_DEBUG_ANY,
                                   "[%s:%d] rewriteMap needs at least 'type'"
                                   " and 'name' ['args']\n%s",
                                   fname, lineno, "" );
                     return -1;
              }

              rc = rewrite_parse_builtin_map( info, fname, lineno,
                            argc, argv );

       /*
        * Set the value of a global scope parameter
        */
       } else if ( strcasecmp( argv[ 0 ], "rewriteParam" ) == 0 ) {
              if ( argc < 3 ) {
                     Debug( LDAP_DEBUG_ANY,
                                   "[%s:%d] rewriteParam needs 'name'"
                                   " and 'value'\n%s",
                                   fname, lineno, "" );
                     return -1;
              }

              rc = rewrite_param_set( info, argv[ 1 ], argv[ 2 ] );
              
       /*
        * Error
        */
       } else {
              Debug( LDAP_DEBUG_ANY,
                            "[%s:%d] unknown command '%s'\n",
                            fname, lineno, "" );
              return -1;
       }

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

rewrite_read ( FILE *  fin,
struct rewrite_info info 
)

Definition at line 90 of file parse.c.

{
       char buf[ 1024 ];
       char *argv[11];
       int argc, lineno;

       /* 
        * Empty rule at the beginning of the context
        */

       for ( lineno = 0; fgets( buf, sizeof( buf ), fin ); lineno++ ) {
              switch ( parse_line( argv, &argc, sizeof( argv ) - 1, buf ) ) {
              case -1:
                     return REWRITE_ERR;
              case 0:
                     break;
              case 1:
                     if ( strncasecmp( argv[ 0 ], "rewrite", 7 ) == 0 ) {
                            int rc;
                            rc = rewrite_parse( info, "file", lineno, 
                                          argc, argv );
                            if ( rc != REWRITE_SUCCESS ) {
                                   return rc;
                            }
                     }
                     break;
              }
       }

       return REWRITE_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

rewrite_session ( struct rewrite_info info,
const char *  rewriteContext,
const char *  string,
const void cookie,
char **  result 
)

Definition at line 170 of file info.c.

{
       struct rewrite_context *context;
       struct rewrite_op op = { 0, 0, NULL, NULL, NULL };
       int rc;
       
       assert( info != NULL );
       assert( rewriteContext != NULL );
       assert( string != NULL );
       assert( result != NULL );

       /*
        * cookie can be null; means: don't care about session stuff
        */

       *result = NULL;
       op.lo_cookie = cookie;
       
       /*
        * Engine not on means no failure, but explicit no rewriting
        */
       if ( info->li_state != REWRITE_ON ) {
              rc = REWRITE_REGEXEC_OK;
              goto rc_return;
       }
       
       /*
        * Undefined context means no rewriting also
        * (conservative, are we sure it's what we want?)
        */
       context = rewrite_context_find( info, rewriteContext );
       if ( context == NULL ) {
              switch ( info->li_rewrite_mode ) {
              case REWRITE_MODE_ERR:
                     rc = REWRITE_REGEXEC_ERR;
                     goto rc_return;
                     
              case REWRITE_MODE_OK:
                     rc = REWRITE_REGEXEC_OK;
                     goto rc_return;

              case REWRITE_MODE_COPY_INPUT:
                     *result = strdup( string );
                     rc = ( *result != NULL ) ? REWRITE_REGEXEC_OK : REWRITE_REGEXEC_ERR;
                     goto rc_return;

              case REWRITE_MODE_USE_DEFAULT:
                     context = rewrite_context_find( info,
                                   REWRITE_DEFAULT_CONTEXT );
                     break;
              }
       }

#if 0 /* FIXME: not used anywhere! (debug? then, why strdup?) */
       op.lo_string = strdup( string );
       if ( op.lo_string == NULL ) {
              rc = REWRITE_REGEXEC_ERR;
              goto rc_return;
       }
#endif
       
       /*
        * Applies rewrite context
        */
       rc = rewrite_context_apply( info, &op, context, string, result );
       assert( op.lo_depth == 0 );

#if 0 /* FIXME: not used anywhere! (debug? then, why strdup?) */      
       free( op.lo_string );
#endif
       
       switch ( rc ) {
       /*
        * Success
        */
       case REWRITE_REGEXEC_OK:
       case REWRITE_REGEXEC_STOP:
              /*
               * If rewrite succeeded return OK regardless of how
               * the successful rewriting was obtained!
               */
              rc = REWRITE_REGEXEC_OK;
              break;
              
       
       /*
        * Internal or forced error, return = NULL; rc already OK.
        */
       case REWRITE_REGEXEC_UNWILLING:
       case REWRITE_REGEXEC_ERR:
              if ( *result != NULL ) {
                     if ( *result != string ) {
                            free( *result );
                     }
                     *result = NULL;
              }

       default:
              break;
       }

rc_return:;
       if ( op.lo_vars ) {
              rewrite_var_delete( op.lo_vars );
       }
       
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

rewrite_session_delete ( struct rewrite_info info,
const void cookie 
)

Definition at line 334 of file session.c.

{
       struct rewrite_session *session, tmp = { 0 };

       assert( info != NULL );
       assert( cookie != NULL );

       session = rewrite_session_find( info, cookie );

       if ( session == NULL ) {
              return REWRITE_SUCCESS;
       }

       if ( --session->ls_count > 0 ) {
              rewrite_session_return( info, session );
              return REWRITE_SUCCESS;
       }

       rewrite_session_clean( session );

#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_wlock( &info->li_cookies_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       assert( info->li_num_cookies > 0 );
       info->li_num_cookies--;
       
       /*
        * There is nothing to delete in the return value
        */
       tmp.ls_cookie = ( void * )cookie;
       avl_delete( &info->li_cookies, ( caddr_t )&tmp, rewrite_cookie_cmp );

       free( session );

#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_wunlock( &info->li_cookies_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       return REWRITE_SUCCESS;
}

Here is the caller graph for this function:

rewrite_session_init ( struct rewrite_info info,
const void cookie 
) [read]

Definition at line 75 of file session.c.

{
       struct rewrite_session      *session, tmp;
       int                  rc;

       assert( info != NULL );
       assert( cookie != NULL );

#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_wlock( &info->li_cookies_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       tmp.ls_cookie = ( void * )cookie;
       session = ( struct rewrite_session * )avl_find( info->li_cookies, 
                     ( caddr_t )&tmp, rewrite_cookie_cmp );
       if ( session ) {
              session->ls_count++;
#ifdef USE_REWRITE_LDAP_PVT_THREADS
              ldap_pvt_thread_rdwr_wunlock( &info->li_cookies_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
              return session;
       }
              
       session = calloc( sizeof( struct rewrite_session ), 1 );
       if ( session == NULL ) {
              return NULL;
       }
       session->ls_cookie = ( void * )cookie;
       session->ls_count = 1;
       
#ifdef USE_REWRITE_LDAP_PVT_THREADS
       if ( ldap_pvt_thread_mutex_init( &session->ls_mutex ) ) {
              free( session );
              return NULL;
       }
       if ( ldap_pvt_thread_rdwr_init( &session->ls_vars_mutex ) ) {
              ldap_pvt_thread_mutex_destroy( &session->ls_mutex );
              free( session );
              return NULL;
       }
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       rc = avl_insert( &info->li_cookies, ( caddr_t )session,
                     rewrite_cookie_cmp, rewrite_cookie_dup );
       info->li_num_cookies++;

#ifdef USE_REWRITE_LDAP_PVT_THREADS
        ldap_pvt_thread_rdwr_wunlock( &info->li_cookies_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
       
       if ( rc != 0 ) {
#ifdef USE_REWRITE_LDAP_PVT_THREADS
              ldap_pvt_thread_rdwr_destroy( &session->ls_vars_mutex );
              ldap_pvt_thread_mutex_destroy( &session->ls_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

              free( session );
              return NULL;
       }
       
       return session;
}

Here is the call graph for this function:

Here is the caller graph for this function:

rewrite_session_var_set_f ( struct rewrite_info info,
const void cookie,
const char *  name,
const char *  value,
int  flags 
)

Definition at line 188 of file session.c.

{
       struct rewrite_session *session;
       struct rewrite_var *var;

       assert( info != NULL );
       assert( cookie != NULL );
       assert( name != NULL );
       assert( value != NULL );

       session = rewrite_session_find( info, cookie );
       if ( session == NULL ) {
              session = rewrite_session_init( info, cookie );
              if ( session == NULL ) {
                     return REWRITE_ERR;
              }

#ifdef USE_REWRITE_LDAP_PVT_THREADS
              ldap_pvt_thread_mutex_lock( &session->ls_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
       }

#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_wlock( &session->ls_vars_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       var = rewrite_var_find( session->ls_vars, name );
       if ( var != NULL ) {
              assert( var->lv_value.bv_val != NULL );

              (void)rewrite_var_replace( var, value, flags );

       } else {
              var = rewrite_var_insert_f( &session->ls_vars, name, value, flags );
              if ( var == NULL ) {
#ifdef USE_REWRITE_LDAP_PVT_THREADS
                     ldap_pvt_thread_rdwr_wunlock( &session->ls_vars_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
                     rewrite_session_return( info, session );
                     return REWRITE_ERR;
              }
       }      
       
#ifdef USE_REWRITE_LDAP_PVT_THREADS
       ldap_pvt_thread_rdwr_wunlock( &session->ls_vars_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

       rewrite_session_return( info, session );

       return REWRITE_SUCCESS;
}