]>
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
);
548 * Read the mixed data and confirm we converted everything to rangeOfInteger
552 printf("Read Mixed integer/rangeOfInteger from Memory: ");
556 data
.wused
= sizeof(mixed
);
557 data
.wsize
= sizeof(mixed
);
558 data
.wbuffer
= mixed
;
560 while ((state
= ippReadIO(&data
, (ipp_iocb_t
)read_cb
, 1, NULL
,
561 request
)) != IPP_STATE_DATA
)
562 if (state
== IPP_STATE_ERROR
)
565 length
= ippLength(request
);
567 if (state
!= IPP_STATE_DATA
)
569 printf("FAIL - %d bytes read.\n", (int)data
.rpos
);
572 else if (data
.rpos
!= sizeof(mixed
))
574 printf("FAIL - read %d bytes, expected %d bytes!\n", (int)data
.rpos
,
576 print_attributes(request
, 8);
579 else if (length
!= (sizeof(mixed
) + 4))
581 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
582 (int)length
, (int)sizeof(mixed
) + 4);
583 print_attributes(request
, 8);
589 fputs("ippFindAttribute(notify-lease-duration-supported): ", stdout
);
590 if ((attr
= ippFindAttribute(request
, "notify-lease-duration-supported",
591 IPP_TAG_ZERO
)) == NULL
)
593 puts("FAIL (not found)");
596 else if (attr
->value_tag
!= IPP_TAG_RANGE
)
598 printf("FAIL (wrong type - %s)\n", ippTagString(attr
->value_tag
));
601 else if (attr
->num_values
!= 2)
603 printf("FAIL (wrong count - %d)\n", attr
->num_values
);
606 else if (attr
->values
[0].range
.lower
!= 1 ||
607 attr
->values
[0].range
.upper
!= 1 ||
608 attr
->values
[1].range
.lower
!= 16 ||
609 attr
->values
[1].range
.upper
!= 32)
611 printf("FAIL (wrong values - %d,%d and %d,%d)\n",
612 attr
->values
[0].range
.lower
,
613 attr
->values
[0].range
.upper
,
614 attr
->values
[1].range
.lower
,
615 attr
->values
[1].range
.upper
);
625 * Test that private option array is sorted...
628 fputs("_ippCheckOptions: ", stdout
);
629 if ((name
= _ippCheckOptions()) == NULL
)
633 printf("FAIL (\"%s\" out of order)\n", name
);
639 * Test _ippFindOption() private API...
642 fputs("_ippFindOption(\"printer-type\"): ", stdout
);
643 if (_ippFindOption("printer-type"))
658 puts("Core IPP tests failed.");
660 puts("Core IPP tests passed.");
668 for (i
= 1; i
< (size_t)argc
; i
++)
670 if ((fp
= cupsFileOpen(argv
[i
], "r")) == NULL
)
672 printf("Unable to open \"%s\" - %s\n", argv
[i
], strerror(errno
));
678 while ((state
= ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
679 request
)) == IPP_STATE_ATTRIBUTE
);
681 if (state
!= IPP_STATE_DATA
)
683 printf("Error reading IPP message from \"%s\"!\n", argv
[i
]);
688 printf("\n%s:\n", argv
[i
]);
689 print_attributes(request
, 4);
702 * 'hex_dump()' - Produce a hex dump of a buffer.
706 hex_dump(const char *title
, /* I - Title */
707 ipp_uchar_t
*buffer
, /* I - Buffer to dump */
708 size_t bytes
) /* I - Number of bytes */
710 size_t i
, j
; /* Looping vars */
711 int ch
; /* Current ASCII char */
715 * Show lines of 16 bytes at a time...
718 printf(" %s:\n", title
);
720 for (i
= 0; i
< bytes
; i
+= 16)
726 printf(" %04x ", (unsigned)i
);
729 * Then up to 16 bytes in hex...
732 for (j
= 0; j
< 16; j
++)
734 printf(" %02x", buffer
[i
+ j
]);
739 * Then the ASCII representation of the bytes...
745 for (j
= 0; j
< 16 && (i
+ j
) < bytes
; j
++)
747 ch
= buffer
[i
+ j
] & 127;
749 if (ch
< ' ' || ch
== 127)
761 * 'print_attributes()' - Print the attributes in a request...
765 print_attributes(ipp_t
*ipp
, /* I - IPP request */
766 int indent
) /* I - Indentation */
768 int i
; /* Looping var */
769 ipp_tag_t group
; /* Current group */
770 ipp_attribute_t
*attr
; /* Current attribute */
771 _ipp_value_t
*val
; /* Current value */
772 static const char * const tags
[] = /* Value/group tag strings */
775 "operation-attributes-tag",
776 "job-attributes-tag",
777 "end-of-attributes-tag",
778 "printer-attributes-tag",
779 "unsupported-attributes-tag",
780 "subscription-attributes-tag",
781 "event-attributes-tag",
839 "textWithoutLanguage",
840 "nameWithoutLanguage",
852 for (group
= IPP_TAG_ZERO
, attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
854 if (!attr
->name
&& indent
== 4)
856 group
= IPP_TAG_ZERO
;
861 if (group
!= attr
->group_tag
)
863 group
= attr
->group_tag
;
865 printf("\n%*s%s:\n\n", indent
- 4, "", tags
[group
]);
868 printf("%*s%s (", indent
, "", attr
->name
? attr
->name
: "(null)");
869 if (attr
->num_values
> 1)
871 printf("%s):", tags
[attr
->value_tag
]);
873 switch (attr
->value_tag
)
876 case IPP_TAG_INTEGER
:
877 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
878 printf(" %d", val
->integer
);
882 case IPP_TAG_BOOLEAN
:
883 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
884 printf(" %s", val
->boolean
? "true" : "false");
889 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
890 printf(" %d-%d", val
->range
.lower
, val
->range
.upper
);
896 time_t vtime
; /* Date/Time value */
897 struct tm
*vdate
; /* Date info */
898 char vstring
[256]; /* Formatted time */
900 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
902 vtime
= ippDateToTime(val
->date
);
903 vdate
= localtime(&vtime
);
904 strftime(vstring
, sizeof(vstring
), "%c", vdate
);
905 printf(" (%s)", vstring
);
911 case IPP_TAG_RESOLUTION
:
912 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
913 printf(" %dx%d%s", val
->resolution
.xres
, val
->resolution
.yres
,
914 val
->resolution
.units
== IPP_RES_PER_INCH
? "dpi" : "dpcm");
918 case IPP_TAG_STRING
:
919 case IPP_TAG_TEXTLANG
:
920 case IPP_TAG_NAMELANG
:
923 case IPP_TAG_KEYWORD
:
925 case IPP_TAG_URISCHEME
:
926 case IPP_TAG_CHARSET
:
927 case IPP_TAG_LANGUAGE
:
928 case IPP_TAG_MIMETYPE
:
929 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
930 printf(" \"%s\"", val
->string
.text
);
934 case IPP_TAG_BEGIN_COLLECTION
:
937 for (i
= 0, val
= attr
->values
; i
< attr
->num_values
; i
++, val
++)
941 print_attributes(val
->collection
, indent
+ 4);
946 printf("UNKNOWN (%d values)\n", attr
->num_values
);
954 * 'read_cb()' - Read data from a buffer.
957 ssize_t
/* O - Number of bytes read */
958 read_cb(_ippdata_t
*data
, /* I - Data */
959 ipp_uchar_t
*buffer
, /* O - Buffer to read */
960 size_t bytes
) /* I - Number of bytes to read */
962 size_t count
; /* Number of bytes */
966 * Copy bytes from the data buffer to the read buffer...
969 if ((count
= data
->wsize
- data
->rpos
) > bytes
)
972 memcpy(buffer
, data
->wbuffer
+ data
->rpos
, count
);
976 * Return the number of bytes read...
979 return ((ssize_t
)count
);
984 * 'write_cb()' - Write data into a buffer.
987 ssize_t
/* O - Number of bytes written */
988 write_cb(_ippdata_t
*data
, /* I - Data */
989 ipp_uchar_t
*buffer
, /* I - Buffer to write */
990 size_t bytes
) /* I - Number of bytes to write */
992 size_t count
; /* Number of bytes */
996 * Loop until all bytes are written...
999 if ((count
= data
->wsize
- data
->wused
) > bytes
)
1002 memcpy(data
->wbuffer
+ data
->wused
, buffer
, count
);
1003 data
->wused
+= count
;
1006 * Return the number of bytes written...
1009 return ((ssize_t
)count
);