]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/banners.c
2 * "$Id: banners.c 5051 2006-02-02 16:13:16Z mike $"
4 * Banner routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 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_banners() - Compare two banners.
33 * Include necessary headers...
44 static int compare_banners(const cupsd_banner_t
*b0
,
45 const cupsd_banner_t
*b1
);
49 * 'cupsdAddBanner()' - Add a banner to the array.
53 cupsdAddBanner(const char *name
, /* I - Name of banner */
54 const char *filename
) /* I - Filename for banner */
56 mime_type_t
*filetype
; /* Filetype */
57 cupsd_banner_t
*temp
; /* New banner data */
61 * See what the filetype is...
64 if ((filetype
= mimeFileType(MimeDatabase
, filename
, NULL
, NULL
)) == NULL
)
66 cupsdLogMessage(CUPSD_LOG_WARN
,
67 "cupsdAddBanner: Banner \"%s\" (\"%s\") is of an unknown file type - skipping!",
76 temp
= calloc(1, sizeof(cupsd_banner_t
));
79 * Copy the new banner data over...
82 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
83 temp
->filetype
= filetype
;
85 cupsArrayAdd(Banners
, temp
);
90 * 'cupsdFindBanner()' - Find a named banner.
93 cupsd_banner_t
* /* O - Pointer to banner or NULL */
94 cupsdFindBanner(const char *name
) /* I - Name of banner */
96 cupsd_banner_t key
; /* Search key */
99 strlcpy(key
.name
, name
, sizeof(key
.name
));
101 return ((cupsd_banner_t
*)cupsArrayFind(Banners
, &key
));
106 * 'cupsdFreeBanners()' - Free all banners.
110 cupsdFreeBanners(void)
112 cupsd_banner_t
*temp
; /* Current banner */
115 for (temp
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
117 temp
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
120 cupsArrayDelete(Banners
);
126 * 'cupsdLoadBanners()' - Load all available banner files...
130 cupsdLoadBanners(const char *d
) /* I - Directory to search */
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 */
139 * Free old banner info...
145 * Try opening the banner directory...
148 if ((dir
= cupsDirOpen(d
)) == NULL
)
150 cupsdLogMessage(CUPSD_LOG_ERROR
, "cupsdLoadBanners: Unable to open banner directory \"%s\": %s",
156 * Read entries, skipping directories and backup files.
159 Banners
= cupsArrayNew((cups_array_func_t
)compare_banners
, NULL
);
161 while ((dent
= cupsDirRead(dir
)) != NULL
)
164 * Check the file to make sure it isn't a directory or a backup
165 * file of some sort...
168 snprintf(filename
, sizeof(filename
), "%s/%s", d
, dent
->filename
);
170 if (S_ISDIR(dent
->fileinfo
.st_mode
))
173 if (dent
->filename
[0] == '~')
176 if ((ext
= strrchr(dent
->filename
, '.')) != NULL
)
177 if (!strcmp(ext
, ".bck") ||
178 !strcmp(ext
, ".bak") ||
179 !strcmp(ext
, ".sav"))
183 * Must be a valid file; add it!
186 cupsdAddBanner(dent
->filename
, filename
);
190 * Close the directory...
198 * 'compare_banners()' - Compare two banners.
201 static int /* O - -1 if name0 < name1, etc. */
203 const cupsd_banner_t
*b0
, /* I - First banner */
204 const cupsd_banner_t
*b1
) /* I - Second banner */
206 return (strcasecmp(b0
->name
, b1
->name
));
211 * End of "$Id: banners.c 5051 2006-02-02 16:13:16Z mike $".