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