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
;
95 extern BIO_METHOD
*_httpBIOMethods(void);
97 # elif defined HAVE_GNUTLS
99 * The GNU TLS library is more of a "bare metal" SSL/TLS library...
101 # include <gnutls/gnutls.h>
106 gnutls_session session
; /* GNU TLS session object */
107 void *credentials
; /* GNU TLS credentials object */
110 extern ssize_t
_httpReadGNUTLS(gnutls_transport_ptr ptr
, void *data
,
112 extern ssize_t
_httpWriteGNUTLS(gnutls_transport_ptr ptr
, const void *data
,
115 # elif defined(HAVE_CDSASSL)
117 * Darwin's Security framework provides its own SSL/TLS context structure
118 * for its IO and protocol management...
121 # include <Security/SecureTransport.h>
123 typedef struct /**** CDSA connection information ****/
125 SSLContextRef session
; /* CDSA session object */
126 CFArrayRef certsArray
; /* Certificates array */
129 extern OSStatus
_httpReadCDSA(SSLConnectionRef connection
, void *data
,
131 extern OSStatus
_httpWriteCDSA(SSLConnectionRef connection
, const void *data
,
134 # elif defined(HAVE_SSPISSL)
135 # include "sspi-private.h"
136 # endif /* HAVE_LIBSSL */
139 struct _http_s
/**** HTTP connection structure. ****/
141 int fd
; /* File descriptor for this socket */
142 int blocking
; /* To block or not to block */
143 int error
; /* Last error on read */
144 time_t activity
; /* Time since last read/write */
145 http_state_t state
; /* State of client */
146 http_status_t status
; /* Status of last request */
147 http_version_t version
; /* Protocol version */
148 http_keepalive_t keep_alive
; /* Keep-alive supported? */
149 struct sockaddr_in _hostaddr
; /* Address of connected host @deprecated@ */
150 char hostname
[HTTP_MAX_HOST
],
151 /* Name of connected host */
152 fields
[HTTP_FIELD_MAX
][HTTP_MAX_VALUE
];
154 char *data
; /* Pointer to data buffer */
155 http_encoding_t data_encoding
; /* Chunked or not */
156 int _data_remaining
;/* Number of bytes left @deprecated@ */
157 int used
; /* Number of bytes used in buffer */
158 char buffer
[HTTP_MAX_BUFFER
];
159 /* Buffer for incoming data */
160 int auth_type
; /* Authentication in use */
161 _cups_md5_state_t md5_state
; /* MD5 state */
162 char nonce
[HTTP_MAX_VALUE
];
164 int nonce_count
; /* Nonce count */
165 void *tls
; /* TLS state information */
166 http_encryption_t encryption
; /* Encryption requirements */
167 /**** New in CUPS 1.1.19 ****/
168 fd_set
*input_set
; /* select() set for httpWait() @deprecated@ */
169 http_status_t expect
; /* Expect: header @since CUPS 1.1.19@ */
170 char *cookie
; /* Cookie value(s) @since CUPS 1.1.19@ */
171 /**** New in CUPS 1.1.20 ****/
172 char _authstring
[HTTP_MAX_VALUE
],
173 /* Current Authentication value. @deprecated@ */
174 userpass
[HTTP_MAX_VALUE
];
175 /* Username:password string @since CUPS 1.1.20@ */
176 int digest_tries
; /* Number of tries for digest auth @since CUPS 1.1.20@ */
177 /**** New in CUPS 1.2 ****/
178 off_t data_remaining
; /* Number of bytes left @since CUPS 1.2@ */
179 http_addr_t
*hostaddr
; /* Current host address and port @since CUPS 1.2@ */
180 http_addrlist_t
*addrlist
; /* List of valid addresses @since CUPS 1.2@ */
181 char wbuffer
[HTTP_MAX_BUFFER
];
182 /* Buffer for outgoing data */
183 int wused
; /* Write buffer bytes used @since CUPS 1.2@ */
184 /**** New in CUPS 1.3 ****/
185 char *field_authorization
;
186 /* Authorization field @since CUPS 1.3@ */
187 char *authstring
; /* Current authorization field @since CUPS 1.3 */
189 gss_OID gssmech
; /* Authentication mechanism @since CUPS 1.3@ */
190 gss_ctx_id_t gssctx
; /* Authentication context @since CUPS 1.3@ */
191 gss_name_t gssname
; /* Authentication server name @since CUPS 1.3@ */
192 # endif /* HAVE_GSSAPI */
193 # ifdef HAVE_AUTHORIZATION_H
194 AuthorizationRef auth_ref
; /* Authorization ref */
195 # endif /* HAVE_AUTHORIZATION_H */
200 * Some OS's don't have hstrerror(), most notably Solaris...
203 # ifndef HAVE_HSTRERROR
204 extern const char *_cups_hstrerror(int error
);
205 # define hstrerror _cups_hstrerror
206 # elif defined(_AIX) || defined(__osf__)
208 * AIX and Tru64 UNIX don't provide a prototype but do provide the function...
210 extern const char *hstrerror(int error
);
211 # endif /* !HAVE_HSTRERROR */
215 * Some OS's don't have getifaddrs() and freeifaddrs()...
220 # ifdef HAVE_GETIFADDRS
221 # include <ifaddrs.h>
223 # include <sys/ioctl.h>
224 # ifdef HAVE_SYS_SOCKIO_H
225 # include <sys/sockio.h>
226 # endif /* HAVE_SYS_SOCKIO_H */
230 # endif /* ifa_dstaddr */
232 # define ifr_netmask ifr_addr
233 # endif /* !ifr_netmask */
235 struct ifaddrs
/**** Interface Structure ****/
237 struct ifaddrs
*ifa_next
; /* Next interface in list */
238 char *ifa_name
; /* Name of interface */
239 unsigned int ifa_flags
; /* Flags (up, point-to-point, etc.) */
240 struct sockaddr
*ifa_addr
, /* Network address */
241 *ifa_netmask
; /* Address mask */
244 struct sockaddr
*ifu_broadaddr
; /* Broadcast address of this interface. */
245 struct sockaddr
*ifu_dstaddr
; /* Point-to-point destination address. */
248 void *ifa_data
; /* Interface statistics */
251 # ifndef ifa_broadaddr
252 # define ifa_broadaddr ifa_ifu.ifu_broadaddr
253 # endif /* !ifa_broadaddr */
255 # define ifa_dstaddr ifa_ifu.ifu_dstaddr
256 # endif /* !ifa_dstaddr */
258 extern int _cups_getifaddrs(struct ifaddrs
**addrs
);
259 # define getifaddrs _cups_getifaddrs
260 extern void _cups_freeifaddrs(struct ifaddrs
*addrs
);
261 # define freeifaddrs _cups_freeifaddrs
262 # endif /* HAVE_GETIFADDRS */
269 extern int _httpAddrPort(http_addr_t
*addr
);
270 extern http_t
*_httpCreate(const char *host
, int port
,
271 http_encryption_t encryption
);
272 extern void _httpDisconnect(http_t
*http
);
273 extern char *_httpEncodeURI(char *dst
, const char *src
,
275 extern ssize_t
_httpPeek(http_t
*http
, char *buffer
, size_t length
);
276 extern const char *_httpResolveURI(const char *uri
, char *resolved_uri
,
277 size_t resolved_size
, int log
);
278 extern int _httpWait(http_t
*http
, int msec
, int usessl
);
281 #endif /* !_CUPS_HTTP_PRIVATE_H_ */
284 * End of "$Id: http-private.h 7850 2008-08-20 00:07:25Z mike $".