Blame libarchive/archive_read_private.h

Packit Service 1d0348
/*-
Packit Service 1d0348
 * Copyright (c) 2003-2007 Tim Kientzle
Packit Service 1d0348
 * All rights reserved.
Packit Service 1d0348
 *
Packit Service 1d0348
 * Redistribution and use in source and binary forms, with or without
Packit Service 1d0348
 * modification, are permitted provided that the following conditions
Packit Service 1d0348
 * are met:
Packit Service 1d0348
 * 1. Redistributions of source code must retain the above copyright
Packit Service 1d0348
 *    notice, this list of conditions and the following disclaimer.
Packit Service 1d0348
 * 2. Redistributions in binary form must reproduce the above copyright
Packit Service 1d0348
 *    notice, this list of conditions and the following disclaimer in the
Packit Service 1d0348
 *    documentation and/or other materials provided with the distribution.
Packit Service 1d0348
 *
Packit Service 1d0348
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
Packit Service 1d0348
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit Service 1d0348
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Packit Service 1d0348
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit Service 1d0348
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Packit Service 1d0348
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit Service 1d0348
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit Service 1d0348
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit Service 1d0348
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Packit Service 1d0348
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 1d0348
 *
Packit Service 1d0348
 * $FreeBSD: head/lib/libarchive/archive_read_private.h 201088 2009-12-28 02:18:55Z kientzle $
Packit Service 1d0348
 */
Packit Service 1d0348
Packit Service 1d0348
#ifndef __LIBARCHIVE_BUILD
Packit Service 1d0348
#ifndef __LIBARCHIVE_TEST
Packit Service 1d0348
#error This header is only to be used internally to libarchive.
Packit Service 1d0348
#endif
Packit Service 1d0348
#endif
Packit Service 1d0348
Packit Service 1d0348
#ifndef ARCHIVE_READ_PRIVATE_H_INCLUDED
Packit Service 1d0348
#define	ARCHIVE_READ_PRIVATE_H_INCLUDED
Packit Service 1d0348
Packit Service 1d0348
#include "archive.h"
Packit Service 1d0348
#include "archive_string.h"
Packit Service 1d0348
#include "archive_private.h"
Packit Service 1d0348
Packit Service 1d0348
struct archive_read;
Packit Service 1d0348
struct archive_read_filter_bidder;
Packit Service 1d0348
struct archive_read_filter;
Packit Service 1d0348
Packit Service 1d0348
/*
Packit Service 1d0348
 * How bidding works for filters:
Packit Service 1d0348
 *   * The bid manager initializes the client-provided reader as the
Packit Service 1d0348
 *     first filter.
Packit Service 1d0348
 *   * It invokes the bidder for each registered filter with the
Packit Service 1d0348
 *     current head filter.
Packit Service 1d0348
 *   * The bidders can use archive_read_filter_ahead() to peek ahead
Packit Service 1d0348
 *     at the incoming data to compose their bids.
Packit Service 1d0348
 *   * The bid manager creates a new filter structure for the winning
Packit Service 1d0348
 *     bidder and gives the winning bidder a chance to initialize it.
Packit Service 1d0348
 *   * The new filter becomes the new top filter and we repeat the
Packit Service 1d0348
 *     process.
Packit Service 1d0348
 * This ends only when no bidder provides a non-zero bid.  Then
Packit Service 1d0348
 * we perform a similar dance with the registered format handlers.
Packit Service 1d0348
 */
Packit Service 1d0348
struct archive_read_filter_bidder {
Packit Service 1d0348
	/* Configuration data for the bidder. */
Packit Service 1d0348
	void *data;
Packit Service 1d0348
	/* Name of the filter */
Packit Service 1d0348
	const char *name;
Packit Service 1d0348
	/* Taste the upstream filter to see if we handle this. */
Packit Service 1d0348
	int (*bid)(struct archive_read_filter_bidder *,
Packit Service 1d0348
	    struct archive_read_filter *);
Packit Service 1d0348
	/* Initialize a newly-created filter. */
Packit Service 1d0348
	int (*init)(struct archive_read_filter *);
Packit Service 1d0348
	/* Set an option for the filter bidder. */
Packit Service 1d0348
	int (*options)(struct archive_read_filter_bidder *,
Packit Service 1d0348
	    const char *key, const char *value);
Packit Service 1d0348
	/* Release the bidder's configuration data. */
Packit Service 1d0348
	int (*free)(struct archive_read_filter_bidder *);
Packit Service 1d0348
};
Packit Service 1d0348
Packit Service 1d0348
/*
Packit Service 1d0348
 * This structure is allocated within the archive_read core
Packit Service 1d0348
 * and initialized by archive_read and the init() method of the
Packit Service 1d0348
 * corresponding bidder above.
Packit Service 1d0348
 */
Packit Service 1d0348
struct archive_read_filter {
Packit Service 1d0348
	int64_t position;
Packit Service 1d0348
	/* Essentially all filters will need these values, so
Packit Service 1d0348
	 * just declare them here. */
Packit Service 1d0348
	struct archive_read_filter_bidder *bidder; /* My bidder. */
Packit Service 1d0348
	struct archive_read_filter *upstream; /* Who I read from. */
Packit Service 1d0348
	struct archive_read *archive; /* Associated archive. */
Packit Service 1d0348
	/* Open a block for reading */
Packit Service 1d0348
	int (*open)(struct archive_read_filter *self);
Packit Service 1d0348
	/* Return next block. */
Packit Service 1d0348
	ssize_t (*read)(struct archive_read_filter *, const void **);
Packit Service 1d0348
	/* Skip forward this many bytes. */
Packit Service 1d0348
	int64_t (*skip)(struct archive_read_filter *self, int64_t request);
Packit Service 1d0348
	/* Seek to an absolute location. */
Packit Service 1d0348
	int64_t (*seek)(struct archive_read_filter *self, int64_t offset, int whence);
Packit Service 1d0348
	/* Close (just this filter) and free(self). */
Packit Service 1d0348
	int (*close)(struct archive_read_filter *self);
Packit Service 1d0348
	/* Function that handles switching from reading one block to the next/prev */
Packit Service 1d0348
	int (*sswitch)(struct archive_read_filter *self, unsigned int iindex);
Packit Service 1d0348
	/* My private data. */
Packit Service 1d0348
	void *data;
Packit Service 1d0348
Packit Service 1d0348
	const char	*name;
Packit Service 1d0348
	int		 code;
Packit Service 1d0348
Packit Service 1d0348
	/* Used by reblocking logic. */
Packit Service 1d0348
	char		*buffer;
Packit Service 1d0348
	size_t		 buffer_size;
Packit Service 1d0348
	char		*next;		/* Current read location. */
Packit Service 1d0348
	size_t		 avail;		/* Bytes in my buffer. */
Packit Service 1d0348
	const void	*client_buff;	/* Client buffer information. */
Packit Service 1d0348
	size_t		 client_total;
Packit Service 1d0348
	const char	*client_next;
Packit Service 1d0348
	size_t		 client_avail;
Packit Service 1d0348
	char		 end_of_file;
Packit Service 1d0348
	char		 closed;
Packit Service 1d0348
	char		 fatal;
Packit Service 1d0348
};
Packit Service 1d0348
Packit Service 1d0348
/*
Packit Service 1d0348
 * The client looks a lot like a filter, so we just wrap it here.
Packit Service 1d0348
 *
Packit Service 1d0348
 * TODO: Make archive_read_filter and archive_read_client identical so
Packit Service 1d0348
 * that users of the library can easily register their own
Packit Service 1d0348
 * transformation filters.  This will probably break the API/ABI and
Packit Service 1d0348
 * so should be deferred at least until libarchive 3.0.
Packit Service 1d0348
 */
Packit Service 1d0348
struct archive_read_data_node {
Packit Service 1d0348
	int64_t begin_position;
Packit Service 1d0348
	int64_t total_size;
Packit Service 1d0348
	void *data;
Packit Service 1d0348
};
Packit Service 1d0348
struct archive_read_client {
Packit Service 1d0348
	archive_open_callback	*opener;
Packit Service 1d0348
	archive_read_callback	*reader;
Packit Service 1d0348
	archive_skip_callback	*skipper;
Packit Service 1d0348
	archive_seek_callback	*seeker;
Packit Service 1d0348
	archive_close_callback	*closer;
Packit Service 1d0348
	archive_switch_callback *switcher;
Packit Service 1d0348
	unsigned int nodes;
Packit Service 1d0348
	unsigned int cursor;
Packit Service 1d0348
	int64_t position;
Packit Service 1d0348
	struct archive_read_data_node *dataset;
Packit Service 1d0348
};
Packit Service 1d0348
struct archive_read_passphrase {
Packit Service 1d0348
	char	*passphrase;
Packit Service 1d0348
	struct archive_read_passphrase *next;
Packit Service 1d0348
};
Packit Service 1d0348
Packit Service 1d0348
struct archive_read_extract {
Packit Service 1d0348
	struct archive *ad; /* archive_write_disk object */
Packit Service 1d0348
Packit Service 1d0348
	/* Progress function invoked during extract. */
Packit Service 1d0348
	void			(*extract_progress)(void *);
Packit Service 1d0348
	void			 *extract_progress_user_data;
Packit Service 1d0348
};
Packit Service 1d0348
Packit Service 1d0348
struct archive_read {
Packit Service 1d0348
	struct archive	archive;
Packit Service 1d0348
Packit Service 1d0348
	struct archive_entry	*entry;
Packit Service 1d0348
Packit Service 1d0348
	/* Dev/ino of the archive being read/written. */
Packit Service 1d0348
	int		  skip_file_set;
Packit Service 1d0348
	int64_t		  skip_file_dev;
Packit Service 1d0348
	int64_t		  skip_file_ino;
Packit Service 1d0348
Packit Service 1d0348
	/* Callbacks to open/read/write/close client archive streams. */
Packit Service 1d0348
	struct archive_read_client client;
Packit Service 1d0348
Packit Service 1d0348
	/* Registered filter bidders. */
Packit Service 1d0348
	struct archive_read_filter_bidder bidders[16];
Packit Service 1d0348
Packit Service 1d0348
	/* Last filter in chain */
Packit Service 1d0348
	struct archive_read_filter *filter;
Packit Service 1d0348
Packit Service 1d0348
	/* Whether to bypass filter bidding process */
Packit Service 1d0348
	int bypass_filter_bidding;
Packit Service 1d0348
Packit Service 1d0348
	/* File offset of beginning of most recently-read header. */
Packit Service 1d0348
	int64_t		  header_position;
Packit Service 1d0348
Packit Service 1d0348
	/* Nodes and offsets of compressed data block */
Packit Service 1d0348
	unsigned int data_start_node;
Packit Service 1d0348
	unsigned int data_end_node;
Packit Service 1d0348
Packit Service 1d0348
	/*
Packit Service 1d0348
	 * Format detection is mostly the same as compression
Packit Service 1d0348
	 * detection, with one significant difference: The bidders
Packit Service 1d0348
	 * use the read_ahead calls above to examine the stream rather
Packit Service 1d0348
	 * than having the supervisor hand them a block of data to
Packit Service 1d0348
	 * examine.
Packit Service 1d0348
	 */
Packit Service 1d0348
Packit Service 1d0348
	struct archive_format_descriptor {
Packit Service 1d0348
		void	 *data;
Packit Service 1d0348
		const char *name;
Packit Service 1d0348
		int	(*bid)(struct archive_read *, int best_bid);
Packit Service 1d0348
		int	(*options)(struct archive_read *, const char *key,
Packit Service 1d0348
		    const char *value);
Packit Service 1d0348
		int	(*read_header)(struct archive_read *, struct archive_entry *);
Packit Service 1d0348
		int	(*read_data)(struct archive_read *, const void **, size_t *, int64_t *);
Packit Service 1d0348
		int	(*read_data_skip)(struct archive_read *);
Packit Service 1d0348
		int64_t	(*seek_data)(struct archive_read *, int64_t, int);
Packit Service 1d0348
		int	(*cleanup)(struct archive_read *);
Packit Service 1d0348
		int	(*format_capabilties)(struct archive_read *);
Packit Service 1d0348
		int	(*has_encrypted_entries)(struct archive_read *);
Packit Service 1d0348
	}	formats[16];
Packit Service 1d0348
	struct archive_format_descriptor	*format; /* Active format. */
Packit Service 1d0348
Packit Service 1d0348
	/*
Packit Service 1d0348
	 * Various information needed by archive_extract.
Packit Service 1d0348
	 */
Packit Service 1d0348
	struct archive_read_extract		*extract;
Packit Service 1d0348
	int			(*cleanup_archive_extract)(struct archive_read *);
Packit Service 1d0348
Packit Service 1d0348
	/*
Packit Service 1d0348
	 * Decryption passphrase.
Packit Service 1d0348
	 */
Packit Service 1d0348
	struct {
Packit Service 1d0348
		struct archive_read_passphrase *first;
Packit Service 1d0348
		struct archive_read_passphrase **last;
Packit Service 1d0348
		int candidate;
Packit Service 1d0348
		archive_passphrase_callback *callback;
Packit Service 1d0348
		void *client_data;
Packit Service 1d0348
	}		passphrases;
Packit Service 1d0348
};
Packit Service 1d0348
Packit Service 1d0348
int	__archive_read_register_format(struct archive_read *a,
Packit Service 1d0348
		void *format_data,
Packit Service 1d0348
		const char *name,
Packit Service 1d0348
		int (*bid)(struct archive_read *, int),
Packit Service 1d0348
		int (*options)(struct archive_read *, const char *, const char *),
Packit Service 1d0348
		int (*read_header)(struct archive_read *, struct archive_entry *),
Packit Service 1d0348
		int (*read_data)(struct archive_read *, const void **, size_t *, int64_t *),
Packit Service 1d0348
		int (*read_data_skip)(struct archive_read *),
Packit Service 1d0348
		int64_t (*seek_data)(struct archive_read *, int64_t, int),
Packit Service 1d0348
		int (*cleanup)(struct archive_read *),
Packit Service 1d0348
		int (*format_capabilities)(struct archive_read *),
Packit Service 1d0348
		int (*has_encrypted_entries)(struct archive_read *));
Packit Service 1d0348
Packit Service 1d0348
int __archive_read_get_bidder(struct archive_read *a,
Packit Service 1d0348
    struct archive_read_filter_bidder **bidder);
Packit Service 1d0348
Packit Service 1d0348
const void *__archive_read_ahead(struct archive_read *, size_t, ssize_t *);
Packit Service 1d0348
const void *__archive_read_filter_ahead(struct archive_read_filter *,
Packit Service 1d0348
    size_t, ssize_t *);
Packit Service 1d0348
int64_t	__archive_read_seek(struct archive_read*, int64_t, int);
Packit Service 1d0348
int64_t	__archive_read_filter_seek(struct archive_read_filter *, int64_t, int);
Packit Service 1d0348
int64_t	__archive_read_consume(struct archive_read *, int64_t);
Packit Service 1d0348
int64_t	__archive_read_filter_consume(struct archive_read_filter *, int64_t);
Packit Service 1d0348
int __archive_read_program(struct archive_read_filter *, const char *);
Packit Service 1d0348
void __archive_read_free_filters(struct archive_read *);
Packit Service 1d0348
struct archive_read_extract *__archive_read_get_extract(struct archive_read *);
Packit Service 1d0348
Packit Service 1d0348
Packit Service 1d0348
/*
Packit Service 1d0348
 * Get a decryption passphrase.
Packit Service 1d0348
 */
Packit Service 1d0348
void __archive_read_reset_passphrase(struct archive_read *a);
Packit Service 1d0348
const char * __archive_read_next_passphrase(struct archive_read *a);
Packit Service 1d0348
#endif