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
39#ifndef _XAR_ARCHIVE_H_
40#define _XAR_ARCHIVE_H_
41#include <zlib.h>
42#include <libxml/hash.h>
43#ifdef __APPLE__
44#include <CommonCrypto/CommonDigest.h>
45#include <CommonCrypto/CommonDigestSPI.h>
46#else
47#include <openssl/evp.h>
48#endif
49#include <sys/types.h>
50#include <sys/stat.h>
51#include "xar.h"
52#include "filetree.h"
53
54struct errctx {
55	const char *str;
56	int         saved_errno;
57	xar_file_t  file;
58	void       *usrctx;
59	xar_t       x;
60};
61
62struct __xar_t {
63	xar_prop_t props;
64	xar_attr_t attrs;      /* archive options, such as rsize */
65	const char *prefix;
66	const char *ns;
67	const char *filler1;
68	const char *filler2;
69	xar_file_t files;       /* file forest */
70	const char *filename;   /* name of the archive we are operating on */
71	char *dirname;          /* directory of the archive, used in creation */
72	int fd;                 /* open file descriptor for the archive */
73	int heap_fd;            /* fd for tmp heap archive, used in creation */
74	off_t heap_offset;      /* current offset within the heap */
75	off_t heap_len;         /* current length of the heap */
76	xar_header_t header;    /* header of the xar archive */
77	void *readbuf;          /* buffer for reading/writing compressed toc */
78	size_t readbuf_len;     /* length of readbuf */
79	size_t offset;          /* offset into readbuf for keeping track
80	                         * between callbacks. */
81	size_t toc_count;       /* current bytes read of the toc */
82	z_stream zs;            /* gz state for compressing/decompressing toc */
83	char *path_prefix;      /* used for distinguishing absolute paths */
84	err_handler ercallback; /* callback for errors/warnings */
85	struct errctx errctx;   /* error callback context */
86	xar_subdoc_t subdocs;   /* linked list of subdocs */
87	xar_signature_t signatures; /* linked list of signatures */
88	uint64_t last_fileid;       /* unique fileid's in the archive */
89	xmlHashTablePtr ino_hash;   /* Hash for looking up hardlinked files (add)*/
90	xmlHashTablePtr link_hash;  /* Hash for looking up hardlinked files (extract)*/
91	xmlHashTablePtr csum_hash;  /* Hash for looking up checksums of files */
92#ifdef __APPLE__
93    CCDigestRef toc_ctx;
94    unsigned int toc_ctx_length;
95#else
96	EVP_MD_CTX toc_ctx;
97#endif // !__APPLE__
98	int docksum;
99	int skipwarn;
100	struct stat sbcache;
101};
102
103#define XAR(x) ((struct __xar_t *)(x))
104
105#endif /* _XAR_ARCHIVE_H_ */
106