]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * "$Id$" | |
3 | * | |
4 | * MIME type/conversion database definitions for CUPS. | |
5 | * | |
6 | * Copyright 2007-2013 by Apple Inc. | |
7 | * Copyright 1997-2007 by Easy Software Products, all rights reserved. | |
8 | * | |
9 | * These coded instructions, statements, and computer programs are the | |
10 | * property of Apple Inc. and are protected by Federal copyright | |
11 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
12 | * which should have been included with this file. If this file is | |
13 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
14 | */ | |
15 | ||
16 | #ifndef _CUPS_MIME_H_ | |
17 | # define _CUPS_MIME_H_ | |
18 | ||
19 | # include <cups/array.h> | |
20 | # include <cups/ipp.h> | |
21 | # include <cups/file.h> | |
22 | # include <regex.h> | |
23 | ||
24 | ||
25 | /* | |
26 | * C++ magic... | |
27 | */ | |
28 | ||
29 | # ifdef __cplusplus | |
30 | extern "C" { | |
31 | # endif /* __cplusplus */ | |
32 | ||
33 | ||
34 | /* | |
35 | * Constants... | |
36 | */ | |
37 | ||
38 | # define MIME_MAX_SUPER 16 /* Maximum size of supertype name */ | |
39 | # define MIME_MAX_TYPE IPP_MAX_NAME /* Maximum size of type name */ | |
40 | # define MIME_MAX_FILTER 256 /* Maximum size of filter pathname */ | |
41 | # define MIME_MAX_BUFFER 4096 /* Maximum size of file buffer */ | |
42 | ||
43 | ||
44 | /* | |
45 | * Types/structures... | |
46 | */ | |
47 | ||
48 | typedef enum | |
49 | { | |
50 | MIME_MAGIC_NOP, /* No operation */ | |
51 | MIME_MAGIC_AND, /* Logical AND of all children */ | |
52 | MIME_MAGIC_OR, /* Logical OR of all children */ | |
53 | MIME_MAGIC_MATCH, /* Filename match */ | |
54 | MIME_MAGIC_ASCII, /* ASCII characters in range */ | |
55 | MIME_MAGIC_PRINTABLE, /* Printable characters (32-255) in range */ | |
56 | MIME_MAGIC_STRING, /* String matches */ | |
57 | MIME_MAGIC_CHAR, /* Character/byte matches */ | |
58 | MIME_MAGIC_SHORT, /* Short/16-bit word matches */ | |
59 | MIME_MAGIC_INT, /* Integer/32-bit word matches */ | |
60 | MIME_MAGIC_LOCALE, /* Current locale matches string */ | |
61 | MIME_MAGIC_CONTAINS, /* File contains a string */ | |
62 | MIME_MAGIC_ISTRING, /* Case-insensitive string matches */ | |
63 | MIME_MAGIC_REGEX /* Regular expression matches */ | |
64 | } mime_op_t; | |
65 | ||
66 | typedef struct _mime_magic_s /**** MIME Magic Data ****/ | |
67 | { | |
68 | struct _mime_magic_s *prev, /* Previous rule */ | |
69 | *next, /* Next rule */ | |
70 | *parent, /* Parent rules */ | |
71 | *child; /* Child rules */ | |
72 | short op, /* Operation code (see above) */ | |
73 | invert; /* Invert the result */ | |
74 | int offset, /* Offset in file */ | |
75 | region, /* Region length */ | |
76 | length; /* Length of data */ | |
77 | union | |
78 | { | |
79 | char matchv[64]; /* Match value */ | |
80 | char localev[64]; /* Locale value */ | |
81 | char stringv[64]; /* String value */ | |
82 | unsigned char charv; /* Byte value */ | |
83 | unsigned short shortv; /* Short value */ | |
84 | unsigned intv; /* Integer value */ | |
85 | regex_t rev; /* Regular expression value */ | |
86 | } value; | |
87 | } mime_magic_t; | |
88 | ||
89 | typedef struct _mime_type_s /**** MIME Type Data ****/ | |
90 | { | |
91 | mime_magic_t *rules; /* Rules used to detect this type */ | |
92 | int priority; /* Priority of this type */ | |
93 | char super[MIME_MAX_SUPER], /* Super-type name ("image", "application", etc.) */ | |
94 | type[MIME_MAX_TYPE]; /* Type name ("png", "postscript", etc.) */ | |
95 | } mime_type_t; | |
96 | ||
97 | typedef struct _mime_filter_s /**** MIME Conversion Filter Data ****/ | |
98 | { | |
99 | mime_type_t *src, /* Source type */ | |
100 | *dst; /* Destination type */ | |
101 | int cost; /* Relative cost */ | |
102 | char filter[MIME_MAX_FILTER];/* Filter program to use */ | |
103 | size_t maxsize; /* Maximum file size for this filter */ | |
104 | } mime_filter_t; | |
105 | ||
106 | typedef void (*mime_error_cb_t)(void *ctx, const char *message); | |
107 | ||
108 | typedef struct _mime_s /**** MIME Database ****/ | |
109 | { | |
110 | cups_array_t *types; /* File types */ | |
111 | cups_array_t *filters; /* Type conversion filters */ | |
112 | cups_array_t *srcs; /* Filters sorted by source type */ | |
113 | mime_error_cb_t error_cb; /* Error message callback */ | |
114 | void *error_ctx; /* Pointer for callback */ | |
115 | } mime_t; | |
116 | ||
117 | ||
118 | /* | |
119 | * Functions... | |
120 | */ | |
121 | ||
122 | extern void mimeDelete(mime_t *mime); | |
123 | extern mime_t *mimeNew(void) _CUPS_API_1_5; | |
124 | extern mime_t *mimeLoad(const char *pathname, const char *filterpath); | |
125 | extern mime_t *mimeLoadFilters(mime_t *mime, const char *pathname, | |
126 | const char *filterpath); | |
127 | extern mime_t *mimeLoadTypes(mime_t *mime, const char *pathname); | |
128 | ||
129 | extern mime_type_t *mimeAddType(mime_t *mime, const char *super, | |
130 | const char *type); | |
131 | extern int mimeAddTypeRule(mime_type_t *mt, const char *rule); | |
132 | extern void mimeDeleteType(mime_t *mime, mime_type_t *mt); | |
133 | extern mime_type_t *mimeFileType(mime_t *mime, const char *pathname, | |
134 | const char *filename, int *compression); | |
135 | extern mime_type_t *mimeFirstType(mime_t *mime); | |
136 | extern mime_type_t *mimeNextType(mime_t *mime); | |
137 | extern int mimeNumTypes(mime_t *mime); | |
138 | extern mime_type_t *mimeType(mime_t *mime, const char *super, | |
139 | const char *type); | |
140 | ||
141 | extern mime_filter_t *mimeAddFilter(mime_t *mime, mime_type_t *src, | |
142 | mime_type_t *dst, int cost, | |
143 | const char *filter); | |
144 | extern void mimeDeleteFilter(mime_t *mime, mime_filter_t *filter); | |
145 | extern cups_array_t *mimeFilter(mime_t *mime, mime_type_t *src, | |
146 | mime_type_t *dst, int *cost); | |
147 | extern cups_array_t *mimeFilter2(mime_t *mime, mime_type_t *src, | |
148 | size_t srcsize, mime_type_t *dst, | |
149 | int *cost); | |
150 | extern mime_filter_t *mimeFilterLookup(mime_t *mime, mime_type_t *src, | |
151 | mime_type_t *dst); | |
152 | extern mime_filter_t *mimeFirstFilter(mime_t *mime); | |
153 | extern mime_filter_t *mimeNextFilter(mime_t *mime); | |
154 | extern int mimeNumFilters(mime_t *mime); | |
155 | extern void mimeSetErrorCallback(mime_t *mime, mime_error_cb_t cb, | |
156 | void *context) _CUPS_API_1_5; | |
157 | ||
158 | # ifdef __cplusplus | |
159 | } | |
160 | # endif /* __cplusplus */ | |
161 | #endif /* !_CUPS_MIME_H_ */ | |
162 | ||
163 | /* | |
164 | * End of "$Id$". | |
165 | */ |