httpd 5.8 KB

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