File: message-binary-part.c

package info (click to toggle)
dovecot 1%3A2.2.13-12~deb8u4
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 38,792 kB
  • sloc: ansic: 341,472; sh: 16,920; makefile: 5,393; cpp: 1,474; perl: 265; xml: 44; python: 34; pascal: 27
file content (43 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Copyright (c) 2013-2014 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "numpack.h"
#include "message-binary-part.h"

void message_binary_part_serialize(const struct message_binary_part *parts,
				   buffer_t *dest)
{
	const struct message_binary_part *part;

	for (part = parts; part != NULL; part = part->next) {
		numpack_encode(dest, part->physical_pos);
		numpack_encode(dest, part->binary_hdr_size);
		numpack_encode(dest, part->binary_body_size);
		numpack_encode(dest, part->binary_body_lines_count);
	}
}

int message_binary_part_deserialize(pool_t pool, const void *data, size_t size,
				    struct message_binary_part **parts_r)
{
	const uint8_t *p = data, *end = p + size;
	uint64_t n1, n2, n3, n4;
	struct message_binary_part *part = NULL, *prev_part = NULL;

	while (p != end) {
		part = p_new(pool, struct message_binary_part, 1);
		part->next = prev_part;
		prev_part = part;
		if (numpack_decode(&p, end, &n1) < 0 ||
		    numpack_decode(&p, end, &n2) < 0 ||
		    numpack_decode(&p, end, &n3) < 0 ||
		    numpack_decode(&p, end, &n4) < 0)
			return -1;
		part->physical_pos = n1;
		part->binary_hdr_size = n2;
		part->binary_body_size = n3;
		part->binary_body_lines_count = n4;
	}
	*parts_r = part;
	return 0;
}