]> git.lizzy.rs Git - plan9front.git/blob - sys/man/2/httpd
Import sources from 2011-03-30 iso image - sys/man
[plan9front.git] / sys / man / 2 / httpd
1 .TH HTTPD 2
2 .SH NAME
3 HConnect,
4 HContent,
5 HContents,
6 HETag,
7 HFields,
8 Hio,
9 Htmlesc,
10 HttpHead,
11 HttpReq,
12 HRange,
13 HSPairs,
14 hmydomain,
15 hversion,
16 htmlesc,
17 halloc,
18 hbodypush,
19 hbuflen,
20 hcheckcontent,
21 hclose,
22 hdate2sec,
23 hdatefmt,
24 hfail,
25 hflush,
26 hgetc,
27 hgethead,
28 hinit,
29 hiserror,
30 hload,
31 hlower,
32 hmkcontent,
33 hmkhfields,
34 hmkmimeboundary,
35 hmkspairs,
36 hmoved,
37 hokheaders,
38 hparseheaders,
39 hparsequery,
40 hparsereq,
41 hprint,
42 hputc,
43 hreadbuf,
44 hredirected,
45 hreqcleanup,
46 hrevhfields,
47 hrevspairs,
48 hstrdup,
49 http11,
50 httpfmt,
51 httpunesc,
52 hunallowed,
53 hungetc,
54 hunload,
55 hurlfmt,
56 hurlunesc,
57 hvprint,
58 hwrite,
59 hxferenc,
60  \- routines for creating an http server
61 .SH SYNOPSIS
62 .nf
63 .B #include <u.h>
64 .B #include <libc.h>
65 .B #include <httpd.h>
66 .PP
67 .ft L
68 typedef struct HConnect HConnect;
69 typedef struct HContent HContent;
70 typedef struct HContents HContents;
71 typedef struct HETag HETag;
72 typedef struct HFields HFields;
73 typedef struct Hio Hio;
74 typedef struct Htmlesc Htmlesc;
75 typedef struct HttpHead HttpHead;
76 typedef struct HttpReq HttpReq;
77 typedef struct HRange HRange;
78 typedef struct HSPairs HSPairs;
79
80 typedef struct Bin Bin;
81 .ta \w'\fLHContents 'u +\w'\fLHContentsxx 'u +\w'\fLheader[HBufSize + 2];  'u
82
83 struct Htmlesc
84 {
85         char    *name;
86         Rune    value;
87 };
88
89 struct HContent
90 {
91         HContent        *next;
92         char    *generic;
93         char    *specific;
94         float   q;      /* desirability of this kind of file */
95         int     mxb;    /* max uchars until worthless */
96 };
97
98 struct HContents
99 {
100         HContent        *type;
101         HContent         *encoding;
102 };
103
104 /*
105  * generic http header with a list of tokens,
106  * each with an optional list of parameters
107  */
108 struct HFields
109 {
110         char    *s;
111         HSPairs *params;
112         HFields *next;
113 };
114
115 /*
116  * list of pairs a strings
117  * used for tag=val pairs for a search or form submission,
118  * and attribute=value pairs in headers.
119  */
120 struct HSPairs
121 {
122         char    *s;
123         char    *t;
124         HSPairs *next;
125 };
126
127 /*
128  * byte ranges within a file
129  */
130 struct HRange
131 {
132         int     suffix; /* is this a suffix request? */
133         ulong   start;
134         ulong   stop;   /* ~0UL -> not given */
135         HRange  *next;
136 };
137
138 /*
139  * list of http/1.1 entity tags
140  */
141 struct HETag
142 {
143         char    *etag;
144         int     weak;
145         HETag   *next;
146 };
147
148 /*
149  * HTTP custom IO
150  * supports chunked transfer encoding
151  * and initialization of the input buffer from a string.
152  */
153 enum
154 {
155         Hnone,
156         Hread,
157         Hend,
158         Hwrite,
159         Herr,
160
161         Hsize = HBufSize
162 };
163
164 struct Hio {
165         Hio     *hh;    /* next lower layer Hio, or nil if reads from fd */
166         int     fd;     /* associated file descriptor */
167         ulong   seek;   /* of start */
168         uchar   state;  /* state of the file */
169         uchar   xferenc;        /* chunked transfer encoding state */
170         uchar   *pos;   /* current position in the buffer */
171         uchar   *stop;  /* last character active in the buffer */
172         uchar   *start; /* start of data buffer */
173         ulong   bodylen;        /* remaining length of message body */
174         uchar   buf[Hsize+32];
175 };
176
177 /*
178  * request line
179  */
180 struct HttpReq
181 {
182         char    *meth;
183         char    *uri;
184         char    *urihost;
185         char    *search;
186         int     vermaj;
187         int     vermin;
188 };
189
190 /*
191  * header lines
192  */
193 struct HttpHead
194 {
195         int     closeit;        /* http1.1 close connection after this request? */
196         uchar   persist;        /* http/1.1 requests a persistent connection */
197
198         uchar   expectcont;     /* expect a 100-continue */
199         uchar   expectother;    /* expect anything else; should reject with ExpectFail */
200         ulong   contlen;        /* if != ~0UL, length of included message body */
201         HFields *transenc;      /* if present, encoding of included message body */
202         char    *client;
203         char    *host;
204         HContent        *okencode;
205         HContent        *oklang;
206         HContent        *oktype;
207         HContent        *okchar;
208         ulong   ifmodsince;
209         ulong   ifunmodsince;
210         ulong   ifrangedate;
211         HETag   *ifmatch;
212         HETag   *ifnomatch;
213         HETag   *ifrangeetag;
214         HRange  *range;
215         char    *authuser;      /* authorization info */
216         char    *authpass;
217
218         /*
219          * experimental headers
220          */
221         int     fresh_thresh;
222         int     fresh_have;
223 };
224
225 /*
226  * all of the state for a particular connection
227  */
228 struct HConnect
229 {
230         void    *private;       /* for the library clients */
231         void    (*replog)(HConnect*, char*, ...);       /* called when reply sent */
232
233         HttpReq req;
234         HttpHead        head;
235
236         Bin     *bin;
237
238         ulong   reqtime;        /* time at start of request */
239         char    xferbuf[HBufSize];      /* buffer for making up or transferring data */
240         uchar   header[HBufSize + 2];   /* room for \\n\\0 */
241         uchar   *hpos;
242         uchar   *hstop;
243         Hio     hin;
244         Hio     hout;
245 };
246
247 /*
248  * configuration for all connections within the server
249  */
250 extern  char    *hmydomain;
251 extern  char    *hversion;
252 extern  Htmlesc htmlesc[];
253
254 void    *halloc(HConnect *c, ulong size);
255 Hio     *hbodypush(Hio *hh, ulong len, HFields *te);
256 int     hbuflen(Hio *h, void *p);
257 int     hcheckcontent(HContent*, HContent*, char*, int);
258 void    hclose(Hio*);
259 ulong   hdate2sec(char*);
260 int     hdatefmt(Fmt*);
261 int     hfail(HConnect*, int, ...);
262 int     hflush(Hio*);
263 int     hgetc(Hio*);
264 int     hgethead(HConnect *c, int many);
265 int     hinit(Hio*, int, int);
266 int     hiserror(Hio *h);
267 int     hload(Hio*, char*);
268 char    *hlower(char*);
269 HContent        *hmkcontent(HConnect *c, char *generic, char *specific, HContent *next);
270 HFields *hmkhfields(HConnect *c, char *s, HSPairs *p, HFields *next);
271 char    *hmkmimeboundary(HConnect *c);
272 HSPairs *hmkspairs(HConnect *c, char *s, char *t, HSPairs *next);
273 int     hmoved(HConnect *c, char *uri);
274 void    hokheaders(HConnect *c);
275 int     hparseheaders(HConnect*, int timeout);
276 HSPairs *hparsequery(HConnect *c, char *search);
277 int     hparsereq(HConnect *c, int timeout);
278 int     hprint(Hio*, char*, ...);
279 int     hputc(Hio*, int);
280 void    *hreadbuf(Hio *h, void *vsave);
281 int     hredirected(HConnect *c, char *how, char *uri);
282 void    hreqcleanup(HConnect *c);
283 HFields *hrevhfields(HFields *hf);
284 HSPairs *hrevspairs(HSPairs *sp);
285 char    *hstrdup(HConnect *c, char *s);
286 int     http11(HConnect*);
287 int     httpfmt(Fmt*);
288 char    *httpunesc(HConnect *c, char *s);
289 int     hunallowed(HConnect *, char *allowed);
290 int     hungetc(Hio *h);
291 char    *hunload(Hio*);
292 int     hurlfmt(Fmt*);
293 char    *hurlunesc(HConnect *c, char *s);
294 int     hvprint(Hio*, char*, va_list);
295 int     hwrite(Hio*, void*, int);
296 int     hxferenc(Hio*, int);
297 .ft R
298 .SH DESCRIPTION
299 For now, look at the source, or
300 .IR httpd (8).
301 .SH SOURCE
302 .B /sys/src/libhttpd
303 .SH SEE ALSO
304 .IR bin (2)
305 .SH BUGS
306 This is a rough implementation and many details are going to change.
307