コード例 #1
0
int
archive_read_support_filter_all(struct archive *a)
{
	archive_check_magic(a, ARCHIVE_READ_MAGIC,
	    ARCHIVE_STATE_NEW, "archive_read_support_filter_all");

	/* Bzip falls back to "bunzip2" command-line */
	archive_read_support_filter_bzip2(a);
	/* The decompress code doesn't use an outside library. */
	archive_read_support_filter_compress(a);
	/* Gzip decompress falls back to "gzip -d" command-line. */
	archive_read_support_filter_gzip(a);
	/* Lzip falls back to "unlzip" command-line program. */
	archive_read_support_filter_lzip(a);
	/* The LZMA file format has a very weak signature, so it
	 * may not be feasible to keep this here, but we'll try.
	 * This will come back out if there are problems. */
	/* Lzma falls back to "unlzma" command-line program. */
	archive_read_support_filter_lzma(a);
	/* Xz falls back to "unxz" command-line program. */
	archive_read_support_filter_xz(a);
	/* The decode code doesn't use an outside library. */
	archive_read_support_filter_uu(a);
	/* The decode code doesn't use an outside library. */
	archive_read_support_filter_rpm(a);
	/* The decode code always uses "lrzip -q -d" command-line. */
	archive_read_support_filter_lrzip(a);
	/* Lzop decompress falls back to "lzop -d" command-line. */
	archive_read_support_filter_lzop(a);
	/* The decode code always uses "grzip -d" command-line. */
	archive_read_support_filter_grzip(a);
	/* Lz4 falls back to "lz4 -d" command-line program. */
	archive_read_support_filter_lz4(a);
	/* Zstd falls back to "zstd -d" command-line program. */
	archive_read_support_filter_zstd(a);

	/* Note: We always return ARCHIVE_OK here, even if some of the
	 * above return ARCHIVE_WARN.  The intent here is to enable
	 * "as much as possible."  Clients who need specific
	 * compression should enable those individually so they can
	 * verify the level of support. */
	/* Clear any warning messages set by the above functions. */
	archive_clear_error(a);
	return (ARCHIVE_OK);
}
コード例 #2
0
int
archive_read_append_filter(struct archive *_a, int code)
{
    int r1, r2, number_bidders, i;
    char str[20];
    struct archive_read_filter_bidder *bidder;
    struct archive_read_filter *filter;
    struct archive_read *a = (struct archive_read *)_a;

    r1 = r2 = (ARCHIVE_OK);
    switch (code)
    {
    case ARCHIVE_FILTER_NONE:
        /* No filter to add, so do nothing.
         * NOTE: An initial "NONE" type filter is always set at the end of the
         * filter chain.
         */
        r1 = (ARCHIVE_OK);
        break;
    case ARCHIVE_FILTER_GZIP:
        strcpy(str, "gzip");
        r1 = archive_read_support_filter_gzip(_a);
        break;
    case ARCHIVE_FILTER_BZIP2:
        strcpy(str, "bzip2");
        r1 = archive_read_support_filter_bzip2(_a);
        break;
    case ARCHIVE_FILTER_COMPRESS:
        strcpy(str, "compress (.Z)");
        r1 = archive_read_support_filter_compress(_a);
        break;
    case ARCHIVE_FILTER_PROGRAM:
        archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
                          "Cannot append program filter using archive_read_append_filter");
        return (ARCHIVE_FATAL);
    case ARCHIVE_FILTER_LZMA:
        strcpy(str, "lzma");
        r1 = archive_read_support_filter_lzma(_a);
        break;
    case ARCHIVE_FILTER_XZ:
        strcpy(str, "xz");
        r1 = archive_read_support_filter_xz(_a);
        break;
    case ARCHIVE_FILTER_UU:
        strcpy(str, "uu");
        r1 = archive_read_support_filter_uu(_a);
        break;
    case ARCHIVE_FILTER_RPM:
        strcpy(str, "rpm");
        r1 = archive_read_support_filter_rpm(_a);
        break;
    case ARCHIVE_FILTER_LZIP:
        strcpy(str, "lzip");
        r1 = archive_read_support_filter_lzip(_a);
        break;
    case ARCHIVE_FILTER_LRZIP:
        strcpy(str, "lrzip");
        r1 = archive_read_support_filter_lrzip(_a);
        break;
    default:
        archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
                          "Invalid filter code specified");
        return (ARCHIVE_FATAL);
    }

    if (code != ARCHIVE_FILTER_NONE)
    {
        number_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);

        bidder = a->bidders;
        for (i = 0; i < number_bidders; i++, bidder++)
        {
            if (!bidder->name || !strcmp(bidder->name, str))
                break;
        }
        if (!bidder->name || strcmp(bidder->name, str))
        {
            archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
                              "Internal error: Unable to append filter");
            return (ARCHIVE_FATAL);
        }

        filter
            = (struct archive_read_filter *)calloc(1, sizeof(*filter));
        if (filter == NULL)
        {
            archive_set_error(&a->archive, ENOMEM, "Out of memory");
            return (ARCHIVE_FATAL);
        }
        filter->bidder = bidder;
        filter->archive = a;
        filter->upstream = a->filter;
        a->filter = filter;
        r2 = (bidder->init)(a->filter);
        if (r2 != ARCHIVE_OK) {
            __archive_read_close_filters(a);
            __archive_read_free_filters(a);
            return (ARCHIVE_FATAL);
        }
    }

    a->bypass_filter_bidding = 1;
    return (r1 < r2) ? r1 : r2;
}