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