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