]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/ipp.c
Update svn:keyword properties.
[thirdparty/cups.git] / cups / ipp.c
index 96361abdc8d8d6c27626c7835929640e717ced8b..fd6f45f40ac244b3d2c46ea83563c6ac70811922 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: ipp.c 10102 2011-11-02 23:52:39Z mike $"
+ * "$Id$"
  *
  *   Internet Printing Protocol functions for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 2007-2013 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
  *
  * Contents:
  *
- *   _cupsBufferGet()      - Get a read/write buffer.
- *   _cupsBufferRelease()   - Release a read/write buffer.
- *   ippAddBoolean()       - Add a boolean attribute to an IPP message.
- *   ippAddBooleans()      - Add an array of boolean values.
- *   ippAddCollection()     - Add a collection value.
- *   ippAddCollections()    - Add an array of collection values.
- *   ippAddDate()          - Add a date attribute to an IPP message.
- *   ippAddInteger()       - Add a integer attribute to an IPP message.
- *   ippAddIntegers()      - Add an array of integer values.
- *   ippAddOctetString()    - Add an octetString value to an IPP message.
- *   ippAddOutOfBand()     - Add an out-of-band value to an IPP message.
- *   ippAddRange()         - Add a range of values to an IPP message.
- *   ippAddRanges()        - Add ranges of values to an IPP message.
- *   ippAddResolution()     - Add a resolution value to an IPP message.
- *   ippAddResolutions()    - Add resolution values to an IPP message.
- *   ippAddSeparator()     - Add a group separator to an IPP message.
- *   ippAddString()        - Add a language-encoded string to an IPP message.
- *   ippAddStrings()       - Add language-encoded strings to an IPP message.
- *   ippCopyAttribute()     - Copy an attribute.
- *   ippCopyAttributes()    - Copy attributes from one IPP message to another.
- *   ippDateToTime()       - Convert from RFC 1903 Date/Time format to UNIX
- *                           time in seconds.
- *   ippDelete()           - Delete an IPP message.
- *   ippDeleteAttribute()   - Delete a single attribute in an IPP message.
- *   ippDeleteValues()     - Delete values in an attribute.
- *   ippFindAttribute()     - Find a named attribute in a request.
- *   ippFindNextAttribute() - Find the next named attribute in a request.
- *   ippFirstAttribute()    - Return the first attribute in the message.
- *   ippGetBoolean()       - Get a boolean value for an attribute.
- *   ippGetCollection()     - Get a collection value for an attribute.
- *   ippGetCount()         - Get the number of values in an attribute.
- *   ippGetDate()           - Get a date value for an attribute.
- *   ippGetGroupTag()      - Get the group associated with an attribute.
- *   ippGetInteger()       - Get the integer/enum value for an attribute.
- *   ippGetName()          - Get the attribute name.
- *   ippGetOperation()     - Get the operation ID in an IPP message.
- *   ippGetRange()          - Get a rangeOfInteger value from an attribute.
- *   ippGetRequestId()     - Get the request ID from an IPP message.
- *   ippGetResolution()     - Get a resolution value for an attribute.
- *   ippGetStatusCode()     - Get the status code from an IPP response or event
- *                           message.
- *   ippGetString()        - Get the string and optionally the language code
- *                           for an attribute.
- *   ippGetValueTag()      - Get the value tag for an attribute.
- *   ippGetVersion()       - Get the major and minor version number from an
- *                           IPP message.
- *   ippLength()           - Compute the length of an IPP message.
- *   ippNextAttribute()     - Return the next attribute in the message.
- *   ippNew()              - Allocate a new IPP message.
- *   ippNewRequest()       - Allocate a new IPP request message.
- *   ippRead()             - Read data for an IPP message from a HTTP
- *                           connection.
- *   ippReadFile()         - Read data for an IPP message from a file.
- *   ippReadIO()           - Read data for an IPP message.
- *   ippSetBoolean()       - Set a boolean value in an attribute.
- *   ippSetCollection()     - Set a collection value in an attribute.
- *   ippSetDate()           - Set a date value in an attribute.
- *   ippSetGroupTag()      - Set the group tag of an attribute.
- *   ippSetInteger()       - Set an integer or enum value in an attribute.
- *   ippSetName()          - Set the name of an attribute.
- *   ippSetOperation()     - Set the operation ID in an IPP request message.
- *   ippSetRange()         - Set a rangeOfInteger value in an attribute.
- *   ippSetRequestId()     - Set the request ID in an IPP message.
- *   ippSetResolution()     - Set a resolution value in an attribute.
- *   ippSetState()          - Set the current state of the IPP message.
- *   ippSetStatusCode()     - Set the status code in an IPP response or event
- *                           message.
- *   ippSetString()        - Set a string value in an attribute.
- *   ippSetValueTag()      - Set the value tag of an attribute.
- *   ippSetVersion()       - Set the version number in an IPP message.
- *   ippTimeToDate()       - Convert from UNIX time to RFC 1903 format.
- *   ippWrite()            - Write data for an IPP message to a HTTP
- *                           connection.
- *   ippWriteFile()        - Write data for an IPP message to a file.
- *   ippWriteIO()          - Write data for an IPP message.
- *   ipp_add_attr()        - Add a new attribute to the message.
- *   ipp_free_values()     - Free attribute values.
- *   ipp_get_code()        - Convert a C locale/charset name into an IPP
- *                           language/charset code.
- *   ipp_lang_code()       - Convert a C locale name into an IPP language
- *                           code.
- *   ipp_length()          - Compute the length of an IPP message or
- *                           collection value.
- *   ipp_read_http()       - Semi-blocking read on a HTTP connection...
- *   ipp_read_file()       - Read IPP data from a file.
- *   ipp_set_value()       - Get the value element from an attribute,
- *                           expanding it as needed.
- *   ipp_write_file()      - Write IPP data to a file.
+ *   _cupsBufferGet()       - Get a read/write buffer.
+ *   _cupsBufferRelease()    - Release a read/write buffer.
+ *   ippAddBoolean()        - Add a boolean attribute to an IPP message.
+ *   ippAddBooleans()       - Add an array of boolean values.
+ *   ippAddCollection()      - Add a collection value.
+ *   ippAddCollections()     - Add an array of collection values.
+ *   ippAddDate()           - Add a date attribute to an IPP message.
+ *   ippAddInteger()        - Add a integer attribute to an IPP message.
+ *   ippAddIntegers()       - Add an array of integer values.
+ *   ippAddOctetString()     - Add an octetString value to an IPP message.
+ *   ippAddOutOfBand()      - Add an out-of-band value to an IPP message.
+ *   ippAddRange()          - Add a range of values to an IPP message.
+ *   ippAddRanges()         - Add ranges of values to an IPP message.
+ *   ippAddResolution()      - Add a resolution value to an IPP message.
+ *   ippAddResolutions()     - Add resolution values to an IPP message.
+ *   ippAddSeparator()      - Add a group separator to an IPP message.
+ *   ippAddString()         - Add a language-encoded string to an IPP message.
+ *   ippAddStringf()        - Add a formatted string to an IPP message.
+ *   ippAddStringfv()       - Add a formatted string to an IPP message.
+ *   ippAddStrings()        - Add language-encoded strings to an IPP message.
+ *   ippContainsInteger()    - Determine whether an attribute contains the
+ *                            specified value or is within the list of ranges.
+ *   ippContainsString()     - Determine whether an attribute contains the
+ *                            specified string value.
+ *   ippCopyAttribute()      - Copy an attribute.
+ *   ippCopyAttributes()     - Copy attributes from one IPP message to another.
+ *   ippDateToTime()        - Convert from RFC 1903 Date/Time format to UNIX
+ *                            time in seconds.
+ *   ippDelete()            - Delete an IPP message.
+ *   ippDeleteAttribute()    - Delete a single attribute in an IPP message.
+ *   ippDeleteValues()      - Delete values in an attribute.
+ *   ippFindAttribute()      - Find a named attribute in a request.
+ *   ippFindNextAttribute()  - Find the next named attribute in a request.
+ *   ippFirstAttribute()     - Return the first attribute in the message.
+ *   ippGetBoolean()        - Get a boolean value for an attribute.
+ *   ippGetCollection()      - Get a collection value for an attribute.
+ *   ippGetCount()          - Get the number of values in an attribute.
+ *   ippGetDate()           - Get a date value for an attribute.
+ *   ippGetGroupTag()       - Get the group associated with an attribute.
+ *   ippGetInteger()        - Get the integer/enum value for an attribute.
+ *   ippGetName()           - Get the attribute name.
+ *   ippGetOctetString()     - Get an octetString value from an IPP attribute.
+ *   ippGetOperation()      - Get the operation ID in an IPP message.
+ *   ippGetRange()          - Get a rangeOfInteger value from an attribute.
+ *   ippGetRequestId()      - Get the request ID from an IPP message.
+ *   ippGetResolution()      - Get a resolution value for an attribute.
+ *   ippGetState()          - Get the IPP message state.
+ *   ippGetStatusCode()      - Get the status code from an IPP response or
+ *                            event message.
+ *   ippGetString()         - Get the string and optionally the language code
+ *                            for an attribute.
+ *   ippGetValueTag()       - Get the value tag for an attribute.
+ *   ippGetVersion()        - Get the major and minor version number from an
+ *                            IPP message.
+ *   ippLength()            - Compute the length of an IPP message.
+ *   ippNextAttribute()      - Return the next attribute in the message.
+ *   ippNew()               - Allocate a new IPP message.
+ *   ippNewRequest()        - Allocate a new IPP request message.
+ *   ippNewResponse()       - Allocate a new IPP response message.
+ *   ippRead()              - Read data for an IPP message from a HTTP
+ *                            connection.
+ *   ippReadFile()          - Read data for an IPP message from a file.
+ *   ippReadIO()            - Read data for an IPP message.
+ *   ippSetBoolean()        - Set a boolean value in an attribute.
+ *   ippSetCollection()      - Set a collection value in an attribute.
+ *   ippSetDate()           - Set a date value in an attribute.
+ *   ippSetGroupTag()       - Set the group tag of an attribute.
+ *   ippSetInteger()        - Set an integer or enum value in an attribute.
+ *   ippSetName()           - Set the name of an attribute.
+ *   ippSetOctetString()     - Set an octetString value in an IPP attribute.
+ *   ippSetOperation()      - Set the operation ID in an IPP request message.
+ *   ippSetRange()          - Set a rangeOfInteger value in an attribute.
+ *   ippSetRequestId()      - Set the request ID in an IPP message.
+ *   ippSetResolution()      - Set a resolution value in an attribute.
+ *   ippSetState()          - Set the current state of the IPP message.
+ *   ippSetStatusCode()      - Set the status code in an IPP response or event
+ *                            message.
+ *   ippSetString()         - Set a string value in an attribute.
+ *   ippSetStringf()        - Set a formatted string value of an attribute.
+ *   ippSetStringf()        - Set a formatted string value of an attribute.
+ *   ippSetValueTag()       - Set the value tag of an attribute.
+ *   ippSetVersion()        - Set the version number in an IPP message.
+ *   ippTimeToDate()        - Convert from UNIX time to RFC 1903 format.
+ *   ippValidateAttribute()  - Validate the contents of an attribute.
+ *   ippValidateAttributes() - Validate all attributes in an IPP message.
+ *   ippWrite()             - Write data for an IPP message to a HTTP
+ *                            connection.
+ *   ippWriteFile()         - Write data for an IPP message to a file.
+ *   ippWriteIO()           - Write data for an IPP message.
+ *   ipp_add_attr()         - Add a new attribute to the message.
+ *   ipp_free_values()      - Free attribute values.
+ *   ipp_get_code()         - Convert a C locale/charset name into an IPP
+ *                            language/charset code.
+ *   ipp_lang_code()        - Convert a C locale name into an IPP language
+ *                            code.
+ *   ipp_length()           - Compute the length of an IPP message or
+ *                            collection value.
+ *   ipp_read_http()        - Semi-blocking read on a HTTP connection...
+ *   ipp_read_file()        - Read IPP data from a file.
+ *   ipp_set_error()        - Set a formatted, localized error string.
+ *   ipp_set_value()        - Get the value element from an attribute,
+ *                            expanding it as needed.
+ *   ipp_write_file()       - Write IPP data to a file.
  */
 
 /*
  */
 
 #include "cups-private.h"
+#include <regex.h>
 #ifdef WIN32
 #  include <io.h>
 #endif /* WIN32 */
  * Local functions...
  */
 
-static ipp_attribute_t *ipp_add_attr(ipp_t *ipp, const char *name, ipp_tag_t  group_tag,
-                                     ipp_tag_t value_tag, int num_values);
-static void            ipp_free_values(ipp_attribute_t *attr, int element, int count);
-static char            *ipp_get_code(const char *locale, char *buffer, size_t bufsize);
-static char            *ipp_lang_code(const char *locale, char *buffer, size_t bufsize);
+static ipp_attribute_t *ipp_add_attr(ipp_t *ipp, const char *name,
+                                     ipp_tag_t  group_tag, ipp_tag_t value_tag,
+                                     int num_values);
+static void            ipp_free_values(ipp_attribute_t *attr, int element,
+                                       int count);
+static char            *ipp_get_code(const char *locale, char *buffer,
+                                     size_t bufsize)
+                                     __attribute__((nonnull(1,2)));
+static char            *ipp_lang_code(const char *locale, char *buffer,
+                                      size_t bufsize)
+                                      __attribute__((nonnull(1,2)));
 static size_t          ipp_length(ipp_t *ipp, int collection);
 static ssize_t         ipp_read_http(http_t *http, ipp_uchar_t *buffer,
                                      size_t length);
 static ssize_t         ipp_read_file(int *fd, ipp_uchar_t *buffer,
                                      size_t length);
-static _ipp_value_t    *ipp_set_value(ipp_t *ipp, ipp_attribute_t **attr, int element);
+static void            ipp_set_error(ipp_status_t status, const char *format,
+                                     ...);
+static _ipp_value_t    *ipp_set_value(ipp_t *ipp, ipp_attribute_t **attr,
+                                      int element);
 static ssize_t         ipp_write_file(int *fd, ipp_uchar_t *buffer,
                                       size_t length);
 
@@ -189,8 +214,8 @@ _cupsBufferRelease(char *b)         /* I - Buffer to release */
 /*
  * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -235,8 +260,8 @@ ippAddBoolean(ipp_t      *ipp,              /* I - IPP message */
 /*
  * 'ippAddBooleans()' - Add an array of boolean values.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -292,8 +317,8 @@ ippAddBooleans(ipp_t      *ipp,             /* I - IPP message */
 /*
  * 'ippAddCollection()' - Add a collection value.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -301,7 +326,7 @@ ippAddBooleans(ipp_t      *ipp,             /* I - IPP message */
  * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
  * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
  *
- * @since CUPS 1.1.19/Mac OS X 10.3@
+ * @since CUPS 1.1.19/OS X 10.3@
  */
 
 ipp_attribute_t *                      /* O - New attribute */
@@ -343,8 +368,8 @@ ippAddCollection(ipp_t      *ipp,   /* I - IPP message */
 /*
  * 'ippAddCollections()' - Add an array of collection values.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -352,7 +377,7 @@ ippAddCollection(ipp_t      *ipp,   /* I - IPP message */
  * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
  * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
  *
- * @since CUPS 1.1.19/Mac OS X 10.3@
+ * @since CUPS 1.1.19/OS X 10.3@
  */
 
 ipp_attribute_t *                      /* O - New attribute */
@@ -407,8 +432,8 @@ ippAddCollections(
 /*
  * 'ippAddDate()' - Add a date attribute to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -453,8 +478,8 @@ ippAddDate(ipp_t             *ipp,  /* I - IPP message */
 /*
  * 'ippAddInteger()' - Add a integer attribute to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -480,7 +505,7 @@ ippAddInteger(ipp_t      *ipp,              /* I - IPP message */
                 "name=\"%s\", value=%d)", ipp, group, ippTagString(group),
                value_tag, ippTagString(value_tag), name, value));
 
-  value_tag &= IPP_TAG_MASK;
+  value_tag &= IPP_TAG_CUPS_MASK;
 
  /*
   * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
@@ -521,8 +546,8 @@ ippAddInteger(ipp_t      *ipp,              /* I - IPP message */
 /*
  * 'ippAddIntegers()' - Add an array of integer values.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -552,7 +577,7 @@ ippAddIntegers(ipp_t      *ipp,             /* I - IPP message */
                group, ippTagString(group), value_tag, ippTagString(value_tag), name,
                num_values, values));
 
-  value_tag &= IPP_TAG_MASK;
+  value_tag &= IPP_TAG_CUPS_MASK;
 
  /*
   * Range check input...
@@ -593,8 +618,8 @@ ippAddIntegers(ipp_t      *ipp,             /* I - IPP message */
 /*
  * 'ippAddOctetString()' - Add an octetString value to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -602,7 +627,7 @@ ippAddIntegers(ipp_t      *ipp,             /* I - IPP message */
  * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
  * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 ipp_attribute_t        *                       /* O - New attribute */
@@ -616,7 +641,8 @@ ippAddOctetString(ipp_t      *ipp,  /* I - IPP message */
 
 
   if (!ipp || !name || group < IPP_TAG_ZERO ||
-      group == IPP_TAG_END || group >= IPP_TAG_UNSUPPORTED_VALUE)
+      group == IPP_TAG_END || group >= IPP_TAG_UNSUPPORTED_VALUE ||
+      datalen < 0 || datalen > IPP_MAX_LENGTH)
     return (NULL);
 
   if ((attr = ipp_add_attr(ipp, name, group, IPP_TAG_STRING, 1)) == NULL)
@@ -650,8 +676,8 @@ ippAddOctetString(ipp_t      *ipp,  /* I - IPP message */
 /*
  * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -665,7 +691,7 @@ ippAddOctetString(ipp_t      *ipp,  /* I - IPP message */
  * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
  * admin-define (@code IPP_TAG_ADMINDEFINE@).
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 ipp_attribute_t        *                       /* O - New attribute */
@@ -678,7 +704,7 @@ ippAddOutOfBand(ipp_t      *ipp,    /* I - IPP message */
                 "name=\"%s\")", ipp, group, ippTagString(group), value_tag,
                 ippTagString(value_tag), name));
 
-  value_tag &= IPP_TAG_MASK;
+  value_tag &= IPP_TAG_CUPS_MASK;
 
  /*
   * Range check input...
@@ -706,8 +732,8 @@ ippAddOutOfBand(ipp_t      *ipp,    /* I - IPP message */
 /*
  * 'ippAddRange()' - Add a range of values to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -757,8 +783,8 @@ ippAddRange(ipp_t      *ipp,                /* I - IPP message */
 /*
  * 'ippAddRanges()' - Add ranges of values to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -818,8 +844,8 @@ ippAddRanges(ipp_t      *ipp,               /* I - IPP message */
 /*
  * 'ippAddResolution()' - Add a resolution value to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -871,8 +897,8 @@ ippAddResolution(ipp_t      *ipp,   /* I - IPP message */
 /*
  * 'ippAddResolutions()' - Add resolution values to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -935,8 +961,8 @@ ippAddResolutions(ipp_t      *ipp,  /* I - IPP message */
 /*
  * 'ippAddSeparator()' - Add a group separator to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  */
 
 ipp_attribute_t *                      /* O - New attribute */
@@ -962,8 +988,8 @@ ippAddSeparator(ipp_t *ipp)         /* I - IPP message */
 /*
  * 'ippAddString()' - Add a language-encoded string to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -992,7 +1018,8 @@ ippAddString(ipp_t      *ipp,              /* I - IPP message */
 {
   ipp_tag_t            temp_tag;       /* Temporary value tag (masked) */
   ipp_attribute_t      *attr;          /* New attribute */
-  char                 code[32];       /* Charset/language code buffer */
+  char                 code[IPP_MAX_LANGUAGE];
+                                       /* Charset/language code buffer */
 
 
   DEBUG_printf(("ippAddString(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
@@ -1004,7 +1031,7 @@ ippAddString(ipp_t      *ipp,             /* I - IPP message */
   * Range check input...
   */
 
-  temp_tag = (ipp_tag_t)((int)value_tag & IPP_TAG_MASK);
+  temp_tag = (ipp_tag_t)((int)value_tag & IPP_TAG_CUPS_MASK);
 
 #if 0
   if (!ipp || !name || group < IPP_TAG_ZERO ||
@@ -1026,13 +1053,13 @@ ippAddString(ipp_t      *ipp,           /* I - IPP message */
   * See if we need to map charset, language, or locale values...
   */
 
-  if (language && ((int)value_tag & IPP_TAG_COPY) &&
+  if (language && ((int)value_tag & IPP_TAG_CUPS_CONST) &&
       strcmp(language, ipp_lang_code(language, code, sizeof(code))))
     value_tag = temp_tag;              /* Don't do a fast copy */
-  else if (value && value_tag == (ipp_tag_t)(IPP_TAG_CHARSET | IPP_TAG_COPY) &&
+  else if (value && value_tag == (ipp_tag_t)(IPP_TAG_CHARSET | IPP_TAG_CUPS_CONST) &&
            strcmp(value, ipp_get_code(value, code, sizeof(code))))
     value_tag = temp_tag;              /* Don't do a fast copy */
-  else if (value && value_tag == (ipp_tag_t)(IPP_TAG_LANGUAGE | IPP_TAG_COPY) &&
+  else if (value && value_tag == (ipp_tag_t)(IPP_TAG_LANGUAGE | IPP_TAG_CUPS_CONST) &&
            strcmp(value, ipp_lang_code(value, code, sizeof(code))))
     value_tag = temp_tag;              /* Don't do a fast copy */
 
@@ -1047,7 +1074,7 @@ ippAddString(ipp_t      *ipp,             /* I - IPP message */
   * Initialize the attribute data...
   */
 
-  if ((int)value_tag & IPP_TAG_COPY)
+  if ((int)value_tag & IPP_TAG_CUPS_CONST)
   {
     attr->values[0].string.language = (char *)language;
     attr->values[0].string.text     = (char *)value;
@@ -1058,25 +1085,243 @@ ippAddString(ipp_t      *ipp,          /* I - IPP message */
       attr->values[0].string.language = _cupsStrAlloc(ipp_lang_code(language, code,
                                                      sizeof(code)));
 
-    if (value_tag == IPP_TAG_CHARSET)
-      attr->values[0].string.text = _cupsStrAlloc(ipp_get_code(value, code,
-                                                               sizeof(code)));
-    else if (value_tag == IPP_TAG_LANGUAGE)
-      attr->values[0].string.text = _cupsStrAlloc(ipp_lang_code(value, code,
-                                                                sizeof(code)));
-    else
-      attr->values[0].string.text = _cupsStrAlloc(value);
+    if (value)
+    {
+      if (value_tag == IPP_TAG_CHARSET)
+       attr->values[0].string.text = _cupsStrAlloc(ipp_get_code(value, code,
+                                                                sizeof(code)));
+      else if (value_tag == IPP_TAG_LANGUAGE)
+       attr->values[0].string.text = _cupsStrAlloc(ipp_lang_code(value, code,
+                                                                 sizeof(code)));
+      else
+       attr->values[0].string.text = _cupsStrAlloc(value);
+    }
   }
 
   return (attr);
 }
 
 
+/*
+ * 'ippAddStringf()' - Add a formatted string to an IPP message.
+ *
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
+ *
+ * The @code group@ parameter specifies the IPP attribute group tag: none
+ * (@code IPP_TAG_ZERO@, for member attributes), document
+ * (@code IPP_TAG_DOCUMENT@), event notification
+ * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
+ * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
+ * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
+ *
+ * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
+ * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
+ * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
+ * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
+ * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
+ * (@code IPP_TAG_URISCHEME@).
+ *
+ * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
+ * and textWithLanguage string values and must be @code NULL@ for all other
+ * string values.
+ *
+ * The @code format@ parameter uses formatting characters compatible with the
+ * printf family of standard functions.  Additional arguments follow it as
+ * needed.  The formatted string is truncated as needed to the maximum length of
+ * the corresponding value type.
+ *
+ * @since CUPS 1.7@
+ */
+
+ipp_attribute_t *                      /* O - New attribute */
+ippAddStringf(ipp_t      *ipp,         /* I - IPP message */
+              ipp_tag_t  group,                /* I - IPP group */
+             ipp_tag_t  value_tag,     /* I - Type of attribute */
+             const char *name,         /* I - Name of attribute */
+             const char *language,     /* I - Language code (@code NULL@ for default) */
+             const char *format,       /* I - Printf-style format string */
+             ...)                      /* I - Additional arguments as needed */
+{
+  ipp_attribute_t      *attr;          /* New attribute */
+  va_list              ap;             /* Argument pointer */
+
+
+  va_start(ap, format);
+  attr = ippAddStringfv(ipp, group, value_tag, name, language, format, ap);
+  va_end(ap);
+
+  return (attr);
+}
+
+
+/*
+ * 'ippAddStringfv()' - Add a formatted string to an IPP message.
+ *
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
+ *
+ * The @code group@ parameter specifies the IPP attribute group tag: none
+ * (@code IPP_TAG_ZERO@, for member attributes), document
+ * (@code IPP_TAG_DOCUMENT@), event notification
+ * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
+ * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
+ * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
+ *
+ * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
+ * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
+ * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
+ * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
+ * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
+ * (@code IPP_TAG_URISCHEME@).
+ *
+ * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
+ * and textWithLanguage string values and must be @code NULL@ for all other
+ * string values.
+ *
+ * The @code format@ parameter uses formatting characters compatible with the
+ * printf family of standard functions.  Additional arguments are passed in the
+ * stdarg pointer @code ap@.  The formatted string is truncated as needed to the
+ * maximum length of the corresponding value type.
+ *
+ * @since CUPS 1.7@
+ */
+
+ipp_attribute_t *                      /* O - New attribute */
+ippAddStringfv(ipp_t      *ipp,                /* I - IPP message */
+               ipp_tag_t  group,       /* I - IPP group */
+              ipp_tag_t  value_tag,    /* I - Type of attribute */
+              const char *name,        /* I - Name of attribute */
+              const char *language,    /* I - Language code (@code NULL@ for default) */
+              const char *format,      /* I - Printf-style format string */
+              va_list    ap)           /* I - Additional arguments */
+{
+  char         buffer[IPP_MAX_TEXT + 4];
+                                       /* Formatted text string */
+  ssize_t      bytes,                  /* Length of formatted value */
+               max_bytes;              /* Maximum number of bytes for value */
+
+
+ /*
+  * Range check input...
+  */
+
+  if (!ipp || !name || group < IPP_TAG_ZERO ||
+      group == IPP_TAG_END || group >= IPP_TAG_UNSUPPORTED_VALUE ||
+      (value_tag < IPP_TAG_TEXT && value_tag != IPP_TAG_TEXTLANG &&
+       value_tag != IPP_TAG_NAMELANG) || value_tag > IPP_TAG_MIMETYPE ||
+      !format || !ap)
+    return (NULL);
+
+  if ((value_tag == IPP_TAG_TEXTLANG || value_tag == IPP_TAG_NAMELANG)
+          != (language != NULL))
+    return (NULL);
+
+ /*
+  * Format the string...
+  */
+
+  if (!strcmp(format, "%s"))
+  {
+   /*
+    * Optimize the simple case...
+    */
+
+    const char *s = va_arg(ap, char *);
+
+    if (!s)
+      s = "(null)";
+
+    bytes = strlen(s);
+    strlcpy(buffer, s, sizeof(buffer));
+  }
+  else
+  {
+   /*
+    * Do a full formatting of the message...
+    */
+
+    if ((bytes = vsnprintf(buffer, sizeof(buffer), format, ap)) < 0)
+      return (NULL);
+  }
+
+ /*
+  * Limit the length of the string...
+  */
+
+  switch (value_tag)
+  {
+    default :
+    case IPP_TAG_TEXT :
+    case IPP_TAG_TEXTLANG :
+        max_bytes = IPP_MAX_TEXT;
+        break;
+
+    case IPP_TAG_NAME :
+    case IPP_TAG_NAMELANG :
+        max_bytes = IPP_MAX_NAME;
+        break;
+
+    case IPP_TAG_CHARSET :
+        max_bytes = IPP_MAX_CHARSET;
+        break;
+
+    case IPP_TAG_KEYWORD :
+        max_bytes = IPP_MAX_KEYWORD;
+        break;
+
+    case IPP_TAG_LANGUAGE :
+        max_bytes = IPP_MAX_LANGUAGE;
+        break;
+
+    case IPP_TAG_MIMETYPE :
+        max_bytes = IPP_MAX_MIMETYPE;
+        break;
+
+    case IPP_TAG_URI :
+        max_bytes = IPP_MAX_URI;
+        break;
+
+    case IPP_TAG_URISCHEME :
+        max_bytes = IPP_MAX_URISCHEME;
+        break;
+  }
+
+  if (bytes >= max_bytes)
+  {
+    char       *bufmax,                /* Buffer at max_bytes */
+               *bufptr;                /* Pointer into buffer */
+
+    bufptr = buffer + strlen(buffer) - 1;
+    bufmax = buffer + max_bytes - 1;
+
+    while (bufptr > bufmax)
+    {
+      if (*bufptr & 0x80)
+      {
+        while ((*bufptr & 0xc0) == 0x80 && bufptr > buffer)
+          bufptr --;
+      }
+
+      bufptr --;
+    }
+
+    *bufptr = '\0';
+  }
+
+ /*
+  * Add the formatted string and return...
+  */
+
+  return (ippAddString(ipp, group, value_tag, name, language, buffer));
+}
+
+
 /*
  * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code group@ parameter specifies the IPP attribute group tag: none
  * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
@@ -1121,7 +1366,7 @@ ippAddStrings(
   * Range check input...
   */
 
-  temp_tag = (ipp_tag_t)((int)value_tag & IPP_TAG_MASK);
+  temp_tag = (ipp_tag_t)((int)value_tag & IPP_TAG_CUPS_MASK);
 
 #if 0
   if (!ipp || !name || group < IPP_TAG_ZERO ||
@@ -1145,10 +1390,10 @@ ippAddStrings(
   * See if we need to map charset, language, or locale values...
   */
 
-  if (language && ((int)value_tag & IPP_TAG_COPY) &&
+  if (language && ((int)value_tag & IPP_TAG_CUPS_CONST) &&
       strcmp(language, ipp_lang_code(language, code, sizeof(code))))
     value_tag = temp_tag;              /* Don't do a fast copy */
-  else if (values && value_tag == (ipp_tag_t)(IPP_TAG_CHARSET | IPP_TAG_COPY))
+  else if (values && value_tag == (ipp_tag_t)(IPP_TAG_CHARSET | IPP_TAG_CUPS_CONST))
   {
     for (i = 0; i < num_values; i ++)
       if (strcmp(values[i], ipp_get_code(values[i], code, sizeof(code))))
@@ -1157,7 +1402,7 @@ ippAddStrings(
         break;
       }
   }
-  else if (values && value_tag == (ipp_tag_t)(IPP_TAG_LANGUAGE | IPP_TAG_COPY))
+  else if (values && value_tag == (ipp_tag_t)(IPP_TAG_LANGUAGE | IPP_TAG_CUPS_CONST))
   {
     for (i = 0; i < num_values; i ++)
       if (strcmp(values[i], ipp_lang_code(values[i], code, sizeof(code))))
@@ -1186,7 +1431,7 @@ ippAddStrings(
     {
       if (value == attr->values)
       {
-        if ((int)value_tag & IPP_TAG_COPY)
+        if ((int)value_tag & IPP_TAG_CUPS_CONST)
           value->string.language = (char *)language;
         else
           value->string.language = _cupsStrAlloc(ipp_lang_code(language, code,
@@ -1198,7 +1443,7 @@ ippAddStrings(
 
     if (values)
     {
-      if ((int)value_tag & IPP_TAG_COPY)
+      if ((int)value_tag & IPP_TAG_CUPS_CONST)
         value->string.text = (char *)*values++;
       else if (value_tag == IPP_TAG_CHARSET)
        value->string.text = _cupsStrAlloc(ipp_get_code(*values++, code, sizeof(code)));
@@ -1213,6 +1458,133 @@ ippAddStrings(
 }
 
 
+/*
+ * 'ippContainsInteger()' - Determine whether an attribute contains the
+ *                          specified value or is within the list of ranges.
+ *
+ * Returns non-zero when the attribute contains either a matching integer or
+ * enum value, or the value falls within one of the rangeOfInteger values for
+ * the attribute.
+ *
+ * @since CUPS 1.7@
+ */
+
+int                                    /* O - 1 on a match, 0 on no match */
+ippContainsInteger(
+    ipp_attribute_t *attr,             /* I - Attribute */
+    int             value)             /* I - Integer/enum value */
+{
+  int          i;                      /* Looping var */
+  _ipp_value_t *avalue;                /* Current attribute value */
+
+
+ /*
+  * Range check input...
+  */
+
+  if (!attr)
+    return (0);
+
+  if (attr->value_tag != IPP_TAG_INTEGER && attr->value_tag != IPP_TAG_ENUM &&
+      attr->value_tag != IPP_TAG_RANGE)
+    return (0);
+
+ /*
+  * Compare...
+  */
+
+  if (attr->value_tag == IPP_TAG_RANGE)
+  {
+    for (i = attr->num_values, avalue = attr->values; i > 0; i --, avalue ++)
+      if (value >= avalue->range.lower && value <= avalue->range.upper)
+        return (1);
+  }
+  else
+  {
+    for (i = attr->num_values, avalue = attr->values; i > 0; i --, avalue ++)
+      if (value == avalue->integer)
+        return (1);
+  }
+
+  return (0);
+}
+
+
+/*
+ * 'ippContainsString()' - Determine whether an attribute contains the
+ *                         specified string value.
+ *
+ * Returns non-zero when the attribute contains a matching charset, keyword,
+ * language, mimeMediaType, name, text, URI, or URI scheme value.
+ *
+ * @since CUPS 1.7@
+ */
+
+int                                    /* O - 1 on a match, 0 on no match */
+ippContainsString(
+    ipp_attribute_t *attr,             /* I - Attribute */
+    const char      *value)            /* I - String value */
+{
+  int          i;                      /* Looping var */
+  _ipp_value_t *avalue;                /* Current attribute value */
+
+
+  DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", attr, value));
+
+ /*
+  * Range check input...
+  */
+
+  if (!attr || !value)
+  {
+    DEBUG_puts("1ippContainsString: Returning 0 (bad input)");
+    return (0);
+  }
+
+ /*
+  * Compare...
+  */
+
+  DEBUG_printf(("1ippContainsString: attr %s, %s with %d values.",
+               attr->name, ippTagString(attr->value_tag),
+               attr->num_values));
+
+  switch (attr->value_tag & IPP_TAG_CUPS_MASK)
+  {
+    case IPP_TAG_CHARSET :
+    case IPP_TAG_KEYWORD :
+    case IPP_TAG_LANGUAGE :
+    case IPP_TAG_MIMETYPE :
+    case IPP_TAG_NAME :
+    case IPP_TAG_NAMELANG :
+    case IPP_TAG_TEXT :
+    case IPP_TAG_TEXTLANG :
+    case IPP_TAG_URI :
+    case IPP_TAG_URISCHEME :
+       for (i = attr->num_values, avalue = attr->values;
+            i > 0;
+            i --, avalue ++)
+       {
+         DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
+                       attr->num_values - i, avalue->string.text));
+
+         if (!strcmp(value, avalue->string.text))
+         {
+           DEBUG_puts("1ippContainsString: Returning 1 (match)");
+           return (1);
+         }
+        }
+
+    default :
+        break;
+  }
+
+  DEBUG_puts("1ippContainsString: Returning 0 (no match)");
+
+  return (0);
+}
+
+
 /*
  * 'ippCopyAttribute()' - Copy an attribute.
  *
@@ -1221,7 +1593,7 @@ ippAddStrings(
  * created - this should only be done as long as the original source IPP message will
  * not be freed for the life of the destination.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 
@@ -1251,9 +1623,9 @@ ippCopyAttribute(
   * Copy it...
   */
 
-  quickcopy = quickcopy ? IPP_TAG_COPY : 0;
+  quickcopy = quickcopy ? IPP_TAG_CUPS_CONST : 0;
 
-  switch (srcattr->value_tag & ~IPP_TAG_COPY)
+  switch (srcattr->value_tag & ~IPP_TAG_CUPS_CONST)
   {
     case IPP_TAG_ZERO :
         dstattr = ippAddSeparator(dst);
@@ -1306,7 +1678,7 @@ ippCopyAttribute(
               i --, srcval ++, dstval ++)
            dstval->string.text = srcval->string.text;
         }
-       else if (srcattr->value_tag & IPP_TAG_COPY)
+       else if (srcattr->value_tag & IPP_TAG_CUPS_CONST)
        {
          for (i = srcattr->num_values, srcval = srcattr->values,
                   dstval = dstattr->values;
@@ -1383,7 +1755,7 @@ ippCopyAttribute(
            dstval->string.text     = srcval->string.text;
           }
         }
-       else if (srcattr->value_tag & IPP_TAG_COPY)
+       else if (srcattr->value_tag & IPP_TAG_CUPS_CONST)
        {
          for (i = srcattr->num_values, srcval = srcattr->values,
                   dstval = dstattr->values;
@@ -1472,7 +1844,7 @@ ippCopyAttribute(
  * 0 to skip it. The function may also choose to do a partial copy of the source attribute
  * itself.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on error */
@@ -1600,7 +1972,7 @@ ippDelete(ipp_t *ipp)                     /* I - IPP message */
 /*
  * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
  *
- * @since CUPS 1.1.19/Mac OS X 10.3@
+ * @since CUPS 1.1.19/OS X 10.3@
  */
 
 void
@@ -1675,7 +2047,7 @@ ippDeleteAttribute(
  *
  * Deleting all values in an attribute deletes the attribute.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
@@ -1779,7 +2151,7 @@ ippFindNextAttribute(ipp_t      *ipp,     /* I - IPP message */
     DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", attr,
                   attr->name));
 
-    value_tag = (ipp_tag_t)(attr->value_tag & IPP_TAG_MASK);
+    value_tag = (ipp_tag_t)(attr->value_tag & IPP_TAG_CUPS_MASK);
 
     if (attr->name != NULL && _cups_strcasecmp(attr->name, name) == 0 &&
         (value_tag == type || type == IPP_TAG_ZERO ||
@@ -1802,7 +2174,7 @@ ippFindNextAttribute(ipp_t      *ipp,     /* I - IPP message */
 /*
  * 'ippFirstAttribute()' - Return the first attribute in the message.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 ipp_attribute_t        *                       /* O - First attribute or @code NULL@ if none */
@@ -1829,7 +2201,7 @@ ippFirstAttribute(ipp_t *ipp)             /* I - IPP message */
  * The @code element@ parameter specifies which value to get from 0 to
  * @link ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - Boolean value or -1 on error */
@@ -1858,7 +2230,7 @@ ippGetBoolean(ipp_attribute_t *attr,      /* I - IPP attribute */
  * The @code element@ parameter specifies which value to get from 0 to
  * @link ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 ipp_t *                                        /* O - Collection value or @code NULL@ on error */
@@ -1885,7 +2257,7 @@ ippGetCollection(
 /*
  * 'ippGetCount()' - Get the number of values in an attribute.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - Number of values or -1 on error */
@@ -1912,7 +2284,7 @@ ippGetCount(ipp_attribute_t *attr)        /* I - IPP attribute */
  * The @code element@ parameter specifies which value to get from 0 to
  * @link ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 const ipp_uchar_t *                    /* O - Date value or @code NULL@ */
@@ -1938,7 +2310,7 @@ ippGetDate(ipp_attribute_t *attr, /* I - IPP attribute */
 /*
  * 'ippGetGroupTag()' - Get the group associated with an attribute.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 ipp_tag_t                              /* O - Group tag or @code IPP_TAG_ZERO@ on error */
@@ -1965,7 +2337,7 @@ ippGetGroupTag(ipp_attribute_t *attr)     /* I - IPP attribute */
  * The @code element@ parameter specifies which value to get from 0 to
  * @link ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - Value or -1 on error */
@@ -1991,7 +2363,7 @@ ippGetInteger(ipp_attribute_t *attr,      /* I - IPP attribute */
 /*
  * 'ippGetName()' - Get the attribute name.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 const char *                           /* O - Attribute name or @code NULL@ for separators */
@@ -2012,10 +2384,49 @@ ippGetName(ipp_attribute_t *attr)       /* I - IPP attribute */
 }
 
 
+/*
+ * 'ippGetOctetString()' - Get an octetString value from an IPP attribute.
+ *
+ * The @code element@ parameter specifies which value to get from 0 to
+ * @link ippGetCount(attr)@ - 1.
+ *
+ * @since CUPS 1.7@
+ */
+
+void *                                 /* O - Pointer to octetString data */
+ippGetOctetString(
+    ipp_attribute_t *attr,             /* I - IPP attribute */
+    int             element,           /* I - Value number (0-based) */
+    int             *datalen)          /* O - Length of octetString data */
+{
+ /*
+  * Range check input...
+  */
+
+  if (!attr || attr->value_tag != IPP_TAG_STRING ||
+      element < 0 || element >= attr->num_values)
+  {
+    if (datalen)
+      *datalen = 0;
+
+    return (NULL);
+  }
+
+ /*
+  * Return the values...
+  */
+
+  if (datalen)
+    *datalen = attr->values[element].unknown.length;
+
+  return (attr->values[element].unknown.data);
+}
+
+
 /*
  * 'ippGetOperation()' - Get the operation ID in an IPP message.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 ipp_op_t                               /* O - Operation ID or -1 on error */
@@ -2042,7 +2453,7 @@ ippGetOperation(ipp_t *ipp)               /* I - IPP request message */
  * The @code element@ parameter specifies which value to get from 0 to
  * @link ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - Lower value of range or -1 */
@@ -2077,7 +2488,7 @@ ippGetRange(ipp_attribute_t *attr,        /* I - IPP attribute */
 /*
  * 'ippGetRequestId()' - Get the request ID from an IPP message.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - Request ID or -1 on error */
@@ -2104,7 +2515,7 @@ ippGetRequestId(ipp_t *ipp)               /* I - IPP message */
  * The @code element@ parameter specifies which value to get from 0 to
  * @link ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - Horizontal/cross feed resolution or -1 */
@@ -2139,7 +2550,7 @@ ippGetResolution(
 /*
  * 'ippGetState()' - Get the IPP message state.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 ipp_state_t                            /* O - IPP message state value */
@@ -2150,7 +2561,7 @@ ippGetState(ipp_t *ipp)                   /* I - IPP message */
   */
 
   if (!ipp)
-    return (IPP_IDLE);
+    return (IPP_STATE_IDLE);
 
  /*
   * Return the value...
@@ -2163,7 +2574,7 @@ ippGetState(ipp_t *ipp)                   /* I - IPP message */
 /*
  * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 ipp_status_t                           /* O - Status code in IPP message */
@@ -2174,7 +2585,7 @@ ippGetStatusCode(ipp_t *ipp)              /* I - IPP response or event message */
   */
 
   if (!ipp)
-    return (IPP_INTERNAL_ERROR);
+    return (IPP_STATUS_ERROR_INTERNAL);
 
  /*
   * Return the value...
@@ -2190,7 +2601,7 @@ ippGetStatusCode(ipp_t *ipp)              /* I - IPP response or event message */
  * The @code element@ parameter specifies which value to get from 0 to
  * @link ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 const char *
@@ -2221,7 +2632,7 @@ ippGetString(ipp_attribute_t *attr,       /* I - IPP attribute */
 /*
  * 'ippGetValueTag()' - Get the value tag for an attribute.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 ipp_tag_t                              /* O - Value tag or @code IPP_TAG_ZERO@ on error */
@@ -2238,14 +2649,14 @@ ippGetValueTag(ipp_attribute_t *attr)   /* I - IPP attribute */
   * Return the value...
   */
 
-  return (attr->value_tag);
+  return (attr->value_tag & IPP_TAG_CUPS_MASK);
 }
 
 
 /*
  * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - Major version number or -1 on error */
@@ -2289,7 +2700,7 @@ ippLength(ipp_t *ipp)                     /* I - IPP message */
 /*
  * 'ippNextAttribute()' - Return the next attribute in the message.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 ipp_attribute_t *                      /* O - Next attribute or @code NULL@ if none */
@@ -2317,7 +2728,9 @@ ippNextAttribute(ipp_t *ipp)              /* I - IPP message */
 ipp_t *                                        /* O - New IPP message */
 ippNew(void)
 {
-  ipp_t        *temp;                          /* New IPP message */
+  ipp_t                        *temp;          /* New IPP message */
+  _cups_globals_t      *cg = _cupsGlobals();
+                                       /* Global data */
 
 
   DEBUG_puts("ippNew()");
@@ -2325,11 +2738,11 @@ ippNew(void)
   if ((temp = (ipp_t *)calloc(1, sizeof(ipp_t))) != NULL)
   {
    /*
-    * Default to IPP 2.0...
+    * Set default version - usually 2.0...
     */
 
-    temp->request.any.version[0] = 2;
-    temp->request.any.version[1] = 0;
+    temp->request.any.version[0] = cg->server_version / 10;
+    temp->request.any.version[1] = cg->server_version % 10;
     temp->use                    = 1;
   }
 
@@ -2346,7 +2759,7 @@ ippNew(void)
  * attributes-natural-language attributes added. The
  * attributes-natural-language value is derived from the current locale.
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 ipp_t *                                        /* O - IPP request message */
@@ -2404,20 +2817,128 @@ ippNewRequest(ipp_op_t op)             /* I - Operation code */
 
 
 /*
- * 'ippRead()' - Read data for an IPP message from a HTTP connection.
+ * 'ippNewResponse()' - Allocate a new IPP response message.
+ *
+ * The new response message is initialized with the same version-number,
+ * request-id, attributes-charset, and attributes-natural-language as the
+ * provided request message.  If the attributes-charset or
+ * attributes-natural-language attributes are missing from the request,
+ * "utf-8" and a value derived from the current locale are substituted,
+ * respectively.
+ *
+ * @since CUPS 1.7@
  */
 
-ipp_state_t                            /* O - Current state */
-ippRead(http_t *http,                  /* I - HTTP connection */
-        ipp_t  *ipp)                   /* I - IPP data */
+ipp_t *                                        /* O - IPP response message */
+ippNewResponse(ipp_t *request)         /* I - IPP request message */
 {
-  DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT,
-                http, ipp, CUPS_LLCAST (http ? http->data_remaining : -1)));
+  ipp_t                        *response;      /* IPP response message */
+  ipp_attribute_t      *attr;          /* Current attribute */
 
-  if (!http)
-    return (IPP_ERROR);
 
-  DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http->state,
+ /*
+  * Range check input...
+  */
+
+  if (!request)
+    return (NULL);
+
+ /*
+  * Create a new IPP message...
+  */
+
+  if ((response = ippNew()) == NULL)
+    return (NULL);
+
+ /*
+  * Copy the request values over to the response...
+  */
+
+  response->request.status.version[0] = request->request.op.version[0];
+  response->request.status.version[1] = request->request.op.version[1];
+  response->request.status.request_id = request->request.op.request_id;
+
+ /*
+  * The first attribute MUST be attributes-charset...
+  */
+
+  attr = request->attrs;
+
+  if (attr && attr->name && !strcmp(attr->name, "attributes-charset") &&
+      attr->group_tag == IPP_TAG_OPERATION &&
+      attr->value_tag == IPP_TAG_CHARSET &&
+      attr->num_values == 1)
+  {
+   /*
+    * Copy charset from request...
+    */
+
+    ippAddString(response, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
+                "attributes-charset", NULL, attr->values[0].string.text);
+  }
+  else
+  {
+   /*
+    * Use "utf-8" as the default...
+    */
+
+    ippAddString(response, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
+                "attributes-charset", NULL, "utf-8");
+  }
+
+ /*
+  * Then attributes-natural-language...
+  */
+
+  if (attr)
+    attr = attr->next;
+
+  if (attr && attr->name &&
+      !strcmp(attr->name, "attributes-natural-language") &&
+      attr->group_tag == IPP_TAG_OPERATION &&
+      attr->value_tag == IPP_TAG_LANGUAGE &&
+      attr->num_values == 1)
+  {
+   /*
+    * Copy language from request...
+    */
+
+    ippAddString(response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
+                "attributes-natural-language", NULL,
+                attr->values[0].string.text);
+  }
+  else
+  {
+   /*
+    * Use the language from the current locale...
+    */
+
+    cups_lang_t *language = cupsLangDefault();
+                                       /* Current locale */
+
+    ippAddString(response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
+                "attributes-natural-language", NULL, language->language);
+  }
+
+  return (response);
+}
+
+
+/*
+ * 'ippRead()' - Read data for an IPP message from a HTTP connection.
+ */
+
+ipp_state_t                            /* O - Current state */
+ippRead(http_t *http,                  /* I - HTTP connection */
+        ipp_t  *ipp)                   /* I - IPP data */
+{
+  DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT,
+                http, ipp, CUPS_LLCAST (http ? http->data_remaining : -1)));
+
+  if (!http)
+    return (IPP_STATE_ERROR);
+
+  DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http->state,
                 http->used));
 
   return (ippReadIO(http, (ipp_iocb_t)ipp_read_http, http->blocking, NULL,
@@ -2428,7 +2949,7 @@ ippRead(http_t *http,                     /* I - HTTP connection */
 /*
  * 'ippReadFile()' - Read data for an IPP message from a file.
  *
- * @since CUPS 1.1.19/Mac OS X 10.3@
+ * @since CUPS 1.1.19/OS X 10.3@
  */
 
 ipp_state_t                            /* O - Current state */
@@ -2444,7 +2965,7 @@ ippReadFile(int   fd,                     /* I - HTTP data */
 /*
  * 'ippReadIO()' - Read data for an IPP message.
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 ipp_state_t                            /* O - Current state */
@@ -2456,7 +2977,7 @@ ippReadIO(void       *src,                /* I - Data source */
 {
   int                  n;              /* Length of data */
   unsigned char                *buffer,        /* Data buffer */
-                       string[IPP_MAX_NAME],
+                       string[IPP_MAX_TEXT],
                                        /* Small string buffer */
                        *bufptr;        /* Pointer into buffer */
   ipp_attribute_t      *attr;          /* Current attribute */
@@ -2467,23 +2988,23 @@ ippReadIO(void       *src,              /* I - Data source */
 
   DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)",
                 src, cb, blocking, parent, ipp));
-  DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp->state));
+  DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp ? ipp->state : IPP_STATE_ERROR));
 
   if (!src || !ipp)
-    return (IPP_ERROR);
+    return (IPP_STATE_ERROR);
 
   if ((buffer = (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE)) == NULL)
   {
     DEBUG_puts("1ippReadIO: Unable to get read buffer.");
-    return (IPP_ERROR);
+    return (IPP_STATE_ERROR);
   }
 
   switch (ipp->state)
   {
-    case IPP_IDLE :
+    case IPP_STATE_IDLE :
         ipp->state ++; /* Avoid common problem... */
 
-    case IPP_HEADER :
+    case IPP_STATE_HEADER :
         if (parent == NULL)
        {
         /*
@@ -2494,7 +3015,7 @@ ippReadIO(void       *src,                /* I - Data source */
          {
            DEBUG_puts("1ippReadIO: Unable to read header.");
            _cupsBufferRelease((char *)buffer);
-           return (IPP_ERROR);
+           return (IPP_STATE_ERROR);
          }
 
         /*
@@ -2514,7 +3035,7 @@ ippReadIO(void       *src,                /* I - Data source */
                        ipp->request.any.request_id));
         }
 
-        ipp->state   = IPP_ATTRIBUTE;
+        ipp->state   = IPP_STATE_ATTRIBUTE;
        ipp->current = NULL;
        ipp->curtag  = IPP_TAG_ZERO;
        ipp->prev    = ipp->last;
@@ -2526,14 +3047,14 @@ ippReadIO(void       *src,              /* I - Data source */
         if (!blocking)
          break;
 
-    case IPP_ATTRIBUTE :
+    case IPP_STATE_ATTRIBUTE :
         for (;;)
        {
          if ((*cb)(src, buffer, 1) < 1)
          {
            DEBUG_puts("1ippReadIO: Callback returned EOF/error");
            _cupsBufferRelease((char *)buffer);
-           return (IPP_ERROR);
+           return (IPP_STATE_ERROR);
          }
 
          DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p",
@@ -2554,22 +3075,22 @@ ippReadIO(void       *src,              /* I - Data source */
            {
              DEBUG_puts("1ippReadIO: Callback returned EOF/error");
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
 
            tag = (ipp_tag_t)((((((buffer[0] << 8) | buffer[1]) << 8) |
                                buffer[2]) << 8) | buffer[3]);
 
-            if (tag & IPP_TAG_COPY)
+            if (tag & IPP_TAG_CUPS_CONST)
             {
              /*
               * Fail if the high bit is set in the tag...
               */
 
-             _cupsSetError(IPP_INTERNAL_ERROR, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
-             DEBUG_printf(("1ippReadIO: bad name length %d.", n));
+             _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
+             DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag));
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
             }
           }
 
@@ -2581,7 +3102,7 @@ ippReadIO(void       *src,                /* I - Data source */
 
             DEBUG_puts("2ippReadIO: IPP_TAG_END.");
 
-           ipp->state = IPP_DATA;
+           ipp->state = IPP_STATE_DATA;
            break;
          }
           else if (tag < IPP_TAG_UNSUPPORTED_VALUE)
@@ -2613,17 +3134,17 @@ ippReadIO(void       *src,              /* I - Data source */
          {
            DEBUG_puts("1ippReadIO: unable to read name length.");
            _cupsBufferRelease((char *)buffer);
-           return (IPP_ERROR);
+           return (IPP_STATE_ERROR);
          }
 
           n = (buffer[0] << 8) | buffer[1];
 
           if (n >= IPP_BUF_SIZE)
          {
-           _cupsSetError(IPP_INTERNAL_ERROR, _("IPP name larger than 32767 bytes."), 1);
+           _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("IPP name larger than 32767 bytes."), 1);
            DEBUG_printf(("1ippReadIO: bad name length %d.", n));
            _cupsBufferRelease((char *)buffer);
-           return (IPP_ERROR);
+           return (IPP_STATE_ERROR);
          }
 
           DEBUG_printf(("2ippReadIO: name length=%d", n));
@@ -2637,14 +3158,14 @@ ippReadIO(void       *src,              /* I - Data source */
 
             if (ipp->current == NULL)
            {
-             _cupsSetError(IPP_INTERNAL_ERROR, _("IPP attribute has no name."), 1);
+             _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("IPP attribute has no name."), 1);
              DEBUG_puts("1ippReadIO: Attribute without name and no current.");
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
 
             attr      = ipp->current;
-           value_tag = (ipp_tag_t)(attr->value_tag & IPP_TAG_MASK);
+           value_tag = (ipp_tag_t)(attr->value_tag & IPP_TAG_CUPS_MASK);
 
           /*
            * Make sure we aren't adding a new value of a different
@@ -2673,14 +3194,14 @@ ippReadIO(void       *src,              /* I - Data source */
                  (tag < IPP_TAG_TEXT || tag > IPP_TAG_MIMETYPE) &&
                  tag != IPP_TAG_NOVALUE)
              {
-               _cupsSetError(IPP_INTERNAL_ERROR,
+               _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                              _("IPP 1setOf attribute with incompatible value "
                                "tags."), 1);
                DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
                              value_tag, ippTagString(value_tag), tag,
                              ippTagString(tag)));
                _cupsBufferRelease((char *)buffer);
-               return (IPP_ERROR);
+               return (IPP_STATE_ERROR);
              }
 
               if (value_tag != tag)
@@ -2700,14 +3221,14 @@ ippReadIO(void       *src,              /* I - Data source */
 
              if (tag != IPP_TAG_INTEGER && tag != IPP_TAG_RANGE)
              {
-               _cupsSetError(IPP_INTERNAL_ERROR,
+               _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                              _("IPP 1setOf attribute with incompatible value "
                                "tags."), 1);
                DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
                              value_tag, ippTagString(value_tag), tag,
                              ippTagString(tag)));
                _cupsBufferRelease((char *)buffer);
-               return (IPP_ERROR);
+               return (IPP_STATE_ERROR);
              }
 
               if (value_tag == IPP_TAG_INTEGER && tag == IPP_TAG_RANGE)
@@ -2723,14 +3244,14 @@ ippReadIO(void       *src,              /* I - Data source */
             }
            else if (value_tag != tag)
            {
-             _cupsSetError(IPP_INTERNAL_ERROR,
+             _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                            _("IPP 1setOf attribute with incompatible value "
                              "tags."), 1);
              DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
                            value_tag, ippTagString(value_tag), tag,
                            ippTagString(tag)));
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
             }
 
            /*
@@ -2740,7 +3261,7 @@ ippReadIO(void       *src,                /* I - Data source */
            if ((value = ipp_set_value(ipp, &attr, attr->num_values)) == NULL)
            {
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
          }
          else if (tag == IPP_TAG_MEMBERNAME)
@@ -2751,16 +3272,23 @@ ippReadIO(void       *src,              /* I - Data source */
 
            if (n)
            {
-             _cupsSetError(IPP_INTERNAL_ERROR, _("IPP member name is not empty."), 1);
+             _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("IPP member name is not empty."), 1);
              DEBUG_puts("1ippReadIO: member name not empty.");
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
 
             if (ipp->current)
              ipp->prev = ipp->current;
 
            attr = ipp->current = ipp_add_attr(ipp, NULL, ipp->curtag, IPP_TAG_ZERO, 1);
+           if (!attr)
+           {
+             _cupsSetHTTPError(HTTP_STATUS_ERROR);
+             DEBUG_puts("1ippReadIO: unable to allocate attribute.");
+             _cupsBufferRelease((char *)buffer);
+             return (IPP_STATE_ERROR);
+           }
 
            DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p",
                          ipp->current, ipp->prev));
@@ -2777,7 +3305,7 @@ ippReadIO(void       *src,                /* I - Data source */
            {
              DEBUG_puts("1ippReadIO: unable to read name.");
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
 
            buffer[n] = '\0';
@@ -2788,10 +3316,10 @@ ippReadIO(void       *src,              /* I - Data source */
            if ((attr = ipp->current = ipp_add_attr(ipp, (char *)buffer, ipp->curtag, tag,
                                                    1)) == NULL)
            {
-             _cupsSetHTTPError(HTTP_ERROR);
+             _cupsSetHTTPError(HTTP_STATUS_ERROR);
              DEBUG_puts("1ippReadIO: unable to allocate attribute.");
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
 
            DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, "
@@ -2809,7 +3337,7 @@ ippReadIO(void       *src,                /* I - Data source */
          {
            DEBUG_puts("1ippReadIO: unable to read value length.");
            _cupsBufferRelease((char *)buffer);
-           return (IPP_ERROR);
+           return (IPP_STATE_ERROR);
          }
 
          n = (buffer[0] << 8) | buffer[1];
@@ -2817,11 +3345,11 @@ ippReadIO(void       *src,              /* I - Data source */
 
          if (n >= IPP_BUF_SIZE)
          {
-           _cupsSetError(IPP_INTERNAL_ERROR,
+           _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                          _("IPP value larger than 32767 bytes."), 1);
            DEBUG_printf(("1ippReadIO: bad value length %d.", n));
            _cupsBufferRelease((char *)buffer);
-           return (IPP_ERROR);
+           return (IPP_STATE_ERROR);
          }
 
          switch (tag)
@@ -2831,21 +3359,21 @@ ippReadIO(void       *src,              /* I - Data source */
                if (n != 4)
                {
                  if (tag == IPP_TAG_INTEGER)
-                   _cupsSetError(IPP_INTERNAL_ERROR,
+                   _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                  _("IPP integer value not 4 bytes."), 1);
                  else
-                   _cupsSetError(IPP_INTERNAL_ERROR,
+                   _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                  _("IPP enum value not 4 bytes."), 1);
-                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
+                 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                if ((*cb)(src, buffer, 4) < 4)
                {
                  DEBUG_puts("1ippReadIO: Unable to read integer value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                n = (((((buffer[0] << 8) | buffer[1]) << 8) | buffer[2]) << 8) |
@@ -2860,18 +3388,18 @@ ippReadIO(void       *src,              /* I - Data source */
            case IPP_TAG_BOOLEAN :
                if (n != 1)
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR, _("IPP boolean value not 1 byte."),
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("IPP boolean value not 1 byte."),
                                1);
-                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
+                 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                if ((*cb)(src, buffer, 1) < 1)
                {
                  DEBUG_puts("1ippReadIO: Unable to read boolean value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                 value->boolean = buffer[0];
@@ -2903,11 +3431,14 @@ ippReadIO(void       *src,              /* I - Data source */
            case IPP_TAG_CHARSET :
            case IPP_TAG_LANGUAGE :
            case IPP_TAG_MIMETYPE :
-               if ((*cb)(src, buffer, n) < n)
-               {
-                 DEBUG_puts("1ippReadIO: unable to read string value.");
-                 _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+               if (n > 0)
+               {
+                 if ((*cb)(src, buffer, n) < n)
+                 {
+                   DEBUG_puts("1ippReadIO: unable to read string value.");
+                   _cupsBufferRelease((char *)buffer);
+                   return (IPP_STATE_ERROR);
+                 }
                }
 
                buffer[n] = '\0';
@@ -2918,35 +3449,35 @@ ippReadIO(void       *src,              /* I - Data source */
            case IPP_TAG_DATE :
                if (n != 11)
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR, _("IPP date value not 11 bytes."), 1);
-                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("IPP date value not 11 bytes."), 1);
+                 DEBUG_printf(("1ippReadIO: bad date value length %d.", n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                if ((*cb)(src, value->date, 11) < 11)
                {
                  DEBUG_puts("1ippReadIO: Unable to read date value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
                break;
 
            case IPP_TAG_RESOLUTION :
                if (n != 9)
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                _("IPP resolution value not 9 bytes."), 1);
-                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
+                 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                if ((*cb)(src, buffer, 9) < 9)
                {
                  DEBUG_puts("1ippReadIO: Unable to read resolution value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                 value->resolution.xres =
@@ -2962,18 +3493,19 @@ ippReadIO(void       *src,              /* I - Data source */
            case IPP_TAG_RANGE :
                if (n != 8)
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                _("IPP rangeOfInteger value not 8 bytes."), 1);
-                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
+                 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
+                               "%d.", n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                if ((*cb)(src, buffer, 8) < 8)
                {
                  DEBUG_puts("1ippReadIO: Unable to read range value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                 value->range.lower =
@@ -2989,16 +3521,17 @@ ippReadIO(void       *src,              /* I - Data source */
                if (n < 4)
                {
                  if (tag == IPP_TAG_TEXTLANG)
-                   _cupsSetError(IPP_INTERNAL_ERROR,
+                   _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                  _("IPP textWithLanguage value less than "
                                    "minimum 4 bytes."), 1);
                  else
-                   _cupsSetError(IPP_INTERNAL_ERROR,
+                   _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                  _("IPP nameWithLanguage value less than "
                                    "minimum 4 bytes."), 1);
-                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
+                 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
+                               "length %d.", n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                if ((*cb)(src, buffer, n) < n)
@@ -3006,7 +3539,7 @@ ippReadIO(void       *src,                /* I - Data source */
                  DEBUG_puts("1ippReadIO: Unable to read string w/language "
                             "value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                 bufptr = buffer;
@@ -3026,11 +3559,21 @@ ippReadIO(void       *src,              /* I - Data source */
                if ((bufptr + 2 + n) >= (buffer + IPP_BUF_SIZE) ||
                    n >= sizeof(string))
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                _("IPP language length overflows value."), 1);
-                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
+                 DEBUG_printf(("1ippReadIO: bad language value length %d.",
+                               n));
+                 _cupsBufferRelease((char *)buffer);
+                 return (IPP_STATE_ERROR);
+               }
+               else if (n >= IPP_MAX_LANGUAGE)
+               {
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
+                               _("IPP language length too large."), 1);
+                 DEBUG_printf(("1ippReadIO: bad language value length %d.",
+                               n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                memcpy(string, bufptr + 2, n);
@@ -3043,11 +3586,11 @@ ippReadIO(void       *src,              /* I - Data source */
 
                if ((bufptr + 2 + n) >= (buffer + IPP_BUF_SIZE))
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                _("IPP string length overflows value."), 1);
-                 DEBUG_printf(("1ippReadIO: bad value length %d.", n));
+                 DEBUG_printf(("1ippReadIO: bad string value length %d.", n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                bufptr[2 + n] = '\0';
@@ -3063,19 +3606,19 @@ ippReadIO(void       *src,              /* I - Data source */
 
                 if (n > 0)
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                _("IPP begCollection value not 0 bytes."), 1);
                  DEBUG_puts("1ippReadIO: begCollection tag with value length "
                             "> 0.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
-               if (ippReadIO(src, cb, 1, ipp, value->collection) == IPP_ERROR)
+               if (ippReadIO(src, cb, 1, ipp, value->collection) == IPP_STATE_ERROR)
                {
                  DEBUG_puts("1ippReadIO: Unable to read collection value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
                 break;
 
@@ -3084,15 +3627,15 @@ ippReadIO(void       *src,              /* I - Data source */
 
                 if (n > 0)
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                _("IPP endCollection value not 0 bytes."), 1);
                  DEBUG_puts("1ippReadIO: endCollection tag with value length "
                             "> 0.");
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                DEBUG_puts("1ippReadIO: endCollection tag...");
-               return (ipp->state = IPP_DATA);
+               return (ipp->state = IPP_STATE_DATA);
 
             case IPP_TAG_MEMBERNAME :
               /*
@@ -3100,11 +3643,27 @@ ippReadIO(void       *src,              /* I - Data source */
                * we need to carry over...
                */
 
-               if ((*cb)(src, buffer, n) < n)
+                if (!attr)
+                {
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
+                               _("IPP memberName with no attribute."), 1);
+                 DEBUG_puts("1ippReadIO: Member name without attribute.");
+                 _cupsBufferRelease((char *)buffer);
+                 return (IPP_STATE_ERROR);
+                }
+               else if (n == 0)
+               {
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
+                               _("IPP memberName value is empty."), 1);
+                 DEBUG_puts("1ippReadIO: Empty member name value.");
+                 _cupsBufferRelease((char *)buffer);
+                 return (IPP_STATE_ERROR);
+               }
+               else if ((*cb)(src, buffer, n) < n)
                {
                  DEBUG_puts("1ippReadIO: Unable to read member name value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                buffer[n] = '\0';
@@ -3122,22 +3681,33 @@ ippReadIO(void       *src,              /* I - Data source */
                break;
 
             default : /* Other unsupported values */
+                if (tag == IPP_TAG_STRING && n > IPP_MAX_LENGTH)
+               {
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
+                               _("IPP octetString length too large."), 1);
+                 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
+                               n));
+                 _cupsBufferRelease((char *)buffer);
+                 return (IPP_STATE_ERROR);
+               }
+
                 value->unknown.length = n;
+
                if (n > 0)
                {
                  if ((value->unknown.data = malloc(n)) == NULL)
                  {
-                   _cupsSetHTTPError(HTTP_ERROR);
+                   _cupsSetHTTPError(HTTP_STATUS_ERROR);
                    DEBUG_puts("1ippReadIO: Unable to allocate value");
                    _cupsBufferRelease((char *)buffer);
-                   return (IPP_ERROR);
+                   return (IPP_STATE_ERROR);
                  }
 
                  if ((*cb)(src, value->unknown.data, n) < n)
                  {
                    DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
                    _cupsBufferRelease((char *)buffer);
-                   return (IPP_ERROR);
+                   return (IPP_STATE_ERROR);
                  }
                }
                else
@@ -3154,7 +3724,7 @@ ippReadIO(void       *src,                /* I - Data source */
        }
         break;
 
-    case IPP_DATA :
+    case IPP_STATE_DATA :
         break;
 
     default :
@@ -3171,19 +3741,19 @@ ippReadIO(void       *src,              /* I - Data source */
 /*
  * 'ippSetBoolean()' - Set a boolean value in an attribute.
  *
- * The @code ipp@ parameter refers to the IPP message containing the attribute that was
- * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
  * The @code element@ parameter specifies which value to set from 0 to
  * @link ippGetCount(attr)@.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
-ippSetBoolean(ipp_t           *ipp,    /* IO - IPP message */
+ippSetBoolean(ipp_t           *ipp,    /* I  - IPP message */
               ipp_attribute_t **attr,  /* IO - IPP attribute */
               int             element, /* I  - Value number (0-based) */
               int             boolvalue)/* I  - Boolean value */
@@ -3213,20 +3783,20 @@ ippSetBoolean(ipp_t           *ipp,     /* IO - IPP message */
 /*
  * 'ippSetCollection()' - Set a collection value in an attribute.
  *
- * The @code ipp@ parameter refers to the IPP message containing the attribute that was
- * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
  * The @code element@ parameter specifies which value to set from 0 to
  * @link ippGetCount(attr)@.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
 ippSetCollection(
-    ipp_t           *ipp,              /* IO - IPP message */
+    ipp_t           *ipp,              /* I  - IPP message */
     ipp_attribute_t **attr,            /* IO - IPP attribute */
     int             element,           /* I  - Value number (0-based) */
     ipp_t           *colvalue)         /* I  - Collection value */
@@ -3262,19 +3832,19 @@ ippSetCollection(
 /*
  * 'ippSetDate()' - Set a date value in an attribute.
  *
- * The @code ipp@ parameter refers to the IPP message containing the attribute that was
- * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
  * The @code element@ parameter specifies which value to set from 0 to
  * @link ippGetCount(attr)@.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
-ippSetDate(ipp_t             *ipp,     /* IO - IPP message */
+ippSetDate(ipp_t             *ipp,     /* I  - IPP message */
            ipp_attribute_t   **attr,   /* IO - IPP attribute */
            int               element,  /* I  - Value number (0-based) */
            const ipp_uchar_t *datevalue)/* I  - Date value */
@@ -3304,8 +3874,8 @@ ippSetDate(ipp_t             *ipp,        /* IO - IPP message */
 /*
  * 'ippSetGroupTag()' - Set the group tag of an attribute.
  *
- * The @code ipp@ parameter refers to the IPP message containing the attribute that was
- * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
@@ -3315,12 +3885,12 @@ ippSetDate(ipp_t             *ipp,      /* IO - IPP message */
  * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
  * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
 ippSetGroupTag(
-    ipp_t           *ipp,              /* IO - IPP message */
+    ipp_t           *ipp,              /* I  - IPP message */
     ipp_attribute_t **attr,            /* IO - Attribute */
     ipp_tag_t       group_tag)         /* I  - Group tag */
 {
@@ -3328,7 +3898,8 @@ ippSetGroupTag(
   * Range check input - group tag must be 0x01 to 0x0F, per RFC 2911...
   */
 
-  if (!ipp || !attr || group_tag < IPP_TAG_ZERO || group_tag == IPP_TAG_END ||
+  if (!ipp || !attr || !*attr ||
+      group_tag < IPP_TAG_ZERO || group_tag == IPP_TAG_END ||
       group_tag >= IPP_TAG_UNSUPPORTED_VALUE)
     return (0);
 
@@ -3345,19 +3916,19 @@ ippSetGroupTag(
 /*
  * 'ippSetInteger()' - Set an integer or enum value in an attribute.
  *
- * The @code ipp@ parameter refers to the IPP message containing the attribute that was
- * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
  * The @code element@ parameter specifies which value to set from 0 to
  * @link ippGetCount(attr)@.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
-ippSetInteger(ipp_t           *ipp,    /* IO - IPP message */
+ippSetInteger(ipp_t           *ipp,    /* I  - IPP message */
               ipp_attribute_t **attr,  /* IO - IPP attribute */
               int             element, /* I  - Value number (0-based) */
               int             intvalue)        /* I  - Integer/enum value */
@@ -3388,16 +3959,16 @@ ippSetInteger(ipp_t           *ipp,     /* IO - IPP message */
 /*
  * 'ippSetName()' - Set the name of an attribute.
  *
- * The @code ipp@ parameter refers to the IPP message containing the attribute that was
- * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
-ippSetName(ipp_t           *ipp,       /* IO - IPP message */
+ippSetName(ipp_t           *ipp,       /* I  - IPP message */
           ipp_attribute_t **attr,      /* IO - IPP attribute */
           const char      *name)       /* I  - Attribute name */
 {
@@ -3427,13 +3998,101 @@ ippSetName(ipp_t           *ipp,       /* IO - IPP message */
 }
 
 
+/*
+ * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
+ *
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
+ *
+ * The @code attr@ parameter may be modified as a result of setting the value.
+ *
+ * The @code element@ parameter specifies which value to set from 0 to
+ * @link ippGetCount(attr)@.
+ *
+ * @since CUPS 1.7@
+ */
+
+int                                    /* O  - 1 on success, 0 on failure */
+ippSetOctetString(
+    ipp_t           *ipp,              /* I  - IPP message */
+    ipp_attribute_t **attr,            /* IO - IPP attribute */
+    int             element,           /* I  - Value number (0-based) */
+    const void      *data,             /* I  - Pointer to octetString data */
+    int             datalen)           /* I  - Length of octetString data */
+{
+  _ipp_value_t *value;                 /* Current value */
+
+
+ /*
+  * Range check input...
+  */
+
+  if (!ipp || !attr || !*attr || (*attr)->value_tag != IPP_TAG_STRING ||
+      element < 0 || element > (*attr)->num_values ||
+      datalen < 0 || datalen > IPP_MAX_LENGTH)
+    return (0);
+
+ /*
+  * Set the value and return...
+  */
+
+  if ((value = ipp_set_value(ipp, attr, element)) != NULL)
+  {
+    if ((int)((*attr)->value_tag) & IPP_TAG_CUPS_CONST)
+    {
+     /*
+      * Just copy the pointer...
+      */
+
+      value->unknown.data   = (void *)data;
+      value->unknown.length = datalen;
+    }
+    else
+    {
+     /*
+      * Copy the data...
+      */
+
+      if (value->unknown.data)
+      {
+       /*
+       * Free previous data...
+       */
+
+       free(value->unknown.data);
+
+       value->unknown.data   = NULL;
+        value->unknown.length = 0;
+      }
+
+      if (datalen > 0)
+      {
+       void    *temp;                  /* Temporary data pointer */
+
+       if ((temp = malloc(datalen)) != NULL)
+       {
+         memcpy(temp, data, datalen);
+
+         value->unknown.data   = temp;
+         value->unknown.length = datalen;
+       }
+       else
+         return (0);
+      }
+    }
+  }
+
+  return (value != NULL);
+}
+
+
 /*
  * 'ippSetOperation()' - Set the operation ID in an IPP request message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -3460,19 +4119,19 @@ ippSetOperation(ipp_t    *ipp,          /* I - IPP request message */
 /*
  * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
  *
- * The @code ipp@ parameter refers to the IPP message containing the attribute that was
- * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
  * The @code element@ parameter specifies which value to set from 0 to
  * @link ippGetCount(attr)@.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
-ippSetRange(ipp_t           *ipp,      /* IO - IPP message */
+ippSetRange(ipp_t           *ipp,      /* I  - IPP message */
             ipp_attribute_t **attr,    /* IO - IPP attribute */
             int             element,   /* I  - Value number (0-based) */
            int             lowervalue, /* I  - Lower bound for range */
@@ -3506,12 +4165,12 @@ ippSetRange(ipp_t           *ipp,       /* IO - IPP message */
 /*
  * 'ippSetRequestId()' - Set the request ID in an IPP message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code request_id@ parameter must be greater than 0.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -3540,20 +4199,20 @@ ippSetRequestId(ipp_t *ipp,             /* I - IPP message */
 /*
  * 'ippSetResolution()' - Set a resolution value in an attribute.
  *
- * The @code ipp@ parameter refers to the IPP message containing the attribute that was
- * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
  * The @code element@ parameter specifies which value to set from 0 to
  * @link ippGetCount(attr)@.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
 ippSetResolution(
-    ipp_t           *ipp,              /* IO - IPP message */
+    ipp_t           *ipp,              /* I  - IPP message */
     ipp_attribute_t **attr,            /* IO - IPP attribute */
     int             element,           /* I  - Value number (0-based) */
     ipp_res_t       unitsvalue,                /* I  - Resolution units */
@@ -3590,7 +4249,7 @@ ippSetResolution(
 /*
  * 'ippSetState()' - Set the current state of the IPP message.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -3618,10 +4277,10 @@ ippSetState(ipp_t       *ipp,           /* I - IPP message */
 /*
  * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
  *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -3648,19 +4307,19 @@ ippSetStatusCode(ipp_t        *ipp,     /* I - IPP response or event message */
 /*
  * 'ippSetString()' - Set a string value in an attribute.
  *
- * The @code ipp@ parameter refers to the IPP message containing the attribute that was
- * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
  * The @code element@ parameter specifies which value to set from 0 to
  * @link ippGetCount(attr)@.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.6/OS X 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
-ippSetString(ipp_t           *ipp,     /* IO - IPP message */
+ippSetString(ipp_t           *ipp,     /* I  - IPP message */
              ipp_attribute_t **attr,   /* IO - IPP attribute */
              int             element,  /* I  - Value number (0-based) */
             const char      *strvalue) /* I  - String value */
@@ -3673,7 +4332,11 @@ ippSetString(ipp_t           *ipp,       /* IO - IPP message */
   * Range check input...
   */
 
-  if (!ipp || !attr || !*attr || (*attr)->value_tag != IPP_TAG_INTEGER ||
+  if (!ipp || !attr || !*attr ||
+      ((*attr)->value_tag != IPP_TAG_TEXTLANG &&
+      (*attr)->value_tag != IPP_TAG_NAMELANG &&
+       ((*attr)->value_tag < IPP_TAG_TEXT ||
+        (*attr)->value_tag > IPP_TAG_MIMETYPE)) ||
       element < 0 || element > (*attr)->num_values || !strvalue)
     return (0);
 
@@ -3686,7 +4349,7 @@ ippSetString(ipp_t           *ipp,        /* IO - IPP message */
     if (element > 0)
       value->string.language = (*attr)->values[0].string.language;
 
-    if ((int)((*attr)->value_tag) & IPP_TAG_COPY)
+    if ((int)((*attr)->value_tag) & IPP_TAG_CUPS_CONST)
       value->string.text = (char *)strvalue;
     else if ((temp = _cupsStrAlloc(strvalue)) != NULL)
     {
@@ -3704,168 +4367,1075 @@ ippSetString(ipp_t           *ipp,   /* IO - IPP message */
 
 
 /*
- * 'ippSetValueTag()' - Set the value tag of an attribute.
+ * 'ippSetStringf()' - Set a formatted string value of an attribute.
  *
- * The @code ipp@ parameter refers to the IPP message containing the attribute that was
- * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
- * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
- * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
- * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
- * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
- * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
- * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
- * will be rejected.
+ * The @code element@ parameter specifies which value to set from 0 to
+ * @link ippGetCount(attr)@.
  *
- * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
- * code in the "attributes-natural-language" attribute or, if not present, the language
- * code for the current locale.
+ * The @code format@ parameter uses formatting characters compatible with the
+ * printf family of standard functions.  Additional arguments follow it as
+ * needed.  The formatted string is truncated as needed to the maximum length of
+ * the corresponding value type.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.7@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
-ippSetValueTag(
-    ipp_t          *ipp,               /* IO - IPP message */
-    ipp_attribute_t **attr,            /* IO - IPP attribute */
-    ipp_tag_t       value_tag)         /* I  - Value tag */
+ippSetStringf(ipp_t           *ipp,    /* I  - IPP message */
+              ipp_attribute_t **attr,  /* IO - IPP attribute */
+              int             element, /* I  - Value number (0-based) */
+             const char      *format,  /* I  - Printf-style format string */
+             ...)                      /* I  - Additional arguments as needed */
 {
-  int          i;                      /* Looping var */
-  _ipp_value_t *value;                 /* Current value */
-  int          integer;                /* Current integer value */
-  cups_lang_t  *language;              /* Current language */
-  char         code[32];               /* Language code */
-  ipp_tag_t    temp_tag;               /* Temporary value tag */
+  int          ret;                    /* Return value */
+  va_list      ap;                     /* Pointer to additional arguments */
+
+
+  va_start(ap, format);
+  ret = ippSetStringfv(ipp, attr, element, format, ap);
+  va_end(ap);
+
+  return (ret);
+}
+
+
+/*
+ * 'ippSetStringf()' - Set a formatted string value of an attribute.
+ *
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
+ *
+ * The @code attr@ parameter may be modified as a result of setting the value.
+ *
+ * The @code element@ parameter specifies which value to set from 0 to
+ * @link ippGetCount(attr)@.
+ *
+ * The @code format@ parameter uses formatting characters compatible with the
+ * printf family of standard functions.  Additional arguments follow it as
+ * needed.  The formatted string is truncated as needed to the maximum length of
+ * the corresponding value type.
+ *
+ * @since CUPS 1.7@
+ */
+
+int                                    /* O  - 1 on success, 0 on failure */
+ippSetStringfv(ipp_t           *ipp,   /* I  - IPP message */
+               ipp_attribute_t **attr, /* IO - IPP attribute */
+               int             element,        /* I  - Value number (0-based) */
+              const char      *format, /* I  - Printf-style format string */
+              va_list         ap)      /* I  - Pointer to additional arguments */
+{
+  ipp_tag_t    value_tag;              /* Value tag */
+  char         buffer[IPP_MAX_TEXT + 4];
+                                       /* Formatted text string */
+  ssize_t      bytes,                  /* Length of formatted value */
+               max_bytes;              /* Maximum number of bytes for value */
 
 
  /*
   * Range check input...
   */
 
-  if (!ipp || !attr)
+  if (attr && *attr)
+    value_tag = (*attr)->value_tag & IPP_TAG_CUPS_MASK;
+  else
+    value_tag = IPP_TAG_ZERO;
+
+  if (!ipp || !attr || !*attr ||
+      (value_tag < IPP_TAG_TEXT && value_tag != IPP_TAG_TEXTLANG &&
+       value_tag != IPP_TAG_NAMELANG) || value_tag > IPP_TAG_MIMETYPE ||
+      !format || !ap)
     return (0);
 
  /*
-  * If there is no change, return immediately...
+  * Format the string...
   */
 
-  if (value_tag == (*attr)->value_tag)
-    return (1);
+  if (!strcmp(format, "%s"))
+  {
+   /*
+    * Optimize the simple case...
+    */
+
+    const char *s = va_arg(ap, char *);
+
+    if (!s)
+      s = "(null)";
+
+    bytes = strlen(s);
+    strlcpy(buffer, s, sizeof(buffer));
+  }
+  else
+  {
+   /*
+    * Do a full formatting of the message...
+    */
+
+    if ((bytes = vsnprintf(buffer, sizeof(buffer), format, ap)) < 0)
+      return (0);
+  }
 
  /*
-  * Otherwise implement changes as needed...
+  * Limit the length of the string...
   */
 
-  temp_tag = (ipp_tag_t)((int)((*attr)->value_tag) & IPP_TAG_MASK);
-
   switch (value_tag)
   {
-    case IPP_TAG_UNSUPPORTED_VALUE :
-    case IPP_TAG_DEFAULT :
-    case IPP_TAG_UNKNOWN :
-    case IPP_TAG_NOVALUE :
-    case IPP_TAG_NOTSETTABLE :
-    case IPP_TAG_DELETEATTR :
-    case IPP_TAG_ADMINDEFINE :
-       /*
-        * Free any existing values...
-        */
+    default :
+    case IPP_TAG_TEXT :
+    case IPP_TAG_TEXTLANG :
+        max_bytes = IPP_MAX_TEXT;
+        break;
+
+    case IPP_TAG_NAME :
+    case IPP_TAG_NAMELANG :
+        max_bytes = IPP_MAX_NAME;
+        break;
+
+    case IPP_TAG_CHARSET :
+        max_bytes = IPP_MAX_CHARSET;
+        break;
+
+    case IPP_TAG_KEYWORD :
+        max_bytes = IPP_MAX_KEYWORD;
+        break;
+
+    case IPP_TAG_LANGUAGE :
+        max_bytes = IPP_MAX_LANGUAGE;
+        break;
+
+    case IPP_TAG_MIMETYPE :
+        max_bytes = IPP_MAX_MIMETYPE;
+        break;
+
+    case IPP_TAG_URI :
+        max_bytes = IPP_MAX_URI;
+        break;
+
+    case IPP_TAG_URISCHEME :
+        max_bytes = IPP_MAX_URISCHEME;
+        break;
+  }
+
+  if (bytes >= max_bytes)
+  {
+    char       *bufmax,                /* Buffer at max_bytes */
+               *bufptr;                /* Pointer into buffer */
+
+    bufptr = buffer + strlen(buffer) - 1;
+    bufmax = buffer + max_bytes - 1;
+
+    while (bufptr > bufmax)
+    {
+      if (*bufptr & 0x80)
+      {
+        while ((*bufptr & 0xc0) == 0x80 && bufptr > buffer)
+          bufptr --;
+      }
+
+      bufptr --;
+    }
+
+    *bufptr = '\0';
+  }
+
+ /*
+  * Set the formatted string and return...
+  */
+
+  return (ippSetString(ipp, attr, element, buffer));
+}
+
+
+/*
+ * 'ippSetValueTag()' - Set the value tag of an attribute.
+ *
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
+ *
+ * The @code attr@ parameter may be modified as a result of setting the value.
+ *
+ * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
+ * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
+ * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
+ * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
+ * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
+ * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
+ * will be rejected.
+ *
+ * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
+ * code in the "attributes-natural-language" attribute or, if not present, the language
+ * code for the current locale.
+ *
+ * @since CUPS 1.6/OS X 10.8@
+ */
+
+int                                    /* O  - 1 on success, 0 on failure */
+ippSetValueTag(
+    ipp_t          *ipp,               /* I  - IPP message */
+    ipp_attribute_t **attr,            /* IO - IPP attribute */
+    ipp_tag_t       value_tag)         /* I  - Value tag */
+{
+  int          i;                      /* Looping var */
+  _ipp_value_t *value;                 /* Current value */
+  int          integer;                /* Current integer value */
+  cups_lang_t  *language;              /* Current language */
+  char         code[32];               /* Language code */
+  ipp_tag_t    temp_tag;               /* Temporary value tag */
+
+
+ /*
+  * Range check input...
+  */
+
+  if (!ipp || !attr || !*attr)
+    return (0);
+
+ /*
+  * If there is no change, return immediately...
+  */
+
+  if (value_tag == (*attr)->value_tag)
+    return (1);
+
+ /*
+  * Otherwise implement changes as needed...
+  */
+
+  temp_tag = (ipp_tag_t)((int)((*attr)->value_tag) & IPP_TAG_CUPS_MASK);
+
+  switch (value_tag)
+  {
+    case IPP_TAG_UNSUPPORTED_VALUE :
+    case IPP_TAG_DEFAULT :
+    case IPP_TAG_UNKNOWN :
+    case IPP_TAG_NOVALUE :
+    case IPP_TAG_NOTSETTABLE :
+    case IPP_TAG_DELETEATTR :
+    case IPP_TAG_ADMINDEFINE :
+       /*
+        * Free any existing values...
+        */
+
+        if ((*attr)->num_values > 0)
+          ipp_free_values(*attr, 0, (*attr)->num_values);
+
+       /*
+        * Set out-of-band value...
+        */
+
+        (*attr)->value_tag = value_tag;
+        break;
+
+    case IPP_TAG_RANGE :
+        if (temp_tag != IPP_TAG_INTEGER)
+          return (0);
+
+        for (i = (*attr)->num_values, value = (*attr)->values;
+             i > 0;
+             i --, value ++)
+        {
+          integer            = value->integer;
+          value->range.lower = value->range.upper = integer;
+        }
+
+        (*attr)->value_tag = IPP_TAG_RANGE;
+        break;
+
+    case IPP_TAG_NAME :
+        if (temp_tag != IPP_TAG_KEYWORD && temp_tag != IPP_TAG_URI &&
+            temp_tag != IPP_TAG_URISCHEME && temp_tag != IPP_TAG_LANGUAGE &&
+            temp_tag != IPP_TAG_MIMETYPE)
+          return (0);
+
+        (*attr)->value_tag = (ipp_tag_t)(IPP_TAG_NAME | ((*attr)->value_tag & IPP_TAG_CUPS_CONST));
+        break;
+
+    case IPP_TAG_NAMELANG :
+    case IPP_TAG_TEXTLANG :
+        if (value_tag == IPP_TAG_NAMELANG &&
+            (temp_tag != IPP_TAG_NAME && temp_tag != IPP_TAG_KEYWORD &&
+             temp_tag != IPP_TAG_URI && temp_tag != IPP_TAG_URISCHEME &&
+             temp_tag != IPP_TAG_LANGUAGE && temp_tag != IPP_TAG_MIMETYPE))
+          return (0);
+
+        if (value_tag == IPP_TAG_TEXTLANG && temp_tag != IPP_TAG_TEXT)
+          return (0);
+
+        if (ipp->attrs && ipp->attrs->next && ipp->attrs->next->name &&
+            !strcmp(ipp->attrs->next->name, "attributes-natural-language"))
+        {
+         /*
+          * Use the language code from the IPP message...
+          */
+
+         (*attr)->values[0].string.language =
+             _cupsStrAlloc(ipp->attrs->next->values[0].string.text);
+        }
+        else
+        {
+         /*
+          * Otherwise, use the language code corresponding to the locale...
+          */
+
+         language = cupsLangDefault();
+         (*attr)->values[0].string.language = _cupsStrAlloc(ipp_lang_code(language->language,
+                                                                       code,
+                                                                       sizeof(code)));
+        }
+
+        for (i = (*attr)->num_values - 1, value = (*attr)->values + 1;
+             i > 0;
+             i --, value ++)
+          value->string.language = (*attr)->values[0].string.language;
+
+        if ((int)(*attr)->value_tag & IPP_TAG_CUPS_CONST)
+        {
+         /*
+          * Make copies of all values...
+          */
+
+         for (i = (*attr)->num_values, value = (*attr)->values;
+              i > 0;
+              i --, value ++)
+           value->string.text = _cupsStrAlloc(value->string.text);
+        }
+
+        (*attr)->value_tag = IPP_TAG_NAMELANG;
+        break;
+
+    case IPP_TAG_KEYWORD :
+        if (temp_tag == IPP_TAG_NAME || temp_tag == IPP_TAG_NAMELANG)
+          break;                       /* Silently "allow" name -> keyword */
+
+    default :
+        return (0);
+  }
+
+  return (1);
+}
+
+
+/*
+ * 'ippSetVersion()' - Set the version number in an IPP message.
+ *
+ * The @code ipp@ parameter refers to an IPP message previously created using
+ * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
+ *
+ * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
+ *
+ * @since CUPS 1.6/OS X 10.8@
+ */
+
+int                                    /* O - 1 on success, 0 on failure */
+ippSetVersion(ipp_t *ipp,              /* I - IPP message */
+              int   major,             /* I - Major version number (major.minor) */
+              int   minor)             /* I - Minor version number (major.minor) */
+{
+ /*
+  * Range check input...
+  */
+
+  if (!ipp || major < 0 || minor < 0)
+    return (0);
+
+ /*
+  * Set the version number...
+  */
+
+  ipp->request.any.version[0] = major;
+  ipp->request.any.version[1] = minor;
+
+  return (1);
+}
+
+
+/*
+ * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
+ */
+
+const ipp_uchar_t *                    /* O - RFC-1903 date/time data */
+ippTimeToDate(time_t t)                        /* I - UNIX time value */
+{
+  struct tm    *unixdate;              /* UNIX unixdate/time info */
+  ipp_uchar_t  *date = _cupsGlobals()->ipp_date;
+                                       /* RFC-1903 date/time data */
+
+
+ /*
+  * RFC-1903 date/time format is:
+  *
+  *    Byte(s)  Description
+  *    -------  -----------
+  *    0-1      Year (0 to 65535)
+  *    2        Month (1 to 12)
+  *    3        Day (1 to 31)
+  *    4        Hours (0 to 23)
+  *    5        Minutes (0 to 59)
+  *    6        Seconds (0 to 60, 60 = "leap second")
+  *    7        Deciseconds (0 to 9)
+  *    8        +/- UTC
+  *    9        UTC hours (0 to 11)
+  *    10       UTC minutes (0 to 59)
+  */
+
+  unixdate = gmtime(&t);
+  unixdate->tm_year += 1900;
+
+  date[0]  = unixdate->tm_year >> 8;
+  date[1]  = unixdate->tm_year;
+  date[2]  = unixdate->tm_mon + 1;
+  date[3]  = unixdate->tm_mday;
+  date[4]  = unixdate->tm_hour;
+  date[5]  = unixdate->tm_min;
+  date[6]  = unixdate->tm_sec;
+  date[7]  = 0;
+  date[8]  = '+';
+  date[9]  = 0;
+  date[10] = 0;
+
+  return (date);
+}
+
+
+/*
+ * 'ippValidateAttribute()' - Validate the contents of an attribute.
+ *
+ * This function validates the contents of an attribute based on the name and
+ * value tag.  1 is returned if the attribute is valid, 0 otherwise.  On
+ * failure, cupsLastErrorString() is set to a human-readable message.
+ *
+ * @since CUPS 1.7@
+ */
+
+int                                    /* O - 1 if valid, 0 otherwise */
+ippValidateAttribute(
+    ipp_attribute_t *attr)             /* I - Attribute */
+{
+  int          i;                      /* Looping var */
+  char         scheme[64],             /* Scheme from URI */
+               userpass[256],          /* Username/password from URI */
+               hostname[256],          /* Hostname from URI */
+               resource[1024];         /* Resource from URI */
+  int          port,                   /* Port number from URI */
+               uri_status;             /* URI separation status */
+  const char   *ptr;                   /* Pointer into string */
+  ipp_attribute_t *colattr;            /* Collection attribute */
+  regex_t      re;                     /* Regular expression */
+  ipp_uchar_t  *date;                  /* Current date value */
+  static const char * const uri_status_strings[] =
+  {                                    /* URI status strings */
+    "URI too large",
+    "Bad arguments to function",
+    "Bad resource in URI",
+    "Bad port number in URI",
+    "Bad hostname/address in URI",
+    "Bad username in URI",
+    "Bad scheme in URI",
+    "Bad/empty URI",
+    "OK",
+    "Missing scheme in URI",
+    "Unknown scheme in URI",
+    "Missing resource in URI"
+  };
+
+
+ /*
+  * Skip separators.
+  */
+
+  if (!attr->name)
+    return (1);
+
+ /*
+  * Validate the attribute name.
+  */
+
+  for (ptr = attr->name; *ptr; ptr ++)
+    if (!isalnum(*ptr & 255) && *ptr != '-' && *ptr != '.' && *ptr != '_')
+      break;
+
+  if (*ptr || ptr == attr->name)
+  {
+    ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                  _("\"%s\": Bad attribute name - invalid character "
+                   "(RFC 2911 section 4.1.3)."), attr->name);
+    return (0);
+  }
+
+  if ((ptr - attr->name) > 255)
+  {
+    ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                  _("\"%s\": Bad attribute name - bad length %d "
+                   "(RFC 2911 section 4.1.3)."), attr->name,
+                 (int)(ptr - attr->name));
+    return (0);
+  }
+
+  switch (attr->value_tag)
+  {
+    case IPP_TAG_INTEGER :
+        break;
+
+    case IPP_TAG_BOOLEAN :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         if (attr->values[i].boolean != 0 &&
+             attr->values[i].boolean != 1)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                          _("\"%s\": Bad boolen value %d "
+                           "(RFC 2911 section 4.1.11)."), attr->name,
+                         attr->values[i].boolean);
+           return (0);
+         }
+       }
+        break;
+
+    case IPP_TAG_ENUM :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         if (attr->values[i].integer < 1)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad enum value %d - out of range "
+                           "(RFC 2911 section 4.1.4)."), attr->name,
+                           attr->values[i].integer);
+            return (0);
+         }
+       }
+        break;
+
+    case IPP_TAG_STRING :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         if (attr->values[i].unknown.length > IPP_MAX_OCTETSTRING)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad octetString value - bad length %d "
+                           "(RFC 2911 section 4.1.10)."), attr->name,
+                           attr->values[i].unknown.length);
+           return (0);
+         }
+       }
+        break;
+
+    case IPP_TAG_DATE :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         date = attr->values[i].date;
+
+          if (date[2] < 1 || date[2] > 12)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad dateTime month %u "
+                           "(RFC 2911 section 4.1.14)."), attr->name, date[2]);
+           return (0);
+         }
+
+          if (date[3] < 1 || date[3] > 31)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad dateTime day %u "
+                           "(RFC 2911 section 4.1.14)."), attr->name, date[3]);
+           return (0);
+         }
+
+          if (date[4] > 23)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad dateTime hours %u "
+                           "(RFC 2911 section 4.1.14)."), attr->name, date[4]);
+           return (0);
+         }
+
+          if (date[5] > 59)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad dateTime minutes %u "
+                           "(RFC 2911 section 4.1.14)."), attr->name, date[5]);
+           return (0);
+         }
+
+          if (date[6] > 60)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad dateTime seconds %u "
+                           "(RFC 2911 section 4.1.14)."), attr->name, date[6]);
+           return (0);
+         }
+
+          if (date[7] > 9)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad dateTime deciseconds %u "
+                           "(RFC 2911 section 4.1.14)."), attr->name, date[7]);
+           return (0);
+         }
+
+          if (date[8] != '-' && date[8] != '+')
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad dateTime UTC sign '%c' "
+                           "(RFC 2911 section 4.1.14)."), attr->name, date[8]);
+           return (0);
+         }
+
+          if (date[9] > 11)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad dateTime UTC hours %u "
+                           "(RFC 2911 section 4.1.14)."), attr->name, date[9]);
+           return (0);
+         }
+
+          if (date[10] > 59)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad dateTime UTC minutes %u "
+                           "(RFC 2911 section 4.1.14)."), attr->name, date[10]);
+           return (0);
+         }
+       }
+        break;
+
+    case IPP_TAG_RESOLUTION :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         if (attr->values[i].resolution.xres <= 0)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad resolution value %dx%d%s - cross "
+                           "feed resolution must be positive "
+                           "(RFC 2911 section 4.1.15)."), attr->name,
+                         attr->values[i].resolution.xres,
+                         attr->values[i].resolution.yres,
+                         attr->values[i].resolution.units ==
+                             IPP_RES_PER_INCH ? "dpi" :
+                             attr->values[i].resolution.units ==
+                                 IPP_RES_PER_CM ? "dpcm" : "unknown");
+           return (0);
+         }
+
+         if (attr->values[i].resolution.yres <= 0)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad resolution value %dx%d%s - feed "
+                           "resolution must be positive "
+                           "(RFC 2911 section 4.1.15)."), attr->name,
+                         attr->values[i].resolution.xres,
+                         attr->values[i].resolution.yres,
+                         attr->values[i].resolution.units ==
+                             IPP_RES_PER_INCH ? "dpi" :
+                             attr->values[i].resolution.units ==
+                                 IPP_RES_PER_CM ? "dpcm" : "unknown");
+            return (0);
+         }
+
+         if (attr->values[i].resolution.units != IPP_RES_PER_INCH &&
+             attr->values[i].resolution.units != IPP_RES_PER_CM)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad resolution value %dx%d%s - bad "
+                           "units value (RFC 2911 section 4.1.15)."),
+                         attr->name, attr->values[i].resolution.xres,
+                         attr->values[i].resolution.yres,
+                         attr->values[i].resolution.units ==
+                             IPP_RES_PER_INCH ? "dpi" :
+                             attr->values[i].resolution.units ==
+                                 IPP_RES_PER_CM ? "dpcm" : "unknown");
+           return (0);
+         }
+       }
+        break;
+
+    case IPP_TAG_RANGE :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         if (attr->values[i].range.lower > attr->values[i].range.upper)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad rangeOfInteger value %d-%d - lower "
+                           "greater than upper (RFC 2911 section 4.1.13)."),
+                         attr->name, attr->values[i].range.lower,
+                         attr->values[i].range.upper);
+           return (0);
+         }
+       }
+        break;
+
+    case IPP_TAG_BEGIN_COLLECTION :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         for (colattr = attr->values[i].collection->attrs;
+              colattr;
+              colattr = colattr->next)
+         {
+           if (!ippValidateAttribute(colattr))
+             return (0);
+         }
+       }
+        break;
+
+    case IPP_TAG_TEXT :
+    case IPP_TAG_TEXTLANG :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         for (ptr = attr->values[i].string.text; *ptr; ptr ++)
+         {
+           if ((*ptr & 0xe0) == 0xc0)
+           {
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+           }
+           else if ((*ptr & 0xf0) == 0xe0)
+           {
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+           }
+           else if ((*ptr & 0xf8) == 0xf0)
+           {
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+           }
+           else if (*ptr & 0x80)
+             break;
+         }
+
+         if (*ptr)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad text value \"%s\" - bad UTF-8 "
+                           "sequence (RFC 2911 section 4.1.1)."), attr->name,
+                         attr->values[i].string.text);
+           return (0);
+         }
+
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_TEXT - 1))
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad text value \"%s\" - bad length %d "
+                           "(RFC 2911 section 4.1.1)."), attr->name,
+                         attr->values[i].string.text,
+                         (int)(ptr - attr->values[i].string.text));
+           return (0);
+         }
+       }
+        break;
+
+    case IPP_TAG_NAME :
+    case IPP_TAG_NAMELANG :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         for (ptr = attr->values[i].string.text; *ptr; ptr ++)
+         {
+           if ((*ptr & 0xe0) == 0xc0)
+           {
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+           }
+           else if ((*ptr & 0xf0) == 0xe0)
+           {
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+           }
+           else if ((*ptr & 0xf8) == 0xf0)
+           {
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+             ptr ++;
+             if ((*ptr & 0xc0) != 0x80)
+               break;
+           }
+           else if (*ptr & 0x80)
+             break;
+         }
+
+         if (*ptr)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad name value \"%s\" - bad UTF-8 "
+                           "sequence (RFC 2911 section 4.1.2)."), attr->name,
+                         attr->values[i].string.text);
+           return (0);
+         }
+
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_NAME - 1))
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad name value \"%s\" - bad length %d "
+                           "(RFC 2911 section 4.1.2)."), attr->name,
+                         attr->values[i].string.text,
+                         (int)(ptr - attr->values[i].string.text));
+           return (0);
+         }
+       }
+        break;
+
+    case IPP_TAG_KEYWORD :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         for (ptr = attr->values[i].string.text; *ptr; ptr ++)
+           if (!isalnum(*ptr & 255) && *ptr != '-' && *ptr != '.' &&
+               *ptr != '_')
+             break;
 
-        if ((*attr)->num_values > 0)
-          ipp_free_values(*attr, 0, (*attr)->num_values);
+         if (*ptr || ptr == attr->values[i].string.text)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad keyword value \"%s\" - invalid "
+                           "character (RFC 2911 section 4.1.3)."),
+                         attr->name, attr->values[i].string.text);
+           return (0);
+         }
 
-       /*
-        * Set out-of-band value...
-        */
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_KEYWORD - 1))
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad keyword value \"%s\" - bad "
+                           "length %d (RFC 2911 section 4.1.3)."),
+                         attr->name, attr->values[i].string.text,
+                         (int)(ptr - attr->values[i].string.text));
+           return (0);
+         }
+       }
+        break;
 
-        (*attr)->value_tag = value_tag;
+    case IPP_TAG_URI :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         uri_status = httpSeparateURI(HTTP_URI_CODING_ALL,
+                                      attr->values[i].string.text,
+                                      scheme, sizeof(scheme),
+                                      userpass, sizeof(userpass),
+                                      hostname, sizeof(hostname),
+                                      &port, resource, sizeof(resource));
+
+         if (uri_status < HTTP_URI_STATUS_OK)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad URI value \"%s\" - %s "
+                           "(RFC 2911 section 4.1.5)."), attr->name,
+                         attr->values[i].string.text,
+                         uri_status_strings[uri_status -
+                                            HTTP_URI_STATUS_OVERFLOW]);
+           return (0);
+         }
+
+         if (strlen(attr->values[i].string.text) > (IPP_MAX_URI - 1))
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad URI value \"%s\" - bad length %d "
+                           "(RFC 2911 section 4.1.5)."), attr->name,
+                         attr->values[i].string.text,
+                         (int)strlen(attr->values[i].string.text));
+         }
+       }
         break;
 
-    case IPP_TAG_RANGE :
-        if (temp_tag != IPP_TAG_INTEGER)
-          return (0);
+    case IPP_TAG_URISCHEME :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         ptr = attr->values[i].string.text;
+         if (islower(*ptr & 255))
+         {
+           for (ptr ++; *ptr; ptr ++)
+             if (!islower(*ptr & 255) && !isdigit(*ptr & 255) &&
+                 *ptr != '+' && *ptr != '-' && *ptr != '.')
+                break;
+         }
 
-        for (i = (*attr)->num_values, value = (*attr)->values;
-             i > 0;
-             i --, value ++)
-        {
-          integer            = value->integer;
-          value->range.lower = value->range.upper = integer;
-        }
+         if (*ptr || ptr == attr->values[i].string.text)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad uriScheme value \"%s\" - bad "
+                           "characters (RFC 2911 section 4.1.6)."),
+                         attr->name, attr->values[i].string.text);
+           return (0);
+         }
 
-        (*attr)->value_tag = IPP_TAG_RANGE;
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_URISCHEME - 1))
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad uriScheme value \"%s\" - bad "
+                           "length %d (RFC 2911 section 4.1.6)."),
+                         attr->name, attr->values[i].string.text,
+                         (int)(ptr - attr->values[i].string.text));
+           return (0);
+         }
+       }
         break;
 
-    case IPP_TAG_NAME :
-        if (temp_tag != IPP_TAG_KEYWORD && temp_tag != IPP_TAG_URI &&
-            temp_tag != IPP_TAG_URISCHEME && temp_tag != IPP_TAG_LANGUAGE &&
-            temp_tag != IPP_TAG_MIMETYPE)
-          return (0);
+    case IPP_TAG_CHARSET :
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         for (ptr = attr->values[i].string.text; *ptr; ptr ++)
+           if (!isprint(*ptr & 255) || isupper(*ptr & 255) ||
+               isspace(*ptr & 255))
+             break;
 
-        (*attr)->value_tag = (ipp_tag_t)(IPP_TAG_NAME | ((*attr)->value_tag & IPP_TAG_COPY));
-        break;
+         if (*ptr || ptr == attr->values[i].string.text)
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad charset value \"%s\" - bad "
+                           "characters (RFC 2911 section 4.1.7)."),
+                         attr->name, attr->values[i].string.text);
+           return (0);
+         }
 
-    case IPP_TAG_NAMELANG :
-    case IPP_TAG_TEXTLANG :
-        if (value_tag == IPP_TAG_NAMELANG &&
-            (temp_tag != IPP_TAG_NAME && temp_tag != IPP_TAG_KEYWORD &&
-             temp_tag != IPP_TAG_URI && temp_tag != IPP_TAG_URISCHEME &&
-             temp_tag != IPP_TAG_LANGUAGE && temp_tag != IPP_TAG_MIMETYPE))
-          return (0);
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_CHARSET - 1))
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad charset value \"%s\" - bad "
+                           "length %d (RFC 2911 section 4.1.7)."),
+                         attr->name, attr->values[i].string.text,
+                         (int)(ptr - attr->values[i].string.text));
+           return (0);
+         }
+       }
+        break;
 
-        if (value_tag == IPP_TAG_TEXTLANG && temp_tag != IPP_TAG_TEXT)
-          return (0);
+    case IPP_TAG_LANGUAGE :
+       /*
+        * The following regular expression is derived from the ABNF for
+       * language tags in RFC 4646.  All I can say is that this is the
+       * easiest way to check the values...
+       */
 
-        if (ipp->attrs && ipp->attrs->next && ipp->attrs->next->name &&
-            !strcmp(ipp->attrs->next->name, "attributes-natural-language"))
+        if ((i = regcomp(&re,
+                        "^("
+                        "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
+                                                               /* language */
+                        "(-[a-z][a-z][a-z][a-z]){0,1}"         /* script */
+                        "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
+                        "(-([a-z]{5,8}|[0-9][0-9][0-9]))*"     /* variant */
+                        "(-[a-wy-z](-[a-z0-9]{2,8})+)*"        /* extension */
+                        "(-x(-[a-z0-9]{1,8})+)*"               /* privateuse */
+                        "|"
+                        "x(-[a-z0-9]{1,8})+"                   /* privateuse */
+                        "|"
+                        "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}"    /* grandfathered */
+                        ")$",
+                        REG_NOSUB | REG_EXTENDED)) != 0)
         {
-         /*
-          * Use the language code from the IPP message...
-          */
+          char temp[256];              /* Temporary error string */
 
-         (*attr)->values[0].string.language =
-             _cupsStrAlloc(ipp->attrs->next->values[0].string.text);
+          regerror(i, &re, temp, sizeof(temp));
+         ipp_set_error(IPP_STATUS_ERROR_INTERNAL,
+                       _("Unable to compile naturalLanguage regular "
+                         "expression: %s."), temp);
+         return (0);
         }
-        else
-        {
-         /*
-          * Otherwise, use the language code corresponding to the locale...
-          */
 
-         language = cupsLangDefault();
-         (*attr)->values[0].string.language = _cupsStrAlloc(ipp_lang_code(language->language,
-                                                                       code,
-                                                                       sizeof(code)));
-        }
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         if (regexec(&re, attr->values[i].string.text, 0, NULL, 0))
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
+                           "characters (RFC 2911 section 4.1.8)."),
+                         attr->name, attr->values[i].string.text);
+           regfree(&re);
+           return (0);
+         }
 
-        for (i = (*attr)->num_values - 1, value = (*attr)->values + 1;
-             i > 0;
-             i --, value ++)
-          value->string.language = (*attr)->values[0].string.language;
+         if (strlen(attr->values[i].string.text) > (IPP_MAX_LANGUAGE - 1))
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
+                           "length %d (RFC 2911 section 4.1.8)."),
+                         attr->name, attr->values[i].string.text,
+                         (int)strlen(attr->values[i].string.text));
+           regfree(&re);
+           return (0);
+         }
+       }
 
-        if ((int)(*attr)->value_tag & IPP_TAG_COPY)
+       regfree(&re);
+        break;
+
+    case IPP_TAG_MIMETYPE :
+       /*
+        * The following regular expression is derived from the ABNF for
+       * MIME media types in RFC 2045 and 4288.  All I can say is that this is
+       * the easiest way to check the values...
+       */
+
+        if ((i = regcomp(&re,
+                        "^"
+                        "[-a-zA-Z0-9!#$&.+^_]{1,127}"          /* type-name */
+                        "/"
+                        "[-a-zA-Z0-9!#$&.+^_]{1,127}"          /* subtype-name */
+                        "(;[-a-zA-Z0-9!#$&.+^_]{1,127}="       /* parameter= */
+                        "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
+                                                               /* value */
+                        "$",
+                        REG_NOSUB | REG_EXTENDED)) != 0)
         {
-         /*
-          * Make copies of all values...
-          */
+          char temp[256];              /* Temporary error string */
 
-         for (i = (*attr)->num_values, value = (*attr)->values;
-              i > 0;
-              i --, value ++)
-           value->string.text = _cupsStrAlloc(value->string.text);
+          regerror(i, &re, temp, sizeof(temp));
+         ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                       _("Unable to compile mimeMediaType regular "
+                         "expression: %s."), temp);
+         return (0);
         }
 
-        (*attr)->value_tag = IPP_TAG_NAMELANG;
-        break;
+        for (i = 0; i < attr->num_values; i ++)
+       {
+         if (regexec(&re, attr->values[i].string.text, 0, NULL, 0))
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
+                           "characters (RFC 2911 section 4.1.9)."),
+                         attr->name, attr->values[i].string.text);
+           regfree(&re);
+           return (0);
+         }
 
-    case IPP_TAG_KEYWORD :
-        if (temp_tag == IPP_TAG_NAME || temp_tag == IPP_TAG_NAMELANG)
-          break;                       /* Silently "allow" name -> keyword */
+         if (strlen(attr->values[i].string.text) > (IPP_MAX_MIMETYPE - 1))
+         {
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
+                         _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
+                           "length %d (RFC 2911 section 4.1.9)."),
+                         attr->name, attr->values[i].string.text,
+                         (int)strlen(attr->values[i].string.text));
+           regfree(&re);
+           return (0);
+         }
+       }
+
+       regfree(&re);
+        break;
 
     default :
-        return (0);
+        break;
   }
 
   return (1);
@@ -3873,87 +5443,32 @@ ippSetValueTag(
 
 
 /*
- * 'ippSetVersion()' - Set the version number in an IPP message.
- *
- * The @code ipp@ parameter refers to an IPP message previously created using the
- * @link ippNew@ or @link ippNewRequest@ functions.
+ * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
  *
- * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
+ * This function validates the contents of the IPP message, including each
+ * attribute.  Like @link ippValidateAttribute@, cupsLastErrorString() is set
+ * to a human-readable message on failure.
  *
- * @since CUPS 1.6@
+ * @since CUPS 1.7@
  */
 
-int                                    /* O - 1 on success, 0 on failure */
-ippSetVersion(ipp_t *ipp,              /* I - IPP message */
-              int   major,             /* I - Major version number (major.minor) */
-              int   minor)             /* I - Minor version number (major.minor) */
+int                                    /* O - 1 if valid, 0 otherwise */
+ippValidateAttributes(ipp_t *ipp)      /* I - IPP message */
 {
- /*
-  * Range check input...
-  */
+  ipp_attribute_t      *attr;          /* Current attribute */
 
-  if (!ipp || major < 0 || minor < 0)
-    return (0);
 
- /*
-  * Set the version number...
-  */
+  if (!ipp)
+    return (1);
 
-  ipp->request.any.version[0] = major;
-  ipp->request.any.version[1] = minor;
+  for (attr = ipp->attrs; attr; attr = attr->next)
+    if (!ippValidateAttribute(attr))
+      return (0);
 
   return (1);
 }
 
 
-/*
- * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
- */
-
-const ipp_uchar_t *                    /* O - RFC-1903 date/time data */
-ippTimeToDate(time_t t)                        /* I - UNIX time value */
-{
-  struct tm    *unixdate;              /* UNIX unixdate/time info */
-  ipp_uchar_t  *date = _cupsGlobals()->ipp_date;
-                                       /* RFC-1903 date/time data */
-
-
- /*
-  * RFC-1903 date/time format is:
-  *
-  *    Byte(s)  Description
-  *    -------  -----------
-  *    0-1      Year (0 to 65535)
-  *    2        Month (1 to 12)
-  *    3        Day (1 to 31)
-  *    4        Hours (0 to 23)
-  *    5        Minutes (0 to 59)
-  *    6        Seconds (0 to 60, 60 = "leap second")
-  *    7        Deciseconds (0 to 9)
-  *    8        +/- UTC
-  *    9        UTC hours (0 to 11)
-  *    10       UTC minutes (0 to 59)
-  */
-
-  unixdate = gmtime(&t);
-  unixdate->tm_year += 1900;
-
-  date[0]  = unixdate->tm_year >> 8;
-  date[1]  = unixdate->tm_year;
-  date[2]  = unixdate->tm_mon + 1;
-  date[3]  = unixdate->tm_mday;
-  date[4]  = unixdate->tm_hour;
-  date[5]  = unixdate->tm_min;
-  date[6]  = unixdate->tm_sec;
-  date[7]  = 0;
-  date[8]  = '+';
-  date[9]  = 0;
-  date[10] = 0;
-
-  return (date);
-}
-
-
 /*
  * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
  */
@@ -3965,7 +5480,7 @@ ippWrite(http_t *http,                    /* I - HTTP connection */
   DEBUG_printf(("ippWrite(http=%p, ipp=%p)", http, ipp));
 
   if (!http)
-    return (IPP_ERROR);
+    return (IPP_STATE_ERROR);
 
   return (ippWriteIO(http, (ipp_iocb_t)httpWrite2, http->blocking, NULL, ipp));
 }
@@ -3974,7 +5489,7 @@ ippWrite(http_t *http,                    /* I - HTTP connection */
 /*
  * 'ippWriteFile()' - Write data for an IPP message to a file.
  *
- * @since CUPS 1.1.19/Mac OS X 10.3@
+ * @since CUPS 1.1.19/OS X 10.3@
  */
 
 ipp_state_t                            /* O - Current state */
@@ -3983,7 +5498,7 @@ ippWriteFile(int   fd,                    /* I - HTTP data */
 {
   DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd, ipp));
 
-  ipp->state = IPP_IDLE;
+  ipp->state = IPP_STATE_IDLE;
 
   return (ippWriteIO(&fd, (ipp_iocb_t)ipp_write_file, 1, NULL, ipp));
 }
@@ -3992,7 +5507,7 @@ ippWriteFile(int   fd,                    /* I - HTTP data */
 /*
  * 'ippWriteIO()' - Write data for an IPP message.
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 ipp_state_t                            /* O - Current state */
@@ -4014,20 +5529,20 @@ ippWriteIO(void       *dst,             /* I - Destination */
                 dst, cb, blocking, parent, ipp));
 
   if (!dst || !ipp)
-    return (IPP_ERROR);
+    return (IPP_STATE_ERROR);
 
   if ((buffer = (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE)) == NULL)
   {
     DEBUG_puts("1ippWriteIO: Unable to get write buffer");
-    return (IPP_ERROR);
+    return (IPP_STATE_ERROR);
   }
 
   switch (ipp->state)
   {
-    case IPP_IDLE :
+    case IPP_STATE_IDLE :
         ipp->state ++; /* Avoid common problem... */
 
-    case IPP_HEADER :
+    case IPP_STATE_HEADER :
         if (parent == NULL)
        {
         /*
@@ -4060,7 +5575,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
          {
            DEBUG_puts("1ippWriteIO: Could not write IPP header...");
            _cupsBufferRelease((char *)buffer);
-           return (IPP_ERROR);
+           return (IPP_STATE_ERROR);
          }
        }
 
@@ -4069,7 +5584,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
        * in the request/response, with no current group.
        */
 
-        ipp->state   = IPP_ATTRIBUTE;
+        ipp->state   = IPP_STATE_ATTRIBUTE;
        ipp->current = ipp->attrs;
        ipp->curtag  = IPP_TAG_ZERO;
 
@@ -4082,7 +5597,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
         if (!blocking)
          break;
 
-    case IPP_ATTRIBUTE :
+    case IPP_STATE_ATTRIBUTE :
         while (ipp->current != NULL)
        {
         /*
@@ -4139,7 +5654,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
            {
              DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n));
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
 
            /*
@@ -4178,7 +5693,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
            {
              DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n));
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
 
            /*
@@ -4221,7 +5736,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
          * Now write the attribute value(s)...
          */
 
-         switch (attr->value_tag & ~IPP_TAG_COPY)
+         switch (attr->value_tag & ~IPP_TAG_CUPS_CONST)
          {
            case IPP_TAG_UNSUPPORTED_VALUE :
            case IPP_TAG_DEFAULT :
@@ -4247,7 +5762,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -4293,7 +5808,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -4354,7 +5869,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                        DEBUG_puts("1ippWriteIO: Could not write IPP "
                                   "attribute...");
                        _cupsBufferRelease((char *)buffer);
-                       return (IPP_ERROR);
+                       return (IPP_STATE_ERROR);
                      }
 
                      bufptr = buffer;
@@ -4374,7 +5889,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                  {
                    DEBUG_printf(("1ippWriteIO: String too long (%d)", n));
                    _cupsBufferRelease((char *)buffer);
-                   return (IPP_ERROR);
+                   return (IPP_STATE_ERROR);
                  }
 
                   DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n,
@@ -4387,7 +5902,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -4426,7 +5941,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -4471,7 +5986,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -4524,7 +6039,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -4583,7 +6098,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                        DEBUG_puts("1ippWriteIO: Could not write IPP "
                                   "attribute...");
                        _cupsBufferRelease((char *)buffer);
-                       return (IPP_ERROR);
+                       return (IPP_STATE_ERROR);
                      }
 
                      bufptr = buffer;
@@ -4617,7 +6132,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
                                  "too long (%d)", n));
                    _cupsBufferRelease((char *)buffer);
-                   return (IPP_ERROR);
+                   return (IPP_STATE_ERROR);
                   }
 
                   if ((int)(IPP_BUF_SIZE - (bufptr - buffer)) < (n + 2))
@@ -4627,7 +6142,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -4690,7 +6205,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -4720,7 +6235,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    DEBUG_puts("1ippWriteIO: Could not write IPP "
                               "attribute...");
                    _cupsBufferRelease((char *)buffer);
-                   return (IPP_ERROR);
+                   return (IPP_STATE_ERROR);
                  }
 
                  bufptr = buffer;
@@ -4729,14 +6244,14 @@ ippWriteIO(void       *dst,             /* I - Destination */
                  * Then write the collection attribute...
                  */
 
-                  value->collection->state = IPP_IDLE;
+                  value->collection->state = IPP_STATE_IDLE;
 
                  if (ippWriteIO(dst, cb, 1, ipp,
-                                value->collection) == IPP_ERROR)
+                                value->collection) == IPP_STATE_ERROR)
                  {
                    DEBUG_puts("1ippWriteIO: Unable to write collection value");
                    _cupsBufferRelease((char *)buffer);
-                   return (IPP_ERROR);
+                   return (IPP_STATE_ERROR);
                  }
                }
                break;
@@ -4760,7 +6275,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                        DEBUG_puts("1ippWriteIO: Could not write IPP "
                                   "attribute...");
                        _cupsBufferRelease((char *)buffer);
-                       return (IPP_ERROR);
+                       return (IPP_STATE_ERROR);
                      }
 
                      bufptr = buffer;
@@ -4785,7 +6300,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
                                  n));
                    _cupsBufferRelease((char *)buffer);
-                   return (IPP_ERROR);
+                   return (IPP_STATE_ERROR);
                  }
 
                   if ((int)(IPP_BUF_SIZE - (bufptr - buffer)) < (n + 2))
@@ -4795,7 +6310,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -4825,7 +6340,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
            {
              DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
 
            DEBUG_printf(("2ippWriteIO: wrote %d bytes",
@@ -4866,14 +6381,14 @@ ippWriteIO(void       *dst,             /* I - Destination */
          {
            DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
            _cupsBufferRelease((char *)buffer);
-           return (IPP_ERROR);
+           return (IPP_STATE_ERROR);
          }
 
-         ipp->state = IPP_DATA;
+         ipp->state = IPP_STATE_DATA;
        }
         break;
 
-    case IPP_DATA :
+    case IPP_STATE_DATA :
         break;
 
     default :
@@ -4968,9 +6483,10 @@ ipp_free_values(ipp_attribute_t *attr,   /* I - Attribute to free values from */
   _ipp_value_t *value;                 /* Current value */
 
 
-  DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", attr, element, count));
+  DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", attr,
+                element, count));
 
-  if (!(attr->value_tag & IPP_TAG_COPY))
+  if (!(attr->value_tag & IPP_TAG_CUPS_CONST))
   {
    /*
     * Free values as needed...
@@ -4980,8 +6496,13 @@ ipp_free_values(ipp_attribute_t *attr,   /* I - Attribute to free values from */
     {
       case IPP_TAG_TEXTLANG :
       case IPP_TAG_NAMELANG :
-         if (element == 0 && count == attr->num_values && attr->values[0].string.language)
+         if (element == 0 && count == attr->num_values &&
+             attr->values[0].string.language)
+         {
            _cupsStrFree(attr->values[0].string.language);
+           attr->values[0].string.language = NULL;
+         }
+         /* Fall through to other string values */
 
       case IPP_TAG_TEXT :
       case IPP_TAG_NAME :
@@ -4995,7 +6516,10 @@ ipp_free_values(ipp_attribute_t *attr,   /* I - Attribute to free values from */
          for (i = count, value = attr->values + element;
               i > 0;
               i --, value ++)
+         {
            _cupsStrFree(value->string.text);
+           value->string.text = NULL;
+         }
          break;
 
       case IPP_TAG_DEFAULT :
@@ -5016,7 +6540,10 @@ ipp_free_values(ipp_attribute_t *attr,   /* I - Attribute to free values from */
          for (i = count, value = attr->values + element;
               i > 0;
               i --, value ++)
+         {
            ippDelete(value->collection);
+           value->collection = NULL;
+         }
          break;
 
       case IPP_TAG_STRING :
@@ -5024,8 +6551,13 @@ ipp_free_values(ipp_attribute_t *attr,   /* I - Attribute to free values from */
          for (i = count, value = attr->values + element;
               i > 0;
               i --, value ++)
+         {
            if (value->unknown.data)
+           {
              free(value->unknown.data);
+             value->unknown.data = NULL;
+           }
+         }
          break;
     }
   }
@@ -5169,7 +6701,7 @@ ipp_length(ipp_t *ipp,                    /* I - IPP message or collection */
     if (collection)
       bytes += 5;                      /* Add membername overhead */
 
-    switch (attr->value_tag & ~IPP_TAG_COPY)
+    switch (attr->value_tag & ~IPP_TAG_CUPS_CONST)
     {
       case IPP_TAG_UNSUPPORTED_VALUE :
       case IPP_TAG_DEFAULT :
@@ -5273,9 +6805,8 @@ ipp_read_http(http_t      *http,  /* I - Client connection */
               ipp_uchar_t *buffer,     /* O - Buffer for data */
              size_t      length)       /* I - Total length */
 {
-  int          tbytes,                 /* Total bytes read */
-               bytes;                  /* Bytes read this pass */
-  char         len[32];                /* Length string */
+  int  tbytes,                         /* Total bytes read */
+       bytes;                          /* Bytes read this pass */
 
 
   DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)",
@@ -5292,94 +6823,39 @@ ipp_read_http(http_t      *http,        /* I - Client connection */
     DEBUG_printf(("9ipp_read_http: tbytes=%d, http->state=%d", tbytes,
                   http->state));
 
-    if (http->state == HTTP_WAITING)
+    if (http->state == HTTP_STATE_WAITING)
       break;
 
-    if (http->used > 0 && http->data_encoding == HTTP_ENCODE_LENGTH)
-    {
-     /*
-      * Do "fast read" from HTTP buffer directly...
-      */
-
-      if (http->used > (int)(length - tbytes))
-        bytes = (int)(length - tbytes);
-      else
-        bytes = http->used;
-
-      if (bytes == 1)
-       buffer[0] = http->buffer[0];
-      else
-       memcpy(buffer, http->buffer, bytes);
-
-      http->used           -= bytes;
-      http->data_remaining -= bytes;
-
-      if (http->data_remaining <= INT_MAX)
-       http->_data_remaining = (int)http->data_remaining;
-      else
-       http->_data_remaining = INT_MAX;
-
-      if (http->used > 0)
-       memmove(http->buffer, http->buffer + bytes, http->used);
-
-      if (http->data_remaining == 0)
-      {
-       if (http->data_encoding == HTTP_ENCODE_CHUNKED)
-       {
-        /*
-         * Get the trailing CR LF after the chunk...
-         */
-
-         if (!httpGets(len, sizeof(len), http))
-           return (-1);
-       }
-
-       if (http->data_encoding != HTTP_ENCODE_CHUNKED)
-       {
-         if (http->state == HTTP_POST_RECV)
-           http->state ++;
-         else
-           http->state = HTTP_WAITING;
-       }
-      }
-    }
-    else
+    if (http->used == 0 && !http->blocking)
     {
      /*
-      * Wait a maximum of 1 second for data...
+      * Wait up to 10 seconds for more data on non-blocking sockets...
       */
 
-      if (!http->blocking)
+      if (!httpWait(http, 10000))
       {
        /*
-        * Wait up to 10 seconds for more data on non-blocking sockets...
+       * Signal no data...
        */
 
-       if (!httpWait(http, 10000))
-       {
-        /*
-          * Signal no data...
-         */
-
-          bytes = -1;
-         break;
-       }
+       bytes = -1;
+       break;
       }
+    }
 
-      if ((bytes = httpRead2(http, (char *)buffer, length - tbytes)) < 0)
-      {
+    if ((bytes = httpRead2(http, (char *)buffer, length - tbytes)) < 0)
+    {
 #ifdef WIN32
-        break;
+      break;
 #else
-        if (errno != EAGAIN && errno != EINTR)
-         break;
+      if (errno != EAGAIN && errno != EINTR)
+       break;
 
-       bytes = 0;
+      bytes = 0;
 #endif /* WIN32 */
-      }
-      else if (bytes == 0)
-        break;
     }
+    else if (bytes == 0)
+      break;
   }
 
  /*
@@ -5412,6 +6888,29 @@ ipp_read_file(int         *fd,           /* I - File descriptor */
 }
 
 
+/*
+ * 'ipp_set_error()' - Set a formatted, localized error string.
+ */
+
+static void
+ipp_set_error(ipp_status_t status,     /* I - Status code */
+              const char   *format,    /* I - Printf-style error string */
+             ...)                      /* I - Additional arguments as needed */
+{
+  va_list      ap;                     /* Pointer to additional args */
+  char         buffer[2048];           /* Message buffer */
+  cups_lang_t  *lang = cupsLangDefault();
+                                       /* Current language */
+
+
+  va_start(ap, format);
+  vsnprintf(buffer, sizeof(buffer), _cupsLangString(lang, format), ap);
+  va_end(ap);
+
+  _cupsSetError(status, buffer, 0);
+}
+
+
 /*
  * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
  *                     needed.
@@ -5468,7 +6967,7 @@ ipp_set_value(ipp_t           *ipp,       /* IO - IPP message */
   if ((temp = realloc(temp, sizeof(ipp_attribute_t) +
                            (alloc_values - 1) * sizeof(_ipp_value_t))) == NULL)
   {
-    _cupsSetHTTPError(HTTP_ERROR);
+    _cupsSetHTTPError(HTTP_STATUS_ERROR);
     DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
     return (NULL);
   }
@@ -5511,7 +7010,7 @@ ipp_set_value(ipp_t           *ipp,       /* IO - IPP message */
        */
 
        *attr = temp;
-       _cupsSetError(IPP_INTERNAL_ERROR,
+       _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                      _("IPP attribute is not a member of the message."), 1);
        DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
        return (NULL);
@@ -5561,5 +7060,5 @@ ipp_write_file(int         *fd,           /* I - File descriptor */
 
 
 /*
- * End of "$Id: ipp.c 10102 2011-11-02 23:52:39Z mike $".
+ * End of "$Id$".
  */