]> git.ipfire.org Git - thirdparty/cups.git/blame - scheduler/printers.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / printers.c
CommitLineData
ef416fc2 1/*
f7deaa1a 2 * "$Id: printers.c 6318 2007-03-06 04:36:55Z mike $"
ef416fc2 3 *
4 * Printer routines for the Common UNIX Printing System (CUPS).
5 *
f7deaa1a 6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * cupsdAddPrinter() - Add a printer to the system.
ef416fc2 27 * cupsdAddPrinterHistory() - Add the current printer state to the history.
28 * cupsdAddPrinterUser() - Add a user to the ACL.
29 * cupsdDeleteAllPrinters() - Delete all printers from the system.
30 * cupsdDeletePrinter() - Delete a printer from the system.
ef416fc2 31 * cupsdFindPrinter() - Find a printer in the list.
32 * cupsdFreePrinterUsers() - Free allow/deny users.
33 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
b423cd4c 34 * cupsdRenamePrinter() - Rename a printer.
fa73b229 35 * cupsdSaveAllPrinters() - Save all printer definitions to the
36 * printers.conf file.
37 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
38 * file.
ef416fc2 39 * cupsdSetPrinterReasons() - Set/update the reasons strings.
40 * cupsdSetPrinterState() - Update the current state of a printer.
41 * cupsdStopPrinter() - Stop a printer from printing any jobs...
42 * cupsdUpdatePrinters() - Update printers after a partial reload.
43 * cupsdValidateDest() - Validate a printer/class destination.
44 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
45 * applications that need it...
46 * cupsdSanitizeURI() - Sanitize a device URI...
b423cd4c 47 * add_printer_defaults() - Add name-default attributes to the printer
48 * attributes.
bd7854cb 49 * add_printer_filter() - Add a MIME filter for a printer.
50 * add_printer_formats() - Add document-format-supported values for
51 * a printer.
ef416fc2 52 * compare_printers() - Compare two printers.
e1d6a774 53 * delete_printer_filters() - Delete all MIME filters for a printer.
ef416fc2 54 * write_irix_config() - Update the config files used by the IRIX
55 * desktop tools.
fa73b229 56 * write_irix_state() - Update the status files used by IRIX
57 * printing desktop tools.
ef416fc2 58 */
59
60/*
61 * Include necessary headers...
62 */
63
64#include "cupsd.h"
ed486911 65#include <cups/dir.h>
ef416fc2 66
67
68/*
69 * Local functions...
70 */
71
b423cd4c 72static void add_printer_defaults(cupsd_printer_t *p);
f7deaa1a 73static void add_printer_filter(cupsd_printer_t *p, mime_type_t *type,
74 const char *filter);
bd7854cb 75static void add_printer_formats(cupsd_printer_t *p);
ef416fc2 76static int compare_printers(void *first, void *second, void *data);
e1d6a774 77static void delete_printer_filters(cupsd_printer_t *p);
ef416fc2 78#ifdef __sgi
79static void write_irix_config(cupsd_printer_t *p);
80static void write_irix_state(cupsd_printer_t *p);
81#endif /* __sgi */
82
83
84/*
85 * 'cupsdAddPrinter()' - Add a printer to the system.
86 */
87
88cupsd_printer_t * /* O - New printer */
89cupsdAddPrinter(const char *name) /* I - Name of printer */
90{
91 cupsd_printer_t *p; /* New printer */
92
93
94 /*
95 * Range check input...
96 */
97
98 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdAddPrinter(\"%s\")", name);
99
100 /*
101 * Create a new printer entity...
102 */
103
104 if ((p = calloc(1, sizeof(cupsd_printer_t))) == NULL)
105 {
106 cupsdLogMessage(CUPSD_LOG_CRIT, "Unable to allocate memory for printer - %s",
107 strerror(errno));
108 return (NULL);
109 }
110
111 cupsdSetString(&p->name, name);
112 cupsdSetString(&p->info, name);
113 cupsdSetString(&p->hostname, ServerName);
114
115 cupsdSetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName, LocalPort, name);
116 cupsdSetStringf(&p->device_uri, "file:/dev/null");
117
118 p->state = IPP_PRINTER_STOPPED;
119 p->state_time = time(NULL);
120 p->accepting = 0;
fa73b229 121 p->shared = DefaultShared;
ef416fc2 122 p->filetype = mimeAddType(MimeDatabase, "printer", name);
123
124 cupsdSetString(&p->job_sheets[0], "none");
125 cupsdSetString(&p->job_sheets[1], "none");
126
127 cupsdSetString(&p->error_policy, "stop-printer");
128 cupsdSetString(&p->op_policy, DefaultPolicy);
129
130 p->op_policy_ptr = DefaultPolicyPtr;
131
132 if (MaxPrinterHistory)
133 p->history = calloc(MaxPrinterHistory, sizeof(ipp_t *));
134
135 /*
136 * Insert the printer in the printer list alphabetically...
137 */
138
139 if (!Printers)
140 Printers = cupsArrayNew(compare_printers, NULL);
141
142 cupsArrayAdd(Printers, p);
143
144 if (!ImplicitPrinters)
145 ImplicitPrinters = cupsArrayNew(compare_printers, NULL);
146
147 /*
148 * Return the new printer...
149 */
150
151 return (p);
152}
153
154
ef416fc2 155/*
156 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
157 */
158
159void
160cupsdAddPrinterHistory(
161 cupsd_printer_t *p) /* I - Printer */
162{
163 ipp_t *history; /* History collection */
164
165
166 /*
167 * Stop early if we aren't keeping history data...
168 */
169
170 if (MaxPrinterHistory <= 0)
171 return;
172
173 /*
174 * Retire old history data as needed...
175 */
176
177 p->sequence_number ++;
178
179 if (p->num_history >= MaxPrinterHistory)
180 {
181 p->num_history --;
182 ippDelete(p->history[0]);
183 memmove(p->history, p->history + 1, p->num_history * sizeof(ipp_t *));
184 }
185
186 /*
187 * Create a collection containing the current printer-state, printer-up-time,
188 * printer-state-message, and printer-state-reasons attributes.
189 */
190
191 history = ippNew();
192 ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
193 p->state);
194 ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
195 p->accepting);
fa73b229 196 ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-shared", p->shared);
ef416fc2 197 ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-state-message",
198 NULL, p->state_message);
e00b005a 199#ifdef __APPLE__
200 if (p->recoverable)
201 ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT,
202 "com.apple.print.recoverable-message", NULL, p->recoverable);
203#endif /* __APPLE__ */
ef416fc2 204 if (p->num_reasons == 0)
205 ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
206 "printer-state-reasons", NULL,
207 p->state == IPP_PRINTER_STOPPED ? "paused" : "none");
208 else
209 ippAddStrings(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
210 "printer-state-reasons", p->num_reasons, NULL,
211 (const char * const *)p->reasons);
212 ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
213 "printer-state-change-time", p->state_time);
214 ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
215 "printer-state-sequence-number", p->sequence_number);
216
217 p->history[p->num_history] = history;
218 p->num_history ++;
219}
220
221
222/*
223 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
224 */
225
226void
227cupsdAddPrinterUser(
228 cupsd_printer_t *p, /* I - Printer */
229 const char *username) /* I - User */
230{
231 const char **temp; /* Temporary array pointer */
232
233
234 if (!p || !username)
235 return;
236
237 if (p->num_users == 0)
238 temp = malloc(sizeof(char **));
239 else
240 temp = realloc(p->users, sizeof(char **) * (p->num_users + 1));
241
242 if (!temp)
243 return;
244
245 p->users = temp;
246 temp += p->num_users;
247
248 if ((*temp = strdup(username)) != NULL)
249 p->num_users ++;
250}
251
252
253/*
254 * 'cupsdCreateCommonData()' - Create the common printer data.
255 */
256
257void
258cupsdCreateCommonData(void)
259{
260 int i; /* Looping var */
261 ipp_attribute_t *attr; /* Attribute data */
ed486911 262 cups_dir_t *dir; /* Notifier directory */
263 cups_dentry_t *dent; /* Notifier directory entry */
264 cups_array_t *notifiers; /* Notifier array */
265 char filename[1024], /* Filename */
266 *notifier; /* Current notifier */
ef416fc2 267 static const int nups[] = /* number-up-supported values */
268 { 1, 2, 4, 6, 9, 16 };
269 static const ipp_orient_t orients[4] =/* orientation-requested-supported values */
270 {
271 IPP_PORTRAIT,
272 IPP_LANDSCAPE,
273 IPP_REVERSE_LANDSCAPE,
274 IPP_REVERSE_PORTRAIT
275 };
276 static const char * const holds[] = /* job-hold-until-supported values */
277 {
278 "no-hold",
279 "indefinite",
280 "day-time",
281 "evening",
282 "night",
283 "second-shift",
284 "third-shift",
285 "weekend"
286 };
287 static const char * const versions[] =/* ipp-versions-supported values */
288 {
289 "1.0",
290 "1.1"
291 };
292 static const ipp_op_t ops[] = /* operations-supported values */
293 {
294 IPP_PRINT_JOB,
295 IPP_VALIDATE_JOB,
296 IPP_CREATE_JOB,
297 IPP_SEND_DOCUMENT,
298 IPP_CANCEL_JOB,
299 IPP_GET_JOB_ATTRIBUTES,
300 IPP_GET_JOBS,
301 IPP_GET_PRINTER_ATTRIBUTES,
302 IPP_HOLD_JOB,
303 IPP_RELEASE_JOB,
304 IPP_PAUSE_PRINTER,
305 IPP_RESUME_PRINTER,
306 IPP_PURGE_JOBS,
307 IPP_SET_JOB_ATTRIBUTES,
308 IPP_CREATE_PRINTER_SUBSCRIPTION,
309 IPP_CREATE_JOB_SUBSCRIPTION,
310 IPP_GET_SUBSCRIPTION_ATTRIBUTES,
311 IPP_GET_SUBSCRIPTIONS,
312 IPP_RENEW_SUBSCRIPTION,
313 IPP_CANCEL_SUBSCRIPTION,
314 IPP_GET_NOTIFICATIONS,
315 IPP_ENABLE_PRINTER,
316 IPP_DISABLE_PRINTER,
317 CUPS_GET_DEFAULT,
318 CUPS_GET_PRINTERS,
319 CUPS_ADD_PRINTER,
320 CUPS_DELETE_PRINTER,
321 CUPS_GET_CLASSES,
322 CUPS_ADD_CLASS,
323 CUPS_DELETE_CLASS,
324 CUPS_ACCEPT_JOBS,
325 CUPS_REJECT_JOBS,
326 CUPS_SET_DEFAULT,
327 CUPS_GET_DEVICES,
328 CUPS_GET_PPDS,
329 CUPS_MOVE_JOB,
330 CUPS_AUTHENTICATE_JOB,
331 IPP_RESTART_JOB
332 };
333 static const char * const charsets[] =/* charset-supported values */
334 {
335 "us-ascii",
336 "utf-8"
337 };
338 static const char * const compressions[] =
339 { /* document-compression-supported values */
340 "none"
341#ifdef HAVE_LIBZ
342 ,"gzip"
343#endif /* HAVE_LIBZ */
344 };
345 static const char * const multiple_document_handling[] =
346 { /* multiple-document-handling-supported values */
347 "separate-documents-uncollated-copies",
348 "separate-documents-collated-copies"
349 };
350 static const char * const errors[] = /* printer-error-policy-supported values */
351 {
352 "abort-job",
353 "retry-job",
354 "stop-printer"
355 };
356 static const char * const notify_attrs[] =
357 { /* notify-attributes-supported values */
358 "printer-state-change-time",
359 "notify-lease-expiration-time",
360 "notify-subscriber-user-name"
361 };
362 static const char * const notify_events[] =
363 { /* notify-events-supported values */
364 "job-completed",
365 "job-config-changed",
366 "job-created",
367 "job-progress",
368 "job-state-changed",
369 "job-stopped",
370 "printer-added",
371 "printer-changed",
372 "printer-config-changed",
373 "printer-deleted",
374 "printer-finishings-changed",
375 "printer-media-changed",
376 "printer-modified",
377 "printer-restarted",
378 "printer-shutdown",
379 "printer-state-changed",
380 "printer-stopped",
381 "server-audit",
382 "server-restarted",
383 "server-started",
384 "server-stopped"
385 };
386
387
388 if (CommonData)
389 ippDelete(CommonData);
390
391 CommonData = ippNew();
392
393 /*
394 * This list of attributes is sorted to improve performance when the
395 * client provides a requested-attributes attribute...
396 */
397
398 /* charset-configured */
399 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET,
400 "charset-configured", NULL, DefaultCharset);
401
402 /* charset-supported */
403 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET,
404 "charset-supported", sizeof(charsets) / sizeof(charsets[0]),
405 NULL, charsets);
406
407 /* compression-supported */
408 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
409 "compression-supported",
410 sizeof(compressions) / sizeof(compressions[0]),
411 NULL, compressions);
412
ef416fc2 413 /* copies-supported */
414 ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies);
415
ef416fc2 416 /* generated-natural-language-supported */
417 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
418 "generated-natural-language-supported", NULL, DefaultLanguage);
419
420 /* ipp-versions-supported */
421 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
422 "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]),
423 NULL, versions);
424
ef416fc2 425 /* job-hold-until-supported */
426 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
427 "job-hold-until-supported", sizeof(holds) / sizeof(holds[0]),
428 NULL, holds);
429
ef416fc2 430 /* job-priority-supported */
431 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
432 "job-priority-supported", 100);
433
434 /* job-sheets-supported */
fa73b229 435 if (cupsArrayCount(Banners) > 0)
ef416fc2 436 {
437 /*
438 * Setup the job-sheets-supported attribute...
439 */
440
441 if (Classification && !ClassifyOverride)
442 attr = ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
443 "job-sheets-supported", NULL, Classification);
444 else
445 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
fa73b229 446 "job-sheets-supported", cupsArrayCount(Banners) + 1,
447 NULL, NULL);
ef416fc2 448
449 if (attr == NULL)
450 cupsdLogMessage(CUPSD_LOG_EMERG,
bd7854cb 451 "Unable to allocate memory for "
ef416fc2 452 "job-sheets-supported attribute: %s!", strerror(errno));
453 else if (!Classification || ClassifyOverride)
454 {
fa73b229 455 cupsd_banner_t *banner; /* Current banner */
456
457
757d2cad 458 attr->values[0].string.text = _cupsStrAlloc("none");
ef416fc2 459
fa73b229 460 for (i = 1, banner = (cupsd_banner_t *)cupsArrayFirst(Banners);
461 banner;
462 i ++, banner = (cupsd_banner_t *)cupsArrayNext(Banners))
757d2cad 463 attr->values[i].string.text = _cupsStrAlloc(banner->name);
ef416fc2 464 }
465 }
466 else
467 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
468 "job-sheets-supported", NULL, "none");
469
470 /* multiple-document-handling-supported */
471 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
472 "multiple-document-handling-supported",
473 sizeof(multiple_document_handling) /
474 sizeof(multiple_document_handling[0]), NULL,
475 multiple_document_handling);
476
477 /* multiple-document-jobs-supported */
478 ippAddBoolean(CommonData, IPP_TAG_PRINTER,
479 "multiple-document-jobs-supported", 1);
480
481 /* multiple-operation-time-out */
482 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
483 "multiple-operation-time-out", 60);
484
485 /* natural-language-configured */
486 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
487 "natural-language-configured", NULL, DefaultLanguage);
488
489 /* notify-attributes-supported */
490 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
491 "notify-attributes-supported",
492 (int)(sizeof(notify_attrs) / sizeof(notify_attrs[0])),
493 NULL, notify_attrs);
494
ef416fc2 495 /* notify-lease-duration-supported */
496 ippAddRange(CommonData, IPP_TAG_PRINTER,
497 "notify-lease-duration-supported", 0,
498 MaxLeaseDuration ? MaxLeaseDuration : 2147483647);
499
500 /* notify-max-events-supported */
501 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
502 "notify-max-events-supported", MaxEvents);
503
ed486911 504 /* notify-events-supported */
ef416fc2 505 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
506 "notify-events-supported",
507 (int)(sizeof(notify_events) / sizeof(notify_events[0])),
508 NULL, notify_events);
509
510 /* notify-pull-method-supported */
511 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
512 "notify-pull-method-supported", NULL, "ippget");
513
ef416fc2 514 /* notify-schemes-supported */
ed486911 515 snprintf(filename, sizeof(filename), "%s/notifier", ServerBin);
516 if ((dir = cupsDirOpen(filename)) != NULL)
517 {
518 notifiers = cupsArrayNew((cups_array_func_t)strcmp, NULL);
519
520 while ((dent = cupsDirRead(dir)) != NULL)
521 if (S_ISREG(dent->fileinfo.st_mode) &&
522 (dent->fileinfo.st_mode & S_IXOTH) != 0)
523 cupsArrayAdd(notifiers, _cupsStrAlloc(dent->filename));
524
525 if (cupsArrayCount(notifiers) > 0)
526 {
527 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
528 "notify-schemes-supported",
529 cupsArrayCount(notifiers), NULL, NULL);
530
531 for (i = 0, notifier = (char *)cupsArrayFirst(notifiers);
532 notifier;
533 i ++, notifier = (char *)cupsArrayNext(notifiers))
534 attr->values[i].string.text = notifier;
535 }
536
537 cupsArrayDelete(notifiers);
8ca02f3c 538 cupsDirClose(dir);
ed486911 539 }
ef416fc2 540
ef416fc2 541 /* number-up-supported */
542 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
543 "number-up-supported", sizeof(nups) / sizeof(nups[0]), nups);
544
545 /* operations-supported */
546 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
547 "operations-supported",
548 sizeof(ops) / sizeof(ops[0]) + JobFiles - 1, (int *)ops);
549
ef416fc2 550 /* orientation-requested-supported */
551 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
552 "orientation-requested-supported", 4, (int *)orients);
553
554 /* page-ranges-supported */
555 ippAddBoolean(CommonData, IPP_TAG_PRINTER, "page-ranges-supported", 1);
556
557 /* pdf-override-supported */
558 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
559 "pdl-override-supported", NULL, "not-attempted");
560
561 /* printer-error-policy-supported */
562 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
563 "printer-error-policy-supported",
564 sizeof(errors) / sizeof(errors[0]), NULL, errors);
565
566 /* printer-op-policy-supported */
567 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
568 "printer-op-policy-supported", NumPolicies, NULL, NULL);
569 for (i = 0; i < NumPolicies; i ++)
757d2cad 570 attr->values[i].string.text = _cupsStrAlloc(Policies[i]->name);
ef416fc2 571}
572
573
574/*
575 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
576 */
577
578void
579cupsdDeleteAllPrinters(void)
580{
581 cupsd_printer_t *p; /* Pointer to current printer/class */
582
583
584 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
585 p;
586 p = (cupsd_printer_t *)cupsArrayNext(Printers))
587 if (!(p->type & CUPS_PRINTER_CLASS))
588 cupsdDeletePrinter(p, 0);
589}
590
591
592/*
593 * 'cupsdDeletePrinter()' - Delete a printer from the system.
594 */
595
596void
597cupsdDeletePrinter(
598 cupsd_printer_t *p, /* I - Printer to delete */
599 int update) /* I - Update printers.conf? */
600{
601 int i; /* Looping var */
602#ifdef __sgi
603 char filename[1024]; /* Interface script filename */
604#endif /* __sgi */
605
606
607 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdDeletePrinter(p=%p(%s), update=%d)",
608 p, p->name, update);
609
610 /*
611 * Save the current position in the Printers array...
612 */
613
614 cupsArraySave(Printers);
615
616 /*
617 * Stop printing on this printer...
618 */
619
620 cupsdStopPrinter(p, update);
621
622 /*
623 * If this printer is the next for browsing, point to the next one...
624 */
625
626 if (p == BrowseNext)
627 {
628 cupsArrayFind(Printers, p);
629 BrowseNext = (cupsd_printer_t *)cupsArrayNext(Printers);
630 }
631
632 /*
633 * Remove the printer from the list...
634 */
635
636 cupsArrayRemove(Printers, p);
637
8ca02f3c 638 if (p->type & CUPS_PRINTER_IMPLICIT)
639 cupsArrayRemove(ImplicitPrinters, p);
640
ef416fc2 641 /*
642 * Remove the dummy interface/icon/option files under IRIX...
643 */
644
645#ifdef __sgi
646 snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);
647 unlink(filename);
648
649 snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui",
650 p->name);
651 unlink(filename);
652
653 snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);
654 unlink(filename);
655
656 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);
657 unlink(filename);
658
659 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);
660 unlink(filename);
661
662 snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);
663 unlink(filename);
664#endif /* __sgi */
665
666 /*
e00b005a 667 * If p is the default printer, assign a different one...
ef416fc2 668 */
669
670 if (p == DefaultPrinter)
e00b005a 671 {
672 DefaultPrinter = NULL;
673
674 if (UseNetworkDefault)
675 {
676 /*
677 * Find the first network default printer and use it...
678 */
679
680 cupsd_printer_t *dp; /* New default printer */
681
682
683 for (dp = (cupsd_printer_t *)cupsArrayFirst(Printers);
684 dp;
685 dp = (cupsd_printer_t *)cupsArrayNext(Printers))
686 if (dp != p && (dp->type & CUPS_PRINTER_DEFAULT))
687 {
ed486911 688 DefaultPrinter = dp;
e00b005a 689 break;
690 }
691 }
692 }
ef416fc2 693
694 /*
f7deaa1a 695 * Remove this printer from any classes...
ef416fc2 696 */
697
698 if (!(p->type & CUPS_PRINTER_IMPLICIT))
699 {
700 cupsdDeletePrinterFromClasses(p);
f7deaa1a 701
702 /*
703 * Deregister from any browse protocols...
704 */
705
706 cupsdDeregisterPrinter(p, 1);
ef416fc2 707 }
708
709 /*
710 * Free all memory used by the printer...
711 */
712
713 if (p->printers != NULL)
714 free(p->printers);
715
716 if (MaxPrinterHistory)
717 {
718 for (i = 0; i < p->num_history; i ++)
719 ippDelete(p->history[i]);
720
721 free(p->history);
722 }
723
724 for (i = 0; i < p->num_reasons; i ++)
725 free(p->reasons[i]);
726
727 ippDelete(p->attrs);
728
e1d6a774 729 delete_printer_filters(p);
ef416fc2 730
fa73b229 731 mimeDeleteType(MimeDatabase, p->filetype);
f7deaa1a 732 mimeDeleteType(MimeDatabase, p->prefiltertype);
fa73b229 733
ef416fc2 734 cupsdFreePrinterUsers(p);
735 cupsdFreeQuotas(p);
736
737 cupsdClearString(&p->uri);
738 cupsdClearString(&p->hostname);
739 cupsdClearString(&p->name);
740 cupsdClearString(&p->location);
741 cupsdClearString(&p->make_model);
742 cupsdClearString(&p->info);
743 cupsdClearString(&p->job_sheets[0]);
744 cupsdClearString(&p->job_sheets[1]);
745 cupsdClearString(&p->device_uri);
746 cupsdClearString(&p->port_monitor);
747 cupsdClearString(&p->op_policy);
748 cupsdClearString(&p->error_policy);
749
f7deaa1a 750#ifdef HAVE_DNSSD
751 cupsdClearString(&p->product);
752 cupsdClearString(&p->pdl);
753#endif /* HAVE_DNSSD */
754
80ca4592 755 cupsArrayDelete(p->filetypes);
756
b423cd4c 757 if (p->browse_attrs)
758 free(p->browse_attrs);
759
e00b005a 760#ifdef __APPLE__
761 cupsdClearString(&p->recoverable);
762#endif /* __APPLE__ */
763
b423cd4c 764 cupsFreeOptions(p->num_options, p->options);
765
ef416fc2 766 free(p);
767
768 /*
769 * Restore the previous position in the Printers array...
770 */
771
772 cupsArrayRestore(Printers);
773}
774
775
ef416fc2 776/*
777 * 'cupsdFindDest()' - Find a destination in the list.
778 */
779
780cupsd_printer_t * /* O - Destination in list */
781cupsdFindDest(const char *name) /* I - Name of printer or class to find */
782{
783 cupsd_printer_t key; /* Search key */
784
785
786 key.name = (char *)name;
787 return ((cupsd_printer_t *)cupsArrayFind(Printers, &key));
788}
789
790
791/*
792 * 'cupsdFindPrinter()' - Find a printer in the list.
793 */
794
795cupsd_printer_t * /* O - Printer in list */
796cupsdFindPrinter(const char *name) /* I - Name of printer to find */
797{
798 cupsd_printer_t *p; /* Printer in list */
799
800
801 if ((p = cupsdFindDest(name)) != NULL && (p->type & CUPS_PRINTER_CLASS))
802 return (NULL);
803 else
804 return (p);
805}
806
807
808/*
809 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
810 */
811
812void
813cupsdFreePrinterUsers(
814 cupsd_printer_t *p) /* I - Printer */
815{
816 int i; /* Looping var */
817
818
819 if (!p || !p->num_users)
820 return;
821
822 for (i = 0; i < p->num_users; i ++)
823 free((void *)p->users[i]);
824
825 free(p->users);
826
827 p->num_users = 0;
828 p->users = NULL;
829}
830
831
832/*
833 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
834 */
835
836void
837cupsdLoadAllPrinters(void)
838{
839 cups_file_t *fp; /* printers.conf file */
840 int linenum; /* Current line number */
841 char line[1024], /* Line from file */
842 *value, /* Pointer to value */
843 *valueptr; /* Pointer into value */
844 cupsd_printer_t *p; /* Current printer */
845
846
847 /*
848 * Open the printers.conf file...
849 */
850
851 snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot);
852 if ((fp = cupsFileOpen(line, "r")) == NULL)
853 {
fa73b229 854 if (errno != ENOENT)
bd7854cb 855 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open %s - %s", line,
fa73b229 856 strerror(errno));
ef416fc2 857 return;
858 }
859
860 /*
861 * Read printer configurations until we hit EOF...
862 */
863
864 linenum = 0;
865 p = NULL;
866
867 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
868 {
869 /*
870 * Decode the directive...
871 */
872
873 if (!strcasecmp(line, "<Printer") ||
874 !strcasecmp(line, "<DefaultPrinter"))
875 {
876 /*
877 * <Printer name> or <DefaultPrinter name>
878 */
879
880 if (p == NULL && value)
881 {
882 /*
883 * Add the printer and a base file type...
884 */
885
bd7854cb 886 cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading printer %s...", value);
ef416fc2 887
888 p = cupsdAddPrinter(value);
889 p->accepting = 1;
890 p->state = IPP_PRINTER_IDLE;
891
892 /*
893 * Set the default printer as needed...
894 */
895
896 if (!strcasecmp(line, "<DefaultPrinter"))
897 DefaultPrinter = p;
898 }
899 else
900 {
901 cupsdLogMessage(CUPSD_LOG_ERROR,
902 "Syntax error on line %d of printers.conf.", linenum);
903 return;
904 }
905 }
906 else if (!strcasecmp(line, "</Printer>"))
907 {
908 if (p != NULL)
909 {
910 /*
911 * Close out the current printer...
912 */
913
914 cupsdSetPrinterAttrs(p);
915 cupsdAddPrinterHistory(p);
916
917 if (p->device_uri && strncmp(p->device_uri, "file:", 5) &&
918 p->state != IPP_PRINTER_STOPPED)
919 {
920 /*
921 * See if the backend exists...
922 */
923
924 snprintf(line, sizeof(line), "%s/backend/%s", ServerBin,
925 p->device_uri);
926
927 if ((valueptr = strchr(line + strlen(ServerBin), ':')) != NULL)
928 *valueptr = '\0'; /* Chop everything but URI scheme */
929
930 if (access(line, 0))
931 {
932 /*
933 * Backend does not exist, stop printer...
934 */
935
936 p->state = IPP_PRINTER_STOPPED;
937 snprintf(p->state_message, sizeof(p->state_message),
938 "Backend %s does not exist!", line);
939 }
940 }
941
942 p = NULL;
943 }
944 else
945 {
946 cupsdLogMessage(CUPSD_LOG_ERROR,
947 "Syntax error on line %d of printers.conf.", linenum);
948 return;
949 }
950 }
951 else if (!p)
952 {
953 cupsdLogMessage(CUPSD_LOG_ERROR,
954 "Syntax error on line %d of printers.conf.", linenum);
955 return;
956 }
f7deaa1a 957 else if (!strcasecmp(line, "AuthInfoRequired"))
958 {
959 if (!cupsdSetAuthInfoRequired(p, value, NULL))
960 cupsdLogMessage(CUPSD_LOG_ERROR,
961 "Bad AuthInfoRequired on line %d of printers.conf.",
962 linenum);
963 }
ef416fc2 964 else if (!strcasecmp(line, "Info"))
965 {
966 if (value)
967 cupsdSetString(&p->info, value);
968 }
969 else if (!strcasecmp(line, "Location"))
970 {
971 if (value)
972 cupsdSetString(&p->location, value);
973 }
974 else if (!strcasecmp(line, "DeviceURI"))
975 {
976 if (value)
977 cupsdSetString(&p->device_uri, value);
978 else
979 {
980 cupsdLogMessage(CUPSD_LOG_ERROR,
981 "Syntax error on line %d of printers.conf.", linenum);
982 return;
983 }
984 }
b423cd4c 985 else if (!strcasecmp(line, "Option") && value)
986 {
987 /*
988 * Option name value
989 */
990
991 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
992
993 if (!*valueptr)
994 cupsdLogMessage(CUPSD_LOG_ERROR,
995 "Syntax error on line %d of printers.conf.", linenum);
996 else
997 {
998 for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0');
999
1000 p->num_options = cupsAddOption(value, valueptr, p->num_options,
1001 &(p->options));
1002 }
1003 }
ef416fc2 1004 else if (!strcasecmp(line, "PortMonitor"))
1005 {
1006 if (value && strcmp(value, "none"))
1007 cupsdSetString(&p->port_monitor, value);
1008 else if (value)
1009 cupsdClearString(&p->port_monitor);
1010 else
1011 {
1012 cupsdLogMessage(CUPSD_LOG_ERROR,
1013 "Syntax error on line %d of printers.conf.", linenum);
1014 return;
1015 }
1016 }
1017 else if (!strcasecmp(line, "State"))
1018 {
1019 /*
1020 * Set the initial queue state...
1021 */
1022
1023 if (value && !strcasecmp(value, "idle"))
1024 p->state = IPP_PRINTER_IDLE;
1025 else if (value && !strcasecmp(value, "stopped"))
1026 p->state = IPP_PRINTER_STOPPED;
1027 else
1028 {
1029 cupsdLogMessage(CUPSD_LOG_ERROR,
1030 "Syntax error on line %d of printers.conf.", linenum);
1031 return;
1032 }
1033 }
1034 else if (!strcasecmp(line, "StateMessage"))
1035 {
1036 /*
1037 * Set the initial queue state message...
1038 */
1039
1040 if (value)
1041 strlcpy(p->state_message, value, sizeof(p->state_message));
1042 }
1043 else if (!strcasecmp(line, "StateTime"))
1044 {
1045 /*
1046 * Set the state time...
1047 */
1048
1049 if (value)
1050 p->state_time = atoi(value);
1051 }
1052 else if (!strcasecmp(line, "Accepting"))
1053 {
1054 /*
1055 * Set the initial accepting state...
1056 */
1057
1058 if (value &&
1059 (!strcasecmp(value, "yes") ||
1060 !strcasecmp(value, "on") ||
1061 !strcasecmp(value, "true")))
1062 p->accepting = 1;
1063 else if (value &&
1064 (!strcasecmp(value, "no") ||
1065 !strcasecmp(value, "off") ||
1066 !strcasecmp(value, "false")))
1067 p->accepting = 0;
1068 else
1069 {
1070 cupsdLogMessage(CUPSD_LOG_ERROR,
1071 "Syntax error on line %d of printers.conf.", linenum);
1072 return;
1073 }
1074 }
1075 else if (!strcasecmp(line, "Shared"))
1076 {
1077 /*
1078 * Set the initial shared state...
1079 */
1080
1081 if (value &&
1082 (!strcasecmp(value, "yes") ||
1083 !strcasecmp(value, "on") ||
1084 !strcasecmp(value, "true")))
1085 p->shared = 1;
1086 else if (value &&
1087 (!strcasecmp(value, "no") ||
1088 !strcasecmp(value, "off") ||
1089 !strcasecmp(value, "false")))
1090 p->shared = 0;
1091 else
1092 {
1093 cupsdLogMessage(CUPSD_LOG_ERROR,
1094 "Syntax error on line %d of printers.conf.", linenum);
1095 return;
1096 }
1097 }
1098 else if (!strcasecmp(line, "JobSheets"))
1099 {
1100 /*
1101 * Set the initial job sheets...
1102 */
1103
1104 if (value)
1105 {
1106 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1107
1108 if (*valueptr)
1109 *valueptr++ = '\0';
1110
1111 cupsdSetString(&p->job_sheets[0], value);
1112
1113 while (isspace(*valueptr & 255))
1114 valueptr ++;
1115
1116 if (*valueptr)
1117 {
1118 for (value = valueptr; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1119
1120 if (*valueptr)
1121 *valueptr++ = '\0';
1122
1123 cupsdSetString(&p->job_sheets[1], value);
1124 }
1125 }
1126 else
1127 {
1128 cupsdLogMessage(CUPSD_LOG_ERROR,
1129 "Syntax error on line %d of printers.conf.", linenum);
1130 return;
1131 }
1132 }
1133 else if (!strcasecmp(line, "AllowUser"))
1134 {
1135 if (value)
1136 {
1137 p->deny_users = 0;
1138 cupsdAddPrinterUser(p, value);
1139 }
1140 else
1141 {
1142 cupsdLogMessage(CUPSD_LOG_ERROR,
1143 "Syntax error on line %d of printers.conf.", linenum);
1144 return;
1145 }
1146 }
1147 else if (!strcasecmp(line, "DenyUser"))
1148 {
1149 if (value)
1150 {
1151 p->deny_users = 1;
1152 cupsdAddPrinterUser(p, value);
1153 }
1154 else
1155 {
1156 cupsdLogMessage(CUPSD_LOG_ERROR,
1157 "Syntax error on line %d of printers.conf.", linenum);
1158 return;
1159 }
1160 }
1161 else if (!strcasecmp(line, "QuotaPeriod"))
1162 {
1163 if (value)
1164 p->quota_period = atoi(value);
1165 else
1166 {
1167 cupsdLogMessage(CUPSD_LOG_ERROR,
1168 "Syntax error on line %d of printers.conf.", linenum);
1169 return;
1170 }
1171 }
1172 else if (!strcasecmp(line, "PageLimit"))
1173 {
1174 if (value)
1175 p->page_limit = atoi(value);
1176 else
1177 {
1178 cupsdLogMessage(CUPSD_LOG_ERROR,
1179 "Syntax error on line %d of printers.conf.", linenum);
1180 return;
1181 }
1182 }
1183 else if (!strcasecmp(line, "KLimit"))
1184 {
1185 if (value)
1186 p->k_limit = atoi(value);
1187 else
1188 {
1189 cupsdLogMessage(CUPSD_LOG_ERROR,
1190 "Syntax error on line %d of printers.conf.", linenum);
1191 return;
1192 }
1193 }
1194 else if (!strcasecmp(line, "OpPolicy"))
1195 {
1196 if (value)
1197 cupsdSetString(&p->op_policy, value);
1198 else
1199 {
1200 cupsdLogMessage(CUPSD_LOG_ERROR,
1201 "Syntax error on line %d of printers.conf.", linenum);
1202 return;
1203 }
1204 }
1205 else if (!strcasecmp(line, "ErrorPolicy"))
1206 {
1207 if (value)
1208 cupsdSetString(&p->error_policy, value);
1209 else
1210 {
1211 cupsdLogMessage(CUPSD_LOG_ERROR,
1212 "Syntax error on line %d of printers.conf.", linenum);
1213 return;
1214 }
1215 }
1216 else
1217 {
1218 /*
1219 * Something else we don't understand...
1220 */
1221
1222 cupsdLogMessage(CUPSD_LOG_ERROR,
1223 "Unknown configuration directive %s on line %d of printers.conf.",
1224 line, linenum);
1225 }
1226 }
1227
1228 cupsFileClose(fp);
1229}
1230
1231
b423cd4c 1232/*
1233 * 'cupsdRenamePrinter()' - Rename a printer.
1234 */
1235
1236void
1237cupsdRenamePrinter(
1238 cupsd_printer_t *p, /* I - Printer */
1239 const char *name) /* I - New name */
1240{
1241 /*
1242 * Remove the printer from the array(s) first...
1243 */
1244
1245 cupsArrayRemove(Printers, p);
1246
1247 if (p->type & CUPS_PRINTER_IMPLICIT)
1248 cupsArrayRemove(ImplicitPrinters, p);
1249
1250 /*
1251 * Rename the printer type...
1252 */
1253
1254 mimeDeleteType(MimeDatabase, p->filetype);
1255 p->filetype = mimeAddType(MimeDatabase, "printer", name);
1256
f7deaa1a 1257 mimeDeleteType(MimeDatabase, p->prefiltertype);
1258 p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", name);
1259
b423cd4c 1260 /*
1261 * Rename the printer...
1262 */
1263
a74454a7 1264 cupsdSetString(&p->name, name);
b423cd4c 1265
1266 /*
1267 * Reset printer attributes...
1268 */
1269
1270 cupsdSetPrinterAttrs(p);
1271
1272 /*
1273 * Add the printer back to the printer array(s)...
1274 */
1275
1276 cupsArrayAdd(Printers, p);
8ca02f3c 1277
b423cd4c 1278 if (p->type & CUPS_PRINTER_IMPLICIT)
1279 cupsArrayAdd(ImplicitPrinters, p);
1280}
1281
1282
ef416fc2 1283/*
1284 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1285 * file.
1286 */
1287
1288void
1289cupsdSaveAllPrinters(void)
1290{
1291 int i; /* Looping var */
1292 cups_file_t *fp; /* printers.conf file */
1293 char temp[1024]; /* Temporary string */
1294 char backup[1024]; /* printers.conf.O file */
1295 cupsd_printer_t *printer; /* Current printer class */
1296 time_t curtime; /* Current time */
1297 struct tm *curdate; /* Current date */
b423cd4c 1298 cups_option_t *option; /* Current option */
f7deaa1a 1299 const char *ptr; /* Pointer into info/location */
ef416fc2 1300
1301
1302 /*
1303 * Create the printers.conf file...
1304 */
1305
1306 snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot);
1307 snprintf(backup, sizeof(backup), "%s/printers.conf.O", ServerRoot);
1308
1309 if (rename(temp, backup))
1310 {
1311 if (errno != ENOENT)
1312 cupsdLogMessage(CUPSD_LOG_ERROR,
1313 "Unable to backup printers.conf - %s", strerror(errno));
1314 }
1315
1316 if ((fp = cupsFileOpen(temp, "w")) == NULL)
1317 {
1318 cupsdLogMessage(CUPSD_LOG_ERROR,
1319 "Unable to save printers.conf - %s", strerror(errno));
1320
1321 if (rename(backup, temp))
1322 cupsdLogMessage(CUPSD_LOG_ERROR,
1323 "Unable to restore printers.conf - %s", strerror(errno));
1324 return;
1325 }
1326 else
1327 cupsdLogMessage(CUPSD_LOG_INFO, "Saving printers.conf...");
1328
1329 /*
1330 * Restrict access to the file...
1331 */
1332
1333 fchown(cupsFileNumber(fp), getuid(), Group);
fa73b229 1334 fchmod(cupsFileNumber(fp), 0600);
ef416fc2 1335
1336 /*
1337 * Write a small header to the file...
1338 */
1339
1340 curtime = time(NULL);
1341 curdate = localtime(&curtime);
1342 strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
1343
1344 cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
1345 cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
1346
1347 /*
1348 * Write each local printer known to the system...
1349 */
1350
1351 for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
1352 printer;
1353 printer = (cupsd_printer_t *)cupsArrayNext(Printers))
1354 {
1355 /*
1356 * Skip remote destinations and printer classes...
1357 */
1358
1359 if ((printer->type & CUPS_PRINTER_REMOTE) ||
1360 (printer->type & CUPS_PRINTER_CLASS) ||
1361 (printer->type & CUPS_PRINTER_IMPLICIT))
1362 continue;
1363
1364 /*
1365 * Write printers as needed...
1366 */
1367
1368 if (printer == DefaultPrinter)
1369 cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name);
1370 else
1371 cupsFilePrintf(fp, "<Printer %s>\n", printer->name);
1372
f7deaa1a 1373 if (printer->num_auth_info_required > 0)
1374 {
1375 cupsFilePrintf(fp, "AuthInfoRequired %s", printer->auth_info_required[0]);
1376 for (i = 1; i < printer->num_auth_info_required; i ++)
1377 cupsFilePrintf(fp, ",%s", printer->auth_info_required[i]);
1378 cupsFilePutChar(fp, '\n');
1379 }
1380
ef416fc2 1381 if (printer->info)
f7deaa1a 1382 {
1383 if ((ptr = strchr(printer->info, '#')) != NULL)
1384 {
1385 /*
1386 * Need to quote the first # in the info string...
1387 */
1388
1389 cupsFilePuts(fp, "Info ");
1390 cupsFileWrite(fp, printer->info, ptr - printer->info);
1391 cupsFilePutChar(fp, '\\');
1392 cupsFilePuts(fp, ptr);
1393 cupsFilePutChar(fp, '\n');
1394 }
1395 else
1396 cupsFilePrintf(fp, "Info %s\n", printer->info);
1397 }
ef416fc2 1398
1399 if (printer->location)
f7deaa1a 1400 {
1401 if ((ptr = strchr(printer->info, '#')) != NULL)
1402 {
1403 /*
1404 * Need to quote the first # in the location string...
1405 */
ef416fc2 1406
f7deaa1a 1407 cupsFilePuts(fp, "Location ");
1408 cupsFileWrite(fp, printer->location, ptr - printer->location);
1409 cupsFilePutChar(fp, '\\');
1410 cupsFilePuts(fp, ptr);
1411 cupsFilePutChar(fp, '\n');
1412 }
1413 else
1414 cupsFilePrintf(fp, "Location %s\n", printer->location);
1415 }
ef416fc2 1416 if (printer->device_uri)
1417 cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);
1418
1419 if (printer->port_monitor)
1420 cupsFilePrintf(fp, "PortMonitor %s\n", printer->port_monitor);
1421
1422 if (printer->state == IPP_PRINTER_STOPPED)
1423 {
1424 cupsFilePuts(fp, "State Stopped\n");
1425 cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);
1426 }
1427 else
1428 cupsFilePuts(fp, "State Idle\n");
1429
1430 cupsFilePrintf(fp, "StateTime %d\n", (int)printer->state_time);
1431
1432 if (printer->accepting)
1433 cupsFilePuts(fp, "Accepting Yes\n");
1434 else
1435 cupsFilePuts(fp, "Accepting No\n");
1436
1437 if (printer->shared)
1438 cupsFilePuts(fp, "Shared Yes\n");
1439 else
1440 cupsFilePuts(fp, "Shared No\n");
1441
1442 cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
1443 printer->job_sheets[1]);
1444
1445 cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period);
1446 cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit);
1447 cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit);
1448
1449 for (i = 0; i < printer->num_users; i ++)
1450 cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
1451 printer->users[i]);
1452
1453 if (printer->op_policy)
1454 cupsFilePrintf(fp, "OpPolicy %s\n", printer->op_policy);
1455 if (printer->error_policy)
1456 cupsFilePrintf(fp, "ErrorPolicy %s\n", printer->error_policy);
1457
b423cd4c 1458 for (i = printer->num_options, option = printer->options;
1459 i > 0;
1460 i --, option ++)
1461 cupsFilePrintf(fp, "Option %s %s\n", option->name, option->value);
1462
ef416fc2 1463 cupsFilePuts(fp, "</Printer>\n");
1464
1465#ifdef __sgi
1466 /*
1467 * Make IRIX desktop & printer status happy
1468 */
1469
1470 write_irix_state(printer);
1471#endif /* __sgi */
1472 }
1473
1474 cupsFileClose(fp);
1475}
1476
1477
f7deaa1a 1478/*
1479 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1480 */
1481
1482int /* O - 1 if value OK, 0 otherwise */
1483cupsdSetAuthInfoRequired(
1484 cupsd_printer_t *p, /* I - Printer */
1485 const char *values, /* I - Plain text value (or NULL) */
1486 ipp_attribute_t *attr) /* I - IPP attribute value (or NULL) */
1487{
1488 int i; /* Looping var */
1489
1490
1491 p->num_auth_info_required = 0;
1492
1493 /*
1494 * Do we have a plain text value?
1495 */
1496
1497 if (values)
1498 {
1499 /*
1500 * Yes, grab the keywords...
1501 */
1502
1503 const char *end; /* End of current value */
1504
1505
1506 while (*values && p->num_auth_info_required < 4)
1507 {
1508 if ((end = strchr(values, ',')) == NULL)
1509 end = values + strlen(values);
1510
1511 if (!strncmp(values, "none", end - values))
1512 {
1513 if (p->num_auth_info_required != 0 || *end)
1514 return (0);
1515
1516 p->auth_info_required[p->num_auth_info_required] = "none";
1517 p->num_auth_info_required ++;
1518
1519 return (1);
1520 }
1521 else if (!strncmp(values, "domain", end - values))
1522 {
1523 p->auth_info_required[p->num_auth_info_required] = "domain";
1524 p->num_auth_info_required ++;
1525 }
1526 else if (!strncmp(values, "password", end - values))
1527 {
1528 p->auth_info_required[p->num_auth_info_required] = "password";
1529 p->num_auth_info_required ++;
1530 }
1531 else if (!strncmp(values, "username", end - values))
1532 {
1533 p->auth_info_required[p->num_auth_info_required] = "username";
1534 p->num_auth_info_required ++;
1535 }
1536 else
1537 return (0);
1538 }
1539
1540 if (p->num_auth_info_required == 0)
1541 {
1542 p->auth_info_required[0] = "none";
1543 p->num_auth_info_required = 1;
1544 }
1545
1546 return (1);
1547 }
1548
1549 /*
1550 * Grab values from an attribute instead...
1551 */
1552
1553 if (!attr || attr->num_values > 4)
1554 return (0);
1555
1556 for (i = 0; i < attr->num_values; i ++)
1557 {
1558 if (!strcmp(attr->values[i].string.text, "none"))
1559 {
1560 if (p->num_auth_info_required != 0 || attr->num_values != 1)
1561 return (0);
1562
1563 p->auth_info_required[p->num_auth_info_required] = "none";
1564 p->num_auth_info_required ++;
1565
1566 return (1);
1567 }
1568 else if (!strcmp(attr->values[i].string.text, "domain"))
1569 {
1570 p->auth_info_required[p->num_auth_info_required] = "domain";
1571 p->num_auth_info_required ++;
1572 }
1573 else if (!strcmp(attr->values[i].string.text, "password"))
1574 {
1575 p->auth_info_required[p->num_auth_info_required] = "password";
1576 p->num_auth_info_required ++;
1577 }
1578 else if (!strcmp(attr->values[i].string.text, "username"))
1579 {
1580 p->auth_info_required[p->num_auth_info_required] = "username";
1581 p->num_auth_info_required ++;
1582 }
1583 else
1584 return (0);
1585 }
1586
1587 return (1);
1588}
1589
1590
ef416fc2 1591/*
1592 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1593 */
1594
1595void
1596cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
1597{
b423cd4c 1598 int i, /* Looping var */
1599 length; /* Length of browse attributes */
1600 char uri[HTTP_MAX_URI]; /* URI for printer */
1601 char resource[HTTP_MAX_URI]; /* Resource portion of URI */
1602 char filename[1024]; /* Name of PPD file */
1603 int num_media; /* Number of media options */
1604 cupsd_location_t *auth; /* Pointer to authentication element */
1605 const char *auth_supported; /* Authentication supported */
1606 cups_ptype_t printer_type; /* Printer type data */
1607 ppd_file_t *ppd; /* PPD file data */
1608 ppd_option_t *input_slot, /* InputSlot options */
1609 *media_type, /* MediaType options */
1610 *page_size, /* PageSize options */
1611 *output_bin, /* OutputBin options */
1612 *media_quality, /* EFMediaQualityMode options */
1613 *duplex; /* Duplex options */
1614 ppd_attr_t *ppdattr; /* PPD attribute */
1615 ipp_attribute_t *attr; /* Attribute data */
1616 ipp_value_t *val; /* Attribute value */
1617 int num_finishings; /* Number of finishings */
1618 ipp_finish_t finishings[5]; /* finishings-supported values */
1619 cups_option_t *option; /* Current printer option */
ef416fc2 1620 static const char * const sides[3] = /* sides-supported values */
1621 {
b423cd4c 1622 "one-sided",
1623 "two-sided-long-edge",
1624 "two-sided-short-edge"
ef416fc2 1625 };
1626
1627
1628 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name,
1629 p->type));
1630
1631 /*
1632 * Make sure that we have the common attributes defined...
1633 */
1634
1635 if (!CommonData)
1636 cupsdCreateCommonData();
1637
1638 /*
1639 * Clear out old filters, if any...
1640 */
1641
e1d6a774 1642 delete_printer_filters(p);
ef416fc2 1643
1644 /*
1645 * Figure out the authentication that is required for the printer.
1646 */
1647
1648 auth_supported = "requesting-user-name";
1649 if (!(p->type & CUPS_PRINTER_REMOTE))
1650 {
1651 if (p->type & CUPS_PRINTER_CLASS)
1652 snprintf(resource, sizeof(resource), "/classes/%s", p->name);
1653 else
1654 snprintf(resource, sizeof(resource), "/printers/%s", p->name);
1655
d09495fa 1656 if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL ||
1657 auth->type == AUTH_NONE)
ef416fc2 1658 auth = cupsdFindPolicyOp(p->op_policy_ptr, IPP_PRINT_JOB);
1659
1660 if (auth)
1661 {
1662 if (auth->type == AUTH_BASIC || auth->type == AUTH_BASICDIGEST)
1663 auth_supported = "basic";
1664 else if (auth->type == AUTH_DIGEST)
1665 auth_supported = "digest";
1666
1667 if (auth->type != AUTH_NONE)
1668 p->type |= CUPS_PRINTER_AUTHENTICATED;
1669 else
1670 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
1671 }
1672 else
1673 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
1674 }
1675
1676 /*
1677 * Create the required IPP attributes for a printer...
1678 */
1679
1680 if (p->attrs)
1681 ippDelete(p->attrs);
1682
1683 p->attrs = ippNew();
1684
1685 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1686 "uri-authentication-supported", NULL, auth_supported);
1687 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1688 "uri-security-supported", NULL, "none");
1689 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL,
1690 p->name);
1691 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location",
1692 NULL, p->location ? p->location : "");
1693 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info",
1694 NULL, p->info ? p->info : "");
1695 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info",
1696 NULL, p->uri);
1697
1698 if (p->num_users)
1699 {
1700 if (p->deny_users)
1701 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1702 "requesting-user-name-denied", p->num_users, NULL,
1703 p->users);
1704 else
1705 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1706 "requesting-user-name-allowed", p->num_users, NULL,
1707 p->users);
1708 }
1709
1710 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
1711 "job-quota-period", p->quota_period);
1712 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
1713 "job-k-limit", p->k_limit);
1714 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
1715 "job-page-limit", p->page_limit);
f7deaa1a 1716 if (p->num_auth_info_required)
1717 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1718 "auth-info-required", p->num_auth_info_required,
1719 NULL, p->auth_info_required);
1720 else
1721 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1722 "auth-info-required", NULL, "none");
ef416fc2 1723
fa73b229 1724 if (cupsArrayCount(Banners) > 0 && !(p->type & CUPS_PRINTER_REMOTE))
ef416fc2 1725 {
1726 /*
1727 * Setup the job-sheets-default attribute...
1728 */
1729
1730 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1731 "job-sheets-default", 2, NULL, NULL);
1732
1733 if (attr != NULL)
1734 {
757d2cad 1735 attr->values[0].string.text = _cupsStrAlloc(Classification ?
ef416fc2 1736 Classification : p->job_sheets[0]);
757d2cad 1737 attr->values[1].string.text = _cupsStrAlloc(Classification ?
ef416fc2 1738 Classification : p->job_sheets[1]);
1739 }
1740 }
1741
e00b005a 1742 printer_type = p->type;
ef416fc2 1743
d09495fa 1744 p->raw = 0;
1745 p->remote = 0;
ef416fc2 1746
1747 if (p->type & CUPS_PRINTER_REMOTE)
1748 {
1749 /*
1750 * Tell the client this is a remote printer of some type...
1751 */
1752
1753 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
1754 "printer-uri-supported", NULL, p->uri);
1755
1756 if (p->make_model)
1757 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1758 "printer-make-and-model", NULL, p->make_model);
1759
fa73b229 1760 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
1761 p->uri);
1762
d09495fa 1763 p->raw = 1;
1764 p->remote = 1;
ef416fc2 1765 }
1766 else
1767 {
1768 /*
1769 * Assign additional attributes depending on whether this is a printer
1770 * or class...
1771 */
1772
1773 p->type &= ~CUPS_PRINTER_OPTIONS;
1774
1775 if (p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
1776 {
1777 p->raw = 1;
1778
1779 /*
1780 * Add class-specific attributes...
1781 */
1782
1783 if ((p->type & CUPS_PRINTER_IMPLICIT) && p->num_printers > 0 &&
1784 p->printers[0]->make_model)
1785 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1786 "printer-make-and-model", NULL, p->printers[0]->make_model);
1787 else
1788 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1789 "printer-make-and-model", NULL, "Local Printer Class");
1790
fa73b229 1791 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
1792 "file:///dev/null");
1793
ef416fc2 1794 if (p->num_printers > 0)
1795 {
1796 /*
1797 * Add a list of member URIs and names...
1798 */
1799
1800 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
1801 "member-uris", p->num_printers, NULL, NULL);
1802 p->type |= CUPS_PRINTER_OPTIONS;
1803
1804 for (i = 0; i < p->num_printers; i ++)
1805 {
1806 if (attr != NULL)
757d2cad 1807 attr->values[i].string.text = _cupsStrAlloc(p->printers[i]->uri);
ef416fc2 1808
1809 p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type;
1810 }
1811
1812 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1813 "member-names", p->num_printers, NULL, NULL);
1814
1815 if (attr != NULL)
1816 {
1817 for (i = 0; i < p->num_printers; i ++)
757d2cad 1818 attr->values[i].string.text = _cupsStrAlloc(p->printers[i]->name);
ef416fc2 1819 }
1820 }
1821 }
1822 else
1823 {
1824 /*
1825 * Add printer-specific attributes... Start by sanitizing the device
1826 * URI so it doesn't have a username or password in it...
1827 */
1828
1829 if (!p->device_uri)
1830 strcpy(uri, "file:/dev/null");
1831 else if (strstr(p->device_uri, "://") != NULL)
1832 {
1833 /*
1834 * http://..., ipp://..., etc.
1835 */
1836
1837 cupsdSanitizeURI(p->device_uri, uri, sizeof(uri));
1838 }
1839 else
1840 {
1841 /*
1842 * file:..., serial:..., etc.
1843 */
1844
1845 strlcpy(uri, p->device_uri, sizeof(uri));
1846 }
1847
1848 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
1849 uri);
1850
1851 /*
1852 * Assign additional attributes from the PPD file (if any)...
1853 */
1854
1855 p->type |= CUPS_PRINTER_BW;
1856 finishings[0] = IPP_FINISHINGS_NONE;
1857 num_finishings = 1;
1858
1859 snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
1860 p->name);
1861
1862 if ((ppd = ppdOpenFile(filename)) != NULL)
1863 {
1864 /*
1865 * Add make/model and other various attributes...
1866 */
1867
1868 if (ppd->color_device)
1869 p->type |= CUPS_PRINTER_COLOR;
1870 if (ppd->variable_sizes)
1871 p->type |= CUPS_PRINTER_VARIABLE;
1872 if (!ppd->manual_copies)
1873 p->type |= CUPS_PRINTER_COPIES;
1874 if ((ppdattr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL)
1875 if (ppdattr->value && !strcasecmp(ppdattr->value, "true"))
1876 p->type |= CUPS_PRINTER_FAX;
1877
1878 ippAddBoolean(p->attrs, IPP_TAG_PRINTER, "color-supported",
1879 ppd->color_device);
1880 if (ppd->throughput)
1881 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
1882 "pages-per-minute", ppd->throughput);
1883
1884 if (ppd->nickname)
bd7854cb 1885 {
1886 /*
1887 * The NickName can be localized in the character set specified
e1d6a774 1888 * by the LanugageEncoding attribute. However, ppdOpen2() has
1889 * already converted the ppd->nickname member to UTF-8 for us
1890 * (the original attribute value is available separately)
bd7854cb 1891 */
1892
e1d6a774 1893 cupsdSetString(&p->make_model, ppd->nickname);
bd7854cb 1894 }
ef416fc2 1895 else if (ppd->modelname)
e1d6a774 1896 {
1897 /*
1898 * Model name can only contain specific characters...
1899 */
1900
ef416fc2 1901 cupsdSetString(&p->make_model, ppd->modelname);
e1d6a774 1902 }
ef416fc2 1903 else
1904 cupsdSetString(&p->make_model, "Bad PPD File");
1905
bd7854cb 1906 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1907 "printer-make-and-model", NULL, p->make_model);
ef416fc2 1908
1909 /*
1910 * Add media options from the PPD file...
1911 */
1912
1913 if ((input_slot = ppdFindOption(ppd, "InputSlot")) != NULL)
1914 num_media = input_slot->num_choices;
1915 else
1916 num_media = 0;
1917
1918 if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL)
1919 num_media += media_type->num_choices;
1920
1921 if ((page_size = ppdFindOption(ppd, "PageSize")) != NULL)
1922 num_media += page_size->num_choices;
1923
1924 if ((media_quality = ppdFindOption(ppd, "EFMediaQualityMode")) != NULL)
1925 num_media += media_quality->num_choices;
1926
1927 if (num_media == 0)
1928 {
bd7854cb 1929 cupsdLogMessage(CUPSD_LOG_CRIT,
b423cd4c 1930 "The PPD file for printer %s contains no media "
1931 "options and is therefore invalid!", p->name);
ef416fc2 1932 }
1933 else
1934 {
1935 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1936 "media-supported", num_media, NULL, NULL);
1937 if (attr != NULL)
1938 {
1939 val = attr->values;
1940
1941 if (input_slot != NULL)
1942 for (i = 0; i < input_slot->num_choices; i ++, val ++)
757d2cad 1943 val->string.text = _cupsStrAlloc(input_slot->choices[i].choice);
ef416fc2 1944
1945 if (media_type != NULL)
1946 for (i = 0; i < media_type->num_choices; i ++, val ++)
757d2cad 1947 val->string.text = _cupsStrAlloc(media_type->choices[i].choice);
ef416fc2 1948
1949 if (media_quality != NULL)
1950 for (i = 0; i < media_quality->num_choices; i ++, val ++)
757d2cad 1951 val->string.text = _cupsStrAlloc(media_quality->choices[i].choice);
ef416fc2 1952
1953 if (page_size != NULL)
1954 {
1955 for (i = 0; i < page_size->num_choices; i ++, val ++)
757d2cad 1956 val->string.text = _cupsStrAlloc(page_size->choices[i].choice);
ef416fc2 1957
b423cd4c 1958 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1959 "media-default", NULL, page_size->defchoice);
ef416fc2 1960 }
1961 else if (input_slot != NULL)
b423cd4c 1962 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1963 "media-default", NULL, input_slot->defchoice);
ef416fc2 1964 else if (media_type != NULL)
b423cd4c 1965 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1966 "media-default", NULL, media_type->defchoice);
ef416fc2 1967 else if (media_quality != NULL)
b423cd4c 1968 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1969 "media-default", NULL, media_quality->defchoice);
ef416fc2 1970 else
b423cd4c 1971 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1972 "media-default", NULL, "none");
ef416fc2 1973 }
1974 }
1975
1976 /*
1977 * Output bin...
1978 */
1979
1980 if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL)
1981 {
1982 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1983 "output-bin-supported", output_bin->num_choices,
1984 NULL, NULL);
1985
1986 if (attr != NULL)
1987 {
1988 for (i = 0, val = attr->values;
1989 i < output_bin->num_choices;
1990 i ++, val ++)
757d2cad 1991 val->string.text = _cupsStrAlloc(output_bin->choices[i].choice);
ef416fc2 1992 }
1993 }
1994
1995 /*
1996 * Duplexing, etc...
1997 */
1998
b423cd4c 1999 if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL)
2000 if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL)
2001 if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL)
2002 if ((duplex = ppdFindOption(ppd, "KD03Duplex")) == NULL)
2003 duplex = ppdFindOption(ppd, "JCLDuplex");
2004
2005 if (duplex && duplex->num_choices > 1)
ef416fc2 2006 {
2007 p->type |= CUPS_PRINTER_DUPLEX;
2008
b423cd4c 2009 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2010 "sides-supported", 3, NULL, sides);
2011
2012 if (!strcasecmp(duplex->defchoice, "DuplexTumble"))
2013 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2014 "sides-default", NULL, "two-sided-short-edge");
2015 else if (!strcasecmp(duplex->defchoice, "DuplexNoTumble"))
2016 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2017 "sides-default", NULL, "two-sided-long-edge");
2018 else
2019 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2020 "sides-default", NULL, "one-sided");
ef416fc2 2021 }
2022
2023 if (ppdFindOption(ppd, "Collate") != NULL)
2024 p->type |= CUPS_PRINTER_COLLATE;
2025
2026 if (ppdFindOption(ppd, "StapleLocation") != NULL)
2027 {
2028 p->type |= CUPS_PRINTER_STAPLE;
2029 finishings[num_finishings++] = IPP_FINISHINGS_STAPLE;
2030 }
2031
2032 if (ppdFindOption(ppd, "BindEdge") != NULL)
2033 {
2034 p->type |= CUPS_PRINTER_BIND;
2035 finishings[num_finishings++] = IPP_FINISHINGS_BIND;
2036 }
2037
2038 for (i = 0; i < ppd->num_sizes; i ++)
2039 if (ppd->sizes[i].length > 1728)
2040 p->type |= CUPS_PRINTER_LARGE;
2041 else if (ppd->sizes[i].length > 1008)
2042 p->type |= CUPS_PRINTER_MEDIUM;
2043 else
2044 p->type |= CUPS_PRINTER_SMALL;
2045
2046 /*
2047 * Add a filter from application/vnd.cups-raw to printer/name to
2048 * handle "raw" printing by users.
2049 */
2050
f7deaa1a 2051 add_printer_filter(p, p->filetype, "application/vnd.cups-raw 0 -");
2052
2053 /*
2054 * Add any pre-filters in the PPD file...
2055 */
2056
2057 if ((ppdattr = ppdFindAttr(ppd, "cupsPreFilter", NULL)) != NULL)
2058 {
2059 p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", p->name);
2060
2061 for (; ppdattr; ppdattr = ppdFindNextAttr(ppd, "cupsPreFilter", NULL))
2062 if (ppdattr->value)
2063 add_printer_filter(p, p->prefiltertype, ppdattr->value);
2064 }
ef416fc2 2065
2066 /*
2067 * Add any filters in the PPD file...
2068 */
2069
2070 DEBUG_printf(("ppd->num_filters = %d\n", ppd->num_filters));
2071 for (i = 0; i < ppd->num_filters; i ++)
2072 {
2073 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i, ppd->filters[i]));
f7deaa1a 2074 add_printer_filter(p, p->filetype, ppd->filters[i]);
ef416fc2 2075 }
2076
2077 if (ppd->num_filters == 0)
2078 {
2079 /*
2080 * If there are no filters, add a PostScript printing filter.
2081 */
2082
f7deaa1a 2083 add_printer_filter(p, p->filetype,
2084 "application/vnd.cups-postscript 0 -");
ef416fc2 2085 }
2086
2087 /*
2088 * Show current and available port monitors for this printer...
2089 */
2090
2091 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "port-monitor",
2092 NULL, p->port_monitor ? p->port_monitor : "none");
2093
2094
2095 for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
2096 ppdattr;
2097 i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL));
2098
2099 if (ppd->protocols)
2100 {
2101 if (strstr(ppd->protocols, "TBCP"))
2102 i ++;
2103 else if (strstr(ppd->protocols, "BCP"))
2104 i ++;
2105 }
2106
2107 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2108 "port-monitor-supported", i, NULL, NULL);
2109
757d2cad 2110 attr->values[0].string.text = _cupsStrAlloc("none");
ef416fc2 2111
2112 for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
2113 ppdattr;
2114 i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL))
757d2cad 2115 attr->values[i].string.text = _cupsStrAlloc(ppdattr->value);
ef416fc2 2116
2117 if (ppd->protocols)
2118 {
2119 if (strstr(ppd->protocols, "TBCP"))
757d2cad 2120 attr->values[i].string.text = _cupsStrAlloc("tbcp");
ef416fc2 2121 else if (strstr(ppd->protocols, "BCP"))
757d2cad 2122 attr->values[i].string.text = _cupsStrAlloc("bcp");
ef416fc2 2123 }
2124
f7deaa1a 2125#ifdef HAVE_DNSSD
2126 cupsdSetString(&p->product, ppd->product);
2127#endif /* HAVE_DNSSD */
2128
ef416fc2 2129 /*
2130 * Close the PPD and set the type...
2131 */
2132
2133 ppdClose(ppd);
2134
e00b005a 2135 printer_type = p->type;
ef416fc2 2136 }
2137 else if (!access(filename, 0))
2138 {
2139 int pline; /* PPD line number */
2140 ppd_status_t pstatus; /* PPD load status */
2141
2142
2143 pstatus = ppdLastError(&pline);
2144
b423cd4c 2145 cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!",
2146 p->name);
ef416fc2 2147
2148 if (pstatus <= PPD_ALLOC_ERROR)
2149 cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno));
2150 else
b423cd4c 2151 cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.",
2152 ppdErrorString(pstatus), pline);
ef416fc2 2153
b423cd4c 2154 cupsdLogMessage(CUPSD_LOG_INFO,
2155 "Hint: Run \"cupstestppd %s\" and fix any errors.",
2156 filename);
ef416fc2 2157
2158 /*
2159 * Add a filter from application/vnd.cups-raw to printer/name to
2160 * handle "raw" printing by users.
2161 */
2162
f7deaa1a 2163 add_printer_filter(p, p->filetype, "application/vnd.cups-raw 0 -");
ef416fc2 2164
2165 /*
2166 * Add a PostScript filter, since this is still possibly PS printer.
2167 */
2168
f7deaa1a 2169 add_printer_filter(p, p->filetype,
2170 "application/vnd.cups-postscript 0 -");
ef416fc2 2171 }
2172 else
2173 {
2174 /*
2175 * If we have an interface script, add a filter entry for it...
2176 */
2177
2178 snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot,
2179 p->name);
b423cd4c 2180 if (!access(filename, X_OK))
ef416fc2 2181 {
2182 /*
2183 * Yes, we have a System V style interface script; use it!
2184 */
2185
2186 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
f7deaa1a 2187 "printer-make-and-model", NULL,
2188 "Local System V Printer");
ef416fc2 2189
2190 snprintf(filename, sizeof(filename), "*/* 0 %s/interfaces/%s",
2191 ServerRoot, p->name);
f7deaa1a 2192 add_printer_filter(p, p->filetype, filename);
ef416fc2 2193 }
2194 else if (p->device_uri &&
2195 !strncmp(p->device_uri, "ipp://", 6) &&
2196 (strstr(p->device_uri, "/printers/") != NULL ||
2197 strstr(p->device_uri, "/classes/") != NULL))
2198 {
2199 /*
2200 * Tell the client this is really a hard-wired remote printer.
2201 */
2202
e00b005a 2203 printer_type |= CUPS_PRINTER_REMOTE;
ef416fc2 2204
2205 /*
2206 * Point the printer-uri-supported attribute to the
2207 * remote printer...
2208 */
2209
2210 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
2211 "printer-uri-supported", NULL, p->device_uri);
2212
2213 /*
2214 * Then set the make-and-model accordingly...
2215 */
2216
2217 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2218 "printer-make-and-model", NULL, "Remote Printer");
2219
2220 /*
2221 * Print all files directly...
2222 */
2223
d09495fa 2224 p->raw = 1;
2225 p->remote = 1;
ef416fc2 2226 }
2227 else
2228 {
2229 /*
2230 * Otherwise we have neither - treat this as a "dumb" printer
2231 * with no PPD file...
2232 */
2233
2234 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2235 "printer-make-and-model", NULL, "Local Raw Printer");
2236
2237 p->raw = 1;
2238 }
2239 }
2240
2241 ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
2242 "finishings-supported", num_finishings, (int *)finishings);
2243 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
2244 "finishings-default", IPP_FINISHINGS_NONE);
2245 }
2246 }
2247
b423cd4c 2248 /*
2249 * Copy the printer options into a browse attributes string we can re-use.
2250 */
2251
2252 if (!(p->type & CUPS_PRINTER_REMOTE))
2253 {
2254 const char *valptr; /* Pointer into value */
2255 char *attrptr; /* Pointer into attribute string */
2256
2257
2258 /*
2259 * Free the old browse attributes as needed...
2260 */
2261
2262 if (p->browse_attrs)
2263 free(p->browse_attrs);
2264
2265 /*
2266 * Compute the length of all attributes + job-sheets, lease-duration,
2267 * and BrowseLocalOptions.
2268 */
2269
2270 for (length = 1, i = p->num_options, option = p->options;
2271 i > 0;
2272 i --, option ++)
2273 {
2274 length += strlen(option->name) + 2;
2275
2276 if (option->value)
2277 {
2278 for (valptr = option->value; *valptr; valptr ++)
2279 if (strchr(" \"\'\\", *valptr))
2280 length += 2;
2281 else
2282 length ++;
2283 }
2284 }
2285
2286 length += 13 + strlen(p->job_sheets[0]) + strlen(p->job_sheets[1]);
2287 length += 32;
2288 if (BrowseLocalOptions)
f7deaa1a 2289 length += 12 + strlen(BrowseLocalOptions);
b423cd4c 2290
2291 /*
2292 * Allocate the new string...
2293 */
f7deaa1a 2294
b423cd4c 2295 if ((p->browse_attrs = calloc(1, length)) == NULL)
2296 cupsdLogMessage(CUPSD_LOG_ERROR,
2297 "Unable to allocate %d bytes for browse data!",
2298 length);
2299 else
2300 {
2301 /*
2302 * Got the allocated string, now copy the options and attributes over...
2303 */
2304
2305 sprintf(p->browse_attrs, "job-sheets=%s,%s lease-duration=%d",
2306 p->job_sheets[0], p->job_sheets[1], BrowseTimeout);
2307 attrptr = p->browse_attrs + strlen(p->browse_attrs);
2308
2309 if (BrowseLocalOptions)
2310 {
2311 sprintf(attrptr, " ipp-options=%s", BrowseLocalOptions);
2312 attrptr += strlen(attrptr);
2313 }
2314
2315 for (i = p->num_options, option = p->options;
2316 i > 0;
2317 i --, option ++)
2318 {
2319 *attrptr++ = ' ';
2320 strcpy(attrptr, option->name);
2321 attrptr += strlen(attrptr);
2322
2323 if (option->value)
2324 {
2325 *attrptr++ = '=';
2326
2327 for (valptr = option->value; *valptr; valptr ++)
2328 {
2329 if (strchr(" \"\'\\", *valptr))
2330 *attrptr++ = '\\';
2331
2332 *attrptr++ = *valptr;
2333 }
2334 }
2335 }
2336
2337 *attrptr = '\0';
2338 }
2339 }
2340
bd7854cb 2341 /*
2342 * Populate the document-format-supported attribute...
2343 */
2344
2345 add_printer_formats(p);
2346
ef416fc2 2347 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p->name,
2348 p->type));
2349
b423cd4c 2350 /*
2351 * Add name-default attributes...
2352 */
2353
2354 add_printer_defaults(p);
2355
ef416fc2 2356#ifdef __sgi
2357 /*
2358 * Write the IRIX printer config and status files...
2359 */
2360
2361 write_irix_config(p);
2362 write_irix_state(p);
2363#endif /* __sgi */
f7deaa1a 2364
2365 /*
2366 * Let the browse protocols reflect the change
2367 */
2368
2369 cupsdRegisterPrinter(p);
ef416fc2 2370}
2371
2372
2373/*
2374 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2375 */
2376
2377void
2378cupsdSetPrinterReasons(
2379 cupsd_printer_t *p, /* I - Printer */
2380 const char *s) /* I - Reasons strings */
2381{
2382 int i; /* Looping var */
2383 const char *sptr; /* Pointer into reasons */
2384 char reason[255], /* Reason string */
2385 *rptr; /* Pointer into reason */
2386
2387
2388 if (s[0] == '-' || s[0] == '+')
2389 {
2390 /*
2391 * Add/remove reasons...
2392 */
2393
2394 sptr = s + 1;
2395 }
2396 else
2397 {
2398 /*
2399 * Replace reasons...
2400 */
2401
2402 sptr = s;
2403
2404 for (i = 0; i < p->num_reasons; i ++)
2405 free(p->reasons[i]);
2406
2407 p->num_reasons = 0;
2408 }
2409
2410 /*
2411 * Loop through all of the reasons...
2412 */
2413
2414 while (*sptr)
2415 {
2416 /*
2417 * Skip leading whitespace and commas...
2418 */
2419
2420 while (isspace(*sptr & 255) || *sptr == ',')
2421 sptr ++;
2422
2423 for (rptr = reason; *sptr && !isspace(*sptr & 255) && *sptr != ','; sptr ++)
2424 if (rptr < (reason + sizeof(reason) - 1))
2425 *rptr++ = *sptr;
2426
2427 if (rptr == reason)
2428 break;
2429
2430 *rptr = '\0';
2431
2432 if (s[0] == '-')
2433 {
2434 /*
2435 * Remove reason...
2436 */
2437
2438 for (i = 0; i < p->num_reasons; i ++)
2439 if (!strcasecmp(reason, p->reasons[i]))
2440 {
2441 /*
2442 * Found a match, so remove it...
2443 */
2444
2445 p->num_reasons --;
2446 free(p->reasons[i]);
2447
2448 if (i < p->num_reasons)
2449 memmove(p->reasons + i, p->reasons + i + 1,
2450 (p->num_reasons - i) * sizeof(char *));
2451
2452 i --;
2453 }
2454 }
2455 else if (p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
2456 {
2457 /*
2458 * Add reason...
2459 */
2460
2461 for (i = 0; i < p->num_reasons; i ++)
2462 if (!strcasecmp(reason, p->reasons[i]))
2463 break;
2464
2465 if (i >= p->num_reasons)
2466 {
2467 p->reasons[i] = strdup(reason);
2468 p->num_reasons ++;
2469 }
2470 }
2471 }
2472}
2473
2474
2475/*
2476 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2477 */
2478
2479void
2480cupsdSetPrinterState(
2481 cupsd_printer_t *p, /* I - Printer to change */
2482 ipp_pstate_t s, /* I - New state */
2483 int update) /* I - Update printers.conf? */
2484{
2485 ipp_pstate_t old_state; /* Old printer state */
2486
2487
2488 /*
2489 * Can't set status of remote printers...
2490 */
2491
2492 if (p->type & CUPS_PRINTER_REMOTE)
2493 return;
2494
2495 /*
2496 * Set the new state...
2497 */
2498
2499 old_state = p->state;
2500 p->state = s;
2501
2502 if (old_state != s)
2503 {
e53920b9 2504 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE_CHANGED, p, NULL,
2505 "%s \"%s\" state changed.",
2506 (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
2507 p->name);
2508
ef416fc2 2509 /*
2510 * Let the browse code know this needs to be updated...
2511 */
2512
2513 BrowseNext = p;
2514 p->state_time = time(NULL);
2515 p->browse_time = 0;
2516
2517#ifdef __sgi
2518 write_irix_state(p);
2519#endif /* __sgi */
2520 }
2521
2522 cupsdAddPrinterHistory(p);
2523
f7deaa1a 2524 /*
2525 * Let the browse protocols reflect the change...
2526 */
2527
2528 cupsdRegisterPrinter(p);
2529
ef416fc2 2530 /*
2531 * Save the printer configuration if a printer goes from idle or processing
2532 * to stopped (or visa-versa)...
2533 */
2534
2535 if ((old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED) &&
2536 update)
2537 {
2538 if (p->type & CUPS_PRINTER_CLASS)
2539 cupsdSaveAllClasses();
2540 else
2541 cupsdSaveAllPrinters();
2542 }
2543}
2544
2545
2546/*
2547 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2548 */
2549
2550void
2551cupsdStopPrinter(cupsd_printer_t *p, /* I - Printer to stop */
2552 int update)/* I - Update printers.conf? */
2553{
2554 cupsd_job_t *job; /* Active print job */
2555
2556
2557 /*
2558 * Set the printer state...
2559 */
2560
2561 cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, update);
2562
2563 /*
2564 * See if we have a job printing on this printer...
2565 */
2566
2567 if (p->job)
2568 {
2569 /*
2570 * Get pointer to job...
2571 */
2572
2573 job = (cupsd_job_t *)p->job;
2574
2575 /*
2576 * Stop it...
2577 */
2578
2579 cupsdStopJob(job, 0);
2580
2581 /*
2582 * Reset the state to pending...
2583 */
2584
2585 job->state->values[0].integer = IPP_JOB_PENDING;
bd7854cb 2586 job->state_value = IPP_JOB_PENDING;
ef416fc2 2587
2588 cupsdSaveJob(job);
07725fee 2589
2590 cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED, p, job,
2591 "Job stopped due to printer being paused");
ef416fc2 2592 }
2593}
2594
2595
2596/*
2597 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2598 */
2599
2600void
2601cupsdUpdatePrinters(void)
2602{
2603 cupsd_printer_t *p; /* Current printer */
2604
2605
2606 /*
2607 * Loop through the printers and recreate the printer attributes
2608 * for any local printers since the policy and/or access control
2609 * stuff may have changed. Also, if browsing is disabled, remove
2610 * any remote printers...
2611 */
2612
2613 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2614 p;
2615 p = (cupsd_printer_t *)cupsArrayNext(Printers))
2616 {
07725fee 2617 /*
2618 * Remove remote printers if we are no longer browsing...
2619 */
2620
ef416fc2 2621 if (!Browsing && (p->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_REMOTE)))
2622 {
2623 if (p->type & CUPS_PRINTER_IMPLICIT)
2624 cupsArrayRemove(ImplicitPrinters, p);
2625
2626 cupsArraySave(Printers);
2627 cupsdDeletePrinter(p, 0);
2628 cupsArrayRestore(Printers);
2629 continue;
2630 }
ef416fc2 2631
2632 /*
2633 * Update the operation policy pointer...
2634 */
2635
2636 if ((p->op_policy_ptr = cupsdFindPolicy(p->op_policy)) == NULL)
2637 p->op_policy_ptr = DefaultPolicyPtr;
07725fee 2638
2639 /*
2640 * Update printer attributes as needed...
2641 */
2642
2643 if (!(p->type & CUPS_PRINTER_REMOTE))
2644 cupsdSetPrinterAttrs(p);
ef416fc2 2645 }
2646}
2647
2648
2649/*
2650 * 'cupsdValidateDest()' - Validate a printer/class destination.
2651 */
2652
2653const char * /* O - Printer or class name */
2654cupsdValidateDest(
f7deaa1a 2655 const char *uri, /* I - Printer URI */
ef416fc2 2656 cups_ptype_t *dtype, /* O - Type (printer or class) */
2657 cupsd_printer_t **printer) /* O - Printer pointer */
2658{
2659 cupsd_printer_t *p; /* Current printer */
2660 char localname[1024],/* Localized hostname */
2661 *lptr, /* Pointer into localized hostname */
f7deaa1a 2662 *sptr, /* Pointer into server name */
2663 *rptr, /* Pointer into resource */
2664 scheme[32], /* Scheme portion of URI */
2665 username[64], /* Username portion of URI */
2666 hostname[HTTP_MAX_HOST],
2667 /* Host portion of URI */
2668 resource[HTTP_MAX_URI];
2669 /* Resource portion of URI */
2670 int port; /* Port portion of URI */
2671
2672
2673 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri,
ef416fc2 2674 dtype, printer));
2675
2676 /*
2677 * Initialize return values...
2678 */
2679
2680 if (printer)
2681 *printer = NULL;
2682
f7deaa1a 2683 if (dtype)
2684 *dtype = (cups_ptype_t)0;
2685
2686 /*
2687 * Pull the hostname and resource from the URI...
2688 */
2689
2690 httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
2691 username, sizeof(username), hostname, sizeof(hostname),
2692 &port, resource, sizeof(resource));
ef416fc2 2693
2694 /*
2695 * See if the resource is a class or printer...
2696 */
2697
2698 if (!strncmp(resource, "/classes/", 9))
2699 {
2700 /*
2701 * Class...
2702 */
2703
f7deaa1a 2704 rptr = resource + 9;
ef416fc2 2705 }
2706 else if (!strncmp(resource, "/printers/", 10))
2707 {
2708 /*
2709 * Printer...
2710 */
2711
f7deaa1a 2712 rptr = resource + 10;
ef416fc2 2713 }
2714 else
2715 {
2716 /*
2717 * Bad resource name...
2718 */
2719
2720 return (NULL);
2721 }
2722
2723 /*
2724 * See if the printer or class name exists...
2725 */
2726
f7deaa1a 2727 p = cupsdFindDest(rptr);
ef416fc2 2728
f7deaa1a 2729 if (p == NULL && strchr(rptr, '@') == NULL)
ef416fc2 2730 return (NULL);
2731 else if (p != NULL)
2732 {
2733 if (printer)
2734 *printer = p;
2735
f7deaa1a 2736 if (dtype)
2737 *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
2738 CUPS_PRINTER_REMOTE);
2739
ef416fc2 2740 return (p->name);
2741 }
2742
2743 /*
2744 * Change localhost to the server name...
2745 */
2746
2747 if (!strcasecmp(hostname, "localhost"))
f7deaa1a 2748 strlcpy(hostname, ServerName, sizeof(hostname));
ef416fc2 2749
2750 strlcpy(localname, hostname, sizeof(localname));
2751
2752 if (!strcasecmp(hostname, ServerName))
2753 {
2754 /*
2755 * Localize the hostname...
2756 */
2757
2758 lptr = strchr(localname, '.');
2759 sptr = strchr(ServerName, '.');
2760
2761 if (sptr != NULL && lptr != NULL)
2762 {
2763 /*
2764 * Strip the common domain name components...
2765 */
2766
2767 while (lptr != NULL)
2768 {
2769 if (!strcasecmp(lptr, sptr))
2770 {
2771 *lptr = '\0';
2772 break;
2773 }
2774 else
2775 lptr = strchr(lptr + 1, '.');
2776 }
2777 }
2778 }
2779
2780 DEBUG_printf(("localized hostname is \"%s\"...\n", localname));
2781
2782 /*
2783 * Find a matching printer or class...
2784 */
2785
2786 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2787 p;
2788 p = (cupsd_printer_t *)cupsArrayNext(Printers))
2789 if (!strcasecmp(p->hostname, localname) &&
f7deaa1a 2790 !strcasecmp(p->name, rptr))
ef416fc2 2791 {
2792 if (printer)
2793 *printer = p;
2794
f7deaa1a 2795 if (dtype)
2796 *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
2797 CUPS_PRINTER_REMOTE);
2798
ef416fc2 2799 return (p->name);
2800 }
2801
2802 return (NULL);
2803}
2804
2805
2806/*
2807 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2808 * that need it...
2809 */
2810
2811void
2812cupsdWritePrintcap(void)
2813{
2814 cups_file_t *fp; /* printcap file */
2815 cupsd_printer_t *p; /* Current printer */
2816
2817
2818#ifdef __sgi
2819 /*
2820 * Update the IRIX printer state for the default printer; if
2821 * no printers remain, then the default printer file will be
2822 * removed...
2823 */
2824
2825 write_irix_state(DefaultPrinter);
2826#endif /* __sgi */
2827
2828 /*
2829 * See if we have a printcap file; if not, don't bother writing it.
2830 */
2831
2832 if (!Printcap || !*Printcap)
2833 return;
2834
2835 /*
2836 * Open the printcap file...
2837 */
2838
2839 if ((fp = cupsFileOpen(Printcap, "w")) == NULL)
2840 return;
2841
2842 /*
2843 * Put a comment header at the top so that users will know where the
2844 * data has come from...
2845 */
2846
2847 cupsFilePuts(fp, "# This file was automatically generated by cupsd(8) from the\n");
2848 cupsFilePrintf(fp, "# %s/printers.conf file. All changes to this file\n",
2849 ServerRoot);
2850 cupsFilePuts(fp, "# will be lost.\n");
2851
2852 if (Printers)
2853 {
2854 /*
2855 * Write a new printcap with the current list of printers.
2856 */
2857
2858 switch (PrintcapFormat)
2859 {
2860 case PRINTCAP_BSD:
2861 /*
2862 * Each printer is put in the file as:
2863 *
2864 * Printer1:
2865 * Printer2:
2866 * Printer3:
2867 * ...
2868 * PrinterN:
2869 */
2870
2871 if (DefaultPrinter)
2872 cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
2873 DefaultPrinter->info, ServerName, DefaultPrinter->name);
2874
2875 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2876 p;
2877 p = (cupsd_printer_t *)cupsArrayNext(Printers))
2878 if (p != DefaultPrinter)
2879 cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
2880 ServerName, p->name);
2881 break;
2882
2883 case PRINTCAP_SOLARIS:
2884 /*
2885 * Each printer is put in the file as:
2886 *
2887 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2888 * _default:use=DefaultPrinter
2889 * Printer1:\
2890 * :bsdaddr=ServerName,Printer1:\
2891 * :description=Description:
2892 * Printer2:
2893 * :bsdaddr=ServerName,Printer2:\
2894 * :description=Description:
2895 * Printer3:
2896 * :bsdaddr=ServerName,Printer3:\
2897 * :description=Description:
2898 * ...
2899 * PrinterN:
2900 * :bsdaddr=ServerName,PrinterN:\
2901 * :description=Description:
2902 */
2903
2904 cupsFilePuts(fp, "_all:all=");
2905 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2906 p;
2907 p = (cupsd_printer_t *)cupsArrayCurrent(Printers))
2908 cupsFilePrintf(fp, "%s%c", p->name,
2909 cupsArrayNext(Printers) ? ',' : '\n');
2910
2911 if (DefaultPrinter)
2912 cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);
2913
2914 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2915 p;
2916 p = (cupsd_printer_t *)cupsArrayNext(Printers))
2917 cupsFilePrintf(fp, "%s:\\\n"
2918 "\t:bsdaddr=%s,%s:\\\n"
2919 "\t:description=%s:\n",
2920 p->name, ServerName, p->name, p->info ? p->info : "");
2921 break;
2922 }
2923 }
2924
2925 /*
2926 * Close the file...
2927 */
2928
2929 cupsFileClose(fp);
2930}
2931
2932
2933/*
2934 * 'cupsdSanitizeURI()' - Sanitize a device URI...
2935 */
2936
2937char * /* O - New device URI */
2938cupsdSanitizeURI(const char *uri, /* I - Original device URI */
2939 char *buffer, /* O - New device URI */
2940 int buflen) /* I - Size of new device URI buffer */
2941{
2942 char *start, /* Start of data after scheme */
2943 *slash, /* First slash after scheme:// */
2944 *ptr; /* Pointer into user@host:port part */
2945
2946
2947 /*
2948 * Range check input...
2949 */
2950
2951 if (!uri || !buffer || buflen < 2)
2952 return (NULL);
2953
2954 /*
2955 * Copy the device URI to the new buffer...
2956 */
2957
2958 strlcpy(buffer, uri, buflen);
2959
2960 /*
2961 * Find the end of the scheme:// part...
2962 */
2963
2964 if ((ptr = strchr(buffer, ':')) == NULL)
2965 return (buffer); /* No scheme: part... */
2966
2967 for (start = ptr + 1; *start; start ++)
2968 if (*start != '/')
2969 break;
2970
2971 /*
2972 * Find the next slash (/) in the URI...
2973 */
2974
2975 if ((slash = strchr(start, '/')) == NULL)
2976 slash = start + strlen(start); /* No slash, point to the end */
2977
2978 /*
2979 * Check for an @ sign before the slash...
2980 */
2981
2982 if ((ptr = strchr(start, '@')) != NULL && ptr < slash)
2983 {
2984 /*
2985 * Found an @ sign and it is before the resource part, so we have
2986 * an authentication string. Copy the remaining URI over the
2987 * authentication string...
2988 */
2989
2990 _cups_strcpy(start, ptr + 1);
2991 }
2992
2993 /*
2994 * Return the new device URI...
2995 */
2996
2997 return (buffer);
2998}
2999
3000
b423cd4c 3001/*
3002 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3003 */
3004
3005static void
3006add_printer_defaults(cupsd_printer_t *p)/* I - Printer */
3007{
3008 int i; /* Looping var */
3009 int num_options; /* Number of default options */
3010 cups_option_t *options, /* Default options */
3011 *option; /* Current option */
3012 char name[256]; /* name-default */
3013
3014
f7deaa1a 3015 /*
3016 * Maintain a common array of default attribute names...
3017 */
3018
3019 if (!CommonDefaults)
3020 {
3021 CommonDefaults = cupsArrayNew((cups_array_func_t)strcmp, NULL);
3022
3023 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("copies-default"));
3024 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("document-format-default"));
3025 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("finishings-default"));
3026 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-hold-until-default"));
3027 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-priority-default"));
3028 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-sheets-default"));
3029 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("media-default"));
3030 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("number-up-default"));
3031 cupsArrayAdd(CommonDefaults,
3032 _cupsStrAlloc("orientation-requested-default"));
3033 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("sides-default"));
3034 }
3035
b423cd4c 3036 /*
3037 * Add all of the default options from the .conf files...
3038 */
3039
3040 for (num_options = 0, i = p->num_options, option = p->options;
3041 i > 0;
3042 i --, option ++)
3043 {
3044 if (strcmp(option->name, "ipp-options") &&
3045 strcmp(option->name, "job-sheets") &&
3046 strcmp(option->name, "lease-duration"))
3047 {
3048 snprintf(name, sizeof(name), "%s-default", option->name);
3049 num_options = cupsAddOption(name, option->value, num_options, &options);
f7deaa1a 3050
3051 if (!cupsArrayFind(CommonDefaults, name))
3052 cupsArrayAdd(CommonDefaults, _cupsStrAlloc(name));
b423cd4c 3053 }
3054 }
3055
3056 /*
3057 * Convert options to IPP attributes...
3058 */
3059
3060 cupsEncodeOptions2(p->attrs, num_options, options, IPP_TAG_PRINTER);
3061 cupsFreeOptions(num_options, options);
3062
3063 /*
3064 * Add standard -default attributes as needed...
3065 */
3066
3067 if (!cupsGetOption("copies", p->num_options, p->options))
3068 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default",
3069 1);
3070
f7deaa1a 3071 if (!cupsGetOption("document-format", p->num_options, p->options))
3072 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
3073 "document-format-default", NULL, "application/octet-stream");
3074
b423cd4c 3075 if (!cupsGetOption("job-hold-until", p->num_options, p->options))
3076 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
3077 "job-hold-until-default", NULL, "no-hold");
3078
3079 if (!cupsGetOption("job-priority", p->num_options, p->options))
3080 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
3081 "job-priority-default", 50);
3082
3083 if (!cupsGetOption("number-up", p->num_options, p->options))
3084 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
3085 "number-up-default", 1);
3086
3087 if (!cupsGetOption("orientation-requested", p->num_options, p->options))
3088 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
3089 "orientation-requested-default", IPP_PORTRAIT);
f7deaa1a 3090
3091 if (!cupsGetOption("notify-lease-duration", p->num_options, p->options))
3092 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
3093 "notify-lease-duration-default", DefaultLeaseDuration);
3094
3095 if (!cupsGetOption("notify-events", p->num_options, p->options))
3096 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
3097 "notify-events-default", NULL, "job-completed");
b423cd4c 3098}
3099
3100
bd7854cb 3101/*
3102 * 'add_printer_filter()' - Add a MIME filter for a printer.
3103 */
3104
3105static void
3106add_printer_filter(
3107 cupsd_printer_t *p, /* I - Printer to add to */
f7deaa1a 3108 mime_type_t *filtertype, /* I - Filter or prefilter MIME type */
bd7854cb 3109 const char *filter) /* I - Filter to add */
3110{
3111 char super[MIME_MAX_SUPER], /* Super-type for filter */
3112 type[MIME_MAX_TYPE], /* Type for filter */
3113 program[1024]; /* Program/filter name */
3114 int cost; /* Cost of filter */
3115 mime_type_t *temptype; /* MIME type looping var */
3116 char filename[1024]; /* Full filter filename */
3117
3118
3119 /*
3120 * Parse the filter string; it should be in the following format:
3121 *
3122 * super/type cost program
3123 */
3124
3125 if (sscanf(filter, "%15[^/]/%31s%d%1023s", super, type, &cost, program) != 4)
3126 {
3127 cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!",
3128 p->name, filter);
3129 return;
3130 }
3131
3132 /*
3133 * See if the filter program exists; if not, stop the printer and flag
3134 * the error!
3135 */
3136
ecdc0628 3137 if (strcmp(program, "-"))
bd7854cb 3138 {
ecdc0628 3139 if (program[0] == '/')
3140 strlcpy(filename, program, sizeof(filename));
3141 else
3142 snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program);
3143
3144 if (access(filename, X_OK))
3145 {
3146 snprintf(p->state_message, sizeof(p->state_message),
3147 "Filter \"%s\" for printer \"%s\" not available: %s",
3148 program, p->name, strerror(errno));
ecdc0628 3149 cupsdSetPrinterReasons(p, "+cups-missing-filter-error");
07725fee 3150 cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 0);
ecdc0628 3151
3152 cupsdLogMessage(CUPSD_LOG_ERROR, "%s", p->state_message);
3153 }
bd7854cb 3154 }
3155
b423cd4c 3156 /*
3157 * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
3158 * application/vnd.cups-command...
3159 */
3160
3161 if (!strcasecmp(super, "application") &&
3162 !strcasecmp(type, "vnd.cups-command"))
3163 p->type |= CUPS_PRINTER_COMMANDS;
3164
bd7854cb 3165 /*
3166 * Add the filter to the MIME database, supporting wildcards as needed...
3167 */
3168
3169 for (temptype = mimeFirstType(MimeDatabase);
3170 temptype;
3171 temptype = mimeNextType(MimeDatabase))
3172 if (((super[0] == '*' && strcasecmp(temptype->super, "printer")) ||
3173 !strcasecmp(temptype->super, super)) &&
3174 (type[0] == '*' || !strcasecmp(temptype->type, type)))
3175 {
3176 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3177 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
3178 p->name, temptype->super, temptype->type,
f7deaa1a 3179 filtertype->super, filtertype->type,
bd7854cb 3180 cost, program);
f7deaa1a 3181 mimeAddFilter(MimeDatabase, temptype, filtertype, cost, program);
bd7854cb 3182 }
3183}
3184
3185
3186/*
3187 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3188 */
3189
3190static void
3191add_printer_formats(cupsd_printer_t *p) /* I - Printer */
3192{
3193 int i; /* Looping var */
3194 mime_type_t *type; /* Current MIME type */
3195 cups_array_t *filters; /* Filters */
80ca4592 3196 ipp_attribute_t *attr; /* document-format-supported attribute */
bd7854cb 3197 char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2];
3198 /* MIME type name */
3199
3200
3201 /*
3202 * Raw (and remote) queues advertise all of the supported MIME
3203 * types...
3204 */
3205
80ca4592 3206 cupsArrayDelete(p->filetypes);
3207 p->filetypes = NULL;
3208
bd7854cb 3209 if (p->raw)
3210 {
3211 ippAddStrings(p->attrs, IPP_TAG_PRINTER,
3212 (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY),
3213 "document-format-supported", NumMimeTypes, NULL, MimeTypes);
3214 return;
3215 }
3216
3217 /*
3218 * Otherwise, loop through the supported MIME types and see if there
3219 * are filters for them...
3220 */
3221
bd7854cb 3222 cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters",
3223 mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
3224
80ca4592 3225 p->filetypes = cupsArrayNew(NULL, NULL);
bd7854cb 3226
80ca4592 3227 for (type = mimeFirstType(MimeDatabase);
bd7854cb 3228 type;
3229 type = mimeNextType(MimeDatabase))
3230 {
bd7854cb 3231 snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
3232
3233 if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL)
3234 {
3235 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3236 "add_printer_formats: %s: %s needs %d filters",
3237 p->name, mimetype, cupsArrayCount(filters));
3238
3239 cupsArrayDelete(filters);
80ca4592 3240 cupsArrayAdd(p->filetypes, type);
bd7854cb 3241 }
3242 else
3243 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3244 "add_printer_formats: %s: %s not supported",
3245 p->name, mimetype);
3246 }
3247
3248 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3249 "add_printer_formats: %s: %d supported types",
80ca4592 3250 p->name, cupsArrayCount(p->filetypes) + 1);
bd7854cb 3251
3252 /*
3253 * Add the file formats that can be filtered...
3254 */
3255
f301802f 3256 if ((type = mimeType(MimeDatabase, "application", "octet-stream")) == NULL ||
3257 !cupsArrayFind(p->filetypes, type))
3258 i = 1;
3259 else
3260 i = 0;
bd7854cb 3261
80ca4592 3262 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
3263 "document-format-supported",
3264 cupsArrayCount(p->filetypes) + 1, NULL, NULL);
3265
f301802f 3266 if (i)
3267 attr->values[0].string.text = _cupsStrAlloc("application/octet-stream");
bd7854cb 3268
f301802f 3269 for (type = (mime_type_t *)cupsArrayFirst(p->filetypes);
80ca4592 3270 type;
3271 i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes))
3272 {
3273 snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
bd7854cb 3274
80ca4592 3275 attr->values[i].string.text = _cupsStrAlloc(mimetype);
3276 }
f7deaa1a 3277
3278#ifdef HAVE_DNSSD
3279 {
3280 char pdl[1024]; /* Buffer to build pdl list */
3281 mime_filter_t *filter; /* MIME filter looping var */
3282
3283
3284 pdl[0] = '\0';
3285
3286 if (mimeType(MimeDatabase, "application", "pdf"))
3287 strlcat(pdl, "application/pdf,", sizeof(pdl));
3288
3289 if (mimeType(MimeDatabase, "application", "postscript"))
3290 strlcat(pdl, "application/postscript,", sizeof(pdl));
3291
3292 if (mimeType(MimeDatabase, "application", "vnd.cups-raster"))
3293 strlcat(pdl, "application/vnd.cups-raster,", sizeof(pdl));
3294
3295 /*
3296 * Determine if this is a Tioga PrintJobMgr based queue...
3297 */
3298
3299 for (filter = (mime_filter_t *)cupsArrayFirst(MimeDatabase->filters);
3300 filter;
3301 filter = (mime_filter_t *)cupsArrayNext(MimeDatabase->filters))
3302 {
3303 if (filter->dst == p->filetype && filter->filter &&
3304 strstr(filter->filter, "PrintJobMgr"))
3305 break;
3306 }
3307
3308 /*
3309 * We only support raw printing if this is not a Tioga PrintJobMgr based
3310 * queue and if application/octet-stream is a known conversion...
3311 */
3312
3313 if (!filter && mimeType(MimeDatabase, "application", "octet-stream"))
3314 strlcat(pdl, "application/octet-stream,", sizeof(pdl));
3315
3316 if (mimeType(MimeDatabase, "image", "png"))
3317 strlcat(pdl, "image/png,", sizeof(pdl));
3318
3319 if (pdl[0])
3320 pdl[strlen(pdl) - 1] = '\0'; /* Remove trailing comma */
3321
3322 cupsdSetString(&p->pdl, pdl);
3323 }
3324#endif /* HAVE_DNSSD */
bd7854cb 3325}
3326
3327
ef416fc2 3328/*
3329 * 'compare_printers()' - Compare two printers.
3330 */
3331
3332static int /* O - Result of comparison */
3333compare_printers(void *first, /* I - First printer */
3334 void *second, /* I - Second printer */
3335 void *data) /* I - App data (not used) */
3336{
3337 return (strcasecmp(((cupsd_printer_t *)first)->name,
3338 ((cupsd_printer_t *)second)->name));
3339}
3340
3341
bd7854cb 3342/*
e1d6a774 3343 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
bd7854cb 3344 */
3345
3346static void
e1d6a774 3347delete_printer_filters(
3348 cupsd_printer_t *p) /* I - Printer to remove from */
bd7854cb 3349{
e1d6a774 3350 mime_filter_t *filter; /* MIME filter looping var */
bd7854cb 3351
bd7854cb 3352
3353 /*
e1d6a774 3354 * Range check input...
bd7854cb 3355 */
3356
e1d6a774 3357 if (p == NULL)
3358 return;
bd7854cb 3359
3360 /*
e1d6a774 3361 * Remove all filters from the MIME database that have a destination
3362 * type == printer...
bd7854cb 3363 */
3364
e1d6a774 3365 for (filter = mimeFirstFilter(MimeDatabase);
3366 filter;
3367 filter = mimeNextFilter(MimeDatabase))
3368 if (filter->dst == p->filetype)
3369 {
3370 /*
3371 * Delete the current filter...
3372 */
bd7854cb 3373
e1d6a774 3374 mimeDeleteFilter(MimeDatabase, filter);
3375 }
bd7854cb 3376}
3377
3378
ef416fc2 3379#ifdef __sgi
3380/*
3381 * 'write_irix_config()' - Update the config files used by the IRIX
3382 * desktop tools.
3383 */
3384
3385static void
3386write_irix_config(cupsd_printer_t *p) /* I - Printer to update */
3387{
3388 char filename[1024]; /* Interface script filename */
3389 cups_file_t *fp; /* Interface script file */
f301802f 3390 ipp_attribute_t *attr; /* Attribute data */
ef416fc2 3391
3392
3393 /*
3394 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
3395 * tools. First the interface script that tells the tools what kind of
3396 * printer we have...
3397 */
3398
3399 snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);
3400
3401 if (p->type & CUPS_PRINTER_CLASS)
3402 unlink(filename);
3403 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
3404 {
3405 cupsFilePuts(fp, "#!/bin/sh\n");
3406
3407 if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model",
3408 IPP_TAG_TEXT)) != NULL)
3409 cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);
3410 else if (p->type & CUPS_PRINTER_CLASS)
3411 cupsFilePuts(fp, "NAME=\"Printer Class\"\n");
3412 else
3413 cupsFilePuts(fp, "NAME=\"Remote Destination\"\n");
3414
3415 if (p->type & CUPS_PRINTER_COLOR)
3416 cupsFilePuts(fp, "TYPE=ColorPostScript\n");
3417 else
3418 cupsFilePuts(fp, "TYPE=MonoPostScript\n");
3419
3420 cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName);
3421 cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name);
3422
3423 cupsFileClose(fp);
3424
3425 chmod(filename, 0755);
3426 chown(filename, User, Group);
3427 }
3428
3429 /*
3430 * Then the member file that tells which device file the queue is connected
3431 * to... Networked printers use "/dev/null" in this file, so that's what
3432 * we use (the actual device URI can confuse some apps...)
3433 */
3434
3435 snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);
3436
3437 if (p->type & CUPS_PRINTER_CLASS)
3438 unlink(filename);
3439 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
3440 {
3441 cupsFilePuts(fp, "/dev/null\n");
3442
3443 cupsFileClose(fp);
3444
3445 chmod(filename, 0644);
3446 chown(filename, User, Group);
3447 }
3448
3449 /*
3450 * The gui_interface file is a script or program that launches a GUI
3451 * option panel for the printer, using options specified on the
3452 * command-line in the third argument. The option panel must send
3453 * any printing options to stdout on a single line when the user
3454 * accepts them, or nothing if the user cancels the dialog.
3455 *
3456 * The default options panel program is /usr/bin/glpoptions, from
3457 * the ESP Print Pro software. You can select another using the
3458 * PrintcapGUI option.
3459 */
3460
3461 snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", p->name);
3462
3463 if (p->type & CUPS_PRINTER_CLASS)
3464 unlink(filename);
3465 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
3466 {
3467 cupsFilePuts(fp, "#!/bin/sh\n");
3468 cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
3469
3470 cupsFileClose(fp);
3471
3472 chmod(filename, 0755);
3473 chown(filename, User, Group);
3474 }
3475
3476 /*
3477 * The POD config file is needed by the printstatus command to show
3478 * the printer location and device.
3479 */
3480
3481 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);
3482
3483 if (p->type & CUPS_PRINTER_CLASS)
3484 unlink(filename);
3485 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
3486 {
3487 cupsFilePrintf(fp, "Printer Class | %s\n",
3488 (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript");
3489 cupsFilePrintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : "");
3490 cupsFilePrintf(fp, "Location Code | %s\n", p->location ? p->location : "");
3491 cupsFilePrintf(fp, "Physical Location | %s\n", p->info ? p->info : "");
3492 cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri ? p->device_uri : "");
3493 cupsFilePrintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name);
3494 cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
3495 cupsFilePuts(fp, "Status Update Wait | 10 seconds\n");
3496
3497 cupsFileClose(fp);
3498
3499 chmod(filename, 0664);
3500 chown(filename, User, Group);
3501 }
3502}
3503
3504
3505/*
3506 * 'write_irix_state()' - Update the status files used by IRIX printing
3507 * desktop tools.
3508 */
3509
3510static void
3511write_irix_state(cupsd_printer_t *p) /* I - Printer to update */
3512{
3513 char filename[1024]; /* Interface script filename */
3514 cups_file_t *fp; /* Interface script file */
3515 int tag; /* Status tag value */
3516
3517
3518 if (p)
3519 {
3520 /*
3521 * The POD status file is needed for the printstatus window to
3522 * provide the current status of the printer.
3523 */
3524
3525 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);
3526
3527 if (p->type & CUPS_PRINTER_CLASS)
3528 unlink(filename);
3529 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
3530 {
3531 cupsFilePrintf(fp, "Operational Status | %s\n",
3532 (p->state == IPP_PRINTER_IDLE) ? "Idle" :
3533 (p->state == IPP_PRINTER_PROCESSING) ? "Busy" :
3534 "Faulted");
3535 cupsFilePrintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION);
3536 cupsFilePrintf(fp, "Information | 02 00 00 | Device URI: %s\n",
3537 p->device_uri ? p->device_uri : "");
3538 cupsFilePrintf(fp, "Information | 03 00 00 | %s jobs\n",
3539 p->accepting ? "Accepting" : "Not accepting");
3540 cupsFilePrintf(fp, "Information | 04 00 00 | %s\n", p->state_message);
3541
3542 cupsFileClose(fp);
3543
3544 chmod(filename, 0664);
3545 chown(filename, User, Group);
3546 }
3547
3548 /*
3549 * The activeicons file is needed to provide desktop icons for printers:
3550 *
3551 * [ quoted from /usr/lib/print/tagit ]
3552 *
3553 * --- Type of printer tags (base values)
3554 *
3555 * Dumb=66048 # 0x10200
3556 * DumbColor=66080 # 0x10220
3557 * Raster=66112 # 0x10240
3558 * ColorRaster=66144 # 0x10260
3559 * Plotter=66176 # 0x10280
3560 * PostScript=66208 # 0x102A0
3561 * ColorPostScript=66240 # 0x102C0
3562 * MonoPostScript=66272 # 0x102E0
3563 *
3564 * --- Printer state modifiers for local printers
3565 *
3566 * Idle=0 # 0x0
3567 * Busy=1 # 0x1
3568 * Faulted=2 # 0x2
3569 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3570 *
3571 * --- Printer state modifiers for network printers
3572 *
3573 * NetIdle=8 # 0x8
3574 * NetBusy=9 # 0x9
3575 * NetFaulted=10 # 0xA
3576 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3577 */
3578
3579 snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);
3580
3581 if (p->type & CUPS_PRINTER_CLASS)
3582 unlink(filename);
3583 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
3584 {
3585 if (p->type & CUPS_PRINTER_COLOR)
3586 tag = 66240;
3587 else
3588 tag = 66272;
3589
3590 if (p->type & CUPS_PRINTER_REMOTE)
3591 tag |= 8;
3592
3593 if (p->state == IPP_PRINTER_PROCESSING)
3594 tag |= 1;
3595
3596 else if (p->state == IPP_PRINTER_STOPPED)
3597 tag |= 2;
3598
3599 cupsFilePuts(fp, "#!/bin/sh\n");
3600 cupsFilePrintf(fp, "#Tag %d\n", tag);
3601
3602 cupsFileClose(fp);
3603
3604 chmod(filename, 0755);
3605 chown(filename, User, Group);
3606 }
3607 }
3608
3609 /*
3610 * The default file is needed by the printers window to show
3611 * the default printer.
3612 */
3613
3614 snprintf(filename, sizeof(filename), "/var/spool/lp/default");
3615
3616 if (DefaultPrinter != NULL)
3617 {
3618 if ((fp = cupsFileOpen(filename, "w")) != NULL)
3619 {
3620 cupsFilePrintf(fp, "%s\n", DefaultPrinter->name);
3621
3622 cupsFileClose(fp);
3623
3624 chmod(filename, 0644);
3625 chown(filename, User, Group);
3626 }
3627 }
3628 else
3629 unlink(filename);
3630}
3631#endif /* __sgi */
3632
3633
3634/*
f7deaa1a 3635 * End of "$Id: printers.c 6318 2007-03-06 04:36:55Z mike $".
ef416fc2 3636 */