]> git.ipfire.org Git - thirdparty/cups.git/blame - scheduler/banners.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / banners.c
CommitLineData
ef416fc2 1/*
4400e98d 2 * "$Id: banners.c 5051 2006-02-02 16:13:16Z mike $"
ef416fc2 3 *
4 * Banner routines for the Common UNIX Printing System (CUPS).
5 *
fa73b229 6 * Copyright 1997-2006 by Easy Software Products.
ef416fc2 7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * cupsdAddBanner() - Add a banner to the array.
27 * cupsdFindBanner() - Find a named banner.
28 * cupsdLoadBanners() - Load all available banner files...
fa73b229 29 * compare_banners() - Compare two banners.
ef416fc2 30 */
31
32/*
33 * Include necessary headers...
34 */
35
36#include "cupsd.h"
37#include <cups/dir.h>
38
39
40/*
41 * Local functions...
42 */
43
fa73b229 44static int compare_banners(const cupsd_banner_t *b0,
45 const cupsd_banner_t *b1);
ef416fc2 46
47
48/*
49 * 'cupsdAddBanner()' - Add a banner to the array.
50 */
51
52void
53cupsdAddBanner(const char *name, /* I - Name of banner */
54 const char *filename) /* I - Filename for banner */
55{
56 mime_type_t *filetype; /* Filetype */
57 cupsd_banner_t *temp; /* New banner data */
58
59
60 /*
61 * See what the filetype is...
62 */
63
4400e98d 64 if ((filetype = mimeFileType(MimeDatabase, filename, NULL, NULL)) == NULL)
ef416fc2 65 {
66 cupsdLogMessage(CUPSD_LOG_WARN,
67 "cupsdAddBanner: Banner \"%s\" (\"%s\") is of an unknown file type - skipping!",
68 name, filename);
69 return;
70 }
71
72 /*
73 * Allocate memory...
74 */
75
fa73b229 76 temp = calloc(1, sizeof(cupsd_banner_t));
ef416fc2 77
78 /*
79 * Copy the new banner data over...
80 */
81
ef416fc2 82 strlcpy(temp->name, name, sizeof(temp->name));
83 temp->filetype = filetype;
fa73b229 84
85 cupsArrayAdd(Banners, temp);
ef416fc2 86}
87
88
89/*
90 * 'cupsdFindBanner()' - Find a named banner.
91 */
92
93cupsd_banner_t * /* O - Pointer to banner or NULL */
94cupsdFindBanner(const char *name) /* I - Name of banner */
95{
96 cupsd_banner_t key; /* Search key */
97
98
99 strlcpy(key.name, name, sizeof(key.name));
100
fa73b229 101 return ((cupsd_banner_t *)cupsArrayFind(Banners, &key));
102}
103
104
105/*
106 * 'cupsdFreeBanners()' - Free all banners.
107 */
108
109void
110cupsdFreeBanners(void)
111{
112 cupsd_banner_t *temp; /* Current banner */
113
114
115 for (temp = (cupsd_banner_t *)cupsArrayFirst(Banners);
116 temp;
117 temp = (cupsd_banner_t *)cupsArrayNext(Banners))
118 free(temp);
119
120 cupsArrayDelete(Banners);
121 Banners = NULL;
ef416fc2 122}
123
124
125/*
126 * 'cupsdLoadBanners()' - Load all available banner files...
127 */
128
129void
130cupsdLoadBanners(const char *d) /* I - Directory to search */
131{
132 cups_dir_t *dir; /* Directory pointer */
133 cups_dentry_t *dent; /* Directory entry */
134 char filename[1024], /* Name of banner */
135 *ext; /* Pointer to extension */
136
137
138 /*
139 * Free old banner info...
140 */
141
fa73b229 142 cupsdFreeBanners();
ef416fc2 143
144 /*
145 * Try opening the banner directory...
146 */
147
148 if ((dir = cupsDirOpen(d)) == NULL)
149 {
150 cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdLoadBanners: Unable to open banner directory \"%s\": %s",
151 d, strerror(errno));
152 return;
153 }
154
155 /*
156 * Read entries, skipping directories and backup files.
157 */
158
fa73b229 159 Banners = cupsArrayNew((cups_array_func_t)compare_banners, NULL);
160
ef416fc2 161 while ((dent = cupsDirRead(dir)) != NULL)
162 {
163 /*
164 * Check the file to make sure it isn't a directory or a backup
165 * file of some sort...
166 */
167
168 snprintf(filename, sizeof(filename), "%s/%s", d, dent->filename);
169
170 if (S_ISDIR(dent->fileinfo.st_mode))
171 continue;
172
173 if (dent->filename[0] == '~')
174 continue;
175
176 if ((ext = strrchr(dent->filename, '.')) != NULL)
177 if (!strcmp(ext, ".bck") ||
178 !strcmp(ext, ".bak") ||
179 !strcmp(ext, ".sav"))
180 continue;
181
182 /*
183 * Must be a valid file; add it!
184 */
185
186 cupsdAddBanner(dent->filename, filename);
187 }
188
189 /*
fa73b229 190 * Close the directory...
ef416fc2 191 */
192
193 cupsDirClose(dir);
ef416fc2 194}
195
196
197/*
fa73b229 198 * 'compare_banners()' - Compare two banners.
ef416fc2 199 */
200
201static int /* O - -1 if name0 < name1, etc. */
fa73b229 202compare_banners(
203 const cupsd_banner_t *b0, /* I - First banner */
204 const cupsd_banner_t *b1) /* I - Second banner */
ef416fc2 205{
206 return (strcasecmp(b0->name, b1->name));
207}
208
209
210/*
4400e98d 211 * End of "$Id: banners.c 5051 2006-02-02 16:13:16Z mike $".
ef416fc2 212 */