]>
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 | ||
52f6f666 MS |
1315 | if (!strcmp(value, "marker-change-time")) |
1316 | p->marker_time = atoi(valueptr); | |
1317 | else | |
1318 | cupsdSetPrinterAttr(p, value, valueptr); | |
20fbc903 MS |
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 ++) |
e6013cfa MS |
1547 | if (strcmp(printer->reasons[i], "connecting-to-device")) |
1548 | cupsFilePutConf(fp, "Reason", printer->reasons[i]); | |
58dc1933 | 1549 | |
61cf44e2 | 1550 | cupsFilePrintf(fp, "Type %d\n", printer->type); |
58dc1933 MS |
1551 | |
1552 | #ifdef HAVE_DNSSD | |
1553 | if (printer->product) | |
1554 | cupsFilePutConf(fp, "Product", printer->product); | |
1555 | #endif /* HAVE_DNSSD */ | |
1556 | ||
1557 | for (ptr = (char *)cupsArrayFirst(printer->filters); | |
1558 | ptr; | |
1559 | ptr = (char *)cupsArrayNext(printer->filters)) | |
1560 | cupsFilePutConf(fp, "Filter", ptr); | |
1561 | ||
1562 | for (ptr = (char *)cupsArrayFirst(printer->pre_filters); | |
1563 | ptr; | |
1564 | ptr = (char *)cupsArrayNext(printer->pre_filters)) | |
1565 | cupsFilePutConf(fp, "PreFilter", ptr); | |
0af14961 | 1566 | |
ef416fc2 | 1567 | if (printer->accepting) |
1568 | cupsFilePuts(fp, "Accepting Yes\n"); | |
1569 | else | |
1570 | cupsFilePuts(fp, "Accepting No\n"); | |
1571 | ||
1572 | if (printer->shared) | |
1573 | cupsFilePuts(fp, "Shared Yes\n"); | |
1574 | else | |
1575 | cupsFilePuts(fp, "Shared No\n"); | |
1576 | ||
58dc1933 MS |
1577 | snprintf(value, sizeof(value), "%s %s", printer->job_sheets[0], |
1578 | printer->job_sheets[1]); | |
1579 | cupsFilePutConf(fp, "JobSheets", value); | |
ef416fc2 | 1580 | |
1581 | cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period); | |
1582 | cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit); | |
1583 | cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit); | |
1584 | ||
1585 | for (i = 0; i < printer->num_users; i ++) | |
58dc1933 MS |
1586 | cupsFilePutConf(fp, printer->deny_users ? "DenyUser" : "AllowUser", |
1587 | printer->users[i]); | |
ef416fc2 | 1588 | |
1589 | if (printer->op_policy) | |
58dc1933 | 1590 | cupsFilePutConf(fp, "OpPolicy", printer->op_policy); |
ef416fc2 | 1591 | if (printer->error_policy) |
58dc1933 | 1592 | cupsFilePutConf(fp, "ErrorPolicy", printer->error_policy); |
ef416fc2 | 1593 | |
b423cd4c | 1594 | for (i = printer->num_options, option = printer->options; |
1595 | i > 0; | |
1596 | i --, option ++) | |
8922323b | 1597 | { |
58dc1933 MS |
1598 | snprintf(value, sizeof(value), "%s %s", option->name, option->value); |
1599 | cupsFilePutConf(fp, "Option", value); | |
8922323b | 1600 | } |
b423cd4c | 1601 | |
20fbc903 MS |
1602 | if ((marker = ippFindAttribute(printer->attrs, "marker-colors", |
1603 | IPP_TAG_NAME)) != NULL) | |
1604 | { | |
58dc1933 | 1605 | snprintf(value, sizeof(value), "%s ", marker->name); |
8922323b | 1606 | |
58dc1933 MS |
1607 | for (i = 0, ptr = value + strlen(value); |
1608 | i < marker->num_values && ptr < (value + sizeof(value) - 1); | |
1609 | i ++) | |
8922323b MS |
1610 | { |
1611 | if (i) | |
58dc1933 | 1612 | *ptr++ = ','; |
8922323b | 1613 | |
58dc1933 MS |
1614 | strlcpy(ptr, marker->values[i].string.text, |
1615 | value + sizeof(value) - ptr); | |
1616 | ptr += strlen(ptr); | |
8922323b MS |
1617 | } |
1618 | ||
58dc1933 MS |
1619 | *ptr = '\0'; |
1620 | cupsFilePutConf(fp, "Attribute", value); | |
20fbc903 MS |
1621 | } |
1622 | ||
1623 | if ((marker = ippFindAttribute(printer->attrs, "marker-levels", | |
1624 | IPP_TAG_INTEGER)) != NULL) | |
1625 | { | |
1626 | cupsFilePrintf(fp, "Attribute %s %d", marker->name, | |
1627 | marker->values[0].integer); | |
1628 | for (i = 1; i < marker->num_values; i ++) | |
1629 | cupsFilePrintf(fp, ",%d", marker->values[i].integer); | |
1630 | cupsFilePuts(fp, "\n"); | |
1631 | } | |
1632 | ||
ed6e7faf MS |
1633 | if ((marker = ippFindAttribute(printer->attrs, "marker-low-levels", |
1634 | IPP_TAG_INTEGER)) != NULL) | |
1635 | { | |
1636 | cupsFilePrintf(fp, "Attribute %s %d", marker->name, | |
1637 | marker->values[0].integer); | |
1638 | for (i = 1; i < marker->num_values; i ++) | |
1639 | cupsFilePrintf(fp, ",%d", marker->values[i].integer); | |
1640 | cupsFilePuts(fp, "\n"); | |
1641 | } | |
1642 | ||
1643 | if ((marker = ippFindAttribute(printer->attrs, "marker-high-levels", | |
1644 | IPP_TAG_INTEGER)) != NULL) | |
1645 | { | |
1646 | cupsFilePrintf(fp, "Attribute %s %d", marker->name, | |
1647 | marker->values[0].integer); | |
1648 | for (i = 1; i < marker->num_values; i ++) | |
1649 | cupsFilePrintf(fp, ",%d", marker->values[i].integer); | |
1650 | cupsFilePuts(fp, "\n"); | |
1651 | } | |
1652 | ||
75bd9771 MS |
1653 | if ((marker = ippFindAttribute(printer->attrs, "marker-message", |
1654 | IPP_TAG_TEXT)) != NULL) | |
1655 | { | |
58dc1933 MS |
1656 | snprintf(value, sizeof(value), "%s %s", marker->name, |
1657 | marker->values[0].string.text); | |
75bd9771 | 1658 | |
58dc1933 | 1659 | cupsFilePutConf(fp, "Attribute", value); |
75bd9771 MS |
1660 | } |
1661 | ||
20fbc903 MS |
1662 | if ((marker = ippFindAttribute(printer->attrs, "marker-names", |
1663 | IPP_TAG_NAME)) != 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 | ||
1683 | if ((marker = ippFindAttribute(printer->attrs, "marker-types", | |
1684 | IPP_TAG_KEYWORD)) != NULL) | |
1685 | { | |
58dc1933 | 1686 | snprintf(value, sizeof(value), "%s ", marker->name); |
8922323b | 1687 | |
58dc1933 MS |
1688 | for (i = 0, ptr = value + strlen(value); |
1689 | i < marker->num_values && ptr < (value + sizeof(value) - 1); | |
1690 | i ++) | |
8922323b MS |
1691 | { |
1692 | if (i) | |
58dc1933 | 1693 | *ptr++ = ','; |
8922323b | 1694 | |
58dc1933 MS |
1695 | strlcpy(ptr, marker->values[i].string.text, |
1696 | value + sizeof(value) - ptr); | |
1697 | ptr += strlen(ptr); | |
8922323b MS |
1698 | } |
1699 | ||
58dc1933 MS |
1700 | *ptr = '\0'; |
1701 | cupsFilePutConf(fp, "Attribute", value); | |
20fbc903 MS |
1702 | } |
1703 | ||
52f6f666 MS |
1704 | if (printer->marker_time) |
1705 | cupsFilePrintf(fp, "Attribute marker-change-time %ld\n", | |
1706 | (long)printer->marker_time); | |
1707 | ||
ef416fc2 | 1708 | cupsFilePuts(fp, "</Printer>\n"); |
1709 | ||
1710 | #ifdef __sgi | |
1711 | /* | |
1712 | * Make IRIX desktop & printer status happy | |
1713 | */ | |
1714 | ||
1715 | write_irix_state(printer); | |
1716 | #endif /* __sgi */ | |
1717 | } | |
1718 | ||
1719 | cupsFileClose(fp); | |
1720 | } | |
1721 | ||
1722 | ||
f7deaa1a | 1723 | /* |
1724 | * 'cupsdSetAuthInfoRequired()' - Set the required authentication info. | |
1725 | */ | |
1726 | ||
1727 | int /* O - 1 if value OK, 0 otherwise */ | |
1728 | cupsdSetAuthInfoRequired( | |
1729 | cupsd_printer_t *p, /* I - Printer */ | |
1730 | const char *values, /* I - Plain text value (or NULL) */ | |
1731 | ipp_attribute_t *attr) /* I - IPP attribute value (or NULL) */ | |
1732 | { | |
1733 | int i; /* Looping var */ | |
1734 | ||
1735 | ||
1736 | p->num_auth_info_required = 0; | |
1737 | ||
1738 | /* | |
1739 | * Do we have a plain text value? | |
1740 | */ | |
1741 | ||
1742 | if (values) | |
1743 | { | |
1744 | /* | |
1745 | * Yes, grab the keywords... | |
1746 | */ | |
1747 | ||
1748 | const char *end; /* End of current value */ | |
1749 | ||
1750 | ||
1751 | while (*values && p->num_auth_info_required < 4) | |
1752 | { | |
1753 | if ((end = strchr(values, ',')) == NULL) | |
1754 | end = values + strlen(values); | |
1755 | ||
f899b121 | 1756 | if ((end - values) == 4 && !strncmp(values, "none", 4)) |
f7deaa1a | 1757 | { |
1758 | if (p->num_auth_info_required != 0 || *end) | |
1759 | return (0); | |
1760 | ||
1761 | p->auth_info_required[p->num_auth_info_required] = "none"; | |
1762 | p->num_auth_info_required ++; | |
1763 | ||
1764 | return (1); | |
1765 | } | |
f899b121 | 1766 | else if ((end - values) == 9 && !strncmp(values, "negotiate", 9)) |
1767 | { | |
1768 | if (p->num_auth_info_required != 0 || *end) | |
1769 | return (0); | |
1770 | ||
1771 | p->auth_info_required[p->num_auth_info_required] = "negotiate"; | |
1772 | p->num_auth_info_required ++; | |
f899b121 | 1773 | } |
1774 | else if ((end - values) == 6 && !strncmp(values, "domain", 6)) | |
f7deaa1a | 1775 | { |
1776 | p->auth_info_required[p->num_auth_info_required] = "domain"; | |
1777 | p->num_auth_info_required ++; | |
1778 | } | |
f899b121 | 1779 | else if ((end - values) == 8 && !strncmp(values, "password", 8)) |
f7deaa1a | 1780 | { |
1781 | p->auth_info_required[p->num_auth_info_required] = "password"; | |
1782 | p->num_auth_info_required ++; | |
1783 | } | |
f899b121 | 1784 | else if ((end - values) == 8 && !strncmp(values, "username", 8)) |
f7deaa1a | 1785 | { |
1786 | p->auth_info_required[p->num_auth_info_required] = "username"; | |
1787 | p->num_auth_info_required ++; | |
1788 | } | |
1789 | else | |
1790 | return (0); | |
09a101d6 | 1791 | |
1792 | values = (*end) ? end + 1 : end; | |
f7deaa1a | 1793 | } |
1794 | ||
1795 | if (p->num_auth_info_required == 0) | |
1796 | { | |
1797 | p->auth_info_required[0] = "none"; | |
1798 | p->num_auth_info_required = 1; | |
1799 | } | |
1800 | ||
09a101d6 | 1801 | /* |
1802 | * Update the printer-type value as needed... | |
1803 | */ | |
1804 | ||
1805 | if (p->num_auth_info_required > 1 || | |
1806 | strcmp(p->auth_info_required[0], "none")) | |
1807 | p->type |= CUPS_PRINTER_AUTHENTICATED; | |
1808 | else | |
1809 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; | |
1810 | ||
f7deaa1a | 1811 | return (1); |
1812 | } | |
1813 | ||
1814 | /* | |
1815 | * Grab values from an attribute instead... | |
1816 | */ | |
1817 | ||
1818 | if (!attr || attr->num_values > 4) | |
1819 | return (0); | |
1820 | ||
09a101d6 | 1821 | /* |
1822 | * Update the printer-type value as needed... | |
1823 | */ | |
1824 | ||
1825 | if (attr->num_values > 1 || | |
1826 | strcmp(attr->values[0].string.text, "none")) | |
1827 | p->type |= CUPS_PRINTER_AUTHENTICATED; | |
1828 | else | |
1829 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; | |
1830 | ||
f7deaa1a | 1831 | for (i = 0; i < attr->num_values; i ++) |
1832 | { | |
1833 | if (!strcmp(attr->values[i].string.text, "none")) | |
1834 | { | |
1835 | if (p->num_auth_info_required != 0 || attr->num_values != 1) | |
1836 | return (0); | |
1837 | ||
1838 | p->auth_info_required[p->num_auth_info_required] = "none"; | |
1839 | p->num_auth_info_required ++; | |
1840 | ||
1841 | return (1); | |
1842 | } | |
f899b121 | 1843 | else if (!strcmp(attr->values[i].string.text, "negotiate")) |
1844 | { | |
1845 | if (p->num_auth_info_required != 0 || attr->num_values != 1) | |
1846 | return (0); | |
1847 | ||
1848 | p->auth_info_required[p->num_auth_info_required] = "negotiate"; | |
1849 | p->num_auth_info_required ++; | |
1850 | ||
1851 | return (1); | |
1852 | } | |
f7deaa1a | 1853 | else if (!strcmp(attr->values[i].string.text, "domain")) |
1854 | { | |
1855 | p->auth_info_required[p->num_auth_info_required] = "domain"; | |
1856 | p->num_auth_info_required ++; | |
1857 | } | |
1858 | else if (!strcmp(attr->values[i].string.text, "password")) | |
1859 | { | |
1860 | p->auth_info_required[p->num_auth_info_required] = "password"; | |
1861 | p->num_auth_info_required ++; | |
1862 | } | |
1863 | else if (!strcmp(attr->values[i].string.text, "username")) | |
1864 | { | |
1865 | p->auth_info_required[p->num_auth_info_required] = "username"; | |
1866 | p->num_auth_info_required ++; | |
1867 | } | |
1868 | else | |
1869 | return (0); | |
1870 | } | |
1871 | ||
1872 | return (1); | |
1873 | } | |
1874 | ||
1875 | ||
0af14961 MS |
1876 | /* |
1877 | * 'cupsdSetDeviceURI()' - Set the device URI for a printer. | |
1878 | */ | |
1879 | ||
1880 | void | |
1881 | cupsdSetDeviceURI(cupsd_printer_t *p, /* I - Printer */ | |
1882 | const char *uri) /* I - Device URI */ | |
1883 | { | |
1884 | char buffer[1024], /* URI buffer */ | |
1885 | *start, /* Start of data after scheme */ | |
1886 | *slash, /* First slash after scheme:// */ | |
1887 | *ptr; /* Pointer into user@host:port part */ | |
1888 | ||
1889 | ||
1890 | /* | |
1891 | * Set the full device URI.. | |
1892 | */ | |
1893 | ||
1894 | cupsdSetString(&(p->device_uri), uri); | |
1895 | ||
1896 | /* | |
1897 | * Copy the device URI to a temporary buffer so we can sanitize any auth | |
1898 | * info in it... | |
1899 | */ | |
1900 | ||
1901 | strlcpy(buffer, uri, sizeof(buffer)); | |
1902 | ||
1903 | /* | |
1904 | * Find the end of the scheme:// part... | |
1905 | */ | |
1906 | ||
1907 | if ((ptr = strchr(buffer, ':')) != NULL) | |
1908 | { | |
1909 | for (start = ptr + 1; *start; start ++) | |
1910 | if (*start != '/') | |
1911 | break; | |
1912 | ||
1913 | /* | |
1914 | * Find the next slash (/) in the URI... | |
1915 | */ | |
1916 | ||
1917 | if ((slash = strchr(start, '/')) == NULL) | |
1918 | slash = start + strlen(start); /* No slash, point to the end */ | |
1919 | ||
1920 | /* | |
1921 | * Check for an @ sign before the slash... | |
1922 | */ | |
1923 | ||
1924 | if ((ptr = strchr(start, '@')) != NULL && ptr < slash) | |
1925 | { | |
1926 | /* | |
1927 | * Found an @ sign and it is before the resource part, so we have | |
1928 | * an authentication string. Copy the remaining URI over the | |
1929 | * authentication string... | |
1930 | */ | |
1931 | ||
1932 | _cups_strcpy(start, ptr + 1); | |
1933 | } | |
1934 | } | |
1935 | ||
1936 | /* | |
1937 | * Save the sanitized URI... | |
1938 | */ | |
1939 | ||
1940 | cupsdSetString(&(p->sanitized_device_uri), buffer); | |
1941 | } | |
1942 | ||
1943 | ||
5a738aea MS |
1944 | /* |
1945 | * 'cupsdSetPrinterAttr()' - Set a printer attribute. | |
1946 | */ | |
1947 | ||
1948 | void | |
1949 | cupsdSetPrinterAttr( | |
1950 | cupsd_printer_t *p, /* I - Printer */ | |
1951 | const char *name, /* I - Attribute name */ | |
1952 | char *value) /* I - Attribute value string */ | |
1953 | { | |
1954 | ipp_attribute_t *attr; /* Attribute */ | |
1955 | int i, /* Looping var */ | |
1956 | count; /* Number of values */ | |
1957 | char *ptr; /* Pointer into value */ | |
1958 | ipp_tag_t value_tag; /* Value tag for this attribute */ | |
1959 | ||
1960 | ||
e6013cfa MS |
1961 | /* |
1962 | * Don't allow empty values... | |
1963 | */ | |
1964 | ||
1965 | if (!*value) | |
1966 | { | |
1967 | cupsdLogMessage(CUPSD_LOG_ERROR, "Ignoring empty \"%s\" attribute", name); | |
1968 | return; | |
1969 | } | |
1970 | ||
5a738aea MS |
1971 | /* |
1972 | * Count the number of values... | |
1973 | */ | |
1974 | ||
1975 | for (count = 1, ptr = value; | |
1976 | (ptr = strchr(ptr, ',')) != NULL; | |
1977 | ptr ++, count ++); | |
1978 | ||
1979 | /* | |
1980 | * Then add or update the attribute as needed... | |
1981 | */ | |
1982 | ||
ed6e7faf MS |
1983 | if (!strcmp(name, "marker-levels") || !strcmp(name, "marker-low-levels") || |
1984 | !strcmp(name, "marker-high-levels")) | |
5a738aea MS |
1985 | { |
1986 | /* | |
1987 | * Integer values... | |
1988 | */ | |
1989 | ||
1990 | if ((attr = ippFindAttribute(p->attrs, name, IPP_TAG_INTEGER)) != NULL && | |
1991 | attr->num_values < count) | |
1992 | { | |
1993 | ippDeleteAttribute(p->attrs, attr); | |
1994 | attr = NULL; | |
1995 | } | |
1996 | ||
1997 | if (attr) | |
1998 | attr->num_values = count; | |
1999 | else | |
2000 | attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, name, | |
2001 | count, NULL); | |
2002 | ||
2003 | if (!attr) | |
2004 | { | |
2005 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2006 | "Unable to allocate memory for printer attribute " | |
2007 | "(%d values)", count); | |
2008 | return; | |
2009 | } | |
2010 | ||
2011 | for (i = 0; i < count; i ++) | |
2012 | { | |
2013 | if ((ptr = strchr(value, ',')) != NULL) | |
2014 | *ptr++ = '\0'; | |
2015 | ||
2016 | attr->values[i].integer = strtol(value, NULL, 10); | |
2017 | ||
2018 | if (ptr) | |
2019 | value = ptr; | |
2020 | } | |
2021 | } | |
2022 | else | |
2023 | { | |
2024 | /* | |
2025 | * Name or keyword values... | |
2026 | */ | |
2027 | ||
2028 | if (!strcmp(name, "marker-types")) | |
2029 | value_tag = IPP_TAG_KEYWORD; | |
75bd9771 MS |
2030 | else if (!strcmp(name, "marker-message")) |
2031 | value_tag = IPP_TAG_TEXT; | |
5a738aea MS |
2032 | else |
2033 | value_tag = IPP_TAG_NAME; | |
2034 | ||
2035 | if ((attr = ippFindAttribute(p->attrs, name, value_tag)) != NULL && | |
2036 | attr->num_values < count) | |
2037 | { | |
2038 | ippDeleteAttribute(p->attrs, attr); | |
2039 | attr = NULL; | |
2040 | } | |
2041 | ||
2042 | if (attr) | |
75bd9771 MS |
2043 | { |
2044 | for (i = 0; i < attr->num_values; i ++) | |
2045 | _cupsStrFree(attr->values[i].string.text); | |
2046 | ||
5a738aea | 2047 | attr->num_values = count; |
75bd9771 | 2048 | } |
5a738aea MS |
2049 | else |
2050 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, value_tag, name, | |
2051 | count, NULL, NULL); | |
2052 | ||
2053 | if (!attr) | |
2054 | { | |
2055 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2056 | "Unable to allocate memory for printer attribute " | |
2057 | "(%d values)", count); | |
2058 | return; | |
2059 | } | |
2060 | ||
2061 | for (i = 0; i < count; i ++) | |
2062 | { | |
2063 | if ((ptr = strchr(value, ',')) != NULL) | |
2064 | *ptr++ = '\0'; | |
2065 | ||
5a738aea MS |
2066 | attr->values[i].string.text = _cupsStrAlloc(value); |
2067 | ||
2068 | if (ptr) | |
2069 | value = ptr; | |
2070 | } | |
2071 | } | |
2072 | } | |
2073 | ||
2074 | ||
ef416fc2 | 2075 | /* |
2076 | * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file. | |
2077 | */ | |
2078 | ||
2079 | void | |
2080 | cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */ | |
2081 | { | |
b423cd4c | 2082 | int i, /* Looping var */ |
2083 | length; /* Length of browse attributes */ | |
b423cd4c | 2084 | char resource[HTTP_MAX_URI]; /* Resource portion of URI */ |
bc44d920 | 2085 | int num_air; /* Number of auth-info-required values */ |
2086 | const char * const *air; /* auth-info-required values */ | |
b423cd4c | 2087 | cupsd_location_t *auth; /* Pointer to authentication element */ |
2088 | const char *auth_supported; /* Authentication supported */ | |
8922323b | 2089 | ipp_t *oldattrs; /* Old printer attributes */ |
b423cd4c | 2090 | ipp_attribute_t *attr; /* Attribute data */ |
b423cd4c | 2091 | cups_option_t *option; /* Current printer option */ |
61cf44e2 | 2092 | char *filter; /* Current filter */ |
bc44d920 | 2093 | static const char * const air_userpass[] = |
2094 | { /* Basic/Digest authentication */ | |
2095 | "username", | |
2096 | "password" | |
2097 | }; | |
a4924f6c | 2098 | #ifdef HAVE_GSSAPI |
bc44d920 | 2099 | static const char * const air_negotiate[] = |
2100 | { /* Kerberos authentication */ | |
2101 | "negotiate" | |
2102 | }; | |
a4924f6c | 2103 | #endif /* HAVE_GSSAPI */ |
bc44d920 | 2104 | static const char * const air_none[] = |
2105 | { /* No authentication */ | |
2106 | "none" | |
2107 | }; | |
ef416fc2 | 2108 | |
2109 | ||
2110 | DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name, | |
2111 | p->type)); | |
2112 | ||
2113 | /* | |
2114 | * Make sure that we have the common attributes defined... | |
2115 | */ | |
2116 | ||
2117 | if (!CommonData) | |
2118 | cupsdCreateCommonData(); | |
2119 | ||
2120 | /* | |
2121 | * Clear out old filters, if any... | |
2122 | */ | |
2123 | ||
e1d6a774 | 2124 | delete_printer_filters(p); |
ef416fc2 | 2125 | |
2126 | /* | |
2127 | * Figure out the authentication that is required for the printer. | |
2128 | */ | |
2129 | ||
2130 | auth_supported = "requesting-user-name"; | |
bc44d920 | 2131 | num_air = 1; |
2132 | air = air_none; | |
2133 | ||
2134 | if (p->num_auth_info_required > 0 && strcmp(p->auth_info_required[0], "none")) | |
2135 | { | |
2136 | num_air = p->num_auth_info_required; | |
2137 | air = p->auth_info_required; | |
2138 | ||
2139 | if (!strcmp(air[0], "username")) | |
2140 | auth_supported = "basic"; | |
2141 | else | |
2142 | auth_supported = "negotiate"; | |
2143 | } | |
2144 | else if (!(p->type & CUPS_PRINTER_DISCOVERED)) | |
ef416fc2 | 2145 | { |
2146 | if (p->type & CUPS_PRINTER_CLASS) | |
2147 | snprintf(resource, sizeof(resource), "/classes/%s", p->name); | |
2148 | else | |
2149 | snprintf(resource, sizeof(resource), "/printers/%s", p->name); | |
2150 | ||
d09495fa | 2151 | if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL || |
5bd77a73 | 2152 | auth->type == CUPSD_AUTH_NONE) |
ef416fc2 | 2153 | auth = cupsdFindPolicyOp(p->op_policy_ptr, IPP_PRINT_JOB); |
2154 | ||
2155 | if (auth) | |
2156 | { | |
9a4f8274 MS |
2157 | int auth_type; /* Authentication type */ |
2158 | ||
2159 | ||
2160 | if ((auth_type = auth->type) == CUPSD_AUTH_DEFAULT) | |
2161 | auth_type = DefaultAuthType; | |
2162 | ||
2163 | if (auth_type == CUPSD_AUTH_BASIC || auth_type == CUPSD_AUTH_BASICDIGEST) | |
f899b121 | 2164 | { |
ef416fc2 | 2165 | auth_supported = "basic"; |
bc44d920 | 2166 | num_air = 2; |
2167 | air = air_userpass; | |
f899b121 | 2168 | } |
9a4f8274 | 2169 | else if (auth_type == CUPSD_AUTH_DIGEST) |
f899b121 | 2170 | { |
ef416fc2 | 2171 | auth_supported = "digest"; |
bc44d920 | 2172 | num_air = 2; |
2173 | air = air_userpass; | |
f899b121 | 2174 | } |
2175 | #ifdef HAVE_GSSAPI | |
9a4f8274 | 2176 | else if (auth_type == CUPSD_AUTH_NEGOTIATE) |
f899b121 | 2177 | { |
2178 | auth_supported = "negotiate"; | |
bc44d920 | 2179 | num_air = 1; |
2180 | air = air_negotiate; | |
f899b121 | 2181 | } |
2182 | #endif /* HAVE_GSSAPI */ | |
ef416fc2 | 2183 | |
9a4f8274 | 2184 | if (auth_type != CUPSD_AUTH_NONE) |
ef416fc2 | 2185 | p->type |= CUPS_PRINTER_AUTHENTICATED; |
2186 | else | |
2187 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; | |
2188 | } | |
2189 | else | |
2190 | p->type &= ~CUPS_PRINTER_AUTHENTICATED; | |
2191 | } | |
bc44d920 | 2192 | else if (p->type & CUPS_PRINTER_AUTHENTICATED) |
2193 | { | |
2194 | num_air = 2; | |
2195 | air = air_userpass; | |
2196 | } | |
ef416fc2 | 2197 | |
2198 | /* | |
2199 | * Create the required IPP attributes for a printer... | |
2200 | */ | |
2201 | ||
8922323b | 2202 | oldattrs = p->attrs; |
ef416fc2 | 2203 | p->attrs = ippNew(); |
2204 | ||
2205 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
2206 | "uri-authentication-supported", NULL, auth_supported); | |
2207 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
2208 | "uri-security-supported", NULL, "none"); | |
2209 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL, | |
2210 | p->name); | |
2211 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location", | |
2212 | NULL, p->location ? p->location : ""); | |
2213 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info", | |
2214 | NULL, p->info ? p->info : ""); | |
ef416fc2 | 2215 | |
2216 | if (p->num_users) | |
2217 | { | |
2218 | if (p->deny_users) | |
2219 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2220 | "requesting-user-name-denied", p->num_users, NULL, | |
2221 | p->users); | |
2222 | else | |
2223 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2224 | "requesting-user-name-allowed", p->num_users, NULL, | |
2225 | p->users); | |
2226 | } | |
2227 | ||
2228 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2229 | "job-quota-period", p->quota_period); | |
2230 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2231 | "job-k-limit", p->k_limit); | |
2232 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2233 | "job-page-limit", p->page_limit); | |
bc44d920 | 2234 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, |
2235 | "auth-info-required", num_air, NULL, air); | |
ef416fc2 | 2236 | |
09a101d6 | 2237 | if (cupsArrayCount(Banners) > 0 && !(p->type & CUPS_PRINTER_DISCOVERED)) |
ef416fc2 | 2238 | { |
2239 | /* | |
2240 | * Setup the job-sheets-default attribute... | |
2241 | */ | |
2242 | ||
2243 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2244 | "job-sheets-default", 2, NULL, NULL); | |
2245 | ||
2246 | if (attr != NULL) | |
2247 | { | |
757d2cad | 2248 | attr->values[0].string.text = _cupsStrAlloc(Classification ? |
ef416fc2 | 2249 | Classification : p->job_sheets[0]); |
757d2cad | 2250 | attr->values[1].string.text = _cupsStrAlloc(Classification ? |
ef416fc2 | 2251 | Classification : p->job_sheets[1]); |
2252 | } | |
2253 | } | |
2254 | ||
d09495fa | 2255 | p->raw = 0; |
2256 | p->remote = 0; | |
ef416fc2 | 2257 | |
09a101d6 | 2258 | if (p->type & CUPS_PRINTER_DISCOVERED) |
ef416fc2 | 2259 | { |
2260 | /* | |
2261 | * Tell the client this is a remote printer of some type... | |
2262 | */ | |
2263 | ||
2264 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, | |
2265 | "printer-uri-supported", NULL, p->uri); | |
2266 | ||
58dc1933 MS |
2267 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info", |
2268 | NULL, p->uri); | |
2269 | ||
ef416fc2 | 2270 | if (p->make_model) |
2271 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
2272 | "printer-make-and-model", NULL, p->make_model); | |
2273 | ||
fa73b229 | 2274 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, |
2275 | p->uri); | |
2276 | ||
d09495fa | 2277 | p->raw = 1; |
2278 | p->remote = 1; | |
ef416fc2 | 2279 | } |
2280 | else | |
2281 | { | |
2282 | /* | |
2283 | * Assign additional attributes depending on whether this is a printer | |
2284 | * or class... | |
2285 | */ | |
2286 | ||
ef416fc2 | 2287 | if (p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT)) |
2288 | { | |
2289 | p->raw = 1; | |
61cf44e2 | 2290 | p->type &= ~CUPS_PRINTER_OPTIONS; |
ef416fc2 | 2291 | |
2292 | /* | |
2293 | * Add class-specific attributes... | |
2294 | */ | |
2295 | ||
2296 | if ((p->type & CUPS_PRINTER_IMPLICIT) && p->num_printers > 0 && | |
2297 | p->printers[0]->make_model) | |
2298 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
2299 | "printer-make-and-model", NULL, p->printers[0]->make_model); | |
2300 | else | |
2301 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
2302 | "printer-make-and-model", NULL, "Local Printer Class"); | |
2303 | ||
fa73b229 | 2304 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, |
2305 | "file:///dev/null"); | |
2306 | ||
ef416fc2 | 2307 | if (p->num_printers > 0) |
2308 | { | |
2309 | /* | |
dd1abb6b | 2310 | * Add a list of member names; URIs are added in copy_printer_attrs... |
ef416fc2 | 2311 | */ |
2312 | ||
dd1abb6b MS |
2313 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, |
2314 | "member-names", p->num_printers, NULL, NULL); | |
ef416fc2 | 2315 | p->type |= CUPS_PRINTER_OPTIONS; |
2316 | ||
2317 | for (i = 0; i < p->num_printers; i ++) | |
2318 | { | |
2319 | if (attr != NULL) | |
426c6a59 | 2320 | attr->values[i].string.text = _cupsStrRetain(p->printers[i]->name); |
ef416fc2 | 2321 | |
2322 | p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type; | |
2323 | } | |
ef416fc2 | 2324 | } |
2325 | } | |
2326 | else | |
2327 | { | |
2328 | /* | |
0af14961 | 2329 | * Add printer-specific attributes... |
ef416fc2 | 2330 | */ |
2331 | ||
ef416fc2 | 2332 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, |
0af14961 | 2333 | p->sanitized_device_uri); |
ef416fc2 | 2334 | |
2335 | /* | |
2336 | * Assign additional attributes from the PPD file (if any)... | |
2337 | */ | |
2338 | ||
61cf44e2 | 2339 | load_ppd(p); |
f7deaa1a | 2340 | |
61cf44e2 MS |
2341 | /* |
2342 | * Add filters for printer... | |
2343 | */ | |
ef416fc2 | 2344 | |
61cf44e2 MS |
2345 | for (filter = (char *)cupsArrayFirst(p->filters); |
2346 | filter; | |
2347 | filter = (char *)cupsArrayNext(p->filters)) | |
2348 | add_printer_filter(p, p->filetype, filter); | |
ef416fc2 | 2349 | |
61cf44e2 | 2350 | if (p->pre_filters) |
ef416fc2 | 2351 | { |
61cf44e2 | 2352 | p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", p->name); |
ef416fc2 | 2353 | |
61cf44e2 MS |
2354 | for (filter = (char *)cupsArrayFirst(p->pre_filters); |
2355 | filter; | |
2356 | filter = (char *)cupsArrayNext(p->pre_filters)) | |
2357 | add_printer_filter(p, p->prefiltertype, filter); | |
ef416fc2 | 2358 | } |
ef416fc2 | 2359 | } |
2360 | } | |
2361 | ||
8922323b MS |
2362 | /* |
2363 | * Copy marker attributes as needed... | |
2364 | */ | |
2365 | ||
2366 | if (oldattrs) | |
2367 | { | |
2368 | ipp_attribute_t *oldattr; /* Old attribute */ | |
2369 | ||
2370 | ||
2371 | if ((oldattr = ippFindAttribute(oldattrs, "marker-colors", | |
2372 | IPP_TAG_NAME)) != NULL) | |
2373 | { | |
2374 | if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2375 | "marker-colors", oldattr->num_values, NULL, | |
2376 | NULL)) != NULL) | |
2377 | { | |
2378 | for (i = 0; i < oldattr->num_values; i ++) | |
2379 | attr->values[i].string.text = | |
426c6a59 | 2380 | _cupsStrRetain(oldattr->values[i].string.text); |
8922323b MS |
2381 | } |
2382 | } | |
2383 | ||
2384 | if ((oldattr = ippFindAttribute(oldattrs, "marker-levels", | |
2385 | IPP_TAG_INTEGER)) != NULL) | |
2386 | { | |
2387 | if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
2388 | "marker-levels", oldattr->num_values, | |
2389 | NULL)) != NULL) | |
2390 | { | |
2391 | for (i = 0; i < oldattr->num_values; i ++) | |
2392 | attr->values[i].integer = oldattr->values[i].integer; | |
2393 | } | |
2394 | } | |
2395 | ||
2396 | if ((oldattr = ippFindAttribute(oldattrs, "marker-names", | |
2397 | IPP_TAG_NAME)) != NULL) | |
2398 | { | |
2399 | if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
2400 | "marker-names", oldattr->num_values, NULL, | |
2401 | NULL)) != NULL) | |
2402 | { | |
2403 | for (i = 0; i < oldattr->num_values; i ++) | |
2404 | attr->values[i].string.text = | |
426c6a59 | 2405 | _cupsStrRetain(oldattr->values[i].string.text); |
8922323b MS |
2406 | } |
2407 | } | |
2408 | ||
2409 | if ((oldattr = ippFindAttribute(oldattrs, "marker-types", | |
2410 | IPP_TAG_KEYWORD)) != NULL) | |
2411 | { | |
2412 | if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
2413 | "marker-types", oldattr->num_values, NULL, | |
2414 | NULL)) != NULL) | |
2415 | { | |
2416 | for (i = 0; i < oldattr->num_values; i ++) | |
2417 | attr->values[i].string.text = | |
426c6a59 | 2418 | _cupsStrRetain(oldattr->values[i].string.text); |
8922323b MS |
2419 | } |
2420 | } | |
2421 | ||
2422 | ippDelete(oldattrs); | |
2423 | } | |
2424 | ||
b423cd4c | 2425 | /* |
bc44d920 | 2426 | * Force sharing off for remote queues... |
b423cd4c | 2427 | */ |
2428 | ||
bc44d920 | 2429 | if (p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) |
2430 | p->shared = 0; | |
2431 | else | |
b423cd4c | 2432 | { |
bc44d920 | 2433 | /* |
2434 | * Copy the printer options into a browse attributes string we can re-use. | |
2435 | */ | |
2436 | ||
b423cd4c | 2437 | const char *valptr; /* Pointer into value */ |
2438 | char *attrptr; /* Pointer into attribute string */ | |
2439 | ||
2440 | ||
2441 | /* | |
2442 | * Free the old browse attributes as needed... | |
2443 | */ | |
2444 | ||
2445 | if (p->browse_attrs) | |
2446 | free(p->browse_attrs); | |
2447 | ||
2448 | /* | |
2449 | * Compute the length of all attributes + job-sheets, lease-duration, | |
2450 | * and BrowseLocalOptions. | |
2451 | */ | |
2452 | ||
2453 | for (length = 1, i = p->num_options, option = p->options; | |
2454 | i > 0; | |
2455 | i --, option ++) | |
2456 | { | |
2457 | length += strlen(option->name) + 2; | |
2458 | ||
2459 | if (option->value) | |
2460 | { | |
2461 | for (valptr = option->value; *valptr; valptr ++) | |
2462 | if (strchr(" \"\'\\", *valptr)) | |
2463 | length += 2; | |
2464 | else | |
2465 | length ++; | |
2466 | } | |
2467 | } | |
2468 | ||
2469 | length += 13 + strlen(p->job_sheets[0]) + strlen(p->job_sheets[1]); | |
2470 | length += 32; | |
2471 | if (BrowseLocalOptions) | |
f7deaa1a | 2472 | length += 12 + strlen(BrowseLocalOptions); |
b423cd4c | 2473 | |
7594b224 | 2474 | if (p->num_auth_info_required > 0) |
2475 | { | |
2476 | length += 18; /* auth-info-required */ | |
2477 | ||
2478 | for (i = 0; i < p->num_auth_info_required; i ++) | |
2479 | length += strlen(p->auth_info_required[i]) + 1; | |
2480 | } | |
2481 | ||
b423cd4c | 2482 | /* |
2483 | * Allocate the new string... | |
2484 | */ | |
f7deaa1a | 2485 | |
b423cd4c | 2486 | if ((p->browse_attrs = calloc(1, length)) == NULL) |
2487 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
2488 | "Unable to allocate %d bytes for browse data!", | |
2489 | length); | |
2490 | else | |
2491 | { | |
2492 | /* | |
2493 | * Got the allocated string, now copy the options and attributes over... | |
2494 | */ | |
2495 | ||
2496 | sprintf(p->browse_attrs, "job-sheets=%s,%s lease-duration=%d", | |
2497 | p->job_sheets[0], p->job_sheets[1], BrowseTimeout); | |
2498 | attrptr = p->browse_attrs + strlen(p->browse_attrs); | |
2499 | ||
2500 | if (BrowseLocalOptions) | |
2501 | { | |
2502 | sprintf(attrptr, " ipp-options=%s", BrowseLocalOptions); | |
2503 | attrptr += strlen(attrptr); | |
2504 | } | |
2505 | ||
2506 | for (i = p->num_options, option = p->options; | |
2507 | i > 0; | |
2508 | i --, option ++) | |
2509 | { | |
2510 | *attrptr++ = ' '; | |
2511 | strcpy(attrptr, option->name); | |
2512 | attrptr += strlen(attrptr); | |
2513 | ||
2514 | if (option->value) | |
2515 | { | |
2516 | *attrptr++ = '='; | |
2517 | ||
2518 | for (valptr = option->value; *valptr; valptr ++) | |
2519 | { | |
2520 | if (strchr(" \"\'\\", *valptr)) | |
2521 | *attrptr++ = '\\'; | |
2522 | ||
2523 | *attrptr++ = *valptr; | |
2524 | } | |
2525 | } | |
2526 | } | |
2527 | ||
7594b224 | 2528 | if (p->num_auth_info_required > 0) |
2529 | { | |
2530 | strcpy(attrptr, "auth-info-required"); | |
2531 | attrptr += 18; | |
2532 | ||
2533 | for (i = 0; i < p->num_auth_info_required; i ++) | |
2534 | { | |
2535 | *attrptr++ = i ? ',' : '='; | |
2536 | strcpy(attrptr, p->auth_info_required[i]); | |
2537 | attrptr += strlen(attrptr); | |
2538 | } | |
2539 | } | |
2540 | else | |
2541 | *attrptr = '\0'; | |
b423cd4c | 2542 | } |
2543 | } | |
2544 | ||
bd7854cb | 2545 | /* |
2546 | * Populate the document-format-supported attribute... | |
2547 | */ | |
2548 | ||
2549 | add_printer_formats(p); | |
2550 | ||
ef416fc2 | 2551 | DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p->name, |
2552 | p->type)); | |
2553 | ||
b423cd4c | 2554 | /* |
2555 | * Add name-default attributes... | |
2556 | */ | |
2557 | ||
2558 | add_printer_defaults(p); | |
2559 | ||
ef416fc2 | 2560 | #ifdef __sgi |
2561 | /* | |
2562 | * Write the IRIX printer config and status files... | |
2563 | */ | |
2564 | ||
2565 | write_irix_config(p); | |
2566 | write_irix_state(p); | |
2567 | #endif /* __sgi */ | |
f7deaa1a | 2568 | |
2569 | /* | |
2570 | * Let the browse protocols reflect the change | |
2571 | */ | |
2572 | ||
2573 | cupsdRegisterPrinter(p); | |
ef416fc2 | 2574 | } |
2575 | ||
2576 | ||
2577 | /* | |
2578 | * 'cupsdSetPrinterReasons()' - Set/update the reasons strings. | |
2579 | */ | |
2580 | ||
2581 | void | |
2582 | cupsdSetPrinterReasons( | |
2583 | cupsd_printer_t *p, /* I - Printer */ | |
2584 | const char *s) /* I - Reasons strings */ | |
2585 | { | |
2586 | int i; /* Looping var */ | |
2587 | const char *sptr; /* Pointer into reasons */ | |
2588 | char reason[255], /* Reason string */ | |
2589 | *rptr; /* Pointer into reason */ | |
2590 | ||
2591 | ||
2592 | if (s[0] == '-' || s[0] == '+') | |
2593 | { | |
2594 | /* | |
2595 | * Add/remove reasons... | |
2596 | */ | |
2597 | ||
2598 | sptr = s + 1; | |
2599 | } | |
2600 | else | |
2601 | { | |
2602 | /* | |
2603 | * Replace reasons... | |
2604 | */ | |
2605 | ||
2606 | sptr = s; | |
2607 | ||
2608 | for (i = 0; i < p->num_reasons; i ++) | |
0af14961 | 2609 | _cupsStrFree(p->reasons[i]); |
ef416fc2 | 2610 | |
2611 | p->num_reasons = 0; | |
0af14961 | 2612 | |
e6013cfa MS |
2613 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); |
2614 | ||
0af14961 MS |
2615 | if (PrintcapFormat == PRINTCAP_PLIST) |
2616 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); | |
ef416fc2 | 2617 | } |
2618 | ||
bc44d920 | 2619 | if (!strcmp(s, "none")) |
2620 | return; | |
2621 | ||
ef416fc2 | 2622 | /* |
2623 | * Loop through all of the reasons... | |
2624 | */ | |
2625 | ||
2626 | while (*sptr) | |
2627 | { | |
2628 | /* | |
2629 | * Skip leading whitespace and commas... | |
2630 | */ | |
2631 | ||
2632 | while (isspace(*sptr & 255) || *sptr == ',') | |
2633 | sptr ++; | |
2634 | ||
2635 | for (rptr = reason; *sptr && !isspace(*sptr & 255) && *sptr != ','; sptr ++) | |
2636 | if (rptr < (reason + sizeof(reason) - 1)) | |
2637 | *rptr++ = *sptr; | |
2638 | ||
2639 | if (rptr == reason) | |
2640 | break; | |
2641 | ||
2642 | *rptr = '\0'; | |
2643 | ||
2644 | if (s[0] == '-') | |
2645 | { | |
2646 | /* | |
2647 | * Remove reason... | |
2648 | */ | |
2649 | ||
2650 | for (i = 0; i < p->num_reasons; i ++) | |
2651 | if (!strcasecmp(reason, p->reasons[i])) | |
2652 | { | |
2653 | /* | |
2654 | * Found a match, so remove it... | |
2655 | */ | |
2656 | ||
2657 | p->num_reasons --; | |
1f6f3dbc | 2658 | _cupsStrFree(p->reasons[i]); |
ef416fc2 | 2659 | |
2660 | if (i < p->num_reasons) | |
2661 | memmove(p->reasons + i, p->reasons + i + 1, | |
2662 | (p->num_reasons - i) * sizeof(char *)); | |
2663 | ||
2664 | i --; | |
c0e1af83 | 2665 | |
2666 | if (!strcmp(reason, "paused") && p->state == IPP_PRINTER_STOPPED) | |
2667 | cupsdSetPrinterState(p, IPP_PRINTER_IDLE, 1); | |
0af14961 | 2668 | |
e6013cfa MS |
2669 | if (strcmp(reason, "connecting-to-device")) |
2670 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); | |
2671 | ||
0af14961 MS |
2672 | if (PrintcapFormat == PRINTCAP_PLIST) |
2673 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); | |
ef416fc2 | 2674 | } |
2675 | } | |
2676 | else if (p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0]))) | |
2677 | { | |
2678 | /* | |
2679 | * Add reason... | |
2680 | */ | |
2681 | ||
2682 | for (i = 0; i < p->num_reasons; i ++) | |
2683 | if (!strcasecmp(reason, p->reasons[i])) | |
2684 | break; | |
2685 | ||
2686 | if (i >= p->num_reasons) | |
2687 | { | |
0af14961 | 2688 | p->reasons[i] = _cupsStrAlloc(reason); |
ef416fc2 | 2689 | p->num_reasons ++; |
c0e1af83 | 2690 | |
2691 | if (!strcmp(reason, "paused") && p->state != IPP_PRINTER_STOPPED) | |
2692 | cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 1); | |
0af14961 | 2693 | |
e6013cfa MS |
2694 | if (strcmp(reason, "connecting-to-device")) |
2695 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); | |
2696 | ||
0af14961 MS |
2697 | if (PrintcapFormat == PRINTCAP_PLIST) |
2698 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); | |
ef416fc2 | 2699 | } |
2700 | } | |
2701 | } | |
2702 | } | |
2703 | ||
2704 | ||
2705 | /* | |
2706 | * 'cupsdSetPrinterState()' - Update the current state of a printer. | |
2707 | */ | |
2708 | ||
2709 | void | |
2710 | cupsdSetPrinterState( | |
2711 | cupsd_printer_t *p, /* I - Printer to change */ | |
2712 | ipp_pstate_t s, /* I - New state */ | |
2713 | int update) /* I - Update printers.conf? */ | |
2714 | { | |
2715 | ipp_pstate_t old_state; /* Old printer state */ | |
2716 | ||
2717 | ||
2718 | /* | |
2719 | * Can't set status of remote printers... | |
2720 | */ | |
2721 | ||
09a101d6 | 2722 | if (p->type & CUPS_PRINTER_DISCOVERED) |
ef416fc2 | 2723 | return; |
2724 | ||
2725 | /* | |
2726 | * Set the new state... | |
2727 | */ | |
2728 | ||
0af14961 MS |
2729 | if (PrintcapFormat == PRINTCAP_PLIST) |
2730 | cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP); | |
2731 | ||
ef416fc2 | 2732 | old_state = p->state; |
2733 | p->state = s; | |
2734 | ||
2735 | if (old_state != s) | |
2736 | { | |
0a682745 | 2737 | cupsdAddEvent(s == IPP_PRINTER_STOPPED ? CUPSD_EVENT_PRINTER_STOPPED : |
d9bca400 | 2738 | CUPSD_EVENT_PRINTER_STATE, p, NULL, |
e53920b9 | 2739 | "%s \"%s\" state changed.", |
2740 | (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer", | |
2741 | p->name); | |
2742 | ||
ef416fc2 | 2743 | /* |
2744 | * Let the browse code know this needs to be updated... | |
2745 | */ | |
2746 | ||
2747 | BrowseNext = p; | |
2748 | p->state_time = time(NULL); | |
2749 | p->browse_time = 0; | |
2750 | ||
2751 | #ifdef __sgi | |
2752 | write_irix_state(p); | |
2753 | #endif /* __sgi */ | |
2754 | } | |
2755 | ||
2756 | cupsdAddPrinterHistory(p); | |
2757 | ||
f7deaa1a | 2758 | /* |
2759 | * Let the browse protocols reflect the change... | |
2760 | */ | |
2761 | ||
7a14d768 MS |
2762 | if (update) |
2763 | cupsdRegisterPrinter(p); | |
f7deaa1a | 2764 | |
ef416fc2 | 2765 | /* |
2766 | * Save the printer configuration if a printer goes from idle or processing | |
2767 | * to stopped (or visa-versa)... | |
2768 | */ | |
2769 | ||
2770 | if ((old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED) && | |
2771 | update) | |
2772 | { | |
2773 | if (p->type & CUPS_PRINTER_CLASS) | |
3dfe78b3 | 2774 | cupsdMarkDirty(CUPSD_DIRTY_CLASSES); |
ef416fc2 | 2775 | else |
3dfe78b3 | 2776 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); |
ef416fc2 | 2777 | } |
2778 | } | |
2779 | ||
2780 | ||
2781 | /* | |
2782 | * 'cupsdStopPrinter()' - Stop a printer from printing any jobs... | |
2783 | */ | |
2784 | ||
2785 | void | |
2786 | cupsdStopPrinter(cupsd_printer_t *p, /* I - Printer to stop */ | |
2787 | int update)/* I - Update printers.conf? */ | |
2788 | { | |
2789 | cupsd_job_t *job; /* Active print job */ | |
2790 | ||
2791 | ||
2792 | /* | |
2793 | * Set the printer state... | |
2794 | */ | |
2795 | ||
2796 | cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, update); | |
2797 | ||
2798 | /* | |
2799 | * See if we have a job printing on this printer... | |
2800 | */ | |
2801 | ||
2802 | if (p->job) | |
2803 | { | |
2804 | /* | |
2805 | * Get pointer to job... | |
2806 | */ | |
2807 | ||
2808 | job = (cupsd_job_t *)p->job; | |
2809 | ||
2810 | /* | |
2811 | * Stop it... | |
2812 | */ | |
2813 | ||
2814 | cupsdStopJob(job, 0); | |
2815 | ||
2816 | /* | |
2817 | * Reset the state to pending... | |
2818 | */ | |
2819 | ||
2820 | job->state->values[0].integer = IPP_JOB_PENDING; | |
bd7854cb | 2821 | job->state_value = IPP_JOB_PENDING; |
3dfe78b3 | 2822 | job->dirty = 1; |
ef416fc2 | 2823 | |
3dfe78b3 | 2824 | cupsdMarkDirty(CUPSD_DIRTY_JOBS); |
07725fee | 2825 | |
2826 | cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED, p, job, | |
2827 | "Job stopped due to printer being paused"); | |
ef416fc2 | 2828 | } |
2829 | } | |
2830 | ||
2831 | ||
c9fc04c6 MS |
2832 | /* |
2833 | * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file. | |
2834 | */ | |
2835 | ||
2836 | int /* O - 1 if successful, 0 otherwise */ | |
2837 | cupsdUpdatePrinterPPD( | |
2838 | cupsd_printer_t *p, /* I - Printer */ | |
2839 | int num_keywords, /* I - Number of keywords */ | |
2840 | cups_option_t *keywords) /* I - Keywords */ | |
2841 | { | |
2842 | int i; /* Looping var */ | |
2843 | cups_file_t *src, /* Original file */ | |
2844 | *dst; /* New file */ | |
2845 | char srcfile[1024], /* Original filename */ | |
2846 | dstfile[1024], /* New filename */ | |
2847 | line[1024], /* Line from file */ | |
2848 | keystring[41]; /* Keyword from line */ | |
2849 | cups_option_t *keyword; /* Current keyword */ | |
2850 | ||
2851 | ||
2852 | cupsdLogMessage(CUPSD_LOG_INFO, "Updating keywords in PPD file for %s...", | |
2853 | p->name); | |
2854 | ||
2855 | /* | |
2856 | * Get the old and new PPD filenames... | |
2857 | */ | |
2858 | ||
2859 | snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd.O", ServerRoot, p->name); | |
2860 | snprintf(dstfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot, p->name); | |
2861 | ||
2862 | /* | |
2863 | * Rename the old file and open the old and new... | |
2864 | */ | |
2865 | ||
2866 | if (rename(dstfile, srcfile)) | |
2867 | { | |
2868 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to backup PPD file for %s: %s", | |
2869 | p->name, strerror(errno)); | |
2870 | return (0); | |
2871 | } | |
2872 | ||
2873 | if ((src = cupsFileOpen(srcfile, "r")) == NULL) | |
2874 | { | |
2875 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open PPD file \"%s\": %s", | |
2876 | srcfile, strerror(errno)); | |
2877 | rename(srcfile, dstfile); | |
2878 | return (0); | |
2879 | } | |
2880 | ||
2881 | if ((dst = cupsFileOpen(dstfile, "w")) == NULL) | |
2882 | { | |
2883 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create PPD file \"%s\": %s", | |
2884 | dstfile, strerror(errno)); | |
2885 | cupsFileClose(src); | |
2886 | rename(srcfile, dstfile); | |
2887 | return (0); | |
2888 | } | |
2889 | ||
2890 | /* | |
2891 | * Copy the first line and then write out all of the keywords... | |
2892 | */ | |
2893 | ||
2894 | if (!cupsFileGets(src, line, sizeof(line))) | |
2895 | { | |
2896 | cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s", | |
2897 | srcfile, strerror(errno)); | |
2898 | cupsFileClose(src); | |
2899 | cupsFileClose(dst); | |
2900 | rename(srcfile, dstfile); | |
2901 | return (0); | |
2902 | } | |
2903 | ||
2904 | cupsFilePrintf(dst, "%s\n", line); | |
2905 | ||
2906 | for (i = num_keywords, keyword = keywords; i > 0; i --, keyword ++) | |
2907 | { | |
2908 | cupsdLogMessage(CUPSD_LOG_DEBUG, "*%s: %s", keyword->name, keyword->value); | |
2909 | cupsFilePrintf(dst, "*%s: %s\n", keyword->name, keyword->value); | |
2910 | } | |
2911 | ||
2912 | /* | |
2913 | * Then copy the rest of the PPD file, dropping any keywords we changed. | |
2914 | */ | |
2915 | ||
2916 | while (cupsFileGets(src, line, sizeof(line))) | |
2917 | { | |
2918 | /* | |
2919 | * Skip keywords we've already set... | |
2920 | */ | |
2921 | ||
2922 | if (sscanf(line, "*%40[^:]:", keystring) == 1 && | |
2923 | cupsGetOption(keystring, num_keywords, keywords)) | |
2924 | continue; | |
2925 | ||
2926 | /* | |
2927 | * Otherwise write the line... | |
2928 | */ | |
2929 | ||
2930 | cupsFilePrintf(dst, "%s\n", line); | |
2931 | } | |
2932 | ||
2933 | /* | |
2934 | * Close files and return... | |
2935 | */ | |
2936 | ||
2937 | cupsFileClose(src); | |
2938 | cupsFileClose(dst); | |
2939 | ||
2940 | return (1); | |
2941 | } | |
2942 | ||
2943 | ||
ef416fc2 | 2944 | /* |
2945 | * 'cupsdUpdatePrinters()' - Update printers after a partial reload. | |
2946 | */ | |
2947 | ||
2948 | void | |
2949 | cupsdUpdatePrinters(void) | |
2950 | { | |
2951 | cupsd_printer_t *p; /* Current printer */ | |
2952 | ||
2953 | ||
2954 | /* | |
2955 | * Loop through the printers and recreate the printer attributes | |
2956 | * for any local printers since the policy and/or access control | |
2957 | * stuff may have changed. Also, if browsing is disabled, remove | |
2958 | * any remote printers... | |
2959 | */ | |
2960 | ||
2961 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
2962 | p; | |
2963 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
2964 | { | |
07725fee | 2965 | /* |
2966 | * Remove remote printers if we are no longer browsing... | |
2967 | */ | |
2968 | ||
09a101d6 | 2969 | if (!Browsing && |
2970 | (p->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_DISCOVERED))) | |
ef416fc2 | 2971 | { |
2972 | if (p->type & CUPS_PRINTER_IMPLICIT) | |
2973 | cupsArrayRemove(ImplicitPrinters, p); | |
2974 | ||
2975 | cupsArraySave(Printers); | |
2976 | cupsdDeletePrinter(p, 0); | |
2977 | cupsArrayRestore(Printers); | |
2978 | continue; | |
2979 | } | |
ef416fc2 | 2980 | |
2981 | /* | |
2982 | * Update the operation policy pointer... | |
2983 | */ | |
2984 | ||
2985 | if ((p->op_policy_ptr = cupsdFindPolicy(p->op_policy)) == NULL) | |
2986 | p->op_policy_ptr = DefaultPolicyPtr; | |
07725fee | 2987 | |
2988 | /* | |
2989 | * Update printer attributes as needed... | |
2990 | */ | |
2991 | ||
09a101d6 | 2992 | if (!(p->type & CUPS_PRINTER_DISCOVERED)) |
07725fee | 2993 | cupsdSetPrinterAttrs(p); |
ef416fc2 | 2994 | } |
2995 | } | |
2996 | ||
2997 | ||
2998 | /* | |
2999 | * 'cupsdValidateDest()' - Validate a printer/class destination. | |
3000 | */ | |
3001 | ||
3002 | const char * /* O - Printer or class name */ | |
3003 | cupsdValidateDest( | |
f7deaa1a | 3004 | const char *uri, /* I - Printer URI */ |
ef416fc2 | 3005 | cups_ptype_t *dtype, /* O - Type (printer or class) */ |
3006 | cupsd_printer_t **printer) /* O - Printer pointer */ | |
3007 | { | |
3008 | cupsd_printer_t *p; /* Current printer */ | |
3009 | char localname[1024],/* Localized hostname */ | |
3010 | *lptr, /* Pointer into localized hostname */ | |
f7deaa1a | 3011 | *sptr, /* Pointer into server name */ |
3012 | *rptr, /* Pointer into resource */ | |
3013 | scheme[32], /* Scheme portion of URI */ | |
3014 | username[64], /* Username portion of URI */ | |
3015 | hostname[HTTP_MAX_HOST], | |
3016 | /* Host portion of URI */ | |
3017 | resource[HTTP_MAX_URI]; | |
3018 | /* Resource portion of URI */ | |
3019 | int port; /* Port portion of URI */ | |
3020 | ||
3021 | ||
3022 | DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri, | |
ef416fc2 | 3023 | dtype, printer)); |
3024 | ||
3025 | /* | |
3026 | * Initialize return values... | |
3027 | */ | |
3028 | ||
3029 | if (printer) | |
3030 | *printer = NULL; | |
3031 | ||
f7deaa1a | 3032 | if (dtype) |
3033 | *dtype = (cups_ptype_t)0; | |
3034 | ||
3035 | /* | |
3036 | * Pull the hostname and resource from the URI... | |
3037 | */ | |
3038 | ||
3039 | httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), | |
3040 | username, sizeof(username), hostname, sizeof(hostname), | |
3041 | &port, resource, sizeof(resource)); | |
ef416fc2 | 3042 | |
3043 | /* | |
3044 | * See if the resource is a class or printer... | |
3045 | */ | |
3046 | ||
3047 | if (!strncmp(resource, "/classes/", 9)) | |
3048 | { | |
3049 | /* | |
3050 | * Class... | |
3051 | */ | |
3052 | ||
f7deaa1a | 3053 | rptr = resource + 9; |
ef416fc2 | 3054 | } |
3055 | else if (!strncmp(resource, "/printers/", 10)) | |
3056 | { | |
3057 | /* | |
3058 | * Printer... | |
3059 | */ | |
3060 | ||
f7deaa1a | 3061 | rptr = resource + 10; |
ef416fc2 | 3062 | } |
3063 | else | |
3064 | { | |
3065 | /* | |
3066 | * Bad resource name... | |
3067 | */ | |
3068 | ||
3069 | return (NULL); | |
3070 | } | |
3071 | ||
3072 | /* | |
3073 | * See if the printer or class name exists... | |
3074 | */ | |
3075 | ||
f7deaa1a | 3076 | p = cupsdFindDest(rptr); |
ef416fc2 | 3077 | |
f7deaa1a | 3078 | if (p == NULL && strchr(rptr, '@') == NULL) |
ef416fc2 | 3079 | return (NULL); |
3080 | else if (p != NULL) | |
3081 | { | |
3082 | if (printer) | |
3083 | *printer = p; | |
3084 | ||
f7deaa1a | 3085 | if (dtype) |
3086 | *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT | | |
09a101d6 | 3087 | CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED); |
f7deaa1a | 3088 | |
ef416fc2 | 3089 | return (p->name); |
3090 | } | |
3091 | ||
3092 | /* | |
3093 | * Change localhost to the server name... | |
3094 | */ | |
3095 | ||
3096 | if (!strcasecmp(hostname, "localhost")) | |
f7deaa1a | 3097 | strlcpy(hostname, ServerName, sizeof(hostname)); |
ef416fc2 | 3098 | |
3099 | strlcpy(localname, hostname, sizeof(localname)); | |
3100 | ||
3101 | if (!strcasecmp(hostname, ServerName)) | |
3102 | { | |
3103 | /* | |
3104 | * Localize the hostname... | |
3105 | */ | |
3106 | ||
3107 | lptr = strchr(localname, '.'); | |
3108 | sptr = strchr(ServerName, '.'); | |
3109 | ||
3110 | if (sptr != NULL && lptr != NULL) | |
3111 | { | |
3112 | /* | |
3113 | * Strip the common domain name components... | |
3114 | */ | |
3115 | ||
3116 | while (lptr != NULL) | |
3117 | { | |
3118 | if (!strcasecmp(lptr, sptr)) | |
3119 | { | |
3120 | *lptr = '\0'; | |
3121 | break; | |
3122 | } | |
3123 | else | |
3124 | lptr = strchr(lptr + 1, '.'); | |
3125 | } | |
3126 | } | |
3127 | } | |
3128 | ||
3129 | DEBUG_printf(("localized hostname is \"%s\"...\n", localname)); | |
3130 | ||
3131 | /* | |
3132 | * Find a matching printer or class... | |
3133 | */ | |
3134 | ||
3135 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
3136 | p; | |
3137 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
3138 | if (!strcasecmp(p->hostname, localname) && | |
f7deaa1a | 3139 | !strcasecmp(p->name, rptr)) |
ef416fc2 | 3140 | { |
3141 | if (printer) | |
3142 | *printer = p; | |
3143 | ||
f7deaa1a | 3144 | if (dtype) |
3145 | *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT | | |
09a101d6 | 3146 | CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED); |
f7deaa1a | 3147 | |
ef416fc2 | 3148 | return (p->name); |
3149 | } | |
3150 | ||
3151 | return (NULL); | |
3152 | } | |
3153 | ||
3154 | ||
3155 | /* | |
3156 | * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications | |
3157 | * that need it... | |
3158 | */ | |
3159 | ||
3160 | void | |
3161 | cupsdWritePrintcap(void) | |
3162 | { | |
0af14961 MS |
3163 | int i; /* Looping var */ |
3164 | cups_file_t *fp; /* Printcap file */ | |
ef416fc2 | 3165 | cupsd_printer_t *p; /* Current printer */ |
3166 | ||
3167 | ||
3168 | #ifdef __sgi | |
3169 | /* | |
3170 | * Update the IRIX printer state for the default printer; if | |
3171 | * no printers remain, then the default printer file will be | |
3172 | * removed... | |
3173 | */ | |
3174 | ||
3175 | write_irix_state(DefaultPrinter); | |
3176 | #endif /* __sgi */ | |
3177 | ||
3178 | /* | |
3179 | * See if we have a printcap file; if not, don't bother writing it. | |
3180 | */ | |
3181 | ||
3182 | if (!Printcap || !*Printcap) | |
3183 | return; | |
3184 | ||
3185 | /* | |
3186 | * Open the printcap file... | |
3187 | */ | |
3188 | ||
3189 | if ((fp = cupsFileOpen(Printcap, "w")) == NULL) | |
3190 | return; | |
3191 | ||
3192 | /* | |
3193 | * Put a comment header at the top so that users will know where the | |
3194 | * data has come from... | |
3195 | */ | |
3196 | ||
0af14961 MS |
3197 | if (PrintcapFormat != PRINTCAP_PLIST) |
3198 | cupsFilePrintf(fp, "# This file was automatically generated by cupsd(8) " | |
3199 | "from the\n" | |
3200 | "# %s/printers.conf file. All changes to this file\n" | |
3201 | "# will be lost.\n", ServerRoot); | |
ef416fc2 | 3202 | |
3203 | if (Printers) | |
3204 | { | |
3205 | /* | |
3206 | * Write a new printcap with the current list of printers. | |
3207 | */ | |
3208 | ||
3209 | switch (PrintcapFormat) | |
3210 | { | |
0af14961 | 3211 | case PRINTCAP_BSD : |
ef416fc2 | 3212 | /* |
3213 | * Each printer is put in the file as: | |
3214 | * | |
3215 | * Printer1: | |
3216 | * Printer2: | |
3217 | * Printer3: | |
3218 | * ... | |
3219 | * PrinterN: | |
3220 | */ | |
3221 | ||
3222 | if (DefaultPrinter) | |
3223 | cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name, | |
c277e2f8 MS |
3224 | DefaultPrinter->info, ServerName, |
3225 | DefaultPrinter->name); | |
ef416fc2 | 3226 | |
3227 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
3228 | p; | |
3229 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
3230 | if (p != DefaultPrinter) | |
3231 | cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info, | |
c277e2f8 | 3232 | ServerName, p->name); |
ef416fc2 | 3233 | break; |
3234 | ||
0af14961 MS |
3235 | case PRINTCAP_PLIST : |
3236 | /* | |
3237 | * Each printer is written as a dictionary in a plist file. | |
3238 | * Currently the printer-name, printer-info, printer-is-accepting-jobs, | |
3239 | * printer-location, printer-make-and-model, printer-state, | |
3240 | * printer-state-reasons, printer-type, and (sanitized) device-uri. | |
3241 | */ | |
3242 | ||
3243 | cupsFilePuts(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | |
3244 | "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD " | |
3245 | "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/" | |
3246 | "PropertyList-1.0.dtd\">\n" | |
3247 | "<plist version=\"1.0\">\n" | |
3248 | "<array>\n"); | |
3249 | ||
3250 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
3251 | p; | |
3252 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
3253 | { | |
3254 | cupsFilePuts(fp, "\t<dict>\n" | |
3255 | "\t\t<key>printer-name</key>\n" | |
3256 | "\t\t<string>"); | |
3257 | write_xml_string(fp, p->name); | |
3258 | cupsFilePuts(fp, "</string>\n" | |
3259 | "\t\t<key>printer-info</key>\n" | |
3260 | "\t\t<string>"); | |
3261 | write_xml_string(fp, p->info); | |
3262 | cupsFilePrintf(fp, "</string>\n" | |
3263 | "\t\t<key>printer-is-accepting-jobs</key>\n" | |
3264 | "\t\t<%s/>\n" | |
3265 | "\t\t<key>printer-location</key>\n" | |
3266 | "\t\t<string>", p->accepting ? "true" : "false"); | |
3267 | write_xml_string(fp, p->location); | |
3268 | cupsFilePuts(fp, "</string>\n" | |
3269 | "\t\t<key>printer-make-and-model</key>\n" | |
3270 | "\t\t<string>"); | |
3271 | write_xml_string(fp, p->make_model); | |
3272 | cupsFilePrintf(fp, "</string>\n" | |
3273 | "\t\t<key>printer-state</key>\n" | |
3274 | "\t\t<integer>%d</integer>\n" | |
3275 | "\t\t<key>printer-state-reasons</key>\n" | |
3276 | "\t\t<array>\n", p->state); | |
3277 | for (i = 0; i < p->num_reasons; i ++) | |
3278 | { | |
3279 | cupsFilePuts(fp, "\t\t\t<string>"); | |
3280 | write_xml_string(fp, p->reasons[i]); | |
3281 | cupsFilePuts(fp, "</string>\n"); | |
3282 | } | |
3283 | cupsFilePrintf(fp, "\t\t</array>\n" | |
3284 | "\t\t<key>printer-type</key>\n" | |
3285 | "\t\t<integer>%d</integer>\n" | |
3286 | "\t\t<key>device-uri</key>\n" | |
3287 | "\t\t<string>", p->type); | |
3288 | write_xml_string(fp, p->sanitized_device_uri); | |
3289 | cupsFilePuts(fp, "</string>\n" | |
3290 | "\t</dict>\n"); | |
3291 | } | |
3292 | cupsFilePuts(fp, "</array>\n" | |
3293 | "</plist>\n"); | |
3294 | break; | |
3295 | ||
3296 | case PRINTCAP_SOLARIS : | |
ef416fc2 | 3297 | /* |
3298 | * Each printer is put in the file as: | |
3299 | * | |
3300 | * _all:all=Printer1,Printer2,Printer3,...,PrinterN | |
3301 | * _default:use=DefaultPrinter | |
3302 | * Printer1:\ | |
3303 | * :bsdaddr=ServerName,Printer1:\ | |
3304 | * :description=Description: | |
3305 | * Printer2: | |
3306 | * :bsdaddr=ServerName,Printer2:\ | |
3307 | * :description=Description: | |
3308 | * Printer3: | |
3309 | * :bsdaddr=ServerName,Printer3:\ | |
3310 | * :description=Description: | |
3311 | * ... | |
3312 | * PrinterN: | |
3313 | * :bsdaddr=ServerName,PrinterN:\ | |
3314 | * :description=Description: | |
3315 | */ | |
3316 | ||
3317 | cupsFilePuts(fp, "_all:all="); | |
3318 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
3319 | p; | |
3320 | p = (cupsd_printer_t *)cupsArrayCurrent(Printers)) | |
3321 | cupsFilePrintf(fp, "%s%c", p->name, | |
3322 | cupsArrayNext(Printers) ? ',' : '\n'); | |
3323 | ||
3324 | if (DefaultPrinter) | |
3325 | cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name); | |
3326 | ||
3327 | for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); | |
3328 | p; | |
3329 | p = (cupsd_printer_t *)cupsArrayNext(Printers)) | |
3330 | cupsFilePrintf(fp, "%s:\\\n" | |
c277e2f8 MS |
3331 | "\t:bsdaddr=%s,%s:\\\n" |
3332 | "\t:description=%s:\n", | |
3333 | p->name, ServerName, p->name, | |
3334 | p->info ? p->info : ""); | |
ef416fc2 | 3335 | break; |
3336 | } | |
3337 | } | |
3338 | ||
3339 | /* | |
3340 | * Close the file... | |
3341 | */ | |
3342 | ||
3343 | cupsFileClose(fp); | |
3344 | } | |
3345 | ||
3346 | ||
b423cd4c | 3347 | /* |
3348 | * 'add_printer_defaults()' - Add name-default attributes to the printer attributes. | |
3349 | */ | |
3350 | ||
3351 | static void | |
3352 | add_printer_defaults(cupsd_printer_t *p)/* I - Printer */ | |
3353 | { | |
3354 | int i; /* Looping var */ | |
3355 | int num_options; /* Number of default options */ | |
3356 | cups_option_t *options, /* Default options */ | |
3357 | *option; /* Current option */ | |
3358 | char name[256]; /* name-default */ | |
3359 | ||
3360 | ||
f7deaa1a | 3361 | /* |
3362 | * Maintain a common array of default attribute names... | |
3363 | */ | |
3364 | ||
3365 | if (!CommonDefaults) | |
3366 | { | |
3367 | CommonDefaults = cupsArrayNew((cups_array_func_t)strcmp, NULL); | |
3368 | ||
3369 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("copies-default")); | |
3370 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("document-format-default")); | |
3371 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("finishings-default")); | |
3372 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-hold-until-default")); | |
3373 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-priority-default")); | |
3374 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-sheets-default")); | |
3375 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("media-default")); | |
3376 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("number-up-default")); | |
3377 | cupsArrayAdd(CommonDefaults, | |
3378 | _cupsStrAlloc("orientation-requested-default")); | |
3379 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc("sides-default")); | |
3380 | } | |
3381 | ||
b423cd4c | 3382 | /* |
3383 | * Add all of the default options from the .conf files... | |
3384 | */ | |
3385 | ||
1f0275e3 | 3386 | for (num_options = 0, options = NULL, i = p->num_options, option = p->options; |
b423cd4c | 3387 | i > 0; |
3388 | i --, option ++) | |
3389 | { | |
3390 | if (strcmp(option->name, "ipp-options") && | |
3391 | strcmp(option->name, "job-sheets") && | |
3392 | strcmp(option->name, "lease-duration")) | |
3393 | { | |
3394 | snprintf(name, sizeof(name), "%s-default", option->name); | |
3395 | num_options = cupsAddOption(name, option->value, num_options, &options); | |
f7deaa1a | 3396 | |
3397 | if (!cupsArrayFind(CommonDefaults, name)) | |
3398 | cupsArrayAdd(CommonDefaults, _cupsStrAlloc(name)); | |
b423cd4c | 3399 | } |
3400 | } | |
3401 | ||
3402 | /* | |
3403 | * Convert options to IPP attributes... | |
3404 | */ | |
3405 | ||
3406 | cupsEncodeOptions2(p->attrs, num_options, options, IPP_TAG_PRINTER); | |
3407 | cupsFreeOptions(num_options, options); | |
3408 | ||
3409 | /* | |
3410 | * Add standard -default attributes as needed... | |
3411 | */ | |
3412 | ||
3413 | if (!cupsGetOption("copies", p->num_options, p->options)) | |
3414 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default", | |
3415 | 1); | |
3416 | ||
f7deaa1a | 3417 | if (!cupsGetOption("document-format", p->num_options, p->options)) |
c934a06c | 3418 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE, |
f7deaa1a | 3419 | "document-format-default", NULL, "application/octet-stream"); |
3420 | ||
b423cd4c | 3421 | if (!cupsGetOption("job-hold-until", p->num_options, p->options)) |
3422 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3423 | "job-hold-until-default", NULL, "no-hold"); | |
3424 | ||
3425 | if (!cupsGetOption("job-priority", p->num_options, p->options)) | |
3426 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3427 | "job-priority-default", 50); | |
3428 | ||
3429 | if (!cupsGetOption("number-up", p->num_options, p->options)) | |
3430 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3431 | "number-up-default", 1); | |
3432 | ||
3433 | if (!cupsGetOption("orientation-requested", p->num_options, p->options)) | |
c277e2f8 MS |
3434 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NOVALUE, |
3435 | "orientation-requested-default", NULL, NULL); | |
f7deaa1a | 3436 | |
3437 | if (!cupsGetOption("notify-lease-duration", p->num_options, p->options)) | |
3438 | ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3439 | "notify-lease-duration-default", DefaultLeaseDuration); | |
3440 | ||
3441 | if (!cupsGetOption("notify-events", p->num_options, p->options)) | |
3442 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3443 | "notify-events-default", NULL, "job-completed"); | |
b423cd4c | 3444 | } |
3445 | ||
3446 | ||
bd7854cb | 3447 | /* |
3448 | * 'add_printer_filter()' - Add a MIME filter for a printer. | |
3449 | */ | |
3450 | ||
3451 | static void | |
3452 | add_printer_filter( | |
3453 | cupsd_printer_t *p, /* I - Printer to add to */ | |
f7deaa1a | 3454 | mime_type_t *filtertype, /* I - Filter or prefilter MIME type */ |
bd7854cb | 3455 | const char *filter) /* I - Filter to add */ |
3456 | { | |
3457 | char super[MIME_MAX_SUPER], /* Super-type for filter */ | |
3458 | type[MIME_MAX_TYPE], /* Type for filter */ | |
3459 | program[1024]; /* Program/filter name */ | |
3460 | int cost; /* Cost of filter */ | |
3461 | mime_type_t *temptype; /* MIME type looping var */ | |
3462 | char filename[1024]; /* Full filter filename */ | |
3463 | ||
3464 | ||
3465 | /* | |
3466 | * Parse the filter string; it should be in the following format: | |
3467 | * | |
3468 | * super/type cost program | |
3469 | */ | |
3470 | ||
1f0275e3 MS |
3471 | if (sscanf(filter, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super, type, &cost, |
3472 | program) != 4) | |
bd7854cb | 3473 | { |
3474 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!", | |
3475 | p->name, filter); | |
3476 | return; | |
3477 | } | |
3478 | ||
3479 | /* | |
3480 | * See if the filter program exists; if not, stop the printer and flag | |
3481 | * the error! | |
3482 | */ | |
3483 | ||
ecdc0628 | 3484 | if (strcmp(program, "-")) |
bd7854cb | 3485 | { |
ecdc0628 | 3486 | if (program[0] == '/') |
3487 | strlcpy(filename, program, sizeof(filename)); | |
3488 | else | |
3489 | snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program); | |
3490 | ||
3491 | if (access(filename, X_OK)) | |
3492 | { | |
3493 | snprintf(p->state_message, sizeof(p->state_message), | |
3494 | "Filter \"%s\" for printer \"%s\" not available: %s", | |
3495 | program, p->name, strerror(errno)); | |
ecdc0628 | 3496 | cupsdSetPrinterReasons(p, "+cups-missing-filter-error"); |
07725fee | 3497 | cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 0); |
ecdc0628 | 3498 | |
3499 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s", p->state_message); | |
3500 | } | |
bd7854cb | 3501 | } |
3502 | ||
b423cd4c | 3503 | /* |
3504 | * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for | |
3505 | * application/vnd.cups-command... | |
3506 | */ | |
3507 | ||
3508 | if (!strcasecmp(super, "application") && | |
3509 | !strcasecmp(type, "vnd.cups-command")) | |
3510 | p->type |= CUPS_PRINTER_COMMANDS; | |
3511 | ||
bd7854cb | 3512 | /* |
3513 | * Add the filter to the MIME database, supporting wildcards as needed... | |
3514 | */ | |
3515 | ||
3516 | for (temptype = mimeFirstType(MimeDatabase); | |
3517 | temptype; | |
3518 | temptype = mimeNextType(MimeDatabase)) | |
3519 | if (((super[0] == '*' && strcasecmp(temptype->super, "printer")) || | |
3520 | !strcasecmp(temptype->super, super)) && | |
3521 | (type[0] == '*' || !strcasecmp(temptype->type, type))) | |
3522 | { | |
3523 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3524 | "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s", | |
3525 | p->name, temptype->super, temptype->type, | |
f7deaa1a | 3526 | filtertype->super, filtertype->type, |
bd7854cb | 3527 | cost, program); |
f7deaa1a | 3528 | mimeAddFilter(MimeDatabase, temptype, filtertype, cost, program); |
bd7854cb | 3529 | } |
3530 | } | |
3531 | ||
3532 | ||
3533 | /* | |
3534 | * 'add_printer_formats()' - Add document-format-supported values for a printer. | |
3535 | */ | |
3536 | ||
3537 | static void | |
3538 | add_printer_formats(cupsd_printer_t *p) /* I - Printer */ | |
3539 | { | |
3540 | int i; /* Looping var */ | |
3541 | mime_type_t *type; /* Current MIME type */ | |
3542 | cups_array_t *filters; /* Filters */ | |
80ca4592 | 3543 | ipp_attribute_t *attr; /* document-format-supported attribute */ |
bd7854cb | 3544 | char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2]; |
3545 | /* MIME type name */ | |
3546 | ||
3547 | ||
3548 | /* | |
3549 | * Raw (and remote) queues advertise all of the supported MIME | |
3550 | * types... | |
3551 | */ | |
3552 | ||
80ca4592 | 3553 | cupsArrayDelete(p->filetypes); |
3554 | p->filetypes = NULL; | |
3555 | ||
bd7854cb | 3556 | if (p->raw) |
3557 | { | |
3558 | ippAddStrings(p->attrs, IPP_TAG_PRINTER, | |
3559 | (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY), | |
3560 | "document-format-supported", NumMimeTypes, NULL, MimeTypes); | |
3561 | return; | |
3562 | } | |
3563 | ||
3564 | /* | |
3565 | * Otherwise, loop through the supported MIME types and see if there | |
3566 | * are filters for them... | |
3567 | */ | |
3568 | ||
bd7854cb | 3569 | cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters", |
3570 | mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase)); | |
3571 | ||
80ca4592 | 3572 | p->filetypes = cupsArrayNew(NULL, NULL); |
bd7854cb | 3573 | |
80ca4592 | 3574 | for (type = mimeFirstType(MimeDatabase); |
bd7854cb | 3575 | type; |
3576 | type = mimeNextType(MimeDatabase)) | |
3577 | { | |
bd7854cb | 3578 | snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type); |
3579 | ||
3580 | if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL) | |
3581 | { | |
3582 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3583 | "add_printer_formats: %s: %s needs %d filters", | |
3584 | p->name, mimetype, cupsArrayCount(filters)); | |
3585 | ||
3586 | cupsArrayDelete(filters); | |
80ca4592 | 3587 | cupsArrayAdd(p->filetypes, type); |
bd7854cb | 3588 | } |
3589 | else | |
3590 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3591 | "add_printer_formats: %s: %s not supported", | |
3592 | p->name, mimetype); | |
3593 | } | |
3594 | ||
3595 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
3596 | "add_printer_formats: %s: %d supported types", | |
80ca4592 | 3597 | p->name, cupsArrayCount(p->filetypes) + 1); |
bd7854cb | 3598 | |
3599 | /* | |
3600 | * Add the file formats that can be filtered... | |
3601 | */ | |
3602 | ||
f301802f | 3603 | if ((type = mimeType(MimeDatabase, "application", "octet-stream")) == NULL || |
3604 | !cupsArrayFind(p->filetypes, type)) | |
3605 | i = 1; | |
3606 | else | |
3607 | i = 0; | |
bd7854cb | 3608 | |
80ca4592 | 3609 | attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE, |
3610 | "document-format-supported", | |
3611 | cupsArrayCount(p->filetypes) + 1, NULL, NULL); | |
3612 | ||
f301802f | 3613 | if (i) |
3614 | attr->values[0].string.text = _cupsStrAlloc("application/octet-stream"); | |
bd7854cb | 3615 | |
f301802f | 3616 | for (type = (mime_type_t *)cupsArrayFirst(p->filetypes); |
80ca4592 | 3617 | type; |
3618 | i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes)) | |
3619 | { | |
3620 | snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type); | |
bd7854cb | 3621 | |
80ca4592 | 3622 | attr->values[i].string.text = _cupsStrAlloc(mimetype); |
3623 | } | |
f7deaa1a | 3624 | |
3625 | #ifdef HAVE_DNSSD | |
3626 | { | |
3627 | char pdl[1024]; /* Buffer to build pdl list */ | |
3628 | mime_filter_t *filter; /* MIME filter looping var */ | |
3629 | ||
3630 | ||
3631 | pdl[0] = '\0'; | |
3632 | ||
3633 | if (mimeType(MimeDatabase, "application", "pdf")) | |
3634 | strlcat(pdl, "application/pdf,", sizeof(pdl)); | |
3635 | ||
3636 | if (mimeType(MimeDatabase, "application", "postscript")) | |
3637 | strlcat(pdl, "application/postscript,", sizeof(pdl)); | |
3638 | ||
3639 | if (mimeType(MimeDatabase, "application", "vnd.cups-raster")) | |
3640 | strlcat(pdl, "application/vnd.cups-raster,", sizeof(pdl)); | |
3641 | ||
3642 | /* | |
3643 | * Determine if this is a Tioga PrintJobMgr based queue... | |
3644 | */ | |
3645 | ||
3646 | for (filter = (mime_filter_t *)cupsArrayFirst(MimeDatabase->filters); | |
3647 | filter; | |
3648 | filter = (mime_filter_t *)cupsArrayNext(MimeDatabase->filters)) | |
3649 | { | |
3650 | if (filter->dst == p->filetype && filter->filter && | |
3651 | strstr(filter->filter, "PrintJobMgr")) | |
3652 | break; | |
3653 | } | |
3654 | ||
3655 | /* | |
3656 | * We only support raw printing if this is not a Tioga PrintJobMgr based | |
3657 | * queue and if application/octet-stream is a known conversion... | |
3658 | */ | |
3659 | ||
3660 | if (!filter && mimeType(MimeDatabase, "application", "octet-stream")) | |
3661 | strlcat(pdl, "application/octet-stream,", sizeof(pdl)); | |
3662 | ||
3663 | if (mimeType(MimeDatabase, "image", "png")) | |
3664 | strlcat(pdl, "image/png,", sizeof(pdl)); | |
3665 | ||
3666 | if (pdl[0]) | |
3667 | pdl[strlen(pdl) - 1] = '\0'; /* Remove trailing comma */ | |
3668 | ||
3669 | cupsdSetString(&p->pdl, pdl); | |
3670 | } | |
3671 | #endif /* HAVE_DNSSD */ | |
bd7854cb | 3672 | } |
3673 | ||
3674 | ||
61cf44e2 MS |
3675 | /* |
3676 | * 'add_string_array()' - Add a string to an array of CUPS strings. | |
3677 | */ | |
3678 | ||
3679 | static void | |
3680 | add_string_array(cups_array_t **a, /* I - Array */ | |
3681 | const char *s) /* I - String */ | |
3682 | { | |
3683 | if (!*a) | |
3684 | *a = cupsArrayNew(NULL, NULL); | |
3685 | ||
3686 | cupsArrayAdd(*a, _cupsStrAlloc(s)); | |
3687 | } | |
3688 | ||
3689 | ||
ef416fc2 | 3690 | /* |
3691 | * 'compare_printers()' - Compare two printers. | |
3692 | */ | |
3693 | ||
3694 | static int /* O - Result of comparison */ | |
3695 | compare_printers(void *first, /* I - First printer */ | |
3696 | void *second, /* I - Second printer */ | |
3697 | void *data) /* I - App data (not used) */ | |
3698 | { | |
3699 | return (strcasecmp(((cupsd_printer_t *)first)->name, | |
3700 | ((cupsd_printer_t *)second)->name)); | |
3701 | } | |
3702 | ||
3703 | ||
bd7854cb | 3704 | /* |
e1d6a774 | 3705 | * 'delete_printer_filters()' - Delete all MIME filters for a printer. |
bd7854cb | 3706 | */ |
3707 | ||
3708 | static void | |
e1d6a774 | 3709 | delete_printer_filters( |
3710 | cupsd_printer_t *p) /* I - Printer to remove from */ | |
bd7854cb | 3711 | { |
e1d6a774 | 3712 | mime_filter_t *filter; /* MIME filter looping var */ |
bd7854cb | 3713 | |
bd7854cb | 3714 | |
3715 | /* | |
e1d6a774 | 3716 | * Range check input... |
bd7854cb | 3717 | */ |
3718 | ||
e1d6a774 | 3719 | if (p == NULL) |
3720 | return; | |
bd7854cb | 3721 | |
3722 | /* | |
e1d6a774 | 3723 | * Remove all filters from the MIME database that have a destination |
3724 | * type == printer... | |
bd7854cb | 3725 | */ |
3726 | ||
e1d6a774 | 3727 | for (filter = mimeFirstFilter(MimeDatabase); |
3728 | filter; | |
3729 | filter = mimeNextFilter(MimeDatabase)) | |
3730 | if (filter->dst == p->filetype) | |
3731 | { | |
3732 | /* | |
3733 | * Delete the current filter... | |
3734 | */ | |
bd7854cb | 3735 | |
e1d6a774 | 3736 | mimeDeleteFilter(MimeDatabase, filter); |
3737 | } | |
bd7854cb | 3738 | } |
3739 | ||
3740 | ||
61cf44e2 MS |
3741 | /* |
3742 | * 'delete_string_array()' - Delete an array of CUPS strings. | |
3743 | */ | |
3744 | ||
3745 | static void | |
3746 | delete_string_array(cups_array_t **a) /* I - Array */ | |
3747 | { | |
3748 | char *ptr; /* Current string */ | |
3749 | ||
3750 | ||
3751 | for (ptr = (char *)cupsArrayFirst(*a); | |
3752 | ptr; | |
3753 | ptr = (char *)cupsArrayNext(*a)) | |
3754 | _cupsStrFree(ptr); | |
3755 | ||
3756 | cupsArrayDelete(*a); | |
3757 | *a = NULL; | |
3758 | } | |
3759 | ||
3760 | ||
3761 | /* | |
3762 | * 'load_ppd()' - Load a cached PPD file, updating the cache as needed. | |
3763 | */ | |
3764 | ||
3765 | static void | |
3766 | load_ppd(cupsd_printer_t *p) /* I - Printer */ | |
3767 | { | |
3768 | int i; /* Looping var */ | |
3769 | cups_file_t *cache; /* Cache file */ | |
3770 | char cache_name[1024]; /* Cache filename */ | |
3771 | struct stat cache_info; /* Cache file info */ | |
3772 | ppd_file_t *ppd; /* PPD file */ | |
3773 | char ppd_name[1024]; /* PPD filename */ | |
3774 | struct stat ppd_info; /* PPD file info */ | |
3775 | int num_media; /* Number of media options */ | |
3776 | ppd_option_t *input_slot, /* InputSlot options */ | |
3777 | *media_type, /* MediaType options */ | |
3778 | *page_size, /* PageSize options */ | |
3779 | *output_bin, /* OutputBin options */ | |
3780 | *media_quality, /* EFMediaQualityMode options */ | |
3781 | *duplex; /* Duplex options */ | |
3782 | ppd_attr_t *ppd_attr; /* PPD attribute */ | |
3783 | ipp_attribute_t *attr; /* Attribute data */ | |
3784 | ipp_value_t *val; /* Attribute value */ | |
3785 | int num_finishings; /* Number of finishings */ | |
3786 | int finishings[5]; /* finishings-supported values */ | |
3787 | static const char * const sides[3] = /* sides-supported values */ | |
3788 | { | |
3789 | "one-sided", | |
3790 | "two-sided-long-edge", | |
3791 | "two-sided-short-edge" | |
3792 | }; | |
3793 | static const char * const standard_commands[] = | |
3794 | { /* Standard CUPS commands */ | |
3795 | "AutoConfigure", | |
3796 | "Clean", | |
3797 | "PrintSelfTestPage", | |
3798 | "ReportLevels" | |
3799 | }; | |
3800 | ||
3801 | ||
3802 | /* | |
3803 | * Check to see if the cache is up-to-date... | |
3804 | */ | |
3805 | ||
3806 | snprintf(cache_name, sizeof(cache_name), "%s/%s.ipp", CacheDir, p->name); | |
3807 | if (stat(cache_name, &cache_info)) | |
3808 | cache_info.st_mtime = 0; | |
3809 | ||
3810 | snprintf(ppd_name, sizeof(ppd_name), "%s/ppd/%s.ppd", ServerRoot, p->name); | |
3811 | if (stat(ppd_name, &ppd_info)) | |
3812 | ppd_info.st_mtime = 1; | |
3813 | ||
3814 | ippDelete(p->ppd_attrs); | |
3815 | p->ppd_attrs = ippNew(); | |
3816 | ||
3817 | if (cache_info.st_mtime >= ppd_info.st_mtime && | |
3818 | (cache = cupsFileOpen(cache_name, "r")) != NULL) | |
3819 | { | |
3820 | /* | |
3821 | * Load cached information and return... | |
3822 | */ | |
3823 | ||
3824 | cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", cache_name); | |
3825 | ||
3826 | if (ippReadIO(cache, (ipp_iocb_t)cupsFileRead, 1, NULL, | |
3827 | p->ppd_attrs) == IPP_DATA) | |
3828 | { | |
3829 | cupsFileClose(cache); | |
3830 | return; | |
3831 | } | |
3832 | ||
3833 | cupsFileClose(cache); | |
3834 | } | |
3835 | ||
3836 | /* | |
3837 | * Reload PPD attributes from disk... | |
3838 | */ | |
3839 | ||
8b450588 MS |
3840 | cupsdMarkDirty(CUPSD_DIRTY_PRINTERS); |
3841 | ||
61cf44e2 MS |
3842 | cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", ppd_name); |
3843 | ||
3844 | delete_string_array(&(p->filters)); | |
3845 | delete_string_array(&(p->pre_filters)); | |
3846 | ||
3847 | p->type &= ~CUPS_PRINTER_OPTIONS; | |
3848 | p->type |= CUPS_PRINTER_BW; | |
3849 | ||
3850 | finishings[0] = IPP_FINISHINGS_NONE; | |
3851 | num_finishings = 1; | |
3852 | ||
3853 | if ((ppd = ppdOpenFile(ppd_name)) != NULL) | |
3854 | { | |
3855 | /* | |
3856 | * Add make/model and other various attributes... | |
3857 | */ | |
3858 | ||
3859 | if (ppd->color_device) | |
3860 | p->type |= CUPS_PRINTER_COLOR; | |
3861 | if (ppd->variable_sizes) | |
3862 | p->type |= CUPS_PRINTER_VARIABLE; | |
3863 | if (!ppd->manual_copies) | |
3864 | p->type |= CUPS_PRINTER_COPIES; | |
3865 | if ((ppd_attr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL) | |
3866 | if (ppd_attr->value && !strcasecmp(ppd_attr->value, "true")) | |
3867 | p->type |= CUPS_PRINTER_FAX; | |
3868 | ||
3869 | ippAddBoolean(p->ppd_attrs, IPP_TAG_PRINTER, "color-supported", | |
3870 | ppd->color_device); | |
3871 | if (ppd->throughput) | |
3872 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, | |
3873 | "pages-per-minute", ppd->throughput); | |
3874 | ||
3875 | if (ppd->nickname) | |
3876 | { | |
3877 | /* | |
3878 | * The NickName can be localized in the character set specified | |
3879 | * by the LanugageEncoding attribute. However, ppdOpen2() has | |
3880 | * already converted the ppd->nickname member to UTF-8 for us | |
3881 | * (the original attribute value is available separately) | |
3882 | */ | |
3883 | ||
3884 | cupsdSetString(&p->make_model, ppd->nickname); | |
3885 | } | |
3886 | else if (ppd->modelname) | |
3887 | { | |
3888 | /* | |
3889 | * Model name can only contain specific characters... | |
3890 | */ | |
3891 | ||
3892 | cupsdSetString(&p->make_model, ppd->modelname); | |
3893 | } | |
3894 | else | |
3895 | cupsdSetString(&p->make_model, "Bad PPD File"); | |
3896 | ||
3897 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
3898 | "printer-make-and-model", NULL, p->make_model); | |
3899 | ||
3900 | /* | |
3901 | * Add media options from the PPD file... | |
3902 | */ | |
3903 | ||
3904 | if ((input_slot = ppdFindOption(ppd, "InputSlot")) != NULL) | |
3905 | num_media = input_slot->num_choices; | |
3906 | else | |
3907 | num_media = 0; | |
3908 | ||
3909 | if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL) | |
3910 | num_media += media_type->num_choices; | |
3911 | ||
3912 | if ((page_size = ppdFindOption(ppd, "PageSize")) != NULL) | |
3913 | num_media += page_size->num_choices; | |
3914 | ||
3915 | if ((media_quality = ppdFindOption(ppd, "EFMediaQualityMode")) != NULL) | |
3916 | num_media += media_quality->num_choices; | |
3917 | ||
3918 | if (num_media == 0) | |
3919 | { | |
3920 | cupsdLogMessage(CUPSD_LOG_CRIT, | |
3921 | "The PPD file for printer %s contains no media " | |
3922 | "options and is therefore invalid!", p->name); | |
3923 | } | |
3924 | else | |
3925 | { | |
3926 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3927 | "media-supported", num_media, NULL, NULL); | |
3928 | if (attr != NULL) | |
3929 | { | |
3930 | val = attr->values; | |
3931 | ||
3932 | if (input_slot != NULL) | |
3933 | for (i = 0; i < input_slot->num_choices; i ++, val ++) | |
3934 | val->string.text = _cupsStrAlloc(input_slot->choices[i].choice); | |
3935 | ||
3936 | if (media_type != NULL) | |
3937 | for (i = 0; i < media_type->num_choices; i ++, val ++) | |
3938 | val->string.text = _cupsStrAlloc(media_type->choices[i].choice); | |
3939 | ||
3940 | if (media_quality != NULL) | |
3941 | for (i = 0; i < media_quality->num_choices; i ++, val ++) | |
3942 | val->string.text = _cupsStrAlloc(media_quality->choices[i].choice); | |
3943 | ||
3944 | if (page_size != NULL) | |
3945 | { | |
3946 | for (i = 0; i < page_size->num_choices; i ++, val ++) | |
3947 | val->string.text = _cupsStrAlloc(page_size->choices[i].choice); | |
3948 | ||
3949 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3950 | "media-default", NULL, page_size->defchoice); | |
3951 | } | |
3952 | else if (input_slot != NULL) | |
3953 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3954 | "media-default", NULL, input_slot->defchoice); | |
3955 | else if (media_type != NULL) | |
3956 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3957 | "media-default", NULL, media_type->defchoice); | |
3958 | else if (media_quality != NULL) | |
3959 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3960 | "media-default", NULL, media_quality->defchoice); | |
3961 | else | |
3962 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3963 | "media-default", NULL, "none"); | |
3964 | } | |
3965 | } | |
3966 | ||
3967 | /* | |
3968 | * Output bin... | |
3969 | */ | |
3970 | ||
3971 | if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL) | |
3972 | { | |
3973 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
3974 | "output-bin-supported", output_bin->num_choices, | |
3975 | NULL, NULL); | |
3976 | ||
3977 | if (attr != NULL) | |
3978 | { | |
3979 | for (i = 0, val = attr->values; | |
3980 | i < output_bin->num_choices; | |
3981 | i ++, val ++) | |
3982 | val->string.text = _cupsStrAlloc(output_bin->choices[i].choice); | |
3983 | } | |
3984 | } | |
3985 | ||
3986 | /* | |
3987 | * Duplexing, etc... | |
3988 | */ | |
3989 | ||
3990 | if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL) | |
3991 | if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL) | |
3992 | if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL) | |
3993 | if ((duplex = ppdFindOption(ppd, "KD03Duplex")) == NULL) | |
3994 | duplex = ppdFindOption(ppd, "JCLDuplex"); | |
3995 | ||
3996 | if (duplex && duplex->num_choices > 1 && | |
3997 | !ppdInstallableConflict(ppd, duplex->keyword, "DuplexTumble")) | |
3998 | { | |
3999 | p->type |= CUPS_PRINTER_DUPLEX; | |
4000 | ||
4001 | ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4002 | "sides-supported", 3, NULL, sides); | |
4003 | ||
4004 | if (!strcasecmp(duplex->defchoice, "DuplexTumble")) | |
4005 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4006 | "sides-default", NULL, "two-sided-short-edge"); | |
4007 | else if (!strcasecmp(duplex->defchoice, "DuplexNoTumble")) | |
4008 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4009 | "sides-default", NULL, "two-sided-long-edge"); | |
4010 | else | |
4011 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4012 | "sides-default", NULL, "one-sided"); | |
4013 | } | |
4014 | ||
4015 | if (ppdFindOption(ppd, "Collate") != NULL) | |
4016 | p->type |= CUPS_PRINTER_COLLATE; | |
4017 | ||
4018 | if (ppdFindOption(ppd, "StapleLocation") != NULL) | |
4019 | { | |
4020 | p->type |= CUPS_PRINTER_STAPLE; | |
4021 | finishings[num_finishings++] = IPP_FINISHINGS_STAPLE; | |
4022 | } | |
4023 | ||
4024 | if (ppdFindOption(ppd, "BindEdge") != NULL) | |
4025 | { | |
4026 | p->type |= CUPS_PRINTER_BIND; | |
4027 | finishings[num_finishings++] = IPP_FINISHINGS_BIND; | |
4028 | } | |
4029 | ||
4030 | for (i = 0; i < ppd->num_sizes; i ++) | |
4031 | if (ppd->sizes[i].length > 1728) | |
4032 | p->type |= CUPS_PRINTER_LARGE; | |
4033 | else if (ppd->sizes[i].length > 1008) | |
4034 | p->type |= CUPS_PRINTER_MEDIUM; | |
4035 | else | |
4036 | p->type |= CUPS_PRINTER_SMALL; | |
4037 | ||
4038 | /* | |
4039 | * Add a filter from application/vnd.cups-raw to printer/name to | |
4040 | * handle "raw" printing by users. | |
4041 | */ | |
4042 | ||
4043 | add_string_array(&(p->filters), "application/vnd.cups-raw 0 -"); | |
4044 | ||
4045 | /* | |
4046 | * Add any pre-filters in the PPD file... | |
4047 | */ | |
4048 | ||
4049 | if ((ppd_attr = ppdFindAttr(ppd, "cupsPreFilter", NULL)) != NULL) | |
4050 | { | |
4051 | for (; ppd_attr; ppd_attr = ppdFindNextAttr(ppd, "cupsPreFilter", NULL)) | |
4052 | if (ppd_attr->value) | |
4053 | add_string_array(&(p->pre_filters), ppd_attr->value); | |
4054 | } | |
4055 | ||
4056 | /* | |
4057 | * Add any filters in the PPD file... | |
4058 | */ | |
4059 | ||
4060 | DEBUG_printf(("ppd->num_filters = %d\n", ppd->num_filters)); | |
4061 | for (i = 0; i < ppd->num_filters; i ++) | |
4062 | { | |
4063 | DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i, ppd->filters[i])); | |
4064 | add_string_array(&(p->filters), ppd->filters[i]); | |
4065 | } | |
4066 | ||
4067 | if (ppd->num_filters == 0) | |
4068 | { | |
4069 | /* | |
4070 | * If there are no filters, add PostScript printing filters. | |
4071 | */ | |
4072 | ||
4073 | add_string_array(&(p->filters), | |
4074 | "application/vnd.cups-command 0 commandtops"); | |
4075 | add_string_array(&(p->filters), | |
4076 | "application/vnd.cups-postscript 0 -"); | |
4077 | ||
4078 | p->type |= CUPS_PRINTER_COMMANDS; | |
4079 | } | |
4080 | else if (!(p->type & CUPS_PRINTER_COMMANDS)) | |
4081 | { | |
4082 | /* | |
4083 | * See if this is a PostScript device without a command filter... | |
4084 | */ | |
4085 | ||
4086 | for (i = 0; i < ppd->num_filters; i ++) | |
4087 | if (!strncasecmp(ppd->filters[i], | |
4088 | "application/vnd.cups-postscript", 31)) | |
4089 | break; | |
4090 | ||
4091 | if (i < ppd->num_filters) | |
4092 | { | |
4093 | /* | |
4094 | * Add the generic PostScript command filter... | |
4095 | */ | |
4096 | ||
4097 | add_string_array(&(p->filters), | |
4098 | "application/vnd.cups-command 0 commandtops"); | |
4099 | p->type |= CUPS_PRINTER_COMMANDS; | |
4100 | } | |
4101 | } | |
4102 | ||
4103 | if (p->type & CUPS_PRINTER_COMMANDS) | |
4104 | { | |
4105 | char *commands, /* Copy of commands */ | |
4106 | *start, /* Start of name */ | |
4107 | *end; /* End of name */ | |
4108 | int count; /* Number of commands */ | |
4109 | ||
4110 | ||
4111 | if ((ppd_attr = ppdFindAttr(ppd, "cupsCommands", NULL)) != NULL && | |
4112 | ppd_attr->value && ppd_attr->value[0]) | |
4113 | { | |
4114 | for (count = 0, start = ppd_attr->value; *start; count ++) | |
4115 | { | |
4116 | while (isspace(*start & 255)) | |
4117 | start ++; | |
4118 | ||
4119 | if (!*start) | |
4120 | break; | |
4121 | ||
4122 | while (*start && !isspace(*start & 255)) | |
4123 | start ++; | |
4124 | } | |
4125 | } | |
4126 | else | |
4127 | count = 0; | |
4128 | ||
4129 | if (count > 0) | |
4130 | { | |
4131 | /* | |
4132 | * Make a copy of the commands string and count how many ... | |
4133 | */ | |
4134 | ||
4135 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4136 | "printer-commands", count, NULL, NULL); | |
4137 | ||
4138 | commands = strdup(ppd_attr->value); | |
4139 | ||
4140 | for (count = 0, start = commands; *start; count ++) | |
4141 | { | |
4142 | while (isspace(*start & 255)) | |
4143 | start ++; | |
4144 | ||
4145 | if (!*start) | |
4146 | break; | |
4147 | ||
4148 | end = start; | |
4149 | while (*end && !isspace(*end & 255)) | |
4150 | end ++; | |
4151 | ||
4152 | if (*end) | |
4153 | *end++ = '\0'; | |
4154 | ||
4155 | attr->values[count].string.text = _cupsStrAlloc(start); | |
4156 | ||
4157 | start = end; | |
4158 | } | |
4159 | ||
4160 | free(commands); | |
4161 | } | |
4162 | else | |
4163 | { | |
4164 | /* | |
4165 | * Add the standard list of commands... | |
4166 | */ | |
4167 | ||
4168 | ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4169 | "printer-commands", | |
4170 | (int)(sizeof(standard_commands) / | |
4171 | sizeof(standard_commands[0])), NULL, | |
4172 | standard_commands); | |
4173 | } | |
4174 | } | |
4175 | else | |
4176 | { | |
4177 | /* | |
4178 | * No commands supported... | |
4179 | */ | |
4180 | ||
4181 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, | |
4182 | "printer-commands", NULL, "none"); | |
4183 | } | |
4184 | ||
4185 | /* | |
4186 | * Show current and available port monitors for this printer... | |
4187 | */ | |
4188 | ||
4189 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor", | |
4190 | NULL, p->port_monitor ? p->port_monitor : "none"); | |
4191 | ||
4192 | for (i = 1, ppd_attr = ppdFindAttr(ppd, "cupsPortMonitor", NULL); | |
4193 | ppd_attr; | |
4194 | i ++, ppd_attr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL)); | |
4195 | ||
4196 | if (ppd->protocols) | |
4197 | { | |
4198 | if (strstr(ppd->protocols, "TBCP")) | |
4199 | i ++; | |
4200 | else if (strstr(ppd->protocols, "BCP")) | |
4201 | i ++; | |
4202 | } | |
4203 | ||
4204 | attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, | |
4205 | "port-monitor-supported", i, NULL, NULL); | |
4206 | ||
4207 | attr->values[0].string.text = _cupsStrAlloc("none"); | |
4208 | ||
4209 | for (i = 1, ppd_attr = ppdFindAttr(ppd, "cupsPortMonitor", NULL); | |
4210 | ppd_attr; | |
4211 | i ++, ppd_attr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL)) | |
4212 | attr->values[i].string.text = _cupsStrAlloc(ppd_attr->value); | |
4213 | ||
4214 | if (ppd->protocols) | |
4215 | { | |
4216 | if (strstr(ppd->protocols, "TBCP")) | |
4217 | attr->values[i].string.text = _cupsStrAlloc("tbcp"); | |
4218 | else if (strstr(ppd->protocols, "BCP")) | |
4219 | attr->values[i].string.text = _cupsStrAlloc("bcp"); | |
4220 | } | |
4221 | ||
4222 | #ifdef HAVE_DNSSD | |
4223 | cupsdSetString(&p->product, ppd->product); | |
4224 | #endif /* HAVE_DNSSD */ | |
4225 | ||
4226 | if (ppdFindAttr(ppd, "APRemoteQueueID", NULL)) | |
4227 | p->type |= CUPS_PRINTER_REMOTE; | |
4228 | ||
4229 | /* | |
4230 | * Close the PPD and set the type... | |
4231 | */ | |
4232 | ||
4233 | ppdClose(ppd); | |
4234 | } | |
4235 | else if (!access(ppd_name, 0)) | |
4236 | { | |
4237 | int pline; /* PPD line number */ | |
4238 | ppd_status_t pstatus; /* PPD load status */ | |
4239 | ||
4240 | ||
4241 | pstatus = ppdLastError(&pline); | |
4242 | ||
4243 | cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!", | |
4244 | p->name); | |
4245 | ||
4246 | if (pstatus <= PPD_ALLOC_ERROR) | |
4247 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno)); | |
4248 | else | |
4249 | cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.", | |
4250 | ppdErrorString(pstatus), pline); | |
4251 | ||
4252 | cupsdLogMessage(CUPSD_LOG_INFO, | |
4253 | "Hint: Run \"cupstestppd %s\" and fix any errors.", | |
4254 | ppd_name); | |
4255 | ||
4256 | /* | |
4257 | * Add a filter from application/vnd.cups-raw to printer/name to | |
4258 | * handle "raw" printing by users. | |
4259 | */ | |
4260 | ||
4261 | add_string_array(&(p->filters), "application/vnd.cups-raw 0 -"); | |
4262 | ||
4263 | /* | |
4264 | * Add a PostScript filter, since this is still possibly PS printer. | |
4265 | */ | |
4266 | ||
4267 | add_string_array(&(p->filters), "application/vnd.cups-postscript 0 -"); | |
4268 | } | |
4269 | else | |
4270 | { | |
4271 | /* | |
4272 | * If we have an interface script, add a filter entry for it... | |
4273 | */ | |
4274 | ||
4275 | char interface[1024]; /* Interface script */ | |
4276 | ||
4277 | ||
4278 | snprintf(interface, sizeof(interface), "%s/interfaces/%s", ServerRoot, | |
4279 | p->name); | |
4280 | if (!access(interface, X_OK)) | |
4281 | { | |
4282 | /* | |
4283 | * Yes, we have a System V style interface script; use it! | |
4284 | */ | |
4285 | ||
4286 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
4287 | "printer-make-and-model", NULL, | |
4288 | "Local System V Printer"); | |
4289 | ||
4290 | snprintf(interface, sizeof(interface), "*/* 0 %s/interfaces/%s", | |
4291 | ServerRoot, p->name); | |
4292 | add_string_array(&(p->filters), interface); | |
4293 | } | |
4294 | else if (!strncmp(p->device_uri, "ipp://", 6) && | |
4295 | (strstr(p->device_uri, "/printers/") != NULL || | |
4296 | strstr(p->device_uri, "/classes/") != NULL || | |
4297 | (strstr(p->device_uri, "._ipp.") != NULL && | |
4298 | !strcmp(p->device_uri + strlen(p->device_uri) - 5, | |
4299 | "/cups")))) | |
4300 | { | |
4301 | /* | |
4302 | * Tell the client this is really a hard-wired remote printer. | |
4303 | */ | |
4304 | ||
4305 | p->type |= CUPS_PRINTER_REMOTE; | |
4306 | ||
4307 | /* | |
4308 | * Point the printer-uri-supported attribute to the | |
4309 | * remote printer... | |
4310 | */ | |
4311 | ||
4312 | ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, | |
4313 | "printer-uri-supported", NULL, p->device_uri); | |
4314 | ||
4315 | /* | |
4316 | * Then set the make-and-model accordingly... | |
4317 | */ | |
4318 | ||
4319 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
4320 | "printer-make-and-model", NULL, "Remote Printer"); | |
4321 | ||
4322 | /* | |
4323 | * Print all files directly... | |
4324 | */ | |
4325 | ||
4326 | p->raw = 1; | |
4327 | p->remote = 1; | |
4328 | } | |
4329 | else | |
4330 | { | |
4331 | /* | |
4332 | * Otherwise we have neither - treat this as a "dumb" printer | |
4333 | * with no PPD file... | |
4334 | */ | |
4335 | ||
4336 | ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, | |
4337 | "printer-make-and-model", NULL, "Local Raw Printer"); | |
4338 | ||
4339 | p->raw = 1; | |
4340 | } | |
4341 | } | |
4342 | ||
4343 | ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
4344 | "finishings-supported", num_finishings, finishings); | |
4345 | ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, | |
4346 | "finishings-default", IPP_FINISHINGS_NONE); | |
4347 | ||
4348 | if (ppd && (cache = cupsFileOpen(cache_name, "w")) != NULL) | |
4349 | { | |
4350 | /* | |
4351 | * Save cached PPD attributes to disk... | |
4352 | */ | |
4353 | ||
4354 | cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Saving %s...", cache_name); | |
4355 | ||
4356 | p->ppd_attrs->state = IPP_IDLE; | |
4357 | ||
4358 | if (ippWriteIO(cache, (ipp_iocb_t)cupsFileWrite, 1, NULL, | |
4359 | p->ppd_attrs) != IPP_DATA) | |
4360 | { | |
4361 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
4362 | "Unable to save PPD cache file \"%s\" - %s", cache_name, | |
4363 | strerror(errno)); | |
4364 | unlink(cache_name); | |
4365 | } | |
4366 | ||
4367 | cupsFileClose(cache); | |
4368 | } | |
4369 | else if (cache_info.st_mtime) | |
4370 | { | |
4371 | /* | |
4372 | * Remove cache file... | |
4373 | */ | |
4374 | ||
4375 | unlink(cache_name); | |
4376 | } | |
4377 | } | |
4378 | ||
4379 | ||
ef416fc2 | 4380 | #ifdef __sgi |
4381 | /* | |
4382 | * 'write_irix_config()' - Update the config files used by the IRIX | |
4383 | * desktop tools. | |
4384 | */ | |
4385 | ||
4386 | static void | |
4387 | write_irix_config(cupsd_printer_t *p) /* I - Printer to update */ | |
4388 | { | |
4389 | char filename[1024]; /* Interface script filename */ | |
4390 | cups_file_t *fp; /* Interface script file */ | |
f301802f | 4391 | ipp_attribute_t *attr; /* Attribute data */ |
ef416fc2 | 4392 | |
4393 | ||
4394 | /* | |
4395 | * Add dummy interface and GUI scripts to fool SGI's "challenged" printing | |
4396 | * tools. First the interface script that tells the tools what kind of | |
4397 | * printer we have... | |
4398 | */ | |
4399 | ||
4400 | snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name); | |
4401 | ||
4402 | if (p->type & CUPS_PRINTER_CLASS) | |
4403 | unlink(filename); | |
4404 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
4405 | { | |
4406 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
4407 | ||
4408 | if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model", | |
4409 | IPP_TAG_TEXT)) != NULL) | |
4410 | cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text); | |
4411 | else if (p->type & CUPS_PRINTER_CLASS) | |
4412 | cupsFilePuts(fp, "NAME=\"Printer Class\"\n"); | |
4413 | else | |
4414 | cupsFilePuts(fp, "NAME=\"Remote Destination\"\n"); | |
4415 | ||
4416 | if (p->type & CUPS_PRINTER_COLOR) | |
4417 | cupsFilePuts(fp, "TYPE=ColorPostScript\n"); | |
4418 | else | |
4419 | cupsFilePuts(fp, "TYPE=MonoPostScript\n"); | |
4420 | ||
4421 | cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName); | |
4422 | cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name); | |
4423 | ||
4424 | cupsFileClose(fp); | |
4425 | ||
4426 | chmod(filename, 0755); | |
4427 | chown(filename, User, Group); | |
4428 | } | |
4429 | ||
4430 | /* | |
4431 | * Then the member file that tells which device file the queue is connected | |
4432 | * to... Networked printers use "/dev/null" in this file, so that's what | |
4433 | * we use (the actual device URI can confuse some apps...) | |
4434 | */ | |
4435 | ||
4436 | snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name); | |
4437 | ||
4438 | if (p->type & CUPS_PRINTER_CLASS) | |
4439 | unlink(filename); | |
4440 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
4441 | { | |
4442 | cupsFilePuts(fp, "/dev/null\n"); | |
4443 | ||
4444 | cupsFileClose(fp); | |
4445 | ||
4446 | chmod(filename, 0644); | |
4447 | chown(filename, User, Group); | |
4448 | } | |
4449 | ||
4450 | /* | |
4451 | * The gui_interface file is a script or program that launches a GUI | |
4452 | * option panel for the printer, using options specified on the | |
4453 | * command-line in the third argument. The option panel must send | |
4454 | * any printing options to stdout on a single line when the user | |
4455 | * accepts them, or nothing if the user cancels the dialog. | |
4456 | * | |
4457 | * The default options panel program is /usr/bin/glpoptions, from | |
4458 | * the ESP Print Pro software. You can select another using the | |
4459 | * PrintcapGUI option. | |
4460 | */ | |
4461 | ||
4462 | snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", p->name); | |
4463 | ||
4464 | if (p->type & CUPS_PRINTER_CLASS) | |
4465 | unlink(filename); | |
4466 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
4467 | { | |
4468 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
4469 | cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name); | |
4470 | ||
4471 | cupsFileClose(fp); | |
4472 | ||
4473 | chmod(filename, 0755); | |
4474 | chown(filename, User, Group); | |
4475 | } | |
4476 | ||
4477 | /* | |
4478 | * The POD config file is needed by the printstatus command to show | |
4479 | * the printer location and device. | |
4480 | */ | |
4481 | ||
4482 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", 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, "Printer Class | %s\n", | |
4489 | (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript"); | |
4490 | cupsFilePrintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : ""); | |
4491 | cupsFilePrintf(fp, "Location Code | %s\n", p->location ? p->location : ""); | |
4492 | cupsFilePrintf(fp, "Physical Location | %s\n", p->info ? p->info : ""); | |
0af14961 | 4493 | cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri); |
ef416fc2 | 4494 | cupsFilePrintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name); |
4495 | cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name); | |
4496 | cupsFilePuts(fp, "Status Update Wait | 10 seconds\n"); | |
4497 | ||
4498 | cupsFileClose(fp); | |
4499 | ||
4500 | chmod(filename, 0664); | |
4501 | chown(filename, User, Group); | |
4502 | } | |
4503 | } | |
4504 | ||
4505 | ||
4506 | /* | |
4507 | * 'write_irix_state()' - Update the status files used by IRIX printing | |
4508 | * desktop tools. | |
4509 | */ | |
4510 | ||
4511 | static void | |
4512 | write_irix_state(cupsd_printer_t *p) /* I - Printer to update */ | |
4513 | { | |
4514 | char filename[1024]; /* Interface script filename */ | |
4515 | cups_file_t *fp; /* Interface script file */ | |
4516 | int tag; /* Status tag value */ | |
4517 | ||
4518 | ||
4519 | if (p) | |
4520 | { | |
4521 | /* | |
4522 | * The POD status file is needed for the printstatus window to | |
4523 | * provide the current status of the printer. | |
4524 | */ | |
4525 | ||
4526 | snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name); | |
4527 | ||
4528 | if (p->type & CUPS_PRINTER_CLASS) | |
4529 | unlink(filename); | |
4530 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
4531 | { | |
4532 | cupsFilePrintf(fp, "Operational Status | %s\n", | |
4533 | (p->state == IPP_PRINTER_IDLE) ? "Idle" : | |
4534 | (p->state == IPP_PRINTER_PROCESSING) ? "Busy" : | |
4535 | "Faulted"); | |
4536 | cupsFilePrintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION); | |
4537 | cupsFilePrintf(fp, "Information | 02 00 00 | Device URI: %s\n", | |
0af14961 | 4538 | p->device_uri); |
ef416fc2 | 4539 | cupsFilePrintf(fp, "Information | 03 00 00 | %s jobs\n", |
4540 | p->accepting ? "Accepting" : "Not accepting"); | |
4541 | cupsFilePrintf(fp, "Information | 04 00 00 | %s\n", p->state_message); | |
4542 | ||
4543 | cupsFileClose(fp); | |
4544 | ||
4545 | chmod(filename, 0664); | |
4546 | chown(filename, User, Group); | |
4547 | } | |
4548 | ||
4549 | /* | |
4550 | * The activeicons file is needed to provide desktop icons for printers: | |
4551 | * | |
4552 | * [ quoted from /usr/lib/print/tagit ] | |
4553 | * | |
4554 | * --- Type of printer tags (base values) | |
4555 | * | |
4556 | * Dumb=66048 # 0x10200 | |
4557 | * DumbColor=66080 # 0x10220 | |
4558 | * Raster=66112 # 0x10240 | |
4559 | * ColorRaster=66144 # 0x10260 | |
4560 | * Plotter=66176 # 0x10280 | |
4561 | * PostScript=66208 # 0x102A0 | |
4562 | * ColorPostScript=66240 # 0x102C0 | |
4563 | * MonoPostScript=66272 # 0x102E0 | |
4564 | * | |
4565 | * --- Printer state modifiers for local printers | |
4566 | * | |
4567 | * Idle=0 # 0x0 | |
4568 | * Busy=1 # 0x1 | |
4569 | * Faulted=2 # 0x2 | |
4570 | * Unknown=3 # 0x3 (Faulted due to unknown reason) | |
4571 | * | |
4572 | * --- Printer state modifiers for network printers | |
4573 | * | |
4574 | * NetIdle=8 # 0x8 | |
4575 | * NetBusy=9 # 0x9 | |
4576 | * NetFaulted=10 # 0xA | |
4577 | * NetUnknown=11 # 0xB (Faulted due to unknown reason) | |
4578 | */ | |
4579 | ||
4580 | snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name); | |
4581 | ||
4582 | if (p->type & CUPS_PRINTER_CLASS) | |
4583 | unlink(filename); | |
4584 | else if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
4585 | { | |
4586 | if (p->type & CUPS_PRINTER_COLOR) | |
4587 | tag = 66240; | |
4588 | else | |
4589 | tag = 66272; | |
4590 | ||
4591 | if (p->type & CUPS_PRINTER_REMOTE) | |
4592 | tag |= 8; | |
4593 | ||
4594 | if (p->state == IPP_PRINTER_PROCESSING) | |
4595 | tag |= 1; | |
4596 | ||
4597 | else if (p->state == IPP_PRINTER_STOPPED) | |
4598 | tag |= 2; | |
4599 | ||
4600 | cupsFilePuts(fp, "#!/bin/sh\n"); | |
4601 | cupsFilePrintf(fp, "#Tag %d\n", tag); | |
4602 | ||
4603 | cupsFileClose(fp); | |
4604 | ||
4605 | chmod(filename, 0755); | |
4606 | chown(filename, User, Group); | |
4607 | } | |
4608 | } | |
4609 | ||
4610 | /* | |
4611 | * The default file is needed by the printers window to show | |
4612 | * the default printer. | |
4613 | */ | |
4614 | ||
4615 | snprintf(filename, sizeof(filename), "/var/spool/lp/default"); | |
4616 | ||
4617 | if (DefaultPrinter != NULL) | |
4618 | { | |
4619 | if ((fp = cupsFileOpen(filename, "w")) != NULL) | |
4620 | { | |
4621 | cupsFilePrintf(fp, "%s\n", DefaultPrinter->name); | |
4622 | ||
4623 | cupsFileClose(fp); | |
4624 | ||
4625 | chmod(filename, 0644); | |
4626 | chown(filename, User, Group); | |
4627 | } | |
4628 | } | |
4629 | else | |
4630 | unlink(filename); | |
4631 | } | |
4632 | #endif /* __sgi */ | |
4633 | ||
4634 | ||
4635 | /* | |
0af14961 MS |
4636 | * 'write_xml_string()' - Write a string with XML escaping. |
4637 | */ | |
4638 | ||
4639 | static void | |
4640 | write_xml_string(cups_file_t *fp, /* I - File to write to */ | |
4641 | const char *s) /* I - String to write */ | |
4642 | { | |
4643 | const char *start; /* Start of current sequence */ | |
4644 | ||
4645 | ||
4646 | if (!s) | |
4647 | return; | |
4648 | ||
4649 | for (start = s; *s; s ++) | |
4650 | { | |
4651 | if (*s == '&') | |
4652 | { | |
4653 | if (s > start) | |
4654 | cupsFileWrite(fp, start, s - start); | |
4655 | ||
4656 | cupsFilePuts(fp, "&"); | |
4657 | start = s + 1; | |
4658 | } | |
4659 | else if (*s == '<') | |
4660 | { | |
4661 | if (s > start) | |
4662 | cupsFileWrite(fp, start, s - start); | |
4663 | ||
4664 | cupsFilePuts(fp, "<"); | |
4665 | start = s + 1; | |
4666 | } | |
4667 | } | |
4668 | ||
4669 | if (s > start) | |
4670 | cupsFilePuts(fp, start); | |
4671 | } | |
4672 | ||
4673 | ||
4674 | /* | |
4675 | * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $". | |
ef416fc2 | 4676 | */ |