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