2 * "$Id: printers.c 10295 2012-02-15 23:21:06Z mike $"
4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2012 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdAddPrinter() - Add a printer to the system.
18 * cupsdCreateCommonData() - Create the common printer data.
19 * cupsdDeleteAllPrinters() - Delete all printers from the system.
20 * cupsdDeletePrinter() - Delete a printer from the system.
21 * cupsdFindDest() - Find a destination in the list.
22 * cupsdFindPrinter() - Find a printer in the list.
23 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
24 * cupsdRenamePrinter() - Rename a printer.
25 * cupsdSaveAllPrinters() - Save all printer definitions to the
27 * cupsdSetAuthInfoRequired() - Set the required authentication info.
28 * cupsdSetDeviceURI() - Set the device URI for a printer.
29 * cupsdSetPrinterAttr() - Set a printer attribute.
30 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
32 * cupsdSetPrinterReasons() - Set/update the reasons strings.
33 * cupsdSetPrinterState() - Update the current state of a printer.
34 * cupsdStopPrinter() - Stop a printer from printing any jobs...
35 * cupsdUpdatePrinterPPD() - Update keywords in a printer's PPD file.
36 * cupsdUpdatePrinters() - Update printers after a partial reload.
37 * cupsdValidateDest() - Validate a printer/class destination.
38 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
39 * applications that need it...
40 * add_printer_defaults() - Add name-default attributes to the printer
42 * add_printer_filter() - Add a MIME filter for a printer.
43 * add_printer_formats() - Add document-format-supported values for a
45 * compare_printers() - Compare two printers.
46 * delete_printer_filters() - Delete all MIME filters for a printer.
47 * dirty_printer() - Mark config and state files dirty for the
49 * load_ppd() - Load a cached PPD file, updating the cache as
51 * new_media_col() - Create a media-col collection value.
52 * write_irix_config() - Update the config files used by the IRIX
54 * write_irix_state() - Update the status files used by IRIX printing
56 * write_xml_string() - Write a string with XML escaping.
60 * Include necessary headers...
65 #ifdef HAVE_APPLICATIONSERVICES_H
66 # include <ApplicationServices/ApplicationServices.h>
67 #endif /* HAVE_APPLICATIONSERVICES_H */
68 #ifdef HAVE_SYS_MOUNT_H
69 # include <sys/mount.h>
70 #endif /* HAVE_SYS_MOUNT_H */
71 #ifdef HAVE_SYS_STATVFS_H
72 # include <sys/statvfs.h>
73 #elif defined(HAVE_SYS_STATFS_H)
74 # include <sys/statfs.h>
75 #endif /* HAVE_SYS_STATVFS_H */
78 #endif /* HAVE_SYS_VFS_H */
81 #endif /* __APPLE__ */
85 #endif /* HAVE_DBUS */
91 static void add_printer_defaults(cupsd_printer_t *p);
92 static void add_printer_filter(cupsd_printer_t *p, mime_type_t *type,
94 static void add_printer_formats(cupsd_printer_t *p);
95 static int compare_printers(void *first, void *second, void *data);
96 static void delete_printer_filters(cupsd_printer_t *p);
97 static void dirty_printer(cupsd_printer_t *p);
98 static void load_ppd(cupsd_printer_t *p);
99 static void log_ipp_conformance(cupsd_printer_t *p, const char *reason);
100 static ipp_t *new_media_col(_pwg_size_t *size, const char *source,
103 static void write_irix_config(cupsd_printer_t *p);
104 static void write_irix_state(cupsd_printer_t *p);
106 static void write_xml_string(cups_file_t *fp, const char *s);
110 * 'cupsdAddPrinter()' - Add a printer to the system.
113 cupsd_printer_t * /* O - New printer */
114 cupsdAddPrinter(const char *name) /* I - Name of printer */
116 cupsd_printer_t *p; /* New printer */
117 char uri[1024], /* Printer URI */
118 uuid[64]; /* Printer UUID */
122 * Range check input...
125 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdAddPrinter(\"%s\")", name);
128 * Create a new printer entity...
131 if ((p = calloc(1, sizeof(cupsd_printer_t))) == NULL)
133 cupsdLogMessage(CUPSD_LOG_CRIT, "Unable to allocate memory for printer - %s",
138 cupsdSetString(&p->name, name);
139 cupsdSetString(&p->info, name);
140 cupsdSetString(&p->hostname, ServerName);
142 httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
143 ServerName, RemotePort, "/printers/%s", name);
144 cupsdSetString(&p->uri, uri);
145 cupsdSetString(&p->uuid, _httpAssembleUUID(ServerName, RemotePort, name, 0,
146 uuid, sizeof(uuid)));
147 cupsdSetDeviceURI(p, "file:///dev/null");
149 p->state = IPP_PRINTER_STOPPED;
150 p->state_time = time(NULL);
152 p->shared = DefaultShared;
153 p->filetype = mimeAddType(MimeDatabase, "printer", name);
155 cupsdSetString(&p->job_sheets[0], "none");
156 cupsdSetString(&p->job_sheets[1], "none");
158 cupsdSetString(&p->error_policy, ErrorPolicy);
159 cupsdSetString(&p->op_policy, DefaultPolicy);
161 p->op_policy_ptr = DefaultPolicyPtr;
164 * Insert the printer in the printer list alphabetically...
168 Printers = cupsArrayNew(compare_printers, NULL);
170 cupsdLogMessage(CUPSD_LOG_DEBUG2,
171 "cupsdAddPrinter: Adding %s to Printers", p->name);
172 cupsArrayAdd(Printers, p);
174 if (!ImplicitPrinters)
175 ImplicitPrinters = cupsArrayNew(compare_printers, NULL);
178 * Return the new printer...
186 * 'cupsdCreateCommonData()' - Create the common printer data.
190 cupsdCreateCommonData(void)
192 int i; /* Looping var */
193 ipp_attribute_t *attr; /* Attribute data */
194 cups_dir_t *dir; /* Notifier directory */
195 cups_dentry_t *dent; /* Notifier directory entry */
196 cups_array_t *notifiers; /* Notifier array */
197 char filename[1024], /* Filename */
198 *notifier; /* Current notifier */
199 cupsd_policy_t *p; /* Current policy */
200 int k_supported; /* Maximum file size supported */
202 struct statvfs spoolinfo; /* FS info for spool directory */
203 double spoolsize; /* FS size */
204 #elif defined(HAVE_STATFS)
205 struct statfs spoolinfo; /* FS info for spool directory */
206 double spoolsize; /* FS size */
207 #endif /* HAVE_STATVFS */
208 static const int nups[] = /* number-up-supported values */
209 { 1, 2, 4, 6, 9, 16 };
210 static const int orients[4] =/* orientation-requested-supported values */
214 IPP_REVERSE_LANDSCAPE,
217 static const char * const holds[] = /* job-hold-until-supported values */
228 static const char * const versions[] =/* ipp-versions-supported values */
235 static const int ops[] = /* operations-supported values */
242 IPP_GET_JOB_ATTRIBUTES,
244 IPP_GET_PRINTER_ATTRIBUTES,
251 IPP_SET_PRINTER_ATTRIBUTES,
252 IPP_SET_JOB_ATTRIBUTES,
253 IPP_GET_PRINTER_SUPPORTED_VALUES,
254 IPP_CREATE_PRINTER_SUBSCRIPTION,
255 IPP_CREATE_JOB_SUBSCRIPTION,
256 IPP_GET_SUBSCRIPTION_ATTRIBUTES,
257 IPP_GET_SUBSCRIPTIONS,
258 IPP_RENEW_SUBSCRIPTION,
259 IPP_CANCEL_SUBSCRIPTION,
260 IPP_GET_NOTIFICATIONS,
264 IPP_RELEASE_HELD_NEW_JOBS,
281 CUPS_AUTHENTICATE_JOB,
286 static const char * const charsets[] =/* charset-supported values */
291 static const char * const compressions[] =
292 { /* document-compression-supported values */
296 #endif /* HAVE_LIBZ */
298 static const char * const media_col_supported[] =
299 { /* media-col-supported values */
300 "media-bottom-margin",
302 "media-right-margin",
308 static const char * const multiple_document_handling[] =
309 { /* multiple-document-handling-supported values */
310 "separate-documents-uncollated-copies",
311 "separate-documents-collated-copies"
313 static const char * const notify_attrs[] =
314 { /* notify-attributes-supported values */
315 "printer-state-change-time",
316 "notify-lease-expiration-time",
317 "notify-subscriber-user-name"
319 static const char * const notify_events[] =
320 { /* notify-events-supported values */
322 "job-config-changed",
329 "printer-config-changed",
331 "printer-finishings-changed",
332 "printer-media-changed",
336 "printer-state-changed",
343 static const char * const job_creation[] =
344 { /* job-creation-attributes-supported */
347 "ipp-attribute-fidelity",
354 "multiple-document-handling",
358 "orientation-requested",
361 "printer-resolution",
364 static const char * const job_settable[] =
365 { /* job-settable-attributes-supported */
373 "multiple-document-handling",
377 "orientation-requested",
380 "printer-resolution",
383 static const char * const pdf_versions[] =
384 { /* pdf-versions-supported */
395 static const char * const printer_settable[] =
396 { /* printer-settable-attributes-supported */
400 static const char * const which_jobs[] =
401 { /* which-jobs-supported values */
415 ippDelete(CommonData);
417 CommonData = ippNew();
420 * Get the maximum spool size based on the size of the filesystem used for
421 * the RequestRoot directory. If the host OS doesn't support the statfs call
422 * or the filesystem is larger than 2TiB, always report INT_MAX.
426 if (statvfs(RequestRoot, &spoolinfo))
427 k_supported = INT_MAX;
428 else if ((spoolsize = (double)spoolinfo.f_frsize * spoolinfo.f_blocks / 1024) >
430 k_supported = INT_MAX;
432 k_supported = (int)spoolsize;
434 #elif defined(HAVE_STATFS)
435 if (statfs(RequestRoot, &spoolinfo))
436 k_supported = INT_MAX;
437 else if ((spoolsize = (double)spoolinfo.f_bsize * spoolinfo.f_blocks / 1024) >
439 k_supported = INT_MAX;
441 k_supported = (int)spoolsize;
444 k_supported = INT_MAX;
445 #endif /* HAVE_STATVFS */
448 * This list of attributes is sorted to improve performance when the
449 * client provides a requested-attributes attribute...
452 /* charset-configured */
453 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET | IPP_TAG_COPY,
454 "charset-configured", NULL, "utf-8");
456 /* charset-supported */
457 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET | IPP_TAG_COPY,
458 "charset-supported", sizeof(charsets) / sizeof(charsets[0]),
461 /* compression-supported */
462 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
463 "compression-supported",
464 sizeof(compressions) / sizeof(compressions[0]),
467 /* copies-supported */
468 ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies);
471 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_TEXT | IPP_TAG_COPY,
472 "cups-version", NULL, CUPS_SVERSION + 6);
474 /* generated-natural-language-supported (no IPP_TAG_COPY) */
475 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
476 "generated-natural-language-supported", NULL, DefaultLanguage);
478 /* ipp-versions-supported */
479 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
480 "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]),
483 /* ippget-event-life */
484 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
485 "ippget-event-life", 15);
487 /* job-creation-attributes-supported */
488 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
489 "job-creation-attributes-supported",
490 sizeof(job_creation) / sizeof(job_creation[0]),
493 /* job-hold-until-supported */
494 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
495 "job-hold-until-supported", sizeof(holds) / sizeof(holds[0]),
498 /* job-ids-supported */
499 ippAddBoolean(CommonData, IPP_TAG_PRINTER, "job-ids-supported", 1);
501 /* job-k-octets-supported */
502 ippAddRange(CommonData, IPP_TAG_PRINTER, "job-k-octets-supported", 0,
505 /* job-priority-supported */
506 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
507 "job-priority-supported", 100);
509 /* job-settable-attributes-supported */
510 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
511 "job-settable-attributes-supported",
512 sizeof(job_settable) / sizeof(job_settable[0]),
515 /* job-sheets-supported */
516 if (cupsArrayCount(Banners) > 0)
519 * Setup the job-sheets-supported attribute...
522 if (Classification && !ClassifyOverride)
523 attr = ippAddString(CommonData, IPP_TAG_PRINTER,
524 IPP_TAG_NAME | IPP_TAG_COPY,
525 "job-sheets-supported", NULL, Classification);
527 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER,
528 IPP_TAG_NAME | IPP_TAG_COPY,
529 "job-sheets-supported", cupsArrayCount(Banners) + 1,
533 cupsdLogMessage(CUPSD_LOG_EMERG,
534 "Unable to allocate memory for "
535 "job-sheets-supported attribute: %s!", strerror(errno));
536 else if (!Classification || ClassifyOverride)
538 cupsd_banner_t *banner; /* Current banner */
541 attr->values[0].string.text = _cupsStrAlloc("none");
543 for (i = 1, banner = (cupsd_banner_t *)cupsArrayFirst(Banners);
545 i ++, banner = (cupsd_banner_t *)cupsArrayNext(Banners))
546 attr->values[i].string.text = banner->name;
550 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
551 "job-sheets-supported", NULL, "none");
553 /* jpeg-k-octets-supported */
554 ippAddRange(CommonData, IPP_TAG_PRINTER, "jpeg-k-octets-supported", 0,
557 /* jpeg-x-dimension-supported */
558 ippAddRange(CommonData, IPP_TAG_PRINTER, "jpeg-x-dimension-supported", 0,
561 /* jpeg-y-dimension-supported */
562 ippAddRange(CommonData, IPP_TAG_PRINTER, "jpeg-y-dimension-supported", 1,
565 /* media-col-supported */
566 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
567 "media-col-supported",
568 sizeof(media_col_supported) /
569 sizeof(media_col_supported[0]), NULL,
570 media_col_supported);
572 /* multiple-document-handling-supported */
573 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
574 "multiple-document-handling-supported",
575 sizeof(multiple_document_handling) /
576 sizeof(multiple_document_handling[0]), NULL,
577 multiple_document_handling);
579 /* multiple-document-jobs-supported */
580 ippAddBoolean(CommonData, IPP_TAG_PRINTER,
581 "multiple-document-jobs-supported", 1);
583 /* multiple-operation-time-out */
584 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
585 "multiple-operation-time-out", MultipleOperationTimeout);
587 /* natural-language-configured (no IPP_TAG_COPY) */
588 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
589 "natural-language-configured", NULL, DefaultLanguage);
591 /* notify-attributes-supported */
592 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
593 "notify-attributes-supported",
594 (int)(sizeof(notify_attrs) / sizeof(notify_attrs[0])),
597 /* notify-lease-duration-supported */
598 ippAddRange(CommonData, IPP_TAG_PRINTER,
599 "notify-lease-duration-supported", 0,
600 MaxLeaseDuration ? MaxLeaseDuration : 2147483647);
602 /* notify-max-events-supported */
603 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
604 "notify-max-events-supported", MaxEvents);
606 /* notify-events-supported */
607 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
608 "notify-events-supported",
609 (int)(sizeof(notify_events) / sizeof(notify_events[0])),
610 NULL, notify_events);
612 /* notify-pull-method-supported */
613 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
614 "notify-pull-method-supported", NULL, "ippget");
616 /* notify-schemes-supported */
617 snprintf(filename, sizeof(filename), "%s/notifier", ServerBin);
618 if ((dir = cupsDirOpen(filename)) != NULL)
620 notifiers = cupsArrayNew((cups_array_func_t)strcmp, NULL);
622 while ((dent = cupsDirRead(dir)) != NULL)
623 if (S_ISREG(dent->fileinfo.st_mode) &&
624 (dent->fileinfo.st_mode & S_IXOTH) != 0)
625 cupsArrayAdd(notifiers, _cupsStrAlloc(dent->filename));
627 if (cupsArrayCount(notifiers) > 0)
629 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
630 "notify-schemes-supported",
631 cupsArrayCount(notifiers), NULL, NULL);
633 for (i = 0, notifier = (char *)cupsArrayFirst(notifiers);
635 i ++, notifier = (char *)cupsArrayNext(notifiers))
636 attr->values[i].string.text = notifier;
639 cupsArrayDelete(notifiers);
643 /* number-up-supported */
644 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
645 "number-up-supported", sizeof(nups) / sizeof(nups[0]), nups);
647 /* operations-supported */
648 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
649 "operations-supported",
650 sizeof(ops) / sizeof(ops[0]) + JobFiles - 1, ops);
652 /* orientation-requested-supported */
653 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
654 "orientation-requested-supported", 4, orients);
656 /* page-ranges-supported */
657 ippAddBoolean(CommonData, IPP_TAG_PRINTER, "page-ranges-supported", 1);
659 /* pdf-k-octets-supported */
660 ippAddRange(CommonData, IPP_TAG_PRINTER, "pdf-k-octets-supported", 0,
663 /* pdf-versions-supported */
664 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
665 "pdf-versions-supported",
666 sizeof(pdf_versions) / sizeof(pdf_versions[0]), NULL,
669 /* pdl-override-supported */
670 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
671 "pdl-override-supported", NULL, "attempted");
673 /* printer-op-policy-supported */
674 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
675 "printer-op-policy-supported", cupsArrayCount(Policies),
677 for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies);
679 i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies))
680 attr->values[i].string.text = p->name;
682 /* printer-settable-attributes-supported */
683 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
684 "printer-settable-attributes-supported",
685 sizeof(printer_settable) / sizeof(printer_settable[0]),
686 NULL, printer_settable);
688 /* server-is-sharing-printers */
689 ippAddBoolean(CommonData, IPP_TAG_PRINTER, "server-is-sharing-printers",
690 BrowseLocalProtocols != 0 && Browsing);
692 /* which-jobs-supported */
693 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
694 "which-jobs-supported",
695 sizeof(which_jobs) / sizeof(which_jobs[0]), NULL, which_jobs);
700 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
704 cupsdDeleteAllPrinters(void)
706 cupsd_printer_t *p; /* Pointer to current printer/class */
709 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
711 p = (cupsd_printer_t *)cupsArrayNext(Printers))
713 p->op_policy_ptr = DefaultPolicyPtr;
714 cupsdDeletePrinter(p, 0);
719 * 'cupsdCmsRegisterPrinter()' - Registers a printer and profiles with the CMS
723 cupsdCmsRegisterPrinter(cupsd_printer_t *p)
725 #if defined(HAVE_DBUS)
726 colordRegisterPrinter(p);
727 #endif /* defined(HAVE_DBUS) */
731 * 'cupsdCmsUnregisterPrinter()' - Unregisters a printer and profiles with the CMS
735 cupsdCmsUnregisterPrinter(cupsd_printer_t *p)
737 #if defined(HAVE_DBUS)
738 colordUnregisterPrinter(p);
739 #endif /* defined(HAVE_DBUS) */
743 * 'cupsdCmsStart()' - Starts the CMS
749 #if defined(HAVE_DBUS)
751 #endif /* defined(HAVE_DBUS) */
755 * 'cupsdCmsStop()' - Stops the CMS
761 #if defined(HAVE_DBUS)
763 #endif /* defined(HAVE_DBUS) */
767 * 'cupsdDeletePrinter()' - Delete a printer from the system.
770 int /* O - 1 if classes affected, 0 otherwise */
772 cupsd_printer_t *p, /* I - Printer to delete */
773 int update) /* I - Update printers.conf? */
775 int i, /* Looping var */
776 changed = 0; /* Class changed? */
778 char filename[1024]; /* Interface script filename */
782 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdDeletePrinter(p=%p(%s), update=%d)",
786 * Save the current position in the Printers array...
789 cupsArraySave(Printers);
792 * Stop printing on this printer...
795 cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, update);
797 p->state = IPP_PRINTER_STOPPED; /* Force for browsed printers */
800 cupsdSetJobState(p->job, IPP_JOB_PENDING, CUPSD_JOB_FORCE,
801 update ? "Job stopped due to printer being deleted." :
805 * Unregister profiles...
808 cupsdCmsUnregisterPrinter(p);
811 * If this printer is the next for browsing, point to the next one...
816 cupsArrayFind(Printers, p);
817 BrowseNext = (cupsd_printer_t *)cupsArrayNext(Printers);
821 * Remove the printer from the list...
824 cupsdLogMessage(CUPSD_LOG_DEBUG2,
825 "cupsdDeletePrinter: Removing %s from Printers", p->name);
826 cupsArrayRemove(Printers, p);
828 if (p->type & CUPS_PRINTER_IMPLICIT)
830 cupsdLogMessage(CUPSD_LOG_DEBUG2,
831 "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
833 cupsArrayRemove(ImplicitPrinters, p);
837 * Remove the dummy interface/icon/option files under IRIX...
841 snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);
844 snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui",
848 snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);
851 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);
854 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);
857 snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);
862 * If p is the default printer, assign a different one...
865 if (p == DefaultPrinter)
867 DefaultPrinter = NULL;
869 if (UseNetworkDefault)
872 * Find the first network default printer and use it...
875 cupsd_printer_t *dp; /* New default printer */
878 for (dp = (cupsd_printer_t *)cupsArrayFirst(Printers);
880 dp = (cupsd_printer_t *)cupsArrayNext(Printers))
881 if (dp != p && (dp->type & CUPS_PRINTER_DEFAULT))
890 * Remove this printer from any classes...
893 if (!(p->type & CUPS_PRINTER_IMPLICIT))
895 changed = cupsdDeletePrinterFromClasses(p);
898 * Deregister from any browse protocols...
901 cupsdDeregisterPrinter(p, 1);
905 * Free all memory used by the printer...
908 if (p->printers != NULL)
911 delete_printer_filters(p);
913 for (i = 0; i < p->num_reasons; i ++)
914 _cupsStrFree(p->reasons[i]);
917 ippDelete(p->ppd_attrs);
919 mimeDeleteType(MimeDatabase, p->filetype);
920 mimeDeleteType(MimeDatabase, p->prefiltertype);
922 cupsdFreeStrings(&(p->users));
925 cupsdClearString(&p->uri);
926 cupsdClearString(&p->hostname);
927 cupsdClearString(&p->name);
928 cupsdClearString(&p->location);
929 cupsdClearString(&p->make_model);
930 cupsdClearString(&p->info);
931 cupsdClearString(&p->job_sheets[0]);
932 cupsdClearString(&p->job_sheets[1]);
933 cupsdClearString(&p->device_uri);
934 cupsdClearString(&p->sanitized_device_uri);
935 cupsdClearString(&p->port_monitor);
936 cupsdClearString(&p->op_policy);
937 cupsdClearString(&p->error_policy);
939 cupsdClearString(&p->alert);
940 cupsdClearString(&p->alert_description);
942 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
943 cupsdClearString(&p->pdl);
944 #endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
946 cupsArrayDelete(p->filetypes);
949 free(p->browse_attrs);
951 cupsFreeOptions(p->num_options, p->options);
956 * Restore the previous position in the Printers array...
959 cupsArrayRestore(Printers);
966 * 'cupsdFindDest()' - Find a destination in the list.
969 cupsd_printer_t * /* O - Destination in list */
970 cupsdFindDest(const char *name) /* I - Name of printer or class to find */
972 cupsd_printer_t key; /* Search key */
975 key.name = (char *)name;
976 return ((cupsd_printer_t *)cupsArrayFind(Printers, &key));
981 * 'cupsdFindPrinter()' - Find a printer in the list.
984 cupsd_printer_t * /* O - Printer in list */
985 cupsdFindPrinter(const char *name) /* I - Name of printer to find */
987 cupsd_printer_t *p; /* Printer in list */
990 if ((p = cupsdFindDest(name)) != NULL && (p->type & CUPS_PRINTER_CLASS))
998 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
1002 cupsdLoadAllPrinters(void)
1004 int i; /* Looping var */
1005 cups_file_t *fp; /* printers.conf file */
1006 int linenum; /* Current line number */
1007 char line[4096], /* Line from file */
1008 *value, /* Pointer to value */
1009 *valueptr; /* Pointer into value */
1010 cupsd_printer_t *p; /* Current printer */
1014 * Open the printers.conf file...
1017 snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot);
1018 if ((fp = cupsdOpenConfFile(line)) == NULL)
1022 * Read printer configurations until we hit EOF...
1028 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
1031 * Decode the directive...
1034 if (!_cups_strcasecmp(line, "<Printer") ||
1035 !_cups_strcasecmp(line, "<DefaultPrinter"))
1038 * <Printer name> or <DefaultPrinter name>
1041 if (p == NULL && value)
1044 * Add the printer and a base file type...
1047 cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading printer %s...", value);
1049 p = cupsdAddPrinter(value);
1051 p->state = IPP_PRINTER_IDLE;
1054 * Set the default printer as needed...
1057 if (!_cups_strcasecmp(line, "<DefaultPrinter"))
1061 cupsdLogMessage(CUPSD_LOG_ERROR,
1062 "Syntax error on line %d of printers.conf.", linenum);
1064 else if (!_cups_strcasecmp(line, "</Printer>"))
1069 * Close out the current printer...
1072 cupsdSetPrinterAttrs(p);
1074 if (strncmp(p->device_uri, "file:", 5) &&
1075 p->state != IPP_PRINTER_STOPPED)
1078 * See if the backend exists...
1081 snprintf(line, sizeof(line), "%s/backend/%s", ServerBin,
1084 if ((valueptr = strchr(line + strlen(ServerBin), ':')) != NULL)
1085 *valueptr = '\0'; /* Chop everything but URI scheme */
1087 if (access(line, 0))
1090 * Backend does not exist, stop printer...
1093 p->state = IPP_PRINTER_STOPPED;
1094 snprintf(p->state_message, sizeof(p->state_message),
1095 "Backend %s does not exist!", line);
1102 cupsdLogMessage(CUPSD_LOG_ERROR,
1103 "Syntax error on line %d of printers.conf.", linenum);
1107 cupsdLogMessage(CUPSD_LOG_ERROR,
1108 "Syntax error on line %d of printers.conf.", linenum);
1110 else if (!_cups_strcasecmp(line, "UUID"))
1112 if (value && !strncmp(value, "urn:uuid:", 9))
1113 cupsdSetString(&(p->uuid), value);
1115 cupsdLogMessage(CUPSD_LOG_ERROR,
1116 "Bad UUID on line %d of printers.conf.", linenum);
1118 else if (!_cups_strcasecmp(line, "AuthInfoRequired"))
1120 if (!cupsdSetAuthInfoRequired(p, value, NULL))
1121 cupsdLogMessage(CUPSD_LOG_ERROR,
1122 "Bad AuthInfoRequired on line %d of printers.conf.",
1125 else if (!_cups_strcasecmp(line, "Info"))
1128 cupsdSetString(&p->info, value);
1130 else if (!_cups_strcasecmp(line, "MakeModel"))
1133 cupsdSetString(&p->make_model, value);
1135 else if (!_cups_strcasecmp(line, "Location"))
1138 cupsdSetString(&p->location, value);
1140 else if (!_cups_strcasecmp(line, "DeviceURI"))
1143 cupsdSetDeviceURI(p, value);
1145 cupsdLogMessage(CUPSD_LOG_ERROR,
1146 "Syntax error on line %d of printers.conf.", linenum);
1148 else if (!_cups_strcasecmp(line, "Option") && value)
1154 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1157 cupsdLogMessage(CUPSD_LOG_ERROR,
1158 "Syntax error on line %d of printers.conf.", linenum);
1161 for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0');
1163 p->num_options = cupsAddOption(value, valueptr, p->num_options,
1167 else if (!_cups_strcasecmp(line, "PortMonitor"))
1169 if (value && strcmp(value, "none"))
1170 cupsdSetString(&p->port_monitor, value);
1172 cupsdClearString(&p->port_monitor);
1174 cupsdLogMessage(CUPSD_LOG_ERROR,
1175 "Syntax error on line %d of printers.conf.", linenum);
1177 else if (!_cups_strcasecmp(line, "Reason"))
1180 strcmp(value, "connecting-to-device") &&
1181 strcmp(value, "cups-insecure-filter-warning") &&
1182 strcmp(value, "cups-missing-filter-warning"))
1184 for (i = 0 ; i < p->num_reasons; i ++)
1185 if (!strcmp(value, p->reasons[i]))
1188 if (i >= p->num_reasons &&
1189 p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
1191 p->reasons[p->num_reasons] = _cupsStrAlloc(value);
1196 cupsdLogMessage(CUPSD_LOG_ERROR,
1197 "Syntax error on line %d of printers.conf.", linenum);
1199 else if (!_cups_strcasecmp(line, "State"))
1202 * Set the initial queue state...
1205 if (value && !_cups_strcasecmp(value, "idle"))
1206 p->state = IPP_PRINTER_IDLE;
1207 else if (value && !_cups_strcasecmp(value, "stopped"))
1209 p->state = IPP_PRINTER_STOPPED;
1211 for (i = 0 ; i < p->num_reasons; i ++)
1212 if (!strcmp("paused", p->reasons[i]))
1215 if (i >= p->num_reasons &&
1216 p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
1218 p->reasons[p->num_reasons] = _cupsStrAlloc("paused");
1223 cupsdLogMessage(CUPSD_LOG_ERROR,
1224 "Syntax error on line %d of printers.conf.", linenum);
1226 else if (!_cups_strcasecmp(line, "StateMessage"))
1229 * Set the initial queue state message...
1233 strlcpy(p->state_message, value, sizeof(p->state_message));
1235 else if (!_cups_strcasecmp(line, "StateTime"))
1238 * Set the state time...
1242 p->state_time = atoi(value);
1244 else if (!_cups_strcasecmp(line, "Accepting"))
1247 * Set the initial accepting state...
1251 (!_cups_strcasecmp(value, "yes") ||
1252 !_cups_strcasecmp(value, "on") ||
1253 !_cups_strcasecmp(value, "true")))
1256 (!_cups_strcasecmp(value, "no") ||
1257 !_cups_strcasecmp(value, "off") ||
1258 !_cups_strcasecmp(value, "false")))
1261 cupsdLogMessage(CUPSD_LOG_ERROR,
1262 "Syntax error on line %d of printers.conf.", linenum);
1264 else if (!_cups_strcasecmp(line, "Type"))
1267 p->type = atoi(value);
1269 cupsdLogMessage(CUPSD_LOG_ERROR,
1270 "Syntax error on line %d of printers.conf.", linenum);
1272 else if (!_cups_strcasecmp(line, "Shared"))
1275 * Set the initial shared state...
1279 (!_cups_strcasecmp(value, "yes") ||
1280 !_cups_strcasecmp(value, "on") ||
1281 !_cups_strcasecmp(value, "true")))
1284 (!_cups_strcasecmp(value, "no") ||
1285 !_cups_strcasecmp(value, "off") ||
1286 !_cups_strcasecmp(value, "false")))
1289 cupsdLogMessage(CUPSD_LOG_ERROR,
1290 "Syntax error on line %d of printers.conf.", linenum);
1292 else if (!_cups_strcasecmp(line, "JobSheets"))
1295 * Set the initial job sheets...
1300 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1305 cupsdSetString(&p->job_sheets[0], value);
1307 while (isspace(*valueptr & 255))
1312 for (value = valueptr; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1317 cupsdSetString(&p->job_sheets[1], value);
1321 cupsdLogMessage(CUPSD_LOG_ERROR,
1322 "Syntax error on line %d of printers.conf.", linenum);
1324 else if (!_cups_strcasecmp(line, "AllowUser"))
1329 cupsdAddString(&(p->users), value);
1332 cupsdLogMessage(CUPSD_LOG_ERROR,
1333 "Syntax error on line %d of printers.conf.", linenum);
1335 else if (!_cups_strcasecmp(line, "DenyUser"))
1340 cupsdAddString(&(p->users), value);
1343 cupsdLogMessage(CUPSD_LOG_ERROR,
1344 "Syntax error on line %d of printers.conf.", linenum);
1346 else if (!_cups_strcasecmp(line, "QuotaPeriod"))
1349 p->quota_period = atoi(value);
1351 cupsdLogMessage(CUPSD_LOG_ERROR,
1352 "Syntax error on line %d of printers.conf.", linenum);
1354 else if (!_cups_strcasecmp(line, "PageLimit"))
1357 p->page_limit = atoi(value);
1359 cupsdLogMessage(CUPSD_LOG_ERROR,
1360 "Syntax error on line %d of printers.conf.", linenum);
1362 else if (!_cups_strcasecmp(line, "KLimit"))
1365 p->k_limit = atoi(value);
1367 cupsdLogMessage(CUPSD_LOG_ERROR,
1368 "Syntax error on line %d of printers.conf.", linenum);
1370 else if (!_cups_strcasecmp(line, "OpPolicy"))
1374 cupsd_policy_t *pol; /* Policy */
1377 if ((pol = cupsdFindPolicy(value)) != NULL)
1379 cupsdSetString(&p->op_policy, value);
1380 p->op_policy_ptr = pol;
1383 cupsdLogMessage(CUPSD_LOG_ERROR,
1384 "Bad policy \"%s\" on line %d of printers.conf",
1388 cupsdLogMessage(CUPSD_LOG_ERROR,
1389 "Syntax error on line %d of printers.conf.", linenum);
1391 else if (!_cups_strcasecmp(line, "ErrorPolicy"))
1394 cupsdSetString(&p->error_policy, value);
1396 cupsdLogMessage(CUPSD_LOG_ERROR,
1397 "Syntax error on line %d of printers.conf.", linenum);
1399 else if (!_cups_strcasecmp(line, "Attribute") && value)
1401 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1404 cupsdLogMessage(CUPSD_LOG_ERROR,
1405 "Syntax error on line %d of printers.conf.", linenum);
1408 for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0');
1411 cupsdSetPrinterAttrs(p);
1413 if (!strcmp(value, "marker-change-time"))
1414 p->marker_time = atoi(valueptr);
1416 cupsdSetPrinterAttr(p, value, valueptr);
1419 else if (_cups_strcasecmp(line, "Filter") &&
1420 _cups_strcasecmp(line, "Prefilter") &&
1421 _cups_strcasecmp(line, "Product"))
1424 * Something else we don't understand (and that wasn't used in a prior
1425 * release of CUPS...
1428 cupsdLogMessage(CUPSD_LOG_ERROR,
1429 "Unknown configuration directive %s on line %d of "
1430 "printers.conf.", line, linenum);
1439 * 'cupsdRenamePrinter()' - Rename a printer.
1444 cupsd_printer_t *p, /* I - Printer */
1445 const char *name) /* I - New name */
1448 * Remove the printer from the array(s) first...
1451 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1452 "cupsdRenamePrinter: Removing %s from Printers", p->name);
1453 cupsArrayRemove(Printers, p);
1455 if (p->type & CUPS_PRINTER_IMPLICIT)
1457 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1458 "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
1460 cupsArrayRemove(ImplicitPrinters, p);
1464 * Rename the printer type...
1467 mimeDeleteType(MimeDatabase, p->filetype);
1468 p->filetype = mimeAddType(MimeDatabase, "printer", name);
1470 if (p->prefiltertype)
1472 mimeDeleteType(MimeDatabase, p->prefiltertype);
1473 p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", name);
1477 * Unregister profiles...
1480 cupsdCmsUnregisterPrinter(p);
1483 * Rename the printer...
1486 cupsdSetString(&p->name, name);
1489 * Reset printer attributes...
1492 cupsdSetPrinterAttrs(p);
1495 * Add the printer back to the printer array(s)...
1498 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1499 "cupsdRenamePrinter: Adding %s to Printers", p->name);
1500 cupsArrayAdd(Printers, p);
1502 if (p->type & CUPS_PRINTER_IMPLICIT)
1504 cupsdLogMessage(CUPSD_LOG_DEBUG2,
1505 "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
1507 cupsArrayAdd(ImplicitPrinters, p);
1513 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1518 cupsdSaveAllPrinters(void)
1520 int i; /* Looping var */
1521 cups_file_t *fp; /* printers.conf file */
1522 char filename[1024], /* printers.conf filename */
1523 temp[1024], /* Temporary string */
1524 value[2048], /* Value string */
1525 *ptr, /* Pointer into value */
1526 *name; /* Current user/group name */
1527 cupsd_printer_t *printer; /* Current printer class */
1528 time_t curtime; /* Current time */
1529 struct tm *curdate; /* Current date */
1530 cups_option_t *option; /* Current option */
1531 ipp_attribute_t *marker; /* Current marker attribute */
1535 * Create the printers.conf file...
1538 snprintf(filename, sizeof(filename), "%s/printers.conf", ServerRoot);
1540 if ((fp = cupsdCreateConfFile(filename, ConfigFilePerm & 0600)) == NULL)
1543 cupsdLogMessage(CUPSD_LOG_INFO, "Saving printers.conf...");
1546 * Write a small header to the file...
1549 curtime = time(NULL);
1550 curdate = localtime(&curtime);
1551 strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
1553 cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
1554 cupsFilePrintf(fp, "# Written by cupsd\n");
1555 cupsFilePuts(fp, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1558 * Write each local printer known to the system...
1561 for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
1563 printer = (cupsd_printer_t *)cupsArrayNext(Printers))
1566 * Skip remote destinations and printer classes...
1569 if ((printer->type & CUPS_PRINTER_DISCOVERED) ||
1570 (printer->type & CUPS_PRINTER_CLASS) ||
1571 (printer->type & CUPS_PRINTER_IMPLICIT))
1575 * Write printers as needed...
1578 if (printer == DefaultPrinter)
1579 cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name);
1581 cupsFilePrintf(fp, "<Printer %s>\n", printer->name);
1583 cupsFilePrintf(fp, "UUID %s\n", printer->uuid);
1585 if (printer->num_auth_info_required > 0)
1587 switch (printer->num_auth_info_required)
1590 strlcpy(value, printer->auth_info_required[0], sizeof(value));
1594 snprintf(value, sizeof(value), "%s,%s",
1595 printer->auth_info_required[0],
1596 printer->auth_info_required[1]);
1601 snprintf(value, sizeof(value), "%s,%s,%s",
1602 printer->auth_info_required[0],
1603 printer->auth_info_required[1],
1604 printer->auth_info_required[2]);
1608 cupsFilePutConf(fp, "AuthInfoRequired", value);
1612 cupsFilePutConf(fp, "Info", printer->info);
1614 if (printer->location)
1615 cupsFilePutConf(fp, "Location", printer->location);
1617 if (printer->make_model)
1618 cupsFilePutConf(fp, "MakeModel", printer->make_model);
1620 cupsFilePutConf(fp, "DeviceURI", printer->device_uri);
1622 if (printer->port_monitor)
1623 cupsFilePutConf(fp, "PortMonitor", printer->port_monitor);
1625 if (printer->state == IPP_PRINTER_STOPPED)
1627 cupsFilePuts(fp, "State Stopped\n");
1629 if (printer->state_message)
1630 cupsFilePutConf(fp, "StateMessage", printer->state_message);
1633 cupsFilePuts(fp, "State Idle\n");
1635 cupsFilePrintf(fp, "StateTime %d\n", (int)printer->state_time);
1637 for (i = 0; i < printer->num_reasons; i ++)
1638 if (strcmp(printer->reasons[i], "connecting-to-device") &&
1639 strcmp(printer->reasons[i], "cups-insecure-filter-warning") &&
1640 strcmp(printer->reasons[i], "cups-missing-filter-warning"))
1641 cupsFilePutConf(fp, "Reason", printer->reasons[i]);
1643 cupsFilePrintf(fp, "Type %d\n", printer->type);
1645 if (printer->accepting)
1646 cupsFilePuts(fp, "Accepting Yes\n");
1648 cupsFilePuts(fp, "Accepting No\n");
1650 if (printer->shared)
1651 cupsFilePuts(fp, "Shared Yes\n");
1653 cupsFilePuts(fp, "Shared No\n");
1655 snprintf(value, sizeof(value), "%s %s", printer->job_sheets[0],
1656 printer->job_sheets[1]);
1657 cupsFilePutConf(fp, "JobSheets", value);
1659 cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period);
1660 cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit);
1661 cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit);
1663 for (name = (char *)cupsArrayFirst(printer->users);
1665 name = (char *)cupsArrayNext(printer->users))
1666 cupsFilePutConf(fp, printer->deny_users ? "DenyUser" : "AllowUser", name);
1668 if (printer->op_policy)
1669 cupsFilePutConf(fp, "OpPolicy", printer->op_policy);
1670 if (printer->error_policy)
1671 cupsFilePutConf(fp, "ErrorPolicy", printer->error_policy);
1673 for (i = printer->num_options, option = printer->options;
1677 snprintf(value, sizeof(value), "%s %s", option->name, option->value);
1678 cupsFilePutConf(fp, "Option", value);
1681 if ((marker = ippFindAttribute(printer->attrs, "marker-colors",
1682 IPP_TAG_NAME)) != NULL)
1684 snprintf(value, sizeof(value), "%s ", marker->name);
1686 for (i = 0, ptr = value + strlen(value);
1687 i < marker->num_values && ptr < (value + sizeof(value) - 1);
1693 strlcpy(ptr, marker->values[i].string.text,
1694 value + sizeof(value) - ptr);
1699 cupsFilePutConf(fp, "Attribute", value);
1702 if ((marker = ippFindAttribute(printer->attrs, "marker-levels",
1703 IPP_TAG_INTEGER)) != NULL)
1705 cupsFilePrintf(fp, "Attribute %s %d", marker->name,
1706 marker->values[0].integer);
1707 for (i = 1; i < marker->num_values; i ++)
1708 cupsFilePrintf(fp, ",%d", marker->values[i].integer);
1709 cupsFilePuts(fp, "\n");
1712 if ((marker = ippFindAttribute(printer->attrs, "marker-low-levels",
1713 IPP_TAG_INTEGER)) != NULL)
1715 cupsFilePrintf(fp, "Attribute %s %d", marker->name,
1716 marker->values[0].integer);
1717 for (i = 1; i < marker->num_values; i ++)
1718 cupsFilePrintf(fp, ",%d", marker->values[i].integer);
1719 cupsFilePuts(fp, "\n");
1722 if ((marker = ippFindAttribute(printer->attrs, "marker-high-levels",
1723 IPP_TAG_INTEGER)) != NULL)
1725 cupsFilePrintf(fp, "Attribute %s %d", marker->name,
1726 marker->values[0].integer);
1727 for (i = 1; i < marker->num_values; i ++)
1728 cupsFilePrintf(fp, ",%d", marker->values[i].integer);
1729 cupsFilePuts(fp, "\n");
1732 if ((marker = ippFindAttribute(printer->attrs, "marker-message",
1733 IPP_TAG_TEXT)) != NULL)
1735 snprintf(value, sizeof(value), "%s %s", marker->name,
1736 marker->values[0].string.text);
1738 cupsFilePutConf(fp, "Attribute", value);
1741 if ((marker = ippFindAttribute(printer->attrs, "marker-names",
1742 IPP_TAG_NAME)) != NULL)
1744 snprintf(value, sizeof(value), "%s ", marker->name);
1746 for (i = 0, ptr = value + strlen(value);
1747 i < marker->num_values && ptr < (value + sizeof(value) - 1);
1753 strlcpy(ptr, marker->values[i].string.text,
1754 value + sizeof(value) - ptr);
1759 cupsFilePutConf(fp, "Attribute", value);
1762 if ((marker = ippFindAttribute(printer->attrs, "marker-types",
1763 IPP_TAG_KEYWORD)) != NULL)
1765 snprintf(value, sizeof(value), "%s ", marker->name);
1767 for (i = 0, ptr = value + strlen(value);
1768 i < marker->num_values && ptr < (value + sizeof(value) - 1);
1774 strlcpy(ptr, marker->values[i].string.text,
1775 value + sizeof(value) - ptr);
1780 cupsFilePutConf(fp, "Attribute", value);
1783 if (printer->marker_time)
1784 cupsFilePrintf(fp, "Attribute marker-change-time %ld\n",
1785 (long)printer->marker_time);
1787 cupsFilePuts(fp, "</Printer>\n");
1791 * Make IRIX desktop & printer status happy
1794 write_irix_state(printer);
1798 cupsdCloseCreatedConfFile(fp, filename);
1803 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1806 int /* O - 1 if value OK, 0 otherwise */
1807 cupsdSetAuthInfoRequired(
1808 cupsd_printer_t *p, /* I - Printer */
1809 const char *values, /* I - Plain text value (or NULL) */
1810 ipp_attribute_t *attr) /* I - IPP attribute value (or NULL) */
1812 int i; /* Looping var */
1815 p->num_auth_info_required = 0;
1818 * Do we have a plain text value?
1824 * Yes, grab the keywords...
1827 const char *end; /* End of current value */
1830 while (*values && p->num_auth_info_required < 4)
1832 if ((end = strchr(values, ',')) == NULL)
1833 end = values + strlen(values);
1835 if ((end - values) == 4 && !strncmp(values, "none", 4))
1837 if (p->num_auth_info_required != 0 || *end)
1840 p->auth_info_required[p->num_auth_info_required] = "none";
1841 p->num_auth_info_required ++;
1845 else if ((end - values) == 9 && !strncmp(values, "negotiate", 9))
1847 if (p->num_auth_info_required != 0 || *end)
1850 p->auth_info_required[p->num_auth_info_required] = "negotiate";
1851 p->num_auth_info_required ++;
1854 * Don't allow sharing of queues that require Kerberos authentication.
1859 cupsdDeregisterPrinter(p, 1);
1863 else if ((end - values) == 6 && !strncmp(values, "domain", 6))
1865 p->auth_info_required[p->num_auth_info_required] = "domain";
1866 p->num_auth_info_required ++;
1868 else if ((end - values) == 8 && !strncmp(values, "password", 8))
1870 p->auth_info_required[p->num_auth_info_required] = "password";
1871 p->num_auth_info_required ++;
1873 else if ((end - values) == 8 && !strncmp(values, "username", 8))
1875 p->auth_info_required[p->num_auth_info_required] = "username";
1876 p->num_auth_info_required ++;
1881 values = (*end) ? end + 1 : end;
1884 if (p->num_auth_info_required == 0)
1886 p->auth_info_required[0] = "none";
1887 p->num_auth_info_required = 1;
1891 * Update the printer-type value as needed...
1894 if (p->num_auth_info_required > 1 ||
1895 strcmp(p->auth_info_required[0], "none"))
1896 p->type |= CUPS_PRINTER_AUTHENTICATED;
1898 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
1904 * Grab values from an attribute instead...
1907 if (!attr || attr->num_values > 4)
1910 for (i = 0; i < attr->num_values; i ++)
1912 if (!strcmp(attr->values[i].string.text, "none"))
1914 if (p->num_auth_info_required != 0 || attr->num_values != 1)
1917 p->auth_info_required[p->num_auth_info_required] = "none";
1918 p->num_auth_info_required ++;
1922 else if (!strcmp(attr->values[i].string.text, "negotiate"))
1924 if (p->num_auth_info_required != 0 || attr->num_values != 1)
1927 p->auth_info_required[p->num_auth_info_required] = "negotiate";
1928 p->num_auth_info_required ++;
1931 * Don't allow sharing of queues that require Kerberos authentication.
1936 cupsdDeregisterPrinter(p, 1);
1942 else if (!strcmp(attr->values[i].string.text, "domain"))
1944 p->auth_info_required[p->num_auth_info_required] = "domain";
1945 p->num_auth_info_required ++;
1947 else if (!strcmp(attr->values[i].string.text, "password"))
1949 p->auth_info_required[p->num_auth_info_required] = "password";
1950 p->num_auth_info_required ++;
1952 else if (!strcmp(attr->values[i].string.text, "username"))
1954 p->auth_info_required[p->num_auth_info_required] = "username";
1955 p->num_auth_info_required ++;
1966 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1970 cupsdSetDeviceURI(cupsd_printer_t *p, /* I - Printer */
1971 const char *uri) /* I - Device URI */
1973 char buffer[1024], /* URI buffer */
1974 *start, /* Start of data after scheme */
1975 *slash, /* First slash after scheme:// */
1976 *ptr; /* Pointer into user@host:port part */
1980 * Set the full device URI..
1983 cupsdSetString(&(p->device_uri), uri);
1986 * Copy the device URI to a temporary buffer so we can sanitize any auth
1990 strlcpy(buffer, uri, sizeof(buffer));
1993 * Find the end of the scheme:// part...
1996 if ((ptr = strchr(buffer, ':')) != NULL)
1998 for (start = ptr + 1; *start; start ++)
2003 * Find the next slash (/) in the URI...
2006 if ((slash = strchr(start, '/')) == NULL)
2007 slash = start + strlen(start); /* No slash, point to the end */
2010 * Check for an @ sign before the slash...
2013 if ((ptr = strchr(start, '@')) != NULL && ptr < slash)
2016 * Found an @ sign and it is before the resource part, so we have
2017 * an authentication string. Copy the remaining URI over the
2018 * authentication string...
2021 _cups_strcpy(start, ptr + 1);
2026 * Save the sanitized URI...
2029 cupsdSetString(&(p->sanitized_device_uri), buffer);
2034 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
2038 cupsdSetPrinterAttr(
2039 cupsd_printer_t *p, /* I - Printer */
2040 const char *name, /* I - Attribute name */
2041 char *value) /* I - Attribute value string */
2043 ipp_attribute_t *attr; /* Attribute */
2044 int i, /* Looping var */
2045 count; /* Number of values */
2046 char *ptr, /* Pointer into value */
2047 *start, /* Start of value */
2048 quote; /* Quote character */
2049 ipp_tag_t value_tag; /* Value tag for this attribute */
2053 * Don't allow empty values...
2056 if (!*value && strcmp(name, "marker-message"))
2058 cupsdLogMessage(CUPSD_LOG_ERROR, "Ignoring empty \"%s\" attribute", name);
2063 * Count the number of values...
2066 for (count = 1, quote = '\0', ptr = value;
2074 else if (*ptr == '\\' && ptr[1])
2076 else if (*ptr == '\'' || *ptr == '\"')
2078 else if (*ptr == ',')
2083 * Then add or update the attribute as needed...
2086 if (!strcmp(name, "marker-levels") || !strcmp(name, "marker-low-levels") ||
2087 !strcmp(name, "marker-high-levels"))
2093 if ((attr = ippFindAttribute(p->attrs, name, IPP_TAG_INTEGER)) != NULL &&
2094 attr->num_values < count)
2096 ippDeleteAttribute(p->attrs, attr);
2101 attr->num_values = count;
2103 attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, name,
2108 cupsdLogMessage(CUPSD_LOG_ERROR,
2109 "Unable to allocate memory for printer attribute "
2110 "(%d values)", count);
2114 for (i = 0; i < count; i ++)
2116 if ((ptr = strchr(value, ',')) != NULL)
2119 attr->values[i].integer = strtol(value, NULL, 10);
2128 * Name or keyword values...
2131 if (!strcmp(name, "marker-types"))
2132 value_tag = IPP_TAG_KEYWORD;
2133 else if (!strcmp(name, "marker-message"))
2134 value_tag = IPP_TAG_TEXT;
2136 value_tag = IPP_TAG_NAME;
2138 if ((attr = ippFindAttribute(p->attrs, name, value_tag)) != NULL &&
2139 attr->num_values < count)
2141 ippDeleteAttribute(p->attrs, attr);
2147 for (i = 0; i < attr->num_values; i ++)
2148 _cupsStrFree(attr->values[i].string.text);
2150 attr->num_values = count;
2153 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, value_tag, name,
2158 cupsdLogMessage(CUPSD_LOG_ERROR,
2159 "Unable to allocate memory for printer attribute "
2160 "(%d values)", count);
2164 for (i = 0, quote = '\0', ptr = value; i < count; i ++)
2166 for (start = ptr; *ptr; ptr ++)
2169 *ptr = quote = '\0';
2172 else if (*ptr == '\\' && ptr[1])
2173 _cups_strcpy(ptr, ptr + 1);
2174 else if (*ptr == '\'' || *ptr == '\"')
2181 _cups_strcpy(ptr, ptr + 1);
2183 else if (*ptr == ',')
2190 attr->values[i].string.text = _cupsStrAlloc(start);
2197 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2201 cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
2203 int i, /* Looping var */
2204 length; /* Length of browse attributes */
2205 char resource[HTTP_MAX_URI]; /* Resource portion of URI */
2206 int num_air; /* Number of auth-info-required values */
2207 const char * const *air; /* auth-info-required values */
2208 cupsd_location_t *auth; /* Pointer to authentication element */
2209 const char *auth_supported; /* Authentication supported */
2210 ipp_t *oldattrs; /* Old printer attributes */
2211 ipp_attribute_t *attr; /* Attribute data */
2212 cups_option_t *option; /* Current printer option */
2213 char *name, /* Current user/group name */
2214 *filter; /* Current filter */
2215 static const char * const air_none[] =
2216 { /* No authentication */
2219 static const char * const air_userpass[] =
2220 { /* Basic/Digest authentication */
2226 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name,
2230 * Make sure that we have the common attributes defined...
2234 cupsdCreateCommonData();
2237 * Clear out old filters, if any...
2240 delete_printer_filters(p);
2243 * Figure out the authentication that is required for the printer.
2246 auth_supported = "requesting-user-name";
2250 if (p->num_auth_info_required > 0 && strcmp(p->auth_info_required[0], "none"))
2252 num_air = p->num_auth_info_required;
2253 air = p->auth_info_required;
2255 else if ((p->type & CUPS_PRINTER_AUTHENTICATED) &&
2256 (p->type & CUPS_PRINTER_DISCOVERED))
2262 if (p->type & CUPS_PRINTER_CLASS)
2263 snprintf(resource, sizeof(resource), "/classes/%s", p->name);
2265 snprintf(resource, sizeof(resource), "/printers/%s", p->name);
2267 if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL ||
2268 auth->type == CUPSD_AUTH_NONE)
2269 auth = cupsdFindPolicyOp(p->op_policy_ptr, IPP_PRINT_JOB);
2273 int auth_type; /* Authentication type */
2276 if ((auth_type = auth->type) == CUPSD_AUTH_DEFAULT)
2277 auth_type = DefaultAuthType;
2279 if (auth_type == CUPSD_AUTH_BASIC || auth_type == CUPSD_AUTH_BASICDIGEST)
2280 auth_supported = "basic";
2281 else if (auth_type == CUPSD_AUTH_DIGEST)
2282 auth_supported = "digest";
2284 else if (auth_type == CUPSD_AUTH_NEGOTIATE)
2285 auth_supported = "negotiate";
2286 #endif /* HAVE_GSSAPI */
2288 if (!(p->type & CUPS_PRINTER_DISCOVERED))
2290 if (auth_type != CUPSD_AUTH_NONE)
2291 p->type |= CUPS_PRINTER_AUTHENTICATED;
2293 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
2296 else if (!(p->type & CUPS_PRINTER_DISCOVERED))
2297 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
2300 * Create the required IPP attributes for a printer...
2303 oldattrs = p->attrs;
2304 p->attrs = ippNew();
2306 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2307 "uri-authentication-supported", NULL, auth_supported);
2308 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2309 "uri-security-supported", NULL, "none");
2310 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL,
2312 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location",
2313 NULL, p->location ? p->location : "");
2314 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info",
2315 NULL, p->info ? p->info : "");
2316 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-uuid", NULL,
2319 if (cupsArrayCount(p->users) > 0)
2322 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2323 "requesting-user-name-denied",
2324 cupsArrayCount(p->users), NULL, NULL);
2326 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2327 "requesting-user-name-allowed",
2328 cupsArrayCount(p->users), NULL, NULL);
2330 for (i = 0, name = (char *)cupsArrayFirst(p->users);
2332 i ++, name = (char *)cupsArrayNext(p->users))
2333 attr->values[i].string.text = _cupsStrRetain(name);
2336 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2337 "job-quota-period", p->quota_period);
2338 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2339 "job-k-limit", p->k_limit);
2340 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2341 "job-page-limit", p->page_limit);
2342 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2343 "auth-info-required", num_air, NULL, air);
2345 if (cupsArrayCount(Banners) > 0 && !(p->type & CUPS_PRINTER_DISCOVERED))
2348 * Setup the job-sheets-default attribute...
2351 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2352 "job-sheets-default", 2, NULL, NULL);
2356 attr->values[0].string.text = _cupsStrAlloc(Classification ?
2357 Classification : p->job_sheets[0]);
2358 attr->values[1].string.text = _cupsStrAlloc(Classification ?
2359 Classification : p->job_sheets[1]);
2366 if (p->type & CUPS_PRINTER_DISCOVERED)
2369 * Tell the client this is a remote printer of some type...
2372 if (strchr(p->uri, '?'))
2375 * Strip trailing "?options" from URI...
2378 char *ptr; /* Pointer into URI */
2380 strlcpy(resource, p->uri, sizeof(resource));
2381 if ((ptr = strchr(resource, '?')) != NULL)
2384 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
2385 "printer-uri-supported", NULL, resource);
2388 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
2389 "printer-uri-supported", NULL, p->uri);
2391 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info",
2395 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2396 "printer-make-and-model", NULL, p->make_model);
2398 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
2407 * Assign additional attributes depending on whether this is a printer
2411 if (p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
2414 p->type &= ~CUPS_PRINTER_OPTIONS;
2417 * Add class-specific attributes...
2420 if ((p->type & CUPS_PRINTER_IMPLICIT) && p->num_printers > 0 &&
2421 p->printers[0]->make_model)
2422 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2423 "printer-make-and-model", NULL, p->printers[0]->make_model);
2425 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
2426 "printer-make-and-model", NULL, "Local Printer Class");
2428 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
2429 "file:///dev/null");
2431 if (p->num_printers > 0)
2434 * Add a list of member names; URIs are added in copy_printer_attrs...
2437 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2438 "member-names", p->num_printers, NULL, NULL);
2439 p->type |= CUPS_PRINTER_OPTIONS;
2441 for (i = 0; i < p->num_printers; i ++)
2444 attr->values[i].string.text = _cupsStrRetain(p->printers[i]->name);
2446 p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type;
2453 * Add printer-specific attributes...
2456 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
2457 p->sanitized_device_uri);
2460 * Assign additional attributes from the PPD file (if any)...
2466 * Add filters for printer...
2469 cupsdSetPrinterReasons(p, "-cups-missing-filter-warning,"
2470 "cups-insecure-filter-warning");
2472 if (p->pc && p->pc->filters)
2474 for (filter = (char *)cupsArrayFirst(p->pc->filters);
2476 filter = (char *)cupsArrayNext(p->pc->filters))
2477 add_printer_filter(p, p->filetype, filter);
2479 else if (!(p->type & CUPS_PRINTER_REMOTE))
2481 char interface[1024]; /* Interface script */
2484 snprintf(interface, sizeof(interface), "%s/interfaces/%s", ServerRoot,
2486 if (!access(interface, X_OK))
2489 * Yes, we have a System V style interface script; use it!
2492 snprintf(interface, sizeof(interface), "*/* 0 %s/interfaces/%s",
2493 ServerRoot, p->name);
2494 add_printer_filter(p, p->filetype, interface);
2499 * Add a filter from application/vnd.cups-raw to printer/name to
2500 * handle "raw" printing by users.
2503 add_printer_filter(p, p->filetype, "application/vnd.cups-raw 0 -");
2506 * Add a PostScript filter, since this is still possibly PS printer.
2509 add_printer_filter(p, p->filetype,
2510 "application/vnd.cups-postscript 0 -");
2514 if (p->pc && p->pc->prefilters)
2516 if (!p->prefiltertype)
2517 p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", p->name);
2519 for (filter = (char *)cupsArrayFirst(p->pc->prefilters);
2521 filter = (char *)cupsArrayNext(p->pc->prefilters))
2522 add_printer_filter(p, p->prefiltertype, filter);
2528 * Copy marker attributes as needed...
2533 ipp_attribute_t *oldattr; /* Old attribute */
2536 if ((oldattr = ippFindAttribute(oldattrs, "marker-colors",
2537 IPP_TAG_NAME)) != NULL)
2539 if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2540 "marker-colors", oldattr->num_values, NULL,
2543 for (i = 0; i < oldattr->num_values; i ++)
2544 attr->values[i].string.text =
2545 _cupsStrRetain(oldattr->values[i].string.text);
2549 if ((oldattr = ippFindAttribute(oldattrs, "marker-levels",
2550 IPP_TAG_INTEGER)) != NULL)
2552 if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2553 "marker-levels", oldattr->num_values,
2556 for (i = 0; i < oldattr->num_values; i ++)
2557 attr->values[i].integer = oldattr->values[i].integer;
2561 if ((oldattr = ippFindAttribute(oldattrs, "marker-message",
2562 IPP_TAG_TEXT)) != NULL)
2563 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "marker-message",
2564 NULL, oldattr->values[0].string.text);
2566 if ((oldattr = ippFindAttribute(oldattrs, "marker-low-levels",
2567 IPP_TAG_INTEGER)) != NULL)
2569 if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2570 "marker-low-levels", oldattr->num_values,
2573 for (i = 0; i < oldattr->num_values; i ++)
2574 attr->values[i].integer = oldattr->values[i].integer;
2578 if ((oldattr = ippFindAttribute(oldattrs, "marker-high-levels",
2579 IPP_TAG_INTEGER)) != NULL)
2581 if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
2582 "marker-high-levels", oldattr->num_values,
2585 for (i = 0; i < oldattr->num_values; i ++)
2586 attr->values[i].integer = oldattr->values[i].integer;
2590 if ((oldattr = ippFindAttribute(oldattrs, "marker-names",
2591 IPP_TAG_NAME)) != NULL)
2593 if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
2594 "marker-names", oldattr->num_values, NULL,
2597 for (i = 0; i < oldattr->num_values; i ++)
2598 attr->values[i].string.text =
2599 _cupsStrRetain(oldattr->values[i].string.text);
2603 if ((oldattr = ippFindAttribute(oldattrs, "marker-types",
2604 IPP_TAG_KEYWORD)) != NULL)
2606 if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
2607 "marker-types", oldattr->num_values, NULL,
2610 for (i = 0; i < oldattr->num_values; i ++)
2611 attr->values[i].string.text =
2612 _cupsStrRetain(oldattr->values[i].string.text);
2616 ippDelete(oldattrs);
2620 * Force sharing off for remote queues...
2623 if (p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT))
2628 * Copy the printer options into a browse attributes string we can re-use.
2631 const char *valptr; /* Pointer into value */
2632 char *attrptr; /* Pointer into attribute string */
2636 * Free the old browse attributes as needed...
2639 if (p->browse_attrs)
2640 free(p->browse_attrs);
2643 * Compute the length of all attributes + job-sheets, lease-duration,
2644 * and BrowseLocalOptions.
2647 for (length = 1, i = p->num_options, option = p->options;
2651 length += strlen(option->name) + 2;
2655 for (valptr = option->value; *valptr; valptr ++)
2656 if (strchr(" \"\'\\", *valptr))
2663 length += 13 + strlen(p->job_sheets[0]) + strlen(p->job_sheets[1]);
2665 if (BrowseLocalOptions)
2666 length += 12 + strlen(BrowseLocalOptions);
2669 * Allocate the new string...
2672 if ((p->browse_attrs = calloc(1, length)) == NULL)
2673 cupsdLogMessage(CUPSD_LOG_ERROR,
2674 "Unable to allocate %d bytes for browse data!",
2679 * Got the allocated string, now copy the options and attributes over...
2682 sprintf(p->browse_attrs, "job-sheets=%s,%s lease-duration=%d",
2683 p->job_sheets[0], p->job_sheets[1], BrowseTimeout);
2684 attrptr = p->browse_attrs + strlen(p->browse_attrs);
2686 if (BrowseLocalOptions)
2688 sprintf(attrptr, " ipp-options=%s", BrowseLocalOptions);
2689 attrptr += strlen(attrptr);
2692 for (i = p->num_options, option = p->options;
2697 strcpy(attrptr, option->name);
2698 attrptr += strlen(attrptr);
2704 for (valptr = option->value; *valptr; valptr ++)
2706 if (strchr(" \"\'\\", *valptr))
2709 *attrptr++ = *valptr;
2717 * Populate the document-format-supported attribute...
2720 add_printer_formats(p);
2722 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p->name,
2726 * Add name-default attributes...
2729 add_printer_defaults(p);
2733 * Write the IRIX printer config and status files...
2736 write_irix_config(p);
2737 write_irix_state(p);
2741 * Re-register profiles...
2744 cupsdCmsUnregisterPrinter(p);
2745 cupsdCmsRegisterPrinter(p);
2748 * Let the browse protocols reflect the change
2751 cupsdRegisterPrinter(p);
2756 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2759 int /* O - 1 if something changed, 0 otherwise */
2760 cupsdSetPrinterReasons(
2761 cupsd_printer_t *p, /* I - Printer */
2762 const char *s) /* I - Reasons strings */
2764 int i, /* Looping var */
2765 changed = 0; /* Did something change? */
2766 const char *sptr; /* Pointer into reasons */
2767 char reason[255], /* Reason string */
2768 *rptr; /* Pointer into reason */
2771 cupsdLogMessage(CUPSD_LOG_DEBUG2,
2772 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p, p->name, s);
2774 if (s[0] == '-' || s[0] == '+')
2777 * Add/remove reasons...
2785 * Replace reasons...
2790 for (i = 0; i < p->num_reasons; i ++)
2791 _cupsStrFree(p->reasons[i]);
2799 if (!strcmp(s, "none"))
2803 * Loop through all of the reasons...
2809 * Skip leading whitespace and commas...
2812 while (isspace(*sptr & 255) || *sptr == ',')
2815 for (rptr = reason; *sptr && !isspace(*sptr & 255) && *sptr != ','; sptr ++)
2816 if (rptr < (reason + sizeof(reason) - 1))
2830 for (i = 0; i < p->num_reasons; i ++)
2831 if (!strcmp(reason, p->reasons[i]))
2834 * Found a match, so remove it...
2839 _cupsStrFree(p->reasons[i]);
2841 if (i < p->num_reasons)
2842 memmove(p->reasons + i, p->reasons + i + 1,
2843 (p->num_reasons - i) * sizeof(char *));
2845 if (!strcmp(reason, "paused") && p->state == IPP_PRINTER_STOPPED)
2846 cupsdSetPrinterState(p, IPP_PRINTER_IDLE, 1);
2848 if (strcmp(reason, "connecting-to-device"))
2853 else if (p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
2859 for (i = 0; i < p->num_reasons; i ++)
2860 if (!strcmp(reason, p->reasons[i]))
2863 if (i >= p->num_reasons)
2865 if (!strncmp(reason, "cups-ipp-missing-", 17) ||
2866 !strncmp(reason, "cups-ipp-wrong-", 15))
2867 log_ipp_conformance(p, reason);
2869 if (i >= (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
2871 cupsdLogMessage(CUPSD_LOG_ALERT,
2872 "Too many printer-state-reasons values for %s (%d)",
2877 p->reasons[i] = _cupsStrAlloc(reason);
2881 if (!strcmp(reason, "paused") && p->state != IPP_PRINTER_STOPPED)
2882 cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 1);
2884 if (strcmp(reason, "connecting-to-device"))
2895 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2899 cupsdSetPrinterState(
2900 cupsd_printer_t *p, /* I - Printer to change */
2901 ipp_pstate_t s, /* I - New state */
2902 int update) /* I - Update printers.conf? */
2904 ipp_pstate_t old_state; /* Old printer state */
2905 static const char * const printer_states[] =
2906 { /* State strings */
2914 * Can't set status of remote printers...
2917 if (p->type & CUPS_PRINTER_DISCOVERED)
2921 * Set the new state...
2924 old_state = p->state;
2929 cupsdAddEvent(s == IPP_PRINTER_STOPPED ? CUPSD_EVENT_PRINTER_STOPPED :
2930 CUPSD_EVENT_PRINTER_STATE, p, NULL,
2931 "%s \"%s\" state changed to %s.",
2932 (p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
2933 p->name, printer_states[p->state - IPP_PRINTER_IDLE]);
2936 * Let the browse code know this needs to be updated...
2940 p->state_time = time(NULL);
2944 write_irix_state(p);
2949 * Set/clear the paused reason as needed...
2952 if (s == IPP_PRINTER_STOPPED)
2953 cupsdSetPrinterReasons(p, "+paused");
2955 cupsdSetPrinterReasons(p, "-paused");
2958 * Clear the message for the queue when going to processing...
2961 if (s == IPP_PRINTER_PROCESSING)
2962 p->state_message[0] = '\0';
2965 * Let the browse protocols reflect the change...
2969 cupsdRegisterPrinter(p);
2972 * Save the printer configuration if a printer goes from idle or processing
2973 * to stopped (or visa-versa)...
2977 (old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED))
2983 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2987 cupsdStopPrinter(cupsd_printer_t *p, /* I - Printer to stop */
2988 int update)/* I - Update printers.conf? */
2991 * Set the printer state...
2994 cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, update);
2997 * See if we have a job printing on this printer...
3000 if (p->job && p->job->state_value == IPP_JOB_PROCESSING)
3001 cupsdSetJobState(p->job, IPP_JOB_PENDING, CUPSD_JOB_DEFAULT,
3002 "Job stopped due to printer being paused.");
3007 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
3010 int /* O - 1 if successful, 0 otherwise */
3011 cupsdUpdatePrinterPPD(
3012 cupsd_printer_t *p, /* I - Printer */
3013 int num_keywords, /* I - Number of keywords */
3014 cups_option_t *keywords) /* I - Keywords */
3016 int i; /* Looping var */
3017 cups_file_t *src, /* Original file */
3018 *dst; /* New file */
3019 char srcfile[1024], /* Original filename */
3020 dstfile[1024], /* New filename */
3021 line[1024], /* Line from file */
3022 keystring[41]; /* Keyword from line */
3023 cups_option_t *keyword; /* Current keyword */
3026 cupsdLogMessage(CUPSD_LOG_INFO, "Updating keywords in PPD file for %s...",
3030 * Get the old and new PPD filenames...
3033 snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd.O", ServerRoot, p->name);
3034 snprintf(dstfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot, p->name);
3037 * Rename the old file and open the old and new...
3040 if (rename(dstfile, srcfile))
3042 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to backup PPD file for %s: %s",
3043 p->name, strerror(errno));
3047 if ((src = cupsFileOpen(srcfile, "r")) == NULL)
3049 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open PPD file \"%s\": %s",
3050 srcfile, strerror(errno));
3051 rename(srcfile, dstfile);
3055 if ((dst = cupsFileOpen(dstfile, "w")) == NULL)
3057 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create PPD file \"%s\": %s",
3058 dstfile, strerror(errno));
3060 rename(srcfile, dstfile);
3065 * Copy the first line and then write out all of the keywords...
3068 if (!cupsFileGets(src, line, sizeof(line)))
3070 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s",
3071 srcfile, strerror(errno));
3074 rename(srcfile, dstfile);
3078 cupsFilePrintf(dst, "%s\n", line);
3080 for (i = num_keywords, keyword = keywords; i > 0; i --, keyword ++)
3082 cupsdLogMessage(CUPSD_LOG_DEBUG, "*%s: %s", keyword->name, keyword->value);
3083 cupsFilePrintf(dst, "*%s: %s\n", keyword->name, keyword->value);
3087 * Then copy the rest of the PPD file, dropping any keywords we changed.
3090 while (cupsFileGets(src, line, sizeof(line)))
3093 * Skip keywords we've already set...
3096 if (sscanf(line, "*%40[^:]:", keystring) == 1 &&
3097 cupsGetOption(keystring, num_keywords, keywords))
3101 * Otherwise write the line...
3104 cupsFilePrintf(dst, "%s\n", line);
3108 * Close files and return...
3119 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
3123 cupsdUpdatePrinters(void)
3125 cupsd_printer_t *p; /* Current printer */
3129 * Loop through the printers and recreate the printer attributes
3130 * for any local printers since the policy and/or access control
3131 * stuff may have changed. Also, if browsing is disabled, remove
3132 * any remote printers...
3135 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3137 p = (cupsd_printer_t *)cupsArrayNext(Printers))
3140 * Remove remote printers if we are no longer browsing...
3144 (p->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_DISCOVERED)))
3146 if (p->type & CUPS_PRINTER_IMPLICIT)
3147 cupsArrayRemove(ImplicitPrinters, p);
3149 cupsArraySave(Printers);
3150 cupsdDeletePrinter(p, 0);
3151 cupsArrayRestore(Printers);
3156 * Update the operation policy pointer...
3159 if ((p->op_policy_ptr = cupsdFindPolicy(p->op_policy)) == NULL)
3160 p->op_policy_ptr = DefaultPolicyPtr;
3163 * Update printer attributes as needed...
3166 if (!(p->type & CUPS_PRINTER_DISCOVERED))
3167 cupsdSetPrinterAttrs(p);
3173 * 'cupsdValidateDest()' - Validate a printer/class destination.
3176 const char * /* O - Printer or class name */
3178 const char *uri, /* I - Printer URI */
3179 cups_ptype_t *dtype, /* O - Type (printer or class) */
3180 cupsd_printer_t **printer) /* O - Printer pointer */
3182 cupsd_printer_t *p; /* Current printer */
3183 char localname[1024],/* Localized hostname */
3184 *lptr, /* Pointer into localized hostname */
3185 *sptr, /* Pointer into server name */
3186 *rptr, /* Pointer into resource */
3187 scheme[32], /* Scheme portion of URI */
3188 username[64], /* Username portion of URI */
3189 hostname[HTTP_MAX_HOST],
3190 /* Host portion of URI */
3191 resource[HTTP_MAX_URI];
3192 /* Resource portion of URI */
3193 int port; /* Port portion of URI */
3196 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri,
3200 * Initialize return values...
3207 *dtype = (cups_ptype_t)0;
3210 * Pull the hostname and resource from the URI...
3213 httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme),
3214 username, sizeof(username), hostname, sizeof(hostname),
3215 &port, resource, sizeof(resource));
3218 * See if the resource is a class or printer...
3221 if (!strncmp(resource, "/classes/", 9))
3227 rptr = resource + 9;
3229 else if (!strncmp(resource, "/printers/", 10))
3235 rptr = resource + 10;
3240 * Bad resource name...
3247 * See if the printer or class name exists...
3250 p = cupsdFindDest(rptr);
3252 if (p == NULL && strchr(rptr, '@') == NULL)
3260 *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
3261 CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED);
3267 * Change localhost to the server name...
3270 if (!_cups_strcasecmp(hostname, "localhost"))
3271 strlcpy(hostname, ServerName, sizeof(hostname));
3273 strlcpy(localname, hostname, sizeof(localname));
3275 if (!_cups_strcasecmp(hostname, ServerName))
3278 * Localize the hostname...
3281 lptr = strchr(localname, '.');
3282 sptr = strchr(ServerName, '.');
3284 if (sptr != NULL && lptr != NULL)
3287 * Strip the common domain name components...
3290 while (lptr != NULL)
3292 if (!_cups_strcasecmp(lptr, sptr))
3298 lptr = strchr(lptr + 1, '.');
3303 DEBUG_printf(("localized hostname is \"%s\"...\n", localname));
3306 * Find a matching printer or class...
3309 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3311 p = (cupsd_printer_t *)cupsArrayNext(Printers))
3312 if (!_cups_strcasecmp(p->hostname, localname) &&
3313 !_cups_strcasecmp(p->name, rptr))
3319 *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
3320 CUPS_PRINTER_REMOTE | CUPS_PRINTER_DISCOVERED);
3330 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3335 cupsdWritePrintcap(void)
3337 int i; /* Looping var */
3338 cups_file_t *fp; /* Printcap file */
3339 cupsd_printer_t *p; /* Current printer */
3344 * Update the IRIX printer state for the default printer; if
3345 * no printers remain, then the default printer file will be
3349 write_irix_state(DefaultPrinter);
3353 * See if we have a printcap file; if not, don't bother writing it.
3356 if (!Printcap || !*Printcap)
3359 cupsdLogMessage(CUPSD_LOG_INFO, "Generating printcap %s...", Printcap);
3362 * Open the printcap file...
3365 if ((fp = cupsFileOpen(Printcap, "w")) == NULL)
3369 * Put a comment header at the top so that users will know where the
3370 * data has come from...
3373 if (PrintcapFormat != PRINTCAP_PLIST)
3374 cupsFilePrintf(fp, "# This file was automatically generated by cupsd(8) "
3376 "# %s/printers.conf file. All changes to this file\n"
3377 "# will be lost.\n", ServerRoot);
3380 * Write a new printcap with the current list of printers.
3383 switch (PrintcapFormat)
3387 * Each printer is put in the file as:
3397 cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
3398 DefaultPrinter->info, ServerName,
3399 DefaultPrinter->name);
3401 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3403 p = (cupsd_printer_t *)cupsArrayNext(Printers))
3404 if (p != DefaultPrinter)
3405 cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
3406 ServerName, p->name);
3409 case PRINTCAP_PLIST :
3411 * Each printer is written as a dictionary in a plist file.
3412 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3413 * printer-location, printer-make-and-model, printer-state,
3414 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3417 cupsFilePuts(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3418 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3419 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3420 "PropertyList-1.0.dtd\">\n"
3421 "<plist version=\"1.0\">\n"
3424 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3426 p = (cupsd_printer_t *)cupsArrayNext(Printers))
3428 cupsFilePuts(fp, "\t<dict>\n"
3429 "\t\t<key>printer-name</key>\n"
3431 write_xml_string(fp, p->name);
3432 cupsFilePuts(fp, "</string>\n"
3433 "\t\t<key>printer-info</key>\n"
3435 write_xml_string(fp, p->info);
3436 cupsFilePrintf(fp, "</string>\n"
3437 "\t\t<key>printer-is-accepting-jobs</key>\n"
3439 "\t\t<key>printer-location</key>\n"
3440 "\t\t<string>", p->accepting ? "true" : "false");
3441 write_xml_string(fp, p->location);
3442 cupsFilePuts(fp, "</string>\n"
3443 "\t\t<key>printer-make-and-model</key>\n"
3445 write_xml_string(fp, p->make_model);
3446 cupsFilePrintf(fp, "</string>\n"
3447 "\t\t<key>printer-state</key>\n"
3448 "\t\t<integer>%d</integer>\n"
3449 "\t\t<key>printer-state-reasons</key>\n"
3450 "\t\t<array>\n", p->state);
3451 for (i = 0; i < p->num_reasons; i ++)
3453 cupsFilePuts(fp, "\t\t\t<string>");
3454 write_xml_string(fp, p->reasons[i]);
3455 cupsFilePuts(fp, "</string>\n");
3457 cupsFilePrintf(fp, "\t\t</array>\n"
3458 "\t\t<key>printer-type</key>\n"
3459 "\t\t<integer>%d</integer>\n"
3460 "\t\t<key>device-uri</key>\n"
3461 "\t\t<string>", p->type);
3462 write_xml_string(fp, p->sanitized_device_uri);
3463 cupsFilePuts(fp, "</string>\n"
3466 cupsFilePuts(fp, "</array>\n"
3470 case PRINTCAP_SOLARIS :
3472 * Each printer is put in the file as:
3474 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3475 * _default:use=DefaultPrinter
3477 * :bsdaddr=ServerName,Printer1:\
3478 * :description=Description:
3480 * :bsdaddr=ServerName,Printer2:\
3481 * :description=Description:
3483 * :bsdaddr=ServerName,Printer3:\
3484 * :description=Description:
3487 * :bsdaddr=ServerName,PrinterN:\
3488 * :description=Description:
3491 cupsFilePuts(fp, "_all:all=");
3492 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3494 p = (cupsd_printer_t *)cupsArrayCurrent(Printers))
3495 cupsFilePrintf(fp, "%s%c", p->name,
3496 cupsArrayNext(Printers) ? ',' : '\n');
3499 cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);
3501 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
3503 p = (cupsd_printer_t *)cupsArrayNext(Printers))
3504 cupsFilePrintf(fp, "%s:\\\n"
3505 "\t:bsdaddr=%s,%s:\\\n"
3506 "\t:description=%s:\n",
3507 p->name, ServerName, p->name,
3508 p->info ? p->info : "");
3521 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3525 add_printer_defaults(cupsd_printer_t *p)/* I - Printer */
3527 int i; /* Looping var */
3528 int num_options; /* Number of default options */
3529 cups_option_t *options, /* Default options */
3530 *option; /* Current option */
3531 char name[256]; /* name-default */
3535 * Maintain a common array of default attribute names...
3538 if (!CommonDefaults)
3540 CommonDefaults = cupsArrayNew((cups_array_func_t)strcmp, NULL);
3542 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("copies-default"));
3543 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("document-format-default"));
3544 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("finishings-default"));
3545 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-hold-until-default"));
3546 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-priority-default"));
3547 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-sheets-default"));
3548 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("media-col-default"));
3549 cupsArrayAdd(CommonDefaults, _cupsStrAlloc("number-up-default"));
3550 cupsArrayAdd(CommonDefaults,
3551 _cupsStrAlloc("orientation-requested-default"));
3555 * Add all of the default options from the .conf files...
3558 for (num_options = 0, options = NULL, i = p->num_options, option = p->options;
3562 if (strcmp(option->name, "ipp-options") &&
3563 strcmp(option->name, "job-sheets") &&
3564 strcmp(option->name, "lease-duration"))
3566 snprintf(name, sizeof(name), "%s-default", option->name);
3567 num_options = cupsAddOption(name, option->value, num_options, &options);
3569 if (!cupsArrayFind(CommonDefaults, name))
3570 cupsArrayAdd(CommonDefaults, _cupsStrAlloc(name));
3575 * Convert options to IPP attributes...
3578 cupsEncodeOptions2(p->attrs, num_options, options, IPP_TAG_PRINTER);
3579 cupsFreeOptions(num_options, options);
3582 * Add standard -default attributes as needed...
3585 if (!cupsGetOption("copies", p->num_options, p->options))
3586 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default",
3589 if (!cupsGetOption("document-format", p->num_options, p->options))
3590 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
3591 "document-format-default", NULL, "application/octet-stream");
3593 if (!cupsGetOption("job-hold-until", p->num_options, p->options))
3594 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
3595 "job-hold-until-default", NULL, "no-hold");
3597 if (!cupsGetOption("job-priority", p->num_options, p->options))
3598 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
3599 "job-priority-default", 50);
3601 if (!cupsGetOption("number-up", p->num_options, p->options))
3602 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
3603 "number-up-default", 1);
3605 if (!cupsGetOption("notify-lease-duration", p->num_options, p->options))
3606 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
3607 "notify-lease-duration-default", DefaultLeaseDuration);
3609 if (!cupsGetOption("notify-events", p->num_options, p->options))
3610 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
3611 "notify-events-default", NULL, "job-completed");
3613 if (!cupsGetOption("orientation-requested", p->num_options, p->options))
3614 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
3615 "orientation-requested-default", NULL, NULL);
3617 if (!cupsGetOption("print-quality", p->num_options, p->options))
3618 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
3619 "print-quality-default", IPP_QUALITY_NORMAL);
3624 * 'add_printer_filter()' - Add a MIME filter for a printer.
3629 cupsd_printer_t *p, /* I - Printer to add to */
3630 mime_type_t *filtertype, /* I - Filter or prefilter MIME type */
3631 const char *filter) /* I - Filter to add */
3633 char super[MIME_MAX_SUPER], /* Super-type for filter */
3634 type[MIME_MAX_TYPE], /* Type for filter */
3635 dsuper[MIME_MAX_SUPER], /* Destination super-type for filter */
3636 dtype[MIME_MAX_TYPE], /* Destination type for filter */
3637 dest[MIME_MAX_SUPER + MIME_MAX_TYPE + 2],
3638 /* Destination super/type */
3639 program[1024]; /* Program/filter name */
3640 int cost; /* Cost of filter */
3641 size_t maxsize = 0; /* Maximum supported file size */
3642 mime_type_t *temptype, /* MIME type looping var */
3643 *desttype; /* Destination MIME type */
3644 mime_filter_t *filterptr; /* MIME filter */
3645 char filename[1024]; /* Full filter filename */
3648 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3649 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3650 "filter=\"%s\")", p, p->name, filtertype, filtertype->super,
3651 filtertype->type, filter);
3654 * Parse the filter string; it should be in one of the following formats:
3656 * source/type cost program
3657 * source/type cost maxsize(nnnn) program
3658 * source/type dest/type cost program
3659 * source/type dest/type cost maxsize(nnnn) program
3662 if (sscanf(filter, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3663 super, type, dsuper, dtype, &cost, program) == 6)
3665 snprintf(dest, sizeof(dest), "%s/%s/%s", p->name, dsuper, dtype);
3667 if ((desttype = mimeType(MimeDatabase, "printer", dest)) == NULL)
3669 desttype = mimeAddType(MimeDatabase, "printer", dest);
3671 p->dest_types = cupsArrayNew(NULL, NULL);
3673 cupsArrayAdd(p->dest_types, desttype);
3679 if (sscanf(filter, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super, type, &cost,
3682 desttype = filtertype;
3686 cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!",
3692 if (!strncmp(program, "maxsize(", 8))
3694 char *ptr; /* Pointer into maxsize(nnnn) program */
3696 maxsize = strtoll(program + 8, &ptr, 10);
3700 cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!",
3706 while (_cups_isspace(*ptr))
3709 _cups_strcpy(program, ptr);
3713 * Check permissions on the filter and its containing directory...
3716 if (strcmp(program, "-"))
3718 if (program[0] == '/')
3719 strlcpy(filename, program, sizeof(filename));
3721 snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program);
3723 _cupsFileCheck(filename, _CUPS_FILE_CHECK_PROGRAM, !RunUser,
3724 cupsdLogFCMessage, p);
3728 * Add the filter to the MIME database, supporting wildcards as needed...
3731 for (temptype = mimeFirstType(MimeDatabase);
3733 temptype = mimeNextType(MimeDatabase))
3734 if (((super[0] == '*' && _cups_strcasecmp(temptype->super, "printer")) ||
3735 !_cups_strcasecmp(temptype->super, super)) &&
3736 (type[0] == '*' || !_cups_strcasecmp(temptype->type, type)))
3738 if (desttype != filtertype)
3740 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3741 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3742 "%s", p->name, temptype->super, temptype->type,
3743 desttype->super, desttype->type,
3745 filterptr = mimeAddFilter(MimeDatabase, temptype, desttype, cost,
3748 if (!mimeFilterLookup(MimeDatabase, desttype, filtertype))
3750 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3751 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3752 "0 -", p->name, desttype->super, desttype->type,
3753 filtertype->super, filtertype->type);
3754 mimeAddFilter(MimeDatabase, desttype, filtertype, 0, "-");
3759 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3760 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3761 "%s", p->name, temptype->super, temptype->type,
3762 filtertype->super, filtertype->type,
3764 filterptr = mimeAddFilter(MimeDatabase, temptype, filtertype, cost,
3769 filterptr->maxsize = maxsize;
3775 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3779 add_printer_formats(cupsd_printer_t *p) /* I - Printer */
3781 int i; /* Looping var */
3782 mime_type_t *type; /* Current MIME type */
3783 cups_array_t *filters; /* Filters */
3784 ipp_attribute_t *attr; /* document-format-supported attribute */
3785 char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2];
3786 /* MIME type name */
3790 * Raw (and remote) queues advertise all of the supported MIME
3794 cupsArrayDelete(p->filetypes);
3795 p->filetypes = NULL;
3799 ippAddStrings(p->attrs, IPP_TAG_PRINTER,
3800 (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY),
3801 "document-format-supported", NumMimeTypes, NULL, MimeTypes);
3806 * Otherwise, loop through the supported MIME types and see if there
3807 * are filters for them...
3810 cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters",
3811 mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
3813 p->filetypes = cupsArrayNew(NULL, NULL);
3815 for (type = mimeFirstType(MimeDatabase);
3817 type = mimeNextType(MimeDatabase))
3819 if (!_cups_strcasecmp(type->super, "printer"))
3822 snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
3824 if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL)
3826 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3827 "add_printer_formats: %s: %s needs %d filters",
3828 p->name, mimetype, cupsArrayCount(filters));
3830 cupsArrayDelete(filters);
3831 cupsArrayAdd(p->filetypes, type);
3834 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3835 "add_printer_formats: %s: %s not supported",
3840 * Add the file formats that can be filtered...
3843 if ((type = mimeType(MimeDatabase, "application", "octet-stream")) == NULL ||
3844 !cupsArrayFind(p->filetypes, type))
3849 cupsdLogMessage(CUPSD_LOG_DEBUG2,
3850 "add_printer_formats: %s: %d supported types",
3851 p->name, cupsArrayCount(p->filetypes) + i);
3853 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
3854 "document-format-supported",
3855 cupsArrayCount(p->filetypes) + i, NULL, NULL);
3858 attr->values[0].string.text = _cupsStrAlloc("application/octet-stream");
3860 for (type = (mime_type_t *)cupsArrayFirst(p->filetypes);
3862 i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes))
3864 snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
3866 attr->values[i].string.text = _cupsStrAlloc(mimetype);
3869 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3871 char pdl[1024]; /* Buffer to build pdl list */
3872 mime_filter_t *filter; /* MIME filter looping var */
3876 * We only support raw printing if this is not a Tioga PrintJobMgr based
3877 * queue and if application/octet-stream is a known type...
3880 for (filter = (mime_filter_t *)cupsArrayFirst(MimeDatabase->filters);
3882 filter = (mime_filter_t *)cupsArrayNext(MimeDatabase->filters))
3884 if (filter->dst == p->filetype && filter->filter &&
3885 strstr(filter->filter, "PrintJobMgr"))
3891 if (!filter && mimeType(MimeDatabase, "application", "octet-stream"))
3892 strlcat(pdl, "application/octet-stream,", sizeof(pdl));
3895 * Then list a bunch of formats that are supported by the printer...
3898 for (type = (mime_type_t *)cupsArrayFirst(p->filetypes);
3900 type = (mime_type_t *)cupsArrayNext(p->filetypes))
3902 if (!_cups_strcasecmp(type->super, "application"))
3904 if (!_cups_strcasecmp(type->type, "pdf"))
3905 strlcat(pdl, "application/pdf,", sizeof(pdl));
3906 else if (!_cups_strcasecmp(type->type, "postscript"))
3907 strlcat(pdl, "application/postscript,", sizeof(pdl));
3909 else if (!_cups_strcasecmp(type->super, "image"))
3911 if (!_cups_strcasecmp(type->type, "jpeg"))
3912 strlcat(pdl, "image/jpeg,", sizeof(pdl));
3913 else if (!_cups_strcasecmp(type->type, "png"))
3914 strlcat(pdl, "image/png,", sizeof(pdl));
3915 else if (!_cups_strcasecmp(type->type, "pwg-raster"))
3916 strlcat(pdl, "image/pwg-raster,", sizeof(pdl));
3921 pdl[strlen(pdl) - 1] = '\0'; /* Remove trailing comma */
3923 cupsdSetString(&p->pdl, pdl);
3925 #endif /* defined(HAVE_DNSSD) || defined(HAVE_AVAHI) */
3930 * 'compare_printers()' - Compare two printers.
3933 static int /* O - Result of comparison */
3934 compare_printers(void *first, /* I - First printer */
3935 void *second, /* I - Second printer */
3936 void *data) /* I - App data (not used) */
3940 return (_cups_strcasecmp(((cupsd_printer_t *)first)->name,
3941 ((cupsd_printer_t *)second)->name));
3946 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3950 delete_printer_filters(
3951 cupsd_printer_t *p) /* I - Printer to remove from */
3953 mime_filter_t *filter; /* MIME filter looping var */
3954 mime_type_t *type; /* Destination types for filters */
3958 * Range check input...
3965 * Remove all filters from the MIME database that have a destination
3966 * type == printer...
3969 for (filter = mimeFirstFilter(MimeDatabase);
3971 filter = mimeNextFilter(MimeDatabase))
3972 if (filter->dst == p->filetype || filter->dst == p->prefiltertype ||
3973 cupsArrayFind(p->dest_types, filter->dst))
3976 * Delete the current filter...
3979 mimeDeleteFilter(MimeDatabase, filter);
3982 for (type = (mime_type_t *)cupsArrayFirst(p->dest_types);
3984 type = (mime_type_t *)cupsArrayNext(p->dest_types))
3985 mimeDeleteType(MimeDatabase, type);
3987 cupsArrayDelete(p->dest_types);
3988 p->dest_types = NULL;
3990 cupsdSetPrinterReasons(p, "-cups-insecure-filter-warning"
3991 ",cups-missing-filter-warning");
3996 * 'dirty_printer()' - Mark config and state files dirty for the specified
4001 dirty_printer(cupsd_printer_t *p) /* I - Printer */
4003 if (p->type & CUPS_PRINTER_DISCOVERED)
4004 cupsdMarkDirty(CUPSD_DIRTY_REMOTE);
4005 else if (p->type & CUPS_PRINTER_CLASS)
4006 cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
4008 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
4010 if (PrintcapFormat == PRINTCAP_PLIST)
4011 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
4016 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
4020 load_ppd(cupsd_printer_t *p) /* I - Printer */
4022 int i, j, k; /* Looping vars */
4023 char cache_name[1024]; /* Cache filename */
4024 struct stat cache_info; /* Cache file info */
4025 ppd_file_t *ppd; /* PPD file */
4026 char ppd_name[1024]; /* PPD filename */
4027 struct stat ppd_info; /* PPD file info */
4028 int num_media; /* Number of media options */
4029 ppd_size_t *size; /* Current PPD size */
4030 ppd_option_t *duplex, /* Duplex option */
4031 *output_bin, /* OutputBin option */
4032 *output_mode, /* OutputMode option */
4033 *resolution; /* (Set|JCL|)Resolution option */
4034 ppd_choice_t *choice, /* Current PPD choice */
4035 *input_slot, /* Current input slot */
4036 *media_type; /* Current media type */
4037 ppd_attr_t *ppd_attr; /* PPD attribute */
4038 int xdpi, /* Horizontal resolution */
4039 ydpi; /* Vertical resolution */
4040 const char *resptr; /* Pointer into resolution keyword */
4041 _pwg_size_t *pwgsize; /* Current PWG size */
4042 _pwg_map_t *pwgsource, /* Current PWG source */
4043 *pwgtype; /* Current PWG type */
4044 ipp_attribute_t *attr; /* Attribute data */
4045 ipp_value_t *val; /* Attribute value */
4046 int num_finishings, /* Number of finishings */
4047 finishings[5]; /* finishings-supported values */
4048 int num_qualities, /* Number of print-quality values */
4049 qualities[3]; /* print-quality values */
4050 int num_margins, /* Number of media-*-margin-supported values */
4051 margins[16]; /* media-*-margin-supported values */
4052 const char *filter; /* Current filter */
4053 static const char * const sides[3] = /* sides-supported values */
4056 "two-sided-long-edge",
4057 "two-sided-short-edge"
4059 static const char * const standard_commands[] =
4060 { /* Standard CUPS commands */
4068 * Check to see if the cache is up-to-date...
4071 snprintf(cache_name, sizeof(cache_name), "%s/%s.data", CacheDir, p->name);
4072 if (stat(cache_name, &cache_info))
4073 cache_info.st_mtime = 0;
4075 snprintf(ppd_name, sizeof(ppd_name), "%s/ppd/%s.ppd", ServerRoot, p->name);
4076 if (stat(ppd_name, &ppd_info))
4077 ppd_info.st_mtime = 1;
4079 ippDelete(p->ppd_attrs);
4080 p->ppd_attrs = NULL;
4082 _ppdCacheDestroy(p->pc);
4085 if (cache_info.st_mtime >= ppd_info.st_mtime)
4087 cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", cache_name);
4089 if ((p->pc = _ppdCacheCreateWithFile(cache_name, &p->ppd_attrs)) != NULL &&
4093 * Loaded successfully!
4101 * Reload PPD attributes from disk...
4104 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
4106 cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", ppd_name);
4108 p->type &= ~CUPS_PRINTER_OPTIONS;
4109 p->type |= CUPS_PRINTER_BW;
4111 finishings[0] = IPP_FINISHINGS_NONE;
4114 p->ppd_attrs = ippNew();
4116 if ((ppd = ppdOpenFile(ppd_name)) != NULL)
4119 * Add make/model and other various attributes...
4122 p->pc = _ppdCacheCreateWithPPD(ppd);
4124 ppdMarkDefaults(ppd);
4126 if (ppd->color_device)
4127 p->type |= CUPS_PRINTER_COLOR;
4128 if (ppd->variable_sizes)
4129 p->type |= CUPS_PRINTER_VARIABLE;
4130 if (!ppd->manual_copies)
4131 p->type |= CUPS_PRINTER_COPIES;
4132 if ((ppd_attr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL)
4133 if (ppd_attr->value && !_cups_strcasecmp(ppd_attr->value, "true"))
4134 p->type |= CUPS_PRINTER_FAX;
4136 ippAddBoolean(p->ppd_attrs, IPP_TAG_PRINTER, "color-supported",
4138 if (ppd->throughput)
4140 ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4141 "pages-per-minute", ppd->throughput);
4142 if (ppd->color_device)
4143 ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4144 "pages-per-minute-color", ppd->throughput);
4149 * When there is no speed information, just say "1 page per minute".
4152 ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4153 "pages-per-minute", 1);
4154 if (ppd->color_device)
4155 ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4156 "pages-per-minute-color", 1);
4161 if ((output_mode = ppdFindOption(ppd, "OutputMode")) != NULL)
4163 if (ppdFindChoice(output_mode, "draft") ||
4164 ppdFindChoice(output_mode, "fast"))
4165 qualities[num_qualities ++] = IPP_QUALITY_DRAFT;
4167 qualities[num_qualities ++] = IPP_QUALITY_NORMAL;
4169 if (ppdFindChoice(output_mode, "best") ||
4170 ppdFindChoice(output_mode, "high"))
4171 qualities[num_qualities ++] = IPP_QUALITY_HIGH;
4173 else if ((ppd_attr = ppdFindAttr(ppd, "APPrinterPreset", NULL)) != NULL)
4177 if (strstr(ppd_attr->spec, "draft") ||
4178 strstr(ppd_attr->spec, "Draft"))
4180 qualities[num_qualities ++] = IPP_QUALITY_DRAFT;
4184 while ((ppd_attr = ppdFindNextAttr(ppd, "APPrinterPreset",
4187 qualities[num_qualities ++] = IPP_QUALITY_NORMAL;
4188 qualities[num_qualities ++] = IPP_QUALITY_HIGH;
4191 qualities[num_qualities ++] = IPP_QUALITY_NORMAL;
4193 ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
4194 "print-quality-supported", num_qualities, qualities);
4199 * The NickName can be localized in the character set specified
4200 * by the LanugageEncoding attribute. However, ppdOpen2() has
4201 * already converted the ppd->nickname member to UTF-8 for us
4202 * (the original attribute value is available separately)
4205 cupsdSetString(&p->make_model, ppd->nickname);
4207 else if (ppd->modelname)
4210 * Model name can only contain specific characters...
4213 cupsdSetString(&p->make_model, ppd->modelname);
4216 cupsdSetString(&p->make_model, "Bad PPD File");
4218 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
4219 "printer-make-and-model", NULL, p->make_model);
4222 * Add media options from the PPD file...
4225 if (ppd->num_sizes == 0 || !p->pc)
4227 if (!ppdFindAttr(ppd, "APScannerOnly", NULL))
4228 cupsdLogMessage(CUPSD_LOG_CRIT,
4229 "The PPD file for printer %s contains no media "
4230 "options and is therefore invalid!", p->name);
4232 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4233 "media-default", NULL, "unknown");
4234 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4235 "media-supported", NULL, "unknown");
4243 if ((size = ppdPageSize(ppd, NULL)) != NULL)
4244 pwgsize = _ppdCacheGetSize(p->pc, size->name);
4248 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4249 "media-default", NULL,
4250 pwgsize ? pwgsize->map.pwg : "unknown");
4258 ipp_t *col; /* Collection value */
4260 input_slot = ppdFindMarkedChoice(ppd, "InputSlot");
4261 media_type = ppdFindMarkedChoice(ppd, "MediaType");
4262 col = new_media_col(pwgsize,
4264 _ppdCacheGetSource(p->pc,
4265 input_slot->choice) :
4268 _ppdCacheGetType(p->pc,
4269 media_type->choice) :
4272 ippAddCollection(p->ppd_attrs, IPP_TAG_PRINTER, "media-col-default",
4281 num_media = p->pc->num_sizes;
4282 if (p->pc->custom_min_keyword)
4285 if ((attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4286 "media-supported", num_media, NULL,
4291 for (i = p->pc->num_sizes, pwgsize = p->pc->sizes;
4293 i --, pwgsize ++, val ++)
4294 val->string.text = _cupsStrRetain(pwgsize->map.pwg);
4296 if (p->pc->custom_min_keyword)
4298 val->string.text = _cupsStrRetain(p->pc->custom_min_keyword);
4300 val->string.text = _cupsStrRetain(p->pc->custom_max_keyword);
4305 * media-size-supported
4308 num_media = p->pc->num_sizes;
4309 if (p->pc->custom_min_keyword)
4312 if ((attr = ippAddCollections(p->ppd_attrs, IPP_TAG_PRINTER,
4313 "media-size-supported", num_media,
4318 for (i = p->pc->num_sizes, pwgsize = p->pc->sizes;
4320 i --, pwgsize ++, val ++)
4322 val->collection = ippNew();
4323 ippAddInteger(val->collection, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4324 "x-dimension", pwgsize->width);
4325 ippAddInteger(val->collection, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4326 "y-dimension", pwgsize->length);
4329 if (p->pc->custom_min_keyword)
4331 val->collection = ippNew();
4332 ippAddRange(val->collection, IPP_TAG_PRINTER, "x-dimension",
4333 p->pc->custom_min_width, p->pc->custom_max_width);
4334 ippAddRange(val->collection, IPP_TAG_PRINTER, "y-dimension",
4335 p->pc->custom_min_length, p->pc->custom_max_length);
4340 * media-source-supported
4343 if (p->pc->num_sources > 0 &&
4344 (attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4345 "media-source-supported", p->pc->num_sources,
4346 NULL, NULL)) != NULL)
4348 for (i = p->pc->num_sources, pwgsource = p->pc->sources,
4351 i --, pwgsource ++, val ++)
4352 val->string.text = _cupsStrRetain(pwgsource->pwg);
4356 * media-type-supported
4359 if (p->pc->num_types > 0 &&
4360 (attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4361 "media-type-supported", p->pc->num_types,
4362 NULL, NULL)) != NULL)
4364 for (i = p->pc->num_types, pwgtype = p->pc->types,
4367 i --, pwgtype ++, val ++)
4368 val->string.text = _cupsStrRetain(pwgtype->pwg);
4372 * media-*-margin-supported
4375 for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0;
4376 i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0]));
4379 for (j = 0; j < num_margins; j ++)
4380 if (pwgsize->bottom == margins[j])
4383 if (j >= num_margins)
4385 margins[num_margins] = pwgsize->bottom;
4390 if (num_margins > 0)
4391 ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4392 "media-bottom-margin-supported", num_margins, margins);
4394 ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4395 "media-bottom-margin-supported", 0);
4397 for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0;
4398 i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0]));
4401 for (j = 0; j < num_margins; j ++)
4402 if (pwgsize->left == margins[j])
4405 if (j >= num_margins)
4407 margins[num_margins] = pwgsize->left;
4412 if (num_margins > 0)
4413 ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4414 "media-left-margin-supported", num_margins, margins);
4416 ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4417 "media-left-margin-supported", 0);
4419 for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0;
4420 i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0]));
4423 for (j = 0; j < num_margins; j ++)
4424 if (pwgsize->right == margins[j])
4427 if (j >= num_margins)
4429 margins[num_margins] = pwgsize->right;
4434 if (num_margins > 0)
4435 ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4436 "media-right-margin-supported", num_margins, margins);
4438 ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4439 "media-right-margin-supported", 0);
4441 for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, num_margins = 0;
4442 i > 0 && num_margins < (int)(sizeof(margins) / sizeof(margins[0]));
4445 for (j = 0; j < num_margins; j ++)
4446 if (pwgsize->top == margins[j])
4449 if (j >= num_margins)
4451 margins[num_margins] = pwgsize->top;
4456 if (num_margins > 0)
4457 ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4458 "media-top-margin-supported", num_margins, margins);
4460 ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
4461 "media-top-margin-supported", 0);
4464 * media-col-database
4467 num_media = p->pc->num_sizes;
4468 if (p->pc->num_sources)
4470 if (p->pc->num_types > 0)
4471 num_media += p->pc->num_sizes * p->pc->num_sources *
4474 num_media += p->pc->num_sizes * p->pc->num_sources;
4476 else if (p->pc->num_types)
4477 num_media += p->pc->num_sizes * p->pc->num_types;
4479 if ((attr = ippAddCollections(p->ppd_attrs, IPP_TAG_PRINTER,
4480 "media-col-database", num_media,
4483 for (i = p->pc->num_sizes, pwgsize = p->pc->sizes, val = attr->values;
4488 * Start by adding the page size without source or type...
4491 ppdMarkOption(ppd, "PageSize", pwgsize->map.ppd);
4493 val->collection = new_media_col(pwgsize, NULL, NULL);
4497 * Then add the specific, supported combinations of size, source, and
4501 if (p->pc->num_sources > 0)
4503 for (j = p->pc->num_sources, pwgsource = p->pc->sources;
4507 ppdMarkOption(ppd, "InputSlot", pwgsource->ppd);
4509 if (p->pc->num_types > 0)
4511 for (k = p->pc->num_types, pwgtype = p->pc->types;
4515 if (!ppdMarkOption(ppd, "MediaType", pwgtype->ppd))
4517 val->collection = new_media_col(pwgsize, pwgsource->pwg,
4523 else if (!ppdConflicts(ppd))
4525 val->collection = new_media_col(pwgsize, pwgsource->pwg, NULL);
4530 else if (p->pc->num_types > 0)
4532 for (j = p->pc->num_types, pwgtype = p->pc->types;
4536 if (!ppdMarkOption(ppd, "MediaType", pwgtype->ppd))
4538 val->collection = new_media_col(pwgsize, NULL, pwgtype->pwg);
4546 * Update the number of media-col-database values...
4549 attr->num_values = val - attr->values;
4557 if (p->pc && p->pc->num_bins > 0)
4559 attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4560 "output-bin-supported", p->pc->num_bins,
4565 for (i = 0, val = attr->values;
4566 i < p->pc->num_bins;
4568 val->string.text = _cupsStrAlloc(p->pc->bins[i].pwg);
4571 if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL)
4573 for (i = 0; i < p->pc->num_bins; i ++)
4574 if (!strcmp(p->pc->bins[i].ppd, output_bin->defchoice))
4577 if (i >= p->pc->num_bins)
4580 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4581 "output-bin-default", NULL, p->pc->bins[i].pwg);
4584 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4585 "output-bin-default", NULL, p->pc->bins[0].pwg);
4587 else if (((ppd_attr = ppdFindAttr(ppd, "DefaultOutputOrder",
4589 !_cups_strcasecmp(ppd_attr->value, "Reverse")) ||
4590 (!ppd_attr && ppd->manufacturer && /* "Compatibility heuristic" */
4591 (!_cups_strcasecmp(ppd->manufacturer, "epson") ||
4592 !_cups_strcasecmp(ppd->manufacturer, "lexmark"))))
4595 * Report that this printer has a single output bin that leaves pages face
4599 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4600 "output-bin-supported", NULL, "face-up");
4601 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4602 "output-bin-default", NULL, "face-up");
4606 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4607 "output-bin-supported", NULL, "face-down");
4608 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4609 "output-bin-default", NULL, "face-down");
4613 * output-mode and print-color-mode...
4616 if (ppd->color_device)
4618 static const char * const output_modes[] =
4624 ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4625 "output-mode-supported", 2, NULL, output_modes);
4626 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4627 "output-mode-default", NULL, "color");
4629 ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4630 "print-color-mode-supported", 2, NULL, output_modes);
4631 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4632 "print-color-mode-default", NULL, "color");
4636 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4637 "output-mode-supported", NULL, "monochrome");
4638 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4639 "output-mode-default", NULL, "monochrome");
4641 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4642 "print-color-mode-supported", NULL, "monochrome");
4643 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4644 "print-color-mode-default", NULL, "monochrome");
4648 * Printer resolutions...
4651 if ((resolution = ppdFindOption(ppd, "Resolution")) == NULL)
4652 if ((resolution = ppdFindOption(ppd, "JCLResolution")) == NULL)
4653 if ((resolution = ppdFindOption(ppd, "SetResolution")) == NULL)
4654 resolution = ppdFindOption(ppd, "CNRes_PGP");
4659 * Report all supported resolutions...
4662 attr = ippAddResolutions(p->ppd_attrs, IPP_TAG_PRINTER,
4663 "printer-resolution-supported",
4664 resolution->num_choices, IPP_RES_PER_INCH,
4667 for (i = 0, choice = resolution->choices;
4668 i < resolution->num_choices;
4671 xdpi = ydpi = (int)strtol(choice->choice, (char **)&resptr, 10);
4672 if (resptr > choice->choice && xdpi > 0 && *resptr == 'x')
4673 ydpi = (int)strtol(resptr + 1, (char **)&resptr, 10);
4675 if (xdpi <= 0 || ydpi <= 0)
4677 cupsdLogMessage(CUPSD_LOG_WARN,
4678 "Bad resolution \"%s\" for printer %s.",
4679 choice->choice, p->name);
4683 attr->values[i].resolution.xres = xdpi;
4684 attr->values[i].resolution.yres = ydpi;
4685 attr->values[i].resolution.units = IPP_RES_PER_INCH;
4688 ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER,
4689 "printer-resolution-default", IPP_RES_PER_INCH,
4693 else if ((ppd_attr = ppdFindAttr(ppd, "DefaultResolution", NULL)) != NULL &&
4697 * Just the DefaultResolution to report...
4700 xdpi = ydpi = (int)strtol(ppd_attr->value, (char **)&resptr, 10);
4701 if (resptr > ppd_attr->value && xdpi > 0)
4704 ydpi = (int)strtol(resptr + 1, (char **)&resptr, 10);
4709 if (xdpi <= 0 || ydpi <= 0)
4711 cupsdLogMessage(CUPSD_LOG_WARN,
4712 "Bad default resolution \"%s\" for printer %s.",
4713 ppd_attr->value, p->name);
4717 ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER,
4718 "printer-resolution-default", IPP_RES_PER_INCH,
4720 ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER,
4721 "printer-resolution-supported", IPP_RES_PER_INCH,
4727 * No resolutions in PPD - make one up...
4730 ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER,
4731 "printer-resolution-default", IPP_RES_PER_INCH,
4733 ippAddResolution(p->ppd_attrs, IPP_TAG_PRINTER,
4734 "printer-resolution-supported", IPP_RES_PER_INCH,
4742 ppdMarkDefaults(ppd);
4744 if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL)
4745 if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL)
4746 if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL)
4747 if ((duplex = ppdFindOption(ppd, "KD03Duplex")) == NULL)
4748 duplex = ppdFindOption(ppd, "JCLDuplex");
4750 if (duplex && duplex->num_choices > 1 &&
4751 !ppdInstallableConflict(ppd, duplex->keyword, "DuplexTumble"))
4753 p->type |= CUPS_PRINTER_DUPLEX;
4755 ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4756 "sides-supported", 3, NULL, sides);
4758 if (!_cups_strcasecmp(duplex->defchoice, "DuplexTumble"))
4759 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4760 "sides-default", NULL, "two-sided-short-edge");
4761 else if (!_cups_strcasecmp(duplex->defchoice, "DuplexNoTumble"))
4762 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4763 "sides-default", NULL, "two-sided-long-edge");
4765 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4766 "sides-default", NULL, "one-sided");
4770 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4771 "sides-supported", NULL, "one-sided");
4772 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4773 "sides-default", NULL, "one-sided");
4776 if (ppdFindOption(ppd, "Collate") != NULL)
4777 p->type |= CUPS_PRINTER_COLLATE;
4779 if (ppdFindOption(ppd, "StapleLocation") != NULL)
4781 p->type |= CUPS_PRINTER_STAPLE;
4782 finishings[num_finishings++] = IPP_FINISHINGS_STAPLE;
4785 if (ppdFindOption(ppd, "BindEdge") != NULL)
4787 p->type |= CUPS_PRINTER_BIND;
4788 finishings[num_finishings++] = IPP_FINISHINGS_BIND;
4791 for (i = 0; i < ppd->num_sizes; i ++)
4792 if (ppd->sizes[i].length > 1728)
4793 p->type |= CUPS_PRINTER_LARGE;
4794 else if (ppd->sizes[i].length > 1008)
4795 p->type |= CUPS_PRINTER_MEDIUM;
4797 p->type |= CUPS_PRINTER_SMALL;
4799 if ((ppd_attr = ppdFindAttr(ppd, "APICADriver", NULL)) != NULL &&
4800 ppd_attr->value && !_cups_strcasecmp(ppd_attr->value, "true"))
4802 if ((ppd_attr = ppdFindAttr(ppd, "APScannerOnly", NULL)) != NULL &&
4803 ppd_attr->value && !_cups_strcasecmp(ppd_attr->value, "true"))
4804 p->type |= CUPS_PRINTER_SCANNER;
4806 p->type |= CUPS_PRINTER_MFP;
4810 * Scan the filters in the PPD file...
4815 for (filter = (const char *)cupsArrayFirst(p->pc->filters);
4817 filter = (const char *)cupsArrayNext(p->pc->filters))
4819 if (!_cups_strncasecmp(filter, "application/vnd.cups-command", 28) &&
4820 _cups_isspace(filter[28]))
4822 p->type |= CUPS_PRINTER_COMMANDS;
4828 if (p->type & CUPS_PRINTER_COMMANDS)
4830 char *commands, /* Copy of commands */
4831 *start, /* Start of name */
4832 *end; /* End of name */
4833 int count; /* Number of commands */
4835 if ((ppd_attr = ppdFindAttr(ppd, "cupsCommands", NULL)) != NULL)
4837 for (count = 0, start = ppd_attr->value; *start; count ++)
4839 while (_cups_isspace(*start))
4845 while (*start && !isspace(*start & 255))
4855 * Make a copy of the commands string and count how many commands there
4859 attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4860 "printer-commands", count, NULL, NULL);
4862 commands = strdup(ppd_attr->value);
4864 for (count = 0, start = commands; *start; count ++)
4866 while (isspace(*start & 255))
4873 while (*end && !isspace(*end & 255))
4879 attr->values[count].string.text = _cupsStrAlloc(start);
4889 * Add the standard list of commands...
4892 ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4894 (int)(sizeof(standard_commands) /
4895 sizeof(standard_commands[0])), NULL,
4902 * No commands supported...
4905 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
4906 "printer-commands", NULL, "none");
4910 * Show current and available port monitors for this printer...
4913 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor",
4914 NULL, p->port_monitor ? p->port_monitor : "none");
4916 for (i = 1, ppd_attr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
4918 i ++, ppd_attr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL));
4922 if (strstr(ppd->protocols, "TBCP"))
4924 else if (strstr(ppd->protocols, "BCP"))
4928 attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
4929 "port-monitor-supported", i, NULL, NULL);
4931 attr->values[0].string.text = _cupsStrAlloc("none");
4933 for (i = 1, ppd_attr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
4935 i ++, ppd_attr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL))
4936 attr->values[i].string.text = _cupsStrAlloc(ppd_attr->value);
4940 if (strstr(ppd->protocols, "TBCP"))
4941 attr->values[i].string.text = _cupsStrAlloc("tbcp");
4942 else if (strstr(ppd->protocols, "BCP"))
4943 attr->values[i].string.text = _cupsStrAlloc("bcp");
4946 if (ppdFindAttr(ppd, "APRemoteQueueID", NULL))
4947 p->type |= CUPS_PRINTER_REMOTE;
4949 #ifdef HAVE_APPLICATIONSERVICES_H
4951 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4952 * and save it as cacheDir/printername.png
4955 if ((ppd_attr = ppdFindAttr(ppd, "APPrinterIconPath", NULL)) != NULL &&
4957 !_cupsFileCheck(ppd_attr->value, _CUPS_FILE_CHECK_FILE, !RunUser,
4958 cupsdLogFCMessage, p))
4960 CGImageRef imageRef = NULL;/* Current icon image */
4961 CGImageRef biggestIconRef = NULL;
4962 /* Biggest icon image */
4963 CGImageRef closestTo128IconRef = NULL;
4964 /* Icon image closest to and >= 128 */
4965 CGImageSourceRef sourceRef; /* The file's image source */
4966 char outPath[HTTP_MAX_URI];
4967 /* The path to the PNG file */
4968 CFURLRef outUrl; /* The URL made from the outPath */
4969 CFURLRef icnsFileUrl; /* The URL of the original ICNS icon file */
4970 CGImageDestinationRef destRef; /* The image destination to write */
4971 size_t bytesPerRow; /* The bytes per row used for resizing */
4972 CGContextRef context; /* The CG context used for resizing */
4974 snprintf(outPath, sizeof(outPath), "%s/%s.png", CacheDir, p->name);
4975 outUrl = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
4979 icnsFileUrl = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
4980 (UInt8 *)ppd_attr->value,
4981 strlen(ppd_attr->value),
4983 if (outUrl && icnsFileUrl)
4985 sourceRef = CGImageSourceCreateWithURL(icnsFileUrl, NULL);
4988 for (i = 0; i < CGImageSourceGetCount(sourceRef); i ++)
4990 imageRef = CGImageSourceCreateImageAtIndex(sourceRef, i, NULL);
4994 if (CGImageGetWidth(imageRef) == CGImageGetHeight(imageRef))
4997 * Loop through remembering the icon closest to 128 but >= 128
4998 * and then remember the largest icon.
5001 if (CGImageGetWidth(imageRef) >= 128 &&
5002 (!closestTo128IconRef ||
5003 CGImageGetWidth(imageRef) <
5004 CGImageGetWidth(closestTo128IconRef)))
5006 CGImageRelease(closestTo128IconRef);
5007 CGImageRetain(imageRef);
5008 closestTo128IconRef = imageRef;
5011 if (!biggestIconRef ||
5012 CGImageGetWidth(imageRef) > CGImageGetWidth(biggestIconRef))
5014 CGImageRelease(biggestIconRef);
5015 CGImageRetain(imageRef);
5016 biggestIconRef = imageRef;
5020 CGImageRelease(imageRef);
5026 * If biggestIconRef is NULL, we found no icons. Otherwise we first
5027 * want the closest to 128, but if none are larger than 128, we want
5028 * the largest icon available.
5031 imageRef = closestTo128IconRef ? closestTo128IconRef :
5033 CGImageRetain(imageRef);
5034 CGImageRelease(biggestIconRef);
5035 if (closestTo128IconRef)
5036 CGImageRelease(closestTo128IconRef);
5037 destRef = CGImageDestinationCreateWithURL(outUrl, kUTTypePNG, 1,
5041 if (CGImageGetWidth(imageRef) != 128)
5043 bytesPerRow = CGImageGetBytesPerRow(imageRef) /
5044 CGImageGetWidth(imageRef) * 128;
5045 context = CGBitmapContextCreate(NULL, 128, 128,
5046 CGImageGetBitsPerComponent(imageRef),
5048 CGImageGetColorSpace(imageRef),
5049 kCGImageAlphaPremultipliedFirst);
5052 CGContextDrawImage(context, CGRectMake(0, 0, 128, 128),
5054 CGImageRelease(imageRef);
5055 imageRef = CGBitmapContextCreateImage(context);
5056 CGContextRelease(context);
5060 CGImageDestinationAddImage(destRef, imageRef, NULL);
5061 CGImageDestinationFinalize(destRef);
5065 CGImageRelease(imageRef);
5068 CFRelease(sourceRef);
5076 CFRelease(icnsFileUrl);
5078 #endif /* HAVE_APPLICATIONSERVICES_H */
5081 * Close the PPD and set the type...
5086 else if (!access(ppd_name, 0))
5088 int pline; /* PPD line number */
5089 ppd_status_t pstatus; /* PPD load status */
5092 pstatus = ppdLastError(&pline);
5094 cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!",
5097 if (pstatus <= PPD_ALLOC_ERROR)
5098 cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno));
5100 cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.",
5101 ppdErrorString(pstatus), pline);
5103 cupsdLogMessage(CUPSD_LOG_INFO,
5104 "Hint: Run \"cupstestppd %s\" and fix any errors.",
5110 * If we have an interface script, add a filter entry for it...
5113 char interface[1024]; /* Interface script */
5116 snprintf(interface, sizeof(interface), "%s/interfaces/%s", ServerRoot,
5118 if (!access(interface, X_OK))
5121 * Yes, we have a System V style interface script; use it!
5124 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
5125 "printer-make-and-model", NULL,
5126 "Local System V Printer");
5128 else if (!strncmp(p->device_uri, "ipp://", 6) &&
5129 (strstr(p->device_uri, "/printers/") != NULL ||
5130 strstr(p->device_uri, "/classes/") != NULL ||
5131 (strstr(p->device_uri, "._ipp.") != NULL &&
5132 !strcmp(p->device_uri + strlen(p->device_uri) - 5,
5136 * Tell the client this is really a hard-wired remote printer.
5139 p->type |= CUPS_PRINTER_REMOTE;
5142 * Point the printer-uri-supported attribute to the
5146 if (strchr(p->device_uri, '?'))
5149 * Strip trailing "?options" from URI...
5152 char resource[HTTP_MAX_URI], /* New URI */
5153 *ptr; /* Pointer into URI */
5155 strlcpy(resource, p->device_uri, sizeof(resource));
5156 if ((ptr = strchr(resource, '?')) != NULL)
5159 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
5160 "printer-uri-supported", NULL, resource);
5163 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
5164 "printer-uri-supported", NULL, p->device_uri);
5167 * Then set the make-and-model accordingly...
5170 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
5171 "printer-make-and-model", NULL, "Remote Printer");
5174 * Print all files directly...
5183 * Otherwise we have neither - treat this as a "dumb" printer
5184 * with no PPD file...
5187 ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
5188 "printer-make-and-model", NULL, "Local Raw Printer");
5194 ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
5195 "finishings-supported", num_finishings, finishings);
5196 ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
5197 "finishings-default", IPP_FINISHINGS_NONE);
5202 * Save cached PPD attributes to disk...
5205 cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Saving %s...", cache_name);
5207 _ppdCacheWriteFile(p->pc, cache_name, p->ppd_attrs);
5212 * Remove cache files...
5215 if (cache_info.st_mtime)
5222 * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer.
5226 log_ipp_conformance(
5227 cupsd_printer_t *p, /* I - Printer */
5228 const char *reason) /* I - Printer state reason */
5230 const char *message; /* Message to log */
5232 aslmsg aslm; /* Apple System Log message */
5233 #endif /* __APPLE__ */
5237 * Strip the leading "cups-ipp-" from the reason and create a log message for
5242 if (!strcmp(reason, "missing-cancel-job"))
5243 message = "Printer does not support REQUIRED Cancel-Job operation.";
5244 else if (!strcmp(reason, "missing-get-job-attributes"))
5245 message = "Printer does not support REQUIRED Get-Job-Attributes operation.";
5246 else if (!strcmp(reason, "missing-print-job"))
5247 message = "Printer does not support REQUIRED Print-Job operation.";
5248 else if (!strcmp(reason, "missing-validate-job"))
5249 message = "Printer does not support REQUIRED Validate-Job operation.";
5250 else if (!strcmp(reason, "missing-get-printer-attributes"))
5251 message = "Printer does not support REQUIRED Get-Printer-Attributes operation.";
5252 else if (!strcmp(reason, "missing-send-document"))
5253 message = "Printer supports Create-Job but not Send-Document operation.";
5254 else if (!strcmp(reason, "missing-job-history"))
5255 message = "Printer does not provide REQUIRED job history.";
5256 else if (!strcmp(reason, "missing-job-id"))
5257 message = "Printer does not provide REQUIRED job-id attribute.";
5258 else if (!strcmp(reason, "missing-job-state"))
5259 message = "Printer does not provide REQUIRED job-state attribute.";
5260 else if (!strcmp(reason, "missing-operations-supported"))
5261 message = "Printer does not provide REQUIRED operations-supported "
5263 else if (!strcmp(reason, "missing-printer-is-accepting-jobs"))
5264 message = "Printer does not provide REQUIRED printer-is-accepting-jobs "
5266 else if (!strcmp(reason, "missing-printer-state-reasons"))
5267 message = "Printer does not provide REQUIRED printer-state-reasons "
5269 else if (!strcmp(reason, "wrong-http-version"))
5270 message = "Printer does not use REQUIRED HTTP/1.1 transport.";
5272 message = "Unknown IPP conformance failure.";
5274 cupsdLogMessage(CUPSD_LOG_WARN, "%s: %s", p->name, message);
5278 * Report the failure information to Apple if the user opts into providing
5279 * feedback to Apple...
5282 aslm = asl_new(ASL_TYPE_MSG);
5285 asl_set(aslm, "com.apple.message.domain", "com.apple.printing.ipp.conformance");
5286 asl_set(aslm, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance");
5287 asl_set(aslm, "com.apple.message.signature", reason);
5288 asl_set(aslm, "com.apple.message.signature2",
5289 p->make_model ? p->make_model : "Unknown");
5290 asl_log(NULL, aslm, ASL_LEVEL_NOTICE, "%s: %s",
5291 p->make_model ? p->make_model : "Unknown", message);
5294 #endif /* __APPLE__ */
5299 * 'new_media_col()' - Create a media-col collection value.
5302 static ipp_t * /* O - Collection value */
5303 new_media_col(_pwg_size_t *size, /* I - media-size/margin values */
5304 const char *source, /* I - media-source value */
5305 const char *type) /* I - media-type value */
5307 ipp_t *media_col, /* Collection value */
5308 *media_size; /* media-size value */
5311 media_col = ippNew();
5313 media_size = ippNew();
5314 ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
5315 "x-dimension", size->width);
5316 ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
5317 "y-dimension", size->length);
5318 ippAddCollection(media_col, IPP_TAG_PRINTER, "media-size", media_size);
5319 ippDelete(media_size);
5321 ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
5322 "media-bottom-margin", size->bottom);
5323 ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
5324 "media-left-margin", size->left);
5325 ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
5326 "media-right-margin", size->right);
5327 ippAddInteger(media_col, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
5328 "media-top-margin", size->top);
5331 ippAddString(media_col, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-source",
5335 ippAddString(media_col, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-type",
5344 * 'write_irix_config()' - Update the config files used by the IRIX
5349 write_irix_config(cupsd_printer_t *p) /* I - Printer to update */
5351 char filename[1024]; /* Interface script filename */
5352 cups_file_t *fp; /* Interface script file */
5353 ipp_attribute_t *attr; /* Attribute data */
5357 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
5358 * tools. First the interface script that tells the tools what kind of
5359 * printer we have...
5362 snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);
5364 if (p->type & CUPS_PRINTER_CLASS)
5366 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
5368 cupsFilePuts(fp, "#!/bin/sh\n");
5370 if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model",
5371 IPP_TAG_TEXT)) != NULL)
5372 cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);
5373 else if (p->type & CUPS_PRINTER_CLASS)
5374 cupsFilePuts(fp, "NAME=\"Printer Class\"\n");
5376 cupsFilePuts(fp, "NAME=\"Remote Destination\"\n");
5378 if (p->type & CUPS_PRINTER_COLOR)
5379 cupsFilePuts(fp, "TYPE=ColorPostScript\n");
5381 cupsFilePuts(fp, "TYPE=MonoPostScript\n");
5383 cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName);
5384 cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name);
5388 chmod(filename, 0755);
5389 chown(filename, User, Group);
5393 * Then the member file that tells which device file the queue is connected
5394 * to... Networked printers use "/dev/null" in this file, so that's what
5395 * we use (the actual device URI can confuse some apps...)
5398 snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);
5400 if (p->type & CUPS_PRINTER_CLASS)
5402 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
5404 cupsFilePuts(fp, "/dev/null\n");
5408 chmod(filename, 0644);
5409 chown(filename, User, Group);
5413 * The gui_interface file is a script or program that launches a GUI
5414 * option panel for the printer, using options specified on the
5415 * command-line in the third argument. The option panel must send
5416 * any printing options to stdout on a single line when the user
5417 * accepts them, or nothing if the user cancels the dialog.
5419 * The default options panel program is /usr/bin/glpoptions, from
5420 * the ESP Print Pro software. You can select another using the
5421 * PrintcapGUI option.
5424 snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", p->name);
5426 if (p->type & CUPS_PRINTER_CLASS)
5428 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
5430 cupsFilePuts(fp, "#!/bin/sh\n");
5431 cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
5435 chmod(filename, 0755);
5436 chown(filename, User, Group);
5440 * The POD config file is needed by the printstatus command to show
5441 * the printer location and device.
5444 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);
5446 if (p->type & CUPS_PRINTER_CLASS)
5448 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
5450 cupsFilePrintf(fp, "Printer Class | %s\n",
5451 (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript");
5452 cupsFilePrintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : "");
5453 cupsFilePrintf(fp, "Location Code | %s\n", p->location ? p->location : "");
5454 cupsFilePrintf(fp, "Physical Location | %s\n", p->info ? p->info : "");
5455 cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri);
5456 cupsFilePrintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name);
5457 cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
5458 cupsFilePuts(fp, "Status Update Wait | 10 seconds\n");
5462 chmod(filename, 0664);
5463 chown(filename, User, Group);
5469 * 'write_irix_state()' - Update the status files used by IRIX printing
5474 write_irix_state(cupsd_printer_t *p) /* I - Printer to update */
5476 char filename[1024]; /* Interface script filename */
5477 cups_file_t *fp; /* Interface script file */
5478 int tag; /* Status tag value */
5484 * The POD status file is needed for the printstatus window to
5485 * provide the current status of the printer.
5488 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);
5490 if (p->type & CUPS_PRINTER_CLASS)
5492 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
5494 cupsFilePrintf(fp, "Operational Status | %s\n",
5495 (p->state == IPP_PRINTER_IDLE) ? "Idle" :
5496 (p->state == IPP_PRINTER_PROCESSING) ? "Busy" :
5498 cupsFilePrintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION);
5499 cupsFilePrintf(fp, "Information | 02 00 00 | Device URI: %s\n",
5501 cupsFilePrintf(fp, "Information | 03 00 00 | %s jobs\n",
5502 p->accepting ? "Accepting" : "Not accepting");
5503 cupsFilePrintf(fp, "Information | 04 00 00 | %s\n", p->state_message);
5507 chmod(filename, 0664);
5508 chown(filename, User, Group);
5512 * The activeicons file is needed to provide desktop icons for printers:
5514 * [ quoted from /usr/lib/print/tagit ]
5516 * --- Type of printer tags (base values)
5518 * Dumb=66048 # 0x10200
5519 * DumbColor=66080 # 0x10220
5520 * Raster=66112 # 0x10240
5521 * ColorRaster=66144 # 0x10260
5522 * Plotter=66176 # 0x10280
5523 * PostScript=66208 # 0x102A0
5524 * ColorPostScript=66240 # 0x102C0
5525 * MonoPostScript=66272 # 0x102E0
5527 * --- Printer state modifiers for local printers
5532 * Unknown=3 # 0x3 (Faulted due to unknown reason)
5534 * --- Printer state modifiers for network printers
5538 * NetFaulted=10 # 0xA
5539 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
5542 snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);
5544 if (p->type & CUPS_PRINTER_CLASS)
5546 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
5548 if (p->type & CUPS_PRINTER_COLOR)
5553 if (p->type & CUPS_PRINTER_REMOTE)
5556 if (p->state == IPP_PRINTER_PROCESSING)
5559 else if (p->state == IPP_PRINTER_STOPPED)
5562 cupsFilePuts(fp, "#!/bin/sh\n");
5563 cupsFilePrintf(fp, "#Tag %d\n", tag);
5567 chmod(filename, 0755);
5568 chown(filename, User, Group);
5573 * The default file is needed by the printers window to show
5574 * the default printer.
5577 snprintf(filename, sizeof(filename), "/var/spool/lp/default");
5579 if (DefaultPrinter != NULL)
5581 if ((fp = cupsFileOpen(filename, "w")) != NULL)
5583 cupsFilePrintf(fp, "%s\n", DefaultPrinter->name);
5587 chmod(filename, 0644);
5588 chown(filename, User, Group);
5598 * 'write_xml_string()' - Write a string with XML escaping.
5602 write_xml_string(cups_file_t *fp, /* I - File to write to */
5603 const char *s) /* I - String to write */
5605 const char *start; /* Start of current sequence */
5611 for (start = s; *s; s ++)
5616 cupsFileWrite(fp, start, s - start);
5618 cupsFilePuts(fp, "&");
5624 cupsFileWrite(fp, start, s - start);
5626 cupsFilePuts(fp, "<");
5632 cupsFilePuts(fp, start);
5637 * End of "$Id: printers.c 10295 2012-02-15 23:21:06Z mike $".