25 #include <freeradius-devel/bio/bio_priv.h>
26 #include <freeradius-devel/bio/null.h>
27 #include <freeradius-devel/bio/buf.h>
29 #include <freeradius-devel/bio/mem.h>
66 my->priv_cb.eof = NULL;
142 rcode =
next->read(
next, packet_ctx, p, room);
170 size_t used, room, want;
244 rcode =
next->read(
next, packet_ctx, p, room);
253 if (size <= want) want = size;
279 if (rcode == 0)
return 0;
351 if (rcode == 0)
return 0;
374 size_t room, leftover;
392 if ((
size_t) rcode == size)
return rcode;
398 if ((rcode < 0) && (rcode !=
fr_bio_error(IO_WOULD_BLOCK))) {
418 if (error < 0)
return error;
432 leftover = size - rcode;
440 if (room < leftover) leftover = room;
502 if (rcode < 0)
return rcode;
558 if (rcode < 0)
return rcode;
576 if (rcode < 0)
return rcode;
593 if (!
used)
return NULL;
596 return my->read_buffer.read;
628 packet =
my->read_buffer.read;
629 end =
my->read_buffer.write;
631 while (packet < end) {
641 switch (
my->verify((
fr_bio_t *)
my,
my->verify_ctx, packet_ctx, packet, &want)) {
667 my->read_buffer.read += want;
694 if (size < 1024) size = 1024;
695 if (size > (1 << 20)) size = 1 << 20;
740 if (!
my)
return NULL;
779 if (!write_size)
return NULL;
782 if (!
my)
return NULL;
833 if (room < size) size = room;
852 if (!read_size)
return NULL;
855 if (!
my)
return NULL;
890 my->verify_ctx = verify_ctx;
903 if (
my->write_buffer.start) {
937 if (rcode <= 0)
return rcode;
941 if (!
my->cb.write_resume)
return 1;
943 return my->cb.write_resume(bio);
static int const char char buffer[256]
fr_bio_write_t _CONST write
write to the underlying bio
fr_bio_read_t _CONST read
read from the underlying bio
static fr_bio_t * fr_bio_next(fr_bio_t *bio)
static void fr_bio_chain(fr_bio_t *first, fr_bio_t *second)
Chain one bio after another.
size_t fr_bio_buf_make_room(fr_bio_buf_t *bio_buf)
size_t fr_bio_buf_read(fr_bio_buf_t *bio_buf, void *buffer, size_t size)
int fr_bio_buf_alloc(TALLOC_CTX *ctx, fr_bio_buf_t *bio_buf, size_t size)
ssize_t fr_bio_buf_write(fr_bio_buf_t *bio_buf, const void *buffer, size_t size)
static size_t fr_bio_buf_write_room(fr_bio_buf_t const *bio_buf)
static size_t fr_bio_buf_used(fr_bio_buf_t const *bio_buf)
static uint8_t * fr_bio_buf_write_reserve(fr_bio_buf_t *bio_buf, size_t size)
static int fr_bio_buf_write_alloc(fr_bio_buf_t *bio_buf, size_t size)
int fr_bio_write_blocked(fr_bio_t *bio)
Internal BIO function to tell all BIOs that it's blocked.
void fr_bio_eof(fr_bio_t *bio)
Internal BIO function to run EOF callbacks.
int fr_bio_destructor(fr_bio_t *bio)
Free this bio.
ssize_t fr_bio_next_write(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
Internal bio function which just writes to the "next" bio.
static ssize_t fr_bio_mem_write_read_buffer(fr_bio_t *bio, UNUSED void *packet_ctx, void const *buffer, size_t size)
Write to the read buffer.
static ssize_t fr_bio_mem_read_verify(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Return data only if we have a complete packet.
void * verify_ctx
verify context
void fr_bio_mem_read_discard(fr_bio_t *bio, size_t size)
Discard data from the read buffer.
fr_bio_buf_t read_buffer
buffering for reads
static int fr_bio_mem_eof(fr_bio_t *bio)
fr_bio_t * fr_bio_mem_source_alloc(TALLOC_CTX *ctx, size_t write_size, fr_bio_t *next)
Allocate a memory buffer which sources data from the callers application into the bio system.
struct fr_bio_mem_s fr_bio_mem_t
The memory buffer bio.
static ssize_t fr_bio_mem_write_next(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
Pass writes to the next BIO.
static ssize_t fr_bio_mem_read_verify_datagram(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Return data only if we have a complete packet.
fr_bio_t * fr_bio_mem_sink_alloc(TALLOC_CTX *ctx, size_t read_size)
Allocate a memory buffer which sinks data from a bio system into the callers application.
static ssize_t fr_bio_mem_read_buffer(fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size)
Read from a buffer which a previous bio has filled.
int fr_bio_mem_write_resume(fr_bio_t *bio)
See if we can resume writes to the memory bio.
fr_bio_buf_t write_buffer
buffering for writes
fr_bio_verify_t verify
verify data to see if we have a packet.
static ssize_t fr_bio_mem_read(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Read from a memory BIO.
int fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, void *verify_ctx, bool datagram)
Set the verification function for memory bios.
static void fr_bio_mem_shutdown(fr_bio_t *bio)
static ssize_t fr_bio_mem_read_eof(fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size)
At EOF, read data from the buffer until it is empty.
static bool fr_bio_mem_buf_alloc(fr_bio_mem_t *my, fr_bio_buf_t *buf, size_t size)
Allocate a memory buffer bio for either reading or writing.
static ssize_t fr_bio_mem_write_flush(fr_bio_mem_t *my, size_t size)
Flush the memory buffer.
static int fr_bio_mem_call_verify(fr_bio_t *bio, void *packet_ctx, size_t *size))
Verify that a packet is OK.
fr_bio_t * fr_bio_mem_alloc(TALLOC_CTX *ctx, size_t read_size, size_t write_size, fr_bio_t *next)
Allocate a memory buffer bio.
static ssize_t fr_bio_mem_write_buffer(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
uint8_t const * fr_bio_mem_read_peek(fr_bio_t *bio, size_t *size)
Peek at the data in the read buffer.
@ FR_BIO_VERIFY_ERROR_CLOSE
fatal error, the bio should be closed.
@ FR_BIO_VERIFY_DISCARD
the packet should be discarded
@ FR_BIO_VERIFY_OK
packet is OK
@ FR_BIO_VERIFY_WANT_MORE
not enough data for one packet
fr_bio_verify_action_t(* fr_bio_verify_t)(fr_bio_t *bio, void *verify_ctx, void *packet_ctx, const void *buffer, size_t *size)
Verifies the packet.
ssize_t fr_bio_null_write(UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void const *buffer, UNUSED size_t size)
Always return 0 on write.
ssize_t fr_bio_null_read(UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void *buffer, UNUSED size_t size)
Always return 0 on read.
ssize_t fr_bio_fail_read(UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void *buffer, UNUSED size_t size)
Always return error on read.
ssize_t fr_bio_fail_write(UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void const *buffer, UNUSED size_t size)
Always return 0 on write.
#define fr_strerror_const(_msg)