2 * "$Id: ipp.c 10102 2011-11-02 23:52:39Z mike $"
4 * Internet Printing Protocol functions for CUPS.
6 * Copyright 2007-2012 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 * ippGetOperation() - Get the operation ID in an IPP message.
61 * ippGetRange() - Get a rangeOfInteger value from an attribute.
62 * ippGetRequestId() - Get the request ID from an IPP message.
63 * ippGetResolution() - Get a resolution value for an attribute.
64 * ippGetState() - Get the IPP message state.
65 * ippGetStatusCode() - Get the status code from an IPP response or
67 * ippGetString() - Get the string and optionally the language code
69 * ippGetValueTag() - Get the value tag for an attribute.
70 * ippGetVersion() - Get the major and minor version number from an
72 * ippLength() - Compute the length of an IPP message.
73 * ippNextAttribute() - Return the next attribute in the message.
74 * ippNew() - Allocate a new IPP message.
75 * ippNewRequest() - Allocate a new IPP request message.
76 * ippNewResponse() - Allocate a new IPP response message.
77 * ippRead() - Read data for an IPP message from a HTTP
79 * ippReadFile() - Read data for an IPP message from a file.
80 * ippReadIO() - Read data for an IPP message.
81 * ippSetBoolean() - Set a boolean value in an attribute.
82 * ippSetCollection() - Set a collection value in an attribute.
83 * ippSetDate() - Set a date value in an attribute.
84 * ippSetGroupTag() - Set the group tag of an attribute.
85 * ippSetInteger() - Set an integer or enum value in an attribute.
86 * ippSetName() - Set the name of an attribute.
87 * ippSetOperation() - Set the operation ID in an IPP request message.
88 * ippSetRange() - Set a rangeOfInteger value in an attribute.
89 * ippSetRequestId() - Set the request ID in an IPP message.
90 * ippSetResolution() - Set a resolution value in an attribute.
91 * ippSetState() - Set the current state of the IPP message.
92 * ippSetStatusCode() - Set the status code in an IPP response or event
94 * ippSetString() - Set a string value in an attribute.
95 * ippSetStringf() - Set a formatted string value of an attribute.
96 * ippSetStringf() - Set a formatted string value of an attribute.
97 * ippSetValueTag() - Set the value tag of an attribute.
98 * ippSetVersion() - Set the version number in an IPP message.
99 * ippTimeToDate() - Convert from UNIX time to RFC 1903 format.
100 * ippValidateAttribute() - Validate the contents of an attribute.
101 * ippValidateAttributes() - Validate all attributes in an IPP message.
102 * ippWrite() - Write data for an IPP message to a HTTP
104 * ippWriteFile() - Write data for an IPP message to a file.
105 * ippWriteIO() - Write data for an IPP message.
106 * ipp_add_attr() - Add a new attribute to the message.
107 * ipp_free_values() - Free attribute values.
108 * ipp_get_code() - Convert a C locale/charset name into an IPP
109 * language/charset code.
110 * ipp_lang_code() - Convert a C locale name into an IPP language
112 * ipp_length() - Compute the length of an IPP message or
114 * ipp_read_http() - Semi-blocking read on a HTTP connection...
115 * ipp_read_file() - Read IPP data from a file.
116 * ipp_set_error() - Set a formatted, localized error string.
117 * ipp_set_value() - Get the value element from an attribute,
118 * expanding it as needed.
119 * ipp_write_file() - Write IPP data to a file.
123 * Include necessary headers...
126 #include "cups-private.h"
137 static ipp_attribute_t
*ipp_add_attr(ipp_t
*ipp
, const char *name
,
138 ipp_tag_t group_tag
, ipp_tag_t value_tag
,
140 static void ipp_free_values(ipp_attribute_t
*attr
, int element
,
142 static char *ipp_get_code(const char *locale
, char *buffer
,
144 __attribute__((nonnull(1,2)));
145 static char *ipp_lang_code(const char *locale
, char *buffer
,
147 __attribute__((nonnull(1,2)));
148 static size_t ipp_length(ipp_t
*ipp
, int collection
);
149 static ssize_t
ipp_read_http(http_t
*http
, ipp_uchar_t
*buffer
,
151 static ssize_t
ipp_read_file(int *fd
, ipp_uchar_t
*buffer
,
153 static void ipp_set_error(ipp_status_t status
, const char *format
,
155 static _ipp_value_t
*ipp_set_value(ipp_t
*ipp
, ipp_attribute_t
**attr
,
157 static ssize_t
ipp_write_file(int *fd
, ipp_uchar_t
*buffer
,
162 * '_cupsBufferGet()' - Get a read/write buffer.
165 char * /* O - Buffer */
166 _cupsBufferGet(size_t size
) /* I - Size required */
168 _cups_buffer_t
*buffer
; /* Current buffer */
169 _cups_globals_t
*cg
= _cupsGlobals();
173 for (buffer
= cg
->cups_buffers
; buffer
; buffer
= buffer
->next
)
174 if (!buffer
->used
&& buffer
->size
>= size
)
179 if ((buffer
= malloc(sizeof(_cups_buffer_t
) + size
- 1)) == NULL
)
182 buffer
->next
= cg
->cups_buffers
;
184 cg
->cups_buffers
= buffer
;
194 * '_cupsBufferRelease()' - Release a read/write buffer.
198 _cupsBufferRelease(char *b
) /* I - Buffer to release */
200 _cups_buffer_t
*buffer
; /* Buffer */
204 * Mark this buffer as unused...
207 buffer
= (_cups_buffer_t
*)(b
- offsetof(_cups_buffer_t
, d
));
213 * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
215 * The @code ipp@ parameter refers to an IPP message previously created using
216 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
218 * The @code group@ parameter specifies the IPP attribute group tag: none
219 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
220 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
221 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
222 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
225 ipp_attribute_t
* /* O - New attribute */
226 ippAddBoolean(ipp_t
*ipp
, /* I - IPP message */
227 ipp_tag_t group
, /* I - IPP group */
228 const char *name
, /* I - Name of attribute */
229 char value
) /* I - Value of attribute */
231 ipp_attribute_t
*attr
; /* New attribute */
234 DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)",
235 ipp
, group
, ippTagString(group
), name
, value
));
238 * Range check input...
241 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
242 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
246 * Create the attribute...
249 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, 1)) == NULL
)
252 attr
->values
[0].boolean
= value
;
259 * 'ippAddBooleans()' - Add an array of boolean values.
261 * The @code ipp@ parameter refers to an IPP message previously created using
262 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
264 * The @code group@ parameter specifies the IPP attribute group tag: none
265 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
266 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
267 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
268 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
271 ipp_attribute_t
* /* O - New attribute */
272 ippAddBooleans(ipp_t
*ipp
, /* I - IPP message */
273 ipp_tag_t group
, /* I - IPP group */
274 const char *name
, /* I - Name of attribute */
275 int num_values
, /* I - Number of values */
276 const char *values
) /* I - Values */
278 int i
; /* Looping var */
279 ipp_attribute_t
*attr
; /* New attribute */
280 _ipp_value_t
*value
; /* Current value */
283 DEBUG_printf(("ippAddBooleans(ipp=%p, group=%02x(%s), name=\"%s\", "
284 "num_values=%d, values=%p)", ipp
, group
, ippTagString(group
),
285 name
, num_values
, values
));
288 * Range check input...
291 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
292 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
297 * Create the attribute...
300 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, num_values
)) == NULL
)
305 for (i
= num_values
, value
= attr
->values
;
308 value
->boolean
= *values
++;
316 * 'ippAddCollection()' - Add a collection value.
318 * The @code ipp@ parameter refers to an IPP message previously created using
319 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
321 * The @code group@ parameter specifies the IPP attribute group tag: none
322 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
323 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
324 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
325 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
327 * @since CUPS 1.1.19/OS X 10.3@
330 ipp_attribute_t
* /* O - New attribute */
331 ippAddCollection(ipp_t
*ipp
, /* I - IPP message */
332 ipp_tag_t group
, /* I - IPP group */
333 const char *name
, /* I - Name of attribute */
334 ipp_t
*value
) /* I - Value */
336 ipp_attribute_t
*attr
; /* New attribute */
339 DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", "
340 "value=%p)", ipp
, group
, ippTagString(group
), name
, value
));
343 * Range check input...
346 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
347 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
351 * Create the attribute...
354 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
, 1)) == NULL
)
357 attr
->values
[0].collection
= value
;
367 * 'ippAddCollections()' - Add an array of collection values.
369 * The @code ipp@ parameter refers to an IPP message previously created using
370 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
372 * The @code group@ parameter specifies the IPP attribute group tag: none
373 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
374 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
375 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
376 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
378 * @since CUPS 1.1.19/OS X 10.3@
381 ipp_attribute_t
* /* O - New attribute */
383 ipp_t
*ipp
, /* I - IPP message */
384 ipp_tag_t group
, /* I - IPP group */
385 const char *name
, /* I - Name of attribute */
386 int num_values
, /* I - Number of values */
387 const ipp_t
**values
) /* I - Values */
389 int i
; /* Looping var */
390 ipp_attribute_t
*attr
; /* New attribute */
391 _ipp_value_t
*value
; /* Current value */
394 DEBUG_printf(("ippAddCollections(ipp=%p, group=%02x(%s), name=\"%s\", "
395 "num_values=%d, values=%p)", ipp
, group
, ippTagString(group
),
396 name
, num_values
, values
));
399 * Range check input...
402 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
403 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
408 * Create the attribute...
411 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
,
412 num_values
)) == NULL
)
417 for (i
= num_values
, value
= attr
->values
;
421 value
->collection
= (ipp_t
*)*values
++;
422 value
->collection
->use
++;
431 * 'ippAddDate()' - Add a date attribute to an IPP message.
433 * The @code ipp@ parameter refers to an IPP message previously created using
434 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
436 * The @code group@ parameter specifies the IPP attribute group tag: none
437 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
438 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
439 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
440 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
443 ipp_attribute_t
* /* O - New attribute */
444 ippAddDate(ipp_t
*ipp
, /* I - IPP message */
445 ipp_tag_t group
, /* I - IPP group */
446 const char *name
, /* I - Name of attribute */
447 const ipp_uchar_t
*value
) /* I - Value */
449 ipp_attribute_t
*attr
; /* New attribute */
452 DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)",
453 ipp
, group
, ippTagString(group
), name
, value
));
456 * Range check input...
459 if (!ipp
|| !name
|| !value
|| group
< IPP_TAG_ZERO
||
460 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
464 * Create the attribute...
467 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_DATE
, 1)) == NULL
)
470 memcpy(attr
->values
[0].date
, value
, 11);
477 * 'ippAddInteger()' - Add a integer attribute to an IPP message.
479 * The @code ipp@ parameter refers to an IPP message previously created using
480 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
482 * The @code group@ parameter specifies the IPP attribute group tag: none
483 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
484 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
485 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
486 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
488 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
489 * (@code IPP_TAG_INTEGER@).
492 ipp_attribute_t
* /* O - New attribute */
493 ippAddInteger(ipp_t
*ipp
, /* I - IPP message */
494 ipp_tag_t group
, /* I - IPP group */
495 ipp_tag_t value_tag
, /* I - Type of attribute */
496 const char *name
, /* I - Name of attribute */
497 int value
) /* I - Value of attribute */
499 ipp_attribute_t
*attr
; /* New attribute */
502 DEBUG_printf(("ippAddInteger(ipp=%p, group=%02x(%s), type=%02x(%s), "
503 "name=\"%s\", value=%d)", ipp
, group
, ippTagString(group
),
504 value_tag
, ippTagString(value_tag
), name
, value
));
506 value_tag
&= IPP_TAG_MASK
;
509 * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
513 if (value_tag
>= IPP_TAG_UNSUPPORTED_VALUE
&& value_tag
<= IPP_TAG_ADMINDEFINE
)
514 return (ippAddOutOfBand(ipp
, group
, value_tag
, name
));
517 * Range check input...
521 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
522 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
523 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
))
526 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
527 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
532 * Create the attribute...
535 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
538 attr
->values
[0].integer
= value
;
545 * 'ippAddIntegers()' - Add an array of integer values.
547 * The @code ipp@ parameter refers to an IPP message previously created using
548 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
550 * The @code group@ parameter specifies the IPP attribute group tag: none
551 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
552 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
553 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
554 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
556 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
557 * (@code IPP_TAG_INTEGER@).
560 ipp_attribute_t
* /* O - New attribute */
561 ippAddIntegers(ipp_t
*ipp
, /* I - IPP message */
562 ipp_tag_t group
, /* I - IPP group */
563 ipp_tag_t value_tag
, /* I - Type of attribute */
564 const char *name
, /* I - Name of attribute */
565 int num_values
, /* I - Number of values */
566 const int *values
) /* I - Values */
568 int i
; /* Looping var */
569 ipp_attribute_t
*attr
; /* New attribute */
570 _ipp_value_t
*value
; /* Current value */
573 DEBUG_printf(("ippAddIntegers(ipp=%p, group=%02x(%s), type=%02x(%s), "
574 "name=\"%s\", num_values=%d, values=%p)", ipp
,
575 group
, ippTagString(group
), value_tag
, ippTagString(value_tag
), name
,
576 num_values
, values
));
578 value_tag
&= IPP_TAG_MASK
;
581 * Range check input...
585 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
586 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
587 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
) ||
591 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
592 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
598 * Create the attribute...
601 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
606 for (i
= num_values
, value
= attr
->values
;
609 value
->integer
= *values
++;
617 * 'ippAddOctetString()' - Add an octetString value to an IPP message.
619 * The @code ipp@ parameter refers to an IPP message previously created using
620 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
622 * The @code group@ parameter specifies the IPP attribute group tag: none
623 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
624 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
625 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
626 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
628 * @since CUPS 1.2/OS X 10.5@
631 ipp_attribute_t
* /* O - New attribute */
632 ippAddOctetString(ipp_t
*ipp
, /* I - IPP message */
633 ipp_tag_t group
, /* I - IPP group */
634 const char *name
, /* I - Name of attribute */
635 const void *data
, /* I - octetString data */
636 int datalen
) /* I - Length of data in bytes */
638 ipp_attribute_t
*attr
; /* New attribute */
641 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
642 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
643 datalen
< 0 || datalen
> IPP_MAX_LENGTH
)
646 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_STRING
, 1)) == NULL
)
650 * Initialize the attribute data...
653 attr
->values
[0].unknown
.length
= datalen
;
657 if ((attr
->values
[0].unknown
.data
= malloc(datalen
)) == NULL
)
659 ippDeleteAttribute(ipp
, attr
);
663 memcpy(attr
->values
[0].unknown
.data
, data
, datalen
);
667 * Return the new attribute...
675 * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
677 * The @code ipp@ parameter refers to an IPP message previously created using
678 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
680 * The @code group@ parameter specifies the IPP attribute group tag: none
681 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
682 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
683 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
684 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
686 * Supported out-of-band values include unsupported-value
687 * (@code IPP_TAG_UNSUPPORTED_VALUE@), default (@code IPP_TAG_DEFAULT@), unknown
688 * (@code IPP_TAG_UNKNOWN@), no-value (@code IPP_TAG_NOVALUE@), not-settable
689 * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
690 * admin-define (@code IPP_TAG_ADMINDEFINE@).
692 * @since CUPS 1.6/OS X 10.8@
695 ipp_attribute_t
* /* O - New attribute */
696 ippAddOutOfBand(ipp_t
*ipp
, /* I - IPP message */
697 ipp_tag_t group
, /* I - IPP group */
698 ipp_tag_t value_tag
, /* I - Type of attribute */
699 const char *name
) /* I - Name of attribute */
701 DEBUG_printf(("ippAddOutOfBand(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
702 "name=\"%s\")", ipp
, group
, ippTagString(group
), value_tag
,
703 ippTagString(value_tag
), name
));
705 value_tag
&= IPP_TAG_MASK
;
708 * Range check input...
711 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
712 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
713 (value_tag
!= IPP_TAG_UNSUPPORTED_VALUE
&&
714 value_tag
!= IPP_TAG_DEFAULT
&&
715 value_tag
!= IPP_TAG_UNKNOWN
&&
716 value_tag
!= IPP_TAG_NOVALUE
&&
717 value_tag
!= IPP_TAG_NOTSETTABLE
&&
718 value_tag
!= IPP_TAG_DELETEATTR
&&
719 value_tag
!= IPP_TAG_ADMINDEFINE
))
723 * Create the attribute...
726 return (ipp_add_attr(ipp
, name
, group
, value_tag
, 1));
731 * 'ippAddRange()' - Add a range of values to an IPP message.
733 * The @code ipp@ parameter refers to an IPP message previously created using
734 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
736 * The @code group@ parameter specifies the IPP attribute group tag: none
737 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
738 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
739 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
740 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
742 * The @code lower@ parameter must be less than or equal to the @code upper@ parameter.
745 ipp_attribute_t
* /* O - New attribute */
746 ippAddRange(ipp_t
*ipp
, /* I - IPP message */
747 ipp_tag_t group
, /* I - IPP group */
748 const char *name
, /* I - Name of attribute */
749 int lower
, /* I - Lower value */
750 int upper
) /* I - Upper value */
752 ipp_attribute_t
*attr
; /* New attribute */
755 DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, "
756 "upper=%d)", ipp
, group
, ippTagString(group
), name
, lower
,
760 * Range check input...
763 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
764 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
768 * Create the attribute...
771 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, 1)) == NULL
)
774 attr
->values
[0].range
.lower
= lower
;
775 attr
->values
[0].range
.upper
= upper
;
782 * 'ippAddRanges()' - Add ranges of values to an IPP message.
784 * The @code ipp@ parameter refers to an IPP message previously created using
785 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
787 * The @code group@ parameter specifies the IPP attribute group tag: none
788 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
789 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
790 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
791 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
794 ipp_attribute_t
* /* O - New attribute */
795 ippAddRanges(ipp_t
*ipp
, /* I - IPP message */
796 ipp_tag_t group
, /* I - IPP group */
797 const char *name
, /* I - Name of attribute */
798 int num_values
, /* I - Number of values */
799 const int *lower
, /* I - Lower values */
800 const int *upper
) /* I - Upper values */
802 int i
; /* Looping var */
803 ipp_attribute_t
*attr
; /* New attribute */
804 _ipp_value_t
*value
; /* Current value */
807 DEBUG_printf(("ippAddRanges(ipp=%p, group=%02x(%s), name=\"%s\", "
808 "num_values=%d, lower=%p, upper=%p)", ipp
, group
,
809 ippTagString(group
), name
, num_values
, lower
, upper
));
812 * Range check input...
815 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
816 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
821 * Create the attribute...
824 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, num_values
)) == NULL
)
829 for (i
= num_values
, value
= attr
->values
;
833 value
->range
.lower
= *lower
++;
834 value
->range
.upper
= *upper
++;
843 * 'ippAddResolution()' - Add a resolution value to an IPP message.
845 * The @code ipp@ parameter refers to an IPP message previously created using
846 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
848 * The @code group@ parameter specifies the IPP attribute group tag: none
849 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
850 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
851 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
852 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
855 ipp_attribute_t
* /* O - New attribute */
856 ippAddResolution(ipp_t
*ipp
, /* I - IPP message */
857 ipp_tag_t group
, /* I - IPP group */
858 const char *name
, /* I - Name of attribute */
859 ipp_res_t units
, /* I - Units for resolution */
860 int xres
, /* I - X resolution */
861 int yres
) /* I - Y resolution */
863 ipp_attribute_t
*attr
; /* New attribute */
866 DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", "
867 "units=%d, xres=%d, yres=%d)", ipp
, group
,
868 ippTagString(group
), name
, units
, xres
, yres
));
871 * Range check input...
874 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
875 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
876 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
||
877 xres
< 0 || yres
< 0)
881 * Create the attribute...
884 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, 1)) == NULL
)
887 attr
->values
[0].resolution
.xres
= xres
;
888 attr
->values
[0].resolution
.yres
= yres
;
889 attr
->values
[0].resolution
.units
= units
;
896 * 'ippAddResolutions()' - Add resolution values to an IPP message.
898 * The @code ipp@ parameter refers to an IPP message previously created using
899 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
901 * The @code group@ parameter specifies the IPP attribute group tag: none
902 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
903 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
904 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
905 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
908 ipp_attribute_t
* /* O - New attribute */
909 ippAddResolutions(ipp_t
*ipp
, /* I - IPP message */
910 ipp_tag_t group
, /* I - IPP group */
911 const char *name
, /* I - Name of attribute */
912 int num_values
,/* I - Number of values */
913 ipp_res_t units
, /* I - Units for resolution */
914 const int *xres
, /* I - X resolutions */
915 const int *yres
) /* I - Y resolutions */
917 int i
; /* Looping var */
918 ipp_attribute_t
*attr
; /* New attribute */
919 _ipp_value_t
*value
; /* Current value */
922 DEBUG_printf(("ippAddResolutions(ipp=%p, group=%02x(%s), name=\"%s\", "
923 "num_value=%d, units=%d, xres=%p, yres=%p)", ipp
, group
,
924 ippTagString(group
), name
, num_values
, units
, xres
, yres
));
927 * Range check input...
930 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
931 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
933 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
)
937 * Create the attribute...
940 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, num_values
)) == NULL
)
945 for (i
= num_values
, value
= attr
->values
;
949 value
->resolution
.xres
= *xres
++;
950 value
->resolution
.yres
= *yres
++;
951 value
->resolution
.units
= units
;
960 * 'ippAddSeparator()' - Add a group separator to an IPP message.
962 * The @code ipp@ parameter refers to an IPP message previously created using
963 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
966 ipp_attribute_t
* /* O - New attribute */
967 ippAddSeparator(ipp_t
*ipp
) /* I - IPP message */
969 DEBUG_printf(("ippAddSeparator(ipp=%p)", ipp
));
972 * Range check input...
979 * Create the attribute...
982 return (ipp_add_attr(ipp
, NULL
, IPP_TAG_ZERO
, IPP_TAG_ZERO
, 0));
987 * 'ippAddString()' - Add a language-encoded string to an IPP message.
989 * The @code ipp@ parameter refers to an IPP message previously created using
990 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
992 * The @code group@ parameter specifies the IPP attribute group tag: none
993 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
994 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
995 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
996 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
998 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
999 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1000 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1001 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1002 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1003 * (@code IPP_TAG_URISCHEME@).
1005 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1006 * textWithLanguage string values and must be @code NULL@ for all other string values.
1009 ipp_attribute_t
* /* O - New attribute */
1010 ippAddString(ipp_t
*ipp
, /* I - IPP message */
1011 ipp_tag_t group
, /* I - IPP group */
1012 ipp_tag_t value_tag
, /* I - Type of attribute */
1013 const char *name
, /* I - Name of attribute */
1014 const char *language
, /* I - Language code */
1015 const char *value
) /* I - Value */
1017 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1018 ipp_attribute_t
*attr
; /* New attribute */
1019 char code
[IPP_MAX_LANGUAGE
];
1020 /* Charset/language code buffer */
1023 DEBUG_printf(("ippAddString(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
1024 "name=\"%s\", language=\"%s\", value=\"%s\")", ipp
,
1025 group
, ippTagString(group
), value_tag
, ippTagString(value_tag
), name
,
1029 * Range check input...
1032 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_MASK
);
1035 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1036 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1037 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1038 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
)
1041 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1042 != (language
!= NULL
))
1045 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1046 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
1051 * See if we need to map charset, language, or locale values...
1054 if (language
&& ((int)value_tag
& IPP_TAG_COPY
) &&
1055 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1056 value_tag
= temp_tag
; /* Don't do a fast copy */
1057 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_COPY
) &&
1058 strcmp(value
, ipp_get_code(value
, code
, sizeof(code
))))
1059 value_tag
= temp_tag
; /* Don't do a fast copy */
1060 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_COPY
) &&
1061 strcmp(value
, ipp_lang_code(value
, code
, sizeof(code
))))
1062 value_tag
= temp_tag
; /* Don't do a fast copy */
1065 * Create the attribute...
1068 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
1072 * Initialize the attribute data...
1075 if ((int)value_tag
& IPP_TAG_COPY
)
1077 attr
->values
[0].string
.language
= (char *)language
;
1078 attr
->values
[0].string
.text
= (char *)value
;
1083 attr
->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1088 if (value_tag
== IPP_TAG_CHARSET
)
1089 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_get_code(value
, code
,
1091 else if (value_tag
== IPP_TAG_LANGUAGE
)
1092 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_lang_code(value
, code
,
1095 attr
->values
[0].string
.text
= _cupsStrAlloc(value
);
1104 * 'ippAddStringf()' - Add a formatted string to an IPP message.
1106 * The @code ipp@ parameter refers to an IPP message previously created using
1107 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1109 * The @code group@ parameter specifies the IPP attribute group tag: none
1110 * (@code IPP_TAG_ZERO@, for member attributes), document
1111 * (@code IPP_TAG_DOCUMENT@), event notification
1112 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1113 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1114 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1116 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1117 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1118 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1119 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1120 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1121 * (@code IPP_TAG_URISCHEME@).
1123 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1124 * and textWithLanguage string values and must be @code NULL@ for all other
1127 * The @code format@ parameter uses formatting characters compatible with the
1128 * printf family of standard functions. Additional arguments follow it as
1129 * needed. The formatted string is truncated as needed to the maximum length of
1130 * the corresponding value type.
1135 ipp_attribute_t
* /* O - New attribute */
1136 ippAddStringf(ipp_t
*ipp
, /* I - IPP message */
1137 ipp_tag_t group
, /* I - IPP group */
1138 ipp_tag_t value_tag
, /* I - Type of attribute */
1139 const char *name
, /* I - Name of attribute */
1140 const char *language
, /* I - Language code (@code NULL@ for default) */
1141 const char *format
, /* I - Printf-style format string */
1142 ...) /* I - Additional arguments as needed */
1144 ipp_attribute_t
*attr
; /* New attribute */
1145 va_list ap
; /* Argument pointer */
1148 va_start(ap
, format
);
1149 attr
= ippAddStringfv(ipp
, group
, value_tag
, name
, language
, format
, ap
);
1157 * 'ippAddStringfv()' - Add a formatted string to an IPP message.
1159 * The @code ipp@ parameter refers to an IPP message previously created using
1160 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1162 * The @code group@ parameter specifies the IPP attribute group tag: none
1163 * (@code IPP_TAG_ZERO@, for member attributes), document
1164 * (@code IPP_TAG_DOCUMENT@), event notification
1165 * (@code IPP_TAG_EVENT_NOTIFICATION@), operation (@code IPP_TAG_OPERATION@),
1166 * printer (@code IPP_TAG_PRINTER@), subscription (@code IPP_TAG_SUBSCRIPTION@),
1167 * or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1169 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1170 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1171 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1172 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1173 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1174 * (@code IPP_TAG_URISCHEME@).
1176 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage
1177 * and textWithLanguage string values and must be @code NULL@ for all other
1180 * The @code format@ parameter uses formatting characters compatible with the
1181 * printf family of standard functions. Additional arguments are passed in the
1182 * stdarg pointer @code ap@. The formatted string is truncated as needed to the
1183 * maximum length of the corresponding value type.
1188 ipp_attribute_t
* /* O - New attribute */
1189 ippAddStringfv(ipp_t
*ipp
, /* I - IPP message */
1190 ipp_tag_t group
, /* I - IPP group */
1191 ipp_tag_t value_tag
, /* I - Type of attribute */
1192 const char *name
, /* I - Name of attribute */
1193 const char *language
, /* I - Language code (@code NULL@ for default) */
1194 const char *format
, /* I - Printf-style format string */
1195 va_list ap
) /* I - Additional arguments */
1197 char buffer
[IPP_MAX_TEXT
+ 4];
1198 /* Formatted text string */
1199 ssize_t bytes
, /* Length of formatted value */
1200 max_bytes
; /* Maximum number of bytes for value */
1204 * Range check input...
1207 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1208 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1209 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
1210 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
1214 if ((value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_NAMELANG
)
1215 != (language
!= NULL
))
1219 * Format the string...
1222 if (!strcmp(format
, "%s"))
1225 * Optimize the simple case...
1228 const char *s
= va_arg(ap
, char *);
1234 strlcpy(buffer
, s
, sizeof(buffer
));
1239 * Do a full formatting of the message...
1242 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
1247 * Limit the length of the string...
1254 case IPP_TAG_TEXTLANG
:
1255 max_bytes
= IPP_MAX_TEXT
;
1259 case IPP_TAG_NAMELANG
:
1260 max_bytes
= IPP_MAX_NAME
;
1263 case IPP_TAG_CHARSET
:
1264 max_bytes
= IPP_MAX_CHARSET
;
1267 case IPP_TAG_KEYWORD
:
1268 max_bytes
= IPP_MAX_KEYWORD
;
1271 case IPP_TAG_LANGUAGE
:
1272 max_bytes
= IPP_MAX_LANGUAGE
;
1275 case IPP_TAG_MIMETYPE
:
1276 max_bytes
= IPP_MAX_MIMETYPE
;
1280 max_bytes
= IPP_MAX_URI
;
1283 case IPP_TAG_URISCHEME
:
1284 max_bytes
= IPP_MAX_URISCHEME
;
1288 if (bytes
>= max_bytes
)
1290 char *bufmax
, /* Buffer at max_bytes */
1291 *bufptr
; /* Pointer into buffer */
1293 bufptr
= buffer
+ strlen(buffer
) - 1;
1294 bufmax
= buffer
+ max_bytes
- 1;
1296 while (bufptr
> bufmax
)
1300 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
1311 * Add the formatted string and return...
1314 return (ippAddString(ipp
, group
, value_tag
, name
, language
, buffer
));
1319 * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
1321 * The @code ipp@ parameter refers to an IPP message previously created using
1322 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
1324 * The @code group@ parameter specifies the IPP attribute group tag: none
1325 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
1326 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
1327 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
1328 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1330 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1331 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1332 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1333 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1334 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1335 * (@code IPP_TAG_URISCHEME@).
1337 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1338 * textWithLanguage string values and must be @code NULL@ for all other string values.
1341 ipp_attribute_t
* /* O - New attribute */
1343 ipp_t
*ipp
, /* I - IPP message */
1344 ipp_tag_t group
, /* I - IPP group */
1345 ipp_tag_t value_tag
, /* I - Type of attribute */
1346 const char *name
, /* I - Name of attribute */
1347 int num_values
, /* I - Number of values */
1348 const char *language
, /* I - Language code (@code NULL@ for default) */
1349 const char * const *values
) /* I - Values */
1351 int i
; /* Looping var */
1352 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1353 ipp_attribute_t
*attr
; /* New attribute */
1354 _ipp_value_t
*value
; /* Current value */
1355 char code
[32]; /* Language/charset value buffer */
1358 DEBUG_printf(("ippAddStrings(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
1359 "name=\"%s\", num_values=%d, language=\"%s\", values=%p)", ipp
,
1360 group
, ippTagString(group
), value_tag
, ippTagString(value_tag
), name
,
1361 num_values
, language
, values
));
1364 * Range check input...
1367 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_MASK
);
1370 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1371 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1372 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1373 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
||
1377 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1378 != (language
!= NULL
))
1381 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1382 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1388 * See if we need to map charset, language, or locale values...
1391 if (language
&& ((int)value_tag
& IPP_TAG_COPY
) &&
1392 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1393 value_tag
= temp_tag
; /* Don't do a fast copy */
1394 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_COPY
))
1396 for (i
= 0; i
< num_values
; i
++)
1397 if (strcmp(values
[i
], ipp_get_code(values
[i
], code
, sizeof(code
))))
1399 value_tag
= temp_tag
; /* Don't do a fast copy */
1403 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_COPY
))
1405 for (i
= 0; i
< num_values
; i
++)
1406 if (strcmp(values
[i
], ipp_lang_code(values
[i
], code
, sizeof(code
))))
1408 value_tag
= temp_tag
; /* Don't do a fast copy */
1414 * Create the attribute...
1417 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
1421 * Initialize the attribute data...
1424 for (i
= num_values
, value
= attr
->values
;
1430 if (value
== attr
->values
)
1432 if ((int)value_tag
& IPP_TAG_COPY
)
1433 value
->string
.language
= (char *)language
;
1435 value
->string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1439 value
->string
.language
= attr
->values
[0].string
.language
;
1444 if ((int)value_tag
& IPP_TAG_COPY
)
1445 value
->string
.text
= (char *)*values
++;
1446 else if (value_tag
== IPP_TAG_CHARSET
)
1447 value
->string
.text
= _cupsStrAlloc(ipp_get_code(*values
++, code
, sizeof(code
)));
1448 else if (value_tag
== IPP_TAG_LANGUAGE
)
1449 value
->string
.text
= _cupsStrAlloc(ipp_lang_code(*values
++, code
, sizeof(code
)));
1451 value
->string
.text
= _cupsStrAlloc(*values
++);
1460 * 'ippContainsInteger()' - Determine whether an attribute contains the
1461 * specified value or is within the list of ranges.
1463 * Returns non-zero when the attribute contains either a matching integer or
1464 * enum value, or the value falls within one of the rangeOfInteger values for
1470 int /* O - 1 on a match, 0 on no match */
1472 ipp_attribute_t
*attr
, /* I - Attribute */
1473 int value
) /* I - Integer/enum value */
1475 int i
; /* Looping var */
1476 _ipp_value_t
*avalue
; /* Current attribute value */
1480 * Range check input...
1486 if (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
&&
1487 attr
->value_tag
!= IPP_TAG_RANGE
)
1494 if (attr
->value_tag
== IPP_TAG_RANGE
)
1496 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1497 if (value
>= avalue
->range
.lower
&& value
<= avalue
->range
.upper
)
1502 for (i
= attr
->num_values
, avalue
= attr
->values
; i
> 0; i
--, avalue
++)
1503 if (value
== avalue
->integer
)
1512 * 'ippContainsString()' - Determine whether an attribute contains the
1513 * specified string value.
1515 * Returns non-zero when the attribute contains a matching charset, keyword,
1516 * language, mimeMediaType, name, text, URI, or URI scheme value.
1521 int /* O - 1 on a match, 0 on no match */
1523 ipp_attribute_t
*attr
, /* I - Attribute */
1524 const char *value
) /* I - String value */
1526 int i
; /* Looping var */
1527 _ipp_value_t
*avalue
; /* Current attribute value */
1530 DEBUG_printf(("ippContainsString(attr=%p, value=\"%s\")", attr
, value
));
1533 * Range check input...
1536 if (!attr
|| !value
)
1538 DEBUG_puts("1ippContainsString: Returning 0 (bad input)");
1546 DEBUG_printf(("1ippContainsString: attr %s, %s with %d values.",
1547 attr
->name
, ippTagString(attr
->value_tag
),
1550 switch (attr
->value_tag
& IPP_TAG_CUPS_MASK
)
1552 case IPP_TAG_CHARSET
:
1553 case IPP_TAG_KEYWORD
:
1554 case IPP_TAG_LANGUAGE
:
1555 case IPP_TAG_MIMETYPE
:
1557 case IPP_TAG_NAMELANG
:
1559 case IPP_TAG_TEXTLANG
:
1561 case IPP_TAG_URISCHEME
:
1562 for (i
= attr
->num_values
, avalue
= attr
->values
;
1566 DEBUG_printf(("1ippContainsString: value[%d]=\"%s\"",
1567 attr
->num_values
- i
, avalue
->string
.text
));
1569 if (!strcmp(value
, avalue
->string
.text
))
1571 DEBUG_puts("1ippContainsString: Returning 1 (match)");
1580 DEBUG_puts("1ippContainsString: Returning 0 (no match)");
1587 * 'ippCopyAttribute()' - Copy an attribute.
1589 * The specified attribute, @code attr@, is copied to the destination IPP message.
1590 * When @code quickcopy@ is non-zero, a "shallow" reference copy of the attribute is
1591 * created - this should only be done as long as the original source IPP message will
1592 * not be freed for the life of the destination.
1594 * @since CUPS 1.6/OS X 10.8@
1598 ipp_attribute_t
* /* O - New attribute */
1600 ipp_t
*dst
, /* I - Destination IPP message */
1601 ipp_attribute_t
*srcattr
, /* I - Attribute to copy */
1602 int quickcopy
) /* I - 1 for a referenced copy, 0 for normal */
1604 int i
; /* Looping var */
1605 ipp_attribute_t
*dstattr
; /* Destination attribute */
1606 _ipp_value_t
*srcval
, /* Source value */
1607 *dstval
; /* Destination value */
1610 DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", dst
, srcattr
,
1614 * Range check input...
1617 if (!dst
|| !srcattr
)
1624 quickcopy
= quickcopy
? IPP_TAG_COPY
: 0;
1626 switch (srcattr
->value_tag
& ~IPP_TAG_COPY
)
1629 dstattr
= ippAddSeparator(dst
);
1632 case IPP_TAG_INTEGER
:
1634 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1635 srcattr
->name
, srcattr
->num_values
, NULL
);
1639 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1641 i
--, srcval
++, dstval
++)
1642 dstval
->integer
= srcval
->integer
;
1645 case IPP_TAG_BOOLEAN
:
1646 dstattr
= ippAddBooleans(dst
, srcattr
->group_tag
, srcattr
->name
,
1647 srcattr
->num_values
, NULL
);
1651 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1653 i
--, srcval
++, dstval
++)
1654 dstval
->boolean
= srcval
->boolean
;
1659 case IPP_TAG_KEYWORD
:
1661 case IPP_TAG_URISCHEME
:
1662 case IPP_TAG_CHARSET
:
1663 case IPP_TAG_LANGUAGE
:
1664 case IPP_TAG_MIMETYPE
:
1665 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1666 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1667 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1673 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1674 dstval
= dstattr
->values
;
1676 i
--, srcval
++, dstval
++)
1677 dstval
->string
.text
= srcval
->string
.text
;
1679 else if (srcattr
->value_tag
& IPP_TAG_COPY
)
1681 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1682 dstval
= dstattr
->values
;
1684 i
--, srcval
++, dstval
++)
1685 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1689 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1690 dstval
= dstattr
->values
;
1692 i
--, srcval
++, dstval
++)
1693 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1698 if (srcattr
->num_values
!= 1)
1701 dstattr
= ippAddDate(dst
, srcattr
->group_tag
, srcattr
->name
,
1702 srcattr
->values
[0].date
);
1705 case IPP_TAG_RESOLUTION
:
1706 dstattr
= ippAddResolutions(dst
, srcattr
->group_tag
, srcattr
->name
,
1707 srcattr
->num_values
, IPP_RES_PER_INCH
,
1712 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1714 i
--, srcval
++, dstval
++)
1716 dstval
->resolution
.xres
= srcval
->resolution
.xres
;
1717 dstval
->resolution
.yres
= srcval
->resolution
.yres
;
1718 dstval
->resolution
.units
= srcval
->resolution
.units
;
1722 case IPP_TAG_RANGE
:
1723 dstattr
= ippAddRanges(dst
, srcattr
->group_tag
, srcattr
->name
,
1724 srcattr
->num_values
, NULL
, NULL
);
1728 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1730 i
--, srcval
++, dstval
++)
1732 dstval
->range
.lower
= srcval
->range
.lower
;
1733 dstval
->range
.upper
= srcval
->range
.upper
;
1737 case IPP_TAG_TEXTLANG
:
1738 case IPP_TAG_NAMELANG
:
1739 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1740 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1741 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1747 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1748 dstval
= dstattr
->values
;
1750 i
--, srcval
++, dstval
++)
1752 dstval
->string
.language
= srcval
->string
.language
;
1753 dstval
->string
.text
= srcval
->string
.text
;
1756 else if (srcattr
->value_tag
& IPP_TAG_COPY
)
1758 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1759 dstval
= dstattr
->values
;
1761 i
--, srcval
++, dstval
++)
1763 if (srcval
== srcattr
->values
)
1764 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1766 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1768 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1773 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1774 dstval
= dstattr
->values
;
1776 i
--, srcval
++, dstval
++)
1778 if (srcval
== srcattr
->values
)
1779 dstval
->string
.language
= _cupsStrRetain(srcval
->string
.language
);
1781 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1783 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1788 case IPP_TAG_BEGIN_COLLECTION
:
1789 dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
,
1790 srcattr
->num_values
, NULL
);
1794 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1796 i
--, srcval
++, dstval
++)
1798 dstval
->collection
= srcval
->collection
;
1799 srcval
->collection
->use
++;
1803 case IPP_TAG_STRING
:
1805 /* TODO: Implement quick copy for unknown/octetString values */
1806 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1807 srcattr
->name
, srcattr
->num_values
, NULL
);
1811 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1813 i
--, srcval
++, dstval
++)
1815 dstval
->unknown
.length
= srcval
->unknown
.length
;
1817 if (dstval
->unknown
.length
> 0)
1819 if ((dstval
->unknown
.data
= malloc(dstval
->unknown
.length
)) == NULL
)
1820 dstval
->unknown
.length
= 0;
1822 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, dstval
->unknown
.length
);
1825 break; /* anti-compiler-warning-code */
1833 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1835 * Zero or more attributes are copied from the source IPP message, @code@ src, to the
1836 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1837 * reference copy of the attribute is created - this should only be done as long as the
1838 * original source IPP message will not be freed for the life of the destination.
1840 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1841 * attributes that are copied - the function must return 1 to copy the attribute or
1842 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1845 * @since CUPS 1.6/OS X 10.8@
1848 int /* O - 1 on success, 0 on error */
1850 ipp_t
*dst
, /* I - Destination IPP message */
1851 ipp_t
*src
, /* I - Source IPP message */
1852 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1853 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1854 void *context
) /* I - Context pointer */
1856 ipp_attribute_t
*srcattr
; /* Source attribute */
1859 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)",
1860 dst
, src
, quickcopy
, cb
, context
));
1863 * Range check input...
1870 * Loop through source attributes and copy as needed...
1873 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1874 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1875 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1883 * 'ippDateToTime()' - Convert from RFC 1903 Date/Time format to UNIX time
1887 time_t /* O - UNIX time value */
1888 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 1903 date info */
1890 struct tm unixdate
; /* UNIX date/time info */
1891 time_t t
; /* Computed time */
1897 memset(&unixdate
, 0, sizeof(unixdate
));
1900 * RFC-1903 date/time format is:
1902 * Byte(s) Description
1903 * ------- -----------
1904 * 0-1 Year (0 to 65535)
1908 * 5 Minutes (0 to 59)
1909 * 6 Seconds (0 to 60, 60 = "leap second")
1910 * 7 Deciseconds (0 to 9)
1912 * 9 UTC hours (0 to 11)
1913 * 10 UTC minutes (0 to 59)
1916 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1917 unixdate
.tm_mon
= date
[2] - 1;
1918 unixdate
.tm_mday
= date
[3];
1919 unixdate
.tm_hour
= date
[4];
1920 unixdate
.tm_min
= date
[5];
1921 unixdate
.tm_sec
= date
[6];
1923 t
= mktime(&unixdate
);
1926 t
+= date
[9] * 3600 + date
[10] * 60;
1928 t
-= date
[9] * 3600 + date
[10] * 60;
1935 * 'ippDelete()' - Delete an IPP message.
1939 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1941 ipp_attribute_t
*attr
, /* Current attribute */
1942 *next
; /* Next attribute */
1945 DEBUG_printf(("ippDelete(ipp=%p)", ipp
));
1954 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1958 ipp_free_values(attr
, 0, attr
->num_values
);
1961 _cupsStrFree(attr
->name
);
1971 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1973 * @since CUPS 1.1.19/OS X 10.3@
1978 ipp_t
*ipp
, /* I - IPP message */
1979 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1981 ipp_attribute_t
*current
, /* Current attribute */
1982 *prev
; /* Previous attribute */
1985 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", ipp
, attr
,
1986 attr
? attr
->name
: "(null)"));
1989 * Range check input...
1996 * Find the attribute in the list...
2001 for (current
= ipp
->attrs
, prev
= NULL
;
2003 prev
= current
, current
= current
->next
)
2004 if (current
== attr
)
2007 * Found it, remove the attribute from the list...
2011 prev
->next
= current
->next
;
2013 ipp
->attrs
= current
->next
;
2015 if (current
== ipp
->last
)
2026 * Free memory used by the attribute...
2029 ipp_free_values(attr
, 0, attr
->num_values
);
2032 _cupsStrFree(attr
->name
);
2039 * 'ippDeleteValues()' - Delete values in an attribute.
2041 * The @code element@ parameter specifies the first value to delete, starting at
2042 * 0. It must be less than the number of values returned by @link ippGetCount@.
2044 * The @code attr@ parameter may be modified as a result of setting the value.
2046 * Deleting all values in an attribute deletes the attribute.
2048 * @since CUPS 1.6/OS X 10.8@
2051 int /* O - 1 on success, 0 on failure */
2053 ipp_t
*ipp
, /* I - IPP message */
2054 ipp_attribute_t
**attr
, /* IO - Attribute */
2055 int element
, /* I - Index of first value to delete (0-based) */
2056 int count
) /* I - Number of values to delete */
2059 * Range check input...
2062 if (!ipp
|| !attr
|| !*attr
||
2063 element
< 0 || element
>= (*attr
)->num_values
|| count
<= 0 ||
2064 (element
+ count
) >= (*attr
)->num_values
)
2068 * If we are deleting all values, just delete the attribute entirely.
2071 if (count
== (*attr
)->num_values
)
2073 ippDeleteAttribute(ipp
, *attr
);
2079 * Otherwise free the values in question and return.
2082 ipp_free_values(*attr
, element
, count
);
2089 * 'ippFindAttribute()' - Find a named attribute in a request.
2092 ipp_attribute_t
* /* O - Matching attribute */
2093 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
2094 const char *name
, /* I - Name of attribute */
2095 ipp_tag_t type
) /* I - Type of attribute */
2097 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", ipp
,
2098 name
, type
, ippTagString(type
)));
2104 * Reset the current pointer...
2107 ipp
->current
= NULL
;
2110 * Search for the attribute...
2113 return (ippFindNextAttribute(ipp
, name
, type
));
2118 * 'ippFindNextAttribute()' - Find the next named attribute in a request.
2121 ipp_attribute_t
* /* O - Matching attribute */
2122 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
2123 const char *name
, /* I - Name of attribute */
2124 ipp_tag_t type
) /* I - Type of attribute */
2126 ipp_attribute_t
*attr
; /* Current atttribute */
2127 ipp_tag_t value_tag
; /* Value tag */
2130 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))",
2131 ipp
, name
, type
, ippTagString(type
)));
2138 ipp
->prev
= ipp
->current
;
2139 attr
= ipp
->current
->next
;
2147 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
2149 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", attr
,
2152 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_MASK
);
2154 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
2155 (value_tag
== type
|| type
== IPP_TAG_ZERO
||
2156 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
2157 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
2159 ipp
->current
= attr
;
2165 ipp
->current
= NULL
;
2173 * 'ippFirstAttribute()' - Return the first attribute in the message.
2175 * @since CUPS 1.6/OS X 10.8@
2178 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
2179 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
2182 * Range check input...
2189 * Return the first attribute...
2192 return (ipp
->current
= ipp
->attrs
);
2197 * 'ippGetBoolean()' - Get a boolean value for an attribute.
2199 * The @code element@ parameter specifies which value to get from 0 to
2200 * @link ippGetCount(attr)@ - 1.
2202 * @since CUPS 1.6/OS X 10.8@
2205 int /* O - Boolean value or -1 on error */
2206 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
2207 int element
) /* I - Value number (0-based) */
2210 * Range check input...
2213 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
2214 element
< 0 || element
>= attr
->num_values
)
2218 * Return the value...
2221 return (attr
->values
[element
].boolean
);
2226 * 'ippGetCollection()' - Get a collection value for an attribute.
2228 * The @code element@ parameter specifies which value to get from 0 to
2229 * @link ippGetCount(attr)@ - 1.
2231 * @since CUPS 1.6/OS X 10.8@
2234 ipp_t
* /* O - Collection value or @code NULL@ on error */
2236 ipp_attribute_t
*attr
, /* I - IPP attribute */
2237 int element
) /* I - Value number (0-based) */
2240 * Range check input...
2243 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
2244 element
< 0 || element
>= attr
->num_values
)
2248 * Return the value...
2251 return (attr
->values
[element
].collection
);
2256 * 'ippGetCount()' - Get the number of values in an attribute.
2258 * @since CUPS 1.6/OS X 10.8@
2261 int /* O - Number of values or -1 on error */
2262 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
2265 * Range check input...
2272 * Return the number of values...
2275 return (attr
->num_values
);
2280 * 'ippGetDate()' - Get a date value for an attribute.
2282 * The @code element@ parameter specifies which value to get from 0 to
2283 * @link ippGetCount(attr)@ - 1.
2285 * @since CUPS 1.6/OS X 10.8@
2288 const ipp_uchar_t
* /* O - Date value or @code NULL@ */
2289 ippGetDate(ipp_attribute_t
*attr
, /* I - IPP attribute */
2290 int element
) /* I - Value number (0-based) */
2293 * Range check input...
2296 if (!attr
|| attr
->value_tag
!= IPP_TAG_DATE
||
2297 element
< 0 || element
>= attr
->num_values
)
2301 * Return the value...
2304 return (attr
->values
[element
].date
);
2309 * 'ippGetGroupTag()' - Get the group associated with an attribute.
2311 * @since CUPS 1.6/OS X 10.8@
2314 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
2315 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2318 * Range check input...
2322 return (IPP_TAG_ZERO
);
2325 * Return the group...
2328 return (attr
->group_tag
);
2333 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
2335 * The @code element@ parameter specifies which value to get from 0 to
2336 * @link ippGetCount(attr)@ - 1.
2338 * @since CUPS 1.6/OS X 10.8@
2341 int /* O - Value or -1 on error */
2342 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
2343 int element
) /* I - Value number (0-based) */
2346 * Range check input...
2349 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
2350 element
< 0 || element
>= attr
->num_values
)
2354 * Return the value...
2357 return (attr
->values
[element
].integer
);
2362 * 'ippGetName()' - Get the attribute name.
2364 * @since CUPS 1.6/OS X 10.8@
2367 const char * /* O - Attribute name or @code NULL@ for separators */
2368 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
2371 * Range check input...
2378 * Return the name...
2381 return (attr
->name
);
2386 * 'ippGetOperation()' - Get the operation ID in an IPP message.
2388 * @since CUPS 1.6/OS X 10.8@
2391 ipp_op_t
/* O - Operation ID or -1 on error */
2392 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
2395 * Range check input...
2399 return ((ipp_op_t
)-1);
2402 * Return the value...
2405 return (ipp
->request
.op
.operation_id
);
2410 * 'ippGetRange()' - Get a rangeOfInteger value from an attribute.
2412 * The @code element@ parameter specifies which value to get from 0 to
2413 * @link ippGetCount(attr)@ - 1.
2415 * @since CUPS 1.6/OS X 10.8@
2418 int /* O - Lower value of range or -1 */
2419 ippGetRange(ipp_attribute_t
*attr
, /* I - IPP attribute */
2420 int element
, /* I - Value number (0-based) */
2421 int *uppervalue
)/* O - Upper value of range */
2424 * Range check input...
2427 if (!attr
|| attr
->value_tag
!= IPP_TAG_RANGE
||
2428 element
< 0 || element
>= attr
->num_values
)
2437 * Return the values...
2441 *uppervalue
= attr
->values
[element
].range
.upper
;
2443 return (attr
->values
[element
].range
.lower
);
2448 * 'ippGetRequestId()' - Get the request ID from an IPP message.
2450 * @since CUPS 1.6/OS X 10.8@
2453 int /* O - Request ID or -1 on error */
2454 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
2457 * Range check input...
2464 * Return the request ID...
2467 return (ipp
->request
.any
.request_id
);
2472 * 'ippGetResolution()' - Get a resolution value for an attribute.
2474 * The @code element@ parameter specifies which value to get from 0 to
2475 * @link ippGetCount(attr)@ - 1.
2477 * @since CUPS 1.6/OS X 10.8@
2480 int /* O - Horizontal/cross feed resolution or -1 */
2482 ipp_attribute_t
*attr
, /* I - IPP attribute */
2483 int element
, /* I - Value number (0-based) */
2484 int *yres
, /* O - Vertical/feed resolution */
2485 ipp_res_t
*units
) /* O - Units for resolution */
2488 * Range check input...
2491 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
2492 element
< 0 || element
>= attr
->num_values
)
2496 * Return the value...
2500 *yres
= attr
->values
[element
].resolution
.yres
;
2503 *units
= attr
->values
[element
].resolution
.units
;
2505 return (attr
->values
[element
].resolution
.xres
);
2510 * 'ippGetState()' - Get the IPP message state.
2512 * @since CUPS 1.6/OS X 10.8@
2515 ipp_state_t
/* O - IPP message state value */
2516 ippGetState(ipp_t
*ipp
) /* I - IPP message */
2519 * Range check input...
2526 * Return the value...
2529 return (ipp
->state
);
2534 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2536 * @since CUPS 1.6/OS X 10.8@
2539 ipp_status_t
/* O - Status code in IPP message */
2540 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2543 * Range check input...
2547 return (IPP_INTERNAL_ERROR
);
2550 * Return the value...
2553 return (ipp
->request
.status
.status_code
);
2558 * 'ippGetString()' - Get the string and optionally the language code for an attribute.
2560 * The @code element@ parameter specifies which value to get from 0 to
2561 * @link ippGetCount(attr)@ - 1.
2563 * @since CUPS 1.6/OS X 10.8@
2567 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2568 int element
, /* I - Value number (0-based) */
2569 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2572 * Range check input...
2575 if (!attr
|| element
< 0 || element
>= attr
->num_values
||
2576 (attr
->value_tag
!= IPP_TAG_TEXTLANG
&& attr
->value_tag
!= IPP_TAG_NAMELANG
&&
2577 (attr
->value_tag
< IPP_TAG_TEXT
|| attr
->value_tag
> IPP_TAG_MIMETYPE
)))
2581 * Return the value...
2585 *language
= attr
->values
[element
].string
.language
;
2587 return (attr
->values
[element
].string
.text
);
2592 * 'ippGetValueTag()' - Get the value tag for an attribute.
2594 * @since CUPS 1.6/OS X 10.8@
2597 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2598 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2601 * Range check input...
2605 return (IPP_TAG_ZERO
);
2608 * Return the value...
2611 return (attr
->value_tag
& IPP_TAG_MASK
);
2616 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2618 * @since CUPS 1.6/OS X 10.8@
2621 int /* O - Major version number or -1 on error */
2622 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2623 int *minor
) /* O - Minor version number or @code NULL@ */
2626 * Range check input...
2638 * Return the value...
2642 *minor
= ipp
->request
.any
.version
[1];
2644 return (ipp
->request
.any
.version
[0]);
2649 * 'ippLength()' - Compute the length of an IPP message.
2652 size_t /* O - Size of IPP message */
2653 ippLength(ipp_t
*ipp
) /* I - IPP message */
2655 return (ipp_length(ipp
, 0));
2660 * 'ippNextAttribute()' - Return the next attribute in the message.
2662 * @since CUPS 1.6/OS X 10.8@
2665 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2666 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2669 * Range check input...
2672 if (!ipp
|| !ipp
->current
)
2676 * Return the next attribute...
2679 return (ipp
->current
= ipp
->current
->next
);
2684 * 'ippNew()' - Allocate a new IPP message.
2687 ipp_t
* /* O - New IPP message */
2690 ipp_t
*temp
; /* New IPP message */
2693 DEBUG_puts("ippNew()");
2695 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2698 * Default to IPP 2.0...
2701 temp
->request
.any
.version
[0] = 2;
2702 temp
->request
.any
.version
[1] = 0;
2706 DEBUG_printf(("1ippNew: Returning %p", temp
));
2713 * 'ippNewRequest()' - Allocate a new IPP request message.
2715 * The new request message is initialized with the attributes-charset and
2716 * attributes-natural-language attributes added. The
2717 * attributes-natural-language value is derived from the current locale.
2719 * @since CUPS 1.2/OS X 10.5@
2722 ipp_t
* /* O - IPP request message */
2723 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2725 ipp_t
*request
; /* IPP request message */
2726 cups_lang_t
*language
; /* Current language localization */
2727 static int request_id
= 0; /* Current request ID */
2728 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2729 /* Mutex for request ID */
2732 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2735 * Create a new IPP message...
2738 if ((request
= ippNew()) == NULL
)
2742 * Set the operation and request ID...
2745 _cupsMutexLock(&request_mutex
);
2747 request
->request
.op
.operation_id
= op
;
2748 request
->request
.op
.request_id
= ++request_id
;
2750 _cupsMutexUnlock(&request_mutex
);
2753 * Use UTF-8 as the character set...
2756 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2757 "attributes-charset", NULL
, "utf-8");
2760 * Get the language from the current locale...
2763 language
= cupsLangDefault();
2765 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2766 "attributes-natural-language", NULL
, language
->language
);
2769 * Return the new request...
2777 * 'ippNewResponse()' - Allocate a new IPP response message.
2779 * The new response message is initialized with the same version-number,
2780 * request-id, attributes-charset, and attributes-natural-language as the
2781 * provided request message. If the attributes-charset or
2782 * attributes-natural-language attributes are missing from the request,
2783 * "utf-8" and a value derived from the current locale are substituted,
2789 ipp_t
* /* O - IPP response message */
2790 ippNewResponse(ipp_t
*request
) /* I - IPP request message */
2792 ipp_t
*response
; /* IPP response message */
2793 ipp_attribute_t
*attr
; /* Current attribute */
2797 * Range check input...
2804 * Create a new IPP message...
2807 if ((response
= ippNew()) == NULL
)
2811 * Copy the request values over to the response...
2814 response
->request
.status
.version
[0] = request
->request
.op
.version
[0];
2815 response
->request
.status
.version
[1] = request
->request
.op
.version
[1];
2816 response
->request
.status
.request_id
= request
->request
.op
.request_id
;
2819 * The first attribute MUST be attributes-charset...
2822 attr
= request
->attrs
;
2824 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") &&
2825 attr
->group_tag
== IPP_TAG_OPERATION
&&
2826 attr
->value_tag
== IPP_TAG_CHARSET
&&
2827 attr
->num_values
== 1)
2830 * Copy charset from request...
2833 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2834 "attributes-charset", NULL
, attr
->values
[0].string
.text
);
2839 * Use "utf-8" as the default...
2842 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2843 "attributes-charset", NULL
, "utf-8");
2847 * Then attributes-natural-language...
2853 if (attr
&& attr
->name
&&
2854 !strcmp(attr
->name
, "attributes-natural-language") &&
2855 attr
->group_tag
== IPP_TAG_OPERATION
&&
2856 attr
->value_tag
== IPP_TAG_LANGUAGE
&&
2857 attr
->num_values
== 1)
2860 * Copy language from request...
2863 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2864 "attributes-natural-language", NULL
,
2865 attr
->values
[0].string
.text
);
2870 * Use the language from the current locale...
2873 cups_lang_t
*language
= cupsLangDefault();
2874 /* Current locale */
2876 ippAddString(response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2877 "attributes-natural-language", NULL
, language
->language
);
2885 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2888 ipp_state_t
/* O - Current state */
2889 ippRead(http_t
*http
, /* I - HTTP connection */
2890 ipp_t
*ipp
) /* I - IPP data */
2892 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
,
2893 http
, ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2898 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
,
2901 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2907 * 'ippReadFile()' - Read data for an IPP message from a file.
2909 * @since CUPS 1.1.19/OS X 10.3@
2912 ipp_state_t
/* O - Current state */
2913 ippReadFile(int fd
, /* I - HTTP data */
2914 ipp_t
*ipp
) /* I - IPP data */
2916 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, ipp
));
2918 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2923 * 'ippReadIO()' - Read data for an IPP message.
2925 * @since CUPS 1.2/OS X 10.5@
2928 ipp_state_t
/* O - Current state */
2929 ippReadIO(void *src
, /* I - Data source */
2930 ipp_iocb_t cb
, /* I - Read callback function */
2931 int blocking
, /* I - Use blocking IO? */
2932 ipp_t
*parent
, /* I - Parent request, if any */
2933 ipp_t
*ipp
) /* I - IPP data */
2935 int n
; /* Length of data */
2936 unsigned char *buffer
, /* Data buffer */
2937 string
[IPP_MAX_TEXT
],
2938 /* Small string buffer */
2939 *bufptr
; /* Pointer into buffer */
2940 ipp_attribute_t
*attr
; /* Current attribute */
2941 ipp_tag_t tag
; /* Current tag */
2942 ipp_tag_t value_tag
; /* Current value tag */
2943 _ipp_value_t
*value
; /* Current value */
2946 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)",
2947 src
, cb
, blocking
, parent
, ipp
));
2948 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
? ipp
->state
: IPP_ERROR
));
2953 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
2955 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2962 ipp
->state
++; /* Avoid common problem... */
2968 * Get the request header...
2971 if ((*cb
)(src
, buffer
, 8) < 8)
2973 DEBUG_puts("1ippReadIO: Unable to read header.");
2974 _cupsBufferRelease((char *)buffer
);
2979 * Then copy the request header over...
2982 ipp
->request
.any
.version
[0] = buffer
[0];
2983 ipp
->request
.any
.version
[1] = buffer
[1];
2984 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
2985 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
2986 buffer
[6]) << 8) | buffer
[7];
2988 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
2989 DEBUG_printf(("2ippReadIO: op_status=%04x",
2990 ipp
->request
.any
.op_status
));
2991 DEBUG_printf(("2ippReadIO: request_id=%d",
2992 ipp
->request
.any
.request_id
));
2995 ipp
->state
= IPP_ATTRIBUTE
;
2996 ipp
->current
= NULL
;
2997 ipp
->curtag
= IPP_TAG_ZERO
;
2998 ipp
->prev
= ipp
->last
;
3001 * If blocking is disabled, stop here...
3007 case IPP_ATTRIBUTE
:
3010 if ((*cb
)(src
, buffer
, 1) < 1)
3012 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3013 _cupsBufferRelease((char *)buffer
);
3017 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p",
3018 ipp
->current
, ipp
->prev
));
3021 * Read this attribute...
3024 tag
= (ipp_tag_t
)buffer
[0];
3025 if (tag
== IPP_TAG_EXTENSION
)
3028 * Read 32-bit "extension" tag...
3031 if ((*cb
)(src
, buffer
, 4) < 1)
3033 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
3034 _cupsBufferRelease((char *)buffer
);
3038 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
3039 buffer
[2]) << 8) | buffer
[3]);
3041 if (tag
& IPP_TAG_COPY
)
3044 * Fail if the high bit is set in the tag...
3047 _cupsSetError(IPP_INTERNAL_ERROR
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
3048 DEBUG_printf(("1ippReadIO: bad tag 0x%x.", tag
));
3049 _cupsBufferRelease((char *)buffer
);
3054 if (tag
== IPP_TAG_END
)
3057 * No more attributes left...
3060 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
3062 ipp
->state
= IPP_DATA
;
3065 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
3068 * Group tag... Set the current group and continue...
3071 if (ipp
->curtag
== tag
)
3072 ipp
->prev
= ippAddSeparator(ipp
);
3073 else if (ipp
->current
)
3074 ipp
->prev
= ipp
->current
;
3077 ipp
->current
= NULL
;
3078 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
,
3079 ippTagString(tag
), ipp
->prev
));
3083 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
3084 ippTagString(tag
)));
3090 if ((*cb
)(src
, buffer
, 2) < 2)
3092 DEBUG_puts("1ippReadIO: unable to read name length.");
3093 _cupsBufferRelease((char *)buffer
);
3097 n
= (buffer
[0] << 8) | buffer
[1];
3099 if (n
>= IPP_BUF_SIZE
)
3101 _cupsSetError(IPP_INTERNAL_ERROR
, _("IPP name larger than 32767 bytes."), 1);
3102 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
3103 _cupsBufferRelease((char *)buffer
);
3107 DEBUG_printf(("2ippReadIO: name length=%d", n
));
3109 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
3110 tag
!= IPP_TAG_END_COLLECTION
)
3113 * More values for current attribute...
3116 if (ipp
->current
== NULL
)
3118 _cupsSetError(IPP_INTERNAL_ERROR
, _("IPP attribute has no name."), 1);
3119 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
3120 _cupsBufferRelease((char *)buffer
);
3124 attr
= ipp
->current
;
3125 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_MASK
);
3128 * Make sure we aren't adding a new value of a different
3132 if (value_tag
== IPP_TAG_ZERO
)
3135 * Setting the value of a collection member...
3138 attr
->value_tag
= tag
;
3140 else if (value_tag
== IPP_TAG_TEXTLANG
||
3141 value_tag
== IPP_TAG_NAMELANG
||
3142 (value_tag
>= IPP_TAG_TEXT
&&
3143 value_tag
<= IPP_TAG_MIMETYPE
))
3146 * String values can sometimes come across in different
3147 * forms; accept sets of differing values...
3150 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
3151 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
3152 tag
!= IPP_TAG_NOVALUE
)
3154 _cupsSetError(IPP_INTERNAL_ERROR
,
3155 _("IPP 1setOf attribute with incompatible value "
3157 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3158 value_tag
, ippTagString(value_tag
), tag
,
3159 ippTagString(tag
)));
3160 _cupsBufferRelease((char *)buffer
);
3164 if (value_tag
!= tag
)
3166 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
3167 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
3168 ippSetValueTag(ipp
, &attr
, tag
);
3171 else if (value_tag
== IPP_TAG_INTEGER
||
3172 value_tag
== IPP_TAG_RANGE
)
3175 * Integer and rangeOfInteger values can sometimes be mixed; accept
3176 * sets of differing values...
3179 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
3181 _cupsSetError(IPP_INTERNAL_ERROR
,
3182 _("IPP 1setOf attribute with incompatible value "
3184 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
3185 value_tag
, ippTagString(value_tag
), tag
,
3186 ippTagString(tag
)));
3187 _cupsBufferRelease((char *)buffer
);
3191 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
3194 * Convert integer values to rangeOfInteger values...
3197 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
3198 "rangeOfInteger.", attr
->name
));
3199 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
3202 else if (value_tag
!= tag
)
3204 _cupsSetError(IPP_INTERNAL_ERROR
,
3205 _("IPP 1setOf attribute with incompatible value "
3207 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
3208 value_tag
, ippTagString(value_tag
), tag
,
3209 ippTagString(tag
)));
3210 _cupsBufferRelease((char *)buffer
);
3215 * Finally, reallocate the attribute array as needed...
3218 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
3220 _cupsBufferRelease((char *)buffer
);
3224 else if (tag
== IPP_TAG_MEMBERNAME
)
3227 * Name must be length 0!
3232 _cupsSetError(IPP_INTERNAL_ERROR
, _("IPP member name is not empty."), 1);
3233 DEBUG_puts("1ippReadIO: member name not empty.");
3234 _cupsBufferRelease((char *)buffer
);
3239 ipp
->prev
= ipp
->current
;
3241 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
3244 _cupsSetHTTPError(HTTP_ERROR
);
3245 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3246 _cupsBufferRelease((char *)buffer
);
3250 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p",
3251 ipp
->current
, ipp
->prev
));
3253 value
= attr
->values
;
3255 else if (tag
!= IPP_TAG_END_COLLECTION
)
3258 * New attribute; read the name and add it...
3261 if ((*cb
)(src
, buffer
, n
) < n
)
3263 DEBUG_puts("1ippReadIO: unable to read name.");
3264 _cupsBufferRelease((char *)buffer
);
3271 ipp
->prev
= ipp
->current
;
3273 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
3276 _cupsSetHTTPError(HTTP_ERROR
);
3277 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
3278 _cupsBufferRelease((char *)buffer
);
3282 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, "
3283 "ipp->prev=%p", buffer
, ipp
->current
, ipp
->prev
));
3285 value
= attr
->values
;
3293 if ((*cb
)(src
, buffer
, 2) < 2)
3295 DEBUG_puts("1ippReadIO: unable to read value length.");
3296 _cupsBufferRelease((char *)buffer
);
3300 n
= (buffer
[0] << 8) | buffer
[1];
3301 DEBUG_printf(("2ippReadIO: value length=%d", n
));
3303 if (n
>= IPP_BUF_SIZE
)
3305 _cupsSetError(IPP_INTERNAL_ERROR
,
3306 _("IPP value larger than 32767 bytes."), 1);
3307 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
3308 _cupsBufferRelease((char *)buffer
);
3314 case IPP_TAG_INTEGER
:
3318 if (tag
== IPP_TAG_INTEGER
)
3319 _cupsSetError(IPP_INTERNAL_ERROR
,
3320 _("IPP integer value not 4 bytes."), 1);
3322 _cupsSetError(IPP_INTERNAL_ERROR
,
3323 _("IPP enum value not 4 bytes."), 1);
3324 DEBUG_printf(("1ippReadIO: bad integer value length %d.", n
));
3325 _cupsBufferRelease((char *)buffer
);
3329 if ((*cb
)(src
, buffer
, 4) < 4)
3331 DEBUG_puts("1ippReadIO: Unable to read integer value.");
3332 _cupsBufferRelease((char *)buffer
);
3336 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3339 if (attr
->value_tag
== IPP_TAG_RANGE
)
3340 value
->range
.lower
= value
->range
.upper
= n
;
3345 case IPP_TAG_BOOLEAN
:
3348 _cupsSetError(IPP_INTERNAL_ERROR
, _("IPP boolean value not 1 byte."),
3350 DEBUG_printf(("1ippReadIO: bad boolean value length %d.", n
));
3351 _cupsBufferRelease((char *)buffer
);
3355 if ((*cb
)(src
, buffer
, 1) < 1)
3357 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
3358 _cupsBufferRelease((char *)buffer
);
3362 value
->boolean
= buffer
[0];
3365 case IPP_TAG_NOVALUE
:
3366 case IPP_TAG_NOTSETTABLE
:
3367 case IPP_TAG_DELETEATTR
:
3368 case IPP_TAG_ADMINDEFINE
:
3370 * These value types are not supposed to have values, however
3371 * some vendors (Brother) do not implement IPP correctly and so
3372 * we need to map non-empty values to text...
3375 if (attr
->value_tag
== tag
)
3380 attr
->value_tag
= IPP_TAG_TEXT
;
3385 case IPP_TAG_KEYWORD
:
3387 case IPP_TAG_URISCHEME
:
3388 case IPP_TAG_CHARSET
:
3389 case IPP_TAG_LANGUAGE
:
3390 case IPP_TAG_MIMETYPE
:
3393 if ((*cb
)(src
, buffer
, n
) < n
)
3395 DEBUG_puts("1ippReadIO: unable to read string value.");
3396 _cupsBufferRelease((char *)buffer
);
3402 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
3403 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
3409 _cupsSetError(IPP_INTERNAL_ERROR
, _("IPP date value not 11 bytes."), 1);
3410 DEBUG_printf(("1ippReadIO: bad date value length %d.", n
));
3411 _cupsBufferRelease((char *)buffer
);
3415 if ((*cb
)(src
, value
->date
, 11) < 11)
3417 DEBUG_puts("1ippReadIO: Unable to read date value.");
3418 _cupsBufferRelease((char *)buffer
);
3423 case IPP_TAG_RESOLUTION
:
3426 _cupsSetError(IPP_INTERNAL_ERROR
,
3427 _("IPP resolution value not 9 bytes."), 1);
3428 DEBUG_printf(("1ippReadIO: bad resolution value length %d.", n
));
3429 _cupsBufferRelease((char *)buffer
);
3433 if ((*cb
)(src
, buffer
, 9) < 9)
3435 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
3436 _cupsBufferRelease((char *)buffer
);
3440 value
->resolution
.xres
=
3441 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3443 value
->resolution
.yres
=
3444 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3446 value
->resolution
.units
=
3447 (ipp_res_t
)buffer
[8];
3450 case IPP_TAG_RANGE
:
3453 _cupsSetError(IPP_INTERNAL_ERROR
,
3454 _("IPP rangeOfInteger value not 8 bytes."), 1);
3455 DEBUG_printf(("1ippReadIO: bad rangeOfInteger value length "
3457 _cupsBufferRelease((char *)buffer
);
3461 if ((*cb
)(src
, buffer
, 8) < 8)
3463 DEBUG_puts("1ippReadIO: Unable to read range value.");
3464 _cupsBufferRelease((char *)buffer
);
3468 value
->range
.lower
=
3469 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
3471 value
->range
.upper
=
3472 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
3476 case IPP_TAG_TEXTLANG
:
3477 case IPP_TAG_NAMELANG
:
3480 if (tag
== IPP_TAG_TEXTLANG
)
3481 _cupsSetError(IPP_INTERNAL_ERROR
,
3482 _("IPP textWithLanguage value less than "
3483 "minimum 4 bytes."), 1);
3485 _cupsSetError(IPP_INTERNAL_ERROR
,
3486 _("IPP nameWithLanguage value less than "
3487 "minimum 4 bytes."), 1);
3488 DEBUG_printf(("1ippReadIO: bad stringWithLanguage value "
3490 _cupsBufferRelease((char *)buffer
);
3494 if ((*cb
)(src
, buffer
, n
) < n
)
3496 DEBUG_puts("1ippReadIO: Unable to read string w/language "
3498 _cupsBufferRelease((char *)buffer
);
3505 * text-with-language and name-with-language are composite
3514 n
= (bufptr
[0] << 8) | bufptr
[1];
3516 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) ||
3517 n
>= sizeof(string
))
3519 _cupsSetError(IPP_INTERNAL_ERROR
,
3520 _("IPP language length overflows value."), 1);
3521 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3523 _cupsBufferRelease((char *)buffer
);
3526 else if (n
>= IPP_MAX_LANGUAGE
)
3528 _cupsSetError(IPP_INTERNAL_ERROR
,
3529 _("IPP language length too large."), 1);
3530 DEBUG_printf(("1ippReadIO: bad language value length %d.",
3532 _cupsBufferRelease((char *)buffer
);
3536 memcpy(string
, bufptr
+ 2, n
);
3539 value
->string
.language
= _cupsStrAlloc((char *)string
);
3542 n
= (bufptr
[0] << 8) | bufptr
[1];
3544 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
3546 _cupsSetError(IPP_INTERNAL_ERROR
,
3547 _("IPP string length overflows value."), 1);
3548 DEBUG_printf(("1ippReadIO: bad string value length %d.", n
));
3549 _cupsBufferRelease((char *)buffer
);
3553 bufptr
[2 + n
] = '\0';
3554 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
3557 case IPP_TAG_BEGIN_COLLECTION
:
3559 * Oh, boy, here comes a collection value, so read it...
3562 value
->collection
= ippNew();
3566 _cupsSetError(IPP_INTERNAL_ERROR
,
3567 _("IPP begCollection value not 0 bytes."), 1);
3568 DEBUG_puts("1ippReadIO: begCollection tag with value length "
3570 _cupsBufferRelease((char *)buffer
);
3574 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_ERROR
)
3576 DEBUG_puts("1ippReadIO: Unable to read collection value.");
3577 _cupsBufferRelease((char *)buffer
);
3582 case IPP_TAG_END_COLLECTION
:
3583 _cupsBufferRelease((char *)buffer
);
3587 _cupsSetError(IPP_INTERNAL_ERROR
,
3588 _("IPP endCollection value not 0 bytes."), 1);
3589 DEBUG_puts("1ippReadIO: endCollection tag with value length "
3594 DEBUG_puts("1ippReadIO: endCollection tag...");
3595 return (ipp
->state
= IPP_DATA
);
3597 case IPP_TAG_MEMBERNAME
:
3599 * The value the name of the member in the collection, which
3600 * we need to carry over...
3605 _cupsSetError(IPP_INTERNAL_ERROR
,
3606 _("IPP memberName with no attribute."), 1);
3607 DEBUG_puts("1ippReadIO: Member name without attribute.");
3608 _cupsBufferRelease((char *)buffer
);
3613 _cupsSetError(IPP_INTERNAL_ERROR
,
3614 _("IPP memberName value is empty."), 1);
3615 DEBUG_puts("1ippReadIO: Empty member name value.");
3616 _cupsBufferRelease((char *)buffer
);
3619 else if ((*cb
)(src
, buffer
, n
) < n
)
3621 DEBUG_puts("1ippReadIO: Unable to read member name value.");
3622 _cupsBufferRelease((char *)buffer
);
3627 attr
->name
= _cupsStrAlloc((char *)buffer
);
3630 * Since collection members are encoded differently than
3631 * regular attributes, make sure we don't start with an
3635 attr
->num_values
--;
3637 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
3640 default : /* Other unsupported values */
3641 if (tag
== IPP_TAG_STRING
&& n
> IPP_MAX_LENGTH
)
3643 _cupsSetError(IPP_INTERNAL_ERROR
,
3644 _("IPP octetString length too large."), 1);
3645 DEBUG_printf(("1ippReadIO: bad octetString value length %d.",
3647 _cupsBufferRelease((char *)buffer
);
3651 value
->unknown
.length
= n
;
3655 if ((value
->unknown
.data
= malloc(n
)) == NULL
)
3657 _cupsSetHTTPError(HTTP_ERROR
);
3658 DEBUG_puts("1ippReadIO: Unable to allocate value");
3659 _cupsBufferRelease((char *)buffer
);
3663 if ((*cb
)(src
, value
->unknown
.data
, n
) < n
)
3665 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
3666 _cupsBufferRelease((char *)buffer
);
3671 value
->unknown
.data
= NULL
;
3676 * If blocking is disabled, stop here...
3688 break; /* anti-compiler-warning-code */
3691 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3692 _cupsBufferRelease((char *)buffer
);
3694 return (ipp
->state
);
3699 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3701 * The @code ipp@ parameter refers to an IPP message previously created using
3702 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3704 * The @code attr@ parameter may be modified as a result of setting the value.
3706 * The @code element@ parameter specifies which value to set from 0 to
3707 * @link ippGetCount(attr)@.
3709 * @since CUPS 1.6/OS X 10.8@
3712 int /* O - 1 on success, 0 on failure */
3713 ippSetBoolean(ipp_t
*ipp
, /* IO - IPP message */
3714 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3715 int element
, /* I - Value number (0-based) */
3716 int boolvalue
)/* I - Boolean value */
3718 _ipp_value_t
*value
; /* Current value */
3722 * Range check input...
3725 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3726 element
< 0 || element
> (*attr
)->num_values
)
3730 * Set the value and return...
3733 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3734 value
->boolean
= boolvalue
;
3736 return (value
!= NULL
);
3741 * 'ippSetCollection()' - Set a collection value in an attribute.
3743 * The @code ipp@ parameter refers to an IPP message previously created using
3744 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3746 * The @code attr@ parameter may be modified as a result of setting the value.
3748 * The @code element@ parameter specifies which value to set from 0 to
3749 * @link ippGetCount(attr)@.
3751 * @since CUPS 1.6/OS X 10.8@
3754 int /* O - 1 on success, 0 on failure */
3756 ipp_t
*ipp
, /* IO - IPP message */
3757 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3758 int element
, /* I - Value number (0-based) */
3759 ipp_t
*colvalue
) /* I - Collection value */
3761 _ipp_value_t
*value
; /* Current value */
3765 * Range check input...
3768 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3769 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3773 * Set the value and return...
3776 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3778 if (value
->collection
)
3779 ippDelete(value
->collection
);
3781 value
->collection
= colvalue
;
3785 return (value
!= NULL
);
3790 * 'ippSetDate()' - Set a date value in an attribute.
3792 * The @code ipp@ parameter refers to an IPP message previously created using
3793 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3795 * The @code attr@ parameter may be modified as a result of setting the value.
3797 * The @code element@ parameter specifies which value to set from 0 to
3798 * @link ippGetCount(attr)@.
3800 * @since CUPS 1.6/OS X 10.8@
3803 int /* O - 1 on success, 0 on failure */
3804 ippSetDate(ipp_t
*ipp
, /* IO - IPP message */
3805 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3806 int element
, /* I - Value number (0-based) */
3807 const ipp_uchar_t
*datevalue
)/* I - Date value */
3809 _ipp_value_t
*value
; /* Current value */
3813 * Range check input...
3816 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_DATE
||
3817 element
< 0 || element
> (*attr
)->num_values
|| !datevalue
)
3821 * Set the value and return...
3824 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3825 memcpy(value
->date
, datevalue
, sizeof(value
->date
));
3827 return (value
!= NULL
);
3832 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3834 * The @code ipp@ parameter refers to an IPP message previously created using
3835 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3837 * The @code attr@ parameter may be modified as a result of setting the value.
3839 * The @code group@ parameter specifies the IPP attribute group tag: none
3840 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3841 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3842 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3843 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3845 * @since CUPS 1.6/OS X 10.8@
3848 int /* O - 1 on success, 0 on failure */
3850 ipp_t
*ipp
, /* IO - IPP message */
3851 ipp_attribute_t
**attr
, /* IO - Attribute */
3852 ipp_tag_t group_tag
) /* I - Group tag */
3855 * Range check input - group tag must be 0x01 to 0x0F, per RFC 2911...
3858 if (!ipp
|| !attr
|| !*attr
||
3859 group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3860 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3864 * Set the group tag and return...
3867 (*attr
)->group_tag
= group_tag
;
3874 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3876 * The @code ipp@ parameter refers to an IPP message previously created using
3877 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3879 * The @code attr@ parameter may be modified as a result of setting the value.
3881 * The @code element@ parameter specifies which value to set from 0 to
3882 * @link ippGetCount(attr)@.
3884 * @since CUPS 1.6/OS X 10.8@
3887 int /* O - 1 on success, 0 on failure */
3888 ippSetInteger(ipp_t
*ipp
, /* IO - IPP message */
3889 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3890 int element
, /* I - Value number (0-based) */
3891 int intvalue
) /* I - Integer/enum value */
3893 _ipp_value_t
*value
; /* Current value */
3897 * Range check input...
3900 if (!ipp
|| !attr
|| !*attr
||
3901 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3902 element
< 0 || element
> (*attr
)->num_values
)
3906 * Set the value and return...
3909 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3910 value
->integer
= intvalue
;
3912 return (value
!= NULL
);
3917 * 'ippSetName()' - Set the name of 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 * @since CUPS 1.6/OS X 10.8@
3927 int /* O - 1 on success, 0 on failure */
3928 ippSetName(ipp_t
*ipp
, /* IO - IPP message */
3929 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3930 const char *name
) /* I - Attribute name */
3932 char *temp
; /* Temporary name value */
3936 * Range check input...
3939 if (!ipp
|| !attr
|| !*attr
)
3943 * Set the value and return...
3946 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3949 _cupsStrFree((*attr
)->name
);
3951 (*attr
)->name
= temp
;
3954 return (temp
!= NULL
);
3959 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
3961 * The @code ipp@ parameter refers to an IPP message previously created using
3962 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3964 * @since CUPS 1.6/OS X 10.8@
3967 int /* O - 1 on success, 0 on failure */
3968 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
3969 ipp_op_t op
) /* I - Operation ID */
3972 * Range check input...
3979 * Set the operation and return...
3982 ipp
->request
.op
.operation_id
= op
;
3989 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
3991 * The @code ipp@ parameter refers to an IPP message previously created using
3992 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
3994 * The @code attr@ parameter may be modified as a result of setting the value.
3996 * The @code element@ parameter specifies which value to set from 0 to
3997 * @link ippGetCount(attr)@.
3999 * @since CUPS 1.6/OS X 10.8@
4002 int /* O - 1 on success, 0 on failure */
4003 ippSetRange(ipp_t
*ipp
, /* IO - IPP message */
4004 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4005 int element
, /* I - Value number (0-based) */
4006 int lowervalue
, /* I - Lower bound for range */
4007 int uppervalue
) /* I - Upper bound for range */
4009 _ipp_value_t
*value
; /* Current value */
4013 * Range check input...
4016 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
4017 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
4021 * Set the value and return...
4024 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4026 value
->range
.lower
= lowervalue
;
4027 value
->range
.upper
= uppervalue
;
4030 return (value
!= NULL
);
4035 * 'ippSetRequestId()' - Set the request ID in an IPP message.
4037 * The @code ipp@ parameter refers to an IPP message previously created using
4038 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4040 * The @code request_id@ parameter must be greater than 0.
4042 * @since CUPS 1.6/OS X 10.8@
4045 int /* O - 1 on success, 0 on failure */
4046 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
4047 int request_id
) /* I - Request ID */
4050 * Range check input; not checking request_id values since ipptool wants to send
4051 * invalid values for conformance testing and a bad request_id does not affect the
4052 * encoding of a message...
4059 * Set the request ID and return...
4062 ipp
->request
.any
.request_id
= request_id
;
4069 * 'ippSetResolution()' - Set a resolution value in an attribute.
4071 * The @code ipp@ parameter refers to an IPP message previously created using
4072 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4074 * The @code attr@ parameter may be modified as a result of setting the value.
4076 * The @code element@ parameter specifies which value to set from 0 to
4077 * @link ippGetCount(attr)@.
4079 * @since CUPS 1.6/OS X 10.8@
4082 int /* O - 1 on success, 0 on failure */
4084 ipp_t
*ipp
, /* IO - IPP message */
4085 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4086 int element
, /* I - Value number (0-based) */
4087 ipp_res_t unitsvalue
, /* I - Resolution units */
4088 int xresvalue
, /* I - Horizontal/cross feed resolution */
4089 int yresvalue
) /* I - Vertical/feed resolution */
4091 _ipp_value_t
*value
; /* Current value */
4095 * Range check input...
4098 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
4099 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
4100 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
4104 * Set the value and return...
4107 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4109 value
->resolution
.units
= unitsvalue
;
4110 value
->resolution
.xres
= xresvalue
;
4111 value
->resolution
.yres
= yresvalue
;
4114 return (value
!= NULL
);
4119 * 'ippSetState()' - Set the current state of the IPP message.
4121 * @since CUPS 1.6/OS X 10.8@
4124 int /* O - 1 on success, 0 on failure */
4125 ippSetState(ipp_t
*ipp
, /* I - IPP message */
4126 ipp_state_t state
) /* I - IPP state value */
4129 * Range check input...
4136 * Set the state and return...
4140 ipp
->current
= NULL
;
4147 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
4149 * The @code ipp@ parameter refers to an IPP message previously created using
4150 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4152 * @since CUPS 1.6/OS X 10.8@
4155 int /* O - 1 on success, 0 on failure */
4156 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
4157 ipp_status_t status
) /* I - Status code */
4160 * Range check input...
4167 * Set the status code and return...
4170 ipp
->request
.status
.status_code
= status
;
4177 * 'ippSetString()' - Set a string value in an attribute.
4179 * The @code ipp@ parameter refers to an IPP message previously created using
4180 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4182 * The @code attr@ parameter may be modified as a result of setting the value.
4184 * The @code element@ parameter specifies which value to set from 0 to
4185 * @link ippGetCount(attr)@.
4187 * @since CUPS 1.6/OS X 10.8@
4190 int /* O - 1 on success, 0 on failure */
4191 ippSetString(ipp_t
*ipp
, /* IO - IPP message */
4192 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4193 int element
, /* I - Value number (0-based) */
4194 const char *strvalue
) /* I - String value */
4196 char *temp
; /* Temporary string */
4197 _ipp_value_t
*value
; /* Current value */
4201 * Range check input...
4204 if (!ipp
|| !attr
|| !*attr
||
4205 ((*attr
)->value_tag
!= IPP_TAG_TEXTLANG
&&
4206 (*attr
)->value_tag
!= IPP_TAG_NAMELANG
&&
4207 ((*attr
)->value_tag
< IPP_TAG_TEXT
||
4208 (*attr
)->value_tag
> IPP_TAG_MIMETYPE
)) ||
4209 element
< 0 || element
> (*attr
)->num_values
|| !strvalue
)
4213 * Set the value and return...
4216 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
4219 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4221 if ((int)((*attr
)->value_tag
) & IPP_TAG_COPY
)
4222 value
->string
.text
= (char *)strvalue
;
4223 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
4225 if (value
->string
.text
)
4226 _cupsStrFree(value
->string
.text
);
4228 value
->string
.text
= temp
;
4234 return (value
!= NULL
);
4239 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4241 * The @code ipp@ parameter refers to an IPP message previously created using
4242 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4244 * The @code attr@ parameter may be modified as a result of setting the value.
4246 * The @code element@ parameter specifies which value to set from 0 to
4247 * @link ippGetCount(attr)@.
4249 * The @code format@ parameter uses formatting characters compatible with the
4250 * printf family of standard functions. Additional arguments follow it as
4251 * needed. The formatted string is truncated as needed to the maximum length of
4252 * the corresponding value type.
4257 int /* O - 1 on success, 0 on failure */
4258 ippSetStringf(ipp_t
*ipp
, /* IO - IPP message */
4259 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4260 int element
, /* I - Value number (0-based) */
4261 const char *format
, /* I - Printf-style format string */
4262 ...) /* I - Additional arguments as needed */
4264 int ret
; /* Return value */
4265 va_list ap
; /* Pointer to additional arguments */
4268 va_start(ap
, format
);
4269 ret
= ippSetStringfv(ipp
, attr
, element
, format
, ap
);
4277 * 'ippSetStringf()' - Set a formatted string value of an attribute.
4279 * The @code ipp@ parameter refers to an IPP message previously created using
4280 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4282 * The @code attr@ parameter may be modified as a result of setting the value.
4284 * The @code element@ parameter specifies which value to set from 0 to
4285 * @link ippGetCount(attr)@.
4287 * The @code format@ parameter uses formatting characters compatible with the
4288 * printf family of standard functions. Additional arguments follow it as
4289 * needed. The formatted string is truncated as needed to the maximum length of
4290 * the corresponding value type.
4295 int /* O - 1 on success, 0 on failure */
4296 ippSetStringfv(ipp_t
*ipp
, /* IO - IPP message */
4297 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4298 int element
, /* I - Value number (0-based) */
4299 const char *format
, /* I - Printf-style format string */
4300 va_list ap
) /* I - Pointer to additional arguments */
4302 ipp_tag_t value_tag
; /* Value tag */
4303 char buffer
[IPP_MAX_TEXT
+ 4];
4304 /* Formatted text string */
4305 ssize_t bytes
, /* Length of formatted value */
4306 max_bytes
; /* Maximum number of bytes for value */
4310 * Range check input...
4314 value_tag
= (*attr
)->value_tag
& IPP_TAG_CUPS_MASK
;
4316 value_tag
= IPP_TAG_ZERO
;
4318 if (!ipp
|| !attr
|| !*attr
||
4319 (value_tag
< IPP_TAG_TEXT
&& value_tag
!= IPP_TAG_TEXTLANG
&&
4320 value_tag
!= IPP_TAG_NAMELANG
) || value_tag
> IPP_TAG_MIMETYPE
||
4325 * Format the string...
4328 if (!strcmp(format
, "%s"))
4331 * Optimize the simple case...
4334 const char *s
= va_arg(ap
, char *);
4340 strlcpy(buffer
, s
, sizeof(buffer
));
4345 * Do a full formatting of the message...
4348 if ((bytes
= vsnprintf(buffer
, sizeof(buffer
), format
, ap
)) < 0)
4353 * Limit the length of the string...
4360 case IPP_TAG_TEXTLANG
:
4361 max_bytes
= IPP_MAX_TEXT
;
4365 case IPP_TAG_NAMELANG
:
4366 max_bytes
= IPP_MAX_NAME
;
4369 case IPP_TAG_CHARSET
:
4370 max_bytes
= IPP_MAX_CHARSET
;
4373 case IPP_TAG_KEYWORD
:
4374 max_bytes
= IPP_MAX_KEYWORD
;
4377 case IPP_TAG_LANGUAGE
:
4378 max_bytes
= IPP_MAX_LANGUAGE
;
4381 case IPP_TAG_MIMETYPE
:
4382 max_bytes
= IPP_MAX_MIMETYPE
;
4386 max_bytes
= IPP_MAX_URI
;
4389 case IPP_TAG_URISCHEME
:
4390 max_bytes
= IPP_MAX_URISCHEME
;
4394 if (bytes
>= max_bytes
)
4396 char *bufmax
, /* Buffer at max_bytes */
4397 *bufptr
; /* Pointer into buffer */
4399 bufptr
= buffer
+ strlen(buffer
) - 1;
4400 bufmax
= buffer
+ max_bytes
- 1;
4402 while (bufptr
> bufmax
)
4406 while ((*bufptr
& 0xc0) == 0x80 && bufptr
> buffer
)
4417 * Set the formatted string and return...
4420 return (ippSetString(ipp
, attr
, element
, buffer
));
4425 * 'ippSetValueTag()' - Set the value tag of an attribute.
4427 * The @code ipp@ parameter refers to an IPP message previously created using
4428 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4430 * The @code attr@ parameter may be modified as a result of setting the value.
4432 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
4433 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
4434 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
4435 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
4436 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
4437 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
4440 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
4441 * code in the "attributes-natural-language" attribute or, if not present, the language
4442 * code for the current locale.
4444 * @since CUPS 1.6/OS X 10.8@
4447 int /* O - 1 on success, 0 on failure */
4449 ipp_t
*ipp
, /* IO - IPP message */
4450 ipp_attribute_t
**attr
, /* IO - IPP attribute */
4451 ipp_tag_t value_tag
) /* I - Value tag */
4453 int i
; /* Looping var */
4454 _ipp_value_t
*value
; /* Current value */
4455 int integer
; /* Current integer value */
4456 cups_lang_t
*language
; /* Current language */
4457 char code
[32]; /* Language code */
4458 ipp_tag_t temp_tag
; /* Temporary value tag */
4462 * Range check input...
4465 if (!ipp
|| !attr
|| !*attr
)
4469 * If there is no change, return immediately...
4472 if (value_tag
== (*attr
)->value_tag
)
4476 * Otherwise implement changes as needed...
4479 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_MASK
);
4483 case IPP_TAG_UNSUPPORTED_VALUE
:
4484 case IPP_TAG_DEFAULT
:
4485 case IPP_TAG_UNKNOWN
:
4486 case IPP_TAG_NOVALUE
:
4487 case IPP_TAG_NOTSETTABLE
:
4488 case IPP_TAG_DELETEATTR
:
4489 case IPP_TAG_ADMINDEFINE
:
4491 * Free any existing values...
4494 if ((*attr
)->num_values
> 0)
4495 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
4498 * Set out-of-band value...
4501 (*attr
)->value_tag
= value_tag
;
4504 case IPP_TAG_RANGE
:
4505 if (temp_tag
!= IPP_TAG_INTEGER
)
4508 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4512 integer
= value
->integer
;
4513 value
->range
.lower
= value
->range
.upper
= integer
;
4516 (*attr
)->value_tag
= IPP_TAG_RANGE
;
4520 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
4521 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
4522 temp_tag
!= IPP_TAG_MIMETYPE
)
4525 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_COPY
));
4528 case IPP_TAG_NAMELANG
:
4529 case IPP_TAG_TEXTLANG
:
4530 if (value_tag
== IPP_TAG_NAMELANG
&&
4531 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
4532 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
4533 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
4536 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
4539 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
4540 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
4543 * Use the language code from the IPP message...
4546 (*attr
)->values
[0].string
.language
=
4547 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
4552 * Otherwise, use the language code corresponding to the locale...
4555 language
= cupsLangDefault();
4556 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
4561 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
4564 value
->string
.language
= (*attr
)->values
[0].string
.language
;
4566 if ((int)(*attr
)->value_tag
& IPP_TAG_COPY
)
4569 * Make copies of all values...
4572 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
4575 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
4578 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
4581 case IPP_TAG_KEYWORD
:
4582 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
4583 break; /* Silently "allow" name -> keyword */
4594 * 'ippSetVersion()' - Set the version number in an IPP message.
4596 * The @code ipp@ parameter refers to an IPP message previously created using
4597 * the @link ippNew@, @link ippNewRequest@, or @link ippNewResponse@ functions.
4599 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
4601 * @since CUPS 1.6/OS X 10.8@
4604 int /* O - 1 on success, 0 on failure */
4605 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
4606 int major
, /* I - Major version number (major.minor) */
4607 int minor
) /* I - Minor version number (major.minor) */
4610 * Range check input...
4613 if (!ipp
|| major
< 0 || minor
< 0)
4617 * Set the version number...
4620 ipp
->request
.any
.version
[0] = major
;
4621 ipp
->request
.any
.version
[1] = minor
;
4628 * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
4631 const ipp_uchar_t
* /* O - RFC-1903 date/time data */
4632 ippTimeToDate(time_t t
) /* I - UNIX time value */
4634 struct tm
*unixdate
; /* UNIX unixdate/time info */
4635 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
4636 /* RFC-1903 date/time data */
4640 * RFC-1903 date/time format is:
4642 * Byte(s) Description
4643 * ------- -----------
4644 * 0-1 Year (0 to 65535)
4648 * 5 Minutes (0 to 59)
4649 * 6 Seconds (0 to 60, 60 = "leap second")
4650 * 7 Deciseconds (0 to 9)
4652 * 9 UTC hours (0 to 11)
4653 * 10 UTC minutes (0 to 59)
4656 unixdate
= gmtime(&t
);
4657 unixdate
->tm_year
+= 1900;
4659 date
[0] = unixdate
->tm_year
>> 8;
4660 date
[1] = unixdate
->tm_year
;
4661 date
[2] = unixdate
->tm_mon
+ 1;
4662 date
[3] = unixdate
->tm_mday
;
4663 date
[4] = unixdate
->tm_hour
;
4664 date
[5] = unixdate
->tm_min
;
4665 date
[6] = unixdate
->tm_sec
;
4676 * 'ippValidateAttribute()' - Validate the contents of an attribute.
4678 * This function validates the contents of an attribute based on the name and
4679 * value tag. 1 is returned if the attribute is valid, 0 otherwise. On
4680 * failure, cupsLastErrorString() is set to a human-readable message.
4685 int /* O - 1 if valid, 0 otherwise */
4686 ippValidateAttribute(
4687 ipp_attribute_t
*attr
) /* I - Attribute */
4689 int i
; /* Looping var */
4690 char scheme
[64], /* Scheme from URI */
4691 userpass
[256], /* Username/password from URI */
4692 hostname
[256], /* Hostname from URI */
4693 resource
[1024]; /* Resource from URI */
4694 int port
, /* Port number from URI */
4695 uri_status
; /* URI separation status */
4696 const char *ptr
; /* Pointer into string */
4697 ipp_attribute_t
*colattr
; /* Collection attribute */
4698 regex_t re
; /* Regular expression */
4699 ipp_uchar_t
*date
; /* Current date value */
4700 static const char * const uri_status_strings
[] =
4701 { /* URI status strings */
4703 "Bad arguments to function",
4704 "Bad resource in URI",
4705 "Bad port number in URI",
4706 "Bad hostname/address in URI",
4707 "Bad username in URI",
4708 "Bad scheme in URI",
4711 "Missing scheme in URI",
4712 "Unknown scheme in URI",
4713 "Missing resource in URI"
4725 * Validate the attribute name.
4728 for (ptr
= attr
->name
; *ptr
; ptr
++)
4729 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4732 if (*ptr
|| ptr
== attr
->name
)
4734 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4735 _("\"%s\": Bad attribute name - invalid character "
4736 "(RFC 2911 section 4.1.3)."), attr
->name
);
4740 if ((ptr
- attr
->name
) > 255)
4742 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4743 _("\"%s\": Bad attribute name - bad length %d "
4744 "(RFC 2911 section 4.1.3)."), attr
->name
,
4745 (int)(ptr
- attr
->name
));
4749 switch (attr
->value_tag
)
4751 case IPP_TAG_INTEGER
:
4754 case IPP_TAG_BOOLEAN
:
4755 for (i
= 0; i
< attr
->num_values
; i
++)
4757 if (attr
->values
[i
].boolean
!= 0 &&
4758 attr
->values
[i
].boolean
!= 1)
4760 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4761 _("\"%s\": Bad boolen value %d "
4762 "(RFC 2911 section 4.1.11)."), attr
->name
,
4763 attr
->values
[i
].boolean
);
4770 for (i
= 0; i
< attr
->num_values
; i
++)
4772 if (attr
->values
[i
].integer
< 1)
4774 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4775 _("\"%s\": Bad enum value %d - out of range "
4776 "(RFC 2911 section 4.1.4)."), attr
->name
,
4777 attr
->values
[i
].integer
);
4783 case IPP_TAG_STRING
:
4784 for (i
= 0; i
< attr
->num_values
; i
++)
4786 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4788 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4789 _("\"%s\": Bad octetString value - bad length %d "
4790 "(RFC 2911 section 4.1.10)."), attr
->name
,
4791 attr
->values
[i
].unknown
.length
);
4798 for (i
= 0; i
< attr
->num_values
; i
++)
4800 date
= attr
->values
[i
].date
;
4802 if (date
[2] < 1 || date
[2] > 12)
4804 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4805 _("\"%s\": Bad dateTime month %u "
4806 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[2]);
4810 if (date
[3] < 1 || date
[3] > 31)
4812 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4813 _("\"%s\": Bad dateTime day %u "
4814 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[3]);
4820 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4821 _("\"%s\": Bad dateTime hours %u "
4822 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[4]);
4828 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4829 _("\"%s\": Bad dateTime minutes %u "
4830 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[5]);
4836 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4837 _("\"%s\": Bad dateTime seconds %u "
4838 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[6]);
4844 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4845 _("\"%s\": Bad dateTime deciseconds %u "
4846 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[7]);
4850 if (date
[8] != '-' && date
[8] != '+')
4852 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4853 _("\"%s\": Bad dateTime UTC sign '%c' "
4854 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[8]);
4860 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4861 _("\"%s\": Bad dateTime UTC hours %u "
4862 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[9]);
4868 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4869 _("\"%s\": Bad dateTime UTC minutes %u "
4870 "(RFC 2911 section 4.1.14)."), attr
->name
, date
[10]);
4876 case IPP_TAG_RESOLUTION
:
4877 for (i
= 0; i
< attr
->num_values
; i
++)
4879 if (attr
->values
[i
].resolution
.xres
<= 0)
4881 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4882 _("\"%s\": Bad resolution value %dx%d%s - cross "
4883 "feed resolution must be positive "
4884 "(RFC 2911 section 4.1.15)."), attr
->name
,
4885 attr
->values
[i
].resolution
.xres
,
4886 attr
->values
[i
].resolution
.yres
,
4887 attr
->values
[i
].resolution
.units
==
4888 IPP_RES_PER_INCH
? "dpi" :
4889 attr
->values
[i
].resolution
.units
==
4890 IPP_RES_PER_CM
? "dpcm" : "unknown");
4894 if (attr
->values
[i
].resolution
.yres
<= 0)
4896 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4897 _("\"%s\": Bad resolution value %dx%d%s - feed "
4898 "resolution must be positive "
4899 "(RFC 2911 section 4.1.15)."), attr
->name
,
4900 attr
->values
[i
].resolution
.xres
,
4901 attr
->values
[i
].resolution
.yres
,
4902 attr
->values
[i
].resolution
.units
==
4903 IPP_RES_PER_INCH
? "dpi" :
4904 attr
->values
[i
].resolution
.units
==
4905 IPP_RES_PER_CM
? "dpcm" : "unknown");
4909 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
4910 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
4912 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4913 _("\"%s\": Bad resolution value %dx%d%s - bad "
4914 "units value (RFC 2911 section 4.1.15)."),
4915 attr
->name
, attr
->values
[i
].resolution
.xres
,
4916 attr
->values
[i
].resolution
.yres
,
4917 attr
->values
[i
].resolution
.units
==
4918 IPP_RES_PER_INCH
? "dpi" :
4919 attr
->values
[i
].resolution
.units
==
4920 IPP_RES_PER_CM
? "dpcm" : "unknown");
4926 case IPP_TAG_RANGE
:
4927 for (i
= 0; i
< attr
->num_values
; i
++)
4929 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
4931 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4932 _("\"%s\": Bad rangeOfInteger value %d-%d - lower "
4933 "greater than upper (RFC 2911 section 4.1.13)."),
4934 attr
->name
, attr
->values
[i
].range
.lower
,
4935 attr
->values
[i
].range
.upper
);
4941 case IPP_TAG_BEGIN_COLLECTION
:
4942 for (i
= 0; i
< attr
->num_values
; i
++)
4944 for (colattr
= attr
->values
[i
].collection
->attrs
;
4946 colattr
= colattr
->next
)
4948 if (!ippValidateAttribute(colattr
))
4955 case IPP_TAG_TEXTLANG
:
4956 for (i
= 0; i
< attr
->num_values
; i
++)
4958 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
4960 if ((*ptr
& 0xe0) == 0xc0)
4963 if ((*ptr
& 0xc0) != 0x80)
4966 else if ((*ptr
& 0xf0) == 0xe0)
4969 if ((*ptr
& 0xc0) != 0x80)
4972 if ((*ptr
& 0xc0) != 0x80)
4975 else if ((*ptr
& 0xf8) == 0xf0)
4978 if ((*ptr
& 0xc0) != 0x80)
4981 if ((*ptr
& 0xc0) != 0x80)
4984 if ((*ptr
& 0xc0) != 0x80)
4987 else if (*ptr
& 0x80)
4993 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
4994 _("\"%s\": Bad text value \"%s\" - bad UTF-8 "
4995 "sequence (RFC 2911 section 4.1.1)."), attr
->name
,
4996 attr
->values
[i
].string
.text
);
5000 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5002 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5003 _("\"%s\": Bad text value \"%s\" - bad length %d "
5004 "(RFC 2911 section 4.1.1)."), attr
->name
,
5005 attr
->values
[i
].string
.text
,
5006 (int)(ptr
- attr
->values
[i
].string
.text
));
5013 case IPP_TAG_NAMELANG
:
5014 for (i
= 0; i
< attr
->num_values
; i
++)
5016 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5018 if ((*ptr
& 0xe0) == 0xc0)
5021 if ((*ptr
& 0xc0) != 0x80)
5024 else if ((*ptr
& 0xf0) == 0xe0)
5027 if ((*ptr
& 0xc0) != 0x80)
5030 if ((*ptr
& 0xc0) != 0x80)
5033 else if ((*ptr
& 0xf8) == 0xf0)
5036 if ((*ptr
& 0xc0) != 0x80)
5039 if ((*ptr
& 0xc0) != 0x80)
5042 if ((*ptr
& 0xc0) != 0x80)
5045 else if (*ptr
& 0x80)
5051 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5052 _("\"%s\": Bad name value \"%s\" - bad UTF-8 "
5053 "sequence (RFC 2911 section 4.1.2)."), attr
->name
,
5054 attr
->values
[i
].string
.text
);
5058 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5060 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5061 _("\"%s\": Bad name value \"%s\" - bad length %d "
5062 "(RFC 2911 section 4.1.2)."), attr
->name
,
5063 attr
->values
[i
].string
.text
,
5064 (int)(ptr
- attr
->values
[i
].string
.text
));
5070 case IPP_TAG_KEYWORD
:
5071 for (i
= 0; i
< attr
->num_values
; i
++)
5073 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5074 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5078 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5080 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5081 _("\"%s\": Bad keyword value \"%s\" - invalid "
5082 "character (RFC 2911 section 4.1.3)."),
5083 attr
->name
, attr
->values
[i
].string
.text
);
5087 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5089 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5090 _("\"%s\": Bad keyword value \"%s\" - bad "
5091 "length %d (RFC 2911 section 4.1.3)."),
5092 attr
->name
, attr
->values
[i
].string
.text
,
5093 (int)(ptr
- attr
->values
[i
].string
.text
));
5100 for (i
= 0; i
< attr
->num_values
; i
++)
5102 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5103 attr
->values
[i
].string
.text
,
5104 scheme
, sizeof(scheme
),
5105 userpass
, sizeof(userpass
),
5106 hostname
, sizeof(hostname
),
5107 &port
, resource
, sizeof(resource
));
5109 if (uri_status
< HTTP_URI_OK
)
5111 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5112 _("\"%s\": Bad URI value \"%s\" - %s "
5113 "(RFC 2911 section 4.1.5)."), attr
->name
,
5114 attr
->values
[i
].string
.text
,
5115 uri_status_strings
[uri_status
-
5116 HTTP_URI_OVERFLOW
]);
5120 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5122 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5123 _("\"%s\": Bad URI value \"%s\" - bad length %d "
5124 "(RFC 2911 section 4.1.5)."), attr
->name
,
5125 attr
->values
[i
].string
.text
,
5126 (int)strlen(attr
->values
[i
].string
.text
));
5131 case IPP_TAG_URISCHEME
:
5132 for (i
= 0; i
< attr
->num_values
; i
++)
5134 ptr
= attr
->values
[i
].string
.text
;
5135 if (islower(*ptr
& 255))
5137 for (ptr
++; *ptr
; ptr
++)
5138 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5139 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5143 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5145 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5146 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5147 "characters (RFC 2911 section 4.1.6)."),
5148 attr
->name
, attr
->values
[i
].string
.text
);
5152 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5154 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5155 _("\"%s\": Bad uriScheme value \"%s\" - bad "
5156 "length %d (RFC 2911 section 4.1.6)."),
5157 attr
->name
, attr
->values
[i
].string
.text
,
5158 (int)(ptr
- attr
->values
[i
].string
.text
));
5164 case IPP_TAG_CHARSET
:
5165 for (i
= 0; i
< attr
->num_values
; i
++)
5167 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5168 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5169 isspace(*ptr
& 255))
5172 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5174 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5175 _("\"%s\": Bad charset value \"%s\" - bad "
5176 "characters (RFC 2911 section 4.1.7)."),
5177 attr
->name
, attr
->values
[i
].string
.text
);
5181 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5183 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5184 _("\"%s\": Bad charset value \"%s\" - bad "
5185 "length %d (RFC 2911 section 4.1.7)."),
5186 attr
->name
, attr
->values
[i
].string
.text
,
5187 (int)(ptr
- attr
->values
[i
].string
.text
));
5193 case IPP_TAG_LANGUAGE
:
5195 * The following regular expression is derived from the ABNF for
5196 * language tags in RFC 4646. All I can say is that this is the
5197 * easiest way to check the values...
5200 if ((i
= regcomp(&re
,
5202 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5204 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5205 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5206 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5207 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5208 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5210 "x(-[a-z0-9]{1,8})+" /* privateuse */
5212 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5214 REG_NOSUB
| REG_EXTENDED
)) != 0)
5216 char temp
[256]; /* Temporary error string */
5218 regerror(i
, &re
, temp
, sizeof(temp
));
5219 ipp_set_error(IPP_STATUS_ERROR_INTERNAL
,
5220 _("Unable to compile naturalLanguage regular "
5221 "expression: %s."), temp
);
5225 for (i
= 0; i
< attr
->num_values
; i
++)
5227 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5229 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5230 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5231 "characters (RFC 2911 section 4.1.8)."),
5232 attr
->name
, attr
->values
[i
].string
.text
);
5237 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5239 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5240 _("\"%s\": Bad naturalLanguage value \"%s\" - bad "
5241 "length %d (RFC 2911 section 4.1.8)."),
5242 attr
->name
, attr
->values
[i
].string
.text
,
5243 (int)strlen(attr
->values
[i
].string
.text
));
5252 case IPP_TAG_MIMETYPE
:
5254 * The following regular expression is derived from the ABNF for
5255 * MIME media types in RFC 2045 and 4288. All I can say is that this is
5256 * the easiest way to check the values...
5259 if ((i
= regcomp(&re
,
5261 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5263 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5264 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5265 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5268 REG_NOSUB
| REG_EXTENDED
)) != 0)
5270 char temp
[256]; /* Temporary error string */
5272 regerror(i
, &re
, temp
, sizeof(temp
));
5273 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5274 _("Unable to compile mimeMediaType regular "
5275 "expression: %s."), temp
);
5279 for (i
= 0; i
< attr
->num_values
; i
++)
5281 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5283 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5284 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5285 "characters (RFC 2911 section 4.1.9)."),
5286 attr
->name
, attr
->values
[i
].string
.text
);
5291 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5293 ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST
,
5294 _("\"%s\": Bad mimeMediaType value \"%s\" - bad "
5295 "length %d (RFC 2911 section 4.1.9)."),
5296 attr
->name
, attr
->values
[i
].string
.text
,
5297 (int)strlen(attr
->values
[i
].string
.text
));
5315 * 'ippValidateAttributes()' - Validate all attributes in an IPP message.
5317 * This function validates the contents of the IPP message, including each
5318 * attribute. Like @link ippValidateAttribute@, cupsLastErrorString() is set
5319 * to a human-readable message on failure.
5324 int /* O - 1 if valid, 0 otherwise */
5325 ippValidateAttributes(ipp_t
*ipp
) /* I - IPP message */
5327 ipp_attribute_t
*attr
; /* Current attribute */
5333 for (attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
5334 if (!ippValidateAttribute(attr
))
5342 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
5345 ipp_state_t
/* O - Current state */
5346 ippWrite(http_t
*http
, /* I - HTTP connection */
5347 ipp_t
*ipp
) /* I - IPP data */
5349 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", http
, ipp
));
5354 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
5359 * 'ippWriteFile()' - Write data for an IPP message to a file.
5361 * @since CUPS 1.1.19/OS X 10.3@
5364 ipp_state_t
/* O - Current state */
5365 ippWriteFile(int fd
, /* I - HTTP data */
5366 ipp_t
*ipp
) /* I - IPP data */
5368 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, ipp
));
5370 ipp
->state
= IPP_IDLE
;
5372 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
5377 * 'ippWriteIO()' - Write data for an IPP message.
5379 * @since CUPS 1.2/OS X 10.5@
5382 ipp_state_t
/* O - Current state */
5383 ippWriteIO(void *dst
, /* I - Destination */
5384 ipp_iocb_t cb
, /* I - Write callback function */
5385 int blocking
, /* I - Use blocking IO? */
5386 ipp_t
*parent
, /* I - Parent IPP message */
5387 ipp_t
*ipp
) /* I - IPP data */
5389 int i
; /* Looping var */
5390 int n
; /* Length of data */
5391 unsigned char *buffer
, /* Data buffer */
5392 *bufptr
; /* Pointer into buffer */
5393 ipp_attribute_t
*attr
; /* Current attribute */
5394 _ipp_value_t
*value
; /* Current value */
5397 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)",
5398 dst
, cb
, blocking
, parent
, ipp
));
5403 if ((buffer
= (unsigned char *)_cupsBufferGet(IPP_BUF_SIZE
)) == NULL
)
5405 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
5412 ipp
->state
++; /* Avoid common problem... */
5418 * Send the request header:
5421 * Operation/Status Code = 2 bytes
5422 * Request ID = 4 bytes
5428 *bufptr
++ = ipp
->request
.any
.version
[0];
5429 *bufptr
++ = ipp
->request
.any
.version
[1];
5430 *bufptr
++ = ipp
->request
.any
.op_status
>> 8;
5431 *bufptr
++ = ipp
->request
.any
.op_status
;
5432 *bufptr
++ = ipp
->request
.any
.request_id
>> 24;
5433 *bufptr
++ = ipp
->request
.any
.request_id
>> 16;
5434 *bufptr
++ = ipp
->request
.any
.request_id
>> 8;
5435 *bufptr
++ = ipp
->request
.any
.request_id
;
5437 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
5438 DEBUG_printf(("2ippWriteIO: op_status=%04x",
5439 ipp
->request
.any
.op_status
));
5440 DEBUG_printf(("2ippWriteIO: request_id=%d",
5441 ipp
->request
.any
.request_id
));
5443 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5445 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
5446 _cupsBufferRelease((char *)buffer
);
5452 * Reset the state engine to point to the first attribute
5453 * in the request/response, with no current group.
5456 ipp
->state
= IPP_ATTRIBUTE
;
5457 ipp
->current
= ipp
->attrs
;
5458 ipp
->curtag
= IPP_TAG_ZERO
;
5460 DEBUG_printf(("1ippWriteIO: ipp->current=%p", ipp
->current
));
5463 * If blocking is disabled, stop here...
5469 case IPP_ATTRIBUTE
:
5470 while (ipp
->current
!= NULL
)
5473 * Write this attribute...
5477 attr
= ipp
->current
;
5479 ipp
->current
= ipp
->current
->next
;
5483 if (ipp
->curtag
!= attr
->group_tag
)
5486 * Send a group tag byte...
5489 ipp
->curtag
= attr
->group_tag
;
5491 if (attr
->group_tag
== IPP_TAG_ZERO
)
5494 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
5495 attr
->group_tag
, ippTagString(attr
->group_tag
)));
5496 *bufptr
++ = attr
->group_tag
;
5498 else if (attr
->group_tag
== IPP_TAG_ZERO
)
5502 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
5503 attr
->num_values
> 1 ? "1setOf " : "",
5504 ippTagString(attr
->value_tag
)));
5507 * Write the attribute tag and name.
5509 * The attribute name length does not include the trailing nul
5510 * character in the source string.
5512 * Collection values (parent != NULL) are written differently...
5518 * Get the length of the attribute name, and make sure it won't
5519 * overflow the buffer...
5522 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
5524 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5525 _cupsBufferRelease((char *)buffer
);
5530 * Write the value tag, name length, and name string...
5533 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5534 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5535 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5538 if (attr
->value_tag
> 0xff)
5540 *bufptr
++ = IPP_TAG_EXTENSION
;
5541 *bufptr
++ = attr
->value_tag
>> 24;
5542 *bufptr
++ = attr
->value_tag
>> 16;
5543 *bufptr
++ = attr
->value_tag
>> 8;
5544 *bufptr
++ = attr
->value_tag
;
5547 *bufptr
++ = attr
->value_tag
;
5551 memcpy(bufptr
, attr
->name
, n
);
5557 * Get the length of the attribute name, and make sure it won't
5558 * overflow the buffer...
5561 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
5563 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
5564 _cupsBufferRelease((char *)buffer
);
5569 * Write the member name tag, name length, name string, value tag,
5570 * and empty name for the collection member attribute...
5573 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
5574 IPP_TAG_MEMBERNAME
));
5575 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
5577 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5578 attr
->value_tag
, ippTagString(attr
->value_tag
)));
5579 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
5581 *bufptr
++ = IPP_TAG_MEMBERNAME
;
5586 memcpy(bufptr
, attr
->name
, n
);
5589 if (attr
->value_tag
> 0xff)
5591 *bufptr
++ = IPP_TAG_EXTENSION
;
5592 *bufptr
++ = attr
->value_tag
>> 24;
5593 *bufptr
++ = attr
->value_tag
>> 16;
5594 *bufptr
++ = attr
->value_tag
>> 8;
5595 *bufptr
++ = attr
->value_tag
;
5598 *bufptr
++ = attr
->value_tag
;
5605 * Now write the attribute value(s)...
5608 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
5610 case IPP_TAG_UNSUPPORTED_VALUE
:
5611 case IPP_TAG_DEFAULT
:
5612 case IPP_TAG_UNKNOWN
:
5613 case IPP_TAG_NOVALUE
:
5614 case IPP_TAG_NOTSETTABLE
:
5615 case IPP_TAG_DELETEATTR
:
5616 case IPP_TAG_ADMINDEFINE
:
5621 case IPP_TAG_INTEGER
:
5623 for (i
= 0, value
= attr
->values
;
5624 i
< attr
->num_values
;
5627 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
5629 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5631 DEBUG_puts("1ippWriteIO: Could not write IPP "
5633 _cupsBufferRelease((char *)buffer
);
5643 * Arrays and sets are done by sending additional
5644 * values with a zero-length name...
5647 *bufptr
++ = attr
->value_tag
;
5653 * Integers and enumerations are both 4-byte signed
5654 * (twos-complement) values.
5656 * Put the 2-byte length and 4-byte value into the buffer...
5661 *bufptr
++ = value
->integer
>> 24;
5662 *bufptr
++ = value
->integer
>> 16;
5663 *bufptr
++ = value
->integer
>> 8;
5664 *bufptr
++ = value
->integer
;
5668 case IPP_TAG_BOOLEAN
:
5669 for (i
= 0, value
= attr
->values
;
5670 i
< attr
->num_values
;
5673 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
5675 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5677 DEBUG_puts("1ippWriteIO: Could not write IPP "
5679 _cupsBufferRelease((char *)buffer
);
5689 * Arrays and sets are done by sending additional
5690 * values with a zero-length name...
5693 *bufptr
++ = attr
->value_tag
;
5699 * Boolean values are 1-byte; 0 = false, 1 = true.
5701 * Put the 2-byte length and 1-byte value into the buffer...
5706 *bufptr
++ = value
->boolean
;
5712 case IPP_TAG_KEYWORD
:
5714 case IPP_TAG_URISCHEME
:
5715 case IPP_TAG_CHARSET
:
5716 case IPP_TAG_LANGUAGE
:
5717 case IPP_TAG_MIMETYPE
:
5718 for (i
= 0, value
= attr
->values
;
5719 i
< attr
->num_values
;
5725 * Arrays and sets are done by sending additional
5726 * values with a zero-length name...
5729 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
5731 ippTagString(attr
->value_tag
)));
5732 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
5734 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5736 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5738 DEBUG_puts("1ippWriteIO: Could not write IPP "
5740 _cupsBufferRelease((char *)buffer
);
5747 *bufptr
++ = attr
->value_tag
;
5752 if (value
->string
.text
!= NULL
)
5753 n
= (int)strlen(value
->string
.text
);
5757 if (n
> (IPP_BUF_SIZE
- 2))
5759 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
5760 _cupsBufferRelease((char *)buffer
);
5764 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
5765 value
->string
.text
));
5767 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
5769 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5771 DEBUG_puts("1ippWriteIO: Could not write IPP "
5773 _cupsBufferRelease((char *)buffer
);
5781 * All simple strings consist of the 2-byte length and
5782 * character data without the trailing nul normally found
5783 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
5784 * bytes since the 2-byte length is a signed (twos-complement)
5787 * Put the 2-byte length and string characters in the buffer.
5795 memcpy(bufptr
, value
->string
.text
, n
);
5802 for (i
= 0, value
= attr
->values
;
5803 i
< attr
->num_values
;
5806 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
5808 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5810 DEBUG_puts("1ippWriteIO: Could not write IPP "
5812 _cupsBufferRelease((char *)buffer
);
5822 * Arrays and sets are done by sending additional
5823 * values with a zero-length name...
5826 *bufptr
++ = attr
->value_tag
;
5832 * Date values consist of a 2-byte length and an
5833 * 11-byte date/time structure defined by RFC 1903.
5835 * Put the 2-byte length and 11-byte date/time
5836 * structure in the buffer.
5841 memcpy(bufptr
, value
->date
, 11);
5846 case IPP_TAG_RESOLUTION
:
5847 for (i
= 0, value
= attr
->values
;
5848 i
< attr
->num_values
;
5851 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
5853 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5855 DEBUG_puts("1ippWriteIO: Could not write IPP "
5857 _cupsBufferRelease((char *)buffer
);
5867 * Arrays and sets are done by sending additional
5868 * values with a zero-length name...
5871 *bufptr
++ = attr
->value_tag
;
5877 * Resolution values consist of a 2-byte length,
5878 * 4-byte horizontal resolution value, 4-byte vertical
5879 * resolution value, and a 1-byte units value.
5881 * Put the 2-byte length and resolution value data
5887 *bufptr
++ = value
->resolution
.xres
>> 24;
5888 *bufptr
++ = value
->resolution
.xres
>> 16;
5889 *bufptr
++ = value
->resolution
.xres
>> 8;
5890 *bufptr
++ = value
->resolution
.xres
;
5891 *bufptr
++ = value
->resolution
.yres
>> 24;
5892 *bufptr
++ = value
->resolution
.yres
>> 16;
5893 *bufptr
++ = value
->resolution
.yres
>> 8;
5894 *bufptr
++ = value
->resolution
.yres
;
5895 *bufptr
++ = value
->resolution
.units
;
5899 case IPP_TAG_RANGE
:
5900 for (i
= 0, value
= attr
->values
;
5901 i
< attr
->num_values
;
5904 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
5906 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5908 DEBUG_puts("1ippWriteIO: Could not write IPP "
5910 _cupsBufferRelease((char *)buffer
);
5920 * Arrays and sets are done by sending additional
5921 * values with a zero-length name...
5924 *bufptr
++ = attr
->value_tag
;
5930 * Range values consist of a 2-byte length,
5931 * 4-byte lower value, and 4-byte upper value.
5933 * Put the 2-byte length and range value data
5939 *bufptr
++ = value
->range
.lower
>> 24;
5940 *bufptr
++ = value
->range
.lower
>> 16;
5941 *bufptr
++ = value
->range
.lower
>> 8;
5942 *bufptr
++ = value
->range
.lower
;
5943 *bufptr
++ = value
->range
.upper
>> 24;
5944 *bufptr
++ = value
->range
.upper
>> 16;
5945 *bufptr
++ = value
->range
.upper
>> 8;
5946 *bufptr
++ = value
->range
.upper
;
5950 case IPP_TAG_TEXTLANG
:
5951 case IPP_TAG_NAMELANG
:
5952 for (i
= 0, value
= attr
->values
;
5953 i
< attr
->num_values
;
5959 * Arrays and sets are done by sending additional
5960 * values with a zero-length name...
5963 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
5965 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
5967 DEBUG_puts("1ippWriteIO: Could not write IPP "
5969 _cupsBufferRelease((char *)buffer
);
5976 *bufptr
++ = attr
->value_tag
;
5982 * textWithLanguage and nameWithLanguage values consist
5983 * of a 2-byte length for both strings and their
5984 * individual lengths, a 2-byte length for the
5985 * character string, the character string without the
5986 * trailing nul, a 2-byte length for the character
5987 * set string, and the character set string without
5993 if (value
->string
.language
!= NULL
)
5994 n
+= (int)strlen(value
->string
.language
);
5996 if (value
->string
.text
!= NULL
)
5997 n
+= (int)strlen(value
->string
.text
);
5999 if (n
> (IPP_BUF_SIZE
- 2))
6001 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
6002 "too long (%d)", n
));
6003 _cupsBufferRelease((char *)buffer
);
6007 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6009 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6011 DEBUG_puts("1ippWriteIO: Could not write IPP "
6013 _cupsBufferRelease((char *)buffer
);
6020 /* Length of entire value */
6024 /* Length of language */
6025 if (value
->string
.language
!= NULL
)
6026 n
= (int)strlen(value
->string
.language
);
6036 memcpy(bufptr
, value
->string
.language
, n
);
6040 /* Length of text */
6041 if (value
->string
.text
!= NULL
)
6042 n
= (int)strlen(value
->string
.text
);
6052 memcpy(bufptr
, value
->string
.text
, n
);
6058 case IPP_TAG_BEGIN_COLLECTION
:
6059 for (i
= 0, value
= attr
->values
;
6060 i
< attr
->num_values
;
6064 * Collections are written with the begin-collection
6065 * tag first with a value of 0 length, followed by the
6066 * attributes in the collection, then the end-collection
6070 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
6072 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6074 DEBUG_puts("1ippWriteIO: Could not write IPP "
6076 _cupsBufferRelease((char *)buffer
);
6086 * Arrays and sets are done by sending additional
6087 * values with a zero-length name...
6090 *bufptr
++ = attr
->value_tag
;
6096 * Write a data length of 0 and flush the buffer...
6102 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6104 DEBUG_puts("1ippWriteIO: Could not write IPP "
6106 _cupsBufferRelease((char *)buffer
);
6113 * Then write the collection attribute...
6116 value
->collection
->state
= IPP_IDLE
;
6118 if (ippWriteIO(dst
, cb
, 1, ipp
,
6119 value
->collection
) == IPP_ERROR
)
6121 DEBUG_puts("1ippWriteIO: Unable to write collection value");
6122 _cupsBufferRelease((char *)buffer
);
6129 for (i
= 0, value
= attr
->values
;
6130 i
< attr
->num_values
;
6136 * Arrays and sets are done by sending additional
6137 * values with a zero-length name...
6140 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
6142 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6144 DEBUG_puts("1ippWriteIO: Could not write IPP "
6146 _cupsBufferRelease((char *)buffer
);
6153 *bufptr
++ = attr
->value_tag
;
6159 * An unknown value might some new value that a
6160 * vendor has come up with. It consists of a
6161 * 2-byte length and the bytes in the unknown
6165 n
= value
->unknown
.length
;
6167 if (n
> (IPP_BUF_SIZE
- 2))
6169 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
6171 _cupsBufferRelease((char *)buffer
);
6175 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
6177 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6179 DEBUG_puts("1ippWriteIO: Could not write IPP "
6181 _cupsBufferRelease((char *)buffer
);
6188 /* Length of unknown value */
6195 memcpy(bufptr
, value
->unknown
.data
, n
);
6203 * Write the data out...
6206 if (bufptr
> buffer
)
6208 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
6210 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
6211 _cupsBufferRelease((char *)buffer
);
6215 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
6216 (int)(bufptr
- buffer
)));
6220 * If blocking is disabled, stop here...
6227 if (ipp
->current
== NULL
)
6230 * Done with all of the attributes; add the end-of-attributes
6231 * tag or end-collection attribute...
6236 buffer
[0] = IPP_TAG_END
;
6241 buffer
[0] = IPP_TAG_END_COLLECTION
;
6242 buffer
[1] = 0; /* empty name */
6244 buffer
[3] = 0; /* empty value */
6249 if ((*cb
)(dst
, buffer
, n
) < 0)
6251 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
6252 _cupsBufferRelease((char *)buffer
);
6256 ipp
->state
= IPP_DATA
;
6264 break; /* anti-compiler-warning-code */
6267 _cupsBufferRelease((char *)buffer
);
6269 return (ipp
->state
);
6274 * 'ipp_add_attr()' - Add a new attribute to the message.
6277 static ipp_attribute_t
* /* O - New attribute */
6278 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
6279 const char *name
, /* I - Attribute name or NULL */
6280 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
6281 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
6282 int num_values
) /* I - Number of values */
6284 int alloc_values
; /* Number of values to allocate */
6285 ipp_attribute_t
*attr
; /* New attribute */
6288 DEBUG_printf(("4ipp_add_attr(ipp=%p, name=\"%s\", group_tag=0x%x, value_tag=0x%x, "
6289 "num_values=%d)", ipp
, name
, group_tag
, value_tag
, num_values
));
6292 * Range check input...
6295 if (!ipp
|| num_values
< 0)
6299 * Allocate memory, rounding the allocation up as needed...
6302 if (num_values
<= 1)
6305 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
6307 attr
= calloc(sizeof(ipp_attribute_t
) +
6308 (alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
6313 * Initialize attribute...
6317 attr
->name
= _cupsStrAlloc(name
);
6319 attr
->group_tag
= group_tag
;
6320 attr
->value_tag
= value_tag
;
6321 attr
->num_values
= num_values
;
6324 * Add it to the end of the linked list...
6328 ipp
->last
->next
= attr
;
6332 ipp
->prev
= ipp
->last
;
6333 ipp
->last
= ipp
->current
= attr
;
6336 DEBUG_printf(("5ipp_add_attr: Returning %p", attr
));
6343 * 'ipp_free_values()' - Free attribute values.
6347 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
6348 int element
,/* I - First value to free */
6349 int count
) /* I - Number of values to free */
6351 int i
; /* Looping var */
6352 _ipp_value_t
*value
; /* Current value */
6355 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", attr
,
6358 if (!(attr
->value_tag
& IPP_TAG_COPY
))
6361 * Free values as needed...
6364 switch (attr
->value_tag
)
6366 case IPP_TAG_TEXTLANG
:
6367 case IPP_TAG_NAMELANG
:
6368 if (element
== 0 && count
== attr
->num_values
&&
6369 attr
->values
[0].string
.language
)
6371 _cupsStrFree(attr
->values
[0].string
.language
);
6372 attr
->values
[0].string
.language
= NULL
;
6374 /* Fall through to other string values */
6378 case IPP_TAG_RESERVED_STRING
:
6379 case IPP_TAG_KEYWORD
:
6381 case IPP_TAG_URISCHEME
:
6382 case IPP_TAG_CHARSET
:
6383 case IPP_TAG_LANGUAGE
:
6384 case IPP_TAG_MIMETYPE
:
6385 for (i
= count
, value
= attr
->values
+ element
;
6389 _cupsStrFree(value
->string
.text
);
6390 value
->string
.text
= NULL
;
6394 case IPP_TAG_DEFAULT
:
6395 case IPP_TAG_UNKNOWN
:
6396 case IPP_TAG_NOVALUE
:
6397 case IPP_TAG_NOTSETTABLE
:
6398 case IPP_TAG_DELETEATTR
:
6399 case IPP_TAG_ADMINDEFINE
:
6400 case IPP_TAG_INTEGER
:
6402 case IPP_TAG_BOOLEAN
:
6404 case IPP_TAG_RESOLUTION
:
6405 case IPP_TAG_RANGE
:
6408 case IPP_TAG_BEGIN_COLLECTION
:
6409 for (i
= count
, value
= attr
->values
+ element
;
6413 ippDelete(value
->collection
);
6414 value
->collection
= NULL
;
6418 case IPP_TAG_STRING
:
6420 for (i
= count
, value
= attr
->values
+ element
;
6424 if (value
->unknown
.data
)
6426 free(value
->unknown
.data
);
6427 value
->unknown
.data
= NULL
;
6435 * If we are not freeing values from the end, move the remaining values up...
6438 if ((element
+ count
) < attr
->num_values
)
6439 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
6440 (attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
6442 attr
->num_values
-= count
;
6447 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
6449 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
6450 * to "ll-cc", "ll-region", and "charset-number", respectively.
6453 static char * /* O - Language code string */
6454 ipp_get_code(const char *value
, /* I - Locale/charset string */
6455 char *buffer
, /* I - String buffer */
6456 size_t bufsize
) /* I - Size of string buffer */
6458 char *bufptr
, /* Pointer into buffer */
6459 *bufend
; /* End of buffer */
6463 * Convert values to lowercase and change _ to - as needed...
6466 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
6467 *value
&& bufptr
< bufend
;
6472 *bufptr
++ = _cups_tolower(*value
);
6477 * Return the converted string...
6485 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
6487 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
6488 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
6491 static char * /* O - Language code string */
6492 ipp_lang_code(const char *locale
, /* I - Locale string */
6493 char *buffer
, /* I - String buffer */
6494 size_t bufsize
) /* I - Size of string buffer */
6497 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
6500 if (!_cups_strcasecmp(locale
, "c"))
6502 strlcpy(buffer
, "en", bufsize
);
6506 return (ipp_get_code(locale
, buffer
, bufsize
));
6511 * 'ipp_length()' - Compute the length of an IPP message or collection value.
6514 static size_t /* O - Size of IPP message */
6515 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
6516 int collection
) /* I - 1 if a collection, 0 otherwise */
6518 int i
; /* Looping var */
6519 size_t bytes
; /* Number of bytes */
6520 ipp_attribute_t
*attr
; /* Current attribute */
6521 ipp_tag_t group
; /* Current group */
6522 _ipp_value_t
*value
; /* Current value */
6525 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", ipp
, collection
));
6529 DEBUG_puts("4ipp_length: Returning 0 bytes");
6534 * Start with 8 bytes for the IPP message header...
6537 bytes
= collection
? 0 : 8;
6540 * Then add the lengths of each attribute...
6543 group
= IPP_TAG_ZERO
;
6545 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
6547 if (attr
->group_tag
!= group
&& !collection
)
6549 group
= attr
->group_tag
;
6550 if (group
== IPP_TAG_ZERO
)
6553 bytes
++; /* Group tag */
6559 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
6560 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
6562 if (attr
->value_tag
< IPP_TAG_EXTENSION
)
6563 bytes
+= attr
->num_values
; /* Value tag for each value */
6565 bytes
+= 5 * attr
->num_values
; /* Value tag for each value */
6566 bytes
+= 2 * attr
->num_values
; /* Name lengths */
6567 bytes
+= (int)strlen(attr
->name
); /* Name */
6568 bytes
+= 2 * attr
->num_values
; /* Value lengths */
6571 bytes
+= 5; /* Add membername overhead */
6573 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
6575 case IPP_TAG_UNSUPPORTED_VALUE
:
6576 case IPP_TAG_DEFAULT
:
6577 case IPP_TAG_UNKNOWN
:
6578 case IPP_TAG_NOVALUE
:
6579 case IPP_TAG_NOTSETTABLE
:
6580 case IPP_TAG_DELETEATTR
:
6581 case IPP_TAG_ADMINDEFINE
:
6584 case IPP_TAG_INTEGER
:
6586 bytes
+= 4 * attr
->num_values
;
6589 case IPP_TAG_BOOLEAN
:
6590 bytes
+= attr
->num_values
;
6595 case IPP_TAG_KEYWORD
:
6597 case IPP_TAG_URISCHEME
:
6598 case IPP_TAG_CHARSET
:
6599 case IPP_TAG_LANGUAGE
:
6600 case IPP_TAG_MIMETYPE
:
6601 for (i
= 0, value
= attr
->values
;
6602 i
< attr
->num_values
;
6604 if (value
->string
.text
)
6605 bytes
+= strlen(value
->string
.text
);
6609 bytes
+= 11 * attr
->num_values
;
6612 case IPP_TAG_RESOLUTION
:
6613 bytes
+= 9 * attr
->num_values
;
6616 case IPP_TAG_RANGE
:
6617 bytes
+= 8 * attr
->num_values
;
6620 case IPP_TAG_TEXTLANG
:
6621 case IPP_TAG_NAMELANG
:
6622 bytes
+= 4 * attr
->num_values
;/* Charset + text length */
6624 for (i
= 0, value
= attr
->values
;
6625 i
< attr
->num_values
;
6628 if (value
->string
.language
)
6629 bytes
+= strlen(value
->string
.language
);
6631 if (value
->string
.text
)
6632 bytes
+= strlen(value
->string
.text
);
6636 case IPP_TAG_BEGIN_COLLECTION
:
6637 for (i
= 0, value
= attr
->values
;
6638 i
< attr
->num_values
;
6640 bytes
+= ipp_length(value
->collection
, 1);
6644 for (i
= 0, value
= attr
->values
;
6645 i
< attr
->num_values
;
6647 bytes
+= value
->unknown
.length
;
6653 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
6654 * for the "end of collection" tag and return...
6662 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
6669 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
6672 static ssize_t
/* O - Number of bytes read */
6673 ipp_read_http(http_t
*http
, /* I - Client connection */
6674 ipp_uchar_t
*buffer
, /* O - Buffer for data */
6675 size_t length
) /* I - Total length */
6677 int tbytes
, /* Total bytes read */
6678 bytes
; /* Bytes read this pass */
6681 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)",
6682 http
, buffer
, (int)length
));
6685 * Loop until all bytes are read...
6688 for (tbytes
= 0, bytes
= 0;
6689 tbytes
< (int)length
;
6690 tbytes
+= bytes
, buffer
+= bytes
)
6692 DEBUG_printf(("9ipp_read_http: tbytes=%d, http->state=%d", tbytes
,
6695 if (http
->state
== HTTP_WAITING
)
6698 if (http
->used
== 0 && !http
->blocking
)
6701 * Wait up to 10 seconds for more data on non-blocking sockets...
6704 if (!httpWait(http
, 10000))
6715 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- tbytes
)) < 0)
6720 if (errno
!= EAGAIN
&& errno
!= EINTR
)
6726 else if (bytes
== 0)
6731 * Return the number of bytes read...
6734 if (tbytes
== 0 && bytes
< 0)
6737 DEBUG_printf(("8ipp_read_http: Returning %d bytes", tbytes
));
6744 * 'ipp_read_file()' - Read IPP data from a file.
6747 static ssize_t
/* O - Number of bytes read */
6748 ipp_read_file(int *fd
, /* I - File descriptor */
6749 ipp_uchar_t
*buffer
, /* O - Read buffer */
6750 size_t length
) /* I - Number of bytes to read */
6753 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
6755 return (read(*fd
, buffer
, length
));
6761 * 'ipp_set_error()' - Set a formatted, localized error string.
6765 ipp_set_error(ipp_status_t status
, /* I - Status code */
6766 const char *format
, /* I - Printf-style error string */
6767 ...) /* I - Additional arguments as needed */
6769 va_list ap
; /* Pointer to additional args */
6770 char buffer
[2048]; /* Message buffer */
6771 cups_lang_t
*lang
= cupsLangDefault();
6772 /* Current language */
6775 va_start(ap
, format
);
6776 vsnprintf(buffer
, sizeof(buffer
), _cupsLangString(lang
, format
), ap
);
6779 _cupsSetError(status
, buffer
, 0);
6784 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as
6788 static _ipp_value_t
* /* O - IPP value element or NULL on error */
6789 ipp_set_value(ipp_t
*ipp
, /* IO - IPP message */
6790 ipp_attribute_t
**attr
, /* IO - IPP attribute */
6791 int element
) /* I - Value number (0-based) */
6793 ipp_attribute_t
*temp
, /* New attribute pointer */
6794 *current
, /* Current attribute in list */
6795 *prev
; /* Previous attribute in list */
6796 int alloc_values
; /* Allocated values */
6800 * If we are setting an existing value element, return it...
6805 if (temp
->num_values
<= 1)
6808 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) &
6809 ~(IPP_MAX_VALUES
- 1);
6811 if (element
< alloc_values
)
6813 if (element
>= temp
->num_values
)
6814 temp
->num_values
= element
+ 1;
6816 return (temp
->values
+ element
);
6820 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE
6821 * values when num_values > 1.
6824 if (alloc_values
< IPP_MAX_VALUES
)
6825 alloc_values
= IPP_MAX_VALUES
;
6827 alloc_values
+= IPP_MAX_VALUES
;
6829 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.",
6833 * Reallocate memory...
6836 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) +
6837 (alloc_values
- 1) * sizeof(_ipp_value_t
))) == NULL
)
6839 _cupsSetHTTPError(HTTP_ERROR
);
6840 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
6845 * Zero the new memory...
6848 memset(temp
->values
+ temp
->num_values
, 0,
6849 (alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
6854 * Reset pointers in the list...
6857 if (ipp
->current
== *attr
&& ipp
->prev
)
6860 * Use current "previous" pointer...
6868 * Find this attribute in the linked list...
6871 for (prev
= NULL
, current
= ipp
->attrs
;
6872 current
&& current
!= *attr
;
6873 prev
= current
, current
= current
->next
);
6878 * This is a serious error!
6882 _cupsSetError(IPP_INTERNAL_ERROR
,
6883 _("IPP attribute is not a member of the message."), 1);
6884 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
6894 ipp
->current
= temp
;
6897 if (ipp
->last
== *attr
)
6904 * Return the value element...
6907 if (element
>= temp
->num_values
)
6908 temp
->num_values
= element
+ 1;
6910 return (temp
->values
+ element
);
6915 * 'ipp_write_file()' - Write IPP data to a file.
6918 static ssize_t
/* O - Number of bytes written */
6919 ipp_write_file(int *fd
, /* I - File descriptor */
6920 ipp_uchar_t
*buffer
, /* I - Data to write */
6921 size_t length
) /* I - Number of bytes to write */
6924 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
6926 return (write(*fd
, buffer
, length
));
6932 * End of "$Id: ipp.c 10102 2011-11-02 23:52:39Z mike $".