apple / cups

Apple CUPS Sources
https://www.cups.org
Apache License 2.0
1.95k stars 464 forks source link

Move Filter and other PPD-derived values from printers.conf to a common PPD cache file #3656

Closed michaelrsweet closed 13 years ago

michaelrsweet commented 14 years ago

Version: 1.5-current CUPS.org User: mike

Now that we have a PPD cache, move all of the PPD bits from printers.conf into that cache.

michaelrsweet commented 13 years ago

CUPS.org User: mike

Fixed in Subversion repository.

michaelrsweet commented 13 years ago

"str3656.patch":

Index: backend/ipp.c

--- backend/ipp.c (revision 9599) +++ backend/ipp.c (working copy) @@ -115,7 +115,7 @@ const char user, const char title, int num_options, cups_option_t options, const char compression, int copies,

@@ -1671,8 +1671,7 @@ response; / IPP response _/ ipp_attributet *attr; / Attribute in response / int delay, / Current delay */

+typedef struct _ppd_cache_s _ppd_cache_t;

Index: cups/mark.c

--- cups/mark.c (revision 9599) +++ cups/mark.c (working copy) @@ -3,7 +3,7 @@ *

Index: cups/Makefile

--- cups/Makefile (revision 9599) +++ cups/Makefile (working copy) @@ -56,9 +56,8 @@ options.o \ page.o \ ppd.o \

michaelrsweet commented 13 years ago

Property changes on: cups/ppd-cache.c


Added: svn:keywords

Index: cups/testpwg.c

--- cups/testpwg.c (revision 9599) +++ cups/testpwg.c (working copy) @@ -3,7 +3,7 @@ *

-static int test_pwg(_pwg_t pwg, ppd_file_t ppd); -static int test_pagesize(_pwg_t pwg, ppd_file_t ppd, +static int test_pagesize(_ppd_cache_t pc, ppd_file_t ppd, const char ppdsize); +static int test_ppd_cache(_ppd_cache_t pc, ppd_file_t *ppd);

/ @@ -48,7 +48,7 @@ int status; /* Status of tests (0 = success, 1 = fail) _/ const char ppdfile; / PPD filename / ppd_filet *ppd; / PPD file */

@@ -78,8 +78,8 @@ else puts("PASS");

@@ -268,9 +269,9 @@ */

static int /* O - 1 on failure, 0 on success _/ -test_pagesize(_pwgt *pwg, / I - PWG mapping data */

@@ -71,12 +78,13 @@ _ppd_cups_uiconst_t constraints; / Constraints */ } _ppd_cups_uiconsts_t;

-typedef enum _pwg_output_modee /** PWG output-mode indices */ +typedef enum _pwg_print_color_modee /*** PWG print-color-mode indices ****/ {

-typedef struct _pwgs /** PWG-PPD conversion data */ +struct _ppd_caches /*** PPD cache and PWG conversion data **_/ { int numbins; / Number of output bins _/ _pwg_map_t bins; / Output bins / @@ -105,21 +113,46 @@ _pwg_mapt *sources; / Media sources _/ int numtypes; / Number of media types _/ _pwg_mapt *types; / Media types */

+extern _ppd_cache_t _ppdCacheCreateWithFile(const char filename,

- */

-/*

- */

-#include "cups-private.h"

-#include

-/*

- */

-#define _PWG_EQUIVALENT(x, y) (abs((x)-(y)) < 2)

-/*

- */

-static void pwg_ppdize_name(const char ipp, char name, size_t namesize);

-static void pwg_unppdize_name(const char ppd, char name, size_t namesize);

-/*

- */

-_pwgt * /* O - PWG mapping data / -_pwgCreateWithPPD(ppd_filet *ppd) / I - PPD file */ -{

- _pwg_size_t _newsize; / New size to add, if any */

- DEBUG_printf(("_pwgCreateWithPPD(ppd=%p)", ppd));

- */

- return (NULL);

- */

- }

- */

- }

- }

- */

- continue;

- */

- */

- }

- */

- */

- new_known_pwg = 0;

- }

- */

- new_left == 0 && new_right == 0;

- strncmp(oldsize->map.pwg, "om", 3);

- _PWG_EQUIVALENT(old_size->length, new_length);

- */

- }

- */

- }

- */

- }

- */

- pwg->custom_max_length = _PWG_FROMPTS(ppd->custom_max[1]);

- pwg->custom_min_length = _PWG_FROMPTS(ppd->custom_min[1]);

- }

- */

- input_slot = ppdFindOption(ppd, "HPPaperSource");

- pwg->source_option = _cupsStrAlloc(input_slot->keyword);

- }

- pwg->num_sources = input_slot->num_choices;

- */

- }

- }

- */

- }

- pwg->num_types = media_type->num_choices;

- */

- }

- }

- */

- }

- pwg->num_bins = output_bin->num_choices;

- pwg_unppdize_name(choice->choice, pwg_keyword, sizeof(pwg_keyword));

- }

- */

- _papercoating; / com.apple.print.preset.media-front-coating value */

- _PPD_PARSE_ALL);

- */

- pwg_print_quality = _PWG_PRINT_QUALITY_NORMAL;

- */

- num_options, options);

- continue;

- */

- num_options, options);

- continue;

- */

- color_model_val = cupsGetOption("ColorModel", num_options, options);

- pwg_output_mode = _PWG_OUTPUT_MODE_COLOR;

- */

- }

- }

- */

- _graychoice = NULL; / Choice to select grayscale */

- }

- */

- moption; / Monochrome option */

- */

- options = calloc(sizeof(cups_option_t), num_options);

- }

- continue;

- */

- }

- */

- duplex = ppdFindOption(ppd, "KD03Duplex");

- pwg->sides_option = _cupsStrAlloc(duplex->keyword);

- }

- return (pwg);

- */

- create_error:

- _pwgDestroy(pwg);

- */

-const char * /* O - output-bin or NULL _/ -_pwgGetBin(_pwgt *pwg, / I - PWG mapping data */

- int i; /* Looping var */

- */

- return (NULL);

- */

- return (pwg->bins[i].pwg);

- */

-const char * /* O - PPD InputSlot or NULL _/ -_pwgGetInputSlot(_pwgt *pwg, / I - PWG mapping data */

- */

- return (NULL);

- */

- int margins_set; /* Were the margins set? */

- */

- */

- }

- int i; /* Looping var */

- }

- */

-const char * /* O - PPD MediaType or NULL _/ -_pwgGetMediaType(_pwgt *pwg, / I - PWG mapping data */

- */

- return (NULL);

- */

- _mediatype; / media-type attribute */

- "media-type", IPP_TAG_NAME);

- }

- int i; /* Looping var */

- }

- */

-const char * /* O - PPD OutputBin or NULL _/ -_pwgGetOutputBin(_pwgt *pwg, / I - PWG mapping data */

- int i; /* Looping var */

- */

- return (NULL);

- */

- return (pwg->bins[i].ppd);

- */

-const char * /* O - PPD PageSize or NULL _/ -_pwgGetPageSize(_pwgt *pwg, / I - PWG mapping data */

- const char _ppdname; / PPD media name */

- pwg, job, keyword, exact));

- */

- return (NULL);

- *exact = 0;

- ppd_name = keyword;

- */

- ipp_attribute_t attr; / Job attribute */

- attr = ippFindAttribute(job, "media", IPP_TAG_ZERO);

-#ifdef DEBUG

- }

- DEBUG_printf(("1_pwgGetPageSize: ppd_name=\"%s\"", ppd_name));

- */

- (int)(size - pwg->sizes), size->map.pwg, size->map.ppd));

- *exact = 1;

- DEBUG_printf(("1_pwgGetPageSize: Returning \"%s\"", ppd_name));

- }

- */

- */

- _pwg_media_t media; / Media definition */

- return (NULL);

- }

- */

- dclosest = 999999999;

- */

- dlength = size->length - jobsize.length;

- continue;

- */

- dbottom = size->bottom - jobsize.bottom;

- dmin = dleft + dright + dbottom + dtop;

- }

- }

- *exact = 1;

- DEBUG_printf(("1_pwgGetPageSize: Returning \"%s\"", size->map.ppd));

- }

- closest->map.ppd));

- }

- */

michaelrsweet commented 13 years ago

- */

- (int)_PWG_TOPTS(jobsize.width), (int)_PWG_TOPTS(jobsize.length));

- dbottom = pwg->custom_size.bottom - jobsize.bottom;

- *exact = 1;

- pwg->custom_ppd_size));

- }

- */

- DEBUG_puts("1_pwgGetPageSize: Returning NULL");

- */

-_pwg_sizet * /* O - PWG size or NULL / -_pwgGetSize(_pwgt *pwg, / I - PWG mapping data */

- _pwg_size_t size; / Current size */

- */

- return (NULL);

- */

- struct lconv loc; / Locale data */

- return (NULL);

- return (NULL);

- }

- pwg->custom_size.length = (int)l;

- }

- */

- return (size);

- */

-const char * /* O - PWG media-source keyword _/ -_pwgGetSource(_pwgt *pwg, / I - PWG mapping data */

- _pwg_map_t source; / Current source */

- */

- return (NULL);

- return (source->pwg);

- */

-const char * /* O - PWG media-type keyword _/ -_pwgGetType(_pwgt *pwg, / I - PWG mapping data */

- _pwg_map_t type; / Current type */

- */

- return (NULL);

- return (type->pwg);

- */

-const char * /* O - InputSlot name */ -_pwgInputSlotForSource(

- */

- return (NULL);

- pwg_ppdize_name(media_source, name, namesize);

- */

-const char * /* O - MediaType name */ -_pwgMediaTypeForType(

- */

- return (NULL);

- pwg_ppdize_name(media_type, name, namesize);

- */

-const char * /* O - PageSize name */ -_pwgPageSizeForMedia(

- dimptr; / Pointer to dimensions in PWG name */

- */

- return (NULL);

- */

- */

- */

- */

- }

- */

-static void -pwg_ppdize_name(const char ipp, / I - IPP keyword */

- end; / End of name buffer */

- _name = toupper(_ipp++);

- }

- */

-static void -pwg_unppdize_name(const char ppd, / I - PPD keyword */

- end; / End of name buffer */

- *ptr++ = '-';

- }

- */

-/*

- */

-#include "cups-private.h"

-#include

-/*

- */

-_pwgt * /* O - PWG mapping data / -pwgCreateWithFile(const char *filename)/ I - File to read */ -{

- _pwg_print_quality_t print_quality; /* Print quality for preset */

- DEBUG_printf(("_pwgCreateWithFile(filename=\"%s\")", filename));

- */

- }

- */

- }

- */

- }

- */

- num_types = 0;

- line, value, linenum));

- }

- }

- }

- }

- map->ppd = _cupsStrAlloc(ppd_keyword);

- }

- }

- }

- size = pwg->sizes + pwg->num_sizes;

- }

- size->map.ppd = _cupsStrAlloc(ppd_keyword);

- }

- }

- pwg->custom_max_keyword = _cupsStrAlloc(pwg_keyword);

- }

- }

- }

- }

- map->ppd = _cupsStrAlloc(ppd_keyword);

- }

- }

- }

- }

- map->ppd = _cupsStrAlloc(ppd_keyword);

- */

- print_quality = (_pwg_print_quality_t)strtol(valueptr, &valueptr, 10);

- }

- }

- }

- }

- }

- cupsFileClose(fp);

- return (pwg);

- */

- create_error:

- _pwgDestroy(pwg);

- */

-void -_pwgDestroy(_pwg_t pwg) / I - PWG mapping data */ -{

- _pwg_size_t size; / Current size */

- */

- return;

- */

- }

- }

- }

- }

- _cupsStrFree(pwg->source_option);

- }

- }

- }

- }

- _cupsStrFree(pwg->custom_max_keyword);

- _cupsStrFree(pwg->custom_min_keyword);

- */

-int /* O - 1 on success, 0 on failure _/ -_pwgWriteFile(_pwgt *pwg, / I - PWG mapping data */

- cups_option_t option; / Current option */

- */

- }

- */

- }

- */

- cupsFilePuts(fp, "#CUPS-PWGPPD\n");

- */

- }

- */

- pwg->custom_size.right, pwg->custom_size.top);

- */

- cupsFilePrintf(fp, "SourceOption %s\n", pwg->source_option);

- }

- */

- }

- */

- }

- */

- cupsFilePrintf(fp, "SidesOption %s\n", pwg->sides_option);

- cupsFilePrintf(fp, "Sides1Sided %s\n", pwg->sides_1sided);

- cupsFilePrintf(fp, "Sides2SidedLong %s\n", pwg->sides_2sided_long);

- cupsFilePrintf(fp, "Sides2SidedShort %s\n", pwg->sides_2sided_short);

- */

- unlink(cache_name);

 cupsdSetPrinterReasons(printer, "none");

ifdef APPLE

@@ -7014,13 +7010,10 @@ printer->name); unlink(filename);

- unlink(filename);

snprintf(filename, sizeof(filename), "%s/%s.png", CacheDir, printer->name); unlink(filename);

- delete_string_array(&(p->pre_filters));

cupsdFreeStrings(&(p->users)); cupsdFreeQuotas(p);

@@ -850,7 +843,6 @@ cupsdClearString(&p->alert_description);

ifdef HAVE_DNSSD

@@ -1177,44 +1169,6 @@ cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d of printers.conf.", linenum); }

- p->filters = cupsArrayNew(NULL, NULL);

- p->pre_filters = cupsArrayNew(NULL, NULL);

-#ifdef HAVE_DNSSD

- cupsFilePutConf(fp, "Filter", ptr);

- cupsFilePutConf(fp, "PreFilter", ptr);

 if (printer->accepting)
   cupsFilePuts(fp, "Accepting Yes\n");
 else

@@ -2395,18 +2334,55 @@ cupsdSetPrinterReasons(p, "-cups-missing-filter-warning," "cups-insecure-filter-warning");

- */

-static void -add_string_array(cups_array_t a, / I - Array /

- *a = cupsArrayNew(NULL, NULL);

@@ -3909,26 +3875,6 @@

/*

- */

-static void -delete_string_array(cups_array_t a) / I - Array / -{

- char ptr; / Current string */

- _cupsStrFree(ptr);

- pwg_info.st_mtime = 0;

snprintf(ppd_name, sizeof(ppd_name), "%s/ppd/%s.ppd", ServerRoot, p->name); if (stat(ppd_name, &ppd_info)) ppd_info.st_mtime = 1; @@ -4021,29 +3961,22 @@ ippDelete(p->ppd_attrs); p->ppd_attrs = ippNew();

- p->pwg = _pwgCreateWithFile(pwg_name);

- */

 cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", cache_name);

- p->pwg = NULL;

cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", ppd_name);

- delete_string_array(&(p->pre_filters));

p->type &= ~CUPS_PRINTER_OPTIONS; p->type |= CUPS_PRINTER_BW;

@@ -4072,7 +3999,7 @@ * Add make/model and other various attributes... */

@@ -4175,7 +4102,7 @@ * Add media options from the PPD file... */

@@ -4214,12 +4141,12 @@ media_type = ppdFindMarkedChoice(ppd, "MediaType"); col = new_media_col(pwgsize, input_slot ?

@@ -4258,12 +4185,12 @@ * media-source-supported */

- add_string_array(&(p->filters), "application/vnd.cups-raw 0 -");

- */

- }

- */

- */

- add_string_array(&(p->filters), ppd_attr->value);

- */

- add_string_array(&(p->filters), ppd->filters[i]);

- }

- */

- */

- "application/vnd.cups-postscript 0 -");

- */

- */

@@ -4825,12 +4677,11 @@ end; / End of name / int count; / Number of commands */

-#ifdef HAVE_DNSSD

@@ -5099,19 +4946,6 @@ cupsdLogMessage(CUPSD_LOG_INFO, "Hint: Run \"cupstestppd %s\" and fix any errors.",

ppd_name);

- */

- add_string_array(&(p->filters), "application/vnd.cups-raw 0 -");

- */

- p->ppd_attrs->state = IPP_IDLE;

- }

- cupsFileClose(cache);

Index: scheduler/job.c

--- scheduler/job.c (revision 9599) +++ scheduler/job.c (working copy) @@ -3034,12 +3034,13 @@ char optptr, / Pointer to options / *valptr; / Pointer in value string _/ ipp_attributet *attr; / Current attribute */

@@ -3155,7 +3159,7 @@ IPP_TAG_ZERO)) != NULL && (attr->value_tag == IPP_TAG_KEYWORD || attr->value_tag == IPP_TAG_NAME) &&

michaelrsweet commented 13 years ago

@@ -2396,7 +2396,7 @@ keyvalue[i++][1] = for_lpd ? "100" : "0";

keyvalue[i ][0] = "product";