2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2000-2012 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This work was initially developed by Pierangelo Masarati for
17 * inclusion in OpenLDAP Software.
22 #include "rewrite-int.h"
25 * Defines and inits a variable with global scope
29 struct rewrite_info *info,
34 struct rewrite_var *var;
35 int rc = REWRITE_SUCCESS;
37 assert( info != NULL );
38 assert( name != NULL );
39 assert( value != NULL );
41 #ifdef USE_REWRITE_LDAP_PVT_THREADS
42 ldap_pvt_thread_rdwr_wlock( &info->li_params_mutex );
43 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
45 var = rewrite_var_find( info->li_params, name );
47 assert( var->lv_value.bv_val != NULL );
48 free( var->lv_value.bv_val );
49 var->lv_value.bv_val = strdup( value );
50 var->lv_value.bv_len = strlen( value );
53 var = rewrite_var_insert( &info->li_params, name, value );
56 if ( var == NULL || var->lv_value.bv_val == NULL ) {
60 #ifdef USE_REWRITE_LDAP_PVT_THREADS
61 ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
62 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
68 * Gets a var with global scope
72 struct rewrite_info *info,
77 struct rewrite_var *var;
78 int rc = REWRITE_SUCCESS;
80 assert( info != NULL );
81 assert( name != NULL );
82 assert( value != NULL );
87 #ifdef USE_REWRITE_LDAP_PVT_THREADS
88 ldap_pvt_thread_rdwr_rlock( &info->li_params_mutex );
89 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
91 var = rewrite_var_find( info->li_params, name );
93 value->bv_val = strdup( var->lv_value.bv_val );
94 value->bv_len = var->lv_value.bv_len;
97 if ( var == NULL || value->bv_val == NULL ) {
101 #ifdef USE_REWRITE_LDAP_PVT_THREADS
102 ldap_pvt_thread_rdwr_runlock( &info->li_params_mutex );
103 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
105 return REWRITE_SUCCESS;
113 struct rewrite_var *var = ( struct rewrite_var * )tmp;
114 assert( var != NULL );
116 assert( var->lv_name != NULL );
117 assert( var->lv_value.bv_val != NULL );
119 free( var->lv_name );
120 free( var->lv_value.bv_val );
125 * Destroys the parameter tree
128 rewrite_param_destroy(
129 struct rewrite_info *info
134 assert( info != NULL );
136 #ifdef USE_REWRITE_LDAP_PVT_THREADS
137 ldap_pvt_thread_rdwr_wlock( &info->li_params_mutex );
138 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
140 count = avl_free( info->li_params, rewrite_param_free );
141 info->li_params = NULL;
143 #ifdef USE_REWRITE_LDAP_PVT_THREADS
144 ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
145 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
147 return REWRITE_SUCCESS;