]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testipp.c
2 * IPP test program for CUPS.
4 * Copyright 2007-2017 by Apple Inc.
5 * Copyright 1997-2005 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
15 #include "string-private.h"
16 #include "ipp-private.h"
29 typedef struct _ippdata_t
31 size_t rpos
, /* Read position */
32 wused
, /* Bytes used */
33 wsize
; /* Max size of buffer */
34 ipp_uchar_t
*wbuffer
; /* Buffer */
42 static ipp_uchar_t collection
[] = /* Collection buffer */
44 0x01, 0x01, /* IPP version */
45 0x00, 0x02, /* Print-Job operation */
46 0x00, 0x00, 0x00, 0x01,
52 0x00, 0x12, /* Name length + name */
53 'a','t','t','r','i','b','u','t','e','s','-',
54 'c','h','a','r','s','e','t',
55 0x00, 0x05, /* Value length + value */
59 0x00, 0x1b, /* Name length + name */
60 'a','t','t','r','i','b','u','t','e','s','-',
61 'n','a','t','u','r','a','l','-','l','a','n',
63 0x00, 0x02, /* Value length + value */
67 0x00, 0x0b, /* Name length + name */
68 'p','r','i','n','t','e','r','-','u','r','i',
69 0x00, 0x1c, /* Value length + value */
70 'i','p','p',':','/','/','l','o','c','a','l',
71 'h','o','s','t','/','p','r','i','n','t','e',
72 'r','s','/','f','o','o',
74 IPP_TAG_JOB
, /* job group tag */
76 IPP_TAG_BEGIN_COLLECTION
,
77 /* begCollection tag */
78 0x00, 0x09, /* Name length + name */
79 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l',
80 0x00, 0x00, /* No value */
81 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
82 0x00, 0x00, /* No name */
83 0x00, 0x0a, /* Value length + value */
84 'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e',
85 IPP_TAG_BEGIN_COLLECTION
,
86 /* begCollection tag */
87 0x00, 0x00, /* Name length + name */
88 0x00, 0x00, /* No value */
90 /* memberAttrName tag */
91 0x00, 0x00, /* No name */
92 0x00, 0x0b, /* Value length + value */
93 'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
94 IPP_TAG_INTEGER
, /* integer tag */
95 0x00, 0x00, /* No name */
96 0x00, 0x04, /* Value length + value */
97 0x00, 0x00, 0x54, 0x56,
99 /* memberAttrName tag */
100 0x00, 0x00, /* No name */
101 0x00, 0x0b, /* Value length + value */
102 'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
103 IPP_TAG_INTEGER
, /* integer tag */
104 0x00, 0x00, /* No name */
105 0x00, 0x04, /* Value length + value */
106 0x00, 0x00, 0x6d, 0x24,
107 IPP_TAG_END_COLLECTION
,
108 /* endCollection tag */
109 0x00, 0x00, /* No name */
110 0x00, 0x00, /* No value */
111 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
112 0x00, 0x00, /* No name */
113 0x00, 0x0b, /* Value length + value */
114 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', 'o', 'r',
115 IPP_TAG_KEYWORD
, /* keyword tag */
116 0x00, 0x00, /* No name */
117 0x00, 0x04, /* Value length + value */
120 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
121 0x00, 0x00, /* No name */
122 0x00, 0x0a, /* Value length + value */
123 'm', 'e', 'd', 'i', 'a', '-', 't', 'y', 'p', 'e',
124 IPP_TAG_KEYWORD
, /* keyword tag */
125 0x00, 0x00, /* No name */
126 0x00, 0x05, /* Value length + value */
127 'p', 'l', 'a', 'i', 'n',
128 IPP_TAG_END_COLLECTION
,
129 /* endCollection tag */
130 0x00, 0x00, /* No name */
131 0x00, 0x00, /* No value */
133 IPP_TAG_BEGIN_COLLECTION
,
134 /* begCollection tag */
135 0x00, 0x00, /* No name */
136 0x00, 0x00, /* No value */
137 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
138 0x00, 0x00, /* No name */
139 0x00, 0x0a, /* Value length + value */
140 'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e',
141 IPP_TAG_BEGIN_COLLECTION
,
142 /* begCollection tag */
143 0x00, 0x00, /* Name length + name */
144 0x00, 0x00, /* No value */
146 /* memberAttrName tag */
147 0x00, 0x00, /* No name */
148 0x00, 0x0b, /* Value length + value */
149 'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
150 IPP_TAG_INTEGER
, /* integer tag */
151 0x00, 0x00, /* No name */
152 0x00, 0x04, /* Value length + value */
153 0x00, 0x00, 0x52, 0x08,
155 /* memberAttrName tag */
156 0x00, 0x00, /* No name */
157 0x00, 0x0b, /* Value length + value */
158 'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
159 IPP_TAG_INTEGER
, /* integer tag */
160 0x00, 0x00, /* No name */
161 0x00, 0x04, /* Value length + value */
162 0x00, 0x00, 0x74, 0x04,
163 IPP_TAG_END_COLLECTION
,
164 /* endCollection tag */
165 0x00, 0x00, /* No name */
166 0x00, 0x00, /* No value */
167 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
168 0x00, 0x00, /* No name */
169 0x00, 0x0b, /* Value length + value */
170 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l', 'o', 'r',
171 IPP_TAG_KEYWORD
, /* keyword tag */
172 0x00, 0x00, /* No name */
173 0x00, 0x05, /* Value length + value */
174 'p', 'l', 'a', 'i', 'd',
176 IPP_TAG_MEMBERNAME
, /* memberAttrName tag */
177 0x00, 0x00, /* No name */
178 0x00, 0x0a, /* Value length + value */
179 'm', 'e', 'd', 'i', 'a', '-', 't', 'y', 'p', 'e',
180 IPP_TAG_KEYWORD
, /* keyword tag */
181 0x00, 0x00, /* No name */
182 0x00, 0x06, /* Value length + value */
183 'g', 'l', 'o', 's', 's', 'y',
184 IPP_TAG_END_COLLECTION
,
185 /* endCollection tag */
186 0x00, 0x00, /* No name */
187 0x00, 0x00, /* No value */
189 IPP_TAG_END
/* end tag */
192 static ipp_uchar_t mixed
[] = /* Mixed value buffer */
194 0x01, 0x01, /* IPP version */
195 0x00, 0x02, /* Print-Job operation */
196 0x00, 0x00, 0x00, 0x01,
201 IPP_TAG_INTEGER
, /* integer tag */
202 0x00, 0x1f, /* Name length + name */
203 'n', 'o', 't', 'i', 'f', 'y', '-', 'l', 'e', 'a', 's', 'e',
204 '-', 'd', 'u', 'r', 'a', 't', 'i', 'o', 'n', '-', 's', 'u',
205 'p', 'p', 'o', 'r', 't', 'e', 'd',
206 0x00, 0x04, /* Value length + value */
207 0x00, 0x00, 0x00, 0x01,
209 IPP_TAG_RANGE
, /* rangeOfInteger tag */
210 0x00, 0x00, /* No name */
211 0x00, 0x08, /* Value length + value */
212 0x00, 0x00, 0x00, 0x10,
213 0x00, 0x00, 0x00, 0x20,
215 IPP_TAG_END
/* end tag */
223 void hex_dump(const char *title
, ipp_uchar_t
*buffer
, size_t bytes
);
224 void print_attributes(ipp_t
*ipp
, int indent
);
225 ssize_t
read_cb(_ippdata_t
*data
, ipp_uchar_t
*buffer
, size_t bytes
);
226 ssize_t
write_cb(_ippdata_t
*data
, ipp_uchar_t
*buffer
, size_t bytes
);
230 * 'main()' - Main entry.
233 int /* O - Exit status */
234 main(int argc
, /* I - Number of command-line arguments */
235 char *argv
[]) /* I - Command-line arguments */
237 _ippdata_t data
; /* IPP buffer */
238 ipp_uchar_t buffer
[8192]; /* Write buffer data */
239 ipp_t
*cols
[2], /* Collections */
240 *size
; /* media-size collection */
241 ipp_t
*request
; /* Request */
242 ipp_attribute_t
*media_col
, /* media-col attribute */
243 *media_size
, /* media-size attribute */
244 *attr
; /* Other attribute */
245 ipp_state_t state
; /* State */
246 size_t length
; /* Length of data */
247 cups_file_t
*fp
; /* File pointer */
248 size_t i
; /* Looping var */
249 int status
; /* Status of tests (0 = success, 1 = fail) */
251 const char *name
; /* Option name */
260 * Test request generation code...
263 printf("Create Sample Request: ");
266 request
->request
.op
.version
[0] = 0x01;
267 request
->request
.op
.version
[1] = 0x01;
268 request
->request
.op
.operation_id
= IPP_OP_PRINT_JOB
;
269 request
->request
.op
.request_id
= 1;
271 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
272 "attributes-charset", NULL
, "utf-8");
273 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
274 "attributes-natural-language", NULL
, "en");
275 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
276 "printer-uri", NULL
, "ipp://localhost/printers/foo");
280 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "x-dimension", 21590);
281 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "y-dimension", 27940);
282 ippAddCollection(cols
[0], IPP_TAG_JOB
, "media-size", size
);
284 ippAddString(cols
[0], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-color", NULL
,
286 ippAddString(cols
[0], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-type", NULL
,
291 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "x-dimension", 21000);
292 ippAddInteger(size
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
, "y-dimension", 29700);
293 ippAddCollection(cols
[1], IPP_TAG_JOB
, "media-size", size
);
295 ippAddString(cols
[1], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-color", NULL
,
297 ippAddString(cols
[1], IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "media-type", NULL
,
300 ippAddCollections(request
, IPP_TAG_JOB
, "media-col", 2,
301 (const ipp_t
**)cols
);
305 length
= ippLength(request
);
306 if (length
!= sizeof(collection
))
308 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
309 (int)length
, (int)sizeof(collection
));
319 printf("Write Sample to Memory: ");
322 data
.wsize
= sizeof(buffer
);
323 data
.wbuffer
= buffer
;
325 while ((state
= ippWriteIO(&data
, (ipp_iocb_t
)write_cb
, 1, NULL
,
326 request
)) != IPP_STATE_DATA
)
327 if (state
== IPP_STATE_ERROR
)
330 if (state
!= IPP_STATE_DATA
)
332 printf("FAIL - %d bytes written.\n", (int)data
.wused
);
335 else if (data
.wused
!= sizeof(collection
))
337 printf("FAIL - wrote %d bytes, expected %d bytes!\n", (int)data
.wused
,
338 (int)sizeof(collection
));
339 hex_dump("Bytes Written", data
.wbuffer
, data
.wused
);
340 hex_dump("Baseline", collection
, sizeof(collection
));
343 else if (memcmp(data
.wbuffer
, collection
, data
.wused
))
345 for (i
= 0; i
< data
.wused
; i
++)
346 if (data
.wbuffer
[i
] != collection
[i
])
349 printf("FAIL - output does not match baseline at 0x%04x!\n", (unsigned)i
);
350 hex_dump("Bytes Written", data
.wbuffer
, data
.wused
);
351 hex_dump("Baseline", collection
, sizeof(collection
));
360 * Read the data back in and confirm...
363 printf("Read Sample from Memory: ");
368 while ((state
= ippReadIO(&data
, (ipp_iocb_t
)read_cb
, 1, NULL
,
369 request
)) != IPP_STATE_DATA
)
370 if (state
== IPP_STATE_ERROR
)
373 length
= ippLength(request
);
375 if (state
!= IPP_STATE_DATA
)
377 printf("FAIL - %d bytes read.\n", (int)data
.rpos
);
380 else if (data
.rpos
!= data
.wused
)
382 printf("FAIL - read %d bytes, expected %d bytes!\n", (int)data
.rpos
,
384 print_attributes(request
, 8);
387 else if (length
!= sizeof(collection
))
389 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
390 (int)length
, (int)sizeof(collection
));
391 print_attributes(request
, 8);
397 fputs("ippFindAttribute(media-col): ", stdout
);
398 if ((media_col
= ippFindAttribute(request
, "media-col",
399 IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
401 if ((media_col
= ippFindAttribute(request
, "media-col",
402 IPP_TAG_ZERO
)) == NULL
)
403 puts("FAIL (not found)");
405 printf("FAIL (wrong type - %s)\n", ippTagString(media_col
->value_tag
));
409 else if (media_col
->num_values
!= 2)
411 printf("FAIL (wrong count - %d)\n", media_col
->num_values
);
419 fputs("ippFindAttribute(media-size 1): ", stdout
);
420 if ((media_size
= ippFindAttribute(media_col
->values
[0].collection
,
422 IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
424 if ((media_size
= ippFindAttribute(media_col
->values
[0].collection
,
426 IPP_TAG_ZERO
)) == NULL
)
427 puts("FAIL (not found)");
429 printf("FAIL (wrong type - %s)\n",
430 ippTagString(media_size
->value_tag
));
436 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
437 "x-dimension", IPP_TAG_INTEGER
)) == NULL
)
439 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
440 "x-dimension", IPP_TAG_ZERO
)) == NULL
)
441 puts("FAIL (missing x-dimension)");
443 printf("FAIL (wrong type for x-dimension - %s)\n",
444 ippTagString(attr
->value_tag
));
448 else if (attr
->values
[0].integer
!= 21590)
450 printf("FAIL (wrong value for x-dimension - %d)\n",
451 attr
->values
[0].integer
);
454 else if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
456 IPP_TAG_INTEGER
)) == NULL
)
458 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
459 "y-dimension", IPP_TAG_ZERO
)) == NULL
)
460 puts("FAIL (missing y-dimension)");
462 printf("FAIL (wrong type for y-dimension - %s)\n",
463 ippTagString(attr
->value_tag
));
467 else if (attr
->values
[0].integer
!= 27940)
469 printf("FAIL (wrong value for y-dimension - %d)\n",
470 attr
->values
[0].integer
);
477 fputs("ippFindAttribute(media-size 2): ", stdout
);
478 if ((media_size
= ippFindAttribute(media_col
->values
[1].collection
,
480 IPP_TAG_BEGIN_COLLECTION
)) == NULL
)
482 if ((media_size
= ippFindAttribute(media_col
->values
[1].collection
,
484 IPP_TAG_ZERO
)) == NULL
)
485 puts("FAIL (not found)");
487 printf("FAIL (wrong type - %s)\n",
488 ippTagString(media_size
->value_tag
));
494 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
496 IPP_TAG_INTEGER
)) == NULL
)
498 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
499 "x-dimension", IPP_TAG_ZERO
)) == NULL
)
500 puts("FAIL (missing x-dimension)");
502 printf("FAIL (wrong type for x-dimension - %s)\n",
503 ippTagString(attr
->value_tag
));
507 else if (attr
->values
[0].integer
!= 21000)
509 printf("FAIL (wrong value for x-dimension - %d)\n",
510 attr
->values
[0].integer
);
513 else if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
515 IPP_TAG_INTEGER
)) == NULL
)
517 if ((attr
= ippFindAttribute(media_size
->values
[0].collection
,
518 "y-dimension", IPP_TAG_ZERO
)) == NULL
)
519 puts("FAIL (missing y-dimension)");
521 printf("FAIL (wrong type for y-dimension - %s)\n",
522 ippTagString(attr
->value_tag
));
526 else if (attr
->values
[0].integer
!= 29700)
528 printf("FAIL (wrong value for y-dimension - %d)\n",
529 attr
->values
[0].integer
);
538 * Test hierarchical find...
541 fputs("ippFindAttribute(media-col/media-size/x-dimension): ", stdout
);
542 if ((attr
= ippFindAttribute(request
, "media-col/media-size/x-dimension", IPP_TAG_INTEGER
)) != NULL
)
544 if (ippGetInteger(attr
, 0) != 21590)
546 printf("FAIL (wrong value for x-dimension - %d)\n", ippGetInteger(attr
, 0));
554 puts("FAIL (not found)");
558 fputs("ippFindNextAttribute(media-col/media-size/x-dimension): ", stdout
);
559 if ((attr
= ippFindNextAttribute(request
, "media-col/media-size/x-dimension", IPP_TAG_INTEGER
)) != NULL
)
561 if (ippGetInteger(attr
, 0) != 21000)
563 printf("FAIL (wrong value for x-dimension - %d)\n", ippGetInteger(attr
, 0));
571 puts("FAIL (not found)");
575 fputs("ippFindNextAttribute(media-col/media-size/x-dimension) again: ", stdout
);
576 if ((attr
= ippFindNextAttribute(request
, "media-col/media-size/x-dimension", IPP_TAG_INTEGER
)) != NULL
)
578 printf("FAIL (got %d, expected nothing)\n", ippGetInteger(attr
, 0));
587 * Read the mixed data and confirm we converted everything to rangeOfInteger
591 printf("Read Mixed integer/rangeOfInteger from Memory: ");
595 data
.wused
= sizeof(mixed
);
596 data
.wsize
= sizeof(mixed
);
597 data
.wbuffer
= mixed
;
599 while ((state
= ippReadIO(&data
, (ipp_iocb_t
)read_cb
, 1, NULL
,
600 request
)) != IPP_STATE_DATA
)
601 if (state
== IPP_STATE_ERROR
)
604 length
= ippLength(request
);
606 if (state
!= IPP_STATE_DATA
)
608 printf("FAIL - %d bytes read.\n", (int)data
.rpos
);
611 else if (data
.rpos
!= sizeof(mixed
))
613 printf("FAIL - read %d bytes, expected %d bytes!\n", (int)data
.rpos
,
615 print_attributes(request
, 8);
618 else if (length
!= (sizeof(mixed
) + 4))
620 printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
621 (int)length
, (int)sizeof(mixed
) + 4);
622 print_attributes(request
, 8);
628 fputs("ippFindAttribute(notify-lease-duration-supported): ", stdout
);
629 if ((attr
= ippFindAttribute(request
, "notify-lease-duration-supported",
630 IPP_TAG_ZERO
)) == NULL
)
632 puts("FAIL (not found)");
635 else if (attr
->value_tag
!= IPP_TAG_RANGE
)
637 printf("FAIL (wrong type - %s)\n", ippTagString(attr
->value_tag
));
640 else if (attr
->num_values
!= 2)
642 printf("FAIL (wrong count - %d)\n", attr
->num_values
);
645 else if (attr
->values
[0].range
.lower
!= 1 ||
646 attr
->values
[0].range
.upper
!= 1 ||
647 attr
->values
[1].range
.lower
!= 16 ||
648 attr
->values
[1].range
.upper
!= 32)
650 printf("FAIL (wrong values - %d,%d and %d,%d)\n",
651 attr
->values
[0].range
.lower
,
652 attr
->values
[0].range
.upper
,
653 attr
->values
[1].range
.lower
,
654 attr
->values
[1].range
.upper
);
664 * Test that private option array is sorted...
667 fputs("_ippCheckOptions: ", stdout
);
668 if ((name
= _ippCheckOptions()) == NULL
)
672 printf("FAIL (\"%s\" out of order)\n", name
);
678 * Test _ippFindOption() private API...
681 fputs("_ippFindOption(\"printer-type\"): ", stdout
);
682 if (_ippFindOption("printer-type"))
697 puts("Core IPP tests failed.");
699 puts("Core IPP tests passed.");
707 for (i
= 1; i
< (size_t)argc
; i
++)
709 if ((fp
= cupsFileOpen(argv
[i
], "r")) == NULL
)
711 printf("Unable to open \"%s\" - %s\n", argv
[i
], strerror(errno
));
717 while ((state
= ippReadIO(fp
, (ipp_iocb_t
)cupsFileRead
, 1, NULL
,
718 request
)) == IPP_STATE_ATTRIBUTE
);
720 if (state
!= IPP_STATE_DATA
)
722 printf("Error reading IPP message from \"%s\"!\n", argv
[i
]);
727 printf("\n%s:\n", argv
[i
]);
728 print_attributes(request
, 4);
741 * 'hex_dump()' - Produce a hex dump of a buffer.
745 hex_dump(const char *title
, /* I - Title */
746 ipp_uchar_t
*buffer
, /* I - Buffer to dump */
747 size_t bytes
) /* I - Number of bytes */
749 size_t i
, j
; /* Looping vars */
750 int ch
; /* Current ASCII char */
754 * Show lines of 16 bytes at a time...
757 printf(" %s:\n", title
);
759 for (i
= 0; i
< bytes
; i
+= 16)
765 printf(" %04x ", (unsigned)i
);
768 * Then up to 16 bytes in hex...
771 for (j
= 0; j
< 16; j
++)
773 printf(" %02x", buffer
[i
+ j
]);
778 * Then the ASCII representation of the bytes...
784 for (j
= 0; j
< 16 && (i
+ j
) < bytes
; j
++)
786 ch
= buffer
[i
+ j
] & 127;
788 if (ch
< ' ' || ch
== 127)
800 * 'print_attributes()' - Print the attributes in a request...
804 print_attributes(ipp_t
*ipp
, /* I - IPP request */
805 int indent
) /* I - Indentation */
807 ipp_tag_t group
; /* Current group */
808 ipp_attribute_t
*attr
; /* Current attribute */
809 char buffer
[2048]; /* Value string */
812 for (group
= IPP_TAG_ZERO
, attr
= ipp
->attrs
; attr
; attr
= attr
->next
)
814 if (!attr
->name
&& indent
== 4)
816 group
= IPP_TAG_ZERO
;
821 if (group
!= attr
->group_tag
)
823 group
= attr
->group_tag
;
825 printf("\n%*s%s:\n\n", indent
- 4, "", ippTagString(group
));
828 ippAttributeString(attr
, buffer
, sizeof(buffer
));
830 printf("%*s%s (%s%s): %s\n", indent
, "", attr
->name
? attr
->name
: "(null)", attr
->num_values
> 1 ? "1setOf " : "", ippTagString(attr
->value_tag
), buffer
);
836 * 'read_cb()' - Read data from a buffer.
839 ssize_t
/* O - Number of bytes read */
840 read_cb(_ippdata_t
*data
, /* I - Data */
841 ipp_uchar_t
*buffer
, /* O - Buffer to read */
842 size_t bytes
) /* I - Number of bytes to read */
844 size_t count
; /* Number of bytes */
848 * Copy bytes from the data buffer to the read buffer...
851 if ((count
= data
->wsize
- data
->rpos
) > bytes
)
854 memcpy(buffer
, data
->wbuffer
+ data
->rpos
, count
);
858 * Return the number of bytes read...
861 return ((ssize_t
)count
);
866 * 'write_cb()' - Write data into a buffer.
869 ssize_t
/* O - Number of bytes written */
870 write_cb(_ippdata_t
*data
, /* I - Data */
871 ipp_uchar_t
*buffer
, /* I - Buffer to write */
872 size_t bytes
) /* I - Number of bytes to write */
874 size_t count
; /* Number of bytes */
878 * Loop until all bytes are written...
881 if ((count
= data
->wsize
- data
->wused
) > bytes
)
884 memcpy(data
->wbuffer
+ data
->wused
, buffer
, count
);
885 data
->wused
+= count
;
888 * Return the number of bytes written...
891 return ((ssize_t
)count
);