No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / openldap / dist / libraries / librewrite / params.c
blob09bc077dc59b4481addc3abfb2659a772bd88a26
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.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
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>.
15 /* ACKNOWLEDGEMENT:
16 * This work was initially developed by Pierangelo Masarati for
17 * inclusion in OpenLDAP Software.
20 #include <portable.h>
22 #include "rewrite-int.h"
25 * Defines and inits a variable with global scope
27 int
28 rewrite_param_set(
29 struct rewrite_info *info,
30 const char *name,
31 const char *value
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 );
45 if ( var != NULL ) {
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 );
50 } else {
51 var = rewrite_var_insert( &info->li_params, name, value );
52 if ( var == NULL ) {
53 #ifdef USE_REWRITE_LDAP_PVT_THREADS
54 ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
55 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
56 return REWRITE_ERR;
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
70 int
71 rewrite_param_get(
72 struct rewrite_info *info,
73 const char *name,
74 struct berval *value
77 struct rewrite_var *var;
79 assert( info != NULL );
80 assert( name != NULL );
81 assert( value != NULL );
83 value->bv_val = NULL;
84 value->bv_len = 0;
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 );
91 if ( var == NULL ) {
93 #ifdef USE_REWRITE_LDAP_PVT_THREADS
94 ldap_pvt_thread_rdwr_runlock( &info->li_params_mutex );
95 #endif /* USE_REWRITE_LDAP_PVT_THREADS */
97 return REWRITE_ERR;
98 } else {
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;
110 static void
111 rewrite_param_free(
112 void *tmp
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 );
123 free( var );
127 * Destroys the parameter tree
130 rewrite_param_destroy(
131 struct rewrite_info *info
134 int count;
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;