message-part-serialize.c revision 749c1abc1804e227afa6bae2d5ddf8bcc96e7cc4
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "message-parser.h"
#include "message-part-serialize.h"
/*
Serialized a series of SerializedMessageParts:
root part
root's first children
children's first children
...
root's next children
...
*/
/* struct is 8 byte aligned */
struct serialized_message_part {
unsigned int header_lines;
unsigned int body_lines;
unsigned int children_count;
unsigned int flags;
};
struct deserialize_context {
const struct serialized_message_part *spart;
unsigned int sparts_left;
const char *error;
};
static unsigned int
{
struct serialized_message_part *spart;
unsigned int count = 0;
/* create serialized part */
spart->children_count = 0;
}
count++;
}
return count;
}
{
}
struct message_part *parent,
unsigned int child_count,
struct message_part **part_r)
{
const struct serialized_message_part *spart;
first_part = NULL;
while (child_count > 0) {
child_count--;
if (ctx->sparts_left == 0) {
return FALSE;
}
ctx->sparts_left--;
return FALSE;
}
return FALSE;
}
return FALSE;
}
/* our children must be after our physical_pos and the last
child must be within our size. */
return FALSE;
return FALSE;
}
/* Only one child is possible */
return FALSE;
}
"has multiple children";
return FALSE;
}
}
if (first_part == NULL)
first_part = part;
}
*part_r = first_part;
return TRUE;
}
{
if (size < sizeof(struct serialized_message_part)) {
*error = "Not enough data for root";
return FALSE;
}
if ((size % sizeof(struct serialized_message_part)) != 0) {
*error = "Incorrect data size";
return FALSE;
}
*error = "Insane amount of data";
return FALSE;
}
return TRUE;
}
{
struct deserialize_context ctx;
struct message_part *part;
return NULL;
(unsigned int) (size / sizeof(struct serialized_message_part));
return NULL;
}
if (ctx.sparts_left > 0) {
*error = "Too much data";
return NULL;
}
return part;
}
struct message_size *hdr_size,
const char **error)
{
unsigned int children;
return FALSE;
*error = "Invalid data";
return FALSE;
}
if (pos_diff != 0) {
/* have to update all positions, but skip the first one */
spart++;
/* invalid offset, might cause overflow */
*error = "Invalid offset";
return FALSE;
}
}
return FALSE;
}
}
return TRUE;
}
struct message_size *hdr_size,
struct message_size *body_size)
{
/* make sure it looks valid */
if (size < sizeof(struct serialized_message_part))
return FALSE;
return TRUE;
}