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: a3f9468b7a5322728113a0f13b0c4b814ee3ace3 $
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: a3f9468b7a5322728113a0f13b0c4b814ee3ace3 $")
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 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  */
51 typedef 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 
53 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);
54 
55 fr_bio_t *fr_bio_mem_source_alloc(TALLOC_CTX *ctx, size_t buffer_size, fr_bio_t *next) CC_HINT(nonnull);
56 
57 fr_bio_t *fr_bio_mem_sink_alloc(TALLOC_CTX *ctx, size_t buffer_size) CC_HINT(nonnull);
58 
59 uint8_t const *fr_bio_mem_read_peek(fr_bio_t *bio, size_t *size) CC_HINT(nonnull);
60 
61 void fr_bio_mem_read_discard(fr_bio_t *bio, size_t size) CC_HINT(nonnull);
62 
63 int fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, void *verify_ctx, bool datagram) CC_HINT(nonnull);
64 
65 int fr_bio_mem_write_resume(fr_bio_t *bio) CC_HINT(nonnull);
static int const char char buffer[256]
Definition: acutest.h:574
Definition: base.h:112
#define RCSIDH(h, id)
Definition: build.h:482
next
Definition: dcursor.h:178
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_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
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
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
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
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
Definition: merged_model.c:30
int nonnull(2, 5))