Properly set a clear error message when archive_{write,read}_set_options failed.
int magic, const char *fn, option_handler use_option)
{
const char *mp, *op, *vp;
+ int r;
archive_check_magic(a, magic, ARCHIVE_STATE_NEW, fn);
if (op == NULL && vp == NULL)
return (ARCHIVE_OK);
- if (op == NULL)
+ if (op == NULL) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC, "Empty option");
return (ARCHIVE_FAILED);
+ }
- return use_option(a, mp, op, vp);
+ r = use_option(a, mp, op, vp);
+ if (r == ARCHIVE_WARN - 1) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Unknown module name: `%s'", mp);
+ return (ARCHIVE_FAILED);
+ }
+ if (r == ARCHIVE_WARN) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Undefined option: `%s%s%s%s%s%s'",
+ vp?"":"!", mp?mp:"", mp?":":"", op, vp?"=":"", vp?vp:"");
+ return (ARCHIVE_FAILED);
+ }
+ return (r);
}
int
free(data);
return (ARCHIVE_FATAL);
}
+ if (r == ARCHIVE_FAILED && mod != NULL) {
+ free(data);
+ return (ARCHIVE_FAILED);
+ }
+ if (r == ARCHIVE_WARN - 1) {
+ /* The module name is wrong. */
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Unknown module name: `%s'", mod);
+ free(data);
+ return (ARCHIVE_FAILED);
+ }
+ if (r == ARCHIVE_WARN) {
+ /* The option name is wrong. No-one used this. */
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Undefined option: `%s%s%s'",
+ mod?mod:"", mod?":":"", opt);
+ free(data);
+ return (ARCHIVE_FAILED);
+ }
if (r == ARCHIVE_OK)
anyok = 1;
else
struct archive_read *a = (struct archive_read *)_a;
struct archive_format_descriptor *format;
size_t i;
- int r, rv = ARCHIVE_FAILED;
+ int r, rv = ARCHIVE_WARN;
for (i = 0; i < sizeof(a->formats)/sizeof(a->formats[0]); i++) {
format = &a->formats[i];
if (r == ARCHIVE_OK)
rv = ARCHIVE_OK;
}
+ /* If the format name didn't match, return a special code for
+ * _archive_set_option[s]. */
+ if (rv == ARCHIVE_WARN && m != NULL)
+ rv = ARCHIVE_WARN - 1;
return (rv);
}
struct archive_read *a = (struct archive_read *)_a;
struct archive_read_filter *filter;
struct archive_read_filter_bidder *bidder;
- int r, rv = ARCHIVE_FAILED;
+ int r, rv = ARCHIVE_WARN;
for (filter = a->filter; filter != NULL; filter = filter->upstream) {
bidder = filter->bidder;
if (r == ARCHIVE_OK)
rv = ARCHIVE_OK;
}
+ /* If the filter name didn't match, return a special code for
+ * _archive_set_option[s]. */
+ if (rv == ARCHIVE_WARN && m != NULL)
+ rv = ARCHIVE_WARN - 1;
return (rv);
}
/*-
- * Copyright (c) 2010-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2010-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "cab: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
/*-
* Copyright (c) 2003-2007 Tim Kientzle
- * Copyright (c) 2010-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2010-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
if (strcmp(key, "compat-2x") == 0) {
/* Handle filnames as libarchive 2.x */
cpio->init_default_conversion = (val != NULL)?1:0;
- ret = ARCHIVE_OK;
+ return (ARCHIVE_OK);
} else if (strcmp(key, "hdrcharset") == 0) {
if (val == NULL || val[0] == 0)
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "cpio: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
/*-
- * Copyright (c) 2008-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2008-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "lha: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "rar: unknown keyword ``%s''", key);
-
- return (ret);
+ return (ret);
+ }
+
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
/*-
* Copyright (c) 2003-2007 Tim Kientzle
- * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
/* Handle UTF-8 filnames as libarchive 2.x */
tar->compat_2x = (val != NULL)?1:0;
tar->init_default_conversion = tar->compat_2x;
- ret = ARCHIVE_OK;
+ return (ARCHIVE_OK);
} else if (strcmp(key, "hdrcharset") == 0) {
if (val == NULL || val[0] == 0)
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "tar: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
/* utility function- this exists to centralize the logic of tracking
/*-
* Copyright (c) 2004 Tim Kientzle
- * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
if (strcmp(key, "compat-2x") == 0) {
/* Handle filnames as libarchive 2.x */
zip->init_default_conversion = (val != NULL) ? 1 : 0;
- ret = ARCHIVE_OK;
+ return (ARCHIVE_OK);
} else if (strcmp(key, "hdrcharset") == 0) {
if (val == NULL || val[0] == 0)
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
} else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "zip: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
return (ARCHIVE_OK);
}
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
return (ARCHIVE_WARN);
}
data->compression_level = value[0] - '0';
return (ARCHIVE_OK);
}
+
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
return (ARCHIVE_WARN);
}
/*-
- * Copyright (c) 2009,2010 Michihiro NAKAJIMA
* Copyright (c) 2003-2010 Tim Kientzle
+ * Copyright (c) 2009-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
return (ARCHIVE_OK);
}
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
return (ARCHIVE_WARN);
}
return (ARCHIVE_OK);
}
- return (ARCHIVE_FAILED);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "%s: unknown keyword ``%s''", a->format_name, key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
/*
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "%s: unknown keyword ``%s''", a->format_name, key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static struct archive_string_conv *
/*-
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* Author: Jonas Gastal <jgastal@profusion.mobi>
- * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
*
* All rights reserved.
*
gnutar = (struct gnutar *)calloc(1, sizeof(*gnutar));
if (gnutar == NULL) {
- archive_set_error(&a->archive, ENOMEM, "Can't allocate gnutar data");
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate gnutar data");
return (ARCHIVE_FATAL);
}
a->format_data = gnutar;
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "%s: unknown keyword ``%s''", a->format_name, key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
/*-
- * Copyright (c) 2009-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2009-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
break;
}
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
+
invalid_value:
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"Invalid value for option ``%s''", key);
/*-
- * Copyright (c) 2009,2011 Michihiro NAKAJIMA
* Copyright (c) 2008 Joerg Sonnenberger
+ * Copyright (c) 2009-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
return (ARCHIVE_OK);
}
- return (ARCHIVE_FAILED);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
int
/*-
* Copyright (c) 2003-2007 Tim Kientzle
- * Copyright (c) 2010-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2010-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
} else
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"pax: invalid charset name");
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "pax: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
/*
/*-
* Copyright (c) 2003-2007 Tim Kientzle
- * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "%s: unknown keyword ``%s''", a->format_name, key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
/*-
- * Copyright (c) 2010-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2010-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
return (ARCHIVE_OK);
}
- return (ARCHIVE_FAILED);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
/*-
* Copyright (c) 2008 Anselm Strauss
* Copyright (c) 2009 Joerg Sonnenberger
- * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
zip->compression = COMPRESSION_STORE;
ret = ARCHIVE_OK;
}
+ return (ret);
} else if (strcmp(key, "hdrcharset") == 0) {
if (val == NULL || val[0] == 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "%s: unknown keyword ``%s''", a->format_name, key);
- return (ret);
+ return (ret);
+ }
+
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
int
if (a->format_name == NULL)
return (ARCHIVE_FAILED);
+ /* If the format name didn't match, return a special code for
+ * _archive_set_option[s]. */
if (m != NULL && strcmp(m, a->format_name) != 0)
- return (ARCHIVE_FAILED);
+ return (ARCHIVE_WARN - 1);
if (a->format_options == NULL)
- return (ARCHIVE_FAILED);
+ return (ARCHIVE_WARN);
return a->format_options(a, o, v);
}
{
struct archive_write *a = (struct archive_write *)_a;
struct archive_write_filter *filter;
- int r, rv = ARCHIVE_FAILED;
+ int r, rv = ARCHIVE_WARN;
for (filter = a->filter_first; filter != NULL; filter = filter->next_filter) {
if (filter->options == NULL)
if (r == ARCHIVE_OK)
rv = ARCHIVE_OK;
}
+ /* If the filter name didn't match, return a special code for
+ * _archive_set_option[s]. */
+ if (rv == ARCHIVE_WARN && m != NULL)
+ rv = ARCHIVE_WARN - 1;
return (rv);
}
test(int pristine)
{
struct archive* a = archive_read_new();
- int halfempty_options_rv = pristine ? ARCHIVE_WARN : ARCHIVE_OK;
+ int halfempty_options_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK;
int known_option_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK;
- int mixed_options_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_WARN;
if (!pristine) {
archive_read_support_filter_all(a);
archive_read_support_format_all(a);
- }
+ }
/* NULL and "" denote `no option', so they're ok no matter
* what, if any, formats are registered */
/* unknown modules and options */
should(a, ARCHIVE_FAILED, "fubar:snafu");
+ assertEqualString("Unknown module name: `fubar'",
+ archive_error_string(a));
should(a, ARCHIVE_FAILED, "fubar:snafu=betcha");
+ assertEqualString("Unknown module name: `fubar'",
+ archive_error_string(a));
/* unknown modules and options */
should(a, ARCHIVE_FAILED, "snafu");
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
should(a, ARCHIVE_FAILED, "snafu=betcha");
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
- /* ARCHIVE_OK with iso9660 loaded, ARCHIVE_WARN otherwise */
+ /* ARCHIVE_OK with iso9660 loaded, ARCHIVE_FAILED otherwise */
should(a, known_option_rv, "iso9660:joliet");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "iso9660:joliet");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "!joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, ARCHIVE_OK, ",");
should(a, ARCHIVE_OK, ",,");
should(a, halfempty_options_rv, ",joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, halfempty_options_rv, "joliet,");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
- should(a, mixed_options_rv, "joliet,snafu");
+ should(a, ARCHIVE_FAILED, "joliet,snafu");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ } else {
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
+ }
+
+ should(a, ARCHIVE_FAILED, "iso9660:snafu");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ } else {
+ assertEqualString("Undefined option: `iso9660:snafu'",
+ archive_error_string(a));
+ }
archive_read_finish(a);
}
test(int pristine)
{
struct archive* a = archive_write_new();
- int halfempty_options_rv = pristine ? ARCHIVE_WARN : ARCHIVE_OK;
+ int halfempty_options_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK;
int known_option_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK;
- int mixed_options_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_WARN;
if (!pristine) {
archive_write_set_compression_gzip(a);
archive_write_set_format_iso9660(a);
- }
+ }
/* NULL and "" denote `no option', so they're ok no matter
* what, if any, formats are registered */
/* unknown modules and options */
should(a, ARCHIVE_FAILED, "fubar:snafu");
+ assertEqualString("Unknown module name: `fubar'",
+ archive_error_string(a));
should(a, ARCHIVE_FAILED, "fubar:snafu=betcha");
+ assertEqualString("Unknown module name: `fubar'",
+ archive_error_string(a));
/* unknown modules and options */
should(a, ARCHIVE_FAILED, "snafu");
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
should(a, ARCHIVE_FAILED, "snafu=betcha");
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
- /* ARCHIVE_OK with iso9660 loaded, ARCHIVE_WARN otherwise */
+ /* ARCHIVE_OK with iso9660 loaded, ARCHIVE_FAILED otherwise */
should(a, known_option_rv, "iso9660:joliet");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "iso9660:joliet");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "!joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, ARCHIVE_OK, ",");
should(a, ARCHIVE_OK, ",,");
should(a, halfempty_options_rv, ",joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, halfempty_options_rv, "joliet,");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
- should(a, mixed_options_rv, "joliet,snafu");
+ should(a, ARCHIVE_FAILED, "joliet,snafu");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ } else {
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
+ }
+
+ should(a, ARCHIVE_FAILED, "iso9660:snafu");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ } else {
+ assertEqualString("Undefined option: `iso9660:snafu'",
+ archive_error_string(a));
+ }
archive_write_finish(a);
}