/*
- * "$Id: ipp.c 6911 2007-09-04 20:35:08Z mike $"
+ * "$Id: ipp.c 7018 2007-10-10 22:14:03Z mike $"
*
* IPP backend for the Common UNIX Printing System (CUPS).
*
- * Copyright 2007 by Apple Inc.
+ * Copyright 2007-2008 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
ipp_attribute_t *printer_accepting; /* printer-is-accepting-jobs */
int copies, /* Number of copies for job */
copies_remaining; /* Number of copies remaining */
- const char *content_type; /* CONTENT_TYPE environment variable */
+ const char *content_type, /* CONTENT_TYPE environment variable */
+ *final_content_type; /* FINAL_CONTENT_TYPE environment var */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
* Get the (final) content type...
*/
- if ((content_type = getenv("FINAL_CONTENT_TYPE")) == NULL)
- if ((content_type = getenv("CONTENT_TYPE")) == NULL)
- content_type = "application/octet-stream";
+ if ((content_type = getenv("CONTENT_TYPE")) == NULL)
+ content_type = "application/octet-stream";
- if (!strncmp(content_type, "printer/", 8))
- content_type = "application/vnd.cups-raw";
+ if ((final_content_type = getenv("FINAL_CONTENT_TYPE")) == NULL)
+ {
+ final_content_type = content_type;
+
+ if (!strncmp(final_content_type, "printer/", 8))
+ final_content_type = "application/vnd.cups-raw";
+ }
/*
* Extract the hostname and printer name from the URI...
return (CUPS_BACKEND_STOP);
}
+ if (!port)
+ port = IPP_PORT; /* Default to port 631 */
+
if (!strcmp(method, "https"))
cupsSetEncryption(HTTP_ENCRYPT_ALWAYS);
else
if ((fd = cupsTempFd(tmpfilename, sizeof(tmpfilename))) < 0)
{
- perror("ERROR: unable to create temporary file");
+ _cupsLangPrintError(_("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");
+ _cupsLangPrintError(_("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");
+ _cupsLangPrintError(_("ERROR: Unable to write to temporary file"));
cupsFileClose(fp);
unlink(tmpfilename);
return (CUPS_BACKEND_FAILED);
* Point to the single file from stdin...
*/
- filename = tmpfilename;
- files = &filename;
- num_files = 1;
-
+ filename = tmpfilename;
+ num_files = 1;
+ files = &filename;
send_options = 0;
}
else
* Point to the files on the command-line...
*/
- num_files = argc - 6;
- files = argv + 6;
-
- send_options = strncasecmp(content_type, "application/vnd.cups-", 21) != 0;
+ num_files = argc - 6;
+ files = argv + 6;
+ send_options = 1;
#ifdef HAVE_LIBZ
if (compression)
_("INFO: Unable to contact printer, queuing on next "
"printer in class...\n"));
- if (argc == 6 || strcmp(filename, argv[6]))
- unlink(filename);
+ if (tmpfilename[0])
+ unlink(tmpfilename);
/*
* Sleep 5 seconds to keep the job from requeuing too rapidly...
if (job_cancelled)
{
- if (argc == 6 || strcmp(filename, argv[6]))
- unlink(filename);
+ if (tmpfilename[0])
+ unlink(tmpfilename);
return (CUPS_BACKEND_FAILED);
}
ippDelete(supported);
httpClose(http);
- if (argc == 6 || strcmp(filename, argv[6]))
- unlink(filename);
+ if (tmpfilename[0])
+ unlink(tmpfilename);
/*
* Sleep 5 seconds to keep the job from requeuing too rapidly...
num_options = cupsParseOptions(argv[5], 0, &options);
#ifdef __APPLE__
- if (content_type != NULL &&
- !strcasecmp(content_type, "application/pictwps") && num_files == 1)
+ if (!strcasecmp(final_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))
+ if (!strcasecmp(final_content_type, format_sup->values[i].string.text))
break;
}
* so convert the document to PostScript...
*/
- if (run_pictwps_filter(argv, filename))
+ if (run_pictwps_filter(argv, files[0]))
+ {
+ if (pstmpname[0])
+ unlink(pstmpname);
+
+ if (tmpfilename[0])
+ unlink(tmpfilename);
+
return (CUPS_BACKEND_FAILED);
+ }
- filename = pstmpname;
+ files[0] = pstmpname;
/*
* Change the MIME type to application/postscript and change the
* number of copies to 1...
*/
- content_type = "application/postscript";
- copies = 1;
- copies_remaining = 1;
- send_options = 0;
+ final_content_type = "application/postscript";
+ copies = 1;
+ copies_remaining = 1;
+ send_options = 0;
}
}
#endif /* __APPLE__ */
- if (content_type != NULL && format_sup != NULL)
+ if (format_sup != NULL)
{
for (i = 0; i < format_sup->num_values; i ++)
- if (!strcasecmp(content_type, format_sup->values[i].string.text))
+ if (!strcasecmp(final_content_type, format_sup->values[i].string.text))
break;
if (i < format_sup->num_values)
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
- "document-format", NULL, content_type);
+ "document-format", NULL, final_content_type);
}
if (copies_sup && version > 0 && send_options)
_cupsLangPuts(stderr, _("INFO: Waiting for job to complete...\n"));
- for (; !job_cancelled;)
+ for (delay = 1; !job_cancelled;)
{
/*
* Build an IPP_GET_JOB_ATTRIBUTES request...
check_printer_state(http, uri, resource, argv[2], version, job_id);
/*
- * Wait 10 seconds before polling again...
+ * Wait 1-10 seconds before polling again...
*/
- sleep(10);
+ sleep(delay);
+
+ delay ++;
+ if (delay > 10)
+ delay = 1;
}
}
{
(void)prompt;
- if (password && password_tries < 3)
+ if (password && *password && password_tries < 3)
{
password_tries ++;
else if (!strncmp(reason, "moving-to-paused", 16) ||
!strncmp(reason, "paused", 6) ||
!strncmp(reason, "shutdown", 8))
- message = _("Printer off-line.");
+ message = _("Printer offline.");
else if (!strncmp(reason, "toner-low", 9))
message = _("Toner low.");
else if (!strncmp(reason, "toner-empty", 11))
_cupsLangPrintf(stderr, _("ERROR: Unable to fork pictwpstops: %s\n"),
strerror(errno));
- unlink(filename);
if (ppdfile)
unlink(ppdfile);
return (-1);
_cupsLangPrintf(stderr, _("ERROR: Unable to wait for pictwpstops: %s\n"),
strerror(errno));
close(fd);
- unlink(filename);
if (ppdfile)
unlink(ppdfile);
return (-1);
_cupsLangPrintf(stderr, _("ERROR: pictwpstops exited on signal %d!\n"),
status);
- unlink(filename);
return (status);
}
/*
- * End of "$Id: ipp.c 6911 2007-09-04 20:35:08Z mike $".
+ * End of "$Id: ipp.c 7018 2007-10-10 22:14:03Z mike $".
*/