]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
0af14961 | 2 | * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $" |
ef416fc2 | 3 | * |
4220952d | 4 | * Printer routines for the CUPS scheduler. |
ef416fc2 | 5 | * |
12f89d24 | 6 | * Copyright 2007-2012 by Apple Inc. |
f7deaa1a | 7 | * Copyright 1997-2007 by Easy Software Products, all rights reserved. |
ef416fc2 | 8 | * |
9 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 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/". | |
ef416fc2 | 14 | * |
15 | * Contents: | |
16 | * | |
c168a833 | 17 | * cupsdAddPrinter() - Add a printer to the system. |
c168a833 MS |
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. | |
c168a833 MS |
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. | |
c168a833 MS |
45 | * compare_printers() - Compare two printers. |
46 | * delete_printer_filters() - Delete all MIME filters for a printer. | |
0268488e MS |
47 | * dirty_printer() - Mark config and state files dirty for the |
48 | * specified printer. | |
c168a833 MS |
49 | * load_ppd() - Load a cached PPD file, updating the cache as |
50 | * needed. | |
54afec33 | 51 | * new_media_col() - Create a media-col collection value. |
c168a833 MS |
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. | |
ef416fc2 | 57 | */ |
58 | ||
59 | /* | |
60 | * Include necessary headers... | |
61 | */ | |
62 | ||
63 | #include "cupsd.h" | |
ed486911 | 64 | #include <cups/dir.h> |
7cf5915e MS |
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 */ | |
7cf5915e MS |
71 | #ifdef HAVE_SYS_STATVFS_H |
72 | # include <sys/statvfs.h> | |
0268488e MS |
73 | #elif defined(HAVE_SYS_STATFS_H) |
74 | # include <sys/statfs.h> | |
7cf5915e MS |
75 | #endif /* HAVE_SYS_STATVFS_H */ |
76 | #ifdef HAVE_SYS_VFS_H | |
77 | # include <sys/vfs.h> | |
78 | #endif /* HAVE_SYS_VFS_H */ | |
bd8b6777 MS |
79 | #ifdef __APPLE__ |
80 | # include <asl.h> | |
81 | #endif /* __APPLE__ */ | |
ef416fc2 | 82 | |
83 | ||
84 | /* | |
85 | * Local functions... | |
86 | */ | |
87 | ||
b423cd4c | 88 | static void add_printer_defaults(cupsd_printer_t *p); |
f7deaa1a | 89 | static void add_printer_filter(cupsd_printer_t *p, mime_type_t *type, |
90 | const char *filter); | |
bd7854cb | 91 | static void add_printer_formats(cupsd_printer_t *p); |
ef416fc2 | 92 | static int compare_printers(void *first, void *second, void *data); |
e1d6a774 | 93 | static void delete_printer_filters(cupsd_printer_t *p); |
0268488e | 94 | static void dirty_printer(cupsd_printer_t *p); |
61cf44e2 | 95 | static void load_ppd(cupsd_printer_t *p); |
bd8b6777 | 96 | static void log_ipp_conformance(cupsd_printer_t *p, const char *reason); |
54afec33 MS |
97 | static ipp_t *new_media_col(_pwg_size_t *size, const char *source, |
98 | const char *type); | |
ef416fc2 | 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 */ | |
0af14961 | 103 | static void write_xml_string(cups_file_t *fp, const char *s); |
ef416fc2 | 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 */ | |
82f97232 MS |
114 | char uri[1024], /* Printer URI */ |
115 | uuid[64]; /* Printer UUID */ | |
ef416fc2 | 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 | ||
7cf5915e MS |
139 | httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, |
140 | ServerName, RemotePort, "/printers/%s", name); | |
141 | cupsdSetString(&p->uri, uri); | |
07ed0e9a MS |
142 | cupsdSetString(&p->uuid, _httpAssembleUUID(ServerName, RemotePort, name, 0, |
143 | uuid, sizeof(uuid))); | |
f0ab5bff | 144 | cupsdSetDeviceURI(p, "file:///dev/null"); |
ef416fc2 | 145 | |
146 | p->state = IPP_PRINTER_STOPPED; | |
147 | p->state_time = time(NULL); | |
148 | p->accepting = 0; | |
fa73b229 | 149 | p->shared = DefaultShared; |
ef416fc2 | 150 | p->filetype = mimeAddType(MimeDatabase, "printer", name); |
151 | ||
152 | cupsdSetString(&p->job_sheets[0], "none"); | |
153 | cupsdSetString(&p->job_sheets[1], "none"); | |
154 | ||
323c5de1 | 155 | cupsdSetString(&p->error_policy, ErrorPolicy); |
ef416fc2 | 156 | cupsdSetString(&p->op_policy, DefaultPolicy); |
157 | ||
158 | p->op_policy_ptr = DefaultPolicyPtr; | |
159 | ||
ef416fc2 | 160 | /* |
161 | * Insert the printer in the printer list alphabetically... | |
162 | */ | |
163 | ||
164 | if (!Printers) | |
165 | Printers = cupsArrayNew(compare_printers, NULL); | |
166 | ||
1f0275e3 MS |
167 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
168 | "cupsdAddPrinter: Adding %s to Printers", p->name); | |
ef416fc2 | 169 | cupsArrayAdd(Printers, p); |
170 | ||
ef416fc2 | 171 | /* |
172 | * Return the new printer... | |
173 | */ | |
174 | ||
175 | return (p); | |
176 | } | |
177 | ||
178 | ||
ef416fc2 | 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 */ | |
ed486911 | 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 */ | |
2e4ff8af | 193 | cupsd_policy_t *p; /* Current policy */ |
7cf5915e | 194 | int k_supported; /* Maximum file size supported */ |
0268488e | 195 | #ifdef HAVE_STATVFS |
7cf5915e MS |
196 | struct statvfs spoolinfo; /* FS info for spool directory */ |
197 | double spoolsize; /* FS size */ | |
0268488e MS |
198 | #elif defined(HAVE_STATFS) |
199 | struct statfs spoolinfo; /* FS info for spool directory */ | |
200 | double spoolsize; /* FS size */ | |
201 | #endif /* HAVE_STATVFS */ | |
ef416fc2 | 202 | static const int nups[] = /* number-up-supported values */ |
203 | { 1, 2, 4, 6, 9, 16 }; | |
b94498cf | 204 | static const int orients[4] =/* orientation-requested-supported values */ |
ef416fc2 | 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", | |
c168a833 MS |
225 | "1.1", |
226 | "2.0", | |
227 | "2.1" | |
ef416fc2 | 228 | }; |
b94498cf | 229 | static const int ops[] = /* operations-supported values */ |
ef416fc2 | 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, | |
cc754834 | 241 | IPP_RESTART_JOB, |
ef416fc2 | 242 | IPP_PAUSE_PRINTER, |
243 | IPP_RESUME_PRINTER, | |
244 | IPP_PURGE_JOBS, | |
c168a833 | 245 | IPP_SET_PRINTER_ATTRIBUTES, |
ef416fc2 | 246 | IPP_SET_JOB_ATTRIBUTES, |
c168a833 | 247 | IPP_GET_PRINTER_SUPPORTED_VALUES, |
ef416fc2 | 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, | |
61cf44e2 MS |
257 | IPP_HOLD_NEW_JOBS, |
258 | IPP_RELEASE_HELD_NEW_JOBS, | |
aaf19ab0 MS |
259 | IPP_CANCEL_JOBS, |
260 | IPP_CANCEL_MY_JOBS, | |
261 | IPP_CLOSE_JOB, | |
ef416fc2 | 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, | |
2e4ff8af MS |
276 | CUPS_GET_PPD, |
277 | CUPS_GET_DOCUMENT, | |
ef416fc2 | 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 | }; | |
d2354e63 MS |
292 | static const char * const media_col_supported[] = |
293 | { /* media-col-supported values */ | |
54afec33 | 294 | "media-bottom-margin", |
54afec33 MS |
295 | "media-left-margin", |
296 | "media-right-margin", | |
d2354e63 | 297 | "media-size", |
aaf19ab0 | 298 | "media-source", |
54afec33 | 299 | "media-top-margin", |
d2354e63 MS |
300 | "media-type" |
301 | }; | |
ef416fc2 | 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 | }; | |
ef416fc2 | 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 | }; | |
54afec33 MS |
337 | static const char * const job_creation[] = |
338 | { /* job-creation-attributes-supported */ | |
339 | "copies", | |
340 | "finishings", | |
cc754834 | 341 | "ipp-attribute-fidelity", |
54afec33 MS |
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 | "orientation-requested", | |
352 | "page-ranges", | |
5a9febac | 353 | "print-color-mode", |
54afec33 MS |
354 | "print-quality", |
355 | "printer-resolution", | |
356 | "sides" | |
357 | }; | |
1f6f3dbc MS |
358 | static const char * const job_settable[] = |
359 | { /* job-settable-attributes-supported */ | |
360 | "copies", | |
361 | "finishings", | |
362 | "job-hold-until", | |
54afec33 | 363 | "job-name", |
1f6f3dbc MS |
364 | "job-priority", |
365 | "media", | |
54afec33 | 366 | "media-col", |
1f6f3dbc MS |
367 | "multiple-document-handling", |
368 | "number-up", | |
54afec33 | 369 | "output-bin", |
1f6f3dbc MS |
370 | "orientation-requested", |
371 | "page-ranges", | |
5a9febac | 372 | "print-color-mode", |
1f6f3dbc MS |
373 | "print-quality", |
374 | "printer-resolution", | |
375 | "sides" | |
376 | }; | |
84315f46 MS |
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 | }; | |
c168a833 MS |
389 | static const char * const printer_settable[] = |
390 | { /* printer-settable-attributes-supported */ | |
391 | "printer-info", | |
392 | "printer-location" | |
393 | }; | |
aaf19ab0 | 394 | static const char * const which_jobs[] = |
7cf5915e MS |
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 | }; | |
ef416fc2 | 406 | |
407 | ||
408 | if (CommonData) | |
409 | ippDelete(CommonData); | |
410 | ||
411 | CommonData = ippNew(); | |
412 | ||
7cf5915e MS |
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 | ||
0268488e MS |
419 | #ifdef HAVE_STATVFS |
420 | if (statvfs(RequestRoot, &spoolinfo)) | |
7cf5915e | 421 | k_supported = INT_MAX; |
0268488e | 422 | else if ((spoolsize = (double)spoolinfo.f_frsize * spoolinfo.f_blocks / 1024) > |
7cf5915e MS |
423 | INT_MAX) |
424 | k_supported = INT_MAX; | |
425 | else | |
426 | k_supported = (int)spoolsize; | |
427 | ||
0268488e MS |
428 | #elif defined(HAVE_STATFS) |
429 | if (statfs(RequestRoot, &spoolinfo)) | |
7cf5915e | 430 | k_supported = INT_MAX; |
0268488e | 431 | else if ((spoolsize = (double)spoolinfo.f_bsize * spoolinfo.f_blocks / 1024) > |
7cf5915e MS |
432 | INT_MAX) |
433 | k_supported = INT_MAX; | |
434 | else | |
435 | k_supported = (int)spoolsize; | |
436 | ||
437 | #else | |
438 | k_supported = INT_MAX; | |
0268488e | 439 | #endif /* HAVE_STATVFS */ |
7cf5915e | 440 | |
ef416fc2 | 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 */ | |
1f6f3dbc | 447 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET | IPP_TAG_COPY, |
f8b3a85b | 448 | "charset-configured", NULL, "utf-8"); |
ef416fc2 | 449 | |
450 | /* charset-supported */ | |
1f6f3dbc | 451 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET | IPP_TAG_COPY, |
ef416fc2 | 452 | "charset-supported", sizeof(charsets) / sizeof(charsets[0]), |
453 | NULL, charsets); | |
454 | ||
455 | /* compression-supported */ | |
1f6f3dbc | 456 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, |
ef416fc2 | 457 | "compression-supported", |
458 | sizeof(compressions) / sizeof(compressions[0]), | |
459 | NULL, compressions); | |
460 | ||
ef416fc2 | 461 | /* copies-supported */ |
462 | ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies); | |
463 | ||
b94498cf | 464 | /* cups-version */ |
1f6f3dbc MS |
465 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_TEXT | IPP_TAG_COPY, |
466 | "cups-version", NULL, CUPS_SVERSION + 6); | |
b94498cf | 467 | |
f8b3a85b MS |
468 | /* generated-natural-language-supported (no IPP_TAG_COPY) */ |
469 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE, | |
ef416fc2 | 470 | "generated-natural-language-supported", NULL, DefaultLanguage); |
471 | ||
472 | /* ipp-versions-supported */ | |
1f6f3dbc | 473 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, |
ef416fc2 | 474 | "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]), |
475 | NULL, versions); | |
476 | ||
cc754834 MS |
477 | /* ippget-event-life */ |
478 | ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
479 | "ippget-event-life", 15); | |
480 | ||
54afec33 MS |
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 | ||
ef416fc2 | 487 | /* job-hold-until-supported */ |
1f6f3dbc | 488 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, |
ef416fc2 | 489 | "job-hold-until-supported", sizeof(holds) / sizeof(holds[0]), |
490 | NULL, holds); | |
491 | ||
aaf19ab0 MS |
492 | /* job-ids-supported */ |
493 | ippAddBoolean(CommonData, IPP_TAG_PRINTER, "job-ids-supported", 1); | |
494 | ||
7cf5915e | 495 | /* job-k-octets-supported */ |
83e08001 MS |
496 | ippAddRange(CommonData, IPP_TAG_PRINTER, "job-k-octets-supported", 0, |
497 | k_supported); | |
7cf5915e | 498 | |
ef416fc2 | 499 | /* job-priority-supported */ |
500 | ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
501 | "job-priority-supported", 100); | |
502 | ||
1f6f3dbc MS |
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 | ||
ef416fc2 | 509 | /* job-sheets-supported */ |
fa73b229 | 510 | if (cupsArrayCount(Banners) > 0) |
ef416fc2 | 511 | { |
512 | /* | |
513 | * Setup the job-sheets-supported attribute... | |
514 | */ | |
515 | ||
516 | if (Classification && !ClassifyOverride) | |
1f6f3dbc MS |
517 | attr = ippAddString(CommonData, IPP_TAG_PRINTER, |
518 | IPP_TAG_NAME | IPP_TAG_COPY, | |
ef416fc2 | 519 | "job-sheets-supported", NULL, Classification); |
520 | else | |
1f6f3dbc MS |
521 | attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, |
522 | IPP_TAG_NAME | IPP_TAG_COPY, | |
fa73b229 | 523 | "job-sheets-supported", cupsArrayCount(Banners) + 1, |
524 | NULL, NULL); | |
ef416fc2 | 525 | |
526 | if (attr == NULL) | |
527 | cupsdLogMessage(CUPSD_LOG_EMERG, | |
bd7854cb | 528 | "Unable to allocate memory for " |
ef416fc2 | 529 | "job-sheets-supported attribute: %s!", strerror(errno)); |
530 | else if (!Classification || ClassifyOverride) | |
531 | { | |
fa73b229 | 532 | cupsd_banner_t *banner; /* Current banner */ |
533 | ||
534 | ||
757d2cad | 535 | attr->values[0].string.text = _cupsStrAlloc("none"); |
ef416fc2 | 536 | |
fa73b229 | 537 | for (i = 1, banner = (cupsd_banner_t *)cupsArrayFirst(Banners); |
538 | banner; | |
539 | i ++, banner = (cupsd_banner_t *)cupsArrayNext(Banners)) | |
1f6f3dbc | 540 | attr->values[i].string.text = banner->name; |
ef416fc2 | 541 | } |
542 | } | |
543 | else | |
1f6f3dbc | 544 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY, |
ef416fc2 | 545 | "job-sheets-supported", NULL, "none"); |
546 | ||
84315f46 MS |
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 | ||
d2354e63 MS |
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 | ||
ef416fc2 | 566 | /* multiple-document-handling-supported */ |
1f6f3dbc | 567 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, |
ef416fc2 | 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, | |
dfd5680b | 579 | "multiple-operation-time-out", MultipleOperationTimeout); |
ef416fc2 | 580 | |
f8b3a85b MS |
581 | /* natural-language-configured (no IPP_TAG_COPY) */ |
582 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE, | |
ef416fc2 | 583 | "natural-language-configured", NULL, DefaultLanguage); |
584 | ||
585 | /* notify-attributes-supported */ | |
1f6f3dbc | 586 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, |
ef416fc2 | 587 | "notify-attributes-supported", |
588 | (int)(sizeof(notify_attrs) / sizeof(notify_attrs[0])), | |
589 | NULL, notify_attrs); | |
590 | ||
ef416fc2 | 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 | ||
ed486911 | 600 | /* notify-events-supported */ |
1f6f3dbc | 601 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, |
ef416fc2 | 602 | "notify-events-supported", |
603 | (int)(sizeof(notify_events) / sizeof(notify_events[0])), | |
604 | NULL, notify_events); | |
605 | ||
606 | /* notify-pull-method-supported */ | |
1f6f3dbc | 607 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, |
ef416fc2 | 608 | "notify-pull-method-supported", NULL, "ippget"); |
609 | ||
ef416fc2 | 610 | /* notify-schemes-supported */ |
ed486911 | 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); | |
8ca02f3c | 634 | cupsDirClose(dir); |
ed486911 | 635 | } |
ef416fc2 | 636 | |
ef416fc2 | 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, | |
82cc1f9a | 643 | "operations-supported", sizeof(ops) / sizeof(ops[0]), ops); |
ef416fc2 | 644 | |
ef416fc2 | 645 | /* orientation-requested-supported */ |
646 | ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
b94498cf | 647 | "orientation-requested-supported", 4, orients); |
ef416fc2 | 648 | |
649 | /* page-ranges-supported */ | |
650 | ippAddBoolean(CommonData, IPP_TAG_PRINTER, "page-ranges-supported", 1); | |
651 | ||
84315f46 MS |
652 | /* pdf-k-octets-supported */ |
653 | ippAddRange(CommonData, IPP_TAG_PRINTER, "pdf-k-octets-supported", 0, | |
654 | k_supported); | |
655 | ||
656 | /* pdf-versions-supported */ | |
657 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
658 | "pdf-versions-supported", | |
659 | sizeof(pdf_versions) / sizeof(pdf_versions[0]), NULL, | |
660 | pdf_versions); | |
661 | ||
7cf5915e | 662 | /* pdl-override-supported */ |
1f6f3dbc | 663 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, |
7cf5915e | 664 | "pdl-override-supported", NULL, "attempted"); |
ef416fc2 | 665 | |
ef416fc2 | 666 | /* printer-op-policy-supported */ |
1f6f3dbc | 667 | attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY, |
2e4ff8af MS |
668 | "printer-op-policy-supported", cupsArrayCount(Policies), |
669 | NULL, NULL); | |
670 | for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies); | |
671 | p; | |
672 | i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies)) | |
1f6f3dbc | 673 | attr->values[i].string.text = p->name; |
2e4ff8af | 674 | |
c168a833 MS |
675 | /* printer-settable-attributes-supported */ |
676 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
677 | "printer-settable-attributes-supported", | |
678 | sizeof(printer_settable) / sizeof(printer_settable[0]), | |
679 | NULL, printer_settable); | |
680 | ||
1f6f3dbc | 681 | /* server-is-sharing-printers */ |
2e4ff8af MS |
682 | ippAddBoolean(CommonData, IPP_TAG_PRINTER, "server-is-sharing-printers", |
683 | BrowseLocalProtocols != 0 && Browsing); | |
aaf19ab0 MS |
684 | |
685 | /* which-jobs-supported */ | |
686 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY, | |
687 | "which-jobs-supported", | |
688 | sizeof(which_jobs) / sizeof(which_jobs[0]), NULL, which_jobs); | |
ef416fc2 | 689 | } |
690 | ||
691 | ||
692 | /* | |
693 | * 'cupsdDeleteAllPrinters()' - Delete all printers from the system. | |
694 | */ | |
695 | ||
696 | void | |
697 | cupsdDeleteAllPrinters(void) | |
698 | { | |
699 | cupsd_printer_t *p; /* Pointer to current printer/class */ | |
700 | ||
701 | ||
702 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
703 | p; | |
704 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
5a662dc0 MS |
705 | { |
706 | p->op_policy_ptr = DefaultPolicyPtr; | |
0af14961 | 707 | cupsdDeletePrinter(p, 0); |
5a662dc0 | 708 | } |
ef416fc2 | 709 | } |
710 | ||
711 | ||
712 | /* | |
713 | * 'cupsdDeletePrinter()' - Delete a printer from the system. | |
714 | */ | |
715 | ||
f8b3a85b | 716 | int /* O - 1 if classes affected, 0 otherwise */ |
ef416fc2 | 717 | cupsdDeletePrinter( |
718 | cupsd_printer_t *p, /* I - Printer to delete */ | |
719 | int update) /* I - Update printers.conf? */ | |
720 | { | |
f8b3a85b MS |
721 | int i, /* Looping var */ |
722 | changed = 0; /* Class changed? */ | |
ef416fc2 | 723 | #ifdef __sgi |
61cf44e2 | 724 | char filename[1024]; /* Interface script filename */ |
ef416fc2 | 725 | #endif /* __sgi */ |
726 | ||
727 | ||
728 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdDeletePrinter(p=%p(%s), update=%d)", | |
729 | p, p->name, update); | |
730 | ||
731 | /* | |
732 | * Save the current position in the Printers array... | |
733 | */ | |
734 | ||
735 | cupsArraySave(Printers); | |
736 | ||
737 | /* | |
738 | * Stop printing on this printer... | |
739 | */ | |
740 | ||
e07d4801 MS |
741 | cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, update); |
742 | ||
0268488e MS |
743 | p->state = IPP_PRINTER_STOPPED; /* Force for browsed printers */ |
744 | ||
e07d4801 MS |
745 | if (p->job) |
746 | cupsdSetJobState(p->job, IPP_JOB_PENDING, CUPSD_JOB_FORCE, | |
747 | update ? "Job stopped due to printer being deleted." : | |
748 | "Job stopped."); | |
ef416fc2 | 749 | |
ef416fc2 | 750 | /* |
751 | * Remove the printer from the list... | |
752 | */ | |
753 | ||
1f0275e3 MS |
754 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
755 | "cupsdDeletePrinter: Removing %s from Printers", p->name); | |
ef416fc2 | 756 | cupsArrayRemove(Printers, p); |
757 | ||
758 | /* | |
759 | * Remove the dummy interface/icon/option files under IRIX... | |
760 | */ | |
761 | ||
762 | #ifdef __sgi | |
763 | snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name); | |
764 | unlink(filename); | |
765 | ||
766 | snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", | |
767 | p->name); | |
768 | unlink(filename); | |
769 | ||
770 | snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name); | |
771 | unlink(filename); | |
772 | ||
773 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name); | |
774 | unlink(filename); | |
775 | ||
776 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name); | |
777 | unlink(filename); | |
778 | ||
779 | snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name); | |
780 | unlink(filename); | |
781 | #endif /* __sgi */ | |
782 | ||
783 | /* | |
e00b005a | 784 | * If p is the default printer, assign a different one... |
ef416fc2 | 785 | */ |
786 | ||
787 | if (p == DefaultPrinter) | |
e00b005a | 788 | DefaultPrinter = NULL; |
789 | ||
ef416fc2 | 790 | /* |
f7deaa1a | 791 | * Remove this printer from any classes... |
ef416fc2 | 792 | */ |
793 | ||
a2326b5b | 794 | changed = cupsdDeletePrinterFromClasses(p); |
f7deaa1a | 795 | |
a2326b5b MS |
796 | /* |
797 | * Deregister from any browse protocols... | |
798 | */ | |
f7deaa1a | 799 | |
a2326b5b | 800 | cupsdDeregisterPrinter(p, 1); |
ef416fc2 | 801 | |
802 | /* | |
803 | * Free all memory used by the printer... | |
804 | */ | |
805 | ||
806 | if (p->printers != NULL) | |
807 | free(p->printers); | |
808 | ||
b9faaae1 MS |
809 | delete_printer_filters(p); |
810 | ||
ef416fc2 | 811 | for (i = 0; i < p->num_reasons; i ++) |
1f6f3dbc | 812 | _cupsStrFree(p->reasons[i]); |
ef416fc2 | 813 | |
814 | ippDelete(p->attrs); | |
61cf44e2 | 815 | ippDelete(p->ppd_attrs); |
ef416fc2 | 816 | |
fa73b229 | 817 | mimeDeleteType(MimeDatabase, p->filetype); |
f7deaa1a | 818 | mimeDeleteType(MimeDatabase, p->prefiltertype); |
fa73b229 | 819 | |
10d09e33 | 820 | cupsdFreeStrings(&(p->users)); |
ef416fc2 | 821 | cupsdFreeQuotas(p); |
822 | ||
823 | cupsdClearString(&p->uri); | |
824 | cupsdClearString(&p->hostname); | |
825 | cupsdClearString(&p->name); | |
826 | cupsdClearString(&p->location); | |
827 | cupsdClearString(&p->make_model); | |
828 | cupsdClearString(&p->info); | |
829 | cupsdClearString(&p->job_sheets[0]); | |
830 | cupsdClearString(&p->job_sheets[1]); | |
831 | cupsdClearString(&p->device_uri); | |
0af14961 | 832 | cupsdClearString(&p->sanitized_device_uri); |
ef416fc2 | 833 | cupsdClearString(&p->port_monitor); |
834 | cupsdClearString(&p->op_policy); | |
835 | cupsdClearString(&p->error_policy); | |
836 | ||
323c5de1 | 837 | cupsdClearString(&p->alert); |
838 | cupsdClearString(&p->alert_description); | |
839 | ||
f3c17241 | 840 | #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) |
f7deaa1a | 841 | cupsdClearString(&p->pdl); |
f3c17241 MS |
842 | cupsdClearString(&p->reg_name); |
843 | #endif /* HAVE_DNSSD || HAVE_AVAHI */ | |
f7deaa1a | 844 | |
80ca4592 | 845 | cupsArrayDelete(p->filetypes); |
846 | ||
b423cd4c | 847 | cupsFreeOptions(p->num_options, p->options); |
848 | ||
ef416fc2 | 849 | free(p); |
850 | ||
851 | /* | |
852 | * Restore the previous position in the Printers array... | |
853 | */ | |
854 | ||
855 | cupsArrayRestore(Printers); | |
f8b3a85b MS |
856 | |
857 | return (changed); | |
ef416fc2 | 858 | } |
859 | ||
860 | ||
ef416fc2 | 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 | ||
ef416fc2 | 893 | /* |
894 | * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file. | |
895 | */ | |
896 | ||
897 | void | |
898 | cupsdLoadAllPrinters(void) | |
899 | { | |
745129be | 900 | int i; /* Looping var */ |
ef416fc2 | 901 | cups_file_t *fp; /* printers.conf file */ |
902 | int linenum; /* Current line number */ | |
d1c13e16 | 903 | char line[4096], /* Line from file */ |
ef416fc2 | 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); | |
321d8d57 | 914 | if ((fp = cupsdOpenConfFile(line)) == NULL) |
ef416fc2 | 915 | return; |
ef416fc2 | 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 | ||
88f9aafc MS |
930 | if (!_cups_strcasecmp(line, "<Printer") || |
931 | !_cups_strcasecmp(line, "<DefaultPrinter")) | |
ef416fc2 | 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 | ||
bd7854cb | 943 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading printer %s...", value); |
ef416fc2 | 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 | ||
88f9aafc | 953 | if (!_cups_strcasecmp(line, "<DefaultPrinter")) |
ef416fc2 | 954 | DefaultPrinter = p; |
955 | } | |
956 | else | |
ef416fc2 | 957 | cupsdLogMessage(CUPSD_LOG_ERROR, |
958 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 959 | } |
88f9aafc | 960 | else if (!_cups_strcasecmp(line, "</Printer>")) |
ef416fc2 | 961 | { |
962 | if (p != NULL) | |
963 | { | |
964 | /* | |
965 | * Close out the current printer... | |
966 | */ | |
967 | ||
968 | cupsdSetPrinterAttrs(p); | |
ef416fc2 | 969 | |
0af14961 | 970 | if (strncmp(p->device_uri, "file:", 5) && |
ef416fc2 | 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 | |
ef416fc2 | 998 | cupsdLogMessage(CUPSD_LOG_ERROR, |
999 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1000 | } |
1001 | else if (!p) | |
1002 | { | |
1003 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1004 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1005 | } |
88f9aafc | 1006 | else if (!_cups_strcasecmp(line, "UUID")) |
82f97232 MS |
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 | } | |
88f9aafc | 1014 | else if (!_cups_strcasecmp(line, "AuthInfoRequired")) |
f7deaa1a | 1015 | { |
1016 | if (!cupsdSetAuthInfoRequired(p, value, NULL)) | |
1017 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1018 | "Bad AuthInfoRequired on line %d of printers.conf.", | |
1019 | linenum); | |
1020 | } | |
88f9aafc | 1021 | else if (!_cups_strcasecmp(line, "Info")) |
ef416fc2 | 1022 | { |
1023 | if (value) | |
1024 | cupsdSetString(&p->info, value); | |
1025 | } | |
88f9aafc | 1026 | else if (!_cups_strcasecmp(line, "MakeModel")) |
58dc1933 MS |
1027 | { |
1028 | if (value) | |
1029 | cupsdSetString(&p->make_model, value); | |
1030 | } | |
88f9aafc | 1031 | else if (!_cups_strcasecmp(line, "Location")) |
ef416fc2 | 1032 | { |
1033 | if (value) | |
1034 | cupsdSetString(&p->location, value); | |
1035 | } | |
88f9aafc | 1036 | else if (!_cups_strcasecmp(line, "DeviceURI")) |
ef416fc2 | 1037 | { |
1038 | if (value) | |
0af14961 | 1039 | cupsdSetDeviceURI(p, value); |
ef416fc2 | 1040 | else |
ef416fc2 | 1041 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1042 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1043 | } |
88f9aafc | 1044 | else if (!_cups_strcasecmp(line, "Option") && value) |
b423cd4c | 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 | } | |
88f9aafc | 1063 | else if (!_cups_strcasecmp(line, "PortMonitor")) |
ef416fc2 | 1064 | { |
1065 | if (value && strcmp(value, "none")) | |
1066 | cupsdSetString(&p->port_monitor, value); | |
1067 | else if (value) | |
1068 | cupsdClearString(&p->port_monitor); | |
1069 | else | |
ef416fc2 | 1070 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1071 | "Syntax error on line %d of printers.conf.", linenum); | |
0af14961 | 1072 | } |
88f9aafc | 1073 | else if (!_cups_strcasecmp(line, "Reason")) |
0af14961 | 1074 | { |
b9faaae1 | 1075 | if (value && |
b9faaae1 | 1076 | strcmp(value, "connecting-to-device") && |
38e73f87 MS |
1077 | strcmp(value, "cups-insecure-filter-warning") && |
1078 | strcmp(value, "cups-missing-filter-warning")) | |
0af14961 | 1079 | { |
745129be MS |
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 | } | |
ef416fc2 | 1090 | } |
0af14961 MS |
1091 | else |
1092 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1093 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1094 | } |
88f9aafc | 1095 | else if (!_cups_strcasecmp(line, "State")) |
ef416fc2 | 1096 | { |
1097 | /* | |
1098 | * Set the initial queue state... | |
1099 | */ | |
1100 | ||
88f9aafc | 1101 | if (value && !_cups_strcasecmp(value, "idle")) |
ef416fc2 | 1102 | p->state = IPP_PRINTER_IDLE; |
88f9aafc | 1103 | else if (value && !_cups_strcasecmp(value, "stopped")) |
745129be | 1104 | { |
ef416fc2 | 1105 | p->state = IPP_PRINTER_STOPPED; |
68b10830 MS |
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 | } | |
745129be | 1117 | } |
ef416fc2 | 1118 | else |
ef416fc2 | 1119 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1120 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1121 | } |
88f9aafc | 1122 | else if (!_cups_strcasecmp(line, "StateMessage")) |
ef416fc2 | 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 | } | |
88f9aafc | 1131 | else if (!_cups_strcasecmp(line, "StateTime")) |
ef416fc2 | 1132 | { |
1133 | /* | |
1134 | * Set the state time... | |
1135 | */ | |
1136 | ||
1137 | if (value) | |
1138 | p->state_time = atoi(value); | |
1139 | } | |
88f9aafc | 1140 | else if (!_cups_strcasecmp(line, "Accepting")) |
ef416fc2 | 1141 | { |
1142 | /* | |
1143 | * Set the initial accepting state... | |
1144 | */ | |
1145 | ||
1146 | if (value && | |
88f9aafc MS |
1147 | (!_cups_strcasecmp(value, "yes") || |
1148 | !_cups_strcasecmp(value, "on") || | |
1149 | !_cups_strcasecmp(value, "true"))) | |
ef416fc2 | 1150 | p->accepting = 1; |
1151 | else if (value && | |
88f9aafc MS |
1152 | (!_cups_strcasecmp(value, "no") || |
1153 | !_cups_strcasecmp(value, "off") || | |
1154 | !_cups_strcasecmp(value, "false"))) | |
ef416fc2 | 1155 | p->accepting = 0; |
1156 | else | |
ef416fc2 | 1157 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1158 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1159 | } |
88f9aafc | 1160 | else if (!_cups_strcasecmp(line, "Type")) |
58dc1933 MS |
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 | } | |
88f9aafc | 1168 | else if (!_cups_strcasecmp(line, "Shared")) |
ef416fc2 | 1169 | { |
1170 | /* | |
1171 | * Set the initial shared state... | |
1172 | */ | |
1173 | ||
1174 | if (value && | |
88f9aafc MS |
1175 | (!_cups_strcasecmp(value, "yes") || |
1176 | !_cups_strcasecmp(value, "on") || | |
1177 | !_cups_strcasecmp(value, "true"))) | |
ef416fc2 | 1178 | p->shared = 1; |
1179 | else if (value && | |
88f9aafc MS |
1180 | (!_cups_strcasecmp(value, "no") || |
1181 | !_cups_strcasecmp(value, "off") || | |
1182 | !_cups_strcasecmp(value, "false"))) | |
ef416fc2 | 1183 | p->shared = 0; |
1184 | else | |
ef416fc2 | 1185 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1186 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1187 | } |
88f9aafc | 1188 | else if (!_cups_strcasecmp(line, "JobSheets")) |
ef416fc2 | 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) | |
1f0275e3 | 1211 | *valueptr = '\0'; |
ef416fc2 | 1212 | |
1213 | cupsdSetString(&p->job_sheets[1], value); | |
1214 | } | |
1215 | } | |
1216 | else | |
ef416fc2 | 1217 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1218 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1219 | } |
88f9aafc | 1220 | else if (!_cups_strcasecmp(line, "AllowUser")) |
ef416fc2 | 1221 | { |
1222 | if (value) | |
1223 | { | |
1224 | p->deny_users = 0; | |
10d09e33 | 1225 | cupsdAddString(&(p->users), value); |
ef416fc2 | 1226 | } |
1227 | else | |
ef416fc2 | 1228 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1229 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1230 | } |
88f9aafc | 1231 | else if (!_cups_strcasecmp(line, "DenyUser")) |
ef416fc2 | 1232 | { |
1233 | if (value) | |
1234 | { | |
1235 | p->deny_users = 1; | |
10d09e33 | 1236 | cupsdAddString(&(p->users), value); |
ef416fc2 | 1237 | } |
1238 | else | |
ef416fc2 | 1239 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1240 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1241 | } |
88f9aafc | 1242 | else if (!_cups_strcasecmp(line, "QuotaPeriod")) |
ef416fc2 | 1243 | { |
1244 | if (value) | |
1245 | p->quota_period = atoi(value); | |
1246 | else | |
ef416fc2 | 1247 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1248 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1249 | } |
88f9aafc | 1250 | else if (!_cups_strcasecmp(line, "PageLimit")) |
ef416fc2 | 1251 | { |
1252 | if (value) | |
1253 | p->page_limit = atoi(value); | |
1254 | else | |
ef416fc2 | 1255 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1256 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1257 | } |
88f9aafc | 1258 | else if (!_cups_strcasecmp(line, "KLimit")) |
ef416fc2 | 1259 | { |
1260 | if (value) | |
1261 | p->k_limit = atoi(value); | |
1262 | else | |
ef416fc2 | 1263 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1264 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1265 | } |
88f9aafc | 1266 | else if (!_cups_strcasecmp(line, "OpPolicy")) |
ef416fc2 | 1267 | { |
1268 | if (value) | |
c0e1af83 | 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 | } | |
ef416fc2 | 1283 | else |
ef416fc2 | 1284 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1285 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1286 | } |
88f9aafc | 1287 | else if (!_cups_strcasecmp(line, "ErrorPolicy")) |
ef416fc2 | 1288 | { |
1289 | if (value) | |
1290 | cupsdSetString(&p->error_policy, value); | |
1291 | else | |
ef416fc2 | 1292 | cupsdLogMessage(CUPSD_LOG_ERROR, |
1293 | "Syntax error on line %d of printers.conf.", linenum); | |
ef416fc2 | 1294 | } |
88f9aafc | 1295 | else if (!_cups_strcasecmp(line, "Attribute") && value) |
20fbc903 MS |
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 | ||
8922323b MS |
1306 | if (!p->attrs) |
1307 | cupsdSetPrinterAttrs(p); | |
1308 | ||
52f6f666 MS |
1309 | if (!strcmp(value, "marker-change-time")) |
1310 | p->marker_time = atoi(valueptr); | |
1311 | else | |
1312 | cupsdSetPrinterAttr(p, value, valueptr); | |
20fbc903 MS |
1313 | } |
1314 | } | |
88f9aafc MS |
1315 | else if (_cups_strcasecmp(line, "Filter") && |
1316 | _cups_strcasecmp(line, "Prefilter") && | |
1317 | _cups_strcasecmp(line, "Product")) | |
ef416fc2 | 1318 | { |
1319 | /* | |
88f9aafc MS |
1320 | * Something else we don't understand (and that wasn't used in a prior |
1321 | * release of CUPS... | |
ef416fc2 | 1322 | */ |
1323 | ||
1324 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
88f9aafc MS |
1325 | "Unknown configuration directive %s on line %d of " |
1326 | "printers.conf.", line, linenum); | |
ef416fc2 | 1327 | } |
1328 | } | |
1329 | ||
1330 | cupsFileClose(fp); | |
1331 | } | |
1332 | ||
1333 | ||
b423cd4c | 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 | ||
1f0275e3 MS |
1347 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
1348 | "cupsdRenamePrinter: Removing %s from Printers", p->name); | |
b423cd4c | 1349 | cupsArrayRemove(Printers, p); |
1350 | ||
b423cd4c | 1351 | /* |
1352 | * Rename the printer type... | |
1353 | */ | |
1354 | ||
1355 | mimeDeleteType(MimeDatabase, p->filetype); | |
1356 | p->filetype = mimeAddType(MimeDatabase, "printer", name); | |
1357 | ||
22c9029b MS |
1358 | if (p->prefiltertype) |
1359 | { | |
1360 | mimeDeleteType(MimeDatabase, p->prefiltertype); | |
1361 | p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", name); | |
1362 | } | |
f7deaa1a | 1363 | |
b423cd4c | 1364 | /* |
1365 | * Rename the printer... | |
1366 | */ | |
1367 | ||
a74454a7 | 1368 | cupsdSetString(&p->name, name); |
b423cd4c | 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 | ||
1f0275e3 MS |
1380 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
1381 | "cupsdRenamePrinter: Adding %s to Printers", p->name); | |
b423cd4c | 1382 | cupsArrayAdd(Printers, p); |
b423cd4c | 1383 | } |
1384 | ||
1385 | ||
ef416fc2 | 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 */ | |
321d8d57 MS |
1396 | char filename[1024], /* printers.conf filename */ |
1397 | temp[1024], /* Temporary string */ | |
58dc1933 | 1398 | value[2048], /* Value string */ |
10d09e33 MS |
1399 | *ptr, /* Pointer into value */ |
1400 | *name; /* Current user/group name */ | |
ef416fc2 | 1401 | cupsd_printer_t *printer; /* Current printer class */ |
1402 | time_t curtime; /* Current time */ | |
1403 | struct tm *curdate; /* Current date */ | |
b423cd4c | 1404 | cups_option_t *option; /* Current option */ |
20fbc903 | 1405 | ipp_attribute_t *marker; /* Current marker attribute */ |
ef416fc2 | 1406 | |
1407 | ||
1408 | /* | |
1409 | * Create the printers.conf file... | |
1410 | */ | |
1411 | ||
321d8d57 | 1412 | snprintf(filename, sizeof(filename), "%s/printers.conf", ServerRoot); |
ef416fc2 | 1413 | |
321d8d57 | 1414 | if ((fp = cupsdCreateConfFile(filename, ConfigFilePerm & 0600)) == NULL) |
ef416fc2 | 1415 | return; |
ef416fc2 | 1416 | |
321d8d57 | 1417 | cupsdLogMessage(CUPSD_LOG_INFO, "Saving printers.conf..."); |
ef416fc2 | 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); | |
b226ab99 | 1429 | cupsFilePuts(fp, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n"); |
ef416fc2 | 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 | /* | |
a2326b5b | 1440 | * Skip printer classes... |
ef416fc2 | 1441 | */ |
1442 | ||
a2326b5b | 1443 | if (printer->type & CUPS_PRINTER_CLASS) |
ef416fc2 | 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 | ||
82f97232 MS |
1455 | cupsFilePrintf(fp, "UUID %s\n", printer->uuid); |
1456 | ||
f7deaa1a | 1457 | if (printer->num_auth_info_required > 0) |
1458 | { | |
58dc1933 | 1459 | switch (printer->num_auth_info_required) |
f7deaa1a | 1460 | { |
58dc1933 MS |
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; | |
f7deaa1a | 1478 | } |
58dc1933 MS |
1479 | |
1480 | cupsFilePutConf(fp, "AuthInfoRequired", value); | |
f7deaa1a | 1481 | } |
ef416fc2 | 1482 | |
58dc1933 MS |
1483 | if (printer->info) |
1484 | cupsFilePutConf(fp, "Info", printer->info); | |
1485 | ||
ef416fc2 | 1486 | if (printer->location) |
58dc1933 | 1487 | cupsFilePutConf(fp, "Location", printer->location); |
ef416fc2 | 1488 | |
58dc1933 MS |
1489 | if (printer->make_model) |
1490 | cupsFilePutConf(fp, "MakeModel", printer->make_model); | |
1491 | ||
1492 | cupsFilePutConf(fp, "DeviceURI", printer->device_uri); | |
ef416fc2 | 1493 | |
1494 | if (printer->port_monitor) | |
58dc1933 | 1495 | cupsFilePutConf(fp, "PortMonitor", printer->port_monitor); |
ef416fc2 | 1496 | |
1497 | if (printer->state == IPP_PRINTER_STOPPED) | |
1498 | { | |
1499 | cupsFilePuts(fp, "State Stopped\n"); | |
58dc1933 MS |
1500 | |
1501 | if (printer->state_message) | |
1502 | cupsFilePutConf(fp, "StateMessage", printer->state_message); | |
ef416fc2 | 1503 | } |
1504 | else | |
1505 | cupsFilePuts(fp, "State Idle\n"); | |
1506 | ||
1507 | cupsFilePrintf(fp, "StateTime %d\n", (int)printer->state_time); | |
1508 | ||
0af14961 | 1509 | for (i = 0; i < printer->num_reasons; i ++) |
5a662dc0 | 1510 | if (strcmp(printer->reasons[i], "connecting-to-device") && |
38e73f87 MS |
1511 | strcmp(printer->reasons[i], "cups-insecure-filter-warning") && |
1512 | strcmp(printer->reasons[i], "cups-missing-filter-warning")) | |
e6013cfa | 1513 | cupsFilePutConf(fp, "Reason", printer->reasons[i]); |
58dc1933 | 1514 | |
61cf44e2 | 1515 | cupsFilePrintf(fp, "Type %d\n", printer->type); |
58dc1933 | 1516 | |
ef416fc2 | 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 | ||
58dc1933 MS |
1527 | snprintf(value, sizeof(value), "%s %s", printer->job_sheets[0], |
1528 | printer->job_sheets[1]); | |
1529 | cupsFilePutConf(fp, "JobSheets", value); | |
ef416fc2 | 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 | ||
10d09e33 MS |
1535 | for (name = (char *)cupsArrayFirst(printer->users); |
1536 | name; | |
1537 | name = (char *)cupsArrayNext(printer->users)) | |
1538 | cupsFilePutConf(fp, printer->deny_users ? "DenyUser" : "AllowUser", name); | |
ef416fc2 | 1539 | |
1540 | if (printer->op_policy) | |
58dc1933 | 1541 | cupsFilePutConf(fp, "OpPolicy", printer->op_policy); |
ef416fc2 | 1542 | if (printer->error_policy) |
58dc1933 | 1543 | cupsFilePutConf(fp, "ErrorPolicy", printer->error_policy); |
ef416fc2 | 1544 | |
b423cd4c | 1545 | for (i = printer->num_options, option = printer->options; |
1546 | i > 0; | |
1547 | i --, option ++) | |
8922323b | 1548 | { |
58dc1933 MS |
1549 | snprintf(value, sizeof(value), "%s %s", option->name, option->value); |
1550 | cupsFilePutConf(fp, "Option", value); | |
8922323b | 1551 | } |
b423cd4c | 1552 | |
20fbc903 MS |
1553 | if ((marker = ippFindAttribute(printer->attrs, "marker-colors", |
1554 | IPP_TAG_NAME)) != NULL) | |
1555 | { | |
58dc1933 | 1556 | snprintf(value, sizeof(value), "%s ", marker->name); |
8922323b | 1557 | |
58dc1933 MS |
1558 | for (i = 0, ptr = value + strlen(value); |
1559 | i < marker->num_values && ptr < (value + sizeof(value) - 1); | |
1560 | i ++) | |
8922323b MS |
1561 | { |
1562 | if (i) | |
58dc1933 | 1563 | *ptr++ = ','; |
8922323b | 1564 | |
58dc1933 MS |
1565 | strlcpy(ptr, marker->values[i].string.text, |
1566 | value + sizeof(value) - ptr); | |
1567 | ptr += strlen(ptr); | |
8922323b MS |
1568 | } |
1569 | ||
58dc1933 MS |
1570 | *ptr = '\0'; |
1571 | cupsFilePutConf(fp, "Attribute", value); | |
20fbc903 MS |
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 | ||
ed6e7faf MS |
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 | ||
75bd9771 MS |
1604 | if ((marker = ippFindAttribute(printer->attrs, "marker-message", |
1605 | IPP_TAG_TEXT)) != NULL) | |
1606 | { | |
58dc1933 MS |
1607 | snprintf(value, sizeof(value), "%s %s", marker->name, |
1608 | marker->values[0].string.text); | |
75bd9771 | 1609 | |
58dc1933 | 1610 | cupsFilePutConf(fp, "Attribute", value); |
75bd9771 MS |
1611 | } |
1612 | ||
20fbc903 MS |
1613 | if ((marker = ippFindAttribute(printer->attrs, "marker-names", |
1614 | IPP_TAG_NAME)) != NULL) | |
1615 | { | |
58dc1933 | 1616 | snprintf(value, sizeof(value), "%s ", marker->name); |
8922323b | 1617 | |
58dc1933 MS |
1618 | for (i = 0, ptr = value + strlen(value); |
1619 | i < marker->num_values && ptr < (value + sizeof(value) - 1); | |
1620 | i ++) | |
8922323b MS |
1621 | { |
1622 | if (i) | |
58dc1933 | 1623 | *ptr++ = ','; |
8922323b | 1624 | |
58dc1933 MS |
1625 | strlcpy(ptr, marker->values[i].string.text, |
1626 | value + sizeof(value) - ptr); | |
1627 | ptr += strlen(ptr); | |
8922323b MS |
1628 | } |
1629 | ||
58dc1933 MS |
1630 | *ptr = '\0'; |
1631 | cupsFilePutConf(fp, "Attribute", value); | |
20fbc903 MS |
1632 | } |
1633 | ||
1634 | if ((marker = ippFindAttribute(printer->attrs, "marker-types", | |
1635 | IPP_TAG_KEYWORD)) != NULL) | |
1636 | { | |
58dc1933 | 1637 | snprintf(value, sizeof(value), "%s ", marker->name); |
8922323b | 1638 | |
58dc1933 MS |
1639 | for (i = 0, ptr = value + strlen(value); |
1640 | i < marker->num_values && ptr < (value + sizeof(value) - 1); | |
1641 | i ++) | |
8922323b MS |
1642 | { |
1643 | if (i) | |
58dc1933 | 1644 | *ptr++ = ','; |
8922323b | 1645 | |
58dc1933 MS |
1646 | strlcpy(ptr, marker->values[i].string.text, |
1647 | value + sizeof(value) - ptr); | |
1648 | ptr += strlen(ptr); | |
8922323b MS |
1649 | } |
1650 | ||
58dc1933 MS |
1651 | *ptr = '\0'; |
1652 | cupsFilePutConf(fp, "Attribute", value); | |
20fbc903 MS |
1653 | } |
1654 | ||
52f6f666 MS |
1655 | if (printer->marker_time) |
1656 | cupsFilePrintf(fp, "Attribute marker-change-time %ld\n", | |
1657 | (long)printer->marker_time); | |
1658 | ||
ef416fc2 | 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 | ||
321d8d57 | 1670 | cupsdCloseCreatedConfFile(fp, filename); |
ef416fc2 | 1671 | } |
1672 | ||
1673 | ||
f7deaa1a | 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 | ||
f899b121 | 1707 | if ((end - values) == 4 && !strncmp(values, "none", 4)) |
f7deaa1a | 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 | } | |
f899b121 | 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 ++; | |
07ed0e9a MS |
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 | } | |
f899b121 | 1734 | } |
1735 | else if ((end - values) == 6 && !strncmp(values, "domain", 6)) | |
f7deaa1a | 1736 | { |
1737 | p->auth_info_required[p->num_auth_info_required] = "domain"; | |
1738 | p->num_auth_info_required ++; | |
1739 | } | |
f899b121 | 1740 | else if ((end - values) == 8 && !strncmp(values, "password", 8)) |
f7deaa1a | 1741 | { |
1742 | p->auth_info_required[p->num_auth_info_required] = "password"; | |
1743 | p->num_auth_info_required ++; | |
1744 | } | |
f899b121 | 1745 | else if ((end - values) == 8 && !strncmp(values, "username", 8)) |
f7deaa1a | 1746 | { |
1747 | p->auth_info_required[p->num_auth_info_required] = "username"; | |
1748 | p->num_auth_info_required ++; | |
1749 | } | |
1750 | else | |
1751 | return (0); | |
09a101d6 | 1752 | |
1753 | values = (*end) ? end + 1 : end; | |
f7deaa1a | 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 | ||
09a101d6 | 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 | ||
f7deaa1a | 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 | } | |
f899b121 | 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 | ||
07ed0e9a MS |
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 | ||
f899b121 | 1812 | return (1); |
1813 | } | |
f7deaa1a | 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 | ||
0af14961 MS |
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 | ||
5a738aea MS |
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 */ | |
12f89d24 MS |
1918 | char *ptr, /* Pointer into value */ |
1919 | *start, /* Start of value */ | |
1920 | quote; /* Quote character */ | |
5a738aea MS |
1921 | ipp_tag_t value_tag; /* Value tag for this attribute */ |
1922 | ||
1923 | ||
e6013cfa MS |
1924 | /* |
1925 | * Don't allow empty values... | |
1926 | */ | |
1927 | ||
1340db2d | 1928 | if (!*value && strcmp(name, "marker-message")) |
e6013cfa MS |
1929 | { |
1930 | cupsdLogMessage(CUPSD_LOG_ERROR, "Ignoring empty \"%s\" attribute", name); | |
1931 | return; | |
1932 | } | |
1933 | ||
5a738aea MS |
1934 | /* |
1935 | * Count the number of values... | |
1936 | */ | |
1937 | ||
12f89d24 MS |
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; | |
3e7fe0ca | 1950 | else if (*ptr == ',') |
12f89d24 MS |
1951 | count ++; |
1952 | } | |
5a738aea MS |
1953 | |
1954 | /* | |
1955 | * Then add or update the attribute as needed... | |
1956 | */ | |
1957 | ||
ed6e7faf MS |
1958 | if (!strcmp(name, "marker-levels") || !strcmp(name, "marker-low-levels") || |
1959 | !strcmp(name, "marker-high-levels")) | |
5a738aea MS |
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; | |
75bd9771 MS |
2005 | else if (!strcmp(name, "marker-message")) |
2006 | value_tag = IPP_TAG_TEXT; | |
5a738aea MS |
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) | |
75bd9771 MS |
2018 | { |
2019 | for (i = 0; i < attr->num_values; i ++) | |
2020 | _cupsStrFree(attr->values[i].string.text); | |
2021 | ||
5a738aea | 2022 | attr->num_values = count; |
75bd9771 | 2023 | } |
5a738aea MS |
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 | ||
12f89d24 | 2036 | for (i = 0, quote = '\0', ptr = value; i < count; i ++) |
5a738aea | 2037 | { |
12f89d24 MS |
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; | |
5a738aea | 2049 | |
12f89d24 MS |
2050 | if (ptr == start) |
2051 | start ++; | |
2052 | else | |
2053 | _cups_strcpy(ptr, ptr + 1); | |
2054 | } | |
3e7fe0ca | 2055 | else if (*ptr == ',') |
12f89d24 MS |
2056 | { |
2057 | *ptr++ = '\0'; | |
2058 | break; | |
2059 | } | |
2060 | } | |
5a738aea | 2061 | |
12f89d24 | 2062 | attr->values[i].string.text = _cupsStrAlloc(start); |
5a738aea MS |
2063 | } |
2064 | } | |
2065 | } | |
2066 | ||
2067 | ||
ef416fc2 | 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 | { | |
a2326b5b | 2075 | int i; /* Looping var */ |
b423cd4c | 2076 | char resource[HTTP_MAX_URI]; /* Resource portion of URI */ |
bc44d920 | 2077 | int num_air; /* Number of auth-info-required values */ |
2078 | const char * const *air; /* auth-info-required values */ | |
b423cd4c | 2079 | cupsd_location_t *auth; /* Pointer to authentication element */ |
2080 | const char *auth_supported; /* Authentication supported */ | |
8922323b | 2081 | ipp_t *oldattrs; /* Old printer attributes */ |
b423cd4c | 2082 | ipp_attribute_t *attr; /* Attribute data */ |
10d09e33 MS |
2083 | char *name, /* Current user/group name */ |
2084 | *filter; /* Current filter */ | |
178cb736 MS |
2085 | static const char * const air_none[] = |
2086 | { /* No authentication */ | |
2087 | "none" | |
2088 | }; | |
bc44d920 | 2089 | static const char * const air_userpass[] = |
2090 | { /* Basic/Digest authentication */ | |
2091 | "username", | |
2092 | "password" | |
2093 | }; | |
ef416fc2 | 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 | ||
e1d6a774 | 2110 | delete_printer_filters(p); |
ef416fc2 | 2111 | |
2112 | /* | |
2113 | * Figure out the authentication that is required for the printer. | |
2114 | */ | |
2115 | ||
2116 | auth_supported = "requesting-user-name"; | |
bc44d920 | 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; | |
bc44d920 | 2124 | } |
a2326b5b | 2125 | else if (p->type & CUPS_PRINTER_AUTHENTICATED) |
ef416fc2 | 2126 | { |
178cb736 MS |
2127 | num_air = 2; |
2128 | air = air_userpass; | |
2129 | } | |
ef416fc2 | 2130 | |
178cb736 MS |
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); | |
ef416fc2 | 2135 | |
178cb736 MS |
2136 | if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL || |
2137 | auth->type == CUPSD_AUTH_NONE) | |
2138 | auth = cupsdFindPolicyOp(p->op_policy_ptr, IPP_PRINT_JOB); | |
9a4f8274 | 2139 | |
178cb736 MS |
2140 | if (auth) |
2141 | { | |
2142 | int auth_type; /* Authentication type */ | |
9a4f8274 | 2143 | |
9a4f8274 | 2144 | |
178cb736 | 2145 | if ((auth_type = auth->type) == CUPSD_AUTH_DEFAULT) |
dcb445bc | 2146 | auth_type = cupsdDefaultAuthType(); |
178cb736 MS |
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"; | |
f899b121 | 2152 | #ifdef HAVE_GSSAPI |
178cb736 MS |
2153 | else if (auth_type == CUPSD_AUTH_NEGOTIATE) |
2154 | auth_supported = "negotiate"; | |
f899b121 | 2155 | #endif /* HAVE_GSSAPI */ |
ef416fc2 | 2156 | |
a2326b5b MS |
2157 | if (auth_type != CUPSD_AUTH_NONE) |
2158 | p->type |= CUPS_PRINTER_AUTHENTICATED; | |
2159 | else | |
2160 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; | |
bc44d920 | 2161 | } |
a2326b5b | 2162 | else |
178cb736 | 2163 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; |
ef416fc2 | 2164 | |
2165 | /* | |
2166 | * Create the required IPP attributes for a printer... | |
2167 | */ | |
2168 | ||
8922323b | 2169 | oldattrs = p->attrs; |
ef416fc2 | 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 : ""); | |
82f97232 MS |
2182 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-uuid", NULL, |
2183 | p->uuid); | |
ef416fc2 | 2184 | |
10d09e33 | 2185 | if (cupsArrayCount(p->users) > 0) |
ef416fc2 | 2186 | { |
2187 | if (p->deny_users) | |
10d09e33 MS |
2188 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, |
2189 | "requesting-user-name-denied", | |
2190 | cupsArrayCount(p->users), NULL, NULL); | |
ef416fc2 | 2191 | else |
10d09e33 MS |
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); | |
ef416fc2 | 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); | |
bc44d920 | 2208 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
2209 | "auth-info-required", num_air, NULL, air); | |
ef416fc2 | 2210 | |
a2326b5b | 2211 | if (cupsArrayCount(Banners) > 0) |
ef416fc2 | 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 | { | |
757d2cad | 2222 | attr->values[0].string.text = _cupsStrAlloc(Classification ? |
ef416fc2 | 2223 | Classification : p->job_sheets[0]); |
757d2cad | 2224 | attr->values[1].string.text = _cupsStrAlloc(Classification ? |
ef416fc2 | 2225 | Classification : p->job_sheets[1]); |
2226 | } | |
2227 | } | |
2228 | ||
d09495fa | 2229 | p->raw = 0; |
2230 | p->remote = 0; | |
ef416fc2 | 2231 | |
a2326b5b MS |
2232 | /* |
2233 | * Assign additional attributes depending on whether this is a printer | |
2234 | * or class... | |
2235 | */ | |
2236 | ||
2237 | if (p->type & CUPS_PRINTER_CLASS) | |
ef416fc2 | 2238 | { |
a2326b5b MS |
2239 | p->raw = 1; |
2240 | p->type &= ~CUPS_PRINTER_OPTIONS; | |
2241 | ||
ef416fc2 | 2242 | /* |
a2326b5b | 2243 | * Add class-specific attributes... |
ef416fc2 | 2244 | */ |
2245 | ||
a2326b5b MS |
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) | |
0268488e MS |
2252 | { |
2253 | /* | |
a2326b5b | 2254 | * Add a list of member names; URIs are added in copy_printer_attrs... |
0268488e MS |
2255 | */ |
2256 | ||
a2326b5b MS |
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; | |
0268488e | 2260 | |
a2326b5b MS |
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); | |
0268488e | 2265 | |
a2326b5b MS |
2266 | p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type; |
2267 | } | |
0268488e | 2268 | } |
ef416fc2 | 2269 | } |
2270 | else | |
2271 | { | |
2272 | /* | |
a2326b5b | 2273 | * Add printer-specific attributes... |
ef416fc2 | 2274 | */ |
2275 | ||
a2326b5b MS |
2276 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, |
2277 | p->sanitized_device_uri); | |
ef416fc2 | 2278 | |
a2326b5b MS |
2279 | /* |
2280 | * Assign additional attributes from the PPD file (if any)... | |
2281 | */ | |
fa73b229 | 2282 | |
a2326b5b | 2283 | load_ppd(p); |
ef416fc2 | 2284 | |
a2326b5b MS |
2285 | /* |
2286 | * Add filters for printer... | |
2287 | */ | |
ef416fc2 | 2288 | |
a2326b5b MS |
2289 | cupsdSetPrinterReasons(p, "-cups-missing-filter-warning," |
2290 | "cups-insecure-filter-warning"); | |
ef416fc2 | 2291 | |
a2326b5b MS |
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); | |
ef416fc2 | 2298 | } |
a2326b5b | 2299 | else if (!(p->type & CUPS_PRINTER_REMOTE)) |
ef416fc2 | 2300 | { |
a2326b5b | 2301 | char interface[1024]; /* Interface script */ |
ef416fc2 | 2302 | |
ef416fc2 | 2303 | |
a2326b5b MS |
2304 | snprintf(interface, sizeof(interface), "%s/interfaces/%s", ServerRoot, |
2305 | p->name); | |
2306 | if (!access(interface, X_OK)) | |
f14324a7 | 2307 | { |
a2326b5b MS |
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); | |
f14324a7 | 2315 | } |
a2326b5b | 2316 | else |
f14324a7 | 2317 | { |
a2326b5b MS |
2318 | /* |
2319 | * Add a filter from application/vnd.cups-raw to printer/name to | |
2320 | * handle "raw" printing by users. | |
2321 | */ | |
f14324a7 | 2322 | |
a2326b5b | 2323 | add_printer_filter(p, p->filetype, "application/vnd.cups-raw 0 -"); |
ef416fc2 | 2324 | |
a2326b5b MS |
2325 | /* |
2326 | * Add a PostScript filter, since this is still possibly PS printer. | |
2327 | */ | |
f14324a7 | 2328 | |
a2326b5b MS |
2329 | add_printer_filter(p, p->filetype, |
2330 | "application/vnd.cups-postscript 0 -"); | |
f14324a7 | 2331 | } |
a2326b5b | 2332 | } |
f14324a7 | 2333 | |
a2326b5b MS |
2334 | if (p->pc && p->pc->prefilters) |
2335 | { | |
2336 | if (!p->prefiltertype) | |
2337 | p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", p->name); | |
ef416fc2 | 2338 | |
a2326b5b MS |
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); | |
ef416fc2 | 2343 | } |
2344 | } | |
2345 | ||
8922323b MS |
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 = | |
426c6a59 | 2364 | _cupsStrRetain(oldattr->values[i].string.text); |
8922323b MS |
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 | ||
94da7e34 MS |
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 | ||
b9faaae1 MS |
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 | ||
8922323b MS |
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 = | |
426c6a59 | 2418 | _cupsStrRetain(oldattr->values[i].string.text); |
8922323b MS |
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 = | |
426c6a59 | 2431 | _cupsStrRetain(oldattr->values[i].string.text); |
8922323b MS |
2432 | } |
2433 | } | |
2434 | ||
2435 | ippDelete(oldattrs); | |
2436 | } | |
2437 | ||
b423cd4c | 2438 | /* |
bc44d920 | 2439 | * Force sharing off for remote queues... |
b423cd4c | 2440 | */ |
2441 | ||
a2326b5b | 2442 | if (p->type & CUPS_PRINTER_REMOTE) |
bc44d920 | 2443 | p->shared = 0; |
b423cd4c | 2444 | |
bd7854cb | 2445 | /* |
2446 | * Populate the document-format-supported attribute... | |
2447 | */ | |
2448 | ||
2449 | add_printer_formats(p); | |
2450 | ||
ef416fc2 | 2451 | DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p->name, |
2452 | p->type)); | |
2453 | ||
b423cd4c | 2454 | /* |
2455 | * Add name-default attributes... | |
2456 | */ | |
2457 | ||
2458 | add_printer_defaults(p); | |
2459 | ||
ef416fc2 | 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 */ | |
f7deaa1a | 2468 | |
2469 | /* | |
2470 | * Let the browse protocols reflect the change | |
2471 | */ | |
2472 | ||
2473 | cupsdRegisterPrinter(p); | |
ef416fc2 | 2474 | } |
2475 | ||
2476 | ||
2477 | /* | |
2478 | * 'cupsdSetPrinterReasons()' - Set/update the reasons strings. | |
2479 | */ | |
2480 | ||
e07d4801 | 2481 | int /* O - 1 if something changed, 0 otherwise */ |
ef416fc2 | 2482 | cupsdSetPrinterReasons( |
c7017ecc MS |
2483 | cupsd_printer_t *p, /* I - Printer */ |
2484 | const char *s) /* I - Reasons strings */ | |
ef416fc2 | 2485 | { |
e07d4801 MS |
2486 | int i, /* Looping var */ |
2487 | changed = 0; /* Did something change? */ | |
ef416fc2 | 2488 | const char *sptr; /* Pointer into reasons */ |
2489 | char reason[255], /* Reason string */ | |
2490 | *rptr; /* Pointer into reason */ | |
2491 | ||
2492 | ||
b9faaae1 MS |
2493 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
2494 | "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p, p->name, s); | |
d1c13e16 | 2495 | |
ef416fc2 | 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 ++) | |
0af14961 | 2513 | _cupsStrFree(p->reasons[i]); |
ef416fc2 | 2514 | |
2515 | p->num_reasons = 0; | |
e07d4801 | 2516 | changed = 1; |
0af14961 | 2517 | |
0268488e | 2518 | dirty_printer(p); |
ef416fc2 | 2519 | } |
2520 | ||
bc44d920 | 2521 | if (!strcmp(s, "none")) |
e07d4801 | 2522 | return (changed); |
bc44d920 | 2523 | |
ef416fc2 | 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 ++) | |
d1c13e16 | 2553 | if (!strcmp(reason, p->reasons[i])) |
ef416fc2 | 2554 | { |
2555 | /* | |
2556 | * Found a match, so remove it... | |
2557 | */ | |
2558 | ||
2559 | p->num_reasons --; | |
e07d4801 | 2560 | changed = 1; |
1f6f3dbc | 2561 | _cupsStrFree(p->reasons[i]); |
ef416fc2 | 2562 | |
2563 | if (i < p->num_reasons) | |
2564 | memmove(p->reasons + i, p->reasons + i + 1, | |
2565 | (p->num_reasons - i) * sizeof(char *)); | |
2566 | ||
c0e1af83 | 2567 | if (!strcmp(reason, "paused") && p->state == IPP_PRINTER_STOPPED) |
2568 | cupsdSetPrinterState(p, IPP_PRINTER_IDLE, 1); | |
0af14961 | 2569 | |
e6013cfa | 2570 | if (strcmp(reason, "connecting-to-device")) |
0268488e | 2571 | dirty_printer(p); |
d1c13e16 | 2572 | break; |
ef416fc2 | 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 ++) | |
d1c13e16 | 2582 | if (!strcmp(reason, p->reasons[i])) |
ef416fc2 | 2583 | break; |
2584 | ||
2585 | if (i >= p->num_reasons) | |
2586 | { | |
bd8b6777 MS |
2587 | if (!strncmp(reason, "cups-ipp-missing-", 17) || |
2588 | !strncmp(reason, "cups-ipp-wrong-", 15)) | |
2589 | log_ipp_conformance(p, reason); | |
2590 | ||
d1c13e16 MS |
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); | |
e07d4801 | 2596 | return (changed); |
d1c13e16 MS |
2597 | } |
2598 | ||
0af14961 | 2599 | p->reasons[i] = _cupsStrAlloc(reason); |
ef416fc2 | 2600 | p->num_reasons ++; |
e07d4801 | 2601 | changed = 1; |
c0e1af83 | 2602 | |
2603 | if (!strcmp(reason, "paused") && p->state != IPP_PRINTER_STOPPED) | |
2604 | cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 1); | |
0af14961 | 2605 | |
e6013cfa | 2606 | if (strcmp(reason, "connecting-to-device")) |
0268488e | 2607 | dirty_printer(p); |
ef416fc2 | 2608 | } |
2609 | } | |
2610 | } | |
e07d4801 MS |
2611 | |
2612 | return (changed); | |
ef416fc2 | 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 | { | |
12f89d24 | 2626 | cupsd_job_t *job; /* Current job */ |
ef416fc2 | 2627 | ipp_pstate_t old_state; /* Old printer state */ |
f8b3a85b MS |
2628 | static const char * const printer_states[] = |
2629 | { /* State strings */ | |
2630 | "idle", | |
2631 | "processing", | |
2632 | "stopped" | |
2633 | }; | |
ef416fc2 | 2634 | |
2635 | ||
ef416fc2 | 2636 | /* |
2637 | * Set the new state... | |
2638 | */ | |
2639 | ||
2640 | old_state = p->state; | |
2641 | p->state = s; | |
2642 | ||
2643 | if (old_state != s) | |
2644 | { | |
0a682745 | 2645 | cupsdAddEvent(s == IPP_PRINTER_STOPPED ? CUPSD_EVENT_PRINTER_STOPPED : |
d9bca400 | 2646 | CUPSD_EVENT_PRINTER_STATE, p, NULL, |
f8b3a85b | 2647 | "%s \"%s\" state changed to %s.", |
e53920b9 | 2648 | (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer", |
0268488e | 2649 | p->name, printer_states[p->state - IPP_PRINTER_IDLE]); |
e53920b9 | 2650 | |
ef416fc2 | 2651 | /* |
2652 | * Let the browse code know this needs to be updated... | |
2653 | */ | |
2654 | ||
a2326b5b | 2655 | p->state_time = time(NULL); |
ef416fc2 | 2656 | |
2657 | #ifdef __sgi | |
2658 | write_irix_state(p); | |
2659 | #endif /* __sgi */ | |
2660 | } | |
2661 | ||
b9faaae1 MS |
2662 | /* |
2663 | * Set/clear the paused reason as needed... | |
2664 | */ | |
2665 | ||
745129be MS |
2666 | if (s == IPP_PRINTER_STOPPED) |
2667 | cupsdSetPrinterReasons(p, "+paused"); | |
2668 | else | |
2669 | cupsdSetPrinterReasons(p, "-paused"); | |
2670 | ||
12f89d24 MS |
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 | ||
b9faaae1 MS |
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 | ||
f7deaa1a | 2689 | /* |
2690 | * Let the browse protocols reflect the change... | |
2691 | */ | |
2692 | ||
7a14d768 MS |
2693 | if (update) |
2694 | cupsdRegisterPrinter(p); | |
f7deaa1a | 2695 | |
ef416fc2 | 2696 | /* |
2697 | * Save the printer configuration if a printer goes from idle or processing | |
2698 | * to stopped (or visa-versa)... | |
2699 | */ | |
2700 | ||
b9faaae1 MS |
2701 | if (update && |
2702 | (old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED)) | |
0268488e | 2703 | dirty_printer(p); |
ef416fc2 | 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 | { | |
ef416fc2 | 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 | ||
f11a948a | 2725 | if (p->job && p->job->state_value == IPP_JOB_PROCESSING) |
b9faaae1 MS |
2726 | cupsdSetJobState(p->job, IPP_JOB_PENDING, CUPSD_JOB_DEFAULT, |
2727 | "Job stopped due to printer being paused."); | |
ef416fc2 | 2728 | } |
2729 | ||
2730 | ||
c9fc04c6 MS |
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 | ||
ef416fc2 | 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 | { | |
ef416fc2 | 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; | |
07725fee | 2870 | |
2871 | /* | |
a2326b5b | 2872 | * Update printer attributes... |
07725fee | 2873 | */ |
2874 | ||
a2326b5b | 2875 | cupsdSetPrinterAttrs(p); |
ef416fc2 | 2876 | } |
2877 | } | |
2878 | ||
2879 | ||
2880 | /* | |
2881 | * 'cupsdValidateDest()' - Validate a printer/class destination. | |
2882 | */ | |
2883 | ||
2884 | const char * /* O - Printer or class name */ | |
2885 | cupsdValidateDest( | |
f7deaa1a | 2886 | const char *uri, /* I - Printer URI */ |
ef416fc2 | 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 */ | |
f7deaa1a | 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, | |
ef416fc2 | 2905 | dtype, printer)); |
2906 | ||
2907 | /* | |
2908 | * Initialize return values... | |
2909 | */ | |
2910 | ||
2911 | if (printer) | |
2912 | *printer = NULL; | |
2913 | ||
f7deaa1a | 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)); | |
ef416fc2 | 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 | ||
f7deaa1a | 2935 | rptr = resource + 9; |
ef416fc2 | 2936 | } |
2937 | else if (!strncmp(resource, "/printers/", 10)) | |
2938 | { | |
2939 | /* | |
2940 | * Printer... | |
2941 | */ | |
2942 | ||
f7deaa1a | 2943 | rptr = resource + 10; |
ef416fc2 | 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 | ||
f7deaa1a | 2958 | p = cupsdFindDest(rptr); |
ef416fc2 | 2959 | |
f7deaa1a | 2960 | if (p == NULL && strchr(rptr, '@') == NULL) |
ef416fc2 | 2961 | return (NULL); |
2962 | else if (p != NULL) | |
2963 | { | |
2964 | if (printer) | |
2965 | *printer = p; | |
2966 | ||
f7deaa1a | 2967 | if (dtype) |
a2326b5b | 2968 | *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE); |
f7deaa1a | 2969 | |
ef416fc2 | 2970 | return (p->name); |
2971 | } | |
2972 | ||
2973 | /* | |
2974 | * Change localhost to the server name... | |
2975 | */ | |
2976 | ||
88f9aafc | 2977 | if (!_cups_strcasecmp(hostname, "localhost")) |
f7deaa1a | 2978 | strlcpy(hostname, ServerName, sizeof(hostname)); |
ef416fc2 | 2979 | |
2980 | strlcpy(localname, hostname, sizeof(localname)); | |
2981 | ||
88f9aafc | 2982 | if (!_cups_strcasecmp(hostname, ServerName)) |
ef416fc2 | 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 | { | |
88f9aafc | 2999 | if (!_cups_strcasecmp(lptr, sptr)) |
ef416fc2 | 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)) | |
88f9aafc MS |
3019 | if (!_cups_strcasecmp(p->hostname, localname) && |
3020 | !_cups_strcasecmp(p->name, rptr)) | |
ef416fc2 | 3021 | { |
3022 | if (printer) | |
3023 | *printer = p; | |
3024 | ||
f7deaa1a | 3025 | if (dtype) |
a2326b5b | 3026 | *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE); |
f7deaa1a | 3027 | |
ef416fc2 | 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 | { | |
0af14961 MS |
3043 | int i; /* Looping var */ |
3044 | cups_file_t *fp; /* Printcap file */ | |
ef416fc2 | 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 | ||
68b10830 MS |
3065 | cupsdLogMessage(CUPSD_LOG_INFO, "Generating printcap %s...", Printcap); |
3066 | ||
ef416fc2 | 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 | ||
0af14961 MS |
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); | |
ef416fc2 | 3084 | |
d1c13e16 MS |
3085 | /* |
3086 | * Write a new printcap with the current list of printers. | |
3087 | */ | |
3088 | ||
3089 | switch (PrintcapFormat) | |
ef416fc2 | 3090 | { |
d1c13e16 MS |
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 | */ | |
ef416fc2 | 3101 | |
d1c13e16 MS |
3102 | if (DefaultPrinter) |
3103 | cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name, | |
3104 | DefaultPrinter->info, ServerName, | |
3105 | DefaultPrinter->name); | |
ef416fc2 | 3106 | |
d1c13e16 MS |
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; | |
0af14961 | 3114 | |
d1c13e16 MS |
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 | */ | |
0af14961 | 3122 | |
d1c13e16 MS |
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"); | |
ef416fc2 | 3129 | |
d1c13e16 MS |
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; | |
ef416fc2 | 3216 | } |
3217 | ||
3218 | /* | |
3219 | * Close the file... | |
3220 | */ | |
3221 | ||
3222 | cupsFileClose(fp); | |
3223 | } | |
3224 | ||
3225 | ||
b423cd4c | 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 | ||
f7deaa1a | 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")); | |
5a9febac MS |
3251 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-account-id-default")); |
3252 | cupsArrayAdd(CommonDefaults, | |
3253 | _cupsStrAlloc("job-accounting-user-id-default")); | |
f7deaa1a | 3254 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-hold-until-default")); |
3255 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-priority-default")); | |
3256 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-sheets-default")); | |
54afec33 | 3257 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("media-col-default")); |
f7deaa1a | 3258 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("number-up-default")); |
3259 | cupsArrayAdd(CommonDefaults, | |
3260 | _cupsStrAlloc("orientation-requested-default")); | |
f7deaa1a | 3261 | } |
3262 | ||
b423cd4c | 3263 | /* |
3264 | * Add all of the default options from the .conf files... | |
3265 | */ | |
3266 | ||
1f0275e3 | 3267 | for (num_options = 0, options = NULL, i = p->num_options, option = p->options; |
b423cd4c | 3268 | i > 0; |
3269 | i --, option ++) | |
3270 | { | |
3271 | if (strcmp(option->name, "ipp-options") && | |
3272 | strcmp(option->name, "job-sheets") && | |
3273 | strcmp(option->name, "lease-duration")) | |
3274 | { | |
3275 | snprintf(name, sizeof(name), "%s-default", option->name); | |
3276 | num_options = cupsAddOption(name, option->value, num_options, &options); | |
f7deaa1a | 3277 | |
3278 | if (!cupsArrayFind(CommonDefaults, name)) | |
3279 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc(name)); | |
b423cd4c | 3280 | } |
3281 | } | |
3282 | ||
3283 | /* | |
3284 | * Convert options to IPP attributes... | |
3285 | */ | |
3286 | ||
3287 | cupsEncodeOptions2(p->attrs, num_options, options, IPP_TAG_PRINTER); | |
3288 | cupsFreeOptions(num_options, options); | |
3289 | ||
3290 | /* | |
3291 | * Add standard -default attributes as needed... | |
3292 | */ | |
3293 | ||
3294 | if (!cupsGetOption("copies", p->num_options, p->options)) | |
3295 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default", | |
3296 | 1); | |
3297 | ||
f7deaa1a | 3298 | if (!cupsGetOption("document-format", p->num_options, p->options)) |
c934a06c | 3299 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE, |
f7deaa1a | 3300 | "document-format-default", NULL, "application/octet-stream"); |
3301 | ||
b423cd4c | 3302 | if (!cupsGetOption("job-hold-until", p->num_options, p->options)) |
3303 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3304 | "job-hold-until-default", NULL, "no-hold"); | |
3305 | ||
3306 | if (!cupsGetOption("job-priority", p->num_options, p->options)) | |
3307 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3308 | "job-priority-default", 50); | |
3309 | ||
3310 | if (!cupsGetOption("number-up", p->num_options, p->options)) | |
3311 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3312 | "number-up-default", 1); | |
3313 | ||
f7deaa1a | 3314 | if (!cupsGetOption("notify-lease-duration", p->num_options, p->options)) |
3315 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3316 | "notify-lease-duration-default", DefaultLeaseDuration); | |
3317 | ||
3318 | if (!cupsGetOption("notify-events", p->num_options, p->options)) | |
3319 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3320 | "notify-events-default", NULL, "job-completed"); | |
ba55dc12 MS |
3321 | |
3322 | if (!cupsGetOption("orientation-requested", p->num_options, p->options)) | |
3323 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NOVALUE, | |
3324 | "orientation-requested-default", NULL, NULL); | |
3325 | ||
3326 | if (!cupsGetOption("print-quality", p->num_options, p->options)) | |
3327 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
3328 | "print-quality-default", IPP_QUALITY_NORMAL); | |
b423cd4c | 3329 | } |
3330 | ||
3331 | ||
bd7854cb | 3332 | /* |
3333 | * 'add_printer_filter()' - Add a MIME filter for a printer. | |
3334 | */ | |
3335 | ||
3336 | static void | |
3337 | add_printer_filter( | |
3338 | cupsd_printer_t *p, /* I - Printer to add to */ | |
f7deaa1a | 3339 | mime_type_t *filtertype, /* I - Filter or prefilter MIME type */ |
bd7854cb | 3340 | const char *filter) /* I - Filter to add */ |
3341 | { | |
3342 | char super[MIME_MAX_SUPER], /* Super-type for filter */ | |
3343 | type[MIME_MAX_TYPE], /* Type for filter */ | |
c8fef167 MS |
3344 | dsuper[MIME_MAX_SUPER], /* Destination super-type for filter */ |
3345 | dtype[MIME_MAX_TYPE], /* Destination type for filter */ | |
3346 | dest[MIME_MAX_SUPER + MIME_MAX_TYPE + 2], | |
3347 | /* Destination super/type */ | |
bd7854cb | 3348 | program[1024]; /* Program/filter name */ |
3349 | int cost; /* Cost of filter */ | |
07ed0e9a | 3350 | size_t maxsize = 0; /* Maximum supported file size */ |
c8fef167 MS |
3351 | mime_type_t *temptype, /* MIME type looping var */ |
3352 | *desttype; /* Destination MIME type */ | |
22c9029b MS |
3353 | mime_filter_t *filterptr; /* MIME filter */ |
3354 | char filename[1024]; /* Full filter filename */ | |
bd7854cb | 3355 | |
3356 | ||
f14324a7 MS |
3357 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
3358 | "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), " | |
3359 | "filter=\"%s\")", p, p->name, filtertype, filtertype->super, | |
3360 | filtertype->type, filter); | |
3361 | ||
bd7854cb | 3362 | /* |
c8fef167 | 3363 | * Parse the filter string; it should be in one of the following formats: |
bd7854cb | 3364 | * |
c8fef167 | 3365 | * source/type cost program |
07ed0e9a | 3366 | * source/type cost maxsize(nnnn) program |
c8fef167 | 3367 | * source/type dest/type cost program |
07ed0e9a | 3368 | * source/type dest/type cost maxsize(nnnn) program |
bd7854cb | 3369 | */ |
3370 | ||
c8fef167 MS |
3371 | if (sscanf(filter, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]", |
3372 | super, type, dsuper, dtype, &cost, program) == 6) | |
bd7854cb | 3373 | { |
f14324a7 MS |
3374 | snprintf(dest, sizeof(dest), "%s/%s/%s", p->name, dsuper, dtype); |
3375 | ||
3376 | if ((desttype = mimeType(MimeDatabase, "printer", dest)) == NULL) | |
3377 | { | |
3378 | desttype = mimeAddType(MimeDatabase, "printer", dest); | |
3379 | if (!p->dest_types) | |
3380 | p->dest_types = cupsArrayNew(NULL, NULL); | |
3381 | ||
3382 | cupsArrayAdd(p->dest_types, desttype); | |
3383 | } | |
3384 | ||
c8fef167 MS |
3385 | } |
3386 | else | |
3387 | { | |
3388 | if (sscanf(filter, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type, &cost, | |
3389 | program) == 4) | |
3390 | { | |
f14324a7 | 3391 | desttype = filtertype; |
c8fef167 MS |
3392 | } |
3393 | else | |
3394 | { | |
3395 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!", | |
3396 | p->name, filter); | |
3397 | return; | |
3398 | } | |
bd7854cb | 3399 | } |
3400 | ||
07ed0e9a MS |
3401 | if (!strncmp(program, "maxsize(", 8)) |
3402 | { | |
3403 | char *ptr; /* Pointer into maxsize(nnnn) program */ | |
3404 | ||
3405 | maxsize = strtoll(program + 8, &ptr, 10); | |
3406 | ||
3407 | if (*ptr != ')') | |
3408 | { | |
3409 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!", | |
3410 | p->name, filter); | |
3411 | return; | |
3412 | } | |
3413 | ||
3414 | ptr ++; | |
3415 | while (_cups_isspace(*ptr)) | |
3416 | ptr ++; | |
3417 | ||
3418 | _cups_strcpy(program, ptr); | |
3419 | } | |
3420 | ||
bd7854cb | 3421 | /* |
22c9029b | 3422 | * Check permissions on the filter and its containing directory... |
bd7854cb | 3423 | */ |
3424 | ||
ecdc0628 | 3425 | if (strcmp(program, "-")) |
bd7854cb | 3426 | { |
ecdc0628 | 3427 | if (program[0] == '/') |
3428 | strlcpy(filename, program, sizeof(filename)); | |
3429 | else | |
3430 | snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program); | |
3431 | ||
88f9aafc MS |
3432 | _cupsFileCheck(filename, _CUPS_FILE_CHECK_PROGRAM, !RunUser, |
3433 | cupsdLogFCMessage, p); | |
bd7854cb | 3434 | } |
3435 | ||
3436 | /* | |
3437 | * Add the filter to the MIME database, supporting wildcards as needed... | |
3438 | */ | |
3439 | ||
3440 | for (temptype = mimeFirstType(MimeDatabase); | |
3441 | temptype; | |
3442 | temptype = mimeNextType(MimeDatabase)) | |
88f9aafc MS |
3443 | if (((super[0] == '*' && _cups_strcasecmp(temptype->super, "printer")) || |
3444 | !_cups_strcasecmp(temptype->super, super)) && | |
3445 | (type[0] == '*' || !_cups_strcasecmp(temptype->type, type))) | |
bd7854cb | 3446 | { |
c8fef167 MS |
3447 | if (desttype != filtertype) |
3448 | { | |
3449 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3450 | "add_printer_filter: %s: adding filter %s/%s %s/%s %d " | |
3451 | "%s", p->name, temptype->super, temptype->type, | |
3452 | desttype->super, desttype->type, | |
3453 | cost, program); | |
22c9029b MS |
3454 | filterptr = mimeAddFilter(MimeDatabase, temptype, desttype, cost, |
3455 | program); | |
c8fef167 MS |
3456 | |
3457 | if (!mimeFilterLookup(MimeDatabase, desttype, filtertype)) | |
3458 | { | |
3459 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3460 | "add_printer_filter: %s: adding filter %s/%s %s/%s " | |
3461 | "0 -", p->name, desttype->super, desttype->type, | |
3462 | filtertype->super, filtertype->type); | |
771bd8cb | 3463 | mimeAddFilter(MimeDatabase, desttype, filtertype, 0, "-"); |
c8fef167 MS |
3464 | } |
3465 | } | |
3466 | else | |
3467 | { | |
3468 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3469 | "add_printer_filter: %s: adding filter %s/%s %s/%s %d " | |
3470 | "%s", p->name, temptype->super, temptype->type, | |
3471 | filtertype->super, filtertype->type, | |
3472 | cost, program); | |
22c9029b MS |
3473 | filterptr = mimeAddFilter(MimeDatabase, temptype, filtertype, cost, |
3474 | program); | |
c8fef167 | 3475 | } |
22c9029b MS |
3476 | |
3477 | if (filterptr) | |
3478 | filterptr->maxsize = maxsize; | |
bd7854cb | 3479 | } |
3480 | } | |
3481 | ||
3482 | ||
3483 | /* | |
3484 | * 'add_printer_formats()' - Add document-format-supported values for a printer. | |
3485 | */ | |
3486 | ||
3487 | static void | |
3488 | add_printer_formats(cupsd_printer_t *p) /* I - Printer */ | |
3489 | { | |
3490 | int i; /* Looping var */ | |
3491 | mime_type_t *type; /* Current MIME type */ | |
3492 | cups_array_t *filters; /* Filters */ | |
80ca4592 | 3493 | ipp_attribute_t *attr; /* document-format-supported attribute */ |
bd7854cb | 3494 | char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2]; |
3495 | /* MIME type name */ | |
3496 | ||
3497 | ||
3498 | /* | |
3499 | * Raw (and remote) queues advertise all of the supported MIME | |
3500 | * types... | |
3501 | */ | |
3502 | ||
80ca4592 | 3503 | cupsArrayDelete(p->filetypes); |
3504 | p->filetypes = NULL; | |
3505 | ||
bd7854cb | 3506 | if (p->raw) |
3507 | { | |
3508 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, | |
3509 | (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY), | |
3510 | "document-format-supported", NumMimeTypes, NULL, MimeTypes); | |
3511 | return; | |
3512 | } | |
3513 | ||
3514 | /* | |
3515 | * Otherwise, loop through the supported MIME types and see if there | |
3516 | * are filters for them... | |
3517 | */ | |
3518 | ||
bd7854cb | 3519 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters", |
3520 | mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase)); | |
3521 | ||
80ca4592 | 3522 | p->filetypes = cupsArrayNew(NULL, NULL); |
bd7854cb | 3523 | |
80ca4592 | 3524 | for (type = mimeFirstType(MimeDatabase); |
bd7854cb | 3525 | type; |
3526 | type = mimeNextType(MimeDatabase)) | |
3527 | { | |
88f9aafc | 3528 | if (!_cups_strcasecmp(type->super, "printer")) |
c8fef167 MS |
3529 | continue; |
3530 | ||
bd7854cb | 3531 | snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type); |
3532 | ||
3533 | if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL) | |
3534 | { | |
3535 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3536 | "add_printer_formats: %s: %s needs %d filters", | |
3537 | p->name, mimetype, cupsArrayCount(filters)); | |
3538 | ||
3539 | cupsArrayDelete(filters); | |
80ca4592 | 3540 | cupsArrayAdd(p->filetypes, type); |
bd7854cb | 3541 | } |
3542 | else | |
3543 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3544 | "add_printer_formats: %s: %s not supported", | |
3545 | p->name, mimetype); | |
3546 | } | |
3547 | ||
bd7854cb | 3548 | /* |
3549 | * Add the file formats that can be filtered... | |
3550 | */ | |
3551 | ||
f301802f | 3552 | if ((type = mimeType(MimeDatabase, "application", "octet-stream")) == NULL || |
3553 | !cupsArrayFind(p->filetypes, type)) | |
3554 | i = 1; | |
3555 | else | |
3556 | i = 0; | |
bd7854cb | 3557 | |
7a0cbd5e MS |
3558 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
3559 | "add_printer_formats: %s: %d supported types", | |
3560 | p->name, cupsArrayCount(p->filetypes) + i); | |
3561 | ||
80ca4592 | 3562 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE, |
3563 | "document-format-supported", | |
7a0cbd5e | 3564 | cupsArrayCount(p->filetypes) + i, NULL, NULL); |
80ca4592 | 3565 | |
f301802f | 3566 | if (i) |
3567 | attr->values[0].string.text = _cupsStrAlloc("application/octet-stream"); | |
bd7854cb | 3568 | |
f301802f | 3569 | for (type = (mime_type_t *)cupsArrayFirst(p->filetypes); |
80ca4592 | 3570 | type; |
3571 | i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes)) | |
3572 | { | |
3573 | snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type); | |
bd7854cb | 3574 | |
80ca4592 | 3575 | attr->values[i].string.text = _cupsStrAlloc(mimetype); |
3576 | } | |
f7deaa1a | 3577 | |
f3c17241 | 3578 | #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) |
f7deaa1a | 3579 | { |
3580 | char pdl[1024]; /* Buffer to build pdl list */ | |
3581 | mime_filter_t *filter; /* MIME filter looping var */ | |
3582 | ||
3583 | ||
f7deaa1a | 3584 | /* |
ba55dc12 MS |
3585 | * We only support raw printing if this is not a Tioga PrintJobMgr based |
3586 | * queue and if application/octet-stream is a known type... | |
f7deaa1a | 3587 | */ |
3588 | ||
3589 | for (filter = (mime_filter_t *)cupsArrayFirst(MimeDatabase->filters); | |
3590 | filter; | |
3591 | filter = (mime_filter_t *)cupsArrayNext(MimeDatabase->filters)) | |
3592 | { | |
5a662dc0 | 3593 | if (filter->dst == p->filetype && filter->filter && |
f7deaa1a | 3594 | strstr(filter->filter, "PrintJobMgr")) |
3595 | break; | |
3596 | } | |
3597 | ||
ba55dc12 | 3598 | pdl[0] = '\0'; |
f7deaa1a | 3599 | |
3600 | if (!filter && mimeType(MimeDatabase, "application", "octet-stream")) | |
3601 | strlcat(pdl, "application/octet-stream,", sizeof(pdl)); | |
3602 | ||
ba55dc12 MS |
3603 | /* |
3604 | * Then list a bunch of formats that are supported by the printer... | |
3605 | */ | |
3606 | ||
3607 | for (type = (mime_type_t *)cupsArrayFirst(p->filetypes); | |
3608 | type; | |
3609 | type = (mime_type_t *)cupsArrayNext(p->filetypes)) | |
3610 | { | |
88f9aafc | 3611 | if (!_cups_strcasecmp(type->super, "application")) |
ba55dc12 | 3612 | { |
88f9aafc | 3613 | if (!_cups_strcasecmp(type->type, "pdf")) |
ba55dc12 | 3614 | strlcat(pdl, "application/pdf,", sizeof(pdl)); |
88f9aafc | 3615 | else if (!_cups_strcasecmp(type->type, "postscript")) |
ba55dc12 MS |
3616 | strlcat(pdl, "application/postscript,", sizeof(pdl)); |
3617 | } | |
88f9aafc | 3618 | else if (!_cups_strcasecmp(type->super, "image")) |
ba55dc12 | 3619 | { |
88f9aafc | 3620 | if (!_cups_strcasecmp(type->type, "jpeg")) |
ba55dc12 | 3621 | strlcat(pdl, "image/jpeg,", sizeof(pdl)); |
88f9aafc | 3622 | else if (!_cups_strcasecmp(type->type, "png")) |
ba55dc12 | 3623 | strlcat(pdl, "image/png,", sizeof(pdl)); |
88f9aafc | 3624 | else if (!_cups_strcasecmp(type->type, "pwg-raster")) |
c8fef167 | 3625 | strlcat(pdl, "image/pwg-raster,", sizeof(pdl)); |
ba55dc12 MS |
3626 | } |
3627 | } | |
f7deaa1a | 3628 | |
3629 | if (pdl[0]) | |
3630 | pdl[strlen(pdl) - 1] = '\0'; /* Remove trailing comma */ | |
3631 | ||
3632 | cupsdSetString(&p->pdl, pdl); | |
3633 | } | |
f3c17241 | 3634 | #endif /* HAVE_DNSSD || HAVE_AVAHI */ |
bd7854cb | 3635 | } |
3636 | ||
3637 | ||
ef416fc2 | 3638 | /* |
3639 | * 'compare_printers()' - Compare two printers. | |
3640 | */ | |
3641 | ||
3642 | static int /* O - Result of comparison */ | |
3643 | compare_printers(void *first, /* I - First printer */ | |
3644 | void *second, /* I - Second printer */ | |
3645 | void *data) /* I - App data (not used) */ | |
3646 | { | |
321d8d57 MS |
3647 | (void)data; |
3648 | ||
88f9aafc | 3649 | return (_cups_strcasecmp(((cupsd_printer_t *)first)->name, |
ef416fc2 | 3650 | ((cupsd_printer_t *)second)->name)); |
3651 | } | |
3652 | ||
3653 | ||
bd7854cb | 3654 | /* |
e1d6a774 | 3655 | * 'delete_printer_filters()' - Delete all MIME filters for a printer. |
bd7854cb | 3656 | */ |
3657 | ||
3658 | static void | |
e1d6a774 | 3659 | delete_printer_filters( |
3660 | cupsd_printer_t *p) /* I - Printer to remove from */ | |
bd7854cb | 3661 | { |
e1d6a774 | 3662 | mime_filter_t *filter; /* MIME filter looping var */ |
c8fef167 | 3663 | mime_type_t *type; /* Destination types for filters */ |
bd7854cb | 3664 | |
bd7854cb | 3665 | |
3666 | /* | |
e1d6a774 | 3667 | * Range check input... |
bd7854cb | 3668 | */ |
3669 | ||
e1d6a774 | 3670 | if (p == NULL) |
3671 | return; | |
bd7854cb | 3672 | |
3673 | /* | |
e1d6a774 | 3674 | * Remove all filters from the MIME database that have a destination |
3675 | * type == printer... | |
bd7854cb | 3676 | */ |
3677 | ||
e1d6a774 | 3678 | for (filter = mimeFirstFilter(MimeDatabase); |
3679 | filter; | |
3680 | filter = mimeNextFilter(MimeDatabase)) | |
c8fef167 MS |
3681 | if (filter->dst == p->filetype || filter->dst == p->prefiltertype || |
3682 | cupsArrayFind(p->dest_types, filter->dst)) | |
e1d6a774 | 3683 | { |
3684 | /* | |
3685 | * Delete the current filter... | |
3686 | */ | |
bd7854cb | 3687 | |
e1d6a774 | 3688 | mimeDeleteFilter(MimeDatabase, filter); |
3689 | } | |
b9faaae1 | 3690 | |
c8fef167 MS |
3691 | for (type = (mime_type_t *)cupsArrayFirst(p->dest_types); |
3692 | type; | |
3693 | type = (mime_type_t *)cupsArrayNext(p->dest_types)) | |
3694 | mimeDeleteType(MimeDatabase, type); | |
3695 | ||
3696 | cupsArrayDelete(p->dest_types); | |
3697 | p->dest_types = NULL; | |
3698 | ||
38e73f87 MS |
3699 | cupsdSetPrinterReasons(p, "-cups-insecure-filter-warning" |
3700 | ",cups-missing-filter-warning"); | |
bd7854cb | 3701 | } |
3702 | ||
3703 | ||
0268488e MS |
3704 | /* |
3705 | * 'dirty_printer()' - Mark config and state files dirty for the specified | |
3706 | * printer. | |
3707 | */ | |
3708 | ||
3709 | static void | |
3710 | dirty_printer(cupsd_printer_t *p) /* I - Printer */ | |
3711 | { | |
a2326b5b | 3712 | if (p->type & CUPS_PRINTER_CLASS) |
0268488e MS |
3713 | cupsdMarkDirty(CUPSD_DIRTY_CLASSES); |
3714 | else | |
3715 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); | |
3716 | ||
3717 | if (PrintcapFormat == PRINTCAP_PLIST) | |
3718 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); | |
3719 | } | |
3720 | ||
3721 | ||
61cf44e2 MS |
3722 | /* |
3723 | * 'load_ppd()' - Load a cached PPD file, updating the cache as needed. | |
3724 | */ | |
3725 | ||
3726 | static void | |
3727 | load_ppd(cupsd_printer_t *p) /* I - Printer */ | |
3728 | { | |
54afec33 | 3729 | int i, j, k; /* Looping vars */ |
f14324a7 MS |
3730 | char cache_name[1024]; /* Cache filename */ |
3731 | struct stat cache_info; /* Cache file info */ | |
61cf44e2 MS |
3732 | ppd_file_t *ppd; /* PPD file */ |
3733 | char ppd_name[1024]; /* PPD filename */ | |
3734 | struct stat ppd_info; /* PPD file info */ | |
3735 | int num_media; /* Number of media options */ | |
54afec33 | 3736 | ppd_size_t *size; /* Current PPD size */ |
5a6b583a MS |
3737 | ppd_option_t *duplex, /* Duplex option */ |
3738 | *output_bin, /* OutputBin option */ | |
ba55dc12 | 3739 | *output_mode, /* OutputMode option */ |
5a6b583a | 3740 | *resolution; /* (Set|JCL|)Resolution option */ |
54afec33 MS |
3741 | ppd_choice_t *choice, /* Current PPD choice */ |
3742 | *input_slot, /* Current input slot */ | |
3743 | *media_type; /* Current media type */ | |
61cf44e2 | 3744 | ppd_attr_t *ppd_attr; /* PPD attribute */ |
5a6b583a MS |
3745 | int xdpi, /* Horizontal resolution */ |
3746 | ydpi; /* Vertical resolution */ | |
3747 | const char *resptr; /* Pointer into resolution keyword */ | |
54afec33 MS |
3748 | _pwg_size_t *pwgsize; /* Current PWG size */ |
3749 | _pwg_map_t *pwgsource, /* Current PWG source */ | |
3750 | *pwgtype; /* Current PWG type */ | |
61cf44e2 | 3751 | ipp_attribute_t *attr; /* Attribute data */ |
a2326b5b | 3752 | _ipp_value_t *val; /* Attribute value */ |
ba55dc12 MS |
3753 | int num_finishings, /* Number of finishings */ |
3754 | finishings[5]; /* finishings-supported values */ | |
3755 | int num_qualities, /* Number of print-quality values */ | |
3756 | qualities[3]; /* print-quality values */ | |
54afec33 MS |
3757 | int num_margins, /* Number of media-*-margin-supported values */ |
3758 | margins[16]; /* media-*-margin-supported values */ | |
5a9febac MS |
3759 | const char *filter, /* Current filter */ |
3760 | *mandatory; /* Current mandatory attribute */ | |
61cf44e2 MS |
3761 | static const char * const sides[3] = /* sides-supported values */ |
3762 | { | |
3763 | "one-sided", | |
3764 | "two-sided-long-edge", | |
3765 | "two-sided-short-edge" | |
3766 | }; | |
3767 | static const char * const standard_commands[] = | |
3768 | { /* Standard CUPS commands */ | |
3769 | "AutoConfigure", | |
3770 | "Clean", | |
c168a833 | 3771 | "PrintSelfTestPage" |
61cf44e2 MS |
3772 | }; |
3773 | ||
3774 | ||
3775 | /* | |
3776 | * Check to see if the cache is up-to-date... | |
3777 | */ | |
3778 | ||
f14324a7 | 3779 | snprintf(cache_name, sizeof(cache_name), "%s/%s.data", CacheDir, p->name); |
61cf44e2 MS |
3780 | if (stat(cache_name, &cache_info)) |
3781 | cache_info.st_mtime = 0; | |
3782 | ||
3783 | snprintf(ppd_name, sizeof(ppd_name), "%s/ppd/%s.ppd", ServerRoot, p->name); | |
3784 | if (stat(ppd_name, &ppd_info)) | |
3785 | ppd_info.st_mtime = 1; | |
3786 | ||
3787 | ippDelete(p->ppd_attrs); | |
22c9029b | 3788 | p->ppd_attrs = NULL; |
61cf44e2 | 3789 | |
f14324a7 MS |
3790 | _ppdCacheDestroy(p->pc); |
3791 | p->pc = NULL; | |
54afec33 | 3792 | |
f14324a7 | 3793 | if (cache_info.st_mtime >= ppd_info.st_mtime) |
61cf44e2 | 3794 | { |
61cf44e2 MS |
3795 | cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", cache_name); |
3796 | ||
f14324a7 MS |
3797 | if ((p->pc = _ppdCacheCreateWithFile(cache_name, &p->ppd_attrs)) != NULL && |
3798 | p->ppd_attrs) | |
61cf44e2 | 3799 | { |
f14324a7 MS |
3800 | /* |
3801 | * Loaded successfully! | |
3802 | */ | |
3803 | ||
61cf44e2 MS |
3804 | return; |
3805 | } | |
61cf44e2 MS |
3806 | } |
3807 | ||
3808 | /* | |
3809 | * Reload PPD attributes from disk... | |
3810 | */ | |
3811 | ||
8b450588 MS |
3812 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); |
3813 | ||
61cf44e2 MS |
3814 | cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", ppd_name); |
3815 | ||
61cf44e2 MS |
3816 | p->type &= ~CUPS_PRINTER_OPTIONS; |
3817 | p->type |= CUPS_PRINTER_BW; | |
3818 | ||
3819 | finishings[0] = IPP_FINISHINGS_NONE; | |
3820 | num_finishings = 1; | |
3821 | ||
22c9029b MS |
3822 | p->ppd_attrs = ippNew(); |
3823 | ||
9c80ffa2 | 3824 | if ((ppd = _ppdOpenFile(ppd_name, _PPD_LOCALIZATION_NONE)) != NULL) |
61cf44e2 MS |
3825 | { |
3826 | /* | |
3827 | * Add make/model and other various attributes... | |
3828 | */ | |
3829 | ||
f14324a7 | 3830 | p->pc = _ppdCacheCreateWithPPD(ppd); |
54afec33 | 3831 | |
5a9febac MS |
3832 | if (!p->pc) |
3833 | cupsdLogMessage(CUPSD_LOG_WARN, "Unable to create cache of \"%s\": %s", | |
3834 | ppd_name, cupsLastErrorString()); | |
3835 | ||
c168a833 MS |
3836 | ppdMarkDefaults(ppd); |
3837 | ||
61cf44e2 MS |
3838 | if (ppd->color_device) |
3839 | p->type |= CUPS_PRINTER_COLOR; | |
3840 | if (ppd->variable_sizes) | |
3841 | p->type |= CUPS_PRINTER_VARIABLE; | |
3842 | if (!ppd->manual_copies) | |
3843 | p->type |= CUPS_PRINTER_COPIES; | |
3844 | if ((ppd_attr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL) | |
88f9aafc | 3845 | if (ppd_attr->value && !_cups_strcasecmp(ppd_attr->value, "true")) |
61cf44e2 MS |
3846 | p->type |= CUPS_PRINTER_FAX; |
3847 | ||
3848 | ippAddBoolean(p->ppd_attrs, IPP_TAG_PRINTER, "color-supported", | |
3849 | ppd->color_device); | |
5a9febac MS |
3850 | |
3851 | if (p->pc && p->pc->account_id) | |
3852 | ippAddBoolean(p->ppd_attrs, IPP_TAG_PRINTER, "job-account-id-supported", | |
3853 | 1); | |
3854 | ||
3855 | if (p->pc && p->pc->accounting_user_id) | |
3856 | ippAddBoolean(p->ppd_attrs, IPP_TAG_PRINTER, | |
3857 | "job-accounting-user-id-supported", 1); | |
3858 | ||
3859 | if (p->pc && p->pc->password) | |
3860 | { | |
3861 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3862 | "job-password-encryption-supported", NULL, "none"); | |
3863 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3864 | "job-password-supported", strlen(p->pc->password)); | |
3865 | } | |
3866 | ||
61cf44e2 | 3867 | if (ppd->throughput) |
ba55dc12 | 3868 | { |
61cf44e2 MS |
3869 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, |
3870 | "pages-per-minute", ppd->throughput); | |
ba55dc12 MS |
3871 | if (ppd->color_device) |
3872 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3873 | "pages-per-minute-color", ppd->throughput); | |
3874 | } | |
e60ec91f MS |
3875 | else |
3876 | { | |
3877 | /* | |
3878 | * When there is no speed information, just say "1 page per minute". | |
3879 | */ | |
3880 | ||
3881 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3882 | "pages-per-minute", 1); | |
3883 | if (ppd->color_device) | |
3884 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3885 | "pages-per-minute-color", 1); | |
3886 | } | |
ba55dc12 MS |
3887 | |
3888 | num_qualities = 0; | |
3889 | ||
3890 | if ((output_mode = ppdFindOption(ppd, "OutputMode")) != NULL) | |
3891 | { | |
3892 | if (ppdFindChoice(output_mode, "draft") || | |
3893 | ppdFindChoice(output_mode, "fast")) | |
3894 | qualities[num_qualities ++] = IPP_QUALITY_DRAFT; | |
f14324a7 MS |
3895 | |
3896 | qualities[num_qualities ++] = IPP_QUALITY_NORMAL; | |
3897 | ||
ba55dc12 MS |
3898 | if (ppdFindChoice(output_mode, "best") || |
3899 | ppdFindChoice(output_mode, "high")) | |
3900 | qualities[num_qualities ++] = IPP_QUALITY_HIGH; | |
3901 | } | |
3902 | else if ((ppd_attr = ppdFindAttr(ppd, "APPrinterPreset", NULL)) != NULL) | |
3903 | { | |
3904 | do | |
3905 | { | |
3906 | if (strstr(ppd_attr->spec, "draft") || | |
3907 | strstr(ppd_attr->spec, "Draft")) | |
3908 | { | |
3909 | qualities[num_qualities ++] = IPP_QUALITY_DRAFT; | |
3910 | break; | |
3911 | } | |
3912 | } | |
3913 | while ((ppd_attr = ppdFindNextAttr(ppd, "APPrinterPreset", | |
3914 | NULL)) != NULL); | |
3915 | ||
3916 | qualities[num_qualities ++] = IPP_QUALITY_NORMAL; | |
3917 | qualities[num_qualities ++] = IPP_QUALITY_HIGH; | |
3918 | } | |
f14324a7 | 3919 | else |
ba55dc12 MS |
3920 | qualities[num_qualities ++] = IPP_QUALITY_NORMAL; |
3921 | ||
3922 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
3923 | "print-quality-supported", num_qualities, qualities); | |
61cf44e2 MS |
3924 | |
3925 | if (ppd->nickname) | |
3926 | { | |
3927 | /* | |
3928 | * The NickName can be localized in the character set specified | |
3929 | * by the LanugageEncoding attribute. However, ppdOpen2() has | |
3930 | * already converted the ppd->nickname member to UTF-8 for us | |
3931 | * (the original attribute value is available separately) | |
3932 | */ | |
3933 | ||
3934 | cupsdSetString(&p->make_model, ppd->nickname); | |
3935 | } | |
3936 | else if (ppd->modelname) | |
3937 | { | |
3938 | /* | |
3939 | * Model name can only contain specific characters... | |
3940 | */ | |
3941 | ||
3942 | cupsdSetString(&p->make_model, ppd->modelname); | |
3943 | } | |
3944 | else | |
3945 | cupsdSetString(&p->make_model, "Bad PPD File"); | |
3946 | ||
3947 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
3948 | "printer-make-and-model", NULL, p->make_model); | |
3949 | ||
3950 | /* | |
3951 | * Add media options from the PPD file... | |
3952 | */ | |
3953 | ||
f14324a7 | 3954 | if (ppd->num_sizes == 0 || !p->pc) |
61cf44e2 | 3955 | { |
b9faaae1 MS |
3956 | if (!ppdFindAttr(ppd, "APScannerOnly", NULL)) |
3957 | cupsdLogMessage(CUPSD_LOG_CRIT, | |
3958 | "The PPD file for printer %s contains no media " | |
3959 | "options and is therefore invalid!", p->name); | |
3960 | ||
54afec33 MS |
3961 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
3962 | "media-default", NULL, "unknown"); | |
b9faaae1 MS |
3963 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
3964 | "media-supported", NULL, "unknown"); | |
61cf44e2 MS |
3965 | } |
3966 | else | |
3967 | { | |
54afec33 MS |
3968 | /* |
3969 | * media-default | |
3970 | */ | |
c168a833 | 3971 | |
54afec33 | 3972 | if ((size = ppdPageSize(ppd, NULL)) != NULL) |
f14324a7 | 3973 | pwgsize = _ppdCacheGetSize(p->pc, size->name); |
54afec33 MS |
3974 | else |
3975 | pwgsize = NULL; | |
3976 | ||
3977 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3978 | "media-default", NULL, | |
3979 | pwgsize ? pwgsize->map.pwg : "unknown"); | |
3980 | ||
3981 | /* | |
3982 | * media-col-default | |
3983 | */ | |
3984 | ||
3985 | if (pwgsize) | |
3986 | { | |
aaf19ab0 MS |
3987 | ipp_t *col; /* Collection value */ |
3988 | ||
54afec33 MS |
3989 | input_slot = ppdFindMarkedChoice(ppd, "InputSlot"); |
3990 | media_type = ppdFindMarkedChoice(ppd, "MediaType"); | |
aaf19ab0 MS |
3991 | col = new_media_col(pwgsize, |
3992 | input_slot ? | |
f14324a7 MS |
3993 | _ppdCacheGetSource(p->pc, |
3994 | input_slot->choice) : | |
aaf19ab0 MS |
3995 | NULL, |
3996 | media_type ? | |
f14324a7 MS |
3997 | _ppdCacheGetType(p->pc, |
3998 | media_type->choice) : | |
cc754834 | 3999 | NULL); |
54afec33 MS |
4000 | |
4001 | ippAddCollection(p->ppd_attrs, IPP_TAG_PRINTER, "media-col-default", | |
aaf19ab0 MS |
4002 | col); |
4003 | ippDelete(col); | |
54afec33 MS |
4004 | } |
4005 | ||
4006 | /* | |
4007 | * media-supported | |
4008 | */ | |
4009 | ||
f14324a7 MS |
4010 | num_media = p->pc->num_sizes; |
4011 | if (p->pc->custom_min_keyword) | |
54afec33 MS |
4012 | num_media += 2; |
4013 | ||
4014 | if ((attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4015 | "media-supported", num_media, NULL, | |
4016 | NULL)) != NULL) | |
61cf44e2 MS |
4017 | { |
4018 | val = attr->values; | |
4019 | ||
f14324a7 | 4020 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes; |
54afec33 MS |
4021 | i > 0; |
4022 | i --, pwgsize ++, val ++) | |
4023 | val->string.text = _cupsStrRetain(pwgsize->map.pwg); | |
4024 | ||
f14324a7 | 4025 | if (p->pc->custom_min_keyword) |
54afec33 | 4026 | { |
f14324a7 | 4027 | val->string.text = _cupsStrRetain(p->pc->custom_min_keyword); |
54afec33 | 4028 | val ++; |
f14324a7 | 4029 | val->string.text = _cupsStrRetain(p->pc->custom_max_keyword); |
54afec33 MS |
4030 | } |
4031 | } | |
4032 | ||
a29fd7dd MS |
4033 | /* |
4034 | * media-size-supported | |
4035 | */ | |
4036 | ||
4037 | num_media = p->pc->num_sizes; | |
4038 | if (p->pc->custom_min_keyword) | |
4039 | num_media ++; | |
4040 | ||
4041 | if ((attr = ippAddCollections(p->ppd_attrs, IPP_TAG_PRINTER, | |
4042 | "media-size-supported", num_media, | |
4043 | NULL)) != NULL) | |
4044 | { | |
4045 | val = attr->values; | |
4046 | ||
4047 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes; | |
4048 | i > 0; | |
4049 | i --, pwgsize ++, val ++) | |
4050 | { | |
4051 | val->collection = ippNew(); | |
4052 | ippAddInteger(val->collection, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4053 | "x-dimension", pwgsize->width); | |
4054 | ippAddInteger(val->collection, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4055 | "y-dimension", pwgsize->length); | |
4056 | } | |
4057 | ||
4058 | if (p->pc->custom_min_keyword) | |
4059 | { | |
4060 | val->collection = ippNew(); | |
4061 | ippAddRange(val->collection, IPP_TAG_PRINTER, "x-dimension", | |
4062 | p->pc->custom_min_width, p->pc->custom_max_width); | |
4063 | ippAddRange(val->collection, IPP_TAG_PRINTER, "y-dimension", | |
4064 | p->pc->custom_min_length, p->pc->custom_max_length); | |
4065 | } | |
4066 | } | |
4067 | ||
54afec33 MS |
4068 | /* |
4069 | * media-source-supported | |
4070 | */ | |
4071 | ||
f14324a7 | 4072 | if (p->pc->num_sources > 0 && |
54afec33 | 4073 | (attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
f14324a7 | 4074 | "media-source-supported", p->pc->num_sources, |
54afec33 MS |
4075 | NULL, NULL)) != NULL) |
4076 | { | |
f14324a7 | 4077 | for (i = p->pc->num_sources, pwgsource = p->pc->sources, |
54afec33 MS |
4078 | val = attr->values; |
4079 | i > 0; | |
4080 | i --, pwgsource ++, val ++) | |
4081 | val->string.text = _cupsStrRetain(pwgsource->pwg); | |
4082 | } | |
4083 | ||
4084 | /* | |
4085 | * media-type-supported | |
4086 | */ | |
4087 | ||
f14324a7 | 4088 | if (p->pc->num_types > 0 && |
54afec33 | 4089 | (attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
f14324a7 | 4090 | "media-type-supported", p->pc->num_types, |
54afec33 MS |
4091 | NULL, NULL)) != NULL) |
4092 | { | |
f14324a7 | 4093 | for (i = p->pc->num_types, pwgtype = p->pc->types, |
54afec33 MS |
4094 | val = attr->values; |
4095 | i > 0; | |
4096 | i --, pwgtype ++, val ++) | |
4097 | val->string.text = _cupsStrRetain(pwgtype->pwg); | |
4098 | } | |
4099 | ||
4100 | /* | |
4101 | * media-*-margin-supported | |
4102 | */ | |
4103 | ||
f14324a7 | 4104 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0; |
54afec33 MS |
4105 | i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0])); |
4106 | i --, pwgsize ++) | |
4107 | { | |
4108 | for (j = 0; j < num_margins; j ++) | |
4109 | if (pwgsize->bottom == margins[j]) | |
4110 | break; | |
4111 | ||
4112 | if (j >= num_margins) | |
4113 | { | |
4114 | margins[num_margins] = pwgsize->bottom; | |
4115 | num_margins ++; | |
4116 | } | |
4117 | } | |
4118 | ||
4119 | if (num_margins > 0) | |
4120 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4121 | "media-bottom-margin-supported", num_margins, margins); | |
4122 | else | |
4123 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4124 | "media-bottom-margin-supported", 0); | |
4125 | ||
f14324a7 | 4126 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0; |
54afec33 MS |
4127 | i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0])); |
4128 | i --, pwgsize ++) | |
4129 | { | |
4130 | for (j = 0; j < num_margins; j ++) | |
4131 | if (pwgsize->left == margins[j]) | |
4132 | break; | |
4133 | ||
4134 | if (j >= num_margins) | |
c168a833 | 4135 | { |
54afec33 MS |
4136 | margins[num_margins] = pwgsize->left; |
4137 | num_margins ++; | |
4138 | } | |
4139 | } | |
4140 | ||
4141 | if (num_margins > 0) | |
4142 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4143 | "media-left-margin-supported", num_margins, margins); | |
4144 | else | |
4145 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4146 | "media-left-margin-supported", 0); | |
4147 | ||
f14324a7 | 4148 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0; |
54afec33 MS |
4149 | i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0])); |
4150 | i --, pwgsize ++) | |
4151 | { | |
4152 | for (j = 0; j < num_margins; j ++) | |
4153 | if (pwgsize->right == margins[j]) | |
4154 | break; | |
4155 | ||
4156 | if (j >= num_margins) | |
4157 | { | |
4158 | margins[num_margins] = pwgsize->right; | |
4159 | num_margins ++; | |
4160 | } | |
4161 | } | |
4162 | ||
4163 | if (num_margins > 0) | |
4164 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4165 | "media-right-margin-supported", num_margins, margins); | |
4166 | else | |
4167 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4168 | "media-right-margin-supported", 0); | |
4169 | ||
f14324a7 | 4170 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0; |
54afec33 MS |
4171 | i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0])); |
4172 | i --, pwgsize ++) | |
4173 | { | |
4174 | for (j = 0; j < num_margins; j ++) | |
4175 | if (pwgsize->top == margins[j]) | |
4176 | break; | |
4177 | ||
4178 | if (j >= num_margins) | |
4179 | { | |
4180 | margins[num_margins] = pwgsize->top; | |
4181 | num_margins ++; | |
4182 | } | |
4183 | } | |
4184 | ||
4185 | if (num_margins > 0) | |
4186 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4187 | "media-top-margin-supported", num_margins, margins); | |
4188 | else | |
4189 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
4190 | "media-top-margin-supported", 0); | |
4191 | ||
4192 | /* | |
4193 | * media-col-database | |
4194 | */ | |
4195 | ||
f14324a7 MS |
4196 | num_media = p->pc->num_sizes; |
4197 | if (p->pc->num_sources) | |
54afec33 | 4198 | { |
f14324a7 MS |
4199 | if (p->pc->num_types > 0) |
4200 | num_media += p->pc->num_sizes * p->pc->num_sources * | |
4201 | p->pc->num_types; | |
54afec33 | 4202 | else |
f14324a7 | 4203 | num_media += p->pc->num_sizes * p->pc->num_sources; |
54afec33 | 4204 | } |
f14324a7 MS |
4205 | else if (p->pc->num_types) |
4206 | num_media += p->pc->num_sizes * p->pc->num_types; | |
54afec33 MS |
4207 | |
4208 | if ((attr = ippAddCollections(p->ppd_attrs, IPP_TAG_PRINTER, | |
4209 | "media-col-database", num_media, | |
4210 | NULL)) != NULL) | |
4211 | { | |
f14324a7 | 4212 | for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, val = attr->values; |
54afec33 MS |
4213 | i > 0; |
4214 | i --, pwgsize ++) | |
4215 | { | |
4216 | /* | |
4217 | * Start by adding the page size without source or type... | |
4218 | */ | |
4219 | ||
4220 | ppdMarkOption(ppd, "PageSize", pwgsize->map.ppd); | |
4221 | ||
4222 | val->collection = new_media_col(pwgsize, NULL, NULL); | |
4223 | val ++; | |
4224 | ||
4225 | /* | |
4226 | * Then add the specific, supported combinations of size, source, and | |
4227 | * type... | |
4228 | */ | |
4229 | ||
f14324a7 | 4230 | if (p->pc->num_sources > 0) |
c168a833 | 4231 | { |
f14324a7 | 4232 | for (j = p->pc->num_sources, pwgsource = p->pc->sources; |
54afec33 MS |
4233 | j > 0; |
4234 | j --, pwgsource ++) | |
c168a833 | 4235 | { |
54afec33 | 4236 | ppdMarkOption(ppd, "InputSlot", pwgsource->ppd); |
61cf44e2 | 4237 | |
f14324a7 | 4238 | if (p->pc->num_types > 0) |
54afec33 | 4239 | { |
f14324a7 | 4240 | for (k = p->pc->num_types, pwgtype = p->pc->types; |
54afec33 MS |
4241 | k > 0; |
4242 | k --, pwgtype ++) | |
4243 | { | |
4244 | if (!ppdMarkOption(ppd, "MediaType", pwgtype->ppd)) | |
4245 | { | |
4246 | val->collection = new_media_col(pwgsize, pwgsource->pwg, | |
4247 | pwgtype->pwg); | |
4248 | val ++; | |
4249 | } | |
4250 | } | |
4251 | } | |
4252 | else if (!ppdConflicts(ppd)) | |
4253 | { | |
4254 | val->collection = new_media_col(pwgsize, pwgsource->pwg, NULL); | |
4255 | val ++; | |
4256 | } | |
4257 | } | |
4258 | } | |
f14324a7 | 4259 | else if (p->pc->num_types > 0) |
54afec33 | 4260 | { |
f14324a7 | 4261 | for (j = p->pc->num_types, pwgtype = p->pc->types; |
54afec33 MS |
4262 | j > 0; |
4263 | j --, pwgtype ++) | |
d2354e63 | 4264 | { |
54afec33 MS |
4265 | if (!ppdMarkOption(ppd, "MediaType", pwgtype->ppd)) |
4266 | { | |
4267 | val->collection = new_media_col(pwgsize, NULL, pwgtype->pwg); | |
4268 | val ++; | |
4269 | } | |
d2354e63 | 4270 | } |
c168a833 MS |
4271 | } |
4272 | } | |
61cf44e2 | 4273 | |
54afec33 MS |
4274 | /* |
4275 | * Update the number of media-col-database values... | |
4276 | */ | |
c168a833 | 4277 | |
54afec33 | 4278 | attr->num_values = val - attr->values; |
61cf44e2 MS |
4279 | } |
4280 | } | |
4281 | ||
4282 | /* | |
4283 | * Output bin... | |
4284 | */ | |
4285 | ||
f14324a7 | 4286 | if (p->pc && p->pc->num_bins > 0) |
61cf44e2 MS |
4287 | { |
4288 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
f14324a7 | 4289 | "output-bin-supported", p->pc->num_bins, |
61cf44e2 MS |
4290 | NULL, NULL); |
4291 | ||
4292 | if (attr != NULL) | |
4293 | { | |
4294 | for (i = 0, val = attr->values; | |
f14324a7 | 4295 | i < p->pc->num_bins; |
61cf44e2 | 4296 | i ++, val ++) |
f14324a7 | 4297 | val->string.text = _cupsStrAlloc(p->pc->bins[i].pwg); |
61cf44e2 | 4298 | } |
c168a833 | 4299 | |
cc754834 MS |
4300 | if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL) |
4301 | { | |
f14324a7 MS |
4302 | for (i = 0; i < p->pc->num_bins; i ++) |
4303 | if (!strcmp(p->pc->bins[i].ppd, output_bin->defchoice)) | |
cc754834 MS |
4304 | break; |
4305 | ||
f14324a7 | 4306 | if (i >= p->pc->num_bins) |
cc754834 MS |
4307 | i = 0; |
4308 | ||
4309 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
f14324a7 | 4310 | "output-bin-default", NULL, p->pc->bins[i].pwg); |
cc754834 MS |
4311 | } |
4312 | else | |
4313 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
f14324a7 | 4314 | "output-bin-default", NULL, p->pc->bins[0].pwg); |
cc754834 | 4315 | } |
4220952d | 4316 | else if (((ppd_attr = ppdFindAttr(ppd, "DefaultOutputOrder", |
cc754834 | 4317 | NULL)) != NULL && |
88f9aafc | 4318 | !_cups_strcasecmp(ppd_attr->value, "Reverse")) || |
7cf5915e | 4319 | (!ppd_attr && ppd->manufacturer && /* "Compatibility heuristic" */ |
88f9aafc MS |
4320 | (!_cups_strcasecmp(ppd->manufacturer, "epson") || |
4321 | !_cups_strcasecmp(ppd->manufacturer, "lexmark")))) | |
cc754834 | 4322 | { |
4220952d MS |
4323 | /* |
4324 | * Report that this printer has a single output bin that leaves pages face | |
4325 | * up. | |
4326 | */ | |
4327 | ||
e07d4801 | 4328 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
cc754834 MS |
4329 | "output-bin-supported", NULL, "face-up"); |
4330 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4331 | "output-bin-default", NULL, "face-up"); | |
4332 | } | |
4333 | else | |
4334 | { | |
4335 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4336 | "output-bin-supported", NULL, "face-down"); | |
4337 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4338 | "output-bin-default", NULL, "face-down"); | |
61cf44e2 MS |
4339 | } |
4340 | ||
7cf5915e | 4341 | /* |
5a9febac | 4342 | * print-color-mode... |
7cf5915e MS |
4343 | */ |
4344 | ||
4345 | if (ppd->color_device) | |
4346 | { | |
5a9febac | 4347 | static const char * const color_modes[] = |
7cf5915e MS |
4348 | { |
4349 | "monochrome", | |
4350 | "color" | |
4351 | }; | |
4352 | ||
4353 | ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
5a9febac | 4354 | "print-color-mode-supported", 2, NULL, color_modes); |
f14324a7 MS |
4355 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
4356 | "print-color-mode-default", NULL, "color"); | |
7cf5915e MS |
4357 | } |
4358 | else | |
4359 | { | |
f14324a7 MS |
4360 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
4361 | "print-color-mode-supported", NULL, "monochrome"); | |
4362 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4363 | "print-color-mode-default", NULL, "monochrome"); | |
7cf5915e MS |
4364 | } |
4365 | ||
5a9febac MS |
4366 | /* |
4367 | * Mandatory job attributes, if any... | |
4368 | */ | |
4369 | ||
4370 | if (p->pc && cupsArrayCount(p->pc->mandatory) > 0) | |
4371 | { | |
4372 | int count = cupsArrayCount(p->pc->mandatory); | |
4373 | /* Number of mandatory attributes */ | |
4374 | ||
4375 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4376 | "printer-mandatory-job-attributes", count, NULL, | |
4377 | NULL); | |
4378 | ||
4379 | for (val = attr->values, | |
4380 | mandatory = (char *)cupsArrayFirst(p->pc->mandatory); | |
4381 | mandatory; | |
4382 | val ++, mandatory = (char *)cupsArrayNext(p->pc->mandatory)) | |
4383 | val->string.text = _cupsStrRetain(mandatory); | |
4384 | } | |
4385 | ||
5a6b583a MS |
4386 | /* |
4387 | * Printer resolutions... | |
4388 | */ | |
4389 | ||
4390 | if ((resolution = ppdFindOption(ppd, "Resolution")) == NULL) | |
4391 | if ((resolution = ppdFindOption(ppd, "JCLResolution")) == NULL) | |
4392 | if ((resolution = ppdFindOption(ppd, "SetResolution")) == NULL) | |
4393 | resolution = ppdFindOption(ppd, "CNRes_PGP"); | |
4394 | ||
4395 | if (resolution) | |
4396 | { | |
4397 | /* | |
4398 | * Report all supported resolutions... | |
4399 | */ | |
4400 | ||
4401 | attr = ippAddResolutions(p->ppd_attrs, IPP_TAG_PRINTER, | |
4402 | "printer-resolution-supported", | |
4403 | resolution->num_choices, IPP_RES_PER_INCH, | |
4404 | NULL, NULL); | |
4405 | ||
4406 | for (i = 0, choice = resolution->choices; | |
4407 | i < resolution->num_choices; | |
4408 | i ++, choice ++) | |
4409 | { | |
aaf19ab0 MS |
4410 | xdpi = ydpi = (int)strtol(choice->choice, (char **)&resptr, 10); |
4411 | if (resptr > choice->choice && xdpi > 0 && *resptr == 'x') | |
4412 | ydpi = (int)strtol(resptr + 1, (char **)&resptr, 10); | |
5a6b583a MS |
4413 | |
4414 | if (xdpi <= 0 || ydpi <= 0) | |
4415 | { | |
4416 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4417 | "Bad resolution \"%s\" for printer %s.", | |
4418 | choice->choice, p->name); | |
7cf5915e | 4419 | xdpi = ydpi = 300; |
5a6b583a MS |
4420 | } |
4421 | ||
4422 | attr->values[i].resolution.xres = xdpi; | |
ba55dc12 | 4423 | attr->values[i].resolution.yres = ydpi; |
5a6b583a MS |
4424 | attr->values[i].resolution.units = IPP_RES_PER_INCH; |
4425 | ||
4426 | if (choice->marked) | |
4427 | ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER, | |
4428 | "printer-resolution-default", IPP_RES_PER_INCH, | |
4429 | xdpi, ydpi); | |
4430 | } | |
4431 | } | |
4432 | else if ((ppd_attr = ppdFindAttr(ppd, "DefaultResolution", NULL)) != NULL && | |
4433 | ppd_attr->value) | |
4434 | { | |
4435 | /* | |
4436 | * Just the DefaultResolution to report... | |
4437 | */ | |
4438 | ||
39ff2fe7 | 4439 | xdpi = ydpi = (int)strtol(ppd_attr->value, (char **)&resptr, 10); |
5a6b583a MS |
4440 | if (resptr > ppd_attr->value && xdpi > 0) |
4441 | { | |
4442 | if (*resptr == 'x') | |
4443 | ydpi = (int)strtol(resptr + 1, (char **)&resptr, 10); | |
4444 | else | |
4445 | ydpi = xdpi; | |
4446 | } | |
4447 | ||
4448 | if (xdpi <= 0 || ydpi <= 0) | |
4449 | { | |
4450 | cupsdLogMessage(CUPSD_LOG_WARN, | |
4451 | "Bad default resolution \"%s\" for printer %s.", | |
4452 | ppd_attr->value, p->name); | |
7cf5915e | 4453 | xdpi = ydpi = 300; |
5a6b583a MS |
4454 | } |
4455 | ||
4456 | ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER, | |
4457 | "printer-resolution-default", IPP_RES_PER_INCH, | |
4458 | xdpi, ydpi); | |
4459 | ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER, | |
4460 | "printer-resolution-supported", IPP_RES_PER_INCH, | |
4461 | xdpi, ydpi); | |
4462 | } | |
4463 | else | |
4464 | { | |
4465 | /* | |
4466 | * No resolutions in PPD - make one up... | |
4467 | */ | |
4468 | ||
4469 | ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER, | |
4470 | "printer-resolution-default", IPP_RES_PER_INCH, | |
7cf5915e | 4471 | 300, 300); |
5a6b583a MS |
4472 | ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER, |
4473 | "printer-resolution-supported", IPP_RES_PER_INCH, | |
7cf5915e | 4474 | 300, 300); |
5a6b583a MS |
4475 | } |
4476 | ||
61cf44e2 MS |
4477 | /* |
4478 | * Duplexing, etc... | |
4479 | */ | |
4480 | ||
7cf5915e MS |
4481 | ppdMarkDefaults(ppd); |
4482 | ||
61cf44e2 MS |
4483 | if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL) |
4484 | if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL) | |
4485 | if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL) | |
4486 | if ((duplex = ppdFindOption(ppd, "KD03Duplex")) == NULL) | |
4487 | duplex = ppdFindOption(ppd, "JCLDuplex"); | |
4488 | ||
4489 | if (duplex && duplex->num_choices > 1 && | |
4490 | !ppdInstallableConflict(ppd, duplex->keyword, "DuplexTumble")) | |
4491 | { | |
4492 | p->type |= CUPS_PRINTER_DUPLEX; | |
4493 | ||
4494 | ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4495 | "sides-supported", 3, NULL, sides); | |
4496 | ||
88f9aafc | 4497 | if (!_cups_strcasecmp(duplex->defchoice, "DuplexTumble")) |
61cf44e2 MS |
4498 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
4499 | "sides-default", NULL, "two-sided-short-edge"); | |
88f9aafc | 4500 | else if (!_cups_strcasecmp(duplex->defchoice, "DuplexNoTumble")) |
61cf44e2 MS |
4501 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
4502 | "sides-default", NULL, "two-sided-long-edge"); | |
4503 | else | |
4504 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4505 | "sides-default", NULL, "one-sided"); | |
4506 | } | |
cc754834 MS |
4507 | else |
4508 | { | |
4509 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4510 | "sides-supported", NULL, "one-sided"); | |
4511 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4512 | "sides-default", NULL, "one-sided"); | |
4513 | } | |
61cf44e2 MS |
4514 | |
4515 | if (ppdFindOption(ppd, "Collate") != NULL) | |
4516 | p->type |= CUPS_PRINTER_COLLATE; | |
4517 | ||
4518 | if (ppdFindOption(ppd, "StapleLocation") != NULL) | |
4519 | { | |
4520 | p->type |= CUPS_PRINTER_STAPLE; | |
4521 | finishings[num_finishings++] = IPP_FINISHINGS_STAPLE; | |
4522 | } | |
4523 | ||
4524 | if (ppdFindOption(ppd, "BindEdge") != NULL) | |
4525 | { | |
4526 | p->type |= CUPS_PRINTER_BIND; | |
4527 | finishings[num_finishings++] = IPP_FINISHINGS_BIND; | |
4528 | } | |
4529 | ||
4530 | for (i = 0; i < ppd->num_sizes; i ++) | |
4531 | if (ppd->sizes[i].length > 1728) | |
4532 | p->type |= CUPS_PRINTER_LARGE; | |
4533 | else if (ppd->sizes[i].length > 1008) | |
4534 | p->type |= CUPS_PRINTER_MEDIUM; | |
4535 | else | |
4536 | p->type |= CUPS_PRINTER_SMALL; | |
4537 | ||
b9faaae1 | 4538 | if ((ppd_attr = ppdFindAttr(ppd, "APICADriver", NULL)) != NULL && |
88f9aafc | 4539 | ppd_attr->value && !_cups_strcasecmp(ppd_attr->value, "true")) |
b9faaae1 MS |
4540 | { |
4541 | if ((ppd_attr = ppdFindAttr(ppd, "APScannerOnly", NULL)) != NULL && | |
88f9aafc | 4542 | ppd_attr->value && !_cups_strcasecmp(ppd_attr->value, "true")) |
b9faaae1 MS |
4543 | p->type |= CUPS_PRINTER_SCANNER; |
4544 | else | |
4545 | p->type |= CUPS_PRINTER_MFP; | |
4546 | } | |
4547 | ||
61cf44e2 | 4548 | /* |
f14324a7 | 4549 | * Scan the filters in the PPD file... |
61cf44e2 MS |
4550 | */ |
4551 | ||
f14324a7 | 4552 | if (p->pc) |
c8fef167 | 4553 | { |
f14324a7 MS |
4554 | for (filter = (const char *)cupsArrayFirst(p->pc->filters); |
4555 | filter; | |
4556 | filter = (const char *)cupsArrayNext(p->pc->filters)) | |
c8fef167 | 4557 | { |
88f9aafc | 4558 | if (!_cups_strncasecmp(filter, "application/vnd.cups-command", 28) && |
f14324a7 MS |
4559 | _cups_isspace(filter[28])) |
4560 | { | |
4561 | p->type |= CUPS_PRINTER_COMMANDS; | |
61cf44e2 | 4562 | break; |
f14324a7 | 4563 | } |
61cf44e2 MS |
4564 | } |
4565 | } | |
4566 | ||
4567 | if (p->type & CUPS_PRINTER_COMMANDS) | |
4568 | { | |
4569 | char *commands, /* Copy of commands */ | |
4570 | *start, /* Start of name */ | |
4571 | *end; /* End of name */ | |
4572 | int count; /* Number of commands */ | |
4573 | ||
f14324a7 | 4574 | if ((ppd_attr = ppdFindAttr(ppd, "cupsCommands", NULL)) != NULL) |
61cf44e2 MS |
4575 | { |
4576 | for (count = 0, start = ppd_attr->value; *start; count ++) | |
4577 | { | |
f14324a7 | 4578 | while (_cups_isspace(*start)) |
61cf44e2 MS |
4579 | start ++; |
4580 | ||
4581 | if (!*start) | |
4582 | break; | |
4583 | ||
4584 | while (*start && !isspace(*start & 255)) | |
4585 | start ++; | |
4586 | } | |
4587 | } | |
4588 | else | |
4589 | count = 0; | |
4590 | ||
4591 | if (count > 0) | |
4592 | { | |
4593 | /* | |
0268488e MS |
4594 | * Make a copy of the commands string and count how many commands there |
4595 | * are... | |
61cf44e2 MS |
4596 | */ |
4597 | ||
4598 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4599 | "printer-commands", count, NULL, NULL); | |
4600 | ||
4601 | commands = strdup(ppd_attr->value); | |
4602 | ||
4603 | for (count = 0, start = commands; *start; count ++) | |
4604 | { | |
4605 | while (isspace(*start & 255)) | |
4606 | start ++; | |
4607 | ||
4608 | if (!*start) | |
4609 | break; | |
4610 | ||
4611 | end = start; | |
4612 | while (*end && !isspace(*end & 255)) | |
4613 | end ++; | |
4614 | ||
4615 | if (*end) | |
4616 | *end++ = '\0'; | |
4617 | ||
4618 | attr->values[count].string.text = _cupsStrAlloc(start); | |
4619 | ||
4620 | start = end; | |
4621 | } | |
4622 | ||
4623 | free(commands); | |
4624 | } | |
4625 | else | |
4626 | { | |
4627 | /* | |
4628 | * Add the standard list of commands... | |
4629 | */ | |
4630 | ||
4631 | ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4632 | "printer-commands", | |
4633 | (int)(sizeof(standard_commands) / | |
4634 | sizeof(standard_commands[0])), NULL, | |
4635 | standard_commands); | |
4636 | } | |
4637 | } | |
4638 | else | |
4639 | { | |
4640 | /* | |
4641 | * No commands supported... | |
4642 | */ | |
4643 | ||
4644 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4645 | "printer-commands", NULL, "none"); | |
4646 | } | |
4647 | ||
4648 | /* | |
4649 | * Show current and available port monitors for this printer... | |
4650 | */ | |
4651 | ||
4652 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor", | |
4653 | NULL, p->port_monitor ? p->port_monitor : "none"); | |
4654 | ||
4655 | for (i = 1, ppd_attr = ppdFindAttr(ppd, "cupsPortMonitor", NULL); | |
4656 | ppd_attr; | |
4657 | i ++, ppd_attr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL)); | |
4658 | ||
4659 | if (ppd->protocols) | |
4660 | { | |
4661 | if (strstr(ppd->protocols, "TBCP")) | |
4662 | i ++; | |
4663 | else if (strstr(ppd->protocols, "BCP")) | |
4664 | i ++; | |
4665 | } | |
4666 | ||
4667 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
4668 | "port-monitor-supported", i, NULL, NULL); | |
4669 | ||
4670 | attr->values[0].string.text = _cupsStrAlloc("none"); | |
4671 | ||
4672 | for (i = 1, ppd_attr = ppdFindAttr(ppd, "cupsPortMonitor", NULL); | |
4673 | ppd_attr; | |
4674 | i ++, ppd_attr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL)) | |
4675 | attr->values[i].string.text = _cupsStrAlloc(ppd_attr->value); | |
4676 | ||
4677 | if (ppd->protocols) | |
4678 | { | |
4679 | if (strstr(ppd->protocols, "TBCP")) | |
4680 | attr->values[i].string.text = _cupsStrAlloc("tbcp"); | |
4681 | else if (strstr(ppd->protocols, "BCP")) | |
4682 | attr->values[i].string.text = _cupsStrAlloc("bcp"); | |
4683 | } | |
4684 | ||
61cf44e2 MS |
4685 | if (ppdFindAttr(ppd, "APRemoteQueueID", NULL)) |
4686 | p->type |= CUPS_PRINTER_REMOTE; | |
4687 | ||
7cf5915e MS |
4688 | #ifdef HAVE_APPLICATIONSERVICES_H |
4689 | /* | |
4690 | * Convert the file referenced in APPrinterIconPath to a 128x128 PNG | |
4691 | * and save it as cacheDir/printername.png | |
4692 | */ | |
4693 | ||
4694 | if ((ppd_attr = ppdFindAttr(ppd, "APPrinterIconPath", NULL)) != NULL && | |
22c9029b MS |
4695 | ppd_attr->value && |
4696 | !_cupsFileCheck(ppd_attr->value, _CUPS_FILE_CHECK_FILE, !RunUser, | |
4697 | cupsdLogFCMessage, p)) | |
7cf5915e MS |
4698 | { |
4699 | CGImageRef imageRef = NULL;/* Current icon image */ | |
4700 | CGImageRef biggestIconRef = NULL; | |
4701 | /* Biggest icon image */ | |
4702 | CGImageRef closestTo128IconRef = NULL; | |
4703 | /* Icon image closest to and >= 128 */ | |
4704 | CGImageSourceRef sourceRef; /* The file's image source */ | |
4705 | char outPath[HTTP_MAX_URI]; | |
4706 | /* The path to the PNG file */ | |
4707 | CFURLRef outUrl; /* The URL made from the outPath */ | |
4708 | CFURLRef icnsFileUrl; /* The URL of the original ICNS icon file */ | |
4709 | CGImageDestinationRef destRef; /* The image destination to write */ | |
4710 | size_t bytesPerRow; /* The bytes per row used for resizing */ | |
4711 | CGContextRef context; /* The CG context used for resizing */ | |
4712 | ||
4713 | snprintf(outPath, sizeof(outPath), "%s/%s.png", CacheDir, p->name); | |
4714 | outUrl = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, | |
4715 | (UInt8 *)outPath, | |
4716 | strlen(outPath), | |
4717 | FALSE); | |
4718 | icnsFileUrl = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, | |
4719 | (UInt8 *)ppd_attr->value, | |
4720 | strlen(ppd_attr->value), | |
4721 | FALSE); | |
4722 | if (outUrl && icnsFileUrl) | |
4723 | { | |
4724 | sourceRef = CGImageSourceCreateWithURL(icnsFileUrl, NULL); | |
4725 | if (sourceRef) | |
4726 | { | |
4727 | for (i = 0; i < CGImageSourceGetCount(sourceRef); i ++) | |
4728 | { | |
4729 | imageRef = CGImageSourceCreateImageAtIndex(sourceRef, i, NULL); | |
c8fef167 MS |
4730 | if (!imageRef) |
4731 | continue; | |
4732 | ||
4733 | if (CGImageGetWidth(imageRef) == CGImageGetHeight(imageRef)) | |
7cf5915e MS |
4734 | { |
4735 | /* | |
4736 | * Loop through remembering the icon closest to 128 but >= 128 | |
4737 | * and then remember the largest icon. | |
4738 | */ | |
4739 | ||
4740 | if (CGImageGetWidth(imageRef) >= 128 && | |
4741 | (!closestTo128IconRef || | |
4742 | CGImageGetWidth(imageRef) < | |
4743 | CGImageGetWidth(closestTo128IconRef))) | |
4744 | { | |
4745 | CGImageRelease(closestTo128IconRef); | |
4746 | CGImageRetain(imageRef); | |
4747 | closestTo128IconRef = imageRef; | |
4748 | } | |
4749 | ||
4750 | if (!biggestIconRef || | |
4751 | CGImageGetWidth(imageRef) > CGImageGetWidth(biggestIconRef)) | |
4752 | { | |
4753 | CGImageRelease(biggestIconRef); | |
4754 | CGImageRetain(imageRef); | |
4755 | biggestIconRef = imageRef; | |
4756 | } | |
c8fef167 | 4757 | } |
7cf5915e | 4758 | |
c8fef167 | 4759 | CGImageRelease(imageRef); |
7cf5915e MS |
4760 | } |
4761 | ||
4762 | if (biggestIconRef) | |
4763 | { | |
4764 | /* | |
4765 | * If biggestIconRef is NULL, we found no icons. Otherwise we first | |
4766 | * want the closest to 128, but if none are larger than 128, we want | |
4767 | * the largest icon available. | |
4768 | */ | |
4769 | ||
4770 | imageRef = closestTo128IconRef ? closestTo128IconRef : | |
4771 | biggestIconRef; | |
4772 | CGImageRetain(imageRef); | |
4773 | CGImageRelease(biggestIconRef); | |
c8fef167 MS |
4774 | if (closestTo128IconRef) |
4775 | CGImageRelease(closestTo128IconRef); | |
7cf5915e MS |
4776 | destRef = CGImageDestinationCreateWithURL(outUrl, kUTTypePNG, 1, |
4777 | NULL); | |
4778 | if (destRef) | |
4779 | { | |
4780 | if (CGImageGetWidth(imageRef) != 128) | |
4781 | { | |
4782 | bytesPerRow = CGImageGetBytesPerRow(imageRef) / | |
4783 | CGImageGetWidth(imageRef) * 128; | |
4784 | context = CGBitmapContextCreate(NULL, 128, 128, | |
4785 | CGImageGetBitsPerComponent(imageRef), | |
4786 | bytesPerRow, | |
4787 | CGImageGetColorSpace(imageRef), | |
4788 | kCGImageAlphaPremultipliedFirst); | |
4789 | if (context) | |
4790 | { | |
4791 | CGContextDrawImage(context, CGRectMake(0, 0, 128, 128), | |
4792 | imageRef); | |
4793 | CGImageRelease(imageRef); | |
4794 | imageRef = CGBitmapContextCreateImage(context); | |
4795 | CGContextRelease(context); | |
4796 | } | |
4797 | } | |
4798 | ||
4799 | CGImageDestinationAddImage(destRef, imageRef, NULL); | |
4800 | CGImageDestinationFinalize(destRef); | |
4801 | CFRelease(destRef); | |
4802 | } | |
4803 | ||
4804 | CGImageRelease(imageRef); | |
c8fef167 | 4805 | } |
7cf5915e MS |
4806 | |
4807 | CFRelease(sourceRef); | |
7cf5915e | 4808 | } |
e60ec91f | 4809 | } |
7cf5915e | 4810 | |
e60ec91f | 4811 | if (outUrl) |
7cf5915e | 4812 | CFRelease(outUrl); |
e60ec91f MS |
4813 | |
4814 | if (icnsFileUrl) | |
4815 | CFRelease(icnsFileUrl); | |
7cf5915e MS |
4816 | } |
4817 | #endif /* HAVE_APPLICATIONSERVICES_H */ | |
4818 | ||
61cf44e2 MS |
4819 | /* |
4820 | * Close the PPD and set the type... | |
4821 | */ | |
4822 | ||
4823 | ppdClose(ppd); | |
4824 | } | |
4825 | else if (!access(ppd_name, 0)) | |
4826 | { | |
4827 | int pline; /* PPD line number */ | |
4828 | ppd_status_t pstatus; /* PPD load status */ | |
4829 | ||
4830 | ||
4831 | pstatus = ppdLastError(&pline); | |
4832 | ||
4833 | cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!", | |
4834 | p->name); | |
4835 | ||
4836 | if (pstatus <= PPD_ALLOC_ERROR) | |
4837 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno)); | |
4838 | else | |
4839 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.", | |
4840 | ppdErrorString(pstatus), pline); | |
4841 | ||
4842 | cupsdLogMessage(CUPSD_LOG_INFO, | |
4843 | "Hint: Run \"cupstestppd %s\" and fix any errors.", | |
4844 | ppd_name); | |
61cf44e2 MS |
4845 | } |
4846 | else | |
4847 | { | |
4848 | /* | |
4849 | * If we have an interface script, add a filter entry for it... | |
4850 | */ | |
4851 | ||
4852 | char interface[1024]; /* Interface script */ | |
4853 | ||
4854 | ||
4855 | snprintf(interface, sizeof(interface), "%s/interfaces/%s", ServerRoot, | |
4856 | p->name); | |
4857 | if (!access(interface, X_OK)) | |
4858 | { | |
4859 | /* | |
4860 | * Yes, we have a System V style interface script; use it! | |
4861 | */ | |
4862 | ||
4863 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
4864 | "printer-make-and-model", NULL, | |
4865 | "Local System V Printer"); | |
61cf44e2 | 4866 | } |
37e7e6e0 MS |
4867 | else if (((!strncmp(p->device_uri, "ipp://", 6) || |
4868 | !strncmp(p->device_uri, "ipps://", 7)) && | |
4869 | (strstr(p->device_uri, "/printers/") != NULL || | |
4870 | strstr(p->device_uri, "/classes/") != NULL)) || | |
4871 | ((strstr(p->device_uri, "._ipp.") != NULL || | |
4872 | strstr(p->device_uri, "._ipps.") != NULL) && | |
4873 | !strcmp(p->device_uri + strlen(p->device_uri) - 5, "/cups"))) | |
61cf44e2 MS |
4874 | { |
4875 | /* | |
4876 | * Tell the client this is really a hard-wired remote printer. | |
4877 | */ | |
4878 | ||
4879 | p->type |= CUPS_PRINTER_REMOTE; | |
4880 | ||
4881 | /* | |
4882 | * Point the printer-uri-supported attribute to the | |
4883 | * remote printer... | |
4884 | */ | |
4885 | ||
0268488e MS |
4886 | if (strchr(p->device_uri, '?')) |
4887 | { | |
4888 | /* | |
4889 | * Strip trailing "?options" from URI... | |
4890 | */ | |
4891 | ||
4892 | char resource[HTTP_MAX_URI], /* New URI */ | |
4893 | *ptr; /* Pointer into URI */ | |
4894 | ||
4895 | strlcpy(resource, p->device_uri, sizeof(resource)); | |
4896 | if ((ptr = strchr(resource, '?')) != NULL) | |
4897 | *ptr = '\0'; | |
4898 | ||
4899 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, | |
4900 | "printer-uri-supported", NULL, resource); | |
4901 | } | |
4902 | else | |
4903 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, | |
4904 | "printer-uri-supported", NULL, p->device_uri); | |
61cf44e2 MS |
4905 | |
4906 | /* | |
4907 | * Then set the make-and-model accordingly... | |
4908 | */ | |
4909 | ||
4910 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
4911 | "printer-make-and-model", NULL, "Remote Printer"); | |
4912 | ||
4913 | /* | |
4914 | * Print all files directly... | |
4915 | */ | |
4916 | ||
4917 | p->raw = 1; | |
4918 | p->remote = 1; | |
4919 | } | |
4920 | else | |
4921 | { | |
4922 | /* | |
4923 | * Otherwise we have neither - treat this as a "dumb" printer | |
4924 | * with no PPD file... | |
4925 | */ | |
4926 | ||
4927 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
4928 | "printer-make-and-model", NULL, "Local Raw Printer"); | |
4929 | ||
4930 | p->raw = 1; | |
4931 | } | |
4932 | } | |
4933 | ||
4934 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
4935 | "finishings-supported", num_finishings, finishings); | |
4936 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
4937 | "finishings-default", IPP_FINISHINGS_NONE); | |
4938 | ||
f14324a7 | 4939 | if (ppd && p->pc) |
61cf44e2 MS |
4940 | { |
4941 | /* | |
4942 | * Save cached PPD attributes to disk... | |
4943 | */ | |
4944 | ||
4945 | cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Saving %s...", cache_name); | |
4946 | ||
f14324a7 | 4947 | _ppdCacheWriteFile(p->pc, cache_name, p->ppd_attrs); |
61cf44e2 | 4948 | } |
54afec33 | 4949 | else |
61cf44e2 MS |
4950 | { |
4951 | /* | |
54afec33 | 4952 | * Remove cache files... |
61cf44e2 MS |
4953 | */ |
4954 | ||
54afec33 MS |
4955 | if (cache_info.st_mtime) |
4956 | unlink(cache_name); | |
61cf44e2 MS |
4957 | } |
4958 | } | |
4959 | ||
4960 | ||
bd8b6777 MS |
4961 | /* |
4962 | * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer. | |
4963 | */ | |
4964 | ||
4965 | static void | |
4966 | log_ipp_conformance( | |
4967 | cupsd_printer_t *p, /* I - Printer */ | |
4968 | const char *reason) /* I - Printer state reason */ | |
4969 | { | |
4970 | const char *message; /* Message to log */ | |
4971 | #ifdef __APPLE__ | |
4972 | aslmsg aslm; /* Apple System Log message */ | |
4973 | #endif /* __APPLE__ */ | |
4974 | ||
4975 | ||
4976 | /* | |
4977 | * Strip the leading "cups-ipp-" from the reason and create a log message for | |
4978 | * it... | |
4979 | */ | |
4980 | ||
4981 | reason += 9; | |
4982 | if (!strcmp(reason, "missing-cancel-job")) | |
4983 | message = "Printer does not support REQUIRED Cancel-Job operation."; | |
4984 | else if (!strcmp(reason, "missing-get-job-attributes")) | |
4985 | message = "Printer does not support REQUIRED Get-Job-Attributes operation."; | |
4986 | else if (!strcmp(reason, "missing-print-job")) | |
4987 | message = "Printer does not support REQUIRED Print-Job operation."; | |
4988 | else if (!strcmp(reason, "missing-validate-job")) | |
4989 | message = "Printer does not support REQUIRED Validate-Job operation."; | |
4990 | else if (!strcmp(reason, "missing-get-printer-attributes")) | |
4991 | message = "Printer does not support REQUIRED Get-Printer-Attributes operation."; | |
a29fd7dd MS |
4992 | else if (!strcmp(reason, "missing-send-document")) |
4993 | message = "Printer supports Create-Job but not Send-Document operation."; | |
bd8b6777 MS |
4994 | else if (!strcmp(reason, "missing-job-history")) |
4995 | message = "Printer does not provide REQUIRED job history."; | |
4996 | else if (!strcmp(reason, "missing-job-id")) | |
4997 | message = "Printer does not provide REQUIRED job-id attribute."; | |
4998 | else if (!strcmp(reason, "missing-job-state")) | |
4999 | message = "Printer does not provide REQUIRED job-state attribute."; | |
5000 | else if (!strcmp(reason, "missing-operations-supported")) | |
5001 | message = "Printer does not provide REQUIRED operations-supported " | |
5002 | "attribute."; | |
5003 | else if (!strcmp(reason, "missing-printer-is-accepting-jobs")) | |
5004 | message = "Printer does not provide REQUIRED printer-is-accepting-jobs " | |
5005 | "attribute."; | |
5006 | else if (!strcmp(reason, "missing-printer-state-reasons")) | |
5007 | message = "Printer does not provide REQUIRED printer-state-reasons " | |
5008 | "attribute."; | |
5009 | else if (!strcmp(reason, "wrong-http-version")) | |
5010 | message = "Printer does not use REQUIRED HTTP/1.1 transport."; | |
5011 | else | |
5012 | message = "Unknown IPP conformance failure."; | |
5013 | ||
5014 | cupsdLogMessage(CUPSD_LOG_WARN, "%s: %s", p->name, message); | |
5015 | ||
5016 | #ifdef __APPLE__ | |
5017 | /* | |
5018 | * Report the failure information to Apple if the user opts into providing | |
5019 | * feedback to Apple... | |
5020 | */ | |
5021 | ||
5022 | aslm = asl_new(ASL_TYPE_MSG); | |
5023 | if (aslm) | |
5024 | { | |
5025 | asl_set(aslm, "com.apple.message.domain", "com.apple.printing.ipp.conformance"); | |
5026 | asl_set(aslm, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance"); | |
5027 | asl_set(aslm, "com.apple.message.signature", reason); | |
5028 | asl_set(aslm, "com.apple.message.signature2", | |
5029 | p->make_model ? p->make_model : "Unknown"); | |
5030 | asl_log(NULL, aslm, ASL_LEVEL_NOTICE, "%s: %s", | |
5031 | p->make_model ? p->make_model : "Unknown", message); | |
5032 | asl_free(aslm); | |
5033 | } | |
5034 | #endif /* __APPLE__ */ | |
5035 | } | |
5036 | ||
5037 | ||
54afec33 MS |
5038 | /* |
5039 | * 'new_media_col()' - Create a media-col collection value. | |
5040 | */ | |
5041 | ||
5042 | static ipp_t * /* O - Collection value */ | |
5043 | new_media_col(_pwg_size_t *size, /* I - media-size/margin values */ | |
5044 | const char *source, /* I - media-source value */ | |
5045 | const char *type) /* I - media-type value */ | |
5046 | { | |
5047 | ipp_t *media_col, /* Collection value */ | |
5048 | *media_size; /* media-size value */ | |
5049 | ||
5050 | ||
5051 | media_col = ippNew(); | |
5052 | ||
5053 | media_size = ippNew(); | |
5054 | ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
5055 | "x-dimension", size->width); | |
5056 | ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
5057 | "y-dimension", size->length); | |
54afec33 | 5058 | ippAddCollection(media_col, IPP_TAG_PRINTER, "media-size", media_size); |
aaf19ab0 MS |
5059 | ippDelete(media_size); |
5060 | ||
54afec33 MS |
5061 | ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, |
5062 | "media-bottom-margin", size->bottom); | |
5063 | ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
5064 | "media-left-margin", size->left); | |
5065 | ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
5066 | "media-right-margin", size->right); | |
5067 | ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
5068 | "media-top-margin", size->top); | |
5069 | ||
5070 | if (source) | |
5071 | ippAddString(media_col, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-source", | |
5072 | NULL, source); | |
5073 | ||
5074 | if (type) | |
5075 | ippAddString(media_col, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-type", | |
5076 | NULL, type); | |
5077 | ||
5078 | return (media_col); | |
5079 | } | |
5080 | ||
5081 | ||
ef416fc2 | 5082 | #ifdef __sgi |
5083 | /* | |
5084 | * 'write_irix_config()' - Update the config files used by the IRIX | |
5085 | * desktop tools. | |
5086 | */ | |
5087 | ||
5088 | static void | |
5089 | write_irix_config(cupsd_printer_t *p) /* I - Printer to update */ | |
5090 | { | |
5091 | char filename[1024]; /* Interface script filename */ | |
5092 | cups_file_t *fp; /* Interface script file */ | |
f301802f | 5093 | ipp_attribute_t *attr; /* Attribute data */ |
ef416fc2 | 5094 | |
5095 | ||
5096 | /* | |
5097 | * Add dummy interface and GUI scripts to fool SGI's "challenged" printing | |
5098 | * tools. First the interface script that tells the tools what kind of | |
5099 | * printer we have... | |
5100 | */ | |
5101 | ||
5102 | snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name); | |
5103 | ||
5104 | if (p->type & CUPS_PRINTER_CLASS) | |
5105 | unlink(filename); | |
5106 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5107 | { | |
5108 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
5109 | ||
5110 | if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model", | |
5111 | IPP_TAG_TEXT)) != NULL) | |
5112 | cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text); | |
5113 | else if (p->type & CUPS_PRINTER_CLASS) | |
5114 | cupsFilePuts(fp, "NAME=\"Printer Class\"\n"); | |
5115 | else | |
5116 | cupsFilePuts(fp, "NAME=\"Remote Destination\"\n"); | |
5117 | ||
5118 | if (p->type & CUPS_PRINTER_COLOR) | |
5119 | cupsFilePuts(fp, "TYPE=ColorPostScript\n"); | |
5120 | else | |
5121 | cupsFilePuts(fp, "TYPE=MonoPostScript\n"); | |
5122 | ||
5123 | cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName); | |
5124 | cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name); | |
5125 | ||
5126 | cupsFileClose(fp); | |
5127 | ||
5128 | chmod(filename, 0755); | |
5129 | chown(filename, User, Group); | |
5130 | } | |
5131 | ||
5132 | /* | |
5133 | * Then the member file that tells which device file the queue is connected | |
5134 | * to... Networked printers use "/dev/null" in this file, so that's what | |
5135 | * we use (the actual device URI can confuse some apps...) | |
5136 | */ | |
5137 | ||
5138 | snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name); | |
5139 | ||
5140 | if (p->type & CUPS_PRINTER_CLASS) | |
5141 | unlink(filename); | |
5142 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5143 | { | |
5144 | cupsFilePuts(fp, "/dev/null\n"); | |
5145 | ||
5146 | cupsFileClose(fp); | |
5147 | ||
5148 | chmod(filename, 0644); | |
5149 | chown(filename, User, Group); | |
5150 | } | |
5151 | ||
5152 | /* | |
5153 | * The gui_interface file is a script or program that launches a GUI | |
5154 | * option panel for the printer, using options specified on the | |
5155 | * command-line in the third argument. The option panel must send | |
5156 | * any printing options to stdout on a single line when the user | |
5157 | * accepts them, or nothing if the user cancels the dialog. | |
5158 | * | |
5159 | * The default options panel program is /usr/bin/glpoptions, from | |
5160 | * the ESP Print Pro software. You can select another using the | |
5161 | * PrintcapGUI option. | |
5162 | */ | |
5163 | ||
5164 | snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", p->name); | |
5165 | ||
5166 | if (p->type & CUPS_PRINTER_CLASS) | |
5167 | unlink(filename); | |
5168 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5169 | { | |
5170 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
5171 | cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name); | |
5172 | ||
5173 | cupsFileClose(fp); | |
5174 | ||
5175 | chmod(filename, 0755); | |
5176 | chown(filename, User, Group); | |
5177 | } | |
5178 | ||
5179 | /* | |
5180 | * The POD config file is needed by the printstatus command to show | |
5181 | * the printer location and device. | |
5182 | */ | |
5183 | ||
5184 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name); | |
5185 | ||
5186 | if (p->type & CUPS_PRINTER_CLASS) | |
5187 | unlink(filename); | |
5188 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5189 | { | |
5190 | cupsFilePrintf(fp, "Printer Class | %s\n", | |
5191 | (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript"); | |
5192 | cupsFilePrintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : ""); | |
5193 | cupsFilePrintf(fp, "Location Code | %s\n", p->location ? p->location : ""); | |
5194 | cupsFilePrintf(fp, "Physical Location | %s\n", p->info ? p->info : ""); | |
0af14961 | 5195 | cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri); |
ef416fc2 | 5196 | cupsFilePrintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name); |
5197 | cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name); | |
5198 | cupsFilePuts(fp, "Status Update Wait | 10 seconds\n"); | |
5199 | ||
5200 | cupsFileClose(fp); | |
5201 | ||
5202 | chmod(filename, 0664); | |
5203 | chown(filename, User, Group); | |
5204 | } | |
5205 | } | |
5206 | ||
5207 | ||
5208 | /* | |
5209 | * 'write_irix_state()' - Update the status files used by IRIX printing | |
5210 | * desktop tools. | |
5211 | */ | |
5212 | ||
5213 | static void | |
5214 | write_irix_state(cupsd_printer_t *p) /* I - Printer to update */ | |
5215 | { | |
5216 | char filename[1024]; /* Interface script filename */ | |
5217 | cups_file_t *fp; /* Interface script file */ | |
5218 | int tag; /* Status tag value */ | |
5219 | ||
5220 | ||
5221 | if (p) | |
5222 | { | |
5223 | /* | |
5224 | * The POD status file is needed for the printstatus window to | |
5225 | * provide the current status of the printer. | |
5226 | */ | |
5227 | ||
5228 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name); | |
5229 | ||
5230 | if (p->type & CUPS_PRINTER_CLASS) | |
5231 | unlink(filename); | |
5232 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5233 | { | |
5234 | cupsFilePrintf(fp, "Operational Status | %s\n", | |
5235 | (p->state == IPP_PRINTER_IDLE) ? "Idle" : | |
5236 | (p->state == IPP_PRINTER_PROCESSING) ? "Busy" : | |
5237 | "Faulted"); | |
5238 | cupsFilePrintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION); | |
5239 | cupsFilePrintf(fp, "Information | 02 00 00 | Device URI: %s\n", | |
0af14961 | 5240 | p->device_uri); |
ef416fc2 | 5241 | cupsFilePrintf(fp, "Information | 03 00 00 | %s jobs\n", |
5242 | p->accepting ? "Accepting" : "Not accepting"); | |
5243 | cupsFilePrintf(fp, "Information | 04 00 00 | %s\n", p->state_message); | |
5244 | ||
5245 | cupsFileClose(fp); | |
5246 | ||
5247 | chmod(filename, 0664); | |
5248 | chown(filename, User, Group); | |
5249 | } | |
5250 | ||
5251 | /* | |
5252 | * The activeicons file is needed to provide desktop icons for printers: | |
5253 | * | |
5254 | * [ quoted from /usr/lib/print/tagit ] | |
5255 | * | |
5256 | * --- Type of printer tags (base values) | |
5257 | * | |
5258 | * Dumb=66048 # 0x10200 | |
5259 | * DumbColor=66080 # 0x10220 | |
5260 | * Raster=66112 # 0x10240 | |
5261 | * ColorRaster=66144 # 0x10260 | |
5262 | * Plotter=66176 # 0x10280 | |
5263 | * PostScript=66208 # 0x102A0 | |
5264 | * ColorPostScript=66240 # 0x102C0 | |
5265 | * MonoPostScript=66272 # 0x102E0 | |
5266 | * | |
5267 | * --- Printer state modifiers for local printers | |
5268 | * | |
5269 | * Idle=0 # 0x0 | |
5270 | * Busy=1 # 0x1 | |
5271 | * Faulted=2 # 0x2 | |
5272 | * Unknown=3 # 0x3 (Faulted due to unknown reason) | |
5273 | * | |
5274 | * --- Printer state modifiers for network printers | |
5275 | * | |
5276 | * NetIdle=8 # 0x8 | |
5277 | * NetBusy=9 # 0x9 | |
5278 | * NetFaulted=10 # 0xA | |
5279 | * NetUnknown=11 # 0xB (Faulted due to unknown reason) | |
5280 | */ | |
5281 | ||
5282 | snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name); | |
5283 | ||
5284 | if (p->type & CUPS_PRINTER_CLASS) | |
5285 | unlink(filename); | |
5286 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5287 | { | |
5288 | if (p->type & CUPS_PRINTER_COLOR) | |
5289 | tag = 66240; | |
5290 | else | |
5291 | tag = 66272; | |
5292 | ||
5293 | if (p->type & CUPS_PRINTER_REMOTE) | |
5294 | tag |= 8; | |
5295 | ||
5296 | if (p->state == IPP_PRINTER_PROCESSING) | |
5297 | tag |= 1; | |
5298 | ||
5299 | else if (p->state == IPP_PRINTER_STOPPED) | |
5300 | tag |= 2; | |
5301 | ||
5302 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
5303 | cupsFilePrintf(fp, "#Tag %d\n", tag); | |
5304 | ||
5305 | cupsFileClose(fp); | |
5306 | ||
5307 | chmod(filename, 0755); | |
5308 | chown(filename, User, Group); | |
5309 | } | |
5310 | } | |
5311 | ||
5312 | /* | |
5313 | * The default file is needed by the printers window to show | |
5314 | * the default printer. | |
5315 | */ | |
5316 | ||
5317 | snprintf(filename, sizeof(filename), "/var/spool/lp/default"); | |
5318 | ||
5319 | if (DefaultPrinter != NULL) | |
5320 | { | |
5321 | if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
5322 | { | |
5323 | cupsFilePrintf(fp, "%s\n", DefaultPrinter->name); | |
5324 | ||
5325 | cupsFileClose(fp); | |
5326 | ||
5327 | chmod(filename, 0644); | |
5328 | chown(filename, User, Group); | |
5329 | } | |
5330 | } | |
5331 | else | |
5332 | unlink(filename); | |
5333 | } | |
5334 | #endif /* __sgi */ | |
5335 | ||
5336 | ||
5337 | /* | |
0af14961 MS |
5338 | * 'write_xml_string()' - Write a string with XML escaping. |
5339 | */ | |
5340 | ||
5341 | static void | |
5342 | write_xml_string(cups_file_t *fp, /* I - File to write to */ | |
5343 | const char *s) /* I - String to write */ | |
5344 | { | |
5345 | const char *start; /* Start of current sequence */ | |
5346 | ||
5347 | ||
5348 | if (!s) | |
5349 | return; | |
5350 | ||
5351 | for (start = s; *s; s ++) | |
5352 | { | |
5353 | if (*s == '&') | |
5354 | { | |
5355 | if (s > start) | |
5356 | cupsFileWrite(fp, start, s - start); | |
5357 | ||
5358 | cupsFilePuts(fp, "&"); | |
5359 | start = s + 1; | |
5360 | } | |
5361 | else if (*s == '<') | |
5362 | { | |
5363 | if (s > start) | |
5364 | cupsFileWrite(fp, start, s - start); | |
5365 | ||
5366 | cupsFilePuts(fp, "<"); | |
5367 | start = s + 1; | |
5368 | } | |
5369 | } | |
5370 | ||
5371 | if (s > start) | |
5372 | cupsFilePuts(fp, start); | |
5373 | } | |
5374 | ||
5375 | ||
5376 | /* | |
5377 | * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $". | |
ef416fc2 | 5378 | */ |