The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
mem.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: 914acbda46e49aeccc20b99b2258d266d338ecd5 $
20 * @file lib/bio/mem.h
21 * @brief Binary IO abstractions for memory buffers
22 *
23 * Allow reads and writes from memory buffers
24 *
25 * @copyright 2024 Network RADIUS SAS (legal@networkradius.com)
26 */
27RCSIDH(lib_bio_mem_h, "$Id: 914acbda46e49aeccc20b99b2258d266d338ecd5 $")
28
29/** Status returned by the verification callback.
30 *
31 */
32typedef enum {
33 FR_BIO_VERIFY_OK = 0, //!< packet is OK
34 FR_BIO_VERIFY_DISCARD, //!< the packet should be discarded
35 FR_BIO_VERIFY_WANT_MORE, //!< not enough data for one packet
36 FR_BIO_VERIFY_ERROR_CLOSE, //!< fatal error, the bio should be closed.
38
39/** Verifies the packet
40 *
41 * If the packet is a dup, then this function can return DISCARD, or
42 * update the packet_ctx to say "dup", and then return OK.
43 *
44 * @param bio the bio to read
45 * @param verify_ctx data specific for verifying
46 * @param packet_ctx as passed in to fr_bio_read()
47 * @param buffer pointer to the raw data
48 * @param[in,out] size in: size of data in the buffer. out: size of the packet to return, or data to discard.
49 * @return action to take
50 */
51typedef 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);
52
53fr_bio_t *fr_bio_mem_alloc(TALLOC_CTX *ctx, size_t read_size, size_t write_size, fr_bio_t *next) CC_HINT(nonnull);
54
55fr_bio_t *fr_bio_mem_source_alloc(TALLOC_CTX *ctx, size_t buffer_size, fr_bio_t *next) CC_HINT(nonnull);
56
57fr_bio_t *fr_bio_mem_sink_alloc(TALLOC_CTX *ctx, size_t buffer_size) CC_HINT(nonnull);
58
59uint8_t const *fr_bio_mem_read_peek(fr_bio_t *bio, size_t *size) CC_HINT(nonnull);
60
61void fr_bio_mem_read_discard(fr_bio_t *bio, size_t size) CC_HINT(nonnull);
62
63int fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, void *verify_ctx, bool datagram) CC_HINT(nonnull);
64
66
67int fr_bio_mem_write_pause(fr_bio_t *bio) CC_HINT(nonnull);
static int const char char buffer[256]
Definition acutest.h:576
#define RCSIDH(h, id)
Definition build.h:484
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.
Definition mem.c:727
fr_bio_verify_action_t
Status returned by the verification callback.
Definition mem.h:32
@ FR_BIO_VERIFY_ERROR_CLOSE
fatal error, the bio should be closed.
Definition mem.h:36
@ FR_BIO_VERIFY_DISCARD
the packet should be discarded
Definition mem.h:34
@ FR_BIO_VERIFY_OK
packet is OK
Definition mem.h:33
@ FR_BIO_VERIFY_WANT_MORE
not enough data for one packet
Definition mem.h:35
void fr_bio_mem_read_discard(fr_bio_t *bio, size_t size)
Discard data from the read buffer.
Definition mem.c:604
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.
Definition mem.h:51
int fr_bio_mem_write_resume(fr_bio_t *bio)
See if we can resume writes to the memory bio.
Definition mem.c:926
fr_bio_t * fr_bio_mem_sink_alloc(TALLOC_CTX *ctx, size_t buffer_size)
Allocate a memory buffer which sinks data from a bio system into the callers application.
Definition mem.c:845
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.
Definition mem.c:880
fr_bio_t * fr_bio_mem_source_alloc(TALLOC_CTX *ctx, size_t buffer_size, fr_bio_t *next)
Allocate a memory buffer which sources data from the callers application into the bio system.
Definition mem.c:772
int fr_bio_mem_write_pause(fr_bio_t *bio)
Pause writes.
Definition mem.c:952
uint8_t const * fr_bio_mem_read_peek(fr_bio_t *bio, size_t *size)
Peek at the data in the read buffer.
Definition mem.c:586
unsigned char uint8_t
int nonnull(2, 5))