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