]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/cupsfilter.c
Merge changes from CUPS 1.5svn-r9641
[thirdparty/cups.git] / scheduler / cupsfilter.c
index 6f73b62d5d7841fab74a2f9a15d95fa1fcb23221..94fc713fcbffac051f9919a36075b532ebcf7a23 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * "$Id: cupsfilter.c 7952 2008-09-17 00:56:20Z mike $"
  *
- *   CUPS filtering program for the Common UNIX Printing System (CUPS).
+ *   Filtering program for CUPS.
  *
- *   Copyright 2007-2009 by Apple Inc.
+ *   Copyright 2007-2011 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
  * Include necessary headers...
  */
 
-#include <cups/cups.h>
-#include <cups/i18n.h>
-#include <cups/string.h>
-#include <errno.h>
+#include <cups/cups-private.h>
 #include "mime.h"
-#include <stdlib.h>
 #include <limits.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -66,7 +62,7 @@ static char           *ServerBin = NULL;
 static char            *ServerRoot = NULL;
                                        /* CUPS_SERVERROOT environment variable */
 static char            *RIPCache = NULL;
-                                       /* RIP_CACHE environment variable */
+                                       /* RIP_MAX_CACHE environment variable */
 static char            TempFile[1024] = "";
                                        /* Temporary file */
 
@@ -212,6 +208,14 @@ main(int  argc,                            /* I - Number of command-line args */
                usage(command, opt);
              break;
 
+          case 'd' : /* Specify the real printer name */
+             i ++;
+             if (i < argc)
+               printer = argv[i];
+             else
+               usage(command, opt);
+             break;
+
          case 'D' : /* Delete input file after conversion */
              removeinfile = 1;
              break;
@@ -340,14 +344,14 @@ main(int  argc,                           /* I - Number of command-line args */
       {
        _cupsLangPuts(stderr,
                      _("convert: Use the -f option to specify a file to "
-                       "convert.\n"));
+                       "convert."));
        usage(command, NULL);
       }
     }
     else
     {
       _cupsLangPuts(stderr,
-                    _("cupsfilter: Only one filename can be specified\n"));
+                    _("cupsfilter: Only one filename can be specified."));
       usage(command, NULL);
     }
 
@@ -382,7 +386,7 @@ main(int  argc,                             /* I - Number of command-line args */
   {
     _cupsLangPrintf(stderr,
                     _("%s: Unable to read MIME database from \"%s\" or "
-                     "\"%s\"\n"),
+                     "\"%s\"."),
                    command, mimedir, ServerRoot);
     return (1);
   }
@@ -408,7 +412,7 @@ main(int  argc,                             /* I - Number of command-line args */
     if ((src = mimeType(mime, super, type)) == NULL)
     {
       _cupsLangPrintf(stderr,
-                     _("%s: Unknown source MIME type %s/%s\n"),
+                     _("%s: Unknown source MIME type %s/%s."),
                      command, super, type);
       return (1);
     }
@@ -416,7 +420,7 @@ main(int  argc,                             /* I - Number of command-line args */
   else if ((src = mimeFileType(mime, infile, infile, &compression)) == NULL)
   {
     _cupsLangPrintf(stderr,
-                    _("%s: Unable to determine MIME type of \"%s\"\n"),
+                    _("%s: Unable to determine MIME type of \"%s\"."),
                    command, infile);
     return (1);
   }
@@ -427,7 +431,7 @@ main(int  argc,                             /* I - Number of command-line args */
   else if ((dst = mimeType(mime, super, type)) == NULL)
   {
     _cupsLangPrintf(stderr,
-                    _("%s: Unknown destination MIME type %s/%s\n"),
+                    _("%s: Unknown destination MIME type %s/%s."),
                    command, super, type);
     return (1);
   }
@@ -450,7 +454,7 @@ main(int  argc,                             /* I - Number of command-line args */
   else if ((filters = mimeFilter(mime, src, dst, &cost)) == NULL)
   {
     _cupsLangPrintf(stderr,
-                    _("%s: No filter to convert from %s/%s to %s/%s\n"),
+                    _("%s: No filter to convert from %s/%s to %s/%s."),
                    command, src->super, src->type, dst->super, dst->type);
     return (1);
   }
@@ -536,7 +540,7 @@ add_printer_filter(
   if (sscanf(filter, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super, type, &cost,
              program) != 4)
   {
-    _cupsLangPrintf(stderr, _("%s: Invalid filter string \"%s\"\n"), command,
+    _cupsLangPrintf(stderr, _("%s: Invalid filter string \"%s\"."), command,
                     filter);
     return;
   }
@@ -555,7 +559,7 @@ add_printer_filter(
 
     if (access(filename, X_OK))
     {
-      _cupsLangPrintf(stderr, _("%s: Filter \"%s\" not available: %s\n"),
+      _cupsLangPrintf(stderr, _("%s: Filter \"%s\" not available: %s"),
                       command, program, strerror(errno));
       return;
     }
@@ -600,7 +604,7 @@ add_printer_filters(
     ppd_status_t  status;              /* PPD load status */
 
     status = ppdLastError(&i);
-    _cupsLangPrintf(stderr, _("%s: Unable to open PPD file: %s on line %d\n"),
+    _cupsLangPrintf(stderr, _("%s: Unable to open PPD file: %s on line %d."),
                     command, ppdErrorString(status), i);
     return (NULL);
   }
@@ -835,7 +839,7 @@ exec_filters(mime_type_t   *srctype,        /* I - Source type */
 {
   int          i;                      /* Looping var */
   const char   *argv[8],               /* Command-line arguments */
-               *envp[12],              /* Environment variables */
+               *envp[15],              /* Environment variables */
                *temp;                  /* Temporary string */
   char         *optstr,                /* Filter options */
                content_type[1024],     /* CONTENT_TYPE */
@@ -846,7 +850,10 @@ exec_filters(mime_type_t   *srctype,       /* I - Source type */
                lang[1024],             /* LANG */
                path[1024],             /* PATH */
                ppd[1024],              /* PPD */
-               rip_cache[1024],        /* RIP_CACHE */
+               printer_info[255],      /* PRINTER_INFO env variable */
+               printer_location[255],  /* PRINTER_LOCATION env variable */
+               printer_name[255],      /* PRINTER env variable */
+               rip_max_cache[1024],    /* RIP_MAX_CACHE */
                userenv[1024],          /* USER */
                program[1024];          /* Program to run */
   mime_filter_t        *filter,                /* Current filter */
@@ -859,6 +866,7 @@ exec_filters(mime_type_t   *srctype,        /* I - Source type */
   cups_array_t *pids;                  /* Executed filters array */
   mime_filter_t        key;                    /* Search key for filters */
   cups_lang_t  *language;              /* Current language */
+  cups_dest_t  *dest;                  /* Destination information */
 
 
  /*
@@ -897,9 +905,37 @@ exec_filters(mime_type_t   *srctype,       /* I - Source type */
 #else
     snprintf(ppd, sizeof(ppd), "PPD=%s/model/laserjet.ppd", DataDir);
 #endif /* __APPLE__ */
-  snprintf(rip_cache, sizeof(rip_cache), "RIP_CACHE=%s", RIPCache);
+  snprintf(rip_max_cache, sizeof(rip_max_cache), "RIP_MAX_CACHE=%s", RIPCache);
   snprintf(userenv, sizeof(userenv), "USER=%s", user);
 
+  if (printer &&
+      (dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer, NULL)) != NULL)
+  {
+    if ((temp = cupsGetOption("printer-info", dest->num_options,
+                              dest->options)) != NULL)
+      snprintf(printer_info, sizeof(printer_info), "PRINTER_INFO=%s", temp);
+    else
+      snprintf(printer_info, sizeof(printer_info), "PRINTER_INFO=%s", printer);
+
+    if ((temp = cupsGetOption("printer-location", dest->num_options,
+                              dest->options)) != NULL)
+      snprintf(printer_location, sizeof(printer_location),
+               "PRINTER_LOCATION=%s", temp);
+    else
+      strlcpy(printer_location, "PRINTER_LOCATION=Unknown",
+              sizeof(printer_location));
+  }
+  else
+  {
+    snprintf(printer_info, sizeof(printer_info), "PRINTER_INFO=%s",
+             printer ? printer : "Unknown");
+    strlcpy(printer_location, "PRINTER_LOCATION=Unknown",
+            sizeof(printer_location));
+  }
+
+  snprintf(printer_name, sizeof(printer_name), "PRINTER=%s",
+          printer ? printer : "Unknown");
+
   argv[0] = (char *)printer;
   argv[1] = "1";
   argv[2] = user;
@@ -921,9 +957,12 @@ exec_filters(mime_type_t   *srctype,       /* I - Source type */
   envp[6]  = lang;
   envp[7]  = path;
   envp[8]  = ppd;
-  envp[9]  = rip_cache;
-  envp[10] = userenv;
-  envp[11] = NULL;
+  envp[9]  = printer_info;
+  envp[10] = printer_location;
+  envp[11] = printer_name;
+  envp[12] = rip_max_cache;
+  envp[13] = userenv;
+  envp[14] = NULL;
 
   for (i = 0; argv[i]; i ++)
     fprintf(stderr, "DEBUG: argv[%d]=\"%s\"\n", i, argv[i]);
@@ -1085,13 +1124,13 @@ get_job_file(const char *job)           /* I - Job ID */
 
   if (jobid < 1 || jobid > INT_MAX)
   {
-    _cupsLangPrintf(stderr, _("cupsfilter: Invalid job ID %d\n"), (int)jobid);
+    _cupsLangPrintf(stderr, _("cupsfilter: Invalid job ID %d."), (int)jobid);
     exit(1);
   }
 
   if (docnum < 1 || docnum > INT_MAX)
   {
-    _cupsLangPrintf(stderr, _("cupsfilter: Invalid document number %d\n"),
+    _cupsLangPrintf(stderr, _("cupsfilter: Invalid document number %d."),
                     (int)docnum);
     exit(1);
   }
@@ -1103,7 +1142,7 @@ get_job_file(const char *job)             /* I - Job ID */
   if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
                                  cupsEncryption())) == NULL)
   {
-    _cupsLangPrintf(stderr, _("%s: Unable to connect to server\n"),
+    _cupsLangPrintf(stderr, _("%s: Unable to connect to server."),
                     "cupsfilter");
     exit(1);
   }
@@ -1118,7 +1157,7 @@ get_job_file(const char *job)             /* I - Job ID */
 
   if ((tempfd = cupsTempFd(TempFile, sizeof(TempFile))) == -1)
   {
-    _cupsLangPrintError(_("ERROR: Unable to create temporary file"));
+    _cupsLangPrintError("ERROR", _("Unable to create temporary file"));
     httpClose(http);
     exit(1);
   }
@@ -1133,7 +1172,7 @@ get_job_file(const char *job)             /* I - Job ID */
 
   if (cupsLastError() != IPP_OK)
   {
-    _cupsLangPrintf(stderr, _("cupsfilter: Unable to get job file - %s\n"),
+    _cupsLangPrintf(stderr, _("cupsfilter: Unable to get job file - %s"),
                     cupsLastErrorString());
     unlink(TempFile);
     exit(1);
@@ -1309,39 +1348,61 @@ usage(const char *command,              /* I - Command name */
       const char *opt)                 /* I - Incorrect option, if any */
 {
   if (opt)
-    _cupsLangPrintf(stderr, _("%s: Unknown option '%c'\n"), command, *opt);
+    _cupsLangPrintf(stderr, _("%s: Unknown option \"%c\"."), command, *opt);
 
   if (!strcmp(command, "cupsfilter"))
-    _cupsLangPuts(stdout,
-                 _("Usage: cupsfilter -m mime/type [ options ] filename\n"
-                   "\n"
-                   "Options:\n"
-                   "\n"
-                   "  -c cupsd.conf    Set cupsd.conf file to use\n"
-                   "  -e               Use every filter from the PPD file\n"
-                   "  -j job-id[,N]    Filter file N from the specified job (default is file 1)\n"
-                   "  -n copies        Set number of copies\n"
-                   "  -o name=value    Set option(s)\n"
-                   "  -p filename.ppd  Set PPD file\n"
-                   "  -t title         Set title\n"));
+  {
+    _cupsLangPuts(stdout, _("Usage: cupsfilter [ options ] filename"));
+    _cupsLangPuts(stdout, _("Options:"));
+    _cupsLangPuts(stdout, _("  -D                      Remove the input file "
+                            "when finished."));
+    _cupsLangPuts(stdout, _("  -P filename.ppd         Set PPD file."));
+    _cupsLangPuts(stdout, _("  -U username             Set username for job."));
+    _cupsLangPuts(stdout, _("  -c cupsd.conf           Set cupsd.conf file to "
+                            "use."));
+    _cupsLangPuts(stdout, _("  -d printer              Use the named "
+                            "printer."));
+    _cupsLangPuts(stdout, _("  -e                      Use every filter from "
+                            "the PPD file."));
+    _cupsLangPuts(stdout, _("  -i mime/type            Set input MIME type "
+                            "(otherwise auto-typed)."));
+    _cupsLangPuts(stdout, _("  -j job-id[,N]           Filter file N from the "
+                            "specified job (default is file 1)."));
+    _cupsLangPuts(stdout, _("  -m mime/type            Set output MIME type "
+                           "(otherwise application/pdf)."));
+    _cupsLangPuts(stdout, _("  -n copies               Set number of copies."));
+    _cupsLangPuts(stdout, _("  -o name=value           Set option(s)."));
+    _cupsLangPuts(stdout, _("  -p filename.ppd         Set PPD file."));
+    _cupsLangPuts(stdout, _("  -t title                Set title."));
+    _cupsLangPuts(stdout, _("  -u                      Remove the PPD file "
+                            "when finished."));
+  }
   else
-    _cupsLangPuts(stdout,
-                 _("Usage: convert [ options ]\n"
-                   "\n"
-                   "Options:\n"
-                   "\n"
-                   "  -e                   Use every filter from the PPD file\n"
-                   "  -f filename          Set file to be converted (otherwise stdin)\n"
-                   "  -o filename          Set file to be generated (otherwise stdout)\n"
-                   "  -i mime/type         Set input MIME type (otherwise auto-typed)\n"
-                   "  -j mime/type         Set output MIME type (otherwise application/pdf)\n"
-                   "  -P filename.ppd      Set PPD file\n"
-                   "  -a 'name=value ...'  Set option(s)\n"
-                   "  -U username          Set username for job\n"
-                   "  -J title             Set title\n"
-                   "  -c copies            Set number of copies\n"
-                   "  -u                   Remove the PPD file when finished\n"
-                   "  -D                   Remove the input file when finished\n"));
+  {
+    _cupsLangPuts(stdout, _("Usage: convert [ options ]"));
+    _cupsLangPuts(stdout, _("Options:"));
+    _cupsLangPuts(stdout, _("  -D                      Remove the input file "
+                            "when finished."));
+    _cupsLangPuts(stdout, _("  -J title                Set title."));
+    _cupsLangPuts(stdout, _("  -P filename.ppd         Set PPD file."));
+    _cupsLangPuts(stdout, _("  -U username             Set username for job."));
+    _cupsLangPuts(stdout, _("  -a 'name=value ...'     Set option(s)."));
+    _cupsLangPuts(stdout, _("  -c copies               Set number of copies."));
+    _cupsLangPuts(stdout, _("  -d printer              Use the named "
+                            "printer."));
+    _cupsLangPuts(stdout, _("  -e                      Use every filter from "
+                            "the PPD file."));
+    _cupsLangPuts(stdout, _("  -f filename             Set file to be "
+                            "converted (otherwise stdin)."));
+    _cupsLangPuts(stdout, _("  -i mime/type            Set input MIME type "
+                            "(otherwise auto-typed)."));
+    _cupsLangPuts(stdout, _("  -j mime/type            Set output MIME type "
+                           "(otherwise application/pdf)."));
+    _cupsLangPuts(stdout, _("  -o filename             Set file to be "
+                            "generated (otherwise stdout)."));
+    _cupsLangPuts(stdout, _("  -u                      Remove the PPD file "
+                            "when finished."));
+  }
 
   exit(1);
 }