Annotation of libwww/Library/src/HTAccess.html, revision 2.17
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.14 luotonen 218: char * location; /* Location for redirection */
2.16 luotonen 219: HTAtom * content_type; /* Content-Type: */
220: int content_length; /* Content-Length: */
221: char * last_modified; /* Last-Modified: */
222: char * expires; /* Expires: */
223: char * uri; /* Uri: */
224: char * message_id; /* Message-Id: */
225: HTList * allowed; /* Allowed: (list of HTAtoms) */
226: HTList * public; /* Public: (list of HTAtoms) */
2.17 ! luotonen 227: char * meta_file; /* File for meta information */
2.14 luotonen 228: char * authorization; /* Authorization: field */
229: HTAAScheme scheme; /* Authentication scheme used */
230: char * auth_string; /* Authentication string */
2.15 luotonen 231: char * www_authenticate;/*WWW-Authenticate: (should be a */
232: /* a HTList *) */
2.14 luotonen 233: HTAAFailReason reason; /* Reason for failing */
2.16 luotonen 234:
2.14 luotonen 235: /*
236: ** Client side AA
237: */
238: HTList * valid_schemes; /* Valid auth.schemes */
239: HTAssocList ** scheme_specifics;/* Scheme-specific parameters */
240: char * prot_template; /* WWW-Protection-Template: field */
241: HTAASetup * setup; /* Doc protection info */
242: HTAARealm * realm; /* Password realm */
243: char * dialog_msg; /* Authentication prompt (client) */
244: HTRetryCallbackType
245: retry_callback; /* Called when password entered */
2.10 timbl 246: };
2.9 timbl 247:
248: </PRE>The elements of the request structure
249: are as follows.
250: <DL>
2.14 luotonen 251: <DT><CODE>method</CODE>
2.13 timbl 252: <DD>An atom for the name of the
253: operation using HTTP <A
254: NAME="z7" HREF="../../Protocols/HTTP/Methods.html">method names</A>.
2.14 luotonen 255: <DT><CODE>conversions</CODE>
2.10 timbl 256: <DD> NULL, or a list of conversions
2.9 timbl 257: which the format manager can do in
258: order to fulfill the request. This
259: is set by the caller of HTAccess.
2.10 timbl 260: Typically points to a list set up
2.9 timbl 261: an initialisation time for example
262: by HTInit.
2.14 luotonen 263: <DT><CODE>from</CODE>
264: <DD>Email format adderss of person
2.9 timbl 265: responible for request
2.14 luotonen 266: <DT><CODE>output_stream</CODE>
267: <DD>NULL or if a specific
2.9 timbl 268: output stream is required, te stream.
2.14 luotonen 269: <DT><CODE>output_format</CODE>
270: <DD>The output format required,
2.9 timbl 271: or a generic format such as www/present
272: (present to user).
2.14 luotonen 273: <DT><CODE>anchor</CODE>
274: <DD>The anchor for teh object in
275: question. NOTE: Set by HTAcesss.
2.13 timbl 276: <DT><A
277: NAME="z6">childAnchor</A>
278: <DD>the anchor for the subobject
279: if any. The object builder should
280: ensure that htis is selected, highlighted,
281: etc when the object is loaded. NOTE:
282: Set by HTAccess.
2.14 luotonen 283: <DT><CODE>simplified</CODE>
284: <DD>Simplified filename (after removing <CODE>..</CODE> etc).
285: <DT><CODE>translated</CODE>
286: <DD>Translated filename (set by function <CODE>HTTranslateReq().</CODE>
287: <CODE>NULL,</CODE> if this is a script execution request.
288: <DT><CODE>script</CODE>
289: <DD>Executable script name (set by <CODE>HTTranslateReq().</CODE>
290: <CODE>NULL</CODE> if not a script request.
291: <DT><CODE>authorization</CODE>
292: <DD><CODE>Authorization:</CODE> field contents.
293: <DT><CODE>scheme</CODE>
294: <DD>Authentication scheme used.
295: <DT><CODE>scheme_specifics</CODE>
296: <DD>Authentication scheme specific information.
297: <DT><CODE>user</CODE>
298: <DD>Authenticated user.
2.9 timbl 299: </DL>
300: Just to make things easier especially
301: for clients, here is a function to
302: return a new blank request:
303: <H2>Create blank request</H2>This request has defaults in -- in
304: most cases it will need some information
305: added before being passed to HTAccess,
306: but it will work as is for a simple
307: request.
2.14 luotonen 308: <PRE>
309: PUBLIC HTRequest * HTRequest_new NOPARAMS;
310:
311:
312: </PRE>
313: <H2>Delete request structure</H2>
314: Frees also conversion list hanging from <CODE>req->conversions.</CODE>
315: <PRE>
316: PUBLIC void HTRequest_delete PARAMS((HTRequest * req));
1.1 timbl 317:
2.9 timbl 318:
2.5 timbl 319: </PRE>
320: <H2>Flags which may be set to control
321: this module</H2>
322: <PRE>extern int HTDiag; /* Flag: load source as plain text */
1.1 timbl 323: extern char * HTClientHost; /* Name or number of telnetting host */
324: extern FILE * logfile; /* File to output one-liners to */
2.7 timbl 325: extern BOOL HTSecure; /* Disable security holes? */
1.1 timbl 326:
327:
328:
2.5 timbl 329: </PRE>
330: <H2>Load a document from relative name</H2>
331: <H3>On Entry,</H3>
332: <DL>
333: <DT>relative_name
2.6 timbl 334: <DD> The relative address
2.5 timbl 335: of the file to be accessed.
336: <DT>here
2.6 timbl 337: <DD> The anchor of the object being
2.5 timbl 338: searched
2.9 timbl 339: <DT>request->anchor
340: <DD> not filled in yet
2.5 timbl 341: </DL>
342:
343: <H3>On Exit,</H3>
344: <DL>
345: <DT>returns YES
2.6 timbl 346: <DD> Success in opening
2.5 timbl 347: file
348: <DT>NO
2.6 timbl 349: <DD> Failure
2.5 timbl 350: </DL>
1.1 timbl 351:
2.5 timbl 352: <PRE>extern BOOL HTLoadRelative PARAMS((
1.1 timbl 353: CONST char * relative_name,
2.9 timbl 354: HTParentAnchor * here,
355: HTRequest * request));
1.1 timbl 356:
357:
2.5 timbl 358: </PRE>
359: <H2>Load a document from absolute name</H2>
360: <H3>On Entry,</H3>
361: <DL>
362: <DT>addr
2.6 timbl 363: <DD> The absolute address of the
364: document to be accessed.
2.5 timbl 365: <DT>filter
2.6 timbl 366: <DD> if YES, treat document as
367: HTML
2.9 timbl 368: <DT>request->anchor
369: <DD> not filled in yet
2.5 timbl 370: </DL>
1.1 timbl 371:
2.5 timbl 372: <PRE>
373: </PRE>
374: <H3>On Exit,</H3>
375: <PRE>
376: </PRE>
377: <DL>
378: <DT>returns YES
2.6 timbl 379: <DD> Success in opening document
2.5 timbl 380: <DT>NO
2.6 timbl 381: <DD> Failure
2.5 timbl 382: </DL>
1.1 timbl 383:
2.9 timbl 384: <PRE>extern BOOL HTLoadAbsolute PARAMS((CONST char * addr,
385: HTRequest * request));
1.1 timbl 386:
387:
2.5 timbl 388: </PRE>
389: <H2>Load a document from absolute name
390: to a stream</H2>
391: <H3>On Entry,</H3>
392: <DL>
393: <DT>addr
2.6 timbl 394: <DD> The absolute address of the
395: document to be accessed.
2.5 timbl 396: <DT>filter
2.6 timbl 397: <DD> if YES, treat document as
398: HTML
2.9 timbl 399: <DT>request->anchor
400: <DD> not filled in yet
2.5 timbl 401: </DL>
402:
403: <H3>On Exit,</H3>
404: <DL>
405: <DT>returns YES
2.6 timbl 406: <DD> Success in opening document
2.5 timbl 407: <DT>NO
2.6 timbl 408: <DD> Failure
2.5 timbl 409: </DL>
410: Note: This is equivalent to HTLoadDocument
2.9 timbl 411: <PRE>extern BOOL HTLoadToStream PARAMS((
412: CONST char * addr,
413: BOOL filter,
414: HTRequest * request));
1.1 timbl 415:
416:
2.5 timbl 417: </PRE>
418: <H2>Load if necessary, and select an
2.9 timbl 419: anchor</H2>The anchor parameter may be a child
420: anchor. The anchor in the request
421: is set to the parent anchor.
2.5 timbl 422: <H3>On Entry,</H3>
423: <DL>
2.9 timbl 424: <DT>anchor
425: <DD> may be a child or parenet
426: anchor or 0 in which case there is
427: no effect.
428: <DT>request->anchor
429: <DD> Not set
430: yet.
2.5 timbl 431: </DL>
432:
433: <H3>On Exit,</H3>
434: <PRE>
435: </PRE>
436: <DL>
437: <DT>returns YES
2.6 timbl 438: <DD> Success
2.5 timbl 439: <DT>returns NO
2.6 timbl 440: <DD> Failure
2.9 timbl 441: <DT>request->anchor
442: <DD> The parenet anchor.
2.5 timbl 443: </DL>
444:
2.9 timbl 445: <PRE>extern BOOL HTLoadAnchor PARAMS((HTAnchor * a,
446: HTRequest * request));
1.1 timbl 447:
448:
2.5 timbl 449: </PRE>
450: <H2>Make a stream for Saving object back</H2>
451: <H3>On Entry,</H3>
452: <DL>
2.9 timbl 453: <DT>request->anchor
454: <DD> is valid anchor which
455: has previously beeing loaded
2.5 timbl 456: </DL>
457:
458: <H3>On exit,</H3>
459: <DL>
460: <DT>returns
2.6 timbl 461: <DD> 0 if error else a stream
462: to save the object to.
2.5 timbl 463: </DL>
464:
465: <PRE>
466:
2.13 timbl 467: extern HTStream * HTSaveStream PARAMS((HTRequest * request));
1.1 timbl 468:
469:
2.5 timbl 470: </PRE>
471: <H2>Search</H2>Performs a search on word given by
472: the user. Adds the search words to
473: the end of the current address and
474: attempts to open the new address.
475: <H3>On Entry,</H3>
476: <DL>
477: <DT>*keywords
2.6 timbl 478: <DD> space-separated keyword
2.5 timbl 479: list or similar search list
480: <DT>here
2.6 timbl 481: <DD> The anchor of the object being
2.5 timbl 482: searched
483: </DL>
1.1 timbl 484:
2.9 timbl 485: <PRE>extern BOOL HTSearch PARAMS((
486: CONST char * keywords,
487: HTParentAnchor* here,
488: HTRequest * request));
1.1 timbl 489:
490:
2.5 timbl 491: </PRE>
492: <H2>Search Given Indexname</H2>Performs a keyword search on word
493: given by the user. Adds the keyword
494: to the end of the current address
495: and attempts to open the new address.
496: <H3>On Entry,</H3>
497: <DL>
498: <DT>*keywords
2.6 timbl 499: <DD> space-separated keyword
2.5 timbl 500: list or similar search list
501: <DT>*indexname
2.6 timbl 502: <DD> is name of object search
2.5 timbl 503: is to be done on.
504: </DL>
1.1 timbl 505:
2.5 timbl 506: <PRE>extern BOOL HTSearchAbsolute PARAMS((
2.9 timbl 507: CONST char * keywords,
508: CONST char * indexname,
509: HTRequest * request));
1.1 timbl 510:
511:
2.5 timbl 512: </PRE>
2.9 timbl 513: <H2>Register an access method</H2>An access method is defined by an
514: HTProtocol structure which point
515: to the routines for performing the
516: various logical operations on an
517: object: in HTTP terms, GET, PUT,
518: and POST.<P>
519: Each of these routine takes as a
520: parameter a <A
521: NAME="z2" HREF="#z1">request structure</A> containing
522: details ofthe request. When the
523: protocol class routine is called,
524: the anchor elemnt in the request
525: is already valid (made valid by HTAccess).
526: <PRE>typedef struct _HTProtocol {
1.1 timbl 527: char * name;
528:
2.11 timbl 529: int (*load)PARAMS((HTRequest * request));
1.1 timbl 530:
2.11 timbl 531: HTStream* (*saveStream)PARAMS((HTRequest * request));
532:
2.9 timbl 533: HTStream* (*postStream)PARAMS((
534: HTRequest * request,
535: HTParentAnchor* postTo));
1.1 timbl 536:
537: } HTProtocol;
538:
539: extern BOOL HTRegisterProtocol PARAMS((HTProtocol * protocol));
540:
541:
2.5 timbl 542: </PRE>
543: <H2>Generate the anchor for the home
544: page</H2>
545: <PRE>
546: </PRE>As it involves file access, this
547: should only be done once when the
548: program first runs. This is a default
549: algorithm -- browser don't HAVE to
550: use this.
551: <PRE>extern HTParentAnchor * HTHomeAnchor NOPARAMS;
1.1 timbl 552:
553: #endif /* HTACCESS_H */
2.11 timbl 554:
2.12 timbl 555: </PRE>end of HTAccess</BODY>
2.9 timbl 556: </HTML>
Webmaster