1
1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## search_mime_files_in_usr_share.dpatch by <martin.pitt@ubuntu.com>
2
## search_mime_files_in_usr_share.dpatch by <till.kamppeter@gmail.com>
4
## All lines beginning with `## DP:' are a description of the patch.
5
## DP: http://www.cups.org/str.php?L2719
4
## DP: http://www.cups.org/str.php?L2719, svn trunk r7670
8
diff -urNad trunk~/scheduler/conf.c trunk/scheduler/conf.c
9
--- trunk~/scheduler/conf.c 2008-03-16 14:22:22.000000000 +0100
10
+++ trunk/scheduler/conf.c 2008-03-16 14:23:33.000000000 +0100
7
diff -urNad cups-1.3.8~/scheduler/conf.c cups-1.3.8/scheduler/conf.c
8
--- cups-1.3.8~/scheduler/conf.c 2008-08-06 22:31:38.000000000 +0200
9
+++ cups-1.3.8/scheduler/conf.c 2008-08-06 22:32:28.000000000 +0200
11
10
@@ -342,6 +342,7 @@
12
11
cups_file_t *fp; /* Configuration file */
13
12
int status; /* Return status */
14
13
char temp[1024], /* Temporary buffer */
15
+ temp2[1024], /* Temporary buffer */
14
+ mimedir[1024], /* MIME directory */
16
15
*slash; /* Directory separator */
17
16
cups_lang_t *language; /* Language */
18
17
struct passwd *user; /* Default user */
19
@@ -1073,11 +1074,21 @@
22
* Read the MIME type and conversion database...
23
+ * Files are read from DataDir/mime by default, and can be overridden in
18
@@ -1100,20 +1101,25 @@
27
21
snprintf(temp, sizeof(temp), "%s/filter", ServerBin);
22
+ snprintf(mimedir, sizeof(mimedir), "%s/mime", DataDir);
29
24
- MimeDatabase = mimeLoad(ServerRoot, temp);
30
+ snprintf(temp2, sizeof(temp2), "%s/mime", DataDir);
31
+ MimeDatabase = mimeLoad(temp2, temp);
34
+ cupsdLogMessage(CUPSD_LOG_INFO,
35
+ "Unable to load MIME database from \'%s\'!", temp2);
38
+ MimeDatabase = mimeMerge(MimeDatabase, ServerRoot, temp);
25
+ MimeDatabase = mimeLoadTypes(NULL, mimedir);
26
+ MimeDatabase = mimeLoadTypes(MimeDatabase, ServerRoot);
27
+ MimeDatabase = mimeLoadFilters(MimeDatabase, mimedir, temp);
28
+ MimeDatabase = mimeLoadFilters(MimeDatabase, ServerRoot, temp);
32
cupsdLogMessage(CUPSD_LOG_EMERG,
33
- "Unable to load MIME database from \'%s\'!", ServerRoot);
34
+ "Unable to load MIME database from \"%s\" or \"%s\"!",
35
+ mimedir, ServerRoot);
39
cupsdLogMessage(CUPSD_LOG_INFO,
40
- "Loaded MIME database from \'%s\': %d types, %d filters...",
41
- ServerRoot, mimeNumTypes(MimeDatabase),
42
- mimeNumFilters(MimeDatabase));
43
+ "Loaded MIME database from \"%s\" and \"%s\": %d types, "
44
+ "%d filters...", mimedir, ServerRoot,
45
+ mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
48
* Create a list of MIME types for the document-format-supported
49
--- cups-1.3.8~/scheduler/cupsfilter.c 2008-01-16 23:20:33.000000000 +0100
50
+++ cups-1.3.8/scheduler/cupsfilter.c 2008-08-06 22:32:38.000000000 +0200
52
int compression; /* Compression of file */
53
int cost; /* Cost of filters */
54
mime_t *mime; /* MIME database */
55
+ char mimedir[1024]; /* MIME directory */
56
char *infile, /* File to filter */
57
*outfile; /* File to create */
58
char cupsdconf[1024]; /* cupsd.conf file */
60
if (read_cupsd_conf(cupsdconf))
63
- if ((mime = mimeLoad(ServerRoot, Path)) == NULL)
64
+ snprintf(mimedir, sizeof(mimedir), "%s/mime", DataDir);
66
+ mime = mimeLoadTypes(NULL, mimedir);
67
+ mime = mimeLoadTypes(mime, ServerRoot);
68
+ mime = mimeLoadFilters(mime, mimedir, Path);
69
+ mime = mimeLoadFilters(mime, ServerRoot, Path);
73
_cupsLangPrintf(stderr,
74
- _("%s: Unable to read MIME database from \"%s\"!\n"),
75
- command, ServerRoot);
76
+ _("%s: Unable to read MIME database from \"%s\" or "
78
+ command, mimedir, ServerRoot);
82
--- cups-1.3.8~/scheduler/mime.c 2008-01-17 00:42:35.000000000 +0100
83
+++ cups-1.3.8/scheduler/mime.c 2008-08-06 22:32:48.000000000 +0200
85
const char *filterpath,
86
cups_array_t *filtercache);
87
static void load_types(mime_t *mime, const char *filename);
88
+static mime_t *mime_new(void);
95
* 'mimeLoad()' - Create a new MIME database from disk.
97
+ * This function uses @link mimeLoadFilters@ and @link mimeLoadTypes@ to
98
+ * create a MIME database from a single directory.
101
mime_t * /* O - New MIME database */
102
mimeLoad(const char *pathname, /* I - Directory to load */
103
const char *filterpath) /* I - Directory to load */
105
- return (mimeMerge(NULL, pathname, filterpath));
106
+ return (mimeLoadFilters(mimeLoadTypes(NULL, pathname), pathname, filterpath));
111
- * 'mimeMerge()' - Merge a MIME database from disk with the current one.
112
+ * 'mimeLoadFilters()' - Load filter definitions from disk.
114
+ * This function loads all of the .convs files from the specified directory.
115
+ * Use @link mimeLoadTypes@ to load all types before you load the filters.
118
-mime_t * /* O - Updated MIME database */
119
-mimeMerge(mime_t *mime, /* I - MIME database to add to */
120
- const char *pathname, /* I - Directory to load */
121
- const char *filterpath) /* I - Directory to load */
122
+mime_t * /* O - MIME database */
123
+mimeLoadFilters(mime_t *mime, /* I - MIME database */
124
+ const char *pathname, /* I - Directory to load from */
125
+ const char *filterpath) /* I - Default filter program directory */
127
cups_dir_t *dir; /* Directory */
128
cups_dentry_t *dent; /* Directory entry */
129
- char filename[1024]; /* Full filename of types/converts file */
130
+ char filename[1024]; /* Full filename of .convs file */
131
cups_array_t *filtercache; /* Filter cache */
135
- * First open the directory specified by pathname... Return NULL if nothing
136
- * was read or if the pathname is NULL...
142
- if ((dir = cupsDirOpen(pathname)) == NULL)
146
- * If "mime" is NULL, make a new, blank database...
147
+ * Range check input...
157
+ if (!mime || !pathname || !filterpath)
161
- * Read all the .types files...
162
+ * Then open the directory specified by pathname...
165
- while ((dent = cupsDirRead(dir)) != NULL)
167
- if (strlen(dent->filename) > 6 &&
168
- !strcmp(dent->filename + strlen(dent->filename) - 6, ".types"))
171
- * Load a mime.types file...
174
- snprintf(filename, sizeof(filename), "%s/%s", pathname, dent->filename);
175
- load_types(mime, filename);
179
- cupsDirRewind(dir);
180
+ if ((dir = cupsDirOpen(pathname)) == NULL)
184
* Read all the .convs files...
185
@@ -289,13 +267,62 @@
189
- * 'mimeNew()' - Create a new, empty MIME database.
190
+ * 'mimeLoadTypes()' - Load type definitions from disk.
192
+ * This function loads all of the .types files from the specified directory.
193
+ * Use @link mimeLoadFilters@ to load all filters after you load the types.
196
mime_t * /* O - MIME database */
198
+mimeLoadTypes(mime_t *mime, /* I - MIME database or @code NULL@ to create a new one */
199
+ const char *pathname) /* I - Directory to load from */
201
- return ((mime_t *)calloc(1, sizeof(mime_t)));
202
+ cups_dir_t *dir; /* Directory */
203
+ cups_dentry_t *dent; /* Directory entry */
204
+ char filename[1024]; /* Full filename of .types file */
208
+ * First open the directory specified by pathname...
211
+ if ((dir = cupsDirOpen(pathname)) == NULL)
215
+ * If "mime" is NULL, make a new, empty database...
228
+ * Read all the .types files...
231
+ while ((dent = cupsDirRead(dir)) != NULL)
233
+ if (strlen(dent->filename) > 6 &&
234
+ !strcmp(dent->filename + strlen(dent->filename) - 6, ".types"))
237
+ * Load a mime.types file...
240
+ snprintf(filename, sizeof(filename), "%s/%s", pathname, dent->filename);
241
+ load_types(mime, filename);
252
int cost; /* Cost of filter */
255
+ DEBUG_printf(("load_convs(mime=%p, filename=\"%s\", filterpath=\"%s\", "
256
+ "filtercache=%p)\n", mime, filename, filterpath, filtercache));
260
* First try to open the file...
263
if ((fp = cupsFileOpen(filename, "r")) == NULL)
266
- DEBUG_printf(("\"%s\":\n", filename));
269
* Then read each line from the file, skipping any comments in the file...
272
* Skip blank lines and lines starting with a #...
277
if (!line[0] || line[0] == '#')
282
if ((dsttype = mimeType(mime, super, type)) == NULL)
284
- DEBUG_printf((" Destination type %s/%s not found!\n", super, type));
285
+ DEBUG_printf(("load_convs: Destination type %s/%s not found!\n",
292
if (!add_fcache(filtercache, filter, filterpath))
294
- DEBUG_printf((" Filter %s not found in %s!\n", filter, filterpath));
295
+ DEBUG_printf(("load_convs: Filter %s not found in %s!\n", filter,
301
mime_type_t *typeptr; /* New MIME type */
304
+ DEBUG_printf(("load_types(mime=%p, filename=\"%s\")\n", mime, filename));
307
* First try to open the file...
310
if ((fp = cupsFileOpen(filename, "r")) == NULL)
313
- DEBUG_printf(("\"%s\":\n", filename));
316
* Then read each line from the file, skipping any comments in the file...
319
* Skip blank lines and lines starting with a #...
324
if (!line[0] || line[0] == '#')
331
+ * 'mime_new()' - Create a new, empty MIME database.
334
+static mime_t * /* O - MIME database */
337
+ return ((mime_t *)calloc(1, sizeof(mime_t)));
342
* End of "$Id: mime.c 7224 2008-01-16 23:42:35Z mike $".
344
--- cups-1.3.8~/scheduler/mime.h 2007-07-11 23:46:42.000000000 +0200
345
+++ cups-1.3.8/scheduler/mime.h 2008-08-06 22:32:51.000000000 +0200
348
* MIME type/conversion database definitions for the Common UNIX Printing System (CUPS).
350
- * Copyright 2007 by Apple Inc.
351
+ * Copyright 2007-2008 by Apple Inc.
352
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
354
* These coded instructions, statements, and computer programs are the
356
typedef struct _mime_type_s /**** MIME Type Data ****/
358
mime_magic_t *rules; /* Rules used to detect this type */
359
+ int priority; /* Priority of this type */
360
char super[MIME_MAX_SUPER], /* Super-type name ("image", "application", etc.) */
361
type[MIME_MAX_TYPE]; /* Type name ("png", "postscript", etc.) */
365
extern void mimeDelete(mime_t *mime);
366
extern mime_t *mimeLoad(const char *pathname, const char *filterpath);
367
-extern mime_t *mimeMerge(mime_t *mime, const char *pathname,
368
- const char *filterpath);
369
-extern mime_t *mimeNew(void);
370
+extern mime_t *mimeLoadFilters(mime_t *mime, const char *pathname,
371
+ const char *filterpath);
372
+extern mime_t *mimeLoadTypes(mime_t *mime, const char *pathname);
374
extern mime_type_t *mimeAddType(mime_t *mime, const char *super,
376
--- cups-1.3.8~/scheduler/type.c 2008-07-12 00:48:49.000000000 +0200
377
+++ cups-1.3.8/scheduler/type.c 2008-08-06 22:33:06.000000000 +0200
380
* MIME typing routines for the Common UNIX Printing System (CUPS).
382
- * Copyright 2007 by Apple Inc.
383
+ * Copyright 2007-2008 by Apple Inc.
384
* Copyright 1997-2006 by Easy Software Products, all rights reserved.
386
* These coded instructions, statements, and computer programs are the
389
strlcpy(temp->super, super, sizeof(temp->super));
390
strcpy(temp->type, type); /* Safe: temp->type is allocated */
391
+ temp->priority = 100;
393
cupsArrayAdd(mime->types, temp);
396
logic = MIME_MAGIC_NOP;
399
- DEBUG_printf(("%s/%s: %s\n", mt->super, mt->type, rule));
400
+ DEBUG_printf(("mimeAddTypeRule: %s/%s: %s\n", mt->super, mt->type, rule));
402
while (*rule != '\0')
404
@@ -165,13 +166,13 @@
408
- DEBUG_puts("new parenthesis group");
409
+ DEBUG_puts("mimeAddTypeRule: New parenthesis group");
410
logic = MIME_MAGIC_NOP;
413
else if (*rule == ')')
415
- DEBUG_puts("close paren...");
416
+ DEBUG_puts("mimeAddTypeRule: Close paren...");
417
if (current == NULL || current->parent == NULL)
420
@@ -207,11 +208,12 @@
421
current->prev = NULL;
422
current->parent = temp;
424
- DEBUG_printf(("creating new AND group %p...\n", temp));
425
+ DEBUG_printf(("mimeAddTypeRule: Creating new AND group %p...\n", temp));
429
- DEBUG_printf(("setting group %p op to AND...\n", current->parent));
430
+ DEBUG_printf(("mimeAddTypeRule: Setting group %p op to AND...\n",
432
current->parent->op = MIME_MAGIC_AND;
436
if ((temp = calloc(1, sizeof(mime_magic_t))) == NULL)
439
- DEBUG_printf(("creating new AND group %p inside OR group\n", temp));
440
+ DEBUG_printf(("mimeAddTypeRule: Creating new AND group %p inside OR "
443
while (current->prev != NULL)
446
* This isn't the top rule, so go up one level...
449
- DEBUG_puts("going up one level");
450
+ DEBUG_puts("mimeAddTypeRule: Going up one level");
451
current = current->parent;
456
else if (*rule == '!')
459
+ DEBUG_puts("mimeAddTypeRule: NOT");
464
op = MIME_MAGIC_LOCALE;
465
else if (!strcmp(name, "contains"))
466
op = MIME_MAGIC_CONTAINS;
467
+ else if (!strcmp(name, "priority") && num_values == 1)
469
+ mt->priority = atoi(value[0]);
476
* Add parenthetical grouping...
479
- DEBUG_printf(("making new OR group %p for parenthesis...\n", temp));
480
+ DEBUG_printf(("mimeAddTypeRule: Making new OR group %p for "
481
+ "parenthesis...\n", temp));
483
temp->op = MIME_MAGIC_OR;
486
logic = MIME_MAGIC_OR;
489
- DEBUG_printf(("adding %p: %s, op = %d, logic = %d, invert = %d\n",
490
- temp, name, op, logic, invert));
491
+ DEBUG_printf(("mimeAddTypeRule: adding %p: %s, op=%d, logic=%d, "
492
+ "invert=%d\n", temp, name, op, logic, invert));
495
* Fill in data for the rule...
496
@@ -530,14 +539,12 @@
498
_mime_filebuf_t fb; /* File buffer */
499
const char *base; /* Base filename of file */
500
- mime_type_t *type; /* File type */
501
+ mime_type_t *type, /* File type */
502
+ *best; /* Best match */
505
DEBUG_printf(("mimeFileType(mime=%p, pathname=\"%s\", filename=\"%s\", "
506
- "compression=%p)\n",
507
- mime, pathname ? pathname : "(nil)",
508
- filename ? filename : "(nil)",
510
+ "compression=%p)\n", mime, pathname, filename, compression));
513
* Range check input parameters...
514
@@ -576,11 +583,14 @@
515
* Then check it against all known types...
518
- for (type = (mime_type_t *)cupsArrayFirst(mime->types);
519
+ for (type = (mime_type_t *)cupsArrayFirst(mime->types), best = NULL;
521
type = (mime_type_t *)cupsArrayNext(mime->types))
522
if (checkrules(base, &fb, type->rules))
525
+ if (!best || type->priority > best->priority)
530
* Finally, close the file and return a match (if any)...
533
cupsFileClose(fb.fp);
543
case MIME_MAGIC_STRING :
544
- DEBUG_printf((" string(%d, \"%s\")\n", rules->offset,
545
+ DEBUG_printf(("checkrules: string(%d, \"%s\")\n", rules->offset,
546
rules->value.stringv));
551
fb->offset = rules->offset;
553
- DEBUG_printf((" loaded %d byte fb->buffer at %d, starts "
554
+ DEBUG_printf(("checkrules: loaded %d byte fb->buffer at %d, starts "
555
"with \"%c%c%c%c\"...\n",
556
fb->length, fb->offset, fb->buffer[0], fb->buffer[1],
557
fb->buffer[2], fb->buffer[3]));
560
result = (memcmp(fb->buffer + rules->offset - fb->offset,
561
rules->value.stringv, rules->length) == 0);
562
- DEBUG_printf((" result=%d\n", result));
563
+ DEBUG_printf(("checkrules: result=%d\n", result));
566
case MIME_MAGIC_ISTRING :
567
@@ -1027,8 +1037,8 @@
568
* the the rule set is false...
571
- DEBUG_printf((" result of test %p (MIME_MAGIC_%s) is %d\n", rules,
572
- debug_tests[rules->op], result));
573
+ DEBUG_printf(("checkrules: result of test %p (MIME_MAGIC_%s) is %d\n",
574
+ rules, debug_tests[rules->op], result));
576
if ((result && logic == MIME_MAGIC_OR) ||
577
(!result && logic == MIME_MAGIC_AND))