archive_write_add_filter_by_name.c revision 316337
1109998Smarkm/*- 2194206Ssimon * Copyright (c) 2003-2007 Tim Kientzle 3109998Smarkm * Copyright (c) 2012 Michihiro NAKAJIMA 4109998Smarkm * All rights reserved. 5109998Smarkm * 6238405Sjkim * Redistribution and use in source and binary forms, with or without 7109998Smarkm * modification, are permitted provided that the following conditions 8109998Smarkm * are met: 9109998Smarkm * 1. Redistributions of source code must retain the above copyright 10109998Smarkm * notice, this list of conditions and the following disclaimer. 11109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright 12109998Smarkm * notice, this list of conditions and the following disclaimer in the 13109998Smarkm * documentation and/or other materials provided with the distribution. 14109998Smarkm * 15109998Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16109998Smarkm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17109998Smarkm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18109998Smarkm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19109998Smarkm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20109998Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21109998Smarkm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22109998Smarkm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23109998Smarkm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24109998Smarkm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25109998Smarkm */ 26109998Smarkm 27109998Smarkm#include "archive_platform.h" 28109998Smarkm__FBSDID("$FreeBSD$"); 29109998Smarkm 30109998Smarkm#ifdef HAVE_SYS_TYPES_H 31109998Smarkm#include <sys/types.h> 32109998Smarkm#endif 33109998Smarkm 34109998Smarkm#ifdef HAVE_ERRNO_H 35109998Smarkm#include <errno.h> 36109998Smarkm#endif 37109998Smarkm#ifdef HAVE_STRING_H 38109998Smarkm#include <string.h> 39109998Smarkm#endif 40109998Smarkm 41109998Smarkm#include "archive.h" 42109998Smarkm#include "archive_private.h" 43109998Smarkm 44109998Smarkm/* A table that maps names to functions. */ 45109998Smarkmstatic const 46109998Smarkmstruct { const char *name; int (*setter)(struct archive *); } names[] = 47109998Smarkm{ 48109998Smarkm { "b64encode", archive_write_add_filter_b64encode }, 49109998Smarkm { "bzip2", archive_write_add_filter_bzip2 }, 50109998Smarkm { "compress", archive_write_add_filter_compress }, 51109998Smarkm { "grzip", archive_write_add_filter_grzip }, 52109998Smarkm { "gzip", archive_write_add_filter_gzip }, 53109998Smarkm { "lrzip", archive_write_add_filter_lrzip }, 54109998Smarkm { "lz4", archive_write_add_filter_lz4 }, 55109998Smarkm { "lzip", archive_write_add_filter_lzip }, 56109998Smarkm { "lzma", archive_write_add_filter_lzma }, 57109998Smarkm { "lzop", archive_write_add_filter_lzop }, 5855714Skris { "uuencode", archive_write_add_filter_uuencode }, 5955714Skris { "xz", archive_write_add_filter_xz }, 6055714Skris { NULL, NULL } 6155714Skris}; 6255714Skris 63109998Smarkmint 64205128Ssimonarchive_write_add_filter_by_name(struct archive *a, const char *name) 6555714Skris{ 66109998Smarkm int i; 67238405Sjkim 68238405Sjkim for (i = 0; names[i].name != NULL; i++) { 6955714Skris if (strcmp(name, names[i].name) == 0) 70109998Smarkm return ((names[i].setter)(a)); 71109998Smarkm } 72109998Smarkm 73238405Sjkim archive_set_error(a, EINVAL, "No such filter '%s'", name); 74238405Sjkim a->state = ARCHIVE_STATE_FATAL; 75238405Sjkim return (ARCHIVE_FATAL); 76238405Sjkim} 77238405Sjkim