]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/http-private.h
Fix some build issues with the "core" component selection (rdar://47394086)
[thirdparty/cups.git] / cups / http-private.h
CommitLineData
ef416fc2 1/*
2c85b752 2 * Private HTTP definitions for CUPS.
ef416fc2 3 *
378eeedf 4 * Copyright 2007-2018 by Apple Inc.
2c85b752 5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 6 *
378eeedf
MS
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
8 * information.
ef416fc2 9 */
10
11#ifndef _CUPS_HTTP_PRIVATE_H_
12# define _CUPS_HTTP_PRIVATE_H_
13
14/*
15 * Include necessary headers...
16 */
17
71e16022 18# include "config.h"
41e6c1f1 19# include <cups/language.h>
5180a04c 20# include <stddef.h>
a74454a7 21# include <stdlib.h>
ef416fc2 22
23# ifdef __sun
ef416fc2 24# include <sys/select.h>
25# endif /* __sun */
26
27# include <limits.h>
19dc16f7 28# ifdef _WIN32
104c5283 29# define _WINSOCK_DEPRECATED_NO_WARNINGS 1
ef416fc2 30# include <io.h>
31# include <winsock2.h>
db8b865d 32# define CUPS_SOCAST (const char *)
ef416fc2 33# else
34# include <unistd.h>
35# include <fcntl.h>
36# include <sys/socket.h>
db8b865d 37# define CUPS_SOCAST
19dc16f7 38# endif /* _WIN32 */
ef416fc2 39
f7deaa1a 40# ifdef HAVE_GSSAPI
eac3a0a0
MS
41# ifdef HAVE_GSS_GSSAPI_H
42# include <GSS/gssapi.h>
eac3a0a0 43# elif defined(HAVE_GSSAPI_GSSAPI_H)
f7deaa1a 44# include <gssapi/gssapi.h>
eac3a0a0 45# elif defined(HAVE_GSSAPI_H)
f7deaa1a 46# include <gssapi.h>
eac3a0a0 47# endif /* HAVE_GSS_GSSAPI_H */
f7deaa1a 48# ifndef HAVE_GSS_C_NT_HOSTBASED_SERVICE
49# define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name
50# endif /* !HAVE_GSS_C_NT_HOSTBASED_SERVICE */
51# endif /* HAVE_GSSAPI */
52
b94498cf 53# ifdef HAVE_AUTHORIZATION_H
54# include <Security/Authorization.h>
55# endif /* HAVE_AUTHORIZATION_H */
56
3dd9c340 57# if defined(__APPLE__) && !defined(_SOCKLEN_T)
ef416fc2 58/*
d4874933 59 * macOS 10.2.x does not define socklen_t, and in fact uses an int instead of
ef416fc2 60 * unsigned type for length values...
61 */
62
63typedef int socklen_t;
3dd9c340 64# endif /* __APPLE__ && !_SOCKLEN_T */
ef416fc2 65
71e16022 66# include <cups/http.h>
fa73b229 67# include "ipp-private.h"
ef416fc2 68
724e1819 69# ifdef HAVE_GNUTLS
07ed0e9a
MS
70# include <gnutls/gnutls.h>
71# include <gnutls/x509.h>
07ed0e9a
MS
72# elif defined(HAVE_CDSASSL)
73# include <CoreFoundation/CoreFoundation.h>
74# include <Security/Security.h>
75# include <Security/SecureTransport.h>
76# ifdef HAVE_SECITEM_H
77# include <Security/SecItem.h>
78# endif /* HAVE_SECITEM_H */
07ed0e9a
MS
79# ifdef HAVE_SECCERTIFICATE_H
80# include <Security/SecCertificate.h>
81# include <Security/SecIdentity.h>
82# endif /* HAVE_SECCERTIFICATE_H */
07ed0e9a 83# elif defined(HAVE_SSPISSL)
2ece34a9
MS
84# include <wincrypt.h>
85# include <wintrust.h>
86# include <schannel.h>
87# define SECURITY_WIN32
88# include <security.h>
89# include <sspi.h>
724e1819 90# endif /* HAVE_GNUTLS */
07ed0e9a 91
19dc16f7 92# ifndef _WIN32
07ed0e9a 93# include <net/if.h>
ed26f50f 94# include <resolv.h>
07ed0e9a
MS
95# ifdef HAVE_GETIFADDRS
96# include <ifaddrs.h>
97# else
98# include <sys/ioctl.h>
99# ifdef HAVE_SYS_SOCKIO_H
100# include <sys/sockio.h>
101# endif /* HAVE_SYS_SOCKIO_H */
102# endif /* HAVE_GETIFADDRS */
19dc16f7 103# endif /* !_WIN32 */
07ed0e9a
MS
104
105
106/*
107 * C++ magic...
108 */
109
110# ifdef __cplusplus
111extern "C" {
112# endif /* __cplusplus */
113
114
eac3a0a0
MS
115/*
116 * Constants...
117 */
118
02c88e67
MS
119# define _HTTP_MAX_SBUFFER 65536 /* Size of (de)compression buffer */
120# define _HTTP_RESOLVE_DEFAULT 0 /* Just resolve with default options */
121# define _HTTP_RESOLVE_STDERR 1 /* Log resolve progress to stderr */
122# define _HTTP_RESOLVE_FQDN 2 /* Resolve to a FQDN */
123# define _HTTP_RESOLVE_FAXOUT 4 /* Resolve FaxOut service? */
124
125# define _HTTP_TLS_NONE 0 /* No TLS options */
126# define _HTTP_TLS_ALLOW_RC4 1 /* Allow RC4 cipher suites */
8f1fbdec
MS
127# define _HTTP_TLS_ALLOW_DH 2 /* Allow DH/DHE key negotiation */
128# define _HTTP_TLS_DENY_CBC 4 /* Deny CBC cipher suites */
02c88e67 129# define _HTTP_TLS_SET_DEFAULT 128 /* Setting the default TLS options */
63aefcd5 130
8f1fbdec
MS
131# define _HTTP_TLS_SSL3 0 /* Min/max version is SSL/3.0 */
132# define _HTTP_TLS_1_0 1 /* Min/max version is TLS/1.0 */
133# define _HTTP_TLS_1_1 2 /* Min/max version is TLS/1.1 */
134# define _HTTP_TLS_1_2 3 /* Min/max version is TLS/1.2 */
135# define _HTTP_TLS_1_3 4 /* Min/max version is TLS/1.3 */
136# define _HTTP_TLS_MAX 5 /* Highest known TLS version */
137
eac3a0a0 138
07ed0e9a
MS
139/*
140 * Types and functions for SSL support...
141 */
142
724e1819 143# ifdef HAVE_GNUTLS
ef416fc2 144/*
145 * The GNU TLS library is more of a "bare metal" SSL/TLS library...
146 */
ef416fc2 147
dd332638 148typedef gnutls_session_t http_tls_t;
172bdf5d 149typedef gnutls_certificate_credentials_t *http_tls_credentials_t;
ef416fc2 150
151# elif defined(HAVE_CDSASSL)
152/*
153 * Darwin's Security framework provides its own SSL/TLS context structure
154 * for its IO and protocol management...
155 */
156
07ed0e9a 157# if !defined(HAVE_SECIDENTITYSEARCHPRIV_H) && defined(HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY) /* Declare prototype for function in that header... */
7cf5915e
MS
158extern OSStatus SecIdentitySearchCreateWithPolicy(SecPolicyRef policy,
159 CFStringRef idString, CSSM_KEYUSE keyUsage,
160 CFTypeRef keychainOrArray,
161 Boolean returnOnlyValidIdentities,
162 SecIdentitySearchRef* searchRef);
07ed0e9a
MS
163# endif /* !HAVE_SECIDENTITYSEARCHPRIV_H && HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY */
164# if !defined(HAVE_SECPOLICYPRIV_H) && defined(HAVE_SECPOLICYSETVALUE) /* Declare prototype for function in that header... */
7cf5915e
MS
165extern OSStatus SecPolicySetValue(SecPolicyRef policyRef,
166 const CSSM_DATA *value);
07ed0e9a 167# endif /* !HAVE_SECPOLICYPRIV_H && HAVE_SECPOLICYSETVALUE */
7cf5915e
MS
168
169typedef SSLContextRef http_tls_t;
170typedef CFArrayRef http_tls_credentials_t;
ef416fc2 171
cc754834 172# elif defined(HAVE_SSPISSL)
07ed0e9a
MS
173/*
174 * Windows' SSPI library gets a CUPS wrapper...
175 */
176
2ece34a9
MS
177typedef struct _http_sspi_s /**** SSPI/SSL data structure ****/
178{
179 CredHandle creds; /* Credentials */
180 CtxtHandle context; /* SSL context */
181 BOOL contextInitialized; /* Is context init'd? */
182 SecPkgContext_StreamSizes streamSizes;/* SSL data stream sizes */
183 BYTE *decryptBuffer; /* Data pre-decryption*/
184 size_t decryptBufferLength; /* Length of decrypt buffer */
185 size_t decryptBufferUsed; /* Bytes used in buffer */
186 BYTE *readBuffer; /* Data post-decryption */
187 int readBufferLength; /* Length of read buffer */
188 int readBufferUsed; /* Bytes used in buffer */
189 BYTE *writeBuffer; /* Data pre-encryption */
190 int writeBufferLength; /* Length of write buffer */
2ece34a9
MS
191 PCCERT_CONTEXT localCert, /* Local certificate */
192 remoteCert; /* Remote (peer's) certificate */
d777d26d 193 char error[256]; /* Most recent error message */
2ece34a9
MS
194} _http_sspi_t;
195typedef _http_sspi_t *http_tls_t;
17eecbf1 196typedef PCCERT_CONTEXT http_tls_credentials_t;
07ed0e9a 197
7cf5915e 198# else
07ed0e9a
MS
199/*
200 * Otherwise define stub types since we have no SSL support...
201 */
202
7cf5915e 203typedef void *http_tls_t;
07ed0e9a 204typedef void *http_tls_credentials_t;
724e1819 205# endif /* HAVE_GNUTLS */
ef416fc2 206
a469f8a5
MS
207typedef enum _http_coding_e /**** HTTP content coding enumeration ****/
208{
209 _HTTP_CODING_IDENTITY, /* No content coding */
210 _HTTP_CODING_GZIP, /* LZ77+gzip decompression */
211 _HTTP_CODING_DEFLATE, /* LZ77+zlib compression */
212 _HTTP_CODING_GUNZIP, /* LZ77+gzip decompression */
213 _HTTP_CODING_INFLATE /* LZ77+zlib decompression */
214} _http_coding_t;
215
216typedef enum _http_mode_e /**** HTTP mode enumeration ****/
217{
218 _HTTP_MODE_CLIENT, /* Client connected to server */
219 _HTTP_MODE_SERVER /* Server connected (accepted) from client */
220} _http_mode_t;
221
5ec1fd3d 222# ifndef _HTTP_NO_PRIVATE
a469f8a5 223struct _http_s /**** HTTP connection structure ****/
f7deaa1a 224{
225 int fd; /* File descriptor for this socket */
226 int blocking; /* To block or not to block */
227 int error; /* Last error on read */
228 time_t activity; /* Time since last read/write */
229 http_state_t state; /* State of client */
230 http_status_t status; /* Status of last request */
231 http_version_t version; /* Protocol version */
232 http_keepalive_t keep_alive; /* Keep-alive supported? */
85dda01c 233 struct sockaddr_in _hostaddr; /* Address of connected host (deprecated) */
f7deaa1a 234 char hostname[HTTP_MAX_HOST],
235 /* Name of connected host */
378eeedf
MS
236 _fields[HTTP_FIELD_ACCEPT_ENCODING][HTTP_MAX_VALUE];
237 /* Field values up to Accept-Encoding (deprecated) */
f7deaa1a 238 char *data; /* Pointer to data buffer */
239 http_encoding_t data_encoding; /* Chunked or not */
85dda01c 240 int _data_remaining;/* Number of bytes left (deprecated) */
f7deaa1a 241 int used; /* Number of bytes used in buffer */
242 char buffer[HTTP_MAX_BUFFER];
243 /* Buffer for incoming data */
5ec1fd3d 244 int _auth_type; /* Authentication in use (deprecated) */
7ec11630 245 unsigned char _md5_state[88]; /* MD5 state (deprecated) */
f7deaa1a 246 char nonce[HTTP_MAX_VALUE];
247 /* Nonce value */
7ec11630 248 unsigned nonce_count; /* Nonce count */
7cf5915e 249 http_tls_t tls; /* TLS state information */
f7deaa1a 250 http_encryption_t encryption; /* Encryption requirements */
a469f8a5 251
f7deaa1a 252 /**** New in CUPS 1.1.19 ****/
85dda01c
MS
253 fd_set *input_set; /* select() set for httpWait() (deprecated) */
254 http_status_t expect; /* Expect: header */
255 char *cookie; /* Cookie value(s) */
a469f8a5 256
f7deaa1a 257 /**** New in CUPS 1.1.20 ****/
258 char _authstring[HTTP_MAX_VALUE],
c1420c87 259 /* Current Authorization value (deprecated) */
f7deaa1a 260 userpass[HTTP_MAX_VALUE];
85dda01c
MS
261 /* Username:password string */
262 int digest_tries; /* Number of tries for digest auth */
a469f8a5 263
f7deaa1a 264 /**** New in CUPS 1.2 ****/
85dda01c
MS
265 off_t data_remaining; /* Number of bytes left */
266 http_addr_t *hostaddr; /* Current host address and port */
267 http_addrlist_t *addrlist; /* List of valid addresses */
f7deaa1a 268 char wbuffer[HTTP_MAX_BUFFER];
269 /* Buffer for outgoing data */
85dda01c 270 int wused; /* Write buffer bytes used */
a469f8a5 271
f7deaa1a 272 /**** New in CUPS 1.3 ****/
c1420c87 273 char *authstring; /* Current Authorization field */
f7deaa1a 274# ifdef HAVE_GSSAPI
85dda01c
MS
275 gss_OID gssmech; /* Authentication mechanism */
276 gss_ctx_id_t gssctx; /* Authentication context */
277 gss_name_t gssname; /* Authentication server name */
f7deaa1a 278# endif /* HAVE_GSSAPI */
b94498cf 279# ifdef HAVE_AUTHORIZATION_H
85dda01c 280 AuthorizationRef auth_ref; /* Authorization ref */
b94498cf 281# endif /* HAVE_AUTHORIZATION_H */
a469f8a5 282
7cf5915e
MS
283 /**** New in CUPS 1.5 ****/
284 http_tls_credentials_t tls_credentials;
85dda01c
MS
285 /* TLS credentials */
286 http_timeout_cb_t timeout_cb; /* Timeout callback */
287 void *timeout_data; /* User data pointer */
288 double timeout_value; /* Timeout in seconds */
289 int wait_value; /* httpWait value for timeout */
eac3a0a0
MS
290# ifdef HAVE_GSSAPI
291 char gsshost[256]; /* Hostname for Kerberos */
292# endif /* HAVE_GSSAPI */
a469f8a5
MS
293
294 /**** New in CUPS 1.7 ****/
cb7f98ee 295 int tls_upgrade; /* Non-zero if we are doing an upgrade */
a469f8a5 296 _http_mode_t mode; /* _HTTP_MODE_CLIENT or _HTTP_MODE_SERVER */
a469f8a5
MS
297# ifdef HAVE_LIBZ
298 _http_coding_t coding; /* _HTTP_CODING_xxx */
5a855d85
MS
299 void *stream; /* (De)compression stream */
300 unsigned char *sbuffer; /* (De)compression buffer */
a469f8a5 301# endif /* HAVE_LIBZ */
7ec11630 302
16f67389
MS
303 /**** New in CUPS 2.2.9 ****/
304 char algorithm[65], /* Algorithm from WWW-Authenticate */
305 nextnonce[HTTP_MAX_VALUE],
306 /* Next nonce value from Authentication-Info */
307 opaque[HTTP_MAX_VALUE],
308 /* Opaque value from WWW-Authenticate */
309 realm[HTTP_MAX_VALUE];
310 /* Realm from WWW-Authenticate */
311
7ec11630 312 /**** New in CUPS 2.3 ****/
378eeedf
MS
313 char *fields[HTTP_FIELD_MAX],
314 /* Allocated field values */
315 *default_fields[HTTP_FIELD_MAX];
316 /* Default field values, if any */
f7deaa1a 317};
5ec1fd3d 318# endif /* !_HTTP_NO_PRIVATE */
f7deaa1a 319
320
ef416fc2 321/*
322 * Some OS's don't have hstrerror(), most notably Solaris...
323 */
324
325# ifndef HAVE_HSTRERROR
326extern const char *_cups_hstrerror(int error);
327# define hstrerror _cups_hstrerror
ef416fc2 328# endif /* !HAVE_HSTRERROR */
329
89d46774 330
839a51c8 331/*
1ff0402e 332 * Prototypes...
839a51c8
MS
333 */
334
e3586875 335extern void _httpAddrSetPort(http_addr_t *addr, int port) _CUPS_PRIVATE;
85dda01c 336extern http_tls_credentials_t
e3586875 337 _httpCreateCredentials(cups_array_t *credentials) _CUPS_PRIVATE;
1106b00e 338extern char *_httpDecodeURI(char *dst, const char *src,
e3586875
MS
339 size_t dstsize) _CUPS_PRIVATE;
340extern void _httpDisconnect(http_t *http) _CUPS_PRIVATE;
5eb9da71 341extern char *_httpEncodeURI(char *dst, const char *src,
e3586875
MS
342 size_t dstsize) _CUPS_PRIVATE;
343extern void _httpFreeCredentials(http_tls_credentials_t credentials) _CUPS_PRIVATE;
5eb9da71 344extern const char *_httpResolveURI(const char *uri, char *resolved_uri,
eac3a0a0 345 size_t resolved_size, int options,
07ed0e9a 346 int (*cb)(void *context),
e3586875
MS
347 void *context) _CUPS_PRIVATE;
348extern int _httpSetDigestAuthString(http_t *http, const char *nonce, const char *method, const char *resource) _CUPS_PRIVATE;
349extern const char *_httpStatus(cups_lang_t *lang, http_status_t status) _CUPS_PRIVATE;
350extern void _httpTLSInitialize(void) _CUPS_PRIVATE;
351extern size_t _httpTLSPending(http_t *http) _CUPS_PRIVATE;
352extern int _httpTLSRead(http_t *http, char *buf, int len) _CUPS_PRIVATE;
e3586875
MS
353extern void _httpTLSSetOptions(int options, int min_version, int max_version) _CUPS_PRIVATE;
354extern int _httpTLSStart(http_t *http) _CUPS_PRIVATE;
355extern void _httpTLSStop(http_t *http) _CUPS_PRIVATE;
356extern int _httpTLSWrite(http_t *http, const char *buf, int len) _CUPS_PRIVATE;
357extern int _httpUpdate(http_t *http, http_status_t *status) _CUPS_PRIVATE;
358extern int _httpWait(http_t *http, int msec, int usessl) _CUPS_PRIVATE;
6d2f911b
MS
359
360
07ed0e9a
MS
361/*
362 * C++ magic...
363 */
364
365# ifdef __cplusplus
366}
367# endif /* __cplusplus */
368
ef416fc2 369#endif /* !_CUPS_HTTP_PRIVATE_H_ */