1 /* 2 * "$Id: http-private.h 9104 2010-04-12 04:03:53Z mike $" 3 * 4 * Private HTTP definitions for the Common UNIX Printing System (CUPS). 5 * 6 * Copyright 2007-2008 by Apple Inc. 7 * Copyright 1997-2007 by Easy Software Products, all rights reserved. 8 * 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/". 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 25 # include <stdlib.h> 26 # include <config.h> 27 28 # ifdef __sun 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 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 */ 59 # ifdef HAVE_KRB5_H 60 # include <krb5.h> 61 # endif /* HAVE_KRB5_H */ 62 # endif /* HAVE_GSSAPI */ 63 64 # ifdef HAVE_AUTHORIZATION_H 65 # include <Security/Authorization.h> 66 # endif /* HAVE_AUTHORIZATION_H */ 67 68 # if defined(__sgi) || (defined(__APPLE__) && !defined(_SOCKLEN_T)) 69 /* 70 * IRIX and MacOS X 10.2.x do not define socklen_t, and in fact use an int instead of 71 * unsigned type for length values... 72 */ 73 74 typedef int socklen_t; 75 # endif /* __sgi || (__APPLE__ && !_SOCKLEN_T) */ 76 77 # include "http.h" 78 # include "md5.h" 79 # include "ipp-private.h" 80 81 # if defined HAVE_LIBSSL 82 /* 83 * The OpenSSL library provides its own SSL/TLS context structure for its 84 * IO and protocol management. However, we need to provide our own BIO 85 * (basic IO) implementation to do timeouts... 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 94 extern BIO_METHOD *_httpBIOMethods(void); 95 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 # include <gcrypt.h> 102 103 typedef struct 104 { 105 gnutls_session session; /* GNU TLS session object */ 106 void *credentials; /* GNU TLS credentials object */ 107 } http_tls_t; 108 109 extern ssize_t _httpReadGNUTLS(gnutls_transport_ptr ptr, void *data, 110 size_t length); 111 extern ssize_t _httpWriteGNUTLS(gnutls_transport_ptr ptr, const void *data, 112 size_t length); 113 114 # elif defined(HAVE_CDSASSL) 115 /* 116 * Darwin's Security framework provides its own SSL/TLS context structure 117 * for its IO and protocol management... 118 */ 119 120 # include <Security/SecureTransport.h> 121 122 typedef struct /**** CDSA connection information ****/ 123 { 124 SSLContextRef session; /* CDSA session object */ 125 CFArrayRef certsArray; /* Certificates array */ 126 } http_tls_t; 127 128 extern OSStatus _httpReadCDSA(SSLConnectionRef connection, void *data, 129 size_t *dataLength); 130 extern OSStatus _httpWriteCDSA(SSLConnectionRef connection, const void *data, 131 size_t *dataLength); 132 # endif /* HAVE_LIBSSL */ 133 134 135 struct _http_s /**** HTTP connection structure. ****/ 136 { 137 int fd; /* File descriptor for this socket */ 138 int blocking; /* To block or not to block */ 139 int error; /* Last error on read */ 140 time_t activity; /* Time since last read/write */ 141 http_state_t state; /* State of client */ 142 http_status_t status; /* Status of last request */ 143 http_version_t version; /* Protocol version */ 144 http_keepalive_t keep_alive; /* Keep-alive supported? */ 145 struct sockaddr_in _hostaddr; /* Address of connected host @deprecated@ */ 146 char hostname[HTTP_MAX_HOST], 147 /* Name of connected host */ 148 fields[HTTP_FIELD_MAX][HTTP_MAX_VALUE]; 149 /* Field values */ 150 char *data; /* Pointer to data buffer */ 151 http_encoding_t data_encoding; /* Chunked or not */ 152 int _data_remaining;/* Number of bytes left @deprecated@ */ 153 int used; /* Number of bytes used in buffer */ 154 char buffer[HTTP_MAX_BUFFER]; 155 /* Buffer for incoming data */ 156 int auth_type; /* Authentication in use */ 157 _cups_md5_state_t md5_state; /* MD5 state */ 158 char nonce[HTTP_MAX_VALUE]; 159 /* Nonce value */ 160 int nonce_count; /* Nonce count */ 161 void *tls; /* TLS state information */ 162 http_encryption_t encryption; /* Encryption requirements */ 163 /**** New in CUPS 1.1.19 ****/ 164 fd_set *input_set; /* select() set for httpWait() @deprecated@ */ 165 http_status_t expect; /* Expect: header @since CUPS 1.1.19@ */ 166 char *cookie; /* Cookie value(s) @since CUPS 1.1.19@ */ 167 /**** New in CUPS 1.1.20 ****/ 168 char _authstring[HTTP_MAX_VALUE], 169 /* Current Authentication value. @deprecated@ */ 170 userpass[HTTP_MAX_VALUE]; 171 /* Username:password string @since CUPS 1.1.20@ */ 172 int digest_tries; /* Number of tries for digest auth @since CUPS 1.1.20@ */ 173 /**** New in CUPS 1.2 ****/ 174 off_t data_remaining; /* Number of bytes left @since CUPS 1.2@ */ 175 http_addr_t *hostaddr; /* Current host address and port @since CUPS 1.2@ */ 176 http_addrlist_t *addrlist; /* List of valid addresses @since CUPS 1.2@ */ 177 char wbuffer[HTTP_MAX_BUFFER]; 178 /* Buffer for outgoing data */ 179 int wused; /* Write buffer bytes used @since CUPS 1.2@ */ 180 /**** New in CUPS 1.3 ****/ 181 char *field_authorization; 182 /* Authorization field @since CUPS 1.3@ */ 183 char *authstring; /* Current authorization field @since CUPS 1.3 */ 184 # ifdef HAVE_GSSAPI 185 gss_OID gssmech; /* Authentication mechanism @since CUPS 1.3@ */ 186 gss_ctx_id_t gssctx; /* Authentication context @since CUPS 1.3@ */ 187 gss_name_t gssname; /* Authentication server name @since CUPS 1.3@ */ 188 # endif /* HAVE_GSSAPI */ 189 # ifdef HAVE_AUTHORIZATION_H 190 AuthorizationRef auth_ref; /* Authorization ref */ 191 # endif /* HAVE_AUTHORIZATION_H */ 192 }; 193 194 195 /* 196 * Some OS's don't have hstrerror(), most notably Solaris... 197 */ 198 199 # ifndef HAVE_HSTRERROR 200 extern const char *_cups_hstrerror(int error); 201 # define hstrerror _cups_hstrerror 202 # elif defined(_AIX) || defined(__osf__) 203 /* 204 * AIX and Tru64 UNIX don't provide a prototype but do provide the function... 205 */ 206 extern const char *hstrerror(int error); 207 # endif /* !HAVE_HSTRERROR */ 208 209 210 /* 211 * Some OS's don't have getifaddrs() and freeifaddrs()... 212 */ 213 214 # ifndef WIN32 215 # include <net/if.h> 216 # ifdef HAVE_GETIFADDRS 217 # include <ifaddrs.h> 218 # else 219 # include <sys/ioctl.h> 220 # ifdef HAVE_SYS_SOCKIO_H 221 # include <sys/sockio.h> 222 # endif /* HAVE_SYS_SOCKIO_H */ 223 224 # ifdef ifa_dstaddr 225 # undef ifa_dstaddr 226 # endif /* ifa_dstaddr */ 227 # ifndef ifr_netmask 228 # define ifr_netmask ifr_addr 229 # endif /* !ifr_netmask */ 230 231 struct ifaddrs /**** Interface Structure ****/ 232 { 233 struct ifaddrs *ifa_next; /* Next interface in list */ 234 char *ifa_name; /* Name of interface */ 235 unsigned int ifa_flags; /* Flags (up, point-to-point, etc.) */ 236 struct sockaddr *ifa_addr, /* Network address */ 237 *ifa_netmask; /* Address mask */ 238 union 239 { 240 struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */ 241 struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */ 242 } ifa_ifu; 243 244 void *ifa_data; /* Interface statistics */ 245 }; 246 247 # ifndef ifa_broadaddr 248 # define ifa_broadaddr ifa_ifu.ifu_broadaddr 249 # endif /* !ifa_broadaddr */ 250 # ifndef ifa_dstaddr 251 # define ifa_dstaddr ifa_ifu.ifu_dstaddr 252 # endif /* !ifa_dstaddr */ 253 254 extern int _cups_getifaddrs(struct ifaddrs **addrs); 255 # define getifaddrs _cups_getifaddrs 256 extern void _cups_freeifaddrs(struct ifaddrs *addrs); 257 # define freeifaddrs _cups_freeifaddrs 258 # endif /* HAVE_GETIFADDRS */ 259 # endif /* !WIN32 */ 260 261 /* 262 * Prototypes... 263 */ 264 265 extern int _httpAddrPort(http_addr_t *addr); 266 extern http_t *_httpCreate(const char *host, int port, 267 http_encryption_t encryption); 268 extern char *_httpEncodeURI(char *dst, const char *src, 269 size_t dstsize); 270 extern const char *_httpResolveURI(const char *uri, char *resolved_uri, 271 size_t resolved_size, int log); 272 extern int _httpWait(http_t *http, int msec, int usessl); 273 #endif /* !_CUPS_HTTP_PRIVATE_H_ */ 274 275 /* 276 * End of "$Id: http-private.h 9104 2010-04-12 04:03:53Z mike $". 277 */ 278