Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ (2) — Plan9 4th Edition

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

bin(2)

HTTPD(2)

NAME

HConnect, HContent, HContents, HETag, HFields, Hio, Htmlesc, HttpHead, HttpReq, HRange, HSPairs, hmydomain, hversion, htmlesc, halloc, hbodypush, hbuflen, hcheckcontent, hclose, hdate2sec, hdatefmt, hfail, hflush, hgetc, hgethead, hinit, hiserror, hload, hlower, hmkcontent, hmkhfields, hmkmimeboundary, hmkspairs, hmoved, hokheaders, hparseheaders, hparsequery, hparsereq, hprint, hputc, hreadbuf, hredirected, hreqcleanup, hrevhfields, hrevspairs, hstrdup, http11, httpfmt, httpunesc, hunallowed, hungetc, hunload, hurlfmt, hurlunesc, hvprint, hwrite, hxferenc,
 − routines for creating an http server

SYNOPSIS

­#include <u.h>

­#include <u.h>
­#include <libc.h>
­#include <httpd.h>

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;
 struct Htmlesc
{
char∗name;
Runevalue;
};
 struct HContent
{
HContent∗next;
char∗generic;
char∗specific;
floatq;/∗ desirability of this kind of file ∗/
intmxb;/∗ 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;
};
 /∗
 ∗ byte ranges within a file
 ∗/
struct HRange
{
intsuffix;/∗ is this a suffix request? ∗/
ulongstart;
ulongstop;/∗ ~0UL -> not given ∗/
HRange∗next;
};
 /∗
 ∗ list of http/1.1 entity tags
 ∗/
struct HETag
{
char∗etag;
intweak;
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 ∗/
intfd;/∗ associated file descriptor ∗/
ulongseek;/∗ of start ∗/
ucharstate;/∗ state of the file ∗/
ucharxferenc;/∗ 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 ∗/
ulongbodylen;/∗ remaining length of message body ∗/
ucharbuf[Hsize+32];
};
 /∗
 ∗ request line
 ∗/
struct HttpReq
{
char∗meth;
char∗uri;
char∗urihost;
char∗search;
intvermaj;
intvermin;
};
 /∗
 ∗ header lines
 ∗/
struct HttpHead
{
intcloseit;/∗ http1.1 close connection after this request? ∗/
ucharpersist;/∗ http/1.1 requests a persistent connection ∗/
 ucharexpectcont;/∗ expect a 100-continue ∗/
ucharexpectother;/∗ expect anything else; should reject with ExpectFail ∗/
ulongcontlen;/∗ if != ~0UL, length of included message body ∗/
HFields∗transenc;/∗ if present, encoding of included message body ∗/
char∗client;
char∗host;
HContent∗okencode;
HContent∗oklang;
HContent∗oktype;
HContent∗okchar;
ulongifmodsince;
ulongifunmodsince;
ulongifrangedate;
HETag∗ifmatch;
HETag∗ifnomatch;
HETag∗ifrangeetag;
HRange∗range;
char∗authuser;/∗ authorization info ∗/
char∗authpass;
 /∗
∗ experimental headers
∗/
intfresh_thresh;
intfresh_have;
};
 /∗
 ∗ all of the state for a particular connection
 ∗/
struct HConnect
{
void∗private;/∗ for the library clients ∗/
void(∗replog)(HConnect∗, char∗, ...); /∗ called when reply sent ∗/
 HttpReqreq;
HttpHeadhead;
 Bin∗bin;
 ulongreqtime;/∗ time at start of request ∗/
charxferbuf[HBufSize];/∗ buffer for making up or transferring data ∗/
ucharheader[HBufSize + 2];/∗ room for \n\0 ∗/
uchar∗hpos;
uchar∗hstop;
Hiohin;
Hiohout;
};
 /∗
 ∗ configuration for all connections within the server
 ∗/
externchar∗hmydomain;
externchar∗hversion;
externHtmleschtmlesc[];
 void∗halloc(HConnect ∗c, ulong size);
Hio∗hbodypush(Hio ∗hh, ulong len, HFields ∗te);
inthbuflen(Hio ∗h, void ∗p);
inthcheckcontent(HContent∗, HContent∗, char∗, int);
voidhclose(Hio∗);
ulonghdate2sec(char∗);
inthdatefmt(Fmt∗);
inthfail(HConnect∗, int, ...);
inthflush(Hio∗);
inthgetc(Hio∗);
inthgethead(HConnect ∗c, int many);
inthinit(Hio∗, int, int);
inthiserror(Hio ∗h);
inthload(Hio∗, char∗);
char∗hlower(char∗);
HContent∗hmkcontent(HConnect ∗c, char ∗generic, char ∗specific, HContent ∗next);
HFields∗hmkhfields(HConnect ∗c, char ∗s, HSPairs ∗p, HFields ∗next);
char∗hmkmimeboundary(HConnect ∗c);
HSPairs∗hmkspairs(HConnect ∗c, char ∗s, char ∗t, HSPairs ∗next);
inthmoved(HConnect ∗c, char ∗uri);
voidhokheaders(HConnect ∗c);
inthparseheaders(HConnect∗, int timeout);
HSPairs∗hparsequery(HConnect ∗c, char ∗search);
inthparsereq(HConnect ∗c, int timeout);
inthprint(Hio∗, char∗, ...);
inthputc(Hio∗, int);
void∗hreadbuf(Hio ∗h, void ∗vsave);
inthredirected(HConnect ∗c, char ∗how, char ∗uri);
voidhreqcleanup(HConnect ∗c);
HFields∗hrevhfields(HFields ∗hf);
HSPairs∗hrevspairs(HSPairs ∗sp);
char∗hstrdup(HConnect ∗c, char ∗s);
inthttp11(HConnect∗);
inthttpfmt(Fmt∗);
char∗httpunesc(HConnect ∗c, char ∗s);
inthunallowed(HConnect ∗, char ∗allowed);
inthungetc(Hio ∗h);
char∗hunload(Hio∗);
inthurlfmt(Fmt∗);
char∗hurlunesc(HConnect ∗c, char ∗s);
inthvprint(Hio∗, char∗, va_list);
inthwrite(Hio∗, void∗, int);
inthxferenc(Hio∗, int);

DESCRIPTION

For now, look at the source, or httpd(8).

SOURCE

­/sys/src/libhttpd

SEE ALSO

bin(2)

BUGS

This is a rough implementation and many details are going to change. 
 

Plan 9  —  September 21, 2002

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026