2 * "$Id: http-private.h 7850 2008-08-20 00:07:25Z mike $"
4 * Private HTTP definitions for CUPS.
6 * Copyright 2007-2010 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_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 */
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 */
62 # endif /* HAVE_KRB5_H */
63 # endif /* HAVE_GSSAPI */
65 # ifdef HAVE_AUTHORIZATION_H
66 # include <Security/Authorization.h>
67 # endif /* HAVE_AUTHORIZATION_H */
69 # if defined(__sgi) || (defined(__APPLE__) && !defined(_SOCKLEN_T))
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...
75 typedef int socklen_t
;
76 # endif /* __sgi || (__APPLE__ && !_SOCKLEN_T) */
78 # include <cups/http.h>
79 # include "md5-private.h"
80 # include "ipp-private.h"
82 # if defined HAVE_LIBSSL
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...
89 # include <openssl/err.h>
90 # include <openssl/rand.h>
91 # include <openssl/ssl.h>
93 typedef SSL
*http_tls_t
;
94 typedef void *http_tls_credentials_t
;
96 extern BIO_METHOD
*_httpBIOMethods(void);
98 # elif defined HAVE_GNUTLS
100 * The GNU TLS library is more of a "bare metal" SSL/TLS library...
102 # include <gnutls/gnutls.h>
103 # include <gnutls/x509.h>
106 typedef gnutls_session http_tls_t
;
107 typedef void *http_tls_credentials_t
;
109 extern ssize_t
_httpReadGNUTLS(gnutls_transport_ptr ptr
, void *data
,
111 extern ssize_t
_httpWriteGNUTLS(gnutls_transport_ptr ptr
, const void *data
,
114 # elif defined(HAVE_CDSASSL)
116 * Darwin's Security framework provides its own SSL/TLS context structure
117 * for its IO and protocol management...
120 # include <CoreFoundation/CoreFoundation.h>
121 # include <Security/Security.h>
122 # include <Security/SecureTransport.h>
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... */
127 extern 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... */
136 extern const CFTypeRef kSecClassCertificate
;
137 extern 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... */
142 extern 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... */
151 extern OSStatus
SecPolicySetValue(SecPolicyRef policyRef
,
152 const CSSM_DATA
*value
);
153 # endif /* HAVE_SECPOLICYPRIV_H */
155 typedef SSLContextRef http_tls_t
;
156 typedef CFArrayRef http_tls_credentials_t
;
158 extern OSStatus
_httpReadCDSA(SSLConnectionRef connection
, void *data
,
160 extern OSStatus
_httpWriteCDSA(SSLConnectionRef connection
, const void *data
,
163 # elif defined(HAVE_SSPISSL)
164 # include "sspi-private.h"
165 typedef _sspi_struct_t
* http_tls_t
;
166 typedef void *http_tls_credentials_t
;
168 typedef void *http_tls_t
;
169 # endif /* HAVE_LIBSSL */
172 struct _http_s
/**** HTTP connection structure. ****/
174 int fd
; /* File descriptor for this socket */
175 int blocking
; /* To block or not to block */
176 int error
; /* Last error on read */
177 time_t activity
; /* Time since last read/write */
178 http_state_t state
; /* State of client */
179 http_status_t status
; /* Status of last request */
180 http_version_t version
; /* Protocol version */
181 http_keepalive_t keep_alive
; /* Keep-alive supported? */
182 struct sockaddr_in _hostaddr
; /* Address of connected host @deprecated@ */
183 char hostname
[HTTP_MAX_HOST
],
184 /* Name of connected host */
185 fields
[HTTP_FIELD_MAX
][HTTP_MAX_VALUE
];
187 char *data
; /* Pointer to data buffer */
188 http_encoding_t data_encoding
; /* Chunked or not */
189 int _data_remaining
;/* Number of bytes left @deprecated@ */
190 int used
; /* Number of bytes used in buffer */
191 char buffer
[HTTP_MAX_BUFFER
];
192 /* Buffer for incoming data */
193 int auth_type
; /* Authentication in use */
194 _cups_md5_state_t md5_state
; /* MD5 state */
195 char nonce
[HTTP_MAX_VALUE
];
197 int nonce_count
; /* Nonce count */
198 http_tls_t tls
; /* TLS state information */
199 http_encryption_t encryption
; /* Encryption requirements */
200 /**** New in CUPS 1.1.19 ****/
201 fd_set
*input_set
; /* select() set for httpWait() @deprecated@ */
202 http_status_t expect
; /* Expect: header @since CUPS 1.1.19@ */
203 char *cookie
; /* Cookie value(s) @since CUPS 1.1.19@ */
204 /**** New in CUPS 1.1.20 ****/
205 char _authstring
[HTTP_MAX_VALUE
],
206 /* Current Authentication value. @deprecated@ */
207 userpass
[HTTP_MAX_VALUE
];
208 /* Username:password string @since CUPS 1.1.20@ */
209 int digest_tries
; /* Number of tries for digest auth @since CUPS 1.1.20@ */
210 /**** New in CUPS 1.2 ****/
211 off_t data_remaining
; /* Number of bytes left @since CUPS 1.2@ */
212 http_addr_t
*hostaddr
; /* Current host address and port @since CUPS 1.2@ */
213 http_addrlist_t
*addrlist
; /* List of valid addresses @since CUPS 1.2@ */
214 char wbuffer
[HTTP_MAX_BUFFER
];
215 /* Buffer for outgoing data */
216 int wused
; /* Write buffer bytes used @since CUPS 1.2@ */
217 /**** New in CUPS 1.3 ****/
218 char *field_authorization
;
219 /* Authorization field @since CUPS 1.3@ */
220 char *authstring
; /* Current authorization field @since CUPS 1.3 */
222 gss_OID gssmech
; /* Authentication mechanism @since CUPS 1.3@ */
223 gss_ctx_id_t gssctx
; /* Authentication context @since CUPS 1.3@ */
224 gss_name_t gssname
; /* Authentication server name @since CUPS 1.3@ */
225 # endif /* HAVE_GSSAPI */
226 # ifdef HAVE_AUTHORIZATION_H
227 AuthorizationRef auth_ref
; /* Authorization ref */
228 # endif /* HAVE_AUTHORIZATION_H */
229 /**** New in CUPS 1.5 ****/
230 http_tls_credentials_t tls_credentials
;
231 /* TLS credentials */
236 * Some OS's don't have hstrerror(), most notably Solaris...
239 # ifndef HAVE_HSTRERROR
240 extern const char *_cups_hstrerror(int error
);
241 # define hstrerror _cups_hstrerror
242 # elif defined(_AIX) || defined(__osf__)
244 * AIX and Tru64 UNIX don't provide a prototype but do provide the function...
246 extern const char *hstrerror(int error
);
247 # endif /* !HAVE_HSTRERROR */
251 * Some OS's don't have getifaddrs() and freeifaddrs()...
256 # ifdef HAVE_GETIFADDRS
257 # include <ifaddrs.h>
259 # include <sys/ioctl.h>
260 # ifdef HAVE_SYS_SOCKIO_H
261 # include <sys/sockio.h>
262 # endif /* HAVE_SYS_SOCKIO_H */
266 # endif /* ifa_dstaddr */
268 # define ifr_netmask ifr_addr
269 # endif /* !ifr_netmask */
271 struct ifaddrs
/**** Interface Structure ****/
273 struct ifaddrs
*ifa_next
; /* Next interface in list */
274 char *ifa_name
; /* Name of interface */
275 unsigned int ifa_flags
; /* Flags (up, point-to-point, etc.) */
276 struct sockaddr
*ifa_addr
, /* Network address */
277 *ifa_netmask
; /* Address mask */
280 struct sockaddr
*ifu_broadaddr
; /* Broadcast address of this interface. */
281 struct sockaddr
*ifu_dstaddr
; /* Point-to-point destination address. */
284 void *ifa_data
; /* Interface statistics */
287 # ifndef ifa_broadaddr
288 # define ifa_broadaddr ifa_ifu.ifu_broadaddr
289 # endif /* !ifa_broadaddr */
291 # define ifa_dstaddr ifa_ifu.ifu_dstaddr
292 # endif /* !ifa_dstaddr */
294 extern int _cups_getifaddrs(struct ifaddrs
**addrs
);
295 # define getifaddrs _cups_getifaddrs
296 extern void _cups_freeifaddrs(struct ifaddrs
*addrs
);
297 # define freeifaddrs _cups_freeifaddrs
298 # endif /* HAVE_GETIFADDRS */
305 extern int _httpAddrPort(http_addr_t
*addr
);
306 extern http_tls_credentials_t
307 _httpConvertCredentials(cups_array_t
*credentials
);
308 extern http_t
*_httpCreate(const char *host
, int port
,
309 http_encryption_t encryption
);
310 extern void _httpDisconnect(http_t
*http
);
311 extern char *_httpEncodeURI(char *dst
, const char *src
,
313 extern void _httpFreeCredentials(http_tls_credentials_t credentials
);
314 extern ssize_t
_httpPeek(http_t
*http
, char *buffer
, size_t length
);
315 extern const char *_httpResolveURI(const char *uri
, char *resolved_uri
,
316 size_t resolved_size
, int log
);
317 extern int _httpWait(http_t
*http
, int msec
, int usessl
);
320 #endif /* !_CUPS_HTTP_PRIVATE_H_ */
323 * End of "$Id: http-private.h 7850 2008-08-20 00:07:25Z mike $".