]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/ipp.c
Remove old files.
[thirdparty/cups.git] / backend / ipp.c
index 693a85bc8dc761c677c59e1de46b102b1c485867..1feb6fdb1d70fc48e0dcd625c4764ac19011e132 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$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
@@ -132,7 +132,8 @@ main(int  argc,                             /* I - Number of command-line args */
   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 */
@@ -209,12 +210,16 @@ main(int  argc,                           /* I - Number of command-line args */
   * 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...
@@ -231,6 +236,9 @@ main(int  argc,                             /* I - Number of command-line args */
     return (CUPS_BACKEND_STOP);
   }
 
+  if (!port)
+    port = IPP_PORT;                   /* Default to port 631 */
+
   if (!strcmp(method, "https"))
     cupsSetEncryption(HTTP_ENCRYPT_ALWAYS);
   else
@@ -399,13 +407,13 @@ main(int  argc,                           /* I - Number of command-line args */
 
     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);
@@ -414,7 +422,7 @@ main(int  argc,                             /* I - Number of command-line args */
     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);
@@ -426,10 +434,9 @@ main(int  argc,                            /* I - Number of command-line args */
     * 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
@@ -438,10 +445,9 @@ main(int  argc,                            /* I - Number of command-line args */
     * 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)
@@ -515,8 +521,8 @@ main(int  argc,                             /* I - Number of command-line args */
                      _("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...
@@ -573,8 +579,8 @@ main(int  argc,                             /* I - Number of command-line args */
 
   if (job_cancelled)
   {
-    if (argc == 6 || strcmp(filename, argv[6]))
-      unlink(filename);
+    if (tmpfilename[0])
+      unlink(tmpfilename);
 
     return (CUPS_BACKEND_FAILED);
   }
@@ -759,8 +765,8 @@ main(int  argc,                             /* I - Number of command-line args */
       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...
@@ -859,13 +865,13 @@ main(int  argc,                           /* I - Number of command-line args */
     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;
       }
 
@@ -876,33 +882,41 @@ main(int  argc,                           /* I - Number of command-line args */
        * 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)
@@ -1053,7 +1067,7 @@ main(int  argc,                           /* I - Number of command-line args */
 
     _cupsLangPuts(stderr, _("INFO: Waiting for job to complete...\n"));
 
-    for (; !job_cancelled;)
+    for (delay = 1; !job_cancelled;)
     {
      /*
       * Build an IPP_GET_JOB_ATTRIBUTES request...
@@ -1144,10 +1158,14 @@ main(int  argc,                         /* I - Number of command-line args */
       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;
     }
   }
 
@@ -1392,7 +1410,7 @@ password_cb(const char *prompt)           /* I - Prompt (not used) */
 {
   (void)prompt;
 
-  if (password && password_tries < 3)
+  if (password && *password && password_tries < 3)
   {
     password_tries ++;
 
@@ -1475,7 +1493,7 @@ report_printer_state(ipp_t *ipp,  /* I - IPP response */
     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))
@@ -1671,7 +1689,6 @@ run_pictwps_filter(char       **argv,     /* I - Command-line arguments */
 
     _cupsLangPrintf(stderr, _("ERROR: Unable to fork pictwpstops: %s\n"),
                    strerror(errno));
-    unlink(filename);
     if (ppdfile)
       unlink(ppdfile);
     return (-1);
@@ -1686,7 +1703,6 @@ run_pictwps_filter(char       **argv,     /* I - Command-line arguments */
     _cupsLangPrintf(stderr, _("ERROR: Unable to wait for pictwpstops: %s\n"),
                    strerror(errno));
     close(fd);
-    unlink(filename);
     if (ppdfile)
       unlink(ppdfile);
     return (-1);
@@ -1706,7 +1722,6 @@ run_pictwps_filter(char       **argv,     /* I - Command-line arguments */
       _cupsLangPrintf(stderr, _("ERROR: pictwpstops exited on signal %d!\n"),
                      status);
 
-    unlink(filename);
     return (status);
   }
 
@@ -1756,5 +1771,5 @@ sigterm_handler(int sig)          /* I - Signal */
 
 
 /*
- * 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 $".
  */