]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/ipp.c
Merge changes from CUPS 1.4svn-r7961.
[thirdparty/cups.git] / cups / ipp.c
index e9be31fe68cd664234edfa8c8676fe757cb998e2..929f1dc4122c8c3a4c01e7489078534f93a0affe 100644 (file)
@@ -1,26 +1,17 @@
 /*
- * "$Id: ipp.c 5047 2006-02-02 05:14:15Z mike $"
+ * "$Id: ipp.c 7847 2008-08-19 04:22:14Z mike $"
  *
  *   Internet Printing Protocol support functions for the Common UNIX
  *   Printing System (CUPS).
  *
- *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ *   Copyright 2007-2008 by Apple Inc.
+ *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   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.
  *
@@ -57,8 +48,8 @@
  *                            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 request.
- *   _ipp_free_attr()       - Free an attribute.
+ *   _ippAddAttr()          - Add a new attribute to the request.
+ *   _ippFreeAttr()         - Free an attribute.
  *   ipp_length()           - Compute the length of an IPP message or
  *                            collection value.
  *   ipp_read_http()        - Semi-blocking read on a HTTP connection...
@@ -106,15 +97,16 @@ ippAddBoolean(ipp_t      *ipp,             /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddBoolean(%p, %02x, \'%s\', %d)\n", ipp, group, name, value));
+  DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)\n",
+                ipp, group, ippTagString(group), name, value));
 
-  if (ipp == NULL || name == NULL)
+  if (!ipp || !name)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
+  if ((attr = _ippAddAttr(ipp, 1)) == NULL)
     return (NULL);
 
-  attr->name              = _cups_sp_alloc(name);
+  attr->name              = _cupsStrAlloc(name);
   attr->group_tag         = group;
   attr->value_tag         = IPP_TAG_BOOLEAN;
   attr->values[0].boolean = value;
@@ -139,16 +131,17 @@ ippAddBooleans(ipp_t      *ipp,           /* I - IPP message */
   ipp_value_t          *value;         /* Current value */
 
 
-  DEBUG_printf(("ippAddBooleans(%p, %02x, \'%s\', %d, %p)\n", ipp,
-                group, name, num_values, values));
+  DEBUG_printf(("ippAddBooleans(ipp=%p, group=%02x(%s), name=\"%s\", "
+                "num_values=%d, values=%p)\n", ipp, group, ippTagString(group),
+                name, num_values, values));
 
-  if (ipp == NULL || name == NULL || num_values < 1)
+  if (!ipp || !name || num_values < 1)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
+  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
     return (NULL);
 
-  attr->name      = _cups_sp_alloc(name);
+  attr->name      = _cupsStrAlloc(name);
   attr->group_tag = group;
   attr->value_tag = IPP_TAG_BOOLEAN;
 
@@ -177,16 +170,16 @@ ippAddCollection(ipp_t      *ipp, /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddCollection(%p, %02x, \'%s\', %p)\n", ipp, group, name,
-                value));
+  DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", "
+                "value=%p)\n", ipp, group, ippTagString(group), name, value));
 
-  if (ipp == NULL || name == NULL)
+  if (!ipp || !name)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
+  if ((attr = _ippAddAttr(ipp, 1)) == NULL)
     return (NULL);
 
-  attr->name                 = _cups_sp_alloc(name);
+  attr->name                 = _cupsStrAlloc(name);
   attr->group_tag            = group;
   attr->value_tag            = IPP_TAG_BEGIN_COLLECTION;
   attr->values[0].collection = value;
@@ -214,16 +207,17 @@ ippAddCollections(
   ipp_value_t          *value;         /* Current value */
 
 
-  DEBUG_printf(("ippAddCollections(%p, %02x, \'%s\', %d, %p)\n", ipp,
-                group, name, num_values, values));
+  DEBUG_printf(("ippAddCollections(ipp=%p, group=%02x(%s), name=\"%s\", "
+                "num_values=%d, values=%p)\n", ipp, group, ippTagString(group),
+                name, num_values, values));
 
-  if (ipp == NULL || name == NULL || num_values < 1)
+  if (!ipp || !name || num_values < 1)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
+  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
     return (NULL);
 
-  attr->name      = _cups_sp_alloc(name);
+  attr->name      = _cupsStrAlloc(name);
   attr->group_tag = group;
   attr->value_tag = IPP_TAG_BEGIN_COLLECTION;
 
@@ -250,16 +244,16 @@ ippAddDate(ipp_t             *ipp,        /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddDate(%p, %02x, \'%s\', %p)\n", ipp, group, name,
-                value));
+  DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)\n",
+                ipp, group, ippTagString(group), name, value));
 
-  if (ipp == NULL || name == NULL || value == NULL)
+  if (!ipp || !name || !value)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
+  if ((attr = _ippAddAttr(ipp, 1)) == NULL)
     return (NULL);
 
-  attr->name      = _cups_sp_alloc(name);
+  attr->name      = _cupsStrAlloc(name);
   attr->group_tag = group;
   attr->value_tag = IPP_TAG_DATE;
   memcpy(attr->values[0].date, value, 11);
@@ -282,16 +276,17 @@ ippAddInteger(ipp_t      *ipp,            /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddInteger(%p, %d, \'%s\', %d)\n", ipp, group, name,
-                value));
+  DEBUG_printf(("ippAddInteger(ipp=%p, group=%02x(%s), type=%02x(%s), "
+                "name=\"%s\", value=%d)\n", ipp, group, ippTagString(group),
+               type, ippTagString(type), name, value));
 
-  if (ipp == NULL || name == NULL)
+  if (!ipp || !name)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
+  if ((attr = _ippAddAttr(ipp, 1)) == NULL)
     return (NULL);
 
-  attr->name              = _cups_sp_alloc(name);
+  attr->name              = _cupsStrAlloc(name);
   attr->group_tag         = group;
   attr->value_tag         = type;
   attr->values[0].integer = value;
@@ -317,13 +312,18 @@ ippAddIntegers(ipp_t      *ipp,           /* I - IPP message */
   ipp_value_t          *value;         /* Current value */
 
 
-  if (ipp == NULL || name == NULL || num_values < 1)
+  DEBUG_printf(("ippAddIntegers(ipp=%p, group=%02x(%s), type=%02x(%s), "
+                "name=\"%s\", num_values=%d, values=%p)\n", ipp,
+               group, ippTagString(group), type, ippTagString(type), name,
+               num_values, values));
+
+  if (!ipp || !name || num_values < 1)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
+  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
     return (NULL);
 
-  attr->name      = _cups_sp_alloc(name);
+  attr->name      = _cupsStrAlloc(name);
   attr->group_tag = group;
   attr->value_tag = type;
 
@@ -356,21 +356,26 @@ ippAddOctetString(ipp_t      *ipp,        /* I - IPP message */
   if (ipp == NULL || name == NULL)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
+  if ((attr = _ippAddAttr(ipp, 1)) == NULL)
     return (NULL);
 
  /*
   * Initialize the attribute data...
   */
 
-  attr->name                     = _cups_sp_alloc(name);
+  attr->name                     = _cupsStrAlloc(name);
   attr->group_tag                = group;
   attr->value_tag                = IPP_TAG_STRING;
   attr->values[0].unknown.length = datalen;
 
   if (data)
   {
-    attr->values[0].unknown.data = malloc(datalen);
+    if ((attr->values[0].unknown.data = malloc(datalen)) == NULL)
+    {
+      ippDeleteAttribute(ipp, attr);
+      return (NULL);
+    }
+
     memcpy(attr->values[0].unknown.data, data, datalen);
   }
 
@@ -399,10 +404,15 @@ ippAddString(ipp_t      *ipp,             /* I - IPP message */
                        *bufptr;        /* Pointer into buffer */
 
 
-  if (ipp == NULL || name == NULL)
+  DEBUG_printf(("ippAddString(ipp=%p, group=%02x(%s), type=%02x(%s), "
+                "name=\"%s\", charset=\"%s\", value=\"%s\")\n", ipp,
+               group, ippTagString(group), type, ippTagString(type), name,
+               charset, value));
+
+  if (!ipp || !name)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
+  if ((attr = _ippAddAttr(ipp, 1)) == NULL)
     return (NULL);
 
  /*
@@ -432,13 +442,13 @@ ippAddString(ipp_t      *ipp,             /* I - IPP message */
   * Initialize the attribute data...
   */
 
-  attr->name                     = _cups_sp_alloc(name);
+  attr->name                     = _cupsStrAlloc(name);
   attr->group_tag                = group;
   attr->value_tag                = type;
   attr->values[0].string.charset = ((int)type & IPP_TAG_COPY) ? (char *)charset :
-                                   charset ? _cups_sp_alloc(charset) : NULL;
+                                   charset ? _cupsStrAlloc(charset) : NULL;
   attr->values[0].string.text    = ((int)type & IPP_TAG_COPY) ? (char *)value :
-                                   value ? _cups_sp_alloc(value) : NULL;
+                                   value ? _cupsStrAlloc(value) : NULL;
 
   return (attr);
 }
@@ -463,17 +473,22 @@ ippAddStrings(
   ipp_value_t          *value;         /* Current value */
 
 
-  if (ipp == NULL || name == NULL || num_values < 1)
+  DEBUG_printf(("ippAddStrings(ipp=%p, group=%02x(%s), type=%02x(%s), "
+                "name=\"%s\", num_values=%d, charset=\"%s\", values=%p)\n", ipp,
+               group, ippTagString(group), type, ippTagString(type), name,
+               num_values, charset, values));
+
+  if (!ipp || !name || num_values < 1)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
+  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
     return (NULL);
 
  /*
   * Initialize the attribute data...
   */
 
-  attr->name      = _cups_sp_alloc(name);
+  attr->name      = _cupsStrAlloc(name);
   attr->group_tag = group;
   attr->value_tag = type;
 
@@ -483,7 +498,7 @@ ippAddStrings(
   {
     if (i == 0)
       value->string.charset = ((int)type & IPP_TAG_COPY) ? (char *)charset :
-                                   charset ? _cups_sp_alloc(charset) : NULL;
+                                   charset ? _cupsStrAlloc(charset) : NULL;
     else
       value->string.charset = attr->values[0].string.charset;
 
@@ -495,10 +510,10 @@ ippAddStrings(
 
       if (type == IPP_TAG_LANGUAGE && !strcasecmp(values[i], "C"))
        value->string.text = ((int)type & IPP_TAG_COPY) ? "en" :
-                                      _cups_sp_alloc("en");
+                                      _cupsStrAlloc("en");
       else
        value->string.text = ((int)type & IPP_TAG_COPY) ? (char *)values[i] :
-                                      _cups_sp_alloc(values[i]);
+                                      _cupsStrAlloc(values[i]);
     }
   }
 
@@ -520,13 +535,17 @@ ippAddRange(ipp_t      *ipp,              /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  if (ipp == NULL || name == NULL)
+  DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, "
+                "upper=%d)\n", ipp, group, ippTagString(group), name, lower,
+               upper));
+
+  if (!ipp || !name)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
+  if ((attr = _ippAddAttr(ipp, 1)) == NULL)
     return (NULL);
 
-  attr->name                  = _cups_sp_alloc(name);
+  attr->name                  = _cupsStrAlloc(name);
   attr->group_tag             = group;
   attr->value_tag             = IPP_TAG_RANGE;
   attr->values[0].range.lower = lower;
@@ -553,13 +572,17 @@ ippAddRanges(ipp_t      *ipp,             /* I - IPP message */
   ipp_value_t          *value;         /* Current value */
 
 
-  if (ipp == NULL || name == NULL || num_values < 1)
+  DEBUG_printf(("ippAddRanges(ipp=%p, group=%02x(%s), name=\"%s\", "
+                "num_values=%d, lower=%p, upper=%p)\n", ipp, group,
+               ippTagString(group), name, num_values, lower, upper));
+
+  if (!ipp || !name || num_values < 1)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
+  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
     return (NULL);
 
-  attr->name      = _cups_sp_alloc(name);
+  attr->name      = _cupsStrAlloc(name);
   attr->group_tag = group;
   attr->value_tag = IPP_TAG_RANGE;
 
@@ -591,13 +614,17 @@ ippAddResolution(ipp_t      *ipp, /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  if (ipp == NULL || name == NULL)
+  DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", "
+                "units=%d, xres=%d, yres=%d)\n", ipp, group,
+               ippTagString(group), name, units, xres, yres));
+
+  if (!ipp || !name)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
+  if ((attr = _ippAddAttr(ipp, 1)) == NULL)
     return (NULL);
 
-  attr->name                       = _cups_sp_alloc(name);
+  attr->name                       = _cupsStrAlloc(name);
   attr->group_tag                  = group;
   attr->value_tag                  = IPP_TAG_RESOLUTION;
   attr->values[0].resolution.xres  = xres;
@@ -626,13 +653,17 @@ ippAddResolutions(ipp_t      *ipp,        /* I - IPP message */
   ipp_value_t          *value;         /* Current value */
 
 
-  if (ipp == NULL || name == NULL || num_values < 1)
+  DEBUG_printf(("ippAddResolutions(ipp=%p, group=%02x(%s), name=\"%s\", "
+                "num_value=%d, units=%d, xres=%p, yres=%p)\n", ipp, group,
+               ippTagString(group), name, num_values, units, xres, yres));
+
+  if (!ipp || !name || num_values < 1)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
+  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
     return (NULL);
 
-  attr->name      = _cups_sp_alloc(name);
+  attr->name      = _cupsStrAlloc(name);
   attr->group_tag = group;
   attr->value_tag = IPP_TAG_RESOLUTION;
 
@@ -660,12 +691,12 @@ ippAddSeparator(ipp_t *ipp)               /* I - IPP message */
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("ippAddSeparator(%p)\n", ipp));
+  DEBUG_printf(("ippAddSeparator(ipp=%p)\n", ipp));
 
-  if (ipp == NULL)
+  if (!ipp)
     return (NULL);
 
-  if ((attr = _ipp_add_attr(ipp, 0)) == NULL)
+  if ((attr = _ippAddAttr(ipp, 0)) == NULL)
     return (NULL);
 
   attr->group_tag = IPP_TAG_ZERO;
@@ -687,6 +718,9 @@ ippDateToTime(const ipp_uchar_t *date)      /* I - RFC 1903 date info */
   time_t       t;                      /* Computed time */
 
 
+  if (!date)
+    return (0);
+
   memset(&unixdate, 0, sizeof(unixdate));
 
  /*
@@ -735,15 +769,15 @@ ippDelete(ipp_t *ipp)                     /* I - IPP message */
                        *next;          /* Next attribute */
 
 
-  DEBUG_printf(("ippDelete(): %p\n", ipp));
+  DEBUG_printf(("ippDelete(ipp=%p)\n", ipp));
 
-  if (ipp == NULL)
+  if (!ipp)
     return;
 
   for (attr = ipp->attrs; attr != NULL; attr = next)
   {
     next = attr->next;
-    _ipp_free_attr(attr);
+    _ippFreeAttr(attr);
   }
 
   free(ipp);
@@ -765,6 +799,8 @@ ippDeleteAttribute(
                        *prev;          /* Previous attribute */
 
 
+  DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p)\n", ipp, attr));
+
  /*
   * Find the attribute in the list...
   */
@@ -791,7 +827,7 @@ ippDeleteAttribute(
     * Free memory used by the attribute...
     */
 
-    _ipp_free_attr(current);
+    _ippFreeAttr(current);
   }
 }
 
@@ -805,9 +841,10 @@ ippFindAttribute(ipp_t      *ipp,  /* I - IPP message */
                  const char *name,     /* I - Name of attribute */
                 ipp_tag_t  type)       /* I - Type of attribute */
 {
-  DEBUG_printf(("ippFindAttribute(%p, \'%s\')\n", ipp, name));
+  DEBUG_printf(("ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))\n", ipp,
+                name, type, ippTagString(type)));
 
-  if (ipp == NULL || name == NULL)
+  if (!ipp || !name)
     return (NULL);
 
  /*
@@ -837,9 +874,10 @@ ippFindNextAttribute(ipp_t      *ipp,      /* I - IPP message */
   ipp_tag_t            value_tag;      /* Value tag */
 
 
-  DEBUG_printf(("ippFindNextAttribute(%p, \'%s\')\n", ipp, name));
+  DEBUG_printf(("ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))\n",
+                ipp, name, type, ippTagString(type)));
 
-  if (ipp == NULL || name == NULL)
+  if (!ipp || !name)
     return (NULL);
 
   if (ipp->current)
@@ -855,7 +893,7 @@ ippFindNextAttribute(ipp_t      *ipp,       /* I - IPP message */
 
   for (; attr != NULL; ipp->prev = attr, attr = attr->next)
   {
-    DEBUG_printf(("ippFindAttribute: attr = %p, name = \'%s\'\n", attr,
+    DEBUG_printf(("ippFindAttribute: attr=%p, name=\"%s\"\n", attr,
                   attr->name));
 
     value_tag = (ipp_tag_t)(attr->value_tag & IPP_TAG_MASK);
@@ -934,6 +972,8 @@ ippNewRequest(ipp_op_t op)          /* I - Operation code */
   cups_lang_t  *language;              /* Current language localization */
 
 
+  DEBUG_printf(("ippNewRequest(op=%02x(%s))\n", op, ippOpString(op)));
+
  /*
   * Create a new IPP message...
   */
@@ -983,13 +1023,14 @@ ippRead(http_t *http,                    /* I - HTTP connection */
   DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT "\n",
                 http, ipp, CUPS_LLCAST (http ? http->data_remaining : -1)));
 
-  if (http == NULL)
+  if (!http)
     return (IPP_ERROR);
 
-  DEBUG_printf(("http->state = %d\n", http->state));
+  DEBUG_printf(("ippRead: http->state=%d, http->used=%d\n", http->state,
+                http->used));
 
-  return (ippReadIO(http, (ipp_iocb_t)ipp_read_http,
-                    http->blocking || http->used != 0, NULL, ipp));
+  return (ippReadIO(http, (ipp_iocb_t)ipp_read_http, http->blocking, NULL,
+                    ipp));
 }
 
 
@@ -1003,7 +1044,7 @@ ipp_state_t                               /* O - Current state */
 ippReadFile(int   fd,                  /* I - HTTP data */
             ipp_t *ipp)                        /* I - IPP data */
 {
-  DEBUG_printf(("ippReadFile(%d, %p)\n", fd, ipp));
+  DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)\n", fd, ipp));
 
   return (ippReadIO(&fd, (ipp_iocb_t)ipp_read_file, 1, NULL, ipp));
 }
@@ -1023,8 +1064,10 @@ ippReadIO(void       *src,               /* I - Data source */
           ipp_t      *ipp)             /* I - IPP data */
 {
   int                  n;              /* Length of data */
-  unsigned char                buffer[32768],  /* Data buffer */
-                       string[255],    /* Small string buffer */
+  unsigned char                buffer[IPP_MAX_LENGTH + 1],
+                                       /* Data buffer */
+                       string[IPP_MAX_NAME],
+                                       /* Small string buffer */
                        *bufptr;        /* Pointer into buffer */
   ipp_attribute_t      *attr;          /* Current attribute */
   ipp_tag_t            tag;            /* Current tag */
@@ -1032,10 +1075,11 @@ ippReadIO(void       *src,              /* I - Data source */
   ipp_value_t          *value;         /* Current value */
 
 
-  DEBUG_printf(("ippReadIO(%p, %p, %d, %p, %p)\n", src, cb, blocking,
-                parent, ipp));
+  DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)\n",
+                src, cb, blocking, parent, ipp));
+  DEBUG_printf(("ippReadIO: ipp->state=%d\n", ipp->state));
 
-  if (src == NULL || ipp == NULL)
+  if (!src || !ipp)
     return (IPP_ERROR);
 
   switch (ipp->state)
@@ -1050,10 +1094,10 @@ ippReadIO(void       *src,              /* I - Data source */
           * Get the request header...
          */
 
-          if ((n = (*cb)(src, buffer, 8)) < 8)
+          if ((*cb)(src, buffer, 8) < 8)
          {
-           DEBUG_printf(("ippReadIO: Unable to read header (%d bytes read)!\n", n));
-           return (n == 0 ? IPP_IDLE : IPP_ERROR);
+           DEBUG_puts("ippReadIO: Unable to read header!");
+           return (IPP_ERROR);
          }
 
         /*
@@ -1062,8 +1106,8 @@ ippReadIO(void       *src,                /* I - Data source */
 
          if (buffer[0] != 1)
          {
-           DEBUG_printf(("ippReadIO: version number (%d.%d) is bad.\n", buffer[0],
-                         buffer[1]));
+           DEBUG_printf(("ippReadIO: version number (%d.%d) is bad.\n",
+                         buffer[0], buffer[1]));
            return (IPP_ERROR);
          }
 
@@ -1097,8 +1141,11 @@ ippReadIO(void       *src,               /* I - Data source */
          break;
 
     case IPP_ATTRIBUTE :
-        while ((*cb)(src, buffer, 1) > 0)
+        for (;;)
        {
+         if ((*cb)(src, buffer, 1) < 1)
+           return (IPP_ERROR);
+
          DEBUG_printf(("ippReadIO: ipp->current=%p, ipp->prev=%p\n",
                        ipp->current, ipp->prev));
 
@@ -1132,12 +1179,13 @@ ippReadIO(void       *src,              /* I - Data source */
 
            ipp->curtag  = tag;
            ipp->current = NULL;
-           DEBUG_printf(("ippReadIO: group tag = %x, ipp->prev=%p\n", tag,
-                         ipp->prev));
+           DEBUG_printf(("ippReadIO: group tag=%x(%s), ipp->prev=%p\n", tag,
+                         ippTagString(tag), ipp->prev));
            continue;
          }
 
-          DEBUG_printf(("ippReadIO: value tag = %x\n", tag));
+          DEBUG_printf(("ippReadIO: value tag=%x(%s)\n", tag,
+                       ippTagString(tag)));
 
          /*
          * Get the name...
@@ -1157,7 +1205,7 @@ ippReadIO(void       *src,                /* I - Data source */
            return (IPP_ERROR);
          }
 
-          DEBUG_printf(("ippReadIO: name length = %d\n", n));
+          DEBUG_printf(("ippReadIO: name length=%d\n", n));
 
           if (n == 0 && tag != IPP_TAG_MEMBERNAME &&
              tag != IPP_TAG_END_COLLECTION)
@@ -1185,8 +1233,7 @@ ippReadIO(void       *src,                /* I - Data source */
 
              attr->value_tag = tag;
            }
-           else if (value_tag == IPP_TAG_STRING ||
-                    (value_tag >= IPP_TAG_TEXTLANG &&
+           else if ((value_tag >= IPP_TAG_TEXTLANG &&
                      value_tag <= IPP_TAG_MIMETYPE))
             {
             /*
@@ -1194,12 +1241,22 @@ ippReadIO(void       *src,              /* I - Data source */
              * forms; accept sets of differing values...
              */
 
-             if (tag != IPP_TAG_STRING &&
-                 (tag < IPP_TAG_TEXTLANG || tag > IPP_TAG_MIMETYPE))
+             if ((tag < IPP_TAG_TEXTLANG || tag > IPP_TAG_MIMETYPE) &&
+                 tag != IPP_TAG_NOVALUE)
+             {
+               DEBUG_printf(("ippReadIO: 1setOf value tag %x(%s) != %x(%s)\n",
+                             value_tag, ippTagString(value_tag), tag,
+                             ippTagString(tag)));
                return (IPP_ERROR);
+             }
             }
            else if (value_tag != tag)
+           {
+             DEBUG_printf(("ippReadIO: value tag %x(%s) != %x(%s)\n",
+                           value_tag, ippTagString(value_tag), tag,
+                           ippTagString(tag)));
              return (IPP_ERROR);
+            }
 
            /*
            * Finally, reallocate the attribute array as needed...
@@ -1254,10 +1311,10 @@ ippReadIO(void       *src,              /* I - Data source */
             if (ipp->current)
              ipp->prev = ipp->current;
 
-           attr = ipp->current = _ipp_add_attr(ipp, 1);
+           attr = ipp->current = _ippAddAttr(ipp, 1);
 
-           DEBUG_printf(("ippReadIO: membername, ipp->current=%p, ipp->prev=%p\n",
-                         ipp->current, ipp->prev));
+           DEBUG_printf(("ippReadIO: membername, ipp->current=%p, "
+                         "ipp->prev=%p\n", ipp->current, ipp->prev));
 
            attr->group_tag  = ipp->curtag;
            attr->value_tag  = IPP_TAG_ZERO;
@@ -1280,14 +1337,18 @@ ippReadIO(void       *src,              /* I - Data source */
             if (ipp->current)
              ipp->prev = ipp->current;
 
-           attr = ipp->current = _ipp_add_attr(ipp, 1);
+           if ((attr = ipp->current = _ippAddAttr(ipp, 1)) == NULL)
+           {
+             DEBUG_puts("ippReadIO: unable to allocate attribute!");
+             return (IPP_ERROR);
+           }
 
-           DEBUG_printf(("ippReadIO: name=\'%s\', ipp->current=%p, ipp->prev=%p\n",
-                         buffer, ipp->current, ipp->prev));
+           DEBUG_printf(("ippReadIO: name=\"%s\", ipp->current=%p, "
+                         "ipp->prev=%p\n", buffer, ipp->current, ipp->prev));
 
            attr->group_tag  = ipp->curtag;
            attr->value_tag  = tag;
-           attr->name       = _cups_sp_alloc((char *)buffer);
+           attr->name       = _cupsStrAlloc((char *)buffer);
            attr->num_values = 0;
          }
          else
@@ -1305,12 +1366,18 @@ ippReadIO(void       *src,              /* I - Data source */
          }
 
          n = (buffer[0] << 8) | buffer[1];
-          DEBUG_printf(("ippReadIO: value length = %d\n", n));
+          DEBUG_printf(("ippReadIO: value length=%d\n", n));
 
          switch (tag)
          {
            case IPP_TAG_INTEGER :
            case IPP_TAG_ENUM :
+               if (n != 4)
+               {
+                 DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
+                 return (IPP_ERROR);
+               }
+
                if ((*cb)(src, buffer, 4) < 4)
                {
                  DEBUG_puts("ippReadIO: Unable to read integer value!");
@@ -1322,7 +1389,14 @@ ippReadIO(void       *src,               /* I - Data source */
 
                 value->integer = n;
                break;
+
            case IPP_TAG_BOOLEAN :
+               if (n != 1)
+               {
+                 DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
+                 return (IPP_ERROR);
+               }
+
                if ((*cb)(src, buffer, 1) < 1)
                {
                  DEBUG_puts("ippReadIO: Unable to read boolean value!");
@@ -1331,15 +1405,30 @@ ippReadIO(void       *src,              /* I - Data source */
 
                 value->boolean = buffer[0];
                break;
+
+            case IPP_TAG_NOVALUE :
+               if (attr->value_tag == IPP_TAG_NOVALUE)
+               {
+                 if (n == 0)
+                   break;
+
+                 attr->value_tag = IPP_TAG_TEXT;
+               }
+
            case IPP_TAG_TEXT :
            case IPP_TAG_NAME :
            case IPP_TAG_KEYWORD :
-           case IPP_TAG_STRING :
            case IPP_TAG_URI :
            case IPP_TAG_URISCHEME :
            case IPP_TAG_CHARSET :
            case IPP_TAG_LANGUAGE :
            case IPP_TAG_MIMETYPE :
+               if (n >= sizeof(buffer))
+               {
+                 DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
+                 return (IPP_ERROR);
+               }
+
                if ((*cb)(src, buffer, n) < n)
                {
                  DEBUG_puts("ippReadIO: unable to read name!");
@@ -1347,18 +1436,32 @@ ippReadIO(void       *src,              /* I - Data source */
                }
 
                buffer[n] = '\0';
-               value->string.text = _cups_sp_alloc((char *)buffer);
-               DEBUG_printf(("ippReadIO: value = \'%s\'\n",
+               value->string.text = _cupsStrAlloc((char *)buffer);
+               DEBUG_printf(("ippReadIO: value=\"%s\"\n",
                              value->string.text));
                break;
+
            case IPP_TAG_DATE :
+               if (n != 11)
+               {
+                 DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
+                 return (IPP_ERROR);
+               }
+
                if ((*cb)(src, value->date, 11) < 11)
                {
                  DEBUG_puts("ippReadIO: Unable to date integer value!");
                  return (IPP_ERROR);
                }
                break;
+
            case IPP_TAG_RESOLUTION :
+               if (n != 9)
+               {
+                 DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
+                 return (IPP_ERROR);
+               }
+
                if ((*cb)(src, buffer, 9) < 9)
                {
                  DEBUG_puts("ippReadIO: Unable to read resolution value!");
@@ -1374,7 +1477,14 @@ ippReadIO(void       *src,               /* I - Data source */
                 value->resolution.units =
                    (ipp_res_t)buffer[8];
                break;
+
            case IPP_TAG_RANGE :
+               if (n != 8)
+               {
+                 DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
+                 return (IPP_ERROR);
+               }
+
                if ((*cb)(src, buffer, 8) < 8)
                {
                  DEBUG_puts("ippReadIO: Unable to read range value!");
@@ -1388,9 +1498,10 @@ ippReadIO(void       *src,               /* I - Data source */
                    (((((buffer[4] << 8) | buffer[5]) << 8) | buffer[6]) << 8) |
                    buffer[7];
                break;
+
            case IPP_TAG_TEXTLANG :
            case IPP_TAG_NAMELANG :
-               if (n > sizeof(buffer) || n < 4)
+               if (n >= sizeof(buffer) || n < 4)
                {
                  DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
                  return (IPP_ERROR);
@@ -1416,24 +1527,29 @@ ippReadIO(void       *src,              /* I - Data source */
 
                n = (bufptr[0] << 8) | bufptr[1];
 
-                if (n >= sizeof(string))
+               if ((bufptr + 2 + n) >= (buffer + sizeof(buffer)) ||
+                   n >= sizeof(string))
                {
-                 memcpy(string, bufptr + 2, sizeof(string) - 1);
-                 string[sizeof(string) - 1] = '\0';
+                 DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
+                 return (IPP_ERROR);
                }
-               else
-               {
-                 memcpy(string, bufptr + 2, n);
-                 string[n] = '\0';
-                }
 
-               value->string.charset = _cups_sp_alloc((char *)string);
+               memcpy(string, bufptr + 2, n);
+               string[n] = '\0';
+
+               value->string.charset = _cupsStrAlloc((char *)string);
 
                 bufptr += 2 + n;
                n = (bufptr[0] << 8) | bufptr[1];
 
+               if ((bufptr + 2 + n) >= (buffer + sizeof(buffer)))
+               {
+                 DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
+                 return (IPP_ERROR);
+               }
+
                bufptr[2 + n] = '\0';
-                value->string.text = _cups_sp_alloc((char *)bufptr + 2);
+                value->string.text = _cupsStrAlloc((char *)bufptr + 2);
                break;
 
             case IPP_TAG_BEGIN_COLLECTION :
@@ -1445,7 +1561,8 @@ ippReadIO(void       *src,                /* I - Data source */
 
                 if (n > 0)
                {
-                 DEBUG_puts("ippReadIO: begCollection tag with value length > 0!");
+                 DEBUG_puts("ippReadIO: begCollection tag with value length "
+                            "> 0!");
                  return (IPP_ERROR);
                }
 
@@ -1459,7 +1576,8 @@ ippReadIO(void       *src,                /* I - Data source */
             case IPP_TAG_END_COLLECTION :
                 if (n > 0)
                {
-                 DEBUG_puts("ippReadIO: endCollection tag with value length > 0!");
+                 DEBUG_puts("ippReadIO: endCollection tag with value length "
+                            "> 0!");
                  return (IPP_ERROR);
                }
 
@@ -1473,6 +1591,12 @@ ippReadIO(void       *src,               /* I - Data source */
                * we need to carry over...
                */
 
+               if (n >= sizeof(buffer))
+               {
+                 DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
+                 return (IPP_ERROR);
+               }
+
                if ((*cb)(src, buffer, n) < n)
                {
                  DEBUG_puts("ippReadIO: Unable to read member name value!");
@@ -1480,7 +1604,7 @@ ippReadIO(void       *src,                /* I - Data source */
                }
 
                buffer[n] = '\0';
-               attr->name = _cups_sp_alloc((char *)buffer);
+               attr->name = _cupsStrAlloc((char *)buffer);
 
                /*
                * Since collection members are encoded differently than
@@ -1490,14 +1614,31 @@ ippReadIO(void       *src,              /* I - Data source */
 
                 attr->num_values --;
 
-               DEBUG_printf(("ippReadIO: member name = \"%s\"\n", attr->name));
+               DEBUG_printf(("ippReadIO: member name=\"%s\"\n", attr->name));
                break;
 
             default : /* Other unsupported values */
+               if (n > IPP_MAX_LENGTH)
+               {
+                 DEBUG_printf(("ippReadIO: bad value length %d!\n", n));
+                 return (IPP_ERROR);
+               }
+
+               if (!value)
+               {
+                 DEBUG_puts("ippReadIO: NULL value!");
+                 return (IPP_ERROR);
+               }
+
                 value->unknown.length = n;
                if (n > 0)
                {
-                 value->unknown.data = malloc(n);
+                 if ((value->unknown.data = malloc(n)) == NULL)
+                 {
+                   DEBUG_puts("ippReadIO: Unable to allocate value");
+                   return (IPP_ERROR);
+                 }
+
                  if ((*cb)(src, value->unknown.data, n) < n)
                  {
                    DEBUG_puts("ippReadIO: Unable to read unsupported value!");
@@ -1527,6 +1668,8 @@ ippReadIO(void       *src,                /* I - Data source */
         break; /* anti-compiler-warning-code */
   }
 
+  DEBUG_printf(("ippReadIO: returning ipp->state=%d!\n", ipp->state));
+
   return (ipp->state);
 }
 
@@ -1587,9 +1730,9 @@ ipp_state_t                               /* O - Current state */
 ippWrite(http_t *http,                 /* I - HTTP connection */
          ipp_t  *ipp)                  /* I - IPP data */
 {
-  DEBUG_printf(("ippWrite(%p, %p)\n", http, ipp));
+  DEBUG_printf(("ippWrite(http=%p, ipp=%p)\n", http, ipp));
 
-  if (http == NULL)
+  if (!http)
     return (IPP_ERROR);
 
   return (ippWriteIO(http, (ipp_iocb_t)httpWrite2,
@@ -1607,7 +1750,7 @@ ipp_state_t                               /* O - Current state */
 ippWriteFile(int   fd,                 /* I - HTTP data */
              ipp_t *ipp)               /* I - IPP data */
 {
-  DEBUG_printf(("ippWriteFile(%d, %p)\n", fd, ipp));
+  DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)\n", fd, ipp));
 
   ipp->state = IPP_IDLE;
 
@@ -1630,16 +1773,17 @@ ippWriteIO(void       *dst,             /* I - Destination */
 {
   int                  i;              /* Looping var */
   int                  n;              /* Length of data */
-  unsigned char                buffer[32768],  /* Data buffer */
+  unsigned char                buffer[IPP_MAX_LENGTH + 2],
+                                       /* Data buffer + length bytes */
                        *bufptr;        /* Pointer into buffer */
   ipp_attribute_t      *attr;          /* Current attribute */
   ipp_value_t          *value;         /* Current value */
 
 
-  DEBUG_printf(("ippWriteIO(%p, %p, %d, %p, %p)\n", dst, cb, blocking,
-                parent, ipp));
+  DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)\n",
+                dst, cb, blocking, parent, ipp));
 
-  if (dst == NULL || ipp == NULL)
+  if (!dst || !ipp)
     return (IPP_ERROR);
 
   switch (ipp->state)
@@ -1672,7 +1816,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
 
           if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
          {
-           DEBUG_puts("ippWrite: Could not write IPP header...");
+           DEBUG_puts("ippWriteIO: Could not write IPP header...");
            return (IPP_ERROR);
          }
        }
@@ -1686,9 +1830,11 @@ ippWriteIO(void       *dst,              /* I - Destination */
        ipp->current = ipp->attrs;
        ipp->curtag  = IPP_TAG_ZERO;
 
-        DEBUG_printf(("ippWrite: version=%d.%d\n", buffer[0], buffer[1]));
-       DEBUG_printf(("ippWrite: op_status=%04x\n", ipp->request.any.op_status));
-       DEBUG_printf(("ippWrite: request_id=%d\n", ipp->request.any.request_id));
+        DEBUG_printf(("ippWriteIO: version=%d.%d\n", buffer[0], buffer[1]));
+       DEBUG_printf(("ippWriteIO: op_status=%04x\n",
+                     ipp->request.any.op_status));
+       DEBUG_printf(("ippWriteIO: request_id=%d\n",
+                     ipp->request.any.request_id));
 
        /*
         * If blocking is disabled, stop here...
@@ -1720,7 +1866,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
             if (attr->group_tag == IPP_TAG_ZERO)
              continue;
 
-            DEBUG_printf(("ippWrite: wrote group tag = %x\n", attr->group_tag));
+            DEBUG_printf(("ippWriteIO: wrote group tag=%x(%s)\n",
+                         attr->group_tag, ippTagString(attr->group_tag)));
            *bufptr++ = attr->group_tag;
          }
          else if (attr->group_tag == IPP_TAG_ZERO)
@@ -1751,8 +1898,10 @@ ippWriteIO(void       *dst,              /* I - Destination */
            * Write the value tag, name length, and name string...
            */
 
-            DEBUG_printf(("ippWrite: writing value tag = %x\n", attr->value_tag));
-            DEBUG_printf(("ippWrite: writing name = %d, \'%s\'\n", n, attr->name));
+            DEBUG_printf(("ippWriteIO: writing value tag=%x(%s)\n",
+                         attr->value_tag, ippTagString(attr->value_tag)));
+            DEBUG_printf(("ippWriteIO: writing name=%d,\"%s\"\n", n,
+                         attr->name));
 
             *bufptr++ = attr->value_tag;
            *bufptr++ = n >> 8;
@@ -1775,11 +1924,13 @@ ippWriteIO(void       *dst,             /* I - Destination */
            * and empty name for the collection member attribute...
            */
 
-            DEBUG_printf(("ippWrite: writing value tag = %x\n",
+            DEBUG_printf(("ippWriteIO: writing value tag=%x(memberName)\n",
                          IPP_TAG_MEMBERNAME));
-            DEBUG_printf(("ippWrite: writing name = %d, \'%s\'\n", n, attr->name));
-            DEBUG_printf(("ippWrite: writing value tag = %x\n", attr->value_tag));
-            DEBUG_puts("ippWrite: writing name = 0, \'\'\n");
+            DEBUG_printf(("ippWriteIO: writing name=%d,\"%s\"\n", n,
+                         attr->name));
+            DEBUG_printf(("ippWriteIO: writing value tag=%x(%s)\n",
+                         attr->value_tag, ippTagString(attr->value_tag)));
+            DEBUG_puts("ippWriteIO: writing name=0,\"\"\n");
 
             *bufptr++ = IPP_TAG_MEMBERNAME;
            *bufptr++ = 0;
@@ -1810,7 +1961,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
                  {
                     if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                    {
-                     DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                     DEBUG_puts("ippWriteIO: Could not write IPP "
+                                "attribute...");
                      return (IPP_ERROR);
                    }
 
@@ -1854,7 +2006,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
                  {
                     if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                    {
-                     DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                     DEBUG_puts("ippWriteIO: Could not write IPP "
+                                "attribute...");
                      return (IPP_ERROR);
                    }
 
@@ -1888,7 +2041,6 @@ ippWriteIO(void       *dst,               /* I - Destination */
            case IPP_TAG_TEXT :
            case IPP_TAG_NAME :
            case IPP_TAG_KEYWORD :
-           case IPP_TAG_STRING :
            case IPP_TAG_URI :
            case IPP_TAG_URISCHEME :
            case IPP_TAG_CHARSET :
@@ -1905,15 +2057,17 @@ ippWriteIO(void       *dst,             /* I - Destination */
                    * values with a zero-length name...
                    */
 
-                   DEBUG_printf(("ippWrite: writing value tag = %x\n",
-                                 attr->value_tag));
-                   DEBUG_printf(("ippWrite: writing name = 0, \'\'\n"));
+                   DEBUG_printf(("ippWriteIO: writing value tag=%x(%s)\n",
+                                 attr->value_tag,
+                                 ippTagString(attr->value_tag)));
+                   DEBUG_printf(("ippWriteIO: writing name=0,\"\"\n"));
 
                     if ((sizeof(buffer) - (bufptr - buffer)) < 3)
                    {
                       if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                      {
-                       DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                       DEBUG_puts("ippWriteIO: Could not write IPP "
+                                  "attribute...");
                        return (IPP_ERROR);
                      }
 
@@ -1933,14 +2087,15 @@ ippWriteIO(void       *dst,             /* I - Destination */
                   if (n > (sizeof(buffer) - 2))
                    return (IPP_ERROR);
 
-                  DEBUG_printf(("ippWrite: writing string = %d, \'%s\'\n", n,
+                  DEBUG_printf(("ippWriteIO: writing string=%d,\"%s\"\n", n,
                                value->string.text));
 
                   if ((int)(sizeof(buffer) - (bufptr - buffer)) < (n + 2))
                  {
                     if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                    {
-                     DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                     DEBUG_puts("ippWriteIO: Could not write IPP "
+                                "attribute...");
                      return (IPP_ERROR);
                    }
 
@@ -1950,7 +2105,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
                 /*
                  * All simple strings consist of the 2-byte length and
                  * character data without the trailing nul normally found
-                 * in C strings.  Also, strings cannot be longer than 32767
+                 * in C strings.  Also, strings cannot be longer than IPP_MAX_LENGTH
                  * bytes since the 2-byte length is a signed (twos-complement)
                  * value.
                  *
@@ -1977,7 +2132,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
                  {
                     if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                    {
-                     DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                     DEBUG_puts("ippWriteIO: Could not write IPP "
+                                "attribute...");
                      return (IPP_ERROR);
                    }
 
@@ -2020,7 +2176,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
                  {
                     if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                    {
-                     DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                     DEBUG_puts("ippWriteIO: Could not write IPP "
+                                "attribute...");
                      return (IPP_ERROR);
                    }
 
@@ -2071,7 +2228,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
                  {
                     if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                    {
-                     DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                     DEBUG_puts("ippWriteIO: Could not write IPP "
+                                "attribute...");
                      return (IPP_ERROR);
                    }
 
@@ -2128,7 +2286,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    {
                       if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                      {
-                       DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                       DEBUG_puts("ippWriteIO: Could not write IPP "
+                                  "attribute...");
                        return (IPP_ERROR);
                      }
 
@@ -2153,10 +2312,10 @@ ippWriteIO(void       *dst,             /* I - Destination */
                   n = 4;
 
                  if (value->string.charset != NULL)
-                    n += strlen(value->string.charset);
+                    n += (int)strlen(value->string.charset);
 
                  if (value->string.text != NULL)
-                    n += strlen(value->string.text);
+                    n += (int)strlen(value->string.text);
 
                   if (n > (sizeof(buffer) - 2))
                    return (IPP_ERROR);
@@ -2165,7 +2324,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
                  {
                     if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                    {
-                     DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                     DEBUG_puts("ippWriteIO: Could not write IPP "
+                                "attribute...");
                      return (IPP_ERROR);
                    }
 
@@ -2226,7 +2386,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
                  {
                     if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                    {
-                     DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                     DEBUG_puts("ippWriteIO: Could not write IPP "
+                                "attribute...");
                      return (IPP_ERROR);
                    }
 
@@ -2254,7 +2415,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
 
                   if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                  {
-                   DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                   DEBUG_puts("ippWriteIO: Could not write IPP "
+                              "attribute...");
                    return (IPP_ERROR);
                  }
 
@@ -2287,7 +2449,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
                    {
                       if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                      {
-                       DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                       DEBUG_puts("ippWriteIO: Could not write IPP "
+                                  "attribute...");
                        return (IPP_ERROR);
                      }
 
@@ -2315,7 +2478,8 @@ ippWriteIO(void       *dst,               /* I - Destination */
                  {
                     if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
                    {
-                     DEBUG_puts("ippWrite: Could not write IPP attribute...");
+                     DEBUG_puts("ippWriteIO: Could not write IPP "
+                                "attribute...");
                      return (IPP_ERROR);
                    }
 
@@ -2342,11 +2506,12 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
           if ((*cb)(dst, buffer, (int)(bufptr - buffer)) < 0)
          {
-           DEBUG_puts("ippWrite: Could not write IPP attribute...");
+           DEBUG_puts("ippWriteIO: Could not write IPP attribute...");
            return (IPP_ERROR);
          }
 
-          DEBUG_printf(("ippWrite: wrote %d bytes\n", bufptr - buffer));
+          DEBUG_printf(("ippWriteIO: wrote %d bytes\n",
+                       (int)(bufptr - buffer)));
 
         /*
           * If blocking is disabled, stop here...
@@ -2380,7 +2545,7 @@ ippWriteIO(void       *dst,               /* I - Destination */
 
          if ((*cb)(dst, buffer, n) < 0)
          {
-           DEBUG_puts("ippWrite: Could not write IPP end-tag...");
+           DEBUG_puts("ippWriteIO: Could not write IPP end-tag...");
            return (IPP_ERROR);
          }
 
@@ -2400,19 +2565,19 @@ ippWriteIO(void       *dst,             /* I - Destination */
 
 
 /*
- * '_ipp_add_attr()' - Add a new attribute to the request.
+ * '_ippAddAttr()' - Add a new attribute to the request.
  */
 
 ipp_attribute_t *                      /* O - New attribute */
-_ipp_add_attr(ipp_t *ipp,              /* I - IPP message */
-              int   num_values)                /* I - Number of values */
+_ippAddAttr(ipp_t *ipp,                        /* I - IPP message */
+            int   num_values)          /* I - Number of values */
 {
   ipp_attribute_t      *attr;          /* New attribute */
 
 
-  DEBUG_printf(("_ipp_add_attr(%p, %d)\n", ipp, num_values));
+  DEBUG_printf(("_ippAddAttr(ipp=%p, num_values=%d)\n", ipp, num_values));
 
-  if (ipp == NULL || num_values < 0)
+  if (!ipp || num_values < 0)
     return (NULL);
 
   attr = calloc(sizeof(ipp_attribute_t) +
@@ -2430,31 +2595,30 @@ _ipp_add_attr(ipp_t *ipp,               /* I - IPP message */
     ipp->last = attr;
   }
 
-  DEBUG_printf(("_ipp_add_attr(): %p\n", attr));
+  DEBUG_printf(("_ippAddAttr(): %p\n", attr));
 
   return (attr);
 }
 
 
 /*
- * '_ipp_free_attr()' - Free an attribute.
+ * '_ippFreeAttr()' - Free an attribute.
  */
 
 void
-_ipp_free_attr(ipp_attribute_t *attr)  /* I - Attribute to free */
+_ippFreeAttr(ipp_attribute_t *attr)    /* I - Attribute to free */
 {
   int          i;                      /* Looping var */
   ipp_value_t  *value;                 /* Current value */
 
 
-  DEBUG_printf(("_ipp_free_attr(): %p\n", attr));
+  DEBUG_printf(("_ippFreeAttr(attr=%p)\n", attr));
 
   switch (attr->value_tag)
   {
     case IPP_TAG_TEXT :
     case IPP_TAG_NAME :
     case IPP_TAG_KEYWORD :
-    case IPP_TAG_STRING :
     case IPP_TAG_URI :
     case IPP_TAG_URISCHEME :
     case IPP_TAG_CHARSET :
@@ -2463,7 +2627,7 @@ _ipp_free_attr(ipp_attribute_t *attr)     /* I - Attribute to free */
        for (i = 0, value = attr->values;
             i < attr->num_values;
             i ++, value ++)
-         _cups_sp_free(value->string.text);
+         _cupsStrFree(value->string.text);
        break;
 
     case IPP_TAG_TEXTLANG :
@@ -2473,8 +2637,8 @@ _ipp_free_attr(ipp_attribute_t *attr)     /* I - Attribute to free */
             i ++, value ++)
        {
          if (value->string.charset && i == 0)
-           _cups_sp_free(value->string.charset);
-         _cups_sp_free(value->string.text);
+           _cupsStrFree(value->string.charset);
+         _cupsStrFree(value->string.text);
        }
        break;
 
@@ -2493,6 +2657,13 @@ _ipp_free_attr(ipp_attribute_t *attr)    /* I - Attribute to free */
           ippDelete(value->collection);
        break;
 
+    case IPP_TAG_STRING :
+       for (i = 0, value = attr->values;
+            i < attr->num_values;
+            i ++, value ++)
+         free(value->unknown.data);
+        break;
+
     default :
         if (!((int)attr->value_tag & IPP_TAG_COPY))
        {
@@ -2506,7 +2677,7 @@ _ipp_free_attr(ipp_attribute_t *attr)     /* I - Attribute to free */
   }
 
   if (attr->name)
-    _cups_sp_free(attr->name);
+    _cupsStrFree(attr->name);
 
   free(attr);
 }
@@ -2556,10 +2727,10 @@ ipp_length(ipp_t *ipp,                  /* I - IPP message or collection */
     if (!attr->name)
       continue;
 
-    DEBUG_printf(("attr->name = %s, attr->num_values = %d, bytes = %d\n",
-                  attr->name, attr->num_values, bytes));
+    DEBUG_printf(("ipp_length: attr->name=\"%s\", attr->num_values=%d, "
+                  "bytes=%d\n", attr->name, attr->num_values, bytes));
 
-    bytes += strlen(attr->name);       /* Name */
+    bytes += (int)strlen(attr->name);  /* Name */
     bytes += attr->num_values;         /* Value tag for each value */
     bytes += 2 * attr->num_values;     /* Name lengths */
     bytes += 2 * attr->num_values;     /* Value lengths */
@@ -2581,7 +2752,6 @@ ipp_length(ipp_t *ipp,                    /* I - IPP message or collection */
       case IPP_TAG_TEXT :
       case IPP_TAG_NAME :
       case IPP_TAG_KEYWORD :
-      case IPP_TAG_STRING :
       case IPP_TAG_URI :
       case IPP_TAG_URISCHEME :
       case IPP_TAG_CHARSET :
@@ -2591,7 +2761,7 @@ ipp_length(ipp_t *ipp,                    /* I - IPP message or collection */
               i < attr->num_values;
               i ++, value ++)
            if (value->string.text != NULL)
-             bytes += strlen(value->string.text);
+             bytes += (int)strlen(value->string.text);
          break;
 
       case IPP_TAG_DATE :
@@ -2615,10 +2785,10 @@ ipp_length(ipp_t *ipp,                  /* I - IPP message or collection */
               i ++, value ++)
          {
            if (value->string.charset != NULL)
-             bytes += strlen(value->string.charset);
+             bytes += (int)strlen(value->string.charset);
 
            if (value->string.text != NULL)
-             bytes += strlen(value->string.text);
+             bytes += (int)strlen(value->string.text);
          }
          break;
 
@@ -2626,7 +2796,7 @@ ipp_length(ipp_t *ipp,                    /* I - IPP message or collection */
          for (i = 0, value = attr->values;
               i < attr->num_values;
               i ++, value ++)
-            bytes += ipp_length(value->collection, 1);
+            bytes += (int)ipp_length(value->collection, 1);
          break;
 
       default :
@@ -2648,7 +2818,7 @@ ipp_length(ipp_t *ipp,                    /* I - IPP message or collection */
   else
     bytes ++;
 
-  DEBUG_printf(("bytes = %d\n", bytes));
+  DEBUG_printf(("ipp_length: bytes=%d\n", bytes));
 
   return (bytes);
 }
@@ -2669,15 +2839,18 @@ ipp_read_http(http_t      *http,        /* I - Client connection */
   
 
   DEBUG_printf(("ipp_read_http(http=%p, buffer=%p, length=%d)\n",
-                http, buffer, length));
+                http, buffer, (int)length));
 
  /*
   * Loop until all bytes are read...
   */
 
-  for (tbytes = 0, bytes = 0; tbytes < length; tbytes += bytes, buffer += bytes)
+  for (tbytes = 0, bytes = 0;
+       tbytes < (int)length;
+       tbytes += bytes, buffer += bytes)
   {
-    DEBUG_printf(("tbytes = %d, http->state = %d\n", tbytes, http->state));
+    DEBUG_printf(("ipp_read_http: tbytes=%d, http->state=%d\n", tbytes,
+                  http->state));
 
     if (http->state == HTTP_WAITING)
       break;
@@ -2688,8 +2861,8 @@ ipp_read_http(http_t      *http,  /* I - Client connection */
       * Do "fast read" from HTTP buffer directly...
       */
 
-      if (http->used > (length - tbytes))
-        bytes = length - tbytes;
+      if (http->used > (int)(length - tbytes))
+        bytes = (int)(length - tbytes);
       else
         bytes = http->used;
 
@@ -2739,10 +2912,10 @@ ipp_read_http(http_t      *http,        /* I - Client connection */
       if (!http->blocking)
       {
        /*
-        * Wait up to 1 second for more data on non-blocking sockets...
+        * Wait up to 10 seconds for more data on non-blocking sockets...
        */
 
-       if (!httpWait(http, 1000))
+       if (!httpWait(http, 10000))
        {
         /*
           * Signal no data...
@@ -2765,7 +2938,7 @@ ipp_read_http(http_t      *http,  /* I - Client connection */
   if (tbytes == 0 && bytes < 0)
     tbytes = -1;
 
-  DEBUG_printf(("returning %d bytes...\n", tbytes));
+  DEBUG_printf(("ipp_read_http: returning %d bytes...\n", tbytes));
 
   return (tbytes);
 }
@@ -2780,7 +2953,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
+  return ((ssize_t)read(*fd, buffer, (unsigned)length));
+#else
   return (read(*fd, buffer, length));
+#endif /* WIN32 */
 }
 
 
@@ -2793,10 +2970,37 @@ 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
+  return ((ssize_t)write(*fd, buffer, (unsigned)length));
+#else
   return (write(*fd, buffer, length));
+#endif /* WIN32 */
+}
+
+
+#ifdef __linux
+/*
+ * The following symbol definitions are provided only for KDE
+ * compatibility during the CUPS 1.2 testing period and will be
+ * removed in a future release of CUPS.  These are PRIVATE APIs
+ * from CUPS 1.1.x that the KDE developers chose to use...
+ */
+
+ipp_attribute_t *                      /* O - New attribute */
+_ipp_add_attr(ipp_t *ipp,              /* I - IPP message */
+              int   num_values)                /* I - Number of values */
+{
+  return (_ippAddAttr(ipp, num_values));
+}
+
+void
+_ipp_free_attr(ipp_attribute_t *attr)  /* I - Attribute to free */
+{
+  _ippFreeAttr(attr);
 }
+#endif /* __linux */
 
 
 /*
- * End of "$Id: ipp.c 5047 2006-02-02 05:14:15Z mike $".
+ * End of "$Id: ipp.c 7847 2008-08-19 04:22:14Z mike $".
  */