]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/http-private.h
Remove old private API.
[thirdparty/cups.git] / cups / http-private.h
CommitLineData
dd88778b 1/*
c9d3f842 2 * "$Id$"
dd88778b 3 *
3d94661a 4 * Private HTTP definitions for CUPS.
dd88778b 5 *
deda1b91 6 * Copyright 2007-2012 by Apple Inc.
d220c7b8 7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
dd88778b 8 *
9 * These coded instructions, statements, and computer programs are the
4e8d321f 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/".
dd88778b 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
3d94661a 25# include "config.h"
e7b6dd76 26# include <stddef.h>
425577ed 27# include <stdlib.h>
086c584d 28
0a0621ae 29# ifdef __sun
0a0621ae 30# include <sys/select.h>
31# endif /* __sun */
32
1a59b1c1 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
cf94bcb1 44# ifdef HAVE_GSSAPI
ec6e3e5a 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)
cf94bcb1 54# include <gssapi/gssapi.h>
ec6e3e5a 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)
cf94bcb1 62# include <gssapi.h>
ec6e3e5a 63# endif /* HAVE_GSS_GSSAPI_H */
8b3c3ab7 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 */
3b14922f 67# ifdef HAVE_KRB5_H
68# include <krb5.h>
69# endif /* HAVE_KRB5_H */
cf94bcb1 70# endif /* HAVE_GSSAPI */
71
f39a71fd 72# ifdef HAVE_AUTHORIZATION_H
73# include <Security/Authorization.h>
74# endif /* HAVE_AUTHORIZATION_H */
75
bb2fc480 76# if defined(__APPLE__) && !defined(_SOCKLEN_T)
bdb1331d 77/*
bb2fc480 78 * MacOS X 10.2.x does not define socklen_t, and in fact uses an int instead of
bdb1331d 79 * unsigned type for length values...
80 */
81
82typedef int socklen_t;
bb2fc480 83# endif /* __APPLE__ && !_SOCKLEN_T */
bdb1331d 84
3d94661a 85# include <cups/http.h>
86# include "md5-private.h"
b0a98a63 87# include "ipp-private.h"
0a0621ae 88
b1d20b15 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>
d4017d8c 101# ifdef HAVE_SECURETRANSPORTPRIV_H
102# include <Security/SecureTransportPriv.h>
103# endif /* HAVE_SECURETRANSPORTPRIV_H */
b1d20b15 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
2d3aac27 139# ifdef HAVE_LIBZ
140# include <zlib.h>
141# endif /* HAVE_LIBZ */
142
b1d20b15 143
144/*
145 * C++ magic...
146 */
147
148# ifdef __cplusplus
149extern "C" {
150# endif /* __cplusplus */
151
152
1c4d0a47 153/*
154 * Constants...
155 */
156
157
158#define _HTTP_RESOLVE_DEFAULT 0 /* Just resolve with default options */
159#define _HTTP_RESOLVE_STDERR 1 /* Log resolve progress to stderr */
160#define _HTTP_RESOLVE_FQDN 2 /* Resolve to a FQDN */
deda1b91 161#define _HTTP_RESOLVE_FAXOUT 4 /* Resolve FaxOut service? */
1c4d0a47 162
163
b1d20b15 164/*
165 * Types and functions for SSL support...
166 */
167
dd88778b 168# if defined HAVE_LIBSSL
169/*
170 * The OpenSSL library provides its own SSL/TLS context structure for its
38cf3b08 171 * IO and protocol management. However, we need to provide our own BIO
172 * (basic IO) implementation to do timeouts...
dd88778b 173 */
174
b9738d7c 175typedef SSL *http_tls_t;
176typedef void *http_tls_credentials_t;
dd88778b 177
38cf3b08 178extern BIO_METHOD *_httpBIOMethods(void);
179
dd88778b 180# elif defined HAVE_GNUTLS
181/*
182 * The GNU TLS library is more of a "bare metal" SSL/TLS library...
183 */
dd88778b 184
b9738d7c 185typedef gnutls_session http_tls_t;
186typedef void *http_tls_credentials_t;
dd88778b 187
d774b661 188extern ssize_t _httpReadGNUTLS(gnutls_transport_ptr ptr, void *data,
189 size_t length);
190extern ssize_t _httpWriteGNUTLS(gnutls_transport_ptr ptr, const void *data,
191 size_t length);
192
dcfcaeac 193# elif defined(HAVE_CDSASSL)
194/*
195 * Darwin's Security framework provides its own SSL/TLS context structure
196 * for its IO and protocol management...
197 */
198
b1d20b15 199# if !defined(HAVE_SECBASEPRIV_H) && defined(HAVE_CSSMERRORSTRING) /* Declare prototype for function in that header... */
b9738d7c 200extern const char *cssmErrorString(int error);
b1d20b15 201# endif /* !HAVE_SECBASEPRIV_H && HAVE_CSSMERRORSTRING */
202# ifndef HAVE_SECITEMPRIV_H /* Declare constants from that header... */
b9738d7c 203extern const CFTypeRef kSecClassCertificate;
204extern const CFTypeRef kSecClassIdentity;
b1d20b15 205# endif /* !HAVE_SECITEMPRIV_H */
206# if !defined(HAVE_SECIDENTITYSEARCHPRIV_H) && defined(HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY) /* Declare prototype for function in that header... */
b9738d7c 207extern OSStatus SecIdentitySearchCreateWithPolicy(SecPolicyRef policy,
208 CFStringRef idString, CSSM_KEYUSE keyUsage,
209 CFTypeRef keychainOrArray,
210 Boolean returnOnlyValidIdentities,
211 SecIdentitySearchRef* searchRef);
b1d20b15 212# endif /* !HAVE_SECIDENTITYSEARCHPRIV_H && HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY */
213# if !defined(HAVE_SECPOLICYPRIV_H) && defined(HAVE_SECPOLICYSETVALUE) /* Declare prototype for function in that header... */
b9738d7c 214extern OSStatus SecPolicySetValue(SecPolicyRef policyRef,
215 const CSSM_DATA *value);
b1d20b15 216# endif /* !HAVE_SECPOLICYPRIV_H && HAVE_SECPOLICYSETVALUE */
b9738d7c 217
218typedef SSLContextRef http_tls_t;
219typedef CFArrayRef http_tls_credentials_t;
dcfcaeac 220
fe3f3c8c 221extern OSStatus _httpReadCDSA(SSLConnectionRef connection, void *data,
222 size_t *dataLength);
223extern OSStatus _httpWriteCDSA(SSLConnectionRef connection, const void *data,
224 size_t *dataLength);
6875feac 225
226# elif defined(HAVE_SSPISSL)
b1d20b15 227/*
228 * Windows' SSPI library gets a CUPS wrapper...
229 */
230
b9738d7c 231typedef _sspi_struct_t * http_tls_t;
232typedef void *http_tls_credentials_t;
b1d20b15 233
b9738d7c 234# else
b1d20b15 235/*
236 * Otherwise define stub types since we have no SSL support...
237 */
238
b9738d7c 239typedef void *http_tls_t;
97d5667d 240typedef void *http_tls_credentials_t;
dd88778b 241# endif /* HAVE_LIBSSL */
2d417cb3 242
2d3aac27 243typedef enum _http_coding_e /**** HTTP content coding enumeration ****/
244{
245 _HTTP_CODING_IDENTITY, /* No content coding */
246 _HTTP_CODING_GZIP, /* LZ77+gzip decompression */
247 _HTTP_CODING_DEFLATE, /* LZ77+zlib compression */
248 _HTTP_CODING_GUNZIP, /* LZ77+gzip decompression */
249 _HTTP_CODING_INFLATE /* LZ77+zlib decompression */
250} _http_coding_t;
251
252typedef enum _http_mode_e /**** HTTP mode enumeration ****/
253{
254 _HTTP_MODE_CLIENT, /* Client connected to server */
255 _HTTP_MODE_SERVER /* Server connected (accepted) from client */
256} _http_mode_t;
257
258struct _http_s /**** HTTP connection structure ****/
72510b94 259{
260 int fd; /* File descriptor for this socket */
261 int blocking; /* To block or not to block */
262 int error; /* Last error on read */
263 time_t activity; /* Time since last read/write */
264 http_state_t state; /* State of client */
265 http_status_t status; /* Status of last request */
266 http_version_t version; /* Protocol version */
267 http_keepalive_t keep_alive; /* Keep-alive supported? */
ce9290e8 268 struct sockaddr_in _hostaddr; /* Address of connected host (deprecated) */
72510b94 269 char hostname[HTTP_MAX_HOST],
270 /* Name of connected host */
2d3aac27 271 fields[HTTP_FIELD_ACCEPT_ENCODING][HTTP_MAX_VALUE];
272 /* Field values up to Accept-Encoding */
72510b94 273 char *data; /* Pointer to data buffer */
274 http_encoding_t data_encoding; /* Chunked or not */
ce9290e8 275 int _data_remaining;/* Number of bytes left (deprecated) */
72510b94 276 int used; /* Number of bytes used in buffer */
277 char buffer[HTTP_MAX_BUFFER];
278 /* Buffer for incoming data */
279 int auth_type; /* Authentication in use */
280 _cups_md5_state_t md5_state; /* MD5 state */
281 char nonce[HTTP_MAX_VALUE];
282 /* Nonce value */
283 int nonce_count; /* Nonce count */
b9738d7c 284 http_tls_t tls; /* TLS state information */
72510b94 285 http_encryption_t encryption; /* Encryption requirements */
2d3aac27 286
72510b94 287 /**** New in CUPS 1.1.19 ****/
ce9290e8 288 fd_set *input_set; /* select() set for httpWait() (deprecated) */
289 http_status_t expect; /* Expect: header */
290 char *cookie; /* Cookie value(s) */
2d3aac27 291
72510b94 292 /**** New in CUPS 1.1.20 ****/
cf94bcb1 293 char _authstring[HTTP_MAX_VALUE],
ce9290e8 294 /* Current Authentication value (deprecated) */
72510b94 295 userpass[HTTP_MAX_VALUE];
ce9290e8 296 /* Username:password string */
297 int digest_tries; /* Number of tries for digest auth */
2d3aac27 298
72510b94 299 /**** New in CUPS 1.2 ****/
ce9290e8 300 off_t data_remaining; /* Number of bytes left */
301 http_addr_t *hostaddr; /* Current host address and port */
302 http_addrlist_t *addrlist; /* List of valid addresses */
72510b94 303 char wbuffer[HTTP_MAX_BUFFER];
304 /* Buffer for outgoing data */
ce9290e8 305 int wused; /* Write buffer bytes used */
2d3aac27 306
cf94bcb1 307 /**** New in CUPS 1.3 ****/
308 char *field_authorization;
ce9290e8 309 /* Authorization field */
310 char *authstring; /* Current authorization field */
cf94bcb1 311# ifdef HAVE_GSSAPI
ce9290e8 312 gss_OID gssmech; /* Authentication mechanism */
313 gss_ctx_id_t gssctx; /* Authentication context */
314 gss_name_t gssname; /* Authentication server name */
cf94bcb1 315# endif /* HAVE_GSSAPI */
f39a71fd 316# ifdef HAVE_AUTHORIZATION_H
ce9290e8 317 AuthorizationRef auth_ref; /* Authorization ref */
f39a71fd 318# endif /* HAVE_AUTHORIZATION_H */
2d3aac27 319
b9738d7c 320 /**** New in CUPS 1.5 ****/
321 http_tls_credentials_t tls_credentials;
ce9290e8 322 /* TLS credentials */
323 http_timeout_cb_t timeout_cb; /* Timeout callback */
324 void *timeout_data; /* User data pointer */
325 double timeout_value; /* Timeout in seconds */
326 int wait_value; /* httpWait value for timeout */
ec6e3e5a 327# ifdef HAVE_GSSAPI
328 char gsshost[256]; /* Hostname for Kerberos */
329# endif /* HAVE_GSSAPI */
2d3aac27 330
331 /**** New in CUPS 1.7 ****/
332 _http_mode_t mode; /* _HTTP_MODE_CLIENT or _HTTP_MODE_SERVER */
333 char *accept_encoding,
334 /* Accept-Encoding field */
335 *allow, /* Allow field */
336 *server; /* Server field */
337# ifdef HAVE_LIBZ
338 _http_coding_t coding; /* _HTTP_CODING_xxx */
339 z_stream stream; /* (De)compression stream */
340# endif /* HAVE_LIBZ */
72510b94 341};
342
343
2d417cb3 344/*
345 * Some OS's don't have hstrerror(), most notably Solaris...
346 */
347
348# ifndef HAVE_HSTRERROR
2625096f 349extern const char *_cups_hstrerror(int error);
350# define hstrerror _cups_hstrerror
1159efaa 351# elif defined(_AIX) || defined(__osf__)
2d417cb3 352/*
1159efaa 353 * AIX and Tru64 UNIX don't provide a prototype but do provide the function...
2d417cb3 354 */
355extern const char *hstrerror(int error);
356# endif /* !HAVE_HSTRERROR */
357
846f45a0 358
359/*
360 * Some OS's don't have getifaddrs() and freeifaddrs()...
361 */
362
b1d20b15 363# if !defined(WIN32) && !defined(HAVE_GETIFADDRS)
364# ifdef ifa_dstaddr
365# undef ifa_dstaddr
366# endif /* ifa_dstaddr */
367# ifndef ifr_netmask
368# define ifr_netmask ifr_addr
369# endif /* !ifr_netmask */
846f45a0 370
371struct ifaddrs /**** Interface Structure ****/
372{
373 struct ifaddrs *ifa_next; /* Next interface in list */
374 char *ifa_name; /* Name of interface */
375 unsigned int ifa_flags; /* Flags (up, point-to-point, etc.) */
376 struct sockaddr *ifa_addr, /* Network address */
7671e38d 377 *ifa_netmask; /* Address mask */
378 union
379 {
380 struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */
381 struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */
382 } ifa_ifu;
383
846f45a0 384 void *ifa_data; /* Interface statistics */
385};
386
b1d20b15 387# ifndef ifa_broadaddr
388# define ifa_broadaddr ifa_ifu.ifu_broadaddr
389# endif /* !ifa_broadaddr */
390# ifndef ifa_dstaddr
391# define ifa_dstaddr ifa_ifu.ifu_dstaddr
392# endif /* !ifa_dstaddr */
7671e38d 393
425577ed 394extern int _cups_getifaddrs(struct ifaddrs **addrs);
b1d20b15 395# define getifaddrs _cups_getifaddrs
425577ed 396extern void _cups_freeifaddrs(struct ifaddrs *addrs);
b1d20b15 397# define freeifaddrs _cups_freeifaddrs
398# endif /* !WIN32 && !HAVE_GETIFADDRS */
399
846f45a0 400
96fa6605 401/*
bb235d9a 402 * Prototypes...
96fa6605 403 */
404
f0aa54a1 405#define _httpAddrFamily(addrp) (addrp)->addr.sa_family
f0aa54a1 406extern void _httpAddrSetPort(http_addr_t *addr, int port);
fc4935ca 407extern char *_httpAssembleUUID(const char *server, int port,
408 const char *name, int number,
409 char *buffer, size_t bufsize);
9217ee14 410extern http_t *_httpCreate(const char *host, int port,
2d3aac27 411 http_addrlist_t *addrlist, int family,
cce0044f 412 http_encryption_t encryption,
2d3aac27 413 int blocking, _http_mode_t mode);
4fee0aad 414extern http_tls_credentials_t
415 _httpCreateCredentials(cups_array_t *credentials);
e491fdbc 416extern char *_httpDecodeURI(char *dst, const char *src,
417 size_t dstsize);
fa7e8544 418extern void _httpDisconnect(http_t *http);
012d7a28 419extern char *_httpEncodeURI(char *dst, const char *src,
420 size_t dstsize);
b9738d7c 421extern void _httpFreeCredentials(http_tls_credentials_t credentials);
012d7a28 422extern const char *_httpResolveURI(const char *uri, char *resolved_uri,
1c4d0a47 423 size_t resolved_size, int options,
71fa6b56 424 int (*cb)(void *context),
425 void *context);
205bf9e8 426extern int _httpUpdate(http_t *http, http_status_t *status);
da97a504 427extern int _httpWait(http_t *http, int msec, int usessl);
fa7e8544 428
429
b1d20b15 430/*
431 * C++ magic...
432 */
433
434# ifdef __cplusplus
435}
436# endif /* __cplusplus */
437
dd88778b 438#endif /* !_CUPS_HTTP_PRIVATE_H_ */
439
440/*
c9d3f842 441 * End of "$Id$".
dd88778b 442 */