]> git.sesse.net Git - betaftpd/commitdiff
More dcache separation.
authorsgunderson <sgunderson>
Sun, 17 Sep 2000 01:02:30 +0000 (01:02 +0000)
committersgunderson <sgunderson>
Sun, 17 Sep 2000 01:02:30 +0000 (01:02 +0000)
dcache.c
dcache.h
ftpd.c
ftpd.h

index ddf5cab37a30662e043695e2c15e35cf7fd6fa61..5827bc54e78f94fd1b1e384fec252ac2924fbfab 100644 (file)
--- a/dcache.c
+++ b/dcache.c
@@ -63,6 +63,25 @@ struct dcache *alloc_new_dcache()
        return d;
 }
 
+/*
+ * destroy_dcache():
+ *             Destroy a directory listing cache entry, remove it from the
+ *             linked list, and clean up after it.
+ *
+ *             If you free a cache entry that is in use (use_count > 0),
+ *             BetaFTPD will most likely crash (later). The thing you're supposed
+ *             to do when you're done with a dcache entry, is to decrement
+ *             its use_count, and let the timeout functions do the destroying
+ *             when it's time to do so.
+ */
+void destroy_dcache(struct dcache * const d)
+{
+       if (d == NULL) return;
+
+       if (d->dir_data != NULL) free(d->dir_data);
+       remove_from_linked_list((struct list_element *)d);
+}
+
 /*
  * time_out_dcache():
  *             Time out expired directory listing cache entries.
@@ -108,4 +127,32 @@ void populate_dcache(struct ftran * const f, const char * const cwd,
                d->lo = *lo;
        }
 }
+
+/*
+ * find_dcache():
+ *             Check if there is an existing dcache object matching our
+ *             criteria.
+ */
+struct dcache *find_dcache(const char * const cwd, const char * const pattern,
+                           const struct list_options * const lo)
+{
+       struct dcache *d = NULL, *next = first_dcache->next_dcache;
+       struct stat buf;
+
+       if (stat(cwd, &buf) > -1) {
+               /* run through the linked list */
+               while (next != NULL) {
+                       d = next;
+                       next = d->next_dcache;
+
+                       if (buf.st_mtime <= d->generated &&
+                           strcmp(d->dir_name, cwd) == 0 &&
+                           strcmp(d->pattern, pattern) == 0 &&
+                           memcmp(&(d->lo), lo, sizeof(struct list_options)) == 0) {
+                               return d;
+                       }
+               }
+       }
+       return NULL;
+}
 #endif /* WANT_DCACHE */
index d45614bebcba9e8f010421c1c6c7770def33debc..a3037267d2a986f23874be8055f1e1bbeee15b40 100644 (file)
--- a/dcache.h
+++ b/dcache.h
@@ -46,8 +46,12 @@ struct dcache {
 };
 
 struct dcache *alloc_new_dcache();
+void destroy_dcache(struct dcache * const d);
+
 void time_out_dcache();
 void populate_dcache(struct ftran * const f, const char * const cwd,
                     const char * const pattern, const struct list_options * const lo);
+struct dcache *find_dcache(const char * const cwd, const char * const pattern, 
+                          const struct list_options * const lo);
 
 #endif
diff --git a/ftpd.c b/ftpd.c
index 0f497c9a2a60bc194db5c5bfe055546219d384b2..7f73e8951ca177e08e15bbd060c05c9e2b1ae16a 100644 (file)
--- a/ftpd.c
+++ b/ftpd.c
 #include <config.h>
 #endif
 
-#if HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
 #if HAVE_ERRNO_H
 #include <errno.h>
 #endif
 #include <unistd.h>
 #endif
 
-#if HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
 #if HAVE_ARPA_INET_H
 #include <arpa/inet.h>
 #endif
 #include <sys/stat.h>
 #endif
 
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
 #if HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
@@ -522,27 +510,6 @@ void destroy_ftran(struct ftran * const f)
        remove_from_linked_list((struct list_element *)f);
 }
 
-#if WANT_DCACHE
-/*
- * destroy_dcache():
- *             Destroy a directory listing cache entry, remove it from the
- *             linked list, and clean up after it.
- *
- *             If you free a cache entry that is in use (use_count > 0),
- *             BetaFTPD will most likely crash (later). The thing you're supposed
- *             to do when you're done with a dcache entry, is to decrement
- *             its use_count, and let the timeout functions do the destroying
- *             when it's time to do so.
- */
-void destroy_dcache(struct dcache * const d)
-{
-        if (d == NULL) return;
-
-       if (d->dir_data != NULL) free(d->dir_data);
-       remove_from_linked_list((struct list_element *)d);
-}
-#endif
-
 /*
  * process_all_clients():
  *             Processes all the _control_ connections in active_clients
diff --git a/ftpd.h b/ftpd.h
index 11bb81a74ecf169e303951254d39de37cb553154..3110b10dd853f6fa2cb245a616246534ac2ca240 100644 (file)
--- a/ftpd.h
+++ b/ftpd.h
@@ -177,18 +177,12 @@ void remove_from_linked_list(struct list_element * const elem);
 
 struct conn *alloc_new_conn(const int sock);
 struct ftran *alloc_new_ftran(const int sock, const struct conn * const c);
-#if WANT_DCACHE
-struct dcache *alloc_new_dcache();
-#endif
 
 int add_fd(const int fd, const int events);
 void del_fd(const int fd);
 
 void destroy_conn(struct conn * const c);
 void destroy_ftran(struct ftran * const f);
-#if WANT_DCACHE
-void destroy_dcache(struct dcache * const d);
-#endif
 
 #if HAVE_POLL
 int process_all_clients(const int num_ac);
@@ -207,9 +201,6 @@ RETSIGTYPE handle_alarm(int signum);
 
 void accept_new_client(int * const server_sock);
 void time_out_sockets();
-#if WANT_DCACHE
-void time_out_dcache();
-#endif
 
 void remove_bytes(struct conn * const c, const int i);
 void numeric(struct conn * const c, const int numeric, const char * const format, ...);