/*
- * "$Id: ipp.c 6365 2007-03-19 20:56:57Z mike $"
+ * "$Id: ipp.c 6422 2007-03-30 20:49:37Z mike $"
*
* IPP backend for the Common UNIX Printing System (CUPS).
*
#include <cups/backend.h>
#include <cups/cups.h>
#include <cups/language.h>
+#include <cups/i18n.h>
#include <cups/string.h>
#include <signal.h>
#include <sys/wait.h>
ipp_t *request, /* IPP request */
*response, /* IPP response */
*supported; /* get-printer-attributes response */
+ time_t start_time; /* Time of first connect */
+ int recoverable; /* Recoverable error shown? */
+ int contimeout; /* Connection timeout */
+ int delay; /* Delay for retries... */
int compression, /* Do compression of the job data? */
waitjob, /* Wait for job complete? */
waitprinter; /* Wait for printer ready? */
}
else if (argc < 6)
{
- fprintf(stderr,
- "Usage: %s job-id user title copies options [file ... fileN]\n",
+ fprintf(stderr, _("Usage: %s job-id user title copies options [file]\n"),
argv[0]);
return (CUPS_BACKEND_STOP);
}
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);
}
version = 1;
waitjob = 1;
waitprinter = 1;
+ contimeout = 7 * 24 * 60 * 60;
if ((optptr = strchr(resource, '?')) != NULL)
{
cupsSetEncryption(HTTP_ENCRYPT_IF_REQUESTED);
else
{
- fprintf(stderr, "ERROR: Unknown encryption option value \"%s\"!\n",
- value);
+ fprintf(stderr,
+ _("ERROR: Unknown encryption option value \"%s\"!\n"),
+ value);
}
}
else if (!strcasecmp(name, "version"))
version = 1;
else
{
- fprintf(stderr, "ERROR: Unknown version option value \"%s\"!\n",
- value);
+ fprintf(stderr,
+ _("ERROR: Unknown version option value \"%s\"!\n"),
+ value);
}
}
#ifdef HAVE_LIBZ
!strcasecmp(value, "gzip");
}
#endif /* HAVE_LIBZ */
+ else if (!strcasecmp(name, "contimeout"))
+ {
+ /*
+ * Set the connection timeout...
+ */
+
+ if (atoi(value) > 0)
+ contimeout = atoi(value);
+ }
else
{
/*
* Unknown option...
*/
- fprintf(stderr, "ERROR: Unknown option \"%s\" with value \"%s\"!\n",
+ fprintf(stderr, _("ERROR: Unknown option \"%s\" with value \"%s\"!\n"),
name, value);
}
}
* Try connecting to the remote server...
*/
+ delay = 5;
+ recoverable = 0;
+ start_time = time(NULL);
+
fputs("STATE: +connecting-to-device\n", stderr);
do
{
- fprintf(stderr, "INFO: Connecting to %s on port %d...\n", hostname, port);
+ fprintf(stderr, _("INFO: Connecting to %s on port %d...\n"),
+ hostname, port);
if ((http = httpConnectEncrypt(hostname, port, cupsEncryption())) == NULL)
{
* available printer in the class.
*/
- fprintf(stderr,
- "INFO: Unable to connect to %s, queuing on next printer in "
- "class...\n",
- hostname);
+ fputs(_("INFO: Unable to contact printer, queuing on next "
+ "printer in class...\n"), stderr);
if (argc == 6 || strcmp(filename, argv[6]))
unlink(filename);
if (errno == ECONNREFUSED || errno == EHOSTDOWN ||
errno == EHOSTUNREACH)
{
+ if (contimeout && (time(NULL) - start_time) > contimeout)
+ {
+ fputs(_("ERROR: Printer not responding!\n"), stderr);
+ return (CUPS_BACKEND_FAILED);
+ }
+
+ recoverable = 1;
+
fprintf(stderr,
- "INFO: Network host \'%s\' is busy; will retry in 30 "
- "seconds...\n",
- hostname);
- sleep(30);
+ _("WARNING: recoverable: Network host \'%s\' is busy; will "
+ "retry in %d seconds...\n"),
+ hostname, delay);
+
+ sleep(delay);
+
+ if (delay < 30)
+ delay += 5;
}
else if (h_errno)
{
- fprintf(stderr, "INFO: Unable to lookup host \'%s\' - %s\n",
- hostname, hstrerror(h_errno));
- sleep(30);
+ fprintf(stderr, _("ERROR: Unable to locate printer \'%s\'!\n"),
+ hostname);
+ return (CUPS_BACKEND_STOP);
}
else
{
- perror("ERROR: Unable to connect to IPP host");
+ recoverable = 1;
+
+ fprintf(stderr, "DEBUG: Connection error: %s\n", strerror(errno));
+ fputs(_("ERROR: recoverable: Unable to connect to printer; will "
+ "retry in 30 seconds...\n"), stderr);
sleep(30);
}
}
fputs("STATE: -connecting-to-device\n", stderr);
- fprintf(stderr, "INFO: Connected to %s...\n", hostname);
+ fprintf(stderr, _("INFO: Connected to %s...\n"), hostname);
#ifdef AF_INET6
if (http->hostaddr->addr.sa_family == AF_INET6)
- fprintf(stderr, "DEBUG: Connected to [%s]:%d (IPv6)...\n",
- httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
- ntohs(http->hostaddr->ipv6.sin6_port));
+ fprintf(stderr, "DEBUG: Connected to [%s]:%d (IPv6)...\n",
+ httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
+ ntohs(http->hostaddr->ipv6.sin6_port));
else
#endif /* AF_INET6 */
if (http->hostaddr->addr.sa_family == AF_INET)
fprintf(stderr, "DEBUG: Connected to %s:%d (IPv4)...\n",
- httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
- ntohs(http->hostaddr->ipv4.sin_port));
+ httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
+ ntohs(http->hostaddr->ipv4.sin_port));
/*
* Build a URI for the printer and fill the standard IPP attributes for
if (ipp_status == IPP_PRINTER_BUSY ||
ipp_status == IPP_SERVICE_UNAVAILABLE)
{
- fputs("INFO: Printer busy; will retry in 10 seconds...\n", stderr);
+ if (contimeout && (time(NULL) - start_time) > contimeout)
+ {
+ fputs(_("ERROR: Printer not responding!\n"), stderr);
+ return (CUPS_BACKEND_FAILED);
+ }
+
+ recoverable = 1;
+
+ fprintf(stderr,
+ _("WARNING: recoverable: Network host \'%s\' is busy; will "
+ "retry in %d seconds...\n"),
+ hostname, delay);
+
report_printer_state(supported);
- sleep(10);
+
+ sleep(delay);
+
+ if (delay < 30)
+ delay += 5;
}
else if ((ipp_status == IPP_BAD_REQUEST ||
ipp_status == IPP_VERSION_NOT_SUPPORTED) && version == 1)
* Switch to IPP/1.0...
*/
- fputs("INFO: Printer does not support IPP/1.1, trying IPP/1.0...\n",
+ fputs(_("INFO: Printer does not support IPP/1.1, trying IPP/1.0...\n"),
stderr);
version = 0;
httpReconnect(http);
}
else if (ipp_status == IPP_NOT_FOUND)
{
- fputs("ERROR: Destination printer does not exist!\n", stderr);
+ fputs(_("ERROR: Destination printer does not exist!\n"), stderr);
if (supported)
ippDelete(supported);
}
else
{
- fprintf(stderr, "ERROR: Unable to get printer status (%s)!\n",
- ippErrorString(ipp_status));
+ fprintf(stderr, _("ERROR: Unable to get printer status (%s)!\n"),
+ cupsLastErrorString());
sleep(10);
}
* available printer in the class.
*/
- fprintf(stderr,
- "INFO: Unable to queue job on %s, queuing on next printer in "
- "class...\n",
- hostname);
+ fputs(_("INFO: Unable to contact printer, queuing on next "
+ "printer in class...\n"), stderr);
ippDelete(supported);
httpClose(http);
}
}
+ if (recoverable)
+ {
+ /*
+ * If we've shown a recoverable error make sure the printer proxies
+ * have a chance to see the recovered message. Not pretty but
+ * necessary for now...
+ */
+
+ fputs("INFO: recovered: \n", stderr);
+ sleep(5);
+ }
+
/*
* See if the printer supports multiple copies...
*/
if (ipp_status == IPP_SERVICE_UNAVAILABLE ||
ipp_status == IPP_PRINTER_BUSY)
{
- fputs("INFO: Printer is busy; retrying print job...\n", stderr);
+ fputs(_("INFO: Printer busy; will retry in 10 seconds...\n"), stderr);
sleep(10);
}
else if ((ipp_status == IPP_BAD_REQUEST ||
* Switch to IPP/1.0...
*/
- fputs("INFO: Printer does not support IPP/1.1, trying IPP/1.0...\n",
+ fputs(_("INFO: Printer does not support IPP/1.1, trying IPP/1.0...\n"),
stderr);
version = 0;
httpReconnect(http);
}
else
- fprintf(stderr, "ERROR: Print file was not accepted (%s)!\n",
+ fprintf(stderr, _("ERROR: Print file was not accepted (%s)!\n"),
cupsLastErrorString());
}
else if ((job_id_attr = ippFindAttribute(response, "job-id",
IPP_TAG_INTEGER)) == NULL)
{
- fputs("NOTICE: Print file accepted - job ID unknown.\n", stderr);
+ fputs(_("NOTICE: Print file accepted - job ID unknown.\n"), stderr);
job_id = 0;
}
else
{
job_id = job_id_attr->values[0].integer;
- fprintf(stderr, "NOTICE: Print file accepted - job ID %d.\n", job_id);
+ fprintf(stderr, _("NOTICE: Print file accepted - job ID %d.\n"), job_id);
}
ippDelete(response);
{
ipp_status = cupsLastError();
- fprintf(stderr, "ERROR: Unable to add file %d to job: %s\n",
+ fprintf(stderr, _("ERROR: Unable to add file %d to job: %s\n"),
job_id, cupsLastErrorString());
break;
}
if (!job_id || !waitjob)
continue;
- fputs("INFO: Waiting for job to complete...\n", stderr);
+ fputs(_("INFO: Waiting for job to complete...\n"), stderr);
for (; !job_cancelled;)
{
{
ippDelete(response);
- fprintf(stderr, "ERROR: Unable to get job %d attributes (%s)!\n",
- job_id, ippErrorString(ipp_status));
+ fprintf(stderr, _("ERROR: Unable to get job %d attributes (%s)!\n"),
+ job_id, cupsLastErrorString());
break;
}
}
ipp_t *request; /* Cancel-Job request */
- fputs("INFO: Cancelling print job...\n", stderr);
+ fputs(_("INFO: Canceling print job...\n"), stderr);
request = ippNewRequest(IPP_CANCEL_JOB);
request->request.op.version[1] = version;
ippDelete(cupsDoRequest(http, request, resource));
if (cupsLastError() > IPP_OK_CONFLICT)
- fprintf(stderr, "ERROR: Unable to cancel job %d: %s\n", id,
+ fprintf(stderr, _("ERROR: Unable to cancel job %d: %s\n"), id,
cupsLastErrorString());
}
{
if ((fd = cupsTempFd(filename, sizeof(filename))) < 0)
{
- perror("ERROR: Unable to create temporary compressed print file");
+ fprintf(stderr,
+ _("ERROR: Unable to create temporary compressed print file: %s\n"),
+ strerror(errno));
exit(CUPS_BACKEND_FAILED);
}
if ((out = cupsFileOpenFd(fd, "w9")) == NULL)
{
- perror("ERROR: Unable to open temporary compressed print file");
+ fprintf(stderr,
+ _("ERROR: Unable to open temporary compressed print file: %s\n"),
+ strerror(errno));
exit(CUPS_BACKEND_FAILED);
}
if ((in = cupsFileOpen(files[i], "r")) == NULL)
{
- fprintf(stderr, "ERROR: Unable to open print file \"%s\": %s\n",
+ fprintf(stderr, _("ERROR: Unable to open print file \"%s\": %s\n"),
files[i], strerror(errno));
cupsFileClose(out);
exit(CUPS_BACKEND_FAILED);
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));
+ fprintf(stderr, _("ERROR: Unable to write %d bytes to \"%s\": %s\n"),
+ (int)bytes, filename, strerror(errno));
cupsFileClose(in);
cupsFileClose(out);
exit(CUPS_BACKEND_FAILED);
message = "";
if (!strncmp(reason, "media-needed", 12))
- message = "Media tray needs to be filled.";
+ message = _("Media tray needs to be filled.");
else if (!strncmp(reason, "media-jam", 9))
- message = "Media jam!";
+ message = _("Media jam!");
else if (!strncmp(reason, "moving-to-paused", 16) ||
!strncmp(reason, "paused", 6) ||
!strncmp(reason, "shutdown", 8))
- message = "Printer off-line.";
+ message = _("Printer off-line.");
else if (!strncmp(reason, "toner-low", 9))
- message = "Toner low.";
+ message = _("Toner low.");
else if (!strncmp(reason, "toner-empty", 11))
- message = "Out of toner!";
+ message = _("Out of toner!");
else if (!strncmp(reason, "cover-open", 10))
- message = "Cover open.";
+ message = _("Cover open.");
else if (!strncmp(reason, "interlock-open", 14))
- message = "Interlock open.";
+ message = _("Interlock open.");
else if (!strncmp(reason, "door-open", 9))
- message = "Door open.";
+ message = _("Door open.");
else if (!strncmp(reason, "input-tray-missing", 18))
- message = "Media tray missing!";
+ message = _("Media tray missing!");
else if (!strncmp(reason, "media-low", 9))
- message = "Media tray almost empty.";
+ message = _("Media tray almost empty.");
else if (!strncmp(reason, "media-empty", 11))
- message = "Media tray empty!";
+ message = _("Media tray empty!");
else if (!strncmp(reason, "output-tray-missing", 19))
- message = "Output tray missing!";
+ message = _("Output tray missing!");
else if (!strncmp(reason, "output-area-almost-full", 23))
- message = "Output bin almost full.";
+ message = _("Output bin almost full.");
else if (!strncmp(reason, "output-area-full", 16))
- message = "Output bin full!";
+ message = _("Output bin full!");
else if (!strncmp(reason, "marker-supply-low", 17))
- message = "Ink/toner almost empty.";
+ message = _("Ink/toner almost empty.");
else if (!strncmp(reason, "marker-supply-empty", 19))
- message = "Ink/toner empty!";
+ message = _("Ink/toner empty!");
else if (!strncmp(reason, "marker-waste-almost-full", 24))
- message = "Ink/toner waste bin almost full.";
+ message = _("Ink/toner waste bin almost full.");
else if (!strncmp(reason, "marker-waste-full", 17))
- message = "Ink/toner waste bin full!";
+ message = _("Ink/toner waste bin full!");
else if (!strncmp(reason, "fuser-over-temp", 15))
- message = "Fuser temperature high!";
+ message = _("Fuser temperature high!");
else if (!strncmp(reason, "fuser-under-temp", 16))
- message = "Fuser temperature low!";
+ message = _("Fuser temperature low!");
else if (!strncmp(reason, "opc-near-eol", 12))
- message = "OPC almost at end-of-life.";
+ message = _("OPC almost at end-of-life.");
else if (!strncmp(reason, "opc-life-over", 13))
- message = "OPC at end-of-life!";
+ message = _("OPC at end-of-life!");
else if (!strncmp(reason, "developer-low", 13))
- message = "Developer almost empty.";
+ message = _("Developer almost empty.");
else if (!strncmp(reason, "developer-empty", 15))
- message = "Developer empty!";
+ message = _("Developer empty!");
else if (strstr(reason, "error") != NULL)
{
message = unknown;
- snprintf(unknown, sizeof(unknown), "Unknown printer error (%s)!",
+ snprintf(unknown, sizeof(unknown), _("Unknown printer error (%s)!"),
reason);
}
printer = getenv("PRINTER");
if (!printer)
{
- fputs("ERROR: PRINTER environment variable not defined!\n", stderr);
+ fputs(_("ERROR: PRINTER environment variable not defined!\n"), stderr);
return (-1);
}
if ((ppdfile = cupsGetPPD(printer)) == NULL)
{
- fprintf(stderr, "ERROR: Unable to get PPD file for printer \"%s\" - %s.\n",
- printer, ippErrorString(cupsLastError()));
- /*return (-1);*/
+ fprintf(stderr,
+ _("ERROR: Unable to get PPD file for printer \"%s\" - %s.\n"),
+ printer, cupsLastErrorString());
}
else
{
if ((fd = cupsTempFd(pstmpname, sizeof(pstmpname))) < 0)
{
- fprintf(stderr, "ERROR: Unable to create temporary file - %s.\n",
+ fprintf(stderr, _("ERROR: Unable to create temporary file - %s.\n"),
strerror(errno));
if (ppdfile)
unlink(ppdfile);
execlp("pictwpstops", printer, argv[1], argv[2], argv[3], argv[4], argv[5],
filename, NULL);
- perror("ERROR: Unable to exec pictwpstops");
+ fprintf(stderr, _("ERROR: Unable to exec pictwpstops: %s\n"),
+ strerror(errno));
return (errno);
}
* Error!
*/
- perror("ERROR: Unable to fork pictwpstops");
+ fprintf(stderr, _("ERROR: Unable to fork pictwpstops: %s\n"),
+ strerror(errno));
unlink(filename);
if (ppdfile)
unlink(ppdfile);
if (wait(&status) < 0)
{
- perror("ERROR: Unable to wait for pictwpstops");
+ fprintf(stderr, _("ERROR: Unable to wait for pictwpstops: %s\n"),
+ strerror(errno));
close(fd);
unlink(filename);
if (ppdfile)
if (status)
{
if (status >= 256)
- fprintf(stderr, "ERROR: pictwpstops exited with status %d!\n",
+ fprintf(stderr, _("ERROR: pictwpstops exited with status %d!\n"),
status / 256);
else
- fprintf(stderr, "ERROR: pictwpstops exited on signal %d!\n",
+ fprintf(stderr, _("ERROR: pictwpstops exited on signal %d!\n"),
status);
unlink(filename);
/*
- * End of "$Id: ipp.c 6365 2007-03-19 20:56:57Z mike $".
+ * End of "$Id: ipp.c 6422 2007-03-30 20:49:37Z mike $".
*/