4 * Internet Printing Protocol functions for CUPS.
6 * Copyright 2007-2013 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * _cupsBufferGet() - Get a read/write buffer.
20 * _cupsBufferRelease() - Release a read/write buffer.
21 * ippAddBoolean() - Add a boolean attribute to an IPP message.
22 * ippAddBooleans() - Add an array of boolean values.
23 * ippAddCollection() - Add a collection value.
24 * ippAddCollections() - Add an array of collection values.
25 * ippAddDate() - Add a date attribute to an IPP message.
26 * ippAddInteger() - Add a integer attribute to an IPP message.
27 * ippAddIntegers() - Add an array of integer values.
28 * ippAddOctetString() - Add an octetString value to an IPP message.
29 * ippAddOutOfBand() - Add an out-of-band value to an IPP message.
30 * ippAddRange() - Add a range of values to an IPP message.
31 * ippAddRanges() - Add ranges of values to an IPP message.
32 * ippAddResolution() - Add a resolution value to an IPP message.
33 * ippAddResolutions() - Add resolution values to an IPP message.
34 * ippAddSeparator() - Add a group separator to an IPP message.
35 * ippAddString() - Add a language-encoded string to an IPP message.
36 * ippAddStringf() - Add a formatted string to an IPP message.
37 * ippAddStringfv() - Add a formatted string to an IPP message.
38 * ippAddStrings() - Add language-encoded strings to an IPP message.
39 * ippContainsInteger() - Determine whether an attribute contains the
40 * specified value or is within the list of ranges.
41 * ippContainsString() - Determine whether an attribute contains the
42 * specified string value.
43 * ippCopyAttribute() - Copy an attribute.
44 * ippCopyAttributes() - Copy attributes from one IPP message to another.
45 * ippDateToTime() - Convert from RFC 1903 Date/Time format to UNIX
47 * ippDelete() - Delete an IPP message.
48 * ippDeleteAttribute() - Delete a single attribute in an IPP message.
49 * ippDeleteValues() - Delete values in an attribute.
50 * ippFindAttribute() - Find a named attribute in a request.
51 * ippFindNextAttribute() - Find the next named attribute in a request.
52 * ippFirstAttribute() - Return the first attribute in the message.
53 * ippGetBoolean() - Get a boolean value for an attribute.
54 * ippGetCollection() - Get a collection value for an attribute.
55 * ippGetCount() - Get the number of values in an attribute.
56 * ippGetDate() - Get a date value for an attribute.
57 * ippGetGroupTag() - Get the group associated with an attribute.
58 * ippGetInteger() - Get the integer/enum value for an attribute.
59 * ippGetName() - Get the attribute name.
60 * ippGetOctetString() - Get an octetString value from an IPP attribute.
61 * ippGetOperation() - Get the operation ID in an IPP message.
62 * ippGetRange() - Get a rangeOfInteger value from an attribute.
63 * ippGetRequestId() - Get the request ID from an IPP message.
64 * ippGetResolution() - Get a resolution value for an attribute.
65 * ippGetState() - Get the IPP message state.
66 * ippGetStatusCode() - Get the status code from an IPP response or
68 * ippGetString() - Get the string and optionally the language code
70 * ippGetValueTag() - Get the value tag for an attribute.
71 * ippGetVersion() - Get the major and minor version number from an
73 * ippLength() - Compute the length of an IPP message.
74 * ippNextAttribute() - Return the next attribute in the message.
75 * ippNew() - Allocate a new IPP message.
76 * ippNewRequest() - Allocate a new IPP request message.
77 * ippNewResponse() - Allocate a new IPP response message.
78 * ippRead() - Read data for an IPP message from a HTTP
80 * ippReadFile() - Read data for an IPP message from a file.
81 * ippReadIO() - Read data for an IPP message.
82 * ippSetBoolean() - Set a boolean value in an attribute.
83 * ippSetCollection() - Set a collection value in an attribute.
84 * ippSetDate() - Set a date value in an attribute.
85 * ippSetGroupTag() - Set the group tag of an attribute.
86 * ippSetInteger() - Set an integer or enum value in an attribute.
87 * ippSetName() - Set the name of an attribute.
88 * ippSetOctetString() - Set an octetString value in an IPP attribute.
89 * ippSetOperation() - Set the operation ID in an IPP request message.
90 * ippSetRange() - Set a rangeOfInteger value in an attribute.
91 * ippSetRequestId() - Set the request ID in an IPP message.
92 * ippSetResolution() - Set a resolution value in an attribute.
93 * ippSetState() - Set the current state of the IPP message.
94 * ippSetStatusCode() - Set the status code in an IPP response or event
96 * ippSetString() - Set a string value in an attribute.
97 * ippSetStringf() - Set a formatted string value of an attribute.
98 * ippSetStringf() - Set a formatted string value of an attribute.
99 * ippSetValueTag() - Set the value tag of an attribute.
100 * ippSetVersion() - Set the version number in an IPP message.
101 * ippTimeToDate() - Convert from UNIX time to RFC 1903 format.
102 * ippValidateAttribute() - Validate the contents of an attribute.
103 * ippValidateAttributes() - Validate all attributes in an IPP message.
104 * ippWrite() - Write data for an IPP message to a HTTP
106 * ippWriteFile() - Write data for an IPP message to a file.
107 * ippWriteIO() - Write data for an IPP message.
108 * ipp_add_attr() - Add a new attribute to the message.
109 * ipp_free_values() - Free attribute values.
110 * ipp_get_code() - Convert a C locale/charset name into an IPP
111 * language/charset code.
112 * ipp_lang_code() - Convert a C locale name into an IPP language
114 * ipp_length() - Compute the length of an IPP message or
116 * ipp_read_http() - Semi-blocking read on a HTTP connection...
117 * ipp_read_file() - Read IPP data from a file.
118 * ipp_set_error() - Set a formatted, localized error string.
119 * ipp_set_value() - Get the value element from an attribute,
120 * expanding it as needed.
121 * ipp_write_file() - Write IPP data to a file.
125 * Include necessary headers...
128 #include "cups-private.h"
139 static ipp_attribute_t
*ipp_add_attr(ipp_t
*ipp
, const char *name
,
140 ipp_tag_t group_tag
, ipp_tag_t value_tag
,
142 static void ipp_free_values(ipp_attribute_t
*attr
, int element
,
144 static char *ipp_get_code(const char *locale
, char *buffer
,
146 __attribute__((nonnull(1,2)));
147 static char *ipp_lang_code(const char *locale
, char *buffer
,
149 __attribute__((nonnull(1,2)));
150 static size_t ipp_length(ipp_t
*ipp
, int collection
);
151 static ssize_t
ipp_read_http(http_t
*http
, ipp_uchar_t
*buffer
,
153 static ssize_t
ipp_read_file(int *fd
, ipp_uchar_t
*buffer
,
155 static void ipp_set_error(ipp_status_t status
, const char *format
,
157 static _ipp_value_t
*ipp_set_value(ipp_t
*ipp
, ipp_attribute_t
**attr
,
159 static ssize_t
ipp_write_file(int *fd
, ipp_uchar_t
*buffer
,
164 * '_cupsBufferGet()' - Get a read/write buffer.
167 char * /* O - Buffer */
168 _cupsBufferGet(size_t size
) /* I - Size required */
170 _cups_buffer_t
*buffer
; /* Current buffer */
171 _cups_globals_t
*cg
= _cupsGlobals();
175 for (buffer
= cg
->cups_buffers
; buffer
; buffer
= buffer
->next
)
176 if (!buffer
->used
&& buffer
->size
>= size
)
181 if ((buffer
= malloc(sizeof(_cups_buffer_t
) + size
- 1)) == NULL
)
184 buffer
->next
= cg
->cups_buffers
;
186 cg
->cups_buffers
= buffer
;
196 * '_cupsBufferRelease()' - Release a read/write buffer.
200 _cupsBufferRelease(char *b
) /* I - Buffer to release */
202 _cups_buffer_t
*buffer
; /* Buffer */
206 * Mark this buffer as unused...
209 buffer
= (_cups_buffer_t
*)(b
- offsetof(_cups_buffer_t
, d
));
215 * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
217 * The @code ipp@ parameter refers to an IPP message previously created using
218 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
220 * The @code group@ parameter specifies the IPP attribute group tag: none
221 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
222 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
223 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
224 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
227 ipp_attribute_t
* /* O - New attribute */
228 ippAddBoolean(ipp_t
*ipp
, /* I - IPP message */
229 ipp_tag_t group
, /* I - IPP group */
230 const char *name
, /* I - Name of attribute */
231 char value
) /* I - Value of attribute */
233 ipp_attribute_t
*attr
; /* New attribute */
236 DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)",
237 ipp
, group
, ippTagString(group
), name
, value
));
240 * Range check input...
243 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
244 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
248 * Create the attribute...
251 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, 1)) == NULL
)
254 attr
->values
[0].boolean
= value
;
261 * 'ippAddBooleans()' - Add an array of boolean values.
263 * The @code ipp@ parameter refers to an IPP message previously created using
264 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
266 * The @code group@ parameter specifies the IPP attribute group tag: none
267 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
268 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
269 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
270 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
273 ipp_attribute_t
* /* O - New attribute */
274 ippAddBooleans(ipp_t
*ipp
, /* I - IPP message */
275 ipp_tag_t group
, /* I - IPP group */
276 const char *name
, /* I - Name of attribute */
277 int num_values
, /* I - Number of values */
278 const char *values
) /* I - Values */
280 int i
; /* Looping var */
281 ipp_attribute_t
*attr
; /* New attribute */
282 _ipp_value_t
*value
; /* Current value */
285 DEBUG_printf(("ippAddBooleans(ipp=%p, group=%02x(%s), name=\"%s\", "
286 "num_values=%d, values=%p)", ipp
, group
, ippTagString(group
),
287 name
, num_values
, values
));
290 * Range check input...
293 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
294 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
299 * Create the attribute...
302 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, num_values
)) == NULL
)
307 for (i
= num_values
, value
= attr
->values
;
310 value
->boolean
= *values
++;
318 * 'ippAddCollection()' - Add a collection value.
320 * The @code ipp@ parameter refers to an IPP message previously created using
321 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
323 * The @code group@ parameter specifies the IPP attribute group tag: none
324 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
325 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
326 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
327 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
329 * @since CUPS 1.1.19/OS X 10.3@
332 ipp_attribute_t
* /* O - New attribute */
333 ippAddCollection(ipp_t
*ipp
, /* I - IPP message */
334 ipp_tag_t group
, /* I - IPP group */
335 const char *name
, /* I - Name of attribute */
336 ipp_t
*value
) /* I - Value */
338 ipp_attribute_t
*attr
; /* New attribute */
341 DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", "
342 "value=%p)", ipp
, group
, ippTagString(group
), name
, value
));
345 * Range check input...
348 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
349 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
353 * Create the attribute...
356 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
, 1)) == NULL
)
359 attr
->values
[0].collection
= value
;
369 * 'ippAddCollections()' - Add an array of collection values.
371 * The @code ipp@ parameter refers to an IPP message previously created using
372 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
374 * The @code group@ parameter specifies the IPP attribute group tag: none
375 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
376 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
377 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
378 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
380 * @since CUPS 1.1.19/OS X 10.3@
383 ipp_attribute_t
* /* O - New attribute */
385 ipp_t
*ipp
, /* I - IPP message */
386 ipp_tag_t group
, /* I - IPP group */
387 const char *name
, /* I - Name of attribute */
388 int num_values
, /* I - Number of values */
389 const ipp_t
**values
) /* I - Values */
391 int i
; /* Looping var */
392 ipp_attribute_t
*attr
; /* New attribute */
393 _ipp_value_t
*value
; /* Current value */
396 DEBUG_printf(("ippAddCollections(ipp=%p, group=%02x(%s), name=\"%s\", "
397 "num_values=%d, values=%p)", ipp
, group
, ippTagString(group
),
398 name
, num_values
, values
));
401 * Range check input...
404 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
405 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
410 * Create the attribute...
413 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
,
414 num_values
)) == NULL
)
419 for (i
= num_values
, value
= attr
->values
;
423 value
->collection
= (ipp_t
*)*values
++;
424 value
->collection
->use
++;
433 * 'ippAddDate()' - Add a date attribute to an IPP message.
435 * The @code ipp@ parameter refers to an IPP message previously created using
436 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
438 * The @code group@ parameter specifies the IPP attribute group tag: none
439 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
440 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
441 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
442 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
445 ipp_attribute_t
* /* O - New attribute */
446 ippAddDate(ipp_t
*ipp
, /* I - IPP message */
447 ipp_tag_t group
, /* I - IPP group */
448 const char *name
, /* I - Name of attribute */
449 const ipp_uchar_t
*value
) /* I - Value */
451 ipp_attribute_t
*attr
; /* New attribute */
454 DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)",
455 ipp
, group
, ippTagString(group
), name
, value
));
458 * Range check input...
461 if (!ipp
|| !name
|| !value
|| group
< IPP_TAG_ZERO
||
462 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
466 * Create the attribute...
469 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_DATE
, 1)) == NULL
)
472 memcpy(attr
->values
[0].date
, value
, 11);
479 * 'ippAddInteger()' - Add a integer attribute to an IPP message.
481 * The @code ipp@ parameter refers to an IPP message previously created using
482 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
484 * The @code group@ parameter specifies the IPP attribute group tag: none
485 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
486 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
487 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
488 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
490 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
491 * (@code IPP_TAG_INTEGER@).
494 ipp_attribute_t
* /* O - New attribute */
495 ippAddInteger(ipp_t
*ipp
, /* I - IPP message */
496 ipp_tag_t group
, /* I - IPP group */
497 ipp_tag_t value_tag
, /* I - Type of attribute */
498 const char *name
, /* I - Name of attribute */
499 int value
) /* I - Value of attribute */
501 ipp_attribute_t
*attr
; /* New attribute */
504 DEBUG_printf(("ippAddInteger(ipp=%p, group=%02x(%s), type=%02x(%s), "
505 "name=\"%s\", value=%d)", ipp
, group
, ippTagString(group
),
506 value_tag
, ippTagString(value_tag
), name
, value
));
508 value_tag
&= IPP_TAG_CUPS_MASK
;
511 * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
515 if (value_tag
>= IPP_TAG_UNSUPPORTED_VALUE
&& value_tag
<= IPP_TAG_ADMINDEFINE
)
516 return (ippAddOutOfBand(ipp
, group
, value_tag
, name
));
519 * Range check input...
523 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
524 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
525 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
))
528 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
529 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
534 * Create the attribute...
537 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
540 attr
->values
[0].integer
= value
;
547 * 'ippAddIntegers()' - Add an array of integer values.
549 * The @code ipp@ parameter refers to an IPP message previously created using
550 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
552 * The @code group@ parameter specifies the IPP attribute group tag: none
553 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
554 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
555 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
556 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
558 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
559 * (@code IPP_TAG_INTEGER@).
562 ipp_attribute_t
* /* O - New attribute */
563 ippAddIntegers(ipp_t
*ipp
, /* I - IPP message */
564 ipp_tag_t group
, /* I - IPP group */
565 ipp_tag_t value_tag
, /* I - Type of attribute */
566 const char *name
, /* I - Name of attribute */
567 int num_values
, /* I - Number of values */
568 const int *values
) /* I - Values */
570 int i
; /* Looping var */
571 ipp_attribute_t
*attr
; /* New attribute */
572 _ipp_value_t
*value
; /* Current value */
575 DEBUG_printf(("ippAddIntegers(ipp=%p, group=%02x(%s), type=%02x(%s), "
576 "name=\"%s\", num_values=%d, values=%p)", ipp
,
577 group
, ippTagString(group
), value_tag
, ippTagString(value_tag
), name
,
578 num_values
, values
));
580 value_tag
&= IPP_TAG_CUPS_MASK
;
583 * Range check input...
587 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
588 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
589 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
) ||
593 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
594 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
600 * Create the attribute...
603 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
608 for (i
= num_values
, value
= attr
->values
;
611 value
->integer
= *values
++;
619 * 'ippAddOctetString()' - Add an octetString value to an IPP message.
621 * The @code ipp@ parameter refers to an IPP message previously created using
622 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
624 * The @code group@ parameter specifies the IPP attribute group tag: none
625 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
626 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
627 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
628 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
630 * @since CUPS 1.2/OS X 10.5@
633 ipp_attribute_t
* /* O - New attribute */
634 ippAddOctetString(ipp_t
*ipp
, /* I - IPP message */
635 ipp_tag_t group
, /* I - IPP group */
636 const char *name
, /* I - Name of attribute */
637 const void *data
, /* I - octetString data */
638 int datalen
) /* I - Length of data in bytes */
640 ipp_attribute_t
*attr
; /* New attribute */
643 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
644 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
645 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
648 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_STRING
, 1)) == NULL
)
652 * Initialize the attribute data...
655 attr
->values
[0].unknown
.length
= datalen
;
659 if ((attr
->values
[0].unknown
.data
= malloc(datalen
)) == NULL
)
661 ippDeleteAttribute(ipp
, attr
);
665 memcpy(attr
->values
[0].unknown
.data
, data
, datalen
);
669 * Return the new attribute...
677 * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
679 * The @code ipp@ parameter refers to an IPP message previously created using
680 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
682 * The @code group@ parameter specifies the IPP attribute group tag: none
683 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
684 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
685 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
686 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
688 * Supported out-of-band values include unsupported-value
689 * (@code IPP_TAG_UNSUPPORTED_VALUE@), default (@code IPP_TAG_DEFAULT@), unknown
690 * (@code IPP_TAG_UNKNOWN@), no-value (@code IPP_TAG_NOVALUE@), not-settable
691 * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
692 * admin-define (@code IPP_TAG_ADMINDEFINE@).
694 * @since CUPS 1.6/OS X 10.8@
697 ipp_attribute_t
* /* O - New attribute */
698 ippAddOutOfBand(ipp_t
*ipp
, /* I - IPP message */
699 ipp_tag_t group
, /* I - IPP group */
700 ipp_tag_t value_tag
, /* I - Type of attribute */
701 const char *name
) /* I - Name of attribute */
703 DEBUG_printf(("ippAddOutOfBand(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
704 "name=\"%s\")", ipp
, group
, ippTagString(group
), value_tag
,
705 ippTagString(value_tag
), name
));
707 value_tag
&= IPP_TAG_CUPS_MASK
;
710 * Range check input...
713 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
714 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
715 (value_tag
!= IPP_TAG_UNSUPPORTED_VALUE
&&
716 value_tag
!= IPP_TAG_DEFAULT
&&
717 value_tag
!= IPP_TAG_UNKNOWN
&&
718 value_tag
!= IPP_TAG_NOVALUE
&&
719 value_tag
!= IPP_TAG_NOTSETTABLE
&&
720 value_tag
!= IPP_TAG_DELETEATTR
&&
721 value_tag
!= IPP_TAG_ADMINDEFINE
))
725 * Create the attribute...
728 return (ipp_add_attr(ipp
, name
, group
, value_tag
, 1));
733 * 'ippAddRange()' - Add a range of values to an IPP message.
735 * The @code ipp@ parameter refers to an IPP message previously created using
736 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
738 * The @code group@ parameter specifies the IPP attribute group tag: none
739 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
740 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
741 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
742 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
744 * The @code lower@ parameter must be less than or equal to the @code upper@ parameter.
747 ipp_attribute_t
* /* O - New attribute */
748 ippAddRange(ipp_t
*ipp
, /* I - IPP message */
749 ipp_tag_t group
, /* I - IPP group */
750 const char *name
, /* I - Name of attribute */
751 int lower
, /* I - Lower value */
752 int upper
) /* I - Upper value */
754 ipp_attribute_t
*attr
; /* New attribute */
757 DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, "
758 "upper=%d)", ipp
, group
, ippTagString(group
), name
, lower
,
762 * Range check input...
765 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
766 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
770 * Create the attribute...
773 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, 1)) == NULL
)
776 attr
->values
[0].range
.lower
= lower
;
777 attr
->values
[0].range
.upper
= upper
;
784 * 'ippAddRanges()' - Add ranges of values to an IPP message.
786 * The @code ipp@ parameter refers to an IPP message previously created using
787 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
789 * The @code group@ parameter specifies the IPP attribute group tag: none
790 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
791 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
792 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
793 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
796 ipp_attribute_t
* /* O - New attribute */
797 ippAddRanges(ipp_t
*ipp
, /* I - IPP message */
798 ipp_tag_t group
, /* I - IPP group */
799 const char *name
, /* I - Name of attribute */
800 int num_values
, /* I - Number of values */
801 const int *lower
, /* I - Lower values */
802 const int *upper
) /* I - Upper values */
804 int i
; /* Looping var */
805 ipp_attribute_t
*attr
; /* New attribute */
806 _ipp_value_t
*value
; /* Current value */
809 DEBUG_printf(("ippAddRanges(ipp=%p, group=%02x(%s), name=\"%s\", "
810 "num_values=%d, lower=%p, upper=%p)", ipp
, group
,
811 ippTagString(group
), name
, num_values
, lower
, upper
));
814 * Range check input...
817 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
818 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
823 * Create the attribute...
826 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, num_values
)) == NULL
)
831 for (i
= num_values
, value
= attr
->values
;
835 value
->range
.lower
= *lower
++;
836 value
->range
.upper
= *upper
++;
845 * 'ippAddResolution()' - Add a resolution value to an IPP message.
847 * The @code ipp@ parameter refers to an IPP message previously created using
848 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
850 * The @code group@ parameter specifies the IPP attribute group tag: none
851 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
852 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
853 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
854 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
857 ipp_attribute_t
* /* O - New attribute */
858 ippAddResolution(ipp_t
*ipp
, /* I - IPP message */
859 ipp_tag_t group
, /* I - IPP group */
860 const char *name
, /* I - Name of attribute */
861 ipp_res_t units
, /* I - Units for resolution */
862 int xres
, /* I - X resolution */
863 int yres
) /* I - Y resolution */
865 ipp_attribute_t
*attr
; /* New attribute */
868 DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", "
869 "units=%d, xres=%d, yres=%d)", ipp
, group
,
870 ippTagString(group
), name
, units
, xres
, yres
));
873 * Range check input...
876 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
877 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
878 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
||
879 xres
< 0 || yres
< 0)
883 * Create the attribute...
886 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, 1)) == NULL
)
889 attr
->values
[0].resolution
.xres
= xres
;
890 attr
->values
[0].resolution
.yres
= yres
;
891 attr
->values
[0].resolution
.units
= units
;
898 * 'ippAddResolutions()' - Add resolution values to an IPP message.
900 * The @code ipp@ parameter refers to an IPP message previously created using
901 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
903 * The @code group@ parameter specifies the IPP attribute group tag: none
904 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
905 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
906 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
907 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
910 ipp_attribute_t
* /* O - New attribute */
911 ippAddResolutions(ipp_t
*ipp
, /* I - IPP message */
912 ipp_tag_t group
, /* I - IPP group */
913 const char *name
, /* I - Name of attribute */
914 int num_values
,/* I - Number of values */
915 ipp_res_t units
, /* I - Units for resolution */
916 const int *xres
, /* I - X resolutions */
917 const int *yres
) /* I - Y resolutions */
919 int i
; /* Looping var */
920 ipp_attribute_t
*attr
; /* New attribute */
921 _ipp_value_t
*value
; /* Current value */
924 DEBUG_printf(("ippAddResolutions(ipp=%p, group=%02x(%s), name=\"%s\", "
925 "num_value=%d, units=%d, xres=%p, yres=%p)", ipp
, group
,
926 ippTagString(group
), name
, num_values
, units
, xres
, yres
));
929 * Range check input...
932 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
933 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
935 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
)
939 * Create the attribute...
942 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, num_values
)) == NULL
)
947 for (i
= num_values
, value
= attr
->values
;
951 value
->resolution
.xres
= *xres
++;
952 value
->resolution
.yres
= *yres
++;
953 value
->resolution
.units
= units
;
962 * 'ippAddSeparator()' - Add a group separator to an IPP message.
964 * The @code ipp@ parameter refers to an IPP message previously created using
965 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
968 ipp_attribute_t
* /* O - New attribute */
969 ippAddSeparator(ipp_t
*ipp
) /* I - IPP message */
971 DEBUG_printf(("ippAddSeparator(ipp=%p)", ipp
));
974 * Range check input...
981 * Create the attribute...
984 return (ipp_add_attr(ipp
, NULL
, IPP_TAG_ZERO
, IPP_TAG_ZERO
, 0));
989 * 'ippAddString()' - Add a language-encoded string to an IPP message.
991 * The @code ipp@ parameter refers to an IPP message previously created using
992 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
994 * The @code group@ parameter specifies the IPP attribute group tag: none
995 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
996 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
997 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
998 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1000 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1001 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1002 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1003 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1004 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1005 * (@code IPP_TAG_URISCHEME@).
1007 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1008 * textWithLanguage string values and must be @code NULL@ for all other string values.
1011 ipp_attribute_t
* /* O - New attribute */
1012 ippAddString(ipp_t
*ipp
, /* I - IPP message */
1013 ipp_tag_t group
, /* I - IPP group */
1014 ipp_tag_t value_tag
, /* I - Type of attribute */
1015 const char *name
, /* I - Name of attribute */
1016 const char *language
, /* I - Language code */
1017 const char *value
) /* I - Value */
1019 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1020 ipp_attribute_t
*attr
; /* New attribute */
1021 char code
[IPP_MAX_LANGUAGE
];
1022 /* Charset/language code buffer */
1025 DEBUG_printf(("ippAddString(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
1026 "name=\"%s\", language=\"%s\", value=\"%s\")", ipp
,
1027 group
, ippTagString(group
), value_tag
, ippTagString(value_tag
), name
,
1031 * Range check input...
1034 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
1037 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1038 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1039 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1040 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
)
1043 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1044 != (language
!= NULL
))
1047 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1048 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
1053 * See if we need to map charset, language, or locale values...
1056 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
1057 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1058 value_tag
= temp_tag
; /* Don't do a fast copy */
1059 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
) &&
1060 strcmp(value
, ipp_get_code(value
, code
, sizeof(code
))))
1061 value_tag
= temp_tag
; /* Don't do a fast copy */
1062 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
) &&
1063 strcmp(value
, ipp_lang_code(value
, code
, sizeof(code
))))
1064 value_tag
= temp_tag
; /* Don't do a fast copy */
1067 * Create the attribute...
1070 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
1074 * Initialize the attribute data...
1077 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1079 attr
->values
[0].string
.language
= (char *)language
;
1080 attr
->values
[0].string
.text
= (char *)value
;
1085 attr
->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1090 if (value_tag
== IPP_TAG_CHARSET
)
1091 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_get_code(value
, code
,
1093 else if (value_tag
== IPP_TAG_LANGUAGE
)
1094 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_lang_code(value
, code
,
1097 attr
->values
[0].string
.text
= _cupsStrAlloc(value
);
1106 * 'ippAddStringf()' - Add a formatted string to an IPP message.
1108 * The @code ipp@ parameter refers to an IPP message previously created using
1109 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1111 * The @code group@ parameter specifies the IPP attribute group tag: none
1112 * (@code IPP_TAG_ZERO@, for member attributes), document
1113 * (@code IPP_TAG_DOCUMENT@), event notification
1114 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1115 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1116 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1118 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1119 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1120 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1121 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1122 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1123 * (@code IPP_TAG_URISCHEME@).
1125 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1126 * and textWithLanguage string values and must be @code NULL@ for all other
1129 * The @code format@ parameter uses formatting characters compatible with the
1130 * printf family of standard functions. Additional arguments follow it as
1131 * needed. The formatted string is truncated as needed to the maximum length of
1132 * the corresponding value type.
1137 ipp_attribute_t
* /* O - New attribute */
1138 ippAddStringf(ipp_t
*ipp
, /* I - IPP message */
1139 ipp_tag_t group
, /* I - IPP group */
1140 ipp_tag_t value_tag
, /* I - Type of attribute */
1141 const char *name
, /* I - Name of attribute */
1142 const char *language
, /* I - Language code (@code NULL@ for default) */
1143 const char *format
, /* I - Printf-style format string */
1144 ...) /* I - Additional arguments as needed */
1146 ipp_attribute_t
*attr
; /* New attribute */
1147 va_list ap
; /* Argument pointer */
1150 va_start(ap
, format
);
1151 attr
= ippAddStringfv(ipp
, group
, value_tag
, name
, language
, format
, ap
);
1159 * 'ippAddStringfv()' - Add a formatted string to an IPP message.
1161 * The @code ipp@ parameter refers to an IPP message previously created using
1162 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1164 * The @code group@ parameter specifies the IPP attribute group tag: none
1165 * (@code IPP_TAG_ZERO@, for member attributes), document
1166 * (@code IPP_TAG_DOCUMENT@), event notification
1167 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1168 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1169 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1171 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1172 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1173 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1174 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1175 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1176 * (@code IPP_TAG_URISCHEME@).
1178 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1179 * and textWithLanguage string values and must be @code NULL@ for all other
1182 * The @code format@ parameter uses formatting characters compatible with the
1183 * printf family of standard functions. Additional arguments are passed in the
1184 * stdarg pointer @code ap@. The formatted string is truncated as needed to the
1185 * maximum length of the corresponding value type.
1190 ipp_attribute_t
* /* O - New attribute */
1191 ippAddStringfv(ipp_t
*ipp
, /* I - IPP message */
1192 ipp_tag_t group
, /* I - IPP group */
1193 ipp_tag_t value_tag
, /* I - Type of attribute */
1194 const char *name
, /* I - Name of attribute */
1195 const char *language
, /* I - Language code (@code NULL@ for default) */
1196 const char *format
, /* I - Printf-style format string */
1197 va_list ap
) /* I - Additional arguments */
1199 char buffer
[IPP_MAX_TEXT
+ 4];
1200 /* Formatted text string */
1201 ssize_t bytes
, /* Length of formatted value */
1202 max_bytes
; /* Maximum number of bytes for value */
1206 * Range check input...
1209 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1210 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1211 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
1212 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
1216 if ((value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_NAMELANG
)
1217 != (language
!= NULL
))
1221 * Format the string...
1224 if (!strcmp(format
, "%s"))
1227 * Optimize the simple case...
1230 const char *s
= va_arg(ap
, char *);
1236 strlcpy(buffer
, s
, sizeof(buffer
));
1241 * Do a full formatting of the message...
1244 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
1249 * Limit the length of the string...
1256 case IPP_TAG_TEXTLANG
:
1257 max_bytes
= IPP_MAX_TEXT
;
1261 case IPP_TAG_NAMELANG
:
1262 max_bytes
= IPP_MAX_NAME
;
1265 case IPP_TAG_CHARSET
:
1266 max_bytes
= IPP_MAX_CHARSET
;
1269 case IPP_TAG_KEYWORD
:
1270 max_bytes
= IPP_MAX_KEYWORD
;
1273 case IPP_TAG_LANGUAGE
:
1274 max_bytes
= IPP_MAX_LANGUAGE
;
1277 case IPP_TAG_MIMETYPE
:
1278 max_bytes
= IPP_MAX_MIMETYPE
;
1282 max_bytes
= IPP_MAX_URI
;
1285 case IPP_TAG_URISCHEME
:
1286 max_bytes
= IPP_MAX_URISCHEME
;
1290 if (bytes
>= max_bytes
)
1292 char *bufmax
, /* Buffer at max_bytes */
1293 *bufptr
; /* Pointer into buffer */
1295 bufptr
= buffer
+ strlen(buffer
) - 1;
1296 bufmax
= buffer
+ max_bytes
- 1;
1298 while (bufptr
> bufmax
)
1302 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
1313 * Add the formatted string and return...
1316 return (ippAddString(ipp
, group
, value_tag
, name
, language
, buffer
));
1321 * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
1323 * The @code ipp@ parameter refers to an IPP message previously created using
1324 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1326 * The @code group@ parameter specifies the IPP attribute group tag: none
1327 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
1328 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
1329 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
1330 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1332 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1333 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1334 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1335 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1336 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1337 * (@code IPP_TAG_URISCHEME@).
1339 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1340 * textWithLanguage string values and must be @code NULL@ for all other string values.
1343 ipp_attribute_t
* /* O - New attribute */
1345 ipp_t
*ipp
, /* I - IPP message */
1346 ipp_tag_t group
, /* I - IPP group */
1347 ipp_tag_t value_tag
, /* I - Type of attribute */
1348 const char *name
, /* I - Name of attribute */
1349 int num_values
, /* I - Number of values */
1350 const char *language
, /* I - Language code (@code NULL@ for default) */
1351 const char * const *values
) /* I - Values */
1353 int i
; /* Looping var */
1354 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1355 ipp_attribute_t
*attr
; /* New attribute */
1356 _ipp_value_t
*value
; /* Current value */
1357 char code
[32]; /* Language/charset value buffer */
1360 DEBUG_printf(("ippAddStrings(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
1361 "name=\"%s\", num_values=%d, language=\"%s\", values=%p)", ipp
,
1362 group
, ippTagString(group
), value_tag
, ippTagString(value_tag
), name
,
1363 num_values
, language
, values
));
1366 * Range check input...
1369 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_CUPS_MASK
);
1372 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1373 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1374 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1375 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
||
1379 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1380 != (language
!= NULL
))
1383 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1384 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1390 * See if we need to map charset, language, or locale values...
1393 if (language
&& ((int)value_tag
& IPP_TAG_CUPS_CONST
) &&
1394 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1395 value_tag
= temp_tag
; /* Don't do a fast copy */
1396 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_CUPS_CONST
))
1398 for (i
= 0; i
< num_values
; i
++)
1399 if (strcmp(values
[i
], ipp_get_code(values
[i
], code
, sizeof(code
))))
1401 value_tag
= temp_tag
; /* Don't do a fast copy */
1405 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_CUPS_CONST
))
1407 for (i
= 0; i
< num_values
; i
++)
1408 if (strcmp(values
[i
], ipp_lang_code(values
[i
], code
, sizeof(code
))))
1410 value_tag
= temp_tag
; /* Don't do a fast copy */
1416 * Create the attribute...
1419 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
1423 * Initialize the attribute data...
1426 for (i
= num_values
, value
= attr
->values
;
1432 if (value
== attr
->values
)
1434 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1435 value
->string
.language
= (char *)language
;
1437 value
->string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1441 value
->string
.language
= attr
->values
[0].string
.language
;
1446 if ((int)value_tag
& IPP_TAG_CUPS_CONST
)
1447 value
->string
.text
= (char *)*values
++;
1448 else if (value_tag
== IPP_TAG_CHARSET
)
1449 value
->string
.text
= _cupsStrAlloc(ipp_get_code(*values
++, code
, sizeof(code
)));
1450 else if (value_tag
== IPP_TAG_LANGUAGE
)
1451 value
->string
.text
= _cupsStrAlloc(ipp_lang_code(*values
++, code
, sizeof(code
)));
1453 value
->string
.text
= _cupsStrAlloc(*values
++);
1462 * 'ippContainsInteger()' - Determine whether an attribute contains the
1463 * specified value or is within the list of ranges.
1465 * Returns non-zero when the attribute contains either a matching integer or
1466 * enum value, or the value falls within one of the rangeOfInteger values for
1472 int /* O - 1 on a match, 0 on no match */
1474 ipp_attribute_t
*attr
, /* I - Attribute */
1475 int value
) /* I - Integer/enum value */
1477 int i
; /* Looping var */
1478 _ipp_value_t
*avalue
; /* Current attribute value */
1482 * Range check input...
1488 if (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
&&
1489 attr
->value_tag
!= IPP_TAG_RANGE
)
1496 if (attr
->value_tag
== IPP_TAG_RANGE
)
1498 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1499 if (value
>= avalue
->range
.lower
&& value
<= avalue
->range
.upper
)
1504 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1505 if (value
== avalue
->integer
)
1514 * 'ippContainsString()' - Determine whether an attribute contains the
1515 * specified string value.
1517 * Returns non-zero when the attribute contains a matching charset, keyword,
1518 * language, mimeMediaType, name, text, URI, or URI scheme value.
1523 int /* O - 1 on a match, 0 on no match */
1525 ipp_attribute_t
*attr
, /* I - Attribute */
1526 const char *value
) /* I - String value */
1528 int i
; /* Looping var */
1529 _ipp_value_t
*avalue
; /* Current attribute value */
1532 DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", attr
, value
));
1535 * Range check input...
1538 if (!attr
|| !value
)
1540 DEBUG_puts("1ippContainsString: Returning 0 (bad input)");
1548 DEBUG_printf(("1ippContainsString: attr %s, %s with %d values.",
1549 attr
->name
, ippTagString(attr
->value_tag
),
1552 switch (attr
->value_tag
& IPP_TAG_CUPS_MASK
)
1554 case IPP_TAG_CHARSET
:
1555 case IPP_TAG_KEYWORD
:
1556 case IPP_TAG_LANGUAGE
:
1557 case IPP_TAG_MIMETYPE
:
1559 case IPP_TAG_NAMELANG
:
1561 case IPP_TAG_TEXTLANG
:
1563 case IPP_TAG_URISCHEME
:
1564 for (i
= attr
->num_values
, avalue
= attr
->values
;
1568 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1569 attr
->num_values
- i
, avalue
->string
.text
));
1571 if (!strcmp(value
, avalue
->string
.text
))
1573 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1582 DEBUG_puts("1ippContainsString: Returning 0 (no match)");
1589 * 'ippCopyAttribute()' - Copy an attribute.
1591 * The specified attribute, @code attr@, is copied to the destination IPP message.
1592 * When @code quickcopy@ is non-zero, a "shallow" reference copy of the attribute is
1593 * created - this should only be done as long as the original source IPP message will
1594 * not be freed for the life of the destination.
1596 * @since CUPS 1.6/OS X 10.8@
1600 ipp_attribute_t
* /* O - New attribute */
1602 ipp_t
*dst
, /* I - Destination IPP message */
1603 ipp_attribute_t
*srcattr
, /* I - Attribute to copy */
1604 int quickcopy
) /* I - 1 for a referenced copy, 0 for normal */
1606 int i
; /* Looping var */
1607 ipp_attribute_t
*dstattr
; /* Destination attribute */
1608 _ipp_value_t
*srcval
, /* Source value */
1609 *dstval
; /* Destination value */
1612 DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", dst
, srcattr
,
1616 * Range check input...
1619 if (!dst
|| !srcattr
)
1626 quickcopy
= quickcopy
? IPP_TAG_CUPS_CONST
: 0;
1628 switch (srcattr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
1631 dstattr
= ippAddSeparator(dst
);
1634 case IPP_TAG_INTEGER
:
1636 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1637 srcattr
->name
, srcattr
->num_values
, NULL
);
1641 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1643 i
--, srcval
++, dstval
++)
1644 dstval
->integer
= srcval
->integer
;
1647 case IPP_TAG_BOOLEAN
:
1648 dstattr
= ippAddBooleans(dst
, srcattr
->group_tag
, srcattr
->name
,
1649 srcattr
->num_values
, NULL
);
1653 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1655 i
--, srcval
++, dstval
++)
1656 dstval
->boolean
= srcval
->boolean
;
1661 case IPP_TAG_KEYWORD
:
1663 case IPP_TAG_URISCHEME
:
1664 case IPP_TAG_CHARSET
:
1665 case IPP_TAG_LANGUAGE
:
1666 case IPP_TAG_MIMETYPE
:
1667 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1668 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1669 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1675 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1676 dstval
= dstattr
->values
;
1678 i
--, srcval
++, dstval
++)
1679 dstval
->string
.text
= srcval
->string
.text
;
1681 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1683 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1684 dstval
= dstattr
->values
;
1686 i
--, srcval
++, dstval
++)
1687 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1691 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1692 dstval
= dstattr
->values
;
1694 i
--, srcval
++, dstval
++)
1695 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1700 if (srcattr
->num_values
!= 1)
1703 dstattr
= ippAddDate(dst
, srcattr
->group_tag
, srcattr
->name
,
1704 srcattr
->values
[0].date
);
1707 case IPP_TAG_RESOLUTION
:
1708 dstattr
= ippAddResolutions(dst
, srcattr
->group_tag
, srcattr
->name
,
1709 srcattr
->num_values
, IPP_RES_PER_INCH
,
1714 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1716 i
--, srcval
++, dstval
++)
1718 dstval
->resolution
.xres
= srcval
->resolution
.xres
;
1719 dstval
->resolution
.yres
= srcval
->resolution
.yres
;
1720 dstval
->resolution
.units
= srcval
->resolution
.units
;
1724 case IPP_TAG_RANGE
:
1725 dstattr
= ippAddRanges(dst
, srcattr
->group_tag
, srcattr
->name
,
1726 srcattr
->num_values
, NULL
, NULL
);
1730 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1732 i
--, srcval
++, dstval
++)
1734 dstval
->range
.lower
= srcval
->range
.lower
;
1735 dstval
->range
.upper
= srcval
->range
.upper
;
1739 case IPP_TAG_TEXTLANG
:
1740 case IPP_TAG_NAMELANG
:
1741 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1742 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1743 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1749 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1750 dstval
= dstattr
->values
;
1752 i
--, srcval
++, dstval
++)
1754 dstval
->string
.language
= srcval
->string
.language
;
1755 dstval
->string
.text
= srcval
->string
.text
;
1758 else if (srcattr
->value_tag
& IPP_TAG_CUPS_CONST
)
1760 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1761 dstval
= dstattr
->values
;
1763 i
--, srcval
++, dstval
++)
1765 if (srcval
== srcattr
->values
)
1766 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1768 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1770 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1775 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1776 dstval
= dstattr
->values
;
1778 i
--, srcval
++, dstval
++)
1780 if (srcval
== srcattr
->values
)
1781 dstval
->string
.language
= _cupsStrRetain(srcval
->string
.language
);
1783 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1785 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1790 case IPP_TAG_BEGIN_COLLECTION
:
1791 dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
,
1792 srcattr
->num_values
, NULL
);
1796 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1798 i
--, srcval
++, dstval
++)
1800 dstval
->collection
= srcval
->collection
;
1801 srcval
->collection
->use
++;
1805 case IPP_TAG_STRING
:
1807 /* TODO: Implement quick copy for unknown/octetString values */
1808 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1809 srcattr
->name
, srcattr
->num_values
, NULL
);
1813 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1815 i
--, srcval
++, dstval
++)
1817 dstval
->unknown
.length
= srcval
->unknown
.length
;
1819 if (dstval
->unknown
.length
> 0)
1821 if ((dstval
->unknown
.data
= malloc(dstval
->unknown
.length
)) == NULL
)
1822 dstval
->unknown
.length
= 0;
1824 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, dstval
->unknown
.length
);
1827 break; /* anti-compiler-warning-code */
1835 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1837 * Zero or more attributes are copied from the source IPP message, @code@ src, to the
1838 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1839 * reference copy of the attribute is created - this should only be done as long as the
1840 * original source IPP message will not be freed for the life of the destination.
1842 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1843 * attributes that are copied - the function must return 1 to copy the attribute or
1844 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1847 * @since CUPS 1.6/OS X 10.8@
1850 int /* O - 1 on success, 0 on error */
1852 ipp_t
*dst
, /* I - Destination IPP message */
1853 ipp_t
*src
, /* I - Source IPP message */
1854 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1855 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1856 void *context
) /* I - Context pointer */
1858 ipp_attribute_t
*srcattr
; /* Source attribute */
1861 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)",
1862 dst
, src
, quickcopy
, cb
, context
));
1865 * Range check input...
1872 * Loop through source attributes and copy as needed...
1875 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1876 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1877 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1885 * 'ippDateToTime()' - Convert from RFC 1903 Date/Time format to UNIX time
1889 time_t /* O - UNIX time value */
1890 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 1903 date info */
1892 struct tm unixdate
; /* UNIX date/time info */
1893 time_t t
; /* Computed time */
1899 memset(&unixdate
, 0, sizeof(unixdate
));
1902 * RFC-1903 date/time format is:
1904 * Byte(s) Description
1905 * ------- -----------
1906 * 0-1 Year (0 to 65535)
1910 * 5 Minutes (0 to 59)
1911 * 6 Seconds (0 to 60, 60 = "leap second")
1912 * 7 Deciseconds (0 to 9)
1914 * 9 UTC hours (0 to 11)
1915 * 10 UTC minutes (0 to 59)
1918 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1919 unixdate
.tm_mon
= date
[2] - 1;
1920 unixdate
.tm_mday
= date
[3];
1921 unixdate
.tm_hour
= date
[4];
1922 unixdate
.tm_min
= date
[5];
1923 unixdate
.tm_sec
= date
[6];
1925 t
= mktime(&unixdate
);
1928 t
+= date
[9] * 3600 + date
[10] * 60;
1930 t
-= date
[9] * 3600 + date
[10] * 60;
1937 * 'ippDelete()' - Delete an IPP message.
1941 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1943 ipp_attribute_t
*attr
, /* Current attribute */
1944 *next
; /* Next attribute */
1947 DEBUG_printf(("ippDelete(ipp=%p)", ipp
));
1956 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1960 ipp_free_values(attr
, 0, attr
->num_values
);
1963 _cupsStrFree(attr
->name
);
1973 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1975 * @since CUPS 1.1.19/OS X 10.3@
1980 ipp_t
*ipp
, /* I - IPP message */
1981 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1983 ipp_attribute_t
*current
, /* Current attribute */
1984 *prev
; /* Previous attribute */
1987 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", ipp
, attr
,
1988 attr
? attr
->name
: "(null)"));
1991 * Range check input...
1998 * Find the attribute in the list...
2003 for (current
= ipp
->attrs
, prev
= NULL
;
2005 prev
= current
, current
= current
->next
)
2006 if (current
== attr
)
2009 * Found it, remove the attribute from the list...
2013 prev
->next
= current
->next
;
2015 ipp
->attrs
= current
->next
;
2017 if (current
== ipp
->last
)
2028 * Free memory used by the attribute...
2031 ipp_free_values(attr
, 0, attr
->num_values
);
2034 _cupsStrFree(attr
->name
);
2041 * 'ippDeleteValues()' - Delete values in an attribute.
2043 * The @code element@ parameter specifies the first value to delete, starting at
2044 * 0. It must be less than the number of values returned by @link ippGetCount@.
2046 * The @code attr@ parameter may be modified as a result of setting the value.
2048 * Deleting all values in an attribute deletes the attribute.
2050 * @since CUPS 1.6/OS X 10.8@
2053 int /* O - 1 on success, 0 on failure */
2055 ipp_t
*ipp
, /* I - IPP message */
2056 ipp_attribute_t
**attr
, /* IO - Attribute */
2057 int element
, /* I - Index of first value to delete (0-based) */
2058 int count
) /* I - Number of values to delete */
2061 * Range check input...
2064 if (!ipp
|| !attr
|| !*attr
||
2065 element
< 0 || element
>= (*attr
)->num_values
|| count
<= 0 ||
2066 (element
+ count
) >= (*attr
)->num_values
)
2070 * If we are deleting all values, just delete the attribute entirely.
2073 if (count
== (*attr
)->num_values
)
2075 ippDeleteAttribute(ipp
, *attr
);
2081 * Otherwise free the values in question and return.
2084 ipp_free_values(*attr
, element
, count
);
2091 * 'ippFindAttribute()' - Find a named attribute in a request.
2094 ipp_attribute_t
* /* O - Matching attribute */
2095 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
2096 const char *name
, /* I - Name of attribute */
2097 ipp_tag_t type
) /* I - Type of attribute */
2099 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", ipp
,
2100 name
, type
, ippTagString(type
)));
2106 * Reset the current pointer...
2109 ipp
->current
= NULL
;
2112 * Search for the attribute...
2115 return (ippFindNextAttribute(ipp
, name
, type
));
2120 * 'ippFindNextAttribute()' - Find the next named attribute in a request.
2123 ipp_attribute_t
* /* O - Matching attribute */
2124 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
2125 const char *name
, /* I - Name of attribute */
2126 ipp_tag_t type
) /* I - Type of attribute */
2128 ipp_attribute_t
*attr
; /* Current atttribute */
2129 ipp_tag_t value_tag
; /* Value tag */
2132 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))",
2133 ipp
, name
, type
, ippTagString(type
)));
2140 ipp
->prev
= ipp
->current
;
2141 attr
= ipp
->current
->next
;
2149 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
2151 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", attr
,
2154 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2156 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
2157 (value_tag
== type
|| type
== IPP_TAG_ZERO
||
2158 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
2159 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
2161 ipp
->current
= attr
;
2167 ipp
->current
= NULL
;
2175 * 'ippFirstAttribute()' - Return the first attribute in the message.
2177 * @since CUPS 1.6/OS X 10.8@
2180 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
2181 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
2184 * Range check input...
2191 * Return the first attribute...
2194 return (ipp
->current
= ipp
->attrs
);
2199 * 'ippGetBoolean()' - Get a boolean value for an attribute.
2201 * The @code element@ parameter specifies which value to get from 0 to
2202 * @link ippGetCount(attr)@ - 1.
2204 * @since CUPS 1.6/OS X 10.8@
2207 int /* O - Boolean value or -1 on error */
2208 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
2209 int element
) /* I - Value number (0-based) */
2212 * Range check input...
2215 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
2216 element
< 0 || element
>= attr
->num_values
)
2220 * Return the value...
2223 return (attr
->values
[element
].boolean
);
2228 * 'ippGetCollection()' - Get a collection value for an attribute.
2230 * The @code element@ parameter specifies which value to get from 0 to
2231 * @link ippGetCount(attr)@ - 1.
2233 * @since CUPS 1.6/OS X 10.8@
2236 ipp_t
* /* O - Collection value or @code NULL@ on error */
2238 ipp_attribute_t
*attr
, /* I - IPP attribute */
2239 int element
) /* I - Value number (0-based) */
2242 * Range check input...
2245 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
2246 element
< 0 || element
>= attr
->num_values
)
2250 * Return the value...
2253 return (attr
->values
[element
].collection
);
2258 * 'ippGetCount()' - Get the number of values in an attribute.
2260 * @since CUPS 1.6/OS X 10.8@
2263 int /* O - Number of values or -1 on error */
2264 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
2267 * Range check input...
2274 * Return the number of values...
2277 return (attr
->num_values
);
2282 * 'ippGetDate()' - Get a date value for an attribute.
2284 * The @code element@ parameter specifies which value to get from 0 to
2285 * @link ippGetCount(attr)@ - 1.
2287 * @since CUPS 1.6/OS X 10.8@
2290 const ipp_uchar_t
* /* O - Date value or @code NULL@ */
2291 ippGetDate(ipp_attribute_t
*attr
, /* I - IPP attribute */
2292 int element
) /* I - Value number (0-based) */
2295 * Range check input...
2298 if (!attr
|| attr
->value_tag
!= IPP_TAG_DATE
||
2299 element
< 0 || element
>= attr
->num_values
)
2303 * Return the value...
2306 return (attr
->values
[element
].date
);
2311 * 'ippGetGroupTag()' - Get the group associated with an attribute.
2313 * @since CUPS 1.6/OS X 10.8@
2316 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
2317 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2320 * Range check input...
2324 return (IPP_TAG_ZERO
);
2327 * Return the group...
2330 return (attr
->group_tag
);
2335 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
2337 * The @code element@ parameter specifies which value to get from 0 to
2338 * @link ippGetCount(attr)@ - 1.
2340 * @since CUPS 1.6/OS X 10.8@
2343 int /* O - Value or -1 on error */
2344 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
2345 int element
) /* I - Value number (0-based) */
2348 * Range check input...
2351 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
2352 element
< 0 || element
>= attr
->num_values
)
2356 * Return the value...
2359 return (attr
->values
[element
].integer
);
2364 * 'ippGetName()' - Get the attribute name.
2366 * @since CUPS 1.6/OS X 10.8@
2369 const char * /* O - Attribute name or @code NULL@ for separators */
2370 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
2373 * Range check input...
2380 * Return the name...
2383 return (attr
->name
);
2388 * 'ippGetOctetString()' - Get an octetString value from an IPP attribute.
2390 * The @code element@ parameter specifies which value to get from 0 to
2391 * @link ippGetCount(attr)@ - 1.
2396 void * /* O - Pointer to octetString data */
2398 ipp_attribute_t
*attr
, /* I - IPP attribute */
2399 int element
, /* I - Value number (0-based) */
2400 int *datalen
) /* O - Length of octetString data */
2403 * Range check input...
2406 if (!attr
|| attr
->value_tag
!= IPP_TAG_STRING
||
2407 element
< 0 || element
>= attr
->num_values
)
2416 * Return the values...
2420 *datalen
= attr
->values
[element
].unknown
.length
;
2422 return (attr
->values
[element
].unknown
.data
);
2427 * 'ippGetOperation()' - Get the operation ID in an IPP message.
2429 * @since CUPS 1.6/OS X 10.8@
2432 ipp_op_t
/* O - Operation ID or -1 on error */
2433 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
2436 * Range check input...
2440 return ((ipp_op_t
)-1);
2443 * Return the value...
2446 return (ipp
->request
.op
.operation_id
);
2451 * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
2453 * The @code element@ parameter specifies which value to get from 0 to
2454 * @link ippGetCount(attr)@ - 1.
2456 * @since CUPS 1.6/OS X 10.8@
2459 int /* O - Lower value of range or -1 */
2460 ippGetRange(ipp_attribute_t
*attr
, /* I - IPP attribute */
2461 int element
, /* I - Value number (0-based) */
2462 int *uppervalue
)/* O - Upper value of range */
2465 * Range check input...
2468 if (!attr
|| attr
->value_tag
!= IPP_TAG_RANGE
||
2469 element
< 0 || element
>= attr
->num_values
)
2478 * Return the values...
2482 *uppervalue
= attr
->values
[element
].range
.upper
;
2484 return (attr
->values
[element
].range
.lower
);
2489 * 'ippGetRequestId()' - Get the request ID from an IPP message.
2491 * @since CUPS 1.6/OS X 10.8@
2494 int /* O - Request ID or -1 on error */
2495 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
2498 * Range check input...
2505 * Return the request ID...
2508 return (ipp
->request
.any
.request_id
);
2513 * 'ippGetResolution()' - Get a resolution value for an attribute.
2515 * The @code element@ parameter specifies which value to get from 0 to
2516 * @link ippGetCount(attr)@ - 1.
2518 * @since CUPS 1.6/OS X 10.8@
2521 int /* O - Horizontal/cross feed resolution or -1 */
2523 ipp_attribute_t
*attr
, /* I - IPP attribute */
2524 int element
, /* I - Value number (0-based) */
2525 int *yres
, /* O - Vertical/feed resolution */
2526 ipp_res_t
*units
) /* O - Units for resolution */
2529 * Range check input...
2532 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
2533 element
< 0 || element
>= attr
->num_values
)
2537 * Return the value...
2541 *yres
= attr
->values
[element
].resolution
.yres
;
2544 *units
= attr
->values
[element
].resolution
.units
;
2546 return (attr
->values
[element
].resolution
.xres
);
2551 * 'ippGetState()' - Get the IPP message state.
2553 * @since CUPS 1.6/OS X 10.8@
2556 ipp_state_t
/* O - IPP message state value */
2557 ippGetState(ipp_t
*ipp
) /* I - IPP message */
2560 * Range check input...
2564 return (IPP_STATE_IDLE
);
2567 * Return the value...
2570 return (ipp
->state
);
2575 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2577 * @since CUPS 1.6/OS X 10.8@
2580 ipp_status_t
/* O - Status code in IPP message */
2581 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2584 * Range check input...
2588 return (IPP_STATUS_ERROR_INTERNAL
);
2591 * Return the value...
2594 return (ipp
->request
.status
.status_code
);
2599 * 'ippGetString()' - Get the string and optionally the language code for an attribute.
2601 * The @code element@ parameter specifies which value to get from 0 to
2602 * @link ippGetCount(attr)@ - 1.
2604 * @since CUPS 1.6/OS X 10.8@
2608 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2609 int element
, /* I - Value number (0-based) */
2610 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2613 * Range check input...
2616 if (!attr
|| element
< 0 || element
>= attr
->num_values
||
2617 (attr
->value_tag
!= IPP_TAG_TEXTLANG
&& attr
->value_tag
!= IPP_TAG_NAMELANG
&&
2618 (attr
->value_tag
< IPP_TAG_TEXT
|| attr
->value_tag
> IPP_TAG_MIMETYPE
)))
2622 * Return the value...
2626 *language
= attr
->values
[element
].string
.language
;
2628 return (attr
->values
[element
].string
.text
);
2633 * 'ippGetValueTag()' - Get the value tag for an attribute.
2635 * @since CUPS 1.6/OS X 10.8@
2638 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2639 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2642 * Range check input...
2646 return (IPP_TAG_ZERO
);
2649 * Return the value...
2652 return (attr
->value_tag
& IPP_TAG_CUPS_MASK
);
2657 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2659 * @since CUPS 1.6/OS X 10.8@
2662 int /* O - Major version number or -1 on error */
2663 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2664 int *minor
) /* O - Minor version number or @code NULL@ */
2667 * Range check input...
2679 * Return the value...
2683 *minor
= ipp
->request
.any
.version
[1];
2685 return (ipp
->request
.any
.version
[0]);
2690 * 'ippLength()' - Compute the length of an IPP message.
2693 size_t /* O - Size of IPP message */
2694 ippLength(ipp_t
*ipp
) /* I - IPP message */
2696 return (ipp_length(ipp
, 0));
2701 * 'ippNextAttribute()' - Return the next attribute in the message.
2703 * @since CUPS 1.6/OS X 10.8@
2706 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2707 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2710 * Range check input...
2713 if (!ipp
|| !ipp
->current
)
2717 * Return the next attribute...
2720 return (ipp
->current
= ipp
->current
->next
);
2725 * 'ippNew()' - Allocate a new IPP message.
2728 ipp_t
* /* O - New IPP message */
2731 ipp_t
*temp
; /* New IPP message */
2732 _cups_globals_t
*cg
= _cupsGlobals();
2736 DEBUG_puts("ippNew()");
2738 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2741 * Set default version - usually 2.0...
2744 temp
->request
.any
.version
[0] = cg
->server_version
/ 10;
2745 temp
->request
.any
.version
[1] = cg
->server_version
% 10;
2749 DEBUG_printf(("1ippNew: Returning %p", temp
));
2756 * 'ippNewRequest()' - Allocate a new IPP request message.
2758 * The new request message is initialized with the attributes-charset and
2759 * attributes-natural-language attributes added. The
2760 * attributes-natural-language value is derived from the current locale.
2762 * @since CUPS 1.2/OS X 10.5@
2765 ipp_t
* /* O - IPP request message */
2766 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2768 ipp_t
*request
; /* IPP request message */
2769 cups_lang_t
*language
; /* Current language localization */
2770 static int request_id
= 0; /* Current request ID */
2771 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2772 /* Mutex for request ID */
2775 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2778 * Create a new IPP message...
2781 if ((request
= ippNew()) == NULL
)
2785 * Set the operation and request ID...
2788 _cupsMutexLock(&request_mutex
);
2790 request
->request
.op
.operation_id
= op
;
2791 request
->request
.op
.request_id
= ++request_id
;
2793 _cupsMutexUnlock(&request_mutex
);
2796 * Use UTF-8 as the character set...
2799 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2800 "attributes-charset", NULL
, "utf-8");
2803 * Get the language from the current locale...
2806 language
= cupsLangDefault();
2808 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2809 "attributes-natural-language", NULL
, language
->language
);
2812 * Return the new request...
2820 * 'ippNewResponse()' - Allocate a new IPP response message.
2822 * The new response message is initialized with the same version-number,
2823 * request-id, attributes-charset, and attributes-natural-language as the
2824 * provided request message. If the attributes-charset or
2825 * attributes-natural-language attributes are missing from the request,
2826 * "utf-8" and a value derived from the current locale are substituted,
2832 ipp_t
* /* O - IPP response message */
2833 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2835 ipp_t
*response
; /* IPP response message */
2836 ipp_attribute_t
*attr
; /* Current attribute */
2840 * Range check input...
2847 * Create a new IPP message...
2850 if ((response
= ippNew()) == NULL
)
2854 * Copy the request values over to the response...
2857 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2858 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2859 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2862 * The first attribute MUST be attributes-charset...
2865 attr
= request
->attrs
;
2867 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2868 attr
->group_tag
== IPP_TAG_OPERATION
&&
2869 attr
->value_tag
== IPP_TAG_CHARSET
&&
2870 attr
->num_values
== 1)
2873 * Copy charset from request...
2876 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2877 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2882 * Use "utf-8" as the default...
2885 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2886 "attributes-charset", NULL
, "utf-8");
2890 * Then attributes-natural-language...
2896 if (attr
&& attr
->name
&&
2897 !strcmp(attr
->name
, "attributes-natural-language") &&
2898 attr
->group_tag
== IPP_TAG_OPERATION
&&
2899 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2900 attr
->num_values
== 1)
2903 * Copy language from request...
2906 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2907 "attributes-natural-language", NULL
,
2908 attr
->values
[0].string
.text
);
2913 * Use the language from the current locale...
2916 cups_lang_t
*language
= cupsLangDefault();
2917 /* Current locale */
2919 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2920 "attributes-natural-language", NULL
, language
->language
);
2928 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2931 ipp_state_t
/* O - Current state */
2932 ippRead(http_t
*http
, /* I - HTTP connection */
2933 ipp_t
*ipp
) /* I - IPP data */
2935 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
,
2936 http
, ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2939 return (IPP_STATE_ERROR
);
2941 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
,
2944 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2950 * 'ippReadFile()' - Read data for an IPP message from a file.
2952 * @since CUPS 1.1.19/OS X 10.3@
2955 ipp_state_t
/* O - Current state */
2956 ippReadFile(int fd
, /* I - HTTP data */
2957 ipp_t
*ipp
) /* I - IPP data */
2959 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, ipp
));
2961 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2966 * 'ippReadIO()' - Read data for an IPP message.
2968 * @since CUPS 1.2/OS X 10.5@
2971 ipp_state_t
/* O - Current state */
2972 ippReadIO(void *src
, /* I - Data source */
2973 ipp_iocb_t cb
, /* I - Read callback function */
2974 int blocking
, /* I - Use blocking IO? */
2975 ipp_t
*parent
, /* I - Parent request, if any */
2976 ipp_t
*ipp
) /* I - IPP data */
2978 int n
; /* Length of data */
2979 unsigned char *buffer
, /* Data buffer */
2980 string
[IPP_MAX_TEXT
],
2981 /* Small string buffer */
2982 *bufptr
; /* Pointer into buffer */
2983 ipp_attribute_t
*attr
; /* Current attribute */
2984 ipp_tag_t tag
; /* Current tag */
2985 ipp_tag_t value_tag
; /* Current value tag */
2986 _ipp_value_t
*value
; /* Current value */
2989 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)",
2990 src
, cb
, blocking
, parent
, ipp
));
2991 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_STATE_ERROR
));
2994 return (IPP_STATE_ERROR
);
2996 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2998 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2999 return (IPP_STATE_ERROR
);
3004 case IPP_STATE_IDLE
:
3005 ipp
->state
++; /* Avoid common problem... */
3007 case IPP_STATE_HEADER
:
3011 * Get the request header...
3014 if ((*cb
)(src
, buffer
, 8) < 8)
3016 DEBUG_puts("1ippReadIO: Unable to read header.");
3017 _cupsBufferRelease((char *)buffer
);
3018 return (IPP_STATE_ERROR
);
3022 * Then copy the request header over...
3025 ipp
->request
.any
.version
[0] = buffer
[0];
3026 ipp
->request
.any
.version
[1] = buffer
[1];
3027 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
3028 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
3029 buffer
[6]) << 8) | buffer
[7];
3031 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
3032 DEBUG_printf(("2ippReadIO: op_status=%04x",
3033 ipp
->request
.any
.op_status
));
3034 DEBUG_printf(("2ippReadIO: request_id=%d",
3035 ipp
->request
.any
.request_id
));
3038 ipp
->state
= IPP_STATE_ATTRIBUTE
;
3039 ipp
->current
= NULL
;
3040 ipp
->curtag
= IPP_TAG_ZERO
;
3041 ipp
->prev
= ipp
->last
;
3044 * If blocking is disabled, stop here...
3050 case IPP_STATE_ATTRIBUTE
:
3053 if ((*cb
)(src
, buffer
, 1) < 1)
3055 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3056 _cupsBufferRelease((char *)buffer
);
3057 return (IPP_STATE_ERROR
);
3060 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p",
3061 ipp
->current
, ipp
->prev
));
3064 * Read this attribute...
3067 tag
= (ipp_tag_t
)buffer
[0];
3068 if (tag
== IPP_TAG_EXTENSION
)
3071 * Read 32-bit "extension" tag...
3074 if ((*cb
)(src
, buffer
, 4) < 1)
3076 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3077 _cupsBufferRelease((char *)buffer
);
3078 return (IPP_STATE_ERROR
);
3081 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
3082 buffer
[2]) << 8) | buffer
[3]);
3084 if (tag
& IPP_TAG_CUPS_CONST
)
3087 * Fail if the high bit is set in the tag...
3090 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
3091 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
3092 _cupsBufferRelease((char *)buffer
);
3093 return (IPP_STATE_ERROR
);
3097 if (tag
== IPP_TAG_END
)
3100 * No more attributes left...
3103 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
3105 ipp
->state
= IPP_STATE_DATA
;
3108 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3111 * Group tag... Set the current group and continue...
3114 if (ipp
->curtag
== tag
)
3115 ipp
->prev
= ippAddSeparator(ipp
);
3116 else if (ipp
->current
)
3117 ipp
->prev
= ipp
->current
;
3120 ipp
->current
= NULL
;
3121 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
,
3122 ippTagString(tag
), ipp
->prev
));
3126 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3127 ippTagString(tag
)));
3133 if ((*cb
)(src
, buffer
, 2) < 2)
3135 DEBUG_puts("1ippReadIO: unable to read name length.");
3136 _cupsBufferRelease((char *)buffer
);
3137 return (IPP_STATE_ERROR
);
3140 n
= (buffer
[0] << 8) | buffer
[1];
3142 if (n
>= IPP_BUF_SIZE
)
3144 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP name larger than 32767 bytes."), 1);
3145 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3146 _cupsBufferRelease((char *)buffer
);
3147 return (IPP_STATE_ERROR
);
3150 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3152 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3153 tag
!= IPP_TAG_END_COLLECTION
)
3156 * More values for current attribute...
3159 if (ipp
->current
== NULL
)
3161 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP attribute has no name."), 1);
3162 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3163 _cupsBufferRelease((char *)buffer
);
3164 return (IPP_STATE_ERROR
);
3167 attr
= ipp
->current
;
3168 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_CUPS_MASK
);
3171 * Make sure we aren't adding a new value of a different
3175 if (value_tag
== IPP_TAG_ZERO
)
3178 * Setting the value of a collection member...
3181 attr
->value_tag
= tag
;
3183 else if (value_tag
== IPP_TAG_TEXTLANG
||
3184 value_tag
== IPP_TAG_NAMELANG
||
3185 (value_tag
>= IPP_TAG_TEXT
&&
3186 value_tag
<= IPP_TAG_MIMETYPE
))
3189 * String values can sometimes come across in different
3190 * forms; accept sets of differing values...
3193 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3194 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3195 tag
!= IPP_TAG_NOVALUE
)
3197 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3198 _("IPP 1setOf attribute with incompatible value "
3200 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3201 value_tag
, ippTagString(value_tag
), tag
,
3202 ippTagString(tag
)));
3203 _cupsBufferRelease((char *)buffer
);
3204 return (IPP_STATE_ERROR
);
3207 if (value_tag
!= tag
)
3209 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3210 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3211 ippSetValueTag(ipp
, &attr
, tag
);
3214 else if (value_tag
== IPP_TAG_INTEGER
||
3215 value_tag
== IPP_TAG_RANGE
)
3218 * Integer and rangeOfInteger values can sometimes be mixed; accept
3219 * sets of differing values...
3222 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3224 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3225 _("IPP 1setOf attribute with incompatible value "
3227 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3228 value_tag
, ippTagString(value_tag
), tag
,
3229 ippTagString(tag
)));
3230 _cupsBufferRelease((char *)buffer
);
3231 return (IPP_STATE_ERROR
);
3234 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3237 * Convert integer values to rangeOfInteger values...
3240 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3241 "rangeOfInteger.", attr
->name
));
3242 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3245 else if (value_tag
!= tag
)
3247 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3248 _("IPP 1setOf attribute with incompatible value "
3250 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3251 value_tag
, ippTagString(value_tag
), tag
,
3252 ippTagString(tag
)));
3253 _cupsBufferRelease((char *)buffer
);
3254 return (IPP_STATE_ERROR
);
3258 * Finally, reallocate the attribute array as needed...
3261 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3263 _cupsBufferRelease((char *)buffer
);
3264 return (IPP_STATE_ERROR
);
3267 else if (tag
== IPP_TAG_MEMBERNAME
)
3270 * Name must be length 0!
3275 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP member name is not empty."), 1);
3276 DEBUG_puts("1ippReadIO: member name not empty.");
3277 _cupsBufferRelease((char *)buffer
);
3278 return (IPP_STATE_ERROR
);
3282 ipp
->prev
= ipp
->current
;
3284 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3287 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3288 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3289 _cupsBufferRelease((char *)buffer
);
3290 return (IPP_STATE_ERROR
);
3293 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p",
3294 ipp
->current
, ipp
->prev
));
3296 value
= attr
->values
;
3298 else if (tag
!= IPP_TAG_END_COLLECTION
)
3301 * New attribute; read the name and add it...
3304 if ((*cb
)(src
, buffer
, n
) < n
)
3306 DEBUG_puts("1ippReadIO: unable to read name.");
3307 _cupsBufferRelease((char *)buffer
);
3308 return (IPP_STATE_ERROR
);
3314 ipp
->prev
= ipp
->current
;
3316 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3319 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3320 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3321 _cupsBufferRelease((char *)buffer
);
3322 return (IPP_STATE_ERROR
);
3325 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, "
3326 "ipp->prev=%p", buffer
, ipp
->current
, ipp
->prev
));
3328 value
= attr
->values
;
3336 if ((*cb
)(src
, buffer
, 2) < 2)
3338 DEBUG_puts("1ippReadIO: unable to read value length.");
3339 _cupsBufferRelease((char *)buffer
);
3340 return (IPP_STATE_ERROR
);
3343 n
= (buffer
[0] << 8) | buffer
[1];
3344 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3346 if (n
>= IPP_BUF_SIZE
)
3348 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3349 _("IPP value larger than 32767 bytes."), 1);
3350 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3351 _cupsBufferRelease((char *)buffer
);
3352 return (IPP_STATE_ERROR
);
3357 case IPP_TAG_INTEGER
:
3361 if (tag
== IPP_TAG_INTEGER
)
3362 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3363 _("IPP integer value not 4 bytes."), 1);
3365 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3366 _("IPP enum value not 4 bytes."), 1);
3367 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3368 _cupsBufferRelease((char *)buffer
);
3369 return (IPP_STATE_ERROR
);
3372 if ((*cb
)(src
, buffer
, 4) < 4)
3374 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3375 _cupsBufferRelease((char *)buffer
);
3376 return (IPP_STATE_ERROR
);
3379 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3382 if (attr
->value_tag
== IPP_TAG_RANGE
)
3383 value
->range
.lower
= value
->range
.upper
= n
;
3388 case IPP_TAG_BOOLEAN
:
3391 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP boolean value not 1 byte."),
3393 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3394 _cupsBufferRelease((char *)buffer
);
3395 return (IPP_STATE_ERROR
);
3398 if ((*cb
)(src
, buffer
, 1) < 1)
3400 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3401 _cupsBufferRelease((char *)buffer
);
3402 return (IPP_STATE_ERROR
);
3405 value
->boolean
= buffer
[0];
3408 case IPP_TAG_NOVALUE
:
3409 case IPP_TAG_NOTSETTABLE
:
3410 case IPP_TAG_DELETEATTR
:
3411 case IPP_TAG_ADMINDEFINE
:
3413 * These value types are not supposed to have values, however
3414 * some vendors (Brother) do not implement IPP correctly and so
3415 * we need to map non-empty values to text...
3418 if (attr
->value_tag
== tag
)
3423 attr
->value_tag
= IPP_TAG_TEXT
;
3428 case IPP_TAG_KEYWORD
:
3430 case IPP_TAG_URISCHEME
:
3431 case IPP_TAG_CHARSET
:
3432 case IPP_TAG_LANGUAGE
:
3433 case IPP_TAG_MIMETYPE
:
3436 if ((*cb
)(src
, buffer
, n
) < n
)
3438 DEBUG_puts("1ippReadIO: unable to read string value.");
3439 _cupsBufferRelease((char *)buffer
);
3440 return (IPP_STATE_ERROR
);
3445 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3446 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3452 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
, _("IPP date value not 11 bytes."), 1);
3453 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3454 _cupsBufferRelease((char *)buffer
);
3455 return (IPP_STATE_ERROR
);
3458 if ((*cb
)(src
, value
->date
, 11) < 11)
3460 DEBUG_puts("1ippReadIO: Unable to read date value.");
3461 _cupsBufferRelease((char *)buffer
);
3462 return (IPP_STATE_ERROR
);
3466 case IPP_TAG_RESOLUTION
:
3469 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3470 _("IPP resolution value not 9 bytes."), 1);
3471 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3472 _cupsBufferRelease((char *)buffer
);
3473 return (IPP_STATE_ERROR
);
3476 if ((*cb
)(src
, buffer
, 9) < 9)
3478 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3479 _cupsBufferRelease((char *)buffer
);
3480 return (IPP_STATE_ERROR
);
3483 value
->resolution
.xres
=
3484 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3486 value
->resolution
.yres
=
3487 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3489 value
->resolution
.units
=
3490 (ipp_res_t
)buffer
[8];
3493 case IPP_TAG_RANGE
:
3496 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3497 _("IPP rangeOfInteger value not 8 bytes."), 1);
3498 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3500 _cupsBufferRelease((char *)buffer
);
3501 return (IPP_STATE_ERROR
);
3504 if ((*cb
)(src
, buffer
, 8) < 8)
3506 DEBUG_puts("1ippReadIO: Unable to read range value.");
3507 _cupsBufferRelease((char *)buffer
);
3508 return (IPP_STATE_ERROR
);
3511 value
->range
.lower
=
3512 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3514 value
->range
.upper
=
3515 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3519 case IPP_TAG_TEXTLANG
:
3520 case IPP_TAG_NAMELANG
:
3523 if (tag
== IPP_TAG_TEXTLANG
)
3524 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3525 _("IPP textWithLanguage value less than "
3526 "minimum 4 bytes."), 1);
3528 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3529 _("IPP nameWithLanguage value less than "
3530 "minimum 4 bytes."), 1);
3531 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3533 _cupsBufferRelease((char *)buffer
);
3534 return (IPP_STATE_ERROR
);
3537 if ((*cb
)(src
, buffer
, n
) < n
)
3539 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3541 _cupsBufferRelease((char *)buffer
);
3542 return (IPP_STATE_ERROR
);
3548 * text-with-language and name-with-language are composite
3557 n
= (bufptr
[0] << 8) | bufptr
[1];
3559 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) ||
3560 n
>= sizeof(string
))
3562 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3563 _("IPP language length overflows value."), 1);
3564 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3566 _cupsBufferRelease((char *)buffer
);
3567 return (IPP_STATE_ERROR
);
3569 else if (n
>= IPP_MAX_LANGUAGE
)
3571 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3572 _("IPP language length too large."), 1);
3573 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3575 _cupsBufferRelease((char *)buffer
);
3576 return (IPP_STATE_ERROR
);
3579 memcpy(string
, bufptr
+ 2, n
);
3582 value
->string
.language
= _cupsStrAlloc((char *)string
);
3585 n
= (bufptr
[0] << 8) | bufptr
[1];
3587 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3589 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3590 _("IPP string length overflows value."), 1);
3591 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3592 _cupsBufferRelease((char *)buffer
);
3593 return (IPP_STATE_ERROR
);
3596 bufptr
[2 + n
] = '\0';
3597 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3600 case IPP_TAG_BEGIN_COLLECTION
:
3602 * Oh, boy, here comes a collection value, so read it...
3605 value
->collection
= ippNew();
3609 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3610 _("IPP begCollection value not 0 bytes."), 1);
3611 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3613 _cupsBufferRelease((char *)buffer
);
3614 return (IPP_STATE_ERROR
);
3617 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_STATE_ERROR
)
3619 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3620 _cupsBufferRelease((char *)buffer
);
3621 return (IPP_STATE_ERROR
);
3625 case IPP_TAG_END_COLLECTION
:
3626 _cupsBufferRelease((char *)buffer
);
3630 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3631 _("IPP endCollection value not 0 bytes."), 1);
3632 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3634 return (IPP_STATE_ERROR
);
3637 DEBUG_puts("1ippReadIO: endCollection tag...");
3638 return (ipp
->state
= IPP_STATE_DATA
);
3640 case IPP_TAG_MEMBERNAME
:
3642 * The value the name of the member in the collection, which
3643 * we need to carry over...
3648 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3649 _("IPP memberName with no attribute."), 1);
3650 DEBUG_puts("1ippReadIO: Member name without attribute.");
3651 _cupsBufferRelease((char *)buffer
);
3652 return (IPP_STATE_ERROR
);
3656 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3657 _("IPP memberName value is empty."), 1);
3658 DEBUG_puts("1ippReadIO: Empty member name value.");
3659 _cupsBufferRelease((char *)buffer
);
3660 return (IPP_STATE_ERROR
);
3662 else if ((*cb
)(src
, buffer
, n
) < n
)
3664 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3665 _cupsBufferRelease((char *)buffer
);
3666 return (IPP_STATE_ERROR
);
3670 attr
->name
= _cupsStrAlloc((char *)buffer
);
3673 * Since collection members are encoded differently than
3674 * regular attributes, make sure we don't start with an
3678 attr
->num_values
--;
3680 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3683 default : /* Other unsupported values */
3684 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3686 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
3687 _("IPP octetString length too large."), 1);
3688 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3690 _cupsBufferRelease((char *)buffer
);
3691 return (IPP_STATE_ERROR
);
3694 value
->unknown
.length
= n
;
3698 if ((value
->unknown
.data
= malloc(n
)) == NULL
)
3700 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
3701 DEBUG_puts("1ippReadIO: Unable to allocate value");
3702 _cupsBufferRelease((char *)buffer
);
3703 return (IPP_STATE_ERROR
);
3706 if ((*cb
)(src
, value
->unknown
.data
, n
) < n
)
3708 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3709 _cupsBufferRelease((char *)buffer
);
3710 return (IPP_STATE_ERROR
);
3714 value
->unknown
.data
= NULL
;
3719 * If blocking is disabled, stop here...
3727 case IPP_STATE_DATA
:
3731 break; /* anti-compiler-warning-code */
3734 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3735 _cupsBufferRelease((char *)buffer
);
3737 return (ipp
->state
);
3742 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3744 * The @code ipp@ parameter refers to an IPP message previously created using
3745 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3747 * The @code attr@ parameter may be modified as a result of setting the value.
3749 * The @code element@ parameter specifies which value to set from 0 to
3750 * @link ippGetCount(attr)@.
3752 * @since CUPS 1.6/OS X 10.8@
3755 int /* O - 1 on success, 0 on failure */
3756 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3757 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3758 int element
, /* I - Value number (0-based) */
3759 int boolvalue
)/* I - Boolean value */
3761 _ipp_value_t
*value
; /* Current value */
3765 * Range check input...
3768 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3769 element
< 0 || element
> (*attr
)->num_values
)
3773 * Set the value and return...
3776 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3777 value
->boolean
= boolvalue
;
3779 return (value
!= NULL
);
3784 * 'ippSetCollection()' - Set a collection value in an attribute.
3786 * The @code ipp@ parameter refers to an IPP message previously created using
3787 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3789 * The @code attr@ parameter may be modified as a result of setting the value.
3791 * The @code element@ parameter specifies which value to set from 0 to
3792 * @link ippGetCount(attr)@.
3794 * @since CUPS 1.6/OS X 10.8@
3797 int /* O - 1 on success, 0 on failure */
3799 ipp_t
*ipp
, /* I - IPP message */
3800 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3801 int element
, /* I - Value number (0-based) */
3802 ipp_t
*colvalue
) /* I - Collection value */
3804 _ipp_value_t
*value
; /* Current value */
3808 * Range check input...
3811 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3812 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3816 * Set the value and return...
3819 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3821 if (value
->collection
)
3822 ippDelete(value
->collection
);
3824 value
->collection
= colvalue
;
3828 return (value
!= NULL
);
3833 * 'ippSetDate()' - Set a date value in an attribute.
3835 * The @code ipp@ parameter refers to an IPP message previously created using
3836 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3838 * The @code attr@ parameter may be modified as a result of setting the value.
3840 * The @code element@ parameter specifies which value to set from 0 to
3841 * @link ippGetCount(attr)@.
3843 * @since CUPS 1.6/OS X 10.8@
3846 int /* O - 1 on success, 0 on failure */
3847 ippSetDate(ipp_t
*ipp
, /* I - IPP message */
3848 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3849 int element
, /* I - Value number (0-based) */
3850 const ipp_uchar_t
*datevalue
)/* I - Date value */
3852 _ipp_value_t
*value
; /* Current value */
3856 * Range check input...
3859 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3860 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3864 * Set the value and return...
3867 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3868 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3870 return (value
!= NULL
);
3875 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3877 * The @code ipp@ parameter refers to an IPP message previously created using
3878 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3880 * The @code attr@ parameter may be modified as a result of setting the value.
3882 * The @code group@ parameter specifies the IPP attribute group tag: none
3883 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3884 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3885 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3886 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3888 * @since CUPS 1.6/OS X 10.8@
3891 int /* O - 1 on success, 0 on failure */
3893 ipp_t
*ipp
, /* I - IPP message */
3894 ipp_attribute_t
**attr
, /* IO - Attribute */
3895 ipp_tag_t group_tag
) /* I - Group tag */
3898 * Range check input - group tag must be 0x01 to 0x0F, per RFC 2911...
3901 if (!ipp
|| !attr
|| !*attr
||
3902 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3903 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3907 * Set the group tag and return...
3910 (*attr
)->group_tag
= group_tag
;
3917 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3919 * The @code ipp@ parameter refers to an IPP message previously created using
3920 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3922 * The @code attr@ parameter may be modified as a result of setting the value.
3924 * The @code element@ parameter specifies which value to set from 0 to
3925 * @link ippGetCount(attr)@.
3927 * @since CUPS 1.6/OS X 10.8@
3930 int /* O - 1 on success, 0 on failure */
3931 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3932 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3933 int element
, /* I - Value number (0-based) */
3934 int intvalue
) /* I - Integer/enum value */
3936 _ipp_value_t
*value
; /* Current value */
3940 * Range check input...
3943 if (!ipp
|| !attr
|| !*attr
||
3944 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3945 element
< 0 || element
> (*attr
)->num_values
)
3949 * Set the value and return...
3952 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3953 value
->integer
= intvalue
;
3955 return (value
!= NULL
);
3960 * 'ippSetName()' - Set the name of an attribute.
3962 * The @code ipp@ parameter refers to an IPP message previously created using
3963 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3965 * The @code attr@ parameter may be modified as a result of setting the value.
3967 * @since CUPS 1.6/OS X 10.8@
3970 int /* O - 1 on success, 0 on failure */
3971 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3972 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3973 const char *name
) /* I - Attribute name */
3975 char *temp
; /* Temporary name value */
3979 * Range check input...
3982 if (!ipp
|| !attr
|| !*attr
)
3986 * Set the value and return...
3989 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3992 _cupsStrFree((*attr
)->name
);
3994 (*attr
)->name
= temp
;
3997 return (temp
!= NULL
);
4002 * 'ippSetOctetString()' - Set an octetString value in an IPP attribute.
4004 * The @code ipp@ parameter refers to an IPP message previously created using
4005 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4007 * The @code attr@ parameter may be modified as a result of setting the value.
4009 * The @code element@ parameter specifies which value to set from 0 to
4010 * @link ippGetCount(attr)@.
4015 int /* O - 1 on success, 0 on failure */
4017 ipp_t
*ipp
, /* I - IPP message */
4018 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4019 int element
, /* I - Value number (0-based) */
4020 const void *data
, /* I - Pointer to octetString data */
4021 int datalen
) /* I - Length of octetString data */
4023 _ipp_value_t
*value
; /* Current value */
4027 * Range check input...
4030 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_STRING
||
4031 element
< 0 || element
> (*attr
)->num_values
||
4032 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
4036 * Set the value and return...
4039 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4041 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4044 * Just copy the pointer...
4047 value
->unknown
.data
= (void *)data
;
4048 value
->unknown
.length
= datalen
;
4056 if (value
->unknown
.data
)
4059 * Free previous data...
4062 free(value
->unknown
.data
);
4064 value
->unknown
.data
= NULL
;
4065 value
->unknown
.length
= 0;
4070 void *temp
; /* Temporary data pointer */
4072 if ((temp
= malloc(datalen
)) != NULL
)
4074 memcpy(temp
, data
, datalen
);
4076 value
->unknown
.data
= temp
;
4077 value
->unknown
.length
= datalen
;
4085 return (value
!= NULL
);
4090 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
4092 * The @code ipp@ parameter refers to an IPP message previously created using
4093 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4095 * @since CUPS 1.6/OS X 10.8@
4098 int /* O - 1 on success, 0 on failure */
4099 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
4100 ipp_op_t op
) /* I - Operation ID */
4103 * Range check input...
4110 * Set the operation and return...
4113 ipp
->request
.op
.operation_id
= op
;
4120 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
4122 * The @code ipp@ parameter refers to an IPP message previously created using
4123 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4125 * The @code attr@ parameter may be modified as a result of setting the value.
4127 * The @code element@ parameter specifies which value to set from 0 to
4128 * @link ippGetCount(attr)@.
4130 * @since CUPS 1.6/OS X 10.8@
4133 int /* O - 1 on success, 0 on failure */
4134 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
4135 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4136 int element
, /* I - Value number (0-based) */
4137 int lowervalue
, /* I - Lower bound for range */
4138 int uppervalue
) /* I - Upper bound for range */
4140 _ipp_value_t
*value
; /* Current value */
4144 * Range check input...
4147 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4148 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4152 * Set the value and return...
4155 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4157 value
->range
.lower
= lowervalue
;
4158 value
->range
.upper
= uppervalue
;
4161 return (value
!= NULL
);
4166 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4168 * The @code ipp@ parameter refers to an IPP message previously created using
4169 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4171 * The @code request_id@ parameter must be greater than 0.
4173 * @since CUPS 1.6/OS X 10.8@
4176 int /* O - 1 on success, 0 on failure */
4177 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4178 int request_id
) /* I - Request ID */
4181 * Range check input; not checking request_id values since ipptool wants to send
4182 * invalid values for conformance testing and a bad request_id does not affect the
4183 * encoding of a message...
4190 * Set the request ID and return...
4193 ipp
->request
.any
.request_id
= request_id
;
4200 * 'ippSetResolution()' - Set a resolution value in an attribute.
4202 * The @code ipp@ parameter refers to an IPP message previously created using
4203 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4205 * The @code attr@ parameter may be modified as a result of setting the value.
4207 * The @code element@ parameter specifies which value to set from 0 to
4208 * @link ippGetCount(attr)@.
4210 * @since CUPS 1.6/OS X 10.8@
4213 int /* O - 1 on success, 0 on failure */
4215 ipp_t
*ipp
, /* I - IPP message */
4216 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4217 int element
, /* I - Value number (0-based) */
4218 ipp_res_t unitsvalue
, /* I - Resolution units */
4219 int xresvalue
, /* I - Horizontal/cross feed resolution */
4220 int yresvalue
) /* I - Vertical/feed resolution */
4222 _ipp_value_t
*value
; /* Current value */
4226 * Range check input...
4229 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4230 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4231 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4235 * Set the value and return...
4238 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4240 value
->resolution
.units
= unitsvalue
;
4241 value
->resolution
.xres
= xresvalue
;
4242 value
->resolution
.yres
= yresvalue
;
4245 return (value
!= NULL
);
4250 * 'ippSetState()' - Set the current state of the IPP message.
4252 * @since CUPS 1.6/OS X 10.8@
4255 int /* O - 1 on success, 0 on failure */
4256 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4257 ipp_state_t state
) /* I - IPP state value */
4260 * Range check input...
4267 * Set the state and return...
4271 ipp
->current
= NULL
;
4278 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4280 * The @code ipp@ parameter refers to an IPP message previously created using
4281 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4283 * @since CUPS 1.6/OS X 10.8@
4286 int /* O - 1 on success, 0 on failure */
4287 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4288 ipp_status_t status
) /* I - Status code */
4291 * Range check input...
4298 * Set the status code and return...
4301 ipp
->request
.status
.status_code
= status
;
4308 * 'ippSetString()' - Set a string value in an attribute.
4310 * The @code ipp@ parameter refers to an IPP message previously created using
4311 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4313 * The @code attr@ parameter may be modified as a result of setting the value.
4315 * The @code element@ parameter specifies which value to set from 0 to
4316 * @link ippGetCount(attr)@.
4318 * @since CUPS 1.6/OS X 10.8@
4321 int /* O - 1 on success, 0 on failure */
4322 ippSetString(ipp_t
*ipp
, /* I - IPP message */
4323 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4324 int element
, /* I - Value number (0-based) */
4325 const char *strvalue
) /* I - String value */
4327 char *temp
; /* Temporary string */
4328 _ipp_value_t
*value
; /* Current value */
4332 * Range check input...
4335 if (!ipp
|| !attr
|| !*attr
||
4336 ((*attr
)->value_tag
!= IPP_TAG_TEXTLANG
&&
4337 (*attr
)->value_tag
!= IPP_TAG_NAMELANG
&&
4338 ((*attr
)->value_tag
< IPP_TAG_TEXT
||
4339 (*attr
)->value_tag
> IPP_TAG_MIMETYPE
)) ||
4340 element
< 0 || element
> (*attr
)->num_values
|| !strvalue
)
4344 * Set the value and return...
4347 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4350 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4352 if ((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_CONST
)
4353 value
->string
.text
= (char *)strvalue
;
4354 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4356 if (value
->string
.text
)
4357 _cupsStrFree(value
->string
.text
);
4359 value
->string
.text
= temp
;
4365 return (value
!= NULL
);
4370 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4372 * The @code ipp@ parameter refers to an IPP message previously created using
4373 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4375 * The @code attr@ parameter may be modified as a result of setting the value.
4377 * The @code element@ parameter specifies which value to set from 0 to
4378 * @link ippGetCount(attr)@.
4380 * The @code format@ parameter uses formatting characters compatible with the
4381 * printf family of standard functions. Additional arguments follow it as
4382 * needed. The formatted string is truncated as needed to the maximum length of
4383 * the corresponding value type.
4388 int /* O - 1 on success, 0 on failure */
4389 ippSetStringf(ipp_t
*ipp
, /* I - IPP message */
4390 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4391 int element
, /* I - Value number (0-based) */
4392 const char *format
, /* I - Printf-style format string */
4393 ...) /* I - Additional arguments as needed */
4395 int ret
; /* Return value */
4396 va_list ap
; /* Pointer to additional arguments */
4399 va_start(ap
, format
);
4400 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4408 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4410 * The @code ipp@ parameter refers to an IPP message previously created using
4411 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4413 * The @code attr@ parameter may be modified as a result of setting the value.
4415 * The @code element@ parameter specifies which value to set from 0 to
4416 * @link ippGetCount(attr)@.
4418 * The @code format@ parameter uses formatting characters compatible with the
4419 * printf family of standard functions. Additional arguments follow it as
4420 * needed. The formatted string is truncated as needed to the maximum length of
4421 * the corresponding value type.
4426 int /* O - 1 on success, 0 on failure */
4427 ippSetStringfv(ipp_t
*ipp
, /* I - IPP message */
4428 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4429 int element
, /* I - Value number (0-based) */
4430 const char *format
, /* I - Printf-style format string */
4431 va_list ap
) /* I - Pointer to additional arguments */
4433 ipp_tag_t value_tag
; /* Value tag */
4434 char buffer
[IPP_MAX_TEXT
+ 4];
4435 /* Formatted text string */
4436 ssize_t bytes
, /* Length of formatted value */
4437 max_bytes
; /* Maximum number of bytes for value */
4441 * Range check input...
4445 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4447 value_tag
= IPP_TAG_ZERO
;
4449 if (!ipp
|| !attr
|| !*attr
||
4450 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4451 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4456 * Format the string...
4459 if (!strcmp(format
, "%s"))
4462 * Optimize the simple case...
4465 const char *s
= va_arg(ap
, char *);
4471 strlcpy(buffer
, s
, sizeof(buffer
));
4476 * Do a full formatting of the message...
4479 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4484 * Limit the length of the string...
4491 case IPP_TAG_TEXTLANG
:
4492 max_bytes
= IPP_MAX_TEXT
;
4496 case IPP_TAG_NAMELANG
:
4497 max_bytes
= IPP_MAX_NAME
;
4500 case IPP_TAG_CHARSET
:
4501 max_bytes
= IPP_MAX_CHARSET
;
4504 case IPP_TAG_KEYWORD
:
4505 max_bytes
= IPP_MAX_KEYWORD
;
4508 case IPP_TAG_LANGUAGE
:
4509 max_bytes
= IPP_MAX_LANGUAGE
;
4512 case IPP_TAG_MIMETYPE
:
4513 max_bytes
= IPP_MAX_MIMETYPE
;
4517 max_bytes
= IPP_MAX_URI
;
4520 case IPP_TAG_URISCHEME
:
4521 max_bytes
= IPP_MAX_URISCHEME
;
4525 if (bytes
>= max_bytes
)
4527 char *bufmax
, /* Buffer at max_bytes */
4528 *bufptr
; /* Pointer into buffer */
4530 bufptr
= buffer
+ strlen(buffer
) - 1;
4531 bufmax
= buffer
+ max_bytes
- 1;
4533 while (bufptr
> bufmax
)
4537 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4548 * Set the formatted string and return...
4551 return (ippSetString(ipp
, attr
, element
, buffer
));
4556 * 'ippSetValueTag()' - Set the value tag of an attribute.
4558 * The @code ipp@ parameter refers to an IPP message previously created using
4559 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4561 * The @code attr@ parameter may be modified as a result of setting the value.
4563 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4564 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4565 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4566 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4567 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4568 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4571 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4572 * code in the "attributes-natural-language" attribute or, if not present, the language
4573 * code for the current locale.
4575 * @since CUPS 1.6/OS X 10.8@
4578 int /* O - 1 on success, 0 on failure */
4580 ipp_t
*ipp
, /* I - IPP message */
4581 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4582 ipp_tag_t value_tag
) /* I - Value tag */
4584 int i
; /* Looping var */
4585 _ipp_value_t
*value
; /* Current value */
4586 int integer
; /* Current integer value */
4587 cups_lang_t
*language
; /* Current language */
4588 char code
[32]; /* Language code */
4589 ipp_tag_t temp_tag
; /* Temporary value tag */
4593 * Range check input...
4596 if (!ipp
|| !attr
|| !*attr
)
4600 * If there is no change, return immediately...
4603 if (value_tag
== (*attr
)->value_tag
)
4607 * Otherwise implement changes as needed...
4610 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_CUPS_MASK
);
4614 case IPP_TAG_UNSUPPORTED_VALUE
:
4615 case IPP_TAG_DEFAULT
:
4616 case IPP_TAG_UNKNOWN
:
4617 case IPP_TAG_NOVALUE
:
4618 case IPP_TAG_NOTSETTABLE
:
4619 case IPP_TAG_DELETEATTR
:
4620 case IPP_TAG_ADMINDEFINE
:
4622 * Free any existing values...
4625 if ((*attr
)->num_values
> 0)
4626 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4629 * Set out-of-band value...
4632 (*attr
)->value_tag
= value_tag
;
4635 case IPP_TAG_RANGE
:
4636 if (temp_tag
!= IPP_TAG_INTEGER
)
4639 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4643 integer
= value
->integer
;
4644 value
->range
.lower
= value
->range
.upper
= integer
;
4647 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4651 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4652 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4653 temp_tag
!= IPP_TAG_MIMETYPE
)
4656 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_CUPS_CONST
));
4659 case IPP_TAG_NAMELANG
:
4660 case IPP_TAG_TEXTLANG
:
4661 if (value_tag
== IPP_TAG_NAMELANG
&&
4662 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4663 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4664 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4667 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4670 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4671 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4674 * Use the language code from the IPP message...
4677 (*attr
)->values
[0].string
.language
=
4678 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4683 * Otherwise, use the language code corresponding to the locale...
4686 language
= cupsLangDefault();
4687 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4692 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4695 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4697 if ((int)(*attr
)->value_tag
& IPP_TAG_CUPS_CONST
)
4700 * Make copies of all values...
4703 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4706 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4709 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4712 case IPP_TAG_KEYWORD
:
4713 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4714 break; /* Silently "allow" name -> keyword */
4725 * 'ippSetVersion()' - Set the version number in an IPP message.
4727 * The @code ipp@ parameter refers to an IPP message previously created using
4728 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4730 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4732 * @since CUPS 1.6/OS X 10.8@
4735 int /* O - 1 on success, 0 on failure */
4736 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4737 int major
, /* I - Major version number (major.minor) */
4738 int minor
) /* I - Minor version number (major.minor) */
4741 * Range check input...
4744 if (!ipp
|| major
< 0 || minor
< 0)
4748 * Set the version number...
4751 ipp
->request
.any
.version
[0] = major
;
4752 ipp
->request
.any
.version
[1] = minor
;
4759 * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
4762 const ipp_uchar_t
* /* O - RFC-1903 date/time data */
4763 ippTimeToDate(time_t t
) /* I - UNIX time value */
4765 struct tm
*unixdate
; /* UNIX unixdate/time info */
4766 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4767 /* RFC-1903 date/time data */
4771 * RFC-1903 date/time format is:
4773 * Byte(s) Description
4774 * ------- -----------
4775 * 0-1 Year (0 to 65535)
4779 * 5 Minutes (0 to 59)
4780 * 6 Seconds (0 to 60, 60 = "leap second")
4781 * 7 Deciseconds (0 to 9)
4783 * 9 UTC hours (0 to 11)
4784 * 10 UTC minutes (0 to 59)
4787 unixdate
= gmtime(&t
);
4788 unixdate
->tm_year
+= 1900;
4790 date
[0] = unixdate
->tm_year
>> 8;
4791 date
[1] = unixdate
->tm_year
;
4792 date
[2] = unixdate
->tm_mon
+ 1;
4793 date
[3] = unixdate
->tm_mday
;
4794 date
[4] = unixdate
->tm_hour
;
4795 date
[5] = unixdate
->tm_min
;
4796 date
[6] = unixdate
->tm_sec
;
4807 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4809 * This function validates the contents of an attribute based on the name and
4810 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4811 * failure, cupsLastErrorString() is set to a human-readable message.
4816 int /* O - 1 if valid, 0 otherwise */
4817 ippValidateAttribute(
4818 ipp_attribute_t
*attr
) /* I - Attribute */
4820 int i
; /* Looping var */
4821 char scheme
[64], /* Scheme from URI */
4822 userpass
[256], /* Username/password from URI */
4823 hostname
[256], /* Hostname from URI */
4824 resource
[1024]; /* Resource from URI */
4825 int port
, /* Port number from URI */
4826 uri_status
; /* URI separation status */
4827 const char *ptr
; /* Pointer into string */
4828 ipp_attribute_t
*colattr
; /* Collection attribute */
4829 regex_t re
; /* Regular expression */
4830 ipp_uchar_t
*date
; /* Current date value */
4831 static const char * const uri_status_strings
[] =
4832 { /* URI status strings */
4834 "Bad arguments to function",
4835 "Bad resource in URI",
4836 "Bad port number in URI",
4837 "Bad hostname/address in URI",
4838 "Bad username in URI",
4839 "Bad scheme in URI",
4842 "Missing scheme in URI",
4843 "Unknown scheme in URI",
4844 "Missing resource in URI"
4856 * Validate the attribute name.
4859 for (ptr
= attr
->name
; *ptr
; ptr
++)
4860 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4863 if (*ptr
|| ptr
== attr
->name
)
4865 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4866 _("\"%s\": Bad attribute name - invalid character "
4867 "(RFC 2911 section 4.1.3)."), attr
->name
);
4871 if ((ptr
- attr
->name
) > 255)
4873 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4874 _("\"%s\": Bad attribute name - bad length %d "
4875 "(RFC 2911 section 4.1.3)."), attr
->name
,
4876 (int)(ptr
- attr
->name
));
4880 switch (attr
->value_tag
)
4882 case IPP_TAG_INTEGER
:
4885 case IPP_TAG_BOOLEAN
:
4886 for (i
= 0; i
< attr
->num_values
; i
++)
4888 if (attr
->values
[i
].boolean
!= 0 &&
4889 attr
->values
[i
].boolean
!= 1)
4891 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4892 _("\"%s\": Bad boolen value %d "
4893 "(RFC 2911 section 4.1.11)."), attr
->name
,
4894 attr
->values
[i
].boolean
);
4901 for (i
= 0; i
< attr
->num_values
; i
++)
4903 if (attr
->values
[i
].integer
< 1)
4905 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4906 _("\"%s\": Bad enum value %d - out of range "
4907 "(RFC 2911 section 4.1.4)."), attr
->name
,
4908 attr
->values
[i
].integer
);
4914 case IPP_TAG_STRING
:
4915 for (i
= 0; i
< attr
->num_values
; i
++)
4917 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4919 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4920 _("\"%s\": Bad octetString value - bad length %d "
4921 "(RFC 2911 section 4.1.10)."), attr
->name
,
4922 attr
->values
[i
].unknown
.length
);
4929 for (i
= 0; i
< attr
->num_values
; i
++)
4931 date
= attr
->values
[i
].date
;
4933 if (date
[2] < 1 || date
[2] > 12)
4935 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4936 _("\"%s\": Bad dateTime month %u "
4937 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[2]);
4941 if (date
[3] < 1 || date
[3] > 31)
4943 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4944 _("\"%s\": Bad dateTime day %u "
4945 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[3]);
4951 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4952 _("\"%s\": Bad dateTime hours %u "
4953 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[4]);
4959 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4960 _("\"%s\": Bad dateTime minutes %u "
4961 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[5]);
4967 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4968 _("\"%s\": Bad dateTime seconds %u "
4969 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[6]);
4975 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4976 _("\"%s\": Bad dateTime deciseconds %u "
4977 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[7]);
4981 if (date
[8] != '-' && date
[8] != '+')
4983 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4984 _("\"%s\": Bad dateTime UTC sign '%c' "
4985 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[8]);
4991 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4992 _("\"%s\": Bad dateTime UTC hours %u "
4993 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[9]);
4999 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5000 _("\"%s\": Bad dateTime UTC minutes %u "
5001 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[10]);
5007 case IPP_TAG_RESOLUTION
:
5008 for (i
= 0; i
< attr
->num_values
; i
++)
5010 if (attr
->values
[i
].resolution
.xres
<= 0)
5012 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5013 _("\"%s\": Bad resolution value %dx%d%s - cross "
5014 "feed resolution must be positive "
5015 "(RFC 2911 section 4.1.15)."), attr
->name
,
5016 attr
->values
[i
].resolution
.xres
,
5017 attr
->values
[i
].resolution
.yres
,
5018 attr
->values
[i
].resolution
.units
==
5019 IPP_RES_PER_INCH
? "dpi" :
5020 attr
->values
[i
].resolution
.units
==
5021 IPP_RES_PER_CM
? "dpcm" : "unknown");
5025 if (attr
->values
[i
].resolution
.yres
<= 0)
5027 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5028 _("\"%s\": Bad resolution value %dx%d%s - feed "
5029 "resolution must be positive "
5030 "(RFC 2911 section 4.1.15)."), attr
->name
,
5031 attr
->values
[i
].resolution
.xres
,
5032 attr
->values
[i
].resolution
.yres
,
5033 attr
->values
[i
].resolution
.units
==
5034 IPP_RES_PER_INCH
? "dpi" :
5035 attr
->values
[i
].resolution
.units
==
5036 IPP_RES_PER_CM
? "dpcm" : "unknown");
5040 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
5041 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
5043 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5044 _("\"%s\": Bad resolution value %dx%d%s - bad "
5045 "units value (RFC 2911 section 4.1.15)."),
5046 attr
->name
, attr
->values
[i
].resolution
.xres
,
5047 attr
->values
[i
].resolution
.yres
,
5048 attr
->values
[i
].resolution
.units
==
5049 IPP_RES_PER_INCH
? "dpi" :
5050 attr
->values
[i
].resolution
.units
==
5051 IPP_RES_PER_CM
? "dpcm" : "unknown");
5057 case IPP_TAG_RANGE
:
5058 for (i
= 0; i
< attr
->num_values
; i
++)
5060 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
5062 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5063 _("\"%s\": Bad rangeOfInteger value %d-%d - lower "
5064 "greater than upper (RFC 2911 section 4.1.13)."),
5065 attr
->name
, attr
->values
[i
].range
.lower
,
5066 attr
->values
[i
].range
.upper
);
5072 case IPP_TAG_BEGIN_COLLECTION
:
5073 for (i
= 0; i
< attr
->num_values
; i
++)
5075 for (colattr
= attr
->values
[i
].collection
->attrs
;
5077 colattr
= colattr
->next
)
5079 if (!ippValidateAttribute(colattr
))
5086 case IPP_TAG_TEXTLANG
:
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 text value \"%s\" - bad UTF-8 "
5126 "sequence (RFC 2911 section 4.1.1)."), attr
->name
,
5127 attr
->values
[i
].string
.text
);
5131 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5133 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5134 _("\"%s\": Bad text value \"%s\" - bad length %d "
5135 "(RFC 2911 section 4.1.1)."), attr
->name
,
5136 attr
->values
[i
].string
.text
,
5137 (int)(ptr
- attr
->values
[i
].string
.text
));
5144 case IPP_TAG_NAMELANG
:
5145 for (i
= 0; i
< attr
->num_values
; i
++)
5147 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5149 if ((*ptr
& 0xe0) == 0xc0)
5152 if ((*ptr
& 0xc0) != 0x80)
5155 else if ((*ptr
& 0xf0) == 0xe0)
5158 if ((*ptr
& 0xc0) != 0x80)
5161 if ((*ptr
& 0xc0) != 0x80)
5164 else if ((*ptr
& 0xf8) == 0xf0)
5167 if ((*ptr
& 0xc0) != 0x80)
5170 if ((*ptr
& 0xc0) != 0x80)
5173 if ((*ptr
& 0xc0) != 0x80)
5176 else if (*ptr
& 0x80)
5182 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5183 _("\"%s\": Bad name value \"%s\" - bad UTF-8 "
5184 "sequence (RFC 2911 section 4.1.2)."), attr
->name
,
5185 attr
->values
[i
].string
.text
);
5189 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5191 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5192 _("\"%s\": Bad name value \"%s\" - bad length %d "
5193 "(RFC 2911 section 4.1.2)."), attr
->name
,
5194 attr
->values
[i
].string
.text
,
5195 (int)(ptr
- attr
->values
[i
].string
.text
));
5201 case IPP_TAG_KEYWORD
:
5202 for (i
= 0; i
< attr
->num_values
; i
++)
5204 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5205 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5209 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5211 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5212 _("\"%s\": Bad keyword value \"%s\" - invalid "
5213 "character (RFC 2911 section 4.1.3)."),
5214 attr
->name
, attr
->values
[i
].string
.text
);
5218 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5220 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5221 _("\"%s\": Bad keyword value \"%s\" - bad "
5222 "length %d (RFC 2911 section 4.1.3)."),
5223 attr
->name
, attr
->values
[i
].string
.text
,
5224 (int)(ptr
- attr
->values
[i
].string
.text
));
5231 for (i
= 0; i
< attr
->num_values
; i
++)
5233 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5234 attr
->values
[i
].string
.text
,
5235 scheme
, sizeof(scheme
),
5236 userpass
, sizeof(userpass
),
5237 hostname
, sizeof(hostname
),
5238 &port
, resource
, sizeof(resource
));
5240 if (uri_status
< HTTP_URI_STATUS_OK
)
5242 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5243 _("\"%s\": Bad URI value \"%s\" - %s "
5244 "(RFC 2911 section 4.1.5)."), attr
->name
,
5245 attr
->values
[i
].string
.text
,
5246 uri_status_strings
[uri_status
-
5247 HTTP_URI_STATUS_OVERFLOW
]);
5251 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5253 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5254 _("\"%s\": Bad URI value \"%s\" - bad length %d "
5255 "(RFC 2911 section 4.1.5)."), attr
->name
,
5256 attr
->values
[i
].string
.text
,
5257 (int)strlen(attr
->values
[i
].string
.text
));
5262 case IPP_TAG_URISCHEME
:
5263 for (i
= 0; i
< attr
->num_values
; i
++)
5265 ptr
= attr
->values
[i
].string
.text
;
5266 if (islower(*ptr
& 255))
5268 for (ptr
++; *ptr
; ptr
++)
5269 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5270 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5274 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5276 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5277 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5278 "characters (RFC 2911 section 4.1.6)."),
5279 attr
->name
, attr
->values
[i
].string
.text
);
5283 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5285 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5286 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5287 "length %d (RFC 2911 section 4.1.6)."),
5288 attr
->name
, attr
->values
[i
].string
.text
,
5289 (int)(ptr
- attr
->values
[i
].string
.text
));
5295 case IPP_TAG_CHARSET
:
5296 for (i
= 0; i
< attr
->num_values
; i
++)
5298 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5299 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5300 isspace(*ptr
& 255))
5303 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5305 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5306 _("\"%s\": Bad charset value \"%s\" - bad "
5307 "characters (RFC 2911 section 4.1.7)."),
5308 attr
->name
, attr
->values
[i
].string
.text
);
5312 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5314 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5315 _("\"%s\": Bad charset value \"%s\" - bad "
5316 "length %d (RFC 2911 section 4.1.7)."),
5317 attr
->name
, attr
->values
[i
].string
.text
,
5318 (int)(ptr
- attr
->values
[i
].string
.text
));
5324 case IPP_TAG_LANGUAGE
:
5326 * The following regular expression is derived from the ABNF for
5327 * language tags in RFC 4646. All I can say is that this is the
5328 * easiest way to check the values...
5331 if ((i
= regcomp(&re
,
5333 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5335 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5336 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5337 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5338 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5339 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5341 "x(-[a-z0-9]{1,8})+" /* privateuse */
5343 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5345 REG_NOSUB
| REG_EXTENDED
)) != 0)
5347 char temp
[256]; /* Temporary error string */
5349 regerror(i
, &re
, temp
, sizeof(temp
));
5350 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
,
5351 _("Unable to compile naturalLanguage regular "
5352 "expression: %s."), temp
);
5356 for (i
= 0; i
< attr
->num_values
; i
++)
5358 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5360 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5361 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5362 "characters (RFC 2911 section 4.1.8)."),
5363 attr
->name
, attr
->values
[i
].string
.text
);
5368 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5370 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5371 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5372 "length %d (RFC 2911 section 4.1.8)."),
5373 attr
->name
, attr
->values
[i
].string
.text
,
5374 (int)strlen(attr
->values
[i
].string
.text
));
5383 case IPP_TAG_MIMETYPE
:
5385 * The following regular expression is derived from the ABNF for
5386 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5387 * the easiest way to check the values...
5390 if ((i
= regcomp(&re
,
5392 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5394 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5395 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5396 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5399 REG_NOSUB
| REG_EXTENDED
)) != 0)
5401 char temp
[256]; /* Temporary error string */
5403 regerror(i
, &re
, temp
, sizeof(temp
));
5404 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5405 _("Unable to compile mimeMediaType regular "
5406 "expression: %s."), temp
);
5410 for (i
= 0; i
< attr
->num_values
; i
++)
5412 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5414 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5415 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5416 "characters (RFC 2911 section 4.1.9)."),
5417 attr
->name
, attr
->values
[i
].string
.text
);
5422 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5424 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5425 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5426 "length %d (RFC 2911 section 4.1.9)."),
5427 attr
->name
, attr
->values
[i
].string
.text
,
5428 (int)strlen(attr
->values
[i
].string
.text
));
5446 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5448 * This function validates the contents of the IPP message, including each
5449 * attribute. Like @link ippValidateAttribute@, cupsLastErrorString() is set
5450 * to a human-readable message on failure.
5455 int /* O - 1 if valid, 0 otherwise */
5456 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5458 ipp_attribute_t
*attr
; /* Current attribute */
5464 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5465 if (!ippValidateAttribute(attr
))
5473 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5476 ipp_state_t
/* O - Current state */
5477 ippWrite(http_t
*http
, /* I - HTTP connection */
5478 ipp_t
*ipp
) /* I - IPP data */
5480 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", http
, ipp
));
5483 return (IPP_STATE_ERROR
);
5485 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5490 * 'ippWriteFile()' - Write data for an IPP message to a file.
5492 * @since CUPS 1.1.19/OS X 10.3@
5495 ipp_state_t
/* O - Current state */
5496 ippWriteFile(int fd
, /* I - HTTP data */
5497 ipp_t
*ipp
) /* I - IPP data */
5499 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, ipp
));
5501 ipp
->state
= IPP_STATE_IDLE
;
5503 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5508 * 'ippWriteIO()' - Write data for an IPP message.
5510 * @since CUPS 1.2/OS X 10.5@
5513 ipp_state_t
/* O - Current state */
5514 ippWriteIO(void *dst
, /* I - Destination */
5515 ipp_iocb_t cb
, /* I - Write callback function */
5516 int blocking
, /* I - Use blocking IO? */
5517 ipp_t
*parent
, /* I - Parent IPP message */
5518 ipp_t
*ipp
) /* I - IPP data */
5520 int i
; /* Looping var */
5521 int n
; /* Length of data */
5522 unsigned char *buffer
, /* Data buffer */
5523 *bufptr
; /* Pointer into buffer */
5524 ipp_attribute_t
*attr
; /* Current attribute */
5525 _ipp_value_t
*value
; /* Current value */
5528 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)",
5529 dst
, cb
, blocking
, parent
, ipp
));
5532 return (IPP_STATE_ERROR
);
5534 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5536 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5537 return (IPP_STATE_ERROR
);
5542 case IPP_STATE_IDLE
:
5543 ipp
->state
++; /* Avoid common problem... */
5545 case IPP_STATE_HEADER
:
5549 * Send the request header:
5552 * Operation/Status Code = 2 bytes
5553 * Request ID = 4 bytes
5559 *bufptr
++ = ipp
->request
.any
.version
[0];
5560 *bufptr
++ = ipp
->request
.any
.version
[1];
5561 *bufptr
++ = ipp
->request
.any
.op_status
>> 8;
5562 *bufptr
++ = ipp
->request
.any
.op_status
;
5563 *bufptr
++ = ipp
->request
.any
.request_id
>> 24;
5564 *bufptr
++ = ipp
->request
.any
.request_id
>> 16;
5565 *bufptr
++ = ipp
->request
.any
.request_id
>> 8;
5566 *bufptr
++ = ipp
->request
.any
.request_id
;
5568 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5569 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5570 ipp
->request
.any
.op_status
));
5571 DEBUG_printf(("2ippWriteIO: request_id=%d",
5572 ipp
->request
.any
.request_id
));
5574 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5576 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5577 _cupsBufferRelease((char *)buffer
);
5578 return (IPP_STATE_ERROR
);
5583 * Reset the state engine to point to the first attribute
5584 * in the request/response, with no current group.
5587 ipp
->state
= IPP_STATE_ATTRIBUTE
;
5588 ipp
->current
= ipp
->attrs
;
5589 ipp
->curtag
= IPP_TAG_ZERO
;
5591 DEBUG_printf(("1ippWriteIO: ipp->current=%p", ipp
->current
));
5594 * If blocking is disabled, stop here...
5600 case IPP_STATE_ATTRIBUTE
:
5601 while (ipp
->current
!= NULL
)
5604 * Write this attribute...
5608 attr
= ipp
->current
;
5610 ipp
->current
= ipp
->current
->next
;
5614 if (ipp
->curtag
!= attr
->group_tag
)
5617 * Send a group tag byte...
5620 ipp
->curtag
= attr
->group_tag
;
5622 if (attr
->group_tag
== IPP_TAG_ZERO
)
5625 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5626 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5627 *bufptr
++ = attr
->group_tag
;
5629 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5633 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5634 attr
->num_values
> 1 ? "1setOf " : "",
5635 ippTagString(attr
->value_tag
)));
5638 * Write the attribute tag and name.
5640 * The attribute name length does not include the trailing nul
5641 * character in the source string.
5643 * Collection values (parent != NULL) are written differently...
5649 * Get the length of the attribute name, and make sure it won't
5650 * overflow the buffer...
5653 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5655 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5656 _cupsBufferRelease((char *)buffer
);
5657 return (IPP_STATE_ERROR
);
5661 * Write the value tag, name length, and name string...
5664 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5665 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5666 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5669 if (attr
->value_tag
> 0xff)
5671 *bufptr
++ = IPP_TAG_EXTENSION
;
5672 *bufptr
++ = attr
->value_tag
>> 24;
5673 *bufptr
++ = attr
->value_tag
>> 16;
5674 *bufptr
++ = attr
->value_tag
>> 8;
5675 *bufptr
++ = attr
->value_tag
;
5678 *bufptr
++ = attr
->value_tag
;
5682 memcpy(bufptr
, attr
->name
, n
);
5688 * Get the length of the attribute name, and make sure it won't
5689 * overflow the buffer...
5692 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5694 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5695 _cupsBufferRelease((char *)buffer
);
5696 return (IPP_STATE_ERROR
);
5700 * Write the member name tag, name length, name string, value tag,
5701 * and empty name for the collection member attribute...
5704 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5705 IPP_TAG_MEMBERNAME
));
5706 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5708 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5709 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5710 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5712 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5717 memcpy(bufptr
, attr
->name
, n
);
5720 if (attr
->value_tag
> 0xff)
5722 *bufptr
++ = IPP_TAG_EXTENSION
;
5723 *bufptr
++ = attr
->value_tag
>> 24;
5724 *bufptr
++ = attr
->value_tag
>> 16;
5725 *bufptr
++ = attr
->value_tag
>> 8;
5726 *bufptr
++ = attr
->value_tag
;
5729 *bufptr
++ = attr
->value_tag
;
5736 * Now write the attribute value(s)...
5739 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
5741 case IPP_TAG_UNSUPPORTED_VALUE
:
5742 case IPP_TAG_DEFAULT
:
5743 case IPP_TAG_UNKNOWN
:
5744 case IPP_TAG_NOVALUE
:
5745 case IPP_TAG_NOTSETTABLE
:
5746 case IPP_TAG_DELETEATTR
:
5747 case IPP_TAG_ADMINDEFINE
:
5752 case IPP_TAG_INTEGER
:
5754 for (i
= 0, value
= attr
->values
;
5755 i
< attr
->num_values
;
5758 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5760 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5762 DEBUG_puts("1ippWriteIO: Could not write IPP "
5764 _cupsBufferRelease((char *)buffer
);
5765 return (IPP_STATE_ERROR
);
5774 * Arrays and sets are done by sending additional
5775 * values with a zero-length name...
5778 *bufptr
++ = attr
->value_tag
;
5784 * Integers and enumerations are both 4-byte signed
5785 * (twos-complement) values.
5787 * Put the 2-byte length and 4-byte value into the buffer...
5792 *bufptr
++ = value
->integer
>> 24;
5793 *bufptr
++ = value
->integer
>> 16;
5794 *bufptr
++ = value
->integer
>> 8;
5795 *bufptr
++ = value
->integer
;
5799 case IPP_TAG_BOOLEAN
:
5800 for (i
= 0, value
= attr
->values
;
5801 i
< attr
->num_values
;
5804 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5806 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5808 DEBUG_puts("1ippWriteIO: Could not write IPP "
5810 _cupsBufferRelease((char *)buffer
);
5811 return (IPP_STATE_ERROR
);
5820 * Arrays and sets are done by sending additional
5821 * values with a zero-length name...
5824 *bufptr
++ = attr
->value_tag
;
5830 * Boolean values are 1-byte; 0 = false, 1 = true.
5832 * Put the 2-byte length and 1-byte value into the buffer...
5837 *bufptr
++ = value
->boolean
;
5843 case IPP_TAG_KEYWORD
:
5845 case IPP_TAG_URISCHEME
:
5846 case IPP_TAG_CHARSET
:
5847 case IPP_TAG_LANGUAGE
:
5848 case IPP_TAG_MIMETYPE
:
5849 for (i
= 0, value
= attr
->values
;
5850 i
< attr
->num_values
;
5856 * Arrays and sets are done by sending additional
5857 * values with a zero-length name...
5860 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5862 ippTagString(attr
->value_tag
)));
5863 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5865 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5867 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5869 DEBUG_puts("1ippWriteIO: Could not write IPP "
5871 _cupsBufferRelease((char *)buffer
);
5872 return (IPP_STATE_ERROR
);
5878 *bufptr
++ = attr
->value_tag
;
5883 if (value
->string
.text
!= NULL
)
5884 n
= (int)strlen(value
->string
.text
);
5888 if (n
> (IPP_BUF_SIZE
- 2))
5890 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5891 _cupsBufferRelease((char *)buffer
);
5892 return (IPP_STATE_ERROR
);
5895 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5896 value
->string
.text
));
5898 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5900 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5902 DEBUG_puts("1ippWriteIO: Could not write IPP "
5904 _cupsBufferRelease((char *)buffer
);
5905 return (IPP_STATE_ERROR
);
5912 * All simple strings consist of the 2-byte length and
5913 * character data without the trailing nul normally found
5914 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5915 * bytes since the 2-byte length is a signed (twos-complement)
5918 * Put the 2-byte length and string characters in the buffer.
5926 memcpy(bufptr
, value
->string
.text
, n
);
5933 for (i
= 0, value
= attr
->values
;
5934 i
< attr
->num_values
;
5937 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5939 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5941 DEBUG_puts("1ippWriteIO: Could not write IPP "
5943 _cupsBufferRelease((char *)buffer
);
5944 return (IPP_STATE_ERROR
);
5953 * Arrays and sets are done by sending additional
5954 * values with a zero-length name...
5957 *bufptr
++ = attr
->value_tag
;
5963 * Date values consist of a 2-byte length and an
5964 * 11-byte date/time structure defined by RFC 1903.
5966 * Put the 2-byte length and 11-byte date/time
5967 * structure in the buffer.
5972 memcpy(bufptr
, value
->date
, 11);
5977 case IPP_TAG_RESOLUTION
:
5978 for (i
= 0, value
= attr
->values
;
5979 i
< attr
->num_values
;
5982 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5984 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5986 DEBUG_puts("1ippWriteIO: Could not write IPP "
5988 _cupsBufferRelease((char *)buffer
);
5989 return (IPP_STATE_ERROR
);
5998 * Arrays and sets are done by sending additional
5999 * values with a zero-length name...
6002 *bufptr
++ = attr
->value_tag
;
6008 * Resolution values consist of a 2-byte length,
6009 * 4-byte horizontal resolution value, 4-byte vertical
6010 * resolution value, and a 1-byte units value.
6012 * Put the 2-byte length and resolution value data
6018 *bufptr
++ = value
->resolution
.xres
>> 24;
6019 *bufptr
++ = value
->resolution
.xres
>> 16;
6020 *bufptr
++ = value
->resolution
.xres
>> 8;
6021 *bufptr
++ = value
->resolution
.xres
;
6022 *bufptr
++ = value
->resolution
.yres
>> 24;
6023 *bufptr
++ = value
->resolution
.yres
>> 16;
6024 *bufptr
++ = value
->resolution
.yres
>> 8;
6025 *bufptr
++ = value
->resolution
.yres
;
6026 *bufptr
++ = value
->resolution
.units
;
6030 case IPP_TAG_RANGE
:
6031 for (i
= 0, value
= attr
->values
;
6032 i
< attr
->num_values
;
6035 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
6037 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6039 DEBUG_puts("1ippWriteIO: Could not write IPP "
6041 _cupsBufferRelease((char *)buffer
);
6042 return (IPP_STATE_ERROR
);
6051 * Arrays and sets are done by sending additional
6052 * values with a zero-length name...
6055 *bufptr
++ = attr
->value_tag
;
6061 * Range values consist of a 2-byte length,
6062 * 4-byte lower value, and 4-byte upper value.
6064 * Put the 2-byte length and range value data
6070 *bufptr
++ = value
->range
.lower
>> 24;
6071 *bufptr
++ = value
->range
.lower
>> 16;
6072 *bufptr
++ = value
->range
.lower
>> 8;
6073 *bufptr
++ = value
->range
.lower
;
6074 *bufptr
++ = value
->range
.upper
>> 24;
6075 *bufptr
++ = value
->range
.upper
>> 16;
6076 *bufptr
++ = value
->range
.upper
>> 8;
6077 *bufptr
++ = value
->range
.upper
;
6081 case IPP_TAG_TEXTLANG
:
6082 case IPP_TAG_NAMELANG
:
6083 for (i
= 0, value
= attr
->values
;
6084 i
< attr
->num_values
;
6090 * Arrays and sets are done by sending additional
6091 * values with a zero-length name...
6094 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6096 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6098 DEBUG_puts("1ippWriteIO: Could not write IPP "
6100 _cupsBufferRelease((char *)buffer
);
6101 return (IPP_STATE_ERROR
);
6107 *bufptr
++ = attr
->value_tag
;
6113 * textWithLanguage and nameWithLanguage values consist
6114 * of a 2-byte length for both strings and their
6115 * individual lengths, a 2-byte length for the
6116 * character string, the character string without the
6117 * trailing nul, a 2-byte length for the character
6118 * set string, and the character set string without
6124 if (value
->string
.language
!= NULL
)
6125 n
+= (int)strlen(value
->string
.language
);
6127 if (value
->string
.text
!= NULL
)
6128 n
+= (int)strlen(value
->string
.text
);
6130 if (n
> (IPP_BUF_SIZE
- 2))
6132 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
6133 "too long (%d)", n
));
6134 _cupsBufferRelease((char *)buffer
);
6135 return (IPP_STATE_ERROR
);
6138 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6140 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6142 DEBUG_puts("1ippWriteIO: Could not write IPP "
6144 _cupsBufferRelease((char *)buffer
);
6145 return (IPP_STATE_ERROR
);
6151 /* Length of entire value */
6155 /* Length of language */
6156 if (value
->string
.language
!= NULL
)
6157 n
= (int)strlen(value
->string
.language
);
6167 memcpy(bufptr
, value
->string
.language
, n
);
6171 /* Length of text */
6172 if (value
->string
.text
!= NULL
)
6173 n
= (int)strlen(value
->string
.text
);
6183 memcpy(bufptr
, value
->string
.text
, n
);
6189 case IPP_TAG_BEGIN_COLLECTION
:
6190 for (i
= 0, value
= attr
->values
;
6191 i
< attr
->num_values
;
6195 * Collections are written with the begin-collection
6196 * tag first with a value of 0 length, followed by the
6197 * attributes in the collection, then the end-collection
6201 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6203 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6205 DEBUG_puts("1ippWriteIO: Could not write IPP "
6207 _cupsBufferRelease((char *)buffer
);
6208 return (IPP_STATE_ERROR
);
6217 * Arrays and sets are done by sending additional
6218 * values with a zero-length name...
6221 *bufptr
++ = attr
->value_tag
;
6227 * Write a data length of 0 and flush the buffer...
6233 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6235 DEBUG_puts("1ippWriteIO: Could not write IPP "
6237 _cupsBufferRelease((char *)buffer
);
6238 return (IPP_STATE_ERROR
);
6244 * Then write the collection attribute...
6247 value
->collection
->state
= IPP_STATE_IDLE
;
6249 if (ippWriteIO(dst
, cb
, 1, ipp
,
6250 value
->collection
) == IPP_STATE_ERROR
)
6252 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6253 _cupsBufferRelease((char *)buffer
);
6254 return (IPP_STATE_ERROR
);
6260 for (i
= 0, value
= attr
->values
;
6261 i
< attr
->num_values
;
6267 * Arrays and sets are done by sending additional
6268 * values with a zero-length name...
6271 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6273 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6275 DEBUG_puts("1ippWriteIO: Could not write IPP "
6277 _cupsBufferRelease((char *)buffer
);
6278 return (IPP_STATE_ERROR
);
6284 *bufptr
++ = attr
->value_tag
;
6290 * An unknown value might some new value that a
6291 * vendor has come up with. It consists of a
6292 * 2-byte length and the bytes in the unknown
6296 n
= value
->unknown
.length
;
6298 if (n
> (IPP_BUF_SIZE
- 2))
6300 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6302 _cupsBufferRelease((char *)buffer
);
6303 return (IPP_STATE_ERROR
);
6306 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6308 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6310 DEBUG_puts("1ippWriteIO: Could not write IPP "
6312 _cupsBufferRelease((char *)buffer
);
6313 return (IPP_STATE_ERROR
);
6319 /* Length of unknown value */
6326 memcpy(bufptr
, value
->unknown
.data
, n
);
6334 * Write the data out...
6337 if (bufptr
> buffer
)
6339 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6341 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6342 _cupsBufferRelease((char *)buffer
);
6343 return (IPP_STATE_ERROR
);
6346 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6347 (int)(bufptr
- buffer
)));
6351 * If blocking is disabled, stop here...
6358 if (ipp
->current
== NULL
)
6361 * Done with all of the attributes; add the end-of-attributes
6362 * tag or end-collection attribute...
6367 buffer
[0] = IPP_TAG_END
;
6372 buffer
[0] = IPP_TAG_END_COLLECTION
;
6373 buffer
[1] = 0; /* empty name */
6375 buffer
[3] = 0; /* empty value */
6380 if ((*cb
)(dst
, buffer
, n
) < 0)
6382 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6383 _cupsBufferRelease((char *)buffer
);
6384 return (IPP_STATE_ERROR
);
6387 ipp
->state
= IPP_STATE_DATA
;
6391 case IPP_STATE_DATA
:
6395 break; /* anti-compiler-warning-code */
6398 _cupsBufferRelease((char *)buffer
);
6400 return (ipp
->state
);
6405 * 'ipp_add_attr()' - Add a new attribute to the message.
6408 static ipp_attribute_t
* /* O - New attribute */
6409 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6410 const char *name
, /* I - Attribute name or NULL */
6411 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6412 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6413 int num_values
) /* I - Number of values */
6415 int alloc_values
; /* Number of values to allocate */
6416 ipp_attribute_t
*attr
; /* New attribute */
6419 DEBUG_printf(("4ipp_add_attr(ipp=%p, name=\"%s\", group_tag=0x%x, value_tag=0x%x, "
6420 "num_values=%d)", ipp
, name
, group_tag
, value_tag
, num_values
));
6423 * Range check input...
6426 if (!ipp
|| num_values
< 0)
6430 * Allocate memory, rounding the allocation up as needed...
6433 if (num_values
<= 1)
6436 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6438 attr
= calloc(sizeof(ipp_attribute_t
) +
6439 (alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6444 * Initialize attribute...
6448 attr
->name
= _cupsStrAlloc(name
);
6450 attr
->group_tag
= group_tag
;
6451 attr
->value_tag
= value_tag
;
6452 attr
->num_values
= num_values
;
6455 * Add it to the end of the linked list...
6459 ipp
->last
->next
= attr
;
6463 ipp
->prev
= ipp
->last
;
6464 ipp
->last
= ipp
->current
= attr
;
6467 DEBUG_printf(("5ipp_add_attr: Returning %p", attr
));
6474 * 'ipp_free_values()' - Free attribute values.
6478 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6479 int element
,/* I - First value to free */
6480 int count
) /* I - Number of values to free */
6482 int i
; /* Looping var */
6483 _ipp_value_t
*value
; /* Current value */
6486 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", attr
,
6489 if (!(attr
->value_tag
& IPP_TAG_CUPS_CONST
))
6492 * Free values as needed...
6495 switch (attr
->value_tag
)
6497 case IPP_TAG_TEXTLANG
:
6498 case IPP_TAG_NAMELANG
:
6499 if (element
== 0 && count
== attr
->num_values
&&
6500 attr
->values
[0].string
.language
)
6502 _cupsStrFree(attr
->values
[0].string
.language
);
6503 attr
->values
[0].string
.language
= NULL
;
6505 /* Fall through to other string values */
6509 case IPP_TAG_RESERVED_STRING
:
6510 case IPP_TAG_KEYWORD
:
6512 case IPP_TAG_URISCHEME
:
6513 case IPP_TAG_CHARSET
:
6514 case IPP_TAG_LANGUAGE
:
6515 case IPP_TAG_MIMETYPE
:
6516 for (i
= count
, value
= attr
->values
+ element
;
6520 _cupsStrFree(value
->string
.text
);
6521 value
->string
.text
= NULL
;
6525 case IPP_TAG_DEFAULT
:
6526 case IPP_TAG_UNKNOWN
:
6527 case IPP_TAG_NOVALUE
:
6528 case IPP_TAG_NOTSETTABLE
:
6529 case IPP_TAG_DELETEATTR
:
6530 case IPP_TAG_ADMINDEFINE
:
6531 case IPP_TAG_INTEGER
:
6533 case IPP_TAG_BOOLEAN
:
6535 case IPP_TAG_RESOLUTION
:
6536 case IPP_TAG_RANGE
:
6539 case IPP_TAG_BEGIN_COLLECTION
:
6540 for (i
= count
, value
= attr
->values
+ element
;
6544 ippDelete(value
->collection
);
6545 value
->collection
= NULL
;
6549 case IPP_TAG_STRING
:
6551 for (i
= count
, value
= attr
->values
+ element
;
6555 if (value
->unknown
.data
)
6557 free(value
->unknown
.data
);
6558 value
->unknown
.data
= NULL
;
6566 * If we are not freeing values from the end, move the remaining values up...
6569 if ((element
+ count
) < attr
->num_values
)
6570 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6571 (attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6573 attr
->num_values
-= count
;
6578 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6580 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6581 * to "ll-cc", "ll-region", and "charset-number", respectively.
6584 static char * /* O - Language code string */
6585 ipp_get_code(const char *value
, /* I - Locale/charset string */
6586 char *buffer
, /* I - String buffer */
6587 size_t bufsize
) /* I - Size of string buffer */
6589 char *bufptr
, /* Pointer into buffer */
6590 *bufend
; /* End of buffer */
6594 * Convert values to lowercase and change _ to - as needed...
6597 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6598 *value
&& bufptr
< bufend
;
6603 *bufptr
++ = _cups_tolower(*value
);
6608 * Return the converted string...
6616 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6618 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6619 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6622 static char * /* O - Language code string */
6623 ipp_lang_code(const char *locale
, /* I - Locale string */
6624 char *buffer
, /* I - String buffer */
6625 size_t bufsize
) /* I - Size of string buffer */
6628 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6631 if (!_cups_strcasecmp(locale
, "c"))
6633 strlcpy(buffer
, "en", bufsize
);
6637 return (ipp_get_code(locale
, buffer
, bufsize
));
6642 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6645 static size_t /* O - Size of IPP message */
6646 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6647 int collection
) /* I - 1 if a collection, 0 otherwise */
6649 int i
; /* Looping var */
6650 size_t bytes
; /* Number of bytes */
6651 ipp_attribute_t
*attr
; /* Current attribute */
6652 ipp_tag_t group
; /* Current group */
6653 _ipp_value_t
*value
; /* Current value */
6656 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", ipp
, collection
));
6660 DEBUG_puts("4ipp_length: Returning 0 bytes");
6665 * Start with 8 bytes for the IPP message header...
6668 bytes
= collection
? 0 : 8;
6671 * Then add the lengths of each attribute...
6674 group
= IPP_TAG_ZERO
;
6676 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6678 if (attr
->group_tag
!= group
&& !collection
)
6680 group
= attr
->group_tag
;
6681 if (group
== IPP_TAG_ZERO
)
6684 bytes
++; /* Group tag */
6690 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6691 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6693 if (attr
->value_tag
< IPP_TAG_EXTENSION
)
6694 bytes
+= attr
->num_values
; /* Value tag for each value */
6696 bytes
+= 5 * attr
->num_values
; /* Value tag for each value */
6697 bytes
+= 2 * attr
->num_values
; /* Name lengths */
6698 bytes
+= (int)strlen(attr
->name
); /* Name */
6699 bytes
+= 2 * attr
->num_values
; /* Value lengths */
6702 bytes
+= 5; /* Add membername overhead */
6704 switch (attr
->value_tag
& ~IPP_TAG_CUPS_CONST
)
6706 case IPP_TAG_UNSUPPORTED_VALUE
:
6707 case IPP_TAG_DEFAULT
:
6708 case IPP_TAG_UNKNOWN
:
6709 case IPP_TAG_NOVALUE
:
6710 case IPP_TAG_NOTSETTABLE
:
6711 case IPP_TAG_DELETEATTR
:
6712 case IPP_TAG_ADMINDEFINE
:
6715 case IPP_TAG_INTEGER
:
6717 bytes
+= 4 * attr
->num_values
;
6720 case IPP_TAG_BOOLEAN
:
6721 bytes
+= attr
->num_values
;
6726 case IPP_TAG_KEYWORD
:
6728 case IPP_TAG_URISCHEME
:
6729 case IPP_TAG_CHARSET
:
6730 case IPP_TAG_LANGUAGE
:
6731 case IPP_TAG_MIMETYPE
:
6732 for (i
= 0, value
= attr
->values
;
6733 i
< attr
->num_values
;
6735 if (value
->string
.text
)
6736 bytes
+= strlen(value
->string
.text
);
6740 bytes
+= 11 * attr
->num_values
;
6743 case IPP_TAG_RESOLUTION
:
6744 bytes
+= 9 * attr
->num_values
;
6747 case IPP_TAG_RANGE
:
6748 bytes
+= 8 * attr
->num_values
;
6751 case IPP_TAG_TEXTLANG
:
6752 case IPP_TAG_NAMELANG
:
6753 bytes
+= 4 * attr
->num_values
;/* Charset + text length */
6755 for (i
= 0, value
= attr
->values
;
6756 i
< attr
->num_values
;
6759 if (value
->string
.language
)
6760 bytes
+= strlen(value
->string
.language
);
6762 if (value
->string
.text
)
6763 bytes
+= strlen(value
->string
.text
);
6767 case IPP_TAG_BEGIN_COLLECTION
:
6768 for (i
= 0, value
= attr
->values
;
6769 i
< attr
->num_values
;
6771 bytes
+= ipp_length(value
->collection
, 1);
6775 for (i
= 0, value
= attr
->values
;
6776 i
< attr
->num_values
;
6778 bytes
+= value
->unknown
.length
;
6784 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6785 * for the "end of collection" tag and return...
6793 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6800 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6803 static ssize_t
/* O - Number of bytes read */
6804 ipp_read_http(http_t
*http
, /* I - Client connection */
6805 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6806 size_t length
) /* I - Total length */
6808 int tbytes
, /* Total bytes read */
6809 bytes
; /* Bytes read this pass */
6812 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)",
6813 http
, buffer
, (int)length
));
6816 * Loop until all bytes are read...
6819 for (tbytes
= 0, bytes
= 0;
6820 tbytes
< (int)length
;
6821 tbytes
+= bytes
, buffer
+= bytes
)
6823 DEBUG_printf(("9ipp_read_http: tbytes=%d, http->state=%d", tbytes
,
6826 if (http
->state
== HTTP_STATE_WAITING
)
6829 if (http
->used
== 0 && !http
->blocking
)
6832 * Wait up to 10 seconds for more data on non-blocking sockets...
6835 if (!httpWait(http
, 10000))
6846 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- tbytes
)) < 0)
6851 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6857 else if (bytes
== 0)
6862 * Return the number of bytes read...
6865 if (tbytes
== 0 && bytes
< 0)
6868 DEBUG_printf(("8ipp_read_http: Returning %d bytes", tbytes
));
6875 * 'ipp_read_file()' - Read IPP data from a file.
6878 static ssize_t
/* O - Number of bytes read */
6879 ipp_read_file(int *fd
, /* I - File descriptor */
6880 ipp_uchar_t
*buffer
, /* O - Read buffer */
6881 size_t length
) /* I - Number of bytes to read */
6884 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6886 return (read(*fd
, buffer
, length
));
6892 * 'ipp_set_error()' - Set a formatted, localized error string.
6896 ipp_set_error(ipp_status_t status
, /* I - Status code */
6897 const char *format
, /* I - Printf-style error string */
6898 ...) /* I - Additional arguments as needed */
6900 va_list ap
; /* Pointer to additional args */
6901 char buffer
[2048]; /* Message buffer */
6902 cups_lang_t
*lang
= cupsLangDefault();
6903 /* Current language */
6906 va_start(ap
, format
);
6907 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6910 _cupsSetError(status
, buffer
, 0);
6915 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6919 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6920 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6921 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6922 int element
) /* I - Value number (0-based) */
6924 ipp_attribute_t
*temp
, /* New attribute pointer */
6925 *current
, /* Current attribute in list */
6926 *prev
; /* Previous attribute in list */
6927 int alloc_values
; /* Allocated values */
6931 * If we are setting an existing value element, return it...
6936 if (temp
->num_values
<= 1)
6939 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6940 ~(IPP_MAX_VALUES
- 1);
6942 if (element
< alloc_values
)
6944 if (element
>= temp
->num_values
)
6945 temp
->num_values
= element
+ 1;
6947 return (temp
->values
+ element
);
6951 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6952 * values when num_values > 1.
6955 if (alloc_values
< IPP_MAX_VALUES
)
6956 alloc_values
= IPP_MAX_VALUES
;
6958 alloc_values
+= IPP_MAX_VALUES
;
6960 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6964 * Reallocate memory...
6967 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) +
6968 (alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6970 _cupsSetHTTPError(HTTP_STATUS_ERROR
);
6971 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6976 * Zero the new memory...
6979 memset(temp
->values
+ temp
->num_values
, 0,
6980 (alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6985 * Reset pointers in the list...
6988 if (ipp
->current
== *attr
&& ipp
->prev
)
6991 * Use current "previous" pointer...
6999 * Find this attribute in the linked list...
7002 for (prev
= NULL
, current
= ipp
->attrs
;
7003 current
&& current
!= *attr
;
7004 prev
= current
, current
= current
->next
);
7009 * This is a serious error!
7013 _cupsSetError(IPP_STATUS_ERROR_INTERNAL
,
7014 _("IPP attribute is not a member of the message."), 1);
7015 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
7025 ipp
->current
= temp
;
7028 if (ipp
->last
== *attr
)
7035 * Return the value element...
7038 if (element
>= temp
->num_values
)
7039 temp
->num_values
= element
+ 1;
7041 return (temp
->values
+ element
);
7046 * 'ipp_write_file()' - Write IPP data to a file.
7049 static ssize_t
/* O - Number of bytes written */
7050 ipp_write_file(int *fd
, /* I - File descriptor */
7051 ipp_uchar_t
*buffer
, /* I - Data to write */
7052 size_t length
) /* I - Number of bytes to write */
7055 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
7057 return (write(*fd
, buffer
, length
));