]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/http.h
Import cups.org releases
[thirdparty/cups.git] / cups / http.h
1 /*
2 * "$Id$"
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 connection structure...
250 */
251
252 typedef struct
253 {
254 int fd; /* File descriptor for this socket */
255 int blocking; /* To block or not to block */
256 int error; /* Last error on read */
257 time_t activity; /* Time since last read/write */
258 http_state_t state; /* State of client */
259 http_status_t status; /* Status of last request */
260 http_version_t version; /* Protocol version */
261 http_keepalive_t keep_alive; /* Keep-alive supported? */
262 struct sockaddr_in hostaddr; /* Address of connected host */
263 char hostname[HTTP_MAX_HOST],
264 /* Name of connected host */
265 fields[HTTP_FIELD_MAX][HTTP_MAX_VALUE];
266 /* Field values */
267 char *data; /* Pointer to data buffer */
268 http_encoding_t data_encoding; /* Chunked or not */
269 int data_remaining; /* Number of bytes left */
270 int used; /* Number of bytes used in buffer */
271 char buffer[HTTP_MAX_BUFFER];
272 /* Buffer for messages */
273 int auth_type; /* Authentication in use */
274 md5_state_t md5_state; /* MD5 state */
275 char nonce[HTTP_MAX_VALUE];
276 /* Nonce value */
277 int nonce_count; /* Nonce count */
278 void *tls; /* TLS state information */
279 http_encryption_t encryption; /* Encryption requirements */
280 } http_t;
281
282
283 /*
284 * Prototypes...
285 */
286
287 # define httpBlocking(http,b) (http)->blocking = (b)
288 extern int httpCheck(http_t *http);
289 # define httpClearFields(http) memset((http)->fields, 0, sizeof((http)->fields)),\
290 httpSetField((http), HTTP_FIELD_HOST, (http)->hostname)
291 extern void httpClose(http_t *http);
292 extern http_t *httpConnect(const char *host, int port);
293 extern http_t *httpConnectEncrypt(const char *host, int port,
294 http_encryption_t encrypt);
295 extern int httpDelete(http_t *http, const char *uri);
296 extern int httpEncryption(http_t *http, http_encryption_t e);
297 # define httpError(http) ((http)->error)
298 extern void httpFlush(http_t *http);
299 extern int httpGet(http_t *http, const char *uri);
300 extern char *httpGets(char *line, int length, http_t *http);
301 extern const char *httpGetDateString(time_t t);
302 extern time_t httpGetDateTime(const char *s);
303 # define httpGetField(http,field) (http)->fields[field]
304 extern char *httpGetSubField(http_t *http, http_field_t field,
305 const char *name, char *value);
306 extern int httpHead(http_t *http, const char *uri);
307 extern void httpInitialize(void);
308 extern int httpOptions(http_t *http, const char *uri);
309 extern int httpPost(http_t *http, const char *uri);
310 extern int httpPrintf(http_t *http, const char *format, ...);
311 extern int httpPut(http_t *http, const char *uri);
312 extern int httpRead(http_t *http, char *buffer, int length);
313 extern int httpReconnect(http_t *http);
314 extern void httpSeparate(const char *uri, char *method,
315 char *username, char *host, int *port,
316 char *resource);
317 extern void httpSetField(http_t *http, http_field_t field,
318 const char *value);
319 extern const char *httpStatus(http_status_t status);
320 extern int httpTrace(http_t *http, const char *uri);
321 extern http_status_t httpUpdate(http_t *http);
322 extern int httpWrite(http_t *http, const char *buffer, int length);
323 extern char *httpEncode64(char *out, const char *in);
324 extern char *httpDecode64(char *out, const char *in);
325 extern int httpGetLength(http_t *http);
326 extern char *httpMD5(const char *, const char *, const char *,
327 char [33]);
328 extern char *httpMD5Final(const char *, const char *, const char *,
329 char [33]);
330 extern char *httpMD5String(const md5_byte_t *, char [33]);
331
332
333 /*
334 * C++ magic...
335 */
336
337 # ifdef __cplusplus
338 }
339 # endif /* __cplusplus */
340 #endif /* !_CUPS_HTTP_H_ */
341
342 /*
343 * End of "$Id$".
344 */