1 /*
2 
3 
4   					W3C Sample Code Library libwww File Suffix Binding
5 
6 
7 !
8   File Suffix Binding Manager
9 !
10 */
11 
12 /*
13 **	(c) COPYRIGHT MIT 1995.
14 **	Please first read the full copyright statement in the file COPYRIGH.
15 */
16 
17 /*
18 
19 The preferences that we described in section
20 Request Preferences did not mention
21 what libwww should do if it doesn't know the data format of a document. In
22 many protocols this information is provided by the remote server. Typical
23 examples are MIME like protocols where the metainformation such as the
24 Content-Type and the Content-Language is provided together
25 with the document. However, applications often have access to the local file
26 system using file URLs which in general do not keep any or at least
27 very little information of the file type. It is therefore required to have
28 some kind of binding between the file system and the preferences registered
29 in the Library which provides this mateinformation about the object.
30 
31 Often files in a file system is classified by some sort of a suffix, for
32 example, GIF files are often ending in .gif, text files
33 in .txt etc. This binding is not static and it is therefore required
34 to have a dynamic binding just like the preferences themselves. An example
35 of the latter is HTML files which on most Unix systems end in .html
36 whereas they on many MS-DOS based systems end in .htm.
37 
38 This module provides a generic binding mechanism between a file and its
39 representation internally in libwww. It is not limited to simple file suffix
40 classification but can also be used in more advanced environments using data
41 bases etc. However, at this point we are interested in how we can register
42 bindings between file suffixes and for example content types, content languages
43 etc. The Bind manager is born with a certain knowledge about the set of
44 delimiters but more can be added to provide the functionality desired.
45 
46 All the binding management could of course be replaced by a database interface.
47 
48 This module is implemented by HTBind.c, and it is
49 a part of the  W3C Sample Code
50 Library.
51 */
52 
53 #ifndef HTBIND_H
54 #define HTBIND_H
55 
56 #include "HTFormat.h"
57 #include "HTAnchor.h"
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 
64 /*
65 .
66   Initialization of the Module
67 .
68 
69 These functions must be called on startup and termination of the application.
70 This is done automatically by HTLibInit() and
71 HTLibTerminate().
72 */
73 
74 extern BOOL HTBind_init		(void);
75 extern BOOL HTBind_deleteAll	(void);
76 
77 /*
78 .
79   Case Sensitivity
80 .
81 
82 Should the search for suffixes be case sensitive or not? The default value
83 is case sensitive.
84 */
85 
86 extern void HTBind_caseSensitive	(BOOL sensitive);
87 
88 /*
89 .
90   Suffix Delimiters
91 .
92 
93 Change the set of suffix delimiters. The default is a platform dependent
94 set defined in the tcp module.
95 */
96 
97 extern const char *HTBind_delimiters	(void);
98 extern void HTBind_setDelimiters	(const char * new_suffixes);
99 
100 /*
101 .
102   Set up Bindings Associated with a File Suffix
103 .
104 
105 There are four types of bindings:
106 
107 	   o
108 	     Content Type (media type)
109 	   o
110 	     Language
111 	   o
112 	     Content Encoding
113 	   o
114 	     Content Transfer Encoding
115 
116 
117 And the associated set of methods is defined as:
118 */
119 
120 extern BOOL HTBind_add		(const char *	suffix,
121 				 const char *	representation,
122 				 const char *	encoding,
123 				 const char *	transfer,
124 				 const char *	language,
125 				 double		value);
126 
127 extern BOOL HTBind_addType	(const char *	suffix,
128 				 const char *	format,
129 				 double		value);
130 
131 extern BOOL HTBind_addEncoding	(const char *	suffix,
132 				 const char *	encoding,
133 				 double		value);
134 
135 extern BOOL HTBind_addTransfer	(const char *	suffix,
136 				 const char *	transfer,
137 				 double		value);
138 
139 extern BOOL HTBind_addLanguage	(const char *	suffix,
140 				 const char *	language,
141 				 double		value);
142 
143 /*
144 
145 The first method is a "super" method for binding information to a file suffic.
146 Any of the string values can be NULL. If filename suffix is
147 already defined its previous definition is overridden or modified. For example,
148 a HTBind_setType and HTBind_setEncoding can be
149 called with the same suffix.
150 
151 Calling this with suffix set to "*" will set the default representation.
152 Calling this with suffix set to "*.*" will set the default representation
153 for unknown suffix files which contain a "."
154 
155 NOTE: The suffixes can contain characters that must be escaped
156 in a URL. However, they should not be encoded when parsed as the
157 suffix parameter.
158 .
159   Determine a suitable suffix
160 .
161 
162 Use the set of bindings to find a suitable suffix (or index) for a certain
163 combination of language, media type and encoding given in the anchor. Returns
164 a pointer to a suitable suffix string that must be freed by the caller. If
165 more than one suffix is found they are all concatenated. If no suffix is
166 found, NULL is returned.
167 */
168 
169 extern char * HTBind_getSuffix	(HTParentAnchor * anchor);
170 
171 /*
172 .
173   Determine the content of an Anchor
174 .
175 
176 Use the set of bindings to find the combination of language, media type and
177 encoding of a given anchor. If more than one suffix is found they are all
178 searched. The last suffix has highest priority, the first one lowest. Returns
179 the HTAnchor object with the representations
180 found. See also HTBind_getFormat
181 */
182 
183 extern BOOL HTBind_getAnchorBindings	(HTParentAnchor * anchor);
184 
185 /*
186 .
187   Determine the content of a Response
188 .
189 
190 Use the set of bindings to find the combination of language, media type and
191 encoding of a given anchor. If more than one suffix is found they are all
192 searched. The last suffix has highest priority, the first one lowest. Returns
193 the HTResponse object with the representations
194 found. See also HTBind_getFormat
195 */
196 
197 extern BOOL HTBind_getResponseBindings	(HTResponse * response,
198                                          const char * url);
199 
200 /*
201 .
202   Determine the content of File
203 .
204 
205 Use the set of bindings to find the combination of language, media type and
206 encoding of a given anchor. If more than one suffix is found they are all
207 searched. The last suffix has highest priority, the first one lowest. Returns
208 the format, encoding, and language found. See also
209 HTBind_getBindings.
210 */
211 
212 extern BOOL HTBind_getFormat (const char *	filename,
213 			      HTFormat *	format,
214 			      HTEncoding *	enc,
215 			      HTEncoding *	cte,
216 			      HTLanguage *	lang,
217 			      double *		quality);
218 
219 /*
220 
221 End of declaration module
222 */
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 
228 #endif /* HTBIND_H */
229 
230 /*
231 
232 
233 
234   @(#) $Id$
235 
236 */
237