Annotation of libwww/Library/src/HTAccess.html, revision 2.48
2.9 timbl 1: <HTML>
2: <HEAD>
2.45 frystyk 3: <TITLE>Access manager for libwww</TITLE>
2.19 timbl 4: <NEXTID N="z11">
2.9 timbl 5: </HEAD>
2.5 timbl 6: <BODY>
2.39 frystyk 7:
2.33 frystyk 8: <H1>Access Manager</H1>
2.39 frystyk 9:
2.41 frystyk 10: <PRE>
11: /*
12: ** (c) COPYRIGHT CERN 1994.
13: ** Please first read the full copyright statement in the file COPYRIGH.
14: */
15: </PRE>
16:
2.39 frystyk 17: This module keeps a list of valid protocol (naming scheme) specifiers
18: with associated access code. It allows documents to be loaded given
19: various combinations of parameters. New access protocols may be
20: registered at any time.<P>
21:
22: This module is implemented by <A HREF="HTAccess.c">HTAccess.c</A>, and
23: it is a part of the <A NAME="z10"
2.46 frystyk 24: HREF="http://www.w3.org/hypertext/WWW/Library/User/Guide/Guide.html">Library
2.39 frystyk 25: of Common Code</A>. <P>
26:
27: The module contains a lot of stuff but the main topics are:
28:
29: <UL>
2.41 frystyk 30: <LI><A HREF="#Library">Initializing and Terminating the Library</A>
2.46 frystyk 31: <LI><A HREF="#log">Logging of requests</A>
2.39 frystyk 32: <LI><A HREF="#Methods">Management of access methods</A>
33: <LI><A HREF="#Addresses">A lot of hard coded addresses</A>
34: <LI><A HREF="#z1">The HTRequest structure</A>
35: <LI><A HREF="#z100">Management of the HTRequest structure</A>
36: <LI><A HREF="#LoadDoc">Functions for loading a document</A>
37: <LI><A HREF="#ClientHelp">Help functions for clients to get started</A>
38: <LI><A HREF="#PostDoc">Functions for posting a document</A>
39: <LI><A HREF="#ProtReg">Access Method Registration</H2></A>
40: </UL>
41:
2.33 frystyk 42:
43: <PRE>
44: #ifndef HTACCESS_H
1.1 timbl 45: #define HTACCESS_H
2.44 roeber 46:
2.16 luotonen 47: #include "HTList.h"
2.39 frystyk 48: #include "HTChunk.h"
2.35 frystyk 49: </PRE>
1.1 timbl 50:
2.46 frystyk 51: <H2>Global Flags</H2>
52:
53: Flags and variables which may be set to control the Library
54:
55: <H3>Redirections</H3>
56:
57: The maximum number of redirections is pr. default 10. This prevents
58: the library from going into an infinite loop which is kind of nice :-)
59:
2.35 frystyk 60: <PRE>
2.46 frystyk 61: extern int HTMaxRedirections;
2.33 frystyk 62: </PRE>
1.1 timbl 63:
2.46 frystyk 64: <H3>Other Flags</H3>
2.36 frystyk 65:
66: <PRE>
67: extern char * HTClientHost; /* Name or number of telnetting host */
68: extern BOOL HTSecure; /* Disable security holes? */
2.46 frystyk 69:
2.36 frystyk 70: extern char * HTImServer; /* If I'm cern_httpd */
71: extern BOOL HTImProxy; /* If I'm cern_httpd as a proxy */
72: </PRE>
73:
2.41 frystyk 74: <A NAME="Library"><H2>Initializing and Terminating the Library</H2></A>
75:
2.46 frystyk 76: <IMG SRC="http://www.w3.org/hypertext/WWW/Icons/32x32/warning.gif">
2.41 frystyk 77: These two functions initiates memory and settings for the Library and
78: cleans up memory kept by the Library when about to exit the
79: application. It is highly recommended that they are used!
80:
81: <PRE>
82: extern BOOL HTLibInit NOPARAMS;
83: extern BOOL HTLibTerminate NOPARAMS;
84: </PRE>
85:
2.39 frystyk 86: <A NAME="Methods"><H2>Method Management</H2></A>
2.33 frystyk 87:
2.41 frystyk 88: These are the valid methods, see <A
2.46 frystyk 89: HREF="http://www.w3.org/hypertext/WWW/Protocols/HTTP/Methods.html">HTTP
90: Methods</A>. <P>
91:
92: <B>NOTE:</B> the anchor list of allowed methods are not a bitflag, not
93: at list.
2.33 frystyk 94:
95: <PRE>
2.16 luotonen 96: typedef enum {
2.46 frystyk 97: METHOD_INVALID = 0x0,
98: METHOD_GET = 0x1,
99: METHOD_HEAD = 0x2,
100: METHOD_POST = 0x4,
101: METHOD_PUT = 0x8,
102: METHOD_DELETE = 0x10,
103: METHOD_LINK = 0x20,
104: METHOD_UNLINK = 0x40
2.16 luotonen 105: } HTMethod;
2.33 frystyk 106: </PRE>
107:
108: <H3>Get Method Enumeration</H3>
2.16 luotonen 109:
2.33 frystyk 110: Gives the enumeration value of the method as a function of the (char *) name.
2.16 luotonen 111:
2.33 frystyk 112: <PRE>
2.46 frystyk 113: extern HTMethod HTMethod_enum PARAMS((CONST char * name));
2.16 luotonen 114: </PRE>
115:
2.33 frystyk 116: <H3>Get Method String</H3>
2.16 luotonen 117:
2.33 frystyk 118: The reverse of <I>HTMethod_enum()</I>
2.16 luotonen 119:
2.33 frystyk 120: <PRE>
2.46 frystyk 121: extern CONST char * HTMethod_name PARAMS((HTMethod method));
2.16 luotonen 122: </PRE>
2.33 frystyk 123:
2.35 frystyk 124: <HR>
125: <EM>This section might be move to the Access Authentication Module</EM>
126:
2.36 frystyk 127: <H4>Match Template Against Filename</H4>
2.16 luotonen 128: <PRE>
2.40 frystyk 129: /* extern HTAA_templateMatch()
2.16 luotonen 130: ** STRING COMPARISON FUNCTION FOR FILE NAMES
131: ** WITH ONE WILDCARD * IN THE TEMPLATE
132: ** NOTE:
133: ** This is essentially the same code as in HTRules.c, but it
134: ** cannot be used because it is embedded in between other code.
135: ** (In fact, HTRules.c should use this routine, but then this
136: ** routine would have to be more sophisticated... why is life
137: ** sometimes so hard...)
138: **
139: ** ON ENTRY:
2.37 frystyk 140: ** tmplate is a template string to match the file name
2.16 luotonen 141: ** agaist, may contain a single wildcard
142: ** character * which matches zero or more
143: ** arbitrary characters.
144: ** filename is the filename (or pathname) to be matched
145: ** agaist the template.
146: **
147: ** ON EXIT:
148: ** returns YES, if filename matches the template.
149: ** NO, otherwise.
150: */
2.40 frystyk 151: extern BOOL HTAA_templateMatch PARAMS((CONST char * tmplate,
2.16 luotonen 152: CONST char * filename));
2.35 frystyk 153: </PRE>
154: <HR>
2.16 luotonen 155:
2.46 frystyk 156: The following have to be defined in advance of the other include files
2.10 timbl 157: because of circular references.
2.46 frystyk 158:
2.33 frystyk 159: <PRE>
160: typedef struct _HTRequest HTRequest;
2.39 frystyk 161: typedef struct _HTNetInfo HTNetInfo;
2.10 timbl 162:
2.14 luotonen 163: /*
2.39 frystyk 164: ** Callback to a protocol module
2.14 luotonen 165: */
2.39 frystyk 166: typedef int (*HTLoadCallBack) PARAMS((HTRequest * req));
2.14 luotonen 167:
2.10 timbl 168: #include "HTAnchor.h"
169: #include <A
170: NAME="z3" HREF="HTFormat.html">"HTFormat.h"</A>
2.15 luotonen 171: #include "HTAAUtil.h" /* HTAAScheme, HTAAFailReason */
2.14 luotonen 172: #include "HTAABrow.h" /* HTAASetup */
2.33 frystyk 173: </PRE>
2.10 timbl 174:
2.46 frystyk 175: <A NAME="HeaderMask"><H2>General HTTP Header Mask</H2></A>
176:
177: This mask enables and disables which automaticly generated HTTP
178: headers are to be sent in a request. If the bit is not turned on they
179: are not sent. Extra header can be generated when initializing the <A
180: HREF="#ExtraHeaders">ExtraHeaders field</A>. The first set is general
181: headers and the second is request headers.
182:
183: <PRE>
184: typedef enum _HeaderEnum {
185: HT_DATE = 0x1,
186: HT_MESSAGE_ID = 0x2,
187: HT_MIME = 0x4, /* MIME-Version */
188:
189: HT_ACCEPT = 0x8,
190: HT_FROM = 0x10,
191: HT_PRAGMA = 0x20,
192: HT_REFERER = 0x40,
193: HT_USER_AGENT = 0x80
194: } HeaderEnum;
195:
196: #define <A NAME="DEF_HEAD">DEFAULT_HEADERS</A> HT_ACCEPT+HT_REFERER+HT_USER_AGENT
197: </PRE>
198:
199: <H2>Entity Header Mask</H2>
200:
201: The entity headers contain information about the object sent in the
202: HTTP transaction. See the <A HREF="HTAnchor.html">Anchor module</A>,
203: for the storage of entity headers. This flag defines which headers are
204: to be sent in a request together with an entity body (the <B>O</B>
205: stands for <EM>object</EM>)
206:
207: <PRE>
208: typedef enum _EntityHeaderEnum {
209: HT_ALLOW = 0x1,
210: HT_CONTENT_ENCODING = 0x2,
211: HT_CONTENT_LANGUAGE = 0x4,
212: HT_CONTENT_LENGTH = 0x8,
213: HT_CTE = 0x10, /* Content-Transfer-Encoding */
214: HT_CONTENT_TYPE = 0x20,
215: HT_DERIVED_FROM = 0x40,
216: HT_EXPIRES = 0x80,
217: HT_LAST_MODIFIED = 0x200,
218: HT_LINK = 0x400,
219: HT_TITLE = 0x800,
220: HT_URI = 0x1000,
221: HT_VERSION = 0x2000
222: } EntityHeaderEnum;
223:
224: #define <A NAME="DEF_ENTITY">DEFAULT_ENTITY_HEADERS</A> HT_CONTENT_TYPE+HT_CONTENT_LENGTH \
225: +HT_DERIVED_FROM+HT_VERSION
226: </PRE>
227:
2.39 frystyk 228: <A NAME="Addresses"><H2>Default WWW Addresses</H2></A>
2.10 timbl 229:
2.33 frystyk 230: These control the home page selection. To mess with these for normal browses
2.6 timbl 231: is asking for user confusion.
2.33 frystyk 232: <PRE>
233: #define LOGICAL_DEFAULT "WWW_HOME" /* Defined to be the home page */
1.1 timbl 234:
2.6 timbl 235: #ifndef PERSONAL_DEFAULT
2.33 frystyk 236: #define PERSONAL_DEFAULT "WWW/default.html" /* in home directory */
2.6 timbl 237: #endif
2.33 frystyk 238:
2.46 frystyk 239: /* If the home page isn't found, use this file: */
240: #ifndef LAST_RESORT
241: #define LAST_RESORT "http://www.w3.org/"
2.6 timbl 242: #endif
2.33 frystyk 243:
244: /* If one telnets to an access point it will look in this file for home page */
2.7 timbl 245: #ifndef REMOTE_POINTER
2.33 frystyk 246: #define REMOTE_POINTER "/etc/www-remote.url" /* can't be file */
2.7 timbl 247: #endif
2.33 frystyk 248:
2.7 timbl 249: /* and if that fails it will use this. */
2.6 timbl 250: #ifndef REMOTE_ADDRESS
2.46 frystyk 251: #define REMOTE_ADDRESS "http://www.w3.org/remote.html" /* can't be file */
1.1 timbl 252: #endif
253:
2.46 frystyk 254: /* Default log file name */
1.1 timbl 255: #ifndef DEFAULT_LOGFILE
2.46 frystyk 256: #define DEFAULT_LOGFILE "www-log"
1.1 timbl 257: #endif
258:
2.46 frystyk 259: #ifndef LOCAL_DEFAULT_FILE
260: #define LOCAL_DEFAULT_FILE "/usr/local/lib/WWW/default.html"
1.1 timbl 261: #endif
262:
2.33 frystyk 263: /* This is the default cache directory: */
2.46 frystyk 264: #ifndef HT_CACHE_ROOT
265: #define HT_CACHE_ROOT "/tmp"
2.23 frystyk 266: #endif
267:
2.33 frystyk 268: /* The default directory for "save locally" and "save and execute" files: */
2.46 frystyk 269: #ifndef HT_TMP_ROOT
270: #define HT_TMP_ROOT "/tmp"
2.23 frystyk 271: #endif
2.33 frystyk 272: </PRE>
2.10 timbl 273:
2.34 frystyk 274: <H2><A NAME="HTNetInfo">Protocol Specific Information</A></H2>
275:
2.45 frystyk 276: This structure contains information about socket number, input buffer
277: for reading from the network etc. The structure is used through out
278: the protocol modules and is the refenrence point for introducing multi
279: threaded execution into the library, see specifications on <A
2.46 frystyk 280: HREF="http://www.w3.org/hypertext/WWW/Library/User/Features/multithread.html">Multiple
2.45 frystyk 281: Threads</A>.
2.34 frystyk 282:
283: <PRE>
2.46 frystyk 284: typedef enum _SocAction {
285: SOC_INVALID = -1,
286: SOC_WRITE = 0, /* By default ready to write */
287: SOC_READ,
288: SOC_INTERRUPT
289: } SocAction;
290:
2.39 frystyk 291: struct _HTNetInfo {
2.45 frystyk 292: SOCKFD sockfd; /* Socket descripter */
2.39 frystyk 293: SockA sock_addr; /* SockA is defined in tcp.h */
2.36 frystyk 294: HTInputSocket * isoc; /* Input buffer */
2.46 frystyk 295: SocAction action; /* Result of the select call */
296: HTStream * target; /* Target stream */
2.36 frystyk 297: int addressCount; /* Attempts if multi-homed host */
2.39 frystyk 298: time_t connecttime; /* Used on multihomed hosts */
2.36 frystyk 299: struct _HTRequest * request; /* Link back to request structure */
2.39 frystyk 300: };
2.34 frystyk 301: </PRE>
302:
2.36 frystyk 303: <EM><B>Note:</B> The AddressCount varaible is used to count the number
304: of attempt to connect to a multi-homed host so we know when to stop
305: trying new IP-addresses.</EM>
306:
2.46 frystyk 307: <H2><A NAME="z1">The Request structure</A></H2>
308:
309: When a request is handled, all kinds of things about it need to be
310: passed along. These are all put into a HTRequest structure. This is
311: the most essential structure in the library. It contains two main
312: categories of information regarding a request:
313:
314: <UL>
315: <LI>Application dependent information
316: <LI>Library dependent information
317: </UL>
318:
319: Applications using the Library should <EM>never</EM> use the internal
320: library dependent information. It's only because we dont have real
321: classes that we can't hide it. <P>
322:
323: <B>Note:</B> If you reuse the request structure for more than one
324: request then make sure that the request is re-initialized, so that no
325: `old' data is reused, see <A HREF="#z100">functions to manipulate
326: HTRequest Structure</A>. The library handles its own internal
327: information from request to request but the information set by the
328: caller is untouched. <P>
2.31 frystyk 329:
2.46 frystyk 330: The elements of the request structure are as follows:
2.39 frystyk 331:
332: <PRE>
333: struct _HTRequest {
334: </PRE>
2.19 timbl 335:
2.46 frystyk 336: <H3>Application Dependent - Set by the caller of HTAccess</H3>
2.19 timbl 337:
2.39 frystyk 338: <PRE>
339: <A HREF="#Methods">HTMethod</A> method;
340: </PRE>
341:
342: An enum used to specify the HTTP <A NAME="z7"
2.46 frystyk 343: HREF="../../Protocols/HTTP/Methods.html">method</A> used for the
344: actual request. The default value is <A
345: HREF="#Methods"><CODE>GET</CODE></A>.
346:
347: <H4>HTTP Header Information</H4>
2.39 frystyk 348:
349: <PRE>
350: HTList * conversions;
351: </PRE>
352:
2.46 frystyk 353: NULL, or a <EM>local</EM> list of specific conversions which the
354: format manager can do in order to fulfill the request. It typically
355: points to a list set up on initialisation time for example by <A
356: HREF="HTInit.html">HTInit()</A>. There is also a <A
357: HREF="HTFormat.html#z17"><EM>global</EM></A> list of conversions which
358: contains a generic set of possible conversions.
2.39 frystyk 359:
360: <PRE>
361: HTList * encodings;
362: </PRE>
363:
364: The list of encodings acceptable in the output stream.
365:
366: <PRE>
367: HTList * languages;
368: </PRE>
369:
370: The list of (human) language values acceptable in the response. The default
371: is all languages.
372:
373: <PRE>
2.46 frystyk 374: HeaderEnum HeaderMask;
375: EntityHeaderEnum EntityMask;
376: </PRE>
377:
378: These two masks defines which headers to include in a HTTP request (or
379: any other MIME-like protocol). the first mask defines what
380: autogenerated HTTP header fields should be sent in the HTTP
381: request. The default value is <A
382: HREF="DEF_HEAD">DEFAULT_HEADERS</A>. The second defines what entity
383: headers should be sent along with an entity (using PUT or POST).
384:
385: <PRE>
386: HTParentAnchor *parentAnchor;
387: </PRE>
388:
389: If this parameter is set then a `Referer: <parent address> can
390: be generated in the request to the server, see <A
391: HREF="http://www.w3.org/hypertext/WWW/Protocols/HTTP/HTRQ_Headers.html#z14">
392: Referer field in a HTTP Request</A>
393:
394: <PRE>
395: <A NAME="#ExtraHeaders">char * ExtraHeaders;</A>
2.39 frystyk 396: </PRE>
397:
2.46 frystyk 398: Extra header information can be send along with a request using this
399: variable. The text is sent as is so it must be preformatted with
400: <CRLF> line terminators.
401:
402: <H4>Streams From Network to Application</H4>
2.39 frystyk 403:
404: <PRE>
2.46 frystyk 405: HTStream * output_stream;
2.39 frystyk 406: </PRE>
407:
2.46 frystyk 408: The output stream is to be used to put data down to as they come in
409: <B>from</B> the network and back to the application. The default value
410: is <CODE>NULL</CODE> which means that the stream goes to the user
411: (display).
2.39 frystyk 412:
413: <PRE>
2.46 frystyk 414: HTAtom * output_format;
2.39 frystyk 415: </PRE>
416:
2.46 frystyk 417: The desired format of the output stream. This can be used to get
418: unconverted data etc. from the library. If <CODE>NULL</CODE>, then <A
419: HREF="HTFormat.html#FormatTypes">WWW_PRESENT</A> is default value.
2.45 frystyk 420:
421: <PRE>
2.46 frystyk 422: HTStream* error_stream;
2.45 frystyk 423: </PRE>
424:
425: All object bodies sent from the server with status codes different
426: from <CODE>200 OK</CODE> will be put down this stream. This can be
427: used as a debug window etc. If the value is NULL (default) then the
428: stream used is <A HREF="HTFormat.html#BlackHole">HTBlackHole</A>.
2.39 frystyk 429:
2.47 frystyk 430: <PRE>
431: HTAtom * error_format;
432: </PRE>
433:
434: The desired format of the error stream. This can be used to get
435: unconverted data etc. from the library. The default value if
436: <CODE>WWW_HTML</CODE> as a character based only has one WWW_PRESENT.
437:
2.46 frystyk 438: <H4>Streams From Application to Network</H4>
439:
2.39 frystyk 440: <PRE>
2.46 frystyk 441: HTStream * input_stream;
442: </PRE>
443:
444: The input stream is to be used by the <CODE>PostCallBack</CODE>
445: function to put data out on the network. The user should not
446: initialize this field.
447:
448: <PRE>
449: HTAtom * input_format;
450: </PRE>
451:
452: The desired format of the output stream. This can be used to upload
453: converted data to a remote server. If <CODE>NULL</CODE>, then <A
454: HREF="HTFormat.html#FormatTypes">WWW_SOURCE</A> is default value.
455:
456: <PRE>
457: int (*PostCallBack) PARAMS((struct _HTRequest * request,
458: HTStream * target));
2.39 frystyk 459: </PRE>
460:
2.46 frystyk 461: The call back function which is called when the current request is
462: ready for sending (posting) the data object. The request is the
463: current request so that the application knows which post we are
464: handling. The function must have the same return values as the other
465: <A HREF="#LoadDoc">Load functions</A>.
466:
467: <H4>Other Flags</H4>
2.39 frystyk 468:
469: <PRE>
2.43 frystyk 470: BOOL BlockingIO;
2.46 frystyk 471: BOOL ForceReload;
2.43 frystyk 472: </PRE>
473:
474: This flag can be set to override if a protocol module is registered as
475: using non-blocking IO.
476:
477: <PRE>
2.46 frystyk 478: BOOL (*<A NAME="z9"> callback</A> ) PARAMS((struct _HTRequest* request,
479: void *param));
480: </PRE>
481:
482: A function to be called back in the event that a file has been saved
483: to disk by HTSaveAndCallBack for example.
484:
485: <PRE>
486: void * context;
2.39 frystyk 487: </PRE>
488:
2.46 frystyk 489: An arbitrary pointer passed to HTAccess and passed back as a parameter
490: to the <A NAME="z10" HREF="#z9">callback</A>.
2.39 frystyk 491:
2.46 frystyk 492: <H3>Library Dependent - Set by Library</H3>
2.39 frystyk 493:
2.46 frystyk 494: None of the bits below may be looked at by a WWW application. The
495: Library handles the cleanup by itself.
2.39 frystyk 496:
497: <PRE>
498: HTParentAnchor* anchor;
499: </PRE>
500:
501: The anchor for the object in question. Set immediately by HTAcesss.
502: Used by the protocol and parsing modules. Valid thoughout the access.
503:
504: <PRE>
505: HTChildAnchor * childAnchor; /* For element within the object */
506: </PRE>
507:
508: The anchor for the sub object if any. The object builder should
2.46 frystyk 509: ensure that is is selected, highlighted, etc when the object is
2.39 frystyk 510: loaded.
511:
512: <PRE>
2.46 frystyk 513: struct _HTRequest * CopyRequest;
514: </PRE>
515:
516: We need to know if we have a remote request sending data along with
517: this request.
518:
519: <PRE>
520: void * using_cache;
521: BOOL using_proxy;
2.39 frystyk 522: </PRE>
523:
2.46 frystyk 524: Pointer to cache element if cache hit anfd if using proxy
2.19 timbl 525:
2.25 luotonen 526: <PRE>
2.46 frystyk 527: BOOL error_block; /* YES if stream has been used */
528: HTList * error_stack; /* List of errors */
529: </PRE>
2.25 luotonen 530:
2.46 frystyk 531: These two fields are used by the error reporting system to keep a
532: stack of messages.
533:
534: <PRE>
535: HTNetInfo * net_info; /* Information about socket etc. */
536: int redirections; /* Number of redirections */
2.47 frystyk 537: time_t retry_after; /* Absolut time for a retry */
2.34 frystyk 538: </PRE>
2.46 frystyk 539:
540: Protocol specific information, socket number etc.
541:
2.34 frystyk 542: <PRE>
2.46 frystyk 543: char * redirect; /* Location or URI */
544: char * WWWAAScheme; /* WWW-Authenticate scheme */
545: char * WWWAARealm; /* WWW-Authenticate realm */
546: char * WWWprotection; /* WWW-Protection-Template */
2.25 luotonen 547: </PRE>
2.39 frystyk 548:
2.46 frystyk 549: Information taken from the MIME header specifically oriented towards
550: the request (not the object itself)
551:
2.39 frystyk 552: <PRE>
2.46 frystyk 553: char * authorization; /* Authorization: field */
554: HTAAScheme scheme; /* Authentication scheme used */
555: HTInputSocket * isoc; /* InputSocket object for reading */
2.48 ! frystyk 556: #if 0
2.46 frystyk 557: HTAtom * content_type; /* Content-Type: */
558: HTAtom * content_language; /* Language */
559: HTAtom * content_encoding; /* Encoding */
560: int content_length; /* Content-Length: */
2.48 ! frystyk 561: #endif
2.39 frystyk 562: </PRE>
563:
2.46 frystyk 564: These header fields are only used by the server and will be removed at some
565: point.
566:
2.21 luotonen 567: <PRE>
2.46 frystyk 568: HTList * valid_schemes; /* Valid auth.schemes */
569: HTAssocList ** scheme_specifics;/* Scheme-specific parameters */
570: char * authenticate; /* WWW-authenticate: field */
571: char * prot_template; /* WWW-Protection-Template: field */
572: HTAASetup * setup; /* Doc protection info */
573: HTAARealm * realm; /* Password realm */
574: char * dialog_msg; /* Authentication prompt (client) */
2.19 timbl 575: </PRE>
2.46 frystyk 576:
577: These fields are used by the HTTP access authentication used by a
578: client application.
579:
2.19 timbl 580: <PRE>
2.10 timbl 581: };
2.31 frystyk 582: </PRE>
583:
584: <H2><A NAME="z100">Functions to Manipulate a HTRequest Structure</A></H2>
585:
586: Just to make things easier especially for clients, here are some functions to
587: manipulate the request structure:
588:
589: <H3>Create blank request</H3>This request has defaults in -- in
2.9 timbl 590: most cases it will need some information
591: added before being passed to HTAccess,
592: but it will work as is for a simple
593: request.
2.14 luotonen 594: <PRE>
2.40 frystyk 595: extern HTRequest * HTRequest_new NOPARAMS;
2.31 frystyk 596: </PRE>
2.14 luotonen 597:
2.31 frystyk 598: <H3>Delete request structure</H3>Frees also conversion list hanging
2.19 timbl 599: from req->conversions.
2.14 luotonen 600: <PRE>
2.40 frystyk 601: extern void HTRequest_delete PARAMS((HTRequest * req));
2.31 frystyk 602: </PRE>
1.1 timbl 603:
2.31 frystyk 604: <H3>Clear a request structure</H3>
2.46 frystyk 605:
606: Clears a request structure so that it can be reused. The only thing
607: that differs from using free/new is that the list of conversions is
608: kept. <P>
609:
610: <B>NOTE:</B> It is <B>NOT</B> recommended to reuse a request structure!!!
611:
2.31 frystyk 612: <PRE>
613: extern void HTRequest_clear PARAMS((HTRequest * req));
614: </PRE>
2.9 timbl 615:
2.39 frystyk 616: <A NAME="LoadDoc"><H2>Functions for Loading a Document</H2></A>
617:
618: There are several different ways of loading a document. However, the
619: major difference between them is whether the document is referenced by
620:
621: <UL>
622: <LI><A HREF="#Relative">Relative URI</A>
623: <LI><A HREF="#Absolute">Absolute URI</A>
624: <LI><A HREF="#Anchor">Anchor element</A> or
625: <LI>Contains keywords for <A HREF="#RelSearch">searching an relative URI</A>
626: <LI>Contains keywords for <A HREF="#AbsSearch">searching an absolute URI</A>
627: </UL>
628:
629: <B>NOTE:</B> From release 3.0 of the Library, the return codes from
630: the loading functions are no mode <CODE>BOOL</CODE>, that is
631: <CODE>YES</CODE> or <CODE>NO</CODE>. Insted they have been replaced
632: with the following set of return codes defined in the <A
633: HREF="HTUtils.html#ReturnCodes">Utility module</A>:
634:
2.5 timbl 635: <DL>
2.39 frystyk 636: <DT>HT_WOULD_BLOCK
637: <DD>An I/O operation would block
638:
639: <DT>HT_ERROR
640: <DD>Error has occured
641:
642: <DT>HT_LOADED
643: <DD>Success
644:
645: <DT>HT_NO_DATA
646: <DD>Success, but no document loaded. This might be the situation when a
647: telnet sesssion is started etc.
2.47 frystyk 648:
649: <DT>HT_RETRY
650: <DD>The remote server is down but will serve documents from the
651: calendar time indicated in HTRequest->retry_after.
652:
2.5 timbl 653: </DL>
654:
2.39 frystyk 655: However, a general rule about the return codes is that <B>ERRORS</B>
656: have a <EM>negative</EM> value whereas <B>SUCCESS</B> has a
657: <EM>positive</EM> value. <P>
1.1 timbl 658:
2.39 frystyk 659: There are also some functions to help the client getting started with
660: <A HREF="#ClientHelp">the first URI</A>.
1.1 timbl 661:
2.46 frystyk 662: <A NAME="Relative"><H3>Load a document from relative URL</H3></A>
1.1 timbl 663:
2.39 frystyk 664: <PRE>
665: extern int HTLoadRelative PARAMS((CONST char * relative_name,
666: HTParentAnchor* here,
667: HTRequest * request));
2.5 timbl 668: </PRE>
2.39 frystyk 669:
2.46 frystyk 670: <A NAME="Absolute"></A><H3>Load a document from absolute URL</H3>
1.1 timbl 671:
2.5 timbl 672: <PRE>
2.39 frystyk 673: extern int HTLoadAbsolute PARAMS((CONST char * addr,
674: HTRequest * request));
2.5 timbl 675: </PRE>
2.39 frystyk 676:
677: <H3>Load a document from absolute name to a stream</H3>
678:
2.5 timbl 679: <PRE>
2.39 frystyk 680: extern int HTLoadToStream PARAMS((CONST char * addr,
681: BOOL filter,
682: HTRequest * request));
2.5 timbl 683: </PRE>
1.1 timbl 684:
2.46 frystyk 685: <A NAME="Anchor"><H3>Load a document from anchor</H3></A>
1.1 timbl 686:
2.39 frystyk 687: The anchor parameter may be a child anchor. The anchor in the request
688: is set to the parent anchor. The recursive function keeps the error
689: stack in the request structure so that no information is lost having
690: more than one call. See also <A HREF="#BindAnchor">HTBindAnchor()</A>.
1.1 timbl 691:
2.39 frystyk 692: <PRE>
2.41 frystyk 693: extern int HTLoadAnchor PARAMS((HTAnchor * a,
694: HTRequest * request));
2.39 frystyk 695: extern int HTLoadAnchorRecursive PARAMS((HTAnchor * a,
696: HTRequest * request));
2.5 timbl 697: </PRE>
698:
2.39 frystyk 699: <H3>Load a Document</H3>
700:
2.46 frystyk 701: These are two internal routines for loading a document which has an
2.41 frystyk 702: address AND a matching anchor. (The public routines are called with
703: one OR the other.) This is recursively called from file load module
704: to try ftp (though this will be obsolete in the next major
705: release).<P>
1.1 timbl 706:
2.39 frystyk 707: If <CODE>keep_error_stack</CODE> is YES then the error (or info) stack
708: is not cleared from the previous call.
1.1 timbl 709:
2.39 frystyk 710: <PRE>
2.41 frystyk 711: extern int HTLoad PARAMS((HTRequest * request,
712: BOOL keep_error_stack));
713: </PRE>
714:
715: <PRE>
716: extern BOOL HTLoadTerminate PARAMS((HTRequest * request, int status));
2.5 timbl 717: </PRE>
718:
2.46 frystyk 719: <A NAME="RelSearch"><H3>Search Using Relative URL</H3></A>
2.39 frystyk 720:
721: Performs a search on word given by the user. Adds the search words to
722: the end of the current address and attempts to open the new address.
723:
2.5 timbl 724: <PRE>
2.39 frystyk 725: extern int HTSearch PARAMS((CONST char * keywords,
726: HTParentAnchor* here,
727: HTRequest * request));
2.5 timbl 728: </PRE>
2.39 frystyk 729:
2.46 frystyk 730: <A NAME="AbsSearch"><H3>Search using Absolute URL</H3></A>
2.39 frystyk 731:
732: Performs a keyword search on word given by the user. Adds the keyword
733: to the end of the current address and attempts to open the new
734: address.
2.5 timbl 735:
2.33 frystyk 736: <PRE>
2.40 frystyk 737: extern int HTSearchAbsolute PARAMS((CONST char * keywords,
2.39 frystyk 738: CONST char * indexname,
739: HTRequest * request));
2.5 timbl 740: </PRE>
2.24 luotonen 741:
2.39 frystyk 742:
743: <A NAME="ClientHelp"><H2>Help Function for Clients to get started</H2></A>
744:
745: These function helps the client to load the first document. They are
746: not mandatory to use - but they make life easier!
747:
748: <A NAME="BindAnchor"><H3>Bind an anchor to a request structure without
749: loading</H3></A>
2.24 luotonen 750:
751: <PRE>
2.39 frystyk 752: extern BOOL HTBindAnchor PARAMS((HTAnchor *anchor, HTRequest *request));
2.24 luotonen 753: </PRE>
754:
2.39 frystyk 755: <A NAME="HomePage"><H3>Generate the Anchor for the Home Page</H3></A>
2.24 luotonen 756:
2.39 frystyk 757: As it involves file access, this should only be done once when the
758: program first runs. This is a default algorithm using the
759: <CODE>WWW_HOME</CODE> environment variable.
2.20 frystyk 760:
761: <PRE>
2.40 frystyk 762: extern HTParentAnchor * HTHomeAnchor NOPARAMS;
2.39 frystyk 763: </PRE>
764:
765: <H3>Find Related Name</H3>
766:
767: Creates a local file URI that can be used as a relative name when
768: calling HTParse() to expand a relative file name to an absolute
769: one. <P>
770:
2.46 frystyk 771: The code for this routine originates from the Line Mode Browser and
772: was moved here by <EM>howcome@dxcern.cern.ch</EM> in order for all
773: clients to take advantage.<P>
2.39 frystyk 774:
2.20 frystyk 775: <PRE>
2.39 frystyk 776: extern char * HTFindRelatedName NOPARAMS;
777: </PRE>
778:
779: <A NAME="PostDoc"><H2>Functions for Posting a Document</H2></A>
780:
2.46 frystyk 781: <B>NOTE:</B> The Posting functions are used to send a data object
782: along with the request. The functions have the same set of return
783: codes as for the <A HREF="#LoadDoc">Load Functions</A>.
2.20 frystyk 784:
2.39 frystyk 785: <H3>Get a Save Stream</H3>
2.20 frystyk 786:
2.39 frystyk 787: <H4>On Entry,</H4>
2.5 timbl 788: <DL>
2.9 timbl 789: <DT>request->anchor
790: <DD> is valid anchor which
791: has previously beeing loaded
2.5 timbl 792: </DL>
793:
2.39 frystyk 794: <H4>On exit,</H4>
2.5 timbl 795: <DL>
796: <DT>returns
2.6 timbl 797: <DD> 0 if error else a stream
798: to save the object to.
2.5 timbl 799: </DL>
800:
801: <PRE>
2.46 frystyk 802: extern HTStream * HTSaveStream PARAMS((HTRequest * request));
803: </PRE>
804:
805: <H3>Copy an Anchor</H3>
806:
807: Fetch the URL (possibly local file URL) and send it using either
808: <B>PUT</B> or <B>POST</B> directly to the remote destination using
809: HTTP, that is remote copy of object <EM>O</EM> from <EM>A</EM> to
810: <EM>B</EM> where <EM>A</EM> might be the host of the application. The
811: caller can decide the exact method used and which HTTP header fields
812: to transmit by setting the user fields in the destination request
813: structure.
814:
815: <PRE>
816: extern int HTCopyAnchor PARAMS((HTAnchor * src_anchor,
817: HTRequest * src_req,
818: HTParentAnchor *dest_anchor,
819: HTRequest * dest_req));
820: </PRE>
821:
822:
823: <H3>Upload an Anchor</H3>
824:
825: Send the contents (in hyperdoc) of the source anchor using either
826: <B>PUT</B> or <B>POST</B> to the remote destination using HTTP. The
827: caller can decide the exact method used and which HTTP header fields
828: to transmit by setting the user fields in the request structure.
829: <EM>Format conversion</EM> can be made on the fly by setting the <A
830: HREF="#input_format">input_format field</A> in the destination request
831: structure. If the content-length is unknown (-1) then a <A
832: HREF="HTConLen.html">content-length counter</A> is automaticly put
833: into the stream pipe.
834:
835:
836: <PRE>
837: extern int HTUploadAnchor PARAMS((HTAnchor * src_anchor,
838: HTParentAnchor *dest_anchor,
839: HTRequest * dest_req));
2.39 frystyk 840: </PRE>
2.5 timbl 841:
1.1 timbl 842:
2.39 frystyk 843: <A NAME="ProtReg"><H2>Access Method Registration</H2></A>
1.1 timbl 844:
2.39 frystyk 845: An access method is defined by an HTProtocol structure which point to
846: the routines for performing the various logical operations on an
847: object: in HTTP terms, GET, PUT, and POST. The access methods
848: supported in the Library are initiated automaticly using the private
849: function <CODE>HTAccessInit()</CODE> <B>if not</B> defined
2.46 frystyk 850: <CODE>HT_NO_INIT</CODE> <P>
2.39 frystyk 851:
852: Each of these routine takes as a parameter a <A NAME="z2"
853: HREF="#z1">request structure</A> containing details of the request.
854: When the protocol class routine is called, the anchor element in the
855: request is already valid (made valid by HTAccess).
856:
857: <PRE>
858: typedef enum _HTSocBlock {
859: SOC_BLOCK,
2.42 frystyk 860: SOC_NON_BLOCK
2.39 frystyk 861: } HTSocBlock;
862:
863: typedef struct _HTProtocol {
864: char * name;
865: HTSocBlock block;
866: int (*load) PARAMS((HTRequest * request));
867: HTStream* (*saveStream) PARAMS((HTRequest * request));
868: HTStream* (*postStream) PARAMS((HTRequest * request,
869: HTParentAnchor* postTo));
870: } HTProtocol;
1.1 timbl 871:
2.40 frystyk 872: extern BOOL HTRegisterProtocol PARAMS((HTProtocol * protocol));
2.42 frystyk 873: extern void HTDisposeProtocols NOPARAMS;
2.5 timbl 874: </PRE>
1.1 timbl 875:
2.39 frystyk 876: <H3>Uses Protocol Blocking IO</H3>
1.1 timbl 877:
2.39 frystyk 878: A small function to make life easier. Returns <CODE>YES</CODE> or
2.42 frystyk 879: <CODE>NO</CODE>. If the Library is run in NON-INTERACTIVE MODE then
880: the function always returns YES;
2.38 howcome 881:
882: <PRE>
2.40 frystyk 883: extern BOOL HTProtocolBlocking PARAMS((HTRequest * request));
2.38 howcome 884: </PRE>
885:
2.39 frystyk 886: end
2.25 luotonen 887:
888: <PRE>
1.1 timbl 889: #endif /* HTACCESS_H */
2.25 luotonen 890: </PRE>
891: end of HTAccess
892: </BODY>
2.9 timbl 893: </HTML>
Webmaster