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>
76 my->priv_cb.eof = NULL;
152 rcode = next->
read(next, packet_ctx, p, room);
180 size_t used, room, want;
250 rcode = next->
read(next, packet_ctx, p, room);
255 if (rcode == 0)
return 0;
310 rcode = next->
read(next, packet_ctx,
buffer, size);
315 if (rcode == 0)
return 0;
378 size_t room, leftover;
395 rcode = next->
write(next, packet_ctx,
buffer, size);
396 if ((
size_t) rcode == size)
return rcode;
403 if (rcode ==
fr_bio_error(IO_WOULD_BLOCK))
return rcode;
415 if (!
buffer)
return rcode;
421 if (error < 0)
return error;
435 leftover = size - rcode;
443 if (room < leftover) leftover = room;
494 rcode = next->
write(next, NULL,
my->write_buffer.
read, size);
505 if (rcode < 0)
return rcode;
561 if (rcode < 0)
return rcode;
579 if (rcode < 0)
return rcode;
596 if (!
used)
return NULL;
599 return my->read_buffer.read;
631 packet =
my->read_buffer.read;
632 end =
my->read_buffer.write;
634 while (packet < end) {
644 switch (
my->verify((
fr_bio_t *)
my,
my->verify_ctx, packet_ctx, packet, &want)) {
670 packet =
my->read_buffer.read += want;
696 if (size < 1024) size = 1024;
697 if (size > (1 << 20)) size = 1 << 20;
734 if (!
my)
return NULL;
744 if (write_size > 0) {
746 fr_strerror_const(
"Invalid write size. If read size is zero, then write size must also be zero");
805 if (!write_size)
return NULL;
808 if (!
my)
return NULL;
858 if (room < size) size = room;
877 if (!read_size)
return NULL;
880 if (!
my)
return NULL;
923 fr_strerror_const(
"Invalid memory BIO - we need a read buffer for verifying packets from a stream socket");
933 my->verify_ctx = verify_ctx;
949 if (
my->write_buffer.start) {
985 if (rcode <= 0)
return rcode;
992 if (!
my->cb.write_resume)
return 1;
994 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 void fr_bio_buf_reset(fr_bio_buf_t *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)
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
void fr_bio_shutdown & my
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.
int fr_bio_shutdown(fr_bio_t *bio)
Shut down a set of BIOs.
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_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_stream(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_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.
fr_bio_buf_t read_buffer
buffering for reads
static int fr_bio_mem_eof(fr_bio_t *bio)
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_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.
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.
fr_bio_mem_type_t type
source, sink, etc.
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.
int fr_bio_mem_write_pause(fr_bio_t *bio)
Pause writes.
uint8_t const * fr_bio_mem_read_peek(fr_bio_t *bio, size_t *size)
Peek at the data in the read buffer.
static ssize_t fr_bio_mem_write_buffer(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
@ 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.
#define fr_strerror_const(_msg)