/*
- * "$Id: banners.c 4968 2006-01-24 03:56:31Z mike $"
+ * "$Id: banners.c 7221 2008-01-16 22:20:08Z mike $"
*
* Banner routines for the Common UNIX Printing System (CUPS).
*
+ * Copyright 2007-2008 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* 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:
*
- * cupsdAddBanner() - Add a banner to the array.
* cupsdFindBanner() - Find a named banner.
* cupsdLoadBanners() - Load all available banner files...
+ * add_banner() - Add a banner to the array.
* compare_banners() - Compare two banners.
+ * free_banners() - Free all banners.
*/
/*
* Local functions...
*/
+static void add_banner(const char *name, const char *filename);
static int compare_banners(const cupsd_banner_t *b0,
const cupsd_banner_t *b1);
-
-
-/*
- * 'cupsdAddBanner()' - Add a banner to the array.
- */
-
-void
-cupsdAddBanner(const char *name, /* I - Name of banner */
- const char *filename) /* I - Filename for banner */
-{
- mime_type_t *filetype; /* Filetype */
- cupsd_banner_t *temp; /* New banner data */
-
-
- /*
- * See what the filetype is...
- */
-
- if ((filetype = mimeFileType(MimeDatabase, filename, NULL)) == NULL)
- {
- cupsdLogMessage(CUPSD_LOG_WARN,
- "cupsdAddBanner: Banner \"%s\" (\"%s\") is of an unknown file type - skipping!",
- name, filename);
- return;
- }
-
- /*
- * Allocate memory...
- */
-
- temp = calloc(1, sizeof(cupsd_banner_t));
-
- /*
- * Copy the new banner data over...
- */
-
- strlcpy(temp->name, name, sizeof(temp->name));
- temp->filetype = filetype;
-
- cupsArrayAdd(Banners, temp);
-}
+static void free_banners(void);
/*
cupsd_banner_t key; /* Search key */
- strlcpy(key.name, name, sizeof(key.name));
+ key.name = (char *)name;
return ((cupsd_banner_t *)cupsArrayFind(Banners, &key));
}
-/*
- * 'cupsdFreeBanners()' - Free all banners.
- */
-
-void
-cupsdFreeBanners(void)
-{
- cupsd_banner_t *temp; /* Current banner */
-
-
- for (temp = (cupsd_banner_t *)cupsArrayFirst(Banners);
- temp;
- temp = (cupsd_banner_t *)cupsArrayNext(Banners))
- free(temp);
-
- cupsArrayDelete(Banners);
- Banners = NULL;
-}
-
-
/*
* 'cupsdLoadBanners()' - Load all available banner files...
*/
* Free old banner info...
*/
- cupsdFreeBanners();
+ free_banners();
/*
* Try opening the banner directory...
if (S_ISDIR(dent->fileinfo.st_mode))
continue;
- if (dent->filename[0] == '~')
+ if (dent->filename[0] == '~' ||
+ dent->filename[strlen(dent->filename) - 1] == '~')
continue;
if ((ext = strrchr(dent->filename, '.')) != NULL)
* Must be a valid file; add it!
*/
- cupsdAddBanner(dent->filename, filename);
+ add_banner(dent->filename, filename);
}
/*
}
+/*
+ * 'add_banner()' - Add a banner to the array.
+ */
+
+static void
+add_banner(const char *name, /* I - Name of banner */
+ const char *filename) /* I - Filename for banner */
+{
+ mime_type_t *filetype; /* Filetype */
+ cupsd_banner_t *temp; /* New banner data */
+
+
+ /*
+ * See what the filetype is...
+ */
+
+ if ((filetype = mimeFileType(MimeDatabase, filename, NULL, NULL)) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "add_banner: Banner \"%s\" (\"%s\") is of an unknown file "
+ "type - skipping!", name, filename);
+ return;
+ }
+
+ /*
+ * Allocate memory...
+ */
+
+ if ((temp = calloc(1, sizeof(cupsd_banner_t))) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "add_banner: Unable to allocate memory for banner \"%s\" - "
+ "skipping!", name);
+ return;
+ }
+
+ /*
+ * Copy the new banner data over...
+ */
+
+ if ((temp->name = strdup(name)) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "add_banner: Unable to allocate memory for banner \"%s\" - "
+ "skipping!", name);
+ free(temp);
+ return;
+ }
+
+ temp->filetype = filetype;
+
+ cupsArrayAdd(Banners, temp);
+}
+
+
/*
* 'compare_banners()' - Compare two banners.
*/
/*
- * End of "$Id: banners.c 4968 2006-01-24 03:56:31Z mike $".
+ * 'free_banners()' - Free all banners.
+ */
+
+static void
+free_banners(void)
+{
+ cupsd_banner_t *temp; /* Current banner */
+
+
+ for (temp = (cupsd_banner_t *)cupsArrayFirst(Banners);
+ temp;
+ temp = (cupsd_banner_t *)cupsArrayNext(Banners))
+ {
+ free(temp->name);
+ free(temp);
+ }
+
+ cupsArrayDelete(Banners);
+ Banners = NULL;
+}
+
+
+/*
+ * End of "$Id: banners.c 7221 2008-01-16 22:20:08Z mike $".
*/