cupsd failed detecting charset when two or more languages are specified by www browser. #267

Closed
michaelrsweet opened this Issue Sep 5, 2003 · 3 comments

Comments

Projects
None yet
1 participant
Collaborator

michaelrsweet commented Sep 5, 2003

Version: 1.1.20rc1
CUPS.org User: tomop.teamgedoh

Hello.

I always use Mozilla Firebird browser. The language configuration is below.

primary launguage: Japanese(ja)
secondary language: US English(en-US)

In this case, HTTP_ACCEPT_LANGUAGE header sent by Mozilla Firebird is "ja,en-US;q=0.5". But this expression looks not to be understand. My patch makes cupsd to understand it.

Regards,
Tomohiro 'Tomo-p' KATO

--- cups-1.2/cups/language.c.orig 2003-08-26 01:08:44.000000000 +0900
+++ cups-1.2/cups/language.c 2003-09-06 05:53:29.000000000 +0900
@@ -375,6 +375,10 @@
language ++;
break;
}

  •  else if (*language == ',' || *language == ';')
    
  •    break;
    
  •  else if (*language == ' ')
    
  •    language ++;
    
    else if (ptr < (langname + sizeof(langname) - 1))
    _ptr++ = tolower(_language);

@@ -386,13 +390,21 @@
language ++;
break;
}

  •  else if (*language == ',' || *language == ';')
    
  •    break;
    
  •  else if (*language == ' ')
    
  •    language ++;
    

    else if (ptr < (country + sizeof(country) - 1))
    _ptr++ = toupper(_language);

    *ptr = '\0';

    for (ptr = charset; *language; language ++)

  •  if (ptr < (charset + sizeof(charset) - 1))
    
  •  if (*language == ',' || *language == ';')
    
  •    break;
    
  •  else if (*language == ' ')
    
  •    language ++;
    
  •  else if (ptr < (charset + sizeof(charset) - 1))
     *ptr++ = toupper(*language);
    

    *ptr = '\0';

Collaborator

michaelrsweet commented Sep 10, 2003

CUPS.org User: mike

I've updated this to apply to 1.1.x as well as 1.2.x. Corrected patch to follow shortly...

Collaborator

michaelrsweet commented Sep 10, 2003

CUPS.org User: mike

The attached patch has been commited to CVS and is a more correct patch...

Collaborator

michaelrsweet commented Sep 15, 2003

"str267.patch":

Index: cups/language.c

RCS file: /development/cvs/cups/cups/language.c,v
retrieving revision 1.20.2.25
diff -u -r1.20.2.25 language.c
--- cups/language.c 2003/08/25 16:08:44 1.20.2.25
+++ cups/language.c 2003/09/10 02:56:58
@@ -342,11 +342,13 @@

  • chars...
    */

-#if defined(APPLE) || !defined(LC_CTYPE)
+#if defined(APPLE)

  • /* The ctype bug isn't in Apple's libc _/
    +#elif !defined(LC_CTYPE)
    oldlocale = _cupsSaveLocale(LC_ALL, "C");
    #else
    oldlocale = cupsSaveLocale(LC_CTYPE, "C");
    -#endif /
    APPLE || !LC_CTYPE /
    +#endif /
    APPLE */

/*

  • Parse the language string passed in to a locale string. "C" is the
    @@ -370,33 +372,41 @@
    */

    for (ptr = langname; *language; language ++)

  •  if (*language == '_' || *language == '-')
    
  •  {
    
  •    language ++;
    
  •  if (*language == '_' || *language == '-' || *language == '.')
    

    break;

  •  }
    

    else if (ptr < (langname + sizeof(langname) - 1))
    _ptr++ = tolower(_language);

    *ptr = '\0';

  • for (ptr = country; *language; language ++)

  •  if (*language == '.')
    
  •  {
    
  •    language ++;
    
  • break;

  •  }
    
  •  else if (ptr < (country + sizeof(country) - 1))
    
  •    _ptr++ = toupper(_language);
    
  • if (*language == '_' || *language == '-')

  • {

  • /*
    
  •  \* Copy the country code...
    
  •  */
    
  • *ptr = '\0';

  •  for (language ++, ptr = country; *language; language ++)
    
  • if (*language == '.')

  • break;
    
  • else if (ptr < (country + sizeof(country) - 1))

  •      *ptr++ = toupper(*language);
    
  • for (ptr = charset; *language; language ++)

  •  if (ptr < (charset + sizeof(charset) - 1))
    
  •    _ptr++ = toupper(_language);
    
  •  *ptr = '\0';
    
  • }

  • *ptr = '\0';

  • if (*language == '.')

  • {

  • /*
    
  •  \* Copy the encoding...
    
  •  */
    
  •  for (language ++, ptr = charset; *language; language ++)
    
  • if (ptr < (charset + sizeof(charset) - 1))

  •      _ptr++ = toupper(_language);
    
  •  *ptr = '\0';
    
  • }

/*

  • Force a POSIX locale for an invalid language name...
    */
    @@ -413,11 +423,13 @@
    • Restore the locale...
      */

-#if defined(APPLE) || !defined(LC_CTYPE)
+#if defined(APPLE)

  • /* The ctype bug isn't in Apple's libc _/
    +#elif !defined(LC_CTYPE)
    _cupsRestoreLocale(LC_ALL, oldlocale);
    #else
    cupsRestoreLocale(LC_CTYPE, oldlocale);
    -#endif /
    APPLE || !LC_CTYPE /
    +#endif /
    APPLE */

/*

  • Figure out the desired encoding...
    @@ -425,12 +437,15 @@

encoding = CUPS_US_ASCII;

  • for (i = 0; i < (int)(sizeof(locale_encodings) / sizeof(locale_encodings[0])); i ++)
  • if (!strcmp(charset, locale_encodings[i]))
  • {
  •  encoding = (cups_encoding_t)i;
    
  •  break;
    
  • }
  • if (charset[0])
  • {
  • for (i = 0; i < (int)(sizeof(locale_encodings) / sizeof(locale_encodings[0])); i ++)
  •  if (!strcasecmp(charset, locale_encodings[i]))
    
  •  {
    
  • encoding = (cups_encoding_t)i;
  • break;
  •  }
    
  • }

/*

  • Now find the message catalog for this locale...
    @@ -450,7 +465,7 @@

snprintf(filename, sizeof(filename), "%s/%s/cups_%s", localedir, real, real);

  • if (access(filename, 0))
  • if (!country[0] || access(filename, 0))
    {
    /*
  • Country localization not available, look for generic localization...
    @@ -702,15 +717,90 @@
    /*
    • Code & data to translate OSX's language names to their ISO 639-1 locale.
      *
  • * In Radar bug #2563420 there's a request to have CoreFoundation export a
  • * function to do this mapping. If this function gets implemented we should
  • * use it.
  • * The first version uses the new CoreFoundation API added in 10.3 (Panther),
  • * the second is for 10.2 (Jaguar).
  • /
    +
    +# ifdef HAVE_CF_LOCALE_ID
    +/
  • * 'appleLangDefault()' - Get the default locale string.
  • /
    +
    +static const char * /
    O - Locale string */
    +appleLangDefault(void)
    +{
  • CFPropertyListRef localizationList;
  •               /\* List of localization data */
    
  • CFStringRef languageName; /* Current name */
  • CFStringRef localeName; /* Canonical from of name */
  • static char language[32] = "";
  •               /\* Cached language */
    
  • /*
  • * Only do the lookup and translation the first time.
  • */
  • if (!language[0])
  • {
  • localizationList =
  •    CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),
    
  •                              kCFPreferencesCurrentApplication);
    
  • if (localizationList != NULL)
  • {
  •  if (CFGetTypeID(localizationList) == CFArrayGetTypeID() &&
    
  • CFArrayGetCount(localizationList) > 0)
    
  •  {
    
  •    languageName = CFArrayGetValueAtIndex(localizationList, 0);
    
  •    if (languageName != NULL &&
    
  •        CFGetTypeID(languageName) == CFStringGetTypeID())
    
  •    {
    
  • localeName = CFLocaleCreateCanonicalLocaleIdentifierFromString(
    
  •                  kCFAllocatorDefault, languageName);
    
  • if (localeName != NULL)
    
  • {
    
  •   CFStringGetCString(localeName, language, sizeof(language),
    
  •              kCFStringEncodingASCII);
    
  •   CFRelease(localeName);
    
  •   if (!strcmp(language, "en"))
    
  •     strlcpy(language, "en_US.UTF-8", sizeof(language));
    
  •   else if (strchr(language, '.') == NULL)
    
  •     strlcat(language, ".UTF-8", sizeof(language));
    
  • }
    
  •    }
    
  •  }
    
  •  CFRelease(localizationList);
    
  • }
  • /*
  • * If we didn't find the language, default to en_US...
  • */
  • if (!language[0])
  •  strlcpy(language, "en_US.UTF-8", sizeof(language));
    
  • }
  • /*
  • * Return the cached locale...
  • */
  • return (language);
    +}
    +# else
    +/*

  • * Code & data to translate OSX 10.2's language names to their ISO 639-1

    • locale.
      */

    typedef struct
    {

  • const char * const name; /* Language name */

  • const char * const locale; /* Locale name */

  • const char * const name; /* Language name */

  • const char * const locale; /* Locale name */
    } apple_name_locale_t;

static const apple_name_locale_t apple_name_locale[] =
@@ -761,7 +851,7 @@
{ "Tigrinya" , "ti.UTF-8" }, { "Oromo" , "om.UTF-8" },
{ "Somali" , "so.UTF-8" }, { "Swahili" , "sw.UTF-8" },
{ "Kinyarwanda" , "rw.UTF-8" }, { "Rundi" , "rn.UTF-8" },

  • { "Nyanja" , "" }, { "Malagasy" , "mg.UTF-8" },
  • { "Nyanja" , "" }, { "Malagasy" , "mg.UTF-8" },
    { "Esperanto" , "eo.UTF-8" }, { "Welsh" , "cy.UTF-8" },
    { "Basque" , "eu.UTF-8" }, { "Catalan" , "ca.UTF-8" },
    { "Latin" , "la.UTF-8" }, { "Quechua" , "qu.UTF-8" },
    @@ -781,14 +871,17 @@
  • 'appleLangDefault()' - Get the default locale string.
    */

-static const char * /* O - Locale string /
+static const char * /
O - Locale string */
appleLangDefault(void)
{

  • int i; /* Looping var */

  • CFPropertyListRef localizationList; /* List of localization data */

  • CFStringRef localizationName; /* Current name */

  • char buff[256]; /* Temporary buffer */

  • static const char language = NULL; / Cached language */

  • int i; /* Looping var */

  • CFPropertyListRef localizationList;

  •               /\* List of localization data */
    
  • CFStringRef localizationName;

  •               /\* Current name */
    
  • char buff[256]; /* Temporary buffer */

  • static const char *language = NULL;

  •               /* Cached language */
    

    /*
    @@ -850,6 +943,7 @@

    return (language);
    }
    +# endif /* HAVE_CF_LOCALE_ID /
    #endif /
    APPLE */

Index: scheduler/client.c

RCS file: /development/cvs/cups/scheduler/client.c,v
retrieving revision 1.91.2.69
diff -u -r1.91.2.69 client.c
--- scheduler/client.c 2003/09/02 20:39:57 1.91.2.69
+++ scheduler/client.c 2003/09/10 02:57:08
@@ -823,23 +823,25 @@

  • 'ReadClient()' - Read data from a client.
    */

-int /* O - 1 on success, 0 on error /
-ReadClient(client_t *con) /
I - Client to read from /
+int /
O - 1 on success, 0 on error /
+ReadClient(client_t *con) /
I - Client to read from */
{

  • char line[32768], /* Line from client... */
  •   operation[64],  /\* Operation code from socket */
    
  •   version[64];    /\* HTTP version number string */
    
  • int major, minor; /* HTTP version numbers */
  • http_status_t status; /* Transfer status */
  • ipp_state_t ipp_state; /* State of IPP transfer */
  • int bytes; /* Number of bytes to POST */
  • char filename; / Name of file for GET/HEAD */
  • char buf[1024]; /* Buffer for real filename */
  • struct stat filestats; /* File information */
  • mime_type_t type; / MIME type of file */
  • printer_t p; / Printer */
  • location_t best; / Best match for authentication */
  • static unsigned request_id = 0;/* Request ID for temp files */
  • char line[32768], /* Line from client... */
  •   operation[64],      /\* Operation code from socket */
    
  •   version[64],        /\* HTTP version number string */
    
  •   locale[64],     /\* Locale */
    
  •   _ptr;           /_ Pointer into strings */
    
  • int major, minor; /* HTTP version numbers */
  • http_status_t status; /* Transfer status */
  • ipp_state_t ipp_state; /* State of IPP transfer */
  • int bytes; /* Number of bytes to POST */
  • char filename; / Name of file for GET/HEAD */
  • char buf[1024]; /* Buffer for real filename */
  • struct stat filestats; /* File information */
  • mime_type_t type; / MIME type of file */
  • printer_t p; / Printer */
  • location_t best; / Best match for authentication */
  • static unsigned request_id = 0; /* Request ID for temp files */

status = HTTP_CONTINUE;
@@ -1054,9 +1056,39 @@
if (status == HTTP_OK)
{
if (con->http.fields[HTTP_FIELD_ACCEPT_LANGUAGE][0])

  •  con->language = cupsLangGet(con->http.fields[HTTP_FIELD_ACCEPT_LANGUAGE]);
    
  • {
  • /*
    
  •  \* Figure out the locale from the Accept-Language and Content-Type
    
  •  \* fields...
    
  •  */
    
  •  if ((ptr = strchr(con->http.fields[HTTP_FIELD_ACCEPT_LANGUAGE], ',')) != NULL)
    
  •    *ptr = '\0';
    
  •  if ((ptr = strchr(con->http.fields[HTTP_FIELD_ACCEPT_LANGUAGE], ';')) != NULL)
    
  •    *ptr = '\0';
    
  •  if ((ptr = strstr(con->http.fields[HTTP_FIELD_CONTENT_TYPE], "charset=")) != NULL)
    
  •  {
    
  •   /*
    
  •    \* Combine language and charset, and trim any extra params in the
    
  • * content-type.
  • */
  •    snprintf(locale, sizeof(locale), "%s.%s",
    
  •        con->http.fields[HTTP_FIELD_ACCEPT_LANGUAGE], ptr + 8);
    
  • if ((ptr = strchr(locale, ',')) != NULL)

  • *ptr = '\0';
    
  •  }
    
  •  else
    
  •    snprintf(locale, sizeof(locale), "%s.%s",
    
  •        con->http.fields[HTTP_FIELD_ACCEPT_LANGUAGE], DefaultCharset);
    
  •  con->language = cupsLangGet(locale);
    
  • }
    else

  •  con->language = cupsLangGet(DefaultLanguage);
    
  •  con->language = cupsLangGet(DefaultLocale);
    

    decode_auth(con);

@@ -2963,8 +2995,48 @@
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* POSIX signal handler /
#endif /
HAVE_SIGACTION && !HAVE_SIGSET */

  • static const char * const locale_encodings[] =
  •   {           /\* Locale charset names */
    
  •     "ASCII",  "ISO8859-1",    "ISO8859-2",    "ISO8859-3",
    
  •     "ISO8859-4",  "ISO8859-5",    "ISO8859-6",    "ISO8859-7",
    
  •     "ISO8859-8",  "ISO8859-9",    "ISO8859-10",   "UTF-8",
    
  •     "ISO8859-13", "ISO8859-14",   "ISO8859-15",   "CP874",
    
  •     "CP1250", "CP1251",   "CP1252",   "CP1253",
    
  •     "CP1254", "CP1255",   "CP1256",   "CP1257",
    
  •     "CP1258", "KOI8R",    "KOI8U",    "ISO8859-11",
    
  •     "ISO8859-16", "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "CP932",  "CP936",    "CP949",    "CP950",
    
  •     "CP1361", "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "",       "",     "",     "",
    
  •     "EUC-CN", "EUC-JP",   "EUC-KR",   "EUC-TW"
    
  •   };
    
  • /*
  • Copy the command string...
    */
    @@ -3020,8 +3092,12 @@

  • Setup the environment variables as needed...
    */

  • snprintf(lang, sizeof(lang), "LANG=%s",

  •       con->language ? con->language->language : "C");
    
  • if (con->language)

  • snprintf(lang, sizeof(lang), "LANG=%s.%s", con->language->language,

  •         locale_encodings[con->language->encoding]);
    
  • else

  • strcpy(lang, "LANG=C");

  • sprintf(ipp_port, "IPP_PORT=%d", LocalPort);
    #ifdef AF_INET6
    if (con->http.hostaddr.addr.sa_family == AF_INET6)

    Index: scheduler/conf.c

    RCS file: /development/cvs/cups/scheduler/conf.c,v
    retrieving revision 1.77.2.43
    diff -u -r1.77.2.43 conf.c
    --- scheduler/conf.c 2003/08/22 22:02:34 1.77.2.43
    +++ scheduler/conf.c 2003/09/10 02:57:14
    @@ -487,6 +487,12 @@
    LogMessage(L_INFO, "Loaded configuration file "%s"", ConfigurationFile);

    /*

  • * Set the default locale using the language and charset...

  • */

  • SetStringf(&DefaultLocale, "%s.%s", DefaultLanguage, DefaultCharset);
  • /*
    • Update all relative filenames to include the full path from ServerRoot...
      */

Index: scheduler/conf.h

RCS file: /development/cvs/cups/scheduler/conf.h,v
retrieving revision 1.36.2.19
diff -u -r1.36.2.19 conf.h
--- scheduler/conf.h 2003/08/22 22:02:35 1.36.2.19
+++ scheduler/conf.h 2003/09/10 02:57:15
@@ -84,6 +84,8 @@
/* Default language encoding /
*DefaultCharset VALUE(NULL),
/
Default charset */

  •       *DefaultLocale      VALUE(NULL),
    
  •               /\* Default locale _/
        *RIPCache       VALUE(NULL),
                /_ Amount of memory for RIPs */
        *TempDir        VALUE(NULL),
    

michaelrsweet added this to the Stable milestone Mar 17, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment