2 * "$Id: http.h,v 1.36 2002/01/02 17:58:39 mike Exp $"
4 * Hyper-Text Transport Protocol definitions for the Common UNIX Printing
7 * Copyright 1997-2002 by Easy Software Products, all rights reserved.
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
16 * Attn: CUPS Licensing Information
17 * Easy Software Products
18 * 44141 Airport View Drive, Suite 204
19 * Hollywood, Maryland 20636-3111 USA
21 * Voice: (301) 373-9603
22 * EMail: cups-info@cups.org
23 * WWW: http://www.cups.org
27 # define _CUPS_HTTP_H_
30 * Include necessary headers...
35 # if defined(WIN32) || defined(__EMX__)
39 # include <sys/time.h>
40 # include <sys/types.h>
41 # include <sys/socket.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__ */
59 # endif /* __cplusplus */
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 */
73 * HTTP state values...
76 typedef enum /* States are server-oriented */
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 */
96 * HTTP version numbers...
101 HTTP_0_9
= 9, /* HTTP/0.9 */
102 HTTP_1_0
= 100, /* HTTP/1.0 */
103 HTTP_1_1
= 101 /* HTTP/1.1 */
108 * HTTP keep-alive values...
113 HTTP_KEEPALIVE_OFF
= 0,
119 * HTTP transfer encoding values...
124 HTTP_ENCODE_LENGTH
, /* Data is sent with Content-Length */
125 HTTP_ENCODE_CHUNKED
/* Data is chunked */
130 * HTTP encryption values...
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) */
143 * HTTP authentication types...
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 */
158 * HTTP status codes...
163 HTTP_ERROR
= -1, /* An error response from httpXxxx() */
165 HTTP_CONTINUE
= 100, /* Everything OK, keep going... */
166 HTTP_SWITCHING_PROTOCOLS
, /* HTTP upgrade to TLS/SSL */
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 */
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 */
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 */
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 */
211 * HTTP field names...
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
,
231 HTTP_FIELD_IF_MODIFIED_SINCE
,
232 HTTP_FIELD_IF_UNMODIFIED_SINCE
,
233 HTTP_FIELD_KEEP_ALIVE
,
234 HTTP_FIELD_LAST_MODIFIED
,
239 HTTP_FIELD_RETRY_AFTER
,
240 HTTP_FIELD_TRANSFER_ENCODING
,
242 HTTP_FIELD_USER_AGENT
,
243 HTTP_FIELD_WWW_AUTHENTICATE
,
249 * HTTP connection structure...
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
];
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
];
277 int nonce_count
; /* Nonce count */
278 void *tls
; /* TLS state information */
279 http_encryption_t encryption
; /* Encryption requirements */
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 struct hostent
*httpGetHostByName(const char *name
);
305 extern char *httpGetSubField(http_t
*http
, http_field_t field
,
306 const char *name
, char *value
);
307 extern int httpHead(http_t
*http
, const char *uri
);
308 extern void httpInitialize(void);
309 extern int httpOptions(http_t
*http
, const char *uri
);
310 extern int httpPost(http_t
*http
, const char *uri
);
311 extern int httpPrintf(http_t
*http
, const char *format
, ...);
312 extern int httpPut(http_t
*http
, const char *uri
);
313 extern int httpRead(http_t
*http
, char *buffer
, int length
);
314 extern int httpReconnect(http_t
*http
);
315 extern void httpSeparate(const char *uri
, char *method
,
316 char *username
, char *host
, int *port
,
318 extern void httpSetField(http_t
*http
, http_field_t field
,
320 extern const char *httpStatus(http_status_t status
);
321 extern int httpTrace(http_t
*http
, const char *uri
);
322 extern http_status_t
httpUpdate(http_t
*http
);
323 extern int httpWrite(http_t
*http
, const char *buffer
, int length
);
324 extern char *httpEncode64(char *out
, const char *in
);
325 extern char *httpDecode64(char *out
, const char *in
);
326 extern int httpGetLength(http_t
*http
);
327 extern char *httpMD5(const char *, const char *, const char *,
329 extern char *httpMD5Final(const char *, const char *, const char *,
331 extern char *httpMD5String(const md5_byte_t
*, char [33]);
340 # endif /* __cplusplus */
341 #endif /* !_CUPS_HTTP_H_ */
344 * End of "$Id: http.h,v 1.36 2002/01/02 17:58:39 mike Exp $".