]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $" | |
3 | * | |
4 | * Printer routines for the CUPS scheduler. | |
5 | * | |
6 | * Copyright 2007-2012 by Apple Inc. | |
7 | * Copyright 1997-2007 by Easy Software Products, all rights reserved. | |
8 | * | |
9 | * These coded instructions, statements, and computer programs are the | |
10 | * property of Apple Inc. and are protected by Federal copyright | |
11 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
12 | * which should have been included with this file. If this file is | |
13 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
14 | * | |
15 | * Contents: | |
16 | * | |
17 | * cupsdAddPrinter() - Add a printer to the system. | |
18 | * cupsdCreateCommonData() - Create the common printer data. | |
19 | * cupsdDeleteAllPrinters() - Delete all printers from the system. | |
20 | * cupsdDeletePrinter() - Delete a printer from the system. | |
21 | * cupsdFindDest() - Find a destination in the list. | |
22 | * cupsdFindPrinter() - Find a printer in the list. | |
23 | * cupsdLoadAllPrinters() - Load printers from the printers.conf file. | |
24 | * cupsdRenamePrinter() - Rename a printer. | |
25 | * cupsdSaveAllPrinters() - Save all printer definitions to the | |
26 | * printers.conf file. | |
27 | * cupsdSetAuthInfoRequired() - Set the required authentication info. | |
28 | * cupsdSetDeviceURI() - Set the device URI for a printer. | |
29 | * cupsdSetPrinterAttr() - Set a printer attribute. | |
30 | * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD | |
31 | * file. | |
32 | * cupsdSetPrinterReasons() - Set/update the reasons strings. | |
33 | * cupsdSetPrinterState() - Update the current state of a printer. | |
34 | * cupsdStopPrinter() - Stop a printer from printing any jobs... | |
35 | * cupsdUpdatePrinterPPD() - Update keywords in a printer's PPD file. | |
36 | * cupsdUpdatePrinters() - Update printers after a partial reload. | |
37 | * cupsdValidateDest() - Validate a printer/class destination. | |
38 | * cupsdWritePrintcap() - Write a pseudo-printcap file for older | |
39 | * applications that need it... | |
40 | * add_printer_defaults() - Add name-default attributes to the printer | |
41 | * attributes. | |
42 | * add_printer_filter() - Add a MIME filter for a printer. | |
43 | * add_printer_formats() - Add document-format-supported values for a | |
44 | * printer. | |
45 | * compare_printers() - Compare two printers. | |
46 | * delete_printer_filters() - Delete all MIME filters for a printer. | |
47 | * dirty_printer() - Mark config and state files dirty for the | |
48 | * specified printer. | |
49 | * load_ppd() - Load a cached PPD file, updating the cache as | |
50 | * needed. | |
51 | * new_media_col() - Create a media-col collection value. | |
52 | * write_irix_config() - Update the config files used by the IRIX | |
53 | * desktop tools. | |
54 | * write_irix_state() - Update the status files used by IRIX printing | |
55 | * desktop tools. | |
56 | * write_xml_string() - Write a string with XML escaping. | |
57 | */ | |
58 | ||
59 | /* | |
60 | * Include necessary headers... | |
61 | */ | |
62 | ||
63 | #include "cupsd.h" | |
64 | #include <cups/dir.h> | |
65 | #ifdef HAVE_APPLICATIONSERVICES_H | |
66 | # include <ApplicationServices/ApplicationServices.h> | |
67 | #endif /* HAVE_APPLICATIONSERVICES_H */ | |
68 | #ifdef HAVE_SYS_MOUNT_H | |
69 | # include <sys/mount.h> | |
70 | #endif /* HAVE_SYS_MOUNT_H */ | |
71 | #ifdef HAVE_SYS_STATVFS_H | |
72 | # include <sys/statvfs.h> | |
73 | #elif defined(HAVE_SYS_STATFS_H) | |
74 | # include <sys/statfs.h> | |
75 | #endif /* HAVE_SYS_STATVFS_H */ | |
76 | #ifdef HAVE_SYS_VFS_H | |
77 | # include <sys/vfs.h> | |
78 | #endif /* HAVE_SYS_VFS_H */ | |
79 | #ifdef __APPLE__ | |
80 | # include <asl.h> | |
81 | #endif /* __APPLE__ */ | |
82 | ||
83 | ||
84 | /* | |
85 | * Local functions... | |
86 | */ | |
87 | ||
88 | static void add_printer_defaults(cupsd_printer_t *p); | |
89 | static void add_printer_filter(cupsd_printer_t *p, mime_type_t *type, | |
90 | const char *filter); | |
91 | static void add_printer_formats(cupsd_printer_t *p); | |
92 | static int compare_printers(void *first, void *second, void *data); | |
93 | static void delete_printer_filters(cupsd_printer_t *p); | |
94 | static void dirty_printer(cupsd_printer_t *p); | |
95 | static void load_ppd(cupsd_printer_t *p); | |
96 | static void log_ipp_conformance(cupsd_printer_t *p, const char *reason); | |
97 | static ipp_t *new_media_col(_pwg_size_t *size, const char *source, | |
98 | const char *type); | |
99 | #ifdef __sgi | |
100 | static void write_irix_config(cupsd_printer_t *p); | |
101 | static void write_irix_state(cupsd_printer_t *p); | |
102 | #endif /* __sgi */ | |
103 | static void write_xml_string(cups_file_t *fp, const char *s); | |
104 | ||
105 | ||
106 | /* | |
107 | * 'cupsdAddPrinter()' - Add a printer to the system. | |
108 | */ | |
109 | ||
110 | cupsd_printer_t * /* O - New printer */ | |
111 | cupsdAddPrinter(const char *name) /* I - Name of printer */ | |
112 | { | |
113 | cupsd_printer_t *p; /* New printer */ | |
114 | char uri[1024], /* Printer URI */ | |
115 | uuid[64]; /* Printer UUID */ | |
116 | ||
117 | ||
118 | /* | |
119 | * Range check input... | |
120 | */ | |
121 | ||
122 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdAddPrinter(\"%s\")", name); | |
123 | ||
124 | /* | |
125 | * Create a new printer entity... | |
126 | */ | |
127 | ||
128 | if ((p = calloc(1, sizeof(cupsd_printer_t))) == NULL) | |
129 | { | |
130 | cupsdLogMessage(CUPSD_LOG_CRIT, "Unable to allocate memory for printer - %s", | |
131 | strerror(errno)); | |
132 | return (NULL); | |
133 | } | |
134 | ||
135 | cupsdSetString(&p->name, name); | |
136 | cupsdSetString(&p->info, name); | |
137 | cupsdSetString(&p->hostname, ServerName); | |
138 | ||
139 | httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, | |
140 | ServerName, RemotePort, "/printers/%s", name); | |
141 | cupsdSetString(&p->uri, uri); | |
142 | cupsdSetString(&p->uuid, _httpAssembleUUID(ServerName, RemotePort, name, 0, | |
143 | uuid, sizeof(uuid))); | |
144 | cupsdSetDeviceURI(p, "file:///dev/null"); | |
145 | ||
146 | p->state = IPP_PRINTER_STOPPED; | |
147 | p->state_time = time(NULL); | |
148 | p->accepting = 0; | |
149 | p->shared = DefaultShared; | |
150 | p->filetype = mimeAddType(MimeDatabase, "printer", name); | |
151 | ||
152 | cupsdSetString(&p->job_sheets[0], "none"); | |
153 | cupsdSetString(&p->job_sheets[1], "none"); | |
154 | ||
155 | cupsdSetString(&p->error_policy, ErrorPolicy); | |
156 | cupsdSetString(&p->op_policy, DefaultPolicy); | |
157 | ||
158 | p->op_policy_ptr = DefaultPolicyPtr; | |
159 | ||
160 | /* | |
161 | * Insert the printer in the printer list alphabetically... | |
162 | */ | |
163 | ||
164 | if (!Printers) | |
165 | Printers = cupsArrayNew(compare_printers, NULL); | |
166 | ||
167 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
168 | "cupsdAddPrinter: Adding %s to Printers", p->name); | |
169 | cupsArrayAdd(Printers, p); | |
170 | ||
171 | /* | |
172 | * Return the new printer... | |
173 | */ | |
174 | ||
175 | return (p); | |
176 | } | |
177 | ||
178 | ||
179 | /* | |
180 | * 'cupsdCreateCommonData()' - Create the common printer data. | |
181 | */ | |
182 | ||
183 | void | |
184 | cupsdCreateCommonData(void) | |
185 | { | |
186 | int i; /* Looping var */ | |
187 | ipp_attribute_t *attr; /* Attribute data */ | |
188 | cups_dir_t *dir; /* Notifier directory */ | |
189 | cups_dentry_t *dent; /* Notifier directory entry */ | |
190 | cups_array_t *notifiers; /* Notifier array */ | |
191 | char filename[1024], /* Filename */ | |
192 | *notifier; /* Current notifier */ | |
193 | cupsd_policy_t *p; /* Current policy */ | |
194 | int k_supported; /* Maximum file size supported */ | |
195 | #ifdef HAVE_STATVFS | |
196 | struct statvfs spoolinfo; /* FS info for spool directory */ | |
197 | double spoolsize; /* FS size */ | |
198 | #elif defined(HAVE_STATFS) | |
199 | struct statfs spoolinfo; /* FS info for spool directory */ | |
200 | double spoolsize; /* FS size */ | |
201 | #endif /* HAVE_STATVFS */ | |
202 | static const int nups[] = /* number-up-supported values */ | |
203 | { 1, 2, 4, 6, 9, 16 }; | |
204 | static const int orients[4] =/* orientation-requested-supported values */ | |
205 | { | |
206 | IPP_PORTRAIT, | |
207 | IPP_LANDSCAPE, | |
208 | IPP_REVERSE_LANDSCAPE, | |
209 | IPP_REVERSE_PORTRAIT | |
210 | }; | |
211 | static const char * const holds[] = /* job-hold-until-supported values */ | |
212 | { | |
213 | "no-hold", | |
214 | "indefinite", | |
215 | "day-time", | |
216 | "evening", | |
217 | "night", | |
218 | "second-shift", | |
219 | "third-shift", | |
220 | "weekend" | |
221 | }; | |
222 | static const char * const versions[] =/* ipp-versions-supported values */ | |
223 | { | |
224 | "1.0", | |
225 | "1.1", | |
226 | "2.0", | |
227 | "2.1" | |
228 | }; | |
229 | static const int ops[] = /* operations-supported values */ | |
230 | { | |
231 | IPP_PRINT_JOB, | |
232 | IPP_VALIDATE_JOB, | |
233 | IPP_CREATE_JOB, | |
234 | IPP_SEND_DOCUMENT, | |
235 | IPP_CANCEL_JOB, | |
236 | IPP_GET_JOB_ATTRIBUTES, | |
237 | IPP_GET_JOBS, | |
238 | IPP_GET_PRINTER_ATTRIBUTES, | |
239 | IPP_HOLD_JOB, | |
240 | IPP_RELEASE_JOB, | |
241 | IPP_RESTART_JOB, | |
242 | IPP_PAUSE_PRINTER, | |
243 | IPP_RESUME_PRINTER, | |
244 | IPP_PURGE_JOBS, | |
245 | IPP_SET_PRINTER_ATTRIBUTES, | |
246 | IPP_SET_JOB_ATTRIBUTES, | |
247 | IPP_GET_PRINTER_SUPPORTED_VALUES, | |
248 | IPP_CREATE_PRINTER_SUBSCRIPTION, | |
249 | IPP_CREATE_JOB_SUBSCRIPTION, | |
250 | IPP_GET_SUBSCRIPTION_ATTRIBUTES, | |
251 | IPP_GET_SUBSCRIPTIONS, | |
252 | IPP_RENEW_SUBSCRIPTION, | |
253 | IPP_CANCEL_SUBSCRIPTION, | |
254 | IPP_GET_NOTIFICATIONS, | |
255 | IPP_ENABLE_PRINTER, | |
256 | IPP_DISABLE_PRINTER, | |
257 | IPP_HOLD_NEW_JOBS, | |
258 | IPP_RELEASE_HELD_NEW_JOBS, | |
259 | IPP_CANCEL_JOBS, | |
260 | IPP_CANCEL_MY_JOBS, | |
261 | IPP_CLOSE_JOB, | |
262 | CUPS_GET_DEFAULT, | |
263 | CUPS_GET_PRINTERS, | |
264 | CUPS_ADD_PRINTER, | |
265 | CUPS_DELETE_PRINTER, | |
266 | CUPS_GET_CLASSES, | |
267 | CUPS_ADD_CLASS, | |
268 | CUPS_DELETE_CLASS, | |
269 | CUPS_ACCEPT_JOBS, | |
270 | CUPS_REJECT_JOBS, | |
271 | CUPS_SET_DEFAULT, | |
272 | CUPS_GET_DEVICES, | |
273 | CUPS_GET_PPDS, | |
274 | CUPS_MOVE_JOB, | |
275 | CUPS_AUTHENTICATE_JOB, | |
276 | CUPS_GET_PPD, | |
277 | CUPS_GET_DOCUMENT, | |
278 | IPP_RESTART_JOB | |
279 | }; | |
280 | static const char * const charsets[] =/* charset-supported values */ | |
281 | { | |
282 | "us-ascii", | |
283 | "utf-8" | |
284 | }; | |
285 | static const char * const compressions[] = | |
286 | { /* document-compression-supported values */ | |
287 | "none" | |
288 | #ifdef HAVE_LIBZ | |
289 | ,"gzip" | |
290 | #endif /* HAVE_LIBZ */ | |
291 | }; | |
292 | static const char * const media_col_supported[] = | |
293 | { /* media-col-supported values */ | |
294 | "media-bottom-margin", | |
295 | "media-left-margin", | |
296 | "media-right-margin", | |
297 | "media-size", | |
298 | "media-source", | |
299 | "media-top-margin", | |
300 | "media-type" | |
301 | }; | |
302 | static const char * const multiple_document_handling[] = | |
303 | { /* multiple-document-handling-supported values */ | |
304 | "separate-documents-uncollated-copies", | |
305 | "separate-documents-collated-copies" | |
306 | }; | |
307 | static const char * const notify_attrs[] = | |
308 | { /* notify-attributes-supported values */ | |
309 | "printer-state-change-time", | |
310 | "notify-lease-expiration-time", | |
311 | "notify-subscriber-user-name" | |
312 | }; | |
313 | static const char * const notify_events[] = | |
314 | { /* notify-events-supported values */ | |
315 | "job-completed", | |
316 | "job-config-changed", | |
317 | "job-created", | |
318 | "job-progress", | |
319 | "job-state-changed", | |
320 | "job-stopped", | |
321 | "printer-added", | |
322 | "printer-changed", | |
323 | "printer-config-changed", | |
324 | "printer-deleted", | |
325 | "printer-finishings-changed", | |
326 | "printer-media-changed", | |
327 | "printer-modified", | |
328 | "printer-restarted", | |
329 | "printer-shutdown", | |
330 | "printer-state-changed", | |
331 | "printer-stopped", | |
332 | "server-audit", | |
333 | "server-restarted", | |
334 | "server-started", | |
335 | "server-stopped" | |
336 | }; | |
337 | static const char * const job_creation[] = | |
338 | { /* job-creation-attributes-supported */ | |
339 | "copies", | |
340 | "finishings", | |
341 | "ipp-attribute-fidelity", | |
342 | "job-hold-until", | |
343 | "job-name", | |
344 | "job-priority", | |
345 | "job-sheets", | |
346 | "media", | |
347 | "media-col", | |
348 | "multiple-document-handling", | |
349 | "number-up", | |
350 | "output-bin", | |
351 | "output-mode", | |
352 | "orientation-requested", | |
353 | "page-ranges", | |
354 | "print-quality", | |
355 | "printer-resolution", | |
356 | "sides" | |
357 | }; | |
358 | static const char * const job_settable[] = | |
359 | { /* job-settable-attributes-supported */ | |
360 | "copies", | |
361 | "finishings", | |
362 | "job-hold-until", | |
363 | "job-name", | |
364 | "job-priority", | |
365 | "media", | |
366 | "media-col", | |
367 | "multiple-document-handling", | |
368 | "number-up", | |
369 | "output-bin", | |
370 | "output-mode", | |
371 | "orientation-requested", | |
372 | "page-ranges", | |
373 | "print-quality", | |
374 | "printer-resolution", | |
375 | "sides" | |
376 | }; | |
377 | static const char * const pdf_versions[] = | |
378 | { /* pdf-versions-supported */ | |
379 | "adobe-1.2", | |
380 | "adobe-1.3", | |
381 | "adobe-1.4", | |
382 | "adobe-1.5", | |
383 | "adobe-1.6", | |
384 | "adobe-1.7", | |
385 | "iso-19005-1_2005", | |
386 | "iso-32000-1_2008", | |
387 | "pwg-5102.3" | |
388 | }; | |
389 | static const char * const printer_settable[] = | |
390 | { /* printer-settable-attributes-supported */ | |
391 | "printer-info", | |
392 | "printer-location" | |
393 | }; | |
394 | static const char * const which_jobs[] = | |
395 | { /* which-jobs-supported values */ | |
396 | "completed", | |
397 | "not-completed", | |
398 | "aborted", | |
399 | "all", | |
400 | "canceled", | |
401 | "pending", | |
402 | "pending-held", | |
403 | "processing", | |
404 | "processing-stopped" | |
405 | }; | |
406 | ||
407 | ||
408 | if (CommonData) | |
409 | ippDelete(CommonData); | |
410 | ||
411 | CommonData = ippNew(); | |
412 | ||
413 | /* | |
414 | * Get the maximum spool size based on the size of the filesystem used for | |
415 | * the RequestRoot directory. If the host OS doesn't support the statfs call | |
416 | * or the filesystem is larger than 2TiB, always report INT_MAX. | |
417 | */ | |
418 | ||
419 | #ifdef HAVE_STATVFS | |
420 | if (statvfs(RequestRoot, &spoolinfo)) | |
421 | k_supported = INT_MAX; | |
422 | else if ((spoolsize = (double)spoolinfo.f_frsize * spoolinfo.f_blocks / 1024) > | |
423 | INT_MAX) | |
424 | k_supported = INT_MAX; | |
425 | else | |
426 | k_supported = (int)spoolsize; | |
427 | ||
428 | #elif defined(HAVE_STATFS) | |
429 | if (statfs(RequestRoot, &spoolinfo)) | |
430 | k_supported = INT_MAX; | |
431 | else if ((spoolsize = (double)spoolinfo.f_bsize * spoolinfo.f_blocks / 1024) > | |
432 | INT_MAX) | |
433 | k_supported = INT_MAX; | |
434 | else | |
435 | k_supported = (int)spoolsize; | |
436 | ||
437 | #else | |
438 | k_supported = INT_MAX; | |
439 | #endif /* HAVE_STATVFS */ | |
440 | ||
441 | /* | |
442 | * This list of attributes is sorted to improve performance when the | |
443 | * client provides a requested-attributes attribute... | |
444 | */ | |
445 | ||
446 | /* charset-configured */ | |
447 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET | IPP_TAG_COPY, | |
448 | "charset-configured", NULL, "utf-8"); | |
449 | ||
450 | /* charset-supported */ | |
451 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET | IPP_TAG_COPY, | |
452 | "charset-supported", sizeof(charsets) / sizeof(charsets[0]), | |
453 | NULL, charsets); | |
454 | ||
455 | /* compression-supported */ | |
456 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
457 | "compression-supported", | |
458 | sizeof(compressions) / sizeof(compressions[0]), | |
459 | NULL, compressions); | |
460 | ||
461 | /* copies-supported */ | |
462 | ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies); | |
463 | ||
464 | /* cups-version */ | |
465 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_TEXT | IPP_TAG_COPY, | |
466 | "cups-version", NULL, CUPS_SVERSION + 6); | |
467 | ||
468 | /* generated-natural-language-supported (no IPP_TAG_COPY) */ | |
469 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE, | |
470 | "generated-natural-language-supported", NULL, DefaultLanguage); | |
471 | ||
472 | /* ipp-versions-supported */ | |
473 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
474 | "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]), | |
475 | NULL, versions); | |
476 | ||
477 | /* ippget-event-life */ | |
478 | ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
479 | "ippget-event-life", 15); | |
480 | ||
481 | /* job-creation-attributes-supported */ | |
482 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
483 | "job-creation-attributes-supported", | |
484 | sizeof(job_creation) / sizeof(job_creation[0]), | |
485 | NULL, job_creation); | |
486 | ||
487 | /* job-hold-until-supported */ | |
488 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
489 | "job-hold-until-supported", sizeof(holds) / sizeof(holds[0]), | |
490 | NULL, holds); | |
491 | ||
492 | /* job-ids-supported */ | |
493 | ippAddBoolean(CommonData, IPP_TAG_PRINTER, "job-ids-supported", 1); | |
494 | ||
495 | /* job-k-octets-supported */ | |
496 | ippAddRange(CommonData, IPP_TAG_PRINTER, "job-k-octets-supported", 0, | |
497 | k_supported); | |
498 | ||
499 | /* job-priority-supported */ | |
500 | ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
501 | "job-priority-supported", 100); | |
502 | ||
503 | /* job-settable-attributes-supported */ | |
504 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
505 | "job-settable-attributes-supported", | |
506 | sizeof(job_settable) / sizeof(job_settable[0]), | |
507 | NULL, job_settable); | |
508 | ||
509 | /* job-sheets-supported */ | |
510 | if (cupsArrayCount(Banners) > 0) | |
511 | { | |
512 | /* | |
513 | * Setup the job-sheets-supported attribute... | |
514 | */ | |
515 | ||
516 | if (Classification && !ClassifyOverride) | |
517 | attr = ippAddString(CommonData, IPP_TAG_PRINTER, | |
518 | IPP_TAG_NAME | IPP_TAG_COPY, | |
519 | "job-sheets-supported", NULL, Classification); | |
520 | else | |
521 | attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, | |
522 | IPP_TAG_NAME | IPP_TAG_COPY, | |
523 | "job-sheets-supported", cupsArrayCount(Banners) + 1, | |
524 | NULL, NULL); | |
525 | ||
526 | if (attr == NULL) | |
527 | cupsdLogMessage(CUPSD_LOG_EMERG, | |
528 | "Unable to allocate memory for " | |
529 | "job-sheets-supported attribute: %s!", strerror(errno)); | |
530 | else if (!Classification || ClassifyOverride) | |
531 | { | |
532 | cupsd_banner_t *banner; /* Current banner */ | |
533 | ||
534 | ||
535 | attr->values[0].string.text = _cupsStrAlloc("none"); | |
536 | ||
537 | for (i = 1, banner = (cupsd_banner_t *)cupsArrayFirst(Banners); | |
538 | banner; | |
539 | i ++, banner = (cupsd_banner_t *)cupsArrayNext(Banners)) | |
540 | attr->values[i].string.text = banner->name; | |
541 | } | |
542 | } | |
543 | else | |
544 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY, | |
545 | "job-sheets-supported", NULL, "none"); | |
546 | ||
547 | /* jpeg-k-octets-supported */ | |
548 | ippAddRange(CommonData, IPP_TAG_PRINTER, "jpeg-k-octets-supported", 0, | |
549 | k_supported); | |
550 | ||
551 | /* jpeg-x-dimension-supported */ | |
552 | ippAddRange(CommonData, IPP_TAG_PRINTER, "jpeg-x-dimension-supported", 0, | |
553 | 65535); | |
554 | ||
555 | /* jpeg-y-dimension-supported */ | |
556 | ippAddRange(CommonData, IPP_TAG_PRINTER, "jpeg-y-dimension-supported", 1, | |
557 | 65535); | |
558 | ||
559 | /* media-col-supported */ | |
560 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
561 | "media-col-supported", | |
562 | sizeof(media_col_supported) / | |
563 | sizeof(media_col_supported[0]), NULL, | |
564 | media_col_supported); | |
565 | ||
566 | /* multiple-document-handling-supported */ | |
567 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
568 | "multiple-document-handling-supported", | |
569 | sizeof(multiple_document_handling) / | |
570 | sizeof(multiple_document_handling[0]), NULL, | |
571 | multiple_document_handling); | |
572 | ||
573 | /* multiple-document-jobs-supported */ | |
574 | ippAddBoolean(CommonData, IPP_TAG_PRINTER, | |
575 | "multiple-document-jobs-supported", 1); | |
576 | ||
577 | /* multiple-operation-time-out */ | |
578 | ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
579 | "multiple-operation-time-out", MultipleOperationTimeout); | |
580 | ||
581 | /* natural-language-configured (no IPP_TAG_COPY) */ | |
582 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE, | |
583 | "natural-language-configured", NULL, DefaultLanguage); | |
584 | ||
585 | /* notify-attributes-supported */ | |
586 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
587 | "notify-attributes-supported", | |
588 | (int)(sizeof(notify_attrs) / sizeof(notify_attrs[0])), | |
589 | NULL, notify_attrs); | |
590 | ||
591 | /* notify-lease-duration-supported */ | |
592 | ippAddRange(CommonData, IPP_TAG_PRINTER, | |
593 | "notify-lease-duration-supported", 0, | |
594 | MaxLeaseDuration ? MaxLeaseDuration : 2147483647); | |
595 | ||
596 | /* notify-max-events-supported */ | |
597 | ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
598 | "notify-max-events-supported", MaxEvents); | |
599 | ||
600 | /* notify-events-supported */ | |
601 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
602 | "notify-events-supported", | |
603 | (int)(sizeof(notify_events) / sizeof(notify_events[0])), | |
604 | NULL, notify_events); | |
605 | ||
606 | /* notify-pull-method-supported */ | |
607 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
608 | "notify-pull-method-supported", NULL, "ippget"); | |
609 | ||
610 | /* notify-schemes-supported */ | |
611 | snprintf(filename, sizeof(filename), "%s/notifier", ServerBin); | |
612 | if ((dir = cupsDirOpen(filename)) != NULL) | |
613 | { | |
614 | notifiers = cupsArrayNew((cups_array_func_t)strcmp, NULL); | |
615 | ||
616 | while ((dent = cupsDirRead(dir)) != NULL) | |
617 | if (S_ISREG(dent->fileinfo.st_mode) && | |
618 | (dent->fileinfo.st_mode & S_IXOTH) != 0) | |
619 | cupsArrayAdd(notifiers, _cupsStrAlloc(dent->filename)); | |
620 | ||
621 | if (cupsArrayCount(notifiers) > 0) | |
622 | { | |
623 | attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
624 | "notify-schemes-supported", | |
625 | cupsArrayCount(notifiers), NULL, NULL); | |
626 | ||
627 | for (i = 0, notifier = (char *)cupsArrayFirst(notifiers); | |
628 | notifier; | |
629 | i ++, notifier = (char *)cupsArrayNext(notifiers)) | |
630 | attr->values[i].string.text = notifier; | |
631 | } | |
632 | ||
633 | cupsArrayDelete(notifiers); | |
634 | cupsDirClose(dir); | |
635 | } | |
636 | ||
637 | /* number-up-supported */ | |
638 | ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
639 | "number-up-supported", sizeof(nups) / sizeof(nups[0]), nups); | |
640 | ||
641 | /* operations-supported */ | |
642 | ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
643 | "operations-supported", | |
644 | sizeof(ops) / sizeof(ops[0]) + JobFiles - 1, ops); | |
645 | ||
646 | /* orientation-requested-supported */ | |
647 | ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
648 | "orientation-requested-supported", 4, orients); | |
649 | ||
650 | /* page-ranges-supported */ | |
651 | ippAddBoolean(CommonData, IPP_TAG_PRINTER, "page-ranges-supported", 1); | |
652 | ||
653 | /* pdf-k-octets-supported */ | |
654 | ippAddRange(CommonData, IPP_TAG_PRINTER, "pdf-k-octets-supported", 0, | |
655 | k_supported); | |
656 | ||
657 | /* pdf-versions-supported */ | |
658 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
659 | "pdf-versions-supported", | |
660 | sizeof(pdf_versions) / sizeof(pdf_versions[0]), NULL, | |
661 | pdf_versions); | |
662 | ||
663 | /* pdl-override-supported */ | |
664 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
665 | "pdl-override-supported", NULL, "attempted"); | |
666 | ||
667 | /* printer-op-policy-supported */ | |
668 | attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY, | |
669 | "printer-op-policy-supported", cupsArrayCount(Policies), | |
670 | NULL, NULL); | |
671 | for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies); | |
672 | p; | |
673 | i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies)) | |
674 | attr->values[i].string.text = p->name; | |
675 | ||
676 | /* printer-settable-attributes-supported */ | |
677 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
678 | "printer-settable-attributes-supported", | |
679 | sizeof(printer_settable) / sizeof(printer_settable[0]), | |
680 | NULL, printer_settable); | |
681 | ||
682 | /* server-is-sharing-printers */ | |
683 | ippAddBoolean(CommonData, IPP_TAG_PRINTER, "server-is-sharing-printers", | |
684 | BrowseLocalProtocols != 0 && Browsing); | |
685 | ||
686 | /* which-jobs-supported */ | |
687 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
688 | "which-jobs-supported", | |
689 | sizeof(which_jobs) / sizeof(which_jobs[0]), NULL, which_jobs); | |
690 | } | |
691 | ||
692 | ||
693 | /* | |
694 | * 'cupsdDeleteAllPrinters()' - Delete all printers from the system. | |
695 | */ | |
696 | ||
697 | void | |
698 | cupsdDeleteAllPrinters(void) | |
699 | { | |
700 | cupsd_printer_t *p; /* Pointer to current printer/class */ | |
701 | ||
702 | ||
703 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
704 | p; | |
705 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
706 | { | |
707 | p->op_policy_ptr = DefaultPolicyPtr; | |
708 | cupsdDeletePrinter(p, 0); | |
709 | } | |
710 | } | |
711 | ||
712 | ||
713 | /* | |
714 | * 'cupsdDeletePrinter()' - Delete a printer from the system. | |
715 | */ | |
716 | ||
717 | int /* O - 1 if classes affected, 0 otherwise */ | |
718 | cupsdDeletePrinter( | |
719 | cupsd_printer_t *p, /* I - Printer to delete */ | |
720 | int update) /* I - Update printers.conf? */ | |
721 | { | |
722 | int i, /* Looping var */ | |
723 | changed = 0; /* Class changed? */ | |
724 | #ifdef __sgi | |
725 | char filename[1024]; /* Interface script filename */ | |
726 | #endif /* __sgi */ | |
727 | ||
728 | ||
729 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdDeletePrinter(p=%p(%s), update=%d)", | |
730 | p, p->name, update); | |
731 | ||
732 | /* | |
733 | * Save the current position in the Printers array... | |
734 | */ | |
735 | ||
736 | cupsArraySave(Printers); | |
737 | ||
738 | /* | |
739 | * Stop printing on this printer... | |
740 | */ | |
741 | ||
742 | cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, update); | |
743 | ||
744 | p->state = IPP_PRINTER_STOPPED; /* Force for browsed printers */ | |
745 | ||
746 | if (p->job) | |
747 | cupsdSetJobState(p->job, IPP_JOB_PENDING, CUPSD_JOB_FORCE, | |
748 | update ? "Job stopped due to printer being deleted." : | |
749 | "Job stopped."); | |
750 | ||
751 | /* | |
752 | * Remove the printer from the list... | |
753 | */ | |
754 | ||
755 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
756 | "cupsdDeletePrinter: Removing %s from Printers", p->name); | |
757 | cupsArrayRemove(Printers, p); | |
758 | ||
759 | /* | |
760 | * Remove the dummy interface/icon/option files under IRIX... | |
761 | */ | |
762 | ||
763 | #ifdef __sgi | |
764 | snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name); | |
765 | unlink(filename); | |
766 | ||
767 | snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", | |
768 | p->name); | |
769 | unlink(filename); | |
770 | ||
771 | snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name); | |
772 | unlink(filename); | |
773 | ||
774 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name); | |
775 | unlink(filename); | |
776 | ||
777 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name); | |
778 | unlink(filename); | |
779 | ||
780 | snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name); | |
781 | unlink(filename); | |
782 | #endif /* __sgi */ | |
783 | ||
784 | /* | |
785 | * If p is the default printer, assign a different one... | |
786 | */ | |
787 | ||
788 | if (p == DefaultPrinter) | |
789 | DefaultPrinter = NULL; | |
790 | ||
791 | /* | |
792 | * Remove this printer from any classes... | |
793 | */ | |
794 | ||
795 | changed = cupsdDeletePrinterFromClasses(p); | |
796 | ||
797 | /* | |
798 | * Deregister from any browse protocols... | |
799 | */ | |
800 | ||
801 | cupsdDeregisterPrinter(p, 1); | |
802 | ||
803 | /* | |
804 | * Free all memory used by the printer... | |
805 | */ | |
806 | ||
807 | if (p->printers != NULL) | |
808 | free(p->printers); | |
809 | ||
810 | delete_printer_filters(p); | |
811 | ||
812 | for (i = 0; i < p->num_reasons; i ++) | |
813 | _cupsStrFree(p->reasons[i]); | |
814 | ||
815 | ippDelete(p->attrs); | |
816 | ippDelete(p->ppd_attrs); | |
817 | ||
818 | mimeDeleteType(MimeDatabase, p->filetype); | |
819 | mimeDeleteType(MimeDatabase, p->prefiltertype); | |
820 | ||
821 | cupsdFreeStrings(&(p->users)); | |
822 | cupsdFreeQuotas(p); | |
823 | ||
824 | cupsdClearString(&p->uri); | |
825 | cupsdClearString(&p->hostname); | |
826 | cupsdClearString(&p->name); | |
827 | cupsdClearString(&p->location); | |
828 | cupsdClearString(&p->make_model); | |
829 | cupsdClearString(&p->info); | |
830 | cupsdClearString(&p->job_sheets[0]); | |
831 | cupsdClearString(&p->job_sheets[1]); | |
832 | cupsdClearString(&p->device_uri); | |
833 | cupsdClearString(&p->sanitized_device_uri); | |
834 | cupsdClearString(&p->port_monitor); | |
835 | cupsdClearString(&p->op_policy); | |
836 | cupsdClearString(&p->error_policy); | |
837 | ||
838 | cupsdClearString(&p->alert); | |
839 | cupsdClearString(&p->alert_description); | |
840 | ||
841 | #ifdef HAVE_DNSSD | |
842 | cupsdClearString(&p->pdl); | |
843 | #endif /* HAVE_DNSSD */ | |
844 | ||
845 | cupsArrayDelete(p->filetypes); | |
846 | ||
847 | cupsFreeOptions(p->num_options, p->options); | |
848 | ||
849 | free(p); | |
850 | ||
851 | /* | |
852 | * Restore the previous position in the Printers array... | |
853 | */ | |
854 | ||
855 | cupsArrayRestore(Printers); | |
856 | ||
857 | return (changed); | |
858 | } | |
859 | ||
860 | ||
861 | /* | |
862 | * 'cupsdFindDest()' - Find a destination in the list. | |
863 | */ | |
864 | ||
865 | cupsd_printer_t * /* O - Destination in list */ | |
866 | cupsdFindDest(const char *name) /* I - Name of printer or class to find */ | |
867 | { | |
868 | cupsd_printer_t key; /* Search key */ | |
869 | ||
870 | ||
871 | key.name = (char *)name; | |
872 | return ((cupsd_printer_t *)cupsArrayFind(Printers, &key)); | |
873 | } | |
874 | ||
875 | ||
876 | /* | |
877 | * 'cupsdFindPrinter()' - Find a printer in the list. | |
878 | */ | |
879 | ||
880 | cupsd_printer_t * /* O - Printer in list */ | |
881 | cupsdFindPrinter(const char *name) /* I - Name of printer to find */ | |
882 | { | |
883 | cupsd_printer_t *p; /* Printer in list */ | |
884 | ||
885 | ||
886 | if ((p = cupsdFindDest(name)) != NULL && (p->type & CUPS_PRINTER_CLASS)) | |
887 | return (NULL); | |
888 | else | |
889 | return (p); | |
890 | } | |
891 | ||
892 | ||
893 | /* | |
894 | * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file. | |
895 | */ | |
896 | ||
897 | void | |
898 | cupsdLoadAllPrinters(void) | |
899 | { | |
900 | int i; /* Looping var */ | |
901 | cups_file_t *fp; /* printers.conf file */ | |
902 | int linenum; /* Current line number */ | |
903 | char line[4096], /* Line from file */ | |
904 | *value, /* Pointer to value */ | |
905 | *valueptr; /* Pointer into value */ | |
906 | cupsd_printer_t *p; /* Current printer */ | |
907 | ||
908 | ||
909 | /* | |
910 | * Open the printers.conf file... | |
911 | */ | |
912 | ||
913 | snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot); | |
914 | if ((fp = cupsdOpenConfFile(line)) == NULL) | |
915 | return; | |
916 | ||
917 | /* | |
918 | * Read printer configurations until we hit EOF... | |
919 | */ | |
920 | ||
921 | linenum = 0; | |
922 | p = NULL; | |
923 | ||
924 | while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) | |
925 | { | |
926 | /* | |
927 | * Decode the directive... | |
928 | */ | |
929 | ||
930 | if (!_cups_strcasecmp(line, "<Printer") || | |
931 | !_cups_strcasecmp(line, "<DefaultPrinter")) | |
932 | { | |
933 | /* | |
934 | * <Printer name> or <DefaultPrinter name> | |
935 | */ | |
936 | ||
937 | if (p == NULL && value) | |
938 | { | |
939 | /* | |
940 | * Add the printer and a base file type... | |
941 | */ | |
942 | ||
943 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading printer %s...", value); | |
944 | ||
945 | p = cupsdAddPrinter(value); | |
946 | p->accepting = 1; | |
947 | p->state = IPP_PRINTER_IDLE; | |
948 | ||
949 | /* | |
950 | * Set the default printer as needed... | |
951 | */ | |
952 | ||
953 | if (!_cups_strcasecmp(line, "<DefaultPrinter")) | |
954 | DefaultPrinter = p; | |
955 | } | |
956 | else | |
957 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
958 | "Syntax error on line %d of printers.conf.", linenum); | |
959 | } | |
960 | else if (!_cups_strcasecmp(line, "</Printer>")) | |
961 | { | |
962 | if (p != NULL) | |
963 | { | |
964 | /* | |
965 | * Close out the current printer... | |
966 | */ | |
967 | ||
968 | cupsdSetPrinterAttrs(p); | |
969 | ||
970 | if (strncmp(p->device_uri, "file:", 5) && | |
971 | p->state != IPP_PRINTER_STOPPED) | |
972 | { | |
973 | /* | |
974 | * See if the backend exists... | |
975 | */ | |
976 | ||
977 | snprintf(line, sizeof(line), "%s/backend/%s", ServerBin, | |
978 | p->device_uri); | |
979 | ||
980 | if ((valueptr = strchr(line + strlen(ServerBin), ':')) != NULL) | |
981 | *valueptr = '\0'; /* Chop everything but URI scheme */ | |
982 | ||
983 | if (access(line, 0)) | |
984 | { | |
985 | /* | |
986 | * Backend does not exist, stop printer... | |
987 | */ | |
988 | ||
989 | p->state = IPP_PRINTER_STOPPED; | |
990 | snprintf(p->state_message, sizeof(p->state_message), | |
991 | "Backend %s does not exist!", line); | |
992 | } | |
993 | } | |
994 | ||
995 | p = NULL; | |
996 | } | |
997 | else | |
998 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
999 | "Syntax error on line %d of printers.conf.", linenum); | |
1000 | } | |
1001 | else if (!p) | |
1002 | { | |
1003 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1004 | "Syntax error on line %d of printers.conf.", linenum); | |
1005 | } | |
1006 | else if (!_cups_strcasecmp(line, "UUID")) | |
1007 | { | |
1008 | if (value && !strncmp(value, "urn:uuid:", 9)) | |
1009 | cupsdSetString(&(p->uuid), value); | |
1010 | else | |
1011 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1012 | "Bad UUID on line %d of printers.conf.", linenum); | |
1013 | } | |
1014 | else if (!_cups_strcasecmp(line, "AuthInfoRequired")) | |
1015 | { | |
1016 | if (!cupsdSetAuthInfoRequired(p, value, NULL)) | |
1017 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1018 | "Bad AuthInfoRequired on line %d of printers.conf.", | |
1019 | linenum); | |
1020 | } | |
1021 | else if (!_cups_strcasecmp(line, "Info")) | |
1022 | { | |
1023 | if (value) | |
1024 | cupsdSetString(&p->info, value); | |
1025 | } | |
1026 | else if (!_cups_strcasecmp(line, "MakeModel")) | |
1027 | { | |
1028 | if (value) | |
1029 | cupsdSetString(&p->make_model, value); | |
1030 | } | |
1031 | else if (!_cups_strcasecmp(line, "Location")) | |
1032 | { | |
1033 | if (value) | |
1034 | cupsdSetString(&p->location, value); | |
1035 | } | |
1036 | else if (!_cups_strcasecmp(line, "DeviceURI")) | |
1037 | { | |
1038 | if (value) | |
1039 | cupsdSetDeviceURI(p, value); | |
1040 | else | |
1041 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1042 | "Syntax error on line %d of printers.conf.", linenum); | |
1043 | } | |
1044 | else if (!_cups_strcasecmp(line, "Option") && value) | |
1045 | { | |
1046 | /* | |
1047 | * Option name value | |
1048 | */ | |
1049 | ||
1050 | for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++); | |
1051 | ||
1052 | if (!*valueptr) | |
1053 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1054 | "Syntax error on line %d of printers.conf.", linenum); | |
1055 | else | |
1056 | { | |
1057 | for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0'); | |
1058 | ||
1059 | p->num_options = cupsAddOption(value, valueptr, p->num_options, | |
1060 | &(p->options)); | |
1061 | } | |
1062 | } | |
1063 | else if (!_cups_strcasecmp(line, "PortMonitor")) | |
1064 | { | |
1065 | if (value && strcmp(value, "none")) | |
1066 | cupsdSetString(&p->port_monitor, value); | |
1067 | else if (value) | |
1068 | cupsdClearString(&p->port_monitor); | |
1069 | else | |
1070 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1071 | "Syntax error on line %d of printers.conf.", linenum); | |
1072 | } | |
1073 | else if (!_cups_strcasecmp(line, "Reason")) | |
1074 | { | |
1075 | if (value && | |
1076 | strcmp(value, "connecting-to-device") && | |
1077 | strcmp(value, "cups-insecure-filter-warning") && | |
1078 | strcmp(value, "cups-missing-filter-warning")) | |
1079 | { | |
1080 | for (i = 0 ; i < p->num_reasons; i ++) | |
1081 | if (!strcmp(value, p->reasons[i])) | |
1082 | break; | |
1083 | ||
1084 | if (i >= p->num_reasons && | |
1085 | p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0]))) | |
1086 | { | |
1087 | p->reasons[p->num_reasons] = _cupsStrAlloc(value); | |
1088 | p->num_reasons ++; | |
1089 | } | |
1090 | } | |
1091 | else | |
1092 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1093 | "Syntax error on line %d of printers.conf.", linenum); | |
1094 | } | |
1095 | else if (!_cups_strcasecmp(line, "State")) | |
1096 | { | |
1097 | /* | |
1098 | * Set the initial queue state... | |
1099 | */ | |
1100 | ||
1101 | if (value && !_cups_strcasecmp(value, "idle")) | |
1102 | p->state = IPP_PRINTER_IDLE; | |
1103 | else if (value && !_cups_strcasecmp(value, "stopped")) | |
1104 | { | |
1105 | p->state = IPP_PRINTER_STOPPED; | |
1106 | ||
1107 | for (i = 0 ; i < p->num_reasons; i ++) | |
1108 | if (!strcmp("paused", p->reasons[i])) | |
1109 | break; | |
1110 | ||
1111 | if (i >= p->num_reasons && | |
1112 | p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0]))) | |
1113 | { | |
1114 | p->reasons[p->num_reasons] = _cupsStrAlloc("paused"); | |
1115 | p->num_reasons ++; | |
1116 | } | |
1117 | } | |
1118 | else | |
1119 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1120 | "Syntax error on line %d of printers.conf.", linenum); | |
1121 | } | |
1122 | else if (!_cups_strcasecmp(line, "StateMessage")) | |
1123 | { | |
1124 | /* | |
1125 | * Set the initial queue state message... | |
1126 | */ | |
1127 | ||
1128 | if (value) | |
1129 | strlcpy(p->state_message, value, sizeof(p->state_message)); | |
1130 | } | |
1131 | else if (!_cups_strcasecmp(line, "StateTime")) | |
1132 | { | |
1133 | /* | |
1134 | * Set the state time... | |
1135 | */ | |
1136 | ||
1137 | if (value) | |
1138 | p->state_time = atoi(value); | |
1139 | } | |
1140 | else if (!_cups_strcasecmp(line, "Accepting")) | |
1141 | { | |
1142 | /* | |
1143 | * Set the initial accepting state... | |
1144 | */ | |
1145 | ||
1146 | if (value && | |
1147 | (!_cups_strcasecmp(value, "yes") || | |
1148 | !_cups_strcasecmp(value, "on") || | |
1149 | !_cups_strcasecmp(value, "true"))) | |
1150 | p->accepting = 1; | |
1151 | else if (value && | |
1152 | (!_cups_strcasecmp(value, "no") || | |
1153 | !_cups_strcasecmp(value, "off") || | |
1154 | !_cups_strcasecmp(value, "false"))) | |
1155 | p->accepting = 0; | |
1156 | else | |
1157 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1158 | "Syntax error on line %d of printers.conf.", linenum); | |
1159 | } | |
1160 | else if (!_cups_strcasecmp(line, "Type")) | |
1161 | { | |
1162 | if (value) | |
1163 | p->type = atoi(value); | |
1164 | else | |
1165 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1166 | "Syntax error on line %d of printers.conf.", linenum); | |
1167 | } | |
1168 | else if (!_cups_strcasecmp(line, "Shared")) | |
1169 | { | |
1170 | /* | |
1171 | * Set the initial shared state... | |
1172 | */ | |
1173 | ||
1174 | if (value && | |
1175 | (!_cups_strcasecmp(value, "yes") || | |
1176 | !_cups_strcasecmp(value, "on") || | |
1177 | !_cups_strcasecmp(value, "true"))) | |
1178 | p->shared = 1; | |
1179 | else if (value && | |
1180 | (!_cups_strcasecmp(value, "no") || | |
1181 | !_cups_strcasecmp(value, "off") || | |
1182 | !_cups_strcasecmp(value, "false"))) | |
1183 | p->shared = 0; | |
1184 | else | |
1185 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1186 | "Syntax error on line %d of printers.conf.", linenum); | |
1187 | } | |
1188 | else if (!_cups_strcasecmp(line, "JobSheets")) | |
1189 | { | |
1190 | /* | |
1191 | * Set the initial job sheets... | |
1192 | */ | |
1193 | ||
1194 | if (value) | |
1195 | { | |
1196 | for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++); | |
1197 | ||
1198 | if (*valueptr) | |
1199 | *valueptr++ = '\0'; | |
1200 | ||
1201 | cupsdSetString(&p->job_sheets[0], value); | |
1202 | ||
1203 | while (isspace(*valueptr & 255)) | |
1204 | valueptr ++; | |
1205 | ||
1206 | if (*valueptr) | |
1207 | { | |
1208 | for (value = valueptr; *valueptr && !isspace(*valueptr & 255); valueptr ++); | |
1209 | ||
1210 | if (*valueptr) | |
1211 | *valueptr = '\0'; | |
1212 | ||
1213 | cupsdSetString(&p->job_sheets[1], value); | |
1214 | } | |
1215 | } | |
1216 | else | |
1217 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1218 | "Syntax error on line %d of printers.conf.", linenum); | |
1219 | } | |
1220 | else if (!_cups_strcasecmp(line, "AllowUser")) | |
1221 | { | |
1222 | if (value) | |
1223 | { | |
1224 | p->deny_users = 0; | |
1225 | cupsdAddString(&(p->users), value); | |
1226 | } | |
1227 | else | |
1228 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1229 | "Syntax error on line %d of printers.conf.", linenum); | |
1230 | } | |
1231 | else if (!_cups_strcasecmp(line, "DenyUser")) | |
1232 | { | |
1233 | if (value) | |
1234 | { | |
1235 | p->deny_users = 1; | |
1236 | cupsdAddString(&(p->users), value); | |
1237 | } | |
1238 | else | |
1239 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1240 | "Syntax error on line %d of printers.conf.", linenum); | |
1241 | } | |
1242 | else if (!_cups_strcasecmp(line, "QuotaPeriod")) | |
1243 | { | |
1244 | if (value) | |
1245 | p->quota_period = atoi(value); | |
1246 | else | |
1247 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1248 | "Syntax error on line %d of printers.conf.", linenum); | |
1249 | } | |
1250 | else if (!_cups_strcasecmp(line, "PageLimit")) | |
1251 | { | |
1252 | if (value) | |
1253 | p->page_limit = atoi(value); | |
1254 | else | |
1255 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1256 | "Syntax error on line %d of printers.conf.", linenum); | |
1257 | } | |
1258 | else if (!_cups_strcasecmp(line, "KLimit")) | |
1259 | { | |
1260 | if (value) | |
1261 | p->k_limit = atoi(value); | |
1262 | else | |
1263 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1264 | "Syntax error on line %d of printers.conf.", linenum); | |
1265 | } | |
1266 | else if (!_cups_strcasecmp(line, "OpPolicy")) | |
1267 | { | |
1268 | if (value) | |
1269 | { | |
1270 | cupsd_policy_t *pol; /* Policy */ | |
1271 | ||
1272 | ||
1273 | if ((pol = cupsdFindPolicy(value)) != NULL) | |
1274 | { | |
1275 | cupsdSetString(&p->op_policy, value); | |
1276 | p->op_policy_ptr = pol; | |
1277 | } | |
1278 | else | |
1279 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1280 | "Bad policy \"%s\" on line %d of printers.conf", | |
1281 | value, linenum); | |
1282 | } | |
1283 | else | |
1284 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1285 | "Syntax error on line %d of printers.conf.", linenum); | |
1286 | } | |
1287 | else if (!_cups_strcasecmp(line, "ErrorPolicy")) | |
1288 | { | |
1289 | if (value) | |
1290 | cupsdSetString(&p->error_policy, value); | |
1291 | else | |
1292 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1293 | "Syntax error on line %d of printers.conf.", linenum); | |
1294 | } | |
1295 | else if (!_cups_strcasecmp(line, "Attribute") && value) | |
1296 | { | |
1297 | for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++); | |
1298 | ||
1299 | if (!*valueptr) | |
1300 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1301 | "Syntax error on line %d of printers.conf.", linenum); | |
1302 | else | |
1303 | { | |
1304 | for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0'); | |
1305 | ||
1306 | if (!p->attrs) | |
1307 | cupsdSetPrinterAttrs(p); | |
1308 | ||
1309 | if (!strcmp(value, "marker-change-time")) | |
1310 | p->marker_time = atoi(valueptr); | |
1311 | else | |
1312 | cupsdSetPrinterAttr(p, value, valueptr); | |
1313 | } | |
1314 | } | |
1315 | else if (_cups_strcasecmp(line, "Filter") && | |
1316 | _cups_strcasecmp(line, "Prefilter") && | |
1317 | _cups_strcasecmp(line, "Product")) | |
1318 | { | |
1319 | /* | |
1320 | * Something else we don't understand (and that wasn't used in a prior | |
1321 | * release of CUPS... | |
1322 | */ | |
1323 | ||
1324 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1325 | "Unknown configuration directive %s on line %d of " | |
1326 | "printers.conf.", line, linenum); | |
1327 | } | |
1328 | } | |
1329 | ||
1330 | cupsFileClose(fp); | |
1331 | } | |
1332 | ||
1333 | ||
1334 | /* | |
1335 | * 'cupsdRenamePrinter()' - Rename a printer. | |
1336 | */ | |
1337 | ||
1338 | void | |
1339 | cupsdRenamePrinter( | |
1340 | cupsd_printer_t *p, /* I - Printer */ | |
1341 | const char *name) /* I - New name */ | |
1342 | { | |
1343 | /* | |
1344 | * Remove the printer from the array(s) first... | |
1345 | */ | |
1346 | ||
1347 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
1348 | "cupsdRenamePrinter: Removing %s from Printers", p->name); | |
1349 | cupsArrayRemove(Printers, p); | |
1350 | ||
1351 | /* | |
1352 | * Rename the printer type... | |
1353 | */ | |
1354 | ||
1355 | mimeDeleteType(MimeDatabase, p->filetype); | |
1356 | p->filetype = mimeAddType(MimeDatabase, "printer", name); | |
1357 | ||
1358 | if (p->prefiltertype) | |
1359 | { | |
1360 | mimeDeleteType(MimeDatabase, p->prefiltertype); | |
1361 | p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", name); | |
1362 | } | |
1363 | ||
1364 | /* | |
1365 | * Rename the printer... | |
1366 | */ | |
1367 | ||
1368 | cupsdSetString(&p->name, name); | |
1369 | ||
1370 | /* | |
1371 | * Reset printer attributes... | |
1372 | */ | |
1373 | ||
1374 | cupsdSetPrinterAttrs(p); | |
1375 | ||
1376 | /* | |
1377 | * Add the printer back to the printer array(s)... | |
1378 | */ | |
1379 | ||
1380 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
1381 | "cupsdRenamePrinter: Adding %s to Printers", p->name); | |
1382 | cupsArrayAdd(Printers, p); | |
1383 | } | |
1384 | ||
1385 | ||
1386 | /* | |
1387 | * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf | |
1388 | * file. | |
1389 | */ | |
1390 | ||
1391 | void | |
1392 | cupsdSaveAllPrinters(void) | |
1393 | { | |
1394 | int i; /* Looping var */ | |
1395 | cups_file_t *fp; /* printers.conf file */ | |
1396 | char filename[1024], /* printers.conf filename */ | |
1397 | temp[1024], /* Temporary string */ | |
1398 | value[2048], /* Value string */ | |
1399 | *ptr, /* Pointer into value */ | |
1400 | *name; /* Current user/group name */ | |
1401 | cupsd_printer_t *printer; /* Current printer class */ | |
1402 | time_t curtime; /* Current time */ | |
1403 | struct tm *curdate; /* Current date */ | |
1404 | cups_option_t *option; /* Current option */ | |
1405 | ipp_attribute_t *marker; /* Current marker attribute */ | |
1406 | ||
1407 | ||
1408 | /* | |
1409 | * Create the printers.conf file... | |
1410 | */ | |
1411 | ||
1412 | snprintf(filename, sizeof(filename), "%s/printers.conf", ServerRoot); | |
1413 | ||
1414 | if ((fp = cupsdCreateConfFile(filename, ConfigFilePerm & 0600)) == NULL) | |
1415 | return; | |
1416 | ||
1417 | cupsdLogMessage(CUPSD_LOG_INFO, "Saving printers.conf..."); | |
1418 | ||
1419 | /* | |
1420 | * Write a small header to the file... | |
1421 | */ | |
1422 | ||
1423 | curtime = time(NULL); | |
1424 | curdate = localtime(&curtime); | |
1425 | strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate); | |
1426 | ||
1427 | cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n"); | |
1428 | cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp); | |
1429 | cupsFilePuts(fp, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n"); | |
1430 | ||
1431 | /* | |
1432 | * Write each local printer known to the system... | |
1433 | */ | |
1434 | ||
1435 | for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
1436 | printer; | |
1437 | printer = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
1438 | { | |
1439 | /* | |
1440 | * Skip printer classes... | |
1441 | */ | |
1442 | ||
1443 | if (printer->type & CUPS_PRINTER_CLASS) | |
1444 | continue; | |
1445 | ||
1446 | /* | |
1447 | * Write printers as needed... | |
1448 | */ | |
1449 | ||
1450 | if (printer == DefaultPrinter) | |
1451 | cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name); | |
1452 | else | |
1453 | cupsFilePrintf(fp, "<Printer %s>\n", printer->name); | |
1454 | ||
1455 | cupsFilePrintf(fp, "UUID %s\n", printer->uuid); | |
1456 | ||
1457 | if (printer->num_auth_info_required > 0) | |
1458 | { | |
1459 | switch (printer->num_auth_info_required) | |
1460 | { | |
1461 | case 1 : | |
1462 | strlcpy(value, printer->auth_info_required[0], sizeof(value)); | |
1463 | break; | |
1464 | ||
1465 | case 2 : | |
1466 | snprintf(value, sizeof(value), "%s,%s", | |
1467 | printer->auth_info_required[0], | |
1468 | printer->auth_info_required[1]); | |
1469 | break; | |
1470 | ||
1471 | case 3 : | |
1472 | default : | |
1473 | snprintf(value, sizeof(value), "%s,%s,%s", | |
1474 | printer->auth_info_required[0], | |
1475 | printer->auth_info_required[1], | |
1476 | printer->auth_info_required[2]); | |
1477 | break; | |
1478 | } | |
1479 | ||
1480 | cupsFilePutConf(fp, "AuthInfoRequired", value); | |
1481 | } | |
1482 | ||
1483 | if (printer->info) | |
1484 | cupsFilePutConf(fp, "Info", printer->info); | |
1485 | ||
1486 | if (printer->location) | |
1487 | cupsFilePutConf(fp, "Location", printer->location); | |
1488 | ||
1489 | if (printer->make_model) | |
1490 | cupsFilePutConf(fp, "MakeModel", printer->make_model); | |
1491 | ||
1492 | cupsFilePutConf(fp, "DeviceURI", printer->device_uri); | |
1493 | ||
1494 | if (printer->port_monitor) | |
1495 | cupsFilePutConf(fp, "PortMonitor", printer->port_monitor); | |
1496 | ||
1497 | if (printer->state == IPP_PRINTER_STOPPED) | |
1498 | { | |
1499 | cupsFilePuts(fp, "State Stopped\n"); | |
1500 | ||
1501 | if (printer->state_message) | |
1502 | cupsFilePutConf(fp, "StateMessage", printer->state_message); | |
1503 | } | |
1504 | else | |
1505 | cupsFilePuts(fp, "State Idle\n"); | |
1506 | ||
1507 | cupsFilePrintf(fp, "StateTime %d\n", (int)printer->state_time); | |
1508 | ||
1509 | for (i = 0; i < printer->num_reasons; i ++) | |
1510 | if (strcmp(printer->reasons[i], "connecting-to-device") && | |
1511 | strcmp(printer->reasons[i], "cups-insecure-filter-warning") && | |
1512 | strcmp(printer->reasons[i], "cups-missing-filter-warning")) | |
1513 | cupsFilePutConf(fp, "Reason", printer->reasons[i]); | |
1514 | ||
1515 | cupsFilePrintf(fp, "Type %d\n", printer->type); | |
1516 | ||
1517 | if (printer->accepting) | |
1518 | cupsFilePuts(fp, "Accepting Yes\n"); | |
1519 | else | |
1520 | cupsFilePuts(fp, "Accepting No\n"); | |
1521 | ||
1522 | if (printer->shared) | |
1523 | cupsFilePuts(fp, "Shared Yes\n"); | |
1524 | else | |
1525 | cupsFilePuts(fp, "Shared No\n"); | |
1526 | ||
1527 | snprintf(value, sizeof(value), "%s %s", printer->job_sheets[0], | |
1528 | printer->job_sheets[1]); | |
1529 | cupsFilePutConf(fp, "JobSheets", value); | |
1530 | ||
1531 | cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period); | |
1532 | cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit); | |
1533 | cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit); | |
1534 | ||
1535 | for (name = (char *)cupsArrayFirst(printer->users); | |
1536 | name; | |
1537 | name = (char *)cupsArrayNext(printer->users)) | |
1538 | cupsFilePutConf(fp, printer->deny_users ? "DenyUser" : "AllowUser", name); | |
1539 | ||
1540 | if (printer->op_policy) | |
1541 | cupsFilePutConf(fp, "OpPolicy", printer->op_policy); | |
1542 | if (printer->error_policy) | |
1543 | cupsFilePutConf(fp, "ErrorPolicy", printer->error_policy); | |
1544 | ||
1545 | for (i = printer->num_options, option = printer->options; | |
1546 | i > 0; | |
1547 | i --, option ++) | |
1548 | { | |
1549 | snprintf(value, sizeof(value), "%s %s", option->name, option->value); | |
1550 | cupsFilePutConf(fp, "Option", value); | |
1551 | } | |
1552 | ||
1553 | if ((marker = ippFindAttribute(printer->attrs, "marker-colors", | |
1554 | IPP_TAG_NAME)) != NULL) | |
1555 | { | |
1556 | snprintf(value, sizeof(value), "%s ", marker->name); | |
1557 | ||
1558 | for (i = 0, ptr = value + strlen(value); | |
1559 | i < marker->num_values && ptr < (value + sizeof(value) - 1); | |
1560 | i ++) | |
1561 | { | |
1562 | if (i) | |
1563 | *ptr++ = ','; | |
1564 | ||
1565 | strlcpy(ptr, marker->values[i].string.text, | |
1566 | value + sizeof(value) - ptr); | |
1567 | ptr += strlen(ptr); | |
1568 | } | |
1569 | ||
1570 | *ptr = '\0'; | |
1571 | cupsFilePutConf(fp, "Attribute", value); | |
1572 | } | |
1573 | ||
1574 | if ((marker = ippFindAttribute(printer->attrs, "marker-levels", | |
1575 | IPP_TAG_INTEGER)) != NULL) | |
1576 | { | |
1577 | cupsFilePrintf(fp, "Attribute %s %d", marker->name, | |
1578 | marker->values[0].integer); | |
1579 | for (i = 1; i < marker->num_values; i ++) | |
1580 | cupsFilePrintf(fp, ",%d", marker->values[i].integer); | |
1581 | cupsFilePuts(fp, "\n"); | |
1582 | } | |
1583 | ||
1584 | if ((marker = ippFindAttribute(printer->attrs, "marker-low-levels", | |
1585 | IPP_TAG_INTEGER)) != NULL) | |
1586 | { | |
1587 | cupsFilePrintf(fp, "Attribute %s %d", marker->name, | |
1588 | marker->values[0].integer); | |
1589 | for (i = 1; i < marker->num_values; i ++) | |
1590 | cupsFilePrintf(fp, ",%d", marker->values[i].integer); | |
1591 | cupsFilePuts(fp, "\n"); | |
1592 | } | |
1593 | ||
1594 | if ((marker = ippFindAttribute(printer->attrs, "marker-high-levels", | |
1595 | IPP_TAG_INTEGER)) != NULL) | |
1596 | { | |
1597 | cupsFilePrintf(fp, "Attribute %s %d", marker->name, | |
1598 | marker->values[0].integer); | |
1599 | for (i = 1; i < marker->num_values; i ++) | |
1600 | cupsFilePrintf(fp, ",%d", marker->values[i].integer); | |
1601 | cupsFilePuts(fp, "\n"); | |
1602 | } | |
1603 | ||
1604 | if ((marker = ippFindAttribute(printer->attrs, "marker-message", | |
1605 | IPP_TAG_TEXT)) != NULL) | |
1606 | { | |
1607 | snprintf(value, sizeof(value), "%s %s", marker->name, | |
1608 | marker->values[0].string.text); | |
1609 | ||
1610 | cupsFilePutConf(fp, "Attribute", value); | |
1611 | } | |
1612 | ||
1613 | if ((marker = ippFindAttribute(printer->attrs, "marker-names", | |
1614 | IPP_TAG_NAME)) != NULL) | |
1615 | { | |
1616 | snprintf(value, sizeof(value), "%s ", marker->name); | |
1617 | ||
1618 | for (i = 0, ptr = value + strlen(value); | |
1619 | i < marker->num_values && ptr < (value + sizeof(value) - 1); | |
1620 | i ++) | |
1621 | { | |
1622 | if (i) | |
1623 | *ptr++ = ','; | |
1624 | ||
1625 | strlcpy(ptr, marker->values[i].string.text, | |
1626 | value + sizeof(value) - ptr); | |
1627 | ptr += strlen(ptr); | |
1628 | } | |
1629 | ||
1630 | *ptr = '\0'; | |
1631 | cupsFilePutConf(fp, "Attribute", value); | |
1632 | } | |
1633 | ||
1634 | if ((marker = ippFindAttribute(printer->attrs, "marker-types", | |
1635 | IPP_TAG_KEYWORD)) != NULL) | |
1636 | { | |
1637 | snprintf(value, sizeof(value), "%s ", marker->name); | |
1638 | ||
1639 | for (i = 0, ptr = value + strlen(value); | |
1640 | i < marker->num_values && ptr < (value + sizeof(value) - 1); | |
1641 | i ++) | |
1642 | { | |
1643 | if (i) | |
1644 | *ptr++ = ','; | |
1645 | ||
1646 | strlcpy(ptr, marker->values[i].string.text, | |
1647 | value + sizeof(value) - ptr); | |
1648 | ptr += strlen(ptr); | |
1649 | } | |
1650 | ||
1651 | *ptr = '\0'; | |
1652 | cupsFilePutConf(fp, "Attribute", value); | |
1653 | } | |
1654 | ||
1655 | if (printer->marker_time) | |
1656 | cupsFilePrintf(fp, "Attribute marker-change-time %ld\n", | |
1657 | (long)printer->marker_time); | |
1658 | ||
1659 | cupsFilePuts(fp, "</Printer>\n"); | |
1660 | ||
1661 | #ifdef __sgi | |
1662 | /* | |
1663 | * Make IRIX desktop & printer status happy | |
1664 | */ | |
1665 | ||
1666 | write_irix_state(printer); | |
1667 | #endif /* __sgi */ | |
1668 | } | |
1669 | ||
1670 | cupsdCloseCreatedConfFile(fp, filename); | |
1671 | } | |
1672 | ||
1673 | ||
1674 | /* | |
1675 | * 'cupsdSetAuthInfoRequired()' - Set the required authentication info. | |
1676 | */ | |
1677 | ||
1678 | int /* O - 1 if value OK, 0 otherwise */ | |
1679 | cupsdSetAuthInfoRequired( | |
1680 | cupsd_printer_t *p, /* I - Printer */ | |
1681 | const char *values, /* I - Plain text value (or NULL) */ | |
1682 | ipp_attribute_t *attr) /* I - IPP attribute value (or NULL) */ | |
1683 | { | |
1684 | int i; /* Looping var */ | |
1685 | ||
1686 | ||
1687 | p->num_auth_info_required = 0; | |
1688 | ||
1689 | /* | |
1690 | * Do we have a plain text value? | |
1691 | */ | |
1692 | ||
1693 | if (values) | |
1694 | { | |
1695 | /* | |
1696 | * Yes, grab the keywords... | |
1697 | */ | |
1698 | ||
1699 | const char *end; /* End of current value */ | |
1700 | ||
1701 | ||
1702 | while (*values && p->num_auth_info_required < 4) | |
1703 | { | |
1704 | if ((end = strchr(values, ',')) == NULL) | |
1705 | end = values + strlen(values); | |
1706 | ||
1707 | if ((end - values) == 4 && !strncmp(values, "none", 4)) | |
1708 | { | |
1709 | if (p->num_auth_info_required != 0 || *end) | |
1710 | return (0); | |
1711 | ||
1712 | p->auth_info_required[p->num_auth_info_required] = "none"; | |
1713 | p->num_auth_info_required ++; | |
1714 | ||
1715 | return (1); | |
1716 | } | |
1717 | else if ((end - values) == 9 && !strncmp(values, "negotiate", 9)) | |
1718 | { | |
1719 | if (p->num_auth_info_required != 0 || *end) | |
1720 | return (0); | |
1721 | ||
1722 | p->auth_info_required[p->num_auth_info_required] = "negotiate"; | |
1723 | p->num_auth_info_required ++; | |
1724 | ||
1725 | /* | |
1726 | * Don't allow sharing of queues that require Kerberos authentication. | |
1727 | */ | |
1728 | ||
1729 | if (p->shared) | |
1730 | { | |
1731 | cupsdDeregisterPrinter(p, 1); | |
1732 | p->shared = 0; | |
1733 | } | |
1734 | } | |
1735 | else if ((end - values) == 6 && !strncmp(values, "domain", 6)) | |
1736 | { | |
1737 | p->auth_info_required[p->num_auth_info_required] = "domain"; | |
1738 | p->num_auth_info_required ++; | |
1739 | } | |
1740 | else if ((end - values) == 8 && !strncmp(values, "password", 8)) | |
1741 | { | |
1742 | p->auth_info_required[p->num_auth_info_required] = "password"; | |
1743 | p->num_auth_info_required ++; | |
1744 | } | |
1745 | else if ((end - values) == 8 && !strncmp(values, "username", 8)) | |
1746 | { | |
1747 | p->auth_info_required[p->num_auth_info_required] = "username"; | |
1748 | p->num_auth_info_required ++; | |
1749 | } | |
1750 | else | |
1751 | return (0); | |
1752 | ||
1753 | values = (*end) ? end + 1 : end; | |
1754 | } | |
1755 | ||
1756 | if (p->num_auth_info_required == 0) | |
1757 | { | |
1758 | p->auth_info_required[0] = "none"; | |
1759 | p->num_auth_info_required = 1; | |
1760 | } | |
1761 | ||
1762 | /* | |
1763 | * Update the printer-type value as needed... | |
1764 | */ | |
1765 | ||
1766 | if (p->num_auth_info_required > 1 || | |
1767 | strcmp(p->auth_info_required[0], "none")) | |
1768 | p->type |= CUPS_PRINTER_AUTHENTICATED; | |
1769 | else | |
1770 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; | |
1771 | ||
1772 | return (1); | |
1773 | } | |
1774 | ||
1775 | /* | |
1776 | * Grab values from an attribute instead... | |
1777 | */ | |
1778 | ||
1779 | if (!attr || attr->num_values > 4) | |
1780 | return (0); | |
1781 | ||
1782 | for (i = 0; i < attr->num_values; i ++) | |
1783 | { | |
1784 | if (!strcmp(attr->values[i].string.text, "none")) | |
1785 | { | |
1786 | if (p->num_auth_info_required != 0 || attr->num_values != 1) | |
1787 | return (0); | |
1788 | ||
1789 | p->auth_info_required[p->num_auth_info_required] = "none"; | |
1790 | p->num_auth_info_required ++; | |
1791 | ||
1792 | return (1); | |
1793 | } | |
1794 | else if (!strcmp(attr->values[i].string.text, "negotiate")) | |
1795 | { | |
1796 | if (p->num_auth_info_required != 0 || attr->num_values != 1) | |
1797 | return (0); | |
1798 | ||
1799 | p->auth_info_required[p->num_auth_info_required] = "negotiate"; | |
1800 | p->num_auth_info_required ++; | |
1801 | ||
1802 | /* | |
1803 | * Don't allow sharing of queues that require Kerberos authentication. | |
1804 | */ | |
1805 | ||
1806 | if (p->shared) | |
1807 | { | |
1808 | cupsdDeregisterPrinter(p, 1); | |
1809 | p->shared = 0; | |
1810 | } | |
1811 | ||
1812 | return (1); | |
1813 | } | |
1814 | else if (!strcmp(attr->values[i].string.text, "domain")) | |
1815 | { | |
1816 | p->auth_info_required[p->num_auth_info_required] = "domain"; | |
1817 | p->num_auth_info_required ++; | |
1818 | } | |
1819 | else if (!strcmp(attr->values[i].string.text, "password")) | |
1820 | { | |
1821 | p->auth_info_required[p->num_auth_info_required] = "password"; | |
1822 | p->num_auth_info_required ++; | |
1823 | } | |
1824 | else if (!strcmp(attr->values[i].string.text, "username")) | |
1825 | { | |
1826 | p->auth_info_required[p->num_auth_info_required] = "username"; | |
1827 | p->num_auth_info_required ++; | |
1828 | } | |
1829 | else | |
1830 | return (0); | |
1831 | } | |
1832 | ||
1833 | return (1); | |
1834 | } | |
1835 | ||
1836 | ||
1837 | /* | |
1838 | * 'cupsdSetDeviceURI()' - Set the device URI for a printer. | |
1839 | */ | |
1840 | ||
1841 | void | |
1842 | cupsdSetDeviceURI(cupsd_printer_t *p, /* I - Printer */ | |
1843 | const char *uri) /* I - Device URI */ | |
1844 | { | |
1845 | char buffer[1024], /* URI buffer */ | |
1846 | *start, /* Start of data after scheme */ | |
1847 | *slash, /* First slash after scheme:// */ | |
1848 | *ptr; /* Pointer into user@host:port part */ | |
1849 | ||
1850 | ||
1851 | /* | |
1852 | * Set the full device URI.. | |
1853 | */ | |
1854 | ||
1855 | cupsdSetString(&(p->device_uri), uri); | |
1856 | ||
1857 | /* | |
1858 | * Copy the device URI to a temporary buffer so we can sanitize any auth | |
1859 | * info in it... | |
1860 | */ | |
1861 | ||
1862 | strlcpy(buffer, uri, sizeof(buffer)); | |
1863 | ||
1864 | /* | |
1865 | * Find the end of the scheme:// part... | |
1866 | */ | |
1867 | ||
1868 | if ((ptr = strchr(buffer, ':')) != NULL) | |
1869 | { | |
1870 | for (start = ptr + 1; *start; start ++) | |
1871 | if (*start != '/') | |
1872 | break; | |
1873 | ||
1874 | /* | |
1875 | * Find the next slash (/) in the URI... | |
1876 | */ | |
1877 | ||
1878 | if ((slash = strchr(start, '/')) == NULL) | |
1879 | slash = start + strlen(start); /* No slash, point to the end */ | |
1880 | ||
1881 | /* | |
1882 | * Check for an @ sign before the slash... | |
1883 | */ | |
1884 | ||
1885 | if ((ptr = strchr(start, '@')) != NULL && ptr < slash) | |
1886 | { | |
1887 | /* | |
1888 | * Found an @ sign and it is before the resource part, so we have | |
1889 | * an authentication string. Copy the remaining URI over the | |
1890 | * authentication string... | |
1891 | */ | |
1892 | ||
1893 | _cups_strcpy(start, ptr + 1); | |
1894 | } | |
1895 | } | |
1896 | ||
1897 | /* | |
1898 | * Save the sanitized URI... | |
1899 | */ | |
1900 | ||
1901 | cupsdSetString(&(p->sanitized_device_uri), buffer); | |
1902 | } | |
1903 | ||
1904 | ||
1905 | /* | |
1906 | * 'cupsdSetPrinterAttr()' - Set a printer attribute. | |
1907 | */ | |
1908 | ||
1909 | void | |
1910 | cupsdSetPrinterAttr( | |
1911 | cupsd_printer_t *p, /* I - Printer */ | |
1912 | const char *name, /* I - Attribute name */ | |
1913 | char *value) /* I - Attribute value string */ | |
1914 | { | |
1915 | ipp_attribute_t *attr; /* Attribute */ | |
1916 | int i, /* Looping var */ | |
1917 | count; /* Number of values */ | |
1918 | char *ptr, /* Pointer into value */ | |
1919 | *start, /* Start of value */ | |
1920 | quote; /* Quote character */ | |
1921 | ipp_tag_t value_tag; /* Value tag for this attribute */ | |
1922 | ||
1923 | ||
1924 | /* | |
1925 | * Don't allow empty values... | |
1926 | */ | |
1927 | ||
1928 | if (!*value && strcmp(name, "marker-message")) | |
1929 | { | |
1930 | cupsdLogMessage(CUPSD_LOG_ERROR, "Ignoring empty \"%s\" attribute", name); | |
1931 | return; | |
1932 | } | |
1933 | ||
1934 | /* | |
1935 | * Count the number of values... | |
1936 | */ | |
1937 | ||
1938 | for (count = 1, quote = '\0', ptr = value; | |
1939 | *ptr; | |
1940 | ptr ++) | |
1941 | { | |
1942 | if (*ptr == quote) | |
1943 | quote = '\0'; | |
1944 | else if (quote) | |
1945 | continue; | |
1946 | else if (*ptr == '\\' && ptr[1]) | |
1947 | ptr ++; | |
1948 | else if (*ptr == '\'' || *ptr == '\"') | |
1949 | quote = *ptr; | |
1950 | else if (*ptr == '.') | |
1951 | count ++; | |
1952 | } | |
1953 | ||
1954 | /* | |
1955 | * Then add or update the attribute as needed... | |
1956 | */ | |
1957 | ||
1958 | if (!strcmp(name, "marker-levels") || !strcmp(name, "marker-low-levels") || | |
1959 | !strcmp(name, "marker-high-levels")) | |
1960 | { | |
1961 | /* | |
1962 | * Integer values... | |
1963 | */ | |
1964 | ||
1965 | if ((attr = ippFindAttribute(p->attrs, name, IPP_TAG_INTEGER)) != NULL && | |
1966 | attr->num_values < count) | |
1967 | { | |
1968 | ippDeleteAttribute(p->attrs, attr); | |
1969 | attr = NULL; | |
1970 | } | |
1971 | ||
1972 | if (attr) | |
1973 | attr->num_values = count; | |
1974 | else | |
1975 | attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, name, | |
1976 | count, NULL); | |
1977 | ||
1978 | if (!attr) | |
1979 | { | |
1980 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1981 | "Unable to allocate memory for printer attribute " | |
1982 | "(%d values)", count); | |
1983 | return; | |
1984 | } | |
1985 | ||
1986 | for (i = 0; i < count; i ++) | |
1987 | { | |
1988 | if ((ptr = strchr(value, ',')) != NULL) | |
1989 | *ptr++ = '\0'; | |
1990 | ||
1991 | attr->values[i].integer = strtol(value, NULL, 10); | |
1992 | ||
1993 | if (ptr) | |
1994 | value = ptr; | |
1995 | } | |
1996 | } | |
1997 | else | |
1998 | { | |
1999 | /* | |
2000 | * Name or keyword values... | |
2001 | */ | |
2002 | ||
2003 | if (!strcmp(name, "marker-types")) | |
2004 | value_tag = IPP_TAG_KEYWORD; | |
2005 | else if (!strcmp(name, "marker-message")) | |
2006 | value_tag = IPP_TAG_TEXT; | |
2007 | else | |
2008 | value_tag = IPP_TAG_NAME; | |
2009 | ||
2010 | if ((attr = ippFindAttribute(p->attrs, name, value_tag)) != NULL && | |
2011 | attr->num_values < count) | |
2012 | { | |
2013 | ippDeleteAttribute(p->attrs, attr); | |
2014 | attr = NULL; | |
2015 | } | |
2016 | ||
2017 | if (attr) | |
2018 | { | |
2019 | for (i = 0; i < attr->num_values; i ++) | |
2020 | _cupsStrFree(attr->values[i].string.text); | |
2021 | ||
2022 | attr->num_values = count; | |
2023 | } | |
2024 | else | |
2025 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, value_tag, name, | |
2026 | count, NULL, NULL); | |
2027 | ||
2028 | if (!attr) | |
2029 | { | |
2030 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2031 | "Unable to allocate memory for printer attribute " | |
2032 | "(%d values)", count); | |
2033 | return; | |
2034 | } | |
2035 | ||
2036 | for (i = 0, quote = '\0', ptr = value; i < count; i ++) | |
2037 | { | |
2038 | for (start = ptr; *ptr; ptr ++) | |
2039 | { | |
2040 | if (*ptr == quote) | |
2041 | *ptr = quote = '\0'; | |
2042 | else if (quote) | |
2043 | continue; | |
2044 | else if (*ptr == '\\' && ptr[1]) | |
2045 | _cups_strcpy(ptr, ptr + 1); | |
2046 | else if (*ptr == '\'' || *ptr == '\"') | |
2047 | { | |
2048 | quote = *ptr; | |
2049 | ||
2050 | if (ptr == start) | |
2051 | start ++; | |
2052 | else | |
2053 | _cups_strcpy(ptr, ptr + 1); | |
2054 | } | |
2055 | else if (*ptr == '.') | |
2056 | { | |
2057 | *ptr++ = '\0'; | |
2058 | break; | |
2059 | } | |
2060 | } | |
2061 | ||
2062 | attr->values[i].string.text = _cupsStrAlloc(start); | |
2063 | } | |
2064 | } | |
2065 | } | |
2066 | ||
2067 | ||
2068 | /* | |
2069 | * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file. | |
2070 | */ | |
2071 | ||
2072 | void | |
2073 | cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */ | |
2074 | { | |
2075 | int i; /* Looping var */ | |
2076 | char resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
2077 | int num_air; /* Number of auth-info-required values */ | |
2078 | const char * const *air; /* auth-info-required values */ | |
2079 | cupsd_location_t *auth; /* Pointer to authentication element */ | |
2080 | const char *auth_supported; /* Authentication supported */ | |
2081 | ipp_t *oldattrs; /* Old printer attributes */ | |
2082 | ipp_attribute_t *attr; /* Attribute data */ | |
2083 | char *name, /* Current user/group name */ | |
2084 | *filter; /* Current filter */ | |
2085 | static const char * const air_none[] = | |
2086 | { /* No authentication */ | |
2087 | "none" | |
2088 | }; | |
2089 | static const char * const air_userpass[] = | |
2090 | { /* Basic/Digest authentication */ | |
2091 | "username", | |
2092 | "password" | |
2093 | }; | |
2094 | ||
2095 | ||
2096 | DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name, | |
2097 | p->type)); | |
2098 | ||
2099 | /* | |
2100 | * Make sure that we have the common attributes defined... | |
2101 | */ | |
2102 | ||
2103 | if (!CommonData) | |
2104 | cupsdCreateCommonData(); | |
2105 | ||
2106 | /* | |
2107 | * Clear out old filters, if any... | |
2108 | */ | |
2109 | ||
2110 | delete_printer_filters(p); | |
2111 | ||
2112 | /* | |
2113 | * Figure out the authentication that is required for the printer. | |
2114 | */ | |
2115 | ||
2116 | auth_supported = "requesting-user-name"; | |
2117 | num_air = 1; | |
2118 | air = air_none; | |
2119 | ||
2120 | if (p->num_auth_info_required > 0 && strcmp(p->auth_info_required[0], "none")) | |
2121 | { | |
2122 | num_air = p->num_auth_info_required; | |
2123 | air = p->auth_info_required; | |
2124 | } | |
2125 | else if (p->type & CUPS_PRINTER_AUTHENTICATED) | |
2126 | { | |
2127 | num_air = 2; | |
2128 | air = air_userpass; | |
2129 | } | |
2130 | ||
2131 | if (p->type & CUPS_PRINTER_CLASS) | |
2132 | snprintf(resource, sizeof(resource), "/classes/%s", p->name); | |
2133 | else | |
2134 | snprintf(resource, sizeof(resource), "/printers/%s", p->name); | |
2135 | ||
2136 | if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL || | |
2137 | auth->type == CUPSD_AUTH_NONE) | |
2138 | auth = cupsdFindPolicyOp(p->op_policy_ptr, IPP_PRINT_JOB); | |
2139 | ||
2140 | if (auth) | |
2141 | { | |
2142 | int auth_type; /* Authentication type */ | |
2143 | ||
2144 | ||
2145 | if ((auth_type = auth->type) == CUPSD_AUTH_DEFAULT) | |
2146 | auth_type = cupsdDefaultAuthType(); | |
2147 | ||
2148 | if (auth_type == CUPSD_AUTH_BASIC || auth_type == CUPSD_AUTH_BASICDIGEST) | |
2149 | auth_supported = "basic"; | |
2150 | else if (auth_type == CUPSD_AUTH_DIGEST) | |
2151 | auth_supported = "digest"; | |
2152 | #ifdef HAVE_GSSAPI | |
2153 | else if (auth_type == CUPSD_AUTH_NEGOTIATE) | |
2154 | auth_supported = "negotiate"; | |
2155 | #endif /* HAVE_GSSAPI */ | |
2156 | ||
2157 | if (auth_type != CUPSD_AUTH_NONE) | |
2158 | p->type |= CUPS_PRINTER_AUTHENTICATED; | |
2159 | else | |
2160 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; | |
2161 | } | |
2162 | else | |
2163 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; | |
2164 | ||
2165 | /* | |
2166 | * Create the required IPP attributes for a printer... | |
2167 | */ | |
2168 | ||
2169 | oldattrs = p->attrs; | |
2170 | p->attrs = ippNew(); | |
2171 | ||
2172 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
2173 | "uri-authentication-supported", NULL, auth_supported); | |
2174 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
2175 | "uri-security-supported", NULL, "none"); | |
2176 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL, | |
2177 | p->name); | |
2178 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", | |
2179 | NULL, p->location ? p->location : ""); | |
2180 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", | |
2181 | NULL, p->info ? p->info : ""); | |
2182 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-uuid", NULL, | |
2183 | p->uuid); | |
2184 | ||
2185 | if (cupsArrayCount(p->users) > 0) | |
2186 | { | |
2187 | if (p->deny_users) | |
2188 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2189 | "requesting-user-name-denied", | |
2190 | cupsArrayCount(p->users), NULL, NULL); | |
2191 | else | |
2192 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2193 | "requesting-user-name-allowed", | |
2194 | cupsArrayCount(p->users), NULL, NULL); | |
2195 | ||
2196 | for (i = 0, name = (char *)cupsArrayFirst(p->users); | |
2197 | name; | |
2198 | i ++, name = (char *)cupsArrayNext(p->users)) | |
2199 | attr->values[i].string.text = _cupsStrRetain(name); | |
2200 | } | |
2201 | ||
2202 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2203 | "job-quota-period", p->quota_period); | |
2204 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2205 | "job-k-limit", p->k_limit); | |
2206 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2207 | "job-page-limit", p->page_limit); | |
2208 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
2209 | "auth-info-required", num_air, NULL, air); | |
2210 | ||
2211 | if (cupsArrayCount(Banners) > 0) | |
2212 | { | |
2213 | /* | |
2214 | * Setup the job-sheets-default attribute... | |
2215 | */ | |
2216 | ||
2217 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2218 | "job-sheets-default", 2, NULL, NULL); | |
2219 | ||
2220 | if (attr != NULL) | |
2221 | { | |
2222 | attr->values[0].string.text = _cupsStrAlloc(Classification ? | |
2223 | Classification : p->job_sheets[0]); | |
2224 | attr->values[1].string.text = _cupsStrAlloc(Classification ? | |
2225 | Classification : p->job_sheets[1]); | |
2226 | } | |
2227 | } | |
2228 | ||
2229 | p->raw = 0; | |
2230 | p->remote = 0; | |
2231 | ||
2232 | /* | |
2233 | * Assign additional attributes depending on whether this is a printer | |
2234 | * or class... | |
2235 | */ | |
2236 | ||
2237 | if (p->type & CUPS_PRINTER_CLASS) | |
2238 | { | |
2239 | p->raw = 1; | |
2240 | p->type &= ~CUPS_PRINTER_OPTIONS; | |
2241 | ||
2242 | /* | |
2243 | * Add class-specific attributes... | |
2244 | */ | |
2245 | ||
2246 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
2247 | "printer-make-and-model", NULL, "Local Printer Class"); | |
2248 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, | |
2249 | "file:///dev/null"); | |
2250 | ||
2251 | if (p->num_printers > 0) | |
2252 | { | |
2253 | /* | |
2254 | * Add a list of member names; URIs are added in copy_printer_attrs... | |
2255 | */ | |
2256 | ||
2257 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2258 | "member-names", p->num_printers, NULL, NULL); | |
2259 | p->type |= CUPS_PRINTER_OPTIONS; | |
2260 | ||
2261 | for (i = 0; i < p->num_printers; i ++) | |
2262 | { | |
2263 | if (attr != NULL) | |
2264 | attr->values[i].string.text = _cupsStrRetain(p->printers[i]->name); | |
2265 | ||
2266 | p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type; | |
2267 | } | |
2268 | } | |
2269 | } | |
2270 | else | |
2271 | { | |
2272 | /* | |
2273 | * Add printer-specific attributes... | |
2274 | */ | |
2275 | ||
2276 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, | |
2277 | p->sanitized_device_uri); | |
2278 | ||
2279 | /* | |
2280 | * Assign additional attributes from the PPD file (if any)... | |
2281 | */ | |
2282 | ||
2283 | load_ppd(p); | |
2284 | ||
2285 | /* | |
2286 | * Add filters for printer... | |
2287 | */ | |
2288 | ||
2289 | cupsdSetPrinterReasons(p, "-cups-missing-filter-warning," | |
2290 | "cups-insecure-filter-warning"); | |
2291 | ||
2292 | if (p->pc && p->pc->filters) | |
2293 | { | |
2294 | for (filter = (char *)cupsArrayFirst(p->pc->filters); | |
2295 | filter; | |
2296 | filter = (char *)cupsArrayNext(p->pc->filters)) | |
2297 | add_printer_filter(p, p->filetype, filter); | |
2298 | } | |
2299 | else if (!(p->type & CUPS_PRINTER_REMOTE)) | |
2300 | { | |
2301 | char interface[1024]; /* Interface script */ | |
2302 | ||
2303 | ||
2304 | snprintf(interface, sizeof(interface), "%s/interfaces/%s", ServerRoot, | |
2305 | p->name); | |
2306 | if (!access(interface, X_OK)) | |
2307 | { | |
2308 | /* | |
2309 | * Yes, we have a System V style interface script; use it! | |
2310 | */ | |
2311 | ||
2312 | snprintf(interface, sizeof(interface), "*/* 0 %s/interfaces/%s", | |
2313 | ServerRoot, p->name); | |
2314 | add_printer_filter(p, p->filetype, interface); | |
2315 | } | |
2316 | else | |
2317 | { | |
2318 | /* | |
2319 | * Add a filter from application/vnd.cups-raw to printer/name to | |
2320 | * handle "raw" printing by users. | |
2321 | */ | |
2322 | ||
2323 | add_printer_filter(p, p->filetype, "application/vnd.cups-raw 0 -"); | |
2324 | ||
2325 | /* | |
2326 | * Add a PostScript filter, since this is still possibly PS printer. | |
2327 | */ | |
2328 | ||
2329 | add_printer_filter(p, p->filetype, | |
2330 | "application/vnd.cups-postscript 0 -"); | |
2331 | } | |
2332 | } | |
2333 | ||
2334 | if (p->pc && p->pc->prefilters) | |
2335 | { | |
2336 | if (!p->prefiltertype) | |
2337 | p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", p->name); | |
2338 | ||
2339 | for (filter = (char *)cupsArrayFirst(p->pc->prefilters); | |
2340 | filter; | |
2341 | filter = (char *)cupsArrayNext(p->pc->prefilters)) | |
2342 | add_printer_filter(p, p->prefiltertype, filter); | |
2343 | } | |
2344 | } | |
2345 | ||
2346 | /* | |
2347 | * Copy marker attributes as needed... | |
2348 | */ | |
2349 | ||
2350 | if (oldattrs) | |
2351 | { | |
2352 | ipp_attribute_t *oldattr; /* Old attribute */ | |
2353 | ||
2354 | ||
2355 | if ((oldattr = ippFindAttribute(oldattrs, "marker-colors", | |
2356 | IPP_TAG_NAME)) != NULL) | |
2357 | { | |
2358 | if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2359 | "marker-colors", oldattr->num_values, NULL, | |
2360 | NULL)) != NULL) | |
2361 | { | |
2362 | for (i = 0; i < oldattr->num_values; i ++) | |
2363 | attr->values[i].string.text = | |
2364 | _cupsStrRetain(oldattr->values[i].string.text); | |
2365 | } | |
2366 | } | |
2367 | ||
2368 | if ((oldattr = ippFindAttribute(oldattrs, "marker-levels", | |
2369 | IPP_TAG_INTEGER)) != NULL) | |
2370 | { | |
2371 | if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2372 | "marker-levels", oldattr->num_values, | |
2373 | NULL)) != NULL) | |
2374 | { | |
2375 | for (i = 0; i < oldattr->num_values; i ++) | |
2376 | attr->values[i].integer = oldattr->values[i].integer; | |
2377 | } | |
2378 | } | |
2379 | ||
2380 | if ((oldattr = ippFindAttribute(oldattrs, "marker-message", | |
2381 | IPP_TAG_TEXT)) != NULL) | |
2382 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "marker-message", | |
2383 | NULL, oldattr->values[0].string.text); | |
2384 | ||
2385 | if ((oldattr = ippFindAttribute(oldattrs, "marker-low-levels", | |
2386 | IPP_TAG_INTEGER)) != NULL) | |
2387 | { | |
2388 | if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2389 | "marker-low-levels", oldattr->num_values, | |
2390 | NULL)) != NULL) | |
2391 | { | |
2392 | for (i = 0; i < oldattr->num_values; i ++) | |
2393 | attr->values[i].integer = oldattr->values[i].integer; | |
2394 | } | |
2395 | } | |
2396 | ||
2397 | if ((oldattr = ippFindAttribute(oldattrs, "marker-high-levels", | |
2398 | IPP_TAG_INTEGER)) != NULL) | |
2399 | { | |
2400 | if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2401 | "marker-high-levels", oldattr->num_values, | |
2402 | NULL)) != NULL) | |
2403 | { | |
2404 | for (i = 0; i < oldattr->num_values; i ++) | |
2405 | attr->values[i].integer = oldattr->values[i].integer; | |
2406 | } | |
2407 | } | |
2408 | ||
2409 | if ((oldattr = ippFindAttribute(oldattrs, "marker-names", | |
2410 | IPP_TAG_NAME)) != NULL) | |
2411 | { | |
2412 | if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2413 | "marker-names", oldattr->num_values, NULL, | |
2414 | NULL)) != NULL) | |
2415 | { | |
2416 | for (i = 0; i < oldattr->num_values; i ++) | |
2417 | attr->values[i].string.text = | |
2418 | _cupsStrRetain(oldattr->values[i].string.text); | |
2419 | } | |
2420 | } | |
2421 | ||
2422 | if ((oldattr = ippFindAttribute(oldattrs, "marker-types", | |
2423 | IPP_TAG_KEYWORD)) != NULL) | |
2424 | { | |
2425 | if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
2426 | "marker-types", oldattr->num_values, NULL, | |
2427 | NULL)) != NULL) | |
2428 | { | |
2429 | for (i = 0; i < oldattr->num_values; i ++) | |
2430 | attr->values[i].string.text = | |
2431 | _cupsStrRetain(oldattr->values[i].string.text); | |
2432 | } | |
2433 | } | |
2434 | ||
2435 | ippDelete(oldattrs); | |
2436 | } | |
2437 | ||
2438 | /* | |
2439 | * Force sharing off for remote queues... | |
2440 | */ | |
2441 | ||
2442 | if (p->type & CUPS_PRINTER_REMOTE) | |
2443 | p->shared = 0; | |
2444 | ||
2445 | /* | |
2446 | * Populate the document-format-supported attribute... | |
2447 | */ | |
2448 | ||
2449 | add_printer_formats(p); | |
2450 | ||
2451 | DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p->name, | |
2452 | p->type)); | |
2453 | ||
2454 | /* | |
2455 | * Add name-default attributes... | |
2456 | */ | |
2457 | ||
2458 | add_printer_defaults(p); | |
2459 | ||
2460 | #ifdef __sgi | |
2461 | /* | |
2462 | * Write the IRIX printer config and status files... | |
2463 | */ | |
2464 | ||
2465 | write_irix_config(p); | |
2466 | write_irix_state(p); | |
2467 | #endif /* __sgi */ | |
2468 | ||
2469 | /* | |
2470 | * Let the browse protocols reflect the change | |
2471 | */ | |
2472 | ||
2473 | cupsdRegisterPrinter(p); | |
2474 | } | |
2475 | ||
2476 | ||
2477 | /* | |
2478 | * 'cupsdSetPrinterReasons()' - Set/update the reasons strings. | |
2479 | */ | |
2480 | ||
2481 | int /* O - 1 if something changed, 0 otherwise */ | |
2482 | cupsdSetPrinterReasons( | |
2483 | cupsd_printer_t *p, /* I - Printer */ | |
2484 | const char *s) /* I - Reasons strings */ | |
2485 | { | |
2486 | int i, /* Looping var */ | |
2487 | changed = 0; /* Did something change? */ | |
2488 | const char *sptr; /* Pointer into reasons */ | |
2489 | char reason[255], /* Reason string */ | |
2490 | *rptr; /* Pointer into reason */ | |
2491 | ||
2492 | ||
2493 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
2494 | "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p, p->name, s); | |
2495 | ||
2496 | if (s[0] == '-' || s[0] == '+') | |
2497 | { | |
2498 | /* | |
2499 | * Add/remove reasons... | |
2500 | */ | |
2501 | ||
2502 | sptr = s + 1; | |
2503 | } | |
2504 | else | |
2505 | { | |
2506 | /* | |
2507 | * Replace reasons... | |
2508 | */ | |
2509 | ||
2510 | sptr = s; | |
2511 | ||
2512 | for (i = 0; i < p->num_reasons; i ++) | |
2513 | _cupsStrFree(p->reasons[i]); | |
2514 | ||
2515 | p->num_reasons = 0; | |
2516 | changed = 1; | |
2517 | ||
2518 | dirty_printer(p); | |
2519 | } | |
2520 | ||
2521 | if (!strcmp(s, "none")) | |
2522 | return (changed); | |
2523 | ||
2524 | /* | |
2525 | * Loop through all of the reasons... | |
2526 | */ | |
2527 | ||
2528 | while (*sptr) | |
2529 | { | |
2530 | /* | |
2531 | * Skip leading whitespace and commas... | |
2532 | */ | |
2533 | ||
2534 | while (isspace(*sptr & 255) || *sptr == ',') | |
2535 | sptr ++; | |
2536 | ||
2537 | for (rptr = reason; *sptr && !isspace(*sptr & 255) && *sptr != ','; sptr ++) | |
2538 | if (rptr < (reason + sizeof(reason) - 1)) | |
2539 | *rptr++ = *sptr; | |
2540 | ||
2541 | if (rptr == reason) | |
2542 | break; | |
2543 | ||
2544 | *rptr = '\0'; | |
2545 | ||
2546 | if (s[0] == '-') | |
2547 | { | |
2548 | /* | |
2549 | * Remove reason... | |
2550 | */ | |
2551 | ||
2552 | for (i = 0; i < p->num_reasons; i ++) | |
2553 | if (!strcmp(reason, p->reasons[i])) | |
2554 | { | |
2555 | /* | |
2556 | * Found a match, so remove it... | |
2557 | */ | |
2558 | ||
2559 | p->num_reasons --; | |
2560 | changed = 1; | |
2561 | _cupsStrFree(p->reasons[i]); | |
2562 | ||
2563 | if (i < p->num_reasons) | |
2564 | memmove(p->reasons + i, p->reasons + i + 1, | |
2565 | (p->num_reasons - i) * sizeof(char *)); | |
2566 | ||
2567 | if (!strcmp(reason, "paused") && p->state == IPP_PRINTER_STOPPED) | |
2568 | cupsdSetPrinterState(p, IPP_PRINTER_IDLE, 1); | |
2569 | ||
2570 | if (strcmp(reason, "connecting-to-device")) | |
2571 | dirty_printer(p); | |
2572 | break; | |
2573 | } | |
2574 | } | |
2575 | else if (p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0]))) | |
2576 | { | |
2577 | /* | |
2578 | * Add reason... | |
2579 | */ | |
2580 | ||
2581 | for (i = 0; i < p->num_reasons; i ++) | |
2582 | if (!strcmp(reason, p->reasons[i])) | |
2583 | break; | |
2584 | ||
2585 | if (i >= p->num_reasons) | |
2586 | { | |
2587 | if (!strncmp(reason, "cups-ipp-missing-", 17) || | |
2588 | !strncmp(reason, "cups-ipp-wrong-", 15)) | |
2589 | log_ipp_conformance(p, reason); | |
2590 | ||
2591 | if (i >= (int)(sizeof(p->reasons) / sizeof(p->reasons[0]))) | |
2592 | { | |
2593 | cupsdLogMessage(CUPSD_LOG_ALERT, | |
2594 | "Too many printer-state-reasons values for %s (%d)", | |
2595 | p->name, i + 1); | |
2596 | return (changed); | |
2597 | } | |
2598 | ||
2599 | p->reasons[i] = _cupsStrAlloc(reason); | |
2600 | p->num_reasons ++; | |
2601 | changed = 1; | |
2602 | ||
2603 | if (!strcmp(reason, "paused") && p->state != IPP_PRINTER_STOPPED) | |
2604 | cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 1); | |
2605 | ||
2606 | if (strcmp(reason, "connecting-to-device")) | |
2607 | dirty_printer(p); | |
2608 | } | |
2609 | } | |
2610 | } | |
2611 | ||
2612 | return (changed); | |
2613 | } | |
2614 | ||
2615 | ||
2616 | /* | |
2617 | * 'cupsdSetPrinterState()' - Update the current state of a printer. | |
2618 | */ | |
2619 | ||
2620 | void | |
2621 | cupsdSetPrinterState( | |
2622 | cupsd_printer_t *p, /* I - Printer to change */ | |
2623 | ipp_pstate_t s, /* I - New state */ | |
2624 | int update) /* I - Update printers.conf? */ | |
2625 | { | |
2626 | cupsd_job_t *job; /* Current job */ | |
2627 | ipp_pstate_t old_state; /* Old printer state */ | |
2628 | static const char * const printer_states[] = | |
2629 | { /* State strings */ | |
2630 | "idle", | |
2631 | "processing", | |
2632 | "stopped" | |
2633 | }; | |
2634 | ||
2635 | ||
2636 | /* | |
2637 | * Set the new state... | |
2638 | */ | |
2639 | ||
2640 | old_state = p->state; | |
2641 | p->state = s; | |
2642 | ||
2643 | if (old_state != s) | |
2644 | { | |
2645 | cupsdAddEvent(s == IPP_PRINTER_STOPPED ? CUPSD_EVENT_PRINTER_STOPPED : | |
2646 | CUPSD_EVENT_PRINTER_STATE, p, NULL, | |
2647 | "%s \"%s\" state changed to %s.", | |
2648 | (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer", | |
2649 | p->name, printer_states[p->state - IPP_PRINTER_IDLE]); | |
2650 | ||
2651 | /* | |
2652 | * Let the browse code know this needs to be updated... | |
2653 | */ | |
2654 | ||
2655 | p->state_time = time(NULL); | |
2656 | ||
2657 | #ifdef __sgi | |
2658 | write_irix_state(p); | |
2659 | #endif /* __sgi */ | |
2660 | } | |
2661 | ||
2662 | /* | |
2663 | * Set/clear the paused reason as needed... | |
2664 | */ | |
2665 | ||
2666 | if (s == IPP_PRINTER_STOPPED) | |
2667 | cupsdSetPrinterReasons(p, "+paused"); | |
2668 | else | |
2669 | cupsdSetPrinterReasons(p, "-paused"); | |
2670 | ||
2671 | if (old_state != s) | |
2672 | { | |
2673 | for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs); | |
2674 | job; | |
2675 | job = (cupsd_job_t *)cupsArrayNext(ActiveJobs)) | |
2676 | if (job->reasons && job->state_value == IPP_JOB_PENDING && | |
2677 | !_cups_strcasecmp(job->dest, p->name)) | |
2678 | ippSetString(job->attrs, &job->reasons, 0, | |
2679 | s == IPP_PRINTER_STOPPED ? "printer-stopped" : "none"); | |
2680 | } | |
2681 | ||
2682 | /* | |
2683 | * Clear the message for the queue when going to processing... | |
2684 | */ | |
2685 | ||
2686 | if (s == IPP_PRINTER_PROCESSING) | |
2687 | p->state_message[0] = '\0'; | |
2688 | ||
2689 | /* | |
2690 | * Let the browse protocols reflect the change... | |
2691 | */ | |
2692 | ||
2693 | if (update) | |
2694 | cupsdRegisterPrinter(p); | |
2695 | ||
2696 | /* | |
2697 | * Save the printer configuration if a printer goes from idle or processing | |
2698 | * to stopped (or visa-versa)... | |
2699 | */ | |
2700 | ||
2701 | if (update && | |
2702 | (old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED)) | |
2703 | dirty_printer(p); | |
2704 | } | |
2705 | ||
2706 | ||
2707 | /* | |
2708 | * 'cupsdStopPrinter()' - Stop a printer from printing any jobs... | |
2709 | */ | |
2710 | ||
2711 | void | |
2712 | cupsdStopPrinter(cupsd_printer_t *p, /* I - Printer to stop */ | |
2713 | int update)/* I - Update printers.conf? */ | |
2714 | { | |
2715 | /* | |
2716 | * Set the printer state... | |
2717 | */ | |
2718 | ||
2719 | cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, update); | |
2720 | ||
2721 | /* | |
2722 | * See if we have a job printing on this printer... | |
2723 | */ | |
2724 | ||
2725 | if (p->job && p->job->state_value == IPP_JOB_PROCESSING) | |
2726 | cupsdSetJobState(p->job, IPP_JOB_PENDING, CUPSD_JOB_DEFAULT, | |
2727 | "Job stopped due to printer being paused."); | |
2728 | } | |
2729 | ||
2730 | ||
2731 | /* | |
2732 | * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file. | |
2733 | */ | |
2734 | ||
2735 | int /* O - 1 if successful, 0 otherwise */ | |
2736 | cupsdUpdatePrinterPPD( | |
2737 | cupsd_printer_t *p, /* I - Printer */ | |
2738 | int num_keywords, /* I - Number of keywords */ | |
2739 | cups_option_t *keywords) /* I - Keywords */ | |
2740 | { | |
2741 | int i; /* Looping var */ | |
2742 | cups_file_t *src, /* Original file */ | |
2743 | *dst; /* New file */ | |
2744 | char srcfile[1024], /* Original filename */ | |
2745 | dstfile[1024], /* New filename */ | |
2746 | line[1024], /* Line from file */ | |
2747 | keystring[41]; /* Keyword from line */ | |
2748 | cups_option_t *keyword; /* Current keyword */ | |
2749 | ||
2750 | ||
2751 | cupsdLogMessage(CUPSD_LOG_INFO, "Updating keywords in PPD file for %s...", | |
2752 | p->name); | |
2753 | ||
2754 | /* | |
2755 | * Get the old and new PPD filenames... | |
2756 | */ | |
2757 | ||
2758 | snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd.O", ServerRoot, p->name); | |
2759 | snprintf(dstfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot, p->name); | |
2760 | ||
2761 | /* | |
2762 | * Rename the old file and open the old and new... | |
2763 | */ | |
2764 | ||
2765 | if (rename(dstfile, srcfile)) | |
2766 | { | |
2767 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to backup PPD file for %s: %s", | |
2768 | p->name, strerror(errno)); | |
2769 | return (0); | |
2770 | } | |
2771 | ||
2772 | if ((src = cupsFileOpen(srcfile, "r")) == NULL) | |
2773 | { | |
2774 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open PPD file \"%s\": %s", | |
2775 | srcfile, strerror(errno)); | |
2776 | rename(srcfile, dstfile); | |
2777 | return (0); | |
2778 | } | |
2779 | ||
2780 | if ((dst = cupsFileOpen(dstfile, "w")) == NULL) | |
2781 | { | |
2782 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create PPD file \"%s\": %s", | |
2783 | dstfile, strerror(errno)); | |
2784 | cupsFileClose(src); | |
2785 | rename(srcfile, dstfile); | |
2786 | return (0); | |
2787 | } | |
2788 | ||
2789 | /* | |
2790 | * Copy the first line and then write out all of the keywords... | |
2791 | */ | |
2792 | ||
2793 | if (!cupsFileGets(src, line, sizeof(line))) | |
2794 | { | |
2795 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s", | |
2796 | srcfile, strerror(errno)); | |
2797 | cupsFileClose(src); | |
2798 | cupsFileClose(dst); | |
2799 | rename(srcfile, dstfile); | |
2800 | return (0); | |
2801 | } | |
2802 | ||
2803 | cupsFilePrintf(dst, "%s\n", line); | |
2804 | ||
2805 | for (i = num_keywords, keyword = keywords; i > 0; i --, keyword ++) | |
2806 | { | |
2807 | cupsdLogMessage(CUPSD_LOG_DEBUG, "*%s: %s", keyword->name, keyword->value); | |
2808 | cupsFilePrintf(dst, "*%s: %s\n", keyword->name, keyword->value); | |
2809 | } | |
2810 | ||
2811 | /* | |
2812 | * Then copy the rest of the PPD file, dropping any keywords we changed. | |
2813 | */ | |
2814 | ||
2815 | while (cupsFileGets(src, line, sizeof(line))) | |
2816 | { | |
2817 | /* | |
2818 | * Skip keywords we've already set... | |
2819 | */ | |
2820 | ||
2821 | if (sscanf(line, "*%40[^:]:", keystring) == 1 && | |
2822 | cupsGetOption(keystring, num_keywords, keywords)) | |
2823 | continue; | |
2824 | ||
2825 | /* | |
2826 | * Otherwise write the line... | |
2827 | */ | |
2828 | ||
2829 | cupsFilePrintf(dst, "%s\n", line); | |
2830 | } | |
2831 | ||
2832 | /* | |
2833 | * Close files and return... | |
2834 | */ | |
2835 | ||
2836 | cupsFileClose(src); | |
2837 | cupsFileClose(dst); | |
2838 | ||
2839 | return (1); | |
2840 | } | |
2841 | ||
2842 | ||
2843 | /* | |
2844 | * 'cupsdUpdatePrinters()' - Update printers after a partial reload. | |
2845 | */ | |
2846 | ||
2847 | void | |
2848 | cupsdUpdatePrinters(void) | |
2849 | { | |
2850 | cupsd_printer_t *p; /* Current printer */ | |
2851 | ||
2852 | ||
2853 | /* | |
2854 | * Loop through the printers and recreate the printer attributes | |
2855 | * for any local printers since the policy and/or access control | |
2856 | * stuff may have changed. Also, if browsing is disabled, remove | |
2857 | * any remote printers... | |
2858 | */ | |
2859 | ||
2860 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
2861 | p; | |
2862 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
2863 | { | |
2864 | /* | |
2865 | * Update the operation policy pointer... | |
2866 | */ | |
2867 | ||
2868 | if ((p->op_policy_ptr = cupsdFindPolicy(p->op_policy)) == NULL) | |
2869 | p->op_policy_ptr = DefaultPolicyPtr; | |
2870 | ||
2871 | /* | |
2872 | * Update printer attributes... | |
2873 | */ | |
2874 | ||
2875 | cupsdSetPrinterAttrs(p); | |
2876 | } | |
2877 | } | |
2878 | ||
2879 | ||
2880 | /* | |
2881 | * 'cupsdValidateDest()' - Validate a printer/class destination. | |
2882 | */ | |
2883 | ||
2884 | const char * /* O - Printer or class name */ | |
2885 | cupsdValidateDest( | |
2886 | const char *uri, /* I - Printer URI */ | |
2887 | cups_ptype_t *dtype, /* O - Type (printer or class) */ | |
2888 | cupsd_printer_t **printer) /* O - Printer pointer */ | |
2889 | { | |
2890 | cupsd_printer_t *p; /* Current printer */ | |
2891 | char localname[1024],/* Localized hostname */ | |
2892 | *lptr, /* Pointer into localized hostname */ | |
2893 | *sptr, /* Pointer into server name */ | |
2894 | *rptr, /* Pointer into resource */ | |
2895 | scheme[32], /* Scheme portion of URI */ | |
2896 | username[64], /* Username portion of URI */ | |
2897 | hostname[HTTP_MAX_HOST], | |
2898 | /* Host portion of URI */ | |
2899 | resource[HTTP_MAX_URI]; | |
2900 | /* Resource portion of URI */ | |
2901 | int port; /* Port portion of URI */ | |
2902 | ||
2903 | ||
2904 | DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri, | |
2905 | dtype, printer)); | |
2906 | ||
2907 | /* | |
2908 | * Initialize return values... | |
2909 | */ | |
2910 | ||
2911 | if (printer) | |
2912 | *printer = NULL; | |
2913 | ||
2914 | if (dtype) | |
2915 | *dtype = (cups_ptype_t)0; | |
2916 | ||
2917 | /* | |
2918 | * Pull the hostname and resource from the URI... | |
2919 | */ | |
2920 | ||
2921 | httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), | |
2922 | username, sizeof(username), hostname, sizeof(hostname), | |
2923 | &port, resource, sizeof(resource)); | |
2924 | ||
2925 | /* | |
2926 | * See if the resource is a class or printer... | |
2927 | */ | |
2928 | ||
2929 | if (!strncmp(resource, "/classes/", 9)) | |
2930 | { | |
2931 | /* | |
2932 | * Class... | |
2933 | */ | |
2934 | ||
2935 | rptr = resource + 9; | |
2936 | } | |
2937 | else if (!strncmp(resource, "/printers/", 10)) | |
2938 | { | |
2939 | /* | |
2940 | * Printer... | |
2941 | */ | |
2942 | ||
2943 | rptr = resource + 10; | |
2944 | } | |
2945 | else | |
2946 | { | |
2947 | /* | |
2948 | * Bad resource name... | |
2949 | */ | |
2950 | ||
2951 | return (NULL); | |
2952 | } | |
2953 | ||
2954 | /* | |
2955 | * See if the printer or class name exists... | |
2956 | */ | |
2957 | ||
2958 | p = cupsdFindDest(rptr); | |
2959 | ||
2960 | if (p == NULL && strchr(rptr, '@') == NULL) | |
2961 | return (NULL); | |
2962 | else if (p != NULL) | |
2963 | { | |
2964 | if (printer) | |
2965 | *printer = p; | |
2966 | ||
2967 | if (dtype) | |
2968 | *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE); | |
2969 | ||
2970 | return (p->name); | |
2971 | } | |
2972 | ||
2973 | /* | |
2974 | * Change localhost to the server name... | |
2975 | */ | |
2976 | ||
2977 | if (!_cups_strcasecmp(hostname, "localhost")) | |
2978 | strlcpy(hostname, ServerName, sizeof(hostname)); | |
2979 | ||
2980 | strlcpy(localname, hostname, sizeof(localname)); | |
2981 | ||
2982 | if (!_cups_strcasecmp(hostname, ServerName)) | |
2983 | { | |
2984 | /* | |
2985 | * Localize the hostname... | |
2986 | */ | |
2987 | ||
2988 | lptr = strchr(localname, '.'); | |
2989 | sptr = strchr(ServerName, '.'); | |
2990 | ||
2991 | if (sptr != NULL && lptr != NULL) | |
2992 | { | |
2993 | /* | |
2994 | * Strip the common domain name components... | |
2995 | */ | |
2996 | ||
2997 | while (lptr != NULL) | |
2998 | { | |
2999 | if (!_cups_strcasecmp(lptr, sptr)) | |
3000 | { | |
3001 | *lptr = '\0'; | |
3002 | break; | |
3003 | } | |
3004 | else | |
3005 | lptr = strchr(lptr + 1, '.'); | |
3006 | } | |
3007 | } | |
3008 | } | |
3009 | ||
3010 | DEBUG_printf(("localized hostname is \"%s\"...\n", localname)); | |
3011 | ||
3012 | /* | |
3013 | * Find a matching printer or class... | |
3014 | */ | |
3015 | ||
3016 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
3017 | p; | |
3018 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
3019 | if (!_cups_strcasecmp(p->hostname, localname) && | |
3020 | !_cups_strcasecmp(p->name, rptr)) | |
3021 | { | |
3022 | if (printer) | |
3023 | *printer = p; | |
3024 | ||
3025 | if (dtype) | |
3026 | *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE); | |
3027 | ||
3028 | return (p->name); | |
3029 | } | |
3030 | ||
3031 | return (NULL); | |
3032 | } | |
3033 | ||
3034 | ||
3035 | /* | |
3036 | * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications | |
3037 | * that need it... | |
3038 | */ | |
3039 | ||
3040 | void | |
3041 | cupsdWritePrintcap(void) | |
3042 | { | |
3043 | int i; /* Looping var */ | |
3044 | cups_file_t *fp; /* Printcap file */ | |
3045 | cupsd_printer_t *p; /* Current printer */ | |
3046 | ||
3047 | ||
3048 | #ifdef __sgi | |
3049 | /* | |
3050 | * Update the IRIX printer state for the default printer; if | |
3051 | * no printers remain, then the default printer file will be | |
3052 | * removed... | |
3053 | */ | |
3054 | ||
3055 | write_irix_state(DefaultPrinter); | |
3056 | #endif /* __sgi */ | |
3057 | ||
3058 | /* | |
3059 | * See if we have a printcap file; if not, don't bother writing it. | |
3060 | */ | |
3061 | ||
3062 | if (!Printcap || !*Printcap) | |
3063 | return; | |
3064 | ||
3065 | cupsdLogMessage(CUPSD_LOG_INFO, "Generating printcap %s...", Printcap); | |
3066 | ||
3067 | /* | |
3068 | * Open the printcap file... | |
3069 | */ | |
3070 | ||
3071 | if ((fp = cupsFileOpen(Printcap, "w")) == NULL) | |
3072 | return; | |
3073 | ||
3074 | /* | |
3075 | * Put a comment header at the top so that users will know where the | |
3076 | * data has come from... | |
3077 | */ | |
3078 | ||
3079 | if (PrintcapFormat != PRINTCAP_PLIST) | |
3080 | cupsFilePrintf(fp, "# This file was automatically generated by cupsd(8) " | |
3081 | "from the\n" | |
3082 | "# %s/printers.conf file. All changes to this file\n" | |
3083 | "# will be lost.\n", ServerRoot); | |
3084 | ||
3085 | /* | |
3086 | * Write a new printcap with the current list of printers. | |
3087 | */ | |
3088 | ||
3089 | switch (PrintcapFormat) | |
3090 | { | |
3091 | case PRINTCAP_BSD : | |
3092 | /* | |
3093 | * Each printer is put in the file as: | |
3094 | * | |
3095 | * Printer1: | |
3096 | * Printer2: | |
3097 | * Printer3: | |
3098 | * ... | |
3099 | * PrinterN: | |
3100 | */ | |
3101 | ||
3102 | if (DefaultPrinter) | |
3103 | cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name, | |
3104 | DefaultPrinter->info, ServerName, | |
3105 | DefaultPrinter->name); | |
3106 | ||
3107 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
3108 | p; | |
3109 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
3110 | if (p != DefaultPrinter) | |
3111 | cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info, | |
3112 | ServerName, p->name); | |
3113 | break; | |
3114 | ||
3115 | case PRINTCAP_PLIST : | |
3116 | /* | |
3117 | * Each printer is written as a dictionary in a plist file. | |
3118 | * Currently the printer-name, printer-info, printer-is-accepting-jobs, | |
3119 | * printer-location, printer-make-and-model, printer-state, | |
3120 | * printer-state-reasons, printer-type, and (sanitized) device-uri. | |
3121 | */ | |
3122 | ||
3123 | cupsFilePuts(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | |
3124 | "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD " | |
3125 | "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/" | |
3126 | "PropertyList-1.0.dtd\">\n" | |
3127 | "<plist version=\"1.0\">\n" | |
3128 | "<array>\n"); | |
3129 | ||
3130 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
3131 | p; | |
3132 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
3133 | { | |
3134 | cupsFilePuts(fp, "\t<dict>\n" | |
3135 | "\t\t<key>printer-name</key>\n" | |
3136 | "\t\t<string>"); | |
3137 | write_xml_string(fp, p->name); | |
3138 | cupsFilePuts(fp, "</string>\n" | |
3139 | "\t\t<key>printer-info</key>\n" | |
3140 | "\t\t<string>"); | |
3141 | write_xml_string(fp, p->info); | |
3142 | cupsFilePrintf(fp, "</string>\n" | |
3143 | "\t\t<key>printer-is-accepting-jobs</key>\n" | |
3144 | "\t\t<%s/>\n" | |
3145 | "\t\t<key>printer-location</key>\n" | |
3146 | "\t\t<string>", p->accepting ? "true" : "false"); | |
3147 | write_xml_string(fp, p->location); | |
3148 | cupsFilePuts(fp, "</string>\n" | |
3149 | "\t\t<key>printer-make-and-model</key>\n" | |
3150 | "\t\t<string>"); | |
3151 | write_xml_string(fp, p->make_model); | |
3152 | cupsFilePrintf(fp, "</string>\n" | |
3153 | "\t\t<key>printer-state</key>\n" | |
3154 | "\t\t<integer>%d</integer>\n" | |
3155 | "\t\t<key>printer-state-reasons</key>\n" | |
3156 | "\t\t<array>\n", p->state); | |
3157 | for (i = 0; i < p->num_reasons; i ++) | |
3158 | { | |
3159 | cupsFilePuts(fp, "\t\t\t<string>"); | |
3160 | write_xml_string(fp, p->reasons[i]); | |
3161 | cupsFilePuts(fp, "</string>\n"); | |
3162 | } | |
3163 | cupsFilePrintf(fp, "\t\t</array>\n" | |
3164 | "\t\t<key>printer-type</key>\n" | |
3165 | "\t\t<integer>%d</integer>\n" | |
3166 | "\t\t<key>device-uri</key>\n" | |
3167 | "\t\t<string>", p->type); | |
3168 | write_xml_string(fp, p->sanitized_device_uri); | |
3169 | cupsFilePuts(fp, "</string>\n" | |
3170 | "\t</dict>\n"); | |
3171 | } | |
3172 | cupsFilePuts(fp, "</array>\n" | |
3173 | "</plist>\n"); | |
3174 | break; | |
3175 | ||
3176 | case PRINTCAP_SOLARIS : | |
3177 | /* | |
3178 | * Each printer is put in the file as: | |
3179 | * | |
3180 | * _all:all=Printer1,Printer2,Printer3,...,PrinterN | |
3181 | * _default:use=DefaultPrinter | |
3182 | * Printer1:\ | |
3183 | * :bsdaddr=ServerName,Printer1:\ | |
3184 | * :description=Description: | |
3185 | * Printer2: | |
3186 | * :bsdaddr=ServerName,Printer2:\ | |
3187 | * :description=Description: | |
3188 | * Printer3: | |
3189 | * :bsdaddr=ServerName,Printer3:\ | |
3190 | * :description=Description: | |
3191 | * ... | |
3192 | * PrinterN: | |
3193 | * :bsdaddr=ServerName,PrinterN:\ | |
3194 | * :description=Description: | |
3195 | */ | |
3196 | ||
3197 | cupsFilePuts(fp, "_all:all="); | |
3198 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
3199 | p; | |
3200 | p = (cupsd_printer_t *)cupsArrayCurrent(Printers)) | |
3201 | cupsFilePrintf(fp, "%s%c", p->name, | |
3202 | cupsArrayNext(Printers) ? ',' : '\n'); | |
3203 | ||
3204 | if (DefaultPrinter) | |
3205 | cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name); | |
3206 | ||
3207 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
3208 | p; | |
3209 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
3210 | cupsFilePrintf(fp, "%s:\\\n" | |
3211 | "\t:bsdaddr=%s,%s:\\\n" | |
3212 | "\t:description=%s:\n", | |
3213 | p->name, ServerName, p->name, | |
3214 | p->info ? p->info : ""); | |
3215 | break; | |
3216 | } | |
3217 | ||
3218 | /* | |
3219 | * Close the file... | |
3220 | */ | |
3221 | ||
3222 | cupsFileClose(fp); | |
3223 | } | |
3224 | ||
3225 | ||
3226 | /* | |
3227 | * 'add_printer_defaults()' - Add name-default attributes to the printer attributes. | |
3228 | */ | |
3229 | ||
3230 | static void | |
3231 | add_printer_defaults(cupsd_printer_t *p)/* I - Printer */ | |
3232 | { | |
3233 | int i; /* Looping var */ | |
3234 | int num_options; /* Number of default options */ | |
3235 | cups_option_t *options, /* Default options */ | |
3236 | *option; /* Current option */ | |
3237 | char name[256]; /* name-default */ | |
3238 | ||
3239 | ||
3240 | /* | |
3241 | * Maintain a common array of default attribute names... | |
3242 | */ | |
3243 | ||
3244 | if (!CommonDefaults) | |
3245 | { | |
3246 | CommonDefaults = cupsArrayNew((cups_array_func_t)strcmp, NULL); | |
3247 | ||
3248 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("copies-default")); | |
3249 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("document-format-default")); | |
3250 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("finishings-default")); | |
3251 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-hold-until-default")); | |
3252 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-priority-default")); | |
3253 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-sheets-default")); | |
3254 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("media-col-default")); | |
3255 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("number-up-default")); | |
3256 | cupsArrayAdd(CommonDefaults, | |
3257 | _cupsStrAlloc("orientation-requested-default")); | |
3258 | } | |
3259 | ||
3260 | /* | |
3261 | * Add all of the default options from the .conf files... | |
3262 | */ | |
3263 | ||
3264 | for (num_options = 0, options = NULL, i = p->num_options, option = p->options; | |
3265 | i > 0; | |
3266 | i --, option ++) | |
3267 | { | |
3268 | if (strcmp(option->name, "ipp-options") && | |
3269 | strcmp(option->name, "job-sheets") && | |
3270 | strcmp(option->name, "lease-duration")) | |
3271 | { | |
3272 | snprintf(name, sizeof(name), "%s-default", option->name); | |
3273 | num_options = cupsAddOption(name, option->value, num_options, &options); | |
3274 | ||
3275 | if (!cupsArrayFind(CommonDefaults, name)) | |
3276 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc(name)); | |
3277 | } | |
3278 | } | |
3279 | ||
3280 | /* | |
3281 | * Convert options to IPP attributes... | |
3282 | */ | |
3283 | ||
3284 | cupsEncodeOptions2(p->attrs, num_options, options, IPP_TAG_PRINTER); | |
3285 | cupsFreeOptions(num_options, options); | |
3286 | ||
3287 | /* | |
3288 | * Add standard -default attributes as needed... | |
3289 | */ | |
3290 | ||
3291 | if (!cupsGetOption("copies", p->num_options, p->options)) | |
3292 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default", | |
3293 | 1); | |
3294 | ||
3295 | if (!cupsGetOption("document-format", p->num_options, p->options)) | |
3296 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE, | |
3297 | "document-format-default", NULL, "application/octet-stream"); | |
3298 | ||
3299 | if (!cupsGetOption("job-hold-until", p->num_options, p->options)) | |
3300 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3301 | "job-hold-until-default", NULL, "no-hold"); | |
3302 | ||
3303 | if (!cupsGetOption("job-priority", p->num_options, p->options)) | |
3304 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3305 | "job-priority-default", 50); | |
3306 | ||
3307 | if (!cupsGetOption("number-up", p->num_options, p->options)) | |
3308 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3309 | "number-up-default", 1); | |
3310 | ||
3311 | if (!cupsGetOption("notify-lease-duration", p->num_options, p->options)) | |
3312 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3313 | "notify-lease-duration-default", DefaultLeaseDuration); | |
3314 | ||
3315 | if (!cupsGetOption("notify-events", p->num_options, p->options)) | |
3316 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3317 | "notify-events-default", NULL, "job-completed"); | |
3318 | ||
3319 | if (!cupsGetOption("orientation-requested", p->num_options, p->options)) | |
3320 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NOVALUE, | |
3321 | "orientation-requested-default", NULL, NULL); | |
3322 | ||
3323 | if (!cupsGetOption("print-quality", p->num_options, p->options)) | |
3324 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
3325 | "print-quality-default", IPP_QUALITY_NORMAL); | |
3326 | } | |
3327 | ||
3328 | ||
3329 | /* | |
3330 | * 'add_printer_filter()' - Add a MIME filter for a printer. | |
3331 | */ | |
3332 | ||
3333 | static void | |
3334 | add_printer_filter( | |
3335 | cupsd_printer_t *p, /* I - Printer to add to */ | |
3336 | mime_type_t *filtertype, /* I - Filter or prefilter MIME type */ | |
3337 | const char *filter) /* I - Filter to add */ | |
3338 | { | |
3339 | char super[MIME_MAX_SUPER], /* Super-type for filter */ | |
3340 | type[MIME_MAX_TYPE], /* Type for filter */ | |
3341 | dsuper[MIME_MAX_SUPER], /* Destination super-type for filter */ | |
3342 | dtype[MIME_MAX_TYPE], /* Destination type for filter */ | |
3343 | dest[MIME_MAX_SUPER + MIME_MAX_TYPE + 2], | |
3344 | /* Destination super/type */ | |
3345 | program[1024]; /* Program/filter name */ | |
3346 | int cost; /* Cost of filter */ | |
3347 | size_t maxsize = 0; /* Maximum supported file size */ | |
3348 | mime_type_t *temptype, /* MIME type looping var */ | |
3349 | *desttype; /* Destination MIME type */ | |
3350 | mime_filter_t *filterptr; /* MIME filter */ | |
3351 | char filename[1024]; /* Full filter filename */ | |
3352 | ||
3353 | ||
3354 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3355 | "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), " | |
3356 | "filter=\"%s\")", p, p->name, filtertype, filtertype->super, | |
3357 | filtertype->type, filter); | |
3358 | ||
3359 | /* | |
3360 | * Parse the filter string; it should be in one of the following formats: | |
3361 | * | |
3362 | * source/type cost program | |
3363 | * source/type cost maxsize(nnnn) program | |
3364 | * source/type dest/type cost program | |
3365 | * source/type dest/type cost maxsize(nnnn) program | |
3366 | */ | |
3367 | ||
3368 | if (sscanf(filter, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]", | |
3369 | super, type, dsuper, dtype, &cost, program) == 6) | |
3370 | { | |
3371 | snprintf(dest, sizeof(dest), "%s/%s/%s", p->name, dsuper, dtype); | |
3372 | ||
3373 | if ((desttype = mimeType(MimeDatabase, "printer", dest)) == NULL) | |
3374 | { | |
3375 | desttype = mimeAddType(MimeDatabase, "printer", dest); | |
3376 | if (!p->dest_types) | |
3377 | p->dest_types = cupsArrayNew(NULL, NULL); | |
3378 | ||
3379 | cupsArrayAdd(p->dest_types, desttype); | |
3380 | } | |
3381 | ||
3382 | } | |
3383 | else | |
3384 | { | |
3385 | if (sscanf(filter, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type, &cost, | |
3386 | program) == 4) | |
3387 | { | |
3388 | desttype = filtertype; | |
3389 | } | |
3390 | else | |
3391 | { | |
3392 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!", | |
3393 | p->name, filter); | |
3394 | return; | |
3395 | } | |
3396 | } | |
3397 | ||
3398 | if (!strncmp(program, "maxsize(", 8)) | |
3399 | { | |
3400 | char *ptr; /* Pointer into maxsize(nnnn) program */ | |
3401 | ||
3402 | maxsize = strtoll(program + 8, &ptr, 10); | |
3403 | ||
3404 | if (*ptr != ')') | |
3405 | { | |
3406 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!", | |
3407 | p->name, filter); | |
3408 | return; | |
3409 | } | |
3410 | ||
3411 | ptr ++; | |
3412 | while (_cups_isspace(*ptr)) | |
3413 | ptr ++; | |
3414 | ||
3415 | _cups_strcpy(program, ptr); | |
3416 | } | |
3417 | ||
3418 | /* | |
3419 | * Check permissions on the filter and its containing directory... | |
3420 | */ | |
3421 | ||
3422 | if (strcmp(program, "-")) | |
3423 | { | |
3424 | if (program[0] == '/') | |
3425 | strlcpy(filename, program, sizeof(filename)); | |
3426 | else | |
3427 | snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program); | |
3428 | ||
3429 | _cupsFileCheck(filename, _CUPS_FILE_CHECK_PROGRAM, !RunUser, | |
3430 | cupsdLogFCMessage, p); | |
3431 | } | |
3432 | ||
3433 | /* | |
3434 | * Add the filter to the MIME database, supporting wildcards as needed... | |
3435 | */ | |
3436 | ||
3437 | for (temptype = mimeFirstType(MimeDatabase); | |
3438 | temptype; | |
3439 | temptype = mimeNextType(MimeDatabase)) | |
3440 | if (((super[0] == '*' && _cups_strcasecmp(temptype->super, "printer")) || | |
3441 | !_cups_strcasecmp(temptype->super, super)) && | |
3442 | (type[0] == '*' || !_cups_strcasecmp(temptype->type, type))) | |
3443 | { | |
3444 | if (desttype != filtertype) | |
3445 | { | |
3446 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3447 | "add_printer_filter: %s: adding filter %s/%s %s/%s %d " | |
3448 | "%s", p->name, temptype->super, temptype->type, | |
3449 | desttype->super, desttype->type, | |
3450 | cost, program); | |
3451 | filterptr = mimeAddFilter(MimeDatabase, temptype, desttype, cost, | |
3452 | program); | |
3453 | ||
3454 | if (!mimeFilterLookup(MimeDatabase, desttype, filtertype)) | |
3455 | { | |
3456 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3457 | "add_printer_filter: %s: adding filter %s/%s %s/%s " | |
3458 | "0 -", p->name, desttype->super, desttype->type, | |
3459 | filtertype->super, filtertype->type); | |
3460 | mimeAddFilter(MimeDatabase, desttype, filtertype, 0, "-"); | |
3461 | } | |
3462 | } | |
3463 | else | |
3464 | { | |
3465 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3466 | "add_printer_filter: %s: adding filter %s/%s %s/%s %d " | |
3467 | "%s", p->name, temptype->super, temptype->type, | |
3468 | filtertype->super, filtertype->type, | |
3469 | cost, program); | |
3470 | filterptr = mimeAddFilter(MimeDatabase, temptype, filtertype, cost, | |
3471 | program); | |
3472 | } | |
3473 | ||
3474 | if (filterptr) | |
3475 | filterptr->maxsize = maxsize; | |
3476 | } | |
3477 | } | |
3478 | ||
3479 | ||
3480 | /* | |
3481 | * 'add_printer_formats()' - Add document-format-supported values for a printer. | |
3482 | */ | |
3483 | ||
3484 | static void | |
3485 | add_printer_formats(cupsd_printer_t *p) /* I - Printer */ | |
3486 | { | |
3487 | int i; /* Looping var */ | |
3488 | mime_type_t *type; /* Current MIME type */ | |
3489 | cups_array_t *filters; /* Filters */ | |
3490 | ipp_attribute_t *attr; /* document-format-supported attribute */ | |
3491 | char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2]; | |
3492 | /* MIME type name */ | |
3493 | ||
3494 | ||
3495 | /* | |
3496 | * Raw (and remote) queues advertise all of the supported MIME | |
3497 | * types... | |
3498 | */ | |
3499 | ||
3500 | cupsArrayDelete(p->filetypes); | |
3501 | p->filetypes = NULL; | |
3502 | ||
3503 | if (p->raw) | |
3504 | { | |
3505 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, | |
3506 | (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY), | |
3507 | "document-format-supported", NumMimeTypes, NULL, MimeTypes); | |
3508 | return; | |
3509 | } | |
3510 | ||
3511 | /* | |
3512 | * Otherwise, loop through the supported MIME types and see if there | |
3513 | * are filters for them... | |
3514 | */ | |
3515 | ||
3516 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters", | |
3517 | mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase)); | |
3518 | ||
3519 | p->filetypes = cupsArrayNew(NULL, NULL); | |
3520 | ||
3521 | for (type = mimeFirstType(MimeDatabase); | |
3522 | type; | |
3523 | type = mimeNextType(MimeDatabase)) | |
3524 | { | |
3525 | if (!_cups_strcasecmp(type->super, "printer")) | |
3526 | continue; | |
3527 | ||
3528 | snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type); | |
3529 | ||
3530 | if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL) | |
3531 | { | |
3532 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3533 | "add_printer_formats: %s: %s needs %d filters", | |
3534 | p->name, mimetype, cupsArrayCount(filters)); | |
3535 | ||
3536 | cupsArrayDelete(filters); | |
3537 | cupsArrayAdd(p->filetypes, type); | |
3538 | } | |
3539 | else | |
3540 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3541 | "add_printer_formats: %s: %s not supported", | |
3542 | p->name, mimetype); | |
3543 | } | |
3544 | ||
3545 | /* | |
3546 | * Add the file formats that can be filtered... | |
3547 | */ | |
3548 | ||
3549 | if ((type = mimeType(MimeDatabase, "application", "octet-stream")) == NULL || | |
3550 | !cupsArrayFind(p->filetypes, type)) | |
3551 | i = 1; | |
3552 | else | |
3553 | i = 0; | |
3554 | ||
3555 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3556 | "add_printer_formats: %s: %d supported types", | |
3557 | p->name, cupsArrayCount(p->filetypes) + i); | |
3558 | ||
3559 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE, | |
3560 | "document-format-supported", | |
3561 | cupsArrayCount(p->filetypes) + i, NULL, NULL); | |
3562 | ||
3563 | if (i) | |
3564 | attr->values[0].string.text = _cupsStrAlloc("application/octet-stream"); | |
3565 | ||
3566 | for (type = (mime_type_t *)cupsArrayFirst(p->filetypes); | |
3567 | type; | |
3568 | i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes)) | |
3569 | { | |
3570 | snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type); | |
3571 | ||
3572 | attr->values[i].string.text = _cupsStrAlloc(mimetype); | |
3573 | } | |
3574 | ||
3575 | #ifdef HAVE_DNSSD | |
3576 | { | |
3577 | char pdl[1024]; /* Buffer to build pdl list */ | |
3578 | mime_filter_t *filter; /* MIME filter looping var */ | |
3579 | ||
3580 | ||
3581 | /* | |
3582 | * We only support raw printing if this is not a Tioga PrintJobMgr based | |
3583 | * queue and if application/octet-stream is a known type... | |
3584 | */ | |
3585 | ||
3586 | for (filter = (mime_filter_t *)cupsArrayFirst(MimeDatabase->filters); | |
3587 | filter; | |
3588 | filter = (mime_filter_t *)cupsArrayNext(MimeDatabase->filters)) | |
3589 | { | |
3590 | if (filter->dst == p->filetype && filter->filter && | |
3591 | strstr(filter->filter, "PrintJobMgr")) | |
3592 | break; | |
3593 | } | |
3594 | ||
3595 | pdl[0] = '\0'; | |
3596 | ||
3597 | if (!filter && mimeType(MimeDatabase, "application", "octet-stream")) | |
3598 | strlcat(pdl, "application/octet-stream,", sizeof(pdl)); | |
3599 | ||
3600 | /* | |
3601 | * Then list a bunch of formats that are supported by the printer... | |
3602 | */ | |
3603 | ||
3604 | for (type = (mime_type_t *)cupsArrayFirst(p->filetypes); | |
3605 | type; | |
3606 | type = (mime_type_t *)cupsArrayNext(p->filetypes)) | |
3607 | { | |
3608 | if (!_cups_strcasecmp(type->super, "application")) | |
3609 | { | |
3610 | if (!_cups_strcasecmp(type->type, "pdf")) | |
3611 | strlcat(pdl, "application/pdf,", sizeof(pdl)); | |
3612 | else if (!_cups_strcasecmp(type->type, "postscript")) | |
3613 | strlcat(pdl, "application/postscript,", sizeof(pdl)); | |
3614 | } | |
3615 | else if (!_cups_strcasecmp(type->super, "image")) | |
3616 | { | |
3617 | if (!_cups_strcasecmp(type->type, "jpeg")) | |
3618 | strlcat(pdl, "image/jpeg,", sizeof(pdl)); | |
3619 | else if (!_cups_strcasecmp(type->type, "png")) | |
3620 | strlcat(pdl, "image/png,", sizeof(pdl)); | |
3621 | else if (!_cups_strcasecmp(type->type, "pwg-raster")) | |
3622 | strlcat(pdl, "image/pwg-raster,", sizeof(pdl)); | |
3623 | } | |
3624 | } | |
3625 | ||
3626 | if (pdl[0]) | |
3627 | pdl[strlen(pdl) - 1] = '\0'; /* Remove trailing comma */ | |
3628 | ||
3629 | cupsdSetString(&p->pdl, pdl); | |
3630 | } | |
3631 | #endif /* HAVE_DNSSD */ | |
3632 | } | |
3633 | ||
3634 | ||
3635 | /* | |
3636 | * 'compare_printers()' - Compare two printers. | |
3637 | */ | |
3638 | ||
3639 | static int /* O - Result of comparison */ | |
3640 | compare_printers(void *first, /* I - First printer */ | |
3641 | void *second, /* I - Second printer */ | |
3642 | void *data) /* I - App data (not used) */ | |
3643 | { | |
3644 | (void)data; | |
3645 | ||
3646 | return (_cups_strcasecmp(((cupsd_printer_t *)first)->name, | |
3647 | ((cupsd_printer_t *)second)->name)); | |
3648 | } | |
3649 | ||
3650 | ||
3651 | /* | |
3652 | * 'delete_printer_filters()' - Delete all MIME filters for a printer. | |
3653 | */ | |
3654 | ||
3655 | static void | |
3656 | delete_printer_filters( | |
3657 | cupsd_printer_t *p) /* I - Printer to remove from */ | |
3658 | { | |
3659 | mime_filter_t *filter; /* MIME filter looping var */ | |
3660 | mime_type_t *type; /* Destination types for filters */ | |
3661 | ||
3662 | ||
3663 | /* | |
3664 | * Range check input... | |
3665 | */ | |
3666 | ||
3667 | if (p == NULL) | |
3668 | return; | |
3669 | ||
3670 | /* | |
3671 | * Remove all filters from the MIME database that have a destination | |
3672 | * type == printer... | |
3673 | */ | |
3674 | ||
3675 | for (filter = mimeFirstFilter(MimeDatabase); | |
3676 | filter; | |
3677 | filter = mimeNextFilter(MimeDatabase)) | |
3678 | if (filter->dst == p->filetype || filter->dst == p->prefiltertype || | |
3679 | cupsArrayFind(p->dest_types, filter->dst)) | |
3680 | { | |
3681 | /* | |
3682 | * Delete the current filter... | |
3683 | */ | |
3684 | ||
3685 | mimeDeleteFilter(MimeDatabase, filter); | |
3686 | } | |
3687 | ||
3688 | for (type = (mime_type_t *)cupsArrayFirst(p->dest_types); | |
3689 | type; | |
3690 | type = (mime_type_t *)cupsArrayNext(p->dest_types)) | |
3691 | mimeDeleteType(MimeDatabase, type); | |
3692 | ||
3693 | cupsArrayDelete(p->dest_types); | |
3694 | p->dest_types = NULL; | |
3695 | ||
3696 | cupsdSetPrinterReasons(p, "-cups-insecure-filter-warning" | |
3697 | ",cups-missing-filter-warning"); | |
3698 | } | |
3699 | ||
3700 | ||
3701 | /* | |
3702 | * 'dirty_printer()' - Mark config and state files dirty for the specified | |
3703 | * printer. | |
3704 | */ | |
3705 | ||
3706 | static void | |
3707 | dirty_printer(cupsd_printer_t *p) /* I - Printer */ | |
3708 | { | |
3709 | if (p->type & CUPS_PRINTER_CLASS) | |
3710 | cupsdMarkDirty(CUPSD_DIRTY_CLASSES); | |
3711 | else | |
3712 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); | |
3713 | ||
3714 | if (PrintcapFormat == PRINTCAP_PLIST) | |
3715 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); | |
3716 | } | |
3717 | ||
3718 | ||
3719 | /* | |
3720 | * 'load_ppd()' - Load a cached PPD file, updating the cache as needed. | |
3721 | */ | |
3722 | ||
3723 | static void | |
3724 | load_ppd(cupsd_printer_t *p) /* I - Printer */ | |
3725 | { | |
3726 | int i, j, k; /* Looping vars */ | |
3727 | char cache_name[1024]; /* Cache filename */ | |
3728 | struct stat cache_info; /* Cache file info */ | |
3729 | ppd_file_t *ppd; /* PPD file */ | |
3730 | char ppd_name[1024]; /* PPD filename */ | |
3731 | struct stat ppd_info; /* PPD file info */ | |
3732 | int num_media; /* Number of media options */ | |
3733 | ppd_size_t *size; /* Current PPD size */ | |
3734 | ppd_option_t *duplex, /* Duplex option */ | |
3735 | *output_bin, /* OutputBin option */ | |
3736 | *output_mode, /* OutputMode option */ | |
3737 | *resolution; /* (Set|JCL|)Resolution option */ | |
3738 | ppd_choice_t *choice, /* Current PPD choice */ | |
3739 | *input_slot, /* Current input slot */ | |
3740 | *media_type; /* Current media type */ | |
3741 | ppd_attr_t *ppd_attr; /* PPD attribute */ | |
3742 | int xdpi, /* Horizontal resolution */ | |
3743 | ydpi; /* Vertical resolution */ | |
3744 | const char *resptr; /* Pointer into resolution keyword */ | |
3745 | _pwg_size_t *pwgsize; /* Current PWG size */ | |
3746 | _pwg_map_t *pwgsource, /* Current PWG source */ | |
3747 | *pwgtype; /* Current PWG type */ | |
3748 | ipp_attribute_t *attr; /* Attribute data */ | |
3749 | _ipp_value_t *val; /* Attribute value */ | |
3750 | int num_finishings, /* Number of finishings */ | |
3751 | finishings[5]; /* finishings-supported values */ | |
3752 | int num_qualities, /* Number of print-quality values */ | |
3753 | qualities[3]; /* print-quality values */ | |
3754 | int num_margins, /* Number of media-*-margin-supported values */ | |
3755 | margins[16]; /* media-*-margin-supported values */ | |
3756 | const char *filter; /* Current filter */ | |
3757 | static const char * const sides[3] = /* sides-supported values */ | |
3758 | { | |
3759 | "one-sided", | |
3760 | "two-sided-long-edge", | |
3761 | "two-sided-short-edge" | |
3762 | }; | |
3763 | static const char * const standard_commands[] = | |
3764 | { /* Standard CUPS commands */ | |
3765 | "AutoConfigure", | |
3766 | "Clean", | |
3767 | "PrintSelfTestPage" | |
3768 | }; | |
3769 | ||
3770 | ||
3771 | /* | |
3772 | * Check to see if the cache is up-to-date... | |
3773 | */ | |
3774 | ||
3775 | snprintf(cache_name, sizeof(cache_name), "%s/%s.data", CacheDir, p->name); | |
3776 | if (stat(cache_name, &cache_info)) | |
3777 | cache_info.st_mtime = 0; | |
3778 | ||
3779 | snprintf(ppd_name, sizeof(ppd_name), "%s/ppd/%s.ppd", ServerRoot, p->name); | |
3780 | if (stat(ppd_name, &ppd_info)) | |
3781 | ppd_info.st_mtime = 1; | |
3782 | ||
3783 | ippDelete(p->ppd_attrs); | |
3784 | p->ppd_attrs = NULL; | |
3785 | ||
3786 | _ppdCacheDestroy(p->pc); | |
3787 | p->pc = NULL; | |
3788 | ||
3789 | if (cache_info.st_mtime >= ppd_info.st_mtime) | |
3790 | { | |
3791 | cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", cache_name); | |
3792 | ||
3793 | if ((p->pc = _ppdCacheCreateWithFile(cache_name, &p->ppd_attrs)) != NULL && | |
3794 | p->ppd_attrs) | |
3795 | { | |
3796 | /* | |
3797 | * Loaded successfully! | |
3798 | */ | |
3799 | ||
3800 | return; | |
3801 | } | |
3802 | } | |
3803 | ||
3804 | /* | |
3805 | * Reload PPD attributes from disk... | |
3806 | */ | |
3807 | ||
3808 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); | |
3809 | ||
3810 | cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", ppd_name); | |
3811 | ||
3812 | p->type &= ~CUPS_PRINTER_OPTIONS; | |
3813 | p->type |= CUPS_PRINTER_BW; | |
3814 | ||
3815 | finishings[0] = IPP_FINISHINGS_NONE; | |
3816 | num_finishings = 1; | |
3817 | ||
3818 | p->ppd_attrs = ippNew(); | |
3819 | ||
3820 | if ((ppd = _ppdOpenFile(ppd_name, _PPD_LOCALIZATION_NONE)) != NULL) | |
3821 | { | |
3822 | /* | |
3823 | * Add make/model and other various attributes... | |
3824 | */ | |
3825 | ||
3826 | p->pc = _ppdCacheCreateWithPPD(ppd); | |
3827 | ||
3828 | ppdMarkDefaults(ppd); | |
3829 | ||
3830 | if (ppd->color_device) | |
3831 | p->type |= CUPS_PRINTER_COLOR; | |
3832 | if (ppd->variable_sizes) | |
3833 | p->type |= CUPS_PRINTER_VARIABLE; | |
3834 | if (!ppd->manual_copies) | |
3835 | p->type |= CUPS_PRINTER_COPIES; | |
3836 | if ((ppd_attr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL) | |
3837 | if (ppd_attr->value && !_cups_strcasecmp(ppd_attr->value, "true")) | |
3838 | p->type |= CUPS_PRINTER_FAX; | |
3839 | ||
3840 | ippAddBoolean(p->ppd_attrs, IPP_TAG_PRINTER, "color-supported", | |
3841 | ppd->color_device); | |
3842 | if (ppd->throughput) | |
3843 | { | |
3844 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3845 | "pages-per-minute", ppd->throughput); | |
3846 | if (ppd->color_device) | |
3847 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3848 | "pages-per-minute-color", ppd->throughput); | |
3849 | } | |
3850 | else | |
3851 | { | |
3852 | /* | |
3853 | * When there is no speed information, just say "1 page per minute". | |
3854 | */ | |
3855 | ||
3856 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3857 | "pages-per-minute", 1); | |
3858 | if (ppd->color_device) | |
3859 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3860 | "pages-per-minute-color", 1); | |
3861 | } | |
3862 | ||
3863 | num_qualities = 0; | |
3864 | ||
3865 | if ((output_mode = ppdFindOption(ppd, "OutputMode")) != NULL) | |
3866 | { | |
3867 | if (ppdFindChoice(output_mode, "draft") || | |
3868 | ppdFindChoice(output_mode, "fast")) | |
3869 | qualities[num_qualities ++] = IPP_QUALITY_DRAFT; | |
3870 | ||
3871 | qualities[num_qualities ++] = IPP_QUALITY_NORMAL; | |
3872 | ||
3873 | if (ppdFindChoice(output_mode, "best") || | |
3874 | ppdFindChoice(output_mode, "high")) | |
3875 | qualities[num_qualities ++] = IPP_QUALITY_HIGH; | |
3876 | } | |
3877 | else if ((ppd_attr = ppdFindAttr(ppd, "APPrinterPreset", NULL)) != NULL) | |
3878 | { | |
3879 | do | |
3880 | { | |
3881 | if (strstr(ppd_attr->spec, "draft") || | |
3882 | strstr(ppd_attr->spec, "Draft")) | |
3883 | { | |
3884 | qualities[num_qualities ++] = IPP_QUALITY_DRAFT; | |
3885 | break; | |
3886 | } | |
3887 | } | |
3888 | while ((ppd_attr = ppdFindNextAttr(ppd, "APPrinterPreset", | |
3889 | NULL)) != NULL); | |
3890 | ||
3891 | qualities[num_qualities ++] = IPP_QUALITY_NORMAL; | |
3892 | qualities[num_qualities ++] = IPP_QUALITY_HIGH; | |
3893 | } | |
3894 | else | |
3895 | qualities[num_qualities ++] = IPP_QUALITY_NORMAL; | |
3896 | ||
3897 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
3898 | "print-quality-supported", num_qualities, qualities); | |
3899 | ||
3900 | if (ppd->nickname) | |
3901 | { | |
3902 | /* | |
3903 | * The NickName can be localized in the character set specified | |
3904 | * by the LanugageEncoding attribute. However, ppdOpen2() has | |
3905 | * already converted the ppd->nickname member to UTF-8 for us | |
3906 | * (the original attribute value is available separately) | |
3907 | */ | |
3908 | ||
3909 | cupsdSetString(&p->make_model, ppd->nickname); | |
3910 | } | |
3911 | else if (ppd->modelname) | |
3912 | { | |
3913 | /* | |
3914 | * Model name can only contain specific characters... | |
3915 | */ | |
3916 | ||
3917 | cupsdSetString(&p->make_model, ppd->modelname); | |
3918 | } | |
3919 | else | |
3920 | cupsdSetString(&p->make_model, "Bad PPD File"); | |
3921 | ||
3922 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
3923 | "printer-make-and-model", NULL, p->make_model); | |
3924 | ||
3925 | /* | |
3926 | * Add media options from the PPD file... | |
3927 | */ | |
3928 | ||
3929 | if (ppd->num_sizes == 0 || !p->pc) | |
3930 | { | |
3931 | if (!ppdFindAttr(ppd, "APScannerOnly", NULL)) | |
3932 | cupsdLogMessage(CUPSD_LOG_CRIT, | |
3933 | "The PPD file for printer %s contains no media " | |
3934 | "options and is therefore invalid!", p->name); | |
3935 | ||
3936 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3937 | "media-default", NULL, "unknown"); | |
3938 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3939 | "media-supported", NULL, "unknown"); | |
3940 | } | |
3941 | else | |
3942 | { | |
3943 | /* | |
3944 | * media-default | |
3945 | */ | |
3946 | ||
3947 | if ((size = ppdPageSize(ppd, NULL)) != NULL) | |
3948 | pwgsize = _ppdCacheGetSize(p->pc, size->name); | |
3949 | else | |
3950 | pwgsize = NULL; | |
3951 | ||
3952 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3953 | "media-default", NULL, | |
3954 | pwgsize ? pwgsize->map.pwg : "unknown"); | |
3955 | ||
3956 | /* | |
3957 | * media-col-default | |
3958 | */ | |
3959 | ||
3960 | if (pwgsize) | |
3961 | { | |
3962 | ipp_t *col; /* Collection value */ | |
3963 | ||
3964 | input_slot = ppdFindMarkedChoice(ppd, "InputSlot"); | |
3965 | media_type = ppdFindMarkedChoice(ppd, "MediaType"); | |
3966 | col = new_media_col(pwgsize, | |
3967 | input_slot ? | |
3968 | _ppdCacheGetSource(p->pc, | |
3969 | input_slot->choice) : | |
3970 | NULL, | |
3971 | media_type ? | |
3972 | _ppdCacheGetType(p->pc, | |
3973 | media_type->choice) : | |
3974 | NULL); | |
3975 | ||
3976 | ippAddCollection(p->ppd_attrs, IPP_TAG_PRINTER, "media-col-default", | |
3977 | col); | |
3978 | ippDelete(col); | |
3979 | } | |
3980 | ||
3981 | /* | |
3982 | * media-supported | |
3983 | */ | |
3984 | ||
3985 | num_media = p->pc->num_sizes; | |
3986 | if (p->pc->custom_min_keyword) | |
3987 | num_media += 2; | |
3988 | ||
3989 | if ((attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3990 | "media-supported", num_media, NULL, | |
3991 | NULL)) != NULL) | |
3992 | { | |
3993 | val = attr->values; | |
3994 | ||
3995 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes; | |
3996 | i > 0; | |
3997 | i --, pwgsize ++, val ++) | |
3998 | val->string.text = _cupsStrRetain(pwgsize->map.pwg); | |
3999 | ||
4000 | if (p->pc->custom_min_keyword) | |
4001 | { | |
4002 | val->string.text = _cupsStrRetain(p->pc->custom_min_keyword); | |
4003 | val ++; | |
4004 | val->string.text = _cupsStrRetain(p->pc->custom_max_keyword); | |
4005 | } | |
4006 | } | |
4007 | ||
4008 | /* | |
4009 | * media-source-supported | |
4010 | */ | |
4011 | ||
4012 | if (p->pc->num_sources > 0 && | |
4013 | (attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4014 | "media-source-supported", p->pc->num_sources, | |
4015 | NULL, NULL)) != NULL) | |
4016 | { | |
4017 | for (i = p->pc->num_sources, pwgsource = p->pc->sources, | |
4018 | val = attr->values; | |
4019 | i > 0; | |
4020 | i --, pwgsource ++, val ++) | |
4021 | val->string.text = _cupsStrRetain(pwgsource->pwg); | |
4022 | } | |
4023 | ||
4024 | /* | |
4025 | * media-type-supported | |
4026 | */ | |
4027 | ||
4028 | if (p->pc->num_types > 0 && | |
4029 | (attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4030 | "media-type-supported", p->pc->num_types, | |
4031 | NULL, NULL)) != NULL) | |
4032 | { | |
4033 | for (i = p->pc->num_types, pwgtype = p->pc->types, | |
4034 | val = attr->values; | |
4035 | i > 0; | |
4036 | i --, pwgtype ++, val ++) | |
4037 | val->string.text = _cupsStrRetain(pwgtype->pwg); | |
4038 | } | |
4039 | ||
4040 | /* | |
4041 | * media-*-margin-supported | |
4042 | */ | |
4043 | ||
4044 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0; | |
4045 | i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0])); | |
4046 | i --, pwgsize ++) | |
4047 | { | |
4048 | for (j = 0; j < num_margins; j ++) | |
4049 | if (pwgsize->bottom == margins[j]) | |
4050 | break; | |
4051 | ||
4052 | if (j >= num_margins) | |
4053 | { | |
4054 | margins[num_margins] = pwgsize->bottom; | |
4055 | num_margins ++; | |
4056 | } | |
4057 | } | |
4058 | ||
4059 | if (num_margins > 0) | |
4060 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4061 | "media-bottom-margin-supported", num_margins, margins); | |
4062 | else | |
4063 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4064 | "media-bottom-margin-supported", 0); | |
4065 | ||
4066 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0; | |
4067 | i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0])); | |
4068 | i --, pwgsize ++) | |
4069 | { | |
4070 | for (j = 0; j < num_margins; j ++) | |
4071 | if (pwgsize->left == margins[j]) | |
4072 | break; | |
4073 | ||
4074 | if (j >= num_margins) | |
4075 | { | |
4076 | margins[num_margins] = pwgsize->left; | |
4077 | num_margins ++; | |
4078 | } | |
4079 | } | |
4080 | ||
4081 | if (num_margins > 0) | |
4082 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4083 | "media-left-margin-supported", num_margins, margins); | |
4084 | else | |
4085 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4086 | "media-left-margin-supported", 0); | |
4087 | ||
4088 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0; | |
4089 | i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0])); | |
4090 | i --, pwgsize ++) | |
4091 | { | |
4092 | for (j = 0; j < num_margins; j ++) | |
4093 | if (pwgsize->right == margins[j]) | |
4094 | break; | |
4095 | ||
4096 | if (j >= num_margins) | |
4097 | { | |
4098 | margins[num_margins] = pwgsize->right; | |
4099 | num_margins ++; | |
4100 | } | |
4101 | } | |
4102 | ||
4103 | if (num_margins > 0) | |
4104 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4105 | "media-right-margin-supported", num_margins, margins); | |
4106 | else | |
4107 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4108 | "media-right-margin-supported", 0); | |
4109 | ||
4110 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0; | |
4111 | i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0])); | |
4112 | i --, pwgsize ++) | |
4113 | { | |
4114 | for (j = 0; j < num_margins; j ++) | |
4115 | if (pwgsize->top == margins[j]) | |
4116 | break; | |
4117 | ||
4118 | if (j >= num_margins) | |
4119 | { | |
4120 | margins[num_margins] = pwgsize->top; | |
4121 | num_margins ++; | |
4122 | } | |
4123 | } | |
4124 | ||
4125 | if (num_margins > 0) | |
4126 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4127 | "media-top-margin-supported", num_margins, margins); | |
4128 | else | |
4129 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4130 | "media-top-margin-supported", 0); | |
4131 | ||
4132 | /* | |
4133 | * media-col-database | |
4134 | */ | |
4135 | ||
4136 | num_media = p->pc->num_sizes; | |
4137 | if (p->pc->num_sources) | |
4138 | { | |
4139 | if (p->pc->num_types > 0) | |
4140 | num_media += p->pc->num_sizes * p->pc->num_sources * | |
4141 | p->pc->num_types; | |
4142 | else | |
4143 | num_media += p->pc->num_sizes * p->pc->num_sources; | |
4144 | } | |
4145 | else if (p->pc->num_types) | |
4146 | num_media += p->pc->num_sizes * p->pc->num_types; | |
4147 | ||
4148 | if ((attr = ippAddCollections(p->ppd_attrs, IPP_TAG_PRINTER, | |
4149 | "media-col-database", num_media, | |
4150 | NULL)) != NULL) | |
4151 | { | |
4152 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, val = attr->values; | |
4153 | i > 0; | |
4154 | i --, pwgsize ++) | |
4155 | { | |
4156 | /* | |
4157 | * Start by adding the page size without source or type... | |
4158 | */ | |
4159 | ||
4160 | ppdMarkOption(ppd, "PageSize", pwgsize->map.ppd); | |
4161 | ||
4162 | val->collection = new_media_col(pwgsize, NULL, NULL); | |
4163 | val ++; | |
4164 | ||
4165 | /* | |
4166 | * Then add the specific, supported combinations of size, source, and | |
4167 | * type... | |
4168 | */ | |
4169 | ||
4170 | if (p->pc->num_sources > 0) | |
4171 | { | |
4172 | for (j = p->pc->num_sources, pwgsource = p->pc->sources; | |
4173 | j > 0; | |
4174 | j --, pwgsource ++) | |
4175 | { | |
4176 | ppdMarkOption(ppd, "InputSlot", pwgsource->ppd); | |
4177 | ||
4178 | if (p->pc->num_types > 0) | |
4179 | { | |
4180 | for (k = p->pc->num_types, pwgtype = p->pc->types; | |
4181 | k > 0; | |
4182 | k --, pwgtype ++) | |
4183 | { | |
4184 | if (!ppdMarkOption(ppd, "MediaType", pwgtype->ppd)) | |
4185 | { | |
4186 | val->collection = new_media_col(pwgsize, pwgsource->pwg, | |
4187 | pwgtype->pwg); | |
4188 | val ++; | |
4189 | } | |
4190 | } | |
4191 | } | |
4192 | else if (!ppdConflicts(ppd)) | |
4193 | { | |
4194 | val->collection = new_media_col(pwgsize, pwgsource->pwg, NULL); | |
4195 | val ++; | |
4196 | } | |
4197 | } | |
4198 | } | |
4199 | else if (p->pc->num_types > 0) | |
4200 | { | |
4201 | for (j = p->pc->num_types, pwgtype = p->pc->types; | |
4202 | j > 0; | |
4203 | j --, pwgtype ++) | |
4204 | { | |
4205 | if (!ppdMarkOption(ppd, "MediaType", pwgtype->ppd)) | |
4206 | { | |
4207 | val->collection = new_media_col(pwgsize, NULL, pwgtype->pwg); | |
4208 | val ++; | |
4209 | } | |
4210 | } | |
4211 | } | |
4212 | } | |
4213 | ||
4214 | /* | |
4215 | * Update the number of media-col-database values... | |
4216 | */ | |
4217 | ||
4218 | attr->num_values = val - attr->values; | |
4219 | } | |
4220 | } | |
4221 | ||
4222 | /* | |
4223 | * Output bin... | |
4224 | */ | |
4225 | ||
4226 | if (p->pc && p->pc->num_bins > 0) | |
4227 | { | |
4228 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4229 | "output-bin-supported", p->pc->num_bins, | |
4230 | NULL, NULL); | |
4231 | ||
4232 | if (attr != NULL) | |
4233 | { | |
4234 | for (i = 0, val = attr->values; | |
4235 | i < p->pc->num_bins; | |
4236 | i ++, val ++) | |
4237 | val->string.text = _cupsStrAlloc(p->pc->bins[i].pwg); | |
4238 | } | |
4239 | ||
4240 | if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL) | |
4241 | { | |
4242 | for (i = 0; i < p->pc->num_bins; i ++) | |
4243 | if (!strcmp(p->pc->bins[i].ppd, output_bin->defchoice)) | |
4244 | break; | |
4245 | ||
4246 | if (i >= p->pc->num_bins) | |
4247 | i = 0; | |
4248 | ||
4249 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4250 | "output-bin-default", NULL, p->pc->bins[i].pwg); | |
4251 | } | |
4252 | else | |
4253 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4254 | "output-bin-default", NULL, p->pc->bins[0].pwg); | |
4255 | } | |
4256 | else if (((ppd_attr = ppdFindAttr(ppd, "DefaultOutputOrder", | |
4257 | NULL)) != NULL && | |
4258 | !_cups_strcasecmp(ppd_attr->value, "Reverse")) || | |
4259 | (!ppd_attr && ppd->manufacturer && /* "Compatibility heuristic" */ | |
4260 | (!_cups_strcasecmp(ppd->manufacturer, "epson") || | |
4261 | !_cups_strcasecmp(ppd->manufacturer, "lexmark")))) | |
4262 | { | |
4263 | /* | |
4264 | * Report that this printer has a single output bin that leaves pages face | |
4265 | * up. | |
4266 | */ | |
4267 | ||
4268 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4269 | "output-bin-supported", NULL, "face-up"); | |
4270 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4271 | "output-bin-default", NULL, "face-up"); | |
4272 | } | |
4273 | else | |
4274 | { | |
4275 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4276 | "output-bin-supported", NULL, "face-down"); | |
4277 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4278 | "output-bin-default", NULL, "face-down"); | |
4279 | } | |
4280 | ||
4281 | /* | |
4282 | * output-mode and print-color-mode... | |
4283 | */ | |
4284 | ||
4285 | if (ppd->color_device) | |
4286 | { | |
4287 | static const char * const output_modes[] = | |
4288 | { | |
4289 | "monochrome", | |
4290 | "color" | |
4291 | }; | |
4292 | ||
4293 | ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4294 | "output-mode-supported", 2, NULL, output_modes); | |
4295 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4296 | "output-mode-default", NULL, "color"); | |
4297 | ||
4298 | ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4299 | "print-color-mode-supported", 2, NULL, output_modes); | |
4300 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4301 | "print-color-mode-default", NULL, "color"); | |
4302 | } | |
4303 | else | |
4304 | { | |
4305 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4306 | "output-mode-supported", NULL, "monochrome"); | |
4307 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4308 | "output-mode-default", NULL, "monochrome"); | |
4309 | ||
4310 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4311 | "print-color-mode-supported", NULL, "monochrome"); | |
4312 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4313 | "print-color-mode-default", NULL, "monochrome"); | |
4314 | } | |
4315 | ||
4316 | /* | |
4317 | * Printer resolutions... | |
4318 | */ | |
4319 | ||
4320 | if ((resolution = ppdFindOption(ppd, "Resolution")) == NULL) | |
4321 | if ((resolution = ppdFindOption(ppd, "JCLResolution")) == NULL) | |
4322 | if ((resolution = ppdFindOption(ppd, "SetResolution")) == NULL) | |
4323 | resolution = ppdFindOption(ppd, "CNRes_PGP"); | |
4324 | ||
4325 | if (resolution) | |
4326 | { | |
4327 | /* | |
4328 | * Report all supported resolutions... | |
4329 | */ | |
4330 | ||
4331 | attr = ippAddResolutions(p->ppd_attrs, IPP_TAG_PRINTER, | |
4332 | "printer-resolution-supported", | |
4333 | resolution->num_choices, IPP_RES_PER_INCH, | |
4334 | NULL, NULL); | |
4335 | ||
4336 | for (i = 0, choice = resolution->choices; | |
4337 | i < resolution->num_choices; | |
4338 | i ++, choice ++) | |
4339 | { | |
4340 | xdpi = ydpi = (int)strtol(choice->choice, (char **)&resptr, 10); | |
4341 | if (resptr > choice->choice && xdpi > 0 && *resptr == 'x') | |
4342 | ydpi = (int)strtol(resptr + 1, (char **)&resptr, 10); | |
4343 | ||
4344 | if (xdpi <= 0 || ydpi <= 0) | |
4345 | { | |
4346 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4347 | "Bad resolution \"%s\" for printer %s.", | |
4348 | choice->choice, p->name); | |
4349 | xdpi = ydpi = 300; | |
4350 | } | |
4351 | ||
4352 | attr->values[i].resolution.xres = xdpi; | |
4353 | attr->values[i].resolution.yres = ydpi; | |
4354 | attr->values[i].resolution.units = IPP_RES_PER_INCH; | |
4355 | ||
4356 | if (choice->marked) | |
4357 | ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER, | |
4358 | "printer-resolution-default", IPP_RES_PER_INCH, | |
4359 | xdpi, ydpi); | |
4360 | } | |
4361 | } | |
4362 | else if ((ppd_attr = ppdFindAttr(ppd, "DefaultResolution", NULL)) != NULL && | |
4363 | ppd_attr->value) | |
4364 | { | |
4365 | /* | |
4366 | * Just the DefaultResolution to report... | |
4367 | */ | |
4368 | ||
4369 | xdpi = ydpi = (int)strtol(ppd_attr->value, (char **)&resptr, 10); | |
4370 | if (resptr > ppd_attr->value && xdpi > 0) | |
4371 | { | |
4372 | if (*resptr == 'x') | |
4373 | ydpi = (int)strtol(resptr + 1, (char **)&resptr, 10); | |
4374 | else | |
4375 | ydpi = xdpi; | |
4376 | } | |
4377 | ||
4378 | if (xdpi <= 0 || ydpi <= 0) | |
4379 | { | |
4380 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4381 | "Bad default resolution \"%s\" for printer %s.", | |
4382 | ppd_attr->value, p->name); | |
4383 | xdpi = ydpi = 300; | |
4384 | } | |
4385 | ||
4386 | ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER, | |
4387 | "printer-resolution-default", IPP_RES_PER_INCH, | |
4388 | xdpi, ydpi); | |
4389 | ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER, | |
4390 | "printer-resolution-supported", IPP_RES_PER_INCH, | |
4391 | xdpi, ydpi); | |
4392 | } | |
4393 | else | |
4394 | { | |
4395 | /* | |
4396 | * No resolutions in PPD - make one up... | |
4397 | */ | |
4398 | ||
4399 | ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER, | |
4400 | "printer-resolution-default", IPP_RES_PER_INCH, | |
4401 | 300, 300); | |
4402 | ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER, | |
4403 | "printer-resolution-supported", IPP_RES_PER_INCH, | |
4404 | 300, 300); | |
4405 | } | |
4406 | ||
4407 | /* | |
4408 | * Duplexing, etc... | |
4409 | */ | |
4410 | ||
4411 | ppdMarkDefaults(ppd); | |
4412 | ||
4413 | if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL) | |
4414 | if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL) | |
4415 | if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL) | |
4416 | if ((duplex = ppdFindOption(ppd, "KD03Duplex")) == NULL) | |
4417 | duplex = ppdFindOption(ppd, "JCLDuplex"); | |
4418 | ||
4419 | if (duplex && duplex->num_choices > 1 && | |
4420 | !ppdInstallableConflict(ppd, duplex->keyword, "DuplexTumble")) | |
4421 | { | |
4422 | p->type |= CUPS_PRINTER_DUPLEX; | |
4423 | ||
4424 | ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4425 | "sides-supported", 3, NULL, sides); | |
4426 | ||
4427 | if (!_cups_strcasecmp(duplex->defchoice, "DuplexTumble")) | |
4428 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4429 | "sides-default", NULL, "two-sided-short-edge"); | |
4430 | else if (!_cups_strcasecmp(duplex->defchoice, "DuplexNoTumble")) | |
4431 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4432 | "sides-default", NULL, "two-sided-long-edge"); | |
4433 | else | |
4434 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4435 | "sides-default", NULL, "one-sided"); | |
4436 | } | |
4437 | else | |
4438 | { | |
4439 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4440 | "sides-supported", NULL, "one-sided"); | |
4441 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4442 | "sides-default", NULL, "one-sided"); | |
4443 | } | |
4444 | ||
4445 | if (ppdFindOption(ppd, "Collate") != NULL) | |
4446 | p->type |= CUPS_PRINTER_COLLATE; | |
4447 | ||
4448 | if (ppdFindOption(ppd, "StapleLocation") != NULL) | |
4449 | { | |
4450 | p->type |= CUPS_PRINTER_STAPLE; | |
4451 | finishings[num_finishings++] = IPP_FINISHINGS_STAPLE; | |
4452 | } | |
4453 | ||
4454 | if (ppdFindOption(ppd, "BindEdge") != NULL) | |
4455 | { | |
4456 | p->type |= CUPS_PRINTER_BIND; | |
4457 | finishings[num_finishings++] = IPP_FINISHINGS_BIND; | |
4458 | } | |
4459 | ||
4460 | for (i = 0; i < ppd->num_sizes; i ++) | |
4461 | if (ppd->sizes[i].length > 1728) | |
4462 | p->type |= CUPS_PRINTER_LARGE; | |
4463 | else if (ppd->sizes[i].length > 1008) | |
4464 | p->type |= CUPS_PRINTER_MEDIUM; | |
4465 | else | |
4466 | p->type |= CUPS_PRINTER_SMALL; | |
4467 | ||
4468 | if ((ppd_attr = ppdFindAttr(ppd, "APICADriver", NULL)) != NULL && | |
4469 | ppd_attr->value && !_cups_strcasecmp(ppd_attr->value, "true")) | |
4470 | { | |
4471 | if ((ppd_attr = ppdFindAttr(ppd, "APScannerOnly", NULL)) != NULL && | |
4472 | ppd_attr->value && !_cups_strcasecmp(ppd_attr->value, "true")) | |
4473 | p->type |= CUPS_PRINTER_SCANNER; | |
4474 | else | |
4475 | p->type |= CUPS_PRINTER_MFP; | |
4476 | } | |
4477 | ||
4478 | /* | |
4479 | * Scan the filters in the PPD file... | |
4480 | */ | |
4481 | ||
4482 | if (p->pc) | |
4483 | { | |
4484 | for (filter = (const char *)cupsArrayFirst(p->pc->filters); | |
4485 | filter; | |
4486 | filter = (const char *)cupsArrayNext(p->pc->filters)) | |
4487 | { | |
4488 | if (!_cups_strncasecmp(filter, "application/vnd.cups-command", 28) && | |
4489 | _cups_isspace(filter[28])) | |
4490 | { | |
4491 | p->type |= CUPS_PRINTER_COMMANDS; | |
4492 | break; | |
4493 | } | |
4494 | } | |
4495 | } | |
4496 | ||
4497 | if (p->type & CUPS_PRINTER_COMMANDS) | |
4498 | { | |
4499 | char *commands, /* Copy of commands */ | |
4500 | *start, /* Start of name */ | |
4501 | *end; /* End of name */ | |
4502 | int count; /* Number of commands */ | |
4503 | ||
4504 | if ((ppd_attr = ppdFindAttr(ppd, "cupsCommands", NULL)) != NULL) | |
4505 | { | |
4506 | for (count = 0, start = ppd_attr->value; *start; count ++) | |
4507 | { | |
4508 | while (_cups_isspace(*start)) | |
4509 | start ++; | |
4510 | ||
4511 | if (!*start) | |
4512 | break; | |
4513 | ||
4514 | while (*start && !isspace(*start & 255)) | |
4515 | start ++; | |
4516 | } | |
4517 | } | |
4518 | else | |
4519 | count = 0; | |
4520 | ||
4521 | if (count > 0) | |
4522 | { | |
4523 | /* | |
4524 | * Make a copy of the commands string and count how many commands there | |
4525 | * are... | |
4526 | */ | |
4527 | ||
4528 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4529 | "printer-commands", count, NULL, NULL); | |
4530 | ||
4531 | commands = strdup(ppd_attr->value); | |
4532 | ||
4533 | for (count = 0, start = commands; *start; count ++) | |
4534 | { | |
4535 | while (isspace(*start & 255)) | |
4536 | start ++; | |
4537 | ||
4538 | if (!*start) | |
4539 | break; | |
4540 | ||
4541 | end = start; | |
4542 | while (*end && !isspace(*end & 255)) | |
4543 | end ++; | |
4544 | ||
4545 | if (*end) | |
4546 | *end++ = '\0'; | |
4547 | ||
4548 | attr->values[count].string.text = _cupsStrAlloc(start); | |
4549 | ||
4550 | start = end; | |
4551 | } | |
4552 | ||
4553 | free(commands); | |
4554 | } | |
4555 | else | |
4556 | { | |
4557 | /* | |
4558 | * Add the standard list of commands... | |
4559 | */ | |
4560 | ||
4561 | ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4562 | "printer-commands", | |
4563 | (int)(sizeof(standard_commands) / | |
4564 | sizeof(standard_commands[0])), NULL, | |
4565 | standard_commands); | |
4566 | } | |
4567 | } | |
4568 | else | |
4569 | { | |
4570 | /* | |
4571 | * No commands supported... | |
4572 | */ | |
4573 | ||
4574 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4575 | "printer-commands", NULL, "none"); | |
4576 | } | |
4577 | ||
4578 | /* | |
4579 | * Show current and available port monitors for this printer... | |
4580 | */ | |
4581 | ||
4582 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor", | |
4583 | NULL, p->port_monitor ? p->port_monitor : "none"); | |
4584 | ||
4585 | for (i = 1, ppd_attr = ppdFindAttr(ppd, "cupsPortMonitor", NULL); | |
4586 | ppd_attr; | |
4587 | i ++, ppd_attr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL)); | |
4588 | ||
4589 | if (ppd->protocols) | |
4590 | { | |
4591 | if (strstr(ppd->protocols, "TBCP")) | |
4592 | i ++; | |
4593 | else if (strstr(ppd->protocols, "BCP")) | |
4594 | i ++; | |
4595 | } | |
4596 | ||
4597 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
4598 | "port-monitor-supported", i, NULL, NULL); | |
4599 | ||
4600 | attr->values[0].string.text = _cupsStrAlloc("none"); | |
4601 | ||
4602 | for (i = 1, ppd_attr = ppdFindAttr(ppd, "cupsPortMonitor", NULL); | |
4603 | ppd_attr; | |
4604 | i ++, ppd_attr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL)) | |
4605 | attr->values[i].string.text = _cupsStrAlloc(ppd_attr->value); | |
4606 | ||
4607 | if (ppd->protocols) | |
4608 | { | |
4609 | if (strstr(ppd->protocols, "TBCP")) | |
4610 | attr->values[i].string.text = _cupsStrAlloc("tbcp"); | |
4611 | else if (strstr(ppd->protocols, "BCP")) | |
4612 | attr->values[i].string.text = _cupsStrAlloc("bcp"); | |
4613 | } | |
4614 | ||
4615 | if (ppdFindAttr(ppd, "APRemoteQueueID", NULL)) | |
4616 | p->type |= CUPS_PRINTER_REMOTE; | |
4617 | ||
4618 | #ifdef HAVE_APPLICATIONSERVICES_H | |
4619 | /* | |
4620 | * Convert the file referenced in APPrinterIconPath to a 128x128 PNG | |
4621 | * and save it as cacheDir/printername.png | |
4622 | */ | |
4623 | ||
4624 | if ((ppd_attr = ppdFindAttr(ppd, "APPrinterIconPath", NULL)) != NULL && | |
4625 | ppd_attr->value && | |
4626 | !_cupsFileCheck(ppd_attr->value, _CUPS_FILE_CHECK_FILE, !RunUser, | |
4627 | cupsdLogFCMessage, p)) | |
4628 | { | |
4629 | CGImageRef imageRef = NULL;/* Current icon image */ | |
4630 | CGImageRef biggestIconRef = NULL; | |
4631 | /* Biggest icon image */ | |
4632 | CGImageRef closestTo128IconRef = NULL; | |
4633 | /* Icon image closest to and >= 128 */ | |
4634 | CGImageSourceRef sourceRef; /* The file's image source */ | |
4635 | char outPath[HTTP_MAX_URI]; | |
4636 | /* The path to the PNG file */ | |
4637 | CFURLRef outUrl; /* The URL made from the outPath */ | |
4638 | CFURLRef icnsFileUrl; /* The URL of the original ICNS icon file */ | |
4639 | CGImageDestinationRef destRef; /* The image destination to write */ | |
4640 | size_t bytesPerRow; /* The bytes per row used for resizing */ | |
4641 | CGContextRef context; /* The CG context used for resizing */ | |
4642 | ||
4643 | snprintf(outPath, sizeof(outPath), "%s/%s.png", CacheDir, p->name); | |
4644 | outUrl = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, | |
4645 | (UInt8 *)outPath, | |
4646 | strlen(outPath), | |
4647 | FALSE); | |
4648 | icnsFileUrl = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, | |
4649 | (UInt8 *)ppd_attr->value, | |
4650 | strlen(ppd_attr->value), | |
4651 | FALSE); | |
4652 | if (outUrl && icnsFileUrl) | |
4653 | { | |
4654 | sourceRef = CGImageSourceCreateWithURL(icnsFileUrl, NULL); | |
4655 | if (sourceRef) | |
4656 | { | |
4657 | for (i = 0; i < CGImageSourceGetCount(sourceRef); i ++) | |
4658 | { | |
4659 | imageRef = CGImageSourceCreateImageAtIndex(sourceRef, i, NULL); | |
4660 | if (!imageRef) | |
4661 | continue; | |
4662 | ||
4663 | if (CGImageGetWidth(imageRef) == CGImageGetHeight(imageRef)) | |
4664 | { | |
4665 | /* | |
4666 | * Loop through remembering the icon closest to 128 but >= 128 | |
4667 | * and then remember the largest icon. | |
4668 | */ | |
4669 | ||
4670 | if (CGImageGetWidth(imageRef) >= 128 && | |
4671 | (!closestTo128IconRef || | |
4672 | CGImageGetWidth(imageRef) < | |
4673 | CGImageGetWidth(closestTo128IconRef))) | |
4674 | { | |
4675 | CGImageRelease(closestTo128IconRef); | |
4676 | CGImageRetain(imageRef); | |
4677 | closestTo128IconRef = imageRef; | |
4678 | } | |
4679 | ||
4680 | if (!biggestIconRef || | |
4681 | CGImageGetWidth(imageRef) > CGImageGetWidth(biggestIconRef)) | |
4682 | { | |
4683 | CGImageRelease(biggestIconRef); | |
4684 | CGImageRetain(imageRef); | |
4685 | biggestIconRef = imageRef; | |
4686 | } | |
4687 | } | |
4688 | ||
4689 | CGImageRelease(imageRef); | |
4690 | } | |
4691 | ||
4692 | if (biggestIconRef) | |
4693 | { | |
4694 | /* | |
4695 | * If biggestIconRef is NULL, we found no icons. Otherwise we first | |
4696 | * want the closest to 128, but if none are larger than 128, we want | |
4697 | * the largest icon available. | |
4698 | */ | |
4699 | ||
4700 | imageRef = closestTo128IconRef ? closestTo128IconRef : | |
4701 | biggestIconRef; | |
4702 | CGImageRetain(imageRef); | |
4703 | CGImageRelease(biggestIconRef); | |
4704 | if (closestTo128IconRef) | |
4705 | CGImageRelease(closestTo128IconRef); | |
4706 | destRef = CGImageDestinationCreateWithURL(outUrl, kUTTypePNG, 1, | |
4707 | NULL); | |
4708 | if (destRef) | |
4709 | { | |
4710 | if (CGImageGetWidth(imageRef) != 128) | |
4711 | { | |
4712 | bytesPerRow = CGImageGetBytesPerRow(imageRef) / | |
4713 | CGImageGetWidth(imageRef) * 128; | |
4714 | context = CGBitmapContextCreate(NULL, 128, 128, | |
4715 | CGImageGetBitsPerComponent(imageRef), | |
4716 | bytesPerRow, | |
4717 | CGImageGetColorSpace(imageRef), | |
4718 | kCGImageAlphaPremultipliedFirst); | |
4719 | if (context) | |
4720 | { | |
4721 | CGContextDrawImage(context, CGRectMake(0, 0, 128, 128), | |
4722 | imageRef); | |
4723 | CGImageRelease(imageRef); | |
4724 | imageRef = CGBitmapContextCreateImage(context); | |
4725 | CGContextRelease(context); | |
4726 | } | |
4727 | } | |
4728 | ||
4729 | CGImageDestinationAddImage(destRef, imageRef, NULL); | |
4730 | CGImageDestinationFinalize(destRef); | |
4731 | CFRelease(destRef); | |
4732 | } | |
4733 | ||
4734 | CGImageRelease(imageRef); | |
4735 | } | |
4736 | ||
4737 | CFRelease(sourceRef); | |
4738 | } | |
4739 | } | |
4740 | ||
4741 | if (outUrl) | |
4742 | CFRelease(outUrl); | |
4743 | ||
4744 | if (icnsFileUrl) | |
4745 | CFRelease(icnsFileUrl); | |
4746 | } | |
4747 | #endif /* HAVE_APPLICATIONSERVICES_H */ | |
4748 | ||
4749 | /* | |
4750 | * Close the PPD and set the type... | |
4751 | */ | |
4752 | ||
4753 | ppdClose(ppd); | |
4754 | } | |
4755 | else if (!access(ppd_name, 0)) | |
4756 | { | |
4757 | int pline; /* PPD line number */ | |
4758 | ppd_status_t pstatus; /* PPD load status */ | |
4759 | ||
4760 | ||
4761 | pstatus = ppdLastError(&pline); | |
4762 | ||
4763 | cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!", | |
4764 | p->name); | |
4765 | ||
4766 | if (pstatus <= PPD_ALLOC_ERROR) | |
4767 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno)); | |
4768 | else | |
4769 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.", | |
4770 | ppdErrorString(pstatus), pline); | |
4771 | ||
4772 | cupsdLogMessage(CUPSD_LOG_INFO, | |
4773 | "Hint: Run \"cupstestppd %s\" and fix any errors.", | |
4774 | ppd_name); | |
4775 | } | |
4776 | else | |
4777 | { | |
4778 | /* | |
4779 | * If we have an interface script, add a filter entry for it... | |
4780 | */ | |
4781 | ||
4782 | char interface[1024]; /* Interface script */ | |
4783 | ||
4784 | ||
4785 | snprintf(interface, sizeof(interface), "%s/interfaces/%s", ServerRoot, | |
4786 | p->name); | |
4787 | if (!access(interface, X_OK)) | |
4788 | { | |
4789 | /* | |
4790 | * Yes, we have a System V style interface script; use it! | |
4791 | */ | |
4792 | ||
4793 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
4794 | "printer-make-and-model", NULL, | |
4795 | "Local System V Printer"); | |
4796 | } | |
4797 | else if (!strncmp(p->device_uri, "ipp://", 6) && | |
4798 | (strstr(p->device_uri, "/printers/") != NULL || | |
4799 | strstr(p->device_uri, "/classes/") != NULL || | |
4800 | (strstr(p->device_uri, "._ipp.") != NULL && | |
4801 | !strcmp(p->device_uri + strlen(p->device_uri) - 5, | |
4802 | "/cups")))) | |
4803 | { | |
4804 | /* | |
4805 | * Tell the client this is really a hard-wired remote printer. | |
4806 | */ | |
4807 | ||
4808 | p->type |= CUPS_PRINTER_REMOTE; | |
4809 | ||
4810 | /* | |
4811 | * Point the printer-uri-supported attribute to the | |
4812 | * remote printer... | |
4813 | */ | |
4814 | ||
4815 | if (strchr(p->device_uri, '?')) | |
4816 | { | |
4817 | /* | |
4818 | * Strip trailing "?options" from URI... | |
4819 | */ | |
4820 | ||
4821 | char resource[HTTP_MAX_URI], /* New URI */ | |
4822 | *ptr; /* Pointer into URI */ | |
4823 | ||
4824 | strlcpy(resource, p->device_uri, sizeof(resource)); | |
4825 | if ((ptr = strchr(resource, '?')) != NULL) | |
4826 | *ptr = '\0'; | |
4827 | ||
4828 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, | |
4829 | "printer-uri-supported", NULL, resource); | |
4830 | } | |
4831 | else | |
4832 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, | |
4833 | "printer-uri-supported", NULL, p->device_uri); | |
4834 | ||
4835 | /* | |
4836 | * Then set the make-and-model accordingly... | |
4837 | */ | |
4838 | ||
4839 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
4840 | "printer-make-and-model", NULL, "Remote Printer"); | |
4841 | ||
4842 | /* | |
4843 | * Print all files directly... | |
4844 | */ | |
4845 | ||
4846 | p->raw = 1; | |
4847 | p->remote = 1; | |
4848 | } | |
4849 | else | |
4850 | { | |
4851 | /* | |
4852 | * Otherwise we have neither - treat this as a "dumb" printer | |
4853 | * with no PPD file... | |
4854 | */ | |
4855 | ||
4856 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
4857 | "printer-make-and-model", NULL, "Local Raw Printer"); | |
4858 | ||
4859 | p->raw = 1; | |
4860 | } | |
4861 | } | |
4862 | ||
4863 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
4864 | "finishings-supported", num_finishings, finishings); | |
4865 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
4866 | "finishings-default", IPP_FINISHINGS_NONE); | |
4867 | ||
4868 | if (ppd && p->pc) | |
4869 | { | |
4870 | /* | |
4871 | * Save cached PPD attributes to disk... | |
4872 | */ | |
4873 | ||
4874 | cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Saving %s...", cache_name); | |
4875 | ||
4876 | _ppdCacheWriteFile(p->pc, cache_name, p->ppd_attrs); | |
4877 | } | |
4878 | else | |
4879 | { | |
4880 | /* | |
4881 | * Remove cache files... | |
4882 | */ | |
4883 | ||
4884 | if (cache_info.st_mtime) | |
4885 | unlink(cache_name); | |
4886 | } | |
4887 | } | |
4888 | ||
4889 | ||
4890 | /* | |
4891 | * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer. | |
4892 | */ | |
4893 | ||
4894 | static void | |
4895 | log_ipp_conformance( | |
4896 | cupsd_printer_t *p, /* I - Printer */ | |
4897 | const char *reason) /* I - Printer state reason */ | |
4898 | { | |
4899 | const char *message; /* Message to log */ | |
4900 | #ifdef __APPLE__ | |
4901 | aslmsg aslm; /* Apple System Log message */ | |
4902 | #endif /* __APPLE__ */ | |
4903 | ||
4904 | ||
4905 | /* | |
4906 | * Strip the leading "cups-ipp-" from the reason and create a log message for | |
4907 | * it... | |
4908 | */ | |
4909 | ||
4910 | reason += 9; | |
4911 | if (!strcmp(reason, "missing-cancel-job")) | |
4912 | message = "Printer does not support REQUIRED Cancel-Job operation."; | |
4913 | else if (!strcmp(reason, "missing-get-job-attributes")) | |
4914 | message = "Printer does not support REQUIRED Get-Job-Attributes operation."; | |
4915 | else if (!strcmp(reason, "missing-print-job")) | |
4916 | message = "Printer does not support REQUIRED Print-Job operation."; | |
4917 | else if (!strcmp(reason, "missing-validate-job")) | |
4918 | message = "Printer does not support REQUIRED Validate-Job operation."; | |
4919 | else if (!strcmp(reason, "missing-get-printer-attributes")) | |
4920 | message = "Printer does not support REQUIRED Get-Printer-Attributes operation."; | |
4921 | else if (!strcmp(reason, "missing-job-history")) | |
4922 | message = "Printer does not provide REQUIRED job history."; | |
4923 | else if (!strcmp(reason, "missing-job-id")) | |
4924 | message = "Printer does not provide REQUIRED job-id attribute."; | |
4925 | else if (!strcmp(reason, "missing-job-state")) | |
4926 | message = "Printer does not provide REQUIRED job-state attribute."; | |
4927 | else if (!strcmp(reason, "missing-operations-supported")) | |
4928 | message = "Printer does not provide REQUIRED operations-supported " | |
4929 | "attribute."; | |
4930 | else if (!strcmp(reason, "missing-printer-is-accepting-jobs")) | |
4931 | message = "Printer does not provide REQUIRED printer-is-accepting-jobs " | |
4932 | "attribute."; | |
4933 | else if (!strcmp(reason, "missing-printer-state-reasons")) | |
4934 | message = "Printer does not provide REQUIRED printer-state-reasons " | |
4935 | "attribute."; | |
4936 | else if (!strcmp(reason, "wrong-http-version")) | |
4937 | message = "Printer does not use REQUIRED HTTP/1.1 transport."; | |
4938 | else | |
4939 | message = "Unknown IPP conformance failure."; | |
4940 | ||
4941 | cupsdLogMessage(CUPSD_LOG_WARN, "%s: %s", p->name, message); | |
4942 | ||
4943 | #ifdef __APPLE__ | |
4944 | /* | |
4945 | * Report the failure information to Apple if the user opts into providing | |
4946 | * feedback to Apple... | |
4947 | */ | |
4948 | ||
4949 | aslm = asl_new(ASL_TYPE_MSG); | |
4950 | if (aslm) | |
4951 | { | |
4952 | asl_set(aslm, "com.apple.message.domain", "com.apple.printing.ipp.conformance"); | |
4953 | asl_set(aslm, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance"); | |
4954 | asl_set(aslm, "com.apple.message.signature", reason); | |
4955 | asl_set(aslm, "com.apple.message.signature2", | |
4956 | p->make_model ? p->make_model : "Unknown"); | |
4957 | asl_log(NULL, aslm, ASL_LEVEL_NOTICE, "%s: %s", | |
4958 | p->make_model ? p->make_model : "Unknown", message); | |
4959 | asl_free(aslm); | |
4960 | } | |
4961 | #endif /* __APPLE__ */ | |
4962 | } | |
4963 | ||
4964 | ||
4965 | /* | |
4966 | * 'new_media_col()' - Create a media-col collection value. | |
4967 | */ | |
4968 | ||
4969 | static ipp_t * /* O - Collection value */ | |
4970 | new_media_col(_pwg_size_t *size, /* I - media-size/margin values */ | |
4971 | const char *source, /* I - media-source value */ | |
4972 | const char *type) /* I - media-type value */ | |
4973 | { | |
4974 | ipp_t *media_col, /* Collection value */ | |
4975 | *media_size; /* media-size value */ | |
4976 | ||
4977 | ||
4978 | media_col = ippNew(); | |
4979 | ||
4980 | media_size = ippNew(); | |
4981 | ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4982 | "x-dimension", size->width); | |
4983 | ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4984 | "y-dimension", size->length); | |
4985 | ippAddCollection(media_col, IPP_TAG_PRINTER, "media-size", media_size); | |
4986 | ippDelete(media_size); | |
4987 | ||
4988 | ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4989 | "media-bottom-margin", size->bottom); | |
4990 | ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4991 | "media-left-margin", size->left); | |
4992 | ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4993 | "media-right-margin", size->right); | |
4994 | ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4995 | "media-top-margin", size->top); | |
4996 | ||
4997 | if (source) | |
4998 | ippAddString(media_col, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-source", | |
4999 | NULL, source); | |
5000 | ||
5001 | if (type) | |
5002 | ippAddString(media_col, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-type", | |
5003 | NULL, type); | |
5004 | ||
5005 | return (media_col); | |
5006 | } | |
5007 | ||
5008 | ||
5009 | #ifdef __sgi | |
5010 | /* | |
5011 | * 'write_irix_config()' - Update the config files used by the IRIX | |
5012 | * desktop tools. | |
5013 | */ | |
5014 | ||
5015 | static void | |
5016 | write_irix_config(cupsd_printer_t *p) /* I - Printer to update */ | |
5017 | { | |
5018 | char filename[1024]; /* Interface script filename */ | |
5019 | cups_file_t *fp; /* Interface script file */ | |
5020 | ipp_attribute_t *attr; /* Attribute data */ | |
5021 | ||
5022 | ||
5023 | /* | |
5024 | * Add dummy interface and GUI scripts to fool SGI's "challenged" printing | |
5025 | * tools. First the interface script that tells the tools what kind of | |
5026 | * printer we have... | |
5027 | */ | |
5028 | ||
5029 | snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name); | |
5030 | ||
5031 | if (p->type & CUPS_PRINTER_CLASS) | |
5032 | unlink(filename); | |
5033 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5034 | { | |
5035 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
5036 | ||
5037 | if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model", | |
5038 | IPP_TAG_TEXT)) != NULL) | |
5039 | cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text); | |
5040 | else if (p->type & CUPS_PRINTER_CLASS) | |
5041 | cupsFilePuts(fp, "NAME=\"Printer Class\"\n"); | |
5042 | else | |
5043 | cupsFilePuts(fp, "NAME=\"Remote Destination\"\n"); | |
5044 | ||
5045 | if (p->type & CUPS_PRINTER_COLOR) | |
5046 | cupsFilePuts(fp, "TYPE=ColorPostScript\n"); | |
5047 | else | |
5048 | cupsFilePuts(fp, "TYPE=MonoPostScript\n"); | |
5049 | ||
5050 | cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName); | |
5051 | cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name); | |
5052 | ||
5053 | cupsFileClose(fp); | |
5054 | ||
5055 | chmod(filename, 0755); | |
5056 | chown(filename, User, Group); | |
5057 | } | |
5058 | ||
5059 | /* | |
5060 | * Then the member file that tells which device file the queue is connected | |
5061 | * to... Networked printers use "/dev/null" in this file, so that's what | |
5062 | * we use (the actual device URI can confuse some apps...) | |
5063 | */ | |
5064 | ||
5065 | snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name); | |
5066 | ||
5067 | if (p->type & CUPS_PRINTER_CLASS) | |
5068 | unlink(filename); | |
5069 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5070 | { | |
5071 | cupsFilePuts(fp, "/dev/null\n"); | |
5072 | ||
5073 | cupsFileClose(fp); | |
5074 | ||
5075 | chmod(filename, 0644); | |
5076 | chown(filename, User, Group); | |
5077 | } | |
5078 | ||
5079 | /* | |
5080 | * The gui_interface file is a script or program that launches a GUI | |
5081 | * option panel for the printer, using options specified on the | |
5082 | * command-line in the third argument. The option panel must send | |
5083 | * any printing options to stdout on a single line when the user | |
5084 | * accepts them, or nothing if the user cancels the dialog. | |
5085 | * | |
5086 | * The default options panel program is /usr/bin/glpoptions, from | |
5087 | * the ESP Print Pro software. You can select another using the | |
5088 | * PrintcapGUI option. | |
5089 | */ | |
5090 | ||
5091 | snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", p->name); | |
5092 | ||
5093 | if (p->type & CUPS_PRINTER_CLASS) | |
5094 | unlink(filename); | |
5095 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5096 | { | |
5097 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
5098 | cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name); | |
5099 | ||
5100 | cupsFileClose(fp); | |
5101 | ||
5102 | chmod(filename, 0755); | |
5103 | chown(filename, User, Group); | |
5104 | } | |
5105 | ||
5106 | /* | |
5107 | * The POD config file is needed by the printstatus command to show | |
5108 | * the printer location and device. | |
5109 | */ | |
5110 | ||
5111 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name); | |
5112 | ||
5113 | if (p->type & CUPS_PRINTER_CLASS) | |
5114 | unlink(filename); | |
5115 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5116 | { | |
5117 | cupsFilePrintf(fp, "Printer Class | %s\n", | |
5118 | (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript"); | |
5119 | cupsFilePrintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : ""); | |
5120 | cupsFilePrintf(fp, "Location Code | %s\n", p->location ? p->location : ""); | |
5121 | cupsFilePrintf(fp, "Physical Location | %s\n", p->info ? p->info : ""); | |
5122 | cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri); | |
5123 | cupsFilePrintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name); | |
5124 | cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name); | |
5125 | cupsFilePuts(fp, "Status Update Wait | 10 seconds\n"); | |
5126 | ||
5127 | cupsFileClose(fp); | |
5128 | ||
5129 | chmod(filename, 0664); | |
5130 | chown(filename, User, Group); | |
5131 | } | |
5132 | } | |
5133 | ||
5134 | ||
5135 | /* | |
5136 | * 'write_irix_state()' - Update the status files used by IRIX printing | |
5137 | * desktop tools. | |
5138 | */ | |
5139 | ||
5140 | static void | |
5141 | write_irix_state(cupsd_printer_t *p) /* I - Printer to update */ | |
5142 | { | |
5143 | char filename[1024]; /* Interface script filename */ | |
5144 | cups_file_t *fp; /* Interface script file */ | |
5145 | int tag; /* Status tag value */ | |
5146 | ||
5147 | ||
5148 | if (p) | |
5149 | { | |
5150 | /* | |
5151 | * The POD status file is needed for the printstatus window to | |
5152 | * provide the current status of the printer. | |
5153 | */ | |
5154 | ||
5155 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name); | |
5156 | ||
5157 | if (p->type & CUPS_PRINTER_CLASS) | |
5158 | unlink(filename); | |
5159 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5160 | { | |
5161 | cupsFilePrintf(fp, "Operational Status | %s\n", | |
5162 | (p->state == IPP_PRINTER_IDLE) ? "Idle" : | |
5163 | (p->state == IPP_PRINTER_PROCESSING) ? "Busy" : | |
5164 | "Faulted"); | |
5165 | cupsFilePrintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION); | |
5166 | cupsFilePrintf(fp, "Information | 02 00 00 | Device URI: %s\n", | |
5167 | p->device_uri); | |
5168 | cupsFilePrintf(fp, "Information | 03 00 00 | %s jobs\n", | |
5169 | p->accepting ? "Accepting" : "Not accepting"); | |
5170 | cupsFilePrintf(fp, "Information | 04 00 00 | %s\n", p->state_message); | |
5171 | ||
5172 | cupsFileClose(fp); | |
5173 | ||
5174 | chmod(filename, 0664); | |
5175 | chown(filename, User, Group); | |
5176 | } | |
5177 | ||
5178 | /* | |
5179 | * The activeicons file is needed to provide desktop icons for printers: | |
5180 | * | |
5181 | * [ quoted from /usr/lib/print/tagit ] | |
5182 | * | |
5183 | * --- Type of printer tags (base values) | |
5184 | * | |
5185 | * Dumb=66048 # 0x10200 | |
5186 | * DumbColor=66080 # 0x10220 | |
5187 | * Raster=66112 # 0x10240 | |
5188 | * ColorRaster=66144 # 0x10260 | |
5189 | * Plotter=66176 # 0x10280 | |
5190 | * PostScript=66208 # 0x102A0 | |
5191 | * ColorPostScript=66240 # 0x102C0 | |
5192 | * MonoPostScript=66272 # 0x102E0 | |
5193 | * | |
5194 | * --- Printer state modifiers for local printers | |
5195 | * | |
5196 | * Idle=0 # 0x0 | |
5197 | * Busy=1 # 0x1 | |
5198 | * Faulted=2 # 0x2 | |
5199 | * Unknown=3 # 0x3 (Faulted due to unknown reason) | |
5200 | * | |
5201 | * --- Printer state modifiers for network printers | |
5202 | * | |
5203 | * NetIdle=8 # 0x8 | |
5204 | * NetBusy=9 # 0x9 | |
5205 | * NetFaulted=10 # 0xA | |
5206 | * NetUnknown=11 # 0xB (Faulted due to unknown reason) | |
5207 | */ | |
5208 | ||
5209 | snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name); | |
5210 | ||
5211 | if (p->type & CUPS_PRINTER_CLASS) | |
5212 | unlink(filename); | |
5213 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5214 | { | |
5215 | if (p->type & CUPS_PRINTER_COLOR) | |
5216 | tag = 66240; | |
5217 | else | |
5218 | tag = 66272; | |
5219 | ||
5220 | if (p->type & CUPS_PRINTER_REMOTE) | |
5221 | tag |= 8; | |
5222 | ||
5223 | if (p->state == IPP_PRINTER_PROCESSING) | |
5224 | tag |= 1; | |
5225 | ||
5226 | else if (p->state == IPP_PRINTER_STOPPED) | |
5227 | tag |= 2; | |
5228 | ||
5229 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
5230 | cupsFilePrintf(fp, "#Tag %d\n", tag); | |
5231 | ||
5232 | cupsFileClose(fp); | |
5233 | ||
5234 | chmod(filename, 0755); | |
5235 | chown(filename, User, Group); | |
5236 | } | |
5237 | } | |
5238 | ||
5239 | /* | |
5240 | * The default file is needed by the printers window to show | |
5241 | * the default printer. | |
5242 | */ | |
5243 | ||
5244 | snprintf(filename, sizeof(filename), "/var/spool/lp/default"); | |
5245 | ||
5246 | if (DefaultPrinter != NULL) | |
5247 | { | |
5248 | if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5249 | { | |
5250 | cupsFilePrintf(fp, "%s\n", DefaultPrinter->name); | |
5251 | ||
5252 | cupsFileClose(fp); | |
5253 | ||
5254 | chmod(filename, 0644); | |
5255 | chown(filename, User, Group); | |
5256 | } | |
5257 | } | |
5258 | else | |
5259 | unlink(filename); | |
5260 | } | |
5261 | #endif /* __sgi */ | |
5262 | ||
5263 | ||
5264 | /* | |
5265 | * 'write_xml_string()' - Write a string with XML escaping. | |
5266 | */ | |
5267 | ||
5268 | static void | |
5269 | write_xml_string(cups_file_t *fp, /* I - File to write to */ | |
5270 | const char *s) /* I - String to write */ | |
5271 | { | |
5272 | const char *start; /* Start of current sequence */ | |
5273 | ||
5274 | ||
5275 | if (!s) | |
5276 | return; | |
5277 | ||
5278 | for (start = s; *s; s ++) | |
5279 | { | |
5280 | if (*s == '&') | |
5281 | { | |
5282 | if (s > start) | |
5283 | cupsFileWrite(fp, start, s - start); | |
5284 | ||
5285 | cupsFilePuts(fp, "&"); | |
5286 | start = s + 1; | |
5287 | } | |
5288 | else if (*s == '<') | |
5289 | { | |
5290 | if (s > start) | |
5291 | cupsFileWrite(fp, start, s - start); | |
5292 | ||
5293 | cupsFilePuts(fp, "<"); | |
5294 | start = s + 1; | |
5295 | } | |
5296 | } | |
5297 | ||
5298 | if (s > start) | |
5299 | cupsFilePuts(fp, start); | |
5300 | } | |
5301 | ||
5302 | ||
5303 | /* | |
5304 | * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $". | |
5305 | */ |