archive_write_private.h revision 256281
172445Sassar/*-
2233294Sstas * Copyright (c) 2003-2007 Tim Kientzle
3233294Sstas * All rights reserved.
4233294Sstas *
572445Sassar * Redistribution and use in source and binary forms, with or without
6233294Sstas * modification, are permitted provided that the following conditions
7233294Sstas * are met:
8233294Sstas * 1. Redistributions of source code must retain the above copyright
972445Sassar *    notice, this list of conditions and the following disclaimer.
10233294Sstas * 2. Redistributions in binary form must reproduce the above copyright
11233294Sstas *    notice, this list of conditions and the following disclaimer in the
1272445Sassar *    documentation and/or other materials provided with the distribution.
13233294Sstas *
14233294Sstas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15233294Sstas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1672445Sassar * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17233294Sstas * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18233294Sstas * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19233294Sstas * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2072445Sassar * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21233294Sstas * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22233294Sstas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23233294Sstas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24233294Sstas *
25233294Sstas * $FreeBSD: stable/10/contrib/libarchive/libarchive/archive_write_private.h 248616 2013-03-22 13:36:03Z mm $
26233294Sstas */
27233294Sstas
28233294Sstas#ifndef __LIBARCHIVE_BUILD
29233294Sstas#error This header is only to be used internally to libarchive.
30233294Sstas#endif
31233294Sstas
3272445Sassar#ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED
3372445Sassar#define	ARCHIVE_WRITE_PRIVATE_H_INCLUDED
34233294Sstas
3572445Sassar#include "archive.h"
3672445Sassar#include "archive_string.h"
3772445Sassar#include "archive_private.h"
3872445Sassar
39233294Sstasstruct archive_write;
40233294Sstas
41233294Sstasstruct archive_write_filter {
42233294Sstas	int64_t bytes_written;
43233294Sstas	struct archive *archive; /* Associated archive. */
44233294Sstas	struct archive_write_filter *next_filter; /* Who I write to. */
45233294Sstas	int	(*options)(struct archive_write_filter *,
46233294Sstas	    const char *key, const char *value);
47233294Sstas	int	(*open)(struct archive_write_filter *);
48233294Sstas	int	(*write)(struct archive_write_filter *, const void *, size_t);
49233294Sstas	int	(*close)(struct archive_write_filter *);
50233294Sstas	int	(*free)(struct archive_write_filter *);
51233294Sstas	void	 *data;
52233294Sstas	const char *name;
53233294Sstas	int	  code;
54233294Sstas	int	  bytes_per_block;
55233294Sstas	int	  bytes_in_last_block;
56233294Sstas};
57233294Sstas
58233294Sstas#if ARCHIVE_VERSION < 4000000
5972445Sassarvoid __archive_write_filters_free(struct archive *);
6072445Sassar#endif
6172445Sassar
6272445Sassarstruct archive_write_filter *__archive_write_allocate_filter(struct archive *);
6372445Sassar
6472445Sassarint __archive_write_output(struct archive_write *, const void *, size_t);
6572445Sassarint __archive_write_nulls(struct archive_write *, size_t);
6672445Sassarint __archive_write_filter(struct archive_write_filter *, const void *, size_t);
6772445Sassarint __archive_write_open_filter(struct archive_write_filter *);
6872445Sassarint __archive_write_close_filter(struct archive_write_filter *);
6972445Sassar
7072445Sassarstruct archive_write {
7172445Sassar	struct archive	archive;
7272445Sassar
7372445Sassar	/* Dev/ino of the archive being written. */
74233294Sstas	int		  skip_file_set;
75233294Sstas	int64_t		  skip_file_dev;
7672445Sassar	int64_t		  skip_file_ino;
77233294Sstas
78233294Sstas	/* Utility:  Pointer to a block of nulls. */
79233294Sstas	const unsigned char	*nulls;
80233294Sstas	size_t			 null_length;
81233294Sstas
82233294Sstas	/* Callbacks to open/read/write/close archive stream. */
83233294Sstas	archive_open_callback	*client_opener;
84233294Sstas	archive_write_callback	*client_writer;
85233294Sstas	archive_close_callback	*client_closer;
8672445Sassar	void			*client_data;
87
88	/*
89	 * Blocking information.  Note that bytes_in_last_block is
90	 * misleadingly named; I should find a better name.  These
91	 * control the final output from all compressors, including
92	 * compression_none.
93	 */
94	int		  bytes_per_block;
95	int		  bytes_in_last_block;
96
97	/*
98	 * First and last write filters in the pipeline.
99	 */
100	struct archive_write_filter *filter_first;
101	struct archive_write_filter *filter_last;
102
103	/*
104	 * Pointers to format-specific functions for writing.  They're
105	 * initialized by archive_write_set_format_XXX() calls.
106	 */
107	void	 *format_data;
108	const char *format_name;
109	int	(*format_init)(struct archive_write *);
110	int	(*format_options)(struct archive_write *,
111		    const char *key, const char *value);
112	int	(*format_finish_entry)(struct archive_write *);
113	int 	(*format_write_header)(struct archive_write *,
114		    struct archive_entry *);
115	ssize_t	(*format_write_data)(struct archive_write *,
116		    const void *buff, size_t);
117	int	(*format_close)(struct archive_write *);
118	int	(*format_free)(struct archive_write *);
119};
120
121/*
122 * Utility function to format a USTAR header into a buffer.  If
123 * "strict" is set, this tries to create the absolutely most portable
124 * version of a ustar header.  If "strict" is set to 0, then it will
125 * relax certain requirements.
126 *
127 * Generally, format-specific declarations don't belong in this
128 * header; this is a rare example of a function that is shared by
129 * two very similar formats (ustar and pax).
130 */
131int
132__archive_write_format_header_ustar(struct archive_write *, char buff[512],
133    struct archive_entry *, int tartype, int strict,
134    struct archive_string_conv *);
135
136struct archive_write_program_data;
137struct archive_write_program_data * __archive_write_program_allocate(void);
138int	__archive_write_program_free(struct archive_write_program_data *);
139int	__archive_write_program_open(struct archive_write_filter *,
140	    struct archive_write_program_data *, const char *);
141int	__archive_write_program_close(struct archive_write_filter *,
142	    struct archive_write_program_data *);
143int	__archive_write_program_write(struct archive_write_filter *,
144	    struct archive_write_program_data *, const void *, size_t);
145#endif
146