2 * Internet Printing Protocol functions for CUPS.
4 * Copyright 2007-2017 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include "cups-private.h"
25 static ipp_attribute_t
*ipp_add_attr(ipp_t
*ipp
, const char *name
,
26 ipp_tag_t group_tag
, ipp_tag_t value_tag
,
28 static void ipp_free_values(ipp_attribute_t
*attr
, int element
,
30 static char *ipp_get_code(const char *locale
, char *buffer
,
32 __attribute__((nonnull(1,2)));
33 static char *ipp_lang_code(const char *locale
, char *buffer
,
35 __attribute__((nonnull(1,2)));
36 static size_t ipp_length(ipp_t
*ipp
, int collection
);
37 static ssize_t
ipp_read_http(http_t
*http
, ipp_uchar_t
*buffer
,
39 static ssize_t
ipp_read_file(int *fd
, ipp_uchar_t
*buffer
,
41 static void ipp_set_error(ipp_status_t status
, const char *format
,
43 static _ipp_value_t
*ipp_set_value(ipp_t
*ipp
, ipp_attribute_t
**attr
,
45 static ssize_t
ipp_write_file(int *fd
, ipp_uchar_t
*buffer
,
50 * '_cupsBufferGet()' - Get a read/write buffer.
53 char * /* O - Buffer */
54 _cupsBufferGet(size_t size
) /* I - Size required */
56 _cups_buffer_t
*buffer
; /* Current buffer */
57 _cups_globals_t
*cg
= _cupsGlobals();
61 for (buffer
= cg
->cups_buffers
; buffer
; buffer
= buffer
->next
)
62 if (!buffer
->used
&& buffer
->size
>= size
)
67 if ((buffer
= malloc(sizeof(_cups_buffer_t
) + size
- 1)) == NULL
)
70 buffer
->next
= cg
->cups_buffers
;
72 cg
->cups_buffers
= buffer
;
82 * '_cupsBufferRelease()' - Release a read/write buffer.
86 _cupsBufferRelease(char *b
) /* I - Buffer to release */
88 _cups_buffer_t
*buffer
; /* Buffer */
92 * Mark this buffer as unused...
95 buffer
= (_cups_buffer_t
*)(b
- offsetof(_cups_buffer_t
, d
));
101 * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
103 * The @code ipp@ parameter refers to an IPP message previously created using
104 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
106 * The @code group@ parameter specifies the IPP attribute group tag: none
107 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
108 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
109 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
110 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
113 ipp_attribute_t
* /* O - New attribute */
114 ippAddBoolean(ipp_t
*ipp
, /* I - IPP message */
115 ipp_tag_t group
, /* I - IPP group */
116 const char *name
, /* I - Name of attribute */
117 char value
) /* I - Value of attribute */
119 ipp_attribute_t
*attr
; /* New attribute */
122 DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)", (void *)ipp
, group
, ippTagString(group
), name
, value
));
125 * Range check input...
128 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
129 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
133 * Create the attribute...
136 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, 1)) == NULL
)
139 attr
->values
[0].boolean
= value
;
146 * 'ippAddBooleans()' - Add an array of boolean values.
148 * The @code ipp@ parameter refers to an IPP message previously created using
149 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
151 * The @code group@ parameter specifies the IPP attribute group tag: none
152 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
153 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
154 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
155 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
158 ipp_attribute_t
* /* O - New attribute */
159 ippAddBooleans(ipp_t
*ipp
, /* I - IPP message */
160 ipp_tag_t group
, /* I - IPP group */
161 const char *name
, /* I - Name of attribute */
162 int num_values
, /* I - Number of values */
163 const char *values
) /* I - Values */
165 int i
; /* Looping var */
166 ipp_attribute_t
*attr
; /* New attribute */
167 _ipp_value_t
*value
; /* Current value */
170 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
));
173 * Range check input...
176 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
177 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
182 * Create the attribute...
185 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, num_values
)) == NULL
)
190 for (i
= num_values
, value
= attr
->values
;
193 value
->boolean
= *values
++;
201 * 'ippAddCollection()' - Add a collection value.
203 * The @code ipp@ parameter refers to an IPP message previously created using
204 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
206 * The @code group@ parameter specifies the IPP attribute group tag: none
207 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
208 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
209 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
210 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
212 * @since CUPS 1.1.19/macOS 10.3@
215 ipp_attribute_t
* /* O - New attribute */
216 ippAddCollection(ipp_t
*ipp
, /* I - IPP message */
217 ipp_tag_t group
, /* I - IPP group */
218 const char *name
, /* I - Name of attribute */
219 ipp_t
*value
) /* I - Value */
221 ipp_attribute_t
*attr
; /* New attribute */
224 DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
227 * Range check input...
230 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
231 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
235 * Create the attribute...
238 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
, 1)) == NULL
)
241 attr
->values
[0].collection
= value
;
251 * 'ippAddCollections()' - Add an array of collection values.
253 * The @code ipp@ parameter refers to an IPP message previously created using
254 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
256 * The @code group@ parameter specifies the IPP attribute group tag: none
257 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
258 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
259 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
260 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
262 * @since CUPS 1.1.19/macOS 10.3@
265 ipp_attribute_t
* /* O - New attribute */
267 ipp_t
*ipp
, /* I - IPP message */
268 ipp_tag_t group
, /* I - IPP group */
269 const char *name
, /* I - Name of attribute */
270 int num_values
, /* I - Number of values */
271 const ipp_t
**values
) /* I - Values */
273 int i
; /* Looping var */
274 ipp_attribute_t
*attr
; /* New attribute */
275 _ipp_value_t
*value
; /* Current value */
278 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
));
281 * Range check input...
284 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
285 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
290 * Create the attribute...
293 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
,
294 num_values
)) == NULL
)
299 for (i
= num_values
, value
= attr
->values
;
303 value
->collection
= (ipp_t
*)*values
++;
304 value
->collection
->use
++;
313 * 'ippAddDate()' - Add a dateTime attribute to an IPP message.
315 * The @code ipp@ parameter refers to an IPP message previously created using
316 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
318 * The @code group@ parameter specifies the IPP attribute group tag: none
319 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
320 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
321 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
322 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
325 ipp_attribute_t
* /* O - New attribute */
326 ippAddDate(ipp_t
*ipp
, /* I - IPP message */
327 ipp_tag_t group
, /* I - IPP group */
328 const char *name
, /* I - Name of attribute */
329 const ipp_uchar_t
*value
) /* I - Value */
331 ipp_attribute_t
*attr
; /* New attribute */
334 DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
337 * Range check input...
340 if (!ipp
|| !name
|| !value
|| group
< IPP_TAG_ZERO
||
341 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
345 * Create the attribute...
348 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_DATE
, 1)) == NULL
)
351 memcpy(attr
->values
[0].date
, value
, 11);
358 * 'ippAddInteger()' - Add a integer attribute to an IPP message.
360 * The @code ipp@ parameter refers to an IPP message previously created using
361 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
363 * The @code group@ parameter specifies the IPP attribute group tag: none
364 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
365 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
366 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
367 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
369 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
370 * (@code IPP_TAG_INTEGER@).
373 ipp_attribute_t
* /* O - New attribute */
374 ippAddInteger(ipp_t
*ipp
, /* I - IPP message */
375 ipp_tag_t group
, /* I - IPP group */
376 ipp_tag_t value_tag
, /* I - Type of attribute */
377 const char *name
, /* I - Name of attribute */
378 int value
) /* I - Value of attribute */
380 ipp_attribute_t
*attr
; /* New attribute */
383 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
));
385 value_tag
&= IPP_TAG_CUPS_MASK
;
388 * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
392 if (value_tag
>= IPP_TAG_UNSUPPORTED_VALUE
&& value_tag
<= IPP_TAG_ADMINDEFINE
)
393 return (ippAddOutOfBand(ipp
, group
, value_tag
, name
));
396 * Range check input...
400 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
401 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
402 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
))
405 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
406 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
411 * Create the attribute...
414 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
417 attr
->values
[0].integer
= value
;
424 * 'ippAddIntegers()' - Add an array of integer values.
426 * The @code ipp@ parameter refers to an IPP message previously created using
427 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
429 * The @code group@ parameter specifies the IPP attribute group tag: none
430 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
431 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
432 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
433 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
435 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
436 * (@code IPP_TAG_INTEGER@).
439 ipp_attribute_t
* /* O - New attribute */
440 ippAddIntegers(ipp_t
*ipp
, /* I - IPP message */
441 ipp_tag_t group
, /* I - IPP group */
442 ipp_tag_t value_tag
, /* I - Type of attribute */
443 const char *name
, /* I - Name of attribute */
444 int num_values
, /* I - Number of values */
445 const int *values
) /* I - Values */
447 int i
; /* Looping var */
448 ipp_attribute_t
*attr
; /* New attribute */
449 _ipp_value_t
*value
; /* Current value */
452 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
));
454 value_tag
&= IPP_TAG_CUPS_MASK
;
457 * Range check input...
461 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
462 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
463 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
) ||
467 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
468 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
474 * Create the attribute...
477 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
482 for (i
= num_values
, value
= attr
->values
;
485 value
->integer
= *values
++;
493 * 'ippAddOctetString()' - Add an octetString value to an IPP message.
495 * The @code ipp@ parameter refers to an IPP message previously created using
496 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
498 * The @code group@ parameter specifies the IPP attribute group tag: none
499 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
500 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
501 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
502 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
504 * @since CUPS 1.2/macOS 10.5@
507 ipp_attribute_t
* /* O - New attribute */
508 ippAddOctetString(ipp_t
*ipp
, /* I - IPP message */
509 ipp_tag_t group
, /* I - IPP group */
510 const char *name
, /* I - Name of attribute */
511 const void *data
, /* I - octetString data */
512 int datalen
) /* I - Length of data in bytes */
514 ipp_attribute_t
*attr
; /* New attribute */
517 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
518 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
519 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
522 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_STRING
, 1)) == NULL
)
526 * Initialize the attribute data...
529 attr
->values
[0].unknown
.length
= datalen
;
533 if ((attr
->values
[0].unknown
.data
= malloc((size_t)datalen
)) == NULL
)
535 ippDeleteAttribute(ipp
, attr
);
539 memcpy(attr
->values
[0].unknown
.data
, data
, (size_t)datalen
);
543 * Return the new attribute...
551 * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
553 * The @code ipp@ parameter refers to an IPP message previously created using
554 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
556 * The @code group@ parameter specifies the IPP attribute group tag: none
557 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
558 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
559 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
560 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
562 * Supported out-of-band values include unsupported-value
563 * (@code IPP_TAG_UNSUPPORTED_VALUE@), default (@code IPP_TAG_DEFAULT@), unknown
564 * (@code IPP_TAG_UNKNOWN@), no-value (@code IPP_TAG_NOVALUE@), not-settable
565 * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
566 * admin-define (@code IPP_TAG_ADMINDEFINE@).
568 * @since CUPS 1.6/macOS 10.8@
571 ipp_attribute_t
* /* O - New attribute */
572 ippAddOutOfBand(ipp_t
*ipp
, /* I - IPP message */
573 ipp_tag_t group
, /* I - IPP group */
574 ipp_tag_t value_tag
, /* I - Type of attribute */
575 const char *name
) /* I - Name of attribute */
577 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
));
579 value_tag
&= IPP_TAG_CUPS_MASK
;
582 * Range check input...
585 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
586 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
587 (value_tag
!= IPP_TAG_UNSUPPORTED_VALUE
&&
588 value_tag
!= IPP_TAG_DEFAULT
&&
589 value_tag
!= IPP_TAG_UNKNOWN
&&
590 value_tag
!= IPP_TAG_NOVALUE
&&
591 value_tag
!= IPP_TAG_NOTSETTABLE
&&
592 value_tag
!= IPP_TAG_DELETEATTR
&&
593 value_tag
!= IPP_TAG_ADMINDEFINE
))
597 * Create the attribute...
600 return (ipp_add_attr(ipp
, name
, group
, value_tag
, 1));
605 * 'ippAddRange()' - Add a range of values to an IPP message.
607 * The @code ipp@ parameter refers to an IPP message previously created using
608 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
610 * The @code group@ parameter specifies the IPP attribute group tag: none
611 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
612 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
613 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
614 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
616 * The @code lower@ parameter must be less than or equal to the @code upper@ parameter.
619 ipp_attribute_t
* /* O - New attribute */
620 ippAddRange(ipp_t
*ipp
, /* I - IPP message */
621 ipp_tag_t group
, /* I - IPP group */
622 const char *name
, /* I - Name of attribute */
623 int lower
, /* I - Lower value */
624 int upper
) /* I - Upper value */
626 ipp_attribute_t
*attr
; /* New attribute */
629 DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, upper=%d)", (void *)ipp
, group
, ippTagString(group
), name
, lower
, upper
));
632 * Range check input...
635 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
636 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
640 * Create the attribute...
643 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, 1)) == NULL
)
646 attr
->values
[0].range
.lower
= lower
;
647 attr
->values
[0].range
.upper
= upper
;
654 * 'ippAddRanges()' - Add ranges of values to an IPP message.
656 * The @code ipp@ parameter refers to an IPP message previously created using
657 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
659 * The @code group@ parameter specifies the IPP attribute group tag: none
660 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
661 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
662 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
663 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
666 ipp_attribute_t
* /* O - New attribute */
667 ippAddRanges(ipp_t
*ipp
, /* I - IPP message */
668 ipp_tag_t group
, /* I - IPP group */
669 const char *name
, /* I - Name of attribute */
670 int num_values
, /* I - Number of values */
671 const int *lower
, /* I - Lower values */
672 const int *upper
) /* I - Upper values */
674 int i
; /* Looping var */
675 ipp_attribute_t
*attr
; /* New attribute */
676 _ipp_value_t
*value
; /* Current value */
679 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
));
682 * Range check input...
685 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
686 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
691 * Create the attribute...
694 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, num_values
)) == NULL
)
699 for (i
= num_values
, value
= attr
->values
;
703 value
->range
.lower
= *lower
++;
704 value
->range
.upper
= *upper
++;
713 * 'ippAddResolution()' - Add a resolution value to an IPP message.
715 * The @code ipp@ parameter refers to an IPP message previously created using
716 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
718 * The @code group@ parameter specifies the IPP attribute group tag: none
719 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
720 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
721 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
722 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
725 ipp_attribute_t
* /* O - New attribute */
726 ippAddResolution(ipp_t
*ipp
, /* I - IPP message */
727 ipp_tag_t group
, /* I - IPP group */
728 const char *name
, /* I - Name of attribute */
729 ipp_res_t units
, /* I - Units for resolution */
730 int xres
, /* I - X resolution */
731 int yres
) /* I - Y resolution */
733 ipp_attribute_t
*attr
; /* New attribute */
736 DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", units=%d, xres=%d, yres=%d)", (void *)ipp
, group
,
737 ippTagString(group
), name
, units
, xres
, yres
));
740 * Range check input...
743 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
744 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
745 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
||
746 xres
< 0 || yres
< 0)
750 * Create the attribute...
753 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, 1)) == NULL
)
756 attr
->values
[0].resolution
.xres
= xres
;
757 attr
->values
[0].resolution
.yres
= yres
;
758 attr
->values
[0].resolution
.units
= units
;
765 * 'ippAddResolutions()' - Add resolution values to an IPP message.
767 * The @code ipp@ parameter refers to an IPP message previously created using
768 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
770 * The @code group@ parameter specifies the IPP attribute group tag: none
771 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
772 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
773 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
774 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
777 ipp_attribute_t
* /* O - New attribute */
778 ippAddResolutions(ipp_t
*ipp
, /* I - IPP message */
779 ipp_tag_t group
, /* I - IPP group */
780 const char *name
, /* I - Name of attribute */
781 int num_values
,/* I - Number of values */
782 ipp_res_t units
, /* I - Units for resolution */
783 const int *xres
, /* I - X resolutions */
784 const int *yres
) /* I - Y resolutions */
786 int i
; /* Looping var */
787 ipp_attribute_t
*attr
; /* New attribute */
788 _ipp_value_t
*value
; /* Current value */
791 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
));
794 * Range check input...
797 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
798 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
800 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
)
804 * Create the attribute...
807 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, num_values
)) == NULL
)
812 for (i
= num_values
, value
= attr
->values
;
816 value
->resolution
.xres
= *xres
++;
817 value
->resolution
.yres
= *yres
++;
818 value
->resolution
.units
= units
;
827 * 'ippAddSeparator()' - Add a group separator to an IPP message.
829 * The @code ipp@ parameter refers to an IPP message previously created using
830 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
833 ipp_attribute_t
* /* O - New attribute */
834 ippAddSeparator(ipp_t
*ipp
) /* I - IPP message */
836 DEBUG_printf(("ippAddSeparator(ipp=%p)", (void *)ipp
));
839 * Range check input...
846 * Create the attribute...
849 return (ipp_add_attr(ipp
, NULL
, IPP_TAG_ZERO
, IPP_TAG_ZERO
, 0));
854 * 'ippAddString()' - Add a language-encoded string to an IPP message.
856 * The @code ipp@ parameter refers to an IPP message previously created using
857 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
859 * The @code group@ parameter specifies the IPP attribute group tag: none
860 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
861 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
862 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
863 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
865 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
866 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
867 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
868 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
869 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
870 * (@code IPP_TAG_URISCHEME@).
872 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
873 * textWithLanguage string values and must be @code NULL@ for all other string values.
876 ipp_attribute_t
* /* O - New attribute */
877 ippAddString(ipp_t
*ipp
, /* I - IPP message */
878 ipp_tag_t group
, /* I - IPP group */
879 ipp_tag_t value_tag
, /* I - Type of attribute */
880 const char *name
, /* I - Name of attribute */
881 const char *language
, /* I - Language code */
882 const char *value
) /* I - Value */
884 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
885 ipp_attribute_t
*attr
; /* New attribute */
886 char code
[IPP_MAX_LANGUAGE
];
887 /* Charset/language code buffer */
890 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
));
893 * Range check input...
896 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
899 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
900 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
901 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
902 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
)
905 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
906 != (language
!= NULL
))
909 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
910 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
915 * See if we need to map charset, language, or locale values...
918 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
919 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
920 value_tag
= temp_tag
; /* Don't do a fast copy */
921 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
) &&
922 strcmp(value
, ipp_get_code(value
, code
, sizeof(code
))))
923 value_tag
= temp_tag
; /* Don't do a fast copy */
924 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
) &&
925 strcmp(value
, ipp_lang_code(value
, code
, sizeof(code
))))
926 value_tag
= temp_tag
; /* Don't do a fast copy */
929 * Create the attribute...
932 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
936 * Initialize the attribute data...
939 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
941 attr
->values
[0].string
.language
= (char *)language
;
942 attr
->values
[0].string
.text
= (char *)value
;
947 attr
->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
952 if (value_tag
== IPP_TAG_CHARSET
)
953 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_get_code(value
, code
,
955 else if (value_tag
== IPP_TAG_LANGUAGE
)
956 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_lang_code(value
, code
,
959 attr
->values
[0].string
.text
= _cupsStrAlloc(value
);
968 * 'ippAddStringf()' - Add a formatted string to an IPP message.
970 * The @code ipp@ parameter refers to an IPP message previously created using
971 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
973 * The @code group@ parameter specifies the IPP attribute group tag: none
974 * (@code IPP_TAG_ZERO@, for member attributes), document
975 * (@code IPP_TAG_DOCUMENT@), event notification
976 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
977 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
978 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
980 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
981 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
982 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
983 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
984 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
985 * (@code IPP_TAG_URISCHEME@).
987 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
988 * and textWithLanguage string values and must be @code NULL@ for all other
991 * The @code format@ parameter uses formatting characters compatible with the
992 * printf family of standard functions. Additional arguments follow it as
993 * needed. The formatted string is truncated as needed to the maximum length of
994 * the corresponding value type.
996 * @since CUPS 1.7/macOS 10.9@
999 ipp_attribute_t
* /* O - New attribute */
1000 ippAddStringf(ipp_t
*ipp
, /* I - IPP message */
1001 ipp_tag_t group
, /* I - IPP group */
1002 ipp_tag_t value_tag
, /* I - Type of attribute */
1003 const char *name
, /* I - Name of attribute */
1004 const char *language
, /* I - Language code (@code NULL@ for default) */
1005 const char *format
, /* I - Printf-style format string */
1006 ...) /* I - Additional arguments as needed */
1008 ipp_attribute_t
*attr
; /* New attribute */
1009 va_list ap
; /* Argument pointer */
1012 va_start(ap
, format
);
1013 attr
= ippAddStringfv(ipp
, group
, value_tag
, name
, language
, format
, ap
);
1021 * 'ippAddStringfv()' - Add a formatted string to an IPP message.
1023 * The @code ipp@ parameter refers to an IPP message previously created using
1024 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1026 * The @code group@ parameter specifies the IPP attribute group tag: none
1027 * (@code IPP_TAG_ZERO@, for member attributes), document
1028 * (@code IPP_TAG_DOCUMENT@), event notification
1029 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1030 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1031 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1033 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1034 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1035 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1036 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1037 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1038 * (@code IPP_TAG_URISCHEME@).
1040 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1041 * and textWithLanguage string values and must be @code NULL@ for all other
1044 * The @code format@ parameter uses formatting characters compatible with the
1045 * printf family of standard functions. Additional arguments are passed in the
1046 * stdarg pointer @code ap@. The formatted string is truncated as needed to the
1047 * maximum length of the corresponding value type.
1049 * @since CUPS 1.7/macOS 10.9@
1052 ipp_attribute_t
* /* O - New attribute */
1053 ippAddStringfv(ipp_t
*ipp
, /* I - IPP message */
1054 ipp_tag_t group
, /* I - IPP group */
1055 ipp_tag_t value_tag
, /* I - Type of attribute */
1056 const char *name
, /* I - Name of attribute */
1057 const char *language
, /* I - Language code (@code NULL@ for default) */
1058 const char *format
, /* I - Printf-style format string */
1059 va_list ap
) /* I - Additional arguments */
1061 char buffer
[IPP_MAX_TEXT
+ 4];
1062 /* Formatted text string */
1063 ssize_t bytes
, /* Length of formatted value */
1064 max_bytes
; /* Maximum number of bytes for value */
1068 * Range check input...
1071 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1072 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1073 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
1074 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
1078 if ((value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_NAMELANG
)
1079 != (language
!= NULL
))
1083 * Format the string...
1086 if (!strcmp(format
, "%s"))
1089 * Optimize the simple case...
1092 const char *s
= va_arg(ap
, char *);
1097 bytes
= (ssize_t
)strlen(s
);
1098 strlcpy(buffer
, s
, sizeof(buffer
));
1103 * Do a full formatting of the message...
1106 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
1111 * Limit the length of the string...
1118 case IPP_TAG_TEXTLANG
:
1119 max_bytes
= IPP_MAX_TEXT
;
1123 case IPP_TAG_NAMELANG
:
1124 max_bytes
= IPP_MAX_NAME
;
1127 case IPP_TAG_CHARSET
:
1128 max_bytes
= IPP_MAX_CHARSET
;
1131 case IPP_TAG_KEYWORD
:
1132 max_bytes
= IPP_MAX_KEYWORD
;
1135 case IPP_TAG_LANGUAGE
:
1136 max_bytes
= IPP_MAX_LANGUAGE
;
1139 case IPP_TAG_MIMETYPE
:
1140 max_bytes
= IPP_MAX_MIMETYPE
;
1144 max_bytes
= IPP_MAX_URI
;
1147 case IPP_TAG_URISCHEME
:
1148 max_bytes
= IPP_MAX_URISCHEME
;
1152 if (bytes
>= max_bytes
)
1154 char *bufmax
, /* Buffer at max_bytes */
1155 *bufptr
; /* Pointer into buffer */
1157 bufptr
= buffer
+ strlen(buffer
) - 1;
1158 bufmax
= buffer
+ max_bytes
- 1;
1160 while (bufptr
> bufmax
)
1164 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
1175 * Add the formatted string and return...
1178 return (ippAddString(ipp
, group
, value_tag
, name
, language
, buffer
));
1183 * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
1185 * The @code ipp@ parameter refers to an IPP message previously created using
1186 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1188 * The @code group@ parameter specifies the IPP attribute group tag: none
1189 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
1190 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
1191 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
1192 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1194 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1195 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1196 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1197 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1198 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1199 * (@code IPP_TAG_URISCHEME@).
1201 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1202 * textWithLanguage string values and must be @code NULL@ for all other string values.
1205 ipp_attribute_t
* /* O - New attribute */
1207 ipp_t
*ipp
, /* I - IPP message */
1208 ipp_tag_t group
, /* I - IPP group */
1209 ipp_tag_t value_tag
, /* I - Type of attribute */
1210 const char *name
, /* I - Name of attribute */
1211 int num_values
, /* I - Number of values */
1212 const char *language
, /* I - Language code (@code NULL@ for default) */
1213 const char * const *values
) /* I - Values */
1215 int i
; /* Looping var */
1216 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1217 ipp_attribute_t
*attr
; /* New attribute */
1218 _ipp_value_t
*value
; /* Current value */
1219 char code
[32]; /* Language/charset value buffer */
1222 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
));
1225 * Range check input...
1228 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
1231 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1232 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1233 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1234 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
||
1238 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1239 != (language
!= NULL
))
1242 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1243 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1249 * See if we need to map charset, language, or locale values...
1252 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
1253 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1254 value_tag
= temp_tag
; /* Don't do a fast copy */
1255 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
))
1257 for (i
= 0; i
< num_values
; i
++)
1258 if (strcmp(values
[i
], ipp_get_code(values
[i
], code
, sizeof(code
))))
1260 value_tag
= temp_tag
; /* Don't do a fast copy */
1264 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
))
1266 for (i
= 0; i
< num_values
; i
++)
1267 if (strcmp(values
[i
], ipp_lang_code(values
[i
], code
, sizeof(code
))))
1269 value_tag
= temp_tag
; /* Don't do a fast copy */
1275 * Create the attribute...
1278 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
1282 * Initialize the attribute data...
1285 for (i
= num_values
, value
= attr
->values
;
1291 if (value
== attr
->values
)
1293 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1294 value
->string
.language
= (char *)language
;
1296 value
->string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1300 value
->string
.language
= attr
->values
[0].string
.language
;
1305 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1306 value
->string
.text
= (char *)*values
++;
1307 else if (value_tag
== IPP_TAG_CHARSET
)
1308 value
->string
.text
= _cupsStrAlloc(ipp_get_code(*values
++, code
, sizeof(code
)));
1309 else if (value_tag
== IPP_TAG_LANGUAGE
)
1310 value
->string
.text
= _cupsStrAlloc(ipp_lang_code(*values
++, code
, sizeof(code
)));
1312 value
->string
.text
= _cupsStrAlloc(*values
++);
1321 * 'ippContainsInteger()' - Determine whether an attribute contains the
1322 * specified value or is within the list of ranges.
1324 * Returns non-zero when the attribute contains either a matching integer or
1325 * enum value, or the value falls within one of the rangeOfInteger values for
1328 * @since CUPS 1.7/macOS 10.9@
1331 int /* O - 1 on a match, 0 on no match */
1333 ipp_attribute_t
*attr
, /* I - Attribute */
1334 int value
) /* I - Integer/enum value */
1336 int i
; /* Looping var */
1337 _ipp_value_t
*avalue
; /* Current attribute value */
1341 * Range check input...
1347 if (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
&&
1348 attr
->value_tag
!= IPP_TAG_RANGE
)
1355 if (attr
->value_tag
== IPP_TAG_RANGE
)
1357 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1358 if (value
>= avalue
->range
.lower
&& value
<= avalue
->range
.upper
)
1363 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1364 if (value
== avalue
->integer
)
1373 * 'ippContainsString()' - Determine whether an attribute contains the
1374 * specified string value.
1376 * Returns non-zero when the attribute contains a matching charset, keyword,
1377 * naturalLanguage, mimeMediaType, name, text, uri, or uriScheme value.
1379 * @since CUPS 1.7/macOS 10.9@
1382 int /* O - 1 on a match, 0 on no match */
1384 ipp_attribute_t
*attr
, /* I - Attribute */
1385 const char *value
) /* I - String value */
1387 int i
; /* Looping var */
1388 _ipp_value_t
*avalue
; /* Current attribute value */
1391 DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", (void *)attr
, value
));
1394 * Range check input...
1397 if (!attr
|| !value
)
1399 DEBUG_puts("1ippContainsString: Returning 0 (bad input)");
1407 DEBUG_printf(("1ippContainsString: attr %s, %s with %d values.",
1408 attr
->name
, ippTagString(attr
->value_tag
),
1411 switch (attr
->value_tag
& IPP_TAG_CUPS_MASK
)
1413 case IPP_TAG_CHARSET
:
1414 case IPP_TAG_KEYWORD
:
1415 case IPP_TAG_LANGUAGE
:
1417 case IPP_TAG_URISCHEME
:
1418 for (i
= attr
->num_values
, avalue
= attr
->values
;
1422 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1423 attr
->num_values
- i
, avalue
->string
.text
));
1425 if (!strcmp(value
, avalue
->string
.text
))
1427 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1432 case IPP_TAG_MIMETYPE
:
1434 case IPP_TAG_NAMELANG
:
1436 case IPP_TAG_TEXTLANG
:
1437 for (i
= attr
->num_values
, avalue
= attr
->values
;
1441 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1442 attr
->num_values
- i
, avalue
->string
.text
));
1444 if (!_cups_strcasecmp(value
, avalue
->string
.text
))
1446 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1455 DEBUG_puts("1ippContainsString: Returning 0 (no match)");
1462 * 'ippCopyAttribute()' - Copy an attribute.
1464 * The specified attribute, @code attr@, is copied to the destination IPP message.
1465 * When @code quickcopy@ is non-zero, a "shallow" reference copy of the attribute is
1466 * created - this should only be done as long as the original source IPP message will
1467 * not be freed for the life of the destination.
1469 * @since CUPS 1.6/macOS 10.8@
1473 ipp_attribute_t
* /* O - New attribute */
1475 ipp_t
*dst
, /* I - Destination IPP message */
1476 ipp_attribute_t
*srcattr
, /* I - Attribute to copy */
1477 int quickcopy
) /* I - 1 for a referenced copy, 0 for normal */
1479 int i
; /* Looping var */
1480 ipp_attribute_t
*dstattr
; /* Destination attribute */
1481 _ipp_value_t
*srcval
, /* Source value */
1482 *dstval
; /* Destination value */
1485 DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", (void *)dst
, (void *)srcattr
, quickcopy
));
1488 * Range check input...
1491 if (!dst
|| !srcattr
)
1498 quickcopy
= quickcopy
? IPP_TAG_CUPS_CONST
: 0;
1500 switch (srcattr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
1503 dstattr
= ippAddSeparator(dst
);
1506 case IPP_TAG_UNSUPPORTED_VALUE
:
1507 case IPP_TAG_DEFAULT
:
1508 case IPP_TAG_UNKNOWN
:
1509 case IPP_TAG_NOVALUE
:
1510 case IPP_TAG_NOTSETTABLE
:
1511 case IPP_TAG_DELETEATTR
:
1512 case IPP_TAG_ADMINDEFINE
:
1513 dstattr
= ippAddOutOfBand(dst
, srcattr
->group_tag
, srcattr
->value_tag
& ~IPP_TAG_CUPS_CONST
, srcattr
->name
);
1516 case IPP_TAG_INTEGER
:
1518 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1519 srcattr
->name
, srcattr
->num_values
, NULL
);
1523 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1525 i
--, srcval
++, dstval
++)
1526 dstval
->integer
= srcval
->integer
;
1529 case IPP_TAG_BOOLEAN
:
1530 dstattr
= ippAddBooleans(dst
, srcattr
->group_tag
, srcattr
->name
,
1531 srcattr
->num_values
, NULL
);
1535 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1537 i
--, srcval
++, dstval
++)
1538 dstval
->boolean
= srcval
->boolean
;
1543 case IPP_TAG_KEYWORD
:
1545 case IPP_TAG_URISCHEME
:
1546 case IPP_TAG_CHARSET
:
1547 case IPP_TAG_LANGUAGE
:
1548 case IPP_TAG_MIMETYPE
:
1549 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1550 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1551 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1557 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1558 dstval
= dstattr
->values
;
1560 i
--, srcval
++, dstval
++)
1561 dstval
->string
.text
= srcval
->string
.text
;
1563 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1565 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1566 dstval
= dstattr
->values
;
1568 i
--, srcval
++, dstval
++)
1569 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1573 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1574 dstval
= dstattr
->values
;
1576 i
--, srcval
++, dstval
++)
1577 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1582 if (srcattr
->num_values
!= 1)
1585 dstattr
= ippAddDate(dst
, srcattr
->group_tag
, srcattr
->name
,
1586 srcattr
->values
[0].date
);
1589 case IPP_TAG_RESOLUTION
:
1590 dstattr
= ippAddResolutions(dst
, srcattr
->group_tag
, srcattr
->name
,
1591 srcattr
->num_values
, IPP_RES_PER_INCH
,
1596 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1598 i
--, srcval
++, dstval
++)
1600 dstval
->resolution
.xres
= srcval
->resolution
.xres
;
1601 dstval
->resolution
.yres
= srcval
->resolution
.yres
;
1602 dstval
->resolution
.units
= srcval
->resolution
.units
;
1606 case IPP_TAG_RANGE
:
1607 dstattr
= ippAddRanges(dst
, srcattr
->group_tag
, srcattr
->name
,
1608 srcattr
->num_values
, NULL
, NULL
);
1612 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1614 i
--, srcval
++, dstval
++)
1616 dstval
->range
.lower
= srcval
->range
.lower
;
1617 dstval
->range
.upper
= srcval
->range
.upper
;
1621 case IPP_TAG_TEXTLANG
:
1622 case IPP_TAG_NAMELANG
:
1623 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1624 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1625 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1631 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1632 dstval
= dstattr
->values
;
1634 i
--, srcval
++, dstval
++)
1636 dstval
->string
.language
= srcval
->string
.language
;
1637 dstval
->string
.text
= srcval
->string
.text
;
1640 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1642 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1643 dstval
= dstattr
->values
;
1645 i
--, srcval
++, dstval
++)
1647 if (srcval
== srcattr
->values
)
1648 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1650 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1652 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1657 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1658 dstval
= dstattr
->values
;
1660 i
--, srcval
++, dstval
++)
1662 if (srcval
== srcattr
->values
)
1663 dstval
->string
.language
= _cupsStrRetain(srcval
->string
.language
);
1665 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1667 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1672 case IPP_TAG_BEGIN_COLLECTION
:
1673 dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
,
1674 srcattr
->num_values
, NULL
);
1678 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1680 i
--, srcval
++, dstval
++)
1682 dstval
->collection
= srcval
->collection
;
1683 srcval
->collection
->use
++;
1687 case IPP_TAG_STRING
:
1689 /* TODO: Implement quick copy for unknown/octetString values */
1690 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1691 srcattr
->name
, srcattr
->num_values
, NULL
);
1695 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1697 i
--, srcval
++, dstval
++)
1699 dstval
->unknown
.length
= srcval
->unknown
.length
;
1701 if (dstval
->unknown
.length
> 0)
1703 if ((dstval
->unknown
.data
= malloc((size_t)dstval
->unknown
.length
)) == NULL
)
1704 dstval
->unknown
.length
= 0;
1706 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, (size_t)dstval
->unknown
.length
);
1709 break; /* anti-compiler-warning-code */
1717 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1719 * Zero or more attributes are copied from the source IPP message, @code src@, to the
1720 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1721 * reference copy of the attribute is created - this should only be done as long as the
1722 * original source IPP message will not be freed for the life of the destination.
1724 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1725 * attributes that are copied - the function must return 1 to copy the attribute or
1726 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1729 * @since CUPS 1.6/macOS 10.8@
1732 int /* O - 1 on success, 0 on error */
1734 ipp_t
*dst
, /* I - Destination IPP message */
1735 ipp_t
*src
, /* I - Source IPP message */
1736 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1737 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1738 void *context
) /* I - Context pointer */
1740 ipp_attribute_t
*srcattr
; /* Source attribute */
1743 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)", (void *)dst
, (void *)src
, quickcopy
, (void *)cb
, context
));
1746 * Range check input...
1753 * Loop through source attributes and copy as needed...
1756 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1757 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1758 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1766 * 'ippDateToTime()' - Convert from RFC 2579 Date/Time format to time in
1770 time_t /* O - UNIX time value */
1771 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 2579 date info */
1773 struct tm unixdate
; /* UNIX date/time info */
1774 time_t t
; /* Computed time */
1780 memset(&unixdate
, 0, sizeof(unixdate
));
1783 * RFC-2579 date/time format is:
1785 * Byte(s) Description
1786 * ------- -----------
1787 * 0-1 Year (0 to 65535)
1791 * 5 Minutes (0 to 59)
1792 * 6 Seconds (0 to 60, 60 = "leap second")
1793 * 7 Deciseconds (0 to 9)
1795 * 9 UTC hours (0 to 11)
1796 * 10 UTC minutes (0 to 59)
1799 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1800 unixdate
.tm_mon
= date
[2] - 1;
1801 unixdate
.tm_mday
= date
[3];
1802 unixdate
.tm_hour
= date
[4];
1803 unixdate
.tm_min
= date
[5];
1804 unixdate
.tm_sec
= date
[6];
1806 t
= mktime(&unixdate
);
1809 t
+= date
[9] * 3600 + date
[10] * 60;
1811 t
-= date
[9] * 3600 + date
[10] * 60;
1818 * 'ippDelete()' - Delete an IPP message.
1822 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1824 ipp_attribute_t
*attr
, /* Current attribute */
1825 *next
; /* Next attribute */
1828 DEBUG_printf(("ippDelete(ipp=%p)", (void *)ipp
));
1836 DEBUG_printf(("4debug_retain: %p IPP message (use=%d)", (void *)ipp
, ipp
->use
));
1840 DEBUG_printf(("4debug_free: %p IPP message", (void *)ipp
));
1842 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1846 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
));
1848 ipp_free_values(attr
, 0, attr
->num_values
);
1851 _cupsStrFree(attr
->name
);
1861 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1863 * @since CUPS 1.1.19/macOS 10.3@
1868 ipp_t
*ipp
, /* I - IPP message */
1869 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1871 ipp_attribute_t
*current
, /* Current attribute */
1872 *prev
; /* Previous attribute */
1875 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", (void *)ipp
, (void *)attr
, attr
? attr
->name
: "(null)"));
1878 * Range check input...
1884 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
));
1887 * Find the attribute in the list...
1892 for (current
= ipp
->attrs
, prev
= NULL
;
1894 prev
= current
, current
= current
->next
)
1895 if (current
== attr
)
1898 * Found it, remove the attribute from the list...
1902 prev
->next
= current
->next
;
1904 ipp
->attrs
= current
->next
;
1906 if (current
== ipp
->last
)
1917 * Free memory used by the attribute...
1920 ipp_free_values(attr
, 0, attr
->num_values
);
1923 _cupsStrFree(attr
->name
);
1930 * 'ippDeleteValues()' - Delete values in an attribute.
1932 * The @code element@ parameter specifies the first value to delete, starting at
1933 * 0. It must be less than the number of values returned by @link ippGetCount@.
1935 * The @code attr@ parameter may be modified as a result of setting the value.
1937 * Deleting all values in an attribute deletes the attribute.
1939 * @since CUPS 1.6/macOS 10.8@
1942 int /* O - 1 on success, 0 on failure */
1944 ipp_t
*ipp
, /* I - IPP message */
1945 ipp_attribute_t
**attr
, /* IO - Attribute */
1946 int element
, /* I - Index of first value to delete (0-based) */
1947 int count
) /* I - Number of values to delete */
1950 * Range check input...
1953 if (!ipp
|| !attr
|| !*attr
||
1954 element
< 0 || element
>= (*attr
)->num_values
|| count
<= 0 ||
1955 (element
+ count
) >= (*attr
)->num_values
)
1959 * If we are deleting all values, just delete the attribute entirely.
1962 if (count
== (*attr
)->num_values
)
1964 ippDeleteAttribute(ipp
, *attr
);
1970 * Otherwise free the values in question and return.
1973 ipp_free_values(*attr
, element
, count
);
1980 * 'ippFindAttribute()' - Find a named attribute in a request.
1982 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1983 * of attribute and member names separated by slashes, for example
1984 * "media-col/media-size".
1987 ipp_attribute_t
* /* O - Matching attribute */
1988 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
1989 const char *name
, /* I - Name of attribute */
1990 ipp_tag_t type
) /* I - Type of attribute */
1992 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
1998 * Reset the current pointer...
2001 ipp
->current
= NULL
;
2005 * Search for the attribute...
2008 return (ippFindNextAttribute(ipp
, name
, type
));
2013 * 'ippFindNextAttribute()' - Find the next named attribute in a request.
2015 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
2016 * of attribute and member names separated by slashes, for example
2017 * "media-col/media-size".
2020 ipp_attribute_t
* /* O - Matching attribute */
2021 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
2022 const char *name
, /* I - Name of attribute */
2023 ipp_tag_t type
) /* I - Type of attribute */
2025 ipp_attribute_t
*attr
, /* Current atttribute */
2026 *childattr
; /* Child attribute */
2027 ipp_tag_t value_tag
; /* Value tag */
2028 char parent
[1024], /* Parent attribute name */
2029 *child
= NULL
; /* Child attribute name */
2032 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
2037 DEBUG_printf(("3ippFindNextAttribute: atend=%d", ipp
->atend
));
2042 if (strchr(name
, '/'))
2045 * Search for child attribute...
2048 strlcpy(parent
, name
, sizeof(parent
));
2049 if ((child
= strchr(parent
, '/')) == NULL
)
2051 DEBUG_puts("3ippFindNextAttribute: Attribute name too long.");
2057 if (ipp
->current
&& ipp
->current
->name
&& ipp
->current
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&& !strcmp(parent
, ipp
->current
->name
))
2059 while (ipp
->curindex
< ipp
->current
->num_values
)
2061 if ((childattr
= ippFindNextAttribute(ipp
->current
->values
[ipp
->curindex
].collection
, child
, type
)) != NULL
)
2065 if (ipp
->curindex
< ipp
->current
->num_values
&& ipp
->current
->values
[ipp
->curindex
].collection
)
2066 ipp
->current
->values
[ipp
->curindex
].collection
->current
= NULL
;
2069 ipp
->prev
= ipp
->current
;
2070 ipp
->current
= ipp
->current
->next
;
2083 ipp
->current
= ipp
->attrs
;
2088 attr
= ipp
->current
;
2090 else if (ipp
->current
)
2092 ipp
->prev
= ipp
->current
;
2093 attr
= ipp
->current
->next
;
2101 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
2103 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", (void *)attr
, attr
->name
));
2105 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2107 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
2108 (value_tag
== type
|| type
== IPP_TAG_ZERO
|| name
== parent
||
2109 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
2110 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
2112 ipp
->current
= attr
;
2114 if (name
== parent
&& attr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
)
2116 int i
; /* Looping var */
2118 for (i
= 0; i
< attr
->num_values
; i
++)
2120 if ((childattr
= ippFindAttribute(attr
->values
[i
].collection
, child
, type
)) != NULL
)
2122 attr
->values
[0].collection
->curindex
= i
;
2132 ipp
->current
= NULL
;
2141 * 'ippFirstAttribute()' - Return the first attribute in the message.
2143 * @since CUPS 1.6/macOS 10.8@
2146 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
2147 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
2150 * Range check input...
2157 * Return the first attribute...
2160 return (ipp
->current
= ipp
->attrs
);
2165 * 'ippGetBoolean()' - Get a boolean value for an attribute.
2167 * The @code element@ parameter specifies which value to get from 0 to
2168 * @code ippGetCount(attr)@ - 1.
2170 * @since CUPS 1.6/macOS 10.8@
2173 int /* O - Boolean value or 0 on error */
2174 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
2175 int element
) /* I - Value number (0-based) */
2178 * Range check input...
2181 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
2182 element
< 0 || element
>= attr
->num_values
)
2186 * Return the value...
2189 return (attr
->values
[element
].boolean
);
2194 * 'ippGetCollection()' - Get a collection value for an attribute.
2196 * The @code element@ parameter specifies which value to get from 0 to
2197 * @code ippGetCount(attr)@ - 1.
2199 * @since CUPS 1.6/macOS 10.8@
2202 ipp_t
* /* O - Collection value or @code NULL@ on error */
2204 ipp_attribute_t
*attr
, /* I - IPP attribute */
2205 int element
) /* I - Value number (0-based) */
2208 * Range check input...
2211 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
2212 element
< 0 || element
>= attr
->num_values
)
2216 * Return the value...
2219 return (attr
->values
[element
].collection
);
2224 * 'ippGetCount()' - Get the number of values in an attribute.
2226 * @since CUPS 1.6/macOS 10.8@
2229 int /* O - Number of values or 0 on error */
2230 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
2233 * Range check input...
2240 * Return the number of values...
2243 return (attr
->num_values
);
2248 * 'ippGetDate()' - Get a dateTime value for an attribute.
2250 * The @code element@ parameter specifies which value to get from 0 to
2251 * @code ippGetCount(attr)@ - 1.
2253 * @since CUPS 1.6/macOS 10.8@
2256 const ipp_uchar_t
* /* O - dateTime value or @code NULL@ */
2257 ippGetDate(ipp_attribute_t
*attr
, /* I - IPP attribute */
2258 int element
) /* I - Value number (0-based) */
2261 * Range check input...
2264 if (!attr
|| attr
->value_tag
!= IPP_TAG_DATE
||
2265 element
< 0 || element
>= attr
->num_values
)
2269 * Return the value...
2272 return (attr
->values
[element
].date
);
2277 * 'ippGetGroupTag()' - Get the group associated with an attribute.
2279 * @since CUPS 1.6/macOS 10.8@
2282 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
2283 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2286 * Range check input...
2290 return (IPP_TAG_ZERO
);
2293 * Return the group...
2296 return (attr
->group_tag
);
2301 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
2303 * The @code element@ parameter specifies which value to get from 0 to
2304 * @code ippGetCount(attr)@ - 1.
2306 * @since CUPS 1.6/macOS 10.8@
2309 int /* O - Value or 0 on error */
2310 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
2311 int element
) /* I - Value number (0-based) */
2314 * Range check input...
2317 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
2318 element
< 0 || element
>= attr
->num_values
)
2322 * Return the value...
2325 return (attr
->values
[element
].integer
);
2330 * 'ippGetName()' - Get the attribute name.
2332 * @since CUPS 1.6/macOS 10.8@
2335 const char * /* O - Attribute name or @code NULL@ for separators */
2336 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
2339 * Range check input...
2346 * Return the name...
2349 return (attr
->name
);
2354 * 'ippGetOctetString()' - Get an octetString value from an IPP attribute.
2356 * The @code element@ parameter specifies which value to get from 0 to
2357 * @code ippGetCount(attr)@ - 1.
2359 * @since CUPS 1.7/macOS 10.9@
2362 void * /* O - Pointer to octetString data */
2364 ipp_attribute_t
*attr
, /* I - IPP attribute */
2365 int element
, /* I - Value number (0-based) */
2366 int *datalen
) /* O - Length of octetString data */
2369 * Range check input...
2372 if (!attr
|| attr
->value_tag
!= IPP_TAG_STRING
||
2373 element
< 0 || element
>= attr
->num_values
)
2382 * Return the values...
2386 *datalen
= attr
->values
[element
].unknown
.length
;
2388 return (attr
->values
[element
].unknown
.data
);
2393 * 'ippGetOperation()' - Get the operation ID in an IPP message.
2395 * @since CUPS 1.6/macOS 10.8@
2398 ipp_op_t
/* O - Operation ID or 0 on error */
2399 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
2402 * Range check input...
2406 return ((ipp_op_t
)0);
2409 * Return the value...
2412 return (ipp
->request
.op
.operation_id
);
2417 * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
2419 * The @code element@ parameter specifies which value to get from 0 to
2420 * @code ippGetCount(attr)@ - 1.
2422 * @since CUPS 1.6/macOS 10.8@
2425 int /* O - Lower value of range or 0 */
2426 ippGetRange(ipp_attribute_t
*attr
, /* I - IPP attribute */
2427 int element
, /* I - Value number (0-based) */
2428 int *uppervalue
)/* O - Upper value of range */
2431 * Range check input...
2434 if (!attr
|| attr
->value_tag
!= IPP_TAG_RANGE
||
2435 element
< 0 || element
>= attr
->num_values
)
2444 * Return the values...
2448 *uppervalue
= attr
->values
[element
].range
.upper
;
2450 return (attr
->values
[element
].range
.lower
);
2455 * 'ippGetRequestId()' - Get the request ID from an IPP message.
2457 * @since CUPS 1.6/macOS 10.8@
2460 int /* O - Request ID or 0 on error */
2461 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
2464 * Range check input...
2471 * Return the request ID...
2474 return (ipp
->request
.any
.request_id
);
2479 * 'ippGetResolution()' - Get a resolution value for an attribute.
2481 * The @code element@ parameter specifies which value to get from 0 to
2482 * @code ippGetCount(attr)@ - 1.
2484 * @since CUPS 1.6/macOS 10.8@
2487 int /* O - Horizontal/cross feed resolution or 0 */
2489 ipp_attribute_t
*attr
, /* I - IPP attribute */
2490 int element
, /* I - Value number (0-based) */
2491 int *yres
, /* O - Vertical/feed resolution */
2492 ipp_res_t
*units
) /* O - Units for resolution */
2495 * Range check input...
2498 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
2499 element
< 0 || element
>= attr
->num_values
)
2505 *units
= (ipp_res_t
)0;
2511 * Return the value...
2515 *yres
= attr
->values
[element
].resolution
.yres
;
2518 *units
= attr
->values
[element
].resolution
.units
;
2520 return (attr
->values
[element
].resolution
.xres
);
2525 * 'ippGetState()' - Get the IPP message state.
2527 * @since CUPS 1.6/macOS 10.8@
2530 ipp_state_t
/* O - IPP message state value */
2531 ippGetState(ipp_t
*ipp
) /* I - IPP message */
2534 * Range check input...
2538 return (IPP_STATE_IDLE
);
2541 * Return the value...
2544 return (ipp
->state
);
2549 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2551 * @since CUPS 1.6/macOS 10.8@
2554 ipp_status_t
/* O - Status code in IPP message */
2555 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2558 * Range check input...
2562 return (IPP_STATUS_ERROR_INTERNAL
);
2565 * Return the value...
2568 return (ipp
->request
.status
.status_code
);
2573 * 'ippGetString()' - Get the string and optionally the language code for an attribute.
2575 * The @code element@ parameter specifies which value to get from 0 to
2576 * @code ippGetCount(attr)@ - 1.
2578 * @since CUPS 1.6/macOS 10.8@
2582 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2583 int element
, /* I - Value number (0-based) */
2584 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2586 ipp_tag_t tag
; /* Value tag */
2590 * Range check input...
2593 tag
= ippGetValueTag(attr
);
2595 if (!attr
|| element
< 0 || element
>= attr
->num_values
|| (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&& (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
)))
2599 * Return the value...
2603 *language
= attr
->values
[element
].string
.language
;
2605 return (attr
->values
[element
].string
.text
);
2610 * 'ippGetValueTag()' - Get the value tag for an attribute.
2612 * @since CUPS 1.6/macOS 10.8@
2615 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2616 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2619 * Range check input...
2623 return (IPP_TAG_ZERO
);
2626 * Return the value...
2629 return (attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2634 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2636 * @since CUPS 1.6/macOS 10.8@
2639 int /* O - Major version number or 0 on error */
2640 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2641 int *minor
) /* O - Minor version number or @code NULL@ for don't care */
2644 * Range check input...
2656 * Return the value...
2660 *minor
= ipp
->request
.any
.version
[1];
2662 return (ipp
->request
.any
.version
[0]);
2667 * 'ippLength()' - Compute the length of an IPP message.
2670 size_t /* O - Size of IPP message */
2671 ippLength(ipp_t
*ipp
) /* I - IPP message */
2673 return (ipp_length(ipp
, 0));
2678 * 'ippNextAttribute()' - Return the next attribute in the message.
2680 * @since CUPS 1.6/macOS 10.8@
2683 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2684 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2687 * Range check input...
2690 if (!ipp
|| !ipp
->current
)
2694 * Return the next attribute...
2697 return (ipp
->current
= ipp
->current
->next
);
2702 * 'ippNew()' - Allocate a new IPP message.
2705 ipp_t
* /* O - New IPP message */
2708 ipp_t
*temp
; /* New IPP message */
2709 _cups_globals_t
*cg
= _cupsGlobals();
2713 DEBUG_puts("ippNew()");
2715 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2718 * Set default version - usually 2.0...
2721 DEBUG_printf(("4debug_alloc: %p IPP message", (void *)temp
));
2723 if (cg
->server_version
== 0)
2726 temp
->request
.any
.version
[0] = (ipp_uchar_t
)(cg
->server_version
/ 10);
2727 temp
->request
.any
.version
[1] = (ipp_uchar_t
)(cg
->server_version
% 10);
2731 DEBUG_printf(("1ippNew: Returning %p", (void *)temp
));
2738 * 'ippNewRequest()' - Allocate a new IPP request message.
2740 * The new request message is initialized with the "attributes-charset" and
2741 * "attributes-natural-language" attributes added. The
2742 * "attributes-natural-language" value is derived from the current locale.
2744 * @since CUPS 1.2/macOS 10.5@
2747 ipp_t
* /* O - IPP request message */
2748 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2750 ipp_t
*request
; /* IPP request message */
2751 cups_lang_t
*language
; /* Current language localization */
2752 static int request_id
= 0; /* Current request ID */
2753 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2754 /* Mutex for request ID */
2757 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2760 * Create a new IPP message...
2763 if ((request
= ippNew()) == NULL
)
2767 * Set the operation and request ID...
2770 _cupsMutexLock(&request_mutex
);
2772 request
->request
.op
.operation_id
= op
;
2773 request
->request
.op
.request_id
= ++request_id
;
2775 _cupsMutexUnlock(&request_mutex
);
2778 * Use UTF-8 as the character set...
2781 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2782 "attributes-charset", NULL
, "utf-8");
2785 * Get the language from the current locale...
2788 language
= cupsLangDefault();
2790 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2791 "attributes-natural-language", NULL
, language
->language
);
2794 * Return the new request...
2802 * 'ippNewResponse()' - Allocate a new IPP response message.
2804 * The new response message is initialized with the same "version-number",
2805 * "request-id", "attributes-charset", and "attributes-natural-language" as the
2806 * provided request message. If the "attributes-charset" or
2807 * "attributes-natural-language" attributes are missing from the request,
2808 * 'utf-8' and a value derived from the current locale are substituted,
2811 * @since CUPS 1.7/macOS 10.9@
2814 ipp_t
* /* O - IPP response message */
2815 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2817 ipp_t
*response
; /* IPP response message */
2818 ipp_attribute_t
*attr
; /* Current attribute */
2822 * Range check input...
2829 * Create a new IPP message...
2832 if ((response
= ippNew()) == NULL
)
2836 * Copy the request values over to the response...
2839 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2840 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2841 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2844 * The first attribute MUST be attributes-charset...
2847 attr
= request
->attrs
;
2849 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2850 attr
->group_tag
== IPP_TAG_OPERATION
&&
2851 attr
->value_tag
== IPP_TAG_CHARSET
&&
2852 attr
->num_values
== 1)
2855 * Copy charset from request...
2858 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2859 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2864 * Use "utf-8" as the default...
2867 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2868 "attributes-charset", NULL
, "utf-8");
2872 * Then attributes-natural-language...
2878 if (attr
&& attr
->name
&&
2879 !strcmp(attr
->name
, "attributes-natural-language") &&
2880 attr
->group_tag
== IPP_TAG_OPERATION
&&
2881 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2882 attr
->num_values
== 1)
2885 * Copy language from request...
2888 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2889 "attributes-natural-language", NULL
,
2890 attr
->values
[0].string
.text
);
2895 * Use the language from the current locale...
2898 cups_lang_t
*language
= cupsLangDefault();
2899 /* Current locale */
2901 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2902 "attributes-natural-language", NULL
, language
->language
);
2910 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2913 ipp_state_t
/* O - Current state */
2914 ippRead(http_t
*http
, /* I - HTTP connection */
2915 ipp_t
*ipp
) /* I - IPP data */
2917 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
, (void *)http
, (void *)ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2920 return (IPP_STATE_ERROR
);
2922 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
, http
->used
));
2924 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2930 * 'ippReadFile()' - Read data for an IPP message from a file.
2932 * @since CUPS 1.1.19/macOS 10.3@
2935 ipp_state_t
/* O - Current state */
2936 ippReadFile(int fd
, /* I - HTTP data */
2937 ipp_t
*ipp
) /* I - IPP data */
2939 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
2941 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2946 * 'ippReadIO()' - Read data for an IPP message.
2948 * @since CUPS 1.2/macOS 10.5@
2951 ipp_state_t
/* O - Current state */
2952 ippReadIO(void *src
, /* I - Data source */
2953 ipp_iocb_t cb
, /* I - Read callback function */
2954 int blocking
, /* I - Use blocking IO? */
2955 ipp_t
*parent
, /* I - Parent request, if any */
2956 ipp_t
*ipp
) /* I - IPP data */
2958 int n
; /* Length of data */
2959 unsigned char *buffer
, /* Data buffer */
2960 string
[IPP_MAX_TEXT
],
2961 /* Small string buffer */
2962 *bufptr
; /* Pointer into buffer */
2963 ipp_attribute_t
*attr
; /* Current attribute */
2964 ipp_tag_t tag
; /* Current tag */
2965 ipp_tag_t value_tag
; /* Current value tag */
2966 _ipp_value_t
*value
; /* Current value */
2969 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)src
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
2970 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_STATE_ERROR
));
2973 return (IPP_STATE_ERROR
);
2975 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2977 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2978 return (IPP_STATE_ERROR
);
2983 case IPP_STATE_IDLE
:
2984 ipp
->state
++; /* Avoid common problem... */
2986 case IPP_STATE_HEADER
:
2990 * Get the request header...
2993 if ((*cb
)(src
, buffer
, 8) < 8)
2995 DEBUG_puts("1ippReadIO: Unable to read header.");
2996 _cupsBufferRelease((char *)buffer
);
2997 return (IPP_STATE_ERROR
);
3001 * Then copy the request header over...
3004 ipp
->request
.any
.version
[0] = buffer
[0];
3005 ipp
->request
.any
.version
[1] = buffer
[1];
3006 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
3007 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
3008 buffer
[6]) << 8) | buffer
[7];
3010 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
3011 DEBUG_printf(("2ippReadIO: op_status=%04x",
3012 ipp
->request
.any
.op_status
));
3013 DEBUG_printf(("2ippReadIO: request_id=%d",
3014 ipp
->request
.any
.request_id
));
3017 ipp
->state
= IPP_STATE_ATTRIBUTE
;
3018 ipp
->current
= NULL
;
3019 ipp
->curtag
= IPP_TAG_ZERO
;
3020 ipp
->prev
= ipp
->last
;
3023 * If blocking is disabled, stop here...
3029 case IPP_STATE_ATTRIBUTE
:
3032 if ((*cb
)(src
, buffer
, 1) < 1)
3034 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3035 _cupsBufferRelease((char *)buffer
);
3036 return (IPP_STATE_ERROR
);
3039 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3042 * Read this attribute...
3045 tag
= (ipp_tag_t
)buffer
[0];
3046 if (tag
== IPP_TAG_EXTENSION
)
3049 * Read 32-bit "extension" tag...
3052 if ((*cb
)(src
, buffer
, 4) < 1)
3054 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3055 _cupsBufferRelease((char *)buffer
);
3056 return (IPP_STATE_ERROR
);
3059 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
3060 buffer
[2]) << 8) | buffer
[3]);
3062 if (tag
& IPP_TAG_CUPS_CONST
)
3065 * Fail if the high bit is set in the tag...
3068 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
3069 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
3070 _cupsBufferRelease((char *)buffer
);
3071 return (IPP_STATE_ERROR
);
3075 if (tag
== IPP_TAG_END
)
3078 * No more attributes left...
3081 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
3083 ipp
->state
= IPP_STATE_DATA
;
3086 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3089 * Group tag... Set the current group and continue...
3092 if (ipp
->curtag
== tag
)
3093 ipp
->prev
= ippAddSeparator(ipp
);
3094 else if (ipp
->current
)
3095 ipp
->prev
= ipp
->current
;
3098 ipp
->current
= NULL
;
3099 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
, ippTagString(tag
), (void *)ipp
->prev
));
3103 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3104 ippTagString(tag
)));
3110 if ((*cb
)(src
, buffer
, 2) < 2)
3112 DEBUG_puts("1ippReadIO: unable to read name length.");
3113 _cupsBufferRelease((char *)buffer
);
3114 return (IPP_STATE_ERROR
);
3117 n
= (buffer
[0] << 8) | buffer
[1];
3119 if (n
>= IPP_BUF_SIZE
)
3121 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3122 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3123 _cupsBufferRelease((char *)buffer
);
3124 return (IPP_STATE_ERROR
);
3127 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3129 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3130 tag
!= IPP_TAG_END_COLLECTION
)
3133 * More values for current attribute...
3136 if (ipp
->current
== NULL
)
3138 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3139 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3140 _cupsBufferRelease((char *)buffer
);
3141 return (IPP_STATE_ERROR
);
3144 attr
= ipp
->current
;
3145 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3148 * Make sure we aren't adding a new value of a different
3152 if (value_tag
== IPP_TAG_ZERO
)
3155 * Setting the value of a collection member...
3158 attr
->value_tag
= tag
;
3160 else if (value_tag
== IPP_TAG_TEXTLANG
||
3161 value_tag
== IPP_TAG_NAMELANG
||
3162 (value_tag
>= IPP_TAG_TEXT
&&
3163 value_tag
<= IPP_TAG_MIMETYPE
))
3166 * String values can sometimes come across in different
3167 * forms; accept sets of differing values...
3170 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3171 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3172 tag
!= IPP_TAG_NOVALUE
)
3174 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3175 _("IPP 1setOf attribute with incompatible value "
3177 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3178 value_tag
, ippTagString(value_tag
), tag
,
3179 ippTagString(tag
)));
3180 _cupsBufferRelease((char *)buffer
);
3181 return (IPP_STATE_ERROR
);
3184 if (value_tag
!= tag
)
3186 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3187 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3188 ippSetValueTag(ipp
, &attr
, tag
);
3191 else if (value_tag
== IPP_TAG_INTEGER
||
3192 value_tag
== IPP_TAG_RANGE
)
3195 * Integer and rangeOfInteger values can sometimes be mixed; accept
3196 * sets of differing values...
3199 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3201 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3202 _("IPP 1setOf attribute with incompatible value "
3204 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3205 value_tag
, ippTagString(value_tag
), tag
,
3206 ippTagString(tag
)));
3207 _cupsBufferRelease((char *)buffer
);
3208 return (IPP_STATE_ERROR
);
3211 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3214 * Convert integer values to rangeOfInteger values...
3217 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3218 "rangeOfInteger.", attr
->name
));
3219 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3222 else if (value_tag
!= tag
)
3224 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3225 _("IPP 1setOf attribute with incompatible value "
3227 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3228 value_tag
, ippTagString(value_tag
), tag
,
3229 ippTagString(tag
)));
3230 _cupsBufferRelease((char *)buffer
);
3231 return (IPP_STATE_ERROR
);
3235 * Finally, reallocate the attribute array as needed...
3238 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3240 _cupsBufferRelease((char *)buffer
);
3241 return (IPP_STATE_ERROR
);
3244 else if (tag
== IPP_TAG_MEMBERNAME
)
3247 * Name must be length 0!
3252 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3253 DEBUG_puts("1ippReadIO: member name not empty.");
3254 _cupsBufferRelease((char *)buffer
);
3255 return (IPP_STATE_ERROR
);
3259 ipp
->prev
= ipp
->current
;
3261 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3264 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3265 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3266 _cupsBufferRelease((char *)buffer
);
3267 return (IPP_STATE_ERROR
);
3270 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3272 value
= attr
->values
;
3274 else if (tag
!= IPP_TAG_END_COLLECTION
)
3277 * New attribute; read the name and add it...
3280 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3282 DEBUG_puts("1ippReadIO: unable to read name.");
3283 _cupsBufferRelease((char *)buffer
);
3284 return (IPP_STATE_ERROR
);
3290 ipp
->prev
= ipp
->current
;
3292 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3295 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3296 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3297 _cupsBufferRelease((char *)buffer
);
3298 return (IPP_STATE_ERROR
);
3301 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer
, (void *)ipp
->current
, (void *)ipp
->prev
));
3303 value
= attr
->values
;
3311 if ((*cb
)(src
, buffer
, 2) < 2)
3313 DEBUG_puts("1ippReadIO: unable to read value length.");
3314 _cupsBufferRelease((char *)buffer
);
3315 return (IPP_STATE_ERROR
);
3318 n
= (buffer
[0] << 8) | buffer
[1];
3319 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3321 if (n
>= IPP_BUF_SIZE
)
3323 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3324 _("IPP value larger than 32767 bytes."), 1);
3325 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3326 _cupsBufferRelease((char *)buffer
);
3327 return (IPP_STATE_ERROR
);
3332 case IPP_TAG_INTEGER
:
3336 if (tag
== IPP_TAG_INTEGER
)
3337 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3338 _("IPP integer value not 4 bytes."), 1);
3340 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3341 _("IPP enum value not 4 bytes."), 1);
3342 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3343 _cupsBufferRelease((char *)buffer
);
3344 return (IPP_STATE_ERROR
);
3347 if ((*cb
)(src
, buffer
, 4) < 4)
3349 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3350 _cupsBufferRelease((char *)buffer
);
3351 return (IPP_STATE_ERROR
);
3354 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3357 if (attr
->value_tag
== IPP_TAG_RANGE
)
3358 value
->range
.lower
= value
->range
.upper
= n
;
3363 case IPP_TAG_BOOLEAN
:
3366 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3368 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3369 _cupsBufferRelease((char *)buffer
);
3370 return (IPP_STATE_ERROR
);
3373 if ((*cb
)(src
, buffer
, 1) < 1)
3375 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3376 _cupsBufferRelease((char *)buffer
);
3377 return (IPP_STATE_ERROR
);
3380 value
->boolean
= (char)buffer
[0];
3383 case IPP_TAG_NOVALUE
:
3384 case IPP_TAG_NOTSETTABLE
:
3385 case IPP_TAG_DELETEATTR
:
3386 case IPP_TAG_ADMINDEFINE
:
3388 * These value types are not supposed to have values, however
3389 * some vendors (Brother) do not implement IPP correctly and so
3390 * we need to map non-empty values to text...
3393 if (attr
->value_tag
== tag
)
3398 attr
->value_tag
= IPP_TAG_TEXT
;
3403 case IPP_TAG_KEYWORD
:
3405 case IPP_TAG_URISCHEME
:
3406 case IPP_TAG_CHARSET
:
3407 case IPP_TAG_LANGUAGE
:
3408 case IPP_TAG_MIMETYPE
:
3411 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3413 DEBUG_puts("1ippReadIO: unable to read string value.");
3414 _cupsBufferRelease((char *)buffer
);
3415 return (IPP_STATE_ERROR
);
3420 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3421 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3427 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3428 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3429 _cupsBufferRelease((char *)buffer
);
3430 return (IPP_STATE_ERROR
);
3433 if ((*cb
)(src
, value
->date
, 11) < 11)
3435 DEBUG_puts("1ippReadIO: Unable to read date value.");
3436 _cupsBufferRelease((char *)buffer
);
3437 return (IPP_STATE_ERROR
);
3441 case IPP_TAG_RESOLUTION
:
3444 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3445 _("IPP resolution value not 9 bytes."), 1);
3446 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3447 _cupsBufferRelease((char *)buffer
);
3448 return (IPP_STATE_ERROR
);
3451 if ((*cb
)(src
, buffer
, 9) < 9)
3453 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3454 _cupsBufferRelease((char *)buffer
);
3455 return (IPP_STATE_ERROR
);
3458 value
->resolution
.xres
=
3459 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3461 value
->resolution
.yres
=
3462 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3464 value
->resolution
.units
=
3465 (ipp_res_t
)buffer
[8];
3468 case IPP_TAG_RANGE
:
3471 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3472 _("IPP rangeOfInteger value not 8 bytes."), 1);
3473 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3475 _cupsBufferRelease((char *)buffer
);
3476 return (IPP_STATE_ERROR
);
3479 if ((*cb
)(src
, buffer
, 8) < 8)
3481 DEBUG_puts("1ippReadIO: Unable to read range value.");
3482 _cupsBufferRelease((char *)buffer
);
3483 return (IPP_STATE_ERROR
);
3486 value
->range
.lower
=
3487 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3489 value
->range
.upper
=
3490 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3494 case IPP_TAG_TEXTLANG
:
3495 case IPP_TAG_NAMELANG
:
3498 if (tag
== IPP_TAG_TEXTLANG
)
3499 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3500 _("IPP textWithLanguage value less than "
3501 "minimum 4 bytes."), 1);
3503 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3504 _("IPP nameWithLanguage value less than "
3505 "minimum 4 bytes."), 1);
3506 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3508 _cupsBufferRelease((char *)buffer
);
3509 return (IPP_STATE_ERROR
);
3512 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3514 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3516 _cupsBufferRelease((char *)buffer
);
3517 return (IPP_STATE_ERROR
);
3523 * text-with-language and name-with-language are composite
3532 n
= (bufptr
[0] << 8) | bufptr
[1];
3534 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) || n
>= (int)sizeof(string
))
3536 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3537 _("IPP language length overflows value."), 1);
3538 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3540 _cupsBufferRelease((char *)buffer
);
3541 return (IPP_STATE_ERROR
);
3543 else if (n
>= IPP_MAX_LANGUAGE
)
3545 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3546 _("IPP language length too large."), 1);
3547 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3549 _cupsBufferRelease((char *)buffer
);
3550 return (IPP_STATE_ERROR
);
3553 memcpy(string
, bufptr
+ 2, (size_t)n
);
3556 value
->string
.language
= _cupsStrAlloc((char *)string
);
3559 n
= (bufptr
[0] << 8) | bufptr
[1];
3561 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3563 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3564 _("IPP string length overflows value."), 1);
3565 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3566 _cupsBufferRelease((char *)buffer
);
3567 return (IPP_STATE_ERROR
);
3570 bufptr
[2 + n
] = '\0';
3571 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3574 case IPP_TAG_BEGIN_COLLECTION
:
3576 * Oh, boy, here comes a collection value, so read it...
3579 value
->collection
= ippNew();
3583 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3584 _("IPP begCollection value not 0 bytes."), 1);
3585 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3587 _cupsBufferRelease((char *)buffer
);
3588 return (IPP_STATE_ERROR
);
3591 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3593 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3594 _cupsBufferRelease((char *)buffer
);
3595 return (IPP_STATE_ERROR
);
3599 case IPP_TAG_END_COLLECTION
:
3600 _cupsBufferRelease((char *)buffer
);
3604 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3605 _("IPP endCollection value not 0 bytes."), 1);
3606 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3608 return (IPP_STATE_ERROR
);
3611 DEBUG_puts("1ippReadIO: endCollection tag...");
3612 return (ipp
->state
= IPP_STATE_DATA
);
3614 case IPP_TAG_MEMBERNAME
:
3616 * The value the name of the member in the collection, which
3617 * we need to carry over...
3622 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3623 _("IPP memberName with no attribute."), 1);
3624 DEBUG_puts("1ippReadIO: Member name without attribute.");
3625 _cupsBufferRelease((char *)buffer
);
3626 return (IPP_STATE_ERROR
);
3630 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3631 _("IPP memberName value is empty."), 1);
3632 DEBUG_puts("1ippReadIO: Empty member name value.");
3633 _cupsBufferRelease((char *)buffer
);
3634 return (IPP_STATE_ERROR
);
3636 else if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3638 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3639 _cupsBufferRelease((char *)buffer
);
3640 return (IPP_STATE_ERROR
);
3644 attr
->name
= _cupsStrAlloc((char *)buffer
);
3647 * Since collection members are encoded differently than
3648 * regular attributes, make sure we don't start with an
3652 attr
->num_values
--;
3654 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3657 default : /* Other unsupported values */
3658 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3660 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3661 _("IPP octetString length too large."), 1);
3662 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3664 _cupsBufferRelease((char *)buffer
);
3665 return (IPP_STATE_ERROR
);
3668 value
->unknown
.length
= n
;
3672 if ((value
->unknown
.data
= malloc((size_t)n
)) == NULL
)
3674 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3675 DEBUG_puts("1ippReadIO: Unable to allocate value");
3676 _cupsBufferRelease((char *)buffer
);
3677 return (IPP_STATE_ERROR
);
3680 if ((*cb
)(src
, value
->unknown
.data
, (size_t)n
) < n
)
3682 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3683 _cupsBufferRelease((char *)buffer
);
3684 return (IPP_STATE_ERROR
);
3688 value
->unknown
.data
= NULL
;
3693 * If blocking is disabled, stop here...
3701 case IPP_STATE_DATA
:
3705 break; /* anti-compiler-warning-code */
3708 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3709 _cupsBufferRelease((char *)buffer
);
3711 return (ipp
->state
);
3716 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3718 * The @code ipp@ parameter refers to an IPP message previously created using
3719 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3721 * The @code attr@ parameter may be modified as a result of setting the value.
3723 * The @code element@ parameter specifies which value to set from 0 to
3724 * @code ippGetCount(attr)@.
3726 * @since CUPS 1.6/macOS 10.8@
3729 int /* O - 1 on success, 0 on failure */
3730 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3731 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3732 int element
, /* I - Value number (0-based) */
3733 int boolvalue
)/* I - Boolean value */
3735 _ipp_value_t
*value
; /* Current value */
3739 * Range check input...
3742 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3743 element
< 0 || element
> (*attr
)->num_values
)
3747 * Set the value and return...
3750 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3751 value
->boolean
= (char)boolvalue
;
3753 return (value
!= NULL
);
3758 * 'ippSetCollection()' - Set a collection value in an attribute.
3760 * The @code ipp@ parameter refers to an IPP message previously created using
3761 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3763 * The @code attr@ parameter may be modified as a result of setting the value.
3765 * The @code element@ parameter specifies which value to set from 0 to
3766 * @code ippGetCount(attr)@.
3768 * @since CUPS 1.6/macOS 10.8@
3771 int /* O - 1 on success, 0 on failure */
3773 ipp_t
*ipp
, /* I - IPP message */
3774 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3775 int element
, /* I - Value number (0-based) */
3776 ipp_t
*colvalue
) /* I - Collection value */
3778 _ipp_value_t
*value
; /* Current value */
3782 * Range check input...
3785 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3786 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3790 * Set the value and return...
3793 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3795 if (value
->collection
)
3796 ippDelete(value
->collection
);
3798 value
->collection
= colvalue
;
3802 return (value
!= NULL
);
3807 * 'ippSetDate()' - Set a dateTime value in an attribute.
3809 * The @code ipp@ parameter refers to an IPP message previously created using
3810 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3812 * The @code attr@ parameter may be modified as a result of setting the value.
3814 * The @code element@ parameter specifies which value to set from 0 to
3815 * @code ippGetCount(attr)@.
3817 * @since CUPS 1.6/macOS 10.8@
3820 int /* O - 1 on success, 0 on failure */
3821 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3822 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3823 int element
, /* I - Value number (0-based) */
3824 const ipp_uchar_t
*datevalue
)/* I - dateTime value */
3826 _ipp_value_t
*value
; /* Current value */
3830 * Range check input...
3833 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3834 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3838 * Set the value and return...
3841 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3842 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3844 return (value
!= NULL
);
3849 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3851 * The @code ipp@ parameter refers to an IPP message previously created using
3852 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3854 * The @code attr@ parameter may be modified as a result of setting the value.
3856 * The @code group@ parameter specifies the IPP attribute group tag: none
3857 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3858 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3859 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3860 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3862 * @since CUPS 1.6/macOS 10.8@
3865 int /* O - 1 on success, 0 on failure */
3867 ipp_t
*ipp
, /* I - IPP message */
3868 ipp_attribute_t
**attr
, /* IO - Attribute */
3869 ipp_tag_t group_tag
) /* I - Group tag */
3872 * Range check input - group tag must be 0x01 to 0x0F, per RFC 8011...
3875 if (!ipp
|| !attr
|| !*attr
||
3876 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3877 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3881 * Set the group tag and return...
3884 (*attr
)->group_tag
= group_tag
;
3891 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3893 * The @code ipp@ parameter refers to an IPP message previously created using
3894 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3896 * The @code attr@ parameter may be modified as a result of setting the value.
3898 * The @code element@ parameter specifies which value to set from 0 to
3899 * @code ippGetCount(attr)@.
3901 * @since CUPS 1.6/macOS 10.8@
3904 int /* O - 1 on success, 0 on failure */
3905 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3906 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3907 int element
, /* I - Value number (0-based) */
3908 int intvalue
) /* I - Integer/enum value */
3910 _ipp_value_t
*value
; /* Current value */
3914 * Range check input...
3917 if (!ipp
|| !attr
|| !*attr
||
3918 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3919 element
< 0 || element
> (*attr
)->num_values
)
3923 * Set the value and return...
3926 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3927 value
->integer
= intvalue
;
3929 return (value
!= NULL
);
3934 * 'ippSetName()' - Set the name of an attribute.
3936 * The @code ipp@ parameter refers to an IPP message previously created using
3937 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3939 * The @code attr@ parameter may be modified as a result of setting the value.
3941 * @since CUPS 1.6/macOS 10.8@
3944 int /* O - 1 on success, 0 on failure */
3945 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3946 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3947 const char *name
) /* I - Attribute name */
3949 char *temp
; /* Temporary name value */
3953 * Range check input...
3956 if (!ipp
|| !attr
|| !*attr
)
3960 * Set the value and return...
3963 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3966 _cupsStrFree((*attr
)->name
);
3968 (*attr
)->name
= temp
;
3971 return (temp
!= NULL
);
3976 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
3978 * The @code ipp@ parameter refers to an IPP message previously created using
3979 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3981 * The @code attr@ parameter may be modified as a result of setting the value.
3983 * The @code element@ parameter specifies which value to set from 0 to
3984 * @code ippGetCount(attr)@.
3986 * @since CUPS 1.7/macOS 10.9@
3989 int /* O - 1 on success, 0 on failure */
3991 ipp_t
*ipp
, /* I - IPP message */
3992 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3993 int element
, /* I - Value number (0-based) */
3994 const void *data
, /* I - Pointer to octetString data */
3995 int datalen
) /* I - Length of octetString data */
3997 _ipp_value_t
*value
; /* Current value */
4001 * Range check input...
4004 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_STRING
||
4005 element
< 0 || element
> (*attr
)->num_values
||
4006 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
4010 * Set the value and return...
4013 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4015 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4018 * Just copy the pointer...
4021 value
->unknown
.data
= (void *)data
;
4022 value
->unknown
.length
= datalen
;
4030 if (value
->unknown
.data
)
4033 * Free previous data...
4036 free(value
->unknown
.data
);
4038 value
->unknown
.data
= NULL
;
4039 value
->unknown
.length
= 0;
4044 void *temp
; /* Temporary data pointer */
4046 if ((temp
= malloc((size_t)datalen
)) != NULL
)
4048 memcpy(temp
, data
, (size_t)datalen
);
4050 value
->unknown
.data
= temp
;
4051 value
->unknown
.length
= datalen
;
4059 return (value
!= NULL
);
4064 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
4066 * The @code ipp@ parameter refers to an IPP message previously created using
4067 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4069 * @since CUPS 1.6/macOS 10.8@
4072 int /* O - 1 on success, 0 on failure */
4073 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
4074 ipp_op_t op
) /* I - Operation ID */
4077 * Range check input...
4084 * Set the operation and return...
4087 ipp
->request
.op
.operation_id
= op
;
4094 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4096 * The @code ipp@ parameter refers to an IPP message previously created using
4097 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4099 * The @code attr@ parameter may be modified as a result of setting the value.
4101 * The @code element@ parameter specifies which value to set from 0 to
4102 * @code ippGetCount(attr)@.
4104 * @since CUPS 1.6/macOS 10.8@
4107 int /* O - 1 on success, 0 on failure */
4108 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4109 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4110 int element
, /* I - Value number (0-based) */
4111 int lowervalue
, /* I - Lower bound for range */
4112 int uppervalue
) /* I - Upper bound for range */
4114 _ipp_value_t
*value
; /* Current value */
4118 * Range check input...
4121 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4122 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4126 * Set the value and return...
4129 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4131 value
->range
.lower
= lowervalue
;
4132 value
->range
.upper
= uppervalue
;
4135 return (value
!= NULL
);
4140 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4142 * The @code ipp@ parameter refers to an IPP message previously created using
4143 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4145 * The @code request_id@ parameter must be greater than 0.
4147 * @since CUPS 1.6/macOS 10.8@
4150 int /* O - 1 on success, 0 on failure */
4151 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4152 int request_id
) /* I - Request ID */
4155 * Range check input; not checking request_id values since ipptool wants to send
4156 * invalid values for conformance testing and a bad request_id does not affect the
4157 * encoding of a message...
4164 * Set the request ID and return...
4167 ipp
->request
.any
.request_id
= request_id
;
4174 * 'ippSetResolution()' - Set a resolution value in an attribute.
4176 * The @code ipp@ parameter refers to an IPP message previously created using
4177 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4179 * The @code attr@ parameter may be modified as a result of setting the value.
4181 * The @code element@ parameter specifies which value to set from 0 to
4182 * @code ippGetCount(attr)@.
4184 * @since CUPS 1.6/macOS 10.8@
4187 int /* O - 1 on success, 0 on failure */
4189 ipp_t
*ipp
, /* I - IPP message */
4190 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4191 int element
, /* I - Value number (0-based) */
4192 ipp_res_t unitsvalue
, /* I - Resolution units */
4193 int xresvalue
, /* I - Horizontal/cross feed resolution */
4194 int yresvalue
) /* I - Vertical/feed resolution */
4196 _ipp_value_t
*value
; /* Current value */
4200 * Range check input...
4203 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4204 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4205 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4209 * Set the value and return...
4212 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4214 value
->resolution
.units
= unitsvalue
;
4215 value
->resolution
.xres
= xresvalue
;
4216 value
->resolution
.yres
= yresvalue
;
4219 return (value
!= NULL
);
4224 * 'ippSetState()' - Set the current state of the IPP message.
4226 * @since CUPS 1.6/macOS 10.8@
4229 int /* O - 1 on success, 0 on failure */
4230 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4231 ipp_state_t state
) /* I - IPP state value */
4234 * Range check input...
4241 * Set the state and return...
4245 ipp
->current
= NULL
;
4252 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4254 * The @code ipp@ parameter refers to an IPP message previously created using
4255 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4257 * @since CUPS 1.6/macOS 10.8@
4260 int /* O - 1 on success, 0 on failure */
4261 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4262 ipp_status_t status
) /* I - Status code */
4265 * Range check input...
4272 * Set the status code and return...
4275 ipp
->request
.status
.status_code
= status
;
4282 * 'ippSetString()' - Set a string value in an attribute.
4284 * The @code ipp@ parameter refers to an IPP message previously created using
4285 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4287 * The @code attr@ parameter may be modified as a result of setting the value.
4289 * The @code element@ parameter specifies which value to set from 0 to
4290 * @code ippGetCount(attr)@.
4292 * @since CUPS 1.6/macOS 10.8@
4295 int /* O - 1 on success, 0 on failure */
4296 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4297 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4298 int element
, /* I - Value number (0-based) */
4299 const char *strvalue
) /* I - String value */
4301 char *temp
; /* Temporary string */
4302 _ipp_value_t
*value
; /* Current value */
4306 * Range check input...
4309 if (!ipp
|| !attr
|| !*attr
||
4310 ((*attr
)->value_tag
!= IPP_TAG_TEXTLANG
&&
4311 (*attr
)->value_tag
!= IPP_TAG_NAMELANG
&&
4312 ((*attr
)->value_tag
< IPP_TAG_TEXT
||
4313 (*attr
)->value_tag
> IPP_TAG_MIMETYPE
)) ||
4314 element
< 0 || element
> (*attr
)->num_values
|| !strvalue
)
4318 * Set the value and return...
4321 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4324 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4326 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4327 value
->string
.text
= (char *)strvalue
;
4328 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4330 if (value
->string
.text
)
4331 _cupsStrFree(value
->string
.text
);
4333 value
->string
.text
= temp
;
4339 return (value
!= NULL
);
4344 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4346 * The @code ipp@ parameter refers to an IPP message previously created using
4347 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4349 * The @code attr@ parameter may be modified as a result of setting the value.
4351 * The @code element@ parameter specifies which value to set from 0 to
4352 * @code ippGetCount(attr)@.
4354 * The @code format@ parameter uses formatting characters compatible with the
4355 * printf family of standard functions. Additional arguments follow it as
4356 * needed. The formatted string is truncated as needed to the maximum length of
4357 * the corresponding value type.
4359 * @since CUPS 1.7/macOS 10.9@
4362 int /* O - 1 on success, 0 on failure */
4363 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4364 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4365 int element
, /* I - Value number (0-based) */
4366 const char *format
, /* I - Printf-style format string */
4367 ...) /* I - Additional arguments as needed */
4369 int ret
; /* Return value */
4370 va_list ap
; /* Pointer to additional arguments */
4373 va_start(ap
, format
);
4374 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4382 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4384 * The @code ipp@ parameter refers to an IPP message previously created using
4385 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4387 * The @code attr@ parameter may be modified as a result of setting the value.
4389 * The @code element@ parameter specifies which value to set from 0 to
4390 * @code ippGetCount(attr)@.
4392 * The @code format@ parameter uses formatting characters compatible with the
4393 * printf family of standard functions. Additional arguments follow it as
4394 * needed. The formatted string is truncated as needed to the maximum length of
4395 * the corresponding value type.
4397 * @since CUPS 1.7/macOS 10.9@
4400 int /* O - 1 on success, 0 on failure */
4401 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4402 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4403 int element
, /* I - Value number (0-based) */
4404 const char *format
, /* I - Printf-style format string */
4405 va_list ap
) /* I - Pointer to additional arguments */
4407 ipp_tag_t value_tag
; /* Value tag */
4408 char buffer
[IPP_MAX_TEXT
+ 4];
4409 /* Formatted text string */
4410 ssize_t bytes
, /* Length of formatted value */
4411 max_bytes
; /* Maximum number of bytes for value */
4415 * Range check input...
4419 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4421 value_tag
= IPP_TAG_ZERO
;
4423 if (!ipp
|| !attr
|| !*attr
||
4424 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4425 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4430 * Format the string...
4433 if (!strcmp(format
, "%s"))
4436 * Optimize the simple case...
4439 const char *s
= va_arg(ap
, char *);
4444 bytes
= (ssize_t
)strlen(s
);
4445 strlcpy(buffer
, s
, sizeof(buffer
));
4450 * Do a full formatting of the message...
4453 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4458 * Limit the length of the string...
4465 case IPP_TAG_TEXTLANG
:
4466 max_bytes
= IPP_MAX_TEXT
;
4470 case IPP_TAG_NAMELANG
:
4471 max_bytes
= IPP_MAX_NAME
;
4474 case IPP_TAG_CHARSET
:
4475 max_bytes
= IPP_MAX_CHARSET
;
4478 case IPP_TAG_KEYWORD
:
4479 max_bytes
= IPP_MAX_KEYWORD
;
4482 case IPP_TAG_LANGUAGE
:
4483 max_bytes
= IPP_MAX_LANGUAGE
;
4486 case IPP_TAG_MIMETYPE
:
4487 max_bytes
= IPP_MAX_MIMETYPE
;
4491 max_bytes
= IPP_MAX_URI
;
4494 case IPP_TAG_URISCHEME
:
4495 max_bytes
= IPP_MAX_URISCHEME
;
4499 if (bytes
>= max_bytes
)
4501 char *bufmax
, /* Buffer at max_bytes */
4502 *bufptr
; /* Pointer into buffer */
4504 bufptr
= buffer
+ strlen(buffer
) - 1;
4505 bufmax
= buffer
+ max_bytes
- 1;
4507 while (bufptr
> bufmax
)
4511 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4522 * Set the formatted string and return...
4525 return (ippSetString(ipp
, attr
, element
, buffer
));
4530 * 'ippSetValueTag()' - Set the value tag of an attribute.
4532 * The @code ipp@ parameter refers to an IPP message previously created using
4533 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4535 * The @code attr@ parameter may be modified as a result of setting the value.
4537 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4538 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4539 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4540 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4541 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4542 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4545 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4546 * code in the "attributes-natural-language" attribute or, if not present, the language
4547 * code for the current locale.
4549 * @since CUPS 1.6/macOS 10.8@
4552 int /* O - 1 on success, 0 on failure */
4554 ipp_t
*ipp
, /* I - IPP message */
4555 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4556 ipp_tag_t value_tag
) /* I - Value tag */
4558 int i
; /* Looping var */
4559 _ipp_value_t
*value
; /* Current value */
4560 int integer
; /* Current integer value */
4561 cups_lang_t
*language
; /* Current language */
4562 char code
[32]; /* Language code */
4563 ipp_tag_t temp_tag
; /* Temporary value tag */
4567 * Range check input...
4570 if (!ipp
|| !attr
|| !*attr
)
4574 * If there is no change, return immediately...
4577 if (value_tag
== (*attr
)->value_tag
)
4581 * Otherwise implement changes as needed...
4584 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4588 case IPP_TAG_UNSUPPORTED_VALUE
:
4589 case IPP_TAG_DEFAULT
:
4590 case IPP_TAG_UNKNOWN
:
4591 case IPP_TAG_NOVALUE
:
4592 case IPP_TAG_NOTSETTABLE
:
4593 case IPP_TAG_DELETEATTR
:
4594 case IPP_TAG_ADMINDEFINE
:
4596 * Free any existing values...
4599 if ((*attr
)->num_values
> 0)
4600 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4603 * Set out-of-band value...
4606 (*attr
)->value_tag
= value_tag
;
4609 case IPP_TAG_RANGE
:
4610 if (temp_tag
!= IPP_TAG_INTEGER
)
4613 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4617 integer
= value
->integer
;
4618 value
->range
.lower
= value
->range
.upper
= integer
;
4621 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4625 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4626 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4627 temp_tag
!= IPP_TAG_MIMETYPE
)
4630 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4633 case IPP_TAG_NAMELANG
:
4634 case IPP_TAG_TEXTLANG
:
4635 if (value_tag
== IPP_TAG_NAMELANG
&&
4636 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4637 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4638 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4641 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4644 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4645 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4648 * Use the language code from the IPP message...
4651 (*attr
)->values
[0].string
.language
=
4652 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4657 * Otherwise, use the language code corresponding to the locale...
4660 language
= cupsLangDefault();
4661 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4666 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4669 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4671 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4674 * Make copies of all values...
4677 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4680 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4683 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4686 case IPP_TAG_KEYWORD
:
4687 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4688 break; /* Silently "allow" name -> keyword */
4699 * 'ippSetVersion()' - Set the version number in an IPP message.
4701 * The @code ipp@ parameter refers to an IPP message previously created using
4702 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4704 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4706 * @since CUPS 1.6/macOS 10.8@
4709 int /* O - 1 on success, 0 on failure */
4710 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4711 int major
, /* I - Major version number (major.minor) */
4712 int minor
) /* I - Minor version number (major.minor) */
4715 * Range check input...
4718 if (!ipp
|| major
< 0 || minor
< 0)
4722 * Set the version number...
4725 ipp
->request
.any
.version
[0] = (ipp_uchar_t
)major
;
4726 ipp
->request
.any
.version
[1] = (ipp_uchar_t
)minor
;
4733 * 'ippTimeToDate()' - Convert from time in seconds to RFC 2579 format.
4736 const ipp_uchar_t
* /* O - RFC-2579 date/time data */
4737 ippTimeToDate(time_t t
) /* I - Time in seconds */
4739 struct tm
*unixdate
; /* UNIX unixdate/time info */
4740 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4741 /* RFC-2579 date/time data */
4745 * RFC-2579 date/time format is:
4747 * Byte(s) Description
4748 * ------- -----------
4749 * 0-1 Year (0 to 65535)
4753 * 5 Minutes (0 to 59)
4754 * 6 Seconds (0 to 60, 60 = "leap second")
4755 * 7 Deciseconds (0 to 9)
4757 * 9 UTC hours (0 to 11)
4758 * 10 UTC minutes (0 to 59)
4761 unixdate
= gmtime(&t
);
4762 unixdate
->tm_year
+= 1900;
4764 date
[0] = (ipp_uchar_t
)(unixdate
->tm_year
>> 8);
4765 date
[1] = (ipp_uchar_t
)(unixdate
->tm_year
);
4766 date
[2] = (ipp_uchar_t
)(unixdate
->tm_mon
+ 1);
4767 date
[3] = (ipp_uchar_t
)unixdate
->tm_mday
;
4768 date
[4] = (ipp_uchar_t
)unixdate
->tm_hour
;
4769 date
[5] = (ipp_uchar_t
)unixdate
->tm_min
;
4770 date
[6] = (ipp_uchar_t
)unixdate
->tm_sec
;
4781 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4783 * This function validates the contents of an attribute based on the name and
4784 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4785 * failure, @link cupsLastErrorString@ is set to a human-readable message.
4787 * @since CUPS 1.7/macOS 10.9@
4790 int /* O - 1 if valid, 0 otherwise */
4791 ippValidateAttribute(
4792 ipp_attribute_t
*attr
) /* I - Attribute */
4794 int i
; /* Looping var */
4795 char scheme
[64], /* Scheme from URI */
4796 userpass
[256], /* Username/password from URI */
4797 hostname
[256], /* Hostname from URI */
4798 resource
[1024]; /* Resource from URI */
4799 int port
, /* Port number from URI */
4800 uri_status
; /* URI separation status */
4801 const char *ptr
; /* Pointer into string */
4802 ipp_attribute_t
*colattr
; /* Collection attribute */
4803 regex_t re
; /* Regular expression */
4804 ipp_uchar_t
*date
; /* Current date value */
4805 static const char * const uri_status_strings
[] =
4806 { /* URI status strings */
4808 "Bad arguments to function",
4809 "Bad resource in URI",
4810 "Bad port number in URI",
4811 "Bad hostname/address in URI",
4812 "Bad username in URI",
4813 "Bad scheme in URI",
4816 "Missing scheme in URI",
4817 "Unknown scheme in URI",
4818 "Missing resource in URI"
4830 * Validate the attribute name.
4833 for (ptr
= attr
->name
; *ptr
; ptr
++)
4834 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4837 if (*ptr
|| ptr
== attr
->name
)
4839 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4840 _("\"%s\": Bad attribute name - invalid character "
4841 "(RFC 8011 section 5.1.4)."), attr
->name
);
4845 if ((ptr
- attr
->name
) > 255)
4847 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4848 _("\"%s\": Bad attribute name - bad length %d "
4849 "(RFC 8011 section 5.1.4)."), attr
->name
,
4850 (int)(ptr
- attr
->name
));
4854 switch (attr
->value_tag
)
4856 case IPP_TAG_INTEGER
:
4859 case IPP_TAG_BOOLEAN
:
4860 for (i
= 0; i
< attr
->num_values
; i
++)
4862 if (attr
->values
[i
].boolean
!= 0 &&
4863 attr
->values
[i
].boolean
!= 1)
4865 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4866 _("\"%s\": Bad boolen value %d "
4867 "(RFC 8011 section 5.1.21)."), attr
->name
,
4868 attr
->values
[i
].boolean
);
4875 for (i
= 0; i
< attr
->num_values
; i
++)
4877 if (attr
->values
[i
].integer
< 1)
4879 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4880 _("\"%s\": Bad enum value %d - out of range "
4881 "(RFC 8011 section 5.1.5)."), attr
->name
,
4882 attr
->values
[i
].integer
);
4888 case IPP_TAG_STRING
:
4889 for (i
= 0; i
< attr
->num_values
; i
++)
4891 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4893 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4894 _("\"%s\": Bad octetString value - bad length %d "
4895 "(RFC 8011 section 5.1.20)."), attr
->name
,
4896 attr
->values
[i
].unknown
.length
);
4903 for (i
= 0; i
< attr
->num_values
; i
++)
4905 date
= attr
->values
[i
].date
;
4907 if (date
[2] < 1 || date
[2] > 12)
4909 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4910 _("\"%s\": Bad dateTime month %u "
4911 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[2]);
4915 if (date
[3] < 1 || date
[3] > 31)
4917 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4918 _("\"%s\": Bad dateTime day %u "
4919 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[3]);
4925 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4926 _("\"%s\": Bad dateTime hours %u "
4927 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[4]);
4933 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4934 _("\"%s\": Bad dateTime minutes %u "
4935 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[5]);
4941 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4942 _("\"%s\": Bad dateTime seconds %u "
4943 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[6]);
4949 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4950 _("\"%s\": Bad dateTime deciseconds %u "
4951 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[7]);
4955 if (date
[8] != '-' && date
[8] != '+')
4957 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4958 _("\"%s\": Bad dateTime UTC sign '%c' "
4959 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[8]);
4965 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4966 _("\"%s\": Bad dateTime UTC hours %u "
4967 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[9]);
4973 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4974 _("\"%s\": Bad dateTime UTC minutes %u "
4975 "(RFC 8011 section 5.1.15)."), attr
->name
, date
[10]);
4981 case IPP_TAG_RESOLUTION
:
4982 for (i
= 0; i
< attr
->num_values
; i
++)
4984 if (attr
->values
[i
].resolution
.xres
<= 0)
4986 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4987 _("\"%s\": Bad resolution value %dx%d%s - cross "
4988 "feed resolution must be positive "
4989 "(RFC 8011 section 5.1.16)."), attr
->name
,
4990 attr
->values
[i
].resolution
.xres
,
4991 attr
->values
[i
].resolution
.yres
,
4992 attr
->values
[i
].resolution
.units
==
4993 IPP_RES_PER_INCH
? "dpi" :
4994 attr
->values
[i
].resolution
.units
==
4995 IPP_RES_PER_CM
? "dpcm" : "unknown");
4999 if (attr
->values
[i
].resolution
.yres
<= 0)
5001 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5002 _("\"%s\": Bad resolution value %dx%d%s - feed "
5003 "resolution must be positive "
5004 "(RFC 8011 section 5.1.16)."), attr
->name
,
5005 attr
->values
[i
].resolution
.xres
,
5006 attr
->values
[i
].resolution
.yres
,
5007 attr
->values
[i
].resolution
.units
==
5008 IPP_RES_PER_INCH
? "dpi" :
5009 attr
->values
[i
].resolution
.units
==
5010 IPP_RES_PER_CM
? "dpcm" : "unknown");
5014 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
5015 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
5017 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5018 _("\"%s\": Bad resolution value %dx%d%s - bad "
5019 "units value (RFC 8011 section 5.1.16)."),
5020 attr
->name
, attr
->values
[i
].resolution
.xres
,
5021 attr
->values
[i
].resolution
.yres
,
5022 attr
->values
[i
].resolution
.units
==
5023 IPP_RES_PER_INCH
? "dpi" :
5024 attr
->values
[i
].resolution
.units
==
5025 IPP_RES_PER_CM
? "dpcm" : "unknown");
5031 case IPP_TAG_RANGE
:
5032 for (i
= 0; i
< attr
->num_values
; i
++)
5034 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
5036 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5037 _("\"%s\": Bad rangeOfInteger value %d-%d - lower "
5038 "greater than upper (RFC 8011 section 5.1.14)."),
5039 attr
->name
, attr
->values
[i
].range
.lower
,
5040 attr
->values
[i
].range
.upper
);
5046 case IPP_TAG_BEGIN_COLLECTION
:
5047 for (i
= 0; i
< attr
->num_values
; i
++)
5049 for (colattr
= attr
->values
[i
].collection
->attrs
;
5051 colattr
= colattr
->next
)
5053 if (!ippValidateAttribute(colattr
))
5060 case IPP_TAG_TEXTLANG
:
5061 for (i
= 0; i
< attr
->num_values
; i
++)
5063 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5065 if ((*ptr
& 0xe0) == 0xc0)
5068 if ((*ptr
& 0xc0) != 0x80)
5071 else if ((*ptr
& 0xf0) == 0xe0)
5074 if ((*ptr
& 0xc0) != 0x80)
5077 if ((*ptr
& 0xc0) != 0x80)
5080 else if ((*ptr
& 0xf8) == 0xf0)
5083 if ((*ptr
& 0xc0) != 0x80)
5086 if ((*ptr
& 0xc0) != 0x80)
5089 if ((*ptr
& 0xc0) != 0x80)
5092 else if (*ptr
& 0x80)
5098 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5099 _("\"%s\": Bad text value \"%s\" - bad UTF-8 "
5100 "sequence (RFC 8011 section 5.1.2)."), attr
->name
,
5101 attr
->values
[i
].string
.text
);
5105 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5107 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5108 _("\"%s\": Bad text value \"%s\" - bad length %d "
5109 "(RFC 8011 section 5.1.2)."), attr
->name
,
5110 attr
->values
[i
].string
.text
,
5111 (int)(ptr
- attr
->values
[i
].string
.text
));
5118 case IPP_TAG_NAMELANG
:
5119 for (i
= 0; i
< attr
->num_values
; i
++)
5121 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5123 if ((*ptr
& 0xe0) == 0xc0)
5126 if ((*ptr
& 0xc0) != 0x80)
5129 else if ((*ptr
& 0xf0) == 0xe0)
5132 if ((*ptr
& 0xc0) != 0x80)
5135 if ((*ptr
& 0xc0) != 0x80)
5138 else if ((*ptr
& 0xf8) == 0xf0)
5141 if ((*ptr
& 0xc0) != 0x80)
5144 if ((*ptr
& 0xc0) != 0x80)
5147 if ((*ptr
& 0xc0) != 0x80)
5150 else if (*ptr
& 0x80)
5156 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5157 _("\"%s\": Bad name value \"%s\" - bad UTF-8 "
5158 "sequence (RFC 8011 section 5.1.3)."), attr
->name
,
5159 attr
->values
[i
].string
.text
);
5163 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5165 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5166 _("\"%s\": Bad name value \"%s\" - bad length %d "
5167 "(RFC 8011 section 5.1.3)."), attr
->name
,
5168 attr
->values
[i
].string
.text
,
5169 (int)(ptr
- attr
->values
[i
].string
.text
));
5175 case IPP_TAG_KEYWORD
:
5176 for (i
= 0; i
< attr
->num_values
; i
++)
5178 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5179 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5183 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5185 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5186 _("\"%s\": Bad keyword value \"%s\" - invalid "
5187 "character (RFC 8011 section 5.1.4)."),
5188 attr
->name
, attr
->values
[i
].string
.text
);
5192 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5194 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5195 _("\"%s\": Bad keyword value \"%s\" - bad "
5196 "length %d (RFC 8011 section 5.1.4)."),
5197 attr
->name
, attr
->values
[i
].string
.text
,
5198 (int)(ptr
- attr
->values
[i
].string
.text
));
5205 for (i
= 0; i
< attr
->num_values
; i
++)
5207 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5208 attr
->values
[i
].string
.text
,
5209 scheme
, sizeof(scheme
),
5210 userpass
, sizeof(userpass
),
5211 hostname
, sizeof(hostname
),
5212 &port
, resource
, sizeof(resource
));
5214 if (uri_status
< HTTP_URI_STATUS_OK
)
5216 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5217 _("\"%s\": Bad URI value \"%s\" - %s "
5218 "(RFC 8011 section 5.1.6)."), attr
->name
,
5219 attr
->values
[i
].string
.text
,
5220 uri_status_strings
[uri_status
-
5221 HTTP_URI_STATUS_OVERFLOW
]);
5225 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5227 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5228 _("\"%s\": Bad URI value \"%s\" - bad length %d "
5229 "(RFC 8011 section 5.1.6)."), attr
->name
,
5230 attr
->values
[i
].string
.text
,
5231 (int)strlen(attr
->values
[i
].string
.text
));
5236 case IPP_TAG_URISCHEME
:
5237 for (i
= 0; i
< attr
->num_values
; i
++)
5239 ptr
= attr
->values
[i
].string
.text
;
5240 if (islower(*ptr
& 255))
5242 for (ptr
++; *ptr
; ptr
++)
5243 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5244 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5248 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5250 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5251 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5252 "characters (RFC 8011 section 5.1.7)."),
5253 attr
->name
, attr
->values
[i
].string
.text
);
5257 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5259 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5260 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5261 "length %d (RFC 8011 section 5.1.7)."),
5262 attr
->name
, attr
->values
[i
].string
.text
,
5263 (int)(ptr
- attr
->values
[i
].string
.text
));
5269 case IPP_TAG_CHARSET
:
5270 for (i
= 0; i
< attr
->num_values
; i
++)
5272 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5273 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5274 isspace(*ptr
& 255))
5277 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5279 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5280 _("\"%s\": Bad charset value \"%s\" - bad "
5281 "characters (RFC 8011 section 5.1.8)."),
5282 attr
->name
, attr
->values
[i
].string
.text
);
5286 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5288 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5289 _("\"%s\": Bad charset value \"%s\" - bad "
5290 "length %d (RFC 8011 section 5.1.8)."),
5291 attr
->name
, attr
->values
[i
].string
.text
,
5292 (int)(ptr
- attr
->values
[i
].string
.text
));
5298 case IPP_TAG_LANGUAGE
:
5300 * The following regular expression is derived from the ABNF for
5301 * language tags in RFC 4646. All I can say is that this is the
5302 * easiest way to check the values...
5305 if ((i
= regcomp(&re
,
5307 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5309 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5310 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5311 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5312 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5313 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5315 "x(-[a-z0-9]{1,8})+" /* privateuse */
5317 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5319 REG_NOSUB
| REG_EXTENDED
)) != 0)
5321 char temp
[256]; /* Temporary error string */
5323 regerror(i
, &re
, temp
, sizeof(temp
));
5324 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
,
5325 _("Unable to compile naturalLanguage regular "
5326 "expression: %s."), temp
);
5330 for (i
= 0; i
< attr
->num_values
; i
++)
5332 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5334 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5335 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5336 "characters (RFC 8011 section 5.1.9)."),
5337 attr
->name
, attr
->values
[i
].string
.text
);
5342 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5344 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5345 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5346 "length %d (RFC 8011 section 5.1.9)."),
5347 attr
->name
, attr
->values
[i
].string
.text
,
5348 (int)strlen(attr
->values
[i
].string
.text
));
5357 case IPP_TAG_MIMETYPE
:
5359 * The following regular expression is derived from the ABNF for
5360 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5361 * the easiest way to check the values...
5364 if ((i
= regcomp(&re
,
5366 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5368 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5369 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5370 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5373 REG_NOSUB
| REG_EXTENDED
)) != 0)
5375 char temp
[256]; /* Temporary error string */
5377 regerror(i
, &re
, temp
, sizeof(temp
));
5378 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5379 _("Unable to compile mimeMediaType regular "
5380 "expression: %s."), temp
);
5384 for (i
= 0; i
< attr
->num_values
; i
++)
5386 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5388 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5389 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5390 "characters (RFC 8011 section 5.1.10)."),
5391 attr
->name
, attr
->values
[i
].string
.text
);
5396 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5398 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5399 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5400 "length %d (RFC 8011 section 5.1.10)."),
5401 attr
->name
, attr
->values
[i
].string
.text
,
5402 (int)strlen(attr
->values
[i
].string
.text
));
5420 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5422 * This function validates the contents of the IPP message, including each
5423 * attribute. Like @link ippValidateAttribute@, @link cupsLastErrorString@ is
5424 * set to a human-readable message on failure.
5426 * @since CUPS 1.7/macOS 10.9@
5429 int /* O - 1 if valid, 0 otherwise */
5430 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5432 ipp_attribute_t
*attr
; /* Current attribute */
5438 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5439 if (!ippValidateAttribute(attr
))
5447 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5450 ipp_state_t
/* O - Current state */
5451 ippWrite(http_t
*http
, /* I - HTTP connection */
5452 ipp_t
*ipp
) /* I - IPP data */
5454 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http
, (void *)ipp
));
5457 return (IPP_STATE_ERROR
);
5459 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5464 * 'ippWriteFile()' - Write data for an IPP message to a file.
5466 * @since CUPS 1.1.19/macOS 10.3@
5469 ipp_state_t
/* O - Current state */
5470 ippWriteFile(int fd
, /* I - HTTP data */
5471 ipp_t
*ipp
) /* I - IPP data */
5473 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
5475 ipp
->state
= IPP_STATE_IDLE
;
5477 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5482 * 'ippWriteIO()' - Write data for an IPP message.
5484 * @since CUPS 1.2/macOS 10.5@
5487 ipp_state_t
/* O - Current state */
5488 ippWriteIO(void *dst
, /* I - Destination */
5489 ipp_iocb_t cb
, /* I - Write callback function */
5490 int blocking
, /* I - Use blocking IO? */
5491 ipp_t
*parent
, /* I - Parent IPP message */
5492 ipp_t
*ipp
) /* I - IPP data */
5494 int i
; /* Looping var */
5495 int n
; /* Length of data */
5496 unsigned char *buffer
, /* Data buffer */
5497 *bufptr
; /* Pointer into buffer */
5498 ipp_attribute_t
*attr
; /* Current attribute */
5499 _ipp_value_t
*value
; /* Current value */
5502 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
5505 return (IPP_STATE_ERROR
);
5507 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5509 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5510 return (IPP_STATE_ERROR
);
5515 case IPP_STATE_IDLE
:
5516 ipp
->state
++; /* Avoid common problem... */
5518 case IPP_STATE_HEADER
:
5522 * Send the request header:
5525 * Operation/Status Code = 2 bytes
5526 * Request ID = 4 bytes
5532 *bufptr
++ = ipp
->request
.any
.version
[0];
5533 *bufptr
++ = ipp
->request
.any
.version
[1];
5534 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.op_status
>> 8);
5535 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.op_status
;
5536 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 24);
5537 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 16);
5538 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 8);
5539 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.request_id
;
5541 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5542 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5543 ipp
->request
.any
.op_status
));
5544 DEBUG_printf(("2ippWriteIO: request_id=%d",
5545 ipp
->request
.any
.request_id
));
5547 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5549 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5550 _cupsBufferRelease((char *)buffer
);
5551 return (IPP_STATE_ERROR
);
5556 * Reset the state engine to point to the first attribute
5557 * in the request/response, with no current group.
5560 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5561 ipp
->current
= ipp
->attrs
;
5562 ipp
->curtag
= IPP_TAG_ZERO
;
5564 DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp
->current
));
5567 * If blocking is disabled, stop here...
5573 case IPP_STATE_ATTRIBUTE
:
5574 while (ipp
->current
!= NULL
)
5577 * Write this attribute...
5581 attr
= ipp
->current
;
5583 ipp
->current
= ipp
->current
->next
;
5587 if (ipp
->curtag
!= attr
->group_tag
)
5590 * Send a group tag byte...
5593 ipp
->curtag
= attr
->group_tag
;
5595 if (attr
->group_tag
== IPP_TAG_ZERO
)
5598 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5599 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5600 *bufptr
++ = (ipp_uchar_t
)attr
->group_tag
;
5602 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5606 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5607 attr
->num_values
> 1 ? "1setOf " : "",
5608 ippTagString(attr
->value_tag
)));
5611 * Write the attribute tag and name.
5613 * The attribute name length does not include the trailing nul
5614 * character in the source string.
5616 * Collection values (parent != NULL) are written differently...
5622 * Get the length of the attribute name, and make sure it won't
5623 * overflow the buffer...
5626 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5628 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5629 _cupsBufferRelease((char *)buffer
);
5630 return (IPP_STATE_ERROR
);
5634 * Write the value tag, name length, and name string...
5637 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5638 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5639 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5642 if (attr
->value_tag
> 0xff)
5644 *bufptr
++ = IPP_TAG_EXTENSION
;
5645 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5646 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5647 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5648 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5651 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5653 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5654 *bufptr
++ = (ipp_uchar_t
)n
;
5655 memcpy(bufptr
, attr
->name
, (size_t)n
);
5661 * Get the length of the attribute name, and make sure it won't
5662 * overflow the buffer...
5665 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5667 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5668 _cupsBufferRelease((char *)buffer
);
5669 return (IPP_STATE_ERROR
);
5673 * Write the member name tag, name length, name string, value tag,
5674 * and empty name for the collection member attribute...
5677 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5678 IPP_TAG_MEMBERNAME
));
5679 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5681 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5682 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5683 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5685 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5688 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5689 *bufptr
++ = (ipp_uchar_t
)n
;
5690 memcpy(bufptr
, attr
->name
, (size_t)n
);
5693 if (attr
->value_tag
> 0xff)
5695 *bufptr
++ = IPP_TAG_EXTENSION
;
5696 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5697 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5698 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5699 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5702 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5709 * Now write the attribute value(s)...
5712 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5714 case IPP_TAG_UNSUPPORTED_VALUE
:
5715 case IPP_TAG_DEFAULT
:
5716 case IPP_TAG_UNKNOWN
:
5717 case IPP_TAG_NOVALUE
:
5718 case IPP_TAG_NOTSETTABLE
:
5719 case IPP_TAG_DELETEATTR
:
5720 case IPP_TAG_ADMINDEFINE
:
5725 case IPP_TAG_INTEGER
:
5727 for (i
= 0, value
= attr
->values
;
5728 i
< attr
->num_values
;
5731 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5733 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5735 DEBUG_puts("1ippWriteIO: Could not write IPP "
5737 _cupsBufferRelease((char *)buffer
);
5738 return (IPP_STATE_ERROR
);
5747 * Arrays and sets are done by sending additional
5748 * values with a zero-length name...
5751 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5757 * Integers and enumerations are both 4-byte signed
5758 * (twos-complement) values.
5760 * Put the 2-byte length and 4-byte value into the buffer...
5765 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 24);
5766 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 16);
5767 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 8);
5768 *bufptr
++ = (ipp_uchar_t
)value
->integer
;
5772 case IPP_TAG_BOOLEAN
:
5773 for (i
= 0, value
= attr
->values
;
5774 i
< attr
->num_values
;
5777 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5779 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5781 DEBUG_puts("1ippWriteIO: Could not write IPP "
5783 _cupsBufferRelease((char *)buffer
);
5784 return (IPP_STATE_ERROR
);
5793 * Arrays and sets are done by sending additional
5794 * values with a zero-length name...
5797 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5803 * Boolean values are 1-byte; 0 = false, 1 = true.
5805 * Put the 2-byte length and 1-byte value into the buffer...
5810 *bufptr
++ = (ipp_uchar_t
)value
->boolean
;
5816 case IPP_TAG_KEYWORD
:
5818 case IPP_TAG_URISCHEME
:
5819 case IPP_TAG_CHARSET
:
5820 case IPP_TAG_LANGUAGE
:
5821 case IPP_TAG_MIMETYPE
:
5822 for (i
= 0, value
= attr
->values
;
5823 i
< attr
->num_values
;
5829 * Arrays and sets are done by sending additional
5830 * values with a zero-length name...
5833 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5835 ippTagString(attr
->value_tag
)));
5836 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5838 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5840 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5842 DEBUG_puts("1ippWriteIO: Could not write IPP "
5844 _cupsBufferRelease((char *)buffer
);
5845 return (IPP_STATE_ERROR
);
5851 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5856 if (value
->string
.text
!= NULL
)
5857 n
= (int)strlen(value
->string
.text
);
5861 if (n
> (IPP_BUF_SIZE
- 2))
5863 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5864 _cupsBufferRelease((char *)buffer
);
5865 return (IPP_STATE_ERROR
);
5868 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5869 value
->string
.text
));
5871 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5873 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5875 DEBUG_puts("1ippWriteIO: Could not write IPP "
5877 _cupsBufferRelease((char *)buffer
);
5878 return (IPP_STATE_ERROR
);
5885 * All simple strings consist of the 2-byte length and
5886 * character data without the trailing nul normally found
5887 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5888 * bytes since the 2-byte length is a signed (twos-complement)
5891 * Put the 2-byte length and string characters in the buffer.
5894 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5895 *bufptr
++ = (ipp_uchar_t
)n
;
5899 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5906 for (i
= 0, value
= attr
->values
;
5907 i
< attr
->num_values
;
5910 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5912 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5914 DEBUG_puts("1ippWriteIO: Could not write IPP "
5916 _cupsBufferRelease((char *)buffer
);
5917 return (IPP_STATE_ERROR
);
5926 * Arrays and sets are done by sending additional
5927 * values with a zero-length name...
5930 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5936 * Date values consist of a 2-byte length and an
5937 * 11-byte date/time structure defined by RFC 1903.
5939 * Put the 2-byte length and 11-byte date/time
5940 * structure in the buffer.
5945 memcpy(bufptr
, value
->date
, 11);
5950 case IPP_TAG_RESOLUTION
:
5951 for (i
= 0, value
= attr
->values
;
5952 i
< attr
->num_values
;
5955 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5957 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5959 DEBUG_puts("1ippWriteIO: Could not write IPP "
5961 _cupsBufferRelease((char *)buffer
);
5962 return (IPP_STATE_ERROR
);
5971 * Arrays and sets are done by sending additional
5972 * values with a zero-length name...
5975 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5981 * Resolution values consist of a 2-byte length,
5982 * 4-byte horizontal resolution value, 4-byte vertical
5983 * resolution value, and a 1-byte units value.
5985 * Put the 2-byte length and resolution value data
5991 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 24);
5992 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 16);
5993 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 8);
5994 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.xres
;
5995 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 24);
5996 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 16);
5997 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 8);
5998 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.yres
;
5999 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.units
;
6003 case IPP_TAG_RANGE
:
6004 for (i
= 0, value
= attr
->values
;
6005 i
< attr
->num_values
;
6008 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
6010 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6012 DEBUG_puts("1ippWriteIO: Could not write IPP "
6014 _cupsBufferRelease((char *)buffer
);
6015 return (IPP_STATE_ERROR
);
6024 * Arrays and sets are done by sending additional
6025 * values with a zero-length name...
6028 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6034 * Range values consist of a 2-byte length,
6035 * 4-byte lower value, and 4-byte upper value.
6037 * Put the 2-byte length and range value data
6043 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 24);
6044 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 16);
6045 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 8);
6046 *bufptr
++ = (ipp_uchar_t
)value
->range
.lower
;
6047 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 24);
6048 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 16);
6049 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 8);
6050 *bufptr
++ = (ipp_uchar_t
)value
->range
.upper
;
6054 case IPP_TAG_TEXTLANG
:
6055 case IPP_TAG_NAMELANG
:
6056 for (i
= 0, value
= attr
->values
;
6057 i
< attr
->num_values
;
6063 * Arrays and sets are done by sending additional
6064 * values with a zero-length name...
6067 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6069 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6071 DEBUG_puts("1ippWriteIO: Could not write IPP "
6073 _cupsBufferRelease((char *)buffer
);
6074 return (IPP_STATE_ERROR
);
6080 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6086 * textWithLanguage and nameWithLanguage values consist
6087 * of a 2-byte length for both strings and their
6088 * individual lengths, a 2-byte length for the
6089 * character string, the character string without the
6090 * trailing nul, a 2-byte length for the character
6091 * set string, and the character set string without
6097 if (value
->string
.language
!= NULL
)
6098 n
+= (int)strlen(value
->string
.language
);
6100 if (value
->string
.text
!= NULL
)
6101 n
+= (int)strlen(value
->string
.text
);
6103 if (n
> (IPP_BUF_SIZE
- 2))
6105 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
6106 "too long (%d)", n
));
6107 _cupsBufferRelease((char *)buffer
);
6108 return (IPP_STATE_ERROR
);
6111 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6113 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6115 DEBUG_puts("1ippWriteIO: Could not write IPP "
6117 _cupsBufferRelease((char *)buffer
);
6118 return (IPP_STATE_ERROR
);
6124 /* Length of entire value */
6125 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6126 *bufptr
++ = (ipp_uchar_t
)n
;
6128 /* Length of language */
6129 if (value
->string
.language
!= NULL
)
6130 n
= (int)strlen(value
->string
.language
);
6134 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6135 *bufptr
++ = (ipp_uchar_t
)n
;
6140 memcpy(bufptr
, value
->string
.language
, (size_t)n
);
6144 /* Length of text */
6145 if (value
->string
.text
!= NULL
)
6146 n
= (int)strlen(value
->string
.text
);
6150 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6151 *bufptr
++ = (ipp_uchar_t
)n
;
6156 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
6162 case IPP_TAG_BEGIN_COLLECTION
:
6163 for (i
= 0, value
= attr
->values
;
6164 i
< attr
->num_values
;
6168 * Collections are written with the begin-collection
6169 * tag first with a value of 0 length, followed by the
6170 * attributes in the collection, then the end-collection
6174 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6176 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6178 DEBUG_puts("1ippWriteIO: Could not write IPP "
6180 _cupsBufferRelease((char *)buffer
);
6181 return (IPP_STATE_ERROR
);
6190 * Arrays and sets are done by sending additional
6191 * values with a zero-length name...
6194 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6200 * Write a data length of 0 and flush the buffer...
6206 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6208 DEBUG_puts("1ippWriteIO: Could not write IPP "
6210 _cupsBufferRelease((char *)buffer
);
6211 return (IPP_STATE_ERROR
);
6217 * Then write the collection attribute...
6220 value
->collection
->state
= IPP_STATE_IDLE
;
6222 if (ippWriteIO(dst
, cb
, 1, ipp
,
6223 value
->collection
) == IPP_STATE_ERROR
)
6225 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6226 _cupsBufferRelease((char *)buffer
);
6227 return (IPP_STATE_ERROR
);
6233 for (i
= 0, value
= attr
->values
;
6234 i
< attr
->num_values
;
6240 * Arrays and sets are done by sending additional
6241 * values with a zero-length name...
6244 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6246 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6248 DEBUG_puts("1ippWriteIO: Could not write IPP "
6250 _cupsBufferRelease((char *)buffer
);
6251 return (IPP_STATE_ERROR
);
6257 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6263 * An unknown value might some new value that a
6264 * vendor has come up with. It consists of a
6265 * 2-byte length and the bytes in the unknown
6269 n
= value
->unknown
.length
;
6271 if (n
> (IPP_BUF_SIZE
- 2))
6273 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6275 _cupsBufferRelease((char *)buffer
);
6276 return (IPP_STATE_ERROR
);
6279 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6281 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6283 DEBUG_puts("1ippWriteIO: Could not write IPP "
6285 _cupsBufferRelease((char *)buffer
);
6286 return (IPP_STATE_ERROR
);
6292 /* Length of unknown value */
6293 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6294 *bufptr
++ = (ipp_uchar_t
)n
;
6299 memcpy(bufptr
, value
->unknown
.data
, (size_t)n
);
6307 * Write the data out...
6310 if (bufptr
> buffer
)
6312 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6314 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6315 _cupsBufferRelease((char *)buffer
);
6316 return (IPP_STATE_ERROR
);
6319 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6320 (int)(bufptr
- buffer
)));
6324 * If blocking is disabled and we aren't at the end of the attribute
6325 * list, stop here...
6328 if (!blocking
&& ipp
->current
)
6332 if (ipp
->current
== NULL
)
6335 * Done with all of the attributes; add the end-of-attributes
6336 * tag or end-collection attribute...
6341 buffer
[0] = IPP_TAG_END
;
6346 buffer
[0] = IPP_TAG_END_COLLECTION
;
6347 buffer
[1] = 0; /* empty name */
6349 buffer
[3] = 0; /* empty value */
6354 if ((*cb
)(dst
, buffer
, (size_t)n
) < 0)
6356 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6357 _cupsBufferRelease((char *)buffer
);
6358 return (IPP_STATE_ERROR
);
6361 ipp
->state
= IPP_STATE_DATA
;
6365 case IPP_STATE_DATA
:
6369 break; /* anti-compiler-warning-code */
6372 _cupsBufferRelease((char *)buffer
);
6374 return (ipp
->state
);
6379 * 'ipp_add_attr()' - Add a new attribute to the message.
6382 static ipp_attribute_t
* /* O - New attribute */
6383 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6384 const char *name
, /* I - Attribute name or NULL */
6385 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6386 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6387 int num_values
) /* I - Number of values */
6389 int alloc_values
; /* Number of values to allocate */
6390 ipp_attribute_t
*attr
; /* New attribute */
6393 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
));
6396 * Range check input...
6399 if (!ipp
|| num_values
< 0)
6403 * Allocate memory, rounding the allocation up as needed...
6406 if (num_values
<= 1)
6409 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6411 attr
= calloc(sizeof(ipp_attribute_t
) +
6412 (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6417 * Initialize attribute...
6420 DEBUG_printf(("4debug_alloc: %p %s %s%s (%d values)", (void *)attr
, name
, num_values
> 1 ? "1setOf " : "", ippTagString(value_tag
), num_values
));
6423 attr
->name
= _cupsStrAlloc(name
);
6425 attr
->group_tag
= group_tag
;
6426 attr
->value_tag
= value_tag
;
6427 attr
->num_values
= num_values
;
6430 * Add it to the end of the linked list...
6434 ipp
->last
->next
= attr
;
6438 ipp
->prev
= ipp
->last
;
6439 ipp
->last
= ipp
->current
= attr
;
6442 DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr
));
6449 * 'ipp_free_values()' - Free attribute values.
6453 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6454 int element
,/* I - First value to free */
6455 int count
) /* I - Number of values to free */
6457 int i
; /* Looping var */
6458 _ipp_value_t
*value
; /* Current value */
6461 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", (void *)attr
, element
, count
));
6463 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6466 * Free values as needed...
6469 switch (attr
->value_tag
)
6471 case IPP_TAG_TEXTLANG
:
6472 case IPP_TAG_NAMELANG
:
6473 if (element
== 0 && count
== attr
->num_values
&&
6474 attr
->values
[0].string
.language
)
6476 _cupsStrFree(attr
->values
[0].string
.language
);
6477 attr
->values
[0].string
.language
= NULL
;
6479 /* Fall through to other string values */
6483 case IPP_TAG_RESERVED_STRING
:
6484 case IPP_TAG_KEYWORD
:
6486 case IPP_TAG_URISCHEME
:
6487 case IPP_TAG_CHARSET
:
6488 case IPP_TAG_LANGUAGE
:
6489 case IPP_TAG_MIMETYPE
:
6490 for (i
= count
, value
= attr
->values
+ element
;
6494 _cupsStrFree(value
->string
.text
);
6495 value
->string
.text
= NULL
;
6499 case IPP_TAG_DEFAULT
:
6500 case IPP_TAG_UNKNOWN
:
6501 case IPP_TAG_NOVALUE
:
6502 case IPP_TAG_NOTSETTABLE
:
6503 case IPP_TAG_DELETEATTR
:
6504 case IPP_TAG_ADMINDEFINE
:
6505 case IPP_TAG_INTEGER
:
6507 case IPP_TAG_BOOLEAN
:
6509 case IPP_TAG_RESOLUTION
:
6510 case IPP_TAG_RANGE
:
6513 case IPP_TAG_BEGIN_COLLECTION
:
6514 for (i
= count
, value
= attr
->values
+ element
;
6518 ippDelete(value
->collection
);
6519 value
->collection
= NULL
;
6523 case IPP_TAG_STRING
:
6525 for (i
= count
, value
= attr
->values
+ element
;
6529 if (value
->unknown
.data
)
6531 free(value
->unknown
.data
);
6532 value
->unknown
.data
= NULL
;
6540 * If we are not freeing values from the end, move the remaining values up...
6543 if ((element
+ count
) < attr
->num_values
)
6544 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6545 (size_t)(attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6547 attr
->num_values
-= count
;
6552 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6554 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6555 * to "ll-cc", "ll-region", and "charset-number", respectively.
6558 static char * /* O - Language code string */
6559 ipp_get_code(const char *value
, /* I - Locale/charset string */
6560 char *buffer
, /* I - String buffer */
6561 size_t bufsize
) /* I - Size of string buffer */
6563 char *bufptr
, /* Pointer into buffer */
6564 *bufend
; /* End of buffer */
6568 * Convert values to lowercase and change _ to - as needed...
6571 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6572 *value
&& bufptr
< bufend
;
6577 *bufptr
++ = (char)_cups_tolower(*value
);
6582 * Return the converted string...
6590 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6592 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6593 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6596 static char * /* O - Language code string */
6597 ipp_lang_code(const char *locale
, /* I - Locale string */
6598 char *buffer
, /* I - String buffer */
6599 size_t bufsize
) /* I - Size of string buffer */
6602 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6605 if (!_cups_strcasecmp(locale
, "c"))
6607 strlcpy(buffer
, "en", bufsize
);
6611 return (ipp_get_code(locale
, buffer
, bufsize
));
6616 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6619 static size_t /* O - Size of IPP message */
6620 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6621 int collection
) /* I - 1 if a collection, 0 otherwise */
6623 int i
; /* Looping var */
6624 size_t bytes
; /* Number of bytes */
6625 ipp_attribute_t
*attr
; /* Current attribute */
6626 ipp_tag_t group
; /* Current group */
6627 _ipp_value_t
*value
; /* Current value */
6630 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp
, collection
));
6634 DEBUG_puts("4ipp_length: Returning 0 bytes");
6639 * Start with 8 bytes for the IPP message header...
6642 bytes
= collection
? 0 : 8;
6645 * Then add the lengths of each attribute...
6648 group
= IPP_TAG_ZERO
;
6650 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6652 if (attr
->group_tag
!= group
&& !collection
)
6654 group
= attr
->group_tag
;
6655 if (group
== IPP_TAG_ZERO
)
6658 bytes
++; /* Group tag */
6664 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6665 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6667 if ((attr
->value_tag
& ~IPP_TAG_CUPS_CONST
) < IPP_TAG_EXTENSION
)
6668 bytes
+= (size_t)attr
->num_values
;/* Value tag for each value */
6670 bytes
+= (size_t)(5 * attr
->num_values
);
6671 /* Value tag for each value */
6672 bytes
+= (size_t)(2 * attr
->num_values
);
6674 bytes
+= strlen(attr
->name
); /* Name */
6675 bytes
+= (size_t)(2 * attr
->num_values
);
6679 bytes
+= 5; /* Add membername overhead */
6681 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6683 case IPP_TAG_UNSUPPORTED_VALUE
:
6684 case IPP_TAG_DEFAULT
:
6685 case IPP_TAG_UNKNOWN
:
6686 case IPP_TAG_NOVALUE
:
6687 case IPP_TAG_NOTSETTABLE
:
6688 case IPP_TAG_DELETEATTR
:
6689 case IPP_TAG_ADMINDEFINE
:
6692 case IPP_TAG_INTEGER
:
6694 bytes
+= (size_t)(4 * attr
->num_values
);
6697 case IPP_TAG_BOOLEAN
:
6698 bytes
+= (size_t)attr
->num_values
;
6703 case IPP_TAG_KEYWORD
:
6705 case IPP_TAG_URISCHEME
:
6706 case IPP_TAG_CHARSET
:
6707 case IPP_TAG_LANGUAGE
:
6708 case IPP_TAG_MIMETYPE
:
6709 for (i
= 0, value
= attr
->values
;
6710 i
< attr
->num_values
;
6712 if (value
->string
.text
)
6713 bytes
+= strlen(value
->string
.text
);
6717 bytes
+= (size_t)(11 * attr
->num_values
);
6720 case IPP_TAG_RESOLUTION
:
6721 bytes
+= (size_t)(9 * attr
->num_values
);
6724 case IPP_TAG_RANGE
:
6725 bytes
+= (size_t)(8 * attr
->num_values
);
6728 case IPP_TAG_TEXTLANG
:
6729 case IPP_TAG_NAMELANG
:
6730 bytes
+= (size_t)(4 * attr
->num_values
);
6731 /* Charset + text length */
6733 for (i
= 0, value
= attr
->values
;
6734 i
< attr
->num_values
;
6737 if (value
->string
.language
)
6738 bytes
+= strlen(value
->string
.language
);
6740 if (value
->string
.text
)
6741 bytes
+= strlen(value
->string
.text
);
6745 case IPP_TAG_BEGIN_COLLECTION
:
6746 for (i
= 0, value
= attr
->values
;
6747 i
< attr
->num_values
;
6749 bytes
+= ipp_length(value
->collection
, 1);
6753 for (i
= 0, value
= attr
->values
;
6754 i
< attr
->num_values
;
6756 bytes
+= (size_t)value
->unknown
.length
;
6762 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6763 * for the "end of collection" tag and return...
6771 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6778 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6781 static ssize_t
/* O - Number of bytes read */
6782 ipp_read_http(http_t
*http
, /* I - Client connection */
6783 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6784 size_t length
) /* I - Total length */
6786 ssize_t tbytes
, /* Total bytes read */
6787 bytes
; /* Bytes read this pass */
6790 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http
, (void *)buffer
, (int)length
));
6793 * Loop until all bytes are read...
6796 for (tbytes
= 0, bytes
= 0;
6797 tbytes
< (int)length
;
6798 tbytes
+= bytes
, buffer
+= bytes
)
6800 DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT
", http->state=%d", CUPS_LLCAST tbytes
, http
->state
));
6802 if (http
->state
== HTTP_STATE_WAITING
)
6805 if (http
->used
== 0 && !http
->blocking
)
6808 * Wait up to 10 seconds for more data on non-blocking sockets...
6811 if (!httpWait(http
, 10000))
6821 else if (http
->used
== 0 && http
->timeout_value
> 0)
6824 * Wait up to timeout seconds for more data on blocking sockets...
6827 if (!httpWait(http
, (int)(1000 * http
->timeout_value
)))
6838 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- (size_t)tbytes
)) < 0)
6843 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6849 else if (bytes
== 0)
6854 * Return the number of bytes read...
6857 if (tbytes
== 0 && bytes
< 0)
6860 DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST tbytes
));
6867 * 'ipp_read_file()' - Read IPP data from a file.
6870 static ssize_t
/* O - Number of bytes read */
6871 ipp_read_file(int *fd
, /* I - File descriptor */
6872 ipp_uchar_t
*buffer
, /* O - Read buffer */
6873 size_t length
) /* I - Number of bytes to read */
6876 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6878 return (read(*fd
, buffer
, length
));
6884 * 'ipp_set_error()' - Set a formatted, localized error string.
6888 ipp_set_error(ipp_status_t status
, /* I - Status code */
6889 const char *format
, /* I - Printf-style error string */
6890 ...) /* I - Additional arguments as needed */
6892 va_list ap
; /* Pointer to additional args */
6893 char buffer
[2048]; /* Message buffer */
6894 cups_lang_t
*lang
= cupsLangDefault();
6895 /* Current language */
6898 va_start(ap
, format
);
6899 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6902 _cupsSetError(status
, buffer
, 0);
6907 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6911 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6912 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6913 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6914 int element
) /* I - Value number (0-based) */
6916 ipp_attribute_t
*temp
, /* New attribute pointer */
6917 *current
, /* Current attribute in list */
6918 *prev
; /* Previous attribute in list */
6919 int alloc_values
; /* Allocated values */
6923 * If we are setting an existing value element, return it...
6928 if (temp
->num_values
<= 1)
6931 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6932 ~(IPP_MAX_VALUES
- 1);
6934 if (element
< alloc_values
)
6936 if (element
>= temp
->num_values
)
6937 temp
->num_values
= element
+ 1;
6939 return (temp
->values
+ element
);
6943 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6944 * values when num_values > 1.
6947 if (alloc_values
< IPP_MAX_VALUES
)
6948 alloc_values
= IPP_MAX_VALUES
;
6950 alloc_values
+= IPP_MAX_VALUES
;
6952 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6956 * Reallocate memory...
6959 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) + (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6961 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6962 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6967 * Zero the new memory...
6970 memset(temp
->values
+ temp
->num_values
, 0, (size_t)(alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6975 * Reset pointers in the list...
6978 DEBUG_printf(("4debug_free: %p %s", (void *)*attr
, temp
->name
));
6979 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
));
6981 if (ipp
->current
== *attr
&& ipp
->prev
)
6984 * Use current "previous" pointer...
6992 * Find this attribute in the linked list...
6995 for (prev
= NULL
, current
= ipp
->attrs
;
6996 current
&& current
!= *attr
;
6997 prev
= current
, current
= current
->next
);
7002 * This is a serious error!
7006 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
7007 _("IPP attribute is not a member of the message."), 1);
7008 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
7018 ipp
->current
= temp
;
7021 if (ipp
->last
== *attr
)
7028 * Return the value element...
7031 if (element
>= temp
->num_values
)
7032 temp
->num_values
= element
+ 1;
7034 return (temp
->values
+ element
);
7039 * 'ipp_write_file()' - Write IPP data to a file.
7042 static ssize_t
/* O - Number of bytes written */
7043 ipp_write_file(int *fd
, /* I - File descriptor */
7044 ipp_uchar_t
*buffer
, /* I - Data to write */
7045 size_t length
) /* I - Number of bytes to write */
7048 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
7050 return (write(*fd
, buffer
, length
));