2022-05-13 20:08:20 +08:00
|
|
|
|
/*
|
|
|
|
|
* GZIP/raw pre-filter for CUPS.
|
|
|
|
|
*
|
2023-01-11 16:57:48 +08:00
|
|
|
|
* Copyright © 2021 by OpenPrinting.
|
|
|
|
|
* Copyright © 2007-2015 by Apple Inc.
|
|
|
|
|
* Copyright © 1993-2007 by Easy Software Products.
|
2022-05-13 20:08:20 +08:00
|
|
|
|
*
|
2023-01-11 16:57:48 +08:00
|
|
|
|
* Licensed under Apache License v2.0. See the file "LICENSE" for more
|
|
|
|
|
* information.
|
2022-05-13 20:08:20 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Include necessary headers...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <cups/cups-private.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 'main()' - Copy (and uncompress) files to stdout.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - Exit status */
|
|
|
|
|
main(int argc, /* I - Number of command-line arguments */
|
|
|
|
|
char *argv[]) /* I - Command-line arguments */
|
|
|
|
|
{
|
|
|
|
|
cups_file_t *fp; /* File */
|
|
|
|
|
char buffer[8192]; /* Data buffer */
|
|
|
|
|
ssize_t bytes; /* Number of bytes read/written */
|
|
|
|
|
int copies; /* Number of copies */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check command-line...
|
|
|
|
|
*/
|
|
|
|
|
|
2023-10-26 10:19:35 +08:00
|
|
|
|
if (argc != 6 && argc != 7)
|
2022-05-13 20:08:20 +08:00
|
|
|
|
{
|
|
|
|
|
_cupsLangPrintf(stderr,
|
|
|
|
|
_("Usage: %s job-id user title copies options [file]"),
|
|
|
|
|
argv[0]);
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get the copy count; if we have no final content type, this is a
|
|
|
|
|
* raw queue or raw print file, so we need to make copies...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!getenv("FINAL_CONTENT_TYPE"))
|
2023-01-11 16:57:48 +08:00
|
|
|
|
{
|
|
|
|
|
if ((copies = atoi(argv[4])) < 1)
|
|
|
|
|
copies = 1;
|
|
|
|
|
}
|
2022-05-13 20:08:20 +08:00
|
|
|
|
else
|
2023-01-11 16:57:48 +08:00
|
|
|
|
{
|
2022-05-13 20:08:20 +08:00
|
|
|
|
copies = 1;
|
2023-01-11 16:57:48 +08:00
|
|
|
|
}
|
2022-05-13 20:08:20 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Open the file...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (argc == 6)
|
|
|
|
|
{
|
|
|
|
|
copies = 1;
|
|
|
|
|
fp = cupsFileStdin();
|
|
|
|
|
}
|
|
|
|
|
else if ((fp = cupsFileOpen(argv[6], "r")) == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "DEBUG: Unable to open \"%s\".\n", argv[6]);
|
|
|
|
|
_cupsLangPrintError("ERROR", _("Unable to open print file"));
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copy the file to stdout...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
while (copies > 0)
|
|
|
|
|
{
|
|
|
|
|
if (!getenv("FINAL_CONTENT_TYPE"))
|
|
|
|
|
fputs("PAGE: 1 1\n", stderr);
|
|
|
|
|
|
|
|
|
|
cupsFileRewind(fp);
|
|
|
|
|
|
|
|
|
|
while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
|
|
|
|
|
if (write(1, buffer, (size_t)bytes) < bytes)
|
|
|
|
|
{
|
|
|
|
|
_cupsLangPrintFilter(stderr, "ERROR",
|
|
|
|
|
_("Unable to write uncompressed print data: %s"),
|
|
|
|
|
strerror(errno));
|
|
|
|
|
if (argc == 7)
|
|
|
|
|
cupsFileClose(fp);
|
|
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
copies --;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Close the file and return...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (argc == 7)
|
|
|
|
|
cupsFileClose(fp);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|