]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/http.h
Load cups into easysw/current.
[thirdparty/cups.git] / cups / http.h
1 /*
2 * "$Id: http.h 6187 2007-01-10 16:20:42Z mike $"
3 *
4 * Hyper-Text Transport Protocol definitions for the Common UNIX Printing
5 * System (CUPS).
6 *
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 Easy Software Products and are protected by Federal
11 * copyright law. Distribution and use rights are outlined in the file
12 * "LICENSE.txt" which should have been included with this file. If this
13 * file is missing or damaged please contact Easy Software Products
14 * at:
15 *
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44141 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636 USA
20 *
21 * Voice: (301) 373-9600
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
24 *
25 * This file is subject to the Apple OS-Developed Software exception.
26 */
27
28 #ifndef _CUPS_HTTP_H_
29 # define _CUPS_HTTP_H_
30
31 /*
32 * Include necessary headers...
33 */
34
35 # include <string.h>
36 # include <time.h>
37 # include <sys/types.h>
38 # ifdef WIN32
39 # ifndef __CUPS_SSIZE_T_DEFINED
40 # define __CUPS_SSIZE_T_DEFINED
41 /* Windows does not support the ssize_t type, so map it to off_t... */
42 typedef off_t ssize_t; /* @private@ */
43 # endif /* !__CUPS_SSIZE_T_DEFINED */
44 # include <winsock2.h>
45 # include <ws2tcpip.h>
46 # else
47 # ifdef __sgi
48 # define INET6 /* IRIX IPv6 support... */
49 # endif /* __sgi */
50 # include <unistd.h>
51 # include <sys/time.h>
52 # include <sys/socket.h>
53 # include <netdb.h>
54 # include <netinet/in.h>
55 # include <arpa/inet.h>
56 # include <netinet/in_systm.h>
57 # include <netinet/ip.h>
58 # if !defined(__APPLE__) || !defined(TCP_NODELAY)
59 # include <netinet/tcp.h>
60 # endif /* !__APPLE__ || !TCP_NODELAY */
61 # if defined(AF_UNIX) && !defined(AF_LOCAL)
62 # define AF_LOCAL AF_UNIX /* Older UNIX's have old names... */
63 # endif /* AF_UNIX && !AF_LOCAL */
64 # ifdef AF_LOCAL
65 # include <sys/un.h>
66 # endif /* AF_LOCAL */
67 # endif /* WIN32 */
68
69 /*
70 * With GCC 3.0 and higher, we can mark old APIs "deprecated" so you get
71 * a warning at compile-time.
72 */
73
74 # if defined(__GNUC__) && __GNUC__ > 2
75 # define _HTTP_DEPRECATED __attribute__ ((__deprecated__))
76 # else
77 # define _HTTP_DEPRECATED
78 # endif /* __GNUC__ && __GNUC__ > 2 */
79
80
81 /*
82 * C++ magic...
83 */
84
85 # ifdef __cplusplus
86 extern "C" {
87 # endif /* __cplusplus */
88
89
90 /*
91 * Oh, the wonderful world of IPv6 compatibility. Apparently some
92 * implementations expose the (more logical) 32-bit address parts
93 * to everyone, while others only expose it to kernel code... To
94 * make supporting IPv6 even easier, each vendor chose different
95 * core structure and union names, so the same defines or code
96 * can't be used on all platforms.
97 *
98 * The following will likely need tweaking on new platforms that
99 * support IPv6 - the "s6_addr32" define maps to the 32-bit integer
100 * array in the in6_addr union, which is named differently on various
101 * platforms.
102 */
103
104 #if defined(AF_INET6) && !defined(s6_addr32)
105 # if defined(__sun)
106 # define s6_addr32 _S6_un._S6_u32
107 # elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
108 # define s6_addr32 __u6_addr.__u6_addr32
109 # elif defined(__osf__)
110 # define s6_addr32 s6_un.sa6_laddr
111 # elif defined(WIN32)
112 /*
113 * Windows only defines byte and 16-bit word members of the union and
114 * requires special casing of all raw address code...
115 */
116 # define s6_addr32 error_need_win32_specific_code
117 # endif /* __sun */
118 #endif /* AF_INET6 && !s6_addr32 */
119
120
121 /*
122 * Limits...
123 */
124
125 # define HTTP_MAX_URI 1024 /* Max length of URI string */
126 # define HTTP_MAX_HOST 256 /* Max length of hostname string */
127 # define HTTP_MAX_BUFFER 2048 /* Max length of data buffer */
128 # define HTTP_MAX_VALUE 256 /* Max header field value length */
129
130
131 /*
132 * Types and structures...
133 */
134
135 typedef enum http_auth_e /**** HTTP authentication types ****/
136 {
137 HTTP_AUTH_NONE, /* No authentication in use */
138 HTTP_AUTH_BASIC, /* Basic authentication in use */
139 HTTP_AUTH_MD5, /* Digest authentication in use */
140 HTTP_AUTH_MD5_SESS, /* MD5-session authentication in use */
141 HTTP_AUTH_MD5_INT, /* Digest authentication in use for body */
142 HTTP_AUTH_MD5_SESS_INT, /* MD5-session authentication in use for body */
143 HTTP_AUTH_NEGOTIATE /* GSSAPI authentication in use @since CUPS 1.3@ */
144 } http_auth_t;
145
146 typedef enum http_encoding_e /**** HTTP transfer encoding values ****/
147 {
148 HTTP_ENCODE_LENGTH, /* Data is sent with Content-Length */
149 HTTP_ENCODE_CHUNKED, /* Data is chunked */
150 HTTP_ENCODE_FIELDS /* Sending HTTP fields */
151 } http_encoding_t;
152
153 typedef enum http_encryption_e /**** HTTP encryption values ****/
154 {
155 HTTP_ENCRYPT_IF_REQUESTED, /* Encrypt if requested (TLS upgrade) */
156 HTTP_ENCRYPT_NEVER, /* Never encrypt */
157 HTTP_ENCRYPT_REQUIRED, /* Encryption is required (TLS upgrade) */
158 HTTP_ENCRYPT_ALWAYS /* Always encrypt (SSL) */
159 } http_encryption_t;
160
161 typedef enum http_field_e /**** HTTP field names ****/
162 {
163 HTTP_FIELD_UNKNOWN = -1, /* Unknown field */
164 HTTP_FIELD_ACCEPT_LANGUAGE, /* Accept-Language field */
165 HTTP_FIELD_ACCEPT_RANGES, /* Accept-Ranges field */
166 HTTP_FIELD_AUTHORIZATION, /* Authorization field */
167 HTTP_FIELD_CONNECTION, /* Connection field */
168 HTTP_FIELD_CONTENT_ENCODING, /* Content-Encoding field */
169 HTTP_FIELD_CONTENT_LANGUAGE, /* Content-Language field */
170 HTTP_FIELD_CONTENT_LENGTH, /* Content-Length field */
171 HTTP_FIELD_CONTENT_LOCATION, /* Content-Location field */
172 HTTP_FIELD_CONTENT_MD5, /* Content-MD5 field */
173 HTTP_FIELD_CONTENT_RANGE, /* Content-Range field */
174 HTTP_FIELD_CONTENT_TYPE, /* Content-Type field */
175 HTTP_FIELD_CONTENT_VERSION, /* Content-Version field */
176 HTTP_FIELD_DATE, /* Date field */
177 HTTP_FIELD_HOST, /* Host field */
178 HTTP_FIELD_IF_MODIFIED_SINCE, /* If-Modified-Since field */
179 HTTP_FIELD_IF_UNMODIFIED_SINCE, /* If-Unmodified-Since field */
180 HTTP_FIELD_KEEP_ALIVE, /* Keep-Alive field */
181 HTTP_FIELD_LAST_MODIFIED, /* Last-Modified field */
182 HTTP_FIELD_LINK, /* Link field */
183 HTTP_FIELD_LOCATION, /* Location field */
184 HTTP_FIELD_RANGE, /* Range field */
185 HTTP_FIELD_REFERER, /* Referer field */
186 HTTP_FIELD_RETRY_AFTER, /* Retry-After field */
187 HTTP_FIELD_TRANSFER_ENCODING, /* Transfer-Encoding field */
188 HTTP_FIELD_UPGRADE, /* Upgrade field */
189 HTTP_FIELD_USER_AGENT, /* User-Agent field */
190 HTTP_FIELD_WWW_AUTHENTICATE, /* WWW-Authenticate field */
191 HTTP_FIELD_MAX /* Maximum field index */
192 } http_field_t;
193
194 typedef enum http_keepalive_e /**** HTTP keep-alive values ****/
195 {
196 HTTP_KEEPALIVE_OFF = 0, /* No keep alive support */
197 HTTP_KEEPALIVE_ON /* Use keep alive */
198 } http_keepalive_t;
199
200 typedef enum http_state_e /**** HTTP state values; states
201 **** are server-oriented...
202 ****/
203 {
204 HTTP_WAITING, /* Waiting for command */
205 HTTP_OPTIONS, /* OPTIONS command, waiting for blank line */
206 HTTP_GET, /* GET command, waiting for blank line */
207 HTTP_GET_SEND, /* GET command, sending data */
208 HTTP_HEAD, /* HEAD command, waiting for blank line */
209 HTTP_POST, /* POST command, waiting for blank line */
210 HTTP_POST_RECV, /* POST command, receiving data */
211 HTTP_POST_SEND, /* POST command, sending data */
212 HTTP_PUT, /* PUT command, waiting for blank line */
213 HTTP_PUT_RECV, /* PUT command, receiving data */
214 HTTP_DELETE, /* DELETE command, waiting for blank line */
215 HTTP_TRACE, /* TRACE command, waiting for blank line */
216 HTTP_CLOSE, /* CLOSE command, waiting for blank line */
217 HTTP_STATUS /* Command complete, sending status */
218 } http_state_t;
219
220 typedef enum http_status_e /**** HTTP status codes ****/
221 {
222 HTTP_ERROR = -1, /* An error response from httpXxxx() */
223
224 HTTP_CONTINUE = 100, /* Everything OK, keep going... */
225 HTTP_SWITCHING_PROTOCOLS, /* HTTP upgrade to TLS/SSL */
226
227 HTTP_OK = 200, /* OPTIONS/GET/HEAD/POST/TRACE command was successful */
228 HTTP_CREATED, /* PUT command was successful */
229 HTTP_ACCEPTED, /* DELETE command was successful */
230 HTTP_NOT_AUTHORITATIVE, /* Information isn't authoritative */
231 HTTP_NO_CONTENT, /* Successful command, no new data */
232 HTTP_RESET_CONTENT, /* Content was reset/recreated */
233 HTTP_PARTIAL_CONTENT, /* Only a partial file was recieved/sent */
234
235 HTTP_MULTIPLE_CHOICES = 300, /* Multiple files match request */
236 HTTP_MOVED_PERMANENTLY, /* Document has moved permanently */
237 HTTP_MOVED_TEMPORARILY, /* Document has moved temporarily */
238 HTTP_SEE_OTHER, /* See this other link... */
239 HTTP_NOT_MODIFIED, /* File not modified */
240 HTTP_USE_PROXY, /* Must use a proxy to access this URI */
241
242 HTTP_BAD_REQUEST = 400, /* Bad request */
243 HTTP_UNAUTHORIZED, /* Unauthorized to access host */
244 HTTP_PAYMENT_REQUIRED, /* Payment required */
245 HTTP_FORBIDDEN, /* Forbidden to access this URI */
246 HTTP_NOT_FOUND, /* URI was not found */
247 HTTP_METHOD_NOT_ALLOWED, /* Method is not allowed */
248 HTTP_NOT_ACCEPTABLE, /* Not Acceptable */
249 HTTP_PROXY_AUTHENTICATION, /* Proxy Authentication is Required */
250 HTTP_REQUEST_TIMEOUT, /* Request timed out */
251 HTTP_CONFLICT, /* Request is self-conflicting */
252 HTTP_GONE, /* Server has gone away */
253 HTTP_LENGTH_REQUIRED, /* A content length or encoding is required */
254 HTTP_PRECONDITION, /* Precondition failed */
255 HTTP_REQUEST_TOO_LARGE, /* Request entity too large */
256 HTTP_URI_TOO_LONG, /* URI too long */
257 HTTP_UNSUPPORTED_MEDIATYPE, /* The requested media type is unsupported */
258 HTTP_REQUESTED_RANGE, /* The requested range is not satisfiable */
259 HTTP_EXPECTATION_FAILED, /* The expectation given in an Expect header field was not met */
260 HTTP_UPGRADE_REQUIRED = 426, /* Upgrade to SSL/TLS required */
261
262 HTTP_SERVER_ERROR = 500, /* Internal server error */
263 HTTP_NOT_IMPLEMENTED, /* Feature not implemented */
264 HTTP_BAD_GATEWAY, /* Bad gateway */
265 HTTP_SERVICE_UNAVAILABLE, /* Service is unavailable */
266 HTTP_GATEWAY_TIMEOUT, /* Gateway connection timed out */
267 HTTP_NOT_SUPPORTED /* HTTP version not supported */
268 } http_status_t;
269
270 typedef enum http_uri_status_e /**** URI separation status @since CUPS1.2@ ****/
271 {
272 HTTP_URI_OVERFLOW = -8, /* URI buffer for httpAssembleURI is too small */
273 HTTP_URI_BAD_ARGUMENTS = -7, /* Bad arguments to function (error) */
274 HTTP_URI_BAD_RESOURCE = -6, /* Bad resource in URI (error) */
275 HTTP_URI_BAD_PORT = -5, /* Bad port number in URI (error) */
276 HTTP_URI_BAD_HOSTNAME = -4, /* Bad hostname in URI (error) */
277 HTTP_URI_BAD_USERNAME = -3, /* Bad username in URI (error) */
278 HTTP_URI_BAD_SCHEME = -2, /* Bad scheme in URI (error) */
279 HTTP_URI_BAD_URI = -1, /* Bad/empty URI (error) */
280 HTTP_URI_OK = 0, /* URI decoded OK */
281 HTTP_URI_MISSING_SCHEME, /* Missing scheme in URI (warning) */
282 HTTP_URI_UNKNOWN_SCHEME, /* Unknown scheme in URI (warning) */
283 HTTP_URI_MISSING_RESOURCE /* Missing resource in URI (warning) */
284 } http_uri_status_t;
285
286 typedef enum http_uri_coding_e /**** URI en/decode flags ****/
287 {
288 HTTP_URI_CODING_NONE = 0, /* Don't en/decode anything */
289 HTTP_URI_CODING_USERNAME = 1, /* En/decode the username portion */
290 HTTP_URI_CODING_HOSTNAME = 2, /* En/decode the hostname portion */
291 HTTP_URI_CODING_RESOURCE = 4, /* En/decode the resource portion */
292 HTTP_URI_CODING_MOST = 7, /* En/decode all but the query */
293 HTTP_URI_CODING_QUERY = 8, /* En/decode the query portion */
294 HTTP_URI_CODING_ALL = 15 /* En/decode everything */
295 } http_uri_coding_t;
296
297 typedef enum http_version_e /**** HTTP version numbers ****/
298 {
299 HTTP_0_9 = 9, /* HTTP/0.9 */
300 HTTP_1_0 = 100, /* HTTP/1.0 */
301 HTTP_1_1 = 101 /* HTTP/1.1 */
302 } http_version_t;
303
304 typedef union _http_addr_u /**** Socket address union, which
305 **** makes using IPv6 and other
306 **** address types easier and
307 **** more portable. @since CUPS 1.2@
308 ****/
309 {
310 struct sockaddr addr; /* Base structure for family value */
311 struct sockaddr_in ipv4; /* IPv4 address */
312 #ifdef AF_INET6
313 struct sockaddr_in6 ipv6; /* IPv6 address */
314 #endif /* AF_INET6 */
315 #ifdef AF_LOCAL
316 struct sockaddr_un un; /* Domain socket file */
317 #endif /* AF_LOCAL */
318 char pad[256]; /* Padding to ensure binary compatibility */
319 } http_addr_t;
320
321 typedef struct http_addrlist_s /**** Socket address list, which is
322 **** used to enumerate all of the
323 **** addresses that are associated
324 **** with a hostname. @since CUPS 1.2@
325 ****/
326 {
327 struct http_addrlist_s *next; /* Pointer to next address in list */
328 http_addr_t addr; /* Address */
329 } http_addrlist_t;
330
331 typedef struct _http_s http_t; /**** HTTP connection type ****/
332
333
334 /*
335 * Prototypes...
336 */
337
338 extern void httpBlocking(http_t *http, int b);
339 extern int httpCheck(http_t *http);
340 extern void httpClearFields(http_t *http);
341 extern void httpClose(http_t *http);
342 extern http_t *httpConnect(const char *host, int port);
343 extern http_t *httpConnectEncrypt(const char *host, int port,
344 http_encryption_t encryption);
345 extern int httpDelete(http_t *http, const char *uri);
346 extern int httpEncryption(http_t *http, http_encryption_t e);
347 extern int httpError(http_t *http);
348 extern void httpFlush(http_t *http);
349 extern int httpGet(http_t *http, const char *uri);
350 extern char *httpGets(char *line, int length, http_t *http);
351 extern const char *httpGetDateString(time_t t);
352 extern time_t httpGetDateTime(const char *s);
353 extern const char *httpGetField(http_t *http, http_field_t field);
354 extern struct hostent *httpGetHostByName(const char *name);
355 extern char *httpGetSubField(http_t *http, http_field_t field,
356 const char *name, char *value);
357 extern int httpHead(http_t *http, const char *uri);
358 extern void httpInitialize(void);
359 extern int httpOptions(http_t *http, const char *uri);
360 extern int httpPost(http_t *http, const char *uri);
361 extern int httpPrintf(http_t *http, const char *format, ...)
362 # ifdef __GNUC__
363 __attribute__ ((__format__ (__printf__, 2, 3)))
364 # endif /* __GNUC__ */
365 ;
366 extern int httpPut(http_t *http, const char *uri);
367 extern int httpRead(http_t *http, char *buffer, int length) _HTTP_DEPRECATED;
368 extern int httpReconnect(http_t *http);
369 extern void httpSeparate(const char *uri, char *method,
370 char *username, char *host, int *port,
371 char *resource) _HTTP_DEPRECATED;
372 extern void httpSetField(http_t *http, http_field_t field,
373 const char *value);
374 extern const char *httpStatus(http_status_t status);
375 extern int httpTrace(http_t *http, const char *uri);
376 extern http_status_t httpUpdate(http_t *http);
377 extern int httpWrite(http_t *http, const char *buffer, int length) _HTTP_DEPRECATED;
378 extern char *httpEncode64(char *out, const char *in) _HTTP_DEPRECATED;
379 extern char *httpDecode64(char *out, const char *in) _HTTP_DEPRECATED;
380 extern int httpGetLength(http_t *http) _HTTP_DEPRECATED;
381 extern char *httpMD5(const char *, const char *, const char *,
382 char [33]);
383 extern char *httpMD5Final(const char *, const char *, const char *,
384 char [33]);
385 extern char *httpMD5String(const unsigned char *, char [33]);
386
387 /**** New in CUPS 1.1.19 ****/
388 extern void httpClearCookie(http_t *http);
389 extern const char *httpGetCookie(http_t *http);
390 extern void httpSetCookie(http_t *http, const char *cookie);
391 extern int httpWait(http_t *http, int msec);
392
393 /**** New in CUPS 1.1.21 ****/
394 extern char *httpDecode64_2(char *out, int *outlen, const char *in);
395 extern char *httpEncode64_2(char *out, int outlen, const char *in,
396 int inlen);
397 extern void httpSeparate2(const char *uri,
398 char *method, int methodlen,
399 char *username, int usernamelen,
400 char *host, int hostlen, int *port,
401 char *resource, int resourcelen) _HTTP_DEPRECATED;
402
403 /**** New in CUPS 1.2 ****/
404 extern int httpAddrAny(const http_addr_t *addr);
405 extern http_addrlist_t *httpAddrConnect(http_addrlist_t *addrlist, int *sock);
406 extern int httpAddrEqual(const http_addr_t *addr1,
407 const http_addr_t *addr2);
408 extern void httpAddrFreeList(http_addrlist_t *addrlist);
409 extern http_addrlist_t *httpAddrGetList(const char *hostname, int family,
410 const char *service);
411 extern int httpAddrLength(const http_addr_t *addr);
412 extern int httpAddrLocalhost(const http_addr_t *addr);
413 extern char *httpAddrLookup(const http_addr_t *addr,
414 char *name, int namelen);
415 extern char *httpAddrString(const http_addr_t *addr,
416 char *s, int slen);
417 extern http_uri_status_t httpAssembleURI(http_uri_coding_t encoding,
418 char *uri, int urilen,
419 const char *scheme,
420 const char *username,
421 const char *host, int port,
422 const char *resource);
423 extern http_uri_status_t httpAssembleURIf(http_uri_coding_t encoding,
424 char *uri, int urilen,
425 const char *scheme,
426 const char *username,
427 const char *host, int port,
428 const char *resourcef, ...);
429 extern int httpFlushWrite(http_t *http);
430 extern int httpGetBlocking(http_t *http);
431 extern const char *httpGetDateString2(time_t t, char *s, int slen);
432 extern int httpGetFd(http_t *http);
433 extern const char *httpGetHostname(http_t *http, char *s, int slen);
434 extern off_t httpGetLength2(http_t *http);
435 extern http_status_t httpGetStatus(http_t *http);
436 extern char *httpGetSubField2(http_t *http, http_field_t field,
437 const char *name, char *value,
438 int valuelen);
439 extern ssize_t httpRead2(http_t *http, char *buffer, size_t length);
440 extern http_uri_status_t httpSeparateURI(http_uri_coding_t decoding,
441 const char *uri,
442 char *scheme, int schemelen,
443 char *username, int usernamelen,
444 char *host, int hostlen, int *port,
445 char *resource, int resourcelen);
446 extern void httpSetExpect(http_t *http, http_status_t expect);
447 extern void httpSetLength(http_t *http, size_t length);
448 extern ssize_t httpWrite2(http_t *http, const char *buffer,
449 size_t length);
450
451
452 /*
453 * C++ magic...
454 */
455
456 # ifdef __cplusplus
457 }
458 # endif /* __cplusplus */
459 #endif /* !_CUPS_HTTP_H_ */
460
461 /*
462 * End of "$Id: http.h 6187 2007-01-10 16:20:42Z mike $".
463 */