]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testipp.c
4 * IPP test program for CUPS.
6 * Copyright 2007-2014 by Apple Inc.
7 * Copyright 1997-2005 by Easy Software Products.
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 * Include necessary headers...
23 #include "string-private.h"
24 #include "ipp-private.h"
37 typedef struct _ippdata_t
39 size_t rpos
, /* Read position */
40 wused
, /* Bytes used */
41 wsize
; /* Max size of buffer */
42 ipp_uchar_t
*wbuffer
; /* Buffer */
50 static ipp_uchar_t collection
[] = /* Collection buffer */
52 0x01, 0x01, /* IPP version */
53 0x00, 0x02, /* Print-Job operation */
54 0x00, 0x00, 0x00, 0x01,
60 0x00, 0x12, /* Name length + name */
61 'a','t','t','r','i','b','u','t','e','s','-',
62 'c','h','a','r','s','e','t',
63 0x00, 0x05, /* Value length + value */
67 0x00, 0x1b, /* Name length + name */
68 'a','t','t','r','i','b','u','t','e','s','-',
69 'n','a','t','u','r','a','l','-','l','a','n',
71 0x00, 0x02, /* Value length + value */
75 0x00, 0x0b, /* Name length + name */
76 'p','r','i','n','t','e','r','-','u','r','i',
77 0x00, 0x1c, /* Value length + value */
78 'i','p','p',':','/','/','l','o','c','a','l',
79 'h','o','s','t','/','p','r','i','n','t','e',
80 'r','s','/','f','o','o',
82 IPP_TAG_JOB
, /* job group tag */
84 IPP_TAG_BEGIN_COLLECTION
,
85 /* begCollection tag */
86 0x00, 0x09, /* Name length + name */
87 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l',
88 0x00, 0x00, /* No value */
89 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
90 0x00, 0x00, /* No name */
91 0x00, 0x0a, /* Value length + value */
92 'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e',
93 IPP_TAG_BEGIN_COLLECTION
,
94 /* begCollection tag */
95 0x00, 0x00, /* Name length + name */
96 0x00, 0x00, /* No value */
98 /* memberAttrName tag */
99 0x00, 0x00, /* No name */
100 0x00, 0x0b, /* Value length + value */
101 'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
102 IPP_TAG_INTEGER
, /* integer tag */
103 0x00, 0x00, /* No name */
104 0x00, 0x04, /* Value length + value */
105 0x00, 0x00, 0x54, 0x56,
107 /* memberAttrName tag */
108 0x00, 0x00, /* No name */
109 0x00, 0x0b, /* Value length + value */
110 'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
111 IPP_TAG_INTEGER
, /* integer tag */
112 0x00, 0x00, /* No name */
113 0x00, 0x04, /* Value length + value */
114 0x00, 0x00, 0x6d, 0x24,
115 IPP_TAG_END_COLLECTION
,
116 /* endCollection tag */
117 0x00, 0x00, /* No name */
118 0x00, 0x00, /* No value */
119 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
120 0x00, 0x00, /* No name */
121 0x00, 0x0b, /* Value length + value */
122 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', 'o', 'r',
123 IPP_TAG_KEYWORD
, /* keyword tag */
124 0x00, 0x00, /* No name */
125 0x00, 0x04, /* Value length + value */
128 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
129 0x00, 0x00, /* No name */
130 0x00, 0x0a, /* Value length + value */
131 'm', 'e', 'd', 'i', 'a', '-', 't', 'y', 'p', 'e',
132 IPP_TAG_KEYWORD
, /* keyword tag */
133 0x00, 0x00, /* No name */
134 0x00, 0x05, /* Value length + value */
135 'p', 'l', 'a', 'i', 'n',
136 IPP_TAG_END_COLLECTION
,
137 /* endCollection tag */
138 0x00, 0x00, /* No name */
139 0x00, 0x00, /* No value */
141 IPP_TAG_BEGIN_COLLECTION
,
142 /* begCollection tag */
143 0x00, 0x00, /* No name */
144 0x00, 0x00, /* No value */
145 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
146 0x00, 0x00, /* No name */
147 0x00, 0x0a, /* Value length + value */
148 'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e',
149 IPP_TAG_BEGIN_COLLECTION
,
150 /* begCollection tag */
151 0x00, 0x00, /* Name length + name */
152 0x00, 0x00, /* No value */
154 /* memberAttrName tag */
155 0x00, 0x00, /* No name */
156 0x00, 0x0b, /* Value length + value */
157 'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
158 IPP_TAG_INTEGER
, /* integer tag */
159 0x00, 0x00, /* No name */
160 0x00, 0x04, /* Value length + value */
161 0x00, 0x00, 0x52, 0x08,
163 /* memberAttrName tag */
164 0x00, 0x00, /* No name */
165 0x00, 0x0b, /* Value length + value */
166 'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
167 IPP_TAG_INTEGER
, /* integer tag */
168 0x00, 0x00, /* No name */
169 0x00, 0x04, /* Value length + value */
170 0x00, 0x00, 0x74, 0x04,
171 IPP_TAG_END_COLLECTION
,
172 /* endCollection tag */
173 0x00, 0x00, /* No name */
174 0x00, 0x00, /* No value */
175 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
176 0x00, 0x00, /* No name */
177 0x00, 0x0b, /* Value length + value */
178 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', 'o', 'r',
179 IPP_TAG_KEYWORD
, /* keyword tag */
180 0x00, 0x00, /* No name */
181 0x00, 0x05, /* Value length + value */
182 'p', 'l', 'a', 'i', 'd',
184 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
185 0x00, 0x00, /* No name */
186 0x00, 0x0a, /* Value length + value */
187 'm', 'e', 'd', 'i', 'a', '-', 't', 'y', 'p', 'e',
188 IPP_TAG_KEYWORD
, /* keyword tag */
189 0x00, 0x00, /* No name */
190 0x00, 0x06, /* Value length + value */
191 'g', 'l', 'o', 's', 's', 'y',
192 IPP_TAG_END_COLLECTION
,
193 /* endCollection tag */
194 0x00, 0x00, /* No name */
195 0x00, 0x00, /* No value */
197 IPP_TAG_END
/* end tag */
200 static ipp_uchar_t mixed
[] = /* Mixed value buffer */
202 0x01, 0x01, /* IPP version */
203 0x00, 0x02, /* Print-Job operation */
204 0x00, 0x00, 0x00, 0x01,
209 IPP_TAG_INTEGER
, /* integer tag */
210 0x00, 0x1f, /* Name length + name */
211 'n', 'o', 't', 'i', 'f', 'y', '-', 'l', 'e', 'a', 's', 'e',
212 '-', 'd', 'u', 'r', 'a', 't', 'i', 'o', 'n', '-', 's', 'u',
213 'p', 'p', 'o', 'r', 't', 'e', 'd',
214 0x00, 0x04, /* Value length + value */
215 0x00, 0x00, 0x00, 0x01,
217 IPP_TAG_RANGE
, /* rangeOfInteger tag */
218 0x00, 0x00, /* No name */
219 0x00, 0x08, /* Value length + value */
220 0x00, 0x00, 0x00, 0x10,
221 0x00, 0x00, 0x00, 0x20,
223 IPP_TAG_END
/* end tag */
231 void hex_dump(const char *title
, ipp_uchar_t
*buffer
, size_t bytes
);
232 void print_attributes(ipp_t
*ipp
, int indent
);
233 ssize_t
read_cb(_ippdata_t
*data
, ipp_uchar_t
*buffer
, size_t bytes
);
234 ssize_t
write_cb(_ippdata_t
*data
, ipp_uchar_t
*buffer
, size_t bytes
);
238 * 'main()' - Main entry.
241 int /* O - Exit status */
242 main(int argc
, /* I - Number of command-line arguments */
243 char *argv
[]) /* I - Command-line arguments */
245 _ippdata_t data
; /* IPP buffer */
246 ipp_uchar_t buffer
[8192]; /* Write buffer data */
247 ipp_t
*cols
[2], /* Collections */
248 *size
; /* media-size collection */
249 ipp_t
*request
; /* Request */
250 ipp_attribute_t
*media_col
, /* media-col attribute */
251 *media_size
, /* media-size attribute */
252 *attr
; /* Other attribute */
253 ipp_state_t state
; /* State */
254 size_t length
; /* Length of data */
255 cups_file_t
*fp
; /* File pointer */
256 size_t i
; /* Looping var */
257 int status
; /* Status of tests (0 = success, 1 = fail) */
259 const char *name
; /* Option name */
268 * Test request generation code...
271 printf("Create Sample Request: ");
274 request
->request
.op
.version
[0] = 0x01;
275 request
->request
.op
.version
[1] = 0x01;
276 request
->request
.op
.operation_id
= IPP_OP_PRINT_JOB
;
277 request
->request
.op
.request_id
= 1;
279 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
280 "attributes-charset", NULL
, "utf-8");
281 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
282 "attributes-natural-language", NULL
, "en");
283 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
284 "printer-uri", NULL
, "ipp://localhost/printers/foo");
288 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "x-dimension", 21590);
289 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "y-dimension", 27940);
290 ippAddCollection(cols
[0], IPP_TAG_JOB
, "media-size", size
);
292 ippAddString(cols
[0], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-color", NULL
,
294 ippAddString(cols
[0], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-type", NULL
,
299 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "x-dimension", 21000);
300 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "y-dimension", 29700);
301 ippAddCollection(cols
[1], IPP_TAG_JOB
, "media-size", size
);
303 ippAddString(cols
[1], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-color", NULL
,
305 ippAddString(cols
[1], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-type", NULL
,
308 ippAddCollections(request
, IPP_TAG_JOB
, "media-col", 2,
309 (const ipp_t
**)cols
);
313 length
= ippLength(request
);
314 if (length
!= sizeof(collection
))
316 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
317 (int)length
, (int)sizeof(collection
));
327 printf("Write Sample to Memory: ");
330 data
.wsize
= sizeof(buffer
);
331 data
.wbuffer
= buffer
;
333 while ((state
= ippWriteIO(&data
, (ipp_iocb_t
)write_cb
, 1, NULL
,
334 request
)) != IPP_STATE_DATA
)
335 if (state
== IPP_STATE_ERROR
)
338 if (state
!= IPP_STATE_DATA
)
340 printf("FAIL - %d bytes written.\n", (int)data
.wused
);
343 else if (data
.wused
!= sizeof(collection
))
345 printf("FAIL - wrote %d bytes, expected %d bytes!\n", (int)data
.wused
,
346 (int)sizeof(collection
));
347 hex_dump("Bytes Written", data
.wbuffer
, data
.wused
);
348 hex_dump("Baseline", collection
, sizeof(collection
));
351 else if (memcmp(data
.wbuffer
, collection
, data
.wused
))
353 for (i
= 0; i
< data
.wused
; i
++)
354 if (data
.wbuffer
[i
] != collection
[i
])
357 printf("FAIL - output does not match baseline at 0x%04x!\n", (unsigned)i
);
358 hex_dump("Bytes Written", data
.wbuffer
, data
.wused
);
359 hex_dump("Baseline", collection
, sizeof(collection
));
368 * Read the data back in and confirm...
371 printf("Read Sample from Memory: ");
376 while ((state
= ippReadIO(&data
, (ipp_iocb_t
)read_cb
, 1, NULL
,
377 request
)) != IPP_STATE_DATA
)
378 if (state
== IPP_STATE_ERROR
)
381 length
= ippLength(request
);
383 if (state
!= IPP_STATE_DATA
)
385 printf("FAIL - %d bytes read.\n", (int)data
.rpos
);
388 else if (data
.rpos
!= data
.wused
)
390 printf("FAIL - read %d bytes, expected %d bytes!\n", (int)data
.rpos
,
392 print_attributes(request
, 8);
395 else if (length
!= sizeof(collection
))
397 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
398 (int)length
, (int)sizeof(collection
));
399 print_attributes(request
, 8);
405 fputs("ippFindAttribute(media-col): ", stdout
);
406 if ((media_col
= ippFindAttribute(request
, "media-col",
407 IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
409 if ((media_col
= ippFindAttribute(request
, "media-col",
410 IPP_TAG_ZERO
)) == NULL
)
411 puts("FAIL (not found)");
413 printf("FAIL (wrong type - %s)\n", ippTagString(media_col
->value_tag
));
417 else if (media_col
->num_values
!= 2)
419 printf("FAIL (wrong count - %d)\n", media_col
->num_values
);
427 fputs("ippFindAttribute(media-size 1): ", stdout
);
428 if ((media_size
= ippFindAttribute(media_col
->values
[0].collection
,
430 IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
432 if ((media_size
= ippFindAttribute(media_col
->values
[0].collection
,
434 IPP_TAG_ZERO
)) == NULL
)
435 puts("FAIL (not found)");
437 printf("FAIL (wrong type - %s)\n",
438 ippTagString(media_size
->value_tag
));
444 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
445 "x-dimension", IPP_TAG_INTEGER
)) == NULL
)
447 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
448 "x-dimension", IPP_TAG_ZERO
)) == NULL
)
449 puts("FAIL (missing x-dimension)");
451 printf("FAIL (wrong type for x-dimension - %s)\n",
452 ippTagString(attr
->value_tag
));
456 else if (attr
->values
[0].integer
!= 21590)
458 printf("FAIL (wrong value for x-dimension - %d)\n",
459 attr
->values
[0].integer
);
462 else if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
464 IPP_TAG_INTEGER
)) == NULL
)
466 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
467 "y-dimension", IPP_TAG_ZERO
)) == NULL
)
468 puts("FAIL (missing y-dimension)");
470 printf("FAIL (wrong type for y-dimension - %s)\n",
471 ippTagString(attr
->value_tag
));
475 else if (attr
->values
[0].integer
!= 27940)
477 printf("FAIL (wrong value for y-dimension - %d)\n",
478 attr
->values
[0].integer
);
485 fputs("ippFindAttribute(media-size 2): ", stdout
);
486 if ((media_size
= ippFindAttribute(media_col
->values
[1].collection
,
488 IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
490 if ((media_size
= ippFindAttribute(media_col
->values
[1].collection
,
492 IPP_TAG_ZERO
)) == NULL
)
493 puts("FAIL (not found)");
495 printf("FAIL (wrong type - %s)\n",
496 ippTagString(media_size
->value_tag
));
502 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
504 IPP_TAG_INTEGER
)) == NULL
)
506 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
507 "x-dimension", IPP_TAG_ZERO
)) == NULL
)
508 puts("FAIL (missing x-dimension)");
510 printf("FAIL (wrong type for x-dimension - %s)\n",
511 ippTagString(attr
->value_tag
));
515 else if (attr
->values
[0].integer
!= 21000)
517 printf("FAIL (wrong value for x-dimension - %d)\n",
518 attr
->values
[0].integer
);
521 else if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
523 IPP_TAG_INTEGER
)) == NULL
)
525 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
526 "y-dimension", IPP_TAG_ZERO
)) == NULL
)
527 puts("FAIL (missing y-dimension)");
529 printf("FAIL (wrong type for y-dimension - %s)\n",
530 ippTagString(attr
->value_tag
));
534 else if (attr
->values
[0].integer
!= 29700)
536 printf("FAIL (wrong value for y-dimension - %d)\n",
537 attr
->values
[0].integer
);
546 * Test hierarchical find...
549 fputs("ippFindAttribute(media-col/media-size/x-dimension): ", stdout
);
550 if ((attr
= ippFindAttribute(request
, "media-col/media-size/x-dimension", IPP_TAG_INTEGER
)) != NULL
)
552 if (ippGetInteger(attr
, 0) != 21590)
554 printf("FAIL (wrong value for x-dimension - %d)\n", ippGetInteger(attr
, 0));
562 puts("FAIL (not found)");
566 fputs("ippFindNextAttribute(media-col/media-size/x-dimension): ", stdout
);
567 if ((attr
= ippFindNextAttribute(request
, "media-col/media-size/x-dimension", IPP_TAG_INTEGER
)) != NULL
)
569 if (ippGetInteger(attr
, 0) != 21000)
571 printf("FAIL (wrong value for x-dimension - %d)\n", ippGetInteger(attr
, 0));
579 puts("FAIL (not found)");
583 fputs("ippFindNextAttribute(media-col/media-size/x-dimension) again: ", stdout
);
584 if ((attr
= ippFindNextAttribute(request
, "media-col/media-size/x-dimension", IPP_TAG_INTEGER
)) != NULL
)
586 printf("FAIL (got %d, expected nothing)\n", ippGetInteger(attr
, 0));
595 * Read the mixed data and confirm we converted everything to rangeOfInteger
599 printf("Read Mixed integer/rangeOfInteger from Memory: ");
603 data
.wused
= sizeof(mixed
);
604 data
.wsize
= sizeof(mixed
);
605 data
.wbuffer
= mixed
;
607 while ((state
= ippReadIO(&data
, (ipp_iocb_t
)read_cb
, 1, NULL
,
608 request
)) != IPP_STATE_DATA
)
609 if (state
== IPP_STATE_ERROR
)
612 length
= ippLength(request
);
614 if (state
!= IPP_STATE_DATA
)
616 printf("FAIL - %d bytes read.\n", (int)data
.rpos
);
619 else if (data
.rpos
!= sizeof(mixed
))
621 printf("FAIL - read %d bytes, expected %d bytes!\n", (int)data
.rpos
,
623 print_attributes(request
, 8);
626 else if (length
!= (sizeof(mixed
) + 4))
628 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
629 (int)length
, (int)sizeof(mixed
) + 4);
630 print_attributes(request
, 8);
636 fputs("ippFindAttribute(notify-lease-duration-supported): ", stdout
);
637 if ((attr
= ippFindAttribute(request
, "notify-lease-duration-supported",
638 IPP_TAG_ZERO
)) == NULL
)
640 puts("FAIL (not found)");
643 else if (attr
->value_tag
!= IPP_TAG_RANGE
)
645 printf("FAIL (wrong type - %s)\n", ippTagString(attr
->value_tag
));
648 else if (attr
->num_values
!= 2)
650 printf("FAIL (wrong count - %d)\n", attr
->num_values
);
653 else if (attr
->values
[0].range
.lower
!= 1 ||
654 attr
->values
[0].range
.upper
!= 1 ||
655 attr
->values
[1].range
.lower
!= 16 ||
656 attr
->values
[1].range
.upper
!= 32)
658 printf("FAIL (wrong values - %d,%d and %d,%d)\n",
659 attr
->values
[0].range
.lower
,
660 attr
->values
[0].range
.upper
,
661 attr
->values
[1].range
.lower
,
662 attr
->values
[1].range
.upper
);
672 * Test that private option array is sorted...
675 fputs("_ippCheckOptions: ", stdout
);
676 if ((name
= _ippCheckOptions()) == NULL
)
680 printf("FAIL (\"%s\" out of order)\n", name
);
686 * Test _ippFindOption() private API...
689 fputs("_ippFindOption(\"printer-type\"): ", stdout
);
690 if (_ippFindOption("printer-type"))
705 puts("Core IPP tests failed.");
707 puts("Core IPP tests passed.");
715 for (i
= 1; i
< (size_t)argc
; i
++)
717 if ((fp
= cupsFileOpen(argv
[i
], "r")) == NULL
)
719 printf("Unable to open \"%s\" - %s\n", argv
[i
], strerror(errno
));
725 while ((state
= ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
726 request
)) == IPP_STATE_ATTRIBUTE
);
728 if (state
!= IPP_STATE_DATA
)
730 printf("Error reading IPP message from \"%s\"!\n", argv
[i
]);
735 printf("\n%s:\n", argv
[i
]);
736 print_attributes(request
, 4);
749 * 'hex_dump()' - Produce a hex dump of a buffer.
753 hex_dump(const char *title
, /* I - Title */
754 ipp_uchar_t
*buffer
, /* I - Buffer to dump */
755 size_t bytes
) /* I - Number of bytes */
757 size_t i
, j
; /* Looping vars */
758 int ch
; /* Current ASCII char */
762 * Show lines of 16 bytes at a time...
765 printf(" %s:\n", title
);
767 for (i
= 0; i
< bytes
; i
+= 16)
773 printf(" %04x ", (unsigned)i
);
776 * Then up to 16 bytes in hex...
779 for (j
= 0; j
< 16; j
++)
781 printf(" %02x", buffer
[i
+ j
]);
786 * Then the ASCII representation of the bytes...
792 for (j
= 0; j
< 16 && (i
+ j
) < bytes
; j
++)
794 ch
= buffer
[i
+ j
] & 127;
796 if (ch
< ' ' || ch
== 127)
808 * 'print_attributes()' - Print the attributes in a request...
812 print_attributes(ipp_t
*ipp
, /* I - IPP request */
813 int indent
) /* I - Indentation */
815 int i
; /* Looping var */
816 ipp_tag_t group
; /* Current group */
817 ipp_attribute_t
*attr
; /* Current attribute */
818 _ipp_value_t
*val
; /* Current value */
819 static const char * const tags
[] = /* Value/group tag strings */
822 "operation-attributes-tag",
823 "job-attributes-tag",
824 "end-of-attributes-tag",
825 "printer-attributes-tag",
826 "unsupported-attributes-tag",
827 "subscription-attributes-tag",
828 "event-attributes-tag",
886 "textWithoutLanguage",
887 "nameWithoutLanguage",
899 for (group
= IPP_TAG_ZERO
, attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
901 if (!attr
->name
&& indent
== 4)
903 group
= IPP_TAG_ZERO
;
908 if (group
!= attr
->group_tag
)
910 group
= attr
->group_tag
;
912 printf("\n%*s%s:\n\n", indent
- 4, "", tags
[group
]);
915 printf("%*s%s (", indent
, "", attr
->name
? attr
->name
: "(null)");
916 if (attr
->num_values
> 1)
918 printf("%s):", tags
[attr
->value_tag
]);
920 switch (attr
->value_tag
)
923 case IPP_TAG_INTEGER
:
924 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
925 printf(" %d", val
->integer
);
929 case IPP_TAG_BOOLEAN
:
930 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
931 printf(" %s", val
->boolean
? "true" : "false");
936 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
937 printf(" %d-%d", val
->range
.lower
, val
->range
.upper
);
943 char vstring
[256]; /* Formatted time */
945 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
946 printf(" (%s)", _cupsStrDate(vstring
, sizeof(vstring
), ippDateToTime(val
->date
)));
951 case IPP_TAG_RESOLUTION
:
952 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
953 printf(" %dx%d%s", val
->resolution
.xres
, val
->resolution
.yres
,
954 val
->resolution
.units
== IPP_RES_PER_INCH
? "dpi" : "dpcm");
958 case IPP_TAG_STRING
:
959 case IPP_TAG_TEXTLANG
:
960 case IPP_TAG_NAMELANG
:
963 case IPP_TAG_KEYWORD
:
965 case IPP_TAG_URISCHEME
:
966 case IPP_TAG_CHARSET
:
967 case IPP_TAG_LANGUAGE
:
968 case IPP_TAG_MIMETYPE
:
969 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
970 printf(" \"%s\"", val
->string
.text
);
974 case IPP_TAG_BEGIN_COLLECTION
:
977 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
981 print_attributes(val
->collection
, indent
+ 4);
986 printf("UNKNOWN (%d values)\n", attr
->num_values
);
994 * 'read_cb()' - Read data from a buffer.
997 ssize_t
/* O - Number of bytes read */
998 read_cb(_ippdata_t
*data
, /* I - Data */
999 ipp_uchar_t
*buffer
, /* O - Buffer to read */
1000 size_t bytes
) /* I - Number of bytes to read */
1002 size_t count
; /* Number of bytes */
1006 * Copy bytes from the data buffer to the read buffer...
1009 if ((count
= data
->wsize
- data
->rpos
) > bytes
)
1012 memcpy(buffer
, data
->wbuffer
+ data
->rpos
, count
);
1013 data
->rpos
+= count
;
1016 * Return the number of bytes read...
1019 return ((ssize_t
)count
);
1024 * 'write_cb()' - Write data into a buffer.
1027 ssize_t
/* O - Number of bytes written */
1028 write_cb(_ippdata_t
*data
, /* I - Data */
1029 ipp_uchar_t
*buffer
, /* I - Buffer to write */
1030 size_t bytes
) /* I - Number of bytes to write */
1032 size_t count
; /* Number of bytes */
1036 * Loop until all bytes are written...
1039 if ((count
= data
->wsize
- data
->wused
) > bytes
)
1042 memcpy(data
->wbuffer
+ data
->wused
, buffer
, count
);
1043 data
->wused
+= count
;
1046 * Return the number of bytes written...
1049 return ((ssize_t
)count
);