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