]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/cups-driverd.cxx
b34f6616f4f682d13afb52f4d7b77496dd934c88
4 * PPD/driver support for the Common UNIX Printing System (CUPS).
6 * This program handles listing and installing static PPD files, PPD files
7 * created from driver information files, and dynamically generated PPD files
8 * using driver helper programs.
10 * Copyright 2007-2009 by Apple Inc.
11 * Copyright 1997-2007 by Easy Software Products.
13 * These coded instructions, statements, and computer programs are the
14 * property of Apple Inc. and are protected by Federal copyright
15 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
16 * which should have been included with this file. If this file is
17 * file is missing or damaged, see the license at "http://www.cups.org/".
21 * main() - Scan for drivers and return an IPP response.
22 * add_ppd() - Add a PPD file.
23 * cat_drv() - Generate a PPD from a driver info file.
24 * cat_ppd() - Copy a PPD file to stdout.
25 * copy_static() - Copy a static PPD file to stdout.
26 * compare_inodes() - Compare two inodes.
27 * compare_matches() - Compare PPD match scores for sorting.
28 * compare_names() - Compare PPD filenames for sorting.
29 * compare_ppds() - Compare PPD file make and model names for sorting.
30 * dump_ppds_dat() - Dump the contents of the ppds.dat file.
31 * free_array() - Free an array of strings.
32 * list_ppds() - List PPD files.
33 * load_ppds() - Load PPD files recursively.
34 * load_drv() - Load the PPDs from a driver information file.
35 * load_drivers() - Load driver-generated PPD files.
36 * load_ppds_dat() - Load the ppds.dat file.
37 * regex_device_id() - Compile a regular expression based on the 1284 device
39 * regex_string() - Construct a regular expression to compare a simple
44 * Include necessary headers...
49 #include <cups/transcode.h>
50 #include <cups/ppd-private.h>
51 #include <ppdc/ppdc.h>
59 #define PPD_SYNC 0x50504437 /* Sync word for ppds.dat (PPD7) */
60 #define PPD_MAX_LANG 32 /* Maximum languages */
61 #define PPD_MAX_PROD 32 /* Maximum products */
62 #define PPD_MAX_VERS 32 /* Maximum versions */
64 #define PPD_TYPE_POSTSCRIPT 0 /* PostScript PPD */
65 #define PPD_TYPE_PDF 1 /* PDF PPD */
66 #define PPD_TYPE_RASTER 2 /* CUPS raster PPD */
67 #define PPD_TYPE_FAX 3 /* Facsimile/MFD PPD */
68 #define PPD_TYPE_UNKNOWN 4 /* Other/hybrid PPD */
69 #define PPD_TYPE_DRV 5 /* Driver info file */
71 static const char * const ppd_types
[] = /* ppd-type values */
83 * PPD information structures...
86 typedef struct /**** PPD record ****/
88 time_t mtime
; /* Modification time */
89 off_t size
; /* Size in bytes */
90 int model_number
; /* cupsModelNumber */
91 int type
; /* ppd-type */
92 char filename
[512], /* Filename */
93 name
[512], /* PPD name */
94 languages
[PPD_MAX_LANG
][6],
95 /* LanguageVersion/cupsLanguages */
96 products
[PPD_MAX_PROD
][128],
98 psversions
[PPD_MAX_VERS
][32],
99 /* PSVersion strings */
100 make
[128], /* Manufacturer */
101 make_and_model
[128], /* NickName/ModelName */
102 device_id
[256], /* IEEE 1284 Device ID */
103 scheme
[128]; /* PPD scheme */
106 typedef struct /**** In-memory record ****/
108 int found
; /* 1 if PPD is found */
109 int matches
; /* Match count */
110 ppd_rec_t record
; /* PPDs.dat record */
118 cups_array_t
*Inodes
= NULL
, /* Inodes of directories we've visited */
119 *PPDsByName
= NULL
, /* PPD files sorted by filename and name */
120 *PPDsByMakeModel
= NULL
;/* PPD files sorted by make and model */
121 int ChangedPPD
; /* Did we change the PPD database? */
128 static ppd_info_t
*add_ppd(const char *filename
, const char *name
,
129 const char *language
, const char *make
,
130 const char *make_and_model
,
131 const char *device_id
, const char *product
,
132 const char *psversion
, time_t mtime
,
133 size_t size
, int model_number
, int type
,
135 static int cat_drv(const char *name
, int request_id
);
136 static int cat_ppd(const char *name
, int request_id
);
137 static int cat_static(const char *name
, int request_id
);
138 static int compare_inodes(struct stat
*a
, struct stat
*b
);
139 static int compare_matches(const ppd_info_t
*p0
,
140 const ppd_info_t
*p1
);
141 static int compare_names(const ppd_info_t
*p0
,
142 const ppd_info_t
*p1
);
143 static int compare_ppds(const ppd_info_t
*p0
,
144 const ppd_info_t
*p1
);
145 static int dump_ppds_dat(void);
146 static void free_array(cups_array_t
*a
);
147 static int list_ppds(int request_id
, int limit
, const char *opt
);
148 static int load_drivers(cups_array_t
*include
,
149 cups_array_t
*exclude
);
150 static int load_drv(const char *filename
, const char *name
,
151 cups_file_t
*fp
, time_t mtime
, off_t size
);
152 static int load_ppds(const char *d
, const char *p
, int descend
);
153 static void load_ppds_dat(char *filename
, size_t filesize
,
155 static regex_t
*regex_device_id(const char *device_id
);
156 static regex_t
*regex_string(const char *s
);
160 * 'main()' - Scan for drivers and return an IPP response.
164 * cups-driverd request_id limit options
167 int /* O - Exit code */
168 main(int argc
, /* I - Number of command-line args */
169 char *argv
[]) /* I - Command-line arguments */
172 * Install or list PPDs...
175 if (argc
== 3 && !strcmp(argv
[1], "cat"))
176 return (cat_ppd(argv
[2], 0));
177 else if (argc
== 2 && !strcmp(argv
[1], "dump"))
178 return (dump_ppds_dat());
179 else if (argc
== 4 && !strcmp(argv
[1], "get"))
180 return (cat_ppd(argv
[3], atoi(argv
[2])));
181 else if (argc
== 5 && !strcmp(argv
[1], "list"))
182 return (list_ppds(atoi(argv
[2]), atoi(argv
[3]), argv
[4]));
185 fputs("Usage: cups-driverd cat ppd-name\n", stderr
);
186 fputs("Usage: cups-driverd dump\n", stderr
);
187 fputs("Usage: cups-driverd get request_id ppd-name\n", stderr
);
188 fputs("Usage: cups-driverd list request_id limit options\n", stderr
);
195 * 'add_ppd()' - Add a PPD file.
198 static ppd_info_t
* /* O - PPD */
199 add_ppd(const char *filename
, /* I - PPD filename */
200 const char *name
, /* I - PPD name */
201 const char *language
, /* I - LanguageVersion */
202 const char *make
, /* I - Manufacturer */
203 const char *make_and_model
, /* I - NickName/ModelName */
204 const char *device_id
, /* I - 1284DeviceID */
205 const char *product
, /* I - Product */
206 const char *psversion
, /* I - PSVersion */
207 time_t mtime
, /* I - Modification time */
208 size_t size
, /* I - File size */
209 int model_number
, /* I - Model number */
210 int type
, /* I - Driver type */
211 const char *scheme
) /* I - PPD scheme */
213 ppd_info_t
*ppd
; /* PPD */
214 char *recommended
; /* Foomatic driver string */
218 * Add a new PPD file...
221 if ((ppd
= (ppd_info_t
*)calloc(1, sizeof(ppd_info_t
))) == NULL
)
224 "ERROR: [cups-driverd] Ran out of memory for %d PPD files!\n",
225 cupsArrayCount(PPDsByName
));
230 * Zero-out the PPD data and copy the values over...
234 ppd
->record
.mtime
= mtime
;
235 ppd
->record
.size
= size
;
236 ppd
->record
.model_number
= model_number
;
237 ppd
->record
.type
= type
;
239 strlcpy(ppd
->record
.filename
, filename
, sizeof(ppd
->record
.filename
));
240 strlcpy(ppd
->record
.name
, name
, sizeof(ppd
->record
.name
));
241 strlcpy(ppd
->record
.languages
[0], language
,
242 sizeof(ppd
->record
.languages
[0]));
243 strlcpy(ppd
->record
.products
[0], product
, sizeof(ppd
->record
.products
[0]));
244 strlcpy(ppd
->record
.psversions
[0], psversion
,
245 sizeof(ppd
->record
.psversions
[0]));
246 strlcpy(ppd
->record
.make
, make
, sizeof(ppd
->record
.make
));
247 strlcpy(ppd
->record
.make_and_model
, make_and_model
,
248 sizeof(ppd
->record
.make_and_model
));
249 strlcpy(ppd
->record
.device_id
, device_id
, sizeof(ppd
->record
.device_id
));
250 strlcpy(ppd
->record
.scheme
, scheme
, sizeof(ppd
->record
.scheme
));
253 * Strip confusing (and often wrong) "recommended" suffix added by
254 * Foomatic drivers...
257 if ((recommended
= strstr(ppd
->record
.make_and_model
,
258 " (recommended)")) != NULL
)
262 * Add the PPD to the PPD arrays...
265 cupsArrayAdd(PPDsByName
, ppd
);
266 cupsArrayAdd(PPDsByMakeModel
, ppd
);
269 * Return the new PPD pointer...
277 * 'cat_drv()' - Generate a PPD from a driver info file.
280 static int /* O - Exit code */
281 cat_drv(const char *name
, /* I - PPD name */
282 int request_id
) /* I - Request ID for response? */
284 const char *datadir
; // CUPS_DATADIR env var
285 ppdcSource
*src
; // PPD source file data
286 ppdcDriver
*d
; // Current driver
287 cups_file_t
*out
; // Stdout via CUPS file API
288 char message
[2048], // status-message
289 filename
[1024], // Full path to .drv file(s)
290 scheme
[32], // URI scheme ("drv")
291 userpass
[256], // User/password info (unused)
292 host
[2], // Hostname (unused)
293 resource
[1024], // Resource path (/dir/to/filename.drv)
294 *pc_file_name
; // Filename portion of URI
295 int port
; // Port number (unused)
298 // Determine where CUPS has installed the data files...
299 if ((datadir
= getenv("CUPS_DATADIR")) == NULL
)
300 datadir
= CUPS_DATADIR
;
303 if (httpSeparateURI(HTTP_URI_CODING_ALL
, name
, scheme
, sizeof(scheme
),
304 userpass
, sizeof(userpass
), host
, sizeof(host
), &port
,
305 resource
, sizeof(resource
)) < HTTP_URI_OK
||
306 strstr(resource
, "../") ||
307 (pc_file_name
= strrchr(resource
, '/')) == NULL
||
308 pc_file_name
== resource
)
310 fprintf(stderr
, "ERROR: Bad PPD name \"%s\"!\n", name
);
314 snprintf(message
, sizeof(message
), "Bad PPD name \"%s\"!", name
);
316 cupsdSendIPPHeader(IPP_NOT_FOUND
, request_id
);
317 cupsdSendIPPGroup(IPP_TAG_OPERATION
);
318 cupsdSendIPPString(IPP_TAG_CHARSET
, "attributes-charset", "utf-8");
319 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "attributes-natural-language",
321 cupsdSendIPPString(IPP_TAG_TEXT
, "status-message", message
);
322 cupsdSendIPPTrailer();
328 *pc_file_name
++ = '\0';
331 if (!strncmp(resource
, "/Library/Printers/PPDs/Contents/Resources/", 42) ||
332 !strncmp(resource
, "/System/Library/Printers/PPDs/Contents/Resources/", 49))
333 strlcpy(filename
, resource
, sizeof(filename
));
337 snprintf(filename
, sizeof(filename
), "%s/drv%s", datadir
, resource
);
338 if (access(filename
, 0))
339 snprintf(filename
, sizeof(filename
), "%s/model%s", datadir
, resource
);
342 src
= new ppdcSource(filename
);
344 for (d
= (ppdcDriver
*)src
->drivers
->first();
346 d
= (ppdcDriver
*)src
->drivers
->next())
347 if (!strcmp(pc_file_name
, d
->pc_file_name
->value
) ||
348 (d
->file_name
&& !strcmp(pc_file_name
, d
->file_name
->value
)))
353 ppdcArray
*locales
; // Locale names
354 ppdcCatalog
*catalog
; // Message catalog in .drv file
357 fprintf(stderr
, "DEBUG2: [cups-driverd] %d locales defined in \"%s\"...\n",
358 src
->po_files
->count
, filename
);
360 locales
= new ppdcArray();
361 for (catalog
= (ppdcCatalog
*)src
->po_files
->first();
363 catalog
= (ppdcCatalog
*)src
->po_files
->next())
365 fprintf(stderr
, "DEBUG2: [cups-driverd] Adding locale \"%s\"...\n",
366 catalog
->locale
->value
);
367 catalog
->locale
->retain();
368 locales
->add(catalog
->locale
);
373 cupsdSendIPPHeader(IPP_OK
, request_id
);
374 cupsdSendIPPGroup(IPP_TAG_OPERATION
);
375 cupsdSendIPPString(IPP_TAG_CHARSET
, "attributes-charset", "utf-8");
376 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "attributes-natural-language",
378 cupsdSendIPPTrailer();
382 out
= cupsFileStdout();
383 d
->write_ppd_file(out
, NULL
, locales
, src
, PPDC_LFONLY
);
390 fprintf(stderr
, "ERROR: PPD \"%s\" not found!\n", name
);
394 snprintf(message
, sizeof(message
), "PPD \"%s\" not found!", name
);
396 cupsdSendIPPHeader(IPP_NOT_FOUND
, request_id
);
397 cupsdSendIPPGroup(IPP_TAG_OPERATION
);
398 cupsdSendIPPString(IPP_TAG_CHARSET
, "attributes-charset", "utf-8");
399 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "attributes-natural-language",
401 cupsdSendIPPString(IPP_TAG_TEXT
, "status-message", message
);
402 cupsdSendIPPTrailer();
413 * 'cat_ppd()' - Copy a PPD file to stdout.
416 static int /* O - Exit code */
417 cat_ppd(const char *name
, /* I - PPD name */
418 int request_id
) /* I - Request ID for response? */
420 char scheme
[256], /* Scheme from PPD name */
421 *sptr
, /* Pointer into scheme */
422 line
[1024], /* Line/filename */
423 message
[2048]; /* status-message */
427 * Figure out if this is a static or dynamic PPD file...
430 strlcpy(scheme
, name
, sizeof(scheme
));
431 if ((sptr
= strchr(scheme
, ':')) != NULL
)
435 if (!strcmp(scheme
, "file"))
438 * "file:name" == "name"...
449 puts("Content-Type: application/ipp\n");
452 return (cat_static(name
, request_id
));
453 else if (!strcmp(scheme
, "drv"))
454 return (cat_drv(name
, request_id
));
458 * Dynamic PPD, see if we have a driver program to support it...
461 const char *serverbin
; /* CUPS_SERVERBIN env var */
462 char *argv
[4]; /* Arguments for program */
465 if ((serverbin
= getenv("CUPS_SERVERBIN")) == NULL
)
466 serverbin
= CUPS_SERVERBIN
;
468 snprintf(line
, sizeof(line
), "%s/driver/%s", serverbin
, scheme
);
469 if (access(line
, X_OK
))
472 * File does not exist or is not executable...
475 fprintf(stderr
, "ERROR: [cups-driverd] Unable to access \"%s\" - %s\n",
476 line
, strerror(errno
));
480 snprintf(message
, sizeof(message
), "Unable to access \"%s\" - %s",
481 line
, strerror(errno
));
483 cupsdSendIPPHeader(IPP_NOT_FOUND
, request_id
);
484 cupsdSendIPPGroup(IPP_TAG_OPERATION
);
485 cupsdSendIPPString(IPP_TAG_CHARSET
, "attributes-charset", "utf-8");
486 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "attributes-natural-language",
488 cupsdSendIPPString(IPP_TAG_TEXT
, "status-message", message
);
489 cupsdSendIPPTrailer();
496 * Yes, let it cat the PPD file...
501 cupsdSendIPPHeader(IPP_OK
, request_id
);
502 cupsdSendIPPGroup(IPP_TAG_OPERATION
);
503 cupsdSendIPPString(IPP_TAG_CHARSET
, "attributes-charset", "utf-8");
504 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "attributes-natural-language",
506 cupsdSendIPPTrailer();
510 argv
[1] = (char *)"cat";
511 argv
[2] = (char *)name
;
514 if (cupsdExec(line
, argv
))
517 * Unable to execute driver...
520 fprintf(stderr
, "ERROR: [cups-driverd] Unable to execute \"%s\" - %s\n",
521 line
, strerror(errno
));
527 * Return with no errors...
535 * 'copy_static()' - Copy a static PPD file to stdout.
538 static int /* O - Exit code */
539 cat_static(const char *name
, /* I - PPD name */
540 int request_id
) /* I - Request ID for response? */
542 cups_file_t
*fp
; /* PPD file */
543 const char *datadir
; /* CUPS_DATADIR env var */
544 char line
[1024], /* Line/filename */
545 message
[2048]; /* status-message */
548 if (name
[0] == '/' || strstr(name
, "../") || strstr(name
, "/.."))
554 fprintf(stderr
, "ERROR: [cups-driverd] Bad PPD name \"%s\"!\n", name
);
558 snprintf(message
, sizeof(message
), "Bad PPD name \"%s\"!", name
);
560 cupsdSendIPPHeader(IPP_NOT_FOUND
, request_id
);
561 cupsdSendIPPGroup(IPP_TAG_OPERATION
);
562 cupsdSendIPPString(IPP_TAG_CHARSET
, "attributes-charset", "utf-8");
563 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "attributes-natural-language",
565 cupsdSendIPPString(IPP_TAG_TEXT
, "status-message", message
);
566 cupsdSendIPPTrailer();
573 * Try opening the file...
577 if (!strncmp(name
, "System/Library/Printers/PPDs/Contents/Resources/", 48) ||
578 !strncmp(name
, "Library/Printers/PPDs/Contents/Resources/", 41))
581 * Map ppd-name to Mac OS X standard locations...
584 snprintf(line
, sizeof(line
), "/%s", name
);
588 #elif defined(__linux)
589 if (!strncmp(name
, "lsb/usr/", 8))
592 * Map ppd-name to LSB standard /usr/share/ppd location...
595 snprintf(line
, sizeof(line
), "/usr/share/ppd/%s", name
+ 8);
597 else if (!strncmp(name
, "lsb/opt/", 8))
600 * Map ppd-name to LSB standard /opt/share/ppd location...
603 snprintf(line
, sizeof(line
), "/opt/share/ppd/%s", name
+ 8);
605 else if (!strncmp(name
, "lsb/local/", 10))
608 * Map ppd-name to LSB standard /usr/local/share/ppd location...
611 snprintf(line
, sizeof(line
), "/usr/local/share/ppd/%s", name
+ 10);
615 #endif /* __APPLE__ */
617 if ((datadir
= getenv("CUPS_DATADIR")) == NULL
)
618 datadir
= CUPS_DATADIR
;
620 snprintf(line
, sizeof(line
), "%s/model/%s", datadir
, name
);
623 if ((fp
= cupsFileOpen(line
, "r")) == NULL
)
625 fprintf(stderr
, "ERROR: [cups-driverd] Unable to open \"%s\" - %s\n",
626 line
, strerror(errno
));
630 snprintf(message
, sizeof(message
), "Unable to open \"%s\" - %s",
631 line
, strerror(errno
));
633 cupsdSendIPPHeader(IPP_NOT_FOUND
, request_id
);
634 cupsdSendIPPGroup(IPP_TAG_OPERATION
);
635 cupsdSendIPPString(IPP_TAG_CHARSET
, "attributes-charset", "utf-8");
636 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "attributes-natural-language",
638 cupsdSendIPPString(IPP_TAG_TEXT
, "status-message", message
);
639 cupsdSendIPPTrailer();
647 cupsdSendIPPHeader(IPP_OK
, request_id
);
648 cupsdSendIPPGroup(IPP_TAG_OPERATION
);
649 cupsdSendIPPString(IPP_TAG_CHARSET
, "attributes-charset", "utf-8");
650 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "attributes-natural-language",
652 cupsdSendIPPTrailer();
656 * Now copy the file to stdout...
659 while (cupsFileGets(fp
, line
, sizeof(line
)))
669 * 'compare_inodes()' - Compare two inodes.
672 static int /* O - Result of comparison */
673 compare_inodes(struct stat
*a
, /* I - First inode */
674 struct stat
*b
) /* I - Second inode */
676 if (a
->st_dev
!= b
->st_dev
)
677 return (a
->st_dev
- b
->st_dev
);
679 return (a
->st_ino
- b
->st_ino
);
684 * 'compare_matches()' - Compare PPD match scores for sorting.
688 compare_matches(const ppd_info_t
*p0
, /* I - First PPD */
689 const ppd_info_t
*p1
) /* I - Second PPD */
691 if (p1
->matches
!= p0
->matches
)
692 return (p1
->matches
- p0
->matches
);
694 return (cupsdCompareNames(p0
->record
.make_and_model
,
695 p1
->record
.make_and_model
));
700 * 'compare_names()' - Compare PPD filenames for sorting.
703 static int /* O - Result of comparison */
704 compare_names(const ppd_info_t
*p0
, /* I - First PPD file */
705 const ppd_info_t
*p1
) /* I - Second PPD file */
707 int diff
; /* Difference between strings */
710 if ((diff
= strcmp(p0
->record
.filename
, p1
->record
.filename
)) != 0)
713 return (strcmp(p0
->record
.name
, p1
->record
.name
));
718 * 'compare_ppds()' - Compare PPD file make and model names for sorting.
721 static int /* O - Result of comparison */
722 compare_ppds(const ppd_info_t
*p0
, /* I - First PPD file */
723 const ppd_info_t
*p1
) /* I - Second PPD file */
725 int diff
; /* Difference between strings */
729 * First compare manufacturers...
732 if ((diff
= strcasecmp(p0
->record
.make
, p1
->record
.make
)) != 0)
734 else if ((diff
= cupsdCompareNames(p0
->record
.make_and_model
,
735 p1
->record
.make_and_model
)) != 0)
738 return (strcmp(p0
->record
.languages
[0], p1
->record
.languages
[0]));
743 * 'dump_ppds_dat()' - Dump the contents of the ppds.dat file.
746 static int /* O - Exit status */
749 char filename
[1024]; /* ppds.dat filename */
750 ppd_info_t
*ppd
; /* Current PPD */
754 * See if we a PPD database file...
757 load_ppds_dat(filename
, sizeof(filename
), 0);
759 puts("mtime,size,model_number,type,filename,name,languages0,products0,"
760 "psversions0,make,make_and_model,device_id,scheme");
761 for (ppd
= (ppd_info_t
*)cupsArrayFirst(PPDsByName
);
763 ppd
= (ppd_info_t
*)cupsArrayNext(PPDsByName
))
764 printf("%d,%ld,%d,%d,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\","
766 (int)ppd
->record
.mtime
, (long)ppd
->record
.size
,
767 ppd
->record
.model_number
, ppd
->record
.type
, ppd
->record
.filename
,
768 ppd
->record
.name
, ppd
->record
.languages
[0], ppd
->record
.products
[0],
769 ppd
->record
.psversions
[0], ppd
->record
.make
,
770 ppd
->record
.make_and_model
, ppd
->record
.device_id
,
778 * 'free_array()' - Free an array of strings.
782 free_array(cups_array_t
*a
) /* I - Array to free */
784 char *ptr
; /* Pointer to string */
787 for (ptr
= (char *)cupsArrayFirst(a
);
789 ptr
= (char *)cupsArrayNext(a
))
797 * 'list_ppds()' - List PPD files.
800 static int /* O - Exit code */
801 list_ppds(int request_id
, /* I - Request ID */
802 int limit
, /* I - Limit */
803 const char *opt
) /* I - Option argument */
805 int i
; /* Looping vars */
806 int count
; /* Number of PPDs to send */
807 ppd_info_t
*ppd
; /* Current PPD file */
808 cups_file_t
*fp
; /* ppds.dat file */
809 char filename
[1024], /* ppds.dat filename */
810 model
[1024]; /* Model directory */
811 const char *cups_datadir
; /* CUPS_DATADIR environment variable */
812 int num_options
; /* Number of options */
813 cups_option_t
*options
; /* Options */
814 cups_array_t
*requested
, /* requested-attributes values */
815 *include
, /* PPD schemes to include */
816 *exclude
; /* PPD schemes to exclude */
817 const char *device_id
, /* ppd-device-id option */
818 *language
, /* ppd-natural-language option */
819 *make
, /* ppd-make option */
820 *make_and_model
, /* ppd-make-and-model option */
821 *model_number_str
, /* ppd-model-number option */
822 *product
, /* ppd-product option */
823 *psversion
, /* ppd-psversion option */
824 *type_str
; /* ppd-type option */
825 int model_number
, /* ppd-model-number value */
826 type
, /* ppd-type value */
827 make_and_model_len
, /* Length of ppd-make-and-model */
828 product_len
, /* Length of ppd-product */
829 send_device_id
, /* Send ppd-device-id? */
830 send_make
, /* Send ppd-make? */
831 send_make_and_model
, /* Send ppd-make-and-model? */
832 send_model_number
, /* Send ppd-model-number? */
833 send_name
, /* Send ppd-name? */
834 send_natural_language
, /* Send ppd-natural-language? */
835 send_product
, /* Send ppd-product? */
836 send_psversion
, /* Send ppd-psversion? */
837 send_type
, /* Send ppd-type? */
838 sent_header
; /* Sent the IPP header? */
839 regex_t
*device_id_re
, /* Regular expression for matching device ID */
840 *make_and_model_re
; /* Regular expression for matching make and model */
841 regmatch_t re_matches
[6]; /* Regular expression matches */
842 cups_array_t
*matches
; /* Matching PPDs */
846 "DEBUG2: [cups-driverd] list_ppds(request_id=%d, limit=%d, "
847 "opt=\"%s\"\n", request_id
, limit
, opt
);
850 * See if we a PPD database file...
853 load_ppds_dat(filename
, sizeof(filename
), 1);
856 * Load all PPDs in the specified directory and below...
859 if ((cups_datadir
= getenv("CUPS_DATADIR")) == NULL
)
860 cups_datadir
= CUPS_DATADIR
;
862 Inodes
= cupsArrayNew((cups_array_func_t
)compare_inodes
, NULL
);
864 snprintf(model
, sizeof(model
), "%s/model", cups_datadir
);
865 load_ppds(model
, "", 1);
867 snprintf(model
, sizeof(model
), "%s/drv", cups_datadir
);
868 load_ppds(model
, "", 1);
872 * Load PPDs from standard Mac OS X locations...
875 load_ppds("/Library/Printers/PPDs/Contents/Resources",
876 "Library/Printers/PPDs/Contents/Resources", 0);
877 load_ppds("/Library/Printers/PPDs/Contents/Resources/en.lproj",
878 "Library/Printers/PPDs/Contents/Resources/en.lproj", 0);
879 load_ppds("/System/Library/Printers/PPDs/Contents/Resources",
880 "System/Library/Printers/PPDs/Contents/Resources", 0);
881 load_ppds("/System/Library/Printers/PPDs/Contents/Resources/en.lproj",
882 "System/Library/Printers/PPDs/Contents/Resources/en.lproj", 0);
884 #elif defined(__linux)
886 * Load PPDs from LSB-defined locations...
889 if (!access("/usr/local/share/ppd", 0))
890 load_ppds("/usr/local/share/ppd", "lsb/local", 1);
891 if (!access("/usr/share/ppd", 0))
892 load_ppds("/usr/share/ppd", "lsb/usr", 1);
893 if (!access("/opt/share/ppd", 0))
894 load_ppds("/opt/share/ppd", "lsb/opt", 1);
895 #endif /* __APPLE__ */
898 * Cull PPD files that are no longer present...
901 for (ppd
= (ppd_info_t
*)cupsArrayFirst(PPDsByName
);
903 ppd
= (ppd_info_t
*)cupsArrayNext(PPDsByName
))
907 * Remove this PPD file from the list...
910 cupsArrayRemove(PPDsByName
, ppd
);
911 cupsArrayRemove(PPDsByMakeModel
, ppd
);
918 * Write the new ppds.dat file...
921 fprintf(stderr
, "DEBUG: [cups-driverd] ChangedPPD=%d\n", ChangedPPD
);
925 if ((fp
= cupsFileOpen(filename
, "w")) != NULL
)
927 unsigned ppdsync
= PPD_SYNC
; /* Sync word */
930 cupsFileWrite(fp
, (char *)&ppdsync
, sizeof(ppdsync
));
932 for (ppd
= (ppd_info_t
*)cupsArrayFirst(PPDsByName
);
934 ppd
= (ppd_info_t
*)cupsArrayNext(PPDsByName
))
935 cupsFileWrite(fp
, (char *)&(ppd
->record
), sizeof(ppd_rec_t
));
939 fprintf(stderr
, "INFO: [cups-driverd] Wrote \"%s\", %d PPDs...\n",
940 filename
, cupsArrayCount(PPDsByName
));
943 fprintf(stderr
, "ERROR: [cups-driverd] Unable to write \"%s\" - %s\n",
944 filename
, strerror(errno
));
947 fputs("INFO: [cups-driverd] No new or changed PPDs...\n", stderr
);
950 * Scan for dynamic PPD files...
953 num_options
= cupsParseOptions(opt
, 0, &options
);
954 exclude
= cupsdCreateStringsArray(cupsGetOption("exclude-schemes",
955 num_options
, options
));
956 include
= cupsdCreateStringsArray(cupsGetOption("include-schemes",
957 num_options
, options
));
959 load_drivers(include
, exclude
);
962 * Add the raw driver...
965 add_ppd("", "raw", "en", "Raw", "Raw Queue", "", "", "", 0, 0, 0,
966 PPD_TYPE_UNKNOWN
, "raw");
969 * Send IPP attributes...
972 requested
= cupsdCreateStringsArray(
973 cupsGetOption("requested-attributes", num_options
,
975 device_id
= cupsGetOption("ppd-device-id", num_options
, options
);
976 language
= cupsGetOption("ppd-natural-language", num_options
, options
);
977 make
= cupsGetOption("ppd-make", num_options
, options
);
978 make_and_model
= cupsGetOption("ppd-make-and-model", num_options
, options
);
979 model_number_str
= cupsGetOption("ppd-model-number", num_options
, options
);
980 product
= cupsGetOption("ppd-product", num_options
, options
);
981 psversion
= cupsGetOption("ppd-psversion", num_options
, options
);
982 type_str
= cupsGetOption("ppd-type", num_options
, options
);
985 make_and_model_len
= strlen(make_and_model
);
987 make_and_model_len
= 0;
990 product_len
= strlen(product
);
994 if (model_number_str
)
995 model_number
= atoi(model_number_str
);
1002 type
< (int)(sizeof(ppd_types
) / sizeof(ppd_types
[0]));
1004 if (!strcmp(type_str
, ppd_types
[type
]))
1007 if (type
>= (int)(sizeof(ppd_types
) / sizeof(ppd_types
[0])))
1009 fprintf(stderr
, "ERROR: [cups-driverd] Bad ppd-type=\"%s\" ignored!\n",
1017 for (i
= 0; i
< num_options
; i
++)
1018 fprintf(stderr
, "DEBUG2: [cups-driverd] %s=\"%s\"\n", options
[i
].name
,
1021 if (!requested
|| cupsArrayFind(requested
, (void *)"all") != NULL
)
1025 send_make_and_model
= 1;
1026 send_model_number
= 1;
1027 send_natural_language
= 1;
1035 send_name
= cupsArrayFind(requested
,
1036 (void *)"ppd-name") != NULL
;
1037 send_make
= cupsArrayFind(requested
,
1038 (void *)"ppd-make") != NULL
;
1039 send_make_and_model
= cupsArrayFind(requested
,
1040 (void *)"ppd-make-and-model") != NULL
;
1041 send_model_number
= cupsArrayFind(requested
,
1042 (void *)"ppd-model-number") != NULL
;
1043 send_natural_language
= cupsArrayFind(requested
,
1044 (void *)"ppd-natural-language") != NULL
;
1045 send_device_id
= cupsArrayFind(requested
,
1046 (void *)"ppd-device-id") != NULL
;
1047 send_product
= cupsArrayFind(requested
,
1048 (void *)"ppd-product") != NULL
;
1049 send_psversion
= cupsArrayFind(requested
,
1050 (void *)"ppd-psversion") != NULL
;
1051 send_type
= cupsArrayFind(requested
,
1052 (void *)"ppd-type") != NULL
;
1056 * Send the content type header to the scheduler; request_id can only be
1057 * 0 when run manually since the scheduler enforces the IPP requirement for
1058 * a request ID from 1 to 2^31-1...
1062 puts("Content-Type: application/ipp\n");
1066 if (limit
<= 0 || limit
> cupsArrayCount(PPDsByMakeModel
))
1067 count
= cupsArrayCount(PPDsByMakeModel
);
1071 if (device_id
|| language
|| make
|| make_and_model
|| model_number_str
||
1074 matches
= cupsArrayNew((cups_array_func_t
)compare_matches
, NULL
);
1077 device_id_re
= regex_device_id(device_id
);
1079 device_id_re
= NULL
;
1082 make_and_model_re
= regex_string(make_and_model
);
1084 make_and_model_re
= NULL
;
1086 for (ppd
= (ppd_info_t
*)cupsArrayFirst(PPDsByMakeModel
);
1088 ppd
= (ppd_info_t
*)cupsArrayNext(PPDsByMakeModel
))
1091 * Filter PPDs based on make, model, product, language, model number,
1092 * and/or device ID using the "matches" score value. An exact match
1093 * for product, make-and-model, or device-id adds 3 to the score.
1094 * Partial matches for make-and-model yield 1 or 2 points, and matches
1095 * for the make and language add a single point. Results are then sorted
1096 * by score, highest score first.
1099 if (ppd
->record
.type
< PPD_TYPE_POSTSCRIPT
||
1100 ppd
->record
.type
>= PPD_TYPE_DRV
)
1103 if (cupsArrayFind(exclude
, ppd
->record
.scheme
) ||
1104 (include
&& !cupsArrayFind(include
, ppd
->record
.scheme
)))
1110 !regexec(device_id_re
, ppd
->record
.device_id
,
1111 (int)(sizeof(re_matches
) / sizeof(re_matches
[0])),
1115 * Add the number of matching values from the device ID - it will be
1116 * at least 2 (manufacturer and model), and as much as 3 (command set).
1119 for (i
= 1; i
< (int)(sizeof(re_matches
) / sizeof(re_matches
[0])); i
++)
1120 if (re_matches
[i
].rm_so
>= 0)
1126 for (i
= 0; i
< PPD_MAX_LANG
; i
++)
1127 if (!ppd
->record
.languages
[i
][0])
1129 else if (!strcmp(ppd
->record
.languages
[i
], language
))
1136 if (make
&& !strcasecmp(ppd
->record
.make
, make
))
1139 if (make_and_model_re
&&
1140 !regexec(make_and_model_re
, ppd
->record
.make_and_model
,
1141 (int)(sizeof(re_matches
) / sizeof(re_matches
[0])),
1144 // See how much of the make-and-model string we matched...
1145 if (re_matches
[0].rm_so
== 0)
1147 if (re_matches
[0].rm_eo
== make_and_model_len
)
1148 ppd
->matches
+= 3; // Exact match
1150 ppd
->matches
+= 2; // Prefix match
1153 ppd
->matches
++; // Infix match
1156 if (model_number_str
&& ppd
->record
.model_number
== model_number
)
1161 for (i
= 0; i
< PPD_MAX_PROD
; i
++)
1162 if (!ppd
->record
.products
[i
][0])
1164 else if (!strcasecmp(ppd
->record
.products
[i
], product
))
1173 for (i
= 0; i
< PPD_MAX_VERS
; i
++)
1174 if (!ppd
->record
.psversions
[i
][0])
1176 else if (!strcasecmp(ppd
->record
.psversions
[i
], psversion
))
1183 if (type_str
&& ppd
->record
.type
== type
)
1188 fprintf(stderr
, "DEBUG2: [cups-driverd] %s matches with score %d!\n",
1189 ppd
->record
.name
, ppd
->matches
);
1190 cupsArrayAdd(matches
, ppd
);
1194 else if (include
|| exclude
)
1196 matches
= cupsArrayNew((cups_array_func_t
)compare_ppds
, NULL
);
1198 for (ppd
= (ppd_info_t
*)cupsArrayFirst(PPDsByMakeModel
);
1200 ppd
= (ppd_info_t
*)cupsArrayNext(PPDsByMakeModel
))
1203 * Filter PPDs based on the include/exclude lists.
1206 if (ppd
->record
.type
< PPD_TYPE_POSTSCRIPT
||
1207 ppd
->record
.type
>= PPD_TYPE_DRV
)
1210 if (cupsArrayFind(exclude
, ppd
->record
.scheme
) ||
1211 (include
&& !cupsArrayFind(include
, ppd
->record
.scheme
)))
1214 cupsArrayAdd(matches
, ppd
);
1218 matches
= PPDsByMakeModel
;
1220 for (ppd
= (ppd_info_t
*)cupsArrayFirst(matches
);
1222 ppd
= (ppd_info_t
*)cupsArrayNext(matches
))
1225 * Skip invalid PPDs...
1228 if (ppd
->record
.type
< PPD_TYPE_POSTSCRIPT
||
1229 ppd
->record
.type
>= PPD_TYPE_DRV
)
1240 cupsdSendIPPHeader(IPP_OK
, request_id
);
1241 cupsdSendIPPGroup(IPP_TAG_OPERATION
);
1242 cupsdSendIPPString(IPP_TAG_CHARSET
, "attributes-charset", "utf-8");
1243 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "attributes-natural-language",
1247 fprintf(stderr
, "DEBUG2: [cups-driverd] Sending %s (%s)...\n",
1248 ppd
->record
.name
, ppd
->record
.make_and_model
);
1252 cupsdSendIPPGroup(IPP_TAG_PRINTER
);
1255 cupsdSendIPPString(IPP_TAG_NAME
, "ppd-name", ppd
->record
.name
);
1257 if (send_natural_language
)
1259 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "ppd-natural-language",
1260 ppd
->record
.languages
[0]);
1262 for (i
= 1; i
< PPD_MAX_LANG
&& ppd
->record
.languages
[i
][0]; i
++)
1263 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "", ppd
->record
.languages
[i
]);
1267 cupsdSendIPPString(IPP_TAG_TEXT
, "ppd-make", ppd
->record
.make
);
1269 if (send_make_and_model
)
1270 cupsdSendIPPString(IPP_TAG_TEXT
, "ppd-make-and-model",
1271 ppd
->record
.make_and_model
);
1274 cupsdSendIPPString(IPP_TAG_TEXT
, "ppd-device-id",
1275 ppd
->record
.device_id
);
1279 cupsdSendIPPString(IPP_TAG_TEXT
, "ppd-product",
1280 ppd
->record
.products
[0]);
1282 for (i
= 1; i
< PPD_MAX_PROD
&& ppd
->record
.products
[i
][0]; i
++)
1283 cupsdSendIPPString(IPP_TAG_TEXT
, "", ppd
->record
.products
[i
]);
1288 cupsdSendIPPString(IPP_TAG_TEXT
, "ppd-psversion",
1289 ppd
->record
.psversions
[0]);
1291 for (i
= 1; i
< PPD_MAX_VERS
&& ppd
->record
.psversions
[i
][0]; i
++)
1292 cupsdSendIPPString(IPP_TAG_TEXT
, "", ppd
->record
.psversions
[i
]);
1296 cupsdSendIPPString(IPP_TAG_KEYWORD
, "ppd-type",
1297 ppd_types
[ppd
->record
.type
]);
1299 if (send_model_number
)
1300 cupsdSendIPPInteger(IPP_TAG_INTEGER
, "ppd-model-number",
1301 ppd
->record
.model_number
);
1304 * If we have only requested the ppd-make attribute, then skip
1305 * the remaining PPDs with this make...
1308 if (cupsArrayFind(requested
, (void *)"ppd-make") &&
1309 cupsArrayCount(requested
) == 1)
1311 const char *this_make
; /* This ppd-make */
1314 for (this_make
= ppd
->record
.make
,
1315 ppd
= (ppd_info_t
*)cupsArrayNext(matches
);
1317 ppd
= (ppd_info_t
*)cupsArrayNext(matches
))
1318 if (strcasecmp(this_make
, ppd
->record
.make
))
1321 cupsArrayPrev(matches
);
1327 cupsdSendIPPHeader(IPP_NOT_FOUND
, request_id
);
1328 cupsdSendIPPGroup(IPP_TAG_OPERATION
);
1329 cupsdSendIPPString(IPP_TAG_CHARSET
, "attributes-charset", "utf-8");
1330 cupsdSendIPPString(IPP_TAG_LANGUAGE
, "attributes-natural-language", "en-US");
1333 cupsdSendIPPTrailer();
1340 * 'load_ppds()' - Load PPD files recursively.
1343 static int /* O - 1 on success, 0 on failure */
1344 load_ppds(const char *d
, /* I - Actual directory */
1345 const char *p
, /* I - Virtual path in name */
1346 int descend
) /* I - Descend into directories? */
1348 struct stat dinfo
, /* Directory information */
1349 *dinfoptr
; /* Pointer to match */
1350 int i
; /* Looping var */
1351 cups_file_t
*fp
; /* Pointer to file */
1352 cups_dir_t
*dir
; /* Directory pointer */
1353 cups_dentry_t
*dent
; /* Directory entry */
1354 char filename
[1024], /* Name of PPD or directory */
1355 line
[256], /* Line from backend */
1356 *ptr
, /* Pointer into name */
1357 name
[128], /* Name of PPD file */
1358 lang_version
[64], /* PPD LanguageVersion */
1359 lang_encoding
[64], /* PPD LanguageEncoding */
1360 country
[64], /* Country code */
1361 manufacturer
[256], /* Manufacturer */
1362 make_model
[256], /* Make and Model */
1363 model_name
[256], /* ModelName */
1364 nick_name
[256], /* NickName */
1365 device_id
[256], /* 1284DeviceID */
1366 product
[256], /* Product */
1367 psversion
[256], /* PSVersion */
1368 temp
[512]; /* Temporary make and model */
1369 int model_number
, /* cupsModelNumber */
1370 type
; /* ppd-type */
1371 cups_array_t
*products
, /* Product array */
1372 *psversions
, /* PSVersion array */
1373 *cups_languages
; /* cupsLanguages array */
1374 ppd_info_t
*ppd
, /* New PPD file */
1375 key
; /* Search key */
1376 int new_ppd
; /* Is this a new PPD? */
1377 struct /* LanguageVersion translation table */
1379 const char *version
, /* LanguageVersion string */
1380 *language
; /* Language code */
1383 { "chinese", "zh" },
1387 { "english", "en" },
1388 { "finnish", "fi" },
1392 { "hungarian", "hu" },
1393 { "italian", "it" },
1394 { "japanese", "ja" },
1396 { "norwegian", "no" },
1398 { "portuguese", "pt" },
1399 { "russian", "ru" },
1400 { "simplified chinese", "zh_CN" },
1402 { "spanish", "es" },
1403 { "swedish", "sv" },
1404 { "traditional chinese", "zh_TW" },
1410 * See if we've loaded this directory before...
1413 if (stat(d
, &dinfo
))
1415 if (errno
!= ENOENT
)
1416 fprintf(stderr
, "ERROR: [cups-driverd] Unable to stat \"%s\": %s\n", d
,
1421 else if (cupsArrayFind(Inodes
, &dinfo
))
1423 fprintf(stderr
, "ERROR: [cups-driverd] Skipping \"%s\": loop detected!\n",
1429 * Nope, add it to the Inodes array and continue...
1432 dinfoptr
= (struct stat
*)malloc(sizeof(struct stat
));
1433 memcpy(dinfoptr
, &dinfo
, sizeof(struct stat
));
1434 cupsArrayAdd(Inodes
, dinfoptr
);
1436 if ((dir
= cupsDirOpen(d
)) == NULL
)
1438 if (errno
!= ENOENT
)
1440 "ERROR: [cups-driverd] Unable to open PPD directory \"%s\": %s\n",
1441 d
, strerror(errno
));
1446 fprintf(stderr
, "DEBUG: [cups-driverd] Loading \"%s\"...\n", d
);
1448 while ((dent
= cupsDirRead(dir
)) != NULL
)
1451 * Skip files/directories starting with "."...
1454 if (dent
->filename
[0] == '.')
1458 * See if this is a file...
1461 snprintf(filename
, sizeof(filename
), "%s/%s", d
, dent
->filename
);
1464 snprintf(name
, sizeof(name
), "%s/%s", p
, dent
->filename
);
1466 strlcpy(name
, dent
->filename
, sizeof(name
));
1468 if (S_ISDIR(dent
->fileinfo
.st_mode
))
1471 * Do subdirectory...
1475 if (!load_ppds(filename
, name
, 1))
1485 * See if this file has been scanned before...
1488 strcpy(key
.record
.filename
, name
);
1489 strcpy(key
.record
.name
, name
);
1491 ppd
= (ppd_info_t
*)cupsArrayFind(PPDsByName
, &key
);
1494 ppd
->record
.size
== dent
->fileinfo
.st_size
&&
1495 ppd
->record
.mtime
== dent
->fileinfo
.st_mtime
)
1498 * Rewind to the first entry for this file...
1501 while ((ppd
= (ppd_info_t
*)cupsArrayPrev(PPDsByName
)) != NULL
&&
1502 !strcmp(ppd
->record
.filename
, name
));
1505 * Then mark all of the matches for this file as found...
1508 while ((ppd
= (ppd_info_t
*)cupsArrayNext(PPDsByName
)) != NULL
&&
1509 !strcmp(ppd
->record
.filename
, name
))
1516 * No, file is new/changed, so re-scan it...
1519 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
1523 * Now see if this is a PPD file...
1527 cupsFileGets(fp
, line
, sizeof(line
));
1529 if (strncmp(line
, "*PPD-Adobe:", 11))
1532 * Nope, treat it as a driver information file...
1535 load_drv(filename
, name
, fp
, dent
->fileinfo
.st_mtime
,
1536 dent
->fileinfo
.st_size
);
1541 * Now read until we get the NickName field...
1544 cups_languages
= cupsArrayNew(NULL
, NULL
);
1545 products
= cupsArrayNew(NULL
, NULL
);
1546 psversions
= cupsArrayNew(NULL
, NULL
);
1548 model_name
[0] = '\0';
1549 nick_name
[0] = '\0';
1550 manufacturer
[0] = '\0';
1551 device_id
[0] = '\0';
1552 lang_encoding
[0] = '\0';
1553 strcpy(lang_version
, "en");
1555 type
= PPD_TYPE_POSTSCRIPT
;
1557 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
1559 if (!strncmp(line
, "*Manufacturer:", 14))
1560 sscanf(line
, "%*[^\"]\"%255[^\"]", manufacturer
);
1561 else if (!strncmp(line
, "*ModelName:", 11))
1562 sscanf(line
, "%*[^\"]\"%127[^\"]", model_name
);
1563 else if (!strncmp(line
, "*LanguageEncoding:", 18))
1564 sscanf(line
, "%*[^:]:%63s", lang_encoding
);
1565 else if (!strncmp(line
, "*LanguageVersion:", 17))
1566 sscanf(line
, "%*[^:]:%63s", lang_version
);
1567 else if (!strncmp(line
, "*NickName:", 10))
1568 sscanf(line
, "%*[^\"]\"%255[^\"]", nick_name
);
1569 else if (!strncasecmp(line
, "*1284DeviceID:", 14))
1571 sscanf(line
, "%*[^\"]\"%255[^\"]", device_id
);
1573 // Make sure device ID ends with a semicolon...
1574 if (device_id
[0] && device_id
[strlen(device_id
) - 1] != ';')
1575 strlcat(device_id
, ";", sizeof(device_id
));
1577 else if (!strncmp(line
, "*Product:", 9))
1579 if (sscanf(line
, "%*[^\"]\"(%255[^\"]", product
) == 1)
1582 * Make sure the value ends with a right parenthesis - can't stop at
1583 * the first right paren since the product name may contain escaped
1587 ptr
= product
+ strlen(product
) - 1;
1588 if (ptr
> product
&& *ptr
== ')')
1591 * Yes, ends with a parenthesis, so remove it from the end and
1592 * add the product to the list...
1596 cupsArrayAdd(products
, strdup(product
));
1600 else if (!strncmp(line
, "*PSVersion:", 11))
1602 sscanf(line
, "%*[^\"]\"%255[^\"]", psversion
);
1603 cupsArrayAdd(psversions
, strdup(psversion
));
1605 else if (!strncmp(line
, "*cupsLanguages:", 15))
1607 char *start
; /* Start of language */
1610 for (start
= line
+ 15; *start
&& isspace(*start
& 255); start
++);
1612 if (*start
++ == '\"')
1616 for (ptr
= start
+ 1;
1617 *ptr
&& *ptr
!= '\"' && !isspace(*ptr
& 255);
1624 while (isspace(*ptr
& 255))
1628 cupsArrayAdd(cups_languages
, strdup(start
));
1633 else if (!strncmp(line
, "*cupsFax:", 9))
1635 for (ptr
= line
+ 9; isspace(*ptr
& 255); ptr
++);
1637 if (!strncasecmp(ptr
, "true", 4))
1638 type
= PPD_TYPE_FAX
;
1640 else if (!strncmp(line
, "*cupsFilter:", 12) && type
== PPD_TYPE_POSTSCRIPT
)
1642 if (strstr(line
+ 12, "application/vnd.cups-raster"))
1643 type
= PPD_TYPE_RASTER
;
1644 else if (strstr(line
+ 12, "application/vnd.cups-pdf"))
1645 type
= PPD_TYPE_PDF
;
1647 else if (!strncmp(line
, "*cupsModelNumber:", 17))
1648 sscanf(line
, "*cupsModelNumber:%d", &model_number
);
1649 else if (!strncmp(line
, "*OpenUI", 7))
1652 * Stop early if we have a NickName or ModelName attributes
1653 * before the first OpenUI...
1656 if ((model_name
[0] || nick_name
[0]) && cupsArrayCount(products
) > 0 &&
1657 cupsArrayCount(psversions
) > 0)
1669 * See if we got all of the required info...
1673 cupsCharsetToUTF8((cups_utf8_t
*)make_model
, nick_name
,
1674 sizeof(make_model
), _ppdGetEncoding(lang_encoding
));
1676 strcpy(make_model
, model_name
);
1678 while (isspace(make_model
[0] & 255))
1679 _cups_strcpy(make_model
, make_model
+ 1);
1681 if (!make_model
[0] || cupsArrayCount(products
) == 0 ||
1682 cupsArrayCount(psversions
) == 0)
1685 * We don't have all the info needed, so skip this file...
1689 fprintf(stderr
, "WARNING: Missing NickName and ModelName in %s!\n",
1692 if (cupsArrayCount(products
) == 0)
1693 fprintf(stderr
, "WARNING: Missing Product in %s!\n", filename
);
1695 if (cupsArrayCount(psversions
) == 0)
1696 fprintf(stderr
, "WARNING: Missing PSVersion in %s!\n", filename
);
1698 free_array(products
);
1699 free_array(psversions
);
1700 free_array(cups_languages
);
1706 cupsArrayAdd(products
, strdup(model_name
));
1709 * Normalize the make and model string...
1712 while (isspace(manufacturer
[0] & 255))
1713 _cups_strcpy(manufacturer
, manufacturer
+ 1);
1715 if (!strncasecmp(make_model
, manufacturer
, strlen(manufacturer
)))
1716 strlcpy(temp
, make_model
, sizeof(temp
));
1718 snprintf(temp
, sizeof(temp
), "%s %s", manufacturer
, make_model
);
1720 _ppdNormalizeMakeAndModel(temp
, make_model
, sizeof(make_model
));
1723 * See if we got a manufacturer...
1726 if (!manufacturer
[0] || !strcmp(manufacturer
, "ESP"))
1729 * Nope, copy the first part of the make and model then...
1732 strlcpy(manufacturer
, make_model
, sizeof(manufacturer
));
1735 * Truncate at the first space, dash, or slash, or make the
1736 * manufacturer "Other"...
1739 for (ptr
= manufacturer
; *ptr
; ptr
++)
1740 if (*ptr
== ' ' || *ptr
== '-' || *ptr
== '/')
1743 if (*ptr
&& ptr
> manufacturer
)
1746 strcpy(manufacturer
, "Other");
1748 else if (!strncasecmp(manufacturer
, "LHAG", 4) ||
1749 !strncasecmp(manufacturer
, "linotype", 8))
1750 strcpy(manufacturer
, "LHAG");
1751 else if (!strncasecmp(manufacturer
, "Hewlett", 7))
1752 strcpy(manufacturer
, "HP");
1755 * Fix the lang_version as needed...
1758 if ((ptr
= strchr(lang_version
, '-')) != NULL
)
1760 else if ((ptr
= strchr(lang_version
, '_')) != NULL
)
1766 * Setup the country suffix...
1770 _cups_strcpy(country
+ 1, ptr
);
1775 * No country suffix...
1781 for (i
= 0; i
< (int)(sizeof(languages
) / sizeof(languages
[0])); i
++)
1782 if (!strcasecmp(languages
[i
].version
, lang_version
))
1785 if (i
< (int)(sizeof(languages
) / sizeof(languages
[0])))
1788 * Found a known language...
1791 snprintf(lang_version
, sizeof(lang_version
), "%s%s",
1792 languages
[i
].language
, country
);
1797 * Unknown language; use "xx"...
1800 strcpy(lang_version
, "xx");
1804 * Record the PPD file...
1812 * Add new PPD file...
1815 fprintf(stderr
, "DEBUG2: [cups-driverd] Adding ppd \"%s\"...\n", name
);
1817 ppd
= add_ppd(name
, name
, lang_version
, manufacturer
, make_model
,
1818 device_id
, (char *)cupsArrayFirst(products
),
1819 (char *)cupsArrayFirst(psversions
),
1820 dent
->fileinfo
.st_mtime
, dent
->fileinfo
.st_size
,
1821 model_number
, type
, "file");
1832 * Update existing record...
1835 fprintf(stderr
, "DEBUG2: [cups-driverd] Updating ppd \"%s\"...\n", name
);
1837 memset(ppd
, 0, sizeof(ppd_info_t
));
1840 ppd
->record
.mtime
= dent
->fileinfo
.st_mtime
;
1841 ppd
->record
.size
= dent
->fileinfo
.st_size
;
1842 ppd
->record
.model_number
= model_number
;
1843 ppd
->record
.type
= type
;
1845 strlcpy(ppd
->record
.name
, name
, sizeof(ppd
->record
.name
));
1846 strlcpy(ppd
->record
.make
, manufacturer
, sizeof(ppd
->record
.make
));
1847 strlcpy(ppd
->record
.make_and_model
, make_model
,
1848 sizeof(ppd
->record
.make_and_model
));
1849 strlcpy(ppd
->record
.languages
[0], lang_version
,
1850 sizeof(ppd
->record
.languages
[0]));
1851 strlcpy(ppd
->record
.products
[0], (char *)cupsArrayFirst(products
),
1852 sizeof(ppd
->record
.products
[0]));
1853 strlcpy(ppd
->record
.psversions
[0], (char *)cupsArrayFirst(psversions
),
1854 sizeof(ppd
->record
.psversions
[0]));
1855 strlcpy(ppd
->record
.device_id
, device_id
, sizeof(ppd
->record
.device_id
));
1859 * Add remaining products, versions, and languages...
1863 i
< PPD_MAX_PROD
&& (ptr
= (char *)cupsArrayNext(products
)) != NULL
;
1865 strlcpy(ppd
->record
.products
[i
], ptr
,
1866 sizeof(ppd
->record
.products
[0]));
1869 i
< PPD_MAX_VERS
&& (ptr
= (char *)cupsArrayNext(psversions
)) != NULL
;
1871 strlcpy(ppd
->record
.psversions
[i
], ptr
,
1872 sizeof(ppd
->record
.psversions
[0]));
1874 for (i
= 1, ptr
= (char *)cupsArrayFirst(cups_languages
);
1875 i
< PPD_MAX_LANG
&& ptr
;
1876 i
++, ptr
= (char *)cupsArrayNext(cups_languages
))
1877 strlcpy(ppd
->record
.languages
[i
], ptr
,
1878 sizeof(ppd
->record
.languages
[0]));
1881 * Free products, versions, and languages...
1884 free_array(cups_languages
);
1885 free_array(products
);
1886 free_array(psversions
);
1898 * 'load_drv()' - Load the PPDs from a driver information file.
1901 static int /* O - 1 on success, 0 on failure */
1902 load_drv(const char *filename
, /* I - Actual filename */
1903 const char *name
, /* I - Name to the rest of the world */
1904 cups_file_t
*fp
, /* I - File to read from */
1905 time_t mtime
, /* I - Mod time of driver info file */
1906 off_t size
) /* I - Size of driver info file */
1908 ppdcSource
*src
; // Driver information file
1909 ppdcDriver
*d
; // Current driver
1910 ppdcAttr
*device_id
, // 1284DeviceID attribute
1911 *product
, // Current product value
1912 *ps_version
, // PSVersion attribute
1913 *cups_fax
, // cupsFax attribute
1914 *nick_name
; // NickName attribute
1915 ppdcFilter
*filter
; // Current filter
1916 ppd_info_t
*ppd
; // Current PPD
1917 int products_found
; // Number of products found
1918 char uri
[1024], // Driver URI
1919 make_model
[1024]; // Make and model
1920 int type
; // Driver type
1924 * Load the driver info file...
1927 src
= new ppdcSource(filename
, fp
);
1929 if (src
->drivers
->count
== 0)
1932 "ERROR: [cups-driverd] Bad driver information file \"%s\"!\n",
1939 * Add a dummy entry for the file...
1942 add_ppd(name
, name
, "", "", "", "", "", "", mtime
, size
, 0,
1943 PPD_TYPE_DRV
, "drv");
1947 * Then the drivers in the file...
1950 for (d
= (ppdcDriver
*)src
->drivers
->first();
1952 d
= (ppdcDriver
*)src
->drivers
->next())
1954 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "drv", "", "", 0,
1956 d
->file_name
? d
->file_name
->value
:
1957 d
->pc_file_name
->value
);
1959 device_id
= d
->find_attr("1284DeviceID", NULL
);
1960 ps_version
= d
->find_attr("PSVersion", NULL
);
1961 nick_name
= d
->find_attr("NickName", NULL
);
1964 strlcpy(make_model
, nick_name
->value
->value
, sizeof(make_model
));
1965 else if (strncasecmp(d
->model_name
->value
, d
->manufacturer
->value
,
1966 strlen(d
->manufacturer
->value
)))
1967 snprintf(make_model
, sizeof(make_model
), "%s %s, %s",
1968 d
->manufacturer
->value
, d
->model_name
->value
,
1971 snprintf(make_model
, sizeof(make_model
), "%s, %s", d
->model_name
->value
,
1974 if ((cups_fax
= d
->find_attr("cupsFax", NULL
)) != NULL
&&
1975 !strcasecmp(cups_fax
->value
->value
, "true"))
1976 type
= PPD_TYPE_FAX
;
1977 else if (d
->type
== PPDC_DRIVER_PS
)
1978 type
= PPD_TYPE_POSTSCRIPT
;
1979 else if (d
->type
!= PPDC_DRIVER_CUSTOM
)
1980 type
= PPD_TYPE_RASTER
;
1983 for (filter
= (ppdcFilter
*)d
->filters
->first(),
1984 type
= PPD_TYPE_POSTSCRIPT
;
1986 filter
= (ppdcFilter
*)d
->filters
->next())
1987 if (strcasecmp(filter
->mime_type
->value
, "application/vnd.cups-raster"))
1988 type
= PPD_TYPE_RASTER
;
1989 else if (strcasecmp(filter
->mime_type
->value
,
1990 "application/vnd.cups-pdf"))
1991 type
= PPD_TYPE_PDF
;
1994 for (product
= (ppdcAttr
*)d
->attrs
->first(), products_found
= 0,
1997 product
= (ppdcAttr
*)d
->attrs
->next())
1998 if (!strcmp(product
->name
->value
, "Product"))
2000 if (!products_found
)
2001 ppd
= add_ppd(name
, uri
, "en", d
->manufacturer
->value
, make_model
,
2002 device_id
? device_id
->value
->value
: "",
2003 product
->value
->value
,
2004 ps_version
? ps_version
->value
->value
: "(3010) 0",
2005 mtime
, size
, d
->model_number
, type
, "drv");
2006 else if (products_found
< PPD_MAX_PROD
)
2007 strlcpy(ppd
->record
.products
[products_found
], product
->value
->value
,
2008 sizeof(ppd
->record
.products
[0]));
2015 if (!products_found
)
2016 add_ppd(name
, uri
, "en", d
->manufacturer
->value
, make_model
,
2017 device_id
? device_id
->value
->value
: "",
2018 d
->model_name
->value
,
2019 ps_version
? ps_version
->value
->value
: "(3010) 0",
2020 mtime
, size
, d
->model_number
, type
, "drv");
2030 * 'load_drivers()' - Load driver-generated PPD files.
2033 static int /* O - 1 on success, 0 on failure */
2034 load_drivers(cups_array_t
*include
, /* I - Drivers to include */
2035 cups_array_t
*exclude
) /* I - Drivers to exclude */
2037 int i
; /* Looping var */
2038 char *start
, /* Start of value */
2039 *ptr
; /* Pointer into string */
2040 const char *server_bin
, /* CUPS_SERVERBIN env variable */
2041 *scheme
, /* Scheme for this driver */
2042 *scheme_end
; /* Pointer to end of scheme */
2043 char drivers
[1024]; /* Location of driver programs */
2044 int pid
; /* Process ID for driver program */
2045 cups_file_t
*fp
; /* Pipe to driver program */
2046 cups_dir_t
*dir
; /* Directory pointer */
2047 cups_dentry_t
*dent
; /* Directory entry */
2048 char *argv
[3], /* Arguments for command */
2049 filename
[1024], /* Name of driver */
2050 line
[2048], /* Line from driver */
2051 name
[512], /* ppd-name */
2052 make
[128], /* ppd-make */
2053 make_and_model
[128], /* ppd-make-and-model */
2054 device_id
[128], /* ppd-device-id */
2055 languages
[128], /* ppd-natural-language */
2056 product
[128], /* ppd-product */
2057 psversion
[128], /* ppd-psversion */
2058 type_str
[128]; /* ppd-type */
2059 int type
; /* PPD type */
2060 ppd_info_t
*ppd
; /* Newly added PPD */
2064 * Try opening the driver directory...
2067 if ((server_bin
= getenv("CUPS_SERVERBIN")) == NULL
)
2068 server_bin
= CUPS_SERVERBIN
;
2070 snprintf(drivers
, sizeof(drivers
), "%s/driver", server_bin
);
2072 if ((dir
= cupsDirOpen(drivers
)) == NULL
)
2074 fprintf(stderr
, "ERROR: [cups-driverd] Unable to open driver directory "
2076 drivers
, strerror(errno
));
2081 * Loop through all of the device drivers...
2084 argv
[1] = (char *)"list";
2087 while ((dent
= cupsDirRead(dir
)) != NULL
)
2090 * Only look at executable files...
2093 if (!(dent
->fileinfo
.st_mode
& 0111) || !S_ISREG(dent
->fileinfo
.st_mode
))
2097 * Include/exclude specific drivers...
2103 * Look for "scheme" or "scheme*" (prefix match), and skip any matches.
2106 for (scheme
= (char *)cupsArrayFirst(exclude
);
2108 scheme
= (char *)cupsArrayNext(exclude
))
2110 fprintf(stderr
, "DEBUG: [cups-driverd] Exclude \"%s\" with \"%s\"?\n",
2111 dent
->filename
, scheme
);
2112 scheme_end
= scheme
+ strlen(scheme
) - 1;
2114 if ((scheme_end
> scheme
&& *scheme_end
== '*' &&
2115 !strncmp(scheme
, dent
->filename
, scheme_end
- scheme
)) ||
2116 !strcmp(scheme
, dent
->filename
))
2118 fputs("DEBUG: [cups-driverd] Yes, exclude!\n", stderr
);
2130 * Look for "scheme" or "scheme*" (prefix match), and skip any non-matches.
2133 for (scheme
= (char *)cupsArrayFirst(include
);
2135 scheme
= (char *)cupsArrayNext(include
))
2137 fprintf(stderr
, "DEBUG: [cups-driverd] Include \"%s\" with \"%s\"?\n",
2138 dent
->filename
, scheme
);
2139 scheme_end
= scheme
+ strlen(scheme
) - 1;
2141 if ((scheme_end
> scheme
&& *scheme_end
== '*' &&
2142 !strncmp(scheme
, dent
->filename
, scheme_end
- scheme
)) ||
2143 !strcmp(scheme
, dent
->filename
))
2145 fputs("DEBUG: [cups-driverd] Yes, include!\n", stderr
);
2154 scheme
= dent
->filename
;
2157 * Run the driver with no arguments and collect the output...
2160 argv
[0] = dent
->filename
;
2161 snprintf(filename
, sizeof(filename
), "%s/%s", drivers
, dent
->filename
);
2163 if ((fp
= cupsdPipeCommand(&pid
, filename
, argv
, 0)) != NULL
)
2165 while (cupsFileGets(fp
, line
, sizeof(line
)))
2168 * Each line is of the form:
2170 * "ppd-name" ppd-natural-language "ppd-make" "ppd-make-and-model" \
2171 * "ppd-device-id" "ppd-product" "ppd-psversion"
2174 device_id
[0] = '\0';
2176 psversion
[0] = '\0';
2177 strcpy(type_str
, "postscript");
2179 if (sscanf(line
, "\"%511[^\"]\"%127s%*[ \t]\"%127[^\"]\""
2180 "%*[ \t]\"%127[^\"]\"%*[ \t]\"%127[^\"]\""
2181 "%*[ \t]\"%127[^\"]\"%*[ \t]\"%127[^\"]\""
2182 "%*[ \t]\"%127[^\"]\"",
2183 name
, languages
, make
, make_and_model
,
2184 device_id
, product
, psversion
, type_str
) < 4)
2187 * Bad format; strip trailing newline and write an error message.
2190 if (line
[strlen(line
) - 1] == '\n')
2191 line
[strlen(line
) - 1] = '\0';
2193 fprintf(stderr
, "ERROR: [cups-driverd] Bad line from \"%s\": %s\n",
2194 dent
->filename
, line
);
2200 * Add the device to the array of available devices...
2203 if ((start
= strchr(languages
, ',')) != NULL
)
2207 type
< (int)(sizeof(ppd_types
) / sizeof(ppd_types
[0]));
2209 if (!strcmp(type_str
, ppd_types
[type
]))
2212 if (type
>= (int)(sizeof(ppd_types
) / sizeof(ppd_types
[0])))
2215 "ERROR: [cups-driverd] Bad ppd-type \"%s\" ignored!\n",
2217 type
= PPD_TYPE_UNKNOWN
;
2220 ppd
= add_ppd(filename
, name
, languages
, make
, make_and_model
,
2221 device_id
, product
, psversion
, 0, 0, 0, type
, scheme
);
2230 if (start
&& *start
)
2232 for (i
= 1; i
< PPD_MAX_LANG
&& *start
; i
++)
2234 if ((ptr
= strchr(start
, ',')) != NULL
)
2237 ptr
= start
+ strlen(start
);
2239 strlcpy(ppd
->record
.languages
[i
], start
,
2240 sizeof(ppd
->record
.languages
[0]));
2246 fprintf(stderr
, "DEBUG2: [cups-driverd] Added dynamic PPD \"%s\"...\n",
2254 fprintf(stderr
, "WARNING: [cups-driverd] Unable to execute \"%s\": %s\n",
2255 filename
, strerror(errno
));
2265 * 'load_ppds_dat()' - Load the ppds.dat file.
2269 load_ppds_dat(char *filename
, /* I - Filename buffer */
2270 size_t filesize
, /* I - Size of filename buffer */
2271 int verbose
) /* I - Be verbose? */
2273 ppd_info_t
*ppd
; /* Current PPD file */
2274 cups_file_t
*fp
; /* ppds.dat file */
2275 struct stat fileinfo
; /* ppds.dat information */
2276 const char *cups_cachedir
; /* CUPS_CACHEDIR environment variable */
2279 PPDsByName
= cupsArrayNew((cups_array_func_t
)compare_names
, NULL
);
2280 PPDsByMakeModel
= cupsArrayNew((cups_array_func_t
)compare_ppds
, NULL
);
2283 if ((cups_cachedir
= getenv("CUPS_CACHEDIR")) == NULL
)
2284 cups_cachedir
= CUPS_CACHEDIR
;
2286 snprintf(filename
, filesize
, "%s/ppds.dat", cups_cachedir
);
2287 if ((fp
= cupsFileOpen(filename
, "r")) != NULL
)
2290 * See if we have the right sync word...
2293 unsigned ppdsync
; /* Sync word */
2294 int num_ppds
; /* Number of PPDs */
2297 if (cupsFileRead(fp
, (char *)&ppdsync
, sizeof(ppdsync
))
2298 == sizeof(ppdsync
) &&
2299 ppdsync
== PPD_SYNC
&&
2300 !stat(filename
, &fileinfo
) &&
2301 ((fileinfo
.st_size
- sizeof(ppdsync
)) % sizeof(ppd_rec_t
)) == 0 &&
2302 (num_ppds
= (fileinfo
.st_size
- sizeof(ppdsync
)) /
2303 sizeof(ppd_rec_t
)) > 0)
2306 * We have a ppds.dat file, so read it!
2309 for (; num_ppds
> 0; num_ppds
--)
2311 if ((ppd
= (ppd_info_t
*)calloc(1, sizeof(ppd_info_t
))) == NULL
)
2314 fputs("ERROR: [cups-driverd] Unable to allocate memory for PPD!\n",
2319 if (cupsFileRead(fp
, (char *)&(ppd
->record
), sizeof(ppd_rec_t
)) > 0)
2321 cupsArrayAdd(PPDsByName
, ppd
);
2322 cupsArrayAdd(PPDsByMakeModel
, ppd
);
2332 fprintf(stderr
, "INFO: [cups-driverd] Read \"%s\", %d PPDs...\n",
2333 filename
, cupsArrayCount(PPDsByName
));
2342 * 'regex_device_id()' - Compile a regular expression based on the 1284 device
2346 static regex_t
* /* O - Regular expression */
2347 regex_device_id(const char *device_id
) /* I - IEEE-1284 device ID */
2349 char res
[2048], /* Regular expression string */
2350 *ptr
; /* Pointer into string */
2351 regex_t
*re
; /* Regular expression */
2352 int cmd
; /* Command set string? */
2355 fprintf(stderr
, "DEBUG: [cups-driverd] regex_device_id(\"%s\")\n", device_id
);
2358 * Scan the device ID string and insert class, command set, manufacturer, and
2359 * model attributes to match. We assume that the device ID in the PPD and the
2360 * device ID reported by the device itself use the same attribute names and
2361 * order of attributes.
2366 while (*device_id
&& ptr
< (res
+ sizeof(res
) - 6))
2368 cmd
= !strncasecmp(device_id
, "COMMAND SET:", 12) ||
2369 !strncasecmp(device_id
, "CMD:", 4);
2371 if (cmd
|| !strncasecmp(device_id
, "MANUFACTURER:", 13) ||
2372 !strncasecmp(device_id
, "MFG:", 4) ||
2373 !strncasecmp(device_id
, "MFR:", 4) ||
2374 !strncasecmp(device_id
, "MODEL:", 6) ||
2375 !strncasecmp(device_id
, "MDL:", 4))
2385 while (*device_id
&& *device_id
!= ';' && ptr
< (res
+ sizeof(res
) - 4))
2387 if (strchr("[]{}().*\\|", *device_id
))
2389 *ptr
++ = *device_id
++;
2392 if (*device_id
== ';' || !*device_id
)
2398 else if ((device_id
= strchr(device_id
, ';')) == NULL
)
2406 fprintf(stderr
, "DEBUG: [cups-driverd] regex_device_id: \"%s\"\n", res
);
2409 * Compile the regular expression and return...
2412 if (res
[0] && (re
= (regex_t
*)calloc(1, sizeof(regex_t
))) != NULL
)
2414 if (!regcomp(re
, res
, REG_EXTENDED
| REG_ICASE
))
2416 fputs("DEBUG: [cups-driverd] regex_device_id: OK\n", stderr
);
2428 * 'regex_string()' - Construct a regular expression to compare a simple string.
2431 static regex_t
* /* O - Regular expression */
2432 regex_string(const char *s
) /* I - String to compare */
2434 char res
[2048], /* Regular expression string */
2435 *ptr
; /* Pointer into string */
2436 regex_t
*re
; /* Regular expression */
2439 fprintf(stderr
, "DEBUG: [cups-driverd] regex_string(\"%s\")\n", s
);
2442 * Convert the string to a regular expression, escaping special characters
2448 while (*s
&& ptr
< (res
+ sizeof(res
) - 2))
2450 if (strchr("[]{}().*\\", *s
))
2458 fprintf(stderr
, "DEBUG: [cups-driverd] regex_string: \"%s\"\n", res
);
2461 * Create a case-insensitive regular expression...
2464 if (res
[0] && (re
= (regex_t
*)calloc(1, sizeof(regex_t
))) != NULL
)
2466 if (!regcomp(re
, res
, REG_ICASE
))
2468 fputs("DEBUG: [cups-driverd] regex_string: OK\n", stderr
);