1 /******************************************************************************
3 * Copyright (C) 2000 Pierangelo Masarati, <ando@sys-net.it>
6 * Permission is granted to anyone to use this software for any purpose
7 * on any computer system, and to alter it and redistribute it, subject
8 * to the following restrictions:
10 * 1. The author is not responsible for the consequences of use of this
11 * software, no matter how awful, even if they arise from flaws in it.
13 * 2. The origin of this software must not be misrepresented, either by
14 * explicit claim or by omission. Since few users ever read sources,
15 * credits should appear in the documentation.
17 * 3. Altered versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software. Since few users
19 * ever read sources, credits should appear in the documentation.
21 * 4. This notice may not be removed or altered.
23 ******************************************************************************/
27 #include "rewrite-int.h"
30 * Defines and inits a variable with global scope
34 struct rewrite_info *info,
39 struct rewrite_var *var;
41 assert( info != NULL );
42 assert( name != NULL );
43 assert( value != NULL );
45 #ifdef USE_REWRITE_LDAP_PVT_THREADS
46 ldap_pvt_thread_rdwr_wlock( &info->li_params_mutex );
47 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
49 var = rewrite_var_find( info->li_params, name );
51 assert( var->lv_value.bv_val != NULL );
52 free( var->lv_value.bv_val );
53 var->lv_value.bv_val = strdup( value );
54 var->lv_value.bv_len = strlen( value );
56 var = rewrite_var_insert( &info->li_params, name, value );
58 #ifdef USE_REWRITE_LDAP_PVT_THREADS
59 ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
60 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
65 #ifdef USE_REWRITE_LDAP_PVT_THREADS
66 ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
67 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
69 return REWRITE_SUCCESS;
73 * Gets a var with global scope
77 struct rewrite_info *info,
82 struct rewrite_var *var;
84 assert( info != NULL );
85 assert( name != NULL );
86 assert( value != NULL );
91 #ifdef USE_REWRITE_LDAP_PVT_THREADS
92 ldap_pvt_thread_rdwr_rlock( &info->li_params_mutex );
93 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
95 var = rewrite_var_find( info->li_params, name );
98 #ifdef USE_REWRITE_LDAP_PVT_THREADS
99 ldap_pvt_thread_rdwr_runlock( &info->li_params_mutex );
100 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
104 value->bv_val = strdup( var->lv_value.bv_val );
105 value->bv_len = var->lv_value.bv_len;
108 #ifdef USE_REWRITE_LDAP_PVT_THREADS
109 ldap_pvt_thread_rdwr_runlock( &info->li_params_mutex );
110 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
112 return REWRITE_SUCCESS;
116 * Destroys the parameter tree
119 rewrite_param_destroy(
120 struct rewrite_info *info
125 assert( info != NULL );
127 #ifdef USE_REWRITE_LDAP_PVT_THREADS
128 ldap_pvt_thread_rdwr_wlock( &info->li_params_mutex );
129 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
131 count = avl_free( info->li_params, NULL );
132 info->li_params = NULL;
134 #ifdef USE_REWRITE_LDAP_PVT_THREADS
135 ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
136 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
138 return REWRITE_SUCCESS;