The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: d0fcac39711a936358a224f8eaaeaaaa6ad98ddf $
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  */
27 RCSIDH(lib_bio_mem_h, "$Id: d0fcac39711a936358a224f8eaaeaaaa6ad98ddf $")
28 
29 /** Status returned by the verification callback.
30  *
31  */
32 typedef 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 packet_ctx as passed in to fr_bio_read()
46  * @param buffer pointer to the raw data
47  * @param[in,out] size in: size of data in the buffer. out: size of the packet to return, or data to discard.
48  * @return action to take
49  */
50 typedef fr_bio_verify_action_t (*fr_bio_verify_t)(fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t *size);
51 
52 fr_bio_t *fr_bio_mem_alloc(TALLOC_CTX *ctx, size_t read_size, size_t write_size, fr_bio_t *next) CC_HINT(nonnull);
53 
54 fr_bio_t *fr_bio_mem_source_alloc(TALLOC_CTX *ctx, size_t buffer_size, fr_bio_t *next) CC_HINT(nonnull);
55 
56 fr_bio_t *fr_bio_mem_sink_alloc(TALLOC_CTX *ctx, size_t buffer_size) CC_HINT(nonnull);
57 
58 uint8_t const *fr_bio_mem_read_peek(fr_bio_t *bio, size_t *size) CC_HINT(nonnull);
59 
60 void fr_bio_mem_read_discard(fr_bio_t *bio, size_t size) CC_HINT(nonnull);
61 
62 int fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, bool datagram) CC_HINT(nonnull);
static int const char char buffer[256]
Definition: acutest.h:574
Definition: base.h:103
#define RCSIDH(h, id)
Definition: build.h:445
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:547
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:768
fr_bio_verify_action_t(* fr_bio_verify_t)(fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t *size)
Verifies the packet.
Definition: mem.h:50
int fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, bool datagram)
Set the verification function for memory bios.
Definition: mem.c:799
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:703
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:661
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:529
unsigned char uint8_t
Definition: merged_model.c:30
static fr_bio_t * bio
Definition: radclient-ng.c:86
int nonnull(2, 5))