archive_private.h revision 232153
1228753Smm/*-
2228753Smm * Copyright (c) 2003-2007 Tim Kientzle
3228753Smm * All rights reserved.
4228753Smm *
5228753Smm * Redistribution and use in source and binary forms, with or without
6228753Smm * modification, are permitted provided that the following conditions
7228753Smm * are met:
8228753Smm * 1. Redistributions of source code must retain the above copyright
9228753Smm *    notice, this list of conditions and the following disclaimer.
10228753Smm * 2. Redistributions in binary form must reproduce the above copyright
11228753Smm *    notice, this list of conditions and the following disclaimer in the
12228753Smm *    documentation and/or other materials provided with the distribution.
13228753Smm *
14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24228753Smm *
25228763Smm * $FreeBSD: head/contrib/libarchive/libarchive/archive_private.h 232153 2012-02-25 10:58:02Z mm $
26228753Smm */
27228753Smm
28228753Smm#ifndef __LIBARCHIVE_BUILD
29228753Smm#error This header is only to be used internally to libarchive.
30228753Smm#endif
31228753Smm
32228753Smm#ifndef ARCHIVE_PRIVATE_H_INCLUDED
33228753Smm#define	ARCHIVE_PRIVATE_H_INCLUDED
34228753Smm
35232153Smm#if HAVE_ICONV_H
36232153Smm#include <iconv.h>
37232153Smm#endif
38232153Smm
39228753Smm#include "archive.h"
40228753Smm#include "archive_string.h"
41228753Smm
42228753Smm#if defined(__GNUC__) && (__GNUC__ > 2 || \
43228753Smm			  (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
44228753Smm#define	__LA_DEAD	__attribute__((__noreturn__))
45228753Smm#else
46228753Smm#define	__LA_DEAD
47228753Smm#endif
48228753Smm
49228753Smm#define	ARCHIVE_WRITE_MAGIC	(0xb0c5c0deU)
50228753Smm#define	ARCHIVE_READ_MAGIC	(0xdeb0c5U)
51228753Smm#define	ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U)
52228753Smm#define	ARCHIVE_READ_DISK_MAGIC (0xbadb0c5U)
53228753Smm
54228753Smm#define	ARCHIVE_STATE_NEW	1U
55228753Smm#define	ARCHIVE_STATE_HEADER	2U
56228753Smm#define	ARCHIVE_STATE_DATA	4U
57228753Smm#define	ARCHIVE_STATE_EOF	0x10U
58228753Smm#define	ARCHIVE_STATE_CLOSED	0x20U
59228753Smm#define	ARCHIVE_STATE_FATAL	0x8000U
60232153Smm#define	ARCHIVE_STATE_ANY	(0xFFFFU & ~ARCHIVE_STATE_FATAL)
61228753Smm
62228753Smmstruct archive_vtable {
63228753Smm	int	(*archive_close)(struct archive *);
64228773Smm	int	(*archive_free)(struct archive *);
65228753Smm	int	(*archive_write_header)(struct archive *,
66228753Smm	    struct archive_entry *);
67228753Smm	int	(*archive_write_finish_entry)(struct archive *);
68228753Smm	ssize_t	(*archive_write_data)(struct archive *,
69228753Smm	    const void *, size_t);
70228753Smm	ssize_t	(*archive_write_data_block)(struct archive *,
71232153Smm	    const void *, size_t, int64_t);
72232153Smm
73232153Smm	int	(*archive_read_next_header)(struct archive *,
74232153Smm	    struct archive_entry **);
75232153Smm	int	(*archive_read_next_header2)(struct archive *,
76232153Smm	    struct archive_entry *);
77232153Smm	int	(*archive_read_data_block)(struct archive *,
78232153Smm	    const void **, size_t *, int64_t *);
79232153Smm
80232153Smm	int	(*archive_filter_count)(struct archive *);
81232153Smm	int64_t (*archive_filter_bytes)(struct archive *, int);
82232153Smm	int	(*archive_filter_code)(struct archive *, int);
83232153Smm	const char * (*archive_filter_name)(struct archive *, int);
84228753Smm};
85228753Smm
86232153Smmstruct archive_string_conv;
87232153Smm
88228753Smmstruct archive {
89228753Smm	/*
90228753Smm	 * The magic/state values are used to sanity-check the
91228753Smm	 * client's usage.  If an API function is called at a
92228753Smm	 * ridiculous time, or the client passes us an invalid
93228753Smm	 * pointer, these values allow me to catch that.
94228753Smm	 */
95228753Smm	unsigned int	magic;
96228753Smm	unsigned int	state;
97228753Smm
98228753Smm	/*
99228753Smm	 * Some public API functions depend on the "real" type of the
100228753Smm	 * archive object.
101228753Smm	 */
102228753Smm	struct archive_vtable *vtable;
103228753Smm
104228753Smm	int		  archive_format;
105228753Smm	const char	 *archive_format_name;
106228753Smm
107228753Smm	int	  compression_code;	/* Currently active compression. */
108228753Smm	const char *compression_name;
109228753Smm
110228753Smm	/* Number of file entries processed. */
111228753Smm	int		  file_count;
112228753Smm
113228753Smm	int		  archive_error_number;
114228753Smm	const char	 *error;
115228753Smm	struct archive_string	error_string;
116232153Smm
117232153Smm	char *current_code;
118232153Smm	unsigned current_codepage; /* Current ACP(ANSI CodePage). */
119232153Smm	unsigned current_oemcp; /* Current OEMCP(OEM CodePage). */
120232153Smm	struct archive_string_conv *sconv;
121228753Smm};
122228753Smm
123232153Smm/* Check magic value and state; return(ARCHIVE_FATAL) if it isn't valid. */
124232153Smmint	__archive_check_magic(struct archive *, unsigned int magic,
125228753Smm	    unsigned int state, const char *func);
126232153Smm#define	archive_check_magic(a, expected_magic, allowed_states, function_name) \
127232153Smm	do { \
128232153Smm		int magic_test = __archive_check_magic((a), (expected_magic), \
129232153Smm			(allowed_states), (function_name)); \
130232153Smm		if (magic_test == ARCHIVE_FATAL) \
131232153Smm			return ARCHIVE_FATAL; \
132232153Smm	} while (0)
133228753Smm
134228753Smmvoid	__archive_errx(int retvalue, const char *msg) __LA_DEAD;
135228753Smm
136232153Smmint	__archive_mktemp(const char *tmpdir);
137228753Smm
138232153Smmint	__archive_clean(struct archive *);
139232153Smm
140228753Smm#define	err_combine(a,b)	((a) < (b) ? (a) : (b))
141228753Smm
142228753Smm#if defined(__BORLANDC__) || (defined(_MSC_VER) &&  _MSC_VER <= 1300)
143228753Smm# define	ARCHIVE_LITERAL_LL(x)	x##i64
144228753Smm# define	ARCHIVE_LITERAL_ULL(x)	x##ui64
145228753Smm#else
146228753Smm# define	ARCHIVE_LITERAL_LL(x)	x##ll
147228753Smm# define	ARCHIVE_LITERAL_ULL(x)	x##ull
148228753Smm#endif
149228753Smm
150228753Smm#endif
151