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