HTFile.h 9.2 KB

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