/*
- * "$Id: mime.c 5605 2006-05-30 19:38:02Z mike $"
+ * "$Id: mime.c 7694 2008-06-26 00:23:20Z mike $"
*
* MIME database file routines for the Common UNIX Printing System (CUPS).
*
+ * 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
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* Contents:
*
const char *filterpath,
cups_array_t *filtercache);
static void load_types(mime_t *mime, const char *filename);
+static mime_t *mime_new(void);
/*
/*
* 'mimeLoad()' - Create a new MIME database from disk.
+ *
+ * This function uses @link mimeLoadFilters@ and @link mimeLoadTypes@ to
+ * create a MIME database from a single directory.
*/
mime_t * /* O - New MIME database */
mimeLoad(const char *pathname, /* I - Directory to load */
const char *filterpath) /* I - Directory to load */
{
- return (mimeMerge(NULL, pathname, filterpath));
+ return (mimeLoadFilters(mimeLoadTypes(NULL, pathname), pathname, filterpath));
}
/*
- * 'mimeMerge()' - Merge a MIME database from disk with the current one.
+ * 'mimeLoadFilters()' - Load filter definitions from disk.
+ *
+ * This function loads all of the .convs files from the specified directory.
+ * Use @link mimeLoadTypes@ to load all types before you load the filters.
*/
-mime_t * /* O - Updated MIME database */
-mimeMerge(mime_t *mime, /* I - MIME database to add to */
- const char *pathname, /* I - Directory to load */
- const char *filterpath) /* I - Directory to load */
+mime_t * /* O - MIME database */
+mimeLoadFilters(mime_t *mime, /* I - MIME database */
+ const char *pathname, /* I - Directory to load from */
+ const char *filterpath) /* I - Default filter program directory */
{
cups_dir_t *dir; /* Directory */
cups_dentry_t *dent; /* Directory entry */
- char filename[1024]; /* Full filename of types/converts file */
+ char filename[1024]; /* Full filename of .convs file */
cups_array_t *filtercache; /* Filter cache */
/*
- * First open the directory specified by pathname... Return NULL if nothing
- * was read or if the pathname is NULL...
+ * Range check input...
*/
- if (!pathname)
- return (NULL);
-
- if ((dir = cupsDirOpen(pathname)) == NULL)
- return (NULL);
+ if (!mime || !pathname || !filterpath)
+ return (mime);
/*
- * If "mime" is NULL, make a new, blank database...
+ * Then open the directory specified by pathname...
*/
- if (!mime)
- mime = mimeNew();
- if (!mime)
- return (NULL);
-
- /*
- * Read all the .types files...
- */
-
- while ((dent = cupsDirRead(dir)) != NULL)
- {
- if (strlen(dent->filename) > 6 &&
- !strcmp(dent->filename + strlen(dent->filename) - 6, ".types"))
- {
- /*
- * Load a mime.types file...
- */
-
- snprintf(filename, sizeof(filename), "%s/%s", pathname, dent->filename);
- load_types(mime, filename);
- }
- }
-
- cupsDirRewind(dir);
+ if ((dir = cupsDirOpen(pathname)) == NULL)
+ return (mime);
/*
* Read all the .convs files...
/*
- * 'mimeNew()' - Create a new, empty MIME database.
+ * 'mimeLoadTypes()' - Load type definitions from disk.
+ *
+ * This function loads all of the .types files from the specified directory.
+ * Use @link mimeLoadFilters@ to load all filters after you load the types.
*/
mime_t * /* O - MIME database */
-mimeNew(void)
+mimeLoadTypes(mime_t *mime, /* I - MIME database or @code NULL@ to create a new one */
+ const char *pathname) /* I - Directory to load from */
{
- return ((mime_t *)calloc(1, sizeof(mime_t)));
+ cups_dir_t *dir; /* Directory */
+ cups_dentry_t *dent; /* Directory entry */
+ char filename[1024]; /* Full filename of .types file */
+
+
+ /*
+ * First open the directory specified by pathname...
+ */
+
+ if ((dir = cupsDirOpen(pathname)) == NULL)
+ return (mime);
+
+ /*
+ * If "mime" is NULL, make a new, empty database...
+ */
+
+ if (!mime)
+ mime = mime_new();
+
+ if (!mime)
+ {
+ cupsDirClose(dir);
+ return (NULL);
+ }
+
+ /*
+ * Read all the .types files...
+ */
+
+ while ((dent = cupsDirRead(dir)) != NULL)
+ {
+ if (strlen(dent->filename) > 6 &&
+ !strcmp(dent->filename + strlen(dent->filename) - 6, ".types"))
+ {
+ /*
+ * Load a mime.types file...
+ */
+
+ snprintf(filename, sizeof(filename), "%s/%s", pathname, dent->filename);
+ load_types(mime, filename);
+ }
+ }
+
+ cupsDirClose(dir);
+
+ return (mime);
}
int cost; /* Cost of filter */
+ DEBUG_printf(("load_convs(mime=%p, filename=\"%s\", filterpath=\"%s\", "
+ "filtercache=%p)\n", mime, filename, filterpath, filtercache));
+
+
/*
* First try to open the file...
*/
if ((fp = cupsFileOpen(filename, "r")) == NULL)
return;
- DEBUG_printf(("\"%s\":\n", filename));
-
/*
* Then read each line from the file, skipping any comments in the file...
*/
* Skip blank lines and lines starting with a #...
*/
- DEBUG_puts(line);
-
if (!line[0] || line[0] == '#')
continue;
if ((dsttype = mimeType(mime, super, type)) == NULL)
{
- DEBUG_printf((" Destination type %s/%s not found!\n", super, type));
+ DEBUG_printf(("load_convs: Destination type %s/%s not found!\n",
+ super, type));
continue;
}
if (!add_fcache(filtercache, filter, filterpath))
{
- DEBUG_printf((" Filter %s not found in %s!\n", filter, filterpath));
+ DEBUG_printf(("load_convs: Filter %s not found in %s!\n", filter,
+ filterpath));
continue;
}
}
mime_type_t *typeptr; /* New MIME type */
+ DEBUG_printf(("load_types(mime=%p, filename=\"%s\")\n", mime, filename));
+
/*
* First try to open the file...
*/
if ((fp = cupsFileOpen(filename, "r")) == NULL)
return;
- DEBUG_printf(("\"%s\":\n", filename));
-
/*
* Then read each line from the file, skipping any comments in the file...
*/
* Skip blank lines and lines starting with a #...
*/
- DEBUG_puts(line);
-
if (!line[0] || line[0] == '#')
continue;
/*
- * End of "$Id: mime.c 5605 2006-05-30 19:38:02Z mike $".
+ * 'mime_new()' - Create a new, empty MIME database.
+ */
+
+static mime_t * /* O - MIME database */
+mime_new(void)
+{
+ return ((mime_t *)calloc(1, sizeof(mime_t)));
+}
+
+
+/*
+ * End of "$Id: mime.c 7694 2008-06-26 00:23:20Z mike $".
*/