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