/*
- * "$Id: ipp.c 4906 2006-01-10 20:53:28Z mike $"
+ * "$Id: ipp.c 5686 2006-06-21 21:02:56Z mike $"
*
* IPP backend for the Common UNIX Printing System (CUPS).
*
* Contents:
*
* main() - Send a file to the printer or server.
+ * cancel_job() - Cancel a print job.
* check_printer_state() - Check the printer state...
+ * compress_files() - Compress print files...
* password_cb() - Disable the password prompt for
* cupsDoFileRequest().
* report_printer_state() - Report the printer state.
static char pstmpname[1024] = ""; /* Temporary PostScript file name */
#endif /* __APPLE__ */
static char tmpfilename[1024] = ""; /* Temporary spool file name */
+static int job_cancelled = 0; /* Job cancelled? */
/*
* Local functions...
*/
-void check_printer_state(http_t *http, cups_lang_t *language,
- const char *charset, const char *uri, /* I - Printer URI */
+static void cancel_job(http_t *http, const char *uri, int id,
+ const char *resource, const char *user, int version);
+static void check_printer_state(http_t *http, const char *uri,
const char *resource, const char *user,
int version);
-const char *password_cb(const char *);
-int report_printer_state(ipp_t *ipp);
+#ifdef HAVE_LIBZ
+static void compress_files(int num_files, char **files);
+#endif /* HAVE_LIBZ */
+static const char *password_cb(const char *);
+static int report_printer_state(ipp_t *ipp);
#ifdef __APPLE__
-int run_pictwps_filter(char **argv, const char *filename);
+static int run_pictwps_filter(char **argv, const char *filename);
#endif /* __APPLE__ */
static void sigterm_handler(int sig);
*/
int /* O - Exit status */
-main(int argc, /* I - Number of command-line arguments (6 or 7) */
+main(int argc, /* I - Number of command-line args */
char *argv[]) /* I - Command-line arguments */
{
int i; /* Looping var */
name[255], /* Name of option */
value[255], /* Value of option */
*ptr; /* Pointer into name or value */
- char *filename; /* File to print */
+ int num_files; /* Number of files to print */
+ char **files, /* Files to print */
+ *filename; /* Pointer to single filename */
int port; /* Port number (not used) */
char uri[HTTP_MAX_URI]; /* Updated URI without user/pass */
ipp_status_t ipp_status; /* Status of IPP request */
ipp_t *request, /* IPP request */
*response, /* IPP response */
*supported; /* get-printer-attributes response */
- int waitjob, /* Wait for job complete? */
+ int compression, /* Do compression of the job data? */
+ waitjob, /* Wait for job complete? */
waitprinter; /* Wait for printer ready? */
ipp_attribute_t *job_id_attr; /* job-id attribute */
int job_id; /* job-id value */
- ipp_attribute_t *job_sheets; /* job-media-sheets-completed attribute */
- ipp_attribute_t *job_state; /* job-state attribute */
- ipp_attribute_t *copies_sup; /* copies-supported attribute */
- ipp_attribute_t *charset_sup; /* charset-supported attribute */
- ipp_attribute_t *format_sup; /* document-format-supported attribute */
+ ipp_attribute_t *job_sheets; /* job-media-sheets-completed */
+ ipp_attribute_t *job_state; /* job-state */
+ ipp_attribute_t *copies_sup; /* copies-supported */
+ ipp_attribute_t *format_sup; /* document-format-supported */
ipp_attribute_t *printer_state; /* printer-state attribute */
- ipp_attribute_t *printer_accepting; /* printer-is-accepting-jobs attribute */
- const char *charset; /* Character set to use */
- cups_lang_t *language; /* Default language */
+ ipp_attribute_t *printer_accepting; /* printer-is-accepting-jobs */
int copies; /* Number of copies remaining */
const char *content_type; /* CONTENT_TYPE environment variable */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
int version; /* IPP version */
- int reasons; /* Number of printer-state-reasons shown */
+ int reasons; /* Number of printer-state-reasons */
static const char * const pattrs[] =
{ /* Printer attributes we want */
"copies-supported",
- "charset-supported",
"document-format-supported",
"printer-is-accepting-jobs",
"printer-state",
else
s = argv[0];
- printf("network %s \"Unknown\" \"Internet Printing Protocol (%s)\"\n", s, s);
+ printf("network %s \"Unknown\" \"Internet Printing Protocol (%s)\"\n",
+ s, s);
return (CUPS_BACKEND_OK);
}
- else if (argc < 6 || argc > 7)
+ else if (argc < 6)
{
- fprintf(stderr, "Usage: %s job-id user title copies options [file]\n",
+ fprintf(stderr,
+ "Usage: %s job-id user title copies options [file ... fileN]\n",
argv[0]);
return (CUPS_BACKEND_STOP);
}
/*
- * Get the content type...
+ * Get the (final) content type...
*/
- if (argc > 6)
- content_type = getenv("CONTENT_TYPE");
- else
- content_type = "application/vnd.cups-raw";
-
- if (content_type == NULL)
- content_type = "application/octet-stream";
+ if ((content_type = getenv("FINAL_CONTENT_TYPE")) == NULL)
+ if ((content_type = getenv("CONTENT_TYPE")) == NULL)
+ content_type = "application/octet-stream";
/*
* Extract the hostname and printer name from the URI...
*/
- if (getenv("DEVICE_URI") != NULL)
- /* authentication information is only available in the env var */
- httpSeparateURI(getenv("DEVICE_URI"), method, sizeof(method),
- username, sizeof(username),
- hostname, sizeof(hostname), &port,
- resource, sizeof(resource));
- else if (strchr(argv[0], ':') != NULL)
- httpSeparateURI(argv[0], method, sizeof(method), username, sizeof(username),
- hostname, sizeof(hostname), &port,
- resource, sizeof(resource));
- else
+ if (httpSeparateURI(HTTP_URI_CODING_ALL, cupsBackendDeviceURI(argv),
+ method, sizeof(method), username, sizeof(username),
+ hostname, sizeof(hostname), &port,
+ resource, sizeof(resource)) < HTTP_URI_OK)
{
- fputs("ERROR: Missing device URI on command-line and no DEVICE_URI environment variable!\n",
- stderr);
+ fputs("ERROR: Missing device URI on command-line and no DEVICE_URI "
+ "environment variable!\n", stderr);
return (CUPS_BACKEND_STOP);
}
if (!strcmp(method, "https"))
cupsSetEncryption(HTTP_ENCRYPT_ALWAYS);
- /*
- * If we have 7 arguments, print the file named on the command-line.
- * Otherwise, copy stdin to a temporary file and print the temporary
- * file.
- */
-
- if (argc == 6)
- {
- /*
- * Copy stdin to a temporary file...
- */
-
- int fd; /* Temporary file */
- char buffer[8192]; /* Buffer for copying */
- int bytes; /* Number of bytes read */
-
-
- if ((fd = cupsTempFd(tmpfilename, sizeof(tmpfilename))) < 0)
- {
- perror("ERROR: unable to create temporary file");
- return (CUPS_BACKEND_FAILED);
- }
-
- while ((bytes = fread(buffer, 1, sizeof(buffer), stdin)) > 0)
- if (write(fd, buffer, bytes) < bytes)
- {
- perror("ERROR: unable to write to temporary file");
- close(fd);
- unlink(tmpfilename);
- return (CUPS_BACKEND_FAILED);
- }
-
- close(fd);
- filename = tmpfilename;
- }
- else
- filename = argv[6];
-
/*
* See if there are any options...
*/
+ compression = 0;
version = 1;
waitjob = 1;
waitprinter = 1;
*ptr++ = *optptr++;
*ptr = '\0';
- if (*optptr == '+')
+ if (*optptr == '+' || *optptr == '&')
optptr ++;
}
else
value);
}
}
+#ifdef HAVE_LIBZ
+ else if (!strcasecmp(name, "compression"))
+ {
+ compression = !strcasecmp(value, "true") ||
+ !strcasecmp(value, "yes") ||
+ !strcasecmp(value, "on") ||
+ !strcasecmp(value, "gzip");
+ }
+#endif /* HAVE_LIBZ */
else
{
/*
}
}
+ /*
+ * If we have 7 arguments, print the file named on the command-line.
+ * Otherwise, copy stdin to a temporary file and print the temporary
+ * file.
+ */
+
+ if (argc == 6)
+ {
+ /*
+ * Copy stdin to a temporary file...
+ */
+
+ int fd; /* File descriptor */
+ cups_file_t *fp; /* Temporary file */
+ char buffer[8192]; /* Buffer for copying */
+ int bytes; /* Number of bytes read */
+
+
+ if ((fd = cupsTempFd(tmpfilename, sizeof(tmpfilename))) < 0)
+ {
+ perror("ERROR: unable to create temporary file");
+ return (CUPS_BACKEND_FAILED);
+ }
+
+ if ((fp = cupsFileOpenFd(fd, compression ? "w9" : "w")) == NULL)
+ {
+ perror("ERROR: unable to open temporary file");
+ close(fd);
+ unlink(tmpfilename);
+ return (CUPS_BACKEND_FAILED);
+ }
+
+ while ((bytes = fread(buffer, 1, sizeof(buffer), stdin)) > 0)
+ if (cupsFileWrite(fp, buffer, bytes) < bytes)
+ {
+ perror("ERROR: unable to write to temporary file");
+ cupsFileClose(fp);
+ unlink(tmpfilename);
+ return (CUPS_BACKEND_FAILED);
+ }
+
+ cupsFileClose(fp);
+
+ /*
+ * Point to the single file from stdin...
+ */
+
+ filename = tmpfilename;
+ files = &filename;
+ num_files = 1;
+ }
+ else
+ {
+ /*
+ * Point to the files on the command-line...
+ */
+
+ num_files = argc - 6;
+ files = argv + 6;
+
+#ifdef HAVE_LIBZ
+ if (compression)
+ compress_files(num_files, files);
+#endif /* HAVE_LIBZ */
+ }
+
+ fprintf(stderr, "DEBUG: %d files to send in job...\n", num_files);
+
/*
* Set the authentication info, if any...
*/
* Try connecting to the remote server...
*/
+ fputs("STATE: +connecting-to-device\n", stderr);
+
do
{
fprintf(stderr, "INFO: Connecting to %s on port %d...\n", hostname, port);
* available printer in the class.
*/
- fprintf(stderr, "INFO: Unable to connect to %s, queuing on next printer in class...\n",
+ fprintf(stderr,
+ "INFO: Unable to connect to %s, queuing on next printer in "
+ "class...\n",
hostname);
if (argc == 6 || strcmp(filename, argv[6]))
if (errno == ECONNREFUSED || errno == EHOSTDOWN ||
errno == EHOSTUNREACH)
{
- fprintf(stderr, "INFO: Network host \'%s\' is busy; will retry in 30 seconds...\n",
+ fprintf(stderr,
+ "INFO: Network host \'%s\' is busy; will retry in 30 "
+ "seconds...\n",
hostname);
sleep(30);
}
}
while (http == NULL);
+ fputs("STATE: -connecting-to-device\n", stderr);
fprintf(stderr, "INFO: Connected to %s...\n", hostname);
/*
* don't support the copies attribute...
*/
- language = cupsLangDefault();
- charset_sup = NULL;
- copies_sup = NULL;
- format_sup = NULL;
- supported = NULL;
+ copies_sup = NULL;
+ format_sup = NULL;
+ supported = NULL;
do
{
* Build the IPP request...
*/
- request = ippNew();
- request->request.op.version[1] = version;
- request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
- request->request.op.request_id = 1;
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
- "attributes-charset", NULL, "utf-8");
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
- "attributes-natural-language", NULL,
- language != NULL ? language->language : "en");
+ request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+ request->request.op.version[1] = version;
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
* Switch to IPP/1.0...
*/
- fputs("INFO: Printer does not support IPP/1.1, trying IPP/1.0...\n", stderr);
+ fputs("INFO: Printer does not support IPP/1.1, trying IPP/1.0...\n",
+ stderr);
version = 0;
httpReconnect(http);
}
copies_sup = NULL; /* No */
}
- charset_sup = ippFindAttribute(supported, "charset-supported",
- IPP_TAG_CHARSET);
- format_sup = ippFindAttribute(supported, "document-format-supported",
- IPP_TAG_MIMETYPE);
+ format_sup = ippFindAttribute(supported, "document-format-supported",
+ IPP_TAG_MIMETYPE);
if (format_sup)
{
IPP_TAG_BOOLEAN);
if (printer_state == NULL ||
- (printer_state->values[0].integer > IPP_PRINTER_PROCESSING && waitprinter) ||
+ (printer_state->values[0].integer > IPP_PRINTER_PROCESSING &&
+ waitprinter) ||
printer_accepting == NULL ||
!printer_accepting->values[0].boolean)
{
* available printer in the class.
*/
- fprintf(stderr, "INFO: Unable to queue job on %s, queuing on next printer in class...\n",
+ fprintf(stderr,
+ "INFO: Unable to queue job on %s, queuing on next printer in "
+ "class...\n",
hostname);
ippDelete(supported);
else
copies = atoi(argv[4]);
- /*
- * Figure out the character set to use...
- */
-
- charset = language ? cupsLangEncoding(language) : "us-ascii";
-
- if (charset_sup)
- {
- /*
- * See if IPP server supports the requested character set...
- */
-
- for (i = 0; i < charset_sup->num_values; i ++)
- if (strcasecmp(charset, charset_sup->values[i].string.text) == 0)
- break;
-
- /*
- * If not, choose us-ascii or utf-8...
- */
-
- if (i >= charset_sup->num_values)
- {
- /*
- * See if us-ascii is supported...
- */
-
- for (i = 0; i < charset_sup->num_values; i ++)
- if (strcasecmp("us-ascii", charset_sup->values[i].string.text) == 0)
- break;
-
- if (i < charset_sup->num_values)
- charset = "us-ascii";
- else
- charset = "utf-8";
- }
- }
-
/*
* Then issue the print-job request...
*/
reasons = 0;
+ job_id = 0;
while (copies > 0)
{
* Build the IPP request...
*/
- request = ippNew();
- request->request.op.version[1] = version;
- request->request.op.operation_id = IPP_PRINT_JOB;
- request->request.op.request_id = 1;
+ if (job_cancelled)
+ break;
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
- "attributes-charset", NULL, charset);
+ if (num_files > 1)
+ request = ippNewRequest(IPP_CREATE_JOB);
+ else
+ request = ippNewRequest(IPP_PRINT_JOB);
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
- "attributes-natural-language", NULL,
- language != NULL ? language->language : "en");
+ request->request.op.version[1] = version;
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
fprintf(stderr, "DEBUG: job-name = \"%s\"\n", argv[3]);
+#ifdef HAVE_LIBZ
+ if (compression)
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+ "compression", NULL, "gzip");
+#endif /* HAVE_LIBZ */
+
/*
* Handle options on the command-line...
*/
num_options = cupsParseOptions(argv[5], 0, &options);
#ifdef __APPLE__
- if (content_type != NULL && strcasecmp(content_type, "application/pictwps") == 0)
+ if (content_type != NULL &&
+ !strcasecmp(content_type, "application/pictwps") && num_files == 1)
{
if (format_sup != NULL)
{
for (i = 0; i < format_sup->num_values; i ++)
- if (strcasecmp(content_type, format_sup->values[i].string.text) == 0)
+ if (!strcasecmp(content_type, format_sup->values[i].string.text))
break;
}
filename = pstmpname;
/*
- * Change the MIME type to application/postscript...
+ * Change the MIME type to application/postscript and change the
+ * number of copies to 1...
*/
content_type = "application/postscript";
+ copies = 1;
}
}
#endif /* __APPLE__ */
if (content_type != NULL && format_sup != NULL)
{
for (i = 0; i < format_sup->num_values; i ++)
- if (strcasecmp(content_type, format_sup->values[i].string.text) == 0)
+ if (!strcasecmp(content_type, format_sup->values[i].string.text))
break;
if (i < format_sup->num_values)
* Do the request...
*/
- if ((response = cupsDoFileRequest(http, request, resource, filename)) == NULL)
- ipp_status = cupsLastError();
+ if (num_files > 1)
+ response = cupsDoRequest(http, request, resource);
else
- ipp_status = response->request.status.status_code;
+ response = cupsDoFileRequest(http, request, resource, files[0]);
+
+ ipp_status = cupsLastError();
if (ipp_status > IPP_OK_CONFLICT)
{
job_id = 0;
+ if (job_cancelled)
+ break;
+
if (ipp_status == IPP_SERVICE_UNAVAILABLE ||
ipp_status == IPP_PRINTER_BUSY)
{
}
else
fprintf(stderr, "ERROR: Print file was not accepted (%s)!\n",
- ippErrorString(ipp_status));
+ cupsLastErrorString());
}
else if ((job_id_attr = ippFindAttribute(response, "job-id",
IPP_TAG_INTEGER)) == NULL)
fprintf(stderr, "NOTICE: Print file accepted - job ID %d.\n", job_id);
}
- if (response)
- ippDelete(response);
+ ippDelete(response);
+
+ if (job_cancelled)
+ break;
+
+ if (job_id && num_files > 1)
+ {
+ for (i = 0; i < num_files; i ++)
+ {
+ request = ippNewRequest(IPP_SEND_DOCUMENT);
+
+ request->request.op.version[1] = version;
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, uri);
+
+ ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id",
+ job_id);
+
+ if (argv[2][0])
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+ "requesting-user-name", NULL, argv[2]);
+
+ if ((i + 1) == num_files)
+ ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", 1);
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
+ "document-format", NULL, content_type);
+
+ ippDelete(cupsDoFileRequest(http, request, resource, files[i]));
+
+ if (cupsLastError() > IPP_OK_CONFLICT)
+ {
+ ipp_status = cupsLastError();
+
+ fprintf(stderr, "ERROR: Unable to add file %d to job: %s\n",
+ job_id, cupsLastErrorString());
+ break;
+ }
+ }
+ }
if (ipp_status <= IPP_OK_CONFLICT && argc > 6)
{
fputs("INFO: Waiting for job to complete...\n", stderr);
- for (;;)
+ for (; !job_cancelled;)
{
/*
* Build an IPP_GET_JOB_ATTRIBUTES request...
*/
- request = ippNew();
- request->request.op.version[1] = version;
- request->request.op.operation_id = IPP_GET_JOB_ATTRIBUTES;
- request->request.op.request_id = 1;
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
- "attributes-charset", NULL, charset);
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
- "attributes-natural-language", NULL,
- language != NULL ? language->language : "en");
+ request = ippNewRequest(IPP_GET_JOB_ATTRIBUTES);
+ request->request.op.version[1] = version;
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
if (!copies_sup)
httpReconnect(http);
- if ((response = cupsDoRequest(http, request, resource)) == NULL)
- ipp_status = cupsLastError();
- else
- ipp_status = response->request.status.status_code;
+ response = cupsDoRequest(http, request, resource);
+ ipp_status = cupsLastError();
if (ipp_status == IPP_NOT_FOUND)
{
if (ipp_status != IPP_SERVICE_UNAVAILABLE &&
ipp_status != IPP_PRINTER_BUSY)
{
- if (response)
- ippDelete(response);
+ ippDelete(response);
fprintf(stderr, "ERROR: Unable to get job %d attributes (%s)!\n",
job_id, ippErrorString(ipp_status));
}
}
- if (response != NULL)
+ if (response)
{
if ((job_state = ippFindAttribute(response, "job-state",
IPP_TAG_ENUM)) != NULL)
if (job_state->values[0].integer > IPP_JOB_PROCESSING ||
job_state->values[0].integer == IPP_JOB_HELD)
{
- if ((job_sheets = ippFindAttribute(response, "job-media-sheets-completed",
- IPP_TAG_INTEGER)) != NULL)
- fprintf(stderr, "PAGE: total %d\n", job_sheets->values[0].integer);
+ if ((job_sheets = ippFindAttribute(response,
+ "job-media-sheets-completed",
+ IPP_TAG_INTEGER)) != NULL)
+ fprintf(stderr, "PAGE: total %d\n",
+ job_sheets->values[0].integer);
ippDelete(response);
break;
}
}
- if (response)
- ippDelete(response);
+ ippDelete(response);
/*
* Check the printer state and report it if necessary...
*/
-/* if (!copies_sup)
- httpReconnect(http);*/
-
- check_printer_state(http, language, charset, uri, resource, argv[2],
- version);
+ check_printer_state(http, uri, resource, argv[2], version);
/*
* Wait 10 seconds before polling again...
}
/*
- * Check the printer state and report it if necessary...
+ * Cancel the job as needed...
*/
-/* if (!copies_sup)
- httpReconnect(http);*/
+ if (job_cancelled && job_id)
+ cancel_job(http, uri, job_id, resource, argv[2], version);
- check_printer_state(http, language, charset, uri, resource, argv[2], version);
+ /*
+ * Check the printer state and report it if necessary...
+ */
+
+ check_printer_state(http, uri, resource, argv[2], version);
/*
* Free memory...
httpClose(http);
- if (supported)
- ippDelete(supported);
+ ippDelete(supported);
/*
* Remove the temporary file(s) if necessary...
if (tmpfilename[0])
unlink(tmpfilename);
+#ifdef HAVE_LIBZ
+ if (compression)
+ {
+ for (i = 0; i < num_files; i ++)
+ unlink(files[i]);
+ }
+#endif /* HAVE_LIBZ */
+
#ifdef __APPLE__
if (pstmpname[0])
unlink(pstmpname);
}
+/*
+ * 'cancel_job()' - Cancel a print job.
+ */
+
+static void
+cancel_job(http_t *http, /* I - HTTP connection */
+ const char *uri, /* I - printer-uri */
+ int id, /* I - job-id */
+ const char *resource, /* I - Resource path */
+ const char *user, /* I - requesting-user-name */
+ int version) /* I - IPP version */
+{
+ ipp_t *request; /* Cancel-Job request */
+
+
+ fputs("INFO: Cancelling print job...\n", stderr);
+
+ request = ippNewRequest(IPP_CANCEL_JOB);
+ request->request.op.version[1] = version;
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, uri);
+ ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", id);
+
+ if (user && user[0])
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+ "requesting-user-name", NULL, user);
+
+ /*
+ * Do the request...
+ */
+
+ ippDelete(cupsDoRequest(http, request, resource));
+
+ if (cupsLastError() > IPP_OK_CONFLICT)
+ fprintf(stderr, "ERROR: Unable to cancel job %d: %s\n", id,
+ cupsLastErrorString());
+}
+
+
/*
* 'check_printer_state()' - Check the printer state...
*/
-void
-check_printer_state(http_t *http, /* I - HTTP connection */
- cups_lang_t *language,
- /* I - Language */
- const char *charset,
- /* I - Charset */
- const char *uri, /* I - Printer URI */
- const char *resource,
- /* I - Resource path */
- const char *user, /* I - Username, if any */
- int version)/* I - IPP version */
+static void
+check_printer_state(
+ http_t *http, /* I - HTTP connection */
+ const char *uri, /* I - Printer URI */
+ const char *resource, /* I - Resource path */
+ const char *user, /* I - Username, if any */
+ int version) /* I - IPP version */
{
ipp_t *request, /* IPP request */
*response; /* IPP response */
* Check on the printer state...
*/
- request = ippNew();
- request->request.op.version[1] = version;
- request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
- request->request.op.request_id = 1;
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
- "attributes-charset", NULL, charset);
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
- "attributes-natural-language", NULL,
- language != NULL ? language->language : "en");
+ request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+ request->request.op.version[1] = version;
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
}
+#ifdef HAVE_LIBZ
+/*
+ * 'compress_files()' - Compress print files...
+ */
+
+static void
+compress_files(int num_files, /* I - Number of files */
+ char **files) /* I - Files */
+{
+ int i, /* Looping var */
+ fd; /* Temporary file descriptor */
+ ssize_t bytes; /* Bytes read/written */
+ size_t total; /* Total bytes read */
+ cups_file_t *in, /* Input file */
+ *out; /* Output file */
+ struct stat outinfo; /* Output file information */
+ char filename[1024], /* Temporary filename */
+ buffer[32768]; /* Copy buffer */
+
+
+ fprintf(stderr, "DEBUG: Compressing %d job files...\n", num_files);
+ for (i = 0; i < num_files; i ++)
+ {
+ if ((fd = cupsTempFd(filename, sizeof(filename))) < 0)
+ {
+ perror("ERROR: Unable to create temporary compressed print file");
+ exit(CUPS_BACKEND_FAILED);
+ }
+
+ if ((out = cupsFileOpenFd(fd, "w9")) == NULL)
+ {
+ perror("ERROR: Unable to open temporary compressed print file");
+ exit(CUPS_BACKEND_FAILED);
+ }
+
+ if ((in = cupsFileOpen(files[i], "r")) == NULL)
+ {
+ fprintf(stderr, "ERROR: Unable to open print file \"%s\": %s\n",
+ files[i], strerror(errno));
+ cupsFileClose(out);
+ exit(CUPS_BACKEND_FAILED);
+ }
+
+ total = 0;
+ while ((bytes = cupsFileRead(in, buffer, sizeof(buffer))) > 0)
+ if (cupsFileWrite(out, buffer, bytes) < bytes)
+ {
+ fprintf(stderr, "ERROR: Unable to write " CUPS_LLFMT " bytes to \"%s\": %s\n",
+ CUPS_LLCAST bytes, filename, strerror(errno));
+ cupsFileClose(in);
+ cupsFileClose(out);
+ exit(CUPS_BACKEND_FAILED);
+ }
+ else
+ total += bytes;
+
+ cupsFileClose(out);
+ cupsFileClose(in);
+
+ files[i] = strdup(filename);
+
+ if (!stat(filename, &outinfo))
+ fprintf(stderr,
+ "DEBUG: File %d compressed to %.1f%% of original size, "
+ CUPS_LLFMT " bytes...\n",
+ i + 1, 100.0 * outinfo.st_size / total,
+ CUPS_LLCAST outinfo.st_size);
+ }
+}
+#endif /* HAVE_LIBZ */
+
+
/*
* 'password_cb()' - Disable the password prompt for cupsDoFileRequest().
*/
-const char * /* O - Password */
-password_cb(const char *prompt) /* I - Prompt (not used) */
+static const char * /* O - Password */
+password_cb(const char *prompt) /* I - Prompt (not used) */
{
(void)prompt;
* 'report_printer_state()' - Report the printer state.
*/
-int /* O - Number of reasons shown */
+static int /* O - Number of reasons shown */
report_printer_state(ipp_t *ipp) /* I - IPP response */
{
int i; /* Looping var */
* PostScript file for printing...
*/
-int /* O - Exit status of filter */
-run_pictwps_filter(char **argv, /* I - Command-line arguments */
- const char *filename) /* I - Filename */
+static int /* O - Exit status of filter */
+run_pictwps_filter(char **argv, /* I - Command-line arguments */
+ const char *filename)/* I - Filename */
{
- struct stat fileinfo; /* Print file information */
- const char *ppdfile; /* PPD file for destination printer */
- int pid; /* Child process ID */
- int fd; /* Temporary file descriptor */
- int status; /* Exit status of filter */
- const char *printer; /* PRINTER env var */
- static char ppdenv[1024]; /* PPD environment variable */
+ struct stat fileinfo; /* Print file information */
+ const char *ppdfile; /* PPD file for destination printer */
+ int pid; /* Child process ID */
+ int fd; /* Temporary file descriptor */
+ int status; /* Exit status of filter */
+ const char *printer; /* PRINTER env var */
+ static char ppdenv[1024]; /* PPD environment variable */
/*
{
(void)sig; /* remove compiler warnings... */
+ if (!job_cancelled)
+ {
+ /*
+ * Flag that the job should be cancelled...
+ */
+
+ job_cancelled = 1;
+ return;
+ }
+
/*
- * Remove the temporary file(s) if necessary...
+ * The scheduler already tried to cancel us once, now just terminate
+ * after removing our temp files!
*/
if (tmpfilename[0])
/*
- * End of "$Id: ipp.c 4906 2006-01-10 20:53:28Z mike $".
+ * End of "$Id: ipp.c 5686 2006-06-21 21:02:56Z mike $".
*/