]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/ipp.c
Load cups into easysw/current.
[thirdparty/cups.git] / backend / ipp.c
index 3cc342f2cfdf68c1ca5e08f66957c922c995d483..616c18c62672f2bbca9e06b07f33509a568bd2fd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$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).
  *
@@ -50,6 +50,7 @@
 #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>
@@ -121,6 +122,10 @@ main(int  argc,                            /* I - Number of command-line args */
   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? */
@@ -200,8 +205,7 @@ main(int  argc,                             /* I - Number of command-line args */
   }
   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);
   }
@@ -226,8 +230,8 @@ main(int  argc,                             /* I - Number of command-line args */
                      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);
   }
 
@@ -244,6 +248,7 @@ main(int  argc,                             /* I - Number of command-line args */
   version     = 1;
   waitjob     = 1;
   waitprinter = 1;
+  contimeout  = 7 * 24 * 60 * 60;
 
   if ((optptr = strchr(resource, '?')) != NULL)
   {
@@ -328,8 +333,9 @@ main(int  argc,                             /* I - Number of command-line args */
          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"))
@@ -340,8 +346,9 @@ main(int  argc,                             /* I - Number of command-line args */
          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
@@ -353,13 +360,22 @@ main(int  argc,                           /* I - Number of command-line args */
                      !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);
       }
     }
@@ -513,11 +529,16 @@ main(int  argc,                           /* I - Number of command-line args */
   * 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)
     {
@@ -533,10 +554,8 @@ main(int  argc,                            /* I - Number of command-line args */
        * 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);
@@ -553,21 +572,37 @@ main(int  argc,                           /* I - Number of command-line args */
       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);
       }
 
@@ -586,19 +621,19 @@ main(int  argc,                           /* I - Number of command-line args */
   }
 
   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
@@ -650,9 +685,25 @@ main(int  argc,                            /* I - Number of command-line args */
       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)
@@ -661,14 +712,14 @@ main(int  argc,                           /* I - Number of command-line args */
        * 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);
@@ -677,8 +728,8 @@ main(int  argc,                             /* I - Number of command-line args */
       }
       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);
       }
 
@@ -740,10 +791,8 @@ main(int  argc,                            /* I - Number of command-line args */
       * 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);
@@ -761,6 +810,18 @@ main(int  argc,                            /* I - Number of command-line args */
     }
   }
 
+  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...
   */
@@ -931,7 +992,7 @@ main(int  argc,                             /* I - Number of command-line args */
       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 ||
@@ -941,25 +1002,25 @@ main(int  argc,                          /* I - Number of command-line args */
        * 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);
@@ -997,7 +1058,7 @@ main(int  argc,                            /* I - Number of command-line args */
        {
          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;
        }
@@ -1022,7 +1083,7 @@ main(int  argc,                           /* I - Number of command-line args */
     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;)
     {
@@ -1076,8 +1137,8 @@ main(int  argc,                           /* I - Number of command-line args */
        {
          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;
        }
       }
@@ -1186,7 +1247,7 @@ cancel_job(http_t     *http,              /* I - HTTP connection */
   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;
@@ -1206,7 +1267,7 @@ cancel_job(http_t     *http,              /* I - HTTP connection */
   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());
 }
 
@@ -1281,19 +1342,23 @@ compress_files(int  num_files,          /* I - Number of files */
   {
     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);
@@ -1303,8 +1368,8 @@ compress_files(int  num_files,            /* I - Number of files */
     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);
@@ -1398,60 +1463,60 @@ report_printer_state(ipp_t *ipp)        /* I - IPP response */
     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);
     }
 
@@ -1505,15 +1570,15 @@ run_pictwps_filter(char       **argv,   /* I - Command-line arguments */
   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
   {
@@ -1527,7 +1592,7 @@ run_pictwps_filter(char       **argv,     /* I - Command-line arguments */
 
   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);
@@ -1584,7 +1649,8 @@ run_pictwps_filter(char       **argv,     /* I - Command-line arguments */
 
     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);
   }
 
@@ -1596,7 +1662,8 @@ run_pictwps_filter(char       **argv,     /* I - Command-line arguments */
     * Error!
     */
 
-    perror("ERROR: Unable to fork pictwpstops");
+    fprintf(stderr, _("ERROR: Unable to fork pictwpstops: %s\n"),
+            strerror(errno));
     unlink(filename);
     if (ppdfile)
       unlink(ppdfile);
@@ -1609,7 +1676,8 @@ run_pictwps_filter(char       **argv,     /* I - Command-line arguments */
 
   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)
@@ -1625,10 +1693,10 @@ run_pictwps_filter(char       **argv,   /* I - Command-line arguments */
   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);
@@ -1681,5 +1749,5 @@ sigterm_handler(int sig)          /* I - Signal */
 
 
 /*
- * 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 $".
  */