• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Private definitions for CUPS.
3  *
4  * Copyright © 2020-2025 by OpenPrinting.
5  * Copyright © 2007-2019 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
9  * information.
10  */
11 
12 #ifndef _CUPS_CUPS_PRIVATE_H_
13 #  define _CUPS_CUPS_PRIVATE_H_
14 
15 /*
16  * Include necessary headers...
17  */
18 
19 #  include "string-private.h"
20 #  include "array-private.h"
21 #  include "ipp-private.h"
22 #  include "http-private.h"
23 #  include "language-private.h"
24 #  include "pwg-private.h"
25 #  include "thread-private.h"
26 #  include <cups/cups.h>
27 #  ifdef __APPLE__
28 #    include <sys/cdefs.h>
29 #    include <CoreFoundation/CoreFoundation.h>
30 #  endif /* __APPLE__ */
31 
32 
33 /*
34  * C++ magic...
35  */
36 
37 #  ifdef __cplusplus
38 extern "C" {
39 #  endif /* __cplusplus */
40 
41 
42 /*
43  * Types...
44  */
45 
46 typedef struct _cups_buffer_s		/**** Read/write buffer ****/
47 {
48   struct _cups_buffer_s	*next;		/* Next buffer in list */
49   size_t		size;		/* Size of buffer */
50   char			used,		/* Is this buffer used? */
51 			d[1];		/* Data buffer */
52 } _cups_buffer_t;
53 
54 typedef struct _cups_raster_error_s	/**** Error buffer structure ****/
55 {
56   char	*start,				/* Start of buffer */
57 	*current,			/* Current position in buffer */
58 	*end;				/* End of buffer */
59 } _cups_raster_error_t;
60 
61 typedef enum _cups_digestoptions_e	/**** Digest Options values */
62 {
63   _CUPS_DIGESTOPTIONS_NONE,		/* No Digest authentication options */
64   _CUPS_DIGESTOPTIONS_DENYMD5		/* Do not use MD5 hashes for digest */
65 } _cups_digestoptions_t;
66 
67 typedef enum _cups_uatokens_e		/**** UserAgentTokens values */
68 {
69   _CUPS_UATOKENS_NONE,			/* Do not send User-Agent */
70   _CUPS_UATOKENS_PRODUCT_ONLY,		/* CUPS IPP */
71   _CUPS_UATOKENS_MAJOR,			/* CUPS/major IPP/2 */
72   _CUPS_UATOKENS_MINOR,			/* CUPS/major.minor IPP/2.1 */
73   _CUPS_UATOKENS_MINIMAL,		/* CUPS/major.minor.patch IPP/2.1 */
74   _CUPS_UATOKENS_OS,			/* CUPS/major.minor.patch (osname osversion) IPP/2.1 */
75   _CUPS_UATOKENS_FULL			/* CUPS/major.minor.patch (osname osversion; architecture) IPP/2.1 */
76 } _cups_uatokens_t;
77 
78 typedef struct _cups_globals_s		/**** CUPS global state data ****/
79 {
80   /* Multiple places... */
81   const char		*cups_datadir,	/* CUPS_DATADIR environment var */
82 			*cups_serverbin,/* CUPS_SERVERBIN environment var */
83 			*cups_serverroot,
84 					/* CUPS_SERVERROOT environment var */
85 			*cups_statedir,	/* CUPS_STATEDIR environment var */
86 			*home,		/* HOME environment var */
87 			*localedir;	/* LOCALDIR environment var */
88 
89   /* adminutil.c */
90   time_t		cupsd_update;	/* Last time we got or set cupsd.conf */
91   char			cupsd_hostname[HTTP_MAX_HOST];
92 					/* Hostname for connection */
93   int			cupsd_num_settings;
94 					/* Number of server settings */
95   cups_option_t		*cupsd_settings;/* Server settings */
96 
97   /* auth.c */
98 #  ifdef HAVE_GSSAPI
99   char			gss_service_name[32];
100   					/* Kerberos service name */
101 #  endif /* HAVE_GSSAPI */
102 
103   /* backend.c */
104   char			resolved_uri[1024];
105 					/* Buffer for cupsBackendDeviceURI */
106 
107   /* debug.c */
108 #  ifdef DEBUG
109   int			thread_id;	/* Friendly thread ID */
110 #  endif /* DEBUG */
111 
112   /* file.c */
113   cups_file_t		*stdio_files[3];/* stdin, stdout, stderr */
114 
115   /* http.c */
116   char			http_date[256];	/* Date+time buffer */
117 
118   /* http-addr.c */
119   unsigned		ip_addr;	/* Packed IPv4 address */
120   char			*ip_ptrs[2];	/* Pointer to packed address */
121   struct hostent	hostent;	/* Host entry for IP address */
122 #  ifdef HAVE_GETADDRINFO
123   char			hostname[1024];	/* Hostname */
124 #  endif /* HAVE_GETADDRINFO */
125   int			need_res_init;	/* Need to reinitialize resolver? */
126 
127   /* ipp.c */
128   ipp_uchar_t		ipp_date[11];	/* RFC-2579 date/time data */
129   _cups_buffer_t	*cups_buffers;	/* Buffer list */
130 
131   /* ipp-support.c */
132   int			ipp_port;	/* IPP port number */
133   char			ipp_unknown[255];
134 					/* Unknown error statuses */
135 
136   /* language.c */
137   cups_lang_t		*lang_default;	/* Default language */
138 #  ifdef __APPLE__
139   char			language[32];	/* Cached language */
140 #  endif /* __APPLE__ */
141 
142   /* pwg-media.c */
143   cups_array_t		*leg_size_lut,	/* Lookup table for legacy names */
144 			*ppd_size_lut,	/* Lookup table for PPD names */
145 			*pwg_size_lut;	/* Lookup table for PWG names */
146   pwg_media_t		pwg_media;	/* PWG media data for custom size */
147   char			pwg_name[65],	/* PWG media name for custom size */
148 			ppd_name[41];	/* PPD media name for custom size */
149 
150   /* raster-error.c */
151   _cups_raster_error_t	raster_error;	/* Raster error information */
152 
153   /* request.c */
154   http_t		*http;		/* Current server connection */
155   ipp_status_t		last_error;	/* Last IPP error */
156   char			*last_status_message;
157 					/* Last IPP status-message */
158 
159   /* snmp.c */
160   char			snmp_community[255];
161 					/* Default SNMP community name */
162   int			snmp_debug;	/* Log SNMP IO to stderr? */
163 
164   /* tempfile.c */
165   char			tempfile[1024];	/* cupsTempFd/File buffer */
166 
167   /* usersys.c */
168   _cups_digestoptions_t	digestoptions;	/* DigestOptions setting */
169   _cups_uatokens_t	uatokens;	/* UserAgentTokens setting */
170   http_encryption_t	encryption;	/* Encryption setting */
171   char			user[65],	/* User name */
172 			user_agent[256],/* User-Agent string */
173 			server[256],	/* Server address */
174 			servername[256],/* Server hostname */
175 			password[128];	/* Password for default callback */
176   cups_oauth_cb_t	oauth_cb;	/* OAuth callback */
177   void			*oauth_data;	/* OAuth user data */
178   cups_password_cb2_t	password_cb;	/* Password callback */
179   void			*password_data;	/* Password user data */
180   http_tls_credentials_t tls_credentials;
181 					/* Default client credentials */
182   cups_client_cert_cb_t	client_cert_cb;	/* Client certificate callback */
183   void			*client_cert_data;
184 					/* Client certificate user data */
185   cups_server_cert_cb_t	server_cert_cb;	/* Server certificate callback */
186   void			*server_cert_data;
187 					/* Server certificate user data */
188   int			server_version,	/* Server IPP version */
189 			trust_first,	/* Trust on first use? */
190 			any_root,	/* Allow any (e.g., self-signed) root */
191 			expired_certs,	/* Allow expired certs */
192 			validate_certs;	/* Validate certificates */
193 
194   /* util.c */
195   char			def_printer[256];
196 					/* Default printer */
197 
198 #  ifndef _WIN32
199 #    define PW_BUF_SIZE 16384		/* As per glibc manual page */
200   char			pw_buf[PW_BUF_SIZE];
201 					/* Big buffer for struct passwd buffers */
202 #  endif /* !_WIN32 */
203 } _cups_globals_t;
204 
205 typedef struct _cups_media_db_s		/* Media database */
206 {
207   char		*color,			/* Media color, if any */
208 		*key,			/* Media key, if any */
209 		*info,			/* Media human-readable name, if any */
210 		*size_name,		/* Media PWG size name, if provided */
211 		*source,		/* Media source, if any */
212 		*type;			/* Media type, if any */
213   int		width,			/* Width in hundredths of millimeters */
214 		length,			/* Length in hundredths of
215 					 * millimeters */
216 		bottom,			/* Bottom margin in hundredths of
217 					 * millimeters */
218 		left,			/* Left margin in hundredths of
219 					 * millimeters */
220 		right,			/* Right margin in hundredths of
221 					 * millimeters */
222 		top;			/* Top margin in hundredths of
223 					 * millimeters */
224 } _cups_media_db_t;
225 
226 typedef struct _cups_dconstres_s	/* Constraint/resolver */
227 {
228   char	*name;				/* Name of resolver */
229   ipp_t	*collection;			/* Collection containing attrs */
230 } _cups_dconstres_t;
231 
232 struct _cups_dinfo_s			/* Destination capability and status
233 					 * information */
234 {
235   int			version;	/* IPP version */
236   const char		*uri;		/* Printer URI */
237   char			*resource;	/* Resource path */
238   ipp_t			*attrs;		/* Printer attributes */
239   int			num_defaults;	/* Number of default options */
240   cups_option_t		*defaults;	/* Default options */
241   cups_array_t		*constraints;	/* Job constraints */
242   cups_array_t		*resolvers;	/* Job resolvers */
243   cups_array_t		*localizations;	/* Localization information */
244   cups_array_t		*media_db;	/* Media database */
245   _cups_media_db_t	min_size,	/* Minimum size */
246 			max_size;	/* Maximum size */
247   unsigned		cached_flags;	/* Flags used for cached media */
248   cups_array_t		*cached_db;	/* Cache of media from last index/default */
249   time_t		ready_time;	/* When xxx-ready attributes were last queried */
250   ipp_t			*ready_attrs;	/* xxx-ready attributes */
251   cups_array_t		*ready_db;	/* media[-col]-ready media database */
252 };
253 
254 
255 /*
256  * Prototypes...
257  */
258 
259 #  ifdef __APPLE__
260 extern CFStringRef	_cupsAppleCopyDefaultPaperID(void) _CUPS_PRIVATE;
261 extern CFStringRef	_cupsAppleCopyDefaultPrinter(void) _CUPS_PRIVATE;
262 extern int		_cupsAppleGetUseLastPrinter(void) _CUPS_PRIVATE;
263 extern void		_cupsAppleSetDefaultPaperID(CFStringRef name) _CUPS_PRIVATE;
264 extern void		_cupsAppleSetDefaultPrinter(CFStringRef name) _CUPS_PRIVATE;
265 extern void		_cupsAppleSetUseLastPrinter(int uselast) _CUPS_PRIVATE;
266 #  endif /* __APPLE__ */
267 
268 extern char		*_cupsBufferGet(size_t size) _CUPS_PRIVATE;
269 extern void		_cupsBufferRelease(char *b) _CUPS_PRIVATE;
270 
271 extern http_t		*_cupsConnect(void) _CUPS_PRIVATE;
272 extern char		*_cupsCreateDest(const char *name, const char *info, const char *device_id, const char *device_uri, char *uri, size_t urisize) _CUPS_PRIVATE;
273 extern ipp_attribute_t	*_cupsEncodeOption(ipp_t *ipp, ipp_tag_t group_tag, _ipp_option_t *map, const char *name, const char *value) _CUPS_PRIVATE;
274 extern int		_cupsGet1284Values(const char *device_id, cups_option_t **values) _CUPS_PRIVATE;
275 extern double		_cupsGetClock(void) _CUPS_PRIVATE;
276 extern const char	*_cupsGetDestResource(cups_dest_t *dest, unsigned flags, char *resource, size_t resourcesize) _CUPS_PRIVATE;
277 extern int		_cupsGetDests(http_t *http, ipp_op_t op, const char *name, cups_dest_t **dests, cups_ptype_t type, cups_ptype_t mask) _CUPS_PRIVATE;
278 extern const char	*_cupsGetPassword(const char *prompt) _CUPS_PRIVATE;
279 extern void		_cupsGlobalLock(void) _CUPS_PRIVATE;
280 extern _cups_globals_t	*_cupsGlobals(void) _CUPS_PRIVATE;
281 extern void		_cupsGlobalUnlock(void) _CUPS_PRIVATE;
282 #  ifdef HAVE_GSSAPI
283 extern const char	*_cupsGSSServiceName(void) _CUPS_PRIVATE;
284 #  endif /* HAVE_GSSAPI */
285 extern int		_cupsNextDelay(int current, int *previous) _CUPS_PRIVATE;
286 extern void		_cupsSetDefaults(void) _CUPS_INTERNAL;
287 extern void		_cupsSetError(ipp_status_t status, const char *message, int localize) _CUPS_PRIVATE;
288 extern void		_cupsSetHTTPError(http_t *http, http_status_t status) _CUPS_INTERNAL;
289 #  ifdef HAVE_GSSAPI
290 extern int		_cupsSetNegotiateAuthString(http_t *http, const char *method, const char *resource) _CUPS_PRIVATE;
291 #  endif /* HAVE_GSSAPI */
292 extern char		*_cupsUserDefault(char *name, size_t namesize) _CUPS_INTERNAL;
293 
294 
295 /*
296  * C++ magic...
297  */
298 
299 #  ifdef __cplusplus
300 }
301 #  endif /* __cplusplus */
302 #endif /* !_CUPS_CUPS_PRIVATE_H_ */
303