From: Ted Lemon Date: Tue, 6 Jun 2000 23:46:37 +0000 (+0000) Subject: Add hash_foreach, et al. X-Git-Tag: V3-BETA-2-PATCH-1~173 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0411fbd4d861fc049a1421368174e9619d9b40c;p=thirdparty%2Fdhcp.git Add hash_foreach, et al. --- diff --git a/common/hash.c b/common/hash.c index 9f3bf7063..0588a150e 100644 --- a/common/hash.c +++ b/common/hash.c @@ -43,7 +43,7 @@ #ifndef lint static char copyright[] = -"$Id: hash.c,v 1.23 2000/05/17 16:15:38 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n"; +"$Id: hash.c,v 1.24 2000/06/06 23:46:31 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -229,6 +229,27 @@ int hash_lookup (vp, table, name, len, file, line) return 0; } +int hash_foreach (struct hash_table *table, hash_foreach_func func) +{ + int i; + struct hash_bucket *bp, *next; + int count = 0; + + if (!table) + return 0; + + for (i = 0; i < table -> hash_count; i++) { + bp = table -> buckets [i]; + while (bp) { + next = bp -> next; + (*func) (bp -> name, bp -> len, bp -> value); + bp = next; + count++; + } + } + return count; +} + int casecmp (const void *v1, const void *v2, unsigned long len) { unsigned i; diff --git a/includes/dhcpd.h b/includes/dhcpd.h index e0f821f00..5eab48259 100644 --- a/includes/dhcpd.h +++ b/includes/dhcpd.h @@ -1521,6 +1521,7 @@ void delete_hash_entry PROTO ((struct hash_table *, const unsigned char *, unsigned, const char *, int)); int hash_lookup PROTO ((hashed_object_t **, struct hash_table *, const unsigned char *, unsigned, const char *, int)); +int hash_foreach (struct hash_table *, hash_foreach_func); int casecmp (const void *s, const void *t, unsigned long len); HASH_FUNCTIONS_DECL (group, const char *, struct group_object) HASH_FUNCTIONS_DECL (universe, const char *, struct universe) @@ -2133,6 +2134,8 @@ void uid_hash_delete PROTO ((struct lease *)); void hw_hash_add PROTO ((struct lease *)); void hw_hash_delete PROTO ((struct lease *)); void write_leases PROTO ((void)); +int lease_enqueue (struct lease *); +void lease_instantiate (const unsigned char *, unsigned, struct lease *); void expire_all_pools PROTO ((void)); void dump_subnets PROTO ((void)); HASH_FUNCTIONS_DECL (lease, const unsigned char *, struct lease) @@ -2205,6 +2208,8 @@ isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *, int dhcp_failover_pool_rebalance (dhcp_failover_state_t *); int dhcp_failover_pool_check (struct pool *); int dhcp_failover_state_pool_check (dhcp_failover_state_t *); +void dhcp_failover_timeout (void *); +void dhcp_failover_send_contact (void *); isc_result_t dhcp_failover_send_updates (dhcp_failover_state_t *); int dhcp_failover_queue_update (struct lease *, int); void dhcp_failover_ack_queue_remove (dhcp_failover_state_t *, struct lease *); diff --git a/includes/hash.h b/includes/hash.h index 0e5b593a2..bd6a2b325 100644 --- a/includes/hash.h +++ b/includes/hash.h @@ -48,6 +48,8 @@ typedef struct { int foo; } hashed_object_t; +typedef void (*hash_foreach_func) (const unsigned char *, + unsigned, hashed_object_t *); typedef int (*hash_reference) (hashed_object_t **, hashed_object_t *, const char *, int); typedef int (*hash_dereference) (hashed_object_t **, const char *, int); @@ -82,7 +84,10 @@ void name##_hash_add (struct hash_table *, bufarg, unsigned, type *, \ void name##_hash_delete (struct hash_table *, bufarg, unsigned, \ const char *, int); \ int name##_hash_lookup (type **, struct hash_table *, bufarg, unsigned, \ - const char *, int); + const char *, int); \ +int name##_hash_foreach (struct hash_table *, \ + void (*) (bufarg, unsigned, type *)); + #define HASH_FUNCTIONS(name, bufarg, type) \ void name##_hash_add (struct hash_table *table, \ @@ -106,6 +111,12 @@ int name##_hash_lookup (type **ptr, struct hash_table *table, \ { \ return hash_lookup ((hashed_object_t **)ptr, table, \ (const unsigned char *)buf, len, file, line); \ +} \ + \ +int name##_hash_foreach (struct hash_table *table, \ + void (*func) (bufarg, unsigned, type *)) \ +{ \ + return hash_foreach (table, (hash_foreach_func)func); \ }