/*
* IPP test program for CUPS.
*
- * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 2007-2019 by Apple Inc.
* Copyright © 1997-2005 by Easy Software Products.
*
- * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
*/
/*
#include "file.h"
#include "string-private.h"
#include "ipp-private.h"
-#ifdef WIN32
+#ifdef _WIN32
# include <io.h>
#else
# include <unistd.h>
# include <fcntl.h>
-#endif /* WIN32 */
+#endif /* _WIN32 */
/*
0x01, 0x01, /* IPP version */
0x00, 0x02, /* Print-Job operation */
0x00, 0x00, 0x00, 0x01,
- /* Request ID */
+ /* Request ID */
IPP_TAG_OPERATION,
IPP_TAG_JOB, /* job group tag */
IPP_TAG_BEGIN_COLLECTION,
- /* begCollection tag */
+ /* begCollection tag */
0x00, 0x09, /* Name length + name */
'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l',
0x00, 0x00, /* No value */
0x00, 0x0a, /* Value length + value */
'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e',
IPP_TAG_BEGIN_COLLECTION,
- /* begCollection tag */
+ /* begCollection tag */
0x00, 0x00, /* Name length + name */
0x00, 0x00, /* No value */
IPP_TAG_MEMBERNAME,
- /* memberAttrName tag */
+ /* memberAttrName tag */
0x00, 0x00, /* No name */
0x00, 0x0b, /* Value length + value */
'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
0x00, 0x04, /* Value length + value */
0x00, 0x00, 0x54, 0x56,
IPP_TAG_MEMBERNAME,
- /* memberAttrName tag */
+ /* memberAttrName tag */
0x00, 0x00, /* No name */
0x00, 0x0b, /* Value length + value */
'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
0x00, 0x04, /* Value length + value */
0x00, 0x00, 0x6d, 0x24,
IPP_TAG_END_COLLECTION,
- /* endCollection tag */
+ /* endCollection tag */
0x00, 0x00, /* No name */
0x00, 0x00, /* No value */
IPP_TAG_MEMBERNAME, /* memberAttrName tag */
0x00, 0x05, /* Value length + value */
'p', 'l', 'a', 'i', 'n',
IPP_TAG_END_COLLECTION,
- /* endCollection tag */
+ /* endCollection tag */
0x00, 0x00, /* No name */
0x00, 0x00, /* No value */
IPP_TAG_BEGIN_COLLECTION,
- /* begCollection tag */
+ /* begCollection tag */
0x00, 0x00, /* No name */
0x00, 0x00, /* No value */
IPP_TAG_MEMBERNAME, /* memberAttrName tag */
0x00, 0x0a, /* Value length + value */
'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e',
IPP_TAG_BEGIN_COLLECTION,
- /* begCollection tag */
+ /* begCollection tag */
0x00, 0x00, /* Name length + name */
0x00, 0x00, /* No value */
IPP_TAG_MEMBERNAME,
- /* memberAttrName tag */
+ /* memberAttrName tag */
0x00, 0x00, /* No name */
0x00, 0x0b, /* Value length + value */
'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
0x00, 0x04, /* Value length + value */
0x00, 0x00, 0x52, 0x08,
IPP_TAG_MEMBERNAME,
- /* memberAttrName tag */
+ /* memberAttrName tag */
0x00, 0x00, /* No name */
0x00, 0x0b, /* Value length + value */
'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
0x00, 0x04, /* Value length + value */
0x00, 0x00, 0x74, 0x04,
IPP_TAG_END_COLLECTION,
- /* endCollection tag */
+ /* endCollection tag */
0x00, 0x00, /* No name */
0x00, 0x00, /* No value */
IPP_TAG_MEMBERNAME, /* memberAttrName tag */
0x00, 0x06, /* Value length + value */
'g', 'l', 'o', 's', 's', 'y',
IPP_TAG_END_COLLECTION,
- /* endCollection tag */
+ /* endCollection tag */
+ 0x00, 0x00, /* No name */
+ 0x00, 0x00, /* No value */
+
+ IPP_TAG_END /* end tag */
+ };
+static ipp_uchar_t bad_collection[] = /* Collection buffer (bad encoding) */
+ {
+ 0x01, 0x01, /* IPP version */
+ 0x00, 0x02, /* Print-Job operation */
+ 0x00, 0x00, 0x00, 0x01,
+ /* Request ID */
+
+ IPP_TAG_OPERATION,
+
+ IPP_TAG_CHARSET,
+ 0x00, 0x12, /* Name length + name */
+ 'a','t','t','r','i','b','u','t','e','s','-',
+ 'c','h','a','r','s','e','t',
+ 0x00, 0x05, /* Value length + value */
+ 'u','t','f','-','8',
+
+ IPP_TAG_LANGUAGE,
+ 0x00, 0x1b, /* Name length + name */
+ 'a','t','t','r','i','b','u','t','e','s','-',
+ 'n','a','t','u','r','a','l','-','l','a','n',
+ 'g','u','a','g','e',
+ 0x00, 0x02, /* Value length + value */
+ 'e','n',
+
+ IPP_TAG_URI,
+ 0x00, 0x0b, /* Name length + name */
+ 'p','r','i','n','t','e','r','-','u','r','i',
+ 0x00, 0x1c, /* Value length + value */
+ 'i','p','p',':','/','/','l','o','c','a','l',
+ 'h','o','s','t','/','p','r','i','n','t','e',
+ 'r','s','/','f','o','o',
+
+ IPP_TAG_JOB, /* job group tag */
+
+ IPP_TAG_BEGIN_COLLECTION,
+ /* begCollection tag */
+ 0x00, 0x09, /* Name length + name */
+ 'm', 'e', 'd', 'i', 'a', '-', 'c', 'o', 'l',
+ 0x00, 0x00, /* No value */
+ IPP_TAG_BEGIN_COLLECTION,
+ /* begCollection tag */
+ 0x00, 0x0a, /* Name length + name */
+ 'm', 'e', 'd', 'i', 'a', '-', 's', 'i', 'z', 'e',
+ 0x00, 0x00, /* No value */
+ IPP_TAG_INTEGER, /* integer tag */
+ 0x00, 0x0b, /* Name length + name */
+ 'x', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
+ 0x00, 0x04, /* Value length + value */
+ 0x00, 0x00, 0x54, 0x56,
+ IPP_TAG_INTEGER, /* integer tag */
+ 0x00, 0x0b, /* Name length + name */
+ 'y', '-', 'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n',
+ 0x00, 0x04, /* Value length + value */
+ 0x00, 0x00, 0x6d, 0x24,
+ IPP_TAG_END_COLLECTION,
+ /* endCollection tag */
+ 0x00, 0x00, /* No name */
+ 0x00, 0x00, /* No value */
+ IPP_TAG_END_COLLECTION,
+ /* endCollection tag */
0x00, 0x00, /* No name */
0x00, 0x00, /* No value */
0x01, 0x01, /* IPP version */
0x00, 0x02, /* Print-Job operation */
0x00, 0x00, 0x00, 0x01,
- /* Request ID */
+ /* Request ID */
IPP_TAG_OPERATION,
void hex_dump(const char *title, ipp_uchar_t *buffer, size_t bytes);
void print_attributes(ipp_t *ipp, int indent);
ssize_t read_cb(_ippdata_t *data, ipp_uchar_t *buffer, size_t bytes);
+ssize_t read_hex(cups_file_t *fp, ipp_uchar_t *buffer, size_t bytes);
int token_cb(_ipp_file_t *f, _ipp_vars_t *v, void *user_data, const char *token);
ssize_t write_cb(_ippdata_t *data, ipp_uchar_t *buffer, size_t bytes);
ippDelete(request);
+ /*
+ * Read the bad collection data and confirm we get an error...
+ */
+
+ fputs("Read Bad Collection from Memory: ", stdout);
+
+ request = ippNew();
+ data.rpos = 0;
+ data.wused = sizeof(bad_collection);
+ data.wsize = sizeof(bad_collection);
+ data.wbuffer = bad_collection;
+
+ while ((state = ippReadIO(&data, (ipp_iocb_t)read_cb, 1, NULL, request)) != IPP_STATE_DATA)
+ if (state == IPP_STATE_ERROR)
+ break;
+
+ if (state != IPP_STATE_ERROR)
+ puts("FAIL (read successful)");
+ else
+ puts("PASS");
+
/*
* Read the mixed data and confirm we converted everything to rangeOfInteger
* values...
*/
- printf("Read Mixed integer/rangeOfInteger from Memory: ");
+ fputs("Read Mixed integer/rangeOfInteger from Memory: ", stdout);
request = ippNew();
data.rpos = 0;
request = _ippFileParse(&v, argv[i], NULL);
_ippVarsDeinit(&v);
}
+ else if (strlen(argv[i]) > 4 && !strcmp(argv[i] + strlen(argv[i]) - 4, ".hex"))
+ {
+ /*
+ * Read a hex-encoded IPP message...
+ */
+
+ if ((fp = cupsFileOpen(argv[i], "r")) == NULL)
+ {
+ printf("Unable to open \"%s\" - %s\n", argv[i], strerror(errno));
+ status = 1;
+ continue;
+ }
+
+ request = ippNew();
+ while ((state = ippReadIO(fp, (ipp_iocb_t)read_hex, 1, NULL, request)) == IPP_STATE_ATTRIBUTE);
+
+ if (state != IPP_STATE_DATA)
+ {
+ printf("Error reading IPP message from \"%s\": %s\n", argv[i], cupsLastErrorString());
+ status = 1;
+
+ ippDelete(request);
+ request = NULL;
+ }
+
+ cupsFileClose(fp);
+ }
else
{
/*
}
+/*
+ * 'read_hex()' - Read a hex dump of an IPP request.
+ */
+
+ssize_t /* O - Number of bytes read */
+read_hex(cups_file_t *fp, /* I - File to read from */
+ ipp_uchar_t *buffer, /* I - Buffer to read */
+ size_t bytes) /* I - Number of bytes to read */
+{
+ size_t total = 0; /* Total bytes read */
+ static char hex[256] = ""; /* Line from file */
+ static char *hexptr = NULL; /* Pointer in line */
+
+
+ while (total < bytes)
+ {
+ if (!hexptr || (isspace(hexptr[0] & 255) && isspace(hexptr[1] & 255)))
+ {
+ if (!cupsFileGets(fp, hex, sizeof(hex)))
+ break;
+
+ hexptr = hex;
+ while (isxdigit(*hexptr & 255))
+ hexptr ++;
+ while (isspace(*hexptr & 255))
+ hexptr ++;
+
+ if (!isxdigit(*hexptr & 255))
+ {
+ hexptr = NULL;
+ continue;
+ }
+ }
+
+ *buffer++ = (ipp_uchar_t)strtol(hexptr, &hexptr, 16);
+ total ++;
+ }
+
+ return (total == 0 ? -1 : (ssize_t)total);
+}
+
+
/*
* 'token_cb()' - Token callback for ASCII IPP data file parser.
*/