2 * Internet Printing Protocol functions for CUPS.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
15 #include "cups-private.h"
26 static ipp_attribute_t
*ipp_add_attr(ipp_t
*ipp
, const char *name
,
27 ipp_tag_t group_tag
, ipp_tag_t value_tag
,
29 static void ipp_free_values(ipp_attribute_t
*attr
, int element
,
31 static char *ipp_get_code(const char *locale
, char *buffer
,
33 __attribute__((nonnull(1,2)));
34 static char *ipp_lang_code(const char *locale
, char *buffer
,
36 __attribute__((nonnull(1,2)));
37 static size_t ipp_length(ipp_t
*ipp
, int collection
);
38 static ssize_t
ipp_read_http(http_t
*http
, ipp_uchar_t
*buffer
,
40 static ssize_t
ipp_read_file(int *fd
, ipp_uchar_t
*buffer
,
42 static void ipp_set_error(ipp_status_t status
, const char *format
,
44 static _ipp_value_t
*ipp_set_value(ipp_t
*ipp
, ipp_attribute_t
**attr
,
46 static ssize_t
ipp_write_file(int *fd
, ipp_uchar_t
*buffer
,
51 * '_cupsBufferGet()' - Get a read/write buffer.
54 char * /* O - Buffer */
55 _cupsBufferGet(size_t size
) /* I - Size required */
57 _cups_buffer_t
*buffer
; /* Current buffer */
58 _cups_globals_t
*cg
= _cupsGlobals();
62 for (buffer
= cg
->cups_buffers
; buffer
; buffer
= buffer
->next
)
63 if (!buffer
->used
&& buffer
->size
>= size
)
68 if ((buffer
= malloc(sizeof(_cups_buffer_t
) + size
- 1)) == NULL
)
71 buffer
->next
= cg
->cups_buffers
;
73 cg
->cups_buffers
= buffer
;
83 * '_cupsBufferRelease()' - Release a read/write buffer.
87 _cupsBufferRelease(char *b
) /* I - Buffer to release */
89 _cups_buffer_t
*buffer
; /* Buffer */
93 * Mark this buffer as unused...
96 buffer
= (_cups_buffer_t
*)(b
- offsetof(_cups_buffer_t
, d
));
102 * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
104 * The @code ipp@ parameter refers to an IPP message previously created using
105 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
107 * The @code group@ parameter specifies the IPP attribute group tag: none
108 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
109 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
110 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
111 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
114 ipp_attribute_t
* /* O - New attribute */
115 ippAddBoolean(ipp_t
*ipp
, /* I - IPP message */
116 ipp_tag_t group
, /* I - IPP group */
117 const char *name
, /* I - Name of attribute */
118 char value
) /* I - Value of attribute */
120 ipp_attribute_t
*attr
; /* New attribute */
123 DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)", (void *)ipp
, group
, ippTagString(group
), name
, value
));
126 * Range check input...
129 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
130 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
134 * Create the attribute...
137 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, 1)) == NULL
)
140 attr
->values
[0].boolean
= value
;
147 * 'ippAddBooleans()' - Add an array of boolean values.
149 * The @code ipp@ parameter refers to an IPP message previously created using
150 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
152 * The @code group@ parameter specifies the IPP attribute group tag: none
153 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
154 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
155 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
156 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
159 ipp_attribute_t
* /* O - New attribute */
160 ippAddBooleans(ipp_t
*ipp
, /* I - IPP message */
161 ipp_tag_t group
, /* I - IPP group */
162 const char *name
, /* I - Name of attribute */
163 int num_values
, /* I - Number of values */
164 const char *values
) /* I - Values */
166 int i
; /* Looping var */
167 ipp_attribute_t
*attr
; /* New attribute */
168 _ipp_value_t
*value
; /* Current value */
171 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
));
174 * Range check input...
177 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
178 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
183 * Create the attribute...
186 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, num_values
)) == NULL
)
191 for (i
= num_values
, value
= attr
->values
;
194 value
->boolean
= *values
++;
202 * 'ippAddCollection()' - Add a collection value.
204 * The @code ipp@ parameter refers to an IPP message previously created using
205 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
207 * The @code group@ parameter specifies the IPP attribute group tag: none
208 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
209 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
210 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
211 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
213 * @since CUPS 1.1.19/macOS 10.3@
216 ipp_attribute_t
* /* O - New attribute */
217 ippAddCollection(ipp_t
*ipp
, /* I - IPP message */
218 ipp_tag_t group
, /* I - IPP group */
219 const char *name
, /* I - Name of attribute */
220 ipp_t
*value
) /* I - Value */
222 ipp_attribute_t
*attr
; /* New attribute */
225 DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
228 * Range check input...
231 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
232 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
236 * Create the attribute...
239 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
, 1)) == NULL
)
242 attr
->values
[0].collection
= value
;
252 * 'ippAddCollections()' - Add an array of collection values.
254 * The @code ipp@ parameter refers to an IPP message previously created using
255 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
257 * The @code group@ parameter specifies the IPP attribute group tag: none
258 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
259 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
260 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
261 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
263 * @since CUPS 1.1.19/macOS 10.3@
266 ipp_attribute_t
* /* O - New attribute */
268 ipp_t
*ipp
, /* I - IPP message */
269 ipp_tag_t group
, /* I - IPP group */
270 const char *name
, /* I - Name of attribute */
271 int num_values
, /* I - Number of values */
272 const ipp_t
**values
) /* I - Values */
274 int i
; /* Looping var */
275 ipp_attribute_t
*attr
; /* New attribute */
276 _ipp_value_t
*value
; /* Current value */
279 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
));
282 * Range check input...
285 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
286 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
291 * Create the attribute...
294 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
,
295 num_values
)) == NULL
)
300 for (i
= num_values
, value
= attr
->values
;
304 value
->collection
= (ipp_t
*)*values
++;
305 value
->collection
->use
++;
314 * 'ippAddDate()' - Add a dateTime attribute to an IPP message.
316 * The @code ipp@ parameter refers to an IPP message previously created using
317 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
319 * The @code group@ parameter specifies the IPP attribute group tag: none
320 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
321 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
322 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
323 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
326 ipp_attribute_t
* /* O - New attribute */
327 ippAddDate(ipp_t
*ipp
, /* I - IPP message */
328 ipp_tag_t group
, /* I - IPP group */
329 const char *name
, /* I - Name of attribute */
330 const ipp_uchar_t
*value
) /* I - Value */
332 ipp_attribute_t
*attr
; /* New attribute */
335 DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
338 * Range check input...
341 if (!ipp
|| !name
|| !value
|| group
< IPP_TAG_ZERO
||
342 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
346 * Create the attribute...
349 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_DATE
, 1)) == NULL
)
352 memcpy(attr
->values
[0].date
, value
, 11);
359 * 'ippAddInteger()' - Add a integer attribute to an IPP message.
361 * The @code ipp@ parameter refers to an IPP message previously created using
362 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
364 * The @code group@ parameter specifies the IPP attribute group tag: none
365 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
366 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
367 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
368 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
370 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
371 * (@code IPP_TAG_INTEGER@).
374 ipp_attribute_t
* /* O - New attribute */
375 ippAddInteger(ipp_t
*ipp
, /* I - IPP message */
376 ipp_tag_t group
, /* I - IPP group */
377 ipp_tag_t value_tag
, /* I - Type of attribute */
378 const char *name
, /* I - Name of attribute */
379 int value
) /* I - Value of attribute */
381 ipp_attribute_t
*attr
; /* New attribute */
384 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
));
386 value_tag
&= IPP_TAG_CUPS_MASK
;
389 * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
393 if (value_tag
>= IPP_TAG_UNSUPPORTED_VALUE
&& value_tag
<= IPP_TAG_ADMINDEFINE
)
394 return (ippAddOutOfBand(ipp
, group
, value_tag
, name
));
397 * Range check input...
401 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
402 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
403 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
))
406 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
407 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
412 * Create the attribute...
415 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
418 attr
->values
[0].integer
= value
;
425 * 'ippAddIntegers()' - Add an array of integer values.
427 * The @code ipp@ parameter refers to an IPP message previously created using
428 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
430 * The @code group@ parameter specifies the IPP attribute group tag: none
431 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
432 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
433 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
434 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
436 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
437 * (@code IPP_TAG_INTEGER@).
440 ipp_attribute_t
* /* O - New attribute */
441 ippAddIntegers(ipp_t
*ipp
, /* I - IPP message */
442 ipp_tag_t group
, /* I - IPP group */
443 ipp_tag_t value_tag
, /* I - Type of attribute */
444 const char *name
, /* I - Name of attribute */
445 int num_values
, /* I - Number of values */
446 const int *values
) /* I - Values */
448 int i
; /* Looping var */
449 ipp_attribute_t
*attr
; /* New attribute */
450 _ipp_value_t
*value
; /* Current value */
453 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
));
455 value_tag
&= IPP_TAG_CUPS_MASK
;
458 * Range check input...
462 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
463 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
464 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
) ||
468 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
469 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
475 * Create the attribute...
478 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
483 for (i
= num_values
, value
= attr
->values
;
486 value
->integer
= *values
++;
494 * 'ippAddOctetString()' - Add an octetString value to an IPP message.
496 * The @code ipp@ parameter refers to an IPP message previously created using
497 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
499 * The @code group@ parameter specifies the IPP attribute group tag: none
500 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
501 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
502 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
503 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
505 * @since CUPS 1.2/macOS 10.5@
508 ipp_attribute_t
* /* O - New attribute */
509 ippAddOctetString(ipp_t
*ipp
, /* I - IPP message */
510 ipp_tag_t group
, /* I - IPP group */
511 const char *name
, /* I - Name of attribute */
512 const void *data
, /* I - octetString data */
513 int datalen
) /* I - Length of data in bytes */
515 ipp_attribute_t
*attr
; /* New attribute */
518 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
519 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
520 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
523 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_STRING
, 1)) == NULL
)
527 * Initialize the attribute data...
530 attr
->values
[0].unknown
.length
= datalen
;
534 if ((attr
->values
[0].unknown
.data
= malloc((size_t)datalen
)) == NULL
)
536 ippDeleteAttribute(ipp
, attr
);
540 memcpy(attr
->values
[0].unknown
.data
, data
, (size_t)datalen
);
544 * Return the new attribute...
552 * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
554 * The @code ipp@ parameter refers to an IPP message previously created using
555 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
557 * The @code group@ parameter specifies the IPP attribute group tag: none
558 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
559 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
560 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
561 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
563 * Supported out-of-band values include unsupported-value
564 * (@code IPP_TAG_UNSUPPORTED_VALUE@), default (@code IPP_TAG_DEFAULT@), unknown
565 * (@code IPP_TAG_UNKNOWN@), no-value (@code IPP_TAG_NOVALUE@), not-settable
566 * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
567 * admin-define (@code IPP_TAG_ADMINDEFINE@).
569 * @since CUPS 1.6/macOS 10.8@
572 ipp_attribute_t
* /* O - New attribute */
573 ippAddOutOfBand(ipp_t
*ipp
, /* I - IPP message */
574 ipp_tag_t group
, /* I - IPP group */
575 ipp_tag_t value_tag
, /* I - Type of attribute */
576 const char *name
) /* I - Name of attribute */
578 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
));
580 value_tag
&= IPP_TAG_CUPS_MASK
;
583 * Range check input...
586 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
587 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
588 (value_tag
!= IPP_TAG_UNSUPPORTED_VALUE
&&
589 value_tag
!= IPP_TAG_DEFAULT
&&
590 value_tag
!= IPP_TAG_UNKNOWN
&&
591 value_tag
!= IPP_TAG_NOVALUE
&&
592 value_tag
!= IPP_TAG_NOTSETTABLE
&&
593 value_tag
!= IPP_TAG_DELETEATTR
&&
594 value_tag
!= IPP_TAG_ADMINDEFINE
))
598 * Create the attribute...
601 return (ipp_add_attr(ipp
, name
, group
, value_tag
, 1));
606 * 'ippAddRange()' - Add a range of values to an IPP message.
608 * The @code ipp@ parameter refers to an IPP message previously created using
609 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
611 * The @code group@ parameter specifies the IPP attribute group tag: none
612 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
613 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
614 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
615 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
617 * The @code lower@ parameter must be less than or equal to the @code upper@ parameter.
620 ipp_attribute_t
* /* O - New attribute */
621 ippAddRange(ipp_t
*ipp
, /* I - IPP message */
622 ipp_tag_t group
, /* I - IPP group */
623 const char *name
, /* I - Name of attribute */
624 int lower
, /* I - Lower value */
625 int upper
) /* I - Upper value */
627 ipp_attribute_t
*attr
; /* New attribute */
630 DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, upper=%d)", (void *)ipp
, group
, ippTagString(group
), name
, lower
, upper
));
633 * Range check input...
636 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
637 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
641 * Create the attribute...
644 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, 1)) == NULL
)
647 attr
->values
[0].range
.lower
= lower
;
648 attr
->values
[0].range
.upper
= upper
;
655 * 'ippAddRanges()' - Add ranges of values to an IPP message.
657 * The @code ipp@ parameter refers to an IPP message previously created using
658 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
660 * The @code group@ parameter specifies the IPP attribute group tag: none
661 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
662 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
663 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
664 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
667 ipp_attribute_t
* /* O - New attribute */
668 ippAddRanges(ipp_t
*ipp
, /* I - IPP message */
669 ipp_tag_t group
, /* I - IPP group */
670 const char *name
, /* I - Name of attribute */
671 int num_values
, /* I - Number of values */
672 const int *lower
, /* I - Lower values */
673 const int *upper
) /* I - Upper values */
675 int i
; /* Looping var */
676 ipp_attribute_t
*attr
; /* New attribute */
677 _ipp_value_t
*value
; /* Current value */
680 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
));
683 * Range check input...
686 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
687 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
692 * Create the attribute...
695 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, num_values
)) == NULL
)
700 for (i
= num_values
, value
= attr
->values
;
704 value
->range
.lower
= *lower
++;
705 value
->range
.upper
= *upper
++;
714 * 'ippAddResolution()' - Add a resolution value to an IPP message.
716 * The @code ipp@ parameter refers to an IPP message previously created using
717 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
719 * The @code group@ parameter specifies the IPP attribute group tag: none
720 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
721 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
722 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
723 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
726 ipp_attribute_t
* /* O - New attribute */
727 ippAddResolution(ipp_t
*ipp
, /* I - IPP message */
728 ipp_tag_t group
, /* I - IPP group */
729 const char *name
, /* I - Name of attribute */
730 ipp_res_t units
, /* I - Units for resolution */
731 int xres
, /* I - X resolution */
732 int yres
) /* I - Y resolution */
734 ipp_attribute_t
*attr
; /* New attribute */
737 DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", units=%d, xres=%d, yres=%d)", (void *)ipp
, group
,
738 ippTagString(group
), name
, units
, xres
, yres
));
741 * Range check input...
744 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
745 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
746 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
||
747 xres
< 0 || yres
< 0)
751 * Create the attribute...
754 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, 1)) == NULL
)
757 attr
->values
[0].resolution
.xres
= xres
;
758 attr
->values
[0].resolution
.yres
= yres
;
759 attr
->values
[0].resolution
.units
= units
;
766 * 'ippAddResolutions()' - Add resolution values to an IPP message.
768 * The @code ipp@ parameter refers to an IPP message previously created using
769 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
771 * The @code group@ parameter specifies the IPP attribute group tag: none
772 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
773 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
774 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
775 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
778 ipp_attribute_t
* /* O - New attribute */
779 ippAddResolutions(ipp_t
*ipp
, /* I - IPP message */
780 ipp_tag_t group
, /* I - IPP group */
781 const char *name
, /* I - Name of attribute */
782 int num_values
,/* I - Number of values */
783 ipp_res_t units
, /* I - Units for resolution */
784 const int *xres
, /* I - X resolutions */
785 const int *yres
) /* I - Y resolutions */
787 int i
; /* Looping var */
788 ipp_attribute_t
*attr
; /* New attribute */
789 _ipp_value_t
*value
; /* Current value */
792 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
));
795 * Range check input...
798 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
799 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
801 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
)
805 * Create the attribute...
808 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, num_values
)) == NULL
)
813 for (i
= num_values
, value
= attr
->values
;
817 value
->resolution
.xres
= *xres
++;
818 value
->resolution
.yres
= *yres
++;
819 value
->resolution
.units
= units
;
828 * 'ippAddSeparator()' - Add a group separator to an IPP message.
830 * The @code ipp@ parameter refers to an IPP message previously created using
831 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
834 ipp_attribute_t
* /* O - New attribute */
835 ippAddSeparator(ipp_t
*ipp
) /* I - IPP message */
837 DEBUG_printf(("ippAddSeparator(ipp=%p)", (void *)ipp
));
840 * Range check input...
847 * Create the attribute...
850 return (ipp_add_attr(ipp
, NULL
, IPP_TAG_ZERO
, IPP_TAG_ZERO
, 0));
855 * 'ippAddString()' - Add a language-encoded string to an IPP message.
857 * The @code ipp@ parameter refers to an IPP message previously created using
858 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
860 * The @code group@ parameter specifies the IPP attribute group tag: none
861 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
862 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
863 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
864 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
866 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
867 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
868 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
869 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
870 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
871 * (@code IPP_TAG_URISCHEME@).
873 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
874 * textWithLanguage string values and must be @code NULL@ for all other string values.
877 ipp_attribute_t
* /* O - New attribute */
878 ippAddString(ipp_t
*ipp
, /* I - IPP message */
879 ipp_tag_t group
, /* I - IPP group */
880 ipp_tag_t value_tag
, /* I - Type of attribute */
881 const char *name
, /* I - Name of attribute */
882 const char *language
, /* I - Language code */
883 const char *value
) /* I - Value */
885 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
886 ipp_attribute_t
*attr
; /* New attribute */
887 char code
[IPP_MAX_LANGUAGE
];
888 /* Charset/language code buffer */
891 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
));
894 * Range check input...
897 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
900 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
901 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
902 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
903 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
)
906 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
907 != (language
!= NULL
))
910 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
911 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
916 * See if we need to map charset, language, or locale values...
919 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
920 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
921 value_tag
= temp_tag
; /* Don't do a fast copy */
922 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
) &&
923 strcmp(value
, ipp_get_code(value
, code
, sizeof(code
))))
924 value_tag
= temp_tag
; /* Don't do a fast copy */
925 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
) &&
926 strcmp(value
, ipp_lang_code(value
, code
, sizeof(code
))))
927 value_tag
= temp_tag
; /* Don't do a fast copy */
930 * Create the attribute...
933 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
937 * Initialize the attribute data...
940 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
942 attr
->values
[0].string
.language
= (char *)language
;
943 attr
->values
[0].string
.text
= (char *)value
;
948 attr
->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
953 if (value_tag
== IPP_TAG_CHARSET
)
954 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_get_code(value
, code
,
956 else if (value_tag
== IPP_TAG_LANGUAGE
)
957 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_lang_code(value
, code
,
960 attr
->values
[0].string
.text
= _cupsStrAlloc(value
);
969 * 'ippAddStringf()' - Add a formatted string to an IPP message.
971 * The @code ipp@ parameter refers to an IPP message previously created using
972 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
974 * The @code group@ parameter specifies the IPP attribute group tag: none
975 * (@code IPP_TAG_ZERO@, for member attributes), document
976 * (@code IPP_TAG_DOCUMENT@), event notification
977 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
978 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
979 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
981 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
982 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
983 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
984 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
985 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
986 * (@code IPP_TAG_URISCHEME@).
988 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
989 * and textWithLanguage string values and must be @code NULL@ for all other
992 * The @code format@ parameter uses formatting characters compatible with the
993 * printf family of standard functions. Additional arguments follow it as
994 * needed. The formatted string is truncated as needed to the maximum length of
995 * the corresponding value type.
997 * @since CUPS 1.7/macOS 10.9@
1000 ipp_attribute_t
* /* O - New attribute */
1001 ippAddStringf(ipp_t
*ipp
, /* I - IPP message */
1002 ipp_tag_t group
, /* I - IPP group */
1003 ipp_tag_t value_tag
, /* I - Type of attribute */
1004 const char *name
, /* I - Name of attribute */
1005 const char *language
, /* I - Language code (@code NULL@ for default) */
1006 const char *format
, /* I - Printf-style format string */
1007 ...) /* I - Additional arguments as needed */
1009 ipp_attribute_t
*attr
; /* New attribute */
1010 va_list ap
; /* Argument pointer */
1013 va_start(ap
, format
);
1014 attr
= ippAddStringfv(ipp
, group
, value_tag
, name
, language
, format
, ap
);
1022 * 'ippAddStringfv()' - Add a formatted string to an IPP message.
1024 * The @code ipp@ parameter refers to an IPP message previously created using
1025 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1027 * The @code group@ parameter specifies the IPP attribute group tag: none
1028 * (@code IPP_TAG_ZERO@, for member attributes), document
1029 * (@code IPP_TAG_DOCUMENT@), event notification
1030 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1031 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1032 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1034 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1035 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1036 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1037 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1038 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1039 * (@code IPP_TAG_URISCHEME@).
1041 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1042 * and textWithLanguage string values and must be @code NULL@ for all other
1045 * The @code format@ parameter uses formatting characters compatible with the
1046 * printf family of standard functions. Additional arguments are passed in the
1047 * stdarg pointer @code ap@. The formatted string is truncated as needed to the
1048 * maximum length of the corresponding value type.
1050 * @since CUPS 1.7/macOS 10.9@
1053 ipp_attribute_t
* /* O - New attribute */
1054 ippAddStringfv(ipp_t
*ipp
, /* I - IPP message */
1055 ipp_tag_t group
, /* I - IPP group */
1056 ipp_tag_t value_tag
, /* I - Type of attribute */
1057 const char *name
, /* I - Name of attribute */
1058 const char *language
, /* I - Language code (@code NULL@ for default) */
1059 const char *format
, /* I - Printf-style format string */
1060 va_list ap
) /* I - Additional arguments */
1062 char buffer
[IPP_MAX_TEXT
+ 4];
1063 /* Formatted text string */
1064 ssize_t bytes
, /* Length of formatted value */
1065 max_bytes
; /* Maximum number of bytes for value */
1069 * Range check input...
1072 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1073 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1074 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
1075 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
1079 if ((value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_NAMELANG
)
1080 != (language
!= NULL
))
1084 * Format the string...
1087 if (!strcmp(format
, "%s"))
1090 * Optimize the simple case...
1093 const char *s
= va_arg(ap
, char *);
1098 bytes
= (ssize_t
)strlen(s
);
1099 strlcpy(buffer
, s
, sizeof(buffer
));
1104 * Do a full formatting of the message...
1107 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
1112 * Limit the length of the string...
1119 case IPP_TAG_TEXTLANG
:
1120 max_bytes
= IPP_MAX_TEXT
;
1124 case IPP_TAG_NAMELANG
:
1125 max_bytes
= IPP_MAX_NAME
;
1128 case IPP_TAG_CHARSET
:
1129 max_bytes
= IPP_MAX_CHARSET
;
1132 case IPP_TAG_KEYWORD
:
1133 max_bytes
= IPP_MAX_KEYWORD
;
1136 case IPP_TAG_LANGUAGE
:
1137 max_bytes
= IPP_MAX_LANGUAGE
;
1140 case IPP_TAG_MIMETYPE
:
1141 max_bytes
= IPP_MAX_MIMETYPE
;
1145 max_bytes
= IPP_MAX_URI
;
1148 case IPP_TAG_URISCHEME
:
1149 max_bytes
= IPP_MAX_URISCHEME
;
1153 if (bytes
>= max_bytes
)
1155 char *bufmax
, /* Buffer at max_bytes */
1156 *bufptr
; /* Pointer into buffer */
1158 bufptr
= buffer
+ strlen(buffer
) - 1;
1159 bufmax
= buffer
+ max_bytes
- 1;
1161 while (bufptr
> bufmax
)
1165 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
1176 * Add the formatted string and return...
1179 return (ippAddString(ipp
, group
, value_tag
, name
, language
, buffer
));
1184 * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
1186 * The @code ipp@ parameter refers to an IPP message previously created using
1187 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1189 * The @code group@ parameter specifies the IPP attribute group tag: none
1190 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
1191 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
1192 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
1193 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1195 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1196 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1197 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1198 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1199 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1200 * (@code IPP_TAG_URISCHEME@).
1202 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1203 * textWithLanguage string values and must be @code NULL@ for all other string values.
1206 ipp_attribute_t
* /* O - New attribute */
1208 ipp_t
*ipp
, /* I - IPP message */
1209 ipp_tag_t group
, /* I - IPP group */
1210 ipp_tag_t value_tag
, /* I - Type of attribute */
1211 const char *name
, /* I - Name of attribute */
1212 int num_values
, /* I - Number of values */
1213 const char *language
, /* I - Language code (@code NULL@ for default) */
1214 const char * const *values
) /* I - Values */
1216 int i
; /* Looping var */
1217 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1218 ipp_attribute_t
*attr
; /* New attribute */
1219 _ipp_value_t
*value
; /* Current value */
1220 char code
[32]; /* Language/charset value buffer */
1223 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
));
1226 * Range check input...
1229 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
1232 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1233 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1234 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1235 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
||
1239 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1240 != (language
!= NULL
))
1243 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1244 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1250 * See if we need to map charset, language, or locale values...
1253 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
1254 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1255 value_tag
= temp_tag
; /* Don't do a fast copy */
1256 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
))
1258 for (i
= 0; i
< num_values
; i
++)
1259 if (strcmp(values
[i
], ipp_get_code(values
[i
], code
, sizeof(code
))))
1261 value_tag
= temp_tag
; /* Don't do a fast copy */
1265 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
))
1267 for (i
= 0; i
< num_values
; i
++)
1268 if (strcmp(values
[i
], ipp_lang_code(values
[i
], code
, sizeof(code
))))
1270 value_tag
= temp_tag
; /* Don't do a fast copy */
1276 * Create the attribute...
1279 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
1283 * Initialize the attribute data...
1286 for (i
= num_values
, value
= attr
->values
;
1292 if (value
== attr
->values
)
1294 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1295 value
->string
.language
= (char *)language
;
1297 value
->string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1301 value
->string
.language
= attr
->values
[0].string
.language
;
1306 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1307 value
->string
.text
= (char *)*values
++;
1308 else if (value_tag
== IPP_TAG_CHARSET
)
1309 value
->string
.text
= _cupsStrAlloc(ipp_get_code(*values
++, code
, sizeof(code
)));
1310 else if (value_tag
== IPP_TAG_LANGUAGE
)
1311 value
->string
.text
= _cupsStrAlloc(ipp_lang_code(*values
++, code
, sizeof(code
)));
1313 value
->string
.text
= _cupsStrAlloc(*values
++);
1322 * 'ippContainsInteger()' - Determine whether an attribute contains the
1323 * specified value or is within the list of ranges.
1325 * Returns non-zero when the attribute contains either a matching integer or
1326 * enum value, or the value falls within one of the rangeOfInteger values for
1329 * @since CUPS 1.7/macOS 10.9@
1332 int /* O - 1 on a match, 0 on no match */
1334 ipp_attribute_t
*attr
, /* I - Attribute */
1335 int value
) /* I - Integer/enum value */
1337 int i
; /* Looping var */
1338 _ipp_value_t
*avalue
; /* Current attribute value */
1342 * Range check input...
1348 if (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
&&
1349 attr
->value_tag
!= IPP_TAG_RANGE
)
1356 if (attr
->value_tag
== IPP_TAG_RANGE
)
1358 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1359 if (value
>= avalue
->range
.lower
&& value
<= avalue
->range
.upper
)
1364 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1365 if (value
== avalue
->integer
)
1374 * 'ippContainsString()' - Determine whether an attribute contains the
1375 * specified string value.
1377 * Returns non-zero when the attribute contains a matching charset, keyword,
1378 * naturalLanguage, mimeMediaType, name, text, uri, or uriScheme value.
1380 * @since CUPS 1.7/macOS 10.9@
1383 int /* O - 1 on a match, 0 on no match */
1385 ipp_attribute_t
*attr
, /* I - Attribute */
1386 const char *value
) /* I - String value */
1388 int i
; /* Looping var */
1389 _ipp_value_t
*avalue
; /* Current attribute value */
1392 DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", (void *)attr
, value
));
1395 * Range check input...
1398 if (!attr
|| !value
)
1400 DEBUG_puts("1ippContainsString: Returning 0 (bad input)");
1408 DEBUG_printf(("1ippContainsString: attr %s, %s with %d values.",
1409 attr
->name
, ippTagString(attr
->value_tag
),
1412 switch (attr
->value_tag
& IPP_TAG_CUPS_MASK
)
1414 case IPP_TAG_CHARSET
:
1415 case IPP_TAG_KEYWORD
:
1416 case IPP_TAG_LANGUAGE
:
1418 case IPP_TAG_URISCHEME
:
1419 for (i
= attr
->num_values
, avalue
= attr
->values
;
1423 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1424 attr
->num_values
- i
, avalue
->string
.text
));
1426 if (!strcmp(value
, avalue
->string
.text
))
1428 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1433 case IPP_TAG_MIMETYPE
:
1435 case IPP_TAG_NAMELANG
:
1437 case IPP_TAG_TEXTLANG
:
1438 for (i
= attr
->num_values
, avalue
= attr
->values
;
1442 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1443 attr
->num_values
- i
, avalue
->string
.text
));
1445 if (!_cups_strcasecmp(value
, avalue
->string
.text
))
1447 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1456 DEBUG_puts("1ippContainsString: Returning 0 (no match)");
1463 * 'ippCopyAttribute()' - Copy an attribute.
1465 * The specified attribute, @code attr@, is copied to the destination IPP message.
1466 * When @code quickcopy@ is non-zero, a "shallow" reference copy of the attribute is
1467 * created - this should only be done as long as the original source IPP message will
1468 * not be freed for the life of the destination.
1470 * @since CUPS 1.6/macOS 10.8@
1474 ipp_attribute_t
* /* O - New attribute */
1476 ipp_t
*dst
, /* I - Destination IPP message */
1477 ipp_attribute_t
*srcattr
, /* I - Attribute to copy */
1478 int quickcopy
) /* I - 1 for a referenced copy, 0 for normal */
1480 int i
; /* Looping var */
1481 ipp_attribute_t
*dstattr
; /* Destination attribute */
1482 _ipp_value_t
*srcval
, /* Source value */
1483 *dstval
; /* Destination value */
1486 DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", (void *)dst
, (void *)srcattr
, quickcopy
));
1489 * Range check input...
1492 if (!dst
|| !srcattr
)
1499 quickcopy
= quickcopy
? IPP_TAG_CUPS_CONST
: 0;
1501 switch (srcattr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
1504 dstattr
= ippAddSeparator(dst
);
1507 case IPP_TAG_UNSUPPORTED_VALUE
:
1508 case IPP_TAG_DEFAULT
:
1509 case IPP_TAG_UNKNOWN
:
1510 case IPP_TAG_NOVALUE
:
1511 case IPP_TAG_NOTSETTABLE
:
1512 case IPP_TAG_DELETEATTR
:
1513 case IPP_TAG_ADMINDEFINE
:
1514 dstattr
= ippAddOutOfBand(dst
, srcattr
->group_tag
, srcattr
->value_tag
& ~IPP_TAG_CUPS_CONST
, srcattr
->name
);
1517 case IPP_TAG_INTEGER
:
1519 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1520 srcattr
->name
, srcattr
->num_values
, NULL
);
1524 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1526 i
--, srcval
++, dstval
++)
1527 dstval
->integer
= srcval
->integer
;
1530 case IPP_TAG_BOOLEAN
:
1531 dstattr
= ippAddBooleans(dst
, srcattr
->group_tag
, srcattr
->name
,
1532 srcattr
->num_values
, NULL
);
1536 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1538 i
--, srcval
++, dstval
++)
1539 dstval
->boolean
= srcval
->boolean
;
1544 case IPP_TAG_KEYWORD
:
1546 case IPP_TAG_URISCHEME
:
1547 case IPP_TAG_CHARSET
:
1548 case IPP_TAG_LANGUAGE
:
1549 case IPP_TAG_MIMETYPE
:
1550 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1551 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1552 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1558 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1559 dstval
= dstattr
->values
;
1561 i
--, srcval
++, dstval
++)
1562 dstval
->string
.text
= srcval
->string
.text
;
1564 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1566 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1567 dstval
= dstattr
->values
;
1569 i
--, srcval
++, dstval
++)
1570 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1574 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1575 dstval
= dstattr
->values
;
1577 i
--, srcval
++, dstval
++)
1578 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1583 if (srcattr
->num_values
!= 1)
1586 dstattr
= ippAddDate(dst
, srcattr
->group_tag
, srcattr
->name
,
1587 srcattr
->values
[0].date
);
1590 case IPP_TAG_RESOLUTION
:
1591 dstattr
= ippAddResolutions(dst
, srcattr
->group_tag
, srcattr
->name
,
1592 srcattr
->num_values
, IPP_RES_PER_INCH
,
1597 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1599 i
--, srcval
++, dstval
++)
1601 dstval
->resolution
.xres
= srcval
->resolution
.xres
;
1602 dstval
->resolution
.yres
= srcval
->resolution
.yres
;
1603 dstval
->resolution
.units
= srcval
->resolution
.units
;
1607 case IPP_TAG_RANGE
:
1608 dstattr
= ippAddRanges(dst
, srcattr
->group_tag
, srcattr
->name
,
1609 srcattr
->num_values
, NULL
, NULL
);
1613 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1615 i
--, srcval
++, dstval
++)
1617 dstval
->range
.lower
= srcval
->range
.lower
;
1618 dstval
->range
.upper
= srcval
->range
.upper
;
1622 case IPP_TAG_TEXTLANG
:
1623 case IPP_TAG_NAMELANG
:
1624 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1625 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1626 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1632 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1633 dstval
= dstattr
->values
;
1635 i
--, srcval
++, dstval
++)
1637 dstval
->string
.language
= srcval
->string
.language
;
1638 dstval
->string
.text
= srcval
->string
.text
;
1641 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1643 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1644 dstval
= dstattr
->values
;
1646 i
--, srcval
++, dstval
++)
1648 if (srcval
== srcattr
->values
)
1649 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1651 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1653 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1658 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1659 dstval
= dstattr
->values
;
1661 i
--, srcval
++, dstval
++)
1663 if (srcval
== srcattr
->values
)
1664 dstval
->string
.language
= _cupsStrRetain(srcval
->string
.language
);
1666 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1668 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1673 case IPP_TAG_BEGIN_COLLECTION
:
1674 dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
,
1675 srcattr
->num_values
, NULL
);
1679 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1681 i
--, srcval
++, dstval
++)
1683 dstval
->collection
= srcval
->collection
;
1684 srcval
->collection
->use
++;
1688 case IPP_TAG_STRING
:
1690 /* TODO: Implement quick copy for unknown/octetString values */
1691 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1692 srcattr
->name
, srcattr
->num_values
, NULL
);
1696 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1698 i
--, srcval
++, dstval
++)
1700 dstval
->unknown
.length
= srcval
->unknown
.length
;
1702 if (dstval
->unknown
.length
> 0)
1704 if ((dstval
->unknown
.data
= malloc((size_t)dstval
->unknown
.length
)) == NULL
)
1705 dstval
->unknown
.length
= 0;
1707 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, (size_t)dstval
->unknown
.length
);
1710 break; /* anti-compiler-warning-code */
1718 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1720 * Zero or more attributes are copied from the source IPP message, @code src@, to the
1721 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1722 * reference copy of the attribute is created - this should only be done as long as the
1723 * original source IPP message will not be freed for the life of the destination.
1725 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1726 * attributes that are copied - the function must return 1 to copy the attribute or
1727 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1730 * @since CUPS 1.6/macOS 10.8@
1733 int /* O - 1 on success, 0 on error */
1735 ipp_t
*dst
, /* I - Destination IPP message */
1736 ipp_t
*src
, /* I - Source IPP message */
1737 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1738 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1739 void *context
) /* I - Context pointer */
1741 ipp_attribute_t
*srcattr
; /* Source attribute */
1744 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)", (void *)dst
, (void *)src
, quickcopy
, (void *)cb
, context
));
1747 * Range check input...
1754 * Loop through source attributes and copy as needed...
1757 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1758 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1759 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1767 * 'ippDateToTime()' - Convert from RFC 2579 Date/Time format to time in
1771 time_t /* O - UNIX time value */
1772 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 2579 date info */
1774 struct tm unixdate
; /* UNIX date/time info */
1775 time_t t
; /* Computed time */
1781 memset(&unixdate
, 0, sizeof(unixdate
));
1784 * RFC-2579 date/time format is:
1786 * Byte(s) Description
1787 * ------- -----------
1788 * 0-1 Year (0 to 65535)
1792 * 5 Minutes (0 to 59)
1793 * 6 Seconds (0 to 60, 60 = "leap second")
1794 * 7 Deciseconds (0 to 9)
1796 * 9 UTC hours (0 to 11)
1797 * 10 UTC minutes (0 to 59)
1800 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1801 unixdate
.tm_mon
= date
[2] - 1;
1802 unixdate
.tm_mday
= date
[3];
1803 unixdate
.tm_hour
= date
[4];
1804 unixdate
.tm_min
= date
[5];
1805 unixdate
.tm_sec
= date
[6];
1807 t
= mktime(&unixdate
);
1810 t
+= date
[9] * 3600 + date
[10] * 60;
1812 t
-= date
[9] * 3600 + date
[10] * 60;
1819 * 'ippDelete()' - Delete an IPP message.
1823 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1825 ipp_attribute_t
*attr
, /* Current attribute */
1826 *next
; /* Next attribute */
1829 DEBUG_printf(("ippDelete(ipp=%p)", (void *)ipp
));
1837 DEBUG_printf(("4debug_retain: %p IPP message (use=%d)", (void *)ipp
, ipp
->use
));
1841 DEBUG_printf(("4debug_free: %p IPP message", (void *)ipp
));
1843 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1847 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
));
1849 ipp_free_values(attr
, 0, attr
->num_values
);
1852 _cupsStrFree(attr
->name
);
1862 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1864 * @since CUPS 1.1.19/macOS 10.3@
1869 ipp_t
*ipp
, /* I - IPP message */
1870 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1872 ipp_attribute_t
*current
, /* Current attribute */
1873 *prev
; /* Previous attribute */
1876 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", (void *)ipp
, (void *)attr
, attr
? attr
->name
: "(null)"));
1879 * Range check input...
1885 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
));
1888 * Find the attribute in the list...
1893 for (current
= ipp
->attrs
, prev
= NULL
;
1895 prev
= current
, current
= current
->next
)
1896 if (current
== attr
)
1899 * Found it, remove the attribute from the list...
1903 prev
->next
= current
->next
;
1905 ipp
->attrs
= current
->next
;
1907 if (current
== ipp
->last
)
1918 * Free memory used by the attribute...
1921 ipp_free_values(attr
, 0, attr
->num_values
);
1924 _cupsStrFree(attr
->name
);
1931 * 'ippDeleteValues()' - Delete values in an attribute.
1933 * The @code element@ parameter specifies the first value to delete, starting at
1934 * 0. It must be less than the number of values returned by @link ippGetCount@.
1936 * The @code attr@ parameter may be modified as a result of setting the value.
1938 * Deleting all values in an attribute deletes the attribute.
1940 * @since CUPS 1.6/macOS 10.8@
1943 int /* O - 1 on success, 0 on failure */
1945 ipp_t
*ipp
, /* I - IPP message */
1946 ipp_attribute_t
**attr
, /* IO - Attribute */
1947 int element
, /* I - Index of first value to delete (0-based) */
1948 int count
) /* I - Number of values to delete */
1951 * Range check input...
1954 if (!ipp
|| !attr
|| !*attr
||
1955 element
< 0 || element
>= (*attr
)->num_values
|| count
<= 0 ||
1956 (element
+ count
) >= (*attr
)->num_values
)
1960 * If we are deleting all values, just delete the attribute entirely.
1963 if (count
== (*attr
)->num_values
)
1965 ippDeleteAttribute(ipp
, *attr
);
1971 * Otherwise free the values in question and return.
1974 ipp_free_values(*attr
, element
, count
);
1981 * 'ippFindAttribute()' - Find a named attribute in a request.
1983 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1984 * of attribute and member names separated by slashes, for example
1985 * "media-col/media-size".
1988 ipp_attribute_t
* /* O - Matching attribute */
1989 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
1990 const char *name
, /* I - Name of attribute */
1991 ipp_tag_t type
) /* I - Type of attribute */
1993 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
1999 * Reset the current pointer...
2002 ipp
->current
= NULL
;
2006 * Search for the attribute...
2009 return (ippFindNextAttribute(ipp
, name
, type
));
2014 * 'ippFindNextAttribute()' - Find the next named attribute in a request.
2016 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
2017 * of attribute and member names separated by slashes, for example
2018 * "media-col/media-size".
2021 ipp_attribute_t
* /* O - Matching attribute */
2022 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
2023 const char *name
, /* I - Name of attribute */
2024 ipp_tag_t type
) /* I - Type of attribute */
2026 ipp_attribute_t
*attr
, /* Current atttribute */
2027 *childattr
; /* Child attribute */
2028 ipp_tag_t value_tag
; /* Value tag */
2029 char parent
[1024], /* Parent attribute name */
2030 *child
= NULL
; /* Child attribute name */
2033 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
2038 DEBUG_printf(("3ippFindNextAttribute: atend=%d", ipp
->atend
));
2043 if (strchr(name
, '/'))
2046 * Search for child attribute...
2049 strlcpy(parent
, name
, sizeof(parent
));
2050 if ((child
= strchr(parent
, '/')) == NULL
)
2052 DEBUG_puts("3ippFindNextAttribute: Attribute name too long.");
2058 if (ipp
->current
&& ipp
->current
->name
&& ipp
->current
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&& !strcmp(parent
, ipp
->current
->name
))
2060 while (ipp
->curindex
< ipp
->current
->num_values
)
2062 if ((childattr
= ippFindNextAttribute(ipp
->current
->values
[ipp
->curindex
].collection
, child
, type
)) != NULL
)
2066 if (ipp
->curindex
< ipp
->current
->num_values
&& ipp
->current
->values
[ipp
->curindex
].collection
)
2067 ipp
->current
->values
[ipp
->curindex
].collection
->current
= NULL
;
2070 ipp
->prev
= ipp
->current
;
2071 ipp
->current
= ipp
->current
->next
;
2084 ipp
->current
= ipp
->attrs
;
2089 attr
= ipp
->current
;
2091 else if (ipp
->current
)
2093 ipp
->prev
= ipp
->current
;
2094 attr
= ipp
->current
->next
;
2102 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
2104 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", (void *)attr
, attr
->name
));
2106 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2108 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
2109 (value_tag
== type
|| type
== IPP_TAG_ZERO
|| name
== parent
||
2110 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
2111 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
2113 ipp
->current
= attr
;
2115 if (name
== parent
&& attr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
)
2117 int i
; /* Looping var */
2119 for (i
= 0; i
< attr
->num_values
; i
++)
2121 if ((childattr
= ippFindAttribute(attr
->values
[i
].collection
, child
, type
)) != NULL
)
2123 attr
->values
[0].collection
->curindex
= i
;
2133 ipp
->current
= NULL
;
2142 * 'ippFirstAttribute()' - Return the first attribute in the message.
2144 * @since CUPS 1.6/macOS 10.8@
2147 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
2148 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
2151 * Range check input...
2158 * Return the first attribute...
2161 return (ipp
->current
= ipp
->attrs
);
2166 * 'ippGetBoolean()' - Get a boolean value for an attribute.
2168 * The @code element@ parameter specifies which value to get from 0 to
2169 * @code ippGetCount(attr)@ - 1.
2171 * @since CUPS 1.6/macOS 10.8@
2174 int /* O - Boolean value or 0 on error */
2175 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
2176 int element
) /* I - Value number (0-based) */
2179 * Range check input...
2182 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
2183 element
< 0 || element
>= attr
->num_values
)
2187 * Return the value...
2190 return (attr
->values
[element
].boolean
);
2195 * 'ippGetCollection()' - Get a collection value for an attribute.
2197 * The @code element@ parameter specifies which value to get from 0 to
2198 * @code ippGetCount(attr)@ - 1.
2200 * @since CUPS 1.6/macOS 10.8@
2203 ipp_t
* /* O - Collection value or @code NULL@ on error */
2205 ipp_attribute_t
*attr
, /* I - IPP attribute */
2206 int element
) /* I - Value number (0-based) */
2209 * Range check input...
2212 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
2213 element
< 0 || element
>= attr
->num_values
)
2217 * Return the value...
2220 return (attr
->values
[element
].collection
);
2225 * 'ippGetCount()' - Get the number of values in an attribute.
2227 * @since CUPS 1.6/macOS 10.8@
2230 int /* O - Number of values or 0 on error */
2231 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
2234 * Range check input...
2241 * Return the number of values...
2244 return (attr
->num_values
);
2249 * 'ippGetDate()' - Get a dateTime value for an attribute.
2251 * The @code element@ parameter specifies which value to get from 0 to
2252 * @code ippGetCount(attr)@ - 1.
2254 * @since CUPS 1.6/macOS 10.8@
2257 const ipp_uchar_t
* /* O - dateTime value or @code NULL@ */
2258 ippGetDate(ipp_attribute_t
*attr
, /* I - IPP attribute */
2259 int element
) /* I - Value number (0-based) */
2262 * Range check input...
2265 if (!attr
|| attr
->value_tag
!= IPP_TAG_DATE
||
2266 element
< 0 || element
>= attr
->num_values
)
2270 * Return the value...
2273 return (attr
->values
[element
].date
);
2278 * 'ippGetGroupTag()' - Get the group associated with an attribute.
2280 * @since CUPS 1.6/macOS 10.8@
2283 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
2284 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2287 * Range check input...
2291 return (IPP_TAG_ZERO
);
2294 * Return the group...
2297 return (attr
->group_tag
);
2302 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
2304 * The @code element@ parameter specifies which value to get from 0 to
2305 * @code ippGetCount(attr)@ - 1.
2307 * @since CUPS 1.6/macOS 10.8@
2310 int /* O - Value or 0 on error */
2311 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
2312 int element
) /* I - Value number (0-based) */
2315 * Range check input...
2318 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
2319 element
< 0 || element
>= attr
->num_values
)
2323 * Return the value...
2326 return (attr
->values
[element
].integer
);
2331 * 'ippGetName()' - Get the attribute name.
2333 * @since CUPS 1.6/macOS 10.8@
2336 const char * /* O - Attribute name or @code NULL@ for separators */
2337 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
2340 * Range check input...
2347 * Return the name...
2350 return (attr
->name
);
2355 * 'ippGetOctetString()' - Get an octetString value from an IPP attribute.
2357 * The @code element@ parameter specifies which value to get from 0 to
2358 * @code ippGetCount(attr)@ - 1.
2360 * @since CUPS 1.7/macOS 10.9@
2363 void * /* O - Pointer to octetString data */
2365 ipp_attribute_t
*attr
, /* I - IPP attribute */
2366 int element
, /* I - Value number (0-based) */
2367 int *datalen
) /* O - Length of octetString data */
2370 * Range check input...
2373 if (!attr
|| attr
->value_tag
!= IPP_TAG_STRING
||
2374 element
< 0 || element
>= attr
->num_values
)
2383 * Return the values...
2387 *datalen
= attr
->values
[element
].unknown
.length
;
2389 return (attr
->values
[element
].unknown
.data
);
2394 * 'ippGetOperation()' - Get the operation ID in an IPP message.
2396 * @since CUPS 1.6/macOS 10.8@
2399 ipp_op_t
/* O - Operation ID or 0 on error */
2400 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
2403 * Range check input...
2407 return ((ipp_op_t
)0);
2410 * Return the value...
2413 return (ipp
->request
.op
.operation_id
);
2418 * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
2420 * The @code element@ parameter specifies which value to get from 0 to
2421 * @code ippGetCount(attr)@ - 1.
2423 * @since CUPS 1.6/macOS 10.8@
2426 int /* O - Lower value of range or 0 */
2427 ippGetRange(ipp_attribute_t
*attr
, /* I - IPP attribute */
2428 int element
, /* I - Value number (0-based) */
2429 int *uppervalue
)/* O - Upper value of range */
2432 * Range check input...
2435 if (!attr
|| attr
->value_tag
!= IPP_TAG_RANGE
||
2436 element
< 0 || element
>= attr
->num_values
)
2445 * Return the values...
2449 *uppervalue
= attr
->values
[element
].range
.upper
;
2451 return (attr
->values
[element
].range
.lower
);
2456 * 'ippGetRequestId()' - Get the request ID from an IPP message.
2458 * @since CUPS 1.6/macOS 10.8@
2461 int /* O - Request ID or 0 on error */
2462 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
2465 * Range check input...
2472 * Return the request ID...
2475 return (ipp
->request
.any
.request_id
);
2480 * 'ippGetResolution()' - Get a resolution value for an attribute.
2482 * The @code element@ parameter specifies which value to get from 0 to
2483 * @code ippGetCount(attr)@ - 1.
2485 * @since CUPS 1.6/macOS 10.8@
2488 int /* O - Horizontal/cross feed resolution or 0 */
2490 ipp_attribute_t
*attr
, /* I - IPP attribute */
2491 int element
, /* I - Value number (0-based) */
2492 int *yres
, /* O - Vertical/feed resolution */
2493 ipp_res_t
*units
) /* O - Units for resolution */
2496 * Range check input...
2499 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
2500 element
< 0 || element
>= attr
->num_values
)
2506 *units
= (ipp_res_t
)0;
2512 * Return the value...
2516 *yres
= attr
->values
[element
].resolution
.yres
;
2519 *units
= attr
->values
[element
].resolution
.units
;
2521 return (attr
->values
[element
].resolution
.xres
);
2526 * 'ippGetState()' - Get the IPP message state.
2528 * @since CUPS 1.6/macOS 10.8@
2531 ipp_state_t
/* O - IPP message state value */
2532 ippGetState(ipp_t
*ipp
) /* I - IPP message */
2535 * Range check input...
2539 return (IPP_STATE_IDLE
);
2542 * Return the value...
2545 return (ipp
->state
);
2550 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2552 * @since CUPS 1.6/macOS 10.8@
2555 ipp_status_t
/* O - Status code in IPP message */
2556 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2559 * Range check input...
2563 return (IPP_STATUS_ERROR_INTERNAL
);
2566 * Return the value...
2569 return (ipp
->request
.status
.status_code
);
2574 * 'ippGetString()' - Get the string and optionally the language code for an attribute.
2576 * The @code element@ parameter specifies which value to get from 0 to
2577 * @code ippGetCount(attr)@ - 1.
2579 * @since CUPS 1.6/macOS 10.8@
2583 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2584 int element
, /* I - Value number (0-based) */
2585 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2587 ipp_tag_t tag
; /* Value tag */
2591 * Range check input...
2594 tag
= ippGetValueTag(attr
);
2596 if (!attr
|| element
< 0 || element
>= attr
->num_values
|| (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&& (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
)))
2600 * Return the value...
2604 *language
= attr
->values
[element
].string
.language
;
2606 return (attr
->values
[element
].string
.text
);
2611 * 'ippGetValueTag()' - Get the value tag for an attribute.
2613 * @since CUPS 1.6/macOS 10.8@
2616 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2617 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2620 * Range check input...
2624 return (IPP_TAG_ZERO
);
2627 * Return the value...
2630 return (attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2635 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2637 * @since CUPS 1.6/macOS 10.8@
2640 int /* O - Major version number or 0 on error */
2641 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2642 int *minor
) /* O - Minor version number or @code NULL@ for don't care */
2645 * Range check input...
2657 * Return the value...
2661 *minor
= ipp
->request
.any
.version
[1];
2663 return (ipp
->request
.any
.version
[0]);
2668 * 'ippLength()' - Compute the length of an IPP message.
2671 size_t /* O - Size of IPP message */
2672 ippLength(ipp_t
*ipp
) /* I - IPP message */
2674 return (ipp_length(ipp
, 0));
2679 * 'ippNextAttribute()' - Return the next attribute in the message.
2681 * @since CUPS 1.6/macOS 10.8@
2684 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2685 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2688 * Range check input...
2691 if (!ipp
|| !ipp
->current
)
2695 * Return the next attribute...
2698 return (ipp
->current
= ipp
->current
->next
);
2703 * 'ippNew()' - Allocate a new IPP message.
2706 ipp_t
* /* O - New IPP message */
2709 ipp_t
*temp
; /* New IPP message */
2710 _cups_globals_t
*cg
= _cupsGlobals();
2714 DEBUG_puts("ippNew()");
2716 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2719 * Set default version - usually 2.0...
2722 DEBUG_printf(("4debug_alloc: %p IPP message", (void *)temp
));
2724 if (cg
->server_version
== 0)
2727 temp
->request
.any
.version
[0] = (ipp_uchar_t
)(cg
->server_version
/ 10);
2728 temp
->request
.any
.version
[1] = (ipp_uchar_t
)(cg
->server_version
% 10);
2732 DEBUG_printf(("1ippNew: Returning %p", (void *)temp
));
2739 * 'ippNewRequest()' - Allocate a new IPP request message.
2741 * The new request message is initialized with the "attributes-charset" and
2742 * "attributes-natural-language" attributes added. The
2743 * "attributes-natural-language" value is derived from the current locale.
2745 * @since CUPS 1.2/macOS 10.5@
2748 ipp_t
* /* O - IPP request message */
2749 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2751 ipp_t
*request
; /* IPP request message */
2752 cups_lang_t
*language
; /* Current language localization */
2753 static int request_id
= 0; /* Current request ID */
2754 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2755 /* Mutex for request ID */
2758 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2761 * Create a new IPP message...
2764 if ((request
= ippNew()) == NULL
)
2768 * Set the operation and request ID...
2771 _cupsMutexLock(&request_mutex
);
2773 request
->request
.op
.operation_id
= op
;
2774 request
->request
.op
.request_id
= ++request_id
;
2776 _cupsMutexUnlock(&request_mutex
);
2779 * Use UTF-8 as the character set...
2782 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2783 "attributes-charset", NULL
, "utf-8");
2786 * Get the language from the current locale...
2789 language
= cupsLangDefault();
2791 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2792 "attributes-natural-language", NULL
, language
->language
);
2795 * Return the new request...
2803 * 'ippNewResponse()' - Allocate a new IPP response message.
2805 * The new response message is initialized with the same "version-number",
2806 * "request-id", "attributes-charset", and "attributes-natural-language" as the
2807 * provided request message. If the "attributes-charset" or
2808 * "attributes-natural-language" attributes are missing from the request,
2809 * 'utf-8' and a value derived from the current locale are substituted,
2812 * @since CUPS 1.7/macOS 10.9@
2815 ipp_t
* /* O - IPP response message */
2816 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2818 ipp_t
*response
; /* IPP response message */
2819 ipp_attribute_t
*attr
; /* Current attribute */
2823 * Range check input...
2830 * Create a new IPP message...
2833 if ((response
= ippNew()) == NULL
)
2837 * Copy the request values over to the response...
2840 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2841 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2842 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2845 * The first attribute MUST be attributes-charset...
2848 attr
= request
->attrs
;
2850 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2851 attr
->group_tag
== IPP_TAG_OPERATION
&&
2852 attr
->value_tag
== IPP_TAG_CHARSET
&&
2853 attr
->num_values
== 1)
2856 * Copy charset from request...
2859 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2860 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2865 * Use "utf-8" as the default...
2868 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2869 "attributes-charset", NULL
, "utf-8");
2873 * Then attributes-natural-language...
2879 if (attr
&& attr
->name
&&
2880 !strcmp(attr
->name
, "attributes-natural-language") &&
2881 attr
->group_tag
== IPP_TAG_OPERATION
&&
2882 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2883 attr
->num_values
== 1)
2886 * Copy language from request...
2889 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2890 "attributes-natural-language", NULL
,
2891 attr
->values
[0].string
.text
);
2896 * Use the language from the current locale...
2899 cups_lang_t
*language
= cupsLangDefault();
2900 /* Current locale */
2902 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2903 "attributes-natural-language", NULL
, language
->language
);
2911 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2914 ipp_state_t
/* O - Current state */
2915 ippRead(http_t
*http
, /* I - HTTP connection */
2916 ipp_t
*ipp
) /* I - IPP data */
2918 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
, (void *)http
, (void *)ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2921 return (IPP_STATE_ERROR
);
2923 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
, http
->used
));
2925 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2931 * 'ippReadFile()' - Read data for an IPP message from a file.
2933 * @since CUPS 1.1.19/macOS 10.3@
2936 ipp_state_t
/* O - Current state */
2937 ippReadFile(int fd
, /* I - HTTP data */
2938 ipp_t
*ipp
) /* I - IPP data */
2940 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
2942 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2947 * 'ippReadIO()' - Read data for an IPP message.
2949 * @since CUPS 1.2/macOS 10.5@
2952 ipp_state_t
/* O - Current state */
2953 ippReadIO(void *src
, /* I - Data source */
2954 ipp_iocb_t cb
, /* I - Read callback function */
2955 int blocking
, /* I - Use blocking IO? */
2956 ipp_t
*parent
, /* I - Parent request, if any */
2957 ipp_t
*ipp
) /* I - IPP data */
2959 int n
; /* Length of data */
2960 unsigned char *buffer
, /* Data buffer */
2961 string
[IPP_MAX_TEXT
],
2962 /* Small string buffer */
2963 *bufptr
; /* Pointer into buffer */
2964 ipp_attribute_t
*attr
; /* Current attribute */
2965 ipp_tag_t tag
; /* Current tag */
2966 ipp_tag_t value_tag
; /* Current value tag */
2967 _ipp_value_t
*value
; /* Current value */
2970 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)src
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
2971 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_STATE_ERROR
));
2974 return (IPP_STATE_ERROR
);
2976 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2978 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2979 return (IPP_STATE_ERROR
);
2984 case IPP_STATE_IDLE
:
2985 ipp
->state
++; /* Avoid common problem... */
2987 case IPP_STATE_HEADER
:
2991 * Get the request header...
2994 if ((*cb
)(src
, buffer
, 8) < 8)
2996 DEBUG_puts("1ippReadIO: Unable to read header.");
2997 _cupsBufferRelease((char *)buffer
);
2998 return (IPP_STATE_ERROR
);
3002 * Then copy the request header over...
3005 ipp
->request
.any
.version
[0] = buffer
[0];
3006 ipp
->request
.any
.version
[1] = buffer
[1];
3007 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
3008 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
3009 buffer
[6]) << 8) | buffer
[7];
3011 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
3012 DEBUG_printf(("2ippReadIO: op_status=%04x",
3013 ipp
->request
.any
.op_status
));
3014 DEBUG_printf(("2ippReadIO: request_id=%d",
3015 ipp
->request
.any
.request_id
));
3018 ipp
->state
= IPP_STATE_ATTRIBUTE
;
3019 ipp
->current
= NULL
;
3020 ipp
->curtag
= IPP_TAG_ZERO
;
3021 ipp
->prev
= ipp
->last
;
3024 * If blocking is disabled, stop here...
3030 case IPP_STATE_ATTRIBUTE
:
3033 if ((*cb
)(src
, buffer
, 1) < 1)
3035 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3036 _cupsBufferRelease((char *)buffer
);
3037 return (IPP_STATE_ERROR
);
3040 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3043 * Read this attribute...
3046 tag
= (ipp_tag_t
)buffer
[0];
3047 if (tag
== IPP_TAG_EXTENSION
)
3050 * Read 32-bit "extension" tag...
3053 if ((*cb
)(src
, buffer
, 4) < 1)
3055 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3056 _cupsBufferRelease((char *)buffer
);
3057 return (IPP_STATE_ERROR
);
3060 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
3061 buffer
[2]) << 8) | buffer
[3]);
3063 if (tag
& IPP_TAG_CUPS_CONST
)
3066 * Fail if the high bit is set in the tag...
3069 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
3070 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
3071 _cupsBufferRelease((char *)buffer
);
3072 return (IPP_STATE_ERROR
);
3076 if (tag
== IPP_TAG_END
)
3079 * No more attributes left...
3082 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
3084 ipp
->state
= IPP_STATE_DATA
;
3087 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3090 * Group tag... Set the current group and continue...
3093 if (ipp
->curtag
== tag
)
3094 ipp
->prev
= ippAddSeparator(ipp
);
3095 else if (ipp
->current
)
3096 ipp
->prev
= ipp
->current
;
3099 ipp
->current
= NULL
;
3100 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
, ippTagString(tag
), (void *)ipp
->prev
));
3104 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3105 ippTagString(tag
)));
3111 if ((*cb
)(src
, buffer
, 2) < 2)
3113 DEBUG_puts("1ippReadIO: unable to read name length.");
3114 _cupsBufferRelease((char *)buffer
);
3115 return (IPP_STATE_ERROR
);
3118 n
= (buffer
[0] << 8) | buffer
[1];
3120 if (n
>= IPP_BUF_SIZE
)
3122 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3123 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3124 _cupsBufferRelease((char *)buffer
);
3125 return (IPP_STATE_ERROR
);
3128 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3130 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3131 tag
!= IPP_TAG_END_COLLECTION
)
3134 * More values for current attribute...
3137 if (ipp
->current
== NULL
)
3139 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3140 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3141 _cupsBufferRelease((char *)buffer
);
3142 return (IPP_STATE_ERROR
);
3145 attr
= ipp
->current
;
3146 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3149 * Make sure we aren't adding a new value of a different
3153 if (value_tag
== IPP_TAG_ZERO
)
3156 * Setting the value of a collection member...
3159 attr
->value_tag
= tag
;
3161 else if (value_tag
== IPP_TAG_TEXTLANG
||
3162 value_tag
== IPP_TAG_NAMELANG
||
3163 (value_tag
>= IPP_TAG_TEXT
&&
3164 value_tag
<= IPP_TAG_MIMETYPE
))
3167 * String values can sometimes come across in different
3168 * forms; accept sets of differing values...
3171 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3172 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3173 tag
!= IPP_TAG_NOVALUE
)
3175 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3176 _("IPP 1setOf attribute with incompatible value "
3178 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3179 value_tag
, ippTagString(value_tag
), tag
,
3180 ippTagString(tag
)));
3181 _cupsBufferRelease((char *)buffer
);
3182 return (IPP_STATE_ERROR
);
3185 if (value_tag
!= tag
)
3187 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3188 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3189 ippSetValueTag(ipp
, &attr
, tag
);
3192 else if (value_tag
== IPP_TAG_INTEGER
||
3193 value_tag
== IPP_TAG_RANGE
)
3196 * Integer and rangeOfInteger values can sometimes be mixed; accept
3197 * sets of differing values...
3200 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3202 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3203 _("IPP 1setOf attribute with incompatible value "
3205 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3206 value_tag
, ippTagString(value_tag
), tag
,
3207 ippTagString(tag
)));
3208 _cupsBufferRelease((char *)buffer
);
3209 return (IPP_STATE_ERROR
);
3212 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3215 * Convert integer values to rangeOfInteger values...
3218 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3219 "rangeOfInteger.", attr
->name
));
3220 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3223 else if (value_tag
!= tag
)
3225 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3226 _("IPP 1setOf attribute with incompatible value "
3228 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3229 value_tag
, ippTagString(value_tag
), tag
,
3230 ippTagString(tag
)));
3231 _cupsBufferRelease((char *)buffer
);
3232 return (IPP_STATE_ERROR
);
3236 * Finally, reallocate the attribute array as needed...
3239 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3241 _cupsBufferRelease((char *)buffer
);
3242 return (IPP_STATE_ERROR
);
3245 else if (tag
== IPP_TAG_MEMBERNAME
)
3248 * Name must be length 0!
3253 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3254 DEBUG_puts("1ippReadIO: member name not empty.");
3255 _cupsBufferRelease((char *)buffer
);
3256 return (IPP_STATE_ERROR
);
3260 ipp
->prev
= ipp
->current
;
3262 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3265 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3266 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3267 _cupsBufferRelease((char *)buffer
);
3268 return (IPP_STATE_ERROR
);
3271 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3273 value
= attr
->values
;
3275 else if (tag
!= IPP_TAG_END_COLLECTION
)
3278 * New attribute; read the name and add it...
3281 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3283 DEBUG_puts("1ippReadIO: unable to read name.");
3284 _cupsBufferRelease((char *)buffer
);
3285 return (IPP_STATE_ERROR
);
3291 ipp
->prev
= ipp
->current
;
3293 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3296 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3297 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3298 _cupsBufferRelease((char *)buffer
);
3299 return (IPP_STATE_ERROR
);
3302 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer
, (void *)ipp
->current
, (void *)ipp
->prev
));
3304 value
= attr
->values
;
3312 if ((*cb
)(src
, buffer
, 2) < 2)
3314 DEBUG_puts("1ippReadIO: unable to read value length.");
3315 _cupsBufferRelease((char *)buffer
);
3316 return (IPP_STATE_ERROR
);
3319 n
= (buffer
[0] << 8) | buffer
[1];
3320 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3322 if (n
>= IPP_BUF_SIZE
)
3324 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3325 _("IPP value larger than 32767 bytes."), 1);
3326 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3327 _cupsBufferRelease((char *)buffer
);
3328 return (IPP_STATE_ERROR
);
3333 case IPP_TAG_INTEGER
:
3337 if (tag
== IPP_TAG_INTEGER
)
3338 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3339 _("IPP integer value not 4 bytes."), 1);
3341 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3342 _("IPP enum value not 4 bytes."), 1);
3343 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3344 _cupsBufferRelease((char *)buffer
);
3345 return (IPP_STATE_ERROR
);
3348 if ((*cb
)(src
, buffer
, 4) < 4)
3350 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3351 _cupsBufferRelease((char *)buffer
);
3352 return (IPP_STATE_ERROR
);
3355 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3358 if (attr
->value_tag
== IPP_TAG_RANGE
)
3359 value
->range
.lower
= value
->range
.upper
= n
;
3364 case IPP_TAG_BOOLEAN
:
3367 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3369 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3370 _cupsBufferRelease((char *)buffer
);
3371 return (IPP_STATE_ERROR
);
3374 if ((*cb
)(src
, buffer
, 1) < 1)
3376 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3377 _cupsBufferRelease((char *)buffer
);
3378 return (IPP_STATE_ERROR
);
3381 value
->boolean
= (char)buffer
[0];
3384 case IPP_TAG_NOVALUE
:
3385 case IPP_TAG_NOTSETTABLE
:
3386 case IPP_TAG_DELETEATTR
:
3387 case IPP_TAG_ADMINDEFINE
:
3389 * These value types are not supposed to have values, however
3390 * some vendors (Brother) do not implement IPP correctly and so
3391 * we need to map non-empty values to text...
3394 if (attr
->value_tag
== tag
)
3399 attr
->value_tag
= IPP_TAG_TEXT
;
3404 case IPP_TAG_KEYWORD
:
3406 case IPP_TAG_URISCHEME
:
3407 case IPP_TAG_CHARSET
:
3408 case IPP_TAG_LANGUAGE
:
3409 case IPP_TAG_MIMETYPE
:
3412 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3414 DEBUG_puts("1ippReadIO: unable to read string value.");
3415 _cupsBufferRelease((char *)buffer
);
3416 return (IPP_STATE_ERROR
);
3421 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3422 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3428 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3429 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3430 _cupsBufferRelease((char *)buffer
);
3431 return (IPP_STATE_ERROR
);
3434 if ((*cb
)(src
, value
->date
, 11) < 11)
3436 DEBUG_puts("1ippReadIO: Unable to read date value.");
3437 _cupsBufferRelease((char *)buffer
);
3438 return (IPP_STATE_ERROR
);
3442 case IPP_TAG_RESOLUTION
:
3445 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3446 _("IPP resolution value not 9 bytes."), 1);
3447 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3448 _cupsBufferRelease((char *)buffer
);
3449 return (IPP_STATE_ERROR
);
3452 if ((*cb
)(src
, buffer
, 9) < 9)
3454 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3455 _cupsBufferRelease((char *)buffer
);
3456 return (IPP_STATE_ERROR
);
3459 value
->resolution
.xres
=
3460 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3462 value
->resolution
.yres
=
3463 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3465 value
->resolution
.units
=
3466 (ipp_res_t
)buffer
[8];
3469 case IPP_TAG_RANGE
:
3472 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3473 _("IPP rangeOfInteger value not 8 bytes."), 1);
3474 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3476 _cupsBufferRelease((char *)buffer
);
3477 return (IPP_STATE_ERROR
);
3480 if ((*cb
)(src
, buffer
, 8) < 8)
3482 DEBUG_puts("1ippReadIO: Unable to read range value.");
3483 _cupsBufferRelease((char *)buffer
);
3484 return (IPP_STATE_ERROR
);
3487 value
->range
.lower
=
3488 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3490 value
->range
.upper
=
3491 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3495 case IPP_TAG_TEXTLANG
:
3496 case IPP_TAG_NAMELANG
:
3499 if (tag
== IPP_TAG_TEXTLANG
)
3500 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3501 _("IPP textWithLanguage value less than "
3502 "minimum 4 bytes."), 1);
3504 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3505 _("IPP nameWithLanguage value less than "
3506 "minimum 4 bytes."), 1);
3507 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3509 _cupsBufferRelease((char *)buffer
);
3510 return (IPP_STATE_ERROR
);
3513 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3515 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3517 _cupsBufferRelease((char *)buffer
);
3518 return (IPP_STATE_ERROR
);
3524 * text-with-language and name-with-language are composite
3533 n
= (bufptr
[0] << 8) | bufptr
[1];
3535 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) || n
>= (int)sizeof(string
))
3537 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3538 _("IPP language length overflows value."), 1);
3539 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3541 _cupsBufferRelease((char *)buffer
);
3542 return (IPP_STATE_ERROR
);
3544 else if (n
>= IPP_MAX_LANGUAGE
)
3546 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3547 _("IPP language length too large."), 1);
3548 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3550 _cupsBufferRelease((char *)buffer
);
3551 return (IPP_STATE_ERROR
);
3554 memcpy(string
, bufptr
+ 2, (size_t)n
);
3557 value
->string
.language
= _cupsStrAlloc((char *)string
);
3560 n
= (bufptr
[0] << 8) | bufptr
[1];
3562 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3564 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3565 _("IPP string length overflows value."), 1);
3566 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3567 _cupsBufferRelease((char *)buffer
);
3568 return (IPP_STATE_ERROR
);
3571 bufptr
[2 + n
] = '\0';
3572 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3575 case IPP_TAG_BEGIN_COLLECTION
:
3577 * Oh, boy, here comes a collection value, so read it...
3580 value
->collection
= ippNew();
3584 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3585 _("IPP begCollection value not 0 bytes."), 1);
3586 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3588 _cupsBufferRelease((char *)buffer
);
3589 return (IPP_STATE_ERROR
);
3592 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3594 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3595 _cupsBufferRelease((char *)buffer
);
3596 return (IPP_STATE_ERROR
);
3600 case IPP_TAG_END_COLLECTION
:
3601 _cupsBufferRelease((char *)buffer
);
3605 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3606 _("IPP endCollection value not 0 bytes."), 1);
3607 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3609 return (IPP_STATE_ERROR
);
3612 DEBUG_puts("1ippReadIO: endCollection tag...");
3613 return (ipp
->state
= IPP_STATE_DATA
);
3615 case IPP_TAG_MEMBERNAME
:
3617 * The value the name of the member in the collection, which
3618 * we need to carry over...
3623 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3624 _("IPP memberName with no attribute."), 1);
3625 DEBUG_puts("1ippReadIO: Member name without attribute.");
3626 _cupsBufferRelease((char *)buffer
);
3627 return (IPP_STATE_ERROR
);
3631 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3632 _("IPP memberName value is empty."), 1);
3633 DEBUG_puts("1ippReadIO: Empty member name value.");
3634 _cupsBufferRelease((char *)buffer
);
3635 return (IPP_STATE_ERROR
);
3637 else if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3639 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3640 _cupsBufferRelease((char *)buffer
);
3641 return (IPP_STATE_ERROR
);
3645 attr
->name
= _cupsStrAlloc((char *)buffer
);
3648 * Since collection members are encoded differently than
3649 * regular attributes, make sure we don't start with an
3653 attr
->num_values
--;
3655 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3658 default : /* Other unsupported values */
3659 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3661 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3662 _("IPP octetString length too large."), 1);
3663 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3665 _cupsBufferRelease((char *)buffer
);
3666 return (IPP_STATE_ERROR
);
3669 value
->unknown
.length
= n
;
3673 if ((value
->unknown
.data
= malloc((size_t)n
)) == NULL
)
3675 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3676 DEBUG_puts("1ippReadIO: Unable to allocate value");
3677 _cupsBufferRelease((char *)buffer
);
3678 return (IPP_STATE_ERROR
);
3681 if ((*cb
)(src
, value
->unknown
.data
, (size_t)n
) < n
)
3683 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3684 _cupsBufferRelease((char *)buffer
);
3685 return (IPP_STATE_ERROR
);
3689 value
->unknown
.data
= NULL
;
3694 * If blocking is disabled, stop here...
3702 case IPP_STATE_DATA
:
3706 break; /* anti-compiler-warning-code */
3709 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3710 _cupsBufferRelease((char *)buffer
);
3712 return (ipp
->state
);
3717 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3719 * The @code ipp@ parameter refers to an IPP message previously created using
3720 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3722 * The @code attr@ parameter may be modified as a result of setting the value.
3724 * The @code element@ parameter specifies which value to set from 0 to
3725 * @code ippGetCount(attr)@.
3727 * @since CUPS 1.6/macOS 10.8@
3730 int /* O - 1 on success, 0 on failure */
3731 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3732 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3733 int element
, /* I - Value number (0-based) */
3734 int boolvalue
)/* I - Boolean value */
3736 _ipp_value_t
*value
; /* Current value */
3740 * Range check input...
3743 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3744 element
< 0 || element
> (*attr
)->num_values
)
3748 * Set the value and return...
3751 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3752 value
->boolean
= (char)boolvalue
;
3754 return (value
!= NULL
);
3759 * 'ippSetCollection()' - Set a collection value in an attribute.
3761 * The @code ipp@ parameter refers to an IPP message previously created using
3762 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3764 * The @code attr@ parameter may be modified as a result of setting the value.
3766 * The @code element@ parameter specifies which value to set from 0 to
3767 * @code ippGetCount(attr)@.
3769 * @since CUPS 1.6/macOS 10.8@
3772 int /* O - 1 on success, 0 on failure */
3774 ipp_t
*ipp
, /* I - IPP message */
3775 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3776 int element
, /* I - Value number (0-based) */
3777 ipp_t
*colvalue
) /* I - Collection value */
3779 _ipp_value_t
*value
; /* Current value */
3783 * Range check input...
3786 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3787 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3791 * Set the value and return...
3794 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3796 if (value
->collection
)
3797 ippDelete(value
->collection
);
3799 value
->collection
= colvalue
;
3803 return (value
!= NULL
);
3808 * 'ippSetDate()' - Set a dateTime value in an attribute.
3810 * The @code ipp@ parameter refers to an IPP message previously created using
3811 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3813 * The @code attr@ parameter may be modified as a result of setting the value.
3815 * The @code element@ parameter specifies which value to set from 0 to
3816 * @code ippGetCount(attr)@.
3818 * @since CUPS 1.6/macOS 10.8@
3821 int /* O - 1 on success, 0 on failure */
3822 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3823 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3824 int element
, /* I - Value number (0-based) */
3825 const ipp_uchar_t
*datevalue
)/* I - dateTime value */
3827 _ipp_value_t
*value
; /* Current value */
3831 * Range check input...
3834 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3835 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3839 * Set the value and return...
3842 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3843 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3845 return (value
!= NULL
);
3850 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3852 * The @code ipp@ parameter refers to an IPP message previously created using
3853 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3855 * The @code attr@ parameter may be modified as a result of setting the value.
3857 * The @code group@ parameter specifies the IPP attribute group tag: none
3858 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3859 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3860 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3861 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3863 * @since CUPS 1.6/macOS 10.8@
3866 int /* O - 1 on success, 0 on failure */
3868 ipp_t
*ipp
, /* I - IPP message */
3869 ipp_attribute_t
**attr
, /* IO - Attribute */
3870 ipp_tag_t group_tag
) /* I - Group tag */
3873 * Range check input - group tag must be 0x01 to 0x0F, per RFC 8011...
3876 if (!ipp
|| !attr
|| !*attr
||
3877 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3878 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3882 * Set the group tag and return...
3885 (*attr
)->group_tag
= group_tag
;
3892 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3894 * The @code ipp@ parameter refers to an IPP message previously created using
3895 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3897 * The @code attr@ parameter may be modified as a result of setting the value.
3899 * The @code element@ parameter specifies which value to set from 0 to
3900 * @code ippGetCount(attr)@.
3902 * @since CUPS 1.6/macOS 10.8@
3905 int /* O - 1 on success, 0 on failure */
3906 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3907 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3908 int element
, /* I - Value number (0-based) */
3909 int intvalue
) /* I - Integer/enum value */
3911 _ipp_value_t
*value
; /* Current value */
3915 * Range check input...
3918 if (!ipp
|| !attr
|| !*attr
||
3919 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3920 element
< 0 || element
> (*attr
)->num_values
)
3924 * Set the value and return...
3927 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3928 value
->integer
= intvalue
;
3930 return (value
!= NULL
);
3935 * 'ippSetName()' - Set the name of an attribute.
3937 * The @code ipp@ parameter refers to an IPP message previously created using
3938 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3940 * The @code attr@ parameter may be modified as a result of setting the value.
3942 * @since CUPS 1.6/macOS 10.8@
3945 int /* O - 1 on success, 0 on failure */
3946 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3947 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3948 const char *name
) /* I - Attribute name */
3950 char *temp
; /* Temporary name value */
3954 * Range check input...
3957 if (!ipp
|| !attr
|| !*attr
)
3961 * Set the value and return...
3964 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3967 _cupsStrFree((*attr
)->name
);
3969 (*attr
)->name
= temp
;
3972 return (temp
!= NULL
);
3977 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
3979 * The @code ipp@ parameter refers to an IPP message previously created using
3980 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3982 * The @code attr@ parameter may be modified as a result of setting the value.
3984 * The @code element@ parameter specifies which value to set from 0 to
3985 * @code ippGetCount(attr)@.
3987 * @since CUPS 1.7/macOS 10.9@
3990 int /* O - 1 on success, 0 on failure */
3992 ipp_t
*ipp
, /* I - IPP message */
3993 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3994 int element
, /* I - Value number (0-based) */
3995 const void *data
, /* I - Pointer to octetString data */
3996 int datalen
) /* I - Length of octetString data */
3998 _ipp_value_t
*value
; /* Current value */
4002 * Range check input...
4005 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_STRING
||
4006 element
< 0 || element
> (*attr
)->num_values
||
4007 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
4011 * Set the value and return...
4014 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4016 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4019 * Just copy the pointer...
4022 value
->unknown
.data
= (void *)data
;
4023 value
->unknown
.length
= datalen
;
4031 if (value
->unknown
.data
)
4034 * Free previous data...
4037 free(value
->unknown
.data
);
4039 value
->unknown
.data
= NULL
;
4040 value
->unknown
.length
= 0;
4045 void *temp
; /* Temporary data pointer */
4047 if ((temp
= malloc((size_t)datalen
)) != NULL
)
4049 memcpy(temp
, data
, (size_t)datalen
);
4051 value
->unknown
.data
= temp
;
4052 value
->unknown
.length
= datalen
;
4060 return (value
!= NULL
);
4065 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
4067 * The @code ipp@ parameter refers to an IPP message previously created using
4068 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4070 * @since CUPS 1.6/macOS 10.8@
4073 int /* O - 1 on success, 0 on failure */
4074 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
4075 ipp_op_t op
) /* I - Operation ID */
4078 * Range check input...
4085 * Set the operation and return...
4088 ipp
->request
.op
.operation_id
= op
;
4095 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4097 * The @code ipp@ parameter refers to an IPP message previously created using
4098 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4100 * The @code attr@ parameter may be modified as a result of setting the value.
4102 * The @code element@ parameter specifies which value to set from 0 to
4103 * @code ippGetCount(attr)@.
4105 * @since CUPS 1.6/macOS 10.8@
4108 int /* O - 1 on success, 0 on failure */
4109 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4110 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4111 int element
, /* I - Value number (0-based) */
4112 int lowervalue
, /* I - Lower bound for range */
4113 int uppervalue
) /* I - Upper bound for range */
4115 _ipp_value_t
*value
; /* Current value */
4119 * Range check input...
4122 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4123 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4127 * Set the value and return...
4130 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4132 value
->range
.lower
= lowervalue
;
4133 value
->range
.upper
= uppervalue
;
4136 return (value
!= NULL
);
4141 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4143 * The @code ipp@ parameter refers to an IPP message previously created using
4144 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4146 * The @code request_id@ parameter must be greater than 0.
4148 * @since CUPS 1.6/macOS 10.8@
4151 int /* O - 1 on success, 0 on failure */
4152 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4153 int request_id
) /* I - Request ID */
4156 * Range check input; not checking request_id values since ipptool wants to send
4157 * invalid values for conformance testing and a bad request_id does not affect the
4158 * encoding of a message...
4165 * Set the request ID and return...
4168 ipp
->request
.any
.request_id
= request_id
;
4175 * 'ippSetResolution()' - Set a resolution value in an attribute.
4177 * The @code ipp@ parameter refers to an IPP message previously created using
4178 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4180 * The @code attr@ parameter may be modified as a result of setting the value.
4182 * The @code element@ parameter specifies which value to set from 0 to
4183 * @code ippGetCount(attr)@.
4185 * @since CUPS 1.6/macOS 10.8@
4188 int /* O - 1 on success, 0 on failure */
4190 ipp_t
*ipp
, /* I - IPP message */
4191 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4192 int element
, /* I - Value number (0-based) */
4193 ipp_res_t unitsvalue
, /* I - Resolution units */
4194 int xresvalue
, /* I - Horizontal/cross feed resolution */
4195 int yresvalue
) /* I - Vertical/feed resolution */
4197 _ipp_value_t
*value
; /* Current value */
4201 * Range check input...
4204 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4205 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4206 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4210 * Set the value and return...
4213 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4215 value
->resolution
.units
= unitsvalue
;
4216 value
->resolution
.xres
= xresvalue
;
4217 value
->resolution
.yres
= yresvalue
;
4220 return (value
!= NULL
);
4225 * 'ippSetState()' - Set the current state of the IPP message.
4227 * @since CUPS 1.6/macOS 10.8@
4230 int /* O - 1 on success, 0 on failure */
4231 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4232 ipp_state_t state
) /* I - IPP state value */
4235 * Range check input...
4242 * Set the state and return...
4246 ipp
->current
= NULL
;
4253 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4255 * The @code ipp@ parameter refers to an IPP message previously created using
4256 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4258 * @since CUPS 1.6/macOS 10.8@
4261 int /* O - 1 on success, 0 on failure */
4262 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4263 ipp_status_t status
) /* I - Status code */
4266 * Range check input...
4273 * Set the status code and return...
4276 ipp
->request
.status
.status_code
= status
;
4283 * 'ippSetString()' - Set a string value in an attribute.
4285 * The @code ipp@ parameter refers to an IPP message previously created using
4286 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4288 * The @code attr@ parameter may be modified as a result of setting the value.
4290 * The @code element@ parameter specifies which value to set from 0 to
4291 * @code ippGetCount(attr)@.
4293 * @since CUPS 1.6/macOS 10.8@
4296 int /* O - 1 on success, 0 on failure */
4297 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4298 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4299 int element
, /* I - Value number (0-based) */
4300 const char *strvalue
) /* I - String value */
4302 char *temp
; /* Temporary string */
4303 _ipp_value_t
*value
; /* Current value */
4304 ipp_tag_t value_tag
; /* Value tag */
4308 * Range check input...
4312 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4314 value_tag
= IPP_TAG_ZERO
;
4316 if (!ipp
|| !attr
|| !*attr
||
4317 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4318 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4323 * Set the value and return...
4326 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4329 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4331 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4332 value
->string
.text
= (char *)strvalue
;
4333 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4335 if (value
->string
.text
)
4336 _cupsStrFree(value
->string
.text
);
4338 value
->string
.text
= temp
;
4344 return (value
!= NULL
);
4349 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4351 * The @code ipp@ parameter refers to an IPP message previously created using
4352 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4354 * The @code attr@ parameter may be modified as a result of setting the value.
4356 * The @code element@ parameter specifies which value to set from 0 to
4357 * @code ippGetCount(attr)@.
4359 * The @code format@ parameter uses formatting characters compatible with the
4360 * printf family of standard functions. Additional arguments follow it as
4361 * needed. The formatted string is truncated as needed to the maximum length of
4362 * the corresponding value type.
4364 * @since CUPS 1.7/macOS 10.9@
4367 int /* O - 1 on success, 0 on failure */
4368 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4369 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4370 int element
, /* I - Value number (0-based) */
4371 const char *format
, /* I - Printf-style format string */
4372 ...) /* I - Additional arguments as needed */
4374 int ret
; /* Return value */
4375 va_list ap
; /* Pointer to additional arguments */
4378 va_start(ap
, format
);
4379 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4387 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4389 * The @code ipp@ parameter refers to an IPP message previously created using
4390 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4392 * The @code attr@ parameter may be modified as a result of setting the value.
4394 * The @code element@ parameter specifies which value to set from 0 to
4395 * @code ippGetCount(attr)@.
4397 * The @code format@ parameter uses formatting characters compatible with the
4398 * printf family of standard functions. Additional arguments follow it as
4399 * needed. The formatted string is truncated as needed to the maximum length of
4400 * the corresponding value type.
4402 * @since CUPS 1.7/macOS 10.9@
4405 int /* O - 1 on success, 0 on failure */
4406 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4407 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4408 int element
, /* I - Value number (0-based) */
4409 const char *format
, /* I - Printf-style format string */
4410 va_list ap
) /* I - Pointer to additional arguments */
4412 ipp_tag_t value_tag
; /* Value tag */
4413 char buffer
[IPP_MAX_TEXT
+ 4];
4414 /* Formatted text string */
4415 ssize_t bytes
, /* Length of formatted value */
4416 max_bytes
; /* Maximum number of bytes for value */
4420 * Range check input...
4424 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4426 value_tag
= IPP_TAG_ZERO
;
4428 if (!ipp
|| !attr
|| !*attr
||
4429 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4430 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4435 * Format the string...
4438 if (!strcmp(format
, "%s"))
4441 * Optimize the simple case...
4444 const char *s
= va_arg(ap
, char *);
4449 bytes
= (ssize_t
)strlen(s
);
4450 strlcpy(buffer
, s
, sizeof(buffer
));
4455 * Do a full formatting of the message...
4458 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4463 * Limit the length of the string...
4470 case IPP_TAG_TEXTLANG
:
4471 max_bytes
= IPP_MAX_TEXT
;
4475 case IPP_TAG_NAMELANG
:
4476 max_bytes
= IPP_MAX_NAME
;
4479 case IPP_TAG_CHARSET
:
4480 max_bytes
= IPP_MAX_CHARSET
;
4483 case IPP_TAG_KEYWORD
:
4484 max_bytes
= IPP_MAX_KEYWORD
;
4487 case IPP_TAG_LANGUAGE
:
4488 max_bytes
= IPP_MAX_LANGUAGE
;
4491 case IPP_TAG_MIMETYPE
:
4492 max_bytes
= IPP_MAX_MIMETYPE
;
4496 max_bytes
= IPP_MAX_URI
;
4499 case IPP_TAG_URISCHEME
:
4500 max_bytes
= IPP_MAX_URISCHEME
;
4504 if (bytes
>= max_bytes
)
4506 char *bufmax
, /* Buffer at max_bytes */
4507 *bufptr
; /* Pointer into buffer */
4509 bufptr
= buffer
+ strlen(buffer
) - 1;
4510 bufmax
= buffer
+ max_bytes
- 1;
4512 while (bufptr
> bufmax
)
4516 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4527 * Set the formatted string and return...
4530 return (ippSetString(ipp
, attr
, element
, buffer
));
4535 * 'ippSetValueTag()' - Set the value tag of an attribute.
4537 * The @code ipp@ parameter refers to an IPP message previously created using
4538 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4540 * The @code attr@ parameter may be modified as a result of setting the value.
4542 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4543 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4544 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4545 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4546 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4547 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4550 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4551 * code in the "attributes-natural-language" attribute or, if not present, the language
4552 * code for the current locale.
4554 * @since CUPS 1.6/macOS 10.8@
4557 int /* O - 1 on success, 0 on failure */
4559 ipp_t
*ipp
, /* I - IPP message */
4560 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4561 ipp_tag_t value_tag
) /* I - Value tag */
4563 int i
; /* Looping var */
4564 _ipp_value_t
*value
; /* Current value */
4565 int integer
; /* Current integer value */
4566 cups_lang_t
*language
; /* Current language */
4567 char code
[32]; /* Language code */
4568 ipp_tag_t temp_tag
; /* Temporary value tag */
4572 * Range check input...
4575 if (!ipp
|| !attr
|| !*attr
)
4579 * If there is no change, return immediately...
4582 if (value_tag
== (*attr
)->value_tag
)
4586 * Otherwise implement changes as needed...
4589 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4593 case IPP_TAG_UNSUPPORTED_VALUE
:
4594 case IPP_TAG_DEFAULT
:
4595 case IPP_TAG_UNKNOWN
:
4596 case IPP_TAG_NOVALUE
:
4597 case IPP_TAG_NOTSETTABLE
:
4598 case IPP_TAG_DELETEATTR
:
4599 case IPP_TAG_ADMINDEFINE
:
4601 * Free any existing values...
4604 if ((*attr
)->num_values
> 0)
4605 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4608 * Set out-of-band value...
4611 (*attr
)->value_tag
= value_tag
;
4614 case IPP_TAG_RANGE
:
4615 if (temp_tag
!= IPP_TAG_INTEGER
)
4618 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4622 integer
= value
->integer
;
4623 value
->range
.lower
= value
->range
.upper
= integer
;
4626 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4630 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4631 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4632 temp_tag
!= IPP_TAG_MIMETYPE
)
4635 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4638 case IPP_TAG_NAMELANG
:
4639 case IPP_TAG_TEXTLANG
:
4640 if (value_tag
== IPP_TAG_NAMELANG
&&
4641 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4642 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4643 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4646 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4649 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4650 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4653 * Use the language code from the IPP message...
4656 (*attr
)->values
[0].string
.language
=
4657 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4662 * Otherwise, use the language code corresponding to the locale...
4665 language
= cupsLangDefault();
4666 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4671 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4674 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4676 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4679 * Make copies of all values...
4682 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4685 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4688 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4691 case IPP_TAG_KEYWORD
:
4692 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4693 break; /* Silently "allow" name -> keyword */
4704 * 'ippSetVersion()' - Set the version number in an IPP message.
4706 * The @code ipp@ parameter refers to an IPP message previously created using
4707 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4709 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4711 * @since CUPS 1.6/macOS 10.8@
4714 int /* O - 1 on success, 0 on failure */
4715 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4716 int major
, /* I - Major version number (major.minor) */
4717 int minor
) /* I - Minor version number (major.minor) */
4720 * Range check input...
4723 if (!ipp
|| major
< 0 || minor
< 0)
4727 * Set the version number...
4730 ipp
->request
.any
.version
[0] = (ipp_uchar_t
)major
;
4731 ipp
->request
.any
.version
[1] = (ipp_uchar_t
)minor
;
4738 * 'ippTimeToDate()' - Convert from time in seconds to RFC 2579 format.
4741 const ipp_uchar_t
* /* O - RFC-2579 date/time data */
4742 ippTimeToDate(time_t t
) /* I - Time in seconds */
4744 struct tm
*unixdate
; /* UNIX unixdate/time info */
4745 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4746 /* RFC-2579 date/time data */
4750 * RFC-2579 date/time format is:
4752 * Byte(s) Description
4753 * ------- -----------
4754 * 0-1 Year (0 to 65535)
4758 * 5 Minutes (0 to 59)
4759 * 6 Seconds (0 to 60, 60 = "leap second")
4760 * 7 Deciseconds (0 to 9)
4762 * 9 UTC hours (0 to 11)
4763 * 10 UTC minutes (0 to 59)
4766 unixdate
= gmtime(&t
);
4767 unixdate
->tm_year
+= 1900;
4769 date
[0] = (ipp_uchar_t
)(unixdate
->tm_year
>> 8);
4770 date
[1] = (ipp_uchar_t
)(unixdate
->tm_year
);
4771 date
[2] = (ipp_uchar_t
)(unixdate
->tm_mon
+ 1);
4772 date
[3] = (ipp_uchar_t
)unixdate
->tm_mday
;
4773 date
[4] = (ipp_uchar_t
)unixdate
->tm_hour
;
4774 date
[5] = (ipp_uchar_t
)unixdate
->tm_min
;
4775 date
[6] = (ipp_uchar_t
)unixdate
->tm_sec
;
4786 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4788 * This function validates the contents of an attribute based on the name and
4789 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4790 * failure, @link cupsLastErrorString@ is set to a human-readable message.
4792 * @since CUPS 1.7/macOS 10.9@
4795 int /* O - 1 if valid, 0 otherwise */
4796 ippValidateAttribute(
4797 ipp_attribute_t
*attr
) /* I - Attribute */
4799 int i
; /* Looping var */
4800 char scheme
[64], /* Scheme from URI */
4801 userpass
[256], /* Username/password from URI */
4802 hostname
[256], /* Hostname from URI */
4803 resource
[1024]; /* Resource from URI */
4804 int port
, /* Port number from URI */
4805 uri_status
; /* URI separation status */
4806 const char *ptr
; /* Pointer into string */
4807 ipp_attribute_t
*colattr
; /* Collection attribute */
4808 regex_t re
; /* Regular expression */
4809 ipp_uchar_t
*date
; /* Current date value */
4820 * Validate the attribute name.
4823 for (ptr
= attr
->name
; *ptr
; ptr
++)
4824 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4827 if (*ptr
|| ptr
== attr
->name
)
4829 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad attribute name - invalid character (RFC 8011 section 5.1.4)."), attr
->name
);
4833 if ((ptr
- attr
->name
) > 255)
4835 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad attribute name - bad length %d (RFC 8011 section 5.1.4)."), attr
->name
, (int)(ptr
- attr
->name
));
4839 switch (attr
->value_tag
)
4841 case IPP_TAG_INTEGER
:
4844 case IPP_TAG_BOOLEAN
:
4845 for (i
= 0; i
< attr
->num_values
; i
++)
4847 if (attr
->values
[i
].boolean
!= 0 &&
4848 attr
->values
[i
].boolean
!= 1)
4850 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad boolean value %d (RFC 8011 section 5.1.21)."), attr
->name
, attr
->values
[i
].boolean
);
4857 for (i
= 0; i
< attr
->num_values
; i
++)
4859 if (attr
->values
[i
].integer
< 1)
4861 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad enum value %d - out of range (RFC 8011 section 5.1.5)."), attr
->name
, attr
->values
[i
].integer
);
4867 case IPP_TAG_STRING
:
4868 for (i
= 0; i
< attr
->num_values
; i
++)
4870 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4872 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad octetString value - bad length %d (RFC 8011 section 5.1.20)."), attr
->name
, attr
->values
[i
].unknown
.length
);
4879 for (i
= 0; i
< attr
->num_values
; i
++)
4881 date
= attr
->values
[i
].date
;
4883 if (date
[2] < 1 || date
[2] > 12)
4885 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime month %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[2]);
4889 if (date
[3] < 1 || date
[3] > 31)
4891 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime day %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[3]);
4897 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime hours %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[4]);
4903 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime minutes %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[5]);
4909 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime seconds %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[6]);
4915 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime deciseconds %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[7]);
4919 if (date
[8] != '-' && date
[8] != '+')
4921 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime UTC sign '%c' (RFC 8011 section 5.1.15)."), attr
->name
, date
[8]);
4927 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime UTC hours %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[9]);
4933 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime UTC minutes %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[10]);
4939 case IPP_TAG_RESOLUTION
:
4940 for (i
= 0; i
< attr
->num_values
; i
++)
4942 if (attr
->values
[i
].resolution
.xres
<= 0)
4944 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad resolution value %dx%d%s - cross feed resolution must be positive (RFC 8011 section 5.1.16)."), attr
->name
, attr
->values
[i
].resolution
.xres
, attr
->values
[i
].resolution
.yres
, attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
? "dpi" : attr
->values
[i
].resolution
.units
== IPP_RES_PER_CM
? "dpcm" : "unknown");
4948 if (attr
->values
[i
].resolution
.yres
<= 0)
4950 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad resolution value %dx%d%s - feed resolution must be positive (RFC 8011 section 5.1.16)."), attr
->name
, attr
->values
[i
].resolution
.xres
, attr
->values
[i
].resolution
.yres
, attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
? "dpi" : attr
->values
[i
].resolution
.units
== IPP_RES_PER_CM
? "dpcm" : "unknown");
4954 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&& attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
4956 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad resolution value %dx%d%s - bad units value (RFC 8011 section 5.1.16)."), attr
->name
, attr
->values
[i
].resolution
.xres
, attr
->values
[i
].resolution
.yres
, attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
? "dpi" : attr
->values
[i
].resolution
.units
== IPP_RES_PER_CM
? "dpcm" : "unknown");
4962 case IPP_TAG_RANGE
:
4963 for (i
= 0; i
< attr
->num_values
; i
++)
4965 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
4967 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad rangeOfInteger value %d-%d - lower greater than upper (RFC 8011 section 5.1.14)."), attr
->name
, attr
->values
[i
].range
.lower
, attr
->values
[i
].range
.upper
);
4973 case IPP_TAG_BEGIN_COLLECTION
:
4974 for (i
= 0; i
< attr
->num_values
; i
++)
4976 for (colattr
= attr
->values
[i
].collection
->attrs
;
4978 colattr
= colattr
->next
)
4980 if (!ippValidateAttribute(colattr
))
4987 case IPP_TAG_TEXTLANG
:
4988 for (i
= 0; i
< attr
->num_values
; i
++)
4990 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
4992 if ((*ptr
& 0xe0) == 0xc0)
4995 if ((*ptr
& 0xc0) != 0x80)
4998 else if ((*ptr
& 0xf0) == 0xe0)
5001 if ((*ptr
& 0xc0) != 0x80)
5004 if ((*ptr
& 0xc0) != 0x80)
5007 else if ((*ptr
& 0xf8) == 0xf0)
5010 if ((*ptr
& 0xc0) != 0x80)
5013 if ((*ptr
& 0xc0) != 0x80)
5016 if ((*ptr
& 0xc0) != 0x80)
5019 else if (*ptr
& 0x80)
5021 else if ((*ptr
< ' ' && *ptr
!= '\n' && *ptr
!= '\r' && *ptr
!= '\t') || *ptr
== 0x7f)
5025 if (*ptr
< ' ' || *ptr
== 0x7f)
5027 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad text value \"%s\" - bad control character (PWG 5100.14 section 8.3)."), attr
->name
, attr
->values
[i
].string
.text
);
5032 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad text value \"%s\" - bad UTF-8 sequence (RFC 8011 section 5.1.2)."), attr
->name
, attr
->values
[i
].string
.text
);
5036 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5038 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad text value \"%s\" - bad length %d (RFC 8011 section 5.1.2)."), attr
->name
, attr
->values
[i
].string
.text
, (int)(ptr
- attr
->values
[i
].string
.text
));
5045 case IPP_TAG_NAMELANG
:
5046 for (i
= 0; i
< attr
->num_values
; i
++)
5048 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5050 if ((*ptr
& 0xe0) == 0xc0)
5053 if ((*ptr
& 0xc0) != 0x80)
5056 else if ((*ptr
& 0xf0) == 0xe0)
5059 if ((*ptr
& 0xc0) != 0x80)
5062 if ((*ptr
& 0xc0) != 0x80)
5065 else if ((*ptr
& 0xf8) == 0xf0)
5068 if ((*ptr
& 0xc0) != 0x80)
5071 if ((*ptr
& 0xc0) != 0x80)
5074 if ((*ptr
& 0xc0) != 0x80)
5077 else if (*ptr
& 0x80)
5079 else if (*ptr
< ' ' || *ptr
== 0x7f)
5083 if (*ptr
< ' ' || *ptr
== 0x7f)
5085 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad name value \"%s\" - bad control character (PWG 5100.14 section 8.1)."), attr
->name
, attr
->values
[i
].string
.text
);
5090 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad name value \"%s\" - bad UTF-8 sequence (RFC 8011 section 5.1.3)."), attr
->name
, attr
->values
[i
].string
.text
);
5094 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5096 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad name value \"%s\" - bad length %d (RFC 8011 section 5.1.3)."), attr
->name
, attr
->values
[i
].string
.text
, (int)(ptr
- attr
->values
[i
].string
.text
));
5102 case IPP_TAG_KEYWORD
:
5103 for (i
= 0; i
< attr
->num_values
; i
++)
5105 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5107 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5112 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5114 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad keyword value \"%s\" - invalid character (RFC 8011 section 5.1.4)."), attr
->name
, attr
->values
[i
].string
.text
);
5118 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5120 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad keyword value \"%s\" - bad length %d (RFC 8011 section 5.1.4)."), attr
->name
, attr
->values
[i
].string
.text
, (int)(ptr
- attr
->values
[i
].string
.text
));
5127 for (i
= 0; i
< attr
->num_values
; i
++)
5129 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[i
].string
.text
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), hostname
, sizeof(hostname
), &port
, resource
, sizeof(resource
));
5131 if (uri_status
< HTTP_URI_STATUS_OK
)
5133 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad URI value \"%s\" - %s (RFC 8011 section 5.1.6)."), attr
->name
, attr
->values
[i
].string
.text
, httpURIStatusString(uri_status
));
5137 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5139 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad URI value \"%s\" - bad length %d (RFC 8011 section 5.1.6)."), attr
->name
, attr
->values
[i
].string
.text
, (int)strlen(attr
->values
[i
].string
.text
));
5144 case IPP_TAG_URISCHEME
:
5145 for (i
= 0; i
< attr
->num_values
; i
++)
5147 ptr
= attr
->values
[i
].string
.text
;
5148 if (islower(*ptr
& 255))
5150 for (ptr
++; *ptr
; ptr
++)
5152 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5153 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5158 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5160 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad uriScheme value \"%s\" - bad characters (RFC 8011 section 5.1.7)."), attr
->name
, attr
->values
[i
].string
.text
);
5164 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5166 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad uriScheme value \"%s\" - bad length %d (RFC 8011 section 5.1.7)."), attr
->name
, attr
->values
[i
].string
.text
, (int)(ptr
- attr
->values
[i
].string
.text
));
5172 case IPP_TAG_CHARSET
:
5173 for (i
= 0; i
< attr
->num_values
; i
++)
5175 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5177 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5178 isspace(*ptr
& 255))
5182 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5184 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad charset value \"%s\" - bad characters (RFC 8011 section 5.1.8)."), attr
->name
, attr
->values
[i
].string
.text
);
5188 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5190 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad charset value \"%s\" - bad length %d (RFC 8011 section 5.1.8)."), attr
->name
, attr
->values
[i
].string
.text
, (int)(ptr
- attr
->values
[i
].string
.text
));
5196 case IPP_TAG_LANGUAGE
:
5198 * The following regular expression is derived from the ABNF for
5199 * language tags in RFC 4646. All I can say is that this is the
5200 * easiest way to check the values...
5203 if ((i
= regcomp(&re
,
5205 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5207 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5208 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5209 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5210 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5211 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5213 "x(-[a-z0-9]{1,8})+" /* privateuse */
5215 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5217 REG_NOSUB
| REG_EXTENDED
)) != 0)
5219 char temp
[256]; /* Temporary error string */
5221 regerror(i
, &re
, temp
, sizeof(temp
));
5222 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
, _("Unable to compile naturalLanguage regular expression: %s."), temp
);
5226 for (i
= 0; i
< attr
->num_values
; i
++)
5228 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5230 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad naturalLanguage value \"%s\" - bad characters (RFC 8011 section 5.1.9)."), attr
->name
, attr
->values
[i
].string
.text
);
5235 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5237 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad naturalLanguage value \"%s\" - bad length %d (RFC 8011 section 5.1.9)."), attr
->name
, attr
->values
[i
].string
.text
, (int)strlen(attr
->values
[i
].string
.text
));
5246 case IPP_TAG_MIMETYPE
:
5248 * The following regular expression is derived from the ABNF for
5249 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5250 * the easiest way to check the values...
5253 if ((i
= regcomp(&re
,
5255 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5257 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5258 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5259 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5262 REG_NOSUB
| REG_EXTENDED
)) != 0)
5264 char temp
[256]; /* Temporary error string */
5266 regerror(i
, &re
, temp
, sizeof(temp
));
5267 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("Unable to compile mimeMediaType regular expression: %s."), temp
);
5271 for (i
= 0; i
< attr
->num_values
; i
++)
5273 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5275 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad mimeMediaType value \"%s\" - bad characters (RFC 8011 section 5.1.10)."), attr
->name
, attr
->values
[i
].string
.text
);
5280 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5282 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad mimeMediaType value \"%s\" - bad length %d (RFC 8011 section 5.1.10)."), attr
->name
, attr
->values
[i
].string
.text
, (int)strlen(attr
->values
[i
].string
.text
));
5300 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5302 * This function validates the contents of the IPP message, including each
5303 * attribute. Like @link ippValidateAttribute@, @link cupsLastErrorString@ is
5304 * set to a human-readable message on failure.
5306 * @since CUPS 1.7/macOS 10.9@
5309 int /* O - 1 if valid, 0 otherwise */
5310 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5312 ipp_attribute_t
*attr
; /* Current attribute */
5318 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5319 if (!ippValidateAttribute(attr
))
5327 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5330 ipp_state_t
/* O - Current state */
5331 ippWrite(http_t
*http
, /* I - HTTP connection */
5332 ipp_t
*ipp
) /* I - IPP data */
5334 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http
, (void *)ipp
));
5337 return (IPP_STATE_ERROR
);
5339 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5344 * 'ippWriteFile()' - Write data for an IPP message to a file.
5346 * @since CUPS 1.1.19/macOS 10.3@
5349 ipp_state_t
/* O - Current state */
5350 ippWriteFile(int fd
, /* I - HTTP data */
5351 ipp_t
*ipp
) /* I - IPP data */
5353 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
5355 ipp
->state
= IPP_STATE_IDLE
;
5357 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5362 * 'ippWriteIO()' - Write data for an IPP message.
5364 * @since CUPS 1.2/macOS 10.5@
5367 ipp_state_t
/* O - Current state */
5368 ippWriteIO(void *dst
, /* I - Destination */
5369 ipp_iocb_t cb
, /* I - Write callback function */
5370 int blocking
, /* I - Use blocking IO? */
5371 ipp_t
*parent
, /* I - Parent IPP message */
5372 ipp_t
*ipp
) /* I - IPP data */
5374 int i
; /* Looping var */
5375 int n
; /* Length of data */
5376 unsigned char *buffer
, /* Data buffer */
5377 *bufptr
; /* Pointer into buffer */
5378 ipp_attribute_t
*attr
; /* Current attribute */
5379 _ipp_value_t
*value
; /* Current value */
5382 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
5385 return (IPP_STATE_ERROR
);
5387 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5389 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5390 return (IPP_STATE_ERROR
);
5395 case IPP_STATE_IDLE
:
5396 ipp
->state
++; /* Avoid common problem... */
5398 case IPP_STATE_HEADER
:
5402 * Send the request header:
5405 * Operation/Status Code = 2 bytes
5406 * Request ID = 4 bytes
5412 *bufptr
++ = ipp
->request
.any
.version
[0];
5413 *bufptr
++ = ipp
->request
.any
.version
[1];
5414 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.op_status
>> 8);
5415 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.op_status
;
5416 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 24);
5417 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 16);
5418 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 8);
5419 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.request_id
;
5421 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5422 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5423 ipp
->request
.any
.op_status
));
5424 DEBUG_printf(("2ippWriteIO: request_id=%d",
5425 ipp
->request
.any
.request_id
));
5427 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5429 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5430 _cupsBufferRelease((char *)buffer
);
5431 return (IPP_STATE_ERROR
);
5436 * Reset the state engine to point to the first attribute
5437 * in the request/response, with no current group.
5440 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5441 ipp
->current
= ipp
->attrs
;
5442 ipp
->curtag
= IPP_TAG_ZERO
;
5444 DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp
->current
));
5447 * If blocking is disabled, stop here...
5453 case IPP_STATE_ATTRIBUTE
:
5454 while (ipp
->current
!= NULL
)
5457 * Write this attribute...
5461 attr
= ipp
->current
;
5463 ipp
->current
= ipp
->current
->next
;
5467 if (ipp
->curtag
!= attr
->group_tag
)
5470 * Send a group tag byte...
5473 ipp
->curtag
= attr
->group_tag
;
5475 if (attr
->group_tag
== IPP_TAG_ZERO
)
5478 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5479 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5480 *bufptr
++ = (ipp_uchar_t
)attr
->group_tag
;
5482 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5486 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5487 attr
->num_values
> 1 ? "1setOf " : "",
5488 ippTagString(attr
->value_tag
)));
5491 * Write the attribute tag and name.
5493 * The attribute name length does not include the trailing nul
5494 * character in the source string.
5496 * Collection values (parent != NULL) are written differently...
5502 * Get the length of the attribute name, and make sure it won't
5503 * overflow the buffer...
5506 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5508 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5509 _cupsBufferRelease((char *)buffer
);
5510 return (IPP_STATE_ERROR
);
5514 * Write the value tag, name length, and name string...
5517 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5518 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5519 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5522 if (attr
->value_tag
> 0xff)
5524 *bufptr
++ = IPP_TAG_EXTENSION
;
5525 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5526 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5527 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5528 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5531 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5533 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5534 *bufptr
++ = (ipp_uchar_t
)n
;
5535 memcpy(bufptr
, attr
->name
, (size_t)n
);
5541 * Get the length of the attribute name, and make sure it won't
5542 * overflow the buffer...
5545 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5547 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5548 _cupsBufferRelease((char *)buffer
);
5549 return (IPP_STATE_ERROR
);
5553 * Write the member name tag, name length, name string, value tag,
5554 * and empty name for the collection member attribute...
5557 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5558 IPP_TAG_MEMBERNAME
));
5559 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5561 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5562 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5563 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5565 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5568 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5569 *bufptr
++ = (ipp_uchar_t
)n
;
5570 memcpy(bufptr
, attr
->name
, (size_t)n
);
5573 if (attr
->value_tag
> 0xff)
5575 *bufptr
++ = IPP_TAG_EXTENSION
;
5576 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5577 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5578 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5579 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5582 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5589 * Now write the attribute value(s)...
5592 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5594 case IPP_TAG_UNSUPPORTED_VALUE
:
5595 case IPP_TAG_DEFAULT
:
5596 case IPP_TAG_UNKNOWN
:
5597 case IPP_TAG_NOVALUE
:
5598 case IPP_TAG_NOTSETTABLE
:
5599 case IPP_TAG_DELETEATTR
:
5600 case IPP_TAG_ADMINDEFINE
:
5605 case IPP_TAG_INTEGER
:
5607 for (i
= 0, value
= attr
->values
;
5608 i
< attr
->num_values
;
5611 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5613 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5615 DEBUG_puts("1ippWriteIO: Could not write IPP "
5617 _cupsBufferRelease((char *)buffer
);
5618 return (IPP_STATE_ERROR
);
5627 * Arrays and sets are done by sending additional
5628 * values with a zero-length name...
5631 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5637 * Integers and enumerations are both 4-byte signed
5638 * (twos-complement) values.
5640 * Put the 2-byte length and 4-byte value into the buffer...
5645 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 24);
5646 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 16);
5647 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 8);
5648 *bufptr
++ = (ipp_uchar_t
)value
->integer
;
5652 case IPP_TAG_BOOLEAN
:
5653 for (i
= 0, value
= attr
->values
;
5654 i
< attr
->num_values
;
5657 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5659 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5661 DEBUG_puts("1ippWriteIO: Could not write IPP "
5663 _cupsBufferRelease((char *)buffer
);
5664 return (IPP_STATE_ERROR
);
5673 * Arrays and sets are done by sending additional
5674 * values with a zero-length name...
5677 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5683 * Boolean values are 1-byte; 0 = false, 1 = true.
5685 * Put the 2-byte length and 1-byte value into the buffer...
5690 *bufptr
++ = (ipp_uchar_t
)value
->boolean
;
5696 case IPP_TAG_KEYWORD
:
5698 case IPP_TAG_URISCHEME
:
5699 case IPP_TAG_CHARSET
:
5700 case IPP_TAG_LANGUAGE
:
5701 case IPP_TAG_MIMETYPE
:
5702 for (i
= 0, value
= attr
->values
;
5703 i
< attr
->num_values
;
5709 * Arrays and sets are done by sending additional
5710 * values with a zero-length name...
5713 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5715 ippTagString(attr
->value_tag
)));
5716 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5718 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5720 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5722 DEBUG_puts("1ippWriteIO: Could not write IPP "
5724 _cupsBufferRelease((char *)buffer
);
5725 return (IPP_STATE_ERROR
);
5731 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5736 if (value
->string
.text
!= NULL
)
5737 n
= (int)strlen(value
->string
.text
);
5741 if (n
> (IPP_BUF_SIZE
- 2))
5743 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5744 _cupsBufferRelease((char *)buffer
);
5745 return (IPP_STATE_ERROR
);
5748 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5749 value
->string
.text
));
5751 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5753 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5755 DEBUG_puts("1ippWriteIO: Could not write IPP "
5757 _cupsBufferRelease((char *)buffer
);
5758 return (IPP_STATE_ERROR
);
5765 * All simple strings consist of the 2-byte length and
5766 * character data without the trailing nul normally found
5767 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5768 * bytes since the 2-byte length is a signed (twos-complement)
5771 * Put the 2-byte length and string characters in the buffer.
5774 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5775 *bufptr
++ = (ipp_uchar_t
)n
;
5779 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5786 for (i
= 0, value
= attr
->values
;
5787 i
< attr
->num_values
;
5790 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5792 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5794 DEBUG_puts("1ippWriteIO: Could not write IPP "
5796 _cupsBufferRelease((char *)buffer
);
5797 return (IPP_STATE_ERROR
);
5806 * Arrays and sets are done by sending additional
5807 * values with a zero-length name...
5810 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5816 * Date values consist of a 2-byte length and an
5817 * 11-byte date/time structure defined by RFC 1903.
5819 * Put the 2-byte length and 11-byte date/time
5820 * structure in the buffer.
5825 memcpy(bufptr
, value
->date
, 11);
5830 case IPP_TAG_RESOLUTION
:
5831 for (i
= 0, value
= attr
->values
;
5832 i
< attr
->num_values
;
5835 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5837 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5839 DEBUG_puts("1ippWriteIO: Could not write IPP "
5841 _cupsBufferRelease((char *)buffer
);
5842 return (IPP_STATE_ERROR
);
5851 * Arrays and sets are done by sending additional
5852 * values with a zero-length name...
5855 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5861 * Resolution values consist of a 2-byte length,
5862 * 4-byte horizontal resolution value, 4-byte vertical
5863 * resolution value, and a 1-byte units value.
5865 * Put the 2-byte length and resolution value data
5871 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 24);
5872 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 16);
5873 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 8);
5874 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.xres
;
5875 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 24);
5876 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 16);
5877 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 8);
5878 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.yres
;
5879 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.units
;
5883 case IPP_TAG_RANGE
:
5884 for (i
= 0, value
= attr
->values
;
5885 i
< attr
->num_values
;
5888 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
5890 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5892 DEBUG_puts("1ippWriteIO: Could not write IPP "
5894 _cupsBufferRelease((char *)buffer
);
5895 return (IPP_STATE_ERROR
);
5904 * Arrays and sets are done by sending additional
5905 * values with a zero-length name...
5908 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5914 * Range values consist of a 2-byte length,
5915 * 4-byte lower value, and 4-byte upper value.
5917 * Put the 2-byte length and range value data
5923 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 24);
5924 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 16);
5925 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 8);
5926 *bufptr
++ = (ipp_uchar_t
)value
->range
.lower
;
5927 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 24);
5928 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 16);
5929 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 8);
5930 *bufptr
++ = (ipp_uchar_t
)value
->range
.upper
;
5934 case IPP_TAG_TEXTLANG
:
5935 case IPP_TAG_NAMELANG
:
5936 for (i
= 0, value
= attr
->values
;
5937 i
< attr
->num_values
;
5943 * Arrays and sets are done by sending additional
5944 * values with a zero-length name...
5947 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5949 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5951 DEBUG_puts("1ippWriteIO: Could not write IPP "
5953 _cupsBufferRelease((char *)buffer
);
5954 return (IPP_STATE_ERROR
);
5960 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5966 * textWithLanguage and nameWithLanguage values consist
5967 * of a 2-byte length for both strings and their
5968 * individual lengths, a 2-byte length for the
5969 * character string, the character string without the
5970 * trailing nul, a 2-byte length for the character
5971 * set string, and the character set string without
5977 if (value
->string
.language
!= NULL
)
5978 n
+= (int)strlen(value
->string
.language
);
5980 if (value
->string
.text
!= NULL
)
5981 n
+= (int)strlen(value
->string
.text
);
5983 if (n
> (IPP_BUF_SIZE
- 2))
5985 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
5986 "too long (%d)", n
));
5987 _cupsBufferRelease((char *)buffer
);
5988 return (IPP_STATE_ERROR
);
5991 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5993 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5995 DEBUG_puts("1ippWriteIO: Could not write IPP "
5997 _cupsBufferRelease((char *)buffer
);
5998 return (IPP_STATE_ERROR
);
6004 /* Length of entire value */
6005 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6006 *bufptr
++ = (ipp_uchar_t
)n
;
6008 /* Length of language */
6009 if (value
->string
.language
!= NULL
)
6010 n
= (int)strlen(value
->string
.language
);
6014 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6015 *bufptr
++ = (ipp_uchar_t
)n
;
6020 memcpy(bufptr
, value
->string
.language
, (size_t)n
);
6024 /* Length of text */
6025 if (value
->string
.text
!= NULL
)
6026 n
= (int)strlen(value
->string
.text
);
6030 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6031 *bufptr
++ = (ipp_uchar_t
)n
;
6036 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
6042 case IPP_TAG_BEGIN_COLLECTION
:
6043 for (i
= 0, value
= attr
->values
;
6044 i
< attr
->num_values
;
6048 * Collections are written with the begin-collection
6049 * tag first with a value of 0 length, followed by the
6050 * attributes in the collection, then the end-collection
6054 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6056 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6058 DEBUG_puts("1ippWriteIO: Could not write IPP "
6060 _cupsBufferRelease((char *)buffer
);
6061 return (IPP_STATE_ERROR
);
6070 * Arrays and sets are done by sending additional
6071 * values with a zero-length name...
6074 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6080 * Write a data length of 0 and flush the buffer...
6086 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6088 DEBUG_puts("1ippWriteIO: Could not write IPP "
6090 _cupsBufferRelease((char *)buffer
);
6091 return (IPP_STATE_ERROR
);
6097 * Then write the collection attribute...
6100 value
->collection
->state
= IPP_STATE_IDLE
;
6102 if (ippWriteIO(dst
, cb
, 1, ipp
,
6103 value
->collection
) == IPP_STATE_ERROR
)
6105 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6106 _cupsBufferRelease((char *)buffer
);
6107 return (IPP_STATE_ERROR
);
6113 for (i
= 0, value
= attr
->values
;
6114 i
< attr
->num_values
;
6120 * Arrays and sets are done by sending additional
6121 * values with a zero-length name...
6124 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6126 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6128 DEBUG_puts("1ippWriteIO: Could not write IPP "
6130 _cupsBufferRelease((char *)buffer
);
6131 return (IPP_STATE_ERROR
);
6137 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6143 * An unknown value might some new value that a
6144 * vendor has come up with. It consists of a
6145 * 2-byte length and the bytes in the unknown
6149 n
= value
->unknown
.length
;
6151 if (n
> (IPP_BUF_SIZE
- 2))
6153 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6155 _cupsBufferRelease((char *)buffer
);
6156 return (IPP_STATE_ERROR
);
6159 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6161 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6163 DEBUG_puts("1ippWriteIO: Could not write IPP "
6165 _cupsBufferRelease((char *)buffer
);
6166 return (IPP_STATE_ERROR
);
6172 /* Length of unknown value */
6173 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6174 *bufptr
++ = (ipp_uchar_t
)n
;
6179 memcpy(bufptr
, value
->unknown
.data
, (size_t)n
);
6187 * Write the data out...
6190 if (bufptr
> buffer
)
6192 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6194 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6195 _cupsBufferRelease((char *)buffer
);
6196 return (IPP_STATE_ERROR
);
6199 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6200 (int)(bufptr
- buffer
)));
6204 * If blocking is disabled and we aren't at the end of the attribute
6205 * list, stop here...
6208 if (!blocking
&& ipp
->current
)
6212 if (ipp
->current
== NULL
)
6215 * Done with all of the attributes; add the end-of-attributes
6216 * tag or end-collection attribute...
6221 buffer
[0] = IPP_TAG_END
;
6226 buffer
[0] = IPP_TAG_END_COLLECTION
;
6227 buffer
[1] = 0; /* empty name */
6229 buffer
[3] = 0; /* empty value */
6234 if ((*cb
)(dst
, buffer
, (size_t)n
) < 0)
6236 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6237 _cupsBufferRelease((char *)buffer
);
6238 return (IPP_STATE_ERROR
);
6241 ipp
->state
= IPP_STATE_DATA
;
6245 case IPP_STATE_DATA
:
6249 break; /* anti-compiler-warning-code */
6252 _cupsBufferRelease((char *)buffer
);
6254 return (ipp
->state
);
6259 * 'ipp_add_attr()' - Add a new attribute to the message.
6262 static ipp_attribute_t
* /* O - New attribute */
6263 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6264 const char *name
, /* I - Attribute name or NULL */
6265 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6266 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6267 int num_values
) /* I - Number of values */
6269 int alloc_values
; /* Number of values to allocate */
6270 ipp_attribute_t
*attr
; /* New attribute */
6273 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
));
6276 * Range check input...
6279 if (!ipp
|| num_values
< 0)
6283 * Allocate memory, rounding the allocation up as needed...
6286 if (num_values
<= 1)
6289 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6291 attr
= calloc(sizeof(ipp_attribute_t
) +
6292 (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6297 * Initialize attribute...
6300 DEBUG_printf(("4debug_alloc: %p %s %s%s (%d values)", (void *)attr
, name
, num_values
> 1 ? "1setOf " : "", ippTagString(value_tag
), num_values
));
6303 attr
->name
= _cupsStrAlloc(name
);
6305 attr
->group_tag
= group_tag
;
6306 attr
->value_tag
= value_tag
;
6307 attr
->num_values
= num_values
;
6310 * Add it to the end of the linked list...
6314 ipp
->last
->next
= attr
;
6318 ipp
->prev
= ipp
->last
;
6319 ipp
->last
= ipp
->current
= attr
;
6322 DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr
));
6329 * 'ipp_free_values()' - Free attribute values.
6333 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6334 int element
,/* I - First value to free */
6335 int count
) /* I - Number of values to free */
6337 int i
; /* Looping var */
6338 _ipp_value_t
*value
; /* Current value */
6341 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", (void *)attr
, element
, count
));
6343 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6346 * Free values as needed...
6349 switch (attr
->value_tag
)
6351 case IPP_TAG_TEXTLANG
:
6352 case IPP_TAG_NAMELANG
:
6353 if (element
== 0 && count
== attr
->num_values
&&
6354 attr
->values
[0].string
.language
)
6356 _cupsStrFree(attr
->values
[0].string
.language
);
6357 attr
->values
[0].string
.language
= NULL
;
6359 /* Fall through to other string values */
6363 case IPP_TAG_RESERVED_STRING
:
6364 case IPP_TAG_KEYWORD
:
6366 case IPP_TAG_URISCHEME
:
6367 case IPP_TAG_CHARSET
:
6368 case IPP_TAG_LANGUAGE
:
6369 case IPP_TAG_MIMETYPE
:
6370 for (i
= count
, value
= attr
->values
+ element
;
6374 _cupsStrFree(value
->string
.text
);
6375 value
->string
.text
= NULL
;
6379 case IPP_TAG_DEFAULT
:
6380 case IPP_TAG_UNKNOWN
:
6381 case IPP_TAG_NOVALUE
:
6382 case IPP_TAG_NOTSETTABLE
:
6383 case IPP_TAG_DELETEATTR
:
6384 case IPP_TAG_ADMINDEFINE
:
6385 case IPP_TAG_INTEGER
:
6387 case IPP_TAG_BOOLEAN
:
6389 case IPP_TAG_RESOLUTION
:
6390 case IPP_TAG_RANGE
:
6393 case IPP_TAG_BEGIN_COLLECTION
:
6394 for (i
= count
, value
= attr
->values
+ element
;
6398 ippDelete(value
->collection
);
6399 value
->collection
= NULL
;
6403 case IPP_TAG_STRING
:
6405 for (i
= count
, value
= attr
->values
+ element
;
6409 if (value
->unknown
.data
)
6411 free(value
->unknown
.data
);
6412 value
->unknown
.data
= NULL
;
6420 * If we are not freeing values from the end, move the remaining values up...
6423 if ((element
+ count
) < attr
->num_values
)
6424 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6425 (size_t)(attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6427 attr
->num_values
-= count
;
6432 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6434 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6435 * to "ll-cc", "ll-region", and "charset-number", respectively.
6438 static char * /* O - Language code string */
6439 ipp_get_code(const char *value
, /* I - Locale/charset string */
6440 char *buffer
, /* I - String buffer */
6441 size_t bufsize
) /* I - Size of string buffer */
6443 char *bufptr
, /* Pointer into buffer */
6444 *bufend
; /* End of buffer */
6448 * Convert values to lowercase and change _ to - as needed...
6451 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6452 *value
&& bufptr
< bufend
;
6457 *bufptr
++ = (char)_cups_tolower(*value
);
6462 * Return the converted string...
6470 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6472 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6473 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6476 static char * /* O - Language code string */
6477 ipp_lang_code(const char *locale
, /* I - Locale string */
6478 char *buffer
, /* I - String buffer */
6479 size_t bufsize
) /* I - Size of string buffer */
6482 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6485 if (!_cups_strcasecmp(locale
, "c"))
6487 strlcpy(buffer
, "en", bufsize
);
6491 return (ipp_get_code(locale
, buffer
, bufsize
));
6496 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6499 static size_t /* O - Size of IPP message */
6500 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6501 int collection
) /* I - 1 if a collection, 0 otherwise */
6503 int i
; /* Looping var */
6504 size_t bytes
; /* Number of bytes */
6505 ipp_attribute_t
*attr
; /* Current attribute */
6506 ipp_tag_t group
; /* Current group */
6507 _ipp_value_t
*value
; /* Current value */
6510 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp
, collection
));
6514 DEBUG_puts("4ipp_length: Returning 0 bytes");
6519 * Start with 8 bytes for the IPP message header...
6522 bytes
= collection
? 0 : 8;
6525 * Then add the lengths of each attribute...
6528 group
= IPP_TAG_ZERO
;
6530 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6532 if (attr
->group_tag
!= group
&& !collection
)
6534 group
= attr
->group_tag
;
6535 if (group
== IPP_TAG_ZERO
)
6538 bytes
++; /* Group tag */
6544 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6545 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6547 if ((attr
->value_tag
& ~IPP_TAG_CUPS_CONST
) < IPP_TAG_EXTENSION
)
6548 bytes
+= (size_t)attr
->num_values
;/* Value tag for each value */
6550 bytes
+= (size_t)(5 * attr
->num_values
);
6551 /* Value tag for each value */
6552 bytes
+= (size_t)(2 * attr
->num_values
);
6554 bytes
+= strlen(attr
->name
); /* Name */
6555 bytes
+= (size_t)(2 * attr
->num_values
);
6559 bytes
+= 5; /* Add membername overhead */
6561 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6563 case IPP_TAG_UNSUPPORTED_VALUE
:
6564 case IPP_TAG_DEFAULT
:
6565 case IPP_TAG_UNKNOWN
:
6566 case IPP_TAG_NOVALUE
:
6567 case IPP_TAG_NOTSETTABLE
:
6568 case IPP_TAG_DELETEATTR
:
6569 case IPP_TAG_ADMINDEFINE
:
6572 case IPP_TAG_INTEGER
:
6574 bytes
+= (size_t)(4 * attr
->num_values
);
6577 case IPP_TAG_BOOLEAN
:
6578 bytes
+= (size_t)attr
->num_values
;
6583 case IPP_TAG_KEYWORD
:
6585 case IPP_TAG_URISCHEME
:
6586 case IPP_TAG_CHARSET
:
6587 case IPP_TAG_LANGUAGE
:
6588 case IPP_TAG_MIMETYPE
:
6589 for (i
= 0, value
= attr
->values
;
6590 i
< attr
->num_values
;
6592 if (value
->string
.text
)
6593 bytes
+= strlen(value
->string
.text
);
6597 bytes
+= (size_t)(11 * attr
->num_values
);
6600 case IPP_TAG_RESOLUTION
:
6601 bytes
+= (size_t)(9 * attr
->num_values
);
6604 case IPP_TAG_RANGE
:
6605 bytes
+= (size_t)(8 * attr
->num_values
);
6608 case IPP_TAG_TEXTLANG
:
6609 case IPP_TAG_NAMELANG
:
6610 bytes
+= (size_t)(4 * attr
->num_values
);
6611 /* Charset + text length */
6613 for (i
= 0, value
= attr
->values
;
6614 i
< attr
->num_values
;
6617 if (value
->string
.language
)
6618 bytes
+= strlen(value
->string
.language
);
6620 if (value
->string
.text
)
6621 bytes
+= strlen(value
->string
.text
);
6625 case IPP_TAG_BEGIN_COLLECTION
:
6626 for (i
= 0, value
= attr
->values
;
6627 i
< attr
->num_values
;
6629 bytes
+= ipp_length(value
->collection
, 1);
6633 for (i
= 0, value
= attr
->values
;
6634 i
< attr
->num_values
;
6636 bytes
+= (size_t)value
->unknown
.length
;
6642 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6643 * for the "end of collection" tag and return...
6651 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6658 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6661 static ssize_t
/* O - Number of bytes read */
6662 ipp_read_http(http_t
*http
, /* I - Client connection */
6663 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6664 size_t length
) /* I - Total length */
6666 ssize_t tbytes
, /* Total bytes read */
6667 bytes
; /* Bytes read this pass */
6670 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http
, (void *)buffer
, (int)length
));
6673 * Loop until all bytes are read...
6676 for (tbytes
= 0, bytes
= 0;
6677 tbytes
< (int)length
;
6678 tbytes
+= bytes
, buffer
+= bytes
)
6680 DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT
", http->state=%d", CUPS_LLCAST tbytes
, http
->state
));
6682 if (http
->state
== HTTP_STATE_WAITING
)
6685 if (http
->used
== 0 && !http
->blocking
)
6688 * Wait up to 10 seconds for more data on non-blocking sockets...
6691 if (!httpWait(http
, 10000))
6701 else if (http
->used
== 0 && http
->timeout_value
> 0)
6704 * Wait up to timeout seconds for more data on blocking sockets...
6707 if (!httpWait(http
, (int)(1000 * http
->timeout_value
)))
6718 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- (size_t)tbytes
)) < 0)
6723 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6729 else if (bytes
== 0)
6734 * Return the number of bytes read...
6737 if (tbytes
== 0 && bytes
< 0)
6740 DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST tbytes
));
6747 * 'ipp_read_file()' - Read IPP data from a file.
6750 static ssize_t
/* O - Number of bytes read */
6751 ipp_read_file(int *fd
, /* I - File descriptor */
6752 ipp_uchar_t
*buffer
, /* O - Read buffer */
6753 size_t length
) /* I - Number of bytes to read */
6756 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6758 return (read(*fd
, buffer
, length
));
6764 * 'ipp_set_error()' - Set a formatted, localized error string.
6768 ipp_set_error(ipp_status_t status
, /* I - Status code */
6769 const char *format
, /* I - Printf-style error string */
6770 ...) /* I - Additional arguments as needed */
6772 va_list ap
; /* Pointer to additional args */
6773 char buffer
[2048]; /* Message buffer */
6774 cups_lang_t
*lang
= cupsLangDefault();
6775 /* Current language */
6778 va_start(ap
, format
);
6779 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6782 _cupsSetError(status
, buffer
, 0);
6787 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6791 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6792 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6793 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6794 int element
) /* I - Value number (0-based) */
6796 ipp_attribute_t
*temp
, /* New attribute pointer */
6797 *current
, /* Current attribute in list */
6798 *prev
; /* Previous attribute in list */
6799 int alloc_values
; /* Allocated values */
6803 * If we are setting an existing value element, return it...
6808 if (temp
->num_values
<= 1)
6811 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6812 ~(IPP_MAX_VALUES
- 1);
6814 if (element
< alloc_values
)
6816 if (element
>= temp
->num_values
)
6817 temp
->num_values
= element
+ 1;
6819 return (temp
->values
+ element
);
6823 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6824 * values when num_values > 1.
6827 if (alloc_values
< IPP_MAX_VALUES
)
6828 alloc_values
= IPP_MAX_VALUES
;
6830 alloc_values
+= IPP_MAX_VALUES
;
6832 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6836 * Reallocate memory...
6839 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) + (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6841 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6842 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6847 * Zero the new memory...
6850 memset(temp
->values
+ temp
->num_values
, 0, (size_t)(alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6855 * Reset pointers in the list...
6858 DEBUG_printf(("4debug_free: %p %s", (void *)*attr
, temp
->name
));
6859 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
));
6861 if (ipp
->current
== *attr
&& ipp
->prev
)
6864 * Use current "previous" pointer...
6872 * Find this attribute in the linked list...
6875 for (prev
= NULL
, current
= ipp
->attrs
;
6876 current
&& current
!= *attr
;
6877 prev
= current
, current
= current
->next
);
6882 * This is a serious error!
6886 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
6887 _("IPP attribute is not a member of the message."), 1);
6888 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
6898 ipp
->current
= temp
;
6901 if (ipp
->last
== *attr
)
6908 * Return the value element...
6911 if (element
>= temp
->num_values
)
6912 temp
->num_values
= element
+ 1;
6914 return (temp
->values
+ element
);
6919 * 'ipp_write_file()' - Write IPP data to a file.
6922 static ssize_t
/* O - Number of bytes written */
6923 ipp_write_file(int *fd
, /* I - File descriptor */
6924 ipp_uchar_t
*buffer
, /* I - Data to write */
6925 size_t length
) /* I - Number of bytes to write */
6928 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
6930 return (write(*fd
, buffer
, length
));