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