2 * Internet Printing Protocol functions for CUPS.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
13 * This file is subject to the Apple OS-Developed Software exception.
17 * Include necessary headers...
20 #include "cups-private.h"
31 static ipp_attribute_t
*ipp_add_attr(ipp_t
*ipp
, const char *name
,
32 ipp_tag_t group_tag
, ipp_tag_t value_tag
,
34 static void ipp_free_values(ipp_attribute_t
*attr
, int element
,
36 static char *ipp_get_code(const char *locale
, char *buffer
,
38 __attribute__((nonnull(1,2)));
39 static char *ipp_lang_code(const char *locale
, char *buffer
,
41 __attribute__((nonnull(1,2)));
42 static size_t ipp_length(ipp_t
*ipp
, int collection
);
43 static ssize_t
ipp_read_http(http_t
*http
, ipp_uchar_t
*buffer
,
45 static ssize_t
ipp_read_file(int *fd
, ipp_uchar_t
*buffer
,
47 static void ipp_set_error(ipp_status_t status
, const char *format
,
49 static _ipp_value_t
*ipp_set_value(ipp_t
*ipp
, ipp_attribute_t
**attr
,
51 static ssize_t
ipp_write_file(int *fd
, ipp_uchar_t
*buffer
,
56 * '_cupsBufferGet()' - Get a read/write buffer.
59 char * /* O - Buffer */
60 _cupsBufferGet(size_t size
) /* I - Size required */
62 _cups_buffer_t
*buffer
; /* Current buffer */
63 _cups_globals_t
*cg
= _cupsGlobals();
67 for (buffer
= cg
->cups_buffers
; buffer
; buffer
= buffer
->next
)
68 if (!buffer
->used
&& buffer
->size
>= size
)
73 if ((buffer
= malloc(sizeof(_cups_buffer_t
) + size
- 1)) == NULL
)
76 buffer
->next
= cg
->cups_buffers
;
78 cg
->cups_buffers
= buffer
;
88 * '_cupsBufferRelease()' - Release a read/write buffer.
92 _cupsBufferRelease(char *b
) /* I - Buffer to release */
94 _cups_buffer_t
*buffer
; /* Buffer */
98 * Mark this buffer as unused...
101 buffer
= (_cups_buffer_t
*)(b
- offsetof(_cups_buffer_t
, d
));
107 * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
109 * The @code ipp@ parameter refers to an IPP message previously created using
110 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
112 * The @code group@ parameter specifies the IPP attribute group tag: none
113 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
114 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
115 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
116 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
119 ipp_attribute_t
* /* O - New attribute */
120 ippAddBoolean(ipp_t
*ipp
, /* I - IPP message */
121 ipp_tag_t group
, /* I - IPP group */
122 const char *name
, /* I - Name of attribute */
123 char value
) /* I - Value of attribute */
125 ipp_attribute_t
*attr
; /* New attribute */
128 DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)", (void *)ipp
, group
, ippTagString(group
), name
, value
));
131 * Range check input...
134 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
135 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
139 * Create the attribute...
142 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, 1)) == NULL
)
145 attr
->values
[0].boolean
= value
;
152 * 'ippAddBooleans()' - Add an array of boolean values.
154 * The @code ipp@ parameter refers to an IPP message previously created using
155 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
157 * The @code group@ parameter specifies the IPP attribute group tag: none
158 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
159 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
160 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
161 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
164 ipp_attribute_t
* /* O - New attribute */
165 ippAddBooleans(ipp_t
*ipp
, /* I - IPP message */
166 ipp_tag_t group
, /* I - IPP group */
167 const char *name
, /* I - Name of attribute */
168 int num_values
, /* I - Number of values */
169 const char *values
) /* I - Values */
171 int i
; /* Looping var */
172 ipp_attribute_t
*attr
; /* New attribute */
173 _ipp_value_t
*value
; /* Current value */
176 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
));
179 * Range check input...
182 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
183 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
188 * Create the attribute...
191 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, num_values
)) == NULL
)
196 for (i
= num_values
, value
= attr
->values
;
199 value
->boolean
= *values
++;
207 * 'ippAddCollection()' - Add a collection value.
209 * The @code ipp@ parameter refers to an IPP message previously created using
210 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
212 * The @code group@ parameter specifies the IPP attribute group tag: none
213 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
214 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
215 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
216 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
218 * @since CUPS 1.1.19/OS X 10.3@
221 ipp_attribute_t
* /* O - New attribute */
222 ippAddCollection(ipp_t
*ipp
, /* I - IPP message */
223 ipp_tag_t group
, /* I - IPP group */
224 const char *name
, /* I - Name of attribute */
225 ipp_t
*value
) /* I - Value */
227 ipp_attribute_t
*attr
; /* New attribute */
230 DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
233 * Range check input...
236 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
237 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
241 * Create the attribute...
244 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
, 1)) == NULL
)
247 attr
->values
[0].collection
= value
;
257 * 'ippAddCollections()' - Add an array of collection values.
259 * The @code ipp@ parameter refers to an IPP message previously created using
260 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
262 * The @code group@ parameter specifies the IPP attribute group tag: none
263 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
264 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
265 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
266 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
268 * @since CUPS 1.1.19/OS X 10.3@
271 ipp_attribute_t
* /* O - New attribute */
273 ipp_t
*ipp
, /* I - IPP message */
274 ipp_tag_t group
, /* I - IPP group */
275 const char *name
, /* I - Name of attribute */
276 int num_values
, /* I - Number of values */
277 const ipp_t
**values
) /* I - Values */
279 int i
; /* Looping var */
280 ipp_attribute_t
*attr
; /* New attribute */
281 _ipp_value_t
*value
; /* Current value */
284 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
));
287 * Range check input...
290 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
291 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
296 * Create the attribute...
299 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
,
300 num_values
)) == NULL
)
305 for (i
= num_values
, value
= attr
->values
;
309 value
->collection
= (ipp_t
*)*values
++;
310 value
->collection
->use
++;
319 * 'ippAddDate()' - Add a date attribute to an IPP message.
321 * The @code ipp@ parameter refers to an IPP message previously created using
322 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
324 * The @code group@ parameter specifies the IPP attribute group tag: none
325 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
326 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
327 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
328 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
331 ipp_attribute_t
* /* O - New attribute */
332 ippAddDate(ipp_t
*ipp
, /* I - IPP message */
333 ipp_tag_t group
, /* I - IPP group */
334 const char *name
, /* I - Name of attribute */
335 const ipp_uchar_t
*value
) /* I - Value */
337 ipp_attribute_t
*attr
; /* New attribute */
340 DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)", (void *)ipp
, group
, ippTagString(group
), name
, (void *)value
));
343 * Range check input...
346 if (!ipp
|| !name
|| !value
|| group
< IPP_TAG_ZERO
||
347 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
351 * Create the attribute...
354 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_DATE
, 1)) == NULL
)
357 memcpy(attr
->values
[0].date
, value
, 11);
364 * 'ippAddInteger()' - Add a integer attribute to an IPP message.
366 * The @code ipp@ parameter refers to an IPP message previously created using
367 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
369 * The @code group@ parameter specifies the IPP attribute group tag: none
370 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
371 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
372 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
373 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
375 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
376 * (@code IPP_TAG_INTEGER@).
379 ipp_attribute_t
* /* O - New attribute */
380 ippAddInteger(ipp_t
*ipp
, /* I - IPP message */
381 ipp_tag_t group
, /* I - IPP group */
382 ipp_tag_t value_tag
, /* I - Type of attribute */
383 const char *name
, /* I - Name of attribute */
384 int value
) /* I - Value of attribute */
386 ipp_attribute_t
*attr
; /* New attribute */
389 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
));
391 value_tag
&= IPP_TAG_CUPS_MASK
;
394 * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
398 if (value_tag
>= IPP_TAG_UNSUPPORTED_VALUE
&& value_tag
<= IPP_TAG_ADMINDEFINE
)
399 return (ippAddOutOfBand(ipp
, group
, value_tag
, name
));
402 * Range check input...
406 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
407 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
408 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
))
411 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
412 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
417 * Create the attribute...
420 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
423 attr
->values
[0].integer
= value
;
430 * 'ippAddIntegers()' - Add an array of integer values.
432 * The @code ipp@ parameter refers to an IPP message previously created using
433 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
435 * The @code group@ parameter specifies the IPP attribute group tag: none
436 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
437 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
438 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
439 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
441 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
442 * (@code IPP_TAG_INTEGER@).
445 ipp_attribute_t
* /* O - New attribute */
446 ippAddIntegers(ipp_t
*ipp
, /* I - IPP message */
447 ipp_tag_t group
, /* I - IPP group */
448 ipp_tag_t value_tag
, /* I - Type of attribute */
449 const char *name
, /* I - Name of attribute */
450 int num_values
, /* I - Number of values */
451 const int *values
) /* I - Values */
453 int i
; /* Looping var */
454 ipp_attribute_t
*attr
; /* New attribute */
455 _ipp_value_t
*value
; /* Current value */
458 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
));
460 value_tag
&= IPP_TAG_CUPS_MASK
;
463 * Range check input...
467 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
468 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
469 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
) ||
473 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
474 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
480 * Create the attribute...
483 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
488 for (i
= num_values
, value
= attr
->values
;
491 value
->integer
= *values
++;
499 * 'ippAddOctetString()' - Add an octetString value to an IPP message.
501 * The @code ipp@ parameter refers to an IPP message previously created using
502 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
504 * The @code group@ parameter specifies the IPP attribute group tag: none
505 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
506 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
507 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
508 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
510 * @since CUPS 1.2/OS X 10.5@
513 ipp_attribute_t
* /* O - New attribute */
514 ippAddOctetString(ipp_t
*ipp
, /* I - IPP message */
515 ipp_tag_t group
, /* I - IPP group */
516 const char *name
, /* I - Name of attribute */
517 const void *data
, /* I - octetString data */
518 int datalen
) /* I - Length of data in bytes */
520 ipp_attribute_t
*attr
; /* New attribute */
523 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
524 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
525 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
528 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_STRING
, 1)) == NULL
)
532 * Initialize the attribute data...
535 attr
->values
[0].unknown
.length
= datalen
;
539 if ((attr
->values
[0].unknown
.data
= malloc((size_t)datalen
)) == NULL
)
541 ippDeleteAttribute(ipp
, attr
);
545 memcpy(attr
->values
[0].unknown
.data
, data
, (size_t)datalen
);
549 * Return the new attribute...
557 * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
559 * The @code ipp@ parameter refers to an IPP message previously created using
560 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
562 * The @code group@ parameter specifies the IPP attribute group tag: none
563 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
564 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
565 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
566 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
568 * Supported out-of-band values include unsupported-value
569 * (@code IPP_TAG_UNSUPPORTED_VALUE@), default (@code IPP_TAG_DEFAULT@), unknown
570 * (@code IPP_TAG_UNKNOWN@), no-value (@code IPP_TAG_NOVALUE@), not-settable
571 * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
572 * admin-define (@code IPP_TAG_ADMINDEFINE@).
574 * @since CUPS 1.6/OS X 10.8@
577 ipp_attribute_t
* /* O - New attribute */
578 ippAddOutOfBand(ipp_t
*ipp
, /* I - IPP message */
579 ipp_tag_t group
, /* I - IPP group */
580 ipp_tag_t value_tag
, /* I - Type of attribute */
581 const char *name
) /* I - Name of attribute */
583 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
));
585 value_tag
&= IPP_TAG_CUPS_MASK
;
588 * Range check input...
591 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
592 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
593 (value_tag
!= IPP_TAG_UNSUPPORTED_VALUE
&&
594 value_tag
!= IPP_TAG_DEFAULT
&&
595 value_tag
!= IPP_TAG_UNKNOWN
&&
596 value_tag
!= IPP_TAG_NOVALUE
&&
597 value_tag
!= IPP_TAG_NOTSETTABLE
&&
598 value_tag
!= IPP_TAG_DELETEATTR
&&
599 value_tag
!= IPP_TAG_ADMINDEFINE
))
603 * Create the attribute...
606 return (ipp_add_attr(ipp
, name
, group
, value_tag
, 1));
611 * 'ippAddRange()' - Add a range of values to an IPP message.
613 * The @code ipp@ parameter refers to an IPP message previously created using
614 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
616 * The @code group@ parameter specifies the IPP attribute group tag: none
617 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
618 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
619 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
620 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
622 * The @code lower@ parameter must be less than or equal to the @code upper@ parameter.
625 ipp_attribute_t
* /* O - New attribute */
626 ippAddRange(ipp_t
*ipp
, /* I - IPP message */
627 ipp_tag_t group
, /* I - IPP group */
628 const char *name
, /* I - Name of attribute */
629 int lower
, /* I - Lower value */
630 int upper
) /* I - Upper value */
632 ipp_attribute_t
*attr
; /* New attribute */
635 DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, upper=%d)", (void *)ipp
, group
, ippTagString(group
), name
, lower
, upper
));
638 * Range check input...
641 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
642 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
646 * Create the attribute...
649 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, 1)) == NULL
)
652 attr
->values
[0].range
.lower
= lower
;
653 attr
->values
[0].range
.upper
= upper
;
660 * 'ippAddRanges()' - Add ranges of values to an IPP message.
662 * The @code ipp@ parameter refers to an IPP message previously created using
663 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
665 * The @code group@ parameter specifies the IPP attribute group tag: none
666 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
667 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
668 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
669 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
672 ipp_attribute_t
* /* O - New attribute */
673 ippAddRanges(ipp_t
*ipp
, /* I - IPP message */
674 ipp_tag_t group
, /* I - IPP group */
675 const char *name
, /* I - Name of attribute */
676 int num_values
, /* I - Number of values */
677 const int *lower
, /* I - Lower values */
678 const int *upper
) /* I - Upper values */
680 int i
; /* Looping var */
681 ipp_attribute_t
*attr
; /* New attribute */
682 _ipp_value_t
*value
; /* Current value */
685 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
));
688 * Range check input...
691 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
692 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
697 * Create the attribute...
700 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, num_values
)) == NULL
)
705 for (i
= num_values
, value
= attr
->values
;
709 value
->range
.lower
= *lower
++;
710 value
->range
.upper
= *upper
++;
719 * 'ippAddResolution()' - Add a resolution value to an IPP message.
721 * The @code ipp@ parameter refers to an IPP message previously created using
722 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
724 * The @code group@ parameter specifies the IPP attribute group tag: none
725 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
726 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
727 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
728 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
731 ipp_attribute_t
* /* O - New attribute */
732 ippAddResolution(ipp_t
*ipp
, /* I - IPP message */
733 ipp_tag_t group
, /* I - IPP group */
734 const char *name
, /* I - Name of attribute */
735 ipp_res_t units
, /* I - Units for resolution */
736 int xres
, /* I - X resolution */
737 int yres
) /* I - Y resolution */
739 ipp_attribute_t
*attr
; /* New attribute */
742 DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", units=%d, xres=%d, yres=%d)", (void *)ipp
, group
,
743 ippTagString(group
), name
, units
, xres
, yres
));
746 * Range check input...
749 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
750 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
751 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
||
752 xres
< 0 || yres
< 0)
756 * Create the attribute...
759 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, 1)) == NULL
)
762 attr
->values
[0].resolution
.xres
= xres
;
763 attr
->values
[0].resolution
.yres
= yres
;
764 attr
->values
[0].resolution
.units
= units
;
771 * 'ippAddResolutions()' - Add resolution values to an IPP message.
773 * The @code ipp@ parameter refers to an IPP message previously created using
774 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
776 * The @code group@ parameter specifies the IPP attribute group tag: none
777 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
778 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
779 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
780 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
783 ipp_attribute_t
* /* O - New attribute */
784 ippAddResolutions(ipp_t
*ipp
, /* I - IPP message */
785 ipp_tag_t group
, /* I - IPP group */
786 const char *name
, /* I - Name of attribute */
787 int num_values
,/* I - Number of values */
788 ipp_res_t units
, /* I - Units for resolution */
789 const int *xres
, /* I - X resolutions */
790 const int *yres
) /* I - Y resolutions */
792 int i
; /* Looping var */
793 ipp_attribute_t
*attr
; /* New attribute */
794 _ipp_value_t
*value
; /* Current value */
797 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
));
800 * Range check input...
803 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
804 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
806 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
)
810 * Create the attribute...
813 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, num_values
)) == NULL
)
818 for (i
= num_values
, value
= attr
->values
;
822 value
->resolution
.xres
= *xres
++;
823 value
->resolution
.yres
= *yres
++;
824 value
->resolution
.units
= units
;
833 * 'ippAddSeparator()' - Add a group separator to an IPP message.
835 * The @code ipp@ parameter refers to an IPP message previously created using
836 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
839 ipp_attribute_t
* /* O - New attribute */
840 ippAddSeparator(ipp_t
*ipp
) /* I - IPP message */
842 DEBUG_printf(("ippAddSeparator(ipp=%p)", (void *)ipp
));
845 * Range check input...
852 * Create the attribute...
855 return (ipp_add_attr(ipp
, NULL
, IPP_TAG_ZERO
, IPP_TAG_ZERO
, 0));
860 * 'ippAddString()' - Add a language-encoded string to an IPP message.
862 * The @code ipp@ parameter refers to an IPP message previously created using
863 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
865 * The @code group@ parameter specifies the IPP attribute group tag: none
866 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
867 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
868 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
869 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
871 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
872 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
873 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
874 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
875 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
876 * (@code IPP_TAG_URISCHEME@).
878 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
879 * textWithLanguage string values and must be @code NULL@ for all other string values.
882 ipp_attribute_t
* /* O - New attribute */
883 ippAddString(ipp_t
*ipp
, /* I - IPP message */
884 ipp_tag_t group
, /* I - IPP group */
885 ipp_tag_t value_tag
, /* I - Type of attribute */
886 const char *name
, /* I - Name of attribute */
887 const char *language
, /* I - Language code */
888 const char *value
) /* I - Value */
890 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
891 ipp_attribute_t
*attr
; /* New attribute */
892 char code
[IPP_MAX_LANGUAGE
];
893 /* Charset/language code buffer */
896 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
));
899 * Range check input...
902 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
905 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
906 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
907 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
908 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
)
911 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
912 != (language
!= NULL
))
915 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
916 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
921 * See if we need to map charset, language, or locale values...
924 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
925 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
926 value_tag
= temp_tag
; /* Don't do a fast copy */
927 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
) &&
928 strcmp(value
, ipp_get_code(value
, code
, sizeof(code
))))
929 value_tag
= temp_tag
; /* Don't do a fast copy */
930 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
) &&
931 strcmp(value
, ipp_lang_code(value
, code
, sizeof(code
))))
932 value_tag
= temp_tag
; /* Don't do a fast copy */
935 * Create the attribute...
938 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
942 * Initialize the attribute data...
945 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
947 attr
->values
[0].string
.language
= (char *)language
;
948 attr
->values
[0].string
.text
= (char *)value
;
953 attr
->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
958 if (value_tag
== IPP_TAG_CHARSET
)
959 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_get_code(value
, code
,
961 else if (value_tag
== IPP_TAG_LANGUAGE
)
962 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_lang_code(value
, code
,
965 attr
->values
[0].string
.text
= _cupsStrAlloc(value
);
974 * 'ippAddStringf()' - Add a formatted string to an IPP message.
976 * The @code ipp@ parameter refers to an IPP message previously created using
977 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
979 * The @code group@ parameter specifies the IPP attribute group tag: none
980 * (@code IPP_TAG_ZERO@, for member attributes), document
981 * (@code IPP_TAG_DOCUMENT@), event notification
982 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
983 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
984 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
986 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
987 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
988 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
989 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
990 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
991 * (@code IPP_TAG_URISCHEME@).
993 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
994 * and textWithLanguage string values and must be @code NULL@ for all other
997 * The @code format@ parameter uses formatting characters compatible with the
998 * printf family of standard functions. Additional arguments follow it as
999 * needed. The formatted string is truncated as needed to the maximum length of
1000 * the corresponding value type.
1002 * @since CUPS 1.7/OS X 10.9@
1005 ipp_attribute_t
* /* O - New attribute */
1006 ippAddStringf(ipp_t
*ipp
, /* I - IPP message */
1007 ipp_tag_t group
, /* I - IPP group */
1008 ipp_tag_t value_tag
, /* I - Type of attribute */
1009 const char *name
, /* I - Name of attribute */
1010 const char *language
, /* I - Language code (@code NULL@ for default) */
1011 const char *format
, /* I - Printf-style format string */
1012 ...) /* I - Additional arguments as needed */
1014 ipp_attribute_t
*attr
; /* New attribute */
1015 va_list ap
; /* Argument pointer */
1018 va_start(ap
, format
);
1019 attr
= ippAddStringfv(ipp
, group
, value_tag
, name
, language
, format
, ap
);
1027 * 'ippAddStringfv()' - Add a formatted string to an IPP message.
1029 * The @code ipp@ parameter refers to an IPP message previously created using
1030 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1032 * The @code group@ parameter specifies the IPP attribute group tag: none
1033 * (@code IPP_TAG_ZERO@, for member attributes), document
1034 * (@code IPP_TAG_DOCUMENT@), event notification
1035 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1036 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1037 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1039 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1040 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1041 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1042 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1043 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1044 * (@code IPP_TAG_URISCHEME@).
1046 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1047 * and textWithLanguage string values and must be @code NULL@ for all other
1050 * The @code format@ parameter uses formatting characters compatible with the
1051 * printf family of standard functions. Additional arguments are passed in the
1052 * stdarg pointer @code ap@. The formatted string is truncated as needed to the
1053 * maximum length of the corresponding value type.
1055 * @since CUPS 1.7/OS X 10.9@
1058 ipp_attribute_t
* /* O - New attribute */
1059 ippAddStringfv(ipp_t
*ipp
, /* I - IPP message */
1060 ipp_tag_t group
, /* I - IPP group */
1061 ipp_tag_t value_tag
, /* I - Type of attribute */
1062 const char *name
, /* I - Name of attribute */
1063 const char *language
, /* I - Language code (@code NULL@ for default) */
1064 const char *format
, /* I - Printf-style format string */
1065 va_list ap
) /* I - Additional arguments */
1067 char buffer
[IPP_MAX_TEXT
+ 4];
1068 /* Formatted text string */
1069 ssize_t bytes
, /* Length of formatted value */
1070 max_bytes
; /* Maximum number of bytes for value */
1074 * Range check input...
1077 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1078 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1079 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
1080 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
1084 if ((value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_NAMELANG
)
1085 != (language
!= NULL
))
1089 * Format the string...
1092 if (!strcmp(format
, "%s"))
1095 * Optimize the simple case...
1098 const char *s
= va_arg(ap
, char *);
1103 bytes
= (ssize_t
)strlen(s
);
1104 strlcpy(buffer
, s
, sizeof(buffer
));
1109 * Do a full formatting of the message...
1112 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
1117 * Limit the length of the string...
1124 case IPP_TAG_TEXTLANG
:
1125 max_bytes
= IPP_MAX_TEXT
;
1129 case IPP_TAG_NAMELANG
:
1130 max_bytes
= IPP_MAX_NAME
;
1133 case IPP_TAG_CHARSET
:
1134 max_bytes
= IPP_MAX_CHARSET
;
1137 case IPP_TAG_KEYWORD
:
1138 max_bytes
= IPP_MAX_KEYWORD
;
1141 case IPP_TAG_LANGUAGE
:
1142 max_bytes
= IPP_MAX_LANGUAGE
;
1145 case IPP_TAG_MIMETYPE
:
1146 max_bytes
= IPP_MAX_MIMETYPE
;
1150 max_bytes
= IPP_MAX_URI
;
1153 case IPP_TAG_URISCHEME
:
1154 max_bytes
= IPP_MAX_URISCHEME
;
1158 if (bytes
>= max_bytes
)
1160 char *bufmax
, /* Buffer at max_bytes */
1161 *bufptr
; /* Pointer into buffer */
1163 bufptr
= buffer
+ strlen(buffer
) - 1;
1164 bufmax
= buffer
+ max_bytes
- 1;
1166 while (bufptr
> bufmax
)
1170 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
1181 * Add the formatted string and return...
1184 return (ippAddString(ipp
, group
, value_tag
, name
, language
, buffer
));
1189 * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
1191 * The @code ipp@ parameter refers to an IPP message previously created using
1192 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1194 * The @code group@ parameter specifies the IPP attribute group tag: none
1195 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
1196 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
1197 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
1198 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1200 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1201 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1202 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1203 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1204 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1205 * (@code IPP_TAG_URISCHEME@).
1207 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1208 * textWithLanguage string values and must be @code NULL@ for all other string values.
1211 ipp_attribute_t
* /* O - New attribute */
1213 ipp_t
*ipp
, /* I - IPP message */
1214 ipp_tag_t group
, /* I - IPP group */
1215 ipp_tag_t value_tag
, /* I - Type of attribute */
1216 const char *name
, /* I - Name of attribute */
1217 int num_values
, /* I - Number of values */
1218 const char *language
, /* I - Language code (@code NULL@ for default) */
1219 const char * const *values
) /* I - Values */
1221 int i
; /* Looping var */
1222 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1223 ipp_attribute_t
*attr
; /* New attribute */
1224 _ipp_value_t
*value
; /* Current value */
1225 char code
[32]; /* Language/charset value buffer */
1228 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
));
1231 * Range check input...
1234 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
1237 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1238 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1239 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1240 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
||
1244 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1245 != (language
!= NULL
))
1248 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1249 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1255 * See if we need to map charset, language, or locale values...
1258 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
1259 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1260 value_tag
= temp_tag
; /* Don't do a fast copy */
1261 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
))
1263 for (i
= 0; i
< num_values
; i
++)
1264 if (strcmp(values
[i
], ipp_get_code(values
[i
], code
, sizeof(code
))))
1266 value_tag
= temp_tag
; /* Don't do a fast copy */
1270 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
))
1272 for (i
= 0; i
< num_values
; i
++)
1273 if (strcmp(values
[i
], ipp_lang_code(values
[i
], code
, sizeof(code
))))
1275 value_tag
= temp_tag
; /* Don't do a fast copy */
1281 * Create the attribute...
1284 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
1288 * Initialize the attribute data...
1291 for (i
= num_values
, value
= attr
->values
;
1297 if (value
== attr
->values
)
1299 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1300 value
->string
.language
= (char *)language
;
1302 value
->string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1306 value
->string
.language
= attr
->values
[0].string
.language
;
1311 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1312 value
->string
.text
= (char *)*values
++;
1313 else if (value_tag
== IPP_TAG_CHARSET
)
1314 value
->string
.text
= _cupsStrAlloc(ipp_get_code(*values
++, code
, sizeof(code
)));
1315 else if (value_tag
== IPP_TAG_LANGUAGE
)
1316 value
->string
.text
= _cupsStrAlloc(ipp_lang_code(*values
++, code
, sizeof(code
)));
1318 value
->string
.text
= _cupsStrAlloc(*values
++);
1327 * 'ippContainsInteger()' - Determine whether an attribute contains the
1328 * specified value or is within the list of ranges.
1330 * Returns non-zero when the attribute contains either a matching integer or
1331 * enum value, or the value falls within one of the rangeOfInteger values for
1334 * @since CUPS 1.7/OS X 10.9@
1337 int /* O - 1 on a match, 0 on no match */
1339 ipp_attribute_t
*attr
, /* I - Attribute */
1340 int value
) /* I - Integer/enum value */
1342 int i
; /* Looping var */
1343 _ipp_value_t
*avalue
; /* Current attribute value */
1347 * Range check input...
1353 if (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
&&
1354 attr
->value_tag
!= IPP_TAG_RANGE
)
1361 if (attr
->value_tag
== IPP_TAG_RANGE
)
1363 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1364 if (value
>= avalue
->range
.lower
&& value
<= avalue
->range
.upper
)
1369 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1370 if (value
== avalue
->integer
)
1379 * 'ippContainsString()' - Determine whether an attribute contains the
1380 * specified string value.
1382 * Returns non-zero when the attribute contains a matching charset, keyword,
1383 * language, mimeMediaType, name, text, URI, or URI scheme value.
1385 * @since CUPS 1.7/OS X 10.9@
1388 int /* O - 1 on a match, 0 on no match */
1390 ipp_attribute_t
*attr
, /* I - Attribute */
1391 const char *value
) /* I - String value */
1393 int i
; /* Looping var */
1394 _ipp_value_t
*avalue
; /* Current attribute value */
1397 DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", (void *)attr
, value
));
1400 * Range check input...
1403 if (!attr
|| !value
)
1405 DEBUG_puts("1ippContainsString: Returning 0 (bad input)");
1413 DEBUG_printf(("1ippContainsString: attr %s, %s with %d values.",
1414 attr
->name
, ippTagString(attr
->value_tag
),
1417 switch (attr
->value_tag
& IPP_TAG_CUPS_MASK
)
1419 case IPP_TAG_CHARSET
:
1420 case IPP_TAG_KEYWORD
:
1421 case IPP_TAG_LANGUAGE
:
1422 case IPP_TAG_MIMETYPE
:
1424 case IPP_TAG_NAMELANG
:
1426 case IPP_TAG_TEXTLANG
:
1428 case IPP_TAG_URISCHEME
:
1429 for (i
= attr
->num_values
, avalue
= attr
->values
;
1433 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1434 attr
->num_values
- i
, avalue
->string
.text
));
1436 if (!strcmp(value
, avalue
->string
.text
))
1438 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1447 DEBUG_puts("1ippContainsString: Returning 0 (no match)");
1454 * 'ippCopyAttribute()' - Copy an attribute.
1456 * The specified attribute, @code attr@, is copied to the destination IPP message.
1457 * When @code quickcopy@ is non-zero, a "shallow" reference copy of the attribute is
1458 * created - this should only be done as long as the original source IPP message will
1459 * not be freed for the life of the destination.
1461 * @since CUPS 1.6/OS X 10.8@
1465 ipp_attribute_t
* /* O - New attribute */
1467 ipp_t
*dst
, /* I - Destination IPP message */
1468 ipp_attribute_t
*srcattr
, /* I - Attribute to copy */
1469 int quickcopy
) /* I - 1 for a referenced copy, 0 for normal */
1471 int i
; /* Looping var */
1472 ipp_attribute_t
*dstattr
; /* Destination attribute */
1473 _ipp_value_t
*srcval
, /* Source value */
1474 *dstval
; /* Destination value */
1477 DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", (void *)dst
, (void *)srcattr
, quickcopy
));
1480 * Range check input...
1483 if (!dst
|| !srcattr
)
1490 quickcopy
= quickcopy
? IPP_TAG_CUPS_CONST
: 0;
1492 switch (srcattr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
1495 dstattr
= ippAddSeparator(dst
);
1498 case IPP_TAG_INTEGER
:
1500 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1501 srcattr
->name
, srcattr
->num_values
, NULL
);
1505 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1507 i
--, srcval
++, dstval
++)
1508 dstval
->integer
= srcval
->integer
;
1511 case IPP_TAG_BOOLEAN
:
1512 dstattr
= ippAddBooleans(dst
, srcattr
->group_tag
, srcattr
->name
,
1513 srcattr
->num_values
, NULL
);
1517 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1519 i
--, srcval
++, dstval
++)
1520 dstval
->boolean
= srcval
->boolean
;
1525 case IPP_TAG_KEYWORD
:
1527 case IPP_TAG_URISCHEME
:
1528 case IPP_TAG_CHARSET
:
1529 case IPP_TAG_LANGUAGE
:
1530 case IPP_TAG_MIMETYPE
:
1531 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1532 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1533 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1539 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1540 dstval
= dstattr
->values
;
1542 i
--, srcval
++, dstval
++)
1543 dstval
->string
.text
= srcval
->string
.text
;
1545 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1547 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1548 dstval
= dstattr
->values
;
1550 i
--, srcval
++, dstval
++)
1551 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1555 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1556 dstval
= dstattr
->values
;
1558 i
--, srcval
++, dstval
++)
1559 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1564 if (srcattr
->num_values
!= 1)
1567 dstattr
= ippAddDate(dst
, srcattr
->group_tag
, srcattr
->name
,
1568 srcattr
->values
[0].date
);
1571 case IPP_TAG_RESOLUTION
:
1572 dstattr
= ippAddResolutions(dst
, srcattr
->group_tag
, srcattr
->name
,
1573 srcattr
->num_values
, IPP_RES_PER_INCH
,
1578 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1580 i
--, srcval
++, dstval
++)
1582 dstval
->resolution
.xres
= srcval
->resolution
.xres
;
1583 dstval
->resolution
.yres
= srcval
->resolution
.yres
;
1584 dstval
->resolution
.units
= srcval
->resolution
.units
;
1588 case IPP_TAG_RANGE
:
1589 dstattr
= ippAddRanges(dst
, srcattr
->group_tag
, srcattr
->name
,
1590 srcattr
->num_values
, NULL
, NULL
);
1594 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1596 i
--, srcval
++, dstval
++)
1598 dstval
->range
.lower
= srcval
->range
.lower
;
1599 dstval
->range
.upper
= srcval
->range
.upper
;
1603 case IPP_TAG_TEXTLANG
:
1604 case IPP_TAG_NAMELANG
:
1605 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1606 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1607 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1613 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1614 dstval
= dstattr
->values
;
1616 i
--, srcval
++, dstval
++)
1618 dstval
->string
.language
= srcval
->string
.language
;
1619 dstval
->string
.text
= srcval
->string
.text
;
1622 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1624 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1625 dstval
= dstattr
->values
;
1627 i
--, srcval
++, dstval
++)
1629 if (srcval
== srcattr
->values
)
1630 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1632 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1634 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1639 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1640 dstval
= dstattr
->values
;
1642 i
--, srcval
++, dstval
++)
1644 if (srcval
== srcattr
->values
)
1645 dstval
->string
.language
= _cupsStrRetain(srcval
->string
.language
);
1647 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1649 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1654 case IPP_TAG_BEGIN_COLLECTION
:
1655 dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
,
1656 srcattr
->num_values
, NULL
);
1660 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1662 i
--, srcval
++, dstval
++)
1664 dstval
->collection
= srcval
->collection
;
1665 srcval
->collection
->use
++;
1669 case IPP_TAG_STRING
:
1671 /* TODO: Implement quick copy for unknown/octetString values */
1672 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1673 srcattr
->name
, srcattr
->num_values
, NULL
);
1677 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1679 i
--, srcval
++, dstval
++)
1681 dstval
->unknown
.length
= srcval
->unknown
.length
;
1683 if (dstval
->unknown
.length
> 0)
1685 if ((dstval
->unknown
.data
= malloc((size_t)dstval
->unknown
.length
)) == NULL
)
1686 dstval
->unknown
.length
= 0;
1688 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, (size_t)dstval
->unknown
.length
);
1691 break; /* anti-compiler-warning-code */
1699 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1701 * Zero or more attributes are copied from the source IPP message, @code src@, to the
1702 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1703 * reference copy of the attribute is created - this should only be done as long as the
1704 * original source IPP message will not be freed for the life of the destination.
1706 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1707 * attributes that are copied - the function must return 1 to copy the attribute or
1708 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1711 * @since CUPS 1.6/OS X 10.8@
1714 int /* O - 1 on success, 0 on error */
1716 ipp_t
*dst
, /* I - Destination IPP message */
1717 ipp_t
*src
, /* I - Source IPP message */
1718 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1719 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1720 void *context
) /* I - Context pointer */
1722 ipp_attribute_t
*srcattr
; /* Source attribute */
1725 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)", (void *)dst
, (void *)src
, quickcopy
, (void *)cb
, context
));
1728 * Range check input...
1735 * Loop through source attributes and copy as needed...
1738 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1739 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1740 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1748 * 'ippDateToTime()' - Convert from RFC 1903 Date/Time format to UNIX time
1752 time_t /* O - UNIX time value */
1753 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 1903 date info */
1755 struct tm unixdate
; /* UNIX date/time info */
1756 time_t t
; /* Computed time */
1762 memset(&unixdate
, 0, sizeof(unixdate
));
1765 * RFC-1903 date/time format is:
1767 * Byte(s) Description
1768 * ------- -----------
1769 * 0-1 Year (0 to 65535)
1773 * 5 Minutes (0 to 59)
1774 * 6 Seconds (0 to 60, 60 = "leap second")
1775 * 7 Deciseconds (0 to 9)
1777 * 9 UTC hours (0 to 11)
1778 * 10 UTC minutes (0 to 59)
1781 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1782 unixdate
.tm_mon
= date
[2] - 1;
1783 unixdate
.tm_mday
= date
[3];
1784 unixdate
.tm_hour
= date
[4];
1785 unixdate
.tm_min
= date
[5];
1786 unixdate
.tm_sec
= date
[6];
1788 t
= mktime(&unixdate
);
1791 t
+= date
[9] * 3600 + date
[10] * 60;
1793 t
-= date
[9] * 3600 + date
[10] * 60;
1800 * 'ippDelete()' - Delete an IPP message.
1804 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1806 ipp_attribute_t
*attr
, /* Current attribute */
1807 *next
; /* Next attribute */
1810 DEBUG_printf(("ippDelete(ipp=%p)", (void *)ipp
));
1819 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1823 ipp_free_values(attr
, 0, attr
->num_values
);
1826 _cupsStrFree(attr
->name
);
1836 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1838 * @since CUPS 1.1.19/OS X 10.3@
1843 ipp_t
*ipp
, /* I - IPP message */
1844 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1846 ipp_attribute_t
*current
, /* Current attribute */
1847 *prev
; /* Previous attribute */
1850 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", (void *)ipp
, (void *)attr
, attr
? attr
->name
: "(null)"));
1853 * Range check input...
1860 * Find the attribute in the list...
1865 for (current
= ipp
->attrs
, prev
= NULL
;
1867 prev
= current
, current
= current
->next
)
1868 if (current
== attr
)
1871 * Found it, remove the attribute from the list...
1875 prev
->next
= current
->next
;
1877 ipp
->attrs
= current
->next
;
1879 if (current
== ipp
->last
)
1890 * Free memory used by the attribute...
1893 ipp_free_values(attr
, 0, attr
->num_values
);
1896 _cupsStrFree(attr
->name
);
1903 * 'ippDeleteValues()' - Delete values in an attribute.
1905 * The @code element@ parameter specifies the first value to delete, starting at
1906 * 0. It must be less than the number of values returned by @link ippGetCount@.
1908 * The @code attr@ parameter may be modified as a result of setting the value.
1910 * Deleting all values in an attribute deletes the attribute.
1912 * @since CUPS 1.6/OS X 10.8@
1915 int /* O - 1 on success, 0 on failure */
1917 ipp_t
*ipp
, /* I - IPP message */
1918 ipp_attribute_t
**attr
, /* IO - Attribute */
1919 int element
, /* I - Index of first value to delete (0-based) */
1920 int count
) /* I - Number of values to delete */
1923 * Range check input...
1926 if (!ipp
|| !attr
|| !*attr
||
1927 element
< 0 || element
>= (*attr
)->num_values
|| count
<= 0 ||
1928 (element
+ count
) >= (*attr
)->num_values
)
1932 * If we are deleting all values, just delete the attribute entirely.
1935 if (count
== (*attr
)->num_values
)
1937 ippDeleteAttribute(ipp
, *attr
);
1943 * Otherwise free the values in question and return.
1946 ipp_free_values(*attr
, element
, count
);
1953 * 'ippFindAttribute()' - Find a named attribute in a request.
1955 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1956 * of attribute and member names separated by slashes, for example
1957 * "media-col/media-size".
1960 ipp_attribute_t
* /* O - Matching attribute */
1961 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
1962 const char *name
, /* I - Name of attribute */
1963 ipp_tag_t type
) /* I - Type of attribute */
1965 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
1971 * Reset the current pointer...
1974 ipp
->current
= NULL
;
1978 * Search for the attribute...
1981 return (ippFindNextAttribute(ipp
, name
, type
));
1986 * 'ippFindNextAttribute()' - Find the next named attribute in a request.
1988 * Starting with CUPS 2.0, the attribute name can contain a hierarchical list
1989 * of attribute and member names separated by slashes, for example
1990 * "media-col/media-size".
1993 ipp_attribute_t
* /* O - Matching attribute */
1994 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
1995 const char *name
, /* I - Name of attribute */
1996 ipp_tag_t type
) /* I - Type of attribute */
1998 ipp_attribute_t
*attr
, /* Current atttribute */
1999 *childattr
; /* Child attribute */
2000 ipp_tag_t value_tag
; /* Value tag */
2001 char parent
[1024], /* Parent attribute name */
2002 *child
= NULL
; /* Child attribute name */
2005 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", (void *)ipp
, name
, type
, ippTagString(type
)));
2010 DEBUG_printf(("3ippFindNextAttribute: atend=%d", ipp
->atend
));
2015 if (strchr(name
, '/'))
2018 * Search for child attribute...
2021 strlcpy(parent
, name
, sizeof(parent
));
2022 if ((child
= strchr(parent
, '/')) == NULL
)
2024 DEBUG_puts("3ippFindNextAttribute: Attribute name too long.");
2030 if (ipp
->current
&& ipp
->current
->name
&& ipp
->current
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&& !strcmp(parent
, ipp
->current
->name
))
2032 while (ipp
->curindex
< ipp
->current
->num_values
)
2034 if ((childattr
= ippFindNextAttribute(ipp
->current
->values
[ipp
->curindex
].collection
, child
, type
)) != NULL
)
2038 if (ipp
->curindex
< ipp
->current
->num_values
&& ipp
->current
->values
[ipp
->curindex
].collection
)
2039 ipp
->current
->values
[ipp
->curindex
].collection
->current
= NULL
;
2042 ipp
->prev
= ipp
->current
;
2043 ipp
->current
= ipp
->current
->next
;
2056 ipp
->current
= ipp
->attrs
;
2061 attr
= ipp
->current
;
2063 else if (ipp
->current
)
2065 ipp
->prev
= ipp
->current
;
2066 attr
= ipp
->current
->next
;
2074 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
2076 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", (void *)attr
, attr
->name
));
2078 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2080 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
2081 (value_tag
== type
|| type
== IPP_TAG_ZERO
|| name
== parent
||
2082 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
2083 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
2085 ipp
->current
= attr
;
2087 if (name
== parent
&& attr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
)
2089 int i
; /* Looping var */
2091 for (i
= 0; i
< attr
->num_values
; i
++)
2093 if ((childattr
= ippFindAttribute(attr
->values
[i
].collection
, child
, type
)) != NULL
)
2095 attr
->values
[0].collection
->curindex
= i
;
2105 ipp
->current
= NULL
;
2114 * 'ippFirstAttribute()' - Return the first attribute in the message.
2116 * @since CUPS 1.6/OS X 10.8@
2119 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
2120 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
2123 * Range check input...
2130 * Return the first attribute...
2133 return (ipp
->current
= ipp
->attrs
);
2138 * 'ippGetBoolean()' - Get a boolean value for an attribute.
2140 * The @code element@ parameter specifies which value to get from 0 to
2141 * @link ippGetCount(attr)@ - 1.
2143 * @since CUPS 1.6/OS X 10.8@
2146 int /* O - Boolean value or 0 on error */
2147 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
2148 int element
) /* I - Value number (0-based) */
2151 * Range check input...
2154 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
2155 element
< 0 || element
>= attr
->num_values
)
2159 * Return the value...
2162 return (attr
->values
[element
].boolean
);
2167 * 'ippGetCollection()' - Get a collection value for an attribute.
2169 * The @code element@ parameter specifies which value to get from 0 to
2170 * @link ippGetCount(attr)@ - 1.
2172 * @since CUPS 1.6/OS X 10.8@
2175 ipp_t
* /* O - Collection value or @code NULL@ on error */
2177 ipp_attribute_t
*attr
, /* I - IPP attribute */
2178 int element
) /* I - Value number (0-based) */
2181 * Range check input...
2184 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
2185 element
< 0 || element
>= attr
->num_values
)
2189 * Return the value...
2192 return (attr
->values
[element
].collection
);
2197 * 'ippGetCount()' - Get the number of values in an attribute.
2199 * @since CUPS 1.6/OS X 10.8@
2202 int /* O - Number of values or 0 on error */
2203 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
2206 * Range check input...
2213 * Return the number of values...
2216 return (attr
->num_values
);
2221 * 'ippGetDate()' - Get a date value for an attribute.
2223 * The @code element@ parameter specifies which value to get from 0 to
2224 * @link ippGetCount(attr)@ - 1.
2226 * @since CUPS 1.6/OS X 10.8@
2229 const ipp_uchar_t
* /* O - Date value or @code NULL@ */
2230 ippGetDate(ipp_attribute_t
*attr
, /* I - IPP attribute */
2231 int element
) /* I - Value number (0-based) */
2234 * Range check input...
2237 if (!attr
|| attr
->value_tag
!= IPP_TAG_DATE
||
2238 element
< 0 || element
>= attr
->num_values
)
2242 * Return the value...
2245 return (attr
->values
[element
].date
);
2250 * 'ippGetGroupTag()' - Get the group associated with an attribute.
2252 * @since CUPS 1.6/OS X 10.8@
2255 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
2256 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2259 * Range check input...
2263 return (IPP_TAG_ZERO
);
2266 * Return the group...
2269 return (attr
->group_tag
);
2274 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
2276 * The @code element@ parameter specifies which value to get from 0 to
2277 * @link ippGetCount(attr)@ - 1.
2279 * @since CUPS 1.6/OS X 10.8@
2282 int /* O - Value or 0 on error */
2283 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
2284 int element
) /* I - Value number (0-based) */
2287 * Range check input...
2290 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
2291 element
< 0 || element
>= attr
->num_values
)
2295 * Return the value...
2298 return (attr
->values
[element
].integer
);
2303 * 'ippGetName()' - Get the attribute name.
2305 * @since CUPS 1.6/OS X 10.8@
2308 const char * /* O - Attribute name or @code NULL@ for separators */
2309 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
2312 * Range check input...
2319 * Return the name...
2322 return (attr
->name
);
2327 * 'ippGetOctetString()' - Get an octetString value from an IPP attribute.
2329 * The @code element@ parameter specifies which value to get from 0 to
2330 * @link ippGetCount(attr)@ - 1.
2332 * @since CUPS 1.7/OS X 10.9@
2335 void * /* O - Pointer to octetString data */
2337 ipp_attribute_t
*attr
, /* I - IPP attribute */
2338 int element
, /* I - Value number (0-based) */
2339 int *datalen
) /* O - Length of octetString data */
2342 * Range check input...
2345 if (!attr
|| attr
->value_tag
!= IPP_TAG_STRING
||
2346 element
< 0 || element
>= attr
->num_values
)
2355 * Return the values...
2359 *datalen
= attr
->values
[element
].unknown
.length
;
2361 return (attr
->values
[element
].unknown
.data
);
2366 * 'ippGetOperation()' - Get the operation ID in an IPP message.
2368 * @since CUPS 1.6/OS X 10.8@
2371 ipp_op_t
/* O - Operation ID or 0 on error */
2372 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
2375 * Range check input...
2379 return ((ipp_op_t
)0);
2382 * Return the value...
2385 return (ipp
->request
.op
.operation_id
);
2390 * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
2392 * The @code element@ parameter specifies which value to get from 0 to
2393 * @link ippGetCount(attr)@ - 1.
2395 * @since CUPS 1.6/OS X 10.8@
2398 int /* O - Lower value of range or 0 */
2399 ippGetRange(ipp_attribute_t
*attr
, /* I - IPP attribute */
2400 int element
, /* I - Value number (0-based) */
2401 int *uppervalue
)/* O - Upper value of range */
2404 * Range check input...
2407 if (!attr
|| attr
->value_tag
!= IPP_TAG_RANGE
||
2408 element
< 0 || element
>= attr
->num_values
)
2417 * Return the values...
2421 *uppervalue
= attr
->values
[element
].range
.upper
;
2423 return (attr
->values
[element
].range
.lower
);
2428 * 'ippGetRequestId()' - Get the request ID from an IPP message.
2430 * @since CUPS 1.6/OS X 10.8@
2433 int /* O - Request ID or 0 on error */
2434 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
2437 * Range check input...
2444 * Return the request ID...
2447 return (ipp
->request
.any
.request_id
);
2452 * 'ippGetResolution()' - Get a resolution value for an attribute.
2454 * The @code element@ parameter specifies which value to get from 0 to
2455 * @link ippGetCount(attr)@ - 1.
2457 * @since CUPS 1.6/OS X 10.8@
2460 int /* O - Horizontal/cross feed resolution or 0 */
2462 ipp_attribute_t
*attr
, /* I - IPP attribute */
2463 int element
, /* I - Value number (0-based) */
2464 int *yres
, /* O - Vertical/feed resolution */
2465 ipp_res_t
*units
) /* O - Units for resolution */
2468 * Range check input...
2471 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
2472 element
< 0 || element
>= attr
->num_values
)
2478 *units
= (ipp_res_t
)0;
2484 * Return the value...
2488 *yres
= attr
->values
[element
].resolution
.yres
;
2491 *units
= attr
->values
[element
].resolution
.units
;
2493 return (attr
->values
[element
].resolution
.xres
);
2498 * 'ippGetState()' - Get the IPP message state.
2500 * @since CUPS 1.6/OS X 10.8@
2503 ipp_state_t
/* O - IPP message state value */
2504 ippGetState(ipp_t
*ipp
) /* I - IPP message */
2507 * Range check input...
2511 return (IPP_STATE_IDLE
);
2514 * Return the value...
2517 return (ipp
->state
);
2522 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2524 * @since CUPS 1.6/OS X 10.8@
2527 ipp_status_t
/* O - Status code in IPP message */
2528 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2531 * Range check input...
2535 return (IPP_STATUS_ERROR_INTERNAL
);
2538 * Return the value...
2541 return (ipp
->request
.status
.status_code
);
2546 * 'ippGetString()' - Get the string and optionally the language code for an attribute.
2548 * The @code element@ parameter specifies which value to get from 0 to
2549 * @link ippGetCount(attr)@ - 1.
2551 * @since CUPS 1.6/OS X 10.8@
2555 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2556 int element
, /* I - Value number (0-based) */
2557 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2560 * Range check input...
2563 if (!attr
|| element
< 0 || element
>= attr
->num_values
||
2564 (attr
->value_tag
!= IPP_TAG_TEXTLANG
&& attr
->value_tag
!= IPP_TAG_NAMELANG
&&
2565 (attr
->value_tag
< IPP_TAG_TEXT
|| attr
->value_tag
> IPP_TAG_MIMETYPE
)))
2569 * Return the value...
2573 *language
= attr
->values
[element
].string
.language
;
2575 return (attr
->values
[element
].string
.text
);
2580 * 'ippGetValueTag()' - Get the value tag for an attribute.
2582 * @since CUPS 1.6/OS X 10.8@
2585 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2586 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2589 * Range check input...
2593 return (IPP_TAG_ZERO
);
2596 * Return the value...
2599 return (attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2604 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2606 * @since CUPS 1.6/OS X 10.8@
2609 int /* O - Major version number or 0 on error */
2610 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2611 int *minor
) /* O - Minor version number or @code NULL@ */
2614 * Range check input...
2626 * Return the value...
2630 *minor
= ipp
->request
.any
.version
[1];
2632 return (ipp
->request
.any
.version
[0]);
2637 * 'ippLength()' - Compute the length of an IPP message.
2640 size_t /* O - Size of IPP message */
2641 ippLength(ipp_t
*ipp
) /* I - IPP message */
2643 return (ipp_length(ipp
, 0));
2648 * 'ippNextAttribute()' - Return the next attribute in the message.
2650 * @since CUPS 1.6/OS X 10.8@
2653 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2654 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2657 * Range check input...
2660 if (!ipp
|| !ipp
->current
)
2664 * Return the next attribute...
2667 return (ipp
->current
= ipp
->current
->next
);
2672 * 'ippNew()' - Allocate a new IPP message.
2675 ipp_t
* /* O - New IPP message */
2678 ipp_t
*temp
; /* New IPP message */
2679 _cups_globals_t
*cg
= _cupsGlobals();
2683 DEBUG_puts("ippNew()");
2685 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2688 * Set default version - usually 2.0...
2691 if (cg
->server_version
== 0)
2694 temp
->request
.any
.version
[0] = (ipp_uchar_t
)(cg
->server_version
/ 10);
2695 temp
->request
.any
.version
[1] = (ipp_uchar_t
)(cg
->server_version
% 10);
2699 DEBUG_printf(("1ippNew: Returning %p", (void *)temp
));
2706 * 'ippNewRequest()' - Allocate a new IPP request message.
2708 * The new request message is initialized with the attributes-charset and
2709 * attributes-natural-language attributes added. The
2710 * attributes-natural-language value is derived from the current locale.
2712 * @since CUPS 1.2/OS X 10.5@
2715 ipp_t
* /* O - IPP request message */
2716 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2718 ipp_t
*request
; /* IPP request message */
2719 cups_lang_t
*language
; /* Current language localization */
2720 static int request_id
= 0; /* Current request ID */
2721 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2722 /* Mutex for request ID */
2725 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2728 * Create a new IPP message...
2731 if ((request
= ippNew()) == NULL
)
2735 * Set the operation and request ID...
2738 _cupsMutexLock(&request_mutex
);
2740 request
->request
.op
.operation_id
= op
;
2741 request
->request
.op
.request_id
= ++request_id
;
2743 _cupsMutexUnlock(&request_mutex
);
2746 * Use UTF-8 as the character set...
2749 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2750 "attributes-charset", NULL
, "utf-8");
2753 * Get the language from the current locale...
2756 language
= cupsLangDefault();
2758 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2759 "attributes-natural-language", NULL
, language
->language
);
2762 * Return the new request...
2770 * 'ippNewResponse()' - Allocate a new IPP response message.
2772 * The new response message is initialized with the same version-number,
2773 * request-id, attributes-charset, and attributes-natural-language as the
2774 * provided request message. If the attributes-charset or
2775 * attributes-natural-language attributes are missing from the request,
2776 * "utf-8" and a value derived from the current locale are substituted,
2779 * @since CUPS 1.7/OS X 10.9@
2782 ipp_t
* /* O - IPP response message */
2783 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2785 ipp_t
*response
; /* IPP response message */
2786 ipp_attribute_t
*attr
; /* Current attribute */
2790 * Range check input...
2797 * Create a new IPP message...
2800 if ((response
= ippNew()) == NULL
)
2804 * Copy the request values over to the response...
2807 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2808 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2809 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2812 * The first attribute MUST be attributes-charset...
2815 attr
= request
->attrs
;
2817 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2818 attr
->group_tag
== IPP_TAG_OPERATION
&&
2819 attr
->value_tag
== IPP_TAG_CHARSET
&&
2820 attr
->num_values
== 1)
2823 * Copy charset from request...
2826 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2827 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2832 * Use "utf-8" as the default...
2835 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2836 "attributes-charset", NULL
, "utf-8");
2840 * Then attributes-natural-language...
2846 if (attr
&& attr
->name
&&
2847 !strcmp(attr
->name
, "attributes-natural-language") &&
2848 attr
->group_tag
== IPP_TAG_OPERATION
&&
2849 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2850 attr
->num_values
== 1)
2853 * Copy language from request...
2856 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2857 "attributes-natural-language", NULL
,
2858 attr
->values
[0].string
.text
);
2863 * Use the language from the current locale...
2866 cups_lang_t
*language
= cupsLangDefault();
2867 /* Current locale */
2869 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2870 "attributes-natural-language", NULL
, language
->language
);
2878 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2881 ipp_state_t
/* O - Current state */
2882 ippRead(http_t
*http
, /* I - HTTP connection */
2883 ipp_t
*ipp
) /* I - IPP data */
2885 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
, (void *)http
, (void *)ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2888 return (IPP_STATE_ERROR
);
2890 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
, http
->used
));
2892 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2898 * 'ippReadFile()' - Read data for an IPP message from a file.
2900 * @since CUPS 1.1.19/OS X 10.3@
2903 ipp_state_t
/* O - Current state */
2904 ippReadFile(int fd
, /* I - HTTP data */
2905 ipp_t
*ipp
) /* I - IPP data */
2907 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
2909 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2914 * 'ippReadIO()' - Read data for an IPP message.
2916 * @since CUPS 1.2/OS X 10.5@
2919 ipp_state_t
/* O - Current state */
2920 ippReadIO(void *src
, /* I - Data source */
2921 ipp_iocb_t cb
, /* I - Read callback function */
2922 int blocking
, /* I - Use blocking IO? */
2923 ipp_t
*parent
, /* I - Parent request, if any */
2924 ipp_t
*ipp
) /* I - IPP data */
2926 int n
; /* Length of data */
2927 unsigned char *buffer
, /* Data buffer */
2928 string
[IPP_MAX_TEXT
],
2929 /* Small string buffer */
2930 *bufptr
; /* Pointer into buffer */
2931 ipp_attribute_t
*attr
; /* Current attribute */
2932 ipp_tag_t tag
; /* Current tag */
2933 ipp_tag_t value_tag
; /* Current value tag */
2934 _ipp_value_t
*value
; /* Current value */
2937 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)src
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
2938 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_STATE_ERROR
));
2941 return (IPP_STATE_ERROR
);
2943 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2945 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2946 return (IPP_STATE_ERROR
);
2951 case IPP_STATE_IDLE
:
2952 ipp
->state
++; /* Avoid common problem... */
2954 case IPP_STATE_HEADER
:
2958 * Get the request header...
2961 if ((*cb
)(src
, buffer
, 8) < 8)
2963 DEBUG_puts("1ippReadIO: Unable to read header.");
2964 _cupsBufferRelease((char *)buffer
);
2965 return (IPP_STATE_ERROR
);
2969 * Then copy the request header over...
2972 ipp
->request
.any
.version
[0] = buffer
[0];
2973 ipp
->request
.any
.version
[1] = buffer
[1];
2974 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
2975 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
2976 buffer
[6]) << 8) | buffer
[7];
2978 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
2979 DEBUG_printf(("2ippReadIO: op_status=%04x",
2980 ipp
->request
.any
.op_status
));
2981 DEBUG_printf(("2ippReadIO: request_id=%d",
2982 ipp
->request
.any
.request_id
));
2985 ipp
->state
= IPP_STATE_ATTRIBUTE
;
2986 ipp
->current
= NULL
;
2987 ipp
->curtag
= IPP_TAG_ZERO
;
2988 ipp
->prev
= ipp
->last
;
2991 * If blocking is disabled, stop here...
2997 case IPP_STATE_ATTRIBUTE
:
3000 if ((*cb
)(src
, buffer
, 1) < 1)
3002 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3003 _cupsBufferRelease((char *)buffer
);
3004 return (IPP_STATE_ERROR
);
3007 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3010 * Read this attribute...
3013 tag
= (ipp_tag_t
)buffer
[0];
3014 if (tag
== IPP_TAG_EXTENSION
)
3017 * Read 32-bit "extension" tag...
3020 if ((*cb
)(src
, buffer
, 4) < 1)
3022 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3023 _cupsBufferRelease((char *)buffer
);
3024 return (IPP_STATE_ERROR
);
3027 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
3028 buffer
[2]) << 8) | buffer
[3]);
3030 if (tag
& IPP_TAG_CUPS_CONST
)
3033 * Fail if the high bit is set in the tag...
3036 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
3037 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
3038 _cupsBufferRelease((char *)buffer
);
3039 return (IPP_STATE_ERROR
);
3043 if (tag
== IPP_TAG_END
)
3046 * No more attributes left...
3049 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
3051 ipp
->state
= IPP_STATE_DATA
;
3054 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3057 * Group tag... Set the current group and continue...
3060 if (ipp
->curtag
== tag
)
3061 ipp
->prev
= ippAddSeparator(ipp
);
3062 else if (ipp
->current
)
3063 ipp
->prev
= ipp
->current
;
3066 ipp
->current
= NULL
;
3067 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
, ippTagString(tag
), (void *)ipp
->prev
));
3071 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3072 ippTagString(tag
)));
3078 if ((*cb
)(src
, buffer
, 2) < 2)
3080 DEBUG_puts("1ippReadIO: unable to read name length.");
3081 _cupsBufferRelease((char *)buffer
);
3082 return (IPP_STATE_ERROR
);
3085 n
= (buffer
[0] << 8) | buffer
[1];
3087 if (n
>= IPP_BUF_SIZE
)
3089 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3090 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3091 _cupsBufferRelease((char *)buffer
);
3092 return (IPP_STATE_ERROR
);
3095 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3097 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3098 tag
!= IPP_TAG_END_COLLECTION
)
3101 * More values for current attribute...
3104 if (ipp
->current
== NULL
)
3106 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3107 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3108 _cupsBufferRelease((char *)buffer
);
3109 return (IPP_STATE_ERROR
);
3112 attr
= ipp
->current
;
3113 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3116 * Make sure we aren't adding a new value of a different
3120 if (value_tag
== IPP_TAG_ZERO
)
3123 * Setting the value of a collection member...
3126 attr
->value_tag
= tag
;
3128 else if (value_tag
== IPP_TAG_TEXTLANG
||
3129 value_tag
== IPP_TAG_NAMELANG
||
3130 (value_tag
>= IPP_TAG_TEXT
&&
3131 value_tag
<= IPP_TAG_MIMETYPE
))
3134 * String values can sometimes come across in different
3135 * forms; accept sets of differing values...
3138 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3139 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3140 tag
!= IPP_TAG_NOVALUE
)
3142 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3143 _("IPP 1setOf attribute with incompatible value "
3145 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3146 value_tag
, ippTagString(value_tag
), tag
,
3147 ippTagString(tag
)));
3148 _cupsBufferRelease((char *)buffer
);
3149 return (IPP_STATE_ERROR
);
3152 if (value_tag
!= tag
)
3154 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3155 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3156 ippSetValueTag(ipp
, &attr
, tag
);
3159 else if (value_tag
== IPP_TAG_INTEGER
||
3160 value_tag
== IPP_TAG_RANGE
)
3163 * Integer and rangeOfInteger values can sometimes be mixed; accept
3164 * sets of differing values...
3167 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3169 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3170 _("IPP 1setOf attribute with incompatible value "
3172 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3173 value_tag
, ippTagString(value_tag
), tag
,
3174 ippTagString(tag
)));
3175 _cupsBufferRelease((char *)buffer
);
3176 return (IPP_STATE_ERROR
);
3179 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3182 * Convert integer values to rangeOfInteger values...
3185 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3186 "rangeOfInteger.", attr
->name
));
3187 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3190 else if (value_tag
!= tag
)
3192 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3193 _("IPP 1setOf attribute with incompatible value "
3195 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3196 value_tag
, ippTagString(value_tag
), tag
,
3197 ippTagString(tag
)));
3198 _cupsBufferRelease((char *)buffer
);
3199 return (IPP_STATE_ERROR
);
3203 * Finally, reallocate the attribute array as needed...
3206 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3208 _cupsBufferRelease((char *)buffer
);
3209 return (IPP_STATE_ERROR
);
3212 else if (tag
== IPP_TAG_MEMBERNAME
)
3215 * Name must be length 0!
3220 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3221 DEBUG_puts("1ippReadIO: member name not empty.");
3222 _cupsBufferRelease((char *)buffer
);
3223 return (IPP_STATE_ERROR
);
3227 ipp
->prev
= ipp
->current
;
3229 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3232 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3233 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3234 _cupsBufferRelease((char *)buffer
);
3235 return (IPP_STATE_ERROR
);
3238 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p", (void *)ipp
->current
, (void *)ipp
->prev
));
3240 value
= attr
->values
;
3242 else if (tag
!= IPP_TAG_END_COLLECTION
)
3245 * New attribute; read the name and add it...
3248 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3250 DEBUG_puts("1ippReadIO: unable to read name.");
3251 _cupsBufferRelease((char *)buffer
);
3252 return (IPP_STATE_ERROR
);
3258 ipp
->prev
= ipp
->current
;
3260 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3263 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3264 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3265 _cupsBufferRelease((char *)buffer
);
3266 return (IPP_STATE_ERROR
);
3269 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, ipp->prev=%p", buffer
, (void *)ipp
->current
, (void *)ipp
->prev
));
3271 value
= attr
->values
;
3279 if ((*cb
)(src
, buffer
, 2) < 2)
3281 DEBUG_puts("1ippReadIO: unable to read value length.");
3282 _cupsBufferRelease((char *)buffer
);
3283 return (IPP_STATE_ERROR
);
3286 n
= (buffer
[0] << 8) | buffer
[1];
3287 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3289 if (n
>= IPP_BUF_SIZE
)
3291 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3292 _("IPP value larger than 32767 bytes."), 1);
3293 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3294 _cupsBufferRelease((char *)buffer
);
3295 return (IPP_STATE_ERROR
);
3300 case IPP_TAG_INTEGER
:
3304 if (tag
== IPP_TAG_INTEGER
)
3305 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3306 _("IPP integer value not 4 bytes."), 1);
3308 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3309 _("IPP enum value not 4 bytes."), 1);
3310 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3311 _cupsBufferRelease((char *)buffer
);
3312 return (IPP_STATE_ERROR
);
3315 if ((*cb
)(src
, buffer
, 4) < 4)
3317 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3318 _cupsBufferRelease((char *)buffer
);
3319 return (IPP_STATE_ERROR
);
3322 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3325 if (attr
->value_tag
== IPP_TAG_RANGE
)
3326 value
->range
.lower
= value
->range
.upper
= n
;
3331 case IPP_TAG_BOOLEAN
:
3334 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3336 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3337 _cupsBufferRelease((char *)buffer
);
3338 return (IPP_STATE_ERROR
);
3341 if ((*cb
)(src
, buffer
, 1) < 1)
3343 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3344 _cupsBufferRelease((char *)buffer
);
3345 return (IPP_STATE_ERROR
);
3348 value
->boolean
= (char)buffer
[0];
3351 case IPP_TAG_NOVALUE
:
3352 case IPP_TAG_NOTSETTABLE
:
3353 case IPP_TAG_DELETEATTR
:
3354 case IPP_TAG_ADMINDEFINE
:
3356 * These value types are not supposed to have values, however
3357 * some vendors (Brother) do not implement IPP correctly and so
3358 * we need to map non-empty values to text...
3361 if (attr
->value_tag
== tag
)
3366 attr
->value_tag
= IPP_TAG_TEXT
;
3371 case IPP_TAG_KEYWORD
:
3373 case IPP_TAG_URISCHEME
:
3374 case IPP_TAG_CHARSET
:
3375 case IPP_TAG_LANGUAGE
:
3376 case IPP_TAG_MIMETYPE
:
3379 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3381 DEBUG_puts("1ippReadIO: unable to read string value.");
3382 _cupsBufferRelease((char *)buffer
);
3383 return (IPP_STATE_ERROR
);
3388 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3389 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3395 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3396 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3397 _cupsBufferRelease((char *)buffer
);
3398 return (IPP_STATE_ERROR
);
3401 if ((*cb
)(src
, value
->date
, 11) < 11)
3403 DEBUG_puts("1ippReadIO: Unable to read date value.");
3404 _cupsBufferRelease((char *)buffer
);
3405 return (IPP_STATE_ERROR
);
3409 case IPP_TAG_RESOLUTION
:
3412 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3413 _("IPP resolution value not 9 bytes."), 1);
3414 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3415 _cupsBufferRelease((char *)buffer
);
3416 return (IPP_STATE_ERROR
);
3419 if ((*cb
)(src
, buffer
, 9) < 9)
3421 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3422 _cupsBufferRelease((char *)buffer
);
3423 return (IPP_STATE_ERROR
);
3426 value
->resolution
.xres
=
3427 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3429 value
->resolution
.yres
=
3430 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3432 value
->resolution
.units
=
3433 (ipp_res_t
)buffer
[8];
3436 case IPP_TAG_RANGE
:
3439 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3440 _("IPP rangeOfInteger value not 8 bytes."), 1);
3441 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3443 _cupsBufferRelease((char *)buffer
);
3444 return (IPP_STATE_ERROR
);
3447 if ((*cb
)(src
, buffer
, 8) < 8)
3449 DEBUG_puts("1ippReadIO: Unable to read range value.");
3450 _cupsBufferRelease((char *)buffer
);
3451 return (IPP_STATE_ERROR
);
3454 value
->range
.lower
=
3455 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3457 value
->range
.upper
=
3458 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3462 case IPP_TAG_TEXTLANG
:
3463 case IPP_TAG_NAMELANG
:
3466 if (tag
== IPP_TAG_TEXTLANG
)
3467 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3468 _("IPP textWithLanguage value less than "
3469 "minimum 4 bytes."), 1);
3471 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3472 _("IPP nameWithLanguage value less than "
3473 "minimum 4 bytes."), 1);
3474 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3476 _cupsBufferRelease((char *)buffer
);
3477 return (IPP_STATE_ERROR
);
3480 if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3482 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3484 _cupsBufferRelease((char *)buffer
);
3485 return (IPP_STATE_ERROR
);
3491 * text-with-language and name-with-language are composite
3500 n
= (bufptr
[0] << 8) | bufptr
[1];
3502 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) || n
>= (int)sizeof(string
))
3504 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3505 _("IPP language length overflows value."), 1);
3506 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3508 _cupsBufferRelease((char *)buffer
);
3509 return (IPP_STATE_ERROR
);
3511 else if (n
>= IPP_MAX_LANGUAGE
)
3513 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3514 _("IPP language length too large."), 1);
3515 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3517 _cupsBufferRelease((char *)buffer
);
3518 return (IPP_STATE_ERROR
);
3521 memcpy(string
, bufptr
+ 2, (size_t)n
);
3524 value
->string
.language
= _cupsStrAlloc((char *)string
);
3527 n
= (bufptr
[0] << 8) | bufptr
[1];
3529 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3531 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3532 _("IPP string length overflows value."), 1);
3533 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3534 _cupsBufferRelease((char *)buffer
);
3535 return (IPP_STATE_ERROR
);
3538 bufptr
[2 + n
] = '\0';
3539 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3542 case IPP_TAG_BEGIN_COLLECTION
:
3544 * Oh, boy, here comes a collection value, so read it...
3547 value
->collection
= ippNew();
3551 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3552 _("IPP begCollection value not 0 bytes."), 1);
3553 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3555 _cupsBufferRelease((char *)buffer
);
3556 return (IPP_STATE_ERROR
);
3559 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3561 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3562 _cupsBufferRelease((char *)buffer
);
3563 return (IPP_STATE_ERROR
);
3567 case IPP_TAG_END_COLLECTION
:
3568 _cupsBufferRelease((char *)buffer
);
3572 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3573 _("IPP endCollection value not 0 bytes."), 1);
3574 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3576 return (IPP_STATE_ERROR
);
3579 DEBUG_puts("1ippReadIO: endCollection tag...");
3580 return (ipp
->state
= IPP_STATE_DATA
);
3582 case IPP_TAG_MEMBERNAME
:
3584 * The value the name of the member in the collection, which
3585 * we need to carry over...
3590 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3591 _("IPP memberName with no attribute."), 1);
3592 DEBUG_puts("1ippReadIO: Member name without attribute.");
3593 _cupsBufferRelease((char *)buffer
);
3594 return (IPP_STATE_ERROR
);
3598 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3599 _("IPP memberName value is empty."), 1);
3600 DEBUG_puts("1ippReadIO: Empty member name value.");
3601 _cupsBufferRelease((char *)buffer
);
3602 return (IPP_STATE_ERROR
);
3604 else if ((*cb
)(src
, buffer
, (size_t)n
) < n
)
3606 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3607 _cupsBufferRelease((char *)buffer
);
3608 return (IPP_STATE_ERROR
);
3612 attr
->name
= _cupsStrAlloc((char *)buffer
);
3615 * Since collection members are encoded differently than
3616 * regular attributes, make sure we don't start with an
3620 attr
->num_values
--;
3622 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3625 default : /* Other unsupported values */
3626 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3628 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3629 _("IPP octetString length too large."), 1);
3630 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3632 _cupsBufferRelease((char *)buffer
);
3633 return (IPP_STATE_ERROR
);
3636 value
->unknown
.length
= n
;
3640 if ((value
->unknown
.data
= malloc((size_t)n
)) == NULL
)
3642 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3643 DEBUG_puts("1ippReadIO: Unable to allocate value");
3644 _cupsBufferRelease((char *)buffer
);
3645 return (IPP_STATE_ERROR
);
3648 if ((*cb
)(src
, value
->unknown
.data
, (size_t)n
) < n
)
3650 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3651 _cupsBufferRelease((char *)buffer
);
3652 return (IPP_STATE_ERROR
);
3656 value
->unknown
.data
= NULL
;
3661 * If blocking is disabled, stop here...
3669 case IPP_STATE_DATA
:
3673 break; /* anti-compiler-warning-code */
3676 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3677 _cupsBufferRelease((char *)buffer
);
3679 return (ipp
->state
);
3684 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3686 * The @code ipp@ parameter refers to an IPP message previously created using
3687 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3689 * The @code attr@ parameter may be modified as a result of setting the value.
3691 * The @code element@ parameter specifies which value to set from 0 to
3692 * @link ippGetCount(attr)@.
3694 * @since CUPS 1.6/OS X 10.8@
3697 int /* O - 1 on success, 0 on failure */
3698 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3699 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3700 int element
, /* I - Value number (0-based) */
3701 int boolvalue
)/* I - Boolean value */
3703 _ipp_value_t
*value
; /* Current value */
3707 * Range check input...
3710 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3711 element
< 0 || element
> (*attr
)->num_values
)
3715 * Set the value and return...
3718 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3719 value
->boolean
= (char)boolvalue
;
3721 return (value
!= NULL
);
3726 * 'ippSetCollection()' - Set a collection value in an attribute.
3728 * The @code ipp@ parameter refers to an IPP message previously created using
3729 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3731 * The @code attr@ parameter may be modified as a result of setting the value.
3733 * The @code element@ parameter specifies which value to set from 0 to
3734 * @link ippGetCount(attr)@.
3736 * @since CUPS 1.6/OS X 10.8@
3739 int /* O - 1 on success, 0 on failure */
3741 ipp_t
*ipp
, /* I - IPP message */
3742 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3743 int element
, /* I - Value number (0-based) */
3744 ipp_t
*colvalue
) /* I - Collection value */
3746 _ipp_value_t
*value
; /* Current value */
3750 * Range check input...
3753 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3754 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3758 * Set the value and return...
3761 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3763 if (value
->collection
)
3764 ippDelete(value
->collection
);
3766 value
->collection
= colvalue
;
3770 return (value
!= NULL
);
3775 * 'ippSetDate()' - Set a date value in an attribute.
3777 * The @code ipp@ parameter refers to an IPP message previously created using
3778 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3780 * The @code attr@ parameter may be modified as a result of setting the value.
3782 * The @code element@ parameter specifies which value to set from 0 to
3783 * @link ippGetCount(attr)@.
3785 * @since CUPS 1.6/OS X 10.8@
3788 int /* O - 1 on success, 0 on failure */
3789 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3790 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3791 int element
, /* I - Value number (0-based) */
3792 const ipp_uchar_t
*datevalue
)/* I - Date value */
3794 _ipp_value_t
*value
; /* Current value */
3798 * Range check input...
3801 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3802 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3806 * Set the value and return...
3809 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3810 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3812 return (value
!= NULL
);
3817 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3819 * The @code ipp@ parameter refers to an IPP message previously created using
3820 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3822 * The @code attr@ parameter may be modified as a result of setting the value.
3824 * The @code group@ parameter specifies the IPP attribute group tag: none
3825 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3826 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3827 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3828 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3830 * @since CUPS 1.6/OS X 10.8@
3833 int /* O - 1 on success, 0 on failure */
3835 ipp_t
*ipp
, /* I - IPP message */
3836 ipp_attribute_t
**attr
, /* IO - Attribute */
3837 ipp_tag_t group_tag
) /* I - Group tag */
3840 * Range check input - group tag must be 0x01 to 0x0F, per RFC 2911...
3843 if (!ipp
|| !attr
|| !*attr
||
3844 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3845 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3849 * Set the group tag and return...
3852 (*attr
)->group_tag
= group_tag
;
3859 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3861 * The @code ipp@ parameter refers to an IPP message previously created using
3862 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3864 * The @code attr@ parameter may be modified as a result of setting the value.
3866 * The @code element@ parameter specifies which value to set from 0 to
3867 * @link ippGetCount(attr)@.
3869 * @since CUPS 1.6/OS X 10.8@
3872 int /* O - 1 on success, 0 on failure */
3873 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3874 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3875 int element
, /* I - Value number (0-based) */
3876 int intvalue
) /* I - Integer/enum value */
3878 _ipp_value_t
*value
; /* Current value */
3882 * Range check input...
3885 if (!ipp
|| !attr
|| !*attr
||
3886 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3887 element
< 0 || element
> (*attr
)->num_values
)
3891 * Set the value and return...
3894 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3895 value
->integer
= intvalue
;
3897 return (value
!= NULL
);
3902 * 'ippSetName()' - Set the name of an 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 * @since CUPS 1.6/OS X 10.8@
3912 int /* O - 1 on success, 0 on failure */
3913 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3914 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3915 const char *name
) /* I - Attribute name */
3917 char *temp
; /* Temporary name value */
3921 * Range check input...
3924 if (!ipp
|| !attr
|| !*attr
)
3928 * Set the value and return...
3931 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3934 _cupsStrFree((*attr
)->name
);
3936 (*attr
)->name
= temp
;
3939 return (temp
!= NULL
);
3944 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
3946 * The @code ipp@ parameter refers to an IPP message previously created using
3947 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3949 * The @code attr@ parameter may be modified as a result of setting the value.
3951 * The @code element@ parameter specifies which value to set from 0 to
3952 * @link ippGetCount(attr)@.
3954 * @since CUPS 1.7/OS X 10.9@
3957 int /* O - 1 on success, 0 on failure */
3959 ipp_t
*ipp
, /* I - IPP message */
3960 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3961 int element
, /* I - Value number (0-based) */
3962 const void *data
, /* I - Pointer to octetString data */
3963 int datalen
) /* I - Length of octetString data */
3965 _ipp_value_t
*value
; /* Current value */
3969 * Range check input...
3972 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_STRING
||
3973 element
< 0 || element
> (*attr
)->num_values
||
3974 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
3978 * Set the value and return...
3981 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3983 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
3986 * Just copy the pointer...
3989 value
->unknown
.data
= (void *)data
;
3990 value
->unknown
.length
= datalen
;
3998 if (value
->unknown
.data
)
4001 * Free previous data...
4004 free(value
->unknown
.data
);
4006 value
->unknown
.data
= NULL
;
4007 value
->unknown
.length
= 0;
4012 void *temp
; /* Temporary data pointer */
4014 if ((temp
= malloc((size_t)datalen
)) != NULL
)
4016 memcpy(temp
, data
, (size_t)datalen
);
4018 value
->unknown
.data
= temp
;
4019 value
->unknown
.length
= datalen
;
4027 return (value
!= NULL
);
4032 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
4034 * The @code ipp@ parameter refers to an IPP message previously created using
4035 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4037 * @since CUPS 1.6/OS X 10.8@
4040 int /* O - 1 on success, 0 on failure */
4041 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
4042 ipp_op_t op
) /* I - Operation ID */
4045 * Range check input...
4052 * Set the operation and return...
4055 ipp
->request
.op
.operation_id
= op
;
4062 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4064 * The @code ipp@ parameter refers to an IPP message previously created using
4065 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4067 * The @code attr@ parameter may be modified as a result of setting the value.
4069 * The @code element@ parameter specifies which value to set from 0 to
4070 * @link ippGetCount(attr)@.
4072 * @since CUPS 1.6/OS X 10.8@
4075 int /* O - 1 on success, 0 on failure */
4076 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4077 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4078 int element
, /* I - Value number (0-based) */
4079 int lowervalue
, /* I - Lower bound for range */
4080 int uppervalue
) /* I - Upper bound for range */
4082 _ipp_value_t
*value
; /* Current value */
4086 * Range check input...
4089 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4090 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4094 * Set the value and return...
4097 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4099 value
->range
.lower
= lowervalue
;
4100 value
->range
.upper
= uppervalue
;
4103 return (value
!= NULL
);
4108 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4110 * The @code ipp@ parameter refers to an IPP message previously created using
4111 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4113 * The @code request_id@ parameter must be greater than 0.
4115 * @since CUPS 1.6/OS X 10.8@
4118 int /* O - 1 on success, 0 on failure */
4119 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4120 int request_id
) /* I - Request ID */
4123 * Range check input; not checking request_id values since ipptool wants to send
4124 * invalid values for conformance testing and a bad request_id does not affect the
4125 * encoding of a message...
4132 * Set the request ID and return...
4135 ipp
->request
.any
.request_id
= request_id
;
4142 * 'ippSetResolution()' - Set a resolution value in an attribute.
4144 * The @code ipp@ parameter refers to an IPP message previously created using
4145 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4147 * The @code attr@ parameter may be modified as a result of setting the value.
4149 * The @code element@ parameter specifies which value to set from 0 to
4150 * @link ippGetCount(attr)@.
4152 * @since CUPS 1.6/OS X 10.8@
4155 int /* O - 1 on success, 0 on failure */
4157 ipp_t
*ipp
, /* I - IPP message */
4158 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4159 int element
, /* I - Value number (0-based) */
4160 ipp_res_t unitsvalue
, /* I - Resolution units */
4161 int xresvalue
, /* I - Horizontal/cross feed resolution */
4162 int yresvalue
) /* I - Vertical/feed resolution */
4164 _ipp_value_t
*value
; /* Current value */
4168 * Range check input...
4171 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4172 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4173 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4177 * Set the value and return...
4180 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4182 value
->resolution
.units
= unitsvalue
;
4183 value
->resolution
.xres
= xresvalue
;
4184 value
->resolution
.yres
= yresvalue
;
4187 return (value
!= NULL
);
4192 * 'ippSetState()' - Set the current state of the IPP message.
4194 * @since CUPS 1.6/OS X 10.8@
4197 int /* O - 1 on success, 0 on failure */
4198 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4199 ipp_state_t state
) /* I - IPP state value */
4202 * Range check input...
4209 * Set the state and return...
4213 ipp
->current
= NULL
;
4220 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4222 * The @code ipp@ parameter refers to an IPP message previously created using
4223 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4225 * @since CUPS 1.6/OS X 10.8@
4228 int /* O - 1 on success, 0 on failure */
4229 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4230 ipp_status_t status
) /* I - Status code */
4233 * Range check input...
4240 * Set the status code and return...
4243 ipp
->request
.status
.status_code
= status
;
4250 * 'ippSetString()' - Set a string value in an attribute.
4252 * The @code ipp@ parameter refers to an IPP message previously created using
4253 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4255 * The @code attr@ parameter may be modified as a result of setting the value.
4257 * The @code element@ parameter specifies which value to set from 0 to
4258 * @link ippGetCount(attr)@.
4260 * @since CUPS 1.6/OS X 10.8@
4263 int /* O - 1 on success, 0 on failure */
4264 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4265 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4266 int element
, /* I - Value number (0-based) */
4267 const char *strvalue
) /* I - String value */
4269 char *temp
; /* Temporary string */
4270 _ipp_value_t
*value
; /* Current value */
4274 * Range check input...
4277 if (!ipp
|| !attr
|| !*attr
||
4278 ((*attr
)->value_tag
!= IPP_TAG_TEXTLANG
&&
4279 (*attr
)->value_tag
!= IPP_TAG_NAMELANG
&&
4280 ((*attr
)->value_tag
< IPP_TAG_TEXT
||
4281 (*attr
)->value_tag
> IPP_TAG_MIMETYPE
)) ||
4282 element
< 0 || element
> (*attr
)->num_values
|| !strvalue
)
4286 * Set the value and return...
4289 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4292 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4294 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4295 value
->string
.text
= (char *)strvalue
;
4296 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4298 if (value
->string
.text
)
4299 _cupsStrFree(value
->string
.text
);
4301 value
->string
.text
= temp
;
4307 return (value
!= NULL
);
4312 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4314 * The @code ipp@ parameter refers to an IPP message previously created using
4315 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4317 * The @code attr@ parameter may be modified as a result of setting the value.
4319 * The @code element@ parameter specifies which value to set from 0 to
4320 * @link ippGetCount(attr)@.
4322 * The @code format@ parameter uses formatting characters compatible with the
4323 * printf family of standard functions. Additional arguments follow it as
4324 * needed. The formatted string is truncated as needed to the maximum length of
4325 * the corresponding value type.
4327 * @since CUPS 1.7/OS X 10.9@
4330 int /* O - 1 on success, 0 on failure */
4331 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4332 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4333 int element
, /* I - Value number (0-based) */
4334 const char *format
, /* I - Printf-style format string */
4335 ...) /* I - Additional arguments as needed */
4337 int ret
; /* Return value */
4338 va_list ap
; /* Pointer to additional arguments */
4341 va_start(ap
, format
);
4342 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4350 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4352 * The @code ipp@ parameter refers to an IPP message previously created using
4353 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4355 * The @code attr@ parameter may be modified as a result of setting the value.
4357 * The @code element@ parameter specifies which value to set from 0 to
4358 * @link ippGetCount(attr)@.
4360 * The @code format@ parameter uses formatting characters compatible with the
4361 * printf family of standard functions. Additional arguments follow it as
4362 * needed. The formatted string is truncated as needed to the maximum length of
4363 * the corresponding value type.
4365 * @since CUPS 1.7/OS X 10.9@
4368 int /* O - 1 on success, 0 on failure */
4369 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4370 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4371 int element
, /* I - Value number (0-based) */
4372 const char *format
, /* I - Printf-style format string */
4373 va_list ap
) /* I - Pointer to additional arguments */
4375 ipp_tag_t value_tag
; /* Value tag */
4376 char buffer
[IPP_MAX_TEXT
+ 4];
4377 /* Formatted text string */
4378 ssize_t bytes
, /* Length of formatted value */
4379 max_bytes
; /* Maximum number of bytes for value */
4383 * Range check input...
4387 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4389 value_tag
= IPP_TAG_ZERO
;
4391 if (!ipp
|| !attr
|| !*attr
||
4392 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4393 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4398 * Format the string...
4401 if (!strcmp(format
, "%s"))
4404 * Optimize the simple case...
4407 const char *s
= va_arg(ap
, char *);
4412 bytes
= (ssize_t
)strlen(s
);
4413 strlcpy(buffer
, s
, sizeof(buffer
));
4418 * Do a full formatting of the message...
4421 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4426 * Limit the length of the string...
4433 case IPP_TAG_TEXTLANG
:
4434 max_bytes
= IPP_MAX_TEXT
;
4438 case IPP_TAG_NAMELANG
:
4439 max_bytes
= IPP_MAX_NAME
;
4442 case IPP_TAG_CHARSET
:
4443 max_bytes
= IPP_MAX_CHARSET
;
4446 case IPP_TAG_KEYWORD
:
4447 max_bytes
= IPP_MAX_KEYWORD
;
4450 case IPP_TAG_LANGUAGE
:
4451 max_bytes
= IPP_MAX_LANGUAGE
;
4454 case IPP_TAG_MIMETYPE
:
4455 max_bytes
= IPP_MAX_MIMETYPE
;
4459 max_bytes
= IPP_MAX_URI
;
4462 case IPP_TAG_URISCHEME
:
4463 max_bytes
= IPP_MAX_URISCHEME
;
4467 if (bytes
>= max_bytes
)
4469 char *bufmax
, /* Buffer at max_bytes */
4470 *bufptr
; /* Pointer into buffer */
4472 bufptr
= buffer
+ strlen(buffer
) - 1;
4473 bufmax
= buffer
+ max_bytes
- 1;
4475 while (bufptr
> bufmax
)
4479 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4490 * Set the formatted string and return...
4493 return (ippSetString(ipp
, attr
, element
, buffer
));
4498 * 'ippSetValueTag()' - Set the value tag of an attribute.
4500 * The @code ipp@ parameter refers to an IPP message previously created using
4501 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4503 * The @code attr@ parameter may be modified as a result of setting the value.
4505 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4506 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4507 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4508 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4509 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4510 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4513 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4514 * code in the "attributes-natural-language" attribute or, if not present, the language
4515 * code for the current locale.
4517 * @since CUPS 1.6/OS X 10.8@
4520 int /* O - 1 on success, 0 on failure */
4522 ipp_t
*ipp
, /* I - IPP message */
4523 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4524 ipp_tag_t value_tag
) /* I - Value tag */
4526 int i
; /* Looping var */
4527 _ipp_value_t
*value
; /* Current value */
4528 int integer
; /* Current integer value */
4529 cups_lang_t
*language
; /* Current language */
4530 char code
[32]; /* Language code */
4531 ipp_tag_t temp_tag
; /* Temporary value tag */
4535 * Range check input...
4538 if (!ipp
|| !attr
|| !*attr
)
4542 * If there is no change, return immediately...
4545 if (value_tag
== (*attr
)->value_tag
)
4549 * Otherwise implement changes as needed...
4552 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4556 case IPP_TAG_UNSUPPORTED_VALUE
:
4557 case IPP_TAG_DEFAULT
:
4558 case IPP_TAG_UNKNOWN
:
4559 case IPP_TAG_NOVALUE
:
4560 case IPP_TAG_NOTSETTABLE
:
4561 case IPP_TAG_DELETEATTR
:
4562 case IPP_TAG_ADMINDEFINE
:
4564 * Free any existing values...
4567 if ((*attr
)->num_values
> 0)
4568 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4571 * Set out-of-band value...
4574 (*attr
)->value_tag
= value_tag
;
4577 case IPP_TAG_RANGE
:
4578 if (temp_tag
!= IPP_TAG_INTEGER
)
4581 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4585 integer
= value
->integer
;
4586 value
->range
.lower
= value
->range
.upper
= integer
;
4589 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4593 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4594 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4595 temp_tag
!= IPP_TAG_MIMETYPE
)
4598 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4601 case IPP_TAG_NAMELANG
:
4602 case IPP_TAG_TEXTLANG
:
4603 if (value_tag
== IPP_TAG_NAMELANG
&&
4604 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4605 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4606 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4609 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4612 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4613 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4616 * Use the language code from the IPP message...
4619 (*attr
)->values
[0].string
.language
=
4620 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4625 * Otherwise, use the language code corresponding to the locale...
4628 language
= cupsLangDefault();
4629 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4634 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4637 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4639 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4642 * Make copies of all values...
4645 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4648 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4651 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4654 case IPP_TAG_KEYWORD
:
4655 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4656 break; /* Silently "allow" name -> keyword */
4667 * 'ippSetVersion()' - Set the version number in an IPP message.
4669 * The @code ipp@ parameter refers to an IPP message previously created using
4670 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4672 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4674 * @since CUPS 1.6/OS X 10.8@
4677 int /* O - 1 on success, 0 on failure */
4678 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4679 int major
, /* I - Major version number (major.minor) */
4680 int minor
) /* I - Minor version number (major.minor) */
4683 * Range check input...
4686 if (!ipp
|| major
< 0 || minor
< 0)
4690 * Set the version number...
4693 ipp
->request
.any
.version
[0] = (ipp_uchar_t
)major
;
4694 ipp
->request
.any
.version
[1] = (ipp_uchar_t
)minor
;
4701 * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
4704 const ipp_uchar_t
* /* O - RFC-1903 date/time data */
4705 ippTimeToDate(time_t t
) /* I - UNIX time value */
4707 struct tm
*unixdate
; /* UNIX unixdate/time info */
4708 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4709 /* RFC-1903 date/time data */
4713 * RFC-1903 date/time format is:
4715 * Byte(s) Description
4716 * ------- -----------
4717 * 0-1 Year (0 to 65535)
4721 * 5 Minutes (0 to 59)
4722 * 6 Seconds (0 to 60, 60 = "leap second")
4723 * 7 Deciseconds (0 to 9)
4725 * 9 UTC hours (0 to 11)
4726 * 10 UTC minutes (0 to 59)
4729 unixdate
= gmtime(&t
);
4730 unixdate
->tm_year
+= 1900;
4732 date
[0] = (ipp_uchar_t
)(unixdate
->tm_year
>> 8);
4733 date
[1] = (ipp_uchar_t
)(unixdate
->tm_year
);
4734 date
[2] = (ipp_uchar_t
)(unixdate
->tm_mon
+ 1);
4735 date
[3] = (ipp_uchar_t
)unixdate
->tm_mday
;
4736 date
[4] = (ipp_uchar_t
)unixdate
->tm_hour
;
4737 date
[5] = (ipp_uchar_t
)unixdate
->tm_min
;
4738 date
[6] = (ipp_uchar_t
)unixdate
->tm_sec
;
4749 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4751 * This function validates the contents of an attribute based on the name and
4752 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4753 * failure, cupsLastErrorString() is set to a human-readable message.
4755 * @since CUPS 1.7/OS X 10.9@
4758 int /* O - 1 if valid, 0 otherwise */
4759 ippValidateAttribute(
4760 ipp_attribute_t
*attr
) /* I - Attribute */
4762 int i
; /* Looping var */
4763 char scheme
[64], /* Scheme from URI */
4764 userpass
[256], /* Username/password from URI */
4765 hostname
[256], /* Hostname from URI */
4766 resource
[1024]; /* Resource from URI */
4767 int port
, /* Port number from URI */
4768 uri_status
; /* URI separation status */
4769 const char *ptr
; /* Pointer into string */
4770 ipp_attribute_t
*colattr
; /* Collection attribute */
4771 regex_t re
; /* Regular expression */
4772 ipp_uchar_t
*date
; /* Current date value */
4773 static const char * const uri_status_strings
[] =
4774 { /* URI status strings */
4776 "Bad arguments to function",
4777 "Bad resource in URI",
4778 "Bad port number in URI",
4779 "Bad hostname/address in URI",
4780 "Bad username in URI",
4781 "Bad scheme in URI",
4784 "Missing scheme in URI",
4785 "Unknown scheme in URI",
4786 "Missing resource in URI"
4798 * Validate the attribute name.
4801 for (ptr
= attr
->name
; *ptr
; ptr
++)
4802 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4805 if (*ptr
|| ptr
== attr
->name
)
4807 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4808 _("\"%s\": Bad attribute name - invalid character "
4809 "(RFC 2911 section 4.1.3)."), attr
->name
);
4813 if ((ptr
- attr
->name
) > 255)
4815 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4816 _("\"%s\": Bad attribute name - bad length %d "
4817 "(RFC 2911 section 4.1.3)."), attr
->name
,
4818 (int)(ptr
- attr
->name
));
4822 switch (attr
->value_tag
)
4824 case IPP_TAG_INTEGER
:
4827 case IPP_TAG_BOOLEAN
:
4828 for (i
= 0; i
< attr
->num_values
; i
++)
4830 if (attr
->values
[i
].boolean
!= 0 &&
4831 attr
->values
[i
].boolean
!= 1)
4833 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4834 _("\"%s\": Bad boolen value %d "
4835 "(RFC 2911 section 4.1.11)."), attr
->name
,
4836 attr
->values
[i
].boolean
);
4843 for (i
= 0; i
< attr
->num_values
; i
++)
4845 if (attr
->values
[i
].integer
< 1)
4847 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4848 _("\"%s\": Bad enum value %d - out of range "
4849 "(RFC 2911 section 4.1.4)."), attr
->name
,
4850 attr
->values
[i
].integer
);
4856 case IPP_TAG_STRING
:
4857 for (i
= 0; i
< attr
->num_values
; i
++)
4859 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4861 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4862 _("\"%s\": Bad octetString value - bad length %d "
4863 "(RFC 2911 section 4.1.10)."), attr
->name
,
4864 attr
->values
[i
].unknown
.length
);
4871 for (i
= 0; i
< attr
->num_values
; i
++)
4873 date
= attr
->values
[i
].date
;
4875 if (date
[2] < 1 || date
[2] > 12)
4877 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4878 _("\"%s\": Bad dateTime month %u "
4879 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[2]);
4883 if (date
[3] < 1 || date
[3] > 31)
4885 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4886 _("\"%s\": Bad dateTime day %u "
4887 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[3]);
4893 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4894 _("\"%s\": Bad dateTime hours %u "
4895 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[4]);
4901 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4902 _("\"%s\": Bad dateTime minutes %u "
4903 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[5]);
4909 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4910 _("\"%s\": Bad dateTime seconds %u "
4911 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[6]);
4917 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4918 _("\"%s\": Bad dateTime deciseconds %u "
4919 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[7]);
4923 if (date
[8] != '-' && date
[8] != '+')
4925 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4926 _("\"%s\": Bad dateTime UTC sign '%c' "
4927 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[8]);
4933 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4934 _("\"%s\": Bad dateTime UTC hours %u "
4935 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[9]);
4941 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4942 _("\"%s\": Bad dateTime UTC minutes %u "
4943 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[10]);
4949 case IPP_TAG_RESOLUTION
:
4950 for (i
= 0; i
< attr
->num_values
; i
++)
4952 if (attr
->values
[i
].resolution
.xres
<= 0)
4954 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4955 _("\"%s\": Bad resolution value %dx%d%s - cross "
4956 "feed resolution must be positive "
4957 "(RFC 2911 section 4.1.15)."), attr
->name
,
4958 attr
->values
[i
].resolution
.xres
,
4959 attr
->values
[i
].resolution
.yres
,
4960 attr
->values
[i
].resolution
.units
==
4961 IPP_RES_PER_INCH
? "dpi" :
4962 attr
->values
[i
].resolution
.units
==
4963 IPP_RES_PER_CM
? "dpcm" : "unknown");
4967 if (attr
->values
[i
].resolution
.yres
<= 0)
4969 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4970 _("\"%s\": Bad resolution value %dx%d%s - feed "
4971 "resolution must be positive "
4972 "(RFC 2911 section 4.1.15)."), attr
->name
,
4973 attr
->values
[i
].resolution
.xres
,
4974 attr
->values
[i
].resolution
.yres
,
4975 attr
->values
[i
].resolution
.units
==
4976 IPP_RES_PER_INCH
? "dpi" :
4977 attr
->values
[i
].resolution
.units
==
4978 IPP_RES_PER_CM
? "dpcm" : "unknown");
4982 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
4983 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
4985 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4986 _("\"%s\": Bad resolution value %dx%d%s - bad "
4987 "units value (RFC 2911 section 4.1.15)."),
4988 attr
->name
, attr
->values
[i
].resolution
.xres
,
4989 attr
->values
[i
].resolution
.yres
,
4990 attr
->values
[i
].resolution
.units
==
4991 IPP_RES_PER_INCH
? "dpi" :
4992 attr
->values
[i
].resolution
.units
==
4993 IPP_RES_PER_CM
? "dpcm" : "unknown");
4999 case IPP_TAG_RANGE
:
5000 for (i
= 0; i
< attr
->num_values
; i
++)
5002 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
5004 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5005 _("\"%s\": Bad rangeOfInteger value %d-%d - lower "
5006 "greater than upper (RFC 2911 section 4.1.13)."),
5007 attr
->name
, attr
->values
[i
].range
.lower
,
5008 attr
->values
[i
].range
.upper
);
5014 case IPP_TAG_BEGIN_COLLECTION
:
5015 for (i
= 0; i
< attr
->num_values
; i
++)
5017 for (colattr
= attr
->values
[i
].collection
->attrs
;
5019 colattr
= colattr
->next
)
5021 if (!ippValidateAttribute(colattr
))
5028 case IPP_TAG_TEXTLANG
:
5029 for (i
= 0; i
< attr
->num_values
; i
++)
5031 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5033 if ((*ptr
& 0xe0) == 0xc0)
5036 if ((*ptr
& 0xc0) != 0x80)
5039 else if ((*ptr
& 0xf0) == 0xe0)
5042 if ((*ptr
& 0xc0) != 0x80)
5045 if ((*ptr
& 0xc0) != 0x80)
5048 else if ((*ptr
& 0xf8) == 0xf0)
5051 if ((*ptr
& 0xc0) != 0x80)
5054 if ((*ptr
& 0xc0) != 0x80)
5057 if ((*ptr
& 0xc0) != 0x80)
5060 else if (*ptr
& 0x80)
5066 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5067 _("\"%s\": Bad text value \"%s\" - bad UTF-8 "
5068 "sequence (RFC 2911 section 4.1.1)."), attr
->name
,
5069 attr
->values
[i
].string
.text
);
5073 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5075 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5076 _("\"%s\": Bad text value \"%s\" - bad length %d "
5077 "(RFC 2911 section 4.1.1)."), attr
->name
,
5078 attr
->values
[i
].string
.text
,
5079 (int)(ptr
- attr
->values
[i
].string
.text
));
5086 case IPP_TAG_NAMELANG
:
5087 for (i
= 0; i
< attr
->num_values
; i
++)
5089 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5091 if ((*ptr
& 0xe0) == 0xc0)
5094 if ((*ptr
& 0xc0) != 0x80)
5097 else if ((*ptr
& 0xf0) == 0xe0)
5100 if ((*ptr
& 0xc0) != 0x80)
5103 if ((*ptr
& 0xc0) != 0x80)
5106 else if ((*ptr
& 0xf8) == 0xf0)
5109 if ((*ptr
& 0xc0) != 0x80)
5112 if ((*ptr
& 0xc0) != 0x80)
5115 if ((*ptr
& 0xc0) != 0x80)
5118 else if (*ptr
& 0x80)
5124 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5125 _("\"%s\": Bad name value \"%s\" - bad UTF-8 "
5126 "sequence (RFC 2911 section 4.1.2)."), attr
->name
,
5127 attr
->values
[i
].string
.text
);
5131 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5133 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5134 _("\"%s\": Bad name value \"%s\" - bad length %d "
5135 "(RFC 2911 section 4.1.2)."), attr
->name
,
5136 attr
->values
[i
].string
.text
,
5137 (int)(ptr
- attr
->values
[i
].string
.text
));
5143 case IPP_TAG_KEYWORD
:
5144 for (i
= 0; i
< attr
->num_values
; i
++)
5146 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5147 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5151 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5153 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5154 _("\"%s\": Bad keyword value \"%s\" - invalid "
5155 "character (RFC 2911 section 4.1.3)."),
5156 attr
->name
, attr
->values
[i
].string
.text
);
5160 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5162 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5163 _("\"%s\": Bad keyword value \"%s\" - bad "
5164 "length %d (RFC 2911 section 4.1.3)."),
5165 attr
->name
, attr
->values
[i
].string
.text
,
5166 (int)(ptr
- attr
->values
[i
].string
.text
));
5173 for (i
= 0; i
< attr
->num_values
; i
++)
5175 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5176 attr
->values
[i
].string
.text
,
5177 scheme
, sizeof(scheme
),
5178 userpass
, sizeof(userpass
),
5179 hostname
, sizeof(hostname
),
5180 &port
, resource
, sizeof(resource
));
5182 if (uri_status
< HTTP_URI_STATUS_OK
)
5184 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5185 _("\"%s\": Bad URI value \"%s\" - %s "
5186 "(RFC 2911 section 4.1.5)."), attr
->name
,
5187 attr
->values
[i
].string
.text
,
5188 uri_status_strings
[uri_status
-
5189 HTTP_URI_STATUS_OVERFLOW
]);
5193 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5195 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5196 _("\"%s\": Bad URI value \"%s\" - bad length %d "
5197 "(RFC 2911 section 4.1.5)."), attr
->name
,
5198 attr
->values
[i
].string
.text
,
5199 (int)strlen(attr
->values
[i
].string
.text
));
5204 case IPP_TAG_URISCHEME
:
5205 for (i
= 0; i
< attr
->num_values
; i
++)
5207 ptr
= attr
->values
[i
].string
.text
;
5208 if (islower(*ptr
& 255))
5210 for (ptr
++; *ptr
; ptr
++)
5211 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5212 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5216 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5218 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5219 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5220 "characters (RFC 2911 section 4.1.6)."),
5221 attr
->name
, attr
->values
[i
].string
.text
);
5225 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5227 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5228 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5229 "length %d (RFC 2911 section 4.1.6)."),
5230 attr
->name
, attr
->values
[i
].string
.text
,
5231 (int)(ptr
- attr
->values
[i
].string
.text
));
5237 case IPP_TAG_CHARSET
:
5238 for (i
= 0; i
< attr
->num_values
; i
++)
5240 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5241 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5242 isspace(*ptr
& 255))
5245 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5247 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5248 _("\"%s\": Bad charset value \"%s\" - bad "
5249 "characters (RFC 2911 section 4.1.7)."),
5250 attr
->name
, attr
->values
[i
].string
.text
);
5254 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5256 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5257 _("\"%s\": Bad charset value \"%s\" - bad "
5258 "length %d (RFC 2911 section 4.1.7)."),
5259 attr
->name
, attr
->values
[i
].string
.text
,
5260 (int)(ptr
- attr
->values
[i
].string
.text
));
5266 case IPP_TAG_LANGUAGE
:
5268 * The following regular expression is derived from the ABNF for
5269 * language tags in RFC 4646. All I can say is that this is the
5270 * easiest way to check the values...
5273 if ((i
= regcomp(&re
,
5275 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5277 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5278 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5279 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5280 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5281 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5283 "x(-[a-z0-9]{1,8})+" /* privateuse */
5285 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5287 REG_NOSUB
| REG_EXTENDED
)) != 0)
5289 char temp
[256]; /* Temporary error string */
5291 regerror(i
, &re
, temp
, sizeof(temp
));
5292 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
,
5293 _("Unable to compile naturalLanguage regular "
5294 "expression: %s."), temp
);
5298 for (i
= 0; i
< attr
->num_values
; i
++)
5300 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5302 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5303 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5304 "characters (RFC 2911 section 4.1.8)."),
5305 attr
->name
, attr
->values
[i
].string
.text
);
5310 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5312 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5313 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5314 "length %d (RFC 2911 section 4.1.8)."),
5315 attr
->name
, attr
->values
[i
].string
.text
,
5316 (int)strlen(attr
->values
[i
].string
.text
));
5325 case IPP_TAG_MIMETYPE
:
5327 * The following regular expression is derived from the ABNF for
5328 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5329 * the easiest way to check the values...
5332 if ((i
= regcomp(&re
,
5334 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5336 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5337 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5338 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5341 REG_NOSUB
| REG_EXTENDED
)) != 0)
5343 char temp
[256]; /* Temporary error string */
5345 regerror(i
, &re
, temp
, sizeof(temp
));
5346 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5347 _("Unable to compile mimeMediaType regular "
5348 "expression: %s."), temp
);
5352 for (i
= 0; i
< attr
->num_values
; i
++)
5354 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5356 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5357 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5358 "characters (RFC 2911 section 4.1.9)."),
5359 attr
->name
, attr
->values
[i
].string
.text
);
5364 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5366 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5367 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5368 "length %d (RFC 2911 section 4.1.9)."),
5369 attr
->name
, attr
->values
[i
].string
.text
,
5370 (int)strlen(attr
->values
[i
].string
.text
));
5388 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5390 * This function validates the contents of the IPP message, including each
5391 * attribute. Like @link ippValidateAttribute@, cupsLastErrorString() is set
5392 * to a human-readable message on failure.
5394 * @since CUPS 1.7/OS X 10.9@
5397 int /* O - 1 if valid, 0 otherwise */
5398 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5400 ipp_attribute_t
*attr
; /* Current attribute */
5406 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5407 if (!ippValidateAttribute(attr
))
5415 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5418 ipp_state_t
/* O - Current state */
5419 ippWrite(http_t
*http
, /* I - HTTP connection */
5420 ipp_t
*ipp
) /* I - IPP data */
5422 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", (void *)http
, (void *)ipp
));
5425 return (IPP_STATE_ERROR
);
5427 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5432 * 'ippWriteFile()' - Write data for an IPP message to a file.
5434 * @since CUPS 1.1.19/OS X 10.3@
5437 ipp_state_t
/* O - Current state */
5438 ippWriteFile(int fd
, /* I - HTTP data */
5439 ipp_t
*ipp
) /* I - IPP data */
5441 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, (void *)ipp
));
5443 ipp
->state
= IPP_STATE_IDLE
;
5445 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5450 * 'ippWriteIO()' - Write data for an IPP message.
5452 * @since CUPS 1.2/OS X 10.5@
5455 ipp_state_t
/* O - Current state */
5456 ippWriteIO(void *dst
, /* I - Destination */
5457 ipp_iocb_t cb
, /* I - Write callback function */
5458 int blocking
, /* I - Use blocking IO? */
5459 ipp_t
*parent
, /* I - Parent IPP message */
5460 ipp_t
*ipp
) /* I - IPP data */
5462 int i
; /* Looping var */
5463 int n
; /* Length of data */
5464 unsigned char *buffer
, /* Data buffer */
5465 *bufptr
; /* Pointer into buffer */
5466 ipp_attribute_t
*attr
; /* Current attribute */
5467 _ipp_value_t
*value
; /* Current value */
5470 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)", (void *)dst
, (void *)cb
, blocking
, (void *)parent
, (void *)ipp
));
5473 return (IPP_STATE_ERROR
);
5475 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5477 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5478 return (IPP_STATE_ERROR
);
5483 case IPP_STATE_IDLE
:
5484 ipp
->state
++; /* Avoid common problem... */
5486 case IPP_STATE_HEADER
:
5490 * Send the request header:
5493 * Operation/Status Code = 2 bytes
5494 * Request ID = 4 bytes
5500 *bufptr
++ = ipp
->request
.any
.version
[0];
5501 *bufptr
++ = ipp
->request
.any
.version
[1];
5502 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.op_status
>> 8);
5503 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.op_status
;
5504 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 24);
5505 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 16);
5506 *bufptr
++ = (ipp_uchar_t
)(ipp
->request
.any
.request_id
>> 8);
5507 *bufptr
++ = (ipp_uchar_t
)ipp
->request
.any
.request_id
;
5509 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5510 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5511 ipp
->request
.any
.op_status
));
5512 DEBUG_printf(("2ippWriteIO: request_id=%d",
5513 ipp
->request
.any
.request_id
));
5515 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5517 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5518 _cupsBufferRelease((char *)buffer
);
5519 return (IPP_STATE_ERROR
);
5524 * Reset the state engine to point to the first attribute
5525 * in the request/response, with no current group.
5528 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5529 ipp
->current
= ipp
->attrs
;
5530 ipp
->curtag
= IPP_TAG_ZERO
;
5532 DEBUG_printf(("1ippWriteIO: ipp->current=%p", (void *)ipp
->current
));
5535 * If blocking is disabled, stop here...
5541 case IPP_STATE_ATTRIBUTE
:
5542 while (ipp
->current
!= NULL
)
5545 * Write this attribute...
5549 attr
= ipp
->current
;
5551 ipp
->current
= ipp
->current
->next
;
5555 if (ipp
->curtag
!= attr
->group_tag
)
5558 * Send a group tag byte...
5561 ipp
->curtag
= attr
->group_tag
;
5563 if (attr
->group_tag
== IPP_TAG_ZERO
)
5566 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5567 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5568 *bufptr
++ = (ipp_uchar_t
)attr
->group_tag
;
5570 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5574 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5575 attr
->num_values
> 1 ? "1setOf " : "",
5576 ippTagString(attr
->value_tag
)));
5579 * Write the attribute tag and name.
5581 * The attribute name length does not include the trailing nul
5582 * character in the source string.
5584 * Collection values (parent != NULL) are written differently...
5590 * Get the length of the attribute name, and make sure it won't
5591 * overflow the buffer...
5594 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5596 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5597 _cupsBufferRelease((char *)buffer
);
5598 return (IPP_STATE_ERROR
);
5602 * Write the value tag, name length, and name string...
5605 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5606 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5607 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5610 if (attr
->value_tag
> 0xff)
5612 *bufptr
++ = IPP_TAG_EXTENSION
;
5613 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5614 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5615 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5616 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5619 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5621 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5622 *bufptr
++ = (ipp_uchar_t
)n
;
5623 memcpy(bufptr
, attr
->name
, (size_t)n
);
5629 * Get the length of the attribute name, and make sure it won't
5630 * overflow the buffer...
5633 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5635 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5636 _cupsBufferRelease((char *)buffer
);
5637 return (IPP_STATE_ERROR
);
5641 * Write the member name tag, name length, name string, value tag,
5642 * and empty name for the collection member attribute...
5645 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5646 IPP_TAG_MEMBERNAME
));
5647 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5649 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5650 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5651 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5653 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5656 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5657 *bufptr
++ = (ipp_uchar_t
)n
;
5658 memcpy(bufptr
, attr
->name
, (size_t)n
);
5661 if (attr
->value_tag
> 0xff)
5663 *bufptr
++ = IPP_TAG_EXTENSION
;
5664 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 24);
5665 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 16);
5666 *bufptr
++ = (ipp_uchar_t
)(attr
->value_tag
>> 8);
5667 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5670 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5677 * Now write the attribute value(s)...
5680 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5682 case IPP_TAG_UNSUPPORTED_VALUE
:
5683 case IPP_TAG_DEFAULT
:
5684 case IPP_TAG_UNKNOWN
:
5685 case IPP_TAG_NOVALUE
:
5686 case IPP_TAG_NOTSETTABLE
:
5687 case IPP_TAG_DELETEATTR
:
5688 case IPP_TAG_ADMINDEFINE
:
5693 case IPP_TAG_INTEGER
:
5695 for (i
= 0, value
= attr
->values
;
5696 i
< attr
->num_values
;
5699 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5701 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5703 DEBUG_puts("1ippWriteIO: Could not write IPP "
5705 _cupsBufferRelease((char *)buffer
);
5706 return (IPP_STATE_ERROR
);
5715 * Arrays and sets are done by sending additional
5716 * values with a zero-length name...
5719 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5725 * Integers and enumerations are both 4-byte signed
5726 * (twos-complement) values.
5728 * Put the 2-byte length and 4-byte value into the buffer...
5733 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 24);
5734 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 16);
5735 *bufptr
++ = (ipp_uchar_t
)(value
->integer
>> 8);
5736 *bufptr
++ = (ipp_uchar_t
)value
->integer
;
5740 case IPP_TAG_BOOLEAN
:
5741 for (i
= 0, value
= attr
->values
;
5742 i
< attr
->num_values
;
5745 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5747 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5749 DEBUG_puts("1ippWriteIO: Could not write IPP "
5751 _cupsBufferRelease((char *)buffer
);
5752 return (IPP_STATE_ERROR
);
5761 * Arrays and sets are done by sending additional
5762 * values with a zero-length name...
5765 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5771 * Boolean values are 1-byte; 0 = false, 1 = true.
5773 * Put the 2-byte length and 1-byte value into the buffer...
5778 *bufptr
++ = (ipp_uchar_t
)value
->boolean
;
5784 case IPP_TAG_KEYWORD
:
5786 case IPP_TAG_URISCHEME
:
5787 case IPP_TAG_CHARSET
:
5788 case IPP_TAG_LANGUAGE
:
5789 case IPP_TAG_MIMETYPE
:
5790 for (i
= 0, value
= attr
->values
;
5791 i
< attr
->num_values
;
5797 * Arrays and sets are done by sending additional
5798 * values with a zero-length name...
5801 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5803 ippTagString(attr
->value_tag
)));
5804 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5806 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5808 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5810 DEBUG_puts("1ippWriteIO: Could not write IPP "
5812 _cupsBufferRelease((char *)buffer
);
5813 return (IPP_STATE_ERROR
);
5819 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5824 if (value
->string
.text
!= NULL
)
5825 n
= (int)strlen(value
->string
.text
);
5829 if (n
> (IPP_BUF_SIZE
- 2))
5831 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5832 _cupsBufferRelease((char *)buffer
);
5833 return (IPP_STATE_ERROR
);
5836 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5837 value
->string
.text
));
5839 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5841 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5843 DEBUG_puts("1ippWriteIO: Could not write IPP "
5845 _cupsBufferRelease((char *)buffer
);
5846 return (IPP_STATE_ERROR
);
5853 * All simple strings consist of the 2-byte length and
5854 * character data without the trailing nul normally found
5855 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5856 * bytes since the 2-byte length is a signed (twos-complement)
5859 * Put the 2-byte length and string characters in the buffer.
5862 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
5863 *bufptr
++ = (ipp_uchar_t
)n
;
5867 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
5874 for (i
= 0, value
= attr
->values
;
5875 i
< attr
->num_values
;
5878 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5880 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5882 DEBUG_puts("1ippWriteIO: Could not write IPP "
5884 _cupsBufferRelease((char *)buffer
);
5885 return (IPP_STATE_ERROR
);
5894 * Arrays and sets are done by sending additional
5895 * values with a zero-length name...
5898 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5904 * Date values consist of a 2-byte length and an
5905 * 11-byte date/time structure defined by RFC 1903.
5907 * Put the 2-byte length and 11-byte date/time
5908 * structure in the buffer.
5913 memcpy(bufptr
, value
->date
, 11);
5918 case IPP_TAG_RESOLUTION
:
5919 for (i
= 0, value
= attr
->values
;
5920 i
< attr
->num_values
;
5923 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5925 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5927 DEBUG_puts("1ippWriteIO: Could not write IPP "
5929 _cupsBufferRelease((char *)buffer
);
5930 return (IPP_STATE_ERROR
);
5939 * Arrays and sets are done by sending additional
5940 * values with a zero-length name...
5943 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
5949 * Resolution values consist of a 2-byte length,
5950 * 4-byte horizontal resolution value, 4-byte vertical
5951 * resolution value, and a 1-byte units value.
5953 * Put the 2-byte length and resolution value data
5959 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 24);
5960 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 16);
5961 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.xres
>> 8);
5962 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.xres
;
5963 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 24);
5964 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 16);
5965 *bufptr
++ = (ipp_uchar_t
)(value
->resolution
.yres
>> 8);
5966 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.yres
;
5967 *bufptr
++ = (ipp_uchar_t
)value
->resolution
.units
;
5971 case IPP_TAG_RANGE
:
5972 for (i
= 0, value
= attr
->values
;
5973 i
< attr
->num_values
;
5976 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
5978 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
5980 DEBUG_puts("1ippWriteIO: Could not write IPP "
5982 _cupsBufferRelease((char *)buffer
);
5983 return (IPP_STATE_ERROR
);
5992 * Arrays and sets are done by sending additional
5993 * values with a zero-length name...
5996 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6002 * Range values consist of a 2-byte length,
6003 * 4-byte lower value, and 4-byte upper value.
6005 * Put the 2-byte length and range value data
6011 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 24);
6012 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 16);
6013 *bufptr
++ = (ipp_uchar_t
)(value
->range
.lower
>> 8);
6014 *bufptr
++ = (ipp_uchar_t
)value
->range
.lower
;
6015 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 24);
6016 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 16);
6017 *bufptr
++ = (ipp_uchar_t
)(value
->range
.upper
>> 8);
6018 *bufptr
++ = (ipp_uchar_t
)value
->range
.upper
;
6022 case IPP_TAG_TEXTLANG
:
6023 case IPP_TAG_NAMELANG
:
6024 for (i
= 0, value
= attr
->values
;
6025 i
< attr
->num_values
;
6031 * Arrays and sets are done by sending additional
6032 * values with a zero-length name...
6035 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6037 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6039 DEBUG_puts("1ippWriteIO: Could not write IPP "
6041 _cupsBufferRelease((char *)buffer
);
6042 return (IPP_STATE_ERROR
);
6048 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6054 * textWithLanguage and nameWithLanguage values consist
6055 * of a 2-byte length for both strings and their
6056 * individual lengths, a 2-byte length for the
6057 * character string, the character string without the
6058 * trailing nul, a 2-byte length for the character
6059 * set string, and the character set string without
6065 if (value
->string
.language
!= NULL
)
6066 n
+= (int)strlen(value
->string
.language
);
6068 if (value
->string
.text
!= NULL
)
6069 n
+= (int)strlen(value
->string
.text
);
6071 if (n
> (IPP_BUF_SIZE
- 2))
6073 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
6074 "too long (%d)", n
));
6075 _cupsBufferRelease((char *)buffer
);
6076 return (IPP_STATE_ERROR
);
6079 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6081 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6083 DEBUG_puts("1ippWriteIO: Could not write IPP "
6085 _cupsBufferRelease((char *)buffer
);
6086 return (IPP_STATE_ERROR
);
6092 /* Length of entire value */
6093 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6094 *bufptr
++ = (ipp_uchar_t
)n
;
6096 /* Length of language */
6097 if (value
->string
.language
!= NULL
)
6098 n
= (int)strlen(value
->string
.language
);
6102 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6103 *bufptr
++ = (ipp_uchar_t
)n
;
6108 memcpy(bufptr
, value
->string
.language
, (size_t)n
);
6112 /* Length of text */
6113 if (value
->string
.text
!= NULL
)
6114 n
= (int)strlen(value
->string
.text
);
6118 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6119 *bufptr
++ = (ipp_uchar_t
)n
;
6124 memcpy(bufptr
, value
->string
.text
, (size_t)n
);
6130 case IPP_TAG_BEGIN_COLLECTION
:
6131 for (i
= 0, value
= attr
->values
;
6132 i
< attr
->num_values
;
6136 * Collections are written with the begin-collection
6137 * tag first with a value of 0 length, followed by the
6138 * attributes in the collection, then the end-collection
6142 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6144 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6146 DEBUG_puts("1ippWriteIO: Could not write IPP "
6148 _cupsBufferRelease((char *)buffer
);
6149 return (IPP_STATE_ERROR
);
6158 * Arrays and sets are done by sending additional
6159 * values with a zero-length name...
6162 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6168 * Write a data length of 0 and flush the buffer...
6174 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6176 DEBUG_puts("1ippWriteIO: Could not write IPP "
6178 _cupsBufferRelease((char *)buffer
);
6179 return (IPP_STATE_ERROR
);
6185 * Then write the collection attribute...
6188 value
->collection
->state
= IPP_STATE_IDLE
;
6190 if (ippWriteIO(dst
, cb
, 1, ipp
,
6191 value
->collection
) == IPP_STATE_ERROR
)
6193 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6194 _cupsBufferRelease((char *)buffer
);
6195 return (IPP_STATE_ERROR
);
6201 for (i
= 0, value
= attr
->values
;
6202 i
< attr
->num_values
;
6208 * Arrays and sets are done by sending additional
6209 * values with a zero-length name...
6212 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6214 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6216 DEBUG_puts("1ippWriteIO: Could not write IPP "
6218 _cupsBufferRelease((char *)buffer
);
6219 return (IPP_STATE_ERROR
);
6225 *bufptr
++ = (ipp_uchar_t
)attr
->value_tag
;
6231 * An unknown value might some new value that a
6232 * vendor has come up with. It consists of a
6233 * 2-byte length and the bytes in the unknown
6237 n
= value
->unknown
.length
;
6239 if (n
> (IPP_BUF_SIZE
- 2))
6241 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6243 _cupsBufferRelease((char *)buffer
);
6244 return (IPP_STATE_ERROR
);
6247 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6249 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6251 DEBUG_puts("1ippWriteIO: Could not write IPP "
6253 _cupsBufferRelease((char *)buffer
);
6254 return (IPP_STATE_ERROR
);
6260 /* Length of unknown value */
6261 *bufptr
++ = (ipp_uchar_t
)(n
>> 8);
6262 *bufptr
++ = (ipp_uchar_t
)n
;
6267 memcpy(bufptr
, value
->unknown
.data
, (size_t)n
);
6275 * Write the data out...
6278 if (bufptr
> buffer
)
6280 if ((*cb
)(dst
, buffer
, (size_t)(bufptr
- buffer
)) < 0)
6282 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6283 _cupsBufferRelease((char *)buffer
);
6284 return (IPP_STATE_ERROR
);
6287 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6288 (int)(bufptr
- buffer
)));
6292 * If blocking is disabled and we aren't at the end of the attribute
6293 * list, stop here...
6296 if (!blocking
&& ipp
->current
)
6300 if (ipp
->current
== NULL
)
6303 * Done with all of the attributes; add the end-of-attributes
6304 * tag or end-collection attribute...
6309 buffer
[0] = IPP_TAG_END
;
6314 buffer
[0] = IPP_TAG_END_COLLECTION
;
6315 buffer
[1] = 0; /* empty name */
6317 buffer
[3] = 0; /* empty value */
6322 if ((*cb
)(dst
, buffer
, (size_t)n
) < 0)
6324 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6325 _cupsBufferRelease((char *)buffer
);
6326 return (IPP_STATE_ERROR
);
6329 ipp
->state
= IPP_STATE_DATA
;
6333 case IPP_STATE_DATA
:
6337 break; /* anti-compiler-warning-code */
6340 _cupsBufferRelease((char *)buffer
);
6342 return (ipp
->state
);
6347 * 'ipp_add_attr()' - Add a new attribute to the message.
6350 static ipp_attribute_t
* /* O - New attribute */
6351 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6352 const char *name
, /* I - Attribute name or NULL */
6353 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6354 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6355 int num_values
) /* I - Number of values */
6357 int alloc_values
; /* Number of values to allocate */
6358 ipp_attribute_t
*attr
; /* New attribute */
6361 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
));
6364 * Range check input...
6367 if (!ipp
|| num_values
< 0)
6371 * Allocate memory, rounding the allocation up as needed...
6374 if (num_values
<= 1)
6377 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6379 attr
= calloc(sizeof(ipp_attribute_t
) +
6380 (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6385 * Initialize attribute...
6389 attr
->name
= _cupsStrAlloc(name
);
6391 attr
->group_tag
= group_tag
;
6392 attr
->value_tag
= value_tag
;
6393 attr
->num_values
= num_values
;
6396 * Add it to the end of the linked list...
6400 ipp
->last
->next
= attr
;
6404 ipp
->prev
= ipp
->last
;
6405 ipp
->last
= ipp
->current
= attr
;
6408 DEBUG_printf(("5ipp_add_attr: Returning %p", (void *)attr
));
6415 * 'ipp_free_values()' - Free attribute values.
6419 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6420 int element
,/* I - First value to free */
6421 int count
) /* I - Number of values to free */
6423 int i
; /* Looping var */
6424 _ipp_value_t
*value
; /* Current value */
6427 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", (void *)attr
, element
, count
));
6429 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6432 * Free values as needed...
6435 switch (attr
->value_tag
)
6437 case IPP_TAG_TEXTLANG
:
6438 case IPP_TAG_NAMELANG
:
6439 if (element
== 0 && count
== attr
->num_values
&&
6440 attr
->values
[0].string
.language
)
6442 _cupsStrFree(attr
->values
[0].string
.language
);
6443 attr
->values
[0].string
.language
= NULL
;
6445 /* Fall through to other string values */
6449 case IPP_TAG_RESERVED_STRING
:
6450 case IPP_TAG_KEYWORD
:
6452 case IPP_TAG_URISCHEME
:
6453 case IPP_TAG_CHARSET
:
6454 case IPP_TAG_LANGUAGE
:
6455 case IPP_TAG_MIMETYPE
:
6456 for (i
= count
, value
= attr
->values
+ element
;
6460 _cupsStrFree(value
->string
.text
);
6461 value
->string
.text
= NULL
;
6465 case IPP_TAG_DEFAULT
:
6466 case IPP_TAG_UNKNOWN
:
6467 case IPP_TAG_NOVALUE
:
6468 case IPP_TAG_NOTSETTABLE
:
6469 case IPP_TAG_DELETEATTR
:
6470 case IPP_TAG_ADMINDEFINE
:
6471 case IPP_TAG_INTEGER
:
6473 case IPP_TAG_BOOLEAN
:
6475 case IPP_TAG_RESOLUTION
:
6476 case IPP_TAG_RANGE
:
6479 case IPP_TAG_BEGIN_COLLECTION
:
6480 for (i
= count
, value
= attr
->values
+ element
;
6484 ippDelete(value
->collection
);
6485 value
->collection
= NULL
;
6489 case IPP_TAG_STRING
:
6491 for (i
= count
, value
= attr
->values
+ element
;
6495 if (value
->unknown
.data
)
6497 free(value
->unknown
.data
);
6498 value
->unknown
.data
= NULL
;
6506 * If we are not freeing values from the end, move the remaining values up...
6509 if ((element
+ count
) < attr
->num_values
)
6510 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6511 (size_t)(attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6513 attr
->num_values
-= count
;
6518 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6520 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6521 * to "ll-cc", "ll-region", and "charset-number", respectively.
6524 static char * /* O - Language code string */
6525 ipp_get_code(const char *value
, /* I - Locale/charset string */
6526 char *buffer
, /* I - String buffer */
6527 size_t bufsize
) /* I - Size of string buffer */
6529 char *bufptr
, /* Pointer into buffer */
6530 *bufend
; /* End of buffer */
6534 * Convert values to lowercase and change _ to - as needed...
6537 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6538 *value
&& bufptr
< bufend
;
6543 *bufptr
++ = (char)_cups_tolower(*value
);
6548 * Return the converted string...
6556 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6558 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6559 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6562 static char * /* O - Language code string */
6563 ipp_lang_code(const char *locale
, /* I - Locale string */
6564 char *buffer
, /* I - String buffer */
6565 size_t bufsize
) /* I - Size of string buffer */
6568 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6571 if (!_cups_strcasecmp(locale
, "c"))
6573 strlcpy(buffer
, "en", bufsize
);
6577 return (ipp_get_code(locale
, buffer
, bufsize
));
6582 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6585 static size_t /* O - Size of IPP message */
6586 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6587 int collection
) /* I - 1 if a collection, 0 otherwise */
6589 int i
; /* Looping var */
6590 size_t bytes
; /* Number of bytes */
6591 ipp_attribute_t
*attr
; /* Current attribute */
6592 ipp_tag_t group
; /* Current group */
6593 _ipp_value_t
*value
; /* Current value */
6596 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", (void *)ipp
, collection
));
6600 DEBUG_puts("4ipp_length: Returning 0 bytes");
6605 * Start with 8 bytes for the IPP message header...
6608 bytes
= collection
? 0 : 8;
6611 * Then add the lengths of each attribute...
6614 group
= IPP_TAG_ZERO
;
6616 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6618 if (attr
->group_tag
!= group
&& !collection
)
6620 group
= attr
->group_tag
;
6621 if (group
== IPP_TAG_ZERO
)
6624 bytes
++; /* Group tag */
6630 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6631 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6633 if ((attr
->value_tag
& ~IPP_TAG_CUPS_CONST
) < IPP_TAG_EXTENSION
)
6634 bytes
+= (size_t)attr
->num_values
;/* Value tag for each value */
6636 bytes
+= (size_t)(5 * attr
->num_values
);
6637 /* Value tag for each value */
6638 bytes
+= (size_t)(2 * attr
->num_values
);
6640 bytes
+= strlen(attr
->name
); /* Name */
6641 bytes
+= (size_t)(2 * attr
->num_values
);
6645 bytes
+= 5; /* Add membername overhead */
6647 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6649 case IPP_TAG_UNSUPPORTED_VALUE
:
6650 case IPP_TAG_DEFAULT
:
6651 case IPP_TAG_UNKNOWN
:
6652 case IPP_TAG_NOVALUE
:
6653 case IPP_TAG_NOTSETTABLE
:
6654 case IPP_TAG_DELETEATTR
:
6655 case IPP_TAG_ADMINDEFINE
:
6658 case IPP_TAG_INTEGER
:
6660 bytes
+= (size_t)(4 * attr
->num_values
);
6663 case IPP_TAG_BOOLEAN
:
6664 bytes
+= (size_t)attr
->num_values
;
6669 case IPP_TAG_KEYWORD
:
6671 case IPP_TAG_URISCHEME
:
6672 case IPP_TAG_CHARSET
:
6673 case IPP_TAG_LANGUAGE
:
6674 case IPP_TAG_MIMETYPE
:
6675 for (i
= 0, value
= attr
->values
;
6676 i
< attr
->num_values
;
6678 if (value
->string
.text
)
6679 bytes
+= strlen(value
->string
.text
);
6683 bytes
+= (size_t)(11 * attr
->num_values
);
6686 case IPP_TAG_RESOLUTION
:
6687 bytes
+= (size_t)(9 * attr
->num_values
);
6690 case IPP_TAG_RANGE
:
6691 bytes
+= (size_t)(8 * attr
->num_values
);
6694 case IPP_TAG_TEXTLANG
:
6695 case IPP_TAG_NAMELANG
:
6696 bytes
+= (size_t)(4 * attr
->num_values
);
6697 /* Charset + text length */
6699 for (i
= 0, value
= attr
->values
;
6700 i
< attr
->num_values
;
6703 if (value
->string
.language
)
6704 bytes
+= strlen(value
->string
.language
);
6706 if (value
->string
.text
)
6707 bytes
+= strlen(value
->string
.text
);
6711 case IPP_TAG_BEGIN_COLLECTION
:
6712 for (i
= 0, value
= attr
->values
;
6713 i
< attr
->num_values
;
6715 bytes
+= ipp_length(value
->collection
, 1);
6719 for (i
= 0, value
= attr
->values
;
6720 i
< attr
->num_values
;
6722 bytes
+= (size_t)value
->unknown
.length
;
6728 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6729 * for the "end of collection" tag and return...
6737 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6744 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6747 static ssize_t
/* O - Number of bytes read */
6748 ipp_read_http(http_t
*http
, /* I - Client connection */
6749 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6750 size_t length
) /* I - Total length */
6752 ssize_t tbytes
, /* Total bytes read */
6753 bytes
; /* Bytes read this pass */
6756 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http
, (void *)buffer
, (int)length
));
6759 * Loop until all bytes are read...
6762 for (tbytes
= 0, bytes
= 0;
6763 tbytes
< (int)length
;
6764 tbytes
+= bytes
, buffer
+= bytes
)
6766 DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT
", http->state=%d", CUPS_LLCAST tbytes
, http
->state
));
6768 if (http
->state
== HTTP_STATE_WAITING
)
6771 if (http
->used
== 0 && !http
->blocking
)
6774 * Wait up to 10 seconds for more data on non-blocking sockets...
6777 if (!httpWait(http
, 10000))
6787 else if (http
->used
== 0 && http
->timeout_value
> 0)
6790 * Wait up to timeout seconds for more data on blocking sockets...
6793 if (!httpWait(http
, (int)(1000 * http
->timeout_value
)))
6804 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- (size_t)tbytes
)) < 0)
6809 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6815 else if (bytes
== 0)
6820 * Return the number of bytes read...
6823 if (tbytes
== 0 && bytes
< 0)
6826 DEBUG_printf(("8ipp_read_http: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST tbytes
));
6833 * 'ipp_read_file()' - Read IPP data from a file.
6836 static ssize_t
/* O - Number of bytes read */
6837 ipp_read_file(int *fd
, /* I - File descriptor */
6838 ipp_uchar_t
*buffer
, /* O - Read buffer */
6839 size_t length
) /* I - Number of bytes to read */
6842 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6844 return (read(*fd
, buffer
, length
));
6850 * 'ipp_set_error()' - Set a formatted, localized error string.
6854 ipp_set_error(ipp_status_t status
, /* I - Status code */
6855 const char *format
, /* I - Printf-style error string */
6856 ...) /* I - Additional arguments as needed */
6858 va_list ap
; /* Pointer to additional args */
6859 char buffer
[2048]; /* Message buffer */
6860 cups_lang_t
*lang
= cupsLangDefault();
6861 /* Current language */
6864 va_start(ap
, format
);
6865 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6868 _cupsSetError(status
, buffer
, 0);
6873 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6877 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6878 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6879 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6880 int element
) /* I - Value number (0-based) */
6882 ipp_attribute_t
*temp
, /* New attribute pointer */
6883 *current
, /* Current attribute in list */
6884 *prev
; /* Previous attribute in list */
6885 int alloc_values
; /* Allocated values */
6889 * If we are setting an existing value element, return it...
6894 if (temp
->num_values
<= 1)
6897 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6898 ~(IPP_MAX_VALUES
- 1);
6900 if (element
< alloc_values
)
6902 if (element
>= temp
->num_values
)
6903 temp
->num_values
= element
+ 1;
6905 return (temp
->values
+ element
);
6909 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6910 * values when num_values > 1.
6913 if (alloc_values
< IPP_MAX_VALUES
)
6914 alloc_values
= IPP_MAX_VALUES
;
6916 alloc_values
+= IPP_MAX_VALUES
;
6918 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6922 * Reallocate memory...
6925 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) + (size_t)(alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6927 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6928 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6933 * Zero the new memory...
6936 memset(temp
->values
+ temp
->num_values
, 0, (size_t)(alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6941 * Reset pointers in the list...
6944 if (ipp
->current
== *attr
&& ipp
->prev
)
6947 * Use current "previous" pointer...
6955 * Find this attribute in the linked list...
6958 for (prev
= NULL
, current
= ipp
->attrs
;
6959 current
&& current
!= *attr
;
6960 prev
= current
, current
= current
->next
);
6965 * This is a serious error!
6969 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
6970 _("IPP attribute is not a member of the message."), 1);
6971 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
6981 ipp
->current
= temp
;
6984 if (ipp
->last
== *attr
)
6991 * Return the value element...
6994 if (element
>= temp
->num_values
)
6995 temp
->num_values
= element
+ 1;
6997 return (temp
->values
+ element
);
7002 * 'ipp_write_file()' - Write IPP data to a file.
7005 static ssize_t
/* O - Number of bytes written */
7006 ipp_write_file(int *fd
, /* I - File descriptor */
7007 ipp_uchar_t
*buffer
, /* I - Data to write */
7008 size_t length
) /* I - Number of bytes to write */
7011 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
7013 return (write(*fd
, buffer
, length
));