]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/cupsfilter.c
Merge changes from CUPS 1.5svn-r8849.
[thirdparty/cups.git] / scheduler / cupsfilter.c
index d3c30210a8d261d37f0761cc789278811adf1e04..6f73b62d5d7841fab74a2f9a15d95fa1fcb23221 100644 (file)
@@ -86,7 +86,8 @@ static int            compare_pids(mime_filter_t *a, mime_filter_t *b);
 static char            *escape_options(int num_options, cups_option_t *options);
 static int             exec_filter(const char *filter, char **argv,
                                    char **envp, int infd, int outfd);
-static int             exec_filters(cups_array_t *filters, const char *infile,
+static int             exec_filters(mime_type_t *srctype,
+                                    cups_array_t *filters, const char *infile,
                                     const char *outfile, const char *ppdfile,
                                     const char *printer, const char *user,
                                     const char *title, int num_options,
@@ -133,7 +134,8 @@ main(int  argc,                             /* I - Number of command-line args */
   const char   *ppdfile;               /* PPD file */
   const char   *title,                 /* Title string */
                *user;                  /* Username */
-  int          removeppd,              /* Remove PPD file */
+  int          all_filters,            /* Use all filters */
+               removeppd,              /* Remove PPD file */
                removeinfile;           /* Remove input file */
   int          status;                 /* Execution status */
 
@@ -159,6 +161,7 @@ main(int  argc,                             /* I - Number of command-line args */
   ppdfile      = NULL;
   title        = NULL;
   user         = cupsUser();
+  all_filters  = 0;
   removeppd    = 0;
   removeinfile = 0;
 
@@ -213,6 +216,10 @@ main(int  argc,                            /* I - Number of command-line args */
              removeinfile = 1;
              break;
 
+          case 'e' : /* Use every filter from the PPD file */
+             all_filters = 1;
+             break;
+
           case 'f' : /* Specify input file... */
              i ++;
              if (i < argc && !infile)
@@ -340,7 +347,7 @@ main(int  argc,                             /* I - Number of command-line args */
     else
     {
       _cupsLangPuts(stderr,
-                    _("cupsfilter: Only one filename can be specified!\n"));
+                    _("cupsfilter: Only one filename can be specified\n"));
       usage(command, NULL);
     }
 
@@ -375,13 +382,21 @@ main(int  argc,                           /* I - Number of command-line args */
   {
     _cupsLangPrintf(stderr,
                     _("%s: Unable to read MIME database from \"%s\" or "
-                     "\"%s\"!\n"),
+                     "\"%s\"\n"),
                    command, mimedir, ServerRoot);
     return (1);
   }
 
-  printer_type = add_printer_filters(command, mime, printer, ppdfile,
-                                     &prefilter_type);
+  if (all_filters)
+  {
+    printer_type = add_printer_filters(command, mime, printer, ppdfile,
+                                      &prefilter_type);
+  }
+  else
+  {
+    printer_type   = mimeType(mime, "application", "vnd.cups-postscript");
+    prefilter_type = NULL;
+  }
 
  /*
   * Get the source and destination types...
@@ -393,7 +408,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\n"),
                      command, super, type);
       return (1);
     }
@@ -401,7 +416,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\"\n"),
                    command, infile);
     return (1);
   }
@@ -412,7 +427,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\n"),
                    command, super, type);
     return (1);
   }
@@ -429,11 +444,13 @@ main(int  argc,                           /* I - Number of command-line args */
 
     filters = cupsArrayNew(NULL, NULL);
     cupsArrayAdd(filters, &GZIPFilter);
+    GZIPFilter.src = src;
+    GZIPFilter.dst = dst;
   }
   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\n"),
                    command, src->super, src->type, dst->super, dst->type);
     return (1);
   }
@@ -456,7 +473,8 @@ main(int  argc,                             /* I - Number of command-line args */
         filter;
         filter = (mime_filter_t *)cupsArrayNext(filters))
     {
-      if ((prefilter = mimeFilterLookup(mime, filter->src, prefilter_type)))
+      if ((prefilter = mimeFilterLookup(mime, filter->src,
+                                        prefilter_type)) != NULL)
        cupsArrayAdd(prefilters, prefilter);
 
       cupsArrayAdd(prefilters, filter);
@@ -470,7 +488,7 @@ main(int  argc,                             /* I - Number of command-line args */
   * Do it!
   */
 
-  status = exec_filters(filters, infile, outfile, ppdfile, printer, user,
+  status = exec_filters(src, filters, infile, outfile, ppdfile, printer, user,
                         title, num_options, options);
 
  /*
@@ -610,6 +628,8 @@ add_printer_filters(
       if (ppdattr->value)
        add_printer_filter(command, mime, *prefilter_type, ppdattr->value);
   }
+  else
+    *prefilter_type = NULL;
 
   return (printer_type);
 }
@@ -701,7 +721,8 @@ exec_filter(const char *filter,             /* I - Filter to execute */
            int        infd,            /* I - Stdin file descriptor */
            int        outfd)           /* I - Stdout file descriptor */
 {
-  int          pid;                    /* Process ID */
+  int          pid,                    /* Process ID */
+               fd;                     /* Temporary file descriptor */
 #if defined(__APPLE__)
   char         processPath[1024],      /* CFProcessPath environment variable */
                linkpath[1024];         /* Link path for symlinks... */
@@ -745,28 +766,40 @@ exec_filter(const char *filter,           /* I - Filter to execute */
 
     if (infd != 0)
     {
-      close(0);
+      if (infd < 0)
+        infd = open("/dev/null", O_RDONLY);
+
       if (infd > 0)
-        dup(infd);
-      else
-        open("/dev/null", O_RDONLY);
+      {
+        dup2(infd, 0);
+       close(infd);
+      }
     }
 
     if (outfd != 1)
     {
-      close(1);
-      if (outfd > 0)
-       dup(outfd);
-      else
-        open("/dev/null", O_WRONLY);
+      if (outfd < 0)
+        outfd = open("/dev/null", O_WRONLY);
+
+      if (outfd > 1)
+      {
+       dup2(outfd, 1);
+       close(outfd);
+      }
     }
 
-    close(3);
-    open("/dev/null", O_RDWR);
+    if ((fd = open("/dev/null", O_RDWR)) > 3)
+    {
+      dup2(fd, 3);
+      close(fd);
+    }
     fcntl(3, F_SETFL, O_NDELAY);
 
-    close(4);
-    open("/dev/null", O_RDWR);
+    if ((fd = open("/dev/null", O_RDWR)) > 4)
+    {
+      dup2(fd, 4);
+      close(fd);
+    }
     fcntl(4, F_SETFL, O_NDELAY);
 
    /*
@@ -789,7 +822,8 @@ exec_filter(const char *filter,             /* I - Filter to execute */
  */
 
 static int                             /* O - 0 on success, 1 on error */
-exec_filters(cups_array_t  *filters,   /* I - Array of filters to run */
+exec_filters(mime_type_t   *srctype,   /* I - Source type */
+             cups_array_t  *filters,   /* I - Array of filters to run */
              const char    *infile,    /* I - File to filter */
             const char    *outfile,    /* I - File to create */
             const char    *ppdfile,    /* I - PPD file, if any */
@@ -833,9 +867,8 @@ exec_filters(cups_array_t  *filters,        /* I - Array of filters to run */
 
   optstr = escape_options(num_options, options);
 
-  filter = cupsArrayFirst(filters);
   snprintf(content_type, sizeof(content_type), "CONTENT_TYPE=%s/%s",
-           filter->src->super, filter->src->type);
+           srctype->super, srctype->type);
   snprintf(cups_datadir, sizeof(cups_datadir), "CUPS_DATADIR=%s", DataDir);
   snprintf(cups_fontpath, sizeof(cups_fontpath), "CUPS_FONTPATH=%s", FontPath);
   snprintf(cups_serverbin, sizeof(cups_serverbin), "CUPS_SERVERBIN=%s",
@@ -998,10 +1031,10 @@ exec_filters(cups_array_t  *filters,     /* I - Array of filters to run */
       if (status)
       {
        if (WIFEXITED(status))
-         fprintf(stderr, "ERROR: %s (PID %d) stopped with status %d!\n",
+         fprintf(stderr, "ERROR: %s (PID %d) stopped with status %d\n",
                  filter->filter, pid, WEXITSTATUS(status));
        else
-         fprintf(stderr, "ERROR: %s (PID %d) crashed on signal %d!\n",
+         fprintf(stderr, "ERROR: %s (PID %d) crashed on signal %d\n",
                  filter->filter, pid, WTERMSIG(status));
 
         retval = 1;
@@ -1052,13 +1085,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\n"), (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\n"),
                     (int)docnum);
     exit(1);
   }
@@ -1276,7 +1309,7 @@ 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'\n"), command, *opt);
 
   if (!strcmp(command, "cupsfilter"))
     _cupsLangPuts(stdout,
@@ -1285,6 +1318,7 @@ usage(const char *command,                /* I - Command name */
                    "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"
@@ -1296,6 +1330,7 @@ usage(const char *command,                /* I - Command name */
                    "\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"