]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/banners.c
2 * "$Id: banners.c 7221 2008-01-16 22:20:08Z mike $"
4 * Banner routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdFindBanner() - Find a named banner.
18 * cupsdLoadBanners() - Load all available banner files...
19 * add_banner() - Add a banner to the array.
20 * compare_banners() - Compare two banners.
21 * free_banners() - Free all banners.
25 * Include necessary headers...
36 static void add_banner(const char *name
, const char *filename
);
37 static int compare_banners(const cupsd_banner_t
*b0
,
38 const cupsd_banner_t
*b1
);
39 static void free_banners(void);
43 * 'cupsdFindBanner()' - Find a named banner.
46 cupsd_banner_t
* /* O - Pointer to banner or NULL */
47 cupsdFindBanner(const char *name
) /* I - Name of banner */
49 cupsd_banner_t key
; /* Search key */
52 key
.name
= (char *)name
;
54 return ((cupsd_banner_t
*)cupsArrayFind(Banners
, &key
));
59 * 'cupsdLoadBanners()' - Load all available banner files...
63 cupsdLoadBanners(const char *d
) /* I - Directory to search */
65 cups_dir_t
*dir
; /* Directory pointer */
66 cups_dentry_t
*dent
; /* Directory entry */
67 char filename
[1024], /* Name of banner */
68 *ext
; /* Pointer to extension */
72 * Free old banner info...
78 * Try opening the banner directory...
81 if ((dir
= cupsDirOpen(d
)) == NULL
)
83 cupsdLogMessage(CUPSD_LOG_ERROR
, "cupsdLoadBanners: Unable to open banner directory \"%s\": %s",
89 * Read entries, skipping directories and backup files.
92 Banners
= cupsArrayNew((cups_array_func_t
)compare_banners
, NULL
);
94 while ((dent
= cupsDirRead(dir
)) != NULL
)
97 * Check the file to make sure it isn't a directory or a backup
98 * file of some sort...
101 snprintf(filename
, sizeof(filename
), "%s/%s", d
, dent
->filename
);
103 if (S_ISDIR(dent
->fileinfo
.st_mode
))
106 if (dent
->filename
[0] == '~' ||
107 dent
->filename
[strlen(dent
->filename
) - 1] == '~')
110 if ((ext
= strrchr(dent
->filename
, '.')) != NULL
)
111 if (!strcmp(ext
, ".bck") ||
112 !strcmp(ext
, ".bak") ||
113 !strcmp(ext
, ".sav"))
117 * Must be a valid file; add it!
120 add_banner(dent
->filename
, filename
);
124 * Close the directory...
132 * 'add_banner()' - Add a banner to the array.
136 add_banner(const char *name
, /* I - Name of banner */
137 const char *filename
) /* I - Filename for banner */
139 mime_type_t
*filetype
; /* Filetype */
140 cupsd_banner_t
*temp
; /* New banner data */
144 * See what the filetype is...
147 if ((filetype
= mimeFileType(MimeDatabase
, filename
, NULL
, NULL
)) == NULL
)
149 cupsdLogMessage(CUPSD_LOG_WARN
,
150 "add_banner: Banner \"%s\" (\"%s\") is of an unknown file "
151 "type - skipping!", name
, filename
);
159 if ((temp
= calloc(1, sizeof(cupsd_banner_t
))) == NULL
)
161 cupsdLogMessage(CUPSD_LOG_WARN
,
162 "add_banner: Unable to allocate memory for banner \"%s\" - "
168 * Copy the new banner data over...
171 if ((temp
->name
= strdup(name
)) == NULL
)
173 cupsdLogMessage(CUPSD_LOG_WARN
,
174 "add_banner: Unable to allocate memory for banner \"%s\" - "
180 temp
->filetype
= filetype
;
182 cupsArrayAdd(Banners
, temp
);
187 * 'compare_banners()' - Compare two banners.
190 static int /* O - -1 if name0 < name1, etc. */
192 const cupsd_banner_t
*b0
, /* I - First banner */
193 const cupsd_banner_t
*b1
) /* I - Second banner */
195 return (strcasecmp(b0
->name
, b1
->name
));
200 * 'free_banners()' - Free all banners.
206 cupsd_banner_t
*temp
; /* Current banner */
209 for (temp
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
211 temp
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
217 cupsArrayDelete(Banners
);
223 * End of "$Id: banners.c 7221 2008-01-16 22:20:08Z mike $".