httpd 5.8 KB

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