4 * Internet Printing Protocol functions for CUPS.
6 * Copyright 2007-2015 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * Include necessary headers...
22 #include "cups-private.h"
33 static ipp_attribute_t
*ipp_add_attr(ipp_t
*ipp
, const char *name
,
34 ipp_tag_t group_tag
, ipp_tag_t value_tag
,
36 static void ipp_free_values(ipp_attribute_t
*attr
, int element
,
38 static char *ipp_get_code(const char *locale
, char *buffer
,
40 __attribute__((nonnull(1,2)));
41 static char *ipp_lang_code(const char *locale
, char *buffer
,
43 __attribute__((nonnull(1,2)));
44 static size_t ipp_length(ipp_t
*ipp
, int collection
);
45 static ssize_t
ipp_read_http(http_t
*http
, ipp_uchar_t
*buffer
,
47 static ssize_t
ipp_read_file(int *fd
, ipp_uchar_t
*buffer
,
49 static void ipp_set_error(ipp_status_t status
, const char *format
,
51 static _ipp_value_t
*ipp_set_value(ipp_t
*ipp
, ipp_attribute_t
**attr
,
53 static ssize_t
ipp_write_file(int *fd
, ipp_uchar_t
*buffer
,
58 * '_cupsBufferGet()' - Get a read/write buffer.
61 char * /* O - Buffer */
62 _cupsBufferGet(size_t size
) /* I - Size required */
64 _cups_buffer_t
*buffer
; /* Current buffer */
65 _cups_globals_t
*cg
= _cupsGlobals();
69 for (buffer
= cg
->cups_buffers
; buffer
; buffer
= buffer
->next
)
70 if (!buffer
->used
&& buffer
->size
>= size
)
75 if ((buffer
= malloc(sizeof(_cups_buffer_t
) + size
- 1)) == NULL
)
78 buffer
->next
= cg
->cups_buffers
;
80 cg
->cups_buffers
= buffer
;
90 * '_cupsBufferRelease()' - Release a read/write buffer.
94 _cupsBufferRelease(char *b
) /* I - Buffer to release */
96 _cups_buffer_t
*buffer
; /* Buffer */
100 * Mark this buffer as unused...
103 buffer
= (_cups_buffer_t
*)(b
- offsetof(_cups_buffer_t
, d
));
109 * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
111 * The @code ipp@ parameter refers to an IPP message previously created using
112 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
114 * The @code group@ parameter specifies the IPP attribute group tag: none
115 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
116 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
117 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
118 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
121 ipp_attribute_t
* /* O - New attribute */
122 ippAddBoolean(ipp_t
*ipp
, /* I - IPP message */
123 ipp_tag_t group
, /* I - IPP group */
124 const char *name
, /* I - Name of attribute */
125 char value
) /* I - Value of attribute */
127 ipp_attribute_t
*attr
; /* New attribute */
130 DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)", (void *)ipp
, group
, ippTagString(group
), name
, value
));
133 * Range check input...
136 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
137 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
141 * Create the attribute...
144 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, 1)) == NULL
)
147 attr
->values
[0].boolean
= value
;
154 * 'ippAddBooleans()' - Add an array of boolean values.
156 * The @code ipp@ parameter refers to an IPP message previously created using
157 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
159 * The @code group@ parameter specifies the IPP attribute group tag: none
160 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
161 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
162 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
163 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
166 ipp_attribute_t
* /* O - New attribute */
167 ippAddBooleans(ipp_t
*ipp
, /* I - IPP message */
168 ipp_tag_t group
, /* I - IPP group */
169 const char *name
, /* I - Name of attribute */
170 int num_values
, /* I - Number of values */
171 const char *values
) /* I - Values */
173 int i
; /* Looping var */
174 ipp_attribute_t
*attr
; /* New attribute */
175 _ipp_value_t
*value
; /* Current value */
178 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
));
181 * Range check input...
184 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
185 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
190 * Create the attribute...
193 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, num_values
)) == NULL
)
198 for (i
= num_values
, value
= attr
->values
;
201 value
->boolean
= *values
++;
209 * 'ippAddCollection()' - Add a collection value.
211 * The @code ipp@ parameter refers to an IPP message previously created using
212 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
214 * The @code group@ parameter specifies the IPP attribute group tag: none
215 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
216 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
217 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
218 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
220 * @since CUPS 1.1.19/OS X 10.3@
223 ipp_attribute_t
* /* O - New attribute */
224 ippAddCollection(ipp_t
*ipp
, /* I - IPP message */
225 ipp_tag_t group
, /* I - IPP group */
226 const char *name
, /* I - Name of attribute */
227 ipp_t
*value
) /* I - Value */
229 ipp_attribute_t
*attr
; /* New attribute */
232 DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
235 * Range check input...
238 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
239 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
243 * Create the attribute...
246 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
, 1)) == NULL
)
249 attr
->values
[0].collection
= value
;
259 * 'ippAddCollections()' - Add an array of collection values.
261 * The @code ipp@ parameter refers to an IPP message previously created using
262 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
264 * The @code group@ parameter specifies the IPP attribute group tag: none
265 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
266 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
267 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
268 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
270 * @since CUPS 1.1.19/OS X 10.3@
273 ipp_attribute_t
* /* O - New attribute */
275 ipp_t
*ipp
, /* I - IPP message */
276 ipp_tag_t group
, /* I - IPP group */
277 const char *name
, /* I - Name of attribute */
278 int num_values
, /* I - Number of values */
279 const ipp_t
**values
) /* I - Values */
281 int i
; /* Looping var */
282 ipp_attribute_t
*attr
; /* New attribute */
283 _ipp_value_t
*value
; /* Current value */
286 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
));
289 * Range check input...
292 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
293 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
298 * Create the attribute...
301 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
,
302 num_values
)) == NULL
)
307 for (i
= num_values
, value
= attr
->values
;
311 value
->collection
= (ipp_t
*)*values
++;
312 value
->collection
->use
++;
321 * 'ippAddDate()' - Add a date attribute to an IPP message.
323 * The @code ipp@ parameter refers to an IPP message previously created using
324 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
326 * The @code group@ parameter specifies the IPP attribute group tag: none
327 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
328 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
329 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
330 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
333 ipp_attribute_t
* /* O - New attribute */
334 ippAddDate(ipp_t
*ipp
, /* I - IPP message */
335 ipp_tag_t group
, /* I - IPP group */
336 const char *name
, /* I - Name of attribute */
337 const ipp_uchar_t
*value
) /* I - Value */
339 ipp_attribute_t
*attr
; /* New attribute */
342 DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
345 * Range check input...
348 if (!ipp
|| !name
|| !value
|| group
< IPP_TAG_ZERO
||
349 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
353 * Create the attribute...
356 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_DATE
, 1)) == NULL
)
359 memcpy(attr
->values
[0].date
, value
, 11);
366 * 'ippAddInteger()' - Add a integer attribute to an IPP message.
368 * The @code ipp@ parameter refers to an IPP message previously created using
369 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
371 * The @code group@ parameter specifies the IPP attribute group tag: none
372 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
373 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
374 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
375 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
377 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
378 * (@code IPP_TAG_INTEGER@).
381 ipp_attribute_t
* /* O - New attribute */
382 ippAddInteger(ipp_t
*ipp
, /* I - IPP message */
383 ipp_tag_t group
, /* I - IPP group */
384 ipp_tag_t value_tag
, /* I - Type of attribute */
385 const char *name
, /* I - Name of attribute */
386 int value
) /* I - Value of attribute */
388 ipp_attribute_t
*attr
; /* New attribute */
391 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
));
393 value_tag
&= IPP_TAG_CUPS_MASK
;
396 * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
400 if (value_tag
>= IPP_TAG_UNSUPPORTED_VALUE
&& value_tag
<= IPP_TAG_ADMINDEFINE
)
401 return (ippAddOutOfBand(ipp
, group
, value_tag
, name
));
404 * Range check input...
408 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
409 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
410 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
))
413 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
414 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
419 * Create the attribute...
422 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
425 attr
->values
[0].integer
= value
;
432 * 'ippAddIntegers()' - Add an array of integer values.
434 * The @code ipp@ parameter refers to an IPP message previously created using
435 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
437 * The @code group@ parameter specifies the IPP attribute group tag: none
438 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
439 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
440 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
441 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
443 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
444 * (@code IPP_TAG_INTEGER@).
447 ipp_attribute_t
* /* O - New attribute */
448 ippAddIntegers(ipp_t
*ipp
, /* I - IPP message */
449 ipp_tag_t group
, /* I - IPP group */
450 ipp_tag_t value_tag
, /* I - Type of attribute */
451 const char *name
, /* I - Name of attribute */
452 int num_values
, /* I - Number of values */
453 const int *values
) /* I - Values */
455 int i
; /* Looping var */
456 ipp_attribute_t
*attr
; /* New attribute */
457 _ipp_value_t
*value
; /* Current value */
460 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
));
462 value_tag
&= IPP_TAG_CUPS_MASK
;
465 * Range check input...
469 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
470 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
471 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
) ||
475 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
476 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
482 * Create the attribute...
485 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
490 for (i
= num_values
, value
= attr
->values
;
493 value
->integer
= *values
++;
501 * 'ippAddOctetString()' - Add an octetString value to an IPP message.
503 * The @code ipp@ parameter refers to an IPP message previously created using
504 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
506 * The @code group@ parameter specifies the IPP attribute group tag: none
507 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
508 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
509 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
510 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
512 * @since CUPS 1.2/OS X 10.5@
515 ipp_attribute_t
* /* O - New attribute */
516 ippAddOctetString(ipp_t
*ipp
, /* I - IPP message */
517 ipp_tag_t group
, /* I - IPP group */
518 const char *name
, /* I - Name of attribute */
519 const void *data
, /* I - octetString data */
520 int datalen
) /* I - Length of data in bytes */
522 ipp_attribute_t
*attr
; /* New attribute */
525 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
526 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
527 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
530 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_STRING
, 1)) == NULL
)
534 * Initialize the attribute data...
537 attr
->values
[0].unknown
.length
= datalen
;
541 if ((attr
->values
[0].unknown
.data
= malloc((size_t)datalen
)) == NULL
)
543 ippDeleteAttribute(ipp
, attr
);
547 memcpy(attr
->values
[0].unknown
.data
, data
, (size_t)datalen
);
551 * Return the new attribute...
559 * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
561 * The @code ipp@ parameter refers to an IPP message previously created using
562 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
564 * The @code group@ parameter specifies the IPP attribute group tag: none
565 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
566 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
567 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
568 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
570 * Supported out-of-band values include unsupported-value
571 * (@code IPP_TAG_UNSUPPORTED_VALUE@), default (@code IPP_TAG_DEFAULT@), unknown
572 * (@code IPP_TAG_UNKNOWN@), no-value (@code IPP_TAG_NOVALUE@), not-settable
573 * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
574 * admin-define (@code IPP_TAG_ADMINDEFINE@).
576 * @since CUPS 1.6/OS X 10.8@
579 ipp_attribute_t
* /* O - New attribute */
580 ippAddOutOfBand(ipp_t
*ipp
, /* I - IPP message */
581 ipp_tag_t group
, /* I - IPP group */
582 ipp_tag_t value_tag
, /* I - Type of attribute */
583 const char *name
) /* I - Name of attribute */
585 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
));
587 value_tag
&= IPP_TAG_CUPS_MASK
;
590 * Range check input...
593 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
594 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
595 (value_tag
!= IPP_TAG_UNSUPPORTED_VALUE
&&
596 value_tag
!= IPP_TAG_DEFAULT
&&
597 value_tag
!= IPP_TAG_UNKNOWN
&&
598 value_tag
!= IPP_TAG_NOVALUE
&&
599 value_tag
!= IPP_TAG_NOTSETTABLE
&&
600 value_tag
!= IPP_TAG_DELETEATTR
&&
601 value_tag
!= IPP_TAG_ADMINDEFINE
))
605 * Create the attribute...
608 return (ipp_add_attr(ipp
, name
, group
, value_tag
, 1));
613 * 'ippAddRange()' - Add a range of values to an IPP message.
615 * The @code ipp@ parameter refers to an IPP message previously created using
616 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
618 * The @code group@ parameter specifies the IPP attribute group tag: none
619 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
620 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
621 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
622 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
624 * The @code lower@ parameter must be less than or equal to the @code upper@ parameter.
627 ipp_attribute_t
* /* O - New attribute */
628 ippAddRange(ipp_t
*ipp
, /* I - IPP message */
629 ipp_tag_t group
, /* I - IPP group */
630 const char *name
, /* I - Name of attribute */
631 int lower
, /* I - Lower value */
632 int upper
) /* I - Upper value */
634 ipp_attribute_t
*attr
; /* New attribute */
637 DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, upper=%d)", (void *)ipp
, group
, ippTagString(group
), name
, lower
, upper
));
640 * Range check input...
643 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
644 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
648 * Create the attribute...
651 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, 1)) == NULL
)
654 attr
->values
[0].range
.lower
= lower
;
655 attr
->values
[0].range
.upper
= upper
;
662 * 'ippAddRanges()' - Add ranges of values to an IPP message.
664 * The @code ipp@ parameter refers to an IPP message previously created using
665 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
667 * The @code group@ parameter specifies the IPP attribute group tag: none
668 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
669 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
670 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
671 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
674 ipp_attribute_t
* /* O - New attribute */
675 ippAddRanges(ipp_t
*ipp
, /* I - IPP message */
676 ipp_tag_t group
, /* I - IPP group */
677 const char *name
, /* I - Name of attribute */
678 int num_values
, /* I - Number of values */
679 const int *lower
, /* I - Lower values */
680 const int *upper
) /* I - Upper values */
682 int i
; /* Looping var */
683 ipp_attribute_t
*attr
; /* New attribute */
684 _ipp_value_t
*value
; /* Current value */
687 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
));
690 * Range check input...
693 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
694 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
699 * Create the attribute...
702 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, num_values
)) == NULL
)
707 for (i
= num_values
, value
= attr
->values
;
711 value
->range
.lower
= *lower
++;
712 value
->range
.upper
= *upper
++;
721 * 'ippAddResolution()' - Add a resolution value to an IPP message.
723 * The @code ipp@ parameter refers to an IPP message previously created using
724 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
726 * The @code group@ parameter specifies the IPP attribute group tag: none
727 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
728 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
729 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
730 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
733 ipp_attribute_t
* /* O - New attribute */
734 ippAddResolution(ipp_t
*ipp
, /* I - IPP message */
735 ipp_tag_t group
, /* I - IPP group */
736 const char *name
, /* I - Name of attribute */
737 ipp_res_t units
, /* I - Units for resolution */
738 int xres
, /* I - X resolution */
739 int yres
) /* I - Y resolution */
741 ipp_attribute_t
*attr
; /* New attribute */
744 DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", units=%d, xres=%d, yres=%d)", (void *)ipp
, group
,
745 ippTagString(group
), name
, units
, xres
, yres
));
748 * Range check input...
751 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
752 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
753 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
||
754 xres
< 0 || yres
< 0)
758 * Create the attribute...
761 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, 1)) == NULL
)
764 attr
->values
[0].resolution
.xres
= xres
;
765 attr
->values
[0].resolution
.yres
= yres
;
766 attr
->values
[0].resolution
.units
= units
;
773 * 'ippAddResolutions()' - Add resolution values to an IPP message.
775 * The @code ipp@ parameter refers to an IPP message previously created using
776 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
778 * The @code group@ parameter specifies the IPP attribute group tag: none
779 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
780 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
781 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
782 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
785 ipp_attribute_t
* /* O - New attribute */
786 ippAddResolutions(ipp_t
*ipp
, /* I - IPP message */
787 ipp_tag_t group
, /* I - IPP group */
788 const char *name
, /* I - Name of attribute */
789 int num_values
,/* I - Number of values */
790 ipp_res_t units
, /* I - Units for resolution */
791 const int *xres
, /* I - X resolutions */
792 const int *yres
) /* I - Y resolutions */
794 int i
; /* Looping var */
795 ipp_attribute_t
*attr
; /* New attribute */
796 _ipp_value_t
*value
; /* Current value */
799 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
));
802 * Range check input...
805 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
806 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
808 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
)
812 * Create the attribute...
815 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, num_values
)) == NULL
)
820 for (i
= num_values
, value
= attr
->values
;
824 value
->resolution
.xres
= *xres
++;
825 value
->resolution
.yres
= *yres
++;
826 value
->resolution
.units
= units
;
835 * 'ippAddSeparator()' - Add a group separator to an IPP message.
837 * The @code ipp@ parameter refers to an IPP message previously created using
838 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
841 ipp_attribute_t
* /* O - New attribute */
842 ippAddSeparator(ipp_t
*ipp
) /* I - IPP message */
844 DEBUG_printf(("ippAddSeparator(ipp=%p)", (void *)ipp
));
847 * Range check input...
854 * Create the attribute...
857 return (ipp_add_attr(ipp
, NULL
, IPP_TAG_ZERO
, IPP_TAG_ZERO
, 0));
862 * 'ippAddString()' - Add a language-encoded string to an IPP message.
864 * The @code ipp@ parameter refers to an IPP message previously created using
865 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
867 * The @code group@ parameter specifies the IPP attribute group tag: none
868 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
869 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
870 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
871 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
873 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
874 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
875 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
876 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
877 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
878 * (@code IPP_TAG_URISCHEME@).
880 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
881 * textWithLanguage string values and must be @code NULL@ for all other string values.
884 ipp_attribute_t
* /* O - New attribute */
885 ippAddString(ipp_t
*ipp
, /* I - IPP message */
886 ipp_tag_t group
, /* I - IPP group */
887 ipp_tag_t value_tag
, /* I - Type of attribute */
888 const char *name
, /* I - Name of attribute */
889 const char *language
, /* I - Language code */
890 const char *value
) /* I - Value */
892 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
893 ipp_attribute_t
*attr
; /* New attribute */
894 char code
[IPP_MAX_LANGUAGE
];
895 /* Charset/language code buffer */
898 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
));
901 * Range check input...
904 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
907 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
908 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
909 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
910 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
)
913 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
914 != (language
!= NULL
))
917 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
918 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
923 * See if we need to map charset, language, or locale values...
926 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
927 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
928 value_tag
= temp_tag
; /* Don't do a fast copy */
929 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
) &&
930 strcmp(value
, ipp_get_code(value
, code
, sizeof(code
))))
931 value_tag
= temp_tag
; /* Don't do a fast copy */
932 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
) &&
933 strcmp(value
, ipp_lang_code(value
, code
, sizeof(code
))))
934 value_tag
= temp_tag
; /* Don't do a fast copy */
937 * Create the attribute...
940 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
944 * Initialize the attribute data...
947 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
949 attr
->values
[0].string
.language
= (char *)language
;
950 attr
->values
[0].string
.text
= (char *)value
;
955 attr
->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
960 if (value_tag
== IPP_TAG_CHARSET
)
961 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_get_code(value
, code
,
963 else if (value_tag
== IPP_TAG_LANGUAGE
)
964 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_lang_code(value
, code
,
967 attr
->values
[0].string
.text
= _cupsStrAlloc(value
);
976 * 'ippAddStringf()' - Add a formatted string to an IPP message.
978 * The @code ipp@ parameter refers to an IPP message previously created using
979 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
981 * The @code group@ parameter specifies the IPP attribute group tag: none
982 * (@code IPP_TAG_ZERO@, for member attributes), document
983 * (@code IPP_TAG_DOCUMENT@), event notification
984 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
985 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
986 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
988 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
989 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
990 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
991 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
992 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
993 * (@code IPP_TAG_URISCHEME@).
995 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
996 * and textWithLanguage string values and must be @code NULL@ for all other
999 * The @code format@ parameter uses formatting characters compatible with the
1000 * printf family of standard functions. Additional arguments follow it as
1001 * needed. The formatted string is truncated as needed to the maximum length of
1002 * the corresponding value type.
1004 * @since CUPS 1.7/OS X 10.9@
1007 ipp_attribute_t
* /* O - New attribute */
1008 ippAddStringf(ipp_t
*ipp
, /* I - IPP message */
1009 ipp_tag_t group
, /* I - IPP group */
1010 ipp_tag_t value_tag
, /* I - Type of attribute */
1011 const char *name
, /* I - Name of attribute */
1012 const char *language
, /* I - Language code (@code NULL@ for default) */
1013 const char *format
, /* I - Printf-style format string */
1014 ...) /* I - Additional arguments as needed */
1016 ipp_attribute_t
*attr
; /* New attribute */
1017 va_list ap
; /* Argument pointer */
1020 va_start(ap
, format
);
1021 attr
= ippAddStringfv(ipp
, group
, value_tag
, name
, language
, format
, ap
);
1029 * 'ippAddStringfv()' - Add a formatted string to an IPP message.
1031 * The @code ipp@ parameter refers to an IPP message previously created using
1032 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1034 * The @code group@ parameter specifies the IPP attribute group tag: none
1035 * (@code IPP_TAG_ZERO@, for member attributes), document
1036 * (@code IPP_TAG_DOCUMENT@), event notification
1037 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1038 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1039 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1041 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1042 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1043 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1044 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1045 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1046 * (@code IPP_TAG_URISCHEME@).
1048 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1049 * and textWithLanguage string values and must be @code NULL@ for all other
1052 * The @code format@ parameter uses formatting characters compatible with the
1053 * printf family of standard functions. Additional arguments are passed in the
1054 * stdarg pointer @code ap@. The formatted string is truncated as needed to the
1055 * maximum length of the corresponding value type.
1057 * @since CUPS 1.7/OS X 10.9@
1060 ipp_attribute_t
* /* O - New attribute */
1061 ippAddStringfv(ipp_t
*ipp
, /* I - IPP message */
1062 ipp_tag_t group
, /* I - IPP group */
1063 ipp_tag_t value_tag
, /* I - Type of attribute */
1064 const char *name
, /* I - Name of attribute */
1065 const char *language
, /* I - Language code (@code NULL@ for default) */
1066 const char *format
, /* I - Printf-style format string */
1067 va_list ap
) /* I - Additional arguments */
1069 char buffer
[IPP_MAX_TEXT
+ 4];
1070 /* Formatted text string */
1071 ssize_t bytes
, /* Length of formatted value */
1072 max_bytes
; /* Maximum number of bytes for value */
1076 * Range check input...
1079 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1080 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1081 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
1082 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
1086 if ((value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_NAMELANG
)
1087 != (language
!= NULL
))
1091 * Format the string...
1094 if (!strcmp(format
, "%s"))
1097 * Optimize the simple case...
1100 const char *s
= va_arg(ap
, char *);
1105 bytes
= (ssize_t
)strlen(s
);
1106 strlcpy(buffer
, s
, sizeof(buffer
));
1111 * Do a full formatting of the message...
1114 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
1119 * Limit the length of the string...
1126 case IPP_TAG_TEXTLANG
:
1127 max_bytes
= IPP_MAX_TEXT
;
1131 case IPP_TAG_NAMELANG
:
1132 max_bytes
= IPP_MAX_NAME
;
1135 case IPP_TAG_CHARSET
:
1136 max_bytes
= IPP_MAX_CHARSET
;
1139 case IPP_TAG_KEYWORD
:
1140 max_bytes
= IPP_MAX_KEYWORD
;
1143 case IPP_TAG_LANGUAGE
:
1144 max_bytes
= IPP_MAX_LANGUAGE
;
1147 case IPP_TAG_MIMETYPE
:
1148 max_bytes
= IPP_MAX_MIMETYPE
;
1152 max_bytes
= IPP_MAX_URI
;
1155 case IPP_TAG_URISCHEME
:
1156 max_bytes
= IPP_MAX_URISCHEME
;
1160 if (bytes
>= max_bytes
)
1162 char *bufmax
, /* Buffer at max_bytes */
1163 *bufptr
; /* Pointer into buffer */
1165 bufptr
= buffer
+ strlen(buffer
) - 1;
1166 bufmax
= buffer
+ max_bytes
- 1;
1168 while (bufptr
> bufmax
)
1172 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
1183 * Add the formatted string and return...
1186 return (ippAddString(ipp
, group
, value_tag
, name
, language
, buffer
));
1191 * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
1193 * The @code ipp@ parameter refers to an IPP message previously created using
1194 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1196 * The @code group@ parameter specifies the IPP attribute group tag: none
1197 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
1198 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
1199 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
1200 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1202 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1203 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1204 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1205 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1206 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1207 * (@code IPP_TAG_URISCHEME@).
1209 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1210 * textWithLanguage string values and must be @code NULL@ for all other string values.
1213 ipp_attribute_t
* /* O - New attribute */
1215 ipp_t
*ipp
, /* I - IPP message */
1216 ipp_tag_t group
, /* I - IPP group */
1217 ipp_tag_t value_tag
, /* I - Type of attribute */
1218 const char *name
, /* I - Name of attribute */
1219 int num_values
, /* I - Number of values */
1220 const char *language
, /* I - Language code (@code NULL@ for default) */
1221 const char * const *values
) /* I - Values */
1223 int i
; /* Looping var */
1224 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1225 ipp_attribute_t
*attr
; /* New attribute */
1226 _ipp_value_t
*value
; /* Current value */
1227 char code
[32]; /* Language/charset value buffer */
1230 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
));
1233 * Range check input...
1236 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
1239 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1240 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1241 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1242 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
||
1246 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1247 != (language
!= NULL
))
1250 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1251 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1257 * See if we need to map charset, language, or locale values...
1260 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
1261 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1262 value_tag
= temp_tag
; /* Don't do a fast copy */
1263 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
))
1265 for (i
= 0; i
< num_values
; i
++)
1266 if (strcmp(values
[i
], ipp_get_code(values
[i
], code
, sizeof(code
))))
1268 value_tag
= temp_tag
; /* Don't do a fast copy */
1272 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
))
1274 for (i
= 0; i
< num_values
; i
++)
1275 if (strcmp(values
[i
], ipp_lang_code(values
[i
], code
, sizeof(code
))))
1277 value_tag
= temp_tag
; /* Don't do a fast copy */
1283 * Create the attribute...
1286 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
1290 * Initialize the attribute data...
1293 for (i
= num_values
, value
= attr
->values
;
1299 if (value
== attr
->values
)
1301 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1302 value
->string
.language
= (char *)language
;
1304 value
->string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1308 value
->string
.language
= attr
->values
[0].string
.language
;
1313 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1314 value
->string
.text
= (char *)*values
++;
1315 else if (value_tag
== IPP_TAG_CHARSET
)
1316 value
->string
.text
= _cupsStrAlloc(ipp_get_code(*values
++, code
, sizeof(code
)));
1317 else if (value_tag
== IPP_TAG_LANGUAGE
)
1318 value
->string
.text
= _cupsStrAlloc(ipp_lang_code(*values
++, code
, sizeof(code
)));
1320 value
->string
.text
= _cupsStrAlloc(*values
++);
1329 * 'ippContainsInteger()' - Determine whether an attribute contains the
1330 * specified value or is within the list of ranges.
1332 * Returns non-zero when the attribute contains either a matching integer or
1333 * enum value, or the value falls within one of the rangeOfInteger values for
1336 * @since CUPS 1.7/OS X 10.9@
1339 int /* O - 1 on a match, 0 on no match */
1341 ipp_attribute_t
*attr
, /* I - Attribute */
1342 int value
) /* I - Integer/enum value */
1344 int i
; /* Looping var */
1345 _ipp_value_t
*avalue
; /* Current attribute value */
1349 * Range check input...
1355 if (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
&&
1356 attr
->value_tag
!= IPP_TAG_RANGE
)
1363 if (attr
->value_tag
== IPP_TAG_RANGE
)
1365 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1366 if (value
>= avalue
->range
.lower
&& value
<= avalue
->range
.upper
)
1371 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1372 if (value
== avalue
->integer
)
1381 * 'ippContainsString()' - Determine whether an attribute contains the
1382 * specified string value.
1384 * Returns non-zero when the attribute contains a matching charset, keyword,
1385 * language, mimeMediaType, name, text, URI, or URI scheme value.
1387 * @since CUPS 1.7/OS X 10.9@
1390 int /* O - 1 on a match, 0 on no match */
1392 ipp_attribute_t
*attr
, /* I - Attribute */
1393 const char *value
) /* I - String value */
1395 int i
; /* Looping var */
1396 _ipp_value_t
*avalue
; /* Current attribute value */
1399 DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", (void *)attr
, value
));
1402 * Range check input...
1405 if (!attr
|| !value
)
1407 DEBUG_puts("1ippContainsString: Returning 0 (bad input)");
1415 DEBUG_printf(("1ippContainsString: attr %s, %s with %d values.",
1416 attr
->name
, ippTagString(attr
->value_tag
),
1419 switch (attr
->value_tag
& IPP_TAG_CUPS_MASK
)
1421 case IPP_TAG_CHARSET
:
1422 case IPP_TAG_KEYWORD
:
1423 case IPP_TAG_LANGUAGE
:
1424 case IPP_TAG_MIMETYPE
:
1426 case IPP_TAG_NAMELANG
:
1428 case IPP_TAG_TEXTLANG
:
1430 case IPP_TAG_URISCHEME
:
1431 for (i
= attr
->num_values
, avalue
= attr
->values
;
1435 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1436 attr
->num_values
- i
, avalue
->string
.text
));
1438 if (!strcmp(value
, avalue
->string
.text
))
1440 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1449 DEBUG_puts("1ippContainsString: Returning 0 (no match)");
1456 * 'ippCopyAttribute()' - Copy an attribute.
1458 * The specified attribute, @code attr@, is copied to the destination IPP message.
1459 * When @code quickcopy@ is non-zero, a "shallow" reference copy of the attribute is
1460 * created - this should only be done as long as the original source IPP message will
1461 * not be freed for the life of the destination.
1463 * @since CUPS 1.6/OS X 10.8@
1467 ipp_attribute_t
* /* O - New attribute */
1469 ipp_t
*dst
, /* I - Destination IPP message */
1470 ipp_attribute_t
*srcattr
, /* I - Attribute to copy */
1471 int quickcopy
) /* I - 1 for a referenced copy, 0 for normal */
1473 int i
; /* Looping var */
1474 ipp_attribute_t
*dstattr
; /* Destination attribute */
1475 _ipp_value_t
*srcval
, /* Source value */
1476 *dstval
; /* Destination value */
1479 DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", (void *)dst
, (void *)srcattr
, quickcopy
));
1482 * Range check input...
1485 if (!dst
|| !srcattr
)
1492 quickcopy
= quickcopy
? IPP_TAG_CUPS_CONST
: 0;
1494 switch (srcattr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
1497 dstattr
= ippAddSeparator(dst
);
1500 case IPP_TAG_INTEGER
:
1502 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1503 srcattr
->name
, srcattr
->num_values
, NULL
);
1507 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1509 i
--, srcval
++, dstval
++)
1510 dstval
->integer
= srcval
->integer
;
1513 case IPP_TAG_BOOLEAN
:
1514 dstattr
= ippAddBooleans(dst
, srcattr
->group_tag
, srcattr
->name
,
1515 srcattr
->num_values
, NULL
);
1519 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1521 i
--, srcval
++, dstval
++)
1522 dstval
->boolean
= srcval
->boolean
;
1527 case IPP_TAG_KEYWORD
:
1529 case IPP_TAG_URISCHEME
:
1530 case IPP_TAG_CHARSET
:
1531 case IPP_TAG_LANGUAGE
:
1532 case IPP_TAG_MIMETYPE
:
1533 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1534 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1535 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1541 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1542 dstval
= dstattr
->values
;
1544 i
--, srcval
++, dstval
++)
1545 dstval
->string
.text
= srcval
->string
.text
;
1547 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1549 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1550 dstval
= dstattr
->values
;
1552 i
--, srcval
++, dstval
++)
1553 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1557 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1558 dstval
= dstattr
->values
;
1560 i
--, srcval
++, dstval
++)
1561 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1566 if (srcattr
->num_values
!= 1)
1569 dstattr
= ippAddDate(dst
, srcattr
->group_tag
, srcattr
->name
,
1570 srcattr
->values
[0].date
);
1573 case IPP_TAG_RESOLUTION
:
1574 dstattr
= ippAddResolutions(dst
, srcattr
->group_tag
, srcattr
->name
,
1575 srcattr
->num_values
, IPP_RES_PER_INCH
,
1580 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1582 i
--, srcval
++, dstval
++)
1584 dstval
->resolution
.xres
= srcval
->resolution
.xres
;
1585 dstval
->resolution
.yres
= srcval
->resolution
.yres
;
1586 dstval
->resolution
.units
= srcval
->resolution
.units
;
1590 case IPP_TAG_RANGE
:
1591 dstattr
= ippAddRanges(dst
, srcattr
->group_tag
, srcattr
->name
,
1592 srcattr
->num_values
, NULL
, NULL
);
1596 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1598 i
--, srcval
++, dstval
++)
1600 dstval
->range
.lower
= srcval
->range
.lower
;
1601 dstval
->range
.upper
= srcval
->range
.upper
;
1605 case IPP_TAG_TEXTLANG
:
1606 case IPP_TAG_NAMELANG
:
1607 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1608 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1609 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1615 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1616 dstval
= dstattr
->values
;
1618 i
--, srcval
++, dstval
++)
1620 dstval
->string
.language
= srcval
->string
.language
;
1621 dstval
->string
.text
= srcval
->string
.text
;
1624 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1626 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1627 dstval
= dstattr
->values
;
1629 i
--, srcval
++, dstval
++)
1631 if (srcval
== srcattr
->values
)
1632 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1634 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1636 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1641 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1642 dstval
= dstattr
->values
;
1644 i
--, srcval
++, dstval
++)
1646 if (srcval
== srcattr
->values
)
1647 dstval
->string
.language
= _cupsStrRetain(srcval
->string
.language
);
1649 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1651 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1656 case IPP_TAG_BEGIN_COLLECTION
:
1657 dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
,
1658 srcattr
->num_values
, NULL
);
1662 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1664 i
--, srcval
++, dstval
++)
1666 dstval
->collection
= srcval
->collection
;
1667 srcval
->collection
->use
++;
1671 case IPP_TAG_STRING
:
1673 /* TODO: Implement quick copy for unknown/octetString values */
1674 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1675 srcattr
->name
, srcattr
->num_values
, NULL
);
1679 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1681 i
--, srcval
++, dstval
++)
1683 dstval
->unknown
.length
= srcval
->unknown
.length
;
1685 if (dstval
->unknown
.length
> 0)
1687 if ((dstval
->unknown
.data
= malloc((size_t)dstval
->unknown
.length
)) == NULL
)
1688 dstval
->unknown
.length
= 0;
1690 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, (size_t)dstval
->unknown
.length
);
1693 break; /* anti-compiler-warning-code */
1701 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1703 * Zero or more attributes are copied from the source IPP message, @code src@, to the
1704 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1705 * reference copy of the attribute is created - this should only be done as long as the
1706 * original source IPP message will not be freed for the life of the destination.
1708 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1709 * attributes that are copied - the function must return 1 to copy the attribute or
1710 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1713 * @since CUPS 1.6/OS X 10.8@
1716 int /* O - 1 on success, 0 on error */
1718 ipp_t
*dst
, /* I - Destination IPP message */
1719 ipp_t
*src
, /* I - Source IPP message */
1720 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1721 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1722 void *context
) /* I - Context pointer */
1724 ipp_attribute_t
*srcattr
; /* Source attribute */
1727 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)", (void *)dst
, (void *)src
, quickcopy
, (void *)cb
, context
));
1730 * Range check input...
1737 * Loop through source attributes and copy as needed...
1740 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1741 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1742 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1750 * 'ippDateToTime()' - Convert from RFC 1903 Date/Time format to UNIX time
1754 time_t /* O - UNIX time value */
1755 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 1903 date info */
1757 struct tm unixdate
; /* UNIX date/time info */
1758 time_t t
; /* Computed time */
1764 memset(&unixdate
, 0, sizeof(unixdate
));
1767 * RFC-1903 date/time format is:
1769 * Byte(s) Description
1770 * ------- -----------
1771 * 0-1 Year (0 to 65535)
1775 * 5 Minutes (0 to 59)
1776 * 6 Seconds (0 to 60, 60 = "leap second")
1777 * 7 Deciseconds (0 to 9)
1779 * 9 UTC hours (0 to 11)
1780 * 10 UTC minutes (0 to 59)
1783 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1784 unixdate
.tm_mon
= date
[2] - 1;
1785 unixdate
.tm_mday
= date
[3];
1786 unixdate
.tm_hour
= date
[4];
1787 unixdate
.tm_min
= date
[5];
1788 unixdate
.tm_sec
= date
[6];
1790 t
= mktime(&unixdate
);
1793 t
+= date
[9] * 3600 + date
[10] * 60;
1795 t
-= date
[9] * 3600 + date
[10] * 60;
1802 * 'ippDelete()' - Delete an IPP message.
1806 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1808 ipp_attribute_t
*attr
, /* Current attribute */
1809 *next
; /* Next attribute */
1812 DEBUG_printf(("ippDelete(ipp=%p)", (void *)ipp
));
1821 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1825 ipp_free_values(attr
, 0, attr
->num_values
);
1828 _cupsStrFree(attr
->name
);
1838 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1840 * @since CUPS 1.1.19/OS X 10.3@
1845 ipp_t
*ipp
, /* I - IPP message */
1846 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1848 ipp_attribute_t
*current
, /* Current attribute */
1849 *prev
; /* Previous attribute */
1852 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", (void *)ipp
, (void *)attr
, attr
? attr
->name
: "(null)"));
1855 * Range check input...
1862 * Find the attribute in the list...
1867 for (current
= ipp
->attrs
, prev
= NULL
;
1869 prev
= current
, current
= current
->next
)
1870 if (current
== attr
)
1873 * Found it, remove the attribute from the list...
1877 prev
->next
= current
->next
;
1879 ipp
->attrs
= current
->next
;
1881 if (current
== ipp
->last
)
1892 * Free memory used by the attribute...
1895 ipp_free_values(attr
, 0, attr
->num_values
);
1898 _cupsStrFree(attr
->name
);
1905 * 'ippDeleteValues()' - Delete values in an attribute.
1907 * The @code element@ parameter specifies the first value to delete, starting at
1908 * 0. It must be less than the number of values returned by @link ippGetCount@.
1910 * The @code attr@ parameter may be modified as a result of setting the value.
1912 * Deleting all values in an attribute deletes the attribute.
1914 * @since CUPS 1.6/OS X 10.8@
1917 int /* O - 1 on success, 0 on failure */
1919 ipp_t
*ipp
, /* I - IPP message */
1920 ipp_attribute_t
**attr
, /* IO - Attribute */
1921 int element
, /* I - Index of first value to delete (0-based) */
1922 int count
) /* I - Number of values to delete */
1925 * Range check input...
1928 if (!ipp
|| !attr
|| !*attr
||
1929 element
< 0 || element
>= (*attr
)->num_values
|| count
<= 0 ||
1930 (element
+ count
) >= (*attr
)->num_values
)
1934 * If we are deleting all values, just delete the attribute entirely.
1937 if (count
== (*attr
)->num_values
)
1939 ippDeleteAttribute(ipp
, *attr
);
1945 * Otherwise free the values in question and return.
1948 ipp_free_values(*attr
, element
, count
);
1955 * 'ippFindAttribute()' - Find a named attribute in a request.
1957 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1958 * of attribute and member names separated by slashes, for example
1959 * "media-col/media-size".
1962 ipp_attribute_t
* /* O - Matching attribute */
1963 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
1964 const char *name
, /* I - Name of attribute */
1965 ipp_tag_t type
) /* I - Type of attribute */
1967 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
1973 * Reset the current pointer...
1976 ipp
->current
= NULL
;
1980 * Search for the attribute...
1983 return (ippFindNextAttribute(ipp
, name
, type
));
1988 * 'ippFindNextAttribute()' - Find the next named attribute in a request.
1990 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1991 * of attribute and member names separated by slashes, for example
1992 * "media-col/media-size".
1995 ipp_attribute_t
* /* O - Matching attribute */
1996 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
1997 const char *name
, /* I - Name of attribute */
1998 ipp_tag_t type
) /* I - Type of attribute */
2000 ipp_attribute_t
*attr
, /* Current atttribute */
2001 *childattr
; /* Child attribute */
2002 ipp_tag_t value_tag
; /* Value tag */
2003 char parent
[1024], /* Parent attribute name */
2004 *child
= NULL
; /* Child attribute name */
2007 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
2012 DEBUG_printf(("3ippFindNextAttribute: atend=%d", ipp
->atend
));
2017 if (strchr(name
, '/'))
2020 * Search for child attribute...
2023 strlcpy(parent
, name
, sizeof(parent
));
2024 if ((child
= strchr(parent
, '/')) == NULL
)
2026 DEBUG_puts("3ippFindNextAttribute: Attribute name too long.");
2032 if (ipp
->current
&& ipp
->current
->name
&& ipp
->current
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&& !strcmp(parent
, ipp
->current
->name
))
2034 while (ipp
->curindex
< ipp
->current
->num_values
)
2036 if ((childattr
= ippFindNextAttribute(ipp
->current
->values
[ipp
->curindex
].collection
, child
, type
)) != NULL
)
2040 if (ipp
->curindex
< ipp
->current
->num_values
&& ipp
->current
->values
[ipp
->curindex
].collection
)
2041 ipp
->current
->values
[ipp
->curindex
].collection
->current
= NULL
;
2044 ipp
->prev
= ipp
->current
;
2045 ipp
->current
= ipp
->current
->next
;
2058 ipp
->current
= ipp
->attrs
;
2063 attr
= ipp
->current
;
2065 else if (ipp
->current
)
2067 ipp
->prev
= ipp
->current
;
2068 attr
= ipp
->current
->next
;
2076 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
2078 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", (void *)attr
, attr
->name
));
2080 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2082 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
2083 (value_tag
== type
|| type
== IPP_TAG_ZERO
|| name
== parent
||
2084 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
2085 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
2087 ipp
->current
= attr
;
2089 if (name
== parent
&& attr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
)
2091 int i
; /* Looping var */
2093 for (i
= 0; i
< attr
->num_values
; i
++)
2095 if ((childattr
= ippFindAttribute(attr
->values
[i
].collection
, child
, type
)) != NULL
)
2097 attr
->values
[0].collection
->curindex
= i
;
2107 ipp
->current
= NULL
;
2116 * 'ippFirstAttribute()' - Return the first attribute in the message.
2118 * @since CUPS 1.6/OS X 10.8@
2121 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
2122 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
2125 * Range check input...
2132 * Return the first attribute...
2135 return (ipp
->current
= ipp
->attrs
);
2140 * 'ippGetBoolean()' - Get a boolean value for an attribute.
2142 * The @code element@ parameter specifies which value to get from 0 to
2143 * @link ippGetCount(attr)@ - 1.
2145 * @since CUPS 1.6/OS X 10.8@
2148 int /* O - Boolean value or 0 on error */
2149 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
2150 int element
) /* I - Value number (0-based) */
2153 * Range check input...
2156 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
2157 element
< 0 || element
>= attr
->num_values
)
2161 * Return the value...
2164 return (attr
->values
[element
].boolean
);
2169 * 'ippGetCollection()' - Get a collection value for an attribute.
2171 * The @code element@ parameter specifies which value to get from 0 to
2172 * @link ippGetCount(attr)@ - 1.
2174 * @since CUPS 1.6/OS X 10.8@
2177 ipp_t
* /* O - Collection value or @code NULL@ on error */
2179 ipp_attribute_t
*attr
, /* I - IPP attribute */
2180 int element
) /* I - Value number (0-based) */
2183 * Range check input...
2186 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
2187 element
< 0 || element
>= attr
->num_values
)
2191 * Return the value...
2194 return (attr
->values
[element
].collection
);
2199 * 'ippGetCount()' - Get the number of values in an attribute.
2201 * @since CUPS 1.6/OS X 10.8@
2204 int /* O - Number of values or 0 on error */
2205 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
2208 * Range check input...
2215 * Return the number of values...
2218 return (attr
->num_values
);
2223 * 'ippGetDate()' - Get a date value for an attribute.
2225 * The @code element@ parameter specifies which value to get from 0 to
2226 * @link ippGetCount(attr)@ - 1.
2228 * @since CUPS 1.6/OS X 10.8@
2231 const ipp_uchar_t
* /* O - Date value or @code NULL@ */
2232 ippGetDate(ipp_attribute_t
*attr
, /* I - IPP attribute */
2233 int element
) /* I - Value number (0-based) */
2236 * Range check input...
2239 if (!attr
|| attr
->value_tag
!= IPP_TAG_DATE
||
2240 element
< 0 || element
>= attr
->num_values
)
2244 * Return the value...
2247 return (attr
->values
[element
].date
);
2252 * 'ippGetGroupTag()' - Get the group associated with an attribute.
2254 * @since CUPS 1.6/OS X 10.8@
2257 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
2258 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2261 * Range check input...
2265 return (IPP_TAG_ZERO
);
2268 * Return the group...
2271 return (attr
->group_tag
);
2276 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
2278 * The @code element@ parameter specifies which value to get from 0 to
2279 * @link ippGetCount(attr)@ - 1.
2281 * @since CUPS 1.6/OS X 10.8@
2284 int /* O - Value or 0 on error */
2285 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
2286 int element
) /* I - Value number (0-based) */
2289 * Range check input...
2292 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
2293 element
< 0 || element
>= attr
->num_values
)
2297 * Return the value...
2300 return (attr
->values
[element
].integer
);
2305 * 'ippGetName()' - Get the attribute name.
2307 * @since CUPS 1.6/OS X 10.8@
2310 const char * /* O - Attribute name or @code NULL@ for separators */
2311 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
2314 * Range check input...
2321 * Return the name...
2324 return (attr
->name
);
2329 * 'ippGetOctetString()' - Get an octetString value from an IPP attribute.
2331 * The @code element@ parameter specifies which value to get from 0 to
2332 * @link ippGetCount(attr)@ - 1.
2334 * @since CUPS 1.7/OS X 10.9@
2337 void * /* O - Pointer to octetString data */
2339 ipp_attribute_t
*attr
, /* I - IPP attribute */
2340 int element
, /* I - Value number (0-based) */
2341 int *datalen
) /* O - Length of octetString data */
2344 * Range check input...
2347 if (!attr
|| attr
->value_tag
!= IPP_TAG_STRING
||
2348 element
< 0 || element
>= attr
->num_values
)
2357 * Return the values...
2361 *datalen
= attr
->values
[element
].unknown
.length
;
2363 return (attr
->values
[element
].unknown
.data
);
2368 * 'ippGetOperation()' - Get the operation ID in an IPP message.
2370 * @since CUPS 1.6/OS X 10.8@
2373 ipp_op_t
/* O - Operation ID or 0 on error */
2374 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
2377 * Range check input...
2381 return ((ipp_op_t
)0);
2384 * Return the value...
2387 return (ipp
->request
.op
.operation_id
);
2392 * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
2394 * The @code element@ parameter specifies which value to get from 0 to
2395 * @link ippGetCount(attr)@ - 1.
2397 * @since CUPS 1.6/OS X 10.8@
2400 int /* O - Lower value of range or 0 */
2401 ippGetRange(ipp_attribute_t
*attr
, /* I - IPP attribute */
2402 int element
, /* I - Value number (0-based) */
2403 int *uppervalue
)/* O - Upper value of range */
2406 * Range check input...
2409 if (!attr
|| attr
->value_tag
!= IPP_TAG_RANGE
||
2410 element
< 0 || element
>= attr
->num_values
)
2419 * Return the values...
2423 *uppervalue
= attr
->values
[element
].range
.upper
;
2425 return (attr
->values
[element
].range
.lower
);
2430 * 'ippGetRequestId()' - Get the request ID from an IPP message.
2432 * @since CUPS 1.6/OS X 10.8@
2435 int /* O - Request ID or 0 on error */
2436 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
2439 * Range check input...
2446 * Return the request ID...
2449 return (ipp
->request
.any
.request_id
);
2454 * 'ippGetResolution()' - Get a resolution value for an attribute.
2456 * The @code element@ parameter specifies which value to get from 0 to
2457 * @link ippGetCount(attr)@ - 1.
2459 * @since CUPS 1.6/OS X 10.8@
2462 int /* O - Horizontal/cross feed resolution or 0 */
2464 ipp_attribute_t
*attr
, /* I - IPP attribute */
2465 int element
, /* I - Value number (0-based) */
2466 int *yres
, /* O - Vertical/feed resolution */
2467 ipp_res_t
*units
) /* O - Units for resolution */
2470 * Range check input...
2473 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
2474 element
< 0 || element
>= attr
->num_values
)
2480 *units
= (ipp_res_t
)0;
2486 * Return the value...
2490 *yres
= attr
->values
[element
].resolution
.yres
;
2493 *units
= attr
->values
[element
].resolution
.units
;
2495 return (attr
->values
[element
].resolution
.xres
);
2500 * 'ippGetState()' - Get the IPP message state.
2502 * @since CUPS 1.6/OS X 10.8@
2505 ipp_state_t
/* O - IPP message state value */
2506 ippGetState(ipp_t
*ipp
) /* I - IPP message */
2509 * Range check input...
2513 return (IPP_STATE_IDLE
);
2516 * Return the value...
2519 return (ipp
->state
);
2524 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2526 * @since CUPS 1.6/OS X 10.8@
2529 ipp_status_t
/* O - Status code in IPP message */
2530 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2533 * Range check input...
2537 return (IPP_STATUS_ERROR_INTERNAL
);
2540 * Return the value...
2543 return (ipp
->request
.status
.status_code
);
2548 * 'ippGetString()' - Get the string and optionally the language code for an attribute.
2550 * The @code element@ parameter specifies which value to get from 0 to
2551 * @link ippGetCount(attr)@ - 1.
2553 * @since CUPS 1.6/OS X 10.8@
2557 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2558 int element
, /* I - Value number (0-based) */
2559 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2562 * Range check input...
2565 if (!attr
|| element
< 0 || element
>= attr
->num_values
||
2566 (attr
->value_tag
!= IPP_TAG_TEXTLANG
&& attr
->value_tag
!= IPP_TAG_NAMELANG
&&
2567 (attr
->value_tag
< IPP_TAG_TEXT
|| attr
->value_tag
> IPP_TAG_MIMETYPE
)))
2571 * Return the value...
2575 *language
= attr
->values
[element
].string
.language
;
2577 return (attr
->values
[element
].string
.text
);
2582 * 'ippGetValueTag()' - Get the value tag for an attribute.
2584 * @since CUPS 1.6/OS X 10.8@
2587 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2588 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2591 * Range check input...
2595 return (IPP_TAG_ZERO
);
2598 * Return the value...
2601 return (attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2606 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2608 * @since CUPS 1.6/OS X 10.8@
2611 int /* O - Major version number or 0 on error */
2612 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2613 int *minor
) /* O - Minor version number or @code NULL@ */
2616 * Range check input...
2628 * Return the value...
2632 *minor
= ipp
->request
.any
.version
[1];
2634 return (ipp
->request
.any
.version
[0]);
2639 * 'ippLength()' - Compute the length of an IPP message.
2642 size_t /* O - Size of IPP message */
2643 ippLength(ipp_t
*ipp
) /* I - IPP message */
2645 return (ipp_length(ipp
, 0));
2650 * 'ippNextAttribute()' - Return the next attribute in the message.
2652 * @since CUPS 1.6/OS X 10.8@
2655 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2656 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2659 * Range check input...
2662 if (!ipp
|| !ipp
->current
)
2666 * Return the next attribute...
2669 return (ipp
->current
= ipp
->current
->next
);
2674 * 'ippNew()' - Allocate a new IPP message.
2677 ipp_t
* /* O - New IPP message */
2680 ipp_t
*temp
; /* New IPP message */
2681 _cups_globals_t
*cg
= _cupsGlobals();
2685 DEBUG_puts("ippNew()");
2687 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2690 * Set default version - usually 2.0...
2693 if (cg
->server_version
== 0)
2696 temp
->request
.any
.version
[0] = (ipp_uchar_t
)(cg
->server_version
/ 10);
2697 temp
->request
.any
.version
[1] = (ipp_uchar_t
)(cg
->server_version
% 10);
2701 DEBUG_printf(("1ippNew: Returning %p", (void *)temp
));
2708 * 'ippNewRequest()' - Allocate a new IPP request message.
2710 * The new request message is initialized with the attributes-charset and
2711 * attributes-natural-language attributes added. The
2712 * attributes-natural-language value is derived from the current locale.
2714 * @since CUPS 1.2/OS X 10.5@
2717 ipp_t
* /* O - IPP request message */
2718 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2720 ipp_t
*request
; /* IPP request message */
2721 cups_lang_t
*language
; /* Current language localization */
2722 static int request_id
= 0; /* Current request ID */
2723 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2724 /* Mutex for request ID */
2727 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2730 * Create a new IPP message...
2733 if ((request
= ippNew()) == NULL
)
2737 * Set the operation and request ID...
2740 _cupsMutexLock(&request_mutex
);
2742 request
->request
.op
.operation_id
= op
;
2743 request
->request
.op
.request_id
= ++request_id
;
2745 _cupsMutexUnlock(&request_mutex
);
2748 * Use UTF-8 as the character set...
2751 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2752 "attributes-charset", NULL
, "utf-8");
2755 * Get the language from the current locale...
2758 language
= cupsLangDefault();
2760 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2761 "attributes-natural-language", NULL
, language
->language
);
2764 * Return the new request...
2772 * 'ippNewResponse()' - Allocate a new IPP response message.
2774 * The new response message is initialized with the same version-number,
2775 * request-id, attributes-charset, and attributes-natural-language as the
2776 * provided request message. If the attributes-charset or
2777 * attributes-natural-language attributes are missing from the request,
2778 * "utf-8" and a value derived from the current locale are substituted,
2781 * @since CUPS 1.7/OS X 10.9@
2784 ipp_t
* /* O - IPP response message */
2785 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2787 ipp_t
*response
; /* IPP response message */
2788 ipp_attribute_t
*attr
; /* Current attribute */
2792 * Range check input...
2799 * Create a new IPP message...
2802 if ((response
= ippNew()) == NULL
)
2806 * Copy the request values over to the response...
2809 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2810 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2811 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2814 * The first attribute MUST be attributes-charset...
2817 attr
= request
->attrs
;
2819 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2820 attr
->group_tag
== IPP_TAG_OPERATION
&&
2821 attr
->value_tag
== IPP_TAG_CHARSET
&&
2822 attr
->num_values
== 1)
2825 * Copy charset from request...
2828 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2829 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2834 * Use "utf-8" as the default...
2837 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2838 "attributes-charset", NULL
, "utf-8");
2842 * Then attributes-natural-language...
2848 if (attr
&& attr
->name
&&
2849 !strcmp(attr
->name
, "attributes-natural-language") &&
2850 attr
->group_tag
== IPP_TAG_OPERATION
&&
2851 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2852 attr
->num_values
== 1)
2855 * Copy language from request...
2858 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2859 "attributes-natural-language", NULL
,
2860 attr
->values
[0].string
.text
);
2865 * Use the language from the current locale...
2868 cups_lang_t
*language
= cupsLangDefault();
2869 /* Current locale */
2871 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2872 "attributes-natural-language", NULL
, language
->language
);
2880 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2883 ipp_state_t
/* O - Current state */
2884 ippRead(http_t
*http
, /* I - HTTP connection */
2885 ipp_t
*ipp
) /* I - IPP data */
2887 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
, (void *)http
, (void *)ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2890 return (IPP_STATE_ERROR
);
2892 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
, http
->used
));
2894 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2900 * 'ippReadFile()' - Read data for an IPP message from a file.
2902 * @since CUPS 1.1.19/OS X 10.3@
2905 ipp_state_t
/* O - Current state */
2906 ippReadFile(int fd
, /* I - HTTP data */
2907 ipp_t
*ipp
) /* I - IPP data */
2909 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
2911 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2916 * 'ippReadIO()' - Read data for an IPP message.
2918 * @since CUPS 1.2/OS X 10.5@
2921 ipp_state_t
/* O - Current state */
2922 ippReadIO(void *src
, /* I - Data source */
2923 ipp_iocb_t cb
, /* I - Read callback function */
2924 int blocking
, /* I - Use blocking IO? */
2925 ipp_t
*parent
, /* I - Parent request, if any */
2926 ipp_t
*ipp
) /* I - IPP data */
2928 int n
; /* Length of data */
2929 unsigned char *buffer
, /* Data buffer */
2930 string
[IPP_MAX_TEXT
],
2931 /* Small string buffer */
2932 *bufptr
; /* Pointer into buffer */
2933 ipp_attribute_t
*attr
; /* Current attribute */
2934 ipp_tag_t tag
; /* Current tag */
2935 ipp_tag_t value_tag
; /* Current value tag */
2936 _ipp_value_t
*value
; /* Current value */
2939 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)src
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
2940 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_STATE_ERROR
));
2943 return (IPP_STATE_ERROR
);
2945 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2947 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2948 return (IPP_STATE_ERROR
);
2953 case IPP_STATE_IDLE
:
2954 ipp
->state
++; /* Avoid common problem... */
2956 case IPP_STATE_HEADER
:
2960 * Get the request header...
2963 if ((*cb
)(src
, buffer
, 8) < 8)
2965 DEBUG_puts("1ippReadIO: Unable to read header.");
2966 _cupsBufferRelease((char *)buffer
);
2967 return (IPP_STATE_ERROR
);
2971 * Then copy the request header over...
2974 ipp
->request
.any
.version
[0] = buffer
[0];
2975 ipp
->request
.any
.version
[1] = buffer
[1];
2976 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
2977 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
2978 buffer
[6]) << 8) | buffer
[7];
2980 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
2981 DEBUG_printf(("2ippReadIO: op_status=%04x",
2982 ipp
->request
.any
.op_status
));
2983 DEBUG_printf(("2ippReadIO: request_id=%d",
2984 ipp
->request
.any
.request_id
));
2987 ipp
->state
= IPP_STATE_ATTRIBUTE
;
2988 ipp
->current
= NULL
;
2989 ipp
->curtag
= IPP_TAG_ZERO
;
2990 ipp
->prev
= ipp
->last
;
2993 * If blocking is disabled, stop here...
2999 case IPP_STATE_ATTRIBUTE
:
3002 if ((*cb
)(src
, buffer
, 1) < 1)
3004 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3005 _cupsBufferRelease((char *)buffer
);
3006 return (IPP_STATE_ERROR
);
3009 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3012 * Read this attribute...
3015 tag
= (ipp_tag_t
)buffer
[0];
3016 if (tag
== IPP_TAG_EXTENSION
)
3019 * Read 32-bit "extension" tag...
3022 if ((*cb
)(src
, buffer
, 4) < 1)
3024 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3025 _cupsBufferRelease((char *)buffer
);
3026 return (IPP_STATE_ERROR
);
3029 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
3030 buffer
[2]) << 8) | buffer
[3]);
3032 if (tag
& IPP_TAG_CUPS_CONST
)
3035 * Fail if the high bit is set in the tag...
3038 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
3039 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
3040 _cupsBufferRelease((char *)buffer
);
3041 return (IPP_STATE_ERROR
);
3045 if (tag
== IPP_TAG_END
)
3048 * No more attributes left...
3051 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
3053 ipp
->state
= IPP_STATE_DATA
;
3056 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3059 * Group tag... Set the current group and continue...
3062 if (ipp
->curtag
== tag
)
3063 ipp
->prev
= ippAddSeparator(ipp
);
3064 else if (ipp
->current
)
3065 ipp
->prev
= ipp
->current
;
3068 ipp
->current
= NULL
;
3069 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
, ippTagString(tag
), (void *)ipp
->prev
));
3073 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3074 ippTagString(tag
)));
3080 if ((*cb
)(src
, buffer
, 2) < 2)
3082 DEBUG_puts("1ippReadIO: unable to read name length.");
3083 _cupsBufferRelease((char *)buffer
);
3084 return (IPP_STATE_ERROR
);
3087 n
= (buffer
[0] << 8) | buffer
[1];
3089 if (n
>= IPP_BUF_SIZE
)
3091 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3092 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3093 _cupsBufferRelease((char *)buffer
);
3094 return (IPP_STATE_ERROR
);
3097 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3099 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3100 tag
!= IPP_TAG_END_COLLECTION
)
3103 * More values for current attribute...
3106 if (ipp
->current
== NULL
)
3108 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3109 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3110 _cupsBufferRelease((char *)buffer
);
3111 return (IPP_STATE_ERROR
);
3114 attr
= ipp
->current
;
3115 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3118 * Make sure we aren't adding a new value of a different
3122 if (value_tag
== IPP_TAG_ZERO
)
3125 * Setting the value of a collection member...
3128 attr
->value_tag
= tag
;
3130 else if (value_tag
== IPP_TAG_TEXTLANG
||
3131 value_tag
== IPP_TAG_NAMELANG
||
3132 (value_tag
>= IPP_TAG_TEXT
&&
3133 value_tag
<= IPP_TAG_MIMETYPE
))
3136 * String values can sometimes come across in different
3137 * forms; accept sets of differing values...
3140 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3141 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3142 tag
!= IPP_TAG_NOVALUE
)
3144 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3145 _("IPP 1setOf attribute with incompatible value "
3147 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3148 value_tag
, ippTagString(value_tag
), tag
,
3149 ippTagString(tag
)));
3150 _cupsBufferRelease((char *)buffer
);
3151 return (IPP_STATE_ERROR
);
3154 if (value_tag
!= tag
)
3156 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3157 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3158 ippSetValueTag(ipp
, &attr
, tag
);
3161 else if (value_tag
== IPP_TAG_INTEGER
||
3162 value_tag
== IPP_TAG_RANGE
)
3165 * Integer and rangeOfInteger values can sometimes be mixed; accept
3166 * sets of differing values...
3169 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3171 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3172 _("IPP 1setOf attribute with incompatible value "
3174 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3175 value_tag
, ippTagString(value_tag
), tag
,
3176 ippTagString(tag
)));
3177 _cupsBufferRelease((char *)buffer
);
3178 return (IPP_STATE_ERROR
);
3181 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3184 * Convert integer values to rangeOfInteger values...
3187 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3188 "rangeOfInteger.", attr
->name
));
3189 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3192 else if (value_tag
!= tag
)
3194 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3195 _("IPP 1setOf attribute with incompatible value "
3197 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3198 value_tag
, ippTagString(value_tag
), tag
,
3199 ippTagString(tag
)));
3200 _cupsBufferRelease((char *)buffer
);
3201 return (IPP_STATE_ERROR
);
3205 * Finally, reallocate the attribute array as needed...
3208 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3210 _cupsBufferRelease((char *)buffer
);
3211 return (IPP_STATE_ERROR
);
3214 else if (tag
== IPP_TAG_MEMBERNAME
)
3217 * Name must be length 0!
3222 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3223 DEBUG_puts("1ippReadIO: member name not empty.");
3224 _cupsBufferRelease((char *)buffer
);
3225 return (IPP_STATE_ERROR
);
3229 ipp
->prev
= ipp
->current
;
3231 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3234 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3235 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3236 _cupsBufferRelease((char *)buffer
);
3237 return (IPP_STATE_ERROR
);
3240 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3242 value
= attr
->values
;
3244 else if (tag
!= IPP_TAG_END_COLLECTION
)
3247 * New attribute; read the name and add it...
3250 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3252 DEBUG_puts("1ippReadIO: unable to read name.");
3253 _cupsBufferRelease((char *)buffer
);
3254 return (IPP_STATE_ERROR
);
3260 ipp
->prev
= ipp
->current
;
3262 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3265 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3266 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3267 _cupsBufferRelease((char *)buffer
);
3268 return (IPP_STATE_ERROR
);
3271 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer
, (void *)ipp
->current
, (void *)ipp
->prev
));
3273 value
= attr
->values
;
3281 if ((*cb
)(src
, buffer
, 2) < 2)
3283 DEBUG_puts("1ippReadIO: unable to read value length.");
3284 _cupsBufferRelease((char *)buffer
);
3285 return (IPP_STATE_ERROR
);
3288 n
= (buffer
[0] << 8) | buffer
[1];
3289 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3291 if (n
>= IPP_BUF_SIZE
)
3293 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3294 _("IPP value larger than 32767 bytes."), 1);
3295 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3296 _cupsBufferRelease((char *)buffer
);
3297 return (IPP_STATE_ERROR
);
3302 case IPP_TAG_INTEGER
:
3306 if (tag
== IPP_TAG_INTEGER
)
3307 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3308 _("IPP integer value not 4 bytes."), 1);
3310 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3311 _("IPP enum value not 4 bytes."), 1);
3312 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3313 _cupsBufferRelease((char *)buffer
);
3314 return (IPP_STATE_ERROR
);
3317 if ((*cb
)(src
, buffer
, 4) < 4)
3319 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3320 _cupsBufferRelease((char *)buffer
);
3321 return (IPP_STATE_ERROR
);
3324 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3327 if (attr
->value_tag
== IPP_TAG_RANGE
)
3328 value
->range
.lower
= value
->range
.upper
= n
;
3333 case IPP_TAG_BOOLEAN
:
3336 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3338 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3339 _cupsBufferRelease((char *)buffer
);
3340 return (IPP_STATE_ERROR
);
3343 if ((*cb
)(src
, buffer
, 1) < 1)
3345 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3346 _cupsBufferRelease((char *)buffer
);
3347 return (IPP_STATE_ERROR
);
3350 value
->boolean
= (char)buffer
[0];
3353 case IPP_TAG_NOVALUE
:
3354 case IPP_TAG_NOTSETTABLE
:
3355 case IPP_TAG_DELETEATTR
:
3356 case IPP_TAG_ADMINDEFINE
:
3358 * These value types are not supposed to have values, however
3359 * some vendors (Brother) do not implement IPP correctly and so
3360 * we need to map non-empty values to text...
3363 if (attr
->value_tag
== tag
)
3368 attr
->value_tag
= IPP_TAG_TEXT
;
3373 case IPP_TAG_KEYWORD
:
3375 case IPP_TAG_URISCHEME
:
3376 case IPP_TAG_CHARSET
:
3377 case IPP_TAG_LANGUAGE
:
3378 case IPP_TAG_MIMETYPE
:
3381 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3383 DEBUG_puts("1ippReadIO: unable to read string value.");
3384 _cupsBufferRelease((char *)buffer
);
3385 return (IPP_STATE_ERROR
);
3390 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3391 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3397 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3398 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3399 _cupsBufferRelease((char *)buffer
);
3400 return (IPP_STATE_ERROR
);
3403 if ((*cb
)(src
, value
->date
, 11) < 11)
3405 DEBUG_puts("1ippReadIO: Unable to read date value.");
3406 _cupsBufferRelease((char *)buffer
);
3407 return (IPP_STATE_ERROR
);
3411 case IPP_TAG_RESOLUTION
:
3414 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3415 _("IPP resolution value not 9 bytes."), 1);
3416 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3417 _cupsBufferRelease((char *)buffer
);
3418 return (IPP_STATE_ERROR
);
3421 if ((*cb
)(src
, buffer
, 9) < 9)
3423 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3424 _cupsBufferRelease((char *)buffer
);
3425 return (IPP_STATE_ERROR
);
3428 value
->resolution
.xres
=
3429 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3431 value
->resolution
.yres
=
3432 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3434 value
->resolution
.units
=
3435 (ipp_res_t
)buffer
[8];
3438 case IPP_TAG_RANGE
:
3441 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3442 _("IPP rangeOfInteger value not 8 bytes."), 1);
3443 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3445 _cupsBufferRelease((char *)buffer
);
3446 return (IPP_STATE_ERROR
);
3449 if ((*cb
)(src
, buffer
, 8) < 8)
3451 DEBUG_puts("1ippReadIO: Unable to read range value.");
3452 _cupsBufferRelease((char *)buffer
);
3453 return (IPP_STATE_ERROR
);
3456 value
->range
.lower
=
3457 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3459 value
->range
.upper
=
3460 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3464 case IPP_TAG_TEXTLANG
:
3465 case IPP_TAG_NAMELANG
:
3468 if (tag
== IPP_TAG_TEXTLANG
)
3469 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3470 _("IPP textWithLanguage value less than "
3471 "minimum 4 bytes."), 1);
3473 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3474 _("IPP nameWithLanguage value less than "
3475 "minimum 4 bytes."), 1);
3476 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3478 _cupsBufferRelease((char *)buffer
);
3479 return (IPP_STATE_ERROR
);
3482 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3484 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3486 _cupsBufferRelease((char *)buffer
);
3487 return (IPP_STATE_ERROR
);
3493 * text-with-language and name-with-language are composite
3502 n
= (bufptr
[0] << 8) | bufptr
[1];
3504 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) || n
>= (int)sizeof(string
))
3506 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3507 _("IPP language length overflows value."), 1);
3508 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3510 _cupsBufferRelease((char *)buffer
);
3511 return (IPP_STATE_ERROR
);
3513 else if (n
>= IPP_MAX_LANGUAGE
)
3515 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3516 _("IPP language length too large."), 1);
3517 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3519 _cupsBufferRelease((char *)buffer
);
3520 return (IPP_STATE_ERROR
);
3523 memcpy(string
, bufptr
+ 2, (size_t)n
);
3526 value
->string
.language
= _cupsStrAlloc((char *)string
);
3529 n
= (bufptr
[0] << 8) | bufptr
[1];
3531 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3533 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3534 _("IPP string length overflows value."), 1);
3535 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3536 _cupsBufferRelease((char *)buffer
);
3537 return (IPP_STATE_ERROR
);
3540 bufptr
[2 + n
] = '\0';
3541 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3544 case IPP_TAG_BEGIN_COLLECTION
:
3546 * Oh, boy, here comes a collection value, so read it...
3549 value
->collection
= ippNew();
3553 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3554 _("IPP begCollection value not 0 bytes."), 1);
3555 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3557 _cupsBufferRelease((char *)buffer
);
3558 return (IPP_STATE_ERROR
);
3561 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3563 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3564 _cupsBufferRelease((char *)buffer
);
3565 return (IPP_STATE_ERROR
);
3569 case IPP_TAG_END_COLLECTION
:
3570 _cupsBufferRelease((char *)buffer
);
3574 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3575 _("IPP endCollection value not 0 bytes."), 1);
3576 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3578 return (IPP_STATE_ERROR
);
3581 DEBUG_puts("1ippReadIO: endCollection tag...");
3582 return (ipp
->state
= IPP_STATE_DATA
);
3584 case IPP_TAG_MEMBERNAME
:
3586 * The value the name of the member in the collection, which
3587 * we need to carry over...
3592 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3593 _("IPP memberName with no attribute."), 1);
3594 DEBUG_puts("1ippReadIO: Member name without attribute.");
3595 _cupsBufferRelease((char *)buffer
);
3596 return (IPP_STATE_ERROR
);
3600 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3601 _("IPP memberName value is empty."), 1);
3602 DEBUG_puts("1ippReadIO: Empty member name value.");
3603 _cupsBufferRelease((char *)buffer
);
3604 return (IPP_STATE_ERROR
);
3606 else if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3608 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3609 _cupsBufferRelease((char *)buffer
);
3610 return (IPP_STATE_ERROR
);
3614 attr
->name
= _cupsStrAlloc((char *)buffer
);
3617 * Since collection members are encoded differently than
3618 * regular attributes, make sure we don't start with an
3622 attr
->num_values
--;
3624 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3627 default : /* Other unsupported values */
3628 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3630 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3631 _("IPP octetString length too large."), 1);
3632 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3634 _cupsBufferRelease((char *)buffer
);
3635 return (IPP_STATE_ERROR
);
3638 value
->unknown
.length
= n
;
3642 if ((value
->unknown
.data
= malloc((size_t)n
)) == NULL
)
3644 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3645 DEBUG_puts("1ippReadIO: Unable to allocate value");
3646 _cupsBufferRelease((char *)buffer
);
3647 return (IPP_STATE_ERROR
);
3650 if ((*cb
)(src
, value
->unknown
.data
, (size_t)n
) < n
)
3652 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3653 _cupsBufferRelease((char *)buffer
);
3654 return (IPP_STATE_ERROR
);
3658 value
->unknown
.data
= NULL
;
3663 * If blocking is disabled, stop here...
3671 case IPP_STATE_DATA
:
3675 break; /* anti-compiler-warning-code */
3678 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3679 _cupsBufferRelease((char *)buffer
);
3681 return (ipp
->state
);
3686 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3688 * The @code ipp@ parameter refers to an IPP message previously created using
3689 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3691 * The @code attr@ parameter may be modified as a result of setting the value.
3693 * The @code element@ parameter specifies which value to set from 0 to
3694 * @link ippGetCount(attr)@.
3696 * @since CUPS 1.6/OS X 10.8@
3699 int /* O - 1 on success, 0 on failure */
3700 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3701 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3702 int element
, /* I - Value number (0-based) */
3703 int boolvalue
)/* I - Boolean value */
3705 _ipp_value_t
*value
; /* Current value */
3709 * Range check input...
3712 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3713 element
< 0 || element
> (*attr
)->num_values
)
3717 * Set the value and return...
3720 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3721 value
->boolean
= (char)boolvalue
;
3723 return (value
!= NULL
);
3728 * 'ippSetCollection()' - Set a collection value in an attribute.
3730 * The @code ipp@ parameter refers to an IPP message previously created using
3731 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3733 * The @code attr@ parameter may be modified as a result of setting the value.
3735 * The @code element@ parameter specifies which value to set from 0 to
3736 * @link ippGetCount(attr)@.
3738 * @since CUPS 1.6/OS X 10.8@
3741 int /* O - 1 on success, 0 on failure */
3743 ipp_t
*ipp
, /* I - IPP message */
3744 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3745 int element
, /* I - Value number (0-based) */
3746 ipp_t
*colvalue
) /* I - Collection value */
3748 _ipp_value_t
*value
; /* Current value */
3752 * Range check input...
3755 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3756 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3760 * Set the value and return...
3763 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3765 if (value
->collection
)
3766 ippDelete(value
->collection
);
3768 value
->collection
= colvalue
;
3772 return (value
!= NULL
);
3777 * 'ippSetDate()' - Set a date value in an attribute.
3779 * The @code ipp@ parameter refers to an IPP message previously created using
3780 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3782 * The @code attr@ parameter may be modified as a result of setting the value.
3784 * The @code element@ parameter specifies which value to set from 0 to
3785 * @link ippGetCount(attr)@.
3787 * @since CUPS 1.6/OS X 10.8@
3790 int /* O - 1 on success, 0 on failure */
3791 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3792 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3793 int element
, /* I - Value number (0-based) */
3794 const ipp_uchar_t
*datevalue
)/* I - Date value */
3796 _ipp_value_t
*value
; /* Current value */
3800 * Range check input...
3803 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3804 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3808 * Set the value and return...
3811 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3812 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3814 return (value
!= NULL
);
3819 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3821 * The @code ipp@ parameter refers to an IPP message previously created using
3822 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3824 * The @code attr@ parameter may be modified as a result of setting the value.
3826 * The @code group@ parameter specifies the IPP attribute group tag: none
3827 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3828 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3829 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3830 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3832 * @since CUPS 1.6/OS X 10.8@
3835 int /* O - 1 on success, 0 on failure */
3837 ipp_t
*ipp
, /* I - IPP message */
3838 ipp_attribute_t
**attr
, /* IO - Attribute */
3839 ipp_tag_t group_tag
) /* I - Group tag */
3842 * Range check input - group tag must be 0x01 to 0x0F, per RFC 2911...
3845 if (!ipp
|| !attr
|| !*attr
||
3846 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3847 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3851 * Set the group tag and return...
3854 (*attr
)->group_tag
= group_tag
;
3861 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3863 * The @code ipp@ parameter refers to an IPP message previously created using
3864 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3866 * The @code attr@ parameter may be modified as a result of setting the value.
3868 * The @code element@ parameter specifies which value to set from 0 to
3869 * @link ippGetCount(attr)@.
3871 * @since CUPS 1.6/OS X 10.8@
3874 int /* O - 1 on success, 0 on failure */
3875 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3876 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3877 int element
, /* I - Value number (0-based) */
3878 int intvalue
) /* I - Integer/enum value */
3880 _ipp_value_t
*value
; /* Current value */
3884 * Range check input...
3887 if (!ipp
|| !attr
|| !*attr
||
3888 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3889 element
< 0 || element
> (*attr
)->num_values
)
3893 * Set the value and return...
3896 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3897 value
->integer
= intvalue
;
3899 return (value
!= NULL
);
3904 * 'ippSetName()' - Set the name of an attribute.
3906 * The @code ipp@ parameter refers to an IPP message previously created using
3907 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3909 * The @code attr@ parameter may be modified as a result of setting the value.
3911 * @since CUPS 1.6/OS X 10.8@
3914 int /* O - 1 on success, 0 on failure */
3915 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3916 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3917 const char *name
) /* I - Attribute name */
3919 char *temp
; /* Temporary name value */
3923 * Range check input...
3926 if (!ipp
|| !attr
|| !*attr
)
3930 * Set the value and return...
3933 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3936 _cupsStrFree((*attr
)->name
);
3938 (*attr
)->name
= temp
;
3941 return (temp
!= NULL
);
3946 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
3948 * The @code ipp@ parameter refers to an IPP message previously created using
3949 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3951 * The @code attr@ parameter may be modified as a result of setting the value.
3953 * The @code element@ parameter specifies which value to set from 0 to
3954 * @link ippGetCount(attr)@.
3956 * @since CUPS 1.7/OS X 10.9@
3959 int /* O - 1 on success, 0 on failure */
3961 ipp_t
*ipp
, /* I - IPP message */
3962 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3963 int element
, /* I - Value number (0-based) */
3964 const void *data
, /* I - Pointer to octetString data */
3965 int datalen
) /* I - Length of octetString data */
3967 _ipp_value_t
*value
; /* Current value */
3971 * Range check input...
3974 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_STRING
||
3975 element
< 0 || element
> (*attr
)->num_values
||
3976 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
3980 * Set the value and return...
3983 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3985 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
3988 * Just copy the pointer...
3991 value
->unknown
.data
= (void *)data
;
3992 value
->unknown
.length
= datalen
;
4000 if (value
->unknown
.data
)
4003 * Free previous data...
4006 free(value
->unknown
.data
);
4008 value
->unknown
.data
= NULL
;
4009 value
->unknown
.length
= 0;
4014 void *temp
; /* Temporary data pointer */
4016 if ((temp
= malloc((size_t)datalen
)) != NULL
)
4018 memcpy(temp
, data
, (size_t)datalen
);
4020 value
->unknown
.data
= temp
;
4021 value
->unknown
.length
= datalen
;
4029 return (value
!= NULL
);
4034 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
4036 * The @code ipp@ parameter refers to an IPP message previously created using
4037 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4039 * @since CUPS 1.6/OS X 10.8@
4042 int /* O - 1 on success, 0 on failure */
4043 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
4044 ipp_op_t op
) /* I - Operation ID */
4047 * Range check input...
4054 * Set the operation and return...
4057 ipp
->request
.op
.operation_id
= op
;
4064 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4066 * The @code ipp@ parameter refers to an IPP message previously created using
4067 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4069 * The @code attr@ parameter may be modified as a result of setting the value.
4071 * The @code element@ parameter specifies which value to set from 0 to
4072 * @link ippGetCount(attr)@.
4074 * @since CUPS 1.6/OS X 10.8@
4077 int /* O - 1 on success, 0 on failure */
4078 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4079 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4080 int element
, /* I - Value number (0-based) */
4081 int lowervalue
, /* I - Lower bound for range */
4082 int uppervalue
) /* I - Upper bound for range */
4084 _ipp_value_t
*value
; /* Current value */
4088 * Range check input...
4091 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4092 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4096 * Set the value and return...
4099 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4101 value
->range
.lower
= lowervalue
;
4102 value
->range
.upper
= uppervalue
;
4105 return (value
!= NULL
);
4110 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4112 * The @code ipp@ parameter refers to an IPP message previously created using
4113 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4115 * The @code request_id@ parameter must be greater than 0.
4117 * @since CUPS 1.6/OS X 10.8@
4120 int /* O - 1 on success, 0 on failure */
4121 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4122 int request_id
) /* I - Request ID */
4125 * Range check input; not checking request_id values since ipptool wants to send
4126 * invalid values for conformance testing and a bad request_id does not affect the
4127 * encoding of a message...
4134 * Set the request ID and return...
4137 ipp
->request
.any
.request_id
= request_id
;
4144 * 'ippSetResolution()' - Set a resolution value in an attribute.
4146 * The @code ipp@ parameter refers to an IPP message previously created using
4147 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4149 * The @code attr@ parameter may be modified as a result of setting the value.
4151 * The @code element@ parameter specifies which value to set from 0 to
4152 * @link ippGetCount(attr)@.
4154 * @since CUPS 1.6/OS X 10.8@
4157 int /* O - 1 on success, 0 on failure */
4159 ipp_t
*ipp
, /* I - IPP message */
4160 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4161 int element
, /* I - Value number (0-based) */
4162 ipp_res_t unitsvalue
, /* I - Resolution units */
4163 int xresvalue
, /* I - Horizontal/cross feed resolution */
4164 int yresvalue
) /* I - Vertical/feed resolution */
4166 _ipp_value_t
*value
; /* Current value */
4170 * Range check input...
4173 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4174 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4175 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4179 * Set the value and return...
4182 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4184 value
->resolution
.units
= unitsvalue
;
4185 value
->resolution
.xres
= xresvalue
;
4186 value
->resolution
.yres
= yresvalue
;
4189 return (value
!= NULL
);
4194 * 'ippSetState()' - Set the current state of the IPP message.
4196 * @since CUPS 1.6/OS X 10.8@
4199 int /* O - 1 on success, 0 on failure */
4200 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4201 ipp_state_t state
) /* I - IPP state value */
4204 * Range check input...
4211 * Set the state and return...
4215 ipp
->current
= NULL
;
4222 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4224 * The @code ipp@ parameter refers to an IPP message previously created using
4225 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4227 * @since CUPS 1.6/OS X 10.8@
4230 int /* O - 1 on success, 0 on failure */
4231 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4232 ipp_status_t status
) /* I - Status code */
4235 * Range check input...
4242 * Set the status code and return...
4245 ipp
->request
.status
.status_code
= status
;
4252 * 'ippSetString()' - Set a string value in an attribute.
4254 * The @code ipp@ parameter refers to an IPP message previously created using
4255 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4257 * The @code attr@ parameter may be modified as a result of setting the value.
4259 * The @code element@ parameter specifies which value to set from 0 to
4260 * @link ippGetCount(attr)@.
4262 * @since CUPS 1.6/OS X 10.8@
4265 int /* O - 1 on success, 0 on failure */
4266 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4267 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4268 int element
, /* I - Value number (0-based) */
4269 const char *strvalue
) /* I - String value */
4271 char *temp
; /* Temporary string */
4272 _ipp_value_t
*value
; /* Current value */
4276 * Range check input...
4279 if (!ipp
|| !attr
|| !*attr
||
4280 ((*attr
)->value_tag
!= IPP_TAG_TEXTLANG
&&
4281 (*attr
)->value_tag
!= IPP_TAG_NAMELANG
&&
4282 ((*attr
)->value_tag
< IPP_TAG_TEXT
||
4283 (*attr
)->value_tag
> IPP_TAG_MIMETYPE
)) ||
4284 element
< 0 || element
> (*attr
)->num_values
|| !strvalue
)
4288 * Set the value and return...
4291 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4294 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4296 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4297 value
->string
.text
= (char *)strvalue
;
4298 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4300 if (value
->string
.text
)
4301 _cupsStrFree(value
->string
.text
);
4303 value
->string
.text
= temp
;
4309 return (value
!= NULL
);
4314 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4316 * The @code ipp@ parameter refers to an IPP message previously created using
4317 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4319 * The @code attr@ parameter may be modified as a result of setting the value.
4321 * The @code element@ parameter specifies which value to set from 0 to
4322 * @link ippGetCount(attr)@.
4324 * The @code format@ parameter uses formatting characters compatible with the
4325 * printf family of standard functions. Additional arguments follow it as
4326 * needed. The formatted string is truncated as needed to the maximum length of
4327 * the corresponding value type.
4329 * @since CUPS 1.7/OS X 10.9@
4332 int /* O - 1 on success, 0 on failure */
4333 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4334 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4335 int element
, /* I - Value number (0-based) */
4336 const char *format
, /* I - Printf-style format string */
4337 ...) /* I - Additional arguments as needed */
4339 int ret
; /* Return value */
4340 va_list ap
; /* Pointer to additional arguments */
4343 va_start(ap
, format
);
4344 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4352 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4354 * The @code ipp@ parameter refers to an IPP message previously created using
4355 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4357 * The @code attr@ parameter may be modified as a result of setting the value.
4359 * The @code element@ parameter specifies which value to set from 0 to
4360 * @link ippGetCount(attr)@.
4362 * The @code format@ parameter uses formatting characters compatible with the
4363 * printf family of standard functions. Additional arguments follow it as
4364 * needed. The formatted string is truncated as needed to the maximum length of
4365 * the corresponding value type.
4367 * @since CUPS 1.7/OS X 10.9@
4370 int /* O - 1 on success, 0 on failure */
4371 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4372 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4373 int element
, /* I - Value number (0-based) */
4374 const char *format
, /* I - Printf-style format string */
4375 va_list ap
) /* I - Pointer to additional arguments */
4377 ipp_tag_t value_tag
; /* Value tag */
4378 char buffer
[IPP_MAX_TEXT
+ 4];
4379 /* Formatted text string */
4380 ssize_t bytes
, /* Length of formatted value */
4381 max_bytes
; /* Maximum number of bytes for value */
4385 * Range check input...
4389 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4391 value_tag
= IPP_TAG_ZERO
;
4393 if (!ipp
|| !attr
|| !*attr
||
4394 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4395 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4400 * Format the string...
4403 if (!strcmp(format
, "%s"))
4406 * Optimize the simple case...
4409 const char *s
= va_arg(ap
, char *);
4414 bytes
= (ssize_t
)strlen(s
);
4415 strlcpy(buffer
, s
, sizeof(buffer
));
4420 * Do a full formatting of the message...
4423 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4428 * Limit the length of the string...
4435 case IPP_TAG_TEXTLANG
:
4436 max_bytes
= IPP_MAX_TEXT
;
4440 case IPP_TAG_NAMELANG
:
4441 max_bytes
= IPP_MAX_NAME
;
4444 case IPP_TAG_CHARSET
:
4445 max_bytes
= IPP_MAX_CHARSET
;
4448 case IPP_TAG_KEYWORD
:
4449 max_bytes
= IPP_MAX_KEYWORD
;
4452 case IPP_TAG_LANGUAGE
:
4453 max_bytes
= IPP_MAX_LANGUAGE
;
4456 case IPP_TAG_MIMETYPE
:
4457 max_bytes
= IPP_MAX_MIMETYPE
;
4461 max_bytes
= IPP_MAX_URI
;
4464 case IPP_TAG_URISCHEME
:
4465 max_bytes
= IPP_MAX_URISCHEME
;
4469 if (bytes
>= max_bytes
)
4471 char *bufmax
, /* Buffer at max_bytes */
4472 *bufptr
; /* Pointer into buffer */
4474 bufptr
= buffer
+ strlen(buffer
) - 1;
4475 bufmax
= buffer
+ max_bytes
- 1;
4477 while (bufptr
> bufmax
)
4481 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4492 * Set the formatted string and return...
4495 return (ippSetString(ipp
, attr
, element
, buffer
));
4500 * 'ippSetValueTag()' - Set the value tag of an attribute.
4502 * The @code ipp@ parameter refers to an IPP message previously created using
4503 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4505 * The @code attr@ parameter may be modified as a result of setting the value.
4507 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4508 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4509 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4510 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4511 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4512 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4515 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4516 * code in the "attributes-natural-language" attribute or, if not present, the language
4517 * code for the current locale.
4519 * @since CUPS 1.6/OS X 10.8@
4522 int /* O - 1 on success, 0 on failure */
4524 ipp_t
*ipp
, /* I - IPP message */
4525 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4526 ipp_tag_t value_tag
) /* I - Value tag */
4528 int i
; /* Looping var */
4529 _ipp_value_t
*value
; /* Current value */
4530 int integer
; /* Current integer value */
4531 cups_lang_t
*language
; /* Current language */
4532 char code
[32]; /* Language code */
4533 ipp_tag_t temp_tag
; /* Temporary value tag */
4537 * Range check input...
4540 if (!ipp
|| !attr
|| !*attr
)
4544 * If there is no change, return immediately...
4547 if (value_tag
== (*attr
)->value_tag
)
4551 * Otherwise implement changes as needed...
4554 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4558 case IPP_TAG_UNSUPPORTED_VALUE
:
4559 case IPP_TAG_DEFAULT
:
4560 case IPP_TAG_UNKNOWN
:
4561 case IPP_TAG_NOVALUE
:
4562 case IPP_TAG_NOTSETTABLE
:
4563 case IPP_TAG_DELETEATTR
:
4564 case IPP_TAG_ADMINDEFINE
:
4566 * Free any existing values...
4569 if ((*attr
)->num_values
> 0)
4570 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4573 * Set out-of-band value...
4576 (*attr
)->value_tag
= value_tag
;
4579 case IPP_TAG_RANGE
:
4580 if (temp_tag
!= IPP_TAG_INTEGER
)
4583 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4587 integer
= value
->integer
;
4588 value
->range
.lower
= value
->range
.upper
= integer
;
4591 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4595 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4596 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4597 temp_tag
!= IPP_TAG_MIMETYPE
)
4600 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4603 case IPP_TAG_NAMELANG
:
4604 case IPP_TAG_TEXTLANG
:
4605 if (value_tag
== IPP_TAG_NAMELANG
&&
4606 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4607 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4608 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4611 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4614 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4615 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4618 * Use the language code from the IPP message...
4621 (*attr
)->values
[0].string
.language
=
4622 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4627 * Otherwise, use the language code corresponding to the locale...
4630 language
= cupsLangDefault();
4631 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4636 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4639 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4641 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4644 * Make copies of all values...
4647 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4650 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4653 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4656 case IPP_TAG_KEYWORD
:
4657 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4658 break; /* Silently "allow" name -> keyword */
4669 * 'ippSetVersion()' - Set the version number in an IPP message.
4671 * The @code ipp@ parameter refers to an IPP message previously created using
4672 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4674 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4676 * @since CUPS 1.6/OS X 10.8@
4679 int /* O - 1 on success, 0 on failure */
4680 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4681 int major
, /* I - Major version number (major.minor) */
4682 int minor
) /* I - Minor version number (major.minor) */
4685 * Range check input...
4688 if (!ipp
|| major
< 0 || minor
< 0)
4692 * Set the version number...
4695 ipp
->request
.any
.version
[0] = (ipp_uchar_t
)major
;
4696 ipp
->request
.any
.version
[1] = (ipp_uchar_t
)minor
;
4703 * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
4706 const ipp_uchar_t
* /* O - RFC-1903 date/time data */
4707 ippTimeToDate(time_t t
) /* I - UNIX time value */
4709 struct tm
*unixdate
; /* UNIX unixdate/time info */
4710 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4711 /* RFC-1903 date/time data */
4715 * RFC-1903 date/time format is:
4717 * Byte(s) Description
4718 * ------- -----------
4719 * 0-1 Year (0 to 65535)
4723 * 5 Minutes (0 to 59)
4724 * 6 Seconds (0 to 60, 60 = "leap second")
4725 * 7 Deciseconds (0 to 9)
4727 * 9 UTC hours (0 to 11)
4728 * 10 UTC minutes (0 to 59)
4731 unixdate
= gmtime(&t
);
4732 unixdate
->tm_year
+= 1900;
4734 date
[0] = (ipp_uchar_t
)(unixdate
->tm_year
>> 8);
4735 date
[1] = (ipp_uchar_t
)(unixdate
->tm_year
);
4736 date
[2] = (ipp_uchar_t
)(unixdate
->tm_mon
+ 1);
4737 date
[3] = (ipp_uchar_t
)unixdate
->tm_mday
;
4738 date
[4] = (ipp_uchar_t
)unixdate
->tm_hour
;
4739 date
[5] = (ipp_uchar_t
)unixdate
->tm_min
;
4740 date
[6] = (ipp_uchar_t
)unixdate
->tm_sec
;
4751 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4753 * This function validates the contents of an attribute based on the name and
4754 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4755 * failure, cupsLastErrorString() is set to a human-readable message.
4757 * @since CUPS 1.7/OS X 10.9@
4760 int /* O - 1 if valid, 0 otherwise */
4761 ippValidateAttribute(
4762 ipp_attribute_t
*attr
) /* I - Attribute */
4764 int i
; /* Looping var */
4765 char scheme
[64], /* Scheme from URI */
4766 userpass
[256], /* Username/password from URI */
4767 hostname
[256], /* Hostname from URI */
4768 resource
[1024]; /* Resource from URI */
4769 int port
, /* Port number from URI */
4770 uri_status
; /* URI separation status */
4771 const char *ptr
; /* Pointer into string */
4772 ipp_attribute_t
*colattr
; /* Collection attribute */
4773 regex_t re
; /* Regular expression */
4774 ipp_uchar_t
*date
; /* Current date value */
4775 static const char * const uri_status_strings
[] =
4776 { /* URI status strings */
4778 "Bad arguments to function",
4779 "Bad resource in URI",
4780 "Bad port number in URI",
4781 "Bad hostname/address in URI",
4782 "Bad username in URI",
4783 "Bad scheme in URI",
4786 "Missing scheme in URI",
4787 "Unknown scheme in URI",
4788 "Missing resource in URI"
4800 * Validate the attribute name.
4803 for (ptr
= attr
->name
; *ptr
; ptr
++)
4804 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4807 if (*ptr
|| ptr
== attr
->name
)
4809 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4810 _("\"%s\": Bad attribute name - invalid character "
4811 "(RFC 2911 section 4.1.3)."), attr
->name
);
4815 if ((ptr
- attr
->name
) > 255)
4817 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4818 _("\"%s\": Bad attribute name - bad length %d "
4819 "(RFC 2911 section 4.1.3)."), attr
->name
,
4820 (int)(ptr
- attr
->name
));
4824 switch (attr
->value_tag
)
4826 case IPP_TAG_INTEGER
:
4829 case IPP_TAG_BOOLEAN
:
4830 for (i
= 0; i
< attr
->num_values
; i
++)
4832 if (attr
->values
[i
].boolean
!= 0 &&
4833 attr
->values
[i
].boolean
!= 1)
4835 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4836 _("\"%s\": Bad boolen value %d "
4837 "(RFC 2911 section 4.1.11)."), attr
->name
,
4838 attr
->values
[i
].boolean
);
4845 for (i
= 0; i
< attr
->num_values
; i
++)
4847 if (attr
->values
[i
].integer
< 1)
4849 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4850 _("\"%s\": Bad enum value %d - out of range "
4851 "(RFC 2911 section 4.1.4)."), attr
->name
,
4852 attr
->values
[i
].integer
);
4858 case IPP_TAG_STRING
:
4859 for (i
= 0; i
< attr
->num_values
; i
++)
4861 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4863 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4864 _("\"%s\": Bad octetString value - bad length %d "
4865 "(RFC 2911 section 4.1.10)."), attr
->name
,
4866 attr
->values
[i
].unknown
.length
);
4873 for (i
= 0; i
< attr
->num_values
; i
++)
4875 date
= attr
->values
[i
].date
;
4877 if (date
[2] < 1 || date
[2] > 12)
4879 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4880 _("\"%s\": Bad dateTime month %u "
4881 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[2]);
4885 if (date
[3] < 1 || date
[3] > 31)
4887 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4888 _("\"%s\": Bad dateTime day %u "
4889 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[3]);
4895 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4896 _("\"%s\": Bad dateTime hours %u "
4897 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[4]);
4903 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4904 _("\"%s\": Bad dateTime minutes %u "
4905 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[5]);
4911 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4912 _("\"%s\": Bad dateTime seconds %u "
4913 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[6]);
4919 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4920 _("\"%s\": Bad dateTime deciseconds %u "
4921 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[7]);
4925 if (date
[8] != '-' && date
[8] != '+')
4927 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4928 _("\"%s\": Bad dateTime UTC sign '%c' "
4929 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[8]);
4935 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4936 _("\"%s\": Bad dateTime UTC hours %u "
4937 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[9]);
4943 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4944 _("\"%s\": Bad dateTime UTC minutes %u "
4945 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[10]);
4951 case IPP_TAG_RESOLUTION
:
4952 for (i
= 0; i
< attr
->num_values
; i
++)
4954 if (attr
->values
[i
].resolution
.xres
<= 0)
4956 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4957 _("\"%s\": Bad resolution value %dx%d%s - cross "
4958 "feed resolution must be positive "
4959 "(RFC 2911 section 4.1.15)."), attr
->name
,
4960 attr
->values
[i
].resolution
.xres
,
4961 attr
->values
[i
].resolution
.yres
,
4962 attr
->values
[i
].resolution
.units
==
4963 IPP_RES_PER_INCH
? "dpi" :
4964 attr
->values
[i
].resolution
.units
==
4965 IPP_RES_PER_CM
? "dpcm" : "unknown");
4969 if (attr
->values
[i
].resolution
.yres
<= 0)
4971 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4972 _("\"%s\": Bad resolution value %dx%d%s - feed "
4973 "resolution must be positive "
4974 "(RFC 2911 section 4.1.15)."), attr
->name
,
4975 attr
->values
[i
].resolution
.xres
,
4976 attr
->values
[i
].resolution
.yres
,
4977 attr
->values
[i
].resolution
.units
==
4978 IPP_RES_PER_INCH
? "dpi" :
4979 attr
->values
[i
].resolution
.units
==
4980 IPP_RES_PER_CM
? "dpcm" : "unknown");
4984 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
4985 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
4987 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4988 _("\"%s\": Bad resolution value %dx%d%s - bad "
4989 "units value (RFC 2911 section 4.1.15)."),
4990 attr
->name
, attr
->values
[i
].resolution
.xres
,
4991 attr
->values
[i
].resolution
.yres
,
4992 attr
->values
[i
].resolution
.units
==
4993 IPP_RES_PER_INCH
? "dpi" :
4994 attr
->values
[i
].resolution
.units
==
4995 IPP_RES_PER_CM
? "dpcm" : "unknown");
5001 case IPP_TAG_RANGE
:
5002 for (i
= 0; i
< attr
->num_values
; i
++)
5004 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
5006 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5007 _("\"%s\": Bad rangeOfInteger value %d-%d - lower "
5008 "greater than upper (RFC 2911 section 4.1.13)."),
5009 attr
->name
, attr
->values
[i
].range
.lower
,
5010 attr
->values
[i
].range
.upper
);
5016 case IPP_TAG_BEGIN_COLLECTION
:
5017 for (i
= 0; i
< attr
->num_values
; i
++)
5019 for (colattr
= attr
->values
[i
].collection
->attrs
;
5021 colattr
= colattr
->next
)
5023 if (!ippValidateAttribute(colattr
))
5030 case IPP_TAG_TEXTLANG
:
5031 for (i
= 0; i
< attr
->num_values
; i
++)
5033 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5035 if ((*ptr
& 0xe0) == 0xc0)
5038 if ((*ptr
& 0xc0) != 0x80)
5041 else if ((*ptr
& 0xf0) == 0xe0)
5044 if ((*ptr
& 0xc0) != 0x80)
5047 if ((*ptr
& 0xc0) != 0x80)
5050 else if ((*ptr
& 0xf8) == 0xf0)
5053 if ((*ptr
& 0xc0) != 0x80)
5056 if ((*ptr
& 0xc0) != 0x80)
5059 if ((*ptr
& 0xc0) != 0x80)
5062 else if (*ptr
& 0x80)
5068 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5069 _("\"%s\": Bad text value \"%s\" - bad UTF-8 "
5070 "sequence (RFC 2911 section 4.1.1)."), attr
->name
,
5071 attr
->values
[i
].string
.text
);
5075 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5077 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5078 _("\"%s\": Bad text value \"%s\" - bad length %d "
5079 "(RFC 2911 section 4.1.1)."), attr
->name
,
5080 attr
->values
[i
].string
.text
,
5081 (int)(ptr
- attr
->values
[i
].string
.text
));
5088 case IPP_TAG_NAMELANG
:
5089 for (i
= 0; i
< attr
->num_values
; i
++)
5091 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5093 if ((*ptr
& 0xe0) == 0xc0)
5096 if ((*ptr
& 0xc0) != 0x80)
5099 else if ((*ptr
& 0xf0) == 0xe0)
5102 if ((*ptr
& 0xc0) != 0x80)
5105 if ((*ptr
& 0xc0) != 0x80)
5108 else if ((*ptr
& 0xf8) == 0xf0)
5111 if ((*ptr
& 0xc0) != 0x80)
5114 if ((*ptr
& 0xc0) != 0x80)
5117 if ((*ptr
& 0xc0) != 0x80)
5120 else if (*ptr
& 0x80)
5126 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5127 _("\"%s\": Bad name value \"%s\" - bad UTF-8 "
5128 "sequence (RFC 2911 section 4.1.2)."), attr
->name
,
5129 attr
->values
[i
].string
.text
);
5133 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5135 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5136 _("\"%s\": Bad name value \"%s\" - bad length %d "
5137 "(RFC 2911 section 4.1.2)."), attr
->name
,
5138 attr
->values
[i
].string
.text
,
5139 (int)(ptr
- attr
->values
[i
].string
.text
));
5145 case IPP_TAG_KEYWORD
:
5146 for (i
= 0; i
< attr
->num_values
; i
++)
5148 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5149 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5153 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5155 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5156 _("\"%s\": Bad keyword value \"%s\" - invalid "
5157 "character (RFC 2911 section 4.1.3)."),
5158 attr
->name
, attr
->values
[i
].string
.text
);
5162 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5164 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5165 _("\"%s\": Bad keyword value \"%s\" - bad "
5166 "length %d (RFC 2911 section 4.1.3)."),
5167 attr
->name
, attr
->values
[i
].string
.text
,
5168 (int)(ptr
- attr
->values
[i
].string
.text
));
5175 for (i
= 0; i
< attr
->num_values
; i
++)
5177 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5178 attr
->values
[i
].string
.text
,
5179 scheme
, sizeof(scheme
),
5180 userpass
, sizeof(userpass
),
5181 hostname
, sizeof(hostname
),
5182 &port
, resource
, sizeof(resource
));
5184 if (uri_status
< HTTP_URI_STATUS_OK
)
5186 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5187 _("\"%s\": Bad URI value \"%s\" - %s "
5188 "(RFC 2911 section 4.1.5)."), attr
->name
,
5189 attr
->values
[i
].string
.text
,
5190 uri_status_strings
[uri_status
-
5191 HTTP_URI_STATUS_OVERFLOW
]);
5195 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5197 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5198 _("\"%s\": Bad URI value \"%s\" - bad length %d "
5199 "(RFC 2911 section 4.1.5)."), attr
->name
,
5200 attr
->values
[i
].string
.text
,
5201 (int)strlen(attr
->values
[i
].string
.text
));
5206 case IPP_TAG_URISCHEME
:
5207 for (i
= 0; i
< attr
->num_values
; i
++)
5209 ptr
= attr
->values
[i
].string
.text
;
5210 if (islower(*ptr
& 255))
5212 for (ptr
++; *ptr
; ptr
++)
5213 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5214 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5218 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5220 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5221 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5222 "characters (RFC 2911 section 4.1.6)."),
5223 attr
->name
, attr
->values
[i
].string
.text
);
5227 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5229 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5230 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5231 "length %d (RFC 2911 section 4.1.6)."),
5232 attr
->name
, attr
->values
[i
].string
.text
,
5233 (int)(ptr
- attr
->values
[i
].string
.text
));
5239 case IPP_TAG_CHARSET
:
5240 for (i
= 0; i
< attr
->num_values
; i
++)
5242 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5243 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5244 isspace(*ptr
& 255))
5247 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5249 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5250 _("\"%s\": Bad charset value \"%s\" - bad "
5251 "characters (RFC 2911 section 4.1.7)."),
5252 attr
->name
, attr
->values
[i
].string
.text
);
5256 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5258 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5259 _("\"%s\": Bad charset value \"%s\" - bad "
5260 "length %d (RFC 2911 section 4.1.7)."),
5261 attr
->name
, attr
->values
[i
].string
.text
,
5262 (int)(ptr
- attr
->values
[i
].string
.text
));
5268 case IPP_TAG_LANGUAGE
:
5270 * The following regular expression is derived from the ABNF for
5271 * language tags in RFC 4646. All I can say is that this is the
5272 * easiest way to check the values...
5275 if ((i
= regcomp(&re
,
5277 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5279 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5280 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5281 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5282 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5283 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5285 "x(-[a-z0-9]{1,8})+" /* privateuse */
5287 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5289 REG_NOSUB
| REG_EXTENDED
)) != 0)
5291 char temp
[256]; /* Temporary error string */
5293 regerror(i
, &re
, temp
, sizeof(temp
));
5294 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
,
5295 _("Unable to compile naturalLanguage regular "
5296 "expression: %s."), temp
);
5300 for (i
= 0; i
< attr
->num_values
; i
++)
5302 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5304 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5305 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5306 "characters (RFC 2911 section 4.1.8)."),
5307 attr
->name
, attr
->values
[i
].string
.text
);
5312 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5314 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5315 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5316 "length %d (RFC 2911 section 4.1.8)."),
5317 attr
->name
, attr
->values
[i
].string
.text
,
5318 (int)strlen(attr
->values
[i
].string
.text
));
5327 case IPP_TAG_MIMETYPE
:
5329 * The following regular expression is derived from the ABNF for
5330 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5331 * the easiest way to check the values...
5334 if ((i
= regcomp(&re
,
5336 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5338 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5339 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5340 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5343 REG_NOSUB
| REG_EXTENDED
)) != 0)
5345 char temp
[256]; /* Temporary error string */
5347 regerror(i
, &re
, temp
, sizeof(temp
));
5348 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5349 _("Unable to compile mimeMediaType regular "
5350 "expression: %s."), temp
);
5354 for (i
= 0; i
< attr
->num_values
; i
++)
5356 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5358 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5359 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5360 "characters (RFC 2911 section 4.1.9)."),
5361 attr
->name
, attr
->values
[i
].string
.text
);
5366 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5368 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5369 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5370 "length %d (RFC 2911 section 4.1.9)."),
5371 attr
->name
, attr
->values
[i
].string
.text
,
5372 (int)strlen(attr
->values
[i
].string
.text
));
5390 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5392 * This function validates the contents of the IPP message, including each
5393 * attribute. Like @link ippValidateAttribute@, cupsLastErrorString() is set
5394 * to a human-readable message on failure.
5396 * @since CUPS 1.7/OS X 10.9@
5399 int /* O - 1 if valid, 0 otherwise */
5400 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5402 ipp_attribute_t
*attr
; /* Current attribute */
5408 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5409 if (!ippValidateAttribute(attr
))
5417 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5420 ipp_state_t
/* O - Current state */
5421 ippWrite(http_t
*http
, /* I - HTTP connection */
5422 ipp_t
*ipp
) /* I - IPP data */
5424 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http
, (void *)ipp
));
5427 return (IPP_STATE_ERROR
);
5429 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5434 * 'ippWriteFile()' - Write data for an IPP message to a file.
5436 * @since CUPS 1.1.19/OS X 10.3@
5439 ipp_state_t
/* O - Current state */
5440 ippWriteFile(int fd
, /* I - HTTP data */
5441 ipp_t
*ipp
) /* I - IPP data */
5443 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
5445 ipp
->state
= IPP_STATE_IDLE
;
5447 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5452 * 'ippWriteIO()' - Write data for an IPP message.
5454 * @since CUPS 1.2/OS X 10.5@
5457 ipp_state_t
/* O - Current state */
5458 ippWriteIO(void *dst
, /* I - Destination */
5459 ipp_iocb_t cb
, /* I - Write callback function */
5460 int blocking
, /* I - Use blocking IO? */
5461 ipp_t
*parent
, /* I - Parent IPP message */
5462 ipp_t
*ipp
) /* I - IPP data */
5464 int i
; /* Looping var */
5465 int n
; /* Length of data */
5466 unsigned char *buffer
, /* Data buffer */
5467 *bufptr
; /* Pointer into buffer */
5468 ipp_attribute_t
*attr
; /* Current attribute */
5469 _ipp_value_t
*value
; /* Current value */
5472 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
5475 return (IPP_STATE_ERROR
);
5477 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5479 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5480 return (IPP_STATE_ERROR
);
5485 case IPP_STATE_IDLE
:
5486 ipp
->state
++; /* Avoid common problem... */
5488 case IPP_STATE_HEADER
:
5492 * Send the request header:
5495 * Operation/Status Code = 2 bytes
5496 * Request ID = 4 bytes
5502 *bufptr
++ = ipp
->request
.any
.version
[0];
5503 *bufptr
++ = ipp
->request
.any
.version
[1];
5504 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.op_status
>> 8);
5505 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.op_status
;
5506 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 24);
5507 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 16);
5508 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 8);
5509 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.request_id
;
5511 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5512 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5513 ipp
->request
.any
.op_status
));
5514 DEBUG_printf(("2ippWriteIO: request_id=%d",
5515 ipp
->request
.any
.request_id
));
5517 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5519 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5520 _cupsBufferRelease((char *)buffer
);
5521 return (IPP_STATE_ERROR
);
5526 * Reset the state engine to point to the first attribute
5527 * in the request/response, with no current group.
5530 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5531 ipp
->current
= ipp
->attrs
;
5532 ipp
->curtag
= IPP_TAG_ZERO
;
5534 DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp
->current
));
5537 * If blocking is disabled, stop here...
5543 case IPP_STATE_ATTRIBUTE
:
5544 while (ipp
->current
!= NULL
)
5547 * Write this attribute...
5551 attr
= ipp
->current
;
5553 ipp
->current
= ipp
->current
->next
;
5557 if (ipp
->curtag
!= attr
->group_tag
)
5560 * Send a group tag byte...
5563 ipp
->curtag
= attr
->group_tag
;
5565 if (attr
->group_tag
== IPP_TAG_ZERO
)
5568 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5569 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5570 *bufptr
++ = (ipp_uchar_t
)attr
->group_tag
;
5572 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5576 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5577 attr
->num_values
> 1 ? "1setOf " : "",
5578 ippTagString(attr
->value_tag
)));
5581 * Write the attribute tag and name.
5583 * The attribute name length does not include the trailing nul
5584 * character in the source string.
5586 * Collection values (parent != NULL) are written differently...
5592 * Get the length of the attribute name, and make sure it won't
5593 * overflow the buffer...
5596 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5598 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5599 _cupsBufferRelease((char *)buffer
);
5600 return (IPP_STATE_ERROR
);
5604 * Write the value tag, name length, and name string...
5607 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5608 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5609 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5612 if (attr
->value_tag
> 0xff)
5614 *bufptr
++ = IPP_TAG_EXTENSION
;
5615 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5616 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5617 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5618 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5621 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5623 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5624 *bufptr
++ = (ipp_uchar_t
)n
;
5625 memcpy(bufptr
, attr
->name
, (size_t)n
);
5631 * Get the length of the attribute name, and make sure it won't
5632 * overflow the buffer...
5635 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5637 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5638 _cupsBufferRelease((char *)buffer
);
5639 return (IPP_STATE_ERROR
);
5643 * Write the member name tag, name length, name string, value tag,
5644 * and empty name for the collection member attribute...
5647 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5648 IPP_TAG_MEMBERNAME
));
5649 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5651 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5652 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5653 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5655 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5658 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5659 *bufptr
++ = (ipp_uchar_t
)n
;
5660 memcpy(bufptr
, attr
->name
, (size_t)n
);
5663 if (attr
->value_tag
> 0xff)
5665 *bufptr
++ = IPP_TAG_EXTENSION
;
5666 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5667 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5668 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5669 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5672 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5679 * Now write the attribute value(s)...
5682 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5684 case IPP_TAG_UNSUPPORTED_VALUE
:
5685 case IPP_TAG_DEFAULT
:
5686 case IPP_TAG_UNKNOWN
:
5687 case IPP_TAG_NOVALUE
:
5688 case IPP_TAG_NOTSETTABLE
:
5689 case IPP_TAG_DELETEATTR
:
5690 case IPP_TAG_ADMINDEFINE
:
5695 case IPP_TAG_INTEGER
:
5697 for (i
= 0, value
= attr
->values
;
5698 i
< attr
->num_values
;
5701 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5703 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5705 DEBUG_puts("1ippWriteIO: Could not write IPP "
5707 _cupsBufferRelease((char *)buffer
);
5708 return (IPP_STATE_ERROR
);
5717 * Arrays and sets are done by sending additional
5718 * values with a zero-length name...
5721 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5727 * Integers and enumerations are both 4-byte signed
5728 * (twos-complement) values.
5730 * Put the 2-byte length and 4-byte value into the buffer...
5735 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 24);
5736 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 16);
5737 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 8);
5738 *bufptr
++ = (ipp_uchar_t
)value
->integer
;
5742 case IPP_TAG_BOOLEAN
:
5743 for (i
= 0, value
= attr
->values
;
5744 i
< attr
->num_values
;
5747 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5749 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5751 DEBUG_puts("1ippWriteIO: Could not write IPP "
5753 _cupsBufferRelease((char *)buffer
);
5754 return (IPP_STATE_ERROR
);
5763 * Arrays and sets are done by sending additional
5764 * values with a zero-length name...
5767 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5773 * Boolean values are 1-byte; 0 = false, 1 = true.
5775 * Put the 2-byte length and 1-byte value into the buffer...
5780 *bufptr
++ = (ipp_uchar_t
)value
->boolean
;
5786 case IPP_TAG_KEYWORD
:
5788 case IPP_TAG_URISCHEME
:
5789 case IPP_TAG_CHARSET
:
5790 case IPP_TAG_LANGUAGE
:
5791 case IPP_TAG_MIMETYPE
:
5792 for (i
= 0, value
= attr
->values
;
5793 i
< attr
->num_values
;
5799 * Arrays and sets are done by sending additional
5800 * values with a zero-length name...
5803 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5805 ippTagString(attr
->value_tag
)));
5806 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5808 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5810 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5812 DEBUG_puts("1ippWriteIO: Could not write IPP "
5814 _cupsBufferRelease((char *)buffer
);
5815 return (IPP_STATE_ERROR
);
5821 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5826 if (value
->string
.text
!= NULL
)
5827 n
= (int)strlen(value
->string
.text
);
5831 if (n
> (IPP_BUF_SIZE
- 2))
5833 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5834 _cupsBufferRelease((char *)buffer
);
5835 return (IPP_STATE_ERROR
);
5838 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5839 value
->string
.text
));
5841 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5843 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5845 DEBUG_puts("1ippWriteIO: Could not write IPP "
5847 _cupsBufferRelease((char *)buffer
);
5848 return (IPP_STATE_ERROR
);
5855 * All simple strings consist of the 2-byte length and
5856 * character data without the trailing nul normally found
5857 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5858 * bytes since the 2-byte length is a signed (twos-complement)
5861 * Put the 2-byte length and string characters in the buffer.
5864 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5865 *bufptr
++ = (ipp_uchar_t
)n
;
5869 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5876 for (i
= 0, value
= attr
->values
;
5877 i
< attr
->num_values
;
5880 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5882 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5884 DEBUG_puts("1ippWriteIO: Could not write IPP "
5886 _cupsBufferRelease((char *)buffer
);
5887 return (IPP_STATE_ERROR
);
5896 * Arrays and sets are done by sending additional
5897 * values with a zero-length name...
5900 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5906 * Date values consist of a 2-byte length and an
5907 * 11-byte date/time structure defined by RFC 1903.
5909 * Put the 2-byte length and 11-byte date/time
5910 * structure in the buffer.
5915 memcpy(bufptr
, value
->date
, 11);
5920 case IPP_TAG_RESOLUTION
:
5921 for (i
= 0, value
= attr
->values
;
5922 i
< attr
->num_values
;
5925 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5927 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5929 DEBUG_puts("1ippWriteIO: Could not write IPP "
5931 _cupsBufferRelease((char *)buffer
);
5932 return (IPP_STATE_ERROR
);
5941 * Arrays and sets are done by sending additional
5942 * values with a zero-length name...
5945 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5951 * Resolution values consist of a 2-byte length,
5952 * 4-byte horizontal resolution value, 4-byte vertical
5953 * resolution value, and a 1-byte units value.
5955 * Put the 2-byte length and resolution value data
5961 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 24);
5962 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 16);
5963 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 8);
5964 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.xres
;
5965 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 24);
5966 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 16);
5967 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 8);
5968 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.yres
;
5969 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.units
;
5973 case IPP_TAG_RANGE
:
5974 for (i
= 0, value
= attr
->values
;
5975 i
< attr
->num_values
;
5978 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
5980 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5982 DEBUG_puts("1ippWriteIO: Could not write IPP "
5984 _cupsBufferRelease((char *)buffer
);
5985 return (IPP_STATE_ERROR
);
5994 * Arrays and sets are done by sending additional
5995 * values with a zero-length name...
5998 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6004 * Range values consist of a 2-byte length,
6005 * 4-byte lower value, and 4-byte upper value.
6007 * Put the 2-byte length and range value data
6013 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 24);
6014 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 16);
6015 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 8);
6016 *bufptr
++ = (ipp_uchar_t
)value
->range
.lower
;
6017 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 24);
6018 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 16);
6019 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 8);
6020 *bufptr
++ = (ipp_uchar_t
)value
->range
.upper
;
6024 case IPP_TAG_TEXTLANG
:
6025 case IPP_TAG_NAMELANG
:
6026 for (i
= 0, value
= attr
->values
;
6027 i
< attr
->num_values
;
6033 * Arrays and sets are done by sending additional
6034 * values with a zero-length name...
6037 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6039 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6041 DEBUG_puts("1ippWriteIO: Could not write IPP "
6043 _cupsBufferRelease((char *)buffer
);
6044 return (IPP_STATE_ERROR
);
6050 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6056 * textWithLanguage and nameWithLanguage values consist
6057 * of a 2-byte length for both strings and their
6058 * individual lengths, a 2-byte length for the
6059 * character string, the character string without the
6060 * trailing nul, a 2-byte length for the character
6061 * set string, and the character set string without
6067 if (value
->string
.language
!= NULL
)
6068 n
+= (int)strlen(value
->string
.language
);
6070 if (value
->string
.text
!= NULL
)
6071 n
+= (int)strlen(value
->string
.text
);
6073 if (n
> (IPP_BUF_SIZE
- 2))
6075 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
6076 "too long (%d)", n
));
6077 _cupsBufferRelease((char *)buffer
);
6078 return (IPP_STATE_ERROR
);
6081 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6083 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6085 DEBUG_puts("1ippWriteIO: Could not write IPP "
6087 _cupsBufferRelease((char *)buffer
);
6088 return (IPP_STATE_ERROR
);
6094 /* Length of entire value */
6095 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6096 *bufptr
++ = (ipp_uchar_t
)n
;
6098 /* Length of language */
6099 if (value
->string
.language
!= NULL
)
6100 n
= (int)strlen(value
->string
.language
);
6104 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6105 *bufptr
++ = (ipp_uchar_t
)n
;
6110 memcpy(bufptr
, value
->string
.language
, (size_t)n
);
6114 /* Length of text */
6115 if (value
->string
.text
!= NULL
)
6116 n
= (int)strlen(value
->string
.text
);
6120 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6121 *bufptr
++ = (ipp_uchar_t
)n
;
6126 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
6132 case IPP_TAG_BEGIN_COLLECTION
:
6133 for (i
= 0, value
= attr
->values
;
6134 i
< attr
->num_values
;
6138 * Collections are written with the begin-collection
6139 * tag first with a value of 0 length, followed by the
6140 * attributes in the collection, then the end-collection
6144 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6146 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6148 DEBUG_puts("1ippWriteIO: Could not write IPP "
6150 _cupsBufferRelease((char *)buffer
);
6151 return (IPP_STATE_ERROR
);
6160 * Arrays and sets are done by sending additional
6161 * values with a zero-length name...
6164 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6170 * Write a data length of 0 and flush the buffer...
6176 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6178 DEBUG_puts("1ippWriteIO: Could not write IPP "
6180 _cupsBufferRelease((char *)buffer
);
6181 return (IPP_STATE_ERROR
);
6187 * Then write the collection attribute...
6190 value
->collection
->state
= IPP_STATE_IDLE
;
6192 if (ippWriteIO(dst
, cb
, 1, ipp
,
6193 value
->collection
) == IPP_STATE_ERROR
)
6195 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6196 _cupsBufferRelease((char *)buffer
);
6197 return (IPP_STATE_ERROR
);
6203 for (i
= 0, value
= attr
->values
;
6204 i
< attr
->num_values
;
6210 * Arrays and sets are done by sending additional
6211 * values with a zero-length name...
6214 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6216 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6218 DEBUG_puts("1ippWriteIO: Could not write IPP "
6220 _cupsBufferRelease((char *)buffer
);
6221 return (IPP_STATE_ERROR
);
6227 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6233 * An unknown value might some new value that a
6234 * vendor has come up with. It consists of a
6235 * 2-byte length and the bytes in the unknown
6239 n
= value
->unknown
.length
;
6241 if (n
> (IPP_BUF_SIZE
- 2))
6243 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6245 _cupsBufferRelease((char *)buffer
);
6246 return (IPP_STATE_ERROR
);
6249 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6251 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6253 DEBUG_puts("1ippWriteIO: Could not write IPP "
6255 _cupsBufferRelease((char *)buffer
);
6256 return (IPP_STATE_ERROR
);
6262 /* Length of unknown value */
6263 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6264 *bufptr
++ = (ipp_uchar_t
)n
;
6269 memcpy(bufptr
, value
->unknown
.data
, (size_t)n
);
6277 * Write the data out...
6280 if (bufptr
> buffer
)
6282 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6284 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6285 _cupsBufferRelease((char *)buffer
);
6286 return (IPP_STATE_ERROR
);
6289 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6290 (int)(bufptr
- buffer
)));
6294 * If blocking is disabled and we aren't at the end of the attribute
6295 * list, stop here...
6298 if (!blocking
&& ipp
->current
)
6302 if (ipp
->current
== NULL
)
6305 * Done with all of the attributes; add the end-of-attributes
6306 * tag or end-collection attribute...
6311 buffer
[0] = IPP_TAG_END
;
6316 buffer
[0] = IPP_TAG_END_COLLECTION
;
6317 buffer
[1] = 0; /* empty name */
6319 buffer
[3] = 0; /* empty value */
6324 if ((*cb
)(dst
, buffer
, (size_t)n
) < 0)
6326 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6327 _cupsBufferRelease((char *)buffer
);
6328 return (IPP_STATE_ERROR
);
6331 ipp
->state
= IPP_STATE_DATA
;
6335 case IPP_STATE_DATA
:
6339 break; /* anti-compiler-warning-code */
6342 _cupsBufferRelease((char *)buffer
);
6344 return (ipp
->state
);
6349 * 'ipp_add_attr()' - Add a new attribute to the message.
6352 static ipp_attribute_t
* /* O - New attribute */
6353 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6354 const char *name
, /* I - Attribute name or NULL */
6355 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6356 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6357 int num_values
) /* I - Number of values */
6359 int alloc_values
; /* Number of values to allocate */
6360 ipp_attribute_t
*attr
; /* New attribute */
6363 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
));
6366 * Range check input...
6369 if (!ipp
|| num_values
< 0)
6373 * Allocate memory, rounding the allocation up as needed...
6376 if (num_values
<= 1)
6379 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6381 attr
= calloc(sizeof(ipp_attribute_t
) +
6382 (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6387 * Initialize attribute...
6391 attr
->name
= _cupsStrAlloc(name
);
6393 attr
->group_tag
= group_tag
;
6394 attr
->value_tag
= value_tag
;
6395 attr
->num_values
= num_values
;
6398 * Add it to the end of the linked list...
6402 ipp
->last
->next
= attr
;
6406 ipp
->prev
= ipp
->last
;
6407 ipp
->last
= ipp
->current
= attr
;
6410 DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr
));
6417 * 'ipp_free_values()' - Free attribute values.
6421 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6422 int element
,/* I - First value to free */
6423 int count
) /* I - Number of values to free */
6425 int i
; /* Looping var */
6426 _ipp_value_t
*value
; /* Current value */
6429 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", (void *)attr
, element
, count
));
6431 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6434 * Free values as needed...
6437 switch (attr
->value_tag
)
6439 case IPP_TAG_TEXTLANG
:
6440 case IPP_TAG_NAMELANG
:
6441 if (element
== 0 && count
== attr
->num_values
&&
6442 attr
->values
[0].string
.language
)
6444 _cupsStrFree(attr
->values
[0].string
.language
);
6445 attr
->values
[0].string
.language
= NULL
;
6447 /* Fall through to other string values */
6451 case IPP_TAG_RESERVED_STRING
:
6452 case IPP_TAG_KEYWORD
:
6454 case IPP_TAG_URISCHEME
:
6455 case IPP_TAG_CHARSET
:
6456 case IPP_TAG_LANGUAGE
:
6457 case IPP_TAG_MIMETYPE
:
6458 for (i
= count
, value
= attr
->values
+ element
;
6462 _cupsStrFree(value
->string
.text
);
6463 value
->string
.text
= NULL
;
6467 case IPP_TAG_DEFAULT
:
6468 case IPP_TAG_UNKNOWN
:
6469 case IPP_TAG_NOVALUE
:
6470 case IPP_TAG_NOTSETTABLE
:
6471 case IPP_TAG_DELETEATTR
:
6472 case IPP_TAG_ADMINDEFINE
:
6473 case IPP_TAG_INTEGER
:
6475 case IPP_TAG_BOOLEAN
:
6477 case IPP_TAG_RESOLUTION
:
6478 case IPP_TAG_RANGE
:
6481 case IPP_TAG_BEGIN_COLLECTION
:
6482 for (i
= count
, value
= attr
->values
+ element
;
6486 ippDelete(value
->collection
);
6487 value
->collection
= NULL
;
6491 case IPP_TAG_STRING
:
6493 for (i
= count
, value
= attr
->values
+ element
;
6497 if (value
->unknown
.data
)
6499 free(value
->unknown
.data
);
6500 value
->unknown
.data
= NULL
;
6508 * If we are not freeing values from the end, move the remaining values up...
6511 if ((element
+ count
) < attr
->num_values
)
6512 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6513 (size_t)(attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6515 attr
->num_values
-= count
;
6520 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6522 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6523 * to "ll-cc", "ll-region", and "charset-number", respectively.
6526 static char * /* O - Language code string */
6527 ipp_get_code(const char *value
, /* I - Locale/charset string */
6528 char *buffer
, /* I - String buffer */
6529 size_t bufsize
) /* I - Size of string buffer */
6531 char *bufptr
, /* Pointer into buffer */
6532 *bufend
; /* End of buffer */
6536 * Convert values to lowercase and change _ to - as needed...
6539 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6540 *value
&& bufptr
< bufend
;
6545 *bufptr
++ = (char)_cups_tolower(*value
);
6550 * Return the converted string...
6558 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6560 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6561 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6564 static char * /* O - Language code string */
6565 ipp_lang_code(const char *locale
, /* I - Locale string */
6566 char *buffer
, /* I - String buffer */
6567 size_t bufsize
) /* I - Size of string buffer */
6570 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6573 if (!_cups_strcasecmp(locale
, "c"))
6575 strlcpy(buffer
, "en", bufsize
);
6579 return (ipp_get_code(locale
, buffer
, bufsize
));
6584 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6587 static size_t /* O - Size of IPP message */
6588 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6589 int collection
) /* I - 1 if a collection, 0 otherwise */
6591 int i
; /* Looping var */
6592 size_t bytes
; /* Number of bytes */
6593 ipp_attribute_t
*attr
; /* Current attribute */
6594 ipp_tag_t group
; /* Current group */
6595 _ipp_value_t
*value
; /* Current value */
6598 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp
, collection
));
6602 DEBUG_puts("4ipp_length: Returning 0 bytes");
6607 * Start with 8 bytes for the IPP message header...
6610 bytes
= collection
? 0 : 8;
6613 * Then add the lengths of each attribute...
6616 group
= IPP_TAG_ZERO
;
6618 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6620 if (attr
->group_tag
!= group
&& !collection
)
6622 group
= attr
->group_tag
;
6623 if (group
== IPP_TAG_ZERO
)
6626 bytes
++; /* Group tag */
6632 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6633 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6635 if ((attr
->value_tag
& ~IPP_TAG_CUPS_CONST
) < IPP_TAG_EXTENSION
)
6636 bytes
+= (size_t)attr
->num_values
;/* Value tag for each value */
6638 bytes
+= (size_t)(5 * attr
->num_values
);
6639 /* Value tag for each value */
6640 bytes
+= (size_t)(2 * attr
->num_values
);
6642 bytes
+= strlen(attr
->name
); /* Name */
6643 bytes
+= (size_t)(2 * attr
->num_values
);
6647 bytes
+= 5; /* Add membername overhead */
6649 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6651 case IPP_TAG_UNSUPPORTED_VALUE
:
6652 case IPP_TAG_DEFAULT
:
6653 case IPP_TAG_UNKNOWN
:
6654 case IPP_TAG_NOVALUE
:
6655 case IPP_TAG_NOTSETTABLE
:
6656 case IPP_TAG_DELETEATTR
:
6657 case IPP_TAG_ADMINDEFINE
:
6660 case IPP_TAG_INTEGER
:
6662 bytes
+= (size_t)(4 * attr
->num_values
);
6665 case IPP_TAG_BOOLEAN
:
6666 bytes
+= (size_t)attr
->num_values
;
6671 case IPP_TAG_KEYWORD
:
6673 case IPP_TAG_URISCHEME
:
6674 case IPP_TAG_CHARSET
:
6675 case IPP_TAG_LANGUAGE
:
6676 case IPP_TAG_MIMETYPE
:
6677 for (i
= 0, value
= attr
->values
;
6678 i
< attr
->num_values
;
6680 if (value
->string
.text
)
6681 bytes
+= strlen(value
->string
.text
);
6685 bytes
+= (size_t)(11 * attr
->num_values
);
6688 case IPP_TAG_RESOLUTION
:
6689 bytes
+= (size_t)(9 * attr
->num_values
);
6692 case IPP_TAG_RANGE
:
6693 bytes
+= (size_t)(8 * attr
->num_values
);
6696 case IPP_TAG_TEXTLANG
:
6697 case IPP_TAG_NAMELANG
:
6698 bytes
+= (size_t)(4 * attr
->num_values
);
6699 /* Charset + text length */
6701 for (i
= 0, value
= attr
->values
;
6702 i
< attr
->num_values
;
6705 if (value
->string
.language
)
6706 bytes
+= strlen(value
->string
.language
);
6708 if (value
->string
.text
)
6709 bytes
+= strlen(value
->string
.text
);
6713 case IPP_TAG_BEGIN_COLLECTION
:
6714 for (i
= 0, value
= attr
->values
;
6715 i
< attr
->num_values
;
6717 bytes
+= ipp_length(value
->collection
, 1);
6721 for (i
= 0, value
= attr
->values
;
6722 i
< attr
->num_values
;
6724 bytes
+= (size_t)value
->unknown
.length
;
6730 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6731 * for the "end of collection" tag and return...
6739 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6746 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6749 static ssize_t
/* O - Number of bytes read */
6750 ipp_read_http(http_t
*http
, /* I - Client connection */
6751 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6752 size_t length
) /* I - Total length */
6754 ssize_t tbytes
, /* Total bytes read */
6755 bytes
; /* Bytes read this pass */
6758 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http
, (void *)buffer
, (int)length
));
6761 * Loop until all bytes are read...
6764 for (tbytes
= 0, bytes
= 0;
6765 tbytes
< (int)length
;
6766 tbytes
+= bytes
, buffer
+= bytes
)
6768 DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT
", http->state=%d", CUPS_LLCAST tbytes
, http
->state
));
6770 if (http
->state
== HTTP_STATE_WAITING
)
6773 if (http
->used
== 0 && !http
->blocking
)
6776 * Wait up to 10 seconds for more data on non-blocking sockets...
6779 if (!httpWait(http
, 10000))
6789 else if (http
->used
== 0 && http
->timeout_value
> 0)
6792 * Wait up to timeout seconds for more data on blocking sockets...
6795 if (!httpWait(http
, (int)(1000 * http
->timeout_value
)))
6806 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- (size_t)tbytes
)) < 0)
6811 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6817 else if (bytes
== 0)
6822 * Return the number of bytes read...
6825 if (tbytes
== 0 && bytes
< 0)
6828 DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST tbytes
));
6835 * 'ipp_read_file()' - Read IPP data from a file.
6838 static ssize_t
/* O - Number of bytes read */
6839 ipp_read_file(int *fd
, /* I - File descriptor */
6840 ipp_uchar_t
*buffer
, /* O - Read buffer */
6841 size_t length
) /* I - Number of bytes to read */
6844 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6846 return (read(*fd
, buffer
, length
));
6852 * 'ipp_set_error()' - Set a formatted, localized error string.
6856 ipp_set_error(ipp_status_t status
, /* I - Status code */
6857 const char *format
, /* I - Printf-style error string */
6858 ...) /* I - Additional arguments as needed */
6860 va_list ap
; /* Pointer to additional args */
6861 char buffer
[2048]; /* Message buffer */
6862 cups_lang_t
*lang
= cupsLangDefault();
6863 /* Current language */
6866 va_start(ap
, format
);
6867 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6870 _cupsSetError(status
, buffer
, 0);
6875 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6879 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6880 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6881 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6882 int element
) /* I - Value number (0-based) */
6884 ipp_attribute_t
*temp
, /* New attribute pointer */
6885 *current
, /* Current attribute in list */
6886 *prev
; /* Previous attribute in list */
6887 int alloc_values
; /* Allocated values */
6891 * If we are setting an existing value element, return it...
6896 if (temp
->num_values
<= 1)
6899 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6900 ~(IPP_MAX_VALUES
- 1);
6902 if (element
< alloc_values
)
6904 if (element
>= temp
->num_values
)
6905 temp
->num_values
= element
+ 1;
6907 return (temp
->values
+ element
);
6911 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6912 * values when num_values > 1.
6915 if (alloc_values
< IPP_MAX_VALUES
)
6916 alloc_values
= IPP_MAX_VALUES
;
6918 alloc_values
+= IPP_MAX_VALUES
;
6920 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6924 * Reallocate memory...
6927 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) + (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6929 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6930 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6935 * Zero the new memory...
6938 memset(temp
->values
+ temp
->num_values
, 0, (size_t)(alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6943 * Reset pointers in the list...
6946 if (ipp
->current
== *attr
&& ipp
->prev
)
6949 * Use current "previous" pointer...
6957 * Find this attribute in the linked list...
6960 for (prev
= NULL
, current
= ipp
->attrs
;
6961 current
&& current
!= *attr
;
6962 prev
= current
, current
= current
->next
);
6967 * This is a serious error!
6971 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
6972 _("IPP attribute is not a member of the message."), 1);
6973 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
6983 ipp
->current
= temp
;
6986 if (ipp
->last
== *attr
)
6993 * Return the value element...
6996 if (element
>= temp
->num_values
)
6997 temp
->num_values
= element
+ 1;
6999 return (temp
->values
+ element
);
7004 * 'ipp_write_file()' - Write IPP data to a file.
7007 static ssize_t
/* O - Number of bytes written */
7008 ipp_write_file(int *fd
, /* I - File descriptor */
7009 ipp_uchar_t
*buffer
, /* I - Data to write */
7010 size_t length
) /* I - Number of bytes to write */
7013 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
7015 return (write(*fd
, buffer
, length
));