]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
a74454a7 | 2 | * "$Id: printers.c 5491 2006-05-04 20:53:35Z mike $" |
ef416fc2 | 3 | * |
4 | * Printer routines for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 1997-2006 by Easy Software Products, all rights reserved. | |
7 | * | |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Easy Software Products and are protected by Federal | |
10 | * copyright law. Distribution and use rights are outlined in the file | |
11 | * "LICENSE.txt" which should have been included with this file. If this | |
12 | * file is missing or damaged please contact Easy Software Products | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
18 | * Hollywood, Maryland 20636 USA | |
19 | * | |
20 | * Voice: (301) 373-9600 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * Contents: | |
25 | * | |
26 | * cupsdAddPrinter() - Add a printer to the system. | |
ef416fc2 | 27 | * cupsdAddPrinterHistory() - Add the current printer state to the history. |
28 | * cupsdAddPrinterUser() - Add a user to the ACL. | |
29 | * cupsdDeleteAllPrinters() - Delete all printers from the system. | |
30 | * cupsdDeletePrinter() - Delete a printer from the system. | |
ef416fc2 | 31 | * cupsdFindPrinter() - Find a printer in the list. |
32 | * cupsdFreePrinterUsers() - Free allow/deny users. | |
33 | * cupsdLoadAllPrinters() - Load printers from the printers.conf file. | |
b423cd4c | 34 | * cupsdRenamePrinter() - Rename a printer. |
fa73b229 | 35 | * cupsdSaveAllPrinters() - Save all printer definitions to the |
36 | * printers.conf file. | |
37 | * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD | |
38 | * file. | |
ef416fc2 | 39 | * cupsdSetPrinterReasons() - Set/update the reasons strings. |
40 | * cupsdSetPrinterState() - Update the current state of a printer. | |
41 | * cupsdStopPrinter() - Stop a printer from printing any jobs... | |
42 | * cupsdUpdatePrinters() - Update printers after a partial reload. | |
43 | * cupsdValidateDest() - Validate a printer/class destination. | |
44 | * cupsdWritePrintcap() - Write a pseudo-printcap file for older | |
45 | * applications that need it... | |
46 | * cupsdSanitizeURI() - Sanitize a device URI... | |
b423cd4c | 47 | * add_printer_defaults() - Add name-default attributes to the printer |
48 | * attributes. | |
bd7854cb | 49 | * add_printer_filter() - Add a MIME filter for a printer. |
50 | * add_printer_formats() - Add document-format-supported values for | |
51 | * a printer. | |
ef416fc2 | 52 | * compare_printers() - Compare two printers. |
e1d6a774 | 53 | * delete_printer_filters() - Delete all MIME filters for a printer. |
ef416fc2 | 54 | * write_irix_config() - Update the config files used by the IRIX |
55 | * desktop tools. | |
fa73b229 | 56 | * write_irix_state() - Update the status files used by IRIX |
57 | * printing desktop tools. | |
ef416fc2 | 58 | */ |
59 | ||
60 | /* | |
61 | * Include necessary headers... | |
62 | */ | |
63 | ||
64 | #include "cupsd.h" | |
65 | ||
66 | ||
67 | /* | |
68 | * Local functions... | |
69 | */ | |
70 | ||
b423cd4c | 71 | static void add_printer_defaults(cupsd_printer_t *p); |
bd7854cb | 72 | static void add_printer_filter(cupsd_printer_t *p, const char *filter); |
73 | static void add_printer_formats(cupsd_printer_t *p); | |
ef416fc2 | 74 | static int compare_printers(void *first, void *second, void *data); |
e1d6a774 | 75 | static void delete_printer_filters(cupsd_printer_t *p); |
ef416fc2 | 76 | #ifdef __sgi |
77 | static void write_irix_config(cupsd_printer_t *p); | |
78 | static void write_irix_state(cupsd_printer_t *p); | |
79 | #endif /* __sgi */ | |
80 | ||
81 | ||
82 | /* | |
83 | * 'cupsdAddPrinter()' - Add a printer to the system. | |
84 | */ | |
85 | ||
86 | cupsd_printer_t * /* O - New printer */ | |
87 | cupsdAddPrinter(const char *name) /* I - Name of printer */ | |
88 | { | |
89 | cupsd_printer_t *p; /* New printer */ | |
90 | ||
91 | ||
92 | /* | |
93 | * Range check input... | |
94 | */ | |
95 | ||
96 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdAddPrinter(\"%s\")", name); | |
97 | ||
98 | /* | |
99 | * Create a new printer entity... | |
100 | */ | |
101 | ||
102 | if ((p = calloc(1, sizeof(cupsd_printer_t))) == NULL) | |
103 | { | |
104 | cupsdLogMessage(CUPSD_LOG_CRIT, "Unable to allocate memory for printer - %s", | |
105 | strerror(errno)); | |
106 | return (NULL); | |
107 | } | |
108 | ||
109 | cupsdSetString(&p->name, name); | |
110 | cupsdSetString(&p->info, name); | |
111 | cupsdSetString(&p->hostname, ServerName); | |
112 | ||
113 | cupsdSetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName, LocalPort, name); | |
114 | cupsdSetStringf(&p->device_uri, "file:/dev/null"); | |
115 | ||
116 | p->state = IPP_PRINTER_STOPPED; | |
117 | p->state_time = time(NULL); | |
118 | p->accepting = 0; | |
fa73b229 | 119 | p->shared = DefaultShared; |
ef416fc2 | 120 | p->filetype = mimeAddType(MimeDatabase, "printer", name); |
121 | ||
122 | cupsdSetString(&p->job_sheets[0], "none"); | |
123 | cupsdSetString(&p->job_sheets[1], "none"); | |
124 | ||
125 | cupsdSetString(&p->error_policy, "stop-printer"); | |
126 | cupsdSetString(&p->op_policy, DefaultPolicy); | |
127 | ||
128 | p->op_policy_ptr = DefaultPolicyPtr; | |
129 | ||
130 | if (MaxPrinterHistory) | |
131 | p->history = calloc(MaxPrinterHistory, sizeof(ipp_t *)); | |
132 | ||
133 | /* | |
134 | * Insert the printer in the printer list alphabetically... | |
135 | */ | |
136 | ||
137 | if (!Printers) | |
138 | Printers = cupsArrayNew(compare_printers, NULL); | |
139 | ||
140 | cupsArrayAdd(Printers, p); | |
141 | ||
142 | if (!ImplicitPrinters) | |
143 | ImplicitPrinters = cupsArrayNew(compare_printers, NULL); | |
144 | ||
145 | /* | |
146 | * Return the new printer... | |
147 | */ | |
148 | ||
149 | return (p); | |
150 | } | |
151 | ||
152 | ||
ef416fc2 | 153 | /* |
154 | * 'cupsdAddPrinterHistory()' - Add the current printer state to the history. | |
155 | */ | |
156 | ||
157 | void | |
158 | cupsdAddPrinterHistory( | |
159 | cupsd_printer_t *p) /* I - Printer */ | |
160 | { | |
161 | ipp_t *history; /* History collection */ | |
162 | ||
163 | ||
164 | /* | |
165 | * Stop early if we aren't keeping history data... | |
166 | */ | |
167 | ||
168 | if (MaxPrinterHistory <= 0) | |
169 | return; | |
170 | ||
171 | /* | |
172 | * Retire old history data as needed... | |
173 | */ | |
174 | ||
175 | p->sequence_number ++; | |
176 | ||
177 | if (p->num_history >= MaxPrinterHistory) | |
178 | { | |
179 | p->num_history --; | |
180 | ippDelete(p->history[0]); | |
181 | memmove(p->history, p->history + 1, p->num_history * sizeof(ipp_t *)); | |
182 | } | |
183 | ||
184 | /* | |
185 | * Create a collection containing the current printer-state, printer-up-time, | |
186 | * printer-state-message, and printer-state-reasons attributes. | |
187 | */ | |
188 | ||
189 | history = ippNew(); | |
190 | ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", | |
191 | p->state); | |
192 | ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-accepting-jobs", | |
193 | p->accepting); | |
fa73b229 | 194 | ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-shared", p->shared); |
ef416fc2 | 195 | ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-state-message", |
196 | NULL, p->state_message); | |
e00b005a | 197 | #ifdef __APPLE__ |
198 | if (p->recoverable) | |
199 | ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
200 | "com.apple.print.recoverable-message", NULL, p->recoverable); | |
201 | #endif /* __APPLE__ */ | |
ef416fc2 | 202 | if (p->num_reasons == 0) |
203 | ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
204 | "printer-state-reasons", NULL, | |
205 | p->state == IPP_PRINTER_STOPPED ? "paused" : "none"); | |
206 | else | |
207 | ippAddStrings(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
208 | "printer-state-reasons", p->num_reasons, NULL, | |
209 | (const char * const *)p->reasons); | |
210 | ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
211 | "printer-state-change-time", p->state_time); | |
212 | ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
213 | "printer-state-sequence-number", p->sequence_number); | |
214 | ||
215 | p->history[p->num_history] = history; | |
216 | p->num_history ++; | |
217 | } | |
218 | ||
219 | ||
220 | /* | |
221 | * 'cupsdAddPrinterUser()' - Add a user to the ACL. | |
222 | */ | |
223 | ||
224 | void | |
225 | cupsdAddPrinterUser( | |
226 | cupsd_printer_t *p, /* I - Printer */ | |
227 | const char *username) /* I - User */ | |
228 | { | |
229 | const char **temp; /* Temporary array pointer */ | |
230 | ||
231 | ||
232 | if (!p || !username) | |
233 | return; | |
234 | ||
235 | if (p->num_users == 0) | |
236 | temp = malloc(sizeof(char **)); | |
237 | else | |
238 | temp = realloc(p->users, sizeof(char **) * (p->num_users + 1)); | |
239 | ||
240 | if (!temp) | |
241 | return; | |
242 | ||
243 | p->users = temp; | |
244 | temp += p->num_users; | |
245 | ||
246 | if ((*temp = strdup(username)) != NULL) | |
247 | p->num_users ++; | |
248 | } | |
249 | ||
250 | ||
251 | /* | |
252 | * 'cupsdCreateCommonData()' - Create the common printer data. | |
253 | */ | |
254 | ||
255 | void | |
256 | cupsdCreateCommonData(void) | |
257 | { | |
258 | int i; /* Looping var */ | |
259 | ipp_attribute_t *attr; /* Attribute data */ | |
260 | static const int nups[] = /* number-up-supported values */ | |
261 | { 1, 2, 4, 6, 9, 16 }; | |
262 | static const ipp_orient_t orients[4] =/* orientation-requested-supported values */ | |
263 | { | |
264 | IPP_PORTRAIT, | |
265 | IPP_LANDSCAPE, | |
266 | IPP_REVERSE_LANDSCAPE, | |
267 | IPP_REVERSE_PORTRAIT | |
268 | }; | |
269 | static const char * const holds[] = /* job-hold-until-supported values */ | |
270 | { | |
271 | "no-hold", | |
272 | "indefinite", | |
273 | "day-time", | |
274 | "evening", | |
275 | "night", | |
276 | "second-shift", | |
277 | "third-shift", | |
278 | "weekend" | |
279 | }; | |
280 | static const char * const versions[] =/* ipp-versions-supported values */ | |
281 | { | |
282 | "1.0", | |
283 | "1.1" | |
284 | }; | |
285 | static const ipp_op_t ops[] = /* operations-supported values */ | |
286 | { | |
287 | IPP_PRINT_JOB, | |
288 | IPP_VALIDATE_JOB, | |
289 | IPP_CREATE_JOB, | |
290 | IPP_SEND_DOCUMENT, | |
291 | IPP_CANCEL_JOB, | |
292 | IPP_GET_JOB_ATTRIBUTES, | |
293 | IPP_GET_JOBS, | |
294 | IPP_GET_PRINTER_ATTRIBUTES, | |
295 | IPP_HOLD_JOB, | |
296 | IPP_RELEASE_JOB, | |
297 | IPP_PAUSE_PRINTER, | |
298 | IPP_RESUME_PRINTER, | |
299 | IPP_PURGE_JOBS, | |
300 | IPP_SET_JOB_ATTRIBUTES, | |
301 | IPP_CREATE_PRINTER_SUBSCRIPTION, | |
302 | IPP_CREATE_JOB_SUBSCRIPTION, | |
303 | IPP_GET_SUBSCRIPTION_ATTRIBUTES, | |
304 | IPP_GET_SUBSCRIPTIONS, | |
305 | IPP_RENEW_SUBSCRIPTION, | |
306 | IPP_CANCEL_SUBSCRIPTION, | |
307 | IPP_GET_NOTIFICATIONS, | |
308 | IPP_ENABLE_PRINTER, | |
309 | IPP_DISABLE_PRINTER, | |
310 | CUPS_GET_DEFAULT, | |
311 | CUPS_GET_PRINTERS, | |
312 | CUPS_ADD_PRINTER, | |
313 | CUPS_DELETE_PRINTER, | |
314 | CUPS_GET_CLASSES, | |
315 | CUPS_ADD_CLASS, | |
316 | CUPS_DELETE_CLASS, | |
317 | CUPS_ACCEPT_JOBS, | |
318 | CUPS_REJECT_JOBS, | |
319 | CUPS_SET_DEFAULT, | |
320 | CUPS_GET_DEVICES, | |
321 | CUPS_GET_PPDS, | |
322 | CUPS_MOVE_JOB, | |
323 | CUPS_AUTHENTICATE_JOB, | |
324 | IPP_RESTART_JOB | |
325 | }; | |
326 | static const char * const charsets[] =/* charset-supported values */ | |
327 | { | |
328 | "us-ascii", | |
329 | "utf-8" | |
330 | }; | |
331 | static const char * const compressions[] = | |
332 | { /* document-compression-supported values */ | |
333 | "none" | |
334 | #ifdef HAVE_LIBZ | |
335 | ,"gzip" | |
336 | #endif /* HAVE_LIBZ */ | |
337 | }; | |
338 | static const char * const multiple_document_handling[] = | |
339 | { /* multiple-document-handling-supported values */ | |
340 | "separate-documents-uncollated-copies", | |
341 | "separate-documents-collated-copies" | |
342 | }; | |
343 | static const char * const errors[] = /* printer-error-policy-supported values */ | |
344 | { | |
345 | "abort-job", | |
346 | "retry-job", | |
347 | "stop-printer" | |
348 | }; | |
349 | static const char * const notify_attrs[] = | |
350 | { /* notify-attributes-supported values */ | |
351 | "printer-state-change-time", | |
352 | "notify-lease-expiration-time", | |
353 | "notify-subscriber-user-name" | |
354 | }; | |
355 | static const char * const notify_events[] = | |
356 | { /* notify-events-supported values */ | |
357 | "job-completed", | |
358 | "job-config-changed", | |
359 | "job-created", | |
360 | "job-progress", | |
361 | "job-state-changed", | |
362 | "job-stopped", | |
363 | "printer-added", | |
364 | "printer-changed", | |
365 | "printer-config-changed", | |
366 | "printer-deleted", | |
367 | "printer-finishings-changed", | |
368 | "printer-media-changed", | |
369 | "printer-modified", | |
370 | "printer-restarted", | |
371 | "printer-shutdown", | |
372 | "printer-state-changed", | |
373 | "printer-stopped", | |
374 | "server-audit", | |
375 | "server-restarted", | |
376 | "server-started", | |
377 | "server-stopped" | |
378 | }; | |
379 | ||
380 | ||
381 | if (CommonData) | |
382 | ippDelete(CommonData); | |
383 | ||
384 | CommonData = ippNew(); | |
385 | ||
386 | /* | |
387 | * This list of attributes is sorted to improve performance when the | |
388 | * client provides a requested-attributes attribute... | |
389 | */ | |
390 | ||
391 | /* charset-configured */ | |
392 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET, | |
393 | "charset-configured", NULL, DefaultCharset); | |
394 | ||
395 | /* charset-supported */ | |
396 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET, | |
397 | "charset-supported", sizeof(charsets) / sizeof(charsets[0]), | |
398 | NULL, charsets); | |
399 | ||
400 | /* compression-supported */ | |
401 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
402 | "compression-supported", | |
403 | sizeof(compressions) / sizeof(compressions[0]), | |
404 | NULL, compressions); | |
405 | ||
ef416fc2 | 406 | /* copies-supported */ |
407 | ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies); | |
408 | ||
ef416fc2 | 409 | /* document-format-default */ |
410 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE, | |
411 | "document-format-default", NULL, "application/octet-stream"); | |
412 | ||
ef416fc2 | 413 | /* generated-natural-language-supported */ |
414 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE, | |
415 | "generated-natural-language-supported", NULL, DefaultLanguage); | |
416 | ||
417 | /* ipp-versions-supported */ | |
418 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
419 | "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]), | |
420 | NULL, versions); | |
421 | ||
ef416fc2 | 422 | /* job-hold-until-supported */ |
423 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
424 | "job-hold-until-supported", sizeof(holds) / sizeof(holds[0]), | |
425 | NULL, holds); | |
426 | ||
ef416fc2 | 427 | /* job-priority-supported */ |
428 | ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
429 | "job-priority-supported", 100); | |
430 | ||
431 | /* job-sheets-supported */ | |
fa73b229 | 432 | if (cupsArrayCount(Banners) > 0) |
ef416fc2 | 433 | { |
434 | /* | |
435 | * Setup the job-sheets-supported attribute... | |
436 | */ | |
437 | ||
438 | if (Classification && !ClassifyOverride) | |
439 | attr = ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
440 | "job-sheets-supported", NULL, Classification); | |
441 | else | |
442 | attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
fa73b229 | 443 | "job-sheets-supported", cupsArrayCount(Banners) + 1, |
444 | NULL, NULL); | |
ef416fc2 | 445 | |
446 | if (attr == NULL) | |
447 | cupsdLogMessage(CUPSD_LOG_EMERG, | |
bd7854cb | 448 | "Unable to allocate memory for " |
ef416fc2 | 449 | "job-sheets-supported attribute: %s!", strerror(errno)); |
450 | else if (!Classification || ClassifyOverride) | |
451 | { | |
fa73b229 | 452 | cupsd_banner_t *banner; /* Current banner */ |
453 | ||
454 | ||
757d2cad | 455 | attr->values[0].string.text = _cupsStrAlloc("none"); |
ef416fc2 | 456 | |
fa73b229 | 457 | for (i = 1, banner = (cupsd_banner_t *)cupsArrayFirst(Banners); |
458 | banner; | |
459 | i ++, banner = (cupsd_banner_t *)cupsArrayNext(Banners)) | |
757d2cad | 460 | attr->values[i].string.text = _cupsStrAlloc(banner->name); |
ef416fc2 | 461 | } |
462 | } | |
463 | else | |
464 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
465 | "job-sheets-supported", NULL, "none"); | |
466 | ||
467 | /* multiple-document-handling-supported */ | |
468 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
469 | "multiple-document-handling-supported", | |
470 | sizeof(multiple_document_handling) / | |
471 | sizeof(multiple_document_handling[0]), NULL, | |
472 | multiple_document_handling); | |
473 | ||
474 | /* multiple-document-jobs-supported */ | |
475 | ippAddBoolean(CommonData, IPP_TAG_PRINTER, | |
476 | "multiple-document-jobs-supported", 1); | |
477 | ||
478 | /* multiple-operation-time-out */ | |
479 | ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
480 | "multiple-operation-time-out", 60); | |
481 | ||
482 | /* natural-language-configured */ | |
483 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE, | |
484 | "natural-language-configured", NULL, DefaultLanguage); | |
485 | ||
486 | /* notify-attributes-supported */ | |
487 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
488 | "notify-attributes-supported", | |
489 | (int)(sizeof(notify_attrs) / sizeof(notify_attrs[0])), | |
490 | NULL, notify_attrs); | |
491 | ||
ef416fc2 | 492 | /* notify-lease-duration-default */ |
493 | ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
494 | "notify-lease-duration-default", DefaultLeaseDuration); | |
495 | ||
496 | /* notify-lease-duration-supported */ | |
497 | ippAddRange(CommonData, IPP_TAG_PRINTER, | |
498 | "notify-lease-duration-supported", 0, | |
499 | MaxLeaseDuration ? MaxLeaseDuration : 2147483647); | |
500 | ||
501 | /* notify-max-events-supported */ | |
502 | ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
503 | "notify-max-events-supported", MaxEvents); | |
504 | ||
505 | /* notify-notify-events-default */ | |
506 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
507 | "notify-events-default", NULL, "job-completed"); | |
508 | ||
509 | /* notify-notify-events-supported */ | |
510 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
511 | "notify-events-supported", | |
512 | (int)(sizeof(notify_events) / sizeof(notify_events[0])), | |
513 | NULL, notify_events); | |
514 | ||
515 | /* notify-pull-method-supported */ | |
516 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
517 | "notify-pull-method-supported", NULL, "ippget"); | |
518 | ||
519 | /* TODO: scan notifier directory */ | |
520 | /* notify-schemes-supported */ | |
521 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
522 | "notify-schemes-supported", NULL, "mailto"); | |
523 | ||
ef416fc2 | 524 | /* number-up-supported */ |
525 | ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
526 | "number-up-supported", sizeof(nups) / sizeof(nups[0]), nups); | |
527 | ||
528 | /* operations-supported */ | |
529 | ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
530 | "operations-supported", | |
531 | sizeof(ops) / sizeof(ops[0]) + JobFiles - 1, (int *)ops); | |
532 | ||
ef416fc2 | 533 | /* orientation-requested-supported */ |
534 | ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
535 | "orientation-requested-supported", 4, (int *)orients); | |
536 | ||
537 | /* page-ranges-supported */ | |
538 | ippAddBoolean(CommonData, IPP_TAG_PRINTER, "page-ranges-supported", 1); | |
539 | ||
540 | /* pdf-override-supported */ | |
541 | ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
542 | "pdl-override-supported", NULL, "not-attempted"); | |
543 | ||
544 | /* printer-error-policy-supported */ | |
545 | ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
546 | "printer-error-policy-supported", | |
547 | sizeof(errors) / sizeof(errors[0]), NULL, errors); | |
548 | ||
549 | /* printer-op-policy-supported */ | |
550 | attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
551 | "printer-op-policy-supported", NumPolicies, NULL, NULL); | |
552 | for (i = 0; i < NumPolicies; i ++) | |
757d2cad | 553 | attr->values[i].string.text = _cupsStrAlloc(Policies[i]->name); |
ef416fc2 | 554 | } |
555 | ||
556 | ||
557 | /* | |
558 | * 'cupsdDeleteAllPrinters()' - Delete all printers from the system. | |
559 | */ | |
560 | ||
561 | void | |
562 | cupsdDeleteAllPrinters(void) | |
563 | { | |
564 | cupsd_printer_t *p; /* Pointer to current printer/class */ | |
565 | ||
566 | ||
567 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
568 | p; | |
569 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
570 | if (!(p->type & CUPS_PRINTER_CLASS)) | |
571 | cupsdDeletePrinter(p, 0); | |
572 | } | |
573 | ||
574 | ||
575 | /* | |
576 | * 'cupsdDeletePrinter()' - Delete a printer from the system. | |
577 | */ | |
578 | ||
579 | void | |
580 | cupsdDeletePrinter( | |
581 | cupsd_printer_t *p, /* I - Printer to delete */ | |
582 | int update) /* I - Update printers.conf? */ | |
583 | { | |
584 | int i; /* Looping var */ | |
585 | #ifdef __sgi | |
586 | char filename[1024]; /* Interface script filename */ | |
587 | #endif /* __sgi */ | |
588 | ||
589 | ||
590 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdDeletePrinter(p=%p(%s), update=%d)", | |
591 | p, p->name, update); | |
592 | ||
593 | /* | |
594 | * Save the current position in the Printers array... | |
595 | */ | |
596 | ||
597 | cupsArraySave(Printers); | |
598 | ||
599 | /* | |
600 | * Stop printing on this printer... | |
601 | */ | |
602 | ||
603 | cupsdStopPrinter(p, update); | |
604 | ||
605 | /* | |
606 | * If this printer is the next for browsing, point to the next one... | |
607 | */ | |
608 | ||
609 | if (p == BrowseNext) | |
610 | { | |
611 | cupsArrayFind(Printers, p); | |
612 | BrowseNext = (cupsd_printer_t *)cupsArrayNext(Printers); | |
613 | } | |
614 | ||
615 | /* | |
616 | * Remove the printer from the list... | |
617 | */ | |
618 | ||
619 | cupsArrayRemove(Printers, p); | |
620 | ||
621 | /* | |
622 | * Remove the dummy interface/icon/option files under IRIX... | |
623 | */ | |
624 | ||
625 | #ifdef __sgi | |
626 | snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name); | |
627 | unlink(filename); | |
628 | ||
629 | snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", | |
630 | p->name); | |
631 | unlink(filename); | |
632 | ||
633 | snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name); | |
634 | unlink(filename); | |
635 | ||
636 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name); | |
637 | unlink(filename); | |
638 | ||
639 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name); | |
640 | unlink(filename); | |
641 | ||
642 | snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name); | |
643 | unlink(filename); | |
644 | #endif /* __sgi */ | |
645 | ||
646 | /* | |
e00b005a | 647 | * If p is the default printer, assign a different one... |
ef416fc2 | 648 | */ |
649 | ||
650 | if (p == DefaultPrinter) | |
e00b005a | 651 | { |
652 | DefaultPrinter = NULL; | |
653 | ||
654 | if (UseNetworkDefault) | |
655 | { | |
656 | /* | |
657 | * Find the first network default printer and use it... | |
658 | */ | |
659 | ||
660 | cupsd_printer_t *dp; /* New default printer */ | |
661 | ||
662 | ||
663 | for (dp = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
664 | dp; | |
665 | dp = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
666 | if (dp != p && (dp->type & CUPS_PRINTER_DEFAULT)) | |
667 | { | |
668 | DefaultPrinter = p; | |
669 | break; | |
670 | } | |
671 | } | |
672 | } | |
ef416fc2 | 673 | |
674 | /* | |
675 | * Remove this printer from any classes and send a browse delete message... | |
676 | */ | |
677 | ||
678 | if (!(p->type & CUPS_PRINTER_IMPLICIT)) | |
679 | { | |
680 | cupsdDeletePrinterFromClasses(p); | |
681 | cupsdSendBrowseDelete(p); | |
682 | } | |
683 | ||
684 | /* | |
685 | * Free all memory used by the printer... | |
686 | */ | |
687 | ||
688 | if (p->printers != NULL) | |
689 | free(p->printers); | |
690 | ||
691 | if (MaxPrinterHistory) | |
692 | { | |
693 | for (i = 0; i < p->num_history; i ++) | |
694 | ippDelete(p->history[i]); | |
695 | ||
696 | free(p->history); | |
697 | } | |
698 | ||
699 | for (i = 0; i < p->num_reasons; i ++) | |
700 | free(p->reasons[i]); | |
701 | ||
702 | ippDelete(p->attrs); | |
703 | ||
e1d6a774 | 704 | delete_printer_filters(p); |
ef416fc2 | 705 | |
fa73b229 | 706 | mimeDeleteType(MimeDatabase, p->filetype); |
707 | ||
ef416fc2 | 708 | cupsdFreePrinterUsers(p); |
709 | cupsdFreeQuotas(p); | |
710 | ||
711 | cupsdClearString(&p->uri); | |
712 | cupsdClearString(&p->hostname); | |
713 | cupsdClearString(&p->name); | |
714 | cupsdClearString(&p->location); | |
715 | cupsdClearString(&p->make_model); | |
716 | cupsdClearString(&p->info); | |
717 | cupsdClearString(&p->job_sheets[0]); | |
718 | cupsdClearString(&p->job_sheets[1]); | |
719 | cupsdClearString(&p->device_uri); | |
720 | cupsdClearString(&p->port_monitor); | |
721 | cupsdClearString(&p->op_policy); | |
722 | cupsdClearString(&p->error_policy); | |
723 | ||
80ca4592 | 724 | cupsArrayDelete(p->filetypes); |
725 | ||
b423cd4c | 726 | if (p->browse_attrs) |
727 | free(p->browse_attrs); | |
728 | ||
e00b005a | 729 | #ifdef __APPLE__ |
730 | cupsdClearString(&p->recoverable); | |
731 | #endif /* __APPLE__ */ | |
732 | ||
b423cd4c | 733 | cupsFreeOptions(p->num_options, p->options); |
734 | ||
ef416fc2 | 735 | free(p); |
736 | ||
737 | /* | |
738 | * Restore the previous position in the Printers array... | |
739 | */ | |
740 | ||
741 | cupsArrayRestore(Printers); | |
742 | } | |
743 | ||
744 | ||
ef416fc2 | 745 | /* |
746 | * 'cupsdFindDest()' - Find a destination in the list. | |
747 | */ | |
748 | ||
749 | cupsd_printer_t * /* O - Destination in list */ | |
750 | cupsdFindDest(const char *name) /* I - Name of printer or class to find */ | |
751 | { | |
752 | cupsd_printer_t key; /* Search key */ | |
753 | ||
754 | ||
755 | key.name = (char *)name; | |
756 | return ((cupsd_printer_t *)cupsArrayFind(Printers, &key)); | |
757 | } | |
758 | ||
759 | ||
760 | /* | |
761 | * 'cupsdFindPrinter()' - Find a printer in the list. | |
762 | */ | |
763 | ||
764 | cupsd_printer_t * /* O - Printer in list */ | |
765 | cupsdFindPrinter(const char *name) /* I - Name of printer to find */ | |
766 | { | |
767 | cupsd_printer_t *p; /* Printer in list */ | |
768 | ||
769 | ||
770 | if ((p = cupsdFindDest(name)) != NULL && (p->type & CUPS_PRINTER_CLASS)) | |
771 | return (NULL); | |
772 | else | |
773 | return (p); | |
774 | } | |
775 | ||
776 | ||
777 | /* | |
778 | * 'cupsdFreePrinterUsers()' - Free allow/deny users. | |
779 | */ | |
780 | ||
781 | void | |
782 | cupsdFreePrinterUsers( | |
783 | cupsd_printer_t *p) /* I - Printer */ | |
784 | { | |
785 | int i; /* Looping var */ | |
786 | ||
787 | ||
788 | if (!p || !p->num_users) | |
789 | return; | |
790 | ||
791 | for (i = 0; i < p->num_users; i ++) | |
792 | free((void *)p->users[i]); | |
793 | ||
794 | free(p->users); | |
795 | ||
796 | p->num_users = 0; | |
797 | p->users = NULL; | |
798 | } | |
799 | ||
800 | ||
801 | /* | |
802 | * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file. | |
803 | */ | |
804 | ||
805 | void | |
806 | cupsdLoadAllPrinters(void) | |
807 | { | |
808 | cups_file_t *fp; /* printers.conf file */ | |
809 | int linenum; /* Current line number */ | |
810 | char line[1024], /* Line from file */ | |
811 | *value, /* Pointer to value */ | |
812 | *valueptr; /* Pointer into value */ | |
813 | cupsd_printer_t *p; /* Current printer */ | |
814 | ||
815 | ||
816 | /* | |
817 | * Open the printers.conf file... | |
818 | */ | |
819 | ||
820 | snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot); | |
821 | if ((fp = cupsFileOpen(line, "r")) == NULL) | |
822 | { | |
fa73b229 | 823 | if (errno != ENOENT) |
bd7854cb | 824 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open %s - %s", line, |
fa73b229 | 825 | strerror(errno)); |
ef416fc2 | 826 | return; |
827 | } | |
828 | ||
829 | /* | |
830 | * Read printer configurations until we hit EOF... | |
831 | */ | |
832 | ||
833 | linenum = 0; | |
834 | p = NULL; | |
835 | ||
836 | while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum)) | |
837 | { | |
838 | /* | |
839 | * Decode the directive... | |
840 | */ | |
841 | ||
842 | if (!strcasecmp(line, "<Printer") || | |
843 | !strcasecmp(line, "<DefaultPrinter")) | |
844 | { | |
845 | /* | |
846 | * <Printer name> or <DefaultPrinter name> | |
847 | */ | |
848 | ||
849 | if (p == NULL && value) | |
850 | { | |
851 | /* | |
852 | * Add the printer and a base file type... | |
853 | */ | |
854 | ||
bd7854cb | 855 | cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading printer %s...", value); |
ef416fc2 | 856 | |
857 | p = cupsdAddPrinter(value); | |
858 | p->accepting = 1; | |
859 | p->state = IPP_PRINTER_IDLE; | |
860 | ||
861 | /* | |
862 | * Set the default printer as needed... | |
863 | */ | |
864 | ||
865 | if (!strcasecmp(line, "<DefaultPrinter")) | |
866 | DefaultPrinter = p; | |
867 | } | |
868 | else | |
869 | { | |
870 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
871 | "Syntax error on line %d of printers.conf.", linenum); | |
872 | return; | |
873 | } | |
874 | } | |
875 | else if (!strcasecmp(line, "</Printer>")) | |
876 | { | |
877 | if (p != NULL) | |
878 | { | |
879 | /* | |
880 | * Close out the current printer... | |
881 | */ | |
882 | ||
883 | cupsdSetPrinterAttrs(p); | |
884 | cupsdAddPrinterHistory(p); | |
885 | ||
886 | if (p->device_uri && strncmp(p->device_uri, "file:", 5) && | |
887 | p->state != IPP_PRINTER_STOPPED) | |
888 | { | |
889 | /* | |
890 | * See if the backend exists... | |
891 | */ | |
892 | ||
893 | snprintf(line, sizeof(line), "%s/backend/%s", ServerBin, | |
894 | p->device_uri); | |
895 | ||
896 | if ((valueptr = strchr(line + strlen(ServerBin), ':')) != NULL) | |
897 | *valueptr = '\0'; /* Chop everything but URI scheme */ | |
898 | ||
899 | if (access(line, 0)) | |
900 | { | |
901 | /* | |
902 | * Backend does not exist, stop printer... | |
903 | */ | |
904 | ||
905 | p->state = IPP_PRINTER_STOPPED; | |
906 | snprintf(p->state_message, sizeof(p->state_message), | |
907 | "Backend %s does not exist!", line); | |
908 | } | |
909 | } | |
910 | ||
911 | p = NULL; | |
912 | } | |
913 | else | |
914 | { | |
915 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
916 | "Syntax error on line %d of printers.conf.", linenum); | |
917 | return; | |
918 | } | |
919 | } | |
920 | else if (!p) | |
921 | { | |
922 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
923 | "Syntax error on line %d of printers.conf.", linenum); | |
924 | return; | |
925 | } | |
926 | else if (!strcasecmp(line, "Info")) | |
927 | { | |
928 | if (value) | |
929 | cupsdSetString(&p->info, value); | |
930 | } | |
931 | else if (!strcasecmp(line, "Location")) | |
932 | { | |
933 | if (value) | |
934 | cupsdSetString(&p->location, value); | |
935 | } | |
936 | else if (!strcasecmp(line, "DeviceURI")) | |
937 | { | |
938 | if (value) | |
939 | cupsdSetString(&p->device_uri, value); | |
940 | else | |
941 | { | |
942 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
943 | "Syntax error on line %d of printers.conf.", linenum); | |
944 | return; | |
945 | } | |
946 | } | |
b423cd4c | 947 | else if (!strcasecmp(line, "Option") && value) |
948 | { | |
949 | /* | |
950 | * Option name value | |
951 | */ | |
952 | ||
953 | for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++); | |
954 | ||
955 | if (!*valueptr) | |
956 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
957 | "Syntax error on line %d of printers.conf.", linenum); | |
958 | else | |
959 | { | |
960 | for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0'); | |
961 | ||
962 | p->num_options = cupsAddOption(value, valueptr, p->num_options, | |
963 | &(p->options)); | |
964 | } | |
965 | } | |
ef416fc2 | 966 | else if (!strcasecmp(line, "PortMonitor")) |
967 | { | |
968 | if (value && strcmp(value, "none")) | |
969 | cupsdSetString(&p->port_monitor, value); | |
970 | else if (value) | |
971 | cupsdClearString(&p->port_monitor); | |
972 | else | |
973 | { | |
974 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
975 | "Syntax error on line %d of printers.conf.", linenum); | |
976 | return; | |
977 | } | |
978 | } | |
979 | else if (!strcasecmp(line, "State")) | |
980 | { | |
981 | /* | |
982 | * Set the initial queue state... | |
983 | */ | |
984 | ||
985 | if (value && !strcasecmp(value, "idle")) | |
986 | p->state = IPP_PRINTER_IDLE; | |
987 | else if (value && !strcasecmp(value, "stopped")) | |
988 | p->state = IPP_PRINTER_STOPPED; | |
989 | else | |
990 | { | |
991 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
992 | "Syntax error on line %d of printers.conf.", linenum); | |
993 | return; | |
994 | } | |
995 | } | |
996 | else if (!strcasecmp(line, "StateMessage")) | |
997 | { | |
998 | /* | |
999 | * Set the initial queue state message... | |
1000 | */ | |
1001 | ||
1002 | if (value) | |
1003 | strlcpy(p->state_message, value, sizeof(p->state_message)); | |
1004 | } | |
1005 | else if (!strcasecmp(line, "StateTime")) | |
1006 | { | |
1007 | /* | |
1008 | * Set the state time... | |
1009 | */ | |
1010 | ||
1011 | if (value) | |
1012 | p->state_time = atoi(value); | |
1013 | } | |
1014 | else if (!strcasecmp(line, "Accepting")) | |
1015 | { | |
1016 | /* | |
1017 | * Set the initial accepting state... | |
1018 | */ | |
1019 | ||
1020 | if (value && | |
1021 | (!strcasecmp(value, "yes") || | |
1022 | !strcasecmp(value, "on") || | |
1023 | !strcasecmp(value, "true"))) | |
1024 | p->accepting = 1; | |
1025 | else if (value && | |
1026 | (!strcasecmp(value, "no") || | |
1027 | !strcasecmp(value, "off") || | |
1028 | !strcasecmp(value, "false"))) | |
1029 | p->accepting = 0; | |
1030 | else | |
1031 | { | |
1032 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1033 | "Syntax error on line %d of printers.conf.", linenum); | |
1034 | return; | |
1035 | } | |
1036 | } | |
1037 | else if (!strcasecmp(line, "Shared")) | |
1038 | { | |
1039 | /* | |
1040 | * Set the initial shared state... | |
1041 | */ | |
1042 | ||
1043 | if (value && | |
1044 | (!strcasecmp(value, "yes") || | |
1045 | !strcasecmp(value, "on") || | |
1046 | !strcasecmp(value, "true"))) | |
1047 | p->shared = 1; | |
1048 | else if (value && | |
1049 | (!strcasecmp(value, "no") || | |
1050 | !strcasecmp(value, "off") || | |
1051 | !strcasecmp(value, "false"))) | |
1052 | p->shared = 0; | |
1053 | else | |
1054 | { | |
1055 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1056 | "Syntax error on line %d of printers.conf.", linenum); | |
1057 | return; | |
1058 | } | |
1059 | } | |
1060 | else if (!strcasecmp(line, "JobSheets")) | |
1061 | { | |
1062 | /* | |
1063 | * Set the initial job sheets... | |
1064 | */ | |
1065 | ||
1066 | if (value) | |
1067 | { | |
1068 | for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++); | |
1069 | ||
1070 | if (*valueptr) | |
1071 | *valueptr++ = '\0'; | |
1072 | ||
1073 | cupsdSetString(&p->job_sheets[0], value); | |
1074 | ||
1075 | while (isspace(*valueptr & 255)) | |
1076 | valueptr ++; | |
1077 | ||
1078 | if (*valueptr) | |
1079 | { | |
1080 | for (value = valueptr; *valueptr && !isspace(*valueptr & 255); valueptr ++); | |
1081 | ||
1082 | if (*valueptr) | |
1083 | *valueptr++ = '\0'; | |
1084 | ||
1085 | cupsdSetString(&p->job_sheets[1], value); | |
1086 | } | |
1087 | } | |
1088 | else | |
1089 | { | |
1090 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1091 | "Syntax error on line %d of printers.conf.", linenum); | |
1092 | return; | |
1093 | } | |
1094 | } | |
1095 | else if (!strcasecmp(line, "AllowUser")) | |
1096 | { | |
1097 | if (value) | |
1098 | { | |
1099 | p->deny_users = 0; | |
1100 | cupsdAddPrinterUser(p, value); | |
1101 | } | |
1102 | else | |
1103 | { | |
1104 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1105 | "Syntax error on line %d of printers.conf.", linenum); | |
1106 | return; | |
1107 | } | |
1108 | } | |
1109 | else if (!strcasecmp(line, "DenyUser")) | |
1110 | { | |
1111 | if (value) | |
1112 | { | |
1113 | p->deny_users = 1; | |
1114 | cupsdAddPrinterUser(p, value); | |
1115 | } | |
1116 | else | |
1117 | { | |
1118 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1119 | "Syntax error on line %d of printers.conf.", linenum); | |
1120 | return; | |
1121 | } | |
1122 | } | |
1123 | else if (!strcasecmp(line, "QuotaPeriod")) | |
1124 | { | |
1125 | if (value) | |
1126 | p->quota_period = atoi(value); | |
1127 | else | |
1128 | { | |
1129 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1130 | "Syntax error on line %d of printers.conf.", linenum); | |
1131 | return; | |
1132 | } | |
1133 | } | |
1134 | else if (!strcasecmp(line, "PageLimit")) | |
1135 | { | |
1136 | if (value) | |
1137 | p->page_limit = atoi(value); | |
1138 | else | |
1139 | { | |
1140 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1141 | "Syntax error on line %d of printers.conf.", linenum); | |
1142 | return; | |
1143 | } | |
1144 | } | |
1145 | else if (!strcasecmp(line, "KLimit")) | |
1146 | { | |
1147 | if (value) | |
1148 | p->k_limit = atoi(value); | |
1149 | else | |
1150 | { | |
1151 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1152 | "Syntax error on line %d of printers.conf.", linenum); | |
1153 | return; | |
1154 | } | |
1155 | } | |
1156 | else if (!strcasecmp(line, "OpPolicy")) | |
1157 | { | |
1158 | if (value) | |
1159 | cupsdSetString(&p->op_policy, value); | |
1160 | else | |
1161 | { | |
1162 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1163 | "Syntax error on line %d of printers.conf.", linenum); | |
1164 | return; | |
1165 | } | |
1166 | } | |
1167 | else if (!strcasecmp(line, "ErrorPolicy")) | |
1168 | { | |
1169 | if (value) | |
1170 | cupsdSetString(&p->error_policy, value); | |
1171 | else | |
1172 | { | |
1173 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1174 | "Syntax error on line %d of printers.conf.", linenum); | |
1175 | return; | |
1176 | } | |
1177 | } | |
1178 | else | |
1179 | { | |
1180 | /* | |
1181 | * Something else we don't understand... | |
1182 | */ | |
1183 | ||
1184 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1185 | "Unknown configuration directive %s on line %d of printers.conf.", | |
1186 | line, linenum); | |
1187 | } | |
1188 | } | |
1189 | ||
1190 | cupsFileClose(fp); | |
1191 | } | |
1192 | ||
1193 | ||
b423cd4c | 1194 | /* |
1195 | * 'cupsdRenamePrinter()' - Rename a printer. | |
1196 | */ | |
1197 | ||
1198 | void | |
1199 | cupsdRenamePrinter( | |
1200 | cupsd_printer_t *p, /* I - Printer */ | |
1201 | const char *name) /* I - New name */ | |
1202 | { | |
1203 | /* | |
1204 | * Remove the printer from the array(s) first... | |
1205 | */ | |
1206 | ||
1207 | cupsArrayRemove(Printers, p); | |
1208 | ||
1209 | if (p->type & CUPS_PRINTER_IMPLICIT) | |
1210 | cupsArrayRemove(ImplicitPrinters, p); | |
1211 | ||
1212 | /* | |
1213 | * Rename the printer type... | |
1214 | */ | |
1215 | ||
1216 | mimeDeleteType(MimeDatabase, p->filetype); | |
1217 | p->filetype = mimeAddType(MimeDatabase, "printer", name); | |
1218 | ||
1219 | /* | |
1220 | * Rename the printer... | |
1221 | */ | |
1222 | ||
a74454a7 | 1223 | cupsdSetString(&p->name, name); |
b423cd4c | 1224 | |
1225 | /* | |
1226 | * Reset printer attributes... | |
1227 | */ | |
1228 | ||
1229 | cupsdSetPrinterAttrs(p); | |
1230 | ||
1231 | /* | |
1232 | * Add the printer back to the printer array(s)... | |
1233 | */ | |
1234 | ||
1235 | cupsArrayAdd(Printers, p); | |
1236 | if (p->type & CUPS_PRINTER_IMPLICIT) | |
1237 | cupsArrayAdd(ImplicitPrinters, p); | |
1238 | } | |
1239 | ||
1240 | ||
ef416fc2 | 1241 | /* |
1242 | * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf | |
1243 | * file. | |
1244 | */ | |
1245 | ||
1246 | void | |
1247 | cupsdSaveAllPrinters(void) | |
1248 | { | |
1249 | int i; /* Looping var */ | |
1250 | cups_file_t *fp; /* printers.conf file */ | |
1251 | char temp[1024]; /* Temporary string */ | |
1252 | char backup[1024]; /* printers.conf.O file */ | |
1253 | cupsd_printer_t *printer; /* Current printer class */ | |
1254 | time_t curtime; /* Current time */ | |
1255 | struct tm *curdate; /* Current date */ | |
b423cd4c | 1256 | cups_option_t *option; /* Current option */ |
ef416fc2 | 1257 | |
1258 | ||
1259 | /* | |
1260 | * Create the printers.conf file... | |
1261 | */ | |
1262 | ||
1263 | snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot); | |
1264 | snprintf(backup, sizeof(backup), "%s/printers.conf.O", ServerRoot); | |
1265 | ||
1266 | if (rename(temp, backup)) | |
1267 | { | |
1268 | if (errno != ENOENT) | |
1269 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1270 | "Unable to backup printers.conf - %s", strerror(errno)); | |
1271 | } | |
1272 | ||
1273 | if ((fp = cupsFileOpen(temp, "w")) == NULL) | |
1274 | { | |
1275 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1276 | "Unable to save printers.conf - %s", strerror(errno)); | |
1277 | ||
1278 | if (rename(backup, temp)) | |
1279 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
1280 | "Unable to restore printers.conf - %s", strerror(errno)); | |
1281 | return; | |
1282 | } | |
1283 | else | |
1284 | cupsdLogMessage(CUPSD_LOG_INFO, "Saving printers.conf..."); | |
1285 | ||
1286 | /* | |
1287 | * Restrict access to the file... | |
1288 | */ | |
1289 | ||
1290 | fchown(cupsFileNumber(fp), getuid(), Group); | |
fa73b229 | 1291 | fchmod(cupsFileNumber(fp), 0600); |
ef416fc2 | 1292 | |
1293 | /* | |
1294 | * Write a small header to the file... | |
1295 | */ | |
1296 | ||
1297 | curtime = time(NULL); | |
1298 | curdate = localtime(&curtime); | |
1299 | strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate); | |
1300 | ||
1301 | cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n"); | |
1302 | cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp); | |
1303 | ||
1304 | /* | |
1305 | * Write each local printer known to the system... | |
1306 | */ | |
1307 | ||
1308 | for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
1309 | printer; | |
1310 | printer = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
1311 | { | |
1312 | /* | |
1313 | * Skip remote destinations and printer classes... | |
1314 | */ | |
1315 | ||
1316 | if ((printer->type & CUPS_PRINTER_REMOTE) || | |
1317 | (printer->type & CUPS_PRINTER_CLASS) || | |
1318 | (printer->type & CUPS_PRINTER_IMPLICIT)) | |
1319 | continue; | |
1320 | ||
1321 | /* | |
1322 | * Write printers as needed... | |
1323 | */ | |
1324 | ||
1325 | if (printer == DefaultPrinter) | |
1326 | cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name); | |
1327 | else | |
1328 | cupsFilePrintf(fp, "<Printer %s>\n", printer->name); | |
1329 | ||
1330 | if (printer->info) | |
1331 | cupsFilePrintf(fp, "Info %s\n", printer->info); | |
1332 | ||
1333 | if (printer->location) | |
1334 | cupsFilePrintf(fp, "Location %s\n", printer->location); | |
1335 | ||
1336 | if (printer->device_uri) | |
1337 | cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri); | |
1338 | ||
1339 | if (printer->port_monitor) | |
1340 | cupsFilePrintf(fp, "PortMonitor %s\n", printer->port_monitor); | |
1341 | ||
1342 | if (printer->state == IPP_PRINTER_STOPPED) | |
1343 | { | |
1344 | cupsFilePuts(fp, "State Stopped\n"); | |
1345 | cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message); | |
1346 | } | |
1347 | else | |
1348 | cupsFilePuts(fp, "State Idle\n"); | |
1349 | ||
1350 | cupsFilePrintf(fp, "StateTime %d\n", (int)printer->state_time); | |
1351 | ||
1352 | if (printer->accepting) | |
1353 | cupsFilePuts(fp, "Accepting Yes\n"); | |
1354 | else | |
1355 | cupsFilePuts(fp, "Accepting No\n"); | |
1356 | ||
1357 | if (printer->shared) | |
1358 | cupsFilePuts(fp, "Shared Yes\n"); | |
1359 | else | |
1360 | cupsFilePuts(fp, "Shared No\n"); | |
1361 | ||
1362 | cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0], | |
1363 | printer->job_sheets[1]); | |
1364 | ||
1365 | cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period); | |
1366 | cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit); | |
1367 | cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit); | |
1368 | ||
1369 | for (i = 0; i < printer->num_users; i ++) | |
1370 | cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow", | |
1371 | printer->users[i]); | |
1372 | ||
1373 | if (printer->op_policy) | |
1374 | cupsFilePrintf(fp, "OpPolicy %s\n", printer->op_policy); | |
1375 | if (printer->error_policy) | |
1376 | cupsFilePrintf(fp, "ErrorPolicy %s\n", printer->error_policy); | |
1377 | ||
b423cd4c | 1378 | for (i = printer->num_options, option = printer->options; |
1379 | i > 0; | |
1380 | i --, option ++) | |
1381 | cupsFilePrintf(fp, "Option %s %s\n", option->name, option->value); | |
1382 | ||
ef416fc2 | 1383 | cupsFilePuts(fp, "</Printer>\n"); |
1384 | ||
1385 | #ifdef __sgi | |
1386 | /* | |
1387 | * Make IRIX desktop & printer status happy | |
1388 | */ | |
1389 | ||
1390 | write_irix_state(printer); | |
1391 | #endif /* __sgi */ | |
1392 | } | |
1393 | ||
1394 | cupsFileClose(fp); | |
1395 | } | |
1396 | ||
1397 | ||
1398 | /* | |
1399 | * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file. | |
1400 | */ | |
1401 | ||
1402 | void | |
1403 | cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */ | |
1404 | { | |
b423cd4c | 1405 | int i, /* Looping var */ |
1406 | length; /* Length of browse attributes */ | |
1407 | char uri[HTTP_MAX_URI]; /* URI for printer */ | |
1408 | char resource[HTTP_MAX_URI]; /* Resource portion of URI */ | |
1409 | char filename[1024]; /* Name of PPD file */ | |
1410 | int num_media; /* Number of media options */ | |
1411 | cupsd_location_t *auth; /* Pointer to authentication element */ | |
1412 | const char *auth_supported; /* Authentication supported */ | |
1413 | cups_ptype_t printer_type; /* Printer type data */ | |
1414 | ppd_file_t *ppd; /* PPD file data */ | |
1415 | ppd_option_t *input_slot, /* InputSlot options */ | |
1416 | *media_type, /* MediaType options */ | |
1417 | *page_size, /* PageSize options */ | |
1418 | *output_bin, /* OutputBin options */ | |
1419 | *media_quality, /* EFMediaQualityMode options */ | |
1420 | *duplex; /* Duplex options */ | |
1421 | ppd_attr_t *ppdattr; /* PPD attribute */ | |
1422 | ipp_attribute_t *attr; /* Attribute data */ | |
1423 | ipp_value_t *val; /* Attribute value */ | |
1424 | int num_finishings; /* Number of finishings */ | |
1425 | ipp_finish_t finishings[5]; /* finishings-supported values */ | |
1426 | cups_option_t *option; /* Current printer option */ | |
ef416fc2 | 1427 | static const char * const sides[3] = /* sides-supported values */ |
1428 | { | |
b423cd4c | 1429 | "one-sided", |
1430 | "two-sided-long-edge", | |
1431 | "two-sided-short-edge" | |
ef416fc2 | 1432 | }; |
1433 | ||
1434 | ||
1435 | DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name, | |
1436 | p->type)); | |
1437 | ||
1438 | /* | |
1439 | * Make sure that we have the common attributes defined... | |
1440 | */ | |
1441 | ||
1442 | if (!CommonData) | |
1443 | cupsdCreateCommonData(); | |
1444 | ||
1445 | /* | |
1446 | * Clear out old filters, if any... | |
1447 | */ | |
1448 | ||
e1d6a774 | 1449 | delete_printer_filters(p); |
ef416fc2 | 1450 | |
1451 | /* | |
1452 | * Figure out the authentication that is required for the printer. | |
1453 | */ | |
1454 | ||
1455 | auth_supported = "requesting-user-name"; | |
1456 | if (!(p->type & CUPS_PRINTER_REMOTE)) | |
1457 | { | |
1458 | if (p->type & CUPS_PRINTER_CLASS) | |
1459 | snprintf(resource, sizeof(resource), "/classes/%s", p->name); | |
1460 | else | |
1461 | snprintf(resource, sizeof(resource), "/printers/%s", p->name); | |
1462 | ||
1463 | if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL) | |
1464 | auth = cupsdFindPolicyOp(p->op_policy_ptr, IPP_PRINT_JOB); | |
1465 | ||
1466 | if (auth) | |
1467 | { | |
1468 | if (auth->type == AUTH_BASIC || auth->type == AUTH_BASICDIGEST) | |
1469 | auth_supported = "basic"; | |
1470 | else if (auth->type == AUTH_DIGEST) | |
1471 | auth_supported = "digest"; | |
1472 | ||
1473 | if (auth->type != AUTH_NONE) | |
1474 | p->type |= CUPS_PRINTER_AUTHENTICATED; | |
1475 | else | |
1476 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; | |
1477 | } | |
1478 | else | |
1479 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; | |
1480 | } | |
1481 | ||
1482 | /* | |
1483 | * Create the required IPP attributes for a printer... | |
1484 | */ | |
1485 | ||
1486 | if (p->attrs) | |
1487 | ippDelete(p->attrs); | |
1488 | ||
1489 | p->attrs = ippNew(); | |
1490 | ||
1491 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
1492 | "uri-authentication-supported", NULL, auth_supported); | |
1493 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
1494 | "uri-security-supported", NULL, "none"); | |
1495 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL, | |
1496 | p->name); | |
1497 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", | |
1498 | NULL, p->location ? p->location : ""); | |
1499 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", | |
1500 | NULL, p->info ? p->info : ""); | |
1501 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info", | |
1502 | NULL, p->uri); | |
1503 | ||
1504 | if (p->num_users) | |
1505 | { | |
1506 | if (p->deny_users) | |
1507 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
1508 | "requesting-user-name-denied", p->num_users, NULL, | |
1509 | p->users); | |
1510 | else | |
1511 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
1512 | "requesting-user-name-allowed", p->num_users, NULL, | |
1513 | p->users); | |
1514 | } | |
1515 | ||
1516 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
1517 | "job-quota-period", p->quota_period); | |
1518 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
1519 | "job-k-limit", p->k_limit); | |
1520 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
1521 | "job-page-limit", p->page_limit); | |
1522 | ||
fa73b229 | 1523 | if (cupsArrayCount(Banners) > 0 && !(p->type & CUPS_PRINTER_REMOTE)) |
ef416fc2 | 1524 | { |
1525 | /* | |
1526 | * Setup the job-sheets-default attribute... | |
1527 | */ | |
1528 | ||
1529 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
1530 | "job-sheets-default", 2, NULL, NULL); | |
1531 | ||
1532 | if (attr != NULL) | |
1533 | { | |
757d2cad | 1534 | attr->values[0].string.text = _cupsStrAlloc(Classification ? |
ef416fc2 | 1535 | Classification : p->job_sheets[0]); |
757d2cad | 1536 | attr->values[1].string.text = _cupsStrAlloc(Classification ? |
ef416fc2 | 1537 | Classification : p->job_sheets[1]); |
1538 | } | |
1539 | } | |
1540 | ||
e00b005a | 1541 | printer_type = p->type; |
ef416fc2 | 1542 | |
1543 | p->raw = 0; | |
1544 | ||
1545 | if (p->type & CUPS_PRINTER_REMOTE) | |
1546 | { | |
1547 | /* | |
1548 | * Tell the client this is a remote printer of some type... | |
1549 | */ | |
1550 | ||
1551 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, | |
1552 | "printer-uri-supported", NULL, p->uri); | |
1553 | ||
1554 | if (p->make_model) | |
1555 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
1556 | "printer-make-and-model", NULL, p->make_model); | |
1557 | ||
fa73b229 | 1558 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, |
1559 | p->uri); | |
1560 | ||
ef416fc2 | 1561 | p->raw = 1; |
1562 | } | |
1563 | else | |
1564 | { | |
1565 | /* | |
1566 | * Assign additional attributes depending on whether this is a printer | |
1567 | * or class... | |
1568 | */ | |
1569 | ||
1570 | p->type &= ~CUPS_PRINTER_OPTIONS; | |
1571 | ||
1572 | if (p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT)) | |
1573 | { | |
1574 | p->raw = 1; | |
1575 | ||
1576 | /* | |
1577 | * Add class-specific attributes... | |
1578 | */ | |
1579 | ||
1580 | if ((p->type & CUPS_PRINTER_IMPLICIT) && p->num_printers > 0 && | |
1581 | p->printers[0]->make_model) | |
1582 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
1583 | "printer-make-and-model", NULL, p->printers[0]->make_model); | |
1584 | else | |
1585 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
1586 | "printer-make-and-model", NULL, "Local Printer Class"); | |
1587 | ||
fa73b229 | 1588 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, |
1589 | "file:///dev/null"); | |
1590 | ||
ef416fc2 | 1591 | if (p->num_printers > 0) |
1592 | { | |
1593 | /* | |
1594 | * Add a list of member URIs and names... | |
1595 | */ | |
1596 | ||
1597 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, | |
1598 | "member-uris", p->num_printers, NULL, NULL); | |
1599 | p->type |= CUPS_PRINTER_OPTIONS; | |
1600 | ||
1601 | for (i = 0; i < p->num_printers; i ++) | |
1602 | { | |
1603 | if (attr != NULL) | |
757d2cad | 1604 | attr->values[i].string.text = _cupsStrAlloc(p->printers[i]->uri); |
ef416fc2 | 1605 | |
1606 | p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type; | |
1607 | } | |
1608 | ||
1609 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
1610 | "member-names", p->num_printers, NULL, NULL); | |
1611 | ||
1612 | if (attr != NULL) | |
1613 | { | |
1614 | for (i = 0; i < p->num_printers; i ++) | |
757d2cad | 1615 | attr->values[i].string.text = _cupsStrAlloc(p->printers[i]->name); |
ef416fc2 | 1616 | } |
1617 | } | |
1618 | } | |
1619 | else | |
1620 | { | |
1621 | /* | |
1622 | * Add printer-specific attributes... Start by sanitizing the device | |
1623 | * URI so it doesn't have a username or password in it... | |
1624 | */ | |
1625 | ||
1626 | if (!p->device_uri) | |
1627 | strcpy(uri, "file:/dev/null"); | |
1628 | else if (strstr(p->device_uri, "://") != NULL) | |
1629 | { | |
1630 | /* | |
1631 | * http://..., ipp://..., etc. | |
1632 | */ | |
1633 | ||
1634 | cupsdSanitizeURI(p->device_uri, uri, sizeof(uri)); | |
1635 | } | |
1636 | else | |
1637 | { | |
1638 | /* | |
1639 | * file:..., serial:..., etc. | |
1640 | */ | |
1641 | ||
1642 | strlcpy(uri, p->device_uri, sizeof(uri)); | |
1643 | } | |
1644 | ||
1645 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, | |
1646 | uri); | |
1647 | ||
1648 | /* | |
1649 | * Assign additional attributes from the PPD file (if any)... | |
1650 | */ | |
1651 | ||
1652 | p->type |= CUPS_PRINTER_BW; | |
1653 | finishings[0] = IPP_FINISHINGS_NONE; | |
1654 | num_finishings = 1; | |
1655 | ||
1656 | snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, | |
1657 | p->name); | |
1658 | ||
1659 | if ((ppd = ppdOpenFile(filename)) != NULL) | |
1660 | { | |
1661 | /* | |
1662 | * Add make/model and other various attributes... | |
1663 | */ | |
1664 | ||
1665 | if (ppd->color_device) | |
1666 | p->type |= CUPS_PRINTER_COLOR; | |
1667 | if (ppd->variable_sizes) | |
1668 | p->type |= CUPS_PRINTER_VARIABLE; | |
1669 | if (!ppd->manual_copies) | |
1670 | p->type |= CUPS_PRINTER_COPIES; | |
1671 | if ((ppdattr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL) | |
1672 | if (ppdattr->value && !strcasecmp(ppdattr->value, "true")) | |
1673 | p->type |= CUPS_PRINTER_FAX; | |
1674 | ||
1675 | ippAddBoolean(p->attrs, IPP_TAG_PRINTER, "color-supported", | |
1676 | ppd->color_device); | |
1677 | if (ppd->throughput) | |
1678 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
1679 | "pages-per-minute", ppd->throughput); | |
1680 | ||
1681 | if (ppd->nickname) | |
bd7854cb | 1682 | { |
1683 | /* | |
1684 | * The NickName can be localized in the character set specified | |
e1d6a774 | 1685 | * by the LanugageEncoding attribute. However, ppdOpen2() has |
1686 | * already converted the ppd->nickname member to UTF-8 for us | |
1687 | * (the original attribute value is available separately) | |
bd7854cb | 1688 | */ |
1689 | ||
e1d6a774 | 1690 | cupsdSetString(&p->make_model, ppd->nickname); |
bd7854cb | 1691 | } |
ef416fc2 | 1692 | else if (ppd->modelname) |
e1d6a774 | 1693 | { |
1694 | /* | |
1695 | * Model name can only contain specific characters... | |
1696 | */ | |
1697 | ||
ef416fc2 | 1698 | cupsdSetString(&p->make_model, ppd->modelname); |
e1d6a774 | 1699 | } |
ef416fc2 | 1700 | else |
1701 | cupsdSetString(&p->make_model, "Bad PPD File"); | |
1702 | ||
bd7854cb | 1703 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, |
1704 | "printer-make-and-model", NULL, p->make_model); | |
ef416fc2 | 1705 | |
1706 | /* | |
1707 | * Add media options from the PPD file... | |
1708 | */ | |
1709 | ||
1710 | if ((input_slot = ppdFindOption(ppd, "InputSlot")) != NULL) | |
1711 | num_media = input_slot->num_choices; | |
1712 | else | |
1713 | num_media = 0; | |
1714 | ||
1715 | if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL) | |
1716 | num_media += media_type->num_choices; | |
1717 | ||
1718 | if ((page_size = ppdFindOption(ppd, "PageSize")) != NULL) | |
1719 | num_media += page_size->num_choices; | |
1720 | ||
1721 | if ((media_quality = ppdFindOption(ppd, "EFMediaQualityMode")) != NULL) | |
1722 | num_media += media_quality->num_choices; | |
1723 | ||
1724 | if (num_media == 0) | |
1725 | { | |
bd7854cb | 1726 | cupsdLogMessage(CUPSD_LOG_CRIT, |
b423cd4c | 1727 | "The PPD file for printer %s contains no media " |
1728 | "options and is therefore invalid!", p->name); | |
ef416fc2 | 1729 | } |
1730 | else | |
1731 | { | |
1732 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
1733 | "media-supported", num_media, NULL, NULL); | |
1734 | if (attr != NULL) | |
1735 | { | |
1736 | val = attr->values; | |
1737 | ||
1738 | if (input_slot != NULL) | |
1739 | for (i = 0; i < input_slot->num_choices; i ++, val ++) | |
757d2cad | 1740 | val->string.text = _cupsStrAlloc(input_slot->choices[i].choice); |
ef416fc2 | 1741 | |
1742 | if (media_type != NULL) | |
1743 | for (i = 0; i < media_type->num_choices; i ++, val ++) | |
757d2cad | 1744 | val->string.text = _cupsStrAlloc(media_type->choices[i].choice); |
ef416fc2 | 1745 | |
1746 | if (media_quality != NULL) | |
1747 | for (i = 0; i < media_quality->num_choices; i ++, val ++) | |
757d2cad | 1748 | val->string.text = _cupsStrAlloc(media_quality->choices[i].choice); |
ef416fc2 | 1749 | |
1750 | if (page_size != NULL) | |
1751 | { | |
1752 | for (i = 0; i < page_size->num_choices; i ++, val ++) | |
757d2cad | 1753 | val->string.text = _cupsStrAlloc(page_size->choices[i].choice); |
ef416fc2 | 1754 | |
b423cd4c | 1755 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
1756 | "media-default", NULL, page_size->defchoice); | |
ef416fc2 | 1757 | } |
1758 | else if (input_slot != NULL) | |
b423cd4c | 1759 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
1760 | "media-default", NULL, input_slot->defchoice); | |
ef416fc2 | 1761 | else if (media_type != NULL) |
b423cd4c | 1762 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
1763 | "media-default", NULL, media_type->defchoice); | |
ef416fc2 | 1764 | else if (media_quality != NULL) |
b423cd4c | 1765 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
1766 | "media-default", NULL, media_quality->defchoice); | |
ef416fc2 | 1767 | else |
b423cd4c | 1768 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
1769 | "media-default", NULL, "none"); | |
ef416fc2 | 1770 | } |
1771 | } | |
1772 | ||
1773 | /* | |
1774 | * Output bin... | |
1775 | */ | |
1776 | ||
1777 | if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL) | |
1778 | { | |
1779 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
1780 | "output-bin-supported", output_bin->num_choices, | |
1781 | NULL, NULL); | |
1782 | ||
1783 | if (attr != NULL) | |
1784 | { | |
1785 | for (i = 0, val = attr->values; | |
1786 | i < output_bin->num_choices; | |
1787 | i ++, val ++) | |
757d2cad | 1788 | val->string.text = _cupsStrAlloc(output_bin->choices[i].choice); |
ef416fc2 | 1789 | } |
1790 | } | |
1791 | ||
1792 | /* | |
1793 | * Duplexing, etc... | |
1794 | */ | |
1795 | ||
b423cd4c | 1796 | if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL) |
1797 | if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL) | |
1798 | if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL) | |
1799 | if ((duplex = ppdFindOption(ppd, "KD03Duplex")) == NULL) | |
1800 | duplex = ppdFindOption(ppd, "JCLDuplex"); | |
1801 | ||
1802 | if (duplex && duplex->num_choices > 1) | |
ef416fc2 | 1803 | { |
1804 | p->type |= CUPS_PRINTER_DUPLEX; | |
1805 | ||
b423cd4c | 1806 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
1807 | "sides-supported", 3, NULL, sides); | |
1808 | ||
1809 | if (!strcasecmp(duplex->defchoice, "DuplexTumble")) | |
1810 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
1811 | "sides-default", NULL, "two-sided-short-edge"); | |
1812 | else if (!strcasecmp(duplex->defchoice, "DuplexNoTumble")) | |
1813 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
1814 | "sides-default", NULL, "two-sided-long-edge"); | |
1815 | else | |
1816 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
1817 | "sides-default", NULL, "one-sided"); | |
ef416fc2 | 1818 | } |
1819 | ||
1820 | if (ppdFindOption(ppd, "Collate") != NULL) | |
1821 | p->type |= CUPS_PRINTER_COLLATE; | |
1822 | ||
1823 | if (ppdFindOption(ppd, "StapleLocation") != NULL) | |
1824 | { | |
1825 | p->type |= CUPS_PRINTER_STAPLE; | |
1826 | finishings[num_finishings++] = IPP_FINISHINGS_STAPLE; | |
1827 | } | |
1828 | ||
1829 | if (ppdFindOption(ppd, "BindEdge") != NULL) | |
1830 | { | |
1831 | p->type |= CUPS_PRINTER_BIND; | |
1832 | finishings[num_finishings++] = IPP_FINISHINGS_BIND; | |
1833 | } | |
1834 | ||
1835 | for (i = 0; i < ppd->num_sizes; i ++) | |
1836 | if (ppd->sizes[i].length > 1728) | |
1837 | p->type |= CUPS_PRINTER_LARGE; | |
1838 | else if (ppd->sizes[i].length > 1008) | |
1839 | p->type |= CUPS_PRINTER_MEDIUM; | |
1840 | else | |
1841 | p->type |= CUPS_PRINTER_SMALL; | |
1842 | ||
1843 | /* | |
1844 | * Add a filter from application/vnd.cups-raw to printer/name to | |
1845 | * handle "raw" printing by users. | |
1846 | */ | |
1847 | ||
bd7854cb | 1848 | add_printer_filter(p, "application/vnd.cups-raw 0 -"); |
ef416fc2 | 1849 | |
1850 | /* | |
1851 | * Add any filters in the PPD file... | |
1852 | */ | |
1853 | ||
1854 | DEBUG_printf(("ppd->num_filters = %d\n", ppd->num_filters)); | |
1855 | for (i = 0; i < ppd->num_filters; i ++) | |
1856 | { | |
1857 | DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i, ppd->filters[i])); | |
bd7854cb | 1858 | add_printer_filter(p, ppd->filters[i]); |
ef416fc2 | 1859 | } |
1860 | ||
1861 | if (ppd->num_filters == 0) | |
1862 | { | |
1863 | /* | |
1864 | * If there are no filters, add a PostScript printing filter. | |
1865 | */ | |
1866 | ||
bd7854cb | 1867 | add_printer_filter(p, "application/vnd.cups-postscript 0 -"); |
ef416fc2 | 1868 | } |
1869 | ||
1870 | /* | |
1871 | * Show current and available port monitors for this printer... | |
1872 | */ | |
1873 | ||
1874 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "port-monitor", | |
1875 | NULL, p->port_monitor ? p->port_monitor : "none"); | |
1876 | ||
1877 | ||
1878 | for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL); | |
1879 | ppdattr; | |
1880 | i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL)); | |
1881 | ||
1882 | if (ppd->protocols) | |
1883 | { | |
1884 | if (strstr(ppd->protocols, "TBCP")) | |
1885 | i ++; | |
1886 | else if (strstr(ppd->protocols, "BCP")) | |
1887 | i ++; | |
1888 | } | |
1889 | ||
1890 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
1891 | "port-monitor-supported", i, NULL, NULL); | |
1892 | ||
757d2cad | 1893 | attr->values[0].string.text = _cupsStrAlloc("none"); |
ef416fc2 | 1894 | |
1895 | for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL); | |
1896 | ppdattr; | |
1897 | i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL)) | |
757d2cad | 1898 | attr->values[i].string.text = _cupsStrAlloc(ppdattr->value); |
ef416fc2 | 1899 | |
1900 | if (ppd->protocols) | |
1901 | { | |
1902 | if (strstr(ppd->protocols, "TBCP")) | |
757d2cad | 1903 | attr->values[i].string.text = _cupsStrAlloc("tbcp"); |
ef416fc2 | 1904 | else if (strstr(ppd->protocols, "BCP")) |
757d2cad | 1905 | attr->values[i].string.text = _cupsStrAlloc("bcp"); |
ef416fc2 | 1906 | } |
1907 | ||
1908 | /* | |
1909 | * Close the PPD and set the type... | |
1910 | */ | |
1911 | ||
1912 | ppdClose(ppd); | |
1913 | ||
e00b005a | 1914 | printer_type = p->type; |
ef416fc2 | 1915 | } |
1916 | else if (!access(filename, 0)) | |
1917 | { | |
1918 | int pline; /* PPD line number */ | |
1919 | ppd_status_t pstatus; /* PPD load status */ | |
1920 | ||
1921 | ||
1922 | pstatus = ppdLastError(&pline); | |
1923 | ||
b423cd4c | 1924 | cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!", |
1925 | p->name); | |
ef416fc2 | 1926 | |
1927 | if (pstatus <= PPD_ALLOC_ERROR) | |
1928 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno)); | |
1929 | else | |
b423cd4c | 1930 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.", |
1931 | ppdErrorString(pstatus), pline); | |
ef416fc2 | 1932 | |
b423cd4c | 1933 | cupsdLogMessage(CUPSD_LOG_INFO, |
1934 | "Hint: Run \"cupstestppd %s\" and fix any errors.", | |
1935 | filename); | |
ef416fc2 | 1936 | |
1937 | /* | |
1938 | * Add a filter from application/vnd.cups-raw to printer/name to | |
1939 | * handle "raw" printing by users. | |
1940 | */ | |
1941 | ||
bd7854cb | 1942 | add_printer_filter(p, "application/vnd.cups-raw 0 -"); |
ef416fc2 | 1943 | |
1944 | /* | |
1945 | * Add a PostScript filter, since this is still possibly PS printer. | |
1946 | */ | |
1947 | ||
bd7854cb | 1948 | add_printer_filter(p, "application/vnd.cups-postscript 0 -"); |
ef416fc2 | 1949 | } |
1950 | else | |
1951 | { | |
1952 | /* | |
1953 | * If we have an interface script, add a filter entry for it... | |
1954 | */ | |
1955 | ||
1956 | snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot, | |
1957 | p->name); | |
b423cd4c | 1958 | if (!access(filename, X_OK)) |
ef416fc2 | 1959 | { |
1960 | /* | |
1961 | * Yes, we have a System V style interface script; use it! | |
1962 | */ | |
1963 | ||
1964 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
1965 | "printer-make-and-model", NULL, "Local System V Printer"); | |
1966 | ||
1967 | snprintf(filename, sizeof(filename), "*/* 0 %s/interfaces/%s", | |
1968 | ServerRoot, p->name); | |
bd7854cb | 1969 | add_printer_filter(p, filename); |
ef416fc2 | 1970 | } |
1971 | else if (p->device_uri && | |
1972 | !strncmp(p->device_uri, "ipp://", 6) && | |
1973 | (strstr(p->device_uri, "/printers/") != NULL || | |
1974 | strstr(p->device_uri, "/classes/") != NULL)) | |
1975 | { | |
1976 | /* | |
1977 | * Tell the client this is really a hard-wired remote printer. | |
1978 | */ | |
1979 | ||
e00b005a | 1980 | printer_type |= CUPS_PRINTER_REMOTE; |
ef416fc2 | 1981 | |
1982 | /* | |
1983 | * Point the printer-uri-supported attribute to the | |
1984 | * remote printer... | |
1985 | */ | |
1986 | ||
1987 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, | |
1988 | "printer-uri-supported", NULL, p->device_uri); | |
1989 | ||
1990 | /* | |
1991 | * Then set the make-and-model accordingly... | |
1992 | */ | |
1993 | ||
1994 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
1995 | "printer-make-and-model", NULL, "Remote Printer"); | |
1996 | ||
1997 | /* | |
1998 | * Print all files directly... | |
1999 | */ | |
2000 | ||
2001 | p->raw = 1; | |
2002 | } | |
2003 | else | |
2004 | { | |
2005 | /* | |
2006 | * Otherwise we have neither - treat this as a "dumb" printer | |
2007 | * with no PPD file... | |
2008 | */ | |
2009 | ||
2010 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
2011 | "printer-make-and-model", NULL, "Local Raw Printer"); | |
2012 | ||
2013 | p->raw = 1; | |
2014 | } | |
2015 | } | |
2016 | ||
2017 | ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
2018 | "finishings-supported", num_finishings, (int *)finishings); | |
2019 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
2020 | "finishings-default", IPP_FINISHINGS_NONE); | |
2021 | } | |
2022 | } | |
2023 | ||
b423cd4c | 2024 | /* |
2025 | * Copy the printer options into a browse attributes string we can re-use. | |
2026 | */ | |
2027 | ||
2028 | if (!(p->type & CUPS_PRINTER_REMOTE)) | |
2029 | { | |
2030 | const char *valptr; /* Pointer into value */ | |
2031 | char *attrptr; /* Pointer into attribute string */ | |
2032 | ||
2033 | ||
2034 | /* | |
2035 | * Free the old browse attributes as needed... | |
2036 | */ | |
2037 | ||
2038 | if (p->browse_attrs) | |
2039 | free(p->browse_attrs); | |
2040 | ||
2041 | /* | |
2042 | * Compute the length of all attributes + job-sheets, lease-duration, | |
2043 | * and BrowseLocalOptions. | |
2044 | */ | |
2045 | ||
2046 | for (length = 1, i = p->num_options, option = p->options; | |
2047 | i > 0; | |
2048 | i --, option ++) | |
2049 | { | |
2050 | length += strlen(option->name) + 2; | |
2051 | ||
2052 | if (option->value) | |
2053 | { | |
2054 | for (valptr = option->value; *valptr; valptr ++) | |
2055 | if (strchr(" \"\'\\", *valptr)) | |
2056 | length += 2; | |
2057 | else | |
2058 | length ++; | |
2059 | } | |
2060 | } | |
2061 | ||
2062 | length += 13 + strlen(p->job_sheets[0]) + strlen(p->job_sheets[1]); | |
2063 | length += 32; | |
2064 | if (BrowseLocalOptions) | |
2065 | length += 12 + strlen(BrowseLocalOptions); | |
2066 | ||
2067 | /* | |
2068 | * Allocate the new string... | |
2069 | */ | |
2070 | ||
2071 | if ((p->browse_attrs = calloc(1, length)) == NULL) | |
2072 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2073 | "Unable to allocate %d bytes for browse data!", | |
2074 | length); | |
2075 | else | |
2076 | { | |
2077 | /* | |
2078 | * Got the allocated string, now copy the options and attributes over... | |
2079 | */ | |
2080 | ||
2081 | sprintf(p->browse_attrs, "job-sheets=%s,%s lease-duration=%d", | |
2082 | p->job_sheets[0], p->job_sheets[1], BrowseTimeout); | |
2083 | attrptr = p->browse_attrs + strlen(p->browse_attrs); | |
2084 | ||
2085 | if (BrowseLocalOptions) | |
2086 | { | |
2087 | sprintf(attrptr, " ipp-options=%s", BrowseLocalOptions); | |
2088 | attrptr += strlen(attrptr); | |
2089 | } | |
2090 | ||
2091 | for (i = p->num_options, option = p->options; | |
2092 | i > 0; | |
2093 | i --, option ++) | |
2094 | { | |
2095 | *attrptr++ = ' '; | |
2096 | strcpy(attrptr, option->name); | |
2097 | attrptr += strlen(attrptr); | |
2098 | ||
2099 | if (option->value) | |
2100 | { | |
2101 | *attrptr++ = '='; | |
2102 | ||
2103 | for (valptr = option->value; *valptr; valptr ++) | |
2104 | { | |
2105 | if (strchr(" \"\'\\", *valptr)) | |
2106 | *attrptr++ = '\\'; | |
2107 | ||
2108 | *attrptr++ = *valptr; | |
2109 | } | |
2110 | } | |
2111 | } | |
2112 | ||
2113 | *attrptr = '\0'; | |
2114 | } | |
2115 | } | |
2116 | ||
bd7854cb | 2117 | /* |
2118 | * Populate the document-format-supported attribute... | |
2119 | */ | |
2120 | ||
2121 | add_printer_formats(p); | |
2122 | ||
ef416fc2 | 2123 | DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p->name, |
2124 | p->type)); | |
2125 | ||
b423cd4c | 2126 | /* |
2127 | * Add name-default attributes... | |
2128 | */ | |
2129 | ||
2130 | add_printer_defaults(p); | |
2131 | ||
ef416fc2 | 2132 | #ifdef __sgi |
2133 | /* | |
2134 | * Write the IRIX printer config and status files... | |
2135 | */ | |
2136 | ||
2137 | write_irix_config(p); | |
2138 | write_irix_state(p); | |
2139 | #endif /* __sgi */ | |
2140 | } | |
2141 | ||
2142 | ||
2143 | /* | |
2144 | * 'cupsdSetPrinterReasons()' - Set/update the reasons strings. | |
2145 | */ | |
2146 | ||
2147 | void | |
2148 | cupsdSetPrinterReasons( | |
2149 | cupsd_printer_t *p, /* I - Printer */ | |
2150 | const char *s) /* I - Reasons strings */ | |
2151 | { | |
2152 | int i; /* Looping var */ | |
2153 | const char *sptr; /* Pointer into reasons */ | |
2154 | char reason[255], /* Reason string */ | |
2155 | *rptr; /* Pointer into reason */ | |
2156 | ||
2157 | ||
2158 | if (s[0] == '-' || s[0] == '+') | |
2159 | { | |
2160 | /* | |
2161 | * Add/remove reasons... | |
2162 | */ | |
2163 | ||
2164 | sptr = s + 1; | |
2165 | } | |
2166 | else | |
2167 | { | |
2168 | /* | |
2169 | * Replace reasons... | |
2170 | */ | |
2171 | ||
2172 | sptr = s; | |
2173 | ||
2174 | for (i = 0; i < p->num_reasons; i ++) | |
2175 | free(p->reasons[i]); | |
2176 | ||
2177 | p->num_reasons = 0; | |
2178 | } | |
2179 | ||
2180 | /* | |
2181 | * Loop through all of the reasons... | |
2182 | */ | |
2183 | ||
2184 | while (*sptr) | |
2185 | { | |
2186 | /* | |
2187 | * Skip leading whitespace and commas... | |
2188 | */ | |
2189 | ||
2190 | while (isspace(*sptr & 255) || *sptr == ',') | |
2191 | sptr ++; | |
2192 | ||
2193 | for (rptr = reason; *sptr && !isspace(*sptr & 255) && *sptr != ','; sptr ++) | |
2194 | if (rptr < (reason + sizeof(reason) - 1)) | |
2195 | *rptr++ = *sptr; | |
2196 | ||
2197 | if (rptr == reason) | |
2198 | break; | |
2199 | ||
2200 | *rptr = '\0'; | |
2201 | ||
2202 | if (s[0] == '-') | |
2203 | { | |
2204 | /* | |
2205 | * Remove reason... | |
2206 | */ | |
2207 | ||
2208 | for (i = 0; i < p->num_reasons; i ++) | |
2209 | if (!strcasecmp(reason, p->reasons[i])) | |
2210 | { | |
2211 | /* | |
2212 | * Found a match, so remove it... | |
2213 | */ | |
2214 | ||
2215 | p->num_reasons --; | |
2216 | free(p->reasons[i]); | |
2217 | ||
2218 | if (i < p->num_reasons) | |
2219 | memmove(p->reasons + i, p->reasons + i + 1, | |
2220 | (p->num_reasons - i) * sizeof(char *)); | |
2221 | ||
2222 | i --; | |
2223 | } | |
2224 | } | |
2225 | else if (p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0]))) | |
2226 | { | |
2227 | /* | |
2228 | * Add reason... | |
2229 | */ | |
2230 | ||
2231 | for (i = 0; i < p->num_reasons; i ++) | |
2232 | if (!strcasecmp(reason, p->reasons[i])) | |
2233 | break; | |
2234 | ||
2235 | if (i >= p->num_reasons) | |
2236 | { | |
2237 | p->reasons[i] = strdup(reason); | |
2238 | p->num_reasons ++; | |
2239 | } | |
2240 | } | |
2241 | } | |
2242 | } | |
2243 | ||
2244 | ||
2245 | /* | |
2246 | * 'cupsdSetPrinterState()' - Update the current state of a printer. | |
2247 | */ | |
2248 | ||
2249 | void | |
2250 | cupsdSetPrinterState( | |
2251 | cupsd_printer_t *p, /* I - Printer to change */ | |
2252 | ipp_pstate_t s, /* I - New state */ | |
2253 | int update) /* I - Update printers.conf? */ | |
2254 | { | |
2255 | ipp_pstate_t old_state; /* Old printer state */ | |
2256 | ||
2257 | ||
2258 | /* | |
2259 | * Can't set status of remote printers... | |
2260 | */ | |
2261 | ||
2262 | if (p->type & CUPS_PRINTER_REMOTE) | |
2263 | return; | |
2264 | ||
2265 | /* | |
2266 | * Set the new state... | |
2267 | */ | |
2268 | ||
2269 | old_state = p->state; | |
2270 | p->state = s; | |
2271 | ||
2272 | if (old_state != s) | |
2273 | { | |
e53920b9 | 2274 | cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED, p, NULL, |
2275 | "%s \"%s\" state changed.", | |
2276 | (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer", | |
2277 | p->name); | |
2278 | ||
ef416fc2 | 2279 | /* |
2280 | * Let the browse code know this needs to be updated... | |
2281 | */ | |
2282 | ||
2283 | BrowseNext = p; | |
2284 | p->state_time = time(NULL); | |
2285 | p->browse_time = 0; | |
2286 | ||
2287 | #ifdef __sgi | |
2288 | write_irix_state(p); | |
2289 | #endif /* __sgi */ | |
2290 | } | |
2291 | ||
2292 | cupsdAddPrinterHistory(p); | |
2293 | ||
2294 | /* | |
2295 | * Save the printer configuration if a printer goes from idle or processing | |
2296 | * to stopped (or visa-versa)... | |
2297 | */ | |
2298 | ||
2299 | if ((old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED) && | |
2300 | update) | |
2301 | { | |
2302 | if (p->type & CUPS_PRINTER_CLASS) | |
2303 | cupsdSaveAllClasses(); | |
2304 | else | |
2305 | cupsdSaveAllPrinters(); | |
2306 | } | |
2307 | } | |
2308 | ||
2309 | ||
2310 | /* | |
2311 | * 'cupsdStopPrinter()' - Stop a printer from printing any jobs... | |
2312 | */ | |
2313 | ||
2314 | void | |
2315 | cupsdStopPrinter(cupsd_printer_t *p, /* I - Printer to stop */ | |
2316 | int update)/* I - Update printers.conf? */ | |
2317 | { | |
2318 | cupsd_job_t *job; /* Active print job */ | |
2319 | ||
2320 | ||
2321 | /* | |
2322 | * Set the printer state... | |
2323 | */ | |
2324 | ||
2325 | cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, update); | |
2326 | ||
2327 | /* | |
2328 | * See if we have a job printing on this printer... | |
2329 | */ | |
2330 | ||
2331 | if (p->job) | |
2332 | { | |
2333 | /* | |
2334 | * Get pointer to job... | |
2335 | */ | |
2336 | ||
2337 | job = (cupsd_job_t *)p->job; | |
2338 | ||
2339 | /* | |
2340 | * Stop it... | |
2341 | */ | |
2342 | ||
2343 | cupsdStopJob(job, 0); | |
2344 | ||
2345 | /* | |
2346 | * Reset the state to pending... | |
2347 | */ | |
2348 | ||
2349 | job->state->values[0].integer = IPP_JOB_PENDING; | |
bd7854cb | 2350 | job->state_value = IPP_JOB_PENDING; |
ef416fc2 | 2351 | |
2352 | cupsdSaveJob(job); | |
2353 | } | |
2354 | } | |
2355 | ||
2356 | ||
2357 | /* | |
2358 | * 'cupsdUpdatePrinters()' - Update printers after a partial reload. | |
2359 | */ | |
2360 | ||
2361 | void | |
2362 | cupsdUpdatePrinters(void) | |
2363 | { | |
2364 | cupsd_printer_t *p; /* Current printer */ | |
2365 | ||
2366 | ||
2367 | /* | |
2368 | * Loop through the printers and recreate the printer attributes | |
2369 | * for any local printers since the policy and/or access control | |
2370 | * stuff may have changed. Also, if browsing is disabled, remove | |
2371 | * any remote printers... | |
2372 | */ | |
2373 | ||
2374 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
2375 | p; | |
2376 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
2377 | { | |
2378 | if (!Browsing && (p->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_REMOTE))) | |
2379 | { | |
2380 | if (p->type & CUPS_PRINTER_IMPLICIT) | |
2381 | cupsArrayRemove(ImplicitPrinters, p); | |
2382 | ||
2383 | cupsArraySave(Printers); | |
2384 | cupsdDeletePrinter(p, 0); | |
2385 | cupsArrayRestore(Printers); | |
2386 | continue; | |
2387 | } | |
2388 | else if (!(p->type & CUPS_PRINTER_REMOTE)) | |
2389 | cupsdSetPrinterAttrs(p); | |
2390 | ||
2391 | /* | |
2392 | * Update the operation policy pointer... | |
2393 | */ | |
2394 | ||
2395 | if ((p->op_policy_ptr = cupsdFindPolicy(p->op_policy)) == NULL) | |
2396 | p->op_policy_ptr = DefaultPolicyPtr; | |
2397 | } | |
2398 | } | |
2399 | ||
2400 | ||
2401 | /* | |
2402 | * 'cupsdValidateDest()' - Validate a printer/class destination. | |
2403 | */ | |
2404 | ||
2405 | const char * /* O - Printer or class name */ | |
2406 | cupsdValidateDest( | |
2407 | const char *hostname, /* I - Host name */ | |
2408 | const char *resource, /* I - Resource name */ | |
2409 | cups_ptype_t *dtype, /* O - Type (printer or class) */ | |
2410 | cupsd_printer_t **printer) /* O - Printer pointer */ | |
2411 | { | |
2412 | cupsd_printer_t *p; /* Current printer */ | |
2413 | char localname[1024],/* Localized hostname */ | |
2414 | *lptr, /* Pointer into localized hostname */ | |
2415 | *sptr; /* Pointer into server name */ | |
2416 | ||
2417 | ||
2418 | DEBUG_printf(("cupsdValidateDest(\"%s\", \"%s\", %p, %p)\n", hostname, resource, | |
2419 | dtype, printer)); | |
2420 | ||
2421 | /* | |
2422 | * Initialize return values... | |
2423 | */ | |
2424 | ||
2425 | if (printer) | |
2426 | *printer = NULL; | |
2427 | ||
2428 | *dtype = (cups_ptype_t)0; | |
2429 | ||
2430 | /* | |
2431 | * See if the resource is a class or printer... | |
2432 | */ | |
2433 | ||
2434 | if (!strncmp(resource, "/classes/", 9)) | |
2435 | { | |
2436 | /* | |
2437 | * Class... | |
2438 | */ | |
2439 | ||
2440 | resource += 9; | |
2441 | } | |
2442 | else if (!strncmp(resource, "/printers/", 10)) | |
2443 | { | |
2444 | /* | |
2445 | * Printer... | |
2446 | */ | |
2447 | ||
2448 | resource += 10; | |
2449 | } | |
2450 | else | |
2451 | { | |
2452 | /* | |
2453 | * Bad resource name... | |
2454 | */ | |
2455 | ||
2456 | return (NULL); | |
2457 | } | |
2458 | ||
2459 | /* | |
2460 | * See if the printer or class name exists... | |
2461 | */ | |
2462 | ||
2463 | p = cupsdFindDest(resource); | |
2464 | ||
2465 | if (p == NULL && strchr(resource, '@') == NULL) | |
2466 | return (NULL); | |
2467 | else if (p != NULL) | |
2468 | { | |
2469 | if (printer) | |
2470 | *printer = p; | |
2471 | ||
2472 | *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT | | |
2473 | CUPS_PRINTER_REMOTE); | |
2474 | return (p->name); | |
2475 | } | |
2476 | ||
2477 | /* | |
2478 | * Change localhost to the server name... | |
2479 | */ | |
2480 | ||
2481 | if (!strcasecmp(hostname, "localhost")) | |
2482 | hostname = ServerName; | |
2483 | ||
2484 | strlcpy(localname, hostname, sizeof(localname)); | |
2485 | ||
2486 | if (!strcasecmp(hostname, ServerName)) | |
2487 | { | |
2488 | /* | |
2489 | * Localize the hostname... | |
2490 | */ | |
2491 | ||
2492 | lptr = strchr(localname, '.'); | |
2493 | sptr = strchr(ServerName, '.'); | |
2494 | ||
2495 | if (sptr != NULL && lptr != NULL) | |
2496 | { | |
2497 | /* | |
2498 | * Strip the common domain name components... | |
2499 | */ | |
2500 | ||
2501 | while (lptr != NULL) | |
2502 | { | |
2503 | if (!strcasecmp(lptr, sptr)) | |
2504 | { | |
2505 | *lptr = '\0'; | |
2506 | break; | |
2507 | } | |
2508 | else | |
2509 | lptr = strchr(lptr + 1, '.'); | |
2510 | } | |
2511 | } | |
2512 | } | |
2513 | ||
2514 | DEBUG_printf(("localized hostname is \"%s\"...\n", localname)); | |
2515 | ||
2516 | /* | |
2517 | * Find a matching printer or class... | |
2518 | */ | |
2519 | ||
2520 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
2521 | p; | |
2522 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
2523 | if (!strcasecmp(p->hostname, localname) && | |
2524 | !strcasecmp(p->name, resource)) | |
2525 | { | |
2526 | if (printer) | |
2527 | *printer = p; | |
2528 | ||
2529 | *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT | | |
2530 | CUPS_PRINTER_REMOTE); | |
2531 | return (p->name); | |
2532 | } | |
2533 | ||
2534 | return (NULL); | |
2535 | } | |
2536 | ||
2537 | ||
2538 | /* | |
2539 | * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications | |
2540 | * that need it... | |
2541 | */ | |
2542 | ||
2543 | void | |
2544 | cupsdWritePrintcap(void) | |
2545 | { | |
2546 | cups_file_t *fp; /* printcap file */ | |
2547 | cupsd_printer_t *p; /* Current printer */ | |
2548 | ||
2549 | ||
2550 | #ifdef __sgi | |
2551 | /* | |
2552 | * Update the IRIX printer state for the default printer; if | |
2553 | * no printers remain, then the default printer file will be | |
2554 | * removed... | |
2555 | */ | |
2556 | ||
2557 | write_irix_state(DefaultPrinter); | |
2558 | #endif /* __sgi */ | |
2559 | ||
2560 | /* | |
2561 | * See if we have a printcap file; if not, don't bother writing it. | |
2562 | */ | |
2563 | ||
2564 | if (!Printcap || !*Printcap) | |
2565 | return; | |
2566 | ||
2567 | /* | |
2568 | * Open the printcap file... | |
2569 | */ | |
2570 | ||
2571 | if ((fp = cupsFileOpen(Printcap, "w")) == NULL) | |
2572 | return; | |
2573 | ||
2574 | /* | |
2575 | * Put a comment header at the top so that users will know where the | |
2576 | * data has come from... | |
2577 | */ | |
2578 | ||
2579 | cupsFilePuts(fp, "# This file was automatically generated by cupsd(8) from the\n"); | |
2580 | cupsFilePrintf(fp, "# %s/printers.conf file. All changes to this file\n", | |
2581 | ServerRoot); | |
2582 | cupsFilePuts(fp, "# will be lost.\n"); | |
2583 | ||
2584 | if (Printers) | |
2585 | { | |
2586 | /* | |
2587 | * Write a new printcap with the current list of printers. | |
2588 | */ | |
2589 | ||
2590 | switch (PrintcapFormat) | |
2591 | { | |
2592 | case PRINTCAP_BSD: | |
2593 | /* | |
2594 | * Each printer is put in the file as: | |
2595 | * | |
2596 | * Printer1: | |
2597 | * Printer2: | |
2598 | * Printer3: | |
2599 | * ... | |
2600 | * PrinterN: | |
2601 | */ | |
2602 | ||
2603 | if (DefaultPrinter) | |
2604 | cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name, | |
2605 | DefaultPrinter->info, ServerName, DefaultPrinter->name); | |
2606 | ||
2607 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
2608 | p; | |
2609 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
2610 | if (p != DefaultPrinter) | |
2611 | cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info, | |
2612 | ServerName, p->name); | |
2613 | break; | |
2614 | ||
2615 | case PRINTCAP_SOLARIS: | |
2616 | /* | |
2617 | * Each printer is put in the file as: | |
2618 | * | |
2619 | * _all:all=Printer1,Printer2,Printer3,...,PrinterN | |
2620 | * _default:use=DefaultPrinter | |
2621 | * Printer1:\ | |
2622 | * :bsdaddr=ServerName,Printer1:\ | |
2623 | * :description=Description: | |
2624 | * Printer2: | |
2625 | * :bsdaddr=ServerName,Printer2:\ | |
2626 | * :description=Description: | |
2627 | * Printer3: | |
2628 | * :bsdaddr=ServerName,Printer3:\ | |
2629 | * :description=Description: | |
2630 | * ... | |
2631 | * PrinterN: | |
2632 | * :bsdaddr=ServerName,PrinterN:\ | |
2633 | * :description=Description: | |
2634 | */ | |
2635 | ||
2636 | cupsFilePuts(fp, "_all:all="); | |
2637 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
2638 | p; | |
2639 | p = (cupsd_printer_t *)cupsArrayCurrent(Printers)) | |
2640 | cupsFilePrintf(fp, "%s%c", p->name, | |
2641 | cupsArrayNext(Printers) ? ',' : '\n'); | |
2642 | ||
2643 | if (DefaultPrinter) | |
2644 | cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name); | |
2645 | ||
2646 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
2647 | p; | |
2648 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
2649 | cupsFilePrintf(fp, "%s:\\\n" | |
2650 | "\t:bsdaddr=%s,%s:\\\n" | |
2651 | "\t:description=%s:\n", | |
2652 | p->name, ServerName, p->name, p->info ? p->info : ""); | |
2653 | break; | |
2654 | } | |
2655 | } | |
2656 | ||
2657 | /* | |
2658 | * Close the file... | |
2659 | */ | |
2660 | ||
2661 | cupsFileClose(fp); | |
2662 | } | |
2663 | ||
2664 | ||
2665 | /* | |
2666 | * 'cupsdSanitizeURI()' - Sanitize a device URI... | |
2667 | */ | |
2668 | ||
2669 | char * /* O - New device URI */ | |
2670 | cupsdSanitizeURI(const char *uri, /* I - Original device URI */ | |
2671 | char *buffer, /* O - New device URI */ | |
2672 | int buflen) /* I - Size of new device URI buffer */ | |
2673 | { | |
2674 | char *start, /* Start of data after scheme */ | |
2675 | *slash, /* First slash after scheme:// */ | |
2676 | *ptr; /* Pointer into user@host:port part */ | |
2677 | ||
2678 | ||
2679 | /* | |
2680 | * Range check input... | |
2681 | */ | |
2682 | ||
2683 | if (!uri || !buffer || buflen < 2) | |
2684 | return (NULL); | |
2685 | ||
2686 | /* | |
2687 | * Copy the device URI to the new buffer... | |
2688 | */ | |
2689 | ||
2690 | strlcpy(buffer, uri, buflen); | |
2691 | ||
2692 | /* | |
2693 | * Find the end of the scheme:// part... | |
2694 | */ | |
2695 | ||
2696 | if ((ptr = strchr(buffer, ':')) == NULL) | |
2697 | return (buffer); /* No scheme: part... */ | |
2698 | ||
2699 | for (start = ptr + 1; *start; start ++) | |
2700 | if (*start != '/') | |
2701 | break; | |
2702 | ||
2703 | /* | |
2704 | * Find the next slash (/) in the URI... | |
2705 | */ | |
2706 | ||
2707 | if ((slash = strchr(start, '/')) == NULL) | |
2708 | slash = start + strlen(start); /* No slash, point to the end */ | |
2709 | ||
2710 | /* | |
2711 | * Check for an @ sign before the slash... | |
2712 | */ | |
2713 | ||
2714 | if ((ptr = strchr(start, '@')) != NULL && ptr < slash) | |
2715 | { | |
2716 | /* | |
2717 | * Found an @ sign and it is before the resource part, so we have | |
2718 | * an authentication string. Copy the remaining URI over the | |
2719 | * authentication string... | |
2720 | */ | |
2721 | ||
2722 | _cups_strcpy(start, ptr + 1); | |
2723 | } | |
2724 | ||
2725 | /* | |
2726 | * Return the new device URI... | |
2727 | */ | |
2728 | ||
2729 | return (buffer); | |
2730 | } | |
2731 | ||
2732 | ||
b423cd4c | 2733 | /* |
2734 | * 'add_printer_defaults()' - Add name-default attributes to the printer attributes. | |
2735 | */ | |
2736 | ||
2737 | static void | |
2738 | add_printer_defaults(cupsd_printer_t *p)/* I - Printer */ | |
2739 | { | |
2740 | int i; /* Looping var */ | |
2741 | int num_options; /* Number of default options */ | |
2742 | cups_option_t *options, /* Default options */ | |
2743 | *option; /* Current option */ | |
2744 | char name[256]; /* name-default */ | |
2745 | ||
2746 | ||
2747 | /* | |
2748 | * Add all of the default options from the .conf files... | |
2749 | */ | |
2750 | ||
2751 | for (num_options = 0, i = p->num_options, option = p->options; | |
2752 | i > 0; | |
2753 | i --, option ++) | |
2754 | { | |
2755 | if (strcmp(option->name, "ipp-options") && | |
2756 | strcmp(option->name, "job-sheets") && | |
2757 | strcmp(option->name, "lease-duration")) | |
2758 | { | |
2759 | snprintf(name, sizeof(name), "%s-default", option->name); | |
2760 | num_options = cupsAddOption(name, option->value, num_options, &options); | |
2761 | } | |
2762 | } | |
2763 | ||
2764 | /* | |
2765 | * Convert options to IPP attributes... | |
2766 | */ | |
2767 | ||
2768 | cupsEncodeOptions2(p->attrs, num_options, options, IPP_TAG_PRINTER); | |
2769 | cupsFreeOptions(num_options, options); | |
2770 | ||
2771 | /* | |
2772 | * Add standard -default attributes as needed... | |
2773 | */ | |
2774 | ||
2775 | if (!cupsGetOption("copies", p->num_options, p->options)) | |
2776 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default", | |
2777 | 1); | |
2778 | ||
2779 | if (!cupsGetOption("job-hold-until", p->num_options, p->options)) | |
2780 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
2781 | "job-hold-until-default", NULL, "no-hold"); | |
2782 | ||
2783 | if (!cupsGetOption("job-priority", p->num_options, p->options)) | |
2784 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2785 | "job-priority-default", 50); | |
2786 | ||
2787 | if (!cupsGetOption("number-up", p->num_options, p->options)) | |
2788 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2789 | "number-up-default", 1); | |
2790 | ||
2791 | if (!cupsGetOption("orientation-requested", p->num_options, p->options)) | |
2792 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
2793 | "orientation-requested-default", IPP_PORTRAIT); | |
2794 | } | |
2795 | ||
2796 | ||
bd7854cb | 2797 | /* |
2798 | * 'add_printer_filter()' - Add a MIME filter for a printer. | |
2799 | */ | |
2800 | ||
2801 | static void | |
2802 | add_printer_filter( | |
2803 | cupsd_printer_t *p, /* I - Printer to add to */ | |
2804 | const char *filter) /* I - Filter to add */ | |
2805 | { | |
2806 | char super[MIME_MAX_SUPER], /* Super-type for filter */ | |
2807 | type[MIME_MAX_TYPE], /* Type for filter */ | |
2808 | program[1024]; /* Program/filter name */ | |
2809 | int cost; /* Cost of filter */ | |
2810 | mime_type_t *temptype; /* MIME type looping var */ | |
2811 | char filename[1024]; /* Full filter filename */ | |
2812 | ||
2813 | ||
2814 | /* | |
2815 | * Parse the filter string; it should be in the following format: | |
2816 | * | |
2817 | * super/type cost program | |
2818 | */ | |
2819 | ||
2820 | if (sscanf(filter, "%15[^/]/%31s%d%1023s", super, type, &cost, program) != 4) | |
2821 | { | |
2822 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!", | |
2823 | p->name, filter); | |
2824 | return; | |
2825 | } | |
2826 | ||
2827 | /* | |
2828 | * See if the filter program exists; if not, stop the printer and flag | |
2829 | * the error! | |
2830 | */ | |
2831 | ||
ecdc0628 | 2832 | if (strcmp(program, "-")) |
bd7854cb | 2833 | { |
ecdc0628 | 2834 | if (program[0] == '/') |
2835 | strlcpy(filename, program, sizeof(filename)); | |
2836 | else | |
2837 | snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program); | |
2838 | ||
2839 | if (access(filename, X_OK)) | |
2840 | { | |
2841 | snprintf(p->state_message, sizeof(p->state_message), | |
2842 | "Filter \"%s\" for printer \"%s\" not available: %s", | |
2843 | program, p->name, strerror(errno)); | |
2844 | cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 0); | |
2845 | cupsdSetPrinterReasons(p, "+cups-missing-filter-error"); | |
2846 | cupsdAddPrinterHistory(p); | |
2847 | ||
2848 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s", p->state_message); | |
2849 | } | |
bd7854cb | 2850 | } |
2851 | ||
b423cd4c | 2852 | /* |
2853 | * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for | |
2854 | * application/vnd.cups-command... | |
2855 | */ | |
2856 | ||
2857 | if (!strcasecmp(super, "application") && | |
2858 | !strcasecmp(type, "vnd.cups-command")) | |
2859 | p->type |= CUPS_PRINTER_COMMANDS; | |
2860 | ||
bd7854cb | 2861 | /* |
2862 | * Add the filter to the MIME database, supporting wildcards as needed... | |
2863 | */ | |
2864 | ||
2865 | for (temptype = mimeFirstType(MimeDatabase); | |
2866 | temptype; | |
2867 | temptype = mimeNextType(MimeDatabase)) | |
2868 | if (((super[0] == '*' && strcasecmp(temptype->super, "printer")) || | |
2869 | !strcasecmp(temptype->super, super)) && | |
2870 | (type[0] == '*' || !strcasecmp(temptype->type, type))) | |
2871 | { | |
2872 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
2873 | "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s", | |
2874 | p->name, temptype->super, temptype->type, | |
2875 | p->filetype->super, p->filetype->type, | |
2876 | cost, program); | |
2877 | mimeAddFilter(MimeDatabase, temptype, p->filetype, cost, program); | |
2878 | } | |
2879 | } | |
2880 | ||
2881 | ||
2882 | /* | |
2883 | * 'add_printer_formats()' - Add document-format-supported values for a printer. | |
2884 | */ | |
2885 | ||
2886 | static void | |
2887 | add_printer_formats(cupsd_printer_t *p) /* I - Printer */ | |
2888 | { | |
2889 | int i; /* Looping var */ | |
2890 | mime_type_t *type; /* Current MIME type */ | |
2891 | cups_array_t *filters; /* Filters */ | |
80ca4592 | 2892 | ipp_attribute_t *attr; /* document-format-supported attribute */ |
bd7854cb | 2893 | char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2]; |
2894 | /* MIME type name */ | |
2895 | ||
2896 | ||
2897 | /* | |
2898 | * Raw (and remote) queues advertise all of the supported MIME | |
2899 | * types... | |
2900 | */ | |
2901 | ||
80ca4592 | 2902 | cupsArrayDelete(p->filetypes); |
2903 | p->filetypes = NULL; | |
2904 | ||
bd7854cb | 2905 | if (p->raw) |
2906 | { | |
2907 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, | |
2908 | (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY), | |
2909 | "document-format-supported", NumMimeTypes, NULL, MimeTypes); | |
2910 | return; | |
2911 | } | |
2912 | ||
2913 | /* | |
2914 | * Otherwise, loop through the supported MIME types and see if there | |
2915 | * are filters for them... | |
2916 | */ | |
2917 | ||
bd7854cb | 2918 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters", |
2919 | mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase)); | |
2920 | ||
80ca4592 | 2921 | p->filetypes = cupsArrayNew(NULL, NULL); |
bd7854cb | 2922 | |
80ca4592 | 2923 | for (type = mimeFirstType(MimeDatabase); |
bd7854cb | 2924 | type; |
2925 | type = mimeNextType(MimeDatabase)) | |
2926 | { | |
2927 | if (!strcasecmp(type->super, "application") && | |
2928 | !strcasecmp(type->type, "octet-stream")) | |
2929 | continue; | |
2930 | ||
2931 | snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type); | |
2932 | ||
2933 | if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL) | |
2934 | { | |
2935 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
2936 | "add_printer_formats: %s: %s needs %d filters", | |
2937 | p->name, mimetype, cupsArrayCount(filters)); | |
2938 | ||
2939 | cupsArrayDelete(filters); | |
80ca4592 | 2940 | cupsArrayAdd(p->filetypes, type); |
bd7854cb | 2941 | } |
2942 | else | |
2943 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
2944 | "add_printer_formats: %s: %s not supported", | |
2945 | p->name, mimetype); | |
2946 | } | |
2947 | ||
2948 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
2949 | "add_printer_formats: %s: %d supported types", | |
80ca4592 | 2950 | p->name, cupsArrayCount(p->filetypes) + 1); |
bd7854cb | 2951 | |
2952 | /* | |
2953 | * Add the file formats that can be filtered... | |
2954 | */ | |
2955 | ||
bd7854cb | 2956 | |
80ca4592 | 2957 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE, |
2958 | "document-format-supported", | |
2959 | cupsArrayCount(p->filetypes) + 1, NULL, NULL); | |
2960 | ||
2961 | attr->values[0].string.text = _cupsStrAlloc("application/octet-stream"); | |
bd7854cb | 2962 | |
80ca4592 | 2963 | for (i = 1, type = (mime_type_t *)cupsArrayFirst(p->filetypes); |
2964 | type; | |
2965 | i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes)) | |
2966 | { | |
2967 | snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type); | |
bd7854cb | 2968 | |
80ca4592 | 2969 | attr->values[i].string.text = _cupsStrAlloc(mimetype); |
2970 | } | |
bd7854cb | 2971 | } |
2972 | ||
2973 | ||
ef416fc2 | 2974 | /* |
2975 | * 'compare_printers()' - Compare two printers. | |
2976 | */ | |
2977 | ||
2978 | static int /* O - Result of comparison */ | |
2979 | compare_printers(void *first, /* I - First printer */ | |
2980 | void *second, /* I - Second printer */ | |
2981 | void *data) /* I - App data (not used) */ | |
2982 | { | |
2983 | return (strcasecmp(((cupsd_printer_t *)first)->name, | |
2984 | ((cupsd_printer_t *)second)->name)); | |
2985 | } | |
2986 | ||
2987 | ||
bd7854cb | 2988 | /* |
e1d6a774 | 2989 | * 'delete_printer_filters()' - Delete all MIME filters for a printer. |
bd7854cb | 2990 | */ |
2991 | ||
2992 | static void | |
e1d6a774 | 2993 | delete_printer_filters( |
2994 | cupsd_printer_t *p) /* I - Printer to remove from */ | |
bd7854cb | 2995 | { |
e1d6a774 | 2996 | mime_filter_t *filter; /* MIME filter looping var */ |
bd7854cb | 2997 | |
bd7854cb | 2998 | |
2999 | /* | |
e1d6a774 | 3000 | * Range check input... |
bd7854cb | 3001 | */ |
3002 | ||
e1d6a774 | 3003 | if (p == NULL) |
3004 | return; | |
bd7854cb | 3005 | |
3006 | /* | |
e1d6a774 | 3007 | * Remove all filters from the MIME database that have a destination |
3008 | * type == printer... | |
bd7854cb | 3009 | */ |
3010 | ||
e1d6a774 | 3011 | for (filter = mimeFirstFilter(MimeDatabase); |
3012 | filter; | |
3013 | filter = mimeNextFilter(MimeDatabase)) | |
3014 | if (filter->dst == p->filetype) | |
3015 | { | |
3016 | /* | |
3017 | * Delete the current filter... | |
3018 | */ | |
bd7854cb | 3019 | |
e1d6a774 | 3020 | mimeDeleteFilter(MimeDatabase, filter); |
3021 | } | |
bd7854cb | 3022 | } |
3023 | ||
3024 | ||
ef416fc2 | 3025 | #ifdef __sgi |
3026 | /* | |
3027 | * 'write_irix_config()' - Update the config files used by the IRIX | |
3028 | * desktop tools. | |
3029 | */ | |
3030 | ||
3031 | static void | |
3032 | write_irix_config(cupsd_printer_t *p) /* I - Printer to update */ | |
3033 | { | |
3034 | char filename[1024]; /* Interface script filename */ | |
3035 | cups_file_t *fp; /* Interface script file */ | |
3036 | ||
3037 | ||
3038 | ||
3039 | /* | |
3040 | * Add dummy interface and GUI scripts to fool SGI's "challenged" printing | |
3041 | * tools. First the interface script that tells the tools what kind of | |
3042 | * printer we have... | |
3043 | */ | |
3044 | ||
3045 | snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name); | |
3046 | ||
3047 | if (p->type & CUPS_PRINTER_CLASS) | |
3048 | unlink(filename); | |
3049 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
3050 | { | |
3051 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
3052 | ||
3053 | if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model", | |
3054 | IPP_TAG_TEXT)) != NULL) | |
3055 | cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text); | |
3056 | else if (p->type & CUPS_PRINTER_CLASS) | |
3057 | cupsFilePuts(fp, "NAME=\"Printer Class\"\n"); | |
3058 | else | |
3059 | cupsFilePuts(fp, "NAME=\"Remote Destination\"\n"); | |
3060 | ||
3061 | if (p->type & CUPS_PRINTER_COLOR) | |
3062 | cupsFilePuts(fp, "TYPE=ColorPostScript\n"); | |
3063 | else | |
3064 | cupsFilePuts(fp, "TYPE=MonoPostScript\n"); | |
3065 | ||
3066 | cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName); | |
3067 | cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name); | |
3068 | ||
3069 | cupsFileClose(fp); | |
3070 | ||
3071 | chmod(filename, 0755); | |
3072 | chown(filename, User, Group); | |
3073 | } | |
3074 | ||
3075 | /* | |
3076 | * Then the member file that tells which device file the queue is connected | |
3077 | * to... Networked printers use "/dev/null" in this file, so that's what | |
3078 | * we use (the actual device URI can confuse some apps...) | |
3079 | */ | |
3080 | ||
3081 | snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name); | |
3082 | ||
3083 | if (p->type & CUPS_PRINTER_CLASS) | |
3084 | unlink(filename); | |
3085 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
3086 | { | |
3087 | cupsFilePuts(fp, "/dev/null\n"); | |
3088 | ||
3089 | cupsFileClose(fp); | |
3090 | ||
3091 | chmod(filename, 0644); | |
3092 | chown(filename, User, Group); | |
3093 | } | |
3094 | ||
3095 | /* | |
3096 | * The gui_interface file is a script or program that launches a GUI | |
3097 | * option panel for the printer, using options specified on the | |
3098 | * command-line in the third argument. The option panel must send | |
3099 | * any printing options to stdout on a single line when the user | |
3100 | * accepts them, or nothing if the user cancels the dialog. | |
3101 | * | |
3102 | * The default options panel program is /usr/bin/glpoptions, from | |
3103 | * the ESP Print Pro software. You can select another using the | |
3104 | * PrintcapGUI option. | |
3105 | */ | |
3106 | ||
3107 | snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", p->name); | |
3108 | ||
3109 | if (p->type & CUPS_PRINTER_CLASS) | |
3110 | unlink(filename); | |
3111 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
3112 | { | |
3113 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
3114 | cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name); | |
3115 | ||
3116 | cupsFileClose(fp); | |
3117 | ||
3118 | chmod(filename, 0755); | |
3119 | chown(filename, User, Group); | |
3120 | } | |
3121 | ||
3122 | /* | |
3123 | * The POD config file is needed by the printstatus command to show | |
3124 | * the printer location and device. | |
3125 | */ | |
3126 | ||
3127 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name); | |
3128 | ||
3129 | if (p->type & CUPS_PRINTER_CLASS) | |
3130 | unlink(filename); | |
3131 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
3132 | { | |
3133 | cupsFilePrintf(fp, "Printer Class | %s\n", | |
3134 | (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript"); | |
3135 | cupsFilePrintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : ""); | |
3136 | cupsFilePrintf(fp, "Location Code | %s\n", p->location ? p->location : ""); | |
3137 | cupsFilePrintf(fp, "Physical Location | %s\n", p->info ? p->info : ""); | |
3138 | cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri ? p->device_uri : ""); | |
3139 | cupsFilePrintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name); | |
3140 | cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name); | |
3141 | cupsFilePuts(fp, "Status Update Wait | 10 seconds\n"); | |
3142 | ||
3143 | cupsFileClose(fp); | |
3144 | ||
3145 | chmod(filename, 0664); | |
3146 | chown(filename, User, Group); | |
3147 | } | |
3148 | } | |
3149 | ||
3150 | ||
3151 | /* | |
3152 | * 'write_irix_state()' - Update the status files used by IRIX printing | |
3153 | * desktop tools. | |
3154 | */ | |
3155 | ||
3156 | static void | |
3157 | write_irix_state(cupsd_printer_t *p) /* I - Printer to update */ | |
3158 | { | |
3159 | char filename[1024]; /* Interface script filename */ | |
3160 | cups_file_t *fp; /* Interface script file */ | |
3161 | int tag; /* Status tag value */ | |
3162 | ||
3163 | ||
3164 | if (p) | |
3165 | { | |
3166 | /* | |
3167 | * The POD status file is needed for the printstatus window to | |
3168 | * provide the current status of the printer. | |
3169 | */ | |
3170 | ||
3171 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name); | |
3172 | ||
3173 | if (p->type & CUPS_PRINTER_CLASS) | |
3174 | unlink(filename); | |
3175 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
3176 | { | |
3177 | cupsFilePrintf(fp, "Operational Status | %s\n", | |
3178 | (p->state == IPP_PRINTER_IDLE) ? "Idle" : | |
3179 | (p->state == IPP_PRINTER_PROCESSING) ? "Busy" : | |
3180 | "Faulted"); | |
3181 | cupsFilePrintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION); | |
3182 | cupsFilePrintf(fp, "Information | 02 00 00 | Device URI: %s\n", | |
3183 | p->device_uri ? p->device_uri : ""); | |
3184 | cupsFilePrintf(fp, "Information | 03 00 00 | %s jobs\n", | |
3185 | p->accepting ? "Accepting" : "Not accepting"); | |
3186 | cupsFilePrintf(fp, "Information | 04 00 00 | %s\n", p->state_message); | |
3187 | ||
3188 | cupsFileClose(fp); | |
3189 | ||
3190 | chmod(filename, 0664); | |
3191 | chown(filename, User, Group); | |
3192 | } | |
3193 | ||
3194 | /* | |
3195 | * The activeicons file is needed to provide desktop icons for printers: | |
3196 | * | |
3197 | * [ quoted from /usr/lib/print/tagit ] | |
3198 | * | |
3199 | * --- Type of printer tags (base values) | |
3200 | * | |
3201 | * Dumb=66048 # 0x10200 | |
3202 | * DumbColor=66080 # 0x10220 | |
3203 | * Raster=66112 # 0x10240 | |
3204 | * ColorRaster=66144 # 0x10260 | |
3205 | * Plotter=66176 # 0x10280 | |
3206 | * PostScript=66208 # 0x102A0 | |
3207 | * ColorPostScript=66240 # 0x102C0 | |
3208 | * MonoPostScript=66272 # 0x102E0 | |
3209 | * | |
3210 | * --- Printer state modifiers for local printers | |
3211 | * | |
3212 | * Idle=0 # 0x0 | |
3213 | * Busy=1 # 0x1 | |
3214 | * Faulted=2 # 0x2 | |
3215 | * Unknown=3 # 0x3 (Faulted due to unknown reason) | |
3216 | * | |
3217 | * --- Printer state modifiers for network printers | |
3218 | * | |
3219 | * NetIdle=8 # 0x8 | |
3220 | * NetBusy=9 # 0x9 | |
3221 | * NetFaulted=10 # 0xA | |
3222 | * NetUnknown=11 # 0xB (Faulted due to unknown reason) | |
3223 | */ | |
3224 | ||
3225 | snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name); | |
3226 | ||
3227 | if (p->type & CUPS_PRINTER_CLASS) | |
3228 | unlink(filename); | |
3229 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
3230 | { | |
3231 | if (p->type & CUPS_PRINTER_COLOR) | |
3232 | tag = 66240; | |
3233 | else | |
3234 | tag = 66272; | |
3235 | ||
3236 | if (p->type & CUPS_PRINTER_REMOTE) | |
3237 | tag |= 8; | |
3238 | ||
3239 | if (p->state == IPP_PRINTER_PROCESSING) | |
3240 | tag |= 1; | |
3241 | ||
3242 | else if (p->state == IPP_PRINTER_STOPPED) | |
3243 | tag |= 2; | |
3244 | ||
3245 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
3246 | cupsFilePrintf(fp, "#Tag %d\n", tag); | |
3247 | ||
3248 | cupsFileClose(fp); | |
3249 | ||
3250 | chmod(filename, 0755); | |
3251 | chown(filename, User, Group); | |
3252 | } | |
3253 | } | |
3254 | ||
3255 | /* | |
3256 | * The default file is needed by the printers window to show | |
3257 | * the default printer. | |
3258 | */ | |
3259 | ||
3260 | snprintf(filename, sizeof(filename), "/var/spool/lp/default"); | |
3261 | ||
3262 | if (DefaultPrinter != NULL) | |
3263 | { | |
3264 | if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
3265 | { | |
3266 | cupsFilePrintf(fp, "%s\n", DefaultPrinter->name); | |
3267 | ||
3268 | cupsFileClose(fp); | |
3269 | ||
3270 | chmod(filename, 0644); | |
3271 | chown(filename, User, Group); | |
3272 | } | |
3273 | } | |
3274 | else | |
3275 | unlink(filename); | |
3276 | } | |
3277 | #endif /* __sgi */ | |
3278 | ||
3279 | ||
3280 | /* | |
a74454a7 | 3281 | * End of "$Id: printers.c 5491 2006-05-04 20:53:35Z mike $". |
ef416fc2 | 3282 | */ |