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