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