1/*
2 * Copyright (c) 2005-2007 Rob Braun
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Rob Braun nor the names of his contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29/*
30 * 03-Apr-2005
31 * DRI: Rob Braun <bbraun@synack.net>
32 */
33/*
34 * Portions Copyright 2006, Apple Computer, Inc.
35 * Christopher Ryan <ryanc@apple.com>
36*/
37
38#ifndef _XAR_FILETREE_H_
39#define _XAR_FILETREE_H_
40
41#ifndef _FILE_OFFSET_BITS
42#define _FILE_OFFSET_BITS 64
43#endif
44
45#include <libxml/xmlwriter.h>
46#include <libxml/xmlreader.h>
47
48struct __xar_attr_t {
49	const char *key;
50	const char *value;
51	const char *ns;
52	const struct __xar_attr_t *next;
53};
54typedef const struct __xar_attr_t *xar_attr_t;
55
56struct __xar_prop_t {
57        const char *key;
58        const char *value;
59        const struct __xar_prop_t *parent;
60        const struct __xar_prop_t *children;
61        const struct __xar_prop_t *next;
62        const struct __xar_attr_t *attrs;
63        const struct __xar_file_t *file;
64	const char *prefix;
65	const char *ns;
66};
67typedef const struct __xar_prop_t *xar_prop_t;
68
69#include "ea.h"
70
71struct __xar_file_t {
72	const struct __xar_prop_t *props;
73	const struct __xar_attr_t *attrs;
74	const char *prefix;
75	const char *ns;
76	const char *fspath;
77	char parent_extracted;
78	const struct __xar_file_t *parent;
79	const struct __xar_file_t *children;
80	const struct __xar_file_t *next;
81	xar_ea_t eas;
82	uint64_t nexteaid;
83};
84
85#define XAR_ATTR(x) ((struct __xar_attr_t *)(x))
86#define XAR_FILE(x) ((struct __xar_file_t *)(x))
87#define XAR_PROP(x) ((struct __xar_prop_t *)(x))
88
89void xar_file_free(xar_file_t f);
90xar_attr_t xar_attr_new(void);
91int32_t xar_attr_set(xar_file_t f, const char *prop, const char *key, const char *value);
92int32_t xar_attr_pset(xar_file_t f, xar_prop_t p, const char *key, const char *value);
93const char *xar_attr_get(xar_file_t f, const char *prop, const char *key);
94const char *xar_attr_pget(xar_file_t f, xar_prop_t p, const char *key);
95void xar_attr_free(xar_attr_t a);
96void xar_file_serialize(xar_file_t f, xmlTextWriterPtr writer);
97xar_file_t xar_file_unserialize(xar_t x, xar_file_t parent, xmlTextReaderPtr reader);
98xar_file_t xar_file_find(xar_file_t f, const char *path);
99xar_file_t xar_file_new(xar_file_t f);
100xar_file_t xar_file_replicate(xar_file_t original, xar_file_t newparent);
101void xar_file_free(xar_file_t f);
102
103void xar_prop_serialize(xar_prop_t p, xmlTextWriterPtr writer);
104int32_t xar_prop_unserialize(xar_file_t f, xar_prop_t parent, xmlTextReaderPtr reader);
105void xar_prop_free(xar_prop_t p);
106xar_prop_t xar_prop_new(xar_file_t f, xar_prop_t parent);
107xar_prop_t xar_prop_pset(xar_file_t f, xar_prop_t p, const char *key, const char *value);
108xar_prop_t xar_prop_find(xar_prop_t p, const char *key);
109xar_prop_t xar_prop_pget(xar_prop_t p, const char *key);
110const char *xar_prop_getkey(xar_prop_t p);
111const char *xar_prop_getvalue(xar_prop_t p);
112int32_t xar_prop_setkey(xar_prop_t p, const char *key);
113int32_t xar_prop_setvalue(xar_prop_t p, const char *value);
114xar_prop_t xar_prop_pfirst(xar_file_t f);
115xar_prop_t xar_prop_pnext(xar_prop_t p);
116void xar_prop_punset(xar_file_t f, xar_prop_t p);
117
118#endif /* _XAR_FILETREE_H_ */
119