diff options
Diffstat (limited to 'src/lib/libcrypto/objects/o_names.c')
-rw-r--r-- | src/lib/libcrypto/objects/o_names.c | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c index adb5731f76..84380a96a9 100644 --- a/src/lib/libcrypto/objects/o_names.c +++ b/src/lib/libcrypto/objects/o_names.c | |||
@@ -22,7 +22,8 @@ | |||
22 | /* I use the ex_data stuff to manage the identifiers for the obj_name_types | 22 | /* I use the ex_data stuff to manage the identifiers for the obj_name_types |
23 | * that applications may define. I only really use the free function field. | 23 | * that applications may define. I only really use the free function field. |
24 | */ | 24 | */ |
25 | static LHASH *names_lh=NULL; | 25 | DECLARE_LHASH_OF(OBJ_NAME); |
26 | static LHASH_OF(OBJ_NAME) *names_lh=NULL; | ||
26 | static int names_type_num=OBJ_NAME_TYPE_NUM; | 27 | static int names_type_num=OBJ_NAME_TYPE_NUM; |
27 | 28 | ||
28 | typedef struct name_funcs_st | 29 | typedef struct name_funcs_st |
@@ -46,11 +47,14 @@ static unsigned long obj_name_hash(const void *a_void); | |||
46 | /* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */ | 47 | /* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */ |
47 | static int obj_name_cmp(const void *a_void,const void *b_void); | 48 | static int obj_name_cmp(const void *a_void,const void *b_void); |
48 | 49 | ||
50 | static IMPLEMENT_LHASH_HASH_FN(obj_name, OBJ_NAME) | ||
51 | static IMPLEMENT_LHASH_COMP_FN(obj_name, OBJ_NAME) | ||
52 | |||
49 | int OBJ_NAME_init(void) | 53 | int OBJ_NAME_init(void) |
50 | { | 54 | { |
51 | if (names_lh != NULL) return(1); | 55 | if (names_lh != NULL) return(1); |
52 | MemCheck_off(); | 56 | MemCheck_off(); |
53 | names_lh=lh_new(obj_name_hash, obj_name_cmp); | 57 | names_lh=lh_OBJ_NAME_new(); |
54 | MemCheck_on(); | 58 | MemCheck_on(); |
55 | return(names_lh != NULL); | 59 | return(names_lh != NULL); |
56 | } | 60 | } |
@@ -164,7 +168,7 @@ const char *OBJ_NAME_get(const char *name, int type) | |||
164 | 168 | ||
165 | for (;;) | 169 | for (;;) |
166 | { | 170 | { |
167 | ret=(OBJ_NAME *)lh_retrieve(names_lh,&on); | 171 | ret=lh_OBJ_NAME_retrieve(names_lh,&on); |
168 | if (ret == NULL) return(NULL); | 172 | if (ret == NULL) return(NULL); |
169 | if ((ret->alias) && !alias) | 173 | if ((ret->alias) && !alias) |
170 | { | 174 | { |
@@ -200,7 +204,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data) | |||
200 | onp->type=type; | 204 | onp->type=type; |
201 | onp->data=data; | 205 | onp->data=data; |
202 | 206 | ||
203 | ret=(OBJ_NAME *)lh_insert(names_lh,onp); | 207 | ret=lh_OBJ_NAME_insert(names_lh,onp); |
204 | if (ret != NULL) | 208 | if (ret != NULL) |
205 | { | 209 | { |
206 | /* free things */ | 210 | /* free things */ |
@@ -217,7 +221,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data) | |||
217 | } | 221 | } |
218 | else | 222 | else |
219 | { | 223 | { |
220 | if (lh_error(names_lh)) | 224 | if (lh_OBJ_NAME_error(names_lh)) |
221 | { | 225 | { |
222 | /* ERROR */ | 226 | /* ERROR */ |
223 | return(0); | 227 | return(0); |
@@ -235,7 +239,7 @@ int OBJ_NAME_remove(const char *name, int type) | |||
235 | type&= ~OBJ_NAME_ALIAS; | 239 | type&= ~OBJ_NAME_ALIAS; |
236 | on.name=name; | 240 | on.name=name; |
237 | on.type=type; | 241 | on.type=type; |
238 | ret=(OBJ_NAME *)lh_delete(names_lh,&on); | 242 | ret=lh_OBJ_NAME_delete(names_lh,&on); |
239 | if (ret != NULL) | 243 | if (ret != NULL) |
240 | { | 244 | { |
241 | /* free things */ | 245 | /* free things */ |
@@ -262,13 +266,13 @@ struct doall | |||
262 | void *arg; | 266 | void *arg; |
263 | }; | 267 | }; |
264 | 268 | ||
265 | static void do_all_fn(const OBJ_NAME *name,struct doall *d) | 269 | static void do_all_fn_doall_arg(const OBJ_NAME *name,struct doall *d) |
266 | { | 270 | { |
267 | if(name->type == d->type) | 271 | if(name->type == d->type) |
268 | d->fn(name,d->arg); | 272 | d->fn(name,d->arg); |
269 | } | 273 | } |
270 | 274 | ||
271 | static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME *, struct doall *) | 275 | static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME, struct doall) |
272 | 276 | ||
273 | void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg) | 277 | void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg) |
274 | { | 278 | { |
@@ -278,7 +282,8 @@ void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg) | |||
278 | d.fn=fn; | 282 | d.fn=fn; |
279 | d.arg=arg; | 283 | d.arg=arg; |
280 | 284 | ||
281 | lh_doall_arg(names_lh,LHASH_DOALL_ARG_FN(do_all_fn),&d); | 285 | lh_OBJ_NAME_doall_arg(names_lh, LHASH_DOALL_ARG_FN(do_all_fn), |
286 | struct doall, &d); | ||
282 | } | 287 | } |
283 | 288 | ||
284 | struct doall_sorted | 289 | struct doall_sorted |
@@ -313,7 +318,7 @@ void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg), | |||
313 | int n; | 318 | int n; |
314 | 319 | ||
315 | d.type=type; | 320 | d.type=type; |
316 | d.names=OPENSSL_malloc(lh_num_items(names_lh)*sizeof *d.names); | 321 | d.names=OPENSSL_malloc(lh_OBJ_NAME_num_items(names_lh)*sizeof *d.names); |
317 | d.n=0; | 322 | d.n=0; |
318 | OBJ_NAME_do_all(type,do_all_sorted_fn,&d); | 323 | OBJ_NAME_do_all(type,do_all_sorted_fn,&d); |
319 | 324 | ||
@@ -327,18 +332,16 @@ void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg), | |||
327 | 332 | ||
328 | static int free_type; | 333 | static int free_type; |
329 | 334 | ||
330 | static void names_lh_free(OBJ_NAME *onp) | 335 | static void names_lh_free_doall(OBJ_NAME *onp) |
331 | { | 336 | { |
332 | if(onp == NULL) | 337 | if (onp == NULL) |
333 | return; | 338 | return; |
334 | 339 | ||
335 | if ((free_type < 0) || (free_type == onp->type)) | 340 | if (free_type < 0 || free_type == onp->type) |
336 | { | ||
337 | OBJ_NAME_remove(onp->name,onp->type); | 341 | OBJ_NAME_remove(onp->name,onp->type); |
338 | } | ||
339 | } | 342 | } |
340 | 343 | ||
341 | static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME *) | 344 | static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME) |
342 | 345 | ||
343 | static void name_funcs_free(NAME_FUNCS *ptr) | 346 | static void name_funcs_free(NAME_FUNCS *ptr) |
344 | { | 347 | { |
@@ -352,18 +355,18 @@ void OBJ_NAME_cleanup(int type) | |||
352 | if (names_lh == NULL) return; | 355 | if (names_lh == NULL) return; |
353 | 356 | ||
354 | free_type=type; | 357 | free_type=type; |
355 | down_load=names_lh->down_load; | 358 | down_load=lh_OBJ_NAME_down_load(names_lh); |
356 | names_lh->down_load=0; | 359 | lh_OBJ_NAME_down_load(names_lh)=0; |
357 | 360 | ||
358 | lh_doall(names_lh,LHASH_DOALL_FN(names_lh_free)); | 361 | lh_OBJ_NAME_doall(names_lh,LHASH_DOALL_FN(names_lh_free)); |
359 | if (type < 0) | 362 | if (type < 0) |
360 | { | 363 | { |
361 | lh_free(names_lh); | 364 | lh_OBJ_NAME_free(names_lh); |
362 | sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free); | 365 | sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free); |
363 | names_lh=NULL; | 366 | names_lh=NULL; |
364 | name_funcs_stack = NULL; | 367 | name_funcs_stack = NULL; |
365 | } | 368 | } |
366 | else | 369 | else |
367 | names_lh->down_load=down_load; | 370 | lh_OBJ_NAME_down_load(names_lh)=down_load; |
368 | } | 371 | } |
369 | 372 | ||