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