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