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