2 * Internet Printing Protocol functions for CUPS.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
13 * This file is subject to the Apple OS-Developed Software exception.
17 * Include necessary headers...
20 #include "cups-private.h"
31 static ipp_attribute_t
*ipp_add_attr(ipp_t
*ipp
, const char *name
,
32 ipp_tag_t group_tag
, ipp_tag_t value_tag
,
34 static void ipp_free_values(ipp_attribute_t
*attr
, int element
,
36 static char *ipp_get_code(const char *locale
, char *buffer
,
38 __attribute__((nonnull(1,2)));
39 static char *ipp_lang_code(const char *locale
, char *buffer
,
41 __attribute__((nonnull(1,2)));
42 static size_t ipp_length(ipp_t
*ipp
, int collection
);
43 static ssize_t
ipp_read_http(http_t
*http
, ipp_uchar_t
*buffer
,
45 static ssize_t
ipp_read_file(int *fd
, ipp_uchar_t
*buffer
,
47 static void ipp_set_error(ipp_status_t status
, const char *format
,
49 static _ipp_value_t
*ipp_set_value(ipp_t
*ipp
, ipp_attribute_t
**attr
,
51 static ssize_t
ipp_write_file(int *fd
, ipp_uchar_t
*buffer
,
56 * '_cupsBufferGet()' - Get a read/write buffer.
59 char * /* O - Buffer */
60 _cupsBufferGet(size_t size
) /* I - Size required */
62 _cups_buffer_t
*buffer
; /* Current buffer */
63 _cups_globals_t
*cg
= _cupsGlobals();
67 for (buffer
= cg
->cups_buffers
; buffer
; buffer
= buffer
->next
)
68 if (!buffer
->used
&& buffer
->size
>= size
)
73 if ((buffer
= malloc(sizeof(_cups_buffer_t
) + size
- 1)) == NULL
)
76 buffer
->next
= cg
->cups_buffers
;
78 cg
->cups_buffers
= buffer
;
88 * '_cupsBufferRelease()' - Release a read/write buffer.
92 _cupsBufferRelease(char *b
) /* I - Buffer to release */
94 _cups_buffer_t
*buffer
; /* Buffer */
98 * Mark this buffer as unused...
101 buffer
= (_cups_buffer_t
*)(b
- offsetof(_cups_buffer_t
, d
));
107 * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
109 * The @code ipp@ parameter refers to an IPP message previously created using
110 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
112 * The @code group@ parameter specifies the IPP attribute group tag: none
113 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
114 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
115 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
116 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
119 ipp_attribute_t
* /* O - New attribute */
120 ippAddBoolean(ipp_t
*ipp
, /* I - IPP message */
121 ipp_tag_t group
, /* I - IPP group */
122 const char *name
, /* I - Name of attribute */
123 char value
) /* I - Value of attribute */
125 ipp_attribute_t
*attr
; /* New attribute */
128 DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)", (void *)ipp
, group
, ippTagString(group
), name
, value
));
131 * Range check input...
134 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
135 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
139 * Create the attribute...
142 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, 1)) == NULL
)
145 attr
->values
[0].boolean
= value
;
152 * 'ippAddBooleans()' - Add an array of boolean values.
154 * The @code ipp@ parameter refers to an IPP message previously created using
155 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
157 * The @code group@ parameter specifies the IPP attribute group tag: none
158 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
159 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
160 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
161 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
164 ipp_attribute_t
* /* O - New attribute */
165 ippAddBooleans(ipp_t
*ipp
, /* I - IPP message */
166 ipp_tag_t group
, /* I - IPP group */
167 const char *name
, /* I - Name of attribute */
168 int num_values
, /* I - Number of values */
169 const char *values
) /* I - Values */
171 int i
; /* Looping var */
172 ipp_attribute_t
*attr
; /* New attribute */
173 _ipp_value_t
*value
; /* Current value */
176 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
));
179 * Range check input...
182 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
183 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
188 * Create the attribute...
191 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, num_values
)) == NULL
)
196 for (i
= num_values
, value
= attr
->values
;
199 value
->boolean
= *values
++;
207 * 'ippAddCollection()' - Add a collection value.
209 * The @code ipp@ parameter refers to an IPP message previously created using
210 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
212 * The @code group@ parameter specifies the IPP attribute group tag: none
213 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
214 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
215 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
216 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
218 * @since CUPS 1.1.19/macOS 10.3@
221 ipp_attribute_t
* /* O - New attribute */
222 ippAddCollection(ipp_t
*ipp
, /* I - IPP message */
223 ipp_tag_t group
, /* I - IPP group */
224 const char *name
, /* I - Name of attribute */
225 ipp_t
*value
) /* I - Value */
227 ipp_attribute_t
*attr
; /* New attribute */
230 DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
233 * Range check input...
236 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
237 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
241 * Create the attribute...
244 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
, 1)) == NULL
)
247 attr
->values
[0].collection
= value
;
257 * 'ippAddCollections()' - Add an array of collection values.
259 * The @code ipp@ parameter refers to an IPP message previously created using
260 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
262 * The @code group@ parameter specifies the IPP attribute group tag: none
263 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
264 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
265 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
266 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
268 * @since CUPS 1.1.19/macOS 10.3@
271 ipp_attribute_t
* /* O - New attribute */
273 ipp_t
*ipp
, /* I - IPP message */
274 ipp_tag_t group
, /* I - IPP group */
275 const char *name
, /* I - Name of attribute */
276 int num_values
, /* I - Number of values */
277 const ipp_t
**values
) /* I - Values */
279 int i
; /* Looping var */
280 ipp_attribute_t
*attr
; /* New attribute */
281 _ipp_value_t
*value
; /* Current value */
284 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
));
287 * Range check input...
290 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
291 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
296 * Create the attribute...
299 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
,
300 num_values
)) == NULL
)
305 for (i
= num_values
, value
= attr
->values
;
309 value
->collection
= (ipp_t
*)*values
++;
310 value
->collection
->use
++;
319 * 'ippAddDate()' - Add a dateTime attribute to an IPP message.
321 * The @code ipp@ parameter refers to an IPP message previously created using
322 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
324 * The @code group@ parameter specifies the IPP attribute group tag: none
325 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
326 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
327 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
328 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
331 ipp_attribute_t
* /* O - New attribute */
332 ippAddDate(ipp_t
*ipp
, /* I - IPP message */
333 ipp_tag_t group
, /* I - IPP group */
334 const char *name
, /* I - Name of attribute */
335 const ipp_uchar_t
*value
) /* I - Value */
337 ipp_attribute_t
*attr
; /* New attribute */
340 DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
343 * Range check input...
346 if (!ipp
|| !name
|| !value
|| group
< IPP_TAG_ZERO
||
347 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
351 * Create the attribute...
354 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_DATE
, 1)) == NULL
)
357 memcpy(attr
->values
[0].date
, value
, 11);
364 * 'ippAddInteger()' - Add a integer attribute to an IPP message.
366 * The @code ipp@ parameter refers to an IPP message previously created using
367 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
369 * The @code group@ parameter specifies the IPP attribute group tag: none
370 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
371 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
372 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
373 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
375 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
376 * (@code IPP_TAG_INTEGER@).
379 ipp_attribute_t
* /* O - New attribute */
380 ippAddInteger(ipp_t
*ipp
, /* I - IPP message */
381 ipp_tag_t group
, /* I - IPP group */
382 ipp_tag_t value_tag
, /* I - Type of attribute */
383 const char *name
, /* I - Name of attribute */
384 int value
) /* I - Value of attribute */
386 ipp_attribute_t
*attr
; /* New attribute */
389 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
));
391 value_tag
&= IPP_TAG_CUPS_MASK
;
394 * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
398 if (value_tag
>= IPP_TAG_UNSUPPORTED_VALUE
&& value_tag
<= IPP_TAG_ADMINDEFINE
)
399 return (ippAddOutOfBand(ipp
, group
, value_tag
, name
));
402 * Range check input...
406 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
407 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
408 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
))
411 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
412 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
417 * Create the attribute...
420 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
423 attr
->values
[0].integer
= value
;
430 * 'ippAddIntegers()' - Add an array of integer values.
432 * The @code ipp@ parameter refers to an IPP message previously created using
433 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
435 * The @code group@ parameter specifies the IPP attribute group tag: none
436 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
437 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
438 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
439 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
441 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
442 * (@code IPP_TAG_INTEGER@).
445 ipp_attribute_t
* /* O - New attribute */
446 ippAddIntegers(ipp_t
*ipp
, /* I - IPP message */
447 ipp_tag_t group
, /* I - IPP group */
448 ipp_tag_t value_tag
, /* I - Type of attribute */
449 const char *name
, /* I - Name of attribute */
450 int num_values
, /* I - Number of values */
451 const int *values
) /* I - Values */
453 int i
; /* Looping var */
454 ipp_attribute_t
*attr
; /* New attribute */
455 _ipp_value_t
*value
; /* Current value */
458 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
));
460 value_tag
&= IPP_TAG_CUPS_MASK
;
463 * Range check input...
467 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
468 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
469 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
) ||
473 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
474 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
480 * Create the attribute...
483 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
488 for (i
= num_values
, value
= attr
->values
;
491 value
->integer
= *values
++;
499 * 'ippAddOctetString()' - Add an octetString value to an IPP message.
501 * The @code ipp@ parameter refers to an IPP message previously created using
502 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
504 * The @code group@ parameter specifies the IPP attribute group tag: none
505 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
506 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
507 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
508 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
510 * @since CUPS 1.2/macOS 10.5@
513 ipp_attribute_t
* /* O - New attribute */
514 ippAddOctetString(ipp_t
*ipp
, /* I - IPP message */
515 ipp_tag_t group
, /* I - IPP group */
516 const char *name
, /* I - Name of attribute */
517 const void *data
, /* I - octetString data */
518 int datalen
) /* I - Length of data in bytes */
520 ipp_attribute_t
*attr
; /* New attribute */
523 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
524 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
525 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
528 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_STRING
, 1)) == NULL
)
532 * Initialize the attribute data...
535 attr
->values
[0].unknown
.length
= datalen
;
539 if ((attr
->values
[0].unknown
.data
= malloc((size_t)datalen
)) == NULL
)
541 ippDeleteAttribute(ipp
, attr
);
545 memcpy(attr
->values
[0].unknown
.data
, data
, (size_t)datalen
);
549 * Return the new attribute...
557 * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
559 * The @code ipp@ parameter refers to an IPP message previously created using
560 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
562 * The @code group@ parameter specifies the IPP attribute group tag: none
563 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
564 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
565 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
566 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
568 * Supported out-of-band values include unsupported-value
569 * (@code IPP_TAG_UNSUPPORTED_VALUE@), default (@code IPP_TAG_DEFAULT@), unknown
570 * (@code IPP_TAG_UNKNOWN@), no-value (@code IPP_TAG_NOVALUE@), not-settable
571 * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
572 * admin-define (@code IPP_TAG_ADMINDEFINE@).
574 * @since CUPS 1.6/macOS 10.8@
577 ipp_attribute_t
* /* O - New attribute */
578 ippAddOutOfBand(ipp_t
*ipp
, /* I - IPP message */
579 ipp_tag_t group
, /* I - IPP group */
580 ipp_tag_t value_tag
, /* I - Type of attribute */
581 const char *name
) /* I - Name of attribute */
583 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
));
585 value_tag
&= IPP_TAG_CUPS_MASK
;
588 * Range check input...
591 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
592 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
593 (value_tag
!= IPP_TAG_UNSUPPORTED_VALUE
&&
594 value_tag
!= IPP_TAG_DEFAULT
&&
595 value_tag
!= IPP_TAG_UNKNOWN
&&
596 value_tag
!= IPP_TAG_NOVALUE
&&
597 value_tag
!= IPP_TAG_NOTSETTABLE
&&
598 value_tag
!= IPP_TAG_DELETEATTR
&&
599 value_tag
!= IPP_TAG_ADMINDEFINE
))
603 * Create the attribute...
606 return (ipp_add_attr(ipp
, name
, group
, value_tag
, 1));
611 * 'ippAddRange()' - Add a range of values to an IPP message.
613 * The @code ipp@ parameter refers to an IPP message previously created using
614 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
616 * The @code group@ parameter specifies the IPP attribute group tag: none
617 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
618 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
619 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
620 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
622 * The @code lower@ parameter must be less than or equal to the @code upper@ parameter.
625 ipp_attribute_t
* /* O - New attribute */
626 ippAddRange(ipp_t
*ipp
, /* I - IPP message */
627 ipp_tag_t group
, /* I - IPP group */
628 const char *name
, /* I - Name of attribute */
629 int lower
, /* I - Lower value */
630 int upper
) /* I - Upper value */
632 ipp_attribute_t
*attr
; /* New attribute */
635 DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, upper=%d)", (void *)ipp
, group
, ippTagString(group
), name
, lower
, upper
));
638 * Range check input...
641 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
642 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
646 * Create the attribute...
649 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, 1)) == NULL
)
652 attr
->values
[0].range
.lower
= lower
;
653 attr
->values
[0].range
.upper
= upper
;
660 * 'ippAddRanges()' - Add ranges of values to an IPP message.
662 * The @code ipp@ parameter refers to an IPP message previously created using
663 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
665 * The @code group@ parameter specifies the IPP attribute group tag: none
666 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
667 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
668 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
669 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
672 ipp_attribute_t
* /* O - New attribute */
673 ippAddRanges(ipp_t
*ipp
, /* I - IPP message */
674 ipp_tag_t group
, /* I - IPP group */
675 const char *name
, /* I - Name of attribute */
676 int num_values
, /* I - Number of values */
677 const int *lower
, /* I - Lower values */
678 const int *upper
) /* I - Upper values */
680 int i
; /* Looping var */
681 ipp_attribute_t
*attr
; /* New attribute */
682 _ipp_value_t
*value
; /* Current value */
685 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
));
688 * Range check input...
691 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
692 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
697 * Create the attribute...
700 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, num_values
)) == NULL
)
705 for (i
= num_values
, value
= attr
->values
;
709 value
->range
.lower
= *lower
++;
710 value
->range
.upper
= *upper
++;
719 * 'ippAddResolution()' - Add a resolution value to an IPP message.
721 * The @code ipp@ parameter refers to an IPP message previously created using
722 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
724 * The @code group@ parameter specifies the IPP attribute group tag: none
725 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
726 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
727 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
728 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
731 ipp_attribute_t
* /* O - New attribute */
732 ippAddResolution(ipp_t
*ipp
, /* I - IPP message */
733 ipp_tag_t group
, /* I - IPP group */
734 const char *name
, /* I - Name of attribute */
735 ipp_res_t units
, /* I - Units for resolution */
736 int xres
, /* I - X resolution */
737 int yres
) /* I - Y resolution */
739 ipp_attribute_t
*attr
; /* New attribute */
742 DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", units=%d, xres=%d, yres=%d)", (void *)ipp
, group
,
743 ippTagString(group
), name
, units
, xres
, yres
));
746 * Range check input...
749 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
750 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
751 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
||
752 xres
< 0 || yres
< 0)
756 * Create the attribute...
759 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, 1)) == NULL
)
762 attr
->values
[0].resolution
.xres
= xres
;
763 attr
->values
[0].resolution
.yres
= yres
;
764 attr
->values
[0].resolution
.units
= units
;
771 * 'ippAddResolutions()' - Add resolution values to an IPP message.
773 * The @code ipp@ parameter refers to an IPP message previously created using
774 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
776 * The @code group@ parameter specifies the IPP attribute group tag: none
777 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
778 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
779 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
780 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
783 ipp_attribute_t
* /* O - New attribute */
784 ippAddResolutions(ipp_t
*ipp
, /* I - IPP message */
785 ipp_tag_t group
, /* I - IPP group */
786 const char *name
, /* I - Name of attribute */
787 int num_values
,/* I - Number of values */
788 ipp_res_t units
, /* I - Units for resolution */
789 const int *xres
, /* I - X resolutions */
790 const int *yres
) /* I - Y resolutions */
792 int i
; /* Looping var */
793 ipp_attribute_t
*attr
; /* New attribute */
794 _ipp_value_t
*value
; /* Current value */
797 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
));
800 * Range check input...
803 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
804 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
806 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
)
810 * Create the attribute...
813 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, num_values
)) == NULL
)
818 for (i
= num_values
, value
= attr
->values
;
822 value
->resolution
.xres
= *xres
++;
823 value
->resolution
.yres
= *yres
++;
824 value
->resolution
.units
= units
;
833 * 'ippAddSeparator()' - Add a group separator to an IPP message.
835 * The @code ipp@ parameter refers to an IPP message previously created using
836 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
839 ipp_attribute_t
* /* O - New attribute */
840 ippAddSeparator(ipp_t
*ipp
) /* I - IPP message */
842 DEBUG_printf(("ippAddSeparator(ipp=%p)", (void *)ipp
));
845 * Range check input...
852 * Create the attribute...
855 return (ipp_add_attr(ipp
, NULL
, IPP_TAG_ZERO
, IPP_TAG_ZERO
, 0));
860 * 'ippAddString()' - Add a language-encoded string to an IPP message.
862 * The @code ipp@ parameter refers to an IPP message previously created using
863 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
865 * The @code group@ parameter specifies the IPP attribute group tag: none
866 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
867 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
868 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
869 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
871 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
872 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
873 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
874 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
875 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
876 * (@code IPP_TAG_URISCHEME@).
878 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
879 * textWithLanguage string values and must be @code NULL@ for all other string values.
882 ipp_attribute_t
* /* O - New attribute */
883 ippAddString(ipp_t
*ipp
, /* I - IPP message */
884 ipp_tag_t group
, /* I - IPP group */
885 ipp_tag_t value_tag
, /* I - Type of attribute */
886 const char *name
, /* I - Name of attribute */
887 const char *language
, /* I - Language code */
888 const char *value
) /* I - Value */
890 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
891 ipp_attribute_t
*attr
; /* New attribute */
892 char code
[IPP_MAX_LANGUAGE
];
893 /* Charset/language code buffer */
896 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
));
899 * Range check input...
902 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
905 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
906 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
907 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
908 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
)
911 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
912 != (language
!= NULL
))
915 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
916 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
921 * See if we need to map charset, language, or locale values...
924 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
925 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
926 value_tag
= temp_tag
; /* Don't do a fast copy */
927 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
) &&
928 strcmp(value
, ipp_get_code(value
, code
, sizeof(code
))))
929 value_tag
= temp_tag
; /* Don't do a fast copy */
930 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
) &&
931 strcmp(value
, ipp_lang_code(value
, code
, sizeof(code
))))
932 value_tag
= temp_tag
; /* Don't do a fast copy */
935 * Create the attribute...
938 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
942 * Initialize the attribute data...
945 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
947 attr
->values
[0].string
.language
= (char *)language
;
948 attr
->values
[0].string
.text
= (char *)value
;
953 attr
->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
958 if (value_tag
== IPP_TAG_CHARSET
)
959 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_get_code(value
, code
,
961 else if (value_tag
== IPP_TAG_LANGUAGE
)
962 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_lang_code(value
, code
,
965 attr
->values
[0].string
.text
= _cupsStrAlloc(value
);
974 * 'ippAddStringf()' - Add a formatted string to an IPP message.
976 * The @code ipp@ parameter refers to an IPP message previously created using
977 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
979 * The @code group@ parameter specifies the IPP attribute group tag: none
980 * (@code IPP_TAG_ZERO@, for member attributes), document
981 * (@code IPP_TAG_DOCUMENT@), event notification
982 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
983 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
984 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
986 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
987 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
988 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
989 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
990 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
991 * (@code IPP_TAG_URISCHEME@).
993 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
994 * and textWithLanguage string values and must be @code NULL@ for all other
997 * The @code format@ parameter uses formatting characters compatible with the
998 * printf family of standard functions. Additional arguments follow it as
999 * needed. The formatted string is truncated as needed to the maximum length of
1000 * the corresponding value type.
1002 * @since CUPS 1.7/macOS 10.9@
1005 ipp_attribute_t
* /* O - New attribute */
1006 ippAddStringf(ipp_t
*ipp
, /* I - IPP message */
1007 ipp_tag_t group
, /* I - IPP group */
1008 ipp_tag_t value_tag
, /* I - Type of attribute */
1009 const char *name
, /* I - Name of attribute */
1010 const char *language
, /* I - Language code (@code NULL@ for default) */
1011 const char *format
, /* I - Printf-style format string */
1012 ...) /* I - Additional arguments as needed */
1014 ipp_attribute_t
*attr
; /* New attribute */
1015 va_list ap
; /* Argument pointer */
1018 va_start(ap
, format
);
1019 attr
= ippAddStringfv(ipp
, group
, value_tag
, name
, language
, format
, ap
);
1027 * 'ippAddStringfv()' - Add a formatted string to an IPP message.
1029 * The @code ipp@ parameter refers to an IPP message previously created using
1030 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1032 * The @code group@ parameter specifies the IPP attribute group tag: none
1033 * (@code IPP_TAG_ZERO@, for member attributes), document
1034 * (@code IPP_TAG_DOCUMENT@), event notification
1035 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1036 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1037 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1039 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1040 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1041 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1042 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1043 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1044 * (@code IPP_TAG_URISCHEME@).
1046 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1047 * and textWithLanguage string values and must be @code NULL@ for all other
1050 * The @code format@ parameter uses formatting characters compatible with the
1051 * printf family of standard functions. Additional arguments are passed in the
1052 * stdarg pointer @code ap@. The formatted string is truncated as needed to the
1053 * maximum length of the corresponding value type.
1055 * @since CUPS 1.7/macOS 10.9@
1058 ipp_attribute_t
* /* O - New attribute */
1059 ippAddStringfv(ipp_t
*ipp
, /* I - IPP message */
1060 ipp_tag_t group
, /* I - IPP group */
1061 ipp_tag_t value_tag
, /* I - Type of attribute */
1062 const char *name
, /* I - Name of attribute */
1063 const char *language
, /* I - Language code (@code NULL@ for default) */
1064 const char *format
, /* I - Printf-style format string */
1065 va_list ap
) /* I - Additional arguments */
1067 char buffer
[IPP_MAX_TEXT
+ 4];
1068 /* Formatted text string */
1069 ssize_t bytes
, /* Length of formatted value */
1070 max_bytes
; /* Maximum number of bytes for value */
1074 * Range check input...
1077 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1078 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1079 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
1080 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
1084 if ((value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_NAMELANG
)
1085 != (language
!= NULL
))
1089 * Format the string...
1092 if (!strcmp(format
, "%s"))
1095 * Optimize the simple case...
1098 const char *s
= va_arg(ap
, char *);
1103 bytes
= (ssize_t
)strlen(s
);
1104 strlcpy(buffer
, s
, sizeof(buffer
));
1109 * Do a full formatting of the message...
1112 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
1117 * Limit the length of the string...
1124 case IPP_TAG_TEXTLANG
:
1125 max_bytes
= IPP_MAX_TEXT
;
1129 case IPP_TAG_NAMELANG
:
1130 max_bytes
= IPP_MAX_NAME
;
1133 case IPP_TAG_CHARSET
:
1134 max_bytes
= IPP_MAX_CHARSET
;
1137 case IPP_TAG_KEYWORD
:
1138 max_bytes
= IPP_MAX_KEYWORD
;
1141 case IPP_TAG_LANGUAGE
:
1142 max_bytes
= IPP_MAX_LANGUAGE
;
1145 case IPP_TAG_MIMETYPE
:
1146 max_bytes
= IPP_MAX_MIMETYPE
;
1150 max_bytes
= IPP_MAX_URI
;
1153 case IPP_TAG_URISCHEME
:
1154 max_bytes
= IPP_MAX_URISCHEME
;
1158 if (bytes
>= max_bytes
)
1160 char *bufmax
, /* Buffer at max_bytes */
1161 *bufptr
; /* Pointer into buffer */
1163 bufptr
= buffer
+ strlen(buffer
) - 1;
1164 bufmax
= buffer
+ max_bytes
- 1;
1166 while (bufptr
> bufmax
)
1170 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
1181 * Add the formatted string and return...
1184 return (ippAddString(ipp
, group
, value_tag
, name
, language
, buffer
));
1189 * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
1191 * The @code ipp@ parameter refers to an IPP message previously created using
1192 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1194 * The @code group@ parameter specifies the IPP attribute group tag: none
1195 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
1196 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
1197 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
1198 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1200 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1201 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1202 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1203 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1204 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1205 * (@code IPP_TAG_URISCHEME@).
1207 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1208 * textWithLanguage string values and must be @code NULL@ for all other string values.
1211 ipp_attribute_t
* /* O - New attribute */
1213 ipp_t
*ipp
, /* I - IPP message */
1214 ipp_tag_t group
, /* I - IPP group */
1215 ipp_tag_t value_tag
, /* I - Type of attribute */
1216 const char *name
, /* I - Name of attribute */
1217 int num_values
, /* I - Number of values */
1218 const char *language
, /* I - Language code (@code NULL@ for default) */
1219 const char * const *values
) /* I - Values */
1221 int i
; /* Looping var */
1222 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1223 ipp_attribute_t
*attr
; /* New attribute */
1224 _ipp_value_t
*value
; /* Current value */
1225 char code
[32]; /* Language/charset value buffer */
1228 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
));
1231 * Range check input...
1234 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
1237 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1238 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1239 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1240 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
||
1244 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1245 != (language
!= NULL
))
1248 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1249 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1255 * See if we need to map charset, language, or locale values...
1258 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
1259 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1260 value_tag
= temp_tag
; /* Don't do a fast copy */
1261 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
))
1263 for (i
= 0; i
< num_values
; i
++)
1264 if (strcmp(values
[i
], ipp_get_code(values
[i
], code
, sizeof(code
))))
1266 value_tag
= temp_tag
; /* Don't do a fast copy */
1270 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
))
1272 for (i
= 0; i
< num_values
; i
++)
1273 if (strcmp(values
[i
], ipp_lang_code(values
[i
], code
, sizeof(code
))))
1275 value_tag
= temp_tag
; /* Don't do a fast copy */
1281 * Create the attribute...
1284 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
1288 * Initialize the attribute data...
1291 for (i
= num_values
, value
= attr
->values
;
1297 if (value
== attr
->values
)
1299 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1300 value
->string
.language
= (char *)language
;
1302 value
->string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1306 value
->string
.language
= attr
->values
[0].string
.language
;
1311 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1312 value
->string
.text
= (char *)*values
++;
1313 else if (value_tag
== IPP_TAG_CHARSET
)
1314 value
->string
.text
= _cupsStrAlloc(ipp_get_code(*values
++, code
, sizeof(code
)));
1315 else if (value_tag
== IPP_TAG_LANGUAGE
)
1316 value
->string
.text
= _cupsStrAlloc(ipp_lang_code(*values
++, code
, sizeof(code
)));
1318 value
->string
.text
= _cupsStrAlloc(*values
++);
1327 * 'ippContainsInteger()' - Determine whether an attribute contains the
1328 * specified value or is within the list of ranges.
1330 * Returns non-zero when the attribute contains either a matching integer or
1331 * enum value, or the value falls within one of the rangeOfInteger values for
1334 * @since CUPS 1.7/macOS 10.9@
1337 int /* O - 1 on a match, 0 on no match */
1339 ipp_attribute_t
*attr
, /* I - Attribute */
1340 int value
) /* I - Integer/enum value */
1342 int i
; /* Looping var */
1343 _ipp_value_t
*avalue
; /* Current attribute value */
1347 * Range check input...
1353 if (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
&&
1354 attr
->value_tag
!= IPP_TAG_RANGE
)
1361 if (attr
->value_tag
== IPP_TAG_RANGE
)
1363 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1364 if (value
>= avalue
->range
.lower
&& value
<= avalue
->range
.upper
)
1369 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1370 if (value
== avalue
->integer
)
1379 * 'ippContainsString()' - Determine whether an attribute contains the
1380 * specified string value.
1382 * Returns non-zero when the attribute contains a matching charset, keyword,
1383 * naturalLanguage, mimeMediaType, name, text, uri, or uriScheme value.
1385 * @since CUPS 1.7/macOS 10.9@
1388 int /* O - 1 on a match, 0 on no match */
1390 ipp_attribute_t
*attr
, /* I - Attribute */
1391 const char *value
) /* I - String value */
1393 int i
; /* Looping var */
1394 _ipp_value_t
*avalue
; /* Current attribute value */
1397 DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", (void *)attr
, value
));
1400 * Range check input...
1403 if (!attr
|| !value
)
1405 DEBUG_puts("1ippContainsString: Returning 0 (bad input)");
1413 DEBUG_printf(("1ippContainsString: attr %s, %s with %d values.",
1414 attr
->name
, ippTagString(attr
->value_tag
),
1417 switch (attr
->value_tag
& IPP_TAG_CUPS_MASK
)
1419 case IPP_TAG_CHARSET
:
1420 case IPP_TAG_KEYWORD
:
1421 case IPP_TAG_LANGUAGE
:
1423 case IPP_TAG_URISCHEME
:
1424 for (i
= attr
->num_values
, avalue
= attr
->values
;
1428 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1429 attr
->num_values
- i
, avalue
->string
.text
));
1431 if (!strcmp(value
, avalue
->string
.text
))
1433 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1438 case IPP_TAG_MIMETYPE
:
1440 case IPP_TAG_NAMELANG
:
1442 case IPP_TAG_TEXTLANG
:
1443 for (i
= attr
->num_values
, avalue
= attr
->values
;
1447 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1448 attr
->num_values
- i
, avalue
->string
.text
));
1450 if (!_cups_strcasecmp(value
, avalue
->string
.text
))
1452 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1461 DEBUG_puts("1ippContainsString: Returning 0 (no match)");
1468 * 'ippCopyAttribute()' - Copy an attribute.
1470 * The specified attribute, @code attr@, is copied to the destination IPP message.
1471 * When @code quickcopy@ is non-zero, a "shallow" reference copy of the attribute is
1472 * created - this should only be done as long as the original source IPP message will
1473 * not be freed for the life of the destination.
1475 * @since CUPS 1.6/macOS 10.8@
1479 ipp_attribute_t
* /* O - New attribute */
1481 ipp_t
*dst
, /* I - Destination IPP message */
1482 ipp_attribute_t
*srcattr
, /* I - Attribute to copy */
1483 int quickcopy
) /* I - 1 for a referenced copy, 0 for normal */
1485 int i
; /* Looping var */
1486 ipp_attribute_t
*dstattr
; /* Destination attribute */
1487 _ipp_value_t
*srcval
, /* Source value */
1488 *dstval
; /* Destination value */
1491 DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", (void *)dst
, (void *)srcattr
, quickcopy
));
1494 * Range check input...
1497 if (!dst
|| !srcattr
)
1504 quickcopy
= quickcopy
? IPP_TAG_CUPS_CONST
: 0;
1506 switch (srcattr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
1509 dstattr
= ippAddSeparator(dst
);
1512 case IPP_TAG_UNSUPPORTED_VALUE
:
1513 case IPP_TAG_DEFAULT
:
1514 case IPP_TAG_UNKNOWN
:
1515 case IPP_TAG_NOVALUE
:
1516 case IPP_TAG_NOTSETTABLE
:
1517 case IPP_TAG_DELETEATTR
:
1518 case IPP_TAG_ADMINDEFINE
:
1519 dstattr
= ippAddOutOfBand(dst
, srcattr
->group_tag
, srcattr
->value_tag
& ~IPP_TAG_CUPS_CONST
, srcattr
->name
);
1522 case IPP_TAG_INTEGER
:
1524 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1525 srcattr
->name
, srcattr
->num_values
, NULL
);
1529 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1531 i
--, srcval
++, dstval
++)
1532 dstval
->integer
= srcval
->integer
;
1535 case IPP_TAG_BOOLEAN
:
1536 dstattr
= ippAddBooleans(dst
, srcattr
->group_tag
, srcattr
->name
,
1537 srcattr
->num_values
, NULL
);
1541 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1543 i
--, srcval
++, dstval
++)
1544 dstval
->boolean
= srcval
->boolean
;
1549 case IPP_TAG_KEYWORD
:
1551 case IPP_TAG_URISCHEME
:
1552 case IPP_TAG_CHARSET
:
1553 case IPP_TAG_LANGUAGE
:
1554 case IPP_TAG_MIMETYPE
:
1555 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1556 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1557 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1563 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1564 dstval
= dstattr
->values
;
1566 i
--, srcval
++, dstval
++)
1567 dstval
->string
.text
= srcval
->string
.text
;
1569 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1571 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1572 dstval
= dstattr
->values
;
1574 i
--, srcval
++, dstval
++)
1575 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1579 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1580 dstval
= dstattr
->values
;
1582 i
--, srcval
++, dstval
++)
1583 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1588 if (srcattr
->num_values
!= 1)
1591 dstattr
= ippAddDate(dst
, srcattr
->group_tag
, srcattr
->name
,
1592 srcattr
->values
[0].date
);
1595 case IPP_TAG_RESOLUTION
:
1596 dstattr
= ippAddResolutions(dst
, srcattr
->group_tag
, srcattr
->name
,
1597 srcattr
->num_values
, IPP_RES_PER_INCH
,
1602 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1604 i
--, srcval
++, dstval
++)
1606 dstval
->resolution
.xres
= srcval
->resolution
.xres
;
1607 dstval
->resolution
.yres
= srcval
->resolution
.yres
;
1608 dstval
->resolution
.units
= srcval
->resolution
.units
;
1612 case IPP_TAG_RANGE
:
1613 dstattr
= ippAddRanges(dst
, srcattr
->group_tag
, srcattr
->name
,
1614 srcattr
->num_values
, NULL
, NULL
);
1618 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1620 i
--, srcval
++, dstval
++)
1622 dstval
->range
.lower
= srcval
->range
.lower
;
1623 dstval
->range
.upper
= srcval
->range
.upper
;
1627 case IPP_TAG_TEXTLANG
:
1628 case IPP_TAG_NAMELANG
:
1629 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1630 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1631 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1637 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1638 dstval
= dstattr
->values
;
1640 i
--, srcval
++, dstval
++)
1642 dstval
->string
.language
= srcval
->string
.language
;
1643 dstval
->string
.text
= srcval
->string
.text
;
1646 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1648 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1649 dstval
= dstattr
->values
;
1651 i
--, srcval
++, dstval
++)
1653 if (srcval
== srcattr
->values
)
1654 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1656 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1658 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1663 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1664 dstval
= dstattr
->values
;
1666 i
--, srcval
++, dstval
++)
1668 if (srcval
== srcattr
->values
)
1669 dstval
->string
.language
= _cupsStrRetain(srcval
->string
.language
);
1671 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1673 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1678 case IPP_TAG_BEGIN_COLLECTION
:
1679 dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
,
1680 srcattr
->num_values
, NULL
);
1684 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1686 i
--, srcval
++, dstval
++)
1688 dstval
->collection
= srcval
->collection
;
1689 srcval
->collection
->use
++;
1693 case IPP_TAG_STRING
:
1695 /* TODO: Implement quick copy for unknown/octetString values */
1696 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1697 srcattr
->name
, srcattr
->num_values
, NULL
);
1701 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1703 i
--, srcval
++, dstval
++)
1705 dstval
->unknown
.length
= srcval
->unknown
.length
;
1707 if (dstval
->unknown
.length
> 0)
1709 if ((dstval
->unknown
.data
= malloc((size_t)dstval
->unknown
.length
)) == NULL
)
1710 dstval
->unknown
.length
= 0;
1712 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, (size_t)dstval
->unknown
.length
);
1715 break; /* anti-compiler-warning-code */
1723 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1725 * Zero or more attributes are copied from the source IPP message, @code src@, to the
1726 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1727 * reference copy of the attribute is created - this should only be done as long as the
1728 * original source IPP message will not be freed for the life of the destination.
1730 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1731 * attributes that are copied - the function must return 1 to copy the attribute or
1732 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1735 * @since CUPS 1.6/macOS 10.8@
1738 int /* O - 1 on success, 0 on error */
1740 ipp_t
*dst
, /* I - Destination IPP message */
1741 ipp_t
*src
, /* I - Source IPP message */
1742 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1743 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1744 void *context
) /* I - Context pointer */
1746 ipp_attribute_t
*srcattr
; /* Source attribute */
1749 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)", (void *)dst
, (void *)src
, quickcopy
, (void *)cb
, context
));
1752 * Range check input...
1759 * Loop through source attributes and copy as needed...
1762 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1763 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1764 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1772 * 'ippDateToTime()' - Convert from RFC 2579 Date/Time format to time in
1776 time_t /* O - UNIX time value */
1777 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 2579 date info */
1779 struct tm unixdate
; /* UNIX date/time info */
1780 time_t t
; /* Computed time */
1786 memset(&unixdate
, 0, sizeof(unixdate
));
1789 * RFC-2579 date/time format is:
1791 * Byte(s) Description
1792 * ------- -----------
1793 * 0-1 Year (0 to 65535)
1797 * 5 Minutes (0 to 59)
1798 * 6 Seconds (0 to 60, 60 = "leap second")
1799 * 7 Deciseconds (0 to 9)
1801 * 9 UTC hours (0 to 11)
1802 * 10 UTC minutes (0 to 59)
1805 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1806 unixdate
.tm_mon
= date
[2] - 1;
1807 unixdate
.tm_mday
= date
[3];
1808 unixdate
.tm_hour
= date
[4];
1809 unixdate
.tm_min
= date
[5];
1810 unixdate
.tm_sec
= date
[6];
1812 t
= mktime(&unixdate
);
1815 t
+= date
[9] * 3600 + date
[10] * 60;
1817 t
-= date
[9] * 3600 + date
[10] * 60;
1824 * 'ippDelete()' - Delete an IPP message.
1828 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1830 ipp_attribute_t
*attr
, /* Current attribute */
1831 *next
; /* Next attribute */
1834 DEBUG_printf(("ippDelete(ipp=%p)", (void *)ipp
));
1842 DEBUG_printf(("4debug_retain: %p IPP message (use=%d)", (void *)ipp
, ipp
->use
));
1846 DEBUG_printf(("4debug_free: %p IPP message", (void *)ipp
));
1848 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1852 DEBUG_printf(("4debug_free: %p %s %s%s (%d values)", (void *)attr
, attr
->name
, attr
->num_values
> 1 ? "1setOf " : "", ippTagString(attr
->value_tag
), attr
->num_values
));
1854 ipp_free_values(attr
, 0, attr
->num_values
);
1857 _cupsStrFree(attr
->name
);
1867 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1869 * @since CUPS 1.1.19/macOS 10.3@
1874 ipp_t
*ipp
, /* I - IPP message */
1875 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1877 ipp_attribute_t
*current
, /* Current attribute */
1878 *prev
; /* Previous attribute */
1881 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", (void *)ipp
, (void *)attr
, attr
? attr
->name
: "(null)"));
1884 * Range check input...
1890 DEBUG_printf(("4debug_free: %p %s %s%s (%d values)", (void *)attr
, attr
->name
, attr
->num_values
> 1 ? "1setOf " : "", ippTagString(attr
->value_tag
), attr
->num_values
));
1893 * Find the attribute in the list...
1898 for (current
= ipp
->attrs
, prev
= NULL
;
1900 prev
= current
, current
= current
->next
)
1901 if (current
== attr
)
1904 * Found it, remove the attribute from the list...
1908 prev
->next
= current
->next
;
1910 ipp
->attrs
= current
->next
;
1912 if (current
== ipp
->last
)
1923 * Free memory used by the attribute...
1926 ipp_free_values(attr
, 0, attr
->num_values
);
1929 _cupsStrFree(attr
->name
);
1936 * 'ippDeleteValues()' - Delete values in an attribute.
1938 * The @code element@ parameter specifies the first value to delete, starting at
1939 * 0. It must be less than the number of values returned by @link ippGetCount@.
1941 * The @code attr@ parameter may be modified as a result of setting the value.
1943 * Deleting all values in an attribute deletes the attribute.
1945 * @since CUPS 1.6/macOS 10.8@
1948 int /* O - 1 on success, 0 on failure */
1950 ipp_t
*ipp
, /* I - IPP message */
1951 ipp_attribute_t
**attr
, /* IO - Attribute */
1952 int element
, /* I - Index of first value to delete (0-based) */
1953 int count
) /* I - Number of values to delete */
1956 * Range check input...
1959 if (!ipp
|| !attr
|| !*attr
||
1960 element
< 0 || element
>= (*attr
)->num_values
|| count
<= 0 ||
1961 (element
+ count
) >= (*attr
)->num_values
)
1965 * If we are deleting all values, just delete the attribute entirely.
1968 if (count
== (*attr
)->num_values
)
1970 ippDeleteAttribute(ipp
, *attr
);
1976 * Otherwise free the values in question and return.
1979 ipp_free_values(*attr
, element
, count
);
1986 * 'ippFindAttribute()' - Find a named attribute in a request.
1988 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1989 * of attribute and member names separated by slashes, for example
1990 * "media-col/media-size".
1993 ipp_attribute_t
* /* O - Matching attribute */
1994 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
1995 const char *name
, /* I - Name of attribute */
1996 ipp_tag_t type
) /* I - Type of attribute */
1998 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
2004 * Reset the current pointer...
2007 ipp
->current
= NULL
;
2011 * Search for the attribute...
2014 return (ippFindNextAttribute(ipp
, name
, type
));
2019 * 'ippFindNextAttribute()' - Find the next named attribute in a request.
2021 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
2022 * of attribute and member names separated by slashes, for example
2023 * "media-col/media-size".
2026 ipp_attribute_t
* /* O - Matching attribute */
2027 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
2028 const char *name
, /* I - Name of attribute */
2029 ipp_tag_t type
) /* I - Type of attribute */
2031 ipp_attribute_t
*attr
, /* Current atttribute */
2032 *childattr
; /* Child attribute */
2033 ipp_tag_t value_tag
; /* Value tag */
2034 char parent
[1024], /* Parent attribute name */
2035 *child
= NULL
; /* Child attribute name */
2038 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
2043 DEBUG_printf(("3ippFindNextAttribute: atend=%d", ipp
->atend
));
2048 if (strchr(name
, '/'))
2051 * Search for child attribute...
2054 strlcpy(parent
, name
, sizeof(parent
));
2055 if ((child
= strchr(parent
, '/')) == NULL
)
2057 DEBUG_puts("3ippFindNextAttribute: Attribute name too long.");
2063 if (ipp
->current
&& ipp
->current
->name
&& ipp
->current
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&& !strcmp(parent
, ipp
->current
->name
))
2065 while (ipp
->curindex
< ipp
->current
->num_values
)
2067 if ((childattr
= ippFindNextAttribute(ipp
->current
->values
[ipp
->curindex
].collection
, child
, type
)) != NULL
)
2071 if (ipp
->curindex
< ipp
->current
->num_values
&& ipp
->current
->values
[ipp
->curindex
].collection
)
2072 ipp
->current
->values
[ipp
->curindex
].collection
->current
= NULL
;
2075 ipp
->prev
= ipp
->current
;
2076 ipp
->current
= ipp
->current
->next
;
2089 ipp
->current
= ipp
->attrs
;
2094 attr
= ipp
->current
;
2096 else if (ipp
->current
)
2098 ipp
->prev
= ipp
->current
;
2099 attr
= ipp
->current
->next
;
2107 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
2109 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", (void *)attr
, attr
->name
));
2111 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2113 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
2114 (value_tag
== type
|| type
== IPP_TAG_ZERO
|| name
== parent
||
2115 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
2116 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
2118 ipp
->current
= attr
;
2120 if (name
== parent
&& attr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
)
2122 int i
; /* Looping var */
2124 for (i
= 0; i
< attr
->num_values
; i
++)
2126 if ((childattr
= ippFindAttribute(attr
->values
[i
].collection
, child
, type
)) != NULL
)
2128 attr
->values
[0].collection
->curindex
= i
;
2138 ipp
->current
= NULL
;
2147 * 'ippFirstAttribute()' - Return the first attribute in the message.
2149 * @since CUPS 1.6/macOS 10.8@
2152 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
2153 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
2156 * Range check input...
2163 * Return the first attribute...
2166 return (ipp
->current
= ipp
->attrs
);
2171 * 'ippGetBoolean()' - Get a boolean value for an attribute.
2173 * The @code element@ parameter specifies which value to get from 0 to
2174 * @code ippGetCount(attr)@ - 1.
2176 * @since CUPS 1.6/macOS 10.8@
2179 int /* O - Boolean value or 0 on error */
2180 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
2181 int element
) /* I - Value number (0-based) */
2184 * Range check input...
2187 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
2188 element
< 0 || element
>= attr
->num_values
)
2192 * Return the value...
2195 return (attr
->values
[element
].boolean
);
2200 * 'ippGetCollection()' - Get a collection value for an attribute.
2202 * The @code element@ parameter specifies which value to get from 0 to
2203 * @code ippGetCount(attr)@ - 1.
2205 * @since CUPS 1.6/macOS 10.8@
2208 ipp_t
* /* O - Collection value or @code NULL@ on error */
2210 ipp_attribute_t
*attr
, /* I - IPP attribute */
2211 int element
) /* I - Value number (0-based) */
2214 * Range check input...
2217 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
2218 element
< 0 || element
>= attr
->num_values
)
2222 * Return the value...
2225 return (attr
->values
[element
].collection
);
2230 * 'ippGetCount()' - Get the number of values in an attribute.
2232 * @since CUPS 1.6/macOS 10.8@
2235 int /* O - Number of values or 0 on error */
2236 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
2239 * Range check input...
2246 * Return the number of values...
2249 return (attr
->num_values
);
2254 * 'ippGetDate()' - Get a dateTime value for an attribute.
2256 * The @code element@ parameter specifies which value to get from 0 to
2257 * @code ippGetCount(attr)@ - 1.
2259 * @since CUPS 1.6/macOS 10.8@
2262 const ipp_uchar_t
* /* O - dateTime value or @code NULL@ */
2263 ippGetDate(ipp_attribute_t
*attr
, /* I - IPP attribute */
2264 int element
) /* I - Value number (0-based) */
2267 * Range check input...
2270 if (!attr
|| attr
->value_tag
!= IPP_TAG_DATE
||
2271 element
< 0 || element
>= attr
->num_values
)
2275 * Return the value...
2278 return (attr
->values
[element
].date
);
2283 * 'ippGetGroupTag()' - Get the group associated with an attribute.
2285 * @since CUPS 1.6/macOS 10.8@
2288 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
2289 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2292 * Range check input...
2296 return (IPP_TAG_ZERO
);
2299 * Return the group...
2302 return (attr
->group_tag
);
2307 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
2309 * The @code element@ parameter specifies which value to get from 0 to
2310 * @code ippGetCount(attr)@ - 1.
2312 * @since CUPS 1.6/macOS 10.8@
2315 int /* O - Value or 0 on error */
2316 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
2317 int element
) /* I - Value number (0-based) */
2320 * Range check input...
2323 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
2324 element
< 0 || element
>= attr
->num_values
)
2328 * Return the value...
2331 return (attr
->values
[element
].integer
);
2336 * 'ippGetName()' - Get the attribute name.
2338 * @since CUPS 1.6/macOS 10.8@
2341 const char * /* O - Attribute name or @code NULL@ for separators */
2342 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
2345 * Range check input...
2352 * Return the name...
2355 return (attr
->name
);
2360 * 'ippGetOctetString()' - Get an octetString value from an IPP attribute.
2362 * The @code element@ parameter specifies which value to get from 0 to
2363 * @code ippGetCount(attr)@ - 1.
2365 * @since CUPS 1.7/macOS 10.9@
2368 void * /* O - Pointer to octetString data */
2370 ipp_attribute_t
*attr
, /* I - IPP attribute */
2371 int element
, /* I - Value number (0-based) */
2372 int *datalen
) /* O - Length of octetString data */
2375 * Range check input...
2378 if (!attr
|| attr
->value_tag
!= IPP_TAG_STRING
||
2379 element
< 0 || element
>= attr
->num_values
)
2388 * Return the values...
2392 *datalen
= attr
->values
[element
].unknown
.length
;
2394 return (attr
->values
[element
].unknown
.data
);
2399 * 'ippGetOperation()' - Get the operation ID in an IPP message.
2401 * @since CUPS 1.6/macOS 10.8@
2404 ipp_op_t
/* O - Operation ID or 0 on error */
2405 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
2408 * Range check input...
2412 return ((ipp_op_t
)0);
2415 * Return the value...
2418 return (ipp
->request
.op
.operation_id
);
2423 * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
2425 * The @code element@ parameter specifies which value to get from 0 to
2426 * @code ippGetCount(attr)@ - 1.
2428 * @since CUPS 1.6/macOS 10.8@
2431 int /* O - Lower value of range or 0 */
2432 ippGetRange(ipp_attribute_t
*attr
, /* I - IPP attribute */
2433 int element
, /* I - Value number (0-based) */
2434 int *uppervalue
)/* O - Upper value of range */
2437 * Range check input...
2440 if (!attr
|| attr
->value_tag
!= IPP_TAG_RANGE
||
2441 element
< 0 || element
>= attr
->num_values
)
2450 * Return the values...
2454 *uppervalue
= attr
->values
[element
].range
.upper
;
2456 return (attr
->values
[element
].range
.lower
);
2461 * 'ippGetRequestId()' - Get the request ID from an IPP message.
2463 * @since CUPS 1.6/macOS 10.8@
2466 int /* O - Request ID or 0 on error */
2467 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
2470 * Range check input...
2477 * Return the request ID...
2480 return (ipp
->request
.any
.request_id
);
2485 * 'ippGetResolution()' - Get a resolution value for an attribute.
2487 * The @code element@ parameter specifies which value to get from 0 to
2488 * @code ippGetCount(attr)@ - 1.
2490 * @since CUPS 1.6/macOS 10.8@
2493 int /* O - Horizontal/cross feed resolution or 0 */
2495 ipp_attribute_t
*attr
, /* I - IPP attribute */
2496 int element
, /* I - Value number (0-based) */
2497 int *yres
, /* O - Vertical/feed resolution */
2498 ipp_res_t
*units
) /* O - Units for resolution */
2501 * Range check input...
2504 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
2505 element
< 0 || element
>= attr
->num_values
)
2511 *units
= (ipp_res_t
)0;
2517 * Return the value...
2521 *yres
= attr
->values
[element
].resolution
.yres
;
2524 *units
= attr
->values
[element
].resolution
.units
;
2526 return (attr
->values
[element
].resolution
.xres
);
2531 * 'ippGetState()' - Get the IPP message state.
2533 * @since CUPS 1.6/macOS 10.8@
2536 ipp_state_t
/* O - IPP message state value */
2537 ippGetState(ipp_t
*ipp
) /* I - IPP message */
2540 * Range check input...
2544 return (IPP_STATE_IDLE
);
2547 * Return the value...
2550 return (ipp
->state
);
2555 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2557 * @since CUPS 1.6/macOS 10.8@
2560 ipp_status_t
/* O - Status code in IPP message */
2561 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2564 * Range check input...
2568 return (IPP_STATUS_ERROR_INTERNAL
);
2571 * Return the value...
2574 return (ipp
->request
.status
.status_code
);
2579 * 'ippGetString()' - Get the string and optionally the language code for an attribute.
2581 * The @code element@ parameter specifies which value to get from 0 to
2582 * @code ippGetCount(attr)@ - 1.
2584 * @since CUPS 1.6/macOS 10.8@
2588 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2589 int element
, /* I - Value number (0-based) */
2590 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2592 ipp_tag_t tag
; /* Value tag */
2596 * Range check input...
2599 tag
= ippGetValueTag(attr
);
2601 if (!attr
|| element
< 0 || element
>= attr
->num_values
|| (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&& (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
)))
2605 * Return the value...
2609 *language
= attr
->values
[element
].string
.language
;
2611 return (attr
->values
[element
].string
.text
);
2616 * 'ippGetValueTag()' - Get the value tag for an attribute.
2618 * @since CUPS 1.6/macOS 10.8@
2621 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2622 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2625 * Range check input...
2629 return (IPP_TAG_ZERO
);
2632 * Return the value...
2635 return (attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2640 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2642 * @since CUPS 1.6/macOS 10.8@
2645 int /* O - Major version number or 0 on error */
2646 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2647 int *minor
) /* O - Minor version number or @code NULL@ for don't care */
2650 * Range check input...
2662 * Return the value...
2666 *minor
= ipp
->request
.any
.version
[1];
2668 return (ipp
->request
.any
.version
[0]);
2673 * 'ippLength()' - Compute the length of an IPP message.
2676 size_t /* O - Size of IPP message */
2677 ippLength(ipp_t
*ipp
) /* I - IPP message */
2679 return (ipp_length(ipp
, 0));
2684 * 'ippNextAttribute()' - Return the next attribute in the message.
2686 * @since CUPS 1.6/macOS 10.8@
2689 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2690 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2693 * Range check input...
2696 if (!ipp
|| !ipp
->current
)
2700 * Return the next attribute...
2703 return (ipp
->current
= ipp
->current
->next
);
2708 * 'ippNew()' - Allocate a new IPP message.
2711 ipp_t
* /* O - New IPP message */
2714 ipp_t
*temp
; /* New IPP message */
2715 _cups_globals_t
*cg
= _cupsGlobals();
2719 DEBUG_puts("ippNew()");
2721 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2724 * Set default version - usually 2.0...
2727 DEBUG_printf(("4debug_alloc: %p IPP message", (void *)temp
));
2729 if (cg
->server_version
== 0)
2732 temp
->request
.any
.version
[0] = (ipp_uchar_t
)(cg
->server_version
/ 10);
2733 temp
->request
.any
.version
[1] = (ipp_uchar_t
)(cg
->server_version
% 10);
2737 DEBUG_printf(("1ippNew: Returning %p", (void *)temp
));
2744 * 'ippNewRequest()' - Allocate a new IPP request message.
2746 * The new request message is initialized with the "attributes-charset" and
2747 * "attributes-natural-language" attributes added. The
2748 * "attributes-natural-language" value is derived from the current locale.
2750 * @since CUPS 1.2/macOS 10.5@
2753 ipp_t
* /* O - IPP request message */
2754 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2756 ipp_t
*request
; /* IPP request message */
2757 cups_lang_t
*language
; /* Current language localization */
2758 static int request_id
= 0; /* Current request ID */
2759 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2760 /* Mutex for request ID */
2763 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2766 * Create a new IPP message...
2769 if ((request
= ippNew()) == NULL
)
2773 * Set the operation and request ID...
2776 _cupsMutexLock(&request_mutex
);
2778 request
->request
.op
.operation_id
= op
;
2779 request
->request
.op
.request_id
= ++request_id
;
2781 _cupsMutexUnlock(&request_mutex
);
2784 * Use UTF-8 as the character set...
2787 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2788 "attributes-charset", NULL
, "utf-8");
2791 * Get the language from the current locale...
2794 language
= cupsLangDefault();
2796 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2797 "attributes-natural-language", NULL
, language
->language
);
2800 * Return the new request...
2808 * 'ippNewResponse()' - Allocate a new IPP response message.
2810 * The new response message is initialized with the same "version-number",
2811 * "request-id", "attributes-charset", and "attributes-natural-language" as the
2812 * provided request message. If the "attributes-charset" or
2813 * "attributes-natural-language" attributes are missing from the request,
2814 * 'utf-8' and a value derived from the current locale are substituted,
2817 * @since CUPS 1.7/macOS 10.9@
2820 ipp_t
* /* O - IPP response message */
2821 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2823 ipp_t
*response
; /* IPP response message */
2824 ipp_attribute_t
*attr
; /* Current attribute */
2828 * Range check input...
2835 * Create a new IPP message...
2838 if ((response
= ippNew()) == NULL
)
2842 * Copy the request values over to the response...
2845 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2846 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2847 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2850 * The first attribute MUST be attributes-charset...
2853 attr
= request
->attrs
;
2855 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2856 attr
->group_tag
== IPP_TAG_OPERATION
&&
2857 attr
->value_tag
== IPP_TAG_CHARSET
&&
2858 attr
->num_values
== 1)
2861 * Copy charset from request...
2864 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2865 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2870 * Use "utf-8" as the default...
2873 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2874 "attributes-charset", NULL
, "utf-8");
2878 * Then attributes-natural-language...
2884 if (attr
&& attr
->name
&&
2885 !strcmp(attr
->name
, "attributes-natural-language") &&
2886 attr
->group_tag
== IPP_TAG_OPERATION
&&
2887 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2888 attr
->num_values
== 1)
2891 * Copy language from request...
2894 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2895 "attributes-natural-language", NULL
,
2896 attr
->values
[0].string
.text
);
2901 * Use the language from the current locale...
2904 cups_lang_t
*language
= cupsLangDefault();
2905 /* Current locale */
2907 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2908 "attributes-natural-language", NULL
, language
->language
);
2916 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2919 ipp_state_t
/* O - Current state */
2920 ippRead(http_t
*http
, /* I - HTTP connection */
2921 ipp_t
*ipp
) /* I - IPP data */
2923 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
, (void *)http
, (void *)ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2926 return (IPP_STATE_ERROR
);
2928 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
, http
->used
));
2930 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2936 * 'ippReadFile()' - Read data for an IPP message from a file.
2938 * @since CUPS 1.1.19/macOS 10.3@
2941 ipp_state_t
/* O - Current state */
2942 ippReadFile(int fd
, /* I - HTTP data */
2943 ipp_t
*ipp
) /* I - IPP data */
2945 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
2947 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2952 * 'ippReadIO()' - Read data for an IPP message.
2954 * @since CUPS 1.2/macOS 10.5@
2957 ipp_state_t
/* O - Current state */
2958 ippReadIO(void *src
, /* I - Data source */
2959 ipp_iocb_t cb
, /* I - Read callback function */
2960 int blocking
, /* I - Use blocking IO? */
2961 ipp_t
*parent
, /* I - Parent request, if any */
2962 ipp_t
*ipp
) /* I - IPP data */
2964 int n
; /* Length of data */
2965 unsigned char *buffer
, /* Data buffer */
2966 string
[IPP_MAX_TEXT
],
2967 /* Small string buffer */
2968 *bufptr
; /* Pointer into buffer */
2969 ipp_attribute_t
*attr
; /* Current attribute */
2970 ipp_tag_t tag
; /* Current tag */
2971 ipp_tag_t value_tag
; /* Current value tag */
2972 _ipp_value_t
*value
; /* Current value */
2975 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)src
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
2976 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_STATE_ERROR
));
2979 return (IPP_STATE_ERROR
);
2981 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2983 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2984 return (IPP_STATE_ERROR
);
2989 case IPP_STATE_IDLE
:
2990 ipp
->state
++; /* Avoid common problem... */
2992 case IPP_STATE_HEADER
:
2996 * Get the request header...
2999 if ((*cb
)(src
, buffer
, 8) < 8)
3001 DEBUG_puts("1ippReadIO: Unable to read header.");
3002 _cupsBufferRelease((char *)buffer
);
3003 return (IPP_STATE_ERROR
);
3007 * Then copy the request header over...
3010 ipp
->request
.any
.version
[0] = buffer
[0];
3011 ipp
->request
.any
.version
[1] = buffer
[1];
3012 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
3013 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
3014 buffer
[6]) << 8) | buffer
[7];
3016 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
3017 DEBUG_printf(("2ippReadIO: op_status=%04x",
3018 ipp
->request
.any
.op_status
));
3019 DEBUG_printf(("2ippReadIO: request_id=%d",
3020 ipp
->request
.any
.request_id
));
3023 ipp
->state
= IPP_STATE_ATTRIBUTE
;
3024 ipp
->current
= NULL
;
3025 ipp
->curtag
= IPP_TAG_ZERO
;
3026 ipp
->prev
= ipp
->last
;
3029 * If blocking is disabled, stop here...
3035 case IPP_STATE_ATTRIBUTE
:
3038 if ((*cb
)(src
, buffer
, 1) < 1)
3040 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3041 _cupsBufferRelease((char *)buffer
);
3042 return (IPP_STATE_ERROR
);
3045 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3048 * Read this attribute...
3051 tag
= (ipp_tag_t
)buffer
[0];
3052 if (tag
== IPP_TAG_EXTENSION
)
3055 * Read 32-bit "extension" tag...
3058 if ((*cb
)(src
, buffer
, 4) < 1)
3060 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3061 _cupsBufferRelease((char *)buffer
);
3062 return (IPP_STATE_ERROR
);
3065 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
3066 buffer
[2]) << 8) | buffer
[3]);
3068 if (tag
& IPP_TAG_CUPS_CONST
)
3071 * Fail if the high bit is set in the tag...
3074 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
3075 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
3076 _cupsBufferRelease((char *)buffer
);
3077 return (IPP_STATE_ERROR
);
3081 if (tag
== IPP_TAG_END
)
3084 * No more attributes left...
3087 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
3089 ipp
->state
= IPP_STATE_DATA
;
3092 else if (tag
== IPP_TAG_ZERO
|| (tag
== IPP_TAG_OPERATION
&& ipp
->curtag
!= IPP_TAG_ZERO
))
3094 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Invalid group tag."), 1);
3095 DEBUG_printf(("1ippReadIO: bad tag 0x%02x.", tag
));
3096 _cupsBufferRelease((char *)buffer
);
3097 return (IPP_STATE_ERROR
);
3099 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3102 * Group tag... Set the current group and continue...
3105 if (ipp
->curtag
== tag
)
3106 ipp
->prev
= ippAddSeparator(ipp
);
3107 else if (ipp
->current
)
3108 ipp
->prev
= ipp
->current
;
3111 ipp
->current
= NULL
;
3112 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
, ippTagString(tag
), (void *)ipp
->prev
));
3116 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3117 ippTagString(tag
)));
3123 if ((*cb
)(src
, buffer
, 2) < 2)
3125 DEBUG_puts("1ippReadIO: unable to read name length.");
3126 _cupsBufferRelease((char *)buffer
);
3127 return (IPP_STATE_ERROR
);
3130 n
= (buffer
[0] << 8) | buffer
[1];
3132 if (n
>= IPP_BUF_SIZE
)
3134 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3135 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3136 _cupsBufferRelease((char *)buffer
);
3137 return (IPP_STATE_ERROR
);
3140 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3142 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3143 tag
!= IPP_TAG_END_COLLECTION
)
3146 * More values for current attribute...
3149 if (ipp
->current
== NULL
)
3151 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3152 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3153 _cupsBufferRelease((char *)buffer
);
3154 return (IPP_STATE_ERROR
);
3157 attr
= ipp
->current
;
3158 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3161 * Make sure we aren't adding a new value of a different
3165 if (value_tag
== IPP_TAG_ZERO
)
3168 * Setting the value of a collection member...
3171 attr
->value_tag
= tag
;
3173 else if (value_tag
== IPP_TAG_TEXTLANG
||
3174 value_tag
== IPP_TAG_NAMELANG
||
3175 (value_tag
>= IPP_TAG_TEXT
&&
3176 value_tag
<= IPP_TAG_MIMETYPE
))
3179 * String values can sometimes come across in different
3180 * forms; accept sets of differing values...
3183 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3184 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3185 tag
!= IPP_TAG_NOVALUE
)
3187 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3188 _("IPP 1setOf attribute with incompatible value "
3190 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3191 value_tag
, ippTagString(value_tag
), tag
,
3192 ippTagString(tag
)));
3193 _cupsBufferRelease((char *)buffer
);
3194 return (IPP_STATE_ERROR
);
3197 if (value_tag
!= tag
)
3199 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3200 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3201 ippSetValueTag(ipp
, &attr
, tag
);
3204 else if (value_tag
== IPP_TAG_INTEGER
||
3205 value_tag
== IPP_TAG_RANGE
)
3208 * Integer and rangeOfInteger values can sometimes be mixed; accept
3209 * sets of differing values...
3212 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3214 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3215 _("IPP 1setOf attribute with incompatible value "
3217 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3218 value_tag
, ippTagString(value_tag
), tag
,
3219 ippTagString(tag
)));
3220 _cupsBufferRelease((char *)buffer
);
3221 return (IPP_STATE_ERROR
);
3224 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3227 * Convert integer values to rangeOfInteger values...
3230 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3231 "rangeOfInteger.", attr
->name
));
3232 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3235 else if (value_tag
!= tag
)
3237 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3238 _("IPP 1setOf attribute with incompatible value "
3240 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3241 value_tag
, ippTagString(value_tag
), tag
,
3242 ippTagString(tag
)));
3243 _cupsBufferRelease((char *)buffer
);
3244 return (IPP_STATE_ERROR
);
3248 * Finally, reallocate the attribute array as needed...
3251 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3253 _cupsBufferRelease((char *)buffer
);
3254 return (IPP_STATE_ERROR
);
3257 else if (tag
== IPP_TAG_MEMBERNAME
)
3260 * Name must be length 0!
3265 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3266 DEBUG_puts("1ippReadIO: member name not empty.");
3267 _cupsBufferRelease((char *)buffer
);
3268 return (IPP_STATE_ERROR
);
3272 ipp
->prev
= ipp
->current
;
3274 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3277 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3278 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3279 _cupsBufferRelease((char *)buffer
);
3280 return (IPP_STATE_ERROR
);
3283 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3285 value
= attr
->values
;
3287 else if (tag
!= IPP_TAG_END_COLLECTION
)
3290 * New attribute; read the name and add it...
3293 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3295 DEBUG_puts("1ippReadIO: unable to read name.");
3296 _cupsBufferRelease((char *)buffer
);
3297 return (IPP_STATE_ERROR
);
3303 ipp
->prev
= ipp
->current
;
3305 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3308 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3309 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3310 _cupsBufferRelease((char *)buffer
);
3311 return (IPP_STATE_ERROR
);
3314 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer
, (void *)ipp
->current
, (void *)ipp
->prev
));
3316 value
= attr
->values
;
3324 if ((*cb
)(src
, buffer
, 2) < 2)
3326 DEBUG_puts("1ippReadIO: unable to read value length.");
3327 _cupsBufferRelease((char *)buffer
);
3328 return (IPP_STATE_ERROR
);
3331 n
= (buffer
[0] << 8) | buffer
[1];
3332 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3334 if (n
>= IPP_BUF_SIZE
)
3336 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3337 _("IPP value larger than 32767 bytes."), 1);
3338 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3339 _cupsBufferRelease((char *)buffer
);
3340 return (IPP_STATE_ERROR
);
3345 case IPP_TAG_INTEGER
:
3349 if (tag
== IPP_TAG_INTEGER
)
3350 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3351 _("IPP integer value not 4 bytes."), 1);
3353 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3354 _("IPP enum value not 4 bytes."), 1);
3355 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3356 _cupsBufferRelease((char *)buffer
);
3357 return (IPP_STATE_ERROR
);
3360 if ((*cb
)(src
, buffer
, 4) < 4)
3362 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3363 _cupsBufferRelease((char *)buffer
);
3364 return (IPP_STATE_ERROR
);
3367 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3370 if (attr
->value_tag
== IPP_TAG_RANGE
)
3371 value
->range
.lower
= value
->range
.upper
= n
;
3376 case IPP_TAG_BOOLEAN
:
3379 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3381 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3382 _cupsBufferRelease((char *)buffer
);
3383 return (IPP_STATE_ERROR
);
3386 if ((*cb
)(src
, buffer
, 1) < 1)
3388 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3389 _cupsBufferRelease((char *)buffer
);
3390 return (IPP_STATE_ERROR
);
3393 value
->boolean
= (char)buffer
[0];
3396 case IPP_TAG_UNSUPPORTED_VALUE
:
3397 case IPP_TAG_DEFAULT
:
3398 case IPP_TAG_UNKNOWN
:
3399 case IPP_TAG_NOVALUE
:
3400 case IPP_TAG_NOTSETTABLE
:
3401 case IPP_TAG_DELETEATTR
:
3402 case IPP_TAG_ADMINDEFINE
:
3404 * These value types are not supposed to have values, however
3405 * some vendors (Brother) do not implement IPP correctly and so
3406 * we need to map non-empty values to text...
3409 if (attr
->value_tag
== tag
)
3414 attr
->value_tag
= IPP_TAG_TEXT
;
3419 case IPP_TAG_RESERVED_STRING
:
3420 case IPP_TAG_KEYWORD
:
3422 case IPP_TAG_URISCHEME
:
3423 case IPP_TAG_CHARSET
:
3424 case IPP_TAG_LANGUAGE
:
3425 case IPP_TAG_MIMETYPE
:
3428 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3430 DEBUG_puts("1ippReadIO: unable to read string value.");
3431 _cupsBufferRelease((char *)buffer
);
3432 return (IPP_STATE_ERROR
);
3437 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3438 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3444 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3445 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3446 _cupsBufferRelease((char *)buffer
);
3447 return (IPP_STATE_ERROR
);
3450 if ((*cb
)(src
, value
->date
, 11) < 11)
3452 DEBUG_puts("1ippReadIO: Unable to read date value.");
3453 _cupsBufferRelease((char *)buffer
);
3454 return (IPP_STATE_ERROR
);
3458 case IPP_TAG_RESOLUTION
:
3461 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3462 _("IPP resolution value not 9 bytes."), 1);
3463 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3464 _cupsBufferRelease((char *)buffer
);
3465 return (IPP_STATE_ERROR
);
3468 if ((*cb
)(src
, buffer
, 9) < 9)
3470 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3471 _cupsBufferRelease((char *)buffer
);
3472 return (IPP_STATE_ERROR
);
3475 value
->resolution
.xres
=
3476 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3478 value
->resolution
.yres
=
3479 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3481 value
->resolution
.units
=
3482 (ipp_res_t
)buffer
[8];
3485 case IPP_TAG_RANGE
:
3488 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3489 _("IPP rangeOfInteger value not 8 bytes."), 1);
3490 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3492 _cupsBufferRelease((char *)buffer
);
3493 return (IPP_STATE_ERROR
);
3496 if ((*cb
)(src
, buffer
, 8) < 8)
3498 DEBUG_puts("1ippReadIO: Unable to read range value.");
3499 _cupsBufferRelease((char *)buffer
);
3500 return (IPP_STATE_ERROR
);
3503 value
->range
.lower
=
3504 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3506 value
->range
.upper
=
3507 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3511 case IPP_TAG_TEXTLANG
:
3512 case IPP_TAG_NAMELANG
:
3515 if (tag
== IPP_TAG_TEXTLANG
)
3516 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3517 _("IPP textWithLanguage value less than "
3518 "minimum 4 bytes."), 1);
3520 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3521 _("IPP nameWithLanguage value less than "
3522 "minimum 4 bytes."), 1);
3523 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3525 _cupsBufferRelease((char *)buffer
);
3526 return (IPP_STATE_ERROR
);
3529 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3531 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3533 _cupsBufferRelease((char *)buffer
);
3534 return (IPP_STATE_ERROR
);
3540 * text-with-language and name-with-language are composite
3549 n
= (bufptr
[0] << 8) | bufptr
[1];
3551 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) || n
>= (int)sizeof(string
))
3553 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3554 _("IPP language length overflows value."), 1);
3555 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3557 _cupsBufferRelease((char *)buffer
);
3558 return (IPP_STATE_ERROR
);
3560 else if (n
>= IPP_MAX_LANGUAGE
)
3562 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3563 _("IPP language length too large."), 1);
3564 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3566 _cupsBufferRelease((char *)buffer
);
3567 return (IPP_STATE_ERROR
);
3570 memcpy(string
, bufptr
+ 2, (size_t)n
);
3573 value
->string
.language
= _cupsStrAlloc((char *)string
);
3576 n
= (bufptr
[0] << 8) | bufptr
[1];
3578 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3580 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3581 _("IPP string length overflows value."), 1);
3582 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3583 _cupsBufferRelease((char *)buffer
);
3584 return (IPP_STATE_ERROR
);
3587 bufptr
[2 + n
] = '\0';
3588 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3591 case IPP_TAG_BEGIN_COLLECTION
:
3593 * Oh, boy, here comes a collection value, so read it...
3596 value
->collection
= ippNew();
3600 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3601 _("IPP begCollection value not 0 bytes."), 1);
3602 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3604 _cupsBufferRelease((char *)buffer
);
3605 return (IPP_STATE_ERROR
);
3608 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3610 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3611 _cupsBufferRelease((char *)buffer
);
3612 return (IPP_STATE_ERROR
);
3616 case IPP_TAG_END_COLLECTION
:
3617 _cupsBufferRelease((char *)buffer
);
3621 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3622 _("IPP endCollection value not 0 bytes."), 1);
3623 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3625 return (IPP_STATE_ERROR
);
3628 DEBUG_puts("1ippReadIO: endCollection tag...");
3629 return (ipp
->state
= IPP_STATE_DATA
);
3631 case IPP_TAG_MEMBERNAME
:
3633 * The value the name of the member in the collection, which
3634 * we need to carry over...
3639 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3640 _("IPP memberName with no attribute."), 1);
3641 DEBUG_puts("1ippReadIO: Member name without attribute.");
3642 _cupsBufferRelease((char *)buffer
);
3643 return (IPP_STATE_ERROR
);
3647 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3648 _("IPP memberName value is empty."), 1);
3649 DEBUG_puts("1ippReadIO: Empty member name value.");
3650 _cupsBufferRelease((char *)buffer
);
3651 return (IPP_STATE_ERROR
);
3653 else if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3655 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3656 _cupsBufferRelease((char *)buffer
);
3657 return (IPP_STATE_ERROR
);
3661 attr
->name
= _cupsStrAlloc((char *)buffer
);
3664 * Since collection members are encoded differently than
3665 * regular attributes, make sure we don't start with an
3669 attr
->num_values
--;
3671 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3674 default : /* Other unsupported values */
3675 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3677 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3678 _("IPP octetString length too large."), 1);
3679 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3681 _cupsBufferRelease((char *)buffer
);
3682 return (IPP_STATE_ERROR
);
3685 value
->unknown
.length
= n
;
3689 if ((value
->unknown
.data
= malloc((size_t)n
)) == NULL
)
3691 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3692 DEBUG_puts("1ippReadIO: Unable to allocate value");
3693 _cupsBufferRelease((char *)buffer
);
3694 return (IPP_STATE_ERROR
);
3697 if ((*cb
)(src
, value
->unknown
.data
, (size_t)n
) < n
)
3699 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3700 _cupsBufferRelease((char *)buffer
);
3701 return (IPP_STATE_ERROR
);
3705 value
->unknown
.data
= NULL
;
3710 * If blocking is disabled, stop here...
3718 case IPP_STATE_DATA
:
3722 break; /* anti-compiler-warning-code */
3725 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3726 _cupsBufferRelease((char *)buffer
);
3728 return (ipp
->state
);
3733 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3735 * The @code ipp@ parameter refers to an IPP message previously created using
3736 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3738 * The @code attr@ parameter may be modified as a result of setting the value.
3740 * The @code element@ parameter specifies which value to set from 0 to
3741 * @code ippGetCount(attr)@.
3743 * @since CUPS 1.6/macOS 10.8@
3746 int /* O - 1 on success, 0 on failure */
3747 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3748 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3749 int element
, /* I - Value number (0-based) */
3750 int boolvalue
)/* I - Boolean value */
3752 _ipp_value_t
*value
; /* Current value */
3756 * Range check input...
3759 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3760 element
< 0 || element
> (*attr
)->num_values
)
3764 * Set the value and return...
3767 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3768 value
->boolean
= (char)boolvalue
;
3770 return (value
!= NULL
);
3775 * 'ippSetCollection()' - Set a collection value in an attribute.
3777 * The @code ipp@ parameter refers to an IPP message previously created using
3778 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3780 * The @code attr@ parameter may be modified as a result of setting the value.
3782 * The @code element@ parameter specifies which value to set from 0 to
3783 * @code ippGetCount(attr)@.
3785 * @since CUPS 1.6/macOS 10.8@
3788 int /* O - 1 on success, 0 on failure */
3790 ipp_t
*ipp
, /* I - IPP message */
3791 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3792 int element
, /* I - Value number (0-based) */
3793 ipp_t
*colvalue
) /* I - Collection value */
3795 _ipp_value_t
*value
; /* Current value */
3799 * Range check input...
3802 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3803 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3807 * Set the value and return...
3810 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3812 if (value
->collection
)
3813 ippDelete(value
->collection
);
3815 value
->collection
= colvalue
;
3819 return (value
!= NULL
);
3824 * 'ippSetDate()' - Set a dateTime value in an attribute.
3826 * The @code ipp@ parameter refers to an IPP message previously created using
3827 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3829 * The @code attr@ parameter may be modified as a result of setting the value.
3831 * The @code element@ parameter specifies which value to set from 0 to
3832 * @code ippGetCount(attr)@.
3834 * @since CUPS 1.6/macOS 10.8@
3837 int /* O - 1 on success, 0 on failure */
3838 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3839 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3840 int element
, /* I - Value number (0-based) */
3841 const ipp_uchar_t
*datevalue
)/* I - dateTime value */
3843 _ipp_value_t
*value
; /* Current value */
3847 * Range check input...
3850 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3851 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3855 * Set the value and return...
3858 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3859 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3861 return (value
!= NULL
);
3866 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3868 * The @code ipp@ parameter refers to an IPP message previously created using
3869 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3871 * The @code attr@ parameter may be modified as a result of setting the value.
3873 * The @code group@ parameter specifies the IPP attribute group tag: none
3874 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3875 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3876 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3877 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3879 * @since CUPS 1.6/macOS 10.8@
3882 int /* O - 1 on success, 0 on failure */
3884 ipp_t
*ipp
, /* I - IPP message */
3885 ipp_attribute_t
**attr
, /* IO - Attribute */
3886 ipp_tag_t group_tag
) /* I - Group tag */
3889 * Range check input - group tag must be 0x01 to 0x0F, per RFC 8011...
3892 if (!ipp
|| !attr
|| !*attr
||
3893 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3894 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3898 * Set the group tag and return...
3901 (*attr
)->group_tag
= group_tag
;
3908 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3910 * The @code ipp@ parameter refers to an IPP message previously created using
3911 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3913 * The @code attr@ parameter may be modified as a result of setting the value.
3915 * The @code element@ parameter specifies which value to set from 0 to
3916 * @code ippGetCount(attr)@.
3918 * @since CUPS 1.6/macOS 10.8@
3921 int /* O - 1 on success, 0 on failure */
3922 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3923 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3924 int element
, /* I - Value number (0-based) */
3925 int intvalue
) /* I - Integer/enum value */
3927 _ipp_value_t
*value
; /* Current value */
3931 * Range check input...
3934 if (!ipp
|| !attr
|| !*attr
||
3935 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3936 element
< 0 || element
> (*attr
)->num_values
)
3940 * Set the value and return...
3943 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3944 value
->integer
= intvalue
;
3946 return (value
!= NULL
);
3951 * 'ippSetName()' - Set the name of an attribute.
3953 * The @code ipp@ parameter refers to an IPP message previously created using
3954 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3956 * The @code attr@ parameter may be modified as a result of setting the value.
3958 * @since CUPS 1.6/macOS 10.8@
3961 int /* O - 1 on success, 0 on failure */
3962 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3963 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3964 const char *name
) /* I - Attribute name */
3966 char *temp
; /* Temporary name value */
3970 * Range check input...
3973 if (!ipp
|| !attr
|| !*attr
)
3977 * Set the value and return...
3980 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3983 _cupsStrFree((*attr
)->name
);
3985 (*attr
)->name
= temp
;
3988 return (temp
!= NULL
);
3993 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
3995 * The @code ipp@ parameter refers to an IPP message previously created using
3996 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3998 * The @code attr@ parameter may be modified as a result of setting the value.
4000 * The @code element@ parameter specifies which value to set from 0 to
4001 * @code ippGetCount(attr)@.
4003 * @since CUPS 1.7/macOS 10.9@
4006 int /* O - 1 on success, 0 on failure */
4008 ipp_t
*ipp
, /* I - IPP message */
4009 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4010 int element
, /* I - Value number (0-based) */
4011 const void *data
, /* I - Pointer to octetString data */
4012 int datalen
) /* I - Length of octetString data */
4014 _ipp_value_t
*value
; /* Current value */
4018 * Range check input...
4021 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_STRING
||
4022 element
< 0 || element
> (*attr
)->num_values
||
4023 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
4027 * Set the value and return...
4030 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4032 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4035 * Just copy the pointer...
4038 value
->unknown
.data
= (void *)data
;
4039 value
->unknown
.length
= datalen
;
4047 if (value
->unknown
.data
)
4050 * Free previous data...
4053 free(value
->unknown
.data
);
4055 value
->unknown
.data
= NULL
;
4056 value
->unknown
.length
= 0;
4061 void *temp
; /* Temporary data pointer */
4063 if ((temp
= malloc((size_t)datalen
)) != NULL
)
4065 memcpy(temp
, data
, (size_t)datalen
);
4067 value
->unknown
.data
= temp
;
4068 value
->unknown
.length
= datalen
;
4076 return (value
!= NULL
);
4081 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
4083 * The @code ipp@ parameter refers to an IPP message previously created using
4084 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4086 * @since CUPS 1.6/macOS 10.8@
4089 int /* O - 1 on success, 0 on failure */
4090 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
4091 ipp_op_t op
) /* I - Operation ID */
4094 * Range check input...
4101 * Set the operation and return...
4104 ipp
->request
.op
.operation_id
= op
;
4111 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4113 * The @code ipp@ parameter refers to an IPP message previously created using
4114 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4116 * The @code attr@ parameter may be modified as a result of setting the value.
4118 * The @code element@ parameter specifies which value to set from 0 to
4119 * @code ippGetCount(attr)@.
4121 * @since CUPS 1.6/macOS 10.8@
4124 int /* O - 1 on success, 0 on failure */
4125 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4126 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4127 int element
, /* I - Value number (0-based) */
4128 int lowervalue
, /* I - Lower bound for range */
4129 int uppervalue
) /* I - Upper bound for range */
4131 _ipp_value_t
*value
; /* Current value */
4135 * Range check input...
4138 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4139 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4143 * Set the value and return...
4146 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4148 value
->range
.lower
= lowervalue
;
4149 value
->range
.upper
= uppervalue
;
4152 return (value
!= NULL
);
4157 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4159 * The @code ipp@ parameter refers to an IPP message previously created using
4160 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4162 * The @code request_id@ parameter must be greater than 0.
4164 * @since CUPS 1.6/macOS 10.8@
4167 int /* O - 1 on success, 0 on failure */
4168 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4169 int request_id
) /* I - Request ID */
4172 * Range check input; not checking request_id values since ipptool wants to send
4173 * invalid values for conformance testing and a bad request_id does not affect the
4174 * encoding of a message...
4181 * Set the request ID and return...
4184 ipp
->request
.any
.request_id
= request_id
;
4191 * 'ippSetResolution()' - Set a resolution value in an attribute.
4193 * The @code ipp@ parameter refers to an IPP message previously created using
4194 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4196 * The @code attr@ parameter may be modified as a result of setting the value.
4198 * The @code element@ parameter specifies which value to set from 0 to
4199 * @code ippGetCount(attr)@.
4201 * @since CUPS 1.6/macOS 10.8@
4204 int /* O - 1 on success, 0 on failure */
4206 ipp_t
*ipp
, /* I - IPP message */
4207 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4208 int element
, /* I - Value number (0-based) */
4209 ipp_res_t unitsvalue
, /* I - Resolution units */
4210 int xresvalue
, /* I - Horizontal/cross feed resolution */
4211 int yresvalue
) /* I - Vertical/feed resolution */
4213 _ipp_value_t
*value
; /* Current value */
4217 * Range check input...
4220 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4221 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4222 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4226 * Set the value and return...
4229 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4231 value
->resolution
.units
= unitsvalue
;
4232 value
->resolution
.xres
= xresvalue
;
4233 value
->resolution
.yres
= yresvalue
;
4236 return (value
!= NULL
);
4241 * 'ippSetState()' - Set the current state of the IPP message.
4243 * @since CUPS 1.6/macOS 10.8@
4246 int /* O - 1 on success, 0 on failure */
4247 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4248 ipp_state_t state
) /* I - IPP state value */
4251 * Range check input...
4258 * Set the state and return...
4262 ipp
->current
= NULL
;
4269 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4271 * The @code ipp@ parameter refers to an IPP message previously created using
4272 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4274 * @since CUPS 1.6/macOS 10.8@
4277 int /* O - 1 on success, 0 on failure */
4278 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4279 ipp_status_t status
) /* I - Status code */
4282 * Range check input...
4289 * Set the status code and return...
4292 ipp
->request
.status
.status_code
= status
;
4299 * 'ippSetString()' - Set a string value in an attribute.
4301 * The @code ipp@ parameter refers to an IPP message previously created using
4302 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4304 * The @code attr@ parameter may be modified as a result of setting the value.
4306 * The @code element@ parameter specifies which value to set from 0 to
4307 * @code ippGetCount(attr)@.
4309 * @since CUPS 1.6/macOS 10.8@
4312 int /* O - 1 on success, 0 on failure */
4313 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4314 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4315 int element
, /* I - Value number (0-based) */
4316 const char *strvalue
) /* I - String value */
4318 char *temp
; /* Temporary string */
4319 _ipp_value_t
*value
; /* Current value */
4320 ipp_tag_t value_tag
; /* Value tag */
4324 * Range check input...
4328 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4330 value_tag
= IPP_TAG_ZERO
;
4332 if (!ipp
|| !attr
|| !*attr
||
4333 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4334 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4339 * Set the value and return...
4342 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4345 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4347 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4348 value
->string
.text
= (char *)strvalue
;
4349 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4351 if (value
->string
.text
)
4352 _cupsStrFree(value
->string
.text
);
4354 value
->string
.text
= temp
;
4360 return (value
!= NULL
);
4365 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4367 * The @code ipp@ parameter refers to an IPP message previously created using
4368 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4370 * The @code attr@ parameter may be modified as a result of setting the value.
4372 * The @code element@ parameter specifies which value to set from 0 to
4373 * @code ippGetCount(attr)@.
4375 * The @code format@ parameter uses formatting characters compatible with the
4376 * printf family of standard functions. Additional arguments follow it as
4377 * needed. The formatted string is truncated as needed to the maximum length of
4378 * the corresponding value type.
4380 * @since CUPS 1.7/macOS 10.9@
4383 int /* O - 1 on success, 0 on failure */
4384 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4385 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4386 int element
, /* I - Value number (0-based) */
4387 const char *format
, /* I - Printf-style format string */
4388 ...) /* I - Additional arguments as needed */
4390 int ret
; /* Return value */
4391 va_list ap
; /* Pointer to additional arguments */
4394 va_start(ap
, format
);
4395 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4403 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4405 * The @code ipp@ parameter refers to an IPP message previously created using
4406 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4408 * The @code attr@ parameter may be modified as a result of setting the value.
4410 * The @code element@ parameter specifies which value to set from 0 to
4411 * @code ippGetCount(attr)@.
4413 * The @code format@ parameter uses formatting characters compatible with the
4414 * printf family of standard functions. Additional arguments follow it as
4415 * needed. The formatted string is truncated as needed to the maximum length of
4416 * the corresponding value type.
4418 * @since CUPS 1.7/macOS 10.9@
4421 int /* O - 1 on success, 0 on failure */
4422 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4423 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4424 int element
, /* I - Value number (0-based) */
4425 const char *format
, /* I - Printf-style format string */
4426 va_list ap
) /* I - Pointer to additional arguments */
4428 ipp_tag_t value_tag
; /* Value tag */
4429 char buffer
[IPP_MAX_TEXT
+ 4];
4430 /* Formatted text string */
4431 ssize_t bytes
, /* Length of formatted value */
4432 max_bytes
; /* Maximum number of bytes for value */
4436 * Range check input...
4440 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4442 value_tag
= IPP_TAG_ZERO
;
4444 if (!ipp
|| !attr
|| !*attr
||
4445 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4446 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4451 * Format the string...
4454 if (!strcmp(format
, "%s"))
4457 * Optimize the simple case...
4460 const char *s
= va_arg(ap
, char *);
4465 bytes
= (ssize_t
)strlen(s
);
4466 strlcpy(buffer
, s
, sizeof(buffer
));
4471 * Do a full formatting of the message...
4474 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4479 * Limit the length of the string...
4486 case IPP_TAG_TEXTLANG
:
4487 max_bytes
= IPP_MAX_TEXT
;
4491 case IPP_TAG_NAMELANG
:
4492 max_bytes
= IPP_MAX_NAME
;
4495 case IPP_TAG_CHARSET
:
4496 max_bytes
= IPP_MAX_CHARSET
;
4499 case IPP_TAG_KEYWORD
:
4500 max_bytes
= IPP_MAX_KEYWORD
;
4503 case IPP_TAG_LANGUAGE
:
4504 max_bytes
= IPP_MAX_LANGUAGE
;
4507 case IPP_TAG_MIMETYPE
:
4508 max_bytes
= IPP_MAX_MIMETYPE
;
4512 max_bytes
= IPP_MAX_URI
;
4515 case IPP_TAG_URISCHEME
:
4516 max_bytes
= IPP_MAX_URISCHEME
;
4520 if (bytes
>= max_bytes
)
4522 char *bufmax
, /* Buffer at max_bytes */
4523 *bufptr
; /* Pointer into buffer */
4525 bufptr
= buffer
+ strlen(buffer
) - 1;
4526 bufmax
= buffer
+ max_bytes
- 1;
4528 while (bufptr
> bufmax
)
4532 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4543 * Set the formatted string and return...
4546 return (ippSetString(ipp
, attr
, element
, buffer
));
4551 * 'ippSetValueTag()' - Set the value tag of an attribute.
4553 * The @code ipp@ parameter refers to an IPP message previously created using
4554 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4556 * The @code attr@ parameter may be modified as a result of setting the value.
4558 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4559 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4560 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4561 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4562 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4563 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4566 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4567 * code in the "attributes-natural-language" attribute or, if not present, the language
4568 * code for the current locale.
4570 * @since CUPS 1.6/macOS 10.8@
4573 int /* O - 1 on success, 0 on failure */
4575 ipp_t
*ipp
, /* I - IPP message */
4576 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4577 ipp_tag_t value_tag
) /* I - Value tag */
4579 int i
; /* Looping var */
4580 _ipp_value_t
*value
; /* Current value */
4581 int integer
; /* Current integer value */
4582 cups_lang_t
*language
; /* Current language */
4583 char code
[32]; /* Language code */
4584 ipp_tag_t temp_tag
; /* Temporary value tag */
4588 * Range check input...
4591 if (!ipp
|| !attr
|| !*attr
)
4595 * If there is no change, return immediately...
4598 if (value_tag
== (*attr
)->value_tag
)
4602 * Otherwise implement changes as needed...
4605 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4609 case IPP_TAG_UNSUPPORTED_VALUE
:
4610 case IPP_TAG_DEFAULT
:
4611 case IPP_TAG_UNKNOWN
:
4612 case IPP_TAG_NOVALUE
:
4613 case IPP_TAG_NOTSETTABLE
:
4614 case IPP_TAG_DELETEATTR
:
4615 case IPP_TAG_ADMINDEFINE
:
4617 * Free any existing values...
4620 if ((*attr
)->num_values
> 0)
4621 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4624 * Set out-of-band value...
4627 (*attr
)->value_tag
= value_tag
;
4630 case IPP_TAG_RANGE
:
4631 if (temp_tag
!= IPP_TAG_INTEGER
)
4634 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4638 integer
= value
->integer
;
4639 value
->range
.lower
= value
->range
.upper
= integer
;
4642 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4646 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4647 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4648 temp_tag
!= IPP_TAG_MIMETYPE
)
4651 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4654 case IPP_TAG_NAMELANG
:
4655 case IPP_TAG_TEXTLANG
:
4656 if (value_tag
== IPP_TAG_NAMELANG
&&
4657 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4658 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4659 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4662 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4665 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4666 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4669 * Use the language code from the IPP message...
4672 (*attr
)->values
[0].string
.language
=
4673 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4678 * Otherwise, use the language code corresponding to the locale...
4681 language
= cupsLangDefault();
4682 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4687 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4690 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4692 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4695 * Make copies of all values...
4698 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4701 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4704 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4707 case IPP_TAG_KEYWORD
:
4708 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4709 break; /* Silently "allow" name -> keyword */
4720 * 'ippSetVersion()' - Set the version number in an IPP message.
4722 * The @code ipp@ parameter refers to an IPP message previously created using
4723 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4725 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4727 * @since CUPS 1.6/macOS 10.8@
4730 int /* O - 1 on success, 0 on failure */
4731 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4732 int major
, /* I - Major version number (major.minor) */
4733 int minor
) /* I - Minor version number (major.minor) */
4736 * Range check input...
4739 if (!ipp
|| major
< 0 || minor
< 0)
4743 * Set the version number...
4746 ipp
->request
.any
.version
[0] = (ipp_uchar_t
)major
;
4747 ipp
->request
.any
.version
[1] = (ipp_uchar_t
)minor
;
4754 * 'ippTimeToDate()' - Convert from time in seconds to RFC 2579 format.
4757 const ipp_uchar_t
* /* O - RFC-2579 date/time data */
4758 ippTimeToDate(time_t t
) /* I - Time in seconds */
4760 struct tm
*unixdate
; /* UNIX unixdate/time info */
4761 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4762 /* RFC-2579 date/time data */
4766 * RFC-2579 date/time format is:
4768 * Byte(s) Description
4769 * ------- -----------
4770 * 0-1 Year (0 to 65535)
4774 * 5 Minutes (0 to 59)
4775 * 6 Seconds (0 to 60, 60 = "leap second")
4776 * 7 Deciseconds (0 to 9)
4778 * 9 UTC hours (0 to 11)
4779 * 10 UTC minutes (0 to 59)
4782 unixdate
= gmtime(&t
);
4783 unixdate
->tm_year
+= 1900;
4785 date
[0] = (ipp_uchar_t
)(unixdate
->tm_year
>> 8);
4786 date
[1] = (ipp_uchar_t
)(unixdate
->tm_year
);
4787 date
[2] = (ipp_uchar_t
)(unixdate
->tm_mon
+ 1);
4788 date
[3] = (ipp_uchar_t
)unixdate
->tm_mday
;
4789 date
[4] = (ipp_uchar_t
)unixdate
->tm_hour
;
4790 date
[5] = (ipp_uchar_t
)unixdate
->tm_min
;
4791 date
[6] = (ipp_uchar_t
)unixdate
->tm_sec
;
4802 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4804 * This function validates the contents of an attribute based on the name and
4805 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4806 * failure, @link cupsLastErrorString@ is set to a human-readable message.
4808 * @since CUPS 1.7/macOS 10.9@
4811 int /* O - 1 if valid, 0 otherwise */
4812 ippValidateAttribute(
4813 ipp_attribute_t
*attr
) /* I - Attribute */
4815 int i
; /* Looping var */
4816 char scheme
[64], /* Scheme from URI */
4817 userpass
[256], /* Username/password from URI */
4818 hostname
[256], /* Hostname from URI */
4819 resource
[1024]; /* Resource from URI */
4820 int port
, /* Port number from URI */
4821 uri_status
; /* URI separation status */
4822 const char *ptr
; /* Pointer into string */
4823 ipp_attribute_t
*colattr
; /* Collection attribute */
4824 regex_t re
; /* Regular expression */
4825 ipp_uchar_t
*date
; /* Current date value */
4836 * Validate the attribute name.
4839 for (ptr
= attr
->name
; *ptr
; ptr
++)
4840 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4843 if (*ptr
|| ptr
== attr
->name
)
4845 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4846 _("\"%s\": Bad attribute name - invalid character "
4847 "(RFC 8011 section 5.1.4)."), attr
->name
);
4851 if ((ptr
- attr
->name
) > 255)
4853 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4854 _("\"%s\": Bad attribute name - bad length %d "
4855 "(RFC 8011 section 5.1.4)."), attr
->name
,
4856 (int)(ptr
- attr
->name
));
4860 switch (attr
->value_tag
)
4862 case IPP_TAG_INTEGER
:
4865 case IPP_TAG_BOOLEAN
:
4866 for (i
= 0; i
< attr
->num_values
; i
++)
4868 if (attr
->values
[i
].boolean
!= 0 &&
4869 attr
->values
[i
].boolean
!= 1)
4871 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4872 _("\"%s\": Bad boolen value %d "
4873 "(RFC 8011 section 5.1.21)."), attr
->name
,
4874 attr
->values
[i
].boolean
);
4881 for (i
= 0; i
< attr
->num_values
; i
++)
4883 if (attr
->values
[i
].integer
< 1)
4885 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4886 _("\"%s\": Bad enum value %d - out of range "
4887 "(RFC 8011 section 5.1.5)."), attr
->name
,
4888 attr
->values
[i
].integer
);
4894 case IPP_TAG_STRING
:
4895 for (i
= 0; i
< attr
->num_values
; i
++)
4897 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4899 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4900 _("\"%s\": Bad octetString value - bad length %d "
4901 "(RFC 8011 section 5.1.20)."), attr
->name
,
4902 attr
->values
[i
].unknown
.length
);
4909 for (i
= 0; i
< attr
->num_values
; i
++)
4911 date
= attr
->values
[i
].date
;
4913 if (date
[2] < 1 || date
[2] > 12)
4915 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4916 _("\"%s\": Bad dateTime month %u "
4917 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[2]);
4921 if (date
[3] < 1 || date
[3] > 31)
4923 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4924 _("\"%s\": Bad dateTime day %u "
4925 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[3]);
4931 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4932 _("\"%s\": Bad dateTime hours %u "
4933 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[4]);
4939 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4940 _("\"%s\": Bad dateTime minutes %u "
4941 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[5]);
4947 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4948 _("\"%s\": Bad dateTime seconds %u "
4949 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[6]);
4955 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4956 _("\"%s\": Bad dateTime deciseconds %u "
4957 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[7]);
4961 if (date
[8] != '-' && date
[8] != '+')
4963 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4964 _("\"%s\": Bad dateTime UTC sign '%c' "
4965 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[8]);
4971 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4972 _("\"%s\": Bad dateTime UTC hours %u "
4973 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[9]);
4979 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4980 _("\"%s\": Bad dateTime UTC minutes %u "
4981 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[10]);
4987 case IPP_TAG_RESOLUTION
:
4988 for (i
= 0; i
< attr
->num_values
; i
++)
4990 if (attr
->values
[i
].resolution
.xres
<= 0)
4992 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4993 _("\"%s\": Bad resolution value %dx%d%s - cross "
4994 "feed resolution must be positive "
4995 "(RFC 8011 section 5.1.16)."), attr
->name
,
4996 attr
->values
[i
].resolution
.xres
,
4997 attr
->values
[i
].resolution
.yres
,
4998 attr
->values
[i
].resolution
.units
==
4999 IPP_RES_PER_INCH
? "dpi" :
5000 attr
->values
[i
].resolution
.units
==
5001 IPP_RES_PER_CM
? "dpcm" : "unknown");
5005 if (attr
->values
[i
].resolution
.yres
<= 0)
5007 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5008 _("\"%s\": Bad resolution value %dx%d%s - feed "
5009 "resolution must be positive "
5010 "(RFC 8011 section 5.1.16)."), attr
->name
,
5011 attr
->values
[i
].resolution
.xres
,
5012 attr
->values
[i
].resolution
.yres
,
5013 attr
->values
[i
].resolution
.units
==
5014 IPP_RES_PER_INCH
? "dpi" :
5015 attr
->values
[i
].resolution
.units
==
5016 IPP_RES_PER_CM
? "dpcm" : "unknown");
5020 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
5021 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
5023 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5024 _("\"%s\": Bad resolution value %dx%d%s - bad "
5025 "units value (RFC 8011 section 5.1.16)."),
5026 attr
->name
, attr
->values
[i
].resolution
.xres
,
5027 attr
->values
[i
].resolution
.yres
,
5028 attr
->values
[i
].resolution
.units
==
5029 IPP_RES_PER_INCH
? "dpi" :
5030 attr
->values
[i
].resolution
.units
==
5031 IPP_RES_PER_CM
? "dpcm" : "unknown");
5037 case IPP_TAG_RANGE
:
5038 for (i
= 0; i
< attr
->num_values
; i
++)
5040 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
5042 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5043 _("\"%s\": Bad rangeOfInteger value %d-%d - lower "
5044 "greater than upper (RFC 8011 section 5.1.14)."),
5045 attr
->name
, attr
->values
[i
].range
.lower
,
5046 attr
->values
[i
].range
.upper
);
5052 case IPP_TAG_BEGIN_COLLECTION
:
5053 for (i
= 0; i
< attr
->num_values
; i
++)
5055 for (colattr
= attr
->values
[i
].collection
->attrs
;
5057 colattr
= colattr
->next
)
5059 if (!ippValidateAttribute(colattr
))
5066 case IPP_TAG_TEXTLANG
:
5067 for (i
= 0; i
< attr
->num_values
; i
++)
5069 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5071 if ((*ptr
& 0xe0) == 0xc0)
5074 if ((*ptr
& 0xc0) != 0x80)
5077 else if ((*ptr
& 0xf0) == 0xe0)
5080 if ((*ptr
& 0xc0) != 0x80)
5083 if ((*ptr
& 0xc0) != 0x80)
5086 else if ((*ptr
& 0xf8) == 0xf0)
5089 if ((*ptr
& 0xc0) != 0x80)
5092 if ((*ptr
& 0xc0) != 0x80)
5095 if ((*ptr
& 0xc0) != 0x80)
5098 else if (*ptr
& 0x80)
5100 else if ((*ptr
< ' ' && *ptr
!= '\n' && *ptr
!= '\r' && *ptr
!= '\t') || *ptr
== 0x7f)
5104 if (*ptr
< ' ' || *ptr
== 0x7f)
5106 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad text value \"%s\" - bad control character (PWG 5100.14 section 8.3)."), attr
->name
, attr
->values
[i
].string
.text
);
5111 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad text value \"%s\" - bad UTF-8 sequence (RFC 8011 section 5.1.2)."), attr
->name
, attr
->values
[i
].string
.text
);
5115 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5117 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5118 _("\"%s\": Bad text value \"%s\" - bad length %d "
5119 "(RFC 8011 section 5.1.2)."), attr
->name
,
5120 attr
->values
[i
].string
.text
,
5121 (int)(ptr
- attr
->values
[i
].string
.text
));
5128 case IPP_TAG_NAMELANG
:
5129 for (i
= 0; i
< attr
->num_values
; i
++)
5131 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5133 if ((*ptr
& 0xe0) == 0xc0)
5136 if ((*ptr
& 0xc0) != 0x80)
5139 else if ((*ptr
& 0xf0) == 0xe0)
5142 if ((*ptr
& 0xc0) != 0x80)
5145 if ((*ptr
& 0xc0) != 0x80)
5148 else if ((*ptr
& 0xf8) == 0xf0)
5151 if ((*ptr
& 0xc0) != 0x80)
5154 if ((*ptr
& 0xc0) != 0x80)
5157 if ((*ptr
& 0xc0) != 0x80)
5160 else if (*ptr
& 0x80)
5162 else if (*ptr
< ' ' || *ptr
== 0x7f)
5166 if (*ptr
< ' ' || *ptr
== 0x7f)
5168 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad name value \"%s\" - bad control character (PWG 5100.14 section 8.1)."), attr
->name
, attr
->values
[i
].string
.text
);
5173 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad name value \"%s\" - bad UTF-8 sequence (RFC 8011 section 5.1.3)."), attr
->name
, attr
->values
[i
].string
.text
);
5177 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5179 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5180 _("\"%s\": Bad name value \"%s\" - bad length %d "
5181 "(RFC 8011 section 5.1.3)."), attr
->name
,
5182 attr
->values
[i
].string
.text
,
5183 (int)(ptr
- attr
->values
[i
].string
.text
));
5189 case IPP_TAG_KEYWORD
:
5190 for (i
= 0; i
< attr
->num_values
; i
++)
5192 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5193 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5197 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5199 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5200 _("\"%s\": Bad keyword value \"%s\" - invalid "
5201 "character (RFC 8011 section 5.1.4)."),
5202 attr
->name
, attr
->values
[i
].string
.text
);
5206 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5208 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5209 _("\"%s\": Bad keyword value \"%s\" - bad "
5210 "length %d (RFC 8011 section 5.1.4)."),
5211 attr
->name
, attr
->values
[i
].string
.text
,
5212 (int)(ptr
- attr
->values
[i
].string
.text
));
5219 for (i
= 0; i
< attr
->num_values
; i
++)
5221 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5222 attr
->values
[i
].string
.text
,
5223 scheme
, sizeof(scheme
),
5224 userpass
, sizeof(userpass
),
5225 hostname
, sizeof(hostname
),
5226 &port
, resource
, sizeof(resource
));
5228 if (uri_status
< HTTP_URI_STATUS_OK
)
5230 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad URI value \"%s\" - %s (RFC 8011 section 5.1.6)."), attr
->name
, attr
->values
[i
].string
.text
, httpURIStatusString(uri_status
));
5234 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5236 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5237 _("\"%s\": Bad URI value \"%s\" - bad length %d "
5238 "(RFC 8011 section 5.1.6)."), attr
->name
,
5239 attr
->values
[i
].string
.text
,
5240 (int)strlen(attr
->values
[i
].string
.text
));
5245 case IPP_TAG_URISCHEME
:
5246 for (i
= 0; i
< attr
->num_values
; i
++)
5248 ptr
= attr
->values
[i
].string
.text
;
5249 if (islower(*ptr
& 255))
5251 for (ptr
++; *ptr
; ptr
++)
5252 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5253 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5257 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5259 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5260 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5261 "characters (RFC 8011 section 5.1.7)."),
5262 attr
->name
, attr
->values
[i
].string
.text
);
5266 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5268 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5269 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5270 "length %d (RFC 8011 section 5.1.7)."),
5271 attr
->name
, attr
->values
[i
].string
.text
,
5272 (int)(ptr
- attr
->values
[i
].string
.text
));
5278 case IPP_TAG_CHARSET
:
5279 for (i
= 0; i
< attr
->num_values
; i
++)
5281 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5282 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5283 isspace(*ptr
& 255))
5286 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5288 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5289 _("\"%s\": Bad charset value \"%s\" - bad "
5290 "characters (RFC 8011 section 5.1.8)."),
5291 attr
->name
, attr
->values
[i
].string
.text
);
5295 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5297 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5298 _("\"%s\": Bad charset value \"%s\" - bad "
5299 "length %d (RFC 8011 section 5.1.8)."),
5300 attr
->name
, attr
->values
[i
].string
.text
,
5301 (int)(ptr
- attr
->values
[i
].string
.text
));
5307 case IPP_TAG_LANGUAGE
:
5309 * The following regular expression is derived from the ABNF for
5310 * language tags in RFC 4646. All I can say is that this is the
5311 * easiest way to check the values...
5314 if ((i
= regcomp(&re
,
5316 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5318 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5319 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5320 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5321 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5322 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5324 "x(-[a-z0-9]{1,8})+" /* privateuse */
5326 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5328 REG_NOSUB
| REG_EXTENDED
)) != 0)
5330 char temp
[256]; /* Temporary error string */
5332 regerror(i
, &re
, temp
, sizeof(temp
));
5333 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
,
5334 _("Unable to compile naturalLanguage regular "
5335 "expression: %s."), temp
);
5339 for (i
= 0; i
< attr
->num_values
; i
++)
5341 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5343 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5344 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5345 "characters (RFC 8011 section 5.1.9)."),
5346 attr
->name
, attr
->values
[i
].string
.text
);
5351 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5353 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5354 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5355 "length %d (RFC 8011 section 5.1.9)."),
5356 attr
->name
, attr
->values
[i
].string
.text
,
5357 (int)strlen(attr
->values
[i
].string
.text
));
5366 case IPP_TAG_MIMETYPE
:
5368 * The following regular expression is derived from the ABNF for
5369 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5370 * the easiest way to check the values...
5373 if ((i
= regcomp(&re
,
5375 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5377 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5378 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5379 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5382 REG_NOSUB
| REG_EXTENDED
)) != 0)
5384 char temp
[256]; /* Temporary error string */
5386 regerror(i
, &re
, temp
, sizeof(temp
));
5387 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5388 _("Unable to compile mimeMediaType regular "
5389 "expression: %s."), temp
);
5393 for (i
= 0; i
< attr
->num_values
; i
++)
5395 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5397 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5398 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5399 "characters (RFC 8011 section 5.1.10)."),
5400 attr
->name
, attr
->values
[i
].string
.text
);
5405 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5407 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5408 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5409 "length %d (RFC 8011 section 5.1.10)."),
5410 attr
->name
, attr
->values
[i
].string
.text
,
5411 (int)strlen(attr
->values
[i
].string
.text
));
5429 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5431 * This function validates the contents of the IPP message, including each
5432 * attribute. Like @link ippValidateAttribute@, @link cupsLastErrorString@ is
5433 * set to a human-readable message on failure.
5435 * @since CUPS 1.7/macOS 10.9@
5438 int /* O - 1 if valid, 0 otherwise */
5439 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5441 ipp_attribute_t
*attr
; /* Current attribute */
5447 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5448 if (!ippValidateAttribute(attr
))
5456 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5459 ipp_state_t
/* O - Current state */
5460 ippWrite(http_t
*http
, /* I - HTTP connection */
5461 ipp_t
*ipp
) /* I - IPP data */
5463 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http
, (void *)ipp
));
5466 return (IPP_STATE_ERROR
);
5468 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5473 * 'ippWriteFile()' - Write data for an IPP message to a file.
5475 * @since CUPS 1.1.19/macOS 10.3@
5478 ipp_state_t
/* O - Current state */
5479 ippWriteFile(int fd
, /* I - HTTP data */
5480 ipp_t
*ipp
) /* I - IPP data */
5482 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
5484 ipp
->state
= IPP_STATE_IDLE
;
5486 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5491 * 'ippWriteIO()' - Write data for an IPP message.
5493 * @since CUPS 1.2/macOS 10.5@
5496 ipp_state_t
/* O - Current state */
5497 ippWriteIO(void *dst
, /* I - Destination */
5498 ipp_iocb_t cb
, /* I - Write callback function */
5499 int blocking
, /* I - Use blocking IO? */
5500 ipp_t
*parent
, /* I - Parent IPP message */
5501 ipp_t
*ipp
) /* I - IPP data */
5503 int i
; /* Looping var */
5504 int n
; /* Length of data */
5505 unsigned char *buffer
, /* Data buffer */
5506 *bufptr
; /* Pointer into buffer */
5507 ipp_attribute_t
*attr
; /* Current attribute */
5508 _ipp_value_t
*value
; /* Current value */
5511 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
5514 return (IPP_STATE_ERROR
);
5516 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5518 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5519 return (IPP_STATE_ERROR
);
5524 case IPP_STATE_IDLE
:
5525 ipp
->state
++; /* Avoid common problem... */
5527 case IPP_STATE_HEADER
:
5531 * Send the request header:
5534 * Operation/Status Code = 2 bytes
5535 * Request ID = 4 bytes
5541 *bufptr
++ = ipp
->request
.any
.version
[0];
5542 *bufptr
++ = ipp
->request
.any
.version
[1];
5543 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.op_status
>> 8);
5544 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.op_status
;
5545 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 24);
5546 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 16);
5547 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 8);
5548 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.request_id
;
5550 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5551 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5552 ipp
->request
.any
.op_status
));
5553 DEBUG_printf(("2ippWriteIO: request_id=%d",
5554 ipp
->request
.any
.request_id
));
5556 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5558 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5559 _cupsBufferRelease((char *)buffer
);
5560 return (IPP_STATE_ERROR
);
5565 * Reset the state engine to point to the first attribute
5566 * in the request/response, with no current group.
5569 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5570 ipp
->current
= ipp
->attrs
;
5571 ipp
->curtag
= IPP_TAG_ZERO
;
5573 DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp
->current
));
5576 * If blocking is disabled, stop here...
5582 case IPP_STATE_ATTRIBUTE
:
5583 while (ipp
->current
!= NULL
)
5586 * Write this attribute...
5590 attr
= ipp
->current
;
5592 ipp
->current
= ipp
->current
->next
;
5596 if (ipp
->curtag
!= attr
->group_tag
)
5599 * Send a group tag byte...
5602 ipp
->curtag
= attr
->group_tag
;
5604 if (attr
->group_tag
== IPP_TAG_ZERO
)
5607 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5608 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5609 *bufptr
++ = (ipp_uchar_t
)attr
->group_tag
;
5611 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5615 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5616 attr
->num_values
> 1 ? "1setOf " : "",
5617 ippTagString(attr
->value_tag
)));
5620 * Write the attribute tag and name.
5622 * The attribute name length does not include the trailing nul
5623 * character in the source string.
5625 * Collection values (parent != NULL) are written differently...
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
- 8))
5637 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5638 _cupsBufferRelease((char *)buffer
);
5639 return (IPP_STATE_ERROR
);
5643 * Write the value tag, name length, and name string...
5646 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5647 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5648 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5651 if (attr
->value_tag
> 0xff)
5653 *bufptr
++ = IPP_TAG_EXTENSION
;
5654 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5655 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5656 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5657 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5660 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5662 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5663 *bufptr
++ = (ipp_uchar_t
)n
;
5664 memcpy(bufptr
, attr
->name
, (size_t)n
);
5670 * Get the length of the attribute name, and make sure it won't
5671 * overflow the buffer...
5674 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5676 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5677 _cupsBufferRelease((char *)buffer
);
5678 return (IPP_STATE_ERROR
);
5682 * Write the member name tag, name length, name string, value tag,
5683 * and empty name for the collection member attribute...
5686 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5687 IPP_TAG_MEMBERNAME
));
5688 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5690 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5691 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5692 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5694 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5697 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5698 *bufptr
++ = (ipp_uchar_t
)n
;
5699 memcpy(bufptr
, attr
->name
, (size_t)n
);
5702 if (attr
->value_tag
> 0xff)
5704 *bufptr
++ = IPP_TAG_EXTENSION
;
5705 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5706 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5707 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5708 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5711 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5718 * Now write the attribute value(s)...
5721 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5723 case IPP_TAG_UNSUPPORTED_VALUE
:
5724 case IPP_TAG_DEFAULT
:
5725 case IPP_TAG_UNKNOWN
:
5726 case IPP_TAG_NOVALUE
:
5727 case IPP_TAG_NOTSETTABLE
:
5728 case IPP_TAG_DELETEATTR
:
5729 case IPP_TAG_ADMINDEFINE
:
5734 case IPP_TAG_INTEGER
:
5736 for (i
= 0, value
= attr
->values
;
5737 i
< attr
->num_values
;
5740 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5742 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5744 DEBUG_puts("1ippWriteIO: Could not write IPP "
5746 _cupsBufferRelease((char *)buffer
);
5747 return (IPP_STATE_ERROR
);
5756 * Arrays and sets are done by sending additional
5757 * values with a zero-length name...
5760 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5766 * Integers and enumerations are both 4-byte signed
5767 * (twos-complement) values.
5769 * Put the 2-byte length and 4-byte value into the buffer...
5774 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 24);
5775 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 16);
5776 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 8);
5777 *bufptr
++ = (ipp_uchar_t
)value
->integer
;
5781 case IPP_TAG_BOOLEAN
:
5782 for (i
= 0, value
= attr
->values
;
5783 i
< attr
->num_values
;
5786 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5788 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5790 DEBUG_puts("1ippWriteIO: Could not write IPP "
5792 _cupsBufferRelease((char *)buffer
);
5793 return (IPP_STATE_ERROR
);
5802 * Arrays and sets are done by sending additional
5803 * values with a zero-length name...
5806 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5812 * Boolean values are 1-byte; 0 = false, 1 = true.
5814 * Put the 2-byte length and 1-byte value into the buffer...
5819 *bufptr
++ = (ipp_uchar_t
)value
->boolean
;
5825 case IPP_TAG_KEYWORD
:
5827 case IPP_TAG_URISCHEME
:
5828 case IPP_TAG_CHARSET
:
5829 case IPP_TAG_LANGUAGE
:
5830 case IPP_TAG_MIMETYPE
:
5831 for (i
= 0, value
= attr
->values
;
5832 i
< attr
->num_values
;
5838 * Arrays and sets are done by sending additional
5839 * values with a zero-length name...
5842 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5844 ippTagString(attr
->value_tag
)));
5845 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5847 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5849 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5851 DEBUG_puts("1ippWriteIO: Could not write IPP "
5853 _cupsBufferRelease((char *)buffer
);
5854 return (IPP_STATE_ERROR
);
5860 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5865 if (value
->string
.text
!= NULL
)
5866 n
= (int)strlen(value
->string
.text
);
5870 if (n
> (IPP_BUF_SIZE
- 2))
5872 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5873 _cupsBufferRelease((char *)buffer
);
5874 return (IPP_STATE_ERROR
);
5877 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5878 value
->string
.text
));
5880 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
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
);
5894 * All simple strings consist of the 2-byte length and
5895 * character data without the trailing nul normally found
5896 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5897 * bytes since the 2-byte length is a signed (twos-complement)
5900 * Put the 2-byte length and string characters in the buffer.
5903 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5904 *bufptr
++ = (ipp_uchar_t
)n
;
5908 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5915 for (i
= 0, value
= attr
->values
;
5916 i
< attr
->num_values
;
5919 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5921 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5923 DEBUG_puts("1ippWriteIO: Could not write IPP "
5925 _cupsBufferRelease((char *)buffer
);
5926 return (IPP_STATE_ERROR
);
5935 * Arrays and sets are done by sending additional
5936 * values with a zero-length name...
5939 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5945 * Date values consist of a 2-byte length and an
5946 * 11-byte date/time structure defined by RFC 1903.
5948 * Put the 2-byte length and 11-byte date/time
5949 * structure in the buffer.
5954 memcpy(bufptr
, value
->date
, 11);
5959 case IPP_TAG_RESOLUTION
:
5960 for (i
= 0, value
= attr
->values
;
5961 i
< attr
->num_values
;
5964 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5966 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5968 DEBUG_puts("1ippWriteIO: Could not write IPP "
5970 _cupsBufferRelease((char *)buffer
);
5971 return (IPP_STATE_ERROR
);
5980 * Arrays and sets are done by sending additional
5981 * values with a zero-length name...
5984 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5990 * Resolution values consist of a 2-byte length,
5991 * 4-byte horizontal resolution value, 4-byte vertical
5992 * resolution value, and a 1-byte units value.
5994 * Put the 2-byte length and resolution value data
6000 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 24);
6001 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 16);
6002 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 8);
6003 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.xres
;
6004 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 24);
6005 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 16);
6006 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 8);
6007 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.yres
;
6008 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.units
;
6012 case IPP_TAG_RANGE
:
6013 for (i
= 0, value
= attr
->values
;
6014 i
< attr
->num_values
;
6017 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
6019 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6021 DEBUG_puts("1ippWriteIO: Could not write IPP "
6023 _cupsBufferRelease((char *)buffer
);
6024 return (IPP_STATE_ERROR
);
6033 * Arrays and sets are done by sending additional
6034 * values with a zero-length name...
6037 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6043 * Range values consist of a 2-byte length,
6044 * 4-byte lower value, and 4-byte upper value.
6046 * Put the 2-byte length and range value data
6052 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 24);
6053 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 16);
6054 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 8);
6055 *bufptr
++ = (ipp_uchar_t
)value
->range
.lower
;
6056 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 24);
6057 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 16);
6058 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 8);
6059 *bufptr
++ = (ipp_uchar_t
)value
->range
.upper
;
6063 case IPP_TAG_TEXTLANG
:
6064 case IPP_TAG_NAMELANG
:
6065 for (i
= 0, value
= attr
->values
;
6066 i
< attr
->num_values
;
6072 * Arrays and sets are done by sending additional
6073 * values with a zero-length name...
6076 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6078 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6080 DEBUG_puts("1ippWriteIO: Could not write IPP "
6082 _cupsBufferRelease((char *)buffer
);
6083 return (IPP_STATE_ERROR
);
6089 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6095 * textWithLanguage and nameWithLanguage values consist
6096 * of a 2-byte length for both strings and their
6097 * individual lengths, a 2-byte length for the
6098 * character string, the character string without the
6099 * trailing nul, a 2-byte length for the character
6100 * set string, and the character set string without
6106 if (value
->string
.language
!= NULL
)
6107 n
+= (int)strlen(value
->string
.language
);
6109 if (value
->string
.text
!= NULL
)
6110 n
+= (int)strlen(value
->string
.text
);
6112 if (n
> (IPP_BUF_SIZE
- 2))
6114 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
6115 "too long (%d)", n
));
6116 _cupsBufferRelease((char *)buffer
);
6117 return (IPP_STATE_ERROR
);
6120 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6122 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6124 DEBUG_puts("1ippWriteIO: Could not write IPP "
6126 _cupsBufferRelease((char *)buffer
);
6127 return (IPP_STATE_ERROR
);
6133 /* Length of entire value */
6134 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6135 *bufptr
++ = (ipp_uchar_t
)n
;
6137 /* Length of language */
6138 if (value
->string
.language
!= NULL
)
6139 n
= (int)strlen(value
->string
.language
);
6143 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6144 *bufptr
++ = (ipp_uchar_t
)n
;
6149 memcpy(bufptr
, value
->string
.language
, (size_t)n
);
6153 /* Length of text */
6154 if (value
->string
.text
!= NULL
)
6155 n
= (int)strlen(value
->string
.text
);
6159 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6160 *bufptr
++ = (ipp_uchar_t
)n
;
6165 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
6171 case IPP_TAG_BEGIN_COLLECTION
:
6172 for (i
= 0, value
= attr
->values
;
6173 i
< attr
->num_values
;
6177 * Collections are written with the begin-collection
6178 * tag first with a value of 0 length, followed by the
6179 * attributes in the collection, then the end-collection
6183 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6185 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6187 DEBUG_puts("1ippWriteIO: Could not write IPP "
6189 _cupsBufferRelease((char *)buffer
);
6190 return (IPP_STATE_ERROR
);
6199 * Arrays and sets are done by sending additional
6200 * values with a zero-length name...
6203 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6209 * Write a data length of 0 and flush the buffer...
6215 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6217 DEBUG_puts("1ippWriteIO: Could not write IPP "
6219 _cupsBufferRelease((char *)buffer
);
6220 return (IPP_STATE_ERROR
);
6226 * Then write the collection attribute...
6229 value
->collection
->state
= IPP_STATE_IDLE
;
6231 if (ippWriteIO(dst
, cb
, 1, ipp
,
6232 value
->collection
) == IPP_STATE_ERROR
)
6234 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6235 _cupsBufferRelease((char *)buffer
);
6236 return (IPP_STATE_ERROR
);
6242 for (i
= 0, value
= attr
->values
;
6243 i
< attr
->num_values
;
6249 * Arrays and sets are done by sending additional
6250 * values with a zero-length name...
6253 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6255 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6257 DEBUG_puts("1ippWriteIO: Could not write IPP "
6259 _cupsBufferRelease((char *)buffer
);
6260 return (IPP_STATE_ERROR
);
6266 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6272 * An unknown value might some new value that a
6273 * vendor has come up with. It consists of a
6274 * 2-byte length and the bytes in the unknown
6278 n
= value
->unknown
.length
;
6280 if (n
> (IPP_BUF_SIZE
- 2))
6282 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6284 _cupsBufferRelease((char *)buffer
);
6285 return (IPP_STATE_ERROR
);
6288 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6290 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6292 DEBUG_puts("1ippWriteIO: Could not write IPP "
6294 _cupsBufferRelease((char *)buffer
);
6295 return (IPP_STATE_ERROR
);
6301 /* Length of unknown value */
6302 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6303 *bufptr
++ = (ipp_uchar_t
)n
;
6308 memcpy(bufptr
, value
->unknown
.data
, (size_t)n
);
6316 * Write the data out...
6319 if (bufptr
> buffer
)
6321 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6323 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6324 _cupsBufferRelease((char *)buffer
);
6325 return (IPP_STATE_ERROR
);
6328 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6329 (int)(bufptr
- buffer
)));
6333 * If blocking is disabled and we aren't at the end of the attribute
6334 * list, stop here...
6337 if (!blocking
&& ipp
->current
)
6341 if (ipp
->current
== NULL
)
6344 * Done with all of the attributes; add the end-of-attributes
6345 * tag or end-collection attribute...
6350 buffer
[0] = IPP_TAG_END
;
6355 buffer
[0] = IPP_TAG_END_COLLECTION
;
6356 buffer
[1] = 0; /* empty name */
6358 buffer
[3] = 0; /* empty value */
6363 if ((*cb
)(dst
, buffer
, (size_t)n
) < 0)
6365 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6366 _cupsBufferRelease((char *)buffer
);
6367 return (IPP_STATE_ERROR
);
6370 ipp
->state
= IPP_STATE_DATA
;
6374 case IPP_STATE_DATA
:
6378 break; /* anti-compiler-warning-code */
6381 _cupsBufferRelease((char *)buffer
);
6383 return (ipp
->state
);
6388 * 'ipp_add_attr()' - Add a new attribute to the message.
6391 static ipp_attribute_t
* /* O - New attribute */
6392 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6393 const char *name
, /* I - Attribute name or NULL */
6394 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6395 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6396 int num_values
) /* I - Number of values */
6398 int alloc_values
; /* Number of values to allocate */
6399 ipp_attribute_t
*attr
; /* New attribute */
6402 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
));
6405 * Range check input...
6408 if (!ipp
|| num_values
< 0)
6412 * Allocate memory, rounding the allocation up as needed...
6415 if (num_values
<= 1)
6418 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6420 attr
= calloc(sizeof(ipp_attribute_t
) +
6421 (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6426 * Initialize attribute...
6429 DEBUG_printf(("4debug_alloc: %p %s %s%s (%d values)", (void *)attr
, name
, num_values
> 1 ? "1setOf " : "", ippTagString(value_tag
), num_values
));
6432 attr
->name
= _cupsStrAlloc(name
);
6434 attr
->group_tag
= group_tag
;
6435 attr
->value_tag
= value_tag
;
6436 attr
->num_values
= num_values
;
6439 * Add it to the end of the linked list...
6443 ipp
->last
->next
= attr
;
6447 ipp
->prev
= ipp
->last
;
6448 ipp
->last
= ipp
->current
= attr
;
6451 DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr
));
6458 * 'ipp_free_values()' - Free attribute values.
6462 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6463 int element
,/* I - First value to free */
6464 int count
) /* I - Number of values to free */
6466 int i
; /* Looping var */
6467 _ipp_value_t
*value
; /* Current value */
6470 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", (void *)attr
, element
, count
));
6472 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6475 * Free values as needed...
6478 switch (attr
->value_tag
)
6480 case IPP_TAG_TEXTLANG
:
6481 case IPP_TAG_NAMELANG
:
6482 if (element
== 0 && count
== attr
->num_values
&&
6483 attr
->values
[0].string
.language
)
6485 _cupsStrFree(attr
->values
[0].string
.language
);
6486 attr
->values
[0].string
.language
= NULL
;
6488 /* Fall through to other string values */
6492 case IPP_TAG_RESERVED_STRING
:
6493 case IPP_TAG_KEYWORD
:
6495 case IPP_TAG_URISCHEME
:
6496 case IPP_TAG_CHARSET
:
6497 case IPP_TAG_LANGUAGE
:
6498 case IPP_TAG_MIMETYPE
:
6499 for (i
= count
, value
= attr
->values
+ element
;
6503 _cupsStrFree(value
->string
.text
);
6504 value
->string
.text
= NULL
;
6508 case IPP_TAG_UNSUPPORTED_VALUE
:
6509 case IPP_TAG_DEFAULT
:
6510 case IPP_TAG_UNKNOWN
:
6511 case IPP_TAG_NOVALUE
:
6512 case IPP_TAG_NOTSETTABLE
:
6513 case IPP_TAG_DELETEATTR
:
6514 case IPP_TAG_ADMINDEFINE
:
6515 case IPP_TAG_INTEGER
:
6517 case IPP_TAG_BOOLEAN
:
6519 case IPP_TAG_RESOLUTION
:
6520 case IPP_TAG_RANGE
:
6523 case IPP_TAG_BEGIN_COLLECTION
:
6524 for (i
= count
, value
= attr
->values
+ element
;
6528 ippDelete(value
->collection
);
6529 value
->collection
= NULL
;
6533 case IPP_TAG_STRING
:
6535 for (i
= count
, value
= attr
->values
+ element
;
6539 if (value
->unknown
.data
)
6541 free(value
->unknown
.data
);
6542 value
->unknown
.data
= NULL
;
6550 * If we are not freeing values from the end, move the remaining values up...
6553 if ((element
+ count
) < attr
->num_values
)
6554 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6555 (size_t)(attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6557 attr
->num_values
-= count
;
6562 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6564 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6565 * to "ll-cc", "ll-region", and "charset-number", respectively.
6568 static char * /* O - Language code string */
6569 ipp_get_code(const char *value
, /* I - Locale/charset string */
6570 char *buffer
, /* I - String buffer */
6571 size_t bufsize
) /* I - Size of string buffer */
6573 char *bufptr
, /* Pointer into buffer */
6574 *bufend
; /* End of buffer */
6578 * Convert values to lowercase and change _ to - as needed...
6581 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6582 *value
&& bufptr
< bufend
;
6587 *bufptr
++ = (char)_cups_tolower(*value
);
6592 * Return the converted string...
6600 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6602 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6603 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6606 static char * /* O - Language code string */
6607 ipp_lang_code(const char *locale
, /* I - Locale string */
6608 char *buffer
, /* I - String buffer */
6609 size_t bufsize
) /* I - Size of string buffer */
6612 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6615 if (!_cups_strcasecmp(locale
, "c"))
6617 strlcpy(buffer
, "en", bufsize
);
6621 return (ipp_get_code(locale
, buffer
, bufsize
));
6626 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6629 static size_t /* O - Size of IPP message */
6630 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6631 int collection
) /* I - 1 if a collection, 0 otherwise */
6633 int i
; /* Looping var */
6634 size_t bytes
; /* Number of bytes */
6635 ipp_attribute_t
*attr
; /* Current attribute */
6636 ipp_tag_t group
; /* Current group */
6637 _ipp_value_t
*value
; /* Current value */
6640 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp
, collection
));
6644 DEBUG_puts("4ipp_length: Returning 0 bytes");
6649 * Start with 8 bytes for the IPP message header...
6652 bytes
= collection
? 0 : 8;
6655 * Then add the lengths of each attribute...
6658 group
= IPP_TAG_ZERO
;
6660 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6662 if (attr
->group_tag
!= group
&& !collection
)
6664 group
= attr
->group_tag
;
6665 if (group
== IPP_TAG_ZERO
)
6668 bytes
++; /* Group tag */
6674 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6675 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6677 if ((attr
->value_tag
& ~IPP_TAG_CUPS_CONST
) < IPP_TAG_EXTENSION
)
6678 bytes
+= (size_t)attr
->num_values
;/* Value tag for each value */
6680 bytes
+= (size_t)(5 * attr
->num_values
);
6681 /* Value tag for each value */
6682 bytes
+= (size_t)(2 * attr
->num_values
);
6684 bytes
+= strlen(attr
->name
); /* Name */
6685 bytes
+= (size_t)(2 * attr
->num_values
);
6689 bytes
+= 5; /* Add membername overhead */
6691 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6693 case IPP_TAG_UNSUPPORTED_VALUE
:
6694 case IPP_TAG_DEFAULT
:
6695 case IPP_TAG_UNKNOWN
:
6696 case IPP_TAG_NOVALUE
:
6697 case IPP_TAG_NOTSETTABLE
:
6698 case IPP_TAG_DELETEATTR
:
6699 case IPP_TAG_ADMINDEFINE
:
6702 case IPP_TAG_INTEGER
:
6704 bytes
+= (size_t)(4 * attr
->num_values
);
6707 case IPP_TAG_BOOLEAN
:
6708 bytes
+= (size_t)attr
->num_values
;
6713 case IPP_TAG_KEYWORD
:
6715 case IPP_TAG_URISCHEME
:
6716 case IPP_TAG_CHARSET
:
6717 case IPP_TAG_LANGUAGE
:
6718 case IPP_TAG_MIMETYPE
:
6719 for (i
= 0, value
= attr
->values
;
6720 i
< attr
->num_values
;
6722 if (value
->string
.text
)
6723 bytes
+= strlen(value
->string
.text
);
6727 bytes
+= (size_t)(11 * attr
->num_values
);
6730 case IPP_TAG_RESOLUTION
:
6731 bytes
+= (size_t)(9 * attr
->num_values
);
6734 case IPP_TAG_RANGE
:
6735 bytes
+= (size_t)(8 * attr
->num_values
);
6738 case IPP_TAG_TEXTLANG
:
6739 case IPP_TAG_NAMELANG
:
6740 bytes
+= (size_t)(4 * attr
->num_values
);
6741 /* Charset + text length */
6743 for (i
= 0, value
= attr
->values
;
6744 i
< attr
->num_values
;
6747 if (value
->string
.language
)
6748 bytes
+= strlen(value
->string
.language
);
6750 if (value
->string
.text
)
6751 bytes
+= strlen(value
->string
.text
);
6755 case IPP_TAG_BEGIN_COLLECTION
:
6756 for (i
= 0, value
= attr
->values
;
6757 i
< attr
->num_values
;
6759 bytes
+= ipp_length(value
->collection
, 1);
6763 for (i
= 0, value
= attr
->values
;
6764 i
< attr
->num_values
;
6766 bytes
+= (size_t)value
->unknown
.length
;
6772 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6773 * for the "end of collection" tag and return...
6781 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6788 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6791 static ssize_t
/* O - Number of bytes read */
6792 ipp_read_http(http_t
*http
, /* I - Client connection */
6793 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6794 size_t length
) /* I - Total length */
6796 ssize_t tbytes
, /* Total bytes read */
6797 bytes
; /* Bytes read this pass */
6800 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http
, (void *)buffer
, (int)length
));
6803 * Loop until all bytes are read...
6806 for (tbytes
= 0, bytes
= 0;
6807 tbytes
< (int)length
;
6808 tbytes
+= bytes
, buffer
+= bytes
)
6810 DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT
", http->state=%d", CUPS_LLCAST tbytes
, http
->state
));
6812 if (http
->state
== HTTP_STATE_WAITING
)
6815 if (http
->used
== 0 && !http
->blocking
)
6818 * Wait up to 10 seconds for more data on non-blocking sockets...
6821 if (!httpWait(http
, 10000))
6831 else if (http
->used
== 0 && http
->timeout_value
> 0)
6834 * Wait up to timeout seconds for more data on blocking sockets...
6837 if (!httpWait(http
, (int)(1000 * http
->timeout_value
)))
6848 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- (size_t)tbytes
)) < 0)
6853 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6859 else if (bytes
== 0)
6864 * Return the number of bytes read...
6867 if (tbytes
== 0 && bytes
< 0)
6870 DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST tbytes
));
6877 * 'ipp_read_file()' - Read IPP data from a file.
6880 static ssize_t
/* O - Number of bytes read */
6881 ipp_read_file(int *fd
, /* I - File descriptor */
6882 ipp_uchar_t
*buffer
, /* O - Read buffer */
6883 size_t length
) /* I - Number of bytes to read */
6886 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6888 return (read(*fd
, buffer
, length
));
6894 * 'ipp_set_error()' - Set a formatted, localized error string.
6898 ipp_set_error(ipp_status_t status
, /* I - Status code */
6899 const char *format
, /* I - Printf-style error string */
6900 ...) /* I - Additional arguments as needed */
6902 va_list ap
; /* Pointer to additional args */
6903 char buffer
[2048]; /* Message buffer */
6904 cups_lang_t
*lang
= cupsLangDefault();
6905 /* Current language */
6908 va_start(ap
, format
);
6909 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6912 _cupsSetError(status
, buffer
, 0);
6917 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6921 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6922 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6923 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6924 int element
) /* I - Value number (0-based) */
6926 ipp_attribute_t
*temp
, /* New attribute pointer */
6927 *current
, /* Current attribute in list */
6928 *prev
; /* Previous attribute in list */
6929 int alloc_values
; /* Allocated values */
6933 * If we are setting an existing value element, return it...
6938 if (temp
->num_values
<= 1)
6941 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6942 ~(IPP_MAX_VALUES
- 1);
6944 if (element
< alloc_values
)
6946 if (element
>= temp
->num_values
)
6947 temp
->num_values
= element
+ 1;
6949 return (temp
->values
+ element
);
6953 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6954 * values when num_values > 1.
6957 if (alloc_values
< IPP_MAX_VALUES
)
6958 alloc_values
= IPP_MAX_VALUES
;
6960 alloc_values
+= IPP_MAX_VALUES
;
6962 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6966 * Reallocate memory...
6969 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) + (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6971 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6972 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6977 * Zero the new memory...
6980 memset(temp
->values
+ temp
->num_values
, 0, (size_t)(alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6985 * Reset pointers in the list...
6988 DEBUG_printf(("4debug_free: %p %s", (void *)*attr
, temp
->name
));
6989 DEBUG_printf(("4debug_alloc: %p %s %s%s (%d)", (void *)temp
, temp
->name
, temp
->num_values
> 1 ? "1setOf " : "", ippTagString(temp
->value_tag
), temp
->num_values
));
6991 if (ipp
->current
== *attr
&& ipp
->prev
)
6994 * Use current "previous" pointer...
7002 * Find this attribute in the linked list...
7005 for (prev
= NULL
, current
= ipp
->attrs
;
7006 current
&& current
!= *attr
;
7007 prev
= current
, current
= current
->next
);
7012 * This is a serious error!
7016 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
7017 _("IPP attribute is not a member of the message."), 1);
7018 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
7028 ipp
->current
= temp
;
7031 if (ipp
->last
== *attr
)
7038 * Return the value element...
7041 if (element
>= temp
->num_values
)
7042 temp
->num_values
= element
+ 1;
7044 return (temp
->values
+ element
);
7049 * 'ipp_write_file()' - Write IPP data to a file.
7052 static ssize_t
/* O - Number of bytes written */
7053 ipp_write_file(int *fd
, /* I - File descriptor */
7054 ipp_uchar_t
*buffer
, /* I - Data to write */
7055 size_t length
) /* I - Number of bytes to write */
7058 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
7060 return (write(*fd
, buffer
, length
));