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