Merge in code from main trunk to BRANCH_engine.

This commit is contained in:
Richard Levitte
2000-06-08 11:00:37 +00:00
parent 5decfb7002
commit d44c7dcf00
280 changed files with 2808 additions and 2009 deletions

View File

@@ -57,6 +57,8 @@
#include <openssl/stack.h>
#ifdef DEBUG_SAFESTACK
#define STACK_OF(type) struct stack_st_##type
#define PREDECLARE_STACK_OF(type) STACK_OF(type);
@@ -65,7 +67,8 @@ STACK_OF(type) \
{ \
STACK stack; \
}; \
STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)); \
STACK_OF(type) *sk_##type##_new(int (*cmp)(const type * const *, \
const type * const *)); \
STACK_OF(type) *sk_##type##_new_null(void); \
void sk_##type##_free(STACK_OF(type) *sk); \
int sk_##type##_num(const STACK_OF(type) *sk); \
@@ -76,10 +79,11 @@ int sk_##type##_push(STACK_OF(type) *sk,type *v); \
int sk_##type##_unshift(STACK_OF(type) *sk,type *v); \
int sk_##type##_find(STACK_OF(type) *sk,type *v); \
type *sk_##type##_delete(STACK_OF(type) *sk,int n); \
void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v); \
type *sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v); \
int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n); \
int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \
int (*cmp)(type **,type **)))(type **,type **); \
int (*cmp)(const type * const *,const type * const *))) \
(const type * const *,const type * const *); \
STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk); \
void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)); \
type *sk_##type##_shift(STACK_OF(type) *sk); \
@@ -87,8 +91,10 @@ type *sk_##type##_pop(STACK_OF(type) *sk); \
void sk_##type##_sort(STACK_OF(type) *sk);
#define IMPLEMENT_STACK_OF(type) \
STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)) \
{ return (STACK_OF(type) *)sk_new((int (*)())cmp); } \
STACK_OF(type) *sk_##type##_new(int (*cmp)(const type * const *, \
const type * const *)) \
{ return (STACK_OF(type) *)sk_new( \
(int (*)(const char * const *,const char * const *))cmp); } \
STACK_OF(type) *sk_##type##_new_null() \
{ return (STACK_OF(type) *)sk_new_null(); } \
void sk_##type##_free(STACK_OF(type) *sk) \
@@ -109,13 +115,15 @@ int sk_##type##_find(STACK_OF(type) *sk,type *v) \
{ return sk_find((STACK *)sk,(char *)v); } \
type *sk_##type##_delete(STACK_OF(type) *sk,int n) \
{ return (type *)sk_delete((STACK *)sk,n); } \
void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v) \
{ sk_delete_ptr((STACK *)sk,(char *)v); } \
type *sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v) \
{ return (type *)sk_delete_ptr((STACK *)sk,(char *)v); } \
int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n) \
{ return sk_insert((STACK *)sk,(char *)v,n); } \
int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \
int (*cmp)(type **,type **)))(type **,type **) \
{ return (int (*)(type **,type **))sk_set_cmp_func((STACK *)sk,(int(*)(const void *, const void *))cmp); } \
int (*cmp)(const type * const *,const type * const *))) \
(const type * const *,const type * const *) \
{ return (int (*)(const type * const *,const type * const *))sk_set_cmp_func( \
(STACK *)sk, (int(*)(const char * const *, const char * const *))cmp); } \
STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk) \
{ return (STACK_OF(type) *)sk_dup((STACK *)sk); } \
void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)) \
@@ -127,4 +135,13 @@ type *sk_##type##_pop(STACK_OF(type) *sk) \
void sk_##type##_sort(STACK_OF(type) *sk) \
{ sk_sort((STACK *)sk); }
#else
#define STACK_OF(type) STACK
#define PREDECLARE_STACK_OF(type) /* nada */
#define DECLARE_STACK_OF(type) /* nada */
#define IMPLEMENT_STACK_OF(type) /* nada */
#endif
#endif /* ndef HEADER_SAFESTACK_H */

View File

@@ -76,9 +76,10 @@ const char *STACK_version="Stack" OPENSSL_VERSION_PTEXT;
#include <errno.h>
int (*sk_set_cmp_func(STACK *sk, int (*c)(const void *,const void *)))(const void *, const void *)
int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,const char * const *)))
(const char * const *, const char * const *)
{
int (*old)(const void *,const void *)=sk->comp;
int (*old)(const char * const *,const char * const *)=sk->comp;
if (sk->comp != c)
sk->sorted=0;
@@ -93,7 +94,7 @@ STACK *sk_dup(STACK *sk)
char **s;
if ((ret=sk_new(sk->comp)) == NULL) goto err;
s=(char **)Realloc((char *)ret->data,
s=(char **)OPENSSL_realloc((char *)ret->data,
(unsigned int)sizeof(char *)*sk->num_alloc);
if (s == NULL) goto err;
ret->data=s;
@@ -108,14 +109,14 @@ err:
return(NULL);
}
STACK *sk_new(int (*c)(const void *, const void *))
STACK *sk_new(int (*c)(const char * const *, const char * const *))
{
STACK *ret;
int i;
if ((ret=(STACK *)Malloc(sizeof(STACK))) == NULL)
if ((ret=(STACK *)OPENSSL_malloc(sizeof(STACK))) == NULL)
goto err0;
if ((ret->data=(char **)Malloc(sizeof(char *)*MIN_NODES)) == NULL)
if ((ret->data=(char **)OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)
goto err1;
for (i=0; i<MIN_NODES; i++)
ret->data[i]=NULL;
@@ -125,7 +126,7 @@ STACK *sk_new(int (*c)(const void *, const void *))
ret->sorted=0;
return(ret);
err1:
Free(ret);
OPENSSL_free(ret);
err0:
return(NULL);
}
@@ -137,7 +138,7 @@ int sk_insert(STACK *st, char *data, int loc)
if(st == NULL) return 0;
if (st->num_alloc <= st->num+1)
{
s=(char **)Realloc((char *)st->data,
s=(char **)OPENSSL_realloc((char *)st->data,
(unsigned int)sizeof(char *)*st->num_alloc*2);
if (s == NULL)
return(0);
@@ -218,13 +219,24 @@ int sk_find(STACK *st, char *data)
}
sk_sort(st);
if (data == NULL) return(-1);
comp_func=st->comp;
/* This (and the "qsort" below) are the two places in OpenSSL
* where we need to convert from our standard (type **,type **)
* compare callback type to the (void *,void *) type required by
* bsearch. However, the "data" it is being called(back) with are
* not (type *) pointers, but the *pointers* to (type *) pointers,
* so we get our extra level of pointer dereferencing that way. */
comp_func=(int (*)(const void *,const void *))(st->comp);
r=(char **)bsearch(&data,(char *)st->data,
st->num,sizeof(char *), comp_func);
if (r == NULL) return(-1);
i=(int)(r-st->data);
for ( ; i>0; i--)
if ((*st->comp)(&(st->data[i-1]),&data) < 0)
/* This needs a cast because the type being pointed to from
* the "&" expressions are (char *) rather than (const char *).
* For an explanation, read:
* http://www.eskimo.com/~scs/C-faq/q11.10.html :-) */
if ((*st->comp)((const char * const *)&(st->data[i-1]),
(const char * const *)&data) < 0)
break;
return(i);
}
@@ -275,17 +287,17 @@ void sk_pop_free(STACK *st, void (*func)(void *))
void sk_free(STACK *st)
{
if (st == NULL) return;
if (st->data != NULL) Free(st->data);
Free(st);
if (st->data != NULL) OPENSSL_free(st->data);
OPENSSL_free(st);
}
int sk_num(STACK *st)
int sk_num(const STACK *st)
{
if(st == NULL) return -1;
return st->num;
}
char *sk_value(STACK *st, int i)
char *sk_value(const STACK *st, int i)
{
if(st == NULL) return NULL;
return st->data[i];
@@ -303,7 +315,12 @@ void sk_sort(STACK *st)
{
int (*comp_func)(const void *,const void *);
comp_func=st->comp;
/* same comment as in sk_find ... previously st->comp was declared
* as a (void*,void*) callback type, but this made the population
* of the callback pointer illogical - our callbacks compare
* type** with type**, so we leave the casting until absolutely
* necessary (ie. "now"). */
comp_func=(int (*)(const void *,const void *))(st->comp);
qsort(st->data,st->num,sizeof(char *), comp_func);
st->sorted=1;
}

View File

@@ -70,21 +70,21 @@ typedef struct stack_st
int sorted;
int num_alloc;
int (*comp)(const void *, const void *);
int (*comp)(const char * const *, const char * const *);
} STACK;
#define sk_new_null() sk_new(NULL)
#define sk_new_null() sk_new((int (*)(const char * const *, \
const char * const *))NULL)
#define M_sk_num(sk) ((sk) ? (sk)->num:-1)
#define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL)
int sk_num(STACK *);
char *sk_value(STACK *, int);
int sk_num(const STACK *);
char *sk_value(const STACK *, int);
char *sk_set(STACK *, int, char *);
STACK *sk_new(int (*cmp)(const void *, const void *));
STACK *sk_new(int (*cmp)(const char * const *, const char * const *));
void sk_free(STACK *);
void sk_pop_free(STACK *st, void (*func)(void *));
int sk_insert(STACK *sk,char *data,int where);
@@ -96,7 +96,9 @@ int sk_unshift(STACK *st,char *data);
char *sk_shift(STACK *st);
char *sk_pop(STACK *st);
void sk_zero(STACK *st);
int (*sk_set_cmp_func(STACK *sk, int (*c)(const void *,const void *)))(const void *, const void *);
int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,
const char * const *)))
(const char * const *, const char * const *);
STACK *sk_dup(STACK *st);
void sk_sort(STACK *st);