conf_api.c (237657) | conf_api.c (238405) |
---|---|
1/* conf_api.c */ 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 * All rights reserved. 4 * 5 * This package is an SSL implementation written 6 * by Eric Young (eay@cryptsoft.com). 7 * The implementation was written so as to conform with Netscapes SSL. 8 * --- 56 unchanged lines hidden (view full) --- 65 66#include <assert.h> 67#include <stdlib.h> 68#include <string.h> 69#include <openssl/conf.h> 70#include <openssl/conf_api.h> 71#include "e_os.h" 72 | 1/* conf_api.c */ 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 * All rights reserved. 4 * 5 * This package is an SSL implementation written 6 * by Eric Young (eay@cryptsoft.com). 7 * The implementation was written so as to conform with Netscapes SSL. 8 * --- 56 unchanged lines hidden (view full) --- 65 66#include <assert.h> 67#include <stdlib.h> 68#include <string.h> 69#include <openssl/conf.h> 70#include <openssl/conf_api.h> 71#include "e_os.h" 72 |
73static void value_free_hash(CONF_VALUE *a, LHASH *conf); 74static void value_free_stack(CONF_VALUE *a,LHASH *conf); 75static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE *, LHASH *) 76static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_stack, CONF_VALUE *, LHASH *) 77/* We don't use function pointer casting or wrapper functions - but cast each 78 * callback parameter inside the callback functions. */ 79/* static unsigned long hash(CONF_VALUE *v); */ 80static unsigned long hash(const void *v_void); 81/* static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); */ 82static int cmp_conf(const void *a_void,const void *b_void); | 73static void value_free_hash_doall_arg(CONF_VALUE *a, 74 LHASH_OF(CONF_VALUE) *conf); 75static void value_free_stack_doall(CONF_VALUE *a); 76static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE, 77 LHASH_OF(CONF_VALUE)) 78static IMPLEMENT_LHASH_DOALL_FN(value_free_stack, CONF_VALUE) |
83 84/* Up until OpenSSL 0.9.5a, this was get_section */ 85CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section) 86 { 87 CONF_VALUE *v,vv; 88 89 if ((conf == NULL) || (section == NULL)) return(NULL); 90 vv.name=NULL; 91 vv.section=(char *)section; | 79 80/* Up until OpenSSL 0.9.5a, this was get_section */ 81CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section) 82 { 83 CONF_VALUE *v,vv; 84 85 if ((conf == NULL) || (section == NULL)) return(NULL); 86 vv.name=NULL; 87 vv.section=(char *)section; |
92 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); | 88 v=lh_CONF_VALUE_retrieve(conf->data,&vv); |
93 return(v); 94 } 95 96/* Up until OpenSSL 0.9.5a, this was CONF_get_section */ 97STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf, 98 const char *section) 99 { 100 CONF_VALUE *v; --- 13 unchanged lines hidden (view full) --- 114 ts = (STACK_OF(CONF_VALUE) *)section->value; 115 116 value->section=section->section; 117 if (!sk_CONF_VALUE_push(ts,value)) 118 { 119 return 0; 120 } 121 | 89 return(v); 90 } 91 92/* Up until OpenSSL 0.9.5a, this was CONF_get_section */ 93STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf, 94 const char *section) 95 { 96 CONF_VALUE *v; --- 13 unchanged lines hidden (view full) --- 110 ts = (STACK_OF(CONF_VALUE) *)section->value; 111 112 value->section=section->section; 113 if (!sk_CONF_VALUE_push(ts,value)) 114 { 115 return 0; 116 } 117 |
122 v = (CONF_VALUE *)lh_insert(conf->data, value); | 118 v = lh_CONF_VALUE_insert(conf->data, value); |
123 if (v != NULL) 124 { 125 (void)sk_CONF_VALUE_delete_ptr(ts,v); 126 OPENSSL_free(v->name); 127 OPENSSL_free(v->value); 128 OPENSSL_free(v); 129 } 130 return 1; --- 6 unchanged lines hidden (view full) --- 137 138 if (name == NULL) return(NULL); 139 if (conf != NULL) 140 { 141 if (section != NULL) 142 { 143 vv.name=(char *)name; 144 vv.section=(char *)section; | 119 if (v != NULL) 120 { 121 (void)sk_CONF_VALUE_delete_ptr(ts,v); 122 OPENSSL_free(v->name); 123 OPENSSL_free(v->value); 124 OPENSSL_free(v); 125 } 126 return 1; --- 6 unchanged lines hidden (view full) --- 133 134 if (name == NULL) return(NULL); 135 if (conf != NULL) 136 { 137 if (section != NULL) 138 { 139 vv.name=(char *)name; 140 vv.section=(char *)section; |
145 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); | 141 v=lh_CONF_VALUE_retrieve(conf->data,&vv); |
146 if (v != NULL) return(v->value); 147 if (strcmp(section,"ENV") == 0) 148 { | 142 if (v != NULL) return(v->value); 143 if (strcmp(section,"ENV") == 0) 144 { |
149 p=Getenv(name); | 145 p=getenv(name); |
150 if (p != NULL) return(p); 151 } 152 } 153 vv.section="default"; 154 vv.name=(char *)name; | 146 if (p != NULL) return(p); 147 } 148 } 149 vv.section="default"; 150 vv.name=(char *)name; |
155 v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); | 151 v=lh_CONF_VALUE_retrieve(conf->data,&vv); |
156 if (v != NULL) 157 return(v->value); 158 else 159 return(NULL); 160 } 161 else | 152 if (v != NULL) 153 return(v->value); 154 else 155 return(NULL); 156 } 157 else |
162 return(Getenv(name)); | 158 return(getenv(name)); |
163 } 164 165#if 0 /* There's no way to provide error checking with this function, so 166 force implementors of the higher levels to get a string and read 167 the number themselves. */ 168long _CONF_get_number(CONF *conf, char *section, char *name) 169 { 170 char *str; --- 7 unchanged lines hidden (view full) --- 178 ret=ret*10+conf->meth->to_int(conf, *str); 179 else 180 return(ret); 181 str++; 182 } 183 } 184#endif 185 | 159 } 160 161#if 0 /* There's no way to provide error checking with this function, so 162 force implementors of the higher levels to get a string and read 163 the number themselves. */ 164long _CONF_get_number(CONF *conf, char *section, char *name) 165 { 166 char *str; --- 7 unchanged lines hidden (view full) --- 174 ret=ret*10+conf->meth->to_int(conf, *str); 175 else 176 return(ret); 177 str++; 178 } 179 } 180#endif 181 |
182static unsigned long conf_value_hash(const CONF_VALUE *v) 183 { 184 return (lh_strhash(v->section)<<2)^lh_strhash(v->name); 185 } 186static IMPLEMENT_LHASH_HASH_FN(conf_value, CONF_VALUE) 187 188static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) 189 { 190 int i; 191 192 if (a->section != b->section) 193 { 194 i=strcmp(a->section,b->section); 195 if (i) return(i); 196 } 197 198 if ((a->name != NULL) && (b->name != NULL)) 199 { 200 i=strcmp(a->name,b->name); 201 return(i); 202 } 203 else if (a->name == b->name) 204 return(0); 205 else 206 return((a->name == NULL)?-1:1); 207 } 208static IMPLEMENT_LHASH_COMP_FN(conf_value, CONF_VALUE) 209 |
|
186int _CONF_new_data(CONF *conf) 187 { 188 if (conf == NULL) 189 { 190 return 0; 191 } 192 if (conf->data == NULL) | 210int _CONF_new_data(CONF *conf) 211 { 212 if (conf == NULL) 213 { 214 return 0; 215 } 216 if (conf->data == NULL) |
193 if ((conf->data = lh_new(hash, cmp_conf)) == NULL) | 217 if ((conf->data = lh_CONF_VALUE_new()) == NULL) |
194 { 195 return 0; 196 } 197 return 1; 198 } 199 200void _CONF_free_data(CONF *conf) 201 { 202 if (conf == NULL || conf->data == NULL) return; 203 | 218 { 219 return 0; 220 } 221 return 1; 222 } 223 224void _CONF_free_data(CONF *conf) 225 { 226 if (conf == NULL || conf->data == NULL) return; 227 |
204 conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()' 205 * works as expected */ 206 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_hash), 207 conf->data); | 228 lh_CONF_VALUE_down_load(conf->data)=0; /* evil thing to make 229 * sure the 'OPENSSL_free()' works as 230 * expected */ 231 lh_CONF_VALUE_doall_arg(conf->data, 232 LHASH_DOALL_ARG_FN(value_free_hash), 233 LHASH_OF(CONF_VALUE), conf->data); |
208 209 /* We now have only 'section' entries in the hash table. 210 * Due to problems with */ 211 | 234 235 /* We now have only 'section' entries in the hash table. 236 * Due to problems with */ 237 |
212 lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_stack), 213 conf->data); 214 lh_free(conf->data); | 238 lh_CONF_VALUE_doall(conf->data, LHASH_DOALL_FN(value_free_stack)); 239 lh_CONF_VALUE_free(conf->data); |
215 } 216 | 240 } 241 |
217static void value_free_hash(CONF_VALUE *a, LHASH *conf) | 242static void value_free_hash_doall_arg(CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf) |
218 { 219 if (a->name != NULL) | 243 { 244 if (a->name != NULL) |
220 { 221 a=(CONF_VALUE *)lh_delete(conf,a); 222 } | 245 (void)lh_CONF_VALUE_delete(conf,a); |
223 } 224 | 246 } 247 |
225static void value_free_stack(CONF_VALUE *a, LHASH *conf) | 248static void value_free_stack_doall(CONF_VALUE *a) |
226 { 227 CONF_VALUE *vv; | 249 { 250 CONF_VALUE *vv; |
228 STACK *sk; | 251 STACK_OF(CONF_VALUE) *sk; |
229 int i; 230 231 if (a->name != NULL) return; 232 | 252 int i; 253 254 if (a->name != NULL) return; 255 |
233 sk=(STACK *)a->value; 234 for (i=sk_num(sk)-1; i>=0; i--) | 256 sk=(STACK_OF(CONF_VALUE) *)a->value; 257 for (i=sk_CONF_VALUE_num(sk)-1; i>=0; i--) |
235 { | 258 { |
236 vv=(CONF_VALUE *)sk_value(sk,i); | 259 vv=sk_CONF_VALUE_value(sk,i); |
237 OPENSSL_free(vv->value); 238 OPENSSL_free(vv->name); 239 OPENSSL_free(vv); 240 } | 260 OPENSSL_free(vv->value); 261 OPENSSL_free(vv->name); 262 OPENSSL_free(vv); 263 } |
241 if (sk != NULL) sk_free(sk); | 264 if (sk != NULL) sk_CONF_VALUE_free(sk); |
242 OPENSSL_free(a->section); 243 OPENSSL_free(a); 244 } 245 | 265 OPENSSL_free(a->section); 266 OPENSSL_free(a); 267 } 268 |
246/* static unsigned long hash(CONF_VALUE *v) */ 247static unsigned long hash(const void *v_void) 248 { 249 CONF_VALUE *v = (CONF_VALUE *)v_void; 250 return((lh_strhash(v->section)<<2)^lh_strhash(v->name)); 251 } 252 253/* static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) */ 254static int cmp_conf(const void *a_void,const void *b_void) 255 { 256 int i; 257 CONF_VALUE *a = (CONF_VALUE *)a_void; 258 CONF_VALUE *b = (CONF_VALUE *)b_void; 259 260 if (a->section != b->section) 261 { 262 i=strcmp(a->section,b->section); 263 if (i) return(i); 264 } 265 266 if ((a->name != NULL) && (b->name != NULL)) 267 { 268 i=strcmp(a->name,b->name); 269 return(i); 270 } 271 else if (a->name == b->name) 272 return(0); 273 else 274 return((a->name == NULL)?-1:1); 275 } 276 | |
277/* Up until OpenSSL 0.9.5a, this was new_section */ 278CONF_VALUE *_CONF_new_section(CONF *conf, const char *section) 279 { | 269/* Up until OpenSSL 0.9.5a, this was new_section */ 270CONF_VALUE *_CONF_new_section(CONF *conf, const char *section) 271 { |
280 STACK *sk=NULL; | 272 STACK_OF(CONF_VALUE) *sk=NULL; |
281 int ok=0,i; 282 CONF_VALUE *v=NULL,*vv; 283 | 273 int ok=0,i; 274 CONF_VALUE *v=NULL,*vv; 275 |
284 if ((sk=sk_new_null()) == NULL) | 276 if ((sk=sk_CONF_VALUE_new_null()) == NULL) |
285 goto err; | 277 goto err; |
286 if ((v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL) | 278 if ((v=OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL) |
287 goto err; 288 i=strlen(section)+1; | 279 goto err; 280 i=strlen(section)+1; |
289 if ((v->section=(char *)OPENSSL_malloc(i)) == NULL) | 281 if ((v->section=OPENSSL_malloc(i)) == NULL) |
290 goto err; 291 292 memcpy(v->section,section,i); 293 v->name=NULL; 294 v->value=(char *)sk; 295 | 282 goto err; 283 284 memcpy(v->section,section,i); 285 v->name=NULL; 286 v->value=(char *)sk; 287 |
296 vv=(CONF_VALUE *)lh_insert(conf->data,v); 297 assert(vv == NULL); | 288 vv=lh_CONF_VALUE_insert(conf->data,v); 289 OPENSSL_assert(vv == NULL); |
298 ok=1; 299err: 300 if (!ok) 301 { | 290 ok=1; 291err: 292 if (!ok) 293 { |
302 if (sk != NULL) sk_free(sk); | 294 if (sk != NULL) sk_CONF_VALUE_free(sk); |
303 if (v != NULL) OPENSSL_free(v); 304 v=NULL; 305 } 306 return(v); 307 } 308 309IMPLEMENT_STACK_OF(CONF_VALUE) | 295 if (v != NULL) OPENSSL_free(v); 296 v=NULL; 297 } 298 return(v); 299 } 300 301IMPLEMENT_STACK_OF(CONF_VALUE) |