1 /* 2 * $LynxId: HTFile.h,v 1.33 2012/02/10 00:59:15 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 accesible 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 enconding 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 represntation 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 } CompressFileType; 217 218 /* 219 * Determine compression type from file name, by looking at its suffix. 220 */ 221 extern CompressFileType HTCompressFileType(const char *filename, 222 const char *dots, 223 int *rootlen); 224 225 /* 226 * Determine compression type from the content-encoding. 227 */ 228 extern CompressFileType HTEncodingToCompressType(const char *encoding); 229 /* 230 * Determine compression type from the content-encoding. 231 */ 232 extern CompressFileType HTContentTypeToCompressType(const char *ct); 233 /* 234 * Determine compression type from the content-type and/or content-encoding. 235 */ 236 extern CompressFileType HTContentToCompressType(HTParentAnchor *anchor); 237 /* 238 * Determine compression encoding from the compression method. 239 */ 240 extern const char *HTCompressTypeToEncoding(CompressFileType method); 241 /* 242 * Determine expected file-suffix from the compression method. 243 */ 244 extern const char *HTCompressTypeToSuffix(CompressFileType method); 245 /* 246 * Determine write access to a file. 247 * 248 * ON EXIT, 249 * 250 * return value YES if file can be accessed and can be written to. 251 * 252 * BUGS 253 * 254 * Isn't there a quicker way? 255 */ 256 257 #if defined(HAVE_CONFIG_H) 258 259 #ifndef HAVE_GETGROUPS 260 #define NO_GROUPS 261 #endif 262 263 #else 264 265 #ifdef VMS 266 #define NO_GROUPS 267 #endif /* VMS */ 268 #ifdef NO_UNIX_IO 269 #define NO_GROUPS 270 #endif /* NO_UNIX_IO */ 271 #ifdef PCNFS 272 #define NO_GROUPS 273 #endif /* PCNFS */ 274 #ifdef NOUSERS 275 #define NO_GROUPS 276 #endif /* PCNFS */ 277 278 #endif /* HAVE_CONFIG_H */ 279 280 extern BOOL HTEditable(const char *filename); 281 282 /* Make a save stream. 283 * ------------------- 284 */ 285 extern HTStream *HTFileSaveStream(HTParentAnchor *anchor); 286 287 /* 288 * Determine a suitable suffix, given the representation. 289 * 290 * ON ENTRY, 291 * 292 * rep is the atomized MIME style representation 293 * enc is an encoding (8bit, binary, gzip, compress,..) 294 * 295 * ON EXIT, 296 * 297 * returns a pointer to a suitable suffix string if one has 298 * been found, else NULL. 299 */ 300 extern const char *HTFileSuffix(HTAtom *rep, 301 const char *enc); 302 303 /* 304 * Enumerate external programs that lynx may assume exists. Unlike those 305 * given in download scripts, etc., lynx would really like to know their 306 * absolute paths, for better security. 307 */ 308 typedef enum { 309 ppUnknown = 0 310 ,ppBZIP2 311 ,ppCHMOD 312 ,ppCOMPRESS 313 ,ppCOPY 314 ,ppCSWING 315 ,ppGZIP 316 ,ppINFLATE 317 ,ppINSTALL 318 ,ppMKDIR 319 ,ppMV 320 ,ppRLOGIN 321 ,ppRM 322 ,ppRMDIR 323 ,ppSETFONT 324 ,ppTAR 325 ,ppTELNET 326 ,ppTN3270 327 ,ppTOUCH 328 ,ppUNCOMPRESS 329 ,ppUNZIP 330 ,ppUUDECODE 331 ,ppZCAT 332 ,ppZIP 333 ,pp_Last 334 } ProgramPaths; 335 336 /* 337 * Given a program number, return its path 338 */ 339 extern const char *HTGetProgramPath(ProgramPaths code); 340 341 /* 342 * Store a program's path 343 */ 344 extern void HTSetProgramPath(ProgramPaths code, 345 const char *path); 346 347 /* 348 * Reset the list of known program paths to the ones that are compiled-in 349 */ 350 extern void HTInitProgramPaths(BOOL init); 351 352 /* 353 * The Protocols 354 */ 355 #ifdef GLOBALREF_IS_MACRO 356 extern GLOBALREF (HTProtocol, HTFTP); 357 extern GLOBALREF (HTProtocol, HTFile); 358 359 #else 360 GLOBALREF HTProtocol HTFTP, HTFile; 361 #endif /* GLOBALREF_IS_MACRO */ 362 363 #ifdef __cplusplus 364 } 365 #endif 366 #endif /* HTFILE_H */ 367