]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/ipp.c
CVE-2019-2228: Fix ippSetValueTag validation of default language.
[thirdparty/cups.git] / cups / ipp.c
index 0cc6706dcdc736287f35ad13f78beee32ddac96a..1595b8b6103e0c938dcb9f1a6172ea9b1c7d249e 100644 (file)
 /*
- * "$Id: ipp.c 10102 2011-11-02 23:52:39Z mike $"
- *
- *   Internet Printing Protocol functions for CUPS.
- *
- *   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
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * 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.
- *   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.
- *   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.
- *   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.
+ * Internet Printing Protocol functions for CUPS.
+ *
+ * Copyright © 2007-2019 by Apple Inc.
+ * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
+ *
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
  */
 
 #include "cups-private.h"
+#include "debug-internal.h"
 #include <regex.h>
-#ifdef WIN32
+#ifdef _WIN32
 #  include <io.h>
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
 
 /*
@@ -139,12 +29,8 @@ static ipp_attribute_t      *ipp_add_attr(ipp_t *ipp, const char *name,
                                      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 char            *ipp_get_code(const char *locale, char *buffer, size_t bufsize) _CUPS_NONNULL(1,2);
+static char            *ipp_lang_code(const char *locale, char *buffer, size_t bufsize) _CUPS_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);
@@ -231,8 +117,7 @@ ippAddBoolean(ipp_t      *ipp,              /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)",
-                ipp, group, ippTagString(group), name, value));
+  DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)", (void *)ipp, group, ippTagString(group), name, value));
 
  /*
   * Range check input...
@@ -280,9 +165,7 @@ ippAddBooleans(ipp_t      *ipp,             /* I - IPP message */
   _ipp_value_t         *value;         /* Current value */
 
 
-  DEBUG_printf(("ippAddBooleans(ipp=%p, group=%02x(%s), name=\"%s\", "
-                "num_values=%d, values=%p)", ipp, group, ippTagString(group),
-                name, num_values, values));
+  DEBUG_printf(("ippAddBooleans(ipp=%p, group=%02x(%s), name=\"%s\", num_values=%d, values=%p)", (void *)ipp, group, ippTagString(group), name, num_values, (void *)values));
 
  /*
   * Range check input...
@@ -324,7 +207,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/OS X 10.3@
+ * @since CUPS 1.1.19/macOS 10.3@
  */
 
 ipp_attribute_t *                      /* O - New attribute */
@@ -336,8 +219,7 @@ ippAddCollection(ipp_t      *ipp,   /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", "
-                "value=%p)", ipp, group, ippTagString(group), name, value));
+  DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp, group, ippTagString(group), name, (void *)value));
 
  /*
   * Range check input...
@@ -375,7 +257,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/OS X 10.3@
+ * @since CUPS 1.1.19/macOS 10.3@
  */
 
 ipp_attribute_t *                      /* O - New attribute */
@@ -391,9 +273,7 @@ ippAddCollections(
   _ipp_value_t         *value;         /* Current value */
 
 
-  DEBUG_printf(("ippAddCollections(ipp=%p, group=%02x(%s), name=\"%s\", "
-                "num_values=%d, values=%p)", ipp, group, ippTagString(group),
-                name, num_values, values));
+  DEBUG_printf(("ippAddCollections(ipp=%p, group=%02x(%s), name=\"%s\", num_values=%d, values=%p)", (void *)ipp, group, ippTagString(group), name, num_values, (void *)values));
 
  /*
   * Range check input...
@@ -428,7 +308,7 @@ ippAddCollections(
 
 
 /*
- * 'ippAddDate()' - Add a date attribute to an IPP message.
+ * 'ippAddDate()' - Add a dateTime attribute 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.
@@ -449,8 +329,7 @@ ippAddDate(ipp_t             *ipp,  /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)",
-                ipp, group, ippTagString(group), name, value));
+  DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp, group, ippTagString(group), name, (void *)value));
 
  /*
   * Range check input...
@@ -499,11 +378,9 @@ ippAddInteger(ipp_t      *ipp,             /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddInteger(ipp=%p, group=%02x(%s), type=%02x(%s), "
-                "name=\"%s\", value=%d)", ipp, group, ippTagString(group),
-               value_tag, ippTagString(value_tag), name, value));
+  DEBUG_printf(("ippAddInteger(ipp=%p, group=%02x(%s), type=%02x(%s), name=\"%s\", value=%d)", (void *)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
@@ -570,12 +447,9 @@ ippAddIntegers(ipp_t      *ipp,            /* I - IPP message */
   _ipp_value_t         *value;         /* Current value */
 
 
-  DEBUG_printf(("ippAddIntegers(ipp=%p, group=%02x(%s), type=%02x(%s), "
-                "name=\"%s\", num_values=%d, values=%p)", ipp,
-               group, ippTagString(group), value_tag, ippTagString(value_tag), name,
-               num_values, values));
+  DEBUG_printf(("ippAddIntegers(ipp=%p, group=%02x(%s), type=%02x(%s), name=\"%s\", num_values=%d, values=%p)", (void *)ipp, group, ippTagString(group), value_tag, ippTagString(value_tag), name, num_values, (void *)values));
 
-  value_tag &= IPP_TAG_MASK;
+  value_tag &= IPP_TAG_CUPS_MASK;
 
  /*
   * Range check input...
@@ -625,7 +499,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/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 ipp_attribute_t        *                       /* O - New attribute */
@@ -654,13 +528,13 @@ ippAddOctetString(ipp_t      *ipp,        /* I - IPP message */
 
   if (data)
   {
-    if ((attr->values[0].unknown.data = malloc(datalen)) == NULL)
+    if ((attr->values[0].unknown.data = malloc((size_t)datalen)) == NULL)
     {
       ippDeleteAttribute(ipp, attr);
       return (NULL);
     }
 
-    memcpy(attr->values[0].unknown.data, data, datalen);
+    memcpy(attr->values[0].unknown.data, data, (size_t)datalen);
   }
 
  /*
@@ -689,7 +563,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/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 ipp_attribute_t        *                       /* O - New attribute */
@@ -698,11 +572,9 @@ ippAddOutOfBand(ipp_t      *ipp,   /* I - IPP message */
                 ipp_tag_t  value_tag,  /* I - Type of attribute */
                const char *name)       /* I - Name of attribute */
 {
-  DEBUG_printf(("ippAddOutOfBand(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
-                "name=\"%s\")", ipp, group, ippTagString(group), value_tag,
-                ippTagString(value_tag), name));
+  DEBUG_printf(("ippAddOutOfBand(ipp=%p, group=%02x(%s), value_tag=%02x(%s), name=\"%s\")", (void *)ipp, group, ippTagString(group), value_tag, ippTagString(value_tag), name));
 
-  value_tag &= IPP_TAG_MASK;
+  value_tag &= IPP_TAG_CUPS_MASK;
 
  /*
   * Range check input...
@@ -752,9 +624,7 @@ ippAddRange(ipp_t      *ipp,                /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, "
-                "upper=%d)", ipp, group, ippTagString(group), name, lower,
-               upper));
+  DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, upper=%d)", (void *)ipp, group, ippTagString(group), name, lower, upper));
 
  /*
   * Range check input...
@@ -804,9 +674,7 @@ ippAddRanges(ipp_t      *ipp,               /* I - IPP message */
   _ipp_value_t         *value;         /* Current value */
 
 
-  DEBUG_printf(("ippAddRanges(ipp=%p, group=%02x(%s), name=\"%s\", "
-                "num_values=%d, lower=%p, upper=%p)", ipp, group,
-               ippTagString(group), name, num_values, lower, upper));
+  DEBUG_printf(("ippAddRanges(ipp=%p, group=%02x(%s), name=\"%s\", num_values=%d, lower=%p, upper=%p)", (void *)ipp, group, ippTagString(group), name, num_values, (void *)lower, (void *)upper));
 
  /*
   * Range check input...
@@ -863,8 +731,7 @@ ippAddResolution(ipp_t      *ipp,   /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", "
-                "units=%d, xres=%d, yres=%d)", ipp, group,
+  DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", units=%d, xres=%d, yres=%d)", (void *)ipp, group,
                ippTagString(group), name, units, xres, yres));
 
  /*
@@ -919,9 +786,7 @@ ippAddResolutions(ipp_t      *ipp,  /* I - IPP message */
   _ipp_value_t         *value;         /* Current value */
 
 
-  DEBUG_printf(("ippAddResolutions(ipp=%p, group=%02x(%s), name=\"%s\", "
-                "num_value=%d, units=%d, xres=%p, yres=%p)", ipp, group,
-               ippTagString(group), name, num_values, units, xres, yres));
+  DEBUG_printf(("ippAddResolutions(ipp=%p, group=%02x(%s), name=\"%s\", num_value=%d, units=%d, xres=%p, yres=%p)", (void *)ipp, group, ippTagString(group), name, num_values, units, (void *)xres, (void *)yres));
 
  /*
   * Range check input...
@@ -966,7 +831,7 @@ ippAddResolutions(ipp_t      *ipp,  /* I - IPP message */
 ipp_attribute_t *                      /* O - New attribute */
 ippAddSeparator(ipp_t *ipp)            /* I - IPP message */
 {
-  DEBUG_printf(("ippAddSeparator(ipp=%p)", ipp));
+  DEBUG_printf(("ippAddSeparator(ipp=%p)", (void *)ipp));
 
  /*
   * Range check input...
@@ -1020,16 +885,13 @@ ippAddString(ipp_t      *ipp,            /* I - IPP message */
                                        /* Charset/language code buffer */
 
 
-  DEBUG_printf(("ippAddString(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
-                "name=\"%s\", language=\"%s\", value=\"%s\")", ipp,
-               group, ippTagString(group), value_tag, ippTagString(value_tag), name,
-               language, value));
+  DEBUG_printf(("ippAddString(ipp=%p, group=%02x(%s), value_tag=%02x(%s), name=\"%s\", language=\"%s\", value=\"%s\")", (void *)ipp, group, ippTagString(group), value_tag, ippTagString(value_tag), name, language, value));
 
  /*
   * 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 ||
@@ -1051,13 +913,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 */
 
@@ -1072,7 +934,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;
@@ -1129,7 +991,7 @@ ippAddString(ipp_t      *ipp,              /* I - IPP message */
  * needed.  The formatted string is truncated as needed to the maximum length of
  * the corresponding value type.
  *
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 ipp_attribute_t *                      /* O - New attribute */
@@ -1182,7 +1044,7 @@ ippAddStringf(ipp_t      *ipp,            /* I - IPP message */
  * stdarg pointer @code ap@.  The formatted string is truncated as needed to the
  * maximum length of the corresponding value type.
  *
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 ipp_attribute_t *                      /* O - New attribute */
@@ -1208,7 +1070,7 @@ ippAddStringfv(ipp_t      *ipp,           /* I - IPP message */
       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)
+      !format)
     return (NULL);
 
   if ((value_tag == IPP_TAG_TEXTLANG || value_tag == IPP_TAG_NAMELANG)
@@ -1230,7 +1092,7 @@ ippAddStringfv(ipp_t      *ipp,           /* I - IPP message */
     if (!s)
       s = "(null)";
 
-    bytes = strlen(s);
+    bytes = (ssize_t)strlen(s);
     strlcpy(buffer, s, sizeof(buffer));
   }
   else
@@ -1355,16 +1217,13 @@ ippAddStrings(
   char                 code[32];       /* Language/charset value buffer */
 
 
-  DEBUG_printf(("ippAddStrings(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
-                "name=\"%s\", num_values=%d, language=\"%s\", values=%p)", ipp,
-               group, ippTagString(group), value_tag, ippTagString(value_tag), name,
-               num_values, language, values));
+  DEBUG_printf(("ippAddStrings(ipp=%p, group=%02x(%s), value_tag=%02x(%s), name=\"%s\", num_values=%d, language=\"%s\", values=%p)", (void *)ipp, group, ippTagString(group), value_tag, ippTagString(value_tag), name, num_values, language, (void *)values));
 
  /*
   * 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 ||
@@ -1388,10 +1247,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))))
@@ -1400,7 +1259,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))))
@@ -1429,7 +1288,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,
@@ -1441,7 +1300,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)));
@@ -1464,7 +1323,7 @@ ippAddStrings(
  * enum value, or the value falls within one of the rangeOfInteger values for
  * the attribute.
  *
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 int                                    /* O - 1 on a match, 0 on no match */
@@ -1513,9 +1372,9 @@ ippContainsInteger(
  *                         specified string value.
  *
  * Returns non-zero when the attribute contains a matching charset, keyword,
- * language, mimeMediaType, name, text, URI, or URI scheme value.
+ * naturalLanguage, mimeMediaType, name, text, uri, or uriScheme value.
  *
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 int                                    /* O - 1 on a match, 0 on no match */
@@ -1527,7 +1386,7 @@ ippContainsString(
   _ipp_value_t *avalue;                /* Current attribute value */
 
 
-  DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", attr, value));
+  DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", (void *)attr, value));
 
  /*
   * Range check input...
@@ -1552,13 +1411,27 @@ ippContainsString(
     case IPP_TAG_CHARSET :
     case IPP_TAG_KEYWORD :
     case IPP_TAG_LANGUAGE :
+    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);
+         }
+        }
+
     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 ++)
@@ -1566,7 +1439,7 @@ ippContainsString(
          DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
                        attr->num_values - i, avalue->string.text));
 
-         if (!strcmp(value, avalue->string.text))
+         if (!_cups_strcasecmp(value, avalue->string.text))
          {
            DEBUG_puts("1ippContainsString: Returning 1 (match)");
            return (1);
@@ -1591,7 +1464,7 @@ ippContainsString(
  * 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/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 
@@ -1602,13 +1475,13 @@ ippCopyAttribute(
     int             quickcopy)         /* I - 1 for a referenced copy, 0 for normal */
 {
   int                  i;              /* Looping var */
+  ipp_tag_t            srctag;         /* Source value tag */
   ipp_attribute_t      *dstattr;       /* Destination attribute */
   _ipp_value_t         *srcval,        /* Source value */
                        *dstval;        /* Destination value */
 
 
-  DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", dst, srcattr,
-                quickcopy));
+  DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", (void *)dst, (void *)srcattr, quickcopy));
 
  /*
   * Range check input...
@@ -1621,144 +1494,86 @@ ippCopyAttribute(
   * Copy it...
   */
 
-  quickcopy = quickcopy ? IPP_TAG_COPY : 0;
+  quickcopy = (quickcopy && (srcattr->value_tag & IPP_TAG_CUPS_CONST)) ? IPP_TAG_CUPS_CONST : 0;
+  srctag    = srcattr->value_tag & IPP_TAG_CUPS_MASK;
 
-  switch (srcattr->value_tag & ~IPP_TAG_COPY)
+  switch (srctag)
   {
     case IPP_TAG_ZERO :
         dstattr = ippAddSeparator(dst);
        break;
 
-    case IPP_TAG_INTEGER :
-    case IPP_TAG_ENUM :
-        dstattr = ippAddIntegers(dst, srcattr->group_tag, srcattr->value_tag,
-                                srcattr->name, srcattr->num_values, NULL);
-        if (!dstattr)
-          break;
-
-        for (i = srcattr->num_values, srcval = srcattr->values, dstval = dstattr->values;
-             i > 0;
-             i --, srcval ++, dstval ++)
-         dstval->integer = srcval->integer;
+    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 :
+        dstattr = ippAddOutOfBand(dst, srcattr->group_tag, srctag, srcattr->name);
         break;
 
+    case IPP_TAG_INTEGER :
+    case IPP_TAG_ENUM :
     case IPP_TAG_BOOLEAN :
-        dstattr = ippAddBooleans(dst, srcattr->group_tag, srcattr->name,
-                               srcattr->num_values, NULL);
-        if (!dstattr)
-          break;
-
-        for (i = srcattr->num_values, srcval = srcattr->values, dstval = dstattr->values;
-             i > 0;
-             i --, srcval ++, dstval ++)
-         dstval->boolean = srcval->boolean;
+    case IPP_TAG_DATE :
+    case IPP_TAG_RESOLUTION :
+    case IPP_TAG_RANGE :
+        if ((dstattr = ipp_add_attr(dst, srcattr->name, srcattr->group_tag, srctag, srcattr->num_values)) != NULL)
+         memcpy(dstattr->values, srcattr->values, (size_t)srcattr->num_values * sizeof(_ipp_value_t));
         break;
 
     case IPP_TAG_TEXT :
     case IPP_TAG_NAME :
+    case IPP_TAG_RESERVED_STRING :
     case IPP_TAG_KEYWORD :
     case IPP_TAG_URI :
     case IPP_TAG_URISCHEME :
     case IPP_TAG_CHARSET :
     case IPP_TAG_LANGUAGE :
     case IPP_TAG_MIMETYPE :
-        dstattr = ippAddStrings(dst, srcattr->group_tag,
-                               (ipp_tag_t)(srcattr->value_tag | quickcopy),
-                               srcattr->name, srcattr->num_values, NULL, NULL);
-        if (!dstattr)
+        if ((dstattr = ippAddStrings(dst, srcattr->group_tag, (ipp_tag_t)(srctag | quickcopy), srcattr->name, srcattr->num_values, NULL, NULL)) == NULL)
           break;
 
         if (quickcopy)
        {
-         for (i = srcattr->num_values, srcval = srcattr->values,
-                  dstval = dstattr->values;
-              i > 0;
-              i --, srcval ++, dstval ++)
-           dstval->string.text = srcval->string.text;
+        /*
+         * Can safely quick-copy these string values...
+         */
+
+         memcpy(dstattr->values, srcattr->values, (size_t)srcattr->num_values * sizeof(_ipp_value_t));
         }
-       else if (srcattr->value_tag & IPP_TAG_COPY)
-       {
-         for (i = srcattr->num_values, srcval = srcattr->values,
-                  dstval = dstattr->values;
-              i > 0;
-              i --, srcval ++, dstval ++)
-           dstval->string.text = _cupsStrAlloc(srcval->string.text);
-       }
        else
        {
-         for (i = srcattr->num_values, srcval = srcattr->values,
-                  dstval = dstattr->values;
-              i > 0;
-              i --, srcval ++, dstval ++)
-           dstval->string.text = _cupsStrRetain(srcval->string.text);
-       }
-        break;
-
-    case IPP_TAG_DATE :
-        if (srcattr->num_values != 1)
-          return (NULL);
-
-        dstattr = ippAddDate(dst, srcattr->group_tag, srcattr->name,
-                            srcattr->values[0].date);
-        break;
-
-    case IPP_TAG_RESOLUTION :
-        dstattr = ippAddResolutions(dst, srcattr->group_tag, srcattr->name,
-                                   srcattr->num_values, IPP_RES_PER_INCH,
-                                   NULL, NULL);
-        if (!dstattr)
-          break;
-
-        for (i = srcattr->num_values, srcval = srcattr->values, dstval = dstattr->values;
-             i > 0;
-             i --, srcval ++, dstval ++)
-       {
-         dstval->resolution.xres  = srcval->resolution.xres;
-         dstval->resolution.yres  = srcval->resolution.yres;
-         dstval->resolution.units = srcval->resolution.units;
-       }
-        break;
-
-    case IPP_TAG_RANGE :
-        dstattr = ippAddRanges(dst, srcattr->group_tag, srcattr->name,
-                              srcattr->num_values, NULL, NULL);
-        if (!dstattr)
-          break;
+        /*
+         * Otherwise do a normal reference counted copy...
+         */
 
-        for (i = srcattr->num_values, srcval = srcattr->values, dstval = dstattr->values;
-             i > 0;
-             i --, srcval ++, dstval ++)
-       {
-         dstval->range.lower = srcval->range.lower;
-         dstval->range.upper = srcval->range.upper;
+         for (i = srcattr->num_values, srcval = srcattr->values, dstval = dstattr->values; i > 0; i --, srcval ++, dstval ++)
+           dstval->string.text = _cupsStrAlloc(srcval->string.text);
        }
         break;
 
     case IPP_TAG_TEXTLANG :
     case IPP_TAG_NAMELANG :
-        dstattr = ippAddStrings(dst, srcattr->group_tag,
-                               (ipp_tag_t)(srcattr->value_tag | quickcopy),
-                               srcattr->name, srcattr->num_values, NULL, NULL);
-        if (!dstattr)
+        if ((dstattr = ippAddStrings(dst, srcattr->group_tag, (ipp_tag_t)(srctag | quickcopy), srcattr->name, srcattr->num_values, NULL, NULL)) == NULL)
           break;
 
         if (quickcopy)
        {
-         for (i = srcattr->num_values, srcval = srcattr->values,
-                  dstval = dstattr->values;
-              i > 0;
-              i --, srcval ++, dstval ++)
-         {
-            dstval->string.language = srcval->string.language;
-           dstval->string.text     = srcval->string.text;
-          }
+        /*
+         * Can safely quick-copy these string values...
+         */
+
+         memcpy(dstattr->values, srcattr->values, (size_t)srcattr->num_values * sizeof(_ipp_value_t));
         }
-       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;
-              i > 0;
-              i --, srcval ++, dstval ++)
+        /*
+         * Otherwise do a normal reference counted copy...
+         */
+
+         for (i = srcattr->num_values, srcval = srcattr->values, dstval = dstattr->values; i > 0; i --, srcval ++, dstval ++)
          {
            if (srcval == srcattr->values)
               dstval->string.language = _cupsStrAlloc(srcval->string.language);
@@ -1768,32 +1583,13 @@ ippCopyAttribute(
            dstval->string.text = _cupsStrAlloc(srcval->string.text);
           }
         }
-       else
-       {
-         for (i = srcattr->num_values, srcval = srcattr->values,
-                  dstval = dstattr->values;
-              i > 0;
-              i --, srcval ++, dstval ++)
-         {
-           if (srcval == srcattr->values)
-              dstval->string.language = _cupsStrRetain(srcval->string.language);
-           else
-              dstval->string.language = dstattr->values[0].string.language;
-
-           dstval->string.text = _cupsStrRetain(srcval->string.text);
-          }
-        }
         break;
 
     case IPP_TAG_BEGIN_COLLECTION :
-        dstattr = ippAddCollections(dst, srcattr->group_tag, srcattr->name,
-                                   srcattr->num_values, NULL);
-        if (!dstattr)
+        if ((dstattr = ippAddCollections(dst, srcattr->group_tag, srcattr->name, srcattr->num_values, NULL)) == NULL)
           break;
 
-        for (i = srcattr->num_values, srcval = srcattr->values, dstval = dstattr->values;
-             i > 0;
-             i --, srcval ++, dstval ++)
+        for (i = srcattr->num_values, srcval = srcattr->values, dstval = dstattr->values; i > 0; i --, srcval ++, dstval ++)
        {
          dstval->collection = srcval->collection;
          srcval->collection->use ++;
@@ -1802,24 +1598,19 @@ ippCopyAttribute(
 
     case IPP_TAG_STRING :
     default :
-        /* TODO: Implement quick copy for unknown/octetString values */
-        dstattr = ippAddIntegers(dst, srcattr->group_tag, srcattr->value_tag,
-                                srcattr->name, srcattr->num_values, NULL);
-        if (!dstattr)
+        if ((dstattr = ipp_add_attr(dst, srcattr->name, srcattr->group_tag, srctag, srcattr->num_values)) == NULL)
           break;
 
-        for (i = srcattr->num_values, srcval = srcattr->values, dstval = dstattr->values;
-             i > 0;
-             i --, srcval ++, dstval ++)
+        for (i = srcattr->num_values, srcval = srcattr->values, dstval = dstattr->values; i > 0; i --, srcval ++, dstval ++)
        {
          dstval->unknown.length = srcval->unknown.length;
 
          if (dstval->unknown.length > 0)
          {
-           if ((dstval->unknown.data = malloc(dstval->unknown.length)) == NULL)
+           if ((dstval->unknown.data = malloc((size_t)dstval->unknown.length)) == NULL)
              dstval->unknown.length = 0;
            else
-             memcpy(dstval->unknown.data, srcval->unknown.data, dstval->unknown.length);
+             memcpy(dstval->unknown.data, srcval->unknown.data, (size_t)dstval->unknown.length);
          }
        }
         break; /* anti-compiler-warning-code */
@@ -1832,7 +1623,7 @@ ippCopyAttribute(
 /*
  * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
  *
- * Zero or more attributes are copied from the source IPP message, @code@ src, to the
+ * Zero or more attributes are copied from the source IPP message, @code src@, to the
  * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
  * reference copy of the attribute is created - this should only be done as long as the
  * original source IPP message will not be freed for the life of the destination.
@@ -1842,7 +1633,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/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on error */
@@ -1856,8 +1647,7 @@ ippCopyAttributes(
   ipp_attribute_t      *srcattr;       /* Source attribute */
 
 
-  DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)",
-                dst, src, quickcopy, cb, context));
+  DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)", (void *)dst, (void *)src, quickcopy, (void *)cb, context));
 
  /*
   * Range check input...
@@ -1880,12 +1670,12 @@ ippCopyAttributes(
 
 
 /*
- * 'ippDateToTime()' - Convert from RFC 1903 Date/Time format to UNIX time
- *                     in seconds.
+ * 'ippDateToTime()' - Convert from RFC 2579 Date/Time format to time in
+ *                     seconds.
  */
 
 time_t                                 /* O - UNIX time value */
-ippDateToTime(const ipp_uchar_t *date) /* I - RFC 1903 date info */
+ippDateToTime(const ipp_uchar_t *date) /* I - RFC 2579 date info */
 {
   struct tm    unixdate;               /* UNIX date/time info */
   time_t       t;                      /* Computed time */
@@ -1897,7 +1687,7 @@ ippDateToTime(const ipp_uchar_t *date)    /* I - RFC 1903 date info */
   memset(&unixdate, 0, sizeof(unixdate));
 
  /*
-  * RFC-1903 date/time format is:
+  * RFC-2579 date/time format is:
   *
   *    Byte(s)  Description
   *    -------  -----------
@@ -1942,19 +1732,26 @@ ippDelete(ipp_t *ipp)                   /* I - IPP message */
                        *next;          /* Next attribute */
 
 
-  DEBUG_printf(("ippDelete(ipp=%p)", ipp));
+  DEBUG_printf(("ippDelete(ipp=%p)", (void *)ipp));
 
   if (!ipp)
     return;
 
   ipp->use --;
   if (ipp->use > 0)
+  {
+    DEBUG_printf(("4debug_retain: %p IPP message (use=%d)", (void *)ipp, ipp->use));
     return;
+  }
+
+  DEBUG_printf(("4debug_free: %p IPP message", (void *)ipp));
 
   for (attr = ipp->attrs; attr != NULL; attr = next)
   {
     next = attr->next;
 
+    DEBUG_printf(("4debug_free: %p %s %s%s (%d values)", (void *)attr, attr->name, attr->num_values > 1 ? "1setOf " : "", ippTagString(attr->value_tag), attr->num_values));
+
     ipp_free_values(attr, 0, attr->num_values);
 
     if (attr->name)
@@ -1970,7 +1767,7 @@ ippDelete(ipp_t *ipp)                     /* I - IPP message */
 /*
  * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
  *
- * @since CUPS 1.1.19/OS X 10.3@
+ * @since CUPS 1.1.19/macOS 10.3@
  */
 
 void
@@ -1982,8 +1779,7 @@ ippDeleteAttribute(
                        *prev;          /* Previous attribute */
 
 
-  DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", ipp, attr,
-                attr ? attr->name : "(null)"));
+  DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", (void *)ipp, (void *)attr, attr ? attr->name : "(null)"));
 
  /*
   * Range check input...
@@ -1992,6 +1788,8 @@ ippDeleteAttribute(
   if (!attr)
     return;
 
+  DEBUG_printf(("4debug_free: %p %s %s%s (%d values)", (void *)attr, attr->name, attr->num_values > 1 ? "1setOf " : "", ippTagString(attr->value_tag), attr->num_values));
+
  /*
   * Find the attribute in the list...
   */
@@ -2045,7 +1843,7 @@ ippDeleteAttribute(
  *
  * Deleting all values in an attribute deletes the attribute.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
@@ -2087,6 +1885,10 @@ ippDeleteValues(
 
 /*
  * 'ippFindAttribute()' - Find a named attribute in a request.
+ *
+ * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
+ * of attribute and member names separated by slashes, for example
+ * "media-col/media-size".
  */
 
 ipp_attribute_t        *                       /* O - Matching attribute */
@@ -2094,8 +1896,7 @@ ippFindAttribute(ipp_t      *ipp, /* I - IPP message */
                  const char *name,     /* I - Name of attribute */
                 ipp_tag_t  type)       /* I - Type of attribute */
 {
-  DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", ipp,
-                name, type, ippTagString(type)));
+  DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp, name, type, ippTagString(type)));
 
   if (!ipp || !name)
     return (NULL);
@@ -2105,6 +1906,7 @@ ippFindAttribute(ipp_t      *ipp, /* I - IPP message */
   */
 
   ipp->current = NULL;
+  ipp->atend   = 0;
 
  /*
   * Search for the attribute...
@@ -2116,6 +1918,10 @@ ippFindAttribute(ipp_t      *ipp,        /* I - IPP message */
 
 /*
  * 'ippFindNextAttribute()' - Find the next named attribute in a request.
+ *
+ * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
+ * of attribute and member names separated by slashes, for example
+ * "media-col/media-size".
  */
 
 ipp_attribute_t        *                       /* O - Matching attribute */
@@ -2123,17 +1929,72 @@ ippFindNextAttribute(ipp_t      *ipp,   /* I - IPP message */
                      const char *name, /* I - Name of attribute */
                     ipp_tag_t  type)   /* I - Type of attribute */
 {
-  ipp_attribute_t      *attr;          /* Current atttribute */
+  ipp_attribute_t      *attr,          /* Current atttribute */
+                       *childattr;     /* Child attribute */
   ipp_tag_t            value_tag;      /* Value tag */
+  char                 parent[1024],   /* Parent attribute name */
+                       *child = NULL;  /* Child attribute name */
 
 
-  DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))",
-                ipp, name, type, ippTagString(type)));
+  DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp, name, type, ippTagString(type)));
 
   if (!ipp || !name)
     return (NULL);
 
-  if (ipp->current)
+  DEBUG_printf(("3ippFindNextAttribute: atend=%d", ipp->atend));
+
+  if (ipp->atend)
+    return (NULL);
+
+  if (strchr(name, '/'))
+  {
+   /*
+    * Search for child attribute...
+    */
+
+    strlcpy(parent, name, sizeof(parent));
+    if ((child = strchr(parent, '/')) == NULL)
+    {
+      DEBUG_puts("3ippFindNextAttribute: Attribute name too long.");
+      return (NULL);
+    }
+
+    *child++ = '\0';
+
+    if (ipp->current && ipp->current->name && ipp->current->value_tag == IPP_TAG_BEGIN_COLLECTION && !strcmp(parent, ipp->current->name))
+    {
+      while (ipp->curindex < ipp->current->num_values)
+      {
+        if ((childattr = ippFindNextAttribute(ipp->current->values[ipp->curindex].collection, child, type)) != NULL)
+          return (childattr);
+
+        ipp->curindex ++;
+        if (ipp->curindex < ipp->current->num_values && ipp->current->values[ipp->curindex].collection)
+          ipp->current->values[ipp->curindex].collection->current = NULL;
+      }
+
+      ipp->prev     = ipp->current;
+      ipp->current  = ipp->current->next;
+      ipp->curindex = 0;
+
+      if (!ipp->current)
+      {
+        ipp->atend = 1;
+        return (NULL);
+      }
+    }
+
+    if (!ipp->current)
+    {
+      ipp->prev     = NULL;
+      ipp->current  = ipp->attrs;
+      ipp->curindex = 0;
+    }
+
+    name = parent;
+    attr = ipp->current;
+  }
+  else if (ipp->current)
   {
     ipp->prev = ipp->current;
     attr      = ipp->current->next;
@@ -2146,24 +2007,38 @@ ippFindNextAttribute(ipp_t      *ipp,   /* I - IPP message */
 
   for (; attr != NULL; ipp->prev = attr, attr = attr->next)
   {
-    DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", attr,
-                  attr->name));
+    DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", (void *)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 ||
+        (value_tag == type || type == IPP_TAG_ZERO || name == parent ||
         (value_tag == IPP_TAG_TEXTLANG && type == IPP_TAG_TEXT) ||
         (value_tag == IPP_TAG_NAMELANG && type == IPP_TAG_NAME)))
     {
       ipp->current = attr;
 
-      return (attr);
+      if (name == parent && attr->value_tag == IPP_TAG_BEGIN_COLLECTION)
+      {
+        int i;                         /* Looping var */
+
+        for (i = 0; i < attr->num_values; i ++)
+        {
+         if ((childattr = ippFindAttribute(attr->values[i].collection, child, type)) != NULL)
+         {
+           attr->values[0].collection->curindex = i;
+           return (childattr);
+         }
+        }
+      }
+      else
+        return (attr);
     }
   }
 
   ipp->current = NULL;
   ipp->prev    = NULL;
+  ipp->atend   = 1;
 
   return (NULL);
 }
@@ -2172,7 +2047,7 @@ ippFindNextAttribute(ipp_t      *ipp,     /* I - IPP message */
 /*
  * 'ippFirstAttribute()' - Return the first attribute in the message.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 ipp_attribute_t        *                       /* O - First attribute or @code NULL@ if none */
@@ -2197,12 +2072,12 @@ ippFirstAttribute(ipp_t *ipp)           /* I - IPP message */
  * 'ippGetBoolean()' - Get a boolean value for an attribute.
  *
  * The @code element@ parameter specifies which value to get from 0 to
- * @link ippGetCount(attr)@ - 1.
+ * @code ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
-int                                    /* O - Boolean value or -1 on error */
+int                                    /* O - Boolean value or 0 on error */
 ippGetBoolean(ipp_attribute_t *attr,   /* I - IPP attribute */
               int             element) /* I - Value number (0-based) */
 {
@@ -2212,7 +2087,7 @@ ippGetBoolean(ipp_attribute_t *attr,      /* I - IPP attribute */
 
   if (!attr || attr->value_tag != IPP_TAG_BOOLEAN ||
       element < 0 || element >= attr->num_values)
-    return (-1);
+    return (0);
 
  /*
   * Return the value...
@@ -2226,9 +2101,9 @@ ippGetBoolean(ipp_attribute_t *attr,      /* I - IPP attribute */
  * 'ippGetCollection()' - Get a collection value for an attribute.
  *
  * The @code element@ parameter specifies which value to get from 0 to
- * @link ippGetCount(attr)@ - 1.
+ * @code ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 ipp_t *                                        /* O - Collection value or @code NULL@ on error */
@@ -2255,10 +2130,10 @@ ippGetCollection(
 /*
  * 'ippGetCount()' - Get the number of values in an attribute.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
-int                                    /* O - Number of values or -1 on error */
+int                                    /* O - Number of values or 0 on error */
 ippGetCount(ipp_attribute_t *attr)     /* I - IPP attribute */
 {
  /*
@@ -2266,7 +2141,7 @@ ippGetCount(ipp_attribute_t *attr)        /* I - IPP attribute */
   */
 
   if (!attr)
-    return (-1);
+    return (0);
 
  /*
   * Return the number of values...
@@ -2277,15 +2152,15 @@ ippGetCount(ipp_attribute_t *attr)      /* I - IPP attribute */
 
 
 /*
- * 'ippGetDate()' - Get a date value for an attribute.
+ * 'ippGetDate()' - Get a dateTime value for an attribute.
  *
  * The @code element@ parameter specifies which value to get from 0 to
- * @link ippGetCount(attr)@ - 1.
+ * @code ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
-const ipp_uchar_t *                    /* O - Date value or @code NULL@ */
+const ipp_uchar_t *                    /* O - dateTime value or @code NULL@ */
 ippGetDate(ipp_attribute_t *attr,      /* I - IPP attribute */
            int             element)    /* I - Value number (0-based) */
 {
@@ -2308,7 +2183,7 @@ ippGetDate(ipp_attribute_t *attr, /* I - IPP attribute */
 /*
  * 'ippGetGroupTag()' - Get the group associated with an attribute.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 ipp_tag_t                              /* O - Group tag or @code IPP_TAG_ZERO@ on error */
@@ -2333,12 +2208,12 @@ ippGetGroupTag(ipp_attribute_t *attr)   /* I - IPP attribute */
  * 'ippGetInteger()' - Get the integer/enum value for an attribute.
  *
  * The @code element@ parameter specifies which value to get from 0 to
- * @link ippGetCount(attr)@ - 1.
+ * @code ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
-int                                    /* O - Value or -1 on error */
+int                                    /* O - Value or 0 on error */
 ippGetInteger(ipp_attribute_t *attr,   /* I - IPP attribute */
               int             element) /* I - Value number (0-based) */
 {
@@ -2348,7 +2223,7 @@ ippGetInteger(ipp_attribute_t *attr,      /* I - IPP attribute */
 
   if (!attr || (attr->value_tag != IPP_TAG_INTEGER && attr->value_tag != IPP_TAG_ENUM) ||
       element < 0 || element >= attr->num_values)
-    return (-1);
+    return (0);
 
  /*
   * Return the value...
@@ -2361,7 +2236,7 @@ ippGetInteger(ipp_attribute_t *attr,      /* I - IPP attribute */
 /*
  * 'ippGetName()' - Get the attribute name.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 const char *                           /* O - Attribute name or @code NULL@ for separators */
@@ -2382,13 +2257,52 @@ 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
+ * @code ippGetCount(attr)@ - 1.
+ *
+ * @since CUPS 1.7/macOS 10.9@
+ */
+
+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/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
-ipp_op_t                               /* O - Operation ID or -1 on error */
+ipp_op_t                               /* O - Operation ID or 0 on error */
 ippGetOperation(ipp_t *ipp)            /* I - IPP request message */
 {
  /*
@@ -2396,7 +2310,7 @@ ippGetOperation(ipp_t *ipp)               /* I - IPP request message */
   */
 
   if (!ipp)
-    return ((ipp_op_t)-1);
+    return ((ipp_op_t)0);
 
  /*
   * Return the value...
@@ -2410,12 +2324,12 @@ ippGetOperation(ipp_t *ipp)             /* I - IPP request message */
  * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
  *
  * The @code element@ parameter specifies which value to get from 0 to
- * @link ippGetCount(attr)@ - 1.
+ * @code ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
-int                                    /* O - Lower value of range or -1 */
+int                                    /* O - Lower value of range or 0 */
 ippGetRange(ipp_attribute_t *attr,     /* I - IPP attribute */
            int             element,    /* I - Value number (0-based) */
            int             *uppervalue)/* O - Upper value of range */
@@ -2428,9 +2342,9 @@ ippGetRange(ipp_attribute_t *attr,        /* I - IPP attribute */
       element < 0 || element >= attr->num_values)
   {
     if (uppervalue)
-      *uppervalue = -1;
+      *uppervalue = 0;
 
-    return (-1);
+    return (0);
   }
 
  /*
@@ -2447,10 +2361,10 @@ ippGetRange(ipp_attribute_t *attr,      /* I - IPP attribute */
 /*
  * 'ippGetRequestId()' - Get the request ID from an IPP message.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
-int                                    /* O - Request ID or -1 on error */
+int                                    /* O - Request ID or 0 on error */
 ippGetRequestId(ipp_t *ipp)            /* I - IPP message */
 {
  /*
@@ -2458,7 +2372,7 @@ ippGetRequestId(ipp_t *ipp)               /* I - IPP message */
   */
 
   if (!ipp)
-    return (-1);
+    return (0);
 
  /*
   * Return the request ID...
@@ -2472,12 +2386,12 @@ ippGetRequestId(ipp_t *ipp)             /* I - IPP message */
  * 'ippGetResolution()' - Get a resolution value for an attribute.
  *
  * The @code element@ parameter specifies which value to get from 0 to
- * @link ippGetCount(attr)@ - 1.
+ * @code ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
-int                                    /* O - Horizontal/cross feed resolution or -1 */
+int                                    /* O - Horizontal/cross feed resolution or 0 */
 ippGetResolution(
     ipp_attribute_t *attr,             /* I - IPP attribute */
     int             element,           /* I - Value number (0-based) */
@@ -2490,7 +2404,15 @@ ippGetResolution(
 
   if (!attr || attr->value_tag != IPP_TAG_RESOLUTION ||
       element < 0 || element >= attr->num_values)
-    return (-1);
+  {
+    if (yres)
+      *yres = 0;
+
+    if (units)
+      *units = (ipp_res_t)0;
+
+    return (0);
+  }
 
  /*
   * Return the value...
@@ -2509,7 +2431,7 @@ ippGetResolution(
 /*
  * 'ippGetState()' - Get the IPP message state.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 ipp_state_t                            /* O - IPP message state value */
@@ -2520,7 +2442,7 @@ ippGetState(ipp_t *ipp)                   /* I - IPP message */
   */
 
   if (!ipp)
-    return (IPP_IDLE);
+    return (IPP_STATE_IDLE);
 
  /*
   * Return the value...
@@ -2533,7 +2455,7 @@ ippGetState(ipp_t *ipp)                   /* I - IPP message */
 /*
  * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 ipp_status_t                           /* O - Status code in IPP message */
@@ -2544,7 +2466,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...
@@ -2558,9 +2480,9 @@ ippGetStatusCode(ipp_t *ipp)              /* I - IPP response or event message */
  * 'ippGetString()' - Get the string and optionally the language code for an attribute.
  *
  * The @code element@ parameter specifies which value to get from 0 to
- * @link ippGetCount(attr)@ - 1.
+ * @code ippGetCount(attr)@ - 1.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 const char *
@@ -2568,13 +2490,16 @@ ippGetString(ipp_attribute_t *attr,     /* I - IPP attribute */
              int             element,  /* I - Value number (0-based) */
             const char      **language)/* O - Language code (@code NULL@ for don't care) */
 {
+  ipp_tag_t    tag;                    /* Value tag */
+
+
  /*
   * Range check input...
   */
 
-  if (!attr || element < 0 || element >= attr->num_values ||
-      (attr->value_tag != IPP_TAG_TEXTLANG && attr->value_tag != IPP_TAG_NAMELANG &&
-       (attr->value_tag < IPP_TAG_TEXT || attr->value_tag > IPP_TAG_MIMETYPE)))
+  tag = ippGetValueTag(attr);
+
+  if (!attr || element < 0 || element >= attr->num_values || (tag != IPP_TAG_TEXTLANG && tag != IPP_TAG_NAMELANG && (tag < IPP_TAG_TEXT || tag > IPP_TAG_MIMETYPE)))
     return (NULL);
 
  /*
@@ -2591,7 +2516,7 @@ ippGetString(ipp_attribute_t *attr,       /* I - IPP attribute */
 /*
  * 'ippGetValueTag()' - Get the value tag for an attribute.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 ipp_tag_t                              /* O - Value tag or @code IPP_TAG_ZERO@ on error */
@@ -2608,19 +2533,19 @@ ippGetValueTag(ipp_attribute_t *attr)   /* I - IPP attribute */
   * Return the value...
   */
 
-  return (attr->value_tag & IPP_TAG_MASK);
+  return (attr->value_tag & IPP_TAG_CUPS_MASK);
 }
 
 
 /*
  * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
-int                                    /* O - Major version number or -1 on error */
+int                                    /* O - Major version number or 0 on error */
 ippGetVersion(ipp_t *ipp,              /* I - IPP message */
-              int   *minor)            /* O - Minor version number or @code NULL@ */
+              int   *minor)            /* O - Minor version number or @code NULL@ for don't care */
 {
  /*
   * Range check input...
@@ -2629,9 +2554,9 @@ ippGetVersion(ipp_t *ipp,         /* I - IPP message */
   if (!ipp)
   {
     if (minor)
-      *minor = -1;
+      *minor = 0;
 
-    return (-1);
+    return (0);
   }
 
  /*
@@ -2659,7 +2584,7 @@ ippLength(ipp_t *ipp)                     /* I - IPP message */
 /*
  * 'ippNextAttribute()' - Return the next attribute in the message.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 ipp_attribute_t *                      /* O - Next attribute or @code NULL@ if none */
@@ -2700,12 +2625,17 @@ ippNew(void)
     * Set default version - usually 2.0...
     */
 
-    temp->request.any.version[0] = cg->server_version / 10;
-    temp->request.any.version[1] = cg->server_version % 10;
+    DEBUG_printf(("4debug_alloc: %p IPP message", (void *)temp));
+
+    if (cg->server_version == 0)
+      _cupsSetDefaults();
+
+    temp->request.any.version[0] = (ipp_uchar_t)(cg->server_version / 10);
+    temp->request.any.version[1] = (ipp_uchar_t)(cg->server_version % 10);
     temp->use                    = 1;
   }
 
-  DEBUG_printf(("1ippNew: Returning %p", temp));
+  DEBUG_printf(("1ippNew: Returning %p", (void *)temp));
 
   return (temp);
 }
@@ -2714,11 +2644,11 @@ ippNew(void)
 /*
  *  'ippNewRequest()' - Allocate a new IPP request message.
  *
- * The new request message is initialized with the attributes-charset and
- * attributes-natural-language attributes added. The
- * attributes-natural-language value is derived from the current locale.
+ * The new request message is initialized with the "attributes-charset" and
+ * "attributes-natural-language" attributes added. The
+ * "attributes-natural-language" value is derived from the current locale.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 ipp_t *                                        /* O - IPP request message */
@@ -2778,14 +2708,14 @@ ippNewRequest(ipp_op_t op)              /* I - Operation code */
 /*
  * '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,
+ * 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@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 ipp_t *                                        /* O - IPP response message */
@@ -2891,14 +2821,12 @@ 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)));
+  DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT, (void *)http, (void *)ipp, CUPS_LLCAST (http ? http->data_remaining : -1)));
 
   if (!http)
-    return (IPP_ERROR);
+    return (IPP_STATE_ERROR);
 
-  DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http->state,
-                http->used));
+  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,
                     ipp));
@@ -2908,14 +2836,14 @@ ippRead(http_t *http,                   /* I - HTTP connection */
 /*
  * 'ippReadFile()' - Read data for an IPP message from a file.
  *
- * @since CUPS 1.1.19/OS X 10.3@
+ * @since CUPS 1.1.19/macOS 10.3@
  */
 
 ipp_state_t                            /* O - Current state */
 ippReadFile(int   fd,                  /* I - HTTP data */
             ipp_t *ipp)                        /* I - IPP data */
 {
-  DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd, ipp));
+  DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd, (void *)ipp));
 
   return (ippReadIO(&fd, (ipp_iocb_t)ipp_read_file, 1, NULL, ipp));
 }
@@ -2924,7 +2852,7 @@ ippReadFile(int   fd,                     /* I - HTTP data */
 /*
  * 'ippReadIO()' - Read data for an IPP message.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 ipp_state_t                            /* O - Current state */
@@ -2945,25 +2873,24 @@ ippReadIO(void       *src,              /* I - Data source */
   _ipp_value_t         *value;         /* Current value */
 
 
-  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 ? ipp->state : IPP_ERROR));
+  DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)src, (void *)cb, blocking, (void *)parent, (void *)ipp));
+  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)
        {
         /*
@@ -2974,7 +2901,7 @@ ippReadIO(void       *src,                /* I - Data source */
          {
            DEBUG_puts("1ippReadIO: Unable to read header.");
            _cupsBufferRelease((char *)buffer);
-           return (IPP_ERROR);
+           return (IPP_STATE_ERROR);
          }
 
         /*
@@ -2994,7 +2921,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;
@@ -3006,18 +2933,17 @@ 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",
-                       ipp->current, ipp->prev));
+         DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p", (void *)ipp->current, (void *)ipp->prev));
 
         /*
          * Read this attribute...
@@ -3034,22 +2960,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);
+             _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);
             }
           }
 
@@ -3061,9 +2987,16 @@ 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_ZERO || (tag == IPP_TAG_OPERATION && ipp->curtag != IPP_TAG_ZERO))
+         {
+           _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Invalid group tag."), 1);
+           DEBUG_printf(("1ippReadIO: bad tag 0x%02x.", tag));
+           _cupsBufferRelease((char *)buffer);
+           return (IPP_STATE_ERROR);
+         }
           else if (tag < IPP_TAG_UNSUPPORTED_VALUE)
          {
           /*
@@ -3077,8 +3010,7 @@ ippReadIO(void       *src,                /* I - Data source */
 
            ipp->curtag  = tag;
            ipp->current = NULL;
-           DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag,
-                         ippTagString(tag), ipp->prev));
+           DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag, ippTagString(tag), (void *)ipp->prev));
            continue;
          }
 
@@ -3093,23 +3025,28 @@ 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));
 
-          if (n == 0 && tag != IPP_TAG_MEMBERNAME &&
-             tag != IPP_TAG_END_COLLECTION)
+          if (n && parent)
+          {
+            _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Invalid named IPP attribute in collection."), 1);
+            DEBUG_puts("1ippReadIO: bad attribute name in collection.");
+            return (IPP_STATE_ERROR);
+          }
+          else if (n == 0 && tag != IPP_TAG_MEMBERNAME && tag != IPP_TAG_END_COLLECTION)
          {
           /*
            * More values for current attribute...
@@ -3117,14 +3054,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
@@ -3153,14 +3090,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)
@@ -3180,14 +3117,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)
@@ -3203,14 +3140,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);
             }
 
            /*
@@ -3220,7 +3157,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)
@@ -3231,10 +3168,10 @@ 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)
@@ -3243,14 +3180,13 @@ ippReadIO(void       *src,              /* I - Data source */
            attr = ipp->current = ipp_add_attr(ipp, NULL, ipp->curtag, IPP_TAG_ZERO, 1);
            if (!attr)
            {
-             _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: membername, ipp->current=%p, ipp->prev=%p",
-                         ipp->current, ipp->prev));
+           DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp->current, (void *)ipp->prev));
 
            value = attr->values;
          }
@@ -3260,11 +3196,11 @@ ippReadIO(void       *src,              /* I - Data source */
            * New attribute; read the name and add it...
            */
 
-           if ((*cb)(src, buffer, n) < n)
+           if ((*cb)(src, buffer, (size_t)n) < n)
            {
              DEBUG_puts("1ippReadIO: unable to read name.");
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
 
            buffer[n] = '\0';
@@ -3275,14 +3211,13 @@ 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, "
-                         "ipp->prev=%p", buffer, ipp->current, ipp->prev));
+           DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer, (void *)ipp->current, (void *)ipp->prev));
 
            value = attr->values;
          }
@@ -3296,7 +3231,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];
@@ -3304,11 +3239,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)
@@ -3318,21 +3253,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 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) |
@@ -3347,24 +3282,27 @@ 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 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];
+                value->boolean = (char)buffer[0];
                break;
 
-            case IPP_TAG_NOVALUE :
+           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 :
@@ -3384,6 +3322,7 @@ ippReadIO(void       *src,                /* I - Data source */
 
            case IPP_TAG_TEXT :
            case IPP_TAG_NAME :
+           case IPP_TAG_RESERVED_STRING :
            case IPP_TAG_KEYWORD :
            case IPP_TAG_URI :
            case IPP_TAG_URISCHEME :
@@ -3392,11 +3331,11 @@ ippReadIO(void       *src,              /* I - Data source */
            case IPP_TAG_MIMETYPE :
                if (n > 0)
                {
-                 if ((*cb)(src, buffer, n) < n)
+                 if ((*cb)(src, buffer, (size_t)n) < n)
                  {
                    DEBUG_puts("1ippReadIO: unable to read string value.");
                    _cupsBufferRelease((char *)buffer);
-                   return (IPP_ERROR);
+                   return (IPP_STATE_ERROR);
                  }
                }
 
@@ -3408,35 +3347,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);
+                 _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 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 =
@@ -3452,19 +3391,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 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 =
@@ -3480,25 +3419,25 @@ 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 stringWithLanguage value "
                                "length %d.", n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
-               if ((*cb)(src, buffer, n) < n)
+               if ((*cb)(src, buffer, (size_t)n) < n)
                {
                  DEBUG_puts("1ippReadIO: Unable to read string w/language "
                             "value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                 bufptr = buffer;
@@ -3515,27 +3454,26 @@ ippReadIO(void       *src,              /* I - Data source */
 
                n = (bufptr[0] << 8) | bufptr[1];
 
-               if ((bufptr + 2 + n) >= (buffer + IPP_BUF_SIZE) ||
-                   n >= sizeof(string))
+               if ((bufptr + 2 + n) >= (buffer + IPP_BUF_SIZE) || n >= (int)sizeof(string))
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                _("IPP language length overflows value."), 1);
                  DEBUG_printf(("1ippReadIO: bad language value length %d.",
                                n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
                else if (n >= IPP_MAX_LANGUAGE)
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _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);
+               memcpy(string, bufptr + 2, (size_t)n);
                string[n] = '\0';
 
                value->string.language = _cupsStrAlloc((char *)string);
@@ -3545,11 +3483,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 string value length %d.", n));
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                bufptr[2 + n] = '\0';
@@ -3565,19 +3503,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;
 
@@ -3586,15 +3524,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 :
               /*
@@ -3604,25 +3542,25 @@ ippReadIO(void       *src,              /* I - Data source */
 
                 if (!attr)
                 {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                _("IPP memberName with no attribute."), 1);
                  DEBUG_puts("1ippReadIO: Member name without attribute.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                 }
                else if (n == 0)
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
                                _("IPP memberName value is empty."), 1);
                  DEBUG_puts("1ippReadIO: Empty member name value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
-               else if ((*cb)(src, buffer, n) < n)
+               else if ((*cb)(src, buffer, (size_t)n) < n)
                {
                  DEBUG_puts("1ippReadIO: Unable to read member name value.");
                  _cupsBufferRelease((char *)buffer);
-                 return (IPP_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                buffer[n] = '\0';
@@ -3639,34 +3577,35 @@ ippReadIO(void       *src,              /* I - Data source */
                DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr->name));
                break;
 
+            case IPP_TAG_STRING :
             default : /* Other unsupported values */
                 if (tag == IPP_TAG_STRING && n > IPP_MAX_LENGTH)
                {
-                 _cupsSetError(IPP_INTERNAL_ERROR,
+                 _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_ERROR);
+                 return (IPP_STATE_ERROR);
                }
 
                 value->unknown.length = n;
 
                if (n > 0)
                {
-                 if ((value->unknown.data = malloc(n)) == NULL)
+                 if ((value->unknown.data = malloc((size_t)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)
+                 if ((*cb)(src, value->unknown.data, (size_t)n) < n)
                  {
                    DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
                    _cupsBufferRelease((char *)buffer);
-                   return (IPP_ERROR);
+                   return (IPP_STATE_ERROR);
                  }
                }
                else
@@ -3683,7 +3622,7 @@ ippReadIO(void       *src,                /* I - Data source */
        }
         break;
 
-    case IPP_DATA :
+    case IPP_STATE_DATA :
         break;
 
     default :
@@ -3706,13 +3645,13 @@ ippReadIO(void       *src,              /* I - Data source */
  * 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)@.
+ * @code ippGetCount(attr)@.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 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 */
@@ -3733,7 +3672,7 @@ ippSetBoolean(ipp_t           *ipp,       /* IO - IPP message */
   */
 
   if ((value = ipp_set_value(ipp, attr, element)) != NULL)
-    value->boolean = boolvalue;
+    value->boolean = (char)boolvalue;
 
   return (value != NULL);
 }
@@ -3748,14 +3687,14 @@ ippSetBoolean(ipp_t           *ipp,     /* IO - IPP message */
  * 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)@.
+ * @code ippGetCount(attr)@.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 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 */
@@ -3789,7 +3728,7 @@ ippSetCollection(
 
 
 /*
- * 'ippSetDate()' - Set a date value in an attribute.
+ * 'ippSetDate()' - Set a dateTime value in an attribute.
  *
  * The @code ipp@ parameter refers to an IPP message previously created using
  * the @link ippNew@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
@@ -3797,16 +3736,16 @@ ippSetCollection(
  * 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)@.
+ * @code ippGetCount(attr)@.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 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 */
+           const ipp_uchar_t *datevalue)/* I  - dateTime value */
 {
   _ipp_value_t *value;                 /* Current value */
 
@@ -3815,8 +3754,7 @@ ippSetDate(ipp_t             *ipp,        /* IO - IPP message */
   * Range check input...
   */
 
-  if (!ipp || !attr || !*attr || (*attr)->value_tag != IPP_TAG_DATE ||
-      element < 0 || element > (*attr)->num_values || !datevalue)
+  if (!ipp || !attr || !*attr || ((*attr)->value_tag != IPP_TAG_DATE && (*attr)->value_tag != IPP_TAG_NOVALUE && (*attr)->value_tag != IPP_TAG_UNKNOWN) || element < 0 || element > (*attr)->num_values || !datevalue)
     return (0);
 
  /*
@@ -3844,17 +3782,17 @@ 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/OS X 10.8@
+ * @since CUPS 1.6/macOS 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 */
 {
  /*
-  * Range check input - group tag must be 0x01 to 0x0F, per RFC 2911...
+  * Range check input - group tag must be 0x01 to 0x0F, per RFC 8011...
   */
 
   if (!ipp || !attr || !*attr ||
@@ -3881,13 +3819,13 @@ ippSetGroupTag(
  * 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)@.
+ * @code ippGetCount(attr)@.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 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 */
@@ -3899,9 +3837,7 @@ ippSetInteger(ipp_t           *ipp,       /* IO - IPP message */
   * Range check input...
   */
 
-  if (!ipp || !attr || !*attr ||
-      ((*attr)->value_tag != IPP_TAG_INTEGER && (*attr)->value_tag != IPP_TAG_ENUM) ||
-      element < 0 || element > (*attr)->num_values)
+  if (!ipp || !attr || !*attr || ((*attr)->value_tag != IPP_TAG_INTEGER && (*attr)->value_tag != IPP_TAG_ENUM && (*attr)->value_tag != IPP_TAG_NOVALUE && (*attr)->value_tag != IPP_TAG_UNKNOWN) || element < 0 || element > (*attr)->num_values)
     return (0);
 
  /*
@@ -3909,7 +3845,12 @@ ippSetInteger(ipp_t           *ipp,      /* IO - IPP message */
   */
 
   if ((value = ipp_set_value(ipp, attr, element)) != NULL)
+  {
+    if ((*attr)->value_tag != IPP_TAG_ENUM)
+      (*attr)->value_tag = IPP_TAG_INTEGER;
+
     value->integer = intvalue;
+  }
 
   return (value != NULL);
 }
@@ -3923,11 +3864,11 @@ ippSetInteger(ipp_t           *ipp,     /* IO - IPP message */
  *
  * The @code attr@ parameter may be modified as a result of setting the value.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 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 */
 {
@@ -3957,13 +3898,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
+ * @code ippGetCount(attr)@.
+ *
+ * @since CUPS 1.7/macOS 10.9@
+ */
+
+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 && (*attr)->value_tag != IPP_TAG_NOVALUE && (*attr)->value_tag != IPP_TAG_UNKNOWN) || 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...
+      */
+
+      (*attr)->value_tag = IPP_TAG_STRING;
+
+      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((size_t)datalen)) != NULL)
+       {
+         memcpy(temp, data, (size_t)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@, @link ippNewRequest@, or  @link ippNewResponse@ functions.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -3996,13 +4025,13 @@ ippSetOperation(ipp_t    *ipp,          /* I - IPP request message */
  * 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)@.
+ * @code ippGetCount(attr)@.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 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 */
@@ -4015,8 +4044,7 @@ ippSetRange(ipp_t           *ipp, /* IO - IPP message */
   * Range check input...
   */
 
-  if (!ipp || !attr || !*attr || (*attr)->value_tag != IPP_TAG_RANGE ||
-      element < 0 || element > (*attr)->num_values || lowervalue > uppervalue)
+  if (!ipp || !attr || !*attr || ((*attr)->value_tag != IPP_TAG_RANGE && (*attr)->value_tag != IPP_TAG_NOVALUE && (*attr)->value_tag != IPP_TAG_UNKNOWN) || element < 0 || element > (*attr)->num_values || lowervalue > uppervalue)
     return (0);
 
  /*
@@ -4025,6 +4053,7 @@ ippSetRange(ipp_t           *ipp, /* IO - IPP message */
 
   if ((value = ipp_set_value(ipp, attr, element)) != NULL)
   {
+    (*attr)->value_tag = IPP_TAG_RANGE;
     value->range.lower = lowervalue;
     value->range.upper = uppervalue;
   }
@@ -4041,7 +4070,7 @@ ippSetRange(ipp_t           *ipp, /* IO - IPP message */
  *
  * The @code request_id@ parameter must be greater than 0.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -4076,14 +4105,14 @@ ippSetRequestId(ipp_t *ipp,             /* I - IPP message */
  * 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)@.
+ * @code ippGetCount(attr)@.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 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 */
@@ -4097,9 +4126,7 @@ ippSetResolution(
   * Range check input...
   */
 
-  if (!ipp || !attr || !*attr || (*attr)->value_tag != IPP_TAG_RESOLUTION ||
-      element < 0 || element > (*attr)->num_values || xresvalue <= 0 || yresvalue <= 0 ||
-      unitsvalue < IPP_RES_PER_INCH || unitsvalue > IPP_RES_PER_CM)
+  if (!ipp || !attr || !*attr || ((*attr)->value_tag != IPP_TAG_RESOLUTION && (*attr)->value_tag != IPP_TAG_NOVALUE && (*attr)->value_tag != IPP_TAG_UNKNOWN) || element < 0 || element > (*attr)->num_values || xresvalue <= 0 || yresvalue <= 0 || unitsvalue < IPP_RES_PER_INCH || unitsvalue > IPP_RES_PER_CM)
     return (0);
 
  /*
@@ -4108,6 +4135,7 @@ ippSetResolution(
 
   if ((value = ipp_set_value(ipp, attr, element)) != NULL)
   {
+    (*attr)->value_tag      = IPP_TAG_RESOLUTION;
     value->resolution.units = unitsvalue;
     value->resolution.xres  = xresvalue;
     value->resolution.yres  = yresvalue;
@@ -4120,7 +4148,7 @@ ippSetResolution(
 /*
  * 'ippSetState()' - Set the current state of the IPP message.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -4151,7 +4179,7 @@ ippSetState(ipp_t       *ipp,             /* I - IPP message */
  * 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/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -4184,31 +4212,32 @@ ippSetStatusCode(ipp_t        *ipp,     /* I - IPP response or event message */
  * 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)@.
+ * @code ippGetCount(attr)@.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 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 */
 {
   char         *temp;                  /* Temporary string */
   _ipp_value_t *value;                 /* Current value */
+  ipp_tag_t    value_tag;              /* Value tag */
 
 
  /*
   * Range check input...
   */
 
-  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)
+  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_NOVALUE && value_tag != IPP_TAG_UNKNOWN) || value_tag > IPP_TAG_MIMETYPE || element < 0 || element > (*attr)->num_values || !strvalue)
     return (0);
 
  /*
@@ -4217,10 +4246,13 @@ ippSetString(ipp_t           *ipp,      /* IO - IPP message */
 
   if ((value = ipp_set_value(ipp, attr, element)) != NULL)
   {
+    if (value_tag == IPP_TAG_NOVALUE || value_tag == IPP_TAG_UNKNOWN)
+      (*attr)->value_tag = IPP_TAG_KEYWORD;
+
     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)
     {
@@ -4246,18 +4278,18 @@ ippSetString(ipp_t           *ipp,      /* IO - IPP message */
  * 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)@.
+ * @code 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@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
-ippSetStringf(ipp_t           *ipp,    /* IO - IPP message */
+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 */
@@ -4284,18 +4316,18 @@ ippSetStringf(ipp_t           *ipp,     /* IO - IPP message */
  * 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)@.
+ * @code 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@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
-ippSetStringfv(ipp_t           *ipp,   /* IO - IPP message */
+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 */
@@ -4317,10 +4349,7 @@ ippSetStringfv(ipp_t           *ipp,     /* IO - IPP message */
   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)
+  if (!ipp || !attr || !*attr || (value_tag < IPP_TAG_TEXT && value_tag != IPP_TAG_TEXTLANG && value_tag != IPP_TAG_NAMELANG && value_tag != IPP_TAG_NOVALUE && value_tag != IPP_TAG_UNKNOWN) || value_tag > IPP_TAG_MIMETYPE || !format)
     return (0);
 
  /*
@@ -4338,7 +4367,7 @@ ippSetStringfv(ipp_t           *ipp,      /* IO - IPP message */
     if (!s)
       s = "(null)";
 
-    bytes = strlen(s);
+    bytes = (ssize_t)strlen(s);
     strlcpy(buffer, s, sizeof(buffer));
   }
   else
@@ -4372,6 +4401,8 @@ ippSetStringfv(ipp_t           *ipp,      /* IO - IPP message */
         max_bytes = IPP_MAX_CHARSET;
         break;
 
+    case IPP_TAG_NOVALUE :
+    case IPP_TAG_UNKNOWN :
     case IPP_TAG_KEYWORD :
         max_bytes = IPP_MAX_KEYWORD;
         break;
@@ -4443,12 +4474,12 @@ ippSetStringfv(ipp_t           *ipp,    /* IO - IPP message */
  * 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@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int                                    /* O  - 1 on success, 0 on failure */
 ippSetValueTag(
-    ipp_t          *ipp,               /* IO - IPP message */
+    ipp_t          *ipp,               /* I  - IPP message */
     ipp_attribute_t **attr,            /* IO - IPP attribute */
     ipp_tag_t       value_tag)         /* I  - Value tag */
 {
@@ -4478,7 +4509,7 @@ ippSetValueTag(
   * Otherwise implement changes as needed...
   */
 
-  temp_tag = (ipp_tag_t)((int)((*attr)->value_tag) & IPP_TAG_MASK);
+  temp_tag = (ipp_tag_t)((int)((*attr)->value_tag) & IPP_TAG_CUPS_MASK);
 
   switch (value_tag)
   {
@@ -4519,27 +4550,22 @@ ippSetValueTag(
         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)
+        if (temp_tag != IPP_TAG_KEYWORD)
           return (0);
 
-        (*attr)->value_tag = (ipp_tag_t)(IPP_TAG_NAME | ((*attr)->value_tag & IPP_TAG_COPY));
+        (*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))
+        if (value_tag == IPP_TAG_NAMELANG && (temp_tag != IPP_TAG_NAME && temp_tag != IPP_TAG_KEYWORD))
           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"))
+            !strcmp(ipp->attrs->next->name, "attributes-natural-language") && (ipp->attrs->next->value_tag & IPP_TAG_CUPS_MASK) == IPP_TAG_LANGUAGE)
         {
          /*
           * Use the language code from the IPP message...
@@ -4565,7 +4591,7 @@ ippSetValueTag(
              i --, value ++)
           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)
         {
          /*
           * Make copies of all values...
@@ -4600,7 +4626,7 @@ ippSetValueTag(
  *
  * 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@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -4619,27 +4645,27 @@ ippSetVersion(ipp_t *ipp,               /* I - IPP message */
   * Set the version number...
   */
 
-  ipp->request.any.version[0] = major;
-  ipp->request.any.version[1] = minor;
+  ipp->request.any.version[0] = (ipp_uchar_t)major;
+  ipp->request.any.version[1] = (ipp_uchar_t)minor;
 
   return (1);
 }
 
 
 /*
- * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
+ * 'ippTimeToDate()' - Convert from time in seconds to RFC 2579 format.
  */
 
-const ipp_uchar_t *                    /* O - RFC-1903 date/time data */
-ippTimeToDate(time_t t)                        /* I - UNIX time value */
+const ipp_uchar_t *                    /* O - RFC-2579 date/time data */
+ippTimeToDate(time_t t)                        /* I - Time in seconds */
 {
-  struct tm    *unixdate;              /* UNIX unixdate/time info */
+  struct tm    unixdate;               /* UNIX unixdate/time info */
   ipp_uchar_t  *date = _cupsGlobals()->ipp_date;
-                                       /* RFC-1903 date/time data */
+                                       /* RFC-2579 date/time data */
 
 
  /*
-  * RFC-1903 date/time format is:
+  * RFC-2579 date/time format is:
   *
   *    Byte(s)  Description
   *    -------  -----------
@@ -4655,16 +4681,16 @@ ippTimeToDate(time_t t)                 /* I - UNIX time value */
   *    10       UTC minutes (0 to 59)
   */
 
-  unixdate = gmtime(&t);
-  unixdate->tm_year += 1900;
+  gmtime_r(&t, &unixdate);
+  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[0]  = (ipp_uchar_t)(unixdate.tm_year >> 8);
+  date[1]  = (ipp_uchar_t)(unixdate.tm_year);
+  date[2]  = (ipp_uchar_t)(unixdate.tm_mon + 1);
+  date[3]  = (ipp_uchar_t)unixdate.tm_mday;
+  date[4]  = (ipp_uchar_t)unixdate.tm_hour;
+  date[5]  = (ipp_uchar_t)unixdate.tm_min;
+  date[6]  = (ipp_uchar_t)unixdate.tm_sec;
   date[7]  = 0;
   date[8]  = '+';
   date[9]  = 0;
@@ -4679,9 +4705,9 @@ ippTimeToDate(time_t t)                   /* I - UNIX time value */
  *
  * 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.
+ * failure, @link cupsLastErrorString@ is set to a human-readable message.
  *
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 int                                    /* O - 1 if valid, 0 otherwise */
@@ -4699,21 +4725,6 @@ ippValidateAttribute(
   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"
-  };
 
 
  /*
@@ -4733,18 +4744,13 @@ ippValidateAttribute(
 
   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);
+    ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad attribute name - invalid character (RFC 8011 section 5.1.4)."), 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));
+    ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad attribute name - bad length %d (RFC 8011 section 5.1.4)."), attr->name, (int)(ptr - attr->name));
     return (0);
   }
 
@@ -4759,10 +4765,7 @@ ippValidateAttribute(
          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);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad boolean value %d (RFC 8011 section 5.1.21)."), attr->name, attr->values[i].boolean);
            return (0);
          }
        }
@@ -4773,10 +4776,7 @@ ippValidateAttribute(
        {
          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);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad enum value %d - out of range (RFC 8011 section 5.1.5)."), attr->name, attr->values[i].integer);
             return (0);
          }
        }
@@ -4787,10 +4787,7 @@ ippValidateAttribute(
        {
          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);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad octetString value - bad length %d (RFC 8011 section 5.1.20)."), attr->name, attr->values[i].unknown.length);
            return (0);
          }
        }
@@ -4803,73 +4800,55 @@ ippValidateAttribute(
 
           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]);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad dateTime month %u (RFC 8011 section 5.1.15)."), 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]);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad dateTime day %u (RFC 8011 section 5.1.15)."), 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]);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad dateTime hours %u (RFC 8011 section 5.1.15)."), 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]);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad dateTime minutes %u (RFC 8011 section 5.1.15)."), 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]);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad dateTime seconds %u (RFC 8011 section 5.1.15)."), 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]);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad dateTime deciseconds %u (RFC 8011 section 5.1.15)."), 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]);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad dateTime UTC sign '%c' (RFC 8011 section 5.1.15)."), 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]);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad dateTime UTC hours %u (RFC 8011 section 5.1.15)."), 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]);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad dateTime UTC minutes %u (RFC 8011 section 5.1.15)."), attr->name, date[10]);
            return (0);
          }
        }
@@ -4880,46 +4859,19 @@ ippValidateAttribute(
        {
          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");
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad resolution value %dx%d%s - cross feed resolution must be positive (RFC 8011 section 5.1.16)."), 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");
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad resolution value %dx%d%s - feed resolution must be positive (RFC 8011 section 5.1.16)."), 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)
+         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");
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad resolution value %dx%d%s - bad units value (RFC 8011 section 5.1.16)."), 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);
          }
        }
@@ -4930,11 +4882,7 @@ ippValidateAttribute(
        {
          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);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad rangeOfInteger value %d-%d - lower greater than upper (RFC 8011 section 5.1.14)."), attr->name, attr->values[i].range.lower, attr->values[i].range.upper);
            return (0);
          }
        }
@@ -4961,51 +4909,48 @@ ippValidateAttribute(
          {
            if ((*ptr & 0xe0) == 0xc0)
            {
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
+             if ((ptr[1] & 0xc0) != 0x80)
                break;
+
+             ptr ++;
            }
            else if ((*ptr & 0xf0) == 0xe0)
            {
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
-               break;
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
+             if ((ptr[1] & 0xc0) != 0x80 || (ptr[2] & 0xc0) != 0x80)
                break;
+
+             ptr += 2;
            }
            else if ((*ptr & 0xf8) == 0xf0)
            {
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
-               break;
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
-               break;
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
+             if ((ptr[1] & 0xc0) != 0x80 || (ptr[2] & 0xc0) != 0x80 || (ptr[3] & 0xc0) != 0x80)
                break;
+
+             ptr += 3;
            }
            else if (*ptr & 0x80)
              break;
+           else if ((*ptr < ' ' && *ptr != '\n' && *ptr != '\r' && *ptr != '\t') || *ptr == 0x7f)
+             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)
+          {
+           if (*ptr < ' ' || *ptr == 0x7f)
+           {
+             ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad text value \"%s\" - bad control character (PWG 5100.14 section 8.3)."), attr->name, attr->values[i].string.text);
+             return (0);
+           }
+           else
+           {
+             ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad text value \"%s\" - bad UTF-8 sequence (RFC 8011 section 5.1.2)."), 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));
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad text value \"%s\" - bad length %d (RFC 8011 section 5.1.2)."), attr->name, attr->values[i].string.text, (int)(ptr - attr->values[i].string.text));
            return (0);
          }
        }
@@ -5019,51 +4964,48 @@ ippValidateAttribute(
          {
            if ((*ptr & 0xe0) == 0xc0)
            {
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
+             if ((ptr[1] & 0xc0) != 0x80)
                break;
+
+             ptr ++;
            }
            else if ((*ptr & 0xf0) == 0xe0)
            {
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
-               break;
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
+             if ((ptr[1] & 0xc0) != 0x80 || (ptr[2] & 0xc0) != 0x80)
                break;
+
+             ptr += 2;
            }
            else if ((*ptr & 0xf8) == 0xf0)
            {
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
-               break;
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
-               break;
-             ptr ++;
-             if ((*ptr & 0xc0) != 0x80)
+             if ((ptr[1] & 0xc0) != 0x80 || (ptr[2] & 0xc0) != 0x80 || (ptr[3] & 0xc0) != 0x80)
                break;
+
+             ptr += 3;
            }
            else if (*ptr & 0x80)
              break;
+           else if (*ptr < ' ' || *ptr == 0x7f)
+             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 < ' ' || *ptr == 0x7f)
+           {
+             ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad name value \"%s\" - bad control character (PWG 5100.14 section 8.1)."), attr->name, attr->values[i].string.text);
+             return (0);
+           }
+           else
+           {
+             ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad name value \"%s\" - bad UTF-8 sequence (RFC 8011 section 5.1.3)."), 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));
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad name value \"%s\" - bad length %d (RFC 8011 section 5.1.3)."), attr->name, attr->values[i].string.text, (int)(ptr - attr->values[i].string.text));
            return (0);
          }
        }
@@ -5073,26 +5015,21 @@ ippValidateAttribute(
         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 (*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);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad keyword value \"%s\" - invalid character (RFC 8011 section 5.1.4)."), attr->name, attr->values[i].string.text);
            return (0);
          }
 
          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));
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad keyword value \"%s\" - bad length %d (RFC 8011 section 5.1.4)."), attr->name, attr->values[i].string.text, (int)(ptr - attr->values[i].string.text));
            return (0);
          }
        }
@@ -5101,31 +5038,17 @@ ippValidateAttribute(
     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_OK)
+         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_OVERFLOW]);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad URI value \"%s\" - %s (RFC 8011 section 5.1.6)."), attr->name, attr->values[i].string.text, httpURIStatusString(uri_status));
            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));
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad URI value \"%s\" - bad length %d (RFC 8011 section 5.1.6)."), attr->name, attr->values[i].string.text, (int)strlen(attr->values[i].string.text));
          }
        }
         break;
@@ -5137,27 +5060,22 @@ ippValidateAttribute(
          if (islower(*ptr & 255))
          {
            for (ptr ++; *ptr; ptr ++)
+           {
              if (!islower(*ptr & 255) && !isdigit(*ptr & 255) &&
                  *ptr != '+' && *ptr != '-' && *ptr != '.')
                 break;
+           }
          }
 
          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);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad uriScheme value \"%s\" - bad characters (RFC 8011 section 5.1.7)."), attr->name, attr->values[i].string.text);
            return (0);
          }
 
          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));
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad uriScheme value \"%s\" - bad length %d (RFC 8011 section 5.1.7)."), attr->name, attr->values[i].string.text, (int)(ptr - attr->values[i].string.text));
            return (0);
          }
        }
@@ -5167,26 +5085,21 @@ ippValidateAttribute(
         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;
+         }
 
          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);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad charset value \"%s\" - bad characters (RFC 8011 section 5.1.8)."), attr->name, attr->values[i].string.text);
            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));
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad charset value \"%s\" - bad length %d (RFC 8011 section 5.1.8)."), attr->name, attr->values[i].string.text, (int)(ptr - attr->values[i].string.text));
            return (0);
          }
        }
@@ -5218,9 +5131,7 @@ ippValidateAttribute(
           char temp[256];              /* Temporary error string */
 
           regerror(i, &re, temp, sizeof(temp));
-         ipp_set_error(IPP_STATUS_ERROR_INTERNAL,
-                       _("Unable to compile naturalLanguage regular "
-                         "expression: %s."), temp);
+         ipp_set_error(IPP_STATUS_ERROR_INTERNAL, _("Unable to compile naturalLanguage regular expression: %s."), temp);
          return (0);
         }
 
@@ -5228,21 +5139,14 @@ ippValidateAttribute(
        {
          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);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad naturalLanguage value \"%s\" - bad characters (RFC 8011 section 5.1.9)."), attr->name, attr->values[i].string.text);
            regfree(&re);
            return (0);
          }
 
          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));
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad naturalLanguage value \"%s\" - bad length %d (RFC 8011 section 5.1.9)."), attr->name, attr->values[i].string.text, (int)strlen(attr->values[i].string.text));
            regfree(&re);
            return (0);
          }
@@ -5272,9 +5176,7 @@ ippValidateAttribute(
           char temp[256];              /* Temporary error string */
 
           regerror(i, &re, temp, sizeof(temp));
-         ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST,
-                       _("Unable to compile mimeMediaType regular "
-                         "expression: %s."), temp);
+         ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("Unable to compile mimeMediaType regular expression: %s."), temp);
          return (0);
         }
 
@@ -5282,21 +5184,14 @@ ippValidateAttribute(
        {
          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);
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad mimeMediaType value \"%s\" - bad characters (RFC 8011 section 5.1.10)."), attr->name, attr->values[i].string.text);
            regfree(&re);
            return (0);
          }
 
          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));
+           ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad mimeMediaType value \"%s\" - bad length %d (RFC 8011 section 5.1.10)."), attr->name, attr->values[i].string.text, (int)strlen(attr->values[i].string.text));
            regfree(&re);
            return (0);
          }
@@ -5317,10 +5212,10 @@ ippValidateAttribute(
  * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
  *
  * 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.
+ * attribute.  Like @link ippValidateAttribute@, @link cupsLastErrorString@ is
+ * set to a human-readable message on failure.
  *
- * @since CUPS 1.7@
+ * @since CUPS 1.7/macOS 10.9@
  */
 
 int                                    /* O - 1 if valid, 0 otherwise */
@@ -5348,10 +5243,10 @@ ipp_state_t                             /* O - Current state */
 ippWrite(http_t *http,                 /* I - HTTP connection */
          ipp_t  *ipp)                  /* I - IPP data */
 {
-  DEBUG_printf(("ippWrite(http=%p, ipp=%p)", http, ipp));
+  DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http, (void *)ipp));
 
   if (!http)
-    return (IPP_ERROR);
+    return (IPP_STATE_ERROR);
 
   return (ippWriteIO(http, (ipp_iocb_t)httpWrite2, http->blocking, NULL, ipp));
 }
@@ -5360,16 +5255,16 @@ ippWrite(http_t *http,                  /* I - HTTP connection */
 /*
  * 'ippWriteFile()' - Write data for an IPP message to a file.
  *
- * @since CUPS 1.1.19/OS X 10.3@
+ * @since CUPS 1.1.19/macOS 10.3@
  */
 
 ipp_state_t                            /* O - Current state */
 ippWriteFile(int   fd,                 /* I - HTTP data */
              ipp_t *ipp)               /* I - IPP data */
 {
-  DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd, ipp));
+  DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd, (void *)ipp));
 
-  ipp->state = IPP_IDLE;
+  ipp->state = IPP_STATE_IDLE;
 
   return (ippWriteIO(&fd, (ipp_iocb_t)ipp_write_file, 1, NULL, ipp));
 }
@@ -5378,7 +5273,7 @@ ippWriteFile(int   fd,                    /* I - HTTP data */
 /*
  * 'ippWriteIO()' - Write data for an IPP message.
  *
- * @since CUPS 1.2/OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 ipp_state_t                            /* O - Current state */
@@ -5396,24 +5291,23 @@ ippWriteIO(void       *dst,             /* I - Destination */
   _ipp_value_t         *value;         /* Current value */
 
 
-  DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)",
-                dst, cb, blocking, parent, ipp));
+  DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst, (void *)cb, blocking, (void *)parent, (void *)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)
        {
         /*
@@ -5429,12 +5323,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
          *bufptr++ = ipp->request.any.version[0];
          *bufptr++ = ipp->request.any.version[1];
-         *bufptr++ = ipp->request.any.op_status >> 8;
-         *bufptr++ = ipp->request.any.op_status;
-         *bufptr++ = ipp->request.any.request_id >> 24;
-         *bufptr++ = ipp->request.any.request_id >> 16;
-         *bufptr++ = ipp->request.any.request_id >> 8;
-         *bufptr++ = ipp->request.any.request_id;
+         *bufptr++ = (ipp_uchar_t)(ipp->request.any.op_status >> 8);
+         *bufptr++ = (ipp_uchar_t)ipp->request.any.op_status;
+         *bufptr++ = (ipp_uchar_t)(ipp->request.any.request_id >> 24);
+         *bufptr++ = (ipp_uchar_t)(ipp->request.any.request_id >> 16);
+         *bufptr++ = (ipp_uchar_t)(ipp->request.any.request_id >> 8);
+         *bufptr++ = (ipp_uchar_t)ipp->request.any.request_id;
 
          DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer[0], buffer[1]));
          DEBUG_printf(("2ippWriteIO: op_status=%04x",
@@ -5442,11 +5336,11 @@ ippWriteIO(void       *dst,             /* I - Destination */
          DEBUG_printf(("2ippWriteIO: request_id=%d",
                        ipp->request.any.request_id));
 
-          if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+          if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
          {
            DEBUG_puts("1ippWriteIO: Could not write IPP header...");
            _cupsBufferRelease((char *)buffer);
-           return (IPP_ERROR);
+           return (IPP_STATE_ERROR);
          }
        }
 
@@ -5455,11 +5349,11 @@ 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;
 
-       DEBUG_printf(("1ippWriteIO: ipp->current=%p", ipp->current));
+       DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp->current));
 
        /*
         * If blocking is disabled, stop here...
@@ -5468,7 +5362,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
         if (!blocking)
          break;
 
-    case IPP_ATTRIBUTE :
+    case IPP_STATE_ATTRIBUTE :
         while (ipp->current != NULL)
        {
         /*
@@ -5495,7 +5389,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
 
              DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
                            attr->group_tag, ippTagString(attr->group_tag)));
-             *bufptr++ = attr->group_tag;
+             *bufptr++ = (ipp_uchar_t)attr->group_tag;
            }
            else if (attr->group_tag == IPP_TAG_ZERO)
              continue;
@@ -5525,7 +5419,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);
            }
 
            /*
@@ -5540,17 +5434,17 @@ ippWriteIO(void       *dst,             /* I - Destination */
             if (attr->value_tag > 0xff)
             {
               *bufptr++ = IPP_TAG_EXTENSION;
-             *bufptr++ = attr->value_tag >> 24;
-             *bufptr++ = attr->value_tag >> 16;
-             *bufptr++ = attr->value_tag >> 8;
-             *bufptr++ = attr->value_tag;
+             *bufptr++ = (ipp_uchar_t)(attr->value_tag >> 24);
+             *bufptr++ = (ipp_uchar_t)(attr->value_tag >> 16);
+             *bufptr++ = (ipp_uchar_t)(attr->value_tag >> 8);
+             *bufptr++ = (ipp_uchar_t)attr->value_tag;
             }
             else
-             *bufptr++ = attr->value_tag;
+             *bufptr++ = (ipp_uchar_t)attr->value_tag;
 
-           *bufptr++ = n >> 8;
-           *bufptr++ = n;
-           memcpy(bufptr, attr->name, n);
+           *bufptr++ = (ipp_uchar_t)(n >> 8);
+           *bufptr++ = (ipp_uchar_t)n;
+           memcpy(bufptr, attr->name, (size_t)n);
            bufptr += n;
           }
          else
@@ -5564,7 +5458,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);
            }
 
            /*
@@ -5583,21 +5477,21 @@ ippWriteIO(void       *dst,             /* I - Destination */
             *bufptr++ = IPP_TAG_MEMBERNAME;
            *bufptr++ = 0;
            *bufptr++ = 0;
-           *bufptr++ = n >> 8;
-           *bufptr++ = n;
-           memcpy(bufptr, attr->name, n);
+           *bufptr++ = (ipp_uchar_t)(n >> 8);
+           *bufptr++ = (ipp_uchar_t)n;
+           memcpy(bufptr, attr->name, (size_t)n);
            bufptr += n;
 
             if (attr->value_tag > 0xff)
             {
               *bufptr++ = IPP_TAG_EXTENSION;
-             *bufptr++ = attr->value_tag >> 24;
-             *bufptr++ = attr->value_tag >> 16;
-             *bufptr++ = attr->value_tag >> 8;
-             *bufptr++ = attr->value_tag;
+             *bufptr++ = (ipp_uchar_t)(attr->value_tag >> 24);
+             *bufptr++ = (ipp_uchar_t)(attr->value_tag >> 16);
+             *bufptr++ = (ipp_uchar_t)(attr->value_tag >> 8);
+             *bufptr++ = (ipp_uchar_t)attr->value_tag;
             }
             else
-             *bufptr++ = attr->value_tag;
+             *bufptr++ = (ipp_uchar_t)attr->value_tag;
 
             *bufptr++ = 0;
             *bufptr++ = 0;
@@ -5607,7 +5501,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 :
@@ -5628,12 +5522,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
                {
                   if ((IPP_BUF_SIZE - (bufptr - buffer)) < 9)
                  {
-                    if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                    if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                    {
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -5646,7 +5540,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    * values with a zero-length name...
                    */
 
-                    *bufptr++ = attr->value_tag;
+                    *bufptr++ = (ipp_uchar_t)attr->value_tag;
                    *bufptr++ = 0;
                    *bufptr++ = 0;
                  }
@@ -5660,10 +5554,10 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
                  *bufptr++ = 0;
                  *bufptr++ = 4;
-                 *bufptr++ = value->integer >> 24;
-                 *bufptr++ = value->integer >> 16;
-                 *bufptr++ = value->integer >> 8;
-                 *bufptr++ = value->integer;
+                 *bufptr++ = (ipp_uchar_t)(value->integer >> 24);
+                 *bufptr++ = (ipp_uchar_t)(value->integer >> 16);
+                 *bufptr++ = (ipp_uchar_t)(value->integer >> 8);
+                 *bufptr++ = (ipp_uchar_t)value->integer;
                }
                break;
 
@@ -5674,12 +5568,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
                {
                   if ((IPP_BUF_SIZE - (bufptr - buffer)) < 6)
                  {
-                    if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                    if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                    {
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -5692,7 +5586,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    * values with a zero-length name...
                    */
 
-                    *bufptr++ = attr->value_tag;
+                    *bufptr++ = (ipp_uchar_t)attr->value_tag;
                    *bufptr++ = 0;
                    *bufptr++ = 0;
                  }
@@ -5705,7 +5599,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
 
                  *bufptr++ = 0;
                  *bufptr++ = 1;
-                 *bufptr++ = value->boolean;
+                 *bufptr++ = (ipp_uchar_t)value->boolean;
                }
                break;
 
@@ -5735,18 +5629,18 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
                     if ((IPP_BUF_SIZE - (bufptr - buffer)) < 3)
                    {
-                      if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                      if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                      {
                        DEBUG_puts("1ippWriteIO: Could not write IPP "
                                   "attribute...");
                        _cupsBufferRelease((char *)buffer);
-                       return (IPP_ERROR);
+                       return (IPP_STATE_ERROR);
                      }
 
                      bufptr = buffer;
                    }
 
-                    *bufptr++ = attr->value_tag;
+                    *bufptr++ = (ipp_uchar_t)attr->value_tag;
                    *bufptr++ = 0;
                    *bufptr++ = 0;
                  }
@@ -5760,7 +5654,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,
@@ -5768,12 +5662,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
                   if ((int)(IPP_BUF_SIZE - (bufptr - buffer)) < (n + 2))
                  {
-                    if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                    if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                    {
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -5789,12 +5683,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
                  * Put the 2-byte length and string characters in the buffer.
                  */
 
-                 *bufptr++ = n >> 8;
-                 *bufptr++ = n;
+                 *bufptr++ = (ipp_uchar_t)(n >> 8);
+                 *bufptr++ = (ipp_uchar_t)n;
 
                  if (n > 0)
                  {
-                   memcpy(bufptr, value->string.text, n);
+                   memcpy(bufptr, value->string.text, (size_t)n);
                    bufptr += n;
                  }
                }
@@ -5807,12 +5701,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
                {
                   if ((IPP_BUF_SIZE - (bufptr - buffer)) < 16)
                  {
-                    if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                    if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                    {
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -5825,7 +5719,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    * values with a zero-length name...
                    */
 
-                    *bufptr++ = attr->value_tag;
+                    *bufptr++ = (ipp_uchar_t)attr->value_tag;
                    *bufptr++ = 0;
                    *bufptr++ = 0;
                  }
@@ -5852,12 +5746,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
                {
                   if ((IPP_BUF_SIZE - (bufptr - buffer)) < 14)
                  {
-                    if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                    if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                    {
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -5870,7 +5764,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    * values with a zero-length name...
                    */
 
-                    *bufptr++ = attr->value_tag;
+                    *bufptr++ = (ipp_uchar_t)attr->value_tag;
                    *bufptr++ = 0;
                    *bufptr++ = 0;
                  }
@@ -5886,15 +5780,15 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
                  *bufptr++ = 0;
                  *bufptr++ = 9;
-                 *bufptr++ = value->resolution.xres >> 24;
-                 *bufptr++ = value->resolution.xres >> 16;
-                 *bufptr++ = value->resolution.xres >> 8;
-                 *bufptr++ = value->resolution.xres;
-                 *bufptr++ = value->resolution.yres >> 24;
-                 *bufptr++ = value->resolution.yres >> 16;
-                 *bufptr++ = value->resolution.yres >> 8;
-                 *bufptr++ = value->resolution.yres;
-                 *bufptr++ = value->resolution.units;
+                 *bufptr++ = (ipp_uchar_t)(value->resolution.xres >> 24);
+                 *bufptr++ = (ipp_uchar_t)(value->resolution.xres >> 16);
+                 *bufptr++ = (ipp_uchar_t)(value->resolution.xres >> 8);
+                 *bufptr++ = (ipp_uchar_t)value->resolution.xres;
+                 *bufptr++ = (ipp_uchar_t)(value->resolution.yres >> 24);
+                 *bufptr++ = (ipp_uchar_t)(value->resolution.yres >> 16);
+                 *bufptr++ = (ipp_uchar_t)(value->resolution.yres >> 8);
+                 *bufptr++ = (ipp_uchar_t)value->resolution.yres;
+                 *bufptr++ = (ipp_uchar_t)value->resolution.units;
                }
                break;
 
@@ -5905,12 +5799,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
                {
                   if ((IPP_BUF_SIZE - (bufptr - buffer)) < 13)
                  {
-                    if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                    if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                    {
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -5923,7 +5817,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    * values with a zero-length name...
                    */
 
-                    *bufptr++ = attr->value_tag;
+                    *bufptr++ = (ipp_uchar_t)attr->value_tag;
                    *bufptr++ = 0;
                    *bufptr++ = 0;
                  }
@@ -5938,14 +5832,14 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
                  *bufptr++ = 0;
                  *bufptr++ = 8;
-                 *bufptr++ = value->range.lower >> 24;
-                 *bufptr++ = value->range.lower >> 16;
-                 *bufptr++ = value->range.lower >> 8;
-                 *bufptr++ = value->range.lower;
-                 *bufptr++ = value->range.upper >> 24;
-                 *bufptr++ = value->range.upper >> 16;
-                 *bufptr++ = value->range.upper >> 8;
-                 *bufptr++ = value->range.upper;
+                 *bufptr++ = (ipp_uchar_t)(value->range.lower >> 24);
+                 *bufptr++ = (ipp_uchar_t)(value->range.lower >> 16);
+                 *bufptr++ = (ipp_uchar_t)(value->range.lower >> 8);
+                 *bufptr++ = (ipp_uchar_t)value->range.lower;
+                 *bufptr++ = (ipp_uchar_t)(value->range.upper >> 24);
+                 *bufptr++ = (ipp_uchar_t)(value->range.upper >> 16);
+                 *bufptr++ = (ipp_uchar_t)(value->range.upper >> 8);
+                 *bufptr++ = (ipp_uchar_t)value->range.upper;
                }
                break;
 
@@ -5964,18 +5858,18 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
                     if ((IPP_BUF_SIZE - (bufptr - buffer)) < 3)
                    {
-                      if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                      if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                      {
                        DEBUG_puts("1ippWriteIO: Could not write IPP "
                                   "attribute...");
                        _cupsBufferRelease((char *)buffer);
-                       return (IPP_ERROR);
+                       return (IPP_STATE_ERROR);
                      }
 
                      bufptr = buffer;
                    }
 
-                    *bufptr++ = attr->value_tag;
+                    *bufptr++ = (ipp_uchar_t)attr->value_tag;
                    *bufptr++ = 0;
                    *bufptr++ = 0;
                  }
@@ -6003,25 +5897,25 @@ 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))
                  {
-                    if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                    if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                    {
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
                  }
 
                  /* Length of entire value */
-                 *bufptr++ = n >> 8;
-                 *bufptr++ = n;
+                 *bufptr++ = (ipp_uchar_t)(n >> 8);
+                 *bufptr++ = (ipp_uchar_t)n;
 
                  /* Length of language */
                  if (value->string.language != NULL)
@@ -6029,13 +5923,13 @@ ippWriteIO(void       *dst,             /* I - Destination */
                  else
                    n = 0;
 
-                 *bufptr++ = n >> 8;
-                 *bufptr++ = n;
+                 *bufptr++ = (ipp_uchar_t)(n >> 8);
+                 *bufptr++ = (ipp_uchar_t)n;
 
                  /* Language */
                  if (n > 0)
                  {
-                   memcpy(bufptr, value->string.language, n);
+                   memcpy(bufptr, value->string.language, (size_t)n);
                    bufptr += n;
                  }
 
@@ -6045,13 +5939,13 @@ ippWriteIO(void       *dst,             /* I - Destination */
                  else
                    n = 0;
 
-                 *bufptr++ = n >> 8;
-                 *bufptr++ = n;
+                 *bufptr++ = (ipp_uchar_t)(n >> 8);
+                 *bufptr++ = (ipp_uchar_t)n;
 
                  /* Text */
                  if (n > 0)
                  {
-                   memcpy(bufptr, value->string.text, n);
+                   memcpy(bufptr, value->string.text, (size_t)n);
                    bufptr += n;
                  }
                }
@@ -6071,12 +5965,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
                   if ((IPP_BUF_SIZE - (bufptr - buffer)) < 5)
                  {
-                    if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                    if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                    {
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
@@ -6089,7 +5983,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    * values with a zero-length name...
                    */
 
-                    *bufptr++ = attr->value_tag;
+                    *bufptr++ = (ipp_uchar_t)attr->value_tag;
                    *bufptr++ = 0;
                    *bufptr++ = 0;
                  }
@@ -6101,12 +5995,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
                  *bufptr++ = 0;
                  *bufptr++ = 0;
 
-                  if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                  if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                  {
                    DEBUG_puts("1ippWriteIO: Could not write IPP "
                               "attribute...");
                    _cupsBufferRelease((char *)buffer);
-                   return (IPP_ERROR);
+                   return (IPP_STATE_ERROR);
                  }
 
                  bufptr = buffer;
@@ -6115,14 +6009,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;
@@ -6141,18 +6035,18 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
                     if ((IPP_BUF_SIZE - (bufptr - buffer)) < 3)
                    {
-                      if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                      if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                      {
                        DEBUG_puts("1ippWriteIO: Could not write IPP "
                                   "attribute...");
                        _cupsBufferRelease((char *)buffer);
-                       return (IPP_ERROR);
+                       return (IPP_STATE_ERROR);
                      }
 
                      bufptr = buffer;
                    }
 
-                    *bufptr++ = attr->value_tag;
+                    *bufptr++ = (ipp_uchar_t)attr->value_tag;
                    *bufptr++ = 0;
                    *bufptr++ = 0;
                  }
@@ -6171,30 +6065,30 @@ 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))
                  {
-                    if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+                    if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
                    {
                      DEBUG_puts("1ippWriteIO: Could not write IPP "
                                 "attribute...");
                      _cupsBufferRelease((char *)buffer);
-                     return (IPP_ERROR);
+                     return (IPP_STATE_ERROR);
                    }
 
                    bufptr = buffer;
                  }
 
                  /* Length of unknown value */
-                 *bufptr++ = n >> 8;
-                 *bufptr++ = n;
+                 *bufptr++ = (ipp_uchar_t)(n >> 8);
+                 *bufptr++ = (ipp_uchar_t)n;
 
                  /* Value */
                  if (n > 0)
                  {
-                   memcpy(bufptr, value->unknown.data, n);
+                   memcpy(bufptr, value->unknown.data, (size_t)n);
                    bufptr += n;
                  }
                }
@@ -6207,11 +6101,11 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
          if (bufptr > buffer)
          {
-           if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
+           if ((*cb)(dst, buffer, (size_t)(bufptr - buffer)) < 0)
            {
              DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
              _cupsBufferRelease((char *)buffer);
-             return (IPP_ERROR);
+             return (IPP_STATE_ERROR);
            }
 
            DEBUG_printf(("2ippWriteIO: wrote %d bytes",
@@ -6219,10 +6113,11 @@ ippWriteIO(void       *dst,             /* I - Destination */
          }
 
         /*
-          * If blocking is disabled, stop here...
+          * If blocking is disabled and we aren't at the end of the attribute
+          * list, stop here...
          */
 
-          if (!blocking)
+          if (!blocking && ipp->current)
            break;
        }
 
@@ -6248,18 +6143,18 @@ ippWriteIO(void       *dst,             /* I - Destination */
            n         = 5;
          }
 
-         if ((*cb)(dst, buffer, n) < 0)
+         if ((*cb)(dst, buffer, (size_t)n) < 0)
          {
            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 :
@@ -6287,8 +6182,7 @@ ipp_add_attr(ipp_t      *ipp,             /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("4ipp_add_attr(ipp=%p, name=\"%s\", group_tag=0x%x, value_tag=0x%x, "
-                "num_values=%d)", ipp, name, group_tag, value_tag, num_values));
+  DEBUG_printf(("4ipp_add_attr(ipp=%p, name=\"%s\", group_tag=0x%x, value_tag=0x%x, num_values=%d)", (void *)ipp, name, group_tag, value_tag, num_values));
 
  /*
   * Range check input...
@@ -6307,7 +6201,7 @@ ipp_add_attr(ipp_t      *ipp,             /* I - IPP message */
     alloc_values = (num_values + IPP_MAX_VALUES - 1) & ~(IPP_MAX_VALUES - 1);
 
   attr = calloc(sizeof(ipp_attribute_t) +
-                (alloc_values - 1) * sizeof(_ipp_value_t), 1);
+                (size_t)(alloc_values - 1) * sizeof(_ipp_value_t), 1);
 
   if (attr)
   {
@@ -6315,6 +6209,8 @@ ipp_add_attr(ipp_t      *ipp,             /* I - IPP message */
     * Initialize attribute...
     */
 
+    DEBUG_printf(("4debug_alloc: %p %s %s%s (%d values)", (void *)attr, name, num_values > 1 ? "1setOf " : "", ippTagString(value_tag), num_values));
+
     if (name)
       attr->name = _cupsStrAlloc(name);
 
@@ -6335,7 +6231,7 @@ ipp_add_attr(ipp_t      *ipp,             /* I - IPP message */
     ipp->last = ipp->current = attr;
   }
 
-  DEBUG_printf(("5ipp_add_attr: Returning %p", attr));
+  DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr));
 
   return (attr);
 }
@@ -6354,10 +6250,9 @@ 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)", (void *)attr, element, count));
 
-  if (!(attr->value_tag & IPP_TAG_COPY))
+  if (!(attr->value_tag & IPP_TAG_CUPS_CONST))
   {
    /*
     * Free values as needed...
@@ -6393,6 +6288,7 @@ ipp_free_values(ipp_attribute_t *attr,    /* I - Attribute to free values from */
          }
          break;
 
+      case IPP_TAG_UNSUPPORTED_VALUE :
       case IPP_TAG_DEFAULT :
       case IPP_TAG_UNKNOWN :
       case IPP_TAG_NOVALUE :
@@ -6439,7 +6335,7 @@ ipp_free_values(ipp_attribute_t *attr,    /* I - Attribute to free values from */
 
   if ((element + count) < attr->num_values)
     memmove(attr->values + element, attr->values + element + count,
-            (attr->num_values - count - element) * sizeof(_ipp_value_t));
+            (size_t)(attr->num_values - count - element) * sizeof(_ipp_value_t));
 
   attr->num_values -= count;
 }
@@ -6471,7 +6367,7 @@ ipp_get_code(const char *value,           /* I - Locale/charset string */
     if (*value == '_')
       *bufptr++ = '-';
     else
-      *bufptr++ = _cups_tolower(*value);
+      *bufptr++ = (char)_cups_tolower(*value);
 
   *bufptr = '\0';
 
@@ -6524,7 +6420,7 @@ ipp_length(ipp_t *ipp,                    /* I - IPP message or collection */
   _ipp_value_t         *value;         /* Current value */
 
 
-  DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", ipp, collection));
+  DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp, collection));
 
   if (!ipp)
   {
@@ -6561,18 +6457,21 @@ ipp_length(ipp_t *ipp,                  /* I - IPP message or collection */
     DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
                   "bytes=" CUPS_LLFMT, attr->name, attr->num_values, CUPS_LLCAST bytes));
 
-    if (attr->value_tag < IPP_TAG_EXTENSION)
-      bytes += attr->num_values;       /* Value tag for each value */
+    if ((attr->value_tag & ~IPP_TAG_CUPS_CONST) < IPP_TAG_EXTENSION)
+      bytes += (size_t)attr->num_values;/* Value tag for each value */
     else
-      bytes += 5 * attr->num_values;   /* Value tag for each value */
-    bytes += 2 * attr->num_values;     /* Name lengths */
-    bytes += (int)strlen(attr->name);  /* Name */
-    bytes += 2 * attr->num_values;     /* Value lengths */
+      bytes += (size_t)(5 * attr->num_values);
+                                       /* Value tag for each value */
+    bytes += (size_t)(2 * attr->num_values);
+                                       /* Name lengths */
+    bytes += strlen(attr->name);       /* Name */
+    bytes += (size_t)(2 * attr->num_values);
+                                       /* Value lengths */
 
     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 :
@@ -6585,11 +6484,11 @@ ipp_length(ipp_t *ipp,                  /* I - IPP message or collection */
 
       case IPP_TAG_INTEGER :
       case IPP_TAG_ENUM :
-          bytes += 4 * attr->num_values;
+          bytes += (size_t)(4 * attr->num_values);
          break;
 
       case IPP_TAG_BOOLEAN :
-          bytes += attr->num_values;
+          bytes += (size_t)attr->num_values;
          break;
 
       case IPP_TAG_TEXT :
@@ -6608,20 +6507,21 @@ ipp_length(ipp_t *ipp,                  /* I - IPP message or collection */
          break;
 
       case IPP_TAG_DATE :
-          bytes += 11 * attr->num_values;
+          bytes += (size_t)(11 * attr->num_values);
          break;
 
       case IPP_TAG_RESOLUTION :
-          bytes += 9 * attr->num_values;
+          bytes += (size_t)(9 * attr->num_values);
          break;
 
       case IPP_TAG_RANGE :
-          bytes += 8 * attr->num_values;
+          bytes += (size_t)(8 * attr->num_values);
          break;
 
       case IPP_TAG_TEXTLANG :
       case IPP_TAG_NAMELANG :
-          bytes += 4 * attr->num_values;/* Charset + text length */
+          bytes += (size_t)(4 * attr->num_values);
+                                       /* Charset + text length */
 
          for (i = 0, value = attr->values;
               i < attr->num_values;
@@ -6646,7 +6546,7 @@ ipp_length(ipp_t *ipp,                    /* I - IPP message or collection */
          for (i = 0, value = attr->values;
               i < attr->num_values;
               i ++, value ++)
-            bytes += value->unknown.length;
+            bytes += (size_t)value->unknown.length;
          break;
     }
   }
@@ -6676,12 +6576,11 @@ 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 */
+  ssize_t      tbytes,                 /* Total bytes read */
+               bytes;                  /* Bytes read this pass */
 
 
-  DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)",
-                http, buffer, (int)length));
+  DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http, (void *)buffer, (int)length));
 
  /*
   * Loop until all bytes are read...
@@ -6691,10 +6590,9 @@ ipp_read_http(http_t      *http, /* I - Client connection */
        tbytes < (int)length;
        tbytes += bytes, buffer += bytes)
   {
-    DEBUG_printf(("9ipp_read_http: tbytes=%d, http->state=%d", tbytes,
-                  http->state));
+    DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT ", http->state=%d", CUPS_LLCAST tbytes, http->state));
 
-    if (http->state == HTTP_WAITING)
+    if (http->state == HTTP_STATE_WAITING)
       break;
 
     if (http->used == 0 && !http->blocking)
@@ -6713,17 +6611,33 @@ ipp_read_http(http_t      *http,        /* I - Client connection */
        break;
       }
     }
+    else if (http->used == 0 && http->timeout_value > 0)
+    {
+     /*
+      * Wait up to timeout seconds for more data on blocking sockets...
+      */
+
+      if (!httpWait(http, (int)(1000 * http->timeout_value)))
+      {
+       /*
+       * Signal no data...
+       */
+
+       bytes = -1;
+       break;
+      }
+    }
 
-    if ((bytes = httpRead2(http, (char *)buffer, length - tbytes)) < 0)
+    if ((bytes = httpRead2(http, (char *)buffer, length - (size_t)tbytes)) < 0)
     {
-#ifdef WIN32
+#ifdef _WIN32
       break;
 #else
       if (errno != EAGAIN && errno != EINTR)
        break;
 
       bytes = 0;
-#endif /* WIN32 */
+#endif /* _WIN32 */
     }
     else if (bytes == 0)
       break;
@@ -6736,7 +6650,7 @@ ipp_read_http(http_t      *http,  /* I - Client connection */
   if (tbytes == 0 && bytes < 0)
     tbytes = -1;
 
-  DEBUG_printf(("8ipp_read_http: Returning %d bytes", tbytes));
+  DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT " bytes", CUPS_LLCAST tbytes));
 
   return (tbytes);
 }
@@ -6751,11 +6665,11 @@ ipp_read_file(int         *fd,          /* I - File descriptor */
               ipp_uchar_t *buffer,     /* O - Read buffer */
              size_t      length)       /* I - Number of bytes to read */
 {
-#ifdef WIN32
+#ifdef _WIN32
   return ((ssize_t)read(*fd, buffer, (unsigned)length));
 #else
   return (read(*fd, buffer, length));
-#endif /* WIN32 */
+#endif /* _WIN32 */
 }
 
 
@@ -6835,10 +6749,9 @@ ipp_set_value(ipp_t           *ipp,      /* IO - IPP message */
   * Reallocate memory...
   */
 
-  if ((temp = realloc(temp, sizeof(ipp_attribute_t) +
-                           (alloc_values - 1) * sizeof(_ipp_value_t))) == NULL)
+  if ((temp = realloc(temp, sizeof(ipp_attribute_t) + (size_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);
   }
@@ -6847,8 +6760,7 @@ ipp_set_value(ipp_t           *ipp,       /* IO - IPP message */
   * Zero the new memory...
   */
 
-  memset(temp->values + temp->num_values, 0,
-         (alloc_values - temp->num_values) * sizeof(_ipp_value_t));
+  memset(temp->values + temp->num_values, 0, (size_t)(alloc_values - temp->num_values) * sizeof(_ipp_value_t));
 
   if (temp != *attr)
   {
@@ -6856,6 +6768,11 @@ ipp_set_value(ipp_t           *ipp,      /* IO - IPP message */
     * Reset pointers in the list...
     */
 
+#ifndef __clang_analyzer__
+    DEBUG_printf(("4debug_free: %p %s", (void *)*attr, temp->name));
+#endif /* !__clang_analyzer__ */
+    DEBUG_printf(("4debug_alloc: %p %s %s%s (%d)", (void *)temp, temp->name, temp->num_values > 1 ? "1setOf " : "", ippTagString(temp->value_tag), temp->num_values));
+
     if (ipp->current == *attr && ipp->prev)
     {
      /*
@@ -6881,7 +6798,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);
@@ -6922,14 +6839,9 @@ ipp_write_file(int         *fd,          /* I - File descriptor */
                ipp_uchar_t *buffer,    /* I - Data to write */
                size_t      length)     /* I - Number of bytes to write */
 {
-#ifdef WIN32
+#ifdef _WIN32
   return ((ssize_t)write(*fd, buffer, (unsigned)length));
 #else
   return (write(*fd, buffer, length));
-#endif /* WIN32 */
+#endif /* _WIN32 */
 }
-
-
-/*
- * End of "$Id: ipp.c 10102 2011-11-02 23:52:39Z mike $".
- */