Annotation of libwww/Library/src/HTAccess.html, revision 2.18

2.9       timbl       1: <HTML>
                      2: <HEAD>
2.6       timbl       3: <TITLE>HTAccess:  Access manager  for libwww</TITLE>
2.13      timbl       4: <NEXTID N="z8">
2.9       timbl       5: </HEAD>
2.5       timbl       6: <BODY>
                      7: <H1>Access Manager</H1>This module keeps a list of valid
                      8: protocol (naming scheme) specifiers
                      9: with associated access code.  It
                     10: allows documents to be loaded given
                     11: various combinations of parameters.
                     12: New access protocols may be registered
                     13: at any time.<P>
2.9       timbl      14: Note: HTRequest defined and request
                     15: parametsr added to almost all calls
                     16: 18 Nov 1993.<P>
2.5       timbl      17: Part of the <A
2.9       timbl      18: NAME="z0" HREF="Overview.html">libwww library</A> .
2.5       timbl      19: <PRE>#ifndef HTACCESS_H
1.1       timbl      20: #define HTACCESS_H
                     21: 
                     22: /*     Definition uses:
                     23: */
                     24: #include "HTUtils.h"
2.16      luotonen   25: #include "HTList.h"
1.1       timbl      26: #include "tcp.h"
2.14      luotonen   27: 
1.1       timbl      28: 
                     29: #ifdef SHORT_NAMES
2.8       timbl      30: #define HTClientHost           HTClHost
                     31: #define HTSearchAbsolute       HTSeAbso
                     32: #define HTOutputStream         HTOuStre
                     33: #define HTOutputFormat         HTOuForm
1.1       timbl      34: #endif
                     35: 
2.16      luotonen   36: typedef enum {
                     37:        METHOD_INVALID  = 0,
                     38:        METHOD_GET      = 1,
                     39:        METHOD_HEAD,
                     40:        METHOD_POST,
                     41:        METHOD_PUT,
                     42:        METHOD_DELETE,
                     43:        METHOD_CHECKOUT,
                     44:        METHOD_CHECKIN,
                     45:        METHOD_SHOWMETHOD,
                     46:        METHOD_LINK,
                     47:        METHOD_UNLINK,
                     48:        MAX_METHODS
                     49: } HTMethod;
                     50: 
                     51: 
                     52: </PRE>
                     53: 
                     54: <H2>Methods</H2>
                     55: <PRE>
                     56: 
                     57: /*     Get method enum value
                     58: **     ---------------------
                     59: */
                     60: PUBLIC HTMethod HTMethod_enum PARAMS((char * name));
                     61: 
                     62: 
                     63: /*     Get method name
                     64: **     ---------------
                     65: */
                     66: PUBLIC char * HTMethod_name PARAMS((HTMethod method));
                     67: 
                     68: 
                     69: /* PUBLIC                                              HTMethod_inList()
                     70: **             IS A METHOD IN A LIST OF METHOD NAMES
                     71: ** ON ENTRY:
                     72: **     method          is the method to look for.
                     73: **     list            is a list of method names.
                     74: **
                     75: ** ON EXIT:
                     76: **     returns         YES, if method was found.
                     77: **                     NO, if not found.
                     78: */
                     79: PUBLIC BOOL HTMethod_inList PARAMS((HTMethod   method,
                     80:                                    HTList *    list));
                     81: </PRE>
                     82: <H2>Match Template Against Filename</H2>
                     83: <PRE>
                     84: /* PUBLIC                                              HTAA_templateMatch()
                     85: **             STRING COMPARISON FUNCTION FOR FILE NAMES
                     86: **                WITH ONE WILDCARD * IN THE TEMPLATE
                     87: ** NOTE:
                     88: **     This is essentially the same code as in HTRules.c, but it
                     89: **     cannot be used because it is embedded in between other code.
                     90: **     (In fact, HTRules.c should use this routine, but then this
                     91: **      routine would have to be more sophisticated... why is life
                     92: **      sometimes so hard...)
                     93: **
                     94: ** ON ENTRY:
                     95: **     template        is a template string to match the file name
                     96: **                     agaist, may contain a single wildcard
                     97: **                     character * which matches zero or more
                     98: **                     arbitrary characters.
                     99: **     filename        is the filename (or pathname) to be matched
                    100: **                     agaist the template.
                    101: **
                    102: ** ON EXIT:
                    103: **     returns         YES, if filename matches the template.
                    104: **                     NO, otherwise.
                    105: */
                    106: PUBLIC BOOL HTAA_templateMatch PARAMS((CONST char * template, 
                    107:                                       CONST char * filename));
                    108: 
                    109: 
                    110: </PRE>
                    111: 
                    112: The following have to be defined
2.10      timbl     113: in advance of the other include files
                    114: because of circular references.
                    115: <PRE>typedef struct _HTRequest HTRequest;
                    116: 
2.14      luotonen  117: /*
                    118: ** Callback to call when username and password
                    119: ** have been prompted.
                    120: */
                    121: typedef int (*HTRetryCallbackType) PARAMS((HTRequest * req));
                    122: 
                    123: 
2.10      timbl     124: #include "HTAnchor.h"
                    125: #include <A
                    126: NAME="z3" HREF="HTFormat.html">"HTFormat.h"</A>
2.15      luotonen  127: #include "HTAAUtil.h"          /* HTAAScheme, HTAAFailReason */
2.14      luotonen  128: #include "HTAABrow.h"          /* HTAASetup */
2.10      timbl     129: 
                    130: 
1.1       timbl     131: /*     Return codes from load routines:
                    132: **
                    133: **     These codes may be returned by the protocol modules,
                    134: **     and by the HTLoad routines.
                    135: **     In general, positive codes are OK and negative ones are bad.
                    136: */
                    137: 
                    138: #define HT_NO_DATA -9999       /* return code: OK but no data was loaded */
                    139:                                /* Typically, other app started or forked */
                    140: 
2.5       timbl     141: </PRE>
2.6       timbl     142: <H2>Default Addresses</H2>These control the home page selection.
2.8       timbl     143: To mess with these for normal browses
2.6       timbl     144: is asking for user confusion.
                    145: <PRE>#define LOGICAL_DEFAULT "WWW_HOME"  /* Defined to be the home page */
1.1       timbl     146: 
2.6       timbl     147: #ifndef PERSONAL_DEFAULT
                    148: #define PERSONAL_DEFAULT "WWW/default.html"    /* in home directory */
                    149: #endif
                    150: #ifndef LOCAL_DEFAULT_FILE
1.1       timbl     151: #define LOCAL_DEFAULT_FILE "/usr/local/lib/WWW/default.html"
2.6       timbl     152: #endif
2.7       timbl     153: /*  If one telnets to a www access point,
                    154:     it will look in this file for home page */
                    155: #ifndef REMOTE_POINTER
                    156: #define REMOTE_POINTER  "/etc/www-remote.url"  /* can't be file */
                    157: #endif
                    158: /* and if that fails it will use this. */
2.6       timbl     159: #ifndef REMOTE_ADDRESS
1.1       timbl     160: #define REMOTE_ADDRESS  "http://info.cern.ch/remote.html"  /* can't be file */
                    161: #endif
                    162: 
                    163: /* If run from telnet daemon and no -l specified, use this file:
                    164: */
                    165: #ifndef DEFAULT_LOGFILE
                    166: #define DEFAULT_LOGFILE        "/usr/adm/www-log/www-log"
                    167: #endif
                    168: 
                    169: /*     If the home page isn't found, use this file:
                    170: */
                    171: #ifndef LAST_RESORT
2.6       timbl     172: #define LAST_RESORT    "http://info.cern.ch/default.html"
1.1       timbl     173: #endif
                    174: 
2.10      timbl     175: 
2.9       timbl     176: </PRE>
                    177: <H2><A
                    178: NAME="z1">The Request structure</A></H2>When a request is handled, all kinds
                    179: of things about it need to be passed
                    180: along.  These are all put into a
2.11      timbl     181: HTRequest structure.  Note there
                    182: is also a <A
2.12      timbl     183: NAME="z4" HREF="HTFormat.html#z17">global list of converters</A>
                    184: .
2.10      timbl     185: <PRE>struct _HTRequest {
2.15      luotonen  186:        HTList *        <A NAME="z5">conversions</A> ;
                    187:                                        /* conversions allowed in this case */
                    188:        HTList *        encodings;      /* allowed content-encodings      */
                    189:        HTList *        languages;      /* accepted content-languages     */
2.9       timbl     190:        char *          from;           /* On behalf of whom? */
2.15      luotonen  191:        char *          user_agent;     /* Browser software               */
2.9       timbl     192:        HTStream*       output_stream;  /* For non-interactive, set this */ 
2.10      timbl     193:        HTAtom *        output_format;  /* To convert on load, set this */
2.9       timbl     194:        BOOL            (*callback) PARAMS((
                    195:                                struct _HTRequest* request,
                    196:                                void *param));
                    197:        void *          context;        /* caller data -- HTAccess unaware */
                    198:        HTParentAnchor* anchor;         /* Set by HTAccess */
2.12      timbl     199:        void *          using_cache;    /* pointer to cache element if cache hit */
2.16      luotonen  200:        HTMethod        method;         /* HTTP method */
                    201:        HTChildAnchor * childAnchor;    /* For element within the object  */
2.14      luotonen  202:        int             status_code;    /* HTTP status code               */
                    203:        char *          reason_line;    /* Reason for failing             */
2.16      luotonen  204: 
2.14      luotonen  205:        /*
                    206:        ** Server side info about request
                    207:        */
2.15      luotonen  208:        int             soc;            /* Socket from which request came */
                    209:        HTInputSocket * isoc;           /* InputSocket object for reading */
2.14      luotonen  210:        char *          request;        /* First request line as received */
                    211:        char *          argument;       /* Arg to HTTP method as given    */
                    212:        char *          arg_path;       /* Pathinfo part of argument      */
2.16      luotonen  213:        char *          arg_keywords;   /* Keyword part of URL            */
                    214:        char *          translated;     /* Translated pathname            */
                    215:        char *          script;         /* Executable server script path  */
2.14      luotonen  216:        char *          script_pathinfo;/* Path info after script name    */
2.15      luotonen  217:        char *          script_pathtrans;/* Path info translated          */
2.18    ! luotonen  218:        HTAtom *        content_language;/* Language                      */
        !           219:        HTAtom *        content_encoding;/* Encoding                      */
2.14      luotonen  220:        char *          location;       /* Location for redirection       */
2.16      luotonen  221:        HTAtom *        content_type;   /* Content-Type:                  */
                    222:        int             content_length; /* Content-Length:                */
                    223:        char *          last_modified;  /* Last-Modified:                 */
                    224:        char *          expires;        /* Expires:                       */
                    225:        char *          uri;            /* Uri:                           */
                    226:        char *          message_id;     /* Message-Id:                    */
                    227:        HTList *        allowed;        /* Allowed: (list of HTAtoms)     */
                    228:        HTList *        public;         /* Public: (list of HTAtoms)      */
2.17      luotonen  229:        char *          meta_file;      /* File for meta information      */
2.14      luotonen  230:        char *          authorization;  /* Authorization: field           */
                    231:        HTAAScheme      scheme;         /* Authentication scheme used     */
                    232:        char *          auth_string;    /* Authentication string          */
2.15      luotonen  233:        char *          www_authenticate;/*WWW-Authenticate: (should be a */
                    234:                                        /* a HTList *)                    */
2.14      luotonen  235:        HTAAFailReason  reason;         /* Reason for failing             */
2.16      luotonen  236: 
2.14      luotonen  237:        /*
                    238:        ** Client side AA
                    239:        */
                    240:        HTList *        valid_schemes;  /* Valid auth.schemes             */
                    241:        HTAssocList **  scheme_specifics;/* Scheme-specific parameters    */
                    242:        char *          prot_template;  /* WWW-Protection-Template: field */
                    243:        HTAASetup *     setup;          /* Doc protection info            */
                    244:        HTAARealm *     realm;          /* Password realm                 */
                    245:        char *          dialog_msg;     /* Authentication prompt (client) */
                    246:        HTRetryCallbackType
                    247:                        retry_callback; /* Called when password entered   */
2.10      timbl     248: };
2.9       timbl     249: 
                    250: </PRE>The elements of the request structure
                    251: are as follows.
                    252: <DL>
2.14      luotonen  253: <DT><CODE>method</CODE>
2.13      timbl     254: <DD>An atom for the name of the
                    255: operation using HTTP <A
                    256: NAME="z7" HREF="../../Protocols/HTTP/Methods.html">method names</A>.
2.14      luotonen  257: <DT><CODE>conversions</CODE>
2.10      timbl     258: <DD> NULL, or a list of conversions
2.9       timbl     259: which the format manager can do in
                    260: order to fulfill the request.  This
                    261: is set by the caller of HTAccess.
2.10      timbl     262: Typically points to a list set up
2.9       timbl     263: an initialisation time for example
                    264: by HTInit.
2.14      luotonen  265: <DT><CODE>from</CODE>
                    266: <DD>Email format adderss of person
2.9       timbl     267: responible for request
2.14      luotonen  268: <DT><CODE>output_stream</CODE>
                    269: <DD>NULL or if a specific
2.9       timbl     270: output stream is required, te stream.
2.14      luotonen  271: <DT><CODE>output_format</CODE>
                    272: <DD>The output format required,
2.9       timbl     273: or a generic format such as www/present
                    274: (present to user). 
2.14      luotonen  275: <DT><CODE>anchor</CODE>
                    276: <DD>The anchor for teh object in
                    277: question.  NOTE: Set by HTAcesss.
2.13      timbl     278: <DT><A
                    279: NAME="z6">childAnchor</A>
                    280: <DD>the anchor for the subobject
                    281: if any.  The object builder should
                    282: ensure that htis is selected, highlighted,
                    283: etc when the object is loaded. NOTE:
                    284: Set by HTAccess.
2.14      luotonen  285: <DT><CODE>simplified</CODE>
                    286: <DD>Simplified filename (after removing <CODE>..</CODE> etc).
                    287: <DT><CODE>translated</CODE>
                    288: <DD>Translated filename (set by function <CODE>HTTranslateReq().</CODE>
                    289: <CODE>NULL,</CODE> if this is a script execution request.
                    290: <DT><CODE>script</CODE>
                    291: <DD>Executable script name (set by <CODE>HTTranslateReq().</CODE>
                    292: <CODE>NULL</CODE> if not a script request.
                    293: <DT><CODE>authorization</CODE>
                    294: <DD><CODE>Authorization:</CODE> field contents.
                    295: <DT><CODE>scheme</CODE>
                    296: <DD>Authentication scheme used.
                    297: <DT><CODE>scheme_specifics</CODE>
                    298: <DD>Authentication scheme specific information.
                    299: <DT><CODE>user</CODE>
                    300: <DD>Authenticated user.
2.9       timbl     301: </DL>
                    302: Just to make things easier especially
                    303: for clients, here is a function to
                    304: return a new blank request:
                    305: <H2>Create blank request</H2>This request has defaults in -- in
                    306: most cases it will need some information
                    307: added before being passed to HTAccess,
                    308: but it will work as is for a simple
                    309: request.
2.14      luotonen  310: <PRE>
                    311: PUBLIC HTRequest * HTRequest_new NOPARAMS;
                    312: 
                    313: 
                    314: </PRE>
                    315: <H2>Delete request structure</H2>
                    316: Frees also conversion list hanging from <CODE>req-&gt;conversions.</CODE>
                    317: <PRE>
                    318: PUBLIC void HTRequest_delete PARAMS((HTRequest * req));
1.1       timbl     319: 
2.9       timbl     320: 
2.5       timbl     321: </PRE>
                    322: <H2>Flags which may be set to control
                    323: this module</H2>
                    324: <PRE>extern int HTDiag;                        /* Flag: load source as plain text */
1.1       timbl     325: extern char * HTClientHost;            /* Name or number of telnetting host */
                    326: extern FILE * logfile;                 /* File to output one-liners to */
2.7       timbl     327: extern BOOL HTSecure;                  /* Disable security holes? */
1.1       timbl     328: 
                    329: 
                    330: 
2.5       timbl     331: </PRE>
                    332: <H2>Load a document from relative name</H2>
                    333: <H3>On Entry,</H3>
                    334: <DL>
                    335: <DT>relative_name
2.6       timbl     336: <DD> The relative address
2.5       timbl     337: of the file to be accessed.
                    338: <DT>here
2.6       timbl     339: <DD> The anchor of the object being
2.5       timbl     340: searched
2.9       timbl     341: <DT>request->anchor
                    342: <DD> not filled in yet
2.5       timbl     343: </DL>
                    344: 
                    345: <H3>On Exit,</H3>
                    346: <DL>
                    347: <DT>returns    YES
2.6       timbl     348: <DD> Success in opening
2.5       timbl     349: file
                    350: <DT>NO
2.6       timbl     351: <DD> Failure 
2.5       timbl     352: </DL>
1.1       timbl     353: 
2.5       timbl     354: <PRE>extern  BOOL HTLoadRelative PARAMS((
1.1       timbl     355:                CONST char *            relative_name,
2.9       timbl     356:                HTParentAnchor *        here,
                    357:                HTRequest *             request));
1.1       timbl     358: 
                    359: 
2.5       timbl     360: </PRE>
                    361: <H2>Load a document from absolute name</H2>
                    362: <H3>On Entry,</H3>
                    363: <DL>
                    364: <DT>addr
2.6       timbl     365: <DD> The absolute address of the
                    366: document to be accessed.
2.5       timbl     367: <DT>filter
2.6       timbl     368: <DD> if YES, treat document as
                    369: HTML
2.9       timbl     370: <DT>request->anchor
                    371: <DD> not filled in yet
2.5       timbl     372: </DL>
1.1       timbl     373: 
2.5       timbl     374: <PRE>
                    375: </PRE>
                    376: <H3>On Exit,</H3>
                    377: <PRE>
                    378: </PRE>
                    379: <DL>
                    380: <DT>returns YES
2.6       timbl     381: <DD> Success in opening document
2.5       timbl     382: <DT>NO
2.6       timbl     383: <DD> Failure 
2.5       timbl     384: </DL>
1.1       timbl     385: 
2.9       timbl     386: <PRE>extern BOOL HTLoadAbsolute PARAMS((CONST char * addr,
                    387:                HTRequest *             request));
1.1       timbl     388: 
                    389: 
2.5       timbl     390: </PRE>
                    391: <H2>Load a document from absolute name
                    392: to a stream</H2>
                    393: <H3>On Entry,</H3>
                    394: <DL>
                    395: <DT>addr
2.6       timbl     396: <DD> The absolute address of the
                    397: document to be accessed.
2.5       timbl     398: <DT>filter
2.6       timbl     399: <DD> if YES, treat document as
                    400: HTML
2.9       timbl     401: <DT>request->anchor
                    402: <DD> not filled in yet
2.5       timbl     403: </DL>
                    404: 
                    405: <H3>On Exit,</H3>
                    406: <DL>
                    407: <DT>returns YES
2.6       timbl     408: <DD> Success in opening document
2.5       timbl     409: <DT>NO
2.6       timbl     410: <DD> Failure 
2.5       timbl     411: </DL>
                    412: Note: This is equivalent to HTLoadDocument
2.9       timbl     413: <PRE>extern BOOL HTLoadToStream PARAMS((
                    414:                CONST char *            addr,
                    415:                BOOL                    filter,
                    416:                HTRequest *             request));
1.1       timbl     417: 
                    418: 
2.5       timbl     419: </PRE>
                    420: <H2>Load if necessary, and select an
2.9       timbl     421: anchor</H2>The anchor parameter may be a child
                    422: anchor. The anchor in the request
                    423: is set to the parent anchor.
2.5       timbl     424: <H3>On Entry,</H3>
                    425: <DL>
2.9       timbl     426: <DT>anchor
                    427: <DD> may be a child or parenet
                    428: anchor or 0 in which case there is
                    429: no effect.
                    430: <DT>request->anchor      
                    431: <DD>    Not set
                    432: yet.
2.5       timbl     433: </DL>
                    434: 
                    435: <H3>On Exit,</H3>
                    436: <PRE>
                    437: </PRE>
                    438: <DL>
                    439: <DT>returns YES
2.6       timbl     440: <DD> Success
2.5       timbl     441: <DT>returns NO
2.6       timbl     442: <DD> Failure 
2.9       timbl     443: <DT>request->anchor
                    444: <DD> The parenet anchor.
2.5       timbl     445: </DL>
                    446: 
2.9       timbl     447: <PRE>extern BOOL HTLoadAnchor PARAMS((HTAnchor * a,
                    448:                        HTRequest *             request));
1.1       timbl     449: 
                    450: 
2.5       timbl     451: </PRE>
                    452: <H2>Make a stream for Saving object back</H2>
                    453: <H3>On Entry,</H3>
                    454: <DL>
2.9       timbl     455: <DT>request->anchor
                    456: <DD> is valid anchor which
                    457: has previously beeing loaded
2.5       timbl     458: </DL>
                    459: 
                    460: <H3>On exit,</H3>
                    461: <DL>
                    462: <DT>returns
2.6       timbl     463: <DD> 0 if error else a stream
                    464: to save the object to.
2.5       timbl     465: </DL>
                    466: 
                    467: <PRE>
                    468: 
2.13      timbl     469: extern HTStream * HTSaveStream PARAMS((HTRequest * request));
1.1       timbl     470: 
                    471: 
2.5       timbl     472: </PRE>
                    473: <H2>Search</H2>Performs a search on word given by
                    474: the user. Adds the search words to
                    475: the end of the current address and
                    476: attempts to open the new address.
                    477: <H3>On Entry,</H3>
                    478: <DL>
                    479: <DT>*keywords
2.6       timbl     480: <DD> space-separated keyword
2.5       timbl     481: list or similar search list
                    482: <DT>here
2.6       timbl     483: <DD> The anchor of the object being
2.5       timbl     484: searched
                    485: </DL>
1.1       timbl     486: 
2.9       timbl     487: <PRE>extern BOOL HTSearch PARAMS((
                    488:                CONST char *            keywords,
                    489:                HTParentAnchor*         here,
                    490:                HTRequest *             request));
1.1       timbl     491: 
                    492: 
2.5       timbl     493: </PRE>
                    494: <H2>Search Given Indexname</H2>Performs a keyword search on word
                    495: given by the user. Adds the keyword
                    496: to  the end of the current address
                    497: and attempts to open the new address.
                    498: <H3>On Entry,</H3>
                    499: <DL>
                    500: <DT>*keywords
2.6       timbl     501: <DD> space-separated keyword
2.5       timbl     502: list or similar search list
                    503: <DT>*indexname
2.6       timbl     504: <DD> is name of object search
2.5       timbl     505: is to be done on.
                    506: </DL>
1.1       timbl     507: 
2.5       timbl     508: <PRE>extern BOOL HTSearchAbsolute PARAMS((
2.9       timbl     509:        CONST char *            keywords,
                    510:        CONST char *            indexname,
                    511:        HTRequest *             request));
1.1       timbl     512: 
                    513: 
2.5       timbl     514: </PRE>
2.9       timbl     515: <H2>Register an access method</H2>An access method is defined by an
                    516: HTProtocol structure which point
                    517: to the routines for performing the
                    518: various logical operations on an
                    519: object: in HTTP terms,  GET, PUT,
                    520: and POST.<P>
                    521: Each of these routine takes as a
                    522: parameter a <A
                    523: NAME="z2" HREF="#z1">request structure</A> containing
                    524: details ofthe request.  When the
                    525: protocol class routine is called,
                    526: the anchor elemnt in the request
                    527: is already valid (made valid by HTAccess).
                    528: <PRE>typedef struct _HTProtocol {
1.1       timbl     529:        char * name;
                    530:        
2.11      timbl     531:        int (*load)PARAMS((HTRequest *  request));
1.1       timbl     532:                
2.11      timbl     533:        HTStream* (*saveStream)PARAMS((HTRequest *      request));
                    534: 
2.9       timbl     535:        HTStream* (*postStream)PARAMS((
                    536:                                HTRequest *     request,
                    537:                                HTParentAnchor* postTo));
1.1       timbl     538: 
                    539: } HTProtocol;
                    540: 
                    541: extern BOOL HTRegisterProtocol PARAMS((HTProtocol * protocol));
                    542: 
                    543: 
2.5       timbl     544: </PRE>
                    545: <H2>Generate the anchor for the home
                    546: page</H2>
                    547: <PRE>
                    548: </PRE>As it involves file access, this
                    549: should only be done once when the
                    550: program first runs. This is a default
                    551: algorithm -- browser don't HAVE to
                    552: use this.
                    553: <PRE>extern HTParentAnchor * HTHomeAnchor NOPARAMS;
1.1       timbl     554: 
                    555: #endif /* HTACCESS_H */
2.11      timbl     556: 
2.12      timbl     557: </PRE>end of HTAccess</BODY>
2.9       timbl     558: </HTML>

Webmaster