]> git.sur5r.net Git - openldap/blob - libraries/librewrite/params.c
Slapadd is changed to include Operational Attributes (entryUUID, entryCSN,
[openldap] / libraries / librewrite / params.c
1 /******************************************************************************
2  *
3  * Copyright (C) 2000 Pierangelo Masarati, <ando@sys-net.it>
4  * All rights reserved.
5  *
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:
9  *
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.
12  *
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.
16  *
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.
20  * 
21  * 4. This notice may not be removed or altered.
22  *
23  ******************************************************************************/
24
25 #include <portable.h>
26
27 #include "rewrite-int.h"
28
29 /*
30  * Defines and inits a variable with global scope
31  */
32 int
33 rewrite_param_set(
34                 struct rewrite_info *info,
35                 const char *name,
36                 const char *value
37 )
38 {
39         struct rewrite_var *var;
40
41         assert( info != NULL );
42         assert( name != NULL );
43         assert( value != NULL );
44
45 #ifdef USE_REWRITE_LDAP_PVT_THREADS
46         ldap_pvt_thread_rdwr_wlock( &info->li_params_mutex );
47 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
48
49         var = rewrite_var_find( info->li_params, name );
50         if ( var != NULL ) {
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 );
55         } else {
56                 var = rewrite_var_insert( &info->li_params, name, value );
57                 if ( var == NULL ) {
58 #ifdef USE_REWRITE_LDAP_PVT_THREADS
59                         ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
60 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
61                         return REWRITE_ERR;
62                 }
63         }       
64         
65 #ifdef USE_REWRITE_LDAP_PVT_THREADS
66         ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
67 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
68
69         return REWRITE_SUCCESS;
70 }
71
72 /*
73  * Gets a var with global scope
74  */
75 int
76 rewrite_param_get(
77                 struct rewrite_info *info,
78                 const char *name,
79                 struct berval *value
80 )
81 {
82         struct rewrite_var *var;
83
84         assert( info != NULL );
85         assert( name != NULL );
86         assert( value != NULL );
87
88         value->bv_val = NULL;
89         value->bv_len = 0;
90         
91 #ifdef USE_REWRITE_LDAP_PVT_THREADS
92         ldap_pvt_thread_rdwr_rlock( &info->li_params_mutex );
93 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
94         
95         var = rewrite_var_find( info->li_params, name );
96         if ( var == NULL ) {
97                 
98 #ifdef USE_REWRITE_LDAP_PVT_THREADS
99                 ldap_pvt_thread_rdwr_runlock( &info->li_params_mutex );
100 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
101                 
102                 return REWRITE_ERR;
103         } else {
104                 value->bv_val = strdup( var->lv_value.bv_val );
105                 value->bv_len = var->lv_value.bv_len;
106         }
107         
108 #ifdef USE_REWRITE_LDAP_PVT_THREADS
109         ldap_pvt_thread_rdwr_runlock( &info->li_params_mutex );
110 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
111         
112         return REWRITE_SUCCESS;
113 }
114
115 /*
116  * Destroys the parameter tree
117  */
118 int
119 rewrite_param_destroy(
120                 struct rewrite_info *info
121 )
122 {
123         int count;
124
125         assert( info != NULL );
126         
127 #ifdef USE_REWRITE_LDAP_PVT_THREADS
128         ldap_pvt_thread_rdwr_wlock( &info->li_params_mutex );
129 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
130         
131         count = avl_free( info->li_params, NULL );
132         info->li_params = NULL;
133
134 #ifdef USE_REWRITE_LDAP_PVT_THREADS
135         ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
136 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
137
138         return REWRITE_SUCCESS;
139 }
140