Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Java libraries are using iso-8859-1 for requests #2651

Closed

Description

@michaelrsweet

Version: 1.3.5
CUPS.org User: TK

I refer to the java libraries in the CUPS source package, especially /scripting/java/src/com/easyws/cups/Cups.java.
The packages are using 'ISO-8859-1' to make requests to a CUPS server.

--- example ---
a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_CHARSET,
"attributes-charset" );
a.addString( "", "iso-8859-1" );
---/example ---

Any request to a CUPS server fails with the message 'unsupported character set "iso-8859-1"'.

As I have discovered, the cupsd only supports 'UTF-8'. The java sources should be fixed to 'UTF-8' to work correctly.

Activity

  1. michaelrsweet commented on Jan 7, 2008

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Fixed in Subversion repository.

    The code needed a little more than just the iso-8859-1 string changed; we also needed to encode the Java strings using UTF-8 (they are natively UTF-16) and could not just pass the low 8 bits like we were doing before...

  2. michaelrsweet commented on Jan 7, 2008

    @michaelrsweet
    ContributorAuthor

    "str2651.patch":

    Index: scripting/java/src/com/easysw/cups/Cups.java

    --- scripting/java/src/com/easysw/cups/Cups.java (revision 7178)
    +++ scripting/java/src/com/easysw/cups/Cups.java (working copy)
    @@ -7,7 +7,7 @@

    • Internet Printing Protocol definitions for the Common UNIX Printing
    • System (CUPS).
    • * Copyright 2007 by Apple Inc.
    • * Copyright 2007-2008 by Apple Inc.
    • Copyright 1997-2006 by Easy Software Products.
    • These coded instructions, statements, and computer programs are the
      @@ -831,7 +831,7 @@

      a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_CHARSET,
      "attributes-charset" );

    •  a.addString( "", "iso-8859-1" );  
      
    •  a.addString( "", "utf-8" );  
      

      ipp.addAttribute(a);

    @@ -1014,7 +1014,7 @@

       a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_CHARSET,
                             "attributes-charset" );
    
    •  a.addString( "", "iso-8859-1" );  
      
    •  a.addString( "", "utf-8" );  
      
      ipp.addAttribute(a);

    @@ -1091,7 +1091,7 @@

       a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_CHARSET,
                             "attributes-charset" );
    
    •  a.addString( "", "iso-8859-1" );  
      
    •  a.addString( "", "utf-8" );  
      
      ipp.addAttribute(a);

    @@ -1155,7 +1155,7 @@

       a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_CHARSET,
                             "attributes-charset" );
    
    •  a.addString( "", "iso-8859-1" );  
      
    •  a.addString( "", "utf-8" );  
      
      ipp.addAttribute(a);

    @@ -1229,7 +1229,7 @@

       a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_CHARSET,
                             "attributes-charset" );
    
    •  a.addString( "", "iso-8859-1" );  
      
    •  a.addString( "", "utf-8" );  
      

      ipp.addAttribute(a);

      // ------------
      @@ -1315,7 +1315,7 @@

      a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_CHARSET,
      "attributes-charset" );

    •  a.addString( "", "iso-8859-1" );  
      
    •  a.addString( "", "utf-8" );  
      

      ipp.addAttribute(a);

      // ------------
      @@ -1375,7 +1375,7 @@

      a = new IPPAttribute( IPPDefs.TAG_OPERATION, IPPDefs.TAG_CHARSET,
      "attributes-charset" );

    •  a.addString( "", "iso-8859-1" );  
      
    •  a.addString( "", "utf-8" );  
      

      ipp.addAttribute(a);

    Index: scripting/java/src/com/easysw/cups/IPPAttribute.java

    --- scripting/java/src/com/easysw/cups/IPPAttribute.java (revision 7178)
    +++ scripting/java/src/com/easysw/cups/IPPAttribute.java (working copy)
    @@ -7,7 +7,7 @@

    • Internet Printing Protocol definitions for the Common UNIX Printing
    • System (CUPS).
    • * Copyright 2007 by Apple Inc.
    • * Copyright 2007-2008 by Apple Inc.
    • Copyright 1997-2002 by Easy Software Products.
    • These coded instructions, statements, and computer programs are the
      @@ -263,7 +263,9 @@
      {
      IPPValue val;
      int bytes = 0; // Start with one for the group tag.

    • Charset utf8 = Charset::forName("UTF-8");

    • ByteBuffer temp;
      +
      //
      // Add 1 if first time, or group tag changes.
      //
      @@ -308,8 +310,12 @@
      case IPPDefs.TAG_CHARSET:
      case IPPDefs.TAG_LANGUAGE:
      case IPPDefs.TAG_MIMETYPE:

    •   temp = utf8.encode(val.text);
       bytes += 2;
      
    •   bytes += val.text.length();
      
    •   if (temp.capacity() > 32767)
      
    •     bytes += 32767;
      
    •   else
      
    •     bytes += temp.capacity();
      

      break;

      case IPPDefs.TAG_DATE :
      @@ -329,9 +335,13 @@

      case IPPDefs.TAG_TEXTLANG :
      case IPPDefs.TAG_NAMELANG :

    •   temp = utf8.encode(val.text);
       bytes += 6;  // 2 overall len, 2 charset len, 2 text len
      
    •   bytes += val.charset.length() +
      
    •            val.text.length();
      
    •   bytes += val.charset.length();
      
    •   if (temp.capacity() > 32767)
      
    •     bytes += 32767;
      
    •   else
      
    •     bytes += temp.capacity();
      

      break;

      default :
      @@ -359,6 +369,8 @@
      int i,j, n;
      int bi = 0; // Start with one for the group tag.
      byte[] bytes = new byte[sz];

    • Charset utf8 = Charset::forName("UTF-8");

    • ByteBuffer temp;

    if (group_tag != last_group)
    {
    @@ -412,12 +424,16 @@
     case IPPDefs.TAG_CHARSET :
     case IPPDefs.TAG_LANGUAGE :
     case IPPDefs.TAG_MIMETYPE :
    
    •        bytes[bi++] = (byte)((val.text.length() & 0xff00) >> 8);
      
    •        bytes[bi++] = (byte)(val.text.length() & 0xff);
      
    •        for (j=0; j < val.text.length(); j++)
      
    •        {
      
    •          bytes[bi++] = (byte)val.text.charAt(j);
      
    •        }
      
    •   temp = utf8.encode(val.text);
      
    •   n    = temp.capacity();
      
    •   if (n > 32767)
      
    •     n = 32767;
      
    •        bytes[bi++] = (byte)((n & 0x7f00) >> 8);
      
    •        bytes[bi++] = (byte)(n & 0xff);
      
    •   temp.get(bytes, bi, n);
      
    •   bi += n;
      

      break;

      case IPPDefs.TAG_DATE:
      @@ -456,23 +472,30 @@

      case IPPDefs.TAG_TEXTLANG :
      case IPPDefs.TAG_NAMELANG :

    •        n = val.charset.length() +
      
    •            val.text.length() + 4;
      
    •        bytes[bi++] = (byte)((n & 0xff00) >> 8);
      
    •   temp = utf8.encode(val.text);
      
    •   n    = temp.capacity() + val.charset.length() + 4;
      
    •   if (n > 32767)
      
    •     n = 32767;
      
    •        bytes[bi++] = (byte)((n & 0x7f00) >> 8);
       bytes[bi++] = (byte)(n & 0xff);
      
       n = val.charset.length();
      
    •        bytes[bi++] = (byte)((n & 0xff00) >> 8);
      
    •        bytes[bi++] = (byte)((n & 0x7f00) >> 8);
       bytes[bi++] = (byte)(n & 0xff);
       for (j=0; j < val.charset.length(); j++)
         bytes[bi++] = (byte)val.charset.charAt(j);
      
    •        n = val.text.length();
      
    •        bytes[bi++] = (byte)((n & 0xff00) >> 8);
      
    •        n = temp.capacity();
      
    •   if (n > 32767)
      
    •     n = 32767;
      
    •        bytes[bi++] = (byte)((n & 0x7f00) >> 8);
       bytes[bi++] = (byte)(n & 0xff);
      
    •        for (j=0; j < (byte)val.text.length(); j++)
      

    - bytes[bi++] = (byte)val.text.charAt(j);

    •   temp.get(bytes, bi, n);
      
    •   bi += n;
      

      break;

      default :

  3. added this to the Stable milestone on Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions