BIO_FIND_TYPE(3)

NAME
BIO_find_type, BIO_next, BIO_method_type, BIO_method_name - BIO chain traversal

SYNOPSIS
#include <openssl/bio.h>
BIO *
BIO_find_type(BIO *bio, int type);
BIO *
BIO_next(BIO *bio);
int
BIO_method_type(const BIO *bio);
const char *
BIO_method_name(const BIO *bio);
#define BIO_TYPE_NONE 0
#define BIO_TYPE_START 128

DESCRIPTION
BIO_find_type() searches for a BIO matching the given type in the chain starting at bio. If the least significant byte of the type argument is non-zero, only exact matches of the type are accepted. Otherwise, a match only requires that any of the bits set in the type argument is also set in the candidate BIO.

Types with a least significant byte in the range from 0 to BIO_TYPE_START, inclusive, are reserved for BIO types built into the library. Types with a least significant byte greater than BIO_TYPE_START are available for user-defined BIO types; see BIO_get_new_index(3) for details.

BIO_next() returns the next BIO in the chain after bio. This function can be used to traverse all BIOs in a chain or in conjunction with BIO_find_type() to find all BIOs of a certain type.

BIO_method_type() returns the type of the given bio.

BIO_method_name() returns an ASCII string representing the type of the bio.

The following are the built-in source/sink BIO types that operate on file descriptors. They all have both of the bits BIO_TYPE_SOURCE_SINK and BIO_TYPE_DESCRIPTOR but not the bit BIO_TYPE_FILTER set in their type constant.
type constant | name string | BIO_METHOD
BIO_TYPE_ACCEPT | socket accept | BIO_s_accept(3)
BIO_TYPE_CONNECT | socket connect | BIO_s_connect(3)
BIO_TYPE_DGRAM | datagram socket | BIO_s_datagram(3)
BIO_TYPE_FD | file descriptor | BIO_s_fd(3)
BIO_TYPE_SOCKET | socket | BIO_s_socket(3)

The following are the built-in source/sink BIO types that do not directly operate on file descriptors. They all have the bit BIO_TYPE_SOURCE_SINK but not the bits BIO_TYPE_DESCRIPTOR and BIO_TYPE_FILTER set in their type constant.
type constant | name string | BIO_METHOD
BIO_TYPE_BIO | BIO pair | BIO_s_bio(3)
BIO_TYPE_FILE | FILE pointer | BIO_s_file(3)
BIO_TYPE_MEM | memory buffer | BIO_s_mem(3)
BIO_TYPE_NULL | NULL | BIO_s_null(3)

The following are the built-in filter BIO types. They all have the bit BIO_TYPE_FILTER but not the bits BIO_TYPE_SOURCE_SINK and BIO_TYPE_DESCRIPTOR set in their type constant.
type constant | name string | BIO_METHOD
BIO_TYPE_BASE64 | base64 encoding | BIO_f_base64(3)
BIO_TYPE_BUFFER | buffer | BIO_f_buffer(3)
BIO_TYPE_CIPHER | cipher | BIO_f_cipher(3)
BIO_TYPE_MD | message digest | BIO_f_md(3)
BIO_TYPE_NULL_FILTER | NULL filter | BIO_f_null(3)
BIO_TYPE_SSL | ssl | BIO_f_ssl(3)

The constants BIO_TYPE_BER, BIO_TYPE_PROXY_CLIENT, and BIO_TYPE_PROXY_SERVER do not correspond to any BIO types implemented by the library and are not intended to be used for application-defined types, either. The constants BIO_TYPE_COMP, BIO_TYPE_LINEBUFFER, and BIO_TYPE_NBIO_TEST corresponds to a deprecated BIO types that are intentionally undocumented.

If a variable in an application program is intended to store a BIO type but temporarily does not refer to any BIO or refers to a BIO of an unknown type, setting the variable to BIO_TYPE_NONE is recommended.

RETURN VALUES
BIO_find_type() returns the next matching BIO or NULL if bio is a NULL pointer or if no matching BIO is found.

BIO_next() returns the next BIO or NULL if bio is a NULL pointer or points to the last BIO in a chain.

BIO_method_type() returns one of the BIO_TYPE_* constants.

BIO_method_name() returns an internal pointer to a string.

EXAMPLES
Traverse a chain looking for digest BIOs:

    BIO *btmp;
    btmp = in_bio;	/* in_bio is the chain to search through */
    while (btmp != NULL) {
    	btmp = BIO_find_type(btmp, BIO_TYPE_MD);
    	if (btmp == NULL)
    		break;	/* Not found */
    	/* btmp is a digest BIO, do something with it ... */
    	...
    	btmp = BIO_next(btmp);
    }

SEE ALSO
BIO_meth_new(3), BIO_new(3)

HISTORY
BIO_method_type() and BIO_method_name() first appeared in SSLeay 0.6.0. BIO_find_type() first appeared in SSLeay 0.6.6. These functions have been available since OpenBSD 2.4.

BIO_next() first appeared in OpenSSL 0.9.6 and has been available since OpenBSD 2.9.