struct ucl_chunk *chunk;
};
+struct ucl_parser_special_handler_chain {
+ unsigned char *begin;
+ size_t len;
+ struct ucl_parser_special_handler *special_handler;
+ struct ucl_parser_special_handler_chain *next;
+};
+
struct ucl_chunk {
const unsigned char *begin;
const unsigned char *end;
unsigned priority;
enum ucl_duplicate_strategy strategy;
enum ucl_parse_type parse_type;
- struct ucl_parser_special_handler *special_handler;
+ struct ucl_parser_special_handler_chain *special_handlers;
struct ucl_chunk *next;
};
memset (chunk, 0, sizeof (*chunk));
+ /* Apply all matching handlers from the first to the last */
LL_FOREACH (parser->special_handlers, special_handler) {
if ((special_handler->flags & UCL_SPECIAL_HANDLER_PREPROCESS_ALL) ||
(len >= special_handler->magic_len &&
return false;
}
+ struct ucl_parser_special_handler_chain *nchain;
+ nchain = UCL_ALLOC (sizeof (*nchain));
+ nchain->begin = ndata;
+ nchain->len = nlen;
+ nchain->special_handler = special_handler;
+
+ /* Free order is reversed */
+ LL_PREPEND (chunk->special_handlers, nchain);
+
data = ndata;
len = nlen;
- chunk->special_handler = special_handler;
-
- break;
}
}
ucl_chunk_free (struct ucl_chunk *chunk)
{
if (chunk) {
- if (chunk->special_handler) {
- if (chunk->special_handler->free_function) {
- chunk->special_handler->free_function (
- (unsigned char *) chunk->begin,
- chunk->end - chunk->begin,
- chunk->special_handler->user_data);
+ struct ucl_parser_special_handler_chain *chain, *tmp;
+
+ LL_FOREACH_SAFE (chunk->special_handlers, chain, tmp) {
+ if (chain->special_handler->free_function) {
+ chain->special_handler->free_function (
+ chain->begin,
+ chain->len,
+ chain->special_handler->user_data);
} else {
- UCL_FREE (chunk->end - chunk->begin,
- (unsigned char *) chunk->begin);
+ UCL_FREE (chain->len, chain->begin);
}
+
+ UCL_FREE (sizeof (*chain), chain);
}
+ chunk->special_handlers = NULL;
+
if (chunk->fname) {
free (chunk->fname);
}