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 97a5e5f2 2003-11-23 devnull #pragma lib "libhttpd.a"
8 97a5e5f2 2003-11-23 devnull #pragma src "/sys/src/libhttpd"
11 97a5e5f2 2003-11-23 devnull typedef struct HConnect HConnect;
12 97a5e5f2 2003-11-23 devnull typedef struct HContent HContent;
13 97a5e5f2 2003-11-23 devnull typedef struct HContents HContents;
14 97a5e5f2 2003-11-23 devnull typedef struct HETag HETag;
15 97a5e5f2 2003-11-23 devnull typedef struct HFields HFields;
16 97a5e5f2 2003-11-23 devnull typedef struct Hio Hio;
17 97a5e5f2 2003-11-23 devnull typedef struct Htmlesc Htmlesc;
18 97a5e5f2 2003-11-23 devnull typedef struct HttpHead HttpHead;
19 97a5e5f2 2003-11-23 devnull typedef struct HttpReq HttpReq;
20 97a5e5f2 2003-11-23 devnull typedef struct HRange HRange;
21 97a5e5f2 2003-11-23 devnull typedef struct HSPairs HSPairs;
23 97a5e5f2 2003-11-23 devnull #ifndef _HAVE_BIN
24 97a5e5f2 2003-11-23 devnull typedef struct Bin Bin;
25 97a5e5f2 2003-11-23 devnull #define _HAVE_BIN
30 97a5e5f2 2003-11-23 devnull HMaxWord = 32*1024,
31 97a5e5f2 2003-11-23 devnull HBufSize = 32*1024,
34 97a5e5f2 2003-11-23 devnull * error messages
36 97a5e5f2 2003-11-23 devnull HInternal = 0,
37 97a5e5f2 2003-11-23 devnull HTempFail,
40 97a5e5f2 2003-11-23 devnull HBadSearch,
41 97a5e5f2 2003-11-23 devnull HNotFound,
44 97a5e5f2 2003-11-23 devnull HNoSearch,
46 97a5e5f2 2003-11-23 devnull HExpectFail,
47 97a5e5f2 2003-11-23 devnull HUnkVers,
48 97a5e5f2 2003-11-23 devnull HBadCont,
53 97a5e5f2 2003-11-23 devnull * table of html character escape codes
55 97a5e5f2 2003-11-23 devnull struct Htmlesc
57 97a5e5f2 2003-11-23 devnull char *name;
58 97a5e5f2 2003-11-23 devnull Rune value;
61 97a5e5f2 2003-11-23 devnull struct HContent
63 97a5e5f2 2003-11-23 devnull HContent *next;
64 97a5e5f2 2003-11-23 devnull char *generic;
65 97a5e5f2 2003-11-23 devnull char *specific;
66 97a5e5f2 2003-11-23 devnull float q; /* desirability of this kind of file */
67 97a5e5f2 2003-11-23 devnull int mxb; /* max uchars until worthless */
70 97a5e5f2 2003-11-23 devnull struct HContents
72 97a5e5f2 2003-11-23 devnull HContent *type;
73 97a5e5f2 2003-11-23 devnull HContent *encoding;
77 97a5e5f2 2003-11-23 devnull * generic http header with a list of tokens,
78 97a5e5f2 2003-11-23 devnull * each with an optional list of parameters
80 97a5e5f2 2003-11-23 devnull struct HFields
83 97a5e5f2 2003-11-23 devnull HSPairs *params;
84 97a5e5f2 2003-11-23 devnull HFields *next;
88 97a5e5f2 2003-11-23 devnull * list of pairs a strings
89 97a5e5f2 2003-11-23 devnull * used for tag=val pairs for a search or form submission,
90 97a5e5f2 2003-11-23 devnull * and attribute=value pairs in headers.
92 97a5e5f2 2003-11-23 devnull struct HSPairs
96 97a5e5f2 2003-11-23 devnull HSPairs *next;
100 97a5e5f2 2003-11-23 devnull * byte ranges within a file
102 97a5e5f2 2003-11-23 devnull struct HRange
104 97a5e5f2 2003-11-23 devnull int suffix; /* is this a suffix request? */
105 97a5e5f2 2003-11-23 devnull ulong start;
106 97a5e5f2 2003-11-23 devnull ulong stop; /* ~0UL -> not given */
107 97a5e5f2 2003-11-23 devnull HRange *next;
111 97a5e5f2 2003-11-23 devnull * list of http/1.1 entity tags
113 97a5e5f2 2003-11-23 devnull struct HETag
115 97a5e5f2 2003-11-23 devnull char *etag;
116 97a5e5f2 2003-11-23 devnull int weak;
117 97a5e5f2 2003-11-23 devnull HETag *next;
121 97a5e5f2 2003-11-23 devnull * HTTP custom IO
122 97a5e5f2 2003-11-23 devnull * supports chunked transfer encoding
123 97a5e5f2 2003-11-23 devnull * and initialization of the input buffer from a string.
133 97a5e5f2 2003-11-23 devnull Hsize = HBufSize
136 97a5e5f2 2003-11-23 devnull struct Hio {
137 97a5e5f2 2003-11-23 devnull Hio *hh; /* next lower layer Hio, or nil if reads from fd */
138 97a5e5f2 2003-11-23 devnull int fd; /* associated file descriptor */
139 97a5e5f2 2003-11-23 devnull ulong seek; /* of start */
140 97a5e5f2 2003-11-23 devnull uchar state; /* state of the file */
141 97a5e5f2 2003-11-23 devnull uchar xferenc; /* chunked transfer encoding state */
142 97a5e5f2 2003-11-23 devnull uchar *pos; /* current position in the buffer */
143 97a5e5f2 2003-11-23 devnull uchar *stop; /* last character active in the buffer */
144 97a5e5f2 2003-11-23 devnull uchar *start; /* start of data buffer */
145 97a5e5f2 2003-11-23 devnull ulong bodylen; /* remaining length of message body */
146 97a5e5f2 2003-11-23 devnull uchar buf[Hsize+32];
150 97a5e5f2 2003-11-23 devnull * request line
152 97a5e5f2 2003-11-23 devnull struct HttpReq
154 97a5e5f2 2003-11-23 devnull char *meth;
155 97a5e5f2 2003-11-23 devnull char *uri;
156 97a5e5f2 2003-11-23 devnull char *urihost;
157 97a5e5f2 2003-11-23 devnull char *search;
158 97a5e5f2 2003-11-23 devnull int vermaj;
159 97a5e5f2 2003-11-23 devnull int vermin;
163 97a5e5f2 2003-11-23 devnull * header lines
165 97a5e5f2 2003-11-23 devnull struct HttpHead
167 97a5e5f2 2003-11-23 devnull int closeit; /* http1.1 close connection after this request? */
168 97a5e5f2 2003-11-23 devnull uchar persist; /* http/1.1 requests a persistent connection */
170 97a5e5f2 2003-11-23 devnull uchar expectcont; /* expect a 100-continue */
171 97a5e5f2 2003-11-23 devnull uchar expectother; /* expect anything else; should reject with ExpectFail */
172 97a5e5f2 2003-11-23 devnull ulong contlen; /* if != ~0UL, length of included message body */
173 97a5e5f2 2003-11-23 devnull HFields *transenc; /* if present, encoding of included message body */
174 97a5e5f2 2003-11-23 devnull char *client;
175 97a5e5f2 2003-11-23 devnull char *host;
176 97a5e5f2 2003-11-23 devnull HContent *okencode;
177 97a5e5f2 2003-11-23 devnull HContent *oklang;
178 97a5e5f2 2003-11-23 devnull HContent *oktype;
179 97a5e5f2 2003-11-23 devnull HContent *okchar;
180 97a5e5f2 2003-11-23 devnull ulong ifmodsince;
181 97a5e5f2 2003-11-23 devnull ulong ifunmodsince;
182 97a5e5f2 2003-11-23 devnull ulong ifrangedate;
183 97a5e5f2 2003-11-23 devnull HETag *ifmatch;
184 97a5e5f2 2003-11-23 devnull HETag *ifnomatch;
185 97a5e5f2 2003-11-23 devnull HETag *ifrangeetag;
186 97a5e5f2 2003-11-23 devnull HRange *range;
187 97a5e5f2 2003-11-23 devnull char *authuser; /* authorization info */
188 97a5e5f2 2003-11-23 devnull char *authpass;
191 97a5e5f2 2003-11-23 devnull * experimental headers
193 97a5e5f2 2003-11-23 devnull int fresh_thresh;
194 97a5e5f2 2003-11-23 devnull int fresh_have;
198 97a5e5f2 2003-11-23 devnull * all of the state for a particular connection
200 97a5e5f2 2003-11-23 devnull struct HConnect
202 97a5e5f2 2003-11-23 devnull void *private; /* for the library clients */
203 97a5e5f2 2003-11-23 devnull void (*replog)(HConnect*, char*, ...); /* called when reply sent */
205 97a5e5f2 2003-11-23 devnull HttpReq req;
206 97a5e5f2 2003-11-23 devnull HttpHead head;
208 97a5e5f2 2003-11-23 devnull Bin *bin;
210 97a5e5f2 2003-11-23 devnull ulong reqtime; /* time at start of request */
211 97a5e5f2 2003-11-23 devnull char xferbuf[HBufSize]; /* buffer for making up or transferring data */
212 97a5e5f2 2003-11-23 devnull uchar header[HBufSize + 2]; /* room for \n\0 */
213 97a5e5f2 2003-11-23 devnull uchar *hpos;
214 97a5e5f2 2003-11-23 devnull uchar *hstop;
215 97a5e5f2 2003-11-23 devnull Hio hin;
216 97a5e5f2 2003-11-23 devnull Hio hout;
220 97a5e5f2 2003-11-23 devnull * configuration for all connections within the server
222 97a5e5f2 2003-11-23 devnull extern char* hmydomain;
223 97a5e5f2 2003-11-23 devnull extern char* hversion;
224 97a5e5f2 2003-11-23 devnull extern Htmlesc htmlesc[];
227 97a5e5f2 2003-11-23 devnull * .+2,/^$/ | sort -bd +1
229 97a5e5f2 2003-11-23 devnull void *halloc(HConnect *c, ulong size);
230 97a5e5f2 2003-11-23 devnull Hio *hbodypush(Hio *hh, ulong len, HFields *te);
231 97a5e5f2 2003-11-23 devnull int hbuflen(Hio *h, void *p);
232 97a5e5f2 2003-11-23 devnull int hcheckcontent(HContent*, HContent*, char*, int);
233 97a5e5f2 2003-11-23 devnull void hclose(Hio*);
234 97a5e5f2 2003-11-23 devnull ulong hdate2sec(char*);
235 97a5e5f2 2003-11-23 devnull int hdatefmt(Fmt*);
236 97a5e5f2 2003-11-23 devnull int hfail(HConnect*, int, ...);
237 97a5e5f2 2003-11-23 devnull int hflush(Hio*);
238 97a5e5f2 2003-11-23 devnull int hgetc(Hio*);
239 97a5e5f2 2003-11-23 devnull int hgethead(HConnect *c, int many);
240 97a5e5f2 2003-11-23 devnull int hinit(Hio*, int, int);
241 97a5e5f2 2003-11-23 devnull int hiserror(Hio *h);
242 97a5e5f2 2003-11-23 devnull int hload(Hio*, char*);
243 97a5e5f2 2003-11-23 devnull char *hlower(char*);
244 97a5e5f2 2003-11-23 devnull HContent *hmkcontent(HConnect *c, char *generic, char *specific, HContent *next);
245 97a5e5f2 2003-11-23 devnull HFields *hmkhfields(HConnect *c, char *s, HSPairs *p, HFields *next);
246 97a5e5f2 2003-11-23 devnull char *hmkmimeboundary(HConnect *c);
247 97a5e5f2 2003-11-23 devnull HSPairs *hmkspairs(HConnect *c, char *s, char *t, HSPairs *next);
248 97a5e5f2 2003-11-23 devnull int hmoved(HConnect *c, char *uri);
249 97a5e5f2 2003-11-23 devnull void hokheaders(HConnect *c);
250 97a5e5f2 2003-11-23 devnull int hparseheaders(HConnect*, int timeout);
251 97a5e5f2 2003-11-23 devnull HSPairs *hparsequery(HConnect *c, char *search);
252 97a5e5f2 2003-11-23 devnull int hparsereq(HConnect *c, int timeout);
253 97a5e5f2 2003-11-23 devnull int hprint(Hio*, char*, ...);
254 97a5e5f2 2003-11-23 devnull int hputc(Hio*, int);
255 97a5e5f2 2003-11-23 devnull void *hreadbuf(Hio *h, void *vsave);
256 97a5e5f2 2003-11-23 devnull int hredirected(HConnect *c, char *how, char *uri);
257 97a5e5f2 2003-11-23 devnull void hreqcleanup(HConnect *c);
258 97a5e5f2 2003-11-23 devnull HFields *hrevhfields(HFields *hf);
259 97a5e5f2 2003-11-23 devnull HSPairs *hrevspairs(HSPairs *sp);
260 97a5e5f2 2003-11-23 devnull char *hstrdup(HConnect *c, char *s);
261 97a5e5f2 2003-11-23 devnull int http11(HConnect*);
262 97a5e5f2 2003-11-23 devnull int httpfmt(Fmt*);
263 97a5e5f2 2003-11-23 devnull char *httpunesc(HConnect *c, char *s);
264 97a5e5f2 2003-11-23 devnull int hunallowed(HConnect *, char *allowed);
265 97a5e5f2 2003-11-23 devnull int hungetc(Hio *h);
266 97a5e5f2 2003-11-23 devnull char *hunload(Hio*);
267 97a5e5f2 2003-11-23 devnull int hurlfmt(Fmt*);
268 97a5e5f2 2003-11-23 devnull char *hurlunesc(HConnect *c, char *s);
269 97a5e5f2 2003-11-23 devnull int hwrite(Hio*, void*, int);
270 97a5e5f2 2003-11-23 devnull int hxferenc(Hio*, int);
273 97a5e5f2 2003-11-23 devnull #pragma varargck argpos hprint 2
276 97a5e5f2 2003-11-23 devnull * D is httpd format date conversion
277 97a5e5f2 2003-11-23 devnull * U is url escape convertsion
278 97a5e5f2 2003-11-23 devnull * H is html escape conversion
281 97a5e5f2 2003-11-23 devnull #pragma varargck type "D" long
282 97a5e5f2 2003-11-23 devnull #pragma varargck type "D" ulong
283 97a5e5f2 2003-11-23 devnull #pragma varargck type "U" char*
284 97a5e5f2 2003-11-23 devnull #pragma varargck type "H" char*
287 f7012583 2003-11-25 devnull #if defined(__cplusplus)