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