jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 1 | /* |
msweet | 2e4ff8a | 2007-10-17 20:05:25 +0000 | [diff] [blame] | 2 | * "$Id: http-private.h 6933 2007-09-10 16:45:59Z mike $" |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 3 | * |
| 4 | * Private HTTP definitions for the Common UNIX Printing System (CUPS). |
| 5 | * |
jlovell | bc44d92 | 2007-07-16 23:34:09 +0000 | [diff] [blame] | 6 | * Copyright 2007 by Apple Inc. |
jlovell | b86bc4c | 2007-02-14 19:18:46 +0000 | [diff] [blame] | 7 | * Copyright 1997-2007 by Easy Software Products, all rights reserved. |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 8 | * |
| 9 | * These coded instructions, statements, and computer programs are the |
jlovell | bc44d92 | 2007-07-16 23:34:09 +0000 | [diff] [blame] | 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/". |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 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 | |
jlovell | a74454a | 2006-05-05 19:18:41 +0000 | [diff] [blame] | 25 | # include <stdlib.h> |
| 26 | # include <config.h> |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 27 | |
| 28 | # ifdef __sun |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 29 | # include <sys/select.h> |
| 30 | # endif /* __sun */ |
| 31 | |
| 32 | # include <limits.h> |
| 33 | # ifdef WIN32 |
| 34 | # include <io.h> |
| 35 | # include <winsock2.h> |
| 36 | # else |
| 37 | # include <unistd.h> |
| 38 | # include <fcntl.h> |
| 39 | # include <sys/socket.h> |
| 40 | # define closesocket(f) close(f) |
| 41 | # endif /* WIN32 */ |
| 42 | |
jlovell | f7deaa1 | 2007-03-14 16:55:44 +0000 | [diff] [blame] | 43 | # ifdef HAVE_GSSAPI |
| 44 | # ifdef HAVE_GSSAPI_GSSAPI_H |
| 45 | # include <gssapi/gssapi.h> |
| 46 | # endif /* HAVE_GSSAPI_GSSAPI_H */ |
| 47 | # ifdef HAVE_GSSAPI_GSSAPI_GENERIC_H |
| 48 | # include <gssapi/gssapi_generic.h> |
| 49 | # endif /* HAVE_GSSAPI_GSSAPI_GENERIC_H */ |
| 50 | # ifdef HAVE_GSSAPI_GSSAPI_KRB5_H |
| 51 | # include <gssapi/gssapi_krb5.h> |
| 52 | # endif /* HAVE_GSSAPI_GSSAPI_KRB5_H */ |
| 53 | # ifdef HAVE_GSSAPI_H |
| 54 | # include <gssapi.h> |
| 55 | # endif /* HAVE_GSSAPI_H */ |
| 56 | # ifndef HAVE_GSS_C_NT_HOSTBASED_SERVICE |
| 57 | # define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name |
| 58 | # endif /* !HAVE_GSS_C_NT_HOSTBASED_SERVICE */ |
msweet | db1f069 | 2007-09-14 02:27:22 +0000 | [diff] [blame] | 59 | # ifdef HAVE_KRB5_H |
| 60 | # include <krb5.h> |
| 61 | # endif /* HAVE_KRB5_H */ |
jlovell | f7deaa1 | 2007-03-14 16:55:44 +0000 | [diff] [blame] | 62 | # endif /* HAVE_GSSAPI */ |
| 63 | |
jlovell | b94498c | 2007-05-04 21:17:48 +0000 | [diff] [blame] | 64 | # ifdef HAVE_AUTHORIZATION_H |
| 65 | # include <Security/Authorization.h> |
| 66 | # endif /* HAVE_AUTHORIZATION_H */ |
| 67 | |
jlovell | 4400e98 | 2006-02-03 00:47:45 +0000 | [diff] [blame] | 68 | # if defined(__sgi) || (defined(__APPLE__) && !defined(_SOCKLEN_T)) |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 69 | /* |
jlovell | 4400e98 | 2006-02-03 00:47:45 +0000 | [diff] [blame] | 70 | * IRIX and MacOS X 10.2.x do not define socklen_t, and in fact use an int instead of |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 71 | * unsigned type for length values... |
| 72 | */ |
| 73 | |
| 74 | typedef int socklen_t; |
jlovell | 4400e98 | 2006-02-03 00:47:45 +0000 | [diff] [blame] | 75 | # endif /* __sgi || (__APPLE__ && !_SOCKLEN_T) */ |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 76 | |
| 77 | # include "http.h" |
jlovell | f7deaa1 | 2007-03-14 16:55:44 +0000 | [diff] [blame] | 78 | # include "md5.h" |
jlovell | fa73b22 | 2006-01-26 21:39:43 +0000 | [diff] [blame] | 79 | # include "ipp-private.h" |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 80 | |
| 81 | # if defined HAVE_LIBSSL |
| 82 | /* |
| 83 | * The OpenSSL library provides its own SSL/TLS context structure for its |
jlovell | 411affc | 2006-11-16 17:01:30 +0000 | [diff] [blame] | 84 | * IO and protocol management. However, we need to provide our own BIO |
| 85 | * (basic IO) implementation to do timeouts... |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 86 | */ |
| 87 | |
| 88 | # include <openssl/err.h> |
| 89 | # include <openssl/rand.h> |
| 90 | # include <openssl/ssl.h> |
| 91 | |
| 92 | typedef SSL http_tls_t; |
| 93 | |
jlovell | 411affc | 2006-11-16 17:01:30 +0000 | [diff] [blame] | 94 | extern BIO_METHOD *_httpBIOMethods(void); |
| 95 | |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 96 | # elif defined HAVE_GNUTLS |
| 97 | /* |
| 98 | * The GNU TLS library is more of a "bare metal" SSL/TLS library... |
| 99 | */ |
| 100 | # include <gnutls/gnutls.h> |
| 101 | |
| 102 | typedef struct |
| 103 | { |
| 104 | gnutls_session session; /* GNU TLS session object */ |
| 105 | void *credentials; /* GNU TLS credentials object */ |
| 106 | } http_tls_t; |
| 107 | |
jlovell | 411affc | 2006-11-16 17:01:30 +0000 | [diff] [blame] | 108 | extern ssize_t _httpReadGNUTLS(gnutls_transport_ptr ptr, void *data, |
| 109 | size_t length); |
| 110 | extern ssize_t _httpWriteGNUTLS(gnutls_transport_ptr ptr, const void *data, |
| 111 | size_t length); |
| 112 | |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 113 | # elif defined(HAVE_CDSASSL) |
| 114 | /* |
| 115 | * Darwin's Security framework provides its own SSL/TLS context structure |
| 116 | * for its IO and protocol management... |
| 117 | */ |
| 118 | |
| 119 | # include <Security/SecureTransport.h> |
| 120 | |
jlovell | 89d4677 | 2006-04-24 18:03:36 +0000 | [diff] [blame] | 121 | typedef struct /**** CDSA connection information ****/ |
| 122 | { |
| 123 | SSLContextRef session; /* CDSA session object */ |
| 124 | CFArrayRef certsArray; /* Certificates array */ |
| 125 | } http_tls_t; |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 126 | |
| 127 | extern OSStatus _httpReadCDSA(SSLConnectionRef connection, void *data, |
| 128 | size_t *dataLength); |
| 129 | extern OSStatus _httpWriteCDSA(SSLConnectionRef connection, const void *data, |
| 130 | size_t *dataLength); |
| 131 | # endif /* HAVE_LIBSSL */ |
| 132 | |
jlovell | f7deaa1 | 2007-03-14 16:55:44 +0000 | [diff] [blame] | 133 | |
| 134 | struct _http_s /**** HTTP connection structure. ****/ |
| 135 | { |
| 136 | int fd; /* File descriptor for this socket */ |
| 137 | int blocking; /* To block or not to block */ |
| 138 | int error; /* Last error on read */ |
| 139 | time_t activity; /* Time since last read/write */ |
| 140 | http_state_t state; /* State of client */ |
| 141 | http_status_t status; /* Status of last request */ |
| 142 | http_version_t version; /* Protocol version */ |
| 143 | http_keepalive_t keep_alive; /* Keep-alive supported? */ |
| 144 | struct sockaddr_in _hostaddr; /* Address of connected host @deprecated@ */ |
| 145 | char hostname[HTTP_MAX_HOST], |
| 146 | /* Name of connected host */ |
| 147 | fields[HTTP_FIELD_MAX][HTTP_MAX_VALUE]; |
| 148 | /* Field values */ |
| 149 | char *data; /* Pointer to data buffer */ |
| 150 | http_encoding_t data_encoding; /* Chunked or not */ |
| 151 | int _data_remaining;/* Number of bytes left @deprecated@ */ |
| 152 | int used; /* Number of bytes used in buffer */ |
| 153 | char buffer[HTTP_MAX_BUFFER]; |
| 154 | /* Buffer for incoming data */ |
| 155 | int auth_type; /* Authentication in use */ |
| 156 | _cups_md5_state_t md5_state; /* MD5 state */ |
| 157 | char nonce[HTTP_MAX_VALUE]; |
| 158 | /* Nonce value */ |
| 159 | int nonce_count; /* Nonce count */ |
| 160 | void *tls; /* TLS state information */ |
| 161 | http_encryption_t encryption; /* Encryption requirements */ |
| 162 | /**** New in CUPS 1.1.19 ****/ |
| 163 | fd_set *input_set; /* select() set for httpWait() @deprecated@ */ |
| 164 | http_status_t expect; /* Expect: header @since CUPS 1.1.19@ */ |
| 165 | char *cookie; /* Cookie value(s) @since CUPS 1.1.19@ */ |
| 166 | /**** New in CUPS 1.1.20 ****/ |
| 167 | char _authstring[HTTP_MAX_VALUE], |
| 168 | /* Current Authentication value. @deprecated@ */ |
| 169 | userpass[HTTP_MAX_VALUE]; |
| 170 | /* Username:password string @since CUPS 1.1.20@ */ |
| 171 | int digest_tries; /* Number of tries for digest auth @since CUPS 1.1.20@ */ |
| 172 | /**** New in CUPS 1.2 ****/ |
| 173 | off_t data_remaining; /* Number of bytes left @since CUPS 1.2@ */ |
| 174 | http_addr_t *hostaddr; /* Current host address and port @since CUPS 1.2@ */ |
| 175 | http_addrlist_t *addrlist; /* List of valid addresses @since CUPS 1.2@ */ |
| 176 | char wbuffer[HTTP_MAX_BUFFER]; |
| 177 | /* Buffer for outgoing data */ |
| 178 | int wused; /* Write buffer bytes used @since CUPS 1.2@ */ |
| 179 | /**** New in CUPS 1.3 ****/ |
| 180 | char *field_authorization; |
| 181 | /* Authorization field @since CUPS 1.3@ */ |
| 182 | char *authstring; /* Current authorization field @since CUPS 1.3 */ |
| 183 | # ifdef HAVE_GSSAPI |
| 184 | gss_OID gssmech; /* Authentication mechanism @since CUPS 1.3@ */ |
| 185 | gss_ctx_id_t gssctx; /* Authentication context @since CUPS 1.3@ */ |
| 186 | gss_name_t gssname; /* Authentication server name @since CUPS 1.3@ */ |
| 187 | # endif /* HAVE_GSSAPI */ |
jlovell | b94498c | 2007-05-04 21:17:48 +0000 | [diff] [blame] | 188 | # ifdef HAVE_AUTHORIZATION_H |
| 189 | AuthorizationRef auth_ref; /* Authorization ref */ |
| 190 | # endif /* HAVE_AUTHORIZATION_H */ |
jlovell | f7deaa1 | 2007-03-14 16:55:44 +0000 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 194 | /* |
| 195 | * Some OS's don't have hstrerror(), most notably Solaris... |
| 196 | */ |
| 197 | |
| 198 | # ifndef HAVE_HSTRERROR |
| 199 | extern const char *_cups_hstrerror(int error); |
| 200 | # define hstrerror _cups_hstrerror |
| 201 | # elif defined(_AIX) || defined(__osf__) |
| 202 | /* |
| 203 | * AIX and Tru64 UNIX don't provide a prototype but do provide the function... |
| 204 | */ |
| 205 | extern const char *hstrerror(int error); |
| 206 | # endif /* !HAVE_HSTRERROR */ |
| 207 | |
jlovell | 89d4677 | 2006-04-24 18:03:36 +0000 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * Some OS's don't have getifaddrs() and freeifaddrs()... |
| 211 | */ |
| 212 | |
jlovell | b86bc4c | 2007-02-14 19:18:46 +0000 | [diff] [blame] | 213 | # ifndef WIN32 |
| 214 | # include <net/if.h> |
| 215 | # ifdef HAVE_GETIFADDRS |
| 216 | # include <ifaddrs.h> |
| 217 | # else |
| 218 | # include <sys/ioctl.h> |
| 219 | # ifdef HAVE_SYS_SOCKIO_H |
| 220 | # include <sys/sockio.h> |
| 221 | # endif /* HAVE_SYS_SOCKIO_H */ |
jlovell | 89d4677 | 2006-04-24 18:03:36 +0000 | [diff] [blame] | 222 | |
jlovell | b86bc4c | 2007-02-14 19:18:46 +0000 | [diff] [blame] | 223 | # ifdef ifa_dstaddr |
| 224 | # undef ifa_dstaddr |
| 225 | # endif /* ifa_dstaddr */ |
| 226 | # ifndef ifr_netmask |
| 227 | # define ifr_netmask ifr_addr |
| 228 | # endif /* !ifr_netmask */ |
jlovell | 89d4677 | 2006-04-24 18:03:36 +0000 | [diff] [blame] | 229 | |
| 230 | struct ifaddrs /**** Interface Structure ****/ |
| 231 | { |
| 232 | struct ifaddrs *ifa_next; /* Next interface in list */ |
| 233 | char *ifa_name; /* Name of interface */ |
| 234 | unsigned int ifa_flags; /* Flags (up, point-to-point, etc.) */ |
| 235 | struct sockaddr *ifa_addr, /* Network address */ |
jlovell | f301802 | 2006-05-22 21:33:05 +0000 | [diff] [blame] | 236 | *ifa_netmask; /* Address mask */ |
| 237 | union |
| 238 | { |
| 239 | struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */ |
| 240 | struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */ |
| 241 | } ifa_ifu; |
| 242 | |
jlovell | 89d4677 | 2006-04-24 18:03:36 +0000 | [diff] [blame] | 243 | void *ifa_data; /* Interface statistics */ |
| 244 | }; |
| 245 | |
jlovell | b86bc4c | 2007-02-14 19:18:46 +0000 | [diff] [blame] | 246 | # ifndef ifa_broadaddr |
| 247 | # define ifa_broadaddr ifa_ifu.ifu_broadaddr |
| 248 | # endif /* !ifa_broadaddr */ |
| 249 | # ifndef ifa_dstaddr |
| 250 | # define ifa_dstaddr ifa_ifu.ifu_dstaddr |
| 251 | # endif /* !ifa_dstaddr */ |
jlovell | f301802 | 2006-05-22 21:33:05 +0000 | [diff] [blame] | 252 | |
jlovell | a74454a | 2006-05-05 19:18:41 +0000 | [diff] [blame] | 253 | extern int _cups_getifaddrs(struct ifaddrs **addrs); |
jlovell | b86bc4c | 2007-02-14 19:18:46 +0000 | [diff] [blame] | 254 | # define getifaddrs _cups_getifaddrs |
jlovell | a74454a | 2006-05-05 19:18:41 +0000 | [diff] [blame] | 255 | extern void _cups_freeifaddrs(struct ifaddrs *addrs); |
jlovell | b86bc4c | 2007-02-14 19:18:46 +0000 | [diff] [blame] | 256 | # define freeifaddrs _cups_freeifaddrs |
| 257 | # endif /* HAVE_GETIFADDRS */ |
| 258 | # endif /* !WIN32 */ |
jlovell | 89d4677 | 2006-04-24 18:03:36 +0000 | [diff] [blame] | 259 | |
msweet | 839a51c | 2008-04-09 22:42:49 +0000 | [diff] [blame] | 260 | /* |
| 261 | * Common URI encoding function... |
| 262 | */ |
| 263 | |
| 264 | extern char *_httpEncodeURI(char *dst, const char *src, size_t dstsize); |
| 265 | |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 266 | #endif /* !_CUPS_HTTP_PRIVATE_H_ */ |
| 267 | |
| 268 | /* |
msweet | 2e4ff8a | 2007-10-17 20:05:25 +0000 | [diff] [blame] | 269 | * End of "$Id: http-private.h 6933 2007-09-10 16:45:59Z mike $". |
jlovell | ef416fc | 2006-01-13 01:51:53 +0000 | [diff] [blame] | 270 | */ |