/*
 * This file is part of the Poliqarp suite.
 * 
 * Copyright (C) 2004-2009 by Instytut Podstaw Informatyki Polskiej
 * Akademii Nauk (IPI PAN; Institute of Computer Science, Polish
 * Academy of Sciences; cf. www.ipipan.waw.pl).  All rights reserved.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file gpl.txt included in the packaging
 * of this file.  (See http://www.gnu.org/licenses/translations.html for
 * unofficial translations.)
 * 
 * A commercial license is available from IPI PAN (contact
 * Michal.Ciesiolka@ipipan.waw.pl or ipi@ipipan.waw.pl for more
 * information).  Licensees holding a valid commercial license from IPI
 * PAN may use this file in accordance with that license.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

#ifndef HAVE_META_FOO_H
#define HAVE_META_FOO_H

#define _GNU_SOURCE

#include <poliqarp-config.h>

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

#include "viewport.h"
#include "binary-pool.h"
#include "text-stack.h"
#include "utils.h"

#include <sakura/abi.h>

#include "lisp/lisp.h"
#include "lisp/lisp-file-stream.h"
#include <sakura/regexp.h>
#include "list.h"
#include "header-parser.h"

struct meta_item {
   enum poliqarp_binary_metadata_type type;
   struct binary_pool_node *key_node;
   size_t num_paths;
   struct poliqarp_regexp *path;
   struct poliqarp_regexp *def_path;    /* NULL -> not seen / otherwise -> seen, if type!=multi then also collected */
   struct list_item *values;    /* list of metadata of this type */
   struct list_item *valend;    /* last element of the list */
};

struct meta_alias {
   struct binary_pool_node *key_node;
   struct list_item *meta_list;
};

struct poliqarp_meta_date parse_date(const char *text);

void store_meta(struct header_parser *this,
   struct poliqarp_binary_metadata *meta);

void pack_meta_single(struct poliqarp_binary_metadata *this, size_t key,
   size_t value);

void pack_meta_multi(struct poliqarp_binary_metadata *this, size_t key,
   size_t value);

void pack_meta_date(struct poliqarp_binary_metadata *this, size_t key,
   const char *value);

struct meta_item *meta_item_create(struct binary_pool_node *key_node,
   enum poliqarp_binary_metadata_type type, size_t num_paths,
   const char *const *path);

void meta_item_destroy(void *ptr);


int meta_item_compare_by_name(const void *p1, const void *p2);

void meta_item_reset(void *ptr);

void meta_item_store_undefined_value(void *ptr, void *arg);

/*----------------------------------------------------*/

struct meta_alias *meta_alias_create(struct binary_pool_node *key_node,
   struct list_item *list);

void meta_alias_destroy(void *ptr);

void meta_alias_reslove_and_store(void *ptr, void *arg);

#endif
