Hrec's are the basic entity for exchanging sets of information within libht. An hrec is a table of variable/value pairs with optional typing information. By default, variables and their values are normal C strings. Included in this modules is a interface to the HTTP GET and POST methods.
- hrec * newhrec ()
- void hrfree (hrec * hr)
- char * hrget (hrec * h, char * var)
- int hrgetint (hrec * h, char * var)
- double hrgetdouble (hrec * h, char * var)
- char * hrgetvis (hrec * h, char * var)
- char * hrisvis (hrec * h, char * var)
- int hradd (hrec * h, char * var, char * val)
- void hrappend (hrec * h, char * var, char * val, int flags)
- int hraddf (hrec * h, char * var, char * fmt, ...)
- void hraddint (hrec * h, char * var, int ival)
- void hradddouble (hrec * h, char * var, double dval)
- void hrmerge (hrec * old, hrec * new)
- int hrsettype (hrec * h, char * var, int fmt, int subfmt, int (* uvfy) ())
- void hrtypeadd (hrec * h, char * var, char * val, int fmt, int subfmt, int (* uvfy) ())
- void hrsetflg (hrec * h, char * var, int flags)
- void hrclrflg (hrec * h, char * var, int flags)
- int hrvrfy (hrec * r, hrecerr * err)
- hrec * hrgetparams (hrec * h, int ac, char ** av)
- hrec * hrreadget (hrec * h, int ac, char ** av)
- hrec * hrreadpost (hrec * h)
- hrec * hrfind (hrec * h, char * var, char * val)
- hrec * hrreadfile (char * file)
- hrec * hrreadfp (FILE * fp)
- int hrwritefile (char * file, hrec * recs)
- void hrlink (hrec ** list, hrec * new)
- void hrdelink (hrec ** list, hrec * old)
- hrec * newhrec ()
- Create an empty, initialized hrec.
- void hrfree (hrec * hr)
- Free the storage created by newhrec()
- char * hrget (hrec * h, char * var)
- get the value of variable var. If the variable is not found, hrget returns an empty string not null.
- int hrgetint (hrec * h, char * var)
- get the integer value of this variable. hrgetint is like atol(3), in that a non-integer value will cause not terribly useful results.
- double hrgetdouble (hrec * h, char * var)
- get the double floating value of this variable. hrgetdouble is like atof(3), in that a non-double value will cause not terribly useful results.
- char * hrgetvis (hrec * h, char * var)
- Like hrget, except this function obey's the HR_HIDDEN flag, returning an empty string if it is hidden.
- char * hrisvis (hrec * h, char * var)
- Asks whether a variable has been hidden or not. If it is hidden, hrisvis() returns the null pointer, rather than an empty string.
- int hradd (hrec * h, char * var, char * val)
add the variable varwith value valto hrec h
- void hrappend (hrec * h, char * var, char * val, int flags)
- int hraddf (hrec * h, char * var, char * fmt, ...)
- Like hradd(), but the val portion uses a standard printf(3) like interface.
- void hraddint (hrec * h, char * var, int ival)
- Add an integer type variable to the hrec. These maybe accessed as either the string (hrget) or integer represetation (hrgetint).
- void hradddouble (hrec * h, char * var, double dval)
- Add a double floating point type variable to the hrec. These maybe accessed as either the string (hrget) or the double represetation (hrgetdouble).
- void hrmerge (hrec * old, hrec * new)
- Merge hrec new into hrec old. This is essentially a glorified copy, but hrmerge() obeys the HR_NOMERGE flag in each element, giving a way to mask certain elements in old from being overwritten.
- int hrsettype (hrec * h, char * var, int fmt, int subfmt, int (* uvfy) ())
- Change the type of var to the format in fmt and subfmt in subfmt. Formats are basic types, and subformats qualify the base type. These are set implicitly by hradd(), hraddint(), and hradddouble(). Currently, these are the known types:
HRF_TEXT Text format, any length; the default. HRF_CHAR subfmt = { max array size } A bound character array. Subfmt specifies the maximum length of the array. Generates an error if the field is overflowed. HRF_INT subfmt = { HRSF_DEC, HRSF_HEX, HRSF_OCT } An integer value, scanned as decimal, hex or octal. HRF_DOUBLE A double floating point value. HRF_DATE A Date value. Unimplimented. HRF_URL A URL value. Unimplimented. HRF_MONEY A Money value. Unimplemented. case HRF_USER: Greater that HRF_USER is reserved to user formats/subformats.Additionally, you can specify a verify routine to either override the base type's verification, or supply your own datatype. The verify function is called:
uvfy (hrecerr * err);where the context of the call is in err, and the return value is 0 on success, -1 on error. It is up to the verifier to set any additional error information (look at the structure...)
- void hrtypeadd (hrec * h, char * var, char * val, int fmt, int subfmt, int (* uvfy) ())
- Similar to hrsettype, but will create the variable if necessary.
- void hrsetflg (hrec * h, char * var, int flags)
- Several flags control what other functions in this package do.
HR_HIDDEN don't attempt to bind this node in a function which uses all the variables in this hrec implicitly (eg, htbindform()). HR_NOMERGE don't merge this field when performing an hrmerge().
- void hrclrflg (hrec * h, char * var, int flags)
- Clear the specified flags from above.
- int hrvrfy (hrec * r, hrecerr * err)
- Verify an hrec. You normally want to verify the hrec when an untrusted facility (read: user) has diddled with somthing. The usual routine is to create a default record which describes the expect var/val record with their types set appropriately, read the record in using something like hrgetparams(), and finally verify the input with hrvrfy().
hrvyfy() returns -1 on error, 0 otherwise. Additionally, you can specify an hrecerr structure to capture the actual reason/field that hrvrfy() is whining about. See the structure definition in html.h for further information.
- hrec * hrgetparams (hrec * h, int ac, char ** av)
- Do The Right Thing. hrgetparams() takes main()'s argv and argc and gets the parameters from the browser, figuring out whether it was done with the POST or GET method. If you need input verification, you should supply a default record h with the type fields set. Otherwise, hrgetparams() will happily create a text only record if h is null.
- hrec * hrreadget (hrec * h, int ac, char ** av)
- If you're absolutely, positively, pedantically certain that it will be a GET method, you can directly hrreadget () to do the parsing of the command line.
- hrec * hrreadpost (hrec * h)
- If you're absolutely, positively, pedantically certain that it will be a POST method, you can directly hrreadpost () to do the parsing of the command line. Unlike hrreadget, there may be some reason to insist on a POST since GET shows up in the browser's Location window.
- hrec * hrfind (hrec * h, char * var, char * val)
- Find the hrec in the list of hrecs which contains a "var" whose value matches "val". Obscure.
- hrec * hrreadfile (char * file)
- Read the contents of a hrec file into a list of hrec's. The format of the file is:
field1: value1 field2: value2 field3: line1 field3: line2 field3: line3 field4: value4 [...] ^L []*Returns a pointer to the first element if successful, null otherwise.
- hrec * hrreadfp (FILE * fp)
- Same as above, but reads from the already open FILE. FILE remains open after hrreadfp is done with it.
- int hrwritefile (char * file, hrec * recs)
- The reverse of hrreadfile: produce a file of hrecs which is readable by hrreadfile().