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