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