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