summaryrefslogtreecommitdiff
path: root/apps/JAWS/clients/WebSTONE/src/nsapi-includes/base/cinfo.h
blob: 6cfdbd6c2c603215758cd04ea71a3bc10cf9549d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * Copyright (c) 1994, 1995.  Netscape Communications Corporation.  All
 * rights reserved.
 *
 * Use of this software is governed by the terms of the license agreement for
 * the Netscape Communications or Netscape Comemrce Server between the
 * parties.
 */


/* ------------------------------------------------------------------------ */


/*
 * cinfo.h: Content Information for a file, i.e. its type, etc.
 *
 * See cinfo.c for dependency information.
 *
 * Rob McCool
 */



#ifndef CINFO_H
#define CINFO_H



/* ------------------------------ Constants ------------------------------- */


/*
 * This will be the first string in the file, followed by x.x version
 * where x is an integer.
 *
 * Updated due to trendy name change
 */

#define MCC_MT_MAGIC "#--Mosaic Communications Corporation MIME Information"
#define MCC_MT_MAGIC_LEN 53
#define NCC_MT_MAGIC "#--Netscape Communications Corporation MIME Information"
#define NCC_MT_MAGIC_LEN 55

/* The character which separates extensions with cinfo_find */

#define CINFO_SEPARATOR '.'

/* The maximum length of a line in this file */

#define CINFO_MAX_LEN 1024

/* The hash function for the database. Hashed on extension. */
#include <ctype.h>
#define CINFO_HASH(s) (isalpha(s[0]) ? tolower(s[0]) - 'a' : 26)

/* The hash table size for that function */
#define CINFO_HASHSIZE 27


/* ------------------------------ Structures ------------------------------ */


/*
 * The ContentInfo structure.
 *
 * Currently, we support the following attributes:
 *
 * 1. Type: This identifies what kind of data is in the file.
 * 2. Encoding: Identifies any compression or otherwise content-independent
 *    transformation which has been applied to the file (uuencode, etc.)
 * 3. Language: Identifies the language a text document is in.
 * 4. Description: A text string describing the file.
 * 5. Viewer: The program to use to view the file.
 *
 * Multiple items are separated with a comma, e.g.
 * encoding="x-gzip, x-uuencode"
 */

typedef struct {
    char *type;
    char *encoding;
    char *language;
} cinfo;


/* ------------------------------ Prototypes ------------------------------ */


/*
 * cinfo_init initializes the content info system. Call this before
 * cinfo_merge.
 */

void cinfo_init(void);

/*
 * cinfo_terminate frees the database for shutdown.
 */

void cinfo_terminate(void);

/*
 * cinfo_merge merges the contents of the given filename with the current
 * cinfo database. It returns NULL upon success and a string (which you
 * must deallocate) upon error.
 */

char *cinfo_merge(char *fn);


/*
 * cinfo_find finds any content information for the given uri. The file name
 * is the string following the last / in the uri. Multiple extensions are
 * separated by CINFO_SEPARATOR. You may pass in a filename instead of uri.
 *
 * Returns a newly allocated cinfo structure with the information it
 * finds. The elements of this structure are coming right out of the types
 * database and so if you change it or want to keep it around for long you
 * should strdup it. You should free only the structure itself when finished
 * with it.
 *
 * If there is no information for any one of the extensions it
 * finds, it will ignore that extension. If it cannot find information for
 * any of the extensions, it will return NULL.
 */

cinfo *cinfo_find(char *uri);

/*
 * cinfo_lookup finds the information about the given content-type, and
 * returns a cinfo structure so you can look up description and icon.
 */

cinfo *cinfo_lookup(char *type);

/*
 * cinfo_dump_database dumps the current database to the given file desc.
 */

#include <stdio.h>
void cinfo_dump_database(FILE *dump);


#endif