]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/http.h
Merge changes from 1.1.x into 1.2 devel.
[thirdparty/cups.git] / cups / http.h
1 /*
2 * "$Id: http.h,v 1.33.2.3 2001/12/26 16:52:12 mike Exp $"
3 *
4 * Hyper-Text Transport Protocol definitions for the Common UNIX Printing
5 * System (CUPS).
6 *
7 * Copyright 1997-2001 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-3111 USA
20 *
21 * Voice: (301) 373-9603
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
24 */
25
26 #ifndef _CUPS_HTTP_H_
27 # define _CUPS_HTTP_H_
28
29 /*
30 * Include necessary headers...
31 */
32
33 # include <string.h>
34 # include <time.h>
35 # if defined(WIN32) || defined(__EMX__)
36 # include <winsock.h>
37 # else
38 # include <unistd.h>
39 # include <sys/time.h>
40 # include <sys/types.h>
41 # include <sys/socket.h>
42 # include <netdb.h>
43 # include <netinet/in.h>
44 # include <arpa/inet.h>
45 # include <netinet/in_systm.h>
46 # include <netinet/ip.h>
47 # include <netinet/tcp.h>
48 # endif /* WIN32 || __EMX__ */
49
50 # include "md5.h"
51
52
53 /*
54 * C++ magic...
55 */
56
57 # ifdef __cplusplus
58 extern "C" {
59 # endif /* __cplusplus */
60
61
62 /*
63 * Limits...
64 */
65
66 # define HTTP_MAX_URI 1024 /* Max length of URI string */
67 # define HTTP_MAX_HOST 256 /* Max length of hostname string */
68 # define HTTP_MAX_BUFFER 2048 /* Max length of data buffer */
69 # define HTTP_MAX_VALUE 256 /* Max header field value length */
70
71
72 /*
73 * HTTP state values...
74 */
75
76 typedef enum /* States are server-oriented */
77 {
78 HTTP_WAITING, /* Waiting for command */
79 HTTP_OPTIONS, /* OPTIONS command, waiting for blank line */
80 HTTP_GET, /* GET command, waiting for blank line */
81 HTTP_GET_SEND, /* GET command, sending data */
82 HTTP_HEAD, /* HEAD command, waiting for blank line */
83 HTTP_POST, /* POST command, waiting for blank line */
84 HTTP_POST_RECV, /* POST command, receiving data */
85 HTTP_POST_SEND, /* POST command, sending data */
86 HTTP_PUT, /* PUT command, waiting for blank line */
87 HTTP_PUT_RECV, /* PUT command, receiving data */
88 HTTP_DELETE, /* DELETE command, waiting for blank line */
89 HTTP_TRACE, /* TRACE command, waiting for blank line */
90 HTTP_CLOSE, /* CLOSE command, waiting for blank line */
91 HTTP_STATUS /* Command complete, sending status */
92 } http_state_t;
93
94
95 /*
96 * HTTP version numbers...
97 */
98
99 typedef enum
100 {
101 HTTP_0_9 = 9, /* HTTP/0.9 */
102 HTTP_1_0 = 100, /* HTTP/1.0 */
103 HTTP_1_1 = 101 /* HTTP/1.1 */
104 } http_version_t;
105
106
107 /*
108 * HTTP keep-alive values...
109 */
110
111 typedef enum
112 {
113 HTTP_KEEPALIVE_OFF = 0,
114 HTTP_KEEPALIVE_ON
115 } http_keepalive_t;
116
117
118 /*
119 * HTTP transfer encoding values...
120 */
121
122 typedef enum
123 {
124 HTTP_ENCODE_LENGTH, /* Data is sent with Content-Length */
125 HTTP_ENCODE_CHUNKED /* Data is chunked */
126 } http_encoding_t;
127
128
129 /*
130 * HTTP encryption values...
131 */
132
133 typedef enum
134 {
135 HTTP_ENCRYPT_IF_REQUESTED, /* Encrypt if requested (TLS upgrade) */
136 HTTP_ENCRYPT_NEVER, /* Never encrypt */
137 HTTP_ENCRYPT_REQUIRED, /* Encryption is required (TLS upgrade) */
138 HTTP_ENCRYPT_ALWAYS /* Always encrypt (SSL) */
139 } http_encryption_t;
140
141
142 /*
143 * HTTP authentication types...
144 */
145
146 typedef enum
147 {
148 HTTP_AUTH_NONE, /* No authentication in use */
149 HTTP_AUTH_BASIC, /* Basic authentication in use */
150 HTTP_AUTH_MD5, /* Digest authentication in use */
151 HTTP_AUTH_MD5_SESS, /* MD5-session authentication in use */
152 HTTP_AUTH_MD5_INT, /* Digest authentication in use for body */
153 HTTP_AUTH_MD5_SESS_INT /* MD5-session authentication in use for body */
154 } http_auth_t;
155
156
157 /*
158 * HTTP status codes...
159 */
160
161 typedef enum
162 {
163 HTTP_ERROR = -1, /* An error response from httpXxxx() */
164
165 HTTP_CONTINUE = 100, /* Everything OK, keep going... */
166 HTTP_SWITCHING_PROTOCOLS, /* HTTP upgrade to TLS/SSL */
167
168 HTTP_OK = 200, /* OPTIONS/GET/HEAD/POST/TRACE command was successful */
169 HTTP_CREATED, /* PUT command was successful */
170 HTTP_ACCEPTED, /* DELETE command was successful */
171 HTTP_NOT_AUTHORITATIVE, /* Information isn't authoritative */
172 HTTP_NO_CONTENT, /* Successful command, no new data */
173 HTTP_RESET_CONTENT, /* Content was reset/recreated */
174 HTTP_PARTIAL_CONTENT, /* Only a partial file was recieved/sent */
175
176 HTTP_MULTIPLE_CHOICES = 300, /* Multiple files match request */
177 HTTP_MOVED_PERMANENTLY, /* Document has moved permanently */
178 HTTP_MOVED_TEMPORARILY, /* Document has moved temporarily */
179 HTTP_SEE_OTHER, /* See this other link... */
180 HTTP_NOT_MODIFIED, /* File not modified */
181 HTTP_USE_PROXY, /* Must use a proxy to access this URI */
182
183 HTTP_BAD_REQUEST = 400, /* Bad request */
184 HTTP_UNAUTHORIZED, /* Unauthorized to access host */
185 HTTP_PAYMENT_REQUIRED, /* Payment required */
186 HTTP_FORBIDDEN, /* Forbidden to access this URI */
187 HTTP_NOT_FOUND, /* URI was not found */
188 HTTP_METHOD_NOT_ALLOWED, /* Method is not allowed */
189 HTTP_NOT_ACCEPTABLE, /* Not Acceptable */
190 HTTP_PROXY_AUTHENTICATION, /* Proxy Authentication is Required */
191 HTTP_REQUEST_TIMEOUT, /* Request timed out */
192 HTTP_CONFLICT, /* Request is self-conflicting */
193 HTTP_GONE, /* Server has gone away */
194 HTTP_LENGTH_REQUIRED, /* A content length or encoding is required */
195 HTTP_PRECONDITION, /* Precondition failed */
196 HTTP_REQUEST_TOO_LARGE, /* Request entity too large */
197 HTTP_URI_TOO_LONG, /* URI too long */
198 HTTP_UNSUPPORTED_MEDIATYPE, /* The requested media type is unsupported */
199 HTTP_UPGRADE_REQUIRED = 426, /* Upgrade to SSL/TLS required */
200
201 HTTP_SERVER_ERROR = 500, /* Internal server error */
202 HTTP_NOT_IMPLEMENTED, /* Feature not implemented */
203 HTTP_BAD_GATEWAY, /* Bad gateway */
204 HTTP_SERVICE_UNAVAILABLE, /* Service is unavailable */
205 HTTP_GATEWAY_TIMEOUT, /* Gateway connection timed out */
206 HTTP_NOT_SUPPORTED /* HTTP version not supported */
207 } http_status_t;
208
209
210 /*
211 * HTTP field names...
212 */
213
214 typedef enum
215 {
216 HTTP_FIELD_UNKNOWN = -1,
217 HTTP_FIELD_ACCEPT_LANGUAGE,
218 HTTP_FIELD_ACCEPT_RANGES,
219 HTTP_FIELD_AUTHORIZATION,
220 HTTP_FIELD_CONNECTION,
221 HTTP_FIELD_CONTENT_ENCODING,
222 HTTP_FIELD_CONTENT_LANGUAGE,
223 HTTP_FIELD_CONTENT_LENGTH,
224 HTTP_FIELD_CONTENT_LOCATION,
225 HTTP_FIELD_CONTENT_MD5,
226 HTTP_FIELD_CONTENT_RANGE,
227 HTTP_FIELD_CONTENT_TYPE,
228 HTTP_FIELD_CONTENT_VERSION,
229 HTTP_FIELD_DATE,
230 HTTP_FIELD_HOST,
231 HTTP_FIELD_IF_MODIFIED_SINCE,
232 HTTP_FIELD_IF_UNMODIFIED_SINCE,
233 HTTP_FIELD_KEEP_ALIVE,
234 HTTP_FIELD_LAST_MODIFIED,
235 HTTP_FIELD_LINK,
236 HTTP_FIELD_LOCATION,
237 HTTP_FIELD_RANGE,
238 HTTP_FIELD_REFERER,
239 HTTP_FIELD_RETRY_AFTER,
240 HTTP_FIELD_TRANSFER_ENCODING,
241 HTTP_FIELD_UPGRADE,
242 HTTP_FIELD_USER_AGENT,
243 HTTP_FIELD_WWW_AUTHENTICATE,
244 HTTP_FIELD_MAX
245 } http_field_t;
246
247
248 /*
249 * HTTP address structure (makes using IPv6 a little easier and more portable.)
250 */
251
252 typedef union
253 {
254 struct sockaddr addr; /* Base structure for family value */
255 struct sockaddr_in ipv4; /* IPv4 address */
256 #ifdef AF_INET6
257 struct sockaddr_in6 ipv6; /* IPv6 address */
258 #endif /* AF_INET6 */
259 char pad[128]; /* Pad to ensure binary compatibility */
260 } http_addr_t;
261
262 /*
263 * HTTP connection structure...
264 */
265
266 typedef struct
267 {
268 int fd; /* File descriptor for this socket */
269 int blocking; /* To block or not to block */
270 int error; /* Last error on read */
271 time_t activity; /* Time since last read/write */
272 http_state_t state; /* State of client */
273 http_status_t status; /* Status of last request */
274 http_version_t version; /* Protocol version */
275 http_keepalive_t keep_alive; /* Keep-alive supported? */
276 http_addr_t hostaddr; /* Host address and port */
277 char hostname[HTTP_MAX_HOST],
278 /* Name of connected host */
279 fields[HTTP_FIELD_MAX][HTTP_MAX_VALUE];
280 /* Field values */
281 char *data; /* Pointer to data buffer */
282 http_encoding_t data_encoding; /* Chunked or not */
283 int data_remaining; /* Number of bytes left */
284 int used; /* Number of bytes used in buffer */
285 char buffer[HTTP_MAX_BUFFER];
286 /* Buffer for messages */
287 int auth_type; /* Authentication in use */
288 md5_state_t md5_state; /* MD5 state */
289 char nonce[HTTP_MAX_VALUE];
290 /* Nonce value */
291 int nonce_count; /* Nonce count */
292 void *tls; /* TLS state information */
293 http_encryption_t encryption; /* Encryption requirements */
294 } http_t;
295
296
297 /*
298 * Prototypes...
299 */
300
301 # define httpBlocking(http,b) (http)->blocking = (b)
302 extern int httpCheck(http_t *http);
303 # define httpClearFields(http) memset((http)->fields, 0, sizeof((http)->fields)),\
304 httpSetField((http), HTTP_FIELD_HOST, (http)->hostname)
305 extern void httpClose(http_t *http);
306 extern http_t *httpConnect(const char *host, int port);
307 extern http_t *httpConnectEncrypt(const char *host, int port,
308 http_encryption_t encrypt);
309 extern int httpDelete(http_t *http, const char *uri);
310 extern int httpEncryption(http_t *http, http_encryption_t e);
311 # define httpError(http) ((http)->error)
312 extern void httpFlush(http_t *http);
313 extern int httpGet(http_t *http, const char *uri);
314 extern char *httpGets(char *line, int length, http_t *http);
315 extern const char *httpGetDateString(time_t t);
316 extern time_t httpGetDateTime(const char *s);
317 # define httpGetField(http,field) (http)->fields[field]
318 extern struct hostent *httpGetHostByName(const char *name);
319 extern char *httpGetSubField(http_t *http, http_field_t field,
320 const char *name, char *value);
321 extern int httpHead(http_t *http, const char *uri);
322 extern void httpInitialize(void);
323 extern int httpOptions(http_t *http, const char *uri);
324 extern int httpPost(http_t *http, const char *uri);
325 extern int httpPrintf(http_t *http, const char *format, ...);
326 extern int httpPut(http_t *http, const char *uri);
327 extern int httpRead(http_t *http, char *buffer, int length);
328 extern int httpReconnect(http_t *http);
329 extern void httpSeparate(const char *uri, char *method,
330 char *username, char *host, int *port,
331 char *resource);
332 extern void httpSetField(http_t *http, http_field_t field,
333 const char *value);
334 extern const char *httpStatus(http_status_t status);
335 extern int httpTrace(http_t *http, const char *uri);
336 extern http_status_t httpUpdate(http_t *http);
337 extern int httpWrite(http_t *http, const char *buffer, int length);
338 extern char *httpEncode64(char *out, const char *in);
339 extern char *httpDecode64(char *out, const char *in);
340 extern int httpGetLength(http_t *http);
341 extern char *httpMD5(const char *, const char *, const char *,
342 char [33]);
343 extern char *httpMD5Final(const char *, const char *, const char *,
344 char [33]);
345 extern char *httpMD5String(const md5_byte_t *, char [33]);
346
347 extern int httpAddrEqual(const http_addr_t *addr1,
348 const http_addr_t *addr2);
349 extern void httpAddrLoad(const struct hostent *host, int port,
350 int n, http_addr_t *addr);
351 extern int httpAddrLocalhost(const http_addr_t *addr);
352 extern char *httpAddrLookup(const http_addr_t *addr,
353 char *name, int namelen);
354 extern char *httpAddrString(const http_addr_t *addr,
355 char *s, int slen);
356
357
358 /*
359 * C++ magic...
360 */
361
362 # ifdef __cplusplus
363 }
364 # endif /* __cplusplus */
365 #endif /* !_CUPS_HTTP_H_ */
366
367 /*
368 * End of "$Id: http.h,v 1.33.2.3 2001/12/26 16:52:12 mike Exp $".
369 */