Debian Codegraph @

WWW/Library/Implementation/HTFile.h

raw
1 /*
2 * $LynxId: HTFile.h,v 1.39 2025/01/06 15:13:11 tom Exp $
3 * File access in libwww
4 * FILE ACCESS
5 *
6 * These are routines for local file access used by WWW browsers and servers.
7 * Implemented by HTFile.c.
8 *
9 * If the file is not a local file, then we pass it on to HTFTP in case it
10 * can be reached by FTP.
11 */
12 #ifndef HTFILE_H
13 #define HTFILE_H
14
15 #include <HTFormat.h>
16 #include <HTAccess.h>
17
18 #ifndef HTML_H
19 #include <HTML.h> /* SCW */
20 #endif /* HTML_H */
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 /*
26 * Controlling globals
27 *
28 * These flags control how directories and files are represented as
29 * hypertext, and are typically set by the application from command
30 * line options, etc.
31 */ extern int HTDirAccess;
32 /* Directory access level */
33
34 #define HT_DIR_FORBID 0 /* Altogether forbidden */
35 #define HT_DIR_SELECTIVE 1 /* If HT_DIR_ENABLE_FILE exists */
36 #define HT_DIR_OK 2 /* Any accessible directory */
37
38 #define HT_DIR_ENABLE_FILE ".www_browsable" /* If exists, can browse */
39
40 extern int HTDirReadme; /* Include readme files in listing? */
41
42 /* Values: */
43 #define HT_DIR_README_NONE 0 /* No */
44 #define HT_DIR_README_TOP 1 /* Yes, first */
45 #define HT_DIR_README_BOTTOM 2 /* Yes, at the end */
46
47 #define HT_DIR_README_FILE "README"
48
49 /*
50 * Convert filenames between local and WWW formats
51 */
52 extern char *HTURLPath_toFile(const char *name, int expand_all, int is_remote);
53 extern char *HTnameOfFile_WWW(const char *name, int WWW_prefix, int expand_all);
54
55 #define HTLocalName(name) HTnameOfFile_WWW(name,TRUE,TRUE)
56 #define HTfullURL_toFile(name) HTnameOfFile_WWW(name,FALSE,TRUE)
57 #define HTpartURL_toFile(name) HTnameOfFile_WWW(name,FALSE,FALSE)
58
59 /*
60 * Make a WWW name from a full local path name
61 */
62 extern char *WWW_nameOfFile(const char *name);
63
64 /*
65 * Generate the name of a cache file
66 */
67 extern char *HTCacheFileName(const char *name);
68
69 /*
70 * Generate fragments of HTML for source-view:
71 */
72 extern void HTStructured_doctype(HTStructured * target, HTFormat format_out);
73
74 extern void HTStructured_meta(HTStructured * target, HTFormat format_out);
75 /*
76 * Output directory titles
77 *
78 * This is (like the next one) used by HTFTP. It is common code to generate
79 * the title and heading 1 and the parent directory link for any anchor.
80 *
81 * changed to return TRUE if parent directory link was generated,
82 * FALSE otherwise - KW
83 */
84 extern BOOL HTDirTitles(HTStructured * target, HTParentAnchor *anchor,
85 HTFormat format_out,
86 int tildeIsTop);
87
88 /*
89 * Check existence.
90 */
91 extern int HTStat(const char *filename,
92 struct stat *data);
93
94 /* Load a document.
95 * ----------------
96 */
97 extern int HTLoadFile(const char *addr,
98 HTParentAnchor *anchor,
99 HTFormat format_out,
100 HTStream *sink);
101
102 /*
103 * Output a directory entry
104 *
105 * This is used by HTFTP.c for example -- it is a common routine for
106 * generating a linked directory entry.
107 */
108 extern void HTDirEntry(HTStructured * target, /* in which to put the linked text */ const char *tail, /* last part of directory name */
109 const char *entry); /* name of this entry */
110
111 /*
112 * HTSetSuffix: Define the representation for a file suffix
113 *
114 * This defines a mapping between local file suffixes and file content
115 * types and encodings.
116 *
117 * ON ENTRY,
118 *
119 * suffix includes the "." if that is important (normally, yes!)
120 *
121 * representation is MIME-style content-type
122 *
123 * encoding is MIME-style content-transfer-encoding
124 * (8bit, 7bit, etc) or HTTP-style content-encoding
125 * (gzip, compress etc.)
126 *
127 * quality an a priori judgement of the quality of such files
128 * (0.0..1.0)
129 *
130 * HTSetSuffix5 has one more parameter for a short description of the type
131 * which is otherwise derived from the representation:
132 *
133 * desc is a short textual description, or NULL
134 *
135 * Examples: HTSetSuffix(".ps", "application/postscript", "8bit", 1.0);
136 * Examples: HTSetSuffix(".psz", "application/postscript", "gzip", 1.0);
137 * A MIME type could also indicate a non-trivial encoding on its own
138 * ("application/x-compressed-tar"), but in that case don't use encoding
139 * to also indicate it but use "binary" etc.
140 */
141 extern void HTSetSuffix5(const char *suffix,
142 const char *representation,
143 const char *encoding,
144 const char *desc,
145 double quality);
146
147 #define HTSetSuffix(suff,rep,enc,q) HTSetSuffix5(suff, rep, enc, NULL, q)
148
149 /*
150 * HTFileFormat: Get Representation and Encoding from file name.
151 *
152 * ON EXIT,
153 *
154 * return The representation it imagines the file is in.
155 *
156 * *pEncoding The encoding (binary, 7bit, etc). See HTSetSuffix.
157 */
158 extern HTFormat HTFileFormat(const char *filename,
159 HTAtom **pEncoding,
160 const char **pDesc);
161
162 /*
163 * HTCharsetFormat: Revise the file format in relation to the Lynx charset.
164 *
165 * This checks the format associated with an anchor for
166 * for an extended MIME Content-Type, and if a charset is
167 * indicated, sets Lynx up for proper handling in relation
168 * to the currently selected character set. - FM
169 */
170 extern HTFormat HTCharsetFormat(HTFormat format,
171 HTParentAnchor *anchor,
172 int default_LYhndl);
173
174 /* Get various pieces of meta info from file name.
175 * -----------------------------------------------
176 *
177 * LYGetFileInfo fills in information that can be determined without
178 * an actual (new) access to the filesystem, based on current suffix
179 * and character set configuration. If the file has been loaded and
180 * parsed before (with the same URL generated here!) and the anchor
181 * is still around, some results may be influenced by that (in
182 * particular, charset info from a META tag - this is not actually
183 * tested!).
184 * The caller should not keep pointers to the returned objects around
185 * for too long, the valid lifetimes vary. In particular, the returned
186 * charset string should be copied if necessary. If return of the
187 * file_anchor is requested, that one can be used to retrieve
188 * additional bits of info that are stored in the anchor object and
189 * are not covered here; as usual, don't keep pointers to the
190 * file_anchor longer than necessary since the object may disappear
191 * through HTuncache_current_document or at the next document load.
192 * - kw
193 */
194 extern void LYGetFileInfo(const char *filename,
195 HTParentAnchor **pfile_anchor,
196 HTFormat *pformat,
197 HTAtom **pencoding,
198 const char **pdesc,
199 const char **pcharset,
200 int *pfile_cs);
201
202 /*
203 * Determine file value from file name.
204 */
205 extern float HTFileValue(const char *filename);
206
207 /*
208 * Known compression types.
209 */
210 typedef enum {
211 cftNone
212 ,cftCompress
213 ,cftGzip
214 ,cftBzip2
215 ,cftDeflate
216 ,cftBrotli
217 ,cftZstd
218 } CompressFileType;
219
220 /*
221 * Determine compression type from file name, by looking at its suffix.
222 */
223 extern CompressFileType HTCompressFileType(const char *filename,
224 const char *dots,
225 int *rootlen);
226
227 /*
228 * Determine compression type from the content-encoding.
229 */
230 extern CompressFileType HTEncodingToCompressType(const char *encoding);
231 /*
232 * Determine compression type from the content-encoding.
233 */
234 extern CompressFileType HTContentTypeToCompressType(const char *ct);
235 /*
236 * Check if a given content-encoding (format) matches something we support.
237 */
238 extern BOOL IsCompressionFormat(HTAtom *format, CompressFileType check);
239 /*
240 * Determine compression type from the content-type and/or content-encoding.
241 */
242 extern CompressFileType HTContentToCompressType(HTParentAnchor *anchor);
243 /*
244 * Determine compression encoding from the compression method.
245 */
246 extern const char *HTCompressTypeToEncoding(CompressFileType method);
247 /*
248 * Determine expected file-suffix from the compression method.
249 */
250 extern const char *HTCompressTypeToSuffix(CompressFileType method);
251 /*
252 * Determine write access to a file.
253 *
254 * ON EXIT,
255 *
256 * return value YES if file can be accessed and can be written to.
257 *
258 * BUGS
259 *
260 * Isn't there a quicker way?
261 */
262
263 #if defined(HAVE_CONFIG_H)
264
265 #ifndef HAVE_GETGROUPS
266 #define NO_GROUPS
267 #endif
268
269 #else
270
271 #ifdef VMS
272 #define NO_GROUPS
273 #endif /* VMS */
274 #ifdef NO_UNIX_IO
275 #define NO_GROUPS
276 #endif /* NO_UNIX_IO */
277 #ifdef PCNFS
278 #define NO_GROUPS
279 #endif /* PCNFS */
280 #ifdef NOUSERS
281 #define NO_GROUPS
282 #endif /* PCNFS */
283
284 #endif /* HAVE_CONFIG_H */
285
286 extern BOOL HTEditable(const char *filename);
287
288 /* Make a save stream.
289 * -------------------
290 */
291 extern HTStream *HTFileSaveStream(HTParentAnchor *anchor);
292
293 /*
294 * Determine a suitable suffix, given the representation.
295 *
296 * ON ENTRY,
297 *
298 * rep is the atomized MIME style representation
299 * enc is an encoding (8bit, binary, gzip, compress,..)
300 *
301 * ON EXIT,
302 *
303 * returns a pointer to a suitable suffix string if one has
304 * been found, else NULL.
305 */
306 extern const char *HTFileSuffix(HTAtom *rep,
307 const char *enc);
308
309 /*
310 * Enumerate external programs that lynx may assume exists. Unlike those
311 * given in download scripts, etc., lynx would really like to know their
312 * absolute paths, for better security.
313 */
314 typedef enum {
315 ppUnknown = 0
316 ,ppBROTLI
317 ,ppBZIP2
318 ,ppCHMOD
319 ,ppCOMPRESS
320 ,ppCOPY
321 ,ppCSWING
322 ,ppGZIP
323 ,ppINFLATE
324 ,ppINSTALL
325 ,ppMKDIR
326 ,ppMV
327 ,ppRLOGIN
328 ,ppRM
329 ,ppRMDIR
330 ,ppSETFONT
331 ,ppTAR
332 ,ppTELNET
333 ,ppTN3270
334 ,ppTOUCH
335 ,ppUNCOMPRESS
336 ,ppUNZIP
337 ,ppUUDECODE
338 ,ppZCAT
339 ,ppZIP
340 ,ppZSTD
341 ,pp_Last
342 } ProgramPaths;
343
344 /*
345 * Given a program number, return its path
346 */
347 extern const char *HTGetProgramPath(ProgramPaths code);
348
349 /*
350 * Store a program's path
351 */
352 extern void HTSetProgramPath(ProgramPaths code,
353 const char *path);
354
355 /*
356 * Reset the list of known program paths to the ones that are compiled-in
357 */
358 extern void HTInitProgramPaths(BOOL init);
359
360 /*
361 * The Protocols
362 */
363 #ifdef GLOBALREF_IS_MACRO
364 extern GLOBALREF (HTProtocol, HTFTP);
365 extern GLOBALREF (HTProtocol, HTFile);
366
367 #else
368 GLOBALREF HTProtocol HTFTP, HTFile;
369 #endif /* GLOBALREF_IS_MACRO */
370
371 #ifdef __cplusplus
372 }
373 #endif
374 #endif /* HTFILE_H */