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