]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: In universal() supply texttopdf parameters in parameters
authorTill Kamppeter <till.kamppeter@gmail.com>
Thu, 24 Mar 2022 16:16:15 +0000 (17:16 +0100)
committerTill Kamppeter <till.kamppeter@gmail.com>
Thu, 24 Mar 2022 16:16:15 +0000 (17:16 +0100)
When the universal() filter function calls the texttopdf() filter
function it grabs the parameters for texttopdf() from the environment
variables which CUPS usually sets. There is no way to supply these
parameters without environment variables (for non-CUPS applications).

With this commit the parameters data structure of universal() is
extended to also contain the parameter data structure of texttopdf()
so that one can supply these parameters on the universal() filter
function call. The environment variables are no checked by the CUPS
wrapper which is used to call universal() as a CUPS filter.

backend/implicitclass.c
cupsfilters/filter.h
cupsfilters/universal.c
filter/universal.c

index 24dd5a021b3f0bd169a60fafb4e8e2c92ef9a861..606f6c947b3b7c438ba874ee0fb75b0a787279cc 100644 (file)
@@ -240,7 +240,7 @@ main(int  argc,                             /* I - Number of command-line args */
       cups_option_t *options = NULL;
       int fd, nullfd;
       filter_data_t filter_data;
-      filter_input_output_format_t input_output_format;
+      universal_parameter_t universal_parameters;
       filter_external_cups_t ipp_backend_params;
       filter_filter_in_chain_t universal_in_chain,
                               ipp_in_chain;
@@ -356,8 +356,10 @@ main(int  argc,                            /* I - Number of command-line args */
       filterOpenBackAndSidePipes(&filter_data);
 
       /* Parameters (input/output MIME types) for universal() call */
-      input_output_format.input_format = "application/vnd.cups-pdf";
-      input_output_format.output_format = document_format;
+      universal_parameters.input_format = "application/vnd.cups-pdf";
+      universal_parameters.output_format = document_format;
+      memset(&(universal_parameters.texttopdf_params), 0,
+            sizeof(texttopdf_parameter_t));
 
       /* Parameters for filterExternalCUPS() call for IPP backend */
       ipp_backend_params.filter = "ipp";
@@ -369,7 +371,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
       /* Filter chain entry for the universal() filter function call */
       universal_in_chain.function = universal;
-      universal_in_chain.parameters = &input_output_format;
+      universal_in_chain.parameters = &universal_parameters;
       universal_in_chain.name = "Filters";
 
       /* Filter chain entry for the IPP CUPS backend call */
index 59cc6ea0ecb98616704b5772ac5a555e909ff82f..a0bfd265f6529a7e7443bdaf0d54f6706d411d7b 100644 (file)
@@ -72,8 +72,8 @@ typedef struct filter_data_s {
 typedef int (*filter_function_t)(int inputfd, int outputfd, int inputseekable,
                                 filter_data_t *data, void *parameters);
 
-typedef enum filter_out_format_e { /* Possible output formats for rastertopdf()
-                                     filter function */
+typedef enum filter_out_format_e { /* Possible output formats for filter
+                                     functions */
   OUTPUT_FORMAT_PDF,        /* PDF */
   OUTPUT_FORMAT_PDF_IMAGE,   /* Raster-only PDF */
   OUTPUT_FORMAT_PCLM,       /* PCLM */
@@ -114,17 +114,21 @@ typedef struct filter_filter_in_chain_s { /* filter entry for CUPS array to
 typedef struct texttopdf_parameter_s {  /* parameters container of environemnt
                                           variables needed by texttopdf
                                           filter function */
-  const char *data_dir;
-  const char *char_set;
-  const char *content_type;
-  const char *classification;
+  char *data_dir;
+  char *char_set;
+  char *content_type;
+  char *classification;
 } texttopdf_parameter_t;
 
-typedef struct filter_input_output_format_s { /* Contains input and output type
-                                            to be supplied to the universal function */
+typedef struct universal_parameter_s { /* Contains input and output
+                                         type to be supplied to the
+                                         universal function, and also
+                                         parameters for texttopdf() */
   char *input_format;                 
   char *output_format;
-} filter_input_output_format_t;
+  texttopdf_parameter_t texttopdf_params;
+} universal_parameter_t;
+
 
 /*
  * Prototypes...
@@ -379,9 +383,10 @@ extern int universal(int inputfd,
                     filter_data_t *data,
                     void *parameters);
 
-/* Parameters: filter_input_output_format_t
-   Contains : Input_type : CONTENT_TYPE environment variable
-              Output type : FINAL_CONTENT TYPE environment variable */
+/* Parameters: universal_parameter_t
+   Contains : Input_type: CONTENT_TYPE environment variable of CUPS
+              Output type: FINAL_CONTENT TYPE environment variable of CUPS
+              texttopdf_params: parameters for texttopdf */
 
 
 extern void filterSetCommonOptions(ppd_file_t *ppd,
index 90061179329d10df19b40a4652a3a2d344feda59..1504b0419bdfd99d2e669ff84bb8a96a6aa88f8b 100644 (file)
@@ -1,5 +1,4 @@
 #include "filter.h"
-#include <config.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -31,16 +30,28 @@ universal(int inputfd,         /* I - File descriptor input stream */
   char output_type[256];
   filter_out_format_t *outformat;
   filter_filter_in_chain_t *filter, *next;
-  filter_input_output_format_t input_output_format;
+  universal_parameter_t universal_parameters;
   ppd_file_t *ppd;
   ppd_cache_t *cache;
   filter_logfunc_t log = data->logfunc;
   void *ld = data->logdata;
   int ret = 0;
 
-  input_output_format = *(filter_input_output_format_t *)parameters;
-  input = input_output_format.input_format;
-  final_output = input_output_format.output_format;
+  universal_parameters = *(universal_parameter_t *)parameters;
+  input = universal_parameters.input_format;
+  if (input == NULL)
+  {
+    if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                "universal: No input data format supplied.");
+    return (1);
+  }
+  final_output = universal_parameters.output_format;
+  if (final_output == NULL)
+  {
+    if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                "universal: No output data format supplied.");
+    return (1);
+  }
   strncpy(output, final_output, sizeof(output) - 1);
 
   /* If we have a PPD, load it and its cache, so that we can access the
@@ -286,27 +297,7 @@ universal(int inputfd,         /* I - File descriptor input stream */
       filter = malloc(sizeof(filter_filter_in_chain_t));
       texttopdf_parameter_t* parameters =
        (texttopdf_parameter_t *) malloc(sizeof(texttopdf_parameter_t));
-      char *p;
-      if ((p = getenv("CUPS_DATADIR")) != NULL)
-       parameters->data_dir = p;
-      else
-       parameters->data_dir = CUPS_DATADIR;
-
-      if ((p = getenv("CHARSET")) != NULL)
-       parameters->char_set = p;
-      else
-       parameters->char_set = NULL;
-
-      if ((p = getenv("CONTENT_TYPE")) != NULL)
-       parameters->content_type = p;
-      else
-       parameters->content_type = NULL;
-
-      if ((p = getenv("CLASSIFICATION")) != NULL)
-       parameters->classification = p;
-      else
-       parameters->classification = NULL;
-
+      *parameters = universal_parameters.texttopdf_params;
       filter->function = texttopdf;
       filter->parameters = parameters;
       filter->name = "texttopdf";
index 9c9e66819a37dc772d0cffeea7212f47ac0c98e6..2ca02c44f90ebfae14171ff96aab041f8e3079ef 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 #include <cupsfilters/filter.h>
+#include <config.h>
 #include <signal.h>
 
 
@@ -29,7 +30,8 @@ main(int  argc,                               /* I - Number of command-line args */
      char *argv[])                     /* I - Command-line arguments */
 {
   int           ret;
-  filter_input_output_format_t input_output_format;
+  char          *p;
+  universal_parameter_t universal_parameters;
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction action;             /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
@@ -50,13 +52,46 @@ main(int  argc,                             /* I - Number of command-line args */
   signal(SIGTERM, cancel_job);
 #endif /* HAVE_SIGSET */
 
-  input_output_format.input_format = getenv("CONTENT_TYPE");
-  input_output_format.output_format = getenv("FINAL_CONTENT_TYPE");
-  ret = filterCUPSWrapper(argc, argv, universal, &input_output_format , &JobCanceled);
+  if ((p = getenv("CONTENT_TYPE")) != NULL)
+    universal_parameters.input_format = strdup(p);
+  else
+    universal_parameters.input_format = NULL;
+
+  if ((p = getenv("FINAL_CONTENT_TYPE")) != NULL)
+    universal_parameters.output_format = strdup(p);
+  else
+    universal_parameters.output_format = NULL;
+
+  if ((p = getenv("CUPS_DATADIR")) != NULL)
+    universal_parameters.texttopdf_params.data_dir = strdup(p);
+  else
+    universal_parameters.texttopdf_params.data_dir = strdup(CUPS_DATADIR);
+
+  if ((p = getenv("CHARSET")) != NULL)
+    universal_parameters.texttopdf_params.char_set = strdup(p);
+  else
+    universal_parameters.texttopdf_params.char_set = NULL;
+
+  universal_parameters.texttopdf_params.content_type =
+    universal_parameters.input_format;
+
+  if ((p = getenv("CLASSIFICATION")) != NULL)
+    universal_parameters.texttopdf_params.classification = strdup(p);
+  else
+    universal_parameters.texttopdf_params.classification = NULL;
+
+  ret = filterCUPSWrapper(argc, argv, universal, &universal_parameters,
+                         &JobCanceled);
 
   if (ret)
     fprintf(stderr, "ERROR: universal filter failed.\n");
 
+  free(universal_parameters.input_format);
+  free(universal_parameters.output_format);
+  free(universal_parameters.texttopdf_params.data_dir);
+  free(universal_parameters.texttopdf_params.char_set);
+  free(universal_parameters.texttopdf_params.classification);
+
   return (ret);
 }