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_IO_H_
39#define _XAR_IO_H_
40
41#include "archive.h"
42//typedef int (*read_callback)(xar_t, xar_file_t, void *, size_t, void *context);
43//typedef int (*write_callback)(xar_t, xar_file_t, void *, size_t, void *context);
44
45typedef int (*fromheap_in)(xar_t x, xar_file_t f, xar_prop_t p, void **in, size_t *inlen, void **context);
46typedef int (*fromheap_out)(xar_t x, xar_file_t f, xar_prop_t p, void *in, size_t inlen, void **context);
47typedef int (*fromheap_done)(xar_t x, xar_file_t f, xar_prop_t p, void **context);
48
49typedef int (*toheap_in)(xar_t x, xar_file_t f, xar_prop_t p, void **in, size_t *inlen, void **context);
50typedef int (*toheap_out)(xar_t x, xar_file_t f, xar_prop_t p, void *in, size_t inlen, void **context);
51typedef int (*toheap_done)(xar_t x, xar_file_t f, xar_prop_t p, void **context);
52
53struct datamod {
54	fromheap_in      fh_in;
55	fromheap_out     fh_out;
56	fromheap_done    fh_done;
57	toheap_in        th_in;
58	toheap_out       th_out;
59	toheap_done      th_done;
60};
61
62typedef struct xar_stream_state {
63        char      *pending_buf;
64        size_t     pending_buf_size;
65
66        void     **modulecontext;
67        int        modulecount;
68        size_t     bsize;
69        int64_t    fsize;
70        xar_t      x;
71        xar_file_t f;
72	xar_prop_t p;
73} xar_stream_state_t;
74
75size_t xar_io_get_rsize(xar_t x);
76off_t xar_io_get_heap_base_offset(xar_t x);
77size_t xar_io_get_toc_checksum_length_for_type(const char *type);
78size_t xar_io_get_toc_checksum_length(xar_t x);
79off_t xar_io_get_file_offset(xar_t x, xar_file_t f, xar_prop_t p);
80int64_t xar_io_get_length(xar_prop_t p);
81
82int32_t xar_attrcopy_to_heap(xar_t x, xar_file_t f, xar_prop_t p, read_callback rcb, void *context);
83int32_t xar_attrcopy_from_heap(xar_t x, xar_file_t f, xar_prop_t p, write_callback wcb, void *context);
84int32_t xar_attrcopy_from_heap_to_heap(xar_t xsource, xar_file_t fsource, xar_prop_t p, xar_t xdest, xar_file_t fdest);
85int32_t xar_attrcopy_from_heap_to_stream_init(xar_t x, xar_file_t f, xar_prop_t p, xar_stream *stream);
86int32_t xar_attrcopy_from_heap_to_stream(xar_stream *stream);
87int32_t xar_attrcopy_from_heap_to_stream_end(xar_stream *stream);
88
89int32_t xar_heap_to_archive(xar_t x);
90
91#pragma mark internal
92
93// IMPORTANT: Keep count synchronized with declaration in io.c!
94extern struct datamod xar_datamods[6];
95
96#endif /* _XAR_IO_H_ */
97