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