luasandbox  1.4.0
Generic Lua sandbox for dynamic data analysis
input_buffer.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 /** Data stream input buffer @file */
8 
9 #ifndef luasandbox_util_input_buffer_h_
10 #define luasandbox_util_input_buffer_h_
11 
12 #include <stdbool.h>
13 #include <stddef.h>
14 
15 #include "util.h"
16 
17 typedef struct lsb_input_buffer
18 {
19  char *buf;
20  size_t size;
21  size_t maxsize;
22  size_t readpos;
23  size_t scanpos;
24  size_t msglen;
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /**
32  * Initialize the provided input buffer
33  *
34  * @param b Input buffer
35  * @param max_message_size The maximum message size the buffer will handle
36  * before erroring (the internal buffer will contain extra space
37  * for the header)
38  *
39  * @return lsb_err_value NULL on success error message on failure
40  */
42 lsb_init_input_buffer(lsb_input_buffer *b, size_t max_message_size);
43 
44 /**
45  * Frees the memory internally allocated by the buffer and resets the state
46  *
47  * @param b Input buffer
48  */
50 
51 /**
52  * Expands the input buffer (if necessary) to accomadate the requested number of
53  * bytes. The expansion happens in power of two increments up to the maxsize.
54  * The buffer never shrinks in size.
55  *
56  * @param b Input buffer
57  * @param len The length of the data being added to the buffer
58  *
59  * @return lsb_err_value NULL on success error message on failure
60  */
63 
64 #ifdef __cplusplus
65 }
66 #endif
67 
68 #endif
const char * lsb_err_value
Definition: error.h:15
Shared types and structures.
#define LSB_UTIL_EXPORT
Definition: util.h:28
LSB_UTIL_EXPORT lsb_err_value lsb_expand_input_buffer(lsb_input_buffer *b, size_t len)
Expands the input buffer (if necessary) to accomadate the requested number of bytes.
struct lsb_input_buffer lsb_input_buffer
LSB_UTIL_EXPORT void lsb_free_input_buffer(lsb_input_buffer *b)
Frees the memory internally allocated by the buffer and resets the state.
LSB_UTIL_EXPORT lsb_err_value lsb_init_input_buffer(lsb_input_buffer *b, size_t max_message_size)
Initialize the provided input buffer.