]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/banners.c
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 * cupsdFindBanner() - Find a named banner.
27 * cupsdLoadBanners() - Load all available banner files...
28 * add_banner() - Add a banner to the array.
29 * compare_banners() - Compare two banners.
30 * free_banners() - Free all banners.
34 * Include necessary headers...
45 static void add_banner(const char *name
, const char *filename
);
46 static int compare_banners(const cupsd_banner_t
*b0
,
47 const cupsd_banner_t
*b1
);
48 static void free_banners(void);
52 * 'cupsdFindBanner()' - Find a named banner.
55 cupsd_banner_t
* /* O - Pointer to banner or NULL */
56 cupsdFindBanner(const char *name
) /* I - Name of banner */
58 cupsd_banner_t key
; /* Search key */
61 key
.name
= (char *)name
;
63 return ((cupsd_banner_t
*)cupsArrayFind(Banners
, &key
));
68 * 'cupsdLoadBanners()' - Load all available banner files...
72 cupsdLoadBanners(const char *d
) /* I - Directory to search */
74 cups_dir_t
*dir
; /* Directory pointer */
75 cups_dentry_t
*dent
; /* Directory entry */
76 char filename
[1024], /* Name of banner */
77 *ext
; /* Pointer to extension */
81 * Free old banner info...
87 * Try opening the banner directory...
90 if ((dir
= cupsDirOpen(d
)) == NULL
)
92 cupsdLogMessage(CUPSD_LOG_ERROR
, "cupsdLoadBanners: Unable to open banner directory \"%s\": %s",
98 * Read entries, skipping directories and backup files.
101 Banners
= cupsArrayNew((cups_array_func_t
)compare_banners
, NULL
);
103 while ((dent
= cupsDirRead(dir
)) != NULL
)
106 * Check the file to make sure it isn't a directory or a backup
107 * file of some sort...
110 snprintf(filename
, sizeof(filename
), "%s/%s", d
, dent
->filename
);
112 if (S_ISDIR(dent
->fileinfo
.st_mode
))
115 if (dent
->filename
[0] == '~' ||
116 dent
->filename
[strlen(dent
->filename
) - 1] == '~')
119 if ((ext
= strrchr(dent
->filename
, '.')) != NULL
)
120 if (!strcmp(ext
, ".bck") ||
121 !strcmp(ext
, ".bak") ||
122 !strcmp(ext
, ".sav"))
126 * Must be a valid file; add it!
129 add_banner(dent
->filename
, filename
);
133 * Close the directory...
141 * 'add_banner()' - Add a banner to the array.
145 add_banner(const char *name
, /* I - Name of banner */
146 const char *filename
) /* I - Filename for banner */
148 mime_type_t
*filetype
; /* Filetype */
149 cupsd_banner_t
*temp
; /* New banner data */
153 * See what the filetype is...
156 if ((filetype
= mimeFileType(MimeDatabase
, filename
, NULL
, NULL
)) == NULL
)
158 cupsdLogMessage(CUPSD_LOG_WARN
,
159 "add_banner: Banner \"%s\" (\"%s\") is of an unknown file type - skipping!",
168 temp
= calloc(1, sizeof(cupsd_banner_t
));
171 * Copy the new banner data over...
174 temp
->name
= strdup(name
);
175 temp
->filetype
= filetype
;
177 cupsArrayAdd(Banners
, temp
);
182 * 'compare_banners()' - Compare two banners.
185 static int /* O - -1 if name0 < name1, etc. */
187 const cupsd_banner_t
*b0
, /* I - First banner */
188 const cupsd_banner_t
*b1
) /* I - Second banner */
190 return (strcasecmp(b0
->name
, b1
->name
));
195 * 'free_banners()' - Free all banners.
201 cupsd_banner_t
*temp
; /* Current banner */
204 for (temp
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
206 temp
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
212 cupsArrayDelete(Banners
);