2 * "$Id: ipp.c 10102 2011-11-02 23:52:39Z mike $"
4 * Internet Printing Protocol functions for CUPS.
6 * Copyright 2007-2011 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 * ippAddBoolean() - Add a boolean attribute to an IPP message.
20 * ippAddBooleans() - Add an array of boolean values.
21 * ippAddCollection() - Add a collection value.
22 * ippAddCollections() - Add an array of collection values.
23 * ippAddDate() - Add a date attribute to an IPP message.
24 * ippAddInteger() - Add a integer attribute to an IPP message.
25 * ippAddIntegers() - Add an array of integer values.
26 * ippAddOctetString() - Add an octetString value to an IPP message.
27 * ippAddOutOfBand() - Add an out-of-band value to an IPP message.
28 * ippAddRange() - Add a range of values to an IPP message.
29 * ippAddRanges() - Add ranges of values to an IPP message.
30 * ippAddResolution() - Add a resolution value to an IPP message.
31 * ippAddResolutions() - Add resolution values to an IPP message.
32 * ippAddSeparator() - Add a group separator to an IPP message.
33 * ippAddString() - Add a language-encoded string to an IPP message.
34 * ippAddStrings() - Add language-encoded strings to an IPP message.
35 * ippCopyAttribute() - Copy an attribute.
36 * ippCopyAttributes() - Copy attributes from one IPP message to another.
37 * ippDateToTime() - Convert from RFC 1903 Date/Time format to UNIX
39 * ippDelete() - Delete an IPP message.
40 * ippDeleteAttribute() - Delete a single attribute in an IPP message.
41 * ippDeleteValues() - Delete values in an attribute.
42 * ippFindAttribute() - Find a named attribute in a request...
43 * ippFindNextAttribute() - Find the next named attribute in a request...
44 * ippFirstAttribute() - Return the first attribute in the message.
45 * ippGetBoolean() - Get a boolean value for an attribute.
46 * ippGetCollection() - Get a collection value for an attribute.
47 * ippGetCount() - Get the number of values in an attribute.
48 * ippGetGroupTag() - Get the group associated with an attribute.
49 * ippGetInteger() - Get the integer/enum value for an attribute.
50 * ippGetName() - Get the attribute name.
51 * ippGetOperation() - Get the operation ID in an IPP message.
52 * ippGetRequestId() - Get the request ID from an IPP message.
53 * ippGetResolution() - Get a resolution value for an attribute.
54 * ippGetStatusCode() - Get the status code from an IPP response or event
56 * ippGetString() - Get the string and optionally the language code
58 * ippGetValueTag() - Get the value tag for an attribute.
59 * ippGetVersion() - Get the major and minor version number from an
61 * ippLength() - Compute the length of an IPP message.
62 * ippNextAttribute() - Return the next attribute in the message.
63 * ippNew() - Allocate a new IPP message.
64 * ippNewRequest() - Allocate a new IPP request message.
65 * ippRead() - Read data for an IPP message from a HTTP
67 * ippReadFile() - Read data for an IPP message from a file.
68 * ippReadIO() - Read data for an IPP message.
69 * ippSetBoolean() - Set a boolean value in an attribute.
70 * ippSetCollection() - Set a collection value in an attribute.
71 * ippSetGroupTag() - Set the group tag of an attribute.
72 * ippSetInteger() - Set an integer or enum value in an attribute.
73 * ippSetName() - Set the name of an attribute.
74 * ippSetOperation() - Set the operation ID in an IPP request message.
75 * ippSetRange() - Set a rangeOfInteger value in an attribute.
76 * ippSetRequestId() - Set the request ID in an IPP message.
77 * ippSetResolution() - Set a resolution value in an attribute.
78 * ippSetStatusCode() - Set the status code in an IPP response or event
80 * ippSetString() - Set a string value in an attribute.
81 * ippSetValueTag() - Set the value tag of an attribute.
82 * ippSetVersion() - Set the version number in an IPP message.
83 * ippTimeToDate() - Convert from UNIX time to RFC 1903 format.
84 * ippWrite() - Write data for an IPP message to a HTTP
86 * ippWriteFile() - Write data for an IPP message to a file.
87 * ippWriteIO() - Write data for an IPP message.
88 * ipp_add_attr() - Add a new attribute to the message.
89 * ipp_buffer_get() - Get a read/write buffer.
90 * ipp_buffer_release() - Release a read/write buffer.
91 * ipp_free_values() - Free attribute values.
92 * ipp_get_code() - Convert a C locale/charset name into an IPP
93 * language/charset code.
94 * ipp_lang_code() - Convert a C locale name into an IPP language
96 * ipp_length() - Compute the length of an IPP message or
98 * ipp_read_http() - Semi-blocking read on a HTTP connection...
99 * ipp_read_file() - Read IPP data from a file.
100 * ipp_set_value() - Get the value element from an attribute,
101 * expanding it as needed.
102 * ipp_write_file() - Write IPP data to a file.
106 * Include necessary headers...
109 #include "cups-private.h"
119 static ipp_attribute_t
*ipp_add_attr(ipp_t
*ipp
, const char *name
, ipp_tag_t group_tag
,
120 ipp_tag_t value_tag
, int num_values
);
121 static unsigned char *ipp_buffer_get(void);
122 static void ipp_buffer_release(unsigned char *b
);
123 static void ipp_free_values(ipp_attribute_t
*attr
, int element
, int count
);
124 static char *ipp_get_code(const char *locale
, char *buffer
, size_t bufsize
);
125 static char *ipp_lang_code(const char *locale
, char *buffer
, size_t bufsize
);
126 static size_t ipp_length(ipp_t
*ipp
, int collection
);
127 static ssize_t
ipp_read_http(http_t
*http
, ipp_uchar_t
*buffer
,
129 static ssize_t
ipp_read_file(int *fd
, ipp_uchar_t
*buffer
,
131 static _ipp_value_t
*ipp_set_value(ipp_t
*ipp
, ipp_attribute_t
**attr
, int element
);
132 static ssize_t
ipp_write_file(int *fd
, ipp_uchar_t
*buffer
,
137 * 'ippAddBoolean()' - Add a boolean attribute to an IPP message.
139 * The @code ipp@ parameter refers to an IPP message previously created using the
140 * @link ippNew@ or @link ippNewRequest@ functions.
142 * The @code group@ parameter specifies the IPP attribute group tag: none
143 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
144 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
145 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
146 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
149 ipp_attribute_t
* /* O - New attribute */
150 ippAddBoolean(ipp_t
*ipp
, /* I - IPP message */
151 ipp_tag_t group
, /* I - IPP group */
152 const char *name
, /* I - Name of attribute */
153 char value
) /* I - Value of attribute */
155 ipp_attribute_t
*attr
; /* New attribute */
158 DEBUG_printf(("ippAddBoolean(ipp=%p, group=%02x(%s), name=\"%s\", value=%d)",
159 ipp
, group
, ippTagString(group
), name
, value
));
162 * Range check input...
165 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
166 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
170 * Create the attribute...
173 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, 1)) == NULL
)
176 attr
->values
[0].boolean
= value
;
183 * 'ippAddBooleans()' - Add an array of boolean values.
185 * The @code ipp@ parameter refers to an IPP message previously created using the
186 * @link ippNew@ or @link ippNewRequest@ functions.
188 * The @code group@ parameter specifies the IPP attribute group tag: none
189 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
190 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
191 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
192 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
195 ipp_attribute_t
* /* O - New attribute */
196 ippAddBooleans(ipp_t
*ipp
, /* I - IPP message */
197 ipp_tag_t group
, /* I - IPP group */
198 const char *name
, /* I - Name of attribute */
199 int num_values
, /* I - Number of values */
200 const char *values
) /* I - Values */
202 int i
; /* Looping var */
203 ipp_attribute_t
*attr
; /* New attribute */
204 _ipp_value_t
*value
; /* Current value */
207 DEBUG_printf(("ippAddBooleans(ipp=%p, group=%02x(%s), name=\"%s\", "
208 "num_values=%d, values=%p)", ipp
, group
, ippTagString(group
),
209 name
, num_values
, values
));
212 * Range check input...
215 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
216 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
221 * Create the attribute...
224 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BOOLEAN
, num_values
)) == NULL
)
229 for (i
= num_values
, value
= attr
->values
;
232 value
->boolean
= *values
++;
240 * 'ippAddCollection()' - Add a collection value.
242 * The @code ipp@ parameter refers to an IPP message previously created using the
243 * @link ippNew@ or @link ippNewRequest@ functions.
245 * The @code group@ parameter specifies the IPP attribute group tag: none
246 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
247 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
248 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
249 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
251 * @since CUPS 1.1.19/Mac OS X 10.3@
254 ipp_attribute_t
* /* O - New attribute */
255 ippAddCollection(ipp_t
*ipp
, /* I - IPP message */
256 ipp_tag_t group
, /* I - IPP group */
257 const char *name
, /* I - Name of attribute */
258 ipp_t
*value
) /* I - Value */
260 ipp_attribute_t
*attr
; /* New attribute */
263 DEBUG_printf(("ippAddCollection(ipp=%p, group=%02x(%s), name=\"%s\", "
264 "value=%p)", ipp
, group
, ippTagString(group
), name
, value
));
267 * Range check input...
270 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
271 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
275 * Create the attribute...
278 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
, 1)) == NULL
)
281 attr
->values
[0].collection
= value
;
290 * 'ippAddCollections()' - Add an array of collection values.
292 * The @code ipp@ parameter refers to an IPP message previously created using the
293 * @link ippNew@ or @link ippNewRequest@ functions.
295 * The @code group@ parameter specifies the IPP attribute group tag: none
296 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
297 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
298 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
299 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
301 * @since CUPS 1.1.19/Mac OS X 10.3@
304 ipp_attribute_t
* /* O - New attribute */
306 ipp_t
*ipp
, /* I - IPP message */
307 ipp_tag_t group
, /* I - IPP group */
308 const char *name
, /* I - Name of attribute */
309 int num_values
, /* I - Number of values */
310 const ipp_t
**values
) /* I - Values */
312 int i
; /* Looping var */
313 ipp_attribute_t
*attr
; /* New attribute */
314 _ipp_value_t
*value
; /* Current value */
317 DEBUG_printf(("ippAddCollections(ipp=%p, group=%02x(%s), name=\"%s\", "
318 "num_values=%d, values=%p)", ipp
, group
, ippTagString(group
),
319 name
, num_values
, values
));
322 * Range check input...
325 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
326 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
331 * Create the attribute...
334 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_BEGIN_COLLECTION
,
335 num_values
)) == NULL
)
340 for (i
= num_values
, value
= attr
->values
;
344 value
->collection
= (ipp_t
*)*values
++;
345 value
->collection
->use
++;
354 * 'ippAddDate()' - Add a date attribute to an IPP message.
356 * The @code ipp@ parameter refers to an IPP message previously created using the
357 * @link ippNew@ or @link ippNewRequest@ functions.
359 * The @code group@ parameter specifies the IPP attribute group tag: none
360 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
361 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
362 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
363 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
366 ipp_attribute_t
* /* O - New attribute */
367 ippAddDate(ipp_t
*ipp
, /* I - IPP message */
368 ipp_tag_t group
, /* I - IPP group */
369 const char *name
, /* I - Name of attribute */
370 const ipp_uchar_t
*value
) /* I - Value */
372 ipp_attribute_t
*attr
; /* New attribute */
375 DEBUG_printf(("ippAddDate(ipp=%p, group=%02x(%s), name=\"%s\", value=%p)",
376 ipp
, group
, ippTagString(group
), name
, value
));
379 * Range check input...
382 if (!ipp
|| !name
|| !value
|| group
< IPP_TAG_ZERO
||
383 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
387 * Create the attribute...
390 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_DATE
, 1)) == NULL
)
393 memcpy(attr
->values
[0].date
, value
, 11);
400 * 'ippAddInteger()' - Add a integer attribute to an IPP message.
402 * The @code ipp@ parameter refers to an IPP message previously created using the
403 * @link ippNew@ or @link ippNewRequest@ functions.
405 * The @code group@ parameter specifies the IPP attribute group tag: none
406 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
407 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
408 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
409 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
411 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
412 * (@code IPP_TAG_INTEGER@).
415 ipp_attribute_t
* /* O - New attribute */
416 ippAddInteger(ipp_t
*ipp
, /* I - IPP message */
417 ipp_tag_t group
, /* I - IPP group */
418 ipp_tag_t value_tag
, /* I - Type of attribute */
419 const char *name
, /* I - Name of attribute */
420 int value
) /* I - Value of attribute */
422 ipp_attribute_t
*attr
; /* New attribute */
425 DEBUG_printf(("ippAddInteger(ipp=%p, group=%02x(%s), type=%02x(%s), "
426 "name=\"%s\", value=%d)", ipp
, group
, ippTagString(group
),
427 value_tag
, ippTagString(value_tag
), name
, value
));
429 value_tag
&= IPP_TAG_MASK
;
432 * Special-case for legacy usage: map out-of-band attributes to new ippAddOutOfBand
436 if (value_tag
>= IPP_TAG_UNSUPPORTED_VALUE
&& value_tag
<= IPP_TAG_ADMINDEFINE
)
437 return (ippAddOutOfBand(ipp
, group
, value_tag
, name
));
440 * Range check input...
444 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
445 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
446 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
))
449 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
450 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
455 * Create the attribute...
458 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
461 attr
->values
[0].integer
= value
;
468 * 'ippAddIntegers()' - Add an array of integer values.
470 * The @code ipp@ parameter refers to an IPP message previously created using the
471 * @link ippNew@ or @link ippNewRequest@ functions.
473 * The @code group@ parameter specifies the IPP attribute group tag: none
474 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
475 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
476 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
477 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
479 * Supported values include enum (@code IPP_TAG_ENUM@) and integer
480 * (@code IPP_TAG_INTEGER@).
483 ipp_attribute_t
* /* O - New attribute */
484 ippAddIntegers(ipp_t
*ipp
, /* I - IPP message */
485 ipp_tag_t group
, /* I - IPP group */
486 ipp_tag_t value_tag
, /* I - Type of attribute */
487 const char *name
, /* I - Name of attribute */
488 int num_values
, /* I - Number of values */
489 const int *values
) /* I - Values */
491 int i
; /* Looping var */
492 ipp_attribute_t
*attr
; /* New attribute */
493 _ipp_value_t
*value
; /* Current value */
496 DEBUG_printf(("ippAddIntegers(ipp=%p, group=%02x(%s), type=%02x(%s), "
497 "name=\"%s\", num_values=%d, values=%p)", ipp
,
498 group
, ippTagString(group
), value_tag
, ippTagString(value_tag
), name
,
499 num_values
, values
));
501 value_tag
&= IPP_TAG_MASK
;
504 * Range check input...
508 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
509 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
510 (value_tag
!= IPP_TAG_INTEGER
&& value_tag
!= IPP_TAG_ENUM
) ||
514 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
515 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
521 * Create the attribute...
524 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
529 for (i
= num_values
, value
= attr
->values
;
532 value
->integer
= *values
++;
540 * 'ippAddOctetString()' - Add an octetString value to an IPP message.
542 * The @code ipp@ parameter refers to an IPP message previously created using the
543 * @link ippNew@ or @link ippNewRequest@ functions.
545 * The @code group@ parameter specifies the IPP attribute group tag: none
546 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
547 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
548 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
549 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
551 * @since CUPS 1.2/Mac OS X 10.5@
554 ipp_attribute_t
* /* O - New attribute */
555 ippAddOctetString(ipp_t
*ipp
, /* I - IPP message */
556 ipp_tag_t group
, /* I - IPP group */
557 const char *name
, /* I - Name of attribute */
558 const void *data
, /* I - octetString data */
559 int datalen
) /* I - Length of data in bytes */
561 ipp_attribute_t
*attr
; /* New attribute */
564 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
565 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
568 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_STRING
, 1)) == NULL
)
572 * Initialize the attribute data...
575 attr
->values
[0].unknown
.length
= datalen
;
579 if ((attr
->values
[0].unknown
.data
= malloc(datalen
)) == NULL
)
581 ippDeleteAttribute(ipp
, attr
);
585 memcpy(attr
->values
[0].unknown
.data
, data
, datalen
);
589 * Return the new attribute...
597 * 'ippAddOutOfBand()' - Add an out-of-band value to an IPP message.
599 * The @code ipp@ parameter refers to an IPP message previously created using the
600 * @link ippNew@ or @link ippNewRequest@ functions.
602 * The @code group@ parameter specifies the IPP attribute group tag: none
603 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
604 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
605 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
606 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
608 * Supported out-of-band values include unsupported-value
609 * (@code IPP_TAG_UNSUPPORTED_VALUE@), default (@code IPP_TAG_DEFAULT@), unknown
610 * (@code IPP_TAG_UNKNOWN@), no-value (@code IPP_TAG_NOVALUE@), not-settable
611 * (@code IPP_TAG_NOTSETTABLE@), delete-attribute (@code IPP_TAG_DELETEATTR@), and
612 * admin-define (@code IPP_TAG_ADMINDEFINE@).
617 ipp_attribute_t
* /* O - New attribute */
618 ippAddOutOfBand(ipp_t
*ipp
, /* I - IPP message */
619 ipp_tag_t group
, /* I - IPP group */
620 ipp_tag_t value_tag
, /* I - Type of attribute */
621 const char *name
) /* I - Name of attribute */
623 DEBUG_printf(("ippAddOutOfBand(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
624 "name=\"%s\")", ipp
, group
, ippTagString(group
), value_tag
,
625 ippTagString(value_tag
), name
));
627 value_tag
&= IPP_TAG_MASK
;
630 * Range check input...
633 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
634 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
635 (value_tag
!= IPP_TAG_UNSUPPORTED_VALUE
&&
636 value_tag
!= IPP_TAG_DEFAULT
&&
637 value_tag
!= IPP_TAG_UNKNOWN
&&
638 value_tag
!= IPP_TAG_NOVALUE
&&
639 value_tag
!= IPP_TAG_NOTSETTABLE
&&
640 value_tag
!= IPP_TAG_DELETEATTR
&&
641 value_tag
!= IPP_TAG_ADMINDEFINE
))
645 * Create the attribute...
648 return (ipp_add_attr(ipp
, name
, group
, value_tag
, 1));
653 * 'ippAddRange()' - Add a range of values to an IPP message.
655 * The @code ipp@ parameter refers to an IPP message previously created using the
656 * @link ippNew@ or @link ippNewRequest@ functions.
658 * The @code group@ parameter specifies the IPP attribute group tag: none
659 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
660 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
661 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
662 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
664 * The @code lower@ parameter must be less than or equal to the @code upper@ parameter.
667 ipp_attribute_t
* /* O - New attribute */
668 ippAddRange(ipp_t
*ipp
, /* I - IPP message */
669 ipp_tag_t group
, /* I - IPP group */
670 const char *name
, /* I - Name of attribute */
671 int lower
, /* I - Lower value */
672 int upper
) /* I - Upper value */
674 ipp_attribute_t
*attr
; /* New attribute */
677 DEBUG_printf(("ippAddRange(ipp=%p, group=%02x(%s), name=\"%s\", lower=%d, "
678 "upper=%d)", ipp
, group
, ippTagString(group
), name
, lower
,
682 * Range check input...
685 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
686 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
690 * Create the attribute...
693 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, 1)) == NULL
)
696 attr
->values
[0].range
.lower
= lower
;
697 attr
->values
[0].range
.upper
= upper
;
704 * 'ippAddRanges()' - Add ranges of values to an IPP message.
706 * The @code ipp@ parameter refers to an IPP message previously created using the
707 * @link ippNew@ or @link ippNewRequest@ functions.
709 * The @code group@ parameter specifies the IPP attribute group tag: none
710 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
711 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
712 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
713 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
716 ipp_attribute_t
* /* O - New attribute */
717 ippAddRanges(ipp_t
*ipp
, /* I - IPP message */
718 ipp_tag_t group
, /* I - IPP group */
719 const char *name
, /* I - Name of attribute */
720 int num_values
, /* I - Number of values */
721 const int *lower
, /* I - Lower values */
722 const int *upper
) /* I - Upper values */
724 int i
; /* Looping var */
725 ipp_attribute_t
*attr
; /* New attribute */
726 _ipp_value_t
*value
; /* Current value */
729 DEBUG_printf(("ippAddRanges(ipp=%p, group=%02x(%s), name=\"%s\", "
730 "num_values=%d, lower=%p, upper=%p)", ipp
, group
,
731 ippTagString(group
), name
, num_values
, lower
, upper
));
734 * Range check input...
737 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
738 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
743 * Create the attribute...
746 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RANGE
, num_values
)) == NULL
)
751 for (i
= num_values
, value
= attr
->values
;
755 value
->range
.lower
= *lower
++;
756 value
->range
.upper
= *upper
++;
765 * 'ippAddResolution()' - Add a resolution value to an IPP message.
767 * The @code ipp@ parameter refers to an IPP message previously created using the
768 * @link ippNew@ or @link ippNewRequest@ functions.
770 * The @code group@ parameter specifies the IPP attribute group tag: none
771 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
772 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
773 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
774 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
777 ipp_attribute_t
* /* O - New attribute */
778 ippAddResolution(ipp_t
*ipp
, /* I - IPP message */
779 ipp_tag_t group
, /* I - IPP group */
780 const char *name
, /* I - Name of attribute */
781 ipp_res_t units
, /* I - Units for resolution */
782 int xres
, /* I - X resolution */
783 int yres
) /* I - Y resolution */
785 ipp_attribute_t
*attr
; /* New attribute */
788 DEBUG_printf(("ippAddResolution(ipp=%p, group=%02x(%s), name=\"%s\", "
789 "units=%d, xres=%d, yres=%d)", ipp
, group
,
790 ippTagString(group
), name
, units
, xres
, yres
));
793 * Range check input...
796 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
797 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
798 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
||
799 xres
< 0 || yres
< 0)
803 * Create the attribute...
806 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, 1)) == NULL
)
809 attr
->values
[0].resolution
.xres
= xres
;
810 attr
->values
[0].resolution
.yres
= yres
;
811 attr
->values
[0].resolution
.units
= units
;
818 * 'ippAddResolutions()' - Add resolution values to an IPP message.
820 * The @code ipp@ parameter refers to an IPP message previously created using the
821 * @link ippNew@ or @link ippNewRequest@ functions.
823 * The @code group@ parameter specifies the IPP attribute group tag: none
824 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
825 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
826 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
827 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
830 ipp_attribute_t
* /* O - New attribute */
831 ippAddResolutions(ipp_t
*ipp
, /* I - IPP message */
832 ipp_tag_t group
, /* I - IPP group */
833 const char *name
, /* I - Name of attribute */
834 int num_values
,/* I - Number of values */
835 ipp_res_t units
, /* I - Units for resolution */
836 const int *xres
, /* I - X resolutions */
837 const int *yres
) /* I - Y resolutions */
839 int i
; /* Looping var */
840 ipp_attribute_t
*attr
; /* New attribute */
841 _ipp_value_t
*value
; /* Current value */
844 DEBUG_printf(("ippAddResolutions(ipp=%p, group=%02x(%s), name=\"%s\", "
845 "num_value=%d, units=%d, xres=%p, yres=%p)", ipp
, group
,
846 ippTagString(group
), name
, num_values
, units
, xres
, yres
));
849 * Range check input...
852 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
853 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
855 units
< IPP_RES_PER_INCH
|| units
> IPP_RES_PER_CM
)
859 * Create the attribute...
862 if ((attr
= ipp_add_attr(ipp
, name
, group
, IPP_TAG_RESOLUTION
, num_values
)) == NULL
)
867 for (i
= num_values
, value
= attr
->values
;
871 value
->resolution
.xres
= *xres
++;
872 value
->resolution
.yres
= *yres
++;
873 value
->resolution
.units
= units
;
882 * 'ippAddSeparator()' - Add a group separator to an IPP message.
884 * The @code ipp@ parameter refers to an IPP message previously created using the
885 * @link ippNew@ or @link ippNewRequest@ functions.
888 ipp_attribute_t
* /* O - New attribute */
889 ippAddSeparator(ipp_t
*ipp
) /* I - IPP message */
891 DEBUG_printf(("ippAddSeparator(ipp=%p)", ipp
));
894 * Range check input...
901 * Create the attribute...
904 return (ipp_add_attr(ipp
, NULL
, IPP_TAG_ZERO
, IPP_TAG_ZERO
, 0));
909 * 'ippAddString()' - Add a language-encoded string to an IPP message.
911 * The @code ipp@ parameter refers to an IPP message previously created using the
912 * @link ippNew@ or @link ippNewRequest@ functions.
914 * The @code group@ parameter specifies the IPP attribute group tag: none
915 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
916 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
917 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
918 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
920 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
921 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
922 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
923 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
924 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
925 * (@code IPP_TAG_URISCHEME@).
927 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
928 * textWithLanguage string values and must be @code NULL@ for all other string values.
931 ipp_attribute_t
* /* O - New attribute */
932 ippAddString(ipp_t
*ipp
, /* I - IPP message */
933 ipp_tag_t group
, /* I - IPP group */
934 ipp_tag_t value_tag
, /* I - Type of attribute */
935 const char *name
, /* I - Name of attribute */
936 const char *language
, /* I - Language code */
937 const char *value
) /* I - Value */
939 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
940 ipp_attribute_t
*attr
; /* New attribute */
941 char code
[32]; /* Charset/language code buffer */
944 DEBUG_printf(("ippAddString(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
945 "name=\"%s\", language=\"%s\", value=\"%s\")", ipp
,
946 group
, ippTagString(group
), value_tag
, ippTagString(value_tag
), name
,
950 * Range check input...
953 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_MASK
);
956 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
957 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
958 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
959 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
)
962 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
963 != (language
!= NULL
))
966 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
967 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
)
972 * See if we need to map charset, language, or locale values...
975 if (language
&& ((int)value_tag
& IPP_TAG_COPY
) &&
976 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
977 value_tag
= temp_tag
; /* Don't do a fast copy */
978 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_COPY
) &&
979 strcmp(value
, ipp_get_code(value
, code
, sizeof(code
))))
980 value_tag
= temp_tag
; /* Don't do a fast copy */
981 else if (value
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_COPY
) &&
982 strcmp(value
, ipp_lang_code(value
, code
, sizeof(code
))))
983 value_tag
= temp_tag
; /* Don't do a fast copy */
986 * Create the attribute...
989 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, 1)) == NULL
)
993 * Initialize the attribute data...
996 if ((int)value_tag
& IPP_TAG_COPY
)
998 attr
->values
[0].string
.language
= (char *)language
;
999 attr
->values
[0].string
.text
= (char *)value
;
1004 attr
->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1007 if (value_tag
== IPP_TAG_CHARSET
)
1008 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_get_code(value
, code
,
1010 else if (value_tag
== IPP_TAG_LANGUAGE
)
1011 attr
->values
[0].string
.text
= _cupsStrAlloc(ipp_lang_code(value
, code
,
1014 attr
->values
[0].string
.text
= _cupsStrAlloc(value
);
1022 * 'ippAddStrings()' - Add language-encoded strings to an IPP message.
1024 * The @code ipp@ parameter refers to an IPP message previously created using the
1025 * @link ippNew@ or @link ippNewRequest@ functions.
1027 * The @code group@ parameter specifies the IPP attribute group tag: none
1028 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
1029 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
1030 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
1031 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
1033 * Supported string values include charset (@code IPP_TAG_CHARSET@), keyword
1034 * (@code IPP_TAG_KEYWORD@), language (@code IPP_TAG_LANGUAGE@), mimeMediaType
1035 * (@code IPP_TAG_MIMETYPE@), name (@code IPP_TAG_NAME@), nameWithLanguage
1036 * (@code IPP_TAG_NAMELANG), text (@code IPP_TAG_TEXT@), textWithLanguage
1037 * (@code IPP_TAG_TEXTLANG@), uri (@code IPP_TAG_URI@), and uriScheme
1038 * (@code IPP_TAG_URISCHEME@).
1040 * The @code language@ parameter must be non-@code NULL@ for nameWithLanguage and
1041 * textWithLanguage string values and must be @code NULL@ for all other string values.
1044 ipp_attribute_t
* /* O - New attribute */
1046 ipp_t
*ipp
, /* I - IPP message */
1047 ipp_tag_t group
, /* I - IPP group */
1048 ipp_tag_t value_tag
, /* I - Type of attribute */
1049 const char *name
, /* I - Name of attribute */
1050 int num_values
, /* I - Number of values */
1051 const char *language
, /* I - Language code (@code NULL@ for default) */
1052 const char * const *values
) /* I - Values */
1054 int i
; /* Looping var */
1055 ipp_tag_t temp_tag
; /* Temporary value tag (masked) */
1056 ipp_attribute_t
*attr
; /* New attribute */
1057 _ipp_value_t
*value
; /* Current value */
1058 char code
[32]; /* Language/charset value buffer */
1061 DEBUG_printf(("ippAddStrings(ipp=%p, group=%02x(%s), value_tag=%02x(%s), "
1062 "name=\"%s\", num_values=%d, language=\"%s\", values=%p)", ipp
,
1063 group
, ippTagString(group
), value_tag
, ippTagString(value_tag
), name
,
1064 num_values
, language
, values
));
1067 * Range check input...
1070 temp_tag
= (ipp_tag_t
)((int)value_tag
& IPP_TAG_MASK
);
1073 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1074 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1075 (temp_tag
< IPP_TAG_TEXT
&& temp_tag
!= IPP_TAG_TEXTLANG
&&
1076 temp_tag
!= IPP_TAG_NAMELANG
) || temp_tag
> IPP_TAG_MIMETYPE
||
1080 if ((temp_tag
== IPP_TAG_TEXTLANG
|| temp_tag
== IPP_TAG_NAMELANG
)
1081 != (language
!= NULL
))
1084 if (!ipp
|| !name
|| group
< IPP_TAG_ZERO
||
1085 group
== IPP_TAG_END
|| group
>= IPP_TAG_UNSUPPORTED_VALUE
||
1091 * See if we need to map charset, language, or locale values...
1094 if (language
&& ((int)value_tag
& IPP_TAG_COPY
) &&
1095 strcmp(language
, ipp_lang_code(language
, code
, sizeof(code
))))
1096 value_tag
= temp_tag
; /* Don't do a fast copy */
1097 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_CHARSET
| IPP_TAG_COPY
))
1099 for (i
= 0; i
< num_values
; i
++)
1100 if (strcmp(values
[i
], ipp_get_code(values
[i
], code
, sizeof(code
))))
1102 value_tag
= temp_tag
; /* Don't do a fast copy */
1106 else if (values
&& value_tag
== (ipp_tag_t
)(IPP_TAG_LANGUAGE
| IPP_TAG_COPY
))
1108 for (i
= 0; i
< num_values
; i
++)
1109 if (strcmp(values
[i
], ipp_lang_code(values
[i
], code
, sizeof(code
))))
1111 value_tag
= temp_tag
; /* Don't do a fast copy */
1117 * Create the attribute...
1120 if ((attr
= ipp_add_attr(ipp
, name
, group
, value_tag
, num_values
)) == NULL
)
1124 * Initialize the attribute data...
1127 for (i
= num_values
, value
= attr
->values
;
1133 if (value
== attr
->values
)
1135 if ((int)value_tag
& IPP_TAG_COPY
)
1136 value
->string
.language
= (char *)language
;
1138 value
->string
.language
= _cupsStrAlloc(ipp_lang_code(language
, code
,
1142 value
->string
.language
= attr
->values
[0].string
.language
;
1147 if ((int)value_tag
& IPP_TAG_COPY
)
1148 value
->string
.text
= (char *)*values
++;
1149 else if (value_tag
== IPP_TAG_CHARSET
)
1150 value
->string
.text
= _cupsStrAlloc(ipp_get_code(*values
++, code
, sizeof(code
)));
1151 else if (value_tag
== IPP_TAG_LANGUAGE
)
1152 value
->string
.text
= _cupsStrAlloc(ipp_lang_code(*values
++, code
, sizeof(code
)));
1154 value
->string
.text
= _cupsStrAlloc(*values
++);
1163 * 'ippCopyAttribute()' - Copy an attribute.
1165 * The specified attribute, @code attr@, is copied to the destination IPP message.
1166 * When @code quickcopy@ is non-zero, a "shallow" reference copy of the attribute is
1167 * created - this should only be done as long as the original source IPP message will
1168 * not be freed for the life of the destination.
1174 ipp_attribute_t
* /* O - New attribute */
1176 ipp_t
*dst
, /* I - Destination IPP message */
1177 ipp_attribute_t
*srcattr
, /* I - Attribute to copy */
1178 int quickcopy
) /* I - 1 for a referenced copy, 0 for normal */
1180 int i
; /* Looping var */
1181 ipp_attribute_t
*dstattr
; /* Destination attribute */
1182 _ipp_value_t
*srcval
, /* Source value */
1183 *dstval
; /* Destination value */
1186 DEBUG_printf(("ippCopyAttribute(dst=%p, srcattr=%p, quickcopy=%d)", dst
, srcattr
,
1190 * Range check input...
1193 if (!dst
|| !srcattr
)
1200 quickcopy
= quickcopy
? IPP_TAG_COPY
: 0;
1202 switch (srcattr
->value_tag
& ~IPP_TAG_COPY
)
1205 dstattr
= ippAddSeparator(dst
);
1208 case IPP_TAG_INTEGER
:
1210 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1211 srcattr
->name
, srcattr
->num_values
, NULL
);
1215 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1217 i
--, srcval
++, dstval
++)
1218 dstval
->integer
= srcval
->integer
;
1221 case IPP_TAG_BOOLEAN
:
1222 dstattr
= ippAddBooleans(dst
, srcattr
->group_tag
, srcattr
->name
,
1223 srcattr
->num_values
, NULL
);
1227 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1229 i
--, srcval
++, dstval
++)
1230 dstval
->boolean
= srcval
->boolean
;
1235 case IPP_TAG_KEYWORD
:
1237 case IPP_TAG_URISCHEME
:
1238 case IPP_TAG_CHARSET
:
1239 case IPP_TAG_LANGUAGE
:
1240 case IPP_TAG_MIMETYPE
:
1241 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1242 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1243 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1249 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1250 dstval
= dstattr
->values
;
1252 i
--, srcval
++, dstval
++)
1253 dstval
->string
.text
= srcval
->string
.text
;
1255 else if (srcattr
->value_tag
& IPP_TAG_COPY
)
1257 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1258 dstval
= dstattr
->values
;
1260 i
--, srcval
++, dstval
++)
1261 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1265 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1266 dstval
= dstattr
->values
;
1268 i
--, srcval
++, dstval
++)
1269 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1274 if (srcattr
->num_values
!= 1)
1277 dstattr
= ippAddDate(dst
, srcattr
->group_tag
, srcattr
->name
,
1278 srcattr
->values
[0].date
);
1281 case IPP_TAG_RESOLUTION
:
1282 dstattr
= ippAddResolutions(dst
, srcattr
->group_tag
, srcattr
->name
,
1283 srcattr
->num_values
, IPP_RES_PER_INCH
,
1288 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1290 i
--, srcval
++, dstval
++)
1292 dstval
->resolution
.xres
= srcval
->resolution
.xres
;
1293 dstval
->resolution
.yres
= srcval
->resolution
.yres
;
1294 dstval
->resolution
.units
= srcval
->resolution
.units
;
1298 case IPP_TAG_RANGE
:
1299 dstattr
= ippAddRanges(dst
, srcattr
->group_tag
, srcattr
->name
,
1300 srcattr
->num_values
, NULL
, NULL
);
1304 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1306 i
--, srcval
++, dstval
++)
1308 dstval
->range
.lower
= srcval
->range
.lower
;
1309 dstval
->range
.upper
= srcval
->range
.upper
;
1313 case IPP_TAG_TEXTLANG
:
1314 case IPP_TAG_NAMELANG
:
1315 dstattr
= ippAddStrings(dst
, srcattr
->group_tag
,
1316 (ipp_tag_t
)(srcattr
->value_tag
| quickcopy
),
1317 srcattr
->name
, srcattr
->num_values
, NULL
, NULL
);
1323 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1324 dstval
= dstattr
->values
;
1326 i
--, srcval
++, dstval
++)
1328 dstval
->string
.language
= srcval
->string
.language
;
1329 dstval
->string
.text
= srcval
->string
.text
;
1332 else if (srcattr
->value_tag
& IPP_TAG_COPY
)
1334 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1335 dstval
= dstattr
->values
;
1337 i
--, srcval
++, dstval
++)
1339 if (srcval
== srcattr
->values
)
1340 dstval
->string
.language
= _cupsStrAlloc(srcval
->string
.language
);
1342 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1344 dstval
->string
.text
= _cupsStrAlloc(srcval
->string
.text
);
1349 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
,
1350 dstval
= dstattr
->values
;
1352 i
--, srcval
++, dstval
++)
1354 if (srcval
== srcattr
->values
)
1355 dstval
->string
.language
= _cupsStrRetain(srcval
->string
.language
);
1357 dstval
->string
.language
= dstattr
->values
[0].string
.language
;
1359 dstval
->string
.text
= _cupsStrRetain(srcval
->string
.text
);
1364 case IPP_TAG_BEGIN_COLLECTION
:
1365 dstattr
= ippAddCollections(dst
, srcattr
->group_tag
, srcattr
->name
,
1366 srcattr
->num_values
, NULL
);
1370 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1372 i
--, srcval
++, dstval
++)
1374 dstval
->collection
= srcval
->collection
;
1375 srcval
->collection
->use
++;
1379 case IPP_TAG_STRING
:
1381 /* TODO: Implement quick copy for unknown/octetString values */
1382 dstattr
= ippAddIntegers(dst
, srcattr
->group_tag
, srcattr
->value_tag
,
1383 srcattr
->name
, srcattr
->num_values
, NULL
);
1387 for (i
= srcattr
->num_values
, srcval
= srcattr
->values
, dstval
= dstattr
->values
;
1389 i
--, srcval
++, dstval
++)
1391 dstval
->unknown
.length
= srcval
->unknown
.length
;
1393 if (dstval
->unknown
.length
> 0)
1395 if ((dstval
->unknown
.data
= malloc(dstval
->unknown
.length
)) == NULL
)
1396 dstval
->unknown
.length
= 0;
1398 memcpy(dstval
->unknown
.data
, srcval
->unknown
.data
, dstval
->unknown
.length
);
1401 break; /* anti-compiler-warning-code */
1409 * 'ippCopyAttributes()' - Copy attributes from one IPP message to another.
1411 * Zero or more attributes are copied from the source IPP message, @code@ src, to the
1412 * destination IPP message, @code dst@. When @code quickcopy@ is non-zero, a "shallow"
1413 * reference copy of the attribute is created - this should only be done as long as the
1414 * original source IPP message will not be freed for the life of the destination.
1416 * The @code cb@ and @code context@ parameters provide a generic way to "filter" the
1417 * attributes that are copied - the function must return 1 to copy the attribute or
1418 * 0 to skip it. The function may also choose to do a partial copy of the source attribute
1424 int /* O - 1 on success, 0 on error */
1426 ipp_t
*dst
, /* I - Destination IPP message */
1427 ipp_t
*src
, /* I - Source IPP message */
1428 int quickcopy
, /* I - 1 for a referenced copy, 0 for normal */
1429 ipp_copycb_t cb
, /* I - Copy callback or @code NULL@ for none */
1430 void *context
) /* I - Context pointer */
1432 ipp_attribute_t
*srcattr
; /* Source attribute */
1435 DEBUG_printf(("ippCopyAttributes(dst=%p, src=%p, quickcopy=%d, cb=%p, context=%p)",
1436 dst
, src
, quickcopy
, cb
, context
));
1439 * Range check input...
1446 * Loop through source attributes and copy as needed...
1449 for (srcattr
= src
->attrs
; srcattr
; srcattr
= srcattr
->next
)
1450 if (!cb
|| (*cb
)(context
, dst
, srcattr
))
1451 if (!ippCopyAttribute(dst
, srcattr
, quickcopy
))
1459 * 'ippDateToTime()' - Convert from RFC 1903 Date/Time format to UNIX time
1463 time_t /* O - UNIX time value */
1464 ippDateToTime(const ipp_uchar_t
*date
) /* I - RFC 1903 date info */
1466 struct tm unixdate
; /* UNIX date/time info */
1467 time_t t
; /* Computed time */
1473 memset(&unixdate
, 0, sizeof(unixdate
));
1476 * RFC-1903 date/time format is:
1478 * Byte(s) Description
1479 * ------- -----------
1480 * 0-1 Year (0 to 65535)
1484 * 5 Minutes (0 to 59)
1485 * 6 Seconds (0 to 60, 60 = "leap second")
1486 * 7 Deciseconds (0 to 9)
1488 * 9 UTC hours (0 to 11)
1489 * 10 UTC minutes (0 to 59)
1492 unixdate
.tm_year
= ((date
[0] << 8) | date
[1]) - 1900;
1493 unixdate
.tm_mon
= date
[2] - 1;
1494 unixdate
.tm_mday
= date
[3];
1495 unixdate
.tm_hour
= date
[4];
1496 unixdate
.tm_min
= date
[5];
1497 unixdate
.tm_sec
= date
[6];
1499 t
= mktime(&unixdate
);
1502 t
+= date
[9] * 3600 + date
[10] * 60;
1504 t
-= date
[9] * 3600 + date
[10] * 60;
1511 * 'ippDelete()' - Delete an IPP message.
1515 ippDelete(ipp_t
*ipp
) /* I - IPP message */
1517 ipp_attribute_t
*attr
, /* Current attribute */
1518 *next
; /* Next attribute */
1521 DEBUG_printf(("ippDelete(ipp=%p)", ipp
));
1530 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= next
)
1534 ipp_free_values(attr
, 0, attr
->num_values
);
1537 _cupsStrFree(attr
->name
);
1547 * 'ippDeleteAttribute()' - Delete a single attribute in an IPP message.
1549 * @since CUPS 1.1.19/Mac OS X 10.3@
1554 ipp_t
*ipp
, /* I - IPP message */
1555 ipp_attribute_t
*attr
) /* I - Attribute to delete */
1557 ipp_attribute_t
*current
, /* Current attribute */
1558 *prev
; /* Previous attribute */
1561 DEBUG_printf(("ippDeleteAttribute(ipp=%p, attr=%p(%s))", ipp
, attr
,
1562 attr
? attr
->name
: "(null)"));
1565 * Range check input...
1572 * Find the attribute in the list...
1577 for (current
= ipp
->attrs
, prev
= NULL
;
1579 prev
= current
, current
= current
->next
)
1580 if (current
== attr
)
1583 * Found it, remove the attribute from the list...
1587 prev
->next
= current
->next
;
1589 ipp
->attrs
= current
->next
;
1591 if (current
== ipp
->last
)
1602 * Free memory used by the attribute...
1605 ipp_free_values(attr
, 0, attr
->num_values
);
1608 _cupsStrFree(attr
->name
);
1615 * 'ippDeleteValues()' - Delete values in an attribute.
1617 * The @code element@ parameter specifies the first value to delete, starting at 0. It
1618 * must be less than the number of values returned by @link ippGetCount@.
1620 * Deleting all values in an attribute deletes the attribute.
1625 int /* O - 1 on success, 0 on failure */
1627 ipp_t
*ipp
, /* I - IPP message */
1628 ipp_attribute_t
*attr
, /* I - Attribute */
1629 int element
, /* I - Index of first value to delete (0-based) */
1630 int count
) /* I - Number of values to delete */
1633 * Range check input...
1636 if (!ipp
|| !attr
|| element
< 0 || element
>= attr
->num_values
|| count
<= 0 ||
1637 (element
+ count
) >= attr
->num_values
)
1641 * If we are deleting all values, just delete the attribute entirely.
1644 if (count
== attr
->num_values
)
1646 ippDeleteAttribute(ipp
, attr
);
1651 * Otherwise free the values in question and return.
1654 ipp_free_values(attr
, element
, count
);
1661 * 'ippFindAttribute()' - Find a named attribute in a request...
1664 ipp_attribute_t
* /* O - Matching attribute */
1665 ippFindAttribute(ipp_t
*ipp
, /* I - IPP message */
1666 const char *name
, /* I - Name of attribute */
1667 ipp_tag_t type
) /* I - Type of attribute */
1669 DEBUG_printf(("2ippFindAttribute(ipp=%p, name=\"%s\", type=%02x(%s))", ipp
,
1670 name
, type
, ippTagString(type
)));
1676 * Reset the current pointer...
1679 ipp
->current
= NULL
;
1682 * Search for the attribute...
1685 return (ippFindNextAttribute(ipp
, name
, type
));
1690 * 'ippFindNextAttribute()' - Find the next named attribute in a request...
1693 ipp_attribute_t
* /* O - Matching attribute */
1694 ippFindNextAttribute(ipp_t
*ipp
, /* I - IPP message */
1695 const char *name
, /* I - Name of attribute */
1696 ipp_tag_t type
) /* I - Type of attribute */
1698 ipp_attribute_t
*attr
; /* Current atttribute */
1699 ipp_tag_t value_tag
; /* Value tag */
1702 DEBUG_printf(("2ippFindNextAttribute(ipp=%p, name=\"%s\", type=%02x(%s))",
1703 ipp
, name
, type
, ippTagString(type
)));
1710 ipp
->prev
= ipp
->current
;
1711 attr
= ipp
->current
->next
;
1719 for (; attr
!= NULL
; ipp
->prev
= attr
, attr
= attr
->next
)
1721 DEBUG_printf(("4ippFindAttribute: attr=%p, name=\"%s\"", attr
,
1724 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_MASK
);
1726 if (attr
->name
!= NULL
&& _cups_strcasecmp(attr
->name
, name
) == 0 &&
1727 (value_tag
== type
|| type
== IPP_TAG_ZERO
||
1728 (value_tag
== IPP_TAG_TEXTLANG
&& type
== IPP_TAG_TEXT
) ||
1729 (value_tag
== IPP_TAG_NAMELANG
&& type
== IPP_TAG_NAME
)))
1731 ipp
->current
= attr
;
1737 ipp
->current
= NULL
;
1745 * 'ippFirstAttribute()' - Return the first attribute in the message.
1750 ipp_attribute_t
* /* O - First attribute or @code NULL@ if none */
1751 ippFirstAttribute(ipp_t
*ipp
) /* I - IPP message */
1754 * Range check input...
1761 * Return the first attribute...
1764 return (ipp
->current
= ipp
->attrs
);
1769 * 'ippGetBoolean()' - Get a boolean value for an attribute.
1771 * The @code element@ parameter specifies which value to get from 0 to
1772 * @link ippGetCount(attr)@ - 1.
1777 int /* O - Boolean value or -1 on error */
1778 ippGetBoolean(ipp_attribute_t
*attr
, /* I - IPP attribute */
1779 int element
) /* I - Value number (0-based) */
1782 * Range check input...
1785 if (!attr
|| attr
->value_tag
!= IPP_TAG_BOOLEAN
||
1786 element
< 0 || element
>= attr
->num_values
)
1790 * Return the value...
1793 return (attr
->values
[element
].boolean
);
1798 * 'ippGetCollection()' - Get a collection value for an attribute.
1800 * The @code element@ parameter specifies which value to get from 0 to
1801 * @link ippGetCount(attr)@ - 1.
1806 ipp_t
* /* O - Collection value or @code NULL@ on error */
1808 ipp_attribute_t
*attr
, /* I - IPP attribute */
1809 int element
) /* I - Value number (0-based) */
1812 * Range check input...
1815 if (!attr
|| attr
->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
1816 element
< 0 || element
>= attr
->num_values
)
1820 * Return the value...
1823 return (attr
->values
[element
].collection
);
1828 * 'ippGetCount()' - Get the number of values in an attribute.
1833 int /* O - Number of values or -1 on error */
1834 ippGetCount(ipp_attribute_t
*attr
) /* I - IPP attribute */
1837 * Range check input...
1844 * Return the number of values...
1847 return (attr
->num_values
);
1852 * 'ippGetGroupTag()' - Get the group associated with an attribute.
1857 ipp_tag_t
/* O - Group tag or @code IPP_TAG_ZERO@ on error */
1858 ippGetGroupTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
1861 * Range check input...
1865 return (IPP_TAG_ZERO
);
1868 * Return the group...
1871 return (attr
->group_tag
);
1876 * 'ippGetInteger()' - Get the integer/enum value for an attribute.
1878 * The @code element@ parameter specifies which value to get from 0 to
1879 * @link ippGetCount(attr)@ - 1.
1884 int /* O - Value or -1 on error */
1885 ippGetInteger(ipp_attribute_t
*attr
, /* I - IPP attribute */
1886 int element
) /* I - Value number (0-based) */
1889 * Range check input...
1892 if (!attr
|| (attr
->value_tag
!= IPP_TAG_INTEGER
&& attr
->value_tag
!= IPP_TAG_ENUM
) ||
1893 element
< 0 || element
>= attr
->num_values
)
1897 * Return the value...
1900 return (attr
->values
[element
].integer
);
1905 * 'ippGetName()' - Get the attribute name.
1910 const char * /* O - Attribute name or @code NULL@ for separators */
1911 ippGetName(ipp_attribute_t
*attr
) /* I - IPP attribute */
1914 * Range check input...
1921 * Return the name...
1924 return (attr
->name
);
1929 * 'ippGetOperation()' - Get the operation ID in an IPP message.
1934 ipp_op_t
/* O - Operation ID or -1 on error */
1935 ippGetOperation(ipp_t
*ipp
) /* I - IPP request message */
1938 * Range check input...
1942 return ((ipp_op_t
)-1);
1945 * Return the value...
1948 return (ipp
->request
.op
.operation_id
);
1953 * 'ippGetRequestId()' - Get the request ID from an IPP message.
1958 int /* O - Request ID or -1 on error */
1959 ippGetRequestId(ipp_t
*ipp
) /* I - IPP message */
1962 * Range check input...
1969 * Return the request ID...
1972 return (ipp
->request
.any
.request_id
);
1977 * 'ippGetResolution()' - Get a resolution value for an attribute.
1979 * The @code element@ parameter specifies which value to get from 0 to
1980 * @link ippGetCount(attr)@ - 1.
1985 int /* O - Horizontal/cross feed resolution or -1 */
1987 ipp_attribute_t
*attr
, /* I - IPP attribute */
1988 int element
, /* I - Value number (0-based) */
1989 int *yres
, /* O - Vertical/feed resolution */
1990 ipp_res_t
*units
) /* O - Units for resolution */
1993 * Range check input...
1996 if (!attr
|| attr
->value_tag
!= IPP_TAG_RESOLUTION
||
1997 element
< 0 || element
>= attr
->num_values
)
2001 * Return the value...
2005 *yres
= attr
->values
[element
].resolution
.yres
;
2008 *units
= attr
->values
[element
].resolution
.units
;
2010 return (attr
->values
[element
].resolution
.xres
);
2015 * 'ippGetStatusCode()' - Get the status code from an IPP response or event message.
2020 ipp_status_t
/* O - Status code in IPP message */
2021 ippGetStatusCode(ipp_t
*ipp
) /* I - IPP response or event message */
2024 * Range check input...
2028 return (IPP_INTERNAL_ERROR
);
2031 * Return the value...
2034 return (ipp
->request
.status
.status_code
);
2039 * 'ippGetString()' - Get the string and optionally the language code for an attribute.
2041 * The @code element@ parameter specifies which value to get from 0 to
2042 * @link ippGetCount(attr)@ - 1.
2048 ippGetString(ipp_attribute_t
*attr
, /* I - IPP attribute */
2049 int element
, /* I - Value number (0-based) */
2050 const char **language
)/* O - Language code (@code NULL@ for don't care) */
2053 * Range check input...
2056 if (!attr
|| element
< 0 || element
>= attr
->num_values
||
2057 (attr
->value_tag
!= IPP_TAG_TEXTLANG
&& attr
->value_tag
!= IPP_TAG_NAMELANG
&&
2058 (attr
->value_tag
< IPP_TAG_TEXT
|| attr
->value_tag
> IPP_TAG_MIMETYPE
)))
2062 * Return the value...
2066 *language
= attr
->values
[element
].string
.language
;
2068 return (attr
->values
[element
].string
.text
);
2073 * 'ippGetValueTag()' - Get the value tag for an attribute.
2078 ipp_tag_t
/* O - Value tag or @code IPP_TAG_ZERO@ on error */
2079 ippGetValueTag(ipp_attribute_t
*attr
) /* I - IPP attribute */
2082 * Range check input...
2086 return (IPP_TAG_ZERO
);
2089 * Return the value...
2092 return (attr
->value_tag
);
2097 * 'ippGetVersion()' - Get the major and minor version number from an IPP message.
2102 int /* O - Major version number or -1 on error */
2103 ippGetVersion(ipp_t
*ipp
, /* I - IPP message */
2104 int *minor
) /* O - Minor version number or @code NULL@ */
2107 * Range check input...
2119 * Return the value...
2123 *minor
= ipp
->request
.any
.version
[1];
2125 return (ipp
->request
.any
.version
[0]);
2130 * 'ippLength()' - Compute the length of an IPP message.
2133 size_t /* O - Size of IPP message */
2134 ippLength(ipp_t
*ipp
) /* I - IPP message */
2136 return (ipp_length(ipp
, 0));
2141 * 'ippNextAttribute()' - Return the next attribute in the message.
2146 ipp_attribute_t
* /* O - Next attribute or @code NULL@ if none */
2147 ippNextAttribute(ipp_t
*ipp
) /* I - IPP message */
2150 * Range check input...
2153 if (!ipp
|| !ipp
->current
)
2157 * Return the next attribute...
2160 return (ipp
->current
= ipp
->current
->next
);
2165 * 'ippNew()' - Allocate a new IPP message.
2168 ipp_t
* /* O - New IPP message */
2171 ipp_t
*temp
; /* New IPP message */
2174 DEBUG_puts("ippNew()");
2176 if ((temp
= (ipp_t
*)calloc(1, sizeof(ipp_t
))) != NULL
)
2179 * Default to IPP 2.0...
2182 temp
->request
.any
.version
[0] = 2;
2183 temp
->request
.any
.version
[1] = 0;
2187 DEBUG_printf(("1ippNew: Returning %p", temp
));
2194 * 'ippNewRequest()' - Allocate a new IPP request message.
2196 * The new request message is initialized with the attributes-charset and
2197 * attributes-natural-language attributes added. The
2198 * attributes-natural-language value is derived from the current locale.
2200 * @since CUPS 1.2/Mac OS X 10.5@
2203 ipp_t
* /* O - IPP request message */
2204 ippNewRequest(ipp_op_t op
) /* I - Operation code */
2206 ipp_t
*request
; /* IPP request message */
2207 cups_lang_t
*language
; /* Current language localization */
2208 static int request_id
= 0; /* Current request ID */
2209 static _cups_mutex_t request_mutex
= _CUPS_MUTEX_INITIALIZER
;
2210 /* Mutex for request ID */
2213 DEBUG_printf(("ippNewRequest(op=%02x(%s))", op
, ippOpString(op
)));
2216 * Create a new IPP message...
2219 if ((request
= ippNew()) == NULL
)
2223 * Set the operation and request ID...
2226 _cupsMutexLock(&request_mutex
);
2228 request
->request
.op
.operation_id
= op
;
2229 request
->request
.op
.request_id
= ++request_id
;
2231 _cupsMutexUnlock(&request_mutex
);
2234 * Use UTF-8 as the character set...
2237 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
2238 "attributes-charset", NULL
, "utf-8");
2241 * Get the language from the current locale...
2244 language
= cupsLangDefault();
2246 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
2247 "attributes-natural-language", NULL
, language
->language
);
2250 * Return the new request...
2258 * 'ippRead()' - Read data for an IPP message from a HTTP connection.
2261 ipp_state_t
/* O - Current state */
2262 ippRead(http_t
*http
, /* I - HTTP connection */
2263 ipp_t
*ipp
) /* I - IPP data */
2265 DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=" CUPS_LLFMT
,
2266 http
, ipp
, CUPS_LLCAST (http
? http
->data_remaining
: -1)));
2271 DEBUG_printf(("2ippRead: http->state=%d, http->used=%d", http
->state
,
2274 return (ippReadIO(http
, (ipp_iocb_t
)ipp_read_http
, http
->blocking
, NULL
,
2280 * 'ippReadFile()' - Read data for an IPP message from a file.
2282 * @since CUPS 1.1.19/Mac OS X 10.3@
2285 ipp_state_t
/* O - Current state */
2286 ippReadFile(int fd
, /* I - HTTP data */
2287 ipp_t
*ipp
) /* I - IPP data */
2289 DEBUG_printf(("ippReadFile(fd=%d, ipp=%p)", fd
, ipp
));
2291 return (ippReadIO(&fd
, (ipp_iocb_t
)ipp_read_file
, 1, NULL
, ipp
));
2296 * 'ippReadIO()' - Read data for an IPP message.
2298 * @since CUPS 1.2/Mac OS X 10.5@
2301 ipp_state_t
/* O - Current state */
2302 ippReadIO(void *src
, /* I - Data source */
2303 ipp_iocb_t cb
, /* I - Read callback function */
2304 int blocking
, /* I - Use blocking IO? */
2305 ipp_t
*parent
, /* I - Parent request, if any */
2306 ipp_t
*ipp
) /* I - IPP data */
2308 int n
; /* Length of data */
2309 unsigned char *buffer
, /* Data buffer */
2310 string
[IPP_MAX_NAME
],
2311 /* Small string buffer */
2312 *bufptr
; /* Pointer into buffer */
2313 ipp_attribute_t
*attr
; /* Current attribute */
2314 ipp_tag_t tag
; /* Current tag */
2315 ipp_tag_t value_tag
; /* Current value tag */
2316 _ipp_value_t
*value
; /* Current value */
2319 DEBUG_printf(("ippReadIO(src=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)",
2320 src
, cb
, blocking
, parent
, ipp
));
2321 DEBUG_printf(("2ippReadIO: ipp->state=%d", ipp
->state
));
2326 if ((buffer
= ipp_buffer_get()) == NULL
)
2328 DEBUG_puts("1ippReadIO: Unable to get read buffer.");
2335 ipp
->state
++; /* Avoid common problem... */
2341 * Get the request header...
2344 if ((*cb
)(src
, buffer
, 8) < 8)
2346 DEBUG_puts("1ippReadIO: Unable to read header.");
2347 ipp_buffer_release(buffer
);
2352 * Then copy the request header over...
2355 ipp
->request
.any
.version
[0] = buffer
[0];
2356 ipp
->request
.any
.version
[1] = buffer
[1];
2357 ipp
->request
.any
.op_status
= (buffer
[2] << 8) | buffer
[3];
2358 ipp
->request
.any
.request_id
= (((((buffer
[4] << 8) | buffer
[5]) << 8) |
2359 buffer
[6]) << 8) | buffer
[7];
2361 DEBUG_printf(("2ippReadIO: version=%d.%d", buffer
[0], buffer
[1]));
2362 DEBUG_printf(("2ippReadIO: op_status=%04x",
2363 ipp
->request
.any
.op_status
));
2364 DEBUG_printf(("2ippReadIO: request_id=%d",
2365 ipp
->request
.any
.request_id
));
2368 ipp
->state
= IPP_ATTRIBUTE
;
2369 ipp
->current
= NULL
;
2370 ipp
->curtag
= IPP_TAG_ZERO
;
2371 ipp
->prev
= ipp
->last
;
2374 * If blocking is disabled, stop here...
2380 case IPP_ATTRIBUTE
:
2383 if ((*cb
)(src
, buffer
, 1) < 1)
2385 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
2386 ipp_buffer_release(buffer
);
2390 DEBUG_printf(("2ippReadIO: ipp->current=%p, ipp->prev=%p",
2391 ipp
->current
, ipp
->prev
));
2394 * Read this attribute...
2397 tag
= (ipp_tag_t
)buffer
[0];
2398 if (tag
== IPP_TAG_EXTENSION
)
2401 * Read 32-bit "extension" tag...
2404 if ((*cb
)(src
, buffer
, 4) < 1)
2406 DEBUG_puts("1ippReadIO: Callback returned EOF/error");
2407 ipp_buffer_release(buffer
);
2411 tag
= (ipp_tag_t
)((((((buffer
[0] << 8) | buffer
[1]) << 8) |
2412 buffer
[2]) << 8) | buffer
[3]);
2414 if (tag
& IPP_TAG_COPY
)
2417 * Fail if the high bit is set in the tag...
2420 _cupsSetError(IPP_ERROR
, _("IPP extension tag larger than 0x7FFFFFFF."), 1);
2421 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
2422 ipp_buffer_release(buffer
);
2427 if (tag
== IPP_TAG_END
)
2430 * No more attributes left...
2433 DEBUG_puts("2ippReadIO: IPP_TAG_END.");
2435 ipp
->state
= IPP_DATA
;
2438 else if (tag
< IPP_TAG_UNSUPPORTED_VALUE
)
2441 * Group tag... Set the current group and continue...
2444 if (ipp
->curtag
== tag
)
2445 ipp
->prev
= ippAddSeparator(ipp
);
2446 else if (ipp
->current
)
2447 ipp
->prev
= ipp
->current
;
2450 ipp
->current
= NULL
;
2451 DEBUG_printf(("2ippReadIO: group tag=%x(%s), ipp->prev=%p", tag
,
2452 ippTagString(tag
), ipp
->prev
));
2456 DEBUG_printf(("2ippReadIO: value tag=%x(%s)", tag
,
2457 ippTagString(tag
)));
2463 if ((*cb
)(src
, buffer
, 2) < 2)
2465 DEBUG_puts("1ippReadIO: unable to read name length.");
2466 ipp_buffer_release(buffer
);
2470 n
= (buffer
[0] << 8) | buffer
[1];
2472 if (n
>= IPP_BUF_SIZE
)
2474 _cupsSetError(IPP_ERROR
, _("IPP name larger than 32767 bytes."), 1);
2475 DEBUG_printf(("1ippReadIO: bad name length %d.", n
));
2476 ipp_buffer_release(buffer
);
2480 DEBUG_printf(("2ippReadIO: name length=%d", n
));
2482 if (n
== 0 && tag
!= IPP_TAG_MEMBERNAME
&&
2483 tag
!= IPP_TAG_END_COLLECTION
)
2486 * More values for current attribute...
2489 if (ipp
->current
== NULL
)
2491 _cupsSetError(IPP_ERROR
, _("IPP attribute has no name."), 1);
2492 DEBUG_puts("1ippReadIO: Attribute without name and no current.");
2493 ipp_buffer_release(buffer
);
2497 attr
= ipp
->current
;
2498 value_tag
= (ipp_tag_t
)(attr
->value_tag
& IPP_TAG_MASK
);
2501 * Make sure we aren't adding a new value of a different
2505 if (value_tag
== IPP_TAG_ZERO
)
2508 * Setting the value of a collection member...
2511 attr
->value_tag
= tag
;
2513 else if (value_tag
== IPP_TAG_TEXTLANG
||
2514 value_tag
== IPP_TAG_NAMELANG
||
2515 (value_tag
>= IPP_TAG_TEXT
&&
2516 value_tag
<= IPP_TAG_MIMETYPE
))
2519 * String values can sometimes come across in different
2520 * forms; accept sets of differing values...
2523 if (tag
!= IPP_TAG_TEXTLANG
&& tag
!= IPP_TAG_NAMELANG
&&
2524 (tag
< IPP_TAG_TEXT
|| tag
> IPP_TAG_MIMETYPE
) &&
2525 tag
!= IPP_TAG_NOVALUE
)
2527 _cupsSetError(IPP_ERROR
,
2528 _("IPP 1setOf attribute with incompatible value "
2530 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
2531 value_tag
, ippTagString(value_tag
), tag
,
2532 ippTagString(tag
)));
2533 ipp_buffer_release(buffer
);
2537 if (value_tag
!= tag
)
2539 DEBUG_printf(("1ippReadIO: Converting %s attribute from %s to %s.",
2540 attr
->name
, ippTagString(value_tag
), ippTagString(tag
)));
2541 ippSetValueTag(ipp
, &attr
, tag
);
2544 else if (value_tag
== IPP_TAG_INTEGER
||
2545 value_tag
== IPP_TAG_RANGE
)
2548 * Integer and rangeOfInteger values can sometimes be mixed; accept
2549 * sets of differing values...
2552 if (tag
!= IPP_TAG_INTEGER
&& tag
!= IPP_TAG_RANGE
)
2554 _cupsSetError(IPP_ERROR
,
2555 _("IPP 1setOf attribute with incompatible value "
2557 DEBUG_printf(("1ippReadIO: 1setOf value tag %x(%s) != %x(%s)",
2558 value_tag
, ippTagString(value_tag
), tag
,
2559 ippTagString(tag
)));
2560 ipp_buffer_release(buffer
);
2564 if (value_tag
== IPP_TAG_INTEGER
&& tag
== IPP_TAG_RANGE
)
2567 * Convert integer values to rangeOfInteger values...
2570 DEBUG_printf(("1ippReadIO: Converting %s attribute to "
2571 "rangeOfInteger.", attr
->name
));
2572 ippSetValueTag(ipp
, &attr
, IPP_TAG_RANGE
);
2575 else if (value_tag
!= tag
)
2577 _cupsSetError(IPP_ERROR
,
2578 _("IPP 1setOf attribute with incompatible value "
2580 DEBUG_printf(("1ippReadIO: value tag %x(%s) != %x(%s)",
2581 value_tag
, ippTagString(value_tag
), tag
,
2582 ippTagString(tag
)));
2583 ipp_buffer_release(buffer
);
2588 * Finally, reallocate the attribute array as needed...
2591 if ((value
= ipp_set_value(ipp
, &attr
, attr
->num_values
)) == NULL
)
2593 ipp_buffer_release(buffer
);
2597 else if (tag
== IPP_TAG_MEMBERNAME
)
2600 * Name must be length 0!
2605 _cupsSetError(IPP_ERROR
, _("IPP member name is not empty."), 1);
2606 DEBUG_puts("1ippReadIO: member name not empty.");
2607 ipp_buffer_release(buffer
);
2612 ipp
->prev
= ipp
->current
;
2614 attr
= ipp
->current
= ipp_add_attr(ipp
, NULL
, ipp
->curtag
, IPP_TAG_ZERO
, 1);
2616 DEBUG_printf(("2ippReadIO: membername, ipp->current=%p, ipp->prev=%p",
2617 ipp
->current
, ipp
->prev
));
2619 attr
->num_values
= 0;
2620 value
= attr
->values
;
2622 else if (tag
!= IPP_TAG_END_COLLECTION
)
2625 * New attribute; read the name and add it...
2628 if ((*cb
)(src
, buffer
, n
) < n
)
2630 DEBUG_puts("1ippReadIO: unable to read name.");
2631 ipp_buffer_release(buffer
);
2638 ipp
->prev
= ipp
->current
;
2640 if ((attr
= ipp
->current
= ipp_add_attr(ipp
, (char *)buffer
, ipp
->curtag
, tag
,
2643 _cupsSetHTTPError(HTTP_ERROR
);
2644 DEBUG_puts("1ippReadIO: unable to allocate attribute.");
2645 ipp_buffer_release(buffer
);
2649 DEBUG_printf(("2ippReadIO: name=\"%s\", ipp->current=%p, "
2650 "ipp->prev=%p", buffer
, ipp
->current
, ipp
->prev
));
2652 attr
->num_values
= 0;
2653 value
= attr
->values
;
2661 if ((*cb
)(src
, buffer
, 2) < 2)
2663 DEBUG_puts("1ippReadIO: unable to read value length.");
2664 ipp_buffer_release(buffer
);
2668 n
= (buffer
[0] << 8) | buffer
[1];
2669 DEBUG_printf(("2ippReadIO: value length=%d", n
));
2671 if (n
>= IPP_BUF_SIZE
)
2673 _cupsSetError(IPP_ERROR
,
2674 _("IPP value larger than 32767 bytes."), 1);
2675 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
2676 ipp_buffer_release(buffer
);
2682 case IPP_TAG_INTEGER
:
2686 if (tag
== IPP_TAG_INTEGER
)
2687 _cupsSetError(IPP_ERROR
,
2688 _("IPP integer value not 4 bytes."), 1);
2690 _cupsSetError(IPP_ERROR
,
2691 _("IPP enum value not 4 bytes."), 1);
2692 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
2693 ipp_buffer_release(buffer
);
2697 if ((*cb
)(src
, buffer
, 4) < 4)
2699 DEBUG_puts("1ippReadIO: Unable to read integer value.");
2700 ipp_buffer_release(buffer
);
2704 n
= (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
2707 if (attr
->value_tag
== IPP_TAG_RANGE
)
2708 value
->range
.lower
= value
->range
.upper
= n
;
2713 case IPP_TAG_BOOLEAN
:
2716 _cupsSetError(IPP_ERROR
, _("IPP boolean value not 1 byte."),
2718 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
2719 ipp_buffer_release(buffer
);
2723 if ((*cb
)(src
, buffer
, 1) < 1)
2725 DEBUG_puts("1ippReadIO: Unable to read boolean value.");
2726 ipp_buffer_release(buffer
);
2730 value
->boolean
= buffer
[0];
2733 case IPP_TAG_NOVALUE
:
2734 case IPP_TAG_NOTSETTABLE
:
2735 case IPP_TAG_DELETEATTR
:
2736 case IPP_TAG_ADMINDEFINE
:
2738 * These value types are not supposed to have values, however
2739 * some vendors (Brother) do not implement IPP correctly and so
2740 * we need to map non-empty values to text...
2743 if (attr
->value_tag
== tag
)
2748 attr
->value_tag
= IPP_TAG_TEXT
;
2753 case IPP_TAG_KEYWORD
:
2755 case IPP_TAG_URISCHEME
:
2756 case IPP_TAG_CHARSET
:
2757 case IPP_TAG_LANGUAGE
:
2758 case IPP_TAG_MIMETYPE
:
2759 if ((*cb
)(src
, buffer
, n
) < n
)
2761 DEBUG_puts("1ippReadIO: unable to read string value.");
2762 ipp_buffer_release(buffer
);
2767 value
->string
.text
= _cupsStrAlloc((char *)buffer
);
2768 DEBUG_printf(("2ippReadIO: value=\"%s\"", value
->string
.text
));
2774 _cupsSetError(IPP_ERROR
, _("IPP date value not 11 bytes."), 1);
2775 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
2776 ipp_buffer_release(buffer
);
2780 if ((*cb
)(src
, value
->date
, 11) < 11)
2782 DEBUG_puts("1ippReadIO: Unable to read date value.");
2783 ipp_buffer_release(buffer
);
2788 case IPP_TAG_RESOLUTION
:
2791 _cupsSetError(IPP_ERROR
,
2792 _("IPP resolution value not 9 bytes."), 1);
2793 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
2794 ipp_buffer_release(buffer
);
2798 if ((*cb
)(src
, buffer
, 9) < 9)
2800 DEBUG_puts("1ippReadIO: Unable to read resolution value.");
2801 ipp_buffer_release(buffer
);
2805 value
->resolution
.xres
=
2806 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
2808 value
->resolution
.yres
=
2809 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
2811 value
->resolution
.units
=
2812 (ipp_res_t
)buffer
[8];
2815 case IPP_TAG_RANGE
:
2818 _cupsSetError(IPP_ERROR
,
2819 _("IPP rangeOfInteger value not 8 bytes."), 1);
2820 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
2821 ipp_buffer_release(buffer
);
2825 if ((*cb
)(src
, buffer
, 8) < 8)
2827 DEBUG_puts("1ippReadIO: Unable to read range value.");
2828 ipp_buffer_release(buffer
);
2832 value
->range
.lower
=
2833 (((((buffer
[0] << 8) | buffer
[1]) << 8) | buffer
[2]) << 8) |
2835 value
->range
.upper
=
2836 (((((buffer
[4] << 8) | buffer
[5]) << 8) | buffer
[6]) << 8) |
2840 case IPP_TAG_TEXTLANG
:
2841 case IPP_TAG_NAMELANG
:
2844 if (tag
== IPP_TAG_TEXTLANG
)
2845 _cupsSetError(IPP_ERROR
,
2846 _("IPP textWithLanguage value less than "
2847 "minimum 4 bytes."), 1);
2849 _cupsSetError(IPP_ERROR
,
2850 _("IPP nameWithLanguage value less than "
2851 "minimum 4 bytes."), 1);
2852 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
2853 ipp_buffer_release(buffer
);
2857 if ((*cb
)(src
, buffer
, n
) < n
)
2859 DEBUG_puts("1ippReadIO: Unable to read string w/language "
2861 ipp_buffer_release(buffer
);
2868 * text-with-language and name-with-language are composite
2877 n
= (bufptr
[0] << 8) | bufptr
[1];
2879 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
) ||
2880 n
>= sizeof(string
))
2882 _cupsSetError(IPP_ERROR
,
2883 _("IPP language length overflows value."), 1);
2884 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
2885 ipp_buffer_release(buffer
);
2889 memcpy(string
, bufptr
+ 2, n
);
2892 value
->string
.language
= _cupsStrAlloc((char *)string
);
2895 n
= (bufptr
[0] << 8) | bufptr
[1];
2897 if ((bufptr
+ 2 + n
) >= (buffer
+ IPP_BUF_SIZE
))
2899 _cupsSetError(IPP_ERROR
,
2900 _("IPP string length overflows value."), 1);
2901 DEBUG_printf(("1ippReadIO: bad value length %d.", n
));
2902 ipp_buffer_release(buffer
);
2906 bufptr
[2 + n
] = '\0';
2907 value
->string
.text
= _cupsStrAlloc((char *)bufptr
+ 2);
2910 case IPP_TAG_BEGIN_COLLECTION
:
2912 * Oh, boy, here comes a collection value, so read it...
2915 value
->collection
= ippNew();
2919 _cupsSetError(IPP_ERROR
,
2920 _("IPP begCollection value not 0 bytes."), 1);
2921 DEBUG_puts("1ippReadIO: begCollection tag with value length "
2923 ipp_buffer_release(buffer
);
2927 if (ippReadIO(src
, cb
, 1, ipp
, value
->collection
) == IPP_ERROR
)
2929 DEBUG_puts("1ippReadIO: Unable to read collection value.");
2930 ipp_buffer_release(buffer
);
2935 case IPP_TAG_END_COLLECTION
:
2936 ipp_buffer_release(buffer
);
2940 _cupsSetError(IPP_ERROR
,
2941 _("IPP endCollection value not 0 bytes."), 1);
2942 DEBUG_puts("1ippReadIO: endCollection tag with value length "
2947 DEBUG_puts("1ippReadIO: endCollection tag...");
2948 return (ipp
->state
= IPP_DATA
);
2950 case IPP_TAG_MEMBERNAME
:
2952 * The value the name of the member in the collection, which
2953 * we need to carry over...
2956 if ((*cb
)(src
, buffer
, n
) < n
)
2958 DEBUG_puts("1ippReadIO: Unable to read member name value.");
2959 ipp_buffer_release(buffer
);
2964 attr
->name
= _cupsStrAlloc((char *)buffer
);
2967 * Since collection members are encoded differently than
2968 * regular attributes, make sure we don't start with an
2972 attr
->num_values
--;
2974 DEBUG_printf(("2ippReadIO: member name=\"%s\"", attr
->name
));
2977 default : /* Other unsupported values */
2978 value
->unknown
.length
= n
;
2981 if ((value
->unknown
.data
= malloc(n
)) == NULL
)
2983 _cupsSetHTTPError(HTTP_ERROR
);
2984 DEBUG_puts("1ippReadIO: Unable to allocate value");
2985 ipp_buffer_release(buffer
);
2989 if ((*cb
)(src
, value
->unknown
.data
, n
) < n
)
2991 DEBUG_puts("1ippReadIO: Unable to read unsupported value.");
2992 ipp_buffer_release(buffer
);
2997 value
->unknown
.data
= NULL
;
3001 attr
->num_values
++;
3004 * If blocking is disabled, stop here...
3016 break; /* anti-compiler-warning-code */
3019 DEBUG_printf(("1ippReadIO: returning ipp->state=%d.", ipp
->state
));
3020 ipp_buffer_release(buffer
);
3022 return (ipp
->state
);
3027 * 'ippSetBoolean()' - Set a boolean value in an attribute.
3029 * The @code ipp@ parameter refers to the IPP message containing the attribute that was
3030 * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
3032 * The @code attr@ parameter may be modified as a result of setting the value.
3034 * The @code element@ parameter specifies which value to set from 0 to
3035 * @link ippGetCount(attr)@.
3040 int /* O - 1 on success, 0 on failure */
3041 ippSetBoolean(ipp_t
*ipp
, /* I - IPP message */
3042 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3043 int element
, /* I - Value number (0-based) */
3044 int boolvalue
)/* I - Boolean value */
3046 _ipp_value_t
*value
; /* Current value */
3050 * Range check input...
3053 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BOOLEAN
||
3054 element
< 0 || element
> (*attr
)->num_values
)
3058 * Set the value and return...
3061 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3062 value
->boolean
= boolvalue
;
3064 return (value
!= NULL
);
3069 * 'ippSetCollection()' - Set a collection value in an attribute.
3071 * The @code ipp@ parameter refers to the IPP message containing the attribute that was
3072 * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
3074 * The @code attr@ parameter may be modified as a result of setting the value.
3076 * The @code element@ parameter specifies which value to set from 0 to
3077 * @link ippGetCount(attr)@.
3082 int /* O - 1 on success, 0 on failure */
3084 ipp_t
*ipp
, /* I - IPP message */
3085 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3086 int element
, /* I - Value number (0-based) */
3087 ipp_t
*colvalue
) /* I - Collection value */
3089 _ipp_value_t
*value
; /* Current value */
3093 * Range check input...
3096 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_BEGIN_COLLECTION
||
3097 element
< 0 || element
> (*attr
)->num_values
|| !colvalue
)
3101 * Set the value and return...
3104 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3106 if (value
->collection
)
3107 ippDelete(value
->collection
);
3109 value
->collection
= colvalue
;
3113 return (value
!= NULL
);
3118 * 'ippSetGroupTag()' - Set the group tag of an attribute.
3120 * The @code ipp@ parameter refers to the IPP message containing the attribute that was
3121 * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
3123 * The @code attr@ parameter may be modified as a result of setting the value.
3125 * The @code group@ parameter specifies the IPP attribute group tag: none
3126 * (@code IPP_TAG_ZERO@, for member attributes), document (@code IPP_TAG_DOCUMENT@),
3127 * event notification (@code IPP_TAG_EVENT_NOTIFICATION@), operation
3128 * (@code IPP_TAG_OPERATION@), printer (@code IPP_TAG_PRINTER@), subscription
3129 * (@code IPP_TAG_SUBSCRIPTION@), or unsupported (@code IPP_TAG_UNSUPPORTED_GROUP@).
3134 int /* O - 1 on success, 0 on failure */
3136 ipp_t
*ipp
, /* I - IPP message */
3137 ipp_attribute_t
**attr
, /* IO - Attribute */
3138 ipp_tag_t group_tag
) /* I - Group tag */
3141 * Range check input - group tag must be 0x01 to 0x0F, per RFC 2911...
3144 if (!ipp
|| !attr
|| group_tag
< IPP_TAG_ZERO
|| group_tag
== IPP_TAG_END
||
3145 group_tag
>= IPP_TAG_UNSUPPORTED_VALUE
)
3149 * Set the group tag and return...
3152 (*attr
)->group_tag
= group_tag
;
3159 * 'ippSetInteger()' - Set an integer or enum value in an attribute.
3161 * The @code ipp@ parameter refers to the IPP message containing the attribute that was
3162 * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
3164 * The @code attr@ parameter may be modified as a result of setting the value.
3166 * The @code element@ parameter specifies which value to set from 0 to
3167 * @link ippGetCount(attr)@.
3172 int /* O - 1 on success, 0 on failure */
3173 ippSetInteger(ipp_t
*ipp
, /* I - IPP message */
3174 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3175 int element
, /* I - Value number (0-based) */
3176 int intvalue
) /* I - Integer/enum value */
3178 _ipp_value_t
*value
; /* Current value */
3182 * Range check input...
3185 if (!ipp
|| !attr
|| !*attr
||
3186 ((*attr
)->value_tag
!= IPP_TAG_INTEGER
&& (*attr
)->value_tag
!= IPP_TAG_ENUM
) ||
3187 element
< 0 || element
> (*attr
)->num_values
)
3191 * Set the value and return...
3194 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3195 value
->integer
= intvalue
;
3197 return (value
!= NULL
);
3202 * 'ippSetName()' - Set the name of an attribute.
3204 * The @code ipp@ parameter refers to the IPP message containing the attribute that was
3205 * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
3207 * The @code attr@ parameter may be modified as a result of setting the value.
3212 int /* O - 1 on success, 0 on failure */
3213 ippSetName(ipp_t
*ipp
, /* I - IPP message */
3214 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3215 const char *name
) /* I - Attribute name */
3217 char *temp
; /* Temporary name value */
3221 * Range check input...
3224 if (!ipp
|| !attr
|| !*attr
)
3228 * Set the value and return...
3231 if ((temp
= _cupsStrAlloc(name
)) != NULL
)
3234 _cupsStrFree((*attr
)->name
);
3236 (*attr
)->name
= temp
;
3239 return (temp
!= NULL
);
3244 * 'ippSetOperation()' - Set the operation ID in an IPP request message.
3246 * The @code ipp@ parameter refers to an IPP message previously created using the
3247 * @link ippNew@ or @link ippNewRequest@ functions.
3252 int /* O - 1 on success, 0 on failure */
3253 ippSetOperation(ipp_t
*ipp
, /* I - IPP request message */
3254 ipp_op_t op
) /* I - Operation ID */
3257 * Range check input...
3264 * Set the operation and return...
3267 ipp
->request
.op
.operation_id
= op
;
3274 * 'ippSetRange()' - Set a rangeOfInteger value in an attribute.
3276 * The @code ipp@ parameter refers to the IPP message containing the attribute that was
3277 * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
3279 * The @code attr@ parameter may be modified as a result of setting the value.
3281 * The @code element@ parameter specifies which value to set from 0 to
3282 * @link ippGetCount(attr)@.
3287 int /* O - 1 on success, 0 on failure */
3288 ippSetRange(ipp_t
*ipp
, /* I - IPP message */
3289 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3290 int element
, /* I - Value number (0-based) */
3291 int lowervalue
, /* I - Lower bound for range */
3292 int uppervalue
) /* I - Upper bound for range */
3294 _ipp_value_t
*value
; /* Current value */
3298 * Range check input...
3301 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RANGE
||
3302 element
< 0 || element
> (*attr
)->num_values
|| lowervalue
> uppervalue
)
3306 * Set the value and return...
3309 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3311 value
->range
.lower
= lowervalue
;
3312 value
->range
.upper
= uppervalue
;
3315 return (value
!= NULL
);
3320 * 'ippSetRequestId()' - Set the request ID in an IPP message.
3322 * The @code ipp@ parameter refers to an IPP message previously created using the
3323 * @link ippNew@ or @link ippNewRequest@ functions.
3325 * The @code request_id@ parameter must be greater than 0.
3330 int /* O - 1 on success, 0 on failure */
3331 ippSetRequestId(ipp_t
*ipp
, /* I - IPP message */
3332 int request_id
) /* I - Request ID */
3335 * Range check input; not checking request_id values since ipptool wants to send
3336 * invalid values for conformance testing and a bad request_id does not affect the
3337 * encoding of a message...
3344 * Set the request ID and return...
3347 ipp
->request
.any
.request_id
= request_id
;
3354 * 'ippSetResolution()' - Set a resolution value in an attribute.
3356 * The @code ipp@ parameter refers to the IPP message containing the attribute that was
3357 * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
3359 * The @code attr@ parameter may be modified as a result of setting the value.
3361 * The @code element@ parameter specifies which value to set from 0 to
3362 * @link ippGetCount(attr)@.
3367 int /* O - 1 on success, 0 on failure */
3369 ipp_t
*ipp
, /* I - IPP message */
3370 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3371 int element
, /* I - Value number (0-based) */
3372 ipp_res_t unitsvalue
, /* I - Resolution units */
3373 int xresvalue
, /* I - Horizontal/cross feed resolution */
3374 int yresvalue
) /* I - Vertical/feed resolution */
3376 _ipp_value_t
*value
; /* Current value */
3380 * Range check input...
3383 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_RESOLUTION
||
3384 element
< 0 || element
> (*attr
)->num_values
|| xresvalue
<= 0 || yresvalue
<= 0 ||
3385 unitsvalue
< IPP_RES_PER_INCH
|| unitsvalue
> IPP_RES_PER_CM
)
3389 * Set the value and return...
3392 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3394 value
->resolution
.units
= unitsvalue
;
3395 value
->resolution
.xres
= xresvalue
;
3396 value
->resolution
.yres
= yresvalue
;
3399 return (value
!= NULL
);
3404 * 'ippSetStatusCode()' - Set the status code in an IPP response or event message.
3406 * The @code ipp@ parameter refers to an IPP message previously created using the
3407 * @link ippNew@ or @link ippNewRequest@ functions.
3412 int /* O - 1 on success, 0 on failure */
3413 ippSetStatusCode(ipp_t
*ipp
, /* I - IPP response or event message */
3414 ipp_status_t status
) /* I - Status code */
3417 * Range check input...
3424 * Set the status code and return...
3427 ipp
->request
.status
.status_code
= status
;
3435 * 'ippSetString()' - Set a string value in an attribute.
3437 * The @code ipp@ parameter refers to the IPP message containing the attribute that was
3438 * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
3440 * The @code attr@ parameter may be modified as a result of setting the value.
3442 * The @code element@ parameter specifies which value to set from 0 to
3443 * @link ippGetCount(attr)@.
3448 int /* O - 1 on success, 0 on failure */
3449 ippSetString(ipp_t
*ipp
, /* I - IPP message */
3450 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3451 int element
, /* I - Value number (0-based) */
3452 const char *strvalue
) /* I - String value */
3454 char *temp
; /* Temporary string */
3455 _ipp_value_t
*value
; /* Current value */
3459 * Range check input...
3462 if (!ipp
|| !attr
|| !*attr
|| (*attr
)->value_tag
!= IPP_TAG_INTEGER
||
3463 element
< 0 || element
> (*attr
)->num_values
|| !strvalue
)
3467 * Set the value and return...
3470 if ((value
= ipp_set_value(ipp
, attr
, element
)) != NULL
)
3473 value
->string
.language
= (*attr
)->values
[0].string
.language
;
3475 if ((int)((*attr
)->value_tag
) & IPP_TAG_COPY
)
3476 value
->string
.text
= (char *)strvalue
;
3477 else if ((temp
= _cupsStrAlloc(strvalue
)) != NULL
)
3479 if (value
->string
.text
)
3480 _cupsStrFree(value
->string
.text
);
3482 value
->string
.text
= temp
;
3488 return (value
!= NULL
);
3493 * 'ippSetValueTag()' - Set the value tag of an attribute.
3495 * The @code ipp@ parameter refers to the IPP message containing the attribute that was
3496 * previously created using the @link ippNew@ or @link ippNewRequest@ functions.
3498 * The @code attr@ parameter may be modified as a result of setting the value.
3500 * Integer (@code IPP_TAG_INTEGER@) values can be promoted to rangeOfInteger
3501 * (@code IPP_TAG_RANGE@) values, the various string tags can be promoted to name
3502 * (@code IPP_TAG_NAME@) or nameWithLanguage (@code IPP_TAG_NAMELANG@) values, text
3503 * (@code IPP_TAG_TEXT@) values can be promoted to textWithLanguage
3504 * (@code IPP_TAG_TEXTLANG@) values, and all values can be demoted to the various
3505 * out-of-band value tags such as no-value (@code IPP_TAG_NOVALUE@). All other changes
3508 * Promoting a string attribute to nameWithLanguage or textWithLanguage adds the language
3509 * code in the "attributes-natural-language" attribute or, if not present, the language
3510 * code for the current locale.
3515 int /* O - 1 on success, 0 on failure */
3517 ipp_t
*ipp
, /* I - IPP message */
3518 ipp_attribute_t
**attr
, /* IO - IPP attribute */
3519 ipp_tag_t value_tag
) /* I - Value tag */
3521 int i
; /* Looping var */
3522 _ipp_value_t
*value
; /* Current value */
3523 int integer
; /* Current integer value */
3524 cups_lang_t
*language
; /* Current language */
3525 char code
[32]; /* Language code */
3526 ipp_tag_t temp_tag
; /* Temporary value tag */
3530 * Range check input...
3537 * If there is no change, return immediately...
3540 if (value_tag
== (*attr
)->value_tag
)
3544 * Otherwise implement changes as needed...
3547 temp_tag
= (ipp_tag_t
)((int)((*attr
)->value_tag
) & IPP_TAG_MASK
);
3551 case IPP_TAG_UNSUPPORTED_VALUE
:
3552 case IPP_TAG_DEFAULT
:
3553 case IPP_TAG_UNKNOWN
:
3554 case IPP_TAG_NOVALUE
:
3555 case IPP_TAG_NOTSETTABLE
:
3556 case IPP_TAG_DELETEATTR
:
3557 case IPP_TAG_ADMINDEFINE
:
3559 * Free any existing values...
3562 if ((*attr
)->num_values
> 0)
3563 ipp_free_values(*attr
, 0, (*attr
)->num_values
);
3566 * Set out-of-band value...
3569 (*attr
)->value_tag
= value_tag
;
3572 case IPP_TAG_RANGE
:
3573 if (temp_tag
!= IPP_TAG_INTEGER
)
3576 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
3580 integer
= value
->integer
;
3581 value
->range
.lower
= value
->range
.upper
= integer
;
3584 (*attr
)->value_tag
= IPP_TAG_RANGE
;
3588 if (temp_tag
!= IPP_TAG_KEYWORD
&& temp_tag
!= IPP_TAG_URI
&&
3589 temp_tag
!= IPP_TAG_URISCHEME
&& temp_tag
!= IPP_TAG_LANGUAGE
&&
3590 temp_tag
!= IPP_TAG_MIMETYPE
)
3593 (*attr
)->value_tag
= (ipp_tag_t
)(IPP_TAG_NAME
| ((*attr
)->value_tag
& IPP_TAG_COPY
));
3596 case IPP_TAG_NAMELANG
:
3597 case IPP_TAG_TEXTLANG
:
3598 if (value_tag
== IPP_TAG_NAMELANG
&&
3599 (temp_tag
!= IPP_TAG_NAME
&& temp_tag
!= IPP_TAG_KEYWORD
&&
3600 temp_tag
!= IPP_TAG_URI
&& temp_tag
!= IPP_TAG_URISCHEME
&&
3601 temp_tag
!= IPP_TAG_LANGUAGE
&& temp_tag
!= IPP_TAG_MIMETYPE
))
3604 if (value_tag
== IPP_TAG_TEXTLANG
&& temp_tag
!= IPP_TAG_TEXT
)
3607 if (ipp
->attrs
&& ipp
->attrs
->next
&& ipp
->attrs
->next
->name
&&
3608 !strcmp(ipp
->attrs
->next
->name
, "attributes-natural-language"))
3611 * Use the language code from the IPP message...
3614 (*attr
)->values
[0].string
.language
=
3615 _cupsStrAlloc(ipp
->attrs
->next
->values
[0].string
.text
);
3620 * Otherwise, use the language code corresponding to the locale...
3623 language
= cupsLangDefault();
3624 (*attr
)->values
[0].string
.language
= _cupsStrAlloc(ipp_lang_code(language
->language
,
3629 for (i
= (*attr
)->num_values
- 1, value
= (*attr
)->values
+ 1;
3632 value
->string
.language
= (*attr
)->values
[0].string
.language
;
3634 if ((int)(*attr
)->value_tag
& IPP_TAG_COPY
)
3637 * Make copies of all values...
3640 for (i
= (*attr
)->num_values
, value
= (*attr
)->values
;
3643 value
->string
.text
= _cupsStrAlloc(value
->string
.text
);
3646 (*attr
)->value_tag
= IPP_TAG_NAMELANG
;
3649 case IPP_TAG_KEYWORD
:
3650 if (temp_tag
== IPP_TAG_NAME
|| temp_tag
== IPP_TAG_NAMELANG
)
3651 break; /* Silently "allow" name -> keyword */
3662 * 'ippSetVersion()' - Set the version number in an IPP message.
3664 * The @code ipp@ parameter refers to an IPP message previously created using the
3665 * @link ippNew@ or @link ippNewRequest@ functions.
3667 * The valid version numbers are currently 1.0, 1.1, 2.0, 2.1, and 2.2.
3672 int /* O - 1 on success, 0 on failure */
3673 ippSetVersion(ipp_t
*ipp
, /* I - IPP message */
3674 int major
, /* I - Major version number (major.minor) */
3675 int minor
) /* I - Minor version number (major.minor) */
3678 * Range check input...
3681 if (!ipp
|| major
< 0 || minor
< 0)
3685 * Set the version number...
3688 ipp
->request
.any
.version
[0] = major
;
3689 ipp
->request
.any
.version
[1] = minor
;
3696 * 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
3699 const ipp_uchar_t
* /* O - RFC-1903 date/time data */
3700 ippTimeToDate(time_t t
) /* I - UNIX time value */
3702 struct tm
*unixdate
; /* UNIX unixdate/time info */
3703 ipp_uchar_t
*date
= _cupsGlobals()->ipp_date
;
3704 /* RFC-1903 date/time data */
3708 * RFC-1903 date/time format is:
3710 * Byte(s) Description
3711 * ------- -----------
3712 * 0-1 Year (0 to 65535)
3716 * 5 Minutes (0 to 59)
3717 * 6 Seconds (0 to 60, 60 = "leap second")
3718 * 7 Deciseconds (0 to 9)
3720 * 9 UTC hours (0 to 11)
3721 * 10 UTC minutes (0 to 59)
3724 unixdate
= gmtime(&t
);
3725 unixdate
->tm_year
+= 1900;
3727 date
[0] = unixdate
->tm_year
>> 8;
3728 date
[1] = unixdate
->tm_year
;
3729 date
[2] = unixdate
->tm_mon
+ 1;
3730 date
[3] = unixdate
->tm_mday
;
3731 date
[4] = unixdate
->tm_hour
;
3732 date
[5] = unixdate
->tm_min
;
3733 date
[6] = unixdate
->tm_sec
;
3744 * 'ippWrite()' - Write data for an IPP message to a HTTP connection.
3747 ipp_state_t
/* O - Current state */
3748 ippWrite(http_t
*http
, /* I - HTTP connection */
3749 ipp_t
*ipp
) /* I - IPP data */
3751 DEBUG_printf(("ippWrite(http=%p, ipp=%p)", http
, ipp
));
3756 return (ippWriteIO(http
, (ipp_iocb_t
)httpWrite2
, http
->blocking
, NULL
, ipp
));
3761 * 'ippWriteFile()' - Write data for an IPP message to a file.
3763 * @since CUPS 1.1.19/Mac OS X 10.3@
3766 ipp_state_t
/* O - Current state */
3767 ippWriteFile(int fd
, /* I - HTTP data */
3768 ipp_t
*ipp
) /* I - IPP data */
3770 DEBUG_printf(("ippWriteFile(fd=%d, ipp=%p)", fd
, ipp
));
3772 ipp
->state
= IPP_IDLE
;
3774 return (ippWriteIO(&fd
, (ipp_iocb_t
)ipp_write_file
, 1, NULL
, ipp
));
3779 * 'ippWriteIO()' - Write data for an IPP message.
3781 * @since CUPS 1.2/Mac OS X 10.5@
3784 ipp_state_t
/* O - Current state */
3785 ippWriteIO(void *dst
, /* I - Destination */
3786 ipp_iocb_t cb
, /* I - Write callback function */
3787 int blocking
, /* I - Use blocking IO? */
3788 ipp_t
*parent
, /* I - Parent IPP message */
3789 ipp_t
*ipp
) /* I - IPP data */
3791 int i
; /* Looping var */
3792 int n
; /* Length of data */
3793 unsigned char *buffer
, /* Data buffer */
3794 *bufptr
; /* Pointer into buffer */
3795 ipp_attribute_t
*attr
; /* Current attribute */
3796 _ipp_value_t
*value
; /* Current value */
3799 DEBUG_printf(("ippWriteIO(dst=%p, cb=%p, blocking=%d, parent=%p, ipp=%p)",
3800 dst
, cb
, blocking
, parent
, ipp
));
3805 if ((buffer
= ipp_buffer_get()) == NULL
)
3807 DEBUG_puts("1ippWriteIO: Unable to get write buffer");
3814 ipp
->state
++; /* Avoid common problem... */
3820 * Send the request header:
3823 * Operation/Status Code = 2 bytes
3824 * Request ID = 4 bytes
3830 *bufptr
++ = ipp
->request
.any
.version
[0];
3831 *bufptr
++ = ipp
->request
.any
.version
[1];
3832 *bufptr
++ = ipp
->request
.any
.op_status
>> 8;
3833 *bufptr
++ = ipp
->request
.any
.op_status
;
3834 *bufptr
++ = ipp
->request
.any
.request_id
>> 24;
3835 *bufptr
++ = ipp
->request
.any
.request_id
>> 16;
3836 *bufptr
++ = ipp
->request
.any
.request_id
>> 8;
3837 *bufptr
++ = ipp
->request
.any
.request_id
;
3839 DEBUG_printf(("2ippWriteIO: version=%d.%d", buffer
[0], buffer
[1]));
3840 DEBUG_printf(("2ippWriteIO: op_status=%04x",
3841 ipp
->request
.any
.op_status
));
3842 DEBUG_printf(("2ippWriteIO: request_id=%d",
3843 ipp
->request
.any
.request_id
));
3845 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
3847 DEBUG_puts("1ippWriteIO: Could not write IPP header...");
3848 ipp_buffer_release(buffer
);
3854 * Reset the state engine to point to the first attribute
3855 * in the request/response, with no current group.
3858 ipp
->state
= IPP_ATTRIBUTE
;
3859 ipp
->current
= ipp
->attrs
;
3860 ipp
->curtag
= IPP_TAG_ZERO
;
3862 DEBUG_printf(("1ippWriteIO: ipp->current=%p", ipp
->current
));
3865 * If blocking is disabled, stop here...
3871 case IPP_ATTRIBUTE
:
3872 while (ipp
->current
!= NULL
)
3875 * Write this attribute...
3879 attr
= ipp
->current
;
3881 ipp
->current
= ipp
->current
->next
;
3885 if (ipp
->curtag
!= attr
->group_tag
)
3888 * Send a group tag byte...
3891 ipp
->curtag
= attr
->group_tag
;
3893 if (attr
->group_tag
== IPP_TAG_ZERO
)
3896 DEBUG_printf(("2ippWriteIO: wrote group tag=%x(%s)",
3897 attr
->group_tag
, ippTagString(attr
->group_tag
)));
3898 *bufptr
++ = attr
->group_tag
;
3900 else if (attr
->group_tag
== IPP_TAG_ZERO
)
3904 DEBUG_printf(("1ippWriteIO: %s (%s%s)", attr
->name
,
3905 attr
->num_values
> 1 ? "1setOf " : "",
3906 ippTagString(attr
->value_tag
)));
3909 * Write the attribute tag and name.
3911 * The attribute name length does not include the trailing nul
3912 * character in the source string.
3914 * Collection values (parent != NULL) are written differently...
3920 * Get the length of the attribute name, and make sure it won't
3921 * overflow the buffer...
3924 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 8))
3926 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
3927 ipp_buffer_release(buffer
);
3932 * Write the value tag, name length, and name string...
3935 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
3936 attr
->value_tag
, ippTagString(attr
->value_tag
)));
3937 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
3940 if (attr
->value_tag
> 0xff)
3942 *bufptr
++ = IPP_TAG_EXTENSION
;
3943 *bufptr
++ = attr
->value_tag
>> 24;
3944 *bufptr
++ = attr
->value_tag
>> 16;
3945 *bufptr
++ = attr
->value_tag
>> 8;
3946 *bufptr
++ = attr
->value_tag
;
3949 *bufptr
++ = attr
->value_tag
;
3953 memcpy(bufptr
, attr
->name
, n
);
3959 * Get the length of the attribute name, and make sure it won't
3960 * overflow the buffer...
3963 if ((n
= (int)strlen(attr
->name
)) > (IPP_BUF_SIZE
- 12))
3965 DEBUG_printf(("1ippWriteIO: Attribute name too long (%d)", n
));
3966 ipp_buffer_release(buffer
);
3971 * Write the member name tag, name length, name string, value tag,
3972 * and empty name for the collection member attribute...
3975 DEBUG_printf(("2ippWriteIO: writing value tag=%x(memberName)",
3976 IPP_TAG_MEMBERNAME
));
3977 DEBUG_printf(("2ippWriteIO: writing name=%d,\"%s\"", n
,
3979 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
3980 attr
->value_tag
, ippTagString(attr
->value_tag
)));
3981 DEBUG_puts("2ippWriteIO: writing name=0,\"\"");
3983 *bufptr
++ = IPP_TAG_MEMBERNAME
;
3988 memcpy(bufptr
, attr
->name
, n
);
3991 if (attr
->value_tag
> 0xff)
3993 *bufptr
++ = IPP_TAG_EXTENSION
;
3994 *bufptr
++ = attr
->value_tag
>> 24;
3995 *bufptr
++ = attr
->value_tag
>> 16;
3996 *bufptr
++ = attr
->value_tag
>> 8;
3997 *bufptr
++ = attr
->value_tag
;
4000 *bufptr
++ = attr
->value_tag
;
4007 * Now write the attribute value(s)...
4010 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4012 case IPP_TAG_UNSUPPORTED_VALUE
:
4013 case IPP_TAG_DEFAULT
:
4014 case IPP_TAG_UNKNOWN
:
4015 case IPP_TAG_NOVALUE
:
4016 case IPP_TAG_NOTSETTABLE
:
4017 case IPP_TAG_DELETEATTR
:
4018 case IPP_TAG_ADMINDEFINE
:
4023 case IPP_TAG_INTEGER
:
4025 for (i
= 0, value
= attr
->values
;
4026 i
< attr
->num_values
;
4029 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 9)
4031 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4033 DEBUG_puts("1ippWriteIO: Could not write IPP "
4035 ipp_buffer_release(buffer
);
4045 * Arrays and sets are done by sending additional
4046 * values with a zero-length name...
4049 *bufptr
++ = attr
->value_tag
;
4055 * Integers and enumerations are both 4-byte signed
4056 * (twos-complement) values.
4058 * Put the 2-byte length and 4-byte value into the buffer...
4063 *bufptr
++ = value
->integer
>> 24;
4064 *bufptr
++ = value
->integer
>> 16;
4065 *bufptr
++ = value
->integer
>> 8;
4066 *bufptr
++ = value
->integer
;
4070 case IPP_TAG_BOOLEAN
:
4071 for (i
= 0, value
= attr
->values
;
4072 i
< attr
->num_values
;
4075 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 6)
4077 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4079 DEBUG_puts("1ippWriteIO: Could not write IPP "
4081 ipp_buffer_release(buffer
);
4091 * Arrays and sets are done by sending additional
4092 * values with a zero-length name...
4095 *bufptr
++ = attr
->value_tag
;
4101 * Boolean values are 1-byte; 0 = false, 1 = true.
4103 * Put the 2-byte length and 1-byte value into the buffer...
4108 *bufptr
++ = value
->boolean
;
4114 case IPP_TAG_KEYWORD
:
4116 case IPP_TAG_URISCHEME
:
4117 case IPP_TAG_CHARSET
:
4118 case IPP_TAG_LANGUAGE
:
4119 case IPP_TAG_MIMETYPE
:
4120 for (i
= 0, value
= attr
->values
;
4121 i
< attr
->num_values
;
4127 * Arrays and sets are done by sending additional
4128 * values with a zero-length name...
4131 DEBUG_printf(("2ippWriteIO: writing value tag=%x(%s)",
4133 ippTagString(attr
->value_tag
)));
4134 DEBUG_printf(("2ippWriteIO: writing name=0,\"\""));
4136 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
4138 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4140 DEBUG_puts("1ippWriteIO: Could not write IPP "
4142 ipp_buffer_release(buffer
);
4149 *bufptr
++ = attr
->value_tag
;
4154 if (value
->string
.text
!= NULL
)
4155 n
= (int)strlen(value
->string
.text
);
4159 if (n
> (IPP_BUF_SIZE
- 2))
4161 DEBUG_printf(("1ippWriteIO: String too long (%d)", n
));
4162 ipp_buffer_release(buffer
);
4166 DEBUG_printf(("2ippWriteIO: writing string=%d,\"%s\"", n
,
4167 value
->string
.text
));
4169 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
4171 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4173 DEBUG_puts("1ippWriteIO: Could not write IPP "
4175 ipp_buffer_release(buffer
);
4183 * All simple strings consist of the 2-byte length and
4184 * character data without the trailing nul normally found
4185 * in C strings. Also, strings cannot be longer than IPP_MAX_LENGTH
4186 * bytes since the 2-byte length is a signed (twos-complement)
4189 * Put the 2-byte length and string characters in the buffer.
4197 memcpy(bufptr
, value
->string
.text
, n
);
4204 for (i
= 0, value
= attr
->values
;
4205 i
< attr
->num_values
;
4208 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 16)
4210 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4212 DEBUG_puts("1ippWriteIO: Could not write IPP "
4214 ipp_buffer_release(buffer
);
4224 * Arrays and sets are done by sending additional
4225 * values with a zero-length name...
4228 *bufptr
++ = attr
->value_tag
;
4234 * Date values consist of a 2-byte length and an
4235 * 11-byte date/time structure defined by RFC 1903.
4237 * Put the 2-byte length and 11-byte date/time
4238 * structure in the buffer.
4243 memcpy(bufptr
, value
->date
, 11);
4248 case IPP_TAG_RESOLUTION
:
4249 for (i
= 0, value
= attr
->values
;
4250 i
< attr
->num_values
;
4253 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 14)
4255 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4257 DEBUG_puts("1ippWriteIO: Could not write IPP "
4259 ipp_buffer_release(buffer
);
4269 * Arrays and sets are done by sending additional
4270 * values with a zero-length name...
4273 *bufptr
++ = attr
->value_tag
;
4279 * Resolution values consist of a 2-byte length,
4280 * 4-byte horizontal resolution value, 4-byte vertical
4281 * resolution value, and a 1-byte units value.
4283 * Put the 2-byte length and resolution value data
4289 *bufptr
++ = value
->resolution
.xres
>> 24;
4290 *bufptr
++ = value
->resolution
.xres
>> 16;
4291 *bufptr
++ = value
->resolution
.xres
>> 8;
4292 *bufptr
++ = value
->resolution
.xres
;
4293 *bufptr
++ = value
->resolution
.yres
>> 24;
4294 *bufptr
++ = value
->resolution
.yres
>> 16;
4295 *bufptr
++ = value
->resolution
.yres
>> 8;
4296 *bufptr
++ = value
->resolution
.yres
;
4297 *bufptr
++ = value
->resolution
.units
;
4301 case IPP_TAG_RANGE
:
4302 for (i
= 0, value
= attr
->values
;
4303 i
< attr
->num_values
;
4306 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 13)
4308 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4310 DEBUG_puts("1ippWriteIO: Could not write IPP "
4312 ipp_buffer_release(buffer
);
4322 * Arrays and sets are done by sending additional
4323 * values with a zero-length name...
4326 *bufptr
++ = attr
->value_tag
;
4332 * Range values consist of a 2-byte length,
4333 * 4-byte lower value, and 4-byte upper value.
4335 * Put the 2-byte length and range value data
4341 *bufptr
++ = value
->range
.lower
>> 24;
4342 *bufptr
++ = value
->range
.lower
>> 16;
4343 *bufptr
++ = value
->range
.lower
>> 8;
4344 *bufptr
++ = value
->range
.lower
;
4345 *bufptr
++ = value
->range
.upper
>> 24;
4346 *bufptr
++ = value
->range
.upper
>> 16;
4347 *bufptr
++ = value
->range
.upper
>> 8;
4348 *bufptr
++ = value
->range
.upper
;
4352 case IPP_TAG_TEXTLANG
:
4353 case IPP_TAG_NAMELANG
:
4354 for (i
= 0, value
= attr
->values
;
4355 i
< attr
->num_values
;
4361 * Arrays and sets are done by sending additional
4362 * values with a zero-length name...
4365 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
4367 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4369 DEBUG_puts("1ippWriteIO: Could not write IPP "
4371 ipp_buffer_release(buffer
);
4378 *bufptr
++ = attr
->value_tag
;
4384 * textWithLanguage and nameWithLanguage values consist
4385 * of a 2-byte length for both strings and their
4386 * individual lengths, a 2-byte length for the
4387 * character string, the character string without the
4388 * trailing nul, a 2-byte length for the character
4389 * set string, and the character set string without
4395 if (value
->string
.language
!= NULL
)
4396 n
+= (int)strlen(value
->string
.language
);
4398 if (value
->string
.text
!= NULL
)
4399 n
+= (int)strlen(value
->string
.text
);
4401 if (n
> (IPP_BUF_SIZE
- 2))
4403 DEBUG_printf(("1ippWriteIO: text/nameWithLanguage value "
4404 "too long (%d)", n
));
4405 ipp_buffer_release(buffer
);
4409 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
4411 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4413 DEBUG_puts("1ippWriteIO: Could not write IPP "
4415 ipp_buffer_release(buffer
);
4422 /* Length of entire value */
4426 /* Length of language */
4427 if (value
->string
.language
!= NULL
)
4428 n
= (int)strlen(value
->string
.language
);
4438 memcpy(bufptr
, value
->string
.language
, n
);
4442 /* Length of text */
4443 if (value
->string
.text
!= NULL
)
4444 n
= (int)strlen(value
->string
.text
);
4454 memcpy(bufptr
, value
->string
.text
, n
);
4460 case IPP_TAG_BEGIN_COLLECTION
:
4461 for (i
= 0, value
= attr
->values
;
4462 i
< attr
->num_values
;
4466 * Collections are written with the begin-collection
4467 * tag first with a value of 0 length, followed by the
4468 * attributes in the collection, then the end-collection
4472 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 5)
4474 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4476 DEBUG_puts("1ippWriteIO: Could not write IPP "
4478 ipp_buffer_release(buffer
);
4488 * Arrays and sets are done by sending additional
4489 * values with a zero-length name...
4492 *bufptr
++ = attr
->value_tag
;
4498 * Write a data length of 0 and flush the buffer...
4504 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4506 DEBUG_puts("1ippWriteIO: Could not write IPP "
4508 ipp_buffer_release(buffer
);
4515 * Then write the collection attribute...
4518 value
->collection
->state
= IPP_IDLE
;
4520 if (ippWriteIO(dst
, cb
, 1, ipp
,
4521 value
->collection
) == IPP_ERROR
)
4523 DEBUG_puts("1ippWriteIO: Unable to write collection value");
4524 ipp_buffer_release(buffer
);
4531 for (i
= 0, value
= attr
->values
;
4532 i
< attr
->num_values
;
4538 * Arrays and sets are done by sending additional
4539 * values with a zero-length name...
4542 if ((IPP_BUF_SIZE
- (bufptr
- buffer
)) < 3)
4544 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4546 DEBUG_puts("1ippWriteIO: Could not write IPP "
4548 ipp_buffer_release(buffer
);
4555 *bufptr
++ = attr
->value_tag
;
4561 * An unknown value might some new value that a
4562 * vendor has come up with. It consists of a
4563 * 2-byte length and the bytes in the unknown
4567 n
= value
->unknown
.length
;
4569 if (n
> (IPP_BUF_SIZE
- 2))
4571 DEBUG_printf(("1ippWriteIO: Data length too long (%d)",
4573 ipp_buffer_release(buffer
);
4577 if ((int)(IPP_BUF_SIZE
- (bufptr
- buffer
)) < (n
+ 2))
4579 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4581 DEBUG_puts("1ippWriteIO: Could not write IPP "
4583 ipp_buffer_release(buffer
);
4590 /* Length of unknown value */
4597 memcpy(bufptr
, value
->unknown
.data
, n
);
4605 * Write the data out...
4608 if (bufptr
> buffer
)
4610 if ((*cb
)(dst
, buffer
, (int)(bufptr
- buffer
)) < 0)
4612 DEBUG_puts("1ippWriteIO: Could not write IPP attribute...");
4613 ipp_buffer_release(buffer
);
4617 DEBUG_printf(("2ippWriteIO: wrote %d bytes",
4618 (int)(bufptr
- buffer
)));
4622 * If blocking is disabled, stop here...
4629 if (ipp
->current
== NULL
)
4632 * Done with all of the attributes; add the end-of-attributes
4633 * tag or end-collection attribute...
4638 buffer
[0] = IPP_TAG_END
;
4643 buffer
[0] = IPP_TAG_END_COLLECTION
;
4644 buffer
[1] = 0; /* empty name */
4646 buffer
[3] = 0; /* empty value */
4651 if ((*cb
)(dst
, buffer
, n
) < 0)
4653 DEBUG_puts("1ippWriteIO: Could not write IPP end-tag...");
4654 ipp_buffer_release(buffer
);
4658 ipp
->state
= IPP_DATA
;
4666 break; /* anti-compiler-warning-code */
4669 ipp_buffer_release(buffer
);
4671 return (ipp
->state
);
4676 * 'ipp_add_attr()' - Add a new attribute to the message.
4679 static ipp_attribute_t
* /* O - New attribute */
4680 ipp_add_attr(ipp_t
*ipp
, /* I - IPP message */
4681 const char *name
, /* I - Attribute name or NULL */
4682 ipp_tag_t group_tag
, /* I - Group tag or IPP_TAG_ZERO */
4683 ipp_tag_t value_tag
, /* I - Value tag or IPP_TAG_ZERO */
4684 int num_values
) /* I - Number of values */
4686 int alloc_values
; /* Number of values to allocate */
4687 ipp_attribute_t
*attr
; /* New attribute */
4690 DEBUG_printf(("4ipp_add_attr(ipp=%p, name=\"%s\", group_tag=0x%x, value_tag=0x%x, "
4691 "num_values=%d)", ipp
, name
, group_tag
, value_tag
, num_values
));
4694 * Range check input...
4697 if (!ipp
|| num_values
< 0)
4701 * Allocate memory, rounding the allocation up as needed...
4704 if (num_values
<= 1)
4705 alloc_values
= num_values
;
4707 alloc_values
= (num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
4709 attr
= calloc(sizeof(ipp_attribute_t
) +
4710 (alloc_values
- 1) * sizeof(_ipp_value_t
), 1);
4715 * Initialize attribute...
4719 attr
->name
= _cupsStrAlloc(name
);
4721 attr
->group_tag
= group_tag
;
4722 attr
->value_tag
= value_tag
;
4723 attr
->num_values
= num_values
;
4726 * Add it to the end of the linked list...
4730 ipp
->last
->next
= attr
;
4734 ipp
->prev
= ipp
->last
;
4735 ipp
->last
= ipp
->current
= attr
;
4738 DEBUG_printf(("5ipp_add_attr: Returning %p", attr
));
4745 * 'ipp_buffer_get()' - Get a read/write buffer.
4748 static unsigned char * /* O - Buffer */
4749 ipp_buffer_get(void)
4751 _ipp_buffer_t
*buffer
; /* Current buffer */
4752 _cups_globals_t
*cg
= _cupsGlobals();
4756 for (buffer
= cg
->ipp_buffers
; buffer
; buffer
= buffer
->next
)
4763 if ((buffer
= malloc(sizeof(_ipp_buffer_t
))) == NULL
)
4767 buffer
->next
= cg
->ipp_buffers
;
4768 cg
->ipp_buffers
= buffer
;
4775 * 'ipp_buffer_release()' - Release a read/write buffer.
4779 ipp_buffer_release(unsigned char *b
) /* I - Buffer to release */
4781 ((_ipp_buffer_t
*)b
)->used
= 0;
4786 * 'ipp_free_values()' - Free attribute values.
4790 ipp_free_values(ipp_attribute_t
*attr
, /* I - Attribute to free values from */
4791 int element
,/* I - First value to free */
4792 int count
) /* I - Number of values to free */
4794 int i
; /* Looping var */
4795 _ipp_value_t
*value
; /* Current value */
4798 DEBUG_printf(("4ipp_free_values(attr=%p, element=%d, count=%d)", attr
, element
, count
));
4800 if (!(attr
->value_tag
& IPP_TAG_COPY
))
4803 * Free values as needed...
4806 switch (attr
->value_tag
)
4808 case IPP_TAG_TEXTLANG
:
4809 case IPP_TAG_NAMELANG
:
4810 if (element
== 0 && count
== attr
->num_values
&& attr
->values
[0].string
.language
)
4811 _cupsStrFree(attr
->values
[0].string
.language
);
4815 case IPP_TAG_RESERVED_STRING
:
4816 case IPP_TAG_KEYWORD
:
4818 case IPP_TAG_URISCHEME
:
4819 case IPP_TAG_CHARSET
:
4820 case IPP_TAG_LANGUAGE
:
4821 case IPP_TAG_MIMETYPE
:
4822 for (i
= count
, value
= attr
->values
+ element
;
4825 _cupsStrFree(value
->string
.text
);
4828 case IPP_TAG_DEFAULT
:
4829 case IPP_TAG_UNKNOWN
:
4830 case IPP_TAG_NOVALUE
:
4831 case IPP_TAG_NOTSETTABLE
:
4832 case IPP_TAG_DELETEATTR
:
4833 case IPP_TAG_ADMINDEFINE
:
4834 case IPP_TAG_INTEGER
:
4836 case IPP_TAG_BOOLEAN
:
4838 case IPP_TAG_RESOLUTION
:
4839 case IPP_TAG_RANGE
:
4842 case IPP_TAG_BEGIN_COLLECTION
:
4843 for (i
= count
, value
= attr
->values
+ element
;
4846 ippDelete(value
->collection
);
4849 case IPP_TAG_STRING
:
4851 for (i
= count
, value
= attr
->values
+ element
;
4854 if (value
->unknown
.data
)
4855 free(value
->unknown
.data
);
4861 * If we are not freeing values from the end, move the remaining values up...
4864 if ((element
+ count
) < attr
->num_values
)
4865 memmove(attr
->values
+ element
, attr
->values
+ element
+ count
,
4866 (attr
->num_values
- count
- element
) * sizeof(_ipp_value_t
));
4868 attr
->num_values
-= count
;
4873 * 'ipp_get_code()' - Convert a C locale/charset name into an IPP language/charset code.
4875 * This typically converts strings of the form "ll_CC", "ll-REGION", and "CHARSET_NUMBER"
4876 * to "ll-cc", "ll-region", and "charset-number", respectively.
4879 static char * /* O - Language code string */
4880 ipp_get_code(const char *value
, /* I - Locale/charset string */
4881 char *buffer
, /* I - String buffer */
4882 size_t bufsize
) /* I - Size of string buffer */
4884 char *bufptr
, /* Pointer into buffer */
4885 *bufend
; /* End of buffer */
4889 * Convert values to lowercase and change _ to - as needed...
4892 for (bufptr
= buffer
, bufend
= buffer
+ bufsize
- 1;
4893 *value
&& bufptr
< bufend
;
4898 *bufptr
++ = _cups_tolower(*value
);
4903 * Return the converted string...
4911 * 'ipp_lang_code()' - Convert a C locale name into an IPP language code.
4913 * This typically converts strings of the form "ll_CC" and "ll-REGION" to "ll-cc" and
4914 * "ll-region", respectively. It also converts the "C" (POSIX) locale to "en".
4917 static char * /* O - Language code string */
4918 ipp_lang_code(const char *locale
, /* I - Locale string */
4919 char *buffer
, /* I - String buffer */
4920 size_t bufsize
) /* I - Size of string buffer */
4923 * Map POSIX ("C") locale to generic English, otherwise convert the locale string as-is.
4926 if (!_cups_strcasecmp(locale
, "c"))
4928 strlcpy(buffer
, "en", bufsize
);
4932 return (ipp_get_code(locale
, buffer
, bufsize
));
4937 * 'ipp_length()' - Compute the length of an IPP message or collection value.
4940 static size_t /* O - Size of IPP message */
4941 ipp_length(ipp_t
*ipp
, /* I - IPP message or collection */
4942 int collection
) /* I - 1 if a collection, 0 otherwise */
4944 int i
; /* Looping var */
4945 size_t bytes
; /* Number of bytes */
4946 ipp_attribute_t
*attr
; /* Current attribute */
4947 ipp_tag_t group
; /* Current group */
4948 _ipp_value_t
*value
; /* Current value */
4951 DEBUG_printf(("3ipp_length(ipp=%p, collection=%d)", ipp
, collection
));
4955 DEBUG_puts("4ipp_length: Returning 0 bytes");
4960 * Start with 8 bytes for the IPP message header...
4963 bytes
= collection
? 0 : 8;
4966 * Then add the lengths of each attribute...
4969 group
= IPP_TAG_ZERO
;
4971 for (attr
= ipp
->attrs
; attr
!= NULL
; attr
= attr
->next
)
4973 if (attr
->group_tag
!= group
&& !collection
)
4975 group
= attr
->group_tag
;
4976 if (group
== IPP_TAG_ZERO
)
4979 bytes
++; /* Group tag */
4985 DEBUG_printf(("5ipp_length: attr->name=\"%s\", attr->num_values=%d, "
4986 "bytes=" CUPS_LLFMT
, attr
->name
, attr
->num_values
, CUPS_LLCAST bytes
));
4988 if (attr
->value_tag
< IPP_TAG_EXTENSION
)
4989 bytes
+= attr
->num_values
; /* Value tag for each value */
4991 bytes
+= 5 * attr
->num_values
; /* Value tag for each value */
4992 bytes
+= 2 * attr
->num_values
; /* Name lengths */
4993 bytes
+= (int)strlen(attr
->name
); /* Name */
4994 bytes
+= 2 * attr
->num_values
; /* Value lengths */
4997 bytes
+= 5; /* Add membername overhead */
4999 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
5001 case IPP_TAG_UNSUPPORTED_VALUE
:
5002 case IPP_TAG_DEFAULT
:
5003 case IPP_TAG_UNKNOWN
:
5004 case IPP_TAG_NOVALUE
:
5005 case IPP_TAG_NOTSETTABLE
:
5006 case IPP_TAG_DELETEATTR
:
5007 case IPP_TAG_ADMINDEFINE
:
5010 case IPP_TAG_INTEGER
:
5012 bytes
+= 4 * attr
->num_values
;
5015 case IPP_TAG_BOOLEAN
:
5016 bytes
+= attr
->num_values
;
5021 case IPP_TAG_KEYWORD
:
5023 case IPP_TAG_URISCHEME
:
5024 case IPP_TAG_CHARSET
:
5025 case IPP_TAG_LANGUAGE
:
5026 case IPP_TAG_MIMETYPE
:
5027 for (i
= 0, value
= attr
->values
;
5028 i
< attr
->num_values
;
5030 if (value
->string
.text
)
5031 bytes
+= strlen(value
->string
.text
);
5035 bytes
+= 11 * attr
->num_values
;
5038 case IPP_TAG_RESOLUTION
:
5039 bytes
+= 9 * attr
->num_values
;
5042 case IPP_TAG_RANGE
:
5043 bytes
+= 8 * attr
->num_values
;
5046 case IPP_TAG_TEXTLANG
:
5047 case IPP_TAG_NAMELANG
:
5048 bytes
+= 4 * attr
->num_values
;/* Charset + text length */
5050 for (i
= 0, value
= attr
->values
;
5051 i
< attr
->num_values
;
5054 if (value
->string
.language
)
5055 bytes
+= strlen(value
->string
.language
);
5057 if (value
->string
.text
)
5058 bytes
+= strlen(value
->string
.text
);
5062 case IPP_TAG_BEGIN_COLLECTION
:
5063 for (i
= 0, value
= attr
->values
;
5064 i
< attr
->num_values
;
5066 bytes
+= ipp_length(value
->collection
, 1);
5070 for (i
= 0, value
= attr
->values
;
5071 i
< attr
->num_values
;
5073 bytes
+= value
->unknown
.length
;
5079 * Finally, add 1 byte for the "end of attributes" tag or 5 bytes
5080 * for the "end of collection" tag and return...
5088 DEBUG_printf(("4ipp_length: Returning " CUPS_LLFMT
" bytes", CUPS_LLCAST bytes
));
5095 * 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
5098 static ssize_t
/* O - Number of bytes read */
5099 ipp_read_http(http_t
*http
, /* I - Client connection */
5100 ipp_uchar_t
*buffer
, /* O - Buffer for data */
5101 size_t length
) /* I - Total length */
5103 int tbytes
, /* Total bytes read */
5104 bytes
; /* Bytes read this pass */
5105 char len
[32]; /* Length string */
5108 DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)",
5109 http
, buffer
, (int)length
));
5112 * Loop until all bytes are read...
5115 for (tbytes
= 0, bytes
= 0;
5116 tbytes
< (int)length
;
5117 tbytes
+= bytes
, buffer
+= bytes
)
5119 DEBUG_printf(("9ipp_read_http: tbytes=%d, http->state=%d", tbytes
,
5122 if (http
->state
== HTTP_WAITING
)
5125 if (http
->used
> 0 && http
->data_encoding
== HTTP_ENCODE_LENGTH
)
5128 * Do "fast read" from HTTP buffer directly...
5131 if (http
->used
> (int)(length
- tbytes
))
5132 bytes
= (int)(length
- tbytes
);
5137 buffer
[0] = http
->buffer
[0];
5139 memcpy(buffer
, http
->buffer
, bytes
);
5141 http
->used
-= bytes
;
5142 http
->data_remaining
-= bytes
;
5144 if (http
->data_remaining
<= INT_MAX
)
5145 http
->_data_remaining
= (int)http
->data_remaining
;
5147 http
->_data_remaining
= INT_MAX
;
5150 memmove(http
->buffer
, http
->buffer
+ bytes
, http
->used
);
5152 if (http
->data_remaining
== 0)
5154 if (http
->data_encoding
== HTTP_ENCODE_CHUNKED
)
5157 * Get the trailing CR LF after the chunk...
5160 if (!httpGets(len
, sizeof(len
), http
))
5164 if (http
->data_encoding
!= HTTP_ENCODE_CHUNKED
)
5166 if (http
->state
== HTTP_POST_RECV
)
5169 http
->state
= HTTP_WAITING
;
5176 * Wait a maximum of 1 second for data...
5179 if (!http
->blocking
)
5182 * Wait up to 10 seconds for more data on non-blocking sockets...
5185 if (!httpWait(http
, 10000))
5196 if ((bytes
= httpRead2(http
, (char *)buffer
, length
- tbytes
)) < 0)
5201 if (errno
!= EAGAIN
&& errno
!= EINTR
)
5207 else if (bytes
== 0)
5213 * Return the number of bytes read...
5216 if (tbytes
== 0 && bytes
< 0)
5219 DEBUG_printf(("8ipp_read_http: Returning %d bytes", tbytes
));
5226 * 'ipp_read_file()' - Read IPP data from a file.
5229 static ssize_t
/* O - Number of bytes read */
5230 ipp_read_file(int *fd
, /* I - File descriptor */
5231 ipp_uchar_t
*buffer
, /* O - Read buffer */
5232 size_t length
) /* I - Number of bytes to read */
5235 return ((ssize_t
)read(*fd
, buffer
, (unsigned)length
));
5237 return (read(*fd
, buffer
, length
));
5243 * 'ipp_set_value()' - Get the value element from an attribute, expanding it as needed.
5246 static _ipp_value_t
* /* O - IPP value element or NULL on error */
5247 ipp_set_value(ipp_t
*ipp
, /* I - IPP message */
5248 ipp_attribute_t
**attr
, /* IO - IPP attribute */
5249 int element
) /* I - Value number (0-based) */
5251 ipp_attribute_t
*temp
, /* New attribute pointer */
5252 *current
, /* Current attribute in list */
5253 *prev
; /* Previous attribute in list */
5254 int alloc_values
; /* Allocated values */
5258 * If we are setting an existing value element, return it...
5263 if (temp
->num_values
<= 1)
5264 alloc_values
= temp
->num_values
;
5266 alloc_values
= (temp
->num_values
+ IPP_MAX_VALUES
- 1) & ~(IPP_MAX_VALUES
- 1);
5268 if (element
< alloc_values
)
5269 return (temp
->values
+ element
);
5272 * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE values
5273 * when num_values > 1.
5276 if (alloc_values
< IPP_MAX_VALUES
)
5277 alloc_values
= IPP_MAX_VALUES
;
5279 alloc_values
+= IPP_MAX_VALUES
;
5281 DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.", alloc_values
));
5284 * Reallocate memory...
5287 if ((temp
= realloc(temp
, sizeof(ipp_attribute_t
) +
5288 (temp
->num_values
+ IPP_MAX_VALUES
- 1) *
5289 sizeof(_ipp_value_t
))) == NULL
)
5291 _cupsSetHTTPError(HTTP_ERROR
);
5292 DEBUG_puts("4ipp_set_value: Unable to resize attribute.");
5297 * Zero the new memory...
5300 memset(temp
->values
+ temp
->num_values
, 0,
5301 (alloc_values
- temp
->num_values
) * sizeof(_ipp_value_t
));
5306 * Reset pointers in the list...
5309 if (ipp
->current
== *attr
&& ipp
->prev
)
5312 * Use current "previous" pointer...
5320 * Find this attribute in the linked list...
5323 for (prev
= NULL
, current
= ipp
->attrs
;
5324 current
&& current
!= *attr
;
5325 prev
= current
, current
= current
->next
);
5330 * This is a serious error!
5334 _cupsSetError(IPP_ERROR
, _("IPP attribute is not a member of the message."), 1);
5335 DEBUG_puts("4ipp_set_value: Unable to find attribute in message.");
5345 ipp
->current
= temp
;
5348 if (ipp
->last
== *attr
)
5355 * Return the value element...
5358 return (temp
->values
+ element
);
5363 * 'ipp_write_file()' - Write IPP data to a file.
5366 static ssize_t
/* O - Number of bytes written */
5367 ipp_write_file(int *fd
, /* I - File descriptor */
5368 ipp_uchar_t
*buffer
, /* I - Data to write */
5369 size_t length
) /* I - Number of bytes to write */
5372 return ((ssize_t
)write(*fd
, buffer
, (unsigned)length
));
5374 return (write(*fd
, buffer
, length
));
5380 * End of "$Id: ipp.c 10102 2011-11-02 23:52:39Z mike $".