1 /* $OpenLDAP: pkg/ldap/libraries/librewrite/params.c,v 1.9.2.3 2008/02/11 23:26:42 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2000-2008 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
;
36 assert( info
!= NULL
);
37 assert( name
!= NULL
);
38 assert( value
!= NULL
);
40 #ifdef USE_REWRITE_LDAP_PVT_THREADS
41 ldap_pvt_thread_rdwr_wlock( &info
->li_params_mutex
);
42 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
44 var
= rewrite_var_find( info
->li_params
, name
);
46 assert( var
->lv_value
.bv_val
!= NULL
);
47 free( var
->lv_value
.bv_val
);
48 var
->lv_value
.bv_val
= strdup( value
);
49 var
->lv_value
.bv_len
= strlen( value
);
51 var
= rewrite_var_insert( &info
->li_params
, name
, value
);
53 #ifdef USE_REWRITE_LDAP_PVT_THREADS
54 ldap_pvt_thread_rdwr_wunlock( &info
->li_params_mutex
);
55 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
60 #ifdef USE_REWRITE_LDAP_PVT_THREADS
61 ldap_pvt_thread_rdwr_wunlock( &info
->li_params_mutex
);
62 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
64 return REWRITE_SUCCESS
;
68 * Gets a var with global scope
72 struct rewrite_info
*info
,
77 struct rewrite_var
*var
;
79 assert( info
!= NULL
);
80 assert( name
!= NULL
);
81 assert( value
!= NULL
);
86 #ifdef USE_REWRITE_LDAP_PVT_THREADS
87 ldap_pvt_thread_rdwr_rlock( &info
->li_params_mutex
);
88 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
90 var
= rewrite_var_find( info
->li_params
, name
);
93 #ifdef USE_REWRITE_LDAP_PVT_THREADS
94 ldap_pvt_thread_rdwr_runlock( &info
->li_params_mutex
);
95 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
99 value
->bv_val
= strdup( var
->lv_value
.bv_val
);
100 value
->bv_len
= var
->lv_value
.bv_len
;
103 #ifdef USE_REWRITE_LDAP_PVT_THREADS
104 ldap_pvt_thread_rdwr_runlock( &info
->li_params_mutex
);
105 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
107 return REWRITE_SUCCESS
;
115 struct rewrite_var
*var
= ( struct rewrite_var
* )tmp
;
116 assert( var
!= NULL
);
118 assert( var
->lv_name
!= NULL
);
119 assert( var
->lv_value
.bv_val
!= NULL
);
121 free( var
->lv_name
);
122 free( var
->lv_value
.bv_val
);
127 * Destroys the parameter tree
130 rewrite_param_destroy(
131 struct rewrite_info
*info
136 assert( info
!= NULL
);
138 #ifdef USE_REWRITE_LDAP_PVT_THREADS
139 ldap_pvt_thread_rdwr_wlock( &info
->li_params_mutex
);
140 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
142 count
= avl_free( info
->li_params
, rewrite_param_free
);
143 info
->li_params
= NULL
;
145 #ifdef USE_REWRITE_LDAP_PVT_THREADS
146 ldap_pvt_thread_rdwr_wunlock( &info
->li_params_mutex
);
147 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
149 return REWRITE_SUCCESS
;