1 f7012583 2003-11-25 devnull #ifndef _HTTPD_H_
2 f7012583 2003-11-25 devnull #define _HTTPD_H_ 1
3 f7012583 2003-11-25 devnull #if defined(__cplusplus)
4 f7012583 2003-11-25 devnull extern "C" {
7 1a0954ab 2005-01-04 devnull AUTOLIB(httpd)
9 97a5e5f2 2003-11-23 devnull #pragma lib "libhttpd.a"
10 97a5e5f2 2003-11-23 devnull #pragma src "/sys/src/libhttpd"
13 97a5e5f2 2003-11-23 devnull typedef struct HConnect HConnect;
14 97a5e5f2 2003-11-23 devnull typedef struct HContent HContent;
15 97a5e5f2 2003-11-23 devnull typedef struct HContents HContents;
16 97a5e5f2 2003-11-23 devnull typedef struct HETag HETag;
17 97a5e5f2 2003-11-23 devnull typedef struct HFields HFields;
18 97a5e5f2 2003-11-23 devnull typedef struct Hio Hio;
19 97a5e5f2 2003-11-23 devnull typedef struct Htmlesc Htmlesc;
20 97a5e5f2 2003-11-23 devnull typedef struct HttpHead HttpHead;
21 97a5e5f2 2003-11-23 devnull typedef struct HttpReq HttpReq;
22 97a5e5f2 2003-11-23 devnull typedef struct HRange HRange;
23 97a5e5f2 2003-11-23 devnull typedef struct HSPairs HSPairs;
25 97a5e5f2 2003-11-23 devnull #ifndef _HAVE_BIN
26 97a5e5f2 2003-11-23 devnull typedef struct Bin Bin;
27 97a5e5f2 2003-11-23 devnull #define _HAVE_BIN
32 97a5e5f2 2003-11-23 devnull HMaxWord = 32*1024,
33 97a5e5f2 2003-11-23 devnull HBufSize = 32*1024,
36 97a5e5f2 2003-11-23 devnull * error messages
38 97a5e5f2 2003-11-23 devnull HInternal = 0,
39 97a5e5f2 2003-11-23 devnull HTempFail,
42 97a5e5f2 2003-11-23 devnull HBadSearch,
43 97a5e5f2 2003-11-23 devnull HNotFound,
46 97a5e5f2 2003-11-23 devnull HNoSearch,
48 97a5e5f2 2003-11-23 devnull HExpectFail,
49 97a5e5f2 2003-11-23 devnull HUnkVers,
50 97a5e5f2 2003-11-23 devnull HBadCont,
55 97a5e5f2 2003-11-23 devnull * table of html character escape codes
57 97a5e5f2 2003-11-23 devnull struct Htmlesc
59 97a5e5f2 2003-11-23 devnull char *name;
60 97a5e5f2 2003-11-23 devnull Rune value;
63 97a5e5f2 2003-11-23 devnull struct HContent
65 97a5e5f2 2003-11-23 devnull HContent *next;
66 97a5e5f2 2003-11-23 devnull char *generic;
67 97a5e5f2 2003-11-23 devnull char *specific;
68 97a5e5f2 2003-11-23 devnull float q; /* desirability of this kind of file */
69 97a5e5f2 2003-11-23 devnull int mxb; /* max uchars until worthless */
72 97a5e5f2 2003-11-23 devnull struct HContents
74 97a5e5f2 2003-11-23 devnull HContent *type;
75 97a5e5f2 2003-11-23 devnull HContent *encoding;
79 97a5e5f2 2003-11-23 devnull * generic http header with a list of tokens,
80 97a5e5f2 2003-11-23 devnull * each with an optional list of parameters
82 97a5e5f2 2003-11-23 devnull struct HFields
85 97a5e5f2 2003-11-23 devnull HSPairs *params;
86 97a5e5f2 2003-11-23 devnull HFields *next;
90 97a5e5f2 2003-11-23 devnull * list of pairs a strings
91 97a5e5f2 2003-11-23 devnull * used for tag=val pairs for a search or form submission,
92 97a5e5f2 2003-11-23 devnull * and attribute=value pairs in headers.
94 97a5e5f2 2003-11-23 devnull struct HSPairs
98 97a5e5f2 2003-11-23 devnull HSPairs *next;
102 97a5e5f2 2003-11-23 devnull * byte ranges within a file
104 97a5e5f2 2003-11-23 devnull struct HRange
106 97a5e5f2 2003-11-23 devnull int suffix; /* is this a suffix request? */
107 97a5e5f2 2003-11-23 devnull ulong start;
108 97a5e5f2 2003-11-23 devnull ulong stop; /* ~0UL -> not given */
109 97a5e5f2 2003-11-23 devnull HRange *next;
113 97a5e5f2 2003-11-23 devnull * list of http/1.1 entity tags
115 97a5e5f2 2003-11-23 devnull struct HETag
117 97a5e5f2 2003-11-23 devnull char *etag;
118 97a5e5f2 2003-11-23 devnull int weak;
119 97a5e5f2 2003-11-23 devnull HETag *next;
123 97a5e5f2 2003-11-23 devnull * HTTP custom IO
124 97a5e5f2 2003-11-23 devnull * supports chunked transfer encoding
125 97a5e5f2 2003-11-23 devnull * and initialization of the input buffer from a string.
135 97a5e5f2 2003-11-23 devnull Hsize = HBufSize
138 97a5e5f2 2003-11-23 devnull struct Hio {
139 97a5e5f2 2003-11-23 devnull Hio *hh; /* next lower layer Hio, or nil if reads from fd */
140 97a5e5f2 2003-11-23 devnull int fd; /* associated file descriptor */
141 97a5e5f2 2003-11-23 devnull ulong seek; /* of start */
142 97a5e5f2 2003-11-23 devnull uchar state; /* state of the file */
143 97a5e5f2 2003-11-23 devnull uchar xferenc; /* chunked transfer encoding state */
144 97a5e5f2 2003-11-23 devnull uchar *pos; /* current position in the buffer */
145 97a5e5f2 2003-11-23 devnull uchar *stop; /* last character active in the buffer */
146 97a5e5f2 2003-11-23 devnull uchar *start; /* start of data buffer */
147 97a5e5f2 2003-11-23 devnull ulong bodylen; /* remaining length of message body */
148 97a5e5f2 2003-11-23 devnull uchar buf[Hsize+32];
152 97a5e5f2 2003-11-23 devnull * request line
154 97a5e5f2 2003-11-23 devnull struct HttpReq
156 97a5e5f2 2003-11-23 devnull char *meth;
157 97a5e5f2 2003-11-23 devnull char *uri;
158 97a5e5f2 2003-11-23 devnull char *urihost;
159 97a5e5f2 2003-11-23 devnull char *search;
160 97a5e5f2 2003-11-23 devnull int vermaj;
161 97a5e5f2 2003-11-23 devnull int vermin;
162 946b8d70 2007-04-21 devnull HSPairs *searchpairs;
166 97a5e5f2 2003-11-23 devnull * header lines
168 97a5e5f2 2003-11-23 devnull struct HttpHead
170 97a5e5f2 2003-11-23 devnull int closeit; /* http1.1 close connection after this request? */
171 97a5e5f2 2003-11-23 devnull uchar persist; /* http/1.1 requests a persistent connection */
173 97a5e5f2 2003-11-23 devnull uchar expectcont; /* expect a 100-continue */
174 97a5e5f2 2003-11-23 devnull uchar expectother; /* expect anything else; should reject with ExpectFail */
175 97a5e5f2 2003-11-23 devnull ulong contlen; /* if != ~0UL, length of included message body */
176 97a5e5f2 2003-11-23 devnull HFields *transenc; /* if present, encoding of included message body */
177 97a5e5f2 2003-11-23 devnull char *client;
178 97a5e5f2 2003-11-23 devnull char *host;
179 97a5e5f2 2003-11-23 devnull HContent *okencode;
180 97a5e5f2 2003-11-23 devnull HContent *oklang;
181 97a5e5f2 2003-11-23 devnull HContent *oktype;
182 97a5e5f2 2003-11-23 devnull HContent *okchar;
183 97a5e5f2 2003-11-23 devnull ulong ifmodsince;
184 97a5e5f2 2003-11-23 devnull ulong ifunmodsince;
185 97a5e5f2 2003-11-23 devnull ulong ifrangedate;
186 97a5e5f2 2003-11-23 devnull HETag *ifmatch;
187 97a5e5f2 2003-11-23 devnull HETag *ifnomatch;
188 97a5e5f2 2003-11-23 devnull HETag *ifrangeetag;
189 97a5e5f2 2003-11-23 devnull HRange *range;
190 97a5e5f2 2003-11-23 devnull char *authuser; /* authorization info */
191 97a5e5f2 2003-11-23 devnull char *authpass;
194 97a5e5f2 2003-11-23 devnull * experimental headers
196 97a5e5f2 2003-11-23 devnull int fresh_thresh;
197 97a5e5f2 2003-11-23 devnull int fresh_have;
201 97a5e5f2 2003-11-23 devnull * all of the state for a particular connection
203 97a5e5f2 2003-11-23 devnull struct HConnect
205 97a5e5f2 2003-11-23 devnull void *private; /* for the library clients */
206 97a5e5f2 2003-11-23 devnull void (*replog)(HConnect*, char*, ...); /* called when reply sent */
208 97a5e5f2 2003-11-23 devnull HttpReq req;
209 97a5e5f2 2003-11-23 devnull HttpHead head;
211 97a5e5f2 2003-11-23 devnull Bin *bin;
213 97a5e5f2 2003-11-23 devnull ulong reqtime; /* time at start of request */
214 97a5e5f2 2003-11-23 devnull char xferbuf[HBufSize]; /* buffer for making up or transferring data */
215 97a5e5f2 2003-11-23 devnull uchar header[HBufSize + 2]; /* room for \n\0 */
216 97a5e5f2 2003-11-23 devnull uchar *hpos;
217 97a5e5f2 2003-11-23 devnull uchar *hstop;
218 97a5e5f2 2003-11-23 devnull Hio hin;
219 97a5e5f2 2003-11-23 devnull Hio hout;
223 97a5e5f2 2003-11-23 devnull * configuration for all connections within the server
225 97a5e5f2 2003-11-23 devnull extern char* hmydomain;
226 97a5e5f2 2003-11-23 devnull extern char* hversion;
227 97a5e5f2 2003-11-23 devnull extern Htmlesc htmlesc[];
230 97a5e5f2 2003-11-23 devnull * .+2,/^$/ | sort -bd +1
232 97a5e5f2 2003-11-23 devnull void *halloc(HConnect *c, ulong size);
233 97a5e5f2 2003-11-23 devnull Hio *hbodypush(Hio *hh, ulong len, HFields *te);
234 97a5e5f2 2003-11-23 devnull int hbuflen(Hio *h, void *p);
235 97a5e5f2 2003-11-23 devnull int hcheckcontent(HContent*, HContent*, char*, int);
236 97a5e5f2 2003-11-23 devnull void hclose(Hio*);
237 97a5e5f2 2003-11-23 devnull ulong hdate2sec(char*);
238 97a5e5f2 2003-11-23 devnull int hdatefmt(Fmt*);
239 97a5e5f2 2003-11-23 devnull int hfail(HConnect*, int, ...);
240 97a5e5f2 2003-11-23 devnull int hflush(Hio*);
241 678ede7e 2004-12-27 devnull int hlflush(Hio*);
242 97a5e5f2 2003-11-23 devnull int hgetc(Hio*);
243 97a5e5f2 2003-11-23 devnull int hgethead(HConnect *c, int many);
244 97a5e5f2 2003-11-23 devnull int hinit(Hio*, int, int);
245 97a5e5f2 2003-11-23 devnull int hiserror(Hio *h);
246 97a5e5f2 2003-11-23 devnull int hload(Hio*, char*);
247 97a5e5f2 2003-11-23 devnull char *hlower(char*);
248 97a5e5f2 2003-11-23 devnull HContent *hmkcontent(HConnect *c, char *generic, char *specific, HContent *next);
249 97a5e5f2 2003-11-23 devnull HFields *hmkhfields(HConnect *c, char *s, HSPairs *p, HFields *next);
250 97a5e5f2 2003-11-23 devnull char *hmkmimeboundary(HConnect *c);
251 97a5e5f2 2003-11-23 devnull HSPairs *hmkspairs(HConnect *c, char *s, char *t, HSPairs *next);
252 97a5e5f2 2003-11-23 devnull int hmoved(HConnect *c, char *uri);
253 97a5e5f2 2003-11-23 devnull void hokheaders(HConnect *c);
254 97a5e5f2 2003-11-23 devnull int hparseheaders(HConnect*, int timeout);
255 97a5e5f2 2003-11-23 devnull HSPairs *hparsequery(HConnect *c, char *search);
256 97a5e5f2 2003-11-23 devnull int hparsereq(HConnect *c, int timeout);
257 97a5e5f2 2003-11-23 devnull int hprint(Hio*, char*, ...);
258 97a5e5f2 2003-11-23 devnull int hputc(Hio*, int);
259 97a5e5f2 2003-11-23 devnull void *hreadbuf(Hio *h, void *vsave);
260 97a5e5f2 2003-11-23 devnull int hredirected(HConnect *c, char *how, char *uri);
261 97a5e5f2 2003-11-23 devnull void hreqcleanup(HConnect *c);
262 97a5e5f2 2003-11-23 devnull HFields *hrevhfields(HFields *hf);
263 97a5e5f2 2003-11-23 devnull HSPairs *hrevspairs(HSPairs *sp);
264 97a5e5f2 2003-11-23 devnull char *hstrdup(HConnect *c, char *s);
265 97a5e5f2 2003-11-23 devnull int http11(HConnect*);
266 97a5e5f2 2003-11-23 devnull int httpfmt(Fmt*);
267 97a5e5f2 2003-11-23 devnull char *httpunesc(HConnect *c, char *s);
268 97a5e5f2 2003-11-23 devnull int hunallowed(HConnect *, char *allowed);
269 97a5e5f2 2003-11-23 devnull int hungetc(Hio *h);
270 97a5e5f2 2003-11-23 devnull char *hunload(Hio*);
271 97a5e5f2 2003-11-23 devnull int hurlfmt(Fmt*);
272 97a5e5f2 2003-11-23 devnull char *hurlunesc(HConnect *c, char *s);
273 97a5e5f2 2003-11-23 devnull int hwrite(Hio*, void*, int);
274 97a5e5f2 2003-11-23 devnull int hxferenc(Hio*, int);
277 97a5e5f2 2003-11-23 devnull #pragma varargck argpos hprint 2
280 97a5e5f2 2003-11-23 devnull * D is httpd format date conversion
281 97a5e5f2 2003-11-23 devnull * U is url escape convertsion
282 97a5e5f2 2003-11-23 devnull * H is html escape conversion
285 97a5e5f2 2003-11-23 devnull #pragma varargck type "D" long
286 97a5e5f2 2003-11-23 devnull #pragma varargck type "D" ulong
287 97a5e5f2 2003-11-23 devnull #pragma varargck type "U" char*
288 97a5e5f2 2003-11-23 devnull #pragma varargck type "H" char*
291 f7012583 2003-11-25 devnull #if defined(__cplusplus)