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