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