PageRenderTime 63ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/lynx2-8-7/WWW/Library/Implementation/HTFormat.h

#
C Header | 544 lines | 178 code | 55 blank | 311 comment | 7 complexity | 5208146b905b8d11bf5bf45aa090d4d1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0
  1. /* HTFormat: The format manager in the WWW Library
  2. MANAGE DIFFERENT DOCUMENT FORMATS
  3. Here we describe the functions of the HTFormat module which handles conversion between
  4. different data representations. (In MIME parlance, a representation is known as a
  5. content-type. In WWW the term "format" is often used as it is shorter).
  6. This module is implemented by HTFormat.c. This hypertext document is used to generate
  7. the HTFormat.h include file. Part of the WWW library.
  8. Preamble
  9. */
  10. #ifndef HTFORMAT_H
  11. #define HTFORMAT_H
  12. #include <HTStream.h>
  13. #include <HTAtom.h>
  14. #include <HTList.h>
  15. #include <HTAnchor.h>
  16. #ifdef USE_SOURCE_CACHE
  17. #include <HTChunk.h>
  18. #endif
  19. #ifdef USE_BZLIB
  20. #include <bzlib.h>
  21. #endif
  22. #ifdef USE_ZLIB
  23. #include <zlib.h>
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /*
  29. These macros (which used to be constants) define some basic internally
  30. referenced representations. The www/xxx ones are of course not MIME
  31. standard.
  32. www/source is an output format which leaves the input untouched. It is
  33. useful for diagnostics, and for users who want to see the original, whatever
  34. it is.
  35. *//* Internal ones *//* #define WWW_SOURCE HTAtom_for("www/source") *//* Whatever it was originally */ extern HTAtom *WWW_SOURCE;
  36. /* calculated once, heavy used */
  37. /*
  38. www/present represents the user's perception of the document. If you
  39. convert to www/present, you present the material to the user.
  40. */
  41. #define WWW_PRESENT HTAtom_for("www/present") /* The user's perception */
  42. #define WWW_DEBUG HTAtom_for("www/debug")
  43. /*
  44. WWW_DEBUG represents the user's perception of debug information, for example
  45. sent as a HTML document in a HTTP redirection message.
  46. */
  47. /*
  48. The message/rfc822 format means a MIME message or a plain text message with
  49. no MIME header. This is what is returned by an HTTP server.
  50. */
  51. #define WWW_MIME HTAtom_for("www/mime") /* A MIME message */
  52. /*
  53. For parsing only the header. - kw
  54. */
  55. #define WWW_MIME_HEAD HTAtom_for("message/x-rfc822-head")
  56. /*
  57. www/print is like www/present except it represents a printed copy.
  58. */
  59. #define WWW_PRINT HTAtom_for("www/print") /* A printed copy */
  60. /*
  61. www/unknown is a really unknown type. Some default action is appropriate.
  62. */
  63. #define WWW_UNKNOWN HTAtom_for("www/unknown")
  64. #ifdef DIRED_SUPPORT
  65. /*
  66. www/dired signals directory edit mode.
  67. */
  68. #define WWW_DIRED HTAtom_for("www/dired")
  69. #endif
  70. /*
  71. These are regular MIME types. HTML is assumed to be added by the W3 code.
  72. application/octet-stream was mistakenly application/binary in earlier libwww
  73. versions (pre 2.11).
  74. */
  75. #define WWW_PLAINTEXT HTAtom_for("text/plain")
  76. #define WWW_POSTSCRIPT HTAtom_for("application/postscript")
  77. #define WWW_RICHTEXT HTAtom_for("application/rtf")
  78. #define WWW_AUDIO HTAtom_for("audio/basic")
  79. #define WWW_HTML HTAtom_for("text/html")
  80. #define WWW_BINARY HTAtom_for("application/octet-stream")
  81. typedef HTAtom *HTEncoding;
  82. /*
  83. * The following are values for the MIME types:
  84. */
  85. #define WWW_ENC_7BIT HTAtom_for("7bit")
  86. #define WWW_ENC_8BIT HTAtom_for("8bit")
  87. #define WWW_ENC_BINARY HTAtom_for("binary")
  88. /*
  89. * We also add
  90. */
  91. #define WWW_ENC_COMPRESS HTAtom_for("compress")
  92. /*
  93. * Does a string designate a real encoding, or is it just
  94. * a "dummy" as for example 7bit, 8bit, and binary?
  95. */
  96. #define IsUnityEncStr(senc) \
  97. ((senc)==NULL || *(senc)=='\0' || !strcmp(senc,"identity") ||\
  98. !strcmp(senc,"8bit") || !strcmp(senc,"binary") || !strcmp(senc,"7bit"))
  99. #define IsUnityEnc(enc) \
  100. ((enc)==NULL || (enc)==HTAtom_for("identity") ||\
  101. (enc)==WWW_ENC_8BIT || (enc)==WWW_ENC_BINARY || (enc)==WWW_ENC_7BIT)
  102. /*
  103. The HTPresentation and HTConverter types
  104. This HTPresentation structure represents a possible conversion algorithm
  105. from one format to another. It includes a pointer to a conversion routine.
  106. The conversion routine returns a stream to which data should be fed. See
  107. also HTStreamStack which scans the list of registered converters and calls
  108. one. See the initialisation module for a list of conversion routines.
  109. */
  110. typedef struct _HTPresentation HTPresentation;
  111. typedef HTStream *HTConverter (HTPresentation *pres,
  112. HTParentAnchor *anchor,
  113. HTStream *sink);
  114. struct _HTPresentation {
  115. HTAtom *rep; /* representation name atomized */
  116. HTAtom *rep_out; /* resulting representation */
  117. HTConverter *converter; /* routine to gen the stream stack */
  118. char *command; /* MIME-format command string */
  119. char *testcommand; /* MIME-format test string */
  120. float quality; /* Between 0 (bad) and 1 (good) */
  121. float secs;
  122. float secs_per_byte;
  123. off_t maxbytes;
  124. BOOL get_accept; /* list in "Accept:" for GET */
  125. int accept_opt; /* matches against LYAcceptMedia */
  126. };
  127. /*
  128. The list of presentations is kept by this module. It is also scanned by
  129. modules which want to know the set of formats supported. for example.
  130. */
  131. extern HTList *HTPresentations;
  132. /*
  133. The default presentation is used when no other is appropriate
  134. */
  135. extern HTPresentation *default_presentation;
  136. /*
  137. * Options used for "Accept:" string
  138. */
  139. typedef enum {
  140. /* make the components powers of two so we can add them */
  141. mediaINT = 1 /* internal types predefined in HTInit.c */
  142. ,mediaEXT = 2 /* external types predefined in HTInit.c */
  143. ,mediaCFG = 4 /* types, e.g., viewers, from lynx.cfg */
  144. ,mediaUSR = 8 /* user's mime-types, etc. */
  145. ,mediaSYS = 16 /* system's mime-types, etc. */
  146. /* these are useful flavors for the options menu */
  147. ,mediaOpt1 = mediaINT
  148. ,mediaOpt2 = mediaINT + mediaCFG
  149. ,mediaOpt3 = mediaINT + mediaCFG + mediaUSR
  150. ,mediaOpt4 = mediaINT + mediaCFG + mediaUSR + mediaSYS
  151. /* this is the flavor from pre-2.8.6 */
  152. ,mediaALL = mediaINT + mediaEXT + mediaCFG + mediaUSR + mediaSYS
  153. } AcceptMedia;
  154. /*
  155. * Options used for "Accept-Encoding:" string
  156. */
  157. typedef enum {
  158. encodingNONE = 0
  159. ,encodingGZIP = 1
  160. ,encodingDEFLATE = 2
  161. ,encodingCOMPRESS = 4
  162. ,encodingBZIP2 = 8
  163. ,encodingALL = (encodingGZIP
  164. + encodingDEFLATE
  165. + encodingCOMPRESS
  166. + encodingBZIP2)
  167. } AcceptEncoding;
  168. /*
  169. HTSetPresentation: Register a system command to present a format
  170. ON ENTRY,
  171. rep is the MIME - style format name
  172. command is the MAILCAP - style command template
  173. testcommand is the MAILCAP - style testcommand template
  174. quality A degradation faction 0..1.0
  175. secs A limit on the time user will wait (0.0 for infinity)
  176. secs_per_byte
  177. maxbytes A limit on the length acceptable as input (0 infinite)
  178. media Used in filtering presentation types for "Accept:"
  179. */
  180. extern void HTSetPresentation(const char *representation,
  181. const char *command,
  182. const char *testcommand,
  183. double quality,
  184. double secs,
  185. double secs_per_byte,
  186. long int maxbytes,
  187. AcceptMedia media
  188. );
  189. /*
  190. HTSetConversion: Register a converstion routine
  191. ON ENTRY,
  192. rep_in is the content-type input
  193. rep_out is the resulting content-type
  194. converter is the routine to make the stream to do it
  195. */
  196. extern void HTSetConversion(const char *rep_in,
  197. const char *rep_out,
  198. HTConverter *converter,
  199. float quality,
  200. float secs,
  201. float secs_per_byte,
  202. long int maxbytes,
  203. AcceptMedia media
  204. );
  205. /*
  206. HTStreamStack: Create a stack of streams
  207. This is the routine which actually sets up the conversion. It currently
  208. checks only for direct conversions, but multi-stage conversions are forseen.
  209. It takes a stream into which the output should be sent in the final format,
  210. builds the conversion stack, and returns a stream into which the data in the
  211. input format should be fed. The anchor is passed because hypertxet objects
  212. load information into the anchor object which represents them.
  213. */
  214. extern HTStream *HTStreamStack(HTFormat format_in,
  215. HTFormat format_out,
  216. HTStream *stream_out,
  217. HTParentAnchor *anchor);
  218. /*
  219. HTReorderPresentation: put presentation near head of list
  220. Look up a presentation (exact match only) and, if found, reorder it to the
  221. start of the HTPresentations list. - kw
  222. */
  223. extern void HTReorderPresentation(HTFormat format_in,
  224. HTFormat format_out);
  225. /*
  226. * Setup 'get_accept' flag to denote presentations that are not redundant,
  227. * and will be listed in "Accept:" header.
  228. */
  229. extern void HTFilterPresentations(void);
  230. /*
  231. HTStackValue: Find the cost of a filter stack
  232. Must return the cost of the same stack which HTStreamStack would set up.
  233. ON ENTRY,
  234. format_in The fomat of the data to be converted
  235. format_out The format required
  236. initial_value The intrinsic "value" of the data before conversion on a scale
  237. from 0 to 1
  238. length The number of bytes expected in the input format
  239. */
  240. extern float HTStackValue(HTFormat format_in,
  241. HTFormat rep_out,
  242. float initial_value,
  243. long int length);
  244. #define NO_VALUE_FOUND -1e20 /* returned if none found */
  245. /* Display the page while transfer in progress
  246. * -------------------------------------------
  247. *
  248. * Repaint the page only when necessary.
  249. * This is a traverse call for HText_pageDispaly() - it works!.
  250. *
  251. */
  252. extern void HTDisplayPartial(void);
  253. extern void HTFinishDisplayPartial(void);
  254. /*
  255. HTCopy: Copy a socket to a stream
  256. This is used by the protocol engines to send data down a stream, typically
  257. one which has been generated by HTStreamStack.
  258. */
  259. extern int HTCopy(HTParentAnchor *anchor,
  260. int file_number,
  261. void *handle,
  262. HTStream *sink);
  263. /*
  264. HTFileCopy: Copy a file to a stream
  265. This is used by the protocol engines to send data down a stream, typically
  266. one which has been generated by HTStreamStack. It is currently called by
  267. HTParseFile
  268. */
  269. extern int HTFileCopy(FILE *fp,
  270. HTStream *sink);
  271. #ifdef USE_SOURCE_CACHE
  272. /*
  273. HTMemCopy: Copy a memory chunk to a stream
  274. This is used by the protocol engines to send data down a stream, typically
  275. one which has been generated by HTStreamStack. It is currently called by
  276. HTParseMem
  277. */
  278. extern int HTMemCopy(HTChunk *chunk,
  279. HTStream *sink);
  280. #endif
  281. /*
  282. HTCopyNoCR: Copy a socket to a stream, stripping CR characters.
  283. It is slower than HTCopy .
  284. */
  285. extern void HTCopyNoCR(HTParentAnchor *anchor,
  286. int file_number,
  287. HTStream *sink);
  288. /*
  289. Clear input buffer and set file number
  290. This routine and the one below provide simple character input from sockets.
  291. (They are left over from the older architecture and may not be used very
  292. much.) The existence of a common routine and buffer saves memory space in
  293. small implementations.
  294. */
  295. extern void HTInitInput(int file_number);
  296. /*
  297. Get next character from buffer
  298. */
  299. extern int interrupted_in_htgetcharacter;
  300. extern int HTGetCharacter(void);
  301. /*
  302. HTParseSocket: Parse a socket given its format
  303. This routine is called by protocol modules to load an object. uses
  304. HTStreamStack and the copy routines above. Returns HT_LOADED if successful,
  305. <0 if not.
  306. */
  307. extern int HTParseSocket(HTFormat format_in,
  308. HTFormat format_out,
  309. HTParentAnchor *anchor,
  310. int file_number,
  311. HTStream *sink);
  312. /*
  313. HTParseFile: Parse a File through a file pointer
  314. This routine is called by protocols modules to load an object. uses
  315. HTStreamStack and HTFileCopy. Returns HT_LOADED if successful, can also
  316. return HT_PARTIAL_CONTENT, HT_NO_DATA, or other <0 for failure.
  317. */
  318. extern int HTParseFile(HTFormat format_in,
  319. HTFormat format_out,
  320. HTParentAnchor *anchor,
  321. FILE *fp,
  322. HTStream *sink);
  323. #ifdef USE_SOURCE_CACHE
  324. /*
  325. HTParseMem: Parse a document in memory
  326. This routine is called by protocols modules to load an object. uses
  327. HTStreamStack and HTMemCopy. Returns HT_LOADED if successful, can also
  328. return <0 for failure.
  329. */
  330. extern int HTParseMem(HTFormat format_in,
  331. HTFormat format_out,
  332. HTParentAnchor *anchor,
  333. HTChunk *chunk,
  334. HTStream *sink);
  335. #endif
  336. #ifdef USE_ZLIB
  337. /*
  338. HTParseGzFile: Parse a gzip'ed File through a file pointer
  339. This routine is called by protocols modules to load an object. uses
  340. HTStreamStack and HTGzFileCopy. Returns HT_LOADED if successful, can also
  341. return HT_PARTIAL_CONTENT, HT_NO_DATA, or other <0 for failure.
  342. */
  343. extern int HTParseGzFile(HTFormat format_in,
  344. HTFormat format_out,
  345. HTParentAnchor *anchor,
  346. gzFile gzfp,
  347. HTStream *sink);
  348. /*
  349. HTParseZzFile: Parse a deflate'd File through a file pointer
  350. This routine is called by protocols modules to load an object. uses
  351. HTStreamStack and HTZzFileCopy. Returns HT_LOADED if successful, can also
  352. return HT_PARTIAL_CONTENT, HT_NO_DATA, or other <0 for failure.
  353. */
  354. extern int HTParseZzFile(HTFormat format_in,
  355. HTFormat format_out,
  356. HTParentAnchor *anchor,
  357. FILE *zzfp,
  358. HTStream *sink);
  359. #endif /* USE_ZLIB */
  360. #ifdef USE_BZLIB
  361. /*
  362. HTParseBzFile: Parse a bzip2'ed File through a file pointer
  363. This routine is called by protocols modules to load an object. uses
  364. HTStreamStack and HTGzFileCopy. Returns HT_LOADED if successful, can also
  365. return HT_PARTIAL_CONTENT, HT_NO_DATA, or other <0 for failure.
  366. */
  367. extern int HTParseBzFile(HTFormat format_in,
  368. HTFormat format_out,
  369. HTParentAnchor *anchor,
  370. BZFILE * bzfp,
  371. HTStream *sink);
  372. #endif /* USE_BZLIB */
  373. /*
  374. HTNetToText: Convert Net ASCII to local representation
  375. This is a filter stream suitable for taking text from a socket and passing
  376. it into a stream which expects text in the local C representation. It does
  377. ASCII and newline conversion. As usual, pass its output stream to it when
  378. creating it.
  379. */
  380. extern HTStream *HTNetToText(HTStream *sink);
  381. /*
  382. HTFormatInit: Set up default presentations and conversions
  383. These are defined in HTInit.c or HTSInit.c if these have been replaced. If
  384. you don't call this routine, and you don't define any presentations, then
  385. this routine will automatically be called the first time a conversion is
  386. needed. However, if you explicitly add some conversions (eg using
  387. HTLoadRules) then you may want also to explicitly call this to get the
  388. defaults as well.
  389. */
  390. extern void HTFormatInit(void);
  391. /*
  392. Epilogue
  393. */
  394. extern BOOL HTOutputSource; /* Flag: shortcut parser */
  395. #ifdef __cplusplus
  396. }
  397. #endif
  398. #endif /* HTFORMAT_H */