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_ZERO
|| (tag
== IPP_TAG_OPERATION
&& ipp
->curtag
!= IPP_TAG_ZERO
))
3089 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Invalid group tag."), 1);
3090 DEBUG_printf(("1ippReadIO: bad tag 0x%02x.", tag
));
3091 _cupsBufferRelease((char *)buffer
);
3092 return (IPP_STATE_ERROR
);
3094 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3097 * Group tag... Set the current group and continue...
3100 if (ipp
->curtag
== tag
)
3101 ipp
->prev
= ippAddSeparator(ipp
);
3102 else if (ipp
->current
)
3103 ipp
->prev
= ipp
->current
;
3106 ipp
->current
= NULL
;
3107 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
, ippTagString(tag
), (void *)ipp
->prev
));
3111 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3112 ippTagString(tag
)));
3118 if ((*cb
)(src
, buffer
, 2) < 2)
3120 DEBUG_puts("1ippReadIO: unable to read name length.");
3121 _cupsBufferRelease((char *)buffer
);
3122 return (IPP_STATE_ERROR
);
3125 n
= (buffer
[0] << 8) | buffer
[1];
3127 if (n
>= IPP_BUF_SIZE
)
3129 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3130 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3131 _cupsBufferRelease((char *)buffer
);
3132 return (IPP_STATE_ERROR
);
3135 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3137 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3138 tag
!= IPP_TAG_END_COLLECTION
)
3141 * More values for current attribute...
3144 if (ipp
->current
== NULL
)
3146 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3147 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3148 _cupsBufferRelease((char *)buffer
);
3149 return (IPP_STATE_ERROR
);
3152 attr
= ipp
->current
;
3153 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3156 * Make sure we aren't adding a new value of a different
3160 if (value_tag
== IPP_TAG_ZERO
)
3163 * Setting the value of a collection member...
3166 attr
->value_tag
= tag
;
3168 else if (value_tag
== IPP_TAG_TEXTLANG
||
3169 value_tag
== IPP_TAG_NAMELANG
||
3170 (value_tag
>= IPP_TAG_TEXT
&&
3171 value_tag
<= IPP_TAG_MIMETYPE
))
3174 * String values can sometimes come across in different
3175 * forms; accept sets of differing values...
3178 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3179 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3180 tag
!= IPP_TAG_NOVALUE
)
3182 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3183 _("IPP 1setOf attribute with incompatible value "
3185 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3186 value_tag
, ippTagString(value_tag
), tag
,
3187 ippTagString(tag
)));
3188 _cupsBufferRelease((char *)buffer
);
3189 return (IPP_STATE_ERROR
);
3192 if (value_tag
!= tag
)
3194 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3195 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3196 ippSetValueTag(ipp
, &attr
, tag
);
3199 else if (value_tag
== IPP_TAG_INTEGER
||
3200 value_tag
== IPP_TAG_RANGE
)
3203 * Integer and rangeOfInteger values can sometimes be mixed; accept
3204 * sets of differing values...
3207 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3209 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3210 _("IPP 1setOf attribute with incompatible value "
3212 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3213 value_tag
, ippTagString(value_tag
), tag
,
3214 ippTagString(tag
)));
3215 _cupsBufferRelease((char *)buffer
);
3216 return (IPP_STATE_ERROR
);
3219 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3222 * Convert integer values to rangeOfInteger values...
3225 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3226 "rangeOfInteger.", attr
->name
));
3227 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3230 else if (value_tag
!= tag
)
3232 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3233 _("IPP 1setOf attribute with incompatible value "
3235 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3236 value_tag
, ippTagString(value_tag
), tag
,
3237 ippTagString(tag
)));
3238 _cupsBufferRelease((char *)buffer
);
3239 return (IPP_STATE_ERROR
);
3243 * Finally, reallocate the attribute array as needed...
3246 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3248 _cupsBufferRelease((char *)buffer
);
3249 return (IPP_STATE_ERROR
);
3252 else if (tag
== IPP_TAG_MEMBERNAME
)
3255 * Name must be length 0!
3260 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3261 DEBUG_puts("1ippReadIO: member name not empty.");
3262 _cupsBufferRelease((char *)buffer
);
3263 return (IPP_STATE_ERROR
);
3267 ipp
->prev
= ipp
->current
;
3269 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3272 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3273 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3274 _cupsBufferRelease((char *)buffer
);
3275 return (IPP_STATE_ERROR
);
3278 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3280 value
= attr
->values
;
3282 else if (tag
!= IPP_TAG_END_COLLECTION
)
3285 * New attribute; read the name and add it...
3288 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3290 DEBUG_puts("1ippReadIO: unable to read name.");
3291 _cupsBufferRelease((char *)buffer
);
3292 return (IPP_STATE_ERROR
);
3298 ipp
->prev
= ipp
->current
;
3300 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3303 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3304 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3305 _cupsBufferRelease((char *)buffer
);
3306 return (IPP_STATE_ERROR
);
3309 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer
, (void *)ipp
->current
, (void *)ipp
->prev
));
3311 value
= attr
->values
;
3319 if ((*cb
)(src
, buffer
, 2) < 2)
3321 DEBUG_puts("1ippReadIO: unable to read value length.");
3322 _cupsBufferRelease((char *)buffer
);
3323 return (IPP_STATE_ERROR
);
3326 n
= (buffer
[0] << 8) | buffer
[1];
3327 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3329 if (n
>= IPP_BUF_SIZE
)
3331 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3332 _("IPP value larger than 32767 bytes."), 1);
3333 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3334 _cupsBufferRelease((char *)buffer
);
3335 return (IPP_STATE_ERROR
);
3340 case IPP_TAG_INTEGER
:
3344 if (tag
== IPP_TAG_INTEGER
)
3345 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3346 _("IPP integer value not 4 bytes."), 1);
3348 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3349 _("IPP enum value not 4 bytes."), 1);
3350 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3351 _cupsBufferRelease((char *)buffer
);
3352 return (IPP_STATE_ERROR
);
3355 if ((*cb
)(src
, buffer
, 4) < 4)
3357 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3358 _cupsBufferRelease((char *)buffer
);
3359 return (IPP_STATE_ERROR
);
3362 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3365 if (attr
->value_tag
== IPP_TAG_RANGE
)
3366 value
->range
.lower
= value
->range
.upper
= n
;
3371 case IPP_TAG_BOOLEAN
:
3374 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3376 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3377 _cupsBufferRelease((char *)buffer
);
3378 return (IPP_STATE_ERROR
);
3381 if ((*cb
)(src
, buffer
, 1) < 1)
3383 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3384 _cupsBufferRelease((char *)buffer
);
3385 return (IPP_STATE_ERROR
);
3388 value
->boolean
= (char)buffer
[0];
3391 case IPP_TAG_NOVALUE
:
3392 case IPP_TAG_NOTSETTABLE
:
3393 case IPP_TAG_DELETEATTR
:
3394 case IPP_TAG_ADMINDEFINE
:
3396 * These value types are not supposed to have values, however
3397 * some vendors (Brother) do not implement IPP correctly and so
3398 * we need to map non-empty values to text...
3401 if (attr
->value_tag
== tag
)
3406 attr
->value_tag
= IPP_TAG_TEXT
;
3411 case IPP_TAG_KEYWORD
:
3413 case IPP_TAG_URISCHEME
:
3414 case IPP_TAG_CHARSET
:
3415 case IPP_TAG_LANGUAGE
:
3416 case IPP_TAG_MIMETYPE
:
3419 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3421 DEBUG_puts("1ippReadIO: unable to read string value.");
3422 _cupsBufferRelease((char *)buffer
);
3423 return (IPP_STATE_ERROR
);
3428 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3429 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3435 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3436 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3437 _cupsBufferRelease((char *)buffer
);
3438 return (IPP_STATE_ERROR
);
3441 if ((*cb
)(src
, value
->date
, 11) < 11)
3443 DEBUG_puts("1ippReadIO: Unable to read date value.");
3444 _cupsBufferRelease((char *)buffer
);
3445 return (IPP_STATE_ERROR
);
3449 case IPP_TAG_RESOLUTION
:
3452 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3453 _("IPP resolution value not 9 bytes."), 1);
3454 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3455 _cupsBufferRelease((char *)buffer
);
3456 return (IPP_STATE_ERROR
);
3459 if ((*cb
)(src
, buffer
, 9) < 9)
3461 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3462 _cupsBufferRelease((char *)buffer
);
3463 return (IPP_STATE_ERROR
);
3466 value
->resolution
.xres
=
3467 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3469 value
->resolution
.yres
=
3470 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3472 value
->resolution
.units
=
3473 (ipp_res_t
)buffer
[8];
3476 case IPP_TAG_RANGE
:
3479 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3480 _("IPP rangeOfInteger value not 8 bytes."), 1);
3481 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3483 _cupsBufferRelease((char *)buffer
);
3484 return (IPP_STATE_ERROR
);
3487 if ((*cb
)(src
, buffer
, 8) < 8)
3489 DEBUG_puts("1ippReadIO: Unable to read range value.");
3490 _cupsBufferRelease((char *)buffer
);
3491 return (IPP_STATE_ERROR
);
3494 value
->range
.lower
=
3495 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3497 value
->range
.upper
=
3498 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3502 case IPP_TAG_TEXTLANG
:
3503 case IPP_TAG_NAMELANG
:
3506 if (tag
== IPP_TAG_TEXTLANG
)
3507 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3508 _("IPP textWithLanguage value less than "
3509 "minimum 4 bytes."), 1);
3511 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3512 _("IPP nameWithLanguage value less than "
3513 "minimum 4 bytes."), 1);
3514 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3516 _cupsBufferRelease((char *)buffer
);
3517 return (IPP_STATE_ERROR
);
3520 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3522 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3524 _cupsBufferRelease((char *)buffer
);
3525 return (IPP_STATE_ERROR
);
3531 * text-with-language and name-with-language are composite
3540 n
= (bufptr
[0] << 8) | bufptr
[1];
3542 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) || n
>= (int)sizeof(string
))
3544 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3545 _("IPP language length overflows value."), 1);
3546 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3548 _cupsBufferRelease((char *)buffer
);
3549 return (IPP_STATE_ERROR
);
3551 else if (n
>= IPP_MAX_LANGUAGE
)
3553 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3554 _("IPP language length too large."), 1);
3555 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3557 _cupsBufferRelease((char *)buffer
);
3558 return (IPP_STATE_ERROR
);
3561 memcpy(string
, bufptr
+ 2, (size_t)n
);
3564 value
->string
.language
= _cupsStrAlloc((char *)string
);
3567 n
= (bufptr
[0] << 8) | bufptr
[1];
3569 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3571 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3572 _("IPP string length overflows value."), 1);
3573 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3574 _cupsBufferRelease((char *)buffer
);
3575 return (IPP_STATE_ERROR
);
3578 bufptr
[2 + n
] = '\0';
3579 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3582 case IPP_TAG_BEGIN_COLLECTION
:
3584 * Oh, boy, here comes a collection value, so read it...
3587 value
->collection
= ippNew();
3591 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3592 _("IPP begCollection value not 0 bytes."), 1);
3593 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3595 _cupsBufferRelease((char *)buffer
);
3596 return (IPP_STATE_ERROR
);
3599 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3601 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3602 _cupsBufferRelease((char *)buffer
);
3603 return (IPP_STATE_ERROR
);
3607 case IPP_TAG_END_COLLECTION
:
3608 _cupsBufferRelease((char *)buffer
);
3612 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3613 _("IPP endCollection value not 0 bytes."), 1);
3614 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3616 return (IPP_STATE_ERROR
);
3619 DEBUG_puts("1ippReadIO: endCollection tag...");
3620 return (ipp
->state
= IPP_STATE_DATA
);
3622 case IPP_TAG_MEMBERNAME
:
3624 * The value the name of the member in the collection, which
3625 * we need to carry over...
3630 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3631 _("IPP memberName with no attribute."), 1);
3632 DEBUG_puts("1ippReadIO: Member name without attribute.");
3633 _cupsBufferRelease((char *)buffer
);
3634 return (IPP_STATE_ERROR
);
3638 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3639 _("IPP memberName value is empty."), 1);
3640 DEBUG_puts("1ippReadIO: Empty member name value.");
3641 _cupsBufferRelease((char *)buffer
);
3642 return (IPP_STATE_ERROR
);
3644 else if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3646 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3647 _cupsBufferRelease((char *)buffer
);
3648 return (IPP_STATE_ERROR
);
3652 attr
->name
= _cupsStrAlloc((char *)buffer
);
3655 * Since collection members are encoded differently than
3656 * regular attributes, make sure we don't start with an
3660 attr
->num_values
--;
3662 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3665 default : /* Other unsupported values */
3666 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3668 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3669 _("IPP octetString length too large."), 1);
3670 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3672 _cupsBufferRelease((char *)buffer
);
3673 return (IPP_STATE_ERROR
);
3676 value
->unknown
.length
= n
;
3680 if ((value
->unknown
.data
= malloc((size_t)n
)) == NULL
)
3682 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3683 DEBUG_puts("1ippReadIO: Unable to allocate value");
3684 _cupsBufferRelease((char *)buffer
);
3685 return (IPP_STATE_ERROR
);
3688 if ((*cb
)(src
, value
->unknown
.data
, (size_t)n
) < n
)
3690 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3691 _cupsBufferRelease((char *)buffer
);
3692 return (IPP_STATE_ERROR
);
3696 value
->unknown
.data
= NULL
;
3701 * If blocking is disabled, stop here...
3709 case IPP_STATE_DATA
:
3713 break; /* anti-compiler-warning-code */
3716 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3717 _cupsBufferRelease((char *)buffer
);
3719 return (ipp
->state
);
3724 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3726 * The @code ipp@ parameter refers to an IPP message previously created using
3727 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3729 * The @code attr@ parameter may be modified as a result of setting the value.
3731 * The @code element@ parameter specifies which value to set from 0 to
3732 * @code ippGetCount(attr)@.
3734 * @since CUPS 1.6/macOS 10.8@
3737 int /* O - 1 on success, 0 on failure */
3738 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3739 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3740 int element
, /* I - Value number (0-based) */
3741 int boolvalue
)/* I - Boolean value */
3743 _ipp_value_t
*value
; /* Current value */
3747 * Range check input...
3750 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3751 element
< 0 || element
> (*attr
)->num_values
)
3755 * Set the value and return...
3758 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3759 value
->boolean
= (char)boolvalue
;
3761 return (value
!= NULL
);
3766 * 'ippSetCollection()' - Set a collection value in an attribute.
3768 * The @code ipp@ parameter refers to an IPP message previously created using
3769 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3771 * The @code attr@ parameter may be modified as a result of setting the value.
3773 * The @code element@ parameter specifies which value to set from 0 to
3774 * @code ippGetCount(attr)@.
3776 * @since CUPS 1.6/macOS 10.8@
3779 int /* O - 1 on success, 0 on failure */
3781 ipp_t
*ipp
, /* I - IPP message */
3782 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3783 int element
, /* I - Value number (0-based) */
3784 ipp_t
*colvalue
) /* I - Collection value */
3786 _ipp_value_t
*value
; /* Current value */
3790 * Range check input...
3793 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3794 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3798 * Set the value and return...
3801 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3803 if (value
->collection
)
3804 ippDelete(value
->collection
);
3806 value
->collection
= colvalue
;
3810 return (value
!= NULL
);
3815 * 'ippSetDate()' - Set a dateTime value in an attribute.
3817 * The @code ipp@ parameter refers to an IPP message previously created using
3818 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3820 * The @code attr@ parameter may be modified as a result of setting the value.
3822 * The @code element@ parameter specifies which value to set from 0 to
3823 * @code ippGetCount(attr)@.
3825 * @since CUPS 1.6/macOS 10.8@
3828 int /* O - 1 on success, 0 on failure */
3829 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3830 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3831 int element
, /* I - Value number (0-based) */
3832 const ipp_uchar_t
*datevalue
)/* I - dateTime value */
3834 _ipp_value_t
*value
; /* Current value */
3838 * Range check input...
3841 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3842 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3846 * Set the value and return...
3849 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3850 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3852 return (value
!= NULL
);
3857 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3859 * The @code ipp@ parameter refers to an IPP message previously created using
3860 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3862 * The @code attr@ parameter may be modified as a result of setting the value.
3864 * The @code group@ parameter specifies the IPP attribute group tag: none
3865 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3866 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3867 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3868 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3870 * @since CUPS 1.6/macOS 10.8@
3873 int /* O - 1 on success, 0 on failure */
3875 ipp_t
*ipp
, /* I - IPP message */
3876 ipp_attribute_t
**attr
, /* IO - Attribute */
3877 ipp_tag_t group_tag
) /* I - Group tag */
3880 * Range check input - group tag must be 0x01 to 0x0F, per RFC 8011...
3883 if (!ipp
|| !attr
|| !*attr
||
3884 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3885 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3889 * Set the group tag and return...
3892 (*attr
)->group_tag
= group_tag
;
3899 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3901 * The @code ipp@ parameter refers to an IPP message previously created using
3902 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3904 * The @code attr@ parameter may be modified as a result of setting the value.
3906 * The @code element@ parameter specifies which value to set from 0 to
3907 * @code ippGetCount(attr)@.
3909 * @since CUPS 1.6/macOS 10.8@
3912 int /* O - 1 on success, 0 on failure */
3913 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3914 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3915 int element
, /* I - Value number (0-based) */
3916 int intvalue
) /* I - Integer/enum value */
3918 _ipp_value_t
*value
; /* Current value */
3922 * Range check input...
3925 if (!ipp
|| !attr
|| !*attr
||
3926 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3927 element
< 0 || element
> (*attr
)->num_values
)
3931 * Set the value and return...
3934 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3935 value
->integer
= intvalue
;
3937 return (value
!= NULL
);
3942 * 'ippSetName()' - Set the name of an attribute.
3944 * The @code ipp@ parameter refers to an IPP message previously created using
3945 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3947 * The @code attr@ parameter may be modified as a result of setting the value.
3949 * @since CUPS 1.6/macOS 10.8@
3952 int /* O - 1 on success, 0 on failure */
3953 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3954 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3955 const char *name
) /* I - Attribute name */
3957 char *temp
; /* Temporary name value */
3961 * Range check input...
3964 if (!ipp
|| !attr
|| !*attr
)
3968 * Set the value and return...
3971 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3974 _cupsStrFree((*attr
)->name
);
3976 (*attr
)->name
= temp
;
3979 return (temp
!= NULL
);
3984 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
3986 * The @code ipp@ parameter refers to an IPP message previously created using
3987 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3989 * The @code attr@ parameter may be modified as a result of setting the value.
3991 * The @code element@ parameter specifies which value to set from 0 to
3992 * @code ippGetCount(attr)@.
3994 * @since CUPS 1.7/macOS 10.9@
3997 int /* O - 1 on success, 0 on failure */
3999 ipp_t
*ipp
, /* I - IPP message */
4000 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4001 int element
, /* I - Value number (0-based) */
4002 const void *data
, /* I - Pointer to octetString data */
4003 int datalen
) /* I - Length of octetString data */
4005 _ipp_value_t
*value
; /* Current value */
4009 * Range check input...
4012 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_STRING
||
4013 element
< 0 || element
> (*attr
)->num_values
||
4014 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
4018 * Set the value and return...
4021 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4023 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4026 * Just copy the pointer...
4029 value
->unknown
.data
= (void *)data
;
4030 value
->unknown
.length
= datalen
;
4038 if (value
->unknown
.data
)
4041 * Free previous data...
4044 free(value
->unknown
.data
);
4046 value
->unknown
.data
= NULL
;
4047 value
->unknown
.length
= 0;
4052 void *temp
; /* Temporary data pointer */
4054 if ((temp
= malloc((size_t)datalen
)) != NULL
)
4056 memcpy(temp
, data
, (size_t)datalen
);
4058 value
->unknown
.data
= temp
;
4059 value
->unknown
.length
= datalen
;
4067 return (value
!= NULL
);
4072 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
4074 * The @code ipp@ parameter refers to an IPP message previously created using
4075 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4077 * @since CUPS 1.6/macOS 10.8@
4080 int /* O - 1 on success, 0 on failure */
4081 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
4082 ipp_op_t op
) /* I - Operation ID */
4085 * Range check input...
4092 * Set the operation and return...
4095 ipp
->request
.op
.operation_id
= op
;
4102 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4104 * The @code ipp@ parameter refers to an IPP message previously created using
4105 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4107 * The @code attr@ parameter may be modified as a result of setting the value.
4109 * The @code element@ parameter specifies which value to set from 0 to
4110 * @code ippGetCount(attr)@.
4112 * @since CUPS 1.6/macOS 10.8@
4115 int /* O - 1 on success, 0 on failure */
4116 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4117 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4118 int element
, /* I - Value number (0-based) */
4119 int lowervalue
, /* I - Lower bound for range */
4120 int uppervalue
) /* I - Upper bound for range */
4122 _ipp_value_t
*value
; /* Current value */
4126 * Range check input...
4129 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4130 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4134 * Set the value and return...
4137 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4139 value
->range
.lower
= lowervalue
;
4140 value
->range
.upper
= uppervalue
;
4143 return (value
!= NULL
);
4148 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4150 * The @code ipp@ parameter refers to an IPP message previously created using
4151 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4153 * The @code request_id@ parameter must be greater than 0.
4155 * @since CUPS 1.6/macOS 10.8@
4158 int /* O - 1 on success, 0 on failure */
4159 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4160 int request_id
) /* I - Request ID */
4163 * Range check input; not checking request_id values since ipptool wants to send
4164 * invalid values for conformance testing and a bad request_id does not affect the
4165 * encoding of a message...
4172 * Set the request ID and return...
4175 ipp
->request
.any
.request_id
= request_id
;
4182 * 'ippSetResolution()' - Set a resolution value in an attribute.
4184 * The @code ipp@ parameter refers to an IPP message previously created using
4185 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4187 * The @code attr@ parameter may be modified as a result of setting the value.
4189 * The @code element@ parameter specifies which value to set from 0 to
4190 * @code ippGetCount(attr)@.
4192 * @since CUPS 1.6/macOS 10.8@
4195 int /* O - 1 on success, 0 on failure */
4197 ipp_t
*ipp
, /* I - IPP message */
4198 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4199 int element
, /* I - Value number (0-based) */
4200 ipp_res_t unitsvalue
, /* I - Resolution units */
4201 int xresvalue
, /* I - Horizontal/cross feed resolution */
4202 int yresvalue
) /* I - Vertical/feed resolution */
4204 _ipp_value_t
*value
; /* Current value */
4208 * Range check input...
4211 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4212 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4213 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4217 * Set the value and return...
4220 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4222 value
->resolution
.units
= unitsvalue
;
4223 value
->resolution
.xres
= xresvalue
;
4224 value
->resolution
.yres
= yresvalue
;
4227 return (value
!= NULL
);
4232 * 'ippSetState()' - Set the current state of the IPP message.
4234 * @since CUPS 1.6/macOS 10.8@
4237 int /* O - 1 on success, 0 on failure */
4238 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4239 ipp_state_t state
) /* I - IPP state value */
4242 * Range check input...
4249 * Set the state and return...
4253 ipp
->current
= NULL
;
4260 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4262 * The @code ipp@ parameter refers to an IPP message previously created using
4263 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4265 * @since CUPS 1.6/macOS 10.8@
4268 int /* O - 1 on success, 0 on failure */
4269 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4270 ipp_status_t status
) /* I - Status code */
4273 * Range check input...
4280 * Set the status code and return...
4283 ipp
->request
.status
.status_code
= status
;
4290 * 'ippSetString()' - Set a string value in an attribute.
4292 * The @code ipp@ parameter refers to an IPP message previously created using
4293 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4295 * The @code attr@ parameter may be modified as a result of setting the value.
4297 * The @code element@ parameter specifies which value to set from 0 to
4298 * @code ippGetCount(attr)@.
4300 * @since CUPS 1.6/macOS 10.8@
4303 int /* O - 1 on success, 0 on failure */
4304 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4305 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4306 int element
, /* I - Value number (0-based) */
4307 const char *strvalue
) /* I - String value */
4309 char *temp
; /* Temporary string */
4310 _ipp_value_t
*value
; /* Current value */
4311 ipp_tag_t value_tag
; /* Value tag */
4315 * Range check input...
4319 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4321 value_tag
= IPP_TAG_ZERO
;
4323 if (!ipp
|| !attr
|| !*attr
||
4324 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4325 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4330 * Set the value and return...
4333 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4336 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4338 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4339 value
->string
.text
= (char *)strvalue
;
4340 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4342 if (value
->string
.text
)
4343 _cupsStrFree(value
->string
.text
);
4345 value
->string
.text
= temp
;
4351 return (value
!= NULL
);
4356 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4358 * The @code ipp@ parameter refers to an IPP message previously created using
4359 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4361 * The @code attr@ parameter may be modified as a result of setting the value.
4363 * The @code element@ parameter specifies which value to set from 0 to
4364 * @code ippGetCount(attr)@.
4366 * The @code format@ parameter uses formatting characters compatible with the
4367 * printf family of standard functions. Additional arguments follow it as
4368 * needed. The formatted string is truncated as needed to the maximum length of
4369 * the corresponding value type.
4371 * @since CUPS 1.7/macOS 10.9@
4374 int /* O - 1 on success, 0 on failure */
4375 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4376 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4377 int element
, /* I - Value number (0-based) */
4378 const char *format
, /* I - Printf-style format string */
4379 ...) /* I - Additional arguments as needed */
4381 int ret
; /* Return value */
4382 va_list ap
; /* Pointer to additional arguments */
4385 va_start(ap
, format
);
4386 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4394 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4396 * The @code ipp@ parameter refers to an IPP message previously created using
4397 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4399 * The @code attr@ parameter may be modified as a result of setting the value.
4401 * The @code element@ parameter specifies which value to set from 0 to
4402 * @code ippGetCount(attr)@.
4404 * The @code format@ parameter uses formatting characters compatible with the
4405 * printf family of standard functions. Additional arguments follow it as
4406 * needed. The formatted string is truncated as needed to the maximum length of
4407 * the corresponding value type.
4409 * @since CUPS 1.7/macOS 10.9@
4412 int /* O - 1 on success, 0 on failure */
4413 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4414 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4415 int element
, /* I - Value number (0-based) */
4416 const char *format
, /* I - Printf-style format string */
4417 va_list ap
) /* I - Pointer to additional arguments */
4419 ipp_tag_t value_tag
; /* Value tag */
4420 char buffer
[IPP_MAX_TEXT
+ 4];
4421 /* Formatted text string */
4422 ssize_t bytes
, /* Length of formatted value */
4423 max_bytes
; /* Maximum number of bytes for value */
4427 * Range check input...
4431 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4433 value_tag
= IPP_TAG_ZERO
;
4435 if (!ipp
|| !attr
|| !*attr
||
4436 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4437 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4442 * Format the string...
4445 if (!strcmp(format
, "%s"))
4448 * Optimize the simple case...
4451 const char *s
= va_arg(ap
, char *);
4456 bytes
= (ssize_t
)strlen(s
);
4457 strlcpy(buffer
, s
, sizeof(buffer
));
4462 * Do a full formatting of the message...
4465 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4470 * Limit the length of the string...
4477 case IPP_TAG_TEXTLANG
:
4478 max_bytes
= IPP_MAX_TEXT
;
4482 case IPP_TAG_NAMELANG
:
4483 max_bytes
= IPP_MAX_NAME
;
4486 case IPP_TAG_CHARSET
:
4487 max_bytes
= IPP_MAX_CHARSET
;
4490 case IPP_TAG_KEYWORD
:
4491 max_bytes
= IPP_MAX_KEYWORD
;
4494 case IPP_TAG_LANGUAGE
:
4495 max_bytes
= IPP_MAX_LANGUAGE
;
4498 case IPP_TAG_MIMETYPE
:
4499 max_bytes
= IPP_MAX_MIMETYPE
;
4503 max_bytes
= IPP_MAX_URI
;
4506 case IPP_TAG_URISCHEME
:
4507 max_bytes
= IPP_MAX_URISCHEME
;
4511 if (bytes
>= max_bytes
)
4513 char *bufmax
, /* Buffer at max_bytes */
4514 *bufptr
; /* Pointer into buffer */
4516 bufptr
= buffer
+ strlen(buffer
) - 1;
4517 bufmax
= buffer
+ max_bytes
- 1;
4519 while (bufptr
> bufmax
)
4523 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4534 * Set the formatted string and return...
4537 return (ippSetString(ipp
, attr
, element
, buffer
));
4542 * 'ippSetValueTag()' - Set the value tag of an attribute.
4544 * The @code ipp@ parameter refers to an IPP message previously created using
4545 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4547 * The @code attr@ parameter may be modified as a result of setting the value.
4549 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4550 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4551 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4552 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4553 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4554 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4557 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4558 * code in the "attributes-natural-language" attribute or, if not present, the language
4559 * code for the current locale.
4561 * @since CUPS 1.6/macOS 10.8@
4564 int /* O - 1 on success, 0 on failure */
4566 ipp_t
*ipp
, /* I - IPP message */
4567 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4568 ipp_tag_t value_tag
) /* I - Value tag */
4570 int i
; /* Looping var */
4571 _ipp_value_t
*value
; /* Current value */
4572 int integer
; /* Current integer value */
4573 cups_lang_t
*language
; /* Current language */
4574 char code
[32]; /* Language code */
4575 ipp_tag_t temp_tag
; /* Temporary value tag */
4579 * Range check input...
4582 if (!ipp
|| !attr
|| !*attr
)
4586 * If there is no change, return immediately...
4589 if (value_tag
== (*attr
)->value_tag
)
4593 * Otherwise implement changes as needed...
4596 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4600 case IPP_TAG_UNSUPPORTED_VALUE
:
4601 case IPP_TAG_DEFAULT
:
4602 case IPP_TAG_UNKNOWN
:
4603 case IPP_TAG_NOVALUE
:
4604 case IPP_TAG_NOTSETTABLE
:
4605 case IPP_TAG_DELETEATTR
:
4606 case IPP_TAG_ADMINDEFINE
:
4608 * Free any existing values...
4611 if ((*attr
)->num_values
> 0)
4612 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4615 * Set out-of-band value...
4618 (*attr
)->value_tag
= value_tag
;
4621 case IPP_TAG_RANGE
:
4622 if (temp_tag
!= IPP_TAG_INTEGER
)
4625 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4629 integer
= value
->integer
;
4630 value
->range
.lower
= value
->range
.upper
= integer
;
4633 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4637 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4638 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4639 temp_tag
!= IPP_TAG_MIMETYPE
)
4642 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4645 case IPP_TAG_NAMELANG
:
4646 case IPP_TAG_TEXTLANG
:
4647 if (value_tag
== IPP_TAG_NAMELANG
&&
4648 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4649 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4650 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4653 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4656 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4657 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4660 * Use the language code from the IPP message...
4663 (*attr
)->values
[0].string
.language
=
4664 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4669 * Otherwise, use the language code corresponding to the locale...
4672 language
= cupsLangDefault();
4673 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4678 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4681 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4683 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4686 * Make copies of all values...
4689 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4692 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4695 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4698 case IPP_TAG_KEYWORD
:
4699 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4700 break; /* Silently "allow" name -> keyword */
4711 * 'ippSetVersion()' - Set the version number in an IPP message.
4713 * The @code ipp@ parameter refers to an IPP message previously created using
4714 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4716 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4718 * @since CUPS 1.6/macOS 10.8@
4721 int /* O - 1 on success, 0 on failure */
4722 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4723 int major
, /* I - Major version number (major.minor) */
4724 int minor
) /* I - Minor version number (major.minor) */
4727 * Range check input...
4730 if (!ipp
|| major
< 0 || minor
< 0)
4734 * Set the version number...
4737 ipp
->request
.any
.version
[0] = (ipp_uchar_t
)major
;
4738 ipp
->request
.any
.version
[1] = (ipp_uchar_t
)minor
;
4745 * 'ippTimeToDate()' - Convert from time in seconds to RFC 2579 format.
4748 const ipp_uchar_t
* /* O - RFC-2579 date/time data */
4749 ippTimeToDate(time_t t
) /* I - Time in seconds */
4751 struct tm
*unixdate
; /* UNIX unixdate/time info */
4752 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4753 /* RFC-2579 date/time data */
4757 * RFC-2579 date/time format is:
4759 * Byte(s) Description
4760 * ------- -----------
4761 * 0-1 Year (0 to 65535)
4765 * 5 Minutes (0 to 59)
4766 * 6 Seconds (0 to 60, 60 = "leap second")
4767 * 7 Deciseconds (0 to 9)
4769 * 9 UTC hours (0 to 11)
4770 * 10 UTC minutes (0 to 59)
4773 unixdate
= gmtime(&t
);
4774 unixdate
->tm_year
+= 1900;
4776 date
[0] = (ipp_uchar_t
)(unixdate
->tm_year
>> 8);
4777 date
[1] = (ipp_uchar_t
)(unixdate
->tm_year
);
4778 date
[2] = (ipp_uchar_t
)(unixdate
->tm_mon
+ 1);
4779 date
[3] = (ipp_uchar_t
)unixdate
->tm_mday
;
4780 date
[4] = (ipp_uchar_t
)unixdate
->tm_hour
;
4781 date
[5] = (ipp_uchar_t
)unixdate
->tm_min
;
4782 date
[6] = (ipp_uchar_t
)unixdate
->tm_sec
;
4793 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4795 * This function validates the contents of an attribute based on the name and
4796 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4797 * failure, @link cupsLastErrorString@ is set to a human-readable message.
4799 * @since CUPS 1.7/macOS 10.9@
4802 int /* O - 1 if valid, 0 otherwise */
4803 ippValidateAttribute(
4804 ipp_attribute_t
*attr
) /* I - Attribute */
4806 int i
; /* Looping var */
4807 char scheme
[64], /* Scheme from URI */
4808 userpass
[256], /* Username/password from URI */
4809 hostname
[256], /* Hostname from URI */
4810 resource
[1024]; /* Resource from URI */
4811 int port
, /* Port number from URI */
4812 uri_status
; /* URI separation status */
4813 const char *ptr
; /* Pointer into string */
4814 ipp_attribute_t
*colattr
; /* Collection attribute */
4815 regex_t re
; /* Regular expression */
4816 ipp_uchar_t
*date
; /* Current date value */
4827 * Validate the attribute name.
4830 for (ptr
= attr
->name
; *ptr
; ptr
++)
4831 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4834 if (*ptr
|| ptr
== attr
->name
)
4836 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad attribute name - invalid character (RFC 8011 section 5.1.4)."), attr
->name
);
4840 if ((ptr
- attr
->name
) > 255)
4842 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
));
4846 switch (attr
->value_tag
)
4848 case IPP_TAG_INTEGER
:
4851 case IPP_TAG_BOOLEAN
:
4852 for (i
= 0; i
< attr
->num_values
; i
++)
4854 if (attr
->values
[i
].boolean
!= 0 &&
4855 attr
->values
[i
].boolean
!= 1)
4857 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
);
4864 for (i
= 0; i
< attr
->num_values
; i
++)
4866 if (attr
->values
[i
].integer
< 1)
4868 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
);
4874 case IPP_TAG_STRING
:
4875 for (i
= 0; i
< attr
->num_values
; i
++)
4877 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4879 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
);
4886 for (i
= 0; i
< attr
->num_values
; i
++)
4888 date
= attr
->values
[i
].date
;
4890 if (date
[2] < 1 || date
[2] > 12)
4892 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime month %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[2]);
4896 if (date
[3] < 1 || date
[3] > 31)
4898 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime day %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[3]);
4904 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime hours %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[4]);
4910 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime minutes %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[5]);
4916 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime seconds %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[6]);
4922 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime deciseconds %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[7]);
4926 if (date
[8] != '-' && date
[8] != '+')
4928 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime UTC sign '%c' (RFC 8011 section 5.1.15)."), attr
->name
, date
[8]);
4934 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime UTC hours %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[9]);
4940 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime UTC minutes %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[10]);
4946 case IPP_TAG_RESOLUTION
:
4947 for (i
= 0; i
< attr
->num_values
; i
++)
4949 if (attr
->values
[i
].resolution
.xres
<= 0)
4951 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");
4955 if (attr
->values
[i
].resolution
.yres
<= 0)
4957 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");
4961 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&& attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
4963 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");
4969 case IPP_TAG_RANGE
:
4970 for (i
= 0; i
< attr
->num_values
; i
++)
4972 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
4974 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
);
4980 case IPP_TAG_BEGIN_COLLECTION
:
4981 for (i
= 0; i
< attr
->num_values
; i
++)
4983 for (colattr
= attr
->values
[i
].collection
->attrs
;
4985 colattr
= colattr
->next
)
4987 if (!ippValidateAttribute(colattr
))
4994 case IPP_TAG_TEXTLANG
:
4995 for (i
= 0; i
< attr
->num_values
; i
++)
4997 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
4999 if ((*ptr
& 0xe0) == 0xc0)
5002 if ((*ptr
& 0xc0) != 0x80)
5005 else if ((*ptr
& 0xf0) == 0xe0)
5008 if ((*ptr
& 0xc0) != 0x80)
5011 if ((*ptr
& 0xc0) != 0x80)
5014 else if ((*ptr
& 0xf8) == 0xf0)
5017 if ((*ptr
& 0xc0) != 0x80)
5020 if ((*ptr
& 0xc0) != 0x80)
5023 if ((*ptr
& 0xc0) != 0x80)
5026 else if (*ptr
& 0x80)
5028 else if ((*ptr
< ' ' && *ptr
!= '\n' && *ptr
!= '\r' && *ptr
!= '\t') || *ptr
== 0x7f)
5032 if (*ptr
< ' ' || *ptr
== 0x7f)
5034 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
);
5039 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
);
5043 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5045 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
));
5052 case IPP_TAG_NAMELANG
:
5053 for (i
= 0; i
< attr
->num_values
; i
++)
5055 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5057 if ((*ptr
& 0xe0) == 0xc0)
5060 if ((*ptr
& 0xc0) != 0x80)
5063 else if ((*ptr
& 0xf0) == 0xe0)
5066 if ((*ptr
& 0xc0) != 0x80)
5069 if ((*ptr
& 0xc0) != 0x80)
5072 else if ((*ptr
& 0xf8) == 0xf0)
5075 if ((*ptr
& 0xc0) != 0x80)
5078 if ((*ptr
& 0xc0) != 0x80)
5081 if ((*ptr
& 0xc0) != 0x80)
5084 else if (*ptr
& 0x80)
5086 else if (*ptr
< ' ' || *ptr
== 0x7f)
5090 if (*ptr
< ' ' || *ptr
== 0x7f)
5092 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
);
5097 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
);
5101 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5103 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
));
5109 case IPP_TAG_KEYWORD
:
5110 for (i
= 0; i
< attr
->num_values
; i
++)
5112 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5114 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5119 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5121 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
);
5125 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5127 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
));
5134 for (i
= 0; i
< attr
->num_values
; i
++)
5136 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
));
5138 if (uri_status
< HTTP_URI_STATUS_OK
)
5140 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
));
5144 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5146 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
));
5151 case IPP_TAG_URISCHEME
:
5152 for (i
= 0; i
< attr
->num_values
; i
++)
5154 ptr
= attr
->values
[i
].string
.text
;
5155 if (islower(*ptr
& 255))
5157 for (ptr
++; *ptr
; ptr
++)
5159 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5160 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5165 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5167 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
);
5171 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5173 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
));
5179 case IPP_TAG_CHARSET
:
5180 for (i
= 0; i
< attr
->num_values
; i
++)
5182 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5184 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5185 isspace(*ptr
& 255))
5189 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5191 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
);
5195 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5197 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
));
5203 case IPP_TAG_LANGUAGE
:
5205 * The following regular expression is derived from the ABNF for
5206 * language tags in RFC 4646. All I can say is that this is the
5207 * easiest way to check the values...
5210 if ((i
= regcomp(&re
,
5212 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5214 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5215 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5216 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5217 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5218 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5220 "x(-[a-z0-9]{1,8})+" /* privateuse */
5222 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5224 REG_NOSUB
| REG_EXTENDED
)) != 0)
5226 char temp
[256]; /* Temporary error string */
5228 regerror(i
, &re
, temp
, sizeof(temp
));
5229 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
, _("Unable to compile naturalLanguage regular expression: %s."), temp
);
5233 for (i
= 0; i
< attr
->num_values
; i
++)
5235 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5237 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
);
5242 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5244 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
));
5253 case IPP_TAG_MIMETYPE
:
5255 * The following regular expression is derived from the ABNF for
5256 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5257 * the easiest way to check the values...
5260 if ((i
= regcomp(&re
,
5262 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5264 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5265 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5266 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5269 REG_NOSUB
| REG_EXTENDED
)) != 0)
5271 char temp
[256]; /* Temporary error string */
5273 regerror(i
, &re
, temp
, sizeof(temp
));
5274 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("Unable to compile mimeMediaType regular expression: %s."), temp
);
5278 for (i
= 0; i
< attr
->num_values
; i
++)
5280 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5282 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
);
5287 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5289 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
));
5307 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5309 * This function validates the contents of the IPP message, including each
5310 * attribute. Like @link ippValidateAttribute@, @link cupsLastErrorString@ is
5311 * set to a human-readable message on failure.
5313 * @since CUPS 1.7/macOS 10.9@
5316 int /* O - 1 if valid, 0 otherwise */
5317 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5319 ipp_attribute_t
*attr
; /* Current attribute */
5325 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5326 if (!ippValidateAttribute(attr
))
5334 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5337 ipp_state_t
/* O - Current state */
5338 ippWrite(http_t
*http
, /* I - HTTP connection */
5339 ipp_t
*ipp
) /* I - IPP data */
5341 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http
, (void *)ipp
));
5344 return (IPP_STATE_ERROR
);
5346 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5351 * 'ippWriteFile()' - Write data for an IPP message to a file.
5353 * @since CUPS 1.1.19/macOS 10.3@
5356 ipp_state_t
/* O - Current state */
5357 ippWriteFile(int fd
, /* I - HTTP data */
5358 ipp_t
*ipp
) /* I - IPP data */
5360 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
5362 ipp
->state
= IPP_STATE_IDLE
;
5364 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5369 * 'ippWriteIO()' - Write data for an IPP message.
5371 * @since CUPS 1.2/macOS 10.5@
5374 ipp_state_t
/* O - Current state */
5375 ippWriteIO(void *dst
, /* I - Destination */
5376 ipp_iocb_t cb
, /* I - Write callback function */
5377 int blocking
, /* I - Use blocking IO? */
5378 ipp_t
*parent
, /* I - Parent IPP message */
5379 ipp_t
*ipp
) /* I - IPP data */
5381 int i
; /* Looping var */
5382 int n
; /* Length of data */
5383 unsigned char *buffer
, /* Data buffer */
5384 *bufptr
; /* Pointer into buffer */
5385 ipp_attribute_t
*attr
; /* Current attribute */
5386 _ipp_value_t
*value
; /* Current value */
5389 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
5392 return (IPP_STATE_ERROR
);
5394 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5396 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5397 return (IPP_STATE_ERROR
);
5402 case IPP_STATE_IDLE
:
5403 ipp
->state
++; /* Avoid common problem... */
5405 case IPP_STATE_HEADER
:
5409 * Send the request header:
5412 * Operation/Status Code = 2 bytes
5413 * Request ID = 4 bytes
5419 *bufptr
++ = ipp
->request
.any
.version
[0];
5420 *bufptr
++ = ipp
->request
.any
.version
[1];
5421 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.op_status
>> 8);
5422 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.op_status
;
5423 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 24);
5424 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 16);
5425 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 8);
5426 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.request_id
;
5428 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5429 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5430 ipp
->request
.any
.op_status
));
5431 DEBUG_printf(("2ippWriteIO: request_id=%d",
5432 ipp
->request
.any
.request_id
));
5434 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5436 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5437 _cupsBufferRelease((char *)buffer
);
5438 return (IPP_STATE_ERROR
);
5443 * Reset the state engine to point to the first attribute
5444 * in the request/response, with no current group.
5447 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5448 ipp
->current
= ipp
->attrs
;
5449 ipp
->curtag
= IPP_TAG_ZERO
;
5451 DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp
->current
));
5454 * If blocking is disabled, stop here...
5460 case IPP_STATE_ATTRIBUTE
:
5461 while (ipp
->current
!= NULL
)
5464 * Write this attribute...
5468 attr
= ipp
->current
;
5470 ipp
->current
= ipp
->current
->next
;
5474 if (ipp
->curtag
!= attr
->group_tag
)
5477 * Send a group tag byte...
5480 ipp
->curtag
= attr
->group_tag
;
5482 if (attr
->group_tag
== IPP_TAG_ZERO
)
5485 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5486 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5487 *bufptr
++ = (ipp_uchar_t
)attr
->group_tag
;
5489 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5493 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5494 attr
->num_values
> 1 ? "1setOf " : "",
5495 ippTagString(attr
->value_tag
)));
5498 * Write the attribute tag and name.
5500 * The attribute name length does not include the trailing nul
5501 * character in the source string.
5503 * Collection values (parent != NULL) are written differently...
5509 * Get the length of the attribute name, and make sure it won't
5510 * overflow the buffer...
5513 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5515 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5516 _cupsBufferRelease((char *)buffer
);
5517 return (IPP_STATE_ERROR
);
5521 * Write the value tag, name length, and name string...
5524 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5525 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5526 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5529 if (attr
->value_tag
> 0xff)
5531 *bufptr
++ = IPP_TAG_EXTENSION
;
5532 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5533 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5534 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5535 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5538 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5540 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5541 *bufptr
++ = (ipp_uchar_t
)n
;
5542 memcpy(bufptr
, attr
->name
, (size_t)n
);
5548 * Get the length of the attribute name, and make sure it won't
5549 * overflow the buffer...
5552 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5554 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5555 _cupsBufferRelease((char *)buffer
);
5556 return (IPP_STATE_ERROR
);
5560 * Write the member name tag, name length, name string, value tag,
5561 * and empty name for the collection member attribute...
5564 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5565 IPP_TAG_MEMBERNAME
));
5566 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5568 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5569 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5570 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5572 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5575 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5576 *bufptr
++ = (ipp_uchar_t
)n
;
5577 memcpy(bufptr
, attr
->name
, (size_t)n
);
5580 if (attr
->value_tag
> 0xff)
5582 *bufptr
++ = IPP_TAG_EXTENSION
;
5583 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5584 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5585 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5586 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5589 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5596 * Now write the attribute value(s)...
5599 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5601 case IPP_TAG_UNSUPPORTED_VALUE
:
5602 case IPP_TAG_DEFAULT
:
5603 case IPP_TAG_UNKNOWN
:
5604 case IPP_TAG_NOVALUE
:
5605 case IPP_TAG_NOTSETTABLE
:
5606 case IPP_TAG_DELETEATTR
:
5607 case IPP_TAG_ADMINDEFINE
:
5612 case IPP_TAG_INTEGER
:
5614 for (i
= 0, value
= attr
->values
;
5615 i
< attr
->num_values
;
5618 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5620 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5622 DEBUG_puts("1ippWriteIO: Could not write IPP "
5624 _cupsBufferRelease((char *)buffer
);
5625 return (IPP_STATE_ERROR
);
5634 * Arrays and sets are done by sending additional
5635 * values with a zero-length name...
5638 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5644 * Integers and enumerations are both 4-byte signed
5645 * (twos-complement) values.
5647 * Put the 2-byte length and 4-byte value into the buffer...
5652 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 24);
5653 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 16);
5654 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 8);
5655 *bufptr
++ = (ipp_uchar_t
)value
->integer
;
5659 case IPP_TAG_BOOLEAN
:
5660 for (i
= 0, value
= attr
->values
;
5661 i
< attr
->num_values
;
5664 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5666 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5668 DEBUG_puts("1ippWriteIO: Could not write IPP "
5670 _cupsBufferRelease((char *)buffer
);
5671 return (IPP_STATE_ERROR
);
5680 * Arrays and sets are done by sending additional
5681 * values with a zero-length name...
5684 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5690 * Boolean values are 1-byte; 0 = false, 1 = true.
5692 * Put the 2-byte length and 1-byte value into the buffer...
5697 *bufptr
++ = (ipp_uchar_t
)value
->boolean
;
5703 case IPP_TAG_KEYWORD
:
5705 case IPP_TAG_URISCHEME
:
5706 case IPP_TAG_CHARSET
:
5707 case IPP_TAG_LANGUAGE
:
5708 case IPP_TAG_MIMETYPE
:
5709 for (i
= 0, value
= attr
->values
;
5710 i
< attr
->num_values
;
5716 * Arrays and sets are done by sending additional
5717 * values with a zero-length name...
5720 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5722 ippTagString(attr
->value_tag
)));
5723 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5725 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5727 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5729 DEBUG_puts("1ippWriteIO: Could not write IPP "
5731 _cupsBufferRelease((char *)buffer
);
5732 return (IPP_STATE_ERROR
);
5738 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5743 if (value
->string
.text
!= NULL
)
5744 n
= (int)strlen(value
->string
.text
);
5748 if (n
> (IPP_BUF_SIZE
- 2))
5750 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5751 _cupsBufferRelease((char *)buffer
);
5752 return (IPP_STATE_ERROR
);
5755 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5756 value
->string
.text
));
5758 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5760 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5762 DEBUG_puts("1ippWriteIO: Could not write IPP "
5764 _cupsBufferRelease((char *)buffer
);
5765 return (IPP_STATE_ERROR
);
5772 * All simple strings consist of the 2-byte length and
5773 * character data without the trailing nul normally found
5774 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5775 * bytes since the 2-byte length is a signed (twos-complement)
5778 * Put the 2-byte length and string characters in the buffer.
5781 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5782 *bufptr
++ = (ipp_uchar_t
)n
;
5786 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5793 for (i
= 0, value
= attr
->values
;
5794 i
< attr
->num_values
;
5797 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5799 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5801 DEBUG_puts("1ippWriteIO: Could not write IPP "
5803 _cupsBufferRelease((char *)buffer
);
5804 return (IPP_STATE_ERROR
);
5813 * Arrays and sets are done by sending additional
5814 * values with a zero-length name...
5817 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5823 * Date values consist of a 2-byte length and an
5824 * 11-byte date/time structure defined by RFC 1903.
5826 * Put the 2-byte length and 11-byte date/time
5827 * structure in the buffer.
5832 memcpy(bufptr
, value
->date
, 11);
5837 case IPP_TAG_RESOLUTION
:
5838 for (i
= 0, value
= attr
->values
;
5839 i
< attr
->num_values
;
5842 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5844 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5846 DEBUG_puts("1ippWriteIO: Could not write IPP "
5848 _cupsBufferRelease((char *)buffer
);
5849 return (IPP_STATE_ERROR
);
5858 * Arrays and sets are done by sending additional
5859 * values with a zero-length name...
5862 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5868 * Resolution values consist of a 2-byte length,
5869 * 4-byte horizontal resolution value, 4-byte vertical
5870 * resolution value, and a 1-byte units value.
5872 * Put the 2-byte length and resolution value data
5878 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 24);
5879 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 16);
5880 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 8);
5881 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.xres
;
5882 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 24);
5883 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 16);
5884 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 8);
5885 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.yres
;
5886 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.units
;
5890 case IPP_TAG_RANGE
:
5891 for (i
= 0, value
= attr
->values
;
5892 i
< attr
->num_values
;
5895 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
5897 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5899 DEBUG_puts("1ippWriteIO: Could not write IPP "
5901 _cupsBufferRelease((char *)buffer
);
5902 return (IPP_STATE_ERROR
);
5911 * Arrays and sets are done by sending additional
5912 * values with a zero-length name...
5915 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5921 * Range values consist of a 2-byte length,
5922 * 4-byte lower value, and 4-byte upper value.
5924 * Put the 2-byte length and range value data
5930 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 24);
5931 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 16);
5932 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 8);
5933 *bufptr
++ = (ipp_uchar_t
)value
->range
.lower
;
5934 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 24);
5935 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 16);
5936 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 8);
5937 *bufptr
++ = (ipp_uchar_t
)value
->range
.upper
;
5941 case IPP_TAG_TEXTLANG
:
5942 case IPP_TAG_NAMELANG
:
5943 for (i
= 0, value
= attr
->values
;
5944 i
< attr
->num_values
;
5950 * Arrays and sets are done by sending additional
5951 * values with a zero-length name...
5954 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5956 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5958 DEBUG_puts("1ippWriteIO: Could not write IPP "
5960 _cupsBufferRelease((char *)buffer
);
5961 return (IPP_STATE_ERROR
);
5967 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5973 * textWithLanguage and nameWithLanguage values consist
5974 * of a 2-byte length for both strings and their
5975 * individual lengths, a 2-byte length for the
5976 * character string, the character string without the
5977 * trailing nul, a 2-byte length for the character
5978 * set string, and the character set string without
5984 if (value
->string
.language
!= NULL
)
5985 n
+= (int)strlen(value
->string
.language
);
5987 if (value
->string
.text
!= NULL
)
5988 n
+= (int)strlen(value
->string
.text
);
5990 if (n
> (IPP_BUF_SIZE
- 2))
5992 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
5993 "too long (%d)", n
));
5994 _cupsBufferRelease((char *)buffer
);
5995 return (IPP_STATE_ERROR
);
5998 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6000 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6002 DEBUG_puts("1ippWriteIO: Could not write IPP "
6004 _cupsBufferRelease((char *)buffer
);
6005 return (IPP_STATE_ERROR
);
6011 /* Length of entire value */
6012 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6013 *bufptr
++ = (ipp_uchar_t
)n
;
6015 /* Length of language */
6016 if (value
->string
.language
!= NULL
)
6017 n
= (int)strlen(value
->string
.language
);
6021 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6022 *bufptr
++ = (ipp_uchar_t
)n
;
6027 memcpy(bufptr
, value
->string
.language
, (size_t)n
);
6031 /* Length of text */
6032 if (value
->string
.text
!= NULL
)
6033 n
= (int)strlen(value
->string
.text
);
6037 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6038 *bufptr
++ = (ipp_uchar_t
)n
;
6043 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
6049 case IPP_TAG_BEGIN_COLLECTION
:
6050 for (i
= 0, value
= attr
->values
;
6051 i
< attr
->num_values
;
6055 * Collections are written with the begin-collection
6056 * tag first with a value of 0 length, followed by the
6057 * attributes in the collection, then the end-collection
6061 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6063 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6065 DEBUG_puts("1ippWriteIO: Could not write IPP "
6067 _cupsBufferRelease((char *)buffer
);
6068 return (IPP_STATE_ERROR
);
6077 * Arrays and sets are done by sending additional
6078 * values with a zero-length name...
6081 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6087 * Write a data length of 0 and flush the buffer...
6093 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6095 DEBUG_puts("1ippWriteIO: Could not write IPP "
6097 _cupsBufferRelease((char *)buffer
);
6098 return (IPP_STATE_ERROR
);
6104 * Then write the collection attribute...
6107 value
->collection
->state
= IPP_STATE_IDLE
;
6109 if (ippWriteIO(dst
, cb
, 1, ipp
,
6110 value
->collection
) == IPP_STATE_ERROR
)
6112 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6113 _cupsBufferRelease((char *)buffer
);
6114 return (IPP_STATE_ERROR
);
6120 for (i
= 0, value
= attr
->values
;
6121 i
< attr
->num_values
;
6127 * Arrays and sets are done by sending additional
6128 * values with a zero-length name...
6131 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6133 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6135 DEBUG_puts("1ippWriteIO: Could not write IPP "
6137 _cupsBufferRelease((char *)buffer
);
6138 return (IPP_STATE_ERROR
);
6144 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6150 * An unknown value might some new value that a
6151 * vendor has come up with. It consists of a
6152 * 2-byte length and the bytes in the unknown
6156 n
= value
->unknown
.length
;
6158 if (n
> (IPP_BUF_SIZE
- 2))
6160 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6162 _cupsBufferRelease((char *)buffer
);
6163 return (IPP_STATE_ERROR
);
6166 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6168 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6170 DEBUG_puts("1ippWriteIO: Could not write IPP "
6172 _cupsBufferRelease((char *)buffer
);
6173 return (IPP_STATE_ERROR
);
6179 /* Length of unknown value */
6180 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6181 *bufptr
++ = (ipp_uchar_t
)n
;
6186 memcpy(bufptr
, value
->unknown
.data
, (size_t)n
);
6194 * Write the data out...
6197 if (bufptr
> buffer
)
6199 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6201 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6202 _cupsBufferRelease((char *)buffer
);
6203 return (IPP_STATE_ERROR
);
6206 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6207 (int)(bufptr
- buffer
)));
6211 * If blocking is disabled and we aren't at the end of the attribute
6212 * list, stop here...
6215 if (!blocking
&& ipp
->current
)
6219 if (ipp
->current
== NULL
)
6222 * Done with all of the attributes; add the end-of-attributes
6223 * tag or end-collection attribute...
6228 buffer
[0] = IPP_TAG_END
;
6233 buffer
[0] = IPP_TAG_END_COLLECTION
;
6234 buffer
[1] = 0; /* empty name */
6236 buffer
[3] = 0; /* empty value */
6241 if ((*cb
)(dst
, buffer
, (size_t)n
) < 0)
6243 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6244 _cupsBufferRelease((char *)buffer
);
6245 return (IPP_STATE_ERROR
);
6248 ipp
->state
= IPP_STATE_DATA
;
6252 case IPP_STATE_DATA
:
6256 break; /* anti-compiler-warning-code */
6259 _cupsBufferRelease((char *)buffer
);
6261 return (ipp
->state
);
6266 * 'ipp_add_attr()' - Add a new attribute to the message.
6269 static ipp_attribute_t
* /* O - New attribute */
6270 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6271 const char *name
, /* I - Attribute name or NULL */
6272 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6273 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6274 int num_values
) /* I - Number of values */
6276 int alloc_values
; /* Number of values to allocate */
6277 ipp_attribute_t
*attr
; /* New attribute */
6280 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
));
6283 * Range check input...
6286 if (!ipp
|| num_values
< 0)
6290 * Allocate memory, rounding the allocation up as needed...
6293 if (num_values
<= 1)
6296 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6298 attr
= calloc(sizeof(ipp_attribute_t
) +
6299 (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6304 * Initialize attribute...
6307 DEBUG_printf(("4debug_alloc: %p %s %s%s (%d values)", (void *)attr
, name
, num_values
> 1 ? "1setOf " : "", ippTagString(value_tag
), num_values
));
6310 attr
->name
= _cupsStrAlloc(name
);
6312 attr
->group_tag
= group_tag
;
6313 attr
->value_tag
= value_tag
;
6314 attr
->num_values
= num_values
;
6317 * Add it to the end of the linked list...
6321 ipp
->last
->next
= attr
;
6325 ipp
->prev
= ipp
->last
;
6326 ipp
->last
= ipp
->current
= attr
;
6329 DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr
));
6336 * 'ipp_free_values()' - Free attribute values.
6340 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6341 int element
,/* I - First value to free */
6342 int count
) /* I - Number of values to free */
6344 int i
; /* Looping var */
6345 _ipp_value_t
*value
; /* Current value */
6348 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", (void *)attr
, element
, count
));
6350 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6353 * Free values as needed...
6356 switch (attr
->value_tag
)
6358 case IPP_TAG_TEXTLANG
:
6359 case IPP_TAG_NAMELANG
:
6360 if (element
== 0 && count
== attr
->num_values
&&
6361 attr
->values
[0].string
.language
)
6363 _cupsStrFree(attr
->values
[0].string
.language
);
6364 attr
->values
[0].string
.language
= NULL
;
6366 /* Fall through to other string values */
6370 case IPP_TAG_RESERVED_STRING
:
6371 case IPP_TAG_KEYWORD
:
6373 case IPP_TAG_URISCHEME
:
6374 case IPP_TAG_CHARSET
:
6375 case IPP_TAG_LANGUAGE
:
6376 case IPP_TAG_MIMETYPE
:
6377 for (i
= count
, value
= attr
->values
+ element
;
6381 _cupsStrFree(value
->string
.text
);
6382 value
->string
.text
= NULL
;
6386 case IPP_TAG_DEFAULT
:
6387 case IPP_TAG_UNKNOWN
:
6388 case IPP_TAG_NOVALUE
:
6389 case IPP_TAG_NOTSETTABLE
:
6390 case IPP_TAG_DELETEATTR
:
6391 case IPP_TAG_ADMINDEFINE
:
6392 case IPP_TAG_INTEGER
:
6394 case IPP_TAG_BOOLEAN
:
6396 case IPP_TAG_RESOLUTION
:
6397 case IPP_TAG_RANGE
:
6400 case IPP_TAG_BEGIN_COLLECTION
:
6401 for (i
= count
, value
= attr
->values
+ element
;
6405 ippDelete(value
->collection
);
6406 value
->collection
= NULL
;
6410 case IPP_TAG_STRING
:
6412 for (i
= count
, value
= attr
->values
+ element
;
6416 if (value
->unknown
.data
)
6418 free(value
->unknown
.data
);
6419 value
->unknown
.data
= NULL
;
6427 * If we are not freeing values from the end, move the remaining values up...
6430 if ((element
+ count
) < attr
->num_values
)
6431 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6432 (size_t)(attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6434 attr
->num_values
-= count
;
6439 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6441 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6442 * to "ll-cc", "ll-region", and "charset-number", respectively.
6445 static char * /* O - Language code string */
6446 ipp_get_code(const char *value
, /* I - Locale/charset string */
6447 char *buffer
, /* I - String buffer */
6448 size_t bufsize
) /* I - Size of string buffer */
6450 char *bufptr
, /* Pointer into buffer */
6451 *bufend
; /* End of buffer */
6455 * Convert values to lowercase and change _ to - as needed...
6458 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6459 *value
&& bufptr
< bufend
;
6464 *bufptr
++ = (char)_cups_tolower(*value
);
6469 * Return the converted string...
6477 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6479 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6480 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6483 static char * /* O - Language code string */
6484 ipp_lang_code(const char *locale
, /* I - Locale string */
6485 char *buffer
, /* I - String buffer */
6486 size_t bufsize
) /* I - Size of string buffer */
6489 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6492 if (!_cups_strcasecmp(locale
, "c"))
6494 strlcpy(buffer
, "en", bufsize
);
6498 return (ipp_get_code(locale
, buffer
, bufsize
));
6503 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6506 static size_t /* O - Size of IPP message */
6507 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6508 int collection
) /* I - 1 if a collection, 0 otherwise */
6510 int i
; /* Looping var */
6511 size_t bytes
; /* Number of bytes */
6512 ipp_attribute_t
*attr
; /* Current attribute */
6513 ipp_tag_t group
; /* Current group */
6514 _ipp_value_t
*value
; /* Current value */
6517 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp
, collection
));
6521 DEBUG_puts("4ipp_length: Returning 0 bytes");
6526 * Start with 8 bytes for the IPP message header...
6529 bytes
= collection
? 0 : 8;
6532 * Then add the lengths of each attribute...
6535 group
= IPP_TAG_ZERO
;
6537 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6539 if (attr
->group_tag
!= group
&& !collection
)
6541 group
= attr
->group_tag
;
6542 if (group
== IPP_TAG_ZERO
)
6545 bytes
++; /* Group tag */
6551 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6552 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6554 if ((attr
->value_tag
& ~IPP_TAG_CUPS_CONST
) < IPP_TAG_EXTENSION
)
6555 bytes
+= (size_t)attr
->num_values
;/* Value tag for each value */
6557 bytes
+= (size_t)(5 * attr
->num_values
);
6558 /* Value tag for each value */
6559 bytes
+= (size_t)(2 * attr
->num_values
);
6561 bytes
+= strlen(attr
->name
); /* Name */
6562 bytes
+= (size_t)(2 * attr
->num_values
);
6566 bytes
+= 5; /* Add membername overhead */
6568 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6570 case IPP_TAG_UNSUPPORTED_VALUE
:
6571 case IPP_TAG_DEFAULT
:
6572 case IPP_TAG_UNKNOWN
:
6573 case IPP_TAG_NOVALUE
:
6574 case IPP_TAG_NOTSETTABLE
:
6575 case IPP_TAG_DELETEATTR
:
6576 case IPP_TAG_ADMINDEFINE
:
6579 case IPP_TAG_INTEGER
:
6581 bytes
+= (size_t)(4 * attr
->num_values
);
6584 case IPP_TAG_BOOLEAN
:
6585 bytes
+= (size_t)attr
->num_values
;
6590 case IPP_TAG_KEYWORD
:
6592 case IPP_TAG_URISCHEME
:
6593 case IPP_TAG_CHARSET
:
6594 case IPP_TAG_LANGUAGE
:
6595 case IPP_TAG_MIMETYPE
:
6596 for (i
= 0, value
= attr
->values
;
6597 i
< attr
->num_values
;
6599 if (value
->string
.text
)
6600 bytes
+= strlen(value
->string
.text
);
6604 bytes
+= (size_t)(11 * attr
->num_values
);
6607 case IPP_TAG_RESOLUTION
:
6608 bytes
+= (size_t)(9 * attr
->num_values
);
6611 case IPP_TAG_RANGE
:
6612 bytes
+= (size_t)(8 * attr
->num_values
);
6615 case IPP_TAG_TEXTLANG
:
6616 case IPP_TAG_NAMELANG
:
6617 bytes
+= (size_t)(4 * attr
->num_values
);
6618 /* Charset + text length */
6620 for (i
= 0, value
= attr
->values
;
6621 i
< attr
->num_values
;
6624 if (value
->string
.language
)
6625 bytes
+= strlen(value
->string
.language
);
6627 if (value
->string
.text
)
6628 bytes
+= strlen(value
->string
.text
);
6632 case IPP_TAG_BEGIN_COLLECTION
:
6633 for (i
= 0, value
= attr
->values
;
6634 i
< attr
->num_values
;
6636 bytes
+= ipp_length(value
->collection
, 1);
6640 for (i
= 0, value
= attr
->values
;
6641 i
< attr
->num_values
;
6643 bytes
+= (size_t)value
->unknown
.length
;
6649 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6650 * for the "end of collection" tag and return...
6658 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6665 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6668 static ssize_t
/* O - Number of bytes read */
6669 ipp_read_http(http_t
*http
, /* I - Client connection */
6670 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6671 size_t length
) /* I - Total length */
6673 ssize_t tbytes
, /* Total bytes read */
6674 bytes
; /* Bytes read this pass */
6677 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http
, (void *)buffer
, (int)length
));
6680 * Loop until all bytes are read...
6683 for (tbytes
= 0, bytes
= 0;
6684 tbytes
< (int)length
;
6685 tbytes
+= bytes
, buffer
+= bytes
)
6687 DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT
", http->state=%d", CUPS_LLCAST tbytes
, http
->state
));
6689 if (http
->state
== HTTP_STATE_WAITING
)
6692 if (http
->used
== 0 && !http
->blocking
)
6695 * Wait up to 10 seconds for more data on non-blocking sockets...
6698 if (!httpWait(http
, 10000))
6708 else if (http
->used
== 0 && http
->timeout_value
> 0)
6711 * Wait up to timeout seconds for more data on blocking sockets...
6714 if (!httpWait(http
, (int)(1000 * http
->timeout_value
)))
6725 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- (size_t)tbytes
)) < 0)
6730 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6736 else if (bytes
== 0)
6741 * Return the number of bytes read...
6744 if (tbytes
== 0 && bytes
< 0)
6747 DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST tbytes
));
6754 * 'ipp_read_file()' - Read IPP data from a file.
6757 static ssize_t
/* O - Number of bytes read */
6758 ipp_read_file(int *fd
, /* I - File descriptor */
6759 ipp_uchar_t
*buffer
, /* O - Read buffer */
6760 size_t length
) /* I - Number of bytes to read */
6763 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6765 return (read(*fd
, buffer
, length
));
6771 * 'ipp_set_error()' - Set a formatted, localized error string.
6775 ipp_set_error(ipp_status_t status
, /* I - Status code */
6776 const char *format
, /* I - Printf-style error string */
6777 ...) /* I - Additional arguments as needed */
6779 va_list ap
; /* Pointer to additional args */
6780 char buffer
[2048]; /* Message buffer */
6781 cups_lang_t
*lang
= cupsLangDefault();
6782 /* Current language */
6785 va_start(ap
, format
);
6786 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6789 _cupsSetError(status
, buffer
, 0);
6794 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6798 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6799 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6800 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6801 int element
) /* I - Value number (0-based) */
6803 ipp_attribute_t
*temp
, /* New attribute pointer */
6804 *current
, /* Current attribute in list */
6805 *prev
; /* Previous attribute in list */
6806 int alloc_values
; /* Allocated values */
6810 * If we are setting an existing value element, return it...
6815 if (temp
->num_values
<= 1)
6818 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6819 ~(IPP_MAX_VALUES
- 1);
6821 if (element
< alloc_values
)
6823 if (element
>= temp
->num_values
)
6824 temp
->num_values
= element
+ 1;
6826 return (temp
->values
+ element
);
6830 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6831 * values when num_values > 1.
6834 if (alloc_values
< IPP_MAX_VALUES
)
6835 alloc_values
= IPP_MAX_VALUES
;
6837 alloc_values
+= IPP_MAX_VALUES
;
6839 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6843 * Reallocate memory...
6846 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) + (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6848 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6849 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6854 * Zero the new memory...
6857 memset(temp
->values
+ temp
->num_values
, 0, (size_t)(alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6862 * Reset pointers in the list...
6865 DEBUG_printf(("4debug_free: %p %s", (void *)*attr
, temp
->name
));
6866 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
));
6868 if (ipp
->current
== *attr
&& ipp
->prev
)
6871 * Use current "previous" pointer...
6879 * Find this attribute in the linked list...
6882 for (prev
= NULL
, current
= ipp
->attrs
;
6883 current
&& current
!= *attr
;
6884 prev
= current
, current
= current
->next
);
6889 * This is a serious error!
6893 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
6894 _("IPP attribute is not a member of the message."), 1);
6895 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
6905 ipp
->current
= temp
;
6908 if (ipp
->last
== *attr
)
6915 * Return the value element...
6918 if (element
>= temp
->num_values
)
6919 temp
->num_values
= element
+ 1;
6921 return (temp
->values
+ element
);
6926 * 'ipp_write_file()' - Write IPP data to a file.
6929 static ssize_t
/* O - Number of bytes written */
6930 ipp_write_file(int *fd
, /* I - File descriptor */
6931 ipp_uchar_t
*buffer
, /* I - Data to write */
6932 size_t length
) /* I - Number of bytes to write */
6935 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
6937 return (write(*fd
, buffer
, length
));