*
* MIME typing routines for the Common UNIX Printing System (CUPS).
*
- * Copyright 2007 by Apple Inc.
+ * Copyright 2007-2008 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
strlcpy(temp->super, super, sizeof(temp->super));
strcpy(temp->type, type); /* Safe: temp->type is allocated */
+ temp->priority = 100;
cupsArrayAdd(mime->types, temp);
op = MIME_MAGIC_LOCALE;
else if (!strcmp(name, "contains"))
op = MIME_MAGIC_CONTAINS;
+ else if (!strcmp(name, "priority") && num_values == 1)
+ {
+ mt->priority = atoi(value[0]);
+ continue;
+ }
else
return (-1);
}
{
_mime_filebuf_t fb; /* File buffer */
const char *base; /* Base filename of file */
- mime_type_t *type; /* File type */
+ mime_type_t *type, /* File type */
+ *best; /* Best match */
DEBUG_printf(("mimeFileType(mime=%p, pathname=\"%s\", filename=\"%s\", "
* Then check it against all known types...
*/
- for (type = (mime_type_t *)cupsArrayFirst(mime->types);
+ for (type = (mime_type_t *)cupsArrayFirst(mime->types), best = NULL;
type;
type = (mime_type_t *)cupsArrayNext(mime->types))
if (checkrules(base, &fb, type->rules))
- break;
+ {
+ if (!best || type->priority > best->priority)
+ best = type;
+ }
/*
* Finally, close the file and return a match (if any)...
cupsFileClose(fb.fp);
- return (type);
+ return (best);
}