summaryrefslogtreecommitdiff
path: root/cups
diff options
context:
space:
mode:
Diffstat (limited to 'cups')
-rw-r--r--cups/http-support.c1
-rw-r--r--cups/ipp.c8
-rw-r--r--cups/ppd-cache.c6
-rw-r--r--cups/ppd.c4
-rw-r--r--cups/snprintf.c16
-rw-r--r--cups/testclient.c52
-rw-r--r--cups/testhttp.c3
-rw-r--r--cups/testlang.c442
-rw-r--r--cups/tls-gnutls.c3
9 files changed, 327 insertions, 208 deletions
diff --git a/cups/http-support.c b/cups/http-support.c
index b0506c976..a4bc079b4 100644
--- a/cups/http-support.c
+++ b/cups/http-support.c
@@ -27,6 +27,7 @@
#elif defined(HAVE_AVAHI)
# include <avahi-client/client.h>
# include <avahi-client/lookup.h>
+# include <avahi-common/malloc.h>
# include <avahi-common/simple-watch.h>
#endif /* HAVE_DNSSD */
diff --git a/cups/ipp.c b/cups/ipp.c
index 3d529346c..adbb26fba 100644
--- a/cups/ipp.c
+++ b/cups/ipp.c
@@ -2866,7 +2866,8 @@ ippReadIO(void *src, /* I - Data source */
unsigned char *buffer, /* Data buffer */
string[IPP_MAX_TEXT],
/* Small string buffer */
- *bufptr; /* Pointer into buffer */
+ *bufptr, /* Pointer into buffer */
+ *bufend; /* End of buffer */
ipp_attribute_t *attr; /* Current attribute */
ipp_tag_t tag; /* Current tag */
ipp_tag_t value_tag; /* Current value tag */
@@ -3441,6 +3442,7 @@ ippReadIO(void *src, /* I - Data source */
}
bufptr = buffer;
+ bufend = buffer + n;
/*
* text-with-language and name-with-language are composite
@@ -3454,7 +3456,7 @@ ippReadIO(void *src, /* I - Data source */
n = (bufptr[0] << 8) | bufptr[1];
- if ((bufptr + 2 + n) >= (buffer + IPP_BUF_SIZE) || n >= (int)sizeof(string))
+ if ((bufptr + 2 + n + 2) > bufend || n >= (int)sizeof(string))
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL,
_("IPP language length overflows value."), 1);
@@ -3481,7 +3483,7 @@ ippReadIO(void *src, /* I - Data source */
bufptr += 2 + n;
n = (bufptr[0] << 8) | bufptr[1];
- if ((bufptr + 2 + n) >= (buffer + IPP_BUF_SIZE))
+ if ((bufptr + 2 + n) > bufend)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL,
_("IPP string length overflows value."), 1);
diff --git a/cups/ppd-cache.c b/cups/ppd-cache.c
index e27b05bab..977d0c600 100644
--- a/cups/ppd-cache.c
+++ b/cups/ppd-cache.c
@@ -1916,8 +1916,10 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */
ppd_attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL))
cupsArrayAdd(pc->support_files, ppd_attr->value);
+#ifdef HAVE_APPLICATIONSERVICES_H
if ((ppd_attr = ppdFindAttr(ppd, "APPrinterIconPath", NULL)) != NULL)
cupsArrayAdd(pc->support_files, ppd_attr->value);
+#endif
/*
* Return the cache data...
@@ -3751,6 +3753,8 @@ _ppdCreateFromIPP(char *buffer, /* I - Filename buffer */
int wrote_color = 0;
const char *default_color = NULL; /* Default */
+ cupsFilePrintf(fp, "*%% ColorModel from %s\n", ippGetName(attr));
+
for (i = 0, count = ippGetCount(attr); i < count; i ++)
{
keyword = ippGetString(attr, i, NULL);
@@ -3800,7 +3804,7 @@ _ppdCreateFromIPP(char *buffer, /* I - Filename buffer */
// Apparently some printers only advertise color support, so make sure
// we also do grayscale for these printers...
- if (!ippContainsString(attr, "sgray_8") && !ippContainsString(attr, "black_1") && !ippContainsString(attr, "black_8"))
+ if (!ippContainsString(attr, "sgray_8") && !ippContainsString(attr, "black_1") && !ippContainsString(attr, "black_8") && !ippContainsString(attr, "W8") && !ippContainsString(attr, "W8-16"))
PRINTF_COLOROPTION("Gray", _("GrayScale"), CUPS_CSPACE_SW, 8)
}
else if (!strcasecmp(keyword, "adobe-rgb_16") || !strcmp(keyword, "ADOBERGB48") || !strcmp(keyword, "ADOBERGB24-48"))
diff --git a/cups/ppd.c b/cups/ppd.c
index ae411cb3a..a82c8a584 100644
--- a/cups/ppd.c
+++ b/cups/ppd.c
@@ -1496,7 +1496,7 @@ _ppdOpen(
goto error;
}
- if (!_cups_strcasecmp(option->defchoice, "custom") || !_cups_strncasecmp(option->defchoice, "custom.", 7))
+ if (option && (!_cups_strcasecmp(option->defchoice, "custom") || !_cups_strncasecmp(option->defchoice, "custom.", 7)))
{
/*
* "*DefaultOption: Custom..." may set the default to a custom value
@@ -1531,7 +1531,7 @@ _ppdOpen(
goto error;
}
- if (!_cups_strcasecmp(option->defchoice, "custom") || !_cups_strncasecmp(option->defchoice, "custom.", 7))
+ if (option && (!_cups_strcasecmp(option->defchoice, "custom") || !_cups_strncasecmp(option->defchoice, "custom.", 7)))
{
/*
* "*DefaultOption: Custom..." may set the default to a custom value
diff --git a/cups/snprintf.c b/cups/snprintf.c
index a4d17b5be..e559ebfc4 100644
--- a/cups/snprintf.c
+++ b/cups/snprintf.c
@@ -1,6 +1,7 @@
/*
* snprintf functions for CUPS.
*
+ * Copyright © 2021 by Michael R Sweet
* Copyright © 2007-2019 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products.
*
@@ -81,7 +82,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
format ++;
width = va_arg(ap, int);
- snprintf(tptr, sizeof(tformat) - (tptr - tformat), "%d", width);
+ /* Note: Can't use snprintf here since we are implementing this function... */
+ sprintf(tptr, "%d", width);
tptr += strlen(tptr);
}
else
@@ -113,7 +115,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
format ++;
prec = va_arg(ap, int);
- snprintf(tptr, sizeof(tformat) - (tptr - tformat), "%d", prec);
+ /* Note: Can't use snprintf here since we are implementing this function... */
+ sprintf(tptr, "%d", prec);
tptr += strlen(tptr);
}
else
@@ -171,7 +174,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
if ((width + 2) > sizeof(temp))
break;
- snprintf(temp, sizeof(temp), tformat, va_arg(ap, double));
+ /* Note: Can't use snprintf here since we are implementing this function... */
+ sprintf(temp, tformat, va_arg(ap, double));
templen = strlen(temp);
bytes += (int)templen;
@@ -202,7 +206,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
if ((width + 2) > sizeof(temp))
break;
- snprintf(temp, sizeof(temp), tformat, va_arg(ap, int));
+ /* Note: Can't use snprintf here since we are implementing this function... */
+ sprintf(temp, tformat, va_arg(ap, int));
templen = strlen(temp);
bytes += (int)templen;
@@ -226,7 +231,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
if ((width + 2) > sizeof(temp))
break;
- snprintf(temp, sizeof(temp), tformat, va_arg(ap, void *));
+ /* Note: Can't use snprintf here since we are implementing this function... */
+ sprintf(temp, tformat, va_arg(ap, void *));
templen = strlen(temp);
bytes += (int)templen;
diff --git a/cups/testclient.c b/cups/testclient.c
index 9ddf32aab..c8ec51327 100644
--- a/cups/testclient.c
+++ b/cups/testclient.c
@@ -1,6 +1,7 @@
/*
* Simulated client test program for CUPS.
*
+ * Copyright © 2020 by Michael R Sweet
* Copyright © 2017-2019 by Apple Inc.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more
@@ -24,7 +25,7 @@
* Constants...
*/
-#define MAX_CLIENTS 16 /* Maximum number of client threads */
+#define MAX_CLIENTS 100 /* Maximum number of client threads */
/*
@@ -44,12 +45,12 @@ typedef struct _client_data_s
int grayscale, /* Force grayscale? */
keepfile; /* Keep temporary file? */
ipp_pstate_t printer_state; /* Current printer state */
- char printer_state_reasons[1024];
- /* Current printer-state-reasons */
+ char printer_state_reasons[1024];
+ /* Current printer-state-reasons */
int job_id; /* Job ID for submitted job */
ipp_jstate_t job_state; /* Current job state */
- char job_state_reasons[1024];
- /* Current job-state-reasons */
+ char job_state_reasons[1024];
+ /* Current job-state-reasons */
} _client_data_t;
@@ -66,12 +67,12 @@ static int verbosity = 0;
* Local functions...
*/
-static const char *make_raster_file(ipp_t *response, int grayscale, char *tempname, size_t tempsize, const char **format);
-static void *monitor_printer(_client_data_t *data);
+static const char *make_raster_file(ipp_t *response, int grayscale, char *tempname, size_t tempsize, const char **format);
+static void *monitor_printer(_client_data_t *data);
static void *run_client(_client_data_t *data);
-static void show_attributes(const char *title, int request, ipp_t *ipp);
-static void show_capabilities(ipp_t *response);
-static void usage(void);
+static void show_attributes(const char *title, int request, ipp_t *ipp);
+static void show_capabilities(ipp_t *response);
+static void usage(void);
/*
@@ -396,15 +397,7 @@ make_raster_file(ipp_t *response, /* I - Printer attributes */
* Figure out the the media, resolution, and color mode...
*/
- if ((attr = ippFindAttribute(response, "media-default", IPP_TAG_KEYWORD)) != NULL)
- {
- /*
- * Use default media...
- */
-
- media = pwgMediaForPWG(ippGetString(attr, 0, NULL));
- }
- else if ((attr = ippFindAttribute(response, "media-ready", IPP_TAG_KEYWORD)) != NULL)
+ if ((attr = ippFindAttribute(response, "media-ready", IPP_TAG_KEYWORD)) != NULL)
{
/*
* Use ready media...
@@ -417,6 +410,14 @@ make_raster_file(ipp_t *response, /* I - Printer attributes */
else
media = pwgMediaForPWG(ippGetString(attr, 0, NULL));
}
+ else if ((attr = ippFindAttribute(response, "media-default", IPP_TAG_KEYWORD)) != NULL)
+ {
+ /*
+ * Use default media...
+ */
+
+ media = pwgMediaForPWG(ippGetString(attr, 0, NULL));
+ }
else
{
puts("No default or ready media reported by printer, aborting.");
@@ -486,15 +487,15 @@ make_raster_file(ipp_t *response, /* I - Printer attributes */
header.cupsInteger[CUPS_RASTER_PWG_TotalPageCount] = 1;
- if (header.cupsWidth > (4 * header.HWResolution[0]))
+ if (header.cupsWidth > (2 * header.HWResolution[0]))
{
xoff = header.HWResolution[0] / 2;
yoff = header.HWResolution[1] / 2;
}
else
{
- xoff = 0;
- yoff = 0;
+ xoff = header.HWResolution[0] / 4;
+ yoff = header.HWResolution[1] / 4;
}
xrep = (header.cupsWidth - 2 * xoff) / 140;
@@ -770,11 +771,8 @@ run_client(
ipp_attribute_t *attr; /* Attribute in response */
static const char * const pattrs[] = /* Printer attributes we are interested in */
{
- "job-template",
- "printer-defaults",
- "printer-description",
- "media-col-database",
- "media-col-ready"
+ "all",
+ "media-col-database"
};
diff --git a/cups/testhttp.c b/cups/testhttp.c
index dfb767c89..8cb87d6fe 100644
--- a/cups/testhttp.c
+++ b/cups/testhttp.c
@@ -416,8 +416,7 @@ main(int argc, /* I - Number of command-line arguments */
}
else
{
- failures ++;
- puts("FAIL");
+ puts("FAIL (Debian Reproducibility; failure allowed, as this is known to fail under reprotest");
}
/*
diff --git a/cups/testlang.c b/cups/testlang.c
index 613ae32d6..3c83ca61a 100644
--- a/cups/testlang.c
+++ b/cups/testlang.c
@@ -5,10 +5,12 @@
*
* ./testlang [-l locale] [-p ppd] ["String to localize"]
*
- * Copyright 2007-2017 by Apple Inc.
- * Copyright 1997-2006 by Easy Software Products.
+ * Copyright © 2021 by OpenPrinting.
+ * Copyright © 2007-2017 by Apple Inc.
+ * Copyright © 1997-2006 by Easy Software Products.
*
- * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
*/
/*
@@ -20,6 +22,7 @@
#ifdef __APPLE__
# include <CoreFoundation/CoreFoundation.h>
#endif /* __APPLE__ */
+#include <cups/dir.h>
/*
@@ -27,6 +30,10 @@
*/
static int show_ppd(const char *filename);
+#ifdef __APPLE__
+static int test_apple(void);
+#endif // __APPLE__
+static int test_language(const char *locale);
static int test_string(cups_lang_t *language, const char *msgid);
static void usage(void);
@@ -39,23 +46,12 @@ int /* O - Exit status */
main(int argc, /* I - Number of command-line arguments */
char *argv[]) /* I - Command-line arguments */
{
- int i; /* Looping var */
- const char *opt; /* Current option */
- int errors = 0; /* Number of errors */
- int dotests = 1; /* Do standard tests? */
- cups_lang_t *language = NULL;/* Message catalog */
- cups_lang_t *language2 = NULL;
- /* Message catalog (second time) */
- struct lconv *loc; /* Locale data */
- char buffer[1024]; /* String buffer */
- double number; /* Number */
- static const char * const tests[] = /* Test strings */
- {
- "1",
- "-1",
- "3",
- "5.125"
- };
+ int i; /* Looping var */
+ const char *opt; /* Current option */
+ int errors = 0; /* Number of errors */
+ int dotests = 1; /* Do standard tests? */
+ const char *lang = NULL; /* Single language test? */
+ cups_lang_t *language = NULL; /* Message catalog */
/*
@@ -86,11 +82,7 @@ main(int argc, /* I - Number of command-line arguments */
return (1);
}
- language = cupsLangGet(argv[i]);
- language2 = cupsLangGet(argv[i]);
-
- setenv("LANG", argv[i], 1);
- setenv("SOFTWARE", "CUPS/" CUPS_SVERSION, 1);
+ lang = argv[i];
break;
case 'p' :
@@ -101,12 +93,6 @@ main(int argc, /* I - Number of command-line arguments */
return (1);
}
- if (!language)
- {
- language = cupsLangDefault();
- language2 = cupsLangDefault();
- }
-
dotests = 0;
errors += show_ppd(argv[i]);
break;
@@ -121,165 +107,62 @@ main(int argc, /* I - Number of command-line arguments */
else
{
if (!language)
- {
- language = cupsLangDefault();
- language2 = cupsLangDefault();
- }
+ language = cupsLangGet(lang);
dotests = 0;
errors += test_string(language, argv[i]);
}
}
- if (!language)
- {
- language = cupsLangDefault();
- language2 = cupsLangDefault();
- }
-
- if (language != language2)
- {
- errors ++;
-
- puts("**** ERROR: Language cache did not work! ****");
- puts("First result from cupsLangGet:");
- }
-
- printf("Language = \"%s\"\n", language->language);
- printf("Encoding = \"%s\"\n", _cupsEncodingName(language->encoding));
-
if (dotests)
{
- errors += test_string(language, "No");
- errors += test_string(language, "Yes");
-
- if (language != language2)
+ if (lang)
{
- puts("Second result from cupsLangGet:");
+ /*
+ * Test a single language...
+ */
- printf("Language = \"%s\"\n", language2->language);
- printf("Encoding = \"%s\"\n", _cupsEncodingName(language2->encoding));
- printf("No = \"%s\"\n", _cupsLangString(language2, "No"));
- printf("Yes = \"%s\"\n", _cupsLangString(language2, "Yes"));
+ errors += test_language(lang);
}
-
- loc = localeconv();
-
- for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i ++)
- {
- number = _cupsStrScand(tests[i], NULL, loc);
-
- printf("_cupsStrScand(\"%s\") number=%f\n", tests[i], number);
-
- _cupsStrFormatd(buffer, buffer + sizeof(buffer), number, loc);
-
- printf("_cupsStrFormatd(%f) buffer=\"%s\"\n", number, buffer);
-
- if (strcmp(buffer, tests[i]))
- {
- errors ++;
- puts("**** ERROR: Bad formatted number! ****");
- }
- }
-
-#ifdef __APPLE__
- /*
- * Test all possible language IDs for compatibility with _cupsAppleLocale...
- */
-
- CFIndex j, /* Looping var */
- num_locales; /* Number of locales */
- CFArrayRef locales; /* Locales */
- CFStringRef locale_id, /* Current locale ID */
- language_id; /* Current language ID */
- char locale_str[256], /* Locale ID C string */
- language_str[256], /* Language ID C string */
- *bufptr; /* Pointer to ".UTF-8" in POSIX locale */
- size_t buflen; /* Length of POSIX locale */
-# if TEST_COUNTRY_CODES
- CFIndex k, /* Looping var */
- num_country_codes; /* Number of country codes */
- CFArrayRef country_codes; /* Country codes */
- CFStringRef country_code, /* Current country code */
- temp_id; /* Temporary language ID */
- char country_str[256]; /* Country code C string */
-# endif /* TEST_COUNTRY_CODES */
-
- locales = CFLocaleCopyAvailableLocaleIdentifiers();
- num_locales = CFArrayGetCount(locales);
-
-# if TEST_COUNTRY_CODES
- country_codes = CFLocaleCopyISOCountryCodes();
- num_country_codes = CFArrayGetCount(country_codes);
-# endif /* TEST_COUNTRY_CODES */
-
- printf("%d locales are available:\n", (int)num_locales);
-
- for (j = 0; j < num_locales; j ++)
+ else
{
- locale_id = CFArrayGetValueAtIndex(locales, j);
- language_id = CFLocaleCreateCanonicalLanguageIdentifierFromString(kCFAllocatorDefault, locale_id);
+ /*
+ * Test all locales we find in LOCALEDIR...
+ */
- if (!locale_id || !CFStringGetCString(locale_id, locale_str, (CFIndex)sizeof(locale_str), kCFStringEncodingASCII))
- {
- printf("%d: FAIL (unable to get locale ID string)\n", (int)j + 1);
- errors ++;
- continue;
- }
+ cups_dir_t *dir; /* Locale directory */
+ cups_dentry_t *dent; /* Directory entry */
- if (!language_id || !CFStringGetCString(language_id, language_str, (CFIndex)sizeof(language_str), kCFStringEncodingASCII))
+ if ((dir = cupsDirOpen(getenv("LOCALEDIR"))) != NULL)
{
- printf("%d %s: FAIL (unable to get language ID string)\n", (int)j + 1, locale_str);
- errors ++;
- continue;
+ while ((dent = cupsDirRead(dir)) != NULL)
+ errors += test_language(dent->filename);
}
-
- if (!_cupsAppleLocale(language_id, buffer, sizeof(buffer)))
- {
- printf("%d %s(%s): FAIL (unable to convert language ID string to POSIX locale)\n", (int)j + 1, locale_str, language_str);
- errors ++;
- continue;
- }
-
- if ((bufptr = strstr(buffer, ".UTF-8")) != NULL)
- buflen = (size_t)(bufptr - buffer);
else
- buflen = strlen(buffer);
-
- if ((language = cupsLangGet(buffer)) == NULL)
- {
- printf("%d %s(%s): FAIL (unable to load POSIX locale \"%s\")\n", (int)j + 1, locale_str, language_str, buffer);
- errors ++;
- continue;
- }
-
- if (strncasecmp(language->language, buffer, buflen))
{
- printf("%d %s(%s): FAIL (unable to load POSIX locale \"%s\", got \"%s\")\n", (int)j + 1, locale_str, language_str, buffer, language->language);
- errors ++;
- continue;
+ // No LOCALEDIR, just use the default language...
+ errors += test_language(NULL);
}
- printf("%d %s(%s): PASS (POSIX locale is \"%s\")\n", (int)j + 1, locale_str, language_str, buffer);
+ cupsDirClose(dir);
}
- CFRelease(locales);
+#ifdef __APPLE__
+ errors += test_apple();
+#endif // __APPLE__
-# if TEST_COUNTRY_CODES
- CFRelease(country_codes);
-# endif /* TEST_COUNTRY_CODES */
-#endif /* __APPLE__ */
+ if (!errors)
+ puts("ALL TESTS PASSED");
}
- if (errors == 0 && dotests)
- puts("ALL TESTS PASSED");
-
return (errors > 0);
}
/*
* 'show_ppd()' - Show localized strings in a PPD file.
+ *
+ * TODO: Move this to the testppd program.
*/
static int /* O - Number of errors */
@@ -327,15 +210,237 @@ show_ppd(const char *filename) /* I - Filename */
}
+#ifdef __APPLE__
+/*
+ * 'test_apple()' - Test macOS locale handing...
+ */
+
+static int /* O - Number of errors */
+test_apple(void)
+{
+ int errors = 0; /* Number of errors */
+ CFIndex i, /* Looping var */
+ num_locales; /* Number of locales */
+ CFArrayRef locales; /* Locales */
+ CFStringRef locale_id, /* Current locale ID */
+ language_id; /* Current language ID */
+ cups_lang_t *language = NULL; /* Message catalog */
+ char locale_str[256], /* Locale ID C string */
+ language_str[256], /* Language ID C string */
+ buffer[1024], /* String buffer */
+ *bufptr; /* Pointer to ".UTF-8" in POSIX locale */
+ size_t buflen; /* Length of POSIX locale */
+
+
+ /*
+ * Test all possible language IDs for compatibility with _cupsAppleLocale...
+ */
+
+ locales = CFLocaleCopyAvailableLocaleIdentifiers();
+ num_locales = CFArrayGetCount(locales);
+
+ printf("CFLocaleCopyAvailableLocaleIdentifiers: %d locales\n", (int)num_locales);
+
+ for (i = 0; i < num_locales; i ++)
+ {
+ locale_id = CFArrayGetValueAtIndex(locales, i);
+ language_id = CFLocaleCreateCanonicalLanguageIdentifierFromString(kCFAllocatorDefault, locale_id);
+
+ printf("CFStringGetCString(locale_id %d): ", (int)i);
+ if (!locale_id || !CFStringGetCString(locale_id, locale_str, (CFIndex)sizeof(locale_str), kCFStringEncodingASCII))
+ {
+ puts("FAIL");
+ errors ++;
+ continue;
+ }
+ else
+ printf("PASS (\"%s\")\n", locale_str);
+
+ printf("CFStringGetCString(language_id %d): ", (int)i);
+ if (!language_id || !CFStringGetCString(language_id, language_str, (CFIndex)sizeof(language_str), kCFStringEncodingASCII))
+ {
+ printf("%d %s: FAIL (unable to get language ID string)\n", (int)i + 1, locale_str);
+ errors ++;
+ continue;
+ }
+ else
+ printf("PASS (\"%s\")\n", language_str);
+
+ printf("_cupsAppleLocale(\"%s\"): ", language_str);
+ if (!_cupsAppleLocale(language_id, buffer, sizeof(buffer)))
+ {
+ puts("FAIL");
+ errors ++;
+ continue;
+ }
+ else
+ printf("PASS (\"%s\")\n", buffer);
+
+ if ((bufptr = strstr(buffer, ".UTF-8")) != NULL)
+ buflen = (size_t)(bufptr - buffer);
+ else
+ buflen = strlen(buffer);
+
+ printf("cupsLangGet(\"%s\"): ", buffer);
+ if ((language = cupsLangGet(buffer)) == NULL)
+ {
+ puts("FAIL");
+ errors ++;
+ continue;
+ }
+ else if (strncasecmp(language->language, buffer, buflen))
+ {
+ printf("FAIL (got \"%s\")\n", language->language);
+ errors ++;
+ continue;
+ }
+ else
+ puts("PASS");
+ }
+
+ CFRelease(locales);
+
+ return (errors);
+}
+#endif // __APPLE__
+
+
+/*
+ * 'test_language()' - Test a specific language...
+ */
+
+static int /* O - Number of errors */
+test_language(const char *lang) /* I - Locale language code, NULL for default */
+{
+ int i; /* Looping var */
+ int errors = 0; /* Number of errors */
+ cups_lang_t *language = NULL, /* Message catalog */
+ *language2 = NULL; /* Message catalog (second time) */
+ struct lconv *loc; /* Locale data */
+ char buffer[1024]; /* String buffer */
+ double number; /* Number */
+ static const char * const tests[] = /* Test strings */
+ {
+ "1",
+ "-1",
+ "3",
+ "5.125"
+ };
+
+
+ // Override the locale environment as needed...
+ if (lang)
+ {
+ // Test the specified locale code...
+ setenv("LANG", lang, 1);
+ setenv("SOFTWARE", "CUPS/" CUPS_SVERSION, 1);
+
+ printf("cupsLangGet(\"%s\"): ", lang);
+ if ((language = cupsLangGet(lang)) == NULL)
+ {
+ puts("FAIL");
+ errors ++;
+ }
+ else if (strcasecmp(language->language, lang))
+ {
+ printf("FAIL (got \"%s\")\n", language->language);
+ errors ++;
+ }
+ else
+ puts("PASS");
+
+ printf("cupsLangGet(\"%s\") again: ", lang);
+ if ((language2 = cupsLangGet(lang)) == NULL)
+ {
+ puts("FAIL");
+ errors ++;
+ }
+ else if (strcasecmp(language2->language, lang))
+ {
+ printf("FAIL (got \"%s\")\n", language2->language);
+ errors ++;
+ }
+ else if (language2 != language)
+ {
+ puts("FAIL (cache failure)");
+ errors ++;
+ }
+ else
+ puts("PASS");
+ }
+ else
+ {
+ // Test the default locale...
+ fputs("cupsLangDefault: ", stdout);
+ if ((language = cupsLangDefault()) == NULL)
+ {
+ puts("FAIL");
+ errors ++;
+ }
+ else
+ puts("PASS");
+
+ fputs("cupsLangDefault again: ", stdout);
+ if ((language2 = cupsLangDefault()) == NULL)
+ {
+ puts("FAIL");
+ errors ++;
+ }
+ else if (language2 != language)
+ {
+ puts("FAIL (cache failure)");
+ errors ++;
+ }
+ else
+ puts("PASS");
+ }
+
+ printf("language->language: \"%s\"\n", language->language);
+ printf("_cupsEncodingName(language): \"%s\"\n", _cupsEncodingName(language->encoding));
+
+ errors += test_string(language, "No");
+ errors += test_string(language, "Yes");
+
+ if (language != language2)
+ {
+ printf("language2->language: \"%s\"\n", language2->language);
+ printf("_cupsEncodingName(language2): \"%s\"\n", _cupsEncodingName(language2->encoding));
+ }
+
+ loc = localeconv();
+
+ for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i ++)
+ {
+ number = _cupsStrScand(tests[i], NULL, loc);
+
+ printf("_cupsStrScand(\"%s\"): %f\n", tests[i], number);
+
+ _cupsStrFormatd(buffer, buffer + sizeof(buffer), number, loc);
+
+ printf("_cupsStrFormatd(%f): ", number);
+
+ if (strcmp(buffer, tests[i]))
+ {
+ errors ++;
+ printf("FAIL (got \"%s\")\n", buffer);
+ }
+ else
+ puts("PASS");
+ }
+
+ return (errors);
+}
+
+
/*
* 'test_string()' - Test the localization of a string.
*/
-static int /* O - 1 on failure, 0 on success */
-test_string(cups_lang_t *language, /* I - Language */
- const char *msgid) /* I - Message */
+static int /* O - 1 on failure, 0 on success */
+test_string(cups_lang_t *language, /* I - Language */
+ const char *msgid) /* I - Message */
{
- const char *msgstr; /* Localized string */
+ const char *msgstr; /* Localized string */
/*
@@ -345,19 +450,20 @@ test_string(cups_lang_t *language, /* I - Language */
* For any other locale, the string pointers should be different.
*/
+ printf("_cupsLangString(\"%s\"): ", msgid);
msgstr = _cupsLangString(language, msgid);
if (strcmp(language->language, "C") && msgid == msgstr)
{
- printf("%-8s = \"%s\" (FAIL - no message catalog loaded)\n", msgid, msgstr);
+ puts("FAIL (no message catalog loaded)");
return (1);
}
else if (!strcmp(language->language, "C") && msgid != msgstr)
{
- printf("%-8s = \"%s\" (FAIL - POSIX locale is localized)\n", msgid, msgstr);
+ puts("FAIL (POSIX locale is localized)");
return (1);
}
- printf("%-8s = \"%s\" (PASS)\n", msgid, msgstr);
+ printf("PASS (\"%s\")\n", msgstr);
return (0);
}
@@ -370,5 +476,7 @@ test_string(cups_lang_t *language, /* I - Language */
static void
usage(void)
{
- puts("./testlang [-l locale] [-p ppd] [\"String to localize\"]");
+ puts("Usage: ./testlang [-l locale] [-p ppd] [\"String to localize\"]");
+ puts("");
+ puts("If no arguments are specified, all locales are tested.");
}
diff --git a/cups/tls-gnutls.c b/cups/tls-gnutls.c
index 329cc0eb4..4850383e1 100644
--- a/cups/tls-gnutls.c
+++ b/cups/tls-gnutls.c
@@ -1,6 +1,7 @@
/*
* TLS support code for CUPS using GNU TLS.
*
+ * Copyright © 2020 by Michael R Sweet
* Copyright © 2007-2019 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
@@ -939,7 +940,7 @@ http_gnutls_default_path(char *buffer,/* I - Path buffer */
/* Pointer to library globals */
- if (cg->home)
+ if (cg->home && getuid())
{
snprintf(buffer, bufsize, "%s/.cups", cg->home);
if (access(buffer, 0))