2 * Internet Printing Protocol functions for CUPS.
4 * Copyright 2007-2015 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 date 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 * language, mimeMediaType, name, text, URI, or URI scheme 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 1903 Date/Time format to UNIX time
1766 time_t /* O - UNIX time value */
1767 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 1903 date info */
1769 struct tm unixdate
; /* UNIX date/time info */
1770 time_t t
; /* Computed time */
1776 memset(&unixdate
, 0, sizeof(unixdate
));
1779 * RFC-1903 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 * @link 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 * @link 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 date value for an attribute.
2237 * The @code element@ parameter specifies which value to get from 0 to
2238 * @link ippGetCount(attr)@ - 1.
2240 * @since CUPS 1.6/macOS 10.8@
2243 const ipp_uchar_t
* /* O - Date 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 * @link 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 * @link 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 * @link 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 * @link 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 * @link 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) */
2574 * Range check input...
2577 if (!attr
|| element
< 0 || element
>= attr
->num_values
||
2578 (attr
->value_tag
!= IPP_TAG_TEXTLANG
&& attr
->value_tag
!= IPP_TAG_NAMELANG
&&
2579 (attr
->value_tag
< IPP_TAG_TEXT
|| attr
->value_tag
> IPP_TAG_MIMETYPE
)))
2583 * Return the value...
2587 *language
= attr
->values
[element
].string
.language
;
2589 return (attr
->values
[element
].string
.text
);
2594 * 'ippGetValueTag()' - Get the value tag for an attribute.
2596 * @since CUPS 1.6/macOS 10.8@
2599 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2600 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2603 * Range check input...
2607 return (IPP_TAG_ZERO
);
2610 * Return the value...
2613 return (attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2618 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2620 * @since CUPS 1.6/macOS 10.8@
2623 int /* O - Major version number or 0 on error */
2624 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2625 int *minor
) /* O - Minor version number or @code NULL@ */
2628 * Range check input...
2640 * Return the value...
2644 *minor
= ipp
->request
.any
.version
[1];
2646 return (ipp
->request
.any
.version
[0]);
2651 * 'ippLength()' - Compute the length of an IPP message.
2654 size_t /* O - Size of IPP message */
2655 ippLength(ipp_t
*ipp
) /* I - IPP message */
2657 return (ipp_length(ipp
, 0));
2662 * 'ippNextAttribute()' - Return the next attribute in the message.
2664 * @since CUPS 1.6/macOS 10.8@
2667 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2668 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2671 * Range check input...
2674 if (!ipp
|| !ipp
->current
)
2678 * Return the next attribute...
2681 return (ipp
->current
= ipp
->current
->next
);
2686 * 'ippNew()' - Allocate a new IPP message.
2689 ipp_t
* /* O - New IPP message */
2692 ipp_t
*temp
; /* New IPP message */
2693 _cups_globals_t
*cg
= _cupsGlobals();
2697 DEBUG_puts("ippNew()");
2699 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2702 * Set default version - usually 2.0...
2705 if (cg
->server_version
== 0)
2708 temp
->request
.any
.version
[0] = (ipp_uchar_t
)(cg
->server_version
/ 10);
2709 temp
->request
.any
.version
[1] = (ipp_uchar_t
)(cg
->server_version
% 10);
2713 DEBUG_printf(("1ippNew: Returning %p", (void *)temp
));
2720 * 'ippNewRequest()' - Allocate a new IPP request message.
2722 * The new request message is initialized with the attributes-charset and
2723 * attributes-natural-language attributes added. The
2724 * attributes-natural-language value is derived from the current locale.
2726 * @since CUPS 1.2/macOS 10.5@
2729 ipp_t
* /* O - IPP request message */
2730 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2732 ipp_t
*request
; /* IPP request message */
2733 cups_lang_t
*language
; /* Current language localization */
2734 static int request_id
= 0; /* Current request ID */
2735 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2736 /* Mutex for request ID */
2739 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2742 * Create a new IPP message...
2745 if ((request
= ippNew()) == NULL
)
2749 * Set the operation and request ID...
2752 _cupsMutexLock(&request_mutex
);
2754 request
->request
.op
.operation_id
= op
;
2755 request
->request
.op
.request_id
= ++request_id
;
2757 _cupsMutexUnlock(&request_mutex
);
2760 * Use UTF-8 as the character set...
2763 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2764 "attributes-charset", NULL
, "utf-8");
2767 * Get the language from the current locale...
2770 language
= cupsLangDefault();
2772 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2773 "attributes-natural-language", NULL
, language
->language
);
2776 * Return the new request...
2784 * 'ippNewResponse()' - Allocate a new IPP response message.
2786 * The new response message is initialized with the same version-number,
2787 * request-id, attributes-charset, and attributes-natural-language as the
2788 * provided request message. If the attributes-charset or
2789 * attributes-natural-language attributes are missing from the request,
2790 * "utf-8" and a value derived from the current locale are substituted,
2793 * @since CUPS 1.7/macOS 10.9@
2796 ipp_t
* /* O - IPP response message */
2797 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2799 ipp_t
*response
; /* IPP response message */
2800 ipp_attribute_t
*attr
; /* Current attribute */
2804 * Range check input...
2811 * Create a new IPP message...
2814 if ((response
= ippNew()) == NULL
)
2818 * Copy the request values over to the response...
2821 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2822 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2823 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2826 * The first attribute MUST be attributes-charset...
2829 attr
= request
->attrs
;
2831 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2832 attr
->group_tag
== IPP_TAG_OPERATION
&&
2833 attr
->value_tag
== IPP_TAG_CHARSET
&&
2834 attr
->num_values
== 1)
2837 * Copy charset from request...
2840 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2841 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2846 * Use "utf-8" as the default...
2849 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2850 "attributes-charset", NULL
, "utf-8");
2854 * Then attributes-natural-language...
2860 if (attr
&& attr
->name
&&
2861 !strcmp(attr
->name
, "attributes-natural-language") &&
2862 attr
->group_tag
== IPP_TAG_OPERATION
&&
2863 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2864 attr
->num_values
== 1)
2867 * Copy language from request...
2870 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2871 "attributes-natural-language", NULL
,
2872 attr
->values
[0].string
.text
);
2877 * Use the language from the current locale...
2880 cups_lang_t
*language
= cupsLangDefault();
2881 /* Current locale */
2883 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2884 "attributes-natural-language", NULL
, language
->language
);
2892 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2895 ipp_state_t
/* O - Current state */
2896 ippRead(http_t
*http
, /* I - HTTP connection */
2897 ipp_t
*ipp
) /* I - IPP data */
2899 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
, (void *)http
, (void *)ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2902 return (IPP_STATE_ERROR
);
2904 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
, http
->used
));
2906 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2912 * 'ippReadFile()' - Read data for an IPP message from a file.
2914 * @since CUPS 1.1.19/macOS 10.3@
2917 ipp_state_t
/* O - Current state */
2918 ippReadFile(int fd
, /* I - HTTP data */
2919 ipp_t
*ipp
) /* I - IPP data */
2921 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
2923 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2928 * 'ippReadIO()' - Read data for an IPP message.
2930 * @since CUPS 1.2/macOS 10.5@
2933 ipp_state_t
/* O - Current state */
2934 ippReadIO(void *src
, /* I - Data source */
2935 ipp_iocb_t cb
, /* I - Read callback function */
2936 int blocking
, /* I - Use blocking IO? */
2937 ipp_t
*parent
, /* I - Parent request, if any */
2938 ipp_t
*ipp
) /* I - IPP data */
2940 int n
; /* Length of data */
2941 unsigned char *buffer
, /* Data buffer */
2942 string
[IPP_MAX_TEXT
],
2943 /* Small string buffer */
2944 *bufptr
; /* Pointer into buffer */
2945 ipp_attribute_t
*attr
; /* Current attribute */
2946 ipp_tag_t tag
; /* Current tag */
2947 ipp_tag_t value_tag
; /* Current value tag */
2948 _ipp_value_t
*value
; /* Current value */
2951 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)src
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
2952 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_STATE_ERROR
));
2955 return (IPP_STATE_ERROR
);
2957 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2959 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2960 return (IPP_STATE_ERROR
);
2965 case IPP_STATE_IDLE
:
2966 ipp
->state
++; /* Avoid common problem... */
2968 case IPP_STATE_HEADER
:
2972 * Get the request header...
2975 if ((*cb
)(src
, buffer
, 8) < 8)
2977 DEBUG_puts("1ippReadIO: Unable to read header.");
2978 _cupsBufferRelease((char *)buffer
);
2979 return (IPP_STATE_ERROR
);
2983 * Then copy the request header over...
2986 ipp
->request
.any
.version
[0] = buffer
[0];
2987 ipp
->request
.any
.version
[1] = buffer
[1];
2988 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
2989 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
2990 buffer
[6]) << 8) | buffer
[7];
2992 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
2993 DEBUG_printf(("2ippReadIO: op_status=%04x",
2994 ipp
->request
.any
.op_status
));
2995 DEBUG_printf(("2ippReadIO: request_id=%d",
2996 ipp
->request
.any
.request_id
));
2999 ipp
->state
= IPP_STATE_ATTRIBUTE
;
3000 ipp
->current
= NULL
;
3001 ipp
->curtag
= IPP_TAG_ZERO
;
3002 ipp
->prev
= ipp
->last
;
3005 * If blocking is disabled, stop here...
3011 case IPP_STATE_ATTRIBUTE
:
3014 if ((*cb
)(src
, buffer
, 1) < 1)
3016 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3017 _cupsBufferRelease((char *)buffer
);
3018 return (IPP_STATE_ERROR
);
3021 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3024 * Read this attribute...
3027 tag
= (ipp_tag_t
)buffer
[0];
3028 if (tag
== IPP_TAG_EXTENSION
)
3031 * Read 32-bit "extension" tag...
3034 if ((*cb
)(src
, buffer
, 4) < 1)
3036 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3037 _cupsBufferRelease((char *)buffer
);
3038 return (IPP_STATE_ERROR
);
3041 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
3042 buffer
[2]) << 8) | buffer
[3]);
3044 if (tag
& IPP_TAG_CUPS_CONST
)
3047 * Fail if the high bit is set in the tag...
3050 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
3051 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
3052 _cupsBufferRelease((char *)buffer
);
3053 return (IPP_STATE_ERROR
);
3057 if (tag
== IPP_TAG_END
)
3060 * No more attributes left...
3063 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
3065 ipp
->state
= IPP_STATE_DATA
;
3068 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3071 * Group tag... Set the current group and continue...
3074 if (ipp
->curtag
== tag
)
3075 ipp
->prev
= ippAddSeparator(ipp
);
3076 else if (ipp
->current
)
3077 ipp
->prev
= ipp
->current
;
3080 ipp
->current
= NULL
;
3081 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
, ippTagString(tag
), (void *)ipp
->prev
));
3085 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3086 ippTagString(tag
)));
3092 if ((*cb
)(src
, buffer
, 2) < 2)
3094 DEBUG_puts("1ippReadIO: unable to read name length.");
3095 _cupsBufferRelease((char *)buffer
);
3096 return (IPP_STATE_ERROR
);
3099 n
= (buffer
[0] << 8) | buffer
[1];
3101 if (n
>= IPP_BUF_SIZE
)
3103 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3104 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3105 _cupsBufferRelease((char *)buffer
);
3106 return (IPP_STATE_ERROR
);
3109 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3111 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3112 tag
!= IPP_TAG_END_COLLECTION
)
3115 * More values for current attribute...
3118 if (ipp
->current
== NULL
)
3120 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3121 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3122 _cupsBufferRelease((char *)buffer
);
3123 return (IPP_STATE_ERROR
);
3126 attr
= ipp
->current
;
3127 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3130 * Make sure we aren't adding a new value of a different
3134 if (value_tag
== IPP_TAG_ZERO
)
3137 * Setting the value of a collection member...
3140 attr
->value_tag
= tag
;
3142 else if (value_tag
== IPP_TAG_TEXTLANG
||
3143 value_tag
== IPP_TAG_NAMELANG
||
3144 (value_tag
>= IPP_TAG_TEXT
&&
3145 value_tag
<= IPP_TAG_MIMETYPE
))
3148 * String values can sometimes come across in different
3149 * forms; accept sets of differing values...
3152 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3153 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3154 tag
!= IPP_TAG_NOVALUE
)
3156 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3157 _("IPP 1setOf attribute with incompatible value "
3159 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3160 value_tag
, ippTagString(value_tag
), tag
,
3161 ippTagString(tag
)));
3162 _cupsBufferRelease((char *)buffer
);
3163 return (IPP_STATE_ERROR
);
3166 if (value_tag
!= tag
)
3168 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3169 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3170 ippSetValueTag(ipp
, &attr
, tag
);
3173 else if (value_tag
== IPP_TAG_INTEGER
||
3174 value_tag
== IPP_TAG_RANGE
)
3177 * Integer and rangeOfInteger values can sometimes be mixed; accept
3178 * sets of differing values...
3181 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3183 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3184 _("IPP 1setOf attribute with incompatible value "
3186 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3187 value_tag
, ippTagString(value_tag
), tag
,
3188 ippTagString(tag
)));
3189 _cupsBufferRelease((char *)buffer
);
3190 return (IPP_STATE_ERROR
);
3193 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3196 * Convert integer values to rangeOfInteger values...
3199 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3200 "rangeOfInteger.", attr
->name
));
3201 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3204 else if (value_tag
!= tag
)
3206 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3207 _("IPP 1setOf attribute with incompatible value "
3209 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3210 value_tag
, ippTagString(value_tag
), tag
,
3211 ippTagString(tag
)));
3212 _cupsBufferRelease((char *)buffer
);
3213 return (IPP_STATE_ERROR
);
3217 * Finally, reallocate the attribute array as needed...
3220 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3222 _cupsBufferRelease((char *)buffer
);
3223 return (IPP_STATE_ERROR
);
3226 else if (tag
== IPP_TAG_MEMBERNAME
)
3229 * Name must be length 0!
3234 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3235 DEBUG_puts("1ippReadIO: member name not empty.");
3236 _cupsBufferRelease((char *)buffer
);
3237 return (IPP_STATE_ERROR
);
3241 ipp
->prev
= ipp
->current
;
3243 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3246 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3247 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3248 _cupsBufferRelease((char *)buffer
);
3249 return (IPP_STATE_ERROR
);
3252 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3254 value
= attr
->values
;
3256 else if (tag
!= IPP_TAG_END_COLLECTION
)
3259 * New attribute; read the name and add it...
3262 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3264 DEBUG_puts("1ippReadIO: unable to read name.");
3265 _cupsBufferRelease((char *)buffer
);
3266 return (IPP_STATE_ERROR
);
3272 ipp
->prev
= ipp
->current
;
3274 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3277 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3278 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3279 _cupsBufferRelease((char *)buffer
);
3280 return (IPP_STATE_ERROR
);
3283 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer
, (void *)ipp
->current
, (void *)ipp
->prev
));
3285 value
= attr
->values
;
3293 if ((*cb
)(src
, buffer
, 2) < 2)
3295 DEBUG_puts("1ippReadIO: unable to read value length.");
3296 _cupsBufferRelease((char *)buffer
);
3297 return (IPP_STATE_ERROR
);
3300 n
= (buffer
[0] << 8) | buffer
[1];
3301 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3303 if (n
>= IPP_BUF_SIZE
)
3305 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3306 _("IPP value larger than 32767 bytes."), 1);
3307 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3308 _cupsBufferRelease((char *)buffer
);
3309 return (IPP_STATE_ERROR
);
3314 case IPP_TAG_INTEGER
:
3318 if (tag
== IPP_TAG_INTEGER
)
3319 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3320 _("IPP integer value not 4 bytes."), 1);
3322 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3323 _("IPP enum value not 4 bytes."), 1);
3324 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3325 _cupsBufferRelease((char *)buffer
);
3326 return (IPP_STATE_ERROR
);
3329 if ((*cb
)(src
, buffer
, 4) < 4)
3331 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3332 _cupsBufferRelease((char *)buffer
);
3333 return (IPP_STATE_ERROR
);
3336 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3339 if (attr
->value_tag
== IPP_TAG_RANGE
)
3340 value
->range
.lower
= value
->range
.upper
= n
;
3345 case IPP_TAG_BOOLEAN
:
3348 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3350 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3351 _cupsBufferRelease((char *)buffer
);
3352 return (IPP_STATE_ERROR
);
3355 if ((*cb
)(src
, buffer
, 1) < 1)
3357 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3358 _cupsBufferRelease((char *)buffer
);
3359 return (IPP_STATE_ERROR
);
3362 value
->boolean
= (char)buffer
[0];
3365 case IPP_TAG_NOVALUE
:
3366 case IPP_TAG_NOTSETTABLE
:
3367 case IPP_TAG_DELETEATTR
:
3368 case IPP_TAG_ADMINDEFINE
:
3370 * These value types are not supposed to have values, however
3371 * some vendors (Brother) do not implement IPP correctly and so
3372 * we need to map non-empty values to text...
3375 if (attr
->value_tag
== tag
)
3380 attr
->value_tag
= IPP_TAG_TEXT
;
3385 case IPP_TAG_KEYWORD
:
3387 case IPP_TAG_URISCHEME
:
3388 case IPP_TAG_CHARSET
:
3389 case IPP_TAG_LANGUAGE
:
3390 case IPP_TAG_MIMETYPE
:
3393 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3395 DEBUG_puts("1ippReadIO: unable to read string value.");
3396 _cupsBufferRelease((char *)buffer
);
3397 return (IPP_STATE_ERROR
);
3402 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3403 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3409 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3410 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3411 _cupsBufferRelease((char *)buffer
);
3412 return (IPP_STATE_ERROR
);
3415 if ((*cb
)(src
, value
->date
, 11) < 11)
3417 DEBUG_puts("1ippReadIO: Unable to read date value.");
3418 _cupsBufferRelease((char *)buffer
);
3419 return (IPP_STATE_ERROR
);
3423 case IPP_TAG_RESOLUTION
:
3426 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3427 _("IPP resolution value not 9 bytes."), 1);
3428 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3429 _cupsBufferRelease((char *)buffer
);
3430 return (IPP_STATE_ERROR
);
3433 if ((*cb
)(src
, buffer
, 9) < 9)
3435 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3436 _cupsBufferRelease((char *)buffer
);
3437 return (IPP_STATE_ERROR
);
3440 value
->resolution
.xres
=
3441 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3443 value
->resolution
.yres
=
3444 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3446 value
->resolution
.units
=
3447 (ipp_res_t
)buffer
[8];
3450 case IPP_TAG_RANGE
:
3453 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3454 _("IPP rangeOfInteger value not 8 bytes."), 1);
3455 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3457 _cupsBufferRelease((char *)buffer
);
3458 return (IPP_STATE_ERROR
);
3461 if ((*cb
)(src
, buffer
, 8) < 8)
3463 DEBUG_puts("1ippReadIO: Unable to read range value.");
3464 _cupsBufferRelease((char *)buffer
);
3465 return (IPP_STATE_ERROR
);
3468 value
->range
.lower
=
3469 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3471 value
->range
.upper
=
3472 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3476 case IPP_TAG_TEXTLANG
:
3477 case IPP_TAG_NAMELANG
:
3480 if (tag
== IPP_TAG_TEXTLANG
)
3481 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3482 _("IPP textWithLanguage value less than "
3483 "minimum 4 bytes."), 1);
3485 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3486 _("IPP nameWithLanguage value less than "
3487 "minimum 4 bytes."), 1);
3488 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3490 _cupsBufferRelease((char *)buffer
);
3491 return (IPP_STATE_ERROR
);
3494 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3496 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3498 _cupsBufferRelease((char *)buffer
);
3499 return (IPP_STATE_ERROR
);
3505 * text-with-language and name-with-language are composite
3514 n
= (bufptr
[0] << 8) | bufptr
[1];
3516 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) || n
>= (int)sizeof(string
))
3518 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3519 _("IPP language length overflows value."), 1);
3520 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3522 _cupsBufferRelease((char *)buffer
);
3523 return (IPP_STATE_ERROR
);
3525 else if (n
>= IPP_MAX_LANGUAGE
)
3527 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3528 _("IPP language length too large."), 1);
3529 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3531 _cupsBufferRelease((char *)buffer
);
3532 return (IPP_STATE_ERROR
);
3535 memcpy(string
, bufptr
+ 2, (size_t)n
);
3538 value
->string
.language
= _cupsStrAlloc((char *)string
);
3541 n
= (bufptr
[0] << 8) | bufptr
[1];
3543 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3545 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3546 _("IPP string length overflows value."), 1);
3547 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3548 _cupsBufferRelease((char *)buffer
);
3549 return (IPP_STATE_ERROR
);
3552 bufptr
[2 + n
] = '\0';
3553 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3556 case IPP_TAG_BEGIN_COLLECTION
:
3558 * Oh, boy, here comes a collection value, so read it...
3561 value
->collection
= ippNew();
3565 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3566 _("IPP begCollection value not 0 bytes."), 1);
3567 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3569 _cupsBufferRelease((char *)buffer
);
3570 return (IPP_STATE_ERROR
);
3573 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3575 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3576 _cupsBufferRelease((char *)buffer
);
3577 return (IPP_STATE_ERROR
);
3581 case IPP_TAG_END_COLLECTION
:
3582 _cupsBufferRelease((char *)buffer
);
3586 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3587 _("IPP endCollection value not 0 bytes."), 1);
3588 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3590 return (IPP_STATE_ERROR
);
3593 DEBUG_puts("1ippReadIO: endCollection tag...");
3594 return (ipp
->state
= IPP_STATE_DATA
);
3596 case IPP_TAG_MEMBERNAME
:
3598 * The value the name of the member in the collection, which
3599 * we need to carry over...
3604 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3605 _("IPP memberName with no attribute."), 1);
3606 DEBUG_puts("1ippReadIO: Member name without attribute.");
3607 _cupsBufferRelease((char *)buffer
);
3608 return (IPP_STATE_ERROR
);
3612 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3613 _("IPP memberName value is empty."), 1);
3614 DEBUG_puts("1ippReadIO: Empty member name value.");
3615 _cupsBufferRelease((char *)buffer
);
3616 return (IPP_STATE_ERROR
);
3618 else if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3620 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3621 _cupsBufferRelease((char *)buffer
);
3622 return (IPP_STATE_ERROR
);
3626 attr
->name
= _cupsStrAlloc((char *)buffer
);
3629 * Since collection members are encoded differently than
3630 * regular attributes, make sure we don't start with an
3634 attr
->num_values
--;
3636 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3639 default : /* Other unsupported values */
3640 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3642 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3643 _("IPP octetString length too large."), 1);
3644 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3646 _cupsBufferRelease((char *)buffer
);
3647 return (IPP_STATE_ERROR
);
3650 value
->unknown
.length
= n
;
3654 if ((value
->unknown
.data
= malloc((size_t)n
)) == NULL
)
3656 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3657 DEBUG_puts("1ippReadIO: Unable to allocate value");
3658 _cupsBufferRelease((char *)buffer
);
3659 return (IPP_STATE_ERROR
);
3662 if ((*cb
)(src
, value
->unknown
.data
, (size_t)n
) < n
)
3664 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3665 _cupsBufferRelease((char *)buffer
);
3666 return (IPP_STATE_ERROR
);
3670 value
->unknown
.data
= NULL
;
3675 * If blocking is disabled, stop here...
3683 case IPP_STATE_DATA
:
3687 break; /* anti-compiler-warning-code */
3690 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3691 _cupsBufferRelease((char *)buffer
);
3693 return (ipp
->state
);
3698 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3700 * The @code ipp@ parameter refers to an IPP message previously created using
3701 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3703 * The @code attr@ parameter may be modified as a result of setting the value.
3705 * The @code element@ parameter specifies which value to set from 0 to
3706 * @link ippGetCount(attr)@.
3708 * @since CUPS 1.6/macOS 10.8@
3711 int /* O - 1 on success, 0 on failure */
3712 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3713 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3714 int element
, /* I - Value number (0-based) */
3715 int boolvalue
)/* I - Boolean value */
3717 _ipp_value_t
*value
; /* Current value */
3721 * Range check input...
3724 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3725 element
< 0 || element
> (*attr
)->num_values
)
3729 * Set the value and return...
3732 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3733 value
->boolean
= (char)boolvalue
;
3735 return (value
!= NULL
);
3740 * 'ippSetCollection()' - Set a collection value in an attribute.
3742 * The @code ipp@ parameter refers to an IPP message previously created using
3743 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3745 * The @code attr@ parameter may be modified as a result of setting the value.
3747 * The @code element@ parameter specifies which value to set from 0 to
3748 * @link ippGetCount(attr)@.
3750 * @since CUPS 1.6/macOS 10.8@
3753 int /* O - 1 on success, 0 on failure */
3755 ipp_t
*ipp
, /* I - IPP message */
3756 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3757 int element
, /* I - Value number (0-based) */
3758 ipp_t
*colvalue
) /* I - Collection value */
3760 _ipp_value_t
*value
; /* Current value */
3764 * Range check input...
3767 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3768 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3772 * Set the value and return...
3775 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3777 if (value
->collection
)
3778 ippDelete(value
->collection
);
3780 value
->collection
= colvalue
;
3784 return (value
!= NULL
);
3789 * 'ippSetDate()' - Set a date value in an attribute.
3791 * The @code ipp@ parameter refers to an IPP message previously created using
3792 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3794 * The @code attr@ parameter may be modified as a result of setting the value.
3796 * The @code element@ parameter specifies which value to set from 0 to
3797 * @link ippGetCount(attr)@.
3799 * @since CUPS 1.6/macOS 10.8@
3802 int /* O - 1 on success, 0 on failure */
3803 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3804 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3805 int element
, /* I - Value number (0-based) */
3806 const ipp_uchar_t
*datevalue
)/* I - Date value */
3808 _ipp_value_t
*value
; /* Current value */
3812 * Range check input...
3815 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3816 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3820 * Set the value and return...
3823 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3824 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3826 return (value
!= NULL
);
3831 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3833 * The @code ipp@ parameter refers to an IPP message previously created using
3834 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3836 * The @code attr@ parameter may be modified as a result of setting the value.
3838 * The @code group@ parameter specifies the IPP attribute group tag: none
3839 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3840 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3841 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3842 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3844 * @since CUPS 1.6/macOS 10.8@
3847 int /* O - 1 on success, 0 on failure */
3849 ipp_t
*ipp
, /* I - IPP message */
3850 ipp_attribute_t
**attr
, /* IO - Attribute */
3851 ipp_tag_t group_tag
) /* I - Group tag */
3854 * Range check input - group tag must be 0x01 to 0x0F, per RFC 2911...
3857 if (!ipp
|| !attr
|| !*attr
||
3858 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3859 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3863 * Set the group tag and return...
3866 (*attr
)->group_tag
= group_tag
;
3873 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3875 * The @code ipp@ parameter refers to an IPP message previously created using
3876 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3878 * The @code attr@ parameter may be modified as a result of setting the value.
3880 * The @code element@ parameter specifies which value to set from 0 to
3881 * @link ippGetCount(attr)@.
3883 * @since CUPS 1.6/macOS 10.8@
3886 int /* O - 1 on success, 0 on failure */
3887 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3888 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3889 int element
, /* I - Value number (0-based) */
3890 int intvalue
) /* I - Integer/enum value */
3892 _ipp_value_t
*value
; /* Current value */
3896 * Range check input...
3899 if (!ipp
|| !attr
|| !*attr
||
3900 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3901 element
< 0 || element
> (*attr
)->num_values
)
3905 * Set the value and return...
3908 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3909 value
->integer
= intvalue
;
3911 return (value
!= NULL
);
3916 * 'ippSetName()' - Set the name of an attribute.
3918 * The @code ipp@ parameter refers to an IPP message previously created using
3919 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3921 * The @code attr@ parameter may be modified as a result of setting the value.
3923 * @since CUPS 1.6/macOS 10.8@
3926 int /* O - 1 on success, 0 on failure */
3927 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3928 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3929 const char *name
) /* I - Attribute name */
3931 char *temp
; /* Temporary name value */
3935 * Range check input...
3938 if (!ipp
|| !attr
|| !*attr
)
3942 * Set the value and return...
3945 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3948 _cupsStrFree((*attr
)->name
);
3950 (*attr
)->name
= temp
;
3953 return (temp
!= NULL
);
3958 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
3960 * The @code ipp@ parameter refers to an IPP message previously created using
3961 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3963 * The @code attr@ parameter may be modified as a result of setting the value.
3965 * The @code element@ parameter specifies which value to set from 0 to
3966 * @link ippGetCount(attr)@.
3968 * @since CUPS 1.7/macOS 10.9@
3971 int /* O - 1 on success, 0 on failure */
3973 ipp_t
*ipp
, /* I - IPP message */
3974 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3975 int element
, /* I - Value number (0-based) */
3976 const void *data
, /* I - Pointer to octetString data */
3977 int datalen
) /* I - Length of octetString data */
3979 _ipp_value_t
*value
; /* Current value */
3983 * Range check input...
3986 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_STRING
||
3987 element
< 0 || element
> (*attr
)->num_values
||
3988 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
3992 * Set the value and return...
3995 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3997 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4000 * Just copy the pointer...
4003 value
->unknown
.data
= (void *)data
;
4004 value
->unknown
.length
= datalen
;
4012 if (value
->unknown
.data
)
4015 * Free previous data...
4018 free(value
->unknown
.data
);
4020 value
->unknown
.data
= NULL
;
4021 value
->unknown
.length
= 0;
4026 void *temp
; /* Temporary data pointer */
4028 if ((temp
= malloc((size_t)datalen
)) != NULL
)
4030 memcpy(temp
, data
, (size_t)datalen
);
4032 value
->unknown
.data
= temp
;
4033 value
->unknown
.length
= datalen
;
4041 return (value
!= NULL
);
4046 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
4048 * The @code ipp@ parameter refers to an IPP message previously created using
4049 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4051 * @since CUPS 1.6/macOS 10.8@
4054 int /* O - 1 on success, 0 on failure */
4055 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
4056 ipp_op_t op
) /* I - Operation ID */
4059 * Range check input...
4066 * Set the operation and return...
4069 ipp
->request
.op
.operation_id
= op
;
4076 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4078 * The @code ipp@ parameter refers to an IPP message previously created using
4079 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4081 * The @code attr@ parameter may be modified as a result of setting the value.
4083 * The @code element@ parameter specifies which value to set from 0 to
4084 * @link ippGetCount(attr)@.
4086 * @since CUPS 1.6/macOS 10.8@
4089 int /* O - 1 on success, 0 on failure */
4090 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4091 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4092 int element
, /* I - Value number (0-based) */
4093 int lowervalue
, /* I - Lower bound for range */
4094 int uppervalue
) /* I - Upper bound for range */
4096 _ipp_value_t
*value
; /* Current value */
4100 * Range check input...
4103 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4104 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4108 * Set the value and return...
4111 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4113 value
->range
.lower
= lowervalue
;
4114 value
->range
.upper
= uppervalue
;
4117 return (value
!= NULL
);
4122 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4124 * The @code ipp@ parameter refers to an IPP message previously created using
4125 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4127 * The @code request_id@ parameter must be greater than 0.
4129 * @since CUPS 1.6/macOS 10.8@
4132 int /* O - 1 on success, 0 on failure */
4133 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4134 int request_id
) /* I - Request ID */
4137 * Range check input; not checking request_id values since ipptool wants to send
4138 * invalid values for conformance testing and a bad request_id does not affect the
4139 * encoding of a message...
4146 * Set the request ID and return...
4149 ipp
->request
.any
.request_id
= request_id
;
4156 * 'ippSetResolution()' - Set a resolution value in an attribute.
4158 * The @code ipp@ parameter refers to an IPP message previously created using
4159 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4161 * The @code attr@ parameter may be modified as a result of setting the value.
4163 * The @code element@ parameter specifies which value to set from 0 to
4164 * @link ippGetCount(attr)@.
4166 * @since CUPS 1.6/macOS 10.8@
4169 int /* O - 1 on success, 0 on failure */
4171 ipp_t
*ipp
, /* I - IPP message */
4172 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4173 int element
, /* I - Value number (0-based) */
4174 ipp_res_t unitsvalue
, /* I - Resolution units */
4175 int xresvalue
, /* I - Horizontal/cross feed resolution */
4176 int yresvalue
) /* I - Vertical/feed resolution */
4178 _ipp_value_t
*value
; /* Current value */
4182 * Range check input...
4185 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4186 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4187 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4191 * Set the value and return...
4194 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4196 value
->resolution
.units
= unitsvalue
;
4197 value
->resolution
.xres
= xresvalue
;
4198 value
->resolution
.yres
= yresvalue
;
4201 return (value
!= NULL
);
4206 * 'ippSetState()' - Set the current state of the IPP message.
4208 * @since CUPS 1.6/macOS 10.8@
4211 int /* O - 1 on success, 0 on failure */
4212 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4213 ipp_state_t state
) /* I - IPP state value */
4216 * Range check input...
4223 * Set the state and return...
4227 ipp
->current
= NULL
;
4234 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4236 * The @code ipp@ parameter refers to an IPP message previously created using
4237 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4239 * @since CUPS 1.6/macOS 10.8@
4242 int /* O - 1 on success, 0 on failure */
4243 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4244 ipp_status_t status
) /* I - Status code */
4247 * Range check input...
4254 * Set the status code and return...
4257 ipp
->request
.status
.status_code
= status
;
4264 * 'ippSetString()' - Set a string value in an attribute.
4266 * The @code ipp@ parameter refers to an IPP message previously created using
4267 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4269 * The @code attr@ parameter may be modified as a result of setting the value.
4271 * The @code element@ parameter specifies which value to set from 0 to
4272 * @link ippGetCount(attr)@.
4274 * @since CUPS 1.6/macOS 10.8@
4277 int /* O - 1 on success, 0 on failure */
4278 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4279 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4280 int element
, /* I - Value number (0-based) */
4281 const char *strvalue
) /* I - String value */
4283 char *temp
; /* Temporary string */
4284 _ipp_value_t
*value
; /* Current value */
4288 * Range check input...
4291 if (!ipp
|| !attr
|| !*attr
||
4292 ((*attr
)->value_tag
!= IPP_TAG_TEXTLANG
&&
4293 (*attr
)->value_tag
!= IPP_TAG_NAMELANG
&&
4294 ((*attr
)->value_tag
< IPP_TAG_TEXT
||
4295 (*attr
)->value_tag
> IPP_TAG_MIMETYPE
)) ||
4296 element
< 0 || element
> (*attr
)->num_values
|| !strvalue
)
4300 * Set the value and return...
4303 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4306 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4308 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4309 value
->string
.text
= (char *)strvalue
;
4310 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4312 if (value
->string
.text
)
4313 _cupsStrFree(value
->string
.text
);
4315 value
->string
.text
= temp
;
4321 return (value
!= NULL
);
4326 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4328 * The @code ipp@ parameter refers to an IPP message previously created using
4329 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4331 * The @code attr@ parameter may be modified as a result of setting the value.
4333 * The @code element@ parameter specifies which value to set from 0 to
4334 * @link ippGetCount(attr)@.
4336 * The @code format@ parameter uses formatting characters compatible with the
4337 * printf family of standard functions. Additional arguments follow it as
4338 * needed. The formatted string is truncated as needed to the maximum length of
4339 * the corresponding value type.
4341 * @since CUPS 1.7/macOS 10.9@
4344 int /* O - 1 on success, 0 on failure */
4345 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4346 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4347 int element
, /* I - Value number (0-based) */
4348 const char *format
, /* I - Printf-style format string */
4349 ...) /* I - Additional arguments as needed */
4351 int ret
; /* Return value */
4352 va_list ap
; /* Pointer to additional arguments */
4355 va_start(ap
, format
);
4356 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4364 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4366 * The @code ipp@ parameter refers to an IPP message previously created using
4367 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4369 * The @code attr@ parameter may be modified as a result of setting the value.
4371 * The @code element@ parameter specifies which value to set from 0 to
4372 * @link ippGetCount(attr)@.
4374 * The @code format@ parameter uses formatting characters compatible with the
4375 * printf family of standard functions. Additional arguments follow it as
4376 * needed. The formatted string is truncated as needed to the maximum length of
4377 * the corresponding value type.
4379 * @since CUPS 1.7/macOS 10.9@
4382 int /* O - 1 on success, 0 on failure */
4383 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4384 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4385 int element
, /* I - Value number (0-based) */
4386 const char *format
, /* I - Printf-style format string */
4387 va_list ap
) /* I - Pointer to additional arguments */
4389 ipp_tag_t value_tag
; /* Value tag */
4390 char buffer
[IPP_MAX_TEXT
+ 4];
4391 /* Formatted text string */
4392 ssize_t bytes
, /* Length of formatted value */
4393 max_bytes
; /* Maximum number of bytes for value */
4397 * Range check input...
4401 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4403 value_tag
= IPP_TAG_ZERO
;
4405 if (!ipp
|| !attr
|| !*attr
||
4406 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4407 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4412 * Format the string...
4415 if (!strcmp(format
, "%s"))
4418 * Optimize the simple case...
4421 const char *s
= va_arg(ap
, char *);
4426 bytes
= (ssize_t
)strlen(s
);
4427 strlcpy(buffer
, s
, sizeof(buffer
));
4432 * Do a full formatting of the message...
4435 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4440 * Limit the length of the string...
4447 case IPP_TAG_TEXTLANG
:
4448 max_bytes
= IPP_MAX_TEXT
;
4452 case IPP_TAG_NAMELANG
:
4453 max_bytes
= IPP_MAX_NAME
;
4456 case IPP_TAG_CHARSET
:
4457 max_bytes
= IPP_MAX_CHARSET
;
4460 case IPP_TAG_KEYWORD
:
4461 max_bytes
= IPP_MAX_KEYWORD
;
4464 case IPP_TAG_LANGUAGE
:
4465 max_bytes
= IPP_MAX_LANGUAGE
;
4468 case IPP_TAG_MIMETYPE
:
4469 max_bytes
= IPP_MAX_MIMETYPE
;
4473 max_bytes
= IPP_MAX_URI
;
4476 case IPP_TAG_URISCHEME
:
4477 max_bytes
= IPP_MAX_URISCHEME
;
4481 if (bytes
>= max_bytes
)
4483 char *bufmax
, /* Buffer at max_bytes */
4484 *bufptr
; /* Pointer into buffer */
4486 bufptr
= buffer
+ strlen(buffer
) - 1;
4487 bufmax
= buffer
+ max_bytes
- 1;
4489 while (bufptr
> bufmax
)
4493 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4504 * Set the formatted string and return...
4507 return (ippSetString(ipp
, attr
, element
, buffer
));
4512 * 'ippSetValueTag()' - Set the value tag of an attribute.
4514 * The @code ipp@ parameter refers to an IPP message previously created using
4515 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4517 * The @code attr@ parameter may be modified as a result of setting the value.
4519 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4520 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4521 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4522 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4523 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4524 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4527 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4528 * code in the "attributes-natural-language" attribute or, if not present, the language
4529 * code for the current locale.
4531 * @since CUPS 1.6/macOS 10.8@
4534 int /* O - 1 on success, 0 on failure */
4536 ipp_t
*ipp
, /* I - IPP message */
4537 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4538 ipp_tag_t value_tag
) /* I - Value tag */
4540 int i
; /* Looping var */
4541 _ipp_value_t
*value
; /* Current value */
4542 int integer
; /* Current integer value */
4543 cups_lang_t
*language
; /* Current language */
4544 char code
[32]; /* Language code */
4545 ipp_tag_t temp_tag
; /* Temporary value tag */
4549 * Range check input...
4552 if (!ipp
|| !attr
|| !*attr
)
4556 * If there is no change, return immediately...
4559 if (value_tag
== (*attr
)->value_tag
)
4563 * Otherwise implement changes as needed...
4566 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4570 case IPP_TAG_UNSUPPORTED_VALUE
:
4571 case IPP_TAG_DEFAULT
:
4572 case IPP_TAG_UNKNOWN
:
4573 case IPP_TAG_NOVALUE
:
4574 case IPP_TAG_NOTSETTABLE
:
4575 case IPP_TAG_DELETEATTR
:
4576 case IPP_TAG_ADMINDEFINE
:
4578 * Free any existing values...
4581 if ((*attr
)->num_values
> 0)
4582 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4585 * Set out-of-band value...
4588 (*attr
)->value_tag
= value_tag
;
4591 case IPP_TAG_RANGE
:
4592 if (temp_tag
!= IPP_TAG_INTEGER
)
4595 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4599 integer
= value
->integer
;
4600 value
->range
.lower
= value
->range
.upper
= integer
;
4603 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4607 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4608 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4609 temp_tag
!= IPP_TAG_MIMETYPE
)
4612 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4615 case IPP_TAG_NAMELANG
:
4616 case IPP_TAG_TEXTLANG
:
4617 if (value_tag
== IPP_TAG_NAMELANG
&&
4618 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4619 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4620 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4623 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4626 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4627 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4630 * Use the language code from the IPP message...
4633 (*attr
)->values
[0].string
.language
=
4634 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4639 * Otherwise, use the language code corresponding to the locale...
4642 language
= cupsLangDefault();
4643 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4648 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4651 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4653 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4656 * Make copies of all values...
4659 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4662 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4665 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4668 case IPP_TAG_KEYWORD
:
4669 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4670 break; /* Silently "allow" name -> keyword */
4681 * 'ippSetVersion()' - Set the version number in an IPP message.
4683 * The @code ipp@ parameter refers to an IPP message previously created using
4684 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4686 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4688 * @since CUPS 1.6/macOS 10.8@
4691 int /* O - 1 on success, 0 on failure */
4692 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4693 int major
, /* I - Major version number (major.minor) */
4694 int minor
) /* I - Minor version number (major.minor) */
4697 * Range check input...
4700 if (!ipp
|| major
< 0 || minor
< 0)
4704 * Set the version number...
4707 ipp
->request
.any
.version
[0] = (ipp_uchar_t
)major
;
4708 ipp
->request
.any
.version
[1] = (ipp_uchar_t
)minor
;
4715 * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
4718 const ipp_uchar_t
* /* O - RFC-1903 date/time data */
4719 ippTimeToDate(time_t t
) /* I - UNIX time value */
4721 struct tm
*unixdate
; /* UNIX unixdate/time info */
4722 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4723 /* RFC-1903 date/time data */
4727 * RFC-1903 date/time format is:
4729 * Byte(s) Description
4730 * ------- -----------
4731 * 0-1 Year (0 to 65535)
4735 * 5 Minutes (0 to 59)
4736 * 6 Seconds (0 to 60, 60 = "leap second")
4737 * 7 Deciseconds (0 to 9)
4739 * 9 UTC hours (0 to 11)
4740 * 10 UTC minutes (0 to 59)
4743 unixdate
= gmtime(&t
);
4744 unixdate
->tm_year
+= 1900;
4746 date
[0] = (ipp_uchar_t
)(unixdate
->tm_year
>> 8);
4747 date
[1] = (ipp_uchar_t
)(unixdate
->tm_year
);
4748 date
[2] = (ipp_uchar_t
)(unixdate
->tm_mon
+ 1);
4749 date
[3] = (ipp_uchar_t
)unixdate
->tm_mday
;
4750 date
[4] = (ipp_uchar_t
)unixdate
->tm_hour
;
4751 date
[5] = (ipp_uchar_t
)unixdate
->tm_min
;
4752 date
[6] = (ipp_uchar_t
)unixdate
->tm_sec
;
4763 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4765 * This function validates the contents of an attribute based on the name and
4766 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4767 * failure, cupsLastErrorString() is set to a human-readable message.
4769 * @since CUPS 1.7/macOS 10.9@
4772 int /* O - 1 if valid, 0 otherwise */
4773 ippValidateAttribute(
4774 ipp_attribute_t
*attr
) /* I - Attribute */
4776 int i
; /* Looping var */
4777 char scheme
[64], /* Scheme from URI */
4778 userpass
[256], /* Username/password from URI */
4779 hostname
[256], /* Hostname from URI */
4780 resource
[1024]; /* Resource from URI */
4781 int port
, /* Port number from URI */
4782 uri_status
; /* URI separation status */
4783 const char *ptr
; /* Pointer into string */
4784 ipp_attribute_t
*colattr
; /* Collection attribute */
4785 regex_t re
; /* Regular expression */
4786 ipp_uchar_t
*date
; /* Current date value */
4787 static const char * const uri_status_strings
[] =
4788 { /* URI status strings */
4790 "Bad arguments to function",
4791 "Bad resource in URI",
4792 "Bad port number in URI",
4793 "Bad hostname/address in URI",
4794 "Bad username in URI",
4795 "Bad scheme in URI",
4798 "Missing scheme in URI",
4799 "Unknown scheme in URI",
4800 "Missing resource in URI"
4812 * Validate the attribute name.
4815 for (ptr
= attr
->name
; *ptr
; ptr
++)
4816 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4819 if (*ptr
|| ptr
== attr
->name
)
4821 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4822 _("\"%s\": Bad attribute name - invalid character "
4823 "(RFC 2911 section 4.1.3)."), attr
->name
);
4827 if ((ptr
- attr
->name
) > 255)
4829 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4830 _("\"%s\": Bad attribute name - bad length %d "
4831 "(RFC 2911 section 4.1.3)."), attr
->name
,
4832 (int)(ptr
- attr
->name
));
4836 switch (attr
->value_tag
)
4838 case IPP_TAG_INTEGER
:
4841 case IPP_TAG_BOOLEAN
:
4842 for (i
= 0; i
< attr
->num_values
; i
++)
4844 if (attr
->values
[i
].boolean
!= 0 &&
4845 attr
->values
[i
].boolean
!= 1)
4847 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4848 _("\"%s\": Bad boolen value %d "
4849 "(RFC 2911 section 4.1.11)."), attr
->name
,
4850 attr
->values
[i
].boolean
);
4857 for (i
= 0; i
< attr
->num_values
; i
++)
4859 if (attr
->values
[i
].integer
< 1)
4861 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4862 _("\"%s\": Bad enum value %d - out of range "
4863 "(RFC 2911 section 4.1.4)."), attr
->name
,
4864 attr
->values
[i
].integer
);
4870 case IPP_TAG_STRING
:
4871 for (i
= 0; i
< attr
->num_values
; i
++)
4873 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4875 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4876 _("\"%s\": Bad octetString value - bad length %d "
4877 "(RFC 2911 section 4.1.10)."), attr
->name
,
4878 attr
->values
[i
].unknown
.length
);
4885 for (i
= 0; i
< attr
->num_values
; i
++)
4887 date
= attr
->values
[i
].date
;
4889 if (date
[2] < 1 || date
[2] > 12)
4891 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4892 _("\"%s\": Bad dateTime month %u "
4893 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[2]);
4897 if (date
[3] < 1 || date
[3] > 31)
4899 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4900 _("\"%s\": Bad dateTime day %u "
4901 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[3]);
4907 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4908 _("\"%s\": Bad dateTime hours %u "
4909 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[4]);
4915 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4916 _("\"%s\": Bad dateTime minutes %u "
4917 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[5]);
4923 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4924 _("\"%s\": Bad dateTime seconds %u "
4925 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[6]);
4931 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4932 _("\"%s\": Bad dateTime deciseconds %u "
4933 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[7]);
4937 if (date
[8] != '-' && date
[8] != '+')
4939 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4940 _("\"%s\": Bad dateTime UTC sign '%c' "
4941 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[8]);
4947 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4948 _("\"%s\": Bad dateTime UTC hours %u "
4949 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[9]);
4955 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4956 _("\"%s\": Bad dateTime UTC minutes %u "
4957 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[10]);
4963 case IPP_TAG_RESOLUTION
:
4964 for (i
= 0; i
< attr
->num_values
; i
++)
4966 if (attr
->values
[i
].resolution
.xres
<= 0)
4968 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4969 _("\"%s\": Bad resolution value %dx%d%s - cross "
4970 "feed resolution must be positive "
4971 "(RFC 2911 section 4.1.15)."), attr
->name
,
4972 attr
->values
[i
].resolution
.xres
,
4973 attr
->values
[i
].resolution
.yres
,
4974 attr
->values
[i
].resolution
.units
==
4975 IPP_RES_PER_INCH
? "dpi" :
4976 attr
->values
[i
].resolution
.units
==
4977 IPP_RES_PER_CM
? "dpcm" : "unknown");
4981 if (attr
->values
[i
].resolution
.yres
<= 0)
4983 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4984 _("\"%s\": Bad resolution value %dx%d%s - feed "
4985 "resolution must be positive "
4986 "(RFC 2911 section 4.1.15)."), attr
->name
,
4987 attr
->values
[i
].resolution
.xres
,
4988 attr
->values
[i
].resolution
.yres
,
4989 attr
->values
[i
].resolution
.units
==
4990 IPP_RES_PER_INCH
? "dpi" :
4991 attr
->values
[i
].resolution
.units
==
4992 IPP_RES_PER_CM
? "dpcm" : "unknown");
4996 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
4997 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
4999 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5000 _("\"%s\": Bad resolution value %dx%d%s - bad "
5001 "units value (RFC 2911 section 4.1.15)."),
5002 attr
->name
, attr
->values
[i
].resolution
.xres
,
5003 attr
->values
[i
].resolution
.yres
,
5004 attr
->values
[i
].resolution
.units
==
5005 IPP_RES_PER_INCH
? "dpi" :
5006 attr
->values
[i
].resolution
.units
==
5007 IPP_RES_PER_CM
? "dpcm" : "unknown");
5013 case IPP_TAG_RANGE
:
5014 for (i
= 0; i
< attr
->num_values
; i
++)
5016 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
5018 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5019 _("\"%s\": Bad rangeOfInteger value %d-%d - lower "
5020 "greater than upper (RFC 2911 section 4.1.13)."),
5021 attr
->name
, attr
->values
[i
].range
.lower
,
5022 attr
->values
[i
].range
.upper
);
5028 case IPP_TAG_BEGIN_COLLECTION
:
5029 for (i
= 0; i
< attr
->num_values
; i
++)
5031 for (colattr
= attr
->values
[i
].collection
->attrs
;
5033 colattr
= colattr
->next
)
5035 if (!ippValidateAttribute(colattr
))
5042 case IPP_TAG_TEXTLANG
:
5043 for (i
= 0; i
< attr
->num_values
; i
++)
5045 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5047 if ((*ptr
& 0xe0) == 0xc0)
5050 if ((*ptr
& 0xc0) != 0x80)
5053 else if ((*ptr
& 0xf0) == 0xe0)
5056 if ((*ptr
& 0xc0) != 0x80)
5059 if ((*ptr
& 0xc0) != 0x80)
5062 else if ((*ptr
& 0xf8) == 0xf0)
5065 if ((*ptr
& 0xc0) != 0x80)
5068 if ((*ptr
& 0xc0) != 0x80)
5071 if ((*ptr
& 0xc0) != 0x80)
5074 else if (*ptr
& 0x80)
5080 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5081 _("\"%s\": Bad text value \"%s\" - bad UTF-8 "
5082 "sequence (RFC 2911 section 4.1.1)."), attr
->name
,
5083 attr
->values
[i
].string
.text
);
5087 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5089 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5090 _("\"%s\": Bad text value \"%s\" - bad length %d "
5091 "(RFC 2911 section 4.1.1)."), attr
->name
,
5092 attr
->values
[i
].string
.text
,
5093 (int)(ptr
- attr
->values
[i
].string
.text
));
5100 case IPP_TAG_NAMELANG
:
5101 for (i
= 0; i
< attr
->num_values
; i
++)
5103 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5105 if ((*ptr
& 0xe0) == 0xc0)
5108 if ((*ptr
& 0xc0) != 0x80)
5111 else if ((*ptr
& 0xf0) == 0xe0)
5114 if ((*ptr
& 0xc0) != 0x80)
5117 if ((*ptr
& 0xc0) != 0x80)
5120 else if ((*ptr
& 0xf8) == 0xf0)
5123 if ((*ptr
& 0xc0) != 0x80)
5126 if ((*ptr
& 0xc0) != 0x80)
5129 if ((*ptr
& 0xc0) != 0x80)
5132 else if (*ptr
& 0x80)
5138 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5139 _("\"%s\": Bad name value \"%s\" - bad UTF-8 "
5140 "sequence (RFC 2911 section 4.1.2)."), attr
->name
,
5141 attr
->values
[i
].string
.text
);
5145 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5147 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5148 _("\"%s\": Bad name value \"%s\" - bad length %d "
5149 "(RFC 2911 section 4.1.2)."), attr
->name
,
5150 attr
->values
[i
].string
.text
,
5151 (int)(ptr
- attr
->values
[i
].string
.text
));
5157 case IPP_TAG_KEYWORD
:
5158 for (i
= 0; i
< attr
->num_values
; i
++)
5160 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5161 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5165 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5167 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5168 _("\"%s\": Bad keyword value \"%s\" - invalid "
5169 "character (RFC 2911 section 4.1.3)."),
5170 attr
->name
, attr
->values
[i
].string
.text
);
5174 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5176 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5177 _("\"%s\": Bad keyword value \"%s\" - bad "
5178 "length %d (RFC 2911 section 4.1.3)."),
5179 attr
->name
, attr
->values
[i
].string
.text
,
5180 (int)(ptr
- attr
->values
[i
].string
.text
));
5187 for (i
= 0; i
< attr
->num_values
; i
++)
5189 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5190 attr
->values
[i
].string
.text
,
5191 scheme
, sizeof(scheme
),
5192 userpass
, sizeof(userpass
),
5193 hostname
, sizeof(hostname
),
5194 &port
, resource
, sizeof(resource
));
5196 if (uri_status
< HTTP_URI_STATUS_OK
)
5198 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5199 _("\"%s\": Bad URI value \"%s\" - %s "
5200 "(RFC 2911 section 4.1.5)."), attr
->name
,
5201 attr
->values
[i
].string
.text
,
5202 uri_status_strings
[uri_status
-
5203 HTTP_URI_STATUS_OVERFLOW
]);
5207 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5209 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5210 _("\"%s\": Bad URI value \"%s\" - bad length %d "
5211 "(RFC 2911 section 4.1.5)."), attr
->name
,
5212 attr
->values
[i
].string
.text
,
5213 (int)strlen(attr
->values
[i
].string
.text
));
5218 case IPP_TAG_URISCHEME
:
5219 for (i
= 0; i
< attr
->num_values
; i
++)
5221 ptr
= attr
->values
[i
].string
.text
;
5222 if (islower(*ptr
& 255))
5224 for (ptr
++; *ptr
; ptr
++)
5225 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5226 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5230 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5232 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5233 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5234 "characters (RFC 2911 section 4.1.6)."),
5235 attr
->name
, attr
->values
[i
].string
.text
);
5239 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5241 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5242 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5243 "length %d (RFC 2911 section 4.1.6)."),
5244 attr
->name
, attr
->values
[i
].string
.text
,
5245 (int)(ptr
- attr
->values
[i
].string
.text
));
5251 case IPP_TAG_CHARSET
:
5252 for (i
= 0; i
< attr
->num_values
; i
++)
5254 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5255 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5256 isspace(*ptr
& 255))
5259 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5261 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5262 _("\"%s\": Bad charset value \"%s\" - bad "
5263 "characters (RFC 2911 section 4.1.7)."),
5264 attr
->name
, attr
->values
[i
].string
.text
);
5268 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5270 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5271 _("\"%s\": Bad charset value \"%s\" - bad "
5272 "length %d (RFC 2911 section 4.1.7)."),
5273 attr
->name
, attr
->values
[i
].string
.text
,
5274 (int)(ptr
- attr
->values
[i
].string
.text
));
5280 case IPP_TAG_LANGUAGE
:
5282 * The following regular expression is derived from the ABNF for
5283 * language tags in RFC 4646. All I can say is that this is the
5284 * easiest way to check the values...
5287 if ((i
= regcomp(&re
,
5289 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5291 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5292 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5293 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5294 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5295 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5297 "x(-[a-z0-9]{1,8})+" /* privateuse */
5299 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5301 REG_NOSUB
| REG_EXTENDED
)) != 0)
5303 char temp
[256]; /* Temporary error string */
5305 regerror(i
, &re
, temp
, sizeof(temp
));
5306 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
,
5307 _("Unable to compile naturalLanguage regular "
5308 "expression: %s."), temp
);
5312 for (i
= 0; i
< attr
->num_values
; i
++)
5314 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5316 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5317 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5318 "characters (RFC 2911 section 4.1.8)."),
5319 attr
->name
, attr
->values
[i
].string
.text
);
5324 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5326 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5327 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5328 "length %d (RFC 2911 section 4.1.8)."),
5329 attr
->name
, attr
->values
[i
].string
.text
,
5330 (int)strlen(attr
->values
[i
].string
.text
));
5339 case IPP_TAG_MIMETYPE
:
5341 * The following regular expression is derived from the ABNF for
5342 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5343 * the easiest way to check the values...
5346 if ((i
= regcomp(&re
,
5348 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5350 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5351 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5352 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5355 REG_NOSUB
| REG_EXTENDED
)) != 0)
5357 char temp
[256]; /* Temporary error string */
5359 regerror(i
, &re
, temp
, sizeof(temp
));
5360 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5361 _("Unable to compile mimeMediaType regular "
5362 "expression: %s."), temp
);
5366 for (i
= 0; i
< attr
->num_values
; i
++)
5368 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5370 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5371 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5372 "characters (RFC 2911 section 4.1.9)."),
5373 attr
->name
, attr
->values
[i
].string
.text
);
5378 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5380 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5381 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5382 "length %d (RFC 2911 section 4.1.9)."),
5383 attr
->name
, attr
->values
[i
].string
.text
,
5384 (int)strlen(attr
->values
[i
].string
.text
));
5402 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5404 * This function validates the contents of the IPP message, including each
5405 * attribute. Like @link ippValidateAttribute@, cupsLastErrorString() is set
5406 * to a human-readable message on failure.
5408 * @since CUPS 1.7/macOS 10.9@
5411 int /* O - 1 if valid, 0 otherwise */
5412 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5414 ipp_attribute_t
*attr
; /* Current attribute */
5420 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5421 if (!ippValidateAttribute(attr
))
5429 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5432 ipp_state_t
/* O - Current state */
5433 ippWrite(http_t
*http
, /* I - HTTP connection */
5434 ipp_t
*ipp
) /* I - IPP data */
5436 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http
, (void *)ipp
));
5439 return (IPP_STATE_ERROR
);
5441 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5446 * 'ippWriteFile()' - Write data for an IPP message to a file.
5448 * @since CUPS 1.1.19/macOS 10.3@
5451 ipp_state_t
/* O - Current state */
5452 ippWriteFile(int fd
, /* I - HTTP data */
5453 ipp_t
*ipp
) /* I - IPP data */
5455 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
5457 ipp
->state
= IPP_STATE_IDLE
;
5459 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5464 * 'ippWriteIO()' - Write data for an IPP message.
5466 * @since CUPS 1.2/macOS 10.5@
5469 ipp_state_t
/* O - Current state */
5470 ippWriteIO(void *dst
, /* I - Destination */
5471 ipp_iocb_t cb
, /* I - Write callback function */
5472 int blocking
, /* I - Use blocking IO? */
5473 ipp_t
*parent
, /* I - Parent IPP message */
5474 ipp_t
*ipp
) /* I - IPP data */
5476 int i
; /* Looping var */
5477 int n
; /* Length of data */
5478 unsigned char *buffer
, /* Data buffer */
5479 *bufptr
; /* Pointer into buffer */
5480 ipp_attribute_t
*attr
; /* Current attribute */
5481 _ipp_value_t
*value
; /* Current value */
5484 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
5487 return (IPP_STATE_ERROR
);
5489 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5491 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5492 return (IPP_STATE_ERROR
);
5497 case IPP_STATE_IDLE
:
5498 ipp
->state
++; /* Avoid common problem... */
5500 case IPP_STATE_HEADER
:
5504 * Send the request header:
5507 * Operation/Status Code = 2 bytes
5508 * Request ID = 4 bytes
5514 *bufptr
++ = ipp
->request
.any
.version
[0];
5515 *bufptr
++ = ipp
->request
.any
.version
[1];
5516 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.op_status
>> 8);
5517 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.op_status
;
5518 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 24);
5519 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 16);
5520 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 8);
5521 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.request_id
;
5523 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5524 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5525 ipp
->request
.any
.op_status
));
5526 DEBUG_printf(("2ippWriteIO: request_id=%d",
5527 ipp
->request
.any
.request_id
));
5529 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5531 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5532 _cupsBufferRelease((char *)buffer
);
5533 return (IPP_STATE_ERROR
);
5538 * Reset the state engine to point to the first attribute
5539 * in the request/response, with no current group.
5542 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5543 ipp
->current
= ipp
->attrs
;
5544 ipp
->curtag
= IPP_TAG_ZERO
;
5546 DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp
->current
));
5549 * If blocking is disabled, stop here...
5555 case IPP_STATE_ATTRIBUTE
:
5556 while (ipp
->current
!= NULL
)
5559 * Write this attribute...
5563 attr
= ipp
->current
;
5565 ipp
->current
= ipp
->current
->next
;
5569 if (ipp
->curtag
!= attr
->group_tag
)
5572 * Send a group tag byte...
5575 ipp
->curtag
= attr
->group_tag
;
5577 if (attr
->group_tag
== IPP_TAG_ZERO
)
5580 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5581 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5582 *bufptr
++ = (ipp_uchar_t
)attr
->group_tag
;
5584 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5588 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5589 attr
->num_values
> 1 ? "1setOf " : "",
5590 ippTagString(attr
->value_tag
)));
5593 * Write the attribute tag and name.
5595 * The attribute name length does not include the trailing nul
5596 * character in the source string.
5598 * Collection values (parent != NULL) are written differently...
5604 * Get the length of the attribute name, and make sure it won't
5605 * overflow the buffer...
5608 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5610 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5611 _cupsBufferRelease((char *)buffer
);
5612 return (IPP_STATE_ERROR
);
5616 * Write the value tag, name length, and name string...
5619 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5620 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5621 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5624 if (attr
->value_tag
> 0xff)
5626 *bufptr
++ = IPP_TAG_EXTENSION
;
5627 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5628 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5629 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5630 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5633 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5635 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5636 *bufptr
++ = (ipp_uchar_t
)n
;
5637 memcpy(bufptr
, attr
->name
, (size_t)n
);
5643 * Get the length of the attribute name, and make sure it won't
5644 * overflow the buffer...
5647 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5649 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5650 _cupsBufferRelease((char *)buffer
);
5651 return (IPP_STATE_ERROR
);
5655 * Write the member name tag, name length, name string, value tag,
5656 * and empty name for the collection member attribute...
5659 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5660 IPP_TAG_MEMBERNAME
));
5661 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5663 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5664 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5665 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5667 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5670 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5671 *bufptr
++ = (ipp_uchar_t
)n
;
5672 memcpy(bufptr
, attr
->name
, (size_t)n
);
5675 if (attr
->value_tag
> 0xff)
5677 *bufptr
++ = IPP_TAG_EXTENSION
;
5678 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5679 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5680 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5681 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5684 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5691 * Now write the attribute value(s)...
5694 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5696 case IPP_TAG_UNSUPPORTED_VALUE
:
5697 case IPP_TAG_DEFAULT
:
5698 case IPP_TAG_UNKNOWN
:
5699 case IPP_TAG_NOVALUE
:
5700 case IPP_TAG_NOTSETTABLE
:
5701 case IPP_TAG_DELETEATTR
:
5702 case IPP_TAG_ADMINDEFINE
:
5707 case IPP_TAG_INTEGER
:
5709 for (i
= 0, value
= attr
->values
;
5710 i
< attr
->num_values
;
5713 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5715 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5717 DEBUG_puts("1ippWriteIO: Could not write IPP "
5719 _cupsBufferRelease((char *)buffer
);
5720 return (IPP_STATE_ERROR
);
5729 * Arrays and sets are done by sending additional
5730 * values with a zero-length name...
5733 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5739 * Integers and enumerations are both 4-byte signed
5740 * (twos-complement) values.
5742 * Put the 2-byte length and 4-byte value into the buffer...
5747 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 24);
5748 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 16);
5749 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 8);
5750 *bufptr
++ = (ipp_uchar_t
)value
->integer
;
5754 case IPP_TAG_BOOLEAN
:
5755 for (i
= 0, value
= attr
->values
;
5756 i
< attr
->num_values
;
5759 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5761 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5763 DEBUG_puts("1ippWriteIO: Could not write IPP "
5765 _cupsBufferRelease((char *)buffer
);
5766 return (IPP_STATE_ERROR
);
5775 * Arrays and sets are done by sending additional
5776 * values with a zero-length name...
5779 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5785 * Boolean values are 1-byte; 0 = false, 1 = true.
5787 * Put the 2-byte length and 1-byte value into the buffer...
5792 *bufptr
++ = (ipp_uchar_t
)value
->boolean
;
5798 case IPP_TAG_KEYWORD
:
5800 case IPP_TAG_URISCHEME
:
5801 case IPP_TAG_CHARSET
:
5802 case IPP_TAG_LANGUAGE
:
5803 case IPP_TAG_MIMETYPE
:
5804 for (i
= 0, value
= attr
->values
;
5805 i
< attr
->num_values
;
5811 * Arrays and sets are done by sending additional
5812 * values with a zero-length name...
5815 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5817 ippTagString(attr
->value_tag
)));
5818 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5820 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5822 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5824 DEBUG_puts("1ippWriteIO: Could not write IPP "
5826 _cupsBufferRelease((char *)buffer
);
5827 return (IPP_STATE_ERROR
);
5833 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5838 if (value
->string
.text
!= NULL
)
5839 n
= (int)strlen(value
->string
.text
);
5843 if (n
> (IPP_BUF_SIZE
- 2))
5845 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5846 _cupsBufferRelease((char *)buffer
);
5847 return (IPP_STATE_ERROR
);
5850 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5851 value
->string
.text
));
5853 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5855 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5857 DEBUG_puts("1ippWriteIO: Could not write IPP "
5859 _cupsBufferRelease((char *)buffer
);
5860 return (IPP_STATE_ERROR
);
5867 * All simple strings consist of the 2-byte length and
5868 * character data without the trailing nul normally found
5869 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5870 * bytes since the 2-byte length is a signed (twos-complement)
5873 * Put the 2-byte length and string characters in the buffer.
5876 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5877 *bufptr
++ = (ipp_uchar_t
)n
;
5881 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5888 for (i
= 0, value
= attr
->values
;
5889 i
< attr
->num_values
;
5892 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5894 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5896 DEBUG_puts("1ippWriteIO: Could not write IPP "
5898 _cupsBufferRelease((char *)buffer
);
5899 return (IPP_STATE_ERROR
);
5908 * Arrays and sets are done by sending additional
5909 * values with a zero-length name...
5912 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5918 * Date values consist of a 2-byte length and an
5919 * 11-byte date/time structure defined by RFC 1903.
5921 * Put the 2-byte length and 11-byte date/time
5922 * structure in the buffer.
5927 memcpy(bufptr
, value
->date
, 11);
5932 case IPP_TAG_RESOLUTION
:
5933 for (i
= 0, value
= attr
->values
;
5934 i
< attr
->num_values
;
5937 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5939 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5941 DEBUG_puts("1ippWriteIO: Could not write IPP "
5943 _cupsBufferRelease((char *)buffer
);
5944 return (IPP_STATE_ERROR
);
5953 * Arrays and sets are done by sending additional
5954 * values with a zero-length name...
5957 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5963 * Resolution values consist of a 2-byte length,
5964 * 4-byte horizontal resolution value, 4-byte vertical
5965 * resolution value, and a 1-byte units value.
5967 * Put the 2-byte length and resolution value data
5973 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 24);
5974 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 16);
5975 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 8);
5976 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.xres
;
5977 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 24);
5978 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 16);
5979 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 8);
5980 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.yres
;
5981 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.units
;
5985 case IPP_TAG_RANGE
:
5986 for (i
= 0, value
= attr
->values
;
5987 i
< attr
->num_values
;
5990 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
5992 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5994 DEBUG_puts("1ippWriteIO: Could not write IPP "
5996 _cupsBufferRelease((char *)buffer
);
5997 return (IPP_STATE_ERROR
);
6006 * Arrays and sets are done by sending additional
6007 * values with a zero-length name...
6010 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6016 * Range values consist of a 2-byte length,
6017 * 4-byte lower value, and 4-byte upper value.
6019 * Put the 2-byte length and range value data
6025 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 24);
6026 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 16);
6027 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 8);
6028 *bufptr
++ = (ipp_uchar_t
)value
->range
.lower
;
6029 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 24);
6030 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 16);
6031 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 8);
6032 *bufptr
++ = (ipp_uchar_t
)value
->range
.upper
;
6036 case IPP_TAG_TEXTLANG
:
6037 case IPP_TAG_NAMELANG
:
6038 for (i
= 0, value
= attr
->values
;
6039 i
< attr
->num_values
;
6045 * Arrays and sets are done by sending additional
6046 * values with a zero-length name...
6049 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6051 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6053 DEBUG_puts("1ippWriteIO: Could not write IPP "
6055 _cupsBufferRelease((char *)buffer
);
6056 return (IPP_STATE_ERROR
);
6062 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6068 * textWithLanguage and nameWithLanguage values consist
6069 * of a 2-byte length for both strings and their
6070 * individual lengths, a 2-byte length for the
6071 * character string, the character string without the
6072 * trailing nul, a 2-byte length for the character
6073 * set string, and the character set string without
6079 if (value
->string
.language
!= NULL
)
6080 n
+= (int)strlen(value
->string
.language
);
6082 if (value
->string
.text
!= NULL
)
6083 n
+= (int)strlen(value
->string
.text
);
6085 if (n
> (IPP_BUF_SIZE
- 2))
6087 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
6088 "too long (%d)", n
));
6089 _cupsBufferRelease((char *)buffer
);
6090 return (IPP_STATE_ERROR
);
6093 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6095 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6097 DEBUG_puts("1ippWriteIO: Could not write IPP "
6099 _cupsBufferRelease((char *)buffer
);
6100 return (IPP_STATE_ERROR
);
6106 /* Length of entire value */
6107 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6108 *bufptr
++ = (ipp_uchar_t
)n
;
6110 /* Length of language */
6111 if (value
->string
.language
!= NULL
)
6112 n
= (int)strlen(value
->string
.language
);
6116 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6117 *bufptr
++ = (ipp_uchar_t
)n
;
6122 memcpy(bufptr
, value
->string
.language
, (size_t)n
);
6126 /* Length of text */
6127 if (value
->string
.text
!= NULL
)
6128 n
= (int)strlen(value
->string
.text
);
6132 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6133 *bufptr
++ = (ipp_uchar_t
)n
;
6138 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
6144 case IPP_TAG_BEGIN_COLLECTION
:
6145 for (i
= 0, value
= attr
->values
;
6146 i
< attr
->num_values
;
6150 * Collections are written with the begin-collection
6151 * tag first with a value of 0 length, followed by the
6152 * attributes in the collection, then the end-collection
6156 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6158 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6160 DEBUG_puts("1ippWriteIO: Could not write IPP "
6162 _cupsBufferRelease((char *)buffer
);
6163 return (IPP_STATE_ERROR
);
6172 * Arrays and sets are done by sending additional
6173 * values with a zero-length name...
6176 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6182 * Write a data length of 0 and flush the buffer...
6188 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6190 DEBUG_puts("1ippWriteIO: Could not write IPP "
6192 _cupsBufferRelease((char *)buffer
);
6193 return (IPP_STATE_ERROR
);
6199 * Then write the collection attribute...
6202 value
->collection
->state
= IPP_STATE_IDLE
;
6204 if (ippWriteIO(dst
, cb
, 1, ipp
,
6205 value
->collection
) == IPP_STATE_ERROR
)
6207 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6208 _cupsBufferRelease((char *)buffer
);
6209 return (IPP_STATE_ERROR
);
6215 for (i
= 0, value
= attr
->values
;
6216 i
< attr
->num_values
;
6222 * Arrays and sets are done by sending additional
6223 * values with a zero-length name...
6226 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6228 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6230 DEBUG_puts("1ippWriteIO: Could not write IPP "
6232 _cupsBufferRelease((char *)buffer
);
6233 return (IPP_STATE_ERROR
);
6239 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6245 * An unknown value might some new value that a
6246 * vendor has come up with. It consists of a
6247 * 2-byte length and the bytes in the unknown
6251 n
= value
->unknown
.length
;
6253 if (n
> (IPP_BUF_SIZE
- 2))
6255 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6257 _cupsBufferRelease((char *)buffer
);
6258 return (IPP_STATE_ERROR
);
6261 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6263 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6265 DEBUG_puts("1ippWriteIO: Could not write IPP "
6267 _cupsBufferRelease((char *)buffer
);
6268 return (IPP_STATE_ERROR
);
6274 /* Length of unknown value */
6275 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6276 *bufptr
++ = (ipp_uchar_t
)n
;
6281 memcpy(bufptr
, value
->unknown
.data
, (size_t)n
);
6289 * Write the data out...
6292 if (bufptr
> buffer
)
6294 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6296 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6297 _cupsBufferRelease((char *)buffer
);
6298 return (IPP_STATE_ERROR
);
6301 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6302 (int)(bufptr
- buffer
)));
6306 * If blocking is disabled and we aren't at the end of the attribute
6307 * list, stop here...
6310 if (!blocking
&& ipp
->current
)
6314 if (ipp
->current
== NULL
)
6317 * Done with all of the attributes; add the end-of-attributes
6318 * tag or end-collection attribute...
6323 buffer
[0] = IPP_TAG_END
;
6328 buffer
[0] = IPP_TAG_END_COLLECTION
;
6329 buffer
[1] = 0; /* empty name */
6331 buffer
[3] = 0; /* empty value */
6336 if ((*cb
)(dst
, buffer
, (size_t)n
) < 0)
6338 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6339 _cupsBufferRelease((char *)buffer
);
6340 return (IPP_STATE_ERROR
);
6343 ipp
->state
= IPP_STATE_DATA
;
6347 case IPP_STATE_DATA
:
6351 break; /* anti-compiler-warning-code */
6354 _cupsBufferRelease((char *)buffer
);
6356 return (ipp
->state
);
6361 * 'ipp_add_attr()' - Add a new attribute to the message.
6364 static ipp_attribute_t
* /* O - New attribute */
6365 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6366 const char *name
, /* I - Attribute name or NULL */
6367 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6368 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6369 int num_values
) /* I - Number of values */
6371 int alloc_values
; /* Number of values to allocate */
6372 ipp_attribute_t
*attr
; /* New attribute */
6375 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
));
6378 * Range check input...
6381 if (!ipp
|| num_values
< 0)
6385 * Allocate memory, rounding the allocation up as needed...
6388 if (num_values
<= 1)
6391 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6393 attr
= calloc(sizeof(ipp_attribute_t
) +
6394 (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6399 * Initialize attribute...
6403 attr
->name
= _cupsStrAlloc(name
);
6405 attr
->group_tag
= group_tag
;
6406 attr
->value_tag
= value_tag
;
6407 attr
->num_values
= num_values
;
6410 * Add it to the end of the linked list...
6414 ipp
->last
->next
= attr
;
6418 ipp
->prev
= ipp
->last
;
6419 ipp
->last
= ipp
->current
= attr
;
6422 DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr
));
6429 * 'ipp_free_values()' - Free attribute values.
6433 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6434 int element
,/* I - First value to free */
6435 int count
) /* I - Number of values to free */
6437 int i
; /* Looping var */
6438 _ipp_value_t
*value
; /* Current value */
6441 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", (void *)attr
, element
, count
));
6443 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6446 * Free values as needed...
6449 switch (attr
->value_tag
)
6451 case IPP_TAG_TEXTLANG
:
6452 case IPP_TAG_NAMELANG
:
6453 if (element
== 0 && count
== attr
->num_values
&&
6454 attr
->values
[0].string
.language
)
6456 _cupsStrFree(attr
->values
[0].string
.language
);
6457 attr
->values
[0].string
.language
= NULL
;
6459 /* Fall through to other string values */
6463 case IPP_TAG_RESERVED_STRING
:
6464 case IPP_TAG_KEYWORD
:
6466 case IPP_TAG_URISCHEME
:
6467 case IPP_TAG_CHARSET
:
6468 case IPP_TAG_LANGUAGE
:
6469 case IPP_TAG_MIMETYPE
:
6470 for (i
= count
, value
= attr
->values
+ element
;
6474 _cupsStrFree(value
->string
.text
);
6475 value
->string
.text
= NULL
;
6479 case IPP_TAG_DEFAULT
:
6480 case IPP_TAG_UNKNOWN
:
6481 case IPP_TAG_NOVALUE
:
6482 case IPP_TAG_NOTSETTABLE
:
6483 case IPP_TAG_DELETEATTR
:
6484 case IPP_TAG_ADMINDEFINE
:
6485 case IPP_TAG_INTEGER
:
6487 case IPP_TAG_BOOLEAN
:
6489 case IPP_TAG_RESOLUTION
:
6490 case IPP_TAG_RANGE
:
6493 case IPP_TAG_BEGIN_COLLECTION
:
6494 for (i
= count
, value
= attr
->values
+ element
;
6498 ippDelete(value
->collection
);
6499 value
->collection
= NULL
;
6503 case IPP_TAG_STRING
:
6505 for (i
= count
, value
= attr
->values
+ element
;
6509 if (value
->unknown
.data
)
6511 free(value
->unknown
.data
);
6512 value
->unknown
.data
= NULL
;
6520 * If we are not freeing values from the end, move the remaining values up...
6523 if ((element
+ count
) < attr
->num_values
)
6524 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6525 (size_t)(attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6527 attr
->num_values
-= count
;
6532 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6534 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6535 * to "ll-cc", "ll-region", and "charset-number", respectively.
6538 static char * /* O - Language code string */
6539 ipp_get_code(const char *value
, /* I - Locale/charset string */
6540 char *buffer
, /* I - String buffer */
6541 size_t bufsize
) /* I - Size of string buffer */
6543 char *bufptr
, /* Pointer into buffer */
6544 *bufend
; /* End of buffer */
6548 * Convert values to lowercase and change _ to - as needed...
6551 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6552 *value
&& bufptr
< bufend
;
6557 *bufptr
++ = (char)_cups_tolower(*value
);
6562 * Return the converted string...
6570 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6572 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6573 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6576 static char * /* O - Language code string */
6577 ipp_lang_code(const char *locale
, /* I - Locale string */
6578 char *buffer
, /* I - String buffer */
6579 size_t bufsize
) /* I - Size of string buffer */
6582 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6585 if (!_cups_strcasecmp(locale
, "c"))
6587 strlcpy(buffer
, "en", bufsize
);
6591 return (ipp_get_code(locale
, buffer
, bufsize
));
6596 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6599 static size_t /* O - Size of IPP message */
6600 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6601 int collection
) /* I - 1 if a collection, 0 otherwise */
6603 int i
; /* Looping var */
6604 size_t bytes
; /* Number of bytes */
6605 ipp_attribute_t
*attr
; /* Current attribute */
6606 ipp_tag_t group
; /* Current group */
6607 _ipp_value_t
*value
; /* Current value */
6610 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp
, collection
));
6614 DEBUG_puts("4ipp_length: Returning 0 bytes");
6619 * Start with 8 bytes for the IPP message header...
6622 bytes
= collection
? 0 : 8;
6625 * Then add the lengths of each attribute...
6628 group
= IPP_TAG_ZERO
;
6630 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6632 if (attr
->group_tag
!= group
&& !collection
)
6634 group
= attr
->group_tag
;
6635 if (group
== IPP_TAG_ZERO
)
6638 bytes
++; /* Group tag */
6644 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6645 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6647 if ((attr
->value_tag
& ~IPP_TAG_CUPS_CONST
) < IPP_TAG_EXTENSION
)
6648 bytes
+= (size_t)attr
->num_values
;/* Value tag for each value */
6650 bytes
+= (size_t)(5 * attr
->num_values
);
6651 /* Value tag for each value */
6652 bytes
+= (size_t)(2 * attr
->num_values
);
6654 bytes
+= strlen(attr
->name
); /* Name */
6655 bytes
+= (size_t)(2 * attr
->num_values
);
6659 bytes
+= 5; /* Add membername overhead */
6661 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6663 case IPP_TAG_UNSUPPORTED_VALUE
:
6664 case IPP_TAG_DEFAULT
:
6665 case IPP_TAG_UNKNOWN
:
6666 case IPP_TAG_NOVALUE
:
6667 case IPP_TAG_NOTSETTABLE
:
6668 case IPP_TAG_DELETEATTR
:
6669 case IPP_TAG_ADMINDEFINE
:
6672 case IPP_TAG_INTEGER
:
6674 bytes
+= (size_t)(4 * attr
->num_values
);
6677 case IPP_TAG_BOOLEAN
:
6678 bytes
+= (size_t)attr
->num_values
;
6683 case IPP_TAG_KEYWORD
:
6685 case IPP_TAG_URISCHEME
:
6686 case IPP_TAG_CHARSET
:
6687 case IPP_TAG_LANGUAGE
:
6688 case IPP_TAG_MIMETYPE
:
6689 for (i
= 0, value
= attr
->values
;
6690 i
< attr
->num_values
;
6692 if (value
->string
.text
)
6693 bytes
+= strlen(value
->string
.text
);
6697 bytes
+= (size_t)(11 * attr
->num_values
);
6700 case IPP_TAG_RESOLUTION
:
6701 bytes
+= (size_t)(9 * attr
->num_values
);
6704 case IPP_TAG_RANGE
:
6705 bytes
+= (size_t)(8 * attr
->num_values
);
6708 case IPP_TAG_TEXTLANG
:
6709 case IPP_TAG_NAMELANG
:
6710 bytes
+= (size_t)(4 * attr
->num_values
);
6711 /* Charset + text length */
6713 for (i
= 0, value
= attr
->values
;
6714 i
< attr
->num_values
;
6717 if (value
->string
.language
)
6718 bytes
+= strlen(value
->string
.language
);
6720 if (value
->string
.text
)
6721 bytes
+= strlen(value
->string
.text
);
6725 case IPP_TAG_BEGIN_COLLECTION
:
6726 for (i
= 0, value
= attr
->values
;
6727 i
< attr
->num_values
;
6729 bytes
+= ipp_length(value
->collection
, 1);
6733 for (i
= 0, value
= attr
->values
;
6734 i
< attr
->num_values
;
6736 bytes
+= (size_t)value
->unknown
.length
;
6742 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6743 * for the "end of collection" tag and return...
6751 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6758 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6761 static ssize_t
/* O - Number of bytes read */
6762 ipp_read_http(http_t
*http
, /* I - Client connection */
6763 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6764 size_t length
) /* I - Total length */
6766 ssize_t tbytes
, /* Total bytes read */
6767 bytes
; /* Bytes read this pass */
6770 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http
, (void *)buffer
, (int)length
));
6773 * Loop until all bytes are read...
6776 for (tbytes
= 0, bytes
= 0;
6777 tbytes
< (int)length
;
6778 tbytes
+= bytes
, buffer
+= bytes
)
6780 DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT
", http->state=%d", CUPS_LLCAST tbytes
, http
->state
));
6782 if (http
->state
== HTTP_STATE_WAITING
)
6785 if (http
->used
== 0 && !http
->blocking
)
6788 * Wait up to 10 seconds for more data on non-blocking sockets...
6791 if (!httpWait(http
, 10000))
6801 else if (http
->used
== 0 && http
->timeout_value
> 0)
6804 * Wait up to timeout seconds for more data on blocking sockets...
6807 if (!httpWait(http
, (int)(1000 * http
->timeout_value
)))
6818 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- (size_t)tbytes
)) < 0)
6823 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6829 else if (bytes
== 0)
6834 * Return the number of bytes read...
6837 if (tbytes
== 0 && bytes
< 0)
6840 DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST tbytes
));
6847 * 'ipp_read_file()' - Read IPP data from a file.
6850 static ssize_t
/* O - Number of bytes read */
6851 ipp_read_file(int *fd
, /* I - File descriptor */
6852 ipp_uchar_t
*buffer
, /* O - Read buffer */
6853 size_t length
) /* I - Number of bytes to read */
6856 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6858 return (read(*fd
, buffer
, length
));
6864 * 'ipp_set_error()' - Set a formatted, localized error string.
6868 ipp_set_error(ipp_status_t status
, /* I - Status code */
6869 const char *format
, /* I - Printf-style error string */
6870 ...) /* I - Additional arguments as needed */
6872 va_list ap
; /* Pointer to additional args */
6873 char buffer
[2048]; /* Message buffer */
6874 cups_lang_t
*lang
= cupsLangDefault();
6875 /* Current language */
6878 va_start(ap
, format
);
6879 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6882 _cupsSetError(status
, buffer
, 0);
6887 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6891 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6892 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6893 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6894 int element
) /* I - Value number (0-based) */
6896 ipp_attribute_t
*temp
, /* New attribute pointer */
6897 *current
, /* Current attribute in list */
6898 *prev
; /* Previous attribute in list */
6899 int alloc_values
; /* Allocated values */
6903 * If we are setting an existing value element, return it...
6908 if (temp
->num_values
<= 1)
6911 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6912 ~(IPP_MAX_VALUES
- 1);
6914 if (element
< alloc_values
)
6916 if (element
>= temp
->num_values
)
6917 temp
->num_values
= element
+ 1;
6919 return (temp
->values
+ element
);
6923 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6924 * values when num_values > 1.
6927 if (alloc_values
< IPP_MAX_VALUES
)
6928 alloc_values
= IPP_MAX_VALUES
;
6930 alloc_values
+= IPP_MAX_VALUES
;
6932 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6936 * Reallocate memory...
6939 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) + (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6941 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6942 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6947 * Zero the new memory...
6950 memset(temp
->values
+ temp
->num_values
, 0, (size_t)(alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6955 * Reset pointers in the list...
6958 if (ipp
->current
== *attr
&& ipp
->prev
)
6961 * Use current "previous" pointer...
6969 * Find this attribute in the linked list...
6972 for (prev
= NULL
, current
= ipp
->attrs
;
6973 current
&& current
!= *attr
;
6974 prev
= current
, current
= current
->next
);
6979 * This is a serious error!
6983 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
6984 _("IPP attribute is not a member of the message."), 1);
6985 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
6995 ipp
->current
= temp
;
6998 if (ipp
->last
== *attr
)
7005 * Return the value element...
7008 if (element
>= temp
->num_values
)
7009 temp
->num_values
= element
+ 1;
7011 return (temp
->values
+ element
);
7016 * 'ipp_write_file()' - Write IPP data to a file.
7019 static ssize_t
/* O - Number of bytes written */
7020 ipp_write_file(int *fd
, /* I - File descriptor */
7021 ipp_uchar_t
*buffer
, /* I - Data to write */
7022 size_t length
) /* I - Number of bytes to write */
7025 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
7027 return (write(*fd
, buffer
, length
));