/*
- * "$Id: ipp.c 5023 2006-01-29 14:39:44Z mike $"
+ * "$Id: ipp.c 5047 2006-02-02 05:14:15Z mike $"
*
* Internet Printing Protocol support functions for the Common UNIX
* Printing System (CUPS).
if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = IPP_TAG_BOOLEAN;
attr->values[0].boolean = value;
if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = IPP_TAG_BOOLEAN;
if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = IPP_TAG_BEGIN_COLLECTION;
attr->values[0].collection = value;
if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = IPP_TAG_BEGIN_COLLECTION;
if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = IPP_TAG_DATE;
memcpy(attr->values[0].date, value, 11);
if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = type;
attr->values[0].integer = value;
if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = type;
* Initialize the attribute data...
*/
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = IPP_TAG_STRING;
attr->values[0].unknown.length = datalen;
const char *value) /* I - Value */
{
ipp_attribute_t *attr; /* New attribute */
+ char buffer[1024], /* Language/charset value buffer */
+ *bufptr; /* Pointer into buffer */
if (ipp == NULL || name == NULL)
* Force value to be English for the POSIX locale...
*/
- if (type == IPP_TAG_LANGUAGE && strcasecmp(value, "C") == 0)
+ if (type == IPP_TAG_LANGUAGE && !strcasecmp(value, "C"))
value = "en";
- /*
- * Initialize the attribute data...
- */
-
- attr->name = strdup(name);
- attr->group_tag = group;
- attr->value_tag = type;
- attr->values[0].string.charset = ((int)type & IPP_TAG_COPY) ? (char *)charset :
- charset ? strdup(charset) : NULL;
- attr->values[0].string.text = ((int)type & IPP_TAG_COPY) ? (char *)value :
- value ? strdup(value) : NULL;
-
/*
* Convert language values to lowercase and change _ to - as needed...
*/
- if ((type == IPP_TAG_LANGUAGE || type == IPP_TAG_CHARSET) &&
- attr->values[0].string.text)
+ if ((type == IPP_TAG_LANGUAGE || type == IPP_TAG_CHARSET) && value)
{
- char *p;
-
+ strlcpy(buffer, value, sizeof(buffer));
+ value = buffer;
- for (p = attr->values[0].string.text; *p; p ++)
- if (*p == '_')
- *p = '-';
+ for (bufptr = buffer; *bufptr; bufptr ++)
+ if (*bufptr == '_')
+ *bufptr = '-';
else
- *p = tolower(*p & 255);
+ *bufptr = tolower(*bufptr & 255);
}
+ /*
+ * Initialize the attribute data...
+ */
+
+ attr->name = _cups_sp_alloc(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;
+ attr->values[0].string.text = ((int)type & IPP_TAG_COPY) ? (char *)value :
+ value ? _cups_sp_alloc(value) : NULL;
+
return (attr);
}
* Initialize the attribute data...
*/
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = type;
{
if (i == 0)
value->string.charset = ((int)type & IPP_TAG_COPY) ? (char *)charset :
- charset ? strdup(charset) : NULL;
+ charset ? _cups_sp_alloc(charset) : NULL;
else
value->string.charset = attr->values[0].string.charset;
* Force language to be English for the POSIX locale...
*/
- if (type == IPP_TAG_LANGUAGE && strcasecmp(values[i], "C") == 0)
+ if (type == IPP_TAG_LANGUAGE && !strcasecmp(values[i], "C"))
value->string.text = ((int)type & IPP_TAG_COPY) ? "en" :
- strdup("en");
+ _cups_sp_alloc("en");
else
value->string.text = ((int)type & IPP_TAG_COPY) ? (char *)values[i] :
- strdup(values[i]);
+ _cups_sp_alloc(values[i]);
}
}
if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = IPP_TAG_RANGE;
attr->values[0].range.lower = lower;
if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = IPP_TAG_RANGE;
if ((attr = _ipp_add_attr(ipp, 1)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = IPP_TAG_RESOLUTION;
attr->values[0].resolution.xres = xres;
if ((attr = _ipp_add_attr(ipp, num_values)) == NULL)
return (NULL);
- attr->name = strdup(name);
+ attr->name = _cups_sp_alloc(name);
attr->group_tag = group;
attr->value_tag = IPP_TAG_RESOLUTION;
/*
* 'ippReadIO()' - Read data for an IPP message.
*
- * @since CUPS 1.1.19@
+ * @since CUPS 1.2@
*/
ipp_state_t /* O - Current state */
{
int n; /* Length of data */
unsigned char buffer[32768], /* Data buffer */
+ string[255], /* Small string buffer */
*bufptr; /* Pointer into buffer */
ipp_attribute_t *attr; /* Current attribute */
ipp_tag_t tag; /* Current tag */
attr->group_tag = ipp->curtag;
attr->value_tag = tag;
- attr->name = strdup((char *)buffer);
+ attr->name = _cups_sp_alloc((char *)buffer);
attr->num_values = 0;
}
else
case IPP_TAG_CHARSET :
case IPP_TAG_LANGUAGE :
case IPP_TAG_MIMETYPE :
- value->string.text = calloc(n + 1, 1);
-
- if ((*cb)(src, (ipp_uchar_t *)value->string.text, n) < n)
+ if ((*cb)(src, buffer, n) < n)
{
- DEBUG_puts("ippReadIO: Unable to read string value!");
+ DEBUG_puts("ippReadIO: unable to read name!");
return (IPP_ERROR);
}
+ buffer[n] = '\0';
+ value->string.text = _cups_sp_alloc((char *)buffer);
DEBUG_printf(("ippReadIO: value = \'%s\'\n",
value->string.text));
break;
n = (bufptr[0] << 8) | bufptr[1];
- value->string.charset = calloc(n + 1, 1);
+ if (n >= sizeof(string))
+ {
+ memcpy(string, bufptr + 2, sizeof(string) - 1);
+ string[sizeof(string) - 1] = '\0';
+ }
+ else
+ {
+ memcpy(string, bufptr + 2, n);
+ string[n] = '\0';
+ }
- memcpy(value->string.charset,
- bufptr + 2, n);
+ value->string.charset = _cups_sp_alloc((char *)string);
bufptr += 2 + n;
n = (bufptr[0] << 8) | bufptr[1];
- value->string.text = calloc(n + 1, 1);
-
- memcpy(value->string.text,
- bufptr + 2, n);
+ bufptr[2 + n] = '\0';
+ value->string.text = _cups_sp_alloc((char *)bufptr + 2);
break;
case IPP_TAG_BEGIN_COLLECTION :
case IPP_TAG_MEMBERNAME :
/*
- * The value is the name of the member in the collection,
- * which we need to carry over...
+ * The value the name of the member in the collection, which
+ * we need to carry over...
*/
- attr->name = calloc(n + 1, 1);
-
- if ((*cb)(src, (ipp_uchar_t *)attr->name, n) < n)
+ if ((*cb)(src, buffer, n) < n)
{
DEBUG_puts("ippReadIO: Unable to read member name value!");
return (IPP_ERROR);
}
+ buffer[n] = '\0';
+ attr->name = _cups_sp_alloc((char *)buffer);
+
/*
* Since collection members are encoded differently than
* regular attributes, make sure we don't start with an
/*
* 'ippWriteIO()' - Write data for an IPP message.
*
- * @since CUPS 1.1.19@
+ * @since CUPS 1.2@
*/
ipp_state_t /* O - Current state */
for (i = 0, value = attr->values;
i < attr->num_values;
i ++, value ++)
- free(value->string.text);
+ _cups_sp_free(value->string.text);
break;
case IPP_TAG_TEXTLANG :
i ++, value ++)
{
if (value->string.charset && i == 0)
- free(value->string.charset);
- free(value->string.text);
+ _cups_sp_free(value->string.charset);
+ _cups_sp_free(value->string.text);
}
break;
+ case IPP_TAG_INTEGER :
+ case IPP_TAG_ENUM :
+ case IPP_TAG_BOOLEAN :
+ case IPP_TAG_DATE :
+ case IPP_TAG_RESOLUTION :
+ case IPP_TAG_RANGE :
+ break;
+
+ case IPP_TAG_BEGIN_COLLECTION :
+ for (i = 0, value = attr->values;
+ i < attr->num_values;
+ i ++, value ++)
+ ippDelete(value->collection);
+ break;
+
default :
- break; /* anti-compiler-warning-code */
+ if (!((int)attr->value_tag & IPP_TAG_COPY))
+ {
+ for (i = 0, value = attr->values;
+ i < attr->num_values;
+ i ++, value ++)
+ if (value->unknown.data)
+ free(value->unknown.data);
+ }
+ break;
}
if (attr->name)
- free(attr->name);
+ _cups_sp_free(attr->name);
free(attr);
}
for (i = 0, value = attr->values;
i < attr->num_values;
i ++, value ++)
- bytes += ipp_length(attr->values[i].collection, 1);
+ bytes += ipp_length(value->collection, 1);
break;
default :
for (i = 0, value = attr->values;
i < attr->num_values;
i ++, value ++)
- bytes += attr->values[0].unknown.length;
+ bytes += value->unknown.length;
break;
}
}
/*
- * End of "$Id: ipp.c 5023 2006-01-29 14:39:44Z mike $".
+ * End of "$Id: ipp.c 5047 2006-02-02 05:14:15Z mike $".
*/