]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testipp.c
67700c64233dc3db7683fbf63c67362167996622
2 * IPP test program for CUPS.
4 * Copyright © 2007-2019 by Apple Inc.
5 * Copyright © 1997-2005 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
16 #include "string-private.h"
17 #include "ipp-private.h"
30 typedef struct _ippdata_t
32 size_t rpos
, /* Read position */
33 wused
, /* Bytes used */
34 wsize
; /* Max size of buffer */
35 ipp_uchar_t
*wbuffer
; /* Buffer */
43 static ipp_uchar_t collection
[] = /* Collection buffer */
45 0x01, 0x01, /* IPP version */
46 0x00, 0x02, /* Print-Job operation */
47 0x00, 0x00, 0x00, 0x01,
53 0x00, 0x12, /* Name length + name */
54 'a','t','t','r','i','b','u','t','e','s','-',
55 'c','h','a','r','s','e','t',
56 0x00, 0x05, /* Value length + value */
60 0x00, 0x1b, /* Name length + name */
61 'a','t','t','r','i','b','u','t','e','s','-',
62 'n','a','t','u','r','a','l','-','l','a','n',
64 0x00, 0x02, /* Value length + value */
68 0x00, 0x0b, /* Name length + name */
69 'p','r','i','n','t','e','r','-','u','r','i',
70 0x00, 0x1c, /* Value length + value */
71 'i','p','p',':','/','/','l','o','c','a','l',
72 'h','o','s','t','/','p','r','i','n','t','e',
73 'r','s','/','f','o','o',
75 IPP_TAG_JOB
, /* job group tag */
77 IPP_TAG_BEGIN_COLLECTION
,
78 /* begCollection tag */
79 0x00, 0x09, /* Name length + name */
80 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l',
81 0x00, 0x00, /* No value */
82 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
83 0x00, 0x00, /* No name */
84 0x00, 0x0a, /* Value length + value */
85 'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e',
86 IPP_TAG_BEGIN_COLLECTION
,
87 /* begCollection tag */
88 0x00, 0x00, /* Name length + name */
89 0x00, 0x00, /* No value */
91 /* memberAttrName tag */
92 0x00, 0x00, /* No name */
93 0x00, 0x0b, /* Value length + value */
94 'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
95 IPP_TAG_INTEGER
, /* integer tag */
96 0x00, 0x00, /* No name */
97 0x00, 0x04, /* Value length + value */
98 0x00, 0x00, 0x54, 0x56,
100 /* memberAttrName tag */
101 0x00, 0x00, /* No name */
102 0x00, 0x0b, /* Value length + value */
103 'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
104 IPP_TAG_INTEGER
, /* integer tag */
105 0x00, 0x00, /* No name */
106 0x00, 0x04, /* Value length + value */
107 0x00, 0x00, 0x6d, 0x24,
108 IPP_TAG_END_COLLECTION
,
109 /* endCollection tag */
110 0x00, 0x00, /* No name */
111 0x00, 0x00, /* No value */
112 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
113 0x00, 0x00, /* No name */
114 0x00, 0x0b, /* Value length + value */
115 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', 'o', 'r',
116 IPP_TAG_KEYWORD
, /* keyword tag */
117 0x00, 0x00, /* No name */
118 0x00, 0x04, /* Value length + value */
121 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
122 0x00, 0x00, /* No name */
123 0x00, 0x0a, /* Value length + value */
124 'm', 'e', 'd', 'i', 'a', '-', 't', 'y', 'p', 'e',
125 IPP_TAG_KEYWORD
, /* keyword tag */
126 0x00, 0x00, /* No name */
127 0x00, 0x05, /* Value length + value */
128 'p', 'l', 'a', 'i', 'n',
129 IPP_TAG_END_COLLECTION
,
130 /* endCollection tag */
131 0x00, 0x00, /* No name */
132 0x00, 0x00, /* No value */
134 IPP_TAG_BEGIN_COLLECTION
,
135 /* begCollection tag */
136 0x00, 0x00, /* No name */
137 0x00, 0x00, /* No value */
138 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
139 0x00, 0x00, /* No name */
140 0x00, 0x0a, /* Value length + value */
141 'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e',
142 IPP_TAG_BEGIN_COLLECTION
,
143 /* begCollection tag */
144 0x00, 0x00, /* Name length + name */
145 0x00, 0x00, /* No value */
147 /* memberAttrName tag */
148 0x00, 0x00, /* No name */
149 0x00, 0x0b, /* Value length + value */
150 'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
151 IPP_TAG_INTEGER
, /* integer tag */
152 0x00, 0x00, /* No name */
153 0x00, 0x04, /* Value length + value */
154 0x00, 0x00, 0x52, 0x08,
156 /* memberAttrName tag */
157 0x00, 0x00, /* No name */
158 0x00, 0x0b, /* Value length + value */
159 'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
160 IPP_TAG_INTEGER
, /* integer tag */
161 0x00, 0x00, /* No name */
162 0x00, 0x04, /* Value length + value */
163 0x00, 0x00, 0x74, 0x04,
164 IPP_TAG_END_COLLECTION
,
165 /* endCollection tag */
166 0x00, 0x00, /* No name */
167 0x00, 0x00, /* No value */
168 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
169 0x00, 0x00, /* No name */
170 0x00, 0x0b, /* Value length + value */
171 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', 'o', 'r',
172 IPP_TAG_KEYWORD
, /* keyword tag */
173 0x00, 0x00, /* No name */
174 0x00, 0x05, /* Value length + value */
175 'p', 'l', 'a', 'i', 'd',
177 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
178 0x00, 0x00, /* No name */
179 0x00, 0x0a, /* Value length + value */
180 'm', 'e', 'd', 'i', 'a', '-', 't', 'y', 'p', 'e',
181 IPP_TAG_KEYWORD
, /* keyword tag */
182 0x00, 0x00, /* No name */
183 0x00, 0x06, /* Value length + value */
184 'g', 'l', 'o', 's', 's', 'y',
185 IPP_TAG_END_COLLECTION
,
186 /* endCollection tag */
187 0x00, 0x00, /* No name */
188 0x00, 0x00, /* No value */
190 IPP_TAG_END
/* end tag */
193 static ipp_uchar_t mixed
[] = /* Mixed value buffer */
195 0x01, 0x01, /* IPP version */
196 0x00, 0x02, /* Print-Job operation */
197 0x00, 0x00, 0x00, 0x01,
202 IPP_TAG_INTEGER
, /* integer tag */
203 0x00, 0x1f, /* Name length + name */
204 'n', 'o', 't', 'i', 'f', 'y', '-', 'l', 'e', 'a', 's', 'e',
205 '-', 'd', 'u', 'r', 'a', 't', 'i', 'o', 'n', '-', 's', 'u',
206 'p', 'p', 'o', 'r', 't', 'e', 'd',
207 0x00, 0x04, /* Value length + value */
208 0x00, 0x00, 0x00, 0x01,
210 IPP_TAG_RANGE
, /* rangeOfInteger tag */
211 0x00, 0x00, /* No name */
212 0x00, 0x08, /* Value length + value */
213 0x00, 0x00, 0x00, 0x10,
214 0x00, 0x00, 0x00, 0x20,
216 IPP_TAG_END
/* end tag */
224 void hex_dump(const char *title
, ipp_uchar_t
*buffer
, size_t bytes
);
225 void print_attributes(ipp_t
*ipp
, int indent
);
226 ssize_t
read_cb(_ippdata_t
*data
, ipp_uchar_t
*buffer
, size_t bytes
);
227 ssize_t
read_hex(cups_file_t
*fp
, ipp_uchar_t
*buffer
, size_t bytes
);
228 int token_cb(_ipp_file_t
*f
, _ipp_vars_t
*v
, void *user_data
, const char *token
);
229 ssize_t
write_cb(_ippdata_t
*data
, ipp_uchar_t
*buffer
, size_t bytes
);
233 * 'main()' - Main entry.
236 int /* O - Exit status */
237 main(int argc
, /* I - Number of command-line arguments */
238 char *argv
[]) /* I - Command-line arguments */
240 _ippdata_t data
; /* IPP buffer */
241 ipp_uchar_t buffer
[8192]; /* Write buffer data */
242 ipp_t
*cols
[2], /* Collections */
243 *size
; /* media-size collection */
244 ipp_t
*request
; /* Request */
245 ipp_attribute_t
*media_col
, /* media-col attribute */
246 *media_size
, /* media-size attribute */
247 *attr
; /* Other attribute */
248 ipp_state_t state
; /* State */
249 size_t length
; /* Length of data */
250 cups_file_t
*fp
; /* File pointer */
251 size_t i
; /* Looping var */
252 int status
; /* Status of tests (0 = success, 1 = fail) */
254 const char *name
; /* Option name */
263 * Test request generation code...
266 printf("Create Sample Request: ");
269 request
->request
.op
.version
[0] = 0x01;
270 request
->request
.op
.version
[1] = 0x01;
271 request
->request
.op
.operation_id
= IPP_OP_PRINT_JOB
;
272 request
->request
.op
.request_id
= 1;
274 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
275 "attributes-charset", NULL
, "utf-8");
276 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
277 "attributes-natural-language", NULL
, "en");
278 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
279 "printer-uri", NULL
, "ipp://localhost/printers/foo");
283 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "x-dimension", 21590);
284 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "y-dimension", 27940);
285 ippAddCollection(cols
[0], IPP_TAG_JOB
, "media-size", size
);
287 ippAddString(cols
[0], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-color", NULL
,
289 ippAddString(cols
[0], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-type", NULL
,
294 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "x-dimension", 21000);
295 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "y-dimension", 29700);
296 ippAddCollection(cols
[1], IPP_TAG_JOB
, "media-size", size
);
298 ippAddString(cols
[1], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-color", NULL
,
300 ippAddString(cols
[1], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-type", NULL
,
303 ippAddCollections(request
, IPP_TAG_JOB
, "media-col", 2,
304 (const ipp_t
**)cols
);
308 length
= ippLength(request
);
309 if (length
!= sizeof(collection
))
311 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
312 (int)length
, (int)sizeof(collection
));
322 printf("Write Sample to Memory: ");
325 data
.wsize
= sizeof(buffer
);
326 data
.wbuffer
= buffer
;
328 while ((state
= ippWriteIO(&data
, (ipp_iocb_t
)write_cb
, 1, NULL
,
329 request
)) != IPP_STATE_DATA
)
330 if (state
== IPP_STATE_ERROR
)
333 if (state
!= IPP_STATE_DATA
)
335 printf("FAIL - %d bytes written.\n", (int)data
.wused
);
338 else if (data
.wused
!= sizeof(collection
))
340 printf("FAIL - wrote %d bytes, expected %d bytes!\n", (int)data
.wused
,
341 (int)sizeof(collection
));
342 hex_dump("Bytes Written", data
.wbuffer
, data
.wused
);
343 hex_dump("Baseline", collection
, sizeof(collection
));
346 else if (memcmp(data
.wbuffer
, collection
, data
.wused
))
348 for (i
= 0; i
< data
.wused
; i
++)
349 if (data
.wbuffer
[i
] != collection
[i
])
352 printf("FAIL - output does not match baseline at 0x%04x!\n", (unsigned)i
);
353 hex_dump("Bytes Written", data
.wbuffer
, data
.wused
);
354 hex_dump("Baseline", collection
, sizeof(collection
));
363 * Read the data back in and confirm...
366 printf("Read Sample from Memory: ");
371 while ((state
= ippReadIO(&data
, (ipp_iocb_t
)read_cb
, 1, NULL
,
372 request
)) != IPP_STATE_DATA
)
373 if (state
== IPP_STATE_ERROR
)
376 length
= ippLength(request
);
378 if (state
!= IPP_STATE_DATA
)
380 printf("FAIL - %d bytes read.\n", (int)data
.rpos
);
383 else if (data
.rpos
!= data
.wused
)
385 printf("FAIL - read %d bytes, expected %d bytes!\n", (int)data
.rpos
,
387 print_attributes(request
, 8);
390 else if (length
!= sizeof(collection
))
392 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
393 (int)length
, (int)sizeof(collection
));
394 print_attributes(request
, 8);
400 fputs("ippFindAttribute(media-col): ", stdout
);
401 if ((media_col
= ippFindAttribute(request
, "media-col",
402 IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
404 if ((media_col
= ippFindAttribute(request
, "media-col",
405 IPP_TAG_ZERO
)) == NULL
)
406 puts("FAIL (not found)");
408 printf("FAIL (wrong type - %s)\n", ippTagString(media_col
->value_tag
));
412 else if (media_col
->num_values
!= 2)
414 printf("FAIL (wrong count - %d)\n", media_col
->num_values
);
422 fputs("ippFindAttribute(media-size 1): ", stdout
);
423 if ((media_size
= ippFindAttribute(media_col
->values
[0].collection
,
425 IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
427 if ((media_size
= ippFindAttribute(media_col
->values
[0].collection
,
429 IPP_TAG_ZERO
)) == NULL
)
430 puts("FAIL (not found)");
432 printf("FAIL (wrong type - %s)\n",
433 ippTagString(media_size
->value_tag
));
439 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
440 "x-dimension", IPP_TAG_INTEGER
)) == NULL
)
442 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
443 "x-dimension", IPP_TAG_ZERO
)) == NULL
)
444 puts("FAIL (missing x-dimension)");
446 printf("FAIL (wrong type for x-dimension - %s)\n",
447 ippTagString(attr
->value_tag
));
451 else if (attr
->values
[0].integer
!= 21590)
453 printf("FAIL (wrong value for x-dimension - %d)\n",
454 attr
->values
[0].integer
);
457 else if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
459 IPP_TAG_INTEGER
)) == NULL
)
461 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
462 "y-dimension", IPP_TAG_ZERO
)) == NULL
)
463 puts("FAIL (missing y-dimension)");
465 printf("FAIL (wrong type for y-dimension - %s)\n",
466 ippTagString(attr
->value_tag
));
470 else if (attr
->values
[0].integer
!= 27940)
472 printf("FAIL (wrong value for y-dimension - %d)\n",
473 attr
->values
[0].integer
);
480 fputs("ippFindAttribute(media-size 2): ", stdout
);
481 if ((media_size
= ippFindAttribute(media_col
->values
[1].collection
,
483 IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
485 if ((media_size
= ippFindAttribute(media_col
->values
[1].collection
,
487 IPP_TAG_ZERO
)) == NULL
)
488 puts("FAIL (not found)");
490 printf("FAIL (wrong type - %s)\n",
491 ippTagString(media_size
->value_tag
));
497 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
499 IPP_TAG_INTEGER
)) == NULL
)
501 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
502 "x-dimension", IPP_TAG_ZERO
)) == NULL
)
503 puts("FAIL (missing x-dimension)");
505 printf("FAIL (wrong type for x-dimension - %s)\n",
506 ippTagString(attr
->value_tag
));
510 else if (attr
->values
[0].integer
!= 21000)
512 printf("FAIL (wrong value for x-dimension - %d)\n",
513 attr
->values
[0].integer
);
516 else if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
518 IPP_TAG_INTEGER
)) == NULL
)
520 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
521 "y-dimension", IPP_TAG_ZERO
)) == NULL
)
522 puts("FAIL (missing y-dimension)");
524 printf("FAIL (wrong type for y-dimension - %s)\n",
525 ippTagString(attr
->value_tag
));
529 else if (attr
->values
[0].integer
!= 29700)
531 printf("FAIL (wrong value for y-dimension - %d)\n",
532 attr
->values
[0].integer
);
541 * Test hierarchical find...
544 fputs("ippFindAttribute(media-col/media-size/x-dimension): ", stdout
);
545 if ((attr
= ippFindAttribute(request
, "media-col/media-size/x-dimension", IPP_TAG_INTEGER
)) != NULL
)
547 if (ippGetInteger(attr
, 0) != 21590)
549 printf("FAIL (wrong value for x-dimension - %d)\n", ippGetInteger(attr
, 0));
557 puts("FAIL (not found)");
561 fputs("ippFindNextAttribute(media-col/media-size/x-dimension): ", stdout
);
562 if ((attr
= ippFindNextAttribute(request
, "media-col/media-size/x-dimension", IPP_TAG_INTEGER
)) != NULL
)
564 if (ippGetInteger(attr
, 0) != 21000)
566 printf("FAIL (wrong value for x-dimension - %d)\n", ippGetInteger(attr
, 0));
574 puts("FAIL (not found)");
578 fputs("ippFindNextAttribute(media-col/media-size/x-dimension) again: ", stdout
);
579 if ((attr
= ippFindNextAttribute(request
, "media-col/media-size/x-dimension", IPP_TAG_INTEGER
)) != NULL
)
581 printf("FAIL (got %d, expected nothing)\n", ippGetInteger(attr
, 0));
590 * Read the mixed data and confirm we converted everything to rangeOfInteger
594 printf("Read Mixed integer/rangeOfInteger from Memory: ");
598 data
.wused
= sizeof(mixed
);
599 data
.wsize
= sizeof(mixed
);
600 data
.wbuffer
= mixed
;
602 while ((state
= ippReadIO(&data
, (ipp_iocb_t
)read_cb
, 1, NULL
,
603 request
)) != IPP_STATE_DATA
)
604 if (state
== IPP_STATE_ERROR
)
607 length
= ippLength(request
);
609 if (state
!= IPP_STATE_DATA
)
611 printf("FAIL - %d bytes read.\n", (int)data
.rpos
);
614 else if (data
.rpos
!= sizeof(mixed
))
616 printf("FAIL - read %d bytes, expected %d bytes!\n", (int)data
.rpos
,
618 print_attributes(request
, 8);
621 else if (length
!= (sizeof(mixed
) + 4))
623 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
624 (int)length
, (int)sizeof(mixed
) + 4);
625 print_attributes(request
, 8);
631 fputs("ippFindAttribute(notify-lease-duration-supported): ", stdout
);
632 if ((attr
= ippFindAttribute(request
, "notify-lease-duration-supported",
633 IPP_TAG_ZERO
)) == NULL
)
635 puts("FAIL (not found)");
638 else if (attr
->value_tag
!= IPP_TAG_RANGE
)
640 printf("FAIL (wrong type - %s)\n", ippTagString(attr
->value_tag
));
643 else if (attr
->num_values
!= 2)
645 printf("FAIL (wrong count - %d)\n", attr
->num_values
);
648 else if (attr
->values
[0].range
.lower
!= 1 ||
649 attr
->values
[0].range
.upper
!= 1 ||
650 attr
->values
[1].range
.lower
!= 16 ||
651 attr
->values
[1].range
.upper
!= 32)
653 printf("FAIL (wrong values - %d,%d and %d,%d)\n",
654 attr
->values
[0].range
.lower
,
655 attr
->values
[0].range
.upper
,
656 attr
->values
[1].range
.lower
,
657 attr
->values
[1].range
.upper
);
667 * Test that private option array is sorted...
670 fputs("_ippCheckOptions: ", stdout
);
671 if ((name
= _ippCheckOptions()) == NULL
)
675 printf("FAIL (\"%s\" out of order)\n", name
);
681 * Test _ippFindOption() private API...
684 fputs("_ippFindOption(\"printer-type\"): ", stdout
);
685 if (_ippFindOption("printer-type"))
700 puts("Core IPP tests failed.");
702 puts("Core IPP tests passed.");
710 for (i
= 1; i
< (size_t)argc
; i
++)
712 if (strlen(argv
[i
]) > 5 && !strcmp(argv
[i
] + strlen(argv
[i
]) - 5, ".test"))
715 * Read an ASCII IPP message...
718 _ipp_vars_t v
; /* IPP variables */
720 _ippVarsInit(&v
, NULL
, NULL
, token_cb
);
721 request
= _ippFileParse(&v
, argv
[i
], NULL
);
724 else if (strlen(argv
[i
]) > 4 && !strcmp(argv
[i
] + strlen(argv
[i
]) - 4, ".hex"))
727 * Read a hex-encoded IPP message...
730 if ((fp
= cupsFileOpen(argv
[i
], "r")) == NULL
)
732 printf("Unable to open \"%s\" - %s\n", argv
[i
], strerror(errno
));
738 while ((state
= ippReadIO(fp
, (ipp_iocb_t
)read_hex
, 1, NULL
, request
)) == IPP_STATE_ATTRIBUTE
);
740 if (state
!= IPP_STATE_DATA
)
742 printf("Error reading IPP message from \"%s\": %s\n", argv
[i
], cupsLastErrorString());
754 * Read a raw (binary) IPP message...
757 if ((fp
= cupsFileOpen(argv
[i
], "r")) == NULL
)
759 printf("Unable to open \"%s\" - %s\n", argv
[i
], strerror(errno
));
765 while ((state
= ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
766 request
)) == IPP_STATE_ATTRIBUTE
);
768 if (state
!= IPP_STATE_DATA
)
770 printf("Error reading IPP message from \"%s\": %s\n", argv
[i
], cupsLastErrorString());
782 printf("\n%s:\n", argv
[i
]);
783 print_attributes(request
, 4);
794 * 'hex_dump()' - Produce a hex dump of a buffer.
798 hex_dump(const char *title
, /* I - Title */
799 ipp_uchar_t
*buffer
, /* I - Buffer to dump */
800 size_t bytes
) /* I - Number of bytes */
802 size_t i
, j
; /* Looping vars */
803 int ch
; /* Current ASCII char */
807 * Show lines of 16 bytes at a time...
810 printf(" %s:\n", title
);
812 for (i
= 0; i
< bytes
; i
+= 16)
818 printf(" %04x ", (unsigned)i
);
821 * Then up to 16 bytes in hex...
824 for (j
= 0; j
< 16; j
++)
826 printf(" %02x", buffer
[i
+ j
]);
831 * Then the ASCII representation of the bytes...
837 for (j
= 0; j
< 16 && (i
+ j
) < bytes
; j
++)
839 ch
= buffer
[i
+ j
] & 127;
841 if (ch
< ' ' || ch
== 127)
853 * 'print_attributes()' - Print the attributes in a request...
857 print_attributes(ipp_t
*ipp
, /* I - IPP request */
858 int indent
) /* I - Indentation */
860 ipp_tag_t group
; /* Current group */
861 ipp_attribute_t
*attr
; /* Current attribute */
862 char buffer
[2048]; /* Value string */
865 for (group
= IPP_TAG_ZERO
, attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
867 if (!attr
->name
&& indent
== 4)
869 group
= IPP_TAG_ZERO
;
874 if (group
!= attr
->group_tag
)
876 group
= attr
->group_tag
;
878 printf("\n%*s%s:\n\n", indent
- 4, "", ippTagString(group
));
881 ippAttributeString(attr
, buffer
, sizeof(buffer
));
883 printf("%*s%s (%s%s): %s\n", indent
, "", attr
->name
? attr
->name
: "(null)", attr
->num_values
> 1 ? "1setOf " : "", ippTagString(attr
->value_tag
), buffer
);
889 * 'read_cb()' - Read data from a buffer.
892 ssize_t
/* O - Number of bytes read */
893 read_cb(_ippdata_t
*data
, /* I - Data */
894 ipp_uchar_t
*buffer
, /* O - Buffer to read */
895 size_t bytes
) /* I - Number of bytes to read */
897 size_t count
; /* Number of bytes */
901 * Copy bytes from the data buffer to the read buffer...
904 if ((count
= data
->wsize
- data
->rpos
) > bytes
)
907 memcpy(buffer
, data
->wbuffer
+ data
->rpos
, count
);
911 * Return the number of bytes read...
914 return ((ssize_t
)count
);
919 * 'read_hex()' - Read a hex dump of an IPP request.
922 ssize_t
/* O - Number of bytes read */
923 read_hex(cups_file_t
*fp
, /* I - File to read from */
924 ipp_uchar_t
*buffer
, /* I - Buffer to read */
925 size_t bytes
) /* I - Number of bytes to read */
927 size_t total
= 0; /* Total bytes read */
928 static char hex
[256] = ""; /* Line from file */
929 static char *hexptr
= NULL
; /* Pointer in line */
932 while (total
< bytes
)
934 if (!hexptr
|| (isspace(hexptr
[0] & 255) && isspace(hexptr
[1] & 255)))
936 if (!cupsFileGets(fp
, hex
, sizeof(hex
)))
940 while (isxdigit(*hexptr
& 255))
942 while (isspace(*hexptr
& 255))
945 if (!isxdigit(*hexptr
& 255))
952 *buffer
++ = (ipp_uchar_t
)strtol(hexptr
, &hexptr
, 16);
956 return (total
== 0 ? -1 : (ssize_t
)total
);
961 * 'token_cb()' - Token callback for ASCII IPP data file parser.
964 int /* O - 1 on success, 0 on failure */
965 token_cb(_ipp_file_t
*f
, /* I - IPP file data */
966 _ipp_vars_t
*v
, /* I - IPP variables */
967 void *user_data
, /* I - User data pointer */
968 const char *token
) /* I - Token string */
976 f
->group_tag
= IPP_TAG_PRINTER
;
980 fprintf(stderr
, "Unknown directive \"%s\" on line %d of \"%s\".\n", token
, f
->linenum
, f
->filename
);
989 * 'write_cb()' - Write data into a buffer.
992 ssize_t
/* O - Number of bytes written */
993 write_cb(_ippdata_t
*data
, /* I - Data */
994 ipp_uchar_t
*buffer
, /* I - Buffer to write */
995 size_t bytes
) /* I - Number of bytes to write */
997 size_t count
; /* Number of bytes */
1001 * Loop until all bytes are written...
1004 if ((count
= data
->wsize
- data
->wused
) > bytes
)
1007 memcpy(data
->wbuffer
+ data
->wused
, buffer
, count
);
1008 data
->wused
+= count
;
1011 * Return the number of bytes written...
1014 return ((ssize_t
)count
);