/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _ADR_STREAM_H
#define _ADR_STREAM_H
#include <sys/types.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* A UNIX file descriptor normally is a sufficient abstraction for a
* connection. Unfortunately, complex layered protocols like SSL
* require some sort of userland linkage, and short of creating pipes
* to ourselves and threads to service them, we are no longer able to
* use file descriptors alone.
*
* Here we define a basic stream abstraction. It supports for basic
* operations: read, write, close, and free. read, write, and close
* are expected to be asynchronously callable. Traditionally, close
* and free were combined in close(2), but here we separate them so
* that streams can be closed in one thread while others are reading or
* writing without risk of use-after-free. free is obviously not
* asynchronously callable.
*
* Note: this functionality doesn't really fit in libadr, but is
* required by both protocol-independent portions of the rad daemon and
* by the rad protocol client code. To economize on libraries we are
* putting its implementation here until there is a critical mass of
* similar functionality.
*/
typedef struct adr_stream adr_stream_t;
adr_stream_t *adr_stream_create(ssize_t (*)(void *, char *, size_t),
ssize_t (*)(void *, const char *, size_t),
void (*)(void *), void (*)(void *), void *);
ssize_t adr_stream_read(adr_stream_t *, char *, size_t);
ssize_t adr_stream_write(adr_stream_t *, const char *, size_t);
void adr_stream_close(adr_stream_t *);
void adr_stream_free(adr_stream_t *);
/*
* Implementations of file descriptor and SSL streams are provided
* for convenience.
*/
adr_stream_t *adr_stream_create_fd(int);
adr_stream_t *adr_stream_create_fds(int, int);
adr_stream_t *adr_stream_create_ssl(SSL *, int);
void adr_ssl_init(void);
#ifdef __cplusplus
}
#endif
#endif /* _ADR_STREAM_H */