busybox/archival/libarchive/filter_accept_list_reassign.c
<<
>>
Prefs
   1/* vi: set sw=4 ts=4: */
   2/*
   3 * Copyright (C) 2002 by Glenn McGrath
   4 *
   5 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
   6 */
   7#include "libbb.h"
   8#include "bb_archive.h"
   9
  10/* Built and used only if ENABLE_DPKG || ENABLE_DPKG_DEB */
  11
  12/*
  13 * Reassign the subarchive metadata parser based on the filename extension
  14 * e.g. if its a .tar.gz modify archive_handle->sub_archive to process a .tar.gz
  15 * or if its a .tar.bz2 make archive_handle->sub_archive handle that
  16 */
  17char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
  18{
  19        /* Check the file entry is in the accept list */
  20        if (find_list_entry(archive_handle->accept, archive_handle->file_header->name)) {
  21                const char *name_ptr;
  22
  23                /* Find extension */
  24                name_ptr = strrchr(archive_handle->file_header->name, '.');
  25                if (!name_ptr)
  26                        return EXIT_FAILURE;
  27                name_ptr++;
  28
  29                /* Modify the subarchive handler based on the extension */
  30                if (strcmp(name_ptr, "tar") == 0) {
  31                        archive_handle->dpkg__action_data_subarchive = get_header_tar;
  32                        return EXIT_SUCCESS;
  33                }
  34                if (ENABLE_FEATURE_SEAMLESS_GZ
  35                 && strcmp(name_ptr, "gz") == 0
  36                ) {
  37                        archive_handle->dpkg__action_data_subarchive = get_header_tar_gz;
  38                        return EXIT_SUCCESS;
  39                }
  40                if (ENABLE_FEATURE_SEAMLESS_BZ2
  41                 && strcmp(name_ptr, "bz2") == 0
  42                ) {
  43                        archive_handle->dpkg__action_data_subarchive = get_header_tar_bz2;
  44                        return EXIT_SUCCESS;
  45                }
  46                if (ENABLE_FEATURE_SEAMLESS_LZMA
  47                 && strcmp(name_ptr, "lzma") == 0
  48                ) {
  49                        archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma;
  50                        return EXIT_SUCCESS;
  51                }
  52                if (ENABLE_FEATURE_SEAMLESS_XZ
  53                 && strcmp(name_ptr, "xz") == 0
  54                ) {
  55                        archive_handle->dpkg__action_data_subarchive = get_header_tar_xz;
  56                        return EXIT_SUCCESS;
  57                }
  58        }
  59        return EXIT_FAILURE;
  60}
  61