]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/banners.c
2 * "$Id: banners.c 4719 2005-09-28 21:12:44Z mike $"
4 * Banner routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdAddBanner() - Add a banner to the array.
27 * cupsdFindBanner() - Find a named banner.
28 * cupsdLoadBanners() - Load all available banner files...
29 * compare() - Compare two banners.
33 * Include necessary headers...
44 static int compare(const cupsd_banner_t
*b0
, const cupsd_banner_t
*b1
);
48 * 'cupsdAddBanner()' - Add a banner to the array.
52 cupsdAddBanner(const char *name
, /* I - Name of banner */
53 const char *filename
) /* I - Filename for banner */
55 mime_type_t
*filetype
; /* Filetype */
56 cupsd_banner_t
*temp
; /* New banner data */
60 * See what the filetype is...
63 if ((filetype
= mimeFileType(MimeDatabase
, filename
, NULL
)) == NULL
)
65 cupsdLogMessage(CUPSD_LOG_WARN
,
66 "cupsdAddBanner: Banner \"%s\" (\"%s\") is of an unknown file type - skipping!",
76 temp
= malloc(sizeof(cupsd_banner_t
));
78 temp
= realloc(Banners
, sizeof(cupsd_banner_t
) * (NumBanners
+ 1));
82 cupsdLogMessage(CUPSD_LOG_ERROR
,
83 "cupsdAddBanner: Ran out of memory adding a banner!");
88 * Copy the new banner data over...
95 memset(temp
, 0, sizeof(cupsd_banner_t
));
96 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
97 temp
->filetype
= filetype
;
102 * 'cupsdFindBanner()' - Find a named banner.
105 cupsd_banner_t
* /* O - Pointer to banner or NULL */
106 cupsdFindBanner(const char *name
) /* I - Name of banner */
108 cupsd_banner_t key
; /* Search key */
111 strlcpy(key
.name
, name
, sizeof(key
.name
));
113 return ((cupsd_banner_t
*)bsearch(&key
, Banners
, NumBanners
, sizeof(cupsd_banner_t
),
114 (int (*)(const void *, const void *))compare
));
119 * 'cupsdLoadBanners()' - Load all available banner files...
123 cupsdLoadBanners(const char *d
) /* I - Directory to search */
125 cups_dir_t
*dir
; /* Directory pointer */
126 cups_dentry_t
*dent
; /* Directory entry */
127 char filename
[1024], /* Name of banner */
128 *ext
; /* Pointer to extension */
132 * Free old banner info...
142 * Try opening the banner directory...
145 if ((dir
= cupsDirOpen(d
)) == NULL
)
147 cupsdLogMessage(CUPSD_LOG_ERROR
, "cupsdLoadBanners: Unable to open banner directory \"%s\": %s",
153 * Read entries, skipping directories and backup files.
156 while ((dent
= cupsDirRead(dir
)) != NULL
)
159 * Check the file to make sure it isn't a directory or a backup
160 * file of some sort...
163 snprintf(filename
, sizeof(filename
), "%s/%s", d
, dent
->filename
);
165 if (S_ISDIR(dent
->fileinfo
.st_mode
))
168 if (dent
->filename
[0] == '~')
171 if ((ext
= strrchr(dent
->filename
, '.')) != NULL
)
172 if (!strcmp(ext
, ".bck") ||
173 !strcmp(ext
, ".bak") ||
174 !strcmp(ext
, ".sav"))
178 * Must be a valid file; add it!
181 cupsdAddBanner(dent
->filename
, filename
);
185 * Close the directory and sort as needed...
191 qsort(Banners
, NumBanners
, sizeof(cupsd_banner_t
),
192 (int (*)(const void *, const void *))compare
);
197 * 'compare()' - Compare two banners.
200 static int /* O - -1 if name0 < name1, etc. */
201 compare(const cupsd_banner_t
*b0
, /* I - First banner */
202 const cupsd_banner_t
*b1
) /* I - Second banner */
204 return (strcasecmp(b0
->name
, b1
->name
));
209 * End of "$Id: banners.c 4719 2005-09-28 21:12:44Z mike $".