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