1 /* dcache.c: BetaFTPD directory listing cache
2 Copyright (C) 2000 Steinar H. Gunderson
4 This program is is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2 if the
6 License as published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
42 extern struct dcache *first_dcache;
46 * Allocates a new directory cache entry (type `struct dcache'),
47 * and adds it to the linked list.
49 struct dcache *alloc_new_dcache()
51 struct dcache *d = (struct dcache *)(malloc(sizeof(struct dcache)));
53 if (d == NULL) return d;
57 strcpy(d->dir_name, "");
60 add_to_linked_list((struct list_element *)first_dcache,
61 (struct list_element *)d);
68 * Time out expired directory listing cache entries.
69 * Uses much of the same code as time_out_sockets().
71 void time_out_dcache()
73 struct dcache *d = NULL, *next = first_dcache->next_dcache;
74 time_t now = time(NULL);
76 /* run through the linked list */
77 while (next != NULL) {
79 next = d->next_dcache;
81 if (d->use_count == 0 && (now - d->last_used > 900)) {
89 * Add a new entry in the dcache, using information from
90 * the given file transfer object, and the current directory
93 void populate_dcache(struct ftran * const f, const char * const cwd,
94 const char * const pattern, const struct list_options * const lo)
97 struct dcache *d = alloc_new_dcache();
98 if (d != NULL && stat(cwd, &buf) > -1) {
101 d->dir_data = f->file_data;
102 d->dir_size = f->size;
103 d->generated = buf.st_mtime;
105 strcpy(d->dir_name, cwd);
106 strncpy(d->pattern, pattern, 255);
111 #endif /* WANT_DCACHE */