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