#pragma lib "libhttpd.a" #pragma src "/sys/src/libhttpd" typedef struct HConnect HConnect; typedef struct HContent HContent; typedef struct HContents HContents; typedef struct HETag HETag; typedef struct HFields HFields; typedef struct Hio Hio; typedef struct Htmlesc Htmlesc; typedef struct HttpHead HttpHead; typedef struct HttpReq HttpReq; typedef struct HRange HRange; typedef struct HSPairs HSPairs; typedef struct Bin Bin; enum { HMaxWord = 32*1024, HBufSize = 32*1024, /* * error messages */ HInternal = 0, HTempFail, HUnimp, HBadReq, HBadSearch, HNotFound, HUnauth, HSyntax, HNoSearch, HNoData, HExpectFail, HUnkVers, HBadCont, HOK, }; /* * table of html character escape codes */ struct Htmlesc { char *name; Rune value; }; struct HContent { HContent *next; char *generic; char *specific; float q; /* desirability of this kind of file */ int mxb; /* max uchars until worthless */ }; struct HContents { HContent *type; HContent *encoding; }; /* * generic http header with a list of tokens, * each with an optional list of parameters */ struct HFields { char *s; HSPairs *params; HFields *next; }; /* * list of pairs a strings * used for tag=val pairs for a search or form submission, * and attribute=value pairs in headers. */ struct HSPairs { char *s; char *t; HSPairs *next; }; /* * uchar ranges within a file */ struct HRange { int suffix; /* is this a suffix request? */ ulong start; ulong stop; /* ~0UL -> not given */ HRange *next; }; /* * list of http/1.1 entity tags */ struct HETag { char *etag; int weak; HETag *next; }; /* * HTTP custom IO * supports chunked transfer encoding * and initialization of the input buffer from a string. */ enum { Hnone, Hread, Hend, Hwrite, Herr, Hsize = HBufSize }; struct Hio { Hio *hh; /* next lower layer Hio, or nil if reads from fd */ int fd; /* associated file descriptor */ ulong seek; /* of start */ uchar state; /* state of the file */ uchar xferenc; /* chunked transfer encoding state */ uchar *pos; /* current position in the buffer */ uchar *stop; /* last character active in the buffer */ uchar *start; /* start of data buffer */ ulong bodylen; /* remaining length of message body */ uchar buf[Hsize+32]; }; /* * request line */ struct HttpReq { /* * request line */ char *meth; char *uri; char *urihost; char *search; int vermaj; int vermin; }; /* * header lines */ struct HttpHead { int closeit; /* http1.1 close connection after this request? */ uchar persist; /*