]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
f2d18633 | 2 | * "$Id$" |
ef416fc2 | 3 | * |
2c85b752 | 4 | * Private HTTP definitions for CUPS. |
ef416fc2 | 5 | * |
2c85b752 MS |
6 | * Copyright 2007-2013 by Apple Inc. |
7 | * Copyright 1997-2007 by Easy Software Products, all rights reserved. | |
ef416fc2 | 8 | * |
2c85b752 MS |
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/". | |
ef416fc2 | 14 | * |
2c85b752 | 15 | * This file is subject to the Apple OS-Developed Software exception. |
ef416fc2 | 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" |
41e6c1f1 | 26 | # include <cups/language.h> |
5180a04c | 27 | # include <stddef.h> |
a74454a7 | 28 | # include <stdlib.h> |
ef416fc2 | 29 | |
30 | # ifdef __sun | |
ef416fc2 | 31 | # include <sys/select.h> |
32 | # endif /* __sun */ | |
33 | ||
34 | # include <limits.h> | |
35 | # ifdef WIN32 | |
36 | # include <io.h> | |
37 | # include <winsock2.h> | |
db8b865d | 38 | # define CUPS_SOCAST (const char *) |
ef416fc2 | 39 | # else |
40 | # include <unistd.h> | |
41 | # include <fcntl.h> | |
42 | # include <sys/socket.h> | |
db8b865d | 43 | # define CUPS_SOCAST |
ef416fc2 | 44 | # endif /* WIN32 */ |
45 | ||
f7deaa1a | 46 | # ifdef HAVE_GSSAPI |
eac3a0a0 MS |
47 | # ifdef HAVE_GSS_GSSAPI_H |
48 | # include <GSS/gssapi.h> | |
eac3a0a0 | 49 | # elif defined(HAVE_GSSAPI_GSSAPI_H) |
f7deaa1a | 50 | # include <gssapi/gssapi.h> |
eac3a0a0 | 51 | # elif defined(HAVE_GSSAPI_H) |
f7deaa1a | 52 | # include <gssapi.h> |
eac3a0a0 | 53 | # endif /* HAVE_GSS_GSSAPI_H */ |
f7deaa1a | 54 | # ifndef HAVE_GSS_C_NT_HOSTBASED_SERVICE |
55 | # define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name | |
56 | # endif /* !HAVE_GSS_C_NT_HOSTBASED_SERVICE */ | |
57 | # endif /* HAVE_GSSAPI */ | |
58 | ||
b94498cf | 59 | # ifdef HAVE_AUTHORIZATION_H |
60 | # include <Security/Authorization.h> | |
61 | # endif /* HAVE_AUTHORIZATION_H */ | |
62 | ||
3dd9c340 | 63 | # if defined(__APPLE__) && !defined(_SOCKLEN_T) |
ef416fc2 | 64 | /* |
3dd9c340 | 65 | * MacOS X 10.2.x does not define socklen_t, and in fact uses an int instead of |
ef416fc2 | 66 | * unsigned type for length values... |
67 | */ | |
68 | ||
69 | typedef int socklen_t; | |
3dd9c340 | 70 | # endif /* __APPLE__ && !_SOCKLEN_T */ |
ef416fc2 | 71 | |
71e16022 MS |
72 | # include <cups/http.h> |
73 | # include "md5-private.h" | |
fa73b229 | 74 | # include "ipp-private.h" |
ef416fc2 | 75 | |
724e1819 | 76 | # ifdef HAVE_GNUTLS |
07ed0e9a MS |
77 | # include <gnutls/gnutls.h> |
78 | # include <gnutls/x509.h> | |
79 | # include <gcrypt.h> | |
80 | # elif defined(HAVE_CDSASSL) | |
81 | # include <CoreFoundation/CoreFoundation.h> | |
82 | # include <Security/Security.h> | |
83 | # include <Security/SecureTransport.h> | |
eac3a0a0 MS |
84 | # ifdef HAVE_SECURETRANSPORTPRIV_H |
85 | # include <Security/SecureTransportPriv.h> | |
86 | # endif /* HAVE_SECURETRANSPORTPRIV_H */ | |
07ed0e9a MS |
87 | # ifdef HAVE_SECITEM_H |
88 | # include <Security/SecItem.h> | |
89 | # endif /* HAVE_SECITEM_H */ | |
90 | # ifdef HAVE_SECBASEPRIV_H | |
91 | # include <Security/SecBasePriv.h> | |
92 | # endif /* HAVE_SECBASEPRIV_H */ | |
93 | # ifdef HAVE_SECCERTIFICATE_H | |
94 | # include <Security/SecCertificate.h> | |
95 | # include <Security/SecIdentity.h> | |
96 | # endif /* HAVE_SECCERTIFICATE_H */ | |
9653cfdf MS |
97 | # ifdef HAVE_SECCERTIFICATEPRIV_H |
98 | # include <Security/SecCertificatePriv.h> | |
99 | # else | |
100 | # ifdef __cplusplus | |
101 | extern "C" { | |
102 | # endif /* __cplusplus */ | |
103 | extern SecCertificateRef SecCertificateCreateWithBytes(CFAllocatorRef allocator, const UInt8 *bytes, CFIndex length); | |
104 | extern bool SecCertificateIsValid(SecCertificateRef certificate, CFAbsoluteTime verifyTime); | |
105 | extern CFAbsoluteTime SecCertificateNotValidAfter(SecCertificateRef certificate); | |
106 | extern OSStatus SecCertificateIsSelfSigned(SecCertificateRef certRef, Boolean *isSelfSigned); | |
107 | # ifdef __cplusplus | |
108 | } | |
109 | # endif /* __cplusplus */ | |
110 | # endif /* HAVE_SECCERTIFICATEPRIV_H */ | |
07ed0e9a MS |
111 | # ifdef HAVE_SECITEMPRIV_H |
112 | # include <Security/SecItemPriv.h> | |
113 | # endif /* HAVE_SECITEMPRIV_H */ | |
114 | # ifdef HAVE_SECIDENTITYSEARCHPRIV_H | |
115 | # include <Security/SecIdentitySearchPriv.h> | |
116 | # endif /* HAVE_SECIDENTITYSEARCHPRIV_H */ | |
117 | # ifdef HAVE_SECPOLICYPRIV_H | |
118 | # include <Security/SecPolicyPriv.h> | |
119 | # endif /* HAVE_SECPOLICYPRIV_H */ | |
120 | # elif defined(HAVE_SSPISSL) | |
121 | # include "sspi-private.h" | |
724e1819 | 122 | # endif /* HAVE_GNUTLS */ |
07ed0e9a MS |
123 | |
124 | # ifndef WIN32 | |
125 | # include <net/if.h> | |
126 | # ifdef HAVE_GETIFADDRS | |
127 | # include <ifaddrs.h> | |
128 | # else | |
129 | # include <sys/ioctl.h> | |
130 | # ifdef HAVE_SYS_SOCKIO_H | |
131 | # include <sys/sockio.h> | |
132 | # endif /* HAVE_SYS_SOCKIO_H */ | |
133 | # endif /* HAVE_GETIFADDRS */ | |
134 | # endif /* !WIN32 */ | |
135 | ||
a469f8a5 MS |
136 | # ifdef HAVE_LIBZ |
137 | # include <zlib.h> | |
138 | # endif /* HAVE_LIBZ */ | |
139 | ||
07ed0e9a MS |
140 | |
141 | /* | |
142 | * C++ magic... | |
143 | */ | |
144 | ||
145 | # ifdef __cplusplus | |
146 | extern "C" { | |
147 | # endif /* __cplusplus */ | |
148 | ||
149 | ||
eac3a0a0 MS |
150 | /* |
151 | * Constants... | |
152 | */ | |
153 | ||
154 | ||
155 | #define _HTTP_RESOLVE_DEFAULT 0 /* Just resolve with default options */ | |
156 | #define _HTTP_RESOLVE_STDERR 1 /* Log resolve progress to stderr */ | |
157 | #define _HTTP_RESOLVE_FQDN 2 /* Resolve to a FQDN */ | |
f3c17241 | 158 | #define _HTTP_RESOLVE_FAXOUT 4 /* Resolve FaxOut service? */ |
eac3a0a0 MS |
159 | |
160 | ||
07ed0e9a MS |
161 | /* |
162 | * Types and functions for SSL support... | |
163 | */ | |
164 | ||
724e1819 | 165 | # ifdef HAVE_GNUTLS |
ef416fc2 | 166 | /* |
167 | * The GNU TLS library is more of a "bare metal" SSL/TLS library... | |
168 | */ | |
ef416fc2 | 169 | |
dd332638 | 170 | typedef gnutls_session_t http_tls_t; |
7cf5915e | 171 | typedef void *http_tls_credentials_t; |
ef416fc2 | 172 | |
173 | # elif defined(HAVE_CDSASSL) | |
174 | /* | |
175 | * Darwin's Security framework provides its own SSL/TLS context structure | |
176 | * for its IO and protocol management... | |
177 | */ | |
178 | ||
07ed0e9a | 179 | # if !defined(HAVE_SECBASEPRIV_H) && defined(HAVE_CSSMERRORSTRING) /* Declare prototype for function in that header... */ |
7cf5915e | 180 | extern const char *cssmErrorString(int error); |
07ed0e9a MS |
181 | # endif /* !HAVE_SECBASEPRIV_H && HAVE_CSSMERRORSTRING */ |
182 | # ifndef HAVE_SECITEMPRIV_H /* Declare constants from that header... */ | |
7cf5915e MS |
183 | extern const CFTypeRef kSecClassCertificate; |
184 | extern const CFTypeRef kSecClassIdentity; | |
07ed0e9a MS |
185 | # endif /* !HAVE_SECITEMPRIV_H */ |
186 | # if !defined(HAVE_SECIDENTITYSEARCHPRIV_H) && defined(HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY) /* Declare prototype for function in that header... */ | |
7cf5915e MS |
187 | extern OSStatus SecIdentitySearchCreateWithPolicy(SecPolicyRef policy, |
188 | CFStringRef idString, CSSM_KEYUSE keyUsage, | |
189 | CFTypeRef keychainOrArray, | |
190 | Boolean returnOnlyValidIdentities, | |
191 | SecIdentitySearchRef* searchRef); | |
07ed0e9a MS |
192 | # endif /* !HAVE_SECIDENTITYSEARCHPRIV_H && HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY */ |
193 | # if !defined(HAVE_SECPOLICYPRIV_H) && defined(HAVE_SECPOLICYSETVALUE) /* Declare prototype for function in that header... */ | |
7cf5915e MS |
194 | extern OSStatus SecPolicySetValue(SecPolicyRef policyRef, |
195 | const CSSM_DATA *value); | |
07ed0e9a | 196 | # endif /* !HAVE_SECPOLICYPRIV_H && HAVE_SECPOLICYSETVALUE */ |
7cf5915e MS |
197 | |
198 | typedef SSLContextRef http_tls_t; | |
199 | typedef CFArrayRef http_tls_credentials_t; | |
ef416fc2 | 200 | |
cc754834 | 201 | # elif defined(HAVE_SSPISSL) |
07ed0e9a MS |
202 | /* |
203 | * Windows' SSPI library gets a CUPS wrapper... | |
204 | */ | |
205 | ||
7cf5915e MS |
206 | typedef _sspi_struct_t * http_tls_t; |
207 | typedef void *http_tls_credentials_t; | |
07ed0e9a | 208 | |
7cf5915e | 209 | # else |
07ed0e9a MS |
210 | /* |
211 | * Otherwise define stub types since we have no SSL support... | |
212 | */ | |
213 | ||
7cf5915e | 214 | typedef void *http_tls_t; |
07ed0e9a | 215 | typedef void *http_tls_credentials_t; |
724e1819 | 216 | # endif /* HAVE_GNUTLS */ |
ef416fc2 | 217 | |
a469f8a5 MS |
218 | typedef enum _http_coding_e /**** HTTP content coding enumeration ****/ |
219 | { | |
220 | _HTTP_CODING_IDENTITY, /* No content coding */ | |
221 | _HTTP_CODING_GZIP, /* LZ77+gzip decompression */ | |
222 | _HTTP_CODING_DEFLATE, /* LZ77+zlib compression */ | |
223 | _HTTP_CODING_GUNZIP, /* LZ77+gzip decompression */ | |
224 | _HTTP_CODING_INFLATE /* LZ77+zlib decompression */ | |
225 | } _http_coding_t; | |
226 | ||
227 | typedef enum _http_mode_e /**** HTTP mode enumeration ****/ | |
228 | { | |
229 | _HTTP_MODE_CLIENT, /* Client connected to server */ | |
230 | _HTTP_MODE_SERVER /* Server connected (accepted) from client */ | |
231 | } _http_mode_t; | |
232 | ||
5ec1fd3d | 233 | # ifndef _HTTP_NO_PRIVATE |
a469f8a5 | 234 | struct _http_s /**** HTTP connection structure ****/ |
f7deaa1a | 235 | { |
236 | int fd; /* File descriptor for this socket */ | |
237 | int blocking; /* To block or not to block */ | |
238 | int error; /* Last error on read */ | |
239 | time_t activity; /* Time since last read/write */ | |
240 | http_state_t state; /* State of client */ | |
241 | http_status_t status; /* Status of last request */ | |
242 | http_version_t version; /* Protocol version */ | |
243 | http_keepalive_t keep_alive; /* Keep-alive supported? */ | |
85dda01c | 244 | struct sockaddr_in _hostaddr; /* Address of connected host (deprecated) */ |
f7deaa1a | 245 | char hostname[HTTP_MAX_HOST], |
246 | /* Name of connected host */ | |
a469f8a5 MS |
247 | fields[HTTP_FIELD_ACCEPT_ENCODING][HTTP_MAX_VALUE]; |
248 | /* Field values up to Accept-Encoding */ | |
f7deaa1a | 249 | char *data; /* Pointer to data buffer */ |
250 | http_encoding_t data_encoding; /* Chunked or not */ | |
85dda01c | 251 | int _data_remaining;/* Number of bytes left (deprecated) */ |
f7deaa1a | 252 | int used; /* Number of bytes used in buffer */ |
253 | char buffer[HTTP_MAX_BUFFER]; | |
254 | /* Buffer for incoming data */ | |
5ec1fd3d | 255 | int _auth_type; /* Authentication in use (deprecated) */ |
f7deaa1a | 256 | _cups_md5_state_t md5_state; /* MD5 state */ |
257 | char nonce[HTTP_MAX_VALUE]; | |
258 | /* Nonce value */ | |
259 | int nonce_count; /* Nonce count */ | |
7cf5915e | 260 | http_tls_t tls; /* TLS state information */ |
f7deaa1a | 261 | http_encryption_t encryption; /* Encryption requirements */ |
a469f8a5 | 262 | |
f7deaa1a | 263 | /**** New in CUPS 1.1.19 ****/ |
85dda01c MS |
264 | fd_set *input_set; /* select() set for httpWait() (deprecated) */ |
265 | http_status_t expect; /* Expect: header */ | |
266 | char *cookie; /* Cookie value(s) */ | |
a469f8a5 | 267 | |
f7deaa1a | 268 | /**** New in CUPS 1.1.20 ****/ |
269 | char _authstring[HTTP_MAX_VALUE], | |
c1420c87 | 270 | /* Current Authorization value (deprecated) */ |
f7deaa1a | 271 | userpass[HTTP_MAX_VALUE]; |
85dda01c MS |
272 | /* Username:password string */ |
273 | int digest_tries; /* Number of tries for digest auth */ | |
a469f8a5 | 274 | |
f7deaa1a | 275 | /**** New in CUPS 1.2 ****/ |
85dda01c MS |
276 | off_t data_remaining; /* Number of bytes left */ |
277 | http_addr_t *hostaddr; /* Current host address and port */ | |
278 | http_addrlist_t *addrlist; /* List of valid addresses */ | |
f7deaa1a | 279 | char wbuffer[HTTP_MAX_BUFFER]; |
280 | /* Buffer for outgoing data */ | |
85dda01c | 281 | int wused; /* Write buffer bytes used */ |
a469f8a5 | 282 | |
f7deaa1a | 283 | /**** New in CUPS 1.3 ****/ |
284 | char *field_authorization; | |
85dda01c | 285 | /* Authorization field */ |
c1420c87 | 286 | char *authstring; /* Current Authorization field */ |
f7deaa1a | 287 | # ifdef HAVE_GSSAPI |
85dda01c MS |
288 | gss_OID gssmech; /* Authentication mechanism */ |
289 | gss_ctx_id_t gssctx; /* Authentication context */ | |
290 | gss_name_t gssname; /* Authentication server name */ | |
f7deaa1a | 291 | # endif /* HAVE_GSSAPI */ |
b94498cf | 292 | # ifdef HAVE_AUTHORIZATION_H |
85dda01c | 293 | AuthorizationRef auth_ref; /* Authorization ref */ |
b94498cf | 294 | # endif /* HAVE_AUTHORIZATION_H */ |
a469f8a5 | 295 | |
7cf5915e MS |
296 | /**** New in CUPS 1.5 ****/ |
297 | http_tls_credentials_t tls_credentials; | |
85dda01c MS |
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 */ | |
eac3a0a0 MS |
303 | # ifdef HAVE_GSSAPI |
304 | char gsshost[256]; /* Hostname for Kerberos */ | |
305 | # endif /* HAVE_GSSAPI */ | |
a469f8a5 MS |
306 | |
307 | /**** New in CUPS 1.7 ****/ | |
cb7f98ee | 308 | int tls_upgrade; /* Non-zero if we are doing an upgrade */ |
a469f8a5 MS |
309 | _http_mode_t mode; /* _HTTP_MODE_CLIENT or _HTTP_MODE_SERVER */ |
310 | char *accept_encoding, | |
311 | /* Accept-Encoding field */ | |
312 | *allow, /* Allow field */ | |
c1420c87 MS |
313 | *server, /* Server field */ |
314 | *default_accept_encoding, | |
315 | *default_server, | |
316 | *default_user_agent; | |
317 | /* Default field values */ | |
a469f8a5 MS |
318 | # ifdef HAVE_LIBZ |
319 | _http_coding_t coding; /* _HTTP_CODING_xxx */ | |
320 | z_stream stream; /* (De)compression stream */ | |
0fa6c7fa | 321 | Bytef *dbuffer; /* Decompression buffer */ |
a469f8a5 | 322 | # endif /* HAVE_LIBZ */ |
f7deaa1a | 323 | }; |
5ec1fd3d | 324 | # endif /* !_HTTP_NO_PRIVATE */ |
f7deaa1a | 325 | |
326 | ||
ef416fc2 | 327 | /* |
328 | * Some OS's don't have hstrerror(), most notably Solaris... | |
329 | */ | |
330 | ||
331 | # ifndef HAVE_HSTRERROR | |
332 | extern const char *_cups_hstrerror(int error); | |
333 | # define hstrerror _cups_hstrerror | |
ef416fc2 | 334 | # endif /* !HAVE_HSTRERROR */ |
335 | ||
89d46774 | 336 | |
337 | /* | |
338 | * Some OS's don't have getifaddrs() and freeifaddrs()... | |
339 | */ | |
340 | ||
07ed0e9a MS |
341 | # if !defined(WIN32) && !defined(HAVE_GETIFADDRS) |
342 | # ifdef ifa_dstaddr | |
343 | # undef ifa_dstaddr | |
344 | # endif /* ifa_dstaddr */ | |
345 | # ifndef ifr_netmask | |
346 | # define ifr_netmask ifr_addr | |
347 | # endif /* !ifr_netmask */ | |
89d46774 | 348 | |
349 | struct ifaddrs /**** Interface Structure ****/ | |
350 | { | |
351 | struct ifaddrs *ifa_next; /* Next interface in list */ | |
352 | char *ifa_name; /* Name of interface */ | |
353 | unsigned int ifa_flags; /* Flags (up, point-to-point, etc.) */ | |
354 | struct sockaddr *ifa_addr, /* Network address */ | |
f301802f | 355 | *ifa_netmask; /* Address mask */ |
356 | union | |
357 | { | |
358 | struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */ | |
359 | struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */ | |
360 | } ifa_ifu; | |
361 | ||
89d46774 | 362 | void *ifa_data; /* Interface statistics */ |
363 | }; | |
364 | ||
07ed0e9a MS |
365 | # ifndef ifa_broadaddr |
366 | # define ifa_broadaddr ifa_ifu.ifu_broadaddr | |
367 | # endif /* !ifa_broadaddr */ | |
368 | # ifndef ifa_dstaddr | |
369 | # define ifa_dstaddr ifa_ifu.ifu_dstaddr | |
370 | # endif /* !ifa_dstaddr */ | |
f301802f | 371 | |
a74454a7 | 372 | extern int _cups_getifaddrs(struct ifaddrs **addrs); |
07ed0e9a | 373 | # define getifaddrs _cups_getifaddrs |
a74454a7 | 374 | extern void _cups_freeifaddrs(struct ifaddrs *addrs); |
07ed0e9a MS |
375 | # define freeifaddrs _cups_freeifaddrs |
376 | # endif /* !WIN32 && !HAVE_GETIFADDRS */ | |
377 | ||
89d46774 | 378 | |
839a51c8 | 379 | /* |
1ff0402e | 380 | * Prototypes... |
839a51c8 MS |
381 | */ |
382 | ||
22c9029b | 383 | extern void _httpAddrSetPort(http_addr_t *addr, int port); |
85dda01c MS |
384 | extern http_tls_credentials_t |
385 | _httpCreateCredentials(cups_array_t *credentials); | |
1106b00e MS |
386 | extern char *_httpDecodeURI(char *dst, const char *src, |
387 | size_t dstsize); | |
6d2f911b | 388 | extern void _httpDisconnect(http_t *http); |
5eb9da71 MS |
389 | extern char *_httpEncodeURI(char *dst, const char *src, |
390 | size_t dstsize); | |
7cf5915e | 391 | extern void _httpFreeCredentials(http_tls_credentials_t credentials); |
5eb9da71 | 392 | extern const char *_httpResolveURI(const char *uri, char *resolved_uri, |
eac3a0a0 | 393 | size_t resolved_size, int options, |
07ed0e9a MS |
394 | int (*cb)(void *context), |
395 | void *context); | |
41e6c1f1 | 396 | extern const char *_httpStatus(cups_lang_t *lang, http_status_t status); |
e60ec91f | 397 | extern int _httpUpdate(http_t *http, http_status_t *status); |
38e73f87 | 398 | extern int _httpWait(http_t *http, int msec, int usessl); |
6d2f911b MS |
399 | |
400 | ||
07ed0e9a MS |
401 | /* |
402 | * C++ magic... | |
403 | */ | |
404 | ||
405 | # ifdef __cplusplus | |
406 | } | |
407 | # endif /* __cplusplus */ | |
408 | ||
ef416fc2 | 409 | #endif /* !_CUPS_HTTP_PRIVATE_H_ */ |
410 | ||
411 | /* | |
f2d18633 | 412 | * End of "$Id$". |
ef416fc2 | 413 | */ |