]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/http-private.h
Remove ".orig" files that somehow got into the repo.
[thirdparty/cups.git] / cups / http-private.h
CommitLineData
ef416fc2 1/*
b19ccc9e 2 * "$Id: http-private.h 7850 2008-08-20 00:07:25Z mike $"
ef416fc2 3 *
71e16022 4 * Private HTTP definitions for CUPS.
ef416fc2 5 *
07ed0e9a 6 * Copyright 2007-2011 by Apple Inc.
b86bc4cf 7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 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 *
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
71e16022 25# include "config.h"
5180a04c 26# include <stddef.h>
a74454a7 27# include <stdlib.h>
ef416fc2 28
29# ifdef __sun
ef416fc2 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
f7deaa1a 44# ifdef HAVE_GSSAPI
eac3a0a0
MS
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)
f7deaa1a 54# include <gssapi/gssapi.h>
eac3a0a0
MS
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)
f7deaa1a 62# include <gssapi.h>
eac3a0a0 63# endif /* HAVE_GSS_GSSAPI_H */
f7deaa1a 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 */
db1f069b
MS
67# ifdef HAVE_KRB5_H
68# include <krb5.h>
69# endif /* HAVE_KRB5_H */
f7deaa1a 70# endif /* HAVE_GSSAPI */
71
b94498cf 72# ifdef HAVE_AUTHORIZATION_H
73# include <Security/Authorization.h>
74# endif /* HAVE_AUTHORIZATION_H */
75
4400e98d 76# if defined(__sgi) || (defined(__APPLE__) && !defined(_SOCKLEN_T))
ef416fc2 77/*
4400e98d 78 * IRIX and MacOS X 10.2.x do not define socklen_t, and in fact use an int instead of
ef416fc2 79 * unsigned type for length values...
80 */
81
82typedef int socklen_t;
4400e98d 83# endif /* __sgi || (__APPLE__ && !_SOCKLEN_T) */
ef416fc2 84
71e16022
MS
85# include <cups/http.h>
86# include "md5-private.h"
fa73b229 87# include "ipp-private.h"
ef416fc2 88
07ed0e9a
MS
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>
96# include <gcrypt.h>
97# elif defined(HAVE_CDSASSL)
98# include <CoreFoundation/CoreFoundation.h>
99# include <Security/Security.h>
100# include <Security/SecureTransport.h>
eac3a0a0
MS
101# ifdef HAVE_SECURETRANSPORTPRIV_H
102# include <Security/SecureTransportPriv.h>
103# endif /* HAVE_SECURETRANSPORTPRIV_H */
07ed0e9a
MS
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 */
126
127# ifndef WIN32
128# include <net/if.h>
129# ifdef HAVE_GETIFADDRS
130# include <ifaddrs.h>
131# else
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 */
137# endif /* !WIN32 */
138
139
140/*
141 * C++ magic...
142 */
143
144# ifdef __cplusplus
145extern "C" {
146# endif /* __cplusplus */
147
148
eac3a0a0
MS
149/*
150 * Constants...
151 */
152
153
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
158
07ed0e9a
MS
159/*
160 * Types and functions for SSL support...
161 */
162
ef416fc2 163# if defined HAVE_LIBSSL
164/*
165 * The OpenSSL library provides its own SSL/TLS context structure for its
411affcf 166 * IO and protocol management. However, we need to provide our own BIO
167 * (basic IO) implementation to do timeouts...
ef416fc2 168 */
169
7cf5915e
MS
170typedef SSL *http_tls_t;
171typedef void *http_tls_credentials_t;
ef416fc2 172
411affcf 173extern BIO_METHOD *_httpBIOMethods(void);
174
ef416fc2 175# elif defined HAVE_GNUTLS
176/*
177 * The GNU TLS library is more of a "bare metal" SSL/TLS library...
178 */
ef416fc2 179
7cf5915e
MS
180typedef gnutls_session http_tls_t;
181typedef void *http_tls_credentials_t;
ef416fc2 182
411affcf 183extern ssize_t _httpReadGNUTLS(gnutls_transport_ptr ptr, void *data,
184 size_t length);
185extern ssize_t _httpWriteGNUTLS(gnutls_transport_ptr ptr, const void *data,
186 size_t length);
187
ef416fc2 188# elif defined(HAVE_CDSASSL)
189/*
190 * Darwin's Security framework provides its own SSL/TLS context structure
191 * for its IO and protocol management...
192 */
193
07ed0e9a 194# if !defined(HAVE_SECBASEPRIV_H) && defined(HAVE_CSSMERRORSTRING) /* Declare prototype for function in that header... */
7cf5915e 195extern const char *cssmErrorString(int error);
07ed0e9a
MS
196# endif /* !HAVE_SECBASEPRIV_H && HAVE_CSSMERRORSTRING */
197# ifndef HAVE_SECITEMPRIV_H /* Declare constants from that header... */
7cf5915e
MS
198extern const CFTypeRef kSecClassCertificate;
199extern const CFTypeRef kSecClassIdentity;
07ed0e9a
MS
200# endif /* !HAVE_SECITEMPRIV_H */
201# if !defined(HAVE_SECIDENTITYSEARCHPRIV_H) && defined(HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY) /* Declare prototype for function in that header... */
7cf5915e
MS
202extern OSStatus SecIdentitySearchCreateWithPolicy(SecPolicyRef policy,
203 CFStringRef idString, CSSM_KEYUSE keyUsage,
204 CFTypeRef keychainOrArray,
205 Boolean returnOnlyValidIdentities,
206 SecIdentitySearchRef* searchRef);
07ed0e9a
MS
207# endif /* !HAVE_SECIDENTITYSEARCHPRIV_H && HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY */
208# if !defined(HAVE_SECPOLICYPRIV_H) && defined(HAVE_SECPOLICYSETVALUE) /* Declare prototype for function in that header... */
7cf5915e
MS
209extern OSStatus SecPolicySetValue(SecPolicyRef policyRef,
210 const CSSM_DATA *value);
07ed0e9a 211# endif /* !HAVE_SECPOLICYPRIV_H && HAVE_SECPOLICYSETVALUE */
7cf5915e
MS
212
213typedef SSLContextRef http_tls_t;
214typedef CFArrayRef http_tls_credentials_t;
ef416fc2 215
216extern OSStatus _httpReadCDSA(SSLConnectionRef connection, void *data,
217 size_t *dataLength);
218extern OSStatus _httpWriteCDSA(SSLConnectionRef connection, const void *data,
219 size_t *dataLength);
cc754834
MS
220
221# elif defined(HAVE_SSPISSL)
07ed0e9a
MS
222/*
223 * Windows' SSPI library gets a CUPS wrapper...
224 */
225
7cf5915e
MS
226typedef _sspi_struct_t * http_tls_t;
227typedef void *http_tls_credentials_t;
07ed0e9a 228
7cf5915e 229# else
07ed0e9a
MS
230/*
231 * Otherwise define stub types since we have no SSL support...
232 */
233
7cf5915e 234typedef void *http_tls_t;
07ed0e9a 235typedef void *http_tls_credentials_t;
ef416fc2 236# endif /* HAVE_LIBSSL */
237
f7deaa1a 238struct _http_s /**** HTTP connection structure. ****/
239{
240 int fd; /* File descriptor for this socket */
241 int blocking; /* To block or not to block */
242 int error; /* Last error on read */
243 time_t activity; /* Time since last read/write */
244 http_state_t state; /* State of client */
245 http_status_t status; /* Status of last request */
246 http_version_t version; /* Protocol version */
247 http_keepalive_t keep_alive; /* Keep-alive supported? */
85dda01c 248 struct sockaddr_in _hostaddr; /* Address of connected host (deprecated) */
f7deaa1a 249 char hostname[HTTP_MAX_HOST],
250 /* Name of connected host */
251 fields[HTTP_FIELD_MAX][HTTP_MAX_VALUE];
252 /* Field values */
253 char *data; /* Pointer to data buffer */
254 http_encoding_t data_encoding; /* Chunked or not */
85dda01c 255 int _data_remaining;/* Number of bytes left (deprecated) */
f7deaa1a 256 int used; /* Number of bytes used in buffer */
257 char buffer[HTTP_MAX_BUFFER];
258 /* Buffer for incoming data */
259 int auth_type; /* Authentication in use */
260 _cups_md5_state_t md5_state; /* MD5 state */
261 char nonce[HTTP_MAX_VALUE];
262 /* Nonce value */
263 int nonce_count; /* Nonce count */
7cf5915e 264 http_tls_t tls; /* TLS state information */
f7deaa1a 265 http_encryption_t encryption; /* Encryption requirements */
266 /**** New in CUPS 1.1.19 ****/
85dda01c
MS
267 fd_set *input_set; /* select() set for httpWait() (deprecated) */
268 http_status_t expect; /* Expect: header */
269 char *cookie; /* Cookie value(s) */
f7deaa1a 270 /**** New in CUPS 1.1.20 ****/
271 char _authstring[HTTP_MAX_VALUE],
85dda01c 272 /* Current Authentication value (deprecated) */
f7deaa1a 273 userpass[HTTP_MAX_VALUE];
85dda01c
MS
274 /* Username:password string */
275 int digest_tries; /* Number of tries for digest auth */
f7deaa1a 276 /**** New in CUPS 1.2 ****/
85dda01c
MS
277 off_t data_remaining; /* Number of bytes left */
278 http_addr_t *hostaddr; /* Current host address and port */
279 http_addrlist_t *addrlist; /* List of valid addresses */
f7deaa1a 280 char wbuffer[HTTP_MAX_BUFFER];
281 /* Buffer for outgoing data */
85dda01c 282 int wused; /* Write buffer bytes used */
f7deaa1a 283 /**** New in CUPS 1.3 ****/
284 char *field_authorization;
85dda01c
MS
285 /* Authorization field */
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 */
7cf5915e
MS
295 /**** New in CUPS 1.5 ****/
296 http_tls_credentials_t tls_credentials;
85dda01c
MS
297 /* TLS credentials */
298 http_timeout_cb_t timeout_cb; /* Timeout callback */
299 void *timeout_data; /* User data pointer */
300 double timeout_value; /* Timeout in seconds */
301 int wait_value; /* httpWait value for timeout */
eac3a0a0
MS
302# ifdef HAVE_GSSAPI
303 char gsshost[256]; /* Hostname for Kerberos */
304# endif /* HAVE_GSSAPI */
f7deaa1a 305};
306
307
ef416fc2 308/*
309 * Some OS's don't have hstrerror(), most notably Solaris...
310 */
311
312# ifndef HAVE_HSTRERROR
313extern const char *_cups_hstrerror(int error);
314# define hstrerror _cups_hstrerror
315# elif defined(_AIX) || defined(__osf__)
316/*
317 * AIX and Tru64 UNIX don't provide a prototype but do provide the function...
318 */
319extern const char *hstrerror(int error);
320# endif /* !HAVE_HSTRERROR */
321
89d46774 322
323/*
324 * Some OS's don't have getifaddrs() and freeifaddrs()...
325 */
326
07ed0e9a
MS
327# if !defined(WIN32) && !defined(HAVE_GETIFADDRS)
328# ifdef ifa_dstaddr
329# undef ifa_dstaddr
330# endif /* ifa_dstaddr */
331# ifndef ifr_netmask
332# define ifr_netmask ifr_addr
333# endif /* !ifr_netmask */
89d46774 334
335struct ifaddrs /**** Interface Structure ****/
336{
337 struct ifaddrs *ifa_next; /* Next interface in list */
338 char *ifa_name; /* Name of interface */
339 unsigned int ifa_flags; /* Flags (up, point-to-point, etc.) */
340 struct sockaddr *ifa_addr, /* Network address */
f301802f 341 *ifa_netmask; /* Address mask */
342 union
343 {
344 struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */
345 struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */
346 } ifa_ifu;
347
89d46774 348 void *ifa_data; /* Interface statistics */
349};
350
07ed0e9a
MS
351# ifndef ifa_broadaddr
352# define ifa_broadaddr ifa_ifu.ifu_broadaddr
353# endif /* !ifa_broadaddr */
354# ifndef ifa_dstaddr
355# define ifa_dstaddr ifa_ifu.ifu_dstaddr
356# endif /* !ifa_dstaddr */
f301802f 357
a74454a7 358extern int _cups_getifaddrs(struct ifaddrs **addrs);
07ed0e9a 359# define getifaddrs _cups_getifaddrs
a74454a7 360extern void _cups_freeifaddrs(struct ifaddrs *addrs);
07ed0e9a
MS
361# define freeifaddrs _cups_freeifaddrs
362# endif /* !WIN32 && !HAVE_GETIFADDRS */
363
89d46774 364
839a51c8 365/*
1ff0402e 366 * Prototypes...
839a51c8
MS
367 */
368
22c9029b 369#define _httpAddrFamily(addrp) (addrp)->addr.sa_family
1ff0402e 370extern int _httpAddrPort(http_addr_t *addr);
22c9029b 371extern void _httpAddrSetPort(http_addr_t *addr, int port);
07ed0e9a
MS
372extern char *_httpAssembleUUID(const char *server, int port,
373 const char *name, int number,
374 char *buffer, size_t bufsize);
1ff0402e 375extern http_t *_httpCreate(const char *host, int port,
c8fef167
MS
376 http_addrlist_t *addrlist,
377 http_encryption_t encryption,
1106b00e 378 int family);
85dda01c
MS
379extern http_tls_credentials_t
380 _httpCreateCredentials(cups_array_t *credentials);
1106b00e
MS
381extern char *_httpDecodeURI(char *dst, const char *src,
382 size_t dstsize);
6d2f911b 383extern void _httpDisconnect(http_t *http);
5eb9da71
MS
384extern char *_httpEncodeURI(char *dst, const char *src,
385 size_t dstsize);
7cf5915e 386extern void _httpFreeCredentials(http_tls_credentials_t credentials);
6d2f911b 387extern ssize_t _httpPeek(http_t *http, char *buffer, size_t length);
5eb9da71 388extern const char *_httpResolveURI(const char *uri, char *resolved_uri,
eac3a0a0 389 size_t resolved_size, int options,
07ed0e9a
MS
390 int (*cb)(void *context),
391 void *context);
e60ec91f 392extern int _httpUpdate(http_t *http, http_status_t *status);
38e73f87 393extern int _httpWait(http_t *http, int msec, int usessl);
6d2f911b
MS
394
395
07ed0e9a
MS
396/*
397 * C++ magic...
398 */
399
400# ifdef __cplusplus
401}
402# endif /* __cplusplus */
403
ef416fc2 404#endif /* !_CUPS_HTTP_PRIVATE_H_ */
405
406/*
b19ccc9e 407 * End of "$Id: http-private.h 7850 2008-08-20 00:07:25Z mike $".
ef416fc2 408 */