提交 8b8d963d 编写于 作者: R Rich Salz

Add BIO_get_new_index()

Reviewed-by: NDr. Stephen Henson <steve@openssl.org>
上级 9e313563
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <ctype.h> #include <ctype.h>
CRYPTO_RWLOCK *bio_lookup_lock; CRYPTO_RWLOCK *bio_lookup_lock;
extern CRYPTO_RWLOCK *bio_type_lock;
static CRYPTO_ONCE bio_lookup_init = CRYPTO_ONCE_STATIC_INIT; static CRYPTO_ONCE bio_lookup_init = CRYPTO_ONCE_STATIC_INIT;
/* /*
...@@ -605,7 +606,8 @@ static int addrinfo_wrap(int family, int socktype, ...@@ -605,7 +606,8 @@ static int addrinfo_wrap(int family, int socktype,
DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init) DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init)
{ {
bio_lookup_lock = CRYPTO_THREAD_lock_new(); bio_lookup_lock = CRYPTO_THREAD_lock_new();
return (bio_lookup_lock != NULL); bio_type_lock = CRYPTO_THREAD_lock_new();
return bio_lookup_lock != NULL && bio_type_lock != NULL;
} }
/*- /*-
......
...@@ -137,6 +137,7 @@ typedef unsigned int socklen_t; ...@@ -137,6 +137,7 @@ typedef unsigned int socklen_t;
# endif # endif
extern CRYPTO_RWLOCK *bio_lookup_lock; extern CRYPTO_RWLOCK *bio_lookup_lock;
extern CRYPTO_RWLOCK *bio_type_lock;
int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa); int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa);
const struct sockaddr *BIO_ADDR_sockaddr(const BIO_ADDR *ap); const struct sockaddr *BIO_ADDR_sockaddr(const BIO_ADDR *ap);
......
...@@ -594,5 +594,7 @@ void bio_cleanup(void) ...@@ -594,5 +594,7 @@ void bio_cleanup(void)
bio_sock_cleanup_int(); bio_sock_cleanup_int();
CRYPTO_THREAD_lock_free(bio_lookup_lock); CRYPTO_THREAD_lock_free(bio_lookup_lock);
bio_lookup_lock = NULL; bio_lookup_lock = NULL;
CRYPTO_THREAD_lock_free(bio_type_lock);
bio_type_lock = NULL;
#endif #endif
} }
...@@ -9,6 +9,18 @@ ...@@ -9,6 +9,18 @@
#include "bio_lcl.h" #include "bio_lcl.h"
CRYPTO_RWLOCK *bio_type_lock;
static int bio_count = BIO_TYPE_START;
int BIO_get_new_index()
{
int newval;
if (!CRYPTO_atomic_add(&bio_count, 1, &newval, bio_type_lock))
return -1;
return newval;
}
BIO_METHOD *BIO_meth_new(int type, const char *name) BIO_METHOD *BIO_meth_new(int type, const char *name)
{ {
BIO_METHOD *biom = OPENSSL_zalloc(sizeof(BIO_METHOD)); BIO_METHOD *biom = OPENSSL_zalloc(sizeof(BIO_METHOD));
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
=head1 NAME =head1 NAME
BIO_get_new_index,
BIO_meth_new, BIO_meth_free, BIO_meth_get_write, BIO_meth_set_write, BIO_meth_new, BIO_meth_free, BIO_meth_get_write, BIO_meth_set_write,
BIO_meth_get_read, BIO_meth_set_read, BIO_meth_get_puts, BIO_meth_set_puts, BIO_meth_get_read, BIO_meth_set_read, BIO_meth_get_puts, BIO_meth_set_puts,
BIO_meth_get_gets, BIO_meth_set_gets, BIO_meth_get_ctrl, BIO_meth_set_ctrl, BIO_meth_get_gets, BIO_meth_set_gets, BIO_meth_get_ctrl, BIO_meth_set_ctrl,
...@@ -13,6 +14,7 @@ BIO_meth_set_callback_ctrl - Routines to build up BIO methods ...@@ -13,6 +14,7 @@ BIO_meth_set_callback_ctrl - Routines to build up BIO methods
#include <openssl/bio.h> #include <openssl/bio.h>
int BIO_get_new_index(void);
BIO_METHOD *BIO_meth_new(int type, const char *name); BIO_METHOD *BIO_meth_new(int type, const char *name);
void BIO_meth_free(BIO_METHOD *biom); void BIO_meth_free(BIO_METHOD *biom);
int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int); int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int);
...@@ -47,7 +49,10 @@ types. It provides a set of of functions used by OpenSSL for the implementation ...@@ -47,7 +49,10 @@ types. It provides a set of of functions used by OpenSSL for the implementation
of the various BIO capabilities. See the L<bio> page for more information. of the various BIO capabilities. See the L<bio> page for more information.
BIO_meth_new() creates a new B<BIO_METHOD> structure. It should be given a BIO_meth_new() creates a new B<BIO_METHOD> structure. It should be given a
unique integer B<type> and a string that represents its B<name>. The set of unique integer B<type> and a string that represents its B<name>.
Use BIO_get_new_index() to get the value for B<type>.
The set of
standard OpenSSL provided BIO types is provided in B<bio.h>. Some examples standard OpenSSL provided BIO types is provided in B<bio.h>. Some examples
include B<BIO_TYPE_BUFFER> and B<BIO_TYPE_CIPHER>. Filter BIOs should have a include B<BIO_TYPE_BUFFER> and B<BIO_TYPE_CIPHER>. Filter BIOs should have a
type which have the "filter" bit set (B<BIO_TYPE_FILTER>). Source/sink BIOs type which have the "filter" bit set (B<BIO_TYPE_FILTER>). Source/sink BIOs
......
...@@ -31,38 +31,39 @@ ...@@ -31,38 +31,39 @@
extern "C" { extern "C" {
#endif #endif
/* There are the classes of BIOs */
# define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
# define BIO_TYPE_FILTER 0x0200
# define BIO_TYPE_SOURCE_SINK 0x0400
/* These are the 'types' of BIOs */ /* These are the 'types' of BIOs */
# define BIO_TYPE_NONE 0 # define BIO_TYPE_NONE 0
# define BIO_TYPE_MEM (1|0x0400) # define BIO_TYPE_MEM ( 1|BIO_TYPE_SOURCE_SINK)
# define BIO_TYPE_FILE (2|0x0400) # define BIO_TYPE_FILE ( 2|BIO_TYPE_SOURCE_SINK)
# define BIO_TYPE_FD (4|0x0400|0x0100) # define BIO_TYPE_FD ( 4|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
# define BIO_TYPE_SOCKET (5|0x0400|0x0100) # define BIO_TYPE_SOCKET ( 5|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
# define BIO_TYPE_NULL (6|0x0400) # define BIO_TYPE_NULL ( 6|BIO_TYPE_SOURCE_SINK)
# define BIO_TYPE_SSL (7|0x0200) # define BIO_TYPE_SSL ( 7|BIO_TYPE_FILTER)
# define BIO_TYPE_MD (8|0x0200)/* passive filter */ # define BIO_TYPE_MD ( 8|BIO_TYPE_FILTER)
# define BIO_TYPE_BUFFER (9|0x0200)/* filter */ # define BIO_TYPE_BUFFER ( 9|BIO_TYPE_FILTER)
# define BIO_TYPE_CIPHER (10|0x0200)/* filter */ # define BIO_TYPE_CIPHER (10|BIO_TYPE_FILTER)
# define BIO_TYPE_BASE64 (11|0x0200)/* filter */ # define BIO_TYPE_BASE64 (11|BIO_TYPE_FILTER)
# define BIO_TYPE_CONNECT (12|0x0400|0x0100)/* socket - connect */ # define BIO_TYPE_CONNECT (12|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
# define BIO_TYPE_ACCEPT (13|0x0400|0x0100)/* socket for accept */ # define BIO_TYPE_ACCEPT (13|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
/* # define BIO_TYPE_PROXY_CLIENT (14|0x0200)*/ /* client proxy BIO */
/* # define BIO_TYPE_PROXY_SERVER (15|0x0200)*/ /* server proxy BIO */ # define BIO_TYPE_NBIO_TEST (16|BIO_TYPE_FILTER)/* server proxy BIO */
# define BIO_TYPE_NBIO_TEST (16|0x0200)/* server proxy BIO */ # define BIO_TYPE_NULL_FILTER (17|BIO_TYPE_FILTER)
# define BIO_TYPE_NULL_FILTER (17|0x0200) # define BIO_TYPE_BIO (19|BIO_TYPE_SOURCE_SINK)/* half a BIO pair */
# define BIO_TYPE_BER (18|0x0200)/* BER -> bin filter */ # define BIO_TYPE_LINEBUFFER (20|BIO_TYPE_FILTER)
# define BIO_TYPE_BIO (19|0x0400)/* (half a) BIO pair */ # define BIO_TYPE_DGRAM (21|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
# define BIO_TYPE_LINEBUFFER (20|0x0200)/* filter */ # define BIO_TYPE_ASN1 (22|BIO_TYPE_FILTER)
# define BIO_TYPE_DGRAM (21|0x0400|0x0100) # define BIO_TYPE_COMP (23|BIO_TYPE_FILTER)
# ifndef OPENSSL_NO_SCTP # ifndef OPENSSL_NO_SCTP
# define BIO_TYPE_DGRAM_SCTP (24|0x0400|0x0100) # define BIO_TYPE_DGRAM_SCTP (24|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
# endif # endif
# define BIO_TYPE_ASN1 (22|0x0200)/* filter */
# define BIO_TYPE_COMP (23|0x0200)/* filter */
# define BIO_TYPE_DESCRIPTOR 0x0100/* socket, fd, connect or accept */ #define BIO_TYPE_START 128
# define BIO_TYPE_FILTER 0x0200
# define BIO_TYPE_SOURCE_SINK 0x0400
/* /*
* BIO_FILENAME_READ|BIO_CLOSE to open or close on free. * BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
...@@ -177,6 +178,7 @@ extern "C" { ...@@ -177,6 +178,7 @@ extern "C" {
typedef union bio_addr_st BIO_ADDR; typedef union bio_addr_st BIO_ADDR;
typedef struct bio_addrinfo_st BIO_ADDRINFO; typedef struct bio_addrinfo_st BIO_ADDRINFO;
int BIO_get_new_index(void);
void BIO_set_flags(BIO *b, int flags); void BIO_set_flags(BIO *b, int flags);
int BIO_test_flags(const BIO *b, int flags); int BIO_test_flags(const BIO *b, int flags);
void BIO_clear_flags(BIO *b, int flags); void BIO_clear_flags(BIO *b, int flags);
......
...@@ -4198,3 +4198,4 @@ X509_CRL_get0_lastUpdate 4144 1_1_0 EXIST::FUNCTION: ...@@ -4198,3 +4198,4 @@ X509_CRL_get0_lastUpdate 4144 1_1_0 EXIST::FUNCTION:
X509_get0_notBefore 4145 1_1_0 EXIST::FUNCTION: X509_get0_notBefore 4145 1_1_0 EXIST::FUNCTION:
X509_get0_notAfter 4146 1_1_0 EXIST::FUNCTION: X509_get0_notAfter 4146 1_1_0 EXIST::FUNCTION:
X509_CRL_get0_nextUpdate 4147 1_1_0 EXIST::FUNCTION: X509_CRL_get0_nextUpdate 4147 1_1_0 EXIST::FUNCTION:
BIO_get_new_index 4148 1_1_0 EXIST::FUNCTION:
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册