Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / libevent / dist / http-internal.h
blob92c57d3929308fd978258cc67554653a8685d5de
1 /* $NetBSD$ */
2 /*
3 * Copyright 2001 Niels Provos <provos@citi.umich.edu>
4 * All rights reserved.
6 * This header file contains definitions for dealing with HTTP requests
7 * that are internal to libevent. As user of the library, you should not
8 * need to know about these.
9 */
11 #ifndef _HTTP_H_
12 #define _HTTP_H_
14 #define HTTP_CONNECT_TIMEOUT 45
15 #define HTTP_WRITE_TIMEOUT 50
16 #define HTTP_READ_TIMEOUT 50
18 #define HTTP_PREFIX "http://"
19 #define HTTP_DEFAULTPORT 80
21 enum message_read_status {
22 ALL_DATA_READ = 1,
23 MORE_DATA_EXPECTED = 0,
24 DATA_CORRUPTED = -1,
25 REQUEST_CANCELED = -2
28 enum evhttp_connection_error {
29 EVCON_HTTP_TIMEOUT,
30 EVCON_HTTP_EOF,
31 EVCON_HTTP_INVALID_HEADER
34 struct evbuffer;
35 struct addrinfo;
36 struct evhttp_request;
38 /* A stupid connection object - maybe make this a bufferevent later */
40 enum evhttp_connection_state {
41 EVCON_DISCONNECTED, /**< not currently connected not trying either*/
42 EVCON_CONNECTING, /**< tries to currently connect */
43 EVCON_IDLE, /**< connection is established */
44 EVCON_READING_FIRSTLINE,/**< reading Request-Line (incoming conn) or
45 **< Status-Line (outgoing conn) */
46 EVCON_READING_HEADERS, /**< reading request/response headers */
47 EVCON_READING_BODY, /**< reading request/response body */
48 EVCON_READING_TRAILER, /**< reading request/response chunked trailer */
49 EVCON_WRITING /**< writing request/response headers/body */
52 struct event_base;
54 struct evhttp_connection {
55 /* we use tailq only if they were created for an http server */
56 TAILQ_ENTRY(evhttp_connection) (next);
58 int fd;
59 struct event ev;
60 struct event close_ev;
61 struct evbuffer *input_buffer;
62 struct evbuffer *output_buffer;
64 char *bind_address; /* address to use for binding the src */
65 u_short bind_port; /* local port for binding the src */
67 char *address; /* address to connect to */
68 u_short port;
70 int flags;
71 #define EVHTTP_CON_INCOMING 0x0001 /* only one request on it ever */
72 #define EVHTTP_CON_OUTGOING 0x0002 /* multiple requests possible */
73 #define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */
75 int timeout; /* timeout in seconds for events */
76 int retry_cnt; /* retry count */
77 int retry_max; /* maximum number of retries */
79 enum evhttp_connection_state state;
81 /* for server connections, the http server they are connected with */
82 struct evhttp *http_server;
84 TAILQ_HEAD(evcon_requestq, evhttp_request) requests;
86 void (*cb)(struct evhttp_connection *, void *);
87 void *cb_arg;
89 void (*closecb)(struct evhttp_connection *, void *);
90 void *closecb_arg;
92 struct event_base *base;
95 struct evhttp_cb {
96 TAILQ_ENTRY(evhttp_cb) next;
98 char *what;
100 void (*cb)(struct evhttp_request *req, void *);
101 void *cbarg;
104 /* both the http server as well as the rpc system need to queue connections */
105 TAILQ_HEAD(evconq, evhttp_connection);
107 /* each bound socket is stored in one of these */
108 struct evhttp_bound_socket {
109 TAILQ_ENTRY(evhttp_bound_socket) (next);
111 struct event bind_ev;
114 struct evhttp {
115 TAILQ_HEAD(boundq, evhttp_bound_socket) sockets;
117 TAILQ_HEAD(httpcbq, evhttp_cb) callbacks;
118 struct evconq connections;
120 int timeout;
122 void (*gencb)(struct evhttp_request *req, void *);
123 void *gencbarg;
125 struct event_base *base;
128 /* resets the connection; can be reused for more requests */
129 void evhttp_connection_reset(struct evhttp_connection *);
131 /* connects if necessary */
132 int evhttp_connection_connect(struct evhttp_connection *);
134 /* notifies the current request that it failed; resets connection */
135 void evhttp_connection_fail(struct evhttp_connection *,
136 enum evhttp_connection_error error);
138 void evhttp_get_request(struct evhttp *, int, struct sockaddr *, socklen_t);
140 int evhttp_hostportfile(char *, char **, u_short *, char **);
142 int evhttp_parse_firstline(struct evhttp_request *, struct evbuffer*);
143 int evhttp_parse_headers(struct evhttp_request *, struct evbuffer*);
145 void evhttp_start_read(struct evhttp_connection *);
146 void evhttp_make_header(struct evhttp_connection *, struct evhttp_request *);
148 void evhttp_write_buffer(struct evhttp_connection *,
149 void (*)(struct evhttp_connection *, void *), void *);
151 /* response sending HTML the data in the buffer */
152 void evhttp_response_code(struct evhttp_request *, int, const char *);
153 void evhttp_send_page(struct evhttp_request *, struct evbuffer *);
155 #endif /* _HTTP_H */