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

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

Webmaster