2 * Internet Printing Protocol functions for CUPS.
4 * Copyright 2007-2017 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_INTEGER
:
1514 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1515 srcattr
->name
, srcattr
->num_values
, NULL
);
1519 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1521 i
--, srcval
++, dstval
++)
1522 dstval
->integer
= srcval
->integer
;
1525 case IPP_TAG_BOOLEAN
:
1526 dstattr
= ippAddBooleans(dst
, srcattr
->group_tag
, srcattr
->name
,
1527 srcattr
->num_values
, NULL
);
1531 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1533 i
--, srcval
++, dstval
++)
1534 dstval
->boolean
= srcval
->boolean
;
1539 case IPP_TAG_KEYWORD
:
1541 case IPP_TAG_URISCHEME
:
1542 case IPP_TAG_CHARSET
:
1543 case IPP_TAG_LANGUAGE
:
1544 case IPP_TAG_MIMETYPE
:
1545 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1546 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1547 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1553 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1554 dstval
= dstattr
->values
;
1556 i
--, srcval
++, dstval
++)
1557 dstval
->string
.text
= srcval
->string
.text
;
1559 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1561 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1562 dstval
= dstattr
->values
;
1564 i
--, srcval
++, dstval
++)
1565 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1569 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1570 dstval
= dstattr
->values
;
1572 i
--, srcval
++, dstval
++)
1573 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1578 if (srcattr
->num_values
!= 1)
1581 dstattr
= ippAddDate(dst
, srcattr
->group_tag
, srcattr
->name
,
1582 srcattr
->values
[0].date
);
1585 case IPP_TAG_RESOLUTION
:
1586 dstattr
= ippAddResolutions(dst
, srcattr
->group_tag
, srcattr
->name
,
1587 srcattr
->num_values
, IPP_RES_PER_INCH
,
1592 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1594 i
--, srcval
++, dstval
++)
1596 dstval
->resolution
.xres
= srcval
->resolution
.xres
;
1597 dstval
->resolution
.yres
= srcval
->resolution
.yres
;
1598 dstval
->resolution
.units
= srcval
->resolution
.units
;
1602 case IPP_TAG_RANGE
:
1603 dstattr
= ippAddRanges(dst
, srcattr
->group_tag
, srcattr
->name
,
1604 srcattr
->num_values
, NULL
, NULL
);
1608 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1610 i
--, srcval
++, dstval
++)
1612 dstval
->range
.lower
= srcval
->range
.lower
;
1613 dstval
->range
.upper
= srcval
->range
.upper
;
1617 case IPP_TAG_TEXTLANG
:
1618 case IPP_TAG_NAMELANG
:
1619 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1620 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1621 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1627 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1628 dstval
= dstattr
->values
;
1630 i
--, srcval
++, dstval
++)
1632 dstval
->string
.language
= srcval
->string
.language
;
1633 dstval
->string
.text
= srcval
->string
.text
;
1636 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1638 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1639 dstval
= dstattr
->values
;
1641 i
--, srcval
++, dstval
++)
1643 if (srcval
== srcattr
->values
)
1644 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1646 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1648 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1653 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1654 dstval
= dstattr
->values
;
1656 i
--, srcval
++, dstval
++)
1658 if (srcval
== srcattr
->values
)
1659 dstval
->string
.language
= _cupsStrRetain(srcval
->string
.language
);
1661 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1663 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1668 case IPP_TAG_BEGIN_COLLECTION
:
1669 dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
,
1670 srcattr
->num_values
, NULL
);
1674 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1676 i
--, srcval
++, dstval
++)
1678 dstval
->collection
= srcval
->collection
;
1679 srcval
->collection
->use
++;
1683 case IPP_TAG_STRING
:
1685 /* TODO: Implement quick copy for unknown/octetString values */
1686 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1687 srcattr
->name
, srcattr
->num_values
, NULL
);
1691 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1693 i
--, srcval
++, dstval
++)
1695 dstval
->unknown
.length
= srcval
->unknown
.length
;
1697 if (dstval
->unknown
.length
> 0)
1699 if ((dstval
->unknown
.data
= malloc((size_t)dstval
->unknown
.length
)) == NULL
)
1700 dstval
->unknown
.length
= 0;
1702 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, (size_t)dstval
->unknown
.length
);
1705 break; /* anti-compiler-warning-code */
1713 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1715 * Zero or more attributes are copied from the source IPP message, @code src@, to the
1716 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1717 * reference copy of the attribute is created - this should only be done as long as the
1718 * original source IPP message will not be freed for the life of the destination.
1720 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1721 * attributes that are copied - the function must return 1 to copy the attribute or
1722 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1725 * @since CUPS 1.6/macOS 10.8@
1728 int /* O - 1 on success, 0 on error */
1730 ipp_t
*dst
, /* I - Destination IPP message */
1731 ipp_t
*src
, /* I - Source IPP message */
1732 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1733 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1734 void *context
) /* I - Context pointer */
1736 ipp_attribute_t
*srcattr
; /* Source attribute */
1739 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)", (void *)dst
, (void *)src
, quickcopy
, (void *)cb
, context
));
1742 * Range check input...
1749 * Loop through source attributes and copy as needed...
1752 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1753 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1754 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1762 * 'ippDateToTime()' - Convert from RFC 2579 Date/Time format to time in
1766 time_t /* O - UNIX time value */
1767 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 2579 date info */
1769 struct tm unixdate
; /* UNIX date/time info */
1770 time_t t
; /* Computed time */
1776 memset(&unixdate
, 0, sizeof(unixdate
));
1779 * RFC-2579 date/time format is:
1781 * Byte(s) Description
1782 * ------- -----------
1783 * 0-1 Year (0 to 65535)
1787 * 5 Minutes (0 to 59)
1788 * 6 Seconds (0 to 60, 60 = "leap second")
1789 * 7 Deciseconds (0 to 9)
1791 * 9 UTC hours (0 to 11)
1792 * 10 UTC minutes (0 to 59)
1795 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1796 unixdate
.tm_mon
= date
[2] - 1;
1797 unixdate
.tm_mday
= date
[3];
1798 unixdate
.tm_hour
= date
[4];
1799 unixdate
.tm_min
= date
[5];
1800 unixdate
.tm_sec
= date
[6];
1802 t
= mktime(&unixdate
);
1805 t
+= date
[9] * 3600 + date
[10] * 60;
1807 t
-= date
[9] * 3600 + date
[10] * 60;
1814 * 'ippDelete()' - Delete an IPP message.
1818 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1820 ipp_attribute_t
*attr
, /* Current attribute */
1821 *next
; /* Next attribute */
1824 DEBUG_printf(("ippDelete(ipp=%p)", (void *)ipp
));
1833 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1837 ipp_free_values(attr
, 0, attr
->num_values
);
1840 _cupsStrFree(attr
->name
);
1850 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1852 * @since CUPS 1.1.19/macOS 10.3@
1857 ipp_t
*ipp
, /* I - IPP message */
1858 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1860 ipp_attribute_t
*current
, /* Current attribute */
1861 *prev
; /* Previous attribute */
1864 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", (void *)ipp
, (void *)attr
, attr
? attr
->name
: "(null)"));
1867 * Range check input...
1874 * Find the attribute in the list...
1879 for (current
= ipp
->attrs
, prev
= NULL
;
1881 prev
= current
, current
= current
->next
)
1882 if (current
== attr
)
1885 * Found it, remove the attribute from the list...
1889 prev
->next
= current
->next
;
1891 ipp
->attrs
= current
->next
;
1893 if (current
== ipp
->last
)
1904 * Free memory used by the attribute...
1907 ipp_free_values(attr
, 0, attr
->num_values
);
1910 _cupsStrFree(attr
->name
);
1917 * 'ippDeleteValues()' - Delete values in an attribute.
1919 * The @code element@ parameter specifies the first value to delete, starting at
1920 * 0. It must be less than the number of values returned by @link ippGetCount@.
1922 * The @code attr@ parameter may be modified as a result of setting the value.
1924 * Deleting all values in an attribute deletes the attribute.
1926 * @since CUPS 1.6/macOS 10.8@
1929 int /* O - 1 on success, 0 on failure */
1931 ipp_t
*ipp
, /* I - IPP message */
1932 ipp_attribute_t
**attr
, /* IO - Attribute */
1933 int element
, /* I - Index of first value to delete (0-based) */
1934 int count
) /* I - Number of values to delete */
1937 * Range check input...
1940 if (!ipp
|| !attr
|| !*attr
||
1941 element
< 0 || element
>= (*attr
)->num_values
|| count
<= 0 ||
1942 (element
+ count
) >= (*attr
)->num_values
)
1946 * If we are deleting all values, just delete the attribute entirely.
1949 if (count
== (*attr
)->num_values
)
1951 ippDeleteAttribute(ipp
, *attr
);
1957 * Otherwise free the values in question and return.
1960 ipp_free_values(*attr
, element
, count
);
1967 * 'ippFindAttribute()' - Find a named attribute in a request.
1969 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1970 * of attribute and member names separated by slashes, for example
1971 * "media-col/media-size".
1974 ipp_attribute_t
* /* O - Matching attribute */
1975 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
1976 const char *name
, /* I - Name of attribute */
1977 ipp_tag_t type
) /* I - Type of attribute */
1979 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
1985 * Reset the current pointer...
1988 ipp
->current
= NULL
;
1992 * Search for the attribute...
1995 return (ippFindNextAttribute(ipp
, name
, type
));
2000 * 'ippFindNextAttribute()' - Find the next named attribute in a request.
2002 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
2003 * of attribute and member names separated by slashes, for example
2004 * "media-col/media-size".
2007 ipp_attribute_t
* /* O - Matching attribute */
2008 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
2009 const char *name
, /* I - Name of attribute */
2010 ipp_tag_t type
) /* I - Type of attribute */
2012 ipp_attribute_t
*attr
, /* Current atttribute */
2013 *childattr
; /* Child attribute */
2014 ipp_tag_t value_tag
; /* Value tag */
2015 char parent
[1024], /* Parent attribute name */
2016 *child
= NULL
; /* Child attribute name */
2019 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
2024 DEBUG_printf(("3ippFindNextAttribute: atend=%d", ipp
->atend
));
2029 if (strchr(name
, '/'))
2032 * Search for child attribute...
2035 strlcpy(parent
, name
, sizeof(parent
));
2036 if ((child
= strchr(parent
, '/')) == NULL
)
2038 DEBUG_puts("3ippFindNextAttribute: Attribute name too long.");
2044 if (ipp
->current
&& ipp
->current
->name
&& ipp
->current
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&& !strcmp(parent
, ipp
->current
->name
))
2046 while (ipp
->curindex
< ipp
->current
->num_values
)
2048 if ((childattr
= ippFindNextAttribute(ipp
->current
->values
[ipp
->curindex
].collection
, child
, type
)) != NULL
)
2052 if (ipp
->curindex
< ipp
->current
->num_values
&& ipp
->current
->values
[ipp
->curindex
].collection
)
2053 ipp
->current
->values
[ipp
->curindex
].collection
->current
= NULL
;
2056 ipp
->prev
= ipp
->current
;
2057 ipp
->current
= ipp
->current
->next
;
2070 ipp
->current
= ipp
->attrs
;
2075 attr
= ipp
->current
;
2077 else if (ipp
->current
)
2079 ipp
->prev
= ipp
->current
;
2080 attr
= ipp
->current
->next
;
2088 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
2090 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", (void *)attr
, attr
->name
));
2092 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2094 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
2095 (value_tag
== type
|| type
== IPP_TAG_ZERO
|| name
== parent
||
2096 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
2097 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
2099 ipp
->current
= attr
;
2101 if (name
== parent
&& attr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
)
2103 int i
; /* Looping var */
2105 for (i
= 0; i
< attr
->num_values
; i
++)
2107 if ((childattr
= ippFindAttribute(attr
->values
[i
].collection
, child
, type
)) != NULL
)
2109 attr
->values
[0].collection
->curindex
= i
;
2119 ipp
->current
= NULL
;
2128 * 'ippFirstAttribute()' - Return the first attribute in the message.
2130 * @since CUPS 1.6/macOS 10.8@
2133 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
2134 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
2137 * Range check input...
2144 * Return the first attribute...
2147 return (ipp
->current
= ipp
->attrs
);
2152 * 'ippGetBoolean()' - Get a boolean value for an attribute.
2154 * The @code element@ parameter specifies which value to get from 0 to
2155 * @code ippGetCount(attr)@ - 1.
2157 * @since CUPS 1.6/macOS 10.8@
2160 int /* O - Boolean value or 0 on error */
2161 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
2162 int element
) /* I - Value number (0-based) */
2165 * Range check input...
2168 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
2169 element
< 0 || element
>= attr
->num_values
)
2173 * Return the value...
2176 return (attr
->values
[element
].boolean
);
2181 * 'ippGetCollection()' - Get a collection value for an attribute.
2183 * The @code element@ parameter specifies which value to get from 0 to
2184 * @code ippGetCount(attr)@ - 1.
2186 * @since CUPS 1.6/macOS 10.8@
2189 ipp_t
* /* O - Collection value or @code NULL@ on error */
2191 ipp_attribute_t
*attr
, /* I - IPP attribute */
2192 int element
) /* I - Value number (0-based) */
2195 * Range check input...
2198 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
2199 element
< 0 || element
>= attr
->num_values
)
2203 * Return the value...
2206 return (attr
->values
[element
].collection
);
2211 * 'ippGetCount()' - Get the number of values in an attribute.
2213 * @since CUPS 1.6/macOS 10.8@
2216 int /* O - Number of values or 0 on error */
2217 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
2220 * Range check input...
2227 * Return the number of values...
2230 return (attr
->num_values
);
2235 * 'ippGetDate()' - Get a dateTime value for an attribute.
2237 * The @code element@ parameter specifies which value to get from 0 to
2238 * @code ippGetCount(attr)@ - 1.
2240 * @since CUPS 1.6/macOS 10.8@
2243 const ipp_uchar_t
* /* O - dateTime value or @code NULL@ */
2244 ippGetDate(ipp_attribute_t
*attr
, /* I - IPP attribute */
2245 int element
) /* I - Value number (0-based) */
2248 * Range check input...
2251 if (!attr
|| attr
->value_tag
!= IPP_TAG_DATE
||
2252 element
< 0 || element
>= attr
->num_values
)
2256 * Return the value...
2259 return (attr
->values
[element
].date
);
2264 * 'ippGetGroupTag()' - Get the group associated with an attribute.
2266 * @since CUPS 1.6/macOS 10.8@
2269 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
2270 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2273 * Range check input...
2277 return (IPP_TAG_ZERO
);
2280 * Return the group...
2283 return (attr
->group_tag
);
2288 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
2290 * The @code element@ parameter specifies which value to get from 0 to
2291 * @code ippGetCount(attr)@ - 1.
2293 * @since CUPS 1.6/macOS 10.8@
2296 int /* O - Value or 0 on error */
2297 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
2298 int element
) /* I - Value number (0-based) */
2301 * Range check input...
2304 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
2305 element
< 0 || element
>= attr
->num_values
)
2309 * Return the value...
2312 return (attr
->values
[element
].integer
);
2317 * 'ippGetName()' - Get the attribute name.
2319 * @since CUPS 1.6/macOS 10.8@
2322 const char * /* O - Attribute name or @code NULL@ for separators */
2323 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
2326 * Range check input...
2333 * Return the name...
2336 return (attr
->name
);
2341 * 'ippGetOctetString()' - Get an octetString value from an IPP attribute.
2343 * The @code element@ parameter specifies which value to get from 0 to
2344 * @code ippGetCount(attr)@ - 1.
2346 * @since CUPS 1.7/macOS 10.9@
2349 void * /* O - Pointer to octetString data */
2351 ipp_attribute_t
*attr
, /* I - IPP attribute */
2352 int element
, /* I - Value number (0-based) */
2353 int *datalen
) /* O - Length of octetString data */
2356 * Range check input...
2359 if (!attr
|| attr
->value_tag
!= IPP_TAG_STRING
||
2360 element
< 0 || element
>= attr
->num_values
)
2369 * Return the values...
2373 *datalen
= attr
->values
[element
].unknown
.length
;
2375 return (attr
->values
[element
].unknown
.data
);
2380 * 'ippGetOperation()' - Get the operation ID in an IPP message.
2382 * @since CUPS 1.6/macOS 10.8@
2385 ipp_op_t
/* O - Operation ID or 0 on error */
2386 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
2389 * Range check input...
2393 return ((ipp_op_t
)0);
2396 * Return the value...
2399 return (ipp
->request
.op
.operation_id
);
2404 * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
2406 * The @code element@ parameter specifies which value to get from 0 to
2407 * @code ippGetCount(attr)@ - 1.
2409 * @since CUPS 1.6/macOS 10.8@
2412 int /* O - Lower value of range or 0 */
2413 ippGetRange(ipp_attribute_t
*attr
, /* I - IPP attribute */
2414 int element
, /* I - Value number (0-based) */
2415 int *uppervalue
)/* O - Upper value of range */
2418 * Range check input...
2421 if (!attr
|| attr
->value_tag
!= IPP_TAG_RANGE
||
2422 element
< 0 || element
>= attr
->num_values
)
2431 * Return the values...
2435 *uppervalue
= attr
->values
[element
].range
.upper
;
2437 return (attr
->values
[element
].range
.lower
);
2442 * 'ippGetRequestId()' - Get the request ID from an IPP message.
2444 * @since CUPS 1.6/macOS 10.8@
2447 int /* O - Request ID or 0 on error */
2448 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
2451 * Range check input...
2458 * Return the request ID...
2461 return (ipp
->request
.any
.request_id
);
2466 * 'ippGetResolution()' - Get a resolution value for an attribute.
2468 * The @code element@ parameter specifies which value to get from 0 to
2469 * @code ippGetCount(attr)@ - 1.
2471 * @since CUPS 1.6/macOS 10.8@
2474 int /* O - Horizontal/cross feed resolution or 0 */
2476 ipp_attribute_t
*attr
, /* I - IPP attribute */
2477 int element
, /* I - Value number (0-based) */
2478 int *yres
, /* O - Vertical/feed resolution */
2479 ipp_res_t
*units
) /* O - Units for resolution */
2482 * Range check input...
2485 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
2486 element
< 0 || element
>= attr
->num_values
)
2492 *units
= (ipp_res_t
)0;
2498 * Return the value...
2502 *yres
= attr
->values
[element
].resolution
.yres
;
2505 *units
= attr
->values
[element
].resolution
.units
;
2507 return (attr
->values
[element
].resolution
.xres
);
2512 * 'ippGetState()' - Get the IPP message state.
2514 * @since CUPS 1.6/macOS 10.8@
2517 ipp_state_t
/* O - IPP message state value */
2518 ippGetState(ipp_t
*ipp
) /* I - IPP message */
2521 * Range check input...
2525 return (IPP_STATE_IDLE
);
2528 * Return the value...
2531 return (ipp
->state
);
2536 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2538 * @since CUPS 1.6/macOS 10.8@
2541 ipp_status_t
/* O - Status code in IPP message */
2542 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2545 * Range check input...
2549 return (IPP_STATUS_ERROR_INTERNAL
);
2552 * Return the value...
2555 return (ipp
->request
.status
.status_code
);
2560 * 'ippGetString()' - Get the string and optionally the language code for an attribute.
2562 * The @code element@ parameter specifies which value to get from 0 to
2563 * @code ippGetCount(attr)@ - 1.
2565 * @since CUPS 1.6/macOS 10.8@
2569 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2570 int element
, /* I - Value number (0-based) */
2571 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2573 ipp_tag_t tag
; /* Value tag */
2577 * Range check input...
2580 tag
= ippGetValueTag(attr
);
2582 if (!attr
|| element
< 0 || element
>= attr
->num_values
|| (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&& (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
)))
2586 * Return the value...
2590 *language
= attr
->values
[element
].string
.language
;
2592 return (attr
->values
[element
].string
.text
);
2597 * 'ippGetValueTag()' - Get the value tag for an attribute.
2599 * @since CUPS 1.6/macOS 10.8@
2602 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2603 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2606 * Range check input...
2610 return (IPP_TAG_ZERO
);
2613 * Return the value...
2616 return (attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2621 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2623 * @since CUPS 1.6/macOS 10.8@
2626 int /* O - Major version number or 0 on error */
2627 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2628 int *minor
) /* O - Minor version number or @code NULL@ for don't care */
2631 * Range check input...
2643 * Return the value...
2647 *minor
= ipp
->request
.any
.version
[1];
2649 return (ipp
->request
.any
.version
[0]);
2654 * 'ippLength()' - Compute the length of an IPP message.
2657 size_t /* O - Size of IPP message */
2658 ippLength(ipp_t
*ipp
) /* I - IPP message */
2660 return (ipp_length(ipp
, 0));
2665 * 'ippNextAttribute()' - Return the next attribute in the message.
2667 * @since CUPS 1.6/macOS 10.8@
2670 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2671 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2674 * Range check input...
2677 if (!ipp
|| !ipp
->current
)
2681 * Return the next attribute...
2684 return (ipp
->current
= ipp
->current
->next
);
2689 * 'ippNew()' - Allocate a new IPP message.
2692 ipp_t
* /* O - New IPP message */
2695 ipp_t
*temp
; /* New IPP message */
2696 _cups_globals_t
*cg
= _cupsGlobals();
2700 DEBUG_puts("ippNew()");
2702 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2705 * Set default version - usually 2.0...
2708 if (cg
->server_version
== 0)
2711 temp
->request
.any
.version
[0] = (ipp_uchar_t
)(cg
->server_version
/ 10);
2712 temp
->request
.any
.version
[1] = (ipp_uchar_t
)(cg
->server_version
% 10);
2716 DEBUG_printf(("1ippNew: Returning %p", (void *)temp
));
2723 * 'ippNewRequest()' - Allocate a new IPP request message.
2725 * The new request message is initialized with the "attributes-charset" and
2726 * "attributes-natural-language" attributes added. The
2727 * "attributes-natural-language" value is derived from the current locale.
2729 * @since CUPS 1.2/macOS 10.5@
2732 ipp_t
* /* O - IPP request message */
2733 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2735 ipp_t
*request
; /* IPP request message */
2736 cups_lang_t
*language
; /* Current language localization */
2737 static int request_id
= 0; /* Current request ID */
2738 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2739 /* Mutex for request ID */
2742 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2745 * Create a new IPP message...
2748 if ((request
= ippNew()) == NULL
)
2752 * Set the operation and request ID...
2755 _cupsMutexLock(&request_mutex
);
2757 request
->request
.op
.operation_id
= op
;
2758 request
->request
.op
.request_id
= ++request_id
;
2760 _cupsMutexUnlock(&request_mutex
);
2763 * Use UTF-8 as the character set...
2766 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2767 "attributes-charset", NULL
, "utf-8");
2770 * Get the language from the current locale...
2773 language
= cupsLangDefault();
2775 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2776 "attributes-natural-language", NULL
, language
->language
);
2779 * Return the new request...
2787 * 'ippNewResponse()' - Allocate a new IPP response message.
2789 * The new response message is initialized with the same "version-number",
2790 * "request-id", "attributes-charset", and "attributes-natural-language" as the
2791 * provided request message. If the "attributes-charset" or
2792 * "attributes-natural-language" attributes are missing from the request,
2793 * 'utf-8' and a value derived from the current locale are substituted,
2796 * @since CUPS 1.7/macOS 10.9@
2799 ipp_t
* /* O - IPP response message */
2800 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2802 ipp_t
*response
; /* IPP response message */
2803 ipp_attribute_t
*attr
; /* Current attribute */
2807 * Range check input...
2814 * Create a new IPP message...
2817 if ((response
= ippNew()) == NULL
)
2821 * Copy the request values over to the response...
2824 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2825 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2826 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2829 * The first attribute MUST be attributes-charset...
2832 attr
= request
->attrs
;
2834 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2835 attr
->group_tag
== IPP_TAG_OPERATION
&&
2836 attr
->value_tag
== IPP_TAG_CHARSET
&&
2837 attr
->num_values
== 1)
2840 * Copy charset from request...
2843 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2844 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2849 * Use "utf-8" as the default...
2852 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2853 "attributes-charset", NULL
, "utf-8");
2857 * Then attributes-natural-language...
2863 if (attr
&& attr
->name
&&
2864 !strcmp(attr
->name
, "attributes-natural-language") &&
2865 attr
->group_tag
== IPP_TAG_OPERATION
&&
2866 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2867 attr
->num_values
== 1)
2870 * Copy language from request...
2873 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2874 "attributes-natural-language", NULL
,
2875 attr
->values
[0].string
.text
);
2880 * Use the language from the current locale...
2883 cups_lang_t
*language
= cupsLangDefault();
2884 /* Current locale */
2886 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2887 "attributes-natural-language", NULL
, language
->language
);
2895 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2898 ipp_state_t
/* O - Current state */
2899 ippRead(http_t
*http
, /* I - HTTP connection */
2900 ipp_t
*ipp
) /* I - IPP data */
2902 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
, (void *)http
, (void *)ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2905 return (IPP_STATE_ERROR
);
2907 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
, http
->used
));
2909 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2915 * 'ippReadFile()' - Read data for an IPP message from a file.
2917 * @since CUPS 1.1.19/macOS 10.3@
2920 ipp_state_t
/* O - Current state */
2921 ippReadFile(int fd
, /* I - HTTP data */
2922 ipp_t
*ipp
) /* I - IPP data */
2924 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
2926 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2931 * 'ippReadIO()' - Read data for an IPP message.
2933 * @since CUPS 1.2/macOS 10.5@
2936 ipp_state_t
/* O - Current state */
2937 ippReadIO(void *src
, /* I - Data source */
2938 ipp_iocb_t cb
, /* I - Read callback function */
2939 int blocking
, /* I - Use blocking IO? */
2940 ipp_t
*parent
, /* I - Parent request, if any */
2941 ipp_t
*ipp
) /* I - IPP data */
2943 int n
; /* Length of data */
2944 unsigned char *buffer
, /* Data buffer */
2945 string
[IPP_MAX_TEXT
],
2946 /* Small string buffer */
2947 *bufptr
; /* Pointer into buffer */
2948 ipp_attribute_t
*attr
; /* Current attribute */
2949 ipp_tag_t tag
; /* Current tag */
2950 ipp_tag_t value_tag
; /* Current value tag */
2951 _ipp_value_t
*value
; /* Current value */
2954 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)src
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
2955 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_STATE_ERROR
));
2958 return (IPP_STATE_ERROR
);
2960 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2962 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2963 return (IPP_STATE_ERROR
);
2968 case IPP_STATE_IDLE
:
2969 ipp
->state
++; /* Avoid common problem... */
2971 case IPP_STATE_HEADER
:
2975 * Get the request header...
2978 if ((*cb
)(src
, buffer
, 8) < 8)
2980 DEBUG_puts("1ippReadIO: Unable to read header.");
2981 _cupsBufferRelease((char *)buffer
);
2982 return (IPP_STATE_ERROR
);
2986 * Then copy the request header over...
2989 ipp
->request
.any
.version
[0] = buffer
[0];
2990 ipp
->request
.any
.version
[1] = buffer
[1];
2991 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
2992 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
2993 buffer
[6]) << 8) | buffer
[7];
2995 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
2996 DEBUG_printf(("2ippReadIO: op_status=%04x",
2997 ipp
->request
.any
.op_status
));
2998 DEBUG_printf(("2ippReadIO: request_id=%d",
2999 ipp
->request
.any
.request_id
));
3002 ipp
->state
= IPP_STATE_ATTRIBUTE
;
3003 ipp
->current
= NULL
;
3004 ipp
->curtag
= IPP_TAG_ZERO
;
3005 ipp
->prev
= ipp
->last
;
3008 * If blocking is disabled, stop here...
3014 case IPP_STATE_ATTRIBUTE
:
3017 if ((*cb
)(src
, buffer
, 1) < 1)
3019 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3020 _cupsBufferRelease((char *)buffer
);
3021 return (IPP_STATE_ERROR
);
3024 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3027 * Read this attribute...
3030 tag
= (ipp_tag_t
)buffer
[0];
3031 if (tag
== IPP_TAG_EXTENSION
)
3034 * Read 32-bit "extension" tag...
3037 if ((*cb
)(src
, buffer
, 4) < 1)
3039 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3040 _cupsBufferRelease((char *)buffer
);
3041 return (IPP_STATE_ERROR
);
3044 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
3045 buffer
[2]) << 8) | buffer
[3]);
3047 if (tag
& IPP_TAG_CUPS_CONST
)
3050 * Fail if the high bit is set in the tag...
3053 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
3054 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
3055 _cupsBufferRelease((char *)buffer
);
3056 return (IPP_STATE_ERROR
);
3060 if (tag
== IPP_TAG_END
)
3063 * No more attributes left...
3066 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
3068 ipp
->state
= IPP_STATE_DATA
;
3071 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3074 * Group tag... Set the current group and continue...
3077 if (ipp
->curtag
== tag
)
3078 ipp
->prev
= ippAddSeparator(ipp
);
3079 else if (ipp
->current
)
3080 ipp
->prev
= ipp
->current
;
3083 ipp
->current
= NULL
;
3084 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
, ippTagString(tag
), (void *)ipp
->prev
));
3088 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3089 ippTagString(tag
)));
3095 if ((*cb
)(src
, buffer
, 2) < 2)
3097 DEBUG_puts("1ippReadIO: unable to read name length.");
3098 _cupsBufferRelease((char *)buffer
);
3099 return (IPP_STATE_ERROR
);
3102 n
= (buffer
[0] << 8) | buffer
[1];
3104 if (n
>= IPP_BUF_SIZE
)
3106 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3107 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3108 _cupsBufferRelease((char *)buffer
);
3109 return (IPP_STATE_ERROR
);
3112 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3114 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3115 tag
!= IPP_TAG_END_COLLECTION
)
3118 * More values for current attribute...
3121 if (ipp
->current
== NULL
)
3123 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3124 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3125 _cupsBufferRelease((char *)buffer
);
3126 return (IPP_STATE_ERROR
);
3129 attr
= ipp
->current
;
3130 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3133 * Make sure we aren't adding a new value of a different
3137 if (value_tag
== IPP_TAG_ZERO
)
3140 * Setting the value of a collection member...
3143 attr
->value_tag
= tag
;
3145 else if (value_tag
== IPP_TAG_TEXTLANG
||
3146 value_tag
== IPP_TAG_NAMELANG
||
3147 (value_tag
>= IPP_TAG_TEXT
&&
3148 value_tag
<= IPP_TAG_MIMETYPE
))
3151 * String values can sometimes come across in different
3152 * forms; accept sets of differing values...
3155 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3156 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3157 tag
!= IPP_TAG_NOVALUE
)
3159 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3160 _("IPP 1setOf attribute with incompatible value "
3162 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3163 value_tag
, ippTagString(value_tag
), tag
,
3164 ippTagString(tag
)));
3165 _cupsBufferRelease((char *)buffer
);
3166 return (IPP_STATE_ERROR
);
3169 if (value_tag
!= tag
)
3171 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3172 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3173 ippSetValueTag(ipp
, &attr
, tag
);
3176 else if (value_tag
== IPP_TAG_INTEGER
||
3177 value_tag
== IPP_TAG_RANGE
)
3180 * Integer and rangeOfInteger values can sometimes be mixed; accept
3181 * sets of differing values...
3184 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3186 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3187 _("IPP 1setOf attribute with incompatible value "
3189 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3190 value_tag
, ippTagString(value_tag
), tag
,
3191 ippTagString(tag
)));
3192 _cupsBufferRelease((char *)buffer
);
3193 return (IPP_STATE_ERROR
);
3196 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3199 * Convert integer values to rangeOfInteger values...
3202 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3203 "rangeOfInteger.", attr
->name
));
3204 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3207 else if (value_tag
!= tag
)
3209 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3210 _("IPP 1setOf attribute with incompatible value "
3212 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3213 value_tag
, ippTagString(value_tag
), tag
,
3214 ippTagString(tag
)));
3215 _cupsBufferRelease((char *)buffer
);
3216 return (IPP_STATE_ERROR
);
3220 * Finally, reallocate the attribute array as needed...
3223 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3225 _cupsBufferRelease((char *)buffer
);
3226 return (IPP_STATE_ERROR
);
3229 else if (tag
== IPP_TAG_MEMBERNAME
)
3232 * Name must be length 0!
3237 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3238 DEBUG_puts("1ippReadIO: member name not empty.");
3239 _cupsBufferRelease((char *)buffer
);
3240 return (IPP_STATE_ERROR
);
3244 ipp
->prev
= ipp
->current
;
3246 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3249 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3250 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3251 _cupsBufferRelease((char *)buffer
);
3252 return (IPP_STATE_ERROR
);
3255 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3257 value
= attr
->values
;
3259 else if (tag
!= IPP_TAG_END_COLLECTION
)
3262 * New attribute; read the name and add it...
3265 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3267 DEBUG_puts("1ippReadIO: unable to read name.");
3268 _cupsBufferRelease((char *)buffer
);
3269 return (IPP_STATE_ERROR
);
3275 ipp
->prev
= ipp
->current
;
3277 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3280 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3281 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3282 _cupsBufferRelease((char *)buffer
);
3283 return (IPP_STATE_ERROR
);
3286 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer
, (void *)ipp
->current
, (void *)ipp
->prev
));
3288 value
= attr
->values
;
3296 if ((*cb
)(src
, buffer
, 2) < 2)
3298 DEBUG_puts("1ippReadIO: unable to read value length.");
3299 _cupsBufferRelease((char *)buffer
);
3300 return (IPP_STATE_ERROR
);
3303 n
= (buffer
[0] << 8) | buffer
[1];
3304 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3306 if (n
>= IPP_BUF_SIZE
)
3308 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3309 _("IPP value larger than 32767 bytes."), 1);
3310 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3311 _cupsBufferRelease((char *)buffer
);
3312 return (IPP_STATE_ERROR
);
3317 case IPP_TAG_INTEGER
:
3321 if (tag
== IPP_TAG_INTEGER
)
3322 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3323 _("IPP integer value not 4 bytes."), 1);
3325 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3326 _("IPP enum value not 4 bytes."), 1);
3327 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3328 _cupsBufferRelease((char *)buffer
);
3329 return (IPP_STATE_ERROR
);
3332 if ((*cb
)(src
, buffer
, 4) < 4)
3334 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3335 _cupsBufferRelease((char *)buffer
);
3336 return (IPP_STATE_ERROR
);
3339 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3342 if (attr
->value_tag
== IPP_TAG_RANGE
)
3343 value
->range
.lower
= value
->range
.upper
= n
;
3348 case IPP_TAG_BOOLEAN
:
3351 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3353 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3354 _cupsBufferRelease((char *)buffer
);
3355 return (IPP_STATE_ERROR
);
3358 if ((*cb
)(src
, buffer
, 1) < 1)
3360 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3361 _cupsBufferRelease((char *)buffer
);
3362 return (IPP_STATE_ERROR
);
3365 value
->boolean
= (char)buffer
[0];
3368 case IPP_TAG_NOVALUE
:
3369 case IPP_TAG_NOTSETTABLE
:
3370 case IPP_TAG_DELETEATTR
:
3371 case IPP_TAG_ADMINDEFINE
:
3373 * These value types are not supposed to have values, however
3374 * some vendors (Brother) do not implement IPP correctly and so
3375 * we need to map non-empty values to text...
3378 if (attr
->value_tag
== tag
)
3383 attr
->value_tag
= IPP_TAG_TEXT
;
3388 case IPP_TAG_KEYWORD
:
3390 case IPP_TAG_URISCHEME
:
3391 case IPP_TAG_CHARSET
:
3392 case IPP_TAG_LANGUAGE
:
3393 case IPP_TAG_MIMETYPE
:
3396 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3398 DEBUG_puts("1ippReadIO: unable to read string value.");
3399 _cupsBufferRelease((char *)buffer
);
3400 return (IPP_STATE_ERROR
);
3405 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3406 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3412 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3413 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3414 _cupsBufferRelease((char *)buffer
);
3415 return (IPP_STATE_ERROR
);
3418 if ((*cb
)(src
, value
->date
, 11) < 11)
3420 DEBUG_puts("1ippReadIO: Unable to read date value.");
3421 _cupsBufferRelease((char *)buffer
);
3422 return (IPP_STATE_ERROR
);
3426 case IPP_TAG_RESOLUTION
:
3429 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3430 _("IPP resolution value not 9 bytes."), 1);
3431 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3432 _cupsBufferRelease((char *)buffer
);
3433 return (IPP_STATE_ERROR
);
3436 if ((*cb
)(src
, buffer
, 9) < 9)
3438 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3439 _cupsBufferRelease((char *)buffer
);
3440 return (IPP_STATE_ERROR
);
3443 value
->resolution
.xres
=
3444 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3446 value
->resolution
.yres
=
3447 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3449 value
->resolution
.units
=
3450 (ipp_res_t
)buffer
[8];
3453 case IPP_TAG_RANGE
:
3456 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3457 _("IPP rangeOfInteger value not 8 bytes."), 1);
3458 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3460 _cupsBufferRelease((char *)buffer
);
3461 return (IPP_STATE_ERROR
);
3464 if ((*cb
)(src
, buffer
, 8) < 8)
3466 DEBUG_puts("1ippReadIO: Unable to read range value.");
3467 _cupsBufferRelease((char *)buffer
);
3468 return (IPP_STATE_ERROR
);
3471 value
->range
.lower
=
3472 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3474 value
->range
.upper
=
3475 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3479 case IPP_TAG_TEXTLANG
:
3480 case IPP_TAG_NAMELANG
:
3483 if (tag
== IPP_TAG_TEXTLANG
)
3484 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3485 _("IPP textWithLanguage value less than "
3486 "minimum 4 bytes."), 1);
3488 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3489 _("IPP nameWithLanguage value less than "
3490 "minimum 4 bytes."), 1);
3491 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3493 _cupsBufferRelease((char *)buffer
);
3494 return (IPP_STATE_ERROR
);
3497 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3499 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3501 _cupsBufferRelease((char *)buffer
);
3502 return (IPP_STATE_ERROR
);
3508 * text-with-language and name-with-language are composite
3517 n
= (bufptr
[0] << 8) | bufptr
[1];
3519 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) || n
>= (int)sizeof(string
))
3521 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3522 _("IPP language length overflows value."), 1);
3523 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3525 _cupsBufferRelease((char *)buffer
);
3526 return (IPP_STATE_ERROR
);
3528 else if (n
>= IPP_MAX_LANGUAGE
)
3530 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3531 _("IPP language length too large."), 1);
3532 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3534 _cupsBufferRelease((char *)buffer
);
3535 return (IPP_STATE_ERROR
);
3538 memcpy(string
, bufptr
+ 2, (size_t)n
);
3541 value
->string
.language
= _cupsStrAlloc((char *)string
);
3544 n
= (bufptr
[0] << 8) | bufptr
[1];
3546 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3548 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3549 _("IPP string length overflows value."), 1);
3550 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3551 _cupsBufferRelease((char *)buffer
);
3552 return (IPP_STATE_ERROR
);
3555 bufptr
[2 + n
] = '\0';
3556 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3559 case IPP_TAG_BEGIN_COLLECTION
:
3561 * Oh, boy, here comes a collection value, so read it...
3564 value
->collection
= ippNew();
3568 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3569 _("IPP begCollection value not 0 bytes."), 1);
3570 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3572 _cupsBufferRelease((char *)buffer
);
3573 return (IPP_STATE_ERROR
);
3576 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3578 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3579 _cupsBufferRelease((char *)buffer
);
3580 return (IPP_STATE_ERROR
);
3584 case IPP_TAG_END_COLLECTION
:
3585 _cupsBufferRelease((char *)buffer
);
3589 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3590 _("IPP endCollection value not 0 bytes."), 1);
3591 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3593 return (IPP_STATE_ERROR
);
3596 DEBUG_puts("1ippReadIO: endCollection tag...");
3597 return (ipp
->state
= IPP_STATE_DATA
);
3599 case IPP_TAG_MEMBERNAME
:
3601 * The value the name of the member in the collection, which
3602 * we need to carry over...
3607 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3608 _("IPP memberName with no attribute."), 1);
3609 DEBUG_puts("1ippReadIO: Member name without attribute.");
3610 _cupsBufferRelease((char *)buffer
);
3611 return (IPP_STATE_ERROR
);
3615 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3616 _("IPP memberName value is empty."), 1);
3617 DEBUG_puts("1ippReadIO: Empty member name value.");
3618 _cupsBufferRelease((char *)buffer
);
3619 return (IPP_STATE_ERROR
);
3621 else if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3623 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3624 _cupsBufferRelease((char *)buffer
);
3625 return (IPP_STATE_ERROR
);
3629 attr
->name
= _cupsStrAlloc((char *)buffer
);
3632 * Since collection members are encoded differently than
3633 * regular attributes, make sure we don't start with an
3637 attr
->num_values
--;
3639 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3642 default : /* Other unsupported values */
3643 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3645 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3646 _("IPP octetString length too large."), 1);
3647 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3649 _cupsBufferRelease((char *)buffer
);
3650 return (IPP_STATE_ERROR
);
3653 value
->unknown
.length
= n
;
3657 if ((value
->unknown
.data
= malloc((size_t)n
)) == NULL
)
3659 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3660 DEBUG_puts("1ippReadIO: Unable to allocate value");
3661 _cupsBufferRelease((char *)buffer
);
3662 return (IPP_STATE_ERROR
);
3665 if ((*cb
)(src
, value
->unknown
.data
, (size_t)n
) < n
)
3667 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3668 _cupsBufferRelease((char *)buffer
);
3669 return (IPP_STATE_ERROR
);
3673 value
->unknown
.data
= NULL
;
3678 * If blocking is disabled, stop here...
3686 case IPP_STATE_DATA
:
3690 break; /* anti-compiler-warning-code */
3693 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3694 _cupsBufferRelease((char *)buffer
);
3696 return (ipp
->state
);
3701 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3703 * The @code ipp@ parameter refers to an IPP message previously created using
3704 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3706 * The @code attr@ parameter may be modified as a result of setting the value.
3708 * The @code element@ parameter specifies which value to set from 0 to
3709 * @code ippGetCount(attr)@.
3711 * @since CUPS 1.6/macOS 10.8@
3714 int /* O - 1 on success, 0 on failure */
3715 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3716 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3717 int element
, /* I - Value number (0-based) */
3718 int boolvalue
)/* I - Boolean value */
3720 _ipp_value_t
*value
; /* Current value */
3724 * Range check input...
3727 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3728 element
< 0 || element
> (*attr
)->num_values
)
3732 * Set the value and return...
3735 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3736 value
->boolean
= (char)boolvalue
;
3738 return (value
!= NULL
);
3743 * 'ippSetCollection()' - Set a collection value in an attribute.
3745 * The @code ipp@ parameter refers to an IPP message previously created using
3746 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3748 * The @code attr@ parameter may be modified as a result of setting the value.
3750 * The @code element@ parameter specifies which value to set from 0 to
3751 * @code ippGetCount(attr)@.
3753 * @since CUPS 1.6/macOS 10.8@
3756 int /* O - 1 on success, 0 on failure */
3758 ipp_t
*ipp
, /* I - IPP message */
3759 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3760 int element
, /* I - Value number (0-based) */
3761 ipp_t
*colvalue
) /* I - Collection value */
3763 _ipp_value_t
*value
; /* Current value */
3767 * Range check input...
3770 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3771 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3775 * Set the value and return...
3778 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3780 if (value
->collection
)
3781 ippDelete(value
->collection
);
3783 value
->collection
= colvalue
;
3787 return (value
!= NULL
);
3792 * 'ippSetDate()' - Set a dateTime value in an attribute.
3794 * The @code ipp@ parameter refers to an IPP message previously created using
3795 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3797 * The @code attr@ parameter may be modified as a result of setting the value.
3799 * The @code element@ parameter specifies which value to set from 0 to
3800 * @code ippGetCount(attr)@.
3802 * @since CUPS 1.6/macOS 10.8@
3805 int /* O - 1 on success, 0 on failure */
3806 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3807 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3808 int element
, /* I - Value number (0-based) */
3809 const ipp_uchar_t
*datevalue
)/* I - dateTime value */
3811 _ipp_value_t
*value
; /* Current value */
3815 * Range check input...
3818 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3819 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3823 * Set the value and return...
3826 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3827 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3829 return (value
!= NULL
);
3834 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3836 * The @code ipp@ parameter refers to an IPP message previously created using
3837 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3839 * The @code attr@ parameter may be modified as a result of setting the value.
3841 * The @code group@ parameter specifies the IPP attribute group tag: none
3842 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3843 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3844 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3845 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3847 * @since CUPS 1.6/macOS 10.8@
3850 int /* O - 1 on success, 0 on failure */
3852 ipp_t
*ipp
, /* I - IPP message */
3853 ipp_attribute_t
**attr
, /* IO - Attribute */
3854 ipp_tag_t group_tag
) /* I - Group tag */
3857 * Range check input - group tag must be 0x01 to 0x0F, per RFC 8011...
3860 if (!ipp
|| !attr
|| !*attr
||
3861 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3862 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3866 * Set the group tag and return...
3869 (*attr
)->group_tag
= group_tag
;
3876 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3878 * The @code ipp@ parameter refers to an IPP message previously created using
3879 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3881 * The @code attr@ parameter may be modified as a result of setting the value.
3883 * The @code element@ parameter specifies which value to set from 0 to
3884 * @code ippGetCount(attr)@.
3886 * @since CUPS 1.6/macOS 10.8@
3889 int /* O - 1 on success, 0 on failure */
3890 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3891 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3892 int element
, /* I - Value number (0-based) */
3893 int intvalue
) /* I - Integer/enum value */
3895 _ipp_value_t
*value
; /* Current value */
3899 * Range check input...
3902 if (!ipp
|| !attr
|| !*attr
||
3903 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3904 element
< 0 || element
> (*attr
)->num_values
)
3908 * Set the value and return...
3911 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3912 value
->integer
= intvalue
;
3914 return (value
!= NULL
);
3919 * 'ippSetName()' - Set the name of an attribute.
3921 * The @code ipp@ parameter refers to an IPP message previously created using
3922 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3924 * The @code attr@ parameter may be modified as a result of setting the value.
3926 * @since CUPS 1.6/macOS 10.8@
3929 int /* O - 1 on success, 0 on failure */
3930 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3931 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3932 const char *name
) /* I - Attribute name */
3934 char *temp
; /* Temporary name value */
3938 * Range check input...
3941 if (!ipp
|| !attr
|| !*attr
)
3945 * Set the value and return...
3948 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3951 _cupsStrFree((*attr
)->name
);
3953 (*attr
)->name
= temp
;
3956 return (temp
!= NULL
);
3961 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
3963 * The @code ipp@ parameter refers to an IPP message previously created using
3964 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3966 * The @code attr@ parameter may be modified as a result of setting the value.
3968 * The @code element@ parameter specifies which value to set from 0 to
3969 * @code ippGetCount(attr)@.
3971 * @since CUPS 1.7/macOS 10.9@
3974 int /* O - 1 on success, 0 on failure */
3976 ipp_t
*ipp
, /* I - IPP message */
3977 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3978 int element
, /* I - Value number (0-based) */
3979 const void *data
, /* I - Pointer to octetString data */
3980 int datalen
) /* I - Length of octetString data */
3982 _ipp_value_t
*value
; /* Current value */
3986 * Range check input...
3989 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_STRING
||
3990 element
< 0 || element
> (*attr
)->num_values
||
3991 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
3995 * Set the value and return...
3998 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4000 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4003 * Just copy the pointer...
4006 value
->unknown
.data
= (void *)data
;
4007 value
->unknown
.length
= datalen
;
4015 if (value
->unknown
.data
)
4018 * Free previous data...
4021 free(value
->unknown
.data
);
4023 value
->unknown
.data
= NULL
;
4024 value
->unknown
.length
= 0;
4029 void *temp
; /* Temporary data pointer */
4031 if ((temp
= malloc((size_t)datalen
)) != NULL
)
4033 memcpy(temp
, data
, (size_t)datalen
);
4035 value
->unknown
.data
= temp
;
4036 value
->unknown
.length
= datalen
;
4044 return (value
!= NULL
);
4049 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
4051 * The @code ipp@ parameter refers to an IPP message previously created using
4052 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4054 * @since CUPS 1.6/macOS 10.8@
4057 int /* O - 1 on success, 0 on failure */
4058 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
4059 ipp_op_t op
) /* I - Operation ID */
4062 * Range check input...
4069 * Set the operation and return...
4072 ipp
->request
.op
.operation_id
= op
;
4079 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4081 * The @code ipp@ parameter refers to an IPP message previously created using
4082 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4084 * The @code attr@ parameter may be modified as a result of setting the value.
4086 * The @code element@ parameter specifies which value to set from 0 to
4087 * @code ippGetCount(attr)@.
4089 * @since CUPS 1.6/macOS 10.8@
4092 int /* O - 1 on success, 0 on failure */
4093 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4094 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4095 int element
, /* I - Value number (0-based) */
4096 int lowervalue
, /* I - Lower bound for range */
4097 int uppervalue
) /* I - Upper bound for range */
4099 _ipp_value_t
*value
; /* Current value */
4103 * Range check input...
4106 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4107 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4111 * Set the value and return...
4114 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4116 value
->range
.lower
= lowervalue
;
4117 value
->range
.upper
= uppervalue
;
4120 return (value
!= NULL
);
4125 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4127 * The @code ipp@ parameter refers to an IPP message previously created using
4128 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4130 * The @code request_id@ parameter must be greater than 0.
4132 * @since CUPS 1.6/macOS 10.8@
4135 int /* O - 1 on success, 0 on failure */
4136 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4137 int request_id
) /* I - Request ID */
4140 * Range check input; not checking request_id values since ipptool wants to send
4141 * invalid values for conformance testing and a bad request_id does not affect the
4142 * encoding of a message...
4149 * Set the request ID and return...
4152 ipp
->request
.any
.request_id
= request_id
;
4159 * 'ippSetResolution()' - Set a resolution value in an attribute.
4161 * The @code ipp@ parameter refers to an IPP message previously created using
4162 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4164 * The @code attr@ parameter may be modified as a result of setting the value.
4166 * The @code element@ parameter specifies which value to set from 0 to
4167 * @code ippGetCount(attr)@.
4169 * @since CUPS 1.6/macOS 10.8@
4172 int /* O - 1 on success, 0 on failure */
4174 ipp_t
*ipp
, /* I - IPP message */
4175 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4176 int element
, /* I - Value number (0-based) */
4177 ipp_res_t unitsvalue
, /* I - Resolution units */
4178 int xresvalue
, /* I - Horizontal/cross feed resolution */
4179 int yresvalue
) /* I - Vertical/feed resolution */
4181 _ipp_value_t
*value
; /* Current value */
4185 * Range check input...
4188 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4189 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4190 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4194 * Set the value and return...
4197 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4199 value
->resolution
.units
= unitsvalue
;
4200 value
->resolution
.xres
= xresvalue
;
4201 value
->resolution
.yres
= yresvalue
;
4204 return (value
!= NULL
);
4209 * 'ippSetState()' - Set the current state of the IPP message.
4211 * @since CUPS 1.6/macOS 10.8@
4214 int /* O - 1 on success, 0 on failure */
4215 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4216 ipp_state_t state
) /* I - IPP state value */
4219 * Range check input...
4226 * Set the state and return...
4230 ipp
->current
= NULL
;
4237 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4239 * The @code ipp@ parameter refers to an IPP message previously created using
4240 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4242 * @since CUPS 1.6/macOS 10.8@
4245 int /* O - 1 on success, 0 on failure */
4246 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4247 ipp_status_t status
) /* I - Status code */
4250 * Range check input...
4257 * Set the status code and return...
4260 ipp
->request
.status
.status_code
= status
;
4267 * 'ippSetString()' - Set a string value in an attribute.
4269 * The @code ipp@ parameter refers to an IPP message previously created using
4270 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4272 * The @code attr@ parameter may be modified as a result of setting the value.
4274 * The @code element@ parameter specifies which value to set from 0 to
4275 * @code ippGetCount(attr)@.
4277 * @since CUPS 1.6/macOS 10.8@
4280 int /* O - 1 on success, 0 on failure */
4281 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4282 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4283 int element
, /* I - Value number (0-based) */
4284 const char *strvalue
) /* I - String value */
4286 char *temp
; /* Temporary string */
4287 _ipp_value_t
*value
; /* Current value */
4291 * Range check input...
4294 if (!ipp
|| !attr
|| !*attr
||
4295 ((*attr
)->value_tag
!= IPP_TAG_TEXTLANG
&&
4296 (*attr
)->value_tag
!= IPP_TAG_NAMELANG
&&
4297 ((*attr
)->value_tag
< IPP_TAG_TEXT
||
4298 (*attr
)->value_tag
> IPP_TAG_MIMETYPE
)) ||
4299 element
< 0 || element
> (*attr
)->num_values
|| !strvalue
)
4303 * Set the value and return...
4306 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4309 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4311 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4312 value
->string
.text
= (char *)strvalue
;
4313 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4315 if (value
->string
.text
)
4316 _cupsStrFree(value
->string
.text
);
4318 value
->string
.text
= temp
;
4324 return (value
!= NULL
);
4329 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4331 * The @code ipp@ parameter refers to an IPP message previously created using
4332 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4334 * The @code attr@ parameter may be modified as a result of setting the value.
4336 * The @code element@ parameter specifies which value to set from 0 to
4337 * @code ippGetCount(attr)@.
4339 * The @code format@ parameter uses formatting characters compatible with the
4340 * printf family of standard functions. Additional arguments follow it as
4341 * needed. The formatted string is truncated as needed to the maximum length of
4342 * the corresponding value type.
4344 * @since CUPS 1.7/macOS 10.9@
4347 int /* O - 1 on success, 0 on failure */
4348 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4349 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4350 int element
, /* I - Value number (0-based) */
4351 const char *format
, /* I - Printf-style format string */
4352 ...) /* I - Additional arguments as needed */
4354 int ret
; /* Return value */
4355 va_list ap
; /* Pointer to additional arguments */
4358 va_start(ap
, format
);
4359 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4367 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4369 * The @code ipp@ parameter refers to an IPP message previously created using
4370 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4372 * The @code attr@ parameter may be modified as a result of setting the value.
4374 * The @code element@ parameter specifies which value to set from 0 to
4375 * @code ippGetCount(attr)@.
4377 * The @code format@ parameter uses formatting characters compatible with the
4378 * printf family of standard functions. Additional arguments follow it as
4379 * needed. The formatted string is truncated as needed to the maximum length of
4380 * the corresponding value type.
4382 * @since CUPS 1.7/macOS 10.9@
4385 int /* O - 1 on success, 0 on failure */
4386 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4387 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4388 int element
, /* I - Value number (0-based) */
4389 const char *format
, /* I - Printf-style format string */
4390 va_list ap
) /* I - Pointer to additional arguments */
4392 ipp_tag_t value_tag
; /* Value tag */
4393 char buffer
[IPP_MAX_TEXT
+ 4];
4394 /* Formatted text string */
4395 ssize_t bytes
, /* Length of formatted value */
4396 max_bytes
; /* Maximum number of bytes for value */
4400 * Range check input...
4404 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4406 value_tag
= IPP_TAG_ZERO
;
4408 if (!ipp
|| !attr
|| !*attr
||
4409 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4410 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4415 * Format the string...
4418 if (!strcmp(format
, "%s"))
4421 * Optimize the simple case...
4424 const char *s
= va_arg(ap
, char *);
4429 bytes
= (ssize_t
)strlen(s
);
4430 strlcpy(buffer
, s
, sizeof(buffer
));
4435 * Do a full formatting of the message...
4438 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4443 * Limit the length of the string...
4450 case IPP_TAG_TEXTLANG
:
4451 max_bytes
= IPP_MAX_TEXT
;
4455 case IPP_TAG_NAMELANG
:
4456 max_bytes
= IPP_MAX_NAME
;
4459 case IPP_TAG_CHARSET
:
4460 max_bytes
= IPP_MAX_CHARSET
;
4463 case IPP_TAG_KEYWORD
:
4464 max_bytes
= IPP_MAX_KEYWORD
;
4467 case IPP_TAG_LANGUAGE
:
4468 max_bytes
= IPP_MAX_LANGUAGE
;
4471 case IPP_TAG_MIMETYPE
:
4472 max_bytes
= IPP_MAX_MIMETYPE
;
4476 max_bytes
= IPP_MAX_URI
;
4479 case IPP_TAG_URISCHEME
:
4480 max_bytes
= IPP_MAX_URISCHEME
;
4484 if (bytes
>= max_bytes
)
4486 char *bufmax
, /* Buffer at max_bytes */
4487 *bufptr
; /* Pointer into buffer */
4489 bufptr
= buffer
+ strlen(buffer
) - 1;
4490 bufmax
= buffer
+ max_bytes
- 1;
4492 while (bufptr
> bufmax
)
4496 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4507 * Set the formatted string and return...
4510 return (ippSetString(ipp
, attr
, element
, buffer
));
4515 * 'ippSetValueTag()' - Set the value tag of an attribute.
4517 * The @code ipp@ parameter refers to an IPP message previously created using
4518 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4520 * The @code attr@ parameter may be modified as a result of setting the value.
4522 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4523 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4524 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4525 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4526 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4527 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4530 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4531 * code in the "attributes-natural-language" attribute or, if not present, the language
4532 * code for the current locale.
4534 * @since CUPS 1.6/macOS 10.8@
4537 int /* O - 1 on success, 0 on failure */
4539 ipp_t
*ipp
, /* I - IPP message */
4540 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4541 ipp_tag_t value_tag
) /* I - Value tag */
4543 int i
; /* Looping var */
4544 _ipp_value_t
*value
; /* Current value */
4545 int integer
; /* Current integer value */
4546 cups_lang_t
*language
; /* Current language */
4547 char code
[32]; /* Language code */
4548 ipp_tag_t temp_tag
; /* Temporary value tag */
4552 * Range check input...
4555 if (!ipp
|| !attr
|| !*attr
)
4559 * If there is no change, return immediately...
4562 if (value_tag
== (*attr
)->value_tag
)
4566 * Otherwise implement changes as needed...
4569 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4573 case IPP_TAG_UNSUPPORTED_VALUE
:
4574 case IPP_TAG_DEFAULT
:
4575 case IPP_TAG_UNKNOWN
:
4576 case IPP_TAG_NOVALUE
:
4577 case IPP_TAG_NOTSETTABLE
:
4578 case IPP_TAG_DELETEATTR
:
4579 case IPP_TAG_ADMINDEFINE
:
4581 * Free any existing values...
4584 if ((*attr
)->num_values
> 0)
4585 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4588 * Set out-of-band value...
4591 (*attr
)->value_tag
= value_tag
;
4594 case IPP_TAG_RANGE
:
4595 if (temp_tag
!= IPP_TAG_INTEGER
)
4598 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4602 integer
= value
->integer
;
4603 value
->range
.lower
= value
->range
.upper
= integer
;
4606 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4610 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4611 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4612 temp_tag
!= IPP_TAG_MIMETYPE
)
4615 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4618 case IPP_TAG_NAMELANG
:
4619 case IPP_TAG_TEXTLANG
:
4620 if (value_tag
== IPP_TAG_NAMELANG
&&
4621 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4622 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4623 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4626 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4629 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4630 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4633 * Use the language code from the IPP message...
4636 (*attr
)->values
[0].string
.language
=
4637 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4642 * Otherwise, use the language code corresponding to the locale...
4645 language
= cupsLangDefault();
4646 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4651 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4654 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4656 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4659 * Make copies of all values...
4662 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4665 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4668 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4671 case IPP_TAG_KEYWORD
:
4672 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4673 break; /* Silently "allow" name -> keyword */
4684 * 'ippSetVersion()' - Set the version number in an IPP message.
4686 * The @code ipp@ parameter refers to an IPP message previously created using
4687 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4689 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4691 * @since CUPS 1.6/macOS 10.8@
4694 int /* O - 1 on success, 0 on failure */
4695 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4696 int major
, /* I - Major version number (major.minor) */
4697 int minor
) /* I - Minor version number (major.minor) */
4700 * Range check input...
4703 if (!ipp
|| major
< 0 || minor
< 0)
4707 * Set the version number...
4710 ipp
->request
.any
.version
[0] = (ipp_uchar_t
)major
;
4711 ipp
->request
.any
.version
[1] = (ipp_uchar_t
)minor
;
4718 * 'ippTimeToDate()' - Convert from time in seconds to RFC 2579 format.
4721 const ipp_uchar_t
* /* O - RFC-2579 date/time data */
4722 ippTimeToDate(time_t t
) /* I - Time in seconds */
4724 struct tm
*unixdate
; /* UNIX unixdate/time info */
4725 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4726 /* RFC-2579 date/time data */
4730 * RFC-2579 date/time format is:
4732 * Byte(s) Description
4733 * ------- -----------
4734 * 0-1 Year (0 to 65535)
4738 * 5 Minutes (0 to 59)
4739 * 6 Seconds (0 to 60, 60 = "leap second")
4740 * 7 Deciseconds (0 to 9)
4742 * 9 UTC hours (0 to 11)
4743 * 10 UTC minutes (0 to 59)
4746 unixdate
= gmtime(&t
);
4747 unixdate
->tm_year
+= 1900;
4749 date
[0] = (ipp_uchar_t
)(unixdate
->tm_year
>> 8);
4750 date
[1] = (ipp_uchar_t
)(unixdate
->tm_year
);
4751 date
[2] = (ipp_uchar_t
)(unixdate
->tm_mon
+ 1);
4752 date
[3] = (ipp_uchar_t
)unixdate
->tm_mday
;
4753 date
[4] = (ipp_uchar_t
)unixdate
->tm_hour
;
4754 date
[5] = (ipp_uchar_t
)unixdate
->tm_min
;
4755 date
[6] = (ipp_uchar_t
)unixdate
->tm_sec
;
4766 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4768 * This function validates the contents of an attribute based on the name and
4769 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4770 * failure, @link cupsLastErrorString@ is set to a human-readable message.
4772 * @since CUPS 1.7/macOS 10.9@
4775 int /* O - 1 if valid, 0 otherwise */
4776 ippValidateAttribute(
4777 ipp_attribute_t
*attr
) /* I - Attribute */
4779 int i
; /* Looping var */
4780 char scheme
[64], /* Scheme from URI */
4781 userpass
[256], /* Username/password from URI */
4782 hostname
[256], /* Hostname from URI */
4783 resource
[1024]; /* Resource from URI */
4784 int port
, /* Port number from URI */
4785 uri_status
; /* URI separation status */
4786 const char *ptr
; /* Pointer into string */
4787 ipp_attribute_t
*colattr
; /* Collection attribute */
4788 regex_t re
; /* Regular expression */
4789 ipp_uchar_t
*date
; /* Current date value */
4790 static const char * const uri_status_strings
[] =
4791 { /* URI status strings */
4793 "Bad arguments to function",
4794 "Bad resource in URI",
4795 "Bad port number in URI",
4796 "Bad hostname/address in URI",
4797 "Bad username in URI",
4798 "Bad scheme in URI",
4801 "Missing scheme in URI",
4802 "Unknown scheme in URI",
4803 "Missing resource in URI"
4815 * Validate the attribute name.
4818 for (ptr
= attr
->name
; *ptr
; ptr
++)
4819 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4822 if (*ptr
|| ptr
== attr
->name
)
4824 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4825 _("\"%s\": Bad attribute name - invalid character "
4826 "(RFC 8011 section 5.1.4)."), attr
->name
);
4830 if ((ptr
- attr
->name
) > 255)
4832 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4833 _("\"%s\": Bad attribute name - bad length %d "
4834 "(RFC 8011 section 5.1.4)."), attr
->name
,
4835 (int)(ptr
- attr
->name
));
4839 switch (attr
->value_tag
)
4841 case IPP_TAG_INTEGER
:
4844 case IPP_TAG_BOOLEAN
:
4845 for (i
= 0; i
< attr
->num_values
; i
++)
4847 if (attr
->values
[i
].boolean
!= 0 &&
4848 attr
->values
[i
].boolean
!= 1)
4850 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4851 _("\"%s\": Bad boolen value %d "
4852 "(RFC 8011 section 5.1.21)."), attr
->name
,
4853 attr
->values
[i
].boolean
);
4860 for (i
= 0; i
< attr
->num_values
; i
++)
4862 if (attr
->values
[i
].integer
< 1)
4864 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4865 _("\"%s\": Bad enum value %d - out of range "
4866 "(RFC 8011 section 5.1.5)."), attr
->name
,
4867 attr
->values
[i
].integer
);
4873 case IPP_TAG_STRING
:
4874 for (i
= 0; i
< attr
->num_values
; i
++)
4876 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4878 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4879 _("\"%s\": Bad octetString value - bad length %d "
4880 "(RFC 8011 section 5.1.20)."), attr
->name
,
4881 attr
->values
[i
].unknown
.length
);
4888 for (i
= 0; i
< attr
->num_values
; i
++)
4890 date
= attr
->values
[i
].date
;
4892 if (date
[2] < 1 || date
[2] > 12)
4894 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4895 _("\"%s\": Bad dateTime month %u "
4896 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[2]);
4900 if (date
[3] < 1 || date
[3] > 31)
4902 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4903 _("\"%s\": Bad dateTime day %u "
4904 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[3]);
4910 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4911 _("\"%s\": Bad dateTime hours %u "
4912 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[4]);
4918 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4919 _("\"%s\": Bad dateTime minutes %u "
4920 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[5]);
4926 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4927 _("\"%s\": Bad dateTime seconds %u "
4928 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[6]);
4934 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4935 _("\"%s\": Bad dateTime deciseconds %u "
4936 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[7]);
4940 if (date
[8] != '-' && date
[8] != '+')
4942 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4943 _("\"%s\": Bad dateTime UTC sign '%c' "
4944 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[8]);
4950 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4951 _("\"%s\": Bad dateTime UTC hours %u "
4952 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[9]);
4958 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4959 _("\"%s\": Bad dateTime UTC minutes %u "
4960 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[10]);
4966 case IPP_TAG_RESOLUTION
:
4967 for (i
= 0; i
< attr
->num_values
; i
++)
4969 if (attr
->values
[i
].resolution
.xres
<= 0)
4971 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4972 _("\"%s\": Bad resolution value %dx%d%s - cross "
4973 "feed resolution must be positive "
4974 "(RFC 8011 section 5.1.16)."), attr
->name
,
4975 attr
->values
[i
].resolution
.xres
,
4976 attr
->values
[i
].resolution
.yres
,
4977 attr
->values
[i
].resolution
.units
==
4978 IPP_RES_PER_INCH
? "dpi" :
4979 attr
->values
[i
].resolution
.units
==
4980 IPP_RES_PER_CM
? "dpcm" : "unknown");
4984 if (attr
->values
[i
].resolution
.yres
<= 0)
4986 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4987 _("\"%s\": Bad resolution value %dx%d%s - feed "
4988 "resolution must be positive "
4989 "(RFC 8011 section 5.1.16)."), attr
->name
,
4990 attr
->values
[i
].resolution
.xres
,
4991 attr
->values
[i
].resolution
.yres
,
4992 attr
->values
[i
].resolution
.units
==
4993 IPP_RES_PER_INCH
? "dpi" :
4994 attr
->values
[i
].resolution
.units
==
4995 IPP_RES_PER_CM
? "dpcm" : "unknown");
4999 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
5000 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
5002 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5003 _("\"%s\": Bad resolution value %dx%d%s - bad "
5004 "units value (RFC 8011 section 5.1.16)."),
5005 attr
->name
, attr
->values
[i
].resolution
.xres
,
5006 attr
->values
[i
].resolution
.yres
,
5007 attr
->values
[i
].resolution
.units
==
5008 IPP_RES_PER_INCH
? "dpi" :
5009 attr
->values
[i
].resolution
.units
==
5010 IPP_RES_PER_CM
? "dpcm" : "unknown");
5016 case IPP_TAG_RANGE
:
5017 for (i
= 0; i
< attr
->num_values
; i
++)
5019 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
5021 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5022 _("\"%s\": Bad rangeOfInteger value %d-%d - lower "
5023 "greater than upper (RFC 8011 section 5.1.14)."),
5024 attr
->name
, attr
->values
[i
].range
.lower
,
5025 attr
->values
[i
].range
.upper
);
5031 case IPP_TAG_BEGIN_COLLECTION
:
5032 for (i
= 0; i
< attr
->num_values
; i
++)
5034 for (colattr
= attr
->values
[i
].collection
->attrs
;
5036 colattr
= colattr
->next
)
5038 if (!ippValidateAttribute(colattr
))
5045 case IPP_TAG_TEXTLANG
:
5046 for (i
= 0; i
< attr
->num_values
; i
++)
5048 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5050 if ((*ptr
& 0xe0) == 0xc0)
5053 if ((*ptr
& 0xc0) != 0x80)
5056 else if ((*ptr
& 0xf0) == 0xe0)
5059 if ((*ptr
& 0xc0) != 0x80)
5062 if ((*ptr
& 0xc0) != 0x80)
5065 else if ((*ptr
& 0xf8) == 0xf0)
5068 if ((*ptr
& 0xc0) != 0x80)
5071 if ((*ptr
& 0xc0) != 0x80)
5074 if ((*ptr
& 0xc0) != 0x80)
5077 else if (*ptr
& 0x80)
5083 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5084 _("\"%s\": Bad text value \"%s\" - bad UTF-8 "
5085 "sequence (RFC 8011 section 5.1.2)."), attr
->name
,
5086 attr
->values
[i
].string
.text
);
5090 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5092 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5093 _("\"%s\": Bad text value \"%s\" - bad length %d "
5094 "(RFC 8011 section 5.1.2)."), attr
->name
,
5095 attr
->values
[i
].string
.text
,
5096 (int)(ptr
- attr
->values
[i
].string
.text
));
5103 case IPP_TAG_NAMELANG
:
5104 for (i
= 0; i
< attr
->num_values
; i
++)
5106 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5108 if ((*ptr
& 0xe0) == 0xc0)
5111 if ((*ptr
& 0xc0) != 0x80)
5114 else if ((*ptr
& 0xf0) == 0xe0)
5117 if ((*ptr
& 0xc0) != 0x80)
5120 if ((*ptr
& 0xc0) != 0x80)
5123 else if ((*ptr
& 0xf8) == 0xf0)
5126 if ((*ptr
& 0xc0) != 0x80)
5129 if ((*ptr
& 0xc0) != 0x80)
5132 if ((*ptr
& 0xc0) != 0x80)
5135 else if (*ptr
& 0x80)
5141 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5142 _("\"%s\": Bad name value \"%s\" - bad UTF-8 "
5143 "sequence (RFC 8011 section 5.1.3)."), attr
->name
,
5144 attr
->values
[i
].string
.text
);
5148 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5150 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5151 _("\"%s\": Bad name value \"%s\" - bad length %d "
5152 "(RFC 8011 section 5.1.3)."), attr
->name
,
5153 attr
->values
[i
].string
.text
,
5154 (int)(ptr
- attr
->values
[i
].string
.text
));
5160 case IPP_TAG_KEYWORD
:
5161 for (i
= 0; i
< attr
->num_values
; i
++)
5163 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5164 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5168 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5170 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5171 _("\"%s\": Bad keyword value \"%s\" - invalid "
5172 "character (RFC 8011 section 5.1.4)."),
5173 attr
->name
, attr
->values
[i
].string
.text
);
5177 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5179 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5180 _("\"%s\": Bad keyword value \"%s\" - bad "
5181 "length %d (RFC 8011 section 5.1.4)."),
5182 attr
->name
, attr
->values
[i
].string
.text
,
5183 (int)(ptr
- attr
->values
[i
].string
.text
));
5190 for (i
= 0; i
< attr
->num_values
; i
++)
5192 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5193 attr
->values
[i
].string
.text
,
5194 scheme
, sizeof(scheme
),
5195 userpass
, sizeof(userpass
),
5196 hostname
, sizeof(hostname
),
5197 &port
, resource
, sizeof(resource
));
5199 if (uri_status
< HTTP_URI_STATUS_OK
)
5201 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5202 _("\"%s\": Bad URI value \"%s\" - %s "
5203 "(RFC 8011 section 5.1.6)."), attr
->name
,
5204 attr
->values
[i
].string
.text
,
5205 uri_status_strings
[uri_status
-
5206 HTTP_URI_STATUS_OVERFLOW
]);
5210 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5212 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5213 _("\"%s\": Bad URI value \"%s\" - bad length %d "
5214 "(RFC 8011 section 5.1.6)."), attr
->name
,
5215 attr
->values
[i
].string
.text
,
5216 (int)strlen(attr
->values
[i
].string
.text
));
5221 case IPP_TAG_URISCHEME
:
5222 for (i
= 0; i
< attr
->num_values
; i
++)
5224 ptr
= attr
->values
[i
].string
.text
;
5225 if (islower(*ptr
& 255))
5227 for (ptr
++; *ptr
; ptr
++)
5228 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5229 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5233 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5235 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5236 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5237 "characters (RFC 8011 section 5.1.7)."),
5238 attr
->name
, attr
->values
[i
].string
.text
);
5242 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5244 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5245 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5246 "length %d (RFC 8011 section 5.1.7)."),
5247 attr
->name
, attr
->values
[i
].string
.text
,
5248 (int)(ptr
- attr
->values
[i
].string
.text
));
5254 case IPP_TAG_CHARSET
:
5255 for (i
= 0; i
< attr
->num_values
; i
++)
5257 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5258 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5259 isspace(*ptr
& 255))
5262 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5264 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5265 _("\"%s\": Bad charset value \"%s\" - bad "
5266 "characters (RFC 8011 section 5.1.8)."),
5267 attr
->name
, attr
->values
[i
].string
.text
);
5271 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5273 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5274 _("\"%s\": Bad charset value \"%s\" - bad "
5275 "length %d (RFC 8011 section 5.1.8)."),
5276 attr
->name
, attr
->values
[i
].string
.text
,
5277 (int)(ptr
- attr
->values
[i
].string
.text
));
5283 case IPP_TAG_LANGUAGE
:
5285 * The following regular expression is derived from the ABNF for
5286 * language tags in RFC 4646. All I can say is that this is the
5287 * easiest way to check the values...
5290 if ((i
= regcomp(&re
,
5292 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5294 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5295 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5296 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5297 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5298 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5300 "x(-[a-z0-9]{1,8})+" /* privateuse */
5302 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5304 REG_NOSUB
| REG_EXTENDED
)) != 0)
5306 char temp
[256]; /* Temporary error string */
5308 regerror(i
, &re
, temp
, sizeof(temp
));
5309 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
,
5310 _("Unable to compile naturalLanguage regular "
5311 "expression: %s."), temp
);
5315 for (i
= 0; i
< attr
->num_values
; i
++)
5317 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5319 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5320 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5321 "characters (RFC 8011 section 5.1.9)."),
5322 attr
->name
, attr
->values
[i
].string
.text
);
5327 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5329 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5330 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5331 "length %d (RFC 8011 section 5.1.9)."),
5332 attr
->name
, attr
->values
[i
].string
.text
,
5333 (int)strlen(attr
->values
[i
].string
.text
));
5342 case IPP_TAG_MIMETYPE
:
5344 * The following regular expression is derived from the ABNF for
5345 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5346 * the easiest way to check the values...
5349 if ((i
= regcomp(&re
,
5351 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5353 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5354 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5355 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5358 REG_NOSUB
| REG_EXTENDED
)) != 0)
5360 char temp
[256]; /* Temporary error string */
5362 regerror(i
, &re
, temp
, sizeof(temp
));
5363 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5364 _("Unable to compile mimeMediaType regular "
5365 "expression: %s."), temp
);
5369 for (i
= 0; i
< attr
->num_values
; i
++)
5371 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5373 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5374 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5375 "characters (RFC 8011 section 5.1.10)."),
5376 attr
->name
, attr
->values
[i
].string
.text
);
5381 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5383 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5384 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5385 "length %d (RFC 8011 section 5.1.10)."),
5386 attr
->name
, attr
->values
[i
].string
.text
,
5387 (int)strlen(attr
->values
[i
].string
.text
));
5405 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5407 * This function validates the contents of the IPP message, including each
5408 * attribute. Like @link ippValidateAttribute@, @link cupsLastErrorString@ is
5409 * set to a human-readable message on failure.
5411 * @since CUPS 1.7/macOS 10.9@
5414 int /* O - 1 if valid, 0 otherwise */
5415 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5417 ipp_attribute_t
*attr
; /* Current attribute */
5423 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5424 if (!ippValidateAttribute(attr
))
5432 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5435 ipp_state_t
/* O - Current state */
5436 ippWrite(http_t
*http
, /* I - HTTP connection */
5437 ipp_t
*ipp
) /* I - IPP data */
5439 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http
, (void *)ipp
));
5442 return (IPP_STATE_ERROR
);
5444 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5449 * 'ippWriteFile()' - Write data for an IPP message to a file.
5451 * @since CUPS 1.1.19/macOS 10.3@
5454 ipp_state_t
/* O - Current state */
5455 ippWriteFile(int fd
, /* I - HTTP data */
5456 ipp_t
*ipp
) /* I - IPP data */
5458 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
5460 ipp
->state
= IPP_STATE_IDLE
;
5462 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5467 * 'ippWriteIO()' - Write data for an IPP message.
5469 * @since CUPS 1.2/macOS 10.5@
5472 ipp_state_t
/* O - Current state */
5473 ippWriteIO(void *dst
, /* I - Destination */
5474 ipp_iocb_t cb
, /* I - Write callback function */
5475 int blocking
, /* I - Use blocking IO? */
5476 ipp_t
*parent
, /* I - Parent IPP message */
5477 ipp_t
*ipp
) /* I - IPP data */
5479 int i
; /* Looping var */
5480 int n
; /* Length of data */
5481 unsigned char *buffer
, /* Data buffer */
5482 *bufptr
; /* Pointer into buffer */
5483 ipp_attribute_t
*attr
; /* Current attribute */
5484 _ipp_value_t
*value
; /* Current value */
5487 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
5490 return (IPP_STATE_ERROR
);
5492 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5494 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5495 return (IPP_STATE_ERROR
);
5500 case IPP_STATE_IDLE
:
5501 ipp
->state
++; /* Avoid common problem... */
5503 case IPP_STATE_HEADER
:
5507 * Send the request header:
5510 * Operation/Status Code = 2 bytes
5511 * Request ID = 4 bytes
5517 *bufptr
++ = ipp
->request
.any
.version
[0];
5518 *bufptr
++ = ipp
->request
.any
.version
[1];
5519 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.op_status
>> 8);
5520 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.op_status
;
5521 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 24);
5522 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 16);
5523 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 8);
5524 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.request_id
;
5526 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5527 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5528 ipp
->request
.any
.op_status
));
5529 DEBUG_printf(("2ippWriteIO: request_id=%d",
5530 ipp
->request
.any
.request_id
));
5532 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5534 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5535 _cupsBufferRelease((char *)buffer
);
5536 return (IPP_STATE_ERROR
);
5541 * Reset the state engine to point to the first attribute
5542 * in the request/response, with no current group.
5545 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5546 ipp
->current
= ipp
->attrs
;
5547 ipp
->curtag
= IPP_TAG_ZERO
;
5549 DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp
->current
));
5552 * If blocking is disabled, stop here...
5558 case IPP_STATE_ATTRIBUTE
:
5559 while (ipp
->current
!= NULL
)
5562 * Write this attribute...
5566 attr
= ipp
->current
;
5568 ipp
->current
= ipp
->current
->next
;
5572 if (ipp
->curtag
!= attr
->group_tag
)
5575 * Send a group tag byte...
5578 ipp
->curtag
= attr
->group_tag
;
5580 if (attr
->group_tag
== IPP_TAG_ZERO
)
5583 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5584 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5585 *bufptr
++ = (ipp_uchar_t
)attr
->group_tag
;
5587 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5591 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5592 attr
->num_values
> 1 ? "1setOf " : "",
5593 ippTagString(attr
->value_tag
)));
5596 * Write the attribute tag and name.
5598 * The attribute name length does not include the trailing nul
5599 * character in the source string.
5601 * Collection values (parent != NULL) are written differently...
5607 * Get the length of the attribute name, and make sure it won't
5608 * overflow the buffer...
5611 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5613 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5614 _cupsBufferRelease((char *)buffer
);
5615 return (IPP_STATE_ERROR
);
5619 * Write the value tag, name length, and name string...
5622 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5623 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5624 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5627 if (attr
->value_tag
> 0xff)
5629 *bufptr
++ = IPP_TAG_EXTENSION
;
5630 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5631 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5632 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5633 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5636 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5638 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5639 *bufptr
++ = (ipp_uchar_t
)n
;
5640 memcpy(bufptr
, attr
->name
, (size_t)n
);
5646 * Get the length of the attribute name, and make sure it won't
5647 * overflow the buffer...
5650 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5652 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5653 _cupsBufferRelease((char *)buffer
);
5654 return (IPP_STATE_ERROR
);
5658 * Write the member name tag, name length, name string, value tag,
5659 * and empty name for the collection member attribute...
5662 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5663 IPP_TAG_MEMBERNAME
));
5664 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5666 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5667 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5668 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5670 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5673 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5674 *bufptr
++ = (ipp_uchar_t
)n
;
5675 memcpy(bufptr
, attr
->name
, (size_t)n
);
5678 if (attr
->value_tag
> 0xff)
5680 *bufptr
++ = IPP_TAG_EXTENSION
;
5681 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5682 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5683 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5684 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5687 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5694 * Now write the attribute value(s)...
5697 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5699 case IPP_TAG_UNSUPPORTED_VALUE
:
5700 case IPP_TAG_DEFAULT
:
5701 case IPP_TAG_UNKNOWN
:
5702 case IPP_TAG_NOVALUE
:
5703 case IPP_TAG_NOTSETTABLE
:
5704 case IPP_TAG_DELETEATTR
:
5705 case IPP_TAG_ADMINDEFINE
:
5710 case IPP_TAG_INTEGER
:
5712 for (i
= 0, value
= attr
->values
;
5713 i
< attr
->num_values
;
5716 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5718 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5720 DEBUG_puts("1ippWriteIO: Could not write IPP "
5722 _cupsBufferRelease((char *)buffer
);
5723 return (IPP_STATE_ERROR
);
5732 * Arrays and sets are done by sending additional
5733 * values with a zero-length name...
5736 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5742 * Integers and enumerations are both 4-byte signed
5743 * (twos-complement) values.
5745 * Put the 2-byte length and 4-byte value into the buffer...
5750 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 24);
5751 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 16);
5752 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 8);
5753 *bufptr
++ = (ipp_uchar_t
)value
->integer
;
5757 case IPP_TAG_BOOLEAN
:
5758 for (i
= 0, value
= attr
->values
;
5759 i
< attr
->num_values
;
5762 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5764 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5766 DEBUG_puts("1ippWriteIO: Could not write IPP "
5768 _cupsBufferRelease((char *)buffer
);
5769 return (IPP_STATE_ERROR
);
5778 * Arrays and sets are done by sending additional
5779 * values with a zero-length name...
5782 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5788 * Boolean values are 1-byte; 0 = false, 1 = true.
5790 * Put the 2-byte length and 1-byte value into the buffer...
5795 *bufptr
++ = (ipp_uchar_t
)value
->boolean
;
5801 case IPP_TAG_KEYWORD
:
5803 case IPP_TAG_URISCHEME
:
5804 case IPP_TAG_CHARSET
:
5805 case IPP_TAG_LANGUAGE
:
5806 case IPP_TAG_MIMETYPE
:
5807 for (i
= 0, value
= attr
->values
;
5808 i
< attr
->num_values
;
5814 * Arrays and sets are done by sending additional
5815 * values with a zero-length name...
5818 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5820 ippTagString(attr
->value_tag
)));
5821 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5823 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5825 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5827 DEBUG_puts("1ippWriteIO: Could not write IPP "
5829 _cupsBufferRelease((char *)buffer
);
5830 return (IPP_STATE_ERROR
);
5836 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5841 if (value
->string
.text
!= NULL
)
5842 n
= (int)strlen(value
->string
.text
);
5846 if (n
> (IPP_BUF_SIZE
- 2))
5848 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5849 _cupsBufferRelease((char *)buffer
);
5850 return (IPP_STATE_ERROR
);
5853 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5854 value
->string
.text
));
5856 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5858 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5860 DEBUG_puts("1ippWriteIO: Could not write IPP "
5862 _cupsBufferRelease((char *)buffer
);
5863 return (IPP_STATE_ERROR
);
5870 * All simple strings consist of the 2-byte length and
5871 * character data without the trailing nul normally found
5872 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5873 * bytes since the 2-byte length is a signed (twos-complement)
5876 * Put the 2-byte length and string characters in the buffer.
5879 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5880 *bufptr
++ = (ipp_uchar_t
)n
;
5884 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5891 for (i
= 0, value
= attr
->values
;
5892 i
< attr
->num_values
;
5895 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5897 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5899 DEBUG_puts("1ippWriteIO: Could not write IPP "
5901 _cupsBufferRelease((char *)buffer
);
5902 return (IPP_STATE_ERROR
);
5911 * Arrays and sets are done by sending additional
5912 * values with a zero-length name...
5915 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5921 * Date values consist of a 2-byte length and an
5922 * 11-byte date/time structure defined by RFC 1903.
5924 * Put the 2-byte length and 11-byte date/time
5925 * structure in the buffer.
5930 memcpy(bufptr
, value
->date
, 11);
5935 case IPP_TAG_RESOLUTION
:
5936 for (i
= 0, value
= attr
->values
;
5937 i
< attr
->num_values
;
5940 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5942 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5944 DEBUG_puts("1ippWriteIO: Could not write IPP "
5946 _cupsBufferRelease((char *)buffer
);
5947 return (IPP_STATE_ERROR
);
5956 * Arrays and sets are done by sending additional
5957 * values with a zero-length name...
5960 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5966 * Resolution values consist of a 2-byte length,
5967 * 4-byte horizontal resolution value, 4-byte vertical
5968 * resolution value, and a 1-byte units value.
5970 * Put the 2-byte length and resolution value data
5976 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 24);
5977 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 16);
5978 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 8);
5979 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.xres
;
5980 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 24);
5981 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 16);
5982 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 8);
5983 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.yres
;
5984 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.units
;
5988 case IPP_TAG_RANGE
:
5989 for (i
= 0, value
= attr
->values
;
5990 i
< attr
->num_values
;
5993 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
5995 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5997 DEBUG_puts("1ippWriteIO: Could not write IPP "
5999 _cupsBufferRelease((char *)buffer
);
6000 return (IPP_STATE_ERROR
);
6009 * Arrays and sets are done by sending additional
6010 * values with a zero-length name...
6013 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6019 * Range values consist of a 2-byte length,
6020 * 4-byte lower value, and 4-byte upper value.
6022 * Put the 2-byte length and range value data
6028 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 24);
6029 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 16);
6030 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 8);
6031 *bufptr
++ = (ipp_uchar_t
)value
->range
.lower
;
6032 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 24);
6033 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 16);
6034 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 8);
6035 *bufptr
++ = (ipp_uchar_t
)value
->range
.upper
;
6039 case IPP_TAG_TEXTLANG
:
6040 case IPP_TAG_NAMELANG
:
6041 for (i
= 0, value
= attr
->values
;
6042 i
< attr
->num_values
;
6048 * Arrays and sets are done by sending additional
6049 * values with a zero-length name...
6052 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6054 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6056 DEBUG_puts("1ippWriteIO: Could not write IPP "
6058 _cupsBufferRelease((char *)buffer
);
6059 return (IPP_STATE_ERROR
);
6065 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6071 * textWithLanguage and nameWithLanguage values consist
6072 * of a 2-byte length for both strings and their
6073 * individual lengths, a 2-byte length for the
6074 * character string, the character string without the
6075 * trailing nul, a 2-byte length for the character
6076 * set string, and the character set string without
6082 if (value
->string
.language
!= NULL
)
6083 n
+= (int)strlen(value
->string
.language
);
6085 if (value
->string
.text
!= NULL
)
6086 n
+= (int)strlen(value
->string
.text
);
6088 if (n
> (IPP_BUF_SIZE
- 2))
6090 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
6091 "too long (%d)", n
));
6092 _cupsBufferRelease((char *)buffer
);
6093 return (IPP_STATE_ERROR
);
6096 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6098 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6100 DEBUG_puts("1ippWriteIO: Could not write IPP "
6102 _cupsBufferRelease((char *)buffer
);
6103 return (IPP_STATE_ERROR
);
6109 /* Length of entire value */
6110 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6111 *bufptr
++ = (ipp_uchar_t
)n
;
6113 /* Length of language */
6114 if (value
->string
.language
!= NULL
)
6115 n
= (int)strlen(value
->string
.language
);
6119 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6120 *bufptr
++ = (ipp_uchar_t
)n
;
6125 memcpy(bufptr
, value
->string
.language
, (size_t)n
);
6129 /* Length of text */
6130 if (value
->string
.text
!= NULL
)
6131 n
= (int)strlen(value
->string
.text
);
6135 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6136 *bufptr
++ = (ipp_uchar_t
)n
;
6141 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
6147 case IPP_TAG_BEGIN_COLLECTION
:
6148 for (i
= 0, value
= attr
->values
;
6149 i
< attr
->num_values
;
6153 * Collections are written with the begin-collection
6154 * tag first with a value of 0 length, followed by the
6155 * attributes in the collection, then the end-collection
6159 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6161 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6163 DEBUG_puts("1ippWriteIO: Could not write IPP "
6165 _cupsBufferRelease((char *)buffer
);
6166 return (IPP_STATE_ERROR
);
6175 * Arrays and sets are done by sending additional
6176 * values with a zero-length name...
6179 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6185 * Write a data length of 0 and flush the buffer...
6191 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6193 DEBUG_puts("1ippWriteIO: Could not write IPP "
6195 _cupsBufferRelease((char *)buffer
);
6196 return (IPP_STATE_ERROR
);
6202 * Then write the collection attribute...
6205 value
->collection
->state
= IPP_STATE_IDLE
;
6207 if (ippWriteIO(dst
, cb
, 1, ipp
,
6208 value
->collection
) == IPP_STATE_ERROR
)
6210 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6211 _cupsBufferRelease((char *)buffer
);
6212 return (IPP_STATE_ERROR
);
6218 for (i
= 0, value
= attr
->values
;
6219 i
< attr
->num_values
;
6225 * Arrays and sets are done by sending additional
6226 * values with a zero-length name...
6229 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6231 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6233 DEBUG_puts("1ippWriteIO: Could not write IPP "
6235 _cupsBufferRelease((char *)buffer
);
6236 return (IPP_STATE_ERROR
);
6242 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6248 * An unknown value might some new value that a
6249 * vendor has come up with. It consists of a
6250 * 2-byte length and the bytes in the unknown
6254 n
= value
->unknown
.length
;
6256 if (n
> (IPP_BUF_SIZE
- 2))
6258 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6260 _cupsBufferRelease((char *)buffer
);
6261 return (IPP_STATE_ERROR
);
6264 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6266 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6268 DEBUG_puts("1ippWriteIO: Could not write IPP "
6270 _cupsBufferRelease((char *)buffer
);
6271 return (IPP_STATE_ERROR
);
6277 /* Length of unknown value */
6278 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6279 *bufptr
++ = (ipp_uchar_t
)n
;
6284 memcpy(bufptr
, value
->unknown
.data
, (size_t)n
);
6292 * Write the data out...
6295 if (bufptr
> buffer
)
6297 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6299 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6300 _cupsBufferRelease((char *)buffer
);
6301 return (IPP_STATE_ERROR
);
6304 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6305 (int)(bufptr
- buffer
)));
6309 * If blocking is disabled and we aren't at the end of the attribute
6310 * list, stop here...
6313 if (!blocking
&& ipp
->current
)
6317 if (ipp
->current
== NULL
)
6320 * Done with all of the attributes; add the end-of-attributes
6321 * tag or end-collection attribute...
6326 buffer
[0] = IPP_TAG_END
;
6331 buffer
[0] = IPP_TAG_END_COLLECTION
;
6332 buffer
[1] = 0; /* empty name */
6334 buffer
[3] = 0; /* empty value */
6339 if ((*cb
)(dst
, buffer
, (size_t)n
) < 0)
6341 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6342 _cupsBufferRelease((char *)buffer
);
6343 return (IPP_STATE_ERROR
);
6346 ipp
->state
= IPP_STATE_DATA
;
6350 case IPP_STATE_DATA
:
6354 break; /* anti-compiler-warning-code */
6357 _cupsBufferRelease((char *)buffer
);
6359 return (ipp
->state
);
6364 * 'ipp_add_attr()' - Add a new attribute to the message.
6367 static ipp_attribute_t
* /* O - New attribute */
6368 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6369 const char *name
, /* I - Attribute name or NULL */
6370 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6371 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6372 int num_values
) /* I - Number of values */
6374 int alloc_values
; /* Number of values to allocate */
6375 ipp_attribute_t
*attr
; /* New attribute */
6378 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
));
6381 * Range check input...
6384 if (!ipp
|| num_values
< 0)
6388 * Allocate memory, rounding the allocation up as needed...
6391 if (num_values
<= 1)
6394 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6396 attr
= calloc(sizeof(ipp_attribute_t
) +
6397 (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6402 * Initialize attribute...
6406 attr
->name
= _cupsStrAlloc(name
);
6408 attr
->group_tag
= group_tag
;
6409 attr
->value_tag
= value_tag
;
6410 attr
->num_values
= num_values
;
6413 * Add it to the end of the linked list...
6417 ipp
->last
->next
= attr
;
6421 ipp
->prev
= ipp
->last
;
6422 ipp
->last
= ipp
->current
= attr
;
6425 DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr
));
6432 * 'ipp_free_values()' - Free attribute values.
6436 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6437 int element
,/* I - First value to free */
6438 int count
) /* I - Number of values to free */
6440 int i
; /* Looping var */
6441 _ipp_value_t
*value
; /* Current value */
6444 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", (void *)attr
, element
, count
));
6446 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6449 * Free values as needed...
6452 switch (attr
->value_tag
)
6454 case IPP_TAG_TEXTLANG
:
6455 case IPP_TAG_NAMELANG
:
6456 if (element
== 0 && count
== attr
->num_values
&&
6457 attr
->values
[0].string
.language
)
6459 _cupsStrFree(attr
->values
[0].string
.language
);
6460 attr
->values
[0].string
.language
= NULL
;
6462 /* Fall through to other string values */
6466 case IPP_TAG_RESERVED_STRING
:
6467 case IPP_TAG_KEYWORD
:
6469 case IPP_TAG_URISCHEME
:
6470 case IPP_TAG_CHARSET
:
6471 case IPP_TAG_LANGUAGE
:
6472 case IPP_TAG_MIMETYPE
:
6473 for (i
= count
, value
= attr
->values
+ element
;
6477 _cupsStrFree(value
->string
.text
);
6478 value
->string
.text
= NULL
;
6482 case IPP_TAG_DEFAULT
:
6483 case IPP_TAG_UNKNOWN
:
6484 case IPP_TAG_NOVALUE
:
6485 case IPP_TAG_NOTSETTABLE
:
6486 case IPP_TAG_DELETEATTR
:
6487 case IPP_TAG_ADMINDEFINE
:
6488 case IPP_TAG_INTEGER
:
6490 case IPP_TAG_BOOLEAN
:
6492 case IPP_TAG_RESOLUTION
:
6493 case IPP_TAG_RANGE
:
6496 case IPP_TAG_BEGIN_COLLECTION
:
6497 for (i
= count
, value
= attr
->values
+ element
;
6501 ippDelete(value
->collection
);
6502 value
->collection
= NULL
;
6506 case IPP_TAG_STRING
:
6508 for (i
= count
, value
= attr
->values
+ element
;
6512 if (value
->unknown
.data
)
6514 free(value
->unknown
.data
);
6515 value
->unknown
.data
= NULL
;
6523 * If we are not freeing values from the end, move the remaining values up...
6526 if ((element
+ count
) < attr
->num_values
)
6527 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6528 (size_t)(attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6530 attr
->num_values
-= count
;
6535 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6537 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6538 * to "ll-cc", "ll-region", and "charset-number", respectively.
6541 static char * /* O - Language code string */
6542 ipp_get_code(const char *value
, /* I - Locale/charset string */
6543 char *buffer
, /* I - String buffer */
6544 size_t bufsize
) /* I - Size of string buffer */
6546 char *bufptr
, /* Pointer into buffer */
6547 *bufend
; /* End of buffer */
6551 * Convert values to lowercase and change _ to - as needed...
6554 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6555 *value
&& bufptr
< bufend
;
6560 *bufptr
++ = (char)_cups_tolower(*value
);
6565 * Return the converted string...
6573 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6575 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6576 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6579 static char * /* O - Language code string */
6580 ipp_lang_code(const char *locale
, /* I - Locale string */
6581 char *buffer
, /* I - String buffer */
6582 size_t bufsize
) /* I - Size of string buffer */
6585 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6588 if (!_cups_strcasecmp(locale
, "c"))
6590 strlcpy(buffer
, "en", bufsize
);
6594 return (ipp_get_code(locale
, buffer
, bufsize
));
6599 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6602 static size_t /* O - Size of IPP message */
6603 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6604 int collection
) /* I - 1 if a collection, 0 otherwise */
6606 int i
; /* Looping var */
6607 size_t bytes
; /* Number of bytes */
6608 ipp_attribute_t
*attr
; /* Current attribute */
6609 ipp_tag_t group
; /* Current group */
6610 _ipp_value_t
*value
; /* Current value */
6613 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp
, collection
));
6617 DEBUG_puts("4ipp_length: Returning 0 bytes");
6622 * Start with 8 bytes for the IPP message header...
6625 bytes
= collection
? 0 : 8;
6628 * Then add the lengths of each attribute...
6631 group
= IPP_TAG_ZERO
;
6633 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6635 if (attr
->group_tag
!= group
&& !collection
)
6637 group
= attr
->group_tag
;
6638 if (group
== IPP_TAG_ZERO
)
6641 bytes
++; /* Group tag */
6647 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6648 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6650 if ((attr
->value_tag
& ~IPP_TAG_CUPS_CONST
) < IPP_TAG_EXTENSION
)
6651 bytes
+= (size_t)attr
->num_values
;/* Value tag for each value */
6653 bytes
+= (size_t)(5 * attr
->num_values
);
6654 /* Value tag for each value */
6655 bytes
+= (size_t)(2 * attr
->num_values
);
6657 bytes
+= strlen(attr
->name
); /* Name */
6658 bytes
+= (size_t)(2 * attr
->num_values
);
6662 bytes
+= 5; /* Add membername overhead */
6664 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6666 case IPP_TAG_UNSUPPORTED_VALUE
:
6667 case IPP_TAG_DEFAULT
:
6668 case IPP_TAG_UNKNOWN
:
6669 case IPP_TAG_NOVALUE
:
6670 case IPP_TAG_NOTSETTABLE
:
6671 case IPP_TAG_DELETEATTR
:
6672 case IPP_TAG_ADMINDEFINE
:
6675 case IPP_TAG_INTEGER
:
6677 bytes
+= (size_t)(4 * attr
->num_values
);
6680 case IPP_TAG_BOOLEAN
:
6681 bytes
+= (size_t)attr
->num_values
;
6686 case IPP_TAG_KEYWORD
:
6688 case IPP_TAG_URISCHEME
:
6689 case IPP_TAG_CHARSET
:
6690 case IPP_TAG_LANGUAGE
:
6691 case IPP_TAG_MIMETYPE
:
6692 for (i
= 0, value
= attr
->values
;
6693 i
< attr
->num_values
;
6695 if (value
->string
.text
)
6696 bytes
+= strlen(value
->string
.text
);
6700 bytes
+= (size_t)(11 * attr
->num_values
);
6703 case IPP_TAG_RESOLUTION
:
6704 bytes
+= (size_t)(9 * attr
->num_values
);
6707 case IPP_TAG_RANGE
:
6708 bytes
+= (size_t)(8 * attr
->num_values
);
6711 case IPP_TAG_TEXTLANG
:
6712 case IPP_TAG_NAMELANG
:
6713 bytes
+= (size_t)(4 * attr
->num_values
);
6714 /* Charset + text length */
6716 for (i
= 0, value
= attr
->values
;
6717 i
< attr
->num_values
;
6720 if (value
->string
.language
)
6721 bytes
+= strlen(value
->string
.language
);
6723 if (value
->string
.text
)
6724 bytes
+= strlen(value
->string
.text
);
6728 case IPP_TAG_BEGIN_COLLECTION
:
6729 for (i
= 0, value
= attr
->values
;
6730 i
< attr
->num_values
;
6732 bytes
+= ipp_length(value
->collection
, 1);
6736 for (i
= 0, value
= attr
->values
;
6737 i
< attr
->num_values
;
6739 bytes
+= (size_t)value
->unknown
.length
;
6745 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6746 * for the "end of collection" tag and return...
6754 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6761 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6764 static ssize_t
/* O - Number of bytes read */
6765 ipp_read_http(http_t
*http
, /* I - Client connection */
6766 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6767 size_t length
) /* I - Total length */
6769 ssize_t tbytes
, /* Total bytes read */
6770 bytes
; /* Bytes read this pass */
6773 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http
, (void *)buffer
, (int)length
));
6776 * Loop until all bytes are read...
6779 for (tbytes
= 0, bytes
= 0;
6780 tbytes
< (int)length
;
6781 tbytes
+= bytes
, buffer
+= bytes
)
6783 DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT
", http->state=%d", CUPS_LLCAST tbytes
, http
->state
));
6785 if (http
->state
== HTTP_STATE_WAITING
)
6788 if (http
->used
== 0 && !http
->blocking
)
6791 * Wait up to 10 seconds for more data on non-blocking sockets...
6794 if (!httpWait(http
, 10000))
6804 else if (http
->used
== 0 && http
->timeout_value
> 0)
6807 * Wait up to timeout seconds for more data on blocking sockets...
6810 if (!httpWait(http
, (int)(1000 * http
->timeout_value
)))
6821 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- (size_t)tbytes
)) < 0)
6826 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6832 else if (bytes
== 0)
6837 * Return the number of bytes read...
6840 if (tbytes
== 0 && bytes
< 0)
6843 DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST tbytes
));
6850 * 'ipp_read_file()' - Read IPP data from a file.
6853 static ssize_t
/* O - Number of bytes read */
6854 ipp_read_file(int *fd
, /* I - File descriptor */
6855 ipp_uchar_t
*buffer
, /* O - Read buffer */
6856 size_t length
) /* I - Number of bytes to read */
6859 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6861 return (read(*fd
, buffer
, length
));
6867 * 'ipp_set_error()' - Set a formatted, localized error string.
6871 ipp_set_error(ipp_status_t status
, /* I - Status code */
6872 const char *format
, /* I - Printf-style error string */
6873 ...) /* I - Additional arguments as needed */
6875 va_list ap
; /* Pointer to additional args */
6876 char buffer
[2048]; /* Message buffer */
6877 cups_lang_t
*lang
= cupsLangDefault();
6878 /* Current language */
6881 va_start(ap
, format
);
6882 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6885 _cupsSetError(status
, buffer
, 0);
6890 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6894 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6895 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6896 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6897 int element
) /* I - Value number (0-based) */
6899 ipp_attribute_t
*temp
, /* New attribute pointer */
6900 *current
, /* Current attribute in list */
6901 *prev
; /* Previous attribute in list */
6902 int alloc_values
; /* Allocated values */
6906 * If we are setting an existing value element, return it...
6911 if (temp
->num_values
<= 1)
6914 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6915 ~(IPP_MAX_VALUES
- 1);
6917 if (element
< alloc_values
)
6919 if (element
>= temp
->num_values
)
6920 temp
->num_values
= element
+ 1;
6922 return (temp
->values
+ element
);
6926 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6927 * values when num_values > 1.
6930 if (alloc_values
< IPP_MAX_VALUES
)
6931 alloc_values
= IPP_MAX_VALUES
;
6933 alloc_values
+= IPP_MAX_VALUES
;
6935 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6939 * Reallocate memory...
6942 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) + (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6944 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6945 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6950 * Zero the new memory...
6953 memset(temp
->values
+ temp
->num_values
, 0, (size_t)(alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6958 * Reset pointers in the list...
6961 if (ipp
->current
== *attr
&& ipp
->prev
)
6964 * Use current "previous" pointer...
6972 * Find this attribute in the linked list...
6975 for (prev
= NULL
, current
= ipp
->attrs
;
6976 current
&& current
!= *attr
;
6977 prev
= current
, current
= current
->next
);
6982 * This is a serious error!
6986 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
6987 _("IPP attribute is not a member of the message."), 1);
6988 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
6998 ipp
->current
= temp
;
7001 if (ipp
->last
== *attr
)
7008 * Return the value element...
7011 if (element
>= temp
->num_values
)
7012 temp
->num_values
= element
+ 1;
7014 return (temp
->values
+ element
);
7019 * 'ipp_write_file()' - Write IPP data to a file.
7022 static ssize_t
/* O - Number of bytes written */
7023 ipp_write_file(int *fd
, /* I - File descriptor */
7024 ipp_uchar_t
*buffer
, /* I - Data to write */
7025 size_t length
) /* I - Number of bytes to write */
7028 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
7030 return (write(*fd
, buffer
, length
));