2 * Internet Printing Protocol functions for CUPS.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
13 * This file is subject to the Apple OS-Developed Software exception.
17 * Include necessary headers...
20 #include "cups-private.h"
31 static ipp_attribute_t
*ipp_add_attr(ipp_t
*ipp
, const char *name
,
32 ipp_tag_t group_tag
, ipp_tag_t value_tag
,
34 static void ipp_free_values(ipp_attribute_t
*attr
, int element
,
36 static char *ipp_get_code(const char *locale
, char *buffer
, size_t bufsize
) _CUPS_NONNULL((1, 2));
37 static char *ipp_lang_code(const char *locale
, char *buffer
, size_t bufsize
) _CUPS_NONNULL((1, 2));
38 static size_t ipp_length(ipp_t
*ipp
, int collection
);
39 static ssize_t
ipp_read_http(http_t
*http
, ipp_uchar_t
*buffer
,
41 static ssize_t
ipp_read_file(int *fd
, ipp_uchar_t
*buffer
,
43 static void ipp_set_error(ipp_status_t status
, const char *format
,
45 static _ipp_value_t
*ipp_set_value(ipp_t
*ipp
, ipp_attribute_t
**attr
,
47 static ssize_t
ipp_write_file(int *fd
, ipp_uchar_t
*buffer
,
52 * '_cupsBufferGet()' - Get a read/write buffer.
55 char * /* O - Buffer */
56 _cupsBufferGet(size_t size
) /* I - Size required */
58 _cups_buffer_t
*buffer
; /* Current buffer */
59 _cups_globals_t
*cg
= _cupsGlobals();
63 for (buffer
= cg
->cups_buffers
; buffer
; buffer
= buffer
->next
)
64 if (!buffer
->used
&& buffer
->size
>= size
)
69 if ((buffer
= malloc(sizeof(_cups_buffer_t
) + size
- 1)) == NULL
)
72 buffer
->next
= cg
->cups_buffers
;
74 cg
->cups_buffers
= buffer
;
84 * '_cupsBufferRelease()' - Release a read/write buffer.
88 _cupsBufferRelease(char *b
) /* I - Buffer to release */
90 _cups_buffer_t
*buffer
; /* Buffer */
94 * Mark this buffer as unused...
97 buffer
= (_cups_buffer_t
*)(b
- offsetof(_cups_buffer_t
, d
));
103 * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
105 * The @code ipp@ parameter refers to an IPP message previously created using
106 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
108 * The @code group@ parameter specifies the IPP attribute group tag: none
109 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
110 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
111 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
112 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
115 ipp_attribute_t
* /* O - New attribute */
116 ippAddBoolean(ipp_t
*ipp
, /* I - IPP message */
117 ipp_tag_t group
, /* I - IPP group */
118 const char *name
, /* I - Name of attribute */
119 char value
) /* I - Value of attribute */
121 ipp_attribute_t
*attr
; /* New attribute */
124 DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)", (void *)ipp
, group
, ippTagString(group
), name
, value
));
127 * Range check input...
130 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
131 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
135 * Create the attribute...
138 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, 1)) == NULL
)
141 attr
->values
[0].boolean
= value
;
148 * 'ippAddBooleans()' - Add an array of boolean values.
150 * The @code ipp@ parameter refers to an IPP message previously created using
151 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
153 * The @code group@ parameter specifies the IPP attribute group tag: none
154 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
155 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
156 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
157 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
160 ipp_attribute_t
* /* O - New attribute */
161 ippAddBooleans(ipp_t
*ipp
, /* I - IPP message */
162 ipp_tag_t group
, /* I - IPP group */
163 const char *name
, /* I - Name of attribute */
164 int num_values
, /* I - Number of values */
165 const char *values
) /* I - Values */
167 int i
; /* Looping var */
168 ipp_attribute_t
*attr
; /* New attribute */
169 _ipp_value_t
*value
; /* Current value */
172 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
));
175 * Range check input...
178 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
179 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
184 * Create the attribute...
187 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, num_values
)) == NULL
)
192 for (i
= num_values
, value
= attr
->values
;
195 value
->boolean
= *values
++;
203 * 'ippAddCollection()' - Add a collection value.
205 * The @code ipp@ parameter refers to an IPP message previously created using
206 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
208 * The @code group@ parameter specifies the IPP attribute group tag: none
209 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
210 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
211 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
212 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
214 * @since CUPS 1.1.19/macOS 10.3@
217 ipp_attribute_t
* /* O - New attribute */
218 ippAddCollection(ipp_t
*ipp
, /* I - IPP message */
219 ipp_tag_t group
, /* I - IPP group */
220 const char *name
, /* I - Name of attribute */
221 ipp_t
*value
) /* I - Value */
223 ipp_attribute_t
*attr
; /* New attribute */
226 DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
229 * Range check input...
232 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
233 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
237 * Create the attribute...
240 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
, 1)) == NULL
)
243 attr
->values
[0].collection
= value
;
253 * 'ippAddCollections()' - Add an array of collection values.
255 * The @code ipp@ parameter refers to an IPP message previously created using
256 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
258 * The @code group@ parameter specifies the IPP attribute group tag: none
259 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
260 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
261 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
262 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
264 * @since CUPS 1.1.19/macOS 10.3@
267 ipp_attribute_t
* /* O - New attribute */
269 ipp_t
*ipp
, /* I - IPP message */
270 ipp_tag_t group
, /* I - IPP group */
271 const char *name
, /* I - Name of attribute */
272 int num_values
, /* I - Number of values */
273 const ipp_t
**values
) /* I - Values */
275 int i
; /* Looping var */
276 ipp_attribute_t
*attr
; /* New attribute */
277 _ipp_value_t
*value
; /* Current value */
280 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
));
283 * Range check input...
286 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
287 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
292 * Create the attribute...
295 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
,
296 num_values
)) == NULL
)
301 for (i
= num_values
, value
= attr
->values
;
305 value
->collection
= (ipp_t
*)*values
++;
306 value
->collection
->use
++;
315 * 'ippAddDate()' - Add a dateTime attribute to an IPP message.
317 * The @code ipp@ parameter refers to an IPP message previously created using
318 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
320 * The @code group@ parameter specifies the IPP attribute group tag: none
321 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
322 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
323 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
324 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
327 ipp_attribute_t
* /* O - New attribute */
328 ippAddDate(ipp_t
*ipp
, /* I - IPP message */
329 ipp_tag_t group
, /* I - IPP group */
330 const char *name
, /* I - Name of attribute */
331 const ipp_uchar_t
*value
) /* I - Value */
333 ipp_attribute_t
*attr
; /* New attribute */
336 DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
339 * Range check input...
342 if (!ipp
|| !name
|| !value
|| group
< IPP_TAG_ZERO
||
343 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
347 * Create the attribute...
350 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_DATE
, 1)) == NULL
)
353 memcpy(attr
->values
[0].date
, value
, 11);
360 * 'ippAddInteger()' - Add a integer attribute to an IPP message.
362 * The @code ipp@ parameter refers to an IPP message previously created using
363 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
365 * The @code group@ parameter specifies the IPP attribute group tag: none
366 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
367 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
368 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
369 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
371 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
372 * (@code IPP_TAG_INTEGER@).
375 ipp_attribute_t
* /* O - New attribute */
376 ippAddInteger(ipp_t
*ipp
, /* I - IPP message */
377 ipp_tag_t group
, /* I - IPP group */
378 ipp_tag_t value_tag
, /* I - Type of attribute */
379 const char *name
, /* I - Name of attribute */
380 int value
) /* I - Value of attribute */
382 ipp_attribute_t
*attr
; /* New attribute */
385 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
));
387 value_tag
&= IPP_TAG_CUPS_MASK
;
390 * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
394 if (value_tag
>= IPP_TAG_UNSUPPORTED_VALUE
&& value_tag
<= IPP_TAG_ADMINDEFINE
)
395 return (ippAddOutOfBand(ipp
, group
, value_tag
, name
));
398 * Range check input...
402 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
403 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
404 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
))
407 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
408 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
413 * Create the attribute...
416 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
419 attr
->values
[0].integer
= value
;
426 * 'ippAddIntegers()' - Add an array of integer values.
428 * The @code ipp@ parameter refers to an IPP message previously created using
429 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
431 * The @code group@ parameter specifies the IPP attribute group tag: none
432 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
433 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
434 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
435 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
437 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
438 * (@code IPP_TAG_INTEGER@).
441 ipp_attribute_t
* /* O - New attribute */
442 ippAddIntegers(ipp_t
*ipp
, /* I - IPP message */
443 ipp_tag_t group
, /* I - IPP group */
444 ipp_tag_t value_tag
, /* I - Type of attribute */
445 const char *name
, /* I - Name of attribute */
446 int num_values
, /* I - Number of values */
447 const int *values
) /* I - Values */
449 int i
; /* Looping var */
450 ipp_attribute_t
*attr
; /* New attribute */
451 _ipp_value_t
*value
; /* Current value */
454 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
));
456 value_tag
&= IPP_TAG_CUPS_MASK
;
459 * Range check input...
463 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
464 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
465 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
) ||
469 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
470 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
476 * Create the attribute...
479 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
484 for (i
= num_values
, value
= attr
->values
;
487 value
->integer
= *values
++;
495 * 'ippAddOctetString()' - Add an octetString value to an IPP message.
497 * The @code ipp@ parameter refers to an IPP message previously created using
498 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
500 * The @code group@ parameter specifies the IPP attribute group tag: none
501 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
502 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
503 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
504 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
506 * @since CUPS 1.2/macOS 10.5@
509 ipp_attribute_t
* /* O - New attribute */
510 ippAddOctetString(ipp_t
*ipp
, /* I - IPP message */
511 ipp_tag_t group
, /* I - IPP group */
512 const char *name
, /* I - Name of attribute */
513 const void *data
, /* I - octetString data */
514 int datalen
) /* I - Length of data in bytes */
516 ipp_attribute_t
*attr
; /* New attribute */
519 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
520 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
521 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
524 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_STRING
, 1)) == NULL
)
528 * Initialize the attribute data...
531 attr
->values
[0].unknown
.length
= datalen
;
535 if ((attr
->values
[0].unknown
.data
= malloc((size_t)datalen
)) == NULL
)
537 ippDeleteAttribute(ipp
, attr
);
541 memcpy(attr
->values
[0].unknown
.data
, data
, (size_t)datalen
);
545 * Return the new attribute...
553 * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
555 * The @code ipp@ parameter refers to an IPP message previously created using
556 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
558 * The @code group@ parameter specifies the IPP attribute group tag: none
559 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
560 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
561 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
562 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
564 * Supported out-of-band values include unsupported-value
565 * (@code IPP_TAG_UNSUPPORTED_VALUE@), default (@code IPP_TAG_DEFAULT@), unknown
566 * (@code IPP_TAG_UNKNOWN@), no-value (@code IPP_TAG_NOVALUE@), not-settable
567 * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
568 * admin-define (@code IPP_TAG_ADMINDEFINE@).
570 * @since CUPS 1.6/macOS 10.8@
573 ipp_attribute_t
* /* O - New attribute */
574 ippAddOutOfBand(ipp_t
*ipp
, /* I - IPP message */
575 ipp_tag_t group
, /* I - IPP group */
576 ipp_tag_t value_tag
, /* I - Type of attribute */
577 const char *name
) /* I - Name of attribute */
579 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
));
581 value_tag
&= IPP_TAG_CUPS_MASK
;
584 * Range check input...
587 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
588 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
589 (value_tag
!= IPP_TAG_UNSUPPORTED_VALUE
&&
590 value_tag
!= IPP_TAG_DEFAULT
&&
591 value_tag
!= IPP_TAG_UNKNOWN
&&
592 value_tag
!= IPP_TAG_NOVALUE
&&
593 value_tag
!= IPP_TAG_NOTSETTABLE
&&
594 value_tag
!= IPP_TAG_DELETEATTR
&&
595 value_tag
!= IPP_TAG_ADMINDEFINE
))
599 * Create the attribute...
602 return (ipp_add_attr(ipp
, name
, group
, value_tag
, 1));
607 * 'ippAddRange()' - Add a range of values to an IPP message.
609 * The @code ipp@ parameter refers to an IPP message previously created using
610 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
612 * The @code group@ parameter specifies the IPP attribute group tag: none
613 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
614 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
615 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
616 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
618 * The @code lower@ parameter must be less than or equal to the @code upper@ parameter.
621 ipp_attribute_t
* /* O - New attribute */
622 ippAddRange(ipp_t
*ipp
, /* I - IPP message */
623 ipp_tag_t group
, /* I - IPP group */
624 const char *name
, /* I - Name of attribute */
625 int lower
, /* I - Lower value */
626 int upper
) /* I - Upper value */
628 ipp_attribute_t
*attr
; /* New attribute */
631 DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, upper=%d)", (void *)ipp
, group
, ippTagString(group
), name
, lower
, upper
));
634 * Range check input...
637 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
638 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
642 * Create the attribute...
645 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, 1)) == NULL
)
648 attr
->values
[0].range
.lower
= lower
;
649 attr
->values
[0].range
.upper
= upper
;
656 * 'ippAddRanges()' - Add ranges of values to an IPP message.
658 * The @code ipp@ parameter refers to an IPP message previously created using
659 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
661 * The @code group@ parameter specifies the IPP attribute group tag: none
662 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
663 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
664 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
665 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
668 ipp_attribute_t
* /* O - New attribute */
669 ippAddRanges(ipp_t
*ipp
, /* I - IPP message */
670 ipp_tag_t group
, /* I - IPP group */
671 const char *name
, /* I - Name of attribute */
672 int num_values
, /* I - Number of values */
673 const int *lower
, /* I - Lower values */
674 const int *upper
) /* I - Upper values */
676 int i
; /* Looping var */
677 ipp_attribute_t
*attr
; /* New attribute */
678 _ipp_value_t
*value
; /* Current value */
681 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
));
684 * Range check input...
687 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
688 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
693 * Create the attribute...
696 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, num_values
)) == NULL
)
701 for (i
= num_values
, value
= attr
->values
;
705 value
->range
.lower
= *lower
++;
706 value
->range
.upper
= *upper
++;
715 * 'ippAddResolution()' - Add a resolution value to an IPP message.
717 * The @code ipp@ parameter refers to an IPP message previously created using
718 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
720 * The @code group@ parameter specifies the IPP attribute group tag: none
721 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
722 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
723 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
724 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
727 ipp_attribute_t
* /* O - New attribute */
728 ippAddResolution(ipp_t
*ipp
, /* I - IPP message */
729 ipp_tag_t group
, /* I - IPP group */
730 const char *name
, /* I - Name of attribute */
731 ipp_res_t units
, /* I - Units for resolution */
732 int xres
, /* I - X resolution */
733 int yres
) /* I - Y resolution */
735 ipp_attribute_t
*attr
; /* New attribute */
738 DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", units=%d, xres=%d, yres=%d)", (void *)ipp
, group
,
739 ippTagString(group
), name
, units
, xres
, yres
));
742 * Range check input...
745 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
746 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
747 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
||
748 xres
< 0 || yres
< 0)
752 * Create the attribute...
755 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, 1)) == NULL
)
758 attr
->values
[0].resolution
.xres
= xres
;
759 attr
->values
[0].resolution
.yres
= yres
;
760 attr
->values
[0].resolution
.units
= units
;
767 * 'ippAddResolutions()' - Add resolution values to an IPP message.
769 * The @code ipp@ parameter refers to an IPP message previously created using
770 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
772 * The @code group@ parameter specifies the IPP attribute group tag: none
773 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
774 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
775 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
776 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
779 ipp_attribute_t
* /* O - New attribute */
780 ippAddResolutions(ipp_t
*ipp
, /* I - IPP message */
781 ipp_tag_t group
, /* I - IPP group */
782 const char *name
, /* I - Name of attribute */
783 int num_values
,/* I - Number of values */
784 ipp_res_t units
, /* I - Units for resolution */
785 const int *xres
, /* I - X resolutions */
786 const int *yres
) /* I - Y resolutions */
788 int i
; /* Looping var */
789 ipp_attribute_t
*attr
; /* New attribute */
790 _ipp_value_t
*value
; /* Current value */
793 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
));
796 * Range check input...
799 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
800 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
802 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
)
806 * Create the attribute...
809 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, num_values
)) == NULL
)
814 for (i
= num_values
, value
= attr
->values
;
818 value
->resolution
.xres
= *xres
++;
819 value
->resolution
.yres
= *yres
++;
820 value
->resolution
.units
= units
;
829 * 'ippAddSeparator()' - Add a group separator to an IPP message.
831 * The @code ipp@ parameter refers to an IPP message previously created using
832 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
835 ipp_attribute_t
* /* O - New attribute */
836 ippAddSeparator(ipp_t
*ipp
) /* I - IPP message */
838 DEBUG_printf(("ippAddSeparator(ipp=%p)", (void *)ipp
));
841 * Range check input...
848 * Create the attribute...
851 return (ipp_add_attr(ipp
, NULL
, IPP_TAG_ZERO
, IPP_TAG_ZERO
, 0));
856 * 'ippAddString()' - Add a language-encoded string to an IPP message.
858 * The @code ipp@ parameter refers to an IPP message previously created using
859 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
861 * The @code group@ parameter specifies the IPP attribute group tag: none
862 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
863 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
864 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
865 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
867 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
868 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
869 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
870 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
871 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
872 * (@code IPP_TAG_URISCHEME@).
874 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
875 * textWithLanguage string values and must be @code NULL@ for all other string values.
878 ipp_attribute_t
* /* O - New attribute */
879 ippAddString(ipp_t
*ipp
, /* I - IPP message */
880 ipp_tag_t group
, /* I - IPP group */
881 ipp_tag_t value_tag
, /* I - Type of attribute */
882 const char *name
, /* I - Name of attribute */
883 const char *language
, /* I - Language code */
884 const char *value
) /* I - Value */
886 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
887 ipp_attribute_t
*attr
; /* New attribute */
888 char code
[IPP_MAX_LANGUAGE
];
889 /* Charset/language code buffer */
892 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
));
895 * Range check input...
898 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
901 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
902 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
903 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
904 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
)
907 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
908 != (language
!= NULL
))
911 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
912 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
917 * See if we need to map charset, language, or locale values...
920 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
921 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
922 value_tag
= temp_tag
; /* Don't do a fast copy */
923 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
) &&
924 strcmp(value
, ipp_get_code(value
, code
, sizeof(code
))))
925 value_tag
= temp_tag
; /* Don't do a fast copy */
926 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
) &&
927 strcmp(value
, ipp_lang_code(value
, code
, sizeof(code
))))
928 value_tag
= temp_tag
; /* Don't do a fast copy */
931 * Create the attribute...
934 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
938 * Initialize the attribute data...
941 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
943 attr
->values
[0].string
.language
= (char *)language
;
944 attr
->values
[0].string
.text
= (char *)value
;
949 attr
->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
954 if (value_tag
== IPP_TAG_CHARSET
)
955 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_get_code(value
, code
,
957 else if (value_tag
== IPP_TAG_LANGUAGE
)
958 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_lang_code(value
, code
,
961 attr
->values
[0].string
.text
= _cupsStrAlloc(value
);
970 * 'ippAddStringf()' - Add a formatted string to an IPP message.
972 * The @code ipp@ parameter refers to an IPP message previously created using
973 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
975 * The @code group@ parameter specifies the IPP attribute group tag: none
976 * (@code IPP_TAG_ZERO@, for member attributes), document
977 * (@code IPP_TAG_DOCUMENT@), event notification
978 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
979 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
980 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
982 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
983 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
984 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
985 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
986 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
987 * (@code IPP_TAG_URISCHEME@).
989 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
990 * and textWithLanguage string values and must be @code NULL@ for all other
993 * The @code format@ parameter uses formatting characters compatible with the
994 * printf family of standard functions. Additional arguments follow it as
995 * needed. The formatted string is truncated as needed to the maximum length of
996 * the corresponding value type.
998 * @since CUPS 1.7/macOS 10.9@
1001 ipp_attribute_t
* /* O - New attribute */
1002 ippAddStringf(ipp_t
*ipp
, /* I - IPP message */
1003 ipp_tag_t group
, /* I - IPP group */
1004 ipp_tag_t value_tag
, /* I - Type of attribute */
1005 const char *name
, /* I - Name of attribute */
1006 const char *language
, /* I - Language code (@code NULL@ for default) */
1007 const char *format
, /* I - Printf-style format string */
1008 ...) /* I - Additional arguments as needed */
1010 ipp_attribute_t
*attr
; /* New attribute */
1011 va_list ap
; /* Argument pointer */
1014 va_start(ap
, format
);
1015 attr
= ippAddStringfv(ipp
, group
, value_tag
, name
, language
, format
, ap
);
1023 * 'ippAddStringfv()' - Add a formatted string to an IPP message.
1025 * The @code ipp@ parameter refers to an IPP message previously created using
1026 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1028 * The @code group@ parameter specifies the IPP attribute group tag: none
1029 * (@code IPP_TAG_ZERO@, for member attributes), document
1030 * (@code IPP_TAG_DOCUMENT@), event notification
1031 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1032 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1033 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1035 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1036 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1037 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1038 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1039 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1040 * (@code IPP_TAG_URISCHEME@).
1042 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1043 * and textWithLanguage string values and must be @code NULL@ for all other
1046 * The @code format@ parameter uses formatting characters compatible with the
1047 * printf family of standard functions. Additional arguments are passed in the
1048 * stdarg pointer @code ap@. The formatted string is truncated as needed to the
1049 * maximum length of the corresponding value type.
1051 * @since CUPS 1.7/macOS 10.9@
1054 ipp_attribute_t
* /* O - New attribute */
1055 ippAddStringfv(ipp_t
*ipp
, /* I - IPP message */
1056 ipp_tag_t group
, /* I - IPP group */
1057 ipp_tag_t value_tag
, /* I - Type of attribute */
1058 const char *name
, /* I - Name of attribute */
1059 const char *language
, /* I - Language code (@code NULL@ for default) */
1060 const char *format
, /* I - Printf-style format string */
1061 va_list ap
) /* I - Additional arguments */
1063 char buffer
[IPP_MAX_TEXT
+ 4];
1064 /* Formatted text string */
1065 ssize_t bytes
, /* Length of formatted value */
1066 max_bytes
; /* Maximum number of bytes for value */
1070 * Range check input...
1073 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1074 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1075 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
1076 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
1080 if ((value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_NAMELANG
)
1081 != (language
!= NULL
))
1085 * Format the string...
1088 if (!strcmp(format
, "%s"))
1091 * Optimize the simple case...
1094 const char *s
= va_arg(ap
, char *);
1099 bytes
= (ssize_t
)strlen(s
);
1100 strlcpy(buffer
, s
, sizeof(buffer
));
1105 * Do a full formatting of the message...
1108 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
1113 * Limit the length of the string...
1120 case IPP_TAG_TEXTLANG
:
1121 max_bytes
= IPP_MAX_TEXT
;
1125 case IPP_TAG_NAMELANG
:
1126 max_bytes
= IPP_MAX_NAME
;
1129 case IPP_TAG_CHARSET
:
1130 max_bytes
= IPP_MAX_CHARSET
;
1133 case IPP_TAG_KEYWORD
:
1134 max_bytes
= IPP_MAX_KEYWORD
;
1137 case IPP_TAG_LANGUAGE
:
1138 max_bytes
= IPP_MAX_LANGUAGE
;
1141 case IPP_TAG_MIMETYPE
:
1142 max_bytes
= IPP_MAX_MIMETYPE
;
1146 max_bytes
= IPP_MAX_URI
;
1149 case IPP_TAG_URISCHEME
:
1150 max_bytes
= IPP_MAX_URISCHEME
;
1154 if (bytes
>= max_bytes
)
1156 char *bufmax
, /* Buffer at max_bytes */
1157 *bufptr
; /* Pointer into buffer */
1159 bufptr
= buffer
+ strlen(buffer
) - 1;
1160 bufmax
= buffer
+ max_bytes
- 1;
1162 while (bufptr
> bufmax
)
1166 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
1177 * Add the formatted string and return...
1180 return (ippAddString(ipp
, group
, value_tag
, name
, language
, buffer
));
1185 * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
1187 * The @code ipp@ parameter refers to an IPP message previously created using
1188 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1190 * The @code group@ parameter specifies the IPP attribute group tag: none
1191 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
1192 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
1193 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
1194 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1196 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1197 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1198 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1199 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1200 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1201 * (@code IPP_TAG_URISCHEME@).
1203 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1204 * textWithLanguage string values and must be @code NULL@ for all other string values.
1207 ipp_attribute_t
* /* O - New attribute */
1209 ipp_t
*ipp
, /* I - IPP message */
1210 ipp_tag_t group
, /* I - IPP group */
1211 ipp_tag_t value_tag
, /* I - Type of attribute */
1212 const char *name
, /* I - Name of attribute */
1213 int num_values
, /* I - Number of values */
1214 const char *language
, /* I - Language code (@code NULL@ for default) */
1215 const char * const *values
) /* I - Values */
1217 int i
; /* Looping var */
1218 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1219 ipp_attribute_t
*attr
; /* New attribute */
1220 _ipp_value_t
*value
; /* Current value */
1221 char code
[32]; /* Language/charset value buffer */
1224 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
));
1227 * Range check input...
1230 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
1233 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1234 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1235 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1236 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
||
1240 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1241 != (language
!= NULL
))
1244 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1245 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1251 * See if we need to map charset, language, or locale values...
1254 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
1255 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1256 value_tag
= temp_tag
; /* Don't do a fast copy */
1257 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
))
1259 for (i
= 0; i
< num_values
; i
++)
1260 if (strcmp(values
[i
], ipp_get_code(values
[i
], code
, sizeof(code
))))
1262 value_tag
= temp_tag
; /* Don't do a fast copy */
1266 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
))
1268 for (i
= 0; i
< num_values
; i
++)
1269 if (strcmp(values
[i
], ipp_lang_code(values
[i
], code
, sizeof(code
))))
1271 value_tag
= temp_tag
; /* Don't do a fast copy */
1277 * Create the attribute...
1280 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
1284 * Initialize the attribute data...
1287 for (i
= num_values
, value
= attr
->values
;
1293 if (value
== attr
->values
)
1295 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1296 value
->string
.language
= (char *)language
;
1298 value
->string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1302 value
->string
.language
= attr
->values
[0].string
.language
;
1307 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1308 value
->string
.text
= (char *)*values
++;
1309 else if (value_tag
== IPP_TAG_CHARSET
)
1310 value
->string
.text
= _cupsStrAlloc(ipp_get_code(*values
++, code
, sizeof(code
)));
1311 else if (value_tag
== IPP_TAG_LANGUAGE
)
1312 value
->string
.text
= _cupsStrAlloc(ipp_lang_code(*values
++, code
, sizeof(code
)));
1314 value
->string
.text
= _cupsStrAlloc(*values
++);
1323 * 'ippContainsInteger()' - Determine whether an attribute contains the
1324 * specified value or is within the list of ranges.
1326 * Returns non-zero when the attribute contains either a matching integer or
1327 * enum value, or the value falls within one of the rangeOfInteger values for
1330 * @since CUPS 1.7/macOS 10.9@
1333 int /* O - 1 on a match, 0 on no match */
1335 ipp_attribute_t
*attr
, /* I - Attribute */
1336 int value
) /* I - Integer/enum value */
1338 int i
; /* Looping var */
1339 _ipp_value_t
*avalue
; /* Current attribute value */
1343 * Range check input...
1349 if (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
&&
1350 attr
->value_tag
!= IPP_TAG_RANGE
)
1357 if (attr
->value_tag
== IPP_TAG_RANGE
)
1359 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1360 if (value
>= avalue
->range
.lower
&& value
<= avalue
->range
.upper
)
1365 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1366 if (value
== avalue
->integer
)
1375 * 'ippContainsString()' - Determine whether an attribute contains the
1376 * specified string value.
1378 * Returns non-zero when the attribute contains a matching charset, keyword,
1379 * naturalLanguage, mimeMediaType, name, text, uri, or uriScheme value.
1381 * @since CUPS 1.7/macOS 10.9@
1384 int /* O - 1 on a match, 0 on no match */
1386 ipp_attribute_t
*attr
, /* I - Attribute */
1387 const char *value
) /* I - String value */
1389 int i
; /* Looping var */
1390 _ipp_value_t
*avalue
; /* Current attribute value */
1393 DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", (void *)attr
, value
));
1396 * Range check input...
1399 if (!attr
|| !value
)
1401 DEBUG_puts("1ippContainsString: Returning 0 (bad input)");
1409 DEBUG_printf(("1ippContainsString: attr %s, %s with %d values.",
1410 attr
->name
, ippTagString(attr
->value_tag
),
1413 switch (attr
->value_tag
& IPP_TAG_CUPS_MASK
)
1415 case IPP_TAG_CHARSET
:
1416 case IPP_TAG_KEYWORD
:
1417 case IPP_TAG_LANGUAGE
:
1419 case IPP_TAG_URISCHEME
:
1420 for (i
= attr
->num_values
, avalue
= attr
->values
;
1424 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1425 attr
->num_values
- i
, avalue
->string
.text
));
1427 if (!strcmp(value
, avalue
->string
.text
))
1429 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1434 case IPP_TAG_MIMETYPE
:
1436 case IPP_TAG_NAMELANG
:
1438 case IPP_TAG_TEXTLANG
:
1439 for (i
= attr
->num_values
, avalue
= attr
->values
;
1443 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1444 attr
->num_values
- i
, avalue
->string
.text
));
1446 if (!_cups_strcasecmp(value
, avalue
->string
.text
))
1448 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1457 DEBUG_puts("1ippContainsString: Returning 0 (no match)");
1464 * 'ippCopyAttribute()' - Copy an attribute.
1466 * The specified attribute, @code attr@, is copied to the destination IPP message.
1467 * When @code quickcopy@ is non-zero, a "shallow" reference copy of the attribute is
1468 * created - this should only be done as long as the original source IPP message will
1469 * not be freed for the life of the destination.
1471 * @since CUPS 1.6/macOS 10.8@
1475 ipp_attribute_t
* /* O - New attribute */
1477 ipp_t
*dst
, /* I - Destination IPP message */
1478 ipp_attribute_t
*srcattr
, /* I - Attribute to copy */
1479 int quickcopy
) /* I - 1 for a referenced copy, 0 for normal */
1481 int i
; /* Looping var */
1482 ipp_tag_t srctag
; /* Source value tag */
1483 ipp_attribute_t
*dstattr
; /* Destination attribute */
1484 _ipp_value_t
*srcval
, /* Source value */
1485 *dstval
; /* Destination value */
1488 DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", (void *)dst
, (void *)srcattr
, quickcopy
));
1491 * Range check input...
1494 if (!dst
|| !srcattr
)
1501 quickcopy
= (quickcopy
&& (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)) ? IPP_TAG_CUPS_CONST
: 0;
1502 srctag
= srcattr
->value_tag
& IPP_TAG_CUPS_MASK
;
1507 dstattr
= ippAddSeparator(dst
);
1510 case IPP_TAG_UNSUPPORTED_VALUE
:
1511 case IPP_TAG_DEFAULT
:
1512 case IPP_TAG_UNKNOWN
:
1513 case IPP_TAG_NOVALUE
:
1514 case IPP_TAG_NOTSETTABLE
:
1515 case IPP_TAG_DELETEATTR
:
1516 case IPP_TAG_ADMINDEFINE
:
1517 dstattr
= ippAddOutOfBand(dst
, srcattr
->group_tag
, srctag
, srcattr
->name
);
1520 case IPP_TAG_INTEGER
:
1522 case IPP_TAG_BOOLEAN
:
1524 case IPP_TAG_RESOLUTION
:
1525 case IPP_TAG_RANGE
:
1526 if ((dstattr
= ipp_add_attr(dst
, srcattr
->name
, srcattr
->group_tag
, srctag
, srcattr
->num_values
)) != NULL
)
1527 memcpy(dstattr
->values
, srcattr
->values
, (size_t)srcattr
->num_values
* sizeof(_ipp_value_t
));
1532 case IPP_TAG_RESERVED_STRING
:
1533 case IPP_TAG_KEYWORD
:
1535 case IPP_TAG_URISCHEME
:
1536 case IPP_TAG_CHARSET
:
1537 case IPP_TAG_LANGUAGE
:
1538 case IPP_TAG_MIMETYPE
:
1539 if ((dstattr
= ippAddStrings(dst
, srcattr
->group_tag
, (ipp_tag_t
)(srctag
| quickcopy
), srcattr
->name
, srcattr
->num_values
, NULL
, NULL
)) == NULL
)
1545 * Can safely quick-copy these string values...
1548 memcpy(dstattr
->values
, srcattr
->values
, (size_t)srcattr
->num_values
* sizeof(_ipp_value_t
));
1553 * Otherwise do a normal reference counted copy...
1556 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
; i
> 0; i
--, srcval
++, dstval
++)
1557 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1561 case IPP_TAG_TEXTLANG
:
1562 case IPP_TAG_NAMELANG
:
1563 if ((dstattr
= ippAddStrings(dst
, srcattr
->group_tag
, (ipp_tag_t
)(srctag
| quickcopy
), srcattr
->name
, srcattr
->num_values
, NULL
, NULL
)) == NULL
)
1569 * Can safely quick-copy these string values...
1572 memcpy(dstattr
->values
, srcattr
->values
, (size_t)srcattr
->num_values
* sizeof(_ipp_value_t
));
1574 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1577 * Otherwise do a normal reference counted copy...
1580 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
; i
> 0; i
--, srcval
++, dstval
++)
1582 if (srcval
== srcattr
->values
)
1583 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1585 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1587 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1592 case IPP_TAG_BEGIN_COLLECTION
:
1593 if ((dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
, srcattr
->num_values
, NULL
)) == NULL
)
1596 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
; i
> 0; i
--, srcval
++, dstval
++)
1598 dstval
->collection
= srcval
->collection
;
1599 srcval
->collection
->use
++;
1603 case IPP_TAG_STRING
:
1605 if ((dstattr
= ipp_add_attr(dst
, srcattr
->name
, srcattr
->group_tag
, srctag
, srcattr
->num_values
)) == NULL
)
1608 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
; i
> 0; i
--, srcval
++, dstval
++)
1610 dstval
->unknown
.length
= srcval
->unknown
.length
;
1612 if (dstval
->unknown
.length
> 0)
1614 if ((dstval
->unknown
.data
= malloc((size_t)dstval
->unknown
.length
)) == NULL
)
1615 dstval
->unknown
.length
= 0;
1617 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, (size_t)dstval
->unknown
.length
);
1620 break; /* anti-compiler-warning-code */
1628 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1630 * Zero or more attributes are copied from the source IPP message, @code src@, to the
1631 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1632 * reference copy of the attribute is created - this should only be done as long as the
1633 * original source IPP message will not be freed for the life of the destination.
1635 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1636 * attributes that are copied - the function must return 1 to copy the attribute or
1637 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1640 * @since CUPS 1.6/macOS 10.8@
1643 int /* O - 1 on success, 0 on error */
1645 ipp_t
*dst
, /* I - Destination IPP message */
1646 ipp_t
*src
, /* I - Source IPP message */
1647 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1648 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1649 void *context
) /* I - Context pointer */
1651 ipp_attribute_t
*srcattr
; /* Source attribute */
1654 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)", (void *)dst
, (void *)src
, quickcopy
, (void *)cb
, context
));
1657 * Range check input...
1664 * Loop through source attributes and copy as needed...
1667 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1668 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1669 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1677 * 'ippDateToTime()' - Convert from RFC 2579 Date/Time format to time in
1681 time_t /* O - UNIX time value */
1682 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 2579 date info */
1684 struct tm unixdate
; /* UNIX date/time info */
1685 time_t t
; /* Computed time */
1691 memset(&unixdate
, 0, sizeof(unixdate
));
1694 * RFC-2579 date/time format is:
1696 * Byte(s) Description
1697 * ------- -----------
1698 * 0-1 Year (0 to 65535)
1702 * 5 Minutes (0 to 59)
1703 * 6 Seconds (0 to 60, 60 = "leap second")
1704 * 7 Deciseconds (0 to 9)
1706 * 9 UTC hours (0 to 11)
1707 * 10 UTC minutes (0 to 59)
1710 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1711 unixdate
.tm_mon
= date
[2] - 1;
1712 unixdate
.tm_mday
= date
[3];
1713 unixdate
.tm_hour
= date
[4];
1714 unixdate
.tm_min
= date
[5];
1715 unixdate
.tm_sec
= date
[6];
1717 t
= mktime(&unixdate
);
1720 t
+= date
[9] * 3600 + date
[10] * 60;
1722 t
-= date
[9] * 3600 + date
[10] * 60;
1729 * 'ippDelete()' - Delete an IPP message.
1733 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1735 ipp_attribute_t
*attr
, /* Current attribute */
1736 *next
; /* Next attribute */
1739 DEBUG_printf(("ippDelete(ipp=%p)", (void *)ipp
));
1747 DEBUG_printf(("4debug_retain: %p IPP message (use=%d)", (void *)ipp
, ipp
->use
));
1751 DEBUG_printf(("4debug_free: %p IPP message", (void *)ipp
));
1753 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1757 DEBUG_printf(("4debug_free: %p %s %s%s (%d values)", (void *)attr
, attr
->name
, attr
->num_values
> 1 ? "1setOf " : "", ippTagString(attr
->value_tag
), attr
->num_values
));
1759 ipp_free_values(attr
, 0, attr
->num_values
);
1762 _cupsStrFree(attr
->name
);
1772 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1774 * @since CUPS 1.1.19/macOS 10.3@
1779 ipp_t
*ipp
, /* I - IPP message */
1780 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1782 ipp_attribute_t
*current
, /* Current attribute */
1783 *prev
; /* Previous attribute */
1786 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", (void *)ipp
, (void *)attr
, attr
? attr
->name
: "(null)"));
1789 * Range check input...
1795 DEBUG_printf(("4debug_free: %p %s %s%s (%d values)", (void *)attr
, attr
->name
, attr
->num_values
> 1 ? "1setOf " : "", ippTagString(attr
->value_tag
), attr
->num_values
));
1798 * Find the attribute in the list...
1803 for (current
= ipp
->attrs
, prev
= NULL
;
1805 prev
= current
, current
= current
->next
)
1806 if (current
== attr
)
1809 * Found it, remove the attribute from the list...
1813 prev
->next
= current
->next
;
1815 ipp
->attrs
= current
->next
;
1817 if (current
== ipp
->last
)
1828 * Free memory used by the attribute...
1831 ipp_free_values(attr
, 0, attr
->num_values
);
1834 _cupsStrFree(attr
->name
);
1841 * 'ippDeleteValues()' - Delete values in an attribute.
1843 * The @code element@ parameter specifies the first value to delete, starting at
1844 * 0. It must be less than the number of values returned by @link ippGetCount@.
1846 * The @code attr@ parameter may be modified as a result of setting the value.
1848 * Deleting all values in an attribute deletes the attribute.
1850 * @since CUPS 1.6/macOS 10.8@
1853 int /* O - 1 on success, 0 on failure */
1855 ipp_t
*ipp
, /* I - IPP message */
1856 ipp_attribute_t
**attr
, /* IO - Attribute */
1857 int element
, /* I - Index of first value to delete (0-based) */
1858 int count
) /* I - Number of values to delete */
1861 * Range check input...
1864 if (!ipp
|| !attr
|| !*attr
||
1865 element
< 0 || element
>= (*attr
)->num_values
|| count
<= 0 ||
1866 (element
+ count
) >= (*attr
)->num_values
)
1870 * If we are deleting all values, just delete the attribute entirely.
1873 if (count
== (*attr
)->num_values
)
1875 ippDeleteAttribute(ipp
, *attr
);
1881 * Otherwise free the values in question and return.
1884 ipp_free_values(*attr
, element
, count
);
1891 * 'ippFindAttribute()' - Find a named attribute in a request.
1893 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1894 * of attribute and member names separated by slashes, for example
1895 * "media-col/media-size".
1898 ipp_attribute_t
* /* O - Matching attribute */
1899 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
1900 const char *name
, /* I - Name of attribute */
1901 ipp_tag_t type
) /* I - Type of attribute */
1903 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
1909 * Reset the current pointer...
1912 ipp
->current
= NULL
;
1916 * Search for the attribute...
1919 return (ippFindNextAttribute(ipp
, name
, type
));
1924 * 'ippFindNextAttribute()' - Find the next named attribute in a request.
1926 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1927 * of attribute and member names separated by slashes, for example
1928 * "media-col/media-size".
1931 ipp_attribute_t
* /* O - Matching attribute */
1932 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
1933 const char *name
, /* I - Name of attribute */
1934 ipp_tag_t type
) /* I - Type of attribute */
1936 ipp_attribute_t
*attr
, /* Current atttribute */
1937 *childattr
; /* Child attribute */
1938 ipp_tag_t value_tag
; /* Value tag */
1939 char parent
[1024], /* Parent attribute name */
1940 *child
= NULL
; /* Child attribute name */
1943 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
1948 DEBUG_printf(("3ippFindNextAttribute: atend=%d", ipp
->atend
));
1953 if (strchr(name
, '/'))
1956 * Search for child attribute...
1959 strlcpy(parent
, name
, sizeof(parent
));
1960 if ((child
= strchr(parent
, '/')) == NULL
)
1962 DEBUG_puts("3ippFindNextAttribute: Attribute name too long.");
1968 if (ipp
->current
&& ipp
->current
->name
&& ipp
->current
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&& !strcmp(parent
, ipp
->current
->name
))
1970 while (ipp
->curindex
< ipp
->current
->num_values
)
1972 if ((childattr
= ippFindNextAttribute(ipp
->current
->values
[ipp
->curindex
].collection
, child
, type
)) != NULL
)
1976 if (ipp
->curindex
< ipp
->current
->num_values
&& ipp
->current
->values
[ipp
->curindex
].collection
)
1977 ipp
->current
->values
[ipp
->curindex
].collection
->current
= NULL
;
1980 ipp
->prev
= ipp
->current
;
1981 ipp
->current
= ipp
->current
->next
;
1994 ipp
->current
= ipp
->attrs
;
1999 attr
= ipp
->current
;
2001 else if (ipp
->current
)
2003 ipp
->prev
= ipp
->current
;
2004 attr
= ipp
->current
->next
;
2012 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
2014 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", (void *)attr
, attr
->name
));
2016 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2018 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
2019 (value_tag
== type
|| type
== IPP_TAG_ZERO
|| name
== parent
||
2020 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
2021 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
2023 ipp
->current
= attr
;
2025 if (name
== parent
&& attr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
)
2027 int i
; /* Looping var */
2029 for (i
= 0; i
< attr
->num_values
; i
++)
2031 if ((childattr
= ippFindAttribute(attr
->values
[i
].collection
, child
, type
)) != NULL
)
2033 attr
->values
[0].collection
->curindex
= i
;
2043 ipp
->current
= NULL
;
2052 * 'ippFirstAttribute()' - Return the first attribute in the message.
2054 * @since CUPS 1.6/macOS 10.8@
2057 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
2058 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
2061 * Range check input...
2068 * Return the first attribute...
2071 return (ipp
->current
= ipp
->attrs
);
2076 * 'ippGetBoolean()' - Get a boolean value for an attribute.
2078 * The @code element@ parameter specifies which value to get from 0 to
2079 * @code ippGetCount(attr)@ - 1.
2081 * @since CUPS 1.6/macOS 10.8@
2084 int /* O - Boolean value or 0 on error */
2085 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
2086 int element
) /* I - Value number (0-based) */
2089 * Range check input...
2092 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
2093 element
< 0 || element
>= attr
->num_values
)
2097 * Return the value...
2100 return (attr
->values
[element
].boolean
);
2105 * 'ippGetCollection()' - Get a collection value for an attribute.
2107 * The @code element@ parameter specifies which value to get from 0 to
2108 * @code ippGetCount(attr)@ - 1.
2110 * @since CUPS 1.6/macOS 10.8@
2113 ipp_t
* /* O - Collection value or @code NULL@ on error */
2115 ipp_attribute_t
*attr
, /* I - IPP attribute */
2116 int element
) /* I - Value number (0-based) */
2119 * Range check input...
2122 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
2123 element
< 0 || element
>= attr
->num_values
)
2127 * Return the value...
2130 return (attr
->values
[element
].collection
);
2135 * 'ippGetCount()' - Get the number of values in an attribute.
2137 * @since CUPS 1.6/macOS 10.8@
2140 int /* O - Number of values or 0 on error */
2141 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
2144 * Range check input...
2151 * Return the number of values...
2154 return (attr
->num_values
);
2159 * 'ippGetDate()' - Get a dateTime value for an attribute.
2161 * The @code element@ parameter specifies which value to get from 0 to
2162 * @code ippGetCount(attr)@ - 1.
2164 * @since CUPS 1.6/macOS 10.8@
2167 const ipp_uchar_t
* /* O - dateTime value or @code NULL@ */
2168 ippGetDate(ipp_attribute_t
*attr
, /* I - IPP attribute */
2169 int element
) /* I - Value number (0-based) */
2172 * Range check input...
2175 if (!attr
|| attr
->value_tag
!= IPP_TAG_DATE
||
2176 element
< 0 || element
>= attr
->num_values
)
2180 * Return the value...
2183 return (attr
->values
[element
].date
);
2188 * 'ippGetGroupTag()' - Get the group associated with an attribute.
2190 * @since CUPS 1.6/macOS 10.8@
2193 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
2194 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2197 * Range check input...
2201 return (IPP_TAG_ZERO
);
2204 * Return the group...
2207 return (attr
->group_tag
);
2212 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
2214 * The @code element@ parameter specifies which value to get from 0 to
2215 * @code ippGetCount(attr)@ - 1.
2217 * @since CUPS 1.6/macOS 10.8@
2220 int /* O - Value or 0 on error */
2221 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
2222 int element
) /* I - Value number (0-based) */
2225 * Range check input...
2228 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
2229 element
< 0 || element
>= attr
->num_values
)
2233 * Return the value...
2236 return (attr
->values
[element
].integer
);
2241 * 'ippGetName()' - Get the attribute name.
2243 * @since CUPS 1.6/macOS 10.8@
2246 const char * /* O - Attribute name or @code NULL@ for separators */
2247 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
2250 * Range check input...
2257 * Return the name...
2260 return (attr
->name
);
2265 * 'ippGetOctetString()' - Get an octetString value from an IPP attribute.
2267 * The @code element@ parameter specifies which value to get from 0 to
2268 * @code ippGetCount(attr)@ - 1.
2270 * @since CUPS 1.7/macOS 10.9@
2273 void * /* O - Pointer to octetString data */
2275 ipp_attribute_t
*attr
, /* I - IPP attribute */
2276 int element
, /* I - Value number (0-based) */
2277 int *datalen
) /* O - Length of octetString data */
2280 * Range check input...
2283 if (!attr
|| attr
->value_tag
!= IPP_TAG_STRING
||
2284 element
< 0 || element
>= attr
->num_values
)
2293 * Return the values...
2297 *datalen
= attr
->values
[element
].unknown
.length
;
2299 return (attr
->values
[element
].unknown
.data
);
2304 * 'ippGetOperation()' - Get the operation ID in an IPP message.
2306 * @since CUPS 1.6/macOS 10.8@
2309 ipp_op_t
/* O - Operation ID or 0 on error */
2310 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
2313 * Range check input...
2317 return ((ipp_op_t
)0);
2320 * Return the value...
2323 return (ipp
->request
.op
.operation_id
);
2328 * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
2330 * The @code element@ parameter specifies which value to get from 0 to
2331 * @code ippGetCount(attr)@ - 1.
2333 * @since CUPS 1.6/macOS 10.8@
2336 int /* O - Lower value of range or 0 */
2337 ippGetRange(ipp_attribute_t
*attr
, /* I - IPP attribute */
2338 int element
, /* I - Value number (0-based) */
2339 int *uppervalue
)/* O - Upper value of range */
2342 * Range check input...
2345 if (!attr
|| attr
->value_tag
!= IPP_TAG_RANGE
||
2346 element
< 0 || element
>= attr
->num_values
)
2355 * Return the values...
2359 *uppervalue
= attr
->values
[element
].range
.upper
;
2361 return (attr
->values
[element
].range
.lower
);
2366 * 'ippGetRequestId()' - Get the request ID from an IPP message.
2368 * @since CUPS 1.6/macOS 10.8@
2371 int /* O - Request ID or 0 on error */
2372 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
2375 * Range check input...
2382 * Return the request ID...
2385 return (ipp
->request
.any
.request_id
);
2390 * 'ippGetResolution()' - Get a resolution value for an attribute.
2392 * The @code element@ parameter specifies which value to get from 0 to
2393 * @code ippGetCount(attr)@ - 1.
2395 * @since CUPS 1.6/macOS 10.8@
2398 int /* O - Horizontal/cross feed resolution or 0 */
2400 ipp_attribute_t
*attr
, /* I - IPP attribute */
2401 int element
, /* I - Value number (0-based) */
2402 int *yres
, /* O - Vertical/feed resolution */
2403 ipp_res_t
*units
) /* O - Units for resolution */
2406 * Range check input...
2409 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
2410 element
< 0 || element
>= attr
->num_values
)
2416 *units
= (ipp_res_t
)0;
2422 * Return the value...
2426 *yres
= attr
->values
[element
].resolution
.yres
;
2429 *units
= attr
->values
[element
].resolution
.units
;
2431 return (attr
->values
[element
].resolution
.xres
);
2436 * 'ippGetState()' - Get the IPP message state.
2438 * @since CUPS 1.6/macOS 10.8@
2441 ipp_state_t
/* O - IPP message state value */
2442 ippGetState(ipp_t
*ipp
) /* I - IPP message */
2445 * Range check input...
2449 return (IPP_STATE_IDLE
);
2452 * Return the value...
2455 return (ipp
->state
);
2460 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2462 * @since CUPS 1.6/macOS 10.8@
2465 ipp_status_t
/* O - Status code in IPP message */
2466 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2469 * Range check input...
2473 return (IPP_STATUS_ERROR_INTERNAL
);
2476 * Return the value...
2479 return (ipp
->request
.status
.status_code
);
2484 * 'ippGetString()' - Get the string and optionally the language code for an attribute.
2486 * The @code element@ parameter specifies which value to get from 0 to
2487 * @code ippGetCount(attr)@ - 1.
2489 * @since CUPS 1.6/macOS 10.8@
2493 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2494 int element
, /* I - Value number (0-based) */
2495 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2497 ipp_tag_t tag
; /* Value tag */
2501 * Range check input...
2504 tag
= ippGetValueTag(attr
);
2506 if (!attr
|| element
< 0 || element
>= attr
->num_values
|| (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&& (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
)))
2510 * Return the value...
2514 *language
= attr
->values
[element
].string
.language
;
2516 return (attr
->values
[element
].string
.text
);
2521 * 'ippGetValueTag()' - Get the value tag for an attribute.
2523 * @since CUPS 1.6/macOS 10.8@
2526 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2527 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2530 * Range check input...
2534 return (IPP_TAG_ZERO
);
2537 * Return the value...
2540 return (attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2545 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2547 * @since CUPS 1.6/macOS 10.8@
2550 int /* O - Major version number or 0 on error */
2551 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2552 int *minor
) /* O - Minor version number or @code NULL@ for don't care */
2555 * Range check input...
2567 * Return the value...
2571 *minor
= ipp
->request
.any
.version
[1];
2573 return (ipp
->request
.any
.version
[0]);
2578 * 'ippLength()' - Compute the length of an IPP message.
2581 size_t /* O - Size of IPP message */
2582 ippLength(ipp_t
*ipp
) /* I - IPP message */
2584 return (ipp_length(ipp
, 0));
2589 * 'ippNextAttribute()' - Return the next attribute in the message.
2591 * @since CUPS 1.6/macOS 10.8@
2594 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2595 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2598 * Range check input...
2601 if (!ipp
|| !ipp
->current
)
2605 * Return the next attribute...
2608 return (ipp
->current
= ipp
->current
->next
);
2613 * 'ippNew()' - Allocate a new IPP message.
2616 ipp_t
* /* O - New IPP message */
2619 ipp_t
*temp
; /* New IPP message */
2620 _cups_globals_t
*cg
= _cupsGlobals();
2624 DEBUG_puts("ippNew()");
2626 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2629 * Set default version - usually 2.0...
2632 DEBUG_printf(("4debug_alloc: %p IPP message", (void *)temp
));
2634 if (cg
->server_version
== 0)
2637 temp
->request
.any
.version
[0] = (ipp_uchar_t
)(cg
->server_version
/ 10);
2638 temp
->request
.any
.version
[1] = (ipp_uchar_t
)(cg
->server_version
% 10);
2642 DEBUG_printf(("1ippNew: Returning %p", (void *)temp
));
2649 * 'ippNewRequest()' - Allocate a new IPP request message.
2651 * The new request message is initialized with the "attributes-charset" and
2652 * "attributes-natural-language" attributes added. The
2653 * "attributes-natural-language" value is derived from the current locale.
2655 * @since CUPS 1.2/macOS 10.5@
2658 ipp_t
* /* O - IPP request message */
2659 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2661 ipp_t
*request
; /* IPP request message */
2662 cups_lang_t
*language
; /* Current language localization */
2663 static int request_id
= 0; /* Current request ID */
2664 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2665 /* Mutex for request ID */
2668 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2671 * Create a new IPP message...
2674 if ((request
= ippNew()) == NULL
)
2678 * Set the operation and request ID...
2681 _cupsMutexLock(&request_mutex
);
2683 request
->request
.op
.operation_id
= op
;
2684 request
->request
.op
.request_id
= ++request_id
;
2686 _cupsMutexUnlock(&request_mutex
);
2689 * Use UTF-8 as the character set...
2692 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2693 "attributes-charset", NULL
, "utf-8");
2696 * Get the language from the current locale...
2699 language
= cupsLangDefault();
2701 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2702 "attributes-natural-language", NULL
, language
->language
);
2705 * Return the new request...
2713 * 'ippNewResponse()' - Allocate a new IPP response message.
2715 * The new response message is initialized with the same "version-number",
2716 * "request-id", "attributes-charset", and "attributes-natural-language" as the
2717 * provided request message. If the "attributes-charset" or
2718 * "attributes-natural-language" attributes are missing from the request,
2719 * 'utf-8' and a value derived from the current locale are substituted,
2722 * @since CUPS 1.7/macOS 10.9@
2725 ipp_t
* /* O - IPP response message */
2726 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2728 ipp_t
*response
; /* IPP response message */
2729 ipp_attribute_t
*attr
; /* Current attribute */
2733 * Range check input...
2740 * Create a new IPP message...
2743 if ((response
= ippNew()) == NULL
)
2747 * Copy the request values over to the response...
2750 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2751 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2752 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2755 * The first attribute MUST be attributes-charset...
2758 attr
= request
->attrs
;
2760 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2761 attr
->group_tag
== IPP_TAG_OPERATION
&&
2762 attr
->value_tag
== IPP_TAG_CHARSET
&&
2763 attr
->num_values
== 1)
2766 * Copy charset from request...
2769 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2770 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2775 * Use "utf-8" as the default...
2778 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2779 "attributes-charset", NULL
, "utf-8");
2783 * Then attributes-natural-language...
2789 if (attr
&& attr
->name
&&
2790 !strcmp(attr
->name
, "attributes-natural-language") &&
2791 attr
->group_tag
== IPP_TAG_OPERATION
&&
2792 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2793 attr
->num_values
== 1)
2796 * Copy language from request...
2799 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2800 "attributes-natural-language", NULL
,
2801 attr
->values
[0].string
.text
);
2806 * Use the language from the current locale...
2809 cups_lang_t
*language
= cupsLangDefault();
2810 /* Current locale */
2812 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2813 "attributes-natural-language", NULL
, language
->language
);
2821 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2824 ipp_state_t
/* O - Current state */
2825 ippRead(http_t
*http
, /* I - HTTP connection */
2826 ipp_t
*ipp
) /* I - IPP data */
2828 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
, (void *)http
, (void *)ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2831 return (IPP_STATE_ERROR
);
2833 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
, http
->used
));
2835 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2841 * 'ippReadFile()' - Read data for an IPP message from a file.
2843 * @since CUPS 1.1.19/macOS 10.3@
2846 ipp_state_t
/* O - Current state */
2847 ippReadFile(int fd
, /* I - HTTP data */
2848 ipp_t
*ipp
) /* I - IPP data */
2850 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
2852 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2857 * 'ippReadIO()' - Read data for an IPP message.
2859 * @since CUPS 1.2/macOS 10.5@
2862 ipp_state_t
/* O - Current state */
2863 ippReadIO(void *src
, /* I - Data source */
2864 ipp_iocb_t cb
, /* I - Read callback function */
2865 int blocking
, /* I - Use blocking IO? */
2866 ipp_t
*parent
, /* I - Parent request, if any */
2867 ipp_t
*ipp
) /* I - IPP data */
2869 int n
; /* Length of data */
2870 unsigned char *buffer
, /* Data buffer */
2871 string
[IPP_MAX_TEXT
],
2872 /* Small string buffer */
2873 *bufptr
; /* Pointer into buffer */
2874 ipp_attribute_t
*attr
; /* Current attribute */
2875 ipp_tag_t tag
; /* Current tag */
2876 ipp_tag_t value_tag
; /* Current value tag */
2877 _ipp_value_t
*value
; /* Current value */
2880 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)src
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
2881 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_STATE_ERROR
));
2884 return (IPP_STATE_ERROR
);
2886 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2888 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2889 return (IPP_STATE_ERROR
);
2894 case IPP_STATE_IDLE
:
2895 ipp
->state
++; /* Avoid common problem... */
2897 case IPP_STATE_HEADER
:
2901 * Get the request header...
2904 if ((*cb
)(src
, buffer
, 8) < 8)
2906 DEBUG_puts("1ippReadIO: Unable to read header.");
2907 _cupsBufferRelease((char *)buffer
);
2908 return (IPP_STATE_ERROR
);
2912 * Then copy the request header over...
2915 ipp
->request
.any
.version
[0] = buffer
[0];
2916 ipp
->request
.any
.version
[1] = buffer
[1];
2917 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
2918 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
2919 buffer
[6]) << 8) | buffer
[7];
2921 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
2922 DEBUG_printf(("2ippReadIO: op_status=%04x",
2923 ipp
->request
.any
.op_status
));
2924 DEBUG_printf(("2ippReadIO: request_id=%d",
2925 ipp
->request
.any
.request_id
));
2928 ipp
->state
= IPP_STATE_ATTRIBUTE
;
2929 ipp
->current
= NULL
;
2930 ipp
->curtag
= IPP_TAG_ZERO
;
2931 ipp
->prev
= ipp
->last
;
2934 * If blocking is disabled, stop here...
2940 case IPP_STATE_ATTRIBUTE
:
2943 if ((*cb
)(src
, buffer
, 1) < 1)
2945 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
2946 _cupsBufferRelease((char *)buffer
);
2947 return (IPP_STATE_ERROR
);
2950 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
2953 * Read this attribute...
2956 tag
= (ipp_tag_t
)buffer
[0];
2957 if (tag
== IPP_TAG_EXTENSION
)
2960 * Read 32-bit "extension" tag...
2963 if ((*cb
)(src
, buffer
, 4) < 1)
2965 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
2966 _cupsBufferRelease((char *)buffer
);
2967 return (IPP_STATE_ERROR
);
2970 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
2971 buffer
[2]) << 8) | buffer
[3]);
2973 if (tag
& IPP_TAG_CUPS_CONST
)
2976 * Fail if the high bit is set in the tag...
2979 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
2980 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
2981 _cupsBufferRelease((char *)buffer
);
2982 return (IPP_STATE_ERROR
);
2986 if (tag
== IPP_TAG_END
)
2989 * No more attributes left...
2992 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
2994 ipp
->state
= IPP_STATE_DATA
;
2997 else if (tag
== IPP_TAG_ZERO
|| (tag
== IPP_TAG_OPERATION
&& ipp
->curtag
!= IPP_TAG_ZERO
))
2999 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Invalid group tag."), 1);
3000 DEBUG_printf(("1ippReadIO: bad tag 0x%02x.", tag
));
3001 _cupsBufferRelease((char *)buffer
);
3002 return (IPP_STATE_ERROR
);
3004 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3007 * Group tag... Set the current group and continue...
3010 if (ipp
->curtag
== tag
)
3011 ipp
->prev
= ippAddSeparator(ipp
);
3012 else if (ipp
->current
)
3013 ipp
->prev
= ipp
->current
;
3016 ipp
->current
= NULL
;
3017 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
, ippTagString(tag
), (void *)ipp
->prev
));
3021 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3022 ippTagString(tag
)));
3028 if ((*cb
)(src
, buffer
, 2) < 2)
3030 DEBUG_puts("1ippReadIO: unable to read name length.");
3031 _cupsBufferRelease((char *)buffer
);
3032 return (IPP_STATE_ERROR
);
3035 n
= (buffer
[0] << 8) | buffer
[1];
3037 if (n
>= IPP_BUF_SIZE
)
3039 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3040 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3041 _cupsBufferRelease((char *)buffer
);
3042 return (IPP_STATE_ERROR
);
3045 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3047 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3048 tag
!= IPP_TAG_END_COLLECTION
)
3051 * More values for current attribute...
3054 if (ipp
->current
== NULL
)
3056 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3057 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3058 _cupsBufferRelease((char *)buffer
);
3059 return (IPP_STATE_ERROR
);
3062 attr
= ipp
->current
;
3063 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3066 * Make sure we aren't adding a new value of a different
3070 if (value_tag
== IPP_TAG_ZERO
)
3073 * Setting the value of a collection member...
3076 attr
->value_tag
= tag
;
3078 else if (value_tag
== IPP_TAG_TEXTLANG
||
3079 value_tag
== IPP_TAG_NAMELANG
||
3080 (value_tag
>= IPP_TAG_TEXT
&&
3081 value_tag
<= IPP_TAG_MIMETYPE
))
3084 * String values can sometimes come across in different
3085 * forms; accept sets of differing values...
3088 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3089 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3090 tag
!= IPP_TAG_NOVALUE
)
3092 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3093 _("IPP 1setOf attribute with incompatible value "
3095 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3096 value_tag
, ippTagString(value_tag
), tag
,
3097 ippTagString(tag
)));
3098 _cupsBufferRelease((char *)buffer
);
3099 return (IPP_STATE_ERROR
);
3102 if (value_tag
!= tag
)
3104 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3105 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3106 ippSetValueTag(ipp
, &attr
, tag
);
3109 else if (value_tag
== IPP_TAG_INTEGER
||
3110 value_tag
== IPP_TAG_RANGE
)
3113 * Integer and rangeOfInteger values can sometimes be mixed; accept
3114 * sets of differing values...
3117 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3119 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3120 _("IPP 1setOf attribute with incompatible value "
3122 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3123 value_tag
, ippTagString(value_tag
), tag
,
3124 ippTagString(tag
)));
3125 _cupsBufferRelease((char *)buffer
);
3126 return (IPP_STATE_ERROR
);
3129 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3132 * Convert integer values to rangeOfInteger values...
3135 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3136 "rangeOfInteger.", attr
->name
));
3137 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3140 else if (value_tag
!= tag
)
3142 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3143 _("IPP 1setOf attribute with incompatible value "
3145 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3146 value_tag
, ippTagString(value_tag
), tag
,
3147 ippTagString(tag
)));
3148 _cupsBufferRelease((char *)buffer
);
3149 return (IPP_STATE_ERROR
);
3153 * Finally, reallocate the attribute array as needed...
3156 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3158 _cupsBufferRelease((char *)buffer
);
3159 return (IPP_STATE_ERROR
);
3162 else if (tag
== IPP_TAG_MEMBERNAME
)
3165 * Name must be length 0!
3170 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3171 DEBUG_puts("1ippReadIO: member name not empty.");
3172 _cupsBufferRelease((char *)buffer
);
3173 return (IPP_STATE_ERROR
);
3177 ipp
->prev
= ipp
->current
;
3179 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3182 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3183 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3184 _cupsBufferRelease((char *)buffer
);
3185 return (IPP_STATE_ERROR
);
3188 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3190 value
= attr
->values
;
3192 else if (tag
!= IPP_TAG_END_COLLECTION
)
3195 * New attribute; read the name and add it...
3198 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3200 DEBUG_puts("1ippReadIO: unable to read name.");
3201 _cupsBufferRelease((char *)buffer
);
3202 return (IPP_STATE_ERROR
);
3208 ipp
->prev
= ipp
->current
;
3210 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3213 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3214 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3215 _cupsBufferRelease((char *)buffer
);
3216 return (IPP_STATE_ERROR
);
3219 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer
, (void *)ipp
->current
, (void *)ipp
->prev
));
3221 value
= attr
->values
;
3229 if ((*cb
)(src
, buffer
, 2) < 2)
3231 DEBUG_puts("1ippReadIO: unable to read value length.");
3232 _cupsBufferRelease((char *)buffer
);
3233 return (IPP_STATE_ERROR
);
3236 n
= (buffer
[0] << 8) | buffer
[1];
3237 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3239 if (n
>= IPP_BUF_SIZE
)
3241 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3242 _("IPP value larger than 32767 bytes."), 1);
3243 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3244 _cupsBufferRelease((char *)buffer
);
3245 return (IPP_STATE_ERROR
);
3250 case IPP_TAG_INTEGER
:
3254 if (tag
== IPP_TAG_INTEGER
)
3255 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3256 _("IPP integer value not 4 bytes."), 1);
3258 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3259 _("IPP enum value not 4 bytes."), 1);
3260 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3261 _cupsBufferRelease((char *)buffer
);
3262 return (IPP_STATE_ERROR
);
3265 if ((*cb
)(src
, buffer
, 4) < 4)
3267 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3268 _cupsBufferRelease((char *)buffer
);
3269 return (IPP_STATE_ERROR
);
3272 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3275 if (attr
->value_tag
== IPP_TAG_RANGE
)
3276 value
->range
.lower
= value
->range
.upper
= n
;
3281 case IPP_TAG_BOOLEAN
:
3284 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3286 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3287 _cupsBufferRelease((char *)buffer
);
3288 return (IPP_STATE_ERROR
);
3291 if ((*cb
)(src
, buffer
, 1) < 1)
3293 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3294 _cupsBufferRelease((char *)buffer
);
3295 return (IPP_STATE_ERROR
);
3298 value
->boolean
= (char)buffer
[0];
3301 case IPP_TAG_UNSUPPORTED_VALUE
:
3302 case IPP_TAG_DEFAULT
:
3303 case IPP_TAG_UNKNOWN
:
3304 case IPP_TAG_NOVALUE
:
3305 case IPP_TAG_NOTSETTABLE
:
3306 case IPP_TAG_DELETEATTR
:
3307 case IPP_TAG_ADMINDEFINE
:
3309 * These value types are not supposed to have values, however
3310 * some vendors (Brother) do not implement IPP correctly and so
3311 * we need to map non-empty values to text...
3314 if (attr
->value_tag
== tag
)
3319 attr
->value_tag
= IPP_TAG_TEXT
;
3324 case IPP_TAG_RESERVED_STRING
:
3325 case IPP_TAG_KEYWORD
:
3327 case IPP_TAG_URISCHEME
:
3328 case IPP_TAG_CHARSET
:
3329 case IPP_TAG_LANGUAGE
:
3330 case IPP_TAG_MIMETYPE
:
3333 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3335 DEBUG_puts("1ippReadIO: unable to read string value.");
3336 _cupsBufferRelease((char *)buffer
);
3337 return (IPP_STATE_ERROR
);
3342 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3343 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3349 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3350 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3351 _cupsBufferRelease((char *)buffer
);
3352 return (IPP_STATE_ERROR
);
3355 if ((*cb
)(src
, value
->date
, 11) < 11)
3357 DEBUG_puts("1ippReadIO: Unable to read date value.");
3358 _cupsBufferRelease((char *)buffer
);
3359 return (IPP_STATE_ERROR
);
3363 case IPP_TAG_RESOLUTION
:
3366 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3367 _("IPP resolution value not 9 bytes."), 1);
3368 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3369 _cupsBufferRelease((char *)buffer
);
3370 return (IPP_STATE_ERROR
);
3373 if ((*cb
)(src
, buffer
, 9) < 9)
3375 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3376 _cupsBufferRelease((char *)buffer
);
3377 return (IPP_STATE_ERROR
);
3380 value
->resolution
.xres
=
3381 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3383 value
->resolution
.yres
=
3384 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3386 value
->resolution
.units
=
3387 (ipp_res_t
)buffer
[8];
3390 case IPP_TAG_RANGE
:
3393 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3394 _("IPP rangeOfInteger value not 8 bytes."), 1);
3395 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3397 _cupsBufferRelease((char *)buffer
);
3398 return (IPP_STATE_ERROR
);
3401 if ((*cb
)(src
, buffer
, 8) < 8)
3403 DEBUG_puts("1ippReadIO: Unable to read range value.");
3404 _cupsBufferRelease((char *)buffer
);
3405 return (IPP_STATE_ERROR
);
3408 value
->range
.lower
=
3409 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3411 value
->range
.upper
=
3412 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3416 case IPP_TAG_TEXTLANG
:
3417 case IPP_TAG_NAMELANG
:
3420 if (tag
== IPP_TAG_TEXTLANG
)
3421 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3422 _("IPP textWithLanguage value less than "
3423 "minimum 4 bytes."), 1);
3425 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3426 _("IPP nameWithLanguage value less than "
3427 "minimum 4 bytes."), 1);
3428 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3430 _cupsBufferRelease((char *)buffer
);
3431 return (IPP_STATE_ERROR
);
3434 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3436 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3438 _cupsBufferRelease((char *)buffer
);
3439 return (IPP_STATE_ERROR
);
3445 * text-with-language and name-with-language are composite
3454 n
= (bufptr
[0] << 8) | bufptr
[1];
3456 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) || n
>= (int)sizeof(string
))
3458 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3459 _("IPP language length overflows value."), 1);
3460 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3462 _cupsBufferRelease((char *)buffer
);
3463 return (IPP_STATE_ERROR
);
3465 else if (n
>= IPP_MAX_LANGUAGE
)
3467 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3468 _("IPP language length too large."), 1);
3469 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3471 _cupsBufferRelease((char *)buffer
);
3472 return (IPP_STATE_ERROR
);
3475 memcpy(string
, bufptr
+ 2, (size_t)n
);
3478 value
->string
.language
= _cupsStrAlloc((char *)string
);
3481 n
= (bufptr
[0] << 8) | bufptr
[1];
3483 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3485 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3486 _("IPP string length overflows value."), 1);
3487 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3488 _cupsBufferRelease((char *)buffer
);
3489 return (IPP_STATE_ERROR
);
3492 bufptr
[2 + n
] = '\0';
3493 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3496 case IPP_TAG_BEGIN_COLLECTION
:
3498 * Oh, boy, here comes a collection value, so read it...
3501 value
->collection
= ippNew();
3505 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3506 _("IPP begCollection value not 0 bytes."), 1);
3507 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3509 _cupsBufferRelease((char *)buffer
);
3510 return (IPP_STATE_ERROR
);
3513 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3515 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3516 _cupsBufferRelease((char *)buffer
);
3517 return (IPP_STATE_ERROR
);
3521 case IPP_TAG_END_COLLECTION
:
3522 _cupsBufferRelease((char *)buffer
);
3526 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3527 _("IPP endCollection value not 0 bytes."), 1);
3528 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3530 return (IPP_STATE_ERROR
);
3533 DEBUG_puts("1ippReadIO: endCollection tag...");
3534 return (ipp
->state
= IPP_STATE_DATA
);
3536 case IPP_TAG_MEMBERNAME
:
3538 * The value the name of the member in the collection, which
3539 * we need to carry over...
3544 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3545 _("IPP memberName with no attribute."), 1);
3546 DEBUG_puts("1ippReadIO: Member name without attribute.");
3547 _cupsBufferRelease((char *)buffer
);
3548 return (IPP_STATE_ERROR
);
3552 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3553 _("IPP memberName value is empty."), 1);
3554 DEBUG_puts("1ippReadIO: Empty member name value.");
3555 _cupsBufferRelease((char *)buffer
);
3556 return (IPP_STATE_ERROR
);
3558 else if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3560 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3561 _cupsBufferRelease((char *)buffer
);
3562 return (IPP_STATE_ERROR
);
3566 attr
->name
= _cupsStrAlloc((char *)buffer
);
3569 * Since collection members are encoded differently than
3570 * regular attributes, make sure we don't start with an
3574 attr
->num_values
--;
3576 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3579 default : /* Other unsupported values */
3580 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3582 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3583 _("IPP octetString length too large."), 1);
3584 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3586 _cupsBufferRelease((char *)buffer
);
3587 return (IPP_STATE_ERROR
);
3590 value
->unknown
.length
= n
;
3594 if ((value
->unknown
.data
= malloc((size_t)n
)) == NULL
)
3596 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3597 DEBUG_puts("1ippReadIO: Unable to allocate value");
3598 _cupsBufferRelease((char *)buffer
);
3599 return (IPP_STATE_ERROR
);
3602 if ((*cb
)(src
, value
->unknown
.data
, (size_t)n
) < n
)
3604 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3605 _cupsBufferRelease((char *)buffer
);
3606 return (IPP_STATE_ERROR
);
3610 value
->unknown
.data
= NULL
;
3615 * If blocking is disabled, stop here...
3623 case IPP_STATE_DATA
:
3627 break; /* anti-compiler-warning-code */
3630 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3631 _cupsBufferRelease((char *)buffer
);
3633 return (ipp
->state
);
3638 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3640 * The @code ipp@ parameter refers to an IPP message previously created using
3641 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3643 * The @code attr@ parameter may be modified as a result of setting the value.
3645 * The @code element@ parameter specifies which value to set from 0 to
3646 * @code ippGetCount(attr)@.
3648 * @since CUPS 1.6/macOS 10.8@
3651 int /* O - 1 on success, 0 on failure */
3652 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3653 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3654 int element
, /* I - Value number (0-based) */
3655 int boolvalue
)/* I - Boolean value */
3657 _ipp_value_t
*value
; /* Current value */
3661 * Range check input...
3664 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3665 element
< 0 || element
> (*attr
)->num_values
)
3669 * Set the value and return...
3672 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3673 value
->boolean
= (char)boolvalue
;
3675 return (value
!= NULL
);
3680 * 'ippSetCollection()' - Set a collection value in an attribute.
3682 * The @code ipp@ parameter refers to an IPP message previously created using
3683 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3685 * The @code attr@ parameter may be modified as a result of setting the value.
3687 * The @code element@ parameter specifies which value to set from 0 to
3688 * @code ippGetCount(attr)@.
3690 * @since CUPS 1.6/macOS 10.8@
3693 int /* O - 1 on success, 0 on failure */
3695 ipp_t
*ipp
, /* I - IPP message */
3696 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3697 int element
, /* I - Value number (0-based) */
3698 ipp_t
*colvalue
) /* I - Collection value */
3700 _ipp_value_t
*value
; /* Current value */
3704 * Range check input...
3707 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3708 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3712 * Set the value and return...
3715 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3717 if (value
->collection
)
3718 ippDelete(value
->collection
);
3720 value
->collection
= colvalue
;
3724 return (value
!= NULL
);
3729 * 'ippSetDate()' - Set a dateTime value in an attribute.
3731 * The @code ipp@ parameter refers to an IPP message previously created using
3732 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3734 * The @code attr@ parameter may be modified as a result of setting the value.
3736 * The @code element@ parameter specifies which value to set from 0 to
3737 * @code ippGetCount(attr)@.
3739 * @since CUPS 1.6/macOS 10.8@
3742 int /* O - 1 on success, 0 on failure */
3743 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3744 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3745 int element
, /* I - Value number (0-based) */
3746 const ipp_uchar_t
*datevalue
)/* I - dateTime value */
3748 _ipp_value_t
*value
; /* Current value */
3752 * Range check input...
3755 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3756 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3760 * Set the value and return...
3763 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3764 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3766 return (value
!= NULL
);
3771 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3773 * The @code ipp@ parameter refers to an IPP message previously created using
3774 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3776 * The @code attr@ parameter may be modified as a result of setting the value.
3778 * The @code group@ parameter specifies the IPP attribute group tag: none
3779 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3780 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3781 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3782 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3784 * @since CUPS 1.6/macOS 10.8@
3787 int /* O - 1 on success, 0 on failure */
3789 ipp_t
*ipp
, /* I - IPP message */
3790 ipp_attribute_t
**attr
, /* IO - Attribute */
3791 ipp_tag_t group_tag
) /* I - Group tag */
3794 * Range check input - group tag must be 0x01 to 0x0F, per RFC 8011...
3797 if (!ipp
|| !attr
|| !*attr
||
3798 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3799 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3803 * Set the group tag and return...
3806 (*attr
)->group_tag
= group_tag
;
3813 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3815 * The @code ipp@ parameter refers to an IPP message previously created using
3816 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3818 * The @code attr@ parameter may be modified as a result of setting the value.
3820 * The @code element@ parameter specifies which value to set from 0 to
3821 * @code ippGetCount(attr)@.
3823 * @since CUPS 1.6/macOS 10.8@
3826 int /* O - 1 on success, 0 on failure */
3827 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3828 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3829 int element
, /* I - Value number (0-based) */
3830 int intvalue
) /* I - Integer/enum value */
3832 _ipp_value_t
*value
; /* Current value */
3836 * Range check input...
3839 if (!ipp
|| !attr
|| !*attr
||
3840 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3841 element
< 0 || element
> (*attr
)->num_values
)
3845 * Set the value and return...
3848 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3849 value
->integer
= intvalue
;
3851 return (value
!= NULL
);
3856 * 'ippSetName()' - Set the name of an attribute.
3858 * The @code ipp@ parameter refers to an IPP message previously created using
3859 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3861 * The @code attr@ parameter may be modified as a result of setting the value.
3863 * @since CUPS 1.6/macOS 10.8@
3866 int /* O - 1 on success, 0 on failure */
3867 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3868 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3869 const char *name
) /* I - Attribute name */
3871 char *temp
; /* Temporary name value */
3875 * Range check input...
3878 if (!ipp
|| !attr
|| !*attr
)
3882 * Set the value and return...
3885 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3888 _cupsStrFree((*attr
)->name
);
3890 (*attr
)->name
= temp
;
3893 return (temp
!= NULL
);
3898 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
3900 * The @code ipp@ parameter refers to an IPP message previously created using
3901 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3903 * The @code attr@ parameter may be modified as a result of setting the value.
3905 * The @code element@ parameter specifies which value to set from 0 to
3906 * @code ippGetCount(attr)@.
3908 * @since CUPS 1.7/macOS 10.9@
3911 int /* O - 1 on success, 0 on failure */
3913 ipp_t
*ipp
, /* I - IPP message */
3914 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3915 int element
, /* I - Value number (0-based) */
3916 const void *data
, /* I - Pointer to octetString data */
3917 int datalen
) /* I - Length of octetString data */
3919 _ipp_value_t
*value
; /* Current value */
3923 * Range check input...
3926 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_STRING
||
3927 element
< 0 || element
> (*attr
)->num_values
||
3928 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
3932 * Set the value and return...
3935 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3937 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
3940 * Just copy the pointer...
3943 value
->unknown
.data
= (void *)data
;
3944 value
->unknown
.length
= datalen
;
3952 if (value
->unknown
.data
)
3955 * Free previous data...
3958 free(value
->unknown
.data
);
3960 value
->unknown
.data
= NULL
;
3961 value
->unknown
.length
= 0;
3966 void *temp
; /* Temporary data pointer */
3968 if ((temp
= malloc((size_t)datalen
)) != NULL
)
3970 memcpy(temp
, data
, (size_t)datalen
);
3972 value
->unknown
.data
= temp
;
3973 value
->unknown
.length
= datalen
;
3981 return (value
!= NULL
);
3986 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
3988 * The @code ipp@ parameter refers to an IPP message previously created using
3989 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3991 * @since CUPS 1.6/macOS 10.8@
3994 int /* O - 1 on success, 0 on failure */
3995 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
3996 ipp_op_t op
) /* I - Operation ID */
3999 * Range check input...
4006 * Set the operation and return...
4009 ipp
->request
.op
.operation_id
= op
;
4016 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4018 * The @code ipp@ parameter refers to an IPP message previously created using
4019 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4021 * The @code attr@ parameter may be modified as a result of setting the value.
4023 * The @code element@ parameter specifies which value to set from 0 to
4024 * @code ippGetCount(attr)@.
4026 * @since CUPS 1.6/macOS 10.8@
4029 int /* O - 1 on success, 0 on failure */
4030 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4031 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4032 int element
, /* I - Value number (0-based) */
4033 int lowervalue
, /* I - Lower bound for range */
4034 int uppervalue
) /* I - Upper bound for range */
4036 _ipp_value_t
*value
; /* Current value */
4040 * Range check input...
4043 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4044 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4048 * Set the value and return...
4051 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4053 value
->range
.lower
= lowervalue
;
4054 value
->range
.upper
= uppervalue
;
4057 return (value
!= NULL
);
4062 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4064 * The @code ipp@ parameter refers to an IPP message previously created using
4065 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4067 * The @code request_id@ parameter must be greater than 0.
4069 * @since CUPS 1.6/macOS 10.8@
4072 int /* O - 1 on success, 0 on failure */
4073 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4074 int request_id
) /* I - Request ID */
4077 * Range check input; not checking request_id values since ipptool wants to send
4078 * invalid values for conformance testing and a bad request_id does not affect the
4079 * encoding of a message...
4086 * Set the request ID and return...
4089 ipp
->request
.any
.request_id
= request_id
;
4096 * 'ippSetResolution()' - Set a resolution value in an attribute.
4098 * The @code ipp@ parameter refers to an IPP message previously created using
4099 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4101 * The @code attr@ parameter may be modified as a result of setting the value.
4103 * The @code element@ parameter specifies which value to set from 0 to
4104 * @code ippGetCount(attr)@.
4106 * @since CUPS 1.6/macOS 10.8@
4109 int /* O - 1 on success, 0 on failure */
4111 ipp_t
*ipp
, /* I - IPP message */
4112 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4113 int element
, /* I - Value number (0-based) */
4114 ipp_res_t unitsvalue
, /* I - Resolution units */
4115 int xresvalue
, /* I - Horizontal/cross feed resolution */
4116 int yresvalue
) /* I - Vertical/feed resolution */
4118 _ipp_value_t
*value
; /* Current value */
4122 * Range check input...
4125 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4126 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4127 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4131 * Set the value and return...
4134 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4136 value
->resolution
.units
= unitsvalue
;
4137 value
->resolution
.xres
= xresvalue
;
4138 value
->resolution
.yres
= yresvalue
;
4141 return (value
!= NULL
);
4146 * 'ippSetState()' - Set the current state of the IPP message.
4148 * @since CUPS 1.6/macOS 10.8@
4151 int /* O - 1 on success, 0 on failure */
4152 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4153 ipp_state_t state
) /* I - IPP state value */
4156 * Range check input...
4163 * Set the state and return...
4167 ipp
->current
= NULL
;
4174 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4176 * The @code ipp@ parameter refers to an IPP message previously created using
4177 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4179 * @since CUPS 1.6/macOS 10.8@
4182 int /* O - 1 on success, 0 on failure */
4183 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4184 ipp_status_t status
) /* I - Status code */
4187 * Range check input...
4194 * Set the status code and return...
4197 ipp
->request
.status
.status_code
= status
;
4204 * 'ippSetString()' - Set a string value in an attribute.
4206 * The @code ipp@ parameter refers to an IPP message previously created using
4207 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4209 * The @code attr@ parameter may be modified as a result of setting the value.
4211 * The @code element@ parameter specifies which value to set from 0 to
4212 * @code ippGetCount(attr)@.
4214 * @since CUPS 1.6/macOS 10.8@
4217 int /* O - 1 on success, 0 on failure */
4218 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4219 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4220 int element
, /* I - Value number (0-based) */
4221 const char *strvalue
) /* I - String value */
4223 char *temp
; /* Temporary string */
4224 _ipp_value_t
*value
; /* Current value */
4225 ipp_tag_t value_tag
; /* Value tag */
4229 * Range check input...
4233 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4235 value_tag
= IPP_TAG_ZERO
;
4237 if (!ipp
|| !attr
|| !*attr
||
4238 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4239 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4240 element
< 0 || element
> (*attr
)->num_values
|| !strvalue
)
4244 * Set the value and return...
4247 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4250 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4252 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4253 value
->string
.text
= (char *)strvalue
;
4254 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4256 if (value
->string
.text
)
4257 _cupsStrFree(value
->string
.text
);
4259 value
->string
.text
= temp
;
4265 return (value
!= NULL
);
4270 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4272 * The @code ipp@ parameter refers to an IPP message previously created using
4273 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4275 * The @code attr@ parameter may be modified as a result of setting the value.
4277 * The @code element@ parameter specifies which value to set from 0 to
4278 * @code ippGetCount(attr)@.
4280 * The @code format@ parameter uses formatting characters compatible with the
4281 * printf family of standard functions. Additional arguments follow it as
4282 * needed. The formatted string is truncated as needed to the maximum length of
4283 * the corresponding value type.
4285 * @since CUPS 1.7/macOS 10.9@
4288 int /* O - 1 on success, 0 on failure */
4289 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4290 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4291 int element
, /* I - Value number (0-based) */
4292 const char *format
, /* I - Printf-style format string */
4293 ...) /* I - Additional arguments as needed */
4295 int ret
; /* Return value */
4296 va_list ap
; /* Pointer to additional arguments */
4299 va_start(ap
, format
);
4300 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4308 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4310 * The @code ipp@ parameter refers to an IPP message previously created using
4311 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4313 * The @code attr@ parameter may be modified as a result of setting the value.
4315 * The @code element@ parameter specifies which value to set from 0 to
4316 * @code ippGetCount(attr)@.
4318 * The @code format@ parameter uses formatting characters compatible with the
4319 * printf family of standard functions. Additional arguments follow it as
4320 * needed. The formatted string is truncated as needed to the maximum length of
4321 * the corresponding value type.
4323 * @since CUPS 1.7/macOS 10.9@
4326 int /* O - 1 on success, 0 on failure */
4327 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4328 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4329 int element
, /* I - Value number (0-based) */
4330 const char *format
, /* I - Printf-style format string */
4331 va_list ap
) /* I - Pointer to additional arguments */
4333 ipp_tag_t value_tag
; /* Value tag */
4334 char buffer
[IPP_MAX_TEXT
+ 4];
4335 /* Formatted text string */
4336 ssize_t bytes
, /* Length of formatted value */
4337 max_bytes
; /* Maximum number of bytes for value */
4341 * Range check input...
4345 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4347 value_tag
= IPP_TAG_ZERO
;
4349 if (!ipp
|| !attr
|| !*attr
||
4350 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4351 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4356 * Format the string...
4359 if (!strcmp(format
, "%s"))
4362 * Optimize the simple case...
4365 const char *s
= va_arg(ap
, char *);
4370 bytes
= (ssize_t
)strlen(s
);
4371 strlcpy(buffer
, s
, sizeof(buffer
));
4376 * Do a full formatting of the message...
4379 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4384 * Limit the length of the string...
4391 case IPP_TAG_TEXTLANG
:
4392 max_bytes
= IPP_MAX_TEXT
;
4396 case IPP_TAG_NAMELANG
:
4397 max_bytes
= IPP_MAX_NAME
;
4400 case IPP_TAG_CHARSET
:
4401 max_bytes
= IPP_MAX_CHARSET
;
4404 case IPP_TAG_KEYWORD
:
4405 max_bytes
= IPP_MAX_KEYWORD
;
4408 case IPP_TAG_LANGUAGE
:
4409 max_bytes
= IPP_MAX_LANGUAGE
;
4412 case IPP_TAG_MIMETYPE
:
4413 max_bytes
= IPP_MAX_MIMETYPE
;
4417 max_bytes
= IPP_MAX_URI
;
4420 case IPP_TAG_URISCHEME
:
4421 max_bytes
= IPP_MAX_URISCHEME
;
4425 if (bytes
>= max_bytes
)
4427 char *bufmax
, /* Buffer at max_bytes */
4428 *bufptr
; /* Pointer into buffer */
4430 bufptr
= buffer
+ strlen(buffer
) - 1;
4431 bufmax
= buffer
+ max_bytes
- 1;
4433 while (bufptr
> bufmax
)
4437 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4448 * Set the formatted string and return...
4451 return (ippSetString(ipp
, attr
, element
, buffer
));
4456 * 'ippSetValueTag()' - Set the value tag of an attribute.
4458 * The @code ipp@ parameter refers to an IPP message previously created using
4459 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4461 * The @code attr@ parameter may be modified as a result of setting the value.
4463 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4464 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4465 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4466 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4467 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4468 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4471 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4472 * code in the "attributes-natural-language" attribute or, if not present, the language
4473 * code for the current locale.
4475 * @since CUPS 1.6/macOS 10.8@
4478 int /* O - 1 on success, 0 on failure */
4480 ipp_t
*ipp
, /* I - IPP message */
4481 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4482 ipp_tag_t value_tag
) /* I - Value tag */
4484 int i
; /* Looping var */
4485 _ipp_value_t
*value
; /* Current value */
4486 int integer
; /* Current integer value */
4487 cups_lang_t
*language
; /* Current language */
4488 char code
[32]; /* Language code */
4489 ipp_tag_t temp_tag
; /* Temporary value tag */
4493 * Range check input...
4496 if (!ipp
|| !attr
|| !*attr
)
4500 * If there is no change, return immediately...
4503 if (value_tag
== (*attr
)->value_tag
)
4507 * Otherwise implement changes as needed...
4510 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4514 case IPP_TAG_UNSUPPORTED_VALUE
:
4515 case IPP_TAG_DEFAULT
:
4516 case IPP_TAG_UNKNOWN
:
4517 case IPP_TAG_NOVALUE
:
4518 case IPP_TAG_NOTSETTABLE
:
4519 case IPP_TAG_DELETEATTR
:
4520 case IPP_TAG_ADMINDEFINE
:
4522 * Free any existing values...
4525 if ((*attr
)->num_values
> 0)
4526 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4529 * Set out-of-band value...
4532 (*attr
)->value_tag
= value_tag
;
4535 case IPP_TAG_RANGE
:
4536 if (temp_tag
!= IPP_TAG_INTEGER
)
4539 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4543 integer
= value
->integer
;
4544 value
->range
.lower
= value
->range
.upper
= integer
;
4547 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4551 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4552 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4553 temp_tag
!= IPP_TAG_MIMETYPE
)
4556 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4559 case IPP_TAG_NAMELANG
:
4560 case IPP_TAG_TEXTLANG
:
4561 if (value_tag
== IPP_TAG_NAMELANG
&&
4562 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4563 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4564 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4567 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4570 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4571 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4574 * Use the language code from the IPP message...
4577 (*attr
)->values
[0].string
.language
=
4578 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4583 * Otherwise, use the language code corresponding to the locale...
4586 language
= cupsLangDefault();
4587 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4592 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4595 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4597 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4600 * Make copies of all values...
4603 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4606 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4609 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4612 case IPP_TAG_KEYWORD
:
4613 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4614 break; /* Silently "allow" name -> keyword */
4625 * 'ippSetVersion()' - Set the version number in an IPP message.
4627 * The @code ipp@ parameter refers to an IPP message previously created using
4628 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4630 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4632 * @since CUPS 1.6/macOS 10.8@
4635 int /* O - 1 on success, 0 on failure */
4636 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4637 int major
, /* I - Major version number (major.minor) */
4638 int minor
) /* I - Minor version number (major.minor) */
4641 * Range check input...
4644 if (!ipp
|| major
< 0 || minor
< 0)
4648 * Set the version number...
4651 ipp
->request
.any
.version
[0] = (ipp_uchar_t
)major
;
4652 ipp
->request
.any
.version
[1] = (ipp_uchar_t
)minor
;
4659 * 'ippTimeToDate()' - Convert from time in seconds to RFC 2579 format.
4662 const ipp_uchar_t
* /* O - RFC-2579 date/time data */
4663 ippTimeToDate(time_t t
) /* I - Time in seconds */
4665 struct tm
*unixdate
; /* UNIX unixdate/time info */
4666 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4667 /* RFC-2579 date/time data */
4671 * RFC-2579 date/time format is:
4673 * Byte(s) Description
4674 * ------- -----------
4675 * 0-1 Year (0 to 65535)
4679 * 5 Minutes (0 to 59)
4680 * 6 Seconds (0 to 60, 60 = "leap second")
4681 * 7 Deciseconds (0 to 9)
4683 * 9 UTC hours (0 to 11)
4684 * 10 UTC minutes (0 to 59)
4687 unixdate
= gmtime(&t
);
4688 unixdate
->tm_year
+= 1900;
4690 date
[0] = (ipp_uchar_t
)(unixdate
->tm_year
>> 8);
4691 date
[1] = (ipp_uchar_t
)(unixdate
->tm_year
);
4692 date
[2] = (ipp_uchar_t
)(unixdate
->tm_mon
+ 1);
4693 date
[3] = (ipp_uchar_t
)unixdate
->tm_mday
;
4694 date
[4] = (ipp_uchar_t
)unixdate
->tm_hour
;
4695 date
[5] = (ipp_uchar_t
)unixdate
->tm_min
;
4696 date
[6] = (ipp_uchar_t
)unixdate
->tm_sec
;
4707 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4709 * This function validates the contents of an attribute based on the name and
4710 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4711 * failure, @link cupsLastErrorString@ is set to a human-readable message.
4713 * @since CUPS 1.7/macOS 10.9@
4716 int /* O - 1 if valid, 0 otherwise */
4717 ippValidateAttribute(
4718 ipp_attribute_t
*attr
) /* I - Attribute */
4720 int i
; /* Looping var */
4721 char scheme
[64], /* Scheme from URI */
4722 userpass
[256], /* Username/password from URI */
4723 hostname
[256], /* Hostname from URI */
4724 resource
[1024]; /* Resource from URI */
4725 int port
, /* Port number from URI */
4726 uri_status
; /* URI separation status */
4727 const char *ptr
; /* Pointer into string */
4728 ipp_attribute_t
*colattr
; /* Collection attribute */
4729 regex_t re
; /* Regular expression */
4730 ipp_uchar_t
*date
; /* Current date value */
4741 * Validate the attribute name.
4744 for (ptr
= attr
->name
; *ptr
; ptr
++)
4745 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4748 if (*ptr
|| ptr
== attr
->name
)
4750 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4751 _("\"%s\": Bad attribute name - invalid character "
4752 "(RFC 8011 section 5.1.4)."), attr
->name
);
4756 if ((ptr
- attr
->name
) > 255)
4758 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4759 _("\"%s\": Bad attribute name - bad length %d "
4760 "(RFC 8011 section 5.1.4)."), attr
->name
,
4761 (int)(ptr
- attr
->name
));
4765 switch (attr
->value_tag
)
4767 case IPP_TAG_INTEGER
:
4770 case IPP_TAG_BOOLEAN
:
4771 for (i
= 0; i
< attr
->num_values
; i
++)
4773 if (attr
->values
[i
].boolean
!= 0 &&
4774 attr
->values
[i
].boolean
!= 1)
4776 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4777 _("\"%s\": Bad boolen value %d "
4778 "(RFC 8011 section 5.1.21)."), attr
->name
,
4779 attr
->values
[i
].boolean
);
4786 for (i
= 0; i
< attr
->num_values
; i
++)
4788 if (attr
->values
[i
].integer
< 1)
4790 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4791 _("\"%s\": Bad enum value %d - out of range "
4792 "(RFC 8011 section 5.1.5)."), attr
->name
,
4793 attr
->values
[i
].integer
);
4799 case IPP_TAG_STRING
:
4800 for (i
= 0; i
< attr
->num_values
; i
++)
4802 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4804 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4805 _("\"%s\": Bad octetString value - bad length %d "
4806 "(RFC 8011 section 5.1.20)."), attr
->name
,
4807 attr
->values
[i
].unknown
.length
);
4814 for (i
= 0; i
< attr
->num_values
; i
++)
4816 date
= attr
->values
[i
].date
;
4818 if (date
[2] < 1 || date
[2] > 12)
4820 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4821 _("\"%s\": Bad dateTime month %u "
4822 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[2]);
4826 if (date
[3] < 1 || date
[3] > 31)
4828 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4829 _("\"%s\": Bad dateTime day %u "
4830 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[3]);
4836 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4837 _("\"%s\": Bad dateTime hours %u "
4838 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[4]);
4844 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4845 _("\"%s\": Bad dateTime minutes %u "
4846 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[5]);
4852 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4853 _("\"%s\": Bad dateTime seconds %u "
4854 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[6]);
4860 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4861 _("\"%s\": Bad dateTime deciseconds %u "
4862 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[7]);
4866 if (date
[8] != '-' && date
[8] != '+')
4868 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4869 _("\"%s\": Bad dateTime UTC sign '%c' "
4870 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[8]);
4876 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4877 _("\"%s\": Bad dateTime UTC hours %u "
4878 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[9]);
4884 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4885 _("\"%s\": Bad dateTime UTC minutes %u "
4886 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[10]);
4892 case IPP_TAG_RESOLUTION
:
4893 for (i
= 0; i
< attr
->num_values
; i
++)
4895 if (attr
->values
[i
].resolution
.xres
<= 0)
4897 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4898 _("\"%s\": Bad resolution value %dx%d%s - cross "
4899 "feed resolution must be positive "
4900 "(RFC 8011 section 5.1.16)."), attr
->name
,
4901 attr
->values
[i
].resolution
.xres
,
4902 attr
->values
[i
].resolution
.yres
,
4903 attr
->values
[i
].resolution
.units
==
4904 IPP_RES_PER_INCH
? "dpi" :
4905 attr
->values
[i
].resolution
.units
==
4906 IPP_RES_PER_CM
? "dpcm" : "unknown");
4910 if (attr
->values
[i
].resolution
.yres
<= 0)
4912 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4913 _("\"%s\": Bad resolution value %dx%d%s - feed "
4914 "resolution must be positive "
4915 "(RFC 8011 section 5.1.16)."), attr
->name
,
4916 attr
->values
[i
].resolution
.xres
,
4917 attr
->values
[i
].resolution
.yres
,
4918 attr
->values
[i
].resolution
.units
==
4919 IPP_RES_PER_INCH
? "dpi" :
4920 attr
->values
[i
].resolution
.units
==
4921 IPP_RES_PER_CM
? "dpcm" : "unknown");
4925 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
4926 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
4928 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4929 _("\"%s\": Bad resolution value %dx%d%s - bad "
4930 "units value (RFC 8011 section 5.1.16)."),
4931 attr
->name
, attr
->values
[i
].resolution
.xres
,
4932 attr
->values
[i
].resolution
.yres
,
4933 attr
->values
[i
].resolution
.units
==
4934 IPP_RES_PER_INCH
? "dpi" :
4935 attr
->values
[i
].resolution
.units
==
4936 IPP_RES_PER_CM
? "dpcm" : "unknown");
4942 case IPP_TAG_RANGE
:
4943 for (i
= 0; i
< attr
->num_values
; i
++)
4945 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
4947 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4948 _("\"%s\": Bad rangeOfInteger value %d-%d - lower "
4949 "greater than upper (RFC 8011 section 5.1.14)."),
4950 attr
->name
, attr
->values
[i
].range
.lower
,
4951 attr
->values
[i
].range
.upper
);
4957 case IPP_TAG_BEGIN_COLLECTION
:
4958 for (i
= 0; i
< attr
->num_values
; i
++)
4960 for (colattr
= attr
->values
[i
].collection
->attrs
;
4962 colattr
= colattr
->next
)
4964 if (!ippValidateAttribute(colattr
))
4971 case IPP_TAG_TEXTLANG
:
4972 for (i
= 0; i
< attr
->num_values
; i
++)
4974 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
4976 if ((*ptr
& 0xe0) == 0xc0)
4979 if ((*ptr
& 0xc0) != 0x80)
4982 else if ((*ptr
& 0xf0) == 0xe0)
4985 if ((*ptr
& 0xc0) != 0x80)
4988 if ((*ptr
& 0xc0) != 0x80)
4991 else if ((*ptr
& 0xf8) == 0xf0)
4994 if ((*ptr
& 0xc0) != 0x80)
4997 if ((*ptr
& 0xc0) != 0x80)
5000 if ((*ptr
& 0xc0) != 0x80)
5003 else if (*ptr
& 0x80)
5005 else if ((*ptr
< ' ' && *ptr
!= '\n' && *ptr
!= '\r' && *ptr
!= '\t') || *ptr
== 0x7f)
5011 if (*ptr
< ' ' || *ptr
== 0x7f)
5013 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad text value \"%s\" - bad control character (PWG 5100.14 section 8.3)."), attr
->name
, attr
->values
[i
].string
.text
);
5018 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad text value \"%s\" - bad UTF-8 sequence (RFC 8011 section 5.1.2)."), attr
->name
, attr
->values
[i
].string
.text
);
5023 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5025 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5026 _("\"%s\": Bad text value \"%s\" - bad length %d "
5027 "(RFC 8011 section 5.1.2)."), attr
->name
,
5028 attr
->values
[i
].string
.text
,
5029 (int)(ptr
- attr
->values
[i
].string
.text
));
5036 case IPP_TAG_NAMELANG
:
5037 for (i
= 0; i
< attr
->num_values
; i
++)
5039 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5041 if ((*ptr
& 0xe0) == 0xc0)
5044 if ((*ptr
& 0xc0) != 0x80)
5047 else if ((*ptr
& 0xf0) == 0xe0)
5050 if ((*ptr
& 0xc0) != 0x80)
5053 if ((*ptr
& 0xc0) != 0x80)
5056 else if ((*ptr
& 0xf8) == 0xf0)
5059 if ((*ptr
& 0xc0) != 0x80)
5062 if ((*ptr
& 0xc0) != 0x80)
5065 if ((*ptr
& 0xc0) != 0x80)
5068 else if (*ptr
& 0x80)
5070 else if (*ptr
< ' ' || *ptr
== 0x7f)
5076 if (*ptr
< ' ' || *ptr
== 0x7f)
5078 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad name value \"%s\" - bad control character (PWG 5100.14 section 8.1)."), attr
->name
, attr
->values
[i
].string
.text
);
5083 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad name value \"%s\" - bad UTF-8 sequence (RFC 8011 section 5.1.3)."), attr
->name
, attr
->values
[i
].string
.text
);
5088 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5090 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5091 _("\"%s\": Bad name value \"%s\" - bad length %d "
5092 "(RFC 8011 section 5.1.3)."), attr
->name
,
5093 attr
->values
[i
].string
.text
,
5094 (int)(ptr
- attr
->values
[i
].string
.text
));
5100 case IPP_TAG_KEYWORD
:
5101 for (i
= 0; i
< attr
->num_values
; i
++)
5103 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5104 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5108 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5110 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5111 _("\"%s\": Bad keyword value \"%s\" - invalid "
5112 "character (RFC 8011 section 5.1.4)."),
5113 attr
->name
, attr
->values
[i
].string
.text
);
5117 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5119 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5120 _("\"%s\": Bad keyword value \"%s\" - bad "
5121 "length %d (RFC 8011 section 5.1.4)."),
5122 attr
->name
, attr
->values
[i
].string
.text
,
5123 (int)(ptr
- attr
->values
[i
].string
.text
));
5130 for (i
= 0; i
< attr
->num_values
; i
++)
5132 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5133 attr
->values
[i
].string
.text
,
5134 scheme
, sizeof(scheme
),
5135 userpass
, sizeof(userpass
),
5136 hostname
, sizeof(hostname
),
5137 &port
, resource
, sizeof(resource
));
5139 if (uri_status
< HTTP_URI_STATUS_OK
)
5141 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad URI value \"%s\" - %s (RFC 8011 section 5.1.6)."), attr
->name
, attr
->values
[i
].string
.text
, httpURIStatusString(uri_status
));
5145 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5147 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5148 _("\"%s\": Bad URI value \"%s\" - bad length %d "
5149 "(RFC 8011 section 5.1.6)."), attr
->name
,
5150 attr
->values
[i
].string
.text
,
5151 (int)strlen(attr
->values
[i
].string
.text
));
5156 case IPP_TAG_URISCHEME
:
5157 for (i
= 0; i
< attr
->num_values
; i
++)
5159 ptr
= attr
->values
[i
].string
.text
;
5160 if (islower(*ptr
& 255))
5162 for (ptr
++; *ptr
; ptr
++)
5163 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5164 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5168 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5170 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5171 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5172 "characters (RFC 8011 section 5.1.7)."),
5173 attr
->name
, attr
->values
[i
].string
.text
);
5177 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5179 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5180 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5181 "length %d (RFC 8011 section 5.1.7)."),
5182 attr
->name
, attr
->values
[i
].string
.text
,
5183 (int)(ptr
- attr
->values
[i
].string
.text
));
5189 case IPP_TAG_CHARSET
:
5190 for (i
= 0; i
< attr
->num_values
; i
++)
5192 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5193 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5194 isspace(*ptr
& 255))
5197 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5199 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5200 _("\"%s\": Bad charset value \"%s\" - bad "
5201 "characters (RFC 8011 section 5.1.8)."),
5202 attr
->name
, attr
->values
[i
].string
.text
);
5206 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5208 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5209 _("\"%s\": Bad charset value \"%s\" - bad "
5210 "length %d (RFC 8011 section 5.1.8)."),
5211 attr
->name
, attr
->values
[i
].string
.text
,
5212 (int)(ptr
- attr
->values
[i
].string
.text
));
5218 case IPP_TAG_LANGUAGE
:
5220 * The following regular expression is derived from the ABNF for
5221 * language tags in RFC 4646. All I can say is that this is the
5222 * easiest way to check the values...
5225 if ((i
= regcomp(&re
,
5227 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5229 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5230 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5231 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5232 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5233 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5235 "x(-[a-z0-9]{1,8})+" /* privateuse */
5237 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5239 REG_NOSUB
| REG_EXTENDED
)) != 0)
5241 char temp
[256]; /* Temporary error string */
5243 regerror(i
, &re
, temp
, sizeof(temp
));
5244 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
,
5245 _("Unable to compile naturalLanguage regular "
5246 "expression: %s."), temp
);
5250 for (i
= 0; i
< attr
->num_values
; i
++)
5252 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5254 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5255 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5256 "characters (RFC 8011 section 5.1.9)."),
5257 attr
->name
, attr
->values
[i
].string
.text
);
5262 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5264 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5265 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5266 "length %d (RFC 8011 section 5.1.9)."),
5267 attr
->name
, attr
->values
[i
].string
.text
,
5268 (int)strlen(attr
->values
[i
].string
.text
));
5277 case IPP_TAG_MIMETYPE
:
5279 * The following regular expression is derived from the ABNF for
5280 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5281 * the easiest way to check the values...
5284 if ((i
= regcomp(&re
,
5286 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5288 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5289 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5290 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5293 REG_NOSUB
| REG_EXTENDED
)) != 0)
5295 char temp
[256]; /* Temporary error string */
5297 regerror(i
, &re
, temp
, sizeof(temp
));
5298 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5299 _("Unable to compile mimeMediaType regular "
5300 "expression: %s."), temp
);
5304 for (i
= 0; i
< attr
->num_values
; i
++)
5306 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5308 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5309 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5310 "characters (RFC 8011 section 5.1.10)."),
5311 attr
->name
, attr
->values
[i
].string
.text
);
5316 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5318 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5319 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5320 "length %d (RFC 8011 section 5.1.10)."),
5321 attr
->name
, attr
->values
[i
].string
.text
,
5322 (int)strlen(attr
->values
[i
].string
.text
));
5340 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5342 * This function validates the contents of the IPP message, including each
5343 * attribute. Like @link ippValidateAttribute@, @link cupsLastErrorString@ is
5344 * set to a human-readable message on failure.
5346 * @since CUPS 1.7/macOS 10.9@
5349 int /* O - 1 if valid, 0 otherwise */
5350 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5352 ipp_attribute_t
*attr
; /* Current attribute */
5358 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5359 if (!ippValidateAttribute(attr
))
5367 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5370 ipp_state_t
/* O - Current state */
5371 ippWrite(http_t
*http
, /* I - HTTP connection */
5372 ipp_t
*ipp
) /* I - IPP data */
5374 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http
, (void *)ipp
));
5377 return (IPP_STATE_ERROR
);
5379 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5384 * 'ippWriteFile()' - Write data for an IPP message to a file.
5386 * @since CUPS 1.1.19/macOS 10.3@
5389 ipp_state_t
/* O - Current state */
5390 ippWriteFile(int fd
, /* I - HTTP data */
5391 ipp_t
*ipp
) /* I - IPP data */
5393 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
5395 ipp
->state
= IPP_STATE_IDLE
;
5397 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5402 * 'ippWriteIO()' - Write data for an IPP message.
5404 * @since CUPS 1.2/macOS 10.5@
5407 ipp_state_t
/* O - Current state */
5408 ippWriteIO(void *dst
, /* I - Destination */
5409 ipp_iocb_t cb
, /* I - Write callback function */
5410 int blocking
, /* I - Use blocking IO? */
5411 ipp_t
*parent
, /* I - Parent IPP message */
5412 ipp_t
*ipp
) /* I - IPP data */
5414 int i
; /* Looping var */
5415 int n
; /* Length of data */
5416 unsigned char *buffer
, /* Data buffer */
5417 *bufptr
; /* Pointer into buffer */
5418 ipp_attribute_t
*attr
; /* Current attribute */
5419 _ipp_value_t
*value
; /* Current value */
5422 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
5425 return (IPP_STATE_ERROR
);
5427 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5429 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5430 return (IPP_STATE_ERROR
);
5435 case IPP_STATE_IDLE
:
5436 ipp
->state
++; /* Avoid common problem... */
5438 case IPP_STATE_HEADER
:
5442 * Send the request header:
5445 * Operation/Status Code = 2 bytes
5446 * Request ID = 4 bytes
5452 *bufptr
++ = ipp
->request
.any
.version
[0];
5453 *bufptr
++ = ipp
->request
.any
.version
[1];
5454 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.op_status
>> 8);
5455 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.op_status
;
5456 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 24);
5457 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 16);
5458 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 8);
5459 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.request_id
;
5461 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5462 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5463 ipp
->request
.any
.op_status
));
5464 DEBUG_printf(("2ippWriteIO: request_id=%d",
5465 ipp
->request
.any
.request_id
));
5467 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5469 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5470 _cupsBufferRelease((char *)buffer
);
5471 return (IPP_STATE_ERROR
);
5476 * Reset the state engine to point to the first attribute
5477 * in the request/response, with no current group.
5480 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5481 ipp
->current
= ipp
->attrs
;
5482 ipp
->curtag
= IPP_TAG_ZERO
;
5484 DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp
->current
));
5487 * If blocking is disabled, stop here...
5493 case IPP_STATE_ATTRIBUTE
:
5494 while (ipp
->current
!= NULL
)
5497 * Write this attribute...
5501 attr
= ipp
->current
;
5503 ipp
->current
= ipp
->current
->next
;
5507 if (ipp
->curtag
!= attr
->group_tag
)
5510 * Send a group tag byte...
5513 ipp
->curtag
= attr
->group_tag
;
5515 if (attr
->group_tag
== IPP_TAG_ZERO
)
5518 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5519 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5520 *bufptr
++ = (ipp_uchar_t
)attr
->group_tag
;
5522 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5526 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5527 attr
->num_values
> 1 ? "1setOf " : "",
5528 ippTagString(attr
->value_tag
)));
5531 * Write the attribute tag and name.
5533 * The attribute name length does not include the trailing nul
5534 * character in the source string.
5536 * Collection values (parent != NULL) are written differently...
5542 * Get the length of the attribute name, and make sure it won't
5543 * overflow the buffer...
5546 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5548 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5549 _cupsBufferRelease((char *)buffer
);
5550 return (IPP_STATE_ERROR
);
5554 * Write the value tag, name length, and name string...
5557 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5558 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5559 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5562 if (attr
->value_tag
> 0xff)
5564 *bufptr
++ = IPP_TAG_EXTENSION
;
5565 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5566 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5567 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5568 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5571 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5573 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5574 *bufptr
++ = (ipp_uchar_t
)n
;
5575 memcpy(bufptr
, attr
->name
, (size_t)n
);
5581 * Get the length of the attribute name, and make sure it won't
5582 * overflow the buffer...
5585 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5587 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5588 _cupsBufferRelease((char *)buffer
);
5589 return (IPP_STATE_ERROR
);
5593 * Write the member name tag, name length, name string, value tag,
5594 * and empty name for the collection member attribute...
5597 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5598 IPP_TAG_MEMBERNAME
));
5599 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5601 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5602 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5603 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5605 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5608 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5609 *bufptr
++ = (ipp_uchar_t
)n
;
5610 memcpy(bufptr
, attr
->name
, (size_t)n
);
5613 if (attr
->value_tag
> 0xff)
5615 *bufptr
++ = IPP_TAG_EXTENSION
;
5616 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5617 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5618 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5619 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5622 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5629 * Now write the attribute value(s)...
5632 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5634 case IPP_TAG_UNSUPPORTED_VALUE
:
5635 case IPP_TAG_DEFAULT
:
5636 case IPP_TAG_UNKNOWN
:
5637 case IPP_TAG_NOVALUE
:
5638 case IPP_TAG_NOTSETTABLE
:
5639 case IPP_TAG_DELETEATTR
:
5640 case IPP_TAG_ADMINDEFINE
:
5645 case IPP_TAG_INTEGER
:
5647 for (i
= 0, value
= attr
->values
;
5648 i
< attr
->num_values
;
5651 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5653 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5655 DEBUG_puts("1ippWriteIO: Could not write IPP "
5657 _cupsBufferRelease((char *)buffer
);
5658 return (IPP_STATE_ERROR
);
5667 * Arrays and sets are done by sending additional
5668 * values with a zero-length name...
5671 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5677 * Integers and enumerations are both 4-byte signed
5678 * (twos-complement) values.
5680 * Put the 2-byte length and 4-byte value into the buffer...
5685 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 24);
5686 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 16);
5687 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 8);
5688 *bufptr
++ = (ipp_uchar_t
)value
->integer
;
5692 case IPP_TAG_BOOLEAN
:
5693 for (i
= 0, value
= attr
->values
;
5694 i
< attr
->num_values
;
5697 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5699 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5701 DEBUG_puts("1ippWriteIO: Could not write IPP "
5703 _cupsBufferRelease((char *)buffer
);
5704 return (IPP_STATE_ERROR
);
5713 * Arrays and sets are done by sending additional
5714 * values with a zero-length name...
5717 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5723 * Boolean values are 1-byte; 0 = false, 1 = true.
5725 * Put the 2-byte length and 1-byte value into the buffer...
5730 *bufptr
++ = (ipp_uchar_t
)value
->boolean
;
5736 case IPP_TAG_KEYWORD
:
5738 case IPP_TAG_URISCHEME
:
5739 case IPP_TAG_CHARSET
:
5740 case IPP_TAG_LANGUAGE
:
5741 case IPP_TAG_MIMETYPE
:
5742 for (i
= 0, value
= attr
->values
;
5743 i
< attr
->num_values
;
5749 * Arrays and sets are done by sending additional
5750 * values with a zero-length name...
5753 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5755 ippTagString(attr
->value_tag
)));
5756 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5758 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5760 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5762 DEBUG_puts("1ippWriteIO: Could not write IPP "
5764 _cupsBufferRelease((char *)buffer
);
5765 return (IPP_STATE_ERROR
);
5771 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5776 if (value
->string
.text
!= NULL
)
5777 n
= (int)strlen(value
->string
.text
);
5781 if (n
> (IPP_BUF_SIZE
- 2))
5783 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5784 _cupsBufferRelease((char *)buffer
);
5785 return (IPP_STATE_ERROR
);
5788 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5789 value
->string
.text
));
5791 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5793 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5795 DEBUG_puts("1ippWriteIO: Could not write IPP "
5797 _cupsBufferRelease((char *)buffer
);
5798 return (IPP_STATE_ERROR
);
5805 * All simple strings consist of the 2-byte length and
5806 * character data without the trailing nul normally found
5807 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5808 * bytes since the 2-byte length is a signed (twos-complement)
5811 * Put the 2-byte length and string characters in the buffer.
5814 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5815 *bufptr
++ = (ipp_uchar_t
)n
;
5819 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5826 for (i
= 0, value
= attr
->values
;
5827 i
< attr
->num_values
;
5830 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5832 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5834 DEBUG_puts("1ippWriteIO: Could not write IPP "
5836 _cupsBufferRelease((char *)buffer
);
5837 return (IPP_STATE_ERROR
);
5846 * Arrays and sets are done by sending additional
5847 * values with a zero-length name...
5850 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5856 * Date values consist of a 2-byte length and an
5857 * 11-byte date/time structure defined by RFC 1903.
5859 * Put the 2-byte length and 11-byte date/time
5860 * structure in the buffer.
5865 memcpy(bufptr
, value
->date
, 11);
5870 case IPP_TAG_RESOLUTION
:
5871 for (i
= 0, value
= attr
->values
;
5872 i
< attr
->num_values
;
5875 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5877 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5879 DEBUG_puts("1ippWriteIO: Could not write IPP "
5881 _cupsBufferRelease((char *)buffer
);
5882 return (IPP_STATE_ERROR
);
5891 * Arrays and sets are done by sending additional
5892 * values with a zero-length name...
5895 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5901 * Resolution values consist of a 2-byte length,
5902 * 4-byte horizontal resolution value, 4-byte vertical
5903 * resolution value, and a 1-byte units value.
5905 * Put the 2-byte length and resolution value data
5911 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 24);
5912 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 16);
5913 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 8);
5914 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.xres
;
5915 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 24);
5916 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 16);
5917 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 8);
5918 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.yres
;
5919 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.units
;
5923 case IPP_TAG_RANGE
:
5924 for (i
= 0, value
= attr
->values
;
5925 i
< attr
->num_values
;
5928 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
5930 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5932 DEBUG_puts("1ippWriteIO: Could not write IPP "
5934 _cupsBufferRelease((char *)buffer
);
5935 return (IPP_STATE_ERROR
);
5944 * Arrays and sets are done by sending additional
5945 * values with a zero-length name...
5948 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5954 * Range values consist of a 2-byte length,
5955 * 4-byte lower value, and 4-byte upper value.
5957 * Put the 2-byte length and range value data
5963 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 24);
5964 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 16);
5965 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 8);
5966 *bufptr
++ = (ipp_uchar_t
)value
->range
.lower
;
5967 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 24);
5968 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 16);
5969 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 8);
5970 *bufptr
++ = (ipp_uchar_t
)value
->range
.upper
;
5974 case IPP_TAG_TEXTLANG
:
5975 case IPP_TAG_NAMELANG
:
5976 for (i
= 0, value
= attr
->values
;
5977 i
< attr
->num_values
;
5983 * Arrays and sets are done by sending additional
5984 * values with a zero-length name...
5987 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5989 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5991 DEBUG_puts("1ippWriteIO: Could not write IPP "
5993 _cupsBufferRelease((char *)buffer
);
5994 return (IPP_STATE_ERROR
);
6000 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6006 * textWithLanguage and nameWithLanguage values consist
6007 * of a 2-byte length for both strings and their
6008 * individual lengths, a 2-byte length for the
6009 * character string, the character string without the
6010 * trailing nul, a 2-byte length for the character
6011 * set string, and the character set string without
6017 if (value
->string
.language
!= NULL
)
6018 n
+= (int)strlen(value
->string
.language
);
6020 if (value
->string
.text
!= NULL
)
6021 n
+= (int)strlen(value
->string
.text
);
6023 if (n
> (IPP_BUF_SIZE
- 2))
6025 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
6026 "too long (%d)", n
));
6027 _cupsBufferRelease((char *)buffer
);
6028 return (IPP_STATE_ERROR
);
6031 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6033 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6035 DEBUG_puts("1ippWriteIO: Could not write IPP "
6037 _cupsBufferRelease((char *)buffer
);
6038 return (IPP_STATE_ERROR
);
6044 /* Length of entire value */
6045 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6046 *bufptr
++ = (ipp_uchar_t
)n
;
6048 /* Length of language */
6049 if (value
->string
.language
!= NULL
)
6050 n
= (int)strlen(value
->string
.language
);
6054 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6055 *bufptr
++ = (ipp_uchar_t
)n
;
6060 memcpy(bufptr
, value
->string
.language
, (size_t)n
);
6064 /* Length of text */
6065 if (value
->string
.text
!= NULL
)
6066 n
= (int)strlen(value
->string
.text
);
6070 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6071 *bufptr
++ = (ipp_uchar_t
)n
;
6076 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
6082 case IPP_TAG_BEGIN_COLLECTION
:
6083 for (i
= 0, value
= attr
->values
;
6084 i
< attr
->num_values
;
6088 * Collections are written with the begin-collection
6089 * tag first with a value of 0 length, followed by the
6090 * attributes in the collection, then the end-collection
6094 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6096 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6098 DEBUG_puts("1ippWriteIO: Could not write IPP "
6100 _cupsBufferRelease((char *)buffer
);
6101 return (IPP_STATE_ERROR
);
6110 * Arrays and sets are done by sending additional
6111 * values with a zero-length name...
6114 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6120 * Write a data length of 0 and flush the buffer...
6126 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6128 DEBUG_puts("1ippWriteIO: Could not write IPP "
6130 _cupsBufferRelease((char *)buffer
);
6131 return (IPP_STATE_ERROR
);
6137 * Then write the collection attribute...
6140 value
->collection
->state
= IPP_STATE_IDLE
;
6142 if (ippWriteIO(dst
, cb
, 1, ipp
,
6143 value
->collection
) == IPP_STATE_ERROR
)
6145 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6146 _cupsBufferRelease((char *)buffer
);
6147 return (IPP_STATE_ERROR
);
6153 for (i
= 0, value
= attr
->values
;
6154 i
< attr
->num_values
;
6160 * Arrays and sets are done by sending additional
6161 * values with a zero-length name...
6164 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6166 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6168 DEBUG_puts("1ippWriteIO: Could not write IPP "
6170 _cupsBufferRelease((char *)buffer
);
6171 return (IPP_STATE_ERROR
);
6177 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6183 * An unknown value might some new value that a
6184 * vendor has come up with. It consists of a
6185 * 2-byte length and the bytes in the unknown
6189 n
= value
->unknown
.length
;
6191 if (n
> (IPP_BUF_SIZE
- 2))
6193 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6195 _cupsBufferRelease((char *)buffer
);
6196 return (IPP_STATE_ERROR
);
6199 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6201 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6203 DEBUG_puts("1ippWriteIO: Could not write IPP "
6205 _cupsBufferRelease((char *)buffer
);
6206 return (IPP_STATE_ERROR
);
6212 /* Length of unknown value */
6213 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6214 *bufptr
++ = (ipp_uchar_t
)n
;
6219 memcpy(bufptr
, value
->unknown
.data
, (size_t)n
);
6227 * Write the data out...
6230 if (bufptr
> buffer
)
6232 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6234 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6235 _cupsBufferRelease((char *)buffer
);
6236 return (IPP_STATE_ERROR
);
6239 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6240 (int)(bufptr
- buffer
)));
6244 * If blocking is disabled and we aren't at the end of the attribute
6245 * list, stop here...
6248 if (!blocking
&& ipp
->current
)
6252 if (ipp
->current
== NULL
)
6255 * Done with all of the attributes; add the end-of-attributes
6256 * tag or end-collection attribute...
6261 buffer
[0] = IPP_TAG_END
;
6266 buffer
[0] = IPP_TAG_END_COLLECTION
;
6267 buffer
[1] = 0; /* empty name */
6269 buffer
[3] = 0; /* empty value */
6274 if ((*cb
)(dst
, buffer
, (size_t)n
) < 0)
6276 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6277 _cupsBufferRelease((char *)buffer
);
6278 return (IPP_STATE_ERROR
);
6281 ipp
->state
= IPP_STATE_DATA
;
6285 case IPP_STATE_DATA
:
6289 break; /* anti-compiler-warning-code */
6292 _cupsBufferRelease((char *)buffer
);
6294 return (ipp
->state
);
6299 * 'ipp_add_attr()' - Add a new attribute to the message.
6302 static ipp_attribute_t
* /* O - New attribute */
6303 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6304 const char *name
, /* I - Attribute name or NULL */
6305 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6306 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6307 int num_values
) /* I - Number of values */
6309 int alloc_values
; /* Number of values to allocate */
6310 ipp_attribute_t
*attr
; /* New attribute */
6313 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
));
6316 * Range check input...
6319 if (!ipp
|| num_values
< 0)
6323 * Allocate memory, rounding the allocation up as needed...
6326 if (num_values
<= 1)
6329 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6331 attr
= calloc(sizeof(ipp_attribute_t
) +
6332 (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6337 * Initialize attribute...
6340 DEBUG_printf(("4debug_alloc: %p %s %s%s (%d values)", (void *)attr
, name
, num_values
> 1 ? "1setOf " : "", ippTagString(value_tag
), num_values
));
6343 attr
->name
= _cupsStrAlloc(name
);
6345 attr
->group_tag
= group_tag
;
6346 attr
->value_tag
= value_tag
;
6347 attr
->num_values
= num_values
;
6350 * Add it to the end of the linked list...
6354 ipp
->last
->next
= attr
;
6358 ipp
->prev
= ipp
->last
;
6359 ipp
->last
= ipp
->current
= attr
;
6362 DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr
));
6369 * 'ipp_free_values()' - Free attribute values.
6373 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6374 int element
,/* I - First value to free */
6375 int count
) /* I - Number of values to free */
6377 int i
; /* Looping var */
6378 _ipp_value_t
*value
; /* Current value */
6381 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", (void *)attr
, element
, count
));
6383 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6386 * Free values as needed...
6389 switch (attr
->value_tag
)
6391 case IPP_TAG_TEXTLANG
:
6392 case IPP_TAG_NAMELANG
:
6393 if (element
== 0 && count
== attr
->num_values
&&
6394 attr
->values
[0].string
.language
)
6396 _cupsStrFree(attr
->values
[0].string
.language
);
6397 attr
->values
[0].string
.language
= NULL
;
6399 /* Fall through to other string values */
6403 case IPP_TAG_RESERVED_STRING
:
6404 case IPP_TAG_KEYWORD
:
6406 case IPP_TAG_URISCHEME
:
6407 case IPP_TAG_CHARSET
:
6408 case IPP_TAG_LANGUAGE
:
6409 case IPP_TAG_MIMETYPE
:
6410 for (i
= count
, value
= attr
->values
+ element
;
6414 _cupsStrFree(value
->string
.text
);
6415 value
->string
.text
= NULL
;
6419 case IPP_TAG_UNSUPPORTED_VALUE
:
6420 case IPP_TAG_DEFAULT
:
6421 case IPP_TAG_UNKNOWN
:
6422 case IPP_TAG_NOVALUE
:
6423 case IPP_TAG_NOTSETTABLE
:
6424 case IPP_TAG_DELETEATTR
:
6425 case IPP_TAG_ADMINDEFINE
:
6426 case IPP_TAG_INTEGER
:
6428 case IPP_TAG_BOOLEAN
:
6430 case IPP_TAG_RESOLUTION
:
6431 case IPP_TAG_RANGE
:
6434 case IPP_TAG_BEGIN_COLLECTION
:
6435 for (i
= count
, value
= attr
->values
+ element
;
6439 ippDelete(value
->collection
);
6440 value
->collection
= NULL
;
6444 case IPP_TAG_STRING
:
6446 for (i
= count
, value
= attr
->values
+ element
;
6450 if (value
->unknown
.data
)
6452 free(value
->unknown
.data
);
6453 value
->unknown
.data
= NULL
;
6461 * If we are not freeing values from the end, move the remaining values up...
6464 if ((element
+ count
) < attr
->num_values
)
6465 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6466 (size_t)(attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6468 attr
->num_values
-= count
;
6473 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6475 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6476 * to "ll-cc", "ll-region", and "charset-number", respectively.
6479 static char * /* O - Language code string */
6480 ipp_get_code(const char *value
, /* I - Locale/charset string */
6481 char *buffer
, /* I - String buffer */
6482 size_t bufsize
) /* I - Size of string buffer */
6484 char *bufptr
, /* Pointer into buffer */
6485 *bufend
; /* End of buffer */
6489 * Convert values to lowercase and change _ to - as needed...
6492 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6493 *value
&& bufptr
< bufend
;
6498 *bufptr
++ = (char)_cups_tolower(*value
);
6503 * Return the converted string...
6511 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6513 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6514 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6517 static char * /* O - Language code string */
6518 ipp_lang_code(const char *locale
, /* I - Locale string */
6519 char *buffer
, /* I - String buffer */
6520 size_t bufsize
) /* I - Size of string buffer */
6523 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6526 if (!_cups_strcasecmp(locale
, "c"))
6528 strlcpy(buffer
, "en", bufsize
);
6532 return (ipp_get_code(locale
, buffer
, bufsize
));
6537 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6540 static size_t /* O - Size of IPP message */
6541 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6542 int collection
) /* I - 1 if a collection, 0 otherwise */
6544 int i
; /* Looping var */
6545 size_t bytes
; /* Number of bytes */
6546 ipp_attribute_t
*attr
; /* Current attribute */
6547 ipp_tag_t group
; /* Current group */
6548 _ipp_value_t
*value
; /* Current value */
6551 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp
, collection
));
6555 DEBUG_puts("4ipp_length: Returning 0 bytes");
6560 * Start with 8 bytes for the IPP message header...
6563 bytes
= collection
? 0 : 8;
6566 * Then add the lengths of each attribute...
6569 group
= IPP_TAG_ZERO
;
6571 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6573 if (attr
->group_tag
!= group
&& !collection
)
6575 group
= attr
->group_tag
;
6576 if (group
== IPP_TAG_ZERO
)
6579 bytes
++; /* Group tag */
6585 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6586 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6588 if ((attr
->value_tag
& ~IPP_TAG_CUPS_CONST
) < IPP_TAG_EXTENSION
)
6589 bytes
+= (size_t)attr
->num_values
;/* Value tag for each value */
6591 bytes
+= (size_t)(5 * attr
->num_values
);
6592 /* Value tag for each value */
6593 bytes
+= (size_t)(2 * attr
->num_values
);
6595 bytes
+= strlen(attr
->name
); /* Name */
6596 bytes
+= (size_t)(2 * attr
->num_values
);
6600 bytes
+= 5; /* Add membername overhead */
6602 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6604 case IPP_TAG_UNSUPPORTED_VALUE
:
6605 case IPP_TAG_DEFAULT
:
6606 case IPP_TAG_UNKNOWN
:
6607 case IPP_TAG_NOVALUE
:
6608 case IPP_TAG_NOTSETTABLE
:
6609 case IPP_TAG_DELETEATTR
:
6610 case IPP_TAG_ADMINDEFINE
:
6613 case IPP_TAG_INTEGER
:
6615 bytes
+= (size_t)(4 * attr
->num_values
);
6618 case IPP_TAG_BOOLEAN
:
6619 bytes
+= (size_t)attr
->num_values
;
6624 case IPP_TAG_KEYWORD
:
6626 case IPP_TAG_URISCHEME
:
6627 case IPP_TAG_CHARSET
:
6628 case IPP_TAG_LANGUAGE
:
6629 case IPP_TAG_MIMETYPE
:
6630 for (i
= 0, value
= attr
->values
;
6631 i
< attr
->num_values
;
6633 if (value
->string
.text
)
6634 bytes
+= strlen(value
->string
.text
);
6638 bytes
+= (size_t)(11 * attr
->num_values
);
6641 case IPP_TAG_RESOLUTION
:
6642 bytes
+= (size_t)(9 * attr
->num_values
);
6645 case IPP_TAG_RANGE
:
6646 bytes
+= (size_t)(8 * attr
->num_values
);
6649 case IPP_TAG_TEXTLANG
:
6650 case IPP_TAG_NAMELANG
:
6651 bytes
+= (size_t)(4 * attr
->num_values
);
6652 /* Charset + text length */
6654 for (i
= 0, value
= attr
->values
;
6655 i
< attr
->num_values
;
6658 if (value
->string
.language
)
6659 bytes
+= strlen(value
->string
.language
);
6661 if (value
->string
.text
)
6662 bytes
+= strlen(value
->string
.text
);
6666 case IPP_TAG_BEGIN_COLLECTION
:
6667 for (i
= 0, value
= attr
->values
;
6668 i
< attr
->num_values
;
6670 bytes
+= ipp_length(value
->collection
, 1);
6674 for (i
= 0, value
= attr
->values
;
6675 i
< attr
->num_values
;
6677 bytes
+= (size_t)value
->unknown
.length
;
6683 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6684 * for the "end of collection" tag and return...
6692 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6699 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6702 static ssize_t
/* O - Number of bytes read */
6703 ipp_read_http(http_t
*http
, /* I - Client connection */
6704 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6705 size_t length
) /* I - Total length */
6707 ssize_t tbytes
, /* Total bytes read */
6708 bytes
; /* Bytes read this pass */
6711 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http
, (void *)buffer
, (int)length
));
6714 * Loop until all bytes are read...
6717 for (tbytes
= 0, bytes
= 0;
6718 tbytes
< (int)length
;
6719 tbytes
+= bytes
, buffer
+= bytes
)
6721 DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT
", http->state=%d", CUPS_LLCAST tbytes
, http
->state
));
6723 if (http
->state
== HTTP_STATE_WAITING
)
6726 if (http
->used
== 0 && !http
->blocking
)
6729 * Wait up to 10 seconds for more data on non-blocking sockets...
6732 if (!httpWait(http
, 10000))
6742 else if (http
->used
== 0 && http
->timeout_value
> 0)
6745 * Wait up to timeout seconds for more data on blocking sockets...
6748 if (!httpWait(http
, (int)(1000 * http
->timeout_value
)))
6759 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- (size_t)tbytes
)) < 0)
6764 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6770 else if (bytes
== 0)
6775 * Return the number of bytes read...
6778 if (tbytes
== 0 && bytes
< 0)
6781 DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST tbytes
));
6788 * 'ipp_read_file()' - Read IPP data from a file.
6791 static ssize_t
/* O - Number of bytes read */
6792 ipp_read_file(int *fd
, /* I - File descriptor */
6793 ipp_uchar_t
*buffer
, /* O - Read buffer */
6794 size_t length
) /* I - Number of bytes to read */
6797 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6799 return (read(*fd
, buffer
, length
));
6805 * 'ipp_set_error()' - Set a formatted, localized error string.
6809 ipp_set_error(ipp_status_t status
, /* I - Status code */
6810 const char *format
, /* I - Printf-style error string */
6811 ...) /* I - Additional arguments as needed */
6813 va_list ap
; /* Pointer to additional args */
6814 char buffer
[2048]; /* Message buffer */
6815 cups_lang_t
*lang
= cupsLangDefault();
6816 /* Current language */
6819 va_start(ap
, format
);
6820 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6823 _cupsSetError(status
, buffer
, 0);
6828 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6832 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6833 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6834 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6835 int element
) /* I - Value number (0-based) */
6837 ipp_attribute_t
*temp
, /* New attribute pointer */
6838 *current
, /* Current attribute in list */
6839 *prev
; /* Previous attribute in list */
6840 int alloc_values
; /* Allocated values */
6844 * If we are setting an existing value element, return it...
6849 if (temp
->num_values
<= 1)
6852 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6853 ~(IPP_MAX_VALUES
- 1);
6855 if (element
< alloc_values
)
6857 if (element
>= temp
->num_values
)
6858 temp
->num_values
= element
+ 1;
6860 return (temp
->values
+ element
);
6864 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6865 * values when num_values > 1.
6868 if (alloc_values
< IPP_MAX_VALUES
)
6869 alloc_values
= IPP_MAX_VALUES
;
6871 alloc_values
+= IPP_MAX_VALUES
;
6873 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6877 * Reallocate memory...
6880 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) + (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6882 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6883 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6888 * Zero the new memory...
6891 memset(temp
->values
+ temp
->num_values
, 0, (size_t)(alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6896 * Reset pointers in the list...
6899 DEBUG_printf(("4debug_free: %p %s", (void *)*attr
, temp
->name
));
6900 DEBUG_printf(("4debug_alloc: %p %s %s%s (%d)", (void *)temp
, temp
->name
, temp
->num_values
> 1 ? "1setOf " : "", ippTagString(temp
->value_tag
), temp
->num_values
));
6902 if (ipp
->current
== *attr
&& ipp
->prev
)
6905 * Use current "previous" pointer...
6913 * Find this attribute in the linked list...
6916 for (prev
= NULL
, current
= ipp
->attrs
;
6917 current
&& current
!= *attr
;
6918 prev
= current
, current
= current
->next
);
6923 * This is a serious error!
6927 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
6928 _("IPP attribute is not a member of the message."), 1);
6929 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
6939 ipp
->current
= temp
;
6942 if (ipp
->last
== *attr
)
6949 * Return the value element...
6952 if (element
>= temp
->num_values
)
6953 temp
->num_values
= element
+ 1;
6955 return (temp
->values
+ element
);
6960 * 'ipp_write_file()' - Write IPP data to a file.
6963 static ssize_t
/* O - Number of bytes written */
6964 ipp_write_file(int *fd
, /* I - File descriptor */
6965 ipp_uchar_t
*buffer
, /* I - Data to write */
6966 size_t length
) /* I - Number of bytes to write */
6969 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
6971 return (write(*fd
, buffer
, length
));