]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/http-private.h
Merge changes from CUPS 1.5svn-r9675.
[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-2011 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 # 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
135 extern "C" {
136 # endif /* __cplusplus */
137
138
139 /*
140 * Types and functions for SSL support...
141 */
142
143 # if defined HAVE_LIBSSL
144 /*
145 * The OpenSSL library provides its own SSL/TLS context structure for its
146 * IO and protocol management. However, we need to provide our own BIO
147 * (basic IO) implementation to do timeouts...
148 */
149
150 typedef SSL *http_tls_t;
151 typedef void *http_tls_credentials_t;
152
153 extern BIO_METHOD *_httpBIOMethods(void);
154
155 # elif defined HAVE_GNUTLS
156 /*
157 * The GNU TLS library is more of a "bare metal" SSL/TLS library...
158 */
159
160 typedef gnutls_session http_tls_t;
161 typedef void *http_tls_credentials_t;
162
163 extern ssize_t _httpReadGNUTLS(gnutls_transport_ptr ptr, void *data,
164 size_t length);
165 extern ssize_t _httpWriteGNUTLS(gnutls_transport_ptr ptr, const void *data,
166 size_t length);
167
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
174 # if !defined(HAVE_SECBASEPRIV_H) && defined(HAVE_CSSMERRORSTRING) /* Declare prototype for function in that header... */
175 extern const char *cssmErrorString(int error);
176 # endif /* !HAVE_SECBASEPRIV_H && HAVE_CSSMERRORSTRING */
177 # ifndef HAVE_SECITEMPRIV_H /* Declare constants from that header... */
178 extern const CFTypeRef kSecClassCertificate;
179 extern const CFTypeRef kSecClassIdentity;
180 # endif /* !HAVE_SECITEMPRIV_H */
181 # if !defined(HAVE_SECIDENTITYSEARCHPRIV_H) && defined(HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY) /* Declare prototype for function in that header... */
182 extern OSStatus SecIdentitySearchCreateWithPolicy(SecPolicyRef policy,
183 CFStringRef idString, CSSM_KEYUSE keyUsage,
184 CFTypeRef keychainOrArray,
185 Boolean returnOnlyValidIdentities,
186 SecIdentitySearchRef* searchRef);
187 # endif /* !HAVE_SECIDENTITYSEARCHPRIV_H && HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY */
188 # if !defined(HAVE_SECPOLICYPRIV_H) && defined(HAVE_SECPOLICYSETVALUE) /* Declare prototype for function in that header... */
189 extern OSStatus SecPolicySetValue(SecPolicyRef policyRef,
190 const CSSM_DATA *value);
191 # endif /* !HAVE_SECPOLICYPRIV_H && HAVE_SECPOLICYSETVALUE */
192
193 typedef SSLContextRef http_tls_t;
194 typedef CFArrayRef http_tls_credentials_t;
195
196 extern OSStatus _httpReadCDSA(SSLConnectionRef connection, void *data,
197 size_t *dataLength);
198 extern OSStatus _httpWriteCDSA(SSLConnectionRef connection, const void *data,
199 size_t *dataLength);
200
201 # elif defined(HAVE_SSPISSL)
202 /*
203 * Windows' SSPI library gets a CUPS wrapper...
204 */
205
206 typedef _sspi_struct_t * http_tls_t;
207 typedef void *http_tls_credentials_t;
208
209 # else
210 /*
211 * Otherwise define stub types since we have no SSL support...
212 */
213
214 typedef void *http_tls_t;
215 typedef void *http_tls_credentials_t;
216 # endif /* HAVE_LIBSSL */
217
218
219 typedef int (*_http_timeout_cb_t)(http_t *http, void *user_data);
220
221 struct _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 */
247 http_tls_t tls; /* TLS state information */
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 */
275 # ifdef HAVE_AUTHORIZATION_H
276 AuthorizationRef auth_ref; /* Authorization ref @since CUPS 1.3@ */
277 # endif /* HAVE_AUTHORIZATION_H */
278 /**** New in CUPS 1.5 ****/
279 http_tls_credentials_t tls_credentials;
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 */
284 };
285
286
287 /*
288 * Some OS's don't have hstrerror(), most notably Solaris...
289 */
290
291 # ifndef HAVE_HSTRERROR
292 extern 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 */
298 extern const char *hstrerror(int error);
299 # endif /* !HAVE_HSTRERROR */
300
301
302 /*
303 * Some OS's don't have getifaddrs() and freeifaddrs()...
304 */
305
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 */
313
314 struct 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 */
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
327 void *ifa_data; /* Interface statistics */
328 };
329
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 */
336
337 extern int _cups_getifaddrs(struct ifaddrs **addrs);
338 # define getifaddrs _cups_getifaddrs
339 extern void _cups_freeifaddrs(struct ifaddrs *addrs);
340 # define freeifaddrs _cups_freeifaddrs
341 # endif /* !WIN32 && !HAVE_GETIFADDRS */
342
343
344 /*
345 * Prototypes...
346 */
347
348 extern int _httpAddrPort(http_addr_t *addr);
349 extern char *_httpAssembleUUID(const char *server, int port,
350 const char *name, int number,
351 char *buffer, size_t bufsize);
352 extern http_tls_credentials_t
353 _httpConvertCredentials(cups_array_t *credentials);
354 extern http_t *_httpCreate(const char *host, int port,
355 http_addrlist_t *addrlist,
356 http_encryption_t encryption,
357 int family);
358 extern char *_httpDecodeURI(char *dst, const char *src,
359 size_t dstsize);
360 extern void _httpDisconnect(http_t *http);
361 extern char *_httpEncodeURI(char *dst, const char *src,
362 size_t dstsize);
363 extern void _httpFreeCredentials(http_tls_credentials_t credentials);
364 extern ssize_t _httpPeek(http_t *http, char *buffer, size_t length);
365 extern const char *_httpResolveURI(const char *uri, char *resolved_uri,
366 size_t resolved_size, int log,
367 int (*cb)(void *context),
368 void *context);
369 extern void _httpSetTimeout(http_t *http, double timeout,
370 _http_timeout_cb_t cb, void *user_data);
371 extern int _httpUpdate(http_t *http, http_status_t *status);
372 extern int _httpWait(http_t *http, int msec, int usessl);
373
374
375 /*
376 * C++ magic...
377 */
378
379 # ifdef __cplusplus
380 }
381 # endif /* __cplusplus */
382
383 #endif /* !_CUPS_HTTP_PRIVATE_H_ */
384
385 /*
386 * End of "$Id: http-private.h 7850 2008-08-20 00:07:25Z mike $".
387 */