1 /* 2 * Printer definitions for the CUPS scheduler. 3 * 4 * Copyright © 2020-2024 by OpenPrinting. 5 * Copyright @ 2007-2017 by Apple Inc. 6 * Copyright @ 1997-2007 by Easy Software Products, all rights reserved. 7 * 8 * Licensed under Apache License v2.0. See the file "LICENSE" for more information. 9 */ 10 11 #ifdef HAVE_MDNSRESPONDER 12 # include <dns_sd.h> 13 #elif defined(HAVE_AVAHI) 14 # include <avahi-client/client.h> 15 # include <avahi-client/publish.h> 16 # include <avahi-common/error.h> 17 # include <avahi-common/thread-watch.h> 18 #endif /* HAVE_MDNSRESPONDER */ 19 #include <cups/pwg-private.h> 20 21 22 /* 23 * Quota data... 24 */ 25 26 typedef struct 27 { 28 char username[33]; /* User data */ 29 time_t next_update; /* Next update time */ 30 int page_count, /* Count of pages */ 31 k_count; /* Count of kilobytes */ 32 } cupsd_quota_t; 33 34 35 /* 36 * DNS-SD types to make the code cleaner/clearer... 37 */ 38 39 #ifdef HAVE_MDNSRESPONDER 40 typedef DNSServiceRef cupsd_srv_t; /* Service reference */ 41 typedef TXTRecordRef cupsd_txt_t; /* TXT record */ 42 43 #elif defined(HAVE_AVAHI) 44 typedef AvahiEntryGroup *cupsd_srv_t; /* Service reference */ 45 typedef AvahiStringList *cupsd_txt_t; /* TXT record */ 46 #endif /* HAVE_MDNSRESPONDER */ 47 48 49 /* 50 * Printer/class information structure... 51 */ 52 53 struct cupsd_printer_s 54 { 55 _cups_rwlock_t lock; /* Concurrency lock for background updates */ 56 int printer_id; /* Printer ID */ 57 char *uri, /* Printer URI */ 58 *uuid, /* Printer UUID */ 59 *hostname, /* Host printer resides on */ 60 *name, /* Printer name */ 61 *location, /* Location string */ 62 *geo_location, /* Geographic location URI */ 63 *make_model, /* Make and model */ 64 *info, /* Description */ 65 *organization, /* Organization name */ 66 *organizational_unit, /* Organizational unit (department, etc.) */ 67 *strings, /* Strings file, if any */ 68 *op_policy, /* Operation policy name */ 69 *error_policy; /* Error policy */ 70 cupsd_policy_t *op_policy_ptr; /* Pointer to operation policy */ 71 int shared; /* Shared? */ 72 int temporary; /* Temporary queue? */ 73 int accepting; /* Accepting jobs? */ 74 int holding_new_jobs; /* Holding new jobs for printing? */ 75 int in_implicit_class; /* In an implicit class? */ 76 ipp_pstate_t state; /* Printer state */ 77 char state_message[1024]; /* Printer state message */ 78 int num_reasons; /* Number of printer-state-reasons */ 79 char *reasons[64]; /* printer-state-reasons strings */ 80 time_t config_time, /* Time at this configuration */ 81 state_time; /* Time at this state */ 82 char *job_sheets[2]; /* Banners/job sheets */ 83 cups_ptype_t type; /* Printer type (color, small, etc.) */ 84 char *device_uri; /* Device URI */ 85 char *sanitized_device_uri; /* Sanitized device URI */ 86 char *port_monitor; /* Port monitor */ 87 int raw; /* Raw queue? */ 88 int remote; /* Remote queue? */ 89 mime_type_t *filetype, /* Pseudo-filetype for printer */ 90 *prefiltertype; /* Pseudo-filetype for pre-filters */ 91 cups_array_t *filetypes, /* Supported file types */ 92 *dest_types; /* Destination types for queue */ 93 cupsd_job_t *job; /* Current job in queue */ 94 ipp_t *attrs, /* Attributes supported by this printer */ 95 *ppd_attrs; /* Attributes based on the PPD */ 96 int num_printers, /* Number of printers in class */ 97 last_printer; /* Last printer job was sent to */ 98 struct cupsd_printer_s **printers; /* Printers in class */ 99 int quota_period, /* Period for quotas */ 100 page_limit, /* Maximum number of pages */ 101 k_limit; /* Maximum number of kilobytes */ 102 cups_array_t *quotas; /* Quota records */ 103 int deny_users; /* 1 = deny, 0 = allow */ 104 cups_array_t *users; /* Allowed/denied users */ 105 int sequence_number; /* Increasing sequence number */ 106 int num_options; /* Number of default options */ 107 cups_option_t *options; /* Default options */ 108 int num_auth_info_required; /* Number of required auth fields */ 109 const char *auth_info_required[4]; /* Required authentication fields */ 110 char *alert, /* PSX printer-alert value */ 111 *alert_description; /* PSX printer-alert-description value */ 112 time_t marker_time; /* Last time marker attributes were updated */ 113 _ppd_cache_t *pc; /* PPD cache and mapping data */ 114 115 #ifdef HAVE_DNSSD 116 char *reg_name, /* Name used for service registration */ 117 *pdl; /* pdl value for TXT record */ 118 cupsd_srv_t ipp_srv; /* IPP service(s) */ 119 # ifdef HAVE_MDNSRESPONDER 120 # ifdef HAVE_TLS 121 cupsd_srv_t ipps_srv; /* IPPS service(s) */ 122 # endif /* HAVE_TLS */ 123 cupsd_srv_t printer_srv; /* LPD service */ 124 # endif /* HAVE_MDNSRESPONDER */ 125 #endif /* HAVE_DNSSD */ 126 }; 127 128 129 /* 130 * Globals... 131 */ 132 133 VAR ipp_t *CommonData VALUE(NULL); 134 /* Common printer object attrs */ 135 VAR cups_array_t *CommonDefaults VALUE(NULL); 136 /* Common -default option names */ 137 VAR int NextPrinterId VALUE(1); 138 /* Next printer-id value */ 139 VAR cups_array_t *Printers VALUE(NULL); 140 /* Printer list */ 141 VAR cupsd_printer_t *DefaultPrinter VALUE(NULL); 142 /* Default printer */ 143 VAR char *DefaultPolicy VALUE(NULL); 144 /* Default policy name */ 145 VAR cupsd_policy_t *DefaultPolicyPtr 146 VALUE(NULL); 147 /* Pointer to default policy */ 148 149 150 /* 151 * Prototypes... 152 */ 153 154 extern cupsd_printer_t *cupsdAddPrinter(const char *name); 155 extern void cupsdCreateCommonData(void); 156 extern void cupsdDeleteAllPrinters(void); 157 extern int cupsdDeletePrinter(cupsd_printer_t *p, int update); 158 extern void cupsdDeleteTemporaryPrinters(int force); 159 extern cupsd_printer_t *cupsdFindDest(const char *name); 160 extern cupsd_printer_t *cupsdFindPrinter(const char *name); 161 extern cupsd_quota_t *cupsdFindQuota(cupsd_printer_t *p, 162 const char *username); 163 extern void cupsdFreeQuotas(cupsd_printer_t *p); 164 extern void cupsdLoadAllPrinters(void); 165 extern void cupsdRenamePrinter(cupsd_printer_t *p, 166 const char *name); 167 extern void cupsdSaveAllPrinters(void); 168 extern int cupsdSetAuthInfoRequired(cupsd_printer_t *p, 169 const char *values, 170 ipp_attribute_t *attr); 171 extern void cupsdSetDeviceURI(cupsd_printer_t *p, const char *uri); 172 extern void cupsdSetPrinterAttr(cupsd_printer_t *p, 173 const char *name, 174 const char *value); 175 extern void cupsdSetPrinterAttrs(cupsd_printer_t *p); 176 extern int cupsdSetPrinterReasons(cupsd_printer_t *p, 177 const char *s); 178 extern void cupsdSetPrinterState(cupsd_printer_t *p, ipp_pstate_t s, 179 int update); 180 #define cupsdStartPrinter(p,u) cupsdSetPrinterState((p), \ 181 IPP_PRINTER_IDLE, (u)) 182 extern void cupsdStopPrinter(cupsd_printer_t *p, int update); 183 extern int cupsdUpdatePrinterPPD(cupsd_printer_t *p, 184 int num_keywords, 185 cups_option_t *keywords); 186 extern void cupsdUpdatePrinters(void); 187 extern cupsd_quota_t *cupsdUpdateQuota(cupsd_printer_t *p, 188 const char *username, int pages, 189 int k); 190 extern const char *cupsdValidateDest(const char *uri, 191 cups_ptype_t *dtype, 192 cupsd_printer_t **printer); 193 extern void cupsdWritePrintcap(void); 194