Email-object serialiser. More...
#include "config.h"#include <stdbool.h>#include <stddef.h>#include <string.h>#include <sys/types.h>#include "mutt/lib.h"#include "address/lib.h"#include "config/lib.h"#include "email/lib.h"#include "core/lib.h"#include "alias/lib.h"#include "serialize.h"Go to the source code of this file.
Macros | |
| #define | SERIAL_MAX_CHAR_SIZE (256 * 1024) |
| Max size for a single serialized string field (256 KiB). | |
| #define | SERIAL_MAX_LIST_COUNT 1024 |
| Max entries in a serialized list (addresses, headers, parameters, tags). | |
Functions | |
| static bool | serial_in_bounds (int off, size_t need, size_t dlen) |
| Does a read stay within the serialized blob? | |
| void | lazy_realloc (void *ptr, size_t size) |
| Reallocate some memory. | |
| unsigned char * | serial_dump_int (const unsigned int i, unsigned char *d, int *off) |
| Pack an integer into a binary blob. | |
| unsigned char * | serial_dump_uint32_t (const uint32_t s, unsigned char *d, int *off) |
| Pack a uint32_t into a binary blob. | |
| unsigned char * | serial_dump_uint64_t (const uint64_t s, unsigned char *d, int *off) |
| Pack a uint64_t into a binary blob. | |
| bool | serial_restore_int (unsigned int *i, const unsigned char *d, int *off, size_t dlen) |
| Unpack an integer from a binary blob. | |
| bool | serial_restore_uint32_t (uint32_t *s, const unsigned char *d, int *off, size_t dlen) |
| Unpack an uint32_t from a binary blob. | |
| bool | serial_restore_uint64_t (uint64_t *s, const unsigned char *d, int *off, size_t dlen) |
| Unpack an uint64_t from a binary blob. | |
| unsigned char * | serial_dump_char_size (const char *c, ssize_t size, unsigned char *d, int *off, bool convert) |
| Pack a fixed-length string into a binary blob. | |
| unsigned char * | serial_dump_char (const char *c, unsigned char *d, int *off, bool convert) |
| Pack a variable-length string into a binary blob. | |
| bool | serial_restore_char (char **c, const unsigned char *d, int *off, size_t dlen, bool convert) |
| Unpack a variable-length string from a binary blob. | |
| unsigned char * | serial_dump_address (const struct AddressList *al, unsigned char *d, int *off, bool convert) |
| Pack an Address into a binary blob. | |
| bool | serial_restore_address (struct AddressList *al, const unsigned char *d, int *off, size_t dlen, bool convert) |
| Unpack an Address from a binary blob. | |
| unsigned char * | serial_dump_stailq (const struct ListHead *l, unsigned char *d, int *off, bool convert) |
| Pack a STAILQ into a binary blob. | |
| bool | serial_restore_stailq (struct ListHead *l, const unsigned char *d, int *off, size_t dlen, bool convert) |
| Unpack a STAILQ from a binary blob. | |
| unsigned char * | serial_dump_buffer (const struct Buffer *buf, unsigned char *d, int *off, bool convert) |
| Pack a Buffer into a binary blob. | |
| bool | serial_restore_buffer (struct Buffer *buf, const unsigned char *d, int *off, size_t dlen, bool convert) |
| Unpack a Buffer from a binary blob. | |
| unsigned char * | serial_dump_parameter (const struct ParameterList *pl, unsigned char *d, int *off, bool convert) |
| Pack a Parameter into a binary blob. | |
| bool | serial_restore_parameter (struct ParameterList *pl, const unsigned char *d, int *off, size_t dlen, bool convert) |
| Unpack a Parameter from a binary blob. | |
| static uint32_t | body_pack_flags (const struct Body *b) |
| Pack the Body flags into a uint32_t. | |
| static void | body_unpack_flags (struct Body *b, uint32_t packed) |
| Unpack the Body flags from a uint32_t. | |
| unsigned char * | serial_dump_body (const struct Body *b, unsigned char *d, int *off, bool convert) |
| Pack an Body into a binary blob. | |
| bool | serial_restore_body (struct Body *b, const unsigned char *d, int *off, size_t dlen, bool convert) |
| Unpack a Body from a binary blob. | |
| unsigned char * | serial_dump_envelope (const struct Envelope *env, unsigned char *d, int *off, bool convert) |
| Pack an Envelope into a binary blob. | |
| bool | serial_restore_envelope (struct Envelope *env, const unsigned char *d, int *off, size_t dlen, bool convert) |
| Unpack an Envelope from a binary blob. | |
| unsigned char * | serial_dump_tags (const struct TagList *tl, unsigned char *d, int *off) |
| Pack a TagList into a binary blob. | |
| bool | serial_restore_tags (struct TagList *tl, const unsigned char *d, int *off, size_t dlen) |
| Unpack a TagList from a binary blob. | |
Email-object serialiser.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file serialize.c.
| #define SERIAL_MAX_CHAR_SIZE (256 * 1024) |
Max size for a single serialized string field (256 KiB).
Definition at line 45 of file serialize.c.
| #define SERIAL_MAX_LIST_COUNT 1024 |
Max entries in a serialized list (addresses, headers, parameters, tags).
Definition at line 48 of file serialize.c.
|
static |
Does a read stay within the serialized blob?
| off | Current offset into the blob |
| need | Number of bytes about to be read |
| dlen | Total length of the blob |
| true | The read is fully contained in the blob |
The restore helpers walk a blob whose length is only known to the caller. A truncated or crafted cache entry can claim fields that extend past the end of the fetched data, so every read is checked against dlen first.
Definition at line 61 of file serialize.c.
| void lazy_realloc | ( | void * | ptr, |
| size_t | size ) |
Reallocate some memory.
| [in] | ptr | Pointer to resize |
| [in] | size | Minimum size |
The minimum size is 4KiB to avoid repeated resizing.
Definition at line 73 of file serialize.c.
| unsigned char * serial_dump_int | ( | const unsigned int | i, |
| unsigned char * | d, | ||
| int * | off ) |
Pack an integer into a binary blob.
| [in] | i | Integer to save |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| ptr | End of the newly packed binary |
Definition at line 90 of file serialize.c.
| unsigned char * serial_dump_uint32_t | ( | const uint32_t | s, |
| unsigned char * | d, | ||
| int * | off ) |
Pack a uint32_t into a binary blob.
| [in] | s | uint32_t to save |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| ptr | End of the newly packed binary |
Definition at line 106 of file serialize.c.
| unsigned char * serial_dump_uint64_t | ( | const uint64_t | s, |
| unsigned char * | d, | ||
| int * | off ) |
Pack a uint64_t into a binary blob.
| [in] | s | uint64_t to save |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| ptr | End of the newly packed binary |
Definition at line 122 of file serialize.c.
| bool serial_restore_int | ( | unsigned int * | i, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen ) |
Unpack an integer from a binary blob.
| [in] | i | Integer to write to |
| [in] | d | Binary blob to read from |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| true | The integer was read |
| false | The read would leave the blob |
Definition at line 140 of file serialize.c.
| bool serial_restore_uint32_t | ( | uint32_t * | s, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen ) |
Unpack an uint32_t from a binary blob.
| [in] | s | uint32_t to write to |
| [in] | d | Binary blob to read from |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| true | The uint32_t was read |
| false | The read would leave the blob |
Definition at line 159 of file serialize.c.
| bool serial_restore_uint64_t | ( | uint64_t * | s, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen ) |
Unpack an uint64_t from a binary blob.
| [in] | s | uint64_t to write to |
| [in] | d | Binary blob to read from |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| true | The uint64_t was read |
| false | The read would leave the blob |
Definition at line 178 of file serialize.c.
| unsigned char * serial_dump_char_size | ( | const char * | c, |
| ssize_t | size, | ||
| unsigned char * | d, | ||
| int * | off, | ||
| bool | convert ) |
Pack a fixed-length string into a binary blob.
| [in] | c | String to pack |
| [in] | d | Binary blob to add to |
| [in] | size | Size of the string |
| [in,out] | off | Offset into the blob |
| [in] | convert | If true, the strings will be converted to utf-8 |
| ptr | End of the newly packed binary |
Definition at line 197 of file serialize.c.
| unsigned char * serial_dump_char | ( | const char * | c, |
| unsigned char * | d, | ||
| int * | off, | ||
| bool | convert ) |
Pack a variable-length string into a binary blob.
| [in] | c | String to pack |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| [in] | convert | If true, the strings will be converted to utf-8 |
| ptr | End of the newly packed binary |
Definition at line 234 of file serialize.c.
| bool serial_restore_char | ( | char ** | c, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen, | ||
| bool | convert ) |
Unpack a variable-length string from a binary blob.
| [out] | c | Store the unpacked string here |
| [in] | d | Binary blob to read from |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| [in] | convert | If true, the strings will be converted to utf-8 |
| true | The string was read (an empty string yields a NULL c) |
| false | The read would leave the blob |
Definition at line 249 of file serialize.c.
| unsigned char * serial_dump_address | ( | const struct AddressList * | al, |
| unsigned char * | d, | ||
| int * | off, | ||
| bool | convert ) |
Pack an Address into a binary blob.
| [in] | al | AddressList to pack |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| [in] | convert | If true, the strings will be converted to utf-8 |
| ptr | End of the newly packed binary |
Definition at line 290 of file serialize.c.
| bool serial_restore_address | ( | struct AddressList * | al, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen, | ||
| bool | convert ) |
Unpack an Address from a binary blob.
| [out] | al | Store the unpacked AddressList here |
| [in] | d | Binary blob to read from |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| [in] | convert | If true, the strings will be converted from utf-8 |
| true | The AddressList was read |
| false | A read would leave the blob, or the count is out of range |
Definition at line 322 of file serialize.c.
| unsigned char * serial_dump_stailq | ( | const struct ListHead * | l, |
| unsigned char * | d, | ||
| int * | off, | ||
| bool | convert ) |
Pack a STAILQ into a binary blob.
| [in] | l | List to read from |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| [in] | convert | If true, the strings will be converted to utf-8 |
| ptr | End of the newly packed binary |
Definition at line 372 of file serialize.c.
| bool serial_restore_stailq | ( | struct ListHead * | l, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen, | ||
| bool | convert ) |
Unpack a STAILQ from a binary blob.
| [in] | l | List to add to |
| [in] | d | Binary blob to read from |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| [in] | convert | If true, the strings will be converted from utf-8 |
| true | The list was read |
| false | A read would leave the blob, or the count is out of range |
Definition at line 402 of file serialize.c.
| unsigned char * serial_dump_buffer | ( | const struct Buffer * | buf, |
| unsigned char * | d, | ||
| int * | off, | ||
| bool | convert ) |
Pack a Buffer into a binary blob.
| [in] | buf | Buffer to pack |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| [in] | convert | If true, the strings will be converted to utf-8 |
| ptr | End of the newly packed binary |
Definition at line 433 of file serialize.c.
| bool serial_restore_buffer | ( | struct Buffer * | buf, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen, | ||
| bool | convert ) |
Unpack a Buffer from a binary blob.
| [out] | buf | Store the unpacked Buffer here |
| [in] | d | Binary blob to read from |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| [in] | convert | If true, the strings will be converted from utf-8 |
| true | The Buffer was read |
| false | A read would leave the blob |
Definition at line 459 of file serialize.c.
| unsigned char * serial_dump_parameter | ( | const struct ParameterList * | pl, |
| unsigned char * | d, | ||
| int * | off, | ||
| bool | convert ) |
Pack a Parameter into a binary blob.
| [in] | pl | Parameter to pack |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| [in] | convert | If true, the strings will be converted to utf-8 |
| ptr | End of the newly packed binary |
Definition at line 487 of file serialize.c.
| bool serial_restore_parameter | ( | struct ParameterList * | pl, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen, | ||
| bool | convert ) |
Unpack a Parameter from a binary blob.
| [in] | pl | Store the unpacked Parameter here |
| [in] | d | Binary blob to read from |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| [in] | convert | If true, the strings will be converted from utf-8 |
| true | The Parameter was read |
| false | A read would leave the blob, or the count is out of range |
Definition at line 518 of file serialize.c.
|
inlinestatic |
Pack the Body flags into a uint32_t.
| b | Body to pack |
| num | uint32_t of packed flags |
Definition at line 551 of file serialize.c.
|
inlinestatic |
Unpack the Body flags from a uint32_t.
| b | Body to unpack into |
| packed | Packed flags |
Definition at line 581 of file serialize.c.
| unsigned char * serial_dump_body | ( | const struct Body * | b, |
| unsigned char * | d, | ||
| int * | off, | ||
| bool | convert ) |
Pack an Body into a binary blob.
| [in] | b | Body to pack |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| [in] | convert | If true, the strings will be converted to utf-8 |
| ptr | End of the newly packed binary |
Definition at line 611 of file serialize.c.
| bool serial_restore_body | ( | struct Body * | b, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen, | ||
| bool | convert ) |
Unpack a Body from a binary blob.
| [in] | b | Store the unpacked Body here |
| [in] | d | Binary blob to read from |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| [in] | convert | If true, the strings will be converted from utf-8 |
| true | The Body was read |
| false | A read would leave the blob |
Definition at line 646 of file serialize.c.
| unsigned char * serial_dump_envelope | ( | const struct Envelope * | env, |
| unsigned char * | d, | ||
| int * | off, | ||
| bool | convert ) |
Pack an Envelope into a binary blob.
| [in] | env | Envelope to pack |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| [in] | convert | If true, the strings will be converted to utf-8 |
| ptr | End of the newly packed binary |
Definition at line 695 of file serialize.c.
| bool serial_restore_envelope | ( | struct Envelope * | env, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen, | ||
| bool | convert ) |
Unpack an Envelope from a binary blob.
| [in] | env | Store the unpacked Envelope here |
| [in] | d | Binary blob to read from |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| [in] | convert | If true, the strings will be converted from utf-8 |
| true | The Envelope was read |
| false | A read would leave the blob |
Definition at line 746 of file serialize.c.
| unsigned char * serial_dump_tags | ( | const struct TagList * | tl, |
| unsigned char * | d, | ||
| int * | off ) |
Pack a TagList into a binary blob.
| [in] | tl | TagList to pack |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| ptr | End of the newly packed binary |
Definition at line 821 of file serialize.c.
| bool serial_restore_tags | ( | struct TagList * | tl, |
| const unsigned char * | d, | ||
| int * | off, | ||
| size_t | dlen ) |
Unpack a TagList from a binary blob.
| [in] | tl | TagList to unpack |
| [in] | d | Binary blob to add to |
| [in,out] | off | Offset into the blob |
| [in] | dlen | Length of the binary blob |
| true | The TagList was read |
| false | A read would leave the blob, or the count is out of range |
Definition at line 849 of file serialize.c.