2 * Internet Printing Protocol functions for CUPS.
4 * Copyright © 2007-2019 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"
16 #include "debug-internal.h"
27 static ipp_attribute_t
*ipp_add_attr(ipp_t
*ipp
, const char *name
,
28 ipp_tag_t group_tag
, ipp_tag_t value_tag
,
30 static void ipp_free_values(ipp_attribute_t
*attr
, int element
,
32 static char *ipp_get_code(const char *locale
, char *buffer
, size_t bufsize
) _CUPS_NONNULL(1,2);
33 static char *ipp_lang_code(const char *locale
, char *buffer
, size_t bufsize
) _CUPS_NONNULL(1,2);
34 static size_t ipp_length(ipp_t
*ipp
, int collection
);
35 static ssize_t
ipp_read_http(http_t
*http
, ipp_uchar_t
*buffer
,
37 static ssize_t
ipp_read_file(int *fd
, ipp_uchar_t
*buffer
,
39 static void ipp_set_error(ipp_status_t status
, const char *format
,
41 static _ipp_value_t
*ipp_set_value(ipp_t
*ipp
, ipp_attribute_t
**attr
,
43 static ssize_t
ipp_write_file(int *fd
, ipp_uchar_t
*buffer
,
48 * '_cupsBufferGet()' - Get a read/write buffer.
51 char * /* O - Buffer */
52 _cupsBufferGet(size_t size
) /* I - Size required */
54 _cups_buffer_t
*buffer
; /* Current buffer */
55 _cups_globals_t
*cg
= _cupsGlobals();
59 for (buffer
= cg
->cups_buffers
; buffer
; buffer
= buffer
->next
)
60 if (!buffer
->used
&& buffer
->size
>= size
)
65 if ((buffer
= malloc(sizeof(_cups_buffer_t
) + size
- 1)) == NULL
)
68 buffer
->next
= cg
->cups_buffers
;
70 cg
->cups_buffers
= buffer
;
80 * '_cupsBufferRelease()' - Release a read/write buffer.
84 _cupsBufferRelease(char *b
) /* I - Buffer to release */
86 _cups_buffer_t
*buffer
; /* Buffer */
90 * Mark this buffer as unused...
93 buffer
= (_cups_buffer_t
*)(b
- offsetof(_cups_buffer_t
, d
));
99 * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
101 * The @code ipp@ parameter refers to an IPP message previously created using
102 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
104 * The @code group@ parameter specifies the IPP attribute group tag: none
105 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
106 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
107 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
108 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
111 ipp_attribute_t
* /* O - New attribute */
112 ippAddBoolean(ipp_t
*ipp
, /* I - IPP message */
113 ipp_tag_t group
, /* I - IPP group */
114 const char *name
, /* I - Name of attribute */
115 char value
) /* I - Value of attribute */
117 ipp_attribute_t
*attr
; /* New attribute */
120 DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)", (void *)ipp
, group
, ippTagString(group
), name
, value
));
123 * Range check input...
126 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
127 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
131 * Create the attribute...
134 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, 1)) == NULL
)
137 attr
->values
[0].boolean
= value
;
144 * 'ippAddBooleans()' - Add an array of boolean values.
146 * The @code ipp@ parameter refers to an IPP message previously created using
147 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
149 * The @code group@ parameter specifies the IPP attribute group tag: none
150 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
151 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
152 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
153 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
156 ipp_attribute_t
* /* O - New attribute */
157 ippAddBooleans(ipp_t
*ipp
, /* I - IPP message */
158 ipp_tag_t group
, /* I - IPP group */
159 const char *name
, /* I - Name of attribute */
160 int num_values
, /* I - Number of values */
161 const char *values
) /* I - Values */
163 int i
; /* Looping var */
164 ipp_attribute_t
*attr
; /* New attribute */
165 _ipp_value_t
*value
; /* Current value */
168 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
));
171 * Range check input...
174 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
175 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
180 * Create the attribute...
183 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, num_values
)) == NULL
)
188 for (i
= num_values
, value
= attr
->values
;
191 value
->boolean
= *values
++;
199 * 'ippAddCollection()' - Add a collection value.
201 * The @code ipp@ parameter refers to an IPP message previously created using
202 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
204 * The @code group@ parameter specifies the IPP attribute group tag: none
205 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
206 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
207 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
208 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
210 * @since CUPS 1.1.19/macOS 10.3@
213 ipp_attribute_t
* /* O - New attribute */
214 ippAddCollection(ipp_t
*ipp
, /* I - IPP message */
215 ipp_tag_t group
, /* I - IPP group */
216 const char *name
, /* I - Name of attribute */
217 ipp_t
*value
) /* I - Value */
219 ipp_attribute_t
*attr
; /* New attribute */
222 DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
225 * Range check input...
228 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
229 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
233 * Create the attribute...
236 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
, 1)) == NULL
)
239 attr
->values
[0].collection
= value
;
249 * 'ippAddCollections()' - Add an array of collection values.
251 * The @code ipp@ parameter refers to an IPP message previously created using
252 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
254 * The @code group@ parameter specifies the IPP attribute group tag: none
255 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
256 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
257 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
258 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
260 * @since CUPS 1.1.19/macOS 10.3@
263 ipp_attribute_t
* /* O - New attribute */
265 ipp_t
*ipp
, /* I - IPP message */
266 ipp_tag_t group
, /* I - IPP group */
267 const char *name
, /* I - Name of attribute */
268 int num_values
, /* I - Number of values */
269 const ipp_t
**values
) /* I - Values */
271 int i
; /* Looping var */
272 ipp_attribute_t
*attr
; /* New attribute */
273 _ipp_value_t
*value
; /* Current value */
276 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
));
279 * Range check input...
282 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
283 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
288 * Create the attribute...
291 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
,
292 num_values
)) == NULL
)
297 for (i
= num_values
, value
= attr
->values
;
301 value
->collection
= (ipp_t
*)*values
++;
302 value
->collection
->use
++;
311 * 'ippAddDate()' - Add a dateTime attribute to an IPP message.
313 * The @code ipp@ parameter refers to an IPP message previously created using
314 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
316 * The @code group@ parameter specifies the IPP attribute group tag: none
317 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
318 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
319 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
320 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
323 ipp_attribute_t
* /* O - New attribute */
324 ippAddDate(ipp_t
*ipp
, /* I - IPP message */
325 ipp_tag_t group
, /* I - IPP group */
326 const char *name
, /* I - Name of attribute */
327 const ipp_uchar_t
*value
) /* I - Value */
329 ipp_attribute_t
*attr
; /* New attribute */
332 DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
335 * Range check input...
338 if (!ipp
|| !name
|| !value
|| group
< IPP_TAG_ZERO
||
339 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
343 * Create the attribute...
346 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_DATE
, 1)) == NULL
)
349 memcpy(attr
->values
[0].date
, value
, 11);
356 * 'ippAddInteger()' - Add a integer attribute to an IPP message.
358 * The @code ipp@ parameter refers to an IPP message previously created using
359 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
361 * The @code group@ parameter specifies the IPP attribute group tag: none
362 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
363 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
364 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
365 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
367 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
368 * (@code IPP_TAG_INTEGER@).
371 ipp_attribute_t
* /* O - New attribute */
372 ippAddInteger(ipp_t
*ipp
, /* I - IPP message */
373 ipp_tag_t group
, /* I - IPP group */
374 ipp_tag_t value_tag
, /* I - Type of attribute */
375 const char *name
, /* I - Name of attribute */
376 int value
) /* I - Value of attribute */
378 ipp_attribute_t
*attr
; /* New attribute */
381 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
));
383 value_tag
&= IPP_TAG_CUPS_MASK
;
386 * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
390 if (value_tag
>= IPP_TAG_UNSUPPORTED_VALUE
&& value_tag
<= IPP_TAG_ADMINDEFINE
)
391 return (ippAddOutOfBand(ipp
, group
, value_tag
, name
));
394 * Range check input...
398 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
399 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
400 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
))
403 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
404 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
409 * Create the attribute...
412 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
415 attr
->values
[0].integer
= value
;
422 * 'ippAddIntegers()' - Add an array of integer values.
424 * The @code ipp@ parameter refers to an IPP message previously created using
425 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
427 * The @code group@ parameter specifies the IPP attribute group tag: none
428 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
429 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
430 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
431 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
433 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
434 * (@code IPP_TAG_INTEGER@).
437 ipp_attribute_t
* /* O - New attribute */
438 ippAddIntegers(ipp_t
*ipp
, /* I - IPP message */
439 ipp_tag_t group
, /* I - IPP group */
440 ipp_tag_t value_tag
, /* I - Type of attribute */
441 const char *name
, /* I - Name of attribute */
442 int num_values
, /* I - Number of values */
443 const int *values
) /* I - Values */
445 int i
; /* Looping var */
446 ipp_attribute_t
*attr
; /* New attribute */
447 _ipp_value_t
*value
; /* Current value */
450 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
));
452 value_tag
&= IPP_TAG_CUPS_MASK
;
455 * Range check input...
459 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
460 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
461 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
) ||
465 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
466 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
472 * Create the attribute...
475 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
480 for (i
= num_values
, value
= attr
->values
;
483 value
->integer
= *values
++;
491 * 'ippAddOctetString()' - Add an octetString value to an IPP message.
493 * The @code ipp@ parameter refers to an IPP message previously created using
494 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
496 * The @code group@ parameter specifies the IPP attribute group tag: none
497 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
498 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
499 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
500 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
502 * @since CUPS 1.2/macOS 10.5@
505 ipp_attribute_t
* /* O - New attribute */
506 ippAddOctetString(ipp_t
*ipp
, /* I - IPP message */
507 ipp_tag_t group
, /* I - IPP group */
508 const char *name
, /* I - Name of attribute */
509 const void *data
, /* I - octetString data */
510 int datalen
) /* I - Length of data in bytes */
512 ipp_attribute_t
*attr
; /* New attribute */
515 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
516 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
517 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
520 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_STRING
, 1)) == NULL
)
524 * Initialize the attribute data...
527 attr
->values
[0].unknown
.length
= datalen
;
531 if ((attr
->values
[0].unknown
.data
= malloc((size_t)datalen
)) == NULL
)
533 ippDeleteAttribute(ipp
, attr
);
537 memcpy(attr
->values
[0].unknown
.data
, data
, (size_t)datalen
);
541 * Return the new attribute...
549 * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
551 * The @code ipp@ parameter refers to an IPP message previously created using
552 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
554 * The @code group@ parameter specifies the IPP attribute group tag: none
555 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
556 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
557 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
558 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
560 * Supported out-of-band values include unsupported-value
561 * (@code IPP_TAG_UNSUPPORTED_VALUE@), default (@code IPP_TAG_DEFAULT@), unknown
562 * (@code IPP_TAG_UNKNOWN@), no-value (@code IPP_TAG_NOVALUE@), not-settable
563 * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
564 * admin-define (@code IPP_TAG_ADMINDEFINE@).
566 * @since CUPS 1.6/macOS 10.8@
569 ipp_attribute_t
* /* O - New attribute */
570 ippAddOutOfBand(ipp_t
*ipp
, /* I - IPP message */
571 ipp_tag_t group
, /* I - IPP group */
572 ipp_tag_t value_tag
, /* I - Type of attribute */
573 const char *name
) /* I - Name of attribute */
575 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
));
577 value_tag
&= IPP_TAG_CUPS_MASK
;
580 * Range check input...
583 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
584 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
585 (value_tag
!= IPP_TAG_UNSUPPORTED_VALUE
&&
586 value_tag
!= IPP_TAG_DEFAULT
&&
587 value_tag
!= IPP_TAG_UNKNOWN
&&
588 value_tag
!= IPP_TAG_NOVALUE
&&
589 value_tag
!= IPP_TAG_NOTSETTABLE
&&
590 value_tag
!= IPP_TAG_DELETEATTR
&&
591 value_tag
!= IPP_TAG_ADMINDEFINE
))
595 * Create the attribute...
598 return (ipp_add_attr(ipp
, name
, group
, value_tag
, 1));
603 * 'ippAddRange()' - Add a range of values to an IPP message.
605 * The @code ipp@ parameter refers to an IPP message previously created using
606 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
608 * The @code group@ parameter specifies the IPP attribute group tag: none
609 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
610 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
611 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
612 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
614 * The @code lower@ parameter must be less than or equal to the @code upper@ parameter.
617 ipp_attribute_t
* /* O - New attribute */
618 ippAddRange(ipp_t
*ipp
, /* I - IPP message */
619 ipp_tag_t group
, /* I - IPP group */
620 const char *name
, /* I - Name of attribute */
621 int lower
, /* I - Lower value */
622 int upper
) /* I - Upper value */
624 ipp_attribute_t
*attr
; /* New attribute */
627 DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, upper=%d)", (void *)ipp
, group
, ippTagString(group
), name
, lower
, upper
));
630 * Range check input...
633 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
634 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
638 * Create the attribute...
641 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, 1)) == NULL
)
644 attr
->values
[0].range
.lower
= lower
;
645 attr
->values
[0].range
.upper
= upper
;
652 * 'ippAddRanges()' - Add ranges of values to an IPP message.
654 * The @code ipp@ parameter refers to an IPP message previously created using
655 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
657 * The @code group@ parameter specifies the IPP attribute group tag: none
658 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
659 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
660 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
661 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
664 ipp_attribute_t
* /* O - New attribute */
665 ippAddRanges(ipp_t
*ipp
, /* I - IPP message */
666 ipp_tag_t group
, /* I - IPP group */
667 const char *name
, /* I - Name of attribute */
668 int num_values
, /* I - Number of values */
669 const int *lower
, /* I - Lower values */
670 const int *upper
) /* I - Upper values */
672 int i
; /* Looping var */
673 ipp_attribute_t
*attr
; /* New attribute */
674 _ipp_value_t
*value
; /* Current value */
677 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
));
680 * Range check input...
683 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
684 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
689 * Create the attribute...
692 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, num_values
)) == NULL
)
697 for (i
= num_values
, value
= attr
->values
;
701 value
->range
.lower
= *lower
++;
702 value
->range
.upper
= *upper
++;
711 * 'ippAddResolution()' - Add a resolution value to an IPP message.
713 * The @code ipp@ parameter refers to an IPP message previously created using
714 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
716 * The @code group@ parameter specifies the IPP attribute group tag: none
717 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
718 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
719 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
720 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
723 ipp_attribute_t
* /* O - New attribute */
724 ippAddResolution(ipp_t
*ipp
, /* I - IPP message */
725 ipp_tag_t group
, /* I - IPP group */
726 const char *name
, /* I - Name of attribute */
727 ipp_res_t units
, /* I - Units for resolution */
728 int xres
, /* I - X resolution */
729 int yres
) /* I - Y resolution */
731 ipp_attribute_t
*attr
; /* New attribute */
734 DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", units=%d, xres=%d, yres=%d)", (void *)ipp
, group
,
735 ippTagString(group
), name
, units
, xres
, yres
));
738 * Range check input...
741 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
742 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
743 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
||
744 xres
< 0 || yres
< 0)
748 * Create the attribute...
751 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, 1)) == NULL
)
754 attr
->values
[0].resolution
.xres
= xres
;
755 attr
->values
[0].resolution
.yres
= yres
;
756 attr
->values
[0].resolution
.units
= units
;
763 * 'ippAddResolutions()' - Add resolution values to an IPP message.
765 * The @code ipp@ parameter refers to an IPP message previously created using
766 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
768 * The @code group@ parameter specifies the IPP attribute group tag: none
769 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
770 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
771 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
772 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
775 ipp_attribute_t
* /* O - New attribute */
776 ippAddResolutions(ipp_t
*ipp
, /* I - IPP message */
777 ipp_tag_t group
, /* I - IPP group */
778 const char *name
, /* I - Name of attribute */
779 int num_values
,/* I - Number of values */
780 ipp_res_t units
, /* I - Units for resolution */
781 const int *xres
, /* I - X resolutions */
782 const int *yres
) /* I - Y resolutions */
784 int i
; /* Looping var */
785 ipp_attribute_t
*attr
; /* New attribute */
786 _ipp_value_t
*value
; /* Current value */
789 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
));
792 * Range check input...
795 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
796 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
798 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
)
802 * Create the attribute...
805 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, num_values
)) == NULL
)
810 for (i
= num_values
, value
= attr
->values
;
814 value
->resolution
.xres
= *xres
++;
815 value
->resolution
.yres
= *yres
++;
816 value
->resolution
.units
= units
;
825 * 'ippAddSeparator()' - Add a group separator to an IPP message.
827 * The @code ipp@ parameter refers to an IPP message previously created using
828 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
831 ipp_attribute_t
* /* O - New attribute */
832 ippAddSeparator(ipp_t
*ipp
) /* I - IPP message */
834 DEBUG_printf(("ippAddSeparator(ipp=%p)", (void *)ipp
));
837 * Range check input...
844 * Create the attribute...
847 return (ipp_add_attr(ipp
, NULL
, IPP_TAG_ZERO
, IPP_TAG_ZERO
, 0));
852 * 'ippAddString()' - Add a language-encoded string to an IPP message.
854 * The @code ipp@ parameter refers to an IPP message previously created using
855 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
857 * The @code group@ parameter specifies the IPP attribute group tag: none
858 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
859 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
860 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
861 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
863 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
864 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
865 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
866 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
867 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
868 * (@code IPP_TAG_URISCHEME@).
870 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
871 * textWithLanguage string values and must be @code NULL@ for all other string values.
874 ipp_attribute_t
* /* O - New attribute */
875 ippAddString(ipp_t
*ipp
, /* I - IPP message */
876 ipp_tag_t group
, /* I - IPP group */
877 ipp_tag_t value_tag
, /* I - Type of attribute */
878 const char *name
, /* I - Name of attribute */
879 const char *language
, /* I - Language code */
880 const char *value
) /* I - Value */
882 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
883 ipp_attribute_t
*attr
; /* New attribute */
884 char code
[IPP_MAX_LANGUAGE
];
885 /* Charset/language code buffer */
888 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
));
891 * Range check input...
894 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
897 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
898 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
899 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
900 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
)
903 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
904 != (language
!= NULL
))
907 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
908 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
913 * See if we need to map charset, language, or locale values...
916 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
917 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
918 value_tag
= temp_tag
; /* Don't do a fast copy */
919 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
) &&
920 strcmp(value
, ipp_get_code(value
, 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_LANGUAGE
| IPP_TAG_CUPS_CONST
) &&
923 strcmp(value
, ipp_lang_code(value
, code
, sizeof(code
))))
924 value_tag
= temp_tag
; /* Don't do a fast copy */
927 * Create the attribute...
930 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
934 * Initialize the attribute data...
937 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
939 attr
->values
[0].string
.language
= (char *)language
;
940 attr
->values
[0].string
.text
= (char *)value
;
945 attr
->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
950 if (value_tag
== IPP_TAG_CHARSET
)
951 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_get_code(value
, code
,
953 else if (value_tag
== IPP_TAG_LANGUAGE
)
954 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_lang_code(value
, code
,
957 attr
->values
[0].string
.text
= _cupsStrAlloc(value
);
966 * 'ippAddStringf()' - Add a formatted string to an IPP message.
968 * The @code ipp@ parameter refers to an IPP message previously created using
969 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
971 * The @code group@ parameter specifies the IPP attribute group tag: none
972 * (@code IPP_TAG_ZERO@, for member attributes), document
973 * (@code IPP_TAG_DOCUMENT@), event notification
974 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
975 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
976 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
978 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
979 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
980 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
981 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
982 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
983 * (@code IPP_TAG_URISCHEME@).
985 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
986 * and textWithLanguage string values and must be @code NULL@ for all other
989 * The @code format@ parameter uses formatting characters compatible with the
990 * printf family of standard functions. Additional arguments follow it as
991 * needed. The formatted string is truncated as needed to the maximum length of
992 * the corresponding value type.
994 * @since CUPS 1.7/macOS 10.9@
997 ipp_attribute_t
* /* O - New attribute */
998 ippAddStringf(ipp_t
*ipp
, /* I - IPP message */
999 ipp_tag_t group
, /* I - IPP group */
1000 ipp_tag_t value_tag
, /* I - Type of attribute */
1001 const char *name
, /* I - Name of attribute */
1002 const char *language
, /* I - Language code (@code NULL@ for default) */
1003 const char *format
, /* I - Printf-style format string */
1004 ...) /* I - Additional arguments as needed */
1006 ipp_attribute_t
*attr
; /* New attribute */
1007 va_list ap
; /* Argument pointer */
1010 va_start(ap
, format
);
1011 attr
= ippAddStringfv(ipp
, group
, value_tag
, name
, language
, format
, ap
);
1019 * 'ippAddStringfv()' - Add a formatted string to an IPP message.
1021 * The @code ipp@ parameter refers to an IPP message previously created using
1022 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1024 * The @code group@ parameter specifies the IPP attribute group tag: none
1025 * (@code IPP_TAG_ZERO@, for member attributes), document
1026 * (@code IPP_TAG_DOCUMENT@), event notification
1027 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1028 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1029 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1031 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1032 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1033 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1034 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1035 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1036 * (@code IPP_TAG_URISCHEME@).
1038 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1039 * and textWithLanguage string values and must be @code NULL@ for all other
1042 * The @code format@ parameter uses formatting characters compatible with the
1043 * printf family of standard functions. Additional arguments are passed in the
1044 * stdarg pointer @code ap@. The formatted string is truncated as needed to the
1045 * maximum length of the corresponding value type.
1047 * @since CUPS 1.7/macOS 10.9@
1050 ipp_attribute_t
* /* O - New attribute */
1051 ippAddStringfv(ipp_t
*ipp
, /* I - IPP message */
1052 ipp_tag_t group
, /* I - IPP group */
1053 ipp_tag_t value_tag
, /* I - Type of attribute */
1054 const char *name
, /* I - Name of attribute */
1055 const char *language
, /* I - Language code (@code NULL@ for default) */
1056 const char *format
, /* I - Printf-style format string */
1057 va_list ap
) /* I - Additional arguments */
1059 char buffer
[IPP_MAX_TEXT
+ 4];
1060 /* Formatted text string */
1061 ssize_t bytes
, /* Length of formatted value */
1062 max_bytes
; /* Maximum number of bytes for value */
1066 * Range check input...
1069 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1070 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1071 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
1072 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
1076 if ((value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_NAMELANG
)
1077 != (language
!= NULL
))
1081 * Format the string...
1084 if (!strcmp(format
, "%s"))
1087 * Optimize the simple case...
1090 const char *s
= va_arg(ap
, char *);
1095 bytes
= (ssize_t
)strlen(s
);
1096 strlcpy(buffer
, s
, sizeof(buffer
));
1101 * Do a full formatting of the message...
1104 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
1109 * Limit the length of the string...
1116 case IPP_TAG_TEXTLANG
:
1117 max_bytes
= IPP_MAX_TEXT
;
1121 case IPP_TAG_NAMELANG
:
1122 max_bytes
= IPP_MAX_NAME
;
1125 case IPP_TAG_CHARSET
:
1126 max_bytes
= IPP_MAX_CHARSET
;
1129 case IPP_TAG_KEYWORD
:
1130 max_bytes
= IPP_MAX_KEYWORD
;
1133 case IPP_TAG_LANGUAGE
:
1134 max_bytes
= IPP_MAX_LANGUAGE
;
1137 case IPP_TAG_MIMETYPE
:
1138 max_bytes
= IPP_MAX_MIMETYPE
;
1142 max_bytes
= IPP_MAX_URI
;
1145 case IPP_TAG_URISCHEME
:
1146 max_bytes
= IPP_MAX_URISCHEME
;
1150 if (bytes
>= max_bytes
)
1152 char *bufmax
, /* Buffer at max_bytes */
1153 *bufptr
; /* Pointer into buffer */
1155 bufptr
= buffer
+ strlen(buffer
) - 1;
1156 bufmax
= buffer
+ max_bytes
- 1;
1158 while (bufptr
> bufmax
)
1162 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
1173 * Add the formatted string and return...
1176 return (ippAddString(ipp
, group
, value_tag
, name
, language
, buffer
));
1181 * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
1183 * The @code ipp@ parameter refers to an IPP message previously created using
1184 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1186 * The @code group@ parameter specifies the IPP attribute group tag: none
1187 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
1188 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
1189 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
1190 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1192 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1193 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1194 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1195 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1196 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1197 * (@code IPP_TAG_URISCHEME@).
1199 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1200 * textWithLanguage string values and must be @code NULL@ for all other string values.
1203 ipp_attribute_t
* /* O - New attribute */
1205 ipp_t
*ipp
, /* I - IPP message */
1206 ipp_tag_t group
, /* I - IPP group */
1207 ipp_tag_t value_tag
, /* I - Type of attribute */
1208 const char *name
, /* I - Name of attribute */
1209 int num_values
, /* I - Number of values */
1210 const char *language
, /* I - Language code (@code NULL@ for default) */
1211 const char * const *values
) /* I - Values */
1213 int i
; /* Looping var */
1214 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1215 ipp_attribute_t
*attr
; /* New attribute */
1216 _ipp_value_t
*value
; /* Current value */
1217 char code
[32]; /* Language/charset value buffer */
1220 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
));
1223 * Range check input...
1226 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
1229 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1230 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1231 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1232 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
||
1236 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1237 != (language
!= NULL
))
1240 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1241 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1247 * See if we need to map charset, language, or locale values...
1250 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
1251 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1252 value_tag
= temp_tag
; /* Don't do a fast copy */
1253 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
))
1255 for (i
= 0; i
< num_values
; i
++)
1256 if (strcmp(values
[i
], ipp_get_code(values
[i
], code
, sizeof(code
))))
1258 value_tag
= temp_tag
; /* Don't do a fast copy */
1262 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
))
1264 for (i
= 0; i
< num_values
; i
++)
1265 if (strcmp(values
[i
], ipp_lang_code(values
[i
], code
, sizeof(code
))))
1267 value_tag
= temp_tag
; /* Don't do a fast copy */
1273 * Create the attribute...
1276 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
1280 * Initialize the attribute data...
1283 for (i
= num_values
, value
= attr
->values
;
1289 if (value
== attr
->values
)
1291 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1292 value
->string
.language
= (char *)language
;
1294 value
->string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1298 value
->string
.language
= attr
->values
[0].string
.language
;
1303 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1304 value
->string
.text
= (char *)*values
++;
1305 else if (value_tag
== IPP_TAG_CHARSET
)
1306 value
->string
.text
= _cupsStrAlloc(ipp_get_code(*values
++, code
, sizeof(code
)));
1307 else if (value_tag
== IPP_TAG_LANGUAGE
)
1308 value
->string
.text
= _cupsStrAlloc(ipp_lang_code(*values
++, code
, sizeof(code
)));
1310 value
->string
.text
= _cupsStrAlloc(*values
++);
1319 * 'ippContainsInteger()' - Determine whether an attribute contains the
1320 * specified value or is within the list of ranges.
1322 * Returns non-zero when the attribute contains either a matching integer or
1323 * enum value, or the value falls within one of the rangeOfInteger values for
1326 * @since CUPS 1.7/macOS 10.9@
1329 int /* O - 1 on a match, 0 on no match */
1331 ipp_attribute_t
*attr
, /* I - Attribute */
1332 int value
) /* I - Integer/enum value */
1334 int i
; /* Looping var */
1335 _ipp_value_t
*avalue
; /* Current attribute value */
1339 * Range check input...
1345 if (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
&&
1346 attr
->value_tag
!= IPP_TAG_RANGE
)
1353 if (attr
->value_tag
== IPP_TAG_RANGE
)
1355 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1356 if (value
>= avalue
->range
.lower
&& value
<= avalue
->range
.upper
)
1361 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1362 if (value
== avalue
->integer
)
1371 * 'ippContainsString()' - Determine whether an attribute contains the
1372 * specified string value.
1374 * Returns non-zero when the attribute contains a matching charset, keyword,
1375 * naturalLanguage, mimeMediaType, name, text, uri, or uriScheme value.
1377 * @since CUPS 1.7/macOS 10.9@
1380 int /* O - 1 on a match, 0 on no match */
1382 ipp_attribute_t
*attr
, /* I - Attribute */
1383 const char *value
) /* I - String value */
1385 int i
; /* Looping var */
1386 _ipp_value_t
*avalue
; /* Current attribute value */
1389 DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", (void *)attr
, value
));
1392 * Range check input...
1395 if (!attr
|| !value
)
1397 DEBUG_puts("1ippContainsString: Returning 0 (bad input)");
1405 DEBUG_printf(("1ippContainsString: attr %s, %s with %d values.",
1406 attr
->name
, ippTagString(attr
->value_tag
),
1409 switch (attr
->value_tag
& IPP_TAG_CUPS_MASK
)
1411 case IPP_TAG_CHARSET
:
1412 case IPP_TAG_KEYWORD
:
1413 case IPP_TAG_LANGUAGE
:
1415 case IPP_TAG_URISCHEME
:
1416 for (i
= attr
->num_values
, avalue
= attr
->values
;
1420 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1421 attr
->num_values
- i
, avalue
->string
.text
));
1423 if (!strcmp(value
, avalue
->string
.text
))
1425 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1430 case IPP_TAG_MIMETYPE
:
1432 case IPP_TAG_NAMELANG
:
1434 case IPP_TAG_TEXTLANG
:
1435 for (i
= attr
->num_values
, avalue
= attr
->values
;
1439 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1440 attr
->num_values
- i
, avalue
->string
.text
));
1442 if (!_cups_strcasecmp(value
, avalue
->string
.text
))
1444 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1453 DEBUG_puts("1ippContainsString: Returning 0 (no match)");
1460 * 'ippCopyAttribute()' - Copy an attribute.
1462 * The specified attribute, @code attr@, is copied to the destination IPP message.
1463 * When @code quickcopy@ is non-zero, a "shallow" reference copy of the attribute is
1464 * created - this should only be done as long as the original source IPP message will
1465 * not be freed for the life of the destination.
1467 * @since CUPS 1.6/macOS 10.8@
1471 ipp_attribute_t
* /* O - New attribute */
1473 ipp_t
*dst
, /* I - Destination IPP message */
1474 ipp_attribute_t
*srcattr
, /* I - Attribute to copy */
1475 int quickcopy
) /* I - 1 for a referenced copy, 0 for normal */
1477 int i
; /* Looping var */
1478 ipp_tag_t srctag
; /* Source value tag */
1479 ipp_attribute_t
*dstattr
; /* Destination attribute */
1480 _ipp_value_t
*srcval
, /* Source value */
1481 *dstval
; /* Destination value */
1484 DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", (void *)dst
, (void *)srcattr
, quickcopy
));
1487 * Range check input...
1490 if (!dst
|| !srcattr
)
1497 quickcopy
= (quickcopy
&& (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)) ? IPP_TAG_CUPS_CONST
: 0;
1498 srctag
= srcattr
->value_tag
& IPP_TAG_CUPS_MASK
;
1503 dstattr
= ippAddSeparator(dst
);
1506 case IPP_TAG_UNSUPPORTED_VALUE
:
1507 case IPP_TAG_DEFAULT
:
1508 case IPP_TAG_UNKNOWN
:
1509 case IPP_TAG_NOVALUE
:
1510 case IPP_TAG_NOTSETTABLE
:
1511 case IPP_TAG_DELETEATTR
:
1512 case IPP_TAG_ADMINDEFINE
:
1513 dstattr
= ippAddOutOfBand(dst
, srcattr
->group_tag
, srctag
, srcattr
->name
);
1516 case IPP_TAG_INTEGER
:
1518 case IPP_TAG_BOOLEAN
:
1520 case IPP_TAG_RESOLUTION
:
1521 case IPP_TAG_RANGE
:
1522 if ((dstattr
= ipp_add_attr(dst
, srcattr
->name
, srcattr
->group_tag
, srctag
, srcattr
->num_values
)) != NULL
)
1523 memcpy(dstattr
->values
, srcattr
->values
, (size_t)srcattr
->num_values
* sizeof(_ipp_value_t
));
1528 case IPP_TAG_RESERVED_STRING
:
1529 case IPP_TAG_KEYWORD
:
1531 case IPP_TAG_URISCHEME
:
1532 case IPP_TAG_CHARSET
:
1533 case IPP_TAG_LANGUAGE
:
1534 case IPP_TAG_MIMETYPE
:
1535 if ((dstattr
= ippAddStrings(dst
, srcattr
->group_tag
, (ipp_tag_t
)(srctag
| quickcopy
), srcattr
->name
, srcattr
->num_values
, NULL
, NULL
)) == NULL
)
1541 * Can safely quick-copy these string values...
1544 memcpy(dstattr
->values
, srcattr
->values
, (size_t)srcattr
->num_values
* sizeof(_ipp_value_t
));
1549 * Otherwise do a normal reference counted copy...
1552 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
; i
> 0; i
--, srcval
++, dstval
++)
1553 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1557 case IPP_TAG_TEXTLANG
:
1558 case IPP_TAG_NAMELANG
:
1559 if ((dstattr
= ippAddStrings(dst
, srcattr
->group_tag
, (ipp_tag_t
)(srctag
| quickcopy
), srcattr
->name
, srcattr
->num_values
, NULL
, NULL
)) == NULL
)
1565 * Can safely quick-copy these string values...
1568 memcpy(dstattr
->values
, srcattr
->values
, (size_t)srcattr
->num_values
* sizeof(_ipp_value_t
));
1570 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1573 * Otherwise do a normal reference counted copy...
1576 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
; i
> 0; i
--, srcval
++, dstval
++)
1578 if (srcval
== srcattr
->values
)
1579 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1581 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1583 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1588 case IPP_TAG_BEGIN_COLLECTION
:
1589 if ((dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
, srcattr
->num_values
, NULL
)) == NULL
)
1592 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
; i
> 0; i
--, srcval
++, dstval
++)
1594 dstval
->collection
= srcval
->collection
;
1595 srcval
->collection
->use
++;
1599 case IPP_TAG_STRING
:
1601 if ((dstattr
= ipp_add_attr(dst
, srcattr
->name
, srcattr
->group_tag
, srctag
, srcattr
->num_values
)) == NULL
)
1604 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
; i
> 0; i
--, srcval
++, dstval
++)
1606 dstval
->unknown
.length
= srcval
->unknown
.length
;
1608 if (dstval
->unknown
.length
> 0)
1610 if ((dstval
->unknown
.data
= malloc((size_t)dstval
->unknown
.length
)) == NULL
)
1611 dstval
->unknown
.length
= 0;
1613 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, (size_t)dstval
->unknown
.length
);
1616 break; /* anti-compiler-warning-code */
1624 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1626 * Zero or more attributes are copied from the source IPP message, @code src@, to the
1627 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1628 * reference copy of the attribute is created - this should only be done as long as the
1629 * original source IPP message will not be freed for the life of the destination.
1631 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1632 * attributes that are copied - the function must return 1 to copy the attribute or
1633 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1636 * @since CUPS 1.6/macOS 10.8@
1639 int /* O - 1 on success, 0 on error */
1641 ipp_t
*dst
, /* I - Destination IPP message */
1642 ipp_t
*src
, /* I - Source IPP message */
1643 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1644 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1645 void *context
) /* I - Context pointer */
1647 ipp_attribute_t
*srcattr
; /* Source attribute */
1650 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)", (void *)dst
, (void *)src
, quickcopy
, (void *)cb
, context
));
1653 * Range check input...
1660 * Loop through source attributes and copy as needed...
1663 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1664 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1665 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1673 * 'ippDateToTime()' - Convert from RFC 2579 Date/Time format to time in
1677 time_t /* O - UNIX time value */
1678 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 2579 date info */
1680 struct tm unixdate
; /* UNIX date/time info */
1681 time_t t
; /* Computed time */
1687 memset(&unixdate
, 0, sizeof(unixdate
));
1690 * RFC-2579 date/time format is:
1692 * Byte(s) Description
1693 * ------- -----------
1694 * 0-1 Year (0 to 65535)
1698 * 5 Minutes (0 to 59)
1699 * 6 Seconds (0 to 60, 60 = "leap second")
1700 * 7 Deciseconds (0 to 9)
1702 * 9 UTC hours (0 to 11)
1703 * 10 UTC minutes (0 to 59)
1706 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1707 unixdate
.tm_mon
= date
[2] - 1;
1708 unixdate
.tm_mday
= date
[3];
1709 unixdate
.tm_hour
= date
[4];
1710 unixdate
.tm_min
= date
[5];
1711 unixdate
.tm_sec
= date
[6];
1713 t
= mktime(&unixdate
);
1716 t
+= date
[9] * 3600 + date
[10] * 60;
1718 t
-= date
[9] * 3600 + date
[10] * 60;
1725 * 'ippDelete()' - Delete an IPP message.
1729 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1731 ipp_attribute_t
*attr
, /* Current attribute */
1732 *next
; /* Next attribute */
1735 DEBUG_printf(("ippDelete(ipp=%p)", (void *)ipp
));
1743 DEBUG_printf(("4debug_retain: %p IPP message (use=%d)", (void *)ipp
, ipp
->use
));
1747 DEBUG_printf(("4debug_free: %p IPP message", (void *)ipp
));
1749 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1753 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
));
1755 ipp_free_values(attr
, 0, attr
->num_values
);
1758 _cupsStrFree(attr
->name
);
1768 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1770 * @since CUPS 1.1.19/macOS 10.3@
1775 ipp_t
*ipp
, /* I - IPP message */
1776 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1778 ipp_attribute_t
*current
, /* Current attribute */
1779 *prev
; /* Previous attribute */
1782 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", (void *)ipp
, (void *)attr
, attr
? attr
->name
: "(null)"));
1785 * Range check input...
1791 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
));
1794 * Find the attribute in the list...
1799 for (current
= ipp
->attrs
, prev
= NULL
;
1801 prev
= current
, current
= current
->next
)
1802 if (current
== attr
)
1805 * Found it, remove the attribute from the list...
1809 prev
->next
= current
->next
;
1811 ipp
->attrs
= current
->next
;
1813 if (current
== ipp
->last
)
1824 * Free memory used by the attribute...
1827 ipp_free_values(attr
, 0, attr
->num_values
);
1830 _cupsStrFree(attr
->name
);
1837 * 'ippDeleteValues()' - Delete values in an attribute.
1839 * The @code element@ parameter specifies the first value to delete, starting at
1840 * 0. It must be less than the number of values returned by @link ippGetCount@.
1842 * The @code attr@ parameter may be modified as a result of setting the value.
1844 * Deleting all values in an attribute deletes the attribute.
1846 * @since CUPS 1.6/macOS 10.8@
1849 int /* O - 1 on success, 0 on failure */
1851 ipp_t
*ipp
, /* I - IPP message */
1852 ipp_attribute_t
**attr
, /* IO - Attribute */
1853 int element
, /* I - Index of first value to delete (0-based) */
1854 int count
) /* I - Number of values to delete */
1857 * Range check input...
1860 if (!ipp
|| !attr
|| !*attr
||
1861 element
< 0 || element
>= (*attr
)->num_values
|| count
<= 0 ||
1862 (element
+ count
) >= (*attr
)->num_values
)
1866 * If we are deleting all values, just delete the attribute entirely.
1869 if (count
== (*attr
)->num_values
)
1871 ippDeleteAttribute(ipp
, *attr
);
1877 * Otherwise free the values in question and return.
1880 ipp_free_values(*attr
, element
, count
);
1887 * 'ippFindAttribute()' - Find a named attribute in a request.
1889 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1890 * of attribute and member names separated by slashes, for example
1891 * "media-col/media-size".
1894 ipp_attribute_t
* /* O - Matching attribute */
1895 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
1896 const char *name
, /* I - Name of attribute */
1897 ipp_tag_t type
) /* I - Type of attribute */
1899 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
1905 * Reset the current pointer...
1908 ipp
->current
= NULL
;
1912 * Search for the attribute...
1915 return (ippFindNextAttribute(ipp
, name
, type
));
1920 * 'ippFindNextAttribute()' - Find the next named attribute in a request.
1922 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1923 * of attribute and member names separated by slashes, for example
1924 * "media-col/media-size".
1927 ipp_attribute_t
* /* O - Matching attribute */
1928 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
1929 const char *name
, /* I - Name of attribute */
1930 ipp_tag_t type
) /* I - Type of attribute */
1932 ipp_attribute_t
*attr
, /* Current atttribute */
1933 *childattr
; /* Child attribute */
1934 ipp_tag_t value_tag
; /* Value tag */
1935 char parent
[1024], /* Parent attribute name */
1936 *child
= NULL
; /* Child attribute name */
1939 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
1944 DEBUG_printf(("3ippFindNextAttribute: atend=%d", ipp
->atend
));
1949 if (strchr(name
, '/'))
1952 * Search for child attribute...
1955 strlcpy(parent
, name
, sizeof(parent
));
1956 if ((child
= strchr(parent
, '/')) == NULL
)
1958 DEBUG_puts("3ippFindNextAttribute: Attribute name too long.");
1964 if (ipp
->current
&& ipp
->current
->name
&& ipp
->current
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&& !strcmp(parent
, ipp
->current
->name
))
1966 while (ipp
->curindex
< ipp
->current
->num_values
)
1968 if ((childattr
= ippFindNextAttribute(ipp
->current
->values
[ipp
->curindex
].collection
, child
, type
)) != NULL
)
1972 if (ipp
->curindex
< ipp
->current
->num_values
&& ipp
->current
->values
[ipp
->curindex
].collection
)
1973 ipp
->current
->values
[ipp
->curindex
].collection
->current
= NULL
;
1976 ipp
->prev
= ipp
->current
;
1977 ipp
->current
= ipp
->current
->next
;
1990 ipp
->current
= ipp
->attrs
;
1995 attr
= ipp
->current
;
1997 else if (ipp
->current
)
1999 ipp
->prev
= ipp
->current
;
2000 attr
= ipp
->current
->next
;
2008 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
2010 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", (void *)attr
, attr
->name
));
2012 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2014 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
2015 (value_tag
== type
|| type
== IPP_TAG_ZERO
|| name
== parent
||
2016 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
2017 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
2019 ipp
->current
= attr
;
2021 if (name
== parent
&& attr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
)
2023 int i
; /* Looping var */
2025 for (i
= 0; i
< attr
->num_values
; i
++)
2027 if ((childattr
= ippFindAttribute(attr
->values
[i
].collection
, child
, type
)) != NULL
)
2029 attr
->values
[0].collection
->curindex
= i
;
2039 ipp
->current
= NULL
;
2048 * 'ippFirstAttribute()' - Return the first attribute in the message.
2050 * @since CUPS 1.6/macOS 10.8@
2053 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
2054 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
2057 * Range check input...
2064 * Return the first attribute...
2067 return (ipp
->current
= ipp
->attrs
);
2072 * 'ippGetBoolean()' - Get a boolean value for an attribute.
2074 * The @code element@ parameter specifies which value to get from 0 to
2075 * @code ippGetCount(attr)@ - 1.
2077 * @since CUPS 1.6/macOS 10.8@
2080 int /* O - Boolean value or 0 on error */
2081 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
2082 int element
) /* I - Value number (0-based) */
2085 * Range check input...
2088 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
2089 element
< 0 || element
>= attr
->num_values
)
2093 * Return the value...
2096 return (attr
->values
[element
].boolean
);
2101 * 'ippGetCollection()' - Get a collection value for an attribute.
2103 * The @code element@ parameter specifies which value to get from 0 to
2104 * @code ippGetCount(attr)@ - 1.
2106 * @since CUPS 1.6/macOS 10.8@
2109 ipp_t
* /* O - Collection value or @code NULL@ on error */
2111 ipp_attribute_t
*attr
, /* I - IPP attribute */
2112 int element
) /* I - Value number (0-based) */
2115 * Range check input...
2118 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
2119 element
< 0 || element
>= attr
->num_values
)
2123 * Return the value...
2126 return (attr
->values
[element
].collection
);
2131 * 'ippGetCount()' - Get the number of values in an attribute.
2133 * @since CUPS 1.6/macOS 10.8@
2136 int /* O - Number of values or 0 on error */
2137 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
2140 * Range check input...
2147 * Return the number of values...
2150 return (attr
->num_values
);
2155 * 'ippGetDate()' - Get a dateTime value for an attribute.
2157 * The @code element@ parameter specifies which value to get from 0 to
2158 * @code ippGetCount(attr)@ - 1.
2160 * @since CUPS 1.6/macOS 10.8@
2163 const ipp_uchar_t
* /* O - dateTime value or @code NULL@ */
2164 ippGetDate(ipp_attribute_t
*attr
, /* I - IPP attribute */
2165 int element
) /* I - Value number (0-based) */
2168 * Range check input...
2171 if (!attr
|| attr
->value_tag
!= IPP_TAG_DATE
||
2172 element
< 0 || element
>= attr
->num_values
)
2176 * Return the value...
2179 return (attr
->values
[element
].date
);
2184 * 'ippGetGroupTag()' - Get the group associated with an attribute.
2186 * @since CUPS 1.6/macOS 10.8@
2189 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
2190 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2193 * Range check input...
2197 return (IPP_TAG_ZERO
);
2200 * Return the group...
2203 return (attr
->group_tag
);
2208 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
2210 * The @code element@ parameter specifies which value to get from 0 to
2211 * @code ippGetCount(attr)@ - 1.
2213 * @since CUPS 1.6/macOS 10.8@
2216 int /* O - Value or 0 on error */
2217 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
2218 int element
) /* I - Value number (0-based) */
2221 * Range check input...
2224 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
2225 element
< 0 || element
>= attr
->num_values
)
2229 * Return the value...
2232 return (attr
->values
[element
].integer
);
2237 * 'ippGetName()' - Get the attribute name.
2239 * @since CUPS 1.6/macOS 10.8@
2242 const char * /* O - Attribute name or @code NULL@ for separators */
2243 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
2246 * Range check input...
2253 * Return the name...
2256 return (attr
->name
);
2261 * 'ippGetOctetString()' - Get an octetString value from an IPP attribute.
2263 * The @code element@ parameter specifies which value to get from 0 to
2264 * @code ippGetCount(attr)@ - 1.
2266 * @since CUPS 1.7/macOS 10.9@
2269 void * /* O - Pointer to octetString data */
2271 ipp_attribute_t
*attr
, /* I - IPP attribute */
2272 int element
, /* I - Value number (0-based) */
2273 int *datalen
) /* O - Length of octetString data */
2276 * Range check input...
2279 if (!attr
|| attr
->value_tag
!= IPP_TAG_STRING
||
2280 element
< 0 || element
>= attr
->num_values
)
2289 * Return the values...
2293 *datalen
= attr
->values
[element
].unknown
.length
;
2295 return (attr
->values
[element
].unknown
.data
);
2300 * 'ippGetOperation()' - Get the operation ID in an IPP message.
2302 * @since CUPS 1.6/macOS 10.8@
2305 ipp_op_t
/* O - Operation ID or 0 on error */
2306 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
2309 * Range check input...
2313 return ((ipp_op_t
)0);
2316 * Return the value...
2319 return (ipp
->request
.op
.operation_id
);
2324 * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
2326 * The @code element@ parameter specifies which value to get from 0 to
2327 * @code ippGetCount(attr)@ - 1.
2329 * @since CUPS 1.6/macOS 10.8@
2332 int /* O - Lower value of range or 0 */
2333 ippGetRange(ipp_attribute_t
*attr
, /* I - IPP attribute */
2334 int element
, /* I - Value number (0-based) */
2335 int *uppervalue
)/* O - Upper value of range */
2338 * Range check input...
2341 if (!attr
|| attr
->value_tag
!= IPP_TAG_RANGE
||
2342 element
< 0 || element
>= attr
->num_values
)
2351 * Return the values...
2355 *uppervalue
= attr
->values
[element
].range
.upper
;
2357 return (attr
->values
[element
].range
.lower
);
2362 * 'ippGetRequestId()' - Get the request ID from an IPP message.
2364 * @since CUPS 1.6/macOS 10.8@
2367 int /* O - Request ID or 0 on error */
2368 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
2371 * Range check input...
2378 * Return the request ID...
2381 return (ipp
->request
.any
.request_id
);
2386 * 'ippGetResolution()' - Get a resolution value for an attribute.
2388 * The @code element@ parameter specifies which value to get from 0 to
2389 * @code ippGetCount(attr)@ - 1.
2391 * @since CUPS 1.6/macOS 10.8@
2394 int /* O - Horizontal/cross feed resolution or 0 */
2396 ipp_attribute_t
*attr
, /* I - IPP attribute */
2397 int element
, /* I - Value number (0-based) */
2398 int *yres
, /* O - Vertical/feed resolution */
2399 ipp_res_t
*units
) /* O - Units for resolution */
2402 * Range check input...
2405 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
2406 element
< 0 || element
>= attr
->num_values
)
2412 *units
= (ipp_res_t
)0;
2418 * Return the value...
2422 *yres
= attr
->values
[element
].resolution
.yres
;
2425 *units
= attr
->values
[element
].resolution
.units
;
2427 return (attr
->values
[element
].resolution
.xres
);
2432 * 'ippGetState()' - Get the IPP message state.
2434 * @since CUPS 1.6/macOS 10.8@
2437 ipp_state_t
/* O - IPP message state value */
2438 ippGetState(ipp_t
*ipp
) /* I - IPP message */
2441 * Range check input...
2445 return (IPP_STATE_IDLE
);
2448 * Return the value...
2451 return (ipp
->state
);
2456 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2458 * @since CUPS 1.6/macOS 10.8@
2461 ipp_status_t
/* O - Status code in IPP message */
2462 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2465 * Range check input...
2469 return (IPP_STATUS_ERROR_INTERNAL
);
2472 * Return the value...
2475 return (ipp
->request
.status
.status_code
);
2480 * 'ippGetString()' - Get the string and optionally the language code 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@
2489 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2490 int element
, /* I - Value number (0-based) */
2491 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2493 ipp_tag_t tag
; /* Value tag */
2497 * Range check input...
2500 tag
= ippGetValueTag(attr
);
2502 if (!attr
|| element
< 0 || element
>= attr
->num_values
|| (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&& (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
)))
2506 * Return the value...
2510 *language
= attr
->values
[element
].string
.language
;
2512 return (attr
->values
[element
].string
.text
);
2517 * 'ippGetValueTag()' - Get the value tag for an attribute.
2519 * @since CUPS 1.6/macOS 10.8@
2522 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2523 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2526 * Range check input...
2530 return (IPP_TAG_ZERO
);
2533 * Return the value...
2536 return (attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2541 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2543 * @since CUPS 1.6/macOS 10.8@
2546 int /* O - Major version number or 0 on error */
2547 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2548 int *minor
) /* O - Minor version number or @code NULL@ for don't care */
2551 * Range check input...
2563 * Return the value...
2567 *minor
= ipp
->request
.any
.version
[1];
2569 return (ipp
->request
.any
.version
[0]);
2574 * 'ippLength()' - Compute the length of an IPP message.
2577 size_t /* O - Size of IPP message */
2578 ippLength(ipp_t
*ipp
) /* I - IPP message */
2580 return (ipp_length(ipp
, 0));
2585 * 'ippNextAttribute()' - Return the next attribute in the message.
2587 * @since CUPS 1.6/macOS 10.8@
2590 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2591 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2594 * Range check input...
2597 if (!ipp
|| !ipp
->current
)
2601 * Return the next attribute...
2604 return (ipp
->current
= ipp
->current
->next
);
2609 * 'ippNew()' - Allocate a new IPP message.
2612 ipp_t
* /* O - New IPP message */
2615 ipp_t
*temp
; /* New IPP message */
2616 _cups_globals_t
*cg
= _cupsGlobals();
2620 DEBUG_puts("ippNew()");
2622 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2625 * Set default version - usually 2.0...
2628 DEBUG_printf(("4debug_alloc: %p IPP message", (void *)temp
));
2630 if (cg
->server_version
== 0)
2633 temp
->request
.any
.version
[0] = (ipp_uchar_t
)(cg
->server_version
/ 10);
2634 temp
->request
.any
.version
[1] = (ipp_uchar_t
)(cg
->server_version
% 10);
2638 DEBUG_printf(("1ippNew: Returning %p", (void *)temp
));
2645 * 'ippNewRequest()' - Allocate a new IPP request message.
2647 * The new request message is initialized with the "attributes-charset" and
2648 * "attributes-natural-language" attributes added. The
2649 * "attributes-natural-language" value is derived from the current locale.
2651 * @since CUPS 1.2/macOS 10.5@
2654 ipp_t
* /* O - IPP request message */
2655 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2657 ipp_t
*request
; /* IPP request message */
2658 cups_lang_t
*language
; /* Current language localization */
2659 static int request_id
= 0; /* Current request ID */
2660 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2661 /* Mutex for request ID */
2664 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2667 * Create a new IPP message...
2670 if ((request
= ippNew()) == NULL
)
2674 * Set the operation and request ID...
2677 _cupsMutexLock(&request_mutex
);
2679 request
->request
.op
.operation_id
= op
;
2680 request
->request
.op
.request_id
= ++request_id
;
2682 _cupsMutexUnlock(&request_mutex
);
2685 * Use UTF-8 as the character set...
2688 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2689 "attributes-charset", NULL
, "utf-8");
2692 * Get the language from the current locale...
2695 language
= cupsLangDefault();
2697 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2698 "attributes-natural-language", NULL
, language
->language
);
2701 * Return the new request...
2709 * 'ippNewResponse()' - Allocate a new IPP response message.
2711 * The new response message is initialized with the same "version-number",
2712 * "request-id", "attributes-charset", and "attributes-natural-language" as the
2713 * provided request message. If the "attributes-charset" or
2714 * "attributes-natural-language" attributes are missing from the request,
2715 * 'utf-8' and a value derived from the current locale are substituted,
2718 * @since CUPS 1.7/macOS 10.9@
2721 ipp_t
* /* O - IPP response message */
2722 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2724 ipp_t
*response
; /* IPP response message */
2725 ipp_attribute_t
*attr
; /* Current attribute */
2729 * Range check input...
2736 * Create a new IPP message...
2739 if ((response
= ippNew()) == NULL
)
2743 * Copy the request values over to the response...
2746 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2747 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2748 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2751 * The first attribute MUST be attributes-charset...
2754 attr
= request
->attrs
;
2756 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2757 attr
->group_tag
== IPP_TAG_OPERATION
&&
2758 attr
->value_tag
== IPP_TAG_CHARSET
&&
2759 attr
->num_values
== 1)
2762 * Copy charset from request...
2765 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2766 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2771 * Use "utf-8" as the default...
2774 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2775 "attributes-charset", NULL
, "utf-8");
2779 * Then attributes-natural-language...
2785 if (attr
&& attr
->name
&&
2786 !strcmp(attr
->name
, "attributes-natural-language") &&
2787 attr
->group_tag
== IPP_TAG_OPERATION
&&
2788 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2789 attr
->num_values
== 1)
2792 * Copy language from request...
2795 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2796 "attributes-natural-language", NULL
,
2797 attr
->values
[0].string
.text
);
2802 * Use the language from the current locale...
2805 cups_lang_t
*language
= cupsLangDefault();
2806 /* Current locale */
2808 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2809 "attributes-natural-language", NULL
, language
->language
);
2817 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2820 ipp_state_t
/* O - Current state */
2821 ippRead(http_t
*http
, /* I - HTTP connection */
2822 ipp_t
*ipp
) /* I - IPP data */
2824 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
, (void *)http
, (void *)ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2827 return (IPP_STATE_ERROR
);
2829 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
, http
->used
));
2831 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2837 * 'ippReadFile()' - Read data for an IPP message from a file.
2839 * @since CUPS 1.1.19/macOS 10.3@
2842 ipp_state_t
/* O - Current state */
2843 ippReadFile(int fd
, /* I - HTTP data */
2844 ipp_t
*ipp
) /* I - IPP data */
2846 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
2848 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2853 * 'ippReadIO()' - Read data for an IPP message.
2855 * @since CUPS 1.2/macOS 10.5@
2858 ipp_state_t
/* O - Current state */
2859 ippReadIO(void *src
, /* I - Data source */
2860 ipp_iocb_t cb
, /* I - Read callback function */
2861 int blocking
, /* I - Use blocking IO? */
2862 ipp_t
*parent
, /* I - Parent request, if any */
2863 ipp_t
*ipp
) /* I - IPP data */
2865 int n
; /* Length of data */
2866 unsigned char *buffer
, /* Data buffer */
2867 string
[IPP_MAX_TEXT
],
2868 /* Small string buffer */
2869 *bufptr
; /* Pointer into buffer */
2870 ipp_attribute_t
*attr
; /* Current attribute */
2871 ipp_tag_t tag
; /* Current tag */
2872 ipp_tag_t value_tag
; /* Current value tag */
2873 _ipp_value_t
*value
; /* Current value */
2876 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)src
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
2877 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_STATE_ERROR
));
2880 return (IPP_STATE_ERROR
);
2882 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2884 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2885 return (IPP_STATE_ERROR
);
2890 case IPP_STATE_IDLE
:
2891 ipp
->state
++; /* Avoid common problem... */
2893 case IPP_STATE_HEADER
:
2897 * Get the request header...
2900 if ((*cb
)(src
, buffer
, 8) < 8)
2902 DEBUG_puts("1ippReadIO: Unable to read header.");
2903 _cupsBufferRelease((char *)buffer
);
2904 return (IPP_STATE_ERROR
);
2908 * Then copy the request header over...
2911 ipp
->request
.any
.version
[0] = buffer
[0];
2912 ipp
->request
.any
.version
[1] = buffer
[1];
2913 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
2914 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
2915 buffer
[6]) << 8) | buffer
[7];
2917 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
2918 DEBUG_printf(("2ippReadIO: op_status=%04x",
2919 ipp
->request
.any
.op_status
));
2920 DEBUG_printf(("2ippReadIO: request_id=%d",
2921 ipp
->request
.any
.request_id
));
2924 ipp
->state
= IPP_STATE_ATTRIBUTE
;
2925 ipp
->current
= NULL
;
2926 ipp
->curtag
= IPP_TAG_ZERO
;
2927 ipp
->prev
= ipp
->last
;
2930 * If blocking is disabled, stop here...
2936 case IPP_STATE_ATTRIBUTE
:
2939 if ((*cb
)(src
, buffer
, 1) < 1)
2941 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
2942 _cupsBufferRelease((char *)buffer
);
2943 return (IPP_STATE_ERROR
);
2946 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
2949 * Read this attribute...
2952 tag
= (ipp_tag_t
)buffer
[0];
2953 if (tag
== IPP_TAG_EXTENSION
)
2956 * Read 32-bit "extension" tag...
2959 if ((*cb
)(src
, buffer
, 4) < 1)
2961 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
2962 _cupsBufferRelease((char *)buffer
);
2963 return (IPP_STATE_ERROR
);
2966 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
2967 buffer
[2]) << 8) | buffer
[3]);
2969 if (tag
& IPP_TAG_CUPS_CONST
)
2972 * Fail if the high bit is set in the tag...
2975 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
2976 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
2977 _cupsBufferRelease((char *)buffer
);
2978 return (IPP_STATE_ERROR
);
2982 if (tag
== IPP_TAG_END
)
2985 * No more attributes left...
2988 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
2990 ipp
->state
= IPP_STATE_DATA
;
2993 else if (tag
== IPP_TAG_ZERO
|| (tag
== IPP_TAG_OPERATION
&& ipp
->curtag
!= IPP_TAG_ZERO
))
2995 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Invalid group tag."), 1);
2996 DEBUG_printf(("1ippReadIO: bad tag 0x%02x.", tag
));
2997 _cupsBufferRelease((char *)buffer
);
2998 return (IPP_STATE_ERROR
);
3000 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3003 * Group tag... Set the current group and continue...
3006 if (ipp
->curtag
== tag
)
3007 ipp
->prev
= ippAddSeparator(ipp
);
3008 else if (ipp
->current
)
3009 ipp
->prev
= ipp
->current
;
3012 ipp
->current
= NULL
;
3013 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
, ippTagString(tag
), (void *)ipp
->prev
));
3017 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3018 ippTagString(tag
)));
3024 if ((*cb
)(src
, buffer
, 2) < 2)
3026 DEBUG_puts("1ippReadIO: unable to read name length.");
3027 _cupsBufferRelease((char *)buffer
);
3028 return (IPP_STATE_ERROR
);
3031 n
= (buffer
[0] << 8) | buffer
[1];
3033 if (n
>= IPP_BUF_SIZE
)
3035 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3036 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3037 _cupsBufferRelease((char *)buffer
);
3038 return (IPP_STATE_ERROR
);
3041 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3045 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("Invalid named IPP attribute in collection."), 1);
3046 DEBUG_puts("1ippReadIO: bad attribute name in collection.");
3047 return (IPP_STATE_ERROR
);
3049 else if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&& tag
!= IPP_TAG_END_COLLECTION
)
3052 * More values for current attribute...
3055 if (ipp
->current
== NULL
)
3057 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3058 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3059 _cupsBufferRelease((char *)buffer
);
3060 return (IPP_STATE_ERROR
);
3063 attr
= ipp
->current
;
3064 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3067 * Make sure we aren't adding a new value of a different
3071 if (value_tag
== IPP_TAG_ZERO
)
3074 * Setting the value of a collection member...
3077 attr
->value_tag
= tag
;
3079 else if (value_tag
== IPP_TAG_TEXTLANG
||
3080 value_tag
== IPP_TAG_NAMELANG
||
3081 (value_tag
>= IPP_TAG_TEXT
&&
3082 value_tag
<= IPP_TAG_MIMETYPE
))
3085 * String values can sometimes come across in different
3086 * forms; accept sets of differing values...
3089 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3090 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3091 tag
!= IPP_TAG_NOVALUE
)
3093 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3094 _("IPP 1setOf attribute with incompatible value "
3096 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3097 value_tag
, ippTagString(value_tag
), tag
,
3098 ippTagString(tag
)));
3099 _cupsBufferRelease((char *)buffer
);
3100 return (IPP_STATE_ERROR
);
3103 if (value_tag
!= tag
)
3105 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3106 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3107 ippSetValueTag(ipp
, &attr
, tag
);
3110 else if (value_tag
== IPP_TAG_INTEGER
||
3111 value_tag
== IPP_TAG_RANGE
)
3114 * Integer and rangeOfInteger values can sometimes be mixed; accept
3115 * sets of differing values...
3118 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3120 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3121 _("IPP 1setOf attribute with incompatible value "
3123 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3124 value_tag
, ippTagString(value_tag
), tag
,
3125 ippTagString(tag
)));
3126 _cupsBufferRelease((char *)buffer
);
3127 return (IPP_STATE_ERROR
);
3130 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3133 * Convert integer values to rangeOfInteger values...
3136 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3137 "rangeOfInteger.", attr
->name
));
3138 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3141 else if (value_tag
!= tag
)
3143 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3144 _("IPP 1setOf attribute with incompatible value "
3146 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3147 value_tag
, ippTagString(value_tag
), tag
,
3148 ippTagString(tag
)));
3149 _cupsBufferRelease((char *)buffer
);
3150 return (IPP_STATE_ERROR
);
3154 * Finally, reallocate the attribute array as needed...
3157 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3159 _cupsBufferRelease((char *)buffer
);
3160 return (IPP_STATE_ERROR
);
3163 else if (tag
== IPP_TAG_MEMBERNAME
)
3166 * Name must be length 0!
3171 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3172 DEBUG_puts("1ippReadIO: member name not empty.");
3173 _cupsBufferRelease((char *)buffer
);
3174 return (IPP_STATE_ERROR
);
3178 ipp
->prev
= ipp
->current
;
3180 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3183 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3184 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3185 _cupsBufferRelease((char *)buffer
);
3186 return (IPP_STATE_ERROR
);
3189 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3191 value
= attr
->values
;
3193 else if (tag
!= IPP_TAG_END_COLLECTION
)
3196 * New attribute; read the name and add it...
3199 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3201 DEBUG_puts("1ippReadIO: unable to read name.");
3202 _cupsBufferRelease((char *)buffer
);
3203 return (IPP_STATE_ERROR
);
3209 ipp
->prev
= ipp
->current
;
3211 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3214 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3215 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3216 _cupsBufferRelease((char *)buffer
);
3217 return (IPP_STATE_ERROR
);
3220 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer
, (void *)ipp
->current
, (void *)ipp
->prev
));
3222 value
= attr
->values
;
3230 if ((*cb
)(src
, buffer
, 2) < 2)
3232 DEBUG_puts("1ippReadIO: unable to read value length.");
3233 _cupsBufferRelease((char *)buffer
);
3234 return (IPP_STATE_ERROR
);
3237 n
= (buffer
[0] << 8) | buffer
[1];
3238 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3240 if (n
>= IPP_BUF_SIZE
)
3242 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3243 _("IPP value larger than 32767 bytes."), 1);
3244 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3245 _cupsBufferRelease((char *)buffer
);
3246 return (IPP_STATE_ERROR
);
3251 case IPP_TAG_INTEGER
:
3255 if (tag
== IPP_TAG_INTEGER
)
3256 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3257 _("IPP integer value not 4 bytes."), 1);
3259 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3260 _("IPP enum value not 4 bytes."), 1);
3261 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3262 _cupsBufferRelease((char *)buffer
);
3263 return (IPP_STATE_ERROR
);
3266 if ((*cb
)(src
, buffer
, 4) < 4)
3268 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3269 _cupsBufferRelease((char *)buffer
);
3270 return (IPP_STATE_ERROR
);
3273 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3276 if (attr
->value_tag
== IPP_TAG_RANGE
)
3277 value
->range
.lower
= value
->range
.upper
= n
;
3282 case IPP_TAG_BOOLEAN
:
3285 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3287 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3288 _cupsBufferRelease((char *)buffer
);
3289 return (IPP_STATE_ERROR
);
3292 if ((*cb
)(src
, buffer
, 1) < 1)
3294 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3295 _cupsBufferRelease((char *)buffer
);
3296 return (IPP_STATE_ERROR
);
3299 value
->boolean
= (char)buffer
[0];
3302 case IPP_TAG_UNSUPPORTED_VALUE
:
3303 case IPP_TAG_DEFAULT
:
3304 case IPP_TAG_UNKNOWN
:
3305 case IPP_TAG_NOVALUE
:
3306 case IPP_TAG_NOTSETTABLE
:
3307 case IPP_TAG_DELETEATTR
:
3308 case IPP_TAG_ADMINDEFINE
:
3310 * These value types are not supposed to have values, however
3311 * some vendors (Brother) do not implement IPP correctly and so
3312 * we need to map non-empty values to text...
3315 if (attr
->value_tag
== tag
)
3320 attr
->value_tag
= IPP_TAG_TEXT
;
3325 case IPP_TAG_RESERVED_STRING
:
3326 case IPP_TAG_KEYWORD
:
3328 case IPP_TAG_URISCHEME
:
3329 case IPP_TAG_CHARSET
:
3330 case IPP_TAG_LANGUAGE
:
3331 case IPP_TAG_MIMETYPE
:
3334 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3336 DEBUG_puts("1ippReadIO: unable to read string value.");
3337 _cupsBufferRelease((char *)buffer
);
3338 return (IPP_STATE_ERROR
);
3343 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3344 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3350 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3351 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3352 _cupsBufferRelease((char *)buffer
);
3353 return (IPP_STATE_ERROR
);
3356 if ((*cb
)(src
, value
->date
, 11) < 11)
3358 DEBUG_puts("1ippReadIO: Unable to read date value.");
3359 _cupsBufferRelease((char *)buffer
);
3360 return (IPP_STATE_ERROR
);
3364 case IPP_TAG_RESOLUTION
:
3367 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3368 _("IPP resolution value not 9 bytes."), 1);
3369 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3370 _cupsBufferRelease((char *)buffer
);
3371 return (IPP_STATE_ERROR
);
3374 if ((*cb
)(src
, buffer
, 9) < 9)
3376 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3377 _cupsBufferRelease((char *)buffer
);
3378 return (IPP_STATE_ERROR
);
3381 value
->resolution
.xres
=
3382 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3384 value
->resolution
.yres
=
3385 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3387 value
->resolution
.units
=
3388 (ipp_res_t
)buffer
[8];
3391 case IPP_TAG_RANGE
:
3394 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3395 _("IPP rangeOfInteger value not 8 bytes."), 1);
3396 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3398 _cupsBufferRelease((char *)buffer
);
3399 return (IPP_STATE_ERROR
);
3402 if ((*cb
)(src
, buffer
, 8) < 8)
3404 DEBUG_puts("1ippReadIO: Unable to read range value.");
3405 _cupsBufferRelease((char *)buffer
);
3406 return (IPP_STATE_ERROR
);
3409 value
->range
.lower
=
3410 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3412 value
->range
.upper
=
3413 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3417 case IPP_TAG_TEXTLANG
:
3418 case IPP_TAG_NAMELANG
:
3421 if (tag
== IPP_TAG_TEXTLANG
)
3422 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3423 _("IPP textWithLanguage value less than "
3424 "minimum 4 bytes."), 1);
3426 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3427 _("IPP nameWithLanguage value less than "
3428 "minimum 4 bytes."), 1);
3429 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3431 _cupsBufferRelease((char *)buffer
);
3432 return (IPP_STATE_ERROR
);
3435 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3437 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3439 _cupsBufferRelease((char *)buffer
);
3440 return (IPP_STATE_ERROR
);
3446 * text-with-language and name-with-language are composite
3455 n
= (bufptr
[0] << 8) | bufptr
[1];
3457 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) || n
>= (int)sizeof(string
))
3459 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3460 _("IPP language length overflows value."), 1);
3461 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3463 _cupsBufferRelease((char *)buffer
);
3464 return (IPP_STATE_ERROR
);
3466 else if (n
>= IPP_MAX_LANGUAGE
)
3468 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3469 _("IPP language length too large."), 1);
3470 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3472 _cupsBufferRelease((char *)buffer
);
3473 return (IPP_STATE_ERROR
);
3476 memcpy(string
, bufptr
+ 2, (size_t)n
);
3479 value
->string
.language
= _cupsStrAlloc((char *)string
);
3482 n
= (bufptr
[0] << 8) | bufptr
[1];
3484 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3486 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3487 _("IPP string length overflows value."), 1);
3488 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3489 _cupsBufferRelease((char *)buffer
);
3490 return (IPP_STATE_ERROR
);
3493 bufptr
[2 + n
] = '\0';
3494 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3497 case IPP_TAG_BEGIN_COLLECTION
:
3499 * Oh, boy, here comes a collection value, so read it...
3502 value
->collection
= ippNew();
3506 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3507 _("IPP begCollection value not 0 bytes."), 1);
3508 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3510 _cupsBufferRelease((char *)buffer
);
3511 return (IPP_STATE_ERROR
);
3514 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3516 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3517 _cupsBufferRelease((char *)buffer
);
3518 return (IPP_STATE_ERROR
);
3522 case IPP_TAG_END_COLLECTION
:
3523 _cupsBufferRelease((char *)buffer
);
3527 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3528 _("IPP endCollection value not 0 bytes."), 1);
3529 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3531 return (IPP_STATE_ERROR
);
3534 DEBUG_puts("1ippReadIO: endCollection tag...");
3535 return (ipp
->state
= IPP_STATE_DATA
);
3537 case IPP_TAG_MEMBERNAME
:
3539 * The value the name of the member in the collection, which
3540 * we need to carry over...
3545 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3546 _("IPP memberName with no attribute."), 1);
3547 DEBUG_puts("1ippReadIO: Member name without attribute.");
3548 _cupsBufferRelease((char *)buffer
);
3549 return (IPP_STATE_ERROR
);
3553 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3554 _("IPP memberName value is empty."), 1);
3555 DEBUG_puts("1ippReadIO: Empty member name value.");
3556 _cupsBufferRelease((char *)buffer
);
3557 return (IPP_STATE_ERROR
);
3559 else if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3561 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3562 _cupsBufferRelease((char *)buffer
);
3563 return (IPP_STATE_ERROR
);
3567 attr
->name
= _cupsStrAlloc((char *)buffer
);
3570 * Since collection members are encoded differently than
3571 * regular attributes, make sure we don't start with an
3575 attr
->num_values
--;
3577 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3580 case IPP_TAG_STRING
:
3581 default : /* Other unsupported values */
3582 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3584 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3585 _("IPP octetString length too large."), 1);
3586 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3588 _cupsBufferRelease((char *)buffer
);
3589 return (IPP_STATE_ERROR
);
3592 value
->unknown
.length
= n
;
3596 if ((value
->unknown
.data
= malloc((size_t)n
)) == NULL
)
3598 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3599 DEBUG_puts("1ippReadIO: Unable to allocate value");
3600 _cupsBufferRelease((char *)buffer
);
3601 return (IPP_STATE_ERROR
);
3604 if ((*cb
)(src
, value
->unknown
.data
, (size_t)n
) < n
)
3606 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3607 _cupsBufferRelease((char *)buffer
);
3608 return (IPP_STATE_ERROR
);
3612 value
->unknown
.data
= NULL
;
3617 * If blocking is disabled, stop here...
3625 case IPP_STATE_DATA
:
3629 break; /* anti-compiler-warning-code */
3632 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3633 _cupsBufferRelease((char *)buffer
);
3635 return (ipp
->state
);
3640 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3642 * The @code ipp@ parameter refers to an IPP message previously created using
3643 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3645 * The @code attr@ parameter may be modified as a result of setting the value.
3647 * The @code element@ parameter specifies which value to set from 0 to
3648 * @code ippGetCount(attr)@.
3650 * @since CUPS 1.6/macOS 10.8@
3653 int /* O - 1 on success, 0 on failure */
3654 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3655 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3656 int element
, /* I - Value number (0-based) */
3657 int boolvalue
)/* I - Boolean value */
3659 _ipp_value_t
*value
; /* Current value */
3663 * Range check input...
3666 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3667 element
< 0 || element
> (*attr
)->num_values
)
3671 * Set the value and return...
3674 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3675 value
->boolean
= (char)boolvalue
;
3677 return (value
!= NULL
);
3682 * 'ippSetCollection()' - Set a collection value in an attribute.
3684 * The @code ipp@ parameter refers to an IPP message previously created using
3685 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3687 * The @code attr@ parameter may be modified as a result of setting the value.
3689 * The @code element@ parameter specifies which value to set from 0 to
3690 * @code ippGetCount(attr)@.
3692 * @since CUPS 1.6/macOS 10.8@
3695 int /* O - 1 on success, 0 on failure */
3697 ipp_t
*ipp
, /* I - IPP message */
3698 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3699 int element
, /* I - Value number (0-based) */
3700 ipp_t
*colvalue
) /* I - Collection value */
3702 _ipp_value_t
*value
; /* Current value */
3706 * Range check input...
3709 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3710 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3714 * Set the value and return...
3717 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3719 if (value
->collection
)
3720 ippDelete(value
->collection
);
3722 value
->collection
= colvalue
;
3726 return (value
!= NULL
);
3731 * 'ippSetDate()' - Set a dateTime value in an attribute.
3733 * The @code ipp@ parameter refers to an IPP message previously created using
3734 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3736 * The @code attr@ parameter may be modified as a result of setting the value.
3738 * The @code element@ parameter specifies which value to set from 0 to
3739 * @code ippGetCount(attr)@.
3741 * @since CUPS 1.6/macOS 10.8@
3744 int /* O - 1 on success, 0 on failure */
3745 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3746 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3747 int element
, /* I - Value number (0-based) */
3748 const ipp_uchar_t
*datevalue
)/* I - dateTime value */
3750 _ipp_value_t
*value
; /* Current value */
3754 * Range check input...
3757 if (!ipp
|| !attr
|| !*attr
|| ((*attr
)->value_tag
!= IPP_TAG_DATE
&& (*attr
)->value_tag
!= IPP_TAG_NOVALUE
&& (*attr
)->value_tag
!= IPP_TAG_UNKNOWN
) || element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3761 * Set the value and return...
3764 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3765 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3767 return (value
!= NULL
);
3772 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3774 * The @code ipp@ parameter refers to an IPP message previously created using
3775 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3777 * The @code attr@ parameter may be modified as a result of setting the value.
3779 * The @code group@ parameter specifies the IPP attribute group tag: none
3780 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3781 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3782 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3783 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3785 * @since CUPS 1.6/macOS 10.8@
3788 int /* O - 1 on success, 0 on failure */
3790 ipp_t
*ipp
, /* I - IPP message */
3791 ipp_attribute_t
**attr
, /* IO - Attribute */
3792 ipp_tag_t group_tag
) /* I - Group tag */
3795 * Range check input - group tag must be 0x01 to 0x0F, per RFC 8011...
3798 if (!ipp
|| !attr
|| !*attr
||
3799 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3800 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3804 * Set the group tag and return...
3807 (*attr
)->group_tag
= group_tag
;
3814 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3816 * The @code ipp@ parameter refers to an IPP message previously created using
3817 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3819 * The @code attr@ parameter may be modified as a result of setting the value.
3821 * The @code element@ parameter specifies which value to set from 0 to
3822 * @code ippGetCount(attr)@.
3824 * @since CUPS 1.6/macOS 10.8@
3827 int /* O - 1 on success, 0 on failure */
3828 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3829 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3830 int element
, /* I - Value number (0-based) */
3831 int intvalue
) /* I - Integer/enum value */
3833 _ipp_value_t
*value
; /* Current value */
3837 * Range check input...
3840 if (!ipp
|| !attr
|| !*attr
|| ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
&& (*attr
)->value_tag
!= IPP_TAG_NOVALUE
&& (*attr
)->value_tag
!= IPP_TAG_UNKNOWN
) || element
< 0 || element
> (*attr
)->num_values
)
3844 * Set the value and return...
3847 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3849 if ((*attr
)->value_tag
!= IPP_TAG_ENUM
)
3850 (*attr
)->value_tag
= IPP_TAG_INTEGER
;
3852 value
->integer
= intvalue
;
3855 return (value
!= NULL
);
3860 * 'ippSetName()' - Set the name of an attribute.
3862 * The @code ipp@ parameter refers to an IPP message previously created using
3863 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3865 * The @code attr@ parameter may be modified as a result of setting the value.
3867 * @since CUPS 1.6/macOS 10.8@
3870 int /* O - 1 on success, 0 on failure */
3871 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3872 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3873 const char *name
) /* I - Attribute name */
3875 char *temp
; /* Temporary name value */
3879 * Range check input...
3882 if (!ipp
|| !attr
|| !*attr
)
3886 * Set the value and return...
3889 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3892 _cupsStrFree((*attr
)->name
);
3894 (*attr
)->name
= temp
;
3897 return (temp
!= NULL
);
3902 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
3904 * The @code ipp@ parameter refers to an IPP message previously created using
3905 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3907 * The @code attr@ parameter may be modified as a result of setting the value.
3909 * The @code element@ parameter specifies which value to set from 0 to
3910 * @code ippGetCount(attr)@.
3912 * @since CUPS 1.7/macOS 10.9@
3915 int /* O - 1 on success, 0 on failure */
3917 ipp_t
*ipp
, /* I - IPP message */
3918 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3919 int element
, /* I - Value number (0-based) */
3920 const void *data
, /* I - Pointer to octetString data */
3921 int datalen
) /* I - Length of octetString data */
3923 _ipp_value_t
*value
; /* Current value */
3927 * Range check input...
3930 if (!ipp
|| !attr
|| !*attr
|| ((*attr
)->value_tag
!= IPP_TAG_STRING
&& (*attr
)->value_tag
!= IPP_TAG_NOVALUE
&& (*attr
)->value_tag
!= IPP_TAG_UNKNOWN
) || element
< 0 || element
> (*attr
)->num_values
|| datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
3934 * Set the value and return...
3937 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3939 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
3942 * Just copy the pointer...
3945 value
->unknown
.data
= (void *)data
;
3946 value
->unknown
.length
= datalen
;
3954 (*attr
)->value_tag
= IPP_TAG_STRING
;
3956 if (value
->unknown
.data
)
3959 * Free previous data...
3962 free(value
->unknown
.data
);
3964 value
->unknown
.data
= NULL
;
3965 value
->unknown
.length
= 0;
3970 void *temp
; /* Temporary data pointer */
3972 if ((temp
= malloc((size_t)datalen
)) != NULL
)
3974 memcpy(temp
, data
, (size_t)datalen
);
3976 value
->unknown
.data
= temp
;
3977 value
->unknown
.length
= datalen
;
3985 return (value
!= NULL
);
3990 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
3992 * The @code ipp@ parameter refers to an IPP message previously created using
3993 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3995 * @since CUPS 1.6/macOS 10.8@
3998 int /* O - 1 on success, 0 on failure */
3999 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
4000 ipp_op_t op
) /* I - Operation ID */
4003 * Range check input...
4010 * Set the operation and return...
4013 ipp
->request
.op
.operation_id
= op
;
4020 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4022 * The @code ipp@ parameter refers to an IPP message previously created using
4023 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4025 * The @code attr@ parameter may be modified as a result of setting the value.
4027 * The @code element@ parameter specifies which value to set from 0 to
4028 * @code ippGetCount(attr)@.
4030 * @since CUPS 1.6/macOS 10.8@
4033 int /* O - 1 on success, 0 on failure */
4034 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4035 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4036 int element
, /* I - Value number (0-based) */
4037 int lowervalue
, /* I - Lower bound for range */
4038 int uppervalue
) /* I - Upper bound for range */
4040 _ipp_value_t
*value
; /* Current value */
4044 * Range check input...
4047 if (!ipp
|| !attr
|| !*attr
|| ((*attr
)->value_tag
!= IPP_TAG_RANGE
&& (*attr
)->value_tag
!= IPP_TAG_NOVALUE
&& (*attr
)->value_tag
!= IPP_TAG_UNKNOWN
) || element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4051 * Set the value and return...
4054 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4056 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4057 value
->range
.lower
= lowervalue
;
4058 value
->range
.upper
= uppervalue
;
4061 return (value
!= NULL
);
4066 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4068 * The @code ipp@ parameter refers to an IPP message previously created using
4069 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4071 * The @code request_id@ parameter must be greater than 0.
4073 * @since CUPS 1.6/macOS 10.8@
4076 int /* O - 1 on success, 0 on failure */
4077 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4078 int request_id
) /* I - Request ID */
4081 * Range check input; not checking request_id values since ipptool wants to send
4082 * invalid values for conformance testing and a bad request_id does not affect the
4083 * encoding of a message...
4090 * Set the request ID and return...
4093 ipp
->request
.any
.request_id
= request_id
;
4100 * 'ippSetResolution()' - Set a resolution value in an attribute.
4102 * The @code ipp@ parameter refers to an IPP message previously created using
4103 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4105 * The @code attr@ parameter may be modified as a result of setting the value.
4107 * The @code element@ parameter specifies which value to set from 0 to
4108 * @code ippGetCount(attr)@.
4110 * @since CUPS 1.6/macOS 10.8@
4113 int /* O - 1 on success, 0 on failure */
4115 ipp_t
*ipp
, /* I - IPP message */
4116 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4117 int element
, /* I - Value number (0-based) */
4118 ipp_res_t unitsvalue
, /* I - Resolution units */
4119 int xresvalue
, /* I - Horizontal/cross feed resolution */
4120 int yresvalue
) /* I - Vertical/feed resolution */
4122 _ipp_value_t
*value
; /* Current value */
4126 * Range check input...
4129 if (!ipp
|| !attr
|| !*attr
|| ((*attr
)->value_tag
!= IPP_TAG_RESOLUTION
&& (*attr
)->value_tag
!= IPP_TAG_NOVALUE
&& (*attr
)->value_tag
!= IPP_TAG_UNKNOWN
) || element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 || unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4133 * Set the value and return...
4136 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4138 (*attr
)->value_tag
= IPP_TAG_RESOLUTION
;
4139 value
->resolution
.units
= unitsvalue
;
4140 value
->resolution
.xres
= xresvalue
;
4141 value
->resolution
.yres
= yresvalue
;
4144 return (value
!= NULL
);
4149 * 'ippSetState()' - Set the current state of the IPP message.
4151 * @since CUPS 1.6/macOS 10.8@
4154 int /* O - 1 on success, 0 on failure */
4155 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4156 ipp_state_t state
) /* I - IPP state value */
4159 * Range check input...
4166 * Set the state and return...
4170 ipp
->current
= NULL
;
4177 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4179 * The @code ipp@ parameter refers to an IPP message previously created using
4180 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4182 * @since CUPS 1.6/macOS 10.8@
4185 int /* O - 1 on success, 0 on failure */
4186 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4187 ipp_status_t status
) /* I - Status code */
4190 * Range check input...
4197 * Set the status code and return...
4200 ipp
->request
.status
.status_code
= status
;
4207 * 'ippSetString()' - Set a string value in an attribute.
4209 * The @code ipp@ parameter refers to an IPP message previously created using
4210 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4212 * The @code attr@ parameter may be modified as a result of setting the value.
4214 * The @code element@ parameter specifies which value to set from 0 to
4215 * @code ippGetCount(attr)@.
4217 * @since CUPS 1.6/macOS 10.8@
4220 int /* O - 1 on success, 0 on failure */
4221 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4222 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4223 int element
, /* I - Value number (0-based) */
4224 const char *strvalue
) /* I - String value */
4226 char *temp
; /* Temporary string */
4227 _ipp_value_t
*value
; /* Current value */
4228 ipp_tag_t value_tag
; /* Value tag */
4232 * Range check input...
4236 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4238 value_tag
= IPP_TAG_ZERO
;
4240 if (!ipp
|| !attr
|| !*attr
|| (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&& value_tag
!= IPP_TAG_NAMELANG
&& value_tag
!= IPP_TAG_NOVALUE
&& value_tag
!= IPP_TAG_UNKNOWN
) || value_tag
> IPP_TAG_MIMETYPE
|| element
< 0 || element
> (*attr
)->num_values
|| !strvalue
)
4244 * Set the value and return...
4247 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4249 if (value_tag
== IPP_TAG_NOVALUE
|| value_tag
== IPP_TAG_UNKNOWN
)
4250 (*attr
)->value_tag
= IPP_TAG_KEYWORD
;
4253 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4255 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4256 value
->string
.text
= (char *)strvalue
;
4257 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4259 if (value
->string
.text
)
4260 _cupsStrFree(value
->string
.text
);
4262 value
->string
.text
= temp
;
4268 return (value
!= NULL
);
4273 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4275 * The @code ipp@ parameter refers to an IPP message previously created using
4276 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4278 * The @code attr@ parameter may be modified as a result of setting the value.
4280 * The @code element@ parameter specifies which value to set from 0 to
4281 * @code ippGetCount(attr)@.
4283 * The @code format@ parameter uses formatting characters compatible with the
4284 * printf family of standard functions. Additional arguments follow it as
4285 * needed. The formatted string is truncated as needed to the maximum length of
4286 * the corresponding value type.
4288 * @since CUPS 1.7/macOS 10.9@
4291 int /* O - 1 on success, 0 on failure */
4292 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4293 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4294 int element
, /* I - Value number (0-based) */
4295 const char *format
, /* I - Printf-style format string */
4296 ...) /* I - Additional arguments as needed */
4298 int ret
; /* Return value */
4299 va_list ap
; /* Pointer to additional arguments */
4302 va_start(ap
, format
);
4303 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4311 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4313 * The @code ipp@ parameter refers to an IPP message previously created using
4314 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4316 * The @code attr@ parameter may be modified as a result of setting the value.
4318 * The @code element@ parameter specifies which value to set from 0 to
4319 * @code ippGetCount(attr)@.
4321 * The @code format@ parameter uses formatting characters compatible with the
4322 * printf family of standard functions. Additional arguments follow it as
4323 * needed. The formatted string is truncated as needed to the maximum length of
4324 * the corresponding value type.
4326 * @since CUPS 1.7/macOS 10.9@
4329 int /* O - 1 on success, 0 on failure */
4330 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4331 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4332 int element
, /* I - Value number (0-based) */
4333 const char *format
, /* I - Printf-style format string */
4334 va_list ap
) /* I - Pointer to additional arguments */
4336 ipp_tag_t value_tag
; /* Value tag */
4337 char buffer
[IPP_MAX_TEXT
+ 4];
4338 /* Formatted text string */
4339 ssize_t bytes
, /* Length of formatted value */
4340 max_bytes
; /* Maximum number of bytes for value */
4344 * Range check input...
4348 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4350 value_tag
= IPP_TAG_ZERO
;
4352 if (!ipp
|| !attr
|| !*attr
|| (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&& value_tag
!= IPP_TAG_NAMELANG
&& value_tag
!= IPP_TAG_NOVALUE
&& value_tag
!= IPP_TAG_UNKNOWN
) || value_tag
> IPP_TAG_MIMETYPE
|| !format
)
4356 * Format the string...
4359 if (!strcmp(format
, "%s"))
4362 * Optimize the simple case...
4365 const char *s
= va_arg(ap
, char *);
4370 bytes
= (ssize_t
)strlen(s
);
4371 strlcpy(buffer
, s
, sizeof(buffer
));
4376 * Do a full formatting of the message...
4379 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4384 * Limit the length of the string...
4391 case IPP_TAG_TEXTLANG
:
4392 max_bytes
= IPP_MAX_TEXT
;
4396 case IPP_TAG_NAMELANG
:
4397 max_bytes
= IPP_MAX_NAME
;
4400 case IPP_TAG_CHARSET
:
4401 max_bytes
= IPP_MAX_CHARSET
;
4404 case IPP_TAG_NOVALUE
:
4405 case IPP_TAG_UNKNOWN
:
4406 case IPP_TAG_KEYWORD
:
4407 max_bytes
= IPP_MAX_KEYWORD
;
4410 case IPP_TAG_LANGUAGE
:
4411 max_bytes
= IPP_MAX_LANGUAGE
;
4414 case IPP_TAG_MIMETYPE
:
4415 max_bytes
= IPP_MAX_MIMETYPE
;
4419 max_bytes
= IPP_MAX_URI
;
4422 case IPP_TAG_URISCHEME
:
4423 max_bytes
= IPP_MAX_URISCHEME
;
4427 if (bytes
>= max_bytes
)
4429 char *bufmax
, /* Buffer at max_bytes */
4430 *bufptr
; /* Pointer into buffer */
4432 bufptr
= buffer
+ strlen(buffer
) - 1;
4433 bufmax
= buffer
+ max_bytes
- 1;
4435 while (bufptr
> bufmax
)
4439 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4450 * Set the formatted string and return...
4453 return (ippSetString(ipp
, attr
, element
, buffer
));
4458 * 'ippSetValueTag()' - Set the value tag of an attribute.
4460 * The @code ipp@ parameter refers to an IPP message previously created using
4461 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4463 * The @code attr@ parameter may be modified as a result of setting the value.
4465 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4466 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4467 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4468 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4469 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4470 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4473 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4474 * code in the "attributes-natural-language" attribute or, if not present, the language
4475 * code for the current locale.
4477 * @since CUPS 1.6/macOS 10.8@
4480 int /* O - 1 on success, 0 on failure */
4482 ipp_t
*ipp
, /* I - IPP message */
4483 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4484 ipp_tag_t value_tag
) /* I - Value tag */
4486 int i
; /* Looping var */
4487 _ipp_value_t
*value
; /* Current value */
4488 int integer
; /* Current integer value */
4489 cups_lang_t
*language
; /* Current language */
4490 char code
[32]; /* Language code */
4491 ipp_tag_t temp_tag
; /* Temporary value tag */
4495 * Range check input...
4498 if (!ipp
|| !attr
|| !*attr
)
4502 * If there is no change, return immediately...
4505 if (value_tag
== (*attr
)->value_tag
)
4509 * Otherwise implement changes as needed...
4512 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4516 case IPP_TAG_UNSUPPORTED_VALUE
:
4517 case IPP_TAG_DEFAULT
:
4518 case IPP_TAG_UNKNOWN
:
4519 case IPP_TAG_NOVALUE
:
4520 case IPP_TAG_NOTSETTABLE
:
4521 case IPP_TAG_DELETEATTR
:
4522 case IPP_TAG_ADMINDEFINE
:
4524 * Free any existing values...
4527 if ((*attr
)->num_values
> 0)
4528 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4531 * Set out-of-band value...
4534 (*attr
)->value_tag
= value_tag
;
4537 case IPP_TAG_RANGE
:
4538 if (temp_tag
!= IPP_TAG_INTEGER
)
4541 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4545 integer
= value
->integer
;
4546 value
->range
.lower
= value
->range
.upper
= integer
;
4549 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4553 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4554 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4555 temp_tag
!= IPP_TAG_MIMETYPE
)
4558 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4561 case IPP_TAG_NAMELANG
:
4562 case IPP_TAG_TEXTLANG
:
4563 if (value_tag
== IPP_TAG_NAMELANG
&&
4564 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4565 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4566 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4569 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4572 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4573 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4576 * Use the language code from the IPP message...
4579 (*attr
)->values
[0].string
.language
=
4580 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4585 * Otherwise, use the language code corresponding to the locale...
4588 language
= cupsLangDefault();
4589 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4594 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4597 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4599 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4602 * Make copies of all values...
4605 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4608 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4611 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4614 case IPP_TAG_KEYWORD
:
4615 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4616 break; /* Silently "allow" name -> keyword */
4627 * 'ippSetVersion()' - Set the version number in an IPP message.
4629 * The @code ipp@ parameter refers to an IPP message previously created using
4630 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4632 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4634 * @since CUPS 1.6/macOS 10.8@
4637 int /* O - 1 on success, 0 on failure */
4638 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4639 int major
, /* I - Major version number (major.minor) */
4640 int minor
) /* I - Minor version number (major.minor) */
4643 * Range check input...
4646 if (!ipp
|| major
< 0 || minor
< 0)
4650 * Set the version number...
4653 ipp
->request
.any
.version
[0] = (ipp_uchar_t
)major
;
4654 ipp
->request
.any
.version
[1] = (ipp_uchar_t
)minor
;
4661 * 'ippTimeToDate()' - Convert from time in seconds to RFC 2579 format.
4664 const ipp_uchar_t
* /* O - RFC-2579 date/time data */
4665 ippTimeToDate(time_t t
) /* I - Time in seconds */
4667 struct tm
*unixdate
; /* UNIX unixdate/time info */
4668 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4669 /* RFC-2579 date/time data */
4673 * RFC-2579 date/time format is:
4675 * Byte(s) Description
4676 * ------- -----------
4677 * 0-1 Year (0 to 65535)
4681 * 5 Minutes (0 to 59)
4682 * 6 Seconds (0 to 60, 60 = "leap second")
4683 * 7 Deciseconds (0 to 9)
4685 * 9 UTC hours (0 to 11)
4686 * 10 UTC minutes (0 to 59)
4689 unixdate
= gmtime(&t
);
4690 unixdate
->tm_year
+= 1900;
4692 date
[0] = (ipp_uchar_t
)(unixdate
->tm_year
>> 8);
4693 date
[1] = (ipp_uchar_t
)(unixdate
->tm_year
);
4694 date
[2] = (ipp_uchar_t
)(unixdate
->tm_mon
+ 1);
4695 date
[3] = (ipp_uchar_t
)unixdate
->tm_mday
;
4696 date
[4] = (ipp_uchar_t
)unixdate
->tm_hour
;
4697 date
[5] = (ipp_uchar_t
)unixdate
->tm_min
;
4698 date
[6] = (ipp_uchar_t
)unixdate
->tm_sec
;
4709 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4711 * This function validates the contents of an attribute based on the name and
4712 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4713 * failure, @link cupsLastErrorString@ is set to a human-readable message.
4715 * @since CUPS 1.7/macOS 10.9@
4718 int /* O - 1 if valid, 0 otherwise */
4719 ippValidateAttribute(
4720 ipp_attribute_t
*attr
) /* I - Attribute */
4722 int i
; /* Looping var */
4723 char scheme
[64], /* Scheme from URI */
4724 userpass
[256], /* Username/password from URI */
4725 hostname
[256], /* Hostname from URI */
4726 resource
[1024]; /* Resource from URI */
4727 int port
, /* Port number from URI */
4728 uri_status
; /* URI separation status */
4729 const char *ptr
; /* Pointer into string */
4730 ipp_attribute_t
*colattr
; /* Collection attribute */
4731 regex_t re
; /* Regular expression */
4732 ipp_uchar_t
*date
; /* Current date value */
4743 * Validate the attribute name.
4746 for (ptr
= attr
->name
; *ptr
; ptr
++)
4747 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4750 if (*ptr
|| ptr
== attr
->name
)
4752 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad attribute name - invalid character (RFC 8011 section 5.1.4)."), attr
->name
);
4756 if ((ptr
- attr
->name
) > 255)
4758 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
));
4762 switch (attr
->value_tag
)
4764 case IPP_TAG_INTEGER
:
4767 case IPP_TAG_BOOLEAN
:
4768 for (i
= 0; i
< attr
->num_values
; i
++)
4770 if (attr
->values
[i
].boolean
!= 0 &&
4771 attr
->values
[i
].boolean
!= 1)
4773 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
);
4780 for (i
= 0; i
< attr
->num_values
; i
++)
4782 if (attr
->values
[i
].integer
< 1)
4784 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
);
4790 case IPP_TAG_STRING
:
4791 for (i
= 0; i
< attr
->num_values
; i
++)
4793 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4795 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
);
4802 for (i
= 0; i
< attr
->num_values
; i
++)
4804 date
= attr
->values
[i
].date
;
4806 if (date
[2] < 1 || date
[2] > 12)
4808 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime month %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[2]);
4812 if (date
[3] < 1 || date
[3] > 31)
4814 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime day %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[3]);
4820 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime hours %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[4]);
4826 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime minutes %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[5]);
4832 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime seconds %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[6]);
4838 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime deciseconds %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[7]);
4842 if (date
[8] != '-' && date
[8] != '+')
4844 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime UTC sign '%c' (RFC 8011 section 5.1.15)."), attr
->name
, date
[8]);
4850 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime UTC hours %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[9]);
4856 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("\"%s\": Bad dateTime UTC minutes %u (RFC 8011 section 5.1.15)."), attr
->name
, date
[10]);
4862 case IPP_TAG_RESOLUTION
:
4863 for (i
= 0; i
< attr
->num_values
; i
++)
4865 if (attr
->values
[i
].resolution
.xres
<= 0)
4867 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");
4871 if (attr
->values
[i
].resolution
.yres
<= 0)
4873 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");
4877 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&& attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
4879 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");
4885 case IPP_TAG_RANGE
:
4886 for (i
= 0; i
< attr
->num_values
; i
++)
4888 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
4890 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
);
4896 case IPP_TAG_BEGIN_COLLECTION
:
4897 for (i
= 0; i
< attr
->num_values
; i
++)
4899 for (colattr
= attr
->values
[i
].collection
->attrs
;
4901 colattr
= colattr
->next
)
4903 if (!ippValidateAttribute(colattr
))
4910 case IPP_TAG_TEXTLANG
:
4911 for (i
= 0; i
< attr
->num_values
; i
++)
4913 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
4915 if ((*ptr
& 0xe0) == 0xc0)
4917 if ((ptr
[1] & 0xc0) != 0x80)
4922 else if ((*ptr
& 0xf0) == 0xe0)
4924 if ((ptr
[1] & 0xc0) != 0x80 || (ptr
[2] & 0xc0) != 0x80)
4929 else if ((*ptr
& 0xf8) == 0xf0)
4931 if ((ptr
[1] & 0xc0) != 0x80 || (ptr
[2] & 0xc0) != 0x80 || (ptr
[3] & 0xc0) != 0x80)
4936 else if (*ptr
& 0x80)
4938 else if ((*ptr
< ' ' && *ptr
!= '\n' && *ptr
!= '\r' && *ptr
!= '\t') || *ptr
== 0x7f)
4944 if (*ptr
< ' ' || *ptr
== 0x7f)
4946 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
);
4951 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
);
4956 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
4958 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
));
4965 case IPP_TAG_NAMELANG
:
4966 for (i
= 0; i
< attr
->num_values
; i
++)
4968 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
4970 if ((*ptr
& 0xe0) == 0xc0)
4972 if ((ptr
[1] & 0xc0) != 0x80)
4977 else if ((*ptr
& 0xf0) == 0xe0)
4979 if ((ptr
[1] & 0xc0) != 0x80 || (ptr
[2] & 0xc0) != 0x80)
4984 else if ((*ptr
& 0xf8) == 0xf0)
4986 if ((ptr
[1] & 0xc0) != 0x80 || (ptr
[2] & 0xc0) != 0x80 || (ptr
[3] & 0xc0) != 0x80)
4991 else if (*ptr
& 0x80)
4993 else if (*ptr
< ' ' || *ptr
== 0x7f)
4999 if (*ptr
< ' ' || *ptr
== 0x7f)
5001 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
);
5006 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
);
5011 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5013 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
));
5019 case IPP_TAG_KEYWORD
:
5020 for (i
= 0; i
< attr
->num_values
; i
++)
5022 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5024 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5029 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5031 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
);
5035 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5037 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
));
5044 for (i
= 0; i
< attr
->num_values
; i
++)
5046 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
));
5048 if (uri_status
< HTTP_URI_STATUS_OK
)
5050 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
));
5054 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5056 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
));
5061 case IPP_TAG_URISCHEME
:
5062 for (i
= 0; i
< attr
->num_values
; i
++)
5064 ptr
= attr
->values
[i
].string
.text
;
5065 if (islower(*ptr
& 255))
5067 for (ptr
++; *ptr
; ptr
++)
5069 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5070 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5075 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5077 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
);
5081 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5083 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
));
5089 case IPP_TAG_CHARSET
:
5090 for (i
= 0; i
< attr
->num_values
; i
++)
5092 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5094 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5095 isspace(*ptr
& 255))
5099 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5101 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
);
5105 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5107 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
));
5113 case IPP_TAG_LANGUAGE
:
5115 * The following regular expression is derived from the ABNF for
5116 * language tags in RFC 4646. All I can say is that this is the
5117 * easiest way to check the values...
5120 if ((i
= regcomp(&re
,
5122 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5124 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5125 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5126 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5127 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5128 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5130 "x(-[a-z0-9]{1,8})+" /* privateuse */
5132 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5134 REG_NOSUB
| REG_EXTENDED
)) != 0)
5136 char temp
[256]; /* Temporary error string */
5138 regerror(i
, &re
, temp
, sizeof(temp
));
5139 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
, _("Unable to compile naturalLanguage regular expression: %s."), temp
);
5143 for (i
= 0; i
< attr
->num_values
; i
++)
5145 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5147 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
);
5152 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5154 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
));
5163 case IPP_TAG_MIMETYPE
:
5165 * The following regular expression is derived from the ABNF for
5166 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5167 * the easiest way to check the values...
5170 if ((i
= regcomp(&re
,
5172 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5174 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5175 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5176 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5179 REG_NOSUB
| REG_EXTENDED
)) != 0)
5181 char temp
[256]; /* Temporary error string */
5183 regerror(i
, &re
, temp
, sizeof(temp
));
5184 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
, _("Unable to compile mimeMediaType regular expression: %s."), temp
);
5188 for (i
= 0; i
< attr
->num_values
; i
++)
5190 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5192 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
);
5197 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5199 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
));
5217 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5219 * This function validates the contents of the IPP message, including each
5220 * attribute. Like @link ippValidateAttribute@, @link cupsLastErrorString@ is
5221 * set to a human-readable message on failure.
5223 * @since CUPS 1.7/macOS 10.9@
5226 int /* O - 1 if valid, 0 otherwise */
5227 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5229 ipp_attribute_t
*attr
; /* Current attribute */
5235 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5236 if (!ippValidateAttribute(attr
))
5244 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5247 ipp_state_t
/* O - Current state */
5248 ippWrite(http_t
*http
, /* I - HTTP connection */
5249 ipp_t
*ipp
) /* I - IPP data */
5251 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http
, (void *)ipp
));
5254 return (IPP_STATE_ERROR
);
5256 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5261 * 'ippWriteFile()' - Write data for an IPP message to a file.
5263 * @since CUPS 1.1.19/macOS 10.3@
5266 ipp_state_t
/* O - Current state */
5267 ippWriteFile(int fd
, /* I - HTTP data */
5268 ipp_t
*ipp
) /* I - IPP data */
5270 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
5272 ipp
->state
= IPP_STATE_IDLE
;
5274 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5279 * 'ippWriteIO()' - Write data for an IPP message.
5281 * @since CUPS 1.2/macOS 10.5@
5284 ipp_state_t
/* O - Current state */
5285 ippWriteIO(void *dst
, /* I - Destination */
5286 ipp_iocb_t cb
, /* I - Write callback function */
5287 int blocking
, /* I - Use blocking IO? */
5288 ipp_t
*parent
, /* I - Parent IPP message */
5289 ipp_t
*ipp
) /* I - IPP data */
5291 int i
; /* Looping var */
5292 int n
; /* Length of data */
5293 unsigned char *buffer
, /* Data buffer */
5294 *bufptr
; /* Pointer into buffer */
5295 ipp_attribute_t
*attr
; /* Current attribute */
5296 _ipp_value_t
*value
; /* Current value */
5299 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
5302 return (IPP_STATE_ERROR
);
5304 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5306 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5307 return (IPP_STATE_ERROR
);
5312 case IPP_STATE_IDLE
:
5313 ipp
->state
++; /* Avoid common problem... */
5315 case IPP_STATE_HEADER
:
5319 * Send the request header:
5322 * Operation/Status Code = 2 bytes
5323 * Request ID = 4 bytes
5329 *bufptr
++ = ipp
->request
.any
.version
[0];
5330 *bufptr
++ = ipp
->request
.any
.version
[1];
5331 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.op_status
>> 8);
5332 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.op_status
;
5333 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 24);
5334 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 16);
5335 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 8);
5336 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.request_id
;
5338 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5339 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5340 ipp
->request
.any
.op_status
));
5341 DEBUG_printf(("2ippWriteIO: request_id=%d",
5342 ipp
->request
.any
.request_id
));
5344 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5346 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5347 _cupsBufferRelease((char *)buffer
);
5348 return (IPP_STATE_ERROR
);
5353 * Reset the state engine to point to the first attribute
5354 * in the request/response, with no current group.
5357 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5358 ipp
->current
= ipp
->attrs
;
5359 ipp
->curtag
= IPP_TAG_ZERO
;
5361 DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp
->current
));
5364 * If blocking is disabled, stop here...
5370 case IPP_STATE_ATTRIBUTE
:
5371 while (ipp
->current
!= NULL
)
5374 * Write this attribute...
5378 attr
= ipp
->current
;
5380 ipp
->current
= ipp
->current
->next
;
5384 if (ipp
->curtag
!= attr
->group_tag
)
5387 * Send a group tag byte...
5390 ipp
->curtag
= attr
->group_tag
;
5392 if (attr
->group_tag
== IPP_TAG_ZERO
)
5395 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5396 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5397 *bufptr
++ = (ipp_uchar_t
)attr
->group_tag
;
5399 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5403 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5404 attr
->num_values
> 1 ? "1setOf " : "",
5405 ippTagString(attr
->value_tag
)));
5408 * Write the attribute tag and name.
5410 * The attribute name length does not include the trailing nul
5411 * character in the source string.
5413 * Collection values (parent != NULL) are written differently...
5419 * Get the length of the attribute name, and make sure it won't
5420 * overflow the buffer...
5423 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5425 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5426 _cupsBufferRelease((char *)buffer
);
5427 return (IPP_STATE_ERROR
);
5431 * Write the value tag, name length, and name string...
5434 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5435 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5436 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5439 if (attr
->value_tag
> 0xff)
5441 *bufptr
++ = IPP_TAG_EXTENSION
;
5442 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5443 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5444 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5445 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5448 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5450 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5451 *bufptr
++ = (ipp_uchar_t
)n
;
5452 memcpy(bufptr
, attr
->name
, (size_t)n
);
5458 * Get the length of the attribute name, and make sure it won't
5459 * overflow the buffer...
5462 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5464 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5465 _cupsBufferRelease((char *)buffer
);
5466 return (IPP_STATE_ERROR
);
5470 * Write the member name tag, name length, name string, value tag,
5471 * and empty name for the collection member attribute...
5474 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5475 IPP_TAG_MEMBERNAME
));
5476 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5478 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5479 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5480 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5482 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5485 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5486 *bufptr
++ = (ipp_uchar_t
)n
;
5487 memcpy(bufptr
, attr
->name
, (size_t)n
);
5490 if (attr
->value_tag
> 0xff)
5492 *bufptr
++ = IPP_TAG_EXTENSION
;
5493 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5494 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5495 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5496 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5499 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5506 * Now write the attribute value(s)...
5509 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5511 case IPP_TAG_UNSUPPORTED_VALUE
:
5512 case IPP_TAG_DEFAULT
:
5513 case IPP_TAG_UNKNOWN
:
5514 case IPP_TAG_NOVALUE
:
5515 case IPP_TAG_NOTSETTABLE
:
5516 case IPP_TAG_DELETEATTR
:
5517 case IPP_TAG_ADMINDEFINE
:
5522 case IPP_TAG_INTEGER
:
5524 for (i
= 0, value
= attr
->values
;
5525 i
< attr
->num_values
;
5528 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5530 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5532 DEBUG_puts("1ippWriteIO: Could not write IPP "
5534 _cupsBufferRelease((char *)buffer
);
5535 return (IPP_STATE_ERROR
);
5544 * Arrays and sets are done by sending additional
5545 * values with a zero-length name...
5548 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5554 * Integers and enumerations are both 4-byte signed
5555 * (twos-complement) values.
5557 * Put the 2-byte length and 4-byte value into the buffer...
5562 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 24);
5563 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 16);
5564 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 8);
5565 *bufptr
++ = (ipp_uchar_t
)value
->integer
;
5569 case IPP_TAG_BOOLEAN
:
5570 for (i
= 0, value
= attr
->values
;
5571 i
< attr
->num_values
;
5574 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5576 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5578 DEBUG_puts("1ippWriteIO: Could not write IPP "
5580 _cupsBufferRelease((char *)buffer
);
5581 return (IPP_STATE_ERROR
);
5590 * Arrays and sets are done by sending additional
5591 * values with a zero-length name...
5594 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5600 * Boolean values are 1-byte; 0 = false, 1 = true.
5602 * Put the 2-byte length and 1-byte value into the buffer...
5607 *bufptr
++ = (ipp_uchar_t
)value
->boolean
;
5613 case IPP_TAG_KEYWORD
:
5615 case IPP_TAG_URISCHEME
:
5616 case IPP_TAG_CHARSET
:
5617 case IPP_TAG_LANGUAGE
:
5618 case IPP_TAG_MIMETYPE
:
5619 for (i
= 0, value
= attr
->values
;
5620 i
< attr
->num_values
;
5626 * Arrays and sets are done by sending additional
5627 * values with a zero-length name...
5630 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5632 ippTagString(attr
->value_tag
)));
5633 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5635 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5637 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5639 DEBUG_puts("1ippWriteIO: Could not write IPP "
5641 _cupsBufferRelease((char *)buffer
);
5642 return (IPP_STATE_ERROR
);
5648 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5653 if (value
->string
.text
!= NULL
)
5654 n
= (int)strlen(value
->string
.text
);
5658 if (n
> (IPP_BUF_SIZE
- 2))
5660 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5661 _cupsBufferRelease((char *)buffer
);
5662 return (IPP_STATE_ERROR
);
5665 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5666 value
->string
.text
));
5668 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5670 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5672 DEBUG_puts("1ippWriteIO: Could not write IPP "
5674 _cupsBufferRelease((char *)buffer
);
5675 return (IPP_STATE_ERROR
);
5682 * All simple strings consist of the 2-byte length and
5683 * character data without the trailing nul normally found
5684 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5685 * bytes since the 2-byte length is a signed (twos-complement)
5688 * Put the 2-byte length and string characters in the buffer.
5691 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5692 *bufptr
++ = (ipp_uchar_t
)n
;
5696 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5703 for (i
= 0, value
= attr
->values
;
5704 i
< attr
->num_values
;
5707 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5709 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5711 DEBUG_puts("1ippWriteIO: Could not write IPP "
5713 _cupsBufferRelease((char *)buffer
);
5714 return (IPP_STATE_ERROR
);
5723 * Arrays and sets are done by sending additional
5724 * values with a zero-length name...
5727 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5733 * Date values consist of a 2-byte length and an
5734 * 11-byte date/time structure defined by RFC 1903.
5736 * Put the 2-byte length and 11-byte date/time
5737 * structure in the buffer.
5742 memcpy(bufptr
, value
->date
, 11);
5747 case IPP_TAG_RESOLUTION
:
5748 for (i
= 0, value
= attr
->values
;
5749 i
< attr
->num_values
;
5752 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5754 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5756 DEBUG_puts("1ippWriteIO: Could not write IPP "
5758 _cupsBufferRelease((char *)buffer
);
5759 return (IPP_STATE_ERROR
);
5768 * Arrays and sets are done by sending additional
5769 * values with a zero-length name...
5772 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5778 * Resolution values consist of a 2-byte length,
5779 * 4-byte horizontal resolution value, 4-byte vertical
5780 * resolution value, and a 1-byte units value.
5782 * Put the 2-byte length and resolution value data
5788 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 24);
5789 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 16);
5790 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 8);
5791 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.xres
;
5792 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 24);
5793 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 16);
5794 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 8);
5795 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.yres
;
5796 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.units
;
5800 case IPP_TAG_RANGE
:
5801 for (i
= 0, value
= attr
->values
;
5802 i
< attr
->num_values
;
5805 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
5807 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5809 DEBUG_puts("1ippWriteIO: Could not write IPP "
5811 _cupsBufferRelease((char *)buffer
);
5812 return (IPP_STATE_ERROR
);
5821 * Arrays and sets are done by sending additional
5822 * values with a zero-length name...
5825 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5831 * Range values consist of a 2-byte length,
5832 * 4-byte lower value, and 4-byte upper value.
5834 * Put the 2-byte length and range value data
5840 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 24);
5841 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 16);
5842 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 8);
5843 *bufptr
++ = (ipp_uchar_t
)value
->range
.lower
;
5844 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 24);
5845 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 16);
5846 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 8);
5847 *bufptr
++ = (ipp_uchar_t
)value
->range
.upper
;
5851 case IPP_TAG_TEXTLANG
:
5852 case IPP_TAG_NAMELANG
:
5853 for (i
= 0, value
= attr
->values
;
5854 i
< attr
->num_values
;
5860 * Arrays and sets are done by sending additional
5861 * values with a zero-length name...
5864 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5866 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5868 DEBUG_puts("1ippWriteIO: Could not write IPP "
5870 _cupsBufferRelease((char *)buffer
);
5871 return (IPP_STATE_ERROR
);
5877 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5883 * textWithLanguage and nameWithLanguage values consist
5884 * of a 2-byte length for both strings and their
5885 * individual lengths, a 2-byte length for the
5886 * character string, the character string without the
5887 * trailing nul, a 2-byte length for the character
5888 * set string, and the character set string without
5894 if (value
->string
.language
!= NULL
)
5895 n
+= (int)strlen(value
->string
.language
);
5897 if (value
->string
.text
!= NULL
)
5898 n
+= (int)strlen(value
->string
.text
);
5900 if (n
> (IPP_BUF_SIZE
- 2))
5902 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
5903 "too long (%d)", n
));
5904 _cupsBufferRelease((char *)buffer
);
5905 return (IPP_STATE_ERROR
);
5908 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5910 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5912 DEBUG_puts("1ippWriteIO: Could not write IPP "
5914 _cupsBufferRelease((char *)buffer
);
5915 return (IPP_STATE_ERROR
);
5921 /* Length of entire value */
5922 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5923 *bufptr
++ = (ipp_uchar_t
)n
;
5925 /* Length of language */
5926 if (value
->string
.language
!= NULL
)
5927 n
= (int)strlen(value
->string
.language
);
5931 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5932 *bufptr
++ = (ipp_uchar_t
)n
;
5937 memcpy(bufptr
, value
->string
.language
, (size_t)n
);
5941 /* Length of text */
5942 if (value
->string
.text
!= NULL
)
5943 n
= (int)strlen(value
->string
.text
);
5947 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5948 *bufptr
++ = (ipp_uchar_t
)n
;
5953 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5959 case IPP_TAG_BEGIN_COLLECTION
:
5960 for (i
= 0, value
= attr
->values
;
5961 i
< attr
->num_values
;
5965 * Collections are written with the begin-collection
5966 * tag first with a value of 0 length, followed by the
5967 * attributes in the collection, then the end-collection
5971 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
5973 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5975 DEBUG_puts("1ippWriteIO: Could not write IPP "
5977 _cupsBufferRelease((char *)buffer
);
5978 return (IPP_STATE_ERROR
);
5987 * Arrays and sets are done by sending additional
5988 * values with a zero-length name...
5991 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5997 * Write a data length of 0 and flush the buffer...
6003 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6005 DEBUG_puts("1ippWriteIO: Could not write IPP "
6007 _cupsBufferRelease((char *)buffer
);
6008 return (IPP_STATE_ERROR
);
6014 * Then write the collection attribute...
6017 value
->collection
->state
= IPP_STATE_IDLE
;
6019 if (ippWriteIO(dst
, cb
, 1, ipp
,
6020 value
->collection
) == IPP_STATE_ERROR
)
6022 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6023 _cupsBufferRelease((char *)buffer
);
6024 return (IPP_STATE_ERROR
);
6030 for (i
= 0, value
= attr
->values
;
6031 i
< attr
->num_values
;
6037 * Arrays and sets are done by sending additional
6038 * values with a zero-length name...
6041 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6043 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6045 DEBUG_puts("1ippWriteIO: Could not write IPP "
6047 _cupsBufferRelease((char *)buffer
);
6048 return (IPP_STATE_ERROR
);
6054 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6060 * An unknown value might some new value that a
6061 * vendor has come up with. It consists of a
6062 * 2-byte length and the bytes in the unknown
6066 n
= value
->unknown
.length
;
6068 if (n
> (IPP_BUF_SIZE
- 2))
6070 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6072 _cupsBufferRelease((char *)buffer
);
6073 return (IPP_STATE_ERROR
);
6076 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6078 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6080 DEBUG_puts("1ippWriteIO: Could not write IPP "
6082 _cupsBufferRelease((char *)buffer
);
6083 return (IPP_STATE_ERROR
);
6089 /* Length of unknown value */
6090 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6091 *bufptr
++ = (ipp_uchar_t
)n
;
6096 memcpy(bufptr
, value
->unknown
.data
, (size_t)n
);
6104 * Write the data out...
6107 if (bufptr
> buffer
)
6109 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6111 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6112 _cupsBufferRelease((char *)buffer
);
6113 return (IPP_STATE_ERROR
);
6116 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6117 (int)(bufptr
- buffer
)));
6121 * If blocking is disabled and we aren't at the end of the attribute
6122 * list, stop here...
6125 if (!blocking
&& ipp
->current
)
6129 if (ipp
->current
== NULL
)
6132 * Done with all of the attributes; add the end-of-attributes
6133 * tag or end-collection attribute...
6138 buffer
[0] = IPP_TAG_END
;
6143 buffer
[0] = IPP_TAG_END_COLLECTION
;
6144 buffer
[1] = 0; /* empty name */
6146 buffer
[3] = 0; /* empty value */
6151 if ((*cb
)(dst
, buffer
, (size_t)n
) < 0)
6153 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6154 _cupsBufferRelease((char *)buffer
);
6155 return (IPP_STATE_ERROR
);
6158 ipp
->state
= IPP_STATE_DATA
;
6162 case IPP_STATE_DATA
:
6166 break; /* anti-compiler-warning-code */
6169 _cupsBufferRelease((char *)buffer
);
6171 return (ipp
->state
);
6176 * 'ipp_add_attr()' - Add a new attribute to the message.
6179 static ipp_attribute_t
* /* O - New attribute */
6180 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6181 const char *name
, /* I - Attribute name or NULL */
6182 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6183 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6184 int num_values
) /* I - Number of values */
6186 int alloc_values
; /* Number of values to allocate */
6187 ipp_attribute_t
*attr
; /* New attribute */
6190 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
));
6193 * Range check input...
6196 if (!ipp
|| num_values
< 0)
6200 * Allocate memory, rounding the allocation up as needed...
6203 if (num_values
<= 1)
6206 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6208 attr
= calloc(sizeof(ipp_attribute_t
) +
6209 (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6214 * Initialize attribute...
6217 DEBUG_printf(("4debug_alloc: %p %s %s%s (%d values)", (void *)attr
, name
, num_values
> 1 ? "1setOf " : "", ippTagString(value_tag
), num_values
));
6220 attr
->name
= _cupsStrAlloc(name
);
6222 attr
->group_tag
= group_tag
;
6223 attr
->value_tag
= value_tag
;
6224 attr
->num_values
= num_values
;
6227 * Add it to the end of the linked list...
6231 ipp
->last
->next
= attr
;
6235 ipp
->prev
= ipp
->last
;
6236 ipp
->last
= ipp
->current
= attr
;
6239 DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr
));
6246 * 'ipp_free_values()' - Free attribute values.
6250 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6251 int element
,/* I - First value to free */
6252 int count
) /* I - Number of values to free */
6254 int i
; /* Looping var */
6255 _ipp_value_t
*value
; /* Current value */
6258 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", (void *)attr
, element
, count
));
6260 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6263 * Free values as needed...
6266 switch (attr
->value_tag
)
6268 case IPP_TAG_TEXTLANG
:
6269 case IPP_TAG_NAMELANG
:
6270 if (element
== 0 && count
== attr
->num_values
&&
6271 attr
->values
[0].string
.language
)
6273 _cupsStrFree(attr
->values
[0].string
.language
);
6274 attr
->values
[0].string
.language
= NULL
;
6276 /* Fall through to other string values */
6280 case IPP_TAG_RESERVED_STRING
:
6281 case IPP_TAG_KEYWORD
:
6283 case IPP_TAG_URISCHEME
:
6284 case IPP_TAG_CHARSET
:
6285 case IPP_TAG_LANGUAGE
:
6286 case IPP_TAG_MIMETYPE
:
6287 for (i
= count
, value
= attr
->values
+ element
;
6291 _cupsStrFree(value
->string
.text
);
6292 value
->string
.text
= NULL
;
6296 case IPP_TAG_UNSUPPORTED_VALUE
:
6297 case IPP_TAG_DEFAULT
:
6298 case IPP_TAG_UNKNOWN
:
6299 case IPP_TAG_NOVALUE
:
6300 case IPP_TAG_NOTSETTABLE
:
6301 case IPP_TAG_DELETEATTR
:
6302 case IPP_TAG_ADMINDEFINE
:
6303 case IPP_TAG_INTEGER
:
6305 case IPP_TAG_BOOLEAN
:
6307 case IPP_TAG_RESOLUTION
:
6308 case IPP_TAG_RANGE
:
6311 case IPP_TAG_BEGIN_COLLECTION
:
6312 for (i
= count
, value
= attr
->values
+ element
;
6316 ippDelete(value
->collection
);
6317 value
->collection
= NULL
;
6321 case IPP_TAG_STRING
:
6323 for (i
= count
, value
= attr
->values
+ element
;
6327 if (value
->unknown
.data
)
6329 free(value
->unknown
.data
);
6330 value
->unknown
.data
= NULL
;
6338 * If we are not freeing values from the end, move the remaining values up...
6341 if ((element
+ count
) < attr
->num_values
)
6342 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6343 (size_t)(attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6345 attr
->num_values
-= count
;
6350 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6352 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6353 * to "ll-cc", "ll-region", and "charset-number", respectively.
6356 static char * /* O - Language code string */
6357 ipp_get_code(const char *value
, /* I - Locale/charset string */
6358 char *buffer
, /* I - String buffer */
6359 size_t bufsize
) /* I - Size of string buffer */
6361 char *bufptr
, /* Pointer into buffer */
6362 *bufend
; /* End of buffer */
6366 * Convert values to lowercase and change _ to - as needed...
6369 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6370 *value
&& bufptr
< bufend
;
6375 *bufptr
++ = (char)_cups_tolower(*value
);
6380 * Return the converted string...
6388 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6390 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6391 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6394 static char * /* O - Language code string */
6395 ipp_lang_code(const char *locale
, /* I - Locale string */
6396 char *buffer
, /* I - String buffer */
6397 size_t bufsize
) /* I - Size of string buffer */
6400 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6403 if (!_cups_strcasecmp(locale
, "c"))
6405 strlcpy(buffer
, "en", bufsize
);
6409 return (ipp_get_code(locale
, buffer
, bufsize
));
6414 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6417 static size_t /* O - Size of IPP message */
6418 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6419 int collection
) /* I - 1 if a collection, 0 otherwise */
6421 int i
; /* Looping var */
6422 size_t bytes
; /* Number of bytes */
6423 ipp_attribute_t
*attr
; /* Current attribute */
6424 ipp_tag_t group
; /* Current group */
6425 _ipp_value_t
*value
; /* Current value */
6428 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp
, collection
));
6432 DEBUG_puts("4ipp_length: Returning 0 bytes");
6437 * Start with 8 bytes for the IPP message header...
6440 bytes
= collection
? 0 : 8;
6443 * Then add the lengths of each attribute...
6446 group
= IPP_TAG_ZERO
;
6448 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6450 if (attr
->group_tag
!= group
&& !collection
)
6452 group
= attr
->group_tag
;
6453 if (group
== IPP_TAG_ZERO
)
6456 bytes
++; /* Group tag */
6462 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6463 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6465 if ((attr
->value_tag
& ~IPP_TAG_CUPS_CONST
) < IPP_TAG_EXTENSION
)
6466 bytes
+= (size_t)attr
->num_values
;/* Value tag for each value */
6468 bytes
+= (size_t)(5 * attr
->num_values
);
6469 /* Value tag for each value */
6470 bytes
+= (size_t)(2 * attr
->num_values
);
6472 bytes
+= strlen(attr
->name
); /* Name */
6473 bytes
+= (size_t)(2 * attr
->num_values
);
6477 bytes
+= 5; /* Add membername overhead */
6479 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6481 case IPP_TAG_UNSUPPORTED_VALUE
:
6482 case IPP_TAG_DEFAULT
:
6483 case IPP_TAG_UNKNOWN
:
6484 case IPP_TAG_NOVALUE
:
6485 case IPP_TAG_NOTSETTABLE
:
6486 case IPP_TAG_DELETEATTR
:
6487 case IPP_TAG_ADMINDEFINE
:
6490 case IPP_TAG_INTEGER
:
6492 bytes
+= (size_t)(4 * attr
->num_values
);
6495 case IPP_TAG_BOOLEAN
:
6496 bytes
+= (size_t)attr
->num_values
;
6501 case IPP_TAG_KEYWORD
:
6503 case IPP_TAG_URISCHEME
:
6504 case IPP_TAG_CHARSET
:
6505 case IPP_TAG_LANGUAGE
:
6506 case IPP_TAG_MIMETYPE
:
6507 for (i
= 0, value
= attr
->values
;
6508 i
< attr
->num_values
;
6510 if (value
->string
.text
)
6511 bytes
+= strlen(value
->string
.text
);
6515 bytes
+= (size_t)(11 * attr
->num_values
);
6518 case IPP_TAG_RESOLUTION
:
6519 bytes
+= (size_t)(9 * attr
->num_values
);
6522 case IPP_TAG_RANGE
:
6523 bytes
+= (size_t)(8 * attr
->num_values
);
6526 case IPP_TAG_TEXTLANG
:
6527 case IPP_TAG_NAMELANG
:
6528 bytes
+= (size_t)(4 * attr
->num_values
);
6529 /* Charset + text length */
6531 for (i
= 0, value
= attr
->values
;
6532 i
< attr
->num_values
;
6535 if (value
->string
.language
)
6536 bytes
+= strlen(value
->string
.language
);
6538 if (value
->string
.text
)
6539 bytes
+= strlen(value
->string
.text
);
6543 case IPP_TAG_BEGIN_COLLECTION
:
6544 for (i
= 0, value
= attr
->values
;
6545 i
< attr
->num_values
;
6547 bytes
+= ipp_length(value
->collection
, 1);
6551 for (i
= 0, value
= attr
->values
;
6552 i
< attr
->num_values
;
6554 bytes
+= (size_t)value
->unknown
.length
;
6560 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6561 * for the "end of collection" tag and return...
6569 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6576 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6579 static ssize_t
/* O - Number of bytes read */
6580 ipp_read_http(http_t
*http
, /* I - Client connection */
6581 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6582 size_t length
) /* I - Total length */
6584 ssize_t tbytes
, /* Total bytes read */
6585 bytes
; /* Bytes read this pass */
6588 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http
, (void *)buffer
, (int)length
));
6591 * Loop until all bytes are read...
6594 for (tbytes
= 0, bytes
= 0;
6595 tbytes
< (int)length
;
6596 tbytes
+= bytes
, buffer
+= bytes
)
6598 DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT
", http->state=%d", CUPS_LLCAST tbytes
, http
->state
));
6600 if (http
->state
== HTTP_STATE_WAITING
)
6603 if (http
->used
== 0 && !http
->blocking
)
6606 * Wait up to 10 seconds for more data on non-blocking sockets...
6609 if (!httpWait(http
, 10000))
6619 else if (http
->used
== 0 && http
->timeout_value
> 0)
6622 * Wait up to timeout seconds for more data on blocking sockets...
6625 if (!httpWait(http
, (int)(1000 * http
->timeout_value
)))
6636 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- (size_t)tbytes
)) < 0)
6641 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6647 else if (bytes
== 0)
6652 * Return the number of bytes read...
6655 if (tbytes
== 0 && bytes
< 0)
6658 DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST tbytes
));
6665 * 'ipp_read_file()' - Read IPP data from a file.
6668 static ssize_t
/* O - Number of bytes read */
6669 ipp_read_file(int *fd
, /* I - File descriptor */
6670 ipp_uchar_t
*buffer
, /* O - Read buffer */
6671 size_t length
) /* I - Number of bytes to read */
6674 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6676 return (read(*fd
, buffer
, length
));
6682 * 'ipp_set_error()' - Set a formatted, localized error string.
6686 ipp_set_error(ipp_status_t status
, /* I - Status code */
6687 const char *format
, /* I - Printf-style error string */
6688 ...) /* I - Additional arguments as needed */
6690 va_list ap
; /* Pointer to additional args */
6691 char buffer
[2048]; /* Message buffer */
6692 cups_lang_t
*lang
= cupsLangDefault();
6693 /* Current language */
6696 va_start(ap
, format
);
6697 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6700 _cupsSetError(status
, buffer
, 0);
6705 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6709 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6710 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6711 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6712 int element
) /* I - Value number (0-based) */
6714 ipp_attribute_t
*temp
, /* New attribute pointer */
6715 *current
, /* Current attribute in list */
6716 *prev
; /* Previous attribute in list */
6717 int alloc_values
; /* Allocated values */
6721 * If we are setting an existing value element, return it...
6726 if (temp
->num_values
<= 1)
6729 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6730 ~(IPP_MAX_VALUES
- 1);
6732 if (element
< alloc_values
)
6734 if (element
>= temp
->num_values
)
6735 temp
->num_values
= element
+ 1;
6737 return (temp
->values
+ element
);
6741 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6742 * values when num_values > 1.
6745 if (alloc_values
< IPP_MAX_VALUES
)
6746 alloc_values
= IPP_MAX_VALUES
;
6748 alloc_values
+= IPP_MAX_VALUES
;
6750 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6754 * Reallocate memory...
6757 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) + (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6759 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6760 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6765 * Zero the new memory...
6768 memset(temp
->values
+ temp
->num_values
, 0, (size_t)(alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6773 * Reset pointers in the list...
6776 #ifndef __clang_analyzer__
6777 DEBUG_printf(("4debug_free: %p %s", (void *)*attr
, temp
->name
));
6778 #endif /* !__clang_analyzer__ */
6779 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
));
6781 if (ipp
->current
== *attr
&& ipp
->prev
)
6784 * Use current "previous" pointer...
6792 * Find this attribute in the linked list...
6795 for (prev
= NULL
, current
= ipp
->attrs
;
6796 current
&& current
!= *attr
;
6797 prev
= current
, current
= current
->next
);
6802 * This is a serious error!
6806 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
6807 _("IPP attribute is not a member of the message."), 1);
6808 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
6818 ipp
->current
= temp
;
6821 if (ipp
->last
== *attr
)
6828 * Return the value element...
6831 if (element
>= temp
->num_values
)
6832 temp
->num_values
= element
+ 1;
6834 return (temp
->values
+ element
);
6839 * 'ipp_write_file()' - Write IPP data to a file.
6842 static ssize_t
/* O - Number of bytes written */
6843 ipp_write_file(int *fd
, /* I - File descriptor */
6844 ipp_uchar_t
*buffer
, /* I - Data to write */
6845 size_t length
) /* I - Number of bytes to write */
6848 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
6850 return (write(*fd
, buffer
, length
));