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