Annotation of libwww/Library/src/HTAAUtil.html, revision 2.3
2.2 timbl 1: <HTML>
2.1 luotonen 2: <HEAD>
2.2 timbl 3: <TITLE>Utilities for the Authorization parts of libwww</TITLE></HEAD>
2.1 luotonen 4: <BODY>
2.2 timbl 5: <H1>Common Parts of Authorization Module
6: to Both Server And Browser</H1>This module is the interface to the
7: common parts of Access Authorization
8: (AA) package for both server and
9: browser. Important to know about
10: memory allocation:<P>
11: Routines in this module use dynamic
12: allocation, but free automatically
13: all the memory reserved by them.<P>
14: Therefore the caller never has to
15: (and never should) free() any object
16: returned by these functions.<P>
17: Therefore also all the strings returned
18: by this package are only valid until
19: the next call to the same function
20: is made. This approach is selected,
21: because of the nature of access authorization:
22: no string returned by the package
23: needs to be valid longer than until
24: the next call.<P>
25: This also makes it easy to plug the
26: AA package in: you don't have to
27: ponder whether to free() something
28: here or is it done somewhere else
29: (because it is always done somewhere
30: else).<P>
31: The strings that the package needs
32: to store are copied so the original
33: strings given as parameters to AA
34: functions may be freed or modified
35: with no side effects.<P>
36: Also note: The AA package does not
37: free() anything else than what it
38: has itself allocated.
2.1 luotonen 39: <PRE>
40: #ifndef HTAAUTIL_H
41: #define HTAAUTIL_H
42:
43: #include "HTUtils.h" /* BOOL, PARAMS, ARGS */
44: #include "HTList.h"
2.2 timbl 45: #include "tcp.h"
2.1 luotonen 46:
47: #ifdef SHORT_NAMES
48: #define HTAASenu HTAAScheme_enum
49: #define HTAASnam HTAAScheme_name
50: #define HTAAMenu HTAAMethod_enum
51: #define HTAAMnam HTAAMethod_name
52: #define HTAAMinL HTAAMethod_inList
53: #define HTAAteMa HTAA_templateMatch
54: #define HTAAmaPT HTAA_makeProtectionTemplate
55: #define HTAApALi HTAA_parseArgList
56: #define HTAAsuRe HTAA_setupReader
57: #define HTAAgUfL HTAA_getUnfoldedLine
58: #endif /*SHORT_NAMES*/
59:
60:
2.2 timbl 61: </PRE>
62: <H2>Default filenames</H2>
63: <PRE>#ifndef PASSWD_FILE
2.1 luotonen 64: #define PASSWD_FILE "/home2/luotonen/passwd"
65: #endif
66:
67: #ifndef GROUP_FILE
68: #define GROUP_FILE "/home2/luotonen/group"
69: #endif
70:
71: #define ACL_FILE_NAME ".www_acl"
72:
73:
74: /*
75: ** Numeric constants
76: */
77: #define MAX_USERNAME_LEN 16 /* @@ Longest allowed username */
78: #define MAX_PASSWORD_LEN 3*13 /* @@ Longest allowed password */
79: /* (encrypted, so really only 3*8)*/
80: #define MAX_METHODNAME_LEN 12 /* @@ Longest allowed method name */
81: #define MAX_FIELDNAME_LEN 16 /* @@ Longest field name in */
82: /* protection setup file */
83: #define MAX_PATHNAME_LEN 80 /* @@ Longest passwd/group file */
84: /* patname to allow */
85:
86: /*
87: ** Helpful macros
88: */
89: #define FREE(x) if (x) {free(x); x=NULL;}
90:
91: </PRE>
92: <H2>Datatype definitions</H2>
2.2 timbl 93: <H3>HTAAScheme</H3>The enumeration HTAAScheme represents
94: the possible authentication schemes
95: used by the WWW Access Authorization.
2.1 luotonen 96: <PRE>
97: typedef enum {
98: HTAA_UNKNOWN,
99: HTAA_NONE,
100: HTAA_BASIC,
101: HTAA_PUBKEY,
102: HTAA_KERBEROS_V4,
103: HTAA_KERBEROS_V5,
104: HTAA_MAX_SCHEMES /* THIS MUST ALWAYS BE LAST! Number of schemes */
105: } HTAAScheme;
106:
2.2 timbl 107: </PRE>
2.1 luotonen 108: <H3>Enumeration to Represent HTTP Methods</H3>
109: <PRE>
110: typedef enum {
111: METHOD_UNKNOWN,
112: METHOD_GET,
113: METHOD_PUT
114: } HTAAMethod;
115:
2.2 timbl 116: </PRE>
2.1 luotonen 117: <H2>Authentication Schemes</H2>
118: <PRE>
119: /* PUBLIC HTAAScheme_enum()
120: ** TRANSLATE SCHEME NAME TO A SCHEME ENUMERATION
121: ** ON ENTRY:
122: ** name is a string representing the scheme name.
123: **
124: ** ON EXIT:
125: ** returns the enumerated constant for that scheme.
126: */
127: PUBLIC HTAAScheme HTAAScheme_enum PARAMS((CONST char* name));
128:
129:
130: /* PUBLIC HTAAScheme_name()
131: ** GET THE NAME OF A GIVEN SCHEME
132: ** ON ENTRY:
133: ** scheme is one of the scheme enum values:
134: ** HTAA_NONE, HTAA_BASIC, HTAA_PUBKEY, ...
135: **
136: ** ON EXIT:
137: ** returns the name of the scheme, i.e.
138: ** "none", "basic", "pubkey", ...
139: */
140: PUBLIC char *HTAAScheme_name PARAMS((HTAAScheme scheme));
2.2 timbl 141:
2.1 luotonen 142: </PRE>
143: <H2>Methods</H2>
144: <PRE>
145: /* PUBLIC HTAAMethod_enum()
146: ** TRANSLATE METHOD NAME INTO AN ENUMERATED VALUE
147: ** ON ENTRY:
148: ** name is the method name to translate.
149: **
150: ** ON EXIT:
151: ** returns HTAAMethod enumerated value corresponding
152: ** to the given name.
153: */
154: PUBLIC HTAAMethod HTAAMethod_enum PARAMS((CONST char * name));
155:
156:
157: /* PUBLIC HTAAMethod_name()
158: ** GET THE NAME OF A GIVEN METHOD
159: ** ON ENTRY:
160: ** method is one of the method enum values:
161: ** METHOD_GET, METHOD_PUT, ...
162: **
163: ** ON EXIT:
164: ** returns the name of the scheme, i.e.
165: ** "GET", "PUT", ...
166: */
167: PUBLIC char *HTAAMethod_name PARAMS((HTAAMethod method));
168:
169:
170: /* PUBLIC HTAAMethod_inList()
171: ** IS A METHOD IN A LIST OF METHOD NAMES
172: ** ON ENTRY:
173: ** method is the method to look for.
174: ** list is a list of method names.
175: **
176: ** ON EXIT:
177: ** returns YES, if method was found.
178: ** NO, if not found.
179: */
180: PUBLIC BOOL HTAAMethod_inList PARAMS((HTAAMethod method,
181: HTList * list));
182: </PRE>
183: <H2>Match Template Against Filename</H2>
184: <PRE>
185: /* PUBLIC HTAA_templateMatch()
186: ** STRING COMPARISON FUNCTION FOR FILE NAMES
187: ** WITH ONE WILDCARD * IN THE TEMPLATE
188: ** NOTE:
189: ** This is essentially the same code as in HTRules.c, but it
190: ** cannot be used because it is embedded in between other code.
191: ** (In fact, HTRules.c should use this routine, but then this
192: ** routine would have to be more sophisticated... why is life
193: ** sometimes so hard...)
194: **
195: ** ON ENTRY:
196: ** template is a template string to match the file name
197: ** agaist, may contain a single wildcard
198: ** character * which matches zero or more
199: ** arbitrary characters.
200: ** filename is the filename (or pathname) to be matched
201: ** agaist the template.
202: **
203: ** ON EXIT:
204: ** returns YES, if filename matches the template.
205: ** NO, otherwise.
206: */
207: PUBLIC BOOL HTAA_templateMatch PARAMS((CONST char * template,
208: CONST char * filename));
209:
210:
211: /* PUBLIC HTAA_makeProtectionTemplate()
212: ** CREATE A PROTECTION TEMPLATE FOR THE FILES
213: ** IN THE SAME DIRECTORY AS THE GIVEN FILE
214: ** (Used by server if there is no fancier way for
215: ** it to tell the client, and by browser if server
216: ** didn't send WWW-ProtectionTemplate: field)
217: ** ON ENTRY:
218: ** docname is the document pathname (from URL).
219: **
220: ** ON EXIT:
221: ** returns a template matching docname, and other files
222: ** files in that directory.
223: **
224: ** E.g. /foo/bar/x.html => /foo/bar/ *
225: ** ^
226: ** Space only to prevent it from
227: ** being a comment marker here,
228: ** there really isn't any space.
229: */
230: PUBLIC char *HTAA_makeProtectionTemplate PARAMS((CONST char * docname));
231: </PRE>
232: <H2>MIME Argument List Parser</H2>
233: <PRE>
234:
235: /* PUBLIC HTAA_parseArgList()
236: ** PARSE AN ARGUMENT LIST GIVEN IN A HEADER FIELD
237: ** ON ENTRY:
238: ** str is a comma-separated list:
239: **
240: ** item, item, item
241: ** where
242: ** item ::= value
243: ** | name=value
244: ** | name="value"
245: **
246: ** Leading and trailing whitespace is ignored
247: ** everywhere except inside quotes, so the following
248: ** examples are equal:
249: **
250: ** name=value,foo=bar
251: ** name="value",foo="bar"
252: ** name = value , foo = bar
253: ** name = "value" , foo = "bar"
254: **
255: ** ON EXIT:
256: ** returns a list of name-value pairs (actually HTAssocList*).
257: ** For items with no name, just value, the name is
258: ** the number of order number of that item. E.g.
259: ** "1" for the first, etc.
260: */
261: PUBLIC HTList *HTAA_parseArgList PARAMS((char * str));
262:
263: </PRE>
264: <H2>Header Line Reader</H2>
265: <PRE>
266: /* PUBLIC HTAA_setupReader()
267: ** SET UP HEADER LINE READER, i.e. give
268: ** the already-read-but-not-yet-processed
269: ** buffer of text to be read before more
270: ** is read from the socket.
271: ** ON ENTRY:
272: ** start_of_headers is a pointer to a buffer containing
273: ** the beginning of the header lines
274: ** (rest will be read from a socket).
275: ** length is the number of valid characters in
276: ** 'start_of_headers' buffer.
277: ** soc is the socket to use when start_of_headers
278: ** buffer is used up.
279: ** ON EXIT:
280: ** returns nothing.
281: ** Subsequent calls to HTAA_getUnfoldedLine()
282: ** will use this buffer first and then
283: ** proceed to read from socket.
284: */
285: PUBLIC void HTAA_setupReader PARAMS((char * start_of_headers,
286: int length,
287: int soc));
288:
289:
290: /* PUBLIC HTAA_getUnfoldedLine()
291: ** READ AN UNFOLDED HEADER LINE FROM SOCKET
292: ** ON ENTRY:
293: ** HTAA_setupReader must absolutely be called before
294: ** this function to set up internal buffer.
295: **
296: ** ON EXIT:
297: ** returns a newly-allocated character string representing
298: ** the read line. The line is unfolded, i.e.
299: ** lines that begin with whitespace are appended
300: ** to current line. E.g.
301: **
302: ** Field-Name: Blaa-Blaa
303: ** This-Is-A-Continuation-Line
304: ** Here-Is_Another
305: **
306: ** is seen by the caller as:
307: **
308: ** Field-Name: Blaa-Blaa This-Is-A-Continuation-Line Here-Is_Another
309: **
310: */
311: PUBLIC char *HTAA_getUnfoldedLine NOPARAMS;
312:
313: #endif /* NOT HTAAUTIL_H */
2.2 timbl 314: </PRE>End of file HTAAUtil.h.</BODY>
315: </HTML>
Webmaster