2 * "$Id: http-private.h 7850 2008-08-20 00:07:25Z mike $"
4 * Private HTTP definitions for CUPS.
6 * Copyright 2007-2012 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
18 #ifndef _CUPS_HTTP_PRIVATE_H_
19 # define _CUPS_HTTP_PRIVATE_H_
22 * Include necessary headers...
30 # include <sys/select.h>
36 # include <winsock2.h>
40 # include <sys/socket.h>
41 # define closesocket(f) close(f)
45 # ifdef HAVE_GSS_GSSAPI_H
46 # include <GSS/gssapi.h>
47 # ifdef HAVE_GSSAPI_GENERIC_H
48 # include <GSS/gssapi_generic.h>
49 # endif /* HAVE_GSSAPI_GENERIC_H */
50 # ifdef HAVE_GSSAPI_KRB5_H
51 # include <GSS/gssapi_krb5.h>
52 # endif /* HAVE_GSSAPI_KRB5_H */
53 # elif defined(HAVE_GSSAPI_GSSAPI_H)
54 # include <gssapi/gssapi.h>
55 # ifdef HAVE_GSSAPI_GENERIC_H
56 # include <gssapi/gssapi_generic.h>
57 # endif /* HAVE_GSSAPI_GENERIC_H */
58 # ifdef HAVE_GSSAPI_KRB5_H
59 # include <gssapi/gssapi_krb5.h>
60 # endif /* HAVE_GSSAPI_KRB5_H */
61 # elif defined(HAVE_GSSAPI_H)
63 # endif /* HAVE_GSS_GSSAPI_H */
64 # ifndef HAVE_GSS_C_NT_HOSTBASED_SERVICE
65 # define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name
66 # endif /* !HAVE_GSS_C_NT_HOSTBASED_SERVICE */
69 # endif /* HAVE_KRB5_H */
70 # endif /* HAVE_GSSAPI */
72 # ifdef HAVE_AUTHORIZATION_H
73 # include <Security/Authorization.h>
74 # endif /* HAVE_AUTHORIZATION_H */
76 # if defined(__APPLE__) && !defined(_SOCKLEN_T)
78 * MacOS X 10.2.x does not define socklen_t, and in fact uses an int instead of
79 * unsigned type for length values...
82 typedef int socklen_t
;
83 # endif /* __APPLE__ && !_SOCKLEN_T */
85 # include <cups/http.h>
86 # include "md5-private.h"
87 # include "ipp-private.h"
89 # if defined HAVE_LIBSSL
90 # include <openssl/err.h>
91 # include <openssl/rand.h>
92 # include <openssl/ssl.h>
93 # elif defined HAVE_GNUTLS
94 # include <gnutls/gnutls.h>
95 # include <gnutls/x509.h>
97 # elif defined(HAVE_CDSASSL)
98 # include <CoreFoundation/CoreFoundation.h>
99 # include <Security/Security.h>
100 # include <Security/SecureTransport.h>
101 # ifdef HAVE_SECURETRANSPORTPRIV_H
102 # include <Security/SecureTransportPriv.h>
103 # endif /* HAVE_SECURETRANSPORTPRIV_H */
104 # ifdef HAVE_SECITEM_H
105 # include <Security/SecItem.h>
106 # endif /* HAVE_SECITEM_H */
107 # ifdef HAVE_SECBASEPRIV_H
108 # include <Security/SecBasePriv.h>
109 # endif /* HAVE_SECBASEPRIV_H */
110 # ifdef HAVE_SECCERTIFICATE_H
111 # include <Security/SecCertificate.h>
112 # include <Security/SecIdentity.h>
113 # endif /* HAVE_SECCERTIFICATE_H */
114 # ifdef HAVE_SECITEMPRIV_H
115 # include <Security/SecItemPriv.h>
116 # endif /* HAVE_SECITEMPRIV_H */
117 # ifdef HAVE_SECIDENTITYSEARCHPRIV_H
118 # include <Security/SecIdentitySearchPriv.h>
119 # endif /* HAVE_SECIDENTITYSEARCHPRIV_H */
120 # ifdef HAVE_SECPOLICYPRIV_H
121 # include <Security/SecPolicyPriv.h>
122 # endif /* HAVE_SECPOLICYPRIV_H */
123 # elif defined(HAVE_SSPISSL)
124 # include "sspi-private.h"
125 # endif /* HAVE_LIBSSL */
129 # ifdef HAVE_GETIFADDRS
130 # include <ifaddrs.h>
132 # include <sys/ioctl.h>
133 # ifdef HAVE_SYS_SOCKIO_H
134 # include <sys/sockio.h>
135 # endif /* HAVE_SYS_SOCKIO_H */
136 # endif /* HAVE_GETIFADDRS */
146 # endif /* __cplusplus */
154 #define _HTTP_RESOLVE_DEFAULT 0 /* Just resolve with default options */
155 #define _HTTP_RESOLVE_STDERR 1 /* Log resolve progress to stderr */
156 #define _HTTP_RESOLVE_FQDN 2 /* Resolve to a FQDN */
157 #define _HTTP_RESOLVE_FAXOUT 4 /* Resolve FaxOut service? */
161 * Types and functions for SSL support...
164 # if defined HAVE_LIBSSL
166 * The OpenSSL library provides its own SSL/TLS context structure for its
167 * IO and protocol management. However, we need to provide our own BIO
168 * (basic IO) implementation to do timeouts...
171 typedef SSL
*http_tls_t
;
172 typedef void *http_tls_credentials_t
;
174 extern BIO_METHOD
*_httpBIOMethods(void);
176 # elif defined HAVE_GNUTLS
178 * The GNU TLS library is more of a "bare metal" SSL/TLS library...
181 typedef gnutls_session http_tls_t
;
182 typedef void *http_tls_credentials_t
;
184 extern ssize_t
_httpReadGNUTLS(gnutls_transport_ptr ptr
, void *data
,
186 extern ssize_t
_httpWriteGNUTLS(gnutls_transport_ptr ptr
, const void *data
,
189 # elif defined(HAVE_CDSASSL)
191 * Darwin's Security framework provides its own SSL/TLS context structure
192 * for its IO and protocol management...
195 # if !defined(HAVE_SECBASEPRIV_H) && defined(HAVE_CSSMERRORSTRING) /* Declare prototype for function in that header... */
196 extern const char *cssmErrorString(int error
);
197 # endif /* !HAVE_SECBASEPRIV_H && HAVE_CSSMERRORSTRING */
198 # ifndef HAVE_SECITEMPRIV_H /* Declare constants from that header... */
199 extern const CFTypeRef kSecClassCertificate
;
200 extern const CFTypeRef kSecClassIdentity
;
201 # endif /* !HAVE_SECITEMPRIV_H */
202 # if !defined(HAVE_SECIDENTITYSEARCHPRIV_H) && defined(HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY) /* Declare prototype for function in that header... */
203 extern OSStatus
SecIdentitySearchCreateWithPolicy(SecPolicyRef policy
,
204 CFStringRef idString
, CSSM_KEYUSE keyUsage
,
205 CFTypeRef keychainOrArray
,
206 Boolean returnOnlyValidIdentities
,
207 SecIdentitySearchRef
* searchRef
);
208 # endif /* !HAVE_SECIDENTITYSEARCHPRIV_H && HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY */
209 # if !defined(HAVE_SECPOLICYPRIV_H) && defined(HAVE_SECPOLICYSETVALUE) /* Declare prototype for function in that header... */
210 extern OSStatus
SecPolicySetValue(SecPolicyRef policyRef
,
211 const CSSM_DATA
*value
);
212 # endif /* !HAVE_SECPOLICYPRIV_H && HAVE_SECPOLICYSETVALUE */
214 typedef SSLContextRef http_tls_t
;
215 typedef CFArrayRef http_tls_credentials_t
;
217 extern OSStatus
_httpReadCDSA(SSLConnectionRef connection
, void *data
,
219 extern OSStatus
_httpWriteCDSA(SSLConnectionRef connection
, const void *data
,
222 # elif defined(HAVE_SSPISSL)
224 * Windows' SSPI library gets a CUPS wrapper...
227 typedef _sspi_struct_t
* http_tls_t
;
228 typedef void *http_tls_credentials_t
;
232 * Otherwise define stub types since we have no SSL support...
235 typedef void *http_tls_t
;
236 typedef void *http_tls_credentials_t
;
237 # endif /* HAVE_LIBSSL */
239 struct _http_s
/**** HTTP connection structure. ****/
241 int fd
; /* File descriptor for this socket */
242 int blocking
; /* To block or not to block */
243 int error
; /* Last error on read */
244 time_t activity
; /* Time since last read/write */
245 http_state_t state
; /* State of client */
246 http_status_t status
; /* Status of last request */
247 http_version_t version
; /* Protocol version */
248 http_keepalive_t keep_alive
; /* Keep-alive supported? */
249 struct sockaddr_in _hostaddr
; /* Address of connected host (deprecated) */
250 char hostname
[HTTP_MAX_HOST
],
251 /* Name of connected host */
252 fields
[HTTP_FIELD_MAX
][HTTP_MAX_VALUE
];
254 char *data
; /* Pointer to data buffer */
255 http_encoding_t data_encoding
; /* Chunked or not */
256 int _data_remaining
;/* Number of bytes left (deprecated) */
257 int used
; /* Number of bytes used in buffer */
258 char buffer
[HTTP_MAX_BUFFER
];
259 /* Buffer for incoming data */
260 int auth_type
; /* Authentication in use */
261 _cups_md5_state_t md5_state
; /* MD5 state */
262 char nonce
[HTTP_MAX_VALUE
];
264 int nonce_count
; /* Nonce count */
265 http_tls_t tls
; /* TLS state information */
266 http_encryption_t encryption
; /* Encryption requirements */
267 /**** New in CUPS 1.1.19 ****/
268 fd_set
*input_set
; /* select() set for httpWait() (deprecated) */
269 http_status_t expect
; /* Expect: header */
270 char *cookie
; /* Cookie value(s) */
271 /**** New in CUPS 1.1.20 ****/
272 char _authstring
[HTTP_MAX_VALUE
],
273 /* Current Authentication value (deprecated) */
274 userpass
[HTTP_MAX_VALUE
];
275 /* Username:password string */
276 int digest_tries
; /* Number of tries for digest auth */
277 /**** New in CUPS 1.2 ****/
278 off_t data_remaining
; /* Number of bytes left */
279 http_addr_t
*hostaddr
; /* Current host address and port */
280 http_addrlist_t
*addrlist
; /* List of valid addresses */
281 char wbuffer
[HTTP_MAX_BUFFER
];
282 /* Buffer for outgoing data */
283 int wused
; /* Write buffer bytes used */
284 /**** New in CUPS 1.3 ****/
285 char *field_authorization
;
286 /* Authorization field */
287 char *authstring
; /* Current authorization field */
289 gss_OID gssmech
; /* Authentication mechanism */
290 gss_ctx_id_t gssctx
; /* Authentication context */
291 gss_name_t gssname
; /* Authentication server name */
292 # endif /* HAVE_GSSAPI */
293 # ifdef HAVE_AUTHORIZATION_H
294 AuthorizationRef auth_ref
; /* Authorization ref */
295 # endif /* HAVE_AUTHORIZATION_H */
296 /**** New in CUPS 1.5 ****/
297 http_tls_credentials_t tls_credentials
;
298 /* TLS credentials */
299 http_timeout_cb_t timeout_cb
; /* Timeout callback */
300 void *timeout_data
; /* User data pointer */
301 double timeout_value
; /* Timeout in seconds */
302 int wait_value
; /* httpWait value for timeout */
304 char gsshost
[256]; /* Hostname for Kerberos */
305 # endif /* HAVE_GSSAPI */
310 * Some OS's don't have hstrerror(), most notably Solaris...
313 # ifndef HAVE_HSTRERROR
314 extern const char *_cups_hstrerror(int error
);
315 # define hstrerror _cups_hstrerror
316 # elif defined(_AIX) || defined(__osf__)
318 * AIX and Tru64 UNIX don't provide a prototype but do provide the function...
320 extern const char *hstrerror(int error
);
321 # endif /* !HAVE_HSTRERROR */
325 * Some OS's don't have getifaddrs() and freeifaddrs()...
328 # if !defined(WIN32) && !defined(HAVE_GETIFADDRS)
331 # endif /* ifa_dstaddr */
333 # define ifr_netmask ifr_addr
334 # endif /* !ifr_netmask */
336 struct ifaddrs
/**** Interface Structure ****/
338 struct ifaddrs
*ifa_next
; /* Next interface in list */
339 char *ifa_name
; /* Name of interface */
340 unsigned int ifa_flags
; /* Flags (up, point-to-point, etc.) */
341 struct sockaddr
*ifa_addr
, /* Network address */
342 *ifa_netmask
; /* Address mask */
345 struct sockaddr
*ifu_broadaddr
; /* Broadcast address of this interface. */
346 struct sockaddr
*ifu_dstaddr
; /* Point-to-point destination address. */
349 void *ifa_data
; /* Interface statistics */
352 # ifndef ifa_broadaddr
353 # define ifa_broadaddr ifa_ifu.ifu_broadaddr
354 # endif /* !ifa_broadaddr */
356 # define ifa_dstaddr ifa_ifu.ifu_dstaddr
357 # endif /* !ifa_dstaddr */
359 extern int _cups_getifaddrs(struct ifaddrs
**addrs
);
360 # define getifaddrs _cups_getifaddrs
361 extern void _cups_freeifaddrs(struct ifaddrs
*addrs
);
362 # define freeifaddrs _cups_freeifaddrs
363 # endif /* !WIN32 && !HAVE_GETIFADDRS */
370 #define _httpAddrFamily(addrp) (addrp)->addr.sa_family
371 extern int _httpAddrPort(http_addr_t
*addr
);
372 extern void _httpAddrSetPort(http_addr_t
*addr
, int port
);
373 extern char *_httpAssembleUUID(const char *server
, int port
,
374 const char *name
, int number
,
375 char *buffer
, size_t bufsize
);
376 extern http_t
*_httpCreate(const char *host
, int port
,
377 http_addrlist_t
*addrlist
,
378 http_encryption_t encryption
,
380 extern http_tls_credentials_t
381 _httpCreateCredentials(cups_array_t
*credentials
);
382 extern char *_httpDecodeURI(char *dst
, const char *src
,
384 extern void _httpDisconnect(http_t
*http
);
385 extern char *_httpEncodeURI(char *dst
, const char *src
,
387 extern void _httpFreeCredentials(http_tls_credentials_t credentials
);
388 extern ssize_t
_httpPeek(http_t
*http
, char *buffer
, size_t length
);
389 extern const char *_httpResolveURI(const char *uri
, char *resolved_uri
,
390 size_t resolved_size
, int options
,
391 int (*cb
)(void *context
),
393 extern int _httpUpdate(http_t
*http
, http_status_t
*status
);
394 extern int _httpWait(http_t
*http
, int msec
, int usessl
);
403 # endif /* __cplusplus */
405 #endif /* !_CUPS_HTTP_PRIVATE_H_ */
408 * End of "$Id: http-private.h 7850 2008-08-20 00:07:25Z mike $".