|
|
538efe |
From 9a99549f5df6ef69dd1d2b509c13aaff4e431742 Mon Sep 17 00:00:00 2001
|
|
|
538efe |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
538efe |
Date: Tue, 19 May 2020 16:11:28 +0100
|
|
|
538efe |
Subject: [PATCH 19/19] common/include: Add locale-safe ascii_strcasecmp and
|
|
|
538efe |
ascii_strncasecmp.
|
|
|
538efe |
|
|
|
538efe |
These are derived from the FreeBSD functions here:
|
|
|
538efe |
https://github.com/freebsd/freebsd/blob/master/sys/libkern/strcasecmp.c
|
|
|
538efe |
|
|
|
538efe |
Thanks: Eric Blake.
|
|
|
538efe |
(cherry picked from commit 46a29b8e91d69e812d78df53e91b526a560000fe)
|
|
|
538efe |
---
|
|
|
538efe |
.gitignore | 1 +
|
|
|
538efe |
common/include/Makefile.am | 6 +++
|
|
|
538efe |
common/include/ascii-ctype.h | 6 +++
|
|
|
538efe |
common/include/ascii-string.h | 77 ++++++++++++++++++++++++++++
|
|
|
538efe |
common/include/test-ascii-string.c | 79 +++++++++++++++++++++++++++++
|
|
|
538efe |
plugins/curl/curl.c | 7 +--
|
|
|
538efe |
plugins/info/info.c | 17 ++++---
|
|
|
538efe |
plugins/nbd/nbd.c | 8 +--
|
|
|
538efe |
plugins/partitioning/partitioning.c | 10 ++--
|
|
|
538efe |
plugins/sh/call.c | 25 ++++-----
|
|
|
538efe |
server/main.c | 8 +--
|
|
|
538efe |
server/public.c | 21 ++++----
|
|
|
538efe |
12 files changed, 222 insertions(+), 43 deletions(-)
|
|
|
538efe |
create mode 100644 common/include/ascii-string.h
|
|
|
538efe |
create mode 100644 common/include/test-ascii-string.c
|
|
|
538efe |
|
|
|
538efe |
diff --git a/.gitignore b/.gitignore
|
|
|
538efe |
index 523894b7..aa148f04 100644
|
|
|
538efe |
--- a/.gitignore
|
|
|
538efe |
+++ b/.gitignore
|
|
|
538efe |
@@ -27,6 +27,7 @@ Makefile.in
|
|
|
538efe |
/autom4te.cache
|
|
|
538efe |
/common/bitmap/test-bitmap
|
|
|
538efe |
/common/include/test-ascii-ctype
|
|
|
538efe |
+/common/include/test-ascii-string
|
|
|
538efe |
/common/include/test-byte-swapping
|
|
|
538efe |
/common/include/test-current-dir-name
|
|
|
538efe |
/common/include/test-isaligned
|
|
|
538efe |
diff --git a/common/include/Makefile.am b/common/include/Makefile.am
|
|
|
538efe |
index d7b0d7a8..eff71863 100644
|
|
|
538efe |
--- a/common/include/Makefile.am
|
|
|
538efe |
+++ b/common/include/Makefile.am
|
|
|
538efe |
@@ -35,6 +35,7 @@ include $(top_srcdir)/common-rules.mk
|
|
|
538efe |
# plugins and/or filters. They are not installed.
|
|
|
538efe |
EXTRA_DIST = \
|
|
|
538efe |
ascii-ctype.h \
|
|
|
538efe |
+ ascii-string.h \
|
|
|
538efe |
byte-swapping.h \
|
|
|
538efe |
exit-with-parent.h \
|
|
|
538efe |
get-current-dir-name.h \
|
|
|
538efe |
@@ -52,6 +53,7 @@ EXTRA_DIST = \
|
|
|
538efe |
|
|
|
538efe |
TESTS = \
|
|
|
538efe |
test-ascii-ctype \
|
|
|
538efe |
+ test-ascii-string \
|
|
|
538efe |
test-byte-swapping \
|
|
|
538efe |
test-current-dir-name \
|
|
|
538efe |
test-isaligned \
|
|
|
538efe |
@@ -68,6 +70,10 @@ test_ascii_ctype_SOURCES = test-ascii-ctype.c ascii-ctype.h
|
|
|
538efe |
test_ascii_ctype_CPPFLAGS = -I$(srcdir)
|
|
|
538efe |
test_ascii_ctype_CFLAGS = $(WARNINGS_CFLAGS)
|
|
|
538efe |
|
|
|
538efe |
+test_ascii_string_SOURCES = test-ascii-string.c ascii-string.h
|
|
|
538efe |
+test_ascii_string_CPPFLAGS = -I$(srcdir)
|
|
|
538efe |
+test_ascii_string_CFLAGS = $(WARNINGS_CFLAGS)
|
|
|
538efe |
+
|
|
|
538efe |
test_byte_swapping_SOURCES = test-byte-swapping.c byte-swapping.h
|
|
|
538efe |
test_byte_swapping_CPPFLAGS = -I$(srcdir)
|
|
|
538efe |
test_byte_swapping_CFLAGS = $(WARNINGS_CFLAGS)
|
|
|
538efe |
diff --git a/common/include/ascii-ctype.h b/common/include/ascii-ctype.h
|
|
|
538efe |
index 5e8bf237..a700563e 100644
|
|
|
538efe |
--- a/common/include/ascii-ctype.h
|
|
|
538efe |
+++ b/common/include/ascii-ctype.h
|
|
|
538efe |
@@ -49,6 +49,9 @@
|
|
|
538efe |
#define ascii_isspace(c) \
|
|
|
538efe |
((c) == '\t' || (c) == '\n' || (c) == '\f' || (c) == '\r' || (c) == ' ')
|
|
|
538efe |
|
|
|
538efe |
+#define ascii_isupper(c) \
|
|
|
538efe |
+ ((c) >= 'A' && (c) <= 'Z')
|
|
|
538efe |
+
|
|
|
538efe |
#define ascii_isxdigit(c) \
|
|
|
538efe |
((c) == '0' || (c) == '1' || (c) == '2' || (c) == '3' || (c) == '4' || \
|
|
|
538efe |
(c) == '5' || (c) == '6' || (c) == '7' || (c) == '8' || (c) == '9' || \
|
|
|
538efe |
@@ -57,4 +60,7 @@
|
|
|
538efe |
(c) == 'A' || (c) == 'B' || (c) == 'C' || \
|
|
|
538efe |
(c) == 'D' || (c) == 'E' || (c) == 'F')
|
|
|
538efe |
|
|
|
538efe |
+#define ascii_tolower(c) \
|
|
|
538efe |
+ (ascii_isupper ((c)) ? (c) - 'A' + 'a' : (c))
|
|
|
538efe |
+
|
|
|
538efe |
#endif /* NBDKIT_ASCII_CTYPE_H */
|
|
|
538efe |
diff --git a/common/include/ascii-string.h b/common/include/ascii-string.h
|
|
|
538efe |
new file mode 100644
|
|
|
538efe |
index 00000000..0a60d5f4
|
|
|
538efe |
--- /dev/null
|
|
|
538efe |
+++ b/common/include/ascii-string.h
|
|
|
538efe |
@@ -0,0 +1,77 @@
|
|
|
538efe |
+/* nbdkit
|
|
|
538efe |
+ * Copyright (C) 2013-2020 Red Hat Inc.
|
|
|
538efe |
+ *
|
|
|
538efe |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
538efe |
+ * modification, are permitted provided that the following conditions are
|
|
|
538efe |
+ * met:
|
|
|
538efe |
+ *
|
|
|
538efe |
+ * * Redistributions of source code must retain the above copyright
|
|
|
538efe |
+ * notice, this list of conditions and the following disclaimer.
|
|
|
538efe |
+ *
|
|
|
538efe |
+ * * Redistributions in binary form must reproduce the above copyright
|
|
|
538efe |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
538efe |
+ * documentation and/or other materials provided with the distribution.
|
|
|
538efe |
+ *
|
|
|
538efe |
+ * * Neither the name of Red Hat nor the names of its contributors may be
|
|
|
538efe |
+ * used to endorse or promote products derived from this software without
|
|
|
538efe |
+ * specific prior written permission.
|
|
|
538efe |
+ *
|
|
|
538efe |
+ * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
|
|
|
538efe |
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
538efe |
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
538efe |
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
|
|
|
538efe |
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
538efe |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
538efe |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
|
538efe |
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
538efe |
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
538efe |
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
538efe |
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
538efe |
+ * SUCH DAMAGE.
|
|
|
538efe |
+ */
|
|
|
538efe |
+
|
|
|
538efe |
+/* Case insensitive string comparison functions (like strcasecmp,
|
|
|
538efe |
+ * strncasecmp) which work correctly in any locale. They can only be
|
|
|
538efe |
+ * used for comparison when one or both strings is 7 bit ASCII.
|
|
|
538efe |
+ */
|
|
|
538efe |
+
|
|
|
538efe |
+#ifndef NBDKIT_ASCII_STRING_H
|
|
|
538efe |
+#define NBDKIT_ASCII_STRING_H
|
|
|
538efe |
+
|
|
|
538efe |
+#include "ascii-ctype.h"
|
|
|
538efe |
+
|
|
|
538efe |
+static inline int
|
|
|
538efe |
+ascii_strcasecmp (const char *s1, const char *s2)
|
|
|
538efe |
+{
|
|
|
538efe |
+ const unsigned char *us1 = (const unsigned char *)s1;
|
|
|
538efe |
+ const unsigned char *us2 = (const unsigned char *)s2;
|
|
|
538efe |
+
|
|
|
538efe |
+ while (ascii_tolower (*us1) == ascii_tolower (*us2)) {
|
|
|
538efe |
+ if (*us1++ == '\0')
|
|
|
538efe |
+ return 0;
|
|
|
538efe |
+ us2++;
|
|
|
538efe |
+ }
|
|
|
538efe |
+
|
|
|
538efe |
+ return ascii_tolower (*us1) - ascii_tolower (*us2);
|
|
|
538efe |
+}
|
|
|
538efe |
+
|
|
|
538efe |
+static inline int
|
|
|
538efe |
+ascii_strncasecmp (const char *s1, const char *s2, size_t n)
|
|
|
538efe |
+{
|
|
|
538efe |
+ if (n != 0) {
|
|
|
538efe |
+ const unsigned char *us1 = (const unsigned char *)s1;
|
|
|
538efe |
+ const unsigned char *us2 = (const unsigned char *)s2;
|
|
|
538efe |
+
|
|
|
538efe |
+ do {
|
|
|
538efe |
+ if (ascii_tolower (*us1) != ascii_tolower (*us2))
|
|
|
538efe |
+ return ascii_tolower (*us1) - ascii_tolower (*us2);
|
|
|
538efe |
+ if (*us1++ == '\0')
|
|
|
538efe |
+ break;
|
|
|
538efe |
+ us2++;
|
|
|
538efe |
+ } while (--n != 0);
|
|
|
538efe |
+ }
|
|
|
538efe |
+
|
|
|
538efe |
+ return 0;
|
|
|
538efe |
+}
|
|
|
538efe |
+
|
|
|
538efe |
+#endif /* NBDKIT_ASCII_STRING_H */
|
|
|
538efe |
diff --git a/common/include/test-ascii-string.c b/common/include/test-ascii-string.c
|
|
|
538efe |
new file mode 100644
|
|
|
538efe |
index 00000000..0fa4a483
|
|
|
538efe |
--- /dev/null
|
|
|
538efe |
+++ b/common/include/test-ascii-string.c
|
|
|
538efe |
@@ -0,0 +1,79 @@
|
|
|
538efe |
+/* nbdkit
|
|
|
538efe |
+ * Copyright (C) 2020 Red Hat Inc.
|
|
|
538efe |
+ *
|
|
|
538efe |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
538efe |
+ * modification, are permitted provided that the following conditions are
|
|
|
538efe |
+ * met:
|
|
|
538efe |
+ *
|
|
|
538efe |
+ * * Redistributions of source code must retain the above copyright
|
|
|
538efe |
+ * notice, this list of conditions and the following disclaimer.
|
|
|
538efe |
+ *
|
|
|
538efe |
+ * * Redistributions in binary form must reproduce the above copyright
|
|
|
538efe |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
538efe |
+ * documentation and/or other materials provided with the distribution.
|
|
|
538efe |
+ *
|
|
|
538efe |
+ * * Neither the name of Red Hat nor the names of its contributors may be
|
|
|
538efe |
+ * used to endorse or promote products derived from this software without
|
|
|
538efe |
+ * specific prior written permission.
|
|
|
538efe |
+ *
|
|
|
538efe |
+ * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
|
|
|
538efe |
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
538efe |
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
538efe |
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
|
|
|
538efe |
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
538efe |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
538efe |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
|
538efe |
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
538efe |
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
538efe |
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
538efe |
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
538efe |
+ * SUCH DAMAGE.
|
|
|
538efe |
+ */
|
|
|
538efe |
+
|
|
|
538efe |
+#include <config.h>
|
|
|
538efe |
+
|
|
|
538efe |
+#include <stdio.h>
|
|
|
538efe |
+#include <stdlib.h>
|
|
|
538efe |
+#include <assert.h>
|
|
|
538efe |
+
|
|
|
538efe |
+#include "ascii-string.h"
|
|
|
538efe |
+
|
|
|
538efe |
+int
|
|
|
538efe |
+main (void)
|
|
|
538efe |
+{
|
|
|
538efe |
+ assert (ascii_strcasecmp ("", "") == 0);
|
|
|
538efe |
+ assert (ascii_strcasecmp ("a", "a") == 0);
|
|
|
538efe |
+ assert (ascii_strcasecmp ("abc", "abc") == 0);
|
|
|
538efe |
+ assert (ascii_strcasecmp ("a", "b") < 0);
|
|
|
538efe |
+ assert (ascii_strcasecmp ("b", "a") > 0);
|
|
|
538efe |
+ assert (ascii_strcasecmp ("aa", "a") > 0);
|
|
|
538efe |
+
|
|
|
538efe |
+ /* Second string contains Turkish dotless lowercase letter 覺. */
|
|
|
538efe |
+ assert (ascii_strcasecmp ("hi", "h覺") != 0);
|
|
|
538efe |
+
|
|
|
538efe |
+ /* Check that we got our rounding behaviour correct. */
|
|
|
538efe |
+ assert (ascii_strcasecmp ("\x1", "\x7f") < 0);
|
|
|
538efe |
+ assert (ascii_strcasecmp ("\x1", "\x80") < 0);
|
|
|
538efe |
+ assert (ascii_strcasecmp ("\x1", "\x81") < 0);
|
|
|
538efe |
+ assert (ascii_strcasecmp ("\x1", "\xff") < 0);
|
|
|
538efe |
+
|
|
|
538efe |
+ assert (ascii_strncasecmp ("", "", 0) == 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("a", "a", 1) == 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("abc", "abc", 3) == 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("abc", "def", 0) == 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("abc", "abd", 2) == 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("a", "b", 1) < 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("b", "a", 1) > 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("aa", "a", 2) > 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("aa", "a", 100) > 0);
|
|
|
538efe |
+
|
|
|
538efe |
+ assert (ascii_strncasecmp ("hi", "h覺", 1) == 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("hi", "h覺", 2) != 0);
|
|
|
538efe |
+
|
|
|
538efe |
+ assert (ascii_strncasecmp ("\x1", "\x7f", 1) < 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("\x1", "\x80", 1) < 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("\x1", "\x81", 1) < 0);
|
|
|
538efe |
+ assert (ascii_strncasecmp ("\x1", "\xff", 1) < 0);
|
|
|
538efe |
+
|
|
|
538efe |
+ exit (EXIT_SUCCESS);
|
|
|
538efe |
+}
|
|
|
538efe |
diff --git a/plugins/curl/curl.c b/plugins/curl/curl.c
|
|
|
538efe |
index ac30cbdd..00f0628a 100644
|
|
|
538efe |
--- a/plugins/curl/curl.c
|
|
|
538efe |
+++ b/plugins/curl/curl.c
|
|
|
538efe |
@@ -58,6 +58,7 @@
|
|
|
538efe |
|
|
|
538efe |
#include "cleanup.h"
|
|
|
538efe |
#include "ascii-ctype.h"
|
|
|
538efe |
+#include "ascii-string.h"
|
|
|
538efe |
|
|
|
538efe |
static const char *url = NULL;
|
|
|
538efe |
static const char *user = NULL;
|
|
|
538efe |
@@ -419,8 +420,8 @@ curl_open (int readonly)
|
|
|
538efe |
#endif
|
|
|
538efe |
nbdkit_debug ("content length: %" PRIi64, h->exportsize);
|
|
|
538efe |
|
|
|
538efe |
- if (strncasecmp (url, "http://", strlen ("http://")) == 0 ||
|
|
|
538efe |
- strncasecmp (url, "https://", strlen ("https://")) == 0) {
|
|
|
538efe |
+ if (ascii_strncasecmp (url, "http://", strlen ("http://")) == 0 ||
|
|
|
538efe |
+ ascii_strncasecmp (url, "https://", strlen ("https://")) == 0) {
|
|
|
538efe |
if (!h->accept_range) {
|
|
|
538efe |
nbdkit_error ("server does not support 'range' (byte range) requests");
|
|
|
538efe |
goto err;
|
|
|
538efe |
@@ -504,7 +505,7 @@ header_cb (void *ptr, size_t size, size_t nmemb, void *opaque)
|
|
|
538efe |
const char *bytes = "bytes";
|
|
|
538efe |
|
|
|
538efe |
if (realsize >= strlen (accept_ranges) &&
|
|
|
538efe |
- strncasecmp (header, accept_ranges, strlen (accept_ranges)) == 0) {
|
|
|
538efe |
+ ascii_strncasecmp (header, accept_ranges, strlen (accept_ranges)) == 0) {
|
|
|
538efe |
const char *p = strchr (header, ':') + 1;
|
|
|
538efe |
|
|
|
538efe |
/* Skip whitespace between the header name and value. */
|
|
|
538efe |
diff --git a/plugins/info/info.c b/plugins/info/info.c
|
|
|
538efe |
index 329a3684..e04d672b 100644
|
|
|
538efe |
--- a/plugins/info/info.c
|
|
|
538efe |
+++ b/plugins/info/info.c
|
|
|
538efe |
@@ -49,6 +49,7 @@
|
|
|
538efe |
|
|
|
538efe |
#include <nbdkit-plugin.h>
|
|
|
538efe |
|
|
|
538efe |
+#include "ascii-string.h"
|
|
|
538efe |
#include "byte-swapping.h"
|
|
|
538efe |
#include "tvdiff.h"
|
|
|
538efe |
|
|
|
538efe |
@@ -76,12 +77,12 @@ static int
|
|
|
538efe |
info_config (const char *key, const char *value)
|
|
|
538efe |
{
|
|
|
538efe |
if (strcmp (key, "mode") == 0) {
|
|
|
538efe |
- if (strcasecmp (value, "exportname") == 0 ||
|
|
|
538efe |
- strcasecmp (value, "export-name") == 0) {
|
|
|
538efe |
+ if (ascii_strcasecmp (value, "exportname") == 0 ||
|
|
|
538efe |
+ ascii_strcasecmp (value, "export-name") == 0) {
|
|
|
538efe |
mode = MODE_EXPORTNAME;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strcasecmp (value, "base64exportname") == 0 ||
|
|
|
538efe |
- strcasecmp (value, "base64-export-name") == 0) {
|
|
|
538efe |
+ else if (ascii_strcasecmp (value, "base64exportname") == 0 ||
|
|
|
538efe |
+ ascii_strcasecmp (value, "base64-export-name") == 0) {
|
|
|
538efe |
#ifdef HAVE_BASE64
|
|
|
538efe |
mode = MODE_BASE64EXPORTNAME;
|
|
|
538efe |
#else
|
|
|
538efe |
@@ -89,13 +90,13 @@ info_config (const char *key, const char *value)
|
|
|
538efe |
return -1;
|
|
|
538efe |
#endif
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strcasecmp (value, "address") == 0)
|
|
|
538efe |
+ else if (ascii_strcasecmp (value, "address") == 0)
|
|
|
538efe |
mode = MODE_ADDRESS;
|
|
|
538efe |
- else if (strcasecmp (value, "time") == 0)
|
|
|
538efe |
+ else if (ascii_strcasecmp (value, "time") == 0)
|
|
|
538efe |
mode = MODE_TIME;
|
|
|
538efe |
- else if (strcasecmp (value, "uptime") == 0)
|
|
|
538efe |
+ else if (ascii_strcasecmp (value, "uptime") == 0)
|
|
|
538efe |
mode = MODE_UPTIME;
|
|
|
538efe |
- else if (strcasecmp (value, "conntime") == 0)
|
|
|
538efe |
+ else if (ascii_strcasecmp (value, "conntime") == 0)
|
|
|
538efe |
mode = MODE_CONNTIME;
|
|
|
538efe |
else {
|
|
|
538efe |
nbdkit_error ("unknown mode: '%s'", value);
|
|
|
538efe |
diff --git a/plugins/nbd/nbd.c b/plugins/nbd/nbd.c
|
|
|
538efe |
index d020beec..980ce8ec 100644
|
|
|
538efe |
--- a/plugins/nbd/nbd.c
|
|
|
538efe |
+++ b/plugins/nbd/nbd.c
|
|
|
538efe |
@@ -52,6 +52,8 @@
|
|
|
538efe |
#define NBDKIT_API_VERSION 2
|
|
|
538efe |
|
|
|
538efe |
#include <nbdkit-plugin.h>
|
|
|
538efe |
+
|
|
|
538efe |
+#include "ascii-string.h"
|
|
|
538efe |
#include "byte-swapping.h"
|
|
|
538efe |
#include "cleanup.h"
|
|
|
538efe |
#include "utils.h"
|
|
|
538efe |
@@ -152,9 +154,9 @@ nbdplug_config (const char *key, const char *value)
|
|
|
538efe |
shared = r;
|
|
|
538efe |
}
|
|
|
538efe |
else if (strcmp (key, "tls") == 0) {
|
|
|
538efe |
- if (strcasecmp (value, "require") == 0 ||
|
|
|
538efe |
- strcasecmp (value, "required") == 0 ||
|
|
|
538efe |
- strcasecmp (value, "force") == 0)
|
|
|
538efe |
+ if (ascii_strcasecmp (value, "require") == 0 ||
|
|
|
538efe |
+ ascii_strcasecmp (value, "required") == 0 ||
|
|
|
538efe |
+ ascii_strcasecmp (value, "force") == 0)
|
|
|
538efe |
tls = LIBNBD_TLS_REQUIRE;
|
|
|
538efe |
else {
|
|
|
538efe |
r = nbdkit_parse_bool (value);
|
|
|
538efe |
diff --git a/plugins/partitioning/partitioning.c b/plugins/partitioning/partitioning.c
|
|
|
538efe |
index 6e426b93..e35764dc 100644
|
|
|
538efe |
--- a/plugins/partitioning/partitioning.c
|
|
|
538efe |
+++ b/plugins/partitioning/partitioning.c
|
|
|
538efe |
@@ -48,6 +48,7 @@
|
|
|
538efe |
|
|
|
538efe |
#include <nbdkit-plugin.h>
|
|
|
538efe |
|
|
|
538efe |
+#include "ascii-string.h"
|
|
|
538efe |
#include "byte-swapping.h"
|
|
|
538efe |
#include "isaligned.h"
|
|
|
538efe |
#include "iszero.h"
|
|
|
538efe |
@@ -176,9 +177,10 @@ partitioning_config (const char *key, const char *value)
|
|
|
538efe |
nr_files++;
|
|
|
538efe |
}
|
|
|
538efe |
else if (strcmp (key, "partition-type") == 0) {
|
|
|
538efe |
- if (strcasecmp (value, "mbr") == 0 || strcasecmp (value, "dos") == 0)
|
|
|
538efe |
+ if (ascii_strcasecmp (value, "mbr") == 0 ||
|
|
|
538efe |
+ ascii_strcasecmp (value, "dos") == 0)
|
|
|
538efe |
parttype = PARTTYPE_MBR;
|
|
|
538efe |
- else if (strcasecmp (value, "gpt") == 0)
|
|
|
538efe |
+ else if (ascii_strcasecmp (value, "gpt") == 0)
|
|
|
538efe |
parttype = PARTTYPE_GPT;
|
|
|
538efe |
else {
|
|
|
538efe |
nbdkit_error ("unknown partition-type: %s", value);
|
|
|
538efe |
@@ -209,13 +211,13 @@ partitioning_config (const char *key, const char *value)
|
|
|
538efe |
alignment = r;
|
|
|
538efe |
}
|
|
|
538efe |
else if (strcmp (key, "mbr-id") == 0) {
|
|
|
538efe |
- if (strcasecmp (value, "default") == 0)
|
|
|
538efe |
+ if (ascii_strcasecmp (value, "default") == 0)
|
|
|
538efe |
mbr_id = DEFAULT_MBR_ID;
|
|
|
538efe |
else if (nbdkit_parse_uint8_t ("mbr-id", value, &mbr_id) == -1)
|
|
|
538efe |
return -1;
|
|
|
538efe |
}
|
|
|
538efe |
else if (strcmp (key, "type-guid") == 0) {
|
|
|
538efe |
- if (strcasecmp (value, "default") == 0)
|
|
|
538efe |
+ if (ascii_strcasecmp (value, "default") == 0)
|
|
|
538efe |
parse_guid (DEFAULT_TYPE_GUID, type_guid);
|
|
|
538efe |
else if (parse_guid (value, type_guid) == -1) {
|
|
|
538efe |
nbdkit_error ("could not validate GUID: %s", value);
|
|
|
538efe |
diff --git a/plugins/sh/call.c b/plugins/sh/call.c
|
|
|
538efe |
index ba9f055f..554e2f78 100644
|
|
|
538efe |
--- a/plugins/sh/call.c
|
|
|
538efe |
+++ b/plugins/sh/call.c
|
|
|
538efe |
@@ -48,6 +48,7 @@
|
|
|
538efe |
#include <nbdkit-plugin.h>
|
|
|
538efe |
|
|
|
538efe |
#include "ascii-ctype.h"
|
|
|
538efe |
+#include "ascii-string.h"
|
|
|
538efe |
#include "cleanup.h"
|
|
|
538efe |
#include "utils.h"
|
|
|
538efe |
|
|
|
538efe |
@@ -332,48 +333,48 @@ handle_script_error (const char *argv0, char *ebuf, size_t len)
|
|
|
538efe |
}
|
|
|
538efe |
|
|
|
538efe |
/* Recognize the errno values that match NBD protocol errors */
|
|
|
538efe |
- if (strncasecmp (ebuf, "EPERM", 5) == 0) {
|
|
|
538efe |
+ if (ascii_strncasecmp (ebuf, "EPERM", 5) == 0) {
|
|
|
538efe |
err = EPERM;
|
|
|
538efe |
skip = 5;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strncasecmp (ebuf, "EIO", 3) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "EIO", 3) == 0) {
|
|
|
538efe |
err = EIO;
|
|
|
538efe |
skip = 3;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strncasecmp (ebuf, "ENOMEM", 6) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "ENOMEM", 6) == 0) {
|
|
|
538efe |
err = ENOMEM;
|
|
|
538efe |
skip = 6;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strncasecmp (ebuf, "EINVAL", 6) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "EINVAL", 6) == 0) {
|
|
|
538efe |
err = EINVAL;
|
|
|
538efe |
skip = 6;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strncasecmp (ebuf, "ENOSPC", 6) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "ENOSPC", 6) == 0) {
|
|
|
538efe |
err = ENOSPC;
|
|
|
538efe |
skip = 6;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strncasecmp (ebuf, "EOVERFLOW", 9) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "EOVERFLOW", 9) == 0) {
|
|
|
538efe |
err = EOVERFLOW;
|
|
|
538efe |
skip = 9;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strncasecmp (ebuf, "ESHUTDOWN", 9) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "ESHUTDOWN", 9) == 0) {
|
|
|
538efe |
err = ESHUTDOWN;
|
|
|
538efe |
skip = 9;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strncasecmp (ebuf, "ENOTSUP", 7) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "ENOTSUP", 7) == 0) {
|
|
|
538efe |
err = ENOTSUP;
|
|
|
538efe |
skip = 7;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strncasecmp (ebuf, "EOPNOTSUPP", 10) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "EOPNOTSUPP", 10) == 0) {
|
|
|
538efe |
err = EOPNOTSUPP;
|
|
|
538efe |
skip = 10;
|
|
|
538efe |
}
|
|
|
538efe |
/* Other errno values that server/protocol.c treats specially */
|
|
|
538efe |
- else if (strncasecmp (ebuf, "EROFS", 5) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "EROFS", 5) == 0) {
|
|
|
538efe |
err = EROFS;
|
|
|
538efe |
skip = 5;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strncasecmp (ebuf, "EDQUOT", 6) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "EDQUOT", 6) == 0) {
|
|
|
538efe |
#ifdef EDQUOT
|
|
|
538efe |
err = EDQUOT;
|
|
|
538efe |
#else
|
|
|
538efe |
@@ -381,7 +382,7 @@ handle_script_error (const char *argv0, char *ebuf, size_t len)
|
|
|
538efe |
#endif
|
|
|
538efe |
skip = 6;
|
|
|
538efe |
}
|
|
|
538efe |
- else if (strncasecmp (ebuf, "EFBIG", 5) == 0) {
|
|
|
538efe |
+ else if (ascii_strncasecmp (ebuf, "EFBIG", 5) == 0) {
|
|
|
538efe |
err = EFBIG;
|
|
|
538efe |
skip = 5;
|
|
|
538efe |
}
|
|
|
538efe |
diff --git a/server/main.c b/server/main.c
|
|
|
538efe |
index 11ba1e6d..08116d74 100644
|
|
|
538efe |
--- a/server/main.c
|
|
|
538efe |
+++ b/server/main.c
|
|
|
538efe |
@@ -55,6 +55,8 @@
|
|
|
538efe |
|
|
|
538efe |
#include <dlfcn.h>
|
|
|
538efe |
|
|
|
538efe |
+#include "ascii-string.h"
|
|
|
538efe |
+
|
|
|
538efe |
#include "internal.h"
|
|
|
538efe |
#include "nbd-protocol.h"
|
|
|
538efe |
#include "options.h"
|
|
|
538efe |
@@ -282,9 +284,9 @@ main (int argc, char *argv[])
|
|
|
538efe |
|
|
|
538efe |
case TLS_OPTION:
|
|
|
538efe |
tls_set_on_cli = true;
|
|
|
538efe |
- if (strcasecmp (optarg, "require") == 0 ||
|
|
|
538efe |
- strcasecmp (optarg, "required") == 0 ||
|
|
|
538efe |
- strcasecmp (optarg, "force") == 0)
|
|
|
538efe |
+ if (ascii_strcasecmp (optarg, "require") == 0 ||
|
|
|
538efe |
+ ascii_strcasecmp (optarg, "required") == 0 ||
|
|
|
538efe |
+ ascii_strcasecmp (optarg, "force") == 0)
|
|
|
538efe |
tls = 2;
|
|
|
538efe |
else {
|
|
|
538efe |
tls = nbdkit_parse_bool (optarg);
|
|
|
538efe |
diff --git a/server/public.c b/server/public.c
|
|
|
538efe |
index 98b78482..919f082d 100644
|
|
|
538efe |
--- a/server/public.c
|
|
|
538efe |
+++ b/server/public.c
|
|
|
538efe |
@@ -52,6 +52,7 @@
|
|
|
538efe |
#include <sys/socket.h>
|
|
|
538efe |
|
|
|
538efe |
#include "ascii-ctype.h"
|
|
|
538efe |
+#include "ascii-string.h"
|
|
|
538efe |
#include "get-current-dir-name.h"
|
|
|
538efe |
|
|
|
538efe |
#include "internal.h"
|
|
|
538efe |
@@ -385,19 +386,19 @@ int
|
|
|
538efe |
nbdkit_parse_bool (const char *str)
|
|
|
538efe |
{
|
|
|
538efe |
if (!strcmp (str, "1") ||
|
|
|
538efe |
- !strcasecmp (str, "true") ||
|
|
|
538efe |
- !strcasecmp (str, "t") ||
|
|
|
538efe |
- !strcasecmp (str, "yes") ||
|
|
|
538efe |
- !strcasecmp (str, "y") ||
|
|
|
538efe |
- !strcasecmp (str, "on"))
|
|
|
538efe |
+ !ascii_strcasecmp (str, "true") ||
|
|
|
538efe |
+ !ascii_strcasecmp (str, "t") ||
|
|
|
538efe |
+ !ascii_strcasecmp (str, "yes") ||
|
|
|
538efe |
+ !ascii_strcasecmp (str, "y") ||
|
|
|
538efe |
+ !ascii_strcasecmp (str, "on"))
|
|
|
538efe |
return 1;
|
|
|
538efe |
|
|
|
538efe |
if (!strcmp (str, "0") ||
|
|
|
538efe |
- !strcasecmp (str, "false") ||
|
|
|
538efe |
- !strcasecmp (str, "f") ||
|
|
|
538efe |
- !strcasecmp (str, "no") ||
|
|
|
538efe |
- !strcasecmp (str, "n") ||
|
|
|
538efe |
- !strcasecmp (str, "off"))
|
|
|
538efe |
+ !ascii_strcasecmp (str, "false") ||
|
|
|
538efe |
+ !ascii_strcasecmp (str, "f") ||
|
|
|
538efe |
+ !ascii_strcasecmp (str, "no") ||
|
|
|
538efe |
+ !ascii_strcasecmp (str, "n") ||
|
|
|
538efe |
+ !ascii_strcasecmp (str, "off"))
|
|
|
538efe |
return 0;
|
|
|
538efe |
|
|
|
538efe |
nbdkit_error ("could not decipher boolean (%s)", str);
|
|
|
538efe |
--
|
|
|
538efe |
2.18.2
|
|
|
538efe |
|