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