~ubuntu-branches/ubuntu/edgy/lynx/edgy

« back to all changes in this revision

Viewing changes to WWW/Library/Implementation/HTFormat.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-16 12:14:10 UTC
  • Revision ID: james.westby@ubuntu.com-20040916121410-cz1gu92c4nqfeyrg
Tags: upstream-2.8.5
ImportĀ upstreamĀ versionĀ 2.8.5

Show diffs side-by-side

added added

removed removed

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